| 271 | |
| 272 | |
| 273 | bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) const { |
| 274 | if (!IsValid()) |
| 275 | return false; |
| 276 | secp256k1_pubkey pubkey; |
| 277 | secp256k1_ecdsa_signature sig; |
| 278 | assert(secp256k1_context_verify && "secp256k1_context_verify must be initialized to use CPubKey."); |
| 279 | if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, size())) { |
| 280 | return false; |
| 281 | } |
| 282 | if (!ecdsa_signature_parse_der_lax(secp256k1_context_verify, &sig, vchSig.data(), vchSig.size())) { |
| 283 | return false; |
| 284 | } |
| 285 | /* libsecp256k1's ECDSA verification requires lower-S signatures, which have |
| 286 | * not historically been enforced in Bitcoin, so normalize them first. */ |
| 287 | secp256k1_ecdsa_signature_normalize(secp256k1_context_verify, &sig, &sig); |
| 288 | return secp256k1_ecdsa_verify(secp256k1_context_verify, &sig, hash.begin(), &pubkey); |
| 289 | } |
| 290 | |
| 291 | bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig) { |
| 292 | if (vchSig.size() != COMPACT_SIGNATURE_SIZE) |
no test coverage detected