Block Ciphers

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

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

if ((status = B_EncryptUpdate

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

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

Step 5: Final

unsigned int outputLenFinal;

if ((status = B_EncryptFinal

(rc5Encrypter, encryptedData + outputLenUpdate, &outputLenFinal, dataToEncryptLen + 8 - outputLenUpdate, (B_ALGORITHM_OBJ)NULL_PTR,

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

Step 6: Destroy

Remember to destroy all objects that you created and free up any memory that you allocated.

B_DestroyKeyObject (&rc5Key);

B_DestroyAlgorithmObject (&rc5Encrypter);

B_DestroyAlgorithmObject (&randomAlgorithm); if (rc5KeyItem.data != NULL_PTR) {

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

rc5KeyItem.data = NULL_PTR; rc5KeyItem.len = 0;

}

C h a p t e r 6 S y m m e t r i c - K e y O p e r a t i o n s

1 9 5

Page 217
Image 217
RSA Security 5.2.2 manual Final