mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-01-26 08:38:29 +00:00
Merge branch '3.0'
This commit is contained in:
commit
004aec954f
@ -33,7 +33,7 @@ install:
|
||||
- travis/setup-composer.sh
|
||||
|
||||
script:
|
||||
- sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then vendor/bin/phing -f build/build.xml sniff; fi"
|
||||
- sh -c "if [ -d build/vendor ]; then build/vendor/bin/phpcs --standard=build/phpcs_ruleset.xml; fi"
|
||||
- sh -c "if [ -d build/vendor ]; then build/vendor/bin/php-cs-fixer fix --config=build/php-cs-fixer.php --diff --dry-run; fi"
|
||||
- sh -c "if [ -d build/vendor ]; then build/vendor/bin/psalm --config="build/psalm.xml" --no-cache --long-progress --report-show-info=false --output-format=text; fi"
|
||||
- travis/run-phpunit.sh
|
||||
|
@ -82,6 +82,7 @@ Special Thanks to our $50+ sponsors!:
|
||||
3. Install Development Dependencies
|
||||
```sh
|
||||
composer install
|
||||
composer install --no-interaction --working-dir=build
|
||||
```
|
||||
|
||||
4. Create a Feature Branch
|
||||
@ -89,10 +90,9 @@ Special Thanks to our $50+ sponsors!:
|
||||
5. Run continuous integration checks:
|
||||
```sh
|
||||
vendor/bin/phpunit
|
||||
vendor/bin/phing -f build/build.xml sniff
|
||||
|
||||
# The following tools are from the build specific composer.json:
|
||||
composer install --no-interaction --working-dir=build
|
||||
# The following tools are from the build specific composer.json using the most recent PHP version:
|
||||
build/vendor/bin/phpcs --standard=build/phpcs_ruleset.xml
|
||||
build/vendor/bin/php-cs-fixer fix --config=build/php-cs-fixer.php --diff --dry-run
|
||||
build/vendor/bin/psalm --config=build/psalm.xml --no-cache --long-progress --report-show-info=false --output-format=text
|
||||
```
|
||||
|
@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="phpseclib"
|
||||
description="PHP Secure Communications Library"
|
||||
default="all"
|
||||
>
|
||||
|
||||
<target name="all" depends="sniff" />
|
||||
|
||||
<!-- Code Sniffer -->
|
||||
<target name="sniff" depends="sniff-php-code,sniff-php-tests" />
|
||||
<target name="sniff-php-code">
|
||||
<exec command="vendor/bin/phpcs -s
|
||||
--extensions=php
|
||||
--standard=build/code-sniffer-ruleset.xml
|
||||
phpseclib/"
|
||||
dir=".." checkreturn="true" passthru="true" />
|
||||
</target>
|
||||
<target name="sniff-php-tests">
|
||||
<exec command="vendor/bin/phpcs -s
|
||||
--extensions=php
|
||||
--standard=build/code-sniffer-ruleset-tests.xml
|
||||
tests/"
|
||||
dir=".." checkreturn="true" passthru="true" />
|
||||
</target>
|
||||
</project>
|
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="phpseclib Test Standard">
|
||||
|
||||
<description>phpseclib coding standard for tests</description>
|
||||
|
||||
<!-- In general rules that apply to library code also apply to tests. -->
|
||||
<rule ref="./code-sniffer-ruleset.xml">
|
||||
<!-- Exceptions to the library coding standard follow. -->
|
||||
|
||||
<!-- Test classes do not have to be namespaced but may use pseudo-namespacing
|
||||
using underscore. -->
|
||||
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
|
||||
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
|
||||
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
@ -1,35 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="phpseclib Standard">
|
||||
|
||||
<description>phpseclib coding standard</description>
|
||||
|
||||
<!-- We are using the PSR2 standard as a base -->
|
||||
<rule ref="PSR2">
|
||||
<!-- Exceptions due to legacy code with PHP4 compatibility -->
|
||||
<exclude name="PSR2.Classes.PropertyDeclaration.ScopeMissing" />
|
||||
<exclude name="PSR2.Classes.PropertyDeclaration.VarUsed" />
|
||||
<exclude name="Squiz.Scope.MethodScope.Missing" />
|
||||
|
||||
<!-- Exceptions for backward compatibility -->
|
||||
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
|
||||
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
|
||||
|
||||
<!-- Exceptions for whitespacing -->
|
||||
<exclude name="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma" />
|
||||
<exclude name="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonCASE" />
|
||||
<exclude name="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonDEFAULT" />
|
||||
|
||||
<!-- Other Exceptions -->
|
||||
<exclude name="Generic.Files.LineLength.TooLong" />
|
||||
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
|
||||
</rule>
|
||||
|
||||
<!-- Useful additional rules follow -->
|
||||
|
||||
<!-- "for (; bar; )" should be "while (bar)" instead -->
|
||||
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop" />
|
||||
|
||||
<!-- A method MUST not only call its parent -->
|
||||
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod" />
|
||||
|
||||
</ruleset>
|
@ -6,6 +6,7 @@
|
||||
"require": {
|
||||
"php": "^8.1.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.5",
|
||||
"squizlabs/php_codesniffer": "^3.6",
|
||||
"vimeo/psalm": "^4.19"
|
||||
},
|
||||
"config": {
|
||||
|
22
build/phpcs_ruleset.xml
Normal file
22
build/phpcs_ruleset.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="phpseclib">
|
||||
<file>../build/php-cs-fixer.php</file>
|
||||
<file>../phpseclib/</file>
|
||||
<file>../tests/</file>
|
||||
|
||||
<arg name="extensions" value="php"/>
|
||||
<arg name="basepath" value=".."/>
|
||||
<arg name="report" value="emacs"/>
|
||||
<arg value="s"/>
|
||||
<arg value="n"/>
|
||||
<arg value="p"/>
|
||||
|
||||
<rule ref="PSR12">
|
||||
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/>
|
||||
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
|
||||
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
|
||||
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment"/>
|
||||
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
|
||||
<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses"/>
|
||||
</rule>
|
||||
</ruleset>
|
@ -56,9 +56,7 @@
|
||||
"php": ">=5.6.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phing/phing": "~2.7",
|
||||
"phpunit/phpunit": "^5.7|^6.0|^9.4",
|
||||
"squizlabs/php_codesniffer": "~2.0"
|
||||
"phpunit/phpunit": "^5.7|^6.0|^9.4"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
|
||||
|
@ -130,7 +130,7 @@ abstract class Strings
|
||||
// you need > 32-bit precision doesn't mean you need the full 64-bit precision
|
||||
extract(unpack('Nupper/Nlower', self::shift($data, 8)));
|
||||
$temp = $upper ? 4294967296 * $upper : 0;
|
||||
$temp+= $lower < 0 ? ($lower & 0x7FFFFFFFF) + 0x80000000 : $lower;
|
||||
$temp += $lower < 0 ? ($lower & 0x7FFFFFFFF) + 0x80000000 : $lower;
|
||||
// $temp = hexdec(bin2hex(self::shift($data, 8)));
|
||||
$result[] = $temp;
|
||||
continue 2;
|
||||
@ -177,20 +177,20 @@ abstract class Strings
|
||||
if (!is_int($element)) {
|
||||
throw new \InvalidArgumentException('Bytes must be represented as an integer between 0 and 255, inclusive.');
|
||||
}
|
||||
$result.= pack('C', $element);
|
||||
$result .= pack('C', $element);
|
||||
break;
|
||||
case 'b':
|
||||
if (!is_bool($element)) {
|
||||
throw new \InvalidArgumentException('A boolean parameter was expected.');
|
||||
}
|
||||
$result.= $element ? "\1" : "\0";
|
||||
$result .= $element ? "\1" : "\0";
|
||||
break;
|
||||
case 'Q':
|
||||
if (!is_int($element) && !is_float($element)) {
|
||||
throw new \InvalidArgumentException('An integer was expected.');
|
||||
}
|
||||
// 4294967296 == 1 << 32
|
||||
$result.= pack('NN', $element / 4294967296, $element);
|
||||
$result .= pack('NN', $element / 4294967296, $element);
|
||||
break;
|
||||
case 'N':
|
||||
if (is_float($element)) {
|
||||
@ -199,27 +199,27 @@ abstract class Strings
|
||||
if (!is_int($element)) {
|
||||
throw new \InvalidArgumentException('An integer was expected.');
|
||||
}
|
||||
$result.= pack('N', $element);
|
||||
$result .= pack('N', $element);
|
||||
break;
|
||||
case 's':
|
||||
if (!self::is_stringable($element)) {
|
||||
throw new \InvalidArgumentException('A string was expected.');
|
||||
}
|
||||
$result.= pack('Na*', strlen($element), $element);
|
||||
$result .= pack('Na*', strlen($element), $element);
|
||||
break;
|
||||
case 'i':
|
||||
if (!$element instanceof BigInteger && !$element instanceof FiniteField\Integer) {
|
||||
throw new \InvalidArgumentException('A phpseclib3\Math\BigInteger or phpseclib3\Math\Common\FiniteField\Integer object was expected.');
|
||||
}
|
||||
$element = $element->toBytes(true);
|
||||
$result.= pack('Na*', strlen($element), $element);
|
||||
$result .= pack('Na*', strlen($element), $element);
|
||||
break;
|
||||
case 'L':
|
||||
if (!is_array($element)) {
|
||||
throw new \InvalidArgumentException('An array was expected.');
|
||||
}
|
||||
$element = implode(',', $element);
|
||||
$result.= pack('Na*', strlen($element), $element);
|
||||
$result .= pack('Na*', strlen($element), $element);
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('$format contains an invalid character');
|
||||
@ -241,10 +241,10 @@ abstract class Strings
|
||||
{
|
||||
$parts = preg_split('#(\d+)#', $format, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$format = '';
|
||||
for ($i = 1; $i < count($parts); $i+=2) {
|
||||
$format.= substr($parts[$i - 1], 0, -1) . str_repeat(substr($parts[$i - 1], -1), $parts[$i]);
|
||||
for ($i = 1; $i < count($parts); $i += 2) {
|
||||
$format .= substr($parts[$i - 1], 0, -1) . str_repeat(substr($parts[$i - 1], -1), $parts[$i]);
|
||||
}
|
||||
$format.= $parts[$i - 1];
|
||||
$format .= $parts[$i - 1];
|
||||
|
||||
return $format;
|
||||
}
|
||||
@ -293,7 +293,7 @@ abstract class Strings
|
||||
foreach ($parts as $part) {
|
||||
$xor = $part[0] == '1' ? PHP_INT_MIN : 0;
|
||||
$part[0] = '0';
|
||||
$str.= pack(
|
||||
$str .= pack(
|
||||
PHP_INT_SIZE == 4 ? 'N' : 'J',
|
||||
$xor ^ eval('return 0b' . $part . ';')
|
||||
);
|
||||
@ -328,12 +328,12 @@ abstract class Strings
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$digits = unpack('N*', $x);
|
||||
foreach ($digits as $digit) {
|
||||
$bits.= sprintf('%032b', $digit);
|
||||
$bits .= sprintf('%032b', $digit);
|
||||
}
|
||||
} else {
|
||||
$digits = unpack('J*', $x);
|
||||
foreach ($digits as $digit) {
|
||||
$bits.= sprintf('%064b', $digit);
|
||||
$bits .= sprintf('%064b', $digit);
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,13 +355,13 @@ abstract class Strings
|
||||
if (PHP_INT_SIZE === 8) {
|
||||
// 3 operations
|
||||
// from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv
|
||||
$r.= chr((($b * 0x0202020202) & 0x010884422010) % 1023);
|
||||
$r .= chr((($b * 0x0202020202) & 0x010884422010) % 1023);
|
||||
} else {
|
||||
// 7 operations
|
||||
// from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits
|
||||
$p1 = ($b * 0x0802) & 0x22110;
|
||||
$p2 = ($b * 0x8020) & 0x88440;
|
||||
$r.= chr(
|
||||
$r .= chr(
|
||||
(($p1 | $p2) * 0x10101) >> 16
|
||||
);
|
||||
}
|
||||
@ -385,7 +385,7 @@ abstract class Strings
|
||||
return $var;
|
||||
}
|
||||
|
||||
for ($i = 4; $i <= strlen($var); $i+= 4) {
|
||||
for ($i = 4; $i <= strlen($var); $i += 4) {
|
||||
$temp = substr($var, -$i, 4);
|
||||
switch ($temp) {
|
||||
case "\xFF\xFF\xFF\xFF":
|
||||
|
@ -422,14 +422,14 @@ class Blowfish extends BlockCipher
|
||||
$l = $in[1];
|
||||
$r = $in[2];
|
||||
|
||||
for ($i = 0; $i < 16; $i+= 2) {
|
||||
$l^= $p[$i];
|
||||
$r^= self::safe_intval((self::safe_intval($sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]) ^
|
||||
for ($i = 0; $i < 16; $i += 2) {
|
||||
$l ^= $p[$i];
|
||||
$r ^= self::safe_intval((self::safe_intval($sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]) ^
|
||||
$sb_2[$l >> 8 & 0xff]) +
|
||||
$sb_3[$l & 0xff]);
|
||||
|
||||
$r^= $p[$i + 1];
|
||||
$l^= self::safe_intval((self::safe_intval($sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff]) ^
|
||||
$r ^= $p[$i + 1];
|
||||
$l ^= self::safe_intval((self::safe_intval($sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff]) ^
|
||||
$sb_2[$r >> 8 & 0xff]) +
|
||||
$sb_3[$r & 0xff]);
|
||||
}
|
||||
@ -455,14 +455,14 @@ class Blowfish extends BlockCipher
|
||||
$l = $in[1];
|
||||
$r = $in[2];
|
||||
|
||||
for ($i = 17; $i > 2; $i-= 2) {
|
||||
$l^= $p[$i];
|
||||
$r^= self::safe_intval((self::safe_intval($sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]) ^
|
||||
for ($i = 17; $i > 2; $i -= 2) {
|
||||
$l ^= $p[$i];
|
||||
$r ^= self::safe_intval((self::safe_intval($sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]) ^
|
||||
$sb_2[$l >> 8 & 0xff]) +
|
||||
$sb_3[$l & 0xff]);
|
||||
|
||||
$r^= $p[$i - 1];
|
||||
$l^= self::safe_intval((self::safe_intval($sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff]) ^
|
||||
$r ^= $p[$i - 1];
|
||||
$l ^= self::safe_intval((self::safe_intval($sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff]) ^
|
||||
$sb_2[$r >> 8 & 0xff]) +
|
||||
$sb_3[$r & 0xff]);
|
||||
}
|
||||
@ -496,8 +496,8 @@ class Blowfish extends BlockCipher
|
||||
$l = $in[1];
|
||||
$r = $in[2];
|
||||
';
|
||||
for ($i = 0; $i < 16; $i+= 2) {
|
||||
$encrypt_block.= '
|
||||
for ($i = 0; $i < 16; $i += 2) {
|
||||
$encrypt_block .= '
|
||||
$l^= ' . $p[$i] . ';
|
||||
$r^= ' . sprintf($safeint, '(' . sprintf($safeint, '$sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]') . ' ^
|
||||
$sb_2[$l >> 8 & 0xff]) +
|
||||
@ -509,7 +509,7 @@ class Blowfish extends BlockCipher
|
||||
$sb_3[$r & 0xff]') . ';
|
||||
';
|
||||
}
|
||||
$encrypt_block.= '
|
||||
$encrypt_block .= '
|
||||
$in = pack("N*",
|
||||
$r ^ ' . $p[17] . ',
|
||||
$l ^ ' . $p[16] . '
|
||||
@ -522,8 +522,8 @@ class Blowfish extends BlockCipher
|
||||
$r = $in[2];
|
||||
';
|
||||
|
||||
for ($i = 17; $i > 2; $i-= 2) {
|
||||
$decrypt_block.= '
|
||||
for ($i = 17; $i > 2; $i -= 2) {
|
||||
$decrypt_block .= '
|
||||
$l^= ' . $p[$i] . ';
|
||||
$r^= ' . sprintf($safeint, '(' . sprintf($safeint, '$sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]') . ' ^
|
||||
$sb_2[$l >> 8 & 0xff]) +
|
||||
@ -536,7 +536,7 @@ class Blowfish extends BlockCipher
|
||||
';
|
||||
}
|
||||
|
||||
$decrypt_block.= '
|
||||
$decrypt_block .= '
|
||||
$in = pack("N*",
|
||||
$r ^ ' . $p[0] . ',
|
||||
$l ^ ' . $p[1] . '
|
||||
|
@ -258,7 +258,7 @@ class ChaCha20 extends Salsa20
|
||||
$key = $this->key;
|
||||
if (strlen($key) == 16) {
|
||||
$constant = 'expand 16-byte k';
|
||||
$key.= $key;
|
||||
$key .= $key;
|
||||
} else {
|
||||
$constant = 'expand 32-byte k';
|
||||
}
|
||||
@ -280,10 +280,15 @@ class ChaCha20 extends Salsa20
|
||||
*/
|
||||
protected static function quarterRound(&$a, &$b, &$c, &$d)
|
||||
{
|
||||
// in https://datatracker.ietf.org/doc/html/rfc7539#section-2.1 the addition,
|
||||
// xor'ing and rotation are all on the same line so i'm keeping it on the same
|
||||
// line here as well
|
||||
// @codingStandardsIgnoreStart
|
||||
$a+= $b; $d = self::leftRotate($d ^ $a, 16);
|
||||
$c+= $d; $b = self::leftRotate($b ^ $c, 12);
|
||||
$a+= $b; $d = self::leftRotate($d ^ $a, 8);
|
||||
$c+= $d; $b = self::leftRotate($b ^ $c, 7);
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,15 +314,15 @@ class ChaCha20 extends Salsa20
|
||||
protected static function doubleRound(&$x0, &$x1, &$x2, &$x3, &$x4, &$x5, &$x6, &$x7, &$x8, &$x9, &$x10, &$x11, &$x12, &$x13, &$x14, &$x15)
|
||||
{
|
||||
// columnRound
|
||||
static::quarterRound($x0, $x4, $x8, $x12);
|
||||
static::quarterRound($x1, $x5, $x9, $x13);
|
||||
static::quarterRound($x2, $x6, $x10, $x14);
|
||||
static::quarterRound($x3, $x7, $x11, $x15);
|
||||
static::quarterRound($x0, $x4, $x8, $x12);
|
||||
static::quarterRound($x1, $x5, $x9, $x13);
|
||||
static::quarterRound($x2, $x6, $x10, $x14);
|
||||
static::quarterRound($x3, $x7, $x11, $x15);
|
||||
// rowRound
|
||||
static::quarterRound($x0, $x5, $x10, $x15);
|
||||
static::quarterRound($x1, $x6, $x11, $x12);
|
||||
static::quarterRound($x2, $x7, $x8, $x13);
|
||||
static::quarterRound($x3, $x4, $x9, $x14);
|
||||
static::quarterRound($x2, $x7, $x8, $x13);
|
||||
static::quarterRound($x3, $x4, $x9, $x14);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -355,6 +360,7 @@ class ChaCha20 extends Salsa20
|
||||
$z14 = $x14;
|
||||
$z15 = $x15;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
// columnRound
|
||||
$x0+= $x4; $x12 = self::leftRotate($x12 ^ $x0, 16);
|
||||
$x8+= $x12; $x4 = self::leftRotate($x4 ^ $x8, 12);
|
||||
@ -774,23 +780,24 @@ class ChaCha20 extends Salsa20
|
||||
$x9+= $x14; $x4 = self::leftRotate($x4 ^ $x9, 12);
|
||||
$x3+= $x4; $x14 = self::leftRotate($x14 ^ $x3, 8);
|
||||
$x9+= $x14; $x4 = self::leftRotate($x4 ^ $x9, 7);
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
$x0+= $z0;
|
||||
$x1+= $z1;
|
||||
$x2+= $z2;
|
||||
$x3+= $z3;
|
||||
$x4+= $z4;
|
||||
$x5+= $z5;
|
||||
$x6+= $z6;
|
||||
$x7+= $z7;
|
||||
$x8+= $z8;
|
||||
$x9+= $z9;
|
||||
$x10+= $z10;
|
||||
$x11+= $z11;
|
||||
$x12+= $z12;
|
||||
$x13+= $z13;
|
||||
$x14+= $z14;
|
||||
$x15+= $z15;
|
||||
$x0 += $z0;
|
||||
$x1 += $z1;
|
||||
$x2 += $z2;
|
||||
$x3 += $z3;
|
||||
$x4 += $z4;
|
||||
$x5 += $z5;
|
||||
$x6 += $z6;
|
||||
$x7 += $z7;
|
||||
$x8 += $z8;
|
||||
$x9 += $z9;
|
||||
$x10 += $z10;
|
||||
$x11 += $z11;
|
||||
$x12 += $z12;
|
||||
$x13 += $z13;
|
||||
$x14 += $z14;
|
||||
$x15 += $z15;
|
||||
|
||||
return pack('V*', $x0, $x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15);
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ abstract class AsymmetricKey
|
||||
protected static function initialize_static_variables()
|
||||
{
|
||||
if (!isset(self::$zero)) {
|
||||
self::$zero= new BigInteger(0);
|
||||
self::$zero = new BigInteger(0);
|
||||
self::$one = new BigInteger(1);
|
||||
}
|
||||
|
||||
@ -337,7 +337,7 @@ abstract class AsymmetricKey
|
||||
* @param string $method optional
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function validatePlugin($format, $type, $method = NULL)
|
||||
protected static function validatePlugin($format, $type, $method = null)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
if (!isset(self::$plugins[static::ALGORITHM][$format][$type])) {
|
||||
@ -519,7 +519,7 @@ abstract class AsymmetricKey
|
||||
*/
|
||||
public function getHash()
|
||||
{
|
||||
return clone $this->hash;
|
||||
return clone $this->hash;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -581,7 +581,7 @@ abstract class AsymmetricKey
|
||||
$rolen = $this->q->getLengthInBytes();
|
||||
if (strlen($out) < $rolen) {
|
||||
return str_pad($out, $rolen, "\0", STR_PAD_LEFT);
|
||||
} else if (strlen($out) > $rolen) {
|
||||
} elseif (strlen($out) > $rolen) {
|
||||
return substr($out, -$rolen);
|
||||
} else {
|
||||
return $out;
|
||||
|
@ -222,7 +222,7 @@ abstract class OpenSSH
|
||||
*/
|
||||
$paddingLength = (7 * strlen($paddedKey)) % 8;
|
||||
for ($i = 1; $i <= $paddingLength; $i++) {
|
||||
$paddedKey.= chr($i);
|
||||
$paddedKey .= chr($i);
|
||||
}
|
||||
$key = Strings::packSSH2('sssNss', 'none', 'none', '', 1, $publicKey, $paddedKey);
|
||||
$key = "openssh-key-v1\0$key";
|
||||
|
@ -77,4 +77,4 @@ abstract class PKCS
|
||||
{
|
||||
self::$format = self::MODE_ANY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ abstract class PKCS1 extends PKCS
|
||||
$symkey = '';
|
||||
$iv = substr($iv, 0, 8);
|
||||
while (strlen($symkey) < $length) {
|
||||
$symkey.= md5($symkey . $password . $iv, true);
|
||||
$symkey .= md5($symkey . $password . $iv, true);
|
||||
}
|
||||
return substr($symkey, 0, $length);
|
||||
}
|
||||
@ -200,7 +200,7 @@ abstract class PKCS1 extends PKCS
|
||||
$iv = strtoupper(Hex::encode($iv));
|
||||
return "-----BEGIN $type PRIVATE KEY-----\r\n" .
|
||||
"Proc-Type: 4,ENCRYPTED\r\n" .
|
||||
"DEK-Info: " . $encryptionAlgorithm. ",$iv\r\n" .
|
||||
"DEK-Info: " . $encryptionAlgorithm . ",$iv\r\n" .
|
||||
"\r\n" .
|
||||
chunk_split(Base64::encode($cipher->encrypt($key)), 64) .
|
||||
"-----END $type PRIVATE KEY-----";
|
||||
@ -220,4 +220,4 @@ abstract class PKCS1 extends PKCS
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
"-----END $type PUBLIC KEY-----";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -275,8 +275,7 @@ abstract class PKCS8 extends PKCS
|
||||
if (!static::$childOIDsLoaded) {
|
||||
ASN1::loadOIDs(is_array(static::OID_NAME) ?
|
||||
array_combine(static::OID_NAME, static::OID_VALUE) :
|
||||
[static::OID_NAME => static::OID_VALUE]
|
||||
);
|
||||
[static::OID_NAME => static::OID_VALUE]);
|
||||
static::$childOIDsLoaded = true;
|
||||
}
|
||||
if (!self::$oidsLoaded) {
|
||||
@ -287,8 +286,8 @@ abstract class PKCS8 extends PKCS
|
||||
'pbeWithMD2AndRC2-CBC' => '1.2.840.113549.1.5.4',
|
||||
'pbeWithMD5AndDES-CBC' => '1.2.840.113549.1.5.3',
|
||||
'pbeWithMD5AndRC2-CBC' => '1.2.840.113549.1.5.6',
|
||||
'pbeWithSHA1AndDES-CBC'=> '1.2.840.113549.1.5.10',
|
||||
'pbeWithSHA1AndRC2-CBC'=> '1.2.840.113549.1.5.11',
|
||||
'pbeWithSHA1AndDES-CBC' => '1.2.840.113549.1.5.10',
|
||||
'pbeWithSHA1AndRC2-CBC' => '1.2.840.113549.1.5.11',
|
||||
|
||||
// from PKCS#12:
|
||||
// https://tools.ietf.org/html/rfc7292
|
||||
@ -308,10 +307,10 @@ abstract class PKCS8 extends PKCS
|
||||
'id-hmacWithSHA1' => '1.2.840.113549.2.7',
|
||||
'id-hmacWithSHA224' => '1.2.840.113549.2.8',
|
||||
'id-hmacWithSHA256' => '1.2.840.113549.2.9',
|
||||
'id-hmacWithSHA384'=> '1.2.840.113549.2.10',
|
||||
'id-hmacWithSHA512'=> '1.2.840.113549.2.11',
|
||||
'id-hmacWithSHA512-224'=> '1.2.840.113549.2.12',
|
||||
'id-hmacWithSHA512-256'=> '1.2.840.113549.2.13',
|
||||
'id-hmacWithSHA384' => '1.2.840.113549.2.10',
|
||||
'id-hmacWithSHA512' => '1.2.840.113549.2.11',
|
||||
'id-hmacWithSHA512-224' => '1.2.840.113549.2.12',
|
||||
'id-hmacWithSHA512-256' => '1.2.840.113549.2.13',
|
||||
|
||||
'desCBC' => '1.3.14.3.2.7',
|
||||
'des-EDE3-CBC' => '1.2.840.113549.3.7',
|
||||
@ -319,8 +318,8 @@ abstract class PKCS8 extends PKCS
|
||||
'rc5-CBC-PAD' => '1.2.840.113549.3.9',
|
||||
|
||||
'aes128-CBC-PAD' => '2.16.840.1.101.3.4.1.2',
|
||||
'aes192-CBC-PAD'=> '2.16.840.1.101.3.4.1.22',
|
||||
'aes256-CBC-PAD'=> '2.16.840.1.101.3.4.1.42'
|
||||
'aes192-CBC-PAD' => '2.16.840.1.101.3.4.1.22',
|
||||
'aes256-CBC-PAD' => '2.16.840.1.101.3.4.1.42'
|
||||
]);
|
||||
self::$oidsLoaded = true;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ abstract class PuTTY
|
||||
$sequence = 0;
|
||||
while (strlen($symkey) < $length) {
|
||||
$temp = pack('Na*', $sequence++, $password);
|
||||
$symkey.= Hex::decode(sha1($temp));
|
||||
$symkey .= Hex::decode(sha1($temp));
|
||||
}
|
||||
return substr($symkey, 0, $length);
|
||||
}
|
||||
@ -119,7 +119,7 @@ abstract class PuTTY
|
||||
$flavour = SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13;
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedAlgorithmException('Only Argon2i and Argon2id are supported');
|
||||
throw new UnsupportedAlgorithmException('Only Argon2i and Argon2id are supported');
|
||||
}
|
||||
|
||||
$length = 80; // keylen + ivlen + mac_keylen
|
||||
@ -170,10 +170,10 @@ abstract class PuTTY
|
||||
break;
|
||||
case $in_value:
|
||||
$in_value = $line[strlen($line) - 1] == '\\';
|
||||
$values[$current].= $in_value ? substr($line, 0, -1) : $line;
|
||||
$values[$current] .= $in_value ? substr($line, 0, -1) : $line;
|
||||
break;
|
||||
default:
|
||||
$data.= $line;
|
||||
$data .= $line;
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ abstract class PuTTY
|
||||
if ($components === false) {
|
||||
throw new \UnexpectedValueException('Unable to decode public key');
|
||||
}
|
||||
$components+= $values;
|
||||
$components += $values;
|
||||
$components['comment'] = str_replace(['\\\\', '\"'], ['\\', '"'], $values['comment']);
|
||||
|
||||
return $components;
|
||||
@ -246,7 +246,7 @@ abstract class PuTTY
|
||||
case 2:
|
||||
$symkey = self::generateV2Key($password, 32);
|
||||
$symiv = str_repeat("\0", $crypto->getBlockLength() >> 3);
|
||||
$hashkey.= $password;
|
||||
$hashkey .= $password;
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@ abstract class PuTTY
|
||||
$private = $crypto->decrypt($private);
|
||||
}
|
||||
|
||||
$source.= Strings::packSSH2('s', $private);
|
||||
$source .= Strings::packSSH2('s', $private);
|
||||
|
||||
$hmac = trim(preg_replace('#Private-MAC: (.+)#', '$1', $key[$offset + $privateLength]));
|
||||
$hmac = Hex::decode($hmac);
|
||||
@ -302,19 +302,19 @@ abstract class PuTTY
|
||||
$version = isset($options['version']) ? $options['version'] : self::$version;
|
||||
|
||||
$key = "PuTTY-User-Key-File-$version: $type\r\n";
|
||||
$key.= "Encryption: $encryption\r\n";
|
||||
$key.= "Comment: $comment\r\n";
|
||||
$key .= "Encryption: $encryption\r\n";
|
||||
$key .= "Comment: $comment\r\n";
|
||||
|
||||
$public = Strings::packSSH2('s', $type) . $public;
|
||||
|
||||
$source = Strings::packSSH2('ssss', $type, $encryption, $comment, $public);
|
||||
|
||||
$public = Base64::encode($public);
|
||||
$key.= "Public-Lines: " . ((strlen($public) + 63) >> 6) . "\r\n";
|
||||
$key.= chunk_split($public, 64);
|
||||
$key .= "Public-Lines: " . ((strlen($public) + 63) >> 6) . "\r\n";
|
||||
$key .= chunk_split($public, 64);
|
||||
|
||||
if (empty($password) && !is_string($password)) {
|
||||
$source.= Strings::packSSH2('s', $private);
|
||||
$source .= Strings::packSSH2('s', $private);
|
||||
switch ($version) {
|
||||
case 3:
|
||||
$hash = new Hash('sha256');
|
||||
@ -325,18 +325,18 @@ abstract class PuTTY
|
||||
$hash->setKey(sha1('putty-private-key-file-mac-key', true));
|
||||
}
|
||||
} else {
|
||||
$private.= Random::string(16 - (strlen($private) & 15));
|
||||
$source.= Strings::packSSH2('s', $private);
|
||||
$private .= Random::string(16 - (strlen($private) & 15));
|
||||
$source .= Strings::packSSH2('s', $private);
|
||||
$crypto = new AES('cbc');
|
||||
|
||||
switch ($version) {
|
||||
case 3:
|
||||
$salt = Random::string(16);
|
||||
$key.= "Key-Derivation: Argon2id\r\n";
|
||||
$key.= "Argon2-Memory: 8192\r\n";
|
||||
$key.= "Argon2-Passes: 13\r\n";
|
||||
$key.= "Argon2-Parallelism: 1\r\n";
|
||||
$key.= "Argon2-Salt: " . Hex::encode($salt) . "\r\n";
|
||||
$key .= "Key-Derivation: Argon2id\r\n";
|
||||
$key .= "Argon2-Memory: 8192\r\n";
|
||||
$key .= "Argon2-Passes: 13\r\n";
|
||||
$key .= "Argon2-Parallelism: 1\r\n";
|
||||
$key .= "Argon2-Salt: " . Hex::encode($salt) . "\r\n";
|
||||
extract(self::generateV3Key($password, 'Argon2id', 8192, 13, $salt));
|
||||
|
||||
$hash = new Hash('sha256');
|
||||
@ -360,9 +360,9 @@ abstract class PuTTY
|
||||
}
|
||||
|
||||
$private = Base64::encode($private);
|
||||
$key.= 'Private-Lines: ' . ((strlen($private) + 63) >> 6) . "\r\n";
|
||||
$key.= chunk_split($private, 64);
|
||||
$key.= 'Private-MAC: ' . Hex::encode($hash->hash($source)) . "\r\n";
|
||||
$key .= 'Private-Lines: ' . ((strlen($private) + 63) >> 6) . "\r\n";
|
||||
$key .= chunk_split($private, 64);
|
||||
$key .= 'Private-MAC: ' . Hex::encode($hash->hash($source)) . "\r\n";
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
@ -887,7 +887,7 @@ abstract class SymmetricKey
|
||||
|
||||
if (is_string($this->key) && strlen($this->key) != $this->explicit_key_length) {
|
||||
$this->key = false;
|
||||
throw new InconsistentSetupException('Key has already been set and is not ' .$this->explicit_key_length . ' bytes long');
|
||||
throw new InconsistentSetupException('Key has already been set and is not ' . $this->explicit_key_length . ' bytes long');
|
||||
}
|
||||
}
|
||||
|
||||
@ -980,7 +980,7 @@ abstract class SymmetricKey
|
||||
|
||||
-- https://tools.ietf.org/html/rfc7292#appendix-B.1
|
||||
*/
|
||||
$password = "\0". chunk_split($password, 1, "\0") . "\0";
|
||||
$password = "\0" . chunk_split($password, 1, "\0") . "\0";
|
||||
|
||||
/*
|
||||
This standard specifies 3 different values for the ID byte mentioned
|
||||
@ -1003,7 +1003,7 @@ abstract class SymmetricKey
|
||||
$s = '';
|
||||
if (strlen($salt)) {
|
||||
while (strlen($s) < $blockLength) {
|
||||
$s.= $salt;
|
||||
$s .= $salt;
|
||||
}
|
||||
}
|
||||
$s = substr($s, 0, $blockLength);
|
||||
@ -1011,7 +1011,7 @@ abstract class SymmetricKey
|
||||
$p = '';
|
||||
if (strlen($password)) {
|
||||
while (strlen($p) < $blockLength) {
|
||||
$p.= $password;
|
||||
$p .= $password;
|
||||
}
|
||||
}
|
||||
$p = substr($p, 0, $blockLength);
|
||||
@ -1047,9 +1047,9 @@ abstract class SymmetricKey
|
||||
$f = $u = $hashObj->hash($salt . pack('N', $i++));
|
||||
for ($j = 2; $j <= $count; ++$j) {
|
||||
$u = $hashObj->hash($u);
|
||||
$f^= $u;
|
||||
$f ^= $u;
|
||||
}
|
||||
$key.= $f;
|
||||
$key .= $f;
|
||||
}
|
||||
$key = substr($key, 0, $dkLen);
|
||||
break;
|
||||
@ -1100,21 +1100,21 @@ abstract class SymmetricKey
|
||||
}
|
||||
$b = '';
|
||||
while (strlen($b) < $blockLength) {
|
||||
$b.= $ai;
|
||||
$b .= $ai;
|
||||
}
|
||||
$b = substr($b, 0, $blockLength);
|
||||
$b = new BigInteger($b, 256);
|
||||
$newi = '';
|
||||
for ($k = 0; $k < strlen($i); $k+= $blockLength) {
|
||||
for ($k = 0; $k < strlen($i); $k += $blockLength) {
|
||||
$temp = substr($i, $k, $blockLength);
|
||||
$temp = new BigInteger($temp, 256);
|
||||
$temp->setPrecision($blockLength << 3);
|
||||
$temp = $temp->add($b);
|
||||
$temp = $temp->add($one);
|
||||
$newi.= $temp->toBytes(false);
|
||||
$newi .= $temp->toBytes(false);
|
||||
}
|
||||
$i = $newi;
|
||||
$a.= $ai;
|
||||
$a .= $ai;
|
||||
}
|
||||
|
||||
return substr($a, 0, $n);
|
||||
@ -1209,11 +1209,11 @@ abstract class SymmetricKey
|
||||
$max = $this->block_size - $pos;
|
||||
if ($len >= $max) {
|
||||
$i = $max;
|
||||
$len-= $max;
|
||||
$len -= $max;
|
||||
$pos = 0;
|
||||
} else {
|
||||
$i = $len;
|
||||
$pos+= $len;
|
||||
$pos += $len;
|
||||
$len = 0;
|
||||
}
|
||||
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
||||
@ -1225,13 +1225,13 @@ abstract class SymmetricKey
|
||||
$overflow = $len % $this->block_size;
|
||||
|
||||
if ($overflow) {
|
||||
$ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
|
||||
$ciphertext .= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
|
||||
$iv = Strings::pop($ciphertext, $this->block_size);
|
||||
|
||||
$size = $len - $overflow;
|
||||
$block = $iv ^ substr($plaintext, -$overflow);
|
||||
$iv = substr_replace($iv, $block, 0, $overflow);
|
||||
$ciphertext.= $block;
|
||||
$ciphertext .= $block;
|
||||
$pos = $overflow;
|
||||
} elseif ($len) {
|
||||
$ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
|
||||
@ -1256,7 +1256,7 @@ abstract class SymmetricKey
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$xor = openssl_encrypt($iv, $this->cipher_name_openssl_ecb, $this->key, $this->openssl_options, $this->decryptIV);
|
||||
$ciphertext.= $plaintext[$i] ^ $xor;
|
||||
$ciphertext .= $plaintext[$i] ^ $xor;
|
||||
$iv = substr($iv, 1) . $xor[0];
|
||||
}
|
||||
|
||||
@ -1270,7 +1270,8 @@ abstract class SymmetricKey
|
||||
}
|
||||
|
||||
if ($this->engine === self::ENGINE_MCRYPT) {
|
||||
set_error_handler(function() {});
|
||||
set_error_handler(function () {
|
||||
});
|
||||
if ($this->enchanged) {
|
||||
mcrypt_generic_init($this->enmcrypt, $this->key, $this->getIV($this->encryptIV));
|
||||
$this->enchanged = false;
|
||||
@ -1291,11 +1292,11 @@ abstract class SymmetricKey
|
||||
$max = $block_size - $pos;
|
||||
if ($len >= $max) {
|
||||
$i = $max;
|
||||
$len-= $max;
|
||||
$len -= $max;
|
||||
$pos = 0;
|
||||
} else {
|
||||
$i = $len;
|
||||
$pos+= $len;
|
||||
$pos += $len;
|
||||
$len = 0;
|
||||
}
|
||||
$ciphertext = substr($iv, $orig_pos) ^ $plaintext;
|
||||
@ -1308,15 +1309,15 @@ abstract class SymmetricKey
|
||||
mcrypt_generic_init($this->enmcrypt, $this->key, $iv);
|
||||
$this->enbuffer['enmcrypt_init'] = false;
|
||||
}
|
||||
$ciphertext.= mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % $block_size));
|
||||
$ciphertext .= mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % $block_size));
|
||||
$iv = substr($ciphertext, -$block_size);
|
||||
$len%= $block_size;
|
||||
$len %= $block_size;
|
||||
} else {
|
||||
while ($len >= $block_size) {
|
||||
$iv = mcrypt_generic($this->ecb, $iv) ^ substr($plaintext, $i, $block_size);
|
||||
$ciphertext.= $iv;
|
||||
$len-= $block_size;
|
||||
$i+= $block_size;
|
||||
$ciphertext .= $iv;
|
||||
$len -= $block_size;
|
||||
$i += $block_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1325,7 +1326,7 @@ abstract class SymmetricKey
|
||||
$iv = mcrypt_generic($this->ecb, $iv);
|
||||
$block = $iv ^ substr($plaintext, -$len);
|
||||
$iv = substr_replace($iv, $block, 0, $len);
|
||||
$ciphertext.= $block;
|
||||
$ciphertext .= $block;
|
||||
$pos = $len;
|
||||
}
|
||||
|
||||
@ -1355,17 +1356,17 @@ abstract class SymmetricKey
|
||||
$ciphertext = '';
|
||||
switch ($this->mode) {
|
||||
case self::MODE_ECB:
|
||||
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
||||
$ciphertext.= $this->encryptBlock(substr($plaintext, $i, $block_size));
|
||||
for ($i = 0; $i < strlen($plaintext); $i += $block_size) {
|
||||
$ciphertext .= $this->encryptBlock(substr($plaintext, $i, $block_size));
|
||||
}
|
||||
break;
|
||||
case self::MODE_CBC:
|
||||
$xor = $this->encryptIV;
|
||||
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($plaintext); $i += $block_size) {
|
||||
$block = substr($plaintext, $i, $block_size);
|
||||
$block = $this->encryptBlock($block ^ $xor);
|
||||
$xor = $block;
|
||||
$ciphertext.= $block;
|
||||
$ciphertext .= $block;
|
||||
}
|
||||
if ($this->continuousBuffer) {
|
||||
$this->encryptIV = $xor;
|
||||
@ -1374,21 +1375,21 @@ abstract class SymmetricKey
|
||||
case self::MODE_CTR:
|
||||
$xor = $this->encryptIV;
|
||||
if (strlen($buffer['ciphertext'])) {
|
||||
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($plaintext); $i += $block_size) {
|
||||
$block = substr($plaintext, $i, $block_size);
|
||||
if (strlen($block) > strlen($buffer['ciphertext'])) {
|
||||
$buffer['ciphertext'].= $this->encryptBlock($xor);
|
||||
$buffer['ciphertext'] .= $this->encryptBlock($xor);
|
||||
Strings::increment_str($xor);
|
||||
}
|
||||
$key = Strings::shift($buffer['ciphertext'], $block_size);
|
||||
$ciphertext.= $block ^ $key;
|
||||
$ciphertext .= $block ^ $key;
|
||||
}
|
||||
} else {
|
||||
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($plaintext); $i += $block_size) {
|
||||
$block = substr($plaintext, $i, $block_size);
|
||||
$key = $this->encryptBlock($xor);
|
||||
Strings::increment_str($xor);
|
||||
$ciphertext.= $block ^ $key;
|
||||
$ciphertext .= $block ^ $key;
|
||||
}
|
||||
}
|
||||
if ($this->continuousBuffer) {
|
||||
@ -1415,11 +1416,11 @@ abstract class SymmetricKey
|
||||
$max = $block_size - $pos;
|
||||
if ($len >= $max) {
|
||||
$i = $max;
|
||||
$len-= $max;
|
||||
$len -= $max;
|
||||
$pos = 0;
|
||||
} else {
|
||||
$i = $len;
|
||||
$pos+= $len;
|
||||
$pos += $len;
|
||||
$len = 0;
|
||||
}
|
||||
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
||||
@ -1428,15 +1429,15 @@ abstract class SymmetricKey
|
||||
}
|
||||
while ($len >= $block_size) {
|
||||
$iv = $this->encryptBlock($iv) ^ substr($plaintext, $i, $block_size);
|
||||
$ciphertext.= $iv;
|
||||
$len-= $block_size;
|
||||
$i+= $block_size;
|
||||
$ciphertext .= $iv;
|
||||
$len -= $block_size;
|
||||
$i += $block_size;
|
||||
}
|
||||
if ($len) {
|
||||
$iv = $this->encryptBlock($iv);
|
||||
$block = $iv ^ substr($plaintext, $i);
|
||||
$iv = substr_replace($iv, $block, 0, $len);
|
||||
$ciphertext.= $block;
|
||||
$ciphertext .= $block;
|
||||
$pos = $len;
|
||||
}
|
||||
break;
|
||||
@ -1465,7 +1466,7 @@ abstract class SymmetricKey
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$xor = $this->encryptBlock($iv);
|
||||
$ciphertext.= $plaintext[$i] ^ $xor;
|
||||
$ciphertext .= $plaintext[$i] ^ $xor;
|
||||
$iv = substr($iv, 1) . $xor[0];
|
||||
}
|
||||
|
||||
@ -1476,19 +1477,19 @@ abstract class SymmetricKey
|
||||
case self::MODE_OFB:
|
||||
$xor = $this->encryptIV;
|
||||
if (strlen($buffer['xor'])) {
|
||||
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($plaintext); $i += $block_size) {
|
||||
$block = substr($plaintext, $i, $block_size);
|
||||
if (strlen($block) > strlen($buffer['xor'])) {
|
||||
$xor = $this->encryptBlock($xor);
|
||||
$buffer['xor'].= $xor;
|
||||
$buffer['xor'] .= $xor;
|
||||
}
|
||||
$key = Strings::shift($buffer['xor'], $block_size);
|
||||
$ciphertext.= $block ^ $key;
|
||||
$ciphertext .= $block ^ $key;
|
||||
}
|
||||
} else {
|
||||
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($plaintext); $i += $block_size) {
|
||||
$xor = $this->encryptBlock($xor);
|
||||
$ciphertext.= substr($plaintext, $i, $block_size) ^ $xor;
|
||||
$ciphertext .= substr($plaintext, $i, $block_size) ^ $xor;
|
||||
}
|
||||
$key = $xor;
|
||||
}
|
||||
@ -1600,11 +1601,11 @@ abstract class SymmetricKey
|
||||
$max = $this->block_size - $pos;
|
||||
if ($len >= $max) {
|
||||
$i = $max;
|
||||
$len-= $max;
|
||||
$len -= $max;
|
||||
$pos = 0;
|
||||
} else {
|
||||
$i = $len;
|
||||
$pos+= $len;
|
||||
$pos += $len;
|
||||
$len = 0;
|
||||
}
|
||||
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $this->blocksize
|
||||
@ -1614,16 +1615,16 @@ abstract class SymmetricKey
|
||||
}
|
||||
$overflow = $len % $this->block_size;
|
||||
if ($overflow) {
|
||||
$plaintext.= openssl_decrypt(substr($ciphertext, 0, -$overflow), $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
|
||||
$plaintext .= openssl_decrypt(substr($ciphertext, 0, -$overflow), $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
|
||||
if ($len - $overflow) {
|
||||
$iv = substr($ciphertext, -$overflow - $this->block_size, -$overflow);
|
||||
}
|
||||
$iv = openssl_encrypt(str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
|
||||
$plaintext.= $iv ^ substr($ciphertext, -$overflow);
|
||||
$plaintext .= $iv ^ substr($ciphertext, -$overflow);
|
||||
$iv = substr_replace($iv, substr($ciphertext, -$overflow), 0, $overflow);
|
||||
$pos = $overflow;
|
||||
} elseif ($len) {
|
||||
$plaintext.= openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
|
||||
$plaintext .= openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
|
||||
$iv = substr($ciphertext, -$this->block_size);
|
||||
}
|
||||
break;
|
||||
@ -1644,7 +1645,7 @@ abstract class SymmetricKey
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$xor = openssl_encrypt($iv, $this->cipher_name_openssl_ecb, $this->key, $this->openssl_options, $this->decryptIV);
|
||||
$plaintext.= $ciphertext[$i] ^ $xor;
|
||||
$plaintext .= $ciphertext[$i] ^ $xor;
|
||||
$iv = substr($iv, 1) . $xor[0];
|
||||
}
|
||||
|
||||
@ -1660,7 +1661,8 @@ abstract class SymmetricKey
|
||||
}
|
||||
|
||||
if ($this->engine === self::ENGINE_MCRYPT) {
|
||||
set_error_handler(function() {});
|
||||
set_error_handler(function () {
|
||||
});
|
||||
$block_size = $this->block_size;
|
||||
if ($this->dechanged) {
|
||||
mcrypt_generic_init($this->demcrypt, $this->key, $this->getIV($this->decryptIV));
|
||||
@ -1678,11 +1680,11 @@ abstract class SymmetricKey
|
||||
$max = $block_size - $pos;
|
||||
if ($len >= $max) {
|
||||
$i = $max;
|
||||
$len-= $max;
|
||||
$len -= $max;
|
||||
$pos = 0;
|
||||
} else {
|
||||
$i = $len;
|
||||
$pos+= $len;
|
||||
$pos += $len;
|
||||
$len = 0;
|
||||
}
|
||||
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
||||
@ -1691,13 +1693,13 @@ abstract class SymmetricKey
|
||||
}
|
||||
if ($len >= $block_size) {
|
||||
$cb = substr($ciphertext, $i, $len - $len % $block_size);
|
||||
$plaintext.= mcrypt_generic($this->ecb, $iv . $cb) ^ $cb;
|
||||
$plaintext .= mcrypt_generic($this->ecb, $iv . $cb) ^ $cb;
|
||||
$iv = substr($cb, -$block_size);
|
||||
$len%= $block_size;
|
||||
$len %= $block_size;
|
||||
}
|
||||
if ($len) {
|
||||
$iv = mcrypt_generic($this->ecb, $iv);
|
||||
$plaintext.= $iv ^ substr($ciphertext, -$len);
|
||||
$plaintext .= $iv ^ substr($ciphertext, -$len);
|
||||
$iv = substr_replace($iv, substr($ciphertext, -$len), 0, $len);
|
||||
$pos = $len;
|
||||
}
|
||||
@ -1729,15 +1731,15 @@ abstract class SymmetricKey
|
||||
$plaintext = '';
|
||||
switch ($this->mode) {
|
||||
case self::MODE_ECB:
|
||||
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
||||
$plaintext.= $this->decryptBlock(substr($ciphertext, $i, $block_size));
|
||||
for ($i = 0; $i < strlen($ciphertext); $i += $block_size) {
|
||||
$plaintext .= $this->decryptBlock(substr($ciphertext, $i, $block_size));
|
||||
}
|
||||
break;
|
||||
case self::MODE_CBC:
|
||||
$xor = $this->decryptIV;
|
||||
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($ciphertext); $i += $block_size) {
|
||||
$block = substr($ciphertext, $i, $block_size);
|
||||
$plaintext.= $this->decryptBlock($block) ^ $xor;
|
||||
$plaintext .= $this->decryptBlock($block) ^ $xor;
|
||||
$xor = $block;
|
||||
}
|
||||
if ($this->continuousBuffer) {
|
||||
@ -1747,21 +1749,21 @@ abstract class SymmetricKey
|
||||
case self::MODE_CTR:
|
||||
$xor = $this->decryptIV;
|
||||
if (strlen($buffer['ciphertext'])) {
|
||||
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($ciphertext); $i += $block_size) {
|
||||
$block = substr($ciphertext, $i, $block_size);
|
||||
if (strlen($block) > strlen($buffer['ciphertext'])) {
|
||||
$buffer['ciphertext'].= $this->encryptBlock($xor);
|
||||
$buffer['ciphertext'] .= $this->encryptBlock($xor);
|
||||
Strings::increment_str($xor);
|
||||
}
|
||||
$key = Strings::shift($buffer['ciphertext'], $block_size);
|
||||
$plaintext.= $block ^ $key;
|
||||
$plaintext .= $block ^ $key;
|
||||
}
|
||||
} else {
|
||||
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($ciphertext); $i += $block_size) {
|
||||
$block = substr($ciphertext, $i, $block_size);
|
||||
$key = $this->encryptBlock($xor);
|
||||
Strings::increment_str($xor);
|
||||
$plaintext.= $block ^ $key;
|
||||
$plaintext .= $block ^ $key;
|
||||
}
|
||||
}
|
||||
if ($this->continuousBuffer) {
|
||||
@ -1786,11 +1788,11 @@ abstract class SymmetricKey
|
||||
$max = $block_size - $pos;
|
||||
if ($len >= $max) {
|
||||
$i = $max;
|
||||
$len-= $max;
|
||||
$len -= $max;
|
||||
$pos = 0;
|
||||
} else {
|
||||
$i = $len;
|
||||
$pos+= $len;
|
||||
$pos += $len;
|
||||
$len = 0;
|
||||
}
|
||||
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
||||
@ -1800,14 +1802,14 @@ abstract class SymmetricKey
|
||||
while ($len >= $block_size) {
|
||||
$iv = $this->encryptBlock($iv);
|
||||
$cb = substr($ciphertext, $i, $block_size);
|
||||
$plaintext.= $iv ^ $cb;
|
||||
$plaintext .= $iv ^ $cb;
|
||||
$iv = $cb;
|
||||
$len-= $block_size;
|
||||
$i+= $block_size;
|
||||
$len -= $block_size;
|
||||
$i += $block_size;
|
||||
}
|
||||
if ($len) {
|
||||
$iv = $this->encryptBlock($iv);
|
||||
$plaintext.= $iv ^ substr($ciphertext, $i);
|
||||
$plaintext .= $iv ^ substr($ciphertext, $i);
|
||||
$iv = substr_replace($iv, substr($ciphertext, $i), 0, $len);
|
||||
$pos = $len;
|
||||
}
|
||||
@ -1837,7 +1839,7 @@ abstract class SymmetricKey
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$xor = $this->encryptBlock($iv);
|
||||
$plaintext.= $ciphertext[$i] ^ $xor;
|
||||
$plaintext .= $ciphertext[$i] ^ $xor;
|
||||
$iv = substr($iv, 1) . $xor[0];
|
||||
}
|
||||
|
||||
@ -1848,19 +1850,19 @@ abstract class SymmetricKey
|
||||
case self::MODE_OFB:
|
||||
$xor = $this->decryptIV;
|
||||
if (strlen($buffer['xor'])) {
|
||||
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($ciphertext); $i += $block_size) {
|
||||
$block = substr($ciphertext, $i, $block_size);
|
||||
if (strlen($block) > strlen($buffer['xor'])) {
|
||||
$xor = $this->encryptBlock($xor);
|
||||
$buffer['xor'].= $xor;
|
||||
$buffer['xor'] .= $xor;
|
||||
}
|
||||
$key = Strings::shift($buffer['xor'], $block_size);
|
||||
$plaintext.= $block ^ $key;
|
||||
$plaintext .= $block ^ $key;
|
||||
}
|
||||
} else {
|
||||
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($ciphertext); $i += $block_size) {
|
||||
$xor = $this->encryptBlock($xor);
|
||||
$plaintext.= substr($ciphertext, $i, $block_size) ^ $xor;
|
||||
$plaintext .= substr($ciphertext, $i, $block_size) ^ $xor;
|
||||
}
|
||||
$key = $xor;
|
||||
}
|
||||
@ -1984,21 +1986,21 @@ abstract class SymmetricKey
|
||||
if ($this->openssl_emulate_ctr) {
|
||||
$xor = $encryptIV;
|
||||
if (strlen($buffer['ciphertext'])) {
|
||||
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($plaintext); $i += $block_size) {
|
||||
$block = substr($plaintext, $i, $block_size);
|
||||
if (strlen($block) > strlen($buffer['ciphertext'])) {
|
||||
$buffer['ciphertext'].= openssl_encrypt($xor, $this->cipher_name_openssl_ecb, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
|
||||
$buffer['ciphertext'] .= openssl_encrypt($xor, $this->cipher_name_openssl_ecb, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
|
||||
}
|
||||
Strings::increment_str($xor);
|
||||
$otp = Strings::shift($buffer['ciphertext'], $block_size);
|
||||
$ciphertext.= $block ^ $otp;
|
||||
$ciphertext .= $block ^ $otp;
|
||||
}
|
||||
} else {
|
||||
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
|
||||
for ($i = 0; $i < strlen($plaintext); $i += $block_size) {
|
||||
$block = substr($plaintext, $i, $block_size);
|
||||
$otp = openssl_encrypt($xor, $this->cipher_name_openssl_ecb, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
|
||||
Strings::increment_str($xor);
|
||||
$ciphertext.= $block ^ $otp;
|
||||
$ciphertext .= $block ^ $otp;
|
||||
}
|
||||
}
|
||||
if ($this->continuousBuffer) {
|
||||
@ -2025,13 +2027,13 @@ abstract class SymmetricKey
|
||||
$plaintext2 = Strings::pop($plaintext, $overflow); // ie. trim $plaintext to a multiple of $block_size and put rest of $plaintext in $plaintext2
|
||||
$encrypted = openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $encryptIV);
|
||||
$temp = Strings::pop($encrypted, $block_size);
|
||||
$ciphertext.= $encrypted . ($plaintext2 ^ $temp);
|
||||
$ciphertext .= $encrypted . ($plaintext2 ^ $temp);
|
||||
if ($this->continuousBuffer) {
|
||||
$buffer['ciphertext'] = substr($temp, $overflow);
|
||||
$encryptIV = $temp;
|
||||
}
|
||||
} elseif (!strlen($buffer['ciphertext'])) {
|
||||
$ciphertext.= openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $encryptIV);
|
||||
$ciphertext .= openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $encryptIV);
|
||||
$temp = Strings::pop($ciphertext, $block_size);
|
||||
if ($this->continuousBuffer) {
|
||||
$encryptIV = $temp;
|
||||
@ -2080,12 +2082,12 @@ abstract class SymmetricKey
|
||||
|
||||
if (strlen($plaintext)) {
|
||||
if ($overflow) {
|
||||
$ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $encryptIV);
|
||||
$ciphertext .= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $encryptIV);
|
||||
$xor = Strings::pop($ciphertext, $block_size);
|
||||
if ($this->continuousBuffer) {
|
||||
$encryptIV = $xor;
|
||||
}
|
||||
$ciphertext.= Strings::shift($xor, $overflow) ^ substr($plaintext, -$overflow);
|
||||
$ciphertext .= Strings::shift($xor, $overflow) ^ substr($plaintext, -$overflow);
|
||||
if ($this->continuousBuffer) {
|
||||
$buffer['xor'] = $xor;
|
||||
}
|
||||
@ -2270,7 +2272,8 @@ abstract class SymmetricKey
|
||||
}
|
||||
return false;
|
||||
case self::ENGINE_MCRYPT:
|
||||
set_error_handler(function() {});
|
||||
set_error_handler(function () {
|
||||
});
|
||||
$result = $this->cipher_name_mcrypt &&
|
||||
extension_loaded('mcrypt') &&
|
||||
in_array($this->cipher_name_mcrypt, mcrypt_list_algorithms());
|
||||
@ -2388,7 +2391,8 @@ abstract class SymmetricKey
|
||||
}
|
||||
|
||||
if ($this->engine != self::ENGINE_MCRYPT && $this->enmcrypt) {
|
||||
set_error_handler(function() {});
|
||||
set_error_handler(function () {
|
||||
});
|
||||
// Closing the current mcrypt resource(s). _mcryptSetup() will, if needed,
|
||||
// (re)open them with the module named in $this->cipher_name_mcrypt
|
||||
mcrypt_module_close($this->enmcrypt);
|
||||
@ -2508,7 +2512,8 @@ abstract class SymmetricKey
|
||||
case self::ENGINE_MCRYPT:
|
||||
$this->enchanged = $this->dechanged = true;
|
||||
|
||||
set_error_handler(function() {});
|
||||
set_error_handler(function () {
|
||||
});
|
||||
|
||||
if (!isset($this->enmcrypt)) {
|
||||
static $mcrypt_modes = [
|
||||
@ -2531,7 +2536,6 @@ abstract class SymmetricKey
|
||||
if ($this->mode == self::MODE_CFB) {
|
||||
$this->ecb = mcrypt_module_open($this->cipher_name_mcrypt, '', MCRYPT_MODE_ECB, '');
|
||||
}
|
||||
|
||||
} // else should mcrypt_generic_deinit be called?
|
||||
|
||||
if ($this->mode == self::MODE_CFB) {
|
||||
@ -2806,9 +2810,9 @@ abstract class SymmetricKey
|
||||
$_ciphertext = "";
|
||||
$_plaintext_len = strlen($_text);
|
||||
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
||||
$in = substr($_text, $_i, '.$block_size.');
|
||||
'.$encrypt_block.'
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= ' . $block_size . ') {
|
||||
$in = substr($_text, $_i, ' . $block_size . ');
|
||||
' . $encrypt_block . '
|
||||
$_ciphertext.= $in;
|
||||
}
|
||||
|
||||
@ -2817,12 +2821,12 @@ abstract class SymmetricKey
|
||||
|
||||
$decrypt = $init_decrypt . '
|
||||
$_plaintext = "";
|
||||
$_text = str_pad($_text, strlen($_text) + ('.$block_size.' - strlen($_text) % '.$block_size.') % '.$block_size.', chr(0));
|
||||
$_text = str_pad($_text, strlen($_text) + (' . $block_size . ' - strlen($_text) % ' . $block_size . ') % ' . $block_size . ', chr(0));
|
||||
$_ciphertext_len = strlen($_text);
|
||||
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
||||
$in = substr($_text, $_i, '.$block_size.');
|
||||
'.$decrypt_block.'
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= ' . $block_size . ') {
|
||||
$in = substr($_text, $_i, ' . $block_size . ');
|
||||
' . $decrypt_block . '
|
||||
$_plaintext.= $in;
|
||||
}
|
||||
|
||||
@ -2836,22 +2840,22 @@ abstract class SymmetricKey
|
||||
$_xor = $this->encryptIV;
|
||||
$_buffer = &$this->enbuffer;
|
||||
if (strlen($_buffer["ciphertext"])) {
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
||||
$_block = substr($_text, $_i, '.$block_size.');
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= ' . $block_size . ') {
|
||||
$_block = substr($_text, $_i, ' . $block_size . ');
|
||||
if (strlen($_block) > strlen($_buffer["ciphertext"])) {
|
||||
$in = $_xor;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
\phpseclib3\Common\Functions\Strings::increment_str($_xor);
|
||||
$_buffer["ciphertext"].= $in;
|
||||
}
|
||||
$_key = \phpseclib3\Common\Functions\Strings::shift($_buffer["ciphertext"], '.$block_size.');
|
||||
$_key = \phpseclib3\Common\Functions\Strings::shift($_buffer["ciphertext"], ' . $block_size . ');
|
||||
$_ciphertext.= $_block ^ $_key;
|
||||
}
|
||||
} else {
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
||||
$_block = substr($_text, $_i, '.$block_size.');
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= ' . $block_size . ') {
|
||||
$_block = substr($_text, $_i, ' . $block_size . ');
|
||||
$in = $_xor;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
\phpseclib3\Common\Functions\Strings::increment_str($_xor);
|
||||
$_key = $in;
|
||||
$_ciphertext.= $_block ^ $_key;
|
||||
@ -2859,7 +2863,7 @@ abstract class SymmetricKey
|
||||
}
|
||||
if ($this->continuousBuffer) {
|
||||
$this->encryptIV = $_xor;
|
||||
if ($_start = $_plaintext_len % '.$block_size.') {
|
||||
if ($_start = $_plaintext_len % ' . $block_size . ') {
|
||||
$_buffer["ciphertext"] = substr($_key, $_start) . $_buffer["ciphertext"];
|
||||
}
|
||||
}
|
||||
@ -2874,22 +2878,22 @@ abstract class SymmetricKey
|
||||
$_buffer = &$this->debuffer;
|
||||
|
||||
if (strlen($_buffer["ciphertext"])) {
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
||||
$_block = substr($_text, $_i, '.$block_size.');
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= ' . $block_size . ') {
|
||||
$_block = substr($_text, $_i, ' . $block_size . ');
|
||||
if (strlen($_block) > strlen($_buffer["ciphertext"])) {
|
||||
$in = $_xor;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
\phpseclib3\Common\Functions\Strings::increment_str($_xor);
|
||||
$_buffer["ciphertext"].= $in;
|
||||
}
|
||||
$_key = \phpseclib3\Common\Functions\Strings::shift($_buffer["ciphertext"], '.$block_size.');
|
||||
$_key = \phpseclib3\Common\Functions\Strings::shift($_buffer["ciphertext"], ' . $block_size . ');
|
||||
$_plaintext.= $_block ^ $_key;
|
||||
}
|
||||
} else {
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
||||
$_block = substr($_text, $_i, '.$block_size.');
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= ' . $block_size . ') {
|
||||
$_block = substr($_text, $_i, ' . $block_size . ');
|
||||
$in = $_xor;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
\phpseclib3\Common\Functions\Strings::increment_str($_xor);
|
||||
$_key = $in;
|
||||
$_plaintext.= $_block ^ $_key;
|
||||
@ -2897,7 +2901,7 @@ abstract class SymmetricKey
|
||||
}
|
||||
if ($this->continuousBuffer) {
|
||||
$this->decryptIV = $_xor;
|
||||
if ($_start = $_ciphertext_len % '.$block_size.') {
|
||||
if ($_start = $_ciphertext_len % ' . $block_size . ') {
|
||||
$_buffer["ciphertext"] = substr($_key, $_start) . $_buffer["ciphertext"];
|
||||
}
|
||||
}
|
||||
@ -2921,7 +2925,7 @@ abstract class SymmetricKey
|
||||
$_i = 0;
|
||||
if ($_pos) {
|
||||
$_orig_pos = $_pos;
|
||||
$_max = '.$block_size.' - $_pos;
|
||||
$_max = ' . $block_size . ' - $_pos;
|
||||
if ($_len >= $_max) {
|
||||
$_i = $_max;
|
||||
$_len-= $_max;
|
||||
@ -2934,17 +2938,17 @@ abstract class SymmetricKey
|
||||
$_ciphertext = substr($_iv, $_orig_pos) ^ $_text;
|
||||
$_iv = substr_replace($_iv, $_ciphertext, $_orig_pos, $_i);
|
||||
}
|
||||
while ($_len >= '.$block_size.') {
|
||||
while ($_len >= ' . $block_size . ') {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.';
|
||||
$_iv = $in ^ substr($_text, $_i, '.$block_size.');
|
||||
' . $encrypt_block . ';
|
||||
$_iv = $in ^ substr($_text, $_i, ' . $block_size . ');
|
||||
$_ciphertext.= $_iv;
|
||||
$_len-= '.$block_size.';
|
||||
$_i+= '.$block_size.';
|
||||
$_len-= ' . $block_size . ';
|
||||
$_i+= ' . $block_size . ';
|
||||
}
|
||||
if ($_len) {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
$_iv = $in;
|
||||
$_block = $_iv ^ substr($_text, $_i);
|
||||
$_iv = substr_replace($_iv, $_block, 0, $_len);
|
||||
@ -2969,7 +2973,7 @@ abstract class SymmetricKey
|
||||
$_i = 0;
|
||||
if ($_pos) {
|
||||
$_orig_pos = $_pos;
|
||||
$_max = '.$block_size.' - $_pos;
|
||||
$_max = ' . $block_size . ' - $_pos;
|
||||
if ($_len >= $_max) {
|
||||
$_i = $_max;
|
||||
$_len-= $_max;
|
||||
@ -2982,19 +2986,19 @@ abstract class SymmetricKey
|
||||
$_plaintext = substr($_iv, $_orig_pos) ^ $_text;
|
||||
$_iv = substr_replace($_iv, substr($_text, 0, $_i), $_orig_pos, $_i);
|
||||
}
|
||||
while ($_len >= '.$block_size.') {
|
||||
while ($_len >= ' . $block_size . ') {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
$_iv = $in;
|
||||
$cb = substr($_text, $_i, '.$block_size.');
|
||||
$cb = substr($_text, $_i, ' . $block_size . ');
|
||||
$_plaintext.= $_iv ^ $cb;
|
||||
$_iv = $cb;
|
||||
$_len-= '.$block_size.';
|
||||
$_i+= '.$block_size.';
|
||||
$_len-= ' . $block_size . ';
|
||||
$_i+= ' . $block_size . ';
|
||||
}
|
||||
if ($_len) {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
$_iv = $in;
|
||||
$_plaintext.= $_iv ^ substr($_text, $_i);
|
||||
$_iv = substr_replace($_iv, substr($_text, $_i), 0, $_len);
|
||||
@ -3012,16 +3016,16 @@ abstract class SymmetricKey
|
||||
|
||||
for ($_i = 0; $_i < $_len; ++$_i) {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
$_ciphertext .= ($_c = $_text[$_i] ^ $in);
|
||||
$_iv = substr($_iv, 1) . $_c;
|
||||
}
|
||||
|
||||
if ($this->continuousBuffer) {
|
||||
if ($_len >= '.$block_size.') {
|
||||
$this->encryptIV = substr($_ciphertext, -'.$block_size.');
|
||||
if ($_len >= ' . $block_size . ') {
|
||||
$this->encryptIV = substr($_ciphertext, -' . $block_size . ');
|
||||
} else {
|
||||
$this->encryptIV = substr($this->encryptIV, $_len - '.$block_size.') . substr($_ciphertext, -$_len);
|
||||
$this->encryptIV = substr($this->encryptIV, $_len - ' . $block_size . ') . substr($_ciphertext, -$_len);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3034,16 +3038,16 @@ abstract class SymmetricKey
|
||||
|
||||
for ($_i = 0; $_i < $_len; ++$_i) {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
$_plaintext .= $_text[$_i] ^ $in;
|
||||
$_iv = substr($_iv, 1) . $_text[$_i];
|
||||
}
|
||||
|
||||
if ($this->continuousBuffer) {
|
||||
if ($_len >= '.$block_size.') {
|
||||
$this->decryptIV = substr($_text, -'.$block_size.');
|
||||
if ($_len >= ' . $block_size . ') {
|
||||
$this->decryptIV = substr($_text, -' . $block_size . ');
|
||||
} else {
|
||||
$this->decryptIV = substr($this->decryptIV, $_len - '.$block_size.') . substr($_text, -$_len);
|
||||
$this->decryptIV = substr($this->decryptIV, $_len - ' . $block_size . ') . substr($_text, -$_len);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3058,7 +3062,7 @@ abstract class SymmetricKey
|
||||
|
||||
for ($_i = 0; $_i < $_len; ++$_i) {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
$_ciphertext.= $_text[$_i] ^ $in;
|
||||
$_iv = substr($_iv, 1) . $in[0];
|
||||
}
|
||||
@ -3076,7 +3080,7 @@ abstract class SymmetricKey
|
||||
|
||||
for ($_i = 0; $_i < $_len; ++$_i) {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
$_plaintext.= $_text[$_i] ^ $in;
|
||||
$_iv = substr($_iv, 1) . $in[0];
|
||||
}
|
||||
@ -3096,29 +3100,29 @@ abstract class SymmetricKey
|
||||
$_buffer = &$this->enbuffer;
|
||||
|
||||
if (strlen($_buffer["xor"])) {
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
||||
$_block = substr($_text, $_i, '.$block_size.');
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= ' . $block_size . ') {
|
||||
$_block = substr($_text, $_i, ' . $block_size . ');
|
||||
if (strlen($_block) > strlen($_buffer["xor"])) {
|
||||
$in = $_xor;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
$_xor = $in;
|
||||
$_buffer["xor"].= $_xor;
|
||||
}
|
||||
$_key = \phpseclib3\Common\Functions\Strings::shift($_buffer["xor"], '.$block_size.');
|
||||
$_key = \phpseclib3\Common\Functions\Strings::shift($_buffer["xor"], ' . $block_size . ');
|
||||
$_ciphertext.= $_block ^ $_key;
|
||||
}
|
||||
} else {
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= ' . $block_size . ') {
|
||||
$in = $_xor;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
$_xor = $in;
|
||||
$_ciphertext.= substr($_text, $_i, '.$block_size.') ^ $_xor;
|
||||
$_ciphertext.= substr($_text, $_i, ' . $block_size . ') ^ $_xor;
|
||||
}
|
||||
$_key = $_xor;
|
||||
}
|
||||
if ($this->continuousBuffer) {
|
||||
$this->encryptIV = $_xor;
|
||||
if ($_start = $_plaintext_len % '.$block_size.') {
|
||||
if ($_start = $_plaintext_len % ' . $block_size . ') {
|
||||
$_buffer["xor"] = substr($_key, $_start) . $_buffer["xor"];
|
||||
}
|
||||
}
|
||||
@ -3132,29 +3136,29 @@ abstract class SymmetricKey
|
||||
$_buffer = &$this->debuffer;
|
||||
|
||||
if (strlen($_buffer["xor"])) {
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
||||
$_block = substr($_text, $_i, '.$block_size.');
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= ' . $block_size . ') {
|
||||
$_block = substr($_text, $_i, ' . $block_size . ');
|
||||
if (strlen($_block) > strlen($_buffer["xor"])) {
|
||||
$in = $_xor;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
$_xor = $in;
|
||||
$_buffer["xor"].= $_xor;
|
||||
}
|
||||
$_key = \phpseclib3\Common\Functions\Strings::shift($_buffer["xor"], '.$block_size.');
|
||||
$_key = \phpseclib3\Common\Functions\Strings::shift($_buffer["xor"], ' . $block_size . ');
|
||||
$_plaintext.= $_block ^ $_key;
|
||||
}
|
||||
} else {
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= ' . $block_size . ') {
|
||||
$in = $_xor;
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
$_xor = $in;
|
||||
$_plaintext.= substr($_text, $_i, '.$block_size.') ^ $_xor;
|
||||
$_plaintext.= substr($_text, $_i, ' . $block_size . ') ^ $_xor;
|
||||
}
|
||||
$_key = $_xor;
|
||||
}
|
||||
if ($this->continuousBuffer) {
|
||||
$this->decryptIV = $_xor;
|
||||
if ($_start = $_ciphertext_len % '.$block_size.') {
|
||||
if ($_start = $_ciphertext_len % ' . $block_size . ') {
|
||||
$_buffer["xor"] = substr($_key, $_start) . $_buffer["xor"];
|
||||
}
|
||||
}
|
||||
@ -3164,12 +3168,12 @@ abstract class SymmetricKey
|
||||
case self::MODE_STREAM:
|
||||
$encrypt = $init_encrypt . '
|
||||
$_ciphertext = "";
|
||||
'.$encrypt_block.'
|
||||
' . $encrypt_block . '
|
||||
return $_ciphertext;
|
||||
';
|
||||
$decrypt = $init_decrypt . '
|
||||
$_plaintext = "";
|
||||
'.$decrypt_block.'
|
||||
' . $decrypt_block . '
|
||||
return $_plaintext;
|
||||
';
|
||||
break;
|
||||
@ -3181,9 +3185,9 @@ abstract class SymmetricKey
|
||||
|
||||
$in = $this->encryptIV;
|
||||
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
||||
$in = substr($_text, $_i, '.$block_size.') ^ $in;
|
||||
'.$encrypt_block.'
|
||||
for ($_i = 0; $_i < $_plaintext_len; $_i+= ' . $block_size . ') {
|
||||
$in = substr($_text, $_i, ' . $block_size . ') ^ $in;
|
||||
' . $encrypt_block . '
|
||||
$_ciphertext.= $in;
|
||||
}
|
||||
|
||||
@ -3196,14 +3200,14 @@ abstract class SymmetricKey
|
||||
|
||||
$decrypt = $init_decrypt . '
|
||||
$_plaintext = "";
|
||||
$_text = str_pad($_text, strlen($_text) + ('.$block_size.' - strlen($_text) % '.$block_size.') % '.$block_size.', chr(0));
|
||||
$_text = str_pad($_text, strlen($_text) + (' . $block_size . ' - strlen($_text) % ' . $block_size . ') % ' . $block_size . ', chr(0));
|
||||
$_ciphertext_len = strlen($_text);
|
||||
|
||||
$_iv = $this->decryptIV;
|
||||
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
||||
$in = $_block = substr($_text, $_i, '.$block_size.');
|
||||
'.$decrypt_block.'
|
||||
for ($_i = 0; $_i < $_ciphertext_len; $_i+= ' . $block_size . ') {
|
||||
$in = $_block = substr($_text, $_i, ' . $block_size . ');
|
||||
' . $decrypt_block . '
|
||||
$_plaintext.= $in ^ $_iv;
|
||||
$_iv = $_block;
|
||||
}
|
||||
@ -3381,7 +3385,7 @@ abstract class SymmetricKey
|
||||
$s = $this->poly1305Key; // strlen($this->poly1305Key) == 32
|
||||
$r = Strings::shift($s, 16);
|
||||
$r = strrev($r);
|
||||
$r&= "\x0f\xff\xff\xfc\x0f\xff\xff\xfc\x0f\xff\xff\xfc\x0f\xff\xff\xff";
|
||||
$r &= "\x0f\xff\xff\xfc\x0f\xff\xff\xfc\x0f\xff\xff\xfc\x0f\xff\xff\xff";
|
||||
$s = strrev($s);
|
||||
|
||||
$r = self::$poly1305Field->newInteger(new BigInteger($r, 256));
|
||||
|
@ -59,4 +59,4 @@ trait Fingerprint
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class DES extends BlockCipher
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
protected $key_length = 8;
|
||||
protected $key_length = 8;
|
||||
|
||||
/**
|
||||
* The mcrypt specific name of the cipher
|
||||
@ -1248,7 +1248,7 @@ class DES extends BlockCipher
|
||||
self::ENCRYPT => [],
|
||||
self::DECRYPT => array_fill(0, 32, 0)
|
||||
];
|
||||
for ($i = 0, $ki = 31; $i < 16; ++$i, $ki-= 2) {
|
||||
for ($i = 0, $ki = 31; $i < 16; ++$i, $ki -= 2) {
|
||||
$c <<= $shifts[$i];
|
||||
$c = ($c | ($c >> 28)) & 0x0FFFFFFF;
|
||||
$d <<= $shifts[$i];
|
||||
@ -1367,7 +1367,7 @@ class DES extends BlockCipher
|
||||
// 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].= '
|
||||
$crypt_block[$c] .= '
|
||||
$b1 = ((' . $r . ' >> 3) & 0x1FFFFFFF) ^ (' . $r . ' << 29) ^ ' . $k[$c][++$ki] . ';
|
||||
$b2 = ((' . $r . ' >> 31) & 0x00000001) ^ (' . $r . ' << 1) ^ ' . $k[$c][++$ki] . ';' .
|
||||
/* S-box indexing. */
|
||||
@ -1385,7 +1385,7 @@ class DES extends BlockCipher
|
||||
}
|
||||
|
||||
// Perform the inverse IP permutation.
|
||||
$crypt_block[$c].= '$in =
|
||||
$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") |
|
||||
|
@ -82,7 +82,7 @@ abstract class DH extends AsymmetricKey
|
||||
*/
|
||||
public static function createParameters(...$args)
|
||||
{
|
||||
$params = new Parameters;
|
||||
$params = new Parameters();
|
||||
if (count($args) == 2 && $args[0] instanceof BigInteger && $args[1] instanceof BigInteger) {
|
||||
//if (!$args[0]->isPrime()) {
|
||||
// throw new \InvalidArgumentException('The first parameter should be a prime number');
|
||||
@ -252,7 +252,7 @@ abstract class DH extends AsymmetricKey
|
||||
$max = $params->prime->subtract($one);
|
||||
}
|
||||
|
||||
$key = new PrivateKey;
|
||||
$key = new PrivateKey();
|
||||
$key->prime = $params->prime;
|
||||
$key->base = $params->base;
|
||||
$key->privateKey = BigInteger::randomRange($one, $max);
|
||||
@ -324,7 +324,8 @@ abstract class DH extends AsymmetricKey
|
||||
{
|
||||
try {
|
||||
return EC::load($key, $password);
|
||||
} catch (NoKeyLoadedException $e) {}
|
||||
} catch (NoKeyLoadedException $e) {
|
||||
}
|
||||
|
||||
return parent::load($key, $password);
|
||||
}
|
||||
@ -339,11 +340,11 @@ abstract class DH extends AsymmetricKey
|
||||
protected static function onLoad($components)
|
||||
{
|
||||
if (!isset($components['privateKey']) && !isset($components['publicKey'])) {
|
||||
$new = new Parameters;
|
||||
$new = new Parameters();
|
||||
} else {
|
||||
$new = isset($components['privateKey']) ?
|
||||
new PrivateKey :
|
||||
new PublicKey;
|
||||
new PrivateKey() :
|
||||
new PublicKey();
|
||||
}
|
||||
|
||||
$new->prime = $components['prime'];
|
||||
|
@ -154,4 +154,4 @@ abstract class PKCS8 extends Progenitor
|
||||
$key = ASN1::encodeDER($publicKey, ['type' => ASN1::TYPE_INTEGER]);
|
||||
return self::wrapPublicKey($key, $params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ abstract class DSA extends AsymmetricKey
|
||||
$h = $h->add(self::$one);
|
||||
}
|
||||
|
||||
$dsa = new Parameters;
|
||||
$dsa = new Parameters();
|
||||
$dsa->p = $p;
|
||||
$dsa->q = $q;
|
||||
$dsa->g = $g;
|
||||
@ -199,15 +199,15 @@ abstract class DSA extends AsymmetricKey
|
||||
|
||||
if (count($args) == 2 && is_int($args[0]) && is_int($args[1])) {
|
||||
$params = self::createParameters($args[0], $args[1]);
|
||||
} else if (count($args) == 1 && $args[0] instanceof Parameters) {
|
||||
} elseif (count($args) == 1 && $args[0] instanceof Parameters) {
|
||||
$params = $args[0];
|
||||
} else if (!count($args)) {
|
||||
} elseif (!count($args)) {
|
||||
$params = self::createParameters();
|
||||
} else {
|
||||
throw new InsufficientSetupException('Valid parameters are either two integers (L and N), a single DSA object or no parameters at all.');
|
||||
}
|
||||
|
||||
$private = new PrivateKey;
|
||||
$private = new PrivateKey();
|
||||
$private->p = $params->p;
|
||||
$private->q = $params->q;
|
||||
$private->g = $params->g;
|
||||
@ -237,12 +237,12 @@ abstract class DSA extends AsymmetricKey
|
||||
}
|
||||
|
||||
if (!isset($components['x']) && !isset($components['y'])) {
|
||||
$new = new Parameters;
|
||||
} else if (isset($components['x'])) {
|
||||
$new = new PrivateKey;
|
||||
$new = new Parameters();
|
||||
} elseif (isset($components['x'])) {
|
||||
$new = new PrivateKey();
|
||||
$new->x = $components['x'];
|
||||
} else {
|
||||
$new = new PublicKey;
|
||||
$new = new PublicKey();
|
||||
}
|
||||
|
||||
$new->p = $components['p'];
|
||||
@ -339,6 +339,6 @@ abstract class DSA extends AsymmetricKey
|
||||
*/
|
||||
public function getSignatureFormat()
|
||||
{
|
||||
return $this->shortFormat;
|
||||
return $this->shortFormat;
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,9 @@ abstract class SSH2
|
||||
if ($r->getLength() > 160 || $s->getLength() > 160) {
|
||||
return false;
|
||||
}
|
||||
return Strings::packSSH2('ss', 'ssh-dss',
|
||||
return Strings::packSSH2(
|
||||
'ss',
|
||||
'ssh-dss',
|
||||
str_pad($r->toBytes(), 20, "\0", STR_PAD_LEFT) .
|
||||
str_pad($s->toBytes(), 20, "\0", STR_PAD_LEFT)
|
||||
);
|
||||
|
@ -158,7 +158,7 @@ abstract class EC extends AsymmetricKey
|
||||
return $privatekey;
|
||||
}
|
||||
|
||||
$privatekey = new PrivateKey;
|
||||
$privatekey = new PrivateKey();
|
||||
|
||||
$curveName = $curve;
|
||||
if (preg_match('#(?:^curve|^ed)\d+$#', $curveName)) {
|
||||
@ -217,14 +217,14 @@ abstract class EC extends AsymmetricKey
|
||||
}
|
||||
|
||||
if (!isset($components['dA']) && !isset($components['QA'])) {
|
||||
$new = new Parameters;
|
||||
$new = new Parameters();
|
||||
$new->curve = $components['curve'];
|
||||
return $new;
|
||||
}
|
||||
|
||||
$new = isset($components['dA']) ?
|
||||
new PrivateKey :
|
||||
new PublicKey;
|
||||
new PrivateKey() :
|
||||
new PublicKey();
|
||||
$new->curve = $components['curve'];
|
||||
$new->QA = $components['QA'];
|
||||
|
||||
@ -396,7 +396,7 @@ abstract class EC extends AsymmetricKey
|
||||
*/
|
||||
public function getSignatureFormat()
|
||||
{
|
||||
return $this->shortFormat;
|
||||
return $this->shortFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -437,7 +437,7 @@ abstract class EC extends AsymmetricKey
|
||||
*/
|
||||
public function getContext()
|
||||
{
|
||||
return $this->context;
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -474,4 +474,4 @@ abstract class EC extends AsymmetricKey
|
||||
|
||||
return parent::__toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ class KoblitzPrime extends Prime
|
||||
];
|
||||
|
||||
if (isset($p['naf'])) {
|
||||
$beta['naf'] = array_map(function($p) {
|
||||
$beta['naf'] = array_map(function ($p) {
|
||||
return [
|
||||
$p[0]->multiply($this->beta),
|
||||
$p[1],
|
||||
@ -202,7 +202,8 @@ class KoblitzPrime extends Prime
|
||||
$f = $e->multiply($e);
|
||||
$x3 = $f->subtract($this->two->multiply($d));
|
||||
$y3 = $e->multiply($d->subtract($x3))->subtract(
|
||||
$this->eight->multiply($c));
|
||||
$this->eight->multiply($c)
|
||||
);
|
||||
$z3 = $this->two->multiply($y1)->multiply($z1);
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
@ -320,4 +321,4 @@ class KoblitzPrime extends Prime
|
||||
['a' => $a2, 'b' => $b2]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -280,4 +280,4 @@ class Montgomery extends Base
|
||||
list($x, $z) = $p;
|
||||
return [$x->divide($z)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -207,8 +207,10 @@ class Prime extends Base
|
||||
$v = $u1->multiply($h2);
|
||||
$x3 = $r->multiply($r)->subtract($h3)->subtract($v->multiply($this->two));
|
||||
$y3 = $r->multiply(
|
||||
$v->subtract($x3))->subtract(
|
||||
$s1->multiply($h3));
|
||||
$v->subtract($x3)
|
||||
)->subtract(
|
||||
$s1->multiply($h3)
|
||||
);
|
||||
return [$x3, $y3, $h];
|
||||
}
|
||||
|
||||
@ -242,8 +244,10 @@ class Prime extends Base
|
||||
$v = $u1->multiply($h2);
|
||||
$x3 = $r->multiply($r)->subtract($h3)->subtract($v->multiply($this->two));
|
||||
$y3 = $r->multiply(
|
||||
$v->subtract($x3))->subtract(
|
||||
$s1->multiply($h3));
|
||||
$v->subtract($x3)
|
||||
)->subtract(
|
||||
$s1->multiply($h3)
|
||||
);
|
||||
$z3 = $h->multiply($z1);
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
@ -279,8 +283,10 @@ class Prime extends Base
|
||||
$v = $u1->multiply($h2);
|
||||
$x3 = $r->multiply($r)->subtract($h3)->subtract($v->multiply($this->two));
|
||||
$y3 = $r->multiply(
|
||||
$v->subtract($x3))->subtract(
|
||||
$s1->multiply($h3));
|
||||
$v->subtract($x3)
|
||||
)->subtract(
|
||||
$s1->multiply($h3)
|
||||
);
|
||||
$z3 = $h->multiply($z1)->multiply($z2);
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
@ -370,7 +376,8 @@ class Prime extends Base
|
||||
$m = $m1->add($m2);
|
||||
$x1 = $m->multiply($m)->subtract($this->two->multiply($s));
|
||||
$y1 = $m->multiply($s->subtract($x1))->subtract(
|
||||
$this->eight->multiply($y2->multiply($y2)));
|
||||
$this->eight->multiply($y2->multiply($y2))
|
||||
);
|
||||
$z1 = $this->two->multiply($y)->multiply($z);
|
||||
return [$x1, $y1, $z1];
|
||||
}
|
||||
@ -390,7 +397,8 @@ class Prime extends Base
|
||||
$m = $m1->add($this->a);
|
||||
$x1 = $m->multiply($m)->subtract($this->two->multiply($s));
|
||||
$y1 = $m->multiply($s->subtract($x1))->subtract(
|
||||
$this->eight->multiply($y2->multiply($y2)));
|
||||
$this->eight->multiply($y2->multiply($y2))
|
||||
);
|
||||
$z1 = $this->two->multiply($y);
|
||||
return [$x1, $y1, $z1];
|
||||
}
|
||||
@ -439,8 +447,12 @@ class Prime extends Base
|
||||
$x = new BigInteger($m, 256);
|
||||
$xp = $this->convertInteger($x);
|
||||
switch ($y) {
|
||||
case 2: $ypn = false; break;
|
||||
case 3: $ypn = true; break;
|
||||
case 2:
|
||||
$ypn = false;
|
||||
break;
|
||||
case 3:
|
||||
$ypn = true;
|
||||
break;
|
||||
default:
|
||||
throw new \RuntimeException('Coordinate not in recognized format');
|
||||
}
|
||||
@ -529,7 +541,7 @@ class Prime extends Base
|
||||
// comb all window NAFs
|
||||
|
||||
$max = 0;
|
||||
for ($i = $length - 1; $i >= 1; $i-= 2) {
|
||||
for ($i = $length - 1; $i >= 1; $i -= 2) {
|
||||
$a = $i - 1;
|
||||
$b = $i;
|
||||
if ($wndWidth[$a] != 1 || $wndWidth[$b] != 1) {
|
||||
@ -687,12 +699,12 @@ class Prime extends Base
|
||||
while ($k1->compare(new BigInteger(-$d1)) > 0 || $k2->compare(new BigInteger(-$d2)) > 0) {
|
||||
// first phase
|
||||
$m14 = $k1->testBit(0) + 2 * $k1->testBit(1);
|
||||
$m14+= $d1;
|
||||
$m14&= 3;
|
||||
$m14 += $d1;
|
||||
$m14 &= 3;
|
||||
|
||||
$m24 = $k2->testBit(0) + 2 * $k2->testBit(1);
|
||||
$m24+= $d2;
|
||||
$m24&= 3;
|
||||
$m24 += $d2;
|
||||
$m24 &= 3;
|
||||
|
||||
if ($m14 == 3) {
|
||||
$m14 = -1;
|
||||
@ -704,8 +716,8 @@ class Prime extends Base
|
||||
$u1 = 0;
|
||||
if ($m14 & 1) { // if $m14 is odd
|
||||
$m8 = $k1->testBit(0) + 2 * $k1->testBit(1) + 4 * $k1->testBit(2);
|
||||
$m8+= $d1;
|
||||
$m8&= 7;
|
||||
$m8 += $d1;
|
||||
$m8 &= 7;
|
||||
$u1 = ($m8 == 3 || $m8 == 5) && $m24 == 2 ? -$m14 : $m14;
|
||||
}
|
||||
$jsf[0][] = $u1;
|
||||
@ -713,8 +725,8 @@ class Prime extends Base
|
||||
$u2 = 0;
|
||||
if ($m24 & 1) { // if $m24 is odd
|
||||
$m8 = $k2->testBit(0) + 2 * $k2->testBit(1) + 4 * $k2->testBit(2);
|
||||
$m8+= $d2;
|
||||
$m8&= 7;
|
||||
$m8 += $d2;
|
||||
$m8 &= 7;
|
||||
$u2 = ($m8 == 3 || $m8 == 5) && $m14 == 2 ? -$m24 : $m24;
|
||||
}
|
||||
$jsf[1][] = $u2;
|
||||
@ -771,4 +783,4 @@ class Prime extends Base
|
||||
$p['fresh'] = true;
|
||||
return $p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,4 +216,4 @@ class TwistedEdwards extends Base
|
||||
|
||||
return $lhs->equals($rhs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,9 +53,9 @@ class Curve25519 extends Montgomery
|
||||
//return [$this->factory->newInteger(new BigInteger($r, 256))];
|
||||
|
||||
$d = $d->toBytes();
|
||||
$d&= "\xF8" . str_repeat("\xFF", 30) . "\x7F";
|
||||
$d &= "\xF8" . str_repeat("\xFF", 30) . "\x7F";
|
||||
$d = strrev($d);
|
||||
$d|= "\x40";
|
||||
$d |= "\x40";
|
||||
$d = new BigInteger($d, -256);
|
||||
|
||||
return parent::multiplyPoint($p, $d);
|
||||
@ -80,4 +80,4 @@ class Curve25519 extends Montgomery
|
||||
throw new \RangeException('x must be a positive integer less than 256 bytes in length');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,13 +25,17 @@ class Curve448 extends Montgomery
|
||||
// 2^448 - 2^224 - 1
|
||||
$this->setModulo(new BigInteger(
|
||||
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE' .
|
||||
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 16));
|
||||
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
|
||||
16
|
||||
));
|
||||
$this->a24 = $this->factory->newInteger(new BigInteger('39081'));
|
||||
$this->p = [$this->factory->newInteger(new BigInteger(5))];
|
||||
// 2^446 - 0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d
|
||||
$this->setOrder(new BigInteger(
|
||||
'3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' .
|
||||
'7CCA23E9C44EDB49AED63690216CC2728DC58F552378C292AB5844F3', 16));
|
||||
'7CCA23E9C44EDB49AED63690216CC2728DC58F552378C292AB5844F3',
|
||||
16
|
||||
));
|
||||
|
||||
/*
|
||||
$this->setCoefficients(
|
||||
@ -62,7 +66,7 @@ class Curve448 extends Montgomery
|
||||
$d = $d->toBytes();
|
||||
$d[0] = $d[0] & "\xFC";
|
||||
$d = strrev($d);
|
||||
$d|= "\x80";
|
||||
$d |= "\x80";
|
||||
$d = new BigInteger($d, 256);
|
||||
|
||||
return parent::multiplyPoint($p, $d);
|
||||
@ -87,4 +91,4 @@ class Curve448 extends Montgomery
|
||||
throw new \RangeException('x must be a positive integer less than 446 bytes in length');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,11 +29,13 @@ class Ed448 extends TwistedEdwards
|
||||
// 2^448 - 2^224 - 1
|
||||
$this->setModulo(new BigInteger(
|
||||
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE' .
|
||||
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 16));
|
||||
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
|
||||
16
|
||||
));
|
||||
$this->setCoefficients(
|
||||
new BigInteger(1),
|
||||
// -39081
|
||||
new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE' .
|
||||
new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE' .
|
||||
'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6756', 16)
|
||||
);
|
||||
$this->setBasePoint(
|
||||
@ -44,7 +46,9 @@ class Ed448 extends TwistedEdwards
|
||||
);
|
||||
$this->setOrder(new BigInteger(
|
||||
'3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' .
|
||||
'7CCA23E9C44EDB49AED63690216CC2728DC58F552378C292AB5844F3', 16));
|
||||
'7CCA23E9C44EDB49AED63690216CC2728DC58F552378C292AB5844F3',
|
||||
16
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -263,4 +267,4 @@ class Ed448 extends TwistedEdwards
|
||||
|
||||
return [$x3, $y3, $z3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class brainpoolP160r1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('E95E4A5F737059DC60DF5991D45029409E60FC09', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,4 @@ class brainpoolP160t1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('E95E4A5F737059DC60DF5991D45029409E60FC09', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class brainpoolP192r1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('C302F41D932A36CDA7A3462F9E9E916B5BE8F1029AC4ACC1', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class brainpoolP192t1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('C302F41D932A36CDA7A3462F9E9E916B5BE8F1029AC4ACC1', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class brainpoolP224r1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('D7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A7939F', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class brainpoolP224t1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('D7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A7939F', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class brainpoolP256r1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,4 +39,4 @@ class brainpoolP320r1 extends Prime
|
||||
$this->setOrder(new BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D4' .
|
||||
'82EC7EE8658E98691555B44C59311', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,4 +39,4 @@ class brainpoolP320t1 extends Prime
|
||||
$this->setOrder(new BigInteger('D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D4' .
|
||||
'82EC7EE8658E98691555B44C59311', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,25 +24,37 @@ class brainpoolP384r1 extends Prime
|
||||
{
|
||||
$this->setModulo(new BigInteger(
|
||||
'8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A7' .
|
||||
'1874700133107EC53', 16));
|
||||
'1874700133107EC53',
|
||||
16
|
||||
));
|
||||
$this->setCoefficients(
|
||||
new BigInteger(
|
||||
'7BC382C63D8C150C3C72080ACE05AFA0C2BEA28E4FB22787139165EFBA91F90F8AA5814A503' .
|
||||
'AD4EB04A8C7DD22CE2826', 16),
|
||||
'AD4EB04A8C7DD22CE2826',
|
||||
16
|
||||
),
|
||||
new BigInteger(
|
||||
'4A8C7DD22CE28268B39B55416F0447C2FB77DE107DCD2A62E880EA53EEB62D57CB4390295DB' .
|
||||
'C9943AB78696FA504C11', 16)
|
||||
'C9943AB78696FA504C11',
|
||||
16
|
||||
)
|
||||
);
|
||||
$this->setBasePoint(
|
||||
new BigInteger(
|
||||
'1D1C64F068CF45FFA2A63A81B7C13F6B8847A3E77EF14FE3DB7FCAFE0CBD10E8E826E03436D' .
|
||||
'646AAEF87B2E247D4AF1E', 16),
|
||||
'646AAEF87B2E247D4AF1E',
|
||||
16
|
||||
),
|
||||
new BigInteger(
|
||||
'8ABE1D7520F9C2A45CB1EB8E95CFD55262B70B29FEEC5864E19C054FF99129280E464621779' .
|
||||
'1811142820341263C5315', 16)
|
||||
'1811142820341263C5315',
|
||||
16
|
||||
)
|
||||
);
|
||||
$this->setOrder(new BigInteger(
|
||||
'8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC31' .
|
||||
'03B883202E9046565', 16));
|
||||
'03B883202E9046565',
|
||||
16
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,25 +24,37 @@ class brainpoolP384t1 extends Prime
|
||||
{
|
||||
$this->setModulo(new BigInteger(
|
||||
'8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A7' .
|
||||
'1874700133107EC53', 16));
|
||||
'1874700133107EC53',
|
||||
16
|
||||
));
|
||||
$this->setCoefficients(
|
||||
new BigInteger(
|
||||
'8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901' .
|
||||
'D1A71874700133107EC50', 16), // eg. -3
|
||||
'D1A71874700133107EC50',
|
||||
16
|
||||
), // eg. -3
|
||||
new BigInteger(
|
||||
'7F519EADA7BDA81BD826DBA647910F8C4B9346ED8CCDC64E4B1ABD11756DCE1D2074AA263B8' .
|
||||
'8805CED70355A33B471EE', 16)
|
||||
'8805CED70355A33B471EE',
|
||||
16
|
||||
)
|
||||
);
|
||||
$this->setBasePoint(
|
||||
new BigInteger(
|
||||
'18DE98B02DB9A306F2AFCD7235F72A819B80AB12EBD653172476FECD462AABFFC4FF191B946' .
|
||||
'A5F54D8D0AA2F418808CC', 16),
|
||||
'A5F54D8D0AA2F418808CC',
|
||||
16
|
||||
),
|
||||
new BigInteger(
|
||||
'25AB056962D30651A114AFD2755AD336747F93475B7A1FCA3B88F2B6A208CCFE469408584DC' .
|
||||
'2B2912675BF5B9E582928', 16)
|
||||
'2B2912675BF5B9E582928',
|
||||
16
|
||||
)
|
||||
);
|
||||
$this->setOrder(new BigInteger(
|
||||
'8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC31' .
|
||||
'03B883202E9046565', 16));
|
||||
'03B883202E9046565',
|
||||
16
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,25 +24,37 @@ class brainpoolP512r1 extends Prime
|
||||
{
|
||||
$this->setModulo(new BigInteger(
|
||||
'AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC' .
|
||||
'66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3', 16));
|
||||
'66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3',
|
||||
16
|
||||
));
|
||||
$this->setCoefficients(
|
||||
new BigInteger(
|
||||
'7830A3318B603B89E2327145AC234CC594CBDD8D3DF91610A83441CAEA9863BC2DED5D5AA82' .
|
||||
'53AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA', 16),
|
||||
'53AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA',
|
||||
16
|
||||
),
|
||||
new BigInteger(
|
||||
'3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C' .
|
||||
'1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723', 16)
|
||||
'1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723',
|
||||
16
|
||||
)
|
||||
);
|
||||
$this->setBasePoint(
|
||||
new BigInteger(
|
||||
'81AEE4BDD82ED9645A21322E9C4C6A9385ED9F70B5D916C1B43B62EEF4D0098EFF3B1F78E2D' .
|
||||
'0D48D50D1687B93B97D5F7C6D5047406A5E688B352209BCB9F822', 16),
|
||||
'0D48D50D1687B93B97D5F7C6D5047406A5E688B352209BCB9F822',
|
||||
16
|
||||
),
|
||||
new BigInteger(
|
||||
'7DDE385D566332ECC0EABFA9CF7822FDF209F70024A57B1AA000C55B881F8111B2DCDE494A5' .
|
||||
'F485E5BCA4BD88A2763AED1CA2B2FA8F0540678CD1E0F3AD80892', 16)
|
||||
'F485E5BCA4BD88A2763AED1CA2B2FA8F0540678CD1E0F3AD80892',
|
||||
16
|
||||
)
|
||||
);
|
||||
$this->setOrder(new BigInteger(
|
||||
'AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA' .
|
||||
'92619418661197FAC10471DB1D381085DDADDB58796829CA90069', 16));
|
||||
'92619418661197FAC10471DB1D381085DDADDB58796829CA90069',
|
||||
16
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,25 +24,37 @@ class brainpoolP512t1 extends Prime
|
||||
{
|
||||
$this->setModulo(new BigInteger(
|
||||
'AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC' .
|
||||
'66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3', 16));
|
||||
'66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3',
|
||||
16
|
||||
));
|
||||
$this->setCoefficients(
|
||||
new BigInteger(
|
||||
'AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC' .
|
||||
'66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F0', 16), // eg. -3
|
||||
'66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F0',
|
||||
16
|
||||
), // eg. -3
|
||||
new BigInteger(
|
||||
'7CBBBCF9441CFAB76E1890E46884EAE321F70C0BCB4981527897504BEC3E36A62BCDFA23049' .
|
||||
'76540F6450085F2DAE145C22553B465763689180EA2571867423E', 16)
|
||||
'76540F6450085F2DAE145C22553B465763689180EA2571867423E',
|
||||
16
|
||||
)
|
||||
);
|
||||
$this->setBasePoint(
|
||||
new BigInteger(
|
||||
'640ECE5C12788717B9C1BA06CBC2A6FEBA85842458C56DDE9DB1758D39C0313D82BA51735CD' .
|
||||
'B3EA499AA77A7D6943A64F7A3F25FE26F06B51BAA2696FA9035DA', 16),
|
||||
'B3EA499AA77A7D6943A64F7A3F25FE26F06B51BAA2696FA9035DA',
|
||||
16
|
||||
),
|
||||
new BigInteger(
|
||||
'5B534BD595F5AF0FA2C892376C84ACE1BB4E3019B71634C01131159CAE03CEE9D9932184BEE' .
|
||||
'F216BD71DF2DADF86A627306ECFF96DBB8BACE198B61E00F8B332', 16)
|
||||
'F216BD71DF2DADF86A627306ECFF96DBB8BACE198B61E00F8B332',
|
||||
16
|
||||
)
|
||||
);
|
||||
$this->setOrder(new BigInteger(
|
||||
'AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA' .
|
||||
'92619418661197FAC10471DB1D381085DDADDB58796829CA90069', 16));
|
||||
'92619418661197FAC10471DB1D381085DDADDB58796829CA90069',
|
||||
16
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistb233 extends sect233r1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistb409 extends sect409r1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistk163 extends sect163k1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistk233 extends sect233k1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistk283 extends sect283k1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistk409 extends sect409k1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistp192 extends secp192r1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistp224 extends secp224r1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistp256 extends secp256r1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistp384 extends secp384r1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistp521 extends secp521r1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class nistt571 extends sect571k1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class prime192v1 extends secp192r1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class prime192v2 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFE5FB1A724DC80418648D8DD31', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class prime192v3 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFF7A62D031C83F4294F640EC13', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class prime239v1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF9E5E9A9F5D9071FBD1522688909D0B', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class prime239v2 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF800000CFA7E8594377D414C03821BC582063', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class prime239v3 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF975DEB41B3A6057C3C432146526551', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ namespace phpseclib3\Crypt\EC\Curves;
|
||||
|
||||
final class prime256v1 extends secp256r1
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class secp112r1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('DB7C2ABF62E35E7628DFAC6561C5', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,4 @@ class secp112r2 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('36DF0AAFD8B8D7597CA10520D04B', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class secp128r1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('FFFFFFFE0000000075A30D1B9038A115', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,4 @@ class secp128r2 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('3FFFFFFF7FFFFFFFBE0024720613B5A3', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,4 +45,4 @@ class secp160k1 extends KoblitzPrime
|
||||
];
|
||||
$this->beta = $this->factory->newInteger(new BigInteger('645B7345A143464942CC46D7CF4D5D1E1E6CBB68', -16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class secp160r1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('0100000000000000000001F4C8F927AED3CA752257', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,4 @@ class secp160r2 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('0100000000000000000000351EE786A818F3A1A16B', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,4 +44,4 @@ class secp192k1 extends KoblitzPrime
|
||||
];
|
||||
$this->beta = $this->factory->newInteger(new BigInteger('447A96E6C647963E2F7809FEAAB46947F34B0AA3CA0BBA74', -16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class secp192r1 extends Prime
|
||||
now, if PHP supported unsigned integers things might be different. no bit-shifting
|
||||
would be required for the PHP engine and it'd be a lot faster. but as is, BigInteger
|
||||
uses base-2**31 or base-2**26 depending on whether or not the system is has a 32-bit
|
||||
or a 64-bit OS.
|
||||
or a 64-bit OS.
|
||||
*/
|
||||
/*
|
||||
$m_length = $this->getLengthInBytes();
|
||||
@ -77,4 +77,4 @@ class secp192r1 extends Prime
|
||||
);
|
||||
$this->setOrder(new BigInteger('FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,4 +44,4 @@ class secp224k1 extends KoblitzPrime
|
||||
];
|
||||
$this->beta = $this->factory->newInteger(new BigInteger('01F178FFA4B17C89E6F73AECE2AAD57AF4C0A748B63C830947B27E04', -16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,4 +48,4 @@ class secp256k1 extends KoblitzPrime
|
||||
];
|
||||
$this->beta = $this->factory->newInteger(new BigInteger('7AE96A2B657C07106E64479EAC3434E99CF0497512F58995C1396C28719501EE', -16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,4 +51,4 @@ class secp384r1 extends Prime
|
||||
16
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,4 +45,4 @@ class secp521r1 extends Prime
|
||||
'FFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E9138' .
|
||||
'6409', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class sect113r1 extends Binary
|
||||
);
|
||||
$this->setOrder(new BigInteger('0100000000000000D9CCEC8A39E56F', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class sect113r2 extends Binary
|
||||
);
|
||||
$this->setOrder(new BigInteger('010000000000000108789B2496AF93', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class sect131r1 extends Binary
|
||||
);
|
||||
$this->setOrder(new BigInteger('0400000000000000023123953A9464B54D', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class sect131r2 extends Binary
|
||||
);
|
||||
$this->setOrder(new BigInteger('0400000000000000016954A233049BA98F', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class sect163k1 extends Binary
|
||||
);
|
||||
$this->setOrder(new BigInteger('04000000000000000000020108A2E0CC0D99F8A5EF', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,4 @@ class sect163r1 extends Binary
|
||||
);
|
||||
$this->setOrder(new BigInteger('03FFFFFFFFFFFFFFFFFFFF48AAB689C29CA710279B', 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ class sect409k1 extends Binary
|
||||
);
|
||||
$this->setOrder(new BigInteger(
|
||||
'7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F' .
|
||||
'83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF', 16
|
||||
'83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF',
|
||||
16
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ class sect409r1 extends Binary
|
||||
);
|
||||
$this->setOrder(new BigInteger(
|
||||
'010000000000000000000000000000000000000000000000000001E2' .
|
||||
'AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173', 16
|
||||
'AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173',
|
||||
16
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,8 @@ class sect571k1 extends Binary
|
||||
);
|
||||
$this->setOrder(new BigInteger(
|
||||
'020000000000000000000000000000000000000000000000000000000000000000000000' .
|
||||
'131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001', 16
|
||||
'131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001',
|
||||
16
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,8 @@ class sect571r1 extends Binary
|
||||
);
|
||||
$this->setOrder(new BigInteger(
|
||||
'03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' .
|
||||
'E661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47', 16
|
||||
'E661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47',
|
||||
16
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -97,8 +97,8 @@ trait Common
|
||||
'sect163k1' => '1.3.132.0.1',
|
||||
'sect163r2' => '1.3.132.0.15',
|
||||
'secp224r1' => '1.3.132.0.33',
|
||||
'sect233k1'=> '1.3.132.0.26',
|
||||
'sect233r1'=> '1.3.132.0.27',
|
||||
'sect233k1' => '1.3.132.0.26',
|
||||
'sect233r1' => '1.3.132.0.27',
|
||||
'secp256r1' => '1.2.840.10045.3.1.7', // aka prime256v1
|
||||
'sect283k1' => '1.3.132.0.16',
|
||||
'sect283r1' => '1.3.132.0.17',
|
||||
|
@ -56,10 +56,10 @@ abstract class MontgomeryPrivate
|
||||
{
|
||||
switch (strlen($key)) {
|
||||
case 32:
|
||||
$curve = new Curve25519;
|
||||
$curve = new Curve25519();
|
||||
break;
|
||||
case 56:
|
||||
$curve = new Curve448;
|
||||
$curve = new Curve448();
|
||||
break;
|
||||
default:
|
||||
throw new \LengthException('The only supported lengths are 32 and 56');
|
||||
|
@ -48,10 +48,10 @@ abstract class MontgomeryPublic
|
||||
{
|
||||
switch (strlen($key)) {
|
||||
case 32:
|
||||
$curve = new Curve25519;
|
||||
$curve = new Curve25519();
|
||||
break;
|
||||
case 56:
|
||||
$curve = new Curve448;
|
||||
$curve = new Curve448();
|
||||
break;
|
||||
default:
|
||||
throw new \LengthException('The only supported lengths are 32 and 56');
|
||||
|
@ -65,7 +65,7 @@ abstract class OpenSSH extends Progenitor
|
||||
if ($type != $parsed['type']) {
|
||||
throw new \RuntimeException("The public and private keys are not of the same type ($type vs $parsed[type])");
|
||||
}
|
||||
if ($type == 'ssh-ed25519' ) {
|
||||
if ($type == 'ssh-ed25519') {
|
||||
list(, $key, $comment) = Strings::unpackSSH2('sss', $paddedKey);
|
||||
$key = libsodium::load($key);
|
||||
$key['comment'] = $comment;
|
||||
@ -117,7 +117,7 @@ abstract class OpenSSH extends Progenitor
|
||||
$name = $reflect->getShortName();
|
||||
|
||||
$oid = self::$curveOIDs[$name];
|
||||
$aliases = array_filter(self::$curveOIDs, function($v) use ($oid) {
|
||||
$aliases = array_filter(self::$curveOIDs, function ($v) use ($oid) {
|
||||
return $v == $oid;
|
||||
});
|
||||
$aliases = array_keys($aliases);
|
||||
|
@ -113,7 +113,7 @@ abstract class PuTTY extends Progenitor
|
||||
if (!$curve instanceof TwistedEdwardsCurve) {
|
||||
$private = $privateKey->toBytes();
|
||||
if (!(strlen($privateKey->toBits()) & 7)) {
|
||||
$private ="\0$private";
|
||||
$private = "\0$private";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ abstract class XML
|
||||
$query = '/';
|
||||
$names = explode('/', $name);
|
||||
foreach ($names as $name) {
|
||||
$query.= "/*[translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='$name']";
|
||||
$query .= "/*[translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='$name']";
|
||||
}
|
||||
$result = $xpath->query($query);
|
||||
if (!isset($error)) {
|
||||
@ -435,7 +435,7 @@ abstract class XML
|
||||
$temp = $result['specifiedCurve'];
|
||||
switch ($temp['fieldID']['fieldType']) {
|
||||
case 'prime-field':
|
||||
$xml.= '<' . $pre . 'PrimeFieldParamsType>' . "\r\n" .
|
||||
$xml .= '<' . $pre . 'PrimeFieldParamsType>' . "\r\n" .
|
||||
'<' . $pre . 'P>' . $temp['fieldID']['parameters'] . '</' . $pre . 'P>' . "\r\n" .
|
||||
'</' . $pre . 'PrimeFieldParamsType>' . "\r\n";
|
||||
$a = $curve->getA();
|
||||
@ -445,7 +445,7 @@ abstract class XML
|
||||
default:
|
||||
throw new UnsupportedCurveException('Field Type of ' . $temp['fieldID']['fieldType'] . ' is not supported');
|
||||
}
|
||||
$xml.= '</' . $pre . 'FieldParams>' . "\r\n" .
|
||||
$xml .= '</' . $pre . 'FieldParams>' . "\r\n" .
|
||||
'<' . $pre . 'CurveParamsType>' . "\r\n" .
|
||||
'<' . $pre . 'A>' . $a . '</' . $pre . 'A>' . "\r\n" .
|
||||
'<' . $pre . 'B>' . $b . '</' . $pre . 'B>' . "\r\n" .
|
||||
@ -470,14 +470,14 @@ abstract class XML
|
||||
$temp = $result['specifiedCurve'];
|
||||
switch ($temp['fieldID']['fieldType']) {
|
||||
case 'prime-field':
|
||||
$xml.= '<' . $pre . 'Prime>' . "\r\n" .
|
||||
$xml .= '<' . $pre . 'Prime>' . "\r\n" .
|
||||
'<' . $pre . 'P>' . Base64::encode($temp['fieldID']['parameters']->toBytes()) . '</' . $pre . 'P>' . "\r\n" .
|
||||
'</' . $pre . 'Prime>' . "\r\n" ;
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedCurveException('Field Type of ' . $temp['fieldID']['fieldType'] . ' is not supported');
|
||||
}
|
||||
$xml.= '</' . $pre . 'FieldID>' . "\r\n" .
|
||||
$xml .= '</' . $pre . 'FieldID>' . "\r\n" .
|
||||
'<' . $pre . 'Curve>' . "\r\n" .
|
||||
'<' . $pre . 'A>' . Base64::encode($temp['curve']['a']) . '</' . $pre . 'A>' . "\r\n" .
|
||||
'<' . $pre . 'B>' . Base64::encode($temp['curve']['b']) . '</' . $pre . 'B>' . "\r\n" .
|
||||
|
@ -404,7 +404,7 @@ class Hash
|
||||
if (in_array(substr($hash, 0, 5), ['sha3-', 'shake', 'kecca'])) {
|
||||
// PHP 7.1.0 introduced support for "SHA3 fixed mode algorithms":
|
||||
// http://php.net/ChangeLog-7.php#7.1.0
|
||||
if (version_compare(PHP_VERSION, '7.1.0') < 0 || substr($hash, 0,5) != 'sha3-') {
|
||||
if (version_compare(PHP_VERSION, '7.1.0') < 0 || substr($hash, 0, 5) != 'sha3-') {
|
||||
//preg_match('#(\d+)$#', $hash, $matches);
|
||||
//$this->parameters['capacity'] = 2 * $matches[1]; // 1600 - $this->blockSize
|
||||
//$this->parameters['rate'] = 1600 - $this->parameters['capacity']; // == $this->blockSize
|
||||
@ -546,15 +546,15 @@ class Hash
|
||||
//
|
||||
$y = '';
|
||||
for ($i = 0; $i < $iters; $i++) {
|
||||
$L1Key_i = substr($L1Key, $i * 16, 1024);
|
||||
$L2Key_i = substr($L2Key, $i * 24, 24);
|
||||
$L1Key_i = substr($L1Key, $i * 16, 1024);
|
||||
$L2Key_i = substr($L2Key, $i * 24, 24);
|
||||
$L3Key1_i = substr($L3Key1, $i * 64, 64);
|
||||
$L3Key2_i = substr($L3Key2, $i * 4, 4);
|
||||
|
||||
$a = self::L1Hash($L1Key_i, $m);
|
||||
$b = strlen($m) <= 1024 ? "\0\0\0\0\0\0\0\0$a" : self::L2Hash($L2Key_i, $a);
|
||||
$c = self::L3Hash($L3Key1_i, $L3Key2_i, $b);
|
||||
$y.= $c;
|
||||
$y .= $c;
|
||||
}
|
||||
|
||||
return $y;
|
||||
@ -586,7 +586,7 @@ class Hash
|
||||
$y = '';
|
||||
for ($i = 0; $i < count($m) - 1; $i++) {
|
||||
$m[$i] = pack('N*', ...unpack('V*', $m[$i])); // ENDIAN-SWAP
|
||||
$y.= static::nh($k, $m[$i], $length);
|
||||
$y .= static::nh($k, $m[$i], $length);
|
||||
}
|
||||
|
||||
//
|
||||
@ -599,7 +599,7 @@ class Hash
|
||||
$m[$i] = str_pad($m[$i], $pad, "\0"); // zeropad
|
||||
$m[$i] = pack('N*', ...unpack('V*', $m[$i])); // ENDIAN-SWAP
|
||||
|
||||
$y.= static::nh($k, $m[$i], new BigInteger($length * 8));
|
||||
$y .= static::nh($k, $m[$i], new BigInteger($length * 8));
|
||||
|
||||
return $y;
|
||||
}
|
||||
@ -613,7 +613,7 @@ class Hash
|
||||
*/
|
||||
private static function nh($k, $m, $length)
|
||||
{
|
||||
$toUInt32 = function($x) {
|
||||
$toUInt32 = function ($x) {
|
||||
$x = new BigInteger($x, 256);
|
||||
$x->setPrecision(32);
|
||||
return $x;
|
||||
@ -635,7 +635,7 @@ class Hash
|
||||
// Perform NH hash on the chunks, pairing words for multiplication
|
||||
// which are 4 apart to accommodate vector-parallelism.
|
||||
//
|
||||
$y = new BigInteger;
|
||||
$y = new BigInteger();
|
||||
$y->setPrecision(64);
|
||||
$i = 0;
|
||||
while ($i < $t) {
|
||||
@ -659,7 +659,7 @@ class Hash
|
||||
$temp = $temp->multiply($m[$i + 7]->add($k[$i + 7]));
|
||||
$y = $y->add($temp);
|
||||
|
||||
$i+= 8;
|
||||
$i += 8;
|
||||
}
|
||||
|
||||
return $y->add($length)->toBytes();
|
||||
@ -702,7 +702,7 @@ class Hash
|
||||
$m_2 = substr($m, 0x20000) . "\x80";
|
||||
$length = strlen($m_2);
|
||||
$pad = 16 - ($length % 16);
|
||||
$pad%= 16;
|
||||
$pad %= 16;
|
||||
$m_2 = str_pad($m_2, $length + $pad, "\0"); // zeropad
|
||||
$y = self::poly(64, self::$maxwordrange64, $k64, $m_1);
|
||||
$y = str_pad($y, 16, "\0", STR_PAD_LEFT);
|
||||
@ -863,7 +863,7 @@ class Hash
|
||||
$temp .= $text;
|
||||
$temp = substr($algo($temp, ...array_values($this->parameters)), 0, $this->length);
|
||||
$output = $this->opad ^ $key;
|
||||
$output.= $temp;
|
||||
$output .= $temp;
|
||||
$output = $algo($output, ...array_values($this->parameters));
|
||||
|
||||
return substr($output, 0, $this->length);
|
||||
@ -981,7 +981,7 @@ class Hash
|
||||
$padLength = $block_size - (strlen($p) % $block_size);
|
||||
$num_ints = $block_size >> 2;
|
||||
|
||||
$p.= static::sha3_pad($padLength, $padType);
|
||||
$p .= static::sha3_pad($padLength, $padType);
|
||||
|
||||
$n = strlen($p) / $r; // number of blocks
|
||||
|
||||
@ -998,9 +998,9 @@ class Hash
|
||||
foreach ($p as $pi) {
|
||||
$pi = unpack('V*', $pi);
|
||||
$x = $y = 0;
|
||||
for ($i = 1; $i <= $num_ints; $i+=2) {
|
||||
$s[$x][$y][0]^= $pi[$i + 1];
|
||||
$s[$x][$y][1]^= $pi[$i];
|
||||
for ($i = 1; $i <= $num_ints; $i += 2) {
|
||||
$s[$x][$y][0] ^= $pi[$i + 1];
|
||||
$s[$x][$y][1] ^= $pi[$i];
|
||||
if (++$y == 5) {
|
||||
$y = 0;
|
||||
$x++;
|
||||
@ -1012,7 +1012,7 @@ class Hash
|
||||
$z = '';
|
||||
$i = $j = 0;
|
||||
while (strlen($z) < $d) {
|
||||
$z.= pack('V2', $s[$i][$j][1], $s[$i][$j++][0]);
|
||||
$z .= pack('V2', $s[$i][$j][1], $s[$i][$j++][0]);
|
||||
if ($j == 5) {
|
||||
$j = 0;
|
||||
$i++;
|
||||
@ -1092,8 +1092,8 @@ class Hash
|
||||
];
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
for ($j = 0; $j < 5; $j++) {
|
||||
$s[$i][$j][0]^= $temp[$j][0];
|
||||
$s[$i][$j][1]^= $temp[$j][1];
|
||||
$s[$i][$j][0] ^= $temp[$j][0];
|
||||
$s[$i][$j][1] ^= $temp[$j][1];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1131,8 +1131,8 @@ class Hash
|
||||
}
|
||||
|
||||
// iota step
|
||||
$s[0][0][0]^= $roundConstants[$round][0];
|
||||
$s[0][0][1]^= $roundConstants[$round][1];
|
||||
$s[0][0][0] ^= $roundConstants[$round][0];
|
||||
$s[0][0][1] ^= $roundConstants[$round][1];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1148,7 +1148,7 @@ class Hash
|
||||
if ($shift < 32) {
|
||||
list($hi, $lo) = $x;
|
||||
} else {
|
||||
$shift-= 32;
|
||||
$shift -= 32;
|
||||
list($lo, $hi) = $x;
|
||||
}
|
||||
|
||||
@ -1174,7 +1174,7 @@ class Hash
|
||||
$padLength = $block_size - (strlen($p) % $block_size);
|
||||
$num_ints = $block_size >> 2;
|
||||
|
||||
$p.= static::sha3_pad($padLength, $padType);
|
||||
$p .= static::sha3_pad($padLength, $padType);
|
||||
|
||||
$n = strlen($p) / $r; // number of blocks
|
||||
|
||||
@ -1192,7 +1192,7 @@ class Hash
|
||||
$pi = unpack('P*', $pi);
|
||||
$x = $y = 0;
|
||||
foreach ($pi as $subpi) {
|
||||
$s[$x][$y++]^= $subpi;
|
||||
$s[$x][$y++] ^= $subpi;
|
||||
if ($y == 5) {
|
||||
$y = 0;
|
||||
$x++;
|
||||
@ -1204,7 +1204,7 @@ class Hash
|
||||
$z = '';
|
||||
$i = $j = 0;
|
||||
while (strlen($z) < $d) {
|
||||
$z.= pack('P', $s[$i][$j++]);
|
||||
$z .= pack('P', $s[$i][$j++]);
|
||||
if ($j == 5) {
|
||||
$j = 0;
|
||||
$i++;
|
||||
@ -1276,7 +1276,7 @@ class Hash
|
||||
];
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
for ($j = 0; $j < 5; $j++) {
|
||||
$s[$i][$j]^= $temp[$j];
|
||||
$s[$i][$j] ^= $temp[$j];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1301,7 +1301,7 @@ class Hash
|
||||
}
|
||||
|
||||
// iota step
|
||||
$s[0][0]^= $roundConstants[$round];
|
||||
$s[0][0] ^= $roundConstants[$round];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1363,10 +1363,10 @@ class Hash
|
||||
// Pre-processing
|
||||
$length = strlen($m);
|
||||
// to round to nearest 112 mod 128, we'll add 128 - (length + (128 - 112)) % 128
|
||||
$m.= str_repeat(chr(0), 128 - (($length + 16) & 0x7F));
|
||||
$m .= str_repeat(chr(0), 128 - (($length + 16) & 0x7F));
|
||||
$m[$length] = chr(0x80);
|
||||
// we don't support hashing strings 512MB long
|
||||
$m.= pack('N4', 0, 0, 0, $length << 3);
|
||||
$m .= pack('N4', 0, 0, 0, $length << 3);
|
||||
|
||||
// Process the message in successive 1024-bit chunks
|
||||
$chunks = str_split($m, 128);
|
||||
|
@ -42,15 +42,18 @@ abstract class PublicKeyLoader
|
||||
{
|
||||
try {
|
||||
return EC::load($key, $password);
|
||||
} catch (NoKeyLoadedException $e) {}
|
||||
} catch (NoKeyLoadedException $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
return RSA::load($key, $password);
|
||||
} catch (NoKeyLoadedException $e) {}
|
||||
} catch (NoKeyLoadedException $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
return DSA::load($key, $password);
|
||||
} catch (NoKeyLoadedException $e) {}
|
||||
} catch (NoKeyLoadedException $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
$x509 = new X509();
|
||||
@ -59,7 +62,8 @@ abstract class PublicKeyLoader
|
||||
if ($key) {
|
||||
return $key;
|
||||
}
|
||||
} catch (\Exception $e) {}
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
throw new NoKeyLoadedException('Unable to read key');
|
||||
}
|
||||
|
@ -615,7 +615,7 @@ class RC2 extends BlockCipher
|
||||
$r3 += $keys[$r2 & 0x3F];';
|
||||
$limit = $actions[$limit];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$encrypt_block .= '$in = pack("v4", $r0, $r1, $r2, $r3);';
|
||||
|
||||
|
@ -425,7 +425,7 @@ abstract class RSA extends AsymmetricKey
|
||||
// coefficient INTEGER, -- (inverse of q) mod p
|
||||
// otherPrimeInfos OtherPrimeInfos OPTIONAL
|
||||
// }
|
||||
$privatekey = new PrivateKey;
|
||||
$privatekey = new PrivateKey();
|
||||
$privatekey->modulus = $n;
|
||||
$privatekey->k = $bits >> 3;
|
||||
$privatekey->publicExponent = $e;
|
||||
@ -456,8 +456,8 @@ abstract class RSA extends AsymmetricKey
|
||||
protected static function onLoad($components)
|
||||
{
|
||||
$key = $components['isPublicKey'] ?
|
||||
new PublicKey :
|
||||
new PrivateKey;
|
||||
new PublicKey() :
|
||||
new PrivateKey();
|
||||
|
||||
$key->modulus = $components['modulus'];
|
||||
$key->publicExponent = $components['publicExponent'];
|
||||
@ -603,7 +603,7 @@ abstract class RSA extends AsymmetricKey
|
||||
case 'sha512/256':
|
||||
$t = "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x06\x05\x00\x04\x20";
|
||||
}
|
||||
$t.= $h;
|
||||
$t .= $h;
|
||||
$tLen = strlen($t);
|
||||
|
||||
if ($emLen < $tLen + 11) {
|
||||
@ -663,7 +663,7 @@ abstract class RSA extends AsymmetricKey
|
||||
default:
|
||||
throw new UnsupportedAlgorithmException('md2 and md5 require NULLs');
|
||||
}
|
||||
$t.= $h;
|
||||
$t .= $h;
|
||||
$tLen = strlen($t);
|
||||
|
||||
if ($emLen < $tLen + 11) {
|
||||
@ -695,7 +695,7 @@ abstract class RSA extends AsymmetricKey
|
||||
$count = ceil($maskLen / $this->mgfHLen);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$c = pack('N', $i);
|
||||
$t.= $this->mgfHash->hash($mgfSeed . $c);
|
||||
$t .= $this->mgfHash->hash($mgfSeed . $c);
|
||||
}
|
||||
|
||||
return substr($t, 0, $maskLen);
|
||||
@ -793,7 +793,7 @@ abstract class RSA extends AsymmetricKey
|
||||
*/
|
||||
public function getMGFHash()
|
||||
{
|
||||
return clone $this->mgfHash;
|
||||
return clone $this->mgfHash;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -823,7 +823,7 @@ abstract class RSA extends AsymmetricKey
|
||||
*/
|
||||
public function getSaltLength()
|
||||
{
|
||||
return $this->sLen !== null ? $this->sLen : $this->hLen;
|
||||
return $this->sLen !== null ? $this->sLen : $this->hLen;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -855,7 +855,7 @@ abstract class RSA extends AsymmetricKey
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -917,7 +917,7 @@ abstract class RSA extends AsymmetricKey
|
||||
*/
|
||||
public function getPadding()
|
||||
{
|
||||
return $this->signaturePadding | $this->encryptionPadding;
|
||||
return $this->signaturePadding | $this->encryptionPadding;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -959,4 +959,4 @@ abstract class RSA extends AsymmetricKey
|
||||
{
|
||||
static::$enableBlinding = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -209,14 +209,14 @@ abstract class MSBLOB
|
||||
$n = strrev($n->toBytes());
|
||||
$e = str_pad(strrev($e->toBytes()), 4, "\0");
|
||||
$key = pack('aavV', chr(self::PRIVATEKEYBLOB), chr(2), 0, self::CALG_RSA_KEYX);
|
||||
$key.= pack('VVa*', self::RSA2, 8 * strlen($n), $e);
|
||||
$key.= $n;
|
||||
$key.= strrev($primes[1]->toBytes());
|
||||
$key.= strrev($primes[2]->toBytes());
|
||||
$key.= strrev($exponents[1]->toBytes());
|
||||
$key.= strrev($exponents[2]->toBytes());
|
||||
$key.= strrev($coefficients[2]->toBytes());
|
||||
$key.= strrev($d->toBytes());
|
||||
$key .= pack('VVa*', self::RSA2, 8 * strlen($n), $e);
|
||||
$key .= $n;
|
||||
$key .= strrev($primes[1]->toBytes());
|
||||
$key .= strrev($primes[2]->toBytes());
|
||||
$key .= strrev($exponents[1]->toBytes());
|
||||
$key .= strrev($exponents[2]->toBytes());
|
||||
$key .= strrev($coefficients[2]->toBytes());
|
||||
$key .= strrev($d->toBytes());
|
||||
|
||||
return Base64::encode($key);
|
||||
}
|
||||
@ -234,8 +234,8 @@ abstract class MSBLOB
|
||||
$n = strrev($n->toBytes());
|
||||
$e = str_pad(strrev($e->toBytes()), 4, "\0");
|
||||
$key = pack('aavV', chr(self::PUBLICKEYBLOB), chr(2), 0, self::CALG_RSA_KEYX);
|
||||
$key.= pack('VVa*', self::RSA1, 8 * strlen($n), $e);
|
||||
$key.= $n;
|
||||
$key .= pack('VVa*', self::RSA1, 8 * strlen($n), $e);
|
||||
$key .= $n;
|
||||
|
||||
return Base64::encode($key);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ abstract class PKCS1 extends Progenitor
|
||||
|
||||
$key = ASN1::asn1map($decoded[0], Maps\RSAPrivateKey::MAP);
|
||||
if (is_array($key)) {
|
||||
$components+= [
|
||||
$components += [
|
||||
'modulus' => $key['modulus'],
|
||||
'publicExponent' => $key['publicExponent'],
|
||||
'privateExponent' => $key['privateExponent'],
|
||||
|
@ -74,7 +74,7 @@ abstract class Raw
|
||||
|
||||
if (isset($key['primes'])) {
|
||||
$components['primes'] = $key['primes'];
|
||||
} else if (isset($key['p']) && isset($key['q'])) {
|
||||
} elseif (isset($key['p']) && isset($key['q'])) {
|
||||
$indices = [
|
||||
['p', 'q'],
|
||||
['prime1', 'prime2']
|
||||
@ -164,9 +164,15 @@ abstract class Raw
|
||||
'e' => clone $e,
|
||||
'n' => clone $n,
|
||||
'd' => clone $d,
|
||||
'primes' => array_map(function($var) { return clone $var; }, $primes),
|
||||
'exponents' => array_map(function($var) { return clone $var; }, $exponents),
|
||||
'coefficients' => array_map(function($var) { return clone $var; }, $coefficients)
|
||||
'primes' => array_map(function ($var) {
|
||||
return clone $var;
|
||||
}, $primes),
|
||||
'exponents' => array_map(function ($var) {
|
||||
return clone $var;
|
||||
}, $exponents),
|
||||
'coefficients' => array_map(function ($var) {
|
||||
return clone $var;
|
||||
}, $coefficients)
|
||||
];
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user