1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-12-13 17:47:29 +01:00

[Triple]DES, Rijndael: Fix overflow in OFB mode

Related to: https://github.com/phpseclib/phpseclib/issues/77
This commit is contained in:
Hans-Jürgen Petrich 2013-03-05 12:25:16 +07:00
parent a45e528ac6
commit deb1516296
3 changed files with 13 additions and 7 deletions

View File

@ -846,7 +846,7 @@ class Crypt_DES {
$xor = $this->decryptIV;
if (strlen($buffer['xor'])) {
for ($i = 0; $i < strlen($ciphertext); $i+=8) {
$block = substr($plaintext, $i, 8);
$block = substr($ciphertext, $i, 8);
if (strlen($block) > strlen($buffer['xor'])) {
$xor = $this->_processBlock($xor, CRYPT_DES_ENCRYPT);
$buffer['xor'].= $xor;

View File

@ -900,12 +900,13 @@ class Crypt_Rijndael {
$xor = $this->encryptIV;
if (strlen($buffer['xor'])) {
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
$block = substr($plaintext, $i, $block_size);
if (strlen($block) > strlen($buffer['xor'])) {
$xor = $this->_encryptBlock($xor);
$buffer['xor'].= $xor;
}
$key = $this->_string_shift($buffer['xor'], $block_size);
$ciphertext.= substr($plaintext, $i, $block_size) ^ $key;
$ciphertext.= $block ^ $key;
}
} else {
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
@ -1040,12 +1041,13 @@ class Crypt_Rijndael {
$xor = $this->decryptIV;
if (strlen($buffer['xor'])) {
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
$block = substr($ciphertext, $i, $block_size);
if (strlen($block) > strlen($buffer['xor'])) {
$xor = $this->_encryptBlock($xor);
$buffer['xor'].= $xor;
}
$key = $this->_string_shift($buffer['xor'], $block_size);
$plaintext.= substr($ciphertext, $i, $block_size) ^ $key;
$plaintext.= $block ^ $key;
}
} else {
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
@ -1973,6 +1975,7 @@ class Crypt_Rijndael {
if (strlen($buffer["xor"])) {
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
$block = substr($text, $i, '.$block_size.');
if (strlen($block) > strlen($buffer["xor"])) {
$in = $xor;
'.$_encryptBlock.'
@ -1980,7 +1983,7 @@ class Crypt_Rijndael {
$buffer["xor"].= $xor;
}
$key = $self->_string_shift($buffer["xor"], '.$block_size.');
$ciphertext.= substr($text, $i, '.$block_size.') ^ $key;
$ciphertext.= $block ^ $key;
}
} else {
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') {
@ -2008,6 +2011,7 @@ class Crypt_Rijndael {
if (strlen($buffer["xor"])) {
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {
$block = substr($text, $i, '.$block_size.');
if (strlen($block) > strlen($buffer["xor"])) {
$in = $xor;
'.$_encryptBlock.'
@ -2015,7 +2019,7 @@ class Crypt_Rijndael {
$buffer["xor"].= $xor;
}
$key = $self->_string_shift($buffer["xor"], '.$block_size.');
$plaintext.= substr($text, $i, '.$block_size.') ^ $key;
$plaintext.= $block ^ $key;
}
} else {
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') {

View File

@ -669,6 +669,7 @@ class Crypt_TripleDES {
$xor = $this->encryptIV;
if (strlen($buffer['xor'])) {
for ($i = 0; $i < strlen($plaintext); $i+=8) {
$block = substr($plaintext, $i, 8);
if (strlen($block) > strlen($buffer['xor'])) {
$xor = $des[0]->_processBlock($xor, CRYPT_DES_ENCRYPT);
$xor = $des[1]->_processBlock($xor, CRYPT_DES_DECRYPT);
@ -676,7 +677,7 @@ class Crypt_TripleDES {
$buffer['xor'].= $xor;
}
$key = $this->_string_shift($buffer['xor'], 8);
$ciphertext.= substr($plaintext, $i, 8) ^ $key;
$ciphertext.= $block ^ $key;
}
} else {
for ($i = 0; $i < strlen($plaintext); $i+=8) {
@ -882,6 +883,7 @@ class Crypt_TripleDES {
$xor = $this->decryptIV;
if (strlen($buffer['xor'])) {
for ($i = 0; $i < strlen($ciphertext); $i+=8) {
$block = substr($ciphertext, $i, 8);
if (strlen($block) > strlen($buffer['xor'])) {
$xor = $des[0]->_processBlock($xor, CRYPT_DES_ENCRYPT);
$xor = $des[1]->_processBlock($xor, CRYPT_DES_DECRYPT);
@ -889,7 +891,7 @@ class Crypt_TripleDES {
$buffer['xor'].= $xor;
}
$key = $this->_string_shift($buffer['xor'], 8);
$plaintext.= substr($ciphertext, $i, 8) ^ $key;
$plaintext.= $block ^ $key;
}
} else {
for ($i = 0; $i < strlen($ciphertext); $i+=8) {