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).
Properties of a Cryptographic Hash Function
| Property | What It Means | Attack It Defeats |
|---|---|---|
| Deterministic | Same input always produces same output | (baseline) |
| Pre-image resistance | Cannot find input x given output H(x) | Reversing a hash to recover the password |
| Second pre-image resistance | Given x, cannot find y≠x such that H(x)=H(y) | Substituting a different document with the same hash |
| Collision resistance | Cannot find any x,y where x≠y and H(x)=H(y) | Finding two documents with the same hash |
| Avalanche effect | Changing 1 bit of input changes ~50% of output bits | Detecting patterns in hashes to infer input |
The Hash Family: MD5, SHA-1, SHA-2, SHA-3
| Algorithm | Output Size | Status | Notes |
|---|---|---|---|
| MD5 | 128 bits | ❌ Broken | Collisions found in 1996; GPU can compute 10B/sec. Never use for security. |
| SHA-1 | 160 bits | ❌ Broken | SHAttered collision (Google, 2017). Deprecated in certificates since 2017. |
| SHA-256 | 256 bits | ✓ Secure | SHA-2 family. Used in TLS, Bitcoin, code signing, digital signatures. |
| SHA-384 | 384 bits | ✓ Secure | SHA-2. Used in high-security contexts and TLS cipher suites. |
| SHA-512 | 512 bits | ✓ Secure | SHA-2. Faster than SHA-256 on 64-bit systems. |
| SHA-3 / Keccak | 224–512 bits | ✓✓ Secure | Different construction from SHA-2. Good hedge if SHA-2 is broken. |
| BLAKE3 | 256 bits | ✓✓ Secure | Fastest 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?
🎮 Practice what you learned
⭐ 0 XP🔥 0 days