What Is a Cryptographic Hash Function?
A cryptographic hash function is a mathematical algorithm that maps an arbitrary, variable-length block of input data (whether a 5-letter word or a 10 GB operating system ISO image) into a fixed-length string of characters, called a hash value, digest, or checksum.
Crucially, cryptographic hashing is strictly a one-way mathematical function. While it is trivial to compute the hash digest from an input file, it is computationally impossible to reverse the process and reconstruct the original input from the resulting digest.
The Four Fundamental Rules of Cryptographic Hashes
To be classified as cryptographically secure, a hashing algorithm must satisfy four rigorous criteria:
- Deterministic Output: The exact same input will always produce the identical hash digest, regardless of when or where it is calculated.
- Pre-image Resistance (One-Way): Given a target hash digest H, it is computationally infeasible to find any original input M such that hash(M) = H.
- Second Pre-image Resistance: Given an input M1, it is impossible to find a different input M2 such that hash(M1) = hash(M2).
- Collision Resistance: It is impossible to find any two arbitrary, distinct inputs that happen to produce the same hash digest.
- The Avalanche Effect: Changing a single bit in the input (e.g., turning a lowercase letter into uppercase) dramatically and unpredictably changes over 50% of the output digest characters.
Why MD5 and SHA-1 Are Cryptographically Broken
In the 1990s and early 2000s, MD5 (Message Digest 5, 128-bit) and SHA-1 (160-bit) were widely deployed across security protocols. However, advances in cryptanalysis and GPU computing demonstrated severe structural collision vulnerabilities.
In 2004, researchers proved that two completely different PDF contracts could be engineered to yield the exact identical MD5 hash. In 2017, Google announced the SHAttered attack, generating two distinct PDF files with the same SHA-1 digest. Today, MD5 and SHA-1 must never be used for digital signatures, SSL certificates, or security credentials.
MD5 Is Obsolete for Security
Never use MD5 or SHA-1 for passwords, digital signatures, or security tokens. They are only acceptable for non-cryptographic cache keys or checksum validation against accidental file corruption.
SHA-256 & SHA-3: The Modern Gold Standard for Data Integrity
Designed by the United States National Security Agency (NSA) and standardized by NIST, the SHA-2 family—specifically SHA-256 (256-bit digest)—remains the global gold standard for cryptographic integrity.
SHA-256 powers the Bitcoin blockchain, TLS/SSL website security certificates, Git commit trees, and software download checksums. To date, there is no known practical collision attack against SHA-256.
The Fatal Mistake: Fast Hashes vs Slow Password Hashes
A pervasive mistake among junior software developers is using fast cryptographic hashes (like raw SHA-256) to store user passwords in databases. Because SHA-256 was designed for high-throughput file checksums, modern consumer graphics cards (GPUs) can compute over 10 billion SHA-256 hashes per second.
If an attacker steals a database of unsalted SHA-256 hashes, they can precompute "rainbow tables" or brute-force typical 8-character passwords in minutes.
Passwords must always be hashed using deliberately slow, memory-hard key derivation functions: Bcrypt, PBKDF2 (with high iteration counts), or Argon2. These algorithms force attackers to expend extensive CPU and memory resources, rendering brute-force attacks mathematically infeasible.
Cryptographic Hashing Algorithm Comparison
Summary of common hashing functions and their contemporary security posture:
| Algorithm | Digest Size | Collision Status | Primary Modern Use Case |
|---|---|---|---|
| MD5 | 128 bits | Broken (instant collisions) | Legacy non-security file checksums only |
| SHA-1 | 160 bits | Broken (SHAttered attack) | Phased out; avoid in all new systems |
| SHA-256 | 256 bits | Secure (no known collisions) | TLS certificates, Git, software integrity, blockchain |
| SHA-512 | 512 bits | Secure (highly resilient) | High-security government & enterprise integrity |
| Bcrypt / Argon2 | Variable | Secure (adaptive work factor) | User password storage and authentication |