crypto/cloudflare/bn256: fix in-place addition and unmarshalling (#23419)

This commit is contained in:
Guillaume Ballet
2021-08-25 17:33:09 +02:00
committed by GitHub
parent d16214228f
commit 887902ea4d
4 changed files with 20 additions and 6 deletions

View File

@ -92,6 +92,19 @@ func TestTripartiteDiffieHellman(t *testing.T) {
}
}
func TestG2SelfAddition(t *testing.T) {
s, _ := rand.Int(rand.Reader, Order)
p := new(G2).ScalarBaseMult(s)
if !p.p.IsOnCurve() {
t.Fatal("p isn't on curve")
}
m := p.Add(p, p).Marshal()
if _, err := p.Unmarshal(m); err != nil {
t.Fatalf("p.Add(p, p) ∉ G₂: %v", err)
}
}
func BenchmarkG1(b *testing.B) {
x, _ := rand.Int(rand.Reader, Order)
b.ResetTimer()