Check a message with a shared secret
01Two parties holding the same secret can calculate a tag for the exact message bytes. The tag authenticates data without hiding it.
The received message changes while its supplied tag does not. The calculated comparison fails and the arrow stops at validation.
Source for this drawing: RFC 2104 · Read RFC section 1 ↗
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.
A valid MAC is a shared-key integrity check, not encryption or a public digital signature.
- HMAC is a hash-based message authentication code (MAC). A MAC is a check value, or tag, calculated with a secret key. A cryptographic hash compresses input bytes to a fixed-size digest; HMAC combines a hash with a shared key using the specific construction in §2. An unkeyed checksum does not serve the same purpose (§1).
- The sender and receiver use the same chosen hash and secret K. The sender sends message bytes and a tag; the receiver calculates the tag for the bytes it received and checks it. The drawing illustrates that use of a MAC, not a wire format or an application authorization decision (§§1,6).
- All numerical examples use public test keys. The main example is RFC 4231 §4.2: HMAC-SHA-256, key byte 0b repeated 20 times and the eight ASCII bytes "Hi There" (without a trailing NUL). Its full 32-byte tag in four hexadecimal groups is b0344c61d8db3853 5ca8afceaf0bf12b 881dc200c9833da7 26e9376c2e32cff7. A displayed tag prefix followed by … is only a preview, not an actual shortened tag.
- In the changed-message example, "Hi There!" is nine bytes but carries the original tag. Recomputing with the same key produces a different tag, so this chosen comparison fails before message acceptance. This is a computed example, not proof that all distinct messages have distinct tags.
- The message remains readable. Both key holders can generate valid tags; this is not a public digital signature or proof to a third party of which holder sent the message. HMAC itself supplies neither a packet format nor freshness, replay prevention, secret exchange or key storage. Algorithm and protocol security depend on their surrounding design (§§1,3,6).
Selected construction rules and public test data; not a cryptographic library, key exchange, authentication protocol or deployment certification.
Read the RFC section ↗