I see that in many scripts are used keys of 16 characters for a block of 16 byte, but can I use key of 40 (for example)? And then why in some scripts with aes module the block size is set to 32 byte if aes can handle a fixed size block of 128 bit? Is it correct?
1 Answer
I see that in many scripts are used keys of 16 characters for a block of 16 byte, but can I use key of 40 (for example)?
No, AES uses a key size of 128, 192 or 256 bits. That's 16, 24 or 32 bytes.
And then why in some scripts with aes module the block size is set to 32 byte if aes can handle a fixed size block of 128 bit? Is it correct?
No, that's not correct. It could however be that the module implements Rijndael instead of AES. AES is a subset of Rijndael, and Rijndael can have the block sizes 128, 160, 192, 224 and indeed 256 bits. So in that case the block size can be 256 bits.
Notes:
- not all implementations of Rijndael offer support for 160 and 224 bit block and key sizes (so many posts don't mention these block and key sizes);
- bytes are not characters, although the name of a byte in C/C++ is traditionally called a
char
as for ASCII each character is represented by exactly one byte - no conversion necessary; - sometimes when characters are mentioned they actually contain hexadecimal digits; as you need two hexadecimal digits to represent one byte it may seem that 256 bits are used instead of the actual 128 bits.
-
$\begingroup$ thanks for the clarification, but if aes supports keys of 256 bit can i use a longer key? $\endgroup$– HenryCCommented Mar 18, 2016 at 0:34
-
$\begingroup$ @HenryC you can use a key size of 16, 24, or 32 bytes $\endgroup$ Commented Mar 18, 2016 at 0:37
-
$\begingroup$ Not directly. The algorithm doesn't support it but 256 is plenty anyway. You can always use a KDF such as HKDF or PBKDF2 to compress larger input into 256 bits. Sometimes a hash or HMAC is used directly as a "poor man's" KDF (SHA-256 obviously makes a lot of sense in this case). $\endgroup$– Maarten Bodewes ♦Commented Mar 18, 2016 at 0:39