Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf ·...

34
Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill Adapted from http://cseweb.ucsd.edu/~mihir/cse107/

Transcript of Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf ·...

Page 1: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

Lecture8–MessageAuthenticationCOSC-260CodesandCiphers

AdamO’NeillAdaptedfromhttp://cseweb.ucsd.edu/~mihir/cse107/

Page 2: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

SettingtheStage

• Wenowhavetwolower-levelprimitivesinourtoolbag:blockciphersandhashfunctions.

Page 3: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

SettingtheStage

• Wenowhavetwolower-levelprimitivesinourtoolbag:blockciphersandhashfunctions.

• Todaywestudyoursecondhigher-levelprimitive,messageauthenticationcodes.

Page 4: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

SettingtheStage

• Wenowhavetwolower-levelprimitivesinourtoolbag:blockciphersandhashfunctions.

• Todaywestudyoursecondhigher-levelprimitive,messageauthenticationcodes.

• Notethatauthenticityofdataisarguablyevenmoreimportantthanprivacy.

Page 5: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

SettingandGoals

0*0=05.Alice

Integrity lavthenticity| /

of data. VM

* m is not modified Eve ¥by Eve

^

* Alice really sent on .

Page 6: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

Example:ElectronicBanking

Like

.de#ngtbdI**isaYA { area

Eve could try to change $100 to $1000

or charge Bob to Eve .

Page 7: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

SyntaxandUsageMessage 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

,tag of m upon teaeiry

under key K ( on ,t1 accept on

iff

¢of =

t.sk#jign Bobaffiliates

Page 8: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

UF-CMAUF-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 ∪ {M}return T

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

The uf-cma advantage of adversary A is

Advuf-cmaT (A) = Pr

!

UFCMAAT ⇒ true

"

Mihir Bellare UCSD 6

vhforgeasility under alhosen message attack

o

.

Page 9: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

Lower-BoundonTagLengthConsider an adversary which simply

guesses a tag at random.

Adversary A

t $Rret ( mit ) for some

arbitrary

.me/).AdruytanaCa1=PrTUFCmAF=71T

¥ 1

=> for n - bit security weneed Iog|k/2n .

Page 10: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

BasicCBC-MACExample: Basic CBC MAC

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

The basic CBC MAC T : {0, 1}k × 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

gCipher - block

Chaining .

Adversary A

ma ]

TiMFD T , Tag(MID)

to %Tzttagcoy.)|k .

.

¥¥f¥gy -

IFHEnotcm##ta

end

Page 11: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

SplicingAttackSee pneniovs slide in

Page 12: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

ReplayAttacks

• Referstoareal-lifeadversarybeingabletocaptureandre-transmitamessageandtag.

Page 13: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

ReplayAttacks

• Referstoareal-lifeadversarybeingabletocaptureandre-transmitamessageandtag.

• NotcapturedbyUF-CMA.

Page 14: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

ReplayAttacks

• Referstoareal-lifeadversarybeingabletocaptureandre-transmitamessageandtag.

• NotcapturedbyUF-CMA.• Bestdealtwithasanadd-ontostandardmessageauthentication.

Page 15: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

UsingTimestampsPreventing 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?

Mihir Bellare UCSD 14

the problem is that Time is not authenticated !

Alice should send ( M , Tk ( Mlkineaftinea )

Page 16: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

UsingCounters

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 17

Page 17: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

PRF-as-a-MACAny PRF is a MAC

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

Theorem [GGM86,BKR96]: Let F : {0, 1}k ×D → {0, 1}n 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 t

plus some overhead.

We do not prove this here, but we give a little intuition.

Mihir Bellare UCSD 18

pseudo- random function

- message\ authentication

Code.

Page 18: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

ProofIntuitionThink of eihangin , the OF - CMA game

to

use a truly random function instead of

the PRF .

Notice that the adversary 's advantage can't

change much when this above change is made,

else we Could build a distinguisher against the

PRF .

AdversaryB

Run Awhen A makes a Tag query ×

Return Fncx )

Until A halls with output ( M ,t)If Fn ( m )=t ret I Else Not

Page 19: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

PRFDomainExtension

