felipe          Sun Sep  7 22:53:21 2008 UTC

  Added files:                 
    /php-src/ext/mcrypt/tests   bug46010.phpt 

  Modified files:              
    /php-src/ext/mcrypt mcrypt.c 
  Log:
  - Fixed bug #46010 (warnings incorrectly generated for iv in ecb mode)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mcrypt/mcrypt.c?r1=1.114&r2=1.115&diff_format=u
Index: php-src/ext/mcrypt/mcrypt.c
diff -u php-src/ext/mcrypt/mcrypt.c:1.114 php-src/ext/mcrypt/mcrypt.c:1.115
--- php-src/ext/mcrypt/mcrypt.c:1.114   Wed Jul 16 08:00:43 2008
+++ php-src/ext/mcrypt/mcrypt.c Sun Sep  7 22:53:20 2008
@@ -16,7 +16,7 @@
    |          Derick Rethans <[EMAIL PROTECTED]>                    |
    +----------------------------------------------------------------------+
  */
-/* $Id: mcrypt.c,v 1.114 2008/07/16 08:00:43 tony2001 Exp $ */
+/* $Id: mcrypt.c,v 1.115 2008/09/07 22:53:20 felipe Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -1276,7 +1276,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, iv_req;
+       int i, status = SUCCESS, count, *key_sizes, key_size, iv_size, 
block_size;
        
        MCRYPT_GET_INI
        
@@ -1314,20 +1314,20 @@
        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);
+       /* IV is required */
+       if (mcrypt_enc_mode_has_iv(td) == 1) {
+               if (iv_len) {
+                       if (iv_len == iv_size) {
+                               iv_copy = estrndup(iv_str, iv_len);
+                       } else {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
MCRYPT_IV_WRONG_SIZE);
+                               iv_copy = ecalloc(1, iv_size);
+                               memcpy(iv_copy, iv_str, MIN(iv_len, iv_size));
+                       }
                } else {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, 
MCRYPT_IV_WRONG_SIZE);
-                       iv_copy = ecalloc(1, iv_size);
-                       memcpy(iv_copy, iv_str, MIN(iv_len, iv_size));
-               }
-       } else {
-               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);
                }
-               iv_copy = ecalloc(1, iv_size);
        }
        
        if (mcrypt_enc_is_block_mode(td) == 1) {

http://cvs.php.net/viewvc.cgi/php-src/ext/mcrypt/tests/bug46010.phpt?view=markup&rev=1.1
Index: php-src/ext/mcrypt/tests/bug46010.phpt
+++ php-src/ext/mcrypt/tests/bug46010.phpt
--TEST---
Bug #46010 (warnings incorrectly generated for iv in ecb mode)
--FILE--
<?php

var_dump(bin2hex(mcrypt_encrypt(MCRYPT_TRIPLEDES, "key", "data", 
MCRYPT_MODE_ECB)));
var_dump(bin2hex(mcrypt_encrypt(MCRYPT_TRIPLEDES, "key", "data", 
MCRYPT_MODE_ECB, "a")));
var_dump(bin2hex(mcrypt_encrypt(MCRYPT_TRIPLEDES, "key", "data", 
MCRYPT_MODE_ECB, "12345678")));

?>
--EXPECTF--
string(16) "372eeb4a524b8d31"
string(16) "372eeb4a524b8d31"
string(16) "372eeb4a524b8d31"



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to