Hash-Based Message Authentication Code (HMAC)

Step 5: Final

After the data to digest has been processed by calls to B_DigestUpdate, call

B_DigestFinal. You need to pass a pointer to the location where B_DigestFinal can store the output. In the case of AI_HMAC using SHA1, you need 20 bytes to store the result.

unsigned char *digestedData; unsigned int digestedDataLen;

digestedData = T_malloc (20);

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

if ((status = B_DigestFinal

(HMACDigester, digestedData, &digestedDataLen, 20, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

Step 6: Destroy

Once you have generated the message authentication code, destroy any objects you used, and free up any memory you allocated:

B_DestroyKeyObject (&HMACKey);

B_DestroyAlgorithmObject (&randomAlgorithm);

B_DestroyAlgorithmObject (&HMACDigester);

if (digestedData != NULL_PTR) { T_memset (digestedData, 0, 20); T_free (digestedData); digestedData = NULL_PTR; digestedDataLen = 0;

}

1 6 4

R S A B S A F E C r y p t o - C D e v e l o p e r ’s G u i d e

Page 186
Image 186
RSA Security 5.2.2 manual Unsigned char *digestedData unsigned int digestedDataLen