Changeset View
Changeset View
Standalone View
Standalone View
src/pubkey.cpp
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "pubkey.h" | #include "pubkey.h" | ||||
#include <secp256k1.h> | #include <secp256k1.h> | ||||
#include <secp256k1_recovery.h> | #include <secp256k1_recovery.h> | ||||
namespace { | namespace { | ||||
/* Global secp256k1_context object used for verification. */ | /* Global secp256k1_context object used for verification. */ | ||||
secp256k1_context *secp256k1_context_verify = nullptr; | secp256k1_context *secp256k1_context_verify = nullptr; | ||||
} | } // namespace | ||||
/** | /** | ||||
* This function is taken from the libsecp256k1 distribution and implements DER | * This function is taken from the libsecp256k1 distribution and implements DER | ||||
* parsing for ECDSA signatures, while supporting an arbitrary subset of format | * parsing for ECDSA signatures, while supporting an arbitrary subset of format | ||||
* violations. | * violations. | ||||
* | * | ||||
* Supported violations include negative integers, excessive padding, garbage at | * Supported violations include negative integers, excessive padding, garbage at | ||||
* the end, and overly long length descriptors. This is safe to use in Bitcoin | * the end, and overly long length descriptors. This is safe to use in Bitcoin | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | if (!secp256k1_ecdsa_recoverable_signature_parse_compact( | ||||
return false; | return false; | ||||
} | } | ||||
if (!secp256k1_ecdsa_recover(secp256k1_context_verify, &pubkey, &sig, | if (!secp256k1_ecdsa_recover(secp256k1_context_verify, &pubkey, &sig, | ||||
hash.begin())) { | hash.begin())) { | ||||
return false; | return false; | ||||
} | } | ||||
uint8_t pub[65]; | uint8_t pub[65]; | ||||
size_t publen = 65; | size_t publen = 65; | ||||
secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, | secp256k1_ec_pubkey_serialize( | ||||
&pubkey, fComp ? SECP256K1_EC_COMPRESSED | secp256k1_context_verify, pub, &publen, &pubkey, | ||||
: SECP256K1_EC_UNCOMPRESSED); | fComp ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED); | ||||
Set(pub, pub + publen); | Set(pub, pub + publen); | ||||
return true; | return true; | ||||
} | } | ||||
bool CPubKey::IsFullyValid() const { | bool CPubKey::IsFullyValid() const { | ||||
if (!IsValid()) return false; | if (!IsValid()) 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, | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |