Checksums Versus Password Hashes: Why MD5 Cannot Serve as Tamper Protection

Checksums and password hashes share the same function family, yet require properties in opposite directions: a checksum must be fast and reproducible, a password hash must be slow and salted. Mixing them causes two kinds of incident — MD5 as tamper protection, or SHA-256 as password storage.

Division: the workflow for checking a download is in file integrity checks. This article covers the adversarial boundary — CRC32 versus cryptographic hashes, the real threat of MD5 collisions, length extension, and why passwords require a KDF.

Start With the Scenario: Would an Attacker Craft Input?

Scenario What causes failure Typical use Requirement
Non-adversarial Random faults: truncated transfers, bad sectors, crashes Download checks, cache keys, ETags, sharding Fast, deterministic, reproducible; CRC32 / MD5 acceptable
Adversarial Someone deliberately crafts input Tamper protection, signatures, password storage Collision resistance, preimage resistance, resistance to precomputation

One question decides it: could the input be chosen by an attacker? If yes, select for the adversarial case; if not, prioritising speed is reasonable. File verification is the lightest adversarial tier: the attacker may not target you, but the digest source still can be manipulated.

Two Tiers of Checksums: Error Codes vs Cryptographic Hashes

CRC32 is an error-detecting code, not a hash. It treats the message as a polynomial and takes a remainder, which is linear and one to two orders of magnitude faster; the price is that anyone able to solve linear equations can construct a message with a chosen CRC. It catches random errors and stops nothing deliberate.

SHA-256 is a cryptographic hash. Collision-resistant, preimage-resistant, with no known practical attack. The difference is not accuracy but threat model: CRC assumes the channel misbehaves, SHA assumes someone is hostile.

Practical rule: use SHA-256 for a single download; the extra time is negligible. Only when a pipeline verifies hundreds of files per second over trusted input does CRC32 justify losing the security property. Either way, the digest source matters as much as the algorithm — a same-source substitution defeats any hash.

MD5 and SHA-1: Collisions Are Constructible, Preimages Are Not

MD5 collisions take seconds on an ordinary laptop; SHA-1's SHAttered attack (2017) cost roughly 45k dollars then, and keeps getting cheaper.

Acceptable: non-adversarial download checks, cache keys, database dedup keys — there is just no reason not to use SHA-256. Unacceptable: file signatures, certificate integrity, anything tamper-evident.

Nuance: a collision attack is not the ability to recover an arbitrary original message, which requires a second-preimage attack and is far harder. But for "replacing a file", it is enough — the attacker prepares a legitimate file A and a malicious file B with the same digest, swaps them, and the checksum matches while the content changes.

So the test is not "is MD5 still easy to compute" but "can someone else choose the input". New projects should use SHA-256 without adding MD5 at all.

Password Storage: Why It Must Be a KDF

General-purpose hashes optimise for throughput, exactly what password storage must not have: a GPU computes billions of SHA-256 per second, so a leaked hash list plus a rainbow table recovers most passwords in minutes.

Password hashing needs two properties those hashes lack: a unique salt per user, so the same password yields different values and an entire rainbow table becomes useless, and a tunable cost, so parameters can rise as hardware improves without changing the format. Argon2id is the first choice, with bcrypt and scrypt behind it; parameters, bcrypt's 72-byte cap, and lazy migration are all in the password hashing guide.

One boundary lets you self-check immediately: checksums must be reproducible, password hashes must not be. Hash the same file twice and the result must match; store the same password twice and the values must differ. If either fails, you are using the wrong tool.

Length Extension: Why hash(secret + data) Is Forgeable

SHA-256 uses the Merkle–Damgård construction: the message is compressed block by block and the digest is the final internal state. Given H(secret || data) and the length of data, an attacker can treat that state as a starting point and keep compressing, producing H(secret || data || padding || extra) without ever knowing the secret.

// ❌ Forgeable via length extension
const sig = hash(secret + body)

// ✅ HMAC mixes the key into the initial state
const sig = crypto.createHmac('sha256', secret).update(body).digest('hex')

This is not academic: in webhook verification, an attacker appends content and the signature still validates. HMAC mixes the key into the state across two rounds and is immune by construction; SHA-3 / BLAKE2 sponge constructions are also unaffected.

A related trap sits in comparison itself: === returns at the first differing character, so timing varies with the shared prefix and can be probed byte by byte. Compare tokens and signatures with timingSafeEqual, or with a constant-time helper from your library.

Self-Check

  • [ ] Ask "can an attacker choose the input" before choosing an algorithm
  • [ ] Use SHA-256 for verification and tamper protection by default; only a pipeline needing CRC32's speed is an exception
  • [ ] Store passwords with Argon2id / bcrypt / scrypt, never bare SHA-256
  • [ ] Use HMAC for keyed purposes, never hand-built hash(secret + data)
  • [ ] Compare tokens and signatures in constant time

Measured: Same Password Twice Differs, Same File Twice Matches

# File: deterministic, two runs must agree
echo -n "hello world" | sha256sum
# b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
// Password: a fresh random salt each time, so the values must differ
const a = await bcrypt.hash('same-password', 12)
const b = await bcrypt.hash('same-password', 12)
console.log(a === b) // false

That is not a bug but the design requirement: reproducibility makes file verification work, non-reproducibility makes precomputation useless. Swap the two and both fail. Tools: text hash, bcrypt hash.

Frequently Asked Questions

Is MD5 still usable for verifying file integrity?

It depends on the goal. For detecting accidental corruption — transfer errors, disk faults, incomplete downloads — MD5 remains adequate: it has not been broken so much as shown to admit constructible collisions, and constructing them requires deliberate effort. File checksums are a non-adversarial setting where nobody builds collisions for you. For tamper protection, MD5 is disqualified: an attacker can produce two different files with the same hash and swap in the malicious one while the checksum still matches. SHA-1 is likewise unsafe since the SHAttered attack. Use SHA-256 for anything new; it has no known practical collision attack. A hashing tool computes SHA-256 directly.

Why not store passwords as plain SHA-256?

Because general-purpose hashes are designed to be fast, which is exactly the property password storage must not have. A GPU computes billions of SHA-256 per second, so testing a leaked list of hashes against a rainbow table takes minutes. Passwords need a deliberately slow KDF with a salt and a tunable cost parameter: Argon2id (preferred), bcrypt, scrypt or PBKDF2. These salt internally, so identical passwords produce different hashes and rainbow tables lose their value, and they expose an iteration cost or memory requirement that makes brute force impractical. A bcrypt tool and a password strength tool cover generation and assessment.

Is hand-rolling hash(secret + message) acceptable?

No — this is among the most common security mistakes. hash(secret + message) is vulnerable to a length-extension attack: an attacker who does not know the secret can still produce a valid hash(secret || message || padding || extra) and tamper with the appended portion. SHA-256 is collision resistant but not length-extension resistant (SHA-3 and BLAKE2 are). Use HMAC, which addresses this by design — crypto.createHmac('sha256', secret) in Node. One more rule: compare any token or signature with timingSafeEqual rather than plain equality, since timing differences leak information.

← Back to Blog