Block Ciphers

if (aesKeyItem.data != NULL_PTR) {

T_memset (aesKeyItem.data, 0, aesKeyItem.len); T_free (aesKeyItem.data);

aesKeyItem.data = NULL_PTR; aesKeyItem.len = 0;

}

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:

B_ALGORITHM_METHOD *AES_CHOOSER[] = { &AM_AES_CBC_ENCRYPT, &AM_AES_CBC_DECRYPT, (B_ALGORITHM_METHOD *)NULL_PTR

};

Once you have passed in the key data and created the chooser, you are ready to make the call to B_EncryptInit:

if ((status = B_EncryptInit (aesEncrypter, aesKey, AES_CHOOSER, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

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:

2 0 4

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 226
Image 226
RSA Security 5.2.2 manual Update, If aesKeyItem.data != Nullptr