message authentication codes and prf …cseweb.ucsd.edu/~mihir/cse207/s-mac.pdf · prf-security,...

46
MESSAGE AUTHENTICATION CODES and PRF DOMAIN EXTENSION Mihir Bellare UCSD 1

Upload: vankhue

Post on 29-Aug-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

MESSAGE AUTHENTICATION CODES

and

PRF DOMAIN EXTENSION

Mihir Bellare UCSD 1

Integrity and authenticity

The goal is to ensure that

• M really originates with Alice and not someone else

• M has not been modified in transit

Mihir Bellare UCSD 2

Integrity and authenticity example

AliceBob(Bank)

Alice

Pay $100 to Charlie

-

Adversary Eve might

• Modify “Charlie” to “Eve”

• Modify “$100” to “$1000”

Integrity prevents such attacks.

Mihir Bellare UCSD 3

Message authentication codes

A message authentication code T : Keys×D → R is a family of functions.The envisaged usage is shown below, where A is the adversary:

T-M

-

- T -

A-

-

M ′

T ′

-

-

V

? ?

K?$

Keys

- d

We refer to T as the MAC or tag. We have defined

Algorithm VK (M ′,T ′)

If TK (M ′) = T ′ then return 1 else return 0

Mihir Bellare UCSD 4

MAC usage

Sender and receiver share key K .

To authenticate M, sender transmits (M,T ) where T = TK (M).

Upon receiving (M ′,T ′), the receiver accepts M ′ as authentic iffVK (M ′,T ′) = 1, or, equivalently, iff TK (M ′) = T ′.

Mihir Bellare UCSD 5

UF-CMA

Let T : Keys× D → R be a message authentication code. Let A be anadversary.

Game UFCMAT

procedure Initialize

K$← Keys ; S ← ∅

procedure Tag(M)T ← TK (M); S ← S ∪ Mreturn T

procedure Finalize(M,T )If M ∈ S then return falseIf M 6∈ D then return falseReturn (T = TK (M))

The uf-cma advantage of adversary A is

Advuf-cmaT (A) = Pr

[UFCMAA

T ⇒ true]

Mihir Bellare UCSD 6

UF-CMA: Explanations

Adversary A does not get the key K .

It can call Tag with any message M of its choice to get back the correcttag T = TK (M).

To win, the adversary A must output a message M ∈ D and a tag T thatare

• Correct: T = TK (M)

• New: M 6∈ S , meaning M was not a query to Tag

Interpretation: Tag represents the sender and Finalize represents thereceiver. Security means that the adversary can’t get the receiver toaccept a message that is not authentic, meaning was not alreadytransmitted by the sender.

Mihir Bellare UCSD 7

Exercise: Tag lengths

Let T : Keys× D → 0, 1` be a message authentication code. Specify inpseudocode an efficient adversary A making zero Tag queries andachieving Advuf-cma

T (A) = 2−`.

Conclusion: Tags have to be long enough.

For 80 bit security, tags have to be at least 80 bits.

Mihir Bellare UCSD 8

Example: Basic CBC MAC

Let E : 0, 1k × B → B be a blockcipher, where B = 0, 1n. View amessage M ∈ B∗ as a sequence of n-bit blocks, M = M[1] . . .M[m].

The basic CBC MAC T : 0, 1k × B∗ → B is defined by

Alg TK (M)

C [0]← 0n

for i = 1, . . . ,m do C [i ]← EK (C [i − 1] ⊕ M[i ])return C [m]

M[1] M[2] M[m]

EK EKEKEK

M[m − 1]

C [m] = TK (M)

Mihir Bellare UCSD 9

Splicing attack on basic CBC MAC

Alg TK (M)

C [0]← 0n

for i = 1, . . . ,m doC [i ]← EK (C [i − 1] ⊕ M[i ])

return C [m]

adversary A

Let x ∈ 0, 1nT1 ← Tag(x)M ← x ||T1 ⊕ xReturn M,T1

Then,

x T1 ⊕ x

T1 T1

EK EK

TK (M) = EK (EK (x) ⊕ T1 ⊕ x)

= EK (T1 ⊕ T1 ⊕ x)

= EK (x)

= T1

Mihir Bellare UCSD 10

Insecurity of basic CBC MAC

Alg TK (M)

C [0]← 0n

for i = 1, . . . ,m doC [i ]← EK (C [i − 1] ⊕ M[i ])

return C [m]

adversary A

Let x ∈ 0, 1nT1 ← Tag(x)M ← x ||T1 ⊕ xReturn M,T1

