diff --git a/sm9/bn256/g1_test.go b/sm9/bn256/g1_test.go index 58db1c9..ac89ce6 100644 --- a/sm9/bn256/g1_test.go +++ b/sm9/bn256/g1_test.go @@ -9,6 +9,21 @@ import ( "time" ) +func TestG1AddNeg(t *testing.T) { + g1, g2 := &G1{}, &G1{} + + g1.Neg(Gen1) + g2.Add(g1, Gen1) + if !g2.p.IsInfinity() { + t.Fail() + } + g3 := &G1{} + g3.Set(Gen1) + if !g3.Equal(Gen1) { + t.Fail() + } +} + type g1BaseMultTest struct { k string } diff --git a/sm9/bn256/g2_test.go b/sm9/bn256/g2_test.go index 74e51d6..d5fb608 100644 --- a/sm9/bn256/g2_test.go +++ b/sm9/bn256/g2_test.go @@ -93,6 +93,21 @@ func TestScaleMult(t *testing.T) { } } +func TestG2AddNeg(t *testing.T) { + g1, g2 := &G2{}, &G2{} + + g1.Neg(Gen2) + g2.Add(g1, Gen2) + if !g2.p.IsInfinity() { + t.Fail() + } + g3 := &G2{} + g3.Set(Gen2) + if !g3.Equal(Gen2) { + t.Fail() + } +} + func BenchmarkG2(b *testing.B) { x, _ := rand.Int(rand.Reader, Order) b.ReportAllocs() diff --git a/sm9/bn256/gfp12.go b/sm9/bn256/gfp12.go index da97314..6b00595 100644 --- a/sm9/bn256/gfp12.go +++ b/sm9/bn256/gfp12.go @@ -100,13 +100,6 @@ func (e *gfP12) IsOne() bool { return e.x.IsZero() && e.y.IsZero() && e.z.IsOne() } -func (e *gfP12) Neg(a *gfP12) *gfP12 { - e.x.Neg(&a.x) - e.y.Neg(&a.y) - e.z.Neg(&a.z) - return e -} - func (e *gfP12) Add(a, b *gfP12) *gfP12 { e.x.Add(&a.x, &b.x) e.y.Add(&a.y, &b.y) diff --git a/sm9/bn256/gt.go b/sm9/bn256/gt.go index 90ab9f4..cab9390 100644 --- a/sm9/bn256/gt.go +++ b/sm9/bn256/gt.go @@ -68,15 +68,6 @@ func (e *GT) Add(a, b *GT) *GT { return e } -// Neg sets e to -a and then returns e. -func (e *GT) Neg(a *GT) *GT { - if e.p == nil { - e.p = &gfP12{} - } - e.p.Neg(a.p) // TODO: fix it. - return e -} - // Set sets e to a and then returns e. func (e *GT) Set(a *GT) *GT { if e.p == nil {