Normalize a key to the hash block size
02The hash block length B and digest length L are different. A long key is hashed first; a short normalized key is padded with zero bytes.
After hashing the long key, append32 zero bytes to form a64-byte K0. The resulting block still needs secret protection.
Source for this drawing: RFC 2104 · Read RFC section 2 ↗
New to this? Start hereA quick picture + helpful background
A seal answers a specific question.
A certificate or signature supports particular checks about a key or message. It does not automatically prove that every claim or sender is trustworthy.
Helpful first, if these ideas are unfamiliar
These pictures are analogies to help you learn. The linked RFC explains the actual rules.
Terms in this drawing
Related RFCs and changes
“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.
Hash a key only when it is longer than B, then pad the result to exactly B bytes.
- B is the underlying hash compression-block length in bytes; L is its digest length. The generic construction does not require B=L. Our SHA-256 example has B=64 and L=32; RFC 4231 §§4.2,4.4,4.7 provide the corresponding SHA-256 examples. These are chosen parameters, not values for every hash.
- If the original key is longer than B bytes, first hash it with H and use that L-byte result as the effective key. Otherwise use the original key unchanged. Then append zero bytes to make a B-byte normalized key block, called K0 in this guide (§2). K0 is explanatory notation, not an extra transmitted field.
- The public 20-byte test key needs44zero bytes to fill B=64. An illustrative64-byte key needs no initial key hash and no appended zero bytes. The equality boundary matters: a key of exactly B bytes is not hashed first.
- RFC 4231 §4.7 uses131 bytes of aa as the public long-key test. For SHA-256, hash all 131 bytes to32 bytes, then append32 zero bytes. Hashing the first 64 bytes only, cutting the key off, or hashing every short key would change the algorithm.
- Held for Document Update erratum4809 proposes forbidding long keys. It is not a verified correction; the published long-key normalization remains the algorithm. The normalized long-key digest is effective secret key material, not a safe public fingerprint. Neither a public test key nor a human password is a recommended source of HMAC key entropy (§§2–3).
Selected construction rules and public test data; not a cryptographic library, key exchange, authentication protocol or deployment certification.
Read the RFC section ↗