From d81563d6f37983f855fdf9fd36d9c19e5ac28b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Petrich?= Date: Mon, 21 Jan 2013 15:46:44 +0700 Subject: [PATCH] Rijndael: little code optimizing little code optimizing --- phpseclib/Crypt/Rijndael.php | 39 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index aa524806..7643ae17 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -765,8 +765,13 @@ class Crypt_Rijndael { case CRYPT_RIJNDAEL_MODE_CFB: // cfb loosely routines inspired by openssl's: // http://cvs.openssl.org/fileview?f=openssl/crypto/modes/cfb128.c&v=1.3.2.2.2.1 - $iv = $this->encryptIV; - $pos = $this->continuousBuffer === true ? $buffer['pos'] : 0; + if ($this->continuousBuffer) { + $iv = &$this->encryptIV; + $pos = &$buffer['pos']; + } else { + $iv = $this->encryptIV; + $pos = 0; + } $len = strlen($plaintext); $i = 0; if ($pos) { @@ -793,15 +798,10 @@ class Crypt_Rijndael { } if ($len) { $iv = $this->_encryptBlock($iv); - //$block = substr($iv, $pos, $len) ^ substr($plaintext, $i, $len); - $block = substr($iv, $pos) ^ substr($plaintext, $i); + $block = $iv ^ substr($plaintext, $i); $iv = substr_replace($iv, $block, 0, $len); $ciphertext.= $block; - $pos+= $len; - } - if($this->continuousBuffer) { - $this->encryptIV = $iv; - $buffer['pos'] = $pos; + $pos = $len; } break; case CRYPT_RIJNDAEL_MODE_OFB: @@ -896,8 +896,13 @@ class Crypt_Rijndael { } break; case CRYPT_RIJNDAEL_MODE_CFB: - $iv = $this->decryptIV; - $pos = $this->continuousBuffer === true ? $buffer['pos'] : 0; + if ($this->continuousBuffer) { + $iv = &$this->decryptIV; + $pos = &$buffer['pos']; + } else { + $iv = $this->decryptIV; + $pos = 0; + } $len = strlen($ciphertext); $i = 0; if ($pos) { @@ -926,13 +931,9 @@ class Crypt_Rijndael { } if ($len) { $iv = $this->_encryptBlock($iv); - $plaintext.= substr($iv, $pos) ^ substr($ciphertext, $i); - $iv = substr_replace($iv, substr($ciphertext, $i, $len), 0, $len); - $pos+= $len; - } - if ($this->continuousBuffer) { - $this->decryptIV = $iv; - $buffer['pos'] = $pos; + $plaintext.= $iv ^ substr($ciphertext, $i); + $iv = substr_replace($iv, substr($ciphertext, $i), 0, $len); + $pos = $len; } break; case CRYPT_RIJNDAEL_MODE_OFB: @@ -1499,4 +1500,4 @@ class Crypt_Rijndael { } // vim: ts=4:sw=4:et: -// vim6: fdl=1: \ No newline at end of file +// vim6: fdl=1: