I seen a lot of AES implementation samples wide spreaded over the Internet in almost every language I can recognize. There is one difference that I reflect to be repeated between all.
Some of them are require a IV and a key. Two entities. Some of them reuse a part of the 128 bit key as a IV. One entity (in my eyes).
For instance, this can be found on the net
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(password, salt); rijndael.Key = pdb.GetBytes(32); rijndael.IV = pdb.GetBytes(16);
..and the whole sample this part come from is quite wide spreaded. Even in MSDN forums. One other hit on the net with 22 upvotes says "This is plug and play code that I found on internet. It just works:"
This cause me some headache. Is this secure? I can't see why authors bother to create an IV functionality just to see it being shortcut just by cutting key in half to produce a byte array with size that fit IV?
I feel that the question will be more complex because if the different cipher modes use the IV on different way. Also it may be dependent on how the application is built. For instance; is the full key always unique? If not, how is the entropy of the key? And separately, is the pair (iv, password) always unique?
By looking at many of the samples that populate IV with a part of the key, they posted an static 16 byte array with fixed values. No indication or attempt to make audience understand that the sample is expected to be used for random -whatever- keys.
Is it safe to use a part of the key as IV and what is best practice?