# Theoretical Hashing Question

I am testing a theoretical hash function, $f()$, which produces n-bits of output.

By the pigeon hole principle, if I run $f(x)$ over a search space of $1+2^n$ values, I will get at least one collision. According to the birthday problem I should get many more collisions than that.

Is there a similar principle that I can determine how many values of $x$ will be needed to ensure with high probability that I have produced all possible $2^n$ values of $f(x)$?

I'm relatively certain that there is no 100% guarantee of obtaining all values, but at least an approximation within a degree of confidence should be possible. Are these approximations only practical when considering specific hashing algorithms?

• Belongs on Crypto SE? – 700 Software Nov 21 '16 at 15:29
• Uhm, why are you testing a theoretical hash function? Are you a security researcher? If not, it might be prudent to stick to existing hash functions. – Pascal Nov 21 '16 at 15:29
• – Wumpus Q. Wumbley Nov 21 '16 at 16:45
• – user991 Nov 21 '16 at 16:58

## 1 Answer

If $f()$ can be modeled as a random function (that is, if each output for a distinct input is independent of all other outputs), then this is a well studied problem in probability theory, known as the Coupon Collector's Problem.

The link I gave you gives more details; the bottom line is that you start getting good probability of seeing all possible sequences after around $C n 2^n$, for a constant $C$ not too far from 1 (and whose actual value depends on what "good probability" actually is).

Of course, if your theoretical hash function doesn't act randomly (for example, there are pairs of inputs $A \ne B$ where we're guarranteed that $f(A) \ne f(B)$), this analysis does not apply.