NEW
Also known as: Hash-based Message Authentication Code
A message authentication code built from a cryptographic hash function and a secret key, providing integrity and authenticity.
DESCRIPTION
HMAC wraps a cryptographic hash function (e.g., SHA-256) in a keyed construction using inner and outer paddings to produce a MAC. It maintains security even if the underlying hash has certain weaknesses, provided the compression function remains sound. HMAC is widely deployed in TLS, OAuth-style API signing, and secure storage. Key separation and correct parameter choices are essential. Its simplicity, provable security bounds, and broad support make HMAC a default integrity mechanism.
ALTERNATIVE DEFINITIONS
IETF RFC 2104
HMAC is a mechanism for message authentication using cryptographic hash functions.
Canonical definition describing HMAC as a keyed-hash mechanism.
NIST SP 800-107 Revision 1
HMAC is a specific construction for calculating a message authentication code (MAC) involving a cryptographic hash function in combination with a secret key.
Formal NIST recommendation highlighting construction specifics.
RELATED TERMS
MAC SHA-256 SHA-3 Keyed Hash Password-Based Key Derivation Function 2 TLS API Authentication Key Derivation Function
COMPETING TERMS
KNOWLEDGE AREAS
Data Security Software Engineering Testing & Validation
TARGET AUDIENCE
Cybersecurity Engineer Security Architect Software Developer MLOps Engineer IT Auditor
EXTERNAL SOURCES
- Wikipedia - HMAC
- IETF RFC 4868 - HMAC-SHA2 for IPsec specification
- IETF - HMAC test cases and conformance
- OAuth - API signing with HMAC in OAuth 1.0
TOP QUESTIONS
Why is HMAC widely used?
It is simple, efficient, widely standardized, and has strong security proofs under standard hash assumptions.
Category: Relevancy
Which hash functions are recommended for HMAC?
Use SHA-256, SHA-384, SHA-512, or SHA-3 variants depending on performance and footprint needs.
Category: Recommendation
Does HMAC protect against replay attacks?
Only if you include nonces, timestamps, or sequence numbers in the data covered by HMAC.
Category: Risk
How long should HMAC keys be?
At least as long as the hash output; 256 bits is common for SHA-256 HMAC.
Category: Requirements
Is HMAC affected by length extension attacks?
No. HMAC’s construction prevents classic Merkle–Damgård length extension vulnerabilities.
Category: Security
Can I truncate HMAC tags?
Yes, but ensure sufficient tag length (e.g., 128 bits) for the threat model and collision resistance.
Category: Best practices
How is HMAC used in API authentication?
Clients sign canonical request data with HMAC; servers recompute and verify to authenticate and ensure integrity.
Category: Example
Should I reuse keys between HMAC and encryption?
No. Derive separate keys via a KDF for MAC and encryption to avoid cross-protocol risks.
Category: Mistakes
How to validate HMAC implementations?
Use official test vectors (e.g., RFC 4231) and constant-time comparisons for tag verification.
Category: Testing