An encapsulated private key.
More...
#include <key.h>

 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 readonly vectorlike interface. More...


const std::byte *  data () const 

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...


bool  Negate () 
 Negate private key. 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, bool grind=true, uint32_t test_case=0) const 
 Create a DERserialized 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  SignSchnorr (const uint256 &hash, Span< unsigned char > sig, const uint256 *merkle_root, const uint256 &aux) const 
 Create a BIP340 Schnorr signature, for the xonlypubkey corresponding to *this, optionally tweaked by *merkle_root. 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 bool  Check (const unsigned char *vch) 
 Check whether the 32byte array pointed to by vch is valid keydata. More...



bool  fValid {false} 
 see www.keylength.com script supports up to 75 for single byte push More...


bool  fCompressed {false} 
 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...


An encapsulated private key.
Definition at line 26 of file key.h.
◆ CKey()
Construct an invalid private key.
Definition at line 58 of file key.h.
◆ begin()
const unsigned char* CKey::begin 
( 
 ) 
const 

inline 
Definition at line 89 of file key.h.
◆ Check()
bool CKey::Check 
( 
const unsigned char * 
vch  ) 


staticprivate 
Check whether the 32byte array pointed to by vch is valid keydata.
Definition at line 156 of file key.cpp.
◆ data()
const std::byte* CKey::data 
( 
 ) 
const 

inline 
Definition at line 88 of file key.h.
◆ Derive()
Derive BIP32 child key.
Definition at line 314 of file key.cpp.
◆ end()
const unsigned char* CKey::end 
( 
 ) 
const 

inline 
Definition at line 90 of file key.h.
◆ GetPrivKey()
Convert the private key to a CPrivKey (serialized OpenSSL private key data).
This is expensive.
Definition at line 174 of file key.cpp.
◆ GetPubKey()
Compute the public key from a private key.
This is expensive.
Definition at line 187 of file key.cpp.
◆ IsCompressed()
bool CKey::IsCompressed 
( 
 ) 
const 

inline 
Check whether the public key corresponding to this private key is (to be) compressed.
Definition at line 96 of file key.h.
◆ IsValid()
bool CKey::IsValid 
( 
 ) 
const 

inline 
Check whether this private key is valid.
Definition at line 93 of file key.h.
◆ Load()
bool CKey::Load 
( 
const CPrivKey & 
privkey, 


const CPubKey & 
vchPubKey, 


bool 
fSkipCheck = false 

) 
 
Load private key and check that public key matches.
Definition at line 302 of file key.cpp.
◆ MakeNewKey()
void CKey::MakeNewKey 
( 
bool 
fCompressed  ) 

Generate a new private key using a cryptographic PRNG.
Definition at line 160 of file key.cpp.
◆ Negate()
Negate private key.
Definition at line 168 of file key.cpp.
◆ Set()
template<typename T >
void CKey::Set 
( 
const T 
pbegin, 


const T 
pend, 


bool 
fCompressedIn 

) 
 

inline 
Initialize using begin and end iterators to byte data.
Definition at line 73 of file key.h.
◆ Sign()
bool CKey::Sign 
( 
const uint256 & 
hash, 


std::vector< unsigned char > & 
vchSig, 


bool 
grind = true , 


uint32_t 
test_case = 0 

) 
 const 
Create a DERserialized signature.
The test_case parameter tweaks the deterministic nonce.
Definition at line 213 of file key.cpp.
◆ 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 254 of file key.cpp.
◆ SignSchnorr()
bool CKey::SignSchnorr 
( 
const uint256 & 
hash, 


Span< unsigned char > 
sig, 


const uint256 * 
merkle_root, 


const uint256 & 
aux 

) 
 const 
Create a BIP340 Schnorr signature, for the xonlypubkey corresponding to *this, optionally tweaked by *merkle_root.
Additional nonce entropy is provided through aux.
merkle_root is used to optionally perform tweaking of the private key, as specified in BIP341:
 If merkle_root == nullptr: no tweaking is done, sign with key directly (this is used for signatures in BIP342 script).
 If merkle_root>IsNull(): sign with key + H_TapTweak(pubkey) (this is used for key path spending when no scripts are present).
 Otherwise: sign with key + H_TapTweak(pubkey  *merkle_root) (this is used for key path spending, with specific Merkle root of the script tree).
Definition at line 277 of file key.cpp.
◆ size()
unsigned int CKey::size 
( 
 ) 
const 

inline 
Simple readonly vectorlike interface.
Definition at line 87 of file key.h.
◆ 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 241 of file key.cpp.
◆ operator==
bool operator== 
( 
const CKey & 
a, 


const CKey & 
b 

) 
 

friend 
Definition at line 64 of file key.h.
◆ COMPRESSED_SIZE
const unsigned int CKey::COMPRESSED_SIZE = 214 

static 
Definition at line 33 of file key.h.
◆ fCompressed
bool CKey::fCompressed {false} 

private 
Whether the public key corresponding to this private key is (to be) compressed.
Definition at line 48 of file key.h.
◆ fValid
bool CKey::fValid {false} 

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 45 of file key.h.
◆ keydata
The actual byte data.
Definition at line 51 of file key.h.
◆ SIZE
const unsigned int CKey::SIZE = 279 

static 
secp256k1:
Definition at line 32 of file key.h.
The documentation for this class was generated from the following files: