Block Ciphers
210 RSA BSAFE Crypto-C Developers Guide
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;