Skip to content

Commit

Permalink
fix: ECPoint.ScalarMult
Browse files Browse the repository at this point in the history
  • Loading branch information
felicityin committed Jul 9, 2024
1 parent 7113b68 commit 6c9bb9b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crypto/ecpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func (p *ECPoint) Add(p1 *ECPoint) (*ECPoint, error) {
}

func (p *ECPoint) ScalarMult(k *big.Int) *ECPoint {
x, y := p.curve.ScalarMult(p.X(), p.Y(), k.Bytes())
kModN := new(big.Int).Mod(k, p.curve.Params().N)
x, y := p.curve.ScalarMult(p.X(), p.Y(), kModN.Bytes())
newP, err := NewECPoint(p.curve, x, y) // it must be on the curve, no need to check.
if err != nil {
panic(fmt.Errorf("scalar mult to an ecpoint %s", err.Error()))
Expand Down Expand Up @@ -105,7 +106,8 @@ func (p *ECPoint) EightInvEight() *ECPoint {
}

func ScalarBaseMult(curve elliptic.Curve, k *big.Int) *ECPoint {
x, y := curve.ScalarBaseMult(k.Bytes())
kModN := new(big.Int).Mod(k, curve.Params().N)
x, y := curve.ScalarBaseMult(kModN.Bytes())
p, err := NewECPoint(curve, x, y) // it must be on the curve, no need to check.
if err != nil {
panic(fmt.Errorf("scalar mult to an ecpoint %s", err.Error()))
Expand Down

0 comments on commit 6c9bb9b

Please sign in to comment.