wire / wire-format / hmac

HMAC (Hash-based Message Authentication Code)

HMAC (RFC 2104) authenticates a message using a hash function and a secret key. HMAC(K, m) = H((K' XOR opad) || H((K' XOR ipad) || m)), where K' is the key padded to the hash's block size (with zeros or hashed if too long), ipad = 0x36 repeated, opad = 0x5C repeated.

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: HMAC (Hash-based Message Authentication Code)

wire format

spec: RFC 2104 / RFC 2202

HMAC (RFC 2104) authenticates a message using a hash function and a secret key. HMAC(K, m) = H((K' XOR opad) || H((K' XOR ipad) || m)), where K' is the key padded to the hash's block size (with zeros or hashed if too long), ipad = 0x36 repeated, opad = 0x5C repeated.

fieldsizemeaning
Key KvariableSecret key. If longer than the hash block size, hash it first. Pad to block size with zeros.
ipadblock size0x36 repeated (block size = 64 for SHA-256, 128 for SHA-512).
opadblock size0x5C repeated.
Inner hashhash sizeH((K XOR ipad) || message).
Outer hashhash sizeH((K XOR opad) || inner_hash). This is the MAC.

example:

36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36

HMAC-SHA256 ipad (0x36 repeated 64 times) before key XOR


provenance

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/hmac or /wire-format/hmac.json