PIVX Core  5.6.99
P2P Digital Currency
key.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2017 The Bitcoin developers
2 // Copyright (c) 2017-2021 The PIVX 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 "crypto/common.h"
9 #include "crypto/hmac_sha512.h"
10 #include "random.h"
11 
12 #include <secp256k1.h>
13 #include <secp256k1_recovery.h>
14 
15 static secp256k1_context* secp256k1_context_sign = nullptr;
16 
34 static int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *out32, const unsigned char *privkey, size_t privkeylen) {
35  const unsigned char *end = privkey + privkeylen;
36  memset(out32, 0, 32);
37  /* sequence header */
38  if (end - privkey < 1 || *privkey != 0x30u) {
39  return 0;
40  }
41  privkey++;
42  /* sequence length constructor */
43  if (end - privkey < 1 || !(*privkey & 0x80u)) {
44  return 0;
45  }
46  ptrdiff_t lenb = *privkey & ~0x80u; privkey++;
47  if (lenb < 1 || lenb > 2) {
48  return 0;
49  }
50  if (end - privkey < lenb) {
51  return 0;
52  }
53  /* sequence length */
54  ptrdiff_t len = privkey[lenb-1] | (lenb > 1 ? privkey[lenb-2] << 8 : 0u);
55  privkey += lenb;
56  if (end - privkey < len) {
57  return 0;
58  }
59  /* sequence element 0: version number (=1) */
60  if (end - privkey < 3 || privkey[0] != 0x02u || privkey[1] != 0x01u || privkey[2] != 0x01u) {
61  return 0;
62  }
63  privkey += 3;
64  /* sequence element 1: octet string, up to 32 bytes */
65  if (end - privkey < 2 || privkey[0] != 0x04u) {
66  return 0;
67  }
68  ptrdiff_t oslen = privkey[1];
69  privkey += 2;
70  if (oslen > 32 || end - privkey < oslen) {
71  return 0;
72  }
73  memcpy(out32 + (32 - oslen), privkey, oslen);
74  if (!secp256k1_ec_seckey_verify(ctx, out32)) {
75  memset(out32, 0, 32);
76  return 0;
77  }
78  return 1;
79 }
80 
91 static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) {
92  assert(*privkeylen >= CKey::PRIVATE_KEY_SIZE);
93  secp256k1_pubkey pubkey;
94  size_t pubkeylen = 0;
95  if (!secp256k1_ec_pubkey_create(ctx, &pubkey, key32)) {
96  *privkeylen = 0;
97  return 0;
98  }
99  if (compressed) {
100  static const unsigned char begin[] = {
101  0x30,0x81,0xD3,0x02,0x01,0x01,0x04,0x20
102  };
103  static const unsigned char middle[] = {
104  0xA0,0x81,0x85,0x30,0x81,0x82,0x02,0x01,0x01,0x30,0x2C,0x06,0x07,0x2A,0x86,0x48,
105  0xCE,0x3D,0x01,0x01,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
106  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
107  0xFF,0xFF,0xFE,0xFF,0xFF,0xFC,0x2F,0x30,0x06,0x04,0x01,0x00,0x04,0x01,0x07,0x04,
108  0x21,0x02,0x79,0xBE,0x66,0x7E,0xF9,0xDC,0xBB,0xAC,0x55,0xA0,0x62,0x95,0xCE,0x87,
109  0x0B,0x07,0x02,0x9B,0xFC,0xDB,0x2D,0xCE,0x28,0xD9,0x59,0xF2,0x81,0x5B,0x16,0xF8,
110  0x17,0x98,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
111  0xFF,0xFF,0xFF,0xFF,0xFE,0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,0xBF,0xD2,0x5E,
112  0x8C,0xD0,0x36,0x41,0x41,0x02,0x01,0x01,0xA1,0x24,0x03,0x22,0x00
113  };
114  unsigned char *ptr = privkey;
115  memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
116  memcpy(ptr, key32, 32); ptr += 32;
117  memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
119  secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
120  ptr += pubkeylen;
121  *privkeylen = ptr - privkey;
122  assert(*privkeylen == CKey::COMPRESSED_PRIVATE_KEY_SIZE);
123  } else {
124  static const unsigned char begin[] = {
125  0x30,0x82,0x01,0x13,0x02,0x01,0x01,0x04,0x20
126  };
127  static const unsigned char middle[] = {
128  0xA0,0x81,0xA5,0x30,0x81,0xA2,0x02,0x01,0x01,0x30,0x2C,0x06,0x07,0x2A,0x86,0x48,
129  0xCE,0x3D,0x01,0x01,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
130  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
131  0xFF,0xFF,0xFE,0xFF,0xFF,0xFC,0x2F,0x30,0x06,0x04,0x01,0x00,0x04,0x01,0x07,0x04,
132  0x41,0x04,0x79,0xBE,0x66,0x7E,0xF9,0xDC,0xBB,0xAC,0x55,0xA0,0x62,0x95,0xCE,0x87,
133  0x0B,0x07,0x02,0x9B,0xFC,0xDB,0x2D,0xCE,0x28,0xD9,0x59,0xF2,0x81,0x5B,0x16,0xF8,
134  0x17,0x98,0x48,0x3A,0xDA,0x77,0x26,0xA3,0xC4,0x65,0x5D,0xA4,0xFB,0xFC,0x0E,0x11,
135  0x08,0xA8,0xFD,0x17,0xB4,0x48,0xA6,0x85,0x54,0x19,0x9C,0x47,0xD0,0x8F,0xFB,0x10,
136  0xD4,0xB8,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
137  0xFF,0xFF,0xFF,0xFF,0xFE,0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,0xBF,0xD2,0x5E,
138  0x8C,0xD0,0x36,0x41,0x41,0x02,0x01,0x01,0xA1,0x44,0x03,0x42,0x00
139  };
140  unsigned char *ptr = privkey;
141  memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
142  memcpy(ptr, key32, 32); ptr += 32;
143  memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
144  pubkeylen = CPubKey::PUBLIC_KEY_SIZE;
145  secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
146  ptr += pubkeylen;
147  *privkeylen = ptr - privkey;
148  assert(*privkeylen == CKey::PRIVATE_KEY_SIZE);
149  }
150  return 1;
151 }
152 
153 bool CKey::Check(const unsigned char* vch)
154 {
155  return secp256k1_ec_seckey_verify(secp256k1_context_sign, vch);
156 }
157 
158 void CKey::MakeNewKey(bool fCompressedIn)
159 {
160  do {
161  GetStrongRandBytes(keydata.data(), keydata.size());
162  } while (!Check(keydata.data()));
163  fValid = true;
164  fCompressed = fCompressedIn;
165 }
166 
168 {
169  void* key = keydata.data();
170  return *(uint256*)key;
171 }
172 
174 {
175  assert(fValid);
176  CPrivKey privkey;
177  size_t privkeylen;
178  privkey.resize(PRIVATE_KEY_SIZE);
179  privkeylen = PRIVATE_KEY_SIZE;
180  int ret = ec_privkey_export_der(secp256k1_context_sign, (unsigned char*)privkey.data(), &privkeylen, begin(), fCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
181  assert(ret);
182  privkey.resize(privkeylen);
183  return privkey;
184 }
185 
187 {
188  assert(fValid);
189  secp256k1_pubkey pubkey;
190  size_t clen = CPubKey::PUBLIC_KEY_SIZE;
191  CPubKey result;
192  int ret = secp256k1_ec_pubkey_create(secp256k1_context_sign, &pubkey, begin());
193  assert(ret);
194  secp256k1_ec_pubkey_serialize(secp256k1_context_sign, (unsigned char*)result.begin(), &clen, &pubkey, fCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
195  assert(result.size() == clen);
196  assert(result.IsValid());
197  return result;
198 }
199 
200 bool CKey::Sign(const uint256& hash, std::vector<unsigned char>& vchSig, uint32_t test_case) const
201 {
202  if (!fValid)
203  return false;
204  vchSig.resize(CPubKey::SIGNATURE_SIZE);
205  size_t nSigLen = CPubKey::SIGNATURE_SIZE;
206  unsigned char extra_entropy[32] = {0};
207  WriteLE32(extra_entropy, test_case);
209  int ret = secp256k1_ecdsa_sign(secp256k1_context_sign, &sig, hash.begin(), begin(), secp256k1_nonce_function_rfc6979, test_case ? extra_entropy : nullptr);
210  assert(ret);
211  secp256k1_ecdsa_signature_serialize_der(secp256k1_context_sign, (unsigned char*)vchSig.data(), &nSigLen, &sig);
212  vchSig.resize(nSigLen);
213  return true;
214 }
215 
216 bool CKey::VerifyPubKey(const CPubKey& pubkey) const
217 {
218  if (pubkey.IsCompressed() != fCompressed) {
219  return false;
220  }
221  unsigned char rnd[8];
222  std::string str = "Bitcoin key verification\n";
223  GetRandBytes(rnd, sizeof(rnd));
224  uint256 hash;
225  CHash256().Write((unsigned char*)str.data(), str.size()).Write(rnd, sizeof(rnd)).Finalize(hash.begin());
226  std::vector<unsigned char> vchSig;
227  Sign(hash, vchSig);
228  return pubkey.Verify(hash, vchSig);
229 }
230 
231 bool CKey::SignCompact(const uint256& hash, std::vector<unsigned char>& vchSig) const
232 {
233  if (!fValid)
234  return false;
235  vchSig.resize(CPubKey::COMPACT_SIGNATURE_SIZE);
236  int rec = -1;
238  int ret = secp256k1_ecdsa_sign_recoverable(secp256k1_context_sign, &sig, hash.begin(), begin(), secp256k1_nonce_function_rfc6979, nullptr);
239  assert(ret);
240  secp256k1_ecdsa_recoverable_signature_serialize_compact(secp256k1_context_sign, (unsigned char*)&vchSig[1], &rec, &sig);
241  assert(ret);
242  assert(rec != -1);
243  vchSig[0] = 27 + rec + (fCompressed ? 4 : 0);
244  return true;
245 }
246 
247 bool CKey::Load(const CPrivKey& privkey, const CPubKey& vchPubKey, bool fSkipCheck = false)
248 {
249  if (!ec_privkey_import_der(secp256k1_context_sign, (unsigned char*)begin(), privkey.data(), privkey.size()))
250  return false;
251  fCompressed = vchPubKey.IsCompressed();
252  fValid = true;
253 
254  if (fSkipCheck)
255  return true;
256 
257  return VerifyPubKey(vchPubKey);
258 }
259 
260 bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc) const
261 {
262  assert(IsValid());
263  assert(IsCompressed());
264  std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
265  if ((nChild >> 31) == 0) {
266  CPubKey pubkey = GetPubKey();
267  assert(pubkey.size() == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE);
268  BIP32Hash(cc, nChild, *pubkey.begin(), pubkey.begin()+1, vout.data());
269  } else {
270  assert(size() == 32);
271  BIP32Hash(cc, nChild, 0, begin(), vout.data());
272  }
273  memcpy(ccChild.begin(), vout.data()+32, 32);
274  memcpy((unsigned char*)keyChild.begin(), begin(), 32);
275  bool ret = secp256k1_ec_privkey_tweak_add(secp256k1_context_sign, (unsigned char*)keyChild.begin(), vout.data());
276  keyChild.fCompressed = true;
277  keyChild.fValid = ret;
278  return ret;
279 }
280 
281 bool CExtKey::Derive(CExtKey& out, unsigned int _nChild) const
282 {
283  out.nDepth = nDepth + 1;
284  CKeyID id = key.GetPubKey().GetID();
285  memcpy(&out.vchFingerprint[0], &id, 4);
286  out.nChild = _nChild;
287  return key.Derive(out.key, out.chaincode, _nChild, chaincode);
288 }
289 
290 void CExtKey::SetSeed(const unsigned char* seed, unsigned int nSeedLen)
291 {
292  static const unsigned char hashkey[] = {'B', 'i', 't', 'c', 'o', 'i', 'n', ' ', 's', 'e', 'e', 'd'};
293  std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
294  CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(vout.data());
295  key.Set(vout.data(), vout.data() + 32, true);
296  memcpy(chaincode.begin(), vout.data() + 32, 32);
297  nDepth = 0;
298  nChild = 0;
299  memset(vchFingerprint, 0, sizeof(vchFingerprint));
300 }
301 
303 {
304  CExtPubKey ret;
305  ret.nDepth = nDepth;
306  memcpy(&ret.vchFingerprint[0], &vchFingerprint[0], 4);
307  ret.nChild = nChild;
308  ret.pubkey = key.GetPubKey();
309  ret.chaincode = chaincode;
310  return ret;
311 }
312 
313 void CExtKey::Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const
314 {
315  code[0] = nDepth;
316  memcpy(code + 1, vchFingerprint, 4);
317  code[5] = (nChild >> 24) & 0xFF;
318  code[6] = (nChild >> 16) & 0xFF;
319  code[7] = (nChild >> 8) & 0xFF;
320  code[8] = (nChild >> 0) & 0xFF;
321  memcpy(code + 9, chaincode.begin(), 32);
322  code[41] = 0;
323  assert(key.size() == 32);
324  memcpy(code + 42, key.begin(), 32);
325 }
326 
327 void CExtKey::Decode(const unsigned char code[BIP32_EXTKEY_SIZE])
328 {
329  nDepth = code[0];
330  memcpy(vchFingerprint, code + 1, 4);
331  nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8];
332  memcpy(chaincode.begin(), code + 9, 32);
333  key.Set(code + 42, code + BIP32_EXTKEY_SIZE, true);
334 }
335 
337 {
338  CKey key;
339  key.MakeNewKey(true);
340  CPubKey pubkey = key.GetPubKey();
341  return key.VerifyPubKey(pubkey);
342 }
343 
344 void ECC_Start() {
345  assert(secp256k1_context_sign == nullptr);
346 
348  assert(ctx != nullptr);
349 
350  {
351  // Pass in a random blinding seed to the secp256k1 context.
352  std::vector<unsigned char, secure_allocator<unsigned char>> vseed(32);
353  GetRandBytes(vseed.data(), 32);
354  bool ret = secp256k1_context_randomize(ctx, vseed.data());
355  assert(ret);
356  }
357 
358  secp256k1_context_sign = ctx;
359 }
360 
361 void ECC_Stop() {
362  secp256k1_context *ctx = secp256k1_context_sign;
363  secp256k1_context_sign = nullptr;
364 
365  if (ctx) {
367  }
368 }
A hasher class for HMAC-SHA-512.
Definition: hmac_sha512.h:15
void Finalize(unsigned char hash[OUTPUT_SIZE])
Definition: hmac_sha512.cpp:29
CHMAC_SHA512 & Write(const unsigned char *data, size_t len)
Definition: hmac_sha512.h:24
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
Definition: hash.h:38
CHash256 & Write(const unsigned char *data, size_t len)
Definition: hash.h:52
void Finalize(unsigned char hash[OUTPUT_SIZE])
Definition: hash.h:45
An encapsulated private key.
Definition: key.h:30
static const unsigned int COMPRESSED_PRIVATE_KEY_SIZE
Definition: key.h:36
uint256 GetPrivKey_256()
Definition: key.cpp:167
unsigned int size() const
Simple read-only vector-like interface.
Definition: key.h:90
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:95
bool fValid
see www.keylength.com script supports up to 75 for single byte push
Definition: key.h:43
CPrivKey GetPrivKey() const
Convert the private key to a CPrivKey (serialized secp256k1 private key data).
Definition: key.cpp:173
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
Definition: key.h:98
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition: key.cpp:158
bool fCompressed
Whether the public key corresponding to this private key is (to be) compressed.
Definition: key.h:51
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:186
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, uint32_t test_case=0) const
Create a DER-serialized signature.
Definition: key.cpp:200
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
Definition: key.h:76
const unsigned char * begin() const
Definition: key.h:91
std::vector< unsigned char, secure_allocator< unsigned char > > keydata
The actual byte data.
Definition: key.h:54
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
Definition: key.cpp:216
bool Load(const CPrivKey &privkey, const CPubKey &vchPubKey, bool fSkipCheck)
Load private key and check that public key matches.
Definition: key.cpp:247
static bool Check(const unsigned char *vch)
Check whether the 32-byte array pointed to be vch is valid keydata.
Definition: key.cpp:153
bool Derive(CKey &keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
Derive BIP32 child key.
Definition: key.cpp:260
static const unsigned int PRIVATE_KEY_SIZE
secp256k1:
Definition: key.h:35
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:231
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:21
An encapsulated public key.
Definition: pubkey.h:44
bool IsCompressed() const
Check whether this is a compressed public key.
Definition: pubkey.h:192
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:167
bool IsValid() const
Definition: pubkey.h:183
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Verify a DER signature (~72 bytes).
Definition: pubkey.cpp:169
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
Definition: pubkey.h:121
const unsigned char * begin() const
Definition: pubkey.h:123
static constexpr unsigned int PUBLIC_KEY_SIZE
secp256k1:
Definition: pubkey.h:49
static constexpr unsigned int SIGNATURE_SIZE
Definition: pubkey.h:51
static constexpr unsigned int COMPRESSED_PUBLIC_KEY_SIZE
Definition: pubkey.h:50
static constexpr unsigned int COMPACT_SIGNATURE_SIZE
Definition: pubkey.h:52
unsigned char * begin()
Definition: uint256.h:63
256-bit opaque blob.
Definition: uint256.h:138
void * memcpy(void *a, const void *b, size_t c)
void BIP32Hash(const ChainCode chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64])
Definition: hash.cpp:72
bool ECC_InitSanityCheck()
Check that required EC support is available at runtime.
Definition: key.cpp:336
void ECC_Start()
Initialize the elliptic curve support.
Definition: key.cpp:344
void ECC_Stop()
Deinitialize the elliptic curve support.
Definition: key.cpp:361
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
CPrivKey is a serialized private key, with all parameters included (PRIVATE_KEY_SIZE bytes)
Definition: key.h:20
const unsigned int BIP32_EXTKEY_SIZE
Definition: pubkey.h:17
void GetRandBytes(unsigned char *buf, int num) noexcept
Overall design of the RNG and entropy sources.
Definition: random.cpp:579
void GetStrongRandBytes(unsigned char *buf, int num) noexcept
Gather entropy from various sources, feed it into the internal PRNG, and generate random data using i...
Definition: random.cpp:580
#define SECP256K1_CONTEXT_SIGN
Definition: secp256k1.h:168
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:467
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:560
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:175
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:404
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:358
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:417
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object.
Definition: secp256k1.c:59
#define SECP256K1_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize and secp256k1_ec_privkey_export.
Definition: secp256k1.h:172
#define SECP256K1_EC_UNCOMPRESSED
Definition: secp256k1.h:173
SECP256K1_API const secp256k1_nonce_function secp256k1_nonce_function_rfc6979
An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function.
Definition: secp256k1.c:355
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:259
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object.
Definition: secp256k1.c:93
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
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
Definition: key.h:148
unsigned char vchFingerprint[4]
Definition: key.h:150
CExtPubKey Neuter() const
Definition: key.cpp:302
bool Derive(CExtKey &out, unsigned int nChild) const
Definition: key.cpp:281
void SetSeed(const unsigned char *seed, unsigned int nSeedLen)
Definition: key.cpp:290
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE])
Definition: key.cpp:327
CKey key
Definition: key.h:153
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const
Definition: key.cpp:313
unsigned char nDepth
Definition: key.h:149
ChainCode chaincode
Definition: key.h:152
unsigned int nChild
Definition: key.h:151
ChainCode chaincode
Definition: pubkey.h:228
unsigned char vchFingerprint[4]
Definition: pubkey.h:226
unsigned char nDepth
Definition: pubkey.h:225
CPubKey pubkey
Definition: pubkey.h:229
unsigned int nChild
Definition: pubkey.h:227
Opaque data structured that holds a parsed ECDSA signature, supporting pubkey recovery.
Opaque data structured that holds a parsed ECDSA signature.
Definition: secp256k1.h:79
Opaque data structure that holds a parsed and valid public key.
Definition: secp256k1.h:66