Bitcoin
Public Member Functions | Static Public Attributes | Static Private Member Functions | Private Attributes | Friends | List of all members
CKey Class Reference

#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...
 
bool Negate ()
 Negate private key. More...
 
CPrivKey GetPrivKey () const
 
CPubKey GetPubKey () const
 
bool Sign (const uint256 &hash, std::vector< unsigned char > &vchSig, bool grind=true, uint32_t test_case=0) const
 
bool SignCompact (const uint256 &hash, std::vector< unsigned char > &vchSig) const
 
bool Derive (CKey &keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
 Derive BIP32 child key. More...
 
bool VerifyPubKey (const CPubKey &vchPubKey) const
 
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
 
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
 
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

An encapsulated private key.

Constructor & Destructor Documentation

◆ CKey()

CKey::CKey ( )
inline

Construct an invalid private key.

Member Function Documentation

◆ begin()

const unsigned char* CKey::begin ( ) const
inline

◆ Check()

bool CKey::Check ( const unsigned char *  vch)
staticprivate

Check whether the 32-byte array pointed to by vch is valid keydata.

◆ Derive()

bool CKey::Derive ( CKey keyChild,
ChainCode ccChild,
unsigned int  nChild,
const ChainCode cc 
) const

Derive BIP32 child key.

◆ end()

const unsigned char* CKey::end ( ) const
inline

◆ GetPrivKey()

CPrivKey CKey::GetPrivKey ( ) const

Convert the private key to a CPrivKey (serialized OpenSSL private key data). This is expensive.

◆ GetPubKey()

CPubKey CKey::GetPubKey ( ) const

Compute the public key from a private key. This is expensive.

◆ IsCompressed()

bool CKey::IsCompressed ( ) const
inline

Check whether the public key corresponding to this private key is (to be) compressed.

◆ IsValid()

bool CKey::IsValid ( ) const
inline

Check whether this private key is valid.

◆ Load()

bool CKey::Load ( const CPrivKey privkey,
const CPubKey vchPubKey,
bool  fSkipCheck = false 
)

Load private key and check that public key matches.

◆ MakeNewKey()

void CKey::MakeNewKey ( bool  fCompressed)

Generate a new private key using a cryptographic PRNG.

◆ Negate()

bool CKey::Negate ( )

Negate private key.

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

◆ Sign()

bool CKey::Sign ( const uint256 hash,
std::vector< unsigned char > &  vchSig,
bool  grind = true,
uint32_t  test_case = 0 
) const

Create a DER-serialized signature. The test_case parameter tweaks the deterministic nonce.

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

◆ size()

unsigned int CKey::size ( ) const
inline

Simple read-only vector-like interface.

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

Friends And Related Function Documentation

◆ operator==

bool operator== ( const CKey a,
const CKey b 
)
friend

Member Data Documentation

◆ COMPRESSED_PRIVATE_KEY_SIZE

const unsigned int CKey::COMPRESSED_PRIVATE_KEY_SIZE = 214
static

◆ fCompressed

bool CKey::fCompressed
private

Whether the public key corresponding to this private key is (to be) compressed.

◆ fValid

bool CKey::fValid
private

see www.keylength.com script supports up to 75 for single byte pushWhether this private key is valid. We check for correctness when modifying the key data, so fValid should always correspond to the actual state.

◆ keydata

std::vector<unsigned char, secure_allocator<unsigned char> > CKey::keydata
private

The actual byte data.

◆ PRIVATE_KEY_SIZE

const unsigned int CKey::PRIVATE_KEY_SIZE = 279
static

secp256k1:


The documentation for this class was generated from the following files: