Cryptography / MD5 and why it is broken

MD5 and why it is broken

MD5 gives every input a 128-bit fingerprint. See what that was used for, how two inputs came to share one fingerprint, and why that ended its use in security.

Beginner7 steps~6 min
Input — any file, message or document
MD5 — the hash function
Hash — the 128-bit fingerprint
Signature — made on the hash, not the input
// THE SHORT VERSION

In 30 seconds

MD5 turns any data into a short 128-bit fingerprint, or hash. It was used to check downloads, store passwords and make digital signatures.

A hash is only safe if nobody can find two different inputs with the same fingerprint, a collision. For MD5 that now takes seconds, so a signature on one document can be moved to another.

For security, use SHA-256 or SHA-3, and a slow password function such as Argon2. MD5 is still fine for spotting accidental damage, where no one is trying to cheat.

MD5 and why it is broken, step by step

STEPS01 / 07

Only collision resistance is broken. Nobody can yet take an MD5 hash and find an input that produces it (a preimage), but MD5 is retired from security use all the same.

STEP 01 / 07 A 128-bit fingerprint
THE MATH
MD5("hello") = 5d41402abc4b2a76 b9719d911017c592
  1. Step 1: A 128-bit fingerprint. MD5 is a hash function from 1991. It boils any input, a word or a whole film, down to 128 bits, written as 32 hex digits. The same input always gives the same result, and changing one letter gives a result with nothing in common.
  2. Step 2: What it was used for. For years MD5 was everywhere: as a checksum beside downloads, as the stored form of passwords, and inside digital signatures, where the signer signs the short hash instead of the whole document or certificate. All three lean on one promise about the hash.
  3. Step 3: The promise: no collisions. A collision is two different inputs with the same hash. Collisions must exist, because there are endless inputs and only a fixed number of 128-bit outputs. The promise is that finding one is out of reach: for a sound 128-bit hash it takes about 2⁶⁴ attempts.
  4. Step 4: Broken in practice. In 2004 Xiaoyun Wang and colleagues showed how to steer MD5 into a collision with far less work than promised. By 2006 it took under a minute on a laptop. These two real 128-byte inputs differ in six bytes and share one MD5 hash.
  5. Step 5: Why it breaks signatures. A signature covers the hash, not the document. Someone who prepares two colliding documents can have the harmless one signed, then attach that signature to the other, and it verifies. Researchers forged a certificate authority this way in 2008, and the Flame malware used the same trick in 2012.
  6. Step 6: What to use instead. For fingerprints, signatures and certificates, use a hash with no known collisions, such as SHA-256 or SHA-3. Passwords need a different tool altogether: a deliberately slow, salted function such as Argon2, bcrypt or PBKDF2, because any fast hash can be guessed against billions of times a second.
  7. Step 7: Where MD5 is still harmless. MD5 still spots accidental damage perfectly well: a flipped bit or a cut-off download changes the hash. So it survives as a checksum, cache key or de-duplication label where nobody is trying to cheat. It gives no protection once someone can craft the data.
VALUES SO FAR
output128 bitsfixed
"hello"5d41402abc4b…hash
promise····design
reality····broken
A and B····collision
forgery····real
instead····use
still ok····checksum
// BEFORE

Learn this first

Nothing. This concept starts from scratch.

Spotted a mistake on this page?