mirror of
https://github.com/danog/phpseclib.git
synced 2024-12-02 09:38:06 +01:00
Fix bad merge
This commit is contained in:
parent
3097d2940b
commit
0aff25ea25
@ -15,12 +15,13 @@
|
||||
|
||||
namespace phpseclib\Crypt\Common;
|
||||
|
||||
use phpseclib\Crypt\DSA;
|
||||
use phpseclib\Exception\UnsupportedFormatException;
|
||||
use phpseclib\Exception\NoKeyLoadedException;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Crypt\Hash;
|
||||
use phpseclib\Crypt\RSA;
|
||||
use phpseclib\Exception\NoKeyLoadedException;
|
||||
use phpseclib\Exception\UnsupportedFormatException;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Crypt\DSA;
|
||||
use phpseclib\Crypt\ECDSA;
|
||||
|
||||
/**
|
||||
* Base Class for all stream cipher classes
|
||||
@ -139,7 +140,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);
|
||||
}
|
||||
|
||||
@ -199,7 +200,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])) {
|
||||
@ -223,12 +224,12 @@ abstract class AsymmetricKey
|
||||
{
|
||||
if (!isset(self::$plugins[static::ALGORITHM][$format])) {
|
||||
self::$plugins[static::ALGORITHM][$format] = [];
|
||||
foreach (new \DirectoryIterator(__DIR__.'/../'.static::ALGORITHM.'/'.$format.'/') as $file) {
|
||||
foreach (new \DirectoryIterator(__DIR__ . '/../' . static::ALGORITHM . '/' . $format . '/') as $file) {
|
||||
if ($file->getExtension() != 'php') {
|
||||
continue;
|
||||
}
|
||||
$name = $file->getBasename('.php');
|
||||
$type = 'phpseclib\Crypt\\'.static::ALGORITHM.'\\'.$format.'\\'.$name;
|
||||
$type = 'phpseclib\Crypt\\' . static::ALGORITHM . '\\' . $format . '\\' . $name;
|
||||
$reflect = new \ReflectionClass($type);
|
||||
if ($reflect->isTrait()) {
|
||||
continue;
|
||||
@ -309,7 +310,7 @@ abstract class AsymmetricKey
|
||||
// this test can be satisfied by either of the following:
|
||||
// http://php.net/manual/en/book.sodium.php
|
||||
// https://github.com/paragonie/sodium_compat
|
||||
'libsodium' => function_exists('sodium_crypto_sign_keypair'),
|
||||
'libsodium' => function_exists('sodium_crypto_sign_keypair')
|
||||
];
|
||||
|
||||
return static::$engines;
|
||||
@ -325,7 +326,7 @@ abstract class AsymmetricKey
|
||||
static::$engines = [
|
||||
'PHP' => true,
|
||||
'OpenSSL' => false,
|
||||
'libsodium' => false,
|
||||
'libsodium' => false
|
||||
];
|
||||
}
|
||||
|
||||
@ -373,10 +374,10 @@ abstract class AsymmetricKey
|
||||
$h1 = $this->bits2octets($h1);
|
||||
|
||||
$this->hmac->setKey($k);
|
||||
$k = $this->hmac->hash($v."\0".$x.$h1);
|
||||
$k = $this->hmac->hash($v . "\0" . $x . $h1);
|
||||
$this->hmac->setKey($k);
|
||||
$v = $this->hmac->hash($v);
|
||||
$k = $this->hmac->hash($v."\1".$x.$h1);
|
||||
$k = $this->hmac->hash($v . "\1" . $x . $h1);
|
||||
$this->hmac->setKey($k);
|
||||
$v = $this->hmac->hash($v);
|
||||
|
||||
@ -386,14 +387,14 @@ abstract class AsymmetricKey
|
||||
$t = '';
|
||||
while (strlen($t) < $qlen) {
|
||||
$v = $this->hmac->hash($v);
|
||||
$t = $t.$v;
|
||||
$t = $t . $v;
|
||||
}
|
||||
$k = $this->bits2int($t);
|
||||
|
||||
if (!$k->equals(self::$zero) && $k->compare($this->q) < 0) {
|
||||
break;
|
||||
}
|
||||
$k = $this->hmac->hash($v."\0");
|
||||
$k = $this->hmac->hash($v . "\0");
|
||||
$this->hmac->setKey($k);
|
||||
$v = $this->hmac->hash($v);
|
||||
}
|
||||
|
@ -54,11 +54,12 @@
|
||||
|
||||
namespace phpseclib\Crypt;
|
||||
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
use phpseclib\Crypt\Common\BlockCipher;
|
||||
use phpseclib\Exception\BadDecryptionException;
|
||||
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
use phpseclib\Exception\BadModeException;
|
||||
use phpseclib\Exception\InsufficientSetupException;
|
||||
use phpseclib\Exception\BadDecryptionException;
|
||||
|
||||
/**
|
||||
* Pure-PHP implementation of Rijndael.
|
||||
@ -211,7 +212,7 @@ class Rijndael extends BlockCipher
|
||||
$this->key_length = $length >> 3;
|
||||
break;
|
||||
default:
|
||||
throw new \LengthException('Key size of '.$length.' bits is not supported by this algorithm. Only keys of sizes 128, 160, 192, 224 or 256 bits are supported');
|
||||
throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys of sizes 128, 160, 192, 224 or 256 bits are supported');
|
||||
}
|
||||
|
||||
parent::setKeyLength($length);
|
||||
@ -237,7 +238,7 @@ class Rijndael extends BlockCipher
|
||||
case 32:
|
||||
break;
|
||||
default:
|
||||
throw new \LengthException('Key of size '.strlen($key).' not supported by this algorithm. Only keys of sizes 16, 20, 24, 28 or 32 are supported');
|
||||
throw new \LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of sizes 16, 20, 24, 28 or 32 are supported');
|
||||
}
|
||||
|
||||
parent::setKey($key);
|
||||
@ -261,7 +262,7 @@ class Rijndael extends BlockCipher
|
||||
case 256:
|
||||
break;
|
||||
default:
|
||||
throw new \LengthException('Key size of '.$length.' bits is not supported by this algorithm. Only keys of sizes 128, 160, 192, 224 or 256 bits are supported');
|
||||
throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys of sizes 128, 160, 192, 224 or 256 bits are supported');
|
||||
}
|
||||
|
||||
$this->Nb = $length >> 5;
|
||||
@ -297,17 +298,17 @@ class Rijndael extends BlockCipher
|
||||
$methods = openssl_get_cipher_methods();
|
||||
return $this->mode == self::MODE_GCM &&
|
||||
version_compare(PHP_VERSION, '7.1.0', '>=') &&
|
||||
in_array('aes-'.$this->getKeyLength().'-gcm', $methods) &&
|
||||
in_array('aes-' . $this->getKeyLength() . '-gcm', $methods) &&
|
||||
$this->block_size == 16;
|
||||
case self::ENGINE_OPENSSL:
|
||||
if ($this->block_size != 16) {
|
||||
return false;
|
||||
}
|
||||
self::$cipher_name_openssl_ecb = 'aes-'.($this->key_length << 3).'-ecb';
|
||||
$this->cipher_name_openssl = 'aes-'.($this->key_length << 3).'-'.$this->openssl_translate_mode();
|
||||
self::$cipher_name_openssl_ecb = 'aes-' . ($this->key_length << 3) . '-ecb';
|
||||
$this->cipher_name_openssl = 'aes-' . ($this->key_length << 3) . '-' . $this->openssl_translate_mode();
|
||||
break;
|
||||
case self::ENGINE_MCRYPT:
|
||||
$this->cipher_name_mcrypt = 'rijndael-'.($this->block_size << 3);
|
||||
$this->cipher_name_mcrypt = 'rijndael-' . ($this->block_size << 3);
|
||||
if ($this->key_length % 8) { // is it a 160/224-bit key?
|
||||
// mcrypt is not usable for them, only for 128/192/256-bit keys
|
||||
return false;
|
||||
@ -502,7 +503,7 @@ class Rijndael extends BlockCipher
|
||||
0x6C000000, 0xD8000000, 0xAB000000, 0x4D000000, 0x9A000000,
|
||||
0x2F000000, 0x5E000000, 0xBC000000, 0x63000000, 0xC6000000,
|
||||
0x97000000, 0x35000000, 0x6A000000, 0xD4000000, 0xB3000000,
|
||||
0x7D000000, 0xFA000000, 0xEF000000, 0xC5000000, 0x91000000,
|
||||
0x7D000000, 0xFA000000, 0xEF000000, 0xC5000000, 0x91000000
|
||||
];
|
||||
|
||||
if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->key_length === $this->kl['key_length'] && $this->block_size === $this->kl['block_size']) {
|
||||
@ -669,7 +670,7 @@ class Rijndael extends BlockCipher
|
||||
0xE1E138D9, 0xF8F813EB, 0x9898B32B, 0x11113322, 0x6969BBD2, 0xD9D970A9, 0x8E8E8907, 0x9494A733,
|
||||
0x9B9BB62D, 0x1E1E223C, 0x87879215, 0xE9E920C9, 0xCECE4987, 0x5555FFAA, 0x28287850, 0xDFDF7AA5,
|
||||
0x8C8C8F03, 0xA1A1F859, 0x89898009, 0x0D0D171A, 0xBFBFDA65, 0xE6E631D7, 0x4242C684, 0x6868B8D0,
|
||||
0x4141C382, 0x9999B029, 0x2D2D775A, 0x0F0F111E, 0xB0B0CB7B, 0x5454FCA8, 0xBBBBD66D, 0x16163A2C,
|
||||
0x4141C382, 0x9999B029, 0x2D2D775A, 0x0F0F111E, 0xB0B0CB7B, 0x5454FCA8, 0xBBBBD66D, 0x16163A2C
|
||||
]);
|
||||
|
||||
foreach ($t3 as $t3i) {
|
||||
@ -701,8 +702,8 @@ class Rijndael extends BlockCipher
|
||||
0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
|
||||
0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
|
||||
0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
|
||||
0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16,
|
||||
],
|
||||
0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
|
||||
]
|
||||
];
|
||||
}
|
||||
return $tables;
|
||||
@ -753,7 +754,7 @@ class Rijndael extends BlockCipher
|
||||
0xD7618C9A, 0xA10C7A37, 0xF8148E59, 0x133C89EB, 0xA927EECE, 0x61C935B7, 0x1CE5EDE1, 0x47B13C7A,
|
||||
0xD2DF599C, 0xF2733F55, 0x14CE7918, 0xC737BF73, 0xF7CDEA53, 0xFDAA5B5F, 0x3D6F14DF, 0x44DB8678,
|
||||
0xAFF381CA, 0x68C43EB9, 0x24342C38, 0xA3405FC2, 0x1DC37216, 0xE2250CBC, 0x3C498B28, 0x0D9541FF,
|
||||
0xA8017139, 0x0CB3DE08, 0xB4E49CD8, 0x56C19064, 0xCB84617B, 0x32B670D5, 0x6C5C7448, 0xB85742D0,
|
||||
0xA8017139, 0x0CB3DE08, 0xB4E49CD8, 0x56C19064, 0xCB84617B, 0x32B670D5, 0x6C5C7448, 0xB85742D0
|
||||
]);
|
||||
|
||||
foreach ($dt3 as $dt3i) {
|
||||
@ -785,8 +786,8 @@ class Rijndael extends BlockCipher
|
||||
0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
|
||||
0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
|
||||
0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
|
||||
0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D,
|
||||
],
|
||||
0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
|
||||
]
|
||||
];
|
||||
}
|
||||
return $tables;
|
||||
@ -810,7 +811,7 @@ class Rijndael extends BlockCipher
|
||||
$c = $this->c;
|
||||
|
||||
// Generating encrypt code:
|
||||
$init_encrypt .= '
|
||||
$init_encrypt.= '
|
||||
static $tables;
|
||||
if (empty($tables)) {
|
||||
$tables = &$this->getTables();
|
||||
@ -836,9 +837,9 @@ class Rijndael extends BlockCipher
|
||||
for ($round = 1; $round < $Nr; ++$round) {
|
||||
list($s, $e) = [$e, $s];
|
||||
for ($i = 0; $i < $Nb; ++$i) {
|
||||
$encrypt_block .=
|
||||
$encrypt_block.=
|
||||
'$'.$e.$i.' =
|
||||
$t0[($'.$s.$i.' >> 24) & 0xff] ^
|
||||
$t0[($'.$s.$i .' >> 24) & 0xff] ^
|
||||
$t1[($'.$s.(($i + $c[1]) % $Nb).' >> 16) & 0xff] ^
|
||||
$t2[($'.$s.(($i + $c[2]) % $Nb).' >> 8) & 0xff] ^
|
||||
$t3[ $'.$s.(($i + $c[3]) % $Nb).' & 0xff] ^
|
||||
@ -848,7 +849,7 @@ class Rijndael extends BlockCipher
|
||||
|
||||
// Finalround: subWord + shiftRows + addRoundKey
|
||||
for ($i = 0; $i < $Nb; ++$i) {
|
||||
$encrypt_block .=
|
||||
$encrypt_block.=
|
||||
'$'.$e.$i.' =
|
||||
$sbox[ $'.$e.$i.' & 0xff] |
|
||||
($sbox[($'.$e.$i.' >> 8) & 0xff] << 8) |
|
||||
@ -857,8 +858,8 @@ class Rijndael extends BlockCipher
|
||||
}
|
||||
$encrypt_block .= '$in = pack("N*"'."\n";
|
||||
for ($i = 0; $i < $Nb; ++$i) {
|
||||
$encrypt_block .= ',
|
||||
($'.$e.$i.' & '.((int) 0xFF000000).') ^
|
||||
$encrypt_block.= ',
|
||||
($'.$e.$i .' & '.((int)0xFF000000).') ^
|
||||
($'.$e.(($i + $c[1]) % $Nb).' & 0x00FF0000 ) ^
|
||||
($'.$e.(($i + $c[2]) % $Nb).' & 0x0000FF00 ) ^
|
||||
($'.$e.(($i + $c[3]) % $Nb).' & 0x000000FF ) ^
|
||||
@ -867,7 +868,7 @@ class Rijndael extends BlockCipher
|
||||
$encrypt_block .= ');';
|
||||
|
||||
// Generating decrypt code:
|
||||
$init_decrypt .= '
|
||||
$init_decrypt.= '
|
||||
static $invtables;
|
||||
if (empty($invtables)) {
|
||||
$invtables = &$this->getInvTables();
|
||||
@ -893,9 +894,9 @@ class Rijndael extends BlockCipher
|
||||
for ($round = 1; $round < $Nr; ++$round) {
|
||||
list($s, $e) = [$e, $s];
|
||||
for ($i = 0; $i < $Nb; ++$i) {
|
||||
$decrypt_block .=
|
||||
$decrypt_block.=
|
||||
'$'.$e.$i.' =
|
||||
$dt0[($'.$s.$i.' >> 24) & 0xff] ^
|
||||
$dt0[($'.$s.$i .' >> 24) & 0xff] ^
|
||||
$dt1[($'.$s.(($Nb + $i - $c[1]) % $Nb).' >> 16) & 0xff] ^
|
||||
$dt2[($'.$s.(($Nb + $i - $c[2]) % $Nb).' >> 8) & 0xff] ^
|
||||
$dt3[ $'.$s.(($Nb + $i - $c[3]) % $Nb).' & 0xff] ^
|
||||
@ -905,7 +906,7 @@ class Rijndael extends BlockCipher
|
||||
|
||||
// Finalround: subWord + shiftRows + addRoundKey
|
||||
for ($i = 0; $i < $Nb; ++$i) {
|
||||
$decrypt_block .=
|
||||
$decrypt_block.=
|
||||
'$'.$e.$i.' =
|
||||
$isbox[ $'.$e.$i.' & 0xff] |
|
||||
($isbox[($'.$e.$i.' >> 8) & 0xff] << 8) |
|
||||
@ -914,8 +915,8 @@ class Rijndael extends BlockCipher
|
||||
}
|
||||
$decrypt_block .= '$in = pack("N*"'."\n";
|
||||
for ($i = 0; $i < $Nb; ++$i) {
|
||||
$decrypt_block .= ',
|
||||
($'.$e.$i.' & '.((int) 0xFF000000).') ^
|
||||
$decrypt_block.= ',
|
||||
($'.$e.$i. ' & '.((int)0xFF000000).') ^
|
||||
($'.$e.(($Nb + $i - $c[1]) % $Nb).' & 0x00FF0000 ) ^
|
||||
($'.$e.(($Nb + $i - $c[2]) % $Nb).' & 0x0000FF00 ) ^
|
||||
($'.$e.(($Nb + $i - $c[3]) % $Nb).' & 0x000000FF ) ^
|
||||
@ -929,7 +930,7 @@ class Rijndael extends BlockCipher
|
||||
'init_encrypt' => $init_encrypt,
|
||||
'init_decrypt' => $init_decrypt,
|
||||
'encrypt_block' => $encrypt_block,
|
||||
'decrypt_block' => $decrypt_block,
|
||||
'decrypt_block' => $decrypt_block
|
||||
]
|
||||
);
|
||||
}
|
||||
@ -954,7 +955,7 @@ class Rijndael extends BlockCipher
|
||||
case self::ENGINE_OPENSSL_GCM:
|
||||
return openssl_encrypt(
|
||||
$plaintext,
|
||||
'aes-'.$this->getKeyLength().'-gcm',
|
||||
'aes-' . $this->getKeyLength() . '-gcm',
|
||||
$this->key,
|
||||
OPENSSL_RAW_DATA,
|
||||
$this->nonce,
|
||||
@ -987,7 +988,7 @@ class Rijndael extends BlockCipher
|
||||
if (strlen($this->oldtag) != 16) {
|
||||
break;
|
||||
}
|
||||
$plaintext = sodium_crypto_aead_aes256gcm_decrypt($ciphertext.$this->oldtag, $this->aad, $this->nonce, $this->key);
|
||||
$plaintext = sodium_crypto_aead_aes256gcm_decrypt($ciphertext . $this->oldtag, $this->aad, $this->nonce, $this->key);
|
||||
if ($plaintext === false) {
|
||||
$this->oldtag = false;
|
||||
throw new BadDecryptionException('Error decrypting ciphertext with libsodium');
|
||||
@ -999,7 +1000,7 @@ class Rijndael extends BlockCipher
|
||||
}
|
||||
$plaintext = openssl_decrypt(
|
||||
$ciphertext,
|
||||
'aes-'.$this->getKeyLength().'-gcm',
|
||||
'aes-' . $this->getKeyLength() . '-gcm',
|
||||
$this->key,
|
||||
OPENSSL_RAW_DATA,
|
||||
$this->nonce,
|
||||
|
@ -81,7 +81,7 @@ class BigInteger implements \Serializable
|
||||
{
|
||||
self::$engines = [];
|
||||
|
||||
$fqmain = 'phpseclib\\Math\\BigInteger\\Engines\\'.$main;
|
||||
$fqmain = 'phpseclib\\Math\\BigInteger\\Engines\\' . $main;
|
||||
if (!class_exists($fqmain) || !method_exists($fqmain, 'isValidEngine')) {
|
||||
throw new \InvalidArgumentException("$main is not a valid engine");
|
||||
}
|
||||
@ -135,7 +135,7 @@ class BigInteger implements \Serializable
|
||||
['GMP'],
|
||||
['PHP64', ['OpenSSL']],
|
||||
['BCMath', ['OpenSSL']],
|
||||
['PHP32', ['OpenSSL']],
|
||||
['PHP32', ['OpenSSL']]
|
||||
];
|
||||
foreach ($engines as $engine) {
|
||||
try {
|
||||
@ -230,7 +230,7 @@ class BigInteger implements \Serializable
|
||||
* @param bool $twos_compliment
|
||||
* @return string
|
||||
*/
|
||||
public function toBits($twos_compliment = false)
|
||||
function toBits($twos_compliment = false)
|
||||
{
|
||||
return $this->value->toBits($twos_compliment);
|
||||
}
|
||||
@ -252,7 +252,7 @@ class BigInteger implements \Serializable
|
||||
* @param BigInteger $y
|
||||
* @return BigInteger
|
||||
*/
|
||||
public function subtract(BigInteger $y)
|
||||
function subtract(BigInteger $y)
|
||||
{
|
||||
return new static($this->value->subtract($y->value));
|
||||
}
|
||||
@ -298,7 +298,7 @@ class BigInteger implements \Serializable
|
||||
list($q, $r) = $this->value->divide($y->value);
|
||||
return [
|
||||
new static($q),
|
||||
new static($r),
|
||||
new static($r)
|
||||
];
|
||||
}
|
||||
|
||||
@ -332,7 +332,7 @@ class BigInteger implements \Serializable
|
||||
return [
|
||||
'gcd' => new static($gcd),
|
||||
'x' => new static($x),
|
||||
'y' => new static($y),
|
||||
'y' => new static($y)
|
||||
];
|
||||
}
|
||||
|
||||
@ -598,7 +598,7 @@ class BigInteger implements \Serializable
|
||||
*/
|
||||
return [
|
||||
'min' => new static($min),
|
||||
'max' => new static($max),
|
||||
'max' => new static($max)
|
||||
];
|
||||
}
|
||||
|
||||
@ -733,10 +733,10 @@ class BigInteger implements \Serializable
|
||||
* @param BigInteger[] $nums
|
||||
* @return BigInteger
|
||||
*/
|
||||
public static function min(BigInteger...$nums)
|
||||
public static function min(BigInteger ...$nums)
|
||||
{
|
||||
$class = self::$mainEngine;
|
||||
$nums = array_map(function ($num) {return $num->value;}, $nums);
|
||||
$nums = array_map(function($num) { return $num->value; }, $nums);
|
||||
return new static($class::min(...$nums));
|
||||
}
|
||||
|
||||
@ -746,10 +746,10 @@ class BigInteger implements \Serializable
|
||||
* @param BigInteger[] $nums
|
||||
* @return BigInteger
|
||||
*/
|
||||
public static function max(BigInteger...$nums)
|
||||
public static function max(BigInteger ...$nums)
|
||||
{
|
||||
$class = self::$mainEngine;
|
||||
$nums = array_map(function ($num) {return $num->value;}, $nums);
|
||||
$nums = array_map(function($num) { return $num->value; }, $nums);
|
||||
return new static($class::max(...$nums));
|
||||
}
|
||||
|
||||
@ -841,7 +841,7 @@ class BigInteger implements \Serializable
|
||||
public function createRecurringModuloFunction()
|
||||
{
|
||||
$func = $this->value->createRecurringModuloFunction();
|
||||
return function (BigInteger $x) use ($func) {
|
||||
return function(BigInteger $x) use ($func) {
|
||||
return new static($func($x->value));
|
||||
};
|
||||
}
|
||||
@ -856,7 +856,7 @@ class BigInteger implements \Serializable
|
||||
*/
|
||||
public function bitwise_split($split)
|
||||
{
|
||||
return array_map(function ($val) {
|
||||
return array_map(function($val) {
|
||||
return new static($val);
|
||||
}, $this->value->bitwise_split($split));
|
||||
}
|
||||
|
@ -16,10 +16,10 @@
|
||||
namespace phpseclib\Math\BigInteger\Engines;
|
||||
|
||||
use ParagonIE\ConstantTime\Hex;
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
use phpseclib\Crypt\Random;
|
||||
use phpseclib\Exception\BadConfigurationException;
|
||||
use phpseclib\Crypt\Random;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
|
||||
/**
|
||||
* Base Engine.
|
||||
@ -85,7 +85,7 @@ abstract class Engine implements \Serializable
|
||||
619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727,
|
||||
733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829,
|
||||
839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947,
|
||||
953, 967, 971, 977, 983, 991, 997,
|
||||
953, 967, 971, 977, 983, 991, 997
|
||||
];
|
||||
static::$zero = new static(0);
|
||||
static::$one = new static(1);
|
||||
@ -180,7 +180,7 @@ abstract class Engine implements \Serializable
|
||||
*/
|
||||
public static function setModExpEngine($engine)
|
||||
{
|
||||
$fqengine = '\\phpseclib\\Math\\BigInteger\\Engines\\'.static::ENGINE_DIR.'\\'.$engine;
|
||||
$fqengine = '\\phpseclib\\Math\\BigInteger\\Engines\\' . static::ENGINE_DIR . '\\' . $engine;
|
||||
if (!class_exists($fqengine) || !method_exists($fqengine, 'isValidEngine')) {
|
||||
throw new \InvalidArgumentException("$engine is not a valid engine");
|
||||
}
|
||||
@ -212,7 +212,7 @@ abstract class Engine implements \Serializable
|
||||
}
|
||||
|
||||
if (ord($bytes[0]) & 0x80) {
|
||||
$bytes = chr(0).$bytes;
|
||||
$bytes = chr(0) . $bytes;
|
||||
}
|
||||
|
||||
return $comparison < 0 ? ~$bytes : $bytes;
|
||||
@ -246,7 +246,7 @@ abstract class Engine implements \Serializable
|
||||
$result = $this->precision > 0 ? substr($bits, -$this->precision) : ltrim($bits, '0');
|
||||
|
||||
if ($twos_compliment && $this->compare(new static()) > 0 && $this->precision <= 0) {
|
||||
return '0'.$result;
|
||||
return '0' . $result;
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -340,8 +340,8 @@ abstract class Engine implements \Serializable
|
||||
public function __debugInfo()
|
||||
{
|
||||
return [
|
||||
'value' => '0x'.$this->toHex(true),
|
||||
'engine' => basename(static::class),
|
||||
'value' => '0x' . $this->toHex(true),
|
||||
'engine' => basename(static::class)
|
||||
];
|
||||
}
|
||||
|
||||
@ -388,7 +388,7 @@ abstract class Engine implements \Serializable
|
||||
*/
|
||||
protected static function setBitmask($bits)
|
||||
{
|
||||
return new static(chr((1 << ($bits & 0x7)) - 1).str_repeat(chr(0xFF), $bits >> 3), 256);
|
||||
return new static(chr((1 << ($bits & 0x7)) - 1) . str_repeat(chr(0xFF), $bits >> 3), 256);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -420,7 +420,7 @@ abstract class Engine implements \Serializable
|
||||
}
|
||||
|
||||
// generate as many leading 1's as we need to.
|
||||
$leading_ones = chr((1 << ($new_bits & 0x7)) - 1).str_repeat(chr(0xFF), $new_bits >> 3);
|
||||
$leading_ones = chr((1 << ($new_bits & 0x7)) - 1) . str_repeat(chr(0xFF), $new_bits >> 3);
|
||||
|
||||
self::base256_lshift($leading_ones, $current_bits);
|
||||
|
||||
@ -454,7 +454,7 @@ abstract class Engine implements \Serializable
|
||||
$carry = $temp >> 8;
|
||||
}
|
||||
$carry = ($carry != 0) ? chr($carry) : '';
|
||||
$x = $carry.$x.str_repeat(chr(0), $num_bytes);
|
||||
$x = $carry . $x . str_repeat(chr(0), $num_bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -482,13 +482,13 @@ abstract class Engine implements \Serializable
|
||||
for ($i = 0; $temp >> $i; ++$i) {
|
||||
}
|
||||
$precision = 8 * strlen($bits) - 8 + $i;
|
||||
$mask = chr((1 << ($precision & 0x7)) - 1).str_repeat(chr(0xFF), $precision >> 3);
|
||||
$mask = chr((1 << ($precision & 0x7)) - 1) . str_repeat(chr(0xFF), $precision >> 3);
|
||||
}
|
||||
|
||||
if ($shift < 0) {
|
||||
$shift += $precision;
|
||||
$shift+= $precision;
|
||||
}
|
||||
$shift %= $precision;
|
||||
$shift%= $precision;
|
||||
|
||||
if (!$shift) {
|
||||
return clone $this;
|
||||
@ -527,14 +527,14 @@ abstract class Engine implements \Serializable
|
||||
$max = str_repeat(chr(0xFF), $bytes);
|
||||
$msb = $bits & 7;
|
||||
if ($msb) {
|
||||
$min = chr(1 << ($msb - 1)).$min;
|
||||
$max = chr((1 << $msb) - 1).$max;
|
||||
$min = chr(1 << ($msb - 1)) . $min;
|
||||
$max = chr((1 << $msb) - 1) . $max;
|
||||
} else {
|
||||
$min[0] = chr(0x80);
|
||||
}
|
||||
return [
|
||||
'min' => new static($min, 256),
|
||||
'max' => new static($max, 256),
|
||||
'max' => new static($max, 256)
|
||||
];
|
||||
}
|
||||
|
||||
@ -770,7 +770,7 @@ abstract class Engine implements \Serializable
|
||||
|
||||
http://crypto.stackexchange.com/questions/5708/creating-a-small-number-from-a-cryptographically-secure-random-string
|
||||
*/
|
||||
$random_max = new static(chr(1).str_repeat("\0", $size), 256);
|
||||
$random_max = new static(chr(1) . str_repeat("\0", $size), 256);
|
||||
$random = new static(Random::string($size), 256);
|
||||
|
||||
list($max_multiple) = $random_max->divide($max);
|
||||
@ -848,18 +848,18 @@ abstract class Engine implements \Serializable
|
||||
|
||||
// see HAC 4.49 "Note (controlling the error probability)"
|
||||
// @codingStandardsIgnoreStart
|
||||
if ($length >= 163) {$t = 2;} // floor(1300 / 8)
|
||||
else if ($length >= 106) {$t = 3;} // floor( 850 / 8)
|
||||
else if ($length >= 81) {$t = 4;} // floor( 650 / 8)
|
||||
else if ($length >= 68) {$t = 5;} // floor( 550 / 8)
|
||||
else if ($length >= 56) {$t = 6;} // floor( 450 / 8)
|
||||
else if ($length >= 50) {$t = 7;} // floor( 400 / 8)
|
||||
else if ($length >= 43) {$t = 8;} // floor( 350 / 8)
|
||||
else if ($length >= 37) {$t = 9;} // floor( 300 / 8)
|
||||
else if ($length >= 31) {$t = 12;} // floor( 250 / 8)
|
||||
else if ($length >= 25) {$t = 15;} // floor( 200 / 8)
|
||||
else if ($length >= 18) {$t = 18;} // floor( 150 / 8)
|
||||
else { $t = 27;}
|
||||
if ($length >= 163) { $t = 2; } // floor(1300 / 8)
|
||||
else if ($length >= 106) { $t = 3; } // floor( 850 / 8)
|
||||
else if ($length >= 81 ) { $t = 4; } // floor( 650 / 8)
|
||||
else if ($length >= 68 ) { $t = 5; } // floor( 550 / 8)
|
||||
else if ($length >= 56 ) { $t = 6; } // floor( 450 / 8)
|
||||
else if ($length >= 50 ) { $t = 7; } // floor( 400 / 8)
|
||||
else if ($length >= 43 ) { $t = 8; } // floor( 350 / 8)
|
||||
else if ($length >= 37 ) { $t = 9; } // floor( 300 / 8)
|
||||
else if ($length >= 31 ) { $t = 12; } // floor( 250 / 8)
|
||||
else if ($length >= 25 ) { $t = 15; } // floor( 200 / 8)
|
||||
else if ($length >= 18 ) { $t = 18; } // floor( 150 / 8)
|
||||
else { $t = 27; }
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
return $t;
|
||||
@ -1068,11 +1068,11 @@ abstract class Engine implements \Serializable
|
||||
$class = static::class;
|
||||
|
||||
$fqengine = !method_exists(static::$modexpEngine, 'reduce') ?
|
||||
'\\phpseclib\\Math\\BigInteger\\Engines\\'.static::ENGINE_DIR.'\\DefaultEngine' :
|
||||
'\\phpseclib\\Math\\BigInteger\\Engines\\' . static::ENGINE_DIR . '\\DefaultEngine' :
|
||||
static::$modexpEngine;
|
||||
if (method_exists($fqengine, 'generateCustomReduction')) {
|
||||
$func = $fqengine::generateCustomReduction($this, static::class);
|
||||
$this->reduce = eval('return function('.static::class.' $x) use ($func, $class) {
|
||||
$this->reduce = eval('return function(' . static::class . ' $x) use ($func, $class) {
|
||||
$r = new $class();
|
||||
$r->value = $func($x->value);
|
||||
return $r;
|
||||
@ -1080,7 +1080,7 @@ abstract class Engine implements \Serializable
|
||||
return clone $this->reduce;
|
||||
}
|
||||
$n = $this->value;
|
||||
$this->reduce = eval('return function('.static::class.' $x) use ($n, $fqengine, $class) {
|
||||
$this->reduce = eval('return function(' . static::class . ' $x) use ($n, $fqengine, $class) {
|
||||
$r = new $class();
|
||||
$r->value = $fqengine::reduce($x->value, $n, $class);
|
||||
return $r;
|
||||
@ -1124,9 +1124,9 @@ abstract class Engine implements \Serializable
|
||||
}
|
||||
|
||||
return [
|
||||
'gcd' => $u,
|
||||
'gcd'=> $u,
|
||||
'x' => $a,
|
||||
'y' => $b,
|
||||
'y' => $b
|
||||
];
|
||||
}
|
||||
|
||||
@ -1208,6 +1208,7 @@ abstract class Engine implements \Serializable
|
||||
|
||||
$length = max(strlen($left), strlen($right));
|
||||
|
||||
|
||||
$left = str_pad($left, $length, chr(0), STR_PAD_LEFT);
|
||||
$right = str_pad($right, $length, chr(0), STR_PAD_LEFT);
|
||||
return $this->normalize(new static($left ^ $right, -256));
|
||||
|
@ -85,7 +85,7 @@ abstract class PHP extends Engine
|
||||
static::$isValidEngine = static::isValidEngine();
|
||||
}
|
||||
if (!static::$isValidEngine) {
|
||||
throw new BadConfigurationException(static::class.' is not setup correctly on this system');
|
||||
throw new BadConfigurationException(static::class . ' is not setup correctly on this system');
|
||||
}
|
||||
|
||||
$this->value = [];
|
||||
@ -102,7 +102,7 @@ abstract class PHP extends Engine
|
||||
{
|
||||
switch (abs($base)) {
|
||||
case 16:
|
||||
$x = (strlen($this->value) & 1) ? '0'.$this->value : $this->value;
|
||||
$x = (strlen($this->value) & 1) ? '0' . $this->value : $this->value;
|
||||
$temp = new static(Hex::decode($x), 256);
|
||||
$this->value = $temp->value;
|
||||
break;
|
||||
@ -164,7 +164,7 @@ abstract class PHP extends Engine
|
||||
$result = '';
|
||||
while (count($temp->value)) {
|
||||
list($temp, $mod) = $temp->divide($divisor);
|
||||
$result = str_pad(isset($mod->value[0]) ? $mod->value[0] : '', static::MAX10LEN, '0', STR_PAD_LEFT).$result;
|
||||
$result = str_pad(isset($mod->value[0]) ? $mod->value[0] : '', static::MAX10LEN, '0', STR_PAD_LEFT) . $result;
|
||||
}
|
||||
$result = ltrim($result, '0');
|
||||
if (empty($result)) {
|
||||
@ -172,7 +172,7 @@ abstract class PHP extends Engine
|
||||
}
|
||||
|
||||
if ($this->is_negative) {
|
||||
$result = '-'.$result;
|
||||
$result = '-' . $result;
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -219,12 +219,12 @@ abstract class PHP extends Engine
|
||||
if ($x_size == 0) {
|
||||
return [
|
||||
self::VALUE => $y_value,
|
||||
self::SIGN => $y_negative,
|
||||
self::SIGN => $y_negative
|
||||
];
|
||||
} elseif ($y_size == 0) {
|
||||
return [
|
||||
self::VALUE => $x_value,
|
||||
self::SIGN => $x_negative,
|
||||
self::SIGN => $x_negative
|
||||
];
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@ abstract class PHP extends Engine
|
||||
if ($x_value == $y_value) {
|
||||
return [
|
||||
self::VALUE => [],
|
||||
self::SIGN => false,
|
||||
self::SIGN => false
|
||||
];
|
||||
}
|
||||
|
||||
@ -255,22 +255,22 @@ abstract class PHP extends Engine
|
||||
$value[count($value)] = 0; // just in case the carry adds an extra digit
|
||||
|
||||
$carry = 0;
|
||||
for ($i = 0, $j = 1; $j < $size; $i += 2, $j += 2) {
|
||||
for ($i = 0, $j = 1; $j < $size; $i+=2, $j+=2) {
|
||||
//$sum = $x_value[$j] * static::BASE_FULL + $x_value[$i] + $y_value[$j] * static::BASE_FULL + $y_value[$i] + $carry;
|
||||
$sum = ($x_value[$j] + $y_value[$j]) * static::BASE_FULL + $x_value[$i] + $y_value[$i] + $carry;
|
||||
$carry = $sum >= static::MAX_DIGIT2; // eg. floor($sum / 2**52); only possible values (in any base) are 0 and 1
|
||||
$sum = $carry ? $sum-static::MAX_DIGIT2 : $sum;
|
||||
$sum = $carry ? $sum - static::MAX_DIGIT2 : $sum;
|
||||
|
||||
$temp = static::BASE === 26 ? intval($sum / 0x4000000) : ($sum >> 31);
|
||||
|
||||
$value[$i] = (int) ($sum-static::BASE_FULL * $temp); // eg. a faster alternative to fmod($sum, 0x4000000)
|
||||
$value[$i] = (int) ($sum - static::BASE_FULL * $temp); // eg. a faster alternative to fmod($sum, 0x4000000)
|
||||
$value[$j] = $temp;
|
||||
}
|
||||
|
||||
if ($j == $size) { // ie. if $y_size is odd
|
||||
$sum = $x_value[$i] + $y_value[$i] + $carry;
|
||||
$carry = $sum >= static::BASE_FULL;
|
||||
$value[$i] = $carry ? $sum-static::BASE_FULL : $sum;
|
||||
$value[$i] = $carry ? $sum - static::BASE_FULL : $sum;
|
||||
++$i; // ie. let $i = $j since we've just done $value[$i]
|
||||
}
|
||||
|
||||
@ -283,7 +283,7 @@ abstract class PHP extends Engine
|
||||
|
||||
return [
|
||||
self::VALUE => self::trim($value),
|
||||
self::SIGN => $x_negative,
|
||||
self::SIGN => $x_negative
|
||||
];
|
||||
}
|
||||
|
||||
@ -296,7 +296,7 @@ abstract class PHP extends Engine
|
||||
* @param bool $y_negative
|
||||
* @return array
|
||||
*/
|
||||
public static function subtractHelper(array $x_value, $x_negative, array $y_value, $y_negative)
|
||||
static function subtractHelper(array $x_value, $x_negative, array $y_value, $y_negative)
|
||||
{
|
||||
$x_size = count($x_value);
|
||||
$y_size = count($y_value);
|
||||
@ -304,12 +304,12 @@ abstract class PHP extends Engine
|
||||
if ($x_size == 0) {
|
||||
return [
|
||||
self::VALUE => $y_value,
|
||||
self::SIGN => !$y_negative,
|
||||
self::SIGN => !$y_negative
|
||||
];
|
||||
} elseif ($y_size == 0) {
|
||||
return [
|
||||
self::VALUE => $x_value,
|
||||
self::SIGN => $x_negative,
|
||||
self::SIGN => $x_negative
|
||||
];
|
||||
}
|
||||
|
||||
@ -326,7 +326,7 @@ abstract class PHP extends Engine
|
||||
if (!$diff) {
|
||||
return [
|
||||
self::VALUE => [],
|
||||
self::SIGN => false,
|
||||
self::SIGN => false
|
||||
];
|
||||
}
|
||||
|
||||
@ -345,27 +345,27 @@ abstract class PHP extends Engine
|
||||
// at this point, $x_value should be at least as big as - if not bigger than - $y_value
|
||||
|
||||
$carry = 0;
|
||||
for ($i = 0, $j = 1; $j < $y_size; $i += 2, $j += 2) {
|
||||
for ($i = 0, $j = 1; $j < $y_size; $i+=2, $j+=2) {
|
||||
$sum = ($x_value[$j] - $y_value[$j]) * static::BASE_FULL + $x_value[$i] - $y_value[$i] - $carry;
|
||||
|
||||
$carry = $sum < 0; // eg. floor($sum / 2**52); only possible values (in any base) are 0 and 1
|
||||
$sum = $carry ? $sum+static::MAX_DIGIT2 : $sum;
|
||||
$sum = $carry ? $sum + static::MAX_DIGIT2 : $sum;
|
||||
|
||||
$temp = static::BASE === 26 ? intval($sum / 0x4000000) : ($sum >> 31);
|
||||
|
||||
$x_value[$i] = (int) ($sum-static::BASE_FULL * $temp);
|
||||
$x_value[$i] = (int) ($sum - static::BASE_FULL * $temp);
|
||||
$x_value[$j] = $temp;
|
||||
}
|
||||
|
||||
if ($j == $y_size) { // ie. if $y_size is odd
|
||||
$sum = $x_value[$i] - $y_value[$i] - $carry;
|
||||
$carry = $sum < 0;
|
||||
$x_value[$i] = $carry ? $sum+static::BASE_FULL : $sum;
|
||||
$x_value[$i] = $carry ? $sum + static::BASE_FULL : $sum;
|
||||
++$i;
|
||||
}
|
||||
|
||||
if ($carry) {
|
||||
for (;!$x_value[$i]; ++$i) {
|
||||
for (; !$x_value[$i]; ++$i) {
|
||||
$x_value[$i] = static::MAX_DIGIT;
|
||||
}
|
||||
--$x_value[$i];
|
||||
@ -373,7 +373,7 @@ abstract class PHP extends Engine
|
||||
|
||||
return [
|
||||
self::VALUE => self::trim($x_value),
|
||||
self::SIGN => $x_negative,
|
||||
self::SIGN => $x_negative
|
||||
];
|
||||
}
|
||||
|
||||
@ -401,7 +401,7 @@ abstract class PHP extends Engine
|
||||
if (!$x_length || !$y_length) { // a 0 is being multiplied
|
||||
return [
|
||||
self::VALUE => [],
|
||||
self::SIGN => false,
|
||||
self::SIGN => false
|
||||
];
|
||||
}
|
||||
|
||||
@ -409,7 +409,7 @@ abstract class PHP extends Engine
|
||||
self::VALUE => min($x_length, $y_length) < 2 * self::KARATSUBA_CUTOFF ?
|
||||
self::trim(self::regularMultiply($x_value, $y_value)) :
|
||||
self::trim(self::karatsuba($x_value, $y_value)),
|
||||
self::SIGN => $x_negative != $y_negative,
|
||||
self::SIGN => $x_negative != $y_negative
|
||||
];
|
||||
}
|
||||
|
||||
@ -484,7 +484,7 @@ abstract class PHP extends Engine
|
||||
for ($j = 0; $j < $x_length; ++$j) { // ie. $i = 0
|
||||
$temp = $x_value[$j] * $y_value[0] + $carry; // $product_value[$k] == 0
|
||||
$carry = static::BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
|
||||
$product_value[$j] = (int) ($temp-static::BASE_FULL * $carry);
|
||||
$product_value[$j] = (int) ($temp - static::BASE_FULL * $carry);
|
||||
}
|
||||
|
||||
$product_value[$j] = $carry;
|
||||
@ -497,7 +497,7 @@ abstract class PHP extends Engine
|
||||
for ($j = 0, $k = $i; $j < $x_length; ++$j, ++$k) {
|
||||
$temp = $product_value[$k] + $x_value[$j] * $y_value[$i] + $carry;
|
||||
$carry = static::BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
|
||||
$product_value[$k] = (int) ($temp-static::BASE_FULL * $carry);
|
||||
$product_value[$k] = (int) ($temp - static::BASE_FULL * $carry);
|
||||
}
|
||||
|
||||
$product_value[$k] = $carry;
|
||||
@ -557,7 +557,7 @@ abstract class PHP extends Engine
|
||||
|
||||
// normalize $x and $y as described in HAC 14.23 / 14.24
|
||||
$msb = $y->value[count($y->value) - 1];
|
||||
for ($shift = 0;!($msb & static::MSB); ++$shift) {
|
||||
for ($shift = 0; !($msb & static::MSB); ++$shift) {
|
||||
$msb <<= 1;
|
||||
}
|
||||
$x->lshift($shift);
|
||||
@ -595,11 +595,11 @@ abstract class PHP extends Engine
|
||||
$x_window = [
|
||||
isset($x_value[$i]) ? $x_value[$i] : 0,
|
||||
isset($x_value[$i - 1]) ? $x_value[$i - 1] : 0,
|
||||
isset($x_value[$i - 2]) ? $x_value[$i - 2] : 0,
|
||||
isset($x_value[$i - 2]) ? $x_value[$i - 2] : 0
|
||||
];
|
||||
$y_window = [
|
||||
$y_value[$y_max],
|
||||
($y_max > 0) ? $y_value[$y_max - 1] : 0,
|
||||
($y_max > 0) ? $y_value[$y_max - 1] : 0
|
||||
];
|
||||
|
||||
$q_index = $i - $y_max - 1;
|
||||
@ -1002,13 +1002,13 @@ abstract class PHP extends Engine
|
||||
|
||||
$temp = $square_value[$i2] + $value[$i] * $value[$i];
|
||||
$carry = static::BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
|
||||
$square_value[$i2] = (int) ($temp-static::BASE_FULL * $carry);
|
||||
$square_value[$i2] = (int) ($temp - static::BASE_FULL * $carry);
|
||||
|
||||
// note how we start from $i+1 instead of 0 as we do in multiplication.
|
||||
for ($j = $i + 1, $k = $i2 + 1; $j <= $max_index; ++$j, ++$k) {
|
||||
$temp = $square_value[$k] + 2 * $value[$j] * $value[$i] + $carry;
|
||||
$carry = static::BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
|
||||
$square_value[$k] = (int) ($temp-static::BASE_FULL * $carry);
|
||||
$square_value[$k] = (int) ($temp - static::BASE_FULL * $carry);
|
||||
}
|
||||
|
||||
// the following line can yield values larger 2**15. at this point, PHP should switch
|
||||
@ -1227,7 +1227,7 @@ abstract class PHP extends Engine
|
||||
$digit = [];
|
||||
if (!$overflow) {
|
||||
$digit = array_slice($val, $i, $width);
|
||||
$i += $width;
|
||||
$i+= $width;
|
||||
$overflow = $split % static::BASE;
|
||||
if ($overflow) {
|
||||
$mask = (1 << $overflow) - 1;
|
||||
@ -1239,7 +1239,7 @@ abstract class PHP extends Engine
|
||||
$tempsplit = $split - $remaining;
|
||||
$tempwidth = (int) ($tempsplit / static::BASE + 1);
|
||||
$digit = array_slice($val, $i, $tempwidth);
|
||||
$i += $tempwidth;
|
||||
$i+= $tempwidth;
|
||||
$tempoverflow = $tempsplit % static::BASE;
|
||||
if ($tempoverflow) {
|
||||
$tempmask = (1 << $tempoverflow) - 1;
|
||||
@ -1282,9 +1282,9 @@ abstract class PHP extends Engine
|
||||
$remaining = static::BASE;
|
||||
while ($i != $len) {
|
||||
$digit = $val[$i] & $mask;
|
||||
$val[$i] >>= $split;
|
||||
$val[$i]>>= $split;
|
||||
if (!$overflow) {
|
||||
$remaining -= $split;
|
||||
$remaining-= $split;
|
||||
$overflow = $split <= $remaining ? 0 : $split - $remaining;
|
||||
|
||||
if (!$remaining) {
|
||||
@ -1294,8 +1294,8 @@ abstract class PHP extends Engine
|
||||
}
|
||||
} else if (++$i != $len) {
|
||||
$tempmask = (1 << $overflow) - 1;
|
||||
$digit |= ($val[$i] & $tempmask) << $remaining;
|
||||
$val[$i] >>= $overflow;
|
||||
$digit|= ($val[$i] & $tempmask) << $remaining;
|
||||
$val[$i]>>= $overflow;
|
||||
$remaining = static::BASE - $overflow;
|
||||
$overflow = $split <= $remaining ? 0 : $split - $remaining;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user