encryptionaesencryption-symmetricsymmetric-key

Can we use the key as the IV for AES?


I wish to be more efficient in generating a random key and a random IV for the encryption. But is it workable and safe to use the random key as the IV?


Solution

  • You could but it would not be secure.

    The usual practice is to use a cryptographically secure random byte sequence for the iv and to prepend the iv to the encrypted data. This allows the decryption function to have the same iv.

    By using a random iv if the same message is encrypted with the same key the cipher text will be different, usia the key will allow the same cipher text. Having the same cipher text may give away crucial information.

    Trading efficiency for security is not a good idea and if it is not proven that the extra efficiency is needed by benchmark testing it is premature optimization.

    Donald Knuth:

    The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming.