One-Time Pad & Block Ciphers
CS 161 Spring 2024 - Lecture 6
Computer Science 161
Project 1 Parties
Project 1 is due this Friday, February 9, 11:59pm.
My office hours: Monday 2-3pm, Soda 729
2
Computer Science 161
Recall the IND-CPA security definition
An encryption scheme is IND-CPA secure if for all polynomial time attackers Eve:
3
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
Keygen()
Computer Science 161
One-Time Pads
4
Textbook Chapter 6.2 & 6.3
Computer Science 161
Cryptography Roadmap
5
| Symmetric-key | Asymmetric-key |
Confidentiality |
|
|
Integrity,�Authentication |
|
|
Computer Science 161
Review: XOR
6
0 ⊕ 0 = 0 |
0 ⊕ 1 = 1 |
1 ⊕ 0 = 1 |
1 ⊕ 1 = 0 |
The XOR operator takes two bits and outputs one bit:
Useful properties of XOR:
x ⊕ 0 = x |
x ⊕ x = 0 |
x ⊕ y = y ⊕ x |
(x ⊕ y) ⊕ z = x ⊕ (y ⊕ z) |
(x ⊕ y) ⊕ x = y |
Computer Science 161
Review: XOR Algebra
7
y ⊕ 1 = 0 | Goal: Solve for y |
y ⊕ 1 ⊕ 1 = 0 ⊕ 1 | XOR both sides by 1 |
y = 1 | Simplify with identities |
Computer Science 161
One-Time Pads: Key Generation
8
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
One-Time Pads: Encryption
9
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
One-Time Pads: Encryption
10
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
One-Time Pads: Decryption
11
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
One-Time Pads: Decryption
12
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
One-Time Pad
13
Computer Science 161
One-Time Pad: Correctness
14
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
One-Time Pad: Security
which message was sent is 1/2, then the
encryption scheme is confidential
15
Alice (challenger)
Eve (adversary)
M0 and M1
Enc(K, Mb)
Guess b = 0 or b = 1
pick b
15
KeyGen():K
Computer Science 161
One-Time Pad: Security
16
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
By “perfectly” we mean that any attacker has chance of winning the security game exactly ½ (not ½+epsilon)
Computer Science 161
Two-Time Pads?
17
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
Two-Time Pads?
18
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
Two-Time Pads?
19
Computer Science 161
OTP does not offer IND-CPA
20
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
Keygen()
Computer Science 161
Impracticality of One-Time Pads
21
Computer Science 161
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.
22
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
A: 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
One-Time Pads in Practice: Spies
23
Computer Science 161
Two-Time Pads in Practice: VENONA
24
Computer Science 161
Summary for one-time pads
25
Computer Science 161
Block Ciphers
26
Textbook Chapter 6.4 & 6.5
Computer Science 161
Cryptography Roadmap
| Symmetric-key | Asymmetric-key |
Confidentiality |
|
|
Integrity,�Authentication |
|
|
Computer Science 161
Block Ciphers: Definition
28
E
K
k bits
n bits
plaintext
n bits
ciphertext
D
K
k bits
n bits
ciphertext
n bits
plaintext
Computer Science 161
Block Ciphers: Correctness
29
00
01
10
11
00
01
10
11
00
01
10
11
00
01
10
11
Not bijective: Two inputs encode to the same output
Bijective: Each input maps to exactly one unique output
Computer Science 161
Block Ciphers: Security
30
00
01
10
11
00
01
10
11
00
01
10
11
00
01
10
11
One of these is EK with a randomly chosen K, and the other one is a randomly chosen permutation. Eve can’t distinguish them.
??
Computer Science 161
Block ciphers: Brute-force attacks?
31
Computer Science 161
Block ciphers: Brute-force attacks?
32
Computer Science 161
Block Ciphers: Efficiency
33
Computer Science 161
DES (Data Encryption Standard)
34
Computer Science 161
AES (Advanced Encryption Standard)
35
Computer Science 161
Are Block Ciphers IND-CPA Secure?
36
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
AES (Advanced Encryption Standard)
37
Computer Science 161
AES Algorithm
38
Computer Science 161
AES Algorithm: SubBytes()
39
Computer Science 161
AES Algorithm: ShiftRows()
40
Computer Science 161
AES Algorithm: MixColumns()
41
Computer Science 161
AES Algorithm: AddRoundKey()
42
Computer Science 161
AES (Advanced Encryption Standard)
43
Computer Science 161
Issues with Block Ciphers
44
Computer Science 161
Summary: Block Ciphers
45
Computer Science 161
Block Cipher Modes of Operation
46
Textbook Chapter 6.6–6.9
Computer Science 161
Scratchpad: Let’s design it together
47
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
Scratchpad: Let’s design it together
48
Idea: Let’s use AES twice!
First 128 bits of message
Second 128 bits of message
Computer Science 161
Scratchpad: Let’s design it together
49
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
ECB Mode
50
Computer Science 161
ECB Mode: Penguin
Original image
51
Computer Science 161
ECB Mode: Penguin
Encrypted with ECB
52
Computer Science 161
Scratchpad: Let’s design it together
53
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
Scratchpad: Let’s design it together
54
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
Scratchpad: Let’s design it together
55
Idea: The first ciphertext block was computed with some randomness. Let’s use it to add randomness to the second block.
Computer Science 161
Scratchpad: Let’s design it together
56
Now the second ciphertext block has some randomness in it. Let’s use it to add randomness to the third block.
Computer Science 161
CBC Mode
57
P1
P2
Pm
Computer Science 161
CBC Mode: Decryption
58
Computer Science 161
CBC Mode: Decryption
59
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
CBC Mode: Efficiency & Parallelism
60
Computer Science 161
CBC Mode: Padding
61
Computer Science 161
CBC Mode: Padding
62
Computer Science 161
CBC Mode: Security
63
Computer Science 161
CBC Mode: IV Reuse
64
Computer Science 161
CBC Mode is IND-CPA (when used correctly)
65
P1
P2
Pm
Computer Science 161
CBC Mode: Penguin
Original image
66
Computer Science 161
CBC Mode: Penguin
Encrypted with CBC, with random IVs
67
Computer Science 161