Top Banner
Lecture 2 Message Authentication Stefan Dziembowski University of Rome La Sapienza
92
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 2   Message Authentication

Lecture 2Message Authentication

Stefan DziembowskiUniversity of Rome

La Sapienza

Page 2: Lecture 2   Message Authentication

Plan

1. Introduction to message authentication codes (MACs).

2. Constructions of MACs block ciphers3. Hash functions

1. a definition2. constructions3. the “birthday attack”4. a construction of MACs from hash functions5. the random oracle model

Page 3: Lecture 2   Message Authentication

Secure communication

encryption authentication

private key private key encryption

private key authentication

public key public keyencryption signatures

1

3

2

4

Page 4: Lecture 2   Message Authentication

4

Message AuthenticationIntegrity:

M

interferes with the transmission(modifies the message, or inserts a new one)

Alice Bob

How can Bob be sure that M really comes from Alice?

Page 5: Lecture 2   Message Authentication

5

Sometimes: more important than secrecy!

Alice Banktransfer 1000 $ to Eve

transfer 1000 $ to Bob

Of course: usually we want both secrecy and integrity.

Page 6: Lecture 2   Message Authentication

6

Does encryption guarantee message integrity?

Idea:

1. Alice encrypts m and sends c=Enc(k,m) to Bob.2. Bob computes Dec(k,m), and if it “makes sense” accepts it.

Intuiton: only Alice knows k, so nobody else can produce a valid

ciphertext.

It does not work!

Example: one-time pad.

transfer 1000 $ to Bob

key K

ciphertext C

plaintext M

xor

If Eve knows M and C then she can calculate K and produce a ciphertext

of any other message

Page 7: Lecture 2   Message Authentication

7

Message authentication

Alice Bob

(m, t=Tagk(m))

Eve can see (m, t=Tagk(m))

She should not be able to compute a valid tag t’ on any other message m’.

k k

mverifies ift=Tagk(m)

Page 8: Lecture 2   Message Authentication

8

Message authentication – multiple messages

Alice Bob

(m1, t1 =Tagk(m1))

Eve should not be able to compute a valid tag t’ on any other message m’.

k k

(m2, t2 =Tagk(m2))m2

m1

(mw, tw =Tagk(mw))mt

. . .

. . .

Page 9: Lecture 2   Message Authentication

9

Alice Bob

(m, t=Tagk(m))

k k

m є {0,1}*

k is chosen randomly from some set K

Vrfyk(m,t) є {yes,no}

Message Authentication Codes – the idea

Page 10: Lecture 2   Message Authentication

A mathematical viewK – key spaceM – plaintext spaceT - set of tags

A MAC scheme is a pair (Tag, Vrfy), where Tag : K × M → T is an tagging algorithm, Vrfy: K × M × T → {yes, no} is a verification algorithm.

We will sometimes write Tagk(m) and Vrfyk(m,t) instead of Tag(k,m) and Vrfy(k,m,t).

Correctnessit should always holds that:Vrfyk(m,Tagk(m)) = yes.

Page 11: Lecture 2   Message Authentication

Conventions

If Tag is deterministic, then Vrfy just computes Tag and compares the result.

In this case we do not need to define Vrfy explicitly.

If Vrfyk(m,t) = yes then we say that t is a valid tag on the message m.

Page 12: Lecture 2   Message Authentication

12

Therefore we assume that

1. The adversary is allowed to chose m1,...,mw.

2. The goal of the adversary is to produce a valid tag onsome m’ such that m’ ≠ m1,...,mw.

How to define security?We need to specify:

1. how the messages m1,...,mw are chosen,

2. what is the goal of the adversary.

Good tradition: be as pessimistic as possible!

Page 13: Lecture 2   Message Authentication

13

security parameter1n

selects random a k Є {0,1}n

oracle

m1

mw

. . .

(m1, t=Tagk(m1))

(mw, t=Tagk(mw))

We say that the adversary breaks the MAC scheme at the end she outputs (m’,t’) such that

Vrfy(m’,t’) = yesand

m’ ≠ m1,...,mw

adversary

Page 14: Lecture 2   Message Authentication

14

