 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
31 static CSecp256k1Init instance_of_csecp256k1;
75 privkey.resize(privkeylen);
85 assert((
int)result.
size() == clen);
91 bool CKey::Sign(
const uint256& hash, std::vector<unsigned char>& vchSig, uint32_t test_case)
const
99 prng.
Generate((
unsigned char*)&nonce, 32);
102 int ret =
secp256k1_ecdsa_sign((
const unsigned char*)&hash, 32, (
unsigned char*)&vchSig[0], &nSigLen,
begin(), (
unsigned char*)&nonce);
105 vchSig.resize(nSigLen);
116 unsigned char rnd[8];
117 std::string str =
"Bitcoin key verification\n";
121 std::vector<unsigned char> vchSig;
123 return pubkey.
Verify(hash, vchSig);
135 prng.
Generate((
unsigned char*)&nonce, 32);
159 bool CKey::Derive(
CKey& keyChild,
unsigned char ccChild[32],
unsigned int nChild,
const unsigned char cc[32])
const
163 unsigned char out[64];
165 if ((nChild >> 31) == 0) {
167 assert(pubkey.
begin() + 33 == pubkey.
end());
173 memcpy(ccChild, out + 32, 32);
193 static const unsigned char hashkey[] = {
'p',
'r',
'c',
'y',
'c',
'o',
'i',
'n',
' ',
's',
'e',
'e',
'd'};
194 unsigned char out[64];
197 key.
Set(&out[0], &out[32],
true);
220 code[5] = (
nChild >> 24) & 0xFF;
221 code[6] = (
nChild >> 16) & 0xFF;
222 code[7] = (
nChild >> 8) & 0xFF;
223 code[8] = (
nChild >> 0) & 0xFF;
234 nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8];
236 key.
Set(code + 42, code + 74,
true);
241 #if !defined(USE_SECP256K1)
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
void UnlockObject(const T &t)
void secp256k1_start(unsigned int flags)
Initialize the library.
void Finalize(unsigned char hash[OUTPUT_SIZE])
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
bool SetPrivKey(const CPrivKey &vchPrivKey, bool fCompressed)
Initialize from a CPrivKey (serialized OpenSSL private key data).
bool Derive(CExtKey &out, unsigned int nChild) const
CPrivKey GetPrivKey() const
Convert the private key to a CPrivKey (serialized OpenSSL private key data).
unsigned char vchFingerprint[4]
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
bool Derive(CKey &keyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const
Derive BIP32 child key.
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
secp256k1: const unsigned int PRIVATE_KEY_SIZE = 279; const unsigned int PUBLIC_KEY_SIZE = 65; const ...
bool ECC_InitSanityCheck()
Check that required EC support is available at runtime.
bool fCompressed
Whether the public key corresponding to this private key is (to be) compressed.
void * memcpy(void *a, const void *b, size_t c)
void Generate(unsigned char *output, size_t outputlen)
Generate a byte array.
#define SECP256K1_START_VERIFY
Flags to pass to secp256k1_start.
bool Check(const unsigned char *vch)
A reference to a CKey: the Hash160 of its serialized public key.
const unsigned char * end() const
CHMAC_SHA512 & Write(const unsigned char *data, size_t len)
unsigned char vch[32]
The actual byte data.
const unsigned char * begin() const
const unsigned char * begin() const
void GetRandBytes(unsigned char *buf, int num)
Functions to gather random data via the OpenSSL PRNG.
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_sign_compact(const unsigned char *msg, int msglen, unsigned char *sig64, const unsigned char *seckey, const unsigned char *nonce, int *recid) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5)
Create a compact ECDSA signature (64 byte + recovery id).
unsigned char vchFingerprint[4]
void Finalize(unsigned char hash[OUTPUT_SIZE])
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Verify a DER signature (~72 bytes).
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(unsigned char *pubkey, int *pubkeylen, const unsigned char *seckey, int compressed) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Compute the public key for a secret key.
void Decode(const unsigned char code[74])
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_sign(const unsigned char *msg, int msglen, unsigned char *sig, int *siglen, const unsigned char *seckey, const unsigned char *nonce) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6)
Create an ECDSA signature.
const unsigned char * end() const
unsigned char vchChainCode[32]
bool SignCompact(const uint256 &hash, std::vector< unsigned char > &vchSig) const
Create a compact signature (65 bytes), which allows reconstructing the used public key.
void LockObject(const T &t)
bool IsValid() const
Check whether this private key is valid.
unsigned char vchChainCode[32]
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_import(unsigned char *seckey, const unsigned char *privkey, int privkeylen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Import a private key in DER format.
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
256-bit unsigned big integer.
CPubKey GetPubKey() const
Compute the public key from a private key.
CHash256 & Write(const unsigned char *data, size_t len)
bool IsCompressed() const
Check whether this is a compressed public key.
void BIP32Hash(const unsigned char chainCode[32], unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64])
An encapsulated public key.
unsigned int size() const
Simple read-only vector-like interface.
bool Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck)
Load private key and check that public key matches.
#define SECP256K1_START_SIGN
An encapsulated private key.
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
void GetStrongRandBytes(unsigned char *out, int num)
Function to gather random data from multiple sources, failing whenever any of those source fail to pr...
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, uint32_t test_case=0) const
Create a DER-serialized signature.
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(unsigned char *seckey, const unsigned char *tweak) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Tweak a private key by adding tweak to it.
void secp256k1_stop(void)
Free all memory associated with this library.
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_export(const unsigned char *seckey, unsigned char *privkey, int *privkeylen, int compressed) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Export a private key in DER format.
bool fValid
Whether this private key is valid.
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
static bool SanityCheck()
The RFC 6979 PRNG using HMAC-SHA256.
CExtPubKey Neuter() const
void Encode(unsigned char code[74]) const
static bool Check(const unsigned char *vch)
Check whether the 32-byte array pointed to be vch is valid keydata.
A hasher class for HMAC-SHA-512.
void SetMaster(const unsigned char *seed, unsigned int nSeedLen)
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)