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> | ||||
#include <secp256k1_schnorr.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 | } // namespace | ||||
/** | /** | ||||
* This function is taken from the libsecp256k1 distribution and implements DER | * This function is taken from the libsecp256k1 distribution and implements DER | ||||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | bool CPubKey::VerifyECDSA(const uint256 &hash, | ||||
* libsecp256k1's ECDSA verification requires lower-S signatures, which have | * libsecp256k1's ECDSA verification requires lower-S signatures, which have | ||||
* not historically been enforced in Bitcoin, so normalize them first. | * not historically been enforced in Bitcoin, so normalize them first. | ||||
*/ | */ | ||||
secp256k1_ecdsa_signature_normalize(secp256k1_context_verify, &sig, &sig); | secp256k1_ecdsa_signature_normalize(secp256k1_context_verify, &sig, &sig); | ||||
return secp256k1_ecdsa_verify(secp256k1_context_verify, &sig, hash.begin(), | return secp256k1_ecdsa_verify(secp256k1_context_verify, &sig, hash.begin(), | ||||
&pubkey); | &pubkey); | ||||
} | } | ||||
bool CPubKey::VerifySchnorr(const uint256 &hash, | |||||
const std::vector<uint8_t> &vchSig) const { | |||||
if (!IsValid()) { | |||||
return false; | |||||
} | |||||
if (vchSig.size() != 64) { | |||||
return false; | |||||
} | |||||
secp256k1_pubkey pubkey; | |||||
if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, | |||||
&(*this)[0], size())) { | |||||
return false; | |||||
} | |||||
return secp256k1_schnorr_verify(secp256k1_context_verify, &vchSig[0], | |||||
hash.begin(), &pubkey); | |||||
} | |||||
bool CPubKey::RecoverCompact(const uint256 &hash, | bool CPubKey::RecoverCompact(const uint256 &hash, | ||||
const std::vector<uint8_t> &vchSig) { | const std::vector<uint8_t> &vchSig) { | ||||
if (vchSig.size() != 65) { | if (vchSig.size() != 65) { | ||||
return false; | return false; | ||||
} | } | ||||
int recid = (vchSig[0] - 27) & 3; | int recid = (vchSig[0] - 27) & 3; | ||||
bool fComp = ((vchSig[0] - 27) & 4) != 0; | bool fComp = ((vchSig[0] - 27) & 4) != 0; | ||||
▲ Show 20 Lines • Show All 129 Lines • Show Last 20 Lines |