What is the Difference Between MAC and HMAC

December 2022 · 3 minute read

The main difference between MAC and HMAC is that MAC is a tag or a piece of information that helps to authenticate a message, while HMAC is a special type of MAC with a cryptographic hash function and a secret cryptographic key.

Cryptography is the process of sending data securely from the source to the destination. It helps to avoid unauthorized parties from accessing confidential data. Cryptography involves two main functionalities as encryption and decryption. Encryption refers to converting the message to an unrecognizable format at the sender’s end. On the other hand, decryption refers to converting the unrecognizable message to a recognizable message. Furthermore, MAC and HMAC are two codes used in cryptography to pass the messages.

Key Areas Covered

1. What is MAC
      -Definition, Functionality
2. What is HMAC
     -Definition, Functionality
3. Difference Between MAC and HMAC
     -Comparison of key differences

Key Terms

Cryptography, HMAC, MAC

Difference Between MAC and HMAC - Comparison Summary

What is MAC

MAC stands for Message Authentication Code. It is a small piece of information that helps to authenticate a message. Moreover, it ensures that the message came from the stated sender. The MAC value protects both a message’s data integrity as well as its authenticity. It helps to figure out any changes to the message content.

Difference Between MAC and HMAC

MAC consists of three algorithms. First, there is a key generation algorithm that selects a key from the keyspace uniformly at random. There is also a signing algorithm that returns a tag given the key and message. Finally, there is a verifying algorithm that helps to authenticate a message that is given the key and the tag. Generally, MAC functions are similar to cryptographic hash functions. These functions have various security requirements.

What is HMAC

HMAC stands for hash-based message authentication code. It is a specific type of MAC. It contains cryptographic hash functions and a secret cryptographic key. HMAC is capable of verifying data integrity and authentication of a message at the same time. Generally, the cryptographic strength of HMAC depends on the cryptographic strength of the underlying hash function, size of the hash output and the size and quality of the key.

HMAC uses two passes of has computation. The secret key helps to find the inner and outer keys. In other words, the first pass of the algorithm generates an internal hash derived from the message and the inner key. Furthermore, the second pass generates the final HMAC code obtained from the inner hash result and the outer key. Overall, the algorithm is capable of providing immunity against length extension attacks.

Difference Between MAC and HMAC

Definition

MAC is a short piece of information used to authenticate a message. In contrast, HMAC is a specific type of MAC that involves a cryptographic hash function and a secret cryptographic key.

Long form

While MAC stands for Message Authentication Code, HMAC stands for Hash based Message Authentication Code.

Conclusion

In brief, HMAC is a type of MAC. The main difference between MAC and HMAC is that MAC is a tag or a piece of information that helps to authenticate a message while HMAC is a special type of MAC with a cryptographic hash function and a secret cryptographic key.

References:

1.“Message Authentication Code.” Wikipedia, Wikimedia Foundation, 7 July 2019, Available here.
2.“HMAC.” Wikipedia, Wikimedia Foundation, 26 June 2019, Available here.

Image Courtesy:

1.”18657246306″ By Blue Coat Photos (CC BY-SA 2.0) via Flickr

ncG1vNJzZmiolZm2oq2NnKamZ6edrrV5yKxkraCVYrGqssWeqZ6mk5p6o7HTsJyepl2irqR5wKebZqCdlrBw