mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-01-27 00:58:25 +00:00
BigInteger: updates per Joey3000
This commit is contained in:
parent
d86c61de78
commit
f7efbcbc8e
@ -525,13 +525,13 @@ class RSA
|
|||||||
$finalMax = $max;
|
$finalMax = $max;
|
||||||
extract(self::_generateMinMax($temp));
|
extract(self::_generateMinMax($temp));
|
||||||
|
|
||||||
$n = self::$one->copy();
|
$n = clone self::$one;
|
||||||
if (!empty($partial)) {
|
if (!empty($partial)) {
|
||||||
extract(unserialize($partial));
|
extract(unserialize($partial));
|
||||||
} else {
|
} else {
|
||||||
$exponents = $coefficients = $primes = array();
|
$exponents = $coefficients = $primes = array();
|
||||||
$lcm = array(
|
$lcm = array(
|
||||||
'top' => self::$one->copy(),
|
'top' => clone self::$one,
|
||||||
'bottom' => false
|
'bottom' => false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -716,13 +716,13 @@ class RSA
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_object($key->modulus)) {
|
if (is_object($key->modulus)) {
|
||||||
$this->modulus = $key->modulus->copy();
|
$this->modulus = clone $key->modulus;
|
||||||
}
|
}
|
||||||
if (is_object($key->exponent)) {
|
if (is_object($key->exponent)) {
|
||||||
$this->exponent = $key->exponent->copy();
|
$this->exponent = clone $key->exponent;
|
||||||
}
|
}
|
||||||
if (is_object($key->publicExponent)) {
|
if (is_object($key->publicExponent)) {
|
||||||
$this->publicExponent = $key->publicExponent->copy();
|
$this->publicExponent = clone $key->publicExponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->primes = array();
|
$this->primes = array();
|
||||||
@ -730,13 +730,13 @@ class RSA
|
|||||||
$this->coefficients = array();
|
$this->coefficients = array();
|
||||||
|
|
||||||
foreach ($this->primes as $prime) {
|
foreach ($this->primes as $prime) {
|
||||||
$this->primes[] = $prime->copy();
|
$this->primes[] = clone $prime;
|
||||||
}
|
}
|
||||||
foreach ($this->exponents as $exponent) {
|
foreach ($this->exponents as $exponent) {
|
||||||
$this->exponents[] = $exponent->copy();
|
$this->exponents[] = clone $exponent;
|
||||||
}
|
}
|
||||||
foreach ($this->coefficients as $coefficient) {
|
foreach ($this->coefficients as $coefficient) {
|
||||||
$this->coefficients[] = $coefficient->copy();
|
$this->coefficients[] = clone $coefficient;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -711,28 +711,6 @@ class BigInteger
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy an object
|
|
||||||
*
|
|
||||||
* PHP5 passes objects by reference while PHP4 passes by value. As such, we need a function to guarantee
|
|
||||||
* that all objects are passed by value, when appropriate. More information can be found here:
|
|
||||||
*
|
|
||||||
* {@link http://php.net/language.oop5.basic#51624}
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @see self::__clone()
|
|
||||||
* @return \phpseclib\Math\BigInteger
|
|
||||||
*/
|
|
||||||
function copy()
|
|
||||||
{
|
|
||||||
$temp = new static();
|
|
||||||
$temp->value = $this->value;
|
|
||||||
$temp->is_negative = $this->is_negative;
|
|
||||||
$temp->precision = $this->precision;
|
|
||||||
$temp->bitmask = $this->bitmask;
|
|
||||||
return $temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __toString() magic method
|
* __toString() magic method
|
||||||
*
|
*
|
||||||
@ -747,22 +725,6 @@ class BigInteger
|
|||||||
return $this->toString();
|
return $this->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* __clone() magic method
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return \phpseclib\Math\BigInteger
|
|
||||||
*/
|
|
||||||
function __clone()
|
|
||||||
{
|
|
||||||
$temp = new static();
|
|
||||||
$temp->value = $this->value;
|
|
||||||
$temp->is_negative = $this->is_negative;
|
|
||||||
$temp->precision = $this->precision;
|
|
||||||
$temp->bitmask = $this->bitmask;
|
|
||||||
return $temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __sleep() magic method
|
* __sleep() magic method
|
||||||
*
|
*
|
||||||
@ -1443,8 +1405,8 @@ class BigInteger
|
|||||||
$zero = new static();
|
$zero = new static();
|
||||||
}
|
}
|
||||||
|
|
||||||
$x = $this->copy();
|
$x = clone $this;
|
||||||
$y = $y->copy();
|
$y = clone $y;
|
||||||
|
|
||||||
$x_sign = $x->is_negative;
|
$x_sign = $x->is_negative;
|
||||||
$y_sign = $y->is_negative;
|
$y_sign = $y->is_negative;
|
||||||
|
@ -352,13 +352,16 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
|
|||||||
|
|
||||||
public function testPrecision()
|
public function testPrecision()
|
||||||
{
|
{
|
||||||
$a = $this->getInstance(50);
|
$a = $this->getInstance(51);
|
||||||
$this->assertSame($a->getPrecision(), -1);
|
$this->assertSame($a->getPrecision(), -1);
|
||||||
$b = $a;
|
$b = $a;
|
||||||
$c = clone $a;
|
$c = clone $a;
|
||||||
$b->setPrecision(4);
|
$b->setPrecision(1);
|
||||||
$this->assertSame($a->getPrecision(), 4);
|
$this->assertSame($a->getPrecision(), 1);
|
||||||
$this->assertSame($b->getPrecision(), 4);
|
$this->assertSame("$a", '1');
|
||||||
|
$this->assertSame($b->getPrecision(), 1);
|
||||||
|
$this->assertSame("$b", '1');
|
||||||
$this->assertSame($c->getPrecision(), -1);
|
$this->assertSame($c->getPrecision(), -1);
|
||||||
|
$this->assertSame("$c", '51');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user