Chapter 6 Symmetric-Key Operations 195

Block Ciphers
Step 5: Final
Step 6: Destroy
Remember to destroy all objects that you created and free up any memory that you allocated.
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;
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;
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;
}