Cryptography Deian Stefan Adopted slides from Kirill Levchenko and - - PowerPoint PPT Presentation

cryptography
SMART_READER_LITE
LIVE PREVIEW

Cryptography Deian Stefan Adopted slides from Kirill Levchenko and - - PowerPoint PPT Presentation

CSE 127: Computer Security Cryptography Deian Stefan Adopted slides from Kirill Levchenko and Dan Boneh Cryptography Is: A tremendous tool The basis for many security mechanisms Is not: The solution to all security problems


slide-1
SLIDE 1

CSE 127: Computer Security

Cryptography

Deian Stefan Adopted slides from Kirill Levchenko and Dan Boneh

slide-2
SLIDE 2

Cryptography

  • Is:

➤ A tremendous tool ➤ The basis for many security mechanisms

  • Is not:

➤ The solution to all security problems ➤ Reliable unless implemented and used properly ➤ Something you should try to invent yourself ➤ Blockchain

slide-3
SLIDE 3

Cryptography

  • Is:

➤ A tremendous tool ➤ The basis for many security mechanisms

  • Is not:

➤ The solution to all security problems ➤ Reliable unless implemented and used properly ➤ Something you should try to invent yourself ➤ Blockchain

slide-4
SLIDE 4

Cryptography

  • Is:

➤ A tremendous tool ➤ The basis for many security mechanisms

  • Is not:

➤ The solution to all security problems ➤ Reliable unless implemented and used properly ➤ Something you should try to invent yourself ➤ Blockchain

slide-5
SLIDE 5

This class: secure communication

Alice Bob Eve

➤ Authenticity: Parties cannot be impersonated ➤ Secrecy: No one else can read messages ➤ Integrity: messages cannot be modified

slide-6
SLIDE 6

Attacker models

➤ Passive attacker: Eve only snoops on channel ➤ Active attacker: Eve can snoop, inject, block, tamper, etc.

Alice Bob Eve

slide-7
SLIDE 7

In the real world (SSL/TLS)

➤ Handshake Protocol: Establish shared secret key 


using public-key cryptography

➤ Record Layer: Transmit data protected by

symmetric-key cryptography (using negotiated key)

slide-8
SLIDE 8

Outline

  • Symmetric-key crypto

➤ Encryption ➤ Hash functions ➤ Message authentication code

  • Asymmetric (public-key) crypto

➤ Encryption ➤ Digital signatures

slide-9
SLIDE 9

Symmetric-key encryption

  • Encryption: (key, plaintext) → ciphertext

➤ Ek(m) = c

  • Decryption: (key, ciphertext) → plaintext

➤ Dk(c) = m

E m c k D c m k

slide-10
SLIDE 10

Symmetric-key encryption

  • One-time key: used to encrypt one message

➤ E.g., encrypted email, new key generate per email

  • Multi-use key: used to encrypt multiple messages

➤ E.g., SSL, same key used to encrypt many packets

E m c k D c m k

slide-11
SLIDE 11

Symmetric-key encryption

  • One-time key: used to encrypt one message

➤ E.g., encrypted email, new key generate per email

  • Multi-use key: used to encrypt multiple messages

➤ E.g., SSL, same key used to encrypt many packets

E m c k D c m k

slide-12
SLIDE 12

Symmetric-key encryption

  • One-time key: used to encrypt one message

➤ E.g., encrypted email, new key generate per email

  • Multi-use key: used to encrypt multiple messages

➤ E.g., SSL, same key used to encrypt many packets

E m c k D c m k n n

slide-13
SLIDE 13

Symmetric-key encryption

  • One-time key: used to encrypt one message

➤ E.g., encrypted email, new key generate per email

  • Multi-use key: used to encrypt multiple messages

➤ E.g., SSL, same key used to encrypt many packets

E m c k D c m k n n Need unique/random nonce

slide-14
SLIDE 14

Encryption properties

  • Encryption and decryption are inverse operations

➤ Dk(Ek(m)) = m

  • Secrecy: ciphertext reveals nothing about plaintext

➤ More formally: can’t distinguish which of two

plaintexts were encrypted without key

slide-15
SLIDE 15

Vernam (1917)

First example: One Time Pad

➤ Encryption: c = Ek(m) = m ⨁ k ➤ Decryption: Dk(c) = c ⨁ k = (m ⨁ k) ⨁k = m

1 1 1 1 1 Key: 1 1 1 1 Plaintext:

1 1 1 1 1 Ciphertext:

slide-16
SLIDE 16

Vernam (1917)

First example: One Time Pad

➤ Encryption: c = Ek(m) = m ⨁ k ➤ Decryption: Dk(c) = c ⨁ k = (m ⨁ k) ⨁k = m

