Cryptographic hash functions · 03 The maths

Hash functions: the maths

The birthday paradox and why security against collisions is half the length of the value, with the pigeonhole principle.

Collisions always exist

A hash function maps an infinite set of messages to a finite set of values. By the pigeonhole principle, different messages with the same value must exist. Security lies not in the impossibility of collisions but in the practical impossibility of finding them.

The birthday paradox

In a group of just 23 people the probability that two share a birthday exceeds 50%. It seems strange, but the number of possible pairs grows much faster than the number of people: with 23 people there are 253 pairs.

  1. 01
    The principle

    With N possible values, about √N attempts are needed to have a good chance of finding two equal values.

  2. 02
    Applied to hash values

    An n-bit value has 2^n possible values: a collision is found with about 2^(n/2) attempts.

  3. 03
    MD5

    128-bit value: theoretical collision security of 2^64, a number within reach of today’s computers even without flaws in the algorithm.

  4. 04
    SHA-256

    256-bit value: about 2^128 attempts are needed, a number beyond any existing computer.

Continue with
04 Worked example

Hash functions: worked example

SHA-256 values of similar words and phrases, to see the avalanche effect, and the official test vectors.

↑