mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-21 17:56:19 +08:00
sm2: recover public keys
This commit is contained in:
parent
63affe5127
commit
7bb7903ce2
11
sm2/sm2.go
11
sm2/sm2.go
@ -747,18 +747,11 @@ func RecoverPublicKeysFromSM2Signature(hash, sig []byte) ([]*ecdsa.PublicKey, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rx = r - e
|
// Rx = r - e
|
||||||
if r.CmpGeq(e) == 0 {
|
r.Sub(e, c.N)
|
||||||
// If r < e, then Rx = N - e + r
|
|
||||||
n0 := bigmod.NewNat().Set(c.N.Nat())
|
|
||||||
n0.Sub(e, c.P)
|
|
||||||
r.Add(n0, c.P)
|
|
||||||
} else {
|
|
||||||
r.Sub(e, c.P)
|
|
||||||
}
|
|
||||||
if r.IsZero() == 1 {
|
if r.IsZero() == 1 {
|
||||||
return nil, ErrInvalidSignature
|
return nil, ErrInvalidSignature
|
||||||
}
|
}
|
||||||
rBytes = r.Bytes(c.P)
|
rBytes = r.Bytes(c.N)
|
||||||
tmp := make([]byte, len(rBytes)+1)
|
tmp := make([]byte, len(rBytes)+1)
|
||||||
copy(tmp[1:], rBytes)
|
copy(tmp[1:], rBytes)
|
||||||
compressFlags := []byte{compressed02, compressed03}
|
compressFlags := []byte{compressed02, compressed03}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user