CBC Decryption via ECB Oracle
- •
What it is
- •
A technique for decrypting CBC-mode ciphertext using only an ECB decryption oracle, by exploiting the fact that CBC decryption is — the ECB oracle directly supplies for any block you feed it.
- •
- •
When to apply
- •
You have an oracle that decrypts arbitrary blocks under ECB (no chaining) with the same key used to CBC-encrypt a separate target, and you know or can extract the target's IV (e.g. it's prepended to the ciphertext).
- •
- •
Math
- •
, with .
- •
- •
Worked example
- •
Plaintext
SECRET_BLOCK_ONESECRET_BLOCK_TWO(2 blocks), CBC-encrypted with a random IV. Feeding each ciphertext block through an ECB decrypt oracle and XORing with the preceding ciphertext block (IV for block 1) reconstructed the plaintext exactly, byte for byte.
- •
- •
Python
- •
plaintext = b"" prev = iv for block in ciphertext_blocks: decrypted_block = ecb_decrypt_oracle(block) plaintext += xor(decrypted_block, prev) prev = block
- •
- •
- •