Then Advuf-cmaT (A) = 1 and A is efficient, so the basic CBC MAC is not

UF-CMA secure.

Mihir Bellare UCSD 11

Exercise

Let E : 0, 1k × 0, 1n → 0, 1n be a blockcipher. Let

D = M ∈ 0, 1∗ : 0 < |M| < n2n and |M| mod n = 0 .Let T : 0, 1k × D → 0, 1n be defined as follows:

Alg TK (M)

M[1] . . .M[m]← M; M[m + 1]← 〈m〉; C [0]← 0n

For i = 1, . . . ,m + 1 do C [i ]← EK (C [i − 1] ⊕ M[i ])T ← C [m + 1]; return T

Above, 〈m〉 denotes the n-bit binary representation of the integer m.

Show that T is not UF-CMA-secure by presenting in pseudocode apractical adversary A making at most 4 Tag queries and achievingAdvuf-cma

T (A) = 1.

Mihir Bellare UCSD 12

Exercise

Let E : 0, 1k × 0, 1n → 0, 1n be a blockcipher. Let

D = M ∈ 0, 1∗ : 0 < |M| < n2n and |M| mod n = 0 .Let T : 0, 1k × D → 0, 1n be defined as follows:

Alg TK (M)

M[1] . . .M[m]← M; C [0]← EK (〈m〉)For i = 1, . . . ,m do C [i ]← EK (C [i − 1] ⊕ M[i ])T ← C [m]; return T

Above, 〈m〉 denotes the n-bit binary representation of the integer m.

Is T UF-CMA-secure? If you say NO, present a practical adversary Aachieving Advuf-cma

T (A) ≥ 1/2. If you say YES, prove this correctassuming E is PRF-secure.

Mihir Bellare UCSD 13

Replay

Suppose Alice transmits (M1,T1) to Bank where M1 =“Pay $100 toBob”. Adversary

• Captures (M1,T1)

• Keeps re-transmitting it to bank

Result: Bob gets $100, $200, $300,...

Our UF-CMA notion of security does not ask for protection against replay,because A will not win if it outputs M,T with M ∈ S , even if T = TK (M)is the correct tag.

Question: Why not?

Answer: Replay is best addressed as an add-on to standard messageauthentication.

Mihir Bellare UCSD 14

Preventing Replay Using Timestamps

Let TimeA be the time as per Alice’s local clock and TimeB the time asper Bob’s local clock.

• Alice sends (M, TK (M),TimeA)

• Bob receives (M,T ,Time) and accepts iff T = TK (M) and|TimeB − Time| ≤ ∆ where ∆ is a small threshold.

Does this work?

Obviously forgery is possible within a ∆ interval. But the main problem isthat TimeA is not authenticated, so adversary can transmit

(M, TK (M),Time1), (M, TK (M),Time2), . . .

for any times Time1,Time2, . . . of its choice, and Bob will accept.

Mihir Bellare UCSD 15

Preventing Replay Using Timestamps

Let TimeA be the time as per Alice’s local clock and TimeB the time asper Bob’s local clock.

• Alice sends (M, TK (M),TimeA)

• Bob receives (M,T ,Time) and accepts iff T = TK (M) and|TimeB − Time| ≤ ∆ where ∆ is a small threshold.

Does this work?

Obviously forgery is possible within a ∆ interval. But the main problem isthat TimeA is not authenticated, so adversary can transmit

(M, TK (M),Time1), (M, TK (M),Time2), . . .

for any times Time1,Time2, . . . of its choice, and Bob will accept.

Mihir Bellare UCSD 16

Preventing Replay Using Timestamps

Let TimeA be the time as per Alice’s local clock and TimeB the time asper Bob’s local clock.

• Alice sends (M, TK (M‖TimeA),TimeA)

• Bob receives (M,T ,Time) and accepts iff TK (M‖Time) = T and|TimeB − Time| ≤ ∆ where ∆ is a small threshold.

Mihir Bellare UCSD 17

Preventing Replay Using Counters

Alice maintains a counter ctrA and Bob maintains a counter ctrB . Initiallyboth are zero.

• Alice sends (M, TK (M‖ctrA)) and then increments ctrA

• Bob receives (M,T ). If TK (M‖ctrB) = T then Bob accepts andincrements ctrB .

Counters need to stay synchronized.

Mihir Bellare UCSD 18

Any PRF is a MAC

If F is PRF-secure then it is also UF-CMA-secure:

