Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
An encapsulated private key. More...
#include <key.h>
Public Member Functions | |
CKey () | |
Construct an invalid private key. More... | |
template<typename T > | |
void | Set (const T pbegin, const T pend, bool fCompressedIn) |
Initialize using begin and end iterators to byte data. More... | |
unsigned int | size () const |
Simple read-only vector-like interface. More... | |
const unsigned char * | begin () const |
const unsigned char * | end () const |
bool | IsValid () const |
Check whether this private key is valid. More... | |
bool | IsCompressed () const |
Check whether the public key corresponding to this private key is (to be) compressed. More... | |
void | MakeNewKey (bool fCompressed) |
Generate a new private key using a cryptographic PRNG. More... | |
CPrivKey | GetPrivKey () const |
Convert the private key to a CPrivKey (serialized OpenSSL private key data). More... | |
CPubKey | GetPubKey () const |
Compute the public key from a private key. More... | |
bool | Sign (const uint256 &hash, std::vector< unsigned char > &vchSig, uint32_t test_case=0) const |
Create a DER-serialized signature. More... | |
bool | SignCompact (const uint256 &hash, std::vector< unsigned char > &vchSig) const |
Create a compact signature (65 bytes), which allows reconstructing the used public key. More... | |
bool | Derive (CKey &keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const |
Derive BIP32 child key. More... | |
bool | VerifyPubKey (const CPubKey &vchPubKey) const |
Verify thoroughly whether a private key and a public key match. More... | |
bool | Load (const CPrivKey &privkey, const CPubKey &vchPubKey, bool fSkipCheck) |
Load private key and check that public key matches. More... | |
Static Public Attributes | |
static const unsigned int | PRIVATE_KEY_SIZE = 279 |
secp256k1: More... | |
static const unsigned int | COMPRESSED_PRIVATE_KEY_SIZE = 214 |
Static Private Member Functions | |
static bool | Check (const unsigned char *vch) |
Check whether the 32-byte array pointed to by vch is valid keydata. More... | |
Private Attributes | |
bool | fValid |
see www.keylength.com script supports up to 75 for single byte push More... | |
bool | fCompressed |
Whether the public key corresponding to this private key is (to be) compressed. More... | |
std::vector< unsigned char, secure_allocator< unsigned char > > | keydata |
The actual byte data. More... | |
Friends | |
bool | operator== (const CKey &a, const CKey &b) |
Detailed Description
Constructor & Destructor Documentation
◆ CKey()
|
inline |
Member Function Documentation
◆ begin()
|
inline |
Definition at line 89 of file key.h.
References keydata.
Referenced by CCryptoKeyStore::AddKeyPubKey(), Derive(), CExtKey::Encode(), CCryptoKeyStore::EncryptKeys(), GetPrivKey(), GetPubKey(), Load(), CBitcoinSecret::SetKey(), Sign(), and SignCompact().
◆ Check()
|
staticprivate |
Check whether the 32-byte array pointed to by vch is valid keydata.
Definition at line 154 of file key.cpp.
References secp256k1_context_sign, and secp256k1_ec_seckey_verify().
Referenced by MakeNewKey(), and Set().
◆ Derive()
bool CKey::Derive | ( | CKey & | keyChild, |
ChainCode & | ccChild, | ||
unsigned int | nChild, | ||
const ChainCode & | cc | ||
) | const |
Derive BIP32 child key.
Definition at line 248 of file key.cpp.
References base_blob< BITS >::begin(), begin(), CPubKey::begin(), BIP32Hash(), CPubKey::COMPRESSED_PUBLIC_KEY_SIZE, fCompressed, fValid, GetPubKey(), IsCompressed(), IsValid(), memcpy(), secp256k1_context_sign, secp256k1_ec_privkey_tweak_add(), size(), and CPubKey::size().
Referenced by CExtKey::Derive().
◆ end()
|
inline |
Definition at line 90 of file key.h.
References keydata, and size().
Referenced by CCryptoKeyStore::AddKeyPubKey(), and CCryptoKeyStore::EncryptKeys().
◆ GetPrivKey()
CPrivKey CKey::GetPrivKey | ( | ) | const |
Convert the private key to a CPrivKey (serialized OpenSSL private key data).
This is expensive.
Definition at line 166 of file key.cpp.
References begin(), ec_privkey_export_der(), fCompressed, fValid, PRIVATE_KEY_SIZE, secp256k1_context_sign, SECP256K1_EC_COMPRESSED, and SECP256K1_EC_UNCOMPRESSED.
Referenced by CWallet::AddKeyPubKeyWithDB().
◆ GetPubKey()
CPubKey CKey::GetPubKey | ( | ) | const |
Compute the public key from a private key.
This is expensive.
Definition at line 179 of file key.cpp.
References begin(), CPubKey::begin(), fCompressed, fValid, CPubKey::IsValid(), CPubKey::PUBLIC_KEY_SIZE, secp256k1_context_sign, SECP256K1_EC_COMPRESSED, secp256k1_ec_pubkey_create(), secp256k1_ec_pubkey_serialize(), SECP256K1_EC_UNCOMPRESSED, and CPubKey::size().
Referenced by CKeyStore::AddKey(), AddKey(), BOOST_FIXTURE_TEST_CASE(), Derive(), CExtKey::Derive(), CWallet::DeriveNewChildKey(), ECC_InitSanityCheck(), ECDSAVerify(), ECDSAVerify_LargeBlock(), CCryptoKeyStore::EncryptKeys(), CWallet::GenerateNewKey(), CMessageSigner::GetKeysFromSecret(), CWallet::GetOutpointAndKeysFromOutput(), CBasicKeyStore::GetPubKey(), importelectrumwallet(), importprivkey(), importwallet(), CExtKey::Neuter(), ProcessImport(), and CSporkMessage::Sign().
◆ IsCompressed()
|
inline |
Check whether the public key corresponding to this private key is (to be) compressed.
Definition at line 96 of file key.h.
References fCompressed.
Referenced by Derive(), and CBitcoinSecret::SetKey().
◆ IsValid()
|
inline |
Check whether this private key is valid.
Definition at line 93 of file key.h.
References fValid.
Referenced by Derive(), importprivkey(), ProcessImport(), CBitcoinSecret::SetKey(), CSporkMessage::Sign(), signmessagewithprivkey(), and signrawtransaction().
◆ Load()
Load private key and check that public key matches.
Definition at line 236 of file key.cpp.
References begin(), ec_privkey_import_der(), fCompressed, fValid, CPubKey::IsCompressed(), secp256k1_context_sign, and VerifyPubKey().
Referenced by ReadKeyValue().
◆ MakeNewKey()
void CKey::MakeNewKey | ( | bool | fCompressed | ) |
Generate a new private key using a cryptographic PRNG.
Definition at line 158 of file key.cpp.
References Check(), fCompressed, fValid, GetStrongRandBytes(), and keydata.
Referenced by BOOST_FIXTURE_TEST_CASE(), ECC_InitSanityCheck(), ECDSASign(), ECDSAVerify(), ECDSAVerify_LargeBlock(), CWallet::GenerateNewKey(), and SetupDummyInputs().
◆ Set()
|
inline |
Initialize using begin and end iterators to byte data.
Definition at line 74 of file key.h.
References Check(), fCompressed, fValid, keydata, and memcpy().
Referenced by CExtKey::Decode(), DecryptKey(), CBitcoinSecret::GetKey(), and CExtKey::SetMaster().
◆ Sign()
bool CKey::Sign | ( | const uint256 & | hash, |
std::vector< unsigned char > & | vchSig, | ||
uint32_t | test_case = 0 |
||
) | const |
Create a DER-serialized signature.
The test_case parameter tweaks the deterministic nonce.
Definition at line 192 of file key.cpp.
References base_blob< BITS >::begin(), begin(), fValid, secp256k1_context_sign, secp256k1_ecdsa_sign(), secp256k1_ecdsa_signature_serialize_der(), secp256k1_nonce_function_rfc6979, CPubKey::SIGNATURE_SIZE, and WriteLE32().
Referenced by TransactionSignatureCreator::CreateSig(), ECDSAVerify(), ECDSAVerify_LargeBlock(), and VerifyPubKey().
◆ SignCompact()
bool CKey::SignCompact | ( | const uint256 & | hash, |
std::vector< unsigned char > & | vchSig | ||
) | const |
Create a compact signature (65 bytes), which allows reconstructing the used public key.
The format is one header byte, followed by two times 32 bytes for the serialized r and s values. The header byte: 0x1B = first key with even y, 0x1C = first key with odd y, 0x1D = second key with even y, 0x1E = second key with odd y, add 0x04 for compressed keys.
Definition at line 221 of file key.cpp.
References base_blob< BITS >::begin(), begin(), CPubKey::COMPACT_SIGNATURE_SIZE, fCompressed, fValid, secp256k1_context_sign, secp256k1_ecdsa_recoverable_signature_serialize_compact(), secp256k1_ecdsa_sign_recoverable(), and secp256k1_nonce_function_rfc6979.
Referenced by SignVerifyMessageDialog::on_signMessageButton_SM_clicked(), CHashSigner::SignHash(), signmessage(), and signmessagewithprivkey().
◆ size()
|
inline |
Simple read-only vector-like interface.
Definition at line 88 of file key.h.
References fValid, and keydata.
Referenced by Derive(), CExtKey::Encode(), end(), and CBitcoinSecret::SetKey().
◆ VerifyPubKey()
bool CKey::VerifyPubKey | ( | const CPubKey & | vchPubKey | ) | const |
Verify thoroughly whether a private key and a public key match.
This is done using a different mechanism than just regenerating it.
Definition at line 207 of file key.cpp.
References base_blob< BITS >::begin(), fCompressed, GetRandBytes(), CPubKey::IsCompressed(), Sign(), CPubKey::Verify(), and CHash256::Write().
Referenced by DecryptKey(), CWallet::DeriveNewChildKey(), ECC_InitSanityCheck(), CWallet::GenerateNewKey(), importelectrumwallet(), importprivkey(), importwallet(), Load(), and ProcessImport().
Friends And Related Function Documentation
◆ operator==
Member Data Documentation
◆ COMPRESSED_PRIVATE_KEY_SIZE
|
static |
Definition at line 34 of file key.h.
Referenced by ec_privkey_export_der().
◆ fCompressed
|
private |
Whether the public key corresponding to this private key is (to be) compressed.
Definition at line 49 of file key.h.
Referenced by Derive(), GetPrivKey(), GetPubKey(), IsCompressed(), Load(), MakeNewKey(), Set(), SignCompact(), and VerifyPubKey().
◆ fValid
|
private |
see www.keylength.com script supports up to 75 for single byte push
Whether this private key is valid. We check for correctness when modifying the key data, so fValid should always correspond to the actual state.
Definition at line 41 of file key.h.
Referenced by Derive(), GetPrivKey(), GetPubKey(), IsValid(), Load(), MakeNewKey(), Set(), Sign(), SignCompact(), and size().
◆ keydata
|
private |
◆ PRIVATE_KEY_SIZE
|
static |
secp256k1:
Definition at line 33 of file key.h.
Referenced by ec_privkey_export_der(), and GetPrivKey().
The documentation for this class was generated from the following files: