Top Banner
Tadayoshi Kohno CSE 490K Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s
138

Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Jun 13, 2020

Download

Documents

dariahiddleston
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: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Tadayoshi Kohno

CSE 490K

Cryptography:Symmetric Foundations

Slides derived from Vitaly Shmatikov’s

Page 2: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Problem

Alice Bob

MM

Basic Internet model: Communications through untrusted intermediaries.

Page 3: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Problem

Alice Bob

MM

Basic Internet model: Communications through untrusted intermediaries.

Page 4: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Problem

Alice Bob

MM

Basic Internet model: Communications through untrusted intermediaries.

I know M (attack privacy)

Page 5: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Problem

Alice Bob

MM

Basic Internet model: Communications through untrusted intermediaries.

I know M (attack privacy)I can change M (attack integrity)

M’

Page 6: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Problem

Alice Bob

MM

Basic Internet model: Communications through untrusted intermediaries.

I know M (attack privacy)I can change M (attack integrity)

M’

Important for: Secure remote logins, file transfers, web access, ....

Page 7: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Symmetric Setting

MEncapsulate Decapsulate

M

Adversary

Symmetric setting: Both parties share some secret information, called a key.

Alice Bob

Solution: Encapsulate and decapsulate messages in some secure way.

Page 8: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Symmetric Setting

MEncapsulate Decapsulate

M

Adversary

Symmetric setting: Both parties share some secret information, called a key.

Alice Bob

K K

Solution: Encapsulate and decapsulate messages in some secure way.

Page 9: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Symmetric Setting

MEncapsulate Decapsulate

M

Adversary

Symmetric setting: Both parties share some secret information, called a key.

Alice BobK KK K

Solution: Encapsulate and decapsulate messages in some secure way.

Page 10: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Achieving Privacy

Encryption schemes

M CEncrypt

K

Decrypt

K

M

Adversary

Key . . . . . . . . . . . . . . . K

. . . . . . . . . .Message M

. . . . . . .Ciphertext C

Alice Bob

K K

Page 11: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Achieving Integrity

Message authentication schemes or message authentication codes or MACs

Alice Bob

K K

Mvalid/invalidT

MAC

K

(M,T)Verify

K

Key . . . . . . . . . . . . . . . K

. . . . . . . . . .Message M

. . . . . . . . . . . . . . . . Tag T Adversary

Page 12: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Achieving Both Privacy and Integrity

Authenticated encryption scheme

Alice Bob

K K

M/invalid

K K

MEncrypt Decrypt

C

Key . . . . . . . . . . . . . . . K

. . . . . . . . . .Message M

. . . . . . .Ciphertext C Adversary

(Authenticated encryption notion is “new” (around 2000), so many books and protocols don’t discuss this. Can be subtle!!!)

Page 13: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

How this is achieved Layered approach:

• Cryptographic primitives, like block ciphers, stream ciphers, and hash functions

• Cryptographic protocols, like CBC mode encryption, CTR mode encryption, HMAC message authentication

Today:• Study the above. Basic concepts. Basic pitfalls.

block cipher hash functions

CBC encryption CTR encryption HMAC auth.

OCB auth. encryption CBC-MAC auth.

Page 14: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Asymmetric Setting (NOT today)

MEncapsulate Decapsulate

M

Adversary

Asymmetric setting: Public and Secret keys. (Can help establish shared secret keys K.)

Alice Bob

PKA,SKA PKB,SKB

Page 15: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Asymmetric Setting (NOT today)

MEncapsulate Decapsulate

M

Adversary

Asymmetric setting: Public and Secret keys. (Can help establish shared secret keys K.)

Alice Bob

PKA,SKA PKB,SKB

PKB PKA

Page 16: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Asymmetric Setting (NOT today)

MEncapsulate Decapsulate

M

Adversary

Asymmetric setting: Public and Secret keys. (Can help establish shared secret keys K.)

Alice BobPKA,SKBPKB,SKAPKA,SKA PKB,SKB

PKB PKA

Page 17: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

One-Time Pad

= 10111101…---------------

= 00110010… 10001111… ⊕

00110010… = ⊕

10111101…

Key is a random bit sequenceas long as the plaintext

Encrypt by bitwise XOR ofplaintext and key:ciphertext = plaintext ⊕ key

Decrypt by bitwise XOR ofciphertext and key:ciphertext ⊕ key = (plaintext ⊕ key) ⊕ key =plaintext ⊕ (key ⊕ key) =plaintext

Cipher achieves perfect secrecy if and only if there are as many possible keys as possible plaintexts, andevery key is equally likely (Claude Shannon)

Page 18: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Advantages of One-Time Pad

Easy to compute• Encryption and decryption are the same operation• Bitwise XOR is very cheap to compute

As secure as theoretically possible• Given a ciphertext, all plaintexts are equally likely,

regardless of attacker’s computational resources• …as long as the key sequence is truly random

– True randomness is expensive to obtain in large quantities

• …as long as each key is same length as plaintext– But how does the sender communicate the key to receiver?

Page 19: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Disadvantages

= 10111101…---------------

= 00110010… 10001111… ⊕

00110010… = ⊕

10111101…

Key is a random bit sequenceas long as the plaintext

Encrypt by bitwise XOR ofplaintext and key:ciphertext = plaintext ⊕ key

