Skip to content
uencoder

HMAC (Keyed-Hash Message Authentication) Reference

Reference for HMAC construction, security properties, and usage guidelines per RFC 2104.

Construction

HMAC nests the hash function with key XOR inner/outer pad constants. The key is padded to the hash block size (or hashed first if longer). The inner hash processes the padded key and message; the outer hash processes the padded key and inner result. This construction is provably secure as long as the underlying hash is a pseudorandom function. The ipad and opad constants are 0x36 and 0x5C repeated.

ipad
Inner pad constant
0x36 repeated
opad
Outer pad constant
0x5C repeated
key padding
Zero-pad or hash
block size

Security and Usage

HMAC security is bounded by the minimum of the hash output size and half the hash output size for collision resistance. HMAC is not affected by length extension attacks unlike raw Merkle-Damgard hashes. Verification must use constant-time comparison to prevent timing attacks. HMAC is used in TLS record protection, JWT signatures, and IPsec. The hash function can be replaced without changing the HMAC interface.

security bound
min(output, output/2)
collision resistance
length extension
Immune
nested construction
constant-time
Required for verify
prevent timing

Related tools

References