summaryrefslogtreecommitdiff
path: root/ext/mcrypt
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2008-09-07 22:57:37 +0000
committerFelipe Pena <felipe@php.net>2008-09-07 22:57:37 +0000
commit49fc9c9e137abcd4672c86d4216a339bf04f4830 (patch)
treee8330c67328796a0822aaa59a50eb491b42bd7ff /ext/mcrypt
parent27637afb90cdd484d63335d467e4f51c1b7074b0 (diff)
downloadphp-git-49fc9c9e137abcd4672c86d4216a339bf04f4830.tar.gz
- MFH: Fixed bug #46010 (warnings incorrectly generated for iv in ecb mode)
Diffstat (limited to 'ext/mcrypt')
-rw-r--r--ext/mcrypt/mcrypt.c23
-rw-r--r--ext/mcrypt/tests/bug46010.phpt14
2 files changed, 26 insertions, 11 deletions
diff --git a/ext/mcrypt/mcrypt.c b/ext/mcrypt/mcrypt.c
index 61bfdfd7f7..ef4aaeac15 100644
--- a/ext/mcrypt/mcrypt.c
+++ b/ext/mcrypt/mcrypt.c
@@ -1196,7 +1196,7 @@ static void php_mcrypt_do_crypt(char* cipher, const char *key, int key_len, cons
{
char *cipher_dir_string;
char *module_dir_string;
- int block_size, max_key_length, use_key_length, i, count, iv_size, req_iv;
+ int block_size, max_key_length, use_key_length, i, count, iv_size;
unsigned long int data_size;
int *key_length_sizes;
char *key_s = NULL, *iv_s;
@@ -1244,16 +1244,17 @@ static void php_mcrypt_do_crypt(char* cipher, const char *key, int key_len, cons
/* Check IV */
iv_s = NULL;
iv_size = mcrypt_enc_get_iv_size (td);
- req_iv = mcrypt_enc_mode_has_iv(td);
- if (argc == 5) {
- if (iv_size != iv_len) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_IV_WRONG_SIZE);
- } else {
- iv_s = emalloc(iv_size + 1);
- memcpy(iv_s, iv, iv_size);
- }
- } else if (argc == 4) {
- if (req_iv == 1) {
+
+ /* IV is required */
+ if (mcrypt_enc_mode_has_iv(td) == 1) {
+ if (argc == 5) {
+ if (iv_size != iv_len) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, MCRYPT_IV_WRONG_SIZE);
+ } else {
+ iv_s = emalloc(iv_size + 1);
+ memcpy(iv_s, 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--
+<?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"