Rijndael, TripleDES: $block not defined in these either

This commit is contained in:
terrafrost 2013-03-05 00:19:11 -06:00
parent 5f64ab67ab
commit 994c2c6c79
2 changed files with 12 additions and 6 deletions

View File

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

View File

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