derick Sat Dec 1 17:19:46 2007 UTC
Added files:
/php-src/ext/mcrypt/tests bug43143.phpt
Modified files:
/php-src/ext/mcrypt mcrypt.c
Log:
- Fixed bug #43143 (Warning about empty IV with MCRYPT_MODE_ECB).
http://cvs.php.net/viewvc.cgi/php-src/ext/mcrypt/mcrypt.c?r1=1.107&r2=1.108&diff_format=u
Index: php-src/ext/mcrypt/mcrypt.c
diff -u php-src/ext/mcrypt/mcrypt.c:1.107 php-src/ext/mcrypt/mcrypt.c:1.108
--- php-src/ext/mcrypt/mcrypt.c:1.107 Thu Sep 27 18:28:40 2007
+++ php-src/ext/mcrypt/mcrypt.c Sat Dec 1 17:19:45 2007
@@ -16,7 +16,7 @@
| Derick Rethans <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: mcrypt.c,v 1.107 2007/09/27 18:28:40 dmitry Exp $ */
+/* $Id: mcrypt.c,v 1.108 2007/12/01 17:19:45 derick Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -1030,7 +1030,7 @@
{
MCRYPT td;
char *cipher_dir_string, *module_dir_string, *key_copy, *iv_copy;
- int i, status = SUCCESS, count, *key_sizes, key_size, iv_size,
block_size;
+ int i, status = SUCCESS, count, *key_sizes, key_size, iv_size,
block_size, iv_req;
MCRYPT_GET_INI
@@ -1068,6 +1068,7 @@
mcrypt_free(key_sizes);
iv_size = mcrypt_enc_get_iv_size(td);
+ iv_req = mcrypt_enc_mode_has_iv(td);
if (iv_len) {
if (iv_len == iv_size) {
iv_copy = estrndup(iv_str, iv_len);
@@ -1077,7 +1078,9 @@
memcpy(iv_copy, iv_str, MIN(iv_len, iv_size));
}
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to use an
empty IV, which is NOT recommended");
+ if (iv_req) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to
use an empty IV, which is NOT recommended");
+ }
iv_copy = ecalloc(1, iv_size);
}
http://cvs.php.net/viewvc.cgi/php-src/ext/mcrypt/tests/bug43143.phpt?view=markup&rev=1.1
Index: php-src/ext/mcrypt/tests/bug43143.phpt
+++ php-src/ext/mcrypt/tests/bug43143.phpt
--TEST--
Bug #43143 (Warning about empty IV with MCRYPT_MODE_ECB)
--SKIPIF--
<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
--FILE--
<?php
echo "ECB\n";
$input = 'to be encrypted';
$mkey = hash('sha256', 'secret key', TRUE);
$data = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $mkey, $input, MCRYPT_MODE_ECB);
echo "CFB\n";
$input = 'to be encrypted';
$mkey = hash('sha256', 'secret key', TRUE);
$data = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $mkey, $input, MCRYPT_MODE_CFB);
echo "END\n";
?>
--EXPECTF--
ECB
CFB
Warning: mcrypt_encrypt(): Attempt to use an empty IV, which is NOT recommended
in %sbug43143.php on line 9
END
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php