Block Ciphers

unsigned char *dataToEncrypt = (unsigned char *)"Encrypt this sentence."; unsigned int dataToEncryptLen;

unsigned char *encryptedData = NULL_PTR;

unsigned int outputLenUpdate, outputLenFinal, outputLenTotal; unsigned int encryptedDataLen;

dataToEncryptLen = T_strlen ((char *)dataToEncrypt) + 1;

RSA_PrintBuf ("Data To Encrypt", dataToEncrypt, dataToEncryptLen);

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

if ((status = (encryptedData == NULL_PTR)) != 0) { status = RSA_DEMO_E_ALLOC;

break;

}

if ((status = B_EncryptUpdate

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

(A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

Step 5: Final

if ((status = B_EncryptFinal

(aesEncrypter, encryptedData + outputLenUpdate, &outputLenFinal, encryptedDataLen - outputLenUpdate, (B_ALGORITHM_OBJ)NULL_PTR,

(A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

outputLenTotal = outputLenUpdate + outputLenFinal;

Step 6: Destroy

Remember to destroy any objects that you created and to free up any memory that has been allocated:

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

2 0 5

Page 227
Image 227
RSA Security 5.2.2 manual Final