wire / wire-format / hmac
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.
aka: HMAC (Hash-based Message Authentication Code)
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.
| field | size | meaning |
|---|---|---|
| Key K | variable | Secret key. If longer than the hash block size, hash it first. Pad to block size with zeros. |
| ipad | block size | 0x36 repeated (block size = 64 for SHA-256, 128 for SHA-512). |
| opad | block size | 0x5C repeated. |
| Inner hash | hash size | H((K XOR ipad) || message). |
| Outer hash | hash size | H((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
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/hmac
or /wire-format/hmac.json