Block Ciphers
204 RSA BSAFE Crypto-C Developers Guide
To call B_EncryptInit, we also need an algorithm chooser. The Reference Manual
entry for AI_AES_CBCPad gives us the AMs necessary. Because you will use this
chooser for decryption also, you should also include those AMs:
Once you have passed in the key data and created the chooser, you are ready to make
the call to B_EncryptInit:
Step 4: Update
Enter the data to encrypt through B_EncryptUpdate. From the Reference Manual
Chapter 2 entry on AI_AES_CBCPad you learn that you may pass
(B_ALGORITHM_OBJ)NULL_PTR for all
randomAlgorithm
arguments. Assuming you have
some input, call B_EncryptUpdate.
Remember that the AES cipher is a block cipher. The current version requires input
that is a multiple of sixteen bytes. Because you are using AI_AES_CBCPad, Crypto-C
will pad to make the input a multiple of sixteen bytes. That means that the output
buffer should be at least sixteen bytes larger than the input length.
The AES cipher is a fast algorithm, so it is reasonable to pass a properly cast NULL_PTR
for the surrender context:
if (aesKeyItem.data != NULL_PTR) {
T_memset (aesKeyItem.data, 0, aesKeyItem.len);
T_free (aesKeyItem.data);
aesKeyItem.data = NULL_PTR;
aesKeyItem.len = 0;
}
B_ALGORITHM_METHOD *AES_CHOOSER[] = {
&AM_AES_CBC_ENCRYPT,
&AM_AES_CBC_DECRYPT,
(B_ALGORITHM_METHOD *)NULL_PTR
};
if ((status = B_EncryptInit (aesEncrypter, aesKey, AES_CHOOSER,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;