61.4.2 HMAC Algorithm
The HMAC algorithm is as follows:
HMACK(m) = h((K0 ⊕ opad) || h((K0 ⊕ ipad) || m))
where:
- h = SHA function
- K0 = the key K after any necessary pre-processing to form a block size key
- m = message to authenticate
- || = concatenation operator
- ⊕ = XOR operator
- ipad = predefined constant (0x3636...3636)
- opad = predefined constant (0x5C5C...5C5C)
The SHA provides a fully optimized processing of the HMAC algorithm by executing the following operations:
- starting the SHA algorithm from any user predefined hash value, thus ‘h(K0 ⊕ ipad)’ for first HMAC hash and ‘h(K0 ⊕ opad)’ for second HMAC hash
- performing automatic padding
- routing automatically the first hash result ‘h((K0 ⊕ ipad) || m)’ to the source of the second hash processing ‘h((K0 ⊕ opad) || (first hash result))’ including the concatenation of the first hash result to ‘K0 ⊕ opad’.
To perform the HMAC operation, the ALGO field value must be greater than 7, the automatic padding feature must be enabled (MSGSIZE and BYTCNT fields differ from 0) and the SHA internal initial hash value registers 0 and 1 must be configured, respectively, with the hash results of input blocks “K0 ⊕ ipad” and “K0 ⊕ opad” (see Internal Registers for Initial Hash Value or Expected Hash Result).
The size of the message (‘m’) must be written in the MSGSIZE and BYTCNT fields.
The FIRST bit in the SHA Control register (SHA_CR) should be set before writing the first block of the message.
The SHA can process HMAC-SHA1, HMAC-SHA224, HMAC-SHA256, HMAC-SHA384, HMAC-SHA512 by configuring the SHA_MR.ALGO field.