Crypt_*: CS and comments

- Crypt_* Some CS
- Crypt_Base: better comments for phpseclib developers
- Crypt_Base::_createInlineCryptFunction(): better namespace for
internal variables (all now prefixed with an underscore to avoid
conflicts)
This commit is contained in:
Hans-Jürgen Petrich 2013-06-26 11:50:40 +07:00
parent 76ea505af8
commit 89ea2da86b
6 changed files with 248 additions and 216 deletions

View File

@ -6,6 +6,26 @@
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* Internally for phpseclib developers:
* If you plan to add a new cipher class, please note following rules:
*
* - The new Crypt_* cipher class should extend Crypt_Base
*
* - Following methods are then required to be overridden/overloaded:
*
* - _encryptBlock()
*
* - _decryptBlock()
*
* - _setupKey()
*
* - All other methods are optional to be overridden/overloaded
*
* - Look at the source code of the current ciphers how they extend Crypt_Base
* and take one of them as a start up for the new cipher class.
*
* - Please read all the other comments/notes/hints here also for each class var/method
*
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy * LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
@ -30,7 +50,7 @@
* @author Hans-Juergen Petrich <petrich@tronic-media.com> * @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @copyright MMVII Jim Wigginton * @copyright MMVII Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License * @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 1.0 * @version 1.0.1
* @link http://phpseclib.sourceforge.net * @link http://phpseclib.sourceforge.net
*/ */
@ -1147,7 +1167,8 @@ class Crypt_Base {
*/ */
function _encryptBlock($in) function _encryptBlock($in)
{ {
echo basename(dirname(__FILE__)) . '/' . basename(__FILE__) . ':' . __LINE__ . ' ' . ( version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__ ) . '() must extend by ' . get_class($this); user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
die(1);
} }
/** /**
@ -1161,7 +1182,24 @@ class Crypt_Base {
*/ */
function _decryptBlock($in) function _decryptBlock($in)
{ {
echo basename(dirname(__FILE__)) . '/' . basename(__FILE__) . ':' . __LINE__ . ' ' . ( version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__ ) . '() must extend by ' . get_class($this); user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
die(1);
}
/**
* Setup the key (expansion)
*
* Only used if $engine == CRYPT_MODE_INTERNAL
*
* Note: Must extend by the child Crypt_* class
*
* @see Crypt_Base::_setup()
* @access private
*/
function _setupKey()
{
user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
die(1);
} }
/** /**
@ -1257,21 +1295,6 @@ class Crypt_Base {
} }
} }
/**
* Setup the key (expansion)
*
* Only used if $engine == CRYPT_MODE_INTERNAL
*
* Note: Must extend by the child Crypt_* class
*
* @see Crypt_Base::_setup()
* @access private
*/
function _setupKey()
{
echo basename(dirname(__FILE__)) . '/' . basename(__FILE__) . ':' . __LINE__ . ' ' . ( version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__ ) . '() must extend by ' . get_class($this);
}
/** /**
* Pads a string * Pads a string
* *
@ -1453,9 +1476,14 @@ class Crypt_Base {
* - memory-nice * - memory-nice
* - short (as good as possible) * - short (as good as possible)
* *
* Note: _setupInlineCrypt() is using _createInlineCryptFunction() to create the full callback function code. * Note: - _setupInlineCrypt() is using _createInlineCryptFunction() to create the full callback function code.
* - In case of using inline crypting, _setupInlineCrypt() must extend by the child Crypt_* class.
* - The following variable names are reversed:
* - $_* (all variable names prefixed with an underscore)
* - $self (object reference to it self. Do not use $this, but $self instead)
* - $in (the content of $in has to en/decrypt by the generated code)
* - The callback function should not use the 'return' statement, but en/decrypt'ing the content of $in only
* *
* Note: In case of using inline crypting, it must extend by the child Crypt_* class
* *
* @see Crypt_Base::_setup() * @see Crypt_Base::_setup()
* @see Crypt_Base::_createInlineCryptFunction() * @see Crypt_Base::_createInlineCryptFunction()
@ -1536,6 +1564,8 @@ class Crypt_Base {
* | // strlen($in) == $this->block_size | * | // strlen($in) == $this->block_size |
* | // here comes the cipher algorithm in action | * | // here comes the cipher algorithm in action |
* | // for encryption. | * | // for encryption. |
* | // $cipher_code['encrypt_block'] has to |
* | // encrypt the content of the $in variable |
* | | * | |
* | $plaintext .= $in; | * | $plaintext .= $in; |
* | } | * | } |
@ -1554,6 +1584,8 @@ class Crypt_Base {
* | // strlen($in) == $this->block_size | * | // strlen($in) == $this->block_size |
* | // here comes the cipher algorithm in action | * | // here comes the cipher algorithm in action |
* | // for decryption. | * | // for decryption. |
* | // $cipher_code['decrypt_block'] has to |
* | // decrypt the content of the $in variable |
* | $ciphertext .= $in; | * | $ciphertext .= $in; |
* | } | * | } |
* | return $ciphertext; | * | return $ciphertext; |
@ -1601,337 +1633,337 @@ class Crypt_Base {
switch ($this->mode) { switch ($this->mode) {
case CRYPT_MODE_ECB: case CRYPT_MODE_ECB:
$encrypt = $init_encrypt . ' $encrypt = $init_encrypt . '
$ciphertext = ""; $_ciphertext = "";
$text = $self->_pad($text); $_text = $self->_pad($_text);
$plaintext_len = strlen($text); $_plaintext_len = strlen($_text);
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') { for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
$in = substr($text, $i, '.$block_size.'); $in = substr($_text, $_i, '.$block_size.');
'.$encrypt_block.' '.$encrypt_block.'
$ciphertext.= $in; $_ciphertext.= $in;
} }
return $ciphertext; return $_ciphertext;
'; ';
$decrypt = $init_decrypt . ' $decrypt = $init_decrypt . '
$plaintext = ""; $_plaintext = "";
$text = str_pad($text, strlen($text) + ('.$block_size.' - strlen($text) % '.$block_size.') % '.$block_size.', chr(0)); $_text = str_pad($_text, strlen($_text) + ('.$block_size.' - strlen($_text) % '.$block_size.') % '.$block_size.', chr(0));
$ciphertext_len = strlen($text); $_ciphertext_len = strlen($_text);
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') { for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
$in = substr($text, $i, '.$block_size.'); $in = substr($_text, $_i, '.$block_size.');
'.$decrypt_block.' '.$decrypt_block.'
$plaintext.= $in; $_plaintext.= $in;
} }
return $self->_unpad($plaintext); return $self->_unpad($_plaintext);
'; ';
break; break;
case CRYPT_MODE_CTR: case CRYPT_MODE_CTR:
$encrypt = $init_encrypt . ' $encrypt = $init_encrypt . '
$ciphertext = ""; $_ciphertext = "";
$plaintext_len = strlen($text); $_plaintext_len = strlen($_text);
$xor = $self->encryptIV; $_xor = $self->encryptIV;
$buffer = &$self->enbuffer; $_buffer = &$self->enbuffer;
if (strlen($buffer["encrypted"])) { if (strlen($_buffer["encrypted"])) {
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') { for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
$block = substr($text, $i, '.$block_size.'); $_block = substr($_text, $_i, '.$block_size.');
if (strlen($block) > strlen($buffer["encrypted"])) { if (strlen($_block) > strlen($_buffer["encrypted"])) {
$in = $self->_generateXor($xor, '.$block_size.'); $in = $self->_generateXor($_xor, '.$block_size.');
'.$encrypt_block.' '.$encrypt_block.'
$buffer["encrypted"].= $in; $_buffer["encrypted"].= $in;
} }
$key = $self->_stringShift($buffer["encrypted"], '.$block_size.'); $_key = $self->_stringShift($_buffer["encrypted"], '.$block_size.');
$ciphertext.= $block ^ $key; $_ciphertext.= $_block ^ $_key;
} }
} else { } else {
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') { for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
$block = substr($text, $i, '.$block_size.'); $_block = substr($_text, $_i, '.$block_size.');
$in = $self->_generateXor($xor, '.$block_size.'); $in = $self->_generateXor($_xor, '.$block_size.');
'.$encrypt_block.' '.$encrypt_block.'
$key = $in; $_key = $in;
$ciphertext.= $block ^ $key; $_ciphertext.= $_block ^ $_key;
} }
} }
if ($self->continuousBuffer) { if ($self->continuousBuffer) {
$self->encryptIV = $xor; $self->encryptIV = $_xor;
if ($start = $plaintext_len % '.$block_size.') { if ($_start = $_plaintext_len % '.$block_size.') {
$buffer["encrypted"] = substr($key, $start) . $buffer["encrypted"]; $_buffer["encrypted"] = substr($_key, $_start) . $_buffer["encrypted"];
} }
} }
return $ciphertext; return $_ciphertext;
'; ';
$decrypt = $init_encrypt . ' $decrypt = $init_encrypt . '
$plaintext = ""; $_plaintext = "";
$ciphertext_len = strlen($text); $_ciphertext_len = strlen($_text);
$xor = $self->decryptIV; $_xor = $self->decryptIV;
$buffer = &$self->debuffer; $_buffer = &$self->debuffer;
if (strlen($buffer["ciphertext"])) { if (strlen($_buffer["ciphertext"])) {
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') { for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
$block = substr($text, $i, '.$block_size.'); $_block = substr($_text, $_i, '.$block_size.');
if (strlen($block) > strlen($buffer["ciphertext"])) { if (strlen($_block) > strlen($_buffer["ciphertext"])) {
$in = $self->_generateXor($xor, '.$block_size.'); $in = $self->_generateXor($_xor, '.$block_size.');
'.$encrypt_block.' '.$encrypt_block.'
$buffer["ciphertext"].= $in; $_buffer["ciphertext"].= $in;
} }
$key = $self->_stringShift($buffer["ciphertext"], '.$block_size.'); $_key = $self->_stringShift($_buffer["ciphertext"], '.$block_size.');
$plaintext.= $block ^ $key; $_plaintext.= $_block ^ $_key;
} }
} else { } else {
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') { for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
$block = substr($text, $i, '.$block_size.'); $_block = substr($_text, $_i, '.$block_size.');
$in = $self->_generateXor($xor, '.$block_size.'); $in = $self->_generateXor($_xor, '.$block_size.');
'.$encrypt_block.' '.$encrypt_block.'
$key = $in; $_key = $in;
$plaintext.= $block ^ $key; $_plaintext.= $_block ^ $_key;
} }
} }
if ($self->continuousBuffer) { if ($self->continuousBuffer) {
$self->decryptIV = $xor; $self->decryptIV = $_xor;
if ($start = $ciphertext_len % '.$block_size.') { if ($_start = $_ciphertext_len % '.$block_size.') {
$buffer["ciphertext"] = substr($key, $start) . $buffer["ciphertext"]; $_buffer["ciphertext"] = substr($_key, $_start) . $_buffer["ciphertext"];
} }
} }
return $plaintext; return $_plaintext;
'; ';
break; break;
case CRYPT_MODE_CFB: case CRYPT_MODE_CFB:
$encrypt = $init_encrypt . ' $encrypt = $init_encrypt . '
$ciphertext = ""; $_ciphertext = "";
$buffer = &$self->enbuffer; $_buffer = &$self->enbuffer;
if ($self->continuousBuffer) { if ($self->continuousBuffer) {
$iv = &$self->encryptIV; $_iv = &$self->encryptIV;
$pos = &$buffer["pos"]; $_pos = &$_buffer["pos"];
} else { } else {
$iv = $self->encryptIV; $_iv = $self->encryptIV;
$pos = 0; $_pos = 0;
} }
$len = strlen($text); $_len = strlen($_text);
$i = 0; $_i = 0;
if ($pos) { if ($_pos) {
$orig_pos = $pos; $_orig_pos = $_pos;
$max = '.$block_size.' - $pos; $_max = '.$block_size.' - $_pos;
if ($len >= $max) { if ($_len >= $_max) {
$i = $max; $_i = $_max;
$len-= $max; $_len-= $_max;
$pos = 0; $_pos = 0;
} else { } else {
$i = $len; $_i = $_len;
$pos+= $len; $_pos+= $_len;
$len = 0; $_len = 0;
} }
$ciphertext = substr($iv, $orig_pos) ^ $text; $_ciphertext = substr($_iv, $_orig_pos) ^ $_text;
$iv = substr_replace($iv, $ciphertext, $orig_pos, $i); $_iv = substr_replace($_iv, $_ciphertext, $_orig_pos, $_i);
} }
while ($len >= '.$block_size.') { while ($_len >= '.$block_size.') {
$in = $iv; $in = $_iv;
'.$encrypt_block.'; '.$encrypt_block.';
$iv = $in ^ substr($text, $i, '.$block_size.'); $_iv = $in ^ substr($_text, $_i, '.$block_size.');
$ciphertext.= $iv; $_ciphertext.= $_iv;
$len-= '.$block_size.'; $_len-= '.$block_size.';
$i+= '.$block_size.'; $_i+= '.$block_size.';
} }
if ($len) { if ($_len) {
$in = $iv; $in = $_iv;
'.$encrypt_block.' '.$encrypt_block.'
$iv = $in; $_iv = $in;
$block = $iv ^ substr($text, $i); $_block = $_iv ^ substr($_text, $_i);
$iv = substr_replace($iv, $block, 0, $len); $_iv = substr_replace($_iv, $_block, 0, $_len);
$ciphertext.= $block; $_ciphertext.= $_block;
$pos = $len; $_pos = $_len;
} }
return $ciphertext; return $_ciphertext;
'; ';
$decrypt = $init_encrypt . ' $decrypt = $init_encrypt . '
$plaintext = ""; $_plaintext = "";
$buffer = &$self->debuffer; $_buffer = &$self->debuffer;
if ($self->continuousBuffer) { if ($self->continuousBuffer) {
$iv = &$self->decryptIV; $_iv = &$self->decryptIV;
$pos = &$buffer["pos"]; $_pos = &$_buffer["pos"];
} else { } else {
$iv = $self->decryptIV; $_iv = $self->decryptIV;
$pos = 0; $_pos = 0;
} }
$len = strlen($text); $_len = strlen($_text);
$i = 0; $_i = 0;
if ($pos) { if ($_pos) {
$orig_pos = $pos; $_orig_pos = $_pos;
$max = '.$block_size.' - $pos; $_max = '.$block_size.' - $_pos;
if ($len >= $max) { if ($_len >= $_max) {
$i = $max; $_i = $_max;
$len-= $max; $_len-= $_max;
$pos = 0; $_pos = 0;
} else { } else {
$i = $len; $_i = $_len;
$pos+= $len; $_pos+= $_len;
$len = 0; $_len = 0;
} }
$plaintext = substr($iv, $orig_pos) ^ $text; $_plaintext = substr($_iv, $_orig_pos) ^ $_text;
$iv = substr_replace($iv, substr($text, 0, $i), $orig_pos, $i); $_iv = substr_replace($_iv, substr($_text, 0, $_i), $_orig_pos, $_i);
} }
while ($len >= '.$block_size.') { while ($_len >= '.$block_size.') {
$in = $iv; $in = $_iv;
'.$encrypt_block.' '.$encrypt_block.'
$iv = $in; $_iv = $in;
$cb = substr($text, $i, '.$block_size.'); $cb = substr($_text, $_i, '.$block_size.');
$plaintext.= $iv ^ $cb; $_plaintext.= $_iv ^ $cb;
$iv = $cb; $_iv = $cb;
$len-= '.$block_size.'; $_len-= '.$block_size.';
$i+= '.$block_size.'; $_i+= '.$block_size.';
} }
if ($len) { if ($_len) {
$in = $iv; $in = $_iv;
'.$encrypt_block.' '.$encrypt_block.'
$iv = $in; $_iv = $in;
$plaintext.= $iv ^ substr($text, $i); $_plaintext.= $_iv ^ substr($_text, $_i);
$iv = substr_replace($iv, substr($text, $i), 0, $len); $_iv = substr_replace($_iv, substr($_text, $_i), 0, $_len);
$pos = $len; $_pos = $_len;
} }
return $plaintext; return $_plaintext;
'; ';
break; break;
case CRYPT_MODE_OFB: case CRYPT_MODE_OFB:
$encrypt = $init_encrypt . ' $encrypt = $init_encrypt . '
$ciphertext = ""; $_ciphertext = "";
$plaintext_len = strlen($text); $_plaintext_len = strlen($_text);
$xor = $self->encryptIV; $_xor = $self->encryptIV;
$buffer = &$self->enbuffer; $_buffer = &$self->enbuffer;
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.'); $_block = substr($_text, $_i, '.$block_size.');
if (strlen($block) > strlen($buffer["xor"])) { if (strlen($_block) > strlen($_buffer["xor"])) {
$in = $xor; $in = $_xor;
'.$encrypt_block.' '.$encrypt_block.'
$xor = $in; $_xor = $in;
$buffer["xor"].= $xor; $_buffer["xor"].= $_xor;
} }
$key = $self->_stringShift($buffer["xor"], '.$block_size.'); $_key = $self->_stringShift($_buffer["xor"], '.$block_size.');
$ciphertext.= $block ^ $key; $_ciphertext.= $_block ^ $_key;
} }
} else { } else {
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') { for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
$in = $xor; $in = $_xor;
'.$encrypt_block.' '.$encrypt_block.'
$xor = $in; $_xor = $in;
$ciphertext.= substr($text, $i, '.$block_size.') ^ $xor; $_ciphertext.= substr($_text, $_i, '.$block_size.') ^ $_xor;
} }
$key = $xor; $_key = $_xor;
} }
if ($self->continuousBuffer) { if ($self->continuousBuffer) {
$self->encryptIV = $xor; $self->encryptIV = $_xor;
if ($start = $plaintext_len % '.$block_size.') { if ($_start = $_plaintext_len % '.$block_size.') {
$buffer["xor"] = substr($key, $start) . $buffer["xor"]; $_buffer["xor"] = substr($_key, $_start) . $_buffer["xor"];
} }
} }
return $ciphertext; return $_ciphertext;
'; ';
$decrypt = $init_encrypt . ' $decrypt = $init_encrypt . '
$plaintext = ""; $_plaintext = "";
$ciphertext_len = strlen($text); $_ciphertext_len = strlen($_text);
$xor = $self->decryptIV; $_xor = $self->decryptIV;
$buffer = &$self->debuffer; $_buffer = &$self->debuffer;
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.'); $_block = substr($_text, $_i, '.$block_size.');
if (strlen($block) > strlen($buffer["xor"])) { if (strlen($_block) > strlen($_buffer["xor"])) {
$in = $xor; $in = $_xor;
'.$encrypt_block.' '.$encrypt_block.'
$xor = $in; $_xor = $in;
$buffer["xor"].= $xor; $_buffer["xor"].= $_xor;
} }
$key = $self->_stringShift($buffer["xor"], '.$block_size.'); $_key = $self->_stringShift($_buffer["xor"], '.$block_size.');
$plaintext.= $block ^ $key; $_plaintext.= $_block ^ $_key;
} }
} else { } else {
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') { for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
$in = $xor; $in = $_xor;
'.$encrypt_block.' '.$encrypt_block.'
$xor = $in; $_xor = $in;
$plaintext.= substr($text, $i, '.$block_size.') ^ $xor; $_plaintext.= substr($_text, $_i, '.$block_size.') ^ $_xor;
} }
$key = $xor; $_key = $_xor;
} }
if ($self->continuousBuffer) { if ($self->continuousBuffer) {
$self->decryptIV = $xor; $self->decryptIV = $_xor;
if ($start = $ciphertext_len % '.$block_size.') { if ($_start = $_ciphertext_len % '.$block_size.') {
$buffer["xor"] = substr($key, $start) . $buffer["xor"]; $_buffer["xor"] = substr($_key, $_start) . $_buffer["xor"];
} }
} }
return $plaintext; return $_plaintext;
'; ';
break; break;
case CRYPT_MODE_STREAM: case CRYPT_MODE_STREAM:
$encrypt = $init_encrypt . ' $encrypt = $init_encrypt . '
$ciphertext = ""; $_ciphertext = "";
'.$encrypt_block.' '.$encrypt_block.'
return $ciphertext; return $_ciphertext;
'; ';
$decrypt = $init_decrypt . ' $decrypt = $init_decrypt . '
$plaintext = ""; $_plaintext = "";
'.$decrypt_block.' '.$decrypt_block.'
return $plaintext; return $_plaintext;
'; ';
break; break;
// case CRYPT_MODE_CBC: // case CRYPT_MODE_CBC:
default: default:
$encrypt = $init_encrypt . ' $encrypt = $init_encrypt . '
$ciphertext = ""; $_ciphertext = "";
$text = $self->_pad($text); $_text = $self->_pad($_text);
$plaintext_len = strlen($text); $_plaintext_len = strlen($_text);
$in = $self->encryptIV; $in = $self->encryptIV;
for ($i = 0; $i < $plaintext_len; $i+= '.$block_size.') { for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
$in = substr($text, $i, '.$block_size.') ^ $in; $in = substr($_text, $_i, '.$block_size.') ^ $in;
'.$encrypt_block.' '.$encrypt_block.'
$ciphertext.= $in; $_ciphertext.= $in;
} }
if ($self->continuousBuffer) { if ($self->continuousBuffer) {
$self->encryptIV = $in; $self->encryptIV = $in;
} }
return $ciphertext; return $_ciphertext;
'; ';
$decrypt = $init_decrypt . ' $decrypt = $init_decrypt . '
$plaintext = ""; $_plaintext = "";
$text = str_pad($text, strlen($text) + ('.$block_size.' - strlen($text) % '.$block_size.') % '.$block_size.', chr(0)); $_text = str_pad($_text, strlen($_text) + ('.$block_size.' - strlen($_text) % '.$block_size.') % '.$block_size.', chr(0));
$ciphertext_len = strlen($text); $_ciphertext_len = strlen($_text);
$iv = $self->decryptIV; $_iv = $self->decryptIV;
for ($i = 0; $i < $ciphertext_len; $i+= '.$block_size.') { for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
$in = $block = substr($text, $i, '.$block_size.'); $in = $_block = substr($_text, $_i, '.$block_size.');
'.$decrypt_block.' '.$decrypt_block.'
$plaintext.= $in ^ $iv; $_plaintext.= $in ^ $_iv;
$iv = $block; $_iv = $_block;
} }
if ($self->continuousBuffer) { if ($self->continuousBuffer) {
$self->decryptIV = $iv; $self->decryptIV = $_iv;
} }
return $self->_unpad($plaintext); return $self->_unpad($_plaintext);
'; ';
break; break;
} }
// Create the $inline function and return its name as string. Ready to run! // Create the $inline function and return its name as string. Ready to run!
return create_function('$action, &$self, $text', $init_crypt . 'if ($action == "encrypt") { ' . $encrypt . ' } else { ' . $decrypt . ' }'); return create_function('$_action, &$self, $_text', $init_crypt . 'if ($_action == "encrypt") { ' . $encrypt . ' } else { ' . $decrypt . ' }');
} }
/** /**

View File

@ -61,7 +61,7 @@
* Base cipher class * Base cipher class
*/ */
if (!class_exists('Crypt_Base')) { if (!class_exists('Crypt_Base')) {
require_once 'Base.php'; require_once('Base.php');
} }
/**#@+ /**#@+

View File

@ -65,7 +65,7 @@
* Base cipher class * Base cipher class
*/ */
if (!class_exists('Crypt_Base')) { if (!class_exists('Crypt_Base')) {
require_once 'Base.php'; require_once('Base.php');
} }
/**#@+ /**#@+

View File

@ -67,7 +67,7 @@
* Base cipher class * Base cipher class
*/ */
if (!class_exists('Crypt_Base')) { if (!class_exists('Crypt_Base')) {
require_once 'Base.php'; require_once('Base.php');
} }
/**#@+ /**#@+

View File

@ -77,7 +77,7 @@
* Base cipher class * Base cipher class
*/ */
if (!class_exists('Crypt_Base')) { if (!class_exists('Crypt_Base')) {
require_once 'Base.php'; require_once('Base.php');
} }
/**#@+ /**#@+

View File

@ -61,7 +61,7 @@
* Base cipher class * Base cipher class
*/ */
if (!class_exists('Crypt_Base')) { if (!class_exists('Crypt_Base')) {
require_once 'Base.php'; require_once('Base.php');
} }
/**#@+ /**#@+