The security definition

We say that (Tag,Vrfy) is secure if

Apolynomial-time

adversary A

P(A breaks it) is negligible (in n)

Page 15: Lecture 2   Message Authentication

15

Aren’t we too paranoid? Maybe it would be enough to require that:

the adversary succeds only if he forges a message that “makes sense”.

(e.g.: forging a message that consists of random noise should not count)

Bad idea:

• hard to define,• is application-dependent.

Page 16: Lecture 2   Message Authentication

16

Warning: MACs do not offer protection against the “replay attacks”.

Alice Bob

(m, t)

(m, t)

(m, t)

(m, t)

. . .Since Vrfy has no state (or

“memory”) there is no way to detect that (m,t) is not fresh!

This problem has to be solved by the higher-level application(methods: time-stamping, sequence numbers...).

Page 17: Lecture 2   Message Authentication

Authentication and EncryptionOptions:• Encrypt-and-authenticate:

c := Enck1(m) and t := Tagk2 (m), send (c,t)

• Authenticate-then-encrypt:t := Tagk2 (m) and c := Enck1(m||t), send (c,t)

• Encrypt-then-authenticate:c := Enck1(m) and t := Tagk2 (c), send (c,t)

wrong

better

the best

m t := Tagk2 (m)c := Enck1(m)

m t := Tagk2 (m)c := Enck1(m ||t)

mt := Tagk2 (c) c := Enck1(m)

Page 18: Lecture 2   Message Authentication

18

Constructing a MAC

1. There exist MACs that are secure even if the adversary is infinitely-powerful.These constructions are not practical.

2. MACs can be constructed from the block-ciphers. We will now discuss to constructions:– simple (and not practical),– a little bit more complicated (and practical) – a CBC-MAC

3. MACs can also be constructed from the hash functions (NMAC, HMAC).

Page 19: Lecture 2   Message Authentication

Plan

1. Introduction to message authentication codes (MACs).

2. Constructions of MACs from block ciphers3. Hash functions

1. a definition2. constructions3. the “birthday attack”4. concrete functions5. a construction of MACs from hash functions6. the random oracle model

Page 20: Lecture 2   Message Authentication

20

A simple construction from a block cipherLet

F : {0,1}n × {0,1}n → {0,1}n

be a block cipher.

We can now define a MAC scheme that works only for messages m Є {0,1}n as follows:

• Tag(k,m) = F(k,m)

It can be proven that it is a secure MAC.

How to generalize it to longer messages?

Fkk

m

F(k,m)

Page 21: Lecture 2   Message Authentication

21

Idea 1

Fk

m1

F(k,m1)

Fk

md

F(k,md)

. . .

• divide the message in blocks m1,...,md

• and authenticate each block separately

This doesn’t work!

Page 22: Lecture 2   Message Authentication

22

t = Tagk(m):

m:

t’ = perm(t):

m’ = perm(m):

perm

Then t’ is a valid tag on m’.

What goes wrong?

Page 23: Lecture 2   Message Authentication

23

Idea 2

Fk

m1

F(k,x1)

Fk

md

F(k,xd)

. . .

Add a counter to each block.

This doesn’t work either!

1 d

x1 xd

Page 24: Lecture 2   Message Authentication

24

xi

m:

t = Tagk(m):

m’ = a prefix of m:

t’ = a prefix of t:

Then t’ is a valid tag on m’.

mii

Page 25: Lecture 2   Message Authentication

25

Idea 3

Fk

m1

F(k,x1)

Fk

md

F(k,xd)

. . .

Add l := |m| to each block

This doesn’t work either!

1 dl l

x1 xd

Page 26: Lecture 2   Message Authentication

26

What goes wrong? xi

m:

t = Tagk(m):

m’:

t’ = Tagk(m’):

m’’ = first half from m || second half from m’

t’’ = first half from t || second half from t’

Then t’’ is a valid tag on m’’.

m1 1l

Page 27: Lecture 2   Message Authentication

27

Idea 4

Fk

F(k,x1)

Fk

md

F(k,xd)

. . .

Add a fresh random value to each block!

This works!

dl

x1 xd

r md dlr

