Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

An encapsulated public key. More...

#include <pubkey.h>

Public Member Functions

 CPubKey ()
 Construct an invalid public key. More...
 
template<typename T >
void Set (const T pbegin, const T pend)
 Initialize a public key using begin/end iterators to byte data. More...
 
template<typename T >
 CPubKey (const T pbegin, const T pend)
 Construct a public key using begin/end iterators to byte data. More...
 
 CPubKey (const std::vector< unsigned char > &_vch)
 Construct a public key from a byte vector. More...
 
unsigned int size () const
 Simple read-only vector-like interface to the pubkey data. More...
 
const unsigned char * begin () const
 
const unsigned char * end () const
 
const unsigned char & operator[] (unsigned int pos) const
 
template<typename Stream >
void Serialize (Stream &s) const
 Implement serialization, as if this was a byte vector. More...
 
template<typename Stream >
void Unserialize (Stream &s)
 
CKeyID GetID () const
 Get the KeyID of this public key (hash of its serialization) More...
 
uint256 GetHash () const
 Get the 256-bit hash of this public key. More...
 
bool IsValid () const
 
bool IsFullyValid () const
 fully validate whether this is a valid public key (more expensive than IsValid()) More...
 
bool IsCompressed () const
 Check whether this is a compressed public key. More...
 
bool Verify (const uint256 &hash, const std::vector< unsigned char > &vchSig) const
 Verify a DER signature (~72 bytes). More...
 
bool RecoverCompact (const uint256 &hash, const std::vector< unsigned char > &vchSig)
 Recover a public key from a compact signature. More...
 
bool Decompress ()
 Turn this public key into an uncompressed public key. More...
 
bool Derive (CPubKey &pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
 Derive BIP32 child pubkey. More...
 

Static Public Member Functions

static bool CheckLowS (const std::vector< unsigned char > &vchSig)
 Check whether a signature is normalized (lower-S). More...
 

Static Public Attributes

static const unsigned int PUBLIC_KEY_SIZE = 65
 secp256k1: More...
 
static const unsigned int COMPRESSED_PUBLIC_KEY_SIZE = 33
 
static const unsigned int SIGNATURE_SIZE = 72
 
static const unsigned int COMPACT_SIGNATURE_SIZE = 65
 

Private Member Functions

void Invalidate ()
 Set this key data to be invalid. More...
 

Static Private Member Functions

unsigned static int GetLen (unsigned char chHeader)
 Compute the length of a pubkey with a given first byte. More...
 

Private Attributes

unsigned char vch [PUBLIC_KEY_SIZE]
 see www.keylength.com script supports up to 75 for single byte push More...
 

Friends

bool operator== (const CPubKey &a, const CPubKey &b)
 Comparator implementation. More...
 
bool operator!= (const CPubKey &a, const CPubKey &b)
 
bool operator< (const CPubKey &a, const CPubKey &b)
 

Detailed Description

An encapsulated public key.

Definition at line 30 of file pubkey.h.

Constructor & Destructor Documentation

◆ CPubKey() [1/3]

CPubKey::CPubKey ( )
inline

Construct an invalid public key.

Definition at line 74 of file pubkey.h.

References Invalidate().

◆ CPubKey() [2/3]

template<typename T >
CPubKey::CPubKey ( const T  pbegin,
const T  pend 
)
inline

Construct a public key using begin/end iterators to byte data.

Definition at line 92 of file pubkey.h.

References Set().

◆ CPubKey() [3/3]

CPubKey::CPubKey ( const std::vector< unsigned char > &  _vch)
inlineexplicit

Construct a public key from a byte vector.

Definition at line 98 of file pubkey.h.

References Set().

Member Function Documentation

◆ begin()

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

◆ CheckLowS()

bool CPubKey::CheckLowS ( const std::vector< unsigned char > &  vchSig)
static

Check whether a signature is normalized (lower-S).

Definition at line 274 of file pubkey.cpp.

References secp256k1_ecdsa_signature::data, ecdsa_signature_parse_der_lax(), and secp256k1_ecdsa_signature_normalize().

Referenced by IsLowDERSignature().

◆ Decompress()

bool CPubKey::Decompress ( )

Turn this public key into an uncompressed public key.

Definition at line 213 of file pubkey.cpp.

References IsValid(), PUBLIC_KEY_SIZE, secp256k1_ec_pubkey_parse(), secp256k1_ec_pubkey_serialize(), SECP256K1_EC_UNCOMPRESSED, Set(), and size().

◆ Derive()

bool CPubKey::Derive ( CPubKey pubkeyChild,
ChainCode ccChild,
unsigned int  nChild,
const ChainCode cc 
) const

◆ end()

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

Definition at line 106 of file pubkey.h.

References size(), and vch.

Referenced by GetScriptForRawPubKey(), and WalletBatch::WriteKey().

◆ GetHash()

uint256 CPubKey::GetHash ( ) const
inline

Get the 256-bit hash of this public key.

Definition at line 155 of file pubkey.h.

References Hash(), size(), and vch.

Referenced by CCryptoKeyStore::AddKeyPubKey(), DecryptKey(), and CCryptoKeyStore::EncryptKeys().

◆ GetID()

◆ GetLen()

unsigned static int CPubKey::GetLen ( unsigned char  chHeader)
inlinestaticprivate

Compute the length of a pubkey with a given first byte.

Definition at line 57 of file pubkey.h.

References COMPRESSED_PUBLIC_KEY_SIZE, and PUBLIC_KEY_SIZE.

Referenced by Set(), and size().

◆ Invalidate()

void CPubKey::Invalidate ( )
inlineprivate

Set this key data to be invalid.

Definition at line 67 of file pubkey.h.

References vch.

Referenced by CPubKey(), Set(), and Unserialize().

◆ IsCompressed()

bool CPubKey::IsCompressed ( ) const
inline

Check whether this is a compressed public key.

Definition at line 174 of file pubkey.h.

References COMPRESSED_PUBLIC_KEY_SIZE, and size().

Referenced by DecryptKey(), CKey::Load(), CoinControlDialog::updateLabels(), and CKey::VerifyPubKey().

◆ IsFullyValid()

bool CPubKey::IsFullyValid ( ) const

fully validate whether this is a valid public key (more expensive than IsValid())

Definition at line 206 of file pubkey.cpp.

References IsValid(), secp256k1_ec_pubkey_parse(), and size().

Referenced by AddrToPubKey(), ExtractPubKey(), HexToPubKey(), CScriptCompressor::IsToPubKey(), MutateTxAddOutMultiSig(), and MutateTxAddOutPubKey().

◆ IsValid()

◆ operator[]()

const unsigned char& CPubKey::operator[] ( unsigned int  pos) const
inline

Definition at line 107 of file pubkey.h.

References vch.

◆ RecoverCompact()

◆ Serialize()

template<typename Stream >
void CPubKey::Serialize ( Stream &  s) const
inline

Implement serialization, as if this was a byte vector.

Definition at line 127 of file pubkey.h.

References size(), vch, and WriteCompactSize().

◆ Set()

template<typename T >
void CPubKey::Set ( const T  pbegin,
const T  pend 
)
inline

Initialize a public key using begin/end iterators to byte data.

Definition at line 81 of file pubkey.h.

References GetLen(), Invalidate(), memcpy(), and vch.

Referenced by CPubKey(), CExtPubKey::Decode(), Decompress(), Derive(), CScriptCompressor::IsToPubKey(), and RecoverCompact().

◆ size()

unsigned int CPubKey::size ( ) const
inline

Simple read-only vector-like interface to the pubkey data.

Definition at line 104 of file pubkey.h.

References GetLen(), and vch.

Referenced by Decompress(), CKey::Derive(), Derive(), CExtPubKey::Encode(), end(), GetHash(), GetID(), CKey::GetPubKey(), IsCompressed(), IsFullyValid(), IsValid(), Serialize(), Verify(), and WalletBatch::WriteKey().

◆ Unserialize()

template<typename Stream >
void CPubKey::Unserialize ( Stream &  s)
inline

Definition at line 134 of file pubkey.h.

References Invalidate(), PUBLIC_KEY_SIZE, ReadCompactSize(), and vch.

◆ Verify()

bool CPubKey::Verify ( const uint256 hash,
const std::vector< unsigned char > &  vchSig 
) const

Verify a DER signature (~72 bytes).

If this public key is not fully valid, the return value will be false.

Definition at line 169 of file pubkey.cpp.

References base_blob< BITS >::begin(), secp256k1_ecdsa_signature::data, ecdsa_signature_parse_der_lax(), IsValid(), secp256k1_ec_pubkey_parse(), secp256k1_ecdsa_signature_normalize(), secp256k1_ecdsa_verify(), and size().

Referenced by CKey::VerifyPubKey(), and TransactionSignatureChecker::VerifySignature().

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const CPubKey a,
const CPubKey b 
)
friend

