Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clone points to avoid race condition issues #17

Merged
merged 4 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion kyber_g1.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ func (k *KyberG1) Mul(s kyber.Scalar, q kyber.Point) kyber.Point {
}

func (k *KyberG1) MarshalBinary() ([]byte, error) {
return bls12381.NewG1().ToCompressed(k.p), nil
// we need to clone the point because of https://github.com/kilic/bls12-381/issues/37
// in order to avoid risks of race conditions.
t := new(bls12381.PointG1).Set(k.p)
return bls12381.NewG1().ToCompressed(t), nil
}

func (k *KyberG1) UnmarshalBinary(buff []byte) error {
Expand Down
10 changes: 8 additions & 2 deletions kyber_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,14 @@ func (s *Suite) GT() kyber.Group {
// ValidatePairing implements the `pairing.Suite` interface
func (s *Suite) ValidatePairing(p1, p2, p3, p4 kyber.Point) bool {
e := bls12381.NewEngine()
e.AddPair(p1.(*KyberG1).p, p2.(*KyberG2).p)
e.AddPairInv(p3.(*KyberG1).p, p4.(*KyberG2).p)
// we need to clone the point because of https://github.com/kilic/bls12-381/issues/37
// in order to avoid risks of race conditions.
g1point := new(bls12381.PointG1).Set(p1.(*KyberG1).p)
g2point := new(bls12381.PointG2).Set(p2.(*KyberG2).p)
g1point2 := p3.(*KyberG1).p
g2point2 := new(bls12381.PointG2).Set(p4.(*KyberG2).p)
e.AddPair(g1point, g2point)
e.AddPairInv(g1point2, g2point2)
return e.Check()
}

Expand Down