What is a MAC/HMAC?
A Message Authentication Code (MAC/HMAC), told as a story about a confirmation seal stamped with a secret mold only the sender and receiver hold.
The sender stamped the note with just a fingerprint (a hash).A fingerprint shows the content didn't change — but not who sent it.
Anyone can simply re-stamp the fingerprint.A fingerprint needs no secret to compute — so whoever changes the content can make a matching one too.
MAC/HMAC is a confirmation seal stamped with a secret mold.Without the mold (the secret key), nobody can stamp a matching seal. → think of it as a fingerprint with a secret added in.
A fingerprint, a secret seal, and a sealed letter, side by side.A fingerprint, a secret seal, and a sealed letter each keep a different promise — none stands in for another.
The mold must be shared in advance, and the seal can't stop a sender denying it later.The key-distribution problem remains, and if you need proof a third party can verify (non-repudiation), use the badge with the king's seal (a digital signature) instead.
MAC/HMAC = a confirmation seal stamped on a message using a secret mold that only the sender and receiver hold. Without the mold nobody can stamp it, so it proves both it's unchanged and who really sent it.
A Message Authentication Code (MAC) uses the message and a shared secret key to produce a tag (HMAC does it with a hash function, CMAC with a block cipher); only a receiver holding the same key can recompute and verify the same tag. A keyless hash (a fingerprint) catches accidental changes but can't stop a deliberate edit, while a MAC protects both integrity and sender authentication. It still requires the key to be shared beforehand, though, and it doesn't provide non-repudiation — that's the job of a public-key digital signature (PKI).
When grown-ups say it
- Message Authentication Code
- A confirmation seal stamped with a secret mold. A tag made from the message combined with a shared secret key.
- HMAC
- A secret seal built out of a hash. The most common way to build a MAC, using a hash function.
- Hash (fingerprint)
- Anyone can compute it, no secret needed. It catches accidental changes, but a deliberate editor can simply recompute it. → a fingerprint on everything
- Integrity
- No tampering, in secret. Both a hash and a MAC protect this. → three things to keep
- Sender authentication
- Whether it really came from them. Proven because only the mold's holder can stamp a matching seal.
- Key-distribution problem
- The homework of sharing the mold beforehand. The remaining problem MAC/HMAC doesn't solve.
- Non-repudiation
- Ruling out claiming you never sent it. A MAC can't do this — the king's seal (a signature) can. → the badge with the king's seal
- TLS
- The promise behind a sealed back-and-forth letter. In practice it runs both a seal (encryption) and a secret stamp (a MAC) together. → the sealed promise with the shop