Chapter 7 Public-Key Operations 303

Performing Elliptic Curve Operations
Step 5: Final
Step 6: Destroy
Destroy any objects that are no longer needed. Also, be sure to zeroize and free any allocated memory when it is no longer needed.
unsigned char *decryptedData;
unsigned int maxDecryptedDataLen;
unsigned int outputLenUpdate;
maxDecryptedDataLen = outputLenTotal; /* Use the outputLenTotal from */
/* Step 5 of ECAES encryption */
decryptedData = T_malloc(maxDecryptedDataLen);
if ((status = (decryptedData == NULL_PTR)) != 0)
break;
if ((status = B_DecryptUpdate
(ecESDecrypt, decryptedData, &outputLenUpdate,
maxDecryptedDataLen, encryptedData, outputLenTotal,
(B_ALGORITHM_OBJ)NULL_PTR,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
unsigned int outputLenFinal, outputLenTotal;
if ((status = B_DecryptFinal
(ecESDecrypt, decryptedData + outputLenUpdate,
&outputLenFinal, maxDecryptedDataLen - outputLenUpdate,
(B_ALGORITHM_OBJ)NULL_PTR,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;
outputLenTotal = outputLenUpdate + outputLenFinal;
B_DestroyAlgorithmObject (&ecESDecrypt);
B_DestroyKeyObject (&privateKey);
T_free (decryptedData);