(pub *PublicKey, msg, uid []byte, r, s *big.Int)
| 165 | return |
| 166 | } |
| 167 | func 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) |
no test coverage detected
searching dependent graphs…