mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 12:16:20 +08:00
stealth private key computation mod order
This commit is contained in:
parent
191cd2622d
commit
eeb60b57d0
@ -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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user