Skip to content

Commit

Permalink
stealth private key computation mod order
Browse files Browse the repository at this point in the history
  • Loading branch information
emmansun authored Nov 28, 2024
1 parent 191cd26 commit eeb60b5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ecdh/sm2ec.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *sm2Curve) newPrivateKey(key []byte, checkOrderMinus1 bool) (*PrivateKey
if len(key) != len(c.scalarOrder) {
return nil, errors.New("ecdh: invalid private key size")
}
if subtle.ConstantTimeAllZero(key) == 1 || (checkOrderMinus1 && !isLess(key, c.scalarOrderMinus1)) {
if subtle.ConstantTimeAllZero(key) == 1 || !isLess(key, c.scalarOrder) || (checkOrderMinus1 && !isLess(key, c.scalarOrderMinus1)) {
return nil, errInvalidPrivateKey
}
return &PrivateKey{
Expand Down Expand Up @@ -161,7 +161,7 @@ func (c *sm2Curve) addPrivateKeys(a, b *PrivateKey) (*PrivateKey, error) {
return nil, err
}
aNat = aNat.Add(bNat, m)
return c.NewPrivateKey(aNat.Bytes(m))
return c.newPrivateKey(aNat.Bytes(m), false)
}

func (c *sm2Curve) secretKey(local *PrivateKey, remote *PublicKey) ([]byte, error) {
Expand Down

0 comments on commit eeb60b5

Please sign in to comment.