mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-27 04:36:19 +08:00
MAGIC - move public key check out of loop
This commit is contained in:
parent
2dd11a9e9a
commit
586ab84f33
@ -192,6 +192,10 @@ func Encrypt(random io.Reader, pub *ecdsa.PublicKey, msg []byte, opts *Encrypter
|
||||
if opts == nil {
|
||||
opts = &defaultEncrypterOpts
|
||||
}
|
||||
//A3, requirement is to check if h*P is infinite point, h is 1
|
||||
if (pub.X.Sign() == 0 && pub.Y.Sign() == 0) || !curve.IsOnCurve(pub.X, pub.Y) {
|
||||
return nil, errors.New("SM2: invalid public key")
|
||||
}
|
||||
for {
|
||||
//A1, generate random k
|
||||
k, err := randFieldElement(curve, random)
|
||||
@ -203,11 +207,6 @@ func Encrypt(random io.Reader, pub *ecdsa.PublicKey, msg []byte, opts *Encrypter
|
||||
x1, y1 := curve.ScalarBaseMult(k.Bytes())
|
||||
c1 := opts.PointMarshalMode.mashal(curve, x1, y1)
|
||||
|
||||
//A3, requirement is to check if h*P is infinite point, h is 1
|
||||
if !curve.IsOnCurve(pub.X, pub.Y) {
|
||||
return nil, errors.New("SM2: invalid public key")
|
||||
}
|
||||
|
||||
//A4, calculate k * P (point of Public Key)
|
||||
x2, y2 := curve.ScalarMult(pub.X, pub.Y, k.Bytes())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user