RSA Security 5 manual Code Example

Models: 5

1 376
Download 376 pages 51.16 Kb
Page 15
Image 15

Code Example

Code Example

The following code example summarizes the six-step model used in Crypto-C. This model is described in depth in Chapter 1 of the User’s Manual. The example encrypts data within a DES key, using a function named EncryptData. The inputs to EncryptData are: a pointer to the buffer, the data’s length, a pointer to the 8-byte DES key value, and a pointer to the 8-byte initialization vector used by the DES-CBC algorithm. EncryptData writes the encrypted data to the buffer supplied by the caller and returns the length of the encrypted data.

#include “aglobal.h” #include “bsafe.h” #include “demochos.h”

#define NULL_SURRENDER_PTR ((A_SURRENDER_CTX *)NULL_PTR)

int EncryptData

(output, outputLen, maxOutputLen, input, inputLen, keyValue, iv)

unsigned char *output;

 

/* pointer to output data */

unsigned int outputLen;

 

/* pointer to length of encrypted data */

unsigned int maxOutputLen;

/* size of output buffer */

unsigned char *input;

 

/* pointer to input data buffer */

unsigned int inputLen;

 

/* length of input data */

unsigned char *keyValue;

 

/* pointer to 8-byte DES key */

unsigned char *iv;

/* pointer to 8-byte initialization vector */

{

B_ALGORITHM_OBJ desAlgorithm = (B_ALGORITHM_OBJ)NULL_PTR; B_KEY_OBJ desKey = (B_KEY_OBJ)NULL_PTR; B_BLK_CIPHER_W_FEEDBACK_PARAMS feedbackParams;

ITEM initVector; unsigned int partOutLen; int status;

/* break commands jump to the end of the do while (0) block */ do {

if ((status = B_CreateKeyObject (&desKey)) != 0) break;

if ((status = B_SetKeyInfo

(desKey, KI_DES8Strong, (POINTER)keyValue)) != 0) break;

C h a p t e r 1 I n t r o d u c t i o n

5

Page 15
Image 15
RSA Security 5 manual Code Example