Decrypt by bitwise XOR ofciphertext and key:ciphertext ⊕ key = (plaintext ⊕ key) ⊕ key =plaintext ⊕ (key ⊕ key) =plaintext

Disadvantage #1: Keys as long as messages.Impractical in most scenarios Still used by intelligence communities

Page 20: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Disadvantages

= 10111101…---------------

= 00110010… 10001111… ⊕

00110010… = ⊕

10111101…

Key is a random bit sequenceas long as the plaintext

Encrypt by bitwise XOR ofplaintext and key:ciphertext = plaintext ⊕ key

Decrypt by bitwise XOR ofciphertext and key:ciphertext ⊕ key = (plaintext ⊕ key) ⊕ key =plaintext ⊕ (key ⊕ key) =plaintext

Disadvantage #2: No integrity protection

Page 21: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Disadvantages

= 10111101…---------------

= 00110010… 10001111… ⊕

00110010… = ⊕

10111101…

Key is a random bit sequenceas long as the plaintext

Encrypt by bitwise XOR ofplaintext and key:ciphertext = plaintext ⊕ key

Decrypt by bitwise XOR ofciphertext and key:ciphertext ⊕ key = (plaintext ⊕ key) ⊕ key =plaintext ⊕ (key ⊕ key) =plaintext

Disadvantage #2: No integrity protection

0

Page 22: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Disadvantages

= 10111101…---------------

= 00110010… 10001111… ⊕

00110010… = ⊕

10111101…

Key is a random bit sequenceas long as the plaintext

Encrypt by bitwise XOR ofplaintext and key:ciphertext = plaintext ⊕ key

Decrypt by bitwise XOR ofciphertext and key:ciphertext ⊕ key = (plaintext ⊕ key) ⊕ key =plaintext ⊕ (key ⊕ key) =plaintext

Disadvantage #2: No integrity protection

0

0

Page 23: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Disadvantages

= 00000000…---------------

= 00110010… 00110010… ⊕

00110010… = ⊕

00000000…

Disadvantage #3: Keys cannot be reused

= 11111111…---------------

= 00110010… 11001101… ⊕

00110010… = ⊕

11111111…

P1

P2

C1

C2

Learn relationship between plaintexts: C1⊕C2 = (P1⊕K)⊕(P2⊕K) = (P1⊕P2)⊕(K⊕K) = P1⊕P2

Page 24: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Reducing Keysize

What do we do when we can’t pre-share huge keys?• When OTP is unrealistic

We use special cryptographic primitives• Single key can be reused (with some restrictions)• But no longer provable secure (in the sense of the

OTP)

Examples: Block ciphers, stream ciphers

Page 25: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Background: Permutation

1234

1234

CODE becomes DCEO

For N-bit input, N! possible permutations Idea: split plaintext into blocks, for each block use

secret key to pick a permutation, rinse and repeat• Without the key, permutation should “look random”

Page 26: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Block Ciphers

Operates on a single chunk (“block”) of plaintext• For example, 64 bits for DES, 128 bits for AES• Same key is reused for each block (can use short keys)

Plaintext

Ciphertext

blockcipherKey

Page 27: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Block Cipher Security

Result should look like a random permutation• “As if” plaintext bits were randomly shuffled

Only computational guarantee of secrecy• Not impossible to break, just very expensive

– If there is no efficient algorithm (unproven assumption!), then can only break by brute-force, try-every-possible-key search

• Time and cost of breaking the cipher exceed the value and/or useful lifetime of protected information

Page 28: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Block Cipher Operation (Simplified)

Block of plaintext

S S S S

S S S S

S S S S

Key

Page 29: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Block Cipher Operation (Simplified)

Block of plaintext

S S S S

S S S S

S S S S

Key

Page 30: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Block Cipher Operation (Simplified)

Block of plaintext

S S S S

S S S S

S S S S

Key

Add some secret key bitsto provide confusion

Page 31: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Block Cipher Operation (Simplified)

Block of plaintext

S S S S

S S S S

S S S S

Key

Add some secret key bitsto provide confusion

Each S-box transforms its input bits in a “random-looking” way to provide diffusion (spread plaintext bits throughout ciphertext)

Page 32: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Block Cipher Operation (Simplified)

Block of plaintext

S S S S

S S S S

S S S S

Key

Add some secret key bitsto provide confusion

Each S-box transforms its input bits in a “random-looking” way to provide diffusion (spread plaintext bits throughout ciphertext)

Page 33: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Block Cipher Operation (Simplified)

Block of plaintext

S S S S

S S S S

S S S S

Key

Add some secret key bitsto provide confusion

Each S-box transforms its input bits in a “random-looking” way to provide diffusion (spread plaintext bits throughout ciphertext)

repeat for several rounds

Page 34: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Block Cipher Operation (Simplified)

Block of plaintext

S S S S

S S S S

S S S S

Key

Add some secret key bitsto provide confusion

Each S-box transforms its input bits in a “random-looking” way to provide diffusion (spread plaintext bits throughout ciphertext)

repeat for several rounds

Block of ciphertext

Page 35: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Block Cipher Operation (Simplified)

Block of plaintext

S S S S

S S S S

S S S S

Key

Add some secret key bitsto provide confusion

Each S-box transforms its input bits in a “random-looking” way to provide diffusion (spread plaintext bits throughout ciphertext)

repeat for several rounds

Block of ciphertextProcedure must be reversible

(for decryption)

