# Get IV from Key, Clear and Cipher text in AES-256 CBC

Newbie question here but can I get the IV if I know the Key, plain text and chiper text ?

(I thought that if I encrypt 16 first bytes of clear with the key and 16 first bytes of cipher text as IV it would work to get original IV but it seems that it doesn't)

Thanks.

• What's the equation relating the $i^\mathit{th}$ plaintext block $P_i$, the $i^\mathit{th}$ ciphertext block $C_i$, and cipher $E_k$ in CBC mode? Where does the initialization vector figure into it? Nov 15 '17 at 16:08
• You mean that C0 = IV ? Nov 15 '17 at 16:11
• That's part of it. How is $P_i$ related to $C_i$ for $i > 0$? Nov 17 '17 at 4:05

The IV is XOR'ed with the plaintext before encrypting the first block. You can get the input of the block cipher by decrypting the first block of ciphertext using the block cipher directly.

After that it is a simple operation to get the IV, of course, considering you know the plaintext and - hopefully - the mathematical properties of XOR.

• @zaph Maarten is talking about a straight decryption of the first block w/o involving any modes, so you don't need an IV, BTW Maarten, you may want to add some mathy formulas to your answer for illustration
– SEJPM
Nov 15 '17 at 19:50
• OK, I finally see. Thx!
– zaph
Nov 15 '17 at 19:58
• @SEJPM This is commonly a question in crypto courses to test if the student understands the mode. This is why I left out the actual calculations and schematics. Usually there is not much use for retrieving the IV, especially if the plaintext is already known anyway. Nov 15 '17 at 20:31