From c1244dd339fe2b35e0bf136bdc16146fedc65047 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Fri, 4 Jan 2013 20:53:23 -0600 Subject: [PATCH] CFB didn't always work in continuous mode --- phpseclib/Crypt/DES.php | 6 ++++-- phpseclib/Crypt/Rijndael.php | 6 ++++-- phpseclib/Crypt/TripleDES.php | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/phpseclib/Crypt/DES.php b/phpseclib/Crypt/DES.php index 8b857c6c..279b6793 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -777,12 +777,14 @@ class Crypt_DES { if (strlen($buffer['ciphertext'])) { $plaintext = $ciphertext ^ substr($this->decryptIV, strlen($buffer['ciphertext'])); $buffer['ciphertext'].= substr($ciphertext, 0, strlen($plaintext)); - if (strlen($buffer['ciphertext']) == 8) { + if (strlen($buffer['ciphertext']) != 8) { + $block = $this->decryptIV; + } else { + $block = $buffer['ciphertext']; $xor = $this->_processBlock($buffer['ciphertext'], CRYPT_DES_ENCRYPT); $buffer['ciphertext'] = ''; } $start = strlen($plaintext); - $block = $this->decryptIV; } else { $plaintext = ''; $xor = $this->_processBlock($this->decryptIV, CRYPT_DES_ENCRYPT); diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index dc22488b..d358fb47 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -887,12 +887,14 @@ class Crypt_Rijndael { if (strlen($buffer['ciphertext'])) { $plaintext = $ciphertext ^ substr($this->decryptIV, strlen($buffer['ciphertext'])); $buffer['ciphertext'].= substr($ciphertext, 0, strlen($plaintext)); - if (strlen($buffer['ciphertext']) == $block_size) { + if (strlen($buffer['ciphertext']) != $block_size) { + $block = $this->decryptIV; + } else { + $block = $buffer['ciphertext']; $xor = $this->_encryptBlock($buffer['ciphertext']); $buffer['ciphertext'] = ''; } $start = strlen($plaintext); - $block = $this->decryptIV; } else { $plaintext = ''; $xor = $this->_encryptBlock($this->decryptIV); diff --git a/phpseclib/Crypt/TripleDES.php b/phpseclib/Crypt/TripleDES.php index f92f7c34..bc9e6c2d 100644 --- a/phpseclib/Crypt/TripleDES.php +++ b/phpseclib/Crypt/TripleDES.php @@ -825,14 +825,16 @@ class Crypt_TripleDES { if (strlen($buffer['ciphertext'])) { $plaintext = $ciphertext ^ substr($this->decryptIV, strlen($buffer['ciphertext'])); $buffer['ciphertext'].= substr($ciphertext, 0, strlen($plaintext)); - if (strlen($buffer['ciphertext']) == 8) { + if (strlen($buffer['ciphertext']) != 8) { + $block = $this->decryptIV; + } else { + $block = $buffer['ciphertext']; $xor = $des[0]->_processBlock($buffer['ciphertext'], CRYPT_DES_ENCRYPT); $xor = $des[1]->_processBlock($xor, CRYPT_DES_DECRYPT); $xor = $des[2]->_processBlock($xor, CRYPT_DES_ENCRYPT); $buffer['ciphertext'] = ''; } $start = strlen($plaintext); - $block = $this->decryptIV; } else { $plaintext = ''; $xor = $des[0]->_processBlock($this->decryptIV, CRYPT_DES_ENCRYPT);