Theorem [GGM86,BKR96]: Let F : 0, 1k × D → 0, 1n be a family offunctions. Let A be a uf-cma adversary making q Tag queries and havingrunning time t. Then there is a prf-adversary B such that

Advuf-cmaF (A) ≤ AdvprfF (B) +

2

2n.

Adversary B makes q + 1 queries to its Fn oracle and has running time tplus some overhead.

Exercise: Prove this theorem.

We now give some intuition.

Mihir Bellare UCSD 19

Intuition for why PRFs are UF-CMA-secure

1 Random functions make good (UF-CMA) MACs

2 PRFs are pretty much as good as random functions

For (1), suppose Fn : D → 0, 1n is random and consider A who

• Can query Fn at any points x1, . . . , xq ∈ D it likes

• To win, must output x ,T such that x /∈ x1, . . . , xq but T = Fn(x)

Then,

Pr[A wins] =

1

2n

because A did not query Fn(x).

Mihir Bellare UCSD 20

Intuition for why PRFs are UF-CMA-secure

1 Random functions make good (UF-CMA) MACs

2 PRFs are pretty much as good as random functions

For (1), suppose Fn : D → 0, 1n is random and consider A who

• Can query Fn at any points x1, . . . , xq ∈ D it likes

• To win, must output x ,T such that x /∈ x1, . . . , xq but T = Fn(x)

Then,

Pr[A wins] =1

2n

because A did not query Fn(x).

Mihir Bellare UCSD 21

Intuition for why PRFs are UF-CMA-secure

1 Random functions make good (UF-CMA) MACs

2 PRFs are pretty much as good as random functions

For (2), consider A who

• Can query FK at any points x1, . . . , xq ∈ D it likes

• To win, must output x ,T such that x /∈ x1, . . . , xq but T = FK (x)

If Pr[A wins] is significantly more then 2−n then we are detecting adifference between FK and a random function.

Mihir Bellare UCSD 22

Exercise: PRF 6= UF-CMA

In this exercise you will show that UF-CMA-security does not implyPRF-security, meaning there exist function families that areUF-CMA-secure but not PRF-secure.

You are given F ′: 0, 1k × D → 0, 1n which is UF-CMA-secure.Construct F : 0, 1k × D → 0, 1` such that

(1) F is UF-CMA-secure, but

(2) F is not PRF-secure

Specify F , including specifying `. Then

• Prove (1) by reduction based on the assumed UF-CMA-security of F ′.

• Prove (2) by giving pseudocode for a prf-adversary that hasprf-advantage ≥ 1/2 against F .

Mihir Bellare UCSD 23

PRF domain extension

A family of functions F : Keys× D → R is

• FIL (Fixed-input-length) if D = 0, 1` for some `

• VIL (Variable-input-length) if D is a “large” set like D = 0, 1∗ or

D = M ∈ 0, 1∗ : 0 < |M| < n2n and |M| mod n = 0 .for some n ≥ 1 or ...

We have families we are willing to assume are PRFs, namely blockciphersand compression functions, but they are FIL.

PRF Domain Extension Problem: Given a FIL PRF, construct a VILPRF.

Mihir Bellare UCSD 24

PRF domain extension

PRF Domain Extension Problem: Given a FIL PRF, construct a VILPRF.

The basic CBC MAC is a candidate construction but we saw above that itfails to be UF-CMA and thus also fails to be a PRF. The exercisesexplored other solutions.

We will see solutions that work including

• ECBC: The encrypted CBC-MAC

• CMAC: A NIST standard

• HMAC: A highly standardized and used hash-function based MAC

Mihir Bellare UCSD 25

ECBC MAC

Let E : 0, 1k × B → B be a block cipher, where B = 0, 1n. Theencrypted CBC (ECBC) MAC T : 0, 12k × B∗ → B is defind by

Alg TKin||Kout(M)

C [0]← 0n

for i = 1, ...,m doC [i ]← EKin

(C [i − 1] ⊕ M[i ])T ← EKout (C [m])return T

EKin

M[1] M[2]

EKinEKin

EKin

M[m]

EKout

M[m − 1]

TKin||Kout(M)

Mihir Bellare UCSD 26

Birthday attacks on MACs

There is a large class of MACs, including ECBC MAC, CMAC,HMAC, ...which are subject to a birthday attack that violates UF-CMA using aboutq ≈ 2n/2 Tag queries, where n is the tag (output) length of the MAC.

Furthermore, we can typically show this is best possible, so the birthdaybound is the “true” indication of security.

The class of MACs in question are called iterated-MACs and work byiterating some lower level primitive such as a blockcipher or compressionfunction.