Page 36: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Feistel Structure (Stallings Fig 2.2)

Page 37: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

DES Feistel structure

• “Ladder” structure: split input in half, put one half through the round and XOR with the other half

• After 3 random rounds, ciphertext indistinguishable from a random permutation (Luby & Rackoff)

DES: Data Encryption Standard• Feistel structure• Invented by IBM, issued as federal standard in 1977• 64-bit blocks, 56-bit key + 8 bits for parity

Page 38: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

DES and 56 bit keys (Stallings Tab 2.2)

56 bit keys are quite short

1999: EFF DES Crack + distibuted machines• < 24 hours to find DES key

DES ---> 3DES• 3DES: DES + inverse DES + DES (with 2 or 3 diff keys)

Page 39: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Advanced Encryption Standard (AES)

New federal standard as of 2001Based on the Rijndael algorithm 128-bit blocks, keys can be 128, 192 or 256 bitsUnlike DES, does not use Feistel structure

• The entire block is processed during each round

Design uses some very nice mathematics

Page 40: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Structure of Rijndael

128-bit plaintext(arranged as 4x4 array of 8-bit bytes)

128-bit key

Page 41: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Structure of Rijndael

128-bit plaintext(arranged as 4x4 array of 8-bit bytes)

128-bit key

Page 42: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Structure of Rijndael

128-bit plaintext(arranged as 4x4 array of 8-bit bytes)

128-bit key

S shuffle the array (16x16 substitution table)

Page 43: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Structure of Rijndael

128-bit plaintext(arranged as 4x4 array of 8-bit bytes)

128-bit key

S shuffle the array (16x16 substitution table)

Shift rows shift array rows (1st unchanged, 2nd left by 1, 3rd left by 2, 4th left by 3)

Page 44: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Structure of Rijndael

128-bit plaintext(arranged as 4x4 array of 8-bit bytes)

128-bit key

S shuffle the array (16x16 substitution table)

Shift rows shift array rows (1st unchanged, 2nd left by 1, 3rd left by 2, 4th left by 3)

Mix columnsmix 4 bytes in each column (each new byte depends on all bytes in old column)

Page 45: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Structure of Rijndael

128-bit plaintext(arranged as 4x4 array of 8-bit bytes)

128-bit key

S shuffle the array (16x16 substitution table)

Shift rows shift array rows (1st unchanged, 2nd left by 1, 3rd left by 2, 4th left by 3)

Expand keyMix columns

mix 4 bytes in each column (each new byte depends on all bytes in old column)

Page 46: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Structure of Rijndael

128-bit plaintext(arranged as 4x4 array of 8-bit bytes)

128-bit key

S shuffle the array (16x16 substitution table)

Shift rows shift array rows (1st unchanged, 2nd left by 1, 3rd left by 2, 4th left by 3)

add key for this round⊕

Expand keyMix columns

mix 4 bytes in each column (each new byte depends on all bytes in old column)

Page 47: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Structure of Rijndael

128-bit plaintext(arranged as 4x4 array of 8-bit bytes)

128-bit key

S shuffle the array (16x16 substitution table)

Shift rows shift array rows (1st unchanged, 2nd left by 1, 3rd left by 2, 4th left by 3)

add key for this round⊕

Expand key

repeat 10 times

Mix columnsmix 4 bytes in each column (each new byte depends on all bytes in old column)

Page 48: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Encrypting a Large Message So, we’ve got a good block cipher, but our

plaintext is larger than 128-bit block size Electronic Code Book (ECB) mode

• Split plaintext into blocks, encrypt each one separately using the block cipher

Cipher Block Chaining (CBC) mode• Split plaintext into blocks, XOR each block with the

result of encrypting previous blocks

Counter (CTR) mode• Use block cipher to generate keystream, like a stream

cipher

...

Page 49: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

ECB Mode

plaintext

ciphertext

blockcipher

blockcipher

blockcipher

blockcipher

blockcipher

Page 50: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

ECB Mode

Identical blocks of plaintext produce identical blocks of ciphertext

plaintext

ciphertext

blockcipher

blockcipher

blockcipher

blockcipher

blockcipher

Page 51: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

ECB Mode

Identical blocks of plaintext produce identical blocks of ciphertext

No integrity checks: can mix and match blocks

plaintext

ciphertext

blockcipher

blockcipher

blockcipher

blockcipher

blockcipher

Page 52: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

CBC Mode: Encryption

Identical blocks of plaintext encrypted differently Last cipherblock depends on entire plaintext

• Still does not guarantee integrity

plaintext

ciphertext

blockcipher

blockcipher

blockcipher

blockcipher

⊕Initializationvector(random)

⊕ ⊕ ⊕

Page 53: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

CBC Mode: Decryption

plaintext

ciphertext

decrypt decrypt decrypt decrypt

⊕Initializationvector ⊕ ⊕ ⊕

Page 54: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

CTR Mode: Encryption

Identical blocks of plaintext encrypted differently Still does not guarantee integrity

ctr ctr+1 ctr+2 ctr+3

ciphertext

blockcipher

blockcipher

blockcipher

blockcipher

Initial ctr(random)

⊕ ⊕ ⊕ ⊕ptpt pt pt

Page 55: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

ct ct ctct

CTR Mode: Decryption

ctr ctr+1 ctr+2 ctr+3

blockcipher

blockcipher

blockcipher

blockcipher

Initial ctr

