2023-03-05 16:44:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace phpseclib3\Tests\Unit\Math;
|
|
|
|
|
|
|
|
use phpseclib3\Math\BigInteger;
|
|
|
|
use phpseclib3\Math\PrimeField;
|
|
|
|
use phpseclib3\Tests\PhpseclibTestCase;
|
|
|
|
|
|
|
|
class PrimeFieldTest extends PhpseclibTestCase
|
|
|
|
{
|
|
|
|
public function testPrimeFieldWithCompositeNumbers()
|
|
|
|
{
|
|
|
|
$this->expectException('UnexpectedValueException');
|
|
|
|
|
|
|
|
$a = new BigInteger('65', 10);
|
|
|
|
$p = new BigInteger('126', 10); // 126 isn't a prime
|
|
|
|
|
|
|
|
$num = new PrimeField($p);
|
|
|
|
$num2 = $num->newInteger($a);
|
|
|
|
|
2023-11-02 01:23:28 +00:00
|
|
|
$num2->squareRoot();
|
2023-03-05 16:44:39 +00:00
|
|
|
}
|
2023-07-27 02:23:08 +00:00
|
|
|
|
2023-11-02 00:27:15 +00:00
|
|
|
public function testPrimeFieldWithPrimeNumbers()
|
|
|
|
{
|
|
|
|
$a = new BigInteger('65', 10);
|
|
|
|
$p = new BigInteger('127', 10);
|
|
|
|
|
|
|
|
$num = new PrimeField($p);
|
|
|
|
$num2 = $num->newInteger($a);
|
|
|
|
|
2023-11-02 01:23:28 +00:00
|
|
|
$this->assertFalse($num2->squareRoot());
|
2023-11-02 00:27:15 +00:00
|
|
|
}
|
|
|
|
|
2023-07-27 02:23:08 +00:00
|
|
|
/**
|
|
|
|
* @group github1929
|
|
|
|
*/
|
|
|
|
public function testGarbageCollectedToBytes()
|
|
|
|
{
|
|
|
|
$blob = base64_decode('BFgsTFQeqKr0toyURbtT43INMDS7FTHjz3yn3MR1/Yv/pb2b9ZCYNQ/Tafe5hQpEJ4TpZOKfikP/hWZvFL8QCPgqbIGqw/KTfA==');
|
|
|
|
$public = "\0" . substr($blob, 0, 49);
|
|
|
|
$private = substr($blob, -24);
|
|
|
|
|
|
|
|
$point = \phpseclib3\Crypt\EC\Formats\Keys\PKCS1::extractPoint(
|
|
|
|
$public,
|
|
|
|
new \phpseclib3\Crypt\EC\Curves\secp192r1()
|
|
|
|
);
|
|
|
|
|
2023-07-27 02:54:02 +00:00
|
|
|
$this->assertIsString($point[0]->toBytes());
|
2023-07-27 02:23:08 +00:00
|
|
|
}
|
2023-03-05 16:44:39 +00:00
|
|
|
}
|