Performing Elliptic Curve Operations

unsigned int maxEncryptedDataLen; unsigned int outputLenUpdate;

maxEncryptedDataLen = 21 + (2 * fieldElementLen) + dataToEncryptLen; encryptedData = T_malloc(maxEncryptedDataLen);

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

if ((status = B_EncryptUpdate

(ecESEncrypt, encryptedData, &outputLenUpdate, maxEncryptedDataLen, dataToEncrypt, dataToEncryptLen, (B_ALGORITHM_OBJ)NULL_PTR,

(A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

Step 5: Final

unsigned int outputLenFinal, outputLenTotal;

if ((status = B_EncryptFinal

(ecESEncrypt, encryptedData + outputLenUpdate, &outputLenFinal, maxEncryptedDataLen - outputLenUpdate, randomAlgorithm, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

outputLenTotal = outputLenUpdate + outputLenFinal;

Step 6: Destroy

Destroy all objects that are no longer needed. Also, be sure to zeroize and free any allocated memory when it is no longer needed.

B_DestroyAlgorithmObject (&ecESEncrypt);

B_DestroyKeyObject (&publicKey);

T_free (encryptedData);

C h a p t e r 7 P u b l i c - K e y O p e r a t i o n s

3 0 1

Page 323
Image 323
RSA Security 5.2.2 manual Final