MCPcopy Create free account
hub / github.com/ElementsProject/elements / RecoverCompact

Method RecoverCompact

src/pubkey.cpp:291–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289}
290
291bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig) {
292 if (vchSig.size() != COMPACT_SIGNATURE_SIZE)
293 return false;
294 int recid = (vchSig[0] - 27) & 3;
295 bool fComp = ((vchSig[0] - 27) & 4) != 0;
296 secp256k1_pubkey pubkey;
297 secp256k1_ecdsa_recoverable_signature sig;
298 assert(secp256k1_context_verify && "secp256k1_context_verify must be initialized to use CPubKey.");
299 if (!secp256k1_ecdsa_recoverable_signature_parse_compact(secp256k1_context_verify, &sig, &vchSig[1], recid)) {
300 return false;
301 }
302 if (!secp256k1_ecdsa_recover(secp256k1_context_verify, &pubkey, &sig, hash.begin())) {
303 return false;
304 }
305 unsigned char pub[SIZE];
306 size_t publen = SIZE;
307 secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, fComp ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
308 Set(pub, pub + publen);
309 return true;
310}
311
312bool CPubKey::IsFullyValid() const {
313 if (!IsValid())

Callers 3

BOOST_AUTO_TEST_CASEFunction · 0.80
FUZZ_TARGET_INITFunction · 0.80
MessageVerifyFunction · 0.80

Calls 5

secp256k1_ecdsa_recoverFunction · 0.85
sizeMethod · 0.45
beginMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.64
FUZZ_TARGET_INITFunction · 0.64