⊕ ⊕ ⊕ ⊕

pt pt pt pt

Page 56: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

ECB vs. CBC

AES in ECB mode AES in CBC mode

Similar plaintextblocks producesimilar ciphertextblocks (not good!)

[Picture due to Bart Preneel]

Page 57: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Information Leakage in ECB Mode[Wikipedia]

Encrypt in ECB mode

Page 58: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

CBC and Electronic Voting

Initializationvector(supposed to be random)

plaintext

ciphertext

DES DES DES DES

⊕ ⊕ ⊕ ⊕

Found in the source code for Diebold voting machines:

DesCBCEncrypt((des_c_block*)tmp, (des_c_block*)record.m_Data, totalSize, DESKEY, NULL, DES_ENCRYPT)

Page 59: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

When Is a Cipher “Secure”?

Hard to recover the key?• What if attacker can learn plaintext without learning

the key?

Hard to recover plaintext from ciphertext?• What if attacker learns some bits or some function of

bits?

Fixed mapping from plaintexts to ciphertexts?• What if attacker sees two identical ciphertexts and

infers that the corresponding plaintexts are identical?• Implication: encryption must be randomized or stateful

Page 60: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

How Can a Cipher Be Attacked?Assume that the attacker knows the encryption

algorithm and wants to decrypt some ciphertextMain question: what else does attacker know?

• Depends on the application in which cipher is used!Ciphertext-only attackKnown-plaintext attack (stronger)

• Knows some plaintext-ciphertext pairsChosen-plaintext attack (even stronger)

• Can obtain ciphertext for any plaintext of his choiceChosen-ciphertext attack (very strong)

• Can decrypt any ciphertext except the target• Sometimes very realistic model

Page 61: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Chosen-Plaintext Attack

Page 62: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Chosen-Plaintext Attack

Crook #1 changeshis PIN to a numberof his choice

Page 63: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Chosen-Plaintext Attack

Crook #1 changeshis PIN to a numberof his choice

cipher(key,PIN)

PIN is encrypted andtransmitted to bank

Page 64: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Chosen-Plaintext Attack

Crook #1 changeshis PIN to a numberof his choice

cipher(key,PIN)

PIN is encrypted andtransmitted to bank

Crook #2 eavesdropson the wire and learnsciphertext correspondingto chosen plaintext PIN

Page 65: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Chosen-Plaintext Attack

Crook #1 changeshis PIN to a numberof his choice

cipher(key,PIN)

PIN is encrypted andtransmitted to bank

Crook #2 eavesdropson the wire and learnsciphertext correspondingto chosen plaintext PIN

… repeat for any PIN value

Page 66: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

The Chosen-Plaintext Game Attacker does not know the keyHe chooses as many plaintexts as he wants, and

learns the corresponding ciphertextsWhen ready, he picks two plaintexts M0 and M1

• He is even allowed to pick plaintexts for which he previously learned ciphertexts!

He receives either a ciphertext of M0, or a ciphertext of M1

He wins if he guesses correctly which one it is

Page 67: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Defining Security

Idea: attacker should not be able to learn even a single bit of the encrypted plaintextDefine Enc(M0,M1,b) to be a function that returns

encrypted Mb

• Given two plaintexts, Enc returns a ciphertext of one or the other depending on the value of bit b

• Think of Enc as a magic box that computes ciphertexts on attacker’s demand. He can obtain a ciphertext of any plaintext M by submitting M0=M1=M, or he can try to learn even more by submitting M0≠M1.

Attacker’s goal is to learn just one bit b

0 or 1

Page 68: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Why Hide Everything? Leaking even a little bit of information about the

plaintext can be disastrous Electronic voting

• 2 candidates on the ballot (1 bit to encode the vote)• If ciphertext leaks the parity bit of the encrypted

plaintext, eavesdropper learns the entire vote

D-Day: Pas-de-Calais or Normandy?• Allies convinced Germans that invasion will take place

at Pas-de-Calais– Dummy landing craft, feed information to double spies

• Goal: hide a 1-bit secret

Also, want a strong definition, that implies others

Page 69: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Chosen-Plaintext Security

Consider two experiments (A is the attacker) Experiment 0 Experiment 1

A interacts with Enc(-,-,0) A interacts with Enc(-,-,1) and outputs bit d and outputs bit d

• Identical except for the value of the secret bit

• d is attacker’s guess of the secret bit

Attacker’s advantage is defined as

| Prob(A outputs 1 in Exp0) - Prob(A outputs 1 in Exp1)) |

Encryption scheme is chosen-plaintext secure if this advantage is negligible for any efficient A

If A “knows” secret bit, he should be able to make his output depend on it

Page 70: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Simple Example

Page 71: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Simple Example

Any deterministic, stateless symmetric encryption scheme is insecure

Page 72: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Simple Example

Any deterministic, stateless symmetric encryption scheme is insecure • Attacker can easily distinguish encryptions of different

plaintexts from encryptions of identical plaintexts

Page 73: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Simple Example

Any deterministic, stateless symmetric encryption scheme is insecure • Attacker can easily distinguish encryptions of different

plaintexts from encryptions of identical plaintexts• This includes ECB mode of common block ciphers!

Page 74: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Simple Example

Any deterministic, stateless symmetric encryption scheme is insecure • Attacker can easily distinguish encryptions of different

plaintexts from encryptions of identical plaintexts• This includes ECB mode of common block ciphers!

Attacker A interacts with Enc(-,-,b)

Page 75: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Simple Example

Any deterministic, stateless symmetric encryption scheme is insecure • Attacker can easily distinguish encryptions of different

plaintexts from encryptions of identical plaintexts• This includes ECB mode of common block ciphers!

Attacker A interacts with Enc(-,-,b)

Let X,Y be any two different plaintexts

Page 76: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Simple Example

Any deterministic, stateless symmetric encryption scheme is insecure • Attacker can easily distinguish encryptions of different

plaintexts from encryptions of identical plaintexts• This includes ECB mode of common block ciphers!

Attacker A interacts with Enc(-,-,b)

Let X,Y be any two different plaintexts

C1 ← Enc(X,Y,b); C2 ← Enc(Y,Y,b);

Page 77: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Simple Example

Any deterministic, stateless symmetric encryption scheme is insecure • Attacker can easily distinguish encryptions of different

plaintexts from encryptions of identical plaintexts• This includes ECB mode of common block ciphers!

Attacker A interacts with Enc(-,-,b)

Let X,Y be any two different plaintexts

C1 ← Enc(X,Y,b); C2 ← Enc(Y,Y,b);

If C1=C2 then b=1 else say b=0

Page 78: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Simple Example

Any deterministic, stateless symmetric encryption scheme is insecure • Attacker can easily distinguish encryptions of different

plaintexts from encryptions of identical plaintexts• This includes ECB mode of common block ciphers!

Attacker A interacts with Enc(-,-,b)

Let X,Y be any two different plaintexts

C1 ← Enc(X,Y,b); C2 ← Enc(Y,Y,b);

If C1=C2 then b=1 else say b=0

The advantage of this attacker A is 1

Page 79: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Simple Example

Any deterministic, stateless symmetric encryption scheme is insecure • Attacker can easily distinguish encryptions of different

plaintexts from encryptions of identical plaintexts• This includes ECB mode of common block ciphers!

Attacker A interacts with Enc(-,-,b)

Let X,Y be any two different plaintexts

C1 ← Enc(X,Y,b); C2 ← Enc(Y,Y,b);

If C1=C2 then b=1 else say b=0

The advantage of this attacker A is 1

Prob(A outputs 1 if b=0)=0 Prob(A outputs 1 if b=1)=1

Page 80: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Integrity

goodFile

Software manufacturer wants to ensure that the executable file is received by users without modification.It sends out the file to users and publishes its hash in NY Times. The goal is integrity, not secrecy

Idea: given goodFile and hash(goodFile), very hard to find badFile such that hash(goodFile)=hash(badFile)

BigFirm™ User

VIRUS

badFile

The Timeshash(goodFile)

Page 81: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Integrity vs. Secrecy

Integrity: attacker cannot tamper with message Encryption does not always guarantee integrity

• Intuition: attacker may able to modify message under encryption without learning what it is

– One-time pad: given key K, encrypt M as M⊕K

– This guarantees perfect secrecy, but attacker can easily change unknown M under encryption to M⊕M’ for any M’

– Online auction: halve competitor’s bid without learning its value

• This is recognized by industry standards (e.g., PKCS)– “RSA encryption is intended primarily to provide confidentiality…

It is not intended to provide integrity” (from RSA Labs Bulletin)

Page 82: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Motivation: Authentication

msg, MAC(KEY,msg)

Alice wants to make sure that nobody modifies message in transit

Idea: given msg, very hard to compute MAC(KEY,msg) without KEY; very easy with KEY

Alice Bob

KEYKEY

Page 83: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Hash Functions: Main Idea

bit strings of any length n-bit bit strings

. .

...

x’x’’

x

y’y

hash function H

H is a lossy compression function• Collisions: h(x)=h(x’) for distinct inputs x, x’• Result of hashing should “look random” (make this precise later)

– Intuition: half of digest bits are “1”; any bit in digest is “1” half the time

Cryptographic hash function needs a few properties…

message “digest”

message

Page 84: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

One-Way

Intuition: hash should be hard to invert• “Preimage resistance”• Let h(x’)=y∈{0,1}n for a random x’

• Given y, it should be hard to find any x such that h(x)=y

How hard?• Brute-force: try every possible x, see if h(x)=y• SHA-1 (common hash function) has 160-bit output

– Suppose have hardware that’ll do 230 trials a pop– Assuming 234 trials per second, can do 289 trials per year– Will take around 271 years to invert SHA-1 on a random

image

Page 85: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Collision Resistance Should be hard to find distinct x, x’ such that

h(x)=h(x’)• Brute-force collision search is only O(2n/2), not O(2n)• For SHA-1, this means O(280) vs. O(2160)

Birthday paradox (informal)• Let t be the number of values x,x’,x’’… we need to look

at before finding the first pair x,x’ s.t. h(x)=h(x’) • What is probability of collision for each pair x,x’? • How many pairs would we need to look at before

finding the first collision?

• How many pairs x,x’ total?

• What is t?

Page 86: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Collision Resistance Should be hard to find distinct x, x’ such that

h(x)=h(x’)• Brute-force collision search is only O(2n/2), not O(2n)• For SHA-1, this means O(280) vs. O(2160)

Birthday paradox (informal)• Let t be the number of values x,x’,x’’… we need to look

at before finding the first pair x,x’ s.t. h(x)=h(x’) • What is probability of collision for each pair x,x’? • How many pairs would we need to look at before