Page 28: Lecture 2   Message Authentication

28pad with zeroes if needed

Fk

F(k,x1)

m

1lr

Fk

F(k,x2)

m22r

Fk

F(k,xd)

mddr

m1 m2 md. . .

. . .

. . .

m1

l

ll

x1x2 xd

|mi| = n/4

r is chosen randomly

r

tagk(m)

000

n – block length

Page 29: Lecture 2   Message Authentication

29

This construction can be proven secure

TheoremAssuming that

F : {0,1}n × {0,1}n → {0,1}n is a pseudorandom permutationthe construction from the previous slide is a secure MAC.

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 F from a

random permutation.

Page 30: Lecture 2   Message Authentication

A new member of “Minicrypt”

computationally-secureMACs exist

cryptographic PRGsexist

one-way functionsexist

this we already knew

this we have just proven

this can be proven

Page 31: Lecture 2   Message Authentication

31

Problem:

The tag is 4 times longer than the message...

This construction is not practical

We can do much better!

Page 32: Lecture 2   Message Authentication

32

CBC-MAC

m

m1 m2 m3 md. . .

pad with zeroes if needed

0000

|m|

Fk Fk Fk Fk Fk

tagk(m)

F : {0,1}n × {0,1}n → {0,1}n - a block cipher

Other variants exist!

Page 33: Lecture 2   Message Authentication

33

m1 m2 m3 md. . . |m|

Fk Fk Fk Fk Fk

Why is this needed?

Suppose we do not prepend |m|...

tagk(m)

Page 34: Lecture 2   Message Authentication

34

m1

Fk

t1=tagk(m1)

m2

Fk

t2=tagk(m2)

m1 m2 xor t1

Fk Fk

t’= tagk(m’)

m’

t’ = t2t1

the adversarychooses:

now she can compute:

m2

Page 35: Lecture 2   Message Authentication

35

Some practictioners don’t like the CBC-MAC

We don’t want to authenticate using the block ciphers!

What do you want to use instead?

Because:1. they are more efficient,2. they are not protected by the

export regulations.

Why?

Hash functions!

Page 36: Lecture 2   Message Authentication

Plan1. Introduction to message authentication codes

(MACs).2. Constructions of MACs:

1. from pairwise independent functions2. from block ciphers

3. Hash functions1. a definition2. constructions3. the “birthday attack”4. concrete functions5. a construction of MACs from hash functions6. the random oracle model

Page 37: Lecture 2   Message Authentication

37

Another idea for authenticating long messages

a “hash function” h

h(m)

long m

a block cipherFk

k

Fk(h(m))

By the way: a similar method is used in the public-key cryptography (it is called “hash-and-sign”).

Page 38: Lecture 2   Message Authentication

How to formalize it?We need to define what is a “hash function”.

The basic property that we require is:

“collision resistance”

Page 39: Lecture 2   Message Authentication

39

Collision-resistant hash functions

a hash functionH : {0,1}* → {0,1}L

short H(m)

long m

Requirement: it should be hard to find a pair (m,m’) such that H(m) =H(m’)

a “collision”collision-resistance

Page 40: Lecture 2   Message Authentication

40

Collisions always exist

domainrange

m

m’

Since the domain is larger than the range the

collisions have to exist.

Page 41: Lecture 2   Message Authentication

41

“Practical definition”H is a collision-resistant hash function if it is “practically

impossible to find collisions in H”.

Popular hash funcitons:

• MD5 (now considered broken)• SHA1• ...

Page 42: Lecture 2   Message Authentication

42

How to formally define “collision resitance”?

IdeaSay something like: H is a collision-resistant hash

function ifAefficient

adversary A

P(A finds a collision in H) is small

ProblemFor 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 always exists!

Page 43: Lecture 2   Message Authentication

43

families of hash functionsindexed by a key s

{Hs} s є keys

SolutionWhen we prove theorems we will always

consider

Page 44: Lecture 2   Message Authentication

44

H

H

H

Hs

Hs

Hs

s

formal model:

informal description:“knows H”

s is chosenrandomly

a protocol

a protocol

Page 45: Lecture 2   Message Authentication

45

H

H

H

SHA1

SHA1

SHA1

real-life implementation (example):

informal description:“knows H”

“knows SHA1”

H

a protocol

a protocol

Page 46: Lecture 2   Message Authentication

46

H takes as input a key s є {0,1}n and a message x є {0,1}* and outputs a string

Hs(x) є {0,1}L(n)

where L(n) is some fixed function.

Hash functions – the functional definition

A hash function is a probabilistic polynomial-time algorithm H such that:

Page 47: Lecture 2   Message Authentication

47

Hash functions – the security definition [1/2]1n

selects a random s є {0,1}n s

outputs (m,m’)

We say that adversary A breaks the function H if Hs(m) = Hs(m’).

Page 48: Lecture 2   Message Authentication

48

H is a collision-resistant hash function if

Hash functions – the security definition [2/2]

Apolynomial-time

adversary A

P(A breaks H) is negligible

Page 49: Lecture 2   Message Authentication

49

How to formalize our idea?

a “hash function” h

h(m)

long m

a block cipherFk

k

Fk(h(m))

Page 50: Lecture 2   Message Authentication

Authentication scheme - formallyA key for the MAC is a pair:

(s,k)a key for the hash function H a key for the PRP F

Tag((k,s),m) = Fk(Hs(m))

Theorem. If H and F are secure then Tag is secure.

This is proven as follows. Suppose we have an adversary that breaks Tag. Then we can construct:

simulates simulates

a distinguisher for F an adversary for H

or

Page 51: Lecture 2   Message Authentication

Do collision-resilient hash functions belong to minicrypt?

[D. Simon: Finding Collisions on a One-Way Street: Can Secure Hash Functions Be Based on General Assumptions? 1998]:

there is no “black-box reduction”.

collision-resilient hash functions exist

one-way functionsexist

? open problemeasy exercise

Page 52: Lecture 2   Message Authentication

52

A common method for constructing hash functions

1. Construct a “fixed-input-length” collision-resistant hash function

Call it: a collision-resistant compression function.

2. Use it to construct a hash function.

h : {0,1}2·L → {0,1}L

h(m)

m

L

2·L

Page 53: Lecture 2   Message Authentication

53

An idea

m

h h

m1

h

m2 mB

IV

0000

pad with zeroesif needed

. . .

t

mi є {0,1}L

H(m)

can be arbitrary

This doesn’t work...

. . .

Page 54: Lecture 2   Message Authentication

54

Why is it wrong?

m

m1 m2 mB

0000

t

If we set m’ = m || 0000 then H(m’) = H(m).

Solution: add a block encoding “t”.

m’

m’1 m’2 m’B

0000

t

m’B+1 := t

. . .

. . .

Page 55: Lecture 2   Message Authentication

55

Merkle-Damgård transform

m

h h h

m1

h

m2 mB mB+1 := t

IV

0000

. . .

t

given h : {0,1}2L → {0,1}L

we construct H : {0,1}*→ {0,1}L

mi є {0,1} L

H(m)

doesn’t need to be know in advance

(nice!)

Page 56: Lecture 2   Message Authentication

56

This construction is secureWe would like to prove the following:

If h : {0,1}2L → {0,1}L

is a collision-resistant compression functionthen

H : {0,1}*→ {0,1}L

is a collision-resistant hash function.

But wait….It doesn’t make sense…

Theorem

Page 57: Lecture 2   Message Authentication

What to do?

To be formal, we would need to consider families of functions

h and Hindexed by key s

Let’s stay on the informal level and “argue” that:“if one can find a collision in H then one can find

a collision in h”

Page 58: Lecture 2   Message Authentication

58

A breaks H

a breaks h (m,m’)

a collision in H

outputs a collision (x,y) in h

Page 59: Lecture 2   Message Authentication

59

How to compute a collision (x,y) in h from a collision (m,m’) in H?

We consider two options:

1. |m| = |m’|

2. |m| ≠ |m’|

Page 60: Lecture 2   Message Authentication

60

Option 1: |m| = |m’|

m

m1 m2 mB mB+1 := t

0000

t

m

m1 m2 mB mB+1 := t

