From 2a1177b256361220c5666faa17d7afef34f39998 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 3 Dec 2016 14:39:11 -0600 Subject: [PATCH] SymmetricCiphers: add public / private / protected as appropriate --- phpseclib/Common/Functions/Strings.php | 19 +- phpseclib/Crypt/AES.php | 17 +- phpseclib/Crypt/Blowfish.php | 62 +-- phpseclib/Crypt/Common/SymmetricKey.php | 490 +++++++++++------------- phpseclib/Crypt/DES.php | 118 +++--- phpseclib/Crypt/RC2.php | 78 ++-- phpseclib/Crypt/RC4.php | 44 +-- phpseclib/Crypt/Rijndael.php | 99 ++--- phpseclib/Crypt/TripleDES.php | 69 ++-- phpseclib/Crypt/Twofish.php | 90 ++--- phpseclib/Net/SSH2.php | 8 +- 11 files changed, 552 insertions(+), 542 deletions(-) diff --git a/phpseclib/Common/Functions/Strings.php b/phpseclib/Common/Functions/Strings.php index e98c4a8e..133f2167 100644 --- a/phpseclib/Common/Functions/Strings.php +++ b/phpseclib/Common/Functions/Strings.php @@ -33,10 +33,27 @@ abstract class Strings * @access public * @return string */ - static function shift(&$string, $index = 1) + public static function shift(&$string, $index = 1) { $substr = substr($string, 0, $index); $string = substr($string, $index); return $substr; } + + /** + * String Pop + * + * Inspired by array_pop + * + * @param string $string + * @param int $index + * @access public + * @return string + */ + public static function pop(&$string, $index = 1) + { + $substr = substr($string, -$index); + $string = substr($string, 0, -$index); + return $substr; + } } diff --git a/phpseclib/Crypt/AES.php b/phpseclib/Crypt/AES.php index 8521eb5e..56186f8d 100644 --- a/phpseclib/Crypt/AES.php +++ b/phpseclib/Crypt/AES.php @@ -68,7 +68,7 @@ class AES extends Rijndael * @param int $length * @throws \BadMethodCallException anytime it's called */ - function setBlockLength($length) + public function setBlockLength($length) { throw new \BadMethodCallException('The block length cannot be set for AES.'); } @@ -83,7 +83,7 @@ class AES extends Rijndael * @param int $length * @throws \LengthException if the key length isn't supported */ - function setKeyLength($length) + public function setKeyLength($length) { switch ($length) { case 128: @@ -107,7 +107,7 @@ class AES extends Rijndael * @param string $key * @throws \LengthException if the key length isn't supported */ - function setKey($key) + public function setKey($key) { switch (strlen($key)) { case 16: @@ -120,4 +120,15 @@ class AES extends Rijndael parent::setKey($key); } + + /** + * Returns the class that defines the private methods + * + * @access private + * @return string + */ + protected function getClassContext() + { + return 'phpseclib\Crypt\Rijndael'; + } } diff --git a/phpseclib/Crypt/Blowfish.php b/phpseclib/Crypt/Blowfish.php index f72e5db5..9f8071ea 100644 --- a/phpseclib/Crypt/Blowfish.php +++ b/phpseclib/Crypt/Blowfish.php @@ -56,7 +56,7 @@ class Blowfish extends BlockCipher * @var int * @access private */ - var $block_size = 8; + protected $block_size = 8; /** * The mcrypt specific name of the cipher @@ -65,7 +65,7 @@ class Blowfish extends BlockCipher * @var string * @access private */ - var $cipher_name_mcrypt = 'blowfish'; + protected $cipher_name_mcrypt = 'blowfish'; /** * Optimizing value while CFB-encrypting @@ -74,7 +74,7 @@ class Blowfish extends BlockCipher * @var int * @access private */ - var $cfb_init_len = 500; + protected $cfb_init_len = 500; /** * The fixed subkeys boxes ($sbox0 - $sbox3) with 256 entries each @@ -84,7 +84,7 @@ class Blowfish extends BlockCipher * @access private * @var array */ - var $sbox0 = [ + private $sbox0 = [ 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, @@ -125,7 +125,7 @@ class Blowfish extends BlockCipher * @access private * @var array */ - var $sbox1 = [ + private $sbox1 = [ 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, @@ -166,7 +166,7 @@ class Blowfish extends BlockCipher * @access private * @var array */ - var $sbox2 = [ + private $sbox2 = [ 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, @@ -207,7 +207,7 @@ class Blowfish extends BlockCipher * @access private * @var array */ - var $sbox3 = [ + private $sbox3 = [ 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, @@ -248,7 +248,7 @@ class Blowfish extends BlockCipher * @var array * @access private */ - var $parray = [ + private $parray = [ 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b @@ -262,7 +262,7 @@ class Blowfish extends BlockCipher * @var array * @access private */ - var $bctx; + private $bctx; /** * Holds the last used key @@ -270,7 +270,7 @@ class Blowfish extends BlockCipher * @var array * @access private */ - var $kl; + private $kl; /** * The Key Length (in bytes) @@ -283,7 +283,7 @@ class Blowfish extends BlockCipher * derive this from $key_length or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu * of that, we'll just precompute it once. */ - var $key_length = 16; + protected $key_length = 16; /** * Default Constructor. @@ -292,7 +292,7 @@ class Blowfish extends BlockCipher * @access public * @throws \InvalidArgumentException if an invalid / unsupported mode is provided */ - function __construct($mode) + public function __construct($mode) { if ($mode == self::MODE_STREAM) { throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode'); @@ -309,7 +309,7 @@ class Blowfish extends BlockCipher * @access public * @param int $length */ - function setKeyLength($length) + public function setKeyLength($length) { if ($length < 32 || $length > 448) { throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys of sizes between 32 and 448 bits are supported'); @@ -330,14 +330,14 @@ class Blowfish extends BlockCipher * @access public * @return bool */ - function isValidEngine($engine) + public function isValidEngine($engine) { if ($engine == self::ENGINE_OPENSSL) { if ($this->key_length != 16) { return false; } $this->cipher_name_openssl_ecb = 'bf-ecb'; - $this->cipher_name_openssl = 'bf-' . $this->_openssl_translate_mode(); + $this->cipher_name_openssl = 'bf-' . $this->openssl_translate_mode(); } return parent::isValidEngine($engine); @@ -349,7 +349,7 @@ class Blowfish extends BlockCipher * @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() * @access private */ - function _setupKey() + protected function setupKey() { if (isset($this->kl['key']) && $this->key === $this->kl['key']) { // already expanded @@ -386,13 +386,13 @@ class Blowfish extends BlockCipher // encrypt P3 and P4 with the new P1 and P2, do it with all P-array and subkeys $data = "\0\0\0\0\0\0\0\0"; for ($i = 0; $i < 18; $i += 2) { - list($l, $r) = array_values(unpack('N*', $data = $this->_encryptBlock($data))); + list($l, $r) = array_values(unpack('N*', $data = $this->encryptBlock($data))); $this->bctx['p'][$i ] = $l; $this->bctx['p'][$i + 1] = $r; } for ($i = 0; $i < 4; ++$i) { for ($j = 0; $j < 256; $j += 2) { - list($l, $r) = array_values(unpack('N*', $data = $this->_encryptBlock($data))); + list($l, $r) = array_values(unpack('N*', $data = $this->encryptBlock($data))); $this->bctx['sb'][$i][$j ] = $l; $this->bctx['sb'][$i][$j + 1] = $r; } @@ -406,7 +406,7 @@ class Blowfish extends BlockCipher * @param string $in * @return string */ - function _encryptBlock($in) + protected function encryptBlock($in) { $p = $this->bctx["p"]; // extract($this->bctx["sb"], EXTR_PREFIX_ALL, "sb"); // slower @@ -442,7 +442,7 @@ class Blowfish extends BlockCipher * @param string $in * @return string */ - function _decryptBlock($in) + protected function decryptBlock($in) { $p = $this->bctx["p"]; $sb_0 = $this->bctx["sb"][0]; @@ -476,9 +476,9 @@ class Blowfish extends BlockCipher * @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt() * @access private */ - function _setupInlineCrypt() + protected function setupInlineCrypt() { - $lambda_functions =& self::_getLambdaFunctions(); + $lambda_functions =& self::getLambdaFunctions(); // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function. // (Currently, for Blowfish, one generated $lambda_function cost on php5.5@32bit ~100kb unfreeable mem and ~180kb on php5.5@64bit) @@ -488,7 +488,7 @@ class Blowfish extends BlockCipher // Generation of a unique hash for our generated code $code_hash = "Crypt_Blowfish, {$this->mode}"; if ($gen_hi_opt_code) { - $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); + $code_hash = str_pad($code_hash, 32) . $this->hashInlineCryptFunction($this->key); } if (!isset($lambda_functions[$code_hash])) { @@ -498,10 +498,10 @@ class Blowfish extends BlockCipher $init_crypt = ' static $sb_0, $sb_1, $sb_2, $sb_3; if (!$sb_0) { - $sb_0 = $self->bctx["sb"][0]; - $sb_1 = $self->bctx["sb"][1]; - $sb_2 = $self->bctx["sb"][2]; - $sb_3 = $self->bctx["sb"][3]; + $sb_0 = $this->bctx["sb"][0]; + $sb_1 = $this->bctx["sb"][1]; + $sb_2 = $this->bctx["sb"][2]; + $sb_3 = $this->bctx["sb"][3]; } '; break; @@ -511,8 +511,8 @@ class Blowfish extends BlockCipher $p[] = '$p_' . $i; } $init_crypt = ' - list($sb_0, $sb_1, $sb_2, $sb_3) = $self->bctx["sb"]; - list(' . implode(',', $p) . ') = $self->bctx["p"]; + list($sb_0, $sb_1, $sb_2, $sb_3) = $this->bctx["sb"]; + list(' . implode(',', $p) . ') = $this->bctx["p"]; '; } @@ -575,7 +575,7 @@ class Blowfish extends BlockCipher ); '; - $lambda_functions[$code_hash] = $this->_createInlineCryptFunction( + $lambda_functions[$code_hash] = $this->createInlineCryptFunction( [ 'init_crypt' => $init_crypt, 'init_encrypt' => '', @@ -585,6 +585,6 @@ class Blowfish extends BlockCipher ] ); } - $this->inline_crypt = $lambda_functions[$code_hash]; + $this->inline_crypt = \Closure::bind($lambda_functions[$code_hash], $this, $this->getClassContext()); } } diff --git a/phpseclib/Crypt/Common/SymmetricKey.php b/phpseclib/Crypt/Common/SymmetricKey.php index da718880..c7c32cbc 100644 --- a/phpseclib/Crypt/Common/SymmetricKey.php +++ b/phpseclib/Crypt/Common/SymmetricKey.php @@ -12,11 +12,11 @@ * * - Following methods are then required to be overridden/overloaded: * - * - _encryptBlock() + * - encryptBlock() * - * - _decryptBlock() + * - decryptBlock() * - * - _setupKey() + * - setupKey() * * - All other methods are optional to be overridden/overloaded * @@ -99,7 +99,7 @@ abstract class SymmetricKey * @var bool * @access private */ - static $WHIRLPOOL_AVAILABLE; + private static $WHIRLPOOL_AVAILABLE; /**#@+ * @access private @@ -126,7 +126,7 @@ abstract class SymmetricKey * @var int * @access private */ - var $mode; + protected $mode; /** * The Block Length of the block cipher @@ -134,7 +134,7 @@ abstract class SymmetricKey * @var int * @access private */ - var $block_size = 16; + protected $block_size = 16; /** * The Key @@ -143,7 +143,7 @@ abstract class SymmetricKey * @var string * @access private */ - var $key = false; + protected $key = false; /** * The Initialization Vector @@ -152,27 +152,27 @@ abstract class SymmetricKey * @var string * @access private */ - var $iv = false; + private $iv = false; /** * A "sliding" Initialization Vector * * @see self::enableContinuousBuffer() - * @see self::_clearBuffers() + * @see self::clearBuffers() * @var string * @access private */ - var $encryptIV; + protected $encryptIV; /** * A "sliding" Initialization Vector * * @see self::enableContinuousBuffer() - * @see self::_clearBuffers() + * @see self::clearBuffers() * @var string * @access private */ - var $decryptIV; + protected $decryptIV; /** * Continuous Buffer status @@ -181,27 +181,27 @@ abstract class SymmetricKey * @var bool * @access private */ - var $continuousBuffer = false; + protected $continuousBuffer = false; /** * Encryption buffer for CTR, OFB and CFB modes * * @see self::encrypt() - * @see self::_clearBuffers() + * @see self::clearBuffers() * @var array * @access private */ - var $enbuffer; + private $enbuffer; /** * Decryption buffer for CTR, OFB and CFB modes * * @see self::decrypt() - * @see self::_clearBuffers() + * @see self::clearBuffers() * @var array * @access private */ - var $debuffer; + private $debuffer; /** * mcrypt resource for encryption @@ -213,7 +213,7 @@ abstract class SymmetricKey * @var resource * @access private */ - var $enmcrypt; + private $enmcrypt; /** * mcrypt resource for decryption @@ -225,7 +225,7 @@ abstract class SymmetricKey * @var resource * @access private */ - var $demcrypt; + private $demcrypt; /** * Does the enmcrypt resource need to be (re)initialized? @@ -235,7 +235,7 @@ abstract class SymmetricKey * @var bool * @access private */ - var $enchanged = true; + private $enchanged = true; /** * Does the demcrypt resource need to be (re)initialized? @@ -245,7 +245,7 @@ abstract class SymmetricKey * @var bool * @access private */ - var $dechanged = true; + private $dechanged = true; /** * mcrypt resource for CFB mode @@ -260,11 +260,11 @@ abstract class SymmetricKey * @link http://phpseclib.sourceforge.net/cfb-demo.phps * @see self::encrypt() * @see self::decrypt() - * @see self::_setupMcrypt() + * @see self::setupMcrypt() * @var resource * @access private */ - var $ecb; + private $ecb; /** * Optimizing value while CFB-encrypting @@ -286,7 +286,7 @@ abstract class SymmetricKey * @var int * @access private */ - var $cfb_init_len = 600; + protected $cfb_init_len = 600; /** * Does internal cipher state need to be (re)initialized? @@ -297,7 +297,7 @@ abstract class SymmetricKey * @var bool * @access private */ - var $changed = true; + protected $changed = true; /** * Padding status @@ -306,7 +306,7 @@ abstract class SymmetricKey * @var bool * @access private */ - var $padding = true; + private $padding = true; /** * Is the mode one that is paddable? @@ -315,7 +315,7 @@ abstract class SymmetricKey * @var bool * @access private */ - var $paddable = false; + private $paddable = false; /** * Holds which crypt engine internaly should be use, @@ -326,23 +326,23 @@ abstract class SymmetricKey * - self::ENGINE_MCRYPT (fast, php-extension: mcrypt, extension_loaded('mcrypt') required) * - self::ENGINE_INTERNAL (slower, pure php-engine, no php-extension required) * - * @see self::_setEngine() + * @see self::setEngine() * @see self::encrypt() * @see self::decrypt() * @var int * @access private */ - var $engine; + protected $engine; /** * Holds the preferred crypt engine * - * @see self::_setEngine() + * @see self::setEngine() * @see self::setPreferredEngine() * @var int * @access private */ - var $preferredEngine; + private $preferredEngine; /** * The mcrypt specific name of the cipher @@ -351,11 +351,11 @@ abstract class SymmetricKey * * @link http://www.php.net/mcrypt_module_open * @link http://www.php.net/mcrypt_list_algorithms - * @see self::_setupMcrypt() + * @see self::setupMcrypt() * @var string * @access private */ - var $cipher_name_mcrypt; + protected $cipher_name_mcrypt; /** * The openssl specific name of the cipher @@ -366,7 +366,7 @@ abstract class SymmetricKey * @var string * @access private */ - var $cipher_name_openssl; + protected $cipher_name_openssl; /** * The openssl specific name of the cipher in ECB mode @@ -378,7 +378,7 @@ abstract class SymmetricKey * @var string * @access private */ - var $cipher_name_openssl_ecb; + protected $cipher_name_openssl_ecb; /** * The default salt used by setPassword() @@ -387,7 +387,7 @@ abstract class SymmetricKey * @var string * @access private */ - var $password_default_salt = 'phpseclib/salt'; + protected $password_default_salt = 'phpseclib/salt'; /** * The name of the performance-optimized callback function @@ -397,12 +397,12 @@ abstract class SymmetricKey * * @see self::encrypt() * @see self::decrypt() - * @see self::_setupInlineCrypt() + * @see self::setupInlineCrypt() * @see self::$use_inline_crypt * @var Callback * @access private */ - var $inline_crypt; + protected $inline_crypt; /** * Holds whether performance-optimized $inline_crypt() can/should be used. @@ -413,34 +413,25 @@ abstract class SymmetricKey * @var mixed * @access private */ - var $use_inline_crypt; + protected $use_inline_crypt; /** * If OpenSSL can be used in ECB but not in CTR we can emulate CTR * - * @see self::_openssl_ctr_process() + * @see self::openssl_ctr_process() * @var bool * @access private */ - var $openssl_emulate_ctr = false; - - /** - * Determines what options are passed to openssl_encrypt/decrypt - * - * @see self::isValidEngine() - * @var mixed - * @access private - */ - var $openssl_options; + private $openssl_emulate_ctr = false; /** * Don't truncate / null pad key * - * @see self::_clearBuffers() + * @see self::clearBuffers() * @var bool * @access private */ - var $skip_key_adjustment = false; + private $skip_key_adjustment = false; /** * Has the key length explicitly been set or should it be derived from the key, itself? @@ -449,7 +440,7 @@ abstract class SymmetricKey * @var bool * @access private */ - var $explicit_key_length = false; + protected $explicit_key_length = false; /** * Default Constructor. @@ -470,7 +461,7 @@ abstract class SymmetricKey * @access public * @throws \InvalidArgumentException if an invalid / unsupported mode is provided */ - function __construct($mode) + public function __construct($mode) { // $mode dependent settings switch ($mode) { @@ -491,7 +482,7 @@ abstract class SymmetricKey $this->mode = $mode; // Determining whether inline crypting can be used by the cipher - if ($this->use_inline_crypt !== false && function_exists('create_function')) { + if ($this->use_inline_crypt !== false) { $this->use_inline_crypt = true; } } @@ -507,7 +498,7 @@ abstract class SymmetricKey * @throws \InvalidArgumentException if an IV is provided when one shouldn't be * @internal Can be overwritten by a sub class, but does not have to be */ - function setIV($iv) + public function setIV($iv) { if ($this->mode == self::MODE_ECB) { throw new \InvalidArgumentException('This mode does not require an IV.'); @@ -531,7 +522,7 @@ abstract class SymmetricKey * @access public * @return bool */ - function usesIV() + public function usesIV() { return true; } @@ -542,7 +533,7 @@ abstract class SymmetricKey * @access public * @return int */ - function getKeyLength() + public function getKeyLength() { return $this->key_length << 3; } @@ -553,11 +544,22 @@ abstract class SymmetricKey * @access public * @return int */ - function getBlockLength() + public function getBlockLength() { return $this->block_size << 3; } + /** + * Returns the current block length in bytes + * + * @access public + * @return int + */ + public function getBlockLengthInBytes() + { + return $this->block_size; + } + /** * Sets the key length. * @@ -566,7 +568,7 @@ abstract class SymmetricKey * @access public * @param int $length */ - function setKeyLength($length) + public function setKeyLength($length) { $this->explicit_key_length = $length >> 3; @@ -590,7 +592,7 @@ abstract class SymmetricKey * @param string $key * @internal Could, but not must, extend by the child Crypt_* class */ - function setKey($key) + public function setKey($key) { if ($this->explicit_key_length !== false && strlen($key) != $this->explicit_key_length) { throw new \LengthException('Key length has already been set to ' . $this->explicit_key_length . ' bytes and this key is ' . strlen($key) . ' bytes'); @@ -599,7 +601,7 @@ abstract class SymmetricKey $this->key = $key; $this->key_length = strlen($key); $this->changed = true; - $this->_setEngine(); + $this->setEngine(); } /** @@ -619,7 +621,7 @@ abstract class SymmetricKey * @access public * @internal Could, but not must, extend by the child Crypt_* class */ - function setPassword($password, $method = 'pbkdf2') + public function setPassword($password, $method = 'pbkdf2') { $key = ''; @@ -700,9 +702,9 @@ abstract class SymmetricKey $i = $s . $p; - $this->setKey(self::_pkcs12helper($dkLen, $hashObj, $i, $d1, $count)); + $this->setKey(self::pkcs12helper($dkLen, $hashObj, $i, $d1, $count)); if ($this->usesIV()) { - $this->setIV(self::_pkcs12helper($this->block_size, $hashObj, $i, $d2, $count)); + $this->setIV(self::pkcs12helper($this->block_size, $hashObj, $i, $d2, $count)); } return true; @@ -766,7 +768,7 @@ abstract class SymmetricKey * @param int $count * @return string $a */ - static function _pkcs12helper($n, $hashObj, $i, $d, $count) + private static function pkcs12helper($n, $hashObj, $i, $d, $count) { static $one; if (!isset($one)) { @@ -824,34 +826,30 @@ abstract class SymmetricKey * @return string $ciphertext * @internal Could, but not must, extend by the child Crypt_* class */ - function encrypt($plaintext) + public function encrypt($plaintext) { if ($this->paddable) { - $plaintext = $this->_pad($plaintext); + $plaintext = $this->pad($plaintext); } if ($this->engine === self::ENGINE_OPENSSL) { if ($this->changed) { - $this->_clearBuffers(); + $this->clearBuffers(); $this->changed = false; } switch ($this->mode) { case self::MODE_STREAM: - return openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options); + return openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING); case self::MODE_ECB: - $result = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options); - return !defined('OPENSSL_RAW_DATA') ? substr($result, 0, -$this->block_size) : $result; + return openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING); case self::MODE_CBC: - $result = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $this->encryptIV); - if (!defined('OPENSSL_RAW_DATA')) { - $result = substr($result, 0, -$this->block_size); - } + $result = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $this->encryptIV); if ($this->continuousBuffer) { $this->encryptIV = substr($result, -$this->block_size); } return $result; case self::MODE_CTR: - return $this->_openssl_ctr_process($plaintext, $this->encryptIV, $this->enbuffer); + return $this->openssl_ctr_process($plaintext, $this->encryptIV, $this->enbuffer); case self::MODE_CFB: // cfb loosely routines inspired by openssl's: // {@link http://cvs.openssl.org/fileview?f=openssl/crypto/modes/cfb128.c&v=1.3.2.2.2.1} @@ -886,8 +884,8 @@ abstract class SymmetricKey $overflow = $len % $this->block_size; if ($overflow) { - $ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); - $iv = $this->_string_pop($ciphertext, $this->block_size); + $ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv); + $iv = Strings::pop($ciphertext, $this->block_size); $size = $len - $overflow; $block = $iv ^ substr($plaintext, -$overflow); @@ -895,23 +893,23 @@ abstract class SymmetricKey $ciphertext.= $block; $pos = $overflow; } elseif ($len) { - $ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); + $ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv); $iv = substr($ciphertext, -$this->block_size); } return $ciphertext; case self::MODE_OFB: - return $this->_openssl_ofb_process($plaintext, $this->encryptIV, $this->enbuffer); + return $this->openssl_ofb_process($plaintext, $this->encryptIV, $this->enbuffer); } } if ($this->engine === self::ENGINE_MCRYPT) { if ($this->changed) { - $this->_setupMcrypt(); + $this->setupMcrypt(); $this->changed = false; } if ($this->enchanged) { - @mcrypt_generic_init($this->enmcrypt, $this->key, $this->_getIV($this->encryptIV)); + @mcrypt_generic_init($this->enmcrypt, $this->key, $this->getIV($this->encryptIV)); $this->enchanged = false; } @@ -974,19 +972,19 @@ abstract class SymmetricKey $ciphertext = @mcrypt_generic($this->enmcrypt, $plaintext); if (!$this->continuousBuffer) { - @mcrypt_generic_init($this->enmcrypt, $this->key, $this->_getIV($this->encryptIV)); + @mcrypt_generic_init($this->enmcrypt, $this->key, $this->getIV($this->encryptIV)); } return $ciphertext; } if ($this->changed) { - $this->_setup(); + $this->setup(); $this->changed = false; } if ($this->use_inline_crypt) { $inline = $this->inline_crypt; - return $inline('encrypt', $this, $plaintext); + return $inline('encrypt', $plaintext); } $buffer = &$this->enbuffer; @@ -995,14 +993,14 @@ abstract class SymmetricKey switch ($this->mode) { case self::MODE_ECB: for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { - $ciphertext.= $this->_encryptBlock(substr($plaintext, $i, $block_size)); + $ciphertext.= $this->encryptBlock(substr($plaintext, $i, $block_size)); } break; case self::MODE_CBC: $xor = $this->encryptIV; for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { $block = substr($plaintext, $i, $block_size); - $block = $this->_encryptBlock($block ^ $xor); + $block = $this->encryptBlock($block ^ $xor); $xor = $block; $ciphertext.= $block; } @@ -1016,17 +1014,17 @@ abstract class SymmetricKey for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { $block = substr($plaintext, $i, $block_size); if (strlen($block) > strlen($buffer['ciphertext'])) { - $buffer['ciphertext'].= $this->_encryptBlock($xor); + $buffer['ciphertext'].= $this->encryptBlock($xor); } - $this->_increment_str($xor); + $this->increment_str($xor); $key = Strings::shift($buffer['ciphertext'], $block_size); $ciphertext.= $block ^ $key; } } else { for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { $block = substr($plaintext, $i, $block_size); - $key = $this->_encryptBlock($xor); - $this->_increment_str($xor); + $key = $this->encryptBlock($xor); + $this->increment_str($xor); $ciphertext.= $block ^ $key; } } @@ -1066,13 +1064,13 @@ abstract class SymmetricKey $iv = substr_replace($iv, $ciphertext, $orig_pos, $i); } while ($len >= $block_size) { - $iv = $this->_encryptBlock($iv) ^ substr($plaintext, $i, $block_size); + $iv = $this->encryptBlock($iv) ^ substr($plaintext, $i, $block_size); $ciphertext.= $iv; $len-= $block_size; $i+= $block_size; } if ($len) { - $iv = $this->_encryptBlock($iv); + $iv = $this->encryptBlock($iv); $block = $iv ^ substr($plaintext, $i); $iv = substr_replace($iv, $block, 0, $len); $ciphertext.= $block; @@ -1085,7 +1083,7 @@ abstract class SymmetricKey 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); + $xor = $this->encryptBlock($xor); $buffer['xor'].= $xor; } $key = Strings::shift($buffer['xor'], $block_size); @@ -1093,7 +1091,7 @@ abstract class SymmetricKey } } else { for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { - $xor = $this->_encryptBlock($xor); + $xor = $this->encryptBlock($xor); $ciphertext.= substr($plaintext, $i, $block_size) ^ $xor; } $key = $xor; @@ -1106,7 +1104,7 @@ abstract class SymmetricKey } break; case self::MODE_STREAM: - $ciphertext = $this->_encryptBlock($plaintext); + $ciphertext = $this->encryptBlock($plaintext); break; } @@ -1126,7 +1124,7 @@ abstract class SymmetricKey * @throws \LengthException if we're inside a block cipher and the ciphertext length is not a multiple of the block size * @internal Could, but not must, extend by the child Crypt_* class */ - function decrypt($ciphertext) + public function decrypt($ciphertext) { if ($this->paddable && strlen($ciphertext) % $this->block_size) { throw new \LengthException('The ciphertext length (' . strlen($ciphertext) . ') needs to be a multiple of the block size (' . $this->block_size . ')'); @@ -1134,34 +1132,25 @@ abstract class SymmetricKey if ($this->engine === self::ENGINE_OPENSSL) { if ($this->changed) { - $this->_clearBuffers(); + $this->clearBuffers(); $this->changed = false; } switch ($this->mode) { case self::MODE_STREAM: - $plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options); + $plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING); break; case self::MODE_ECB: - if (!defined('OPENSSL_RAW_DATA')) { - $ciphertext.= openssl_encrypt('', $this->cipher_name_openssl_ecb, $this->key, true); - } - $plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options); + $plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING); break; case self::MODE_CBC: - if (!defined('OPENSSL_RAW_DATA')) { - $padding = str_repeat(chr($this->block_size), $this->block_size) ^ substr($ciphertext, -$this->block_size); - $ciphertext.= substr(openssl_encrypt($padding, $this->cipher_name_openssl_ecb, $this->key, true), 0, $this->block_size); - $offset = 2 * $this->block_size; - } else { - $offset = $this->block_size; - } - $plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $this->decryptIV); + $offset = $this->block_size; + $plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $this->decryptIV); if ($this->continuousBuffer) { $this->decryptIV = substr($ciphertext, -$offset, $this->block_size); } break; case self::MODE_CTR: - $plaintext = $this->_openssl_ctr_process($ciphertext, $this->decryptIV, $this->debuffer); + $plaintext = $this->openssl_ctr_process($ciphertext, $this->decryptIV, $this->debuffer); break; case self::MODE_CFB: // cfb loosely routines inspired by openssl's: @@ -1195,34 +1184,34 @@ abstract class SymmetricKey } $overflow = $len % $this->block_size; if ($overflow) { - $plaintext.= openssl_decrypt(substr($ciphertext, 0, -$overflow), $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); + $plaintext.= openssl_decrypt(substr($ciphertext, 0, -$overflow), $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv); if ($len - $overflow) { $iv = substr($ciphertext, -$overflow - $this->block_size, -$overflow); } - $iv = openssl_encrypt(str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); + $iv = openssl_encrypt(str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv); $plaintext.= $iv ^ substr($ciphertext, -$overflow); $iv = substr_replace($iv, substr($ciphertext, -$overflow), 0, $overflow); $pos = $overflow; } elseif ($len) { - $plaintext.= openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); + $plaintext.= openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv); $iv = substr($ciphertext, -$this->block_size); } break; case self::MODE_OFB: - $plaintext = $this->_openssl_ofb_process($ciphertext, $this->decryptIV, $this->debuffer); + $plaintext = $this->openssl_ofb_process($ciphertext, $this->decryptIV, $this->debuffer); } - return $this->paddable ? $this->_unpad($plaintext) : $plaintext; + return $this->paddable ? $this->unpad($plaintext) : $plaintext; } if ($this->engine === self::ENGINE_MCRYPT) { $block_size = $this->block_size; if ($this->changed) { - $this->_setupMcrypt(); + $this->setupMcrypt(); $this->changed = false; } if ($this->dechanged) { - @mcrypt_generic_init($this->demcrypt, $this->key, $this->_getIV($this->decryptIV)); + @mcrypt_generic_init($this->demcrypt, $this->key, $this->getIV($this->decryptIV)); $this->dechanged = false; } @@ -1267,19 +1256,19 @@ abstract class SymmetricKey $plaintext = @mdecrypt_generic($this->demcrypt, $ciphertext); if (!$this->continuousBuffer) { - @mcrypt_generic_init($this->demcrypt, $this->key, $this->_getIV($this->decryptIV)); + @mcrypt_generic_init($this->demcrypt, $this->key, $this->getIV($this->decryptIV)); } - return $this->paddable ? $this->_unpad($plaintext) : $plaintext; + return $this->paddable ? $this->unpad($plaintext) : $plaintext; } if ($this->changed) { - $this->_setup(); + $this->setup(); $this->changed = false; } if ($this->use_inline_crypt) { $inline = $this->inline_crypt; - return $inline('decrypt', $this, $ciphertext); + return $inline('decrypt', $ciphertext); } $block_size = $this->block_size; @@ -1289,14 +1278,14 @@ abstract class SymmetricKey switch ($this->mode) { case self::MODE_ECB: for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) { - $plaintext.= $this->_decryptBlock(substr($ciphertext, $i, $block_size)); + $plaintext.= $this->decryptBlock(substr($ciphertext, $i, $block_size)); } break; case self::MODE_CBC: $xor = $this->decryptIV; for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) { $block = substr($ciphertext, $i, $block_size); - $plaintext.= $this->_decryptBlock($block) ^ $xor; + $plaintext.= $this->decryptBlock($block) ^ $xor; $xor = $block; } if ($this->continuousBuffer) { @@ -1309,17 +1298,17 @@ abstract class SymmetricKey for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) { $block = substr($ciphertext, $i, $block_size); if (strlen($block) > strlen($buffer['ciphertext'])) { - $buffer['ciphertext'].= $this->_encryptBlock($xor); - $this->_increment_str($xor); + $buffer['ciphertext'].= $this->encryptBlock($xor); } + $this->increment_str($xor); $key = Strings::shift($buffer['ciphertext'], $block_size); $plaintext.= $block ^ $key; } } else { for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) { $block = substr($ciphertext, $i, $block_size); - $key = $this->_encryptBlock($xor); - $this->_increment_str($xor); + $key = $this->encryptBlock($xor); + $this->increment_str($xor); $plaintext.= $block ^ $key; } } @@ -1357,7 +1346,7 @@ abstract class SymmetricKey $iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i); } while ($len >= $block_size) { - $iv = $this->_encryptBlock($iv); + $iv = $this->encryptBlock($iv); $cb = substr($ciphertext, $i, $block_size); $plaintext.= $iv ^ $cb; $iv = $cb; @@ -1365,7 +1354,7 @@ abstract class SymmetricKey $i+= $block_size; } if ($len) { - $iv = $this->_encryptBlock($iv); + $iv = $this->encryptBlock($iv); $plaintext.= $iv ^ substr($ciphertext, $i); $iv = substr_replace($iv, substr($ciphertext, $i), 0, $len); $pos = $len; @@ -1377,7 +1366,7 @@ abstract class SymmetricKey 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); + $xor = $this->encryptBlock($xor); $buffer['xor'].= $xor; } $key = Strings::shift($buffer['xor'], $block_size); @@ -1385,7 +1374,7 @@ abstract class SymmetricKey } } else { for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) { - $xor = $this->_encryptBlock($xor); + $xor = $this->encryptBlock($xor); $plaintext.= substr($ciphertext, $i, $block_size) ^ $xor; } $key = $xor; @@ -1398,10 +1387,10 @@ abstract class SymmetricKey } break; case self::MODE_STREAM: - $plaintext = $this->_decryptBlock($ciphertext); + $plaintext = $this->decryptBlock($ciphertext); break; } - return $this->paddable ? $this->_unpad($plaintext) : $plaintext; + return $this->paddable ? $this->unpad($plaintext) : $plaintext; } /** @@ -1415,7 +1404,7 @@ abstract class SymmetricKey * @return string * @access private */ - function _getIV($iv) + public function getIV($iv) { return $this->mode == self::MODE_ECB ? str_repeat("\0", $this->block_size) : $iv; } @@ -1436,7 +1425,7 @@ abstract class SymmetricKey * @return string * @access private */ - function _openssl_ctr_process($plaintext, &$encryptIV, &$buffer) + private function openssl_ctr_process($plaintext, &$encryptIV, &$buffer) { $ciphertext = ''; @@ -1449,20 +1438,17 @@ abstract class SymmetricKey for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { $block = substr($plaintext, $i, $block_size); if (strlen($block) > strlen($buffer['ciphertext'])) { - $result = openssl_encrypt($xor, $this->cipher_name_openssl_ecb, $key, $this->openssl_options); - $result = !defined('OPENSSL_RAW_DATA') ? substr($result, 0, -$this->block_size) : $result; - $buffer['ciphertext'].= $result; + $buffer['ciphertext'].= openssl_encrypt($xor, $this->cipher_name_openssl_ecb, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING); } - $this->_increment_str($xor); + $this->increment_str($xor); $otp = Strings::shift($buffer['ciphertext'], $block_size); $ciphertext.= $block ^ $otp; } } else { for ($i = 0; $i < strlen($plaintext); $i+=$block_size) { $block = substr($plaintext, $i, $block_size); - $otp = openssl_encrypt($xor, $this->cipher_name_openssl_ecb, $key, $this->openssl_options); - $otp = !defined('OPENSSL_RAW_DATA') ? substr($otp, 0, -$this->block_size) : $otp; - $this->_increment_str($xor); + $otp = openssl_encrypt($xor, $this->cipher_name_openssl_ecb, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING); + $this->increment_str($xor); $ciphertext.= $block ^ $otp; } } @@ -1487,28 +1473,25 @@ abstract class SymmetricKey $overflow = strlen($plaintext) % $block_size; if ($overflow) { - $plaintext2 = $this->_string_pop($plaintext, $overflow); // ie. trim $plaintext to a multiple of $block_size and put rest of $plaintext in $plaintext2 - $encrypted = openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV); - $temp = $this->_string_pop($encrypted, $block_size); + $plaintext2 = Strings::pop($plaintext, $overflow); // ie. trim $plaintext to a multiple of $block_size and put rest of $plaintext in $plaintext2 + $encrypted = openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $encryptIV); + $temp = Strings::pop($encrypted, $block_size); $ciphertext.= $encrypted . ($plaintext2 ^ $temp); if ($this->continuousBuffer) { $buffer['ciphertext'] = substr($temp, $overflow); $encryptIV = $temp; } } elseif (!strlen($buffer['ciphertext'])) { - $ciphertext.= openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV); - $temp = $this->_string_pop($ciphertext, $block_size); + $ciphertext.= openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $encryptIV); + $temp = Strings::pop($ciphertext, $block_size); if ($this->continuousBuffer) { $encryptIV = $temp; } } if ($this->continuousBuffer) { - if (!defined('OPENSSL_RAW_DATA')) { - $encryptIV.= openssl_encrypt('', $this->cipher_name_openssl_ecb, $key, $this->openssl_options); - } - $encryptIV = openssl_decrypt($encryptIV, $this->cipher_name_openssl_ecb, $key, $this->openssl_options); + $encryptIV = openssl_decrypt($encryptIV, $this->cipher_name_openssl_ecb, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING); if ($overflow) { - $this->_increment_str($encryptIV); + $this->increment_str($encryptIV); } } @@ -1530,7 +1513,7 @@ abstract class SymmetricKey * @return string * @access private */ - function _openssl_ofb_process($plaintext, &$encryptIV, &$buffer) + private function openssl_ofb_process($plaintext, &$encryptIV, &$buffer) { if (strlen($buffer['xor'])) { $ciphertext = $plaintext ^ $buffer['xor']; @@ -1548,8 +1531,8 @@ abstract class SymmetricKey if (strlen($plaintext)) { if ($overflow) { - $ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV); - $xor = $this->_string_pop($ciphertext, $block_size); + $ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $encryptIV); + $xor = Strings::pop($ciphertext, $block_size); if ($this->continuousBuffer) { $encryptIV = $xor; } @@ -1558,7 +1541,7 @@ abstract class SymmetricKey $buffer['xor'] = $xor; } } else { - $ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV); + $ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $encryptIV); if ($this->continuousBuffer) { $encryptIV = substr($ciphertext, -$block_size) ^ substr($plaintext, -$block_size); } @@ -1576,7 +1559,7 @@ abstract class SymmetricKey * @return int * @access private */ - function _openssl_translate_mode() + protected function openssl_translate_mode() { switch ($this->mode) { case self::MODE_ECB: @@ -1607,7 +1590,7 @@ abstract class SymmetricKey * @see self::disablePadding() * @access public */ - function enablePadding() + public function enablePadding() { $this->padding = true; } @@ -1618,7 +1601,7 @@ abstract class SymmetricKey * @see self::enablePadding() * @access public */ - function disablePadding() + public function disablePadding() { $this->padding = false; } @@ -1661,7 +1644,7 @@ abstract class SymmetricKey * @access public * @internal Could, but not must, extend by the child Crypt_* class */ - function enableContinuousBuffer() + public function enableContinuousBuffer() { if ($this->mode == self::MODE_ECB) { return; @@ -1669,7 +1652,7 @@ abstract class SymmetricKey $this->continuousBuffer = true; - $this->_setEngine(); + $this->setEngine(); } /** @@ -1681,7 +1664,7 @@ abstract class SymmetricKey * @access public * @internal Could, but not must, extend by the child Crypt_* class */ - function disableContinuousBuffer() + public function disableContinuousBuffer() { if ($this->mode == self::MODE_ECB) { return; @@ -1693,7 +1676,7 @@ abstract class SymmetricKey $this->continuousBuffer = false; $this->changed = true; - $this->_setEngine(); + $this->setEngine(); } /** @@ -1704,7 +1687,7 @@ abstract class SymmetricKey * @access public * @return bool */ - function isValidEngine($engine) + public function isValidEngine($engine) { switch ($engine) { case self::ENGINE_OPENSSL: @@ -1720,14 +1703,6 @@ abstract class SymmetricKey return false; } - // prior to PHP 5.4.0 OPENSSL_RAW_DATA and OPENSSL_ZERO_PADDING were not defined. instead of expecting an integer - // $options openssl_encrypt expected a boolean $raw_data. - if (!defined('OPENSSL_RAW_DATA')) { - $this->openssl_options = true; - } else { - $this->openssl_options = OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING; - } - $methods = openssl_get_cipher_methods(); if (in_array($this->cipher_name_openssl, $methods)) { return true; @@ -1770,7 +1745,7 @@ abstract class SymmetricKey * @param int $engine * @access public */ - function setPreferredEngine($engine) + public function setPreferredEngine($engine) { switch ($engine) { //case self::ENGINE_OPENSSL; @@ -1782,16 +1757,16 @@ abstract class SymmetricKey $this->preferredEngine = self::ENGINE_OPENSSL; } - $this->_setEngine(); + $this->setEngine(); } /** * Returns the engine currently being utilized * - * @see self::_setEngine() + * @see self::setEngine() * @access public */ - function getEngine() + public function getEngine() { return $this->engine; } @@ -1802,7 +1777,7 @@ abstract class SymmetricKey * @see self::__construct() * @access private */ - function _setEngine() + protected function setEngine() { $this->engine = null; @@ -1847,7 +1822,7 @@ abstract class SymmetricKey * @param string $in * @return string */ - abstract function _encryptBlock($in); + abstract protected function encryptBlock($in); /** * Decrypts a block @@ -1858,7 +1833,7 @@ abstract class SymmetricKey * @param string $in * @return string */ - abstract function _decryptBlock($in); + abstract protected function decryptBlock($in); /** * Setup the key (expansion) @@ -1867,10 +1842,10 @@ abstract class SymmetricKey * * Note: Must extend by the child \phpseclib\Crypt\* class * - * @see self::_setup() + * @see self::setup() * @access private */ - abstract function _setupKey(); + abstract protected function setupKey(); /** * Setup the self::ENGINE_INTERNAL $engine @@ -1893,16 +1868,16 @@ abstract class SymmetricKey * @see self::setIV() * @see self::disableContinuousBuffer() * @access private - * @internal _setup() is always called before en/decryption. + * @internal setup() is always called before en/decryption. * @internal Could, but not must, extend by the child Crypt_* class */ - function _setup() + protected function setup() { - $this->_clearBuffers(); - $this->_setupKey(); + $this->clearBuffers(); + $this->setupKey(); if ($this->use_inline_crypt) { - $this->_setupInlineCrypt(); + $this->setupInlineCrypt(); } } @@ -1929,9 +1904,9 @@ abstract class SymmetricKey * @access private * @internal Could, but not must, extend by the child Crypt_* class */ - function _setupMcrypt() + protected function setupMcrypt() { - $this->_clearBuffers(); + $this->clearBuffers(); $this->enchanged = $this->dechanged = true; if (!isset($this->enmcrypt)) { @@ -1970,13 +1945,13 @@ abstract class SymmetricKey * If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless * and padding will, hence forth, be enabled. * - * @see self::_unpad() + * @see self::unpad() * @param string $text * @throws \LengthException if padding is disabled and the plaintext's length is not a multiple of the block size * @access private * @return string */ - function _pad($text) + protected function pad($text) { $length = strlen($text); @@ -1999,13 +1974,13 @@ abstract class SymmetricKey * If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong * and false will be returned. * - * @see self::_pad() + * @see self::pad() * @param string $text * @throws \LengthException if the ciphertext's length is not a multiple of the block size * @access private * @return string */ - function _unpad($text) + protected function unpad($text) { if (!$this->padding) { return $text; @@ -2031,7 +2006,7 @@ abstract class SymmetricKey * @internal Could, but not must, extend by the child Crypt_* class * @throws \UnexpectedValueException when an IV is required but not defined */ - function _clearBuffers() + private function clearBuffers() { $this->enbuffer = $this->debuffer = ['ciphertext' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true]; @@ -2042,23 +2017,6 @@ abstract class SymmetricKey $this->encryptIV = $this->decryptIV = $this->iv; } - /** - * String Pop - * - * Inspired by array_pop - * - * @param string $string - * @param int $index - * @access private - * @return string - */ - function _string_pop(&$string, $index = 1) - { - $substr = substr($string, -$index); - $string = substr($string, 0, -$index); - return $substr; - } - /** * Increment the current string * @@ -2067,7 +2025,7 @@ abstract class SymmetricKey * @param string $var * @access private */ - function _increment_str(&$var) + protected function increment_str(&$var) { for ($i = 4; $i <= strlen($var); $i+= 4) { $temp = substr($var, -$i, 4); @@ -2149,14 +2107,14 @@ abstract class SymmetricKey * - The callback function should not use the 'return' statement, but en/decrypt'ing the content of $in only * * - * @see self::_setup() - * @see self::_createInlineCryptFunction() + * @see self::setup() + * @see self::createInlineCryptFunction() * @see self::encrypt() * @see self::decrypt() * @access private * @internal If a Crypt_* class providing inline crypting it must extend _setupInlineCrypt() */ - function _setupInlineCrypt() + protected function setupInlineCrypt() { // If, for any reason, an extending \phpseclib\Crypt\Common\SymmetricKey() \phpseclib\Crypt\* class // not using inline crypting then it must be ensured that: $this->use_inline_crypt = false @@ -2271,14 +2229,14 @@ abstract class SymmetricKey * ]; * * - * @see self::_setupInlineCrypt() + * @see self::setupInlineCrypt() * @see self::encrypt() * @see self::decrypt() * @param array $cipher_code * @access private * @return string (the name of the created callback function) */ - function _createInlineCryptFunction($cipher_code) + protected function createInlineCryptFunction($cipher_code) { $block_size = $this->block_size; @@ -2319,22 +2277,22 @@ abstract class SymmetricKey $_plaintext.= $in; } - return $self->_unpad($_plaintext); + return $this->unpad($_plaintext); '; break; case self::MODE_CTR: $encrypt = $init_encrypt . ' $_ciphertext = ""; $_plaintext_len = strlen($_text); - $_xor = $self->encryptIV; - $_buffer = &$self->enbuffer; + $_xor = $this->encryptIV; + $_buffer = &$this->enbuffer; if (strlen($_buffer["ciphertext"])) { for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') { $_block = substr($_text, $_i, '.$block_size.'); if (strlen($_block) > strlen($_buffer["ciphertext"])) { $in = $_xor; '.$encrypt_block.' - $self->_increment_str($_xor); + $this->increment_str($_xor); $_buffer["ciphertext"].= $in; } $_key = \phpseclib\Common\Functions\Strings::shift($_buffer["ciphertext"], '.$block_size.'); @@ -2345,13 +2303,13 @@ abstract class SymmetricKey $_block = substr($_text, $_i, '.$block_size.'); $in = $_xor; '.$encrypt_block.' - $self->_increment_str($_xor); + $this->increment_str($_xor); $_key = $in; $_ciphertext.= $_block ^ $_key; } } - if ($self->continuousBuffer) { - $self->encryptIV = $_xor; + if ($this->continuousBuffer) { + $this->encryptIV = $_xor; if ($_start = $_plaintext_len % '.$block_size.') { $_buffer["ciphertext"] = substr($_key, $_start) . $_buffer["ciphertext"]; } @@ -2363,8 +2321,8 @@ abstract class SymmetricKey $decrypt = $init_encrypt . ' $_plaintext = ""; $_ciphertext_len = strlen($_text); - $_xor = $self->decryptIV; - $_buffer = &$self->debuffer; + $_xor = $this->decryptIV; + $_buffer = &$this->debuffer; if (strlen($_buffer["ciphertext"])) { for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') { @@ -2372,7 +2330,7 @@ abstract class SymmetricKey if (strlen($_block) > strlen($_buffer["ciphertext"])) { $in = $_xor; '.$encrypt_block.' - $self->_increment_str($_xor); + $this->increment_str($_xor); $_buffer["ciphertext"].= $in; } $_key = \phpseclib\Common\Functions\Strings::shift($_buffer["ciphertext"], '.$block_size.'); @@ -2383,13 +2341,13 @@ abstract class SymmetricKey $_block = substr($_text, $_i, '.$block_size.'); $in = $_xor; '.$encrypt_block.' - $self->_increment_str($_xor); + $this->increment_str($_xor); $_key = $in; $_plaintext.= $_block ^ $_key; } } - if ($self->continuousBuffer) { - $self->decryptIV = $_xor; + if ($this->continuousBuffer) { + $this->decryptIV = $_xor; if ($_start = $_ciphertext_len % '.$block_size.') { $_buffer["ciphertext"] = substr($_key, $_start) . $_buffer["ciphertext"]; } @@ -2401,13 +2359,13 @@ abstract class SymmetricKey case self::MODE_CFB: $encrypt = $init_encrypt . ' $_ciphertext = ""; - $_buffer = &$self->enbuffer; + $_buffer = &$this->enbuffer; - if ($self->continuousBuffer) { - $_iv = &$self->encryptIV; + if ($this->continuousBuffer) { + $_iv = &$this->encryptIV; $_pos = &$_buffer["pos"]; } else { - $_iv = $self->encryptIV; + $_iv = $this->encryptIV; $_pos = 0; } $_len = strlen($_text); @@ -2449,13 +2407,13 @@ abstract class SymmetricKey $decrypt = $init_encrypt . ' $_plaintext = ""; - $_buffer = &$self->debuffer; + $_buffer = &$this->debuffer; - if ($self->continuousBuffer) { - $_iv = &$self->decryptIV; + if ($this->continuousBuffer) { + $_iv = &$this->decryptIV; $_pos = &$_buffer["pos"]; } else { - $_iv = $self->decryptIV; + $_iv = $this->decryptIV; $_pos = 0; } $_len = strlen($_text); @@ -2501,8 +2459,8 @@ abstract class SymmetricKey $encrypt = $init_encrypt . ' $_ciphertext = ""; $_plaintext_len = strlen($_text); - $_xor = $self->encryptIV; - $_buffer = &$self->enbuffer; + $_xor = $this->encryptIV; + $_buffer = &$this->enbuffer; if (strlen($_buffer["xor"])) { for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') { @@ -2525,8 +2483,8 @@ abstract class SymmetricKey } $_key = $_xor; } - if ($self->continuousBuffer) { - $self->encryptIV = $_xor; + if ($this->continuousBuffer) { + $this->encryptIV = $_xor; if ($_start = $_plaintext_len % '.$block_size.') { $_buffer["xor"] = substr($_key, $_start) . $_buffer["xor"]; } @@ -2537,8 +2495,8 @@ abstract class SymmetricKey $decrypt = $init_encrypt . ' $_plaintext = ""; $_ciphertext_len = strlen($_text); - $_xor = $self->decryptIV; - $_buffer = &$self->debuffer; + $_xor = $this->decryptIV; + $_buffer = &$this->debuffer; if (strlen($_buffer["xor"])) { for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') { @@ -2561,8 +2519,8 @@ abstract class SymmetricKey } $_key = $_xor; } - if ($self->continuousBuffer) { - $self->decryptIV = $_xor; + if ($this->continuousBuffer) { + $this->decryptIV = $_xor; if ($_start = $_ciphertext_len % '.$block_size.') { $_buffer["xor"] = substr($_key, $_start) . $_buffer["xor"]; } @@ -2588,7 +2546,7 @@ abstract class SymmetricKey $_ciphertext = ""; $_plaintext_len = strlen($_text); - $in = $self->encryptIV; + $in = $this->encryptIV; for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') { $in = substr($_text, $_i, '.$block_size.') ^ $in; @@ -2596,8 +2554,8 @@ abstract class SymmetricKey $_ciphertext.= $in; } - if ($self->continuousBuffer) { - $self->encryptIV = $in; + if ($this->continuousBuffer) { + $this->encryptIV = $in; } return $_ciphertext; @@ -2608,7 +2566,7 @@ abstract class SymmetricKey $_text = str_pad($_text, strlen($_text) + ('.$block_size.' - strlen($_text) % '.$block_size.') % '.$block_size.', chr(0)); $_ciphertext_len = strlen($_text); - $_iv = $self->decryptIV; + $_iv = $this->decryptIV; for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') { $in = $_block = substr($_text, $_i, '.$block_size.'); @@ -2617,17 +2575,18 @@ abstract class SymmetricKey $_iv = $_block; } - if ($self->continuousBuffer) { - $self->decryptIV = $_iv; + if ($this->continuousBuffer) { + $this->decryptIV = $_iv; } - return $self->_unpad($_plaintext); + return $this->unpad($_plaintext); '; break; } - // 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 . ' }'); + eval('$func = function ($_action, $_text) { ' . $init_crypt . 'if ($_action == "encrypt") { ' . $encrypt . ' } else { ' . $decrypt . ' }};'); + + return $func; } /** @@ -2645,7 +2604,7 @@ abstract class SymmetricKey * @access private * @return array &$functions */ - function &_getLambdaFunctions() + protected function &getLambdaFunctions() { static $functions = []; return $functions; @@ -2654,12 +2613,12 @@ abstract class SymmetricKey /** * Generates a digest from $bytes * - * @see self::_setupInlineCrypt() + * @see self::setupInlineCrypt() * @access private * @param $bytes * @return string */ - function _hashInlineCryptFunction($bytes) + protected function hashInlineCryptFunction($bytes) { if (!isset(self::$WHIRLPOOL_AVAILABLE)) { self::$WHIRLPOOL_AVAILABLE = extension_loaded('hash') && in_array('whirlpool', hash_algos()); @@ -2685,4 +2644,15 @@ abstract class SymmetricKey return $result . sha1($hash, true); } } + + /** + * Returns the class that defines the private methods + * + * @access private + * @return string + */ + protected function getClassContext() + { + return get_called_class(); + } } diff --git a/phpseclib/Crypt/DES.php b/phpseclib/Crypt/DES.php index 856dfc53..b0aff601 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -55,8 +55,8 @@ class DES extends BlockCipher { /**#@+ * @access private - * @see \phpseclib\Crypt\DES::_setupKey() - * @see \phpseclib\Crypt\DES::_processBlock() + * @see \phpseclib\Crypt\DES::setupKey() + * @see \phpseclib\Crypt\DES::processBlock() */ /** * Contains $keys[self::ENCRYPT] @@ -75,7 +75,7 @@ class DES extends BlockCipher * @var int * @access private */ - var $block_size = 8; + protected $block_size = 8; /** * Key Length (in bytes) @@ -84,7 +84,7 @@ class DES extends BlockCipher * @var int * @access private */ - var $key_length = 8; + protected $key_length = 8; /** * The mcrypt specific name of the cipher @@ -93,7 +93,7 @@ class DES extends BlockCipher * @var string * @access private */ - var $cipher_name_mcrypt = 'des'; + protected $cipher_name_mcrypt = 'des'; /** * The OpenSSL names of the cipher / modes @@ -102,7 +102,7 @@ class DES extends BlockCipher * @var array * @access private */ - var $openssl_mode_names = [ + protected $openssl_mode_names = [ self::MODE_ECB => 'des-ecb', self::MODE_CBC => 'des-cbc', self::MODE_CFB => 'des-cfb', @@ -117,19 +117,19 @@ class DES extends BlockCipher * @var int * @access private */ - var $cfb_init_len = 500; + protected $cfb_init_len = 500; /** * Switch for DES/3DES encryption * * Used only if $engine == self::ENGINE_INTERNAL * - * @see self::_setupKey() - * @see self::_processBlock() + * @see self::setupKey() + * @see self::processBlock() * @var int * @access private */ - var $des_rounds = 1; + protected $des_rounds = 1; /** * max possible size of $key @@ -138,16 +138,16 @@ class DES extends BlockCipher * @var string * @access private */ - var $key_length_max = 8; + protected $key_length_max = 8; /** * The Key Schedule * - * @see self::_setupKey() + * @see self::setupKey() * @var array * @access private */ - var $keys; + private $keys; /** * Shuffle table. @@ -156,12 +156,12 @@ class DES extends BlockCipher * with each byte containing all bits in the same state as the * corresponding bit in the index value. * - * @see self::_processBlock() - * @see self::_setupKey() + * @see self::processBlock() + * @see self::setupKey() * @var array * @access private */ - var $shuffle = [ + private $shuffle = [ "\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\xFF", "\x00\x00\x00\x00\x00\x00\xFF\x00", "\x00\x00\x00\x00\x00\x00\xFF\xFF", "\x00\x00\x00\x00\x00\xFF\x00\x00", "\x00\x00\x00\x00\x00\xFF\x00\xFF", @@ -300,7 +300,7 @@ class DES extends BlockCipher * @var array * @access private */ - var $ipmap = [ + private $ipmap = [ 0x00, 0x10, 0x01, 0x11, 0x20, 0x30, 0x21, 0x31, 0x02, 0x12, 0x03, 0x13, 0x22, 0x32, 0x23, 0x33, 0x40, 0x50, 0x41, 0x51, 0x60, 0x70, 0x61, 0x71, @@ -342,7 +342,7 @@ class DES extends BlockCipher * @var array * @access private */ - var $invipmap = [ + private $invipmap = [ 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, @@ -386,7 +386,7 @@ class DES extends BlockCipher * @var array * @access private */ - var $sbox1 = [ + private $sbox1 = [ 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000, 0x00000200, 0x00808200, 0x00808202, 0x00000200, @@ -411,7 +411,7 @@ class DES extends BlockCipher * @var array * @access private */ - var $sbox2 = [ + private $sbox2 = [ 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010, 0x40000010, 0x40084010, 0x40084000, 0x40000000, @@ -436,7 +436,7 @@ class DES extends BlockCipher * @var array * @access private */ - var $sbox3 = [ + private $sbox3 = [ 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100, 0x00010004, 0x04000004, 0x04000004, 0x00010000, @@ -461,7 +461,7 @@ class DES extends BlockCipher * @var array * @access private */ - var $sbox4 = [ + private $sbox4 = [ 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000, 0x00000000, 0x00401000, 0x00401000, 0x80401040, @@ -486,7 +486,7 @@ class DES extends BlockCipher * @var array * @access private */ - var $sbox5 = [ + private $sbox5 = [ 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000, 0x20040080, 0x00040000, 0x01000080, 0x20040080, @@ -511,7 +511,7 @@ class DES extends BlockCipher * @var array * @access private */ - var $sbox6 = [ + private $sbox6 = [ 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000, 0x10002000, 0x00202008, 0x00200000, 0x10000008, @@ -536,7 +536,7 @@ class DES extends BlockCipher * @var array * @access private */ - var $sbox7 = [ + private $sbox7 = [ 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400, 0x02100401, 0x00100000, 0x00000000, 0x02000001, @@ -561,7 +561,7 @@ class DES extends BlockCipher * @var array * @access private */ - var $sbox8 = [ + private $sbox8 = [ 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000, 0x00020020, 0x08020000, 0x08020820, 0x00020800, @@ -587,7 +587,7 @@ class DES extends BlockCipher * @access public * @throws \InvalidArgumentException if an invalid / unsupported mode is provided */ - function __construct($mode) + public function __construct($mode) { if ($mode == self::MODE_STREAM) { throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode'); @@ -606,12 +606,12 @@ class DES extends BlockCipher * @access public * @return bool */ - function isValidEngine($engine) + public function isValidEngine($engine) { if ($this->key_length_max == 8) { if ($engine == self::ENGINE_OPENSSL) { $this->cipher_name_openssl_ecb = 'des-ecb'; - $this->cipher_name_openssl = 'des-' . $this->_openssl_translate_mode(); + $this->cipher_name_openssl = 'des-' . $this->openssl_translate_mode(); } } @@ -629,7 +629,7 @@ class DES extends BlockCipher * @access public * @param string $key */ - function setKey($key) + public function setKey($key) { if (!($this instanceof TripleDES) && strlen($key) != 8) { throw new \LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of size 8 are supported'); @@ -642,31 +642,31 @@ class DES extends BlockCipher /** * Encrypts a block * - * @see \phpseclib\Crypt\Common\SymmetricKey::_encryptBlock() + * @see \phpseclib\Crypt\Common\SymmetricKey::encryptBlock() * @see \phpseclib\Crypt\Common\SymmetricKey::encrypt() * @see self::encrypt() * @access private * @param string $in * @return string */ - function _encryptBlock($in) + protected function encryptBlock($in) { - return $this->_processBlock($in, self::ENCRYPT); + return $this->processBlock($in, self::ENCRYPT); } /** * Decrypts a block * - * @see \phpseclib\Crypt\Common\SymmetricKey::_decryptBlock() + * @see \phpseclib\Crypt\Common\SymmetricKey::decryptBlock() * @see \phpseclib\Crypt\Common\SymmetricKey::decrypt() * @see self::decrypt() * @access private * @param string $in * @return string */ - function _decryptBlock($in) + protected function decryptBlock($in) { - return $this->_processBlock($in, self::DECRYPT); + return $this->processBlock($in, self::DECRYPT); } /** @@ -676,14 +676,14 @@ class DES extends BlockCipher * {@link http://en.wikipedia.org/wiki/Image:Feistel.png Feistel.png} to get a general * idea of what this function does. * - * @see self::_encryptBlock() - * @see self::_decryptBlock() + * @see self::encryptBlock() + * @see self::decryptBlock() * @access private * @param string $block * @param int $mode * @return string */ - function _processBlock($block, $mode) + private function processBlock($block, $mode) { static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip; if (!$sbox1) { @@ -761,10 +761,10 @@ class DES extends BlockCipher /** * Creates the key schedule * - * @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() + * @see \phpseclib\Crypt\Common\SymmetricKey::setupKey() * @access private */ - function _setupKey() + protected function setupKey() { if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->des_rounds === $this->kl['des_rounds']) { // already expanded @@ -1296,12 +1296,12 @@ class DES extends BlockCipher /** * Setup the performance-optimized function for de/encrypt() * - * @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt() + * @see \phpseclib\Crypt\Common\SymmetricKey::setupInlineCrypt() * @access private */ - function _setupInlineCrypt() + protected function setupInlineCrypt() { - $lambda_functions =& self::_getLambdaFunctions(); + $lambda_functions =& self::getLambdaFunctions(); // Engine configuration for: // - DES ($des_rounds == 1) or @@ -1322,7 +1322,7 @@ class DES extends BlockCipher // After max 10 hi-optimized functions, we create generic // (still very fast.. but not ultra) functions for each $mode/$des_rounds // Currently 2 * 5 generic functions will be then max. possible. - $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); + $code_hash = str_pad($code_hash, 32) . $this->hashInlineCryptFunction($this->key); } // Is there a re-usable $lambda_functions in there? If not, we have to create it. @@ -1330,18 +1330,18 @@ class DES extends BlockCipher // Init code for both, encrypt and decrypt. $init_crypt = 'static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip; if (!$sbox1) { - $sbox1 = array_map("intval", $self->sbox1); - $sbox2 = array_map("intval", $self->sbox2); - $sbox3 = array_map("intval", $self->sbox3); - $sbox4 = array_map("intval", $self->sbox4); - $sbox5 = array_map("intval", $self->sbox5); - $sbox6 = array_map("intval", $self->sbox6); - $sbox7 = array_map("intval", $self->sbox7); - $sbox8 = array_map("intval", $self->sbox8);' + $sbox1 = array_map("intval", $this->sbox1); + $sbox2 = array_map("intval", $this->sbox2); + $sbox3 = array_map("intval", $this->sbox3); + $sbox4 = array_map("intval", $this->sbox4); + $sbox5 = array_map("intval", $this->sbox5); + $sbox6 = array_map("intval", $this->sbox6); + $sbox7 = array_map("intval", $this->sbox7); + $sbox8 = array_map("intval", $this->sbox8);' /* Merge $shuffle with $[inv]ipmap */ . ' for ($i = 0; $i < 256; ++$i) { - $shuffleip[] = $self->shuffle[$self->ipmap[$i]]; - $shuffleinvip[] = $self->shuffle[$self->invipmap[$i]]; + $shuffleip[] = $this->shuffle[$this->ipmap[$i]]; + $shuffleinvip[] = $this->shuffle[$this->invipmap[$i]]; } } '; @@ -1369,8 +1369,8 @@ class DES extends BlockCipher $k[self::ENCRYPT][$i] = '$ke[' . $i . ']'; $k[self::DECRYPT][$i] = '$kd[' . $i . ']'; } - $init_encrypt = '$ke = $self->keys[self::ENCRYPT];'; - $init_decrypt = '$kd = $self->keys[self::DECRYPT];'; + $init_encrypt = '$ke = $this->keys[self::ENCRYPT];'; + $init_decrypt = '$kd = $this->keys[self::DECRYPT];'; break; } @@ -1438,7 +1438,7 @@ class DES extends BlockCipher } // Creates the inline-crypt function - $lambda_functions[$code_hash] = $this->_createInlineCryptFunction( + $lambda_functions[$code_hash] = $this->createInlineCryptFunction( [ 'init_crypt' => $init_crypt, 'init_encrypt' => $init_encrypt, @@ -1450,6 +1450,6 @@ class DES extends BlockCipher } // Set the inline-crypt function as callback in: $this->inline_crypt - $this->inline_crypt = $lambda_functions[$code_hash]; + $this->inline_crypt = \Closure::bind($lambda_functions[$code_hash], $this, $this->getClassContext()); } } diff --git a/phpseclib/Crypt/RC2.php b/phpseclib/Crypt/RC2.php index ddd35321..2105c022 100644 --- a/phpseclib/Crypt/RC2.php +++ b/phpseclib/Crypt/RC2.php @@ -52,7 +52,7 @@ class RC2 extends BlockCipher * @var int * @access private */ - var $block_size = 8; + protected $block_size = 8; /** * The Key @@ -62,7 +62,7 @@ class RC2 extends BlockCipher * @var string * @access private */ - var $key; + protected $key; /** * The Original (unpadded) Key @@ -74,16 +74,16 @@ class RC2 extends BlockCipher * @var string * @access private */ - var $orig_key; + private $orig_key; /** * Don't truncate / null pad key * - * @see \phpseclib\Crypt\Common\SymmetricKey::_clearBuffers() + * @see \phpseclib\Crypt\Common\SymmetricKey::clearBuffers() * @var bool * @access private */ - var $skip_key_adjustment = true; + private $skip_key_adjustment = true; /** * Key Length (in bytes) @@ -92,7 +92,7 @@ class RC2 extends BlockCipher * @var int * @access private */ - var $key_length = 16; // = 128 bits + protected $key_length = 16; // = 128 bits /** * The mcrypt specific name of the cipher @@ -101,7 +101,7 @@ class RC2 extends BlockCipher * @var string * @access private */ - var $cipher_name_mcrypt = 'rc2'; + protected $cipher_name_mcrypt = 'rc2'; /** * Optimizing value while CFB-encrypting @@ -110,7 +110,7 @@ class RC2 extends BlockCipher * @var int * @access private */ - var $cfb_init_len = 500; + protected $cfb_init_len = 500; /** * The key length in bits. @@ -122,7 +122,7 @@ class RC2 extends BlockCipher * @internal Should be in range [1..1024]. * @internal Changing this value after setting the key has no effect. */ - var $default_key_length = 1024; + private $default_key_length = 1024; /** * The key length in bits. @@ -133,16 +133,16 @@ class RC2 extends BlockCipher * @access private * @internal Should be in range [1..1024]. */ - var $current_key_length; + private $current_key_length; /** * The Key Schedule * - * @see self::_setupKey() + * @see self::setupKey() * @var array * @access private */ - var $keys; + private $keys; /** * Key expansion randomization table. @@ -152,7 +152,7 @@ class RC2 extends BlockCipher * @var array * @access private */ - var $pitable = [ + private $pitable = [ 0xD9, 0x78, 0xF9, 0xC4, 0x19, 0xDD, 0xB5, 0xED, 0x28, 0xE9, 0xFD, 0x79, 0x4A, 0xA0, 0xD8, 0x9D, 0xC6, 0x7E, 0x37, 0x83, 0x2B, 0x76, 0x53, 0x8E, @@ -226,7 +226,7 @@ class RC2 extends BlockCipher * @var array * @access private */ - var $invpitable = [ + private $invpitable = [ 0xD1, 0xDA, 0xB9, 0x6F, 0x9C, 0xC8, 0x78, 0x66, 0x80, 0x2C, 0xF8, 0x37, 0xEA, 0xE0, 0x62, 0xA4, 0xCB, 0x71, 0x50, 0x27, 0x4B, 0x95, 0xD9, 0x20, @@ -268,7 +268,7 @@ class RC2 extends BlockCipher * @access public * @throws \InvalidArgumentException if an invalid / unsupported mode is provided */ - function __construct($mode) + public function __construct($mode) { if ($mode == self::MODE_STREAM) { throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode'); @@ -287,7 +287,7 @@ class RC2 extends BlockCipher * @access public * @return bool */ - function isValidEngine($engine) + public function isValidEngine($engine) { switch ($engine) { case self::ENGINE_OPENSSL: @@ -295,7 +295,7 @@ class RC2 extends BlockCipher return false; } $this->cipher_name_openssl_ecb = 'rc2-ecb'; - $this->cipher_name_openssl = 'rc2-' . $this->_openssl_translate_mode(); + $this->cipher_name_openssl = 'rc2-' . $this->openssl_translate_mode(); } return parent::isValidEngine($engine); @@ -312,7 +312,7 @@ class RC2 extends BlockCipher * @param int $length in bits * @throws \LengthException if the key length isn't supported */ - function setKeyLength($length) + public function setKeyLength($length) { if ($length < 8 || $length > 1024) { throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys between 1 and 1024 bits, inclusive, are supported'); @@ -328,7 +328,7 @@ class RC2 extends BlockCipher * @access public * @return int */ - function getKeyLength() + public function getKeyLength() { return $this->current_key_length; } @@ -347,7 +347,7 @@ class RC2 extends BlockCipher * @param int $t1 optional Effective key length in bits. * @throws \LengthException if the key length isn't supported */ - function setKey($key, $t1 = false) + public function setKey($key, $t1 = false) { $this->orig_key = $key; @@ -395,7 +395,7 @@ class RC2 extends BlockCipher $this->key = call_user_func_array('pack', $l); $this->key_length = strlen($this->key); $this->changed = true; - $this->_setEngine(); + $this->setEngine(); } /** @@ -408,7 +408,7 @@ class RC2 extends BlockCipher * @param string $plaintext * @return string $ciphertext */ - function encrypt($plaintext) + public function encrypt($plaintext) { if ($this->engine == self::ENGINE_OPENSSL) { $temp = $this->key; @@ -431,7 +431,7 @@ class RC2 extends BlockCipher * @param string $ciphertext * @return string $plaintext */ - function decrypt($ciphertext) + public function decrypt($ciphertext) { if ($this->engine == self::ENGINE_OPENSSL) { $temp = $this->key; @@ -447,13 +447,13 @@ class RC2 extends BlockCipher /** * Encrypts a block * - * @see \phpseclib\Crypt\Common\SymmetricKey::_encryptBlock() + * @see \phpseclib\Crypt\Common\SymmetricKey::encryptBlock() * @see \phpseclib\Crypt\Common\SymmetricKey::encrypt() * @access private * @param string $in * @return string */ - function _encryptBlock($in) + protected function encryptBlock($in) { list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in)); $keys = $this->keys; @@ -492,13 +492,13 @@ class RC2 extends BlockCipher /** * Decrypts a block * - * @see \phpseclib\Crypt\Common\SymmetricKey::_decryptBlock() + * @see \phpseclib\Crypt\Common\SymmetricKey::decryptBlock() * @see \phpseclib\Crypt\Common\SymmetricKey::decrypt() * @access private * @param string $in * @return string */ - function _decryptBlock($in) + protected function decryptBlock($in) { list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in)); $keys = $this->keys; @@ -537,25 +537,25 @@ class RC2 extends BlockCipher /** * Setup the \phpseclib\Crypt\Common\SymmetricKey::ENGINE_MCRYPT $engine * - * @see \phpseclib\Crypt\Common\SymmetricKey::_setupMcrypt() + * @see \phpseclib\Crypt\Common\SymmetricKey::setupMcrypt() * @access private */ - function _setupMcrypt() + protected function setupMcrypt() { if (!isset($this->key)) { $this->setKey(''); } - parent::_setupMcrypt(); + parent::setupMcrypt(); } /** * Creates the key schedule * - * @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() + * @see \phpseclib\Crypt\Common\SymmetricKey::setupKey() * @access private */ - function _setupKey() + protected function setupKey() { if (!isset($this->key)) { $this->setKey(''); @@ -573,12 +573,12 @@ class RC2 extends BlockCipher /** * Setup the performance-optimized function for de/encrypt() * - * @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt() + * @see \phpseclib\Crypt\Common\SymmetricKey::setupInlineCrypt() * @access private */ - function _setupInlineCrypt() + protected function setupInlineCrypt() { - $lambda_functions =& self::_getLambdaFunctions(); + $lambda_functions =& self::getLambdaFunctions(); // The first 10 generated $lambda_functions will use the $keys hardcoded as integers // for the mixing rounds, for better inline crypt performance [~20% faster]. @@ -589,14 +589,14 @@ class RC2 extends BlockCipher // Generation of a unique hash for our generated code $code_hash = "Crypt_RC2, {$this->mode}"; if ($gen_hi_opt_code) { - $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); + $code_hash = str_pad($code_hash, 32) . $this->hashInlineCryptFunction($this->key); } // Is there a re-usable $lambda_functions in there? // If not, we have to create it. if (!isset($lambda_functions[$code_hash])) { // Init code for both, encrypt and decrypt. - $init_crypt = '$keys = $self->keys;'; + $init_crypt = '$keys = $this->keys;'; switch (true) { case $gen_hi_opt_code: @@ -694,7 +694,7 @@ class RC2 extends BlockCipher $decrypt_block .= '$in = pack("v4", $r0, $r1, $r2, $r3);'; // Creates the inline-crypt function - $lambda_functions[$code_hash] = $this->_createInlineCryptFunction( + $lambda_functions[$code_hash] = $this->createInlineCryptFunction( [ 'init_crypt' => $init_crypt, 'encrypt_block' => $encrypt_block, @@ -704,6 +704,6 @@ class RC2 extends BlockCipher } // Set the inline-crypt function as callback in: $this->inline_crypt - $this->inline_crypt = $lambda_functions[$code_hash]; + $this->inline_crypt = \Closure::bind($lambda_functions[$code_hash], $this, $this->getClassContext()); } } diff --git a/phpseclib/Crypt/RC4.php b/phpseclib/Crypt/RC4.php index 19afe0c8..153b60cc 100644 --- a/phpseclib/Crypt/RC4.php +++ b/phpseclib/Crypt/RC4.php @@ -73,7 +73,7 @@ class RC4 extends StreamCipher * @var int * @access private */ - var $block_size = 0; + protected $block_size = 0; /** * Key Length (in bytes) @@ -82,7 +82,7 @@ class RC4 extends StreamCipher * @var int * @access private */ - var $key_length = 128; // = 1024 bits + protected $key_length = 128; // = 1024 bits /** * The mcrypt specific name of the cipher @@ -91,7 +91,7 @@ class RC4 extends StreamCipher * @var string * @access private */ - var $cipher_name_mcrypt = 'arcfour'; + protected $cipher_name_mcrypt = 'arcfour'; /** * Holds whether performance-optimized $inline_crypt() can/should be used. @@ -100,7 +100,7 @@ class RC4 extends StreamCipher * @var mixed * @access private */ - var $use_inline_crypt = false; // currently not available + protected $use_inline_crypt = false; // currently not available /** * The Key @@ -109,7 +109,7 @@ class RC4 extends StreamCipher * @var string * @access private */ - var $key; + protected $key; /** * The Key Stream for decryption and encryption @@ -118,7 +118,7 @@ class RC4 extends StreamCipher * @var array * @access private */ - var $stream; + private $stream; /** * Default Constructor. @@ -127,7 +127,7 @@ class RC4 extends StreamCipher * @return \phpseclib\Crypt\RC4 * @access public */ - function __construct() + public function __construct() { parent::__construct(self::MODE_STREAM); } @@ -142,7 +142,7 @@ class RC4 extends StreamCipher * @access public * @return bool */ - function isValidEngine($engine) + public function isValidEngine($engine) { switch ($engine) { case self::ENGINE_OPENSSL: @@ -170,7 +170,7 @@ class RC4 extends StreamCipher * @access public * @return bool */ - function usesIV() + public function usesIV() { return false; } @@ -184,7 +184,7 @@ class RC4 extends StreamCipher * @param int $length * @throws \LengthException if the key length is invalid */ - function setKeyLength($length) + public function setKeyLength($length) { if ($length < 8 || $length > 2048) { throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys between 1 and 256 bytes are supported'); @@ -204,7 +204,7 @@ class RC4 extends StreamCipher * @param int $length * @throws \LengthException if the key length is invalid */ - function setKey($key) + public function setKey($key) { $length = strlen($key); if ($length < 1 || $length > 256) { @@ -218,17 +218,17 @@ class RC4 extends StreamCipher * Encrypts a message. * * @see \phpseclib\Crypt\Common\SymmetricKey::decrypt() - * @see self::_crypt() + * @see self::crypt() * @access public * @param string $plaintext * @return string $ciphertext */ - function encrypt($plaintext) + public function encrypt($plaintext) { if ($this->engine != self::ENGINE_INTERNAL) { return parent::encrypt($plaintext); } - return $this->_crypt($plaintext, self::ENCRYPT); + return $this->crypt($plaintext, self::ENCRYPT); } /** @@ -238,17 +238,17 @@ class RC4 extends StreamCipher * At least if the continuous buffer is disabled. * * @see \phpseclib\Crypt\Common\SymmetricKey::encrypt() - * @see self::_crypt() + * @see self::crypt() * @access public * @param string $ciphertext * @return string $plaintext */ - function decrypt($ciphertext) + public function decrypt($ciphertext) { if ($this->engine != self::ENGINE_INTERNAL) { return parent::decrypt($ciphertext); } - return $this->_crypt($ciphertext, self::DECRYPT); + return $this->crypt($ciphertext, self::DECRYPT); } /** @@ -257,7 +257,7 @@ class RC4 extends StreamCipher * @access private * @param string $in */ - function _encryptBlock($in) + protected function encryptBlock($in) { // RC4 does not utilize this method } @@ -268,7 +268,7 @@ class RC4 extends StreamCipher * @access private * @param string $in */ - function _decryptBlock($in) + protected function decryptBlock($in) { // RC4 does not utilize this method } @@ -279,7 +279,7 @@ class RC4 extends StreamCipher * @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() * @access private */ - function _setupKey() + protected function setupKey() { $key = $this->key; $keyLength = strlen($key); @@ -310,10 +310,10 @@ class RC4 extends StreamCipher * @param int $mode * @return string $text */ - function _crypt($text, $mode) + private function crypt($text, $mode) { if ($this->changed) { - $this->_setup(); + $this->setup(); $this->changed = false; } diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index 127b190d..2ef288be 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -79,7 +79,7 @@ class Rijndael extends BlockCipher * @var string * @access private */ - var $cipher_name_mcrypt = 'rijndael-128'; + protected $cipher_name_mcrypt = 'rijndael-128'; /** * The default salt used by setPassword() @@ -89,25 +89,25 @@ class Rijndael extends BlockCipher * @var string * @access private */ - var $password_default_salt = 'phpseclib'; + protected $password_default_salt = 'phpseclib'; /** * The Key Schedule * - * @see self::_setup() + * @see self::setup() * @var array * @access private */ - var $w; + private $w; /** * The Inverse Key Schedule * - * @see self::_setup() + * @see self::setup() * @var array * @access private */ - var $dw; + private $dw; /** * The Block Length divided by 32 @@ -120,7 +120,7 @@ class Rijndael extends BlockCipher * derive this from $block_size or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu * of that, we'll just precompute it once. */ - var $Nb = 4; + private $Nb = 4; /** * The Key Length (in bytes) @@ -133,7 +133,7 @@ class Rijndael extends BlockCipher * derive this from $key_length or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu * of that, we'll just precompute it once. */ - var $key_length = 16; + protected $key_length = 16; /** * The Key Length divided by 32 @@ -143,7 +143,7 @@ class Rijndael extends BlockCipher * @access private * @internal The max value is 256 / 32 = 8, the min value is 128 / 32 = 4 */ - var $Nk = 4; + private $Nk = 4; /** * The Number of Rounds @@ -152,7 +152,7 @@ class Rijndael extends BlockCipher * @access private * @internal The max value is 14, the min value is 10. */ - var $Nr; + private $Nr; /** * Shift offsets @@ -160,7 +160,7 @@ class Rijndael extends BlockCipher * @var array * @access private */ - var $c; + private $c; /** * Holds the last used key- and block_size information @@ -168,7 +168,7 @@ class Rijndael extends BlockCipher * @var array * @access private */ - var $kl; + private $kl; /** * Default Constructor. @@ -177,7 +177,7 @@ class Rijndael extends BlockCipher * @access public * @throws \InvalidArgumentException if an invalid / unsupported mode is provided */ - function __construct($mode) + public function __construct($mode) { if ($mode == self::MODE_STREAM) { throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode'); @@ -206,7 +206,7 @@ class Rijndael extends BlockCipher * @throws \LengthException if the key length is invalid * @param int $length */ - function setKeyLength($length) + public function setKeyLength($length) { switch ($length) { case 128: @@ -233,7 +233,7 @@ class Rijndael extends BlockCipher * @param string $key * @throws \LengthException if the key length isn't supported */ - function setKey($key) + public function setKey($key) { switch (strlen($key)) { case 16: @@ -257,7 +257,7 @@ class Rijndael extends BlockCipher * @access public * @param int $length */ - function setBlockLength($length) + public function setBlockLength($length) { switch ($length) { case 128: @@ -273,7 +273,7 @@ class Rijndael extends BlockCipher $this->Nb = $length >> 5; $this->block_size = $length >> 3; $this->changed = true; - $this->_setEngine(); + $this->setEngine(); } /** @@ -286,7 +286,7 @@ class Rijndael extends BlockCipher * @access public * @return bool */ - function isValidEngine($engine) + public function isValidEngine($engine) { switch ($engine) { case self::ENGINE_OPENSSL: @@ -294,7 +294,7 @@ class Rijndael extends BlockCipher return false; } $this->cipher_name_openssl_ecb = 'aes-' . ($this->key_length << 3) . '-ecb'; - $this->cipher_name_openssl = 'aes-' . ($this->key_length << 3) . '-' . $this->_openssl_translate_mode(); + $this->cipher_name_openssl = 'aes-' . ($this->key_length << 3) . '-' . $this->openssl_translate_mode(); break; case self::ENGINE_MCRYPT: $this->cipher_name_mcrypt = 'rijndael-' . ($this->block_size << 3); @@ -314,11 +314,11 @@ class Rijndael extends BlockCipher * @param string $in * @return string */ - function _encryptBlock($in) + protected function encryptBlock($in) { static $tables; if (empty($tables)) { - $tables = &$this->_getTables(); + $tables = &$this->getTables(); } $t0 = $tables[0]; $t1 = $tables[1]; @@ -415,11 +415,11 @@ class Rijndael extends BlockCipher * @param string $in * @return string */ - function _decryptBlock($in) + protected function decryptBlock($in) { static $invtables; if (empty($invtables)) { - $invtables = &$this->_getInvTables(); + $invtables = &$this->getInvTables(); } $dt0 = $invtables[0]; $dt1 = $invtables[1]; @@ -501,10 +501,10 @@ class Rijndael extends BlockCipher /** * Setup the key (expansion) * - * @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() + * @see \phpseclib\Crypt\Common\SymmetricKey::setupKey() * @access private */ - function _setupKey() + protected function setupKey() { // Each number in $rcon is equal to the previous number multiplied by two in Rijndael's finite field. // See http://en.wikipedia.org/wiki/Finite_field_arithmetic#Multiplicative_inverse @@ -555,9 +555,9 @@ class Rijndael extends BlockCipher // 0xFFFFFFFF << 8 == 0xFFFFFF00, but on a 64-bit machine, it equals 0xFFFFFFFF00. as such, doing 'and' // with 0xFFFFFFFF (or 0xFFFFFF00) on a 32-bit machine is unnecessary, but on a 64-bit machine, it is. $temp = (($temp << 8) & 0xFFFFFF00) | (($temp >> 24) & 0x000000FF); // rotWord - $temp = $this->_subWord($temp) ^ $rcon[$i / $this->Nk]; + $temp = $this->subWord($temp) ^ $rcon[$i / $this->Nk]; } elseif ($this->Nk > 6 && $i % $this->Nk == 4) { - $temp = $this->_subWord($temp); + $temp = $this->subWord($temp); } $w[$i] = $w[$i - $this->Nk] ^ $temp; } @@ -569,7 +569,7 @@ class Rijndael extends BlockCipher // 1. Apply the Key Expansion. // 2. Apply InvMixColumn to all Round Keys except the first and the last one." // also, see fips-197.pdf#page=27, "5.3.5 Equivalent Inverse Cipher" - list($dt0, $dt1, $dt2, $dt3) = $this->_getInvTables(); + list($dt0, $dt1, $dt2, $dt3) = $this->getInvTables(); $temp = $this->w = $this->dw = []; for ($i = $row = $col = 0; $i < $length; $i++, $col++) { if ($col == $this->Nb) { @@ -579,7 +579,7 @@ class Rijndael extends BlockCipher // subWord + invMixColumn + invSubWord = invMixColumn $j = 0; while ($j < $this->Nb) { - $dw = $this->_subWord($this->w[$row][$j]); + $dw = $this->subWord($this->w[$row][$j]); $temp[$j] = $dt0[$dw >> 24 & 0x000000FF] ^ $dt1[$dw >> 16 & 0x000000FF] ^ $dt2[$dw >> 8 & 0x000000FF] ^ @@ -617,11 +617,11 @@ class Rijndael extends BlockCipher * @access private * @param int $word */ - function _subWord($word) + private function subWord($word) { static $sbox; if (empty($sbox)) { - list(, , , , $sbox) = $this->_getTables(); + list(, , , , $sbox) = self::getTables(); } return $sbox[$word & 0x000000FF] | @@ -633,13 +633,13 @@ class Rijndael extends BlockCipher /** * Provides the mixColumns and sboxes tables * - * @see self::_encryptBlock() - * @see self::_setupInlineCrypt() - * @see self::_subWord() + * @see self::encryptBlock() + * @see self::setupInlineCrypt() + * @see self::subWord() * @access private * @return array &$tables */ - function &_getTables() + private function &getTables() { static $tables; if (empty($tables)) { @@ -722,13 +722,13 @@ class Rijndael extends BlockCipher /** * Provides the inverse mixColumns and inverse sboxes tables * - * @see self::_decryptBlock() - * @see self::_setupInlineCrypt() - * @see self::_setupKey() + * @see self::decryptBlock() + * @see self::setupInlineCrypt() + * @see self::setupKey() * @access private * @return array &$tables */ - function &_getInvTables() + private function &getInvTables() { static $tables; if (empty($tables)) { @@ -806,16 +806,16 @@ class Rijndael extends BlockCipher /** * Setup the performance-optimized function for de/encrypt() * - * @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt() + * @see \phpseclib\Crypt\Common\SymmetricKey::setupInlineCrypt() * @access private */ - function _setupInlineCrypt() + protected function setupInlineCrypt() { // Note: _setupInlineCrypt() will be called only if $this->changed === true // So here we are'nt under the same heavy timing-stress as we are in _de/encryptBlock() or de/encrypt(). // However...the here generated function- $code, stored as php callback in $this->inline_crypt, must work as fast as even possible. - $lambda_functions =& self::_getLambdaFunctions(); + $lambda_functions =& self::getLambdaFunctions(); // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function. // (Currently, for Crypt_Rijndael/AES, one generated $lambda_function cost on php5.5@32bit ~80kb unfreeable mem and ~130kb on php5.5@64bit) @@ -825,7 +825,7 @@ class Rijndael extends BlockCipher // Generation of a uniqe hash for our generated code $code_hash = "Crypt_Rijndael, {$this->mode}, {$this->Nr}, {$this->Nb}"; if ($gen_hi_opt_code) { - $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); + $code_hash = str_pad($code_hash, 32) . $this->hashInlineCryptFunction($this->key); } if (!isset($lambda_functions[$code_hash])) { @@ -842,8 +842,8 @@ class Rijndael extends BlockCipher $w[] = '$w[' . $i . ']'; $dw[] = '$dw[' . $i . ']'; } - $init_encrypt = '$w = $self->w;'; - $init_decrypt = '$dw = $self->dw;'; + $init_encrypt = '$w = $this->w;'; + $init_decrypt = '$dw = $this->dw;'; } $Nr = $this->Nr; @@ -854,7 +854,7 @@ class Rijndael extends BlockCipher $init_encrypt.= ' static $tables; if (empty($tables)) { - $tables = &$self->_getTables(); + $tables = &$this->getTables(); } $t0 = $tables[0]; $t1 = $tables[1]; @@ -911,7 +911,7 @@ class Rijndael extends BlockCipher $init_decrypt.= ' static $invtables; if (empty($invtables)) { - $invtables = &$self->_getInvTables(); + $invtables = &$this->getInvTables(); } $dt0 = $invtables[0]; $dt1 = $invtables[1]; @@ -964,7 +964,7 @@ class Rijndael extends BlockCipher } $decrypt_block .= ');'; - $lambda_functions[$code_hash] = $this->_createInlineCryptFunction( + $lambda_functions[$code_hash] = $this->createInlineCryptFunction( [ 'init_crypt' => '', 'init_encrypt' => $init_encrypt, @@ -974,6 +974,7 @@ class Rijndael extends BlockCipher ] ); } - $this->inline_crypt = $lambda_functions[$code_hash]; + + $this->inline_crypt = \Closure::bind($lambda_functions[$code_hash], $this, $this->getClassContext()); } } diff --git a/phpseclib/Crypt/TripleDES.php b/phpseclib/Crypt/TripleDES.php index e3613b0e..0a73c41c 100644 --- a/phpseclib/Crypt/TripleDES.php +++ b/phpseclib/Crypt/TripleDES.php @@ -66,7 +66,7 @@ class TripleDES extends DES * @var int * @access private */ - var $key_length = 24; + protected $key_length = 24; /** * The default salt used by setPassword() @@ -76,7 +76,7 @@ class TripleDES extends DES * @var string * @access private */ - var $password_default_salt = 'phpseclib'; + protected $password_default_salt = 'phpseclib'; /** * The mcrypt specific name of the cipher @@ -86,7 +86,7 @@ class TripleDES extends DES * @var string * @access private */ - var $cipher_name_mcrypt = 'tripledes'; + protected $cipher_name_mcrypt = 'tripledes'; /** * Optimizing value while CFB-encrypting @@ -95,7 +95,7 @@ class TripleDES extends DES * @var int * @access private */ - var $cfb_init_len = 750; + protected $cfb_init_len = 750; /** * max possible size of $key @@ -105,7 +105,7 @@ class TripleDES extends DES * @var string * @access private */ - var $key_length_max = 24; + protected $key_length_max = 24; /** * Internal flag whether using self::MODE_3CBC or not @@ -113,7 +113,7 @@ class TripleDES extends DES * @var bool * @access private */ - var $mode_3cbc; + private $mode_3cbc; /** * The \phpseclib\Crypt\DES objects @@ -123,7 +123,7 @@ class TripleDES extends DES * @var array * @access private */ - var $des; + private $des; /** * Default Constructor. @@ -149,7 +149,7 @@ class TripleDES extends DES * @param int $mode * @access public */ - function __construct($mode) + public function __construct($mode) { switch ($mode) { // In case of self::MODE_3CBC, we init as CRYPT_DES_MODE_CBC @@ -186,11 +186,11 @@ class TripleDES extends DES * @access public * @return bool */ - function isValidEngine($engine) + public function isValidEngine($engine) { if ($engine == self::ENGINE_OPENSSL) { $this->cipher_name_openssl_ecb = 'des-ede3'; - $mode = $this->_openssl_translate_mode(); + $mode = $this->openssl_translate_mode(); $this->cipher_name_openssl = $mode == 'ecb' ? 'des-ede3' : 'des-ede3-' . $mode; } @@ -206,7 +206,7 @@ class TripleDES extends DES * @access public * @param string $iv */ - function setIV($iv) + public function setIV($iv) { parent::setIV($iv); if ($this->mode_3cbc) { @@ -228,7 +228,7 @@ class TripleDES extends DES * @throws \LengthException if the key length is invalid * @param int $length */ - function setKeyLength($length) + public function setKeyLength($length) { switch ($length) { case 128: @@ -254,7 +254,7 @@ class TripleDES extends DES * @throws \LengthException if the key length is invalid * @param string $key */ - function setKey($key) + public function setKey($key) { if ($this->explicit_key_length !== false && strlen($key) != $this->explicit_key_length) { throw new \LengthException('Key length has already been set to ' . $this->explicit_key_length . ' bytes and this key is ' . strlen($key) . ' bytes'); @@ -273,7 +273,7 @@ class TripleDES extends DES $this->key = $key; $this->key_length = strlen($key); $this->changed = true; - $this->_setEngine(); + $this->setEngine(); if ($this->mode_3cbc) { $this->des[0]->setKey(substr($key, 0, 8)); @@ -290,7 +290,7 @@ class TripleDES extends DES * @param string $plaintext * @return string $cipertext */ - function encrypt($plaintext) + public function encrypt($plaintext) { // parent::en/decrypt() is able to do all the work for all modes and keylengths, // except for: self::MODE_3CBC (inner chaining CBC) with a key > 64bits @@ -300,7 +300,7 @@ class TripleDES extends DES return $this->des[2]->encrypt( $this->des[1]->decrypt( $this->des[0]->encrypt( - $this->_pad($plaintext) + $this->pad($plaintext) ) ) ); @@ -317,10 +317,10 @@ class TripleDES extends DES * @param string $ciphertext * @return string $plaintext */ - function decrypt($ciphertext) + public function decrypt($ciphertext) { if ($this->mode_3cbc && strlen($this->key) > 8) { - return $this->_unpad( + return $this->unpad( $this->des[0]->decrypt( $this->des[1]->encrypt( $this->des[2]->decrypt( @@ -372,7 +372,7 @@ class TripleDES extends DES * @see self::disableContinuousBuffer() * @access public */ - function enableContinuousBuffer() + public function enableContinuousBuffer() { parent::enableContinuousBuffer(); if ($this->mode_3cbc) { @@ -391,7 +391,7 @@ class TripleDES extends DES * @see self::enableContinuousBuffer() * @access public */ - function disableContinuousBuffer() + public function disableContinuousBuffer() { parent::disableContinuousBuffer(); if ($this->mode_3cbc) { @@ -404,11 +404,11 @@ class TripleDES extends DES /** * Creates the key schedule * - * @see \phpseclib\Crypt\DES::_setupKey() - * @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() + * @see \phpseclib\Crypt\DES::setupKey() + * @see \phpseclib\Crypt\Common\SymmetricKey::setupKey() * @access private */ - function _setupKey() + protected function setupKey() { switch (true) { // if $key <= 64bits we configure our internal pure-php cipher engine @@ -423,17 +423,17 @@ class TripleDES extends DES // (only) if 3CBC is used we have, of course, to setup the $des[0-2] keys also separately. if ($this->mode_3cbc) { - $this->des[0]->_setupKey(); - $this->des[1]->_setupKey(); - $this->des[2]->_setupKey(); + $this->des[0]->setupKey(); + $this->des[1]->setupKey(); + $this->des[2]->setupKey(); // because $des[0-2] will, now, do all the work we can return here - // not need unnecessary stress parent::_setupKey() with our, now unused, $key. + // not need unnecessary stress parent::setupKey() with our, now unused, $key. return; } } // setup our key - parent::_setupKey(); + parent::setupKey(); } /** @@ -445,7 +445,7 @@ class TripleDES extends DES * @access public * @return int */ - function setPreferredEngine($engine) + public function setPreferredEngine($engine) { if ($this->mode_3cbc) { $this->des[0]->setPreferredEngine($engine); @@ -455,4 +455,15 @@ class TripleDES extends DES return parent::setPreferredEngine($engine); } + + /** + * Returns the class that defines the private methods + * + * @access private + * @return string + */ + protected function getClassContext() + { + return 'phpseclib\Crypt\DES'; + } } diff --git a/phpseclib/Crypt/Twofish.php b/phpseclib/Crypt/Twofish.php index 61abe728..4a0ba8f4 100644 --- a/phpseclib/Crypt/Twofish.php +++ b/phpseclib/Crypt/Twofish.php @@ -56,7 +56,7 @@ class Twofish extends BlockCipher * @var string * @access private */ - var $cipher_name_mcrypt = 'twofish'; + protected $cipher_name_mcrypt = 'twofish'; /** * Optimizing value while CFB-encrypting @@ -65,7 +65,7 @@ class Twofish extends BlockCipher * @var int * @access private */ - var $cfb_init_len = 800; + protected $cfb_init_len = 800; /** * Q-Table @@ -73,7 +73,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $q0 = [ + private $q0 = [ 0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, 0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38, 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C, @@ -114,7 +114,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $q1 = [ + private $q1 = [ 0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, 0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B, 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1, @@ -155,7 +155,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $m0 = [ + private $m0 = [ 0xBCBC3275, 0xECEC21F3, 0x202043C6, 0xB3B3C9F4, 0xDADA03DB, 0x02028B7B, 0xE2E22BFB, 0x9E9EFAC8, 0xC9C9EC4A, 0xD4D409D3, 0x18186BE6, 0x1E1E9F6B, 0x98980E45, 0xB2B2387D, 0xA6A6D2E8, 0x2626B74B, 0x3C3C57D6, 0x93938A32, 0x8282EED8, 0x525298FD, 0x7B7BD437, 0xBBBB3771, 0x5B5B97F1, 0x474783E1, @@ -196,7 +196,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $m1 = [ + private $m1 = [ 0xA9D93939, 0x67901717, 0xB3719C9C, 0xE8D2A6A6, 0x04050707, 0xFD985252, 0xA3658080, 0x76DFE4E4, 0x9A084545, 0x92024B4B, 0x80A0E0E0, 0x78665A5A, 0xE4DDAFAF, 0xDDB06A6A, 0xD1BF6363, 0x38362A2A, 0x0D54E6E6, 0xC6432020, 0x3562CCCC, 0x98BEF2F2, 0x181E1212, 0xF724EBEB, 0xECD7A1A1, 0x6C774141, @@ -237,7 +237,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $m2 = [ + private $m2 = [ 0xBC75BC32, 0xECF3EC21, 0x20C62043, 0xB3F4B3C9, 0xDADBDA03, 0x027B028B, 0xE2FBE22B, 0x9EC89EFA, 0xC94AC9EC, 0xD4D3D409, 0x18E6186B, 0x1E6B1E9F, 0x9845980E, 0xB27DB238, 0xA6E8A6D2, 0x264B26B7, 0x3CD63C57, 0x9332938A, 0x82D882EE, 0x52FD5298, 0x7B377BD4, 0xBB71BB37, 0x5BF15B97, 0x47E14783, @@ -278,7 +278,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $m3 = [ + private $m3 = [ 0xD939A9D9, 0x90176790, 0x719CB371, 0xD2A6E8D2, 0x05070405, 0x9852FD98, 0x6580A365, 0xDFE476DF, 0x08459A08, 0x024B9202, 0xA0E080A0, 0x665A7866, 0xDDAFE4DD, 0xB06ADDB0, 0xBF63D1BF, 0x362A3836, 0x54E60D54, 0x4320C643, 0x62CC3562, 0xBEF298BE, 0x1E12181E, 0x24EBF724, 0xD7A1ECD7, 0x77416C77, @@ -319,7 +319,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $K = []; + private $K = []; /** * The Key depended S-Table 0 @@ -327,7 +327,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $S0 = []; + private $S0 = []; /** * The Key depended S-Table 1 @@ -335,7 +335,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $S1 = []; + private $S1 = []; /** * The Key depended S-Table 2 @@ -343,7 +343,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $S2 = []; + private $S2 = []; /** * The Key depended S-Table 3 @@ -351,7 +351,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $S3 = []; + private $S3 = []; /** * Holds the last used key @@ -359,7 +359,7 @@ class Twofish extends BlockCipher * @var array * @access private */ - var $kl; + private $kl; /** * The Key Length (in bytes) @@ -368,7 +368,7 @@ class Twofish extends BlockCipher * @var int * @access private */ - var $key_length = 16; + protected $key_length = 16; /** * Default Constructor. @@ -377,7 +377,7 @@ class Twofish extends BlockCipher * @access public * @throws \InvalidArgumentException if an invalid / unsupported mode is provided */ - function __construct($mode) + public function __construct($mode) { if ($mode == self::MODE_STREAM) { throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode'); @@ -394,7 +394,7 @@ class Twofish extends BlockCipher * @access public * @param int $length */ - function setKeyLength($length) + public function setKeyLength($length) { switch ($length) { case 128: @@ -418,7 +418,7 @@ class Twofish extends BlockCipher * @param string $key * @throws \LengthException if the key length isn't supported */ - function setKey($key) + public function setKey($key) { switch (strlen($key)) { case 16: @@ -438,7 +438,7 @@ class Twofish extends BlockCipher * @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() * @access private */ - function _setupKey() + protected function setupKey() { if (isset($this->kl['key']) && $this->key === $this->kl['key']) { // already expanded @@ -460,8 +460,8 @@ class Twofish extends BlockCipher switch (strlen($this->key)) { case 16: - list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[1], $le_longs[2]); - list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[3], $le_longs[4]); + list($s7, $s6, $s5, $s4) = $this->mdsrem($le_longs[1], $le_longs[2]); + list($s3, $s2, $s1, $s0) = $this->mdsrem($le_longs[3], $le_longs[4]); for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { $A = $m0[$q0[$q0[$i] ^ $key[ 9]] ^ $key[1]] ^ $m1[$q0[$q1[$i] ^ $key[10]] ^ $key[2]] ^ @@ -483,9 +483,9 @@ class Twofish extends BlockCipher } break; case 24: - list($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[1], $le_longs[2]); - list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[3], $le_longs[4]); - list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[5], $le_longs[6]); + list($sb, $sa, $s9, $s8) = $this->mdsrem($le_longs[1], $le_longs[2]); + list($s7, $s6, $s5, $s4) = $this->mdsrem($le_longs[3], $le_longs[4]); + list($s3, $s2, $s1, $s0) = $this->mdsrem($le_longs[5], $le_longs[6]); for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { $A = $m0[$q0[$q0[$q1[$i] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^ $m1[$q0[$q1[$q1[$i] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^ @@ -507,10 +507,10 @@ class Twofish extends BlockCipher } break; default: // 32 - list($sf, $se, $sd, $sc) = $this->_mdsrem($le_longs[1], $le_longs[2]); - list($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[3], $le_longs[4]); - list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[5], $le_longs[6]); - list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[7], $le_longs[8]); + list($sf, $se, $sd, $sc) = $this->mdsrem($le_longs[1], $le_longs[2]); + list($sb, $sa, $s9, $s8) = $this->mdsrem($le_longs[3], $le_longs[4]); + list($s7, $s6, $s5, $s4) = $this->mdsrem($le_longs[5], $le_longs[6]); + list($s3, $s2, $s1, $s0) = $this->mdsrem($le_longs[7], $le_longs[8]); for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { $A = $m0[$q0[$q0[$q1[$q1[$i] ^ $key[25]] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^ $m1[$q0[$q1[$q1[$q0[$i] ^ $key[26]] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^ @@ -547,7 +547,7 @@ class Twofish extends BlockCipher * @param string $B * @return array */ - function _mdsrem($A, $B) + private function mdsrem($A, $B) { // No gain by unrolling this loop. for ($i = 0; $i < 8; ++$i) { @@ -594,7 +594,7 @@ class Twofish extends BlockCipher * @param string $in * @return string */ - function _encryptBlock($in) + protected function encryptBlock($in) { $S0 = $this->S0; $S1 = $this->S1; @@ -650,7 +650,7 @@ class Twofish extends BlockCipher * @param string $in * @return string */ - function _decryptBlock($in) + protected function decryptBlock($in) { $S0 = $this->S0; $S1 = $this->S1; @@ -705,9 +705,9 @@ class Twofish extends BlockCipher * @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt() * @access private */ - function _setupInlineCrypt() + protected function setupInlineCrypt() { - $lambda_functions =& self::_getLambdaFunctions(); + $lambda_functions =& self::getLambdaFunctions(); // Max. 10 Ultra-Hi-optimized inline-crypt functions. After that, we'll (still) create very fast code, but not the ultimate fast one. // (Currently, for Crypt_Twofish, one generated $lambda_function cost on php5.5@32bit ~140kb unfreeable mem and ~240kb on php5.5@64bit) @@ -716,7 +716,7 @@ class Twofish extends BlockCipher // Generation of a unique hash for our generated code $code_hash = "Crypt_Twofish, {$this->mode}"; if ($gen_hi_opt_code) { - $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); + $code_hash = str_pad($code_hash, 32) . $this->hashInlineCryptFunction($this->key); } if (!isset($lambda_functions[$code_hash])) { @@ -727,10 +727,10 @@ class Twofish extends BlockCipher static $S0, $S1, $S2, $S3; if (!$S0) { for ($i = 0; $i < 256; ++$i) { - $S0[] = (int)$self->S0[$i]; - $S1[] = (int)$self->S1[$i]; - $S2[] = (int)$self->S2[$i]; - $S3[] = (int)$self->S3[$i]; + $S0[] = (int)$this->S0[$i]; + $S1[] = (int)$this->S1[$i]; + $S2[] = (int)$this->S2[$i]; + $S3[] = (int)$this->S3[$i]; } } '; @@ -741,11 +741,11 @@ class Twofish extends BlockCipher $K[] = '$K_' . $i; } $init_crypt = ' - $S0 = $self->S0; - $S1 = $self->S1; - $S2 = $self->S2; - $S3 = $self->S3; - list(' . implode(',', $K) . ') = $self->K; + $S0 = $this->S0; + $S1 = $this->S1; + $S2 = $this->S2; + $S3 = $this->S3; + list(' . implode(',', $K) . ') = $this->K; '; } @@ -833,7 +833,7 @@ class Twofish extends BlockCipher '.$K[3].' ^ $R1); '; - $lambda_functions[$code_hash] = $this->_createInlineCryptFunction( + $lambda_functions[$code_hash] = $this->createInlineCryptFunction( [ 'init_crypt' => $init_crypt, 'init_encrypt' => '', @@ -843,6 +843,6 @@ class Twofish extends BlockCipher ] ); } - $this->inline_crypt = $lambda_functions[$code_hash]; + $this->inline_crypt = \Closure::bind($lambda_functions[$code_hash], $this, $this->getClassContext()); } } diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 961c9f0c..19079661 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -1630,8 +1630,8 @@ class SSH2 if ($this->crypto_engine) { $this->encrypt->setEngine($this->crypto_engine); } - if ($this->encrypt->block_size) { - $this->encrypt_block_size = $this->encrypt->block_size; + if ($this->encrypt->getBlockLengthInBytes()) { + $this->encrypt_block_size = $this->encrypt->getBlockLengthInBytes(); } $this->encrypt->enableContinuousBuffer(); $this->encrypt->disablePadding(); @@ -1656,8 +1656,8 @@ class SSH2 if ($this->crypto_engine) { $this->decrypt->setEngine($this->crypto_engine); } - if ($this->decrypt->block_size) { - $this->decrypt_block_size = $this->decrypt->block_size; + if ($this->decrypt->getBlockLengthInBytes()) { + $this->decrypt_block_size = $this->decrypt->getBlockLengthInBytes(); } $this->decrypt->enableContinuousBuffer(); $this->decrypt->disablePadding();