Skip to content

Commit 5cb46b2

Browse files
committed
test(p-256): cross test with crypto/elliptic
1 parent 37b7836 commit 5cb46b2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

ecc/secp256r1/g1_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package secp256r1
55

66
import (
7+
"crypto/elliptic"
78
crand "crypto/rand"
89
"fmt"
910
"math/big"
@@ -405,6 +406,37 @@ func TestG1AffineOps(t *testing.T) {
405406
properties.TestingRun(t, gopter.ConsoleReporter(false))
406407
}
407408

409+
func TestG1CrossImplementations(t *testing.T) {
410+
t.Parallel()
411+
parameters := gopter.DefaultTestParameters()
412+
if testing.Short() {
413+
parameters.MinSuccessfulTests = nbFuzzShort
414+
} else {
415+
parameters.MinSuccessfulTests = nbFuzz
416+
}
417+
418+
properties := gopter.NewProperties(parameters)
419+
420+
properties.Property("[SECP256R1] ScalarMultiplication should output the same result as crypto/elliptic", prop.ForAll(
421+
func(s fr.Element) bool {
422+
curve := elliptic.P256()
423+
Gx, Gy := curve.Params().Gx, curve.Params().Gy
424+
var S big.Int
425+
s.BigInt(&S)
426+
Qx, Qy := curve.ScalarMult(Gx, Gy, S.Bytes())
427+
var Q G1Affine
428+
Q.ScalarMultiplication(&g1GenAff, &S)
429+
var qx, qy fp.Element
430+
qx.SetBigInt(Qx)
431+
qy.SetBigInt(Qy)
432+
return Q.X.Equal(&qx) && Q.Y.Equal(&qy)
433+
},
434+
GenFr(),
435+
))
436+
437+
properties.TestingRun(t, gopter.ConsoleReporter(false))
438+
}
439+
408440
// ------------------------------------------------------------
409441
// benches
410442

0 commit comments

Comments
 (0)