Start of change

Example: ILE C program for loading a function control vector for your 4767 Cryptographic Coprocessor

Change this IBM i ILE C program example to suit your needs for loading a function control vector for your 4767 Cryptographic Coprocessor.

Note: Read the Code license and disclaimer information for important legal information.

/*------------------------------------------------------------*/
/* Load the Function Control Vector into the 4767 card.       */
/* The Function Control Vector enables the cryptographic      */
/* functions of the 4767.                                     */
/*                                                            */
/*  COPYRIGHT 5770-SS1 (C) IBM CORP. 1999, 2018               */
/*                                                            */
/*  This material contains programming source code for your   */
/*  consideration.  These examples have not been thoroughly   */
/*  tested under all conditions.  IBM, therefore, cannot      */
/*  guarantee or imply reliability, serviceability, or        */
/*  functions of these program.  All programs contained       */
/*  herein are provided to you "AS IS".  THE IMPLIED          */
/*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           */
/*  PARTICULAR PURPOSE ARE ARE EXPRESSLY DISCLAIMED.  IBM     */
/*  provides no program services for these programs and files.*/
/*                                                            */
/* Note: The Function Control Vector is stored in an IFS      */
/*       file owned by the system. The format of this         */
/*       vector is described in an appendix of the            */
/*       IBM CCA Basic Services Reference and Guide      */
/*       (SC31-8609) publication.                             */
/*                                                            */
/* Use the following command to compile this program:         */
/* CRTCMOD MODULE(LOAD_FCV) SRCFILE(SAMPLE) SYSIFCOPT(*IFSIO) */
/* CRTPGM  PGM(LOAD_FCV) MODULE(LOAD_FCV)                     */
/*         BNDSRVPGM(QCCA/CSUACFC)                            */
/*                                                            */
/* Common Cryptographic Architecture (CCA) verbs used:        */
/* - Cryptographic_Facility_Control (CSUACFC)                 */
/*                                                            */
/*------------------------------------------------------------*/

#include <tdlib.h>
#include <stdio.h>
#include <string.h>
#include "csucincl.h"            /* header file for CCA Cryptographic
                                    Service Provider for IBM i       */

int main(void)
{

/*-------------------------------------------------------------------*/
/* standard return codes                                             */
/*-------------------------------------------------------------------*/

#define ERROR -1
#define OK     0

/*-------------------------------------------------------------------*/
/* standard CCA parameters                                           */
/*-------------------------------------------------------------------*/

  long return_code;
  long reason_code;
  long exit_data_length;
  unsigned char exit_data[2];
  unsigned char rule_array[4][8];
  long rule_array_count;


/*-------------------------------------------------------------------*/
/* fields unique to this sample program                              */
/*-------------------------------------------------------------------*/

  long verb_data_length;
  char *verb_data;
  char buffer[3000];
  int num_bytes;
  FILE *fcv;

/*-------------------------------------------------------------------*/
/* retrieve FCV from IBM supplied file                               */
/*-------------------------------------------------------------------*/
  fcv = fopen("/QIBM/ProdData/CryptoDevMgr/FCV4767.CRT", "rb");
  if (fcv==NULL)
   {
    printf("Function Control Vector file not available\n\n");
    return ERROR;                /* File not found or not authorized */
   }

  num_bytes = fread(buffer,1,3000,fcv);
  fclose(fcv);

  if (num_bytes != 817)                 // 4767 File Length
   {
    printf("Function Control Vector file has wrong size\n\n");
    return ERROR;                /* Incorrect number of bytes read   */
   }

/*-------------------------------------------------------------------*/
/* extract fields in FCV needed by 4767 card                         */
/* Note: use offsets and lengths from CCA publication listed earlier */
/*-------------------------------------------------------------------*/

  verb_data_length = 208;       // 4767 FCV Length

  verb_data = &buffer[477];     // 4767 FCV Offset

  rule_array_count = 2;
  memcpy((char*)rule_array,"ADAPTER1LOAD-FCV",16);

/*-------------------------------------------------------------------*/
/* Load the 4767 card with the FCV just retrieved                    */
/*-------------------------------------------------------------------*/
  CSUACFC(&return_code,
          &reason_code,
          &exit_data_length,
          (unsigned char *)exit_data,
          &rule_array_count,
          (unsigned char *)rule_array,
          &verb_data_length,
          (unsigned char *)verb_data);

  if (return_code != 0)
  {
    printf("Function Control Vector rejected for reason %d/%d\n\n",
            return_code, reason_code);
    return ERROR;                /* Operation failed.                */
  }
  else
  {
    printf("Loading Function Control Vector succeeded\n\n");
    return OK;
  }
 }
End of change