finding the first collision?

• How many pairs x,x’ total?

• What is t?

1/2n

Page 87: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Collision Resistance Should be hard to find distinct x, x’ such that

h(x)=h(x’)• Brute-force collision search is only O(2n/2), not O(2n)• For SHA-1, this means O(280) vs. O(2160)

Birthday paradox (informal)• Let t be the number of values x,x’,x’’… we need to look

at before finding the first pair x,x’ s.t. h(x)=h(x’) • What is probability of collision for each pair x,x’? • How many pairs would we need to look at before

finding the first collision?

• How many pairs x,x’ total?

• What is t?

1/2n

O(2n)

Page 88: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Collision Resistance Should be hard to find distinct x, x’ such that

h(x)=h(x’)• Brute-force collision search is only O(2n/2), not O(2n)• For SHA-1, this means O(280) vs. O(2160)

Birthday paradox (informal)• Let t be the number of values x,x’,x’’… we need to look

at before finding the first pair x,x’ s.t. h(x)=h(x’) • What is probability of collision for each pair x,x’? • How many pairs would we need to look at before

finding the first collision?

• How many pairs x,x’ total?

• What is t?

1/2n

O(2n)

Choose(2,t)=t(t-1)/2 ∼ O(t2)

Page 89: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Collision Resistance Should be hard to find distinct x, x’ such that

h(x)=h(x’)• Brute-force collision search is only O(2n/2), not O(2n)• For SHA-1, this means O(280) vs. O(2160)

Birthday paradox (informal)• Let t be the number of values x,x’,x’’… we need to look

at before finding the first pair x,x’ s.t. h(x)=h(x’) • What is probability of collision for each pair x,x’? • How many pairs would we need to look at before

finding the first collision?

• How many pairs x,x’ total?

• What is t?

1/2n

O(2n)

2n/2

Choose(2,t)=t(t-1)/2 ∼ O(t2)

Page 90: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

One-Way vs. Collision Resistance

Page 91: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

One-Way vs. Collision Resistance

One-wayness does not imply collision resistance• Suppose g is one-way• Define h(x) as g(x’) where x’ is x except the last bit

– h is one-way (to invert h, must invert g)– Collisions for h are easy to find: for any x, h(x0)=h(x1)

Page 92: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

One-Way vs. Collision Resistance

One-wayness does not imply collision resistance• Suppose g is one-way• Define h(x) as g(x’) where x’ is x except the last bit

– h is one-way (to invert h, must invert g)– Collisions for h are easy to find: for any x, h(x0)=h(x1)

Collision resistance does not imply one-wayness• Suppose g is collision-resistant• Define h(x) to be 0x if x is n-bit long, 1g(x) otherwise

– Collisions for h are hard to find: if y starts with 0, then there are no collisions, if y starts with 1, then must find collisions in g

– h is not one way: half of all y’s (those whose first bit is 0) are easy to invert (how?); random y is invertible with probab. 1/2

Page 93: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Weak Collision Resistance

Given randomly chosen x, hard to find x’ such that h(x)=h(x’)• Attacker must find collision for a specific x. By

contrast, to break collision resistance, enough to find any collision.

• Brute-force attack requires O(2n) time• AKA second-preimage collision resistance

Weak collision resistance does not imply collision resistance

Page 94: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Which Property Do We Need?

UNIX passwords stored as hash(password)• One-wayness: hard to recover password

Integrity of software distribution• Weak collision resistance• But software images are not really random… maybe

need full collision resistance

Auction bidding• Alice wants to bid B, sends H(B), later reveals B• One-wayness: rival bidders should not recover B• Collision resistance: Alice should not be able to change

her mind to bid B’ such that H(B)=H(B’)

Page 95: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Common Hash Functions

MD5• 128-bit output• Designed by Ron Rivest, used very widely• Collision-resistance broken (summer of 2004)

RIPEMD-160• 160-bit variant of MD5

SHA-1 (Secure Hash Algorithm)• 160-bit output• US government (NIST) standard as of 1993-95

– Also the hash algorithm for Digital Signature Standard (DSS)

Page 96: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Basic Structure of SHA-1Against padding attacks

Split message into 512-bit blocks

Compression function• Applied to each 512-bit block and current 160-bit buffer • This is the heart of SHA-1

160-bit buffer (5 registers)initialized with magic values

Page 97: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

How Strong Is SHA-1?

Every bit of output depends on every bit of input• Very important property for collision-resistance

Brute-force inversion requires 2160 ops, birthday attack on collision resistance requires 280 ops

Some very recent weaknesses (2005)• Collisions can be found in 263 ops

Page 98: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Authentication Without Encryption

Alice Bob

KEYKEY

message

Page 99: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Authentication Without Encryption

Alice Bob

KEYKEY

message

MAC(message authentication code)

Page 100: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Authentication Without Encryption

Alice Bob

KEYKEY

message

MAC(message authentication code)

message, MAC(KEY,message)

Page 101: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Authentication Without Encryption

Alice Bob

KEYKEY

message

MAC(message authentication code)

message, MAC(KEY,message)

Page 102: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Authentication Without Encryption

Alice Bob

KEYKEY

message

MAC(message authentication code)

message, MAC(KEY,message)

=?

Recomputes MAC and verifies whether it isequal to the MAC attached to the message

