i'm trying to figure out when an Intialization Vector (IV) should be used.
There are anecdotal reports that WEP was broken because of weak IV's. It's also claimed that if two pieces of plaintext are encrypted with the same Key+IV, then it's trivial to recover the plaintext.
To test this, i've encrypted two pieces of equal length plaintext using the same IV and Key. i am using AES, which has a 128-bit block size (16 bytes), so i will make my sample plaintexts less than 16 bytes.
Ciphertext1: ba 81 1b c3 d1 6b ee bd 0a 87 23 33 04 90 5d 8a
Ciphertext2: b0 80 01 ed e8 2c 6c 60 17 b7 5d 60 37 9a e8 3d
Now the theory is that C1 ⊻ C2 = P1 ⊻ P2
:
So i calculate Ciphertext1 xor Ciphertext2
:
Ciphertext1: ba 81 1b c3 d1 6b ee bd 0a 87 23 33 04 90 5d 8a
Ciphertext2: b0 80 01 ed e8 2c 6c 60 17 b7 5d 60 37 9a e8 3d
XOR: 0A 01 1A 2E 39 47 82 DD 1D 30 7E 53 33 0A B5 B7
Now, for comparison, the XOR of the two (15 byte) plaintexts together is:
Plaintext XOR: 03 0C 1E 1F 1B 49 4E 57 28 07 15 01 53 17 18
Ciphertext XOR: AE 2C 0B F7 19 39 FA D6 0B 16 F4 59 1D EA D5 67
Which are not the same.
What causes an encryption algorithm to be weak if a specific key is used?
Pseudo sample code, using WinCrypt API:
hProvider = CryptAcquireContext(null, null, PROV_RSA_AES, CRYPT_VERIFYCONTEXT);
hKey = CryptImportKey(hProvider, keyData, sizeof(keyData), null, 0);
encryptedLength = CryptEncrypt(hKey, null, true, 0, plaintextData, plainLength);
CryptDestroyKey(hKey);
CryptReleaseContext(hProvider, 0);
In other words, in the words of MSDN:
If keys are generated for symmetric block ciphers, the key, by default, is set up in cipher block chaining (CBC) mode with an initialization vector of zero.
i am using an IV of all zeros, in CBC mode. Edit: But since there is only one block being encrypted, there is no "chaining" to be had; so the result is the came as Electronic Cookbook (ECB).