Edit report at https://bugs.php.net/bug.php?id=60705&edit=1
ID: 60705 Comment by: a...@php.net Reported by: erno dot kovacs at freemail dot hu Summary: rijndael iv problem Status: Open Type: Bug Package: mcrypt related Operating System: linux/windows PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: After looking at the mcrypt implementation it turns out, that the way you're doing that in perl is non standard. The init vector SHOULD have the same size the block does. In your case 32 bytes. Looking at some other libs, for instance http://msdn.microsoft.com/en- us/library/system.security.cryptography.symmetricalgorithm.iv.aspx the stuff is handled the same way - vi size = block size. Previous Comments: ------------------------------------------------------------------------ [2012-01-10 23:08:05] erno dot kovacs at freemail dot hu Description: ------------ Cryptography basics: IV is always the same as the block size, which is 16 bytes (128 bits) in case of AES(Rijndael). However, when you use RIJNDAEL_192 or RIJNDAEL_256 with an IV of 16 bytes in CBC mode, you got a warning "mcrypt_generic_init() [function.mcrypt-generic-init]: Iv size incorrect; supplied length: 16, needed: 32". This is bullshit. This way if you try to decrypt data encrypted by a 32 byte (256 bit) key with 16 byte (128 bit) IV with RIJNDAEL_256 in CBC mode, the decrypted data is WRONG. Even worse, if you modify the constant to RIJNDAEL_128, it decrypts the ciphertext correctly. This is a major failure. Tested with PHP 5.3.4 Win32 and 5.3.8 Linux. Test script: --------------- http://pastebin.com/X1S7bUXV Expected result: ---------------- decrypted : hello world decrypted : *garbage* Actual result: -------------- Warning: mcrypt_generic_init() [function.mcrypt-generic-init]: Iv size incorrect; supplied length: 16, needed: 32 in ... decrypted : Ñ2âв ÐÐ/(Ñвy7YÐÆ0z=/оÑ|µ8â0У decrypted : hello world ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60705&edit=1