mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-27 19:54:57 +00:00
PrimeField: prevent infinite loop with composite primefields
This commit is contained in:
parent
3b6030d887
commit
6298d1cd55
@ -44,9 +44,9 @@ class PrimeField extends FiniteField
|
||||
*/
|
||||
public function __construct(BigInteger $modulo)
|
||||
{
|
||||
//if (!$modulo->isPrime()) {
|
||||
// throw new \UnexpectedValueException('PrimeField requires a prime number be passed to the constructor');
|
||||
//}
|
||||
if (!$modulo->isPrime()) {
|
||||
throw new \UnexpectedValueException('PrimeField requires a prime number be passed to the constructor');
|
||||
}
|
||||
|
||||
$this->instanceID = self::$instanceCounter++;
|
||||
Integer::setModulo($this->instanceID, $modulo);
|
||||
|
@ -263,13 +263,13 @@ class Integer extends Base
|
||||
$r = $this->value->powMod($temp, static::$modulo[$this->instanceID]);
|
||||
|
||||
while (!$t->equals($one)) {
|
||||
$i = clone $one;
|
||||
|
||||
while (!$t->powMod($two->pow($i), static::$modulo[$this->instanceID])->equals($one)) {
|
||||
$i = $i->add($one);
|
||||
for ($i == clone $one; $i->compare($m) < 0; $i = $i->add($one)) {
|
||||
if ($t->powMod($two->pow($i), static::$modulo[$this->instanceID])->equals($one)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($i->compare($m) >= 0) {
|
||||
if ($i->compare($m) == 0) {
|
||||
return false;
|
||||
}
|
||||
$b = $c->powMod($two->pow($m->subtract($i)->subtract($one)), static::$modulo[$this->instanceID]);
|
||||
|
Loading…
Reference in New Issue
Block a user