| 167 | } |
| 168 | |
| 169 | bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) const { |
| 170 | if (!IsValid()) |
| 171 | return false; |
| 172 | secp256k1_pubkey pubkey; |
| 173 | secp256k1_ecdsa_signature sig; |
| 174 | if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, size())) { |
| 175 | return false; |
| 176 | } |
| 177 | if (!ecdsa_signature_parse_der_lax(secp256k1_context_verify, &sig, vchSig.data(), vchSig.size())) { |
| 178 | return false; |
| 179 | } |
| 180 | /* libsecp256k1's ECDSA verification requires lower-S signatures, which have |
| 181 | * not historically been enforced in Bitcoin, so normalize them first. */ |
| 182 | secp256k1_ecdsa_signature_normalize(secp256k1_context_verify, &sig, &sig); |
| 183 | return secp256k1_ecdsa_verify(secp256k1_context_verify, &sig, hash.begin(), &pubkey); |
| 184 | } |
| 185 | |
| 186 | bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig) { |
| 187 | if (vchSig.size() != COMPACT_SIGNATURE_SIZE) |
no test coverage detected