Page 103: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Authentication Without Encryption

Integrity and authentication: only someone who knows KEY can compute MAC for a given message

Alice Bob

KEYKEY

message

MAC(message authentication code)

message, MAC(KEY,message)

=?

Recomputes MAC and verifies whether it isequal to the MAC attached to the message

Page 104: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

HMAC

Construct MAC by applying a cryptographic hash function to message and key• Could also use encryption instead of hashing, but…• Hashing is faster than encryption in software• Library code for hash functions widely available• Can easily replace one hash function with another• There used to be US export restrictions on encryption

Invented by Bellare, Canetti, and Krawczyk (1996)• HMAC strength established by cryptographic analysis

Mandatory for IP security, also used in SSL/TLS

Page 105: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Structure of HMAC

Embedded hash function(strength of HMAC relies on

strength of this hash function)

“Black box”: can use this HMACconstruction with any hash function(why is this important?)

Block size of embedded hash function

Secret key paddedto block size

magic value (flips half of key bits)

another magic value(flips different key bits)

hash(key,hash(key,message))

“Amplify” key material(get two keys out of one)

Very common problem:given a small secret, how toderive a lot of new keys?

Page 106: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Achieving Both Privacy and Integrity

Authenticated encryption scheme

Alice Bob

K K

M/invalid

K K

MEncrypt Decrypt

C

Key . . . . . . . . . . . . . . . K

. . . . . . . . . .Message M

. . . . . . .Ciphertext C Adversary

Recall: Often desire both privacy and integrity. (For SSH, SSL, IPsec, etc.)

Page 107: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Some subtleties! Encrypt-and-MAC

Natural approach for authenticated encryption: Combine an encryption scheme and a MAC.

Page 108: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Some subtleties! Encrypt-and-MAC

DKe,KmEKe,Km

Natural approach for authenticated encryption: Combine an encryption scheme and a MAC.

Page 109: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Some subtleties! Encrypt-and-MAC

DKe,KmEKe,KmM

Natural approach for authenticated encryption: Combine an encryption scheme and a MAC.

Page 110: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Some subtleties! Encrypt-and-MAC

DKe,KmEKe,KmM

C’

EncryptKe

Natural approach for authenticated encryption: Combine an encryption scheme and a MAC.

Page 111: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Some subtleties! Encrypt-and-MAC

DKe,KmEKe,KmM

C’

EncryptKe

T

MACKm

Natural approach for authenticated encryption: Combine an encryption scheme and a MAC.

Page 112: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Some subtleties! Encrypt-and-MAC

DKe,KmEKe,KmM

C’

EncryptKe

T

MACKm

Ciphertext

Natural approach for authenticated encryption: Combine an encryption scheme and a MAC.

Page 113: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Some subtleties! Encrypt-and-MAC

DKe,KmEKe,KmM

C’

EncryptKe

T

MACKm

Ciphertext

TC’

Ciphertext

Natural approach for authenticated encryption: Combine an encryption scheme and a MAC.

Page 114: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Some subtleties! Encrypt-and-MAC

M

DecryptKe

DKe,KmEKe,KmM

C’

EncryptKe

T

MACKm

Ciphertext

TC’

Ciphertext

Natural approach for authenticated encryption: Combine an encryption scheme and a MAC.

Page 115: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Some subtleties! Encrypt-and-MAC

valid/invalid

M

DecryptKe VerifyKm

DKe,KmEKe,KmM

C’

EncryptKe

T

MACKm

Ciphertext

TC’

Ciphertext

Natural approach for authenticated encryption: Combine an encryption scheme and a MAC.

Page 116: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Some subtleties! Encrypt-and-MAC

valid/invalid

M

DecryptKe VerifyKm

DKe,KmEKe,KmM

C’

EncryptKe

T

MACKm

Ciphertext

TC’

Ciphertext

Return M if valid

Natural approach for authenticated encryption: Combine an encryption scheme and a MAC.

Page 117: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

But insecure! [BN, Kra]

Assume Alice sends messages:

M2

C’2

EncryptKe

T2

MACKm

M1

C’1

EncryptKe

T1

M3

C’3

EncryptKe

T3

MACKm MACKm

If Ti = Tj then Mi = Mj

Adversary learns whether two plaintexts are equal.

Especially problematic when M1, M2, ... take on only a small number of possible values.

Page 118: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

But insecure! [BN, Kra]

Assume Alice sends messages:

M2

C’2

EncryptKe

T2

MACKm

M1

C’1

EncryptKe

T1

M3

C’3

EncryptKe

T3

DON’T FIREFIRE FIRE

MACKm MACKm

If Ti = Tj then Mi = Mj

Adversary learns whether two plaintexts are equal.

Especially problematic when M1, M2, ... take on only a small number of possible values.

Page 119: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

But insecure! [BN, Kra]

Assume Alice sends messages:

M2

C’2

EncryptKe

T2

MACKm

M1

C’1

EncryptKe

T1

M3

C’3

EncryptKe

T3

DON’T FIREFIRE FIREFIRE FIRE

MACKm MACKm

If Ti = Tj then Mi = Mj

Adversary learns whether two plaintexts are equal.

Especially problematic when M1, M2, ... take on only a small number of possible values.

Page 120: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

But insecure! [BN, Kra]

Assume Alice sends messages:

M2

C’2

EncryptKe

T2

MACKm

M1

C’1

EncryptKe

