mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 20:26:19 +08:00
fix defect
This commit is contained in:
parent
eedd5ebc2b
commit
7ebdf00640
@ -337,8 +337,7 @@ func Encrypt(random io.Reader, pub *ecdsa.PublicKey, msg []byte, opts *Encrypter
|
||||
//A5, calculate t=KDF(x2||y2, klen)
|
||||
var kdfCount int = 0
|
||||
c2 := kdf.Kdf(sm3.New(), append(toBytes(curve, x2), toBytes(curve, y2)...), msgLen)
|
||||
success := subtle.ConstantTimeAllZero(c2)
|
||||
if !success {
|
||||
if subtle.ConstantTimeAllZero(c2) {
|
||||
kdfCount++
|
||||
if kdfCount > maxRetryLimit {
|
||||
return nil, fmt.Errorf("sm2: A5, failed to calculate valid t, tried %v times", kdfCount)
|
||||
@ -399,8 +398,7 @@ func rawDecrypt(priv *PrivateKey, x1, y1 *big.Int, c2, c3 []byte) ([]byte, error
|
||||
x2, y2 := curve.ScalarMult(x1, y1, priv.D.Bytes())
|
||||
msgLen := len(c2)
|
||||
msg := kdf.Kdf(sm3.New(), append(toBytes(curve, x2), toBytes(curve, y2)...), msgLen)
|
||||
success := subtle.ConstantTimeAllZero(c2)
|
||||
if !success {
|
||||
if subtle.ConstantTimeAllZero(c2) {
|
||||
return nil, errors.New("sm2: invalid cipher text")
|
||||
}
|
||||
|
||||
|
@ -228,8 +228,7 @@ func WrapKey(rand io.Reader, pub *EncryptMasterPublicKey, uid []byte, hid byte,
|
||||
buffer = append(buffer, uid...)
|
||||
|
||||
key = kdf.Kdf(sm3.New(), buffer, kLen)
|
||||
ok = subtle.ConstantTimeAllZero(key)
|
||||
if ok {
|
||||
if !subtle.ConstantTimeAllZero(key) {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -300,8 +299,7 @@ func UnwrapKey(priv *EncryptPrivateKey, uid []byte, cipher *bn256.G1, kLen int)
|
||||
buffer = append(buffer, uid...)
|
||||
|
||||
key := kdf.Kdf(sm3.New(), buffer, kLen)
|
||||
ok := subtle.ConstantTimeAllZero(key)
|
||||
if !ok {
|
||||
if subtle.ConstantTimeAllZero(key) {
|
||||
return nil, errors.New("sm9: invalid cipher")
|
||||
}
|
||||
return key, nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user