DEV Community

PPPing
PPPing

Posted on

Ping64|What a Hash Collision Is and Why Old Algorithms Get Retired

Download a large installer and the site may offer a short string of letters and digits beside it. Copy the file, run a tool over it, and compare the results. If the strings match, the file is almost certainly intact.

That string is a hash, a kind of digital fingerprint. The unsettling question is what happens when two different files produce the same one. The answer explains why algorithms that once seemed solid get quietly withdrawn.

A library that labels books with short codes

Imagine a library that cannot fit full titles on the shelf, so it stamps each book with a short code derived from the title. Most of the time the codes are distinct, and staff can find a book by its code alone.

Occasionally two different titles produce the same code. Now a request for one book may pull the wrong volume, and the system has no way to tell the difference from the code alone.

The shorter the code, the more often this happens. A three-letter code collides constantly, while a thirty-letter code barely ever does in ordinary use. Nothing has gone wrong with the labelling process itself; the scheme is simply doing what short codes do.

Why collisions are inevitable but rare

A hash function takes input of any length and returns output of a fixed length, whether the input is a shopping list or a video file. The output space is finite, so the number of possible outputs is finite too.

Feed in enough distinct inputs and repeats must occur. That is a counting argument, not a flaw.

The practical question is how hard a repeat is to find on purpose. For a well-designed 256-bit hash, the output space is enormous, and a generic search needs an effort near the square root of that space, roughly 2^128 attempts. Nobody is doing that with current hardware.

There is a wrinkle known as the birthday problem. Finding any matching pair is easier than matching one specific value, because every new output can be compared against all the earlier ones. That is why collision resistance is measured against the square root, not the full space.

Weakness arrives through design, not brute force. Older functions such as MD5 and SHA-1 have structures that let researchers find collisions far faster than a generic search would allow, and chosen-prefix attacks made those collisions useful rather than merely curious.

Good hash functions also behave unpredictably. Change one character of input and the output should look completely unrelated, with about half the bits flipping. That property is what stops anyone from nudging a document toward a desired fingerprint.

Why organisations pay attention

The consequences are concrete. If two different documents share a hash, a signature over that hash no longer distinguishes them, so a signed contract could be swapped for another one. Certificates have been forged this way in research demonstrations, and the industry responded by moving away from the affected functions.

Backup and storage systems also use hashes to avoid keeping duplicate copies, and a collision there means one file may be mistaken for another and skipped. That risk is low with modern functions, but it is one reason the choice of algorithm is reviewed rather than assumed. Tools like Ping64, an all-in-one office security platform, combine multiple security controls in one system to simplify corporate data protection.

Auditors tend to ask two questions: which function is in use, and where is it still trusted long after it should have been replaced. Those two answers usually say more than the algorithm name on a specification sheet.

What a collision does not mean

A common fear is that a collision lets an attacker read your files. It does not. Hash functions are one-way by design, and recovering input from output is a separate problem from finding two inputs that agree.

Another confusion is treating hashes as encryption. There is no key and nothing to decrypt. Calling a hash encrypted is like calling a fingerprint a photograph.

It is also worth noting that retirement is usually about margin rather than immediate disaster. When an algorithm is deprecated, the practical risk at that moment may still be small, but the trend line is bad and migration takes years, so the decision gets made early.

Context matters too. An old function may remain acceptable for detecting accidental corruption in a download, where nobody is trying to deceive you, while being unsuitable for signatures or evidence.

Password storage is a different story again. There, the concern is speed of guessing rather than collisions, which is why deliberately slow functions are used instead of fast general-purpose ones.

One habit worth forming is checking dates on policy documents. A hash choice that seemed reasonable a decade ago may still be written down somewhere that nobody has opened since.

The short version

Collisions exist because hashes squeeze unlimited input into a fixed output. Modern functions make them impractical to find, older ones did not, and that is why the older ones get retired. If a system still lists a withdrawn algorithm, it is worth asking why.

References

Top comments (0)