Mihir Bellare UCSD 27

Exercise

Let E : 0, 1k × 0, 1n → 0, 1n be a blockcipher and T thecorresponding ECBC MAC. Let q ≤ 2n/2.

Give an adversary A that, via a birthday attack, achieves

Advuf-cmaT (A) = Ω

(q2

2n

)using q Tag queries and running time O(nq · log(nq)).

Mihir Bellare UCSD 28

Security of ECBC

Birthday attack is best possible:

Theorem: Let E : 0, 1k × B → B be a family of functions, whereB = 0, 1n. Define F : 0, 12k × B∗ → 0, 1n by

Alg FKin||Kout(M)

C [0]← 0n

for i = 1, ...,m do C [i ]← EKin(C [i−1] ⊕ M[i ])

T ← EKout (C [m]); return T

Let A be a prf-adversary against F that makes at most q oracle queries,these totalling at most σ blocks, and has running time t. Then there is aprf-adversary D against E such that

AdvprfF (A) ≤ AdvprfE (D) +σ2

2n

and D makes at most σ oracle queries and has running time about t.

Mihir Bellare UCSD 29

Security of iterated MACs

The number q of m-block messages that can be safely authenticated isabout 2n/2/m, where n is the block-length of the blockcipher, or thelength of the chaining input of the compression function.

MAC n m q

DES-ECBC-MAC 64 1024 222

AES-ECBC-MAC 128 1024 254

AES-ECBC-MAC 128 106 244

HMAC-SHA1 160 106 260

HMAC-SHA256 256 106 2108

m = 106 means message length 16Mbytes when n = 128.

Mihir Bellare UCSD 30

Non-full messages

So far we assumed messages have length a multiple of the block-length ofthe blockcipher. Call such messages full. How do we deal with non-fullmessages?

M[1] M[2] M[3]

The obvious approach is padding. But how we pad matters.

Padding with 0∗:

M[1] M[2] M[3] ‖ 0∗

adversary AT ← Tag(1n1n0); Verify(1n1n00,T )

This adversary has uf-cma advantage 1.

Mihir Bellare UCSD 31

Non-full messages

So far we assumed messages have length a multiple of the block-length ofthe blockcipher. Call such messages full. How do we deal with non-fullmessages?

M[1] M[2] M[3]

The obvious approach is padding. But how we pad matters.

Padding with 0∗:

M[1] M[2] M[3] ‖ 0∗

adversary AT ← Tag(1n1n0); Verify(1n1n00,T )

This adversary has uf-cma advantage 1.

Mihir Bellare UCSD 32

Non-full messages

So far we assumed messages have length a multiple of the block-length ofthe blockcipher. Call such messages full. How do we deal with non-fullmessages?

M[1] M[2] M[3]

The obvious approach is padding. But how we pad matters.

Padding with 0∗:

M[1] M[2] M[3] ‖ 0∗

adversary AT ← Tag(1n1n0); Verify(1n1n00,T )

This adversary has uf-cma advantage 1.

Mihir Bellare UCSD 33

Non-full messages

Padding with 10∗: For a non-full message

M[1] M[2] M[3] ‖ 10∗

For a full message

M[1] M[2] M[3] 10∗

This works, but if M was full, an extra block is needed leading to an extrablockcipher operation.

Mihir Bellare UCSD 34

Costs

Handling length-variablity and non-full messages leads to two extrablockcipher invocations in ECBC MAC as compared to basic CBC MAC.

Also ECBC uses two blockcipher keys and needs to rekey, which isexpensive.

Can we do better?

Mihir Bellare UCSD 35

CMAC

Standards: NIST SP 800-38B, RFCs 4493, 4494, 4615

Features: Handles variable-length and non-full messages with

• Minimal overhead

• A single blockcipher key

Security:

• Subject to a birthday attack

• Security proof shows there is no better attack

History: XCBC[BlRo], OMAC/OMAC1[IW]

Mihir Bellare UCSD 36

CMAC Components and Setup

• E : 0, 1n × 0, 1n → 0, 1n is a blockcipher, in practice AES.

• CBCK (M) is the basic CBC MAC of a full message M under keyK ∈ 0, 1n and using E .

• J ∈ 0, 1n is a particular fixed constant.

CMAC uses its key K ∈ 0, 1n to derive subkeys K1,K2 via

Alg CMAC-KEYGEN(K )

K0 ← EK (0)if msb(K0) = 0 then K1 ← (K0 1) else K1 ← (K0 1) ⊕ Jif msb(K1) = 0 then K2 ← (K1 1) else K2 ← (K1 1) ⊕ JReturn (K1,K2)

