Block Ciphers

Step 4: Update

Enter the data to encrypt through B_EncryptUpdate. The Reference Manual Chapter 2 entry on AI_MD5WithRC2_CBCPad states that you can pass (B_ALGORITHM_OBJ)NULL_PTR for all randomAlgorithm arguments. Assuming you have some input data, call B_EncryptUpdate. Remember that the RC2 cipher is a block cipher and requires the input to be a multiple of eight bytes. But because you are using AI_MD5WithRC2_CBCPad, Crypto-C will pad to make the input a multiple of eight bytes. That means, though, that the output buffer should be at least eight bytes larger than the input length.

PBE with MD5 and the RC2 cipher is a fast algorithm, so for small amounts of data, you can pass a properly cast NULL_PTR for the surrender context. If you want to pass a surrender context, you can:

/* Assume dataToEncrypt points to already set data and dataToEncryptLen has been set to the number of bytes in dataToEncrypt. */

#define BLOCK_LEN 8

unsigned char *dataToEncrypt;

unsigned char *encryptedData = NULL_PTR; unsigned int dataToEncryptLen; unsigned int encryptedDataLen; unsigned int outputLenUpdate;

encryptedDataLen = dataToEncryptLen + BLOCK_LEN; encryptedData = T_malloc (encryptedDataLen);

if ((status = (encryptedData == NULL_PTR)) != 0) break;

if ((status = B_EncryptUpdate

(pbEncrypter, encryptedData, &outputLenUpdate, encryptedDataLen, dataToEncrypt, dataToEncryptLen, (B_ALGORITHM_OBJ)NULL_PTR,

(A_SURRENDER_CTX *)NULL_PTR)) != 0) break;

2 1 0

R S A B S A F E C r y p t o - C D e v e l o p e r ’s G u i d e

Page 232
Image 232
RSA Security 5.2.2 manual Update