Skip to content

Commit 1031cc6

Browse files
authored
Replace GMP function calls with overloaded operators (#90)
Fixes #89 (though it really shouldn't).
1 parent d324c80 commit 1031cc6

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ jobs:
7575
run: vendor/bin/phpunit
7676
--coverage-clover coverage.xml
7777
--coverage-text
78-
--printer mheap\\GithubActionsReporter\\Printer
7978

8079
- name: Submit code coverage
8180
if: ${{ always() }}

src/PublicKey/EllipticCurve.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@
1212
use Sop\ASN1\Type as ASN;
1313
use UnexpectedValueException;
1414

15-
use function gmp_pow;
16-
use function gmp_add;
1715
use function gmp_cmp;
1816
use function gmp_import;
19-
use function gmp_mod;
20-
use function gmp_mul;
2117

2218
/**
2319
* @internal
@@ -156,13 +152,15 @@ private function isOnCurve(): bool
156152

157153
// This is only tested with P256 (secp256r1) but SHOULD be the same for
158154
// the other curves (none of which are supported yet)/
159-
$x3 = gmp_pow($x, 3);
160-
$ax = gmp_mul($a, $x);
161-
$rhs = gmp_mod(gmp_add($x3, gmp_add($ax, $b)), $p);
155+
$x3 = $x ** 3; // @phpstan-ignore binaryOp.invalid (phpstan/phpstan#12123)
156+
$ax = $a * $x; // @phpstan-ignore binaryOp.invalid
157+
$rhs = ($x3 + $ax + $b) % $p; // @phpstan-ignore binaryOp.invalid
162158

163-
$y2 = gmp_pow($y, 2);
164-
$lhs = gmp_mod($y2, $p);
159+
$y2 = $y ** 2; // @phpstan-ignore binaryOp.invalid
160+
$lhs = $y2 % $p;
165161

166-
return 0 === gmp_cmp($lhs, $rhs); // Values match
162+
// Functionaly, `$lhs === $rhs` but avoids reference equality issues
163+
// w/out having to introduce loose comparision ($lhs == $rhs works)
164+
return 0 === gmp_cmp($lhs, $rhs);
167165
}
168166
}

0 commit comments

Comments
 (0)