stealth private key computation mod order

This commit is contained in:
Sun Yimin 2024-11-28 10:15:57 +08:00 committed by GitHub
parent 191cd2622d
commit eeb60b57d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -57,7 +57,7 @@ func (c *sm2Curve) newPrivateKey(key []byte, checkOrderMinus1 bool) (*PrivateKey
if len(key) != len(c.scalarOrder) { if len(key) != len(c.scalarOrder) {
return nil, errors.New("ecdh: invalid private key size") 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 nil, errInvalidPrivateKey
} }
return &PrivateKey{ return &PrivateKey{
@ -161,7 +161,7 @@ func (c *sm2Curve) addPrivateKeys(a, b *PrivateKey) (*PrivateKey, error) {
return nil, err return nil, err
} }
aNat = aNat.Add(bNat, m) 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) { func (c *sm2Curve) secretKey(local *PrivateKey, remote *PublicKey) ([]byte, error) {