HMAC Explained

Keyed Hash-based Message Authentication Code (HMAC) in cryptographic terms is a type of message authentication code (MAC) calculated by using a cryptographic hash function along with a secret key. It may be used to simultaneously verify the data's integrity and the message's authenticity. An iterative cryptographic hash function such as MD5 or SHA-1 may be used to calculate the HMAC. When these are used, the resulting MAC algorithm is called HMAC-MD5 or HMAC-SHA-1, for instance. The cryptographic strength of the underlying hash function, along with the size and quality of the key and the size of the hash output length in bits, define the cryptographic strength of the HMAC. Figure 13-2 illustrates HMAC.

Figure 13-2 HMAC

Hash Message Authentication Code (HMAC)

Hash Message Authentication Code (HMAC)

Hash Functions Message Authentication

h = Cryptographic hash function. m = Message to be authenticated.

k = Secret key padded with extra 0's (ipad/opad) to the block size of the hash function. ipad = Inner padding. opad = Outer padding.

h = Cryptographic hash function. m = Message to be authenticated.

k = Secret key padded with extra 0's (ipad/opad) to the block size of the hash function. ipad = Inner padding. opad = Outer padding.

Iterative hash functions, such as MD5 and SHA-1, break a message into blocks of a fixed size and then iterate over them with a compression function. For instance, MD5 and SHA-1 operate on 512-bit blocks. As mentioned, the size of the HMAC output is the same as that of the underlying hash function (128 or 160 bits in the case of MD5 and SHA-1), but you can truncate this if you want to. When the hash image is truncated, the security of the MAC is reduced.

Key Topic

In 1996 Mihir Bellare, Ran Canetti, and Hugo Krawczyk wrote about the construction and analysis of HMACs. These authors also wrote RFC 2104 in 1997 and FIPS PUB 198, which generalizes and standardizes the use of HMACs. Both the IPsec and TLS protocols use HMAC-SHA-1 and HMAC-MD5.

Continue reading here: Vulnerabilities of MD5

Was this article helpful?

0 -1

Readers' Questions

  • marvin hernandez
    What is message authentication code?
    10 months ago
  • A message authentication code (MAC) is an algorithm used to provide data integrity and authentication on message exchanges. The code is applied to a data set using a symmetric key, and is used to verify that the message has not been altered by an unauthorized user. A MAC provides data integrity by calculating a hash of the message that is being sent and then attaching it to the message in the form of a code. Upon receipt, the receiver can then calculate the hash and compare it to the one that was sent to verify that it has not been altered.