Lecture5 (With Notes)
Lecture5 (With Notes)
Ahmed Kosba
1
Outline
• Symmetric Encryption (cont.)
• 3-DES
• Randomized encryption and CPA-security
• Block cipher modes of operation (Encryption of arbitrary-length messages)
• Chosen-ciphertext Attacks
• Padding-oracle attacks
2
Triple DES (3DES)
An attempt to improve DES as DES uses a short key of only 56 bits so brute force can be applied
on it in 2^56, while we need the key to be at least 112 bits so any brute force that would be applied on it
would require 2^112 which is not computationally possible unless after a very very long time.
3
How to make use DES ideas to design a more
secure?
Options: Not a good option because ciphers are sensitive, and a small change may require many other changes and ruin it.
• Change the cipher itself to use a longer key.
• Use the cipher as a black box and construct a more secure scheme
using multiple calls with different keys.
4
Meet-in-the-middle attack: brute force on k1 and k2 separately (2^56 * 2),
this means he has (m, c) (know plaintext attack)
k1
Attempt 1 k1 x k2 x`
m E x
00...0 - (k1*, k2*) and
00...0 (k1`, k2`) ...... are set of
2^56 k2*
2^56 k1* k2 possible keys.
k2`
x`
• Double Encryption
k1` D c 11...1
11...1 k1 56 bits k2 56 bits
c = E(k2 , E(k1, m))
- Why are there many
possibilities? size of key space
is larger than the size of the
message space. x
k 128 bits m E E c
Meet-in-the-Middle Attack
- We are saving the key because when we sort, we need the key (not sequential).
to generate
table 1
to generate
table 2
(concatenate the tables) n*lg(n)
- Also, there might be duplicates in x and we can add a column to indicate whether x is from table 1 or 2.
- meet in the middle attack on 3-DES will cost 2^112.
• Suppose n is the key length of DES and b is the block length.
• Given c = E(k2 , E(k1, m))
Assume the attacker obtained a pair (m, c) - To narrow down the number of possible keys, we can try other
pairs of known plaintexts and get the intersection between the set
Let x = E(k1, m) = D(k2, c) of keys resulting from each know plaintext pair.
- For each k1 in {0,1}n, compute x = E(k1, m). Store (x, k1) in a table T1.
- For each k2 in {0,1}n, compute x’ = D(k2, c). Store (x’, k2) in a table T2.
- Find entries in T1 and T2 such that x = x’.
- Note that there can be more than one pair (k1, k2) at which x = x’, but the attack can
be repeated using other known plaintext-ciphertext pairs to find the (k1, k2) that the
sender uses.
- Time complexity: O(n 2n) if sorting is used to find the matches.
- Space complexity: O((n + b) 2n) n:b: key size
block size
Not Secure (Recall n = 56) 6
Any advantages for using decryption as the middle box?
3-DES Backward Compatibility with DES
Here, the decryption step won't cause a problem because it's done using a
different key so it would be treated as encryption
• Variant 1: k1 k2 k3
• 3 Keys
m E D E c
How would this help? Decryption block can be replaced with encryption
The previous attack (meet in the middle), would decrease block, and it would still work
the cost of brute force from 2^168 to 2^112 (our goal).
k1 k2 k1
• Variant 2:
• 2 Keys
m E D E c
• Note: It is also possible to use DES Encryption in the three blocks. Small block length of 64 bits causes problems, still.
• Variant 1 is also vulnerable to meet-in-the-middle attack, but the complexity of the attack will be 22n.
• Variant 1 provides more security theoretically than variant 2.
7
A theoretic attack was proposed against Variant 2 that requires 2n chosen plaintexts.
Status
9
How to provide security for multiple
encryptions?
• Goal: defend against an eavesdropper that observes multiple
ciphertexts. - if c1 = c2, m1 will be equal to m2 which is info for the attacker
All the previous encryption algorithms were deterministic, which means that if I try to encrypt the same plaintext more
than once, the same ciphertext will appear every time which can be negatively used by the adversary.
• Solution (informal):
• Instead of having a deterministic encryption algorithm, let the encryption
algorithm be randomized (probabilistic).
• Encrypting the same message twice should result into different ciphertexts.
• What will be the challenge if a randomized algorithm is used?
• The decryption algorithm will have to account for the randomness as well.
• Will see shortly how.
10
How to provide security against chosen-
plaintext attacks? (CPA security)
• Goal: defend against an attacker that can obtain encryptions of
chosen plaintexts.
• Known result: Defending against CPA for a single encryption will imply
CPA security for the multiple encryptions setting.
12
CPA security: How to provide security against
chosen-plaintext attacks? (Informal)
Random String r
Key F
O/P
Ciphertext
Plaintext
13
Outline
• Symmetric Encryption (cont.)
• 3-DES
• Randomized encryption and CPA-security
• Block cipher modes of operation (Encryption of arbitrary-length messages)
• Chosen-ciphertext Attacks
• Padding-oracle attacks
14
Block Cipher Modes of Operation
Encryption of Arbitrary-length Messages
15
Block Cipher Modes of Operation: ECB
1G
m1 m2 m3
k F k F
c1 c2
k F k F k F
- no randomness
- change is localized (patterns in the
plaintext appear in the ciphertext)
c1 c2 c3
Any problems?
16
Block Cipher Modes of Operation: ECB
• Problems
• No randomization (no CPA security)
• Patterns in the plaintext could appear in the resulting ciphertext.
17
Figure from Wikipedia
Block Cipher Modes of Operation: CBC
IV: initilisation vector
• Cipher Block Chaining (CBC) mode. Note: The IV is sent
with the ciphertext
IV m1 m2 m3 blocks.
c1 c2 c3
IV
….
Encryption k F-1 k F-1 k F-1
- Function (F) must be invertible to be able to decrypt the cipher
c1 c2 c3 18
Block Cipher Modes of Operation: CBC
• How to choose the initialization vector?
• The IV cannot not be predictable.
• The IV should not repeat.
• CBC characteristics:
• An invertible function is used, i.e., a pseudorandom permutation/block
cipher.
• Encryption cannot be performed in parallel.
• Decryption can be performed in parallel.
To decrypt c3, we only need c2 (already known) and IV (also known).
19
Block Cipher Modes of Operation: Stateful CBC?
• Is the chained CBC mode (stateful CBC mode) secure against CPA
attacks?
m1 m2 m3 c3 m4 m5
IV
k F k F k F k F k F
c1 c2 c4 c5
c3
Example:
The attacker can learn if m1 is a message m’ assume m1 = m` (hello)
- Set m4 = IV c3 m’ c1 Fk(IV XOR m`)
m4 = c3 XOR IV XOR m`
- Check if c4 = c1 if c4 = c1, then the message is the same (m1 = hello). 20
XORing can be done before F calculation but F operations
must be done sequentially (not parallel)
in encryption and decryption. Note: The IV is sent
Block Cipher Modes of Operation: OFB with the ciphertext
blocks.
IV
23
Security and Implementation Aspects (1/2)
• Block length: What if the block length was selected to be short?
• If the block length is short, the randomly selected IV will be expected to
repeat after a certain number of encryptions. This will break the security of
the scheme.
• Recall: The IV has the same length as the block length.
• If the block length of 64 bits, a repetition is likely to happen (with more than
0.5 probability) after more than 232 encryptions are performed.
See the Birthday paradox. We will discuss this paradox later in the course.
• The short block length is one of the DES, and 3-DES drawbacks. The block
length in AES is 128 bits, which avoids this drawback.
25
Outline
• Symmetric Encryption (cont.)
• 3-DES
• Randomized encryption and CPA-security
• Block cipher modes of operation (Encryption of arbitrary-length messages)
• Chosen-ciphertext Attacks
• Padding-oracle attacks
26
Chosen-ciphertext Attacks
27
Recall: Chosen-ciphertext Attacks
• In this threat model, the adversary can acquire decryptions of
selected ciphertexts (except for the original ciphertext).
• Is this a realistic scenario?
28
Malleability (Informal)
• An encryption scheme is malleable if it is possible to modify the
ciphertext in a way that causes a predictable change in the plaintext,
without knowing the original plaintext.
29
Malleability (Example)
c c’
Alice
Change the last few bits of c
m = WITHDRAW 1000 m’ = WITHDRAW xxxx
k
c
30
Encryption using block cipher modes of
operation - Revisited
• In the following, we will consider the CBC mode case.
• What if the plaintext message is not a multiple of the block length L in CBC
mode?
• Padding
• PKCS#5 Padding:
• If the message is of length x bytes, and the block length of length L bytes, then (L – (x
mod L)) bytes will need to be added as padding.
• Let b = L – (x mod L).
• All the padded bytes will have the value of b.
• If b = 4, then four bytes will be padded as 0x04040404.
• Note that if the message is a multiple of block length, padding would still
take place. Why? to be sure when the message actually ends and not confuse the message with padding,
31
Padding Example
• If the block length L = 8 bytes,
• The sender pads the message according to the previous rule, e.g., if the
message length is 5, it will be padded as:
xx xx xx xx xx 03 03 03
• After decryption, the receiver checks the padding and proceeds if padding
was done correctly.
32
Padding Oracle
• What if the padding is done incorrectly?
• An error message will be returned by the receiver.
• This one-bit of information can be used in an attack.
• Note: This still holds if there is any change in timing, or no responses.
33
Recall: CBC mode Encryption / Decryption
IV m1 m2 m3
….
k F k F k F Note: Any change in ci will affect mi+1
Decryption
c1 c2 c3
m1 m2 m3
Encryption
IV
….
k F-1 k F-1 k F-1
c1 c2 c3
Padding Oracle Attack
• Let’s consider two blocks only for simplicity.
• Padded plaintext = IV F-1(k, c1)
• The attacker will modify the IV, and check the reaction of the receiver.
Success/Error?
IV’, c1
IV, c1
35
Padding Oracle Attack
• Padding Oracle Attack Animation
• Slides by Prof. Jonathan Katz [Link]
• Follow-up questions:
• Why does the attacker choose to modify IV not the ciphertext?
• How to protect against this kind of attacks?
• We will study this later in the course.
36