HMAC constructs a message authentication code from a cryptographic hash function and a shared secret key. For a hash with input block size bytes, normalize the key to a -byte string : first hash it if it is longer than , then pad with zero bytes. The construction isHere is bytewise exclusive or, is concatenation of strings,
ipad repeats byte 0x36, and opad repeats byte 0x5c. The inner and outer keyed hashing stages are part of the construction, rather than interchangeable placements of a key beside a message.[ref]HMAC: Keyed-Hashing for Message Authentication (RFC 2104). Section2, definition of HMAC
A concrete interoperability example uses SHA-256, a member of SHA-2. Its block size is64 bytes while its full digest is32 bytes. With a key of20
0x0b bytes and the ASCII message Hi There, the hexadecimal tag is b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7.[ref]The receiver recomputes the tag using the shared key and checks the received tag. HMAC authenticates the message without concealing its contents; encryption is a separate operation. Because both parties know the key, both can make valid tags. A valid tag also remains valid when the same authenticated message is sent again, so replay handling belongs to the surrounding cryptographic protocol.
HMAC's original analysis and design are due to Mihir Bellare, Ran Canetti and Hugo Krawczyk.[ref]
Keying Hash Functions for Message Authentication by Mihir Bellare, Ran Canetti and Hugo Krawczyk. Title page and introduction, keyed hashing constructions and security analysis
New to topics? Read the docs here!