# What is a universal hash function?

Short and to the point. I'm assuming that it is not a kind of hash function that can be used universally. After having read about universal hash functions used with the one-time pad to form an authentication scheme, these things have bugged me out.

• It is a complicated way of saying that you have a parameter to make the hashing unique. For example if you include a nonce or a key as in HMACs. en.m.wikipedia.org/wiki/Universal_hashing Nov 9 '17 at 3:51

From Wikipedia:

In mathematics and computing universal hashing (in a randomized algorithm or data structure) refers to selecting a hash function at random from a family of hash functions with a certain mathematical property. This guarantees a low number of collisions in expectation, even if the data is chosen by an adversary. Many universal families are known (for hashing integers, vectors, strings), and their evaluation is often very efficient. Universal hashing has numerous uses in computer science, for example in implementations of hash tables, randomized algorithms, and cryptography.

Definition:
A randomized algorithm $$H$$ for constructing hash functions $$h\colon U \to \{1,\ldots,M\}$$ is universal if for all $$x \neq y$$ in $$U$$, we have $$\Pr_{h\gets H} [h(x) = h(y)] \leq 1/M$$

Let $$\Phi$$ be a finite collection of hash functions that map a given universe $$U$$ of keys into the range $$\{0, 1, 2,\ldots, m - 1\}.$$
$$\Phi$$ is called universal if for each pair of distinct keys $$x, y \in U$$, the number of hash functions $$h \in\Phi$$ for which $$h(x) = h(y)$$ is precisely equal to $$\frac{\lvert\Phi\rvert}{m}.$$
With a function randomly chosen from $$\Phi$$, the chance of a collision between $$x$$ and $$y$$ where $$x \neq y$$ is exactly $$\frac{1}{m}$$.