Birthday probability for hash outputs
ID: birthday-probability-for-hash-outputs
How soon should a hash collision appear? Specify the probability distribution of the outputs first. Evaluate distinct keys and assume their hash values are independent random variables, each with the uniform distribution on a finite set of possible outputs. The randomness may come from an idealized randomly chosen hash function; a fixed hash function and a fixed list of keys have a definite outcome. Sampling the same key twice creates a repeated hash value without creating a hash collision, so distinctness of the queried keys matters.
This is the existing birthday problem, with hash values in place of birthdays. Let be the probability of at least one equal pair. The exact formula isThe empty product is , so . Given previous distinct hash values, the next value avoids them with conditional probability . Multiply these conditional chances and subtract from . Equivalently, for , exactly of the equally likely ordered outcomes have no repeated value. This derivation also explains why independence of all outputs, rather than merely uniform individual values, is required.[ref]
https://cacr.uwaterloo.ca/hac/about/chap2.pdf. Menezes, van Oorschot and Vanstone, Handbook of Applied Cryptography, section 2.1.5, Fact 2.27(i), birthday probability
For , the exact hash collision probabilities are , , and . Thus only distinct queries already exceed a one-half chance of some pair matching. The striking feature is the number of opportunities: queries supply pairs. By linearity of expectation, the expected value of the number of equal pairs is . This expectation counts pairs, not the probability of at least one pair; three equal outputs contribute three pairs in one outcome. The union bound gives .
Using the natural logarithm expansion in the exact product givesFor , the omitted correction in the logarithm of the no-collision probability is . Thus the approximation is controlled when is small; in particular it becomes accurate at the birthday scale proportional to as increases. The inequality also shows that the displayed approximation is a lower bound for when . Setting its exponent to gives the approximate half-probability sample size for large .
For comparison, under the same independent uniform model the probability of hitting one previously fixed digest in queries isEach query supplies one chance to hit , instead of a growing number of possible pairs. For , , and the first integer with is . In a toy model with possible -bit digests, the any-pair transition therefore has scale queries, while the fixed-target transition has scale . This explains the birthday-search distinction between collision resistance and preimage resistance.[ref]
https://cacr.uwaterloo.ca/hac/about/chap9.pdf. Menezes, van Oorschot and Vanstone, Handbook of Applied Cryptography, Fact 9.33 and section 9.7.1, generic collision versus preimage searches
The assumptions are essential. Uniform marginals alone do not give the product formula: if all equal one shared uniform random variable, every distinct pair collides with probability . A universal hash family bounds each pair's hash collision probability, but that condition alone does not supply joint independence of every output. Nor does a fixed output length establish collision resistance or preimage resistance: the toy has , making deliberate hash collisions immediate. The curves describe the specified model and do not establish the security of a concrete cryptographic hash function.
New to topics? Read the docs here!
