Symmetric-Key Cryptography
CS 161 Fall 2021 - Lecture 10
Computer Science 161
Popa and Weaver
Announcements
2
Computer Science 161
Popa and Weaver
One-Time Pads
3
Textbook Chapter 6.2 & 6.3
Computer Science 161
Popa and Weaver
Cryptography Roadmap
4
| Symmetric-key | Asymmetric-key |
Confidentiality |
|
|
Integrity,�Authentication |
|
|
Computer Science 161
Popa and Weaver
One-Time Pads: Key Generation
5
Alice
0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 |
K
The key K is a randomly-chosen bitstring.
Recall: We are in the symmetric-key setting, so we’ll assume Alice and Bob both know this key.
Computer Science 161
Popa and Weaver
One-Time Pads: Encryption
6
Alice
0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 |
K
1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
M
The plaintext M is the bitstring that Alice wants to encrypt.
Idea: Use XOR to scramble up M with the bits of K.
Computer Science 161
Popa and Weaver
One-Time Pads: Encryption
7
Alice
0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 |
K
1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
M
1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 |
C
Encryption algorithm: XOR each bit of K with the matching bit in M.
⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ |
↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ |
The ciphertext C is the encrypted bitstring that Alice sends to Bob over the insecure channel.
Computer Science 161
Popa and Weaver
One-Time Pads: Decryption
8
Bob
0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 |
K
1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 |
C
Bob receives the ciphertext C. Bob knows the key K. How does Bob recover M?
Computer Science 161
Popa and Weaver
One-Time Pads: Decryption
9
Bob
0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 |
K
1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 |
C
1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
M
⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ | ⊕ |
↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ | ↓ |
Decryption algorithm: XOR each bit of K with the matching bit in C.
Computer Science 161
Popa and Weaver
One-Time Pad
10
Computer Science 161
Popa and Weaver
One-Time Pad: Correctness
11
Enc(K, M) | = | K ⊕ M | Definition of encryption |
Dec(K, Enc(K, M)) | = | Dec(K, K ⊕ M) | Decrypting the ciphertext |
| = | K ⊕ (K ⊕ M) | Definition of decryption |
| = | M | XOR property |
Computer Science 161
Popa and Weaver
One-Time Pad: Security
12
Possibility 0: Alice sends Enc(K, M0)
Possibility 1: Alice sends Enc(K, M1)
The ciphertext is C = K ⊕ M0
Therefore, K = C ⊕ M0
The ciphertext is C = K ⊕ M1
Therefore, K = C ⊕ M1
K was chosen randomly, so both possibilities are equally possible
Eve has learned no new information, so the scheme is perfectly secure
Computer Science 161
Popa and Weaver
Two-Time Pads?
13
M0
K
OTP Enc
K ⊕ M0
Alice
Insecure Channel
M1
K
OTP Enc
K ⊕ M1
What if we use the same key K to encrypt two different messages?
Eve sees two ciphertexts over the insecure channel.
Computer Science 161
Popa and Weaver
Two-Time Pads?
14
M0
K
OTP Enc
K ⊕ M0
Alice
Insecure Channel
M1
K
OTP Enc
K ⊕ M1
⊕
(K ⊕ M0) ⊕ (K ⊕ M1)�= M0 ⊕ M1
Eve
If Eve XORs the two ciphertexts, she learns M0 ⊕ M1!
Computer Science 161
Popa and Weaver
Two-Time Pads?
15
Computer Science 161
Popa and Weaver
Impracticality of One-Time Pads
16
Computer Science 161
Popa and Weaver
Is one-time pad IND-CPA secure?
An encryption scheme is IND-CPA secure if for all polynomial time attackers Eve:
Eve can win with probability <= 1/2 + Ɛ, where Ɛ is negligible.
17
M
Enc(K, M)
(repeat)
Alice (challenger)
Eve (adversary)
M0 and M1
Enc(K, Mb)
M
Enc(K, M)
Guess b = 0 or b = 1
(repeat)
pick b
No, because it requires that the scheme is able to reuse a key K without helping the attacker distinguish. In repeat phase, attacker can ask for M0
Computer Science 161
Popa and Weaver
Traffic Analysis & Side Channels
18
Computer Science 161
Popa and Weaver
Traffic Analysis & Side Channels
19
Computer Science 161
Popa and Weaver
Traffic Analysis & Side Channels in Practice: Spies
20
Computer Science 161
Popa and Weaver
Summary
21
Computer Science 161
Popa and Weaver
Block Ciphers
22
Textbook Chapter 6.4 & 6.5
Computer Science 161
Popa and Weaver
Cryptography Roadmap
| Symmetric-key | Asymmetric-key |
Confidentiality |
|
|
Integrity,�Authentication |
|
|
Computer Science 161
Popa and Weaver
Block Ciphers: Definition
24
E
K
k bits
n bits
plaintext
n bits
ciphertext
D
K
k bits
n bits
ciphertext
n bits
plaintext
Computer Science 161
Popa and Weaver
Block Ciphers: Intuition
25
Computer Science 161
Popa and Weaver
Block Ciphers: Correctness
26
00
01
10
11
00
01
10
11
00
01
10
11
00
01
10
11
Not bijective: Two inputs encrypt to the same output
Bijective: Each input maps to exactly one unique output
Computer Science 161
Popa and Weaver
Block Ciphers: Security
27
00
01
10
11
00
01
10
11
00
01
10
11
00
01
10
11
One of these is EK and the other one is a random permutation. Eve can’t distinguish them.
Computer Science 161
Popa and Weaver
Block ciphers: Brute-force attacks?
28
Computer Science 161
Popa and Weaver
Block ciphers: Brute-force attacks?
29
Computer Science 161
Popa and Weaver
Block Ciphers: Efficiency
30
Computer Science 161
Popa and Weaver
Example: DES (Data Encryption Standard)
31
Computer Science 161
Popa and Weaver
Example: AES (Advanced Encryption Standard)
32
Computer Science 161
Popa and Weaver
Example: AES (Advanced Encryption Standard)
33
Computer Science 161
Popa and Weaver
AES Algorithm
34
Computer Science 161
Popa and Weaver
AES Algorithm: Sub Bytes
35
Computer Science 161
Popa and Weaver
AES Algorithm: Shift Rows
36
Computer Science 161
Popa and Weaver
Example: AES (Advanced Encryption Standard)
37
Computer Science 161
Popa and Weaver
Are Block Ciphers IND-CPA Secure?
38
M
Enc(K, M)
(repeat)
Alice (challenger)
Eve (adversary)
M0 and M1
Enc(K, Mb)
M
Enc(K, M)
Guess b = 0 or b = 1
(repeat)
pick b
Computer Science 161
Popa and Weaver
Issues with Block Ciphers
39
Computer Science 161
Popa and Weaver
Block Ciphers: Summary
40
Computer Science 161
Popa and Weaver
Block Cipher Modes of Operation
41
Textbook Chapter 6.6–6.9
Computer Science 161
Popa and Weaver
Scratchpad: Let’s design it together
42
Here’s an AES block. Remember that it can only encrypt 128-bit messages.
How can we use AES to encrypt a longer message (say, 256 bits?)
Computer Science 161
Popa and Weaver
Scratchpad: Let’s design it together
43
Idea: Let’s use AES twice!
First 128 bits of message
Second 128 bits of message
Computer Science 161
Popa and Weaver
Scratchpad: Let’s design it together
44
Note that we are using the same key twice. We want to avoid a situation like one-time pads where we need very long keys.
Computer Science 161
Popa and Weaver
ECB Mode
45
Computer Science 161
Popa and Weaver
ECB Mode: Penguin
Original image
46
Computer Science 161
Popa and Weaver
ECB Mode: Penguin
Encrypted with ECB
47
Computer Science 161
Popa and Weaver
Scratchpad: Let’s design it together
48
Here’s ECB mode. It’s not IND-CPA secure because it’s deterministic.
Let’s fix that by adding some randomness.
Computer Science 161
Popa and Weaver
Scratchpad: Let’s design it together
49
The Initialization Vector (IV) is different for every encryption. Now the first ciphertext block will be different for every encryption!
Okay, but the other blocks are still deterministic...
Computer Science 161
Popa and Weaver
Scratchpad: Let’s design it together
50
Idea: The first ciphertext block was computed with some randomness. Let’s use it to add randomness to the second block.
Computer Science 161
Popa and Weaver
Scratchpad: Let’s design it together
51
Now the second ciphertext block has some randomness in it. Let’s use it to add randomness to the third block.
Computer Science 161
Popa and Weaver
CBC Mode
52
P1
P2
Pm
Computer Science 161
Popa and Weaver
CBC Mode: Decryption
53
Computer Science 161
Popa and Weaver
CBC Mode: Decryption
54
Ci | = | EK(Mi ⊕ Ci-1) | Definition of encryption |
DK(Ci) | = | DK(EK(Mi ⊕ Ci-1)) | Decrypting both sides |
DK(Ci) | = | Mi ⊕ Ci-1 | Decryption and encryption cancel |
DK(Ci) ⊕ Ci-1 | = | Mi ⊕ Ci-1 ⊕ Ci-1 | XOR both sides with Ci-1 |
DK(Ci) ⊕ Ci-1 | = | Mi | XOR property |
Computer Science 161
Popa and Weaver
CBC Mode: Efficiency & Parallelism
55
Computer Science 161
Popa and Weaver
CBC Mode: Padding
56
Computer Science 161
Popa and Weaver
CBC Mode: Padding
57
Computer Science 161
Popa and Weaver
CBC Mode: Security
58
Computer Science 161
Popa and Weaver
CBC Mode: IV Reuse
59
Computer Science 161
Popa and Weaver
CBC Mode is IND-CPA (when used correctly)
60
P1
P2
Pm
Computer Science 161
Popa and Weaver
CBC Mode: Penguin
Original image
61
Computer Science 161
Popa and Weaver
CBC Mode: Penguin
Encrypted with CBC, with random IVs
62
Computer Science 161
Popa and Weaver