mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-26 11:37:33 +00:00
BigInteger: make select methods static, add type hinting, etc
This commit is contained in:
parent
94fdbba2aa
commit
a0d21b6321
@ -525,8 +525,6 @@ class RSA
|
|||||||
$finalMax = $max;
|
$finalMax = $max;
|
||||||
extract(self::_generateMinMax($temp));
|
extract(self::_generateMinMax($temp));
|
||||||
|
|
||||||
$generator = new BigInteger();
|
|
||||||
|
|
||||||
$n = self::$one->copy();
|
$n = self::$one->copy();
|
||||||
if (!empty($partial)) {
|
if (!empty($partial)) {
|
||||||
extract(unserialize($partial));
|
extract(unserialize($partial));
|
||||||
@ -565,9 +563,9 @@ class RSA
|
|||||||
if (!$temp->equals(self::$zero)) {
|
if (!$temp->equals(self::$zero)) {
|
||||||
$min = $min->add(self::$one); // ie. ceil()
|
$min = $min->add(self::$one); // ie. ceil()
|
||||||
}
|
}
|
||||||
$primes[$i] = $generator->randomPrime($min, $finalMax, $timeout);
|
$primes[$i] = BigInteger::randomPrime($min, $finalMax, $timeout);
|
||||||
} else {
|
} else {
|
||||||
$primes[$i] = $generator->randomPrime($min, $max, $timeout);
|
$primes[$i] = BigInteger::randomPrime($min, $max, $timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($primes[$i] === false) { // if we've reached the timeout
|
if ($primes[$i] === false) { // if we've reached the timeout
|
||||||
@ -1383,7 +1381,7 @@ class RSA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = self::$one->random(self::$one, $smallest->subtract(self::$one));
|
$r = BigInteger::random(self::$one, $smallest->subtract(self::$one));
|
||||||
|
|
||||||
$m_i = array(
|
$m_i = array(
|
||||||
1 => $this->_blind($x, $r, 1),
|
1 => $this->_blind($x, $r, 1),
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1495,7 +1495,7 @@ class SSH2
|
|||||||
$max = $one->bitwise_leftShift(16 * $keyLength); // 2 * 8 * $keyLength
|
$max = $one->bitwise_leftShift(16 * $keyLength); // 2 * 8 * $keyLength
|
||||||
$max = $max->subtract($one);
|
$max = $max->subtract($one);
|
||||||
|
|
||||||
$x = $one->random($one, $max);
|
$x = BigInteger::random($one, $max);
|
||||||
$e = $g->modPow($x, $prime);
|
$e = $g->modPow($x, $prime);
|
||||||
|
|
||||||
$eBytes = $e->toBytes(true);
|
$eBytes = $e->toBytes(true);
|
||||||
|
@ -268,29 +268,13 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
|
|||||||
$min = $this->getInstance(0);
|
$min = $this->getInstance(0);
|
||||||
$max = $this->getInstance('18446744073709551616');
|
$max = $this->getInstance('18446744073709551616');
|
||||||
|
|
||||||
$rand1 = $min->random($min, $max);
|
$rand1 = \phpseclib\Math\BigInteger::random($min, $max);
|
||||||
// technically $rand1 can equal $min but with the $min and $max we've
|
// technically $rand1 can equal $min but with the $min and $max we've
|
||||||
// chosen it's just not that likely
|
// chosen it's just not that likely
|
||||||
$this->assertTrue($rand1->compare($min) > 0);
|
$this->assertTrue($rand1->compare($min) > 0);
|
||||||
$this->assertTrue($rand1->compare($max) < 0);
|
$this->assertTrue($rand1->compare($max) < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRandomOneArgument()
|
|
||||||
{
|
|
||||||
$min = $this->getInstance(0);
|
|
||||||
$max = $this->getInstance('18446744073709551616');
|
|
||||||
|
|
||||||
$rand1 = $min->random($max);
|
|
||||||
$this->assertTrue($rand1->compare($min) > 0);
|
|
||||||
$this->assertTrue($rand1->compare($max) < 0);
|
|
||||||
|
|
||||||
$rand2 = $max->random($min);
|
|
||||||
$this->assertTrue($rand2->compare($min) > 0);
|
|
||||||
$this->assertTrue($rand2->compare($max) < 0);
|
|
||||||
|
|
||||||
$this->assertFalse($rand1->equals($rand2));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group github279
|
* @group github279
|
||||||
*/
|
*/
|
||||||
@ -326,8 +310,8 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
|
|||||||
Code for generation of $alicePrivate and $bobPrivate.
|
Code for generation of $alicePrivate and $bobPrivate.
|
||||||
$one = $this->getInstance(1);
|
$one = $this->getInstance(1);
|
||||||
$max = $one->bitwise_leftShift(512)->subtract($one);
|
$max = $one->bitwise_leftShift(512)->subtract($one);
|
||||||
$alicePrivate = $one->random($one, $max);
|
$alicePrivate = \phpseclib\Math\BigInteger::random($one, $max);
|
||||||
$bobPrivate = $one->random($one, $max);
|
$bobPrivate = \phpseclib\Math\BigInteger::random($one, $max);
|
||||||
var_dump($alicePrivate->toHex(), $bobPrivate->toHex());
|
var_dump($alicePrivate->toHex(), $bobPrivate->toHex());
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user