Merge pull request #1084 from terrafrost/php5-updates

PHP5 updates for master branch
This commit is contained in:
terrafrost 2017-02-02 21:03:07 -05:00 committed by GitHub
commit ab1da5ac1f
148 changed files with 3108 additions and 3224 deletions

View File

@ -0,0 +1,75 @@
<?php
/**
* Common Object Functions
*
* PHP version 5
*
* @category Common
* @package Functions\Objects
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
namespace phpseclib\Common\Functions;
/**
* Common Object Functions
*
* @package Functions\Objects
* @author Jim Wigginton <terrafrost@php.net>
*/
abstract class Objects
{
/**
* Accesses a private variable from an object
*
* @param Object $obj
* @param string $var
* @return mixed
* @access public
*/
public static function getVar($obj, $var)
{
$reflection = new \ReflectionClass(get_class($obj));
$prop = $reflection->getProperty($var);
$prop->setAccessible(true);
return $prop->getValue($obj);
}
/**
* Sets the value of a private variable in an object
*
* @param Object $obj
* @param string $var
* @param mixed $val
* @return mixed
* @access public
*/
public static function setVar($obj, $var, $val)
{
$reflection = new \ReflectionClass(get_class($obj));
$prop = $reflection->getProperty($var);
$prop->setAccessible(true);
return $prop->setValue($obj, $val);
}
/**
* Accesses a private method from an object
*
* @param Object $obj
* @param string $func
* @param array $params
* @return mixed
* @access public
*/
public static function callFunc($obj, $func, $params = array())
{
$reflection = new \ReflectionClass(get_class($obj));
$method = $reflection->getMethod($func);
$method->setAccessible(true);
return $method->invokeArgs($obj, $params);
}
}

View File

