Cryptography: Hash Functions, MACs (finish) Asymmetric Cryptography - - PowerPoint PPT Presentation

cryptography hash functions macs finish asymmetric
SMART_READER_LITE
LIVE PREVIEW

Cryptography: Hash Functions, MACs (finish) Asymmetric Cryptography - - PowerPoint PPT Presentation

CSE 484 / CSE M 584: Computer Security and Privacy Cryptography: Hash Functions, MACs (finish) Asymmetric Cryptography (start) Fall 2016 Ada (Adam) Lerner lerner@cs.washington.edu Thanks to Franzi Roesner, Dan Boneh, Dieter Gollmann, Dan


slide-1
SLIDE 1

Fall 2016 Ada (Adam) Lerner lerner@cs.washington.edu

Thanks to Franzi Roesner, Dan Boneh, Dieter Gollmann, Dan Halperin, Yoshi Kohno, John Manferdelli, John Mitchell, Vitaly Shmatikov, Bennet Yee, and many others for sample slides and materials ...

CSE 484 / CSE M 584: Computer Security and Privacy

Cryptography:

Hash Functions, MACs (finish) Asymmetric Cryptography (start)

slide-2
SLIDE 2

Hash Functions

10/28/16 CSE 484 / CSE M 584 - Fall 2016 2

slide-3
SLIDE 3

Hash Functions: Main Idea

10/28/16 CSE 484 / CSE M 584 - Fall 2016 3

bit strings of any length n-bit bit strings

. . . . .

x’ x’’ x y’ y hash function H

  • Hash function H is a lossy compression function

– Collision: h(x)=h(x’) for distinct inputs x, x’

  • H(x) should look “random”

– Every bit (almost) equally likely to be 0 or 1

  • Cryptographic hash function needs a few properties…

message “digest”

message

slide-4
SLIDE 4

Properties of a Cryptographic Hash Function

  • One-wayness

– Given h(x): hard to find x

  • Collision resistance

– Hard to find x ≠ x’ s.t. h(x) == h(x’)

  • Weak collision resistance

– Hard to find x ≠ x’ s.t. h(x) == h(x’) for specific, random x

10/28/16 CSE 484 / CSE M 584 - Fall 2016 4

slide-5
SLIDE 5

Properties of a Cryptographic Hash Function

  • One-wayness

– Hard to find inputs that match outputs

  • Collision resistance

– Hard to find 2 inputs with the same hash

  • Weak collision resistance

– If I give you a random input, it’s hard to find another input with the same hash.

10/28/16 CSE 484 / CSE M 584 - Fall 2016 5

slide-6
SLIDE 6

Property 1: One-Way

  • The 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

10/28/16 CSE 484 / CSE M 584 - Fall 2016 6

slide-7
SLIDE 7

Property 2: Collision Resistance

  • Should be hard to find x≠x’ such that h(x)=h(x’)
  • Birthday paradox means that brute-force collision

search is only O(2n/2), not O(2n) – For SHA-1, this means O(280) vs. O(2160)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 7

slide-8
SLIDE 8

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 with last bit removed

  • h is one-way (to invert h, must invert g)
  • Collisions for h are easy to find: for any x, h(x|0)=h(x|1)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 8

slide-9
SLIDE 9

One-Way vs. Collision Resistance

  • One-wayness does not imply collision resistance
  • Collision resistance does not imply one-wayness

– Exercise for the reader (on HW#2)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 9

slide-10
SLIDE 10

Property 3: 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 it is enough to find any collision.) – Brute-force attack requires O(2n) time

  • Weak collision resistance does not imply collision

resistance.

10/28/16 CSE 484 / CSE M 584 - Fall 2016 10

slide-11
SLIDE 11

Does Collision Resistance imply Weak Collision Resistance?

  • p: Hard to find x≠x’ such that h(x)=h(x’)
  • q: Random x, hard to find x’ s.t. h(x)=h(x’)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 11

slide-12
SLIDE 12

Does Collision Resistance imply Weak Collision Resistance?

  • p: Hard to find x≠x’ such that h(x)=h(x’)
  • q: Random x, hard to find x’ s.t. h(x)=h(x’)
  • Contrapositive: p → q same as ¬q → ¬p
  • If you can find a collision against a random x,

can you find a collision in general?

10/28/16 CSE 484 / CSE M 584 - Fall 2016 12

slide-13
SLIDE 13

