Skip to content

Commit

Permalink
Merge pull request #424 from c4dt/g2negfix
Browse files Browse the repository at this point in the history
G2negfix
  • Loading branch information
Jeff R. Allen committed Jul 23, 2020
2 parents 8836b44 + 29b3a97 commit 0115c49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions pairing/bn256/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,32 @@ func Test_g2_2add_oncurve_issue400(t *testing.T) {
err = p.UnmarshalBinary(ma)
require.NoError(t, err)
}

func getNegs(g kyber.Group) (neg1, neg2 kyber.Point) {
base := g.Point().Base()
// Use Neg to get the negation
neg1 = g.Point().Neg(base)
// Multiply by -1 to get the negation
minus1 := g.Scalar().SetInt64(-1)
neg2 = g.Point().Mul(minus1, base)

return
}

// Test doing pairings with points produced by G1 and G2's Neg function,
// as well as by multiplying with -1.
// All four possible combinations are tried and tested.
// This fails for neg21-pairs in kyber 3.0.11.
func TestNegPairAll(t *testing.T) {
neg11, neg12 := getNegs(NewSuiteG1())
neg21, neg22 := getNegs(NewSuiteG2())

pair1 := NewSuite().Pair(neg11, neg21)
pair2 := NewSuite().Pair(neg11, neg22)
pair3 := NewSuite().Pair(neg12, neg21)
pair4 := NewSuite().Pair(neg12, neg22)

require.True(t, pair1.Equal(pair2))
require.True(t, pair2.Equal(pair3))
require.True(t, pair3.Equal(pair4))
}
2 changes: 1 addition & 1 deletion pairing/bn256/twist.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (c *twistPoint) Neg(a *twistPoint) {
c.x.Set(&a.x)
c.y.Neg(&a.y)
c.z.Set(&a.z)
c.t.SetZero()
c.t.Set(&a.t)
}

// Clone makes a hard copy of the point
Expand Down

0 comments on commit 0115c49

Please sign in to comment.