2023-03-05 16:44:39 +00:00
|
|
|
<?php
|
|
|
|
|
2023-06-04 16:12:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-03-05 16:44:39 +00:00
|
|
|
namespace phpseclib3\Tests\Unit\Math;
|
|
|
|
|
|
|
|
use phpseclib3\Math\BigInteger;
|
|
|
|
use phpseclib3\Math\PrimeField;
|
|
|
|
use phpseclib3\Tests\PhpseclibTestCase;
|
|
|
|
|
|
|
|
class PrimeFieldTest extends PhpseclibTestCase
|
|
|
|
{
|
2023-03-31 08:43:58 +00:00
|
|
|
public function testPrimeFieldWithCompositeNumbers(): void
|
2023-03-05 16:44:39 +00:00
|
|
|
{
|
|
|
|
$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 01:26:03 +00:00
|
|
|
public function testPrimeFieldWithPrimeNumbers(): void
|
2023-11-02 00:27:15 +00:00
|
|
|
{
|
|
|
|
$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
|
|
|
|
*/
|
2023-09-25 16:14:46 +00:00
|
|
|
public function testGarbageCollectedToBytes(): void
|
2023-07-27 02:23:08 +00:00
|
|
|
{
|
|
|
|
$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
|
|
|
}
|