File: TestCase.php

package info (click to toggle)
php-phpseclib3 3.0.46-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,528 kB
  • sloc: php: 30,756; xml: 392; makefile: 21
file content (61 lines) | stat: -rw-r--r-- 1,665 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

namespace phpseclib3\Tests\Unit\Math\PrimeField;

use phpseclib3\Math\BigInteger;
use phpseclib3\Math\PrimeField;
use phpseclib3\Tests\PhpseclibTestCase;

abstract class TestCase 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);

        $num2->squareRoot();
    }

    public function testPrimeFieldWithPrimeNumbers()
    {
        $a = new BigInteger('65', 10);
        $p = new BigInteger('127', 10);

        $num = new PrimeField($p);
        $num2 = $num->newInteger($a);

        $this->assertFalse($num2->squareRoot());
    }

    /**
     * @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()
        );

        $this->assertIsString($point[0]->toBytes());
    }

    /**
     * @group github2087
     */
    public function testZero()
    {
        $factory = new PrimeField(new BigInteger('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED', 16));
        $zero = $factory->newInteger(new BigInteger(0));
        $this->assertSame('0', "$zero");
    }
}