Modern Cryptography · 6.1

🧮 Hash Functions

One-way fingerprints — fast, fixed-size, and irreversible⏱ ~2 min

🎲A hash function = a fingerprint of data

Every person has unique fingerprints. So does every file, when hashed. A 10 GB movie and a 10-byte text file both produce exactly 256 bits of hash output. The fingerprint is unique (in practice), one-way (you can't reconstruct the file from the fingerprint), and sensitive to any change (flip one bit and the fingerprint completely changes).

"hello""hellp"one letter changed!⚙️SHA-2562cf24dba5fb0a...digest A91f5261c34a99...digest B — totally different!Change ONE letter → the whole fingerprint changes. That's the avalanche effect.
The avalanche effect — one letter changes, the entire fingerprint changes

Properties of a Cryptographic Hash Function

PropertyWhat It MeansAttack It Defeats
DeterministicSame input always produces same output(baseline)
Pre-image resistanceCannot find input x given output H(x)Reversing a hash to recover the password
Second pre-image resistanceGiven x, cannot find y≠x such that H(x)=H(y)Substituting a different document with the same hash
Collision resistanceCannot find any x,y where x≠y and H(x)=H(y)Finding two documents with the same hash
Avalanche effectChanging 1 bit of input changes ~50% of output bitsDetecting patterns in hashes to infer input

The Hash Family: MD5, SHA-1, SHA-2, SHA-3

AlgorithmOutput SizeStatusNotes
MD5128 bits❌ BrokenCollisions found in 1996; GPU can compute 10B/sec. Never use for security.
SHA-1160 bits❌ BrokenSHAttered collision (Google, 2017). Deprecated in certificates since 2017.
SHA-256256 bits✓ SecureSHA-2 family. Used in TLS, Bitcoin, code signing, digital signatures.
SHA-384384 bits✓ SecureSHA-2. Used in high-security contexts and TLS cipher suites.
SHA-512512 bits✓ SecureSHA-2. Faster than SHA-256 on 64-bit systems.
SHA-3 / Keccak224–512 bits✓✓ SecureDifferent construction from SHA-2. Good hedge if SHA-2 is broken.
BLAKE3256 bits✓✓ SecureFastest modern hash. Used in file integrity tools (b3sum).

Real-World Uses of Hash Functions

  • Password storage — hash the password before storing (with bcrypt/Argon2, which use hashing internally)
  • File integrity — SHA-256 checksums detect corruption or tampering in downloads
  • Digital signatures — sign the hash of a document, not the document itself
  • Blockchain — each Bitcoin block contains the SHA-256 hash of the previous block, chaining them immutably
  • Content-addressable storage — Git uses SHA-1 (migrating to SHA-256) to address all objects by their hash
  • Message authentication — HMAC uses a hash function to produce an authenticated MAC
⚠ WarningMD5 and SHA-1 are still widely used for non-security purposes like checksum verification or cache keys — that's fine. They are broken specifically for collision resistance. The danger: using SHA-1 in digital signatures or certificates, where an attacker can forge a valid signature by finding a collision. For any security application, use SHA-256 or higher.
🧠Quick Checkfirst try = +5 XP

Which hash functions are broken for security use?

0 XP🔥 0 days