0000

t

Page 61: Lecture 2   Message Authentication

61

|m| = |m’|

m

h h h

m1

h

m2 mB mB+1 := t

z2IV

0000

. . .

H(m)z1 z3 zB+1zB

Some notation:

Page 62: Lecture 2   Message Authentication

62

|m| = |m’|

m’

h h h

m’1

h

m’2 m’B m’B+1 := t

z’2IV

0000

. . .

H(m’)z’1 z’3 z’B+1z’B

For m’:

Page 63: Lecture 2   Message Authentication

63z1 = IVm1

z2m2

zBmB

zB+1mB+1

. . .

z’1 = IVm’1

z’2m’2

z’Bm’B

z’B+1m’B+1

. . .equalzB+2=H(m) zB+2=H(m’)

not equal

z3 z3

Page 64: Lecture 2   Message Authentication

64z1 = IVm1

z2m2

zBmB

zB+1mB+1

. . .

z’1 = IVm’1

z’2m’2

z’Bm’B

z’B+1m’B+1

. . .equalzB+2=H(m)

Let i* be the least i such that

(mi,zi) = (m’i,z’i)

(because m ≠ m’ such an i* > 1 always exists!)

zB+2=H(m’)

Page 65: Lecture 2   Message Authentication

65

So, we have found a collision!

zi*-1mi*-1

zi*

z’i*-1m’i*-1

z’i*

not equal

equal

h h

Page 66: Lecture 2   Message Authentication

66

Option 2: |m| ≠ |m’|

zB+1mB+1 z’B’+1m’B’+1

equalH(m) H(m’)

. . .

. . .

the last block encodesthe length on the message

so these valuescannot be equal!

So, again we have found a collision!

Page 67: Lecture 2   Message Authentication

67

Concrete functions

• MD5,• SHA-1, SHA-256,...• ....all use (variants of) Merkle-Damgård

transformation.

Hash functions can also be constructed using the number theory.

Page 68: Lecture 2   Message Authentication

Plan1. Introduction to message authentication codes

(MACs).2. Constructions of MACs:

1. from pairwise independent functions2. from block ciphers

3. Hash functions1. a definition2. constructions3. the “birthday attack”4. concrete functions5. a construction of MACs from hash functions6. the random oracle model

Page 69: Lecture 2   Message Authentication

69

What the industry says about the “hash and authenticate” method?

the block cipher is still there...

Why don’t we just hash a message together with a key:

MACk(m) = H(k || m)?

It’s not secure!

Page 70: Lecture 2   Message Authentication

70

Suppose H was constructed using the MD-transform

IVk

z2m

zBt

MACk(m)

IVk

z2m

zBt

MACk(m||t)

t + L MACk(m)

L

she can see this

she can fabricate this

Page 71: Lecture 2   Message Authentication

71

Again, let h : {0,1}2L → {0,1}L be a compression function.

A better ideaM. Bellare, R. Canetti, and H. Krawczyk (1996):

• NMAC (Nested MAC)• HMAC (Hash based MAC)

have some “provable properites”

They both use the Merkle-Damgård transform.

Page 72: Lecture 2   Message Authentication

72

NMAC

m

h h

m1

h

mB mB+1 := |m|

k1

0000

. . .

hk2 NMAC(k1,k2) (m)

Page 73: Lecture 2   Message Authentication

73

What can be provenSuppose that1. h is collision-resistant2. the following function is a secure MAC:

Then NMAC is a secure MAC.

hk2 MACk2(m)

m

Page 74: Lecture 2   Message Authentication

74

Looks better, but

1. our libraries do not permit to change the IV

2. the key is too long: (k1,k2)

HMAC is the solution!

Page 75: Lecture 2   Message Authentication

75

HMAC

h h

k xor ipad

h

m1 mB+1 := |m|

IV

. . .

hIV HMACk (m)h

k xor opad

ipad = 0x36 repeatedopad = 0x5C repeated

Page 76: Lecture 2   Message Authentication

76

HMAC – the properties

Looks complicated, but it is very easy to implement (given an implementation of H):

HMACk(m) = H((k xor opad) || H(k xor ipad || m))

