13

I am using AES-256 encryption with CFB mode. I have to use 32 byte key. But I am little bit confused about the initialization vector. How many bytes of initialization vector should be used with AES-256 ? Is it 16 bytes or 32 bytes ?

Any code example will be appreciated.

2
  • 4
    Typically the size of the IV is the size of the block which is always 128 bit (=16 bytes) in AES, even if the keysize is larger than the block size.
    – Marwie
    Jun 30, 2015 at 7:36
  • Why are you confused? Try to pass an IV that is not 16 bytes long and see what happens.
    – Artjom B.
    Jun 30, 2015 at 7:47

1 Answer 1

20

TL;DR: AES in CFB mode requires a unique (but not necessarily randomized) IV of 16 bytes.


The size of the IV depends on the mode, but typically it is the same size as the block size, which for AES is always 16 bytes. There are modes that differ from this, notably GCM mode which has a default size of 12 bytes but can take any sized IV - although keeping to the default is highly recommended.

The old school modes such as CBC and CFB however simply require an IV of the same size as the block size. Even CTR commonly requires 16 bytes, although in principle the IV can be any size less than 16, in which case it is (again, commonly) right padded with zero valued bytes. Note that CTR is often initialized with an initial counter value which means you must make sure that the counter is not repeated yourself.

The block size of AES is 16 bytes, whatever the key size. Saying that you have AES-256 and a key of 32 bytes is superfluous information. For AES-256 the key size must be 256 bits or 32 bytes.

The IV for CFB mode - as stated earlier - must always be 16 bytes as AES is a 128 bit block cipher. AES is restricted with regards to the block size compared with the Rijndael cipher. Rijndael may be configured with different block sizes.

4
  • Nit, since necroed: saying AES-256 key is 32 bytes in Java (where byte is 8 bytes, not always the case elsewhere) is redundant, duplicative, unnecessary, superflous, and some other unflattering adjectives -- but not spurious. Upvoted anyway :-) Jan 24, 2020 at 1:04
  • @dave_thompson_085 That was quite an extreme nitpick, you must have a tunneling microscope over there :) Jan 24, 2020 at 3:05
  • Not really; it's quite obvious to me just reading the text. But as I indicated, perhaps too tersely, I agree it's not at all important (nit) and I would not have posted it except that this Q was already 'risen from the dead' (necroed) by another update. :):) Jan 26, 2020 at 19:44
  • I was about to edit and replace "spurious" with "inconsistent/contradictory" but then I saw that one definition of spurious is actually "Not trustworthy; dubious or fallacious.", so in that sense the usage is not completely wrong.
    – jacobq
    May 2, 2020 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.