PrimeField: prevent infinite loop with composite primefields

This commit is contained in:
terrafrost 2023-03-02 03:25:08 -06:00
parent 3b6030d887
commit 6298d1cd55
2 changed files with 8 additions and 8 deletions

View File

@ -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);

View File

@ -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]);