What Makes a Hash Function Cryptographically Secure?
As established, hashing is a one-way transformation. But not all hash functions are equal. A cryptographic hash function must satisfy four strict properties to be considered secure:
-
Fixed Output Size: Regardless of input size — a single character or a 4GB video file — the output hash is always the same fixed length. SHA-256 always produces a 256-bit (64 hexadecimal character) output. SHA-512 always produces 512 bits.
-
Deterministic: The same input will always produce the exact same hash.
SHA-256("hello")will always equal2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824, on any machine, at any time. -
Avalanche Effect: A tiny change in the input — even flipping a single bit — should produce a completely different output hash. Changing
"hello"to"Hello"(just capitalizing the H) produces an entirely different SHA-256 hash with no resemblance to the original. This property ensures that an attacker cannot make small, undetected modifications to data. -
Collision Resistance: It must be computationally infeasible to find two different inputs that produce the same hash output (a collision). If collisions can be found, an attacker could substitute a malicious file for a legitimate one while keeping the same hash, defeating integrity checks. MD5 and SHA-1 are now considered broken for security purposes because practical collision attacks have been demonstrated against them. SHA-256 and SHA-3 are the current standards.
Use Case: Data Integrity Verification
When you download software from the internet, the publisher often provides a SHA-256 checksum alongside the download link. After downloading, you compute the SHA-256 hash of your local file and compare it to the published value. If they match exactly, you have cryptographic proof that:
- The file was not corrupted during the download (network errors would change bytes, changing the hash).
- The file was not replaced by a malicious version by an attacker who intercepted your download (they would need to find a file with the same SHA-256 hash, which is computationally infeasible).
Verifying is as simple as computing the hash of your downloaded file (with a tool like sha256sum) and comparing it to the value the publisher posted.
Common Hash Algorithms and Their Status
| Algorithm | Output Size | Status |
|---|---|---|
| MD5 | 128 bits | Broken — collision attacks demonstrated. Do not use for security. |
| SHA-1 | 160 bits | Deprecated — collision attacks demonstrated (SHAttered, 2017). Avoid. |
| SHA-256 | 256 bits | Secure — current standard. Use this. |
| SHA-512 | 512 bits | Secure — higher security margin, slightly slower. |
| SHA-3 | Variable | Secure — different internal design (Keccak), good alternative. |
| BLAKE3 | Variable | Secure — extremely fast, modern design. Used in some newer systems. |