@ -21,7 +21,7 @@ namespace phpseclib\Common\Functions;
* @package Functions\Strings * @package Functions\Strings
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
*/ */
class Strings abstract class Strings
{ {
/** /**
* String Shift * String Shift
@ -33,10 +33,27 @@ class Strings
* @access public * @access public
* @return string * @return string
*/ */
static function shift(&$string, $index = 1) public static function shift(&$string, $index = 1)
{ {
$substr = substr($string, 0, $index); $substr = substr($string, 0, $index);
$string = substr($string, $index); $string = substr($string, $index);
return $substr; 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;
}
} }

View File

@ -68,7 +68,7 @@ class AES extends Rijndael
* @param int $length * @param int $length
* @throws \BadMethodCallException anytime it's called * @throws \BadMethodCallException anytime it's called
*/ */
function setBlockLength($length) public function setBlockLength($length)
{ {
throw new \BadMethodCallException('The block length cannot be set for AES.'); throw new \BadMethodCallException('The block length cannot be set for AES.');
} }
@ -83,7 +83,7 @@ class AES extends Rijndael
* @param int $length * @param int $length
* @throws \LengthException if the key length isn't supported * @throws \LengthException if the key length isn't supported
*/ */
function setKeyLength($length) public function setKeyLength($length)
{ {
switch ($length) { switch ($length) {
case 128: case 128:
@ -107,7 +107,7 @@ class AES extends Rijndael
* @param string $key * @param string $key
* @throws \LengthException if the key length isn't supported * @throws \LengthException if the key length isn't supported
*/ */
function setKey($key) public function setKey($key)
{ {
switch (strlen($key)) { switch (strlen($key)) {
case 16: case 16:
@ -120,4 +120,15 @@ class AES extends Rijndael
parent::setKey($key); parent::setKey($key);
} }
/**
* Returns the class that defines the private methods
*
* @access private
* @return string
*/
protected function getClassContext()
{
return 'phpseclib\Crypt\Rijndael';
}
} }

View File

@ -56,7 +56,7 @@ class Blowfish extends BlockCipher
* @var int * @var int
* @access private * @access private
*/ */
var $block_size = 8; protected $block_size = 8;
/** /**
* The mcrypt specific name of the cipher * The mcrypt specific name of the cipher
@ -65,7 +65,7 @@ class Blowfish extends BlockCipher
* @var string * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'blowfish'; protected $cipher_name_mcrypt = 'blowfish';
/** /**
* Optimizing value while CFB-encrypting * Optimizing value while CFB-encrypting
@ -74,7 +74,7 @@ class Blowfish extends BlockCipher
* @var int * @var int
* @access private * @access private
*/ */
var $cfb_init_len = 500; protected $cfb_init_len = 500;
/** /**
* The fixed subkeys boxes ($sbox0 - $sbox3) with 256 entries each * The fixed subkeys boxes ($sbox0 - $sbox3) with 256 entries each
@ -84,7 +84,7 @@ class Blowfish extends BlockCipher
* @access private * @access private
* @var array * @var array
*/ */
var $sbox0 = array( private $sbox0 = [
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
@ -117,7 +117,7 @@ class Blowfish extends BlockCipher
0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
); ];
/** /**
* S-Box 1 * S-Box 1
@ -125,7 +125,7 @@ class Blowfish extends BlockCipher
* @access private * @access private
* @var array * @var array
*/ */
var $sbox1 = array( private $sbox1 = [
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
@ -158,7 +158,7 @@ class Blowfish extends BlockCipher
0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
); ];
/** /**
* S-Box 2 * S-Box 2
@ -166,7 +166,7 @@ class Blowfish extends BlockCipher
* @access private * @access private
* @var array * @var array
*/ */
var $sbox2 = array( private $sbox2 = [
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
@ -199,7 +199,7 @@ class Blowfish extends BlockCipher
0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
); ];
/** /**
* S-Box 3 * S-Box 3
@ -207,7 +207,7 @@ class Blowfish extends BlockCipher
* @access private * @access private
* @var array * @var array
*/ */
var $sbox3 = array( private $sbox3 = [
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
@ -240,7 +240,7 @@ class Blowfish extends BlockCipher
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
); ];
/** /**
* P-Array consists of 18 32-bit subkeys * P-Array consists of 18 32-bit subkeys
@ -248,11 +248,11 @@ class Blowfish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $parray = array( private $parray = [
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0,
0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b
); ];
/** /**
* The BCTX-working Array * The BCTX-working Array
@ -262,7 +262,7 @@ class Blowfish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $bctx; private $bctx;
/** /**
* Holds the last used key * Holds the last used key
@ -270,7 +270,7 @@ class Blowfish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $kl; private $kl;
/** /**
* The Key Length (in bytes) * 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 * 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. * of that, we'll just precompute it once.
*/ */
var $key_length = 16; protected $key_length = 16;
/** /**
* Default Constructor. * Default Constructor.
@ -292,7 +292,7 @@ class Blowfish extends BlockCipher
* @access public * @access public
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided * @throws \InvalidArgumentException if an invalid / unsupported mode is provided
*/ */
function __construct($mode) public function __construct($mode)
{ {
if ($mode == self::MODE_STREAM) { if ($mode == self::MODE_STREAM) {
throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode'); throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode');
@ -309,7 +309,7 @@ class Blowfish extends BlockCipher
* @access public * @access public
* @param int $length * @param int $length
*/ */
function setKeyLength($length) public function setKeyLength($length)
{ {
if ($length < 32 || $length > 448) { 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'); 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 * @access public
* @return bool * @return bool
*/ */
function isValidEngine($engine) public function isValidEngine($engine)
{ {
if ($engine == self::ENGINE_OPENSSL) { if ($engine == self::ENGINE_OPENSSL) {
if ($this->key_length < 16) { if ($this->key_length < 16) {
return false; return false;
} }
$this->cipher_name_openssl_ecb = 'bf-ecb'; $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); return parent::isValidEngine($engine);
@ -349,24 +349,24 @@ class Blowfish extends BlockCipher
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() * @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey()
* @access private * @access private
*/ */
function _setupKey() protected function setupKey()
{ {
if (isset($this->kl['key']) && $this->key === $this->kl['key']) { if (isset($this->kl['key']) && $this->key === $this->kl['key']) {
// already expanded // already expanded
return; return;
} }
$this->kl = array('key' => $this->key); $this->kl = ['key' => $this->key];
/* key-expanding p[] and S-Box building sb[] */ /* key-expanding p[] and S-Box building sb[] */
$this->bctx = array( $this->bctx = [
'p' => array(), 'p' => [],
'sb' => array( 'sb' => [
$this->sbox0, $this->sbox0,
$this->sbox1, $this->sbox1,
$this->sbox2, $this->sbox2,
$this->sbox3 $this->sbox3
) ]
); ];
// unpack binary string in unsigned chars // unpack binary string in unsigned chars
$key = array_values(unpack('C*', $this->key)); $key = array_values(unpack('C*', $this->key));
@ -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 // 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"; $data = "\0\0\0\0\0\0\0\0";
for ($i = 0; $i < 18; $i += 2) { 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 ] = $l;
$this->bctx['p'][$i + 1] = $r; $this->bctx['p'][$i + 1] = $r;
} }
for ($i = 0; $i < 4; ++$i) { for ($i = 0; $i < 4; ++$i) {
for ($j = 0; $j < 256; $j += 2) { 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 ] = $l;
$this->bctx['sb'][$i][$j + 1] = $r; $this->bctx['sb'][$i][$j + 1] = $r;
} }
@ -406,7 +406,7 @@ class Blowfish extends BlockCipher
* @param string $in * @param string $in
* @return string * @return string
*/ */
function _encryptBlock($in) protected function encryptBlock($in)
{ {
$p = $this->bctx["p"]; $p = $this->bctx["p"];
// extract($this->bctx["sb"], EXTR_PREFIX_ALL, "sb"); // slower // extract($this->bctx["sb"], EXTR_PREFIX_ALL, "sb"); // slower
@ -442,7 +442,7 @@ class Blowfish extends BlockCipher
* @param string $in * @param string $in
* @return string * @return string
*/ */
function _decryptBlock($in) protected function decryptBlock($in)
{ {
$p = $this->bctx["p"]; $p = $this->bctx["p"];
$sb_0 = $this->bctx["sb"][0]; $sb_0 = $this->bctx["sb"][0];
@ -476,115 +476,84 @@ class Blowfish extends BlockCipher
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt() * @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt()
* @access private * @access private
*/ */
function _setupInlineCrypt() protected function setupInlineCrypt()
{ {
$lambda_functions =& self::_getLambdaFunctions(); $p = $this->bctx['p'];
$init_crypt = '
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function. static $sb_0, $sb_1, $sb_2, $sb_3;
// (Currently, for Blowfish, one generated $lambda_function cost on php5.5@32bit ~100kb unfreeable mem and ~180kb on php5.5@64bit) if (!$sb_0) {
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one. $sb_0 = $this->bctx["sb"][0];
$gen_hi_opt_code = (bool)(count($lambda_functions) < 10); $sb_1 = $this->bctx["sb"][1];
$sb_2 = $this->bctx["sb"][2];
// Generation of a unique hash for our generated code $sb_3 = $this->bctx["sb"][3];
$code_hash = "Crypt_Blowfish, {$this->mode}";
if ($gen_hi_opt_code) {
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
}
if (!isset($lambda_functions[$code_hash])) {
switch (true) {
case $gen_hi_opt_code:
$p = $this->bctx['p'];
$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];
}
';
break;
default:
$p = array();
for ($i = 0; $i < 18; ++$i) {
$p[] = '$p_' . $i;
}
$init_crypt = '
list($sb_0, $sb_1, $sb_2, $sb_3) = $self->bctx["sb"];
list(' . implode(',', $p) . ') = $self->bctx["p"];
';
} }
';
// Generating encrypt code: // Generating encrypt code:
$encrypt_block = ' $encrypt_block = '
$in = unpack("N*", $in); $in = unpack("N*", $in);
$l = $in[1]; $l = $in[1];
$r = $in[2]; $r = $in[2];
'; ';
for ($i = 0; $i < 16; $i+= 2) { for ($i = 0; $i < 16; $i+= 2) {
$encrypt_block.= '
$l^= ' . $p[$i] . ';
$r^= ($sb_0[$l >> 24 & 0xff] +
$sb_1[$l >> 16 & 0xff] ^
$sb_2[$l >> 8 & 0xff]) +
$sb_3[$l & 0xff];
$r^= ' . $p[$i + 1] . ';
$l^= ($sb_0[$r >> 24 & 0xff] +
$sb_1[$r >> 16 & 0xff] ^
$sb_2[$r >> 8 & 0xff]) +
$sb_3[$r & 0xff];
';
}
$encrypt_block.= ' $encrypt_block.= '
$in = pack("N*", $l^= ' . $p[$i] . ';
$r ^ ' . $p[17] . ', $r^= ($sb_0[$l >> 24 & 0xff] +
$l ^ ' . $p[16] . ' $sb_1[$l >> 16 & 0xff] ^
); $sb_2[$l >> 8 & 0xff]) +
$sb_3[$l & 0xff];
$r^= ' . $p[$i + 1] . ';
$l^= ($sb_0[$r >> 24 & 0xff] +
$sb_1[$r >> 16 & 0xff] ^
$sb_2[$r >> 8 & 0xff]) +
$sb_3[$r & 0xff];
'; ';
// Generating decrypt code:
$decrypt_block = '
$in = unpack("N*", $in);
$l = $in[1];
$r = $in[2];
';
for ($i = 17; $i > 2; $i-= 2) {
$decrypt_block.= '
$l^= ' . $p[$i] . ';
$r^= ($sb_0[$l >> 24 & 0xff] +
$sb_1[$l >> 16 & 0xff] ^
$sb_2[$l >> 8 & 0xff]) +
$sb_3[$l & 0xff];
$r^= ' . $p[$i - 1] . ';
$l^= ($sb_0[$r >> 24 & 0xff] +
$sb_1[$r >> 16 & 0xff] ^
$sb_2[$r >> 8 & 0xff]) +
$sb_3[$r & 0xff];
';
}
$decrypt_block.= '
$in = pack("N*",
$r ^ ' . $p[0] . ',
$l ^ ' . $p[1] . '
);
';
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
array(
'init_crypt' => $init_crypt,
'init_encrypt' => '',
'init_decrypt' => '',
'encrypt_block' => $encrypt_block,
'decrypt_block' => $decrypt_block
)
);
} }
$this->inline_crypt = $lambda_functions[$code_hash]; $encrypt_block.= '
$in = pack("N*",
$r ^ ' . $p[17] . ',
$l ^ ' . $p[16] . '
);
';
// Generating decrypt code:
$decrypt_block = '
$in = unpack("N*", $in);
$l = $in[1];
$r = $in[2];
';
for ($i = 17; $i > 2; $i-= 2) {
$decrypt_block.= '
$l^= ' . $p[$i] . ';
$r^= ($sb_0[$l >> 24 & 0xff] +
$sb_1[$l >> 16 & 0xff] ^
$sb_2[$l >> 8 & 0xff]) +
$sb_3[$l & 0xff];
$r^= ' . $p[$i - 1] . ';
$l^= ($sb_0[$r >> 24 & 0xff] +
$sb_1[$r >> 16 & 0xff] ^
$sb_2[$r >> 8 & 0xff]) +
$sb_3[$r & 0xff];
';
}
$decrypt_block.= '
$in = pack("N*",
$r ^ ' . $p[0] . ',
$l ^ ' . $p[1] . '
);
';
$this->inline_crypt = $this->createInlineCryptFunction(
[
'init_crypt' => $init_crypt,
'init_encrypt' => '',
'init_decrypt' => '',
'encrypt_block' => $encrypt_block,
'decrypt_block' => $decrypt_block
]
);
} }
} }

View File

@ -44,14 +44,14 @@ abstract class PKCS
* @access private * @access private
* @param int * @param int
*/ */
static $format = self::MODE_ANY; protected static $format = self::MODE_ANY;
/** /**
* Require base64-encoded PEM's be supplied * Require base64-encoded PEM's be supplied
* *
* @access public * @access public
*/ */
static function requirePEM() public static function requirePEM()
{ {
self::$format = self::MODE_PEM; self::$format = self::MODE_PEM;
} }
@ -61,7 +61,7 @@ abstract class PKCS
* *
* @access public * @access public
*/ */
static function requireDER() public static function requireDER()
{ {
self::$format = self::MODE_DER; self::$format = self::MODE_DER;
} }
@ -73,7 +73,7 @@ abstract class PKCS
* *
* @access public * @access public
*/ */
static function requireAny() public static function requireAny()
{ {
self::$format = self::MODE_ANY; self::$format = self::MODE_ANY;
} }

View File

@ -40,7 +40,7 @@ abstract class PKCS1 extends PKCS
* @var string * @var string
* @access private * @access private
*/ */
static $defaultEncryptionAlgorithm = 'AES-128-CBC'; private static $defaultEncryptionAlgorithm = 'AES-128-CBC';
/** /**
* Sets the default encryption algorithm * Sets the default encryption algorithm
@ -48,7 +48,7 @@ abstract class PKCS1 extends PKCS
* @access public * @access public
* @param string $algo * @param string $algo
*/ */
static function setEncryptionAlgorithm($algo) public static function setEncryptionAlgorithm($algo)
{ {
self::$defaultEncryptionAlgorithm = $algo; self::$defaultEncryptionAlgorithm = $algo;
} }
@ -61,7 +61,7 @@ abstract class PKCS1 extends PKCS
* @return int * @return int
* @throws \UnexpectedValueException if the block cipher mode is unsupported * @throws \UnexpectedValueException if the block cipher mode is unsupported
*/ */
static function getEncryptionMode($mode) private static function getEncryptionMode($mode)
{ {
switch ($mode) { switch ($mode) {
case 'CBC': case 'CBC':
@ -86,7 +86,7 @@ abstract class PKCS1 extends PKCS
* @return string * @return string
* @throws \UnexpectedValueException if the encryption algorithm is unsupported * @throws \UnexpectedValueException if the encryption algorithm is unsupported
*/ */
static function getEncryptionObject($algo) private static function getEncryptionObject($algo)
{ {
$modes = '(CBC|ECB|CFB|OFB|CTR)'; $modes = '(CBC|ECB|CFB|OFB|CTR)';
switch (true) { switch (true) {
@ -112,7 +112,7 @@ abstract class PKCS1 extends PKCS
* @param int $length * @param int $length
* @return string * @return string
*/ */
static function generateSymmetricKey($password, $iv, $length) private static function generateSymmetricKey($password, $iv, $length)
{ {
$symkey = ''; $symkey = '';
$iv = substr($iv, 0, 8); $iv = substr($iv, 0, 8);
@ -130,7 +130,7 @@ abstract class PKCS1 extends PKCS
* @param string $password optional * @param string $password optional
* @return array * @return array
*/ */
static function load($key, $password) protected static function load($key, $password)
{ {
if (!is_string($key)) { if (!is_string($key)) {
return false; return false;
@ -186,7 +186,7 @@ abstract class PKCS1 extends PKCS
* @param string $password * @param string $password
* @return string * @return string
*/ */
static function wrapPrivateKey($key, $type, $password) protected static function wrapPrivateKey($key, $type, $password)
{ {
if (empty($password) || !is_string($password)) { if (empty($password) || !is_string($password)) {
return "-----BEGIN $type PRIVATE KEY-----\r\n" . return "-----BEGIN $type PRIVATE KEY-----\r\n" .
@ -215,7 +215,7 @@ abstract class PKCS1 extends PKCS
* @param string $type * @param string $type
* @return string * @return string
*/ */
static function wrapPublicKey($key, $type) protected static function wrapPublicKey($key, $type)
{ {
return "-----BEGIN $type PUBLIC KEY-----\r\n" . return "-----BEGIN $type PUBLIC KEY-----\r\n" .
chunk_split(Base64::encode($key), 64) . chunk_split(Base64::encode($key), 64) .

View File

@ -47,7 +47,7 @@ use phpseclib\Exception\UnsupportedAlgorithmException;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PKCS8 extends PKCS abstract class PKCS8 extends PKCS
{ {
/** /**
* Default encryption algorithm * Default encryption algorithm
@ -55,7 +55,7 @@ class PKCS8 extends PKCS
* @var string * @var string
* @access private * @access private
*/ */
static $defaultEncryptionAlgorithm = 'id-PBES2'; private static $defaultEncryptionAlgorithm = 'id-PBES2';
/** /**
* Default encryption scheme * Default encryption scheme
@ -65,7 +65,7 @@ class PKCS8 extends PKCS
* @var string * @var string
* @access private * @access private
*/ */
static $defaultEncryptionScheme = 'aes128-CBC-PAD'; private static $defaultEncryptionScheme = 'aes128-CBC-PAD';
/** /**
* Default PRF * Default PRF
@ -75,7 +75,7 @@ class PKCS8 extends PKCS
* @var string * @var string
* @access private * @access private
*/ */
static $defaultPRF = 'id-hmacWithSHA256'; private static $defaultPRF = 'id-hmacWithSHA256';
/** /**
* Default Iteration Count * Default Iteration Count
@ -83,7 +83,7 @@ class PKCS8 extends PKCS
* @var int * @var int
* @access private * @access private
*/ */
static $defaultIterationCount = 2048; private static $defaultIterationCount = 2048;
/** /**
* OIDs loaded * OIDs loaded
@ -91,7 +91,7 @@ class PKCS8 extends PKCS
* @var bool * @var bool
* @access private * @access private
*/ */
static $oidsLoaded = false; private static $oidsLoaded = false;
/** /**
* Sets the default encryption algorithm * Sets the default encryption algorithm
@ -99,7 +99,7 @@ class PKCS8 extends PKCS
* @access public * @access public
* @param string $algo * @param string $algo
*/ */
static function setEncryptionAlgorithm($algo) public static function setEncryptionAlgorithm($algo)
{ {
self::$defaultEncryptionAlgorithm = $algo; self::$defaultEncryptionAlgorithm = $algo;
} }
@ -110,7 +110,7 @@ class PKCS8 extends PKCS
* @access public * @access public
* @param string $algo * @param string $algo
*/ */
static function setEncryptionScheme($algo) public static function setEncryptionScheme($algo)
{ {
self::$defaultEncryptionScheme = $algo; self::$defaultEncryptionScheme = $algo;
} }
@ -121,7 +121,7 @@ class PKCS8 extends PKCS
* @access public * @access public
* @param int $count * @param int $count
*/ */
static function setIterationCount($count) public static function setIterationCount($count)
{ {
self::$defaultIterationCount = $count; self::$defaultIterationCount = $count;
} }
@ -132,7 +132,7 @@ class PKCS8 extends PKCS
* @access public * @access public
* @param string $algo * @param string $algo
*/ */
static function setPRF($algo) public static function setPRF($algo)
{ {
self::$defaultPRF = $algo; self::$defaultPRF = $algo;
} }
@ -143,7 +143,7 @@ class PKCS8 extends PKCS
* @access public * @access public
* @param string $algo * @param string $algo
*/ */
static function getPBES1EncryptionObject($algo) private static function getPBES1EncryptionObject($algo)
{ {
$algo = preg_match('#^pbeWith(?:MD2|MD5|SHA1|SHA)And(.*?)-CBC$#', $algo, $matches) ? $algo = preg_match('#^pbeWith(?:MD2|MD5|SHA1|SHA)And(.*?)-CBC$#', $algo, $matches) ?
$matches[1] : $matches[1] :
@ -192,7 +192,7 @@ class PKCS8 extends PKCS
* @access public * @access public
* @param string $algo * @param string $algo
*/ */
static function getPBES1Hash($algo) private static function getPBES1Hash($algo)
{ {
if (preg_match('#^pbeWith(MD2|MD5|SHA1|SHA)And.*?-CBC$#', $algo, $matches)) { if (preg_match('#^pbeWith(MD2|MD5|SHA1|SHA)And.*?-CBC$#', $algo, $matches)) {
return $matches[1] == 'SHA' ? 'sha1' : $matches[1]; return $matches[1] == 'SHA' ? 'sha1' : $matches[1];
@ -207,7 +207,7 @@ class PKCS8 extends PKCS
* @access public * @access public
* @param string $algo * @param string $algo
*/ */
static function getPBES1KDF($algo) private static function getPBES1KDF($algo)
{ {
switch ($algo) { switch ($algo) {
case 'pbeWithMD2AndDES-CBC': case 'pbeWithMD2AndDES-CBC':
@ -228,7 +228,7 @@ class PKCS8 extends PKCS
* @access public * @access public
* @param string $algo * @param string $algo
*/ */
static function getPBES2EncryptionObject($algo) private static function getPBES2EncryptionObject($algo)
{ {
switch ($algo) { switch ($algo) {
case 'desCBC': case 'desCBC':
@ -262,7 +262,7 @@ class PKCS8 extends PKCS
* *
* @access private * @access private
*/ */
static function _initialize_static_variables() private static function initialize_static_variables()
{ {
if (!self::$oidsLoaded) { if (!self::$oidsLoaded) {
// from https://tools.ietf.org/html/rfc2898 // from https://tools.ietf.org/html/rfc2898
@ -318,9 +318,9 @@ class PKCS8 extends PKCS
* @param string $password optional * @param string $password optional
* @return array * @return array
*/ */
static function load($key, $password = '') protected static function load($key, $password = '')
{ {
self::_initialize_static_variables(); self::initialize_static_variables();
if (!is_string($key)) { if (!is_string($key)) {
return false; return false;
@ -482,9 +482,9 @@ class PKCS8 extends PKCS
* @param string $password * @param string $password
* @return string * @return string
*/ */
static function wrapPrivateKey($key, $algorithm, $attr, $password) protected static function wrapPrivateKey($key, $algorithm, $attr, $password)
{ {
self::_initialize_static_variables(); self::initialize_static_variables();
$key = [ $key = [
'version' => 'v1', 'version' => 'v1',
@ -577,9 +577,9 @@ class PKCS8 extends PKCS
* @param string $key * @param string $key
* @return string * @return string
*/ */
static function wrapPublicKey($key, $algorithm) protected static function wrapPublicKey($key, $algorithm)
{ {
self::_initialize_static_variables(); self::initialize_static_variables();
$key = [ $key = [
'publicKeyAlgorithm' => [ 'publicKeyAlgorithm' => [

File diff suppressed because it is too large Load Diff

View File

@ -55,8 +55,8 @@ class DES extends BlockCipher
{ {
/**#@+ /**#@+
* @access private * @access private
* @see \phpseclib\Crypt\DES::_setupKey() * @see \phpseclib\Crypt\DES::setupKey()
* @see \phpseclib\Crypt\DES::_processBlock() * @see \phpseclib\Crypt\DES::processBlock()
*/ */
/** /**
* Contains $keys[self::ENCRYPT] * Contains $keys[self::ENCRYPT]
@ -75,7 +75,7 @@ class DES extends BlockCipher
* @var int * @var int
* @access private * @access private
*/ */
var $block_size = 8; protected $block_size = 8;
/** /**
* Key Length (in bytes) * Key Length (in bytes)
@ -84,7 +84,7 @@ class DES extends BlockCipher
* @var int * @var int
* @access private * @access private
*/ */
var $key_length = 8; protected $key_length = 8;
/** /**
* The mcrypt specific name of the cipher * The mcrypt specific name of the cipher
@ -93,7 +93,7 @@ class DES extends BlockCipher
* @var string * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'des'; protected $cipher_name_mcrypt = 'des';
/** /**
* The OpenSSL names of the cipher / modes * The OpenSSL names of the cipher / modes
@ -102,13 +102,13 @@ class DES extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $openssl_mode_names = array( protected $openssl_mode_names = [
self::MODE_ECB => 'des-ecb', self::MODE_ECB => 'des-ecb',
self::MODE_CBC => 'des-cbc', self::MODE_CBC => 'des-cbc',
self::MODE_CFB => 'des-cfb', self::MODE_CFB => 'des-cfb',
self::MODE_OFB => 'des-ofb' self::MODE_OFB => 'des-ofb'
// self::MODE_CTR is undefined for DES // self::MODE_CTR is undefined for DES
); ];
/** /**
* Optimizing value while CFB-encrypting * Optimizing value while CFB-encrypting
@ -117,19 +117,19 @@ class DES extends BlockCipher
* @var int * @var int
* @access private * @access private
*/ */
var $cfb_init_len = 500; protected $cfb_init_len = 500;
/** /**
* Switch for DES/3DES encryption * Switch for DES/3DES encryption
* *
* Used only if $engine == self::ENGINE_INTERNAL * Used only if $engine == self::ENGINE_INTERNAL
* *
* @see self::_setupKey() * @see self::setupKey()
* @see self::_processBlock() * @see self::processBlock()
* @var int * @var int
* @access private * @access private
*/ */
var $des_rounds = 1; protected $des_rounds = 1;
/** /**
* max possible size of $key * max possible size of $key
@ -138,16 +138,16 @@ class DES extends BlockCipher
* @var string * @var string
* @access private * @access private
*/ */
var $key_length_max = 8; protected $key_length_max = 8;
/** /**
* The Key Schedule * The Key Schedule
* *
* @see self::_setupKey() * @see self::setupKey()
* @var array * @var array
* @access private * @access private
*/ */
var $keys; private $keys;
/** /**
* Shuffle table. * Shuffle table.
@ -156,12 +156,12 @@ class DES extends BlockCipher
* with each byte containing all bits in the same state as the * with each byte containing all bits in the same state as the
* corresponding bit in the index value. * corresponding bit in the index value.
* *
* @see self::_processBlock() * @see self::processBlock()
* @see self::_setupKey() * @see self::setupKey()
* @var array * @var array
* @access private * @access private
*/ */
var $shuffle = array( private $shuffle = [
"\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\xFF", "\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\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", "\x00\x00\x00\x00\x00\xFF\x00\x00", "\x00\x00\x00\x00\x00\xFF\x00\xFF",
@ -290,7 +290,7 @@ class DES extends BlockCipher
"\xFF\xFF\xFF\xFF\xFF\x00\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF", "\xFF\xFF\xFF\xFF\xFF\x00\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF",
"\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF", "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF",
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00", "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
); ];
/** /**
* IP mapping helper table. * IP mapping helper table.
@ -300,7 +300,7 @@ class DES extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $ipmap = array( private $ipmap = [
0x00, 0x10, 0x01, 0x11, 0x20, 0x30, 0x21, 0x31, 0x00, 0x10, 0x01, 0x11, 0x20, 0x30, 0x21, 0x31,
0x02, 0x12, 0x03, 0x13, 0x22, 0x32, 0x23, 0x33, 0x02, 0x12, 0x03, 0x13, 0x22, 0x32, 0x23, 0x33,
0x40, 0x50, 0x41, 0x51, 0x60, 0x70, 0x61, 0x71, 0x40, 0x50, 0x41, 0x51, 0x60, 0x70, 0x61, 0x71,
@ -333,7 +333,7 @@ class DES extends BlockCipher
0x8E, 0x9E, 0x8F, 0x9F, 0xAE, 0xBE, 0xAF, 0xBF, 0x8E, 0x9E, 0x8F, 0x9F, 0xAE, 0xBE, 0xAF, 0xBF,
0xCC, 0xDC, 0xCD, 0xDD, 0xEC, 0xFC, 0xED, 0xFD, 0xCC, 0xDC, 0xCD, 0xDD, 0xEC, 0xFC, 0xED, 0xFD,
0xCE, 0xDE, 0xCF, 0xDF, 0xEE, 0xFE, 0xEF, 0xFF 0xCE, 0xDE, 0xCF, 0xDF, 0xEE, 0xFE, 0xEF, 0xFF
); ];
/** /**
* Inverse IP mapping helper table. * Inverse IP mapping helper table.
@ -342,7 +342,7 @@ class DES extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $invipmap = array( private $invipmap = [
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
@ -375,7 +375,7 @@ class DES extends BlockCipher
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
); ];
/** /**
* Pre-permuted S-box1 * Pre-permuted S-box1
@ -386,7 +386,7 @@ class DES extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $sbox1 = array( private $sbox1 = [
0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808200, 0x00000000, 0x00008000, 0x00808202,
0x00808002, 0x00008202, 0x00000002, 0x00008000, 0x00808002, 0x00008202, 0x00000002, 0x00008000,
0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00000200, 0x00808200, 0x00808202, 0x00000200,
@ -403,7 +403,7 @@ class DES extends BlockCipher
0x00800002, 0x00000202, 0x00008202, 0x00808200, 0x00800002, 0x00000202, 0x00008202, 0x00808200,
0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00000202, 0x00800200, 0x00800200, 0x00000000,
0x00008002, 0x00008200, 0x00000000, 0x00808002 0x00008002, 0x00008200, 0x00000000, 0x00808002
); ];
/** /**
* Pre-permuted S-box2 * Pre-permuted S-box2
@ -411,7 +411,7 @@ class DES extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $sbox2 = array( private $sbox2 = [
0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x40084010, 0x40004000, 0x00004000, 0x00084010,
0x00080000, 0x00000010, 0x40080010, 0x40004010, 0x00080000, 0x00000010, 0x40080010, 0x40004010,
0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40000010, 0x40084010, 0x40084000, 0x40000000,
@ -428,7 +428,7 @@ class DES extends BlockCipher
0x00080010, 0x40004010, 0x40000010, 0x00080010, 0x00080010, 0x40004010, 0x40000010, 0x00080010,
0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x00084000, 0x00000000, 0x40004000, 0x00004010,
0x40000000, 0x40080010, 0x40084010, 0x00084000 0x40000000, 0x40080010, 0x40084010, 0x00084000
); ];
/** /**
* Pre-permuted S-box3 * Pre-permuted S-box3
@ -436,7 +436,7 @@ class DES extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $sbox3 = array( private $sbox3 = [
0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x00000104, 0x04010100, 0x00000000, 0x04010004,
0x04000100, 0x00000000, 0x00010104, 0x04000100, 0x04000100, 0x00000000, 0x00010104, 0x04000100,
0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x00010004, 0x04000004, 0x04000004, 0x00010000,
@ -453,7 +453,7 @@ class DES extends BlockCipher
0x00000004, 0x00010104, 0x00010100, 0x04000004, 0x00000004, 0x00010104, 0x00010100, 0x04000004,
0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x04010000, 0x04000104, 0x00000104, 0x04010000,
0x00010104, 0x00000004, 0x04010004, 0x00010100 0x00010104, 0x00000004, 0x04010004, 0x00010100
); ];
/** /**
* Pre-permuted S-box4 * Pre-permuted S-box4
@ -461,7 +461,7 @@ class DES extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $sbox4 = array( private $sbox4 = [
0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x80401000, 0x80001040, 0x80001040, 0x00000040,
0x00401040, 0x80400040, 0x80400000, 0x80001000, 0x00401040, 0x80400040, 0x80400000, 0x80001000,
0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x00000000, 0x00401000, 0x00401000, 0x80401040,
@ -478,7 +478,7 @@ class DES extends BlockCipher
0x80400000, 0x80001000, 0x00401040, 0x80400040, 0x80400000, 0x80001000, 0x00401040, 0x80400040,
0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x80001000, 0x00001040, 0x00400000, 0x80401000,
0x00000040, 0x00400000, 0x00001000, 0x00401040 0x00000040, 0x00400000, 0x00001000, 0x00401040
); ];
/** /**
* Pre-permuted S-box5 * Pre-permuted S-box5
@ -486,7 +486,7 @@ class DES extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $sbox5 = array( private $sbox5 = [
0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00000080, 0x01040080, 0x01040000, 0x21000080,
0x00040000, 0x00000080, 0x20000000, 0x01040000, 0x00040000, 0x00000080, 0x20000000, 0x01040000,
0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x20040080, 0x00040000, 0x01000080, 0x20040080,
@ -503,7 +503,7 @@ class DES extends BlockCipher
0x01040000, 0x00000000, 0x20040000, 0x21000000, 0x01040000, 0x00000000, 0x20040000, 0x21000000,
0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00040080, 0x01000080, 0x20000080, 0x00040000,
0x00000000, 0x20040000, 0x01040080, 0x20000080 0x00000000, 0x20040000, 0x01040080, 0x20000080
); ];
/** /**
* Pre-permuted S-box6 * Pre-permuted S-box6
@ -511,7 +511,7 @@ class DES extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $sbox6 = array( private $sbox6 = [
0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10000008, 0x10200000, 0x00002000, 0x10202008,
0x10200000, 0x00000008, 0x10202008, 0x00200000, 0x10200000, 0x00000008, 0x10202008, 0x00200000,
0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x10002000, 0x00202008, 0x00200000, 0x10000008,
@ -528,7 +528,7 @@ class DES extends BlockCipher
0x00000008, 0x00002000, 0x10200000, 0x00202008, 0x00000008, 0x00002000, 0x10200000, 0x00202008,
0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x00002000, 0x00200008, 0x10002008, 0x00000000,
0x10202000, 0x10000000, 0x00200008, 0x10002008 0x10202000, 0x10000000, 0x00200008, 0x10002008
); ];
/** /**
* Pre-permuted S-box7 * Pre-permuted S-box7
@ -536,7 +536,7 @@ class DES extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $sbox7 = array( private $sbox7 = [
0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00100000, 0x02100001, 0x02000401, 0x00000000,
0x00000400, 0x02000401, 0x00100401, 0x02100400, 0x00000400, 0x02000401, 0x00100401, 0x02100400,
0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x02100401, 0x00100000, 0x00000000, 0x02000001,
@ -553,7 +553,7 @@ class DES extends BlockCipher
0x00100400, 0x00000000, 0x00000001, 0x02100401, 0x00100400, 0x00000000, 0x00000001, 0x02100401,
0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x00000000, 0x00100401, 0x02100000, 0x00000400,
0x02000001, 0x02000400, 0x00000400, 0x00100001 0x02000001, 0x02000400, 0x00000400, 0x00100001
); ];
/** /**
* Pre-permuted S-box8 * Pre-permuted S-box8
@ -561,7 +561,7 @@ class DES extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $sbox8 = array( private $sbox8 = [
0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000820, 0x00000800, 0x00020000, 0x08020820,
0x08000000, 0x08000820, 0x00000020, 0x08000000, 0x08000000, 0x08000820, 0x00000020, 0x08000000,
0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x00020020, 0x08020000, 0x08020820, 0x00020800,
@ -578,7 +578,7 @@ class DES extends BlockCipher
0x08020000, 0x08000800, 0x08000820, 0x00000000, 0x08020000, 0x08000800, 0x08000820, 0x00000000,
0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x08020820, 0x00020800, 0x00020800, 0x00000820,
0x00000820, 0x00020020, 0x08000000, 0x08020800 0x00000820, 0x00020020, 0x08000000, 0x08020800
); ];
/** /**
* Default Constructor. * Default Constructor.
@ -587,7 +587,7 @@ class DES extends BlockCipher
* @access public * @access public
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided * @throws \InvalidArgumentException if an invalid / unsupported mode is provided
*/ */
function __construct($mode) public function __construct($mode)
{ {
if ($mode == self::MODE_STREAM) { if ($mode == self::MODE_STREAM) {
throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode'); throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode');
@ -606,12 +606,12 @@ class DES extends BlockCipher
* @access public * @access public
* @return bool * @return bool
*/ */
function isValidEngine($engine) public function isValidEngine($engine)
{ {
if ($this->key_length_max == 8) { if ($this->key_length_max == 8) {
if ($engine == self::ENGINE_OPENSSL) { if ($engine == self::ENGINE_OPENSSL) {
$this->cipher_name_openssl_ecb = 'des-ecb'; $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 * @access public
* @param string $key * @param string $key
*/ */
function setKey($key) public function setKey($key)
{ {
if (!($this instanceof TripleDES) && strlen($key) != 8) { 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'); 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 * Encrypts a block
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::_encryptBlock() * @see \phpseclib\Crypt\Common\SymmetricKey::encryptBlock()
* @see \phpseclib\Crypt\Common\SymmetricKey::encrypt() * @see \phpseclib\Crypt\Common\SymmetricKey::encrypt()
* @see self::encrypt() * @see self::encrypt()
* @access private * @access private
* @param string $in * @param string $in
* @return string * @return string
*/ */
function _encryptBlock($in) protected function encryptBlock($in)
{ {
return $this->_processBlock($in, self::ENCRYPT); return $this->processBlock($in, self::ENCRYPT);
} }
/** /**
* Decrypts a block * Decrypts a block
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::_decryptBlock() * @see \phpseclib\Crypt\Common\SymmetricKey::decryptBlock()
* @see \phpseclib\Crypt\Common\SymmetricKey::decrypt() * @see \phpseclib\Crypt\Common\SymmetricKey::decrypt()
* @see self::decrypt() * @see self::decrypt()
* @access private * @access private
* @param string $in * @param string $in
* @return string * @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 * {@link http://en.wikipedia.org/wiki/Image:Feistel.png Feistel.png} to get a general
* idea of what this function does. * idea of what this function does.
* *
* @see self::_encryptBlock() * @see self::encryptBlock()
* @see self::_decryptBlock() * @see self::decryptBlock()
* @access private * @access private
* @param string $block * @param string $block
* @param int $mode * @param int $mode
* @return string * @return string
*/ */
function _processBlock($block, $mode) private function processBlock($block, $mode)
{ {
static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip; static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip;
if (!$sbox1) { if (!$sbox1) {
@ -707,7 +707,7 @@ class DES extends BlockCipher
// Do the initial IP permutation. // Do the initial IP permutation.
$t = unpack('Nl/Nr', $block); $t = unpack('Nl/Nr', $block);
list($l, $r) = array($t['l'], $t['r']); list($l, $r) = [$t['l'], $t['r']];
$block = ($shuffleip[ $r & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") | $block = ($shuffleip[ $r & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") | ($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") | ($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
@ -719,7 +719,7 @@ class DES extends BlockCipher
// Extract L0 and R0. // Extract L0 and R0.
$t = unpack('Nl/Nr', $block); $t = unpack('Nl/Nr', $block);
list($l, $r) = array($t['l'], $t['r']); list($l, $r) = [$t['l'], $t['r']];
for ($des_round = 0; $des_round < $this->des_rounds; ++$des_round) { for ($des_round = 0; $des_round < $this->des_rounds; ++$des_round) {
// Perform the 16 steps. // Perform the 16 steps.
@ -761,22 +761,22 @@ class DES extends BlockCipher
/** /**
* Creates the key schedule * Creates the key schedule
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() * @see \phpseclib\Crypt\Common\SymmetricKey::setupKey()
* @access private * @access private
*/ */
function _setupKey() protected function setupKey()
{ {
if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->des_rounds === $this->kl['des_rounds']) { if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->des_rounds === $this->kl['des_rounds']) {
// already expanded // already expanded
return; return;
} }
$this->kl = array('key' => $this->key, 'des_rounds' => $this->des_rounds); $this->kl = ['key' => $this->key, 'des_rounds' => $this->des_rounds];
static $shifts = array( // number of key bits shifted per round static $shifts = [ // number of key bits shifted per round
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
); ];
static $pc1map = array( static $pc1map = [
0x00, 0x00, 0x08, 0x08, 0x04, 0x04, 0x0C, 0x0C, 0x00, 0x00, 0x08, 0x08, 0x04, 0x04, 0x0C, 0x0C,
0x02, 0x02, 0x0A, 0x0A, 0x06, 0x06, 0x0E, 0x0E, 0x02, 0x02, 0x0A, 0x0A, 0x06, 0x06, 0x0E, 0x0E,
0x10, 0x10, 0x18, 0x18, 0x14, 0x14, 0x1C, 0x1C, 0x10, 0x10, 0x18, 0x18, 0x14, 0x14, 0x1C, 0x1C,
@ -809,16 +809,16 @@ class DES extends BlockCipher
0xE2, 0xE2, 0xEA, 0xEA, 0xE6, 0xE6, 0xEE, 0xEE, 0xE2, 0xE2, 0xEA, 0xEA, 0xE6, 0xE6, 0xEE, 0xEE,
0xF0, 0xF0, 0xF8, 0xF8, 0xF4, 0xF4, 0xFC, 0xFC, 0xF0, 0xF0, 0xF8, 0xF8, 0xF4, 0xF4, 0xFC, 0xFC,
0xF2, 0xF2, 0xFA, 0xFA, 0xF6, 0xF6, 0xFE, 0xFE 0xF2, 0xF2, 0xFA, 0xFA, 0xF6, 0xF6, 0xFE, 0xFE
); ];
// Mapping tables for the PC-2 transformation. // Mapping tables for the PC-2 transformation.
static $pc2mapc1 = array( static $pc2mapc1 = [
0x00000000, 0x00000400, 0x00200000, 0x00200400, 0x00000000, 0x00000400, 0x00200000, 0x00200400,
0x00000001, 0x00000401, 0x00200001, 0x00200401, 0x00000001, 0x00000401, 0x00200001, 0x00200401,
0x02000000, 0x02000400, 0x02200000, 0x02200400, 0x02000000, 0x02000400, 0x02200000, 0x02200400,
0x02000001, 0x02000401, 0x02200001, 0x02200401 0x02000001, 0x02000401, 0x02200001, 0x02200401
); ];
static $pc2mapc2 = array( static $pc2mapc2 = [
0x00000000, 0x00000800, 0x08000000, 0x08000800, 0x00000000, 0x00000800, 0x08000000, 0x08000800,
0x00010000, 0x00010800, 0x08010000, 0x08010800, 0x00010000, 0x00010800, 0x08010000, 0x08010800,
0x00000000, 0x00000800, 0x08000000, 0x08000800, 0x00000000, 0x00000800, 0x08000000, 0x08000800,
@ -883,8 +883,8 @@ class DES extends BlockCipher
0x01050110, 0x01050910, 0x09050110, 0x09050910, 0x01050110, 0x01050910, 0x09050110, 0x09050910,
0x01040110, 0x01040910, 0x09040110, 0x09040910, 0x01040110, 0x01040910, 0x09040110, 0x09040910,
0x01050110, 0x01050910, 0x09050110, 0x09050910 0x01050110, 0x01050910, 0x09050110, 0x09050910
); ];
static $pc2mapc3 = array( static $pc2mapc3 = [
0x00000000, 0x00000004, 0x00001000, 0x00001004, 0x00000000, 0x00000004, 0x00001000, 0x00001004,
0x00000000, 0x00000004, 0x00001000, 0x00001004, 0x00000000, 0x00000004, 0x00001000, 0x00001004,
0x10000000, 0x10000004, 0x10001000, 0x10001004, 0x10000000, 0x10000004, 0x10001000, 0x10001004,
@ -949,8 +949,8 @@ class DES extends BlockCipher
0x20080022, 0x20080026, 0x20081022, 0x20081026, 0x20080022, 0x20080026, 0x20081022, 0x20081026,
0x30080022, 0x30080026, 0x30081022, 0x30081026, 0x30080022, 0x30080026, 0x30081022, 0x30081026,
0x30080022, 0x30080026, 0x30081022, 0x30081026 0x30080022, 0x30080026, 0x30081022, 0x30081026
); ];
static $pc2mapc4 = array( static $pc2mapc4 = [
0x00000000, 0x00100000, 0x00000008, 0x00100008, 0x00000000, 0x00100000, 0x00000008, 0x00100008,
0x00000200, 0x00100200, 0x00000208, 0x00100208, 0x00000200, 0x00100200, 0x00000208, 0x00100208,
0x00000000, 0x00100000, 0x00000008, 0x00100008, 0x00000000, 0x00100000, 0x00000008, 0x00100008,
@ -1015,14 +1015,14 @@ class DES extends BlockCipher
0x04022200, 0x04122200, 0x04022208, 0x04122208, 0x04022200, 0x04122200, 0x04022208, 0x04122208,
0x04022000, 0x04122000, 0x04022008, 0x04122008, 0x04022000, 0x04122000, 0x04022008, 0x04122008,
0x04022200, 0x04122200, 0x04022208, 0x04122208 0x04022200, 0x04122200, 0x04022208, 0x04122208
); ];
static $pc2mapd1 = array( static $pc2mapd1 = [
0x00000000, 0x00000001, 0x08000000, 0x08000001, 0x00000000, 0x00000001, 0x08000000, 0x08000001,
0x00200000, 0x00200001, 0x08200000, 0x08200001, 0x00200000, 0x00200001, 0x08200000, 0x08200001,
0x00000002, 0x00000003, 0x08000002, 0x08000003, 0x00000002, 0x00000003, 0x08000002, 0x08000003,
0x00200002, 0x00200003, 0x08200002, 0x08200003 0x00200002, 0x00200003, 0x08200002, 0x08200003
); ];
static $pc2mapd2 = array( static $pc2mapd2 = [
0x00000000, 0x00100000, 0x00000800, 0x00100800, 0x00000000, 0x00100000, 0x00000800, 0x00100800,
0x00000000, 0x00100000, 0x00000800, 0x00100800, 0x00000000, 0x00100000, 0x00000800, 0x00100800,
0x04000000, 0x04100000, 0x04000800, 0x04100800, 0x04000000, 0x04100000, 0x04000800, 0x04100800,
@ -1087,8 +1087,8 @@ class DES extends BlockCipher
0x00020204, 0x00120204, 0x00020A04, 0x00120A04, 0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
0x04020204, 0x04120204, 0x04020A04, 0x04120A04, 0x04020204, 0x04120204, 0x04020A04, 0x04120A04,
0x04020204, 0x04120204, 0x04020A04, 0x04120A04 0x04020204, 0x04120204, 0x04020A04, 0x04120A04
); ];
static $pc2mapd3 = array( static $pc2mapd3 = [
0x00000000, 0x00010000, 0x02000000, 0x02010000, 0x00000000, 0x00010000, 0x02000000, 0x02010000,
0x00000020, 0x00010020, 0x02000020, 0x02010020, 0x00000020, 0x00010020, 0x02000020, 0x02010020,
0x00040000, 0x00050000, 0x02040000, 0x02050000, 0x00040000, 0x00050000, 0x02040000, 0x02050000,
@ -1153,8 +1153,8 @@ class DES extends BlockCipher
0x20002030, 0x20012030, 0x22002030, 0x22012030, 0x20002030, 0x20012030, 0x22002030, 0x22012030,
0x20042010, 0x20052010, 0x22042010, 0x22052010, 0x20042010, 0x20052010, 0x22042010, 0x22052010,
0x20042030, 0x20052030, 0x22042030, 0x22052030 0x20042030, 0x20052030, 0x22042030, 0x22052030
); ];
static $pc2mapd4 = array( static $pc2mapd4 = [
0x00000000, 0x00000400, 0x01000000, 0x01000400, 0x00000000, 0x00000400, 0x01000000, 0x01000400,
0x00000000, 0x00000400, 0x01000000, 0x01000400, 0x00000000, 0x00000400, 0x01000000, 0x01000400,
0x00000100, 0x00000500, 0x01000100, 0x01000500, 0x00000100, 0x00000500, 0x01000100, 0x01000500,
@ -1219,16 +1219,16 @@ class DES extends BlockCipher
0x10081008, 0x10081408, 0x11081008, 0x11081408, 0x10081008, 0x10081408, 0x11081008, 0x11081408,
0x10081108, 0x10081508, 0x11081108, 0x11081508, 0x10081108, 0x10081508, 0x11081108, 0x11081508,
0x10081108, 0x10081508, 0x11081108, 0x11081508 0x10081108, 0x10081508, 0x11081108, 0x11081508
); ];
$keys = array(); $keys = [];
for ($des_round = 0; $des_round < $this->des_rounds; ++$des_round) { for ($des_round = 0; $des_round < $this->des_rounds; ++$des_round) {
// pad the key and remove extra characters as appropriate. // pad the key and remove extra characters as appropriate.
$key = str_pad(substr($this->key, $des_round * 8, 8), 8, "\0"); $key = str_pad(substr($this->key, $des_round * 8, 8), 8, "\0");
// Perform the PC/1 transformation and compute C and D. // Perform the PC/1 transformation and compute C and D.
$t = unpack('Nl/Nr', $key); $t = unpack('Nl/Nr', $key);
list($l, $r) = array($t['l'], $t['r']); list($l, $r) = [$t['l'], $t['r']];
$key = ($this->shuffle[$pc1map[ $r & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x00") | $key = ($this->shuffle[$pc1map[ $r & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x00") |
($this->shuffle[$pc1map[($r >> 8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x00") | ($this->shuffle[$pc1map[($r >> 8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x00") |
($this->shuffle[$pc1map[($r >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x00") | ($this->shuffle[$pc1map[($r >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x00") |
@ -1241,10 +1241,10 @@ class DES extends BlockCipher
$c = ( $key['c'] >> 4) & 0x0FFFFFFF; $c = ( $key['c'] >> 4) & 0x0FFFFFFF;
$d = (($key['d'] >> 4) & 0x0FFFFFF0) | ($key['c'] & 0x0F); $d = (($key['d'] >> 4) & 0x0FFFFFF0) | ($key['c'] & 0x0F);
$keys[$des_round] = array( $keys[$des_round] = [
self::ENCRYPT => array(), self::ENCRYPT => [],
self::DECRYPT => array_fill(0, 32, 0) self::DECRYPT => array_fill(0, 32, 0)
); ];
for ($i = 0, $ki = 31; $i < 16; ++$i, $ki-= 2) { for ($i = 0, $ki = 31; $i < 16; ++$i, $ki-= 2) {
$c <<= $shifts[$i]; $c <<= $shifts[$i];
$c = ($c | ($c >> 28)) & 0x0FFFFFFF; $c = ($c | ($c >> 28)) & 0x0FFFFFFF;
@ -1271,7 +1271,7 @@ class DES extends BlockCipher
switch ($this->des_rounds) { switch ($this->des_rounds) {
case 3: // 3DES keys case 3: // 3DES keys
$this->keys = array( $this->keys = [
self::ENCRYPT => array_merge( self::ENCRYPT => array_merge(
$keys[0][self::ENCRYPT], $keys[0][self::ENCRYPT],
$keys[1][self::DECRYPT], $keys[1][self::DECRYPT],
@ -1282,174 +1282,127 @@ class DES extends BlockCipher
$keys[1][self::ENCRYPT], $keys[1][self::ENCRYPT],
$keys[0][self::DECRYPT] $keys[0][self::DECRYPT]
) )
); ];
break; break;
// case 1: // DES keys // case 1: // DES keys
default: default:
$this->keys = array( $this->keys = [
self::ENCRYPT => $keys[0][self::ENCRYPT], self::ENCRYPT => $keys[0][self::ENCRYPT],
self::DECRYPT => $keys[0][self::DECRYPT] self::DECRYPT => $keys[0][self::DECRYPT]
); ];
} }
} }
/** /**
* Setup the performance-optimized function for de/encrypt() * Setup the performance-optimized function for de/encrypt()
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt() * @see \phpseclib\Crypt\Common\SymmetricKey::setupInlineCrypt()
* @access private * @access private
*/ */
function _setupInlineCrypt() protected function setupInlineCrypt()
{ {
$lambda_functions =& self::_getLambdaFunctions();
// Engine configuration for: // Engine configuration for:
// - DES ($des_rounds == 1) or // - DES ($des_rounds == 1) or
// - 3DES ($des_rounds == 3) // - 3DES ($des_rounds == 3)
$des_rounds = $this->des_rounds; $des_rounds = $this->des_rounds;
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function. $init_crypt = 'static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip;
// (Currently, for DES, one generated $lambda_function cost on php5.5@32bit ~135kb unfreeable mem and ~230kb on php5.5@64bit) if (!$sbox1) {
// (Currently, for TripleDES, one generated $lambda_function cost on php5.5@32bit ~240kb unfreeable mem and ~340kb on php5.5@64bit) $sbox1 = array_map("intval", $this->sbox1);
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one $sbox2 = array_map("intval", $this->sbox2);
$gen_hi_opt_code = (bool)( count($lambda_functions) < 10 ); $sbox3 = array_map("intval", $this->sbox3);
$sbox4 = array_map("intval", $this->sbox4);
// Generation of a unique hash for our generated code $sbox5 = array_map("intval", $this->sbox5);
$code_hash = "Crypt_DES, $des_rounds, {$this->mode}"; $sbox6 = array_map("intval", $this->sbox6);
if ($gen_hi_opt_code) { $sbox7 = array_map("intval", $this->sbox7);
// For hi-optimized code, we create for each combination of $sbox8 = array_map("intval", $this->sbox8);'
// $mode, $des_rounds and $this->key its own encrypt/decrypt function. /* Merge $shuffle with $[inv]ipmap */ . '
// After max 10 hi-optimized functions, we create generic for ($i = 0; $i < 256; ++$i) {
// (still very fast.. but not ultra) functions for each $mode/$des_rounds $shuffleip[] = $this->shuffle[$this->ipmap[$i]];
// Currently 2 * 5 generic functions will be then max. possible. $shuffleinvip[] = $this->shuffle[$this->invipmap[$i]];
$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 = '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);'
/* Merge $shuffle with $[inv]ipmap */ . '
for ($i = 0; $i < 256; ++$i) {
$shuffleip[] = $self->shuffle[$self->ipmap[$i]];
$shuffleinvip[] = $self->shuffle[$self->invipmap[$i]];
}
} }
}
';
$k = [
self::ENCRYPT => $this->keys[self::ENCRYPT],
self::DECRYPT => $this->keys[self::DECRYPT]
];
$init_encrypt = '';
$init_decrypt = '';
// Creating code for en- and decryption.
$crypt_block = [];
foreach ([self::ENCRYPT, self::DECRYPT] as $c) {
/* Do the initial IP permutation. */
$crypt_block[$c] = '
$in = unpack("N*", $in);
$l = $in[1];
$r = $in[2];
$in = unpack("N*",
($shuffleip[ $r & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
($shuffleip[($r >> 24) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
($shuffleip[ $l & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
($shuffleip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
($shuffleip[($l >> 16) & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
($shuffleip[($l >> 24) & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01")
);
' . /* Extract L0 and R0 */ '
$l = $in[1];
$r = $in[2];
'; ';
switch (true) { $l = '$l';
case $gen_hi_opt_code: $r = '$r';
// In Hi-optimized code mode, we use our [3]DES key schedule as hardcoded integers.
// No futher initialisation of the $keys schedule is necessary.
// That is the extra performance boost.
$k = array(
self::ENCRYPT => $this->keys[self::ENCRYPT],
self::DECRYPT => $this->keys[self::DECRYPT]
);
$init_encrypt = '';
$init_decrypt = '';
break;
default:
// In generic optimized code mode, we have to use, as the best compromise [currently],
// our key schedule as $ke/$kd arrays. (with hardcoded indexes...)
$k = array(
self::ENCRYPT => array(),
self::DECRYPT => array()
);
for ($i = 0, $c = count($this->keys[self::ENCRYPT]); $i < $c; ++$i) {
$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];';
break;
}
// Creating code for en- and decryption. // Perform DES or 3DES.
$crypt_block = array(); for ($ki = -1, $des_round = 0; $des_round < $des_rounds; ++$des_round) {
foreach (array(self::ENCRYPT, self::DECRYPT) as $c) { // Perform the 16 steps.
/* Do the initial IP permutation. */ for ($i = 0; $i < 16; ++$i) {
$crypt_block[$c] = ' // start of "the Feistel (F) function" - see the following URL:
$in = unpack("N*", $in); // http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png
$l = $in[1]; // Merge key schedule.
$r = $in[2]; $crypt_block[$c].= '
$in = unpack("N*", $b1 = ((' . $r . ' >> 3) & 0x1FFFFFFF) ^ (' . $r . ' << 29) ^ ' . $k[$c][++$ki] . ';
($shuffleip[ $r & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") | $b2 = ((' . $r . ' >> 31) & 0x00000001) ^ (' . $r . ' << 1) ^ ' . $k[$c][++$ki] . ';' .
($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") | /* S-box indexing. */
($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") | $l . ' = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
($shuffleip[($r >> 24) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") | $sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
($shuffleip[ $l & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") | $sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^
($shuffleip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") | $sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ ' . $l . ';
($shuffleip[($l >> 16) & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") | ';
($shuffleip[($l >> 24) & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01") // end of "the Feistel (F) function"
);
' . /* Extract L0 and R0 */ '
$l = $in[1];
$r = $in[2];
';
$l = '$l'; // swap L & R
$r = '$r'; list($l, $r) = [$r, $l];
// Perform DES or 3DES.
for ($ki = -1, $des_round = 0; $des_round < $des_rounds; ++$des_round) {
// Perform the 16 steps.
for ($i = 0; $i < 16; ++$i) {
// start of "the Feistel (F) function" - see the following URL:
// http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png
// Merge key schedule.
$crypt_block[$c].= '
$b1 = ((' . $r . ' >> 3) & 0x1FFFFFFF) ^ (' . $r . ' << 29) ^ ' . $k[$c][++$ki] . ';
$b2 = ((' . $r . ' >> 31) & 0x00000001) ^ (' . $r . ' << 1) ^ ' . $k[$c][++$ki] . ';' .
/* S-box indexing. */
$l . ' = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
$sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
$sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^
$sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ ' . $l . ';
';
// end of "the Feistel (F) function"
// swap L & R
list($l, $r) = array($r, $l);
}
list($l, $r) = array($r, $l);
} }
list($l, $r) = [$r, $l];
// Perform the inverse IP permutation.
$crypt_block[$c].= '$in =
($shuffleinvip[($l >> 24) & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
($shuffleinvip[($r >> 24) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
($shuffleinvip[($l >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
($shuffleinvip[($r >> 16) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
($shuffleinvip[($l >> 8) & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
($shuffleinvip[($r >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
($shuffleinvip[ $l & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
($shuffleinvip[ $r & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01");
';
} }
// Creates the inline-crypt function // Perform the inverse IP permutation.
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction( $crypt_block[$c].= '$in =
array( ($shuffleinvip[($l >> 24) & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") |
'init_crypt' => $init_crypt, ($shuffleinvip[($r >> 24) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
'init_encrypt' => $init_encrypt, ($shuffleinvip[($l >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
'init_decrypt' => $init_decrypt, ($shuffleinvip[($r >> 16) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") |
'encrypt_block' => $crypt_block[self::ENCRYPT], ($shuffleinvip[($l >> 8) & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") |
'decrypt_block' => $crypt_block[self::DECRYPT] ($shuffleinvip[($r >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") |
) ($shuffleinvip[ $l & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") |
); ($shuffleinvip[ $r & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01");
';
} }
// Set the inline-crypt function as callback in: $this->inline_crypt // Creates the inline-crypt function
$this->inline_crypt = $lambda_functions[$code_hash]; $this->inline_crypt = $this->createInlineCryptFunction(
[
'init_crypt' => $init_crypt,
'init_encrypt' => $init_encrypt,
'init_decrypt' => $init_decrypt,
'encrypt_block' => $crypt_block[self::ENCRYPT],
'decrypt_block' => $crypt_block[self::DECRYPT]
]
);
} }
} }

View File

@ -52,7 +52,7 @@ class Hash
* @var int * @var int
* @access private * @access private
*/ */
var $hashParam; private $hashParam;
/** /**
* Byte-length of hash output (Internal HMAC) * Byte-length of hash output (Internal HMAC)
@ -61,7 +61,7 @@ class Hash
* @var int * @var int
* @access private * @access private
*/ */
var $length; private $length;
/** /**
* Hash Algorithm * Hash Algorithm
@ -70,7 +70,7 @@ class Hash
* @var string * @var string
* @access private * @access private
*/ */
var $hash; private $hash;
/** /**
* Key * Key
@ -79,7 +79,7 @@ class Hash
* @var string * @var string
* @access private * @access private
*/ */
var $key = false; private $key = false;
/** /**
* Initial Hash * Initial Hash
@ -90,7 +90,7 @@ class Hash
* @var array * @var array
* @access private * @access private
*/ */
var $initial = false; private $initial = false;
/** /**
* Outer XOR (Internal HMAC) * Outer XOR (Internal HMAC)
@ -101,7 +101,7 @@ class Hash
* @var string * @var string
* @access private * @access private
*/ */
var $opad; private $opad;
/** /**
* Inner XOR (Internal HMAC) * Inner XOR (Internal HMAC)
@ -112,7 +112,7 @@ class Hash
* @var string * @var string
* @access private * @access private
*/ */
var $ipad; private $ipad;
/** /**
* Default Constructor. * Default Constructor.
@ -120,7 +120,7 @@ class Hash
* @param string $hash * @param string $hash
* @access public * @access public
*/ */
function __construct($hash = 'sha256') public function __construct($hash = 'sha256')
{ {
$this->setHash($hash); $this->setHash($hash);
@ -136,7 +136,7 @@ class Hash
* @access public * @access public
* @param string $key * @param string $key
*/ */
function setKey($key = false) public function setKey($key = false)
{ {
$this->key = $key; $this->key = $key;
} }
@ -149,7 +149,7 @@ class Hash
* @access public * @access public
* @return string * @return string
*/ */
function getHash() public function getHash()
{ {
return $this->hashParam; return $this->hashParam;
} }
@ -160,7 +160,7 @@ class Hash
* @access public * @access public
* @param string $hash * @param string $hash
*/ */
function setHash($hash) public function setHash($hash)
{ {
$this->hashParam = $hash = strtolower($hash); $this->hashParam = $hash = strtolower($hash);
switch ($hash) { switch ($hash) {
@ -223,14 +223,14 @@ class Hash
if ($hash == 'sha512/224' || $hash == 'sha512/256') { if ($hash == 'sha512/224' || $hash == 'sha512/256') {
// from http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf#page=24 // from http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf#page=24
$this->initial = $hash == 'sha512/256' ? $this->initial = $hash == 'sha512/256' ?
array( [
'22312194FC2BF72C', '9F555FA3C84C64C2', '2393B86B6F53B151', '963877195940EABD', '22312194FC2BF72C', '9F555FA3C84C64C2', '2393B86B6F53B151', '963877195940EABD',
'96283EE2A88EFFE3', 'BE5E1E2553863992', '2B0199FC2C85B8AA', '0EB72DDC81C52CA2' '96283EE2A88EFFE3', 'BE5E1E2553863992', '2B0199FC2C85B8AA', '0EB72DDC81C52CA2'
) : ] :
array( [
'8C3D37C819544DA2', '73E1996689DCD4D6', '1DFAB7AE32FF9C82', '679DD514582F9FCF', '8C3D37C819544DA2', '73E1996689DCD4D6', '1DFAB7AE32FF9C82', '679DD514582F9FCF',
'0F6D2B697BD44DA8', '77E36F7304C48942', '3F9D85A86A1D36C8', '1112E6AD91D692A1' '0F6D2B697BD44DA8', '77E36F7304C48942', '3F9D85A86A1D36C8', '1112E6AD91D692A1'
); ];
for ($i = 0; $i < 8; $i++) { for ($i = 0; $i < 8; $i++) {
$this->initial[$i] = new BigInteger($this->initial[$i], 16); $this->initial[$i] = new BigInteger($this->initial[$i], 16);
$this->initial[$i]->setPrecision(64); $this->initial[$i]->setPrecision(64);
@ -247,7 +247,7 @@ class Hash
* @param string $text * @param string $text
* @return string * @return string
*/ */
function hash($text) public function hash($text)
{ {
switch ($this->hash) { switch ($this->hash) {
case 'sha512/224': case 'sha512/224':
@ -286,7 +286,7 @@ class Hash
* @access public * @access public
* @return int * @return int
*/ */
function getLength() public function getLength()
{ {
return $this->length << 3; return $this->length << 3;
} }
@ -297,7 +297,7 @@ class Hash
* @access public * @access public
* @return int * @return int
*/ */
function getLengthInBytes() public function getLengthInBytes()
{ {
return $this->length; return $this->length;
} }
@ -308,7 +308,7 @@ class Hash
* @access public * @access public
* @return int * @return int
*/ */
function getBlockLength() public function getBlockLength()
{ {
return $this->blockSize; return $this->blockSize;
} }
@ -319,7 +319,7 @@ class Hash
* @access public * @access public
* @return int * @return int
*/ */
function getBlockLengthInBytes() public function getBlockLengthInBytes()
{ {
return $this->blockSize >> 3; return $this->blockSize >> 3;
} }
@ -330,14 +330,14 @@ class Hash
* @access private * @access private
* @param string $m * @param string $m
*/ */
static function _sha512($m, $hash) private static function _sha512($m, $hash)
{ {
static $k; static $k;
if (!isset($k)) { if (!isset($k)) {
// Initialize table of round constants // Initialize table of round constants
// (first 64 bits of the fractional parts of the cube roots of the first 80 primes 2..409) // (first 64 bits of the fractional parts of the cube roots of the first 80 primes 2..409)
$k = array( $k = [
'428a2f98d728ae22', '7137449123ef65cd', 'b5c0fbcfec4d3b2f', 'e9b5dba58189dbbc', '428a2f98d728ae22', '7137449123ef65cd', 'b5c0fbcfec4d3b2f', 'e9b5dba58189dbbc',
'3956c25bf348b538', '59f111f1b605d019', '923f82a4af194f9b', 'ab1c5ed5da6d8118', '3956c25bf348b538', '59f111f1b605d019', '923f82a4af194f9b', 'ab1c5ed5da6d8118',
'd807aa98a3030242', '12835b0145706fbe', '243185be4ee4b28c', '550c7dc3d5ffb4e2', 'd807aa98a3030242', '12835b0145706fbe', '243185be4ee4b28c', '550c7dc3d5ffb4e2',
@ -358,7 +358,7 @@ class Hash
'06f067aa72176fba', '0a637dc5a2c898a6', '113f9804bef90dae', '1b710b35131c471b', '06f067aa72176fba', '0a637dc5a2c898a6', '113f9804bef90dae', '1b710b35131c471b',
'28db77f523047d84', '32caab7b40c72493', '3c9ebe0a15c9bebc', '431d67c49c100d4c', '28db77f523047d84', '32caab7b40c72493', '3c9ebe0a15c9bebc', '431d67c49c100d4c',
'4cc5d4becb3e42b6', '597f299cfc657e2a', '5fcb6fab3ad6faec', '6c44198c4a475817' '4cc5d4becb3e42b6', '597f299cfc657e2a', '5fcb6fab3ad6faec', '6c44198c4a475817'
); ];
for ($i = 0; $i < 80; $i++) { for ($i = 0; $i < 80; $i++) {
$k[$i] = new BigInteger($k[$i], 16); $k[$i] = new BigInteger($k[$i], 16);
@ -376,7 +376,7 @@ class Hash
// Process the message in successive 1024-bit chunks // Process the message in successive 1024-bit chunks
$chunks = str_split($m, 128); $chunks = str_split($m, 128);
foreach ($chunks as $chunk) { foreach ($chunks as $chunk) {
$w = array(); $w = [];
for ($i = 0; $i < 16; $i++) { for ($i = 0; $i < 16; $i++) {
$temp = new BigInteger(Strings::shift($chunk, 8), 256); $temp = new BigInteger(Strings::shift($chunk, 8), 256);
$temp->setPrecision(64); $temp->setPrecision(64);
@ -385,18 +385,18 @@ class Hash
// Extend the sixteen 32-bit words into eighty 32-bit words // Extend the sixteen 32-bit words into eighty 32-bit words
for ($i = 16; $i < 80; $i++) { for ($i = 16; $i < 80; $i++) {
$temp = array( $temp = [
$w[$i - 15]->bitwise_rightRotate(1), $w[$i - 15]->bitwise_rightRotate(1),
$w[$i - 15]->bitwise_rightRotate(8), $w[$i - 15]->bitwise_rightRotate(8),
$w[$i - 15]->bitwise_rightShift(7) $w[$i - 15]->bitwise_rightShift(7)
); ];
$s0 = $temp[0]->bitwise_xor($temp[1]); $s0 = $temp[0]->bitwise_xor($temp[1]);
$s0 = $s0->bitwise_xor($temp[2]); $s0 = $s0->bitwise_xor($temp[2]);
$temp = array( $temp = [
$w[$i - 2]->bitwise_rightRotate(19), $w[$i - 2]->bitwise_rightRotate(19),
$w[$i - 2]->bitwise_rightRotate(61), $w[$i - 2]->bitwise_rightRotate(61),
$w[$i - 2]->bitwise_rightShift(6) $w[$i - 2]->bitwise_rightShift(6)
); ];
$s1 = $temp[0]->bitwise_xor($temp[1]); $s1 = $temp[0]->bitwise_xor($temp[1]);
$s1 = $s1->bitwise_xor($temp[2]); $s1 = $s1->bitwise_xor($temp[2]);
$w[$i] = clone $w[$i - 16]; $w[$i] = clone $w[$i - 16];
@ -417,33 +417,33 @@ class Hash
// Main loop // Main loop
for ($i = 0; $i < 80; $i++) { for ($i = 0; $i < 80; $i++) {
$temp = array( $temp = [
$a->bitwise_rightRotate(28), $a->bitwise_rightRotate(28),
$a->bitwise_rightRotate(34), $a->bitwise_rightRotate(34),
$a->bitwise_rightRotate(39) $a->bitwise_rightRotate(39)
); ];
$s0 = $temp[0]->bitwise_xor($temp[1]); $s0 = $temp[0]->bitwise_xor($temp[1]);
$s0 = $s0->bitwise_xor($temp[2]); $s0 = $s0->bitwise_xor($temp[2]);
$temp = array( $temp = [
$a->bitwise_and($b), $a->bitwise_and($b),
$a->bitwise_and($c), $a->bitwise_and($c),
$b->bitwise_and($c) $b->bitwise_and($c)
); ];
$maj = $temp[0]->bitwise_xor($temp[1]); $maj = $temp[0]->bitwise_xor($temp[1]);
$maj = $maj->bitwise_xor($temp[2]); $maj = $maj->bitwise_xor($temp[2]);
$t2 = $s0->add($maj); $t2 = $s0->add($maj);
$temp = array( $temp = [
$e->bitwise_rightRotate(14), $e->bitwise_rightRotate(14),
$e->bitwise_rightRotate(18), $e->bitwise_rightRotate(18),
$e->bitwise_rightRotate(41) $e->bitwise_rightRotate(41)
); ];
$s1 = $temp[0]->bitwise_xor($temp[1]); $s1 = $temp[0]->bitwise_xor($temp[1]);
$s1 = $s1->bitwise_xor($temp[2]); $s1 = $s1->bitwise_xor($temp[2]);
$temp = array( $temp = [
$e->bitwise_and($f), $e->bitwise_and($f),
$g->bitwise_and($e->bitwise_not()) $g->bitwise_and($e->bitwise_not())
); ];
$ch = $temp[0]->bitwise_xor($temp[1]); $ch = $temp[0]->bitwise_xor($temp[1]);
$t1 = $h->add($s1); $t1 = $h->add($s1);
$t1 = $t1->add($ch); $t1 = $t1->add($ch);
@ -461,7 +461,7 @@ class Hash
} }
// Add this chunk's hash to result so far // Add this chunk's hash to result so far
$hash = array( $hash = [
$hash[0]->add($a), $hash[0]->add($a),
$hash[1]->add($b), $hash[1]->add($b),
$hash[2]->add($c), $hash[2]->add($c),
@ -470,7 +470,7 @@ class Hash
$hash[5]->add($f), $hash[5]->add($f),
$hash[6]->add($g), $hash[6]->add($g),
$hash[7]->add($h) $hash[7]->add($h)
); ];
} }
// Produce the final hash value (big-endian) // Produce the final hash value (big-endian)

View File

@ -52,7 +52,7 @@ class RC2 extends BlockCipher
* @var int * @var int
* @access private * @access private
*/ */
var $block_size = 8; protected $block_size = 8;
/** /**
* The Key * The Key
@ -62,7 +62,7 @@ class RC2 extends BlockCipher
* @var string * @var string
* @access private * @access private
*/ */
var $key; protected $key;
/** /**
* The Original (unpadded) Key * The Original (unpadded) Key
@ -74,16 +74,16 @@ class RC2 extends BlockCipher
* @var string * @var string
* @access private * @access private
*/ */
var $orig_key; private $orig_key;
/** /**
* Don't truncate / null pad key * Don't truncate / null pad key
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::_clearBuffers() * @see \phpseclib\Crypt\Common\SymmetricKey::clearBuffers()
* @var bool * @var bool
* @access private * @access private
*/ */
var $skip_key_adjustment = true; private $skip_key_adjustment = true;
/** /**
* Key Length (in bytes) * Key Length (in bytes)
@ -92,7 +92,7 @@ class RC2 extends BlockCipher
* @var int * @var int
* @access private * @access private
*/ */
var $key_length = 16; // = 128 bits protected $key_length = 16; // = 128 bits
/** /**
* The mcrypt specific name of the cipher * The mcrypt specific name of the cipher
@ -101,7 +101,7 @@ class RC2 extends BlockCipher
* @var string * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'rc2'; protected $cipher_name_mcrypt = 'rc2';
/** /**
* Optimizing value while CFB-encrypting * Optimizing value while CFB-encrypting
@ -110,7 +110,7 @@ class RC2 extends BlockCipher
* @var int * @var int
* @access private * @access private
*/ */
var $cfb_init_len = 500; protected $cfb_init_len = 500;
/** /**
* The key length in bits. * The key length in bits.
@ -122,7 +122,7 @@ class RC2 extends BlockCipher
* @internal Should be in range [1..1024]. * @internal Should be in range [1..1024].
* @internal Changing this value after setting the key has no effect. * @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. * The key length in bits.
@ -133,16 +133,16 @@ class RC2 extends BlockCipher
* @access private * @access private
* @internal Should be in range [1..1024]. * @internal Should be in range [1..1024].
*/ */
var $current_key_length; private $current_key_length;
/** /**
* The Key Schedule * The Key Schedule
* *
* @see self::_setupKey() * @see self::setupKey()
* @var array * @var array
* @access private * @access private
*/ */
var $keys; private $keys;
/** /**
* Key expansion randomization table. * Key expansion randomization table.
@ -152,7 +152,7 @@ class RC2 extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $pitable = array( private $pitable = [
0xD9, 0x78, 0xF9, 0xC4, 0x19, 0xDD, 0xB5, 0xED, 0xD9, 0x78, 0xF9, 0xC4, 0x19, 0xDD, 0xB5, 0xED,
0x28, 0xE9, 0xFD, 0x79, 0x4A, 0xA0, 0xD8, 0x9D, 0x28, 0xE9, 0xFD, 0x79, 0x4A, 0xA0, 0xD8, 0x9D,
0xC6, 0x7E, 0x37, 0x83, 0x2B, 0x76, 0x53, 0x8E, 0xC6, 0x7E, 0x37, 0x83, 0x2B, 0x76, 0x53, 0x8E,
@ -217,7 +217,7 @@ class RC2 extends BlockCipher
0xBB, 0x48, 0x0C, 0x5F, 0xB9, 0xB1, 0xCD, 0x2E, 0xBB, 0x48, 0x0C, 0x5F, 0xB9, 0xB1, 0xCD, 0x2E,
0xC5, 0xF3, 0xDB, 0x47, 0xE5, 0xA5, 0x9C, 0x77, 0xC5, 0xF3, 0xDB, 0x47, 0xE5, 0xA5, 0x9C, 0x77,
0x0A, 0xA6, 0x20, 0x68, 0xFE, 0x7F, 0xC1, 0xAD 0x0A, 0xA6, 0x20, 0x68, 0xFE, 0x7F, 0xC1, 0xAD
); ];
/** /**
* Inverse key expansion randomization table. * Inverse key expansion randomization table.
@ -226,7 +226,7 @@ class RC2 extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $invpitable = array( private $invpitable = [
0xD1, 0xDA, 0xB9, 0x6F, 0x9C, 0xC8, 0x78, 0x66, 0xD1, 0xDA, 0xB9, 0x6F, 0x9C, 0xC8, 0x78, 0x66,
0x80, 0x2C, 0xF8, 0x37, 0xEA, 0xE0, 0x62, 0xA4, 0x80, 0x2C, 0xF8, 0x37, 0xEA, 0xE0, 0x62, 0xA4,
0xCB, 0x71, 0x50, 0x27, 0x4B, 0x95, 0xD9, 0x20, 0xCB, 0x71, 0x50, 0x27, 0x4B, 0x95, 0xD9, 0x20,
@ -259,7 +259,7 @@ class RC2 extends BlockCipher
0x81, 0x09, 0x82, 0x33, 0x9F, 0x07, 0x86, 0x75, 0x81, 0x09, 0x82, 0x33, 0x9F, 0x07, 0x86, 0x75,
0x38, 0x4E, 0x69, 0xF1, 0xAD, 0x23, 0x73, 0x87, 0x38, 0x4E, 0x69, 0xF1, 0xAD, 0x23, 0x73, 0x87,
0x70, 0x02, 0xC2, 0x1E, 0xB8, 0x0A, 0xFC, 0xE6 0x70, 0x02, 0xC2, 0x1E, 0xB8, 0x0A, 0xFC, 0xE6
); ];
/** /**
* Default Constructor. * Default Constructor.
@ -268,7 +268,7 @@ class RC2 extends BlockCipher
* @access public * @access public
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided * @throws \InvalidArgumentException if an invalid / unsupported mode is provided
*/ */
function __construct($mode) public function __construct($mode)
{ {
if ($mode == self::MODE_STREAM) { if ($mode == self::MODE_STREAM) {
throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode'); throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode');
@ -287,7 +287,7 @@ class RC2 extends BlockCipher
* @access public * @access public
* @return bool * @return bool
*/ */
function isValidEngine($engine) public function isValidEngine($engine)
{ {
switch ($engine) { switch ($engine) {
case self::ENGINE_OPENSSL: case self::ENGINE_OPENSSL:
@ -295,7 +295,7 @@ class RC2 extends BlockCipher
return false; return false;
} }
$this->cipher_name_openssl_ecb = 'rc2-ecb'; $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); return parent::isValidEngine($engine);
@ -312,7 +312,7 @@ class RC2 extends BlockCipher
* @param int $length in bits * @param int $length in bits
* @throws \LengthException if the key length isn't supported * @throws \LengthException if the key length isn't supported
*/ */
function setKeyLength($length) public function setKeyLength($length)
{ {
if ($length < 8 || $length > 1024) { 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'); 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 * @access public
* @return int * @return int
*/ */
function getKeyLength() public function getKeyLength()
{ {
return $this->current_key_length; return $this->current_key_length;
} }
@ -347,7 +347,7 @@ class RC2 extends BlockCipher
* @param int $t1 optional Effective key length in bits. * @param int $t1 optional Effective key length in bits.
* @throws \LengthException if the key length isn't supported * @throws \LengthException if the key length isn't supported
*/ */
function setKey($key, $t1 = false) public function setKey($key, $t1 = false)
{ {
$this->orig_key = $key; $this->orig_key = $key;
@ -395,7 +395,7 @@ class RC2 extends BlockCipher
$this->key = call_user_func_array('pack', $l); $this->key = call_user_func_array('pack', $l);
$this->key_length = strlen($this->key); $this->key_length = strlen($this->key);
$this->changed = true; $this->changed = true;
$this->_setEngine(); $this->setEngine();
} }
/** /**
@ -408,7 +408,7 @@ class RC2 extends BlockCipher
* @param string $plaintext * @param string $plaintext
* @return string $ciphertext * @return string $ciphertext
*/ */
function encrypt($plaintext) public function encrypt($plaintext)
{ {
if ($this->engine == self::ENGINE_OPENSSL) { if ($this->engine == self::ENGINE_OPENSSL) {
$temp = $this->key; $temp = $this->key;
@ -431,7 +431,7 @@ class RC2 extends BlockCipher
* @param string $ciphertext * @param string $ciphertext
* @return string $plaintext * @return string $plaintext
*/ */
function decrypt($ciphertext) public function decrypt($ciphertext)
{ {
if ($this->engine == self::ENGINE_OPENSSL) { if ($this->engine == self::ENGINE_OPENSSL) {
$temp = $this->key; $temp = $this->key;
@ -447,18 +447,18 @@ class RC2 extends BlockCipher
/** /**
* Encrypts a block * Encrypts a block
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::_encryptBlock() * @see \phpseclib\Crypt\Common\SymmetricKey::encryptBlock()
* @see \phpseclib\Crypt\Common\SymmetricKey::encrypt() * @see \phpseclib\Crypt\Common\SymmetricKey::encrypt()
* @access private * @access private
* @param string $in * @param string $in
* @return string * @return string
*/ */
function _encryptBlock($in) protected function encryptBlock($in)
{ {
list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in)); list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in));
$keys = $this->keys; $keys = $this->keys;
$limit = 20; $limit = 20;
$actions = array($limit => 44, 44 => 64); $actions = [$limit => 44, 44 => 64];
$j = 0; $j = 0;
for (;;) { for (;;) {
@ -492,18 +492,18 @@ class RC2 extends BlockCipher
/** /**
* Decrypts a block * Decrypts a block
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::_decryptBlock() * @see \phpseclib\Crypt\Common\SymmetricKey::decryptBlock()
* @see \phpseclib\Crypt\Common\SymmetricKey::decrypt() * @see \phpseclib\Crypt\Common\SymmetricKey::decrypt()
* @access private * @access private
* @param string $in * @param string $in
* @return string * @return string
*/ */
function _decryptBlock($in) protected function decryptBlock($in)
{ {
list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in)); list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in));
$keys = $this->keys; $keys = $this->keys;
$limit = 44; $limit = 44;
$actions = array($limit => 20, 20 => 0); $actions = [$limit => 20, 20 => 0];
$j = 64; $j = 64;
for (;;) { for (;;) {
@ -534,28 +534,13 @@ class RC2 extends BlockCipher
return pack('vvvv', $r0, $r1, $r2, $r3); return pack('vvvv', $r0, $r1, $r2, $r3);
} }
/**
* Setup the \phpseclib\Crypt\Common\SymmetricKey::ENGINE_MCRYPT $engine
*
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupMcrypt()
* @access private
*/
function _setupMcrypt()
{
if (!isset($this->key)) {
$this->setKey('');
}
parent::_setupMcrypt();
}
/** /**
* Creates the key schedule * Creates the key schedule
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() * @see \phpseclib\Crypt\Common\SymmetricKey::setupKey()
* @access private * @access private
*/ */
function _setupKey() protected function setupKey()
{ {
if (!isset($this->key)) { if (!isset($this->key)) {
$this->setKey(''); $this->setKey('');
@ -573,137 +558,108 @@ class RC2 extends BlockCipher
/** /**
* Setup the performance-optimized function for de/encrypt() * Setup the performance-optimized function for de/encrypt()
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt() * @see \phpseclib\Crypt\Common\SymmetricKey::setupInlineCrypt()
* @access private * @access private
*/ */
function _setupInlineCrypt() protected function setupInlineCrypt()
{ {
$lambda_functions =& self::_getLambdaFunctions(); // Init code for both, encrypt and decrypt.
$init_crypt = '$keys = $this->keys;';
// The first 10 generated $lambda_functions will use the $keys hardcoded as integers $keys = $this->keys;
// for the mixing rounds, for better inline crypt performance [~20% faster].
// But for memory reason we have to limit those ultra-optimized $lambda_functions to an amount of 10.
// (Currently, for Crypt_RC2, one generated $lambda_function cost on php5.5@32bit ~60kb unfreeable mem and ~100kb on php5.5@64bit)
$gen_hi_opt_code = (bool)(count($lambda_functions) < 10);
// Generation of a unique hash for our generated code // $in is the current 8 bytes block which has to be en/decrypt
$code_hash = "Crypt_RC2, {$this->mode}"; $encrypt_block = $decrypt_block = '
if ($gen_hi_opt_code) { $in = unpack("v4", $in);
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); $r0 = $in[1];
} $r1 = $in[2];
$r2 = $in[3];
$r3 = $in[4];
';
// Is there a re-usable $lambda_functions in there? // Create code for encryption.
// If not, we have to create it. $limit = 20;
if (!isset($lambda_functions[$code_hash])) { $actions = [$limit => 44, 44 => 64];
// Init code for both, encrypt and decrypt. $j = 0;
$init_crypt = '$keys = $self->keys;';
switch (true) { for (;;) {
case $gen_hi_opt_code: // Mixing round.
$keys = $this->keys; $encrypt_block .= '
default: $r0 = (($r0 + ' . $keys[$j++] . ' +
$keys = array(); ((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF) << 1;
foreach ($this->keys as $k => $v) { $r0 |= $r0 >> 16;
$keys[$k] = '$keys[' . $k . ']'; $r1 = (($r1 + ' . $keys[$j++] . ' +
} ((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF) << 2;
} $r1 |= $r1 >> 16;
$r2 = (($r2 + ' . $keys[$j++] . ' +
((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF) << 3;
$r2 |= $r2 >> 16;
$r3 = (($r3 + ' . $keys[$j++] . ' +
((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF) << 5;
$r3 |= $r3 >> 16;';
// $in is the current 8 bytes block which has to be en/decrypt if ($j === $limit) {
$encrypt_block = $decrypt_block = ' if ($limit === 64) {
$in = unpack("v4", $in); break;
$r0 = $in[1]; }
$r1 = $in[2];
$r2 = $in[3];
$r3 = $in[4];
';
// Create code for encryption. // Mashing round.
$limit = 20;
$actions = array($limit => 44, 44 => 64);
$j = 0;
for (;;) {
// Mixing round.
$encrypt_block .= ' $encrypt_block .= '
$r0 = (($r0 + ' . $keys[$j++] . ' + $r0 += $keys[$r3 & 0x3F];
((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF) << 1; $r1 += $keys[$r0 & 0x3F];
$r0 |= $r0 >> 16; $r2 += $keys[$r1 & 0x3F];
$r1 = (($r1 + ' . $keys[$j++] . ' + $r3 += $keys[$r2 & 0x3F];';
((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF) << 2; $limit = $actions[$limit];
$r1 |= $r1 >> 16;
$r2 = (($r2 + ' . $keys[$j++] . ' +
((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF) << 3;
$r2 |= $r2 >> 16;
$r3 = (($r3 + ' . $keys[$j++] . ' +
((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF) << 5;
$r3 |= $r3 >> 16;';
if ($j === $limit) {
if ($limit === 64) {
break;
}
// Mashing round.
$encrypt_block .= '
$r0 += $keys[$r3 & 0x3F];
$r1 += $keys[$r0 & 0x3F];
$r2 += $keys[$r1 & 0x3F];
$r3 += $keys[$r2 & 0x3F];';
$limit = $actions[$limit];
}
} }
}
$encrypt_block .= '$in = pack("v4", $r0, $r1, $r2, $r3);'; $encrypt_block .= '$in = pack("v4", $r0, $r1, $r2, $r3);';
// Create code for decryption. // Create code for decryption.
$limit = 44; $limit = 44;
$actions = array($limit => 20, 20 => 0); $actions = [$limit => 20, 20 => 0];
$j = 64; $j = 64;
for (;;) { for (;;) {
// R-mixing round. // R-mixing round.
$decrypt_block .= '
$r3 = ($r3 | ($r3 << 16)) >> 5;
$r3 = ($r3 - ' . $keys[--$j] . ' -
((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF;
$r2 = ($r2 | ($r2 << 16)) >> 3;
$r2 = ($r2 - ' . $keys[--$j] . ' -
((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF;
$r1 = ($r1 | ($r1 << 16)) >> 2;
$r1 = ($r1 - ' . $keys[--$j] . ' -
((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF;
$r0 = ($r0 | ($r0 << 16)) >> 1;
$r0 = ($r0 - ' . $keys[--$j] . ' -
((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF;';
if ($j === $limit) {
if ($limit === 0) {
break;
}
// R-mashing round.
$decrypt_block .= ' $decrypt_block .= '
$r3 = ($r3 | ($r3 << 16)) >> 5; $r3 = ($r3 - $keys[$r2 & 0x3F]) & 0xFFFF;
$r3 = ($r3 - ' . $keys[--$j] . ' - $r2 = ($r2 - $keys[$r1 & 0x3F]) & 0xFFFF;
((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF; $r1 = ($r1 - $keys[$r0 & 0x3F]) & 0xFFFF;
$r2 = ($r2 | ($r2 << 16)) >> 3; $r0 = ($r0 - $keys[$r3 & 0x3F]) & 0xFFFF;';
$r2 = ($r2 - ' . $keys[--$j] . ' - $limit = $actions[$limit];
((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF;
$r1 = ($r1 | ($r1 << 16)) >> 2;
$r1 = ($r1 - ' . $keys[--$j] . ' -
((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF;
$r0 = ($r0 | ($r0 << 16)) >> 1;
$r0 = ($r0 - ' . $keys[--$j] . ' -
((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF;';
if ($j === $limit) {
if ($limit === 0) {
break;
}
// R-mashing round.
$decrypt_block .= '
$r3 = ($r3 - $keys[$r2 & 0x3F]) & 0xFFFF;
$r2 = ($r2 - $keys[$r1 & 0x3F]) & 0xFFFF;
$r1 = ($r1 - $keys[$r0 & 0x3F]) & 0xFFFF;
$r0 = ($r0 - $keys[$r3 & 0x3F]) & 0xFFFF;';
$limit = $actions[$limit];
}
} }
$decrypt_block .= '$in = pack("v4", $r0, $r1, $r2, $r3);';
// Creates the inline-crypt function
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
array(
'init_crypt' => $init_crypt,
'encrypt_block' => $encrypt_block,
'decrypt_block' => $decrypt_block
)
);
} }
// Set the inline-crypt function as callback in: $this->inline_crypt $decrypt_block .= '$in = pack("v4", $r0, $r1, $r2, $r3);';
$this->inline_crypt = $lambda_functions[$code_hash];
// Creates the inline-crypt function
$this->inline_crypt = $this->createInlineCryptFunction(
[
'init_crypt' => $init_crypt,
'encrypt_block' => $encrypt_block,
'decrypt_block' => $decrypt_block
]
);
} }
} }

View File

@ -73,7 +73,7 @@ class RC4 extends StreamCipher
* @var int * @var int
* @access private * @access private
*/ */
var $block_size = 0; protected $block_size = 0;
/** /**
* Key Length (in bytes) * Key Length (in bytes)
@ -82,7 +82,7 @@ class RC4 extends StreamCipher
* @var int * @var int
* @access private * @access private
*/ */
var $key_length = 128; // = 1024 bits protected $key_length = 128; // = 1024 bits
/** /**
* The mcrypt specific name of the cipher * The mcrypt specific name of the cipher
@ -91,7 +91,7 @@ class RC4 extends StreamCipher
* @var string * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'arcfour'; protected $cipher_name_mcrypt = 'arcfour';
/** /**
* Holds whether performance-optimized $inline_crypt() can/should be used. * Holds whether performance-optimized $inline_crypt() can/should be used.
@ -100,7 +100,7 @@ class RC4 extends StreamCipher
* @var mixed * @var mixed
* @access private * @access private
*/ */
var $use_inline_crypt = false; // currently not available protected $use_inline_crypt = false; // currently not available
/** /**
* The Key * The Key
@ -109,7 +109,7 @@ class RC4 extends StreamCipher
* @var string * @var string
* @access private * @access private
*/ */
var $key; protected $key;
/** /**
* The Key Stream for decryption and encryption * The Key Stream for decryption and encryption
@ -118,7 +118,7 @@ class RC4 extends StreamCipher
* @var array * @var array
* @access private * @access private
*/ */
var $stream; private $stream;
/** /**
* Default Constructor. * Default Constructor.
@ -127,7 +127,7 @@ class RC4 extends StreamCipher
* @return \phpseclib\Crypt\RC4 * @return \phpseclib\Crypt\RC4
* @access public * @access public
*/ */
function __construct() public function __construct()
{ {
parent::__construct(self::MODE_STREAM); parent::__construct(self::MODE_STREAM);
} }
@ -142,7 +142,7 @@ class RC4 extends StreamCipher
* @access public * @access public
* @return bool * @return bool
*/ */
function isValidEngine($engine) public function isValidEngine($engine)
{ {
if ($engine == self::ENGINE_OPENSSL) { if ($engine == self::ENGINE_OPENSSL) {
$this->cipher_name_openssl = 'rc4-40'; $this->cipher_name_openssl = 'rc4-40';
@ -157,7 +157,7 @@ class RC4 extends StreamCipher
* @access public * @access public
* @return bool * @return bool
*/ */
function usesIV() public function usesIV()
{ {
return false; return false;
} }
@ -171,7 +171,7 @@ class RC4 extends StreamCipher
* @param int $length * @param int $length
* @throws \LengthException if the key length is invalid * @throws \LengthException if the key length is invalid
*/ */
function setKeyLength($length) public function setKeyLength($length)
{ {
if ($length < 8 || $length > 2048) { 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'); throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys between 1 and 256 bytes are supported');
@ -191,7 +191,7 @@ class RC4 extends StreamCipher
* @param int $length * @param int $length
* @throws \LengthException if the key length is invalid * @throws \LengthException if the key length is invalid
*/ */
function setKey($key) public function setKey($key)
{ {
$length = strlen($key); $length = strlen($key);
if ($length < 1 || $length > 256) { if ($length < 1 || $length > 256) {
@ -205,17 +205,17 @@ class RC4 extends StreamCipher
* Encrypts a message. * Encrypts a message.
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::decrypt() * @see \phpseclib\Crypt\Common\SymmetricKey::decrypt()
* @see self::_crypt() * @see self::crypt()
* @access public * @access public
* @param string $plaintext * @param string $plaintext
* @return string $ciphertext * @return string $ciphertext
*/ */
function encrypt($plaintext) public function encrypt($plaintext)
{ {
if ($this->engine != self::ENGINE_INTERNAL) { if ($this->engine != self::ENGINE_INTERNAL) {
return parent::encrypt($plaintext); return parent::encrypt($plaintext);
} }
return $this->_crypt($plaintext, self::ENCRYPT); return $this->crypt($plaintext, self::ENCRYPT);
} }
/** /**
@ -225,17 +225,17 @@ class RC4 extends StreamCipher
* At least if the continuous buffer is disabled. * At least if the continuous buffer is disabled.
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::encrypt() * @see \phpseclib\Crypt\Common\SymmetricKey::encrypt()
* @see self::_crypt() * @see self::crypt()
* @access public * @access public
* @param string $ciphertext * @param string $ciphertext
* @return string $plaintext * @return string $plaintext
*/ */
function decrypt($ciphertext) public function decrypt($ciphertext)
{ {
if ($this->engine != self::ENGINE_INTERNAL) { if ($this->engine != self::ENGINE_INTERNAL) {
return parent::decrypt($ciphertext); return parent::decrypt($ciphertext);
} }
return $this->_crypt($ciphertext, self::DECRYPT); return $this->crypt($ciphertext, self::DECRYPT);
} }
/** /**
@ -244,7 +244,7 @@ class RC4 extends StreamCipher
* @access private * @access private
* @param string $in * @param string $in
*/ */
function _encryptBlock($in) protected function encryptBlock($in)
{ {
// RC4 does not utilize this method // RC4 does not utilize this method
} }
@ -255,7 +255,7 @@ class RC4 extends StreamCipher
* @access private * @access private
* @param string $in * @param string $in
*/ */
function _decryptBlock($in) protected function decryptBlock($in)
{ {
// RC4 does not utilize this method // RC4 does not utilize this method
} }
@ -266,7 +266,7 @@ class RC4 extends StreamCipher
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() * @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey()
* @access private * @access private
*/ */
function _setupKey() protected function setupKey()
{ {
$key = $this->key; $key = $this->key;
$keyLength = strlen($key); $keyLength = strlen($key);
@ -279,12 +279,12 @@ class RC4 extends StreamCipher
$keyStream[$j] = $temp; $keyStream[$j] = $temp;
} }
$this->stream = array(); $this->stream = [];
$this->stream[self::DECRYPT] = $this->stream[self::ENCRYPT] = array( $this->stream[self::DECRYPT] = $this->stream[self::ENCRYPT] = [
0, // index $i 0, // index $i
0, // index $j 0, // index $j
$keyStream $keyStream
); ];
} }
/** /**
@ -297,10 +297,10 @@ class RC4 extends StreamCipher
* @param int $mode * @param int $mode
* @return string $text * @return string $text
*/ */
function _crypt($text, $mode) private function crypt($text, $mode)
{ {
if ($this->changed) { if ($this->changed) {
$this->_setup(); $this->setup();
$this->changed = false; $this->changed = false;
} }

File diff suppressed because it is too large Load Diff

View File

@ -30,7 +30,7 @@ use phpseclib\Common\Functions\Strings;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class MSBLOB abstract class MSBLOB
{ {
/**#@+ /**#@+
* @access private * @access private
@ -73,7 +73,7 @@ class MSBLOB
* @param string $password optional * @param string $password optional
* @return array * @return array
*/ */
static function load($key, $password = '') public static function load($key, $password = '')
{ {
if (!is_string($key)) { if (!is_string($key)) {
return false; return false;
@ -100,7 +100,7 @@ class MSBLOB
return false; return false;
} }
$components = array('isPublicKey' => $publickey); $components = ['isPublicKey' => $publickey];
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa375549(v=vs.85).aspx // https://msdn.microsoft.com/en-us/library/windows/desktop/aa375549(v=vs.85).aspx
switch ($algo) { switch ($algo) {
@ -140,15 +140,15 @@ class MSBLOB
$components['isPublicKey'] = false; $components['isPublicKey'] = false;
// BYTE prime1[rsapubkey.bitlen/16] // BYTE prime1[rsapubkey.bitlen/16]
$components['primes'] = array(1 => new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256)); $components['primes'] = [1 => new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256)];
// BYTE prime2[rsapubkey.bitlen/16] // BYTE prime2[rsapubkey.bitlen/16]
$components['primes'][] = new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256); $components['primes'][] = new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256);
// BYTE exponent1[rsapubkey.bitlen/16] // BYTE exponent1[rsapubkey.bitlen/16]
$components['exponents'] = array(1 => new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256)); $components['exponents'] = [1 => new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256)];
// BYTE exponent2[rsapubkey.bitlen/16] // BYTE exponent2[rsapubkey.bitlen/16]
$components['exponents'][] = new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256); $components['exponents'][] = new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256);
// BYTE coefficient[rsapubkey.bitlen/16] // BYTE coefficient[rsapubkey.bitlen/16]
$components['coefficients'] = array(2 => new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256)); $components['coefficients'] = [2 => new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256)];
if (isset($components['privateExponent'])) { if (isset($components['privateExponent'])) {
$components['publicExponent'] = $components['privateExponent']; $components['publicExponent'] = $components['privateExponent'];
} }
@ -171,7 +171,7 @@ class MSBLOB
* @param string $password optional * @param string $password optional
* @return string * @return string
*/ */
static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '') public static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '')
{ {
$n = strrev($n->toBytes()); $n = strrev($n->toBytes());
$e = str_pad(strrev($e->toBytes()), 4, "\0"); $e = str_pad(strrev($e->toBytes()), 4, "\0");
@ -196,7 +196,7 @@ class MSBLOB
* @param \phpseclib\Math\BigInteger $e * @param \phpseclib\Math\BigInteger $e
* @return string * @return string
*/ */
static function savePublicKey(BigInteger $n, BigInteger $e) public static function savePublicKey(BigInteger $n, BigInteger $e)
{ {
$n = strrev($n->toBytes()); $n = strrev($n->toBytes());
$e = str_pad(strrev($e->toBytes()), 4, "\0"); $e = str_pad(strrev($e->toBytes()), 4, "\0");

View File

@ -28,7 +28,7 @@ use phpseclib\Common\Functions\Strings;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class OpenSSH abstract class OpenSSH
{ {
/** /**
* Default comment * Default comment
@ -36,7 +36,7 @@ class OpenSSH
* @var string * @var string
* @access private * @access private
*/ */
static $comment = 'phpseclib-generated-key'; private static $comment = 'phpseclib-generated-key';
/** /**
* Sets the default comment * Sets the default comment
@ -44,9 +44,9 @@ class OpenSSH
* @access public * @access public
* @param string $comment * @param string $comment
*/ */
static function setComment($comment) public static function setComment($comment)
{ {
self::$comment = str_replace(array("\r", "\n"), '', $comment); self::$comment = str_replace(["\r", "\n"], '', $comment);
} }
/** /**
@ -57,7 +57,7 @@ class OpenSSH
* @param string $password optional * @param string $password optional
* @return array * @return array
*/ */
static function load($key, $password = '') public static function load($key, $password = '')
{ {
if (!is_string($key)) { if (!is_string($key)) {
return false; return false;
@ -93,12 +93,12 @@ class OpenSSH
} }
$modulus = new BigInteger(Strings::shift($key, $length), -256); $modulus = new BigInteger(Strings::shift($key, $length), -256);
return array( return [
'isPublicKey' => true, 'isPublicKey' => true,
'modulus' => $modulus, 'modulus' => $modulus,
'publicExponent' => $publicExponent, 'publicExponent' => $publicExponent,
'comment' => $comment 'comment' => $comment
); ];
} }
/** /**
@ -109,7 +109,7 @@ class OpenSSH
* @param \phpseclib\Math\BigInteger $e * @param \phpseclib\Math\BigInteger $e
* @return string * @return string
*/ */
static function savePublicKey(BigInteger $n, BigInteger $e) public static function savePublicKey(BigInteger $n, BigInteger $e)
{ {
$publicExponent = $e->toBytes(true); $publicExponent = $e->toBytes(true);
$modulus = $n->toBytes(true); $modulus = $n->toBytes(true);

View File

@ -36,7 +36,7 @@ use phpseclib\File\ASN1\Maps;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PKCS1 extends Progenitor abstract class PKCS1 extends Progenitor
{ {
/** /**
* Break a public or private key down into its constituent components * Break a public or private key down into its constituent components
@ -46,7 +46,7 @@ class PKCS1 extends Progenitor
* @param string $password optional * @param string $password optional
* @return array * @return array
*/ */
static function load($key, $password = '') public static function load($key, $password = '')
{ {
if (!is_string($key)) { if (!is_string($key)) {
return false; return false;
@ -102,7 +102,7 @@ class PKCS1 extends Progenitor
* @param string $password optional * @param string $password optional
* @return string * @return string
*/ */
static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '') public static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '')
{ {
$num_primes = count($primes); $num_primes = count($primes);
$key = [ $key = [
@ -137,7 +137,7 @@ class PKCS1 extends Progenitor
* @param \phpseclib\Math\BigInteger $e * @param \phpseclib\Math\BigInteger $e
* @return string * @return string
*/ */
static function savePublicKey(BigInteger $n, BigInteger $e) public static function savePublicKey(BigInteger $n, BigInteger $e)
{ {
$key = [ $key = [
'modulus' => $n, 'modulus' => $n,

View File

@ -38,7 +38,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PKCS8 extends Progenitor abstract class PKCS8 extends Progenitor
{ {
/** /**
* Break a public or private key down into its constituent components * Break a public or private key down into its constituent components
@ -48,7 +48,7 @@ class PKCS8 extends Progenitor
* @param string $password optional * @param string $password optional
* @return array * @return array
*/ */
static function load($key, $password = '') public static function load($key, $password = '')
{ {
$components = ['isPublicKey' => strpos($key, 'PUBLIC') !== false]; $components = ['isPublicKey' => strpos($key, 'PUBLIC') !== false];
@ -85,7 +85,7 @@ class PKCS8 extends Progenitor
* @param string $password optional * @param string $password optional
* @return string * @return string
*/ */
static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '') public static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '')
{ {
$key = PKCS1::savePrivateKey($n, $e, $d, $primes, $exponents, $coefficients); $key = PKCS1::savePrivateKey($n, $e, $d, $primes, $exponents, $coefficients);
$key = ASN1::extractBER($key); $key = ASN1::extractBER($key);
@ -100,7 +100,7 @@ class PKCS8 extends Progenitor
* @param \phpseclib\Math\BigInteger $e * @param \phpseclib\Math\BigInteger $e
* @return string * @return string
*/ */
static function savePublicKey(BigInteger $n, BigInteger $e) public static function savePublicKey(BigInteger $n, BigInteger $e)
{ {
$key = PKCS1::savePublicKey($n, $e); $key = PKCS1::savePublicKey($n, $e);
$key = ASN1::extractBER($key); $key = ASN1::extractBER($key);

View File

@ -29,7 +29,7 @@ use phpseclib\Common\Functions\Strings;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PuTTY abstract class PuTTY
{ {
/** /**
* Default comment * Default comment
@ -37,7 +37,7 @@ class PuTTY
* @var string * @var string
* @access private * @access private
*/ */
static $comment = 'phpseclib-generated-key'; private static $comment = 'phpseclib-generated-key';
/** /**
* Sets the default comment * Sets the default comment
@ -45,9 +45,9 @@ class PuTTY
* @access public * @access public
* @param string $comment * @param string $comment
*/ */
static function setComment($comment) public static function setComment($comment)
{ {
self::$comment = str_replace(array("\r", "\n"), '', $comment); self::$comment = str_replace(["\r", "\n"], '', $comment);
} }
/** /**
@ -59,7 +59,7 @@ class PuTTY
* @param int $length * @param int $length
* @return string * @return string
*/ */
static function generateSymmetricKey($password, $length) public static function generateSymmetricKey($password, $length)
{ {
$symkey = ''; $symkey = '';
$sequence = 0; $sequence = 0;
@ -78,7 +78,7 @@ class PuTTY
* @param string $password optional * @param string $password optional
* @return array * @return array
*/ */
static function load($key, $password = '') public static function load($key, $password = '')
{ {
if (!is_string($key)) { if (!is_string($key)) {
return false; return false;
@ -102,12 +102,12 @@ class PuTTY
if (!preg_match('#Comment: "(.+)"#', $key, $matches)) { if (!preg_match('#Comment: "(.+)"#', $key, $matches)) {
return false; return false;
} }
$components['comment'] = str_replace(array('\\\\', '\"'), array('\\', '"'), $matches[1]); $components['comment'] = str_replace(['\\\\', '\"'], ['\\', '"'], $matches[1]);
return $components; return $components;
} }
$components = array('isPublicKey' => false); $components = ['isPublicKey' => false];
$key = preg_split('#\r\n|\r|\n#', $key); $key = preg_split('#\r\n|\r|\n#', $key);
$type = trim(preg_replace('#PuTTY-User-Key-File-2: (.+)#', '$1', $key[0])); $type = trim(preg_replace('#PuTTY-User-Key-File-2: (.+)#', '$1', $key[0]));
if ($type != 'ssh-rsa') { if ($type != 'ssh-rsa') {
@ -149,7 +149,7 @@ class PuTTY
if (strlen($private) < $length) { if (strlen($private) < $length) {
return false; return false;
} }
$components['primes'] = array(1 => new BigInteger(Strings::shift($private, $length), -256)); $components['primes'] = [1 => new BigInteger(Strings::shift($private, $length), -256)];
extract(unpack('Nlength', Strings::shift($private, 4))); extract(unpack('Nlength', Strings::shift($private, 4)));
if (strlen($private) < $length) { if (strlen($private) < $length) {
return false; return false;
@ -157,7 +157,7 @@ class PuTTY
$components['primes'][] = new BigInteger(Strings::shift($private, $length), -256); $components['primes'][] = new BigInteger(Strings::shift($private, $length), -256);
$temp = $components['primes'][1]->subtract($one); $temp = $components['primes'][1]->subtract($one);
$components['exponents'] = array(1 => $components['publicExponent']->modInverse($temp)); $components['exponents'] = [1 => $components['publicExponent']->modInverse($temp)];
$temp = $components['primes'][2]->subtract($one); $temp = $components['primes'][2]->subtract($one);
$components['exponents'][] = $components['publicExponent']->modInverse($temp); $components['exponents'][] = $components['publicExponent']->modInverse($temp);
@ -165,7 +165,7 @@ class PuTTY
if (strlen($private) < $length) { if (strlen($private) < $length) {
return false; return false;
} }
$components['coefficients'] = array(2 => new BigInteger(Strings::shift($private, $length), -256)); $components['coefficients'] = [2 => new BigInteger(Strings::shift($private, $length), -256)];
return $components; return $components;
} }
@ -183,13 +183,13 @@ class PuTTY
* @param string $password optional * @param string $password optional
* @return string * @return string
*/ */
static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '') public static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '')
{ {
if (count($primes) != 2) { if (count($primes) != 2) {
return false; return false;
} }
$raw = array( $raw = [
'modulus' => $n->toBytes(true), 'modulus' => $n->toBytes(true),
'publicExponent' => $e->toBytes(true), 'publicExponent' => $e->toBytes(true),
'privateExponent' => $d->toBytes(true), 'privateExponent' => $d->toBytes(true),
@ -198,7 +198,7 @@ class PuTTY
'exponent1' => $exponents[1]->toBytes(true), 'exponent1' => $exponents[1]->toBytes(true),
'exponent2' => $exponents[2]->toBytes(true), 'exponent2' => $exponents[2]->toBytes(true),
'coefficient' => $coefficients[2]->toBytes(true) 'coefficient' => $coefficients[2]->toBytes(true)
); ];
$key = "PuTTY-User-Key-File-2: ssh-rsa\r\nEncryption: "; $key = "PuTTY-User-Key-File-2: ssh-rsa\r\nEncryption: ";
$encryption = (!empty($password) || is_string($password)) ? 'aes256-cbc' : 'none'; $encryption = (!empty($password) || is_string($password)) ? 'aes256-cbc' : 'none';
@ -271,7 +271,7 @@ class PuTTY
* @param \phpseclib\Math\BigInteger $e * @param \phpseclib\Math\BigInteger $e
* @return string * @return string
*/ */
static function savePublicKey(BigInteger $n, BigInteger $e) public static function savePublicKey(BigInteger $n, BigInteger $e)
{ {
$n = $n->toBytes(true); $n = $n->toBytes(true);
$e = $e->toBytes(true); $e = $e->toBytes(true);
@ -286,7 +286,7 @@ class PuTTY
$n $n
); );
$key = "---- BEGIN SSH2 PUBLIC KEY ----\r\n" . $key = "---- BEGIN SSH2 PUBLIC KEY ----\r\n" .
'Comment: "' . str_replace(array('\\', '"'), array('\\\\', '\"'), self::$comment) . "\"\r\n" . 'Comment: "' . str_replace(['\\', '"'], ['\\\\', '\"'], self::$comment) . "\"\r\n" .
chunk_split(Base64::encode($key), 64) . chunk_split(Base64::encode($key), 64) .
'---- END SSH2 PUBLIC KEY ----'; '---- END SSH2 PUBLIC KEY ----';

View File

@ -34,7 +34,7 @@ use phpseclib\Math\BigInteger;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class Raw abstract class Raw
{ {
/** /**
* Break a public or private key down into its constituent components * Break a public or private key down into its constituent components
@ -44,7 +44,7 @@ class Raw
* @param string $password optional * @param string $password optional
* @return array * @return array
*/ */
static function load($key, $password = '') public static function load($key, $password = '')
{ {
if (!is_array($key)) { if (!is_array($key)) {
return false; return false;
@ -59,7 +59,7 @@ class Raw
} }
} }
} }
$components = array('isPublicKey' => true); $components = ['isPublicKey' => true];
switch (true) { switch (true) {
case isset($key['e']): case isset($key['e']):
$components['publicExponent'] = $key['e']; $components['publicExponent'] = $key['e'];
@ -97,8 +97,8 @@ class Raw
* @param \phpseclib\Math\BigInteger $e * @param \phpseclib\Math\BigInteger $e
* @return string * @return string
*/ */
static function savePublicKey(BigInteger $n, BigInteger $e) public static function savePublicKey(BigInteger $n, BigInteger $e)
{ {
return array('e' => clone $e, 'n' => clone $n); return ['e' => clone $e, 'n' => clone $n];
} }
} }

View File

@ -30,7 +30,7 @@ use phpseclib\Math\BigInteger;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class XML abstract class XML
{ {
/** /**
* Break a public or private key down into its constituent components * Break a public or private key down into its constituent components
@ -40,18 +40,18 @@ class XML
* @param string $password optional * @param string $password optional
* @return array * @return array
*/ */
static function load($key, $password = '') public static function load($key, $password = '')
{ {
if (!is_string($key)) { if (!is_string($key)) {
return false; return false;
} }
$components = array( $components = [
'isPublicKey' => false, 'isPublicKey' => false,
'primes' => array(), 'primes' => [],
'exponents' => array(), 'exponents' => [],
'coefficients' => array() 'coefficients' => []
); ];
$use_errors = libxml_use_internal_errors(true); $use_errors = libxml_use_internal_errors(true);
@ -60,7 +60,7 @@ class XML
return false; return false;
} }
$xpath = new \DOMXPath($dom); $xpath = new \DOMXPath($dom);
$keys = array('modulus', 'exponent', 'p', 'q', 'dp', 'dq', 'inverseq', 'd'); $keys = ['modulus', 'exponent', 'p', 'q', 'dp', 'dq', 'inverseq', 'd'];
foreach ($keys as $key) { foreach ($keys as $key) {
// $dom->getElementsByTagName($key) is case-sensitive // $dom->getElementsByTagName($key) is case-sensitive
$temp = $xpath->query("//*[translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='$key']"); $temp = $xpath->query("//*[translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='$key']");
@ -113,7 +113,7 @@ class XML
* @param string $password optional * @param string $password optional
* @return string * @return string
*/ */
static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '') public static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '')
{ {
if (count($primes) != 2) { if (count($primes) != 2) {
return false; return false;
@ -138,7 +138,7 @@ class XML
* @param \phpseclib\Math\BigInteger $e * @param \phpseclib\Math\BigInteger $e
* @return string * @return string
*/ */
static function savePublicKey(BigInteger $n, BigInteger $e) public static function savePublicKey(BigInteger $n, BigInteger $e)
{ {
return "<RSAKeyValue>\r\n" . return "<RSAKeyValue>\r\n" .
' <Modulus>' . Base64::encode($n->toBytes()) . "</Modulus>\r\n" . ' <Modulus>' . Base64::encode($n->toBytes()) . "</Modulus>\r\n" .

View File

@ -33,7 +33,7 @@ use phpseclib\Crypt\Common\BlockCipher;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class Random abstract class Random
{ {
/** /**
* Generate a random string. * Generate a random string.
@ -46,7 +46,7 @@ class Random
* @throws \RuntimeException if a symmetric cipher is needed but not loaded * @throws \RuntimeException if a symmetric cipher is needed but not loaded
* @return string * @return string
*/ */
static function string($length) public static function string($length)
{ {
try { try {
return \random_bytes($length); return \random_bytes($length);
@ -196,7 +196,7 @@ class Random
* @param mixed $arr * @param mixed $arr
* @access public * @access public
*/ */
static function safe_serialize(&$arr) private static function safe_serialize(&$arr)
{ {
if (is_object($arr)) { if (is_object($arr)) {
return ''; return '';
@ -208,7 +208,7 @@ class Random
if (isset($arr['__phpseclib_marker'])) { if (isset($arr['__phpseclib_marker'])) {
return ''; return '';
} }
$safearr = array(); $safearr = [];
$arr['__phpseclib_marker'] = true; $arr['__phpseclib_marker'] = true;
foreach (array_keys($arr) as $key) { foreach (array_keys($arr) as $key) {
// do not recurse on the '__phpseclib_marker' key itself, for smaller memory usage // do not recurse on the '__phpseclib_marker' key itself, for smaller memory usage

View File

@ -79,35 +79,25 @@ class Rijndael extends BlockCipher
* @var string * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'rijndael-128'; protected $cipher_name_mcrypt = 'rijndael-128';
/**
* The default salt used by setPassword()
*
* @see \phpseclib\Crypt\Common\SymmetricKey::password_default_salt
* @see \phpseclib\Crypt\Common\SymmetricKey::setPassword()
* @var string
* @access private
*/
var $password_default_salt = 'phpseclib';
/** /**
* The Key Schedule * The Key Schedule
* *
* @see self::_setup() * @see self::setup()
* @var array * @var array
* @access private * @access private
*/ */
var $w; private $w;
/** /**
* The Inverse Key Schedule * The Inverse Key Schedule
* *
* @see self::_setup() * @see self::setup()
* @var array * @var array
* @access private * @access private
*/ */
var $dw; private $dw;
/** /**
* The Block Length divided by 32 * The Block Length divided by 32
@ -120,7 +110,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 * 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. * of that, we'll just precompute it once.
*/ */
var $Nb = 4; private $Nb = 4;
/** /**
* The Key Length (in bytes) * The Key Length (in bytes)
@ -133,7 +123,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 * 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. * of that, we'll just precompute it once.
*/ */
var $key_length = 16; protected $key_length = 16;
/** /**
* The Key Length divided by 32 * The Key Length divided by 32
@ -143,7 +133,7 @@ class Rijndael extends BlockCipher
* @access private * @access private
* @internal The max value is 256 / 32 = 8, the min value is 128 / 32 = 4 * @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 * The Number of Rounds
@ -152,7 +142,7 @@ class Rijndael extends BlockCipher
* @access private * @access private
* @internal The max value is 14, the min value is 10. * @internal The max value is 14, the min value is 10.
*/ */
var $Nr; private $Nr;
/** /**
* Shift offsets * Shift offsets
@ -160,7 +150,7 @@ class Rijndael extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $c; private $c;
/** /**
* Holds the last used key- and block_size information * Holds the last used key- and block_size information
@ -168,7 +158,7 @@ class Rijndael extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $kl; private $kl;
/** /**
* Default Constructor. * Default Constructor.
@ -177,7 +167,7 @@ class Rijndael extends BlockCipher
* @access public * @access public
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided * @throws \InvalidArgumentException if an invalid / unsupported mode is provided
*/ */
function __construct($mode) public function __construct($mode)
{ {
if ($mode == self::MODE_STREAM) { if ($mode == self::MODE_STREAM) {
throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode'); throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode');
@ -206,7 +196,7 @@ class Rijndael extends BlockCipher
* @throws \LengthException if the key length is invalid * @throws \LengthException if the key length is invalid
* @param int $length * @param int $length
*/ */
function setKeyLength($length) public function setKeyLength($length)
{ {
switch ($length) { switch ($length) {
case 128: case 128:
@ -233,7 +223,7 @@ class Rijndael extends BlockCipher
* @param string $key * @param string $key
* @throws \LengthException if the key length isn't supported * @throws \LengthException if the key length isn't supported
*/ */
function setKey($key) public function setKey($key)
{ {
switch (strlen($key)) { switch (strlen($key)) {
case 16: case 16:
@ -257,7 +247,7 @@ class Rijndael extends BlockCipher
* @access public * @access public
* @param int $length * @param int $length
*/ */
function setBlockLength($length) public function setBlockLength($length)
{ {
switch ($length) { switch ($length) {
case 128: case 128:
@ -273,7 +263,7 @@ class Rijndael extends BlockCipher
$this->Nb = $length >> 5; $this->Nb = $length >> 5;
$this->block_size = $length >> 3; $this->block_size = $length >> 3;
$this->changed = true; $this->changed = true;
$this->_setEngine(); $this->setEngine();
} }
/** /**
@ -286,7 +276,7 @@ class Rijndael extends BlockCipher
* @access public * @access public
* @return bool * @return bool
*/ */
function isValidEngine($engine) public function isValidEngine($engine)
{ {
switch ($engine) { switch ($engine) {
case self::ENGINE_OPENSSL: case self::ENGINE_OPENSSL:
@ -294,7 +284,7 @@ class Rijndael extends BlockCipher
return false; return false;
} }
$this->cipher_name_openssl_ecb = 'aes-' . ($this->key_length << 3) . '-ecb'; $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; break;
case self::ENGINE_MCRYPT: case self::ENGINE_MCRYPT:
$this->cipher_name_mcrypt = 'rijndael-' . ($this->block_size << 3); $this->cipher_name_mcrypt = 'rijndael-' . ($this->block_size << 3);
@ -314,11 +304,11 @@ class Rijndael extends BlockCipher
* @param string $in * @param string $in
* @return string * @return string
*/ */
function _encryptBlock($in) protected function encryptBlock($in)
{ {
static $tables; static $tables;
if (empty($tables)) { if (empty($tables)) {
$tables = &$this->_getTables(); $tables = &$this->getTables();
} }
$t0 = $tables[0]; $t0 = $tables[0];
$t1 = $tables[1]; $t1 = $tables[1];
@ -326,7 +316,7 @@ class Rijndael extends BlockCipher
$t3 = $tables[3]; $t3 = $tables[3];
$sbox = $tables[4]; $sbox = $tables[4];
$state = array(); $state = [];
$words = unpack('N*', $in); $words = unpack('N*', $in);
$c = $this->c; $c = $this->c;
@ -348,7 +338,7 @@ class Rijndael extends BlockCipher
// equation (7.4.7) is supposed to use addition instead of subtraction, so we'll do that here, as well. // equation (7.4.7) is supposed to use addition instead of subtraction, so we'll do that here, as well.
// [1] http://fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.v316.pdf // [1] http://fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.v316.pdf
$temp = array(); $temp = [];
for ($round = 1; $round < $Nr; ++$round) { for ($round = 1; $round < $Nr; ++$round) {
$i = 0; // $c[0] == 0 $i = 0; // $c[0] == 0
$j = $c[1]; $j = $c[1];
@ -415,11 +405,11 @@ class Rijndael extends BlockCipher
* @param string $in * @param string $in
* @return string * @return string
*/ */
function _decryptBlock($in) protected function decryptBlock($in)
{ {
static $invtables; static $invtables;
if (empty($invtables)) { if (empty($invtables)) {
$invtables = &$this->_getInvTables(); $invtables = &$this->getInvTables();
} }
$dt0 = $invtables[0]; $dt0 = $invtables[0];
$dt1 = $invtables[1]; $dt1 = $invtables[1];
@ -427,7 +417,7 @@ class Rijndael extends BlockCipher
$dt3 = $invtables[3]; $dt3 = $invtables[3];
$isbox = $invtables[4]; $isbox = $invtables[4];
$state = array(); $state = [];
$words = unpack('N*', $in); $words = unpack('N*', $in);
$c = $this->c; $c = $this->c;
@ -441,7 +431,7 @@ class Rijndael extends BlockCipher
$state[] = $word ^ $dw[++$wc]; $state[] = $word ^ $dw[++$wc];
} }
$temp = array(); $temp = [];
for ($round = $Nr - 1; $round > 0; --$round) { for ($round = $Nr - 1; $round > 0; --$round) {
$i = 0; // $c[0] == 0 $i = 0; // $c[0] == 0
$j = $Nb - $c[1]; $j = $Nb - $c[1];
@ -501,27 +491,27 @@ class Rijndael extends BlockCipher
/** /**
* Setup the key (expansion) * Setup the key (expansion)
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() * @see \phpseclib\Crypt\Common\SymmetricKey::setupKey()
* @access private * @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. // 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 // See http://en.wikipedia.org/wiki/Finite_field_arithmetic#Multiplicative_inverse
static $rcon = array(0, static $rcon = [0,
0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000,
0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000, 0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000,
0x6C000000, 0xD8000000, 0xAB000000, 0x4D000000, 0x9A000000, 0x6C000000, 0xD8000000, 0xAB000000, 0x4D000000, 0x9A000000,
0x2F000000, 0x5E000000, 0xBC000000, 0x63000000, 0xC6000000, 0x2F000000, 0x5E000000, 0xBC000000, 0x63000000, 0xC6000000,
0x97000000, 0x35000000, 0x6A000000, 0xD4000000, 0xB3000000, 0x97000000, 0x35000000, 0x6A000000, 0xD4000000, 0xB3000000,
0x7D000000, 0xFA000000, 0xEF000000, 0xC5000000, 0x91000000 0x7D000000, 0xFA000000, 0xEF000000, 0xC5000000, 0x91000000
); ];
if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->key_length === $this->kl['key_length'] && $this->block_size === $this->kl['block_size']) { if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->key_length === $this->kl['key_length'] && $this->block_size === $this->kl['block_size']) {
// already expanded // already expanded
return; return;
} }
$this->kl = array('key' => $this->key, 'key_length' => $this->key_length, 'block_size' => $this->block_size); $this->kl = ['key' => $this->key, 'key_length' => $this->key_length, 'block_size' => $this->block_size];
$this->Nk = $this->key_length >> 2; $this->Nk = $this->key_length >> 2;
// see Rijndael-ammended.pdf#page=44 // see Rijndael-ammended.pdf#page=44
@ -535,13 +525,13 @@ class Rijndael extends BlockCipher
case 4: case 4:
case 5: case 5:
case 6: case 6:
$this->c = array(0, 1, 2, 3); $this->c = [0, 1, 2, 3];
break; break;
case 7: case 7:
$this->c = array(0, 1, 2, 4); $this->c = [0, 1, 2, 4];
break; break;
case 8: case 8:
$this->c = array(0, 1, 3, 4); $this->c = [0, 1, 3, 4];
} }
$w = array_values(unpack('N*words', $this->key)); $w = array_values(unpack('N*words', $this->key));
@ -555,9 +545,9 @@ class Rijndael extends BlockCipher
// 0xFFFFFFFF << 8 == 0xFFFFFF00, but on a 64-bit machine, it equals 0xFFFFFFFF00. as such, doing 'and' // 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. // 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 = (($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) { } elseif ($this->Nk > 6 && $i % $this->Nk == 4) {
$temp = $this->_subWord($temp); $temp = $this->subWord($temp);
} }
$w[$i] = $w[$i - $this->Nk] ^ $temp; $w[$i] = $w[$i - $this->Nk] ^ $temp;
} }
@ -569,8 +559,8 @@ class Rijndael extends BlockCipher
// 1. Apply the Key Expansion. // 1. Apply the Key Expansion.
// 2. Apply InvMixColumn to all Round Keys except the first and the last one." // 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" // 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 = array(); $temp = $this->w = $this->dw = [];
for ($i = $row = $col = 0; $i < $length; $i++, $col++) { for ($i = $row = $col = 0; $i < $length; $i++, $col++) {
if ($col == $this->Nb) { if ($col == $this->Nb) {
if ($row == 0) { if ($row == 0) {
@ -579,7 +569,7 @@ class Rijndael extends BlockCipher
// subWord + invMixColumn + invSubWord = invMixColumn // subWord + invMixColumn + invSubWord = invMixColumn
$j = 0; $j = 0;
while ($j < $this->Nb) { while ($j < $this->Nb) {
$dw = $this->_subWord($this->w[$row][$j]); $dw = $this->subWord($this->w[$row][$j]);
$temp[$j] = $dt0[$dw >> 24 & 0x000000FF] ^ $temp[$j] = $dt0[$dw >> 24 & 0x000000FF] ^
$dt1[$dw >> 16 & 0x000000FF] ^ $dt1[$dw >> 16 & 0x000000FF] ^
$dt2[$dw >> 8 & 0x000000FF] ^ $dt2[$dw >> 8 & 0x000000FF] ^
@ -617,11 +607,11 @@ class Rijndael extends BlockCipher
* @access private * @access private
* @param int $word * @param int $word
*/ */
function _subWord($word) private function subWord($word)
{ {
static $sbox; static $sbox;
if (empty($sbox)) { if (empty($sbox)) {
list(, , , , $sbox) = $this->_getTables(); list(, , , , $sbox) = self::getTables();
} }
return $sbox[$word & 0x000000FF] | return $sbox[$word & 0x000000FF] |
@ -633,20 +623,20 @@ class Rijndael extends BlockCipher
/** /**
* Provides the mixColumns and sboxes tables * Provides the mixColumns and sboxes tables
* *
* @see self::_encryptBlock() * @see self::encryptBlock()
* @see self::_setupInlineCrypt() * @see self::setupInlineCrypt()
* @see self::_subWord() * @see self::subWord()
* @access private * @access private
* @return array &$tables * @return array &$tables
*/ */
function &_getTables() private function &getTables()
{ {
static $tables; static $tables;
if (empty($tables)) { if (empty($tables)) {
// according to <http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=19> (section 5.2.1), // according to <http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=19> (section 5.2.1),
// precomputed tables can be used in the mixColumns phase. in that example, they're assigned t0...t3, so // precomputed tables can be used in the mixColumns phase. in that example, they're assigned t0...t3, so
// those are the names we'll use. // those are the names we'll use.
$t3 = array_map('intval', array( $t3 = array_map('intval', [
// with array_map('intval', ...) we ensure we have only int's and not // with array_map('intval', ...) we ensure we have only int's and not
// some slower floats converted by php automatically on high values // some slower floats converted by php automatically on high values
0x6363A5C6, 0x7C7C84F8, 0x777799EE, 0x7B7B8DF6, 0xF2F20DFF, 0x6B6BBDD6, 0x6F6FB1DE, 0xC5C55491, 0x6363A5C6, 0x7C7C84F8, 0x777799EE, 0x7B7B8DF6, 0xF2F20DFF, 0x6B6BBDD6, 0x6F6FB1DE, 0xC5C55491,
@ -681,7 +671,7 @@ class Rijndael extends BlockCipher
0x9B9BB62D, 0x1E1E223C, 0x87879215, 0xE9E920C9, 0xCECE4987, 0x5555FFAA, 0x28287850, 0xDFDF7AA5, 0x9B9BB62D, 0x1E1E223C, 0x87879215, 0xE9E920C9, 0xCECE4987, 0x5555FFAA, 0x28287850, 0xDFDF7AA5,
0x8C8C8F03, 0xA1A1F859, 0x89898009, 0x0D0D171A, 0xBFBFDA65, 0xE6E631D7, 0x4242C684, 0x6868B8D0, 0x8C8C8F03, 0xA1A1F859, 0x89898009, 0x0D0D171A, 0xBFBFDA65, 0xE6E631D7, 0x4242C684, 0x6868B8D0,
0x4141C382, 0x9999B029, 0x2D2D775A, 0x0F0F111E, 0xB0B0CB7B, 0x5454FCA8, 0xBBBBD66D, 0x16163A2C 0x4141C382, 0x9999B029, 0x2D2D775A, 0x0F0F111E, 0xB0B0CB7B, 0x5454FCA8, 0xBBBBD66D, 0x16163A2C
)); ]);
foreach ($t3 as $t3i) { foreach ($t3 as $t3i) {
$t0[] = (($t3i << 24) & 0xFF000000) | (($t3i >> 8) & 0x00FFFFFF); $t0[] = (($t3i << 24) & 0xFF000000) | (($t3i >> 8) & 0x00FFFFFF);
@ -689,14 +679,14 @@ class Rijndael extends BlockCipher
$t2[] = (($t3i << 8) & 0xFFFFFF00) | (($t3i >> 24) & 0x000000FF); $t2[] = (($t3i << 8) & 0xFFFFFF00) | (($t3i >> 24) & 0x000000FF);
} }
$tables = array( $tables = [
// The Precomputed mixColumns tables t0 - t3 // The Precomputed mixColumns tables t0 - t3
$t0, $t0,
$t1, $t1,
$t2, $t2,
$t3, $t3,
// The SubByte S-Box // The SubByte S-Box
array( [
0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
@ -713,8 +703,8 @@ class Rijndael extends BlockCipher
0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
) ]
); ];
} }
return $tables; return $tables;
} }
@ -722,17 +712,17 @@ class Rijndael extends BlockCipher
/** /**
* Provides the inverse mixColumns and inverse sboxes tables * Provides the inverse mixColumns and inverse sboxes tables
* *
* @see self::_decryptBlock() * @see self::decryptBlock()
* @see self::_setupInlineCrypt() * @see self::setupInlineCrypt()
* @see self::_setupKey() * @see self::setupKey()
* @access private * @access private
* @return array &$tables * @return array &$tables
*/ */
function &_getInvTables() private function &getInvTables()
{ {
static $tables; static $tables;
if (empty($tables)) { if (empty($tables)) {
$dt3 = array_map('intval', array( $dt3 = array_map('intval', [
0xF4A75051, 0x4165537E, 0x17A4C31A, 0x275E963A, 0xAB6BCB3B, 0x9D45F11F, 0xFA58ABAC, 0xE303934B, 0xF4A75051, 0x4165537E, 0x17A4C31A, 0x275E963A, 0xAB6BCB3B, 0x9D45F11F, 0xFA58ABAC, 0xE303934B,
0x30FA5520, 0x766DF6AD, 0xCC769188, 0x024C25F5, 0xE5D7FC4F, 0x2ACBD7C5, 0x35448026, 0x62A38FB5, 0x30FA5520, 0x766DF6AD, 0xCC769188, 0x024C25F5, 0xE5D7FC4F, 0x2ACBD7C5, 0x35448026, 0x62A38FB5,
0xB15A49DE, 0xBA1B6725, 0xEA0E9845, 0xFEC0E15D, 0x2F7502C3, 0x4CF01281, 0x4697A38D, 0xD3F9C66B, 0xB15A49DE, 0xBA1B6725, 0xEA0E9845, 0xFEC0E15D, 0x2F7502C3, 0x4CF01281, 0x4697A38D, 0xD3F9C66B,
@ -765,7 +755,7 @@ class Rijndael extends BlockCipher
0xD2DF599C, 0xF2733F55, 0x14CE7918, 0xC737BF73, 0xF7CDEA53, 0xFDAA5B5F, 0x3D6F14DF, 0x44DB8678, 0xD2DF599C, 0xF2733F55, 0x14CE7918, 0xC737BF73, 0xF7CDEA53, 0xFDAA5B5F, 0x3D6F14DF, 0x44DB8678,
0xAFF381CA, 0x68C43EB9, 0x24342C38, 0xA3405FC2, 0x1DC37216, 0xE2250CBC, 0x3C498B28, 0x0D9541FF, 0xAFF381CA, 0x68C43EB9, 0x24342C38, 0xA3405FC2, 0x1DC37216, 0xE2250CBC, 0x3C498B28, 0x0D9541FF,
0xA8017139, 0x0CB3DE08, 0xB4E49CD8, 0x56C19064, 0xCB84617B, 0x32B670D5, 0x6C5C7448, 0xB85742D0 0xA8017139, 0x0CB3DE08, 0xB4E49CD8, 0x56C19064, 0xCB84617B, 0x32B670D5, 0x6C5C7448, 0xB85742D0
)); ]);
foreach ($dt3 as $dt3i) { foreach ($dt3 as $dt3i) {
$dt0[] = (($dt3i << 24) & 0xFF000000) | (($dt3i >> 8) & 0x00FFFFFF); $dt0[] = (($dt3i << 24) & 0xFF000000) | (($dt3i >> 8) & 0x00FFFFFF);
@ -773,14 +763,14 @@ class Rijndael extends BlockCipher
$dt2[] = (($dt3i << 8) & 0xFFFFFF00) | (($dt3i >> 24) & 0x000000FF); $dt2[] = (($dt3i << 8) & 0xFFFFFF00) | (($dt3i >> 24) & 0x000000FF);
}; };
$tables = array( $tables = [
// The Precomputed inverse mixColumns tables dt0 - dt3 // The Precomputed inverse mixColumns tables dt0 - dt3
$dt0, $dt0,
$dt1, $dt1,
$dt2, $dt2,
$dt3, $dt3,
// The inverse SubByte S-Box // The inverse SubByte S-Box
array( [
0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
@ -797,8 +787,8 @@ class Rijndael extends BlockCipher
0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
) ]
); ];
} }
return $tables; return $tables;
} }
@ -806,174 +796,142 @@ class Rijndael extends BlockCipher
/** /**
* Setup the performance-optimized function for de/encrypt() * Setup the performance-optimized function for de/encrypt()
* *
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt() * @see \phpseclib\Crypt\Common\SymmetricKey::setupInlineCrypt()
* @access private * @access private
*/ */
function _setupInlineCrypt() protected function setupInlineCrypt()
{ {
// Note: _setupInlineCrypt() will be called only if $this->changed === true $w = $this->w;
// So here we are'nt under the same heavy timing-stress as we are in _de/encryptBlock() or de/encrypt(). $dw = $this->dw;
// However...the here generated function- $code, stored as php callback in $this->inline_crypt, must work as fast as even possible. $init_encrypt = '';
$init_decrypt = '';
$lambda_functions =& self::_getLambdaFunctions(); $Nr = $this->Nr;
$Nb = $this->Nb;
$c = $this->c;
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function. // Generating encrypt code:
// (Currently, for Crypt_Rijndael/AES, one generated $lambda_function cost on php5.5@32bit ~80kb unfreeable mem and ~130kb on php5.5@64bit) $init_encrypt.= '
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one. static $tables;
$gen_hi_opt_code = (bool)(count($lambda_functions) < 10); if (empty($tables)) {
$tables = &$this->getTables();
}
$t0 = $tables[0];
$t1 = $tables[1];
$t2 = $tables[2];
$t3 = $tables[3];
$sbox = $tables[4];
';
// Generation of a uniqe hash for our generated code $s = 'e';
$code_hash = "Crypt_Rijndael, {$this->mode}, {$this->Nr}, {$this->Nb}"; $e = 's';
if ($gen_hi_opt_code) { $wc = $Nb - 1;
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
// Preround: addRoundKey
$encrypt_block = '$in = unpack("N*", $in);'."\n";
for ($i = 0; $i < $Nb; ++$i) {
$encrypt_block .= '$s'.$i.' = $in['.($i + 1).'] ^ '.$w[++$wc].";\n";
} }
if (!isset($lambda_functions[$code_hash])) { // Mainrounds: shiftRows + subWord + mixColumns + addRoundKey
switch (true) { for ($round = 1; $round < $Nr; ++$round) {
case $gen_hi_opt_code: list($s, $e) = [$e, $s];
// The hi-optimized $lambda_functions will use the key-words hardcoded for better performance.
$w = $this->w;
$dw = $this->dw;
$init_encrypt = '';
$init_decrypt = '';
break;
default:
for ($i = 0, $cw = count($this->w); $i < $cw; ++$i) {
$w[] = '$w[' . $i . ']';
$dw[] = '$dw[' . $i . ']';
}
$init_encrypt = '$w = $self->w;';
$init_decrypt = '$dw = $self->dw;';
}
$Nr = $this->Nr;
$Nb = $this->Nb;
$c = $this->c;
// Generating encrypt code:
$init_encrypt.= '
static $tables;
if (empty($tables)) {
$tables = &$self->_getTables();
}
$t0 = $tables[0];
$t1 = $tables[1];
$t2 = $tables[2];
$t3 = $tables[3];
$sbox = $tables[4];
';
$s = 'e';
$e = 's';
$wc = $Nb - 1;
// Preround: addRoundKey
$encrypt_block = '$in = unpack("N*", $in);'."\n";
for ($i = 0; $i < $Nb; ++$i) {
$encrypt_block .= '$s'.$i.' = $in['.($i + 1).'] ^ '.$w[++$wc].";\n";
}
// Mainrounds: shiftRows + subWord + mixColumns + addRoundKey
for ($round = 1; $round < $Nr; ++$round) {
list($s, $e) = array($e, $s);
for ($i = 0; $i < $Nb; ++$i) {
$encrypt_block.=
'$'.$e.$i.' =
$t0[($'.$s.$i .' >> 24) & 0xff] ^
$t1[($'.$s.(($i + $c[1]) % $Nb).' >> 16) & 0xff] ^
$t2[($'.$s.(($i + $c[2]) % $Nb).' >> 8) & 0xff] ^
$t3[ $'.$s.(($i + $c[3]) % $Nb).' & 0xff] ^
'.$w[++$wc].";\n";
}
}
// Finalround: subWord + shiftRows + addRoundKey
for ($i = 0; $i < $Nb; ++$i) { for ($i = 0; $i < $Nb; ++$i) {
$encrypt_block.= $encrypt_block.=
'$'.$e.$i.' = '$'.$e.$i.' =
$sbox[ $'.$e.$i.' & 0xff] | $t0[($'.$s.$i .' >> 24) & 0xff] ^
($sbox[($'.$e.$i.' >> 8) & 0xff] << 8) | $t1[($'.$s.(($i + $c[1]) % $Nb).' >> 16) & 0xff] ^
($sbox[($'.$e.$i.' >> 16) & 0xff] << 16) | $t2[($'.$s.(($i + $c[2]) % $Nb).' >> 8) & 0xff] ^
($sbox[($'.$e.$i.' >> 24) & 0xff] << 24);'."\n"; $t3[ $'.$s.(($i + $c[3]) % $Nb).' & 0xff] ^
'.$w[++$wc].";\n";
} }
$encrypt_block .= '$in = pack("N*"'."\n"; }
for ($i = 0; $i < $Nb; ++$i) {
$encrypt_block.= ', // Finalround: subWord + shiftRows + addRoundKey
($'.$e.$i .' & '.((int)0xFF000000).') ^ for ($i = 0; $i < $Nb; ++$i) {
($'.$e.(($i + $c[1]) % $Nb).' & 0x00FF0000 ) ^ $encrypt_block.=
($'.$e.(($i + $c[2]) % $Nb).' & 0x0000FF00 ) ^ '$'.$e.$i.' =
($'.$e.(($i + $c[3]) % $Nb).' & 0x000000FF ) ^ $sbox[ $'.$e.$i.' & 0xff] |
'.$w[$i]."\n"; ($sbox[($'.$e.$i.' >> 8) & 0xff] << 8) |
($sbox[($'.$e.$i.' >> 16) & 0xff] << 16) |
($sbox[($'.$e.$i.' >> 24) & 0xff] << 24);'."\n";
}
$encrypt_block .= '$in = pack("N*"'."\n";
for ($i = 0; $i < $Nb; ++$i) {
$encrypt_block.= ',
($'.$e.$i .' & '.((int)0xFF000000).') ^
($'.$e.(($i + $c[1]) % $Nb).' & 0x00FF0000 ) ^
($'.$e.(($i + $c[2]) % $Nb).' & 0x0000FF00 ) ^
($'.$e.(($i + $c[3]) % $Nb).' & 0x000000FF ) ^
'.$w[$i]."\n";
}
$encrypt_block .= ');';
// Generating decrypt code:
$init_decrypt.= '
static $invtables;
if (empty($invtables)) {
$invtables = &$this->getInvTables();
} }
$encrypt_block .= ');'; $dt0 = $invtables[0];
$dt1 = $invtables[1];
$dt2 = $invtables[2];
$dt3 = $invtables[3];
$isbox = $invtables[4];
';
// Generating decrypt code: $s = 'e';
$init_decrypt.= ' $e = 's';
static $invtables; $wc = $Nb - 1;
if (empty($invtables)) {
$invtables = &$self->_getInvTables();
}
$dt0 = $invtables[0];
$dt1 = $invtables[1];
$dt2 = $invtables[2];
$dt3 = $invtables[3];
$isbox = $invtables[4];
';
$s = 'e'; // Preround: addRoundKey
$e = 's'; $decrypt_block = '$in = unpack("N*", $in);'."\n";
$wc = $Nb - 1; for ($i = 0; $i < $Nb; ++$i) {
$decrypt_block .= '$s'.$i.' = $in['.($i + 1).'] ^ '.$dw[++$wc].';'."\n";
}
// Preround: addRoundKey // Mainrounds: shiftRows + subWord + mixColumns + addRoundKey
$decrypt_block = '$in = unpack("N*", $in);'."\n"; for ($round = 1; $round < $Nr; ++$round) {
for ($i = 0; $i < $Nb; ++$i) { list($s, $e) = [$e, $s];
$decrypt_block .= '$s'.$i.' = $in['.($i + 1).'] ^ '.$dw[++$wc].';'."\n";
}
// Mainrounds: shiftRows + subWord + mixColumns + addRoundKey
for ($round = 1; $round < $Nr; ++$round) {
list($s, $e) = array($e, $s);
for ($i = 0; $i < $Nb; ++$i) {
$decrypt_block.=
'$'.$e.$i.' =
$dt0[($'.$s.$i .' >> 24) & 0xff] ^
$dt1[($'.$s.(($Nb + $i - $c[1]) % $Nb).' >> 16) & 0xff] ^
$dt2[($'.$s.(($Nb + $i - $c[2]) % $Nb).' >> 8) & 0xff] ^
$dt3[ $'.$s.(($Nb + $i - $c[3]) % $Nb).' & 0xff] ^
'.$dw[++$wc].";\n";
}
}
// Finalround: subWord + shiftRows + addRoundKey
for ($i = 0; $i < $Nb; ++$i) { for ($i = 0; $i < $Nb; ++$i) {
$decrypt_block.= $decrypt_block.=
'$'.$e.$i.' = '$'.$e.$i.' =
$isbox[ $'.$e.$i.' & 0xff] | $dt0[($'.$s.$i .' >> 24) & 0xff] ^
($isbox[($'.$e.$i.' >> 8) & 0xff] << 8) | $dt1[($'.$s.(($Nb + $i - $c[1]) % $Nb).' >> 16) & 0xff] ^
($isbox[($'.$e.$i.' >> 16) & 0xff] << 16) | $dt2[($'.$s.(($Nb + $i - $c[2]) % $Nb).' >> 8) & 0xff] ^
($isbox[($'.$e.$i.' >> 24) & 0xff] << 24);'."\n"; $dt3[ $'.$s.(($Nb + $i - $c[3]) % $Nb).' & 0xff] ^
'.$dw[++$wc].";\n";
} }
$decrypt_block .= '$in = pack("N*"'."\n";
for ($i = 0; $i < $Nb; ++$i) {
$decrypt_block.= ',
($'.$e.$i. ' & '.((int)0xFF000000).') ^
($'.$e.(($Nb + $i - $c[1]) % $Nb).' & 0x00FF0000 ) ^
($'.$e.(($Nb + $i - $c[2]) % $Nb).' & 0x0000FF00 ) ^
($'.$e.(($Nb + $i - $c[3]) % $Nb).' & 0x000000FF ) ^
'.$dw[$i]."\n";
}
$decrypt_block .= ');';
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
array(
'init_crypt' => '',
'init_encrypt' => $init_encrypt,
'init_decrypt' => $init_decrypt,
'encrypt_block' => $encrypt_block,
'decrypt_block' => $decrypt_block
)
);
} }
$this->inline_crypt = $lambda_functions[$code_hash];
// Finalround: subWord + shiftRows + addRoundKey
for ($i = 0; $i < $Nb; ++$i) {
$decrypt_block.=
'$'.$e.$i.' =
$isbox[ $'.$e.$i.' & 0xff] |
($isbox[($'.$e.$i.' >> 8) & 0xff] << 8) |
($isbox[($'.$e.$i.' >> 16) & 0xff] << 16) |
($isbox[($'.$e.$i.' >> 24) & 0xff] << 24);'."\n";
}
$decrypt_block .= '$in = pack("N*"'."\n";
for ($i = 0; $i < $Nb; ++$i) {
$decrypt_block.= ',
($'.$e.$i. ' & '.((int)0xFF000000).') ^
($'.$e.(($Nb + $i - $c[1]) % $Nb).' & 0x00FF0000 ) ^
($'.$e.(($Nb + $i - $c[2]) % $Nb).' & 0x0000FF00 ) ^
($'.$e.(($Nb + $i - $c[3]) % $Nb).' & 0x000000FF ) ^
'.$dw[$i]."\n";
}
$decrypt_block .= ');';
$this->inline_crypt = $this->createInlineCryptFunction(
[
'init_crypt' => '',
'init_encrypt' => $init_encrypt,
'init_decrypt' => $init_decrypt,
'encrypt_block' => $encrypt_block,
'decrypt_block' => $decrypt_block
]
);
} }
} }

View File

@ -66,17 +66,7 @@ class TripleDES extends DES
* @var int * @var int
* @access private * @access private
*/ */
var $key_length = 24; protected $key_length = 24;
/**
* The default salt used by setPassword()
*
* @see \phpseclib\Crypt\Common\SymmetricKey::password_default_salt
* @see \phpseclib\Crypt\Common\SymmetricKey::setPassword()
* @var string
* @access private
*/
var $password_default_salt = 'phpseclib';
/** /**
* The mcrypt specific name of the cipher * The mcrypt specific name of the cipher
@ -86,7 +76,7 @@ class TripleDES extends DES
* @var string * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'tripledes'; protected $cipher_name_mcrypt = 'tripledes';
/** /**
* Optimizing value while CFB-encrypting * Optimizing value while CFB-encrypting
@ -95,7 +85,7 @@ class TripleDES extends DES
* @var int * @var int
* @access private * @access private
*/ */
var $cfb_init_len = 750; protected $cfb_init_len = 750;
/** /**
* max possible size of $key * max possible size of $key
@ -105,7 +95,7 @@ class TripleDES extends DES
* @var string * @var string
* @access private * @access private
*/ */
var $key_length_max = 24; protected $key_length_max = 24;
/** /**
* Internal flag whether using self::MODE_3CBC or not * Internal flag whether using self::MODE_3CBC or not
@ -113,7 +103,7 @@ class TripleDES extends DES
* @var bool * @var bool
* @access private * @access private
*/ */
var $mode_3cbc; private $mode_3cbc;
/** /**
* The \phpseclib\Crypt\DES objects * The \phpseclib\Crypt\DES objects
@ -123,7 +113,7 @@ class TripleDES extends DES
* @var array * @var array
* @access private * @access private
*/ */
var $des; private $des;
/** /**
* Default Constructor. * Default Constructor.
@ -149,7 +139,7 @@ class TripleDES extends DES
* @param int $mode * @param int $mode
* @access public * @access public
*/ */
function __construct($mode) public function __construct($mode)
{ {
switch ($mode) { switch ($mode) {
// In case of self::MODE_3CBC, we init as CRYPT_DES_MODE_CBC // In case of self::MODE_3CBC, we init as CRYPT_DES_MODE_CBC
@ -159,11 +149,11 @@ class TripleDES extends DES
$this->mode_3cbc = true; $this->mode_3cbc = true;
// This three $des'es will do the 3CBC work (if $key > 64bits) // This three $des'es will do the 3CBC work (if $key > 64bits)
$this->des = array( $this->des = [
new DES(self::MODE_CBC), new DES(self::MODE_CBC),
new DES(self::MODE_CBC), new DES(self::MODE_CBC),
new DES(self::MODE_CBC), new DES(self::MODE_CBC),
); ];
// we're going to be doing the padding, ourselves, so disable it in the \phpseclib\Crypt\DES objects // we're going to be doing the padding, ourselves, so disable it in the \phpseclib\Crypt\DES objects
$this->des[0]->disablePadding(); $this->des[0]->disablePadding();
@ -186,11 +176,11 @@ class TripleDES extends DES
* @access public * @access public
* @return bool * @return bool
*/ */
function isValidEngine($engine) public function isValidEngine($engine)
{ {
if ($engine == self::ENGINE_OPENSSL) { if ($engine == self::ENGINE_OPENSSL) {
$this->cipher_name_openssl_ecb = 'des-ede3'; $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; $this->cipher_name_openssl = $mode == 'ecb' ? 'des-ede3' : 'des-ede3-' . $mode;
} }
@ -206,7 +196,7 @@ class TripleDES extends DES
* @access public * @access public
* @param string $iv * @param string $iv
*/ */
function setIV($iv) public function setIV($iv)
{ {
parent::setIV($iv); parent::setIV($iv);
if ($this->mode_3cbc) { if ($this->mode_3cbc) {
@ -228,7 +218,7 @@ class TripleDES extends DES
* @throws \LengthException if the key length is invalid * @throws \LengthException if the key length is invalid
* @param int $length * @param int $length
*/ */
function setKeyLength($length) public function setKeyLength($length)
{ {
switch ($length) { switch ($length) {
case 128: case 128:
@ -254,7 +244,7 @@ class TripleDES extends DES
* @throws \LengthException if the key length is invalid * @throws \LengthException if the key length is invalid
* @param string $key * @param string $key
*/ */
function setKey($key) public function setKey($key)
{ {
if ($this->explicit_key_length !== false && strlen($key) != $this->explicit_key_length) { 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'); throw new \LengthException('Key length has already been set to ' . $this->explicit_key_length . ' bytes and this key is ' . strlen($key) . ' bytes');
@ -273,7 +263,7 @@ class TripleDES extends DES
$this->key = $key; $this->key = $key;
$this->key_length = strlen($key); $this->key_length = strlen($key);
$this->changed = true; $this->changed = true;
$this->_setEngine(); $this->setEngine();
if ($this->mode_3cbc) { if ($this->mode_3cbc) {
$this->des[0]->setKey(substr($key, 0, 8)); $this->des[0]->setKey(substr($key, 0, 8));
@ -290,7 +280,7 @@ class TripleDES extends DES
* @param string $plaintext * @param string $plaintext
* @return string $cipertext * @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, // 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 // except for: self::MODE_3CBC (inner chaining CBC) with a key > 64bits
@ -300,7 +290,7 @@ class TripleDES extends DES
return $this->des[2]->encrypt( return $this->des[2]->encrypt(
$this->des[1]->decrypt( $this->des[1]->decrypt(
$this->des[0]->encrypt( $this->des[0]->encrypt(
$this->_pad($plaintext) $this->pad($plaintext)
) )
) )
); );
@ -317,10 +307,10 @@ class TripleDES extends DES
* @param string $ciphertext * @param string $ciphertext
* @return string $plaintext * @return string $plaintext
*/ */
function decrypt($ciphertext) public function decrypt($ciphertext)
{ {
if ($this->mode_3cbc && strlen($this->key) > 8) { if ($this->mode_3cbc && strlen($this->key) > 8) {
return $this->_unpad( return $this->unpad(
$this->des[0]->decrypt( $this->des[0]->decrypt(
$this->des[1]->encrypt( $this->des[1]->encrypt(
$this->des[2]->decrypt( $this->des[2]->decrypt(
@ -372,7 +362,7 @@ class TripleDES extends DES
* @see self::disableContinuousBuffer() * @see self::disableContinuousBuffer()
* @access public * @access public
*/ */
function enableContinuousBuffer() public function enableContinuousBuffer()
{ {
parent::enableContinuousBuffer(); parent::enableContinuousBuffer();
if ($this->mode_3cbc) { if ($this->mode_3cbc) {
@ -391,7 +381,7 @@ class TripleDES extends DES
* @see self::enableContinuousBuffer() * @see self::enableContinuousBuffer()
* @access public * @access public
*/ */
function disableContinuousBuffer() public function disableContinuousBuffer()
{ {
parent::disableContinuousBuffer(); parent::disableContinuousBuffer();
if ($this->mode_3cbc) { if ($this->mode_3cbc) {
@ -404,11 +394,11 @@ class TripleDES extends DES
/** /**
* Creates the key schedule * Creates the key schedule
* *
* @see \phpseclib\Crypt\DES::_setupKey() * @see \phpseclib\Crypt\DES::setupKey()
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() * @see \phpseclib\Crypt\Common\SymmetricKey::setupKey()
* @access private * @access private
*/ */
function _setupKey() protected function setupKey()
{ {
switch (true) { switch (true) {
// if $key <= 64bits we configure our internal pure-php cipher engine // if $key <= 64bits we configure our internal pure-php cipher engine
@ -423,17 +413,17 @@ class TripleDES extends DES
// (only) if 3CBC is used we have, of course, to setup the $des[0-2] keys also separately. // (only) if 3CBC is used we have, of course, to setup the $des[0-2] keys also separately.
if ($this->mode_3cbc) { if ($this->mode_3cbc) {
$this->des[0]->_setupKey(); $this->des[0]->setupKey();
$this->des[1]->_setupKey(); $this->des[1]->setupKey();
$this->des[2]->_setupKey(); $this->des[2]->setupKey();
// because $des[0-2] will, now, do all the work we can return here // 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; return;
} }
} }
// setup our key // setup our key
parent::_setupKey(); parent::setupKey();
} }
/** /**
@ -445,7 +435,7 @@ class TripleDES extends DES
* @access public * @access public
* @return int * @return int
*/ */
function setPreferredEngine($engine) public function setPreferredEngine($engine)
{ {
if ($this->mode_3cbc) { if ($this->mode_3cbc) {
$this->des[0]->setPreferredEngine($engine); $this->des[0]->setPreferredEngine($engine);
@ -455,4 +445,15 @@ class TripleDES extends DES
return parent::setPreferredEngine($engine); return parent::setPreferredEngine($engine);
} }
/**
* Returns the class that defines the private methods
*
* @access private
* @return string
*/
protected function getClassContext()
{
return 'phpseclib\Crypt\DES';
}
} }

View File

@ -56,7 +56,7 @@ class Twofish extends BlockCipher
* @var string * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'twofish'; protected $cipher_name_mcrypt = 'twofish';
/** /**
* Optimizing value while CFB-encrypting * Optimizing value while CFB-encrypting
@ -65,7 +65,7 @@ class Twofish extends BlockCipher
* @var int * @var int
* @access private * @access private
*/ */
var $cfb_init_len = 800; protected $cfb_init_len = 800;
/** /**
* Q-Table * Q-Table
@ -73,7 +73,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $q0 = array( private $q0 = [
0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, 0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76,
0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38, 0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38,
0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C, 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C,
@ -106,7 +106,7 @@ class Twofish extends BlockCipher
0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4, 0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4,
0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00, 0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00,
0x6F, 0x9D, 0x36, 0x42, 0x4A, 0x5E, 0xC1, 0xE0 0x6F, 0x9D, 0x36, 0x42, 0x4A, 0x5E, 0xC1, 0xE0
); ];
/** /**
* Q-Table * Q-Table
@ -114,7 +114,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $q1 = array( private $q1 = [
0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, 0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8,
0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B, 0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B,
0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1, 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1,
@ -147,7 +147,7 @@ class Twofish extends BlockCipher
0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9, 0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9,
0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2, 0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2,
0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xBE, 0x91 0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xBE, 0x91
); ];
/** /**
* M-Table * M-Table
@ -155,7 +155,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $m0 = array( private $m0 = [
0xBCBC3275, 0xECEC21F3, 0x202043C6, 0xB3B3C9F4, 0xDADA03DB, 0x02028B7B, 0xE2E22BFB, 0x9E9EFAC8, 0xBCBC3275, 0xECEC21F3, 0x202043C6, 0xB3B3C9F4, 0xDADA03DB, 0x02028B7B, 0xE2E22BFB, 0x9E9EFAC8,
0xC9C9EC4A, 0xD4D409D3, 0x18186BE6, 0x1E1E9F6B, 0x98980E45, 0xB2B2387D, 0xA6A6D2E8, 0x2626B74B, 0xC9C9EC4A, 0xD4D409D3, 0x18186BE6, 0x1E1E9F6B, 0x98980E45, 0xB2B2387D, 0xA6A6D2E8, 0x2626B74B,
0x3C3C57D6, 0x93938A32, 0x8282EED8, 0x525298FD, 0x7B7BD437, 0xBBBB3771, 0x5B5B97F1, 0x474783E1, 0x3C3C57D6, 0x93938A32, 0x8282EED8, 0x525298FD, 0x7B7BD437, 0xBBBB3771, 0x5B5B97F1, 0x474783E1,
@ -188,7 +188,7 @@ class Twofish extends BlockCipher
0xABABA212, 0x6F6F3EA2, 0xE6E6540D, 0xDBDBF252, 0x92927BBB, 0xB7B7B602, 0x6969CA2F, 0x3939D9A9, 0xABABA212, 0x6F6F3EA2, 0xE6E6540D, 0xDBDBF252, 0x92927BBB, 0xB7B7B602, 0x6969CA2F, 0x3939D9A9,
0xD3D30CD7, 0xA7A72361, 0xA2A2AD1E, 0xC3C399B4, 0x6C6C4450, 0x07070504, 0x04047FF6, 0x272746C2, 0xD3D30CD7, 0xA7A72361, 0xA2A2AD1E, 0xC3C399B4, 0x6C6C4450, 0x07070504, 0x04047FF6, 0x272746C2,
0xACACA716, 0xD0D07625, 0x50501386, 0xDCDCF756, 0x84841A55, 0xE1E15109, 0x7A7A25BE, 0x1313EF91 0xACACA716, 0xD0D07625, 0x50501386, 0xDCDCF756, 0x84841A55, 0xE1E15109, 0x7A7A25BE, 0x1313EF91
); ];
/** /**
* M-Table * M-Table
@ -196,7 +196,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $m1 = array( private $m1 = [
0xA9D93939, 0x67901717, 0xB3719C9C, 0xE8D2A6A6, 0x04050707, 0xFD985252, 0xA3658080, 0x76DFE4E4, 0xA9D93939, 0x67901717, 0xB3719C9C, 0xE8D2A6A6, 0x04050707, 0xFD985252, 0xA3658080, 0x76DFE4E4,
0x9A084545, 0x92024B4B, 0x80A0E0E0, 0x78665A5A, 0xE4DDAFAF, 0xDDB06A6A, 0xD1BF6363, 0x38362A2A, 0x9A084545, 0x92024B4B, 0x80A0E0E0, 0x78665A5A, 0xE4DDAFAF, 0xDDB06A6A, 0xD1BF6363, 0x38362A2A,
0x0D54E6E6, 0xC6432020, 0x3562CCCC, 0x98BEF2F2, 0x181E1212, 0xF724EBEB, 0xECD7A1A1, 0x6C774141, 0x0D54E6E6, 0xC6432020, 0x3562CCCC, 0x98BEF2F2, 0x181E1212, 0xF724EBEB, 0xECD7A1A1, 0x6C774141,
@ -229,7 +229,7 @@ class Twofish extends BlockCipher
0xC8FA9E9E, 0xA882D6D6, 0x2BCF6E6E, 0x40507070, 0xDCEB8585, 0xFE750A0A, 0x328A9393, 0xA48DDFDF, 0xC8FA9E9E, 0xA882D6D6, 0x2BCF6E6E, 0x40507070, 0xDCEB8585, 0xFE750A0A, 0x328A9393, 0xA48DDFDF,
0xCA4C2929, 0x10141C1C, 0x2173D7D7, 0xF0CCB4B4, 0xD309D4D4, 0x5D108A8A, 0x0FE25151, 0x00000000, 0xCA4C2929, 0x10141C1C, 0x2173D7D7, 0xF0CCB4B4, 0xD309D4D4, 0x5D108A8A, 0x0FE25151, 0x00000000,
0x6F9A1919, 0x9DE01A1A, 0x368F9494, 0x42E6C7C7, 0x4AECC9C9, 0x5EFDD2D2, 0xC1AB7F7F, 0xE0D8A8A8 0x6F9A1919, 0x9DE01A1A, 0x368F9494, 0x42E6C7C7, 0x4AECC9C9, 0x5EFDD2D2, 0xC1AB7F7F, 0xE0D8A8A8
); ];
/** /**
* M-Table * M-Table
@ -237,7 +237,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $m2 = array( private $m2 = [
0xBC75BC32, 0xECF3EC21, 0x20C62043, 0xB3F4B3C9, 0xDADBDA03, 0x027B028B, 0xE2FBE22B, 0x9EC89EFA, 0xBC75BC32, 0xECF3EC21, 0x20C62043, 0xB3F4B3C9, 0xDADBDA03, 0x027B028B, 0xE2FBE22B, 0x9EC89EFA,
0xC94AC9EC, 0xD4D3D409, 0x18E6186B, 0x1E6B1E9F, 0x9845980E, 0xB27DB238, 0xA6E8A6D2, 0x264B26B7, 0xC94AC9EC, 0xD4D3D409, 0x18E6186B, 0x1E6B1E9F, 0x9845980E, 0xB27DB238, 0xA6E8A6D2, 0x264B26B7,
0x3CD63C57, 0x9332938A, 0x82D882EE, 0x52FD5298, 0x7B377BD4, 0xBB71BB37, 0x5BF15B97, 0x47E14783, 0x3CD63C57, 0x9332938A, 0x82D882EE, 0x52FD5298, 0x7B377BD4, 0xBB71BB37, 0x5BF15B97, 0x47E14783,
@ -270,7 +270,7 @@ class Twofish extends BlockCipher
0xAB12ABA2, 0x6FA26F3E, 0xE60DE654, 0xDB52DBF2, 0x92BB927B, 0xB702B7B6, 0x692F69CA, 0x39A939D9, 0xAB12ABA2, 0x6FA26F3E, 0xE60DE654, 0xDB52DBF2, 0x92BB927B, 0xB702B7B6, 0x692F69CA, 0x39A939D9,
0xD3D7D30C, 0xA761A723, 0xA21EA2AD, 0xC3B4C399, 0x6C506C44, 0x07040705, 0x04F6047F, 0x27C22746, 0xD3D7D30C, 0xA761A723, 0xA21EA2AD, 0xC3B4C399, 0x6C506C44, 0x07040705, 0x04F6047F, 0x27C22746,
0xAC16ACA7, 0xD025D076, 0x50865013, 0xDC56DCF7, 0x8455841A, 0xE109E151, 0x7ABE7A25, 0x139113EF 0xAC16ACA7, 0xD025D076, 0x50865013, 0xDC56DCF7, 0x8455841A, 0xE109E151, 0x7ABE7A25, 0x139113EF
); ];
/** /**
* M-Table * M-Table
@ -278,7 +278,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $m3 = array( private $m3 = [
0xD939A9D9, 0x90176790, 0x719CB371, 0xD2A6E8D2, 0x05070405, 0x9852FD98, 0x6580A365, 0xDFE476DF, 0xD939A9D9, 0x90176790, 0x719CB371, 0xD2A6E8D2, 0x05070405, 0x9852FD98, 0x6580A365, 0xDFE476DF,
0x08459A08, 0x024B9202, 0xA0E080A0, 0x665A7866, 0xDDAFE4DD, 0xB06ADDB0, 0xBF63D1BF, 0x362A3836, 0x08459A08, 0x024B9202, 0xA0E080A0, 0x665A7866, 0xDDAFE4DD, 0xB06ADDB0, 0xBF63D1BF, 0x362A3836,
0x54E60D54, 0x4320C643, 0x62CC3562, 0xBEF298BE, 0x1E12181E, 0x24EBF724, 0xD7A1ECD7, 0x77416C77, 0x54E60D54, 0x4320C643, 0x62CC3562, 0xBEF298BE, 0x1E12181E, 0x24EBF724, 0xD7A1ECD7, 0x77416C77,
@ -311,7 +311,7 @@ class Twofish extends BlockCipher
0xFA9EC8FA, 0x82D6A882, 0xCF6E2BCF, 0x50704050, 0xEB85DCEB, 0x750AFE75, 0x8A93328A, 0x8DDFA48D, 0xFA9EC8FA, 0x82D6A882, 0xCF6E2BCF, 0x50704050, 0xEB85DCEB, 0x750AFE75, 0x8A93328A, 0x8DDFA48D,
0x4C29CA4C, 0x141C1014, 0x73D72173, 0xCCB4F0CC, 0x09D4D309, 0x108A5D10, 0xE2510FE2, 0x00000000, 0x4C29CA4C, 0x141C1014, 0x73D72173, 0xCCB4F0CC, 0x09D4D309, 0x108A5D10, 0xE2510FE2, 0x00000000,
0x9A196F9A, 0xE01A9DE0, 0x8F94368F, 0xE6C742E6, 0xECC94AEC, 0xFDD25EFD, 0xAB7FC1AB, 0xD8A8E0D8 0x9A196F9A, 0xE01A9DE0, 0x8F94368F, 0xE6C742E6, 0xECC94AEC, 0xFDD25EFD, 0xAB7FC1AB, 0xD8A8E0D8
); ];
/** /**
* The Key Schedule Array * The Key Schedule Array
@ -319,7 +319,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $K = array(); private $K = [];
/** /**
* The Key depended S-Table 0 * The Key depended S-Table 0
@ -327,7 +327,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $S0 = array(); private $S0 = [];
/** /**
* The Key depended S-Table 1 * The Key depended S-Table 1
@ -335,7 +335,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $S1 = array(); private $S1 = [];
/** /**
* The Key depended S-Table 2 * The Key depended S-Table 2
@ -343,7 +343,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $S2 = array(); private $S2 = [];
/** /**
* The Key depended S-Table 3 * The Key depended S-Table 3
@ -351,7 +351,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $S3 = array(); private $S3 = [];
/** /**
* Holds the last used key * Holds the last used key
@ -359,7 +359,7 @@ class Twofish extends BlockCipher
* @var array * @var array
* @access private * @access private
*/ */
var $kl; private $kl;
/** /**
* The Key Length (in bytes) * The Key Length (in bytes)
@ -368,7 +368,7 @@ class Twofish extends BlockCipher
* @var int * @var int
* @access private * @access private
*/ */
var $key_length = 16; protected $key_length = 16;
/** /**
* Default Constructor. * Default Constructor.
@ -377,7 +377,7 @@ class Twofish extends BlockCipher
* @access public * @access public
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided * @throws \InvalidArgumentException if an invalid / unsupported mode is provided
*/ */
function __construct($mode) public function __construct($mode)
{ {
if ($mode == self::MODE_STREAM) { if ($mode == self::MODE_STREAM) {
throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode'); throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode');
@ -394,7 +394,7 @@ class Twofish extends BlockCipher
* @access public * @access public
* @param int $length * @param int $length
*/ */
function setKeyLength($length) public function setKeyLength($length)
{ {
switch ($length) { switch ($length) {
case 128: case 128:
@ -418,7 +418,7 @@ class Twofish extends BlockCipher
* @param string $key * @param string $key
* @throws \LengthException if the key length isn't supported * @throws \LengthException if the key length isn't supported
*/ */
function setKey($key) public function setKey($key)
{ {
switch (strlen($key)) { switch (strlen($key)) {
case 16: case 16:
@ -438,13 +438,13 @@ class Twofish extends BlockCipher
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey() * @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey()
* @access private * @access private
*/ */
function _setupKey() protected function setupKey()
{ {
if (isset($this->kl['key']) && $this->key === $this->kl['key']) { if (isset($this->kl['key']) && $this->key === $this->kl['key']) {
// already expanded // already expanded
return; return;
} }
$this->kl = array('key' => $this->key); $this->kl = ['key' => $this->key];
/* Key expanding and generating the key-depended s-boxes */ /* Key expanding and generating the key-depended s-boxes */
$le_longs = unpack('V*', $this->key); $le_longs = unpack('V*', $this->key);
@ -456,12 +456,12 @@ class Twofish extends BlockCipher
$q0 = $this->q0; $q0 = $this->q0;
$q1 = $this->q1; $q1 = $this->q1;
$K = $S0 = $S1 = $S2 = $S3 = array(); $K = $S0 = $S1 = $S2 = $S3 = [];
switch (strlen($this->key)) { switch (strlen($this->key)) {
case 16: case 16:
list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[1], $le_longs[2]); 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($s3, $s2, $s1, $s0) = $this->mdsrem($le_longs[3], $le_longs[4]);
for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) {
$A = $m0[$q0[$q0[$i] ^ $key[ 9]] ^ $key[1]] ^ $A = $m0[$q0[$q0[$i] ^ $key[ 9]] ^ $key[1]] ^
$m1[$q0[$q1[$i] ^ $key[10]] ^ $key[2]] ^ $m1[$q0[$q1[$i] ^ $key[10]] ^ $key[2]] ^
@ -483,9 +483,9 @@ class Twofish extends BlockCipher
} }
break; break;
case 24: case 24:
list($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[1], $le_longs[2]); 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($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($s3, $s2, $s1, $s0) = $this->mdsrem($le_longs[5], $le_longs[6]);
for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) {
$A = $m0[$q0[$q0[$q1[$i] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^ $A = $m0[$q0[$q0[$q1[$i] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^
$m1[$q0[$q1[$q1[$i] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^ $m1[$q0[$q1[$q1[$i] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^
@ -507,10 +507,10 @@ class Twofish extends BlockCipher
} }
break; break;
default: // 32 default: // 32
list($sf, $se, $sd, $sc) = $this->_mdsrem($le_longs[1], $le_longs[2]); 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($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($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($s3, $s2, $s1, $s0) = $this->mdsrem($le_longs[7], $le_longs[8]);
for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { 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]] ^ $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]] ^ $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 * @param string $B
* @return array * @return array
*/ */
function _mdsrem($A, $B) private function mdsrem($A, $B)
{ {
// No gain by unrolling this loop. // No gain by unrolling this loop.
for ($i = 0; $i < 8; ++$i) { for ($i = 0; $i < 8; ++$i) {
@ -580,11 +580,11 @@ class Twofish extends BlockCipher
$B^= ($u << 24) | ($u << 8); $B^= ($u << 24) | ($u << 8);
} }
return array( return [
0xff & $B >> 24, 0xff & $B >> 24,
0xff & $B >> 16, 0xff & $B >> 16,
0xff & $B >> 8, 0xff & $B >> 8,
0xff & $B); 0xff & $B];
} }
/** /**
@ -594,7 +594,7 @@ class Twofish extends BlockCipher
* @param string $in * @param string $in
* @return string * @return string
*/ */
function _encryptBlock($in) protected function encryptBlock($in)
{ {
$S0 = $this->S0; $S0 = $this->S0;
$S1 = $this->S1; $S1 = $this->S1;
@ -650,7 +650,7 @@ class Twofish extends BlockCipher
* @param string $in * @param string $in
* @return string * @return string
*/ */
function _decryptBlock($in) protected function decryptBlock($in)
{ {
$S0 = $this->S0; $S0 = $this->S0;
$S1 = $this->S1; $S1 = $this->S1;
@ -705,144 +705,113 @@ class Twofish extends BlockCipher
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt() * @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt()
* @access private * @access private
*/ */
function _setupInlineCrypt() protected function setupInlineCrypt()
{ {
$lambda_functions =& self::_getLambdaFunctions(); $K = $this->K;
$init_crypt = '
// Max. 10 Ultra-Hi-optimized inline-crypt functions. After that, we'll (still) create very fast code, but not the ultimate fast one. static $S0, $S1, $S2, $S3;
// (Currently, for Crypt_Twofish, one generated $lambda_function cost on php5.5@32bit ~140kb unfreeable mem and ~240kb on php5.5@64bit) if (!$S0) {
$gen_hi_opt_code = (bool)(count($lambda_functions) < 10); for ($i = 0; $i < 256; ++$i) {
$S0[] = (int)$this->S0[$i];
// Generation of a unique hash for our generated code $S1[] = (int)$this->S1[$i];
$code_hash = "Crypt_Twofish, {$this->mode}"; $S2[] = (int)$this->S2[$i];
if ($gen_hi_opt_code) { $S3[] = (int)$this->S3[$i];
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); }
}
if (!isset($lambda_functions[$code_hash])) {
switch (true) {
case $gen_hi_opt_code:
$K = $this->K;
$init_crypt = '
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];
}
}
';
break;
default:
$K = array();
for ($i = 0; $i < 40; ++$i) {
$K[] = '$K_' . $i;
}
$init_crypt = '
$S0 = $self->S0;
$S1 = $self->S1;
$S2 = $self->S2;
$S3 = $self->S3;
list(' . implode(',', $K) . ') = $self->K;
';
} }
';
// Generating encrypt code: // Generating encrypt code:
$encrypt_block = ' $encrypt_block = '
$in = unpack("V4", $in); $in = unpack("V4", $in);
$R0 = '.$K[0].' ^ $in[1]; $R0 = '.$K[0].' ^ $in[1];
$R1 = '.$K[1].' ^ $in[2]; $R1 = '.$K[1].' ^ $in[2];
$R2 = '.$K[2].' ^ $in[3]; $R2 = '.$K[2].' ^ $in[3];
$R3 = '.$K[3].' ^ $in[4]; $R3 = '.$K[3].' ^ $in[4];
'; ';
for ($ki = 7, $i = 0; $i < 8; ++$i) { for ($ki = 7, $i = 0; $i < 8; ++$i) {
$encrypt_block.= '
$t0 = $S0[ $R0 & 0xff] ^
$S1[($R0 >> 8) & 0xff] ^
$S2[($R0 >> 16) & 0xff] ^
$S3[($R0 >> 24) & 0xff];
$t1 = $S0[($R1 >> 24) & 0xff] ^
$S1[ $R1 & 0xff] ^
$S2[($R1 >> 8) & 0xff] ^
$S3[($R1 >> 16) & 0xff];
$R2^= ($t0 + $t1 + '.$K[++$ki].');
$R2 = ($R2 >> 1 & 0x7fffffff) | ($R2 << 31);
$R3 = ((($R3 >> 31) & 1) | ($R3 << 1)) ^ ($t0 + ($t1 << 1) + '.$K[++$ki].');
$t0 = $S0[ $R2 & 0xff] ^
$S1[($R2 >> 8) & 0xff] ^
$S2[($R2 >> 16) & 0xff] ^
$S3[($R2 >> 24) & 0xff];
$t1 = $S0[($R3 >> 24) & 0xff] ^
$S1[ $R3 & 0xff] ^
$S2[($R3 >> 8) & 0xff] ^
$S3[($R3 >> 16) & 0xff];
$R0^= ($t0 + $t1 + '.$K[++$ki].');
$R0 = ($R0 >> 1 & 0x7fffffff) | ($R0 << 31);
$R1 = ((($R1 >> 31) & 1) | ($R1 << 1)) ^ ($t0 + ($t1 << 1) + '.$K[++$ki].');
';
}
$encrypt_block.= ' $encrypt_block.= '
$in = pack("V4", '.$K[4].' ^ $R2, $t0 = $S0[ $R0 & 0xff] ^
'.$K[5].' ^ $R3, $S1[($R0 >> 8) & 0xff] ^
'.$K[6].' ^ $R0, $S2[($R0 >> 16) & 0xff] ^
'.$K[7].' ^ $R1); $S3[($R0 >> 24) & 0xff];
'; $t1 = $S0[($R1 >> 24) & 0xff] ^
$S1[ $R1 & 0xff] ^
$S2[($R1 >> 8) & 0xff] ^
$S3[($R1 >> 16) & 0xff];
$R2^= ($t0 + $t1 + '.$K[++$ki].');
$R2 = ($R2 >> 1 & 0x7fffffff) | ($R2 << 31);
$R3 = ((($R3 >> 31) & 1) | ($R3 << 1)) ^ ($t0 + ($t1 << 1) + '.$K[++$ki].');
// Generating decrypt code: $t0 = $S0[ $R2 & 0xff] ^
$decrypt_block = ' $S1[($R2 >> 8) & 0xff] ^
$in = unpack("V4", $in); $S2[($R2 >> 16) & 0xff] ^
$R0 = '.$K[4].' ^ $in[1]; $S3[($R2 >> 24) & 0xff];
$R1 = '.$K[5].' ^ $in[2]; $t1 = $S0[($R3 >> 24) & 0xff] ^
$R2 = '.$K[6].' ^ $in[3]; $S1[ $R3 & 0xff] ^
$R3 = '.$K[7].' ^ $in[4]; $S2[($R3 >> 8) & 0xff] ^
$S3[($R3 >> 16) & 0xff];
$R0^= ($t0 + $t1 + '.$K[++$ki].');
$R0 = ($R0 >> 1 & 0x7fffffff) | ($R0 << 31);
$R1 = ((($R1 >> 31) & 1) | ($R1 << 1)) ^ ($t0 + ($t1 << 1) + '.$K[++$ki].');
'; ';
for ($ki = 40, $i = 0; $i < 8; ++$i) {
$decrypt_block.= '
$t0 = $S0[$R0 & 0xff] ^
$S1[$R0 >> 8 & 0xff] ^
$S2[$R0 >> 16 & 0xff] ^
$S3[$R0 >> 24 & 0xff];
$t1 = $S0[$R1 >> 24 & 0xff] ^
$S1[$R1 & 0xff] ^
$S2[$R1 >> 8 & 0xff] ^
$S3[$R1 >> 16 & 0xff];
$R3^= $t0 + ($t1 << 1) + '.$K[--$ki].';
$R3 = $R3 >> 1 & 0x7fffffff | $R3 << 31;
$R2 = ($R2 >> 31 & 0x1 | $R2 << 1) ^ ($t0 + $t1 + '.$K[--$ki].');
$t0 = $S0[$R2 & 0xff] ^
$S1[$R2 >> 8 & 0xff] ^
$S2[$R2 >> 16 & 0xff] ^
$S3[$R2 >> 24 & 0xff];
$t1 = $S0[$R3 >> 24 & 0xff] ^
$S1[$R3 & 0xff] ^
$S2[$R3 >> 8 & 0xff] ^
$S3[$R3 >> 16 & 0xff];
$R1^= $t0 + ($t1 << 1) + '.$K[--$ki].';
$R1 = $R1 >> 1 & 0x7fffffff | $R1 << 31;
$R0 = ($R0 >> 31 & 0x1 | $R0 << 1) ^ ($t0 + $t1 + '.$K[--$ki].');
';
}
$decrypt_block.= '
$in = pack("V4", '.$K[0].' ^ $R2,
'.$K[1].' ^ $R3,
'.$K[2].' ^ $R0,
'.$K[3].' ^ $R1);
';
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
array(
'init_crypt' => $init_crypt,
'init_encrypt' => '',
'init_decrypt' => '',
'encrypt_block' => $encrypt_block,
'decrypt_block' => $decrypt_block
)
);
} }
$this->inline_crypt = $lambda_functions[$code_hash]; $encrypt_block.= '
$in = pack("V4", '.$K[4].' ^ $R2,
'.$K[5].' ^ $R3,
'.$K[6].' ^ $R0,
'.$K[7].' ^ $R1);
';
// Generating decrypt code:
$decrypt_block = '
$in = unpack("V4", $in);
$R0 = '.$K[4].' ^ $in[1];
$R1 = '.$K[5].' ^ $in[2];
$R2 = '.$K[6].' ^ $in[3];
$R3 = '.$K[7].' ^ $in[4];
';
for ($ki = 40, $i = 0; $i < 8; ++$i) {
$decrypt_block.= '
$t0 = $S0[$R0 & 0xff] ^
$S1[$R0 >> 8 & 0xff] ^
$S2[$R0 >> 16 & 0xff] ^
$S3[$R0 >> 24 & 0xff];
$t1 = $S0[$R1 >> 24 & 0xff] ^
$S1[$R1 & 0xff] ^
$S2[$R1 >> 8 & 0xff] ^
$S3[$R1 >> 16 & 0xff];
$R3^= $t0 + ($t1 << 1) + '.$K[--$ki].';
$R3 = $R3 >> 1 & 0x7fffffff | $R3 << 31;
$R2 = ($R2 >> 31 & 0x1 | $R2 << 1) ^ ($t0 + $t1 + '.$K[--$ki].');
$t0 = $S0[$R2 & 0xff] ^
$S1[$R2 >> 8 & 0xff] ^
$S2[$R2 >> 16 & 0xff] ^
$S3[$R2 >> 24 & 0xff];
$t1 = $S0[$R3 >> 24 & 0xff] ^
$S1[$R3 & 0xff] ^
$S2[$R3 >> 8 & 0xff] ^
$S3[$R3 >> 16 & 0xff];
$R1^= $t0 + ($t1 << 1) + '.$K[--$ki].';
$R1 = $R1 >> 1 & 0x7fffffff | $R1 << 31;
$R0 = ($R0 >> 31 & 0x1 | $R0 << 1) ^ ($t0 + $t1 + '.$K[--$ki].');
';
}
$decrypt_block.= '
$in = pack("V4", '.$K[0].' ^ $R2,
'.$K[1].' ^ $R3,
'.$K[2].' ^ $R0,
'.$K[3].' ^ $R1);
';
$this->inline_crypt = $this->createInlineCryptFunction(
[
'init_crypt' => $init_crypt,
'init_encrypt' => '',
'init_decrypt' => '',
'encrypt_block' => $encrypt_block,
'decrypt_block' => $decrypt_block
]
);
} }
} }

View File

@ -35,7 +35,7 @@ class ANSI
* @var int * @var int
* @access private * @access private
*/ */
var $max_x; private $max_x;
/** /**
* Max Height * Max Height
@ -43,7 +43,7 @@ class ANSI
* @var int * @var int
* @access private * @access private
*/ */
var $max_y; private $max_y;
/** /**
* Max History * Max History
@ -51,7 +51,7 @@ class ANSI
* @var int * @var int
* @access private * @access private
*/ */
var $max_history; private $max_history;
/** /**
* History * History
@ -59,7 +59,7 @@ class ANSI
* @var array * @var array
* @access private * @access private
*/ */
var $history; private $history;
/** /**
* History Attributes * History Attributes
@ -67,7 +67,7 @@ class ANSI
* @var array * @var array
* @access private * @access private
*/ */
var $history_attrs; private $history_attrs;
/** /**
* Current Column * Current Column
@ -75,7 +75,7 @@ class ANSI
* @var int * @var int
* @access private * @access private
*/ */
var $x; private $x;
/** /**
* Current Row * Current Row
@ -83,7 +83,7 @@ class ANSI
* @var int * @var int
* @access private * @access private
*/ */
var $y; private $y;
/** /**
* Old Column * Old Column
@ -91,7 +91,7 @@ class ANSI
* @var int * @var int
* @access private * @access private
*/ */
var $old_x; private $old_x;
/** /**
* Old Row * Old Row
@ -99,7 +99,7 @@ class ANSI
* @var int * @var int
* @access private * @access private
*/ */
var $old_y; private $old_y;
/** /**
* An empty attribute cell * An empty attribute cell
@ -107,7 +107,7 @@ class ANSI
* @var object * @var object
* @access private * @access private
*/ */
var $base_attr_cell; private $base_attr_cell;
/** /**
* The current attribute cell * The current attribute cell
@ -115,7 +115,7 @@ class ANSI
* @var object * @var object
* @access private * @access private
*/ */
var $attr_cell; private $attr_cell;
/** /**
* An empty attribute row * An empty attribute row
@ -123,7 +123,7 @@ class ANSI
* @var array * @var array
* @access private * @access private
*/ */
var $attr_row; private $attr_row;
/** /**
* The current screen text * The current screen text
@ -131,7 +131,7 @@ class ANSI
* @var array * @var array
* @access private * @access private
*/ */
var $screen; private $screen;
/** /**
* The current screen attributes * The current screen attributes
@ -139,7 +139,7 @@ class ANSI
* @var array * @var array
* @access private * @access private
*/ */
var $attrs; private $attrs;
/** /**
* Current ANSI code * Current ANSI code
@ -147,7 +147,7 @@ class ANSI
* @var string * @var string
* @access private * @access private
*/ */
var $ansi; private $ansi;
/** /**
* Tokenization * Tokenization
@ -155,7 +155,7 @@ class ANSI
* @var array * @var array
* @access private * @access private
*/ */
var $tokenization; private $tokenization;
/** /**
* Default Constructor. * Default Constructor.
@ -163,7 +163,7 @@ class ANSI
* @return \phpseclib\File\ANSI * @return \phpseclib\File\ANSI
* @access public * @access public
*/ */
function __construct() public function __construct()
{ {
$attr_cell = new \stdClass(); $attr_cell = new \stdClass();
$attr_cell->bold = false; $attr_cell->bold = false;
@ -188,12 +188,12 @@ class ANSI
* @param int $y * @param int $y
* @access public * @access public
*/ */
function setDimensions($x, $y) public function setDimensions($x, $y)
{ {
$this->max_x = $x - 1; $this->max_x = $x - 1;
$this->max_y = $y - 1; $this->max_y = $y - 1;
$this->x = $this->y = 0; $this->x = $this->y = 0;
$this->history = $this->history_attrs = array(); $this->history = $this->history_attrs = [];
$this->attr_row = array_fill(0, $this->max_x + 2, $this->base_attr_cell); $this->attr_row = array_fill(0, $this->max_x + 2, $this->base_attr_cell);
$this->screen = array_fill(0, $this->max_y + 1, ''); $this->screen = array_fill(0, $this->max_y + 1, '');
$this->attrs = array_fill(0, $this->max_y + 1, $this->attr_row); $this->attrs = array_fill(0, $this->max_y + 1, $this->attr_row);
@ -207,7 +207,7 @@ class ANSI
* @param int $y * @param int $y
* @access public * @access public
*/ */
function setHistory($history) public function setHistory($history)
{ {
$this->max_history = $history; $this->max_history = $history;
} }
@ -218,7 +218,7 @@ class ANSI
* @param string $source * @param string $source
* @access public * @access public
*/ */
function loadString($source) public function loadString($source)
{ {
$this->setDimensions($this->max_x + 1, $this->max_y + 1); $this->setDimensions($this->max_x + 1, $this->max_y + 1);
$this->appendString($source); $this->appendString($source);
@ -230,9 +230,9 @@ class ANSI
* @param string $source * @param string $source
* @access public * @access public
*/ */
function appendString($source) public function appendString($source)
{ {
$this->tokenization = array(''); $this->tokenization = [''];
for ($i = 0; $i < strlen($source); $i++) { for ($i = 0; $i < strlen($source); $i++) {
if (strlen($this->ansi)) { if (strlen($this->ansi)) {
$this->ansi.= $source[$i]; $this->ansi.= $source[$i];
@ -283,7 +283,7 @@ class ANSI
case "\x1B(B": // set united states g0 character set case "\x1B(B": // set united states g0 character set
break; break;
case "\x1BE": // Move to next line case "\x1BE": // Move to next line
$this->_newLine(); $this->newLine();
$this->x = 0; $this->x = 0;
break; break;
default: default:
@ -379,7 +379,7 @@ class ANSI
$this->x = 0; $this->x = 0;
break; break;
case "\n": case "\n":
$this->_newLine(); $this->newLine();
break; break;
case "\x08": // backspace case "\x08": // backspace
if ($this->x) { if ($this->x) {
@ -431,17 +431,17 @@ class ANSI
* *
* @access private * @access private
*/ */
function _newLine() private function newLine()
{ {
//if ($this->y < $this->max_y) { //if ($this->y < $this->max_y) {
// $this->y++; // $this->y++;
//} //}
while ($this->y >= $this->max_y) { while ($this->y >= $this->max_y) {
$this->history = array_merge($this->history, array(array_shift($this->screen))); $this->history = array_merge($this->history, [array_shift($this->screen)]);
$this->screen[] = ''; $this->screen[] = '';
$this->history_attrs = array_merge($this->history_attrs, array(array_shift($this->attrs))); $this->history_attrs = array_merge($this->history_attrs, [array_shift($this->attrs)]);
$this->attrs[] = $this->attr_row; $this->attrs[] = $this->attr_row;
if (count($this->history) >= $this->max_history) { if (count($this->history) >= $this->max_history) {
@ -460,7 +460,7 @@ class ANSI
* @access private * @access private
* @return string * @return string
*/ */
function _processCoordinate($last_attr, $cur_attr, $char) private function processCoordinate($last_attr, $cur_attr, $char)
{ {
$output = ''; $output = '';
@ -517,21 +517,21 @@ class ANSI
* @access private * @access private
* @return string * @return string
*/ */
function _getScreen() private function getScreenHelper()
{ {
$output = ''; $output = '';
$last_attr = $this->base_attr_cell; $last_attr = $this->base_attr_cell;
for ($i = 0; $i <= $this->max_y; $i++) { for ($i = 0; $i <= $this->max_y; $i++) {
for ($j = 0; $j <= $this->max_x; $j++) { for ($j = 0; $j <= $this->max_x; $j++) {
$cur_attr = $this->attrs[$i][$j]; $cur_attr = $this->attrs[$i][$j];
$output.= $this->_processCoordinate($last_attr, $cur_attr, isset($this->screen[$i][$j]) ? $this->screen[$i][$j] : ''); $output.= $this->processCoordinate($last_attr, $cur_attr, isset($this->screen[$i][$j]) ? $this->screen[$i][$j] : '');
$last_attr = $this->attrs[$i][$j]; $last_attr = $this->attrs[$i][$j];
} }
$output.= "\r\n"; $output.= "\r\n";
} }
$output = substr($output, 0, -2); $output = substr($output, 0, -2);
// close any remaining open tags // close any remaining open tags
$output.= $this->_processCoordinate($last_attr, $this->base_attr_cell, ''); $output.= $this->processCoordinate($last_attr, $this->base_attr_cell, '');
return rtrim($output); return rtrim($output);
} }
@ -541,9 +541,9 @@ class ANSI
* @access public * @access public
* @return string * @return string
*/ */
function getScreen() public function getScreen()
{ {
return '<pre width="' . ($this->max_x + 1) . '" style="color: white; background: black">' . $this->_getScreen() . '</pre>'; return '<pre width="' . ($this->max_x + 1) . '" style="color: white; background: black">' . $this->getScreenHelper() . '</pre>';
} }
/** /**
@ -552,21 +552,21 @@ class ANSI
* @access public * @access public
* @return string * @return string
*/ */
function getHistory() public function getHistory()
{ {
$scrollback = ''; $scrollback = '';
$last_attr = $this->base_attr_cell; $last_attr = $this->base_attr_cell;
for ($i = 0; $i < count($this->history); $i++) { for ($i = 0; $i < count($this->history); $i++) {
for ($j = 0; $j <= $this->max_x + 1; $j++) { for ($j = 0; $j <= $this->max_x + 1; $j++) {
$cur_attr = $this->history_attrs[$i][$j]; $cur_attr = $this->history_attrs[$i][$j];
$scrollback.= $this->_processCoordinate($last_attr, $cur_attr, isset($this->history[$i][$j]) ? $this->history[$i][$j] : ''); $scrollback.= $this->processCoordinate($last_attr, $cur_attr, isset($this->history[$i][$j]) ? $this->history[$i][$j] : '');
$last_attr = $this->history_attrs[$i][$j]; $last_attr = $this->history_attrs[$i][$j];
} }
$scrollback.= "\r\n"; $scrollback.= "\r\n";
} }
$base_attr_cell = $this->base_attr_cell; $base_attr_cell = $this->base_attr_cell;
$this->base_attr_cell = $last_attr; $this->base_attr_cell = $last_attr;
$scrollback.= $this->_getScreen(); $scrollback.= $this->getScreen();
$this->base_attr_cell = $base_attr_cell; $this->base_attr_cell = $base_attr_cell;
return '<pre width="' . ($this->max_x + 1) . '" style="color: white; background: black">' . $scrollback . '</span></pre>'; return '<pre width="' . ($this->max_x + 1) . '" style="color: white; background: black">' . $scrollback . '</span></pre>';

View File

@ -34,7 +34,7 @@ use phpseclib\Math\BigInteger;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class ASN1 abstract class ASN1
{ {
/**#@+ /**#@+
* Tag Classes * Tag Classes
@ -109,7 +109,7 @@ class ASN1
* @access private * @access private
* @link http://en.wikipedia.org/wiki/Object_identifier * @link http://en.wikipedia.org/wiki/Object_identifier
*/ */
static $oids = []; private static $oids = [];
/** /**
* ASN.1 object identifier reverse mapping * ASN.1 object identifier reverse mapping
@ -117,7 +117,7 @@ class ASN1
* @var array * @var array
* @access private * @access private
*/ */
static $reverseOIDs = []; private static $reverseOIDs = [];
/** /**
* Default date format * Default date format
@ -126,7 +126,7 @@ class ASN1
* @access private * @access private
* @link http://php.net/class.datetime * @link http://php.net/class.datetime
*/ */
static $format = 'D, d M Y H:i:s O'; private static $format = 'D, d M Y H:i:s O';
/** /**
* Filters * Filters
@ -135,9 +135,9 @@ class ASN1
* *
* @var array * @var array
* @access private * @access private
* @see self::_encode_der() * @see self::encode_der()
*/ */
static $filters; private static $filters;
/** /**
* Current Location of most recent ASN.1 encode process * Current Location of most recent ASN.1 encode process
@ -146,9 +146,9 @@ class ASN1
* *
* @var array * @var array
* @access private * @access private
* @see self::_encode_der() * @see self::encode_der()
*/ */
static $location; private static $location;
/** /**
* DER Encoded String * DER Encoded String
@ -159,7 +159,7 @@ class ASN1
* @access private * @access private
* @see self::decodeDER() * @see self::decodeDER()
*/ */
static $encoded; private static $encoded;
/** /**
* Type mapping table for the ANY type. * Type mapping table for the ANY type.
@ -224,7 +224,7 @@ class ASN1
* @return array * @return array
* @access public * @access public
*/ */
static function decodeBER($encoded) public static function decodeBER($encoded)
{ {
if ($encoded instanceof Element) { if ($encoded instanceof Element) {
$encoded = $encoded->element; $encoded = $encoded->element;
@ -232,7 +232,7 @@ class ASN1
self::$encoded = $encoded; self::$encoded = $encoded;
$decoded = [self::_decode_ber($encoded)]; $decoded = [self::decode_ber($encoded)];
// encapsulate in an array for BC with the old decodeBER // encapsulate in an array for BC with the old decodeBER
return $decoded; return $decoded;
@ -251,7 +251,7 @@ class ASN1
* @return array * @return array
* @access private * @access private
*/ */
static function _decode_ber($encoded, $start = 0, $encoded_pos = 0) private static function decode_ber($encoded, $start = 0, $encoded_pos = 0)
{ {
$current = ['start' => $start]; $current = ['start' => $start];
@ -328,7 +328,7 @@ class ASN1
$newcontent = []; $newcontent = [];
$remainingLength = $length; $remainingLength = $length;
while ($remainingLength > 0) { while ($remainingLength > 0) {
$temp = self::_decode_ber($content, $start, $content_pos); $temp = self::decode_ber($content, $start, $content_pos);
$length = $temp['length']; $length = $temp['length'];
// end-of-content octets - see paragraph 8.1.5 // end-of-content octets - see paragraph 8.1.5
if (substr($content, $content_pos + $length, 2) == "\0\0") { if (substr($content, $content_pos + $length, 2) == "\0\0") {
@ -379,7 +379,7 @@ class ASN1
if (!$constructed) { if (!$constructed) {
$current['content'] = substr($content, $content_pos); $current['content'] = substr($content, $content_pos);
} else { } else {
$temp = self::_decode_ber($content, $start, $content_pos); $temp = self::decode_ber($content, $start, $content_pos);
$length-= (strlen($content) - $content_pos); $length-= (strlen($content) - $content_pos);
$last = count($temp) - 1; $last = count($temp) - 1;
for ($i = 0; $i < $last; $i++) { for ($i = 0; $i < $last; $i++) {
@ -403,7 +403,7 @@ class ASN1
$current['content'] = ''; $current['content'] = '';
$length = 0; $length = 0;
while (substr($content, $content_pos, 2) != "\0\0") { while (substr($content, $content_pos, 2) != "\0\0") {
$temp = self::_decode_ber($content, $length + $start, $content_pos); $temp = self::decode_ber($content, $length + $start, $content_pos);
$content_pos += $temp['length']; $content_pos += $temp['length'];
// all subtags should be octet strings // all subtags should be octet strings
//if ($temp['type'] != self::TYPE_OCTET_STRING) { //if ($temp['type'] != self::TYPE_OCTET_STRING) {
@ -435,7 +435,7 @@ class ASN1
$length = $offset + 2; // +2 for the EOC $length = $offset + 2; // +2 for the EOC
break 2; break 2;
} }
$temp = self::_decode_ber($content, $start + $offset, $content_pos); $temp = self::decode_ber($content, $start + $offset, $content_pos);
$content_pos += $temp['length']; $content_pos += $temp['length'];
$current['content'][] = $temp; $current['content'][] = $temp;
$offset+= $temp['length']; $offset+= $temp['length'];
@ -493,7 +493,7 @@ class ASN1
break; break;
case self::TYPE_UTC_TIME: case self::TYPE_UTC_TIME:
case self::TYPE_GENERALIZED_TIME: case self::TYPE_GENERALIZED_TIME:
$current['content'] = self::_decodeTime(substr($content, $content_pos), $tag); $current['content'] = self::decodeTime(substr($content, $content_pos), $tag);
default: default:
} }
@ -516,7 +516,7 @@ class ASN1
* @return array * @return array
* @access public * @access public
*/ */
static function asn1map($decoded, $mapping, $special = []) public static function asn1map($decoded, $mapping, $special = [])
{ {
if (isset($mapping['explicit']) && is_array($decoded['content'])) { if (isset($mapping['explicit']) && is_array($decoded['content'])) {
$decoded = $decoded['content'][0]; $decoded = $decoded['content'][0];
@ -736,7 +736,7 @@ class ASN1
case self::TYPE_UTC_TIME: case self::TYPE_UTC_TIME:
case self::TYPE_GENERALIZED_TIME: case self::TYPE_GENERALIZED_TIME:
if (isset($mapping['implicit'])) { if (isset($mapping['implicit'])) {
$decoded['content'] = self::_decodeTime($decoded['content'], $decoded['type']); $decoded['content'] = self::decodeTime($decoded['content'], $decoded['type']);
} }
return @date(self::$format, $decoded['content']); return @date(self::$format, $decoded['content']);
case self::TYPE_BIT_STRING: case self::TYPE_BIT_STRING:
@ -816,10 +816,10 @@ class ASN1
* @return string * @return string
* @access public * @access public
*/ */
static function encodeDER($source, $mapping, $special = []) public static function encodeDER($source, $mapping, $special = [])
{ {
self::$location = []; self::$location = [];
return self::_encode_der($source, $mapping, null, $special); return self::encode_der($source, $mapping, null, $special);
} }
/** /**
@ -832,7 +832,7 @@ class ASN1
* @throws \RuntimeException if the input has an error in it * @throws \RuntimeException if the input has an error in it
* @access private * @access private
*/ */
static function _encode_der($source, $mapping, $idx = null, $special = []) private static function encode_der($source, $mapping, $idx = null, $special = [])
{ {
if ($source instanceof Element) { if ($source instanceof Element) {
return $source->element; return $source->element;
@ -863,7 +863,7 @@ class ASN1
$child = $mapping['children']; $child = $mapping['children'];
foreach ($source as $content) { foreach ($source as $content) {
$temp = self::_encode_der($content, $child, null, $special); $temp = self::encode_der($content, $child, null, $special);
if ($temp === false) { if ($temp === false) {
return false; return false;
} }
@ -890,7 +890,7 @@ class ASN1
continue; continue;
} }
$temp = self::_encode_der($source[$key], $child, $key, $special); $temp = self::encode_der($source[$key], $child, $key, $special);
if ($temp === false) { if ($temp === false) {
return false; return false;
} }
@ -931,7 +931,7 @@ class ASN1
continue; continue;
} }
$temp = self::_encode_der($source[$key], $child, $key, $special); $temp = self::encode_der($source[$key], $child, $key, $special);
if ($temp === false) { if ($temp === false) {
return false; return false;
} }
@ -1063,19 +1063,19 @@ class ASN1
switch (true) { switch (true) {
case !isset($source): case !isset($source):
return self::_encode_der(null, ['type' => self::TYPE_NULL] + $mapping, null, $special); return self::encode_der(null, ['type' => self::TYPE_NULL] + $mapping, null, $special);
case is_int($source): case is_int($source):
case $source instanceof BigInteger: case $source instanceof BigInteger:
return self::_encode_der($source, ['type' => self::TYPE_INTEGER] + $mapping, null, $special); return self::encode_der($source, ['type' => self::TYPE_INTEGER] + $mapping, null, $special);
case is_float($source): case is_float($source):
return self::_encode_der($source, ['type' => self::TYPE_REAL] + $mapping, null, $special); return self::encode_der($source, ['type' => self::TYPE_REAL] + $mapping, null, $special);
case is_bool($source): case is_bool($source):
return self::_encode_der($source, ['type' => self::TYPE_BOOLEAN] + $mapping, null, $special); return self::encode_der($source, ['type' => self::TYPE_BOOLEAN] + $mapping, null, $special);
case is_array($source) && count($source) == 1: case is_array($source) && count($source) == 1:
$typename = implode('', array_keys($source)); $typename = implode('', array_keys($source));
$outtype = array_search($typename, self::ANY_MAP, true); $outtype = array_search($typename, self::ANY_MAP, true);
if ($outtype !== false) { if ($outtype !== false) {
return self::_encode_der($source[$typename], ['type' => $outtype] + $mapping, null, $special); return self::encode_der($source[$typename], ['type' => $outtype] + $mapping, null, $special);
} }
} }
@ -1090,7 +1090,7 @@ class ASN1
if ($filters === false) { if ($filters === false) {
throw new \RuntimeException('No filters defined for ' . implode('/', $loc)); throw new \RuntimeException('No filters defined for ' . implode('/', $loc));
} }
return self::_encode_der($source, $filters + $mapping, null, $special); return self::encode_der($source, $filters + $mapping, null, $special);
case self::TYPE_NULL: case self::TYPE_NULL:
$value = ''; $value = '';
break; break;
@ -1140,7 +1140,7 @@ class ASN1
* @param int $tag * @param int $tag
* @return string * @return string
*/ */
static function _decodeTime($content, $tag) private static function decodeTime($content, $tag)
{ {
/* UTCTime: /* UTCTime:
http://tools.ietf.org/html/rfc5280#section-4.1.2.5.1 http://tools.ietf.org/html/rfc5280#section-4.1.2.5.1
@ -1187,7 +1187,7 @@ class ASN1
* @access public * @access public
* @param string $format * @param string $format
*/ */
static function setTimeFormat($format) public static function setTimeFormat($format)
{ {
self::$format = $format; self::$format = $format;
} }
@ -1201,7 +1201,7 @@ class ASN1
* @access public * @access public
* @param array $oids * @param array $oids
*/ */
static function loadOIDs($oids) public static function loadOIDs($oids)
{ {
self::$oids+= $oids; self::$oids+= $oids;
self::$reverseOIDs = array_flip(self::$oids); self::$reverseOIDs = array_flip(self::$oids);
@ -1216,7 +1216,7 @@ class ASN1
* @access public * @access public
* @param array $filters * @param array $filters
*/ */
static function setFilters($filters) public static function setFilters($filters)
{ {
self::$filters = $filters; self::$filters = $filters;
} }
@ -1233,7 +1233,7 @@ class ASN1
* @return string * @return string
* @access public * @access public
*/ */
static function convert($in, $from = self::TYPE_UTF8_STRING, $to = self::TYPE_UTF8_STRING) public static function convert($in, $from = self::TYPE_UTF8_STRING, $to = self::TYPE_UTF8_STRING)
{ {
// isset(self::STRING_TYPE_SIZE[$from] returns a fatal error on PHP 5.6 // isset(self::STRING_TYPE_SIZE[$from] returns a fatal error on PHP 5.6
if (!array_key_exists($from, self::STRING_TYPE_SIZE) || !array_key_exists($to, self::STRING_TYPE_SIZE)) { if (!array_key_exists($from, self::STRING_TYPE_SIZE) || !array_key_exists($to, self::STRING_TYPE_SIZE)) {
@ -1328,7 +1328,7 @@ class ASN1
* @param string $str * @param string $str
* @return string * @return string
*/ */
static function extractBER($str) public static function extractBER($str)
{ {
/* X.509 certs are assumed to be base64 encoded but sometimes they'll have additional things in them /* X.509 certs are assumed to be base64 encoded but sometimes they'll have additional things in them
* above and beyond the ceritificate. * above and beyond the ceritificate.
@ -1358,7 +1358,7 @@ class ASN1
* @param string $string * @param string $string
* @return int * @return int
*/ */
static function decodeLength(&$string) public static function decodeLength(&$string)
{ {
$length = ord(Strings::shift($string)); $length = ord(Strings::shift($string));
if ($length & 0x80) { // definite length, long form if ($length & 0x80) { // definite length, long form
@ -1379,7 +1379,7 @@ class ASN1
* @param int $length * @param int $length
* @return string * @return string
*/ */
static function encodeLength($length) public static function encodeLength($length)
{ {
if ($length <= 0x7F) { if ($length <= 0x7F) {
return chr($length); return chr($length);

View File

@ -33,7 +33,7 @@ class Element
* @var string * @var string
* @access private * @access private
*/ */
var $element; public $element;
/** /**
* Constructor * Constructor
@ -42,7 +42,7 @@ class Element
* @return \phpseclib\File\ASN1\Element * @return \phpseclib\File\ASN1\Element
* @access public * @access public
*/ */
function __construct($encoded) public function __construct($encoded)
{ {
$this->element = $encoded; $this->element = $encoded;
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class AccessDescription abstract class AccessDescription
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class AdministrationDomainName abstract class AdministrationDomainName
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_CHOICE, 'type' => ASN1::TYPE_CHOICE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class AlgorithmIdentifier abstract class AlgorithmIdentifier
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class AnotherName abstract class AnotherName
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class Attribute abstract class Attribute
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class AttributeType abstract class AttributeType
{ {
const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER]; const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class AttributeTypeAndValue abstract class AttributeTypeAndValue
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class AttributeValue abstract class AttributeValue
{ {
const MAP = ['type' => ASN1::TYPE_ANY]; const MAP = ['type' => ASN1::TYPE_ANY];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class Attributes abstract class Attributes
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SET, 'type' => ASN1::TYPE_SET,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class AuthorityInfoAccessSyntax abstract class AuthorityInfoAccessSyntax
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class AuthorityKeyIdentifier abstract class AuthorityKeyIdentifier
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class BaseDistance abstract class BaseDistance
{ {
const MAP = ['type' => ASN1::TYPE_INTEGER]; const MAP = ['type' => ASN1::TYPE_INTEGER];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class BasicConstraints abstract class BasicConstraints
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class BuiltInDomainDefinedAttribute abstract class BuiltInDomainDefinedAttribute
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class BuiltInDomainDefinedAttributes abstract class BuiltInDomainDefinedAttributes
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class BuiltInStandardAttributes abstract class BuiltInStandardAttributes
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CPSuri abstract class CPSuri
{ {
const MAP = ['type' => ASN1::TYPE_IA5_STRING]; const MAP = ['type' => ASN1::TYPE_IA5_STRING];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CRLDistributionPoints abstract class CRLDistributionPoints
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CRLNumber abstract class CRLNumber
{ {
const MAP = ['type' => ASN1::TYPE_INTEGER]; const MAP = ['type' => ASN1::TYPE_INTEGER];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CRLReason abstract class CRLReason
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_ENUMERATED, 'type' => ASN1::TYPE_ENUMERATED,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CertPolicyId abstract class CertPolicyId
{ {
const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER]; const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class Certificate abstract class Certificate
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CertificateIssuer abstract class CertificateIssuer
{ {
const MAP = GeneralNames::MAP; const MAP = GeneralNames::MAP;
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CertificateList abstract class CertificateList
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CertificatePolicies abstract class CertificatePolicies
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CertificateSerialNumber abstract class CertificateSerialNumber
{ {
const MAP = ['type' => ASN1::TYPE_INTEGER]; const MAP = ['type' => ASN1::TYPE_INTEGER];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CertificationRequest abstract class CertificationRequest
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CertificationRequestInfo abstract class CertificationRequestInfo
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class CountryName abstract class CountryName
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_CHOICE, 'type' => ASN1::TYPE_CHOICE,

View File

@ -26,7 +26,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class DigestInfo abstract class DigestInfo
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class DirectoryString abstract class DirectoryString
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_CHOICE, 'type' => ASN1::TYPE_CHOICE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class DisplayText abstract class DisplayText
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_CHOICE, 'type' => ASN1::TYPE_CHOICE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class DistributionPoint abstract class DistributionPoint
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class DistributionPointName abstract class DistributionPointName
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_CHOICE, 'type' => ASN1::TYPE_CHOICE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class EDIPartyName abstract class EDIPartyName
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class EncryptedData abstract class EncryptedData
{ {
const MAP = ['type' => ASN1::TYPE_OCTET_STRING]; const MAP = ['type' => ASN1::TYPE_OCTET_STRING];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class EncryptedPrivateKeyInfo abstract class EncryptedPrivateKeyInfo
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class ExtKeyUsageSyntax abstract class ExtKeyUsageSyntax
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -30,7 +30,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class Extension abstract class Extension
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class ExtensionAttribute abstract class ExtensionAttribute
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class ExtensionAttributes abstract class ExtensionAttributes
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SET, 'type' => ASN1::TYPE_SET,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class Extensions abstract class Extensions
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class GeneralName abstract class GeneralName
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_CHOICE, 'type' => ASN1::TYPE_CHOICE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class GeneralNames abstract class GeneralNames
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class GeneralSubtree abstract class GeneralSubtree
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class GeneralSubtrees abstract class GeneralSubtrees
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class HoldInstructionCode abstract class HoldInstructionCode
{ {
const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER]; const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class InvalidityDate abstract class InvalidityDate
{ {
const MAP = ['type' => ASN1::TYPE_GENERALIZED_TIME]; const MAP = ['type' => ASN1::TYPE_GENERALIZED_TIME];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class IssuerAltName abstract class IssuerAltName
{ {
const MAP = GeneralNames::MAP; const MAP = GeneralNames::MAP;
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class IssuingDistributionPoint abstract class IssuingDistributionPoint
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class KeyIdentifier abstract class KeyIdentifier
{ {
const MAP = ['type' => ASN1::TYPE_OCTET_STRING]; const MAP = ['type' => ASN1::TYPE_OCTET_STRING];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class KeyPurposeId abstract class KeyPurposeId
{ {
const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER]; const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class KeyUsage abstract class KeyUsage
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_BIT_STRING, 'type' => ASN1::TYPE_BIT_STRING,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class Name abstract class Name
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_CHOICE, 'type' => ASN1::TYPE_CHOICE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class NameConstraints abstract class NameConstraints
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class NetworkAddress abstract class NetworkAddress
{ {
const MAP = ['type' => ASN1::TYPE_NUMERIC_STRING]; const MAP = ['type' => ASN1::TYPE_NUMERIC_STRING];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class NoticeReference abstract class NoticeReference
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class NumericUserIdentifier abstract class NumericUserIdentifier
{ {
const MAP = ['type' => ASN1::TYPE_NUMERIC_STRING]; const MAP = ['type' => ASN1::TYPE_NUMERIC_STRING];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class ORAddress abstract class ORAddress
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class OrganizationName abstract class OrganizationName
{ {
const MAP = ['type' => ASN1::TYPE_PRINTABLE_STRING]; const MAP = ['type' => ASN1::TYPE_PRINTABLE_STRING];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class OrganizationalUnitNames abstract class OrganizationalUnitNames
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class OtherPrimeInfo abstract class OtherPrimeInfo
{ {
// version must be multi if otherPrimeInfos present // version must be multi if otherPrimeInfos present
const MAP = [ const MAP = [

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class OtherPrimeInfos abstract class OtherPrimeInfos
{ {
// version must be multi if otherPrimeInfos present // version must be multi if otherPrimeInfos present
const MAP = [ const MAP = [

View File

@ -26,7 +26,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PBEParameter abstract class PBEParameter
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -26,7 +26,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PBES2params abstract class PBES2params
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -26,7 +26,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PBKDF2params abstract class PBKDF2params
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -26,7 +26,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PBMAC1params abstract class PBMAC1params
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PKCS9String abstract class PKCS9String
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_CHOICE, 'type' => ASN1::TYPE_CHOICE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PersonalName abstract class PersonalName
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SET, 'type' => ASN1::TYPE_SET,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PolicyInformation abstract class PolicyInformation
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PolicyMappings abstract class PolicyMappings
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PolicyQualifierId abstract class PolicyQualifierId
{ {
const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER]; const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER];
} }

View File

@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access public * @access public
*/ */
class PolicyQualifierInfo abstract class PolicyQualifierInfo
{ {
const MAP = [ const MAP = [
'type' => ASN1::TYPE_SEQUENCE, 'type' => ASN1::TYPE_SEQUENCE,

Some files were not shown because too many files have changed in this diff Show More