Message Authentication and Hash Functions
Message Authentication and Hash Functions
www.dziembowski.net/Studenti/BISS09
Lecture 3
Message Authentication and
Hash Functions
Stefan
Dziembowski
University of Rome
La Sapienza
BiSS 2009
Bertinoro International
Spring School
2-6 March 2009
Plan
1. Introduction to message authentication
codes (MACs).
2. Constructions of MACs:
1. from pairwise independent functions
2. from block ciphers
3. Hash functions
1. a definition
2. constructions
3. the birthday attack
4. concrete functions
5. a construction of MACs from hash functions
6. the random oracle model
Message Authentication
Integrity:
3
Sometimes: more important than
secrecy!
transfer 1000 $ to
Bob
transfer 1000 $ to
Alice Ban
Eve
k
4
Does encryption guarantee message
integrity?
Idea:
verifies if
m
(m, t=Tagk(m))
t=Tagk(m)
Alice Bo
b
k k
6
Message authentication multiple
messages
m1 (m1, t=Tagk(m1))
m2 (m2, t=Tagk(m2))
...
...
Alice Bo
mt (mw, t=Tagk(mw)) b
k k
7
Message Authentication Codes
the idea
Alice Bo
b
k k
k is chosen randomly
from some set T
8
A mathematical view
K key space
M plaintext space
T - set of tags
Correctness
it should always holds that:
Vrfyk(m,Tagk(m)) = yes.
Conventions
If Vrfyk(m,t) = yes then we say that t
is a valid tag on the message m.
m1
adversary
(m1, t=Tagk(m1))
oracle
...
mw
(mw, t=Tagk(mw))
polynomial-time
adversary A
13
Arent we too paranoid?
Maybe it would be enough to require that:
Bad idea:
hard to define,
is application-dependent.
14
Warning: MACs do not offer protection against the replay
attacks.
(m, t)
Alice Bo
) b
,t
(m t)
,
(m )
,t Since Vrfy has no state
(m.. (or memory) there is no
way to detect that (m,t)
is not fresh!
.
Encrypt-and-authenticate: wrong
c Enck1(m) and t Mack2 (m)
Authenticate-then-encrypt: better
t Mack2 (m) and c Enck1(m||t)
Encrypt-then-authenticate: the best
c Enck1(m) and t Mack2 (c)
17
Plan
1. Introduction to message authentication
codes (MACs).
2. Constructions of MACs:
1. from pairwise independent functions
2. from block ciphers
3. Hash functions
1. a definition
2. constructions
3. the birthday attack
4. concrete functions
5. a construction of MACs from hash functions
6. the random oracle model
Information-theoretically secure
MACs
We now show a construction of
information-theoretically secure MACs,
i.e.:
Alice Bo
b
= Zp
= Zp Z p for
for example
example
p
p==2 107- 1
2107 -1
= Zp
Tag((a,b), m) = am + b mod p
Intuition:
...
?
b
...
m0 m1 m0 m1 22
emma. Let (A,B) be distributed uniformly over Zp Zp. Then for every distinct
nd m1 the following variables are independent
(A m0 + B) and (A m1 + B) .
arly, each of those variables is distributed uniformly over Zp and hence of every
have
P (A m0 + B = x) P(A m1 + B = y) = 1/p 1/p = 1/p2
P (A m0 + B = x and A m1 + B = y) = 1/p2
is is equivalent to the fact that the following system of linear equations (over Zp
actly one solution (where a and b are the unknowns):
{ a m0 + b = x
a m1 + b = y
Clearly if m0 m1 then
det
[ m
0
1
] 0
Thus we are done
23
Can we reuse the same key many
times?
After seeing two values:
Tag(k,m0) = A m0 + B
Tag(k,m1) = A m0 + B
(for m0 m1) the adversary can
compute (A,B) by solving a system of
linear equations.
PRG G
k1 k2 k3
...
Tag(k1,m1) Tag(k2,m2) Tag(k3,m3)
one-way functions
exist
Mac(k,m) = F(k,m) m
messages?
Idea 1
divide the message in blocks m1,...,md
and authenticate each block separately
F(k,m1) F(k,md)
...
Fk Fk
m1 md
m:
t=
Tagk(m):
perm
m =
perm(m):
t = perm(t):
30
Idea 2
Add a counter to each block.
F(k,x1) F(k,xd)
...
Fk Fk
1 m1 d md
x1 xd
xi
m:
t=
Tagk(m):
m = a prefix of
m:
t = a prefix
of t:
...
Fk Fk
l 1 m1 l d md
x1 xd
xi
t= t =
Tagk(m): Tagk(m):
F(k,x1) F(k,xd)
...
Fk Fk
r l d md r l d md
x1 xd
This works!
35
tagk(m)
Fk Fk ... Fk
r l 1 m1 r l 2 m2 ... r l d md
x1 x2 xd
Proof idea:
Suppose it is not a secure MAC.
Let A be an adversary that breaks it with a non-
negligible probability.
We construct a distinguisher D that distinguishes
37
F from a random permutation.
This construction is not
practical
Problem:
Fk Fk Fk Fk Fk
m1 m2 m3 ... md
|m|
m 0000
39
tagk(m)
Fk Fk Fk Fk Fk
m1 m2 m3 ... md
|m|
Why is this
needed?
40
t1=tagk(m1) t2=tagk(m2)
the
adversary
chooses: Fk Fk
m1 m2
t= tagk(m)
t1
m 41
Some practictioners dont like the
CBC-MAC
We dont want to
authenticate using the block
ciphers!
What do you want to use
instead?
Hash functions!
Why?
Because:
1. they are more efficient,
2. they are not protected by
the export regulations.
42
Plan
1. Introduction to message authentication
codes (MACs).
2. Constructions of MACs:
1. from pairwise independent functions
2. from block ciphers
3. Hash functions
1. a definition
2. constructions
3. the birthday attack
4. concrete functions
5. a construction of MACs from hash functions
6. the random oracle model
Another idea for authenticating long messages
Fk(h(m))
a block cipher
k Fk
h(m)
a hash function h
long m
collision resistance
Collision-resistant hash
functions
short H(m)
H : {0,1}* {0,1}L
a hash function
long m
collision-resistance a collision
domain
range
m
A bit like:
pseudorandom generators
vs.
cryptographic pseudorandom generators.
48
Practical definition
H is a collision-resistant hash function if it is
practically impossible to find collisions in H.
49
How to formally define collision
resitance?
Idea
Say something like: H is a collision-
resistant hash function if
A P(A finds a collision in H) is
small
efficient
adversary A
Problem
For a fixed H there always exist a constant-time
algorithm that finds a collision in H in constant
time.
It may be hard to find such an algorithm, but it 50
Solution
When we prove theorems we will
always consider
{Hs} s keys
51
informal description:
knows H a protocol
H H
Hs
52
informal description:
knows H a protocol
H H
SHA1 SHA1
SHA1
53
Hash functions the functional
definition
A hash function is a probabilistic
polynomial-time algorithm H such that:
54
Hash functions the security
definition [1/2]
1n
selects a
s random
s {0,1}n
outputs (m,m)
polynomial-time
adversary A
56
How to formalize our idea?
Fk(h(m))
a block cipher
k Fk
h(m)
a hash function h
long m
57
Authentication scheme -
formally
A key for the MAC is a pair:
a key for the hash function
H (s,k) a key for the PRF F
Tag((k,s),m) = Fk(Hs(m))
or
simulates simulates
Do collision-resilient hash functions
belong to minicrypt?
collision-resilient hash
functions exist
easy exercise
? open problem
one-way functions
exist
h(m)
h : {0,1}2L {0,1}L
m
2L
m1 m2 ... mB
mi {0,1}L
...
h h h
IV H(m)
can be
arbitrary
This doesnt work...
62
Why is it wrong?
t
m 0000
m1 m2 ... mB
m 0000
m1 m2 ... mB mB+1 := t
63
Merkle-Damgrd
2L transform
given h : {0,1} {0,1} L
doesnt need to
we construct H : {0,1}* {0,1}L be know in
advance
t (nice!)
m 0000
m1 m2 mB mB+1 := t
mi {0,1} L
...
h h h h
IV H(m)
64
This construction is secure
We would like to prove the following:
Theore
m
If
h : {0,1}2L {0,1}L
is a collision-resistant compression
function
then
H : {0,1}* {0,1}L
is a collision-resistant hash function.
But wait.
It doesnt make sense 65
We need to consider the hash
function families
Suppose (gen,h) is a collision-resistant hash
function such that for every s {0,1}n
we have
hs : {0,1}2L(n) {0,1}L(n)
L(n)
h(m)
m
2L(n)
66
We now show how to transform such
an h into a hash function H.
How?
m 0000
m1 m2 mB mB+1 := t
mi {0,1} L(n)
...
h h h h H(m)
IV
68
This construction is secure
Theorem
If
h
is a collision-resistant hash function
then
H
is a collision-resistant hash function.
Proof
Suppose A is a polynomial-time adversary
that breaks H with a non-negligible
probability.
a breaks hs by
simulating A (m,m)
A breaks Hs
70
How to compute a collision (x,y) in h
from a collision (m,m) in H?
1. |m| = |m|
2. |m| |m|
71
Option 1: |m| = |m|
t
m 0000
m1 m2 mB mB+1 := t
m 0000
m1 m2 mB mB+1 := t
72
|m| = |m|
Some notation:
m 0000
m1 m2 mB mB+1 := t
...
h h h h
IV z1 z2 z3 zB zB+1 H(m)
73
|m| = |m|
For m:
m 0000
m1 m2 mB mB+1 := t
...
h h h h
IV z1 z2 z3 zB zB+1 H(m)
74
zB+2=H(m) equal zB+2=H(m)
mB zB mB zB
...
.
..
z3 z3
m2 z2 not equal m2 z2
m1 z1 = IV m1 z1 = IV
75
zB+2=H(m) equal zB+2=H(m)
Let i* be the
mB zB least i such mB zB
that
...
...
(mi,zi) =
(mi,zi)
m2 z2 m2 z2
(because m
m1 z1 = IV m such an m1 z1 = IV
i* > 1 76
So, we have found a
collision!
h h
77
Option 2: |m| |m|
H(m) equal H(m)
...
the last block encodes
the length on the message
so these values
cannot be equal!
QED
79
Plan
1. Introduction to message authentication
codes (MACs).
2. Constructions of MACs:
1. from pairwise independent functions
2. from block ciphers
3. Hash functions
1. a definition
2. constructions
3. the birthday attack
4. concrete functions
5. a construction of MACs from hash functions
6. the random oracle model
Generic attacks on hash
functions
Remember the brute-force attacks on
the encryption schemes?
81
The birthday paradox
Suppose we have a random function
H:AB
Take n values
x1,...,xn
Let p(n) be the probability that there exist distinct i,j
such that
H(xi) = H(xj).
If n |B| then trivially p(n) = 1.
2
More precisely we n(n-1)
have: p(n) n
4| B| 2 |B|
82
Why is it called a birthday
paradox?
Set:
H : people birthdays
A: 23 is enough!
Counterintuitive... 83
How does the birthday attack
work?
For a hash function
H : {0,1}* {0,1}L
Moral
L has to be such that an attack that needs 2L/2 84
steps is infeasible.
Plan
1. Introduction to message authentication
codes (MACs).
2. Constructions of MACs:
1. from pairwise independent functions
2. from block ciphers
3. Hash functions
1. a definition
2. constructions
3. the birthday attack
4. concrete functions
5. a construction of MACs from hash functions
6. the random oracle model
Concrete functions
MD5,
SHA-1, SHA-256,...
....
all use (variants of) Merkle-Damgrd
transformation.
90
Suppose H was constructed using the
MD-transform
she can fab
ricate this
sh
ec MACk(m||t)
an
se
e thi
s
t zB t zB
m z2 m z2
k IV k IV
L 91
A better idea
M. Bellare, R. Canetti, and H. Krawczyk
(1996):
92
NMAC
m 0000
m1 mB mB+1 := |m|
...
h h h
k1
h
k2 NMAC(k1,k2) (m)
93
What can be proven
Suppose that
1. h is collision-resistant
2. the following function is a secure
MAC:
h
k2 MACk2(m)
HMAC is the
solution!
95
HMAC
k xor ipad m1 mB+1 := |m|
...
h h h
IV
h
IV h HMACk (m)
k xor opad
96
HMAC the properties
a hash function
H : {0,1}* {0,1}L
user generated randomness X (key strokes, mouse movements, etc.)
H(x)
a completely random
H : {0,1}* {0,1}L function
Remember the pseudorandom
functions?
F( x
x)
A random )
x
function F(
F: {0,1}m
{0,1}m
x
)
x
Crucial difference:
F(
a hash function
H : {0,1}* {0,1}L
user generated randomness X
secure in ROM
but
encryption authentication
information-
computational
theoretic,
unconditional
one time pad, based on 2 simultanious
quantum assumptions:
cryptography, 1. some problems are
... computationally difficult
2. our understanding of
what computational
difficulty means is
correct.
Symmetric cryptography
symmetric
cryptograp
hy
encryptio authenticati
n on
Basic information-theoretic
tools
one-way functions
pseudorandom generators
pseudorandom functions/permutations
hash functions
A method for proving security:
reductions
minicrypt P NP
hash functions
one-way
functions
pseudorandom
generators
pseudorandom
functions/permutations
computationally-secure authentication
in general the
computationally-secure encryption picture is much
more
complicated!
Plan for the next lectures
encryption authentication