sm9/bn256: add miller benchmark test

This commit is contained in:
emmansun 2023-07-02 11:46:50 +08:00
parent b493f8cb99
commit 1e5ba7f5a1
2 changed files with 16 additions and 2 deletions

View File

@ -162,6 +162,20 @@ func BenchmarkFinalExponentiation(b *testing.B) {
}
}
func BenchmarkMiller(b *testing.B) {
pk := bigFromHex("0130E78459D78545CB54C587E02CF480CE0B66340F319F348A1D5B1F2DC5F4")
g2 := &G2{}
_, err := g2.ScalarBaseMult(NormalizeScalar(pk.Bytes()))
if err != nil {
b.Fatal(err)
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
miller(g2.p, curveGen)
}
}
func BenchmarkPairingB4(b *testing.B) {
pk := bigFromHex("0130E78459D78545CB54C587E02CF480CE0B66340F319F348A1D5B1F2DC5F4")
g2 := &G2{}

View File

@ -58,7 +58,7 @@ func NewTwistGenerator() *twistPoint {
func (c *twistPoint) polynomial(x *gfP2) *gfP2 {
x3 := &gfP2{}
x3.Square(x).Mul(x3, x).Add(x3, twistB)
x3.SquareNC(x).Mul(x3, x).Add(x3, twistB)
return x3
}
@ -70,7 +70,7 @@ func (c *twistPoint) IsOnCurve() bool {
}
y2 := &gfP2{}
y2.Square(&c.y)
y2.SquareNC(&c.y)
x3 := c.polynomial(&c.x)
return *y2 == *x3