Does Collision Resistance imply Weak Collision Resistance?

  • p: Hard to find x≠x’ such that h(x)=h(x’)
  • q: Random x, hard to find x’ s.t. h(x)=h(x’)
  • If h is not weakly collision resistant, then

there exists an algorithm which takes an input x and “quickly” finds x’ which collides

  • Call this adversarial algorithm A, so for

random x, A(x) = x’ (where x’ collides with x)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 13

slide-14
SLIDE 14

Does Collision Resistance imply Weak Collision Resistance?

  • p: Hard to find x≠x’ such that h(x)=h(x’)
  • q: Random x, hard to find x’ s.t. h(x)=h(x’)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 14

slide-15
SLIDE 15

Hashing vs. Encryption

  • Hashing is one-way. There is no “un-hashing”

– A ciphertext can be decrypted with a decryption key… hashes have no equivalent of “decryption”

  • Hash(x) looks “random” but can be compared for

equality with Hash(x’)

– Hash the same input twice à same hash value – Encrypt the same input twice à different ciphertexts

  • Crytographic hashes are also known as

“cryptographic checksums” or “message digests”

10/28/16 CSE 484 / CSE M 584 - Fall 2016 15

slide-16
SLIDE 16

Application: Password Hashing

  • Instead of user password, store hash(password)
  • When use submits password, hash it and compare

to the stored hash

  • User “alice” sets password “thisismypassword”
  • Server stores hash(“thisismypassword”) =

a0e863aba2d508b6e4744f07d7c260cd

  • When alice logs in, server hashes the server she

provides and compares it to the stored hash.

10/28/16 CSE 484 / CSE M 584 - Fall 2016 16

slide-17
SLIDE 17

Application: Password Hashing

  • Instead of user password, store hash(password)
  • When use submits password, hash it and compare to

the stored hash

  • Let’s say you break into a server and

steal 100 million password hashes. What are the problems with this server’s approach? (Q1)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 17

slide-18
SLIDE 18

Application: Password Hashing

  • How to store password hashes: salt

and hash.

  • Instead of storing hash(password),

store “salt, hash(salt | password)”

  • Salt is a random value per password

10/28/16 CSE 484 / CSE M 584 - Fall 2016 18

slide-19
SLIDE 19

Application: Password Hashing

  • Username: ahaha
  • Hash function: SHA512
  • Salt: FlItSjGy
  • Hashed password:

54IaMBy6ThxAbvnUztWzrl4FjtE wn1sX81/8Ll7PtMpPAiy57QM4q.

  • yUD2cHFL4nwhguDk7eP7c3t0Ar

Kep.

10/28/16 CSE 484 / CSE M 584 - Fall 2016 19

slide-20
SLIDE 20

Application: Software Integrity

Goal: Software manufacturer wants to ensure file is received by users without modification. Idea: given goodFile and hash(goodFile), very hard to find badFile such that hash(goodFile)=hash(badFile)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 20

goodFile

BigFirm™ User

VIRUS

badFile

The NYTimes

hash(goodFile)

slide-21
SLIDE 21

Which Property Do We Need?

  • Auction bidding

– Alice wants to bid B, sends H(B), later reveals B – One-wayness: rival bidders should not recover B (this may mean that she needs to hash some randomness with B too) – Collision resistance: Alice should not be able to change her mind to bid B’ such that H(B)=H(B’)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 21

slide-22
SLIDE 22

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 recently broken! (Theoretically -- not practical.)

  • SHA-256, SHA-512, SHA-224, SHA-384
  • SHA-3: standard released by NIST in August 2015

10/28/16 CSE 484 / CSE M 584 - Fall 2016 22

slide-23
SLIDE 23

Basic Structure of SHA-1 [FYI only]

10/28/16 CSE 484 / CSE M 584 - Fall 2016 23

Against 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

slide-24
SLIDE 24

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 weaknesses, e.g., collisions can be found in

263 ops (2005)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 24

slide-25
SLIDE 25

Recall: Achieving Integrity

10/28/16 CSE 484 / CSE M 584 - Fall 2016 25

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

Alice Bob

KEY KEY

message

MAC: message authentication code

(sometimes called a “tag”)

message, MAC(KEY,message) = ? Recomputes MAC and verifies whether it is equal to the MAC attached to the message

Message authentication schemes: A tool for protecting integrity.

slide-26
SLIDE 26

HMAC

  • Construct MAC from a cryptographic hash function

