Changeset View
Changeset View
Standalone View
Standalone View
src/pubkey.cpp
Show First 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | |||||
bool CPubKey::VerifyECDSA(const uint256 &hash, | bool CPubKey::VerifyECDSA(const uint256 &hash, | ||||
const std::vector<uint8_t> &vchSig) const { | const std::vector<uint8_t> &vchSig) const { | ||||
if (!IsValid()) { | if (!IsValid()) { | ||||
return false; | return false; | ||||
} | } | ||||
secp256k1_pubkey pubkey; | secp256k1_pubkey pubkey; | ||||
secp256k1_ecdsa_signature sig; | secp256k1_ecdsa_signature sig; | ||||
if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, | if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, | ||||
&(*this)[0], size())) { | size())) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!ecdsa_signature_parse_der_lax(secp256k1_context_verify, &sig, | if (!ecdsa_signature_parse_der_lax(secp256k1_context_verify, &sig, | ||||
vchSig.data(), vchSig.size())) { | vchSig.data(), vchSig.size())) { | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* libsecp256k1's ECDSA verification requires lower-S signatures, which have | * libsecp256k1's ECDSA verification requires lower-S signatures, which have | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | bool CPubKey::RecoverCompact(const uint256 &hash, | ||||
return true; | return true; | ||||
} | } | ||||
bool CPubKey::IsFullyValid() const { | bool CPubKey::IsFullyValid() const { | ||||
if (!IsValid()) { | if (!IsValid()) { | ||||
return false; | return false; | ||||
} | } | ||||
secp256k1_pubkey pubkey; | secp256k1_pubkey pubkey; | ||||
return secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, | return secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, | ||||
&(*this)[0], size()); | size()); | ||||
} | } | ||||
bool CPubKey::Decompress() { | bool CPubKey::Decompress() { | ||||
if (!IsValid()) { | if (!IsValid()) { | ||||
return false; | return false; | ||||
} | } | ||||
secp256k1_pubkey pubkey; | secp256k1_pubkey pubkey; | ||||
if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, | if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, | ||||
&(*this)[0], size())) { | size())) { | ||||
return false; | return false; | ||||
} | } | ||||
uint8_t pub[PUBLIC_KEY_SIZE]; | uint8_t pub[PUBLIC_KEY_SIZE]; | ||||
size_t publen = PUBLIC_KEY_SIZE; | size_t publen = PUBLIC_KEY_SIZE; | ||||
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, | secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, | ||||
&pubkey, SECP256K1_EC_UNCOMPRESSED); | &pubkey, SECP256K1_EC_UNCOMPRESSED); | ||||
Set(pub, pub + publen); | Set(pub, pub + publen); | ||||
return true; | return true; | ||||
} | } | ||||
bool CPubKey::Derive(CPubKey &pubkeyChild, ChainCode &ccChild, | bool CPubKey::Derive(CPubKey &pubkeyChild, ChainCode &ccChild, | ||||
unsigned int nChild, const ChainCode &cc) const { | unsigned int nChild, const ChainCode &cc) const { | ||||
assert(IsValid()); | assert(IsValid()); | ||||
assert((nChild >> 31) == 0); | assert((nChild >> 31) == 0); | ||||
assert(size() == COMPRESSED_PUBLIC_KEY_SIZE); | assert(size() == COMPRESSED_PUBLIC_KEY_SIZE); | ||||
uint8_t out[64]; | uint8_t out[64]; | ||||
BIP32Hash(cc, nChild, *begin(), begin() + 1, out); | BIP32Hash(cc, nChild, *begin(), begin() + 1, out); | ||||
memcpy(ccChild.begin(), out + 32, 32); | memcpy(ccChild.begin(), out + 32, 32); | ||||
secp256k1_pubkey pubkey; | secp256k1_pubkey pubkey; | ||||
if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, | if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, | ||||
&(*this)[0], size())) { | size())) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!secp256k1_ec_pubkey_tweak_add(secp256k1_context_verify, &pubkey, | if (!secp256k1_ec_pubkey_tweak_add(secp256k1_context_verify, &pubkey, | ||||
out)) { | out)) { | ||||
return false; | return false; | ||||
} | } | ||||
uint8_t pub[COMPRESSED_PUBLIC_KEY_SIZE]; | uint8_t pub[COMPRESSED_PUBLIC_KEY_SIZE]; | ||||
size_t publen = COMPRESSED_PUBLIC_KEY_SIZE; | size_t publen = COMPRESSED_PUBLIC_KEY_SIZE; | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |