<s>
In	O
mathematics	O
and	O
computing	O
,	O
universal	B-Algorithm
hashing	I-Algorithm
(	O
in	O
a	O
randomized	B-General_Concept
algorithm	I-General_Concept
or	O
data	O
structure	O
)	O
refers	O
to	O
selecting	O
a	O
hash	B-Error_Name
function	I-Error_Name
at	O
random	O
from	O
a	O
family	O
of	O
hash	B-Error_Name
functions	I-Error_Name
with	O
a	O
certain	O
mathematical	O
property	O
(	O
see	O
definition	O
below	O
)	O
.	O
</s>
<s>
Many	O
universal	B-Algorithm
families	I-Algorithm
are	O
known	O
(	O
for	O
hashing	O
integers	O
,	O
vectors	O
,	O
strings	O
)	O
,	O
and	O
their	O
evaluation	O
is	O
often	O
very	O
efficient	O
.	O
</s>
<s>
Universal	B-Algorithm
hashing	I-Algorithm
has	O
numerous	O
uses	O
in	O
computer	O
science	O
,	O
for	O
example	O
in	O
implementations	O
of	O
hash	B-Algorithm
tables	I-Algorithm
,	O
randomized	B-General_Concept
algorithms	I-General_Concept
,	O
and	O
cryptography	O
.	O
</s>
<s>
A	O
deterministic	O
hash	B-Error_Name
function	I-Error_Name
cannot	O
offer	O
any	O
guarantee	O
in	O
an	O
adversarial	O
setting	O
if	O
,	O
since	O
the	O
adversary	O
may	O
choose	O
to	O
be	O
precisely	O
the	O
preimage	O
of	O
a	O
bin	O
.	O
</s>
<s>
Furthermore	O
,	O
a	O
deterministic	O
hash	B-Error_Name
function	I-Error_Name
does	O
not	O
allow	O
for	O
rehashing	B-Algorithm
:	O
sometimes	O
the	O
input	O
data	O
turns	O
out	O
to	O
be	O
bad	O
for	O
the	O
hash	B-Error_Name
function	I-Error_Name
(	O
e.g.	O
</s>
<s>
there	O
are	O
too	O
many	O
collisions	O
)	O
,	O
so	O
one	O
would	O
like	O
to	O
change	O
the	O
hash	B-Error_Name
function	I-Error_Name
.	O
</s>
<s>
The	O
solution	O
to	O
these	O
problems	O
is	O
to	O
pick	O
a	O
function	O
randomly	O
from	O
a	O
family	O
of	O
hash	B-Error_Name
functions	I-Error_Name
.	O
</s>
<s>
A	O
family	O
of	O
functions	O
is	O
called	O
a	O
universal	B-Algorithm
family	I-Algorithm
if	O
,	O
.	O
</s>
<s>
In	O
other	O
words	O
,	O
any	O
two	O
different	O
keys	O
of	O
the	O
universe	O
collide	O
with	O
probability	O
at	O
most	O
when	O
the	O
hash	B-Error_Name
function	I-Error_Name
is	O
drawn	O
uniformly	O
at	O
random	O
from	O
.	O
</s>
<s>
This	O
is	O
exactly	O
the	O
probability	O
of	O
collision	O
we	O
would	O
expect	O
if	O
the	O
hash	B-Error_Name
function	I-Error_Name
assigned	O
truly	O
random	O
hash	B-Error_Name
codes	I-Error_Name
to	O
every	O
key	O
.	O
</s>
<s>
So	O
for	O
example	O
,	O
a	O
universal	B-Algorithm
family	I-Algorithm
has	O
-almost	O
universality	O
.	O
</s>
<s>
Many	O
,	O
but	O
not	O
all	O
,	O
universal	B-Algorithm
families	I-Algorithm
have	O
the	O
following	O
stronger	O
uniform	O
difference	O
property	O
:	O
</s>
<s>
(	O
Similarly	O
,	O
a	O
universal	B-Algorithm
family	I-Algorithm
can	O
be	O
XOR	O
universal	O
if	O
,	O
the	O
value	O
is	O
uniformly	O
distributed	O
in	O
where	O
is	O
the	O
bitwise	O
exclusive	O
or	O
operation	O
.	O
</s>
<s>
An	O
even	O
stronger	O
condition	O
is	O
pairwise	O
independence	O
:	O
we	O
have	O
this	O
property	O
when	O
we	O
have	O
the	O
probability	O
that	O
will	O
hash	B-Error_Name
to	O
any	O
pair	O
of	O
hash	B-Error_Name
values	I-Error_Name
is	O
as	O
if	O
they	O
were	O
perfectly	O
random	O
:	O
.	O
</s>
<s>
We	O
say	O
that	O
a	O
family	O
is	O
uniform	O
if	O
all	O
hash	B-Error_Name
values	I-Error_Name
are	O
equally	O
likely	O
:	O
for	O
any	O
hash	B-Error_Name
value	I-Error_Name
.	O
</s>
<s>
Given	O
a	O
family	O
with	O
the	O
uniform	O
distance	O
property	O
,	O
one	O
can	O
produce	O
a	O
pairwise	O
independent	O
or	O
strongly	O
universal	B-Algorithm
hash	I-Algorithm
family	O
by	O
adding	O
a	O
uniformly	O
distributed	O
random	O
constant	O
with	O
values	O
in	O
to	O
the	O
hash	B-Error_Name
functions	I-Error_Name
.	O
</s>
<s>
(	O
Similarly	O
,	O
if	O
is	O
a	O
power	O
of	O
two	O
,	O
we	O
can	O
achieve	O
pairwise	O
independence	O
from	O
an	O
XOR	O
universal	B-Algorithm
hash	I-Algorithm
family	O
by	O
doing	O
an	O
exclusive	O
or	O
with	O
a	O
uniformly	O
distributed	O
random	O
constant	O
.	O
)	O
</s>
<s>
hash	B-Algorithm
tables	I-Algorithm
)	O
,	O
a	O
careful	O
distinction	O
between	O
the	O
uniform	O
distance	O
property	O
and	O
pairwise	O
independent	O
is	O
sometimes	O
not	O
made	O
.	O
</s>
<s>
For	O
some	O
applications	O
(	O
such	O
as	O
hash	B-Algorithm
tables	I-Algorithm
)	O
,	O
it	O
is	O
important	O
for	O
the	O
least	O
significant	O
bits	O
of	O
the	O
hash	B-Error_Name
values	I-Error_Name
to	O
be	O
also	O
universal	O
.	O
</s>
<s>
When	O
a	O
family	O
is	O
strongly	O
universal	O
,	O
this	O
is	O
guaranteed	O
:	O
if	O
is	O
a	O
strongly	O
universal	B-Algorithm
family	I-Algorithm
with	O
,	O
then	O
the	O
family	O
made	O
of	O
the	O
functions	O
for	O
all	O
is	O
also	O
strongly	O
universal	O
for	O
.	O
</s>
<s>
Unfortunately	O
,	O
the	O
same	O
is	O
not	O
true	O
of	O
(	O
merely	O
)	O
universal	B-Algorithm
families	I-Algorithm
.	O
</s>
<s>
UMAC	B-Algorithm
and	O
Poly1305-AES	B-Algorithm
and	O
several	O
other	O
message	B-Algorithm
authentication	I-Algorithm
code	I-Algorithm
algorithms	O
are	O
based	O
on	O
universal	B-Algorithm
hashing	I-Algorithm
.	O
</s>
<s>
In	O
such	O
applications	O
,	O
the	O
software	O
chooses	O
a	O
new	O
hash	B-Error_Name
function	I-Error_Name
for	O
every	O
message	O
,	O
based	O
on	O
a	O
unique	O
nonce	O
for	O
that	O
message	O
.	O
</s>
<s>
Several	O
hash	B-Algorithm
table	I-Algorithm
implementations	O
are	O
based	O
on	O
universal	B-Algorithm
hashing	I-Algorithm
.	O
</s>
<s>
In	O
such	O
applications	O
,	O
typically	O
the	O
software	O
chooses	O
a	O
new	O
hash	B-Error_Name
function	I-Error_Name
only	O
after	O
it	O
notices	O
that	O
"	O
too	O
many	O
"	O
keys	O
have	O
collided	O
;	O
until	O
then	O
,	O
the	O
same	O
hash	B-Error_Name
function	I-Error_Name
continues	O
to	O
be	O
used	O
over	O
and	O
over	O
.	O
</s>
<s>
(	O
Some	O
collision	O
resolution	O
schemes	O
,	O
such	O
as	O
dynamic	B-Algorithm
perfect	I-Algorithm
hashing	I-Algorithm
,	O
pick	O
a	O
new	O
hash	B-Error_Name
function	I-Error_Name
every	O
time	O
there	O
is	O
a	O
collision	O
.	O
</s>
<s>
Other	O
collision	O
resolution	O
schemes	O
,	O
such	O
as	O
cuckoo	B-Algorithm
hashing	I-Algorithm
and	O
2-choice	B-Algorithm
hashing	I-Algorithm
,	O
allow	O
a	O
number	O
of	O
collisions	O
before	O
picking	O
a	O
new	O
hash	B-Error_Name
function	I-Error_Name
)	O
.	O
</s>
<s>
For	O
any	O
fixed	O
set	O
of	O
keys	O
,	O
using	O
a	O
universal	B-Algorithm
family	I-Algorithm
guarantees	O
the	O
following	O
properties	O
.	O
</s>
<s>
When	O
implementing	O
hash	B-Algorithm
tables	I-Algorithm
by	O
chaining	O
,	O
this	O
number	O
is	O
proportional	O
to	O
the	O
expected	O
running	O
time	O
of	O
an	O
operation	O
involving	O
the	O
key	O
(	O
for	O
example	O
a	O
query	O
,	O
insertion	O
or	O
deletion	O
)	O
.	O
</s>
<s>
This	O
only	O
holds	O
with	O
a	O
hash	B-Error_Name
family	O
whose	O
collision	O
probability	O
is	O
bounded	O
above	O
by	O
.	O
</s>
<s>
However	O
,	O
the	O
adversary	O
has	O
to	O
make	O
this	O
choice	O
before	O
(	O
or	O
independent	O
of	O
)	O
the	O
algorithm	O
's	O
random	O
choice	O
of	O
a	O
hash	B-Error_Name
function	I-Error_Name
.	O
</s>
<s>
The	O
second	O
and	O
third	O
guarantee	O
are	O
typically	O
used	O
in	O
conjunction	O
with	O
rehashing	B-Algorithm
.	O
</s>
<s>
For	O
instance	O
,	O
a	O
randomized	B-General_Concept
algorithm	I-General_Concept
may	O
be	O
prepared	O
to	O
handle	O
some	O
number	O
of	O
collisions	O
.	O
</s>
<s>
Since	O
any	O
computer	O
data	O
can	O
be	O
represented	O
as	O
one	O
or	O
more	O
machine	O
words	O
,	O
one	O
generally	O
needs	O
hash	B-Error_Name
functions	I-Error_Name
for	O
three	O
types	O
of	O
domains	O
:	O
machine	O
words	O
(	O
"	O
integers	O
"	O
)	O
;	O
fixed-length	O
vectors	O
of	O
machine	O
words	O
;	O
and	O
variable-length	O
vectors	O
(	O
"	O
strings	O
"	O
)	O
.	O
</s>
<s>
(	O
This	O
is	O
a	O
single	O
iteration	O
of	O
a	O
linear	B-Algorithm
congruential	I-Algorithm
generator	I-Algorithm
.	O
)	O
</s>
<s>
Another	O
way	O
to	O
see	O
is	O
a	O
universal	B-Algorithm
family	I-Algorithm
is	O
via	O
the	O
notion	O
of	O
statistical	O
distance	O
.	O
</s>
<s>
Then	O
the	O
hash	B-Error_Name
functions	I-Error_Name
are	O
parametrised	O
over	O
odd	O
positive	O
integers	O
(	O
that	O
fit	O
in	O
a	O
word	O
of	O
bits	O
)	O
.	O
</s>
<s>
To	O
evaluate	O
,	O
multiply	O
by	O
modulo	O
and	O
then	O
keep	O
the	O
high	O
order	O
bits	O
as	O
the	O
hash	B-Error_Name
code	I-Error_Name
.	O
</s>
<s>
To	O
understand	O
the	O
behavior	O
of	O
the	O
hash	B-Error_Name
function	I-Error_Name
,	O
</s>
<s>
If	O
is	O
a	O
universal	B-Algorithm
family	I-Algorithm
with	O
the	O
uniform	O
difference	O
property	O
,	O
the	O
following	O
family	O
(	O
dating	O
back	O
to	O
Carter	O
and	O
Wegman	O
)	O
also	O
has	O
the	O
uniform	O
difference	O
property	O
(	O
and	O
hence	O
is	O
universal	O
)	O
:	O
</s>
<s>
In	O
practice	O
,	O
if	O
double-precision	O
arithmetic	O
is	O
available	O
,	O
this	O
is	O
instantiated	O
with	O
the	O
multiply-shift	O
hash	B-Error_Name
family	O
of	O
hash	B-Error_Name
functions	I-Error_Name
.	O
</s>
<s>
Initialize	O
the	O
hash	B-Error_Name
function	I-Error_Name
with	O
a	O
vector	O
of	O
random	O
odd	O
integers	O
on	O
bits	O
each	O
.	O
</s>
<s>
Initialize	O
the	O
hash	B-Error_Name
function	I-Error_Name
with	O
a	O
vector	O
of	O
random	O
odd	O
integers	O
on	O
bits	O
each	O
.	O
</s>
<s>
The	O
following	O
hash	B-Error_Name
family	O
is	O
universal	O
:	O
</s>
<s>
In	O
this	O
variant	O
,	O
the	O
vector	O
technique	O
is	O
known	O
as	O
tabulation	B-Algorithm
hashing	I-Algorithm
and	O
it	O
provides	O
a	O
practical	O
alternative	O
to	O
multiplication-based	O
universal	B-Algorithm
hashing	I-Algorithm
schemes	O
.	O
</s>
<s>
Initialize	O
the	O
hash	B-Error_Name
function	I-Error_Name
with	O
a	O
vector	O
of	O
random	O
integers	O
on	O
bits	O
.	O
</s>
<s>
As	O
long	O
as	O
zeroes	O
are	O
forbidden	O
in	O
the	O
string	O
,	O
the	O
zero-padding	O
can	O
be	O
ignored	O
when	O
evaluating	O
the	O
hash	B-Error_Name
function	I-Error_Name
without	O
affecting	O
universality	O
.	O
</s>
<s>
Now	O
assume	O
we	O
want	O
to	O
hash	B-Error_Name
,	O
where	O
a	O
good	O
bound	O
on	O
is	O
not	O
known	O
a	O
priori	O
.	O
</s>
<s>
,	O
where	O
is	O
uniformly	O
random	O
and	O
is	O
chosen	O
randomly	O
from	O
a	O
universal	B-Algorithm
family	I-Algorithm
mapping	O
integer	O
domain	O
.	O
</s>
<s>
This	O
Rabin-Karp	O
rolling	B-Error_Name
hash	I-Error_Name
is	O
based	O
on	O
a	O
linear	B-Algorithm
congruential	I-Algorithm
generator	I-Algorithm
.	O
</s>
<s>
Above	O
algorithm	O
is	O
also	O
known	O
as	O
Multiplicative	O
hash	B-Error_Name
function	I-Error_Name
.	O
</s>
<s>
Other	O
universal	B-Algorithm
families	I-Algorithm
of	O
hash	B-Error_Name
functions	I-Error_Name
used	O
to	O
hash	B-Error_Name
unknown-length	O
strings	O
to	O
fixed-length	O
hash	B-Error_Name
values	I-Error_Name
include	O
the	O
Rabin	B-Algorithm
fingerprint	I-Algorithm
and	O
the	O
Buzhash	O
.	O
</s>
<s>
The	O
NH	O
hash-function	O
family	O
takes	O
this	O
approach	O
.	O
</s>
