4 #include "keys_global.h" 6 #include <utils/allocators.h> 26 typedef std::vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
40 unsigned char vch[32];
43 bool static Check(
const unsigned char* vch);
47 CKey() : fValid(false), fCompressed(false)
53 CKey(
const CKey& secret) : fValid(secret.fValid), fCompressed(secret.fCompressed)
56 memcpy(vch, secret.vch,
sizeof(vch));
65 friend bool operator==(
const CKey& a,
const CKey& b)
67 return a.fCompressed == b.fCompressed && a.
size() == b.
size() &&
68 memcmp(&a.vch[0], &b.vch[0], a.
size()) == 0;
73 void Set(
const T pbegin,
const T pend,
bool fCompressedIn)
75 if (pend - pbegin != 32) {
79 if (Check(&pbegin[0])) {
80 memcpy(vch, (
unsigned char*)&pbegin[0], 32);
82 fCompressed = fCompressedIn;
89 unsigned int size()
const {
return (fValid ? 32 : 0); }
90 const unsigned char* begin()
const {
return vch; }
91 const unsigned char* end()
const {
return vch +
size(); }
100 bool SetPrivKey(
const CPrivKey& vchPrivKey,
bool fCompressed);
121 bool Sign(
const uint256& hash, std::vector<unsigned char>& vchSig, uint32_t test_case = 0)
const;
142 bool Load(CPrivKey& privkey,
CPubKey& vchPubKey,
bool fSkipCheck);
149 void ECC_Start(
void);
155 bool ECC_InitSanityCheck(
void);
bool VerifyPubKey(const CPubKey &vchPubKey) const
Definition: key.cpp:180
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:94
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
Definition: key.h:97
CPubKey GetPubKey() const
Definition: key.cpp:152
CPrivKey GetPrivKey() const
Definition: key.cpp:137
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition: key.cpp:119
~CKey()
Destructor (again necessary because of memlocking).
Definition: key.h:60
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
Definition: key.h:73
bool Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck)
Load private key and check that public key matches.
Definition: key.cpp:209
Definition: uint256.h:294
bool SetPrivKey(const CPrivKey &vchPrivKey, bool fCompressed)
Initialize from a CPrivKey (serialized OpenSSL private key data).
Definition: key.cpp:129
bool SignCompact(const uint256 &hash, std::vector< unsigned char > &vchSig) const
Definition: key.cpp:194
static bool CheckSignatureElement(const unsigned char *vch, int len, bool half)
Check whether an element of a signature (r or s) is valid.
CKey()
Construct an invalid private key.
Definition: key.h:47
CKey(const CKey &secret)
Copy constructor. This is necessary because of memlocking.
Definition: key.h:53
unsigned int size() const
Simple read-only vector-like interface.
Definition: key.h:89
bool Derive(CKey &keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
Derive BIP32 child key.
Definition: key.cpp:221
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, uint32_t test_case=0) const
Definition: key.cpp:165