HMAC
|
A keyed-hash message authentication code, or HMAC, is a type of message authentication code (MAC) calculated using a cryptographic hash function in combination with a secret key. As with any MAC, it may be used to simultaneously verify both the data integrity and the authenticity of a message. Any iterative cryptographic hash function, such as MD5 or SHA-1, may be used in the calculation of an HMAC; the resulting MAC algorithm is termed HMAC-MD5 or HMAC-SHA-1 accordingly. The cryptographic strength of the HMAC depends upon the cryptographic strength of the underlying hash function and on the size and quality of the key.
An iterative hash function breaks up a message into blocks of a fixed size (L) and iterates over them with a compression function. For MD5 or SHA-1, the block size is 512 bits, L = 512. The size of the output is the same as the underlying hash function (128 or 160 bits in the case of MD5 and SHA-1), although it can be truncated if desired.
HMAC is defined as
- <math>HMAC_K(m) = h((K \oplus opad) \;||\; h((K \oplus ipad) \;||\; m)),<math>
where h is an iterated hash function, K is a secret key padded to length L with extra zeros, and m the input text. "||" denotes concatenation, and "⊕" denotes exclusive or. The two constants ipad and opad, each of length L bits, are defined as ipad = 0x363636...3636 and opad = 0x5c5c5c...5c5c; that is, if L=512, ipad and opad are 64 repetitions of the bytes 0x36 and 0x5c respectively, represented in hexadecimal.
The construction and analysis of HMACs was first published in 1996 by Mihir Bellare, Ran Canetti, and Hugo Krawczyk, who also wrote RFC 2104. FIPS PUB 198 generalizes and standardizes the use of HMACs. HMAC-SHA-1 and HMAC-MD5 are used within the IPsec and TLS protocols.
External links
- RFC 2104, HMAC: Keyed-Hashing for Message Authentication
- RFC 2202, HMAC-MD5 and HMAC-SHA1 Test Vectors, HMAC-SHA1 implementation in C
- FIPS PUB 198, The Keyed-Hash Message Authentication Code (http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf)
- HMAC Algorithm in Detail (http://www.cryptostuff.com/crypto/index.php?title=hmac)
References
- Mihir Bellare, Ran Canetti and Hugo Krawczyk, Keying Hash Functions for Message Authentication, CRYPTO 1996, pp1–15 (PS or PDF) (http://www-cse.ucsd.edu/users/mihir/papers/hmac.html#kmd5-paper).
- Mihir Bellare, Ran Canetti and Hugo Krawczyk, Message authentication using hash functions: The HMAC construction, CryptoBytes 2(1), Spring 1996 (PS or PDF) (http://www-cse.ucsd.edu/users/mihir/papers/hmac.html#hmac-cryptobytes).