@@ -900,8 +900,10 @@ function encrypt($plaintext)
900900 $ xor = $ this ->encryptIV ;
901901 if (strlen ($ buffer ['xor ' ])) {
902902 for ($ i = 0 ; $ i < strlen ($ plaintext ); $ i +=$ block_size ) {
903- $ xor = $ this ->_encryptBlock ($ xor );
904- $ buffer ['xor ' ].= $ xor ;
903+ if (strlen ($ block ) > strlen ($ buffer ['xor ' ])) {
904+ $ xor = $ this ->_encryptBlock ($ xor );
905+ $ buffer ['xor ' ].= $ xor ;
906+ }
905907 $ key = $ this ->_string_shift ($ buffer ['xor ' ], $ block_size );
906908 $ ciphertext .= substr ($ plaintext , $ i , $ block_size ) ^ $ key ;
907909 }
@@ -1038,8 +1040,10 @@ function decrypt($ciphertext)
10381040 $ xor = $ this ->decryptIV ;
10391041 if (strlen ($ buffer ['xor ' ])) {
10401042 for ($ i = 0 ; $ i < strlen ($ ciphertext ); $ i +=$ block_size ) {
1041- $ xor = $ this ->_encryptBlock ($ xor );
1042- $ buffer ['xor ' ].= $ xor ;
1043+ if (strlen ($ block ) > strlen ($ buffer ['xor ' ])) {
1044+ $ xor = $ this ->_encryptBlock ($ xor );
1045+ $ buffer ['xor ' ].= $ xor ;
1046+ }
10431047 $ key = $ this ->_string_shift ($ buffer ['xor ' ], $ block_size );
10441048 $ plaintext .= substr ($ ciphertext , $ i , $ block_size ) ^ $ key ;
10451049 }
@@ -1139,7 +1143,7 @@ function _encryptBlock($in)
11391143 $ l = ($ l + 1 ) % $ Nb ;
11401144 }
11411145
1142- // 100% ugly switch/case code... but ~5% faster (meaning: ~half second faster de/encrypting 1MB text, tested with php5.4.9 on linux/32bit with an AMD Athlon II P360 CPU) then the commented smart code below. Don't know it's worth or not
1146+ // 100% ugly switch/case code... but ~5% faster (" smart code" below commented out)
11431147 switch ($ Nb ) {
11441148 case 8 :
11451149 return pack ('N* ' , $ temp [0 ], $ temp [1 ], $ temp [2 ], $ temp [3 ], $ temp [4 ], $ temp [5 ], $ temp [6 ], $ temp [7 ]);
@@ -1969,10 +1973,12 @@ function inline_crypt_setup()
19691973
19701974 if (strlen($buffer["xor"])) {
19711975 for ($i = 0; $i < $plaintext_len; $i+= ' .$ block_size .') {
1972- $in = $xor;
1973- ' .$ _encryptBlock .'
1974- $xor = $in;
1975- $buffer["xor"].= $xor;
1976+ if (strlen($block) > strlen($buffer["xor"])) {
1977+ $in = $xor;
1978+ ' .$ _encryptBlock .'
1979+ $xor = $in;
1980+ $buffer["xor"].= $xor;
1981+ }
19761982 $key = $self->_string_shift($buffer["xor"], ' .$ block_size .');
19771983 $ciphertext.= substr($text, $i, ' .$ block_size .') ^ $key;
19781984 }
@@ -2002,10 +2008,12 @@ function inline_crypt_setup()
20022008
20032009 if (strlen($buffer["xor"])) {
20042010 for ($i = 0; $i < $ciphertext_len; $i+= ' .$ block_size .') {
2005- $in = $xor;
2006- ' .$ _encryptBlock .'
2007- $xor = $in;
2008- $buffer["xor"].= $xor;
2011+ if (strlen($block) > strlen($buffer["xor"])) {
2012+ $in = $xor;
2013+ ' .$ _encryptBlock .'
2014+ $xor = $in;
2015+ $buffer["xor"].= $xor;
2016+ }
20092017 $key = $self->_string_shift($buffer["xor"], ' .$ block_size .');
20102018 $plaintext.= substr($text, $i, ' .$ block_size .') ^ $key;
20112019 }
0 commit comments