1 1 1 1 1 Key: 1 1 1 1 Plaintext:

1 1 1 1 1 Ciphertext:

slide-17
SLIDE 17

Vernam (1917)

First example: One Time Pad

➤ Encryption: c = Ek(m) = m ⨁ k ➤ Decryption: Dk(c) = c ⨁ k = (m ⨁ k) ⨁k = m

1 1 1 1 1 Key: 1 1 1 1 Plaintext:

1 1 1 1 1 Ciphertext:

slide-18
SLIDE 18

OTP security

  • Shannon (1949)

➤ Information theoretic security: without key, ciphertext

reveals no “information” about plaintext

  • Problems with OTP

➤ Can only use key once ➤ Key is as long as the message

slide-19
SLIDE 19

Computational cryptography

  • Want the size of the secret to be small

➤ If pre-arranged secret smaller than message, not all

plaintexts equally probable — ciphertext reveals info about plaintext

  • Modern cryptography based on idea that

learning anything about plaintext from ciphertext is computationally difficult without secret

slide-20
SLIDE 20

Stream ciphers

  • Problem: OTP key is as long as message
  • Solution: Pseudo random key

➤ Examples: ChaCha, Salsa, Sosemanuk, etc.

key

slide-21
SLIDE 21

Stream ciphers

  • Problem: OTP key is as long as message
  • Solution: Pseudo random key

➤ Examples: ChaCha, Salsa, Sosemanuk, etc.

key

PRG

slide-22
SLIDE 22

Stream ciphers

  • Problem: OTP key is as long as message
  • Solution: Pseudo random key

➤ Examples: ChaCha, Salsa, Sosemanuk, etc.

key

PRG

message

ciphertext

Ek(m) = PRG(k) ⊕ m

slide-23
SLIDE 23

Stream ciphers

  • Problem: OTP key is as long as message
  • Solution: Pseudo random key

➤ Examples: ChaCha, Salsa, Sosemanuk, etc.

key

PRG

message

ciphertext

Ek(m) = PRG(k) ⊕ m

slide-24
SLIDE 24

Stream ciphers

  • Problem: OTP key is as long as message
  • Solution: Pseudo random key

➤ Examples: ChaCha, Salsa, Sosemanuk, etc.

key

PRG

message

ciphertext

Ek(m) = PRG(k) ⊕ m

Computationally hard to distinguish from random

slide-25
SLIDE 25

Dangers in using stream ciphers

  • Can we use a key more than once?

➤ E.g., c1 ← m1 ⊕ PRG(k)

c2 ← m2 ⊕ PRG(k)

➤ A: yes, B: no ➤ Eavesdropper does: c1 ⊕ c2 → m1 ⊕ m2 ➤ Enough redundant information in English that:


m1 ⊕ m2 → m1 , m2

slide-26
SLIDE 26

Dangers in using stream ciphers

  • Can we use a key more than once?

➤ E.g., c1 ← m1 ⊕ PRG(k)

c2 ← m2 ⊕ PRG(k)

➤ A: yes, B: no ➤ Eavesdropper does: c1 ⊕ c2 → m1 ⊕ m2 ➤ Enough redundant information in English that:


m1 ⊕ m2 → m1 , m2

slide-27
SLIDE 27

Block ciphers: crypto work horses

  • Block ciphers operate on fixed-size blocks

➤ E.g., 3DES: |m| = |c| = 64 bits, |k| = 168 bits ➤ E.g., AES: |m| = |c| = 128 bits, |k| = 128, 192, 256

  • A block cipher = permutation of fixed-size inputs

➤ Each input mapped to exactly one output

E m c k D c m k

slide-28
SLIDE 28

R(k1, ⋅) R(k2, ⋅) R(k3, ⋅) R(kn, ⋅)

k1 k2 k3 kn

key k

How do they work?

R(k,m): round function for 3DES (n=48), for AES-128 (n=10)

key expansion

m c

slide-29
SLIDE 29

How do they work?

slide-30
SLIDE 30

Challenges with block ciphers

  • Block ciphers operate on single fixed-size block
  • How do we encrypt longer messages?

➤ Several modes of operation for longer messages

  • How do we deal with messages that are not

block-aligned?

➤ Must pad messages in a distinguishable way

slide-31
SLIDE 31

Challenges with block ciphers

  • Block ciphers operate on single fixed-size block
  • How do we encrypt longer messages?

➤ Several modes of operation for longer messages

  • How do we deal with messages that are not

block-aligned?

➤ Must pad messages in a distinguishable way

slide-32
SLIDE 32

Challenges with block ciphers

  • Block ciphers operate on single fixed-size block
  • How do we encrypt longer messages?

➤ Several modes of operation for longer messages

  • How do we deal with messages that are not

block-aligned?

