Seyed Masoud Hosseini · Overview · Study log · Weekly summaries · Ideas · Search · Transcript · RSS feed
Design & Analysis of Algorithms · Lecture 30 of 34 · 1:22:00
21. Cryptography: Hash Functions
Study guide
What this lecture covers
This lecture asks what makes a hash function useful for security rather than for building a dictionary. Where earlier lectures treated hash functions as a way to spread keys across a table quickly, here the goal is the opposite: functions that are deliberately expensive to invert and that make collisions computationally impossible to find. The lecture introduces the "random oracle" as an ideal model, then works through the concrete properties - one-wayness, collision resistance, target collision resistance, and non-malleability - that real hash functions like SHA try to approximate.
The lecture sits at the start of a two-lecture unit on cryptography (the next covers encryption) inside MIT's algorithms course. After watching, you should be able to name which property a given security scheme depends on, and reason about which properties do or don't imply each other.
Key ideas
- Cryptographic hash function: maps an arbitrary-length string to a fixed-length output (
Dbits) and must be deterministic, public (no secret keys), and behave randomly. - Random oracle: an idealized hash function modeled as an infinite lookup table filled with true random answers, consistent on repeated queries; it clarifies why the real properties below are hard to achieve but cannot itself be built.
- One-wayness (OW / pre-image resistance): given a hash output
Y, it's infeasible to find any inputXwithH(X) = Y. - Collision resistance (CR): infeasible to find any two distinct inputs that hash to the same output.
- Target collision resistance (TCR): a weaker property - given a specific
X, it's infeasible to find a differentX'with the same hash; CR implies TCR but not the other way around. - Non-malleability (NM): given
H(X), it should be infeasible to produceH(X')for a relatedX'(e.g.X' = X + 1) without knowingX. - Property independence: the lecture builds explicit counterexamples showing one-wayness does not imply TCR, and TCR does not imply one-wayness - the properties must be checked separately for each application.
Walkthrough
Defining the hash function and the random oracle (2:01)
The lecture sets up the definition: arbitrary-length input, fixed-length output of D bits, computed deterministically and publicly, with output that should look random. Because outputs are far too large to store as a table (on the order of 160 or 256 bits), these functions can't be dictionaries the way earlier hash functions were; they're used purely to compute a digest. The random oracle is introduced as an infinite "book" that answers each new query with a fresh random string and repeats old answers for repeated queries - a model that is deterministic and random by construction but impossible to implement, since it requires infinite storage.
One-wayness, collision resistance, and TCR (16:11)
The lecture defines the core properties one at a time. One-wayness means no one can recover an input from an output. Simple hash functions used for dictionaries, such as x mod p, fail badly here because inverting them is trivial. Collision resistance (CR) forbids finding any colliding pair; target collision resistance (TCR) only forbids finding a collision for a specific given input, making it a strictly weaker requirement. Real deployed functions mentioned include MD4 and MD5 (by Ron Rivest, since broken), SHA-1, and the current SHA-3, with the point that achieving these properties requires many rounds of mixing, unlike constant-time dictionary hashes.
Proving the properties are independent (34:24)
Using constructed examples, the lecture shows CR implies TCR but TCR does not imply CR. It then builds a hash function H' that XORs two extra input bits together before feeding them into a one-way H: this H' stays one-way but has trivial target collisions, showing one-wayness does not imply TCR. A second construction - passing short inputs straight through unhashed while hashing longer ones normally - stays TCR but is not one-way, showing the reverse direction fails too.
Password storage (52:38)
The first application: systems store H(password) instead of the password itself, and compare H(entered password) against it at login. This only requires one-wayness, assuming the password has enough entropy that it can't just be enumerated; the lecture argues that requiring collision resistance here would be over-engineering, since a false-positive collision on a random guess is already vanishingly unlikely and login-attempt limits handle the risk.
File modification detection and digital signatures (57:47)
Storing H(F) securely for a file F lets you detect later tampering by recomputing the hash; this requires TCR, since an adversary is handed a specific file and must find a different one with the same hash. The lecture then turns to digital signatures, where a large message M is hashed before signing for efficiency. Signing H(M) instead of M still needs TCR: an adversary who sees a signed H(M) must not be able to find a different M' with the same hash, since that would let them attach Alice's real signature to fake content.
Commitments and sealed-bid auctions (1:10:11)
The final and most demanding example: Alice submits C(X) = H(X) as a sealed bid, then later opens it to reveal X. This needs one-wayness (so other bidders can't learn X from the sealed commitment), collision resistance (so Alice can't find two bids that hash the same and pick whichever is convenient after seeing others' bids), and non-malleability (so no one can derive C(X+1) from C(X) without knowing X). The lecture closes with a contrived counterexample - a hash that satisfies all three named properties but still leaks the most significant bit of the bid - to show that the formal properties, while necessary, are not always sufficient in practice.
Before you watch
- Be comfortable with basic hash function ideas (collisions, hash tables) from earlier lectures in this course, since this lecture explicitly contrasts them with cryptographic hash functions.
- Some familiarity with modular arithmetic helps follow the
x mod pandx^2 mod pexamples used to illustrate broken one-wayness.
Check your understanding
- Why can't the random oracle be implemented in practice, even though it satisfies all the desired properties?
- Give an example (from the lecture or your own) of a hash function that is one-way but not target collision resistant.
- Why does password storage only require one-wayness, while file-tamper detection requires target collision resistance?
- Why does a sealed-bid auction commitment scheme need non-malleability in addition to one-wayness and collision resistance?
Vocabulary
- cryptography (noun)
- The study of methods for keeping information secret or verified.
This lecture starts a two-lecture unit on cryptography. - hash function (noun)
- A function that turns input of any length into a fixed-length output.
A cryptographic hash function should behave unpredictably. - digest (noun)
- The fixed-length output produced by a hash function.
The hash function computes a short digest of the input file. - invert (verb)
- To reverse a process and recover the original input from its output.
A good hash function should be hard to invert. - collision (noun)
- A case where two different inputs produce the same hash output.
Finding a collision should be computationally infeasible. - infeasible (adjective)
- So difficult that it cannot practically be done, even with a lot of computing power.
Recovering the password from its hash should be infeasible. - random oracle (noun)
- An idealized imaginary hash function that always gives a fresh random answer to a new question.
The random oracle clarifies what an ideal hash function would do. - one-wayness (noun)
- The property that it is very hard to find the input that produced a given output.
One-wayness protects stored passwords from being reversed. - pre-image (noun)
- An input value that produces a specific output when passed through a function.
Finding a pre-image of the hash output should be infeasible. - collision resistance (noun)
- The property that it is very hard to find any two inputs with the same output.
Digital signatures depend on collision resistance. - target collision resistance (noun)
- The property that, given one specific input, it is hard to find a different input with the same hash.
File tamper detection only needs target collision resistance. - non-malleability (noun)
- The property that you cannot change a hash output in a predictable way without knowing the original input.
Non-malleability stops an attacker from guessing a related hash. - deterministic (adjective)
- Always giving the exact same output for the exact same input.
A hash function must be deterministic to be checked reliably. - digital signature (noun)
- A mathematical proof attached to a message that shows who sent it and that it was not changed.
Large messages are hashed before creating a digital signature. - commitment (noun)
- A value that hides a secret now but can later be revealed and checked.
A sealed bid uses a commitment to hide the offer's value. - sealed-bid auction (noun)
- An auction where each bid is hidden until all bids are revealed together.
A sealed-bid auction uses hash commitments to hide the offers. - entropy (noun)
- A measure of how unpredictable or random something is.
A password needs enough entropy to resist guessing. - enumerate (verb)
- To try or list out every possibility one at a time.
A weak password can be enumerated by an attacker. - tampering (noun)
- Making an unauthorized change to something.
Hashing a file lets you detect later tampering. - counterexample (noun)
- An example that proves a general claim false.
The lecture builds a counterexample to show the properties are independent. - over-engineering (noun)
- Adding more complexity or strength than a problem actually needs.
Requiring collision resistance for passwords would be over-engineering.
From the YouTube description
MIT 6.046J Design and Analysis of Algorithms, Spring 2015
View the complete course: http://ocw.mit.edu/6-046JS15
Instructor: Srinivas Devadas
In this lecture, Professor Devadas covers the basics of cryptography, including desirable properties of cryptographic functions, and their applications to security.
License: Creative Commons BY-NC-SA
More information at http://ocw.mit.edu/terms
More courses at http://ocw.mit.edu
← R10. Distributed Algorithms · 22. Cryptography: Encryption →
