Output Length Matters
A hash function’s security depends on its output size.
More bits = more possible outputs = harder to find collisions.
The Numbers
| Output Size | Possible Outputs | Pre-image Security | Collision Security |
|---|---|---|---|
| 128-bit | |||
| 256-bit | |||
| 512-bit |
Collision security is always half the bit length (birthday attack).
What’s Achievable?
| Operations | Feasibility |
|---|---|
| Laptop in hours | |
| Cluster in days | |
| Nation-state budget | |
| Barely possible | |
| Impossible |
has been done. That’s why 128-bit hashes are broken for collision resistance.
is beyond reach. That’s why 256-bit hashes are secure.
The Rule
For -bit security, you need a -bit hash.
- Want 128-bit collision security? Use SHA-256.
- Want 256-bit collision security? Use SHA-512.
Brute Force Attack
The simplest attack: try every possible input.
Against pre-image resistance:
- Pick random inputs
- Hash each one
- Check if it matches the target hash
- Repeat until found
With a 256-bit hash, you’d need ~ attempts.
The universe has ~ atoms. You’d run out of time and energy.
Why Brute Force Works (Eventually)
Given enough attempts, you will find a match.
But “enough” can mean trillions of years.
| Hash Size | Attempts Needed | Time at /sec |
|---|---|---|
| 64-bit | ~5 hours | |
| 128-bit | ~ years | |
| 256-bit | ~ years |
The universe is ~ years old.
The Takeaway
- Short hashes (128-bit) are vulnerable to birthday attacks
- Long hashes (256-bit+) resist brute force for the foreseeable future
- Always use at least SHA-256 for security applications