# Implementing AES-CBC (Matasano Crypto Challenge 10)

I am currently doing the Matasano Crypto Challenge to learn a bit about cryptography. In that specific challenge one had to implement AES in CBC mode. I did that and verified that encryption and decryption are working using these test vectors. I can't manage to decrypt the message given in the challenge though. I am not asking you to decrypt it, but when I thought about it a bit more I got a bit confused due to the used IV (which is 0x00 for each byte). Doesn't this IV have no effect at all since the decrypted message just get's XORed against the IV? Shouldn't decryption also be possible using simple AES-ECB?

EDIT: Sourcecode in Java: http://pastebin.com/cX8YZjD0

• IV equals to constant zero means that the IV has no impact only on the first block. but for all the others something changes, try to give a look to this picture (from here: di.ens.fr/~jean/latex_crypto). For the first block you xor it with zero, but for the second you xor it with $c_0$ ... Dec 1 '15 at 12:51
• True, I forgot about that since I only dealt with 16 byte texts.. But the first 16 byte are encrypted just like with ECB, aren't they? Does this also mean something is wrong when my algorithm produces random gibberish in the first 16 bytes?
– Joba
Dec 1 '15 at 13:06
• You might have the wrong key. Or maybe the first 16 bytes of plaintext are gibberish. With an all 0 IV and 16 byte plaintext, yes, it is equivalent to ECB. Dec 1 '15 at 13:38
• @Joba, sorry, I did not check the plaintext length, so my comment was more general. Dec 1 '15 at 13:43

I suppose you have removed the base64 decoding, so you are working on the raw data.

Then indeed the first block is decrypted as if we were in ECB-mode, because after decrypting the first block, we xor with the IV, which is all 0 and indeed has no effect.

However, the IV for the next block will be the original previous ciphertext block. So after decrypting that block we have to xor with this new IV, so there we cannot suffice with just ECB mode. See also this picture from the comments:

• I in fact implemented that in my algorithm. However the same algorithm that decrypted the code in the ECB challenge doesn't even work on the first block of this one. I suppose this is not the right place to post my code?
– Joba
Dec 1 '15 at 21:10
• @Joba Posting of code has been known to happen here... Dec 1 '15 at 21:12
• Does that mean I should, or should I rather do that on StackOverflow?
– Joba
Dec 1 '15 at 21:24
• I say, post it. Dec 2 '15 at 4:47
• Editied in a link to the sourcecode.
– Joba
Dec 2 '15 at 9:55