Changeset View
Changeset View
Standalone View
Standalone View
src/key.cpp
Show First 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | |||||
CPrivKey CKey::GetPrivKey() const { | CPrivKey CKey::GetPrivKey() const { | ||||
assert(fValid); | assert(fValid); | ||||
CPrivKey privkey; | CPrivKey privkey; | ||||
int ret; | int ret; | ||||
size_t privkeylen; | size_t privkeylen; | ||||
privkey.resize(PRIVATE_KEY_SIZE); | privkey.resize(PRIVATE_KEY_SIZE); | ||||
privkeylen = PRIVATE_KEY_SIZE; | privkeylen = PRIVATE_KEY_SIZE; | ||||
ret = ec_privkey_export_der( | ret = ec_privkey_export_der( | ||||
secp256k1_context_sign, (uint8_t *)privkey.data(), &privkeylen, begin(), | secp256k1_context_sign, privkey.data(), &privkeylen, begin(), | ||||
fCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED); | fCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED); | ||||
assert(ret); | assert(ret); | ||||
privkey.resize(privkeylen); | privkey.resize(privkeylen); | ||||
return privkey; | return privkey; | ||||
} | } | ||||
CPubKey CKey::GetPubKey() const { | CPubKey CKey::GetPubKey() const { | ||||
assert(fValid); | assert(fValid); | ||||
Show All 20 Lines | bool CKey::SignECDSA(const uint256 &hash, std::vector<uint8_t> &vchSig, | ||||
size_t nSigLen = CPubKey::SIGNATURE_SIZE; | size_t nSigLen = CPubKey::SIGNATURE_SIZE; | ||||
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, | ||||
test_case ? extra_entropy : nullptr); | test_case ? extra_entropy : nullptr); | ||||
assert(ret); | assert(ret); | ||||
secp256k1_ecdsa_signature_serialize_der( | secp256k1_ecdsa_signature_serialize_der(secp256k1_context_sign, | ||||
secp256k1_context_sign, (uint8_t *)vchSig.data(), &nSigLen, &sig); | vchSig.data(), &nSigLen, &sig); | ||||
vchSig.resize(nSigLen); | vchSig.resize(nSigLen); | ||||
return true; | return true; | ||||
} | } | ||||
bool CKey::SignSchnorr(const uint256 &hash, std::vector<uint8_t> &vchSig, | bool CKey::SignSchnorr(const uint256 &hash, std::vector<uint8_t> &vchSig, | ||||
uint32_t test_case) const { | uint32_t test_case) const { | ||||
if (!fValid) { | if (!fValid) { | ||||
return false; | return false; | ||||
Show All 34 Lines | bool CKey::SignCompact(const uint256 &hash, | ||||
vchSig.resize(CPubKey::COMPACT_SIGNATURE_SIZE); | vchSig.resize(CPubKey::COMPACT_SIGNATURE_SIZE); | ||||
int rec = -1; | int rec = -1; | ||||
secp256k1_ecdsa_recoverable_signature sig; | secp256k1_ecdsa_recoverable_signature sig; | ||||
int ret = secp256k1_ecdsa_sign_recoverable( | int ret = secp256k1_ecdsa_sign_recoverable( | ||||
secp256k1_context_sign, &sig, hash.begin(), begin(), | secp256k1_context_sign, &sig, hash.begin(), begin(), | ||||
secp256k1_nonce_function_rfc6979, nullptr); | secp256k1_nonce_function_rfc6979, nullptr); | ||||
assert(ret); | assert(ret); | ||||
secp256k1_ecdsa_recoverable_signature_serialize_compact( | secp256k1_ecdsa_recoverable_signature_serialize_compact( | ||||
secp256k1_context_sign, (uint8_t *)&vchSig[1], &rec, &sig); | secp256k1_context_sign, &vchSig[1], &rec, &sig); | ||||
assert(ret); | assert(ret); | ||||
assert(rec != -1); | assert(rec != -1); | ||||
vchSig[0] = 27 + rec + (fCompressed ? 4 : 0); | vchSig[0] = 27 + rec + (fCompressed ? 4 : 0); | ||||
return true; | return true; | ||||
} | } | ||||
bool CKey::Load(const CPrivKey &privkey, const CPubKey &vchPubKey, | bool CKey::Load(const CPrivKey &privkey, const CPubKey &vchPubKey, | ||||
bool fSkipCheck = false) { | bool fSkipCheck = false) { | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |