mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-28 12:10:59 +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)
|
public function __construct(BigInteger $modulo)
|
||||||
{
|
{
|
||||||
//if (!$modulo->isPrime()) {
|
if (!$modulo->isPrime()) {
|
||||||
// throw new \UnexpectedValueException('PrimeField requires a prime number be passed to the constructor');
|
throw new \UnexpectedValueException('PrimeField requires a prime number be passed to the constructor');
|
||||||
//}
|
}
|
||||||
|
|
||||||
$this->instanceID = self::$instanceCounter++;
|
$this->instanceID = self::$instanceCounter++;
|
||||||
Integer::setModulo($this->instanceID, $modulo);
|
Integer::setModulo($this->instanceID, $modulo);
|
||||||
|
@ -263,13 +263,13 @@ class Integer extends Base
|
|||||||
$r = $this->value->powMod($temp, static::$modulo[$this->instanceID]);
|
$r = $this->value->powMod($temp, static::$modulo[$this->instanceID]);
|
||||||
|
|
||||||
while (!$t->equals($one)) {
|
while (!$t->equals($one)) {
|
||||||
$i = clone $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)) {
|
||||||
while (!$t->powMod($two->pow($i), static::$modulo[$this->instanceID])->equals($one)) {
|
break;
|
||||||
$i = $i->add($one);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($i->compare($m) >= 0) {
|
if ($i->compare($m) == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$b = $c->powMod($two->pow($m->subtract($i)->subtract($one)), static::$modulo[$this->instanceID]);
|
$b = $c->powMod($two->pow($m->subtract($i)->subtract($one)), static::$modulo[$this->instanceID]);
|
||||||
|
Loading…
Reference in New Issue
Block a user