4.9 KiB
4.9 KiB
Padding Oracle Attacks
Block Cipher Modes
- Most messages don’t come in convenient 128-bit block lengths
- We’ll need to run a block cipher repeatedly on consecutive blocks
- Why not use stream ciphers?
- Historically stream ciphgers have proven harder to implement
Padding
- ECB and some other modes require message length to be a multiple of the block size
- Public Key Cryptography Standards
PKCS7is a common padding scheme:- Padding bytes are always added to the plaintext before it is encrypted
- Each padding byte has a value equal to the total number of padding bytes that are added
- The total number of padding bytes is atleast one

- Note in this example there are 7
7s and 1616s - Note the bottom left example there is 1
1. This could be interpreted as 1 bytes of padding or some plaintext. This is why every block must contain at least one padding byte
Electronic Code Book Mode (ECB)
- Just encrypt each block one after another
- This is quick as can be easily parallelised
Weaknesses
- If
x_1andx_3are the same, theny_1andy_3are also the same. - ECB allows an attacker to infer information on the plaintext
- Consider a hypothetical bank transfer between two banks that use a fixed key, where the message format is roughly known
- If we start splicing parts of messages together, we can send a legitimate looking message to the bank
- We could also use a chosen plaintext attack by requesting a bank transfer, finding our bank account info and splicing that with another message
- ECB divulges whenever messages or blocks are the same
Here the RGB pixel data of this image has been encrypted using AES in ECB mode
Deterministic vs Probabilistic Encryption
- An encryption scheme is deterministic if some plaintext is mapped to a fixed ciphertext if the key is unchanged
- ECB is deterministic, but most modern modes of operation of probabilistic
- Probabilistic encryption schemes add randomness to the encryption process to achieve a non-deterministic generation of the ciphertext
ris not a secret
Cipher Block Chaining (CBC)
XORthe output of each cipher block with the next inputIV- Initialisation Vector- The initial random seed that randomises the whole stream
- If you encrypted the same plaintext later it will be different
- An attacker will be unable to tell if
y_1andy_2are the same message but with differentIVor different messages with differentIV
y_1 = e_k(x_1 \oplus IV) \\
y_i = e_k(x_i \oplus y_{i-1})
CBC Decryption
- Similar to encryption, but now
XORtakes place after decryption - This is much easier to parallelise
x_1 = d_k(y_1) \oplus IV \\
x_i = d_k(y_i) \oplus y_{i-1}
- If we lost
y_1we would be unable to decrypty_2- We would be able to decrypt
y_3though
- We would be able to decrypt
Weaknesses
- CBC was the primary method of encryption for many years
- Now it is less common

- If you flip the first bit in
y_2, the same bit is flipped forx_3- Changing
y_2meansx_2no longer decrypts properly
- Changing
Padding Oracles
- Here, an oracle is a system we can query and it will tell us if, once decrypt, some text has valid padding
- A system is unlikely to tell you directly, but it might give away some clue
- Image an example
apithat receives a CBC encrypted authorisation token
Padding Oracle Attacks
- Lets look at a single decryption block in CBC
- The attack is essentially the same for multiple blocks, just one at a time
- You attack the last block, which contains the padding
The general strategy is to manipulate bits in the IV to find valid padding and recover
z_i
Counter Mode (CTR)
- Encrypt a nonce + counter and use this to mask the plaintext with
XOR- This is very easily parallelised
- Each block is encrypted differently, avoiding the issues with ECB mode
- We are now using our block cipher as a stream cipher
- The keystream generation (AES) is run through blocks
- Decrypting is super easy, just the reverse
Galois Counter Mode
- Extends counter mode to add authenticity
- The sender definitely sent that message and it hasn’t been modified
- Very similar to ocunter mode, but adds authentication tag
- Uses multiplication in a Galois Finite field
GF(2^{128})modulox^{128} + x^7 + x^2 + x + 1
- Uses multiplication in a Galois Finite field
- Extremely parallelsiable
- Robust to message modification
- Is now standard in
TLS1.3