It has some “provable properties” (slightly weaker than NMAC).

Widely used in practice.We like it!

Page 77: Lecture 2   Message Authentication

Plan1. Introduction to message authentication codes

(MACs).2. Constructions of MACs:

1. from pairwise independent functions2. from block ciphers

3. Hash functions1. a definition2. constructions3. the “birthday attack”4. concrete functions5. a construction of MACs from hash functions6. the random oracle model

Page 78: Lecture 2   Message Authentication

Other uses of “hash functions”Hash functions are used by practicioners to convert “non-uniform

randomness” into a uniform one.

shorter “uniformly random” H(m)

user generated randomness X (key strokes, mouse movements, etc.)

a hash functionH : {0,1}* → {0,1}L

Example:

Page 79: Lecture 2   Message Authentication

Example: password-based encryption

c = E(H(π),m)Alice Bob

H – hash function(E,D) – encryption scheme

shared password π shared password π

messagem m = D(H(π),c)

Informally:The only thing that Eve can do is to examine all possible passwords .

Warning:there exist much better solutions for this problem

Page 80: Lecture 2   Message Authentication

Random oracle model[Bellare, Rogaway, Random Oracles are Practical:

A Paradigm for Designing Efficient Protocols, 1993]

Idea: model the hash function as a random oracle.

H : {0,1}* → {0,1}La completely random

function

x

H(x)

Page 81: Lecture 2   Message Authentication

Remember the pseudorandom functions?

A random functionF: {0,1}m → {0,1}m

x

F(x)x’

F(x’)

x’’F(x

’’)

Crucial difference:Also the adversary can query the oracle

Page 82: Lecture 2   Message Authentication

82

H

formal model:

informal description:“knows H”

a protocol

a protocolH : {0,1}* → {0,1}L

Every call to H is replaced with a query to the oracle.

also the adversary is allowed to query the oracle.

Page 83: Lecture 2   Message Authentication

How would we use it in the proof?shorter “uniformly random” H(X)

user generated randomness X

a hash functionH : {0,1}* → {0,1}L

As long as the adversary never queried the oracle on X the value H(X) “looks completely random to him”.

Page 84: Lecture 2   Message Authentication

Criticism of the Random Oracle Model

There exists a signature scheme that is

• secure in ROM

but

• is not secure if the random oracle is replaced with any real hash function.

This example is very artificial. No “realistic” example of this type is know.

[Canetti, Goldreich, Halevi: The random oracle methodology, revisited. 1998]

Page 85: Lecture 2   Message Authentication

Terminology

Model without the random oracles:•“plain model”•“cryptographic model”

Random Oracle Model is also called:the “Random Oracle Heuristic”.

Common view: a ROM proof is better than nothing.

Page 86: Lecture 2   Message Authentication

Plan

1. Introduction to message authentication codes (MACs).

2. Constructions of MACs:1. from pairwise independent functions2. from block ciphers

3. Hash functions1. a definition2. constructions3. a construction of MACs from hash functions4. the random oracle model

Page 87: Lecture 2   Message Authentication

Secure communication

encryption authentication

private key private key encryption

private key authentication

public key public keyencryption signatures

1

3

2

4

Page 88: Lecture 2   Message Authentication

Outlook

• one time pad,• quantum cryptography,• ...

based on 2 simultanious assumptions:

1. some problems are computationally difficult

2. our understanding of what “computational difficulty” means is correct.

cryptography

“information-theoretic”, “unconditional” “computational”

Page 89: Lecture 2   Message Authentication

Symmetric cryptography

symmetric cryptography

encryption authentication

Page 90: Lecture 2   Message Authentication

The basic information-theoretic tool

xor (one-time pad)

Page 91: Lecture 2   Message Authentication

Basic tools from the computational cryptography

• one-way functions• pseudorandom generators• pseudorandom functions/permutations• hash functions

Page 92: Lecture 2   Message Authentication

A method for proving security: reductions

one-way functions

computationally-secure encryption

computationally-secure authentication

pseudorandom generators

pseudorandom functions/permutations

hash functions

P ≠ NP

in general the picture is much more complicated!

minicrypt