Changeset View
Changeset View
Standalone View
Standalone View
src/key.cpp
Show First 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | CPubKey CKey::GetPubKey() const { | ||||
secp256k1_ec_pubkey_serialize( | secp256k1_ec_pubkey_serialize( | ||||
secp256k1_context_sign, (uint8_t *)result.begin(), &clen, &pubkey, | secp256k1_context_sign, (uint8_t *)result.begin(), &clen, &pubkey, | ||||
fCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED); | fCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED); | ||||
assert(result.size() == clen); | assert(result.size() == clen); | ||||
assert(result.IsValid()); | assert(result.IsValid()); | ||||
return result; | return result; | ||||
} | } | ||||
bool CKey::Sign(const uint256 &hash, std::vector<uint8_t> &vchSig, | bool CKey::SignECDSA(const uint256 &hash, std::vector<uint8_t> &vchSig, | ||||
uint32_t test_case) const { | uint32_t test_case) const { | ||||
if (!fValid) return false; | if (!fValid) return false; | ||||
vchSig.resize(72); | vchSig.resize(72); | ||||
size_t nSigLen = 72; | size_t nSigLen = 72; | ||||
uint8_t extra_entropy[32] = {0}; | uint8_t extra_entropy[32] = {0}; | ||||
WriteLE32(extra_entropy, test_case); | WriteLE32(extra_entropy, test_case); | ||||
secp256k1_ecdsa_signature sig; | secp256k1_ecdsa_signature sig; | ||||
int ret = secp256k1_ecdsa_sign(secp256k1_context_sign, &sig, hash.begin(), | int ret = secp256k1_ecdsa_sign(secp256k1_context_sign, &sig, hash.begin(), | ||||
begin(), secp256k1_nonce_function_rfc6979, | begin(), secp256k1_nonce_function_rfc6979, | ||||
Show All 13 Lines | bool CKey::VerifyPubKey(const CPubKey &pubkey) const { | ||||
std::string str = "Bitcoin key verification\n"; | std::string str = "Bitcoin key verification\n"; | ||||
GetRandBytes(rnd, sizeof(rnd)); | GetRandBytes(rnd, sizeof(rnd)); | ||||
uint256 hash; | uint256 hash; | ||||
CHash256() | CHash256() | ||||
.Write((uint8_t *)str.data(), str.size()) | .Write((uint8_t *)str.data(), str.size()) | ||||
.Write(rnd, sizeof(rnd)) | .Write(rnd, sizeof(rnd)) | ||||
.Finalize(hash.begin()); | .Finalize(hash.begin()); | ||||
std::vector<uint8_t> vchSig; | std::vector<uint8_t> vchSig; | ||||
Sign(hash, vchSig); | SignECDSA(hash, vchSig); | ||||
return pubkey.Verify(hash, vchSig); | return pubkey.VerifyECDSA(hash, vchSig); | ||||
} | } | ||||
bool CKey::SignCompact(const uint256 &hash, | bool CKey::SignCompact(const uint256 &hash, | ||||
std::vector<uint8_t> &vchSig) const { | std::vector<uint8_t> &vchSig) const { | ||||
if (!fValid) return false; | if (!fValid) return false; | ||||
vchSig.resize(65); | vchSig.resize(65); | ||||
int rec = -1; | int rec = -1; | ||||
secp256k1_ecdsa_recoverable_signature sig; | secp256k1_ecdsa_recoverable_signature sig; | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |