Hash-Based Message Authentication Code

Hash-Based Message Authentication Code (HMAC)

A hash-based message authentication code (HMAC) combines a secret key with a message digest to create a message authentication code. See “Hash-Based Message Authentication Codes (HMAC)” on page 49 for a description of the algorithm.

Crypto-C provides an HMAC implementation based on SHA1. Recall that SHA1 produces a 20-byte digest and takes input in 64-byte blocks.

The example in this section corresponds to the file hmac.c.

Step 1: Creating an Algorithm Object

Declare a variable of type B_ALGORITHM_OBJ. As defined in the function prototype in Chapter 4 of the Reference Manual, its address is the argument for B_CreateAlgorithmObject:

B_ALGORITHM_OBJ HMACDigester = (B_ALGORITHM_OBJ)NULL_PTR;

if ((status = B_CreateAlgorithmObject (&HMACDigester)) != 0) break;

Step 2: Setting the Algorithm Object

There is only one AI for hash-based message authentication codes, AI_HMAC. The Reference Manual Chapter 2 entry for AI_HMAC states that the format of info supplied to B_SetAlgorithmInfo is a pointer to a B_DIGEST_SPECIFIER structure:

typedef struct { B_INFO_TYPE digestInfoType;

POINTER digestInfoParams;

}B_DIGEST_SPECIFIER;

The only choice for digestInfoType in Crypto-C is AI_SHA1. In the case of AI_SHA1, digestInfoParams should be set to NULL_PTR:

C h a p t e r 5 N o n - C r y p t o g r a p h i c O p e r a t i o n s

1 6 1

Page 183
Image 183
RSA Security 5.2.2 manual Hash-Based Message Authentication Code Hmac