➤ Must pad messages in a distinguishable way

slide-33
SLIDE 33

ECB mode

Source: wikipedia

slide-34
SLIDE 34

Is ECB good? A: yes, B: no

Source: wikipedia

slide-35
SLIDE 35

Is ECB good? A: yes, B: no

Ek( )=

Source: wikipedia

slide-36
SLIDE 36

CBC mode with random IV

Source: wikipedia

slide-37
SLIDE 37

CBC mode with random IV

Subtle attacks that abuse padding possible!

Source: wikipedia

slide-38
SLIDE 38

CTR mode with random IV

Source: wikipedia

slide-39
SLIDE 39

CTR mode with random IV

Essentially use block cipher as stream cipher!

Source: wikipedia

slide-40
SLIDE 40

What security do we actually get?

  • All encryption breakable by brute force given

enough knowledge about plaintext

  • Try to decrypt ciphertext with every possible key

until a valid plaintext is found

  • Attack complexity proportional to size of key space

➤ 64-bit key requires 2⁶⁴ decryption attempts

slide-41
SLIDE 41

Outline

  • Symmetric-key crypto

➤ Encryption ➤ Hash functions ➤ Message authentication code

  • Asymmetric (public-key) crypto

➤ Encryption ➤ Digital signatures

slide-42
SLIDE 42

Hash Functions

  • A (cryptographic) hash function maps arbitrary

length input into a fixed-size string
 
 


➤ |m| is arbitrarily large ➤ |h| is fixed, usually 128-512 bits


m

H

h

h=H(m)

slide-43
SLIDE 43

Hash Function Properties

  • Finding a pre-image is hard

➤ Given h, find m such that H(m)=h

  • Finding a collision is hard

➤ Find m1 and m2 such that H(m1)=H(m2)

slide-44
SLIDE 44

Hash Functions

  • MD5: Message Digest

➤ Designed by Ron Rivest ➤ Very popular hash function ➤ Output: 128 bits ➤ Broken — do not use!

slide-45
SLIDE 45

Hash Functions

  • SHA-1: Secure Hash Algorithm 1

➤ Designed by NSA ➤ Output: 160 bits ➤ Broken — do not use!

  • SHA-2: Secure Hash Algorithm 2

➤ Designed by NSA ➤ Output: 224, 256, 384, or 512 bits ➤ Recommended for use today

slide-46
SLIDE 46

Hash Functions

  • SHA-3: Secure Hash Algorithm 3

➤ Result of NIST SHA-3 contest ➤ Output: arbitrary size ➤ Replacement once SHA-2 broken

slide-47
SLIDE 47

Outline

  • Symmetric-key crypto

➤ Encryption ➤ Hash functions ➤ Message authentication code

  • Asymmetric (public-key) crypto

➤ Encryption ➤ Digital signatures

slide-48
SLIDE 48

MAC constructions

  • HMAC: MAC based on hash function


MACk(m) = H( k⊕opad ‖ H( k⊕ipad ‖ m ) )


➤ HMAC-SHA1: HMAC construction using SHA-1 ➤ HMAC-SHA256: HMAC construction using SHA-256

  • CMAC: MAC based on block cipher
slide-49
SLIDE 49

MACs

  • Validate message integrity based on shared secret
  • MAC: Message Authentication Code

➤ Keyed hash function using shared secret ➤ Hard compute hash without knowing key

a=MACk(m)

slide-50
SLIDE 50

Combining MAC with encryption

MAC then Encrypt (SSL)

➤ Integrity for plaintext not

ciphertext

➤ Issue: need to decrypt before

you can verify integrity

➤ Hard to get right!

m a kI MAC c kE E m||a

slide-51
SLIDE 51

Combining MAC with encryption

Encrypt and MAC (SSH)

➤ Integrity for plaintext not

ciphertext

➤ Issue: need to decrypt before

you can verify integrity

➤ Hard to get right!

m a kI MAC c kE E ||

slide-52
SLIDE 52

Combining MAC with encryption

Encrypt then MAC (IPSec)

➤ Integrity for plaintext and

ciphertext

➤ Always right!

m a kI MAC c kE E ||

slide-53
SLIDE 53

AEAD construction

  • Authenticated Encryption with Associated Data

➤ AES-GCM ➤ E.g., as used in Google’s Tink:



 
 
 


import com.google.crypto.tink.Aead; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.aead.AeadKeyTemplates; // 1. Generate the key material. KeysetHandle keysetHandle = KeysetHandle.generateNew( AeadKeyTemplates.AES128_GCM); // 2. Get the primitive. Aead aead = keysetHandle.getPrimitive(Aead.class); // 3. Use the primitive. byte[] ciphertext = aead.encrypt(plaintext, associatedData);