[Botan-devel] Botan IV key incompatibility?

John Proffer jproffer at vli-dc.com
Sun Jul 1 17:12:36 EDT 2007


Well the documentation for PHP's mcrypt functions kinda sucks, but here's the result of:

/* code */
<?php echo "IV Size: ".mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,MCRYPT_MODE_CFB); ?>

/* result */
IV Size: 32

/* end pastes */

and PHP's mcrypt_get_iv_size() documentation:

mcrypt_get_iv_size
Returns the size of the IV belonging to a specific cipher/mode combination (PHP 4 >= 4.0.2, PHP 5) 

int mcrypt_get_iv_size ( string cipher, string mode )

mcrypt_get_iv_size() returns the size of the Initialisation Vector (IV) in bytes. On error the function returns FALSE. 
If the IV is ignored in the specified cipher/mode combination zero is returned. 

cipher is one of the MCRYPT_ciphername constants of the name of the algorithm as string. 

mode is one of the MCRYPT_MODE_modename constants or one of "ecb", "cbc", "cfb", "ofb", "nofb" or "stream". 
The IV is ignored in ECB mode as this mode does not require it. You will need to have the same IV (think: starting point) 
both at encryption and decryption stages, otherwise your encryption will fail. 




On Sun, Jul 01, 2007 at 03:16:40PM -0400, John Proffer wrote:
>/ Hi,
/>/ 
/>/ While trying to do database validation, and have encountered a problem - 
/>/ seems that Botan's AES implementation is incompatible with that used by 
/>/ PHP?  PHP needs an IV the same size as the blocksize (32 bytes).. 
/>/ whereas Botan's IV only works on 16 bytes when using AES-256.
/
AES's blocksize is always 16 bytes (128 bits). Are you sure that PHP
is not requiring 32 bytes in hex (16 bytes of binary)?

>/ In the following code, Botan segfaults my application at cipher->set_iv(iv);
/>/ 
/>/    Botan::byte mykey[33] =  {"Uf0zFs97zUNzPzHa9z_zz!z:L=ozxz!z"};
/>/    Botan::byte mypass[33] = {"UfzzFs97zUzzP2Ha98_az!z:L=ozxz!j"};
/>/    Botan::SymmetricKey key(mypass,32);
/>/    Botan::InitializationVector iv(mykey,32);
/>/    Keyed_Filter* cipher = get_cipher("AES-256/CFB/NoPadding", ENCRYPTION);
/>/    cipher->set_key(key);
/>/    cipher->set_iv(iv);
/>/ 
/>/ Shouldn't the IV be expecting 32 bytes when declaring AES-256 as the 
/>/ cipher?  Am I calling this in the wrong order or something?
/>/ 
/
It should not segfault. It does throw an exception:

$ ./a.out
terminate called after throwing an instance of 'Botan::Invalid_IV_Length'
  what():  Botan: IV length 32 is invalid for AES-256/CFB
Aborted

Jack

-------------- next part --------------
A non-text attachment was scrubbed...
Name: jproffer.vcf
Type: text/x-vcard
Size: 392 bytes
Desc: not available
Url : http://www.randombit.net/pipermail/botan-devel/attachments/20070701/883b8ec7/jproffer.vcf


More information about the botan-devel mailing list