Skip to content

Commit

Permalink
fix: elliptic curve subtraction on proper ec points (#70)
Browse files Browse the repository at this point in the history
* fix issue on elliptic curve addition with negative points that were not remapped back to a proper curve point

* set back minimum version to go 1.16
  • Loading branch information
juanli16 authored Oct 11, 2022
1 parent b48dae0 commit aafd40a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ require (
github.com/twmb/murmur3 v1.1.6
github.com/zeebo/blake3 v0.2.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
)

require golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
7 changes: 6 additions & 1 deletion internal/crypto/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ func (p *Point) ScalarMult(scalar []byte) *Point {

// Sub substracts point p from q
func (p *Point) Sub(q *Point) *Point {
// in order to do point subtraction, we need to make sure
// the negative point is still mapped properly in the field elements.
negQy := new(big.Int).Neg(q.y)
negQy = negQy.Mod(negQy, curve.Params().P) // here P is the order of the curve field

// p - q = p.x + q.x, p.y - q.y
x, y := curve.Add(p.x, p.y, q.x, new(big.Int).Neg(q.y))
x, y := curve.Add(p.x, p.y, q.x, negQy)
return &Point{x: x, y: y}
}

Expand Down

0 comments on commit aafd40a

Please sign in to comment.