T1

M3

C’3

EncryptKe

T3

DON’T FIREFIRE FIREFIRE FIRE

MACKm MACKm

T1 T3

If Ti = Tj then Mi = Mj

Adversary learns whether two plaintexts are equal.

Especially problematic when M1, M2, ... take on only a small number of possible values.

Page 121: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

The Secure Shell (SSH) protocol is designed to provide:

• Secure remote logins.

• Secure file transfers.

Where security includes:

• Protecting the privacy of users’ data.

• Protecting the integrity of users’ data.

OpenSSH is included in the default installations of OS X and many Linux distributions.

Page 122: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

C’

paddingpdlpl

1 byte4 bytes

M

T

EncryptKe MACKm

MData to be

communicated

ctr

4 bytes

Maintained internally; not transmitted

EKe,Km

Ciphertext packet

Authenticated encryption in SSH

Page 123: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

M2M1

Assume Alice sends messages M1 and M2 that are the same.

What’s different about SSH?

Then the tags T1 and T2 will be different with high probability.

Page 124: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

T1C’1

EncryptKe MACKm

M1ctr1

M2M1

Assume Alice sends messages M1 and M2 that are the same.

What’s different about SSH?

T2C’2

EncryptKe MACKm

M2ctr2

Then the tags T1 and T2 will be different with high probability.

Page 125: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

T1C’1

EncryptKe MACKm

M1ctr1

M2M1 FIREFIRE

Assume Alice sends messages M1 and M2 that are the same.

What’s different about SSH?

T2C’2

EncryptKe MACKm

M2ctr2

Then the tags T1 and T2 will be different with high probability.

Page 126: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

T1C’1

EncryptKe MACKm

M1ctr1

M2M1 FIREFIRE

Assume Alice sends messages M1 and M2 that are the same.

What’s different about SSH?

T2C’2

EncryptKe MACKm

M2ctr2 FIREFIRE

Then the tags T1 and T2 will be different with high probability.

Page 127: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

T1C’1

EncryptKe MACKm

M1ctr1

M2M1 FIREFIRE

Assume Alice sends messages M1 and M2 that are the same.

What’s different about SSH?

T2C’2

EncryptKe MACKm

M2ctr2 FIREFIRE

Then the tags T1 and T2 will be different with high probability.

10

Page 128: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

T1C’1

EncryptKe MACKm

M1ctr1

T2T1

M2M1 FIREFIRE

Assume Alice sends messages M1 and M2 that are the same.

What’s different about SSH?

T2C’2

EncryptKe MACKm

M2ctr2 FIREFIRE

Then the tags T1 and T2 will be different with high probability.

10

Page 129: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

T1C’1

EncryptKe MACKm

M1ctr1

T2T1

M2M1 FIREFIRE

Assume Alice sends messages M1 and M2 that are the same.

What’s different about SSH?

T2C’2

EncryptKe MACKm

M2ctr2 FIREFIRE

Then the tags T1 and T2 will be different with high probability.

10

But if counters repeat, tags may once again leak private information about

data.

Page 130: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Results of [BN00,Kra01]

Strong (CTXT)

Strong (CCA) Weak (CPA) InsecurePrivacy

Integrity Weak (PTXT) Weak (PTXT)

MAC-then-EncryptEncrypt-then-MAC Encrypt-and-MAC

M MACKm

TM

EncryptKe

CCiphertext C

M

EncryptKe MACKm

TC’Ciphertext C

EncryptKe

M

MACKmC’

TC’Ciphertext C

Page 131: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Provable security

To prove that a scheme X is secure using reductions [GM]: Show that

• if one can compromise the security of X efficiently,

• then one can compromise the security of Y efficiently,

where Y is believed to be secure.

If Y is secure, an efficient adversary against X cannot exist.

Page 132: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Security Evaluations

First one out todayDue next Tuesday

Consider the security of the U.S. telecommunications system

(Much like in-class study last week.)

Page 133: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Project 1

Out today Part 1: Due next Thursday (April 19, 11:59pm) Part 2: Due following Thursday (April 26,

11:59pm)

Topic: Buffer overflow, format string, and double free vulnerabilities

Seven vulnerable programs Your job: Attack them and obtain a root shellReadings on website will help!

Page 134: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Project 1

Start early! (That’s why there’s two deadlines.)Groups up to three people OK

• Email Nick if you’d like us to pair you up• Goal is not to divide the vulnerable programs

amongst yourselves• Goal is to work together on all vulnerable programs

– You may be tested on how to attack these programs, and best way to deeply know the material is to do the attacks

Page 135: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

GDB will be helpful too!

disassemble run continue break

• break main• break *0x08048643

step / stepi info register x

• x/200x buf

• x/200i buf

• x/200a buf

• x/200x $sp - 16

Page 136: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

Example

Let’s try attacking an example program

Some of the following slides will not be online

Page 137: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...

target0.cint foo(char *arg, char *out) { strcpy(out, arg); return 0;}int main(int argc, char *argv[]) { char buf[64]; /* we want to overflow this buffer */ if (argc != 2) { ... } foo(argv[1], buf); return 0;}

ret/IPSaved SPbuf

64 bytes

Page 138: Cryptography: Symmetric Foundations€¦ · Cryptography: Symmetric Foundations Slides derived from Vitaly Shmatikov’s. Basic Problem Alice Bob M M ... (attack integrity) M ...