Definition at line 115 of file pubkey.h.

◆ operator<

bool operator< ( const CPubKey a,
const CPubKey b 
)
friend

Definition at line 119 of file pubkey.h.

◆ operator==

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

Comparator implementation.

Definition at line 110 of file pubkey.h.

Member Data Documentation

◆ COMPACT_SIGNATURE_SIZE

const unsigned int CPubKey::COMPACT_SIGNATURE_SIZE = 65
static

Definition at line 39 of file pubkey.h.

Referenced by RecoverCompact(), and CKey::SignCompact().

◆ COMPRESSED_PUBLIC_KEY_SIZE

const unsigned int CPubKey::COMPRESSED_PUBLIC_KEY_SIZE = 33
static

◆ PUBLIC_KEY_SIZE

const unsigned int CPubKey::PUBLIC_KEY_SIZE = 65
static

secp256k1:

Definition at line 36 of file pubkey.h.

Referenced by Decompress(), ec_privkey_export_der(), GetLen(), CKey::GetPubKey(), RecoverCompact(), and Unserialize().

◆ SIGNATURE_SIZE

const unsigned int CPubKey::SIGNATURE_SIZE = 72
static

Definition at line 38 of file pubkey.h.

Referenced by CKey::Sign().

◆ vch

unsigned char CPubKey::vch[PUBLIC_KEY_SIZE]
private

see www.keylength.com script supports up to 75 for single byte push

Just store the serialized data. Its length can very cheaply be computed from the first byte.

Definition at line 46 of file pubkey.h.

Referenced by begin(), end(), GetHash(), GetID(), Invalidate(), operator[](), Serialize(), Set(), size(), and Unserialize().


The documentation for this class was generated from the following files:
Released under the MIT license