Encryption, from the ground up · Puzzle 6 · 7 of 9
A hash with a secret
Puzzle 5 showed a fingerprint anyone can recompute, so an attacker who changes the data just sends a new fingerprint. Add a key that only the two sides have, and the fingerprint becomes something only they can make.
The problem
Puzzle 5's hash catches accidental changes. But an attacker who changes the data can hash the changed data and send that digest instead. If both sides already share a secret key (puzzle 3 got them one), can they make a fingerprint the attacker can't forge?
See it
The sender computes a MAC from the message and the shared key, and attaches it as a tag.
Step 1 of 4The receiver has the same key: it recomputes the MAC and compares. Equal: unchanged.
Step 2 of 4An attacker changes the amount, but has no key. Predict: can it make a matching tag?
Step 3 of 4No: the receiver's tag won't match, and the message is rejected. HMAC is the usual recipe.
Step 4 of 4
The building block
A MAC, message authentication code, is a short value computed from two inputs: the data and a secret key. The most common way to build one is HMAC: it runs a hash function like SHA-256 over the data mixed with the key, in a fixed recipe.
How it's used:
- The sender computes the MAC of the data with the shared key and attaches it: the tag.
- The receiver, who has the same key, computes the MAC of the data it received and compares it with the tag.
- Equal: the data is unchanged and came from someone with the key. Different: reject it.
An attacker who changes the data would need a new tag that matches, and making one needs the key. Without it, there's no known way.
Compare the tools so far: a hash anyone can compute; a MAC only key holders can compute. And both sides hold the same key, so a MAC proves "one of us made this", not which one: proving who, to anyone, needs puzzle 7.
The analogy
A wax seal pressed with a ring that only you and your friend own. Anyone can melt the seal and change the letter, but without the ring they can't press a new seal that looks right.
Check yourself
Sources
- RFC 2104, HMAC ("This document describes HMAC, a mechanism for message authentication using cryptographic hash functions")
What you now know
A MAC (message authentication code) is a short value computed from the data and a secret key together; HMAC builds one from a hash function. The sender attaches it as a tag; the receiver, who has the same key, recomputes it and compares. An attacker who changes the data can't compute the matching tag without the key, so any change is caught. TLS protects every chunk of your data this way.
Answer every question above correctly to unlock the next puzzle.
Something wrong or unclear on this page? Tell me: a puzzle that didn't click is a bug in the puzzle.