Blockchain & Cryptocurrency Glossary

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • search-icon Clear Definitions
  • search-icon Practical
  • search-icon Technical
  • search-icon Related Terms

Hash-based Message Authentication Code

1 min read
Pronunciation
[hash-beyst mes-ij aw-then-ti-key-shuhn kohd]
Analogy
Imagine using a very secure food blender (the hash function). To create an HMAC, you first mix your secret key with the message ingredients, blend it, then mix the secret key again with that result and blend it once more. The final, unique texture (the HMAC tag) can only be reproduced by someone who knows your exact secret key and uses the same blender and recipe.
Definition
A specific type of Message Authentication Code (MAC) that uses a cryptographic hash function (like SHA-256) in combination with a secret cryptographic key.
Key Points Intro
HMAC is a widely used and secure method for message authentication.
Key Points

Combines a cryptographic hash function with a secret key.

Resistant to many common attacks against simpler MAC constructions.

Standardized in RFC 2104 and FIPS PUB 198.

Commonly used in protocols like TLS/SSL, IPsec, and JSON Web Tokens (JWT).

Example
When you make an API request to a secure service, the request might include an HMAC. The service, possessing the same secret key, recalculates the HMAC on the received request. If the HMACs match, the service processes the request, assured of its authenticity and integrity.
Technical Deep Dive
The HMAC construction, as defined in RFC 2104, typically involves two nested hashes. The secret key is first padded (if necessary) and XORed with an inner padding constant (ipad), and this result is prepended to the message. The hash of this combined string is calculated. Then, the original (padded) key is XORed with an outer padding constant (opad), and this is prepended to the previously calculated hash result. The final hash of this second combined string is the HMAC tag. This double-hashing process provides strong security properties, even when the underlying hash function might have certain vulnerabilities.
Security Warning
The security of HMAC relies on the strength of the underlying hash function and the secrecy and randomness of the key. A compromised key will allow an attacker to forge HMACs. Keys should be of sufficient length (ideally, the same size as the hash output).

Hash-based Message Authentication Code - Related Articles

No related articles for this term.