where x 1 means x left shifted by 1 bit, so that the msb vanishes andthe lsb becomes 0. These bit operations use simple finite-field operations.

Mihir Bellare UCSD 37

CMAC Algorithm

Alg CMACK (M)

(K1,K2)← CMAC-KEYGEN(K )M[1] . . .M[m − 1]M[m]← M // |M[m]| ≤ n

`← |M[m]| // ` ≤ n

if ` = n then M[m]← K1 ⊕ M[m]else M[m]← K2 ⊕ (M[m]‖10n−`−1)M ← M[1] . . .M[m − 1]M[m]T ← CBCK (M)return T

In an implementation, CMAC-KEYGEN(K ) is run once, meaning K1,K2

are pre-computed, stored and re-used. Performance is then optimal.

Mihir Bellare UCSD 38

MACing with hash functions

The software speed of hash functions (MD5, SHA1) lead people in 1990sto ask whether they could be used to MAC.

But such cryptographic hash functions are keyless.

Question: How do we key hash functions to get MACs?

Proposal: Let H : D → 0, 1n represent the hash function and set

TK (M) = H(K ||M)

Is this UF-CMA / PRF secure?

Mihir Bellare UCSD 39

Extension attack

IV

M[1] M[m]K 〈m + 1〉

H(K ||M)h h h h

h H(K ||M ′)

〈m + 2〉

Let M ′ = M||〈m + 1〉. Then

H(K ||M ′) = h(〈m + 2〉||H(K ||M))

so given the MAC H(K ||M) of M we can easily forge the MAC of M ′.

Exercise: Specify in pseudocode an adversary mounting the above attackto achieve uf-cma advantage 1 using 1 Tag query.

Mihir Bellare UCSD 40

Extension attack

IV

M[1] M[m]K 〈m + 1〉

H(K ||M)h h h h h H(K ||M ′)

〈m + 2〉

Let M ′ = M||〈m + 1〉. Then

H(K ||M ′) = h(〈m + 2〉||H(K ||M))

so given the MAC H(K ||M) of M we can easily forge the MAC of M ′.

Exercise: Specify in pseudocode an adversary mounting the above attackto achieve uf-cma advantage 1 using 1 Tag query.

Mihir Bellare UCSD 41

HMAC [BCK96]

Suppose H: D → 0, 1n is the hash function, built from an underlyingcompression function via the MD transform.

Let B ≥ n/8 denote the byte-length of a message block (B = 64 for MD5,SHA1, SHA256, SHA512)

Define the following constants

• ipad : The byte 36 repeated B times

• opad : The byte 5C repeated B times

Mihir Bellare UCSD 42

HMAC [BCK96]

HMAC: 0, 1n × D → 0, 1n is defined as follows:

Alg HMAC(K ,M)

Ki ← ipad ⊕ K‖08B−n ; Ko ← opad ⊕ K‖08B−nX ← H(Ki‖M) ; Y ← H(Ko‖X )Return Y

hhh

(((- H

hhh

(((- H

? -

Ki‖M

Ko‖X HMACK (M)

Mihir Bellare UCSD 43

HMAC

Features:

• Blackbox use of the hash function, easy to implement

• Fast in software

Usage:

• As a MAC for message authentication

• As a PRF for key derivation

Security:

• Subject to a birthday attack

• Security proof shows there is no better attack [BCK96,Be06]

Adoption and Deployment: HMAC is one of the most widelystandardized and used cryptographic constructs: SSL/TLS, SSH, IPSec,FIPS 198, IEEE 802.11, IEEE 802.11b, ...

Mihir Bellare UCSD 44

HMAC Security

Theorem: [BCK96] HMAC is a secure PRF assuming

• The compression function is a PRF

• The hash function is collision-resistant (CR)

But attacks show MD5 and SHA1 are not CR.

So are HMAC-MD5 and HMAC-SHA1 secure?

• No attacks so far, but

• Proof becomes vacuous!

Theorem: [Be06] HMAC is a secure PRF assuming only

• The compression function is a PRF

Current attacks do not contradict this assumption. This result may explainwhy HMAC-MD5 and HMAC-SHA1 are standing even though the hashfunctions are broken with regard to collision resistance.

Mihir Bellare UCSD 45

HMAC Recommendations

• Don’t use HMAC-MD5

• No immediate need to remove HMAC-SHA1

• Use HMAC-SHA256, HMAC-SHA512 for new applications

Mihir Bellare UCSD 46