– Invented by Bellare, Canetti, and Krawczyk (1996) – Used in SSL/TLS, mandatory for IPsec

  • Why not encryption?

– Hashing is faster than block ciphers in software – Can easily replace one hash function with another – There used to be US export restrictions on encryption

10/28/16 CSE 484 / CSE M 584 - Fall 2016 26

slide-27
SLIDE 27

Structure of HMAC [FYI only]

10/28/16 CSE 484 / CSE M 584 - Fall 2016 27

Embedded hash function “Black box”: can use this HMAC construction with any hash function

Block size of embedded hash function Secret key padded to block size magic value (flips half of key bits) another magic value

(flips different key bits)

hash(key,hash(key,message))

slide-28
SLIDE 28

Authenticated Encryption

  • What if we want both privacy and integrity?
  • Natural approach: combine encryption scheme and a MAC.
  • But be careful!

– Obvious approach: Encrypt-and-MAC – Problem: MAC is deterministic! same plaintext à same MAC

10/28/16 CSE 484 / CSE M 584 - Fall 2016 28

M2 C’2 EncryptKe T2 MACKm M1 C’1 EncryptKe T1 M3 C’3 EncryptKe T3 DON’T FIRE FIRE FIRE FIRE FIRE MACKm MACKm T1 T3

slide-29
SLIDE 29

Authenticated Encryption

  • Instead:

Encrypt then MAC.

  • (Not as good:

MAC-then-Encrypt)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 29

Encrypt-then-MAC

EncryptKe

M

MACKm

C’ T C’

Ciphertext C

slide-30
SLIDE 30

Asymmetric (Public Key) Cryptography

10/28/16 CSE 484 / CSE M 584 - Fall 2016 30

slide-31
SLIDE 31

Reminder: Symmetric Cryptography

  • 1 secret key (or 2 or …), shared between sender/receiver
  • Repeat fast and simple operations lots of times (rounds) to

mix up key and ciphertext

  • Why do we think it is secure? (simplistic)

– Lots of heuristic arguments

  • If we do lots and lots and lots of mixing, no simple formula

(and reversible) describing the whole process (cryptographic weakness).

  • Mix in ways we think it’s hard to short-circuit all the rounds.

Especially non-linear mixing, e.g., S-boxes. – Some math gives us confidence in these assumptions

10/28/16 CSE 484 / CSE M 584 - Fall 2016 31

slide-32
SLIDE 32

Public Key Crypto: Basic Problem

10/28/16 CSE 484 / CSE M 584 - Fall 2016 32

?

Given: Everybody knows Bob’s public key Only Bob knows the corresponding private key

private key

Goals: 1. Alice wants to send a secret message to Bob

  • 2. Bob wants to authenticate himself

public key public key

Alice Bob

slide-33
SLIDE 33

Public Key Cryptography

  • Everyone has 1 private key and 1 public key

– Or 2 private and 2 public, when considering both encryption and authentication

  • Mathematical relationship between private and

public keys

  • Why do we think it is secure? (simplistic)

– Relies entirely on problems we believe are “hard”

10/28/16 CSE 484 / CSE M 584 - Fall 2016 33

slide-34
SLIDE 34

What can Public Key Crypto Do?

  • Encryption for confidentiality

– Anyone can encrypt a message only you can read

  • Digital signatures for authentication

– Can “sign” a message with your private key

10/28/16 CSE 484 / CSE M 584 - Fall 2016 34

slide-35
SLIDE 35

Session Establishment

  • Session key establishment

– Exchange messages to create a secret session key – Then switch to symmetric cryptography (why?)

10/28/16 CSE 484 / CSE M 584 - Fall 2016 35

slide-36
SLIDE 36

Refresher: Modular Arithmetic

10/28/16 CSE 484 / CSE M 584 - Fall 2016 36

(see worksheet Qs 3-5)

slide-37
SLIDE 37

Diffie-Hellman Protocol (1976)

  • Alice and Bob never met and share no secrets
  • They talk publically, with everything they say
  • verheard by Eve. By the end of the

conversation, they share a secret nobody else knows.

10/28/16 CSE 484 / CSE M 584 - Fall 2016 37

Alice Bob

Eve

slide-38
SLIDE 38

Diffie-Hellman: Conceptually

10/28/16 CSE 484 / CSE M 584 - Fall 2016 38

[from Wikipedia]

Common paint: p and g Secret colors: x and y Send over public transport: gx mod p gy mod p Common secret: gxy mod p