From b1c7fed94642671e54521f5a9b6b6a32ab67985d Mon Sep 17 00:00:00 2001 From: Jim Wigginton Date: Wed, 16 Nov 2011 06:53:36 +0000 Subject: [PATCH] - the IV wasn't resetting when mcrypt was being used git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@186 21d32557-59b3-4da0-833f-c5933fad653e --- phpseclib/Crypt/AES.php | 18 ++++++++++++++++++ phpseclib/Crypt/Rijndael.php | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/phpseclib/Crypt/AES.php b/phpseclib/Crypt/AES.php index 2de8821e..07e975b8 100644 --- a/phpseclib/Crypt/AES.php +++ b/phpseclib/Crypt/AES.php @@ -258,6 +258,24 @@ class Crypt_AES extends Crypt_Rijndael { return; } + + /** + * Sets the initialization vector. (optional) + * + * SetIV is not required when CRYPT_RIJNDAEL_MODE_ECB is being used. If not explictly set, it'll be assumed + * to be all zero's. + * + * @access public + * @param String $iv + */ + function setIV($iv) + { + parent::setIV($iv); + if ( CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT ) { + $this->changed = true; + } + } + /** * Encrypts a message. * diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index a8374daa..a123c675 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -550,7 +550,7 @@ class Crypt_Rijndael { */ function setIV($iv) { - $this->encryptIV = $this->decryptIV = $this->iv = str_pad(substr($iv, 0, $this->block_size), $this->block_size, chr(0));; + $this->encryptIV = $this->decryptIV = $this->iv = str_pad(substr($iv, 0, $this->block_size), $this->block_size, chr(0)); } /**