From: Felipe Pena Date: Sun, 7 Sep 2008 23:00:31 +0000 (+0000) Subject: - MFH: Fixed bug #46010 (warnings incorrectly generated for iv in ecb mode) X-Git-Tag: php-5.2.7RC1~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b886771f6905052d775612d26404fad6d3970be8;p=php - MFH: Fixed bug #46010 (warnings incorrectly generated for iv in ecb mode) --- diff --git a/ext/mcrypt/mcrypt.c b/ext/mcrypt/mcrypt.c index c52317e4d4..ed9ae088d5 100644 --- a/ext/mcrypt/mcrypt.c +++ b/ext/mcrypt/mcrypt.c @@ -1041,15 +1041,17 @@ static void php_mcrypt_do_crypt (char* cipher, zval **key, zval **data, char *mo /* Check IV */ iv_s = NULL; iv_size = mcrypt_enc_get_iv_size (td); - if (argc == 5) { - if (iv_size != Z_STRLEN_PP(iv)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_IV_WRONG_SIZE); - } else { - iv_s = emalloc(iv_size + 1); - memcpy(iv_s, Z_STRVAL_PP(iv), iv_size); - } - } else if (argc == 4) { - if (iv_size != 0) { + + /* IV is required */ + if (mcrypt_enc_mode_has_iv(td) == 1) { + if (argc == 5) { + if (iv_size != Z_STRLEN_PP(iv)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_IV_WRONG_SIZE); + } else { + iv_s = emalloc(iv_size + 1); + memcpy(iv_s, Z_STRVAL_PP(iv), iv_size); + } + } else if (argc == 4) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to use an empty IV, which is NOT recommend"); iv_s = emalloc(iv_size + 1); memset(iv_s, 0, iv_size + 1); diff --git a/ext/mcrypt/tests/bug46010.phpt b/ext/mcrypt/tests/bug46010.phpt new file mode 100644 index 0000000000..5aeb3119dc --- /dev/null +++ b/ext/mcrypt/tests/bug46010.phpt @@ -0,0 +1,14 @@ +--TEST--- +Bug #46010 (warnings incorrectly generated for iv in ecb mode) +--FILE-- + +--EXPECTF-- +string(16) "372eeb4a524b8d31" +string(16) "372eeb4a524b8d31" +string(16) "372eeb4a524b8d31" diff --git a/ext/mcrypt/tests/mcrypt_ecb.phpt b/ext/mcrypt/tests/mcrypt_ecb.phpt index 75d9570922..3edc407157 100644 --- a/ext/mcrypt/tests/mcrypt_ecb.phpt +++ b/ext/mcrypt/tests/mcrypt_ecb.phpt @@ -14,10 +14,10 @@ $enc_data = mcrypt_ecb($cipher, $key, $secret, MCRYPT_ENCRYPT, $iv); // we have to trim as AES rounds the blocks and decrypt doesnt detect that echo trim(mcrypt_ecb($cipher, $key, $enc_data, MCRYPT_DECRYPT, $iv)) . "\n"; -// a warning must be issued if we don't use a IV on a AES cipher, that usually requires an IV +// a warning not must be issued if we don't use a IV on a AES cipher, that not requires an IV mcrypt_ecb($cipher, $key, $enc_data, MCRYPT_DECRYPT); --EXPECTF-- PHP Testfest 2008 -Warning: mcrypt_ecb(): Attempt to use an empty IV, which is NOT recommend in %s on line %d +