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

famoser / elliptic / 16437972044

22 Jul 2025 07:42AM UTC coverage: 95.58% (+0.1%) from 95.437%
16437972044

Pull #12

github

web-flow
Merge 90594b1b9 into 85d13e57a
Pull Request #12: WIP: Add montgomery

567 of 589 new or added lines in 35 files covered. (96.26%)

1211 of 1267 relevant lines covered (95.58%)

22.1 hits per line

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

93.33
/src/Serializer/PointDecoder/Traits/FromXCoordinateTrait.php
1
<?php
2

3
namespace Famoser\Elliptic\Serializer\PointDecoder\Traits;
4

5
use Famoser\Elliptic\Primitives\Point;
6
use Famoser\Elliptic\Serializer\PointDecoder\PointDecoderException;
7

8
trait FromXCoordinateTrait
9
{
10
    use PMod43RecoveryTrait;
11
    use PMod85RecoveryTrait;
12

13
    /**
14
     * @throws PointDecoderException
15
     */
16
    public function fromXCoordinate(\GMP $x, ?bool $isEvenY = null): Point
10✔
17
    {
18
        $p = $this->curve->getP();
10✔
19
        $pMod8 = gmp_mod($p, 8);
10✔
20
        if (gmp_cmp($pMod8, 5) === 0) {
10✔
21
            return $this->recoverXForPMod85($x);
4✔
22
        }
23

24
        $pMod4 = gmp_mod($pMod8, 4);
6✔
25
        if (gmp_cmp($pMod4, 3) === 0) {
6✔
26
            if ($isEvenY === null) {
5✔
NEW
27
                throw new PointDecoderException('Point decoding for p mod 4 = 3 needs isEvenY to be defined.');
×
28
            }
29

30
            $beta = $this->recoverXForPMod43($x);
5✔
31

32
            $yp = $isEvenY ? gmp_init(0) : gmp_init(1);
4✔
33
            if (gmp_cmp(gmp_mod($beta, 2), $yp) === 0) {
4✔
34
                return new Point($x, $beta);
2✔
35
            } else {
36
                return new Point($x, gmp_sub($p, $beta));
2✔
37
            }
38
        }
39

40
        throw new PointDecoderException('No general point decoding implemented (e.g. via Tonelli-Shanks), only for special cases p mod 8 = 5 and p mod 4 = 3.');
1✔
41
    }
42
}
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