All lessons Leer en español

Foundations · Unit 15 · Lesson 1 of 2

Hashes, MACs, and signatures

Choose the evidence needed to check a file, a shared-secret message, or a public announcement.

7 minready

Helpful before thisCryptography

After this lesson you can

  • Explain why a hash comparison needs a trusted reference.
  • Distinguish shared-key message authentication from public verification.
  • Separate a valid cryptographic check from confidentiality, freshness, and truth.

A fictional museum publishes a new opening-hours notice. A visitor wants to know whether the file changed, whether it came from the museum, and whether the hours are correct. Those sound like one question, but different evidence answers each part. Hashes, message authentication codes, and digital signatures are useful because their guarantees are specific.

Hashes, MACs, and signaturesThree different checks need different trust: a trusted digest, a shared secret, or a trusted signing public key. These are alternatives for different purposes, not sequential encryption steps.Hash comparisonTrust the reference digestMAC verificationTrust the shared secretSignature verificationTrust the public-key binding
Three different checks need different trust: a trusted digest, a shared secret, or a trusted signing public key. These are alternatives for different purposes, not sequential encryption steps.

A digest helps compare content

A cryptographic hash maps a message to a fixed-length digest for that algorithm. The same exact input gives the same digest. A suitable modern hash makes it computationally difficult to find particular kinds of matching inputs, but its finite output does not mean collisions are mathematically impossible.

If you compare a downloaded notice with an independently trusted digest, a match provides evidence that the content agrees with that reference, under the algorithm’s security assumptions. A different digest indicates different input. The comparison does not explain which version is correct.

An unknown website supplying both the file and its digest has supplied two mutually consistent objects, not independent evidence of museum authorship. Hashing also does not encrypt the notice. Someone can guess a short input, hash that guess, and compare it; the term “one-way” does not turn predictable information into a secret.

A MAC adds a shared secret

A message authentication code, or MAC, uses a secret key to generate and verify a tag over a message. HMAC is a standardized construction based on a cryptographic hash. With a suitable key, algorithm, and implementation, the check can detect unauthorized alteration and support authentication among parties sharing that key.

Suppose the museum’s scheduling and display teams share one MAC key. Each can verify a tagged notice, but each can also create a valid tag. A third party cannot infer which team authored a message merely because the shared-key check succeeds. That is a meaningful limit, not a defect in the mechanism.

A signature separates creating from checking

A digital signature uses a signing private key and a corresponding verification public key. The museum can keep its signing key private while distributing a public key for visitors to verify notices. The verifier still needs a trustworthy association between that public key and the museum. Accepting a replacement key from the same untrusted message does not establish that association.

A valid signature supports integrity and source authentication under those assumptions. It does not hide the notice, prove the signer made no mistake, or establish that an old notice is still current. Protecting signing keys, checking applicable validity information, and managing changes remain part of the design.

PredictA visitor verifies a genuine museum signature on last winter’s timetable. Does it prove the museum closes at that time today?

No. The signature can authenticate that particular timetable. The visitor also needs its effective dates and any replacement notice. Authenticity and current applicability are different claims.

Ask what the check actually proves

For each design, name the content, the trusted reference or key, and the intended claim. If confidentiality is needed, add suitable encryption. If replay or outdated information matters, the surrounding protocol needs freshness rules. If the announcement itself might be mistaken, factual review remains necessary. Cryptographic evidence becomes useful when its scope is understood.

Check yourself

No timer. No penalties. Read the explanation and try again whenever you like.

  1. A file and matching digest come from one unknown website. What has the comparison established?

    Show the answer

    Correct answer: The file agrees with that supplied digest, not an independently trusted source. A trustworthy reference is needed to connect the comparison to the intended file.

  2. Two departments share a MAC key. A tag verifies. Can that alone distinguish the author?

    Show the answer

    Correct answer: No; either department can generate a valid tag. Shared-key verifiers also possess the secret needed to create tags.

  3. A signed timetable verifies with the museum’s trusted key. What still needs checking?

    Show the answer

    Correct answer: Whether its effective dates and claims fit today’s question. Authentic content can be outdated or mistaken.

  4. Visitors should verify notices without gaining the ability to sign new ones. Which design fits?

    Show the answer

    Correct answer: Keep the signing key private and distribute its authenticated public key. Signature verification can be public while creation remains restricted.

Try it

  • WriteInvent a museum announcement and three evidence cards: a hash from the same unknown source, a MAC shared by two departments, and a signature checked with a trusted public key. On paper, write what each establishes and one question it leaves unanswered. Do not calculate anything or use real keys.
References