From 2deea8b4913ec9801c23c87cc2dbc4de073a4835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Petrich?= Date: Mon, 21 Jan 2013 10:08:49 +0700 Subject: [PATCH] AES: Fixed CFB decrypt() using MODE_MCRYPT and ContinuousBuffer AES: Fixed small bug from commit https://github.com/phpseclib/phpseclib/commit/d94f1b252db66f52c42fcc8d4c6f1a3f10f5ff4e (AES.php in line 425-426) in CFB decrypt() using CRYPT_AES_MODE_MCRYPT and enableContinuousBuffer() --- phpseclib/Crypt/AES.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/phpseclib/Crypt/AES.php b/phpseclib/Crypt/AES.php index 0e0e9081..4e612eb1 100644 --- a/phpseclib/Crypt/AES.php +++ b/phpseclib/Crypt/AES.php @@ -337,12 +337,11 @@ class Crypt_AES extends Crypt_Rijndael { } $ciphertext.= mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % 16)); $iv = substr($ciphertext, -16); - $i = strlen($ciphertext); $len%= 16; } if ($len) { $iv = mcrypt_generic($this->ecb, $iv); - $block = substr($iv, $pos) ^ substr($plaintext, $i); + $block = $iv ^ substr($plaintext, -$len); $iv = substr_replace($iv, $block, 0, $len); $ciphertext.= $block; $pos = $len; @@ -412,7 +411,6 @@ class Crypt_AES extends Crypt_Rijndael { // ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize $plaintext = substr($iv, $orig_pos) ^ $ciphertext; $iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i); - $this->debuffer['demcrypt_init'] = true; } if ($len >= 16) { $cb = substr($ciphertext, $i, $len - $len % 16); @@ -422,8 +420,8 @@ class Crypt_AES extends Crypt_Rijndael { } if ($len) { $iv = mcrypt_generic($this->ecb, $iv); - $plaintext.= substr($iv, $pos) ^ substr($ciphertext, $i); - $iv = substr_replace($iv, substr($ciphertext, $i, $len), 0, $len); + $plaintext.= $iv ^ substr($ciphertext, -$len); + $iv = substr_replace($iv, substr($ciphertext, -$len), 0, $len); $pos = $len; } @@ -662,4 +660,4 @@ class Crypt_AES extends Crypt_Rijndael { } // vim: ts=4:sw=4:et: -// vim6: fdl=1: \ No newline at end of file +// vim6: fdl=1: