• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

famoser / elliptic / 16575888417

28 Jul 2025 05:28PM UTC coverage: 97.719% (+2.1%) from 95.58%
16575888417

Pull #15

github

web-flow
Merge 6503eb405 into d917b1701
Pull Request #15: Improve bernstein math

250 of 252 new or added lines in 31 files covered. (99.21%)

6 existing lines in 1 file now uncovered.

1371 of 1403 relevant lines covered (97.72%)

40.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/src/Serializer/PointDecoder/MGPointDecoder.php
1
<?php
2

3
namespace Famoser\Elliptic\Serializer\PointDecoder;
4

5
use Famoser\Elliptic\Primitives\Curve;
6
use Famoser\Elliptic\Primitives\CurveType;
7
use Famoser\Elliptic\Serializer\PointDecoder\Traits\FromCoordinatesTrait;
8
use Famoser\Elliptic\Serializer\PointDecoder\Traits\FromXCoordinateTrait;
9
use Famoser\Elliptic\Serializer\SEC\SECPointDecoderInterface;
10

11
class MGPointDecoder implements SECPointDecoderInterface
12
{
13
    use FromCoordinatesTrait;
14
    use FromXCoordinateTrait;
15

16
    public function __construct(private readonly Curve $curve)
8✔
17
    {
18
        // check allowed to use this decoder
19
        $check = $curve->getType() === CurveType::Montgomery;
8✔
20
        if (!$check) {
8✔
21
            throw new \AssertionError('Cannot use this decoder with the chosen curve.');
1✔
22
        }
23
    }
24

25
    /**
26
     * calculate b * y^2
27
     */
28
    private function calculateLeftSide(\GMP $y): \GMP
4✔
29
    {
30
        return gmp_mul(
4✔
31
            $this->curve->getB(),
4✔
32
            gmp_pow($y, 2)
4✔
33
        );
4✔
34
    }
35

36
    /**
37
     * calculate x^3 + ax^2 + x
38
     */
39
    private function calculateRightSide(\GMP $x): \GMP
7✔
40
    {
41
        return gmp_add(
7✔
42
            gmp_add(
7✔
43
                gmp_powm($x, 3, $this->curve->getP()),
7✔
44
                gmp_mul(
7✔
45
                    $this->curve->getA(),
7✔
46
                    gmp_pow($x, 2)
7✔
47
                )
7✔
48
            ),
7✔
49
            $x
7✔
50
        );
7✔
51
    }
52

53
    /**
54
     * calculate (x^3 + ax^2 + x) / b
55
     */
UNCOV
56
    private function calculateAlpha(\GMP $x): \GMP
×
57
    {
UNCOV
58
        $right = $this->calculateRightSide($x);
×
UNCOV
59
        return gmp_mul(
×
UNCOV
60
            $right,
×
61
            /** @phpstan-ignore-next-line */
UNCOV
62
            gmp_invert($this->curve->getB(), $this->curve->getP())
×
UNCOV
63
        );
×
64
    }
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc