MCPcopy
hub / github.com/tjfoc/gmsm / Sm2Verify

Function Sm2Verify

sm2/sm2.go:167–201  ·  view source on GitHub ↗
(pub *PublicKey, msg, uid []byte, r, s *big.Int)

Source from the content-addressed store, hash-verified

165 return
166}
167func Sm2Verify(pub *PublicKey, msg, uid []byte, r, s *big.Int) bool {
168 c := pub.Curve
169 N := c.Params().N
170 one := new(big.Int).SetInt64(1)
171 if r.Cmp(one) < 0 || s.Cmp(one) < 0 {
172 return false
173 }
174 if r.Cmp(N) >= 0 || s.Cmp(N) >= 0 {
175 return false
176 }
177 if len(uid) == 0 {
178 uid = default_uid
179 }
180 za, err := ZA(pub, uid)
181 if err != nil {
182 return false
183 }
184 e, err := msgHash(za, msg)
185 if err != nil {
186 return false
187 }
188 t := new(big.Int).Add(r, s)
189 t.Mod(t, N)
190 if t.Sign() == 0 {
191 return false
192 }
193 var x *big.Int
194 x1, y1 := c.ScalarBaseMult(s.Bytes())
195 x2, y2 := c.ScalarMult(pub.X, pub.Y, t.Bytes())
196 x, _ = c.Add(x1, y1, x2, y2)
197
198 x.Add(x, e)
199 x.Mod(x, N)
200 return x.Cmp(r) == 0
201}
202
203/*
204 za, err := ZA(pub, uid)

Callers 2

checkSignatureFunction · 0.92
VerifyMethod · 0.85

Calls 7

ZAFunction · 0.85
msgHashFunction · 0.85
ParamsMethod · 0.80
SignMethod · 0.80
ScalarBaseMultMethod · 0.80
ScalarMultMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…