Raven Core  3.0.0
P2P Digital Currency
key.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "key.h"
7 
8 #include "arith_uint256.h"
9 #include "crypto/common.h"
10 #include "crypto/hmac_sha512.h"
11 #include "pubkey.h"
12 #include "random.h"
13 
14 #include <secp256k1.h>
15 #include <secp256k1_recovery.h>
16 
17 static secp256k1_context* secp256k1_context_sign = nullptr;
18 
20 static int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *out32, const unsigned char *privkey, size_t privkeylen) {
21  const unsigned char *end = privkey + privkeylen;
22  int lenb = 0;
23  int len = 0;
24  memset(out32, 0, 32);
25  /* sequence header */
26  if (end < privkey+1 || *privkey != 0x30) {
27  return 0;
28  }
29  privkey++;
30  /* sequence length constructor */
31  if (end < privkey+1 || !(*privkey & 0x80)) {
32  return 0;
33  }
34  lenb = *privkey & ~0x80; privkey++;
35  if (lenb < 1 || lenb > 2) {
36  return 0;
37  }
38  if (end < privkey+lenb) {
39  return 0;
40  }
41  /* sequence length */
42  len = privkey[lenb-1] | (lenb > 1 ? privkey[lenb-2] << 8 : 0);
43  privkey += lenb;
44  if (end < privkey+len) {
45  return 0;
46  }
47  /* sequence element 0: version number (=1) */
48  if (end < privkey+3 || privkey[0] != 0x02 || privkey[1] != 0x01 || privkey[2] != 0x01) {
49  return 0;
50  }
51  privkey += 3;
52  /* sequence element 1: octet string, up to 32 bytes */
53  if (end < privkey+2 || privkey[0] != 0x04 || privkey[1] > 0x20 || end < privkey+2+privkey[1]) {
54  return 0;
55  }
56  memcpy(out32 + 32 - privkey[1], privkey + 2, privkey[1]);
57  if (!secp256k1_ec_seckey_verify(ctx, out32)) {
58  memset(out32, 0, 32);
59  return 0;
60  }
61  return 1;
62 }
63 
64 static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) {
65  secp256k1_pubkey pubkey;
66  size_t pubkeylen = 0;
67  if (!secp256k1_ec_pubkey_create(ctx, &pubkey, key32)) {
68  *privkeylen = 0;
69  return 0;
70  }
71  if (compressed) {
72  static const unsigned char begin[] = {
73  0x30,0x81,0xD3,0x02,0x01,0x01,0x04,0x20
74  };
75  static const unsigned char middle[] = {
76  0xA0,0x81,0x85,0x30,0x81,0x82,0x02,0x01,0x01,0x30,0x2C,0x06,0x07,0x2A,0x86,0x48,
77  0xCE,0x3D,0x01,0x01,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
78  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
79  0xFF,0xFF,0xFE,0xFF,0xFF,0xFC,0x2F,0x30,0x06,0x04,0x01,0x00,0x04,0x01,0x07,0x04,
80  0x21,0x02,0x79,0xBE,0x66,0x7E,0xF9,0xDC,0xBB,0xAC,0x55,0xA0,0x62,0x95,0xCE,0x87,
81  0x0B,0x07,0x02,0x9B,0xFC,0xDB,0x2D,0xCE,0x28,0xD9,0x59,0xF2,0x81,0x5B,0x16,0xF8,
82  0x17,0x98,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
83  0xFF,0xFF,0xFF,0xFF,0xFE,0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,0xBF,0xD2,0x5E,
84  0x8C,0xD0,0x36,0x41,0x41,0x02,0x01,0x01,0xA1,0x24,0x03,0x22,0x00
85  };
86  unsigned char *ptr = privkey;
87  memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
88  memcpy(ptr, key32, 32); ptr += 32;
89  memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
90  pubkeylen = 33;
91  secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
92  ptr += pubkeylen;
93  *privkeylen = ptr - privkey;
94  } else {
95  static const unsigned char begin[] = {
96  0x30,0x82,0x01,0x13,0x02,0x01,0x01,0x04,0x20
97  };
98  static const unsigned char middle[] = {
99  0xA0,0x81,0xA5,0x30,0x81,0xA2,0x02,0x01,0x01,0x30,0x2C,0x06,0x07,0x2A,0x86,0x48,
100  0xCE,0x3D,0x01,0x01,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
101  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
102  0xFF,0xFF,0xFE,0xFF,0xFF,0xFC,0x2F,0x30,0x06,0x04,0x01,0x00,0x04,0x01,0x07,0x04,
103  0x41,0x04,0x79,0xBE,0x66,0x7E,0xF9,0xDC,0xBB,0xAC,0x55,0xA0,0x62,0x95,0xCE,0x87,
104  0x0B,0x07,0x02,0x9B,0xFC,0xDB,0x2D,0xCE,0x28,0xD9,0x59,0xF2,0x81,0x5B,0x16,0xF8,
105  0x17,0x98,0x48,0x3A,0xDA,0x77,0x26,0xA3,0xC4,0x65,0x5D,0xA4,0xFB,0xFC,0x0E,0x11,
106  0x08,0xA8,0xFD,0x17,0xB4,0x48,0xA6,0x85,0x54,0x19,0x9C,0x47,0xD0,0x8F,0xFB,0x10,
107  0xD4,0xB8,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
108  0xFF,0xFF,0xFF,0xFF,0xFE,0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,0xBF,0xD2,0x5E,
109  0x8C,0xD0,0x36,0x41,0x41,0x02,0x01,0x01,0xA1,0x44,0x03,0x42,0x00
110  };
111  unsigned char *ptr = privkey;
112  memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
113  memcpy(ptr, key32, 32); ptr += 32;
114  memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
115  pubkeylen = 65;
116  secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
117  ptr += pubkeylen;
118  *privkeylen = ptr - privkey;
119  }
120  return 1;
121 }
122 
123 bool CKey::Check(const unsigned char *vch) {
124  return secp256k1_ec_seckey_verify(secp256k1_context_sign, vch);
125 }
126 
127 void CKey::MakeNewKey(bool fCompressedIn) {
128  do {
129  GetStrongRandBytes(keydata.data(), keydata.size());
130  } while (!Check(keydata.data()));
131  fValid = true;
132  fCompressed = fCompressedIn;
133 }
134 
136  assert(fValid);
137  CPrivKey privkey;
138  int ret;
139  size_t privkeylen;
140  privkey.resize(279);
141  privkeylen = 279;
142  ret = ec_privkey_export_der(secp256k1_context_sign, (unsigned char*) privkey.data(), &privkeylen, begin(), fCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
143  assert(ret);
144  privkey.resize(privkeylen);
145  return privkey;
146 }
147 
149  assert(fValid);
150  secp256k1_pubkey pubkey;
151  size_t clen = 65;
152  CPubKey result;
153  int ret = secp256k1_ec_pubkey_create(secp256k1_context_sign, &pubkey, begin());
154  assert(ret);
155  secp256k1_ec_pubkey_serialize(secp256k1_context_sign, (unsigned char*)result.begin(), &clen, &pubkey, fCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
156  assert(result.size() == clen);
157  assert(result.IsValid());
158  return result;
159 }
160 
161 bool CKey::Sign(const uint256 &hash, std::vector<unsigned char>& vchSig, uint32_t test_case) const {
162  if (!fValid)
163  return false;
164  vchSig.resize(72);
165  size_t nSigLen = 72;
166  unsigned char extra_entropy[32] = {0};
167  WriteLE32(extra_entropy, test_case);
169  int ret = secp256k1_ecdsa_sign(secp256k1_context_sign, &sig, hash.begin(), begin(), secp256k1_nonce_function_rfc6979, test_case ? extra_entropy : nullptr);
170  assert(ret);
171  secp256k1_ecdsa_signature_serialize_der(secp256k1_context_sign, (unsigned char*)vchSig.data(), &nSigLen, &sig);
172  vchSig.resize(nSigLen);
173  return true;
174 }
175 
176 bool CKey::VerifyPubKey(const CPubKey& pubkey) const {
177  if (pubkey.IsCompressed() != fCompressed) {
178  return false;
179  }
180  unsigned char rnd[8];
181  std::string str = "Raven key verification\n";
182  GetRandBytes(rnd, sizeof(rnd));
183  uint256 hash;
184  CHash256().Write((unsigned char*)str.data(), str.size()).Write(rnd, sizeof(rnd)).Finalize(hash.begin());
185  std::vector<unsigned char> vchSig;
186  Sign(hash, vchSig);
187  return pubkey.Verify(hash, vchSig);
188 }
189 
190 bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig) const {
191  if (!fValid)
192  return false;
193  vchSig.resize(65);
194  int rec = -1;
196  int ret = secp256k1_ecdsa_sign_recoverable(secp256k1_context_sign, &sig, hash.begin(), begin(), secp256k1_nonce_function_rfc6979, nullptr);
197  assert(ret);
198  secp256k1_ecdsa_recoverable_signature_serialize_compact(secp256k1_context_sign, (unsigned char*)&vchSig[1], &rec, &sig);
199  assert(ret);
200  assert(rec != -1);
201  vchSig[0] = 27 + rec + (fCompressed ? 4 : 0);
202  return true;
203 }
204 
205 bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) {
206  if (!ec_privkey_import_der(secp256k1_context_sign, (unsigned char*)begin(), privkey.data(), privkey.size()))
207  return false;
208  fCompressed = vchPubKey.IsCompressed();
209  fValid = true;
210 
211  if (fSkipCheck)
212  return true;
213 
214  return VerifyPubKey(vchPubKey);
215 }
216 
217 bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc) const {
218  assert(IsValid());
219  assert(IsCompressed());
220  std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
221  if ((nChild >> 31) == 0) {
222  CPubKey pubkey = GetPubKey();
223  assert(pubkey.begin() + 33 == pubkey.end());
224  BIP32Hash(cc, nChild, *pubkey.begin(), pubkey.begin()+1, vout.data());
225  } else {
226  assert(begin() + 32 == end());
227  BIP32Hash(cc, nChild, 0, begin(), vout.data());
228  }
229  memcpy(ccChild.begin(), vout.data()+32, 32);
230  memcpy((unsigned char*)keyChild.begin(), begin(), 32);
231  bool ret = secp256k1_ec_privkey_tweak_add(secp256k1_context_sign, (unsigned char*)keyChild.begin(), vout.data());
232  keyChild.fCompressed = true;
233  keyChild.fValid = ret;
234  return ret;
235 }
236 
237 bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
238  out.nDepth = nDepth + 1;
239  CKeyID id = key.GetPubKey().GetID();
240  memcpy(&out.vchFingerprint[0], &id, 4);
241  out.nChild = _nChild;
242  return key.Derive(out.key, out.chaincode, _nChild, chaincode);
243 }
244 
245 void CExtKey::SetSeed(const unsigned char *seed, unsigned int nSeedLen) {
246  static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'};
247  std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
248  CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(vout.data());
249  key.Set(vout.data(), vout.data() + 32, true);
250  memcpy(chaincode.begin(), vout.data() + 32, 32);
251  nDepth = 0;
252  nChild = 0;
253  memset(vchFingerprint, 0, sizeof(vchFingerprint));
254 }
255 
257  CExtPubKey ret;
258  ret.nDepth = nDepth;
259  memcpy(&ret.vchFingerprint[0], &vchFingerprint[0], 4);
260  ret.nChild = nChild;
261  ret.pubkey = key.GetPubKey();
262  ret.chaincode = chaincode;
263  return ret;
264 }
265 
266 void CExtKey::Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const {
267  code[0] = nDepth;
268  memcpy(code+1, vchFingerprint, 4);
269  code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF;
270  code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF;
271  memcpy(code+9, chaincode.begin(), 32);
272  code[41] = 0;
273  assert(key.size() == 32);
274  memcpy(code+42, key.begin(), 32);
275 }
276 
277 void CExtKey::Decode(const unsigned char code[BIP32_EXTKEY_SIZE]) {
278  nDepth = code[0];
279  memcpy(vchFingerprint, code+1, 4);
280  nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8];
281  memcpy(chaincode.begin(), code+9, 32);
282  key.Set(code+42, code+BIP32_EXTKEY_SIZE, true);
283 }
284 
286  CKey key;
287  key.MakeNewKey(true);
288  CPubKey pubkey = key.GetPubKey();
289  return key.VerifyPubKey(pubkey);
290 }
291 
292 void ECC_Start() {
293  assert(secp256k1_context_sign == nullptr);
294 
296  assert(ctx != nullptr);
297 
298  {
299  // Pass in a random blinding seed to the secp256k1 context.
300  std::vector<unsigned char, secure_allocator<unsigned char>> vseed(32);
301  GetRandBytes(vseed.data(), 32);
302  bool ret = secp256k1_context_randomize(ctx, vseed.data());
303  assert(ret);
304  }
305 
306  secp256k1_context_sign = ctx;
307 }
308 
309 void ECC_Stop() {
310  secp256k1_context *ctx = secp256k1_context_sign;
311  secp256k1_context_sign = nullptr;
312 
313  if (ctx) {
315  }
316 }
void Finalize(unsigned char hash[OUTPUT_SIZE])
Definition: hmac_sha512.cpp:30
CHMAC_SHA512 & Write(const unsigned char *data, size_t len)
Definition: hmac_sha512.h:25
void ECC_Start()
Initialize the elliptic curve support.
Definition: key.cpp:292
CPrivKey GetPrivKey() const
Convert the private key to a CPrivKey (serialized OpenSSL private key data).
Definition: key.cpp:135
unsigned char vchFingerprint[4]
Definition: pubkey.h:196
CKey key
Definition: key.h:141
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32) SECP256K1_ARG_NONNULL(1)
Updates the context randomization to protect against side-channel leakage.
Definition: secp256k1.c:547
bool Derive(CExtKey &out, unsigned int nChild) const
Definition: key.cpp:237
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
Definition: key.cpp:176
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:148
CHash256 & Write(const unsigned char *data, size_t len)
Definition: hash.h:88
Definition: key.h:136
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const
Definition: key.cpp:266
Opaque data structured that holds a parsed ECDSA signature, supporting pubkey recovery.
unsigned char vchFingerprint[4]
Definition: key.h:138
unsigned char nDepth
Definition: pubkey.h:195
void GetStrongRandBytes(unsigned char *out, int num)
Function to gather random data from multiple sources, failing whenever any of those source fail to pr...
Definition: random.cpp:318
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize a pubkey object into a serialized byte sequence.
Definition: secp256k1.c:165
A hasher class for Raven&#39;s 256-bit hash (double SHA-256).
Definition: hash.h:76
ChainCode chaincode
Definition: pubkey.h:198
const unsigned char * begin() const
Definition: key.h:84
#define SECP256K1_CONTEXT_SIGN
Definition: secp256k1.h:155
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Tweak a private key by adding tweak to it.
Definition: secp256k1.c:454
unsigned char * begin()
Definition: uint256.h:57
bool fValid
Whether this private key is valid.
Definition: key.h:41
unsigned int nChild
Definition: pubkey.h:197
const unsigned char * begin() const
Definition: pubkey.h:99
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, uint32_t test_case=0) const
Create a DER-serialized signature.
Definition: key.cpp:161
SECP256K1_API const secp256k1_nonce_function secp256k1_nonce_function_rfc6979
An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function.
Definition: secp256k1.c:342
bool SignCompact(const uint256 &hash, std::vector< unsigned char > &vchSig) const
Create a compact signature (65 bytes), which allows reconstructing the used public key...
Definition: key.cpp:190
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object.
Definition: secp256k1.c:92
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Compute the public key for a secret key.
Definition: secp256k1.c:404
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 ...
Definition: key.h:33
#define SECP256K1_EC_UNCOMPRESSED
Definition: secp256k1.h:160
#define SECP256K1_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize and secp256k1_ec_privkey_export.
Definition: secp256k1.h:159
const unsigned char * end() const
Definition: pubkey.h:100
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(const secp256k1_context *ctx, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Verify an ECDSA secret key.
Definition: secp256k1.c:391
void ECC_Stop()
Deinitialize the elliptic curve support.
Definition: key.cpp:309
unsigned char nDepth
Definition: key.h:137
void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64])
Definition: hash.cpp:76
bool IsValid() const
Definition: pubkey.h:159
SECP256K1_API int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Create an ECDSA signature.
Definition: secp256k1.c:345
SECP256K1_API int secp256k1_ecdsa_sign_recoverable(const secp256k1_context *ctx, secp256k1_ecdsa_recoverable_signature *sig, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Create a recoverable ECDSA signature.
Definition: main_impl.h:123
An encapsulated public key.
Definition: pubkey.h:40
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition: key.cpp:127
unsigned int nChild
Definition: key.h:139
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
Definition: pubkey.h:98
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
Definition: key.h:91
Opaque data structured that holds a parsed ECDSA signature.
Definition: secp256k1.h:66
SECP256K1_API int secp256k1_ecdsa_recoverable_signature_serialize_compact(const secp256k1_context *ctx, unsigned char *output64, int *recid, const secp256k1_ecdsa_recoverable_signature *sig) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize an ECDSA signature in compact format (64 bytes + recovery id).
Definition: main_impl.h:60
ChainCode chaincode
Definition: key.h:140
void SetSeed(const unsigned char *seed, unsigned int nSeedLen)
Definition: key.cpp:245
bool Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck)
Load private key and check that public key matches.
Definition: key.cpp:205
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE])
Definition: key.cpp:277
256-bit opaque blob.
Definition: uint256.h:123
SECP256K1_API int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature *sig) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize an ECDSA signature in DER format.
Definition: secp256k1.c:249
CExtPubKey Neuter() const
Definition: key.cpp:256
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Verify a DER signature (~72 bytes).
Definition: pubkey.cpp:167
bool Derive(CKey &keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
Derive BIP32 child key.
Definition: key.cpp:217
void * memcpy(void *a, const void *b, size_t c)
const unsigned char * end() const
Definition: key.h:85
const unsigned int BIP32_EXTKEY_SIZE
secp256k1: const unsigned int PRIVATE_KEY_SIZE = 279; const unsigned int PUBLIC_KEY_SIZE = 65; const ...
Definition: pubkey.h:27
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:30
bool fCompressed
Whether the public key corresponding to this private key is (to be) compressed.
Definition: key.h:44
void GetRandBytes(unsigned char *buf, int num)
Functions to gather random data via the OpenSSL PRNG.
Definition: random.cpp:274
CPubKey pubkey
Definition: pubkey.h:199
std::vector< unsigned char, secure_allocator< unsigned char > > keydata
The actual byte data.
Definition: key.h:47
static bool Check(const unsigned char *vch)
Check whether the 32-byte array pointed to by vch is valid keydata.
Definition: key.cpp:123
An encapsulated private key.
Definition: key.h:36
bool ECC_InitSanityCheck()
Check that required EC support is available at runtime.
Definition: key.cpp:285
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object.
Definition: secp256k1.c:58
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:88
Opaque data structure that holds a parsed and valid public key.
Definition: secp256k1.h:53
bool IsCompressed() const
Check whether this is a compressed public key.
Definition: pubkey.h:168
A hasher class for HMAC-SHA-512.
Definition: hmac_sha512.h:15