diff --git a/composer.json b/composer.json index bd21bbd1..972dd184 100644 --- a/composer.json +++ b/composer.json @@ -66,6 +66,9 @@ "Net": "phpseclib/", "System": "phpseclib/" }, + "psr-4": { + "phpseclib\\": "phpseclib/" + }, "files": [ "phpseclib/Crypt/Random.php" ] diff --git a/composer.lock b/composer.lock index f7485126..736cebfc 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "9550e007a60e2baceebf1185d508dd00", + "hash": "1c5f986d03274ed0b7d509768d1bf277", "packages": [ ], diff --git a/phpseclib/Crypt/Hash.php b/phpseclib/Crypt/Hash.php index 8123d33b..54606d85 100644 --- a/phpseclib/Crypt/Hash.php +++ b/phpseclib/Crypt/Hash.php @@ -54,6 +54,8 @@ * @link http://phpseclib.sourceforge.net */ +use \phpseclib\Math\BigInteger; + /**#@+ * @access private * @see Crypt_Hash::Crypt_Hash() @@ -579,10 +581,6 @@ class Crypt_Hash */ function _sha512($m) { - if (!class_exists('Math_BigInteger')) { - include_once 'Math/BigInteger.php'; - } - static $init384, $init512, $k; if (!isset($k)) { @@ -597,9 +595,9 @@ class Crypt_Hash ); for ($i = 0; $i < 8; $i++) { - $init384[$i] = new Math_BigInteger($init384[$i], 16); + $init384[$i] = new BigInteger($init384[$i], 16); $init384[$i]->setPrecision(64); - $init512[$i] = new Math_BigInteger($init512[$i], 16); + $init512[$i] = new BigInteger($init512[$i], 16); $init512[$i]->setPrecision(64); } @@ -629,7 +627,7 @@ class Crypt_Hash ); for ($i = 0; $i < 80; $i++) { - $k[$i] = new Math_BigInteger($k[$i], 16); + $k[$i] = new BigInteger($k[$i], 16); } } @@ -648,7 +646,7 @@ class Crypt_Hash foreach ($chunks as $chunk) { $w = array(); for ($i = 0; $i < 16; $i++) { - $temp = new Math_BigInteger($this->_string_shift($chunk, 8), 256); + $temp = new BigInteger($this->_string_shift($chunk, 8), 256); $temp->setPrecision(64); $w[] = $temp; } @@ -802,7 +800,7 @@ class Crypt_Hash * Add * * _sha256() adds multiple unsigned 32-bit integers. Since PHP doesn't support unsigned integers and since the - * possibility of overflow exists, care has to be taken. Math_BigInteger() could be used but this should be faster. + * possibility of overflow exists, care has to be taken. BigInteger could be used but this should be faster. * * @param Integer $... * @return Integer diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 68243b00..56b7a84e 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -67,6 +67,8 @@ * @link http://phpseclib.sourceforge.net */ +use \phpseclib\Math\BigInteger; + /** * Include Crypt_Random */ @@ -201,7 +203,7 @@ define('CRYPT_RSA_PRIVATE_FORMAT_XML', 2); /** * Raw public key * - * An array containing two Math_BigInteger objects. + * An array containing two \phpseclib\Math\BigInteger objects. * * The exponent can be indexed with any of the following: * @@ -280,7 +282,7 @@ class Crypt_RSA /** * Modulus (ie. n) * - * @var Math_BigInteger + * @var \phpseclib\Math\BigInteger * @access private */ var $modulus; @@ -288,7 +290,7 @@ class Crypt_RSA /** * Modulus length * - * @var Math_BigInteger + * @var \phpseclib\Math\BigInteger * @access private */ var $k; @@ -296,7 +298,7 @@ class Crypt_RSA /** * Exponent (ie. e or d) * - * @var Math_BigInteger + * @var \phpseclib\Math\BigInteger * @access private */ var $exponent; @@ -459,10 +461,6 @@ class Crypt_RSA */ function Crypt_RSA() { - if (!class_exists('Math_BigInteger')) { - include_once 'Math/BigInteger.php'; - } - $this->configFile = CRYPT_RSA_OPENSSL_CONFIG; if ( !defined('CRYPT_RSA_MODE') ) { @@ -507,8 +505,8 @@ class Crypt_RSA } } - $this->zero = new Math_BigInteger(); - $this->one = new Math_BigInteger(1); + $this->zero = new BigInteger(); + $this->one = new BigInteger(1); $this->hash = new Crypt_Hash('sha1'); $this->hLen = $this->hash->getLength(); @@ -529,7 +527,7 @@ class Crypt_RSA * @access public * @param optional Integer $bits * @param optional Integer $timeout - * @param optional Math_BigInteger $p + * @param optional array $p */ function createKey($bits = 1024, $timeout = false, $partial = array()) { @@ -573,7 +571,7 @@ class Crypt_RSA static $e; if (!isset($e)) { - $e = new Math_BigInteger(CRYPT_RSA_EXPONENT); + $e = new BigInteger(CRYPT_RSA_EXPONENT); } extract($this->_generateMinMax($bits)); @@ -589,7 +587,7 @@ class Crypt_RSA $finalMax = $max; extract($this->_generateMinMax($temp)); - $generator = new Math_BigInteger(); + $generator = new BigInteger(); $n = $this->one->copy(); if (!empty($partial)) { @@ -1100,10 +1098,10 @@ class Crypt_RSA $length = $this->_decodeLength($key); $temp = $this->_string_shift($key, $length); if (strlen($temp) != 1 || ord($temp) > 2) { - $components['modulus'] = new Math_BigInteger($temp, 256); + $components['modulus'] = new BigInteger($temp, 256); $this->_string_shift($key); // skip over CRYPT_RSA_ASN1_INTEGER $length = $this->_decodeLength($key); - $components[$type == CRYPT_RSA_PUBLIC_FORMAT_PKCS1 ? 'publicExponent' : 'privateExponent'] = new Math_BigInteger($this->_string_shift($key, $length), 256); + $components[$type == CRYPT_RSA_PUBLIC_FORMAT_PKCS1 ? 'publicExponent' : 'privateExponent'] = new BigInteger($this->_string_shift($key, $length), 256); return $components; } @@ -1111,28 +1109,28 @@ class Crypt_RSA return false; } $length = $this->_decodeLength($key); - $components['modulus'] = new Math_BigInteger($this->_string_shift($key, $length), 256); + $components['modulus'] = new BigInteger($this->_string_shift($key, $length), 256); $this->_string_shift($key); $length = $this->_decodeLength($key); - $components['publicExponent'] = new Math_BigInteger($this->_string_shift($key, $length), 256); + $components['publicExponent'] = new BigInteger($this->_string_shift($key, $length), 256); $this->_string_shift($key); $length = $this->_decodeLength($key); - $components['privateExponent'] = new Math_BigInteger($this->_string_shift($key, $length), 256); + $components['privateExponent'] = new BigInteger($this->_string_shift($key, $length), 256); $this->_string_shift($key); $length = $this->_decodeLength($key); - $components['primes'] = array(1 => new Math_BigInteger($this->_string_shift($key, $length), 256)); + $components['primes'] = array(1 => new BigInteger($this->_string_shift($key, $length), 256)); $this->_string_shift($key); $length = $this->_decodeLength($key); - $components['primes'][] = new Math_BigInteger($this->_string_shift($key, $length), 256); + $components['primes'][] = new BigInteger($this->_string_shift($key, $length), 256); $this->_string_shift($key); $length = $this->_decodeLength($key); - $components['exponents'] = array(1 => new Math_BigInteger($this->_string_shift($key, $length), 256)); + $components['exponents'] = array(1 => new BigInteger($this->_string_shift($key, $length), 256)); $this->_string_shift($key); $length = $this->_decodeLength($key); - $components['exponents'][] = new Math_BigInteger($this->_string_shift($key, $length), 256); + $components['exponents'][] = new BigInteger($this->_string_shift($key, $length), 256); $this->_string_shift($key); $length = $this->_decodeLength($key); - $components['coefficients'] = array(2 => new Math_BigInteger($this->_string_shift($key, $length), 256)); + $components['coefficients'] = array(2 => new BigInteger($this->_string_shift($key, $length), 256)); if (!empty($key)) { if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) { @@ -1146,13 +1144,13 @@ class Crypt_RSA $this->_decodeLength($key); $key = substr($key, 1); $length = $this->_decodeLength($key); - $components['primes'][] = new Math_BigInteger($this->_string_shift($key, $length), 256); + $components['primes'][] = new BigInteger($this->_string_shift($key, $length), 256); $this->_string_shift($key); $length = $this->_decodeLength($key); - $components['exponents'][] = new Math_BigInteger($this->_string_shift($key, $length), 256); + $components['exponents'][] = new BigInteger($this->_string_shift($key, $length), 256); $this->_string_shift($key); $length = $this->_decodeLength($key); - $components['coefficients'][] = new Math_BigInteger($this->_string_shift($key, $length), 256); + $components['coefficients'][] = new BigInteger($this->_string_shift($key, $length), 256); } } @@ -1173,19 +1171,19 @@ class Crypt_RSA return false; } extract(unpack('Nlength', $this->_string_shift($key, 4))); - $publicExponent = new Math_BigInteger($this->_string_shift($key, $length), -256); + $publicExponent = new BigInteger($this->_string_shift($key, $length), -256); if (strlen($key) <= 4) { return false; } extract(unpack('Nlength', $this->_string_shift($key, 4))); - $modulus = new Math_BigInteger($this->_string_shift($key, $length), -256); + $modulus = new BigInteger($this->_string_shift($key, $length), -256); if ($cleanup && strlen($key)) { if (strlen($key) <= 4) { return false; } extract(unpack('Nlength', $this->_string_shift($key, 4))); - $realModulus = new Math_BigInteger($this->_string_shift($key, $length), -256); + $realModulus = new BigInteger($this->_string_shift($key, $length), -256); return strlen($key) ? false : array( 'modulus' => $realModulus, 'publicExponent' => $modulus, @@ -1229,9 +1227,9 @@ class Crypt_RSA $public = base64_decode(implode('', array_map('trim', array_slice($key, 4, $publicLength)))); $public = substr($public, 11); extract(unpack('Nlength', $this->_string_shift($public, 4))); - $components['publicExponent'] = new Math_BigInteger($this->_string_shift($public, $length), -256); + $components['publicExponent'] = new BigInteger($this->_string_shift($public, $length), -256); extract(unpack('Nlength', $this->_string_shift($public, 4))); - $components['modulus'] = new Math_BigInteger($this->_string_shift($public, $length), -256); + $components['modulus'] = new BigInteger($this->_string_shift($public, $length), -256); $privateLength = trim(preg_replace('#Private-Lines: (\d+)#', '$1', $key[$publicLength + 4])); $private = base64_decode(implode('', array_map('trim', array_slice($key, $publicLength + 5, $privateLength)))); @@ -1264,17 +1262,17 @@ class Crypt_RSA if (strlen($private) < $length) { return false; } - $components['privateExponent'] = new Math_BigInteger($this->_string_shift($private, $length), -256); + $components['privateExponent'] = new BigInteger($this->_string_shift($private, $length), -256); extract(unpack('Nlength', $this->_string_shift($private, 4))); if (strlen($private) < $length) { return false; } - $components['primes'] = array(1 => new Math_BigInteger($this->_string_shift($private, $length), -256)); + $components['primes'] = array(1 => new BigInteger($this->_string_shift($private, $length), -256)); extract(unpack('Nlength', $this->_string_shift($private, 4))); if (strlen($private) < $length) { return false; } - $components['primes'][] = new Math_BigInteger($this->_string_shift($private, $length), -256); + $components['primes'][] = new BigInteger($this->_string_shift($private, $length), -256); $temp = $components['primes'][1]->subtract($this->one); $components['exponents'] = array(1 => $components['publicExponent']->modInverse($temp)); @@ -1285,7 +1283,7 @@ class Crypt_RSA if (strlen($private) < $length) { return false; } - $components['coefficients'] = array(2 => new Math_BigInteger($this->_string_shift($private, $length), -256)); + $components['coefficients'] = array(2 => new BigInteger($this->_string_shift($private, $length), -256)); return $components; } @@ -1357,7 +1355,7 @@ class Crypt_RSA function _stop_element_handler($parser, $name) { if (isset($this->current)) { - $this->current = new Math_BigInteger(base64_decode($this->current), 256); + $this->current = new BigInteger(base64_decode($this->current), 256); unset($this->current); } } @@ -1729,8 +1727,8 @@ class Crypt_RSA } return array( - 'min' => new Math_BigInteger($min, 256), - 'max' => new Math_BigInteger($max, 256) + 'min' => new BigInteger($min, 256), + 'max' => new BigInteger($max, 256) ); } @@ -1894,7 +1892,7 @@ class Crypt_RSA * See {@link http://tools.ietf.org/html/rfc3447#section-4.1 RFC3447#section-4.1}. * * @access private - * @param Math_BigInteger $x + * @param \phpseclib\Math\BigInteger $x * @param Integer $xLen * @return String */ @@ -1915,11 +1913,11 @@ class Crypt_RSA * * @access private * @param String $x - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger */ function _os2ip($x) { - return new Math_BigInteger($x, 256); + return new BigInteger($x, 256); } /** @@ -1928,8 +1926,8 @@ class Crypt_RSA * See {@link http://tools.ietf.org/html/rfc3447#section-5.1.1 RFC3447#section-5.1.2}. * * @access private - * @param Math_BigInteger $x - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $x + * @return \phpseclib\Math\BigInteger */ function _exponentiate($x) { @@ -1969,7 +1967,7 @@ class Crypt_RSA } } - $one = new Math_BigInteger(1); + $one = new BigInteger(1); $r = $one->random($one, $smallest->subtract($one)); @@ -2006,10 +2004,10 @@ class Crypt_RSA * Returns $x->modPow($this->exponents[$i], $this->primes[$i]) * * @access private - * @param Math_BigInteger $x - * @param Math_BigInteger $r + * @param \phpseclib\Math\BigInteger $x + * @param \phpseclib\Math\BigInteger $r * @param Integer $i - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger */ function _blind($x, $r, $i) { @@ -2057,8 +2055,8 @@ class Crypt_RSA * See {@link http://tools.ietf.org/html/rfc3447#section-5.1.1 RFC3447#section-5.1.1}. * * @access private - * @param Math_BigInteger $m - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $m + * @return \phpseclib\Math\BigInteger */ function _rsaep($m) { @@ -2075,8 +2073,8 @@ class Crypt_RSA * See {@link http://tools.ietf.org/html/rfc3447#section-5.1.2 RFC3447#section-5.1.2}. * * @access private - * @param Math_BigInteger $c - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $c + * @return \phpseclib\Math\BigInteger */ function _rsadp($c) { @@ -2093,8 +2091,8 @@ class Crypt_RSA * See {@link http://tools.ietf.org/html/rfc3447#section-5.2.1 RFC3447#section-5.2.1}. * * @access private - * @param Math_BigInteger $m - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $m + * @return \phpseclib\Math\BigInteger */ function _rsasp1($m) { @@ -2111,8 +2109,8 @@ class Crypt_RSA * See {@link http://tools.ietf.org/html/rfc3447#section-5.2.2 RFC3447#section-5.2.2}. * * @access private - * @param Math_BigInteger $s - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $s + * @return \phpseclib\Math\BigInteger */ function _rsavp1($s) { diff --git a/phpseclib/File/ASN1.php b/phpseclib/File/ASN1.php index 2774e7e8..8fe51018 100644 --- a/phpseclib/File/ASN1.php +++ b/phpseclib/File/ASN1.php @@ -39,6 +39,8 @@ * @link http://phpseclib.sourceforge.net */ +use \phpseclib\Math\BigInteger; + /**#@+ * Tag Classes * @@ -240,22 +242,6 @@ class File_ASN1 FILE_ASN1_TYPE_VISIBLE_STRING => 1, ); - /** - * Default Constructor. - * - * @access public - */ - function File_ASN1() - { - static $static_init = null; - if (!$static_init) { - $static_init = true; - if (!class_exists('Math_BigInteger')) { - include_once 'Math/BigInteger.php'; - } - } - } - /** * Parse BER-encoding * @@ -377,7 +363,7 @@ class File_ASN1 break; case FILE_ASN1_TYPE_INTEGER: case FILE_ASN1_TYPE_ENUMERATED: - $current['content'] = new Math_BigInteger($content, -256); + $current['content'] = new BigInteger($content, -256); break; case FILE_ASN1_TYPE_REAL: // not currently supported return false; @@ -773,7 +759,7 @@ class File_ASN1 case FILE_ASN1_TYPE_ENUMERATED: $temp = $decoded['content']; if (isset($mapping['implicit'])) { - $temp = new Math_BigInteger($decoded['content'], -256); + $temp = new BigInteger($decoded['content'], -256); } if (isset($mapping['mapping'])) { $temp = (int) $temp->toString(); @@ -951,7 +937,7 @@ class File_ASN1 case FILE_ASN1_TYPE_ENUMERATED: if (!isset($mapping['mapping'])) { if (is_numeric($source)) { - $source = new Math_BigInteger($source); + $source = new BigInteger($source); } $value = $source->toBytes(true); } else { @@ -959,7 +945,7 @@ class File_ASN1 if ($value === false) { return false; } - $value = new Math_BigInteger($value); + $value = new BigInteger($value); $value = $value->toBytes(true); } if (!strlen($value)) { @@ -1044,7 +1030,7 @@ class File_ASN1 case !isset($source): return $this->_encode_der(null, array('type' => FILE_ASN1_TYPE_NULL) + $mapping, null, $special); case is_int($source): - case is_object($source) && strtolower(get_class($source)) == 'math_biginteger': + case $source instanceof \phpseclib\Math\BigInteger: return $this->_encode_der($source, array('type' => FILE_ASN1_TYPE_INTEGER) + $mapping, null, $special); case is_float($source): return $this->_encode_der($source, array('type' => FILE_ASN1_TYPE_REAL) + $mapping, null, $special); diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index e8c001aa..53c57249 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -305,10 +305,6 @@ class File_X509 */ function File_X509() { - if (!class_exists('Math_BigInteger')) { - include_once 'Math/BigInteger.php'; - } - // Explicitly Tagged Module, 1988 Syntax // http://tools.ietf.org/html/rfc5280#appendix-A.1 @@ -971,7 +967,7 @@ class File_X509 'constant' => 0, 'optional' => true, 'implicit' => true, - 'default' => new Math_BigInteger(0) + 'default' => new BigInteger(0) ) + $BaseDistance, 'maximum' => array( 'constant' => 1, @@ -3197,7 +3193,7 @@ class File_X509 $startDate = !empty($this->startDate) ? $this->startDate : @date('D, d M Y H:i:s O'); $endDate = !empty($this->endDate) ? $this->endDate : @date('D, d M Y H:i:s O', strtotime('+1 year')); - $serialNumber = !empty($this->serialNumber) ? $this->serialNumber : new Math_BigInteger(); + $serialNumber = !empty($this->serialNumber) ? $this->serialNumber : new BigInteger(); $this->currentCert = array( 'tbsCertificate' => @@ -3421,7 +3417,7 @@ class File_X509 $crlNumber = $this->serialNumber; } else { $crlNumber = $this->getExtension('id-ce-cRLNumber'); - $crlNumber = $crlNumber !== false ? $crlNumber->add(new Math_BigInteger(1)) : null; + $crlNumber = $crlNumber !== false ? $crlNumber->add(new BigInteger(1)) : null; } $this->removeExtension('id-ce-authorityKeyIdentifier'); @@ -3572,7 +3568,7 @@ class File_X509 */ function setSerialNumber($serial, $base = -256) { - $this->serialNumber = new Math_BigInteger($serial, $base); + $this->serialNumber = new BigInteger($serial, $base); } /** @@ -4219,7 +4215,7 @@ class File_X509 */ function _revokedCertificate(&$rclist, $serial, $create = false) { - $serial = new Math_BigInteger($serial); + $serial = new BigInteger($serial); foreach ($rclist as $i => $rc) { if (!($serial->compare($rc['userCertificate']))) { diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index e7635ea2..1ed9e216 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -11,7 +11,7 @@ * {@internal (all DocBlock comments regarding implementation - such as the one that follows - refer to the * {@link MATH_BIGINTEGER_MODE_INTERNAL MATH_BIGINTEGER_MODE_INTERNAL} mode) * - * Math_BigInteger uses base-2**26 to perform operations such as multiplication and division and + * BigInteger uses base-2**26 to perform operations such as multiplication and division and * base-2**52 (ie. two base 2**26 digits) to perform addition and subtraction. Because the largest possible * value when multiplying two base-2**26 numbers together is a base-2**52 number, double precision floating * point numbers - numbers that should be supported on most hardware and whose significand is 53 bits - are @@ -20,7 +20,7 @@ * base is being used should more than compensate. * * Numbers are stored in {@link http://en.wikipedia.org/wiki/Endianness little endian} format. ie. - * (new Math_BigInteger(pow(2, 26)))->value = array(0, 1) + * (new \phpseclib\Math\BigInteger(pow(2, 26)))->value = array(0, 1) * * Useful resources are as follows: * @@ -31,10 +31,8 @@ * Here's an example of how to use this library: * * add($b); * @@ -68,31 +66,33 @@ * @link http://pear.php.net/package/Math_BigInteger */ +namespace phpseclib\Math; + /**#@+ * Reduction constants * * @access private - * @see Math_BigInteger::_reduce() + * @see BigInteger::_reduce() */ /** - * @see Math_BigInteger::_montgomery() - * @see Math_BigInteger::_prepMontgomery() + * @see BigInteger::_montgomery() + * @see BigInteger::_prepMontgomery() */ define('MATH_BIGINTEGER_MONTGOMERY', 0); /** - * @see Math_BigInteger::_barrett() + * @see BigInteger::_barrett() */ define('MATH_BIGINTEGER_BARRETT', 1); /** - * @see Math_BigInteger::_mod2() + * @see BigInteger::_mod2() */ define('MATH_BIGINTEGER_POWEROF2', 2); /** - * @see Math_BigInteger::_remainder() + * @see BigInteger::_remainder() */ define('MATH_BIGINTEGER_CLASSIC', 3); /** - * @see Math_BigInteger::__clone() + * @see BigInteger::__clone() */ define('MATH_BIGINTEGER_NONE', 4); /**#@-*/ @@ -100,7 +100,7 @@ define('MATH_BIGINTEGER_NONE', 4); /**#@+ * Array constants * - * Rather than create a thousands and thousands of new Math_BigInteger objects in repeated function calls to add() and + * Rather than create a thousands and thousands of new BigInteger objects in repeated function calls to add() and * multiply() or whatever, we'll just work directly on arrays, taking them in as parameters and returning them. * * @access private @@ -117,8 +117,8 @@ define('MATH_BIGINTEGER_SIGN', 1); /**#@+ * @access private - * @see Math_BigInteger::_montgomery() - * @see Math_BigInteger::_barrett() + * @see BigInteger::_montgomery() + * @see BigInteger::_barrett() */ /** * Cache constants @@ -136,7 +136,7 @@ define('MATH_BIGINTEGER_DATA', 1); * Mode constants. * * @access private - * @see Math_BigInteger::Math_BigInteger() + * @see BigInteger::__construct() */ /** * To use the pure-PHP implementation @@ -173,7 +173,7 @@ define('MATH_BIGINTEGER_KARATSUBA_CUTOFF', 25); * @author Jim Wigginton * @access public */ -class Math_BigInteger +class BigInteger { /** * Holds the BigInteger's value. @@ -237,9 +237,7 @@ class Math_BigInteger * Here's an example: * * toString(); // outputs 50 * ?> @@ -247,10 +245,10 @@ class Math_BigInteger * * @param optional $x base-10 number or base-$base number if $base set. * @param optional integer $base - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger * @access public */ - function Math_BigInteger($x = 0, $base = 10) + function __construct($x = 0, $base = 10) { if ( !defined('MATH_BIGINTEGER_MODE') ) { switch (true) { @@ -386,7 +384,7 @@ class Math_BigInteger if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL) { $this->is_negative = false; } - $temp = $this->add(new Math_BigInteger('-1')); + $temp = $this->add(new static('-1')); $this->value = $temp->value; } break; @@ -413,18 +411,18 @@ class Math_BigInteger break; case MATH_BIGINTEGER_MODE_BCMATH: $x = ( strlen($x) & 1 ) ? '0' . $x : $x; - $temp = new Math_BigInteger(pack('H*', $x), 256); + $temp = new static(pack('H*', $x), 256); $this->value = $this->is_negative ? '-' . $temp->value : $temp->value; $this->is_negative = false; break; default: $x = ( strlen($x) & 1 ) ? '0' . $x : $x; - $temp = new Math_BigInteger(pack('H*', $x), 256); + $temp = new static(pack('H*', $x), 256); $this->value = $temp->value; } if ($is_negative) { - $temp = $this->add(new Math_BigInteger('-1')); + $temp = $this->add(new static('-1')); $this->value = $temp->value; } break; @@ -445,9 +443,9 @@ class Math_BigInteger $this->value = $x === '-' ? '0' : (string) $x; break; default: - $temp = new Math_BigInteger(); + $temp = new static(); - $multiplier = new Math_BigInteger(); + $multiplier = new static(); $multiplier->value = array(MATH_BIGINTEGER_MAX10); if ($x[0] == '-') { @@ -458,7 +456,7 @@ class Math_BigInteger $x = str_pad($x, strlen($x) + ((MATH_BIGINTEGER_MAX10_LEN - 1) * strlen($x)) % MATH_BIGINTEGER_MAX10_LEN, 0, STR_PAD_LEFT); while (strlen($x)) { $temp = $temp->multiply($multiplier); - $temp = $temp->add(new Math_BigInteger($this->_int2bytes(substr($x, 0, MATH_BIGINTEGER_MAX10_LEN)), 256)); + $temp = $temp->add(new static($this->_int2bytes(substr($x, 0, MATH_BIGINTEGER_MAX10_LEN)), 256)); $x = substr($x, MATH_BIGINTEGER_MAX10_LEN); } @@ -486,7 +484,7 @@ class Math_BigInteger $str = '-' . $str; } - $temp = new Math_BigInteger($str, 8 * $base); // ie. either -16 or +16 + $temp = new static($str, 8 * $base); // ie. either -16 or +16 $this->value = $temp->value; $this->is_negative = $temp->is_negative; @@ -505,9 +503,7 @@ class Math_BigInteger * Here's an example: * * toBytes(); // outputs chr(65) * ?> @@ -521,12 +517,12 @@ class Math_BigInteger function toBytes($twos_compliment = false) { if ($twos_compliment) { - $comparison = $this->compare(new Math_BigInteger()); + $comparison = $this->compare(new static()); if ($comparison == 0) { return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : ''; } - $temp = $comparison < 0 ? $this->add(new Math_BigInteger(1)) : $this->copy(); + $temp = $comparison < 0 ? $this->add(new static(1)) : $this->copy(); $bytes = $temp->toBytes(); if (empty($bytes)) { // eg. if the number we're trying to convert is -1 @@ -602,9 +598,7 @@ class Math_BigInteger * Here's an example: * * toHex(); // outputs '41' * ?> @@ -629,9 +623,7 @@ class Math_BigInteger * Here's an example: * * toBits(); // outputs '1000001' * ?> @@ -654,7 +646,7 @@ class Math_BigInteger } $result = $this->precision > 0 ? substr($bits, -$this->precision) : ltrim($bits, '0'); - if ($twos_compliment && $this->compare(new Math_BigInteger()) > 0 && $this->precision <= 0) { + if ($twos_compliment && $this->compare(new static()) > 0 && $this->precision <= 0) { return '0' . $result; } @@ -667,9 +659,7 @@ class Math_BigInteger * Here's an example: * * toString(); // outputs 50 * ?> @@ -699,7 +689,7 @@ class Math_BigInteger $temp = $this->copy(); $temp->is_negative = false; - $divisor = new Math_BigInteger(); + $divisor = new static(); $divisor->value = array(MATH_BIGINTEGER_MAX10); $result = ''; while (count($temp->value)) { @@ -728,11 +718,11 @@ class Math_BigInteger * * @access public * @see __clone() - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger */ function copy() { - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = $this->value; $temp->is_negative = $this->is_negative; $temp->generator = $this->generator; @@ -758,14 +748,14 @@ class Math_BigInteger /** * __clone() magic method * - * Although you can call Math_BigInteger::__toString() directly in PHP5, you cannot call Math_BigInteger::__clone() - * directly in PHP5. You can in PHP4 since it's not a magic method, but in PHP5, you have to call it by using the PHP5 - * only syntax of $y = clone $x. As such, if you're trying to write an application that works on both PHP4 and PHP5, - * call Math_BigInteger::copy(), instead. + * Although you can call BigInteger::__toString() directly in PHP5, you cannot call BigInteger::__clone() directly + * in PHP5. You can in PHP4 since it's not a magic method, but in PHP5, you have to call it by using the PHP5 + * only syntax of $y = clone $x. As such, if you're trying to write an application that works on both PHP4 and + * PHP5, call BigInteger::copy(), instead. * * @access public * @see copy() - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger */ function __clone() { @@ -775,7 +765,7 @@ class Math_BigInteger /** * __sleep() magic method * - * Will be called, automatically, when serialize() is called on a Math_BigInteger object. + * Will be called, automatically, when serialize() is called on a BigInteger object. * * @see __wakeup() * @access public @@ -797,14 +787,14 @@ class Math_BigInteger /** * __wakeup() magic method * - * Will be called, automatically, when unserialize() is called on a Math_BigInteger object. + * Will be called, automatically, when unserialize() is called on a BigInteger object. * * @see __sleep() * @access public */ function __wakeup() { - $temp = new Math_BigInteger($this->hex, -16); + $temp = new static($this->hex, -16); $this->value = $temp->value; $this->is_negative = $temp->is_negative; if ($this->precision > 0) { @@ -819,10 +809,8 @@ class Math_BigInteger * Here's an example: * * add($b); * @@ -830,8 +818,8 @@ class Math_BigInteger * ?> * * - * @param Math_BigInteger $y - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $y + * @return \phpseclib\Math\BigInteger * @access public * @internal Performs base-2**52 addition */ @@ -839,12 +827,12 @@ class Math_BigInteger { switch ( MATH_BIGINTEGER_MODE ) { case MATH_BIGINTEGER_MODE_GMP: - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = gmp_add($this->value, $y->value); return $this->_normalize($temp); case MATH_BIGINTEGER_MODE_BCMATH: - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = bcadd($this->value, $y->value, 0); return $this->_normalize($temp); @@ -852,7 +840,7 @@ class Math_BigInteger $temp = $this->_add($this->value, $this->is_negative, $y->value, $y->is_negative); - $result = new Math_BigInteger(); + $result = new static(); $result->value = $temp[MATH_BIGINTEGER_VALUE]; $result->is_negative = $temp[MATH_BIGINTEGER_SIGN]; @@ -950,10 +938,8 @@ class Math_BigInteger * Here's an example: * * subtract($b); * @@ -961,8 +947,8 @@ class Math_BigInteger * ?> * * - * @param Math_BigInteger $y - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $y + * @return \phpseclib\Math\BigInteger * @access public * @internal Performs base-2**52 subtraction */ @@ -970,12 +956,12 @@ class Math_BigInteger { switch ( MATH_BIGINTEGER_MODE ) { case MATH_BIGINTEGER_MODE_GMP: - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = gmp_sub($this->value, $y->value); return $this->_normalize($temp); case MATH_BIGINTEGER_MODE_BCMATH: - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = bcsub($this->value, $y->value, 0); return $this->_normalize($temp); @@ -983,7 +969,7 @@ class Math_BigInteger $temp = $this->_subtract($this->value, $this->is_negative, $y->value, $y->is_negative); - $result = new Math_BigInteger(); + $result = new static(); $result->value = $temp[MATH_BIGINTEGER_VALUE]; $result->is_negative = $temp[MATH_BIGINTEGER_SIGN]; @@ -1086,10 +1072,8 @@ class Math_BigInteger * Here's an example: * * multiply($b); * @@ -1097,20 +1081,20 @@ class Math_BigInteger * ?> * * - * @param Math_BigInteger $x - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $x + * @return \phpseclib\Math\BigInteger * @access public */ function multiply($x) { switch ( MATH_BIGINTEGER_MODE ) { case MATH_BIGINTEGER_MODE_GMP: - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = gmp_mul($this->value, $x->value); return $this->_normalize($temp); case MATH_BIGINTEGER_MODE_BCMATH: - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = bcmul($this->value, $x->value, 0); return $this->_normalize($temp); @@ -1118,7 +1102,7 @@ class Math_BigInteger $temp = $this->_multiply($this->value, $this->is_negative, $x->value, $x->is_negative); - $product = new Math_BigInteger(); + $product = new static(); $product->value = $temp[MATH_BIGINTEGER_VALUE]; $product->is_negative = $temp[MATH_BIGINTEGER_SIGN]; @@ -1370,10 +1354,8 @@ class Math_BigInteger * Here's an example: * * divide($b); * @@ -1383,7 +1365,7 @@ class Math_BigInteger * ?> * * - * @param Math_BigInteger $y + * @param \phpseclib\Math\BigInteger $y * @return Array * @access public * @internal This function is based off of {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=9 HAC 14.20}. @@ -1392,8 +1374,8 @@ class Math_BigInteger { switch ( MATH_BIGINTEGER_MODE ) { case MATH_BIGINTEGER_MODE_GMP: - $quotient = new Math_BigInteger(); - $remainder = new Math_BigInteger(); + $quotient = new static(); + $remainder = new static(); list($quotient->value, $remainder->value) = gmp_div_qr($this->value, $y->value); @@ -1403,8 +1385,8 @@ class Math_BigInteger return array($this->_normalize($quotient), $this->_normalize($remainder)); case MATH_BIGINTEGER_MODE_BCMATH: - $quotient = new Math_BigInteger(); - $remainder = new Math_BigInteger(); + $quotient = new static(); + $remainder = new static(); $quotient->value = bcdiv($this->value, $y->value, 0); $remainder->value = bcmod($this->value, $y->value); @@ -1418,8 +1400,8 @@ class Math_BigInteger if (count($y->value) == 1) { list($q, $r) = $this->_divide_digit($this->value, $y->value[0]); - $quotient = new Math_BigInteger(); - $remainder = new Math_BigInteger(); + $quotient = new static(); + $remainder = new static(); $quotient->value = $q; $remainder->value = array($r); $quotient->is_negative = $this->is_negative != $y->is_negative; @@ -1428,7 +1410,7 @@ class Math_BigInteger static $zero; if ( !isset($zero) ) { - $zero = new Math_BigInteger(); + $zero = new static(); } $x = $this->copy(); @@ -1442,10 +1424,10 @@ class Math_BigInteger $diff = $x->compare($y); if ( !$diff ) { - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = array(1); $temp->is_negative = $x_sign != $y_sign; - return array($this->_normalize($temp), $this->_normalize(new Math_BigInteger())); + return array($this->_normalize($temp), $this->_normalize(new static())); } if ( $diff < 0 ) { @@ -1453,7 +1435,7 @@ class Math_BigInteger if ( $x_sign ) { $x = $y->subtract($x); } - return array($this->_normalize(new Math_BigInteger()), $this->_normalize($x)); + return array($this->_normalize(new static()), $this->_normalize($x)); } // normalize $x and $y as described in HAC 14.23 / 14.24 @@ -1468,15 +1450,15 @@ class Math_BigInteger $x_max = count($x->value) - 1; $y_max = count($y->value) - 1; - $quotient = new Math_BigInteger(); + $quotient = new static(); $quotient_value = &$quotient->value; $quotient_value = $this->_array_repeat(0, $x_max - $y_max + 1); static $temp, $lhs, $rhs; if (!isset($temp)) { - $temp = new Math_BigInteger(); - $lhs = new Math_BigInteger(); - $rhs = new Math_BigInteger(); + $temp = new static(); + $lhs = new static(); + $rhs = new static(); } $temp_value = &$temp->value; $rhs_value = &$rhs->value; @@ -1589,11 +1571,9 @@ class Math_BigInteger * Here's an example: * * modPow($b, $c); * @@ -1601,9 +1581,9 @@ class Math_BigInteger * ?> * * - * @param Math_BigInteger $e - * @param Math_BigInteger $n - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $e + * @param \phpseclib\Math\BigInteger $n + * @return \phpseclib\Math\BigInteger * @access public * @internal The most naive approach to modular exponentiation has very unreasonable requirements, and * and although the approach involving repeated squaring does vastly better, it, too, is impractical @@ -1629,7 +1609,7 @@ class Math_BigInteger { $n = $this->bitmask !== false && $this->bitmask->compare($n) < 0 ? $this->bitmask : $n->abs(); - if ($e->compare(new Math_BigInteger()) < 0) { + if ($e->compare(new static()) < 0) { $e = $e->abs(); $temp = $this->modInverse($n); @@ -1641,13 +1621,13 @@ class Math_BigInteger } if ( MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_GMP ) { - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = gmp_powm($this->value, $e->value, $n->value); return $this->_normalize($temp); } - if ($this->compare(new Math_BigInteger()) < 0 || $this->compare($n) > 0) { + if ($this->compare(new static()) < 0 || $this->compare($n) > 0) { list(, $temp) = $this->divide($n); return $temp->modPow($e, $n); } @@ -1683,19 +1663,19 @@ class Math_BigInteger $plaintext = str_pad($this->toBytes(), strlen($n->toBytes(true)) - 1, "\0", STR_PAD_LEFT); if (openssl_public_encrypt($plaintext, $result, $RSAPublicKey, OPENSSL_NO_PADDING)) { - return new Math_BigInteger($result, 256); + return new static($result, 256); } } if ( MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH ) { - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = bcpowmod($this->value, $e->value, $n->value, 0); return $this->_normalize($temp); } if ( empty($e->value) ) { - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = array(1); return $this->_normalize($temp); } @@ -1706,7 +1686,7 @@ class Math_BigInteger } if ( $e->value == array(2) ) { - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = $this->_square($this->value); list(, $temp) = $temp->divide($n); return $this->_normalize($temp); @@ -1738,11 +1718,11 @@ class Math_BigInteger $mod1 = $n->copy(); $mod1->_rshift($j); - $mod2 = new Math_BigInteger(); + $mod2 = new static(); $mod2->value = array(1); $mod2->_lshift($j); - $part1 = ( $mod1->value != array(1) ) ? $this->_slidingWindow($e, $mod1, MATH_BIGINTEGER_MONTGOMERY) : new Math_BigInteger(); + $part1 = ( $mod1->value != array(1) ) ? $this->_slidingWindow($e, $mod1, MATH_BIGINTEGER_MONTGOMERY) : new static(); $part2 = $this->_slidingWindow($e, $mod2, MATH_BIGINTEGER_POWEROF2); $y1 = $mod2->modInverse($mod1); @@ -1763,11 +1743,11 @@ class Math_BigInteger /** * Performs modular exponentiation. * - * Alias for Math_BigInteger::modPow() + * Alias for modPow(). * - * @param Math_BigInteger $e - * @param Math_BigInteger $n - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $e + * @param \phpseclib\Math\BigInteger $n + * @return \phpseclib\Math\BigInteger * @access public */ function powMod($e, $n) @@ -1783,10 +1763,10 @@ class Math_BigInteger * however, this function performs a modular reduction after every multiplication and squaring operation. * As such, this function has the same preconditions that the reductions being used do. * - * @param Math_BigInteger $e - * @param Math_BigInteger $n + * @param \phpseclib\Math\BigInteger $e + * @param \phpseclib\Math\BigInteger $n * @param Integer $mode - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger * @access private */ function _slidingWindow($e, $n, $mode) @@ -1846,7 +1826,7 @@ class Math_BigInteger } } - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = $this->_reduce($result, $n_value, $mode); return $temp; @@ -1872,15 +1852,15 @@ class Math_BigInteger case MATH_BIGINTEGER_BARRETT: return $this->_barrett($x, $n); case MATH_BIGINTEGER_POWEROF2: - $lhs = new Math_BigInteger(); + $lhs = new static(); $lhs->value = $x; - $rhs = new Math_BigInteger(); + $rhs = new static(); $rhs->value = $n; return $x->_mod2($n); case MATH_BIGINTEGER_CLASSIC: - $lhs = new Math_BigInteger(); + $lhs = new static(); $lhs->value = $x; - $rhs = new Math_BigInteger(); + $rhs = new static(); $rhs->value = $n; list(, $temp) = $lhs->divide($rhs); return $temp->value; @@ -1955,12 +1935,12 @@ class Math_BigInteger * * @see _slidingWindow() * @access private - * @param Math_BigInteger - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger + * @return \phpseclib\Math\BigInteger */ function _mod2($n) { - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = array(1); return $this->bitwise_and($n->subtract($temp)); } @@ -2000,8 +1980,8 @@ class Math_BigInteger // if ($this->_compare($n, $this->_square($m)) >= 0) { if (count($n) > 2 * $m_length) { - $lhs = new Math_BigInteger(); - $rhs = new Math_BigInteger(); + $lhs = new static(); + $rhs = new static(); $lhs->value = $n; $rhs->value = $m; list(, $temp) = $lhs->divide($rhs); @@ -2019,11 +1999,11 @@ class Math_BigInteger $key = count($cache[MATH_BIGINTEGER_VARIABLE]); $cache[MATH_BIGINTEGER_VARIABLE][] = $m; - $lhs = new Math_BigInteger(); + $lhs = new static(); $lhs_value = &$lhs->value; $lhs_value = $this->_array_repeat(0, $m_length + ($m_length >> 1)); $lhs_value[] = 1; - $rhs = new Math_BigInteger(); + $rhs = new static(); $rhs->value = $m; list($u, $m1) = $lhs->divide($rhs); @@ -2077,7 +2057,7 @@ class Math_BigInteger /** * (Regular) Barrett Modular Reduction * - * For numbers with more than four digits Math_BigInteger::_barrett() is faster. The difference between that and this + * For numbers with more than four digits BigInteger::_barrett() is faster. The difference between that and this * is that this function does not fold the denominator into a smaller form. * * @see _slidingWindow() @@ -2096,8 +2076,8 @@ class Math_BigInteger $n_length = count($n); if (count($x) > 2 * $n_length) { - $lhs = new Math_BigInteger(); - $rhs = new Math_BigInteger(); + $lhs = new static(); + $rhs = new static(); $lhs->value = $x; $rhs->value = $n; list(, $temp) = $lhs->divide($rhs); @@ -2107,11 +2087,11 @@ class Math_BigInteger if ( ($key = array_search($n, $cache[MATH_BIGINTEGER_VARIABLE])) === false ) { $key = count($cache[MATH_BIGINTEGER_VARIABLE]); $cache[MATH_BIGINTEGER_VARIABLE][] = $n; - $lhs = new Math_BigInteger(); + $lhs = new static(); $lhs_value = &$lhs->value; $lhs_value = $this->_array_repeat(0, 2 * $n_length); $lhs_value[] = 1; - $rhs = new Math_BigInteger(); + $rhs = new static(); $rhs->value = $n; list($temp, ) = $lhs->divide($rhs); // m.length $cache[MATH_BIGINTEGER_DATA][] = $temp->value; @@ -2340,9 +2320,9 @@ class Math_BigInteger */ function _prepMontgomery($x, $n) { - $lhs = new Math_BigInteger(); + $lhs = new static(); $lhs->value = array_merge($this->_array_repeat(0, count($n)), $x); - $rhs = new Math_BigInteger(); + $rhs = new static(); $rhs->value = $n; list(, $temp) = $lhs->divide($rhs); @@ -2394,10 +2374,8 @@ class Math_BigInteger * Here's an example: * * modInverse($b); * echo $c->toString(); // outputs 4 @@ -2410,8 +2388,8 @@ class Math_BigInteger * ?> * * - * @param Math_BigInteger $n - * @return mixed false, if no modular inverse exists, Math_BigInteger, otherwise. + * @param \phpseclib\Math\BigInteger $n + * @return mixed false, if no modular inverse exists, \phpseclib\Math\BigInteger, otherwise. * @access public * @internal See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=21 HAC 14.64} for more information. */ @@ -2419,7 +2397,7 @@ class Math_BigInteger { switch ( MATH_BIGINTEGER_MODE ) { case MATH_BIGINTEGER_MODE_GMP: - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = gmp_invert($this->value, $n->value); return ( $temp->value === false ) ? false : $this->_normalize($temp); @@ -2427,8 +2405,8 @@ class Math_BigInteger static $zero, $one; if (!isset($zero)) { - $zero = new Math_BigInteger(); - $one = new Math_BigInteger(1); + $zero = new static(); + $one = new static(1); } // $x mod -$n == $x mod $n. @@ -2462,10 +2440,8 @@ class Math_BigInteger * Here's an example: * * extendedGCD($b)); * @@ -2474,8 +2450,8 @@ class Math_BigInteger * ?> * * - * @param Math_BigInteger $n - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $n + * @return \phpseclib\Math\BigInteger * @access public * @internal Calculates the GCD using the binary xGCD algorithim described in * {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=19 HAC 14.61}. As the text above 14.61 notes, @@ -2488,9 +2464,9 @@ class Math_BigInteger extract(gmp_gcdext($this->value, $n->value)); return array( - 'gcd' => $this->_normalize(new Math_BigInteger($g)), - 'x' => $this->_normalize(new Math_BigInteger($s)), - 'y' => $this->_normalize(new Math_BigInteger($t)) + 'gcd' => $this->_normalize(new static($g)), + 'x' => $this->_normalize(new static($s)), + 'y' => $this->_normalize(new static($t)) ); case MATH_BIGINTEGER_MODE_BCMATH: // it might be faster to use the binary xGCD algorithim here, as well, but (1) that algorithim works @@ -2522,15 +2498,15 @@ class Math_BigInteger } return array( - 'gcd' => $this->_normalize(new Math_BigInteger($u)), - 'x' => $this->_normalize(new Math_BigInteger($a)), - 'y' => $this->_normalize(new Math_BigInteger($b)) + 'gcd' => $this->_normalize(new static($u)), + 'x' => $this->_normalize(new static($a)), + 'y' => $this->_normalize(new static($b)) ); } $y = $n->copy(); $x = $this->copy(); - $g = new Math_BigInteger(); + $g = new static(); $g->value = array(1); while ( !(($x->value[0] & 1)|| ($y->value[0] & 1)) ) { @@ -2542,10 +2518,10 @@ class Math_BigInteger $u = $x->copy(); $v = $y->copy(); - $a = new Math_BigInteger(); - $b = new Math_BigInteger(); - $c = new Math_BigInteger(); - $d = new Math_BigInteger(); + $a = new static(); + $b = new static(); + $c = new static(); + $d = new static(); $a->value = $d->value = $g->value = array(1); $b->value = $c->value = array(); @@ -2597,10 +2573,8 @@ class Math_BigInteger * Here's an example: * * extendedGCD($b); * @@ -2608,8 +2582,8 @@ class Math_BigInteger * ?> * * - * @param Math_BigInteger $n - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger $n + * @return \phpseclib\Math\BigInteger * @access public */ function gcd($n) @@ -2621,12 +2595,12 @@ class Math_BigInteger /** * Absolute value. * - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger * @access public */ function abs() { - $temp = new Math_BigInteger(); + $temp = new static(); switch ( MATH_BIGINTEGER_MODE ) { case MATH_BIGINTEGER_MODE_GMP: @@ -2654,7 +2628,7 @@ class Math_BigInteger * * Note how the same comparison operator is used. If you want to test for equality, use $x->equals($y). * - * @param Math_BigInteger $y + * @param \phpseclib\Math\BigInteger $y * @return Integer < 0 if $this is less than $y; > 0 if $this is greater than $y, and 0 if they are equal. * @access public * @see equals() @@ -2711,9 +2685,9 @@ class Math_BigInteger /** * Tests the equality of two numbers. * - * If you need to see if one number is greater than or less than another number, use Math_BigInteger::compare() + * If you need to see if one number is greater than or less than another number, use BigInteger::compare() * - * @param Math_BigInteger $x + * @param \phpseclib\Math\BigInteger $x * @return Boolean * @access public * @see compare() @@ -2741,9 +2715,9 @@ class Math_BigInteger { $this->precision = $bits; if ( MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_BCMATH ) { - $this->bitmask = new Math_BigInteger(chr((1 << ($bits & 0x7)) - 1) . str_repeat(chr(0xFF), $bits >> 3), 256); + $this->bitmask = new static(chr((1 << ($bits & 0x7)) - 1) . str_repeat(chr(0xFF), $bits >> 3), 256); } else { - $this->bitmask = new Math_BigInteger(bcpow('2', $bits, 0)); + $this->bitmask = new static(bcpow('2', $bits, 0)); } $temp = $this->_normalize($this); @@ -2753,16 +2727,16 @@ class Math_BigInteger /** * Logical And * - * @param Math_BigInteger $x + * @param \phpseclib\Math\BigInteger $x * @access public * @internal Implemented per a request by Lluis Pamies i Juarez - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger */ function bitwise_and($x) { switch ( MATH_BIGINTEGER_MODE ) { case MATH_BIGINTEGER_MODE_GMP: - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = gmp_and($this->value, $x->value); return $this->_normalize($temp); @@ -2775,7 +2749,7 @@ class Math_BigInteger $left = str_pad($left, $length, chr(0), STR_PAD_LEFT); $right = str_pad($right, $length, chr(0), STR_PAD_LEFT); - return $this->_normalize(new Math_BigInteger($left & $right, 256)); + return $this->_normalize(new static($left & $right, 256)); } $result = $this->copy(); @@ -2794,16 +2768,16 @@ class Math_BigInteger /** * Logical Or * - * @param Math_BigInteger $x + * @param \phpseclib\Math\BigInteger $x * @access public * @internal Implemented per a request by Lluis Pamies i Juarez - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger */ function bitwise_or($x) { switch ( MATH_BIGINTEGER_MODE ) { case MATH_BIGINTEGER_MODE_GMP: - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = gmp_or($this->value, $x->value); return $this->_normalize($temp); @@ -2816,7 +2790,7 @@ class Math_BigInteger $left = str_pad($left, $length, chr(0), STR_PAD_LEFT); $right = str_pad($right, $length, chr(0), STR_PAD_LEFT); - return $this->_normalize(new Math_BigInteger($left | $right, 256)); + return $this->_normalize(new static($left | $right, 256)); } $length = max(count($this->value), count($x->value)); @@ -2834,16 +2808,16 @@ class Math_BigInteger /** * Logical Exclusive-Or * - * @param Math_BigInteger $x + * @param \phpseclib\Math\BigInteger $x * @access public * @internal Implemented per a request by Lluis Pamies i Juarez - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger */ function bitwise_xor($x) { switch ( MATH_BIGINTEGER_MODE ) { case MATH_BIGINTEGER_MODE_GMP: - $temp = new Math_BigInteger(); + $temp = new static(); $temp->value = gmp_xor($this->value, $x->value); return $this->_normalize($temp); @@ -2856,7 +2830,7 @@ class Math_BigInteger $left = str_pad($left, $length, chr(0), STR_PAD_LEFT); $right = str_pad($right, $length, chr(0), STR_PAD_LEFT); - return $this->_normalize(new Math_BigInteger($left ^ $right, 256)); + return $this->_normalize(new static($left ^ $right, 256)); } $length = max(count($this->value), count($x->value)); @@ -2876,7 +2850,7 @@ class Math_BigInteger * * @access public * @internal Implemented per a request by Lluis Pamies i Juarez - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger */ function bitwise_not() { @@ -2895,7 +2869,7 @@ class Math_BigInteger $current_bits = strlen($pre_msb) + 8 * strlen($temp) - 8; $new_bits = $this->precision - $current_bits; if ($new_bits <= 0) { - return $this->_normalize(new Math_BigInteger($temp, 256)); + return $this->_normalize(new static($temp, 256)); } // generate as many leading 1's as we need to. @@ -2904,7 +2878,7 @@ class Math_BigInteger $temp = str_pad($temp, ceil($this->bits / 8), chr(0), STR_PAD_LEFT); - return $this->_normalize(new Math_BigInteger($leading_ones | $temp, 256)); + return $this->_normalize(new static($leading_ones | $temp, 256)); } /** @@ -2913,13 +2887,13 @@ class Math_BigInteger * Shifts BigInteger's by $shift bits, effectively dividing by 2**$shift. * * @param Integer $shift - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger * @access public * @internal The only version that yields any speed increases is the internal version. */ function bitwise_rightShift($shift) { - $temp = new Math_BigInteger(); + $temp = new static(); switch ( MATH_BIGINTEGER_MODE ) { case MATH_BIGINTEGER_MODE_GMP: @@ -2951,13 +2925,13 @@ class Math_BigInteger * Shifts BigInteger's by $shift bits, effectively multiplying by 2**$shift. * * @param Integer $shift - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger * @access public * @internal The only version that yields any speed increases is the internal version. */ function bitwise_leftShift($shift) { - $temp = new Math_BigInteger(); + $temp = new static(); switch ( MATH_BIGINTEGER_MODE ) { case MATH_BIGINTEGER_MODE_GMP: @@ -2989,7 +2963,7 @@ class Math_BigInteger * Instead of the top x bits being dropped they're appended to the shifted bit string. * * @param Integer $shift - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger * @access public */ function bitwise_leftRotate($shift) @@ -2999,7 +2973,7 @@ class Math_BigInteger if ($this->precision > 0) { $precision = $this->precision; if ( MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH ) { - $mask = $this->bitmask->subtract(new Math_BigInteger(1)); + $mask = $this->bitmask->subtract(new static(1)); $mask = $mask->toBytes(); } else { $mask = $this->bitmask->toBytes(); @@ -3021,7 +2995,7 @@ class Math_BigInteger } $left = $this->bitwise_leftShift($shift); - $left = $left->bitwise_and(new Math_BigInteger($mask, 256)); + $left = $left->bitwise_and(new static($mask, 256)); $right = $this->bitwise_rightShift($precision - $shift); $result = MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_BCMATH ? $left->bitwise_or($right) : $left->add($right); return $this->_normalize($result); @@ -3033,7 +3007,7 @@ class Math_BigInteger * Instead of the bottom x bits being dropped they're prepended to the shifted bit string. * * @param Integer $shift - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger * @access public */ function bitwise_rightRotate($shift) @@ -3047,7 +3021,7 @@ class Math_BigInteger * Byte length is equal to $length. Uses crypt_random if it's loaded and mt_rand if it's not. * * @param Integer $length - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger * @access private */ function _random_number_helper($size) @@ -3068,7 +3042,7 @@ class Math_BigInteger } } - return new Math_BigInteger($random, 256); + return new static($random, 256); } /** @@ -3076,17 +3050,17 @@ class Math_BigInteger * * @param optional Integer $min * @param optional Integer $max - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger * @access public */ function random($min = false, $max = false) { if ($min === false) { - $min = new Math_BigInteger(0); + $min = new static(0); } if ($max === false) { - $max = new Math_BigInteger(0x7FFFFFFF); + $max = new static(0x7FFFFFFF); } $compare = $max->compare($min); @@ -3102,7 +3076,7 @@ class Math_BigInteger static $one; if (!isset($one)) { - $one = new Math_BigInteger(1); + $one = new static(1); } $max = $max->subtract($min->subtract($one)); @@ -3123,7 +3097,7 @@ class Math_BigInteger http://crypto.stackexchange.com/questions/5708/creating-a-small-number-from-a-cryptographically-secure-random-string */ - $random_max = new Math_BigInteger(chr(1) . str_repeat("\0", $size), 256); + $random_max = new static(chr(1) . str_repeat("\0", $size), 256); $random = $this->_random_number_helper($size); list($max_multiple) = $random_max->divide($max); @@ -3152,18 +3126,18 @@ class Math_BigInteger * @param optional Integer $min * @param optional Integer $max * @param optional Integer $timeout - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger * @access public * @internal See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=15 HAC 4.44}. */ function randomPrime($min = false, $max = false, $timeout = false) { if ($min === false) { - $min = new Math_BigInteger(0); + $min = new static(0); } if ($max === false) { - $max = new Math_BigInteger(0x7FFFFFFF); + $max = new static(0x7FFFFFFF); } $compare = $max->compare($min); @@ -3179,8 +3153,8 @@ class Math_BigInteger static $one, $two; if (!isset($one)) { - $one = new Math_BigInteger(1); - $two = new Math_BigInteger(2); + $one = new static(1); + $two = new static(2); } $start = time(); @@ -3189,7 +3163,7 @@ class Math_BigInteger // gmp_nextprime() requires PHP 5 >= 5.2.0 per . if ( MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_GMP && function_exists('gmp_nextprime') ) { - $p = new Math_BigInteger(); + $p = new static(); $p->value = gmp_nextprime($x->value); if ($p->compare($max) <= 0) { @@ -3272,7 +3246,7 @@ class Math_BigInteger * Checks a numer to see if it's prime * * Assuming the $t parameter is not set, this function has an error rate of 2**-80. The main motivation for the - * $t parameter is distributability. Math_BigInteger::randomPrime() can be distributed across multiple pageloads + * $t parameter is distributability. BigInteger::randomPrime() can be distributed across multiple pageloads * on a website instead of just one. * * @param optional Integer $t @@ -3345,13 +3319,13 @@ class Math_BigInteger if ( MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL ) { for ($i = 0; $i < count($primes); ++$i) { - $primes[$i] = new Math_BigInteger($primes[$i]); + $primes[$i] = new static($primes[$i]); } } - $zero = new Math_BigInteger(); - $one = new Math_BigInteger(1); - $two = new Math_BigInteger(2); + $zero = new static(); + $one = new static(1); + $two = new static(2); } if ($this->equals($one)) { @@ -3496,8 +3470,8 @@ class Math_BigInteger * * Removes leading zeros and truncates (if necessary) to maintain the appropriate precision * - * @param Math_BigInteger - * @return Math_BigInteger + * @param \phpseclib\Math\BigInteger + * @return \phpseclib\Math\BigInteger * @see _trim() * @access private */ @@ -3547,7 +3521,7 @@ class Math_BigInteger * Removes leading zeros * * @param Array $value - * @return Math_BigInteger + * @return \phpseclib\Math\BigInteger * @access private */ function _trim($value) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 002c8e6d..f2d628de 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -2267,7 +2267,7 @@ class Net_SFTP extends Net_SSH2 switch ($flags & $key) { case NET_SFTP_ATTR_SIZE: // 0x00000001 // size is represented by a 64-bit integer, so we perhaps ought to be doing the following: - // $attr['size'] = new Math_BigInteger($this->_string_shift($response, 8), 256); + // $attr['size'] = new \phpseclib\Math\BigInteger($this->_string_shift($response, 8), 256); // of course, you shouldn't be using Net_SFTP to transfer files that are in excess of 4GB // (0xFFFFFFFF bytes), anyway. as such, we'll just represent all file sizes that are bigger than // 4GB as being 4GB. diff --git a/phpseclib/Net/SSH1.php b/phpseclib/Net/SSH1.php index 15e659a9..d4fbdf06 100644 --- a/phpseclib/Net/SSH1.php +++ b/phpseclib/Net/SSH1.php @@ -64,6 +64,8 @@ * @link http://phpseclib.sourceforge.net */ +use \phpseclib\Math\BigInteger; + /**#@+ * Encryption Methods * @@ -517,10 +519,6 @@ class Net_SSH1 */ function Net_SSH1($host, $port = 22, $timeout = 10, $cipher = NET_SSH1_CIPHER_3DES) { - if (!class_exists('Math_BigInteger')) { - include_once 'Math/BigInteger.php'; - } - // Include Crypt_Random // the class_exists() will only be called if the crypt_random_string function hasn't been defined and // will trigger a call to __autoload() if you're wanting to auto-load classes @@ -600,21 +598,21 @@ class Net_SSH1 $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4); $temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2)); - $server_key_public_exponent = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); + $server_key_public_exponent = new BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); $this->server_key_public_exponent = $server_key_public_exponent; $temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2)); - $server_key_public_modulus = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); + $server_key_public_modulus = new BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); $this->server_key_public_modulus = $server_key_public_modulus; $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4); $temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2)); - $host_key_public_exponent = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); + $host_key_public_exponent = new BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); $this->host_key_public_exponent = $host_key_public_exponent; $temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2)); - $host_key_public_modulus = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); + $host_key_public_modulus = new BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); $this->host_key_public_modulus = $host_key_public_modulus; $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4); @@ -1377,7 +1375,7 @@ class Net_SSH1 } $temp = chr(0) . chr(2) . $random . chr(0) . $m; - $m = new Math_BigInteger($temp, 256); + $m = new BigInteger($temp, 256); $m = $m->modPow($key[0], $key[1]); return $m->toBytes(); diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 39fa6d9c..da9c7899 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -66,6 +66,9 @@ * @link http://phpseclib.sourceforge.net */ +// Used to do Diffie-Hellman key exchange and DSA/RSA signature verification. +use \phpseclib\Math\BigInteger; + /**#@+ * Execution Bitmap Masks * @@ -830,12 +833,6 @@ class Net_SSH2 */ function Net_SSH2($host, $port = 22, $timeout = 10) { - // Include Math_BigInteger - // Used to do Diffie-Hellman key exchange and DSA/RSA signature verification. - if (!class_exists('Math_BigInteger')) { - include_once 'Math/BigInteger.php'; - } - if (!function_exists('crypt_random_string')) { include_once 'Crypt/Random.php'; } @@ -1353,8 +1350,8 @@ class Net_SSH2 // For both diffie-hellman-group1-sha1 and diffie-hellman-group14-sha1 // the generator field element is 2 (decimal) and the hash function is sha1. - $g = new Math_BigInteger(2); - $prime = new Math_BigInteger($prime, 16); + $g = new BigInteger(2); + $prime = new BigInteger($prime, 16); $kexHash = new Crypt_Hash('sha1'); //$q = $p->bitwise_rightShift(1); @@ -1365,7 +1362,7 @@ class Net_SSH2 [VAN-OORSCHOT]. -- http://tools.ietf.org/html/rfc4419#section-6.2 */ - $one = new Math_BigInteger(1); + $one = new BigInteger(1); $keyLength = min($keyLength, $kexHash->getLength()); $max = $one->bitwise_leftShift(16 * $keyLength); // 2 * 8 * $keyLength $max = $max->subtract($one); @@ -1401,7 +1398,7 @@ class Net_SSH2 $temp = unpack('Nlength', $this->_string_shift($response, 4)); $fBytes = $this->_string_shift($response, $temp['length']); - $f = new Math_BigInteger($fBytes, -256); + $f = new BigInteger($fBytes, -256); $temp = unpack('Nlength', $this->_string_shift($response, 4)); $this->signature = $this->_string_shift($response, $temp['length']); @@ -3641,19 +3638,19 @@ class Net_SSH2 switch ($this->signature_format) { case 'ssh-dss': - $zero = new Math_BigInteger(); + $zero = new BigInteger(); $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4)); - $p = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); + $p = new BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4)); - $q = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); + $q = new BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4)); - $g = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); + $g = new BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4)); - $y = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); + $y = new BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); /* The value for 'dss_signature_blob' is encoded as a string containing r, followed by s (which are 160-bit integers, without lengths or @@ -3664,8 +3661,8 @@ class Net_SSH2 return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); } - $r = new Math_BigInteger($this->_string_shift($signature, 20), 256); - $s = new Math_BigInteger($this->_string_shift($signature, 20), 256); + $r = new BigInteger($this->_string_shift($signature, 20), 256); + $s = new BigInteger($this->_string_shift($signature, 20), 256); switch (true) { case $r->equals($zero): @@ -3678,7 +3675,7 @@ class Net_SSH2 $w = $s->modInverse($q); - $u1 = $w->multiply(new Math_BigInteger(sha1($this->exchange_hash), 16)); + $u1 = $w->multiply(new BigInteger(sha1($this->exchange_hash), 16)); list(, $u1) = $u1->divide($q); $u2 = $w->multiply($r); @@ -3699,10 +3696,10 @@ class Net_SSH2 break; case 'ssh-rsa': $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4)); - $e = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); + $e = new BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4)); - $n = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); + $n = new BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256); $nLength = $temp['length']; /* @@ -3723,7 +3720,7 @@ class Net_SSH2 */ $temp = unpack('Nlength', $this->_string_shift($signature, 4)); - $s = new Math_BigInteger($this->_string_shift($signature, $temp['length']), 256); + $s = new BigInteger($this->_string_shift($signature, $temp['length']), 256); // validate an RSA signature per "8.2 RSASSA-PKCS1-v1_5", "5.2.2 RSAVP1", and "9.1 EMSA-PSS" in the // following URL: @@ -3731,7 +3728,7 @@ class Net_SSH2 // also, see SSHRSA.c (rsa2_verifysig) in PuTTy's source. - if ($s->compare(new Math_BigInteger()) < 0 || $s->compare($n->subtract(new Math_BigInteger(1))) > 0) { + if ($s->compare(new BigInteger()) < 0 || $s->compare($n->subtract(new BigInteger(1))) > 0) { user_error('Invalid signature'); return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); } diff --git a/tests/Unit/Math/BigInteger/InternalTest.php b/tests/Unit/Math/BigInteger/InternalTest.php index faa9bb79..878f7fc6 100644 --- a/tests/Unit/Math/BigInteger/InternalTest.php +++ b/tests/Unit/Math/BigInteger/InternalTest.php @@ -17,8 +17,8 @@ class Math_BigInteger_InternalTest extends Unit_Math_BigInteger_TestCase public function testInternalRepresentation() { - $x = new Math_BigInteger('FFFFFFFFFFFFFFFFC90FDA', 16); - $y = new Math_BigInteger("$x"); + $x = new \phpseclib\Math\BigInteger('FFFFFFFFFFFFFFFFC90FDA', 16); + $y = new \phpseclib\Math\BigInteger("$x"); $this->assertSame($x->value, $y->value); } } diff --git a/tests/Unit/Math/BigInteger/TestCase.php b/tests/Unit/Math/BigInteger/TestCase.php index d233dfb4..69459ca2 100644 --- a/tests/Unit/Math/BigInteger/TestCase.php +++ b/tests/Unit/Math/BigInteger/TestCase.php @@ -18,7 +18,7 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase public function getInstance($x = 0, $base = 10) { - return new Math_BigInteger($x, $base); + return new \phpseclib\Math\BigInteger($x, $base); } public function testConstructorBase2()