mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-05 21:17:53 +00:00
Merge pull request #1084 from terrafrost/php5-updates
PHP5 updates for master branch
This commit is contained in:
commit
ab1da5ac1f
75
phpseclib/Common/Functions/Objects.php
Normal file
75
phpseclib/Common/Functions/Objects.php
Normal 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);
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ namespace phpseclib\Common\Functions;
|
||||
* @package Functions\Strings
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class Strings
|
||||
abstract class Strings
|
||||
{
|
||||
/**
|
||||
* String Shift
|
||||
@ -33,10 +33,27 @@ class Strings
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
static function shift(&$string, $index = 1)
|
||||
public static function shift(&$string, $index = 1)
|
||||
{
|
||||
$substr = substr($string, 0, $index);
|
||||
$string = substr($string, $index);
|
||||
return $substr;
|
||||
}
|
||||
|
||||
/**
|
||||
* String Pop
|
||||
*
|
||||
* Inspired by array_pop
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $index
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public static function pop(&$string, $index = 1)
|
||||
{
|
||||
$substr = substr($string, -$index);
|
||||
$string = substr($string, 0, -$index);
|
||||
return $substr;
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class AES extends Rijndael
|
||||
* @param int $length
|
||||
* @throws \BadMethodCallException anytime it's called
|
||||
*/
|
||||
function setBlockLength($length)
|
||||
public function setBlockLength($length)
|
||||
{
|
||||
throw new \BadMethodCallException('The block length cannot be set for AES.');
|
||||
}
|
||||
@ -83,7 +83,7 @@ class AES extends Rijndael
|
||||
* @param int $length
|
||||
* @throws \LengthException if the key length isn't supported
|
||||
*/
|
||||
function setKeyLength($length)
|
||||
public function setKeyLength($length)
|
||||
{
|
||||
switch ($length) {
|
||||
case 128:
|
||||
@ -107,7 +107,7 @@ class AES extends Rijndael
|
||||
* @param string $key
|
||||
* @throws \LengthException if the key length isn't supported
|
||||
*/
|
||||
function setKey($key)
|
||||
public function setKey($key)
|
||||
{
|
||||
switch (strlen($key)) {
|
||||
case 16:
|
||||
@ -120,4 +120,15 @@ class AES extends Rijndael
|
||||
|
||||
parent::setKey($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class that defines the private methods
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
protected function getClassContext()
|
||||
{
|
||||
return 'phpseclib\Crypt\Rijndael';
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class Blowfish extends BlockCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $block_size = 8;
|
||||
protected $block_size = 8;
|
||||
|
||||
/**
|
||||
* The mcrypt specific name of the cipher
|
||||
@ -65,7 +65,7 @@ class Blowfish extends BlockCipher
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $cipher_name_mcrypt = 'blowfish';
|
||||
protected $cipher_name_mcrypt = 'blowfish';
|
||||
|
||||
/**
|
||||
* Optimizing value while CFB-encrypting
|
||||
@ -74,7 +74,7 @@ class Blowfish extends BlockCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $cfb_init_len = 500;
|
||||
protected $cfb_init_len = 500;
|
||||
|
||||
/**
|
||||
* The fixed subkeys boxes ($sbox0 - $sbox3) with 256 entries each
|
||||
@ -84,7 +84,7 @@ class Blowfish extends BlockCipher
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $sbox0 = array(
|
||||
private $sbox0 = [
|
||||
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
|
||||
0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
|
||||
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
|
||||
@ -117,7 +117,7 @@ class Blowfish extends BlockCipher
|
||||
0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
|
||||
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
|
||||
0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* S-Box 1
|
||||
@ -125,7 +125,7 @@ class Blowfish extends BlockCipher
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $sbox1 = array(
|
||||
private $sbox1 = [
|
||||
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
|
||||
0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
|
||||
0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
|
||||
@ -158,7 +158,7 @@ class Blowfish extends BlockCipher
|
||||
0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
|
||||
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
|
||||
0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* S-Box 2
|
||||
@ -166,7 +166,7 @@ class Blowfish extends BlockCipher
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $sbox2 = array(
|
||||
private $sbox2 = [
|
||||
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
|
||||
0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
|
||||
0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
|
||||
@ -199,7 +199,7 @@ class Blowfish extends BlockCipher
|
||||
0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
|
||||
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
|
||||
0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* S-Box 3
|
||||
@ -207,7 +207,7 @@ class Blowfish extends BlockCipher
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $sbox3 = array(
|
||||
private $sbox3 = [
|
||||
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
|
||||
0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
|
||||
0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
|
||||
@ -240,7 +240,7 @@ class Blowfish extends BlockCipher
|
||||
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
|
||||
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
|
||||
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* P-Array consists of 18 32-bit subkeys
|
||||
@ -248,11 +248,11 @@ class Blowfish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $parray = array(
|
||||
private $parray = [
|
||||
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0,
|
||||
0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
|
||||
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* The BCTX-working Array
|
||||
@ -262,7 +262,7 @@ class Blowfish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $bctx;
|
||||
private $bctx;
|
||||
|
||||
/**
|
||||
* Holds the last used key
|
||||
@ -270,7 +270,7 @@ class Blowfish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $kl;
|
||||
private $kl;
|
||||
|
||||
/**
|
||||
* The Key Length (in bytes)
|
||||
@ -283,7 +283,7 @@ class Blowfish extends BlockCipher
|
||||
* derive this from $key_length or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu
|
||||
* of that, we'll just precompute it once.
|
||||
*/
|
||||
var $key_length = 16;
|
||||
protected $key_length = 16;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -292,7 +292,7 @@ class Blowfish extends BlockCipher
|
||||
* @access public
|
||||
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided
|
||||
*/
|
||||
function __construct($mode)
|
||||
public function __construct($mode)
|
||||
{
|
||||
if ($mode == self::MODE_STREAM) {
|
||||
throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode');
|
||||
@ -309,7 +309,7 @@ class Blowfish extends BlockCipher
|
||||
* @access public
|
||||
* @param int $length
|
||||
*/
|
||||
function setKeyLength($length)
|
||||
public function setKeyLength($length)
|
||||
{
|
||||
if ($length < 32 || $length > 448) {
|
||||
throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys of sizes between 32 and 448 bits are supported');
|
||||
@ -330,14 +330,14 @@ class Blowfish extends BlockCipher
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isValidEngine($engine)
|
||||
public function isValidEngine($engine)
|
||||
{
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
if ($this->key_length < 16) {
|
||||
return false;
|
||||
}
|
||||
$this->cipher_name_openssl_ecb = 'bf-ecb';
|
||||
$this->cipher_name_openssl = 'bf-' . $this->_openssl_translate_mode();
|
||||
$this->cipher_name_openssl = 'bf-' . $this->openssl_translate_mode();
|
||||
}
|
||||
|
||||
return parent::isValidEngine($engine);
|
||||
@ -349,24 +349,24 @@ class Blowfish extends BlockCipher
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey()
|
||||
* @access private
|
||||
*/
|
||||
function _setupKey()
|
||||
protected function setupKey()
|
||||
{
|
||||
if (isset($this->kl['key']) && $this->key === $this->kl['key']) {
|
||||
// already expanded
|
||||
return;
|
||||
}
|
||||
$this->kl = array('key' => $this->key);
|
||||
$this->kl = ['key' => $this->key];
|
||||
|
||||
/* key-expanding p[] and S-Box building sb[] */
|
||||
$this->bctx = array(
|
||||
'p' => array(),
|
||||
'sb' => array(
|
||||
$this->bctx = [
|
||||
'p' => [],
|
||||
'sb' => [
|
||||
$this->sbox0,
|
||||
$this->sbox1,
|
||||
$this->sbox2,
|
||||
$this->sbox3
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
// unpack binary string in unsigned chars
|
||||
$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
|
||||
$data = "\0\0\0\0\0\0\0\0";
|
||||
for ($i = 0; $i < 18; $i += 2) {
|
||||
list($l, $r) = array_values(unpack('N*', $data = $this->_encryptBlock($data)));
|
||||
list($l, $r) = array_values(unpack('N*', $data = $this->encryptBlock($data)));
|
||||
$this->bctx['p'][$i ] = $l;
|
||||
$this->bctx['p'][$i + 1] = $r;
|
||||
}
|
||||
for ($i = 0; $i < 4; ++$i) {
|
||||
for ($j = 0; $j < 256; $j += 2) {
|
||||
list($l, $r) = array_values(unpack('N*', $data = $this->_encryptBlock($data)));
|
||||
list($l, $r) = array_values(unpack('N*', $data = $this->encryptBlock($data)));
|
||||
$this->bctx['sb'][$i][$j ] = $l;
|
||||
$this->bctx['sb'][$i][$j + 1] = $r;
|
||||
}
|
||||
@ -406,7 +406,7 @@ class Blowfish extends BlockCipher
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
function _encryptBlock($in)
|
||||
protected function encryptBlock($in)
|
||||
{
|
||||
$p = $this->bctx["p"];
|
||||
// extract($this->bctx["sb"], EXTR_PREFIX_ALL, "sb"); // slower
|
||||
@ -442,7 +442,7 @@ class Blowfish extends BlockCipher
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
function _decryptBlock($in)
|
||||
protected function decryptBlock($in)
|
||||
{
|
||||
$p = $this->bctx["p"];
|
||||
$sb_0 = $this->bctx["sb"][0];
|
||||
@ -476,115 +476,84 @@ class Blowfish extends BlockCipher
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt()
|
||||
* @access private
|
||||
*/
|
||||
function _setupInlineCrypt()
|
||||
protected function setupInlineCrypt()
|
||||
{
|
||||
$lambda_functions =& self::_getLambdaFunctions();
|
||||
|
||||
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
|
||||
// (Currently, for Blowfish, one generated $lambda_function cost on php5.5@32bit ~100kb unfreeable mem and ~180kb on php5.5@64bit)
|
||||
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one.
|
||||
$gen_hi_opt_code = (bool)(count($lambda_functions) < 10);
|
||||
|
||||
// Generation of a unique hash for our generated code
|
||||
$code_hash = "Crypt_Blowfish, {$this->mode}";
|
||||
if ($gen_hi_opt_code) {
|
||||
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
|
||||
}
|
||||
|
||||
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"];
|
||||
|
||||
';
|
||||
$p = $this->bctx['p'];
|
||||
$init_crypt = '
|
||||
static $sb_0, $sb_1, $sb_2, $sb_3;
|
||||
if (!$sb_0) {
|
||||
$sb_0 = $this->bctx["sb"][0];
|
||||
$sb_1 = $this->bctx["sb"][1];
|
||||
$sb_2 = $this->bctx["sb"][2];
|
||||
$sb_3 = $this->bctx["sb"][3];
|
||||
}
|
||||
';
|
||||
|
||||
// Generating encrypt code:
|
||||
$encrypt_block = '
|
||||
$in = unpack("N*", $in);
|
||||
$l = $in[1];
|
||||
$r = $in[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];
|
||||
';
|
||||
}
|
||||
// Generating encrypt code:
|
||||
$encrypt_block = '
|
||||
$in = unpack("N*", $in);
|
||||
$l = $in[1];
|
||||
$r = $in[2];
|
||||
';
|
||||
for ($i = 0; $i < 16; $i+= 2) {
|
||||
$encrypt_block.= '
|
||||
$in = pack("N*",
|
||||
$r ^ ' . $p[17] . ',
|
||||
$l ^ ' . $p[16] . '
|
||||
);
|
||||
$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];
|
||||
';
|
||||
|
||||
// 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
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -44,14 +44,14 @@ abstract class PKCS
|
||||
* @access private
|
||||
* @param int
|
||||
*/
|
||||
static $format = self::MODE_ANY;
|
||||
protected static $format = self::MODE_ANY;
|
||||
|
||||
/**
|
||||
* Require base64-encoded PEM's be supplied
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
static function requirePEM()
|
||||
public static function requirePEM()
|
||||
{
|
||||
self::$format = self::MODE_PEM;
|
||||
}
|
||||
@ -61,7 +61,7 @@ abstract class PKCS
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
static function requireDER()
|
||||
public static function requireDER()
|
||||
{
|
||||
self::$format = self::MODE_DER;
|
||||
}
|
||||
@ -73,7 +73,7 @@ abstract class PKCS
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
static function requireAny()
|
||||
public static function requireAny()
|
||||
{
|
||||
self::$format = self::MODE_ANY;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ abstract class PKCS1 extends PKCS
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
static $defaultEncryptionAlgorithm = 'AES-128-CBC';
|
||||
private static $defaultEncryptionAlgorithm = 'AES-128-CBC';
|
||||
|
||||
/**
|
||||
* Sets the default encryption algorithm
|
||||
@ -48,7 +48,7 @@ abstract class PKCS1 extends PKCS
|
||||
* @access public
|
||||
* @param string $algo
|
||||
*/
|
||||
static function setEncryptionAlgorithm($algo)
|
||||
public static function setEncryptionAlgorithm($algo)
|
||||
{
|
||||
self::$defaultEncryptionAlgorithm = $algo;
|
||||
}
|
||||
@ -61,7 +61,7 @@ abstract class PKCS1 extends PKCS
|
||||
* @return int
|
||||
* @throws \UnexpectedValueException if the block cipher mode is unsupported
|
||||
*/
|
||||
static function getEncryptionMode($mode)
|
||||
private static function getEncryptionMode($mode)
|
||||
{
|
||||
switch ($mode) {
|
||||
case 'CBC':
|
||||
@ -86,7 +86,7 @@ abstract class PKCS1 extends PKCS
|
||||
* @return string
|
||||
* @throws \UnexpectedValueException if the encryption algorithm is unsupported
|
||||
*/
|
||||
static function getEncryptionObject($algo)
|
||||
private static function getEncryptionObject($algo)
|
||||
{
|
||||
$modes = '(CBC|ECB|CFB|OFB|CTR)';
|
||||
switch (true) {
|
||||
@ -112,7 +112,7 @@ abstract class PKCS1 extends PKCS
|
||||
* @param int $length
|
||||
* @return string
|
||||
*/
|
||||
static function generateSymmetricKey($password, $iv, $length)
|
||||
private static function generateSymmetricKey($password, $iv, $length)
|
||||
{
|
||||
$symkey = '';
|
||||
$iv = substr($iv, 0, 8);
|
||||
@ -130,7 +130,7 @@ abstract class PKCS1 extends PKCS
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
static function load($key, $password)
|
||||
protected static function load($key, $password)
|
||||
{
|
||||
if (!is_string($key)) {
|
||||
return false;
|
||||
@ -186,7 +186,7 @@ abstract class PKCS1 extends PKCS
|
||||
* @param string $password
|
||||
* @return string
|
||||
*/
|
||||
static function wrapPrivateKey($key, $type, $password)
|
||||
protected static function wrapPrivateKey($key, $type, $password)
|
||||
{
|
||||
if (empty($password) || !is_string($password)) {
|
||||
return "-----BEGIN $type PRIVATE KEY-----\r\n" .
|
||||
@ -215,7 +215,7 @@ abstract class PKCS1 extends PKCS
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
static function wrapPublicKey($key, $type)
|
||||
protected static function wrapPublicKey($key, $type)
|
||||
{
|
||||
return "-----BEGIN $type PUBLIC KEY-----\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
|
@ -47,7 +47,7 @@ use phpseclib\Exception\UnsupportedAlgorithmException;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PKCS8 extends PKCS
|
||||
abstract class PKCS8 extends PKCS
|
||||
{
|
||||
/**
|
||||
* Default encryption algorithm
|
||||
@ -55,7 +55,7 @@ class PKCS8 extends PKCS
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
static $defaultEncryptionAlgorithm = 'id-PBES2';
|
||||
private static $defaultEncryptionAlgorithm = 'id-PBES2';
|
||||
|
||||
/**
|
||||
* Default encryption scheme
|
||||
@ -65,7 +65,7 @@ class PKCS8 extends PKCS
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
static $defaultEncryptionScheme = 'aes128-CBC-PAD';
|
||||
private static $defaultEncryptionScheme = 'aes128-CBC-PAD';
|
||||
|
||||
/**
|
||||
* Default PRF
|
||||
@ -75,7 +75,7 @@ class PKCS8 extends PKCS
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
static $defaultPRF = 'id-hmacWithSHA256';
|
||||
private static $defaultPRF = 'id-hmacWithSHA256';
|
||||
|
||||
/**
|
||||
* Default Iteration Count
|
||||
@ -83,7 +83,7 @@ class PKCS8 extends PKCS
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
static $defaultIterationCount = 2048;
|
||||
private static $defaultIterationCount = 2048;
|
||||
|
||||
/**
|
||||
* OIDs loaded
|
||||
@ -91,7 +91,7 @@ class PKCS8 extends PKCS
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
static $oidsLoaded = false;
|
||||
private static $oidsLoaded = false;
|
||||
|
||||
/**
|
||||
* Sets the default encryption algorithm
|
||||
@ -99,7 +99,7 @@ class PKCS8 extends PKCS
|
||||
* @access public
|
||||
* @param string $algo
|
||||
*/
|
||||
static function setEncryptionAlgorithm($algo)
|
||||
public static function setEncryptionAlgorithm($algo)
|
||||
{
|
||||
self::$defaultEncryptionAlgorithm = $algo;
|
||||
}
|
||||
@ -110,7 +110,7 @@ class PKCS8 extends PKCS
|
||||
* @access public
|
||||
* @param string $algo
|
||||
*/
|
||||
static function setEncryptionScheme($algo)
|
||||
public static function setEncryptionScheme($algo)
|
||||
{
|
||||
self::$defaultEncryptionScheme = $algo;
|
||||
}
|
||||
@ -121,7 +121,7 @@ class PKCS8 extends PKCS
|
||||
* @access public
|
||||
* @param int $count
|
||||
*/
|
||||
static function setIterationCount($count)
|
||||
public static function setIterationCount($count)
|
||||
{
|
||||
self::$defaultIterationCount = $count;
|
||||
}
|
||||
@ -132,7 +132,7 @@ class PKCS8 extends PKCS
|
||||
* @access public
|
||||
* @param string $algo
|
||||
*/
|
||||
static function setPRF($algo)
|
||||
public static function setPRF($algo)
|
||||
{
|
||||
self::$defaultPRF = $algo;
|
||||
}
|
||||
@ -143,7 +143,7 @@ class PKCS8 extends PKCS
|
||||
* @access public
|
||||
* @param string $algo
|
||||
*/
|
||||
static function getPBES1EncryptionObject($algo)
|
||||
private static function getPBES1EncryptionObject($algo)
|
||||
{
|
||||
$algo = preg_match('#^pbeWith(?:MD2|MD5|SHA1|SHA)And(.*?)-CBC$#', $algo, $matches) ?
|
||||
$matches[1] :
|
||||
@ -192,7 +192,7 @@ class PKCS8 extends PKCS
|
||||
* @access public
|
||||
* @param string $algo
|
||||
*/
|
||||
static function getPBES1Hash($algo)
|
||||
private static function getPBES1Hash($algo)
|
||||
{
|
||||
if (preg_match('#^pbeWith(MD2|MD5|SHA1|SHA)And.*?-CBC$#', $algo, $matches)) {
|
||||
return $matches[1] == 'SHA' ? 'sha1' : $matches[1];
|
||||
@ -207,7 +207,7 @@ class PKCS8 extends PKCS
|
||||
* @access public
|
||||
* @param string $algo
|
||||
*/
|
||||
static function getPBES1KDF($algo)
|
||||
private static function getPBES1KDF($algo)
|
||||
{
|
||||
switch ($algo) {
|
||||
case 'pbeWithMD2AndDES-CBC':
|
||||
@ -228,7 +228,7 @@ class PKCS8 extends PKCS
|
||||
* @access public
|
||||
* @param string $algo
|
||||
*/
|
||||
static function getPBES2EncryptionObject($algo)
|
||||
private static function getPBES2EncryptionObject($algo)
|
||||
{
|
||||
switch ($algo) {
|
||||
case 'desCBC':
|
||||
@ -262,7 +262,7 @@ class PKCS8 extends PKCS
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
static function _initialize_static_variables()
|
||||
private static function initialize_static_variables()
|
||||
{
|
||||
if (!self::$oidsLoaded) {
|
||||
// from https://tools.ietf.org/html/rfc2898
|
||||
@ -318,9 +318,9 @@ class PKCS8 extends PKCS
|
||||
* @param string $password optional
|
||||
* @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)) {
|
||||
return false;
|
||||
@ -482,9 +482,9 @@ class PKCS8 extends PKCS
|
||||
* @param string $password
|
||||
* @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 = [
|
||||
'version' => 'v1',
|
||||
@ -577,9 +577,9 @@ class PKCS8 extends PKCS
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
static function wrapPublicKey($key, $algorithm)
|
||||
protected static function wrapPublicKey($key, $algorithm)
|
||||
{
|
||||
self::_initialize_static_variables();
|
||||
self::initialize_static_variables();
|
||||
|
||||
$key = [
|
||||
'publicKeyAlgorithm' => [
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -55,8 +55,8 @@ class DES extends BlockCipher
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
* @see \phpseclib\Crypt\DES::_setupKey()
|
||||
* @see \phpseclib\Crypt\DES::_processBlock()
|
||||
* @see \phpseclib\Crypt\DES::setupKey()
|
||||
* @see \phpseclib\Crypt\DES::processBlock()
|
||||
*/
|
||||
/**
|
||||
* Contains $keys[self::ENCRYPT]
|
||||
@ -75,7 +75,7 @@ class DES extends BlockCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $block_size = 8;
|
||||
protected $block_size = 8;
|
||||
|
||||
/**
|
||||
* Key Length (in bytes)
|
||||
@ -84,7 +84,7 @@ class DES extends BlockCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $key_length = 8;
|
||||
protected $key_length = 8;
|
||||
|
||||
/**
|
||||
* The mcrypt specific name of the cipher
|
||||
@ -93,7 +93,7 @@ class DES extends BlockCipher
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $cipher_name_mcrypt = 'des';
|
||||
protected $cipher_name_mcrypt = 'des';
|
||||
|
||||
/**
|
||||
* The OpenSSL names of the cipher / modes
|
||||
@ -102,13 +102,13 @@ class DES extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $openssl_mode_names = array(
|
||||
protected $openssl_mode_names = [
|
||||
self::MODE_ECB => 'des-ecb',
|
||||
self::MODE_CBC => 'des-cbc',
|
||||
self::MODE_CFB => 'des-cfb',
|
||||
self::MODE_OFB => 'des-ofb'
|
||||
// self::MODE_CTR is undefined for DES
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Optimizing value while CFB-encrypting
|
||||
@ -117,19 +117,19 @@ class DES extends BlockCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $cfb_init_len = 500;
|
||||
protected $cfb_init_len = 500;
|
||||
|
||||
/**
|
||||
* Switch for DES/3DES encryption
|
||||
*
|
||||
* Used only if $engine == self::ENGINE_INTERNAL
|
||||
*
|
||||
* @see self::_setupKey()
|
||||
* @see self::_processBlock()
|
||||
* @see self::setupKey()
|
||||
* @see self::processBlock()
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $des_rounds = 1;
|
||||
protected $des_rounds = 1;
|
||||
|
||||
/**
|
||||
* max possible size of $key
|
||||
@ -138,16 +138,16 @@ class DES extends BlockCipher
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $key_length_max = 8;
|
||||
protected $key_length_max = 8;
|
||||
|
||||
/**
|
||||
* The Key Schedule
|
||||
*
|
||||
* @see self::_setupKey()
|
||||
* @see self::setupKey()
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $keys;
|
||||
private $keys;
|
||||
|
||||
/**
|
||||
* Shuffle table.
|
||||
@ -156,12 +156,12 @@ class DES extends BlockCipher
|
||||
* with each byte containing all bits in the same state as the
|
||||
* corresponding bit in the index value.
|
||||
*
|
||||
* @see self::_processBlock()
|
||||
* @see self::_setupKey()
|
||||
* @see self::processBlock()
|
||||
* @see self::setupKey()
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $shuffle = 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\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",
|
||||
@ -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\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"
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* IP mapping helper table.
|
||||
@ -300,7 +300,7 @@ class DES extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $ipmap = array(
|
||||
private $ipmap = [
|
||||
0x00, 0x10, 0x01, 0x11, 0x20, 0x30, 0x21, 0x31,
|
||||
0x02, 0x12, 0x03, 0x13, 0x22, 0x32, 0x23, 0x33,
|
||||
0x40, 0x50, 0x41, 0x51, 0x60, 0x70, 0x61, 0x71,
|
||||
@ -333,7 +333,7 @@ class DES extends BlockCipher
|
||||
0x8E, 0x9E, 0x8F, 0x9F, 0xAE, 0xBE, 0xAF, 0xBF,
|
||||
0xCC, 0xDC, 0xCD, 0xDD, 0xEC, 0xFC, 0xED, 0xFD,
|
||||
0xCE, 0xDE, 0xCF, 0xDF, 0xEE, 0xFE, 0xEF, 0xFF
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Inverse IP mapping helper table.
|
||||
@ -342,7 +342,7 @@ class DES extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $invipmap = array(
|
||||
private $invipmap = [
|
||||
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
|
||||
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
||||
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
|
||||
@ -375,7 +375,7 @@ class DES extends BlockCipher
|
||||
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
||||
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
|
||||
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Pre-permuted S-box1
|
||||
@ -386,7 +386,7 @@ class DES extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $sbox1 = array(
|
||||
private $sbox1 = [
|
||||
0x00808200, 0x00000000, 0x00008000, 0x00808202,
|
||||
0x00808002, 0x00008202, 0x00000002, 0x00008000,
|
||||
0x00000200, 0x00808200, 0x00808202, 0x00000200,
|
||||
@ -403,7 +403,7 @@ class DES extends BlockCipher
|
||||
0x00800002, 0x00000202, 0x00008202, 0x00808200,
|
||||
0x00000202, 0x00800200, 0x00800200, 0x00000000,
|
||||
0x00008002, 0x00008200, 0x00000000, 0x00808002
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Pre-permuted S-box2
|
||||
@ -411,7 +411,7 @@ class DES extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $sbox2 = array(
|
||||
private $sbox2 = [
|
||||
0x40084010, 0x40004000, 0x00004000, 0x00084010,
|
||||
0x00080000, 0x00000010, 0x40080010, 0x40004010,
|
||||
0x40000010, 0x40084010, 0x40084000, 0x40000000,
|
||||
@ -428,7 +428,7 @@ class DES extends BlockCipher
|
||||
0x00080010, 0x40004010, 0x40000010, 0x00080010,
|
||||
0x00084000, 0x00000000, 0x40004000, 0x00004010,
|
||||
0x40000000, 0x40080010, 0x40084010, 0x00084000
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Pre-permuted S-box3
|
||||
@ -436,7 +436,7 @@ class DES extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $sbox3 = array(
|
||||
private $sbox3 = [
|
||||
0x00000104, 0x04010100, 0x00000000, 0x04010004,
|
||||
0x04000100, 0x00000000, 0x00010104, 0x04000100,
|
||||
0x00010004, 0x04000004, 0x04000004, 0x00010000,
|
||||
@ -453,7 +453,7 @@ class DES extends BlockCipher
|
||||
0x00000004, 0x00010104, 0x00010100, 0x04000004,
|
||||
0x04010000, 0x04000104, 0x00000104, 0x04010000,
|
||||
0x00010104, 0x00000004, 0x04010004, 0x00010100
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Pre-permuted S-box4
|
||||
@ -461,7 +461,7 @@ class DES extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $sbox4 = array(
|
||||
private $sbox4 = [
|
||||
0x80401000, 0x80001040, 0x80001040, 0x00000040,
|
||||
0x00401040, 0x80400040, 0x80400000, 0x80001000,
|
||||
0x00000000, 0x00401000, 0x00401000, 0x80401040,
|
||||
@ -478,7 +478,7 @@ class DES extends BlockCipher
|
||||
0x80400000, 0x80001000, 0x00401040, 0x80400040,
|
||||
0x80001000, 0x00001040, 0x00400000, 0x80401000,
|
||||
0x00000040, 0x00400000, 0x00001000, 0x00401040
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Pre-permuted S-box5
|
||||
@ -486,7 +486,7 @@ class DES extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $sbox5 = array(
|
||||
private $sbox5 = [
|
||||
0x00000080, 0x01040080, 0x01040000, 0x21000080,
|
||||
0x00040000, 0x00000080, 0x20000000, 0x01040000,
|
||||
0x20040080, 0x00040000, 0x01000080, 0x20040080,
|
||||
@ -503,7 +503,7 @@ class DES extends BlockCipher
|
||||
0x01040000, 0x00000000, 0x20040000, 0x21000000,
|
||||
0x00040080, 0x01000080, 0x20000080, 0x00040000,
|
||||
0x00000000, 0x20040000, 0x01040080, 0x20000080
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Pre-permuted S-box6
|
||||
@ -511,7 +511,7 @@ class DES extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $sbox6 = array(
|
||||
private $sbox6 = [
|
||||
0x10000008, 0x10200000, 0x00002000, 0x10202008,
|
||||
0x10200000, 0x00000008, 0x10202008, 0x00200000,
|
||||
0x10002000, 0x00202008, 0x00200000, 0x10000008,
|
||||
@ -528,7 +528,7 @@ class DES extends BlockCipher
|
||||
0x00000008, 0x00002000, 0x10200000, 0x00202008,
|
||||
0x00002000, 0x00200008, 0x10002008, 0x00000000,
|
||||
0x10202000, 0x10000000, 0x00200008, 0x10002008
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Pre-permuted S-box7
|
||||
@ -536,7 +536,7 @@ class DES extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $sbox7 = array(
|
||||
private $sbox7 = [
|
||||
0x00100000, 0x02100001, 0x02000401, 0x00000000,
|
||||
0x00000400, 0x02000401, 0x00100401, 0x02100400,
|
||||
0x02100401, 0x00100000, 0x00000000, 0x02000001,
|
||||
@ -553,7 +553,7 @@ class DES extends BlockCipher
|
||||
0x00100400, 0x00000000, 0x00000001, 0x02100401,
|
||||
0x00000000, 0x00100401, 0x02100000, 0x00000400,
|
||||
0x02000001, 0x02000400, 0x00000400, 0x00100001
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Pre-permuted S-box8
|
||||
@ -561,7 +561,7 @@ class DES extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $sbox8 = array(
|
||||
private $sbox8 = [
|
||||
0x08000820, 0x00000800, 0x00020000, 0x08020820,
|
||||
0x08000000, 0x08000820, 0x00000020, 0x08000000,
|
||||
0x00020020, 0x08020000, 0x08020820, 0x00020800,
|
||||
@ -578,7 +578,7 @@ class DES extends BlockCipher
|
||||
0x08020000, 0x08000800, 0x08000820, 0x00000000,
|
||||
0x08020820, 0x00020800, 0x00020800, 0x00000820,
|
||||
0x00000820, 0x00020020, 0x08000000, 0x08020800
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -587,7 +587,7 @@ class DES extends BlockCipher
|
||||
* @access public
|
||||
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided
|
||||
*/
|
||||
function __construct($mode)
|
||||
public function __construct($mode)
|
||||
{
|
||||
if ($mode == self::MODE_STREAM) {
|
||||
throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode');
|
||||
@ -606,12 +606,12 @@ class DES extends BlockCipher
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isValidEngine($engine)
|
||||
public function isValidEngine($engine)
|
||||
{
|
||||
if ($this->key_length_max == 8) {
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
$this->cipher_name_openssl_ecb = 'des-ecb';
|
||||
$this->cipher_name_openssl = 'des-' . $this->_openssl_translate_mode();
|
||||
$this->cipher_name_openssl = 'des-' . $this->openssl_translate_mode();
|
||||
}
|
||||
}
|
||||
|
||||
@ -629,7 +629,7 @@ class DES extends BlockCipher
|
||||
* @access public
|
||||
* @param string $key
|
||||
*/
|
||||
function setKey($key)
|
||||
public function setKey($key)
|
||||
{
|
||||
if (!($this instanceof TripleDES) && strlen($key) != 8) {
|
||||
throw new \LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of size 8 are supported');
|
||||
@ -642,31 +642,31 @@ class DES extends BlockCipher
|
||||
/**
|
||||
* Encrypts a block
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_encryptBlock()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::encryptBlock()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::encrypt()
|
||||
* @see self::encrypt()
|
||||
* @access private
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
function _encryptBlock($in)
|
||||
protected function encryptBlock($in)
|
||||
{
|
||||
return $this->_processBlock($in, self::ENCRYPT);
|
||||
return $this->processBlock($in, self::ENCRYPT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypts a block
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_decryptBlock()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::decryptBlock()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::decrypt()
|
||||
* @see self::decrypt()
|
||||
* @access private
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
function _decryptBlock($in)
|
||||
protected function decryptBlock($in)
|
||||
{
|
||||
return $this->_processBlock($in, self::DECRYPT);
|
||||
return $this->processBlock($in, self::DECRYPT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -676,14 +676,14 @@ class DES extends BlockCipher
|
||||
* {@link http://en.wikipedia.org/wiki/Image:Feistel.png Feistel.png} to get a general
|
||||
* idea of what this function does.
|
||||
*
|
||||
* @see self::_encryptBlock()
|
||||
* @see self::_decryptBlock()
|
||||
* @see self::encryptBlock()
|
||||
* @see self::decryptBlock()
|
||||
* @access private
|
||||
* @param string $block
|
||||
* @param int $mode
|
||||
* @return string
|
||||
*/
|
||||
function _processBlock($block, $mode)
|
||||
private function processBlock($block, $mode)
|
||||
{
|
||||
static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip;
|
||||
if (!$sbox1) {
|
||||
@ -707,7 +707,7 @@ class DES extends BlockCipher
|
||||
|
||||
// Do the initial IP permutation.
|
||||
$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") |
|
||||
($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") |
|
||||
($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") |
|
||||
@ -719,7 +719,7 @@ class DES extends BlockCipher
|
||||
|
||||
// Extract L0 and R0.
|
||||
$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) {
|
||||
// Perform the 16 steps.
|
||||
@ -761,22 +761,22 @@ class DES extends BlockCipher
|
||||
/**
|
||||
* Creates the key schedule
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::setupKey()
|
||||
* @access private
|
||||
*/
|
||||
function _setupKey()
|
||||
protected function setupKey()
|
||||
{
|
||||
if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->des_rounds === $this->kl['des_rounds']) {
|
||||
// already expanded
|
||||
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
|
||||
);
|
||||
];
|
||||
|
||||
static $pc1map = array(
|
||||
static $pc1map = [
|
||||
0x00, 0x00, 0x08, 0x08, 0x04, 0x04, 0x0C, 0x0C,
|
||||
0x02, 0x02, 0x0A, 0x0A, 0x06, 0x06, 0x0E, 0x0E,
|
||||
0x10, 0x10, 0x18, 0x18, 0x14, 0x14, 0x1C, 0x1C,
|
||||
@ -809,16 +809,16 @@ class DES extends BlockCipher
|
||||
0xE2, 0xE2, 0xEA, 0xEA, 0xE6, 0xE6, 0xEE, 0xEE,
|
||||
0xF0, 0xF0, 0xF8, 0xF8, 0xF4, 0xF4, 0xFC, 0xFC,
|
||||
0xF2, 0xF2, 0xFA, 0xFA, 0xF6, 0xF6, 0xFE, 0xFE
|
||||
);
|
||||
];
|
||||
|
||||
// Mapping tables for the PC-2 transformation.
|
||||
static $pc2mapc1 = array(
|
||||
static $pc2mapc1 = [
|
||||
0x00000000, 0x00000400, 0x00200000, 0x00200400,
|
||||
0x00000001, 0x00000401, 0x00200001, 0x00200401,
|
||||
0x02000000, 0x02000400, 0x02200000, 0x02200400,
|
||||
0x02000001, 0x02000401, 0x02200001, 0x02200401
|
||||
);
|
||||
static $pc2mapc2 = array(
|
||||
];
|
||||
static $pc2mapc2 = [
|
||||
0x00000000, 0x00000800, 0x08000000, 0x08000800,
|
||||
0x00010000, 0x00010800, 0x08010000, 0x08010800,
|
||||
0x00000000, 0x00000800, 0x08000000, 0x08000800,
|
||||
@ -883,8 +883,8 @@ class DES extends BlockCipher
|
||||
0x01050110, 0x01050910, 0x09050110, 0x09050910,
|
||||
0x01040110, 0x01040910, 0x09040110, 0x09040910,
|
||||
0x01050110, 0x01050910, 0x09050110, 0x09050910
|
||||
);
|
||||
static $pc2mapc3 = array(
|
||||
];
|
||||
static $pc2mapc3 = [
|
||||
0x00000000, 0x00000004, 0x00001000, 0x00001004,
|
||||
0x00000000, 0x00000004, 0x00001000, 0x00001004,
|
||||
0x10000000, 0x10000004, 0x10001000, 0x10001004,
|
||||
@ -949,8 +949,8 @@ class DES extends BlockCipher
|
||||
0x20080022, 0x20080026, 0x20081022, 0x20081026,
|
||||
0x30080022, 0x30080026, 0x30081022, 0x30081026,
|
||||
0x30080022, 0x30080026, 0x30081022, 0x30081026
|
||||
);
|
||||
static $pc2mapc4 = array(
|
||||
];
|
||||
static $pc2mapc4 = [
|
||||
0x00000000, 0x00100000, 0x00000008, 0x00100008,
|
||||
0x00000200, 0x00100200, 0x00000208, 0x00100208,
|
||||
0x00000000, 0x00100000, 0x00000008, 0x00100008,
|
||||
@ -1015,14 +1015,14 @@ class DES extends BlockCipher
|
||||
0x04022200, 0x04122200, 0x04022208, 0x04122208,
|
||||
0x04022000, 0x04122000, 0x04022008, 0x04122008,
|
||||
0x04022200, 0x04122200, 0x04022208, 0x04122208
|
||||
);
|
||||
static $pc2mapd1 = array(
|
||||
];
|
||||
static $pc2mapd1 = [
|
||||
0x00000000, 0x00000001, 0x08000000, 0x08000001,
|
||||
0x00200000, 0x00200001, 0x08200000, 0x08200001,
|
||||
0x00000002, 0x00000003, 0x08000002, 0x08000003,
|
||||
0x00200002, 0x00200003, 0x08200002, 0x08200003
|
||||
);
|
||||
static $pc2mapd2 = array(
|
||||
];
|
||||
static $pc2mapd2 = [
|
||||
0x00000000, 0x00100000, 0x00000800, 0x00100800,
|
||||
0x00000000, 0x00100000, 0x00000800, 0x00100800,
|
||||
0x04000000, 0x04100000, 0x04000800, 0x04100800,
|
||||
@ -1087,8 +1087,8 @@ class DES extends BlockCipher
|
||||
0x00020204, 0x00120204, 0x00020A04, 0x00120A04,
|
||||
0x04020204, 0x04120204, 0x04020A04, 0x04120A04,
|
||||
0x04020204, 0x04120204, 0x04020A04, 0x04120A04
|
||||
);
|
||||
static $pc2mapd3 = array(
|
||||
];
|
||||
static $pc2mapd3 = [
|
||||
0x00000000, 0x00010000, 0x02000000, 0x02010000,
|
||||
0x00000020, 0x00010020, 0x02000020, 0x02010020,
|
||||
0x00040000, 0x00050000, 0x02040000, 0x02050000,
|
||||
@ -1153,8 +1153,8 @@ class DES extends BlockCipher
|
||||
0x20002030, 0x20012030, 0x22002030, 0x22012030,
|
||||
0x20042010, 0x20052010, 0x22042010, 0x22052010,
|
||||
0x20042030, 0x20052030, 0x22042030, 0x22052030
|
||||
);
|
||||
static $pc2mapd4 = array(
|
||||
];
|
||||
static $pc2mapd4 = [
|
||||
0x00000000, 0x00000400, 0x01000000, 0x01000400,
|
||||
0x00000000, 0x00000400, 0x01000000, 0x01000400,
|
||||
0x00000100, 0x00000500, 0x01000100, 0x01000500,
|
||||
@ -1219,16 +1219,16 @@ class DES extends BlockCipher
|
||||
0x10081008, 0x10081408, 0x11081008, 0x11081408,
|
||||
0x10081108, 0x10081508, 0x11081108, 0x11081508,
|
||||
0x10081108, 0x10081508, 0x11081108, 0x11081508
|
||||
);
|
||||
];
|
||||
|
||||
$keys = array();
|
||||
$keys = [];
|
||||
for ($des_round = 0; $des_round < $this->des_rounds; ++$des_round) {
|
||||
// pad the key and remove extra characters as appropriate.
|
||||
$key = str_pad(substr($this->key, $des_round * 8, 8), 8, "\0");
|
||||
|
||||
// Perform the PC/1 transformation and compute C and D.
|
||||
$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") |
|
||||
($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") |
|
||||
@ -1241,10 +1241,10 @@ class DES extends BlockCipher
|
||||
$c = ( $key['c'] >> 4) & 0x0FFFFFFF;
|
||||
$d = (($key['d'] >> 4) & 0x0FFFFFF0) | ($key['c'] & 0x0F);
|
||||
|
||||
$keys[$des_round] = array(
|
||||
self::ENCRYPT => array(),
|
||||
$keys[$des_round] = [
|
||||
self::ENCRYPT => [],
|
||||
self::DECRYPT => array_fill(0, 32, 0)
|
||||
);
|
||||
];
|
||||
for ($i = 0, $ki = 31; $i < 16; ++$i, $ki-= 2) {
|
||||
$c <<= $shifts[$i];
|
||||
$c = ($c | ($c >> 28)) & 0x0FFFFFFF;
|
||||
@ -1271,7 +1271,7 @@ class DES extends BlockCipher
|
||||
|
||||
switch ($this->des_rounds) {
|
||||
case 3: // 3DES keys
|
||||
$this->keys = array(
|
||||
$this->keys = [
|
||||
self::ENCRYPT => array_merge(
|
||||
$keys[0][self::ENCRYPT],
|
||||
$keys[1][self::DECRYPT],
|
||||
@ -1282,174 +1282,127 @@ class DES extends BlockCipher
|
||||
$keys[1][self::ENCRYPT],
|
||||
$keys[0][self::DECRYPT]
|
||||
)
|
||||
);
|
||||
];
|
||||
break;
|
||||
// case 1: // DES keys
|
||||
default:
|
||||
$this->keys = array(
|
||||
$this->keys = [
|
||||
self::ENCRYPT => $keys[0][self::ENCRYPT],
|
||||
self::DECRYPT => $keys[0][self::DECRYPT]
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the performance-optimized function for de/encrypt()
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::setupInlineCrypt()
|
||||
* @access private
|
||||
*/
|
||||
function _setupInlineCrypt()
|
||||
protected function setupInlineCrypt()
|
||||
{
|
||||
$lambda_functions =& self::_getLambdaFunctions();
|
||||
|
||||
// Engine configuration for:
|
||||
// - DES ($des_rounds == 1) or
|
||||
// - 3DES ($des_rounds == 3)
|
||||
$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.
|
||||
// (Currently, for DES, one generated $lambda_function cost on php5.5@32bit ~135kb unfreeable mem and ~230kb on php5.5@64bit)
|
||||
// (Currently, for TripleDES, one generated $lambda_function cost on php5.5@32bit ~240kb unfreeable mem and ~340kb on php5.5@64bit)
|
||||
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one
|
||||
$gen_hi_opt_code = (bool)( count($lambda_functions) < 10 );
|
||||
|
||||
// Generation of a unique hash for our generated code
|
||||
$code_hash = "Crypt_DES, $des_rounds, {$this->mode}";
|
||||
if ($gen_hi_opt_code) {
|
||||
// For hi-optimized code, we create for each combination of
|
||||
// $mode, $des_rounds and $this->key its own encrypt/decrypt function.
|
||||
// After max 10 hi-optimized functions, we create generic
|
||||
// (still very fast.. but not ultra) functions for each $mode/$des_rounds
|
||||
// Currently 2 * 5 generic functions will be then max. possible.
|
||||
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
|
||||
}
|
||||
|
||||
// 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]];
|
||||
}
|
||||
$init_crypt = 'static $sbox1, $sbox2, $sbox3, $sbox4, $sbox5, $sbox6, $sbox7, $sbox8, $shuffleip, $shuffleinvip;
|
||||
if (!$sbox1) {
|
||||
$sbox1 = array_map("intval", $this->sbox1);
|
||||
$sbox2 = array_map("intval", $this->sbox2);
|
||||
$sbox3 = array_map("intval", $this->sbox3);
|
||||
$sbox4 = array_map("intval", $this->sbox4);
|
||||
$sbox5 = array_map("intval", $this->sbox5);
|
||||
$sbox6 = array_map("intval", $this->sbox6);
|
||||
$sbox7 = array_map("intval", $this->sbox7);
|
||||
$sbox8 = array_map("intval", $this->sbox8);'
|
||||
/* Merge $shuffle with $[inv]ipmap */ . '
|
||||
for ($i = 0; $i < 256; ++$i) {
|
||||
$shuffleip[] = $this->shuffle[$this->ipmap[$i]];
|
||||
$shuffleinvip[] = $this->shuffle[$this->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) {
|
||||
case $gen_hi_opt_code:
|
||||
// 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;
|
||||
}
|
||||
$l = '$l';
|
||||
$r = '$r';
|
||||
|
||||
// Creating code for en- and decryption.
|
||||
$crypt_block = array();
|
||||
foreach (array(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];
|
||||
';
|
||||
// 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"
|
||||
|
||||
$l = '$l';
|
||||
$r = '$r';
|
||||
|
||||
// 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);
|
||||
// swap L & R
|
||||
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");
|
||||
';
|
||||
list($l, $r) = [$r, $l];
|
||||
}
|
||||
|
||||
// Creates the inline-crypt function
|
||||
$lambda_functions[$code_hash] = $this->_createInlineCryptFunction(
|
||||
array(
|
||||
'init_crypt' => $init_crypt,
|
||||
'init_encrypt' => $init_encrypt,
|
||||
'init_decrypt' => $init_decrypt,
|
||||
'encrypt_block' => $crypt_block[self::ENCRYPT],
|
||||
'decrypt_block' => $crypt_block[self::DECRYPT]
|
||||
)
|
||||
);
|
||||
// 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");
|
||||
';
|
||||
}
|
||||
|
||||
// Set the inline-crypt function as callback in: $this->inline_crypt
|
||||
$this->inline_crypt = $lambda_functions[$code_hash];
|
||||
// Creates the inline-crypt function
|
||||
$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]
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class Hash
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $hashParam;
|
||||
private $hashParam;
|
||||
|
||||
/**
|
||||
* Byte-length of hash output (Internal HMAC)
|
||||
@ -61,7 +61,7 @@ class Hash
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $length;
|
||||
private $length;
|
||||
|
||||
/**
|
||||
* Hash Algorithm
|
||||
@ -70,7 +70,7 @@ class Hash
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $hash;
|
||||
private $hash;
|
||||
|
||||
/**
|
||||
* Key
|
||||
@ -79,7 +79,7 @@ class Hash
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $key = false;
|
||||
private $key = false;
|
||||
|
||||
/**
|
||||
* Initial Hash
|
||||
@ -90,7 +90,7 @@ class Hash
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $initial = false;
|
||||
private $initial = false;
|
||||
|
||||
/**
|
||||
* Outer XOR (Internal HMAC)
|
||||
@ -101,7 +101,7 @@ class Hash
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $opad;
|
||||
private $opad;
|
||||
|
||||
/**
|
||||
* Inner XOR (Internal HMAC)
|
||||
@ -112,7 +112,7 @@ class Hash
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $ipad;
|
||||
private $ipad;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -120,7 +120,7 @@ class Hash
|
||||
* @param string $hash
|
||||
* @access public
|
||||
*/
|
||||
function __construct($hash = 'sha256')
|
||||
public function __construct($hash = 'sha256')
|
||||
{
|
||||
$this->setHash($hash);
|
||||
|
||||
@ -136,7 +136,7 @@ class Hash
|
||||
* @access public
|
||||
* @param string $key
|
||||
*/
|
||||
function setKey($key = false)
|
||||
public function setKey($key = false)
|
||||
{
|
||||
$this->key = $key;
|
||||
}
|
||||
@ -149,7 +149,7 @@ class Hash
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getHash()
|
||||
public function getHash()
|
||||
{
|
||||
return $this->hashParam;
|
||||
}
|
||||
@ -160,7 +160,7 @@ class Hash
|
||||
* @access public
|
||||
* @param string $hash
|
||||
*/
|
||||
function setHash($hash)
|
||||
public function setHash($hash)
|
||||
{
|
||||
$this->hashParam = $hash = strtolower($hash);
|
||||
switch ($hash) {
|
||||
@ -223,14 +223,14 @@ class Hash
|
||||
if ($hash == 'sha512/224' || $hash == 'sha512/256') {
|
||||
// from http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf#page=24
|
||||
$this->initial = $hash == 'sha512/256' ?
|
||||
array(
|
||||
[
|
||||
'22312194FC2BF72C', '9F555FA3C84C64C2', '2393B86B6F53B151', '963877195940EABD',
|
||||
'96283EE2A88EFFE3', 'BE5E1E2553863992', '2B0199FC2C85B8AA', '0EB72DDC81C52CA2'
|
||||
) :
|
||||
array(
|
||||
] :
|
||||
[
|
||||
'8C3D37C819544DA2', '73E1996689DCD4D6', '1DFAB7AE32FF9C82', '679DD514582F9FCF',
|
||||
'0F6D2B697BD44DA8', '77E36F7304C48942', '3F9D85A86A1D36C8', '1112E6AD91D692A1'
|
||||
);
|
||||
];
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$this->initial[$i] = new BigInteger($this->initial[$i], 16);
|
||||
$this->initial[$i]->setPrecision(64);
|
||||
@ -247,7 +247,7 @@ class Hash
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
function hash($text)
|
||||
public function hash($text)
|
||||
{
|
||||
switch ($this->hash) {
|
||||
case 'sha512/224':
|
||||
@ -286,7 +286,7 @@ class Hash
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getLength()
|
||||
public function getLength()
|
||||
{
|
||||
return $this->length << 3;
|
||||
}
|
||||
@ -297,7 +297,7 @@ class Hash
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getLengthInBytes()
|
||||
public function getLengthInBytes()
|
||||
{
|
||||
return $this->length;
|
||||
}
|
||||
@ -308,7 +308,7 @@ class Hash
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getBlockLength()
|
||||
public function getBlockLength()
|
||||
{
|
||||
return $this->blockSize;
|
||||
}
|
||||
@ -319,7 +319,7 @@ class Hash
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getBlockLengthInBytes()
|
||||
public function getBlockLengthInBytes()
|
||||
{
|
||||
return $this->blockSize >> 3;
|
||||
}
|
||||
@ -330,14 +330,14 @@ class Hash
|
||||
* @access private
|
||||
* @param string $m
|
||||
*/
|
||||
static function _sha512($m, $hash)
|
||||
private static function _sha512($m, $hash)
|
||||
{
|
||||
static $k;
|
||||
|
||||
if (!isset($k)) {
|
||||
// Initialize table of round constants
|
||||
// (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',
|
||||
'3956c25bf348b538', '59f111f1b605d019', '923f82a4af194f9b', 'ab1c5ed5da6d8118',
|
||||
'd807aa98a3030242', '12835b0145706fbe', '243185be4ee4b28c', '550c7dc3d5ffb4e2',
|
||||
@ -358,7 +358,7 @@ class Hash
|
||||
'06f067aa72176fba', '0a637dc5a2c898a6', '113f9804bef90dae', '1b710b35131c471b',
|
||||
'28db77f523047d84', '32caab7b40c72493', '3c9ebe0a15c9bebc', '431d67c49c100d4c',
|
||||
'4cc5d4becb3e42b6', '597f299cfc657e2a', '5fcb6fab3ad6faec', '6c44198c4a475817'
|
||||
);
|
||||
];
|
||||
|
||||
for ($i = 0; $i < 80; $i++) {
|
||||
$k[$i] = new BigInteger($k[$i], 16);
|
||||
@ -376,7 +376,7 @@ class Hash
|
||||
// Process the message in successive 1024-bit chunks
|
||||
$chunks = str_split($m, 128);
|
||||
foreach ($chunks as $chunk) {
|
||||
$w = array();
|
||||
$w = [];
|
||||
for ($i = 0; $i < 16; $i++) {
|
||||
$temp = new BigInteger(Strings::shift($chunk, 8), 256);
|
||||
$temp->setPrecision(64);
|
||||
@ -385,18 +385,18 @@ class Hash
|
||||
|
||||
// Extend the sixteen 32-bit words into eighty 32-bit words
|
||||
for ($i = 16; $i < 80; $i++) {
|
||||
$temp = array(
|
||||
$temp = [
|
||||
$w[$i - 15]->bitwise_rightRotate(1),
|
||||
$w[$i - 15]->bitwise_rightRotate(8),
|
||||
$w[$i - 15]->bitwise_rightShift(7)
|
||||
);
|
||||
];
|
||||
$s0 = $temp[0]->bitwise_xor($temp[1]);
|
||||
$s0 = $s0->bitwise_xor($temp[2]);
|
||||
$temp = array(
|
||||
$temp = [
|
||||
$w[$i - 2]->bitwise_rightRotate(19),
|
||||
$w[$i - 2]->bitwise_rightRotate(61),
|
||||
$w[$i - 2]->bitwise_rightShift(6)
|
||||
);
|
||||
];
|
||||
$s1 = $temp[0]->bitwise_xor($temp[1]);
|
||||
$s1 = $s1->bitwise_xor($temp[2]);
|
||||
$w[$i] = clone $w[$i - 16];
|
||||
@ -417,33 +417,33 @@ class Hash
|
||||
|
||||
// Main loop
|
||||
for ($i = 0; $i < 80; $i++) {
|
||||
$temp = array(
|
||||
$temp = [
|
||||
$a->bitwise_rightRotate(28),
|
||||
$a->bitwise_rightRotate(34),
|
||||
$a->bitwise_rightRotate(39)
|
||||
);
|
||||
];
|
||||
$s0 = $temp[0]->bitwise_xor($temp[1]);
|
||||
$s0 = $s0->bitwise_xor($temp[2]);
|
||||
$temp = array(
|
||||
$temp = [
|
||||
$a->bitwise_and($b),
|
||||
$a->bitwise_and($c),
|
||||
$b->bitwise_and($c)
|
||||
);
|
||||
];
|
||||
$maj = $temp[0]->bitwise_xor($temp[1]);
|
||||
$maj = $maj->bitwise_xor($temp[2]);
|
||||
$t2 = $s0->add($maj);
|
||||
|
||||
$temp = array(
|
||||
$temp = [
|
||||
$e->bitwise_rightRotate(14),
|
||||
$e->bitwise_rightRotate(18),
|
||||
$e->bitwise_rightRotate(41)
|
||||
);
|
||||
];
|
||||
$s1 = $temp[0]->bitwise_xor($temp[1]);
|
||||
$s1 = $s1->bitwise_xor($temp[2]);
|
||||
$temp = array(
|
||||
$temp = [
|
||||
$e->bitwise_and($f),
|
||||
$g->bitwise_and($e->bitwise_not())
|
||||
);
|
||||
];
|
||||
$ch = $temp[0]->bitwise_xor($temp[1]);
|
||||
$t1 = $h->add($s1);
|
||||
$t1 = $t1->add($ch);
|
||||
@ -461,7 +461,7 @@ class Hash
|
||||
}
|
||||
|
||||
// Add this chunk's hash to result so far
|
||||
$hash = array(
|
||||
$hash = [
|
||||
$hash[0]->add($a),
|
||||
$hash[1]->add($b),
|
||||
$hash[2]->add($c),
|
||||
@ -470,7 +470,7 @@ class Hash
|
||||
$hash[5]->add($f),
|
||||
$hash[6]->add($g),
|
||||
$hash[7]->add($h)
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Produce the final hash value (big-endian)
|
||||
|
@ -52,7 +52,7 @@ class RC2 extends BlockCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $block_size = 8;
|
||||
protected $block_size = 8;
|
||||
|
||||
/**
|
||||
* The Key
|
||||
@ -62,7 +62,7 @@ class RC2 extends BlockCipher
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $key;
|
||||
protected $key;
|
||||
|
||||
/**
|
||||
* The Original (unpadded) Key
|
||||
@ -74,16 +74,16 @@ class RC2 extends BlockCipher
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $orig_key;
|
||||
private $orig_key;
|
||||
|
||||
/**
|
||||
* Don't truncate / null pad key
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_clearBuffers()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::clearBuffers()
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $skip_key_adjustment = true;
|
||||
private $skip_key_adjustment = true;
|
||||
|
||||
/**
|
||||
* Key Length (in bytes)
|
||||
@ -92,7 +92,7 @@ class RC2 extends BlockCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $key_length = 16; // = 128 bits
|
||||
protected $key_length = 16; // = 128 bits
|
||||
|
||||
/**
|
||||
* The mcrypt specific name of the cipher
|
||||
@ -101,7 +101,7 @@ class RC2 extends BlockCipher
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $cipher_name_mcrypt = 'rc2';
|
||||
protected $cipher_name_mcrypt = 'rc2';
|
||||
|
||||
/**
|
||||
* Optimizing value while CFB-encrypting
|
||||
@ -110,7 +110,7 @@ class RC2 extends BlockCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $cfb_init_len = 500;
|
||||
protected $cfb_init_len = 500;
|
||||
|
||||
/**
|
||||
* The key length in bits.
|
||||
@ -122,7 +122,7 @@ class RC2 extends BlockCipher
|
||||
* @internal Should be in range [1..1024].
|
||||
* @internal Changing this value after setting the key has no effect.
|
||||
*/
|
||||
var $default_key_length = 1024;
|
||||
private $default_key_length = 1024;
|
||||
|
||||
/**
|
||||
* The key length in bits.
|
||||
@ -133,16 +133,16 @@ class RC2 extends BlockCipher
|
||||
* @access private
|
||||
* @internal Should be in range [1..1024].
|
||||
*/
|
||||
var $current_key_length;
|
||||
private $current_key_length;
|
||||
|
||||
/**
|
||||
* The Key Schedule
|
||||
*
|
||||
* @see self::_setupKey()
|
||||
* @see self::setupKey()
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $keys;
|
||||
private $keys;
|
||||
|
||||
/**
|
||||
* Key expansion randomization table.
|
||||
@ -152,7 +152,7 @@ class RC2 extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $pitable = array(
|
||||
private $pitable = [
|
||||
0xD9, 0x78, 0xF9, 0xC4, 0x19, 0xDD, 0xB5, 0xED,
|
||||
0x28, 0xE9, 0xFD, 0x79, 0x4A, 0xA0, 0xD8, 0x9D,
|
||||
0xC6, 0x7E, 0x37, 0x83, 0x2B, 0x76, 0x53, 0x8E,
|
||||
@ -217,7 +217,7 @@ class RC2 extends BlockCipher
|
||||
0xBB, 0x48, 0x0C, 0x5F, 0xB9, 0xB1, 0xCD, 0x2E,
|
||||
0xC5, 0xF3, 0xDB, 0x47, 0xE5, 0xA5, 0x9C, 0x77,
|
||||
0x0A, 0xA6, 0x20, 0x68, 0xFE, 0x7F, 0xC1, 0xAD
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Inverse key expansion randomization table.
|
||||
@ -226,7 +226,7 @@ class RC2 extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $invpitable = array(
|
||||
private $invpitable = [
|
||||
0xD1, 0xDA, 0xB9, 0x6F, 0x9C, 0xC8, 0x78, 0x66,
|
||||
0x80, 0x2C, 0xF8, 0x37, 0xEA, 0xE0, 0x62, 0xA4,
|
||||
0xCB, 0x71, 0x50, 0x27, 0x4B, 0x95, 0xD9, 0x20,
|
||||
@ -259,7 +259,7 @@ class RC2 extends BlockCipher
|
||||
0x81, 0x09, 0x82, 0x33, 0x9F, 0x07, 0x86, 0x75,
|
||||
0x38, 0x4E, 0x69, 0xF1, 0xAD, 0x23, 0x73, 0x87,
|
||||
0x70, 0x02, 0xC2, 0x1E, 0xB8, 0x0A, 0xFC, 0xE6
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -268,7 +268,7 @@ class RC2 extends BlockCipher
|
||||
* @access public
|
||||
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided
|
||||
*/
|
||||
function __construct($mode)
|
||||
public function __construct($mode)
|
||||
{
|
||||
if ($mode == self::MODE_STREAM) {
|
||||
throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode');
|
||||
@ -287,7 +287,7 @@ class RC2 extends BlockCipher
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isValidEngine($engine)
|
||||
public function isValidEngine($engine)
|
||||
{
|
||||
switch ($engine) {
|
||||
case self::ENGINE_OPENSSL:
|
||||
@ -295,7 +295,7 @@ class RC2 extends BlockCipher
|
||||
return false;
|
||||
}
|
||||
$this->cipher_name_openssl_ecb = 'rc2-ecb';
|
||||
$this->cipher_name_openssl = 'rc2-' . $this->_openssl_translate_mode();
|
||||
$this->cipher_name_openssl = 'rc2-' . $this->openssl_translate_mode();
|
||||
}
|
||||
|
||||
return parent::isValidEngine($engine);
|
||||
@ -312,7 +312,7 @@ class RC2 extends BlockCipher
|
||||
* @param int $length in bits
|
||||
* @throws \LengthException if the key length isn't supported
|
||||
*/
|
||||
function setKeyLength($length)
|
||||
public function setKeyLength($length)
|
||||
{
|
||||
if ($length < 8 || $length > 1024) {
|
||||
throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys between 1 and 1024 bits, inclusive, are supported');
|
||||
@ -328,7 +328,7 @@ class RC2 extends BlockCipher
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getKeyLength()
|
||||
public function getKeyLength()
|
||||
{
|
||||
return $this->current_key_length;
|
||||
}
|
||||
@ -347,7 +347,7 @@ class RC2 extends BlockCipher
|
||||
* @param int $t1 optional Effective key length in bits.
|
||||
* @throws \LengthException if the key length isn't supported
|
||||
*/
|
||||
function setKey($key, $t1 = false)
|
||||
public function setKey($key, $t1 = false)
|
||||
{
|
||||
$this->orig_key = $key;
|
||||
|
||||
@ -395,7 +395,7 @@ class RC2 extends BlockCipher
|
||||
$this->key = call_user_func_array('pack', $l);
|
||||
$this->key_length = strlen($this->key);
|
||||
$this->changed = true;
|
||||
$this->_setEngine();
|
||||
$this->setEngine();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -408,7 +408,7 @@ class RC2 extends BlockCipher
|
||||
* @param string $plaintext
|
||||
* @return string $ciphertext
|
||||
*/
|
||||
function encrypt($plaintext)
|
||||
public function encrypt($plaintext)
|
||||
{
|
||||
if ($this->engine == self::ENGINE_OPENSSL) {
|
||||
$temp = $this->key;
|
||||
@ -431,7 +431,7 @@ class RC2 extends BlockCipher
|
||||
* @param string $ciphertext
|
||||
* @return string $plaintext
|
||||
*/
|
||||
function decrypt($ciphertext)
|
||||
public function decrypt($ciphertext)
|
||||
{
|
||||
if ($this->engine == self::ENGINE_OPENSSL) {
|
||||
$temp = $this->key;
|
||||
@ -447,18 +447,18 @@ class RC2 extends BlockCipher
|
||||
/**
|
||||
* Encrypts a block
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_encryptBlock()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::encryptBlock()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::encrypt()
|
||||
* @access private
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
function _encryptBlock($in)
|
||||
protected function encryptBlock($in)
|
||||
{
|
||||
list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in));
|
||||
$keys = $this->keys;
|
||||
$limit = 20;
|
||||
$actions = array($limit => 44, 44 => 64);
|
||||
$actions = [$limit => 44, 44 => 64];
|
||||
$j = 0;
|
||||
|
||||
for (;;) {
|
||||
@ -492,18 +492,18 @@ class RC2 extends BlockCipher
|
||||
/**
|
||||
* Decrypts a block
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_decryptBlock()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::decryptBlock()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::decrypt()
|
||||
* @access private
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
function _decryptBlock($in)
|
||||
protected function decryptBlock($in)
|
||||
{
|
||||
list($r0, $r1, $r2, $r3) = array_values(unpack('v*', $in));
|
||||
$keys = $this->keys;
|
||||
$limit = 44;
|
||||
$actions = array($limit => 20, 20 => 0);
|
||||
$actions = [$limit => 20, 20 => 0];
|
||||
$j = 64;
|
||||
|
||||
for (;;) {
|
||||
@ -534,28 +534,13 @@ class RC2 extends BlockCipher
|
||||
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
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::setupKey()
|
||||
* @access private
|
||||
*/
|
||||
function _setupKey()
|
||||
protected function setupKey()
|
||||
{
|
||||
if (!isset($this->key)) {
|
||||
$this->setKey('');
|
||||
@ -573,137 +558,108 @@ class RC2 extends BlockCipher
|
||||
/**
|
||||
* Setup the performance-optimized function for de/encrypt()
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::setupInlineCrypt()
|
||||
* @access private
|
||||
*/
|
||||
function _setupInlineCrypt()
|
||||
protected function setupInlineCrypt()
|
||||
{
|
||||
$lambda_functions =& self::_getLambdaFunctions();
|
||||
// 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
|
||||
// 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);
|
||||
$keys = $this->keys;
|
||||
|
||||
// Generation of a unique hash for our generated code
|
||||
$code_hash = "Crypt_RC2, {$this->mode}";
|
||||
if ($gen_hi_opt_code) {
|
||||
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
|
||||
}
|
||||
// $in is the current 8 bytes block which has to be en/decrypt
|
||||
$encrypt_block = $decrypt_block = '
|
||||
$in = unpack("v4", $in);
|
||||
$r0 = $in[1];
|
||||
$r1 = $in[2];
|
||||
$r2 = $in[3];
|
||||
$r3 = $in[4];
|
||||
';
|
||||
|
||||
// Is there a re-usable $lambda_functions in there?
|
||||
// If not, we have to create it.
|
||||
if (!isset($lambda_functions[$code_hash])) {
|
||||
// Init code for both, encrypt and decrypt.
|
||||
$init_crypt = '$keys = $self->keys;';
|
||||
// Create code for encryption.
|
||||
$limit = 20;
|
||||
$actions = [$limit => 44, 44 => 64];
|
||||
$j = 0;
|
||||
|
||||
switch (true) {
|
||||
case $gen_hi_opt_code:
|
||||
$keys = $this->keys;
|
||||
default:
|
||||
$keys = array();
|
||||
foreach ($this->keys as $k => $v) {
|
||||
$keys[$k] = '$keys[' . $k . ']';
|
||||
}
|
||||
}
|
||||
for (;;) {
|
||||
// Mixing round.
|
||||
$encrypt_block .= '
|
||||
$r0 = (($r0 + ' . $keys[$j++] . ' +
|
||||
((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF) << 1;
|
||||
$r0 |= $r0 >> 16;
|
||||
$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
|
||||
$encrypt_block = $decrypt_block = '
|
||||
$in = unpack("v4", $in);
|
||||
$r0 = $in[1];
|
||||
$r1 = $in[2];
|
||||
$r2 = $in[3];
|
||||
$r3 = $in[4];
|
||||
';
|
||||
if ($j === $limit) {
|
||||
if ($limit === 64) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Create code for encryption.
|
||||
$limit = 20;
|
||||
$actions = array($limit => 44, 44 => 64);
|
||||
$j = 0;
|
||||
|
||||
for (;;) {
|
||||
// Mixing round.
|
||||
// Mashing round.
|
||||
$encrypt_block .= '
|
||||
$r0 = (($r0 + ' . $keys[$j++] . ' +
|
||||
((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF) << 1;
|
||||
$r0 |= $r0 >> 16;
|
||||
$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;';
|
||||
|
||||
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];
|
||||
}
|
||||
$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.
|
||||
$limit = 44;
|
||||
$actions = array($limit => 20, 20 => 0);
|
||||
$j = 64;
|
||||
// Create code for decryption.
|
||||
$limit = 44;
|
||||
$actions = [$limit => 20, 20 => 0];
|
||||
$j = 64;
|
||||
|
||||
for (;;) {
|
||||
// R-mixing round.
|
||||
for (;;) {
|
||||
// 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 .= '
|
||||
$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 .= '
|
||||
$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];
|
||||
}
|
||||
$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
|
||||
$this->inline_crypt = $lambda_functions[$code_hash];
|
||||
$decrypt_block .= '$in = pack("v4", $r0, $r1, $r2, $r3);';
|
||||
|
||||
// Creates the inline-crypt function
|
||||
$this->inline_crypt = $this->createInlineCryptFunction(
|
||||
[
|
||||
'init_crypt' => $init_crypt,
|
||||
'encrypt_block' => $encrypt_block,
|
||||
'decrypt_block' => $decrypt_block
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ class RC4 extends StreamCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $block_size = 0;
|
||||
protected $block_size = 0;
|
||||
|
||||
/**
|
||||
* Key Length (in bytes)
|
||||
@ -82,7 +82,7 @@ class RC4 extends StreamCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $key_length = 128; // = 1024 bits
|
||||
protected $key_length = 128; // = 1024 bits
|
||||
|
||||
/**
|
||||
* The mcrypt specific name of the cipher
|
||||
@ -91,7 +91,7 @@ class RC4 extends StreamCipher
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $cipher_name_mcrypt = 'arcfour';
|
||||
protected $cipher_name_mcrypt = 'arcfour';
|
||||
|
||||
/**
|
||||
* Holds whether performance-optimized $inline_crypt() can/should be used.
|
||||
@ -100,7 +100,7 @@ class RC4 extends StreamCipher
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $use_inline_crypt = false; // currently not available
|
||||
protected $use_inline_crypt = false; // currently not available
|
||||
|
||||
/**
|
||||
* The Key
|
||||
@ -109,7 +109,7 @@ class RC4 extends StreamCipher
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $key;
|
||||
protected $key;
|
||||
|
||||
/**
|
||||
* The Key Stream for decryption and encryption
|
||||
@ -118,7 +118,7 @@ class RC4 extends StreamCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $stream;
|
||||
private $stream;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -127,7 +127,7 @@ class RC4 extends StreamCipher
|
||||
* @return \phpseclib\Crypt\RC4
|
||||
* @access public
|
||||
*/
|
||||
function __construct()
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(self::MODE_STREAM);
|
||||
}
|
||||
@ -142,7 +142,7 @@ class RC4 extends StreamCipher
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isValidEngine($engine)
|
||||
public function isValidEngine($engine)
|
||||
{
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
$this->cipher_name_openssl = 'rc4-40';
|
||||
@ -157,7 +157,7 @@ class RC4 extends StreamCipher
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function usesIV()
|
||||
public function usesIV()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -171,7 +171,7 @@ class RC4 extends StreamCipher
|
||||
* @param int $length
|
||||
* @throws \LengthException if the key length is invalid
|
||||
*/
|
||||
function setKeyLength($length)
|
||||
public function setKeyLength($length)
|
||||
{
|
||||
if ($length < 8 || $length > 2048) {
|
||||
throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys between 1 and 256 bytes are supported');
|
||||
@ -191,7 +191,7 @@ class RC4 extends StreamCipher
|
||||
* @param int $length
|
||||
* @throws \LengthException if the key length is invalid
|
||||
*/
|
||||
function setKey($key)
|
||||
public function setKey($key)
|
||||
{
|
||||
$length = strlen($key);
|
||||
if ($length < 1 || $length > 256) {
|
||||
@ -205,17 +205,17 @@ class RC4 extends StreamCipher
|
||||
* Encrypts a message.
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::decrypt()
|
||||
* @see self::_crypt()
|
||||
* @see self::crypt()
|
||||
* @access public
|
||||
* @param string $plaintext
|
||||
* @return string $ciphertext
|
||||
*/
|
||||
function encrypt($plaintext)
|
||||
public function encrypt($plaintext)
|
||||
{
|
||||
if ($this->engine != self::ENGINE_INTERNAL) {
|
||||
return parent::encrypt($plaintext);
|
||||
}
|
||||
return $this->_crypt($plaintext, self::ENCRYPT);
|
||||
return $this->crypt($plaintext, self::ENCRYPT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -225,17 +225,17 @@ class RC4 extends StreamCipher
|
||||
* At least if the continuous buffer is disabled.
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::encrypt()
|
||||
* @see self::_crypt()
|
||||
* @see self::crypt()
|
||||
* @access public
|
||||
* @param string $ciphertext
|
||||
* @return string $plaintext
|
||||
*/
|
||||
function decrypt($ciphertext)
|
||||
public function decrypt($ciphertext)
|
||||
{
|
||||
if ($this->engine != self::ENGINE_INTERNAL) {
|
||||
return parent::decrypt($ciphertext);
|
||||
}
|
||||
return $this->_crypt($ciphertext, self::DECRYPT);
|
||||
return $this->crypt($ciphertext, self::DECRYPT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,7 +244,7 @@ class RC4 extends StreamCipher
|
||||
* @access private
|
||||
* @param string $in
|
||||
*/
|
||||
function _encryptBlock($in)
|
||||
protected function encryptBlock($in)
|
||||
{
|
||||
// RC4 does not utilize this method
|
||||
}
|
||||
@ -255,7 +255,7 @@ class RC4 extends StreamCipher
|
||||
* @access private
|
||||
* @param string $in
|
||||
*/
|
||||
function _decryptBlock($in)
|
||||
protected function decryptBlock($in)
|
||||
{
|
||||
// RC4 does not utilize this method
|
||||
}
|
||||
@ -266,7 +266,7 @@ class RC4 extends StreamCipher
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey()
|
||||
* @access private
|
||||
*/
|
||||
function _setupKey()
|
||||
protected function setupKey()
|
||||
{
|
||||
$key = $this->key;
|
||||
$keyLength = strlen($key);
|
||||
@ -279,12 +279,12 @@ class RC4 extends StreamCipher
|
||||
$keyStream[$j] = $temp;
|
||||
}
|
||||
|
||||
$this->stream = array();
|
||||
$this->stream[self::DECRYPT] = $this->stream[self::ENCRYPT] = array(
|
||||
$this->stream = [];
|
||||
$this->stream[self::DECRYPT] = $this->stream[self::ENCRYPT] = [
|
||||
0, // index $i
|
||||
0, // index $j
|
||||
$keyStream
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -297,10 +297,10 @@ class RC4 extends StreamCipher
|
||||
* @param int $mode
|
||||
* @return string $text
|
||||
*/
|
||||
function _crypt($text, $mode)
|
||||
private function crypt($text, $mode)
|
||||
{
|
||||
if ($this->changed) {
|
||||
$this->_setup();
|
||||
$this->setup();
|
||||
$this->changed = false;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -30,7 +30,7 @@ use phpseclib\Common\Functions\Strings;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class MSBLOB
|
||||
abstract class MSBLOB
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
@ -73,7 +73,7 @@ class MSBLOB
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
static function load($key, $password = '')
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
if (!is_string($key)) {
|
||||
return false;
|
||||
@ -100,7 +100,7 @@ class MSBLOB
|
||||
return false;
|
||||
}
|
||||
|
||||
$components = array('isPublicKey' => $publickey);
|
||||
$components = ['isPublicKey' => $publickey];
|
||||
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa375549(v=vs.85).aspx
|
||||
switch ($algo) {
|
||||
@ -140,15 +140,15 @@ class MSBLOB
|
||||
$components['isPublicKey'] = false;
|
||||
|
||||
// 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]
|
||||
$components['primes'][] = new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256);
|
||||
// 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]
|
||||
$components['exponents'][] = new BigInteger(strrev(Strings::shift($key, $bitlen / 16)), 256);
|
||||
// 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'])) {
|
||||
$components['publicExponent'] = $components['privateExponent'];
|
||||
}
|
||||
@ -171,7 +171,7 @@ class MSBLOB
|
||||
* @param string $password optional
|
||||
* @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());
|
||||
$e = str_pad(strrev($e->toBytes()), 4, "\0");
|
||||
@ -196,7 +196,7 @@ class MSBLOB
|
||||
* @param \phpseclib\Math\BigInteger $e
|
||||
* @return string
|
||||
*/
|
||||
static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
public static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
{
|
||||
$n = strrev($n->toBytes());
|
||||
$e = str_pad(strrev($e->toBytes()), 4, "\0");
|
||||
|
@ -28,7 +28,7 @@ use phpseclib\Common\Functions\Strings;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class OpenSSH
|
||||
abstract class OpenSSH
|
||||
{
|
||||
/**
|
||||
* Default comment
|
||||
@ -36,7 +36,7 @@ class OpenSSH
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
static $comment = 'phpseclib-generated-key';
|
||||
private static $comment = 'phpseclib-generated-key';
|
||||
|
||||
/**
|
||||
* Sets the default comment
|
||||
@ -44,9 +44,9 @@ class OpenSSH
|
||||
* @access public
|
||||
* @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
|
||||
* @return array
|
||||
*/
|
||||
static function load($key, $password = '')
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
if (!is_string($key)) {
|
||||
return false;
|
||||
@ -93,12 +93,12 @@ class OpenSSH
|
||||
}
|
||||
$modulus = new BigInteger(Strings::shift($key, $length), -256);
|
||||
|
||||
return array(
|
||||
return [
|
||||
'isPublicKey' => true,
|
||||
'modulus' => $modulus,
|
||||
'publicExponent' => $publicExponent,
|
||||
'comment' => $comment
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,7 +109,7 @@ class OpenSSH
|
||||
* @param \phpseclib\Math\BigInteger $e
|
||||
* @return string
|
||||
*/
|
||||
static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
public static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
{
|
||||
$publicExponent = $e->toBytes(true);
|
||||
$modulus = $n->toBytes(true);
|
||||
|
@ -36,7 +36,7 @@ use phpseclib\File\ASN1\Maps;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PKCS1 extends Progenitor
|
||||
abstract class PKCS1 extends Progenitor
|
||||
{
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
@ -46,7 +46,7 @@ class PKCS1 extends Progenitor
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
static function load($key, $password = '')
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
if (!is_string($key)) {
|
||||
return false;
|
||||
@ -102,7 +102,7 @@ class PKCS1 extends Progenitor
|
||||
* @param string $password optional
|
||||
* @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);
|
||||
$key = [
|
||||
@ -137,7 +137,7 @@ class PKCS1 extends Progenitor
|
||||
* @param \phpseclib\Math\BigInteger $e
|
||||
* @return string
|
||||
*/
|
||||
static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
public static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
{
|
||||
$key = [
|
||||
'modulus' => $n,
|
||||
|
@ -38,7 +38,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PKCS8 extends Progenitor
|
||||
abstract class PKCS8 extends Progenitor
|
||||
{
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
@ -48,7 +48,7 @@ class PKCS8 extends Progenitor
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
static function load($key, $password = '')
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
$components = ['isPublicKey' => strpos($key, 'PUBLIC') !== false];
|
||||
|
||||
@ -85,7 +85,7 @@ class PKCS8 extends Progenitor
|
||||
* @param string $password optional
|
||||
* @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 = ASN1::extractBER($key);
|
||||
@ -100,7 +100,7 @@ class PKCS8 extends Progenitor
|
||||
* @param \phpseclib\Math\BigInteger $e
|
||||
* @return string
|
||||
*/
|
||||
static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
public static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
{
|
||||
$key = PKCS1::savePublicKey($n, $e);
|
||||
$key = ASN1::extractBER($key);
|
||||
|
@ -29,7 +29,7 @@ use phpseclib\Common\Functions\Strings;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PuTTY
|
||||
abstract class PuTTY
|
||||
{
|
||||
/**
|
||||
* Default comment
|
||||
@ -37,7 +37,7 @@ class PuTTY
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
static $comment = 'phpseclib-generated-key';
|
||||
private static $comment = 'phpseclib-generated-key';
|
||||
|
||||
/**
|
||||
* Sets the default comment
|
||||
@ -45,9 +45,9 @@ class PuTTY
|
||||
* @access public
|
||||
* @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
|
||||
* @return string
|
||||
*/
|
||||
static function generateSymmetricKey($password, $length)
|
||||
public static function generateSymmetricKey($password, $length)
|
||||
{
|
||||
$symkey = '';
|
||||
$sequence = 0;
|
||||
@ -78,7 +78,7 @@ class PuTTY
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
static function load($key, $password = '')
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
if (!is_string($key)) {
|
||||
return false;
|
||||
@ -102,12 +102,12 @@ class PuTTY
|
||||
if (!preg_match('#Comment: "(.+)"#', $key, $matches)) {
|
||||
return false;
|
||||
}
|
||||
$components['comment'] = str_replace(array('\\\\', '\"'), array('\\', '"'), $matches[1]);
|
||||
$components['comment'] = str_replace(['\\\\', '\"'], ['\\', '"'], $matches[1]);
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
$components = array('isPublicKey' => false);
|
||||
$components = ['isPublicKey' => false];
|
||||
$key = preg_split('#\r\n|\r|\n#', $key);
|
||||
$type = trim(preg_replace('#PuTTY-User-Key-File-2: (.+)#', '$1', $key[0]));
|
||||
if ($type != 'ssh-rsa') {
|
||||
@ -149,7 +149,7 @@ class PuTTY
|
||||
if (strlen($private) < $length) {
|
||||
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)));
|
||||
if (strlen($private) < $length) {
|
||||
return false;
|
||||
@ -157,7 +157,7 @@ class PuTTY
|
||||
$components['primes'][] = new BigInteger(Strings::shift($private, $length), -256);
|
||||
|
||||
$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);
|
||||
$components['exponents'][] = $components['publicExponent']->modInverse($temp);
|
||||
|
||||
@ -165,7 +165,7 @@ class PuTTY
|
||||
if (strlen($private) < $length) {
|
||||
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;
|
||||
}
|
||||
@ -183,13 +183,13 @@ class PuTTY
|
||||
* @param string $password optional
|
||||
* @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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$raw = array(
|
||||
$raw = [
|
||||
'modulus' => $n->toBytes(true),
|
||||
'publicExponent' => $e->toBytes(true),
|
||||
'privateExponent' => $d->toBytes(true),
|
||||
@ -198,7 +198,7 @@ class PuTTY
|
||||
'exponent1' => $exponents[1]->toBytes(true),
|
||||
'exponent2' => $exponents[2]->toBytes(true),
|
||||
'coefficient' => $coefficients[2]->toBytes(true)
|
||||
);
|
||||
];
|
||||
|
||||
$key = "PuTTY-User-Key-File-2: ssh-rsa\r\nEncryption: ";
|
||||
$encryption = (!empty($password) || is_string($password)) ? 'aes256-cbc' : 'none';
|
||||
@ -271,7 +271,7 @@ class PuTTY
|
||||
* @param \phpseclib\Math\BigInteger $e
|
||||
* @return string
|
||||
*/
|
||||
static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
public static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
{
|
||||
$n = $n->toBytes(true);
|
||||
$e = $e->toBytes(true);
|
||||
@ -286,7 +286,7 @@ class PuTTY
|
||||
$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) .
|
||||
'---- END SSH2 PUBLIC KEY ----';
|
||||
|
||||
|
@ -34,7 +34,7 @@ use phpseclib\Math\BigInteger;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class Raw
|
||||
abstract class Raw
|
||||
{
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
@ -44,7 +44,7 @@ class Raw
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
static function load($key, $password = '')
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
if (!is_array($key)) {
|
||||
return false;
|
||||
@ -59,7 +59,7 @@ class Raw
|
||||
}
|
||||
}
|
||||
}
|
||||
$components = array('isPublicKey' => true);
|
||||
$components = ['isPublicKey' => true];
|
||||
switch (true) {
|
||||
case isset($key['e']):
|
||||
$components['publicExponent'] = $key['e'];
|
||||
@ -97,8 +97,8 @@ class Raw
|
||||
* @param \phpseclib\Math\BigInteger $e
|
||||
* @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];
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ use phpseclib\Math\BigInteger;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class XML
|
||||
abstract class XML
|
||||
{
|
||||
/**
|
||||
* Break a public or private key down into its constituent components
|
||||
@ -40,18 +40,18 @@ class XML
|
||||
* @param string $password optional
|
||||
* @return array
|
||||
*/
|
||||
static function load($key, $password = '')
|
||||
public static function load($key, $password = '')
|
||||
{
|
||||
if (!is_string($key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$components = array(
|
||||
$components = [
|
||||
'isPublicKey' => false,
|
||||
'primes' => array(),
|
||||
'exponents' => array(),
|
||||
'coefficients' => array()
|
||||
);
|
||||
'primes' => [],
|
||||
'exponents' => [],
|
||||
'coefficients' => []
|
||||
];
|
||||
|
||||
$use_errors = libxml_use_internal_errors(true);
|
||||
|
||||
@ -60,7 +60,7 @@ class XML
|
||||
return false;
|
||||
}
|
||||
$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) {
|
||||
// $dom->getElementsByTagName($key) is case-sensitive
|
||||
$temp = $xpath->query("//*[translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='$key']");
|
||||
@ -113,7 +113,7 @@ class XML
|
||||
* @param string $password optional
|
||||
* @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) {
|
||||
return false;
|
||||
@ -138,7 +138,7 @@ class XML
|
||||
* @param \phpseclib\Math\BigInteger $e
|
||||
* @return string
|
||||
*/
|
||||
static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
public static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
{
|
||||
return "<RSAKeyValue>\r\n" .
|
||||
' <Modulus>' . Base64::encode($n->toBytes()) . "</Modulus>\r\n" .
|
||||
|
@ -33,7 +33,7 @@ use phpseclib\Crypt\Common\BlockCipher;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class Random
|
||||
abstract class Random
|
||||
{
|
||||
/**
|
||||
* Generate a random string.
|
||||
@ -46,7 +46,7 @@ class Random
|
||||
* @throws \RuntimeException if a symmetric cipher is needed but not loaded
|
||||
* @return string
|
||||
*/
|
||||
static function string($length)
|
||||
public static function string($length)
|
||||
{
|
||||
try {
|
||||
return \random_bytes($length);
|
||||
@ -196,7 +196,7 @@ class Random
|
||||
* @param mixed $arr
|
||||
* @access public
|
||||
*/
|
||||
static function safe_serialize(&$arr)
|
||||
private static function safe_serialize(&$arr)
|
||||
{
|
||||
if (is_object($arr)) {
|
||||
return '';
|
||||
@ -208,7 +208,7 @@ class Random
|
||||
if (isset($arr['__phpseclib_marker'])) {
|
||||
return '';
|
||||
}
|
||||
$safearr = array();
|
||||
$safearr = [];
|
||||
$arr['__phpseclib_marker'] = true;
|
||||
foreach (array_keys($arr) as $key) {
|
||||
// do not recurse on the '__phpseclib_marker' key itself, for smaller memory usage
|
||||
|
@ -79,35 +79,25 @@ class Rijndael extends BlockCipher
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $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';
|
||||
protected $cipher_name_mcrypt = 'rijndael-128';
|
||||
|
||||
/**
|
||||
* The Key Schedule
|
||||
*
|
||||
* @see self::_setup()
|
||||
* @see self::setup()
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $w;
|
||||
private $w;
|
||||
|
||||
/**
|
||||
* The Inverse Key Schedule
|
||||
*
|
||||
* @see self::_setup()
|
||||
* @see self::setup()
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $dw;
|
||||
private $dw;
|
||||
|
||||
/**
|
||||
* The Block Length divided by 32
|
||||
@ -120,7 +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
|
||||
* of that, we'll just precompute it once.
|
||||
*/
|
||||
var $Nb = 4;
|
||||
private $Nb = 4;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* of that, we'll just precompute it once.
|
||||
*/
|
||||
var $key_length = 16;
|
||||
protected $key_length = 16;
|
||||
|
||||
/**
|
||||
* The Key Length divided by 32
|
||||
@ -143,7 +133,7 @@ class Rijndael extends BlockCipher
|
||||
* @access private
|
||||
* @internal The max value is 256 / 32 = 8, the min value is 128 / 32 = 4
|
||||
*/
|
||||
var $Nk = 4;
|
||||
private $Nk = 4;
|
||||
|
||||
/**
|
||||
* The Number of Rounds
|
||||
@ -152,7 +142,7 @@ class Rijndael extends BlockCipher
|
||||
* @access private
|
||||
* @internal The max value is 14, the min value is 10.
|
||||
*/
|
||||
var $Nr;
|
||||
private $Nr;
|
||||
|
||||
/**
|
||||
* Shift offsets
|
||||
@ -160,7 +150,7 @@ class Rijndael extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $c;
|
||||
private $c;
|
||||
|
||||
/**
|
||||
* Holds the last used key- and block_size information
|
||||
@ -168,7 +158,7 @@ class Rijndael extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $kl;
|
||||
private $kl;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -177,7 +167,7 @@ class Rijndael extends BlockCipher
|
||||
* @access public
|
||||
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided
|
||||
*/
|
||||
function __construct($mode)
|
||||
public function __construct($mode)
|
||||
{
|
||||
if ($mode == self::MODE_STREAM) {
|
||||
throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode');
|
||||
@ -206,7 +196,7 @@ class Rijndael extends BlockCipher
|
||||
* @throws \LengthException if the key length is invalid
|
||||
* @param int $length
|
||||
*/
|
||||
function setKeyLength($length)
|
||||
public function setKeyLength($length)
|
||||
{
|
||||
switch ($length) {
|
||||
case 128:
|
||||
@ -233,7 +223,7 @@ class Rijndael extends BlockCipher
|
||||
* @param string $key
|
||||
* @throws \LengthException if the key length isn't supported
|
||||
*/
|
||||
function setKey($key)
|
||||
public function setKey($key)
|
||||
{
|
||||
switch (strlen($key)) {
|
||||
case 16:
|
||||
@ -257,7 +247,7 @@ class Rijndael extends BlockCipher
|
||||
* @access public
|
||||
* @param int $length
|
||||
*/
|
||||
function setBlockLength($length)
|
||||
public function setBlockLength($length)
|
||||
{
|
||||
switch ($length) {
|
||||
case 128:
|
||||
@ -273,7 +263,7 @@ class Rijndael extends BlockCipher
|
||||
$this->Nb = $length >> 5;
|
||||
$this->block_size = $length >> 3;
|
||||
$this->changed = true;
|
||||
$this->_setEngine();
|
||||
$this->setEngine();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -286,7 +276,7 @@ class Rijndael extends BlockCipher
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isValidEngine($engine)
|
||||
public function isValidEngine($engine)
|
||||
{
|
||||
switch ($engine) {
|
||||
case self::ENGINE_OPENSSL:
|
||||
@ -294,7 +284,7 @@ class Rijndael extends BlockCipher
|
||||
return false;
|
||||
}
|
||||
$this->cipher_name_openssl_ecb = 'aes-' . ($this->key_length << 3) . '-ecb';
|
||||
$this->cipher_name_openssl = 'aes-' . ($this->key_length << 3) . '-' . $this->_openssl_translate_mode();
|
||||
$this->cipher_name_openssl = 'aes-' . ($this->key_length << 3) . '-' . $this->openssl_translate_mode();
|
||||
break;
|
||||
case self::ENGINE_MCRYPT:
|
||||
$this->cipher_name_mcrypt = 'rijndael-' . ($this->block_size << 3);
|
||||
@ -314,11 +304,11 @@ class Rijndael extends BlockCipher
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
function _encryptBlock($in)
|
||||
protected function encryptBlock($in)
|
||||
{
|
||||
static $tables;
|
||||
if (empty($tables)) {
|
||||
$tables = &$this->_getTables();
|
||||
$tables = &$this->getTables();
|
||||
}
|
||||
$t0 = $tables[0];
|
||||
$t1 = $tables[1];
|
||||
@ -326,7 +316,7 @@ class Rijndael extends BlockCipher
|
||||
$t3 = $tables[3];
|
||||
$sbox = $tables[4];
|
||||
|
||||
$state = array();
|
||||
$state = [];
|
||||
$words = unpack('N*', $in);
|
||||
|
||||
$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.
|
||||
|
||||
// [1] http://fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.v316.pdf
|
||||
$temp = array();
|
||||
$temp = [];
|
||||
for ($round = 1; $round < $Nr; ++$round) {
|
||||
$i = 0; // $c[0] == 0
|
||||
$j = $c[1];
|
||||
@ -415,11 +405,11 @@ class Rijndael extends BlockCipher
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
function _decryptBlock($in)
|
||||
protected function decryptBlock($in)
|
||||
{
|
||||
static $invtables;
|
||||
if (empty($invtables)) {
|
||||
$invtables = &$this->_getInvTables();
|
||||
$invtables = &$this->getInvTables();
|
||||
}
|
||||
$dt0 = $invtables[0];
|
||||
$dt1 = $invtables[1];
|
||||
@ -427,7 +417,7 @@ class Rijndael extends BlockCipher
|
||||
$dt3 = $invtables[3];
|
||||
$isbox = $invtables[4];
|
||||
|
||||
$state = array();
|
||||
$state = [];
|
||||
$words = unpack('N*', $in);
|
||||
|
||||
$c = $this->c;
|
||||
@ -441,7 +431,7 @@ class Rijndael extends BlockCipher
|
||||
$state[] = $word ^ $dw[++$wc];
|
||||
}
|
||||
|
||||
$temp = array();
|
||||
$temp = [];
|
||||
for ($round = $Nr - 1; $round > 0; --$round) {
|
||||
$i = 0; // $c[0] == 0
|
||||
$j = $Nb - $c[1];
|
||||
@ -501,27 +491,27 @@ class Rijndael extends BlockCipher
|
||||
/**
|
||||
* Setup the key (expansion)
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::setupKey()
|
||||
* @access private
|
||||
*/
|
||||
function _setupKey()
|
||||
protected function setupKey()
|
||||
{
|
||||
// Each number in $rcon is equal to the previous number multiplied by two in Rijndael's finite field.
|
||||
// See http://en.wikipedia.org/wiki/Finite_field_arithmetic#Multiplicative_inverse
|
||||
static $rcon = array(0,
|
||||
static $rcon = [0,
|
||||
0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000,
|
||||
0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000,
|
||||
0x6C000000, 0xD8000000, 0xAB000000, 0x4D000000, 0x9A000000,
|
||||
0x2F000000, 0x5E000000, 0xBC000000, 0x63000000, 0xC6000000,
|
||||
0x97000000, 0x35000000, 0x6A000000, 0xD4000000, 0xB3000000,
|
||||
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']) {
|
||||
// already expanded
|
||||
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;
|
||||
// see Rijndael-ammended.pdf#page=44
|
||||
@ -535,13 +525,13 @@ class Rijndael extends BlockCipher
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
$this->c = array(0, 1, 2, 3);
|
||||
$this->c = [0, 1, 2, 3];
|
||||
break;
|
||||
case 7:
|
||||
$this->c = array(0, 1, 2, 4);
|
||||
$this->c = [0, 1, 2, 4];
|
||||
break;
|
||||
case 8:
|
||||
$this->c = array(0, 1, 3, 4);
|
||||
$this->c = [0, 1, 3, 4];
|
||||
}
|
||||
|
||||
$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'
|
||||
// with 0xFFFFFFFF (or 0xFFFFFF00) on a 32-bit machine is unnecessary, but on a 64-bit machine, it is.
|
||||
$temp = (($temp << 8) & 0xFFFFFF00) | (($temp >> 24) & 0x000000FF); // rotWord
|
||||
$temp = $this->_subWord($temp) ^ $rcon[$i / $this->Nk];
|
||||
$temp = $this->subWord($temp) ^ $rcon[$i / $this->Nk];
|
||||
} elseif ($this->Nk > 6 && $i % $this->Nk == 4) {
|
||||
$temp = $this->_subWord($temp);
|
||||
$temp = $this->subWord($temp);
|
||||
}
|
||||
$w[$i] = $w[$i - $this->Nk] ^ $temp;
|
||||
}
|
||||
@ -569,8 +559,8 @@ class Rijndael extends BlockCipher
|
||||
// 1. Apply the Key Expansion.
|
||||
// 2. Apply InvMixColumn to all Round Keys except the first and the last one."
|
||||
// also, see fips-197.pdf#page=27, "5.3.5 Equivalent Inverse Cipher"
|
||||
list($dt0, $dt1, $dt2, $dt3) = $this->_getInvTables();
|
||||
$temp = $this->w = $this->dw = array();
|
||||
list($dt0, $dt1, $dt2, $dt3) = $this->getInvTables();
|
||||
$temp = $this->w = $this->dw = [];
|
||||
for ($i = $row = $col = 0; $i < $length; $i++, $col++) {
|
||||
if ($col == $this->Nb) {
|
||||
if ($row == 0) {
|
||||
@ -579,7 +569,7 @@ class Rijndael extends BlockCipher
|
||||
// subWord + invMixColumn + invSubWord = invMixColumn
|
||||
$j = 0;
|
||||
while ($j < $this->Nb) {
|
||||
$dw = $this->_subWord($this->w[$row][$j]);
|
||||
$dw = $this->subWord($this->w[$row][$j]);
|
||||
$temp[$j] = $dt0[$dw >> 24 & 0x000000FF] ^
|
||||
$dt1[$dw >> 16 & 0x000000FF] ^
|
||||
$dt2[$dw >> 8 & 0x000000FF] ^
|
||||
@ -617,11 +607,11 @@ class Rijndael extends BlockCipher
|
||||
* @access private
|
||||
* @param int $word
|
||||
*/
|
||||
function _subWord($word)
|
||||
private function subWord($word)
|
||||
{
|
||||
static $sbox;
|
||||
if (empty($sbox)) {
|
||||
list(, , , , $sbox) = $this->_getTables();
|
||||
list(, , , , $sbox) = self::getTables();
|
||||
}
|
||||
|
||||
return $sbox[$word & 0x000000FF] |
|
||||
@ -633,20 +623,20 @@ class Rijndael extends BlockCipher
|
||||
/**
|
||||
* Provides the mixColumns and sboxes tables
|
||||
*
|
||||
* @see self::_encryptBlock()
|
||||
* @see self::_setupInlineCrypt()
|
||||
* @see self::_subWord()
|
||||
* @see self::encryptBlock()
|
||||
* @see self::setupInlineCrypt()
|
||||
* @see self::subWord()
|
||||
* @access private
|
||||
* @return array &$tables
|
||||
*/
|
||||
function &_getTables()
|
||||
private function &getTables()
|
||||
{
|
||||
static $tables;
|
||||
if (empty($tables)) {
|
||||
// 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
|
||||
// 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
|
||||
// some slower floats converted by php automatically on high values
|
||||
0x6363A5C6, 0x7C7C84F8, 0x777799EE, 0x7B7B8DF6, 0xF2F20DFF, 0x6B6BBDD6, 0x6F6FB1DE, 0xC5C55491,
|
||||
@ -681,7 +671,7 @@ class Rijndael extends BlockCipher
|
||||
0x9B9BB62D, 0x1E1E223C, 0x87879215, 0xE9E920C9, 0xCECE4987, 0x5555FFAA, 0x28287850, 0xDFDF7AA5,
|
||||
0x8C8C8F03, 0xA1A1F859, 0x89898009, 0x0D0D171A, 0xBFBFDA65, 0xE6E631D7, 0x4242C684, 0x6868B8D0,
|
||||
0x4141C382, 0x9999B029, 0x2D2D775A, 0x0F0F111E, 0xB0B0CB7B, 0x5454FCA8, 0xBBBBD66D, 0x16163A2C
|
||||
));
|
||||
]);
|
||||
|
||||
foreach ($t3 as $t3i) {
|
||||
$t0[] = (($t3i << 24) & 0xFF000000) | (($t3i >> 8) & 0x00FFFFFF);
|
||||
@ -689,14 +679,14 @@ class Rijndael extends BlockCipher
|
||||
$t2[] = (($t3i << 8) & 0xFFFFFF00) | (($t3i >> 24) & 0x000000FF);
|
||||
}
|
||||
|
||||
$tables = array(
|
||||
$tables = [
|
||||
// The Precomputed mixColumns tables t0 - t3
|
||||
$t0,
|
||||
$t1,
|
||||
$t2,
|
||||
$t3,
|
||||
// The SubByte S-Box
|
||||
array(
|
||||
[
|
||||
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,
|
||||
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,
|
||||
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
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
}
|
||||
return $tables;
|
||||
}
|
||||
@ -722,17 +712,17 @@ class Rijndael extends BlockCipher
|
||||
/**
|
||||
* Provides the inverse mixColumns and inverse sboxes tables
|
||||
*
|
||||
* @see self::_decryptBlock()
|
||||
* @see self::_setupInlineCrypt()
|
||||
* @see self::_setupKey()
|
||||
* @see self::decryptBlock()
|
||||
* @see self::setupInlineCrypt()
|
||||
* @see self::setupKey()
|
||||
* @access private
|
||||
* @return array &$tables
|
||||
*/
|
||||
function &_getInvTables()
|
||||
private function &getInvTables()
|
||||
{
|
||||
static $tables;
|
||||
if (empty($tables)) {
|
||||
$dt3 = array_map('intval', array(
|
||||
$dt3 = array_map('intval', [
|
||||
0xF4A75051, 0x4165537E, 0x17A4C31A, 0x275E963A, 0xAB6BCB3B, 0x9D45F11F, 0xFA58ABAC, 0xE303934B,
|
||||
0x30FA5520, 0x766DF6AD, 0xCC769188, 0x024C25F5, 0xE5D7FC4F, 0x2ACBD7C5, 0x35448026, 0x62A38FB5,
|
||||
0xB15A49DE, 0xBA1B6725, 0xEA0E9845, 0xFEC0E15D, 0x2F7502C3, 0x4CF01281, 0x4697A38D, 0xD3F9C66B,
|
||||
@ -765,7 +755,7 @@ class Rijndael extends BlockCipher
|
||||
0xD2DF599C, 0xF2733F55, 0x14CE7918, 0xC737BF73, 0xF7CDEA53, 0xFDAA5B5F, 0x3D6F14DF, 0x44DB8678,
|
||||
0xAFF381CA, 0x68C43EB9, 0x24342C38, 0xA3405FC2, 0x1DC37216, 0xE2250CBC, 0x3C498B28, 0x0D9541FF,
|
||||
0xA8017139, 0x0CB3DE08, 0xB4E49CD8, 0x56C19064, 0xCB84617B, 0x32B670D5, 0x6C5C7448, 0xB85742D0
|
||||
));
|
||||
]);
|
||||
|
||||
foreach ($dt3 as $dt3i) {
|
||||
$dt0[] = (($dt3i << 24) & 0xFF000000) | (($dt3i >> 8) & 0x00FFFFFF);
|
||||
@ -773,14 +763,14 @@ class Rijndael extends BlockCipher
|
||||
$dt2[] = (($dt3i << 8) & 0xFFFFFF00) | (($dt3i >> 24) & 0x000000FF);
|
||||
};
|
||||
|
||||
$tables = array(
|
||||
$tables = [
|
||||
// The Precomputed inverse mixColumns tables dt0 - dt3
|
||||
$dt0,
|
||||
$dt1,
|
||||
$dt2,
|
||||
$dt3,
|
||||
// The inverse SubByte S-Box
|
||||
array(
|
||||
[
|
||||
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,
|
||||
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,
|
||||
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
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
}
|
||||
return $tables;
|
||||
}
|
||||
@ -806,174 +796,142 @@ class Rijndael extends BlockCipher
|
||||
/**
|
||||
* Setup the performance-optimized function for de/encrypt()
|
||||
*
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::setupInlineCrypt()
|
||||
* @access private
|
||||
*/
|
||||
function _setupInlineCrypt()
|
||||
protected function setupInlineCrypt()
|
||||
{
|
||||
// Note: _setupInlineCrypt() will be called only if $this->changed === true
|
||||
// So here we are'nt under the same heavy timing-stress as we are in _de/encryptBlock() or de/encrypt().
|
||||
// However...the here generated function- $code, stored as php callback in $this->inline_crypt, must work as fast as even possible.
|
||||
$w = $this->w;
|
||||
$dw = $this->dw;
|
||||
$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.
|
||||
// (Currently, for Crypt_Rijndael/AES, one generated $lambda_function cost on php5.5@32bit ~80kb unfreeable mem and ~130kb on php5.5@64bit)
|
||||
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one.
|
||||
$gen_hi_opt_code = (bool)(count($lambda_functions) < 10);
|
||||
// Generating encrypt code:
|
||||
$init_encrypt.= '
|
||||
static $tables;
|
||||
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
|
||||
$code_hash = "Crypt_Rijndael, {$this->mode}, {$this->Nr}, {$this->Nb}";
|
||||
if ($gen_hi_opt_code) {
|
||||
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
|
||||
$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";
|
||||
}
|
||||
|
||||
if (!isset($lambda_functions[$code_hash])) {
|
||||
switch (true) {
|
||||
case $gen_hi_opt_code:
|
||||
// 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
|
||||
// Mainrounds: shiftRows + subWord + mixColumns + addRoundKey
|
||||
for ($round = 1; $round < $Nr; ++$round) {
|
||||
list($s, $e) = [$e, $s];
|
||||
for ($i = 0; $i < $Nb; ++$i) {
|
||||
$encrypt_block.=
|
||||
'$'.$e.$i.' =
|
||||
$sbox[ $'.$e.$i.' & 0xff] |
|
||||
($sbox[($'.$e.$i.' >> 8) & 0xff] << 8) |
|
||||
($sbox[($'.$e.$i.' >> 16) & 0xff] << 16) |
|
||||
($sbox[($'.$e.$i.' >> 24) & 0xff] << 24);'."\n";
|
||||
$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";
|
||||
}
|
||||
$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";
|
||||
}
|
||||
|
||||
// Finalround: subWord + shiftRows + addRoundKey
|
||||
for ($i = 0; $i < $Nb; ++$i) {
|
||||
$encrypt_block.=
|
||||
'$'.$e.$i.' =
|
||||
$sbox[ $'.$e.$i.' & 0xff] |
|
||||
($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:
|
||||
$init_decrypt.= '
|
||||
static $invtables;
|
||||
if (empty($invtables)) {
|
||||
$invtables = &$self->_getInvTables();
|
||||
}
|
||||
$dt0 = $invtables[0];
|
||||
$dt1 = $invtables[1];
|
||||
$dt2 = $invtables[2];
|
||||
$dt3 = $invtables[3];
|
||||
$isbox = $invtables[4];
|
||||
';
|
||||
$s = 'e';
|
||||
$e = 's';
|
||||
$wc = $Nb - 1;
|
||||
|
||||
$s = 'e';
|
||||
$e = 's';
|
||||
$wc = $Nb - 1;
|
||||
// Preround: addRoundKey
|
||||
$decrypt_block = '$in = unpack("N*", $in);'."\n";
|
||||
for ($i = 0; $i < $Nb; ++$i) {
|
||||
$decrypt_block .= '$s'.$i.' = $in['.($i + 1).'] ^ '.$dw[++$wc].';'."\n";
|
||||
}
|
||||
|
||||
// Preround: addRoundKey
|
||||
$decrypt_block = '$in = unpack("N*", $in);'."\n";
|
||||
for ($i = 0; $i < $Nb; ++$i) {
|
||||
$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
|
||||
// Mainrounds: shiftRows + subWord + mixColumns + addRoundKey
|
||||
for ($round = 1; $round < $Nr; ++$round) {
|
||||
list($s, $e) = [$e, $s];
|
||||
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";
|
||||
$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";
|
||||
}
|
||||
$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
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -66,17 +66,7 @@ class TripleDES extends DES
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $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';
|
||||
protected $key_length = 24;
|
||||
|
||||
/**
|
||||
* The mcrypt specific name of the cipher
|
||||
@ -86,7 +76,7 @@ class TripleDES extends DES
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $cipher_name_mcrypt = 'tripledes';
|
||||
protected $cipher_name_mcrypt = 'tripledes';
|
||||
|
||||
/**
|
||||
* Optimizing value while CFB-encrypting
|
||||
@ -95,7 +85,7 @@ class TripleDES extends DES
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $cfb_init_len = 750;
|
||||
protected $cfb_init_len = 750;
|
||||
|
||||
/**
|
||||
* max possible size of $key
|
||||
@ -105,7 +95,7 @@ class TripleDES extends DES
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $key_length_max = 24;
|
||||
protected $key_length_max = 24;
|
||||
|
||||
/**
|
||||
* Internal flag whether using self::MODE_3CBC or not
|
||||
@ -113,7 +103,7 @@ class TripleDES extends DES
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $mode_3cbc;
|
||||
private $mode_3cbc;
|
||||
|
||||
/**
|
||||
* The \phpseclib\Crypt\DES objects
|
||||
@ -123,7 +113,7 @@ class TripleDES extends DES
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $des;
|
||||
private $des;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -149,7 +139,7 @@ class TripleDES extends DES
|
||||
* @param int $mode
|
||||
* @access public
|
||||
*/
|
||||
function __construct($mode)
|
||||
public function __construct($mode)
|
||||
{
|
||||
switch ($mode) {
|
||||
// In case of self::MODE_3CBC, we init as CRYPT_DES_MODE_CBC
|
||||
@ -159,11 +149,11 @@ class TripleDES extends DES
|
||||
$this->mode_3cbc = true;
|
||||
|
||||
// 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),
|
||||
);
|
||||
];
|
||||
|
||||
// we're going to be doing the padding, ourselves, so disable it in the \phpseclib\Crypt\DES objects
|
||||
$this->des[0]->disablePadding();
|
||||
@ -186,11 +176,11 @@ class TripleDES extends DES
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isValidEngine($engine)
|
||||
public function isValidEngine($engine)
|
||||
{
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
$this->cipher_name_openssl_ecb = 'des-ede3';
|
||||
$mode = $this->_openssl_translate_mode();
|
||||
$mode = $this->openssl_translate_mode();
|
||||
$this->cipher_name_openssl = $mode == 'ecb' ? 'des-ede3' : 'des-ede3-' . $mode;
|
||||
}
|
||||
|
||||
@ -206,7 +196,7 @@ class TripleDES extends DES
|
||||
* @access public
|
||||
* @param string $iv
|
||||
*/
|
||||
function setIV($iv)
|
||||
public function setIV($iv)
|
||||
{
|
||||
parent::setIV($iv);
|
||||
if ($this->mode_3cbc) {
|
||||
@ -228,7 +218,7 @@ class TripleDES extends DES
|
||||
* @throws \LengthException if the key length is invalid
|
||||
* @param int $length
|
||||
*/
|
||||
function setKeyLength($length)
|
||||
public function setKeyLength($length)
|
||||
{
|
||||
switch ($length) {
|
||||
case 128:
|
||||
@ -254,7 +244,7 @@ class TripleDES extends DES
|
||||
* @throws \LengthException if the key length is invalid
|
||||
* @param string $key
|
||||
*/
|
||||
function setKey($key)
|
||||
public function setKey($key)
|
||||
{
|
||||
if ($this->explicit_key_length !== false && strlen($key) != $this->explicit_key_length) {
|
||||
throw new \LengthException('Key length has already been set to ' . $this->explicit_key_length . ' bytes and this key is ' . strlen($key) . ' bytes');
|
||||
@ -273,7 +263,7 @@ class TripleDES extends DES
|
||||
$this->key = $key;
|
||||
$this->key_length = strlen($key);
|
||||
$this->changed = true;
|
||||
$this->_setEngine();
|
||||
$this->setEngine();
|
||||
|
||||
if ($this->mode_3cbc) {
|
||||
$this->des[0]->setKey(substr($key, 0, 8));
|
||||
@ -290,7 +280,7 @@ class TripleDES extends DES
|
||||
* @param string $plaintext
|
||||
* @return string $cipertext
|
||||
*/
|
||||
function encrypt($plaintext)
|
||||
public function encrypt($plaintext)
|
||||
{
|
||||
// parent::en/decrypt() is able to do all the work for all modes and keylengths,
|
||||
// except for: self::MODE_3CBC (inner chaining CBC) with a key > 64bits
|
||||
@ -300,7 +290,7 @@ class TripleDES extends DES
|
||||
return $this->des[2]->encrypt(
|
||||
$this->des[1]->decrypt(
|
||||
$this->des[0]->encrypt(
|
||||
$this->_pad($plaintext)
|
||||
$this->pad($plaintext)
|
||||
)
|
||||
)
|
||||
);
|
||||
@ -317,10 +307,10 @@ class TripleDES extends DES
|
||||
* @param string $ciphertext
|
||||
* @return string $plaintext
|
||||
*/
|
||||
function decrypt($ciphertext)
|
||||
public function decrypt($ciphertext)
|
||||
{
|
||||
if ($this->mode_3cbc && strlen($this->key) > 8) {
|
||||
return $this->_unpad(
|
||||
return $this->unpad(
|
||||
$this->des[0]->decrypt(
|
||||
$this->des[1]->encrypt(
|
||||
$this->des[2]->decrypt(
|
||||
@ -372,7 +362,7 @@ class TripleDES extends DES
|
||||
* @see self::disableContinuousBuffer()
|
||||
* @access public
|
||||
*/
|
||||
function enableContinuousBuffer()
|
||||
public function enableContinuousBuffer()
|
||||
{
|
||||
parent::enableContinuousBuffer();
|
||||
if ($this->mode_3cbc) {
|
||||
@ -391,7 +381,7 @@ class TripleDES extends DES
|
||||
* @see self::enableContinuousBuffer()
|
||||
* @access public
|
||||
*/
|
||||
function disableContinuousBuffer()
|
||||
public function disableContinuousBuffer()
|
||||
{
|
||||
parent::disableContinuousBuffer();
|
||||
if ($this->mode_3cbc) {
|
||||
@ -404,11 +394,11 @@ class TripleDES extends DES
|
||||
/**
|
||||
* Creates the key schedule
|
||||
*
|
||||
* @see \phpseclib\Crypt\DES::_setupKey()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey()
|
||||
* @see \phpseclib\Crypt\DES::setupKey()
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::setupKey()
|
||||
* @access private
|
||||
*/
|
||||
function _setupKey()
|
||||
protected function setupKey()
|
||||
{
|
||||
switch (true) {
|
||||
// if $key <= 64bits we configure our internal pure-php cipher engine
|
||||
@ -423,17 +413,17 @@ class TripleDES extends DES
|
||||
|
||||
// (only) if 3CBC is used we have, of course, to setup the $des[0-2] keys also separately.
|
||||
if ($this->mode_3cbc) {
|
||||
$this->des[0]->_setupKey();
|
||||
$this->des[1]->_setupKey();
|
||||
$this->des[2]->_setupKey();
|
||||
$this->des[0]->setupKey();
|
||||
$this->des[1]->setupKey();
|
||||
$this->des[2]->setupKey();
|
||||
|
||||
// because $des[0-2] will, now, do all the work we can return here
|
||||
// not need unnecessary stress parent::_setupKey() with our, now unused, $key.
|
||||
// not need unnecessary stress parent::setupKey() with our, now unused, $key.
|
||||
return;
|
||||
}
|
||||
}
|
||||
// setup our key
|
||||
parent::_setupKey();
|
||||
parent::setupKey();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -445,7 +435,7 @@ class TripleDES extends DES
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function setPreferredEngine($engine)
|
||||
public function setPreferredEngine($engine)
|
||||
{
|
||||
if ($this->mode_3cbc) {
|
||||
$this->des[0]->setPreferredEngine($engine);
|
||||
@ -455,4 +445,15 @@ class TripleDES extends DES
|
||||
|
||||
return parent::setPreferredEngine($engine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class that defines the private methods
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
protected function getClassContext()
|
||||
{
|
||||
return 'phpseclib\Crypt\DES';
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class Twofish extends BlockCipher
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $cipher_name_mcrypt = 'twofish';
|
||||
protected $cipher_name_mcrypt = 'twofish';
|
||||
|
||||
/**
|
||||
* Optimizing value while CFB-encrypting
|
||||
@ -65,7 +65,7 @@ class Twofish extends BlockCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $cfb_init_len = 800;
|
||||
protected $cfb_init_len = 800;
|
||||
|
||||
/**
|
||||
* Q-Table
|
||||
@ -73,7 +73,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $q0 = array(
|
||||
private $q0 = [
|
||||
0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76,
|
||||
0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38,
|
||||
0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C,
|
||||
@ -106,7 +106,7 @@ class Twofish extends BlockCipher
|
||||
0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4,
|
||||
0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00,
|
||||
0x6F, 0x9D, 0x36, 0x42, 0x4A, 0x5E, 0xC1, 0xE0
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Q-Table
|
||||
@ -114,7 +114,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $q1 = array(
|
||||
private $q1 = [
|
||||
0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8,
|
||||
0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B,
|
||||
0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1,
|
||||
@ -147,7 +147,7 @@ class Twofish extends BlockCipher
|
||||
0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9,
|
||||
0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2,
|
||||
0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xBE, 0x91
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* M-Table
|
||||
@ -155,7 +155,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $m0 = array(
|
||||
private $m0 = [
|
||||
0xBCBC3275, 0xECEC21F3, 0x202043C6, 0xB3B3C9F4, 0xDADA03DB, 0x02028B7B, 0xE2E22BFB, 0x9E9EFAC8,
|
||||
0xC9C9EC4A, 0xD4D409D3, 0x18186BE6, 0x1E1E9F6B, 0x98980E45, 0xB2B2387D, 0xA6A6D2E8, 0x2626B74B,
|
||||
0x3C3C57D6, 0x93938A32, 0x8282EED8, 0x525298FD, 0x7B7BD437, 0xBBBB3771, 0x5B5B97F1, 0x474783E1,
|
||||
@ -188,7 +188,7 @@ class Twofish extends BlockCipher
|
||||
0xABABA212, 0x6F6F3EA2, 0xE6E6540D, 0xDBDBF252, 0x92927BBB, 0xB7B7B602, 0x6969CA2F, 0x3939D9A9,
|
||||
0xD3D30CD7, 0xA7A72361, 0xA2A2AD1E, 0xC3C399B4, 0x6C6C4450, 0x07070504, 0x04047FF6, 0x272746C2,
|
||||
0xACACA716, 0xD0D07625, 0x50501386, 0xDCDCF756, 0x84841A55, 0xE1E15109, 0x7A7A25BE, 0x1313EF91
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* M-Table
|
||||
@ -196,7 +196,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $m1 = array(
|
||||
private $m1 = [
|
||||
0xA9D93939, 0x67901717, 0xB3719C9C, 0xE8D2A6A6, 0x04050707, 0xFD985252, 0xA3658080, 0x76DFE4E4,
|
||||
0x9A084545, 0x92024B4B, 0x80A0E0E0, 0x78665A5A, 0xE4DDAFAF, 0xDDB06A6A, 0xD1BF6363, 0x38362A2A,
|
||||
0x0D54E6E6, 0xC6432020, 0x3562CCCC, 0x98BEF2F2, 0x181E1212, 0xF724EBEB, 0xECD7A1A1, 0x6C774141,
|
||||
@ -229,7 +229,7 @@ class Twofish extends BlockCipher
|
||||
0xC8FA9E9E, 0xA882D6D6, 0x2BCF6E6E, 0x40507070, 0xDCEB8585, 0xFE750A0A, 0x328A9393, 0xA48DDFDF,
|
||||
0xCA4C2929, 0x10141C1C, 0x2173D7D7, 0xF0CCB4B4, 0xD309D4D4, 0x5D108A8A, 0x0FE25151, 0x00000000,
|
||||
0x6F9A1919, 0x9DE01A1A, 0x368F9494, 0x42E6C7C7, 0x4AECC9C9, 0x5EFDD2D2, 0xC1AB7F7F, 0xE0D8A8A8
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* M-Table
|
||||
@ -237,7 +237,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $m2 = array(
|
||||
private $m2 = [
|
||||
0xBC75BC32, 0xECF3EC21, 0x20C62043, 0xB3F4B3C9, 0xDADBDA03, 0x027B028B, 0xE2FBE22B, 0x9EC89EFA,
|
||||
0xC94AC9EC, 0xD4D3D409, 0x18E6186B, 0x1E6B1E9F, 0x9845980E, 0xB27DB238, 0xA6E8A6D2, 0x264B26B7,
|
||||
0x3CD63C57, 0x9332938A, 0x82D882EE, 0x52FD5298, 0x7B377BD4, 0xBB71BB37, 0x5BF15B97, 0x47E14783,
|
||||
@ -270,7 +270,7 @@ class Twofish extends BlockCipher
|
||||
0xAB12ABA2, 0x6FA26F3E, 0xE60DE654, 0xDB52DBF2, 0x92BB927B, 0xB702B7B6, 0x692F69CA, 0x39A939D9,
|
||||
0xD3D7D30C, 0xA761A723, 0xA21EA2AD, 0xC3B4C399, 0x6C506C44, 0x07040705, 0x04F6047F, 0x27C22746,
|
||||
0xAC16ACA7, 0xD025D076, 0x50865013, 0xDC56DCF7, 0x8455841A, 0xE109E151, 0x7ABE7A25, 0x139113EF
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* M-Table
|
||||
@ -278,7 +278,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $m3 = array(
|
||||
private $m3 = [
|
||||
0xD939A9D9, 0x90176790, 0x719CB371, 0xD2A6E8D2, 0x05070405, 0x9852FD98, 0x6580A365, 0xDFE476DF,
|
||||
0x08459A08, 0x024B9202, 0xA0E080A0, 0x665A7866, 0xDDAFE4DD, 0xB06ADDB0, 0xBF63D1BF, 0x362A3836,
|
||||
0x54E60D54, 0x4320C643, 0x62CC3562, 0xBEF298BE, 0x1E12181E, 0x24EBF724, 0xD7A1ECD7, 0x77416C77,
|
||||
@ -311,7 +311,7 @@ class Twofish extends BlockCipher
|
||||
0xFA9EC8FA, 0x82D6A882, 0xCF6E2BCF, 0x50704050, 0xEB85DCEB, 0x750AFE75, 0x8A93328A, 0x8DDFA48D,
|
||||
0x4C29CA4C, 0x141C1014, 0x73D72173, 0xCCB4F0CC, 0x09D4D309, 0x108A5D10, 0xE2510FE2, 0x00000000,
|
||||
0x9A196F9A, 0xE01A9DE0, 0x8F94368F, 0xE6C742E6, 0xECC94AEC, 0xFDD25EFD, 0xAB7FC1AB, 0xD8A8E0D8
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* The Key Schedule Array
|
||||
@ -319,7 +319,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $K = array();
|
||||
private $K = [];
|
||||
|
||||
/**
|
||||
* The Key depended S-Table 0
|
||||
@ -327,7 +327,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $S0 = array();
|
||||
private $S0 = [];
|
||||
|
||||
/**
|
||||
* The Key depended S-Table 1
|
||||
@ -335,7 +335,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $S1 = array();
|
||||
private $S1 = [];
|
||||
|
||||
/**
|
||||
* The Key depended S-Table 2
|
||||
@ -343,7 +343,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $S2 = array();
|
||||
private $S2 = [];
|
||||
|
||||
/**
|
||||
* The Key depended S-Table 3
|
||||
@ -351,7 +351,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $S3 = array();
|
||||
private $S3 = [];
|
||||
|
||||
/**
|
||||
* Holds the last used key
|
||||
@ -359,7 +359,7 @@ class Twofish extends BlockCipher
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $kl;
|
||||
private $kl;
|
||||
|
||||
/**
|
||||
* The Key Length (in bytes)
|
||||
@ -368,7 +368,7 @@ class Twofish extends BlockCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $key_length = 16;
|
||||
protected $key_length = 16;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -377,7 +377,7 @@ class Twofish extends BlockCipher
|
||||
* @access public
|
||||
* @throws \InvalidArgumentException if an invalid / unsupported mode is provided
|
||||
*/
|
||||
function __construct($mode)
|
||||
public function __construct($mode)
|
||||
{
|
||||
if ($mode == self::MODE_STREAM) {
|
||||
throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode');
|
||||
@ -394,7 +394,7 @@ class Twofish extends BlockCipher
|
||||
* @access public
|
||||
* @param int $length
|
||||
*/
|
||||
function setKeyLength($length)
|
||||
public function setKeyLength($length)
|
||||
{
|
||||
switch ($length) {
|
||||
case 128:
|
||||
@ -418,7 +418,7 @@ class Twofish extends BlockCipher
|
||||
* @param string $key
|
||||
* @throws \LengthException if the key length isn't supported
|
||||
*/
|
||||
function setKey($key)
|
||||
public function setKey($key)
|
||||
{
|
||||
switch (strlen($key)) {
|
||||
case 16:
|
||||
@ -438,13 +438,13 @@ class Twofish extends BlockCipher
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupKey()
|
||||
* @access private
|
||||
*/
|
||||
function _setupKey()
|
||||
protected function setupKey()
|
||||
{
|
||||
if (isset($this->kl['key']) && $this->key === $this->kl['key']) {
|
||||
// already expanded
|
||||
return;
|
||||
}
|
||||
$this->kl = array('key' => $this->key);
|
||||
$this->kl = ['key' => $this->key];
|
||||
|
||||
/* Key expanding and generating the key-depended s-boxes */
|
||||
$le_longs = unpack('V*', $this->key);
|
||||
@ -456,12 +456,12 @@ class Twofish extends BlockCipher
|
||||
$q0 = $this->q0;
|
||||
$q1 = $this->q1;
|
||||
|
||||
$K = $S0 = $S1 = $S2 = $S3 = array();
|
||||
$K = $S0 = $S1 = $S2 = $S3 = [];
|
||||
|
||||
switch (strlen($this->key)) {
|
||||
case 16:
|
||||
list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[1], $le_longs[2]);
|
||||
list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[3], $le_longs[4]);
|
||||
list($s7, $s6, $s5, $s4) = $this->mdsrem($le_longs[1], $le_longs[2]);
|
||||
list($s3, $s2, $s1, $s0) = $this->mdsrem($le_longs[3], $le_longs[4]);
|
||||
for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) {
|
||||
$A = $m0[$q0[$q0[$i] ^ $key[ 9]] ^ $key[1]] ^
|
||||
$m1[$q0[$q1[$i] ^ $key[10]] ^ $key[2]] ^
|
||||
@ -483,9 +483,9 @@ class Twofish extends BlockCipher
|
||||
}
|
||||
break;
|
||||
case 24:
|
||||
list($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[1], $le_longs[2]);
|
||||
list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[3], $le_longs[4]);
|
||||
list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[5], $le_longs[6]);
|
||||
list($sb, $sa, $s9, $s8) = $this->mdsrem($le_longs[1], $le_longs[2]);
|
||||
list($s7, $s6, $s5, $s4) = $this->mdsrem($le_longs[3], $le_longs[4]);
|
||||
list($s3, $s2, $s1, $s0) = $this->mdsrem($le_longs[5], $le_longs[6]);
|
||||
for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) {
|
||||
$A = $m0[$q0[$q0[$q1[$i] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^
|
||||
$m1[$q0[$q1[$q1[$i] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^
|
||||
@ -507,10 +507,10 @@ class Twofish extends BlockCipher
|
||||
}
|
||||
break;
|
||||
default: // 32
|
||||
list($sf, $se, $sd, $sc) = $this->_mdsrem($le_longs[1], $le_longs[2]);
|
||||
list($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[3], $le_longs[4]);
|
||||
list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[5], $le_longs[6]);
|
||||
list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[7], $le_longs[8]);
|
||||
list($sf, $se, $sd, $sc) = $this->mdsrem($le_longs[1], $le_longs[2]);
|
||||
list($sb, $sa, $s9, $s8) = $this->mdsrem($le_longs[3], $le_longs[4]);
|
||||
list($s7, $s6, $s5, $s4) = $this->mdsrem($le_longs[5], $le_longs[6]);
|
||||
list($s3, $s2, $s1, $s0) = $this->mdsrem($le_longs[7], $le_longs[8]);
|
||||
for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) {
|
||||
$A = $m0[$q0[$q0[$q1[$q1[$i] ^ $key[25]] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^
|
||||
$m1[$q0[$q1[$q1[$q0[$i] ^ $key[26]] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^
|
||||
@ -547,7 +547,7 @@ class Twofish extends BlockCipher
|
||||
* @param string $B
|
||||
* @return array
|
||||
*/
|
||||
function _mdsrem($A, $B)
|
||||
private function mdsrem($A, $B)
|
||||
{
|
||||
// No gain by unrolling this loop.
|
||||
for ($i = 0; $i < 8; ++$i) {
|
||||
@ -580,11 +580,11 @@ class Twofish extends BlockCipher
|
||||
$B^= ($u << 24) | ($u << 8);
|
||||
}
|
||||
|
||||
return array(
|
||||
return [
|
||||
0xff & $B >> 24,
|
||||
0xff & $B >> 16,
|
||||
0xff & $B >> 8,
|
||||
0xff & $B);
|
||||
0xff & $B];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -594,7 +594,7 @@ class Twofish extends BlockCipher
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
function _encryptBlock($in)
|
||||
protected function encryptBlock($in)
|
||||
{
|
||||
$S0 = $this->S0;
|
||||
$S1 = $this->S1;
|
||||
@ -650,7 +650,7 @@ class Twofish extends BlockCipher
|
||||
* @param string $in
|
||||
* @return string
|
||||
*/
|
||||
function _decryptBlock($in)
|
||||
protected function decryptBlock($in)
|
||||
{
|
||||
$S0 = $this->S0;
|
||||
$S1 = $this->S1;
|
||||
@ -705,144 +705,113 @@ class Twofish extends BlockCipher
|
||||
* @see \phpseclib\Crypt\Common\SymmetricKey::_setupInlineCrypt()
|
||||
* @access private
|
||||
*/
|
||||
function _setupInlineCrypt()
|
||||
protected function setupInlineCrypt()
|
||||
{
|
||||
$lambda_functions =& self::_getLambdaFunctions();
|
||||
|
||||
// Max. 10 Ultra-Hi-optimized inline-crypt functions. After that, we'll (still) create very fast code, but not the ultimate fast one.
|
||||
// (Currently, for Crypt_Twofish, one generated $lambda_function cost on php5.5@32bit ~140kb unfreeable mem and ~240kb on php5.5@64bit)
|
||||
$gen_hi_opt_code = (bool)(count($lambda_functions) < 10);
|
||||
|
||||
// Generation of a unique hash for our generated code
|
||||
$code_hash = "Crypt_Twofish, {$this->mode}";
|
||||
if ($gen_hi_opt_code) {
|
||||
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
|
||||
}
|
||||
|
||||
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;
|
||||
';
|
||||
$K = $this->K;
|
||||
$init_crypt = '
|
||||
static $S0, $S1, $S2, $S3;
|
||||
if (!$S0) {
|
||||
for ($i = 0; $i < 256; ++$i) {
|
||||
$S0[] = (int)$this->S0[$i];
|
||||
$S1[] = (int)$this->S1[$i];
|
||||
$S2[] = (int)$this->S2[$i];
|
||||
$S3[] = (int)$this->S3[$i];
|
||||
}
|
||||
}
|
||||
';
|
||||
|
||||
// Generating encrypt code:
|
||||
$encrypt_block = '
|
||||
$in = unpack("V4", $in);
|
||||
$R0 = '.$K[0].' ^ $in[1];
|
||||
$R1 = '.$K[1].' ^ $in[2];
|
||||
$R2 = '.$K[2].' ^ $in[3];
|
||||
$R3 = '.$K[3].' ^ $in[4];
|
||||
';
|
||||
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].');
|
||||
';
|
||||
}
|
||||
// Generating encrypt code:
|
||||
$encrypt_block = '
|
||||
$in = unpack("V4", $in);
|
||||
$R0 = '.$K[0].' ^ $in[1];
|
||||
$R1 = '.$K[1].' ^ $in[2];
|
||||
$R2 = '.$K[2].' ^ $in[3];
|
||||
$R3 = '.$K[3].' ^ $in[4];
|
||||
';
|
||||
for ($ki = 7, $i = 0; $i < 8; ++$i) {
|
||||
$encrypt_block.= '
|
||||
$in = pack("V4", '.$K[4].' ^ $R2,
|
||||
'.$K[5].' ^ $R3,
|
||||
'.$K[6].' ^ $R0,
|
||||
'.$K[7].' ^ $R1);
|
||||
';
|
||||
$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].');
|
||||
|
||||
// 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];
|
||||
$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].');
|
||||
';
|
||||
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
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class ANSI
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $max_x;
|
||||
private $max_x;
|
||||
|
||||
/**
|
||||
* Max Height
|
||||
@ -43,7 +43,7 @@ class ANSI
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $max_y;
|
||||
private $max_y;
|
||||
|
||||
/**
|
||||
* Max History
|
||||
@ -51,7 +51,7 @@ class ANSI
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $max_history;
|
||||
private $max_history;
|
||||
|
||||
/**
|
||||
* History
|
||||
@ -59,7 +59,7 @@ class ANSI
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $history;
|
||||
private $history;
|
||||
|
||||
/**
|
||||
* History Attributes
|
||||
@ -67,7 +67,7 @@ class ANSI
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $history_attrs;
|
||||
private $history_attrs;
|
||||
|
||||
/**
|
||||
* Current Column
|
||||
@ -75,7 +75,7 @@ class ANSI
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $x;
|
||||
private $x;
|
||||
|
||||
/**
|
||||
* Current Row
|
||||
@ -83,7 +83,7 @@ class ANSI
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $y;
|
||||
private $y;
|
||||
|
||||
/**
|
||||
* Old Column
|
||||
@ -91,7 +91,7 @@ class ANSI
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $old_x;
|
||||
private $old_x;
|
||||
|
||||
/**
|
||||
* Old Row
|
||||
@ -99,7 +99,7 @@ class ANSI
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $old_y;
|
||||
private $old_y;
|
||||
|
||||
/**
|
||||
* An empty attribute cell
|
||||
@ -107,7 +107,7 @@ class ANSI
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $base_attr_cell;
|
||||
private $base_attr_cell;
|
||||
|
||||
/**
|
||||
* The current attribute cell
|
||||
@ -115,7 +115,7 @@ class ANSI
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $attr_cell;
|
||||
private $attr_cell;
|
||||
|
||||
/**
|
||||
* An empty attribute row
|
||||
@ -123,7 +123,7 @@ class ANSI
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $attr_row;
|
||||
private $attr_row;
|
||||
|
||||
/**
|
||||
* The current screen text
|
||||
@ -131,7 +131,7 @@ class ANSI
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $screen;
|
||||
private $screen;
|
||||
|
||||
/**
|
||||
* The current screen attributes
|
||||
@ -139,7 +139,7 @@ class ANSI
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $attrs;
|
||||
private $attrs;
|
||||
|
||||
/**
|
||||
* Current ANSI code
|
||||
@ -147,7 +147,7 @@ class ANSI
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $ansi;
|
||||
private $ansi;
|
||||
|
||||
/**
|
||||
* Tokenization
|
||||
@ -155,7 +155,7 @@ class ANSI
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $tokenization;
|
||||
private $tokenization;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -163,7 +163,7 @@ class ANSI
|
||||
* @return \phpseclib\File\ANSI
|
||||
* @access public
|
||||
*/
|
||||
function __construct()
|
||||
public function __construct()
|
||||
{
|
||||
$attr_cell = new \stdClass();
|
||||
$attr_cell->bold = false;
|
||||
@ -188,12 +188,12 @@ class ANSI
|
||||
* @param int $y
|
||||
* @access public
|
||||
*/
|
||||
function setDimensions($x, $y)
|
||||
public function setDimensions($x, $y)
|
||||
{
|
||||
$this->max_x = $x - 1;
|
||||
$this->max_y = $y - 1;
|
||||
$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->screen = array_fill(0, $this->max_y + 1, '');
|
||||
$this->attrs = array_fill(0, $this->max_y + 1, $this->attr_row);
|
||||
@ -207,7 +207,7 @@ class ANSI
|
||||
* @param int $y
|
||||
* @access public
|
||||
*/
|
||||
function setHistory($history)
|
||||
public function setHistory($history)
|
||||
{
|
||||
$this->max_history = $history;
|
||||
}
|
||||
@ -218,7 +218,7 @@ class ANSI
|
||||
* @param string $source
|
||||
* @access public
|
||||
*/
|
||||
function loadString($source)
|
||||
public function loadString($source)
|
||||
{
|
||||
$this->setDimensions($this->max_x + 1, $this->max_y + 1);
|
||||
$this->appendString($source);
|
||||
@ -230,9 +230,9 @@ class ANSI
|
||||
* @param string $source
|
||||
* @access public
|
||||
*/
|
||||
function appendString($source)
|
||||
public function appendString($source)
|
||||
{
|
||||
$this->tokenization = array('');
|
||||
$this->tokenization = [''];
|
||||
for ($i = 0; $i < strlen($source); $i++) {
|
||||
if (strlen($this->ansi)) {
|
||||
$this->ansi.= $source[$i];
|
||||
@ -283,7 +283,7 @@ class ANSI
|
||||
case "\x1B(B": // set united states g0 character set
|
||||
break;
|
||||
case "\x1BE": // Move to next line
|
||||
$this->_newLine();
|
||||
$this->newLine();
|
||||
$this->x = 0;
|
||||
break;
|
||||
default:
|
||||
@ -379,7 +379,7 @@ class ANSI
|
||||
$this->x = 0;
|
||||
break;
|
||||
case "\n":
|
||||
$this->_newLine();
|
||||
$this->newLine();
|
||||
break;
|
||||
case "\x08": // backspace
|
||||
if ($this->x) {
|
||||
@ -431,17 +431,17 @@ class ANSI
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _newLine()
|
||||
private function newLine()
|
||||
{
|
||||
//if ($this->y < $this->max_y) {
|
||||
// $this->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->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;
|
||||
|
||||
if (count($this->history) >= $this->max_history) {
|
||||
@ -460,7 +460,7 @@ class ANSI
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _processCoordinate($last_attr, $cur_attr, $char)
|
||||
private function processCoordinate($last_attr, $cur_attr, $char)
|
||||
{
|
||||
$output = '';
|
||||
|
||||
@ -517,21 +517,21 @@ class ANSI
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _getScreen()
|
||||
private function getScreenHelper()
|
||||
{
|
||||
$output = '';
|
||||
$last_attr = $this->base_attr_cell;
|
||||
for ($i = 0; $i <= $this->max_y; $i++) {
|
||||
for ($j = 0; $j <= $this->max_x; $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];
|
||||
}
|
||||
$output.= "\r\n";
|
||||
}
|
||||
$output = substr($output, 0, -2);
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -541,9 +541,9 @@ class ANSI
|
||||
* @access public
|
||||
* @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
|
||||
* @return string
|
||||
*/
|
||||
function getHistory()
|
||||
public function getHistory()
|
||||
{
|
||||
$scrollback = '';
|
||||
$last_attr = $this->base_attr_cell;
|
||||
for ($i = 0; $i < count($this->history); $i++) {
|
||||
for ($j = 0; $j <= $this->max_x + 1; $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];
|
||||
}
|
||||
$scrollback.= "\r\n";
|
||||
}
|
||||
$base_attr_cell = $this->base_attr_cell;
|
||||
$this->base_attr_cell = $last_attr;
|
||||
$scrollback.= $this->_getScreen();
|
||||
$scrollback.= $this->getScreen();
|
||||
$this->base_attr_cell = $base_attr_cell;
|
||||
|
||||
return '<pre width="' . ($this->max_x + 1) . '" style="color: white; background: black">' . $scrollback . '</span></pre>';
|
||||
|
@ -34,7 +34,7 @@ use phpseclib\Math\BigInteger;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class ASN1
|
||||
abstract class ASN1
|
||||
{
|
||||
/**#@+
|
||||
* Tag Classes
|
||||
@ -109,7 +109,7 @@ class ASN1
|
||||
* @access private
|
||||
* @link http://en.wikipedia.org/wiki/Object_identifier
|
||||
*/
|
||||
static $oids = [];
|
||||
private static $oids = [];
|
||||
|
||||
/**
|
||||
* ASN.1 object identifier reverse mapping
|
||||
@ -117,7 +117,7 @@ class ASN1
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
static $reverseOIDs = [];
|
||||
private static $reverseOIDs = [];
|
||||
|
||||
/**
|
||||
* Default date format
|
||||
@ -126,7 +126,7 @@ class ASN1
|
||||
* @access private
|
||||
* @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
|
||||
@ -135,9 +135,9 @@ class ASN1
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
* @see self::_encode_der()
|
||||
* @see self::encode_der()
|
||||
*/
|
||||
static $filters;
|
||||
private static $filters;
|
||||
|
||||
/**
|
||||
* Current Location of most recent ASN.1 encode process
|
||||
@ -146,9 +146,9 @@ class ASN1
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
* @see self::_encode_der()
|
||||
* @see self::encode_der()
|
||||
*/
|
||||
static $location;
|
||||
private static $location;
|
||||
|
||||
/**
|
||||
* DER Encoded String
|
||||
@ -159,7 +159,7 @@ class ASN1
|
||||
* @access private
|
||||
* @see self::decodeDER()
|
||||
*/
|
||||
static $encoded;
|
||||
private static $encoded;
|
||||
|
||||
/**
|
||||
* Type mapping table for the ANY type.
|
||||
@ -224,7 +224,7 @@ class ASN1
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
static function decodeBER($encoded)
|
||||
public static function decodeBER($encoded)
|
||||
{
|
||||
if ($encoded instanceof Element) {
|
||||
$encoded = $encoded->element;
|
||||
@ -232,7 +232,7 @@ class ASN1
|
||||
|
||||
self::$encoded = $encoded;
|
||||
|
||||
$decoded = [self::_decode_ber($encoded)];
|
||||
$decoded = [self::decode_ber($encoded)];
|
||||
|
||||
// encapsulate in an array for BC with the old decodeBER
|
||||
return $decoded;
|
||||
@ -251,7 +251,7 @@ class ASN1
|
||||
* @return array
|
||||
* @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];
|
||||
|
||||
@ -328,7 +328,7 @@ class ASN1
|
||||
$newcontent = [];
|
||||
$remainingLength = $length;
|
||||
while ($remainingLength > 0) {
|
||||
$temp = self::_decode_ber($content, $start, $content_pos);
|
||||
$temp = self::decode_ber($content, $start, $content_pos);
|
||||
$length = $temp['length'];
|
||||
// end-of-content octets - see paragraph 8.1.5
|
||||
if (substr($content, $content_pos + $length, 2) == "\0\0") {
|
||||
@ -379,7 +379,7 @@ class ASN1
|
||||
if (!$constructed) {
|
||||
$current['content'] = substr($content, $content_pos);
|
||||
} else {
|
||||
$temp = self::_decode_ber($content, $start, $content_pos);
|
||||
$temp = self::decode_ber($content, $start, $content_pos);
|
||||
$length-= (strlen($content) - $content_pos);
|
||||
$last = count($temp) - 1;
|
||||
for ($i = 0; $i < $last; $i++) {
|
||||
@ -403,7 +403,7 @@ class ASN1
|
||||
$current['content'] = '';
|
||||
$length = 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'];
|
||||
// all subtags should be octet strings
|
||||
//if ($temp['type'] != self::TYPE_OCTET_STRING) {
|
||||
@ -435,7 +435,7 @@ class ASN1
|
||||
$length = $offset + 2; // +2 for the EOC
|
||||
break 2;
|
||||
}
|
||||
$temp = self::_decode_ber($content, $start + $offset, $content_pos);
|
||||
$temp = self::decode_ber($content, $start + $offset, $content_pos);
|
||||
$content_pos += $temp['length'];
|
||||
$current['content'][] = $temp;
|
||||
$offset+= $temp['length'];
|
||||
@ -493,7 +493,7 @@ class ASN1
|
||||
break;
|
||||
case self::TYPE_UTC_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:
|
||||
}
|
||||
|
||||
@ -516,7 +516,7 @@ class ASN1
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
static function asn1map($decoded, $mapping, $special = [])
|
||||
public static function asn1map($decoded, $mapping, $special = [])
|
||||
{
|
||||
if (isset($mapping['explicit']) && is_array($decoded['content'])) {
|
||||
$decoded = $decoded['content'][0];
|
||||
@ -736,7 +736,7 @@ class ASN1
|
||||
case self::TYPE_UTC_TIME:
|
||||
case self::TYPE_GENERALIZED_TIME:
|
||||
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']);
|
||||
case self::TYPE_BIT_STRING:
|
||||
@ -816,10 +816,10 @@ class ASN1
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
static function encodeDER($source, $mapping, $special = [])
|
||||
public static function encodeDER($source, $mapping, $special = [])
|
||||
{
|
||||
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
|
||||
* @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) {
|
||||
return $source->element;
|
||||
@ -863,7 +863,7 @@ class ASN1
|
||||
$child = $mapping['children'];
|
||||
|
||||
foreach ($source as $content) {
|
||||
$temp = self::_encode_der($content, $child, null, $special);
|
||||
$temp = self::encode_der($content, $child, null, $special);
|
||||
if ($temp === false) {
|
||||
return false;
|
||||
}
|
||||
@ -890,7 +890,7 @@ class ASN1
|
||||
continue;
|
||||
}
|
||||
|
||||
$temp = self::_encode_der($source[$key], $child, $key, $special);
|
||||
$temp = self::encode_der($source[$key], $child, $key, $special);
|
||||
if ($temp === false) {
|
||||
return false;
|
||||
}
|
||||
@ -931,7 +931,7 @@ class ASN1
|
||||
continue;
|
||||
}
|
||||
|
||||
$temp = self::_encode_der($source[$key], $child, $key, $special);
|
||||
$temp = self::encode_der($source[$key], $child, $key, $special);
|
||||
if ($temp === false) {
|
||||
return false;
|
||||
}
|
||||
@ -1063,19 +1063,19 @@ class ASN1
|
||||
|
||||
switch (true) {
|
||||
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 $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):
|
||||
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):
|
||||
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:
|
||||
$typename = implode('', array_keys($source));
|
||||
$outtype = array_search($typename, self::ANY_MAP, true);
|
||||
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) {
|
||||
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:
|
||||
$value = '';
|
||||
break;
|
||||
@ -1140,7 +1140,7 @@ class ASN1
|
||||
* @param int $tag
|
||||
* @return string
|
||||
*/
|
||||
static function _decodeTime($content, $tag)
|
||||
private static function decodeTime($content, $tag)
|
||||
{
|
||||
/* UTCTime:
|
||||
http://tools.ietf.org/html/rfc5280#section-4.1.2.5.1
|
||||
@ -1187,7 +1187,7 @@ class ASN1
|
||||
* @access public
|
||||
* @param string $format
|
||||
*/
|
||||
static function setTimeFormat($format)
|
||||
public static function setTimeFormat($format)
|
||||
{
|
||||
self::$format = $format;
|
||||
}
|
||||
@ -1201,7 +1201,7 @@ class ASN1
|
||||
* @access public
|
||||
* @param array $oids
|
||||
*/
|
||||
static function loadOIDs($oids)
|
||||
public static function loadOIDs($oids)
|
||||
{
|
||||
self::$oids+= $oids;
|
||||
self::$reverseOIDs = array_flip(self::$oids);
|
||||
@ -1216,7 +1216,7 @@ class ASN1
|
||||
* @access public
|
||||
* @param array $filters
|
||||
*/
|
||||
static function setFilters($filters)
|
||||
public static function setFilters($filters)
|
||||
{
|
||||
self::$filters = $filters;
|
||||
}
|
||||
@ -1233,7 +1233,7 @@ class ASN1
|
||||
* @return string
|
||||
* @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
|
||||
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
|
||||
* @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
|
||||
* above and beyond the ceritificate.
|
||||
@ -1358,7 +1358,7 @@ class ASN1
|
||||
* @param string $string
|
||||
* @return int
|
||||
*/
|
||||
static function decodeLength(&$string)
|
||||
public static function decodeLength(&$string)
|
||||
{
|
||||
$length = ord(Strings::shift($string));
|
||||
if ($length & 0x80) { // definite length, long form
|
||||
@ -1379,7 +1379,7 @@ class ASN1
|
||||
* @param int $length
|
||||
* @return string
|
||||
*/
|
||||
static function encodeLength($length)
|
||||
public static function encodeLength($length)
|
||||
{
|
||||
if ($length <= 0x7F) {
|
||||
return chr($length);
|
||||
|
@ -33,7 +33,7 @@ class Element
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $element;
|
||||
public $element;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -42,7 +42,7 @@ class Element
|
||||
* @return \phpseclib\File\ASN1\Element
|
||||
* @access public
|
||||
*/
|
||||
function __construct($encoded)
|
||||
public function __construct($encoded)
|
||||
{
|
||||
$this->element = $encoded;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class AccessDescription
|
||||
abstract class AccessDescription
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class AdministrationDomainName
|
||||
abstract class AdministrationDomainName
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_CHOICE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class AlgorithmIdentifier
|
||||
abstract class AlgorithmIdentifier
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class AnotherName
|
||||
abstract class AnotherName
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class Attribute
|
||||
abstract class Attribute
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class AttributeType
|
||||
abstract class AttributeType
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class AttributeTypeAndValue
|
||||
abstract class AttributeTypeAndValue
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class AttributeValue
|
||||
abstract class AttributeValue
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_ANY];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class Attributes
|
||||
abstract class Attributes
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SET,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class AuthorityInfoAccessSyntax
|
||||
abstract class AuthorityInfoAccessSyntax
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class AuthorityKeyIdentifier
|
||||
abstract class AuthorityKeyIdentifier
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class BaseDistance
|
||||
abstract class BaseDistance
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_INTEGER];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class BasicConstraints
|
||||
abstract class BasicConstraints
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class BuiltInDomainDefinedAttribute
|
||||
abstract class BuiltInDomainDefinedAttribute
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class BuiltInDomainDefinedAttributes
|
||||
abstract class BuiltInDomainDefinedAttributes
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class BuiltInStandardAttributes
|
||||
abstract class BuiltInStandardAttributes
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CPSuri
|
||||
abstract class CPSuri
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_IA5_STRING];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CRLDistributionPoints
|
||||
abstract class CRLDistributionPoints
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CRLNumber
|
||||
abstract class CRLNumber
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_INTEGER];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CRLReason
|
||||
abstract class CRLReason
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_ENUMERATED,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CertPolicyId
|
||||
abstract class CertPolicyId
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class Certificate
|
||||
abstract class Certificate
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CertificateIssuer
|
||||
abstract class CertificateIssuer
|
||||
{
|
||||
const MAP = GeneralNames::MAP;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CertificateList
|
||||
abstract class CertificateList
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CertificatePolicies
|
||||
abstract class CertificatePolicies
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CertificateSerialNumber
|
||||
abstract class CertificateSerialNumber
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_INTEGER];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CertificationRequest
|
||||
abstract class CertificationRequest
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CertificationRequestInfo
|
||||
abstract class CertificationRequestInfo
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class CountryName
|
||||
abstract class CountryName
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_CHOICE,
|
||||
|
@ -26,7 +26,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class DigestInfo
|
||||
abstract class DigestInfo
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class DirectoryString
|
||||
abstract class DirectoryString
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_CHOICE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class DisplayText
|
||||
abstract class DisplayText
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_CHOICE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class DistributionPoint
|
||||
abstract class DistributionPoint
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class DistributionPointName
|
||||
abstract class DistributionPointName
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_CHOICE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class EDIPartyName
|
||||
abstract class EDIPartyName
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class EncryptedData
|
||||
abstract class EncryptedData
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_OCTET_STRING];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class EncryptedPrivateKeyInfo
|
||||
abstract class EncryptedPrivateKeyInfo
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class ExtKeyUsageSyntax
|
||||
abstract class ExtKeyUsageSyntax
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -30,7 +30,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class Extension
|
||||
abstract class Extension
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class ExtensionAttribute
|
||||
abstract class ExtensionAttribute
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class ExtensionAttributes
|
||||
abstract class ExtensionAttributes
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SET,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class Extensions
|
||||
abstract class Extensions
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class GeneralName
|
||||
abstract class GeneralName
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_CHOICE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class GeneralNames
|
||||
abstract class GeneralNames
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class GeneralSubtree
|
||||
abstract class GeneralSubtree
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class GeneralSubtrees
|
||||
abstract class GeneralSubtrees
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class HoldInstructionCode
|
||||
abstract class HoldInstructionCode
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class InvalidityDate
|
||||
abstract class InvalidityDate
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_GENERALIZED_TIME];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class IssuerAltName
|
||||
abstract class IssuerAltName
|
||||
{
|
||||
const MAP = GeneralNames::MAP;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class IssuingDistributionPoint
|
||||
abstract class IssuingDistributionPoint
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class KeyIdentifier
|
||||
abstract class KeyIdentifier
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_OCTET_STRING];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class KeyPurposeId
|
||||
abstract class KeyPurposeId
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class KeyUsage
|
||||
abstract class KeyUsage
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_BIT_STRING,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class Name
|
||||
abstract class Name
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_CHOICE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class NameConstraints
|
||||
abstract class NameConstraints
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class NetworkAddress
|
||||
abstract class NetworkAddress
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_NUMERIC_STRING];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class NoticeReference
|
||||
abstract class NoticeReference
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class NumericUserIdentifier
|
||||
abstract class NumericUserIdentifier
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_NUMERIC_STRING];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class ORAddress
|
||||
abstract class ORAddress
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class OrganizationName
|
||||
abstract class OrganizationName
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_PRINTABLE_STRING];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class OrganizationalUnitNames
|
||||
abstract class OrganizationalUnitNames
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class OtherPrimeInfo
|
||||
abstract class OtherPrimeInfo
|
||||
{
|
||||
// version must be multi if otherPrimeInfos present
|
||||
const MAP = [
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class OtherPrimeInfos
|
||||
abstract class OtherPrimeInfos
|
||||
{
|
||||
// version must be multi if otherPrimeInfos present
|
||||
const MAP = [
|
||||
|
@ -26,7 +26,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PBEParameter
|
||||
abstract class PBEParameter
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -26,7 +26,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PBES2params
|
||||
abstract class PBES2params
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -26,7 +26,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PBKDF2params
|
||||
abstract class PBKDF2params
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -26,7 +26,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PBMAC1params
|
||||
abstract class PBMAC1params
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PKCS9String
|
||||
abstract class PKCS9String
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_CHOICE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PersonalName
|
||||
abstract class PersonalName
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SET,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PolicyInformation
|
||||
abstract class PolicyInformation
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PolicyMappings
|
||||
abstract class PolicyMappings
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PolicyQualifierId
|
||||
abstract class PolicyQualifierId
|
||||
{
|
||||
const MAP = ['type' => ASN1::TYPE_OBJECT_IDENTIFIER];
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use phpseclib\File\ASN1;
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @access public
|
||||
*/
|
||||
class PolicyQualifierInfo
|
||||
abstract class PolicyQualifierInfo
|
||||
{
|
||||
const MAP = [
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user