• WehaveblockciphersthataregoodPRFsbutarefixed-input-length(FIL).

Page 20: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

PRFDomainExtension

• WehaveblockciphersthataregoodPRFsbutarefixed-input-length(FIL).

• WantaMACthatisvariable-input-length(VIL).

Page 21: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

PRFDomainExtension

• WehaveblockciphersthataregoodPRFsbutarefixed-input-length(FIL).

• WantaMACthatisvariable-input-length(VIL).• BypriorresultthisreducestobuildingaVIL-PRFfromaFIL-PRF(aka.PRFdomainextension).

Page 22: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

ECBC-MACECBC MAC

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

Alg TKin||Kout(M)

C [0]← 0n

for i = 1, ...,m do

C [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 24

yen

crypt

Ee⇐¥w

Page 23: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

BirthdayAttacksIden : Query Fu on a sequence of 1- block

messages M, ,

...

, Mq and See if any of

the outputs collide .

Adversary AqFor it to q

¥#CGie) ) Yitec 'M

1-aid= (fyq) If Fiiijz st. Y ; ,=Y ; ,

then net 0animal.si#ek:.EIenai*?P

Page 24: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

TheoremSecurity of ECBC

Birthday attack is best possible:

Theorem: Let E : {0, 1}k × B → B be a family of functions, whereB = {0, 1}n . Define F : {0, 1}2k × B∗ → {0, 1}n 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 B against E such that

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

2n

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

Mihir Bellare UCSD 27e. 9 . with,AES-128 Can MAC messageswith total block length up to 264

.

Page 25: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

ProofIntuition

Page 26: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

ImplicationsSecurity 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 28

Page 27: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

MACingwithHashFunctionMACing 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, 1}n represent the hash function and set

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

Is this UF-CMA / PRF secure?

Mihir Bellare UCSD 29

GSHAI

No in the case that hash function

is constructed Via the MD paradigm .

Page 28: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

Length-ExtensionAttack

1€14M

'

HKKMHMYµo¥a¥iei±* ↳##{impression function mapping ntb bits

to h bits

can compile compression function!

MHTFHHAMHDHM

')

Adversary A net ( it' )

Tttagcm)

y h(HIM ' )

T ' a(y11k1@lm'Hb)

Page 29: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

HMAC[BCK’96]HMAC [BCK96]

Suppose H : D → {0, 1}160 is the hash function. HMAC has a 160-bit keyK . Let

Ko = opad ⊕ K ||0352 and Ki = ipad ⊕ K ||0352

whereopad = 5D and ipad = 36

in HEX. ThenHMACK (M) = H(Ko ||H(Ki ||M))

❤❤❤

✭✭✭

✲ H

❤❤❤

✭✭✭

✲ H❄

Ki∥M

Ko∥X HMACK (M)

Mihir Bellare UCSD 32

t¥t the case for SHAI ,can

use other hash function

#0¥08:{green,

ko

¥1Killm) TKDIHCKIHM ) ]b¥11'5#YD Hnacdm)

Page 30: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

SecurityResultsHMAC Security

Theorem: [BCK96] HMAC is a secure PRF assuming

• The compression function is a PRF

• The hash function is collision-resistant (CR)

But recent attacks show MD5 is not CR and SHA1 may not be either.

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 new result mayexplain why HMAC-MD5 is standing even though MD5 is broken withregard to collision resistance.

Mihir Bellare UCSD 34

yinttdpa-

Page 31: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

Recommendations

• Don’tuseHMAC-MD5.

Page 32: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

Recommendations

• Don’tuseHMAC-MD5.• NoimmediateneedtoremoveHMAC-SHA1.

Page 33: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

Recommendations

• Don’tuseHMAC-MD5.• NoimmediateneedtoremoveHMAC-SHA1.• ButfornewapplicationsbesttouseHMAC-SHA2-d(ford=256,512)orHMAC-SHA3.

Page 34: Lecture 8 – Message Authenticationpeople.cs.georgetown.edu/~adam/sp16260/cs260-lec8.pdf · Lecture 8 – Message Authentication COSC-260 Codes and Ciphers Adam O’Neill ... random

Carter-WegmanMACs