Dash Core  0.12.2.1
P2P Digital Currency
secp256k1.c
Go to the documentation of this file.
1 /**********************************************************************
2  * Copyright (c) 2013-2015 Pieter Wuille *
3  * Distributed under the MIT software license, see the accompanying *
4  * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
5  **********************************************************************/
6 
7 #define SECP256K1_BUILD (1)
8 
9 #include "include/secp256k1.h"
10 
11 #include "util.h"
12 #include "num_impl.h"
13 #include "field_impl.h"
14 #include "scalar_impl.h"
15 #include "group_impl.h"
16 #include "ecmult_impl.h"
17 #include "ecmult_const_impl.h"
18 #include "ecmult_gen_impl.h"
19 #include "ecdsa_impl.h"
20 #include "eckey_impl.h"
21 #include "hash_impl.h"
22 
23 #define ARG_CHECK(cond) do { \
24  if (EXPECT(!(cond), 0)) { \
25  secp256k1_callback_call(&ctx->illegal_callback, #cond); \
26  return 0; \
27  } \
28 } while(0)
29 
30 static void default_illegal_callback_fn(const char* str, void* data) {
31  (void)data;
32  fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str);
33  abort();
34 }
35 
38  NULL
39 };
40 
41 static void default_error_callback_fn(const char* str, void* data) {
42  (void)data;
43  fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
44  abort();
45 }
46 
49  NULL
50 };
51 
52 
58 };
59 
64 
67  "Invalid flags");
68  free(ret);
69  return NULL;
70  }
71 
74 
77  }
80  }
81 
82  return ret;
83 }
84 
91  return ret;
92 }
93 
95  if (ctx != NULL) {
98 
99  free(ctx);
100  }
101 }
102 
103 void secp256k1_context_set_illegal_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
104  if (fun == NULL) {
106  }
107  ctx->illegal_callback.fn = fun;
109 }
110 
111 void secp256k1_context_set_error_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
112  if (fun == NULL) {
114  }
115  ctx->error_callback.fn = fun;
117 }
118 
120  if (sizeof(secp256k1_ge_storage) == 64) {
121  /* When the secp256k1_ge_storage type is exactly 64 byte, use its
122  * representation inside secp256k1_pubkey, as conversion is very fast.
123  * Note that secp256k1_pubkey_save must use the same representation. */
125  memcpy(&s, &pubkey->data[0], 64);
127  } else {
128  /* Otherwise, fall back to 32-byte big endian for X and Y. */
129  secp256k1_fe x, y;
130  secp256k1_fe_set_b32(&x, pubkey->data);
131  secp256k1_fe_set_b32(&y, pubkey->data + 32);
132  secp256k1_ge_set_xy(ge, &x, &y);
133  }
135  return 1;
136 }
137 
139  if (sizeof(secp256k1_ge_storage) == 64) {
141  secp256k1_ge_to_storage(&s, ge);
142  memcpy(&pubkey->data[0], &s, 64);
143  } else {
147  secp256k1_fe_get_b32(pubkey->data, &ge->x);
148  secp256k1_fe_get_b32(pubkey->data + 32, &ge->y);
149  }
150 }
151 
152 int secp256k1_ec_pubkey_parse(const secp256k1_context* ctx, secp256k1_pubkey* pubkey, const unsigned char *input, size_t inputlen) {
153  secp256k1_ge Q;
154 
155  (void)ctx;
156  VERIFY_CHECK(ctx != NULL);
157  ARG_CHECK(pubkey != NULL);
158  memset(pubkey, 0, sizeof(*pubkey));
159  ARG_CHECK(input != NULL);
160  if (!secp256k1_eckey_pubkey_parse(&Q, input, inputlen)) {
161  return 0;
162  }
163  secp256k1_pubkey_save(pubkey, &Q);
164  secp256k1_ge_clear(&Q);
165  return 1;
166 }
167 
168 int secp256k1_ec_pubkey_serialize(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey* pubkey, unsigned int flags) {
169  secp256k1_ge Q;
170  size_t len;
171  int ret = 0;
172 
173  (void)ctx;
174  VERIFY_CHECK(ctx != NULL);
175  ARG_CHECK(outputlen != NULL);
176  ARG_CHECK(*outputlen >= ((flags & SECP256K1_FLAGS_BIT_COMPRESSION) ? 33 : 65));
177  len = *outputlen;
178  *outputlen = 0;
179  ARG_CHECK(output != NULL);
180  memset(output, 0, len);
181  ARG_CHECK(pubkey != NULL);
183  if (secp256k1_pubkey_load(ctx, &Q, pubkey)) {
185  if (ret) {
186  *outputlen = len;
187  }
188  }
189  return ret;
190 }
191 
193  (void)ctx;
194  if (sizeof(secp256k1_scalar) == 32) {
195  /* When the secp256k1_scalar type is exactly 32 byte, use its
196  * representation inside secp256k1_ecdsa_signature, as conversion is very fast.
197  * Note that secp256k1_ecdsa_signature_save must use the same representation. */
198  memcpy(r, &sig->data[0], 32);
199  memcpy(s, &sig->data[32], 32);
200  } else {
201  secp256k1_scalar_set_b32(r, &sig->data[0], NULL);
202  secp256k1_scalar_set_b32(s, &sig->data[32], NULL);
203  }
204 }
205 
207  if (sizeof(secp256k1_scalar) == 32) {
208  memcpy(&sig->data[0], r, 32);
209  memcpy(&sig->data[32], s, 32);
210  } else {
211  secp256k1_scalar_get_b32(&sig->data[0], r);
212  secp256k1_scalar_get_b32(&sig->data[32], s);
213  }
214 }
215 
216 int secp256k1_ecdsa_signature_parse_der(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
217  secp256k1_scalar r, s;
218 
219  (void)ctx;
220  ARG_CHECK(sig != NULL);
221  ARG_CHECK(input != NULL);
222 
223  if (secp256k1_ecdsa_sig_parse(&r, &s, input, inputlen)) {
224  secp256k1_ecdsa_signature_save(sig, &r, &s);
225  return 1;
226  } else {
227  memset(sig, 0, sizeof(*sig));
228  return 0;
229  }
230 }
231 
233  secp256k1_scalar r, s;
234  int ret = 1;
235  int overflow = 0;
236 
237  (void)ctx;
238  ARG_CHECK(sig != NULL);
239  ARG_CHECK(input64 != NULL);
240 
241  secp256k1_scalar_set_b32(&r, &input64[0], &overflow);
242  ret &= !overflow;
243  secp256k1_scalar_set_b32(&s, &input64[32], &overflow);
244  ret &= !overflow;
245  if (ret) {
246  secp256k1_ecdsa_signature_save(sig, &r, &s);
247  } else {
248  memset(sig, 0, sizeof(*sig));
249  }
250  return ret;
251 }
252 
253 int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature* sig) {
254  secp256k1_scalar r, s;
255 
256  (void)ctx;
257  ARG_CHECK(output != NULL);
258  ARG_CHECK(outputlen != NULL);
259  ARG_CHECK(sig != NULL);
260 
261  secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
262  return secp256k1_ecdsa_sig_serialize(output, outputlen, &r, &s);
263 }
264 
266  secp256k1_scalar r, s;
267 
268  (void)ctx;
269  ARG_CHECK(output64 != NULL);
270  ARG_CHECK(sig != NULL);
271 
272  secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
273  secp256k1_scalar_get_b32(&output64[0], &r);
274  secp256k1_scalar_get_b32(&output64[32], &s);
275  return 1;
276 }
277 
279  secp256k1_scalar r, s;
280  int ret = 0;
281 
282  VERIFY_CHECK(ctx != NULL);
283  ARG_CHECK(sigin != NULL);
284 
285  secp256k1_ecdsa_signature_load(ctx, &r, &s, sigin);
286  ret = secp256k1_scalar_is_high(&s);
287  if (sigout != NULL) {
288  if (ret) {
289  secp256k1_scalar_negate(&s, &s);
290  }
291  secp256k1_ecdsa_signature_save(sigout, &r, &s);
292  }
293 
294  return ret;
295 }
296 
297 int secp256k1_ecdsa_verify(const secp256k1_context* ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const secp256k1_pubkey *pubkey) {
298  secp256k1_ge q;
299  secp256k1_scalar r, s;
301  VERIFY_CHECK(ctx != NULL);
303  ARG_CHECK(msg32 != NULL);
304  ARG_CHECK(sig != NULL);
305  ARG_CHECK(pubkey != NULL);
306 
307  secp256k1_scalar_set_b32(&m, msg32, NULL);
308  secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
309  return (!secp256k1_scalar_is_high(&s) &&
310  secp256k1_pubkey_load(ctx, &q, pubkey) &&
311  secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &r, &s, &q, &m));
312 }
313 
314 static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) {
315  unsigned char keydata[112];
316  int keylen = 64;
318  unsigned int i;
319  /* We feed a byte array to the PRNG as input, consisting of:
320  * - the private key (32 bytes) and message (32 bytes), see RFC 6979 3.2d.
321  * - optionally 32 extra bytes of data, see RFC 6979 3.6 Additional Data.
322  * - optionally 16 extra bytes with the algorithm name.
323  * Because the arguments have distinct fixed lengths it is not possible for
324  * different argument mixtures to emulate each other and result in the same
325  * nonces.
326  */
327  memcpy(keydata, key32, 32);
328  memcpy(keydata + 32, msg32, 32);
329  if (data != NULL) {
330  memcpy(keydata + 64, data, 32);
331  keylen = 96;
332  }
333  if (algo16 != NULL) {
334  memcpy(keydata + keylen, algo16, 16);
335  keylen += 16;
336  }
337  secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, keylen);
338  memset(keydata, 0, sizeof(keydata));
339  for (i = 0; i <= counter; i++) {
340  secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);
341  }
343  return 1;
344 }
345 
348 
349 int secp256k1_ecdsa_sign(const secp256k1_context* ctx, secp256k1_ecdsa_signature *signature, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void* noncedata) {
350  secp256k1_scalar r, s;
351  secp256k1_scalar sec, non, msg;
352  int ret = 0;
353  int overflow = 0;
354  VERIFY_CHECK(ctx != NULL);
356  ARG_CHECK(msg32 != NULL);
357  ARG_CHECK(signature != NULL);
358  ARG_CHECK(seckey != NULL);
359  if (noncefp == NULL) {
361  }
362 
363  secp256k1_scalar_set_b32(&sec, seckey, &overflow);
364  /* Fail if the secret key is invalid. */
365  if (!overflow && !secp256k1_scalar_is_zero(&sec)) {
366  unsigned int count = 0;
367  secp256k1_scalar_set_b32(&msg, msg32, NULL);
368  while (1) {
369  unsigned char nonce32[32];
370  ret = noncefp(nonce32, msg32, seckey, NULL, (void*)noncedata, count);
371  if (!ret) {
372  break;
373  }
374  secp256k1_scalar_set_b32(&non, nonce32, &overflow);
375  memset(nonce32, 0, 32);
376  if (!overflow && !secp256k1_scalar_is_zero(&non)) {
377  if (secp256k1_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, &r, &s, &sec, &msg, &non, NULL)) {
378  break;
379  }
380  }
381  count++;
382  }
386  }
387  if (ret) {
388  secp256k1_ecdsa_signature_save(signature, &r, &s);
389  } else {
390  memset(signature, 0, sizeof(*signature));
391  }
392  return ret;
393 }
394 
395 int secp256k1_ec_seckey_verify(const secp256k1_context* ctx, const unsigned char *seckey) {
396  secp256k1_scalar sec;
397  int ret;
398  int overflow;
399  VERIFY_CHECK(ctx != NULL);
400  ARG_CHECK(seckey != NULL);
401  (void)ctx;
402 
403  secp256k1_scalar_set_b32(&sec, seckey, &overflow);
404  ret = !overflow && !secp256k1_scalar_is_zero(&sec);
406  return ret;
407 }
408 
409 int secp256k1_ec_pubkey_create(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) {
410  secp256k1_gej pj;
411  secp256k1_ge p;
412  secp256k1_scalar sec;
413  int overflow;
414  int ret = 0;
415  VERIFY_CHECK(ctx != NULL);
416  ARG_CHECK(pubkey != NULL);
417  memset(pubkey, 0, sizeof(*pubkey));
419  ARG_CHECK(seckey != NULL);
420 
421  secp256k1_scalar_set_b32(&sec, seckey, &overflow);
422  ret = (!overflow) & (!secp256k1_scalar_is_zero(&sec));
423  if (ret) {
425  secp256k1_ge_set_gej(&p, &pj);
426  secp256k1_pubkey_save(pubkey, &p);
427  }
429  return ret;
430 }
431 
432 int secp256k1_ec_privkey_tweak_add(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak) {
433  secp256k1_scalar term;
434  secp256k1_scalar sec;
435  int ret = 0;
436  int overflow = 0;
437  VERIFY_CHECK(ctx != NULL);
438  ARG_CHECK(seckey != NULL);
439  ARG_CHECK(tweak != NULL);
440  (void)ctx;
441 
442  secp256k1_scalar_set_b32(&term, tweak, &overflow);
443  secp256k1_scalar_set_b32(&sec, seckey, NULL);
444 
445  ret = !overflow && secp256k1_eckey_privkey_tweak_add(&sec, &term);
446  memset(seckey, 0, 32);
447  if (ret) {
448  secp256k1_scalar_get_b32(seckey, &sec);
449  }
450 
452  secp256k1_scalar_clear(&term);
453  return ret;
454 }
455 
456 int secp256k1_ec_pubkey_tweak_add(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak) {
457  secp256k1_ge p;
458  secp256k1_scalar term;
459  int ret = 0;
460  int overflow = 0;
461  VERIFY_CHECK(ctx != NULL);
463  ARG_CHECK(pubkey != NULL);
464  ARG_CHECK(tweak != NULL);
465 
466  secp256k1_scalar_set_b32(&term, tweak, &overflow);
467  ret = !overflow && secp256k1_pubkey_load(ctx, &p, pubkey);
468  memset(pubkey, 0, sizeof(*pubkey));
469  if (ret) {
471  secp256k1_pubkey_save(pubkey, &p);
472  } else {
473  ret = 0;
474  }
475  }
476 
477  return ret;
478 }
479 
480 int secp256k1_ec_privkey_tweak_mul(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak) {
481  secp256k1_scalar factor;
482  secp256k1_scalar sec;
483  int ret = 0;
484  int overflow = 0;
485  VERIFY_CHECK(ctx != NULL);
486  ARG_CHECK(seckey != NULL);
487  ARG_CHECK(tweak != NULL);
488  (void)ctx;
489 
490  secp256k1_scalar_set_b32(&factor, tweak, &overflow);
491  secp256k1_scalar_set_b32(&sec, seckey, NULL);
492  ret = !overflow && secp256k1_eckey_privkey_tweak_mul(&sec, &factor);
493  memset(seckey, 0, 32);
494  if (ret) {
495  secp256k1_scalar_get_b32(seckey, &sec);
496  }
497 
499  secp256k1_scalar_clear(&factor);
500  return ret;
501 }
502 
503 int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak) {
504  secp256k1_ge p;
505  secp256k1_scalar factor;
506  int ret = 0;
507  int overflow = 0;
508  VERIFY_CHECK(ctx != NULL);
510  ARG_CHECK(pubkey != NULL);
511  ARG_CHECK(tweak != NULL);
512 
513  secp256k1_scalar_set_b32(&factor, tweak, &overflow);
514  ret = !overflow && secp256k1_pubkey_load(ctx, &p, pubkey);
515  memset(pubkey, 0, sizeof(*pubkey));
516  if (ret) {
517  if (secp256k1_eckey_pubkey_tweak_mul(&ctx->ecmult_ctx, &p, &factor)) {
518  secp256k1_pubkey_save(pubkey, &p);
519  } else {
520  ret = 0;
521  }
522  }
523 
524  return ret;
525 }
526 
527 int secp256k1_context_randomize(secp256k1_context* ctx, const unsigned char *seed32) {
528  VERIFY_CHECK(ctx != NULL);
531  return 1;
532 }
533 
534 int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey *pubnonce, const secp256k1_pubkey * const *pubnonces, size_t n) {
535  size_t i;
536  secp256k1_gej Qj;
537  secp256k1_ge Q;
538 
539  ARG_CHECK(pubnonce != NULL);
540  memset(pubnonce, 0, sizeof(*pubnonce));
541  ARG_CHECK(n >= 1);
542  ARG_CHECK(pubnonces != NULL);
543 
545 
546  for (i = 0; i < n; i++) {
547  secp256k1_pubkey_load(ctx, &Q, pubnonces[i]);
548  secp256k1_gej_add_ge(&Qj, &Qj, &Q);
549  }
550  if (secp256k1_gej_is_infinity(&Qj)) {
551  return 0;
552  }
553  secp256k1_ge_set_gej(&Q, &Qj);
554  secp256k1_pubkey_save(pubnonce, &Q);
555  return 1;
556 }
557 
558 #ifdef ENABLE_MODULE_ECDH
559 # include "modules/ecdh/main_impl.h"
560 #endif
561 
562 #ifdef ENABLE_MODULE_SCHNORR
563 # include "modules/schnorr/main_impl.h"
564 #endif
565 
566 #ifdef ENABLE_MODULE_RECOVERY
568 #endif
static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx)
static int secp256k1_ge_is_infinity(const secp256k1_ge *a)
#define VERIFY_CHECK(cond)
Definition: util.h:64
static void default_error_callback_fn(const char *str, void *data)
Definition: secp256k1.c:41
int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature *sig)
Definition: secp256k1.c:253
static int secp256k1_gej_is_infinity(const secp256k1_gej *a)
static int secp256k1_fe_is_zero(const secp256k1_fe *a)
static const secp256k1_callback default_illegal_callback
Definition: secp256k1.c:36
static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp256k1_gej *r, const secp256k1_scalar *a)
static void secp256k1_fe_normalize_var(secp256k1_fe *r)
static void secp256k1_ecmult_gen_context_clone(secp256k1_ecmult_gen_context *dst, const secp256k1_ecmult_gen_context *src, const secp256k1_callback *cb)
static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256_t *rng, const unsigned char *key, size_t keylen)
static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid)
static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak)
static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter)
Definition: secp256k1.c:314
int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags)
Definition: secp256k1.c:168
unsigned char data[64]
Definition: secp256k1.h:73
static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size)
static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a)
static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const unsigned char *seed32)
static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed)
static int secp256k1_scalar_is_zero(const secp256k1_scalar *a)
int secp256k1_ecdsa_signature_parse_der(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *input, size_t inputlen)
Definition: secp256k1.c:216
static void secp256k1_pubkey_save(secp256k1_pubkey *pubkey, secp256k1_ge *ge)
Definition: secp256k1.c:138
int flags
Definition: dash-tx.cpp:326
static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256_t *rng, unsigned char *out, size_t outlen)
int secp256k1_ec_seckey_verify(const secp256k1_context *ctx, const unsigned char *seckey)
Definition: secp256k1.c:395
void(* fn)(const char *text, void *data)
Definition: util.h:19
static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *bin, int *overflow)
static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak)
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context *ctx, const secp256k1_callback *cb)
static const secp256k1_callback default_error_callback
Definition: secp256k1.c:47
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ctx)
static void secp256k1_ecdsa_signature_save(secp256k1_ecdsa_signature *sig, const secp256k1_scalar *r, const secp256k1_scalar *s)
Definition: secp256k1.c:206
#define SECP256K1_FLAGS_TYPE_CONTEXT
Definition: secp256k1.h:152
static void secp256k1_gej_set_infinity(secp256k1_gej *r)
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size)
#define SECP256K1_FLAGS_TYPE_MASK
Definition: secp256k1.h:151
static void default_illegal_callback_fn(const char *str, void *data)
Definition: secp256k1.c:30
const secp256k1_nonce_function secp256k1_nonce_function_rfc6979
Definition: secp256k1.c:346
int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *signature, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *noncedata)
Definition: secp256k1.c:349
static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256_t *rng)
static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak)
secp256k1_context * secp256k1_context_clone(const secp256k1_context *ctx)
Definition: secp256k1.c:85
int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak)
Definition: secp256k1.c:503
static void secp256k1_ecmult_context_clone(secp256k1_ecmult_context *dst, const secp256k1_ecmult_context *src, const secp256k1_callback *cb)
int secp256k1_ec_pubkey_combine(const secp256k1_context *ctx, secp256k1_pubkey *pubnonce, const secp256k1_pubkey *const *pubnonces, size_t n)
Definition: secp256k1.c:534
secp256k1_ecmult_gen_context ecmult_gen_ctx
Definition: secp256k1.c:55
#define ARG_CHECK(cond)
Definition: secp256k1.c:23
int secp256k1_ecdsa_verify(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const secp256k1_pubkey *pubkey)
Definition: secp256k1.c:297
static secp256k1_context * ctx
Definition: tests.c:42
static void secp256k1_ge_set_gej(secp256k1_ge *r, secp256k1_gej *a)
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx)
static int secp256k1_scalar_is_high(const secp256k1_scalar *a)
int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey)
Definition: secp256k1.c:409
void secp256k1_context_set_error_callback(secp256k1_context *ctx, void(*fun)(const char *message, void *data), const void *data)
Definition: secp256k1.c:111
void secp256k1_context_set_illegal_callback(secp256k1_context *ctx, void(*fun)(const char *message, void *data), const void *data)
Definition: secp256k1.c:103
secp256k1_ecmult_context ecmult_ctx
Definition: secp256k1.c:54
static void secp256k1_scalar_clear(secp256k1_scalar *r)
static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak)
secp256k1_fe x
Definition: group.h:15
static void secp256k1_ge_clear(secp256k1_ge *r)
const secp256k1_nonce_function secp256k1_nonce_function_default
Definition: secp256k1.c:347
secp256k1_callback illegal_callback
Definition: secp256k1.c:56
static void secp256k1_ecdsa_signature_load(const secp256k1_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, const secp256k1_ecdsa_signature *sig)
Definition: secp256k1.c:192
#define SECP256K1_FLAGS_BIT_CONTEXT_SIGN
Definition: secp256k1.h:156
#define EXPECT(x, c)
Definition: util.h:42
static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar *a)
static int secp256k1_fe_set_b32(secp256k1_fe *r, const unsigned char *a)
unsigned char data[64]
Definition: secp256k1.h:57
static void secp256k1_ge_set_xy(secp256k1_ge *r, const secp256k1_fe *x, const secp256k1_fe *y)
int secp256k1_ec_pubkey_parse(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *input, size_t inputlen)
Definition: secp256k1.c:152
#define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY
Definition: secp256k1.h:155
int(* secp256k1_nonce_function)(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int attempt)
Definition: secp256k1.h:92
static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context *ctx)
void * memcpy(void *a, const void *b, size_t c)
static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const secp256k1_scalar *r, const secp256k1_scalar *s, const secp256k1_ge *pubkey, const secp256k1_scalar *message)
static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback *const cb, const char *const text)
Definition: util.h:23
void secp256k1_context_destroy(secp256k1_context *ctx)
Definition: secp256k1.c:94
int secp256k1_ecdsa_signature_serialize_compact(const secp256k1_context *ctx, unsigned char *output64, const secp256k1_ecdsa_signature *sig)
Definition: secp256k1.c:265
static void secp256k1_fe_get_b32(unsigned char *r, const secp256k1_fe *a)
static void secp256k1_gej_add_ge(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b)
static int count
Definition: tests.c:41
static int secp256k1_pubkey_load(const secp256k1_context *ctx, secp256k1_ge *ge, const secp256k1_pubkey *pubkey)
Definition: secp256k1.c:119
secp256k1_callback error_callback
Definition: secp256k1.c:57
static void secp256k1_ge_from_storage(secp256k1_ge *r, const secp256k1_ge_storage *a)
const void * data
Definition: util.h:20
int secp256k1_ec_pubkey_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak)
Definition: secp256k1.c:456
int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32)
Definition: secp256k1.c:527
secp256k1_fe y
Definition: group.h:16
static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, const secp256k1_callback *cb)
int secp256k1_ec_privkey_tweak_add(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak)
Definition: secp256k1.c:432
static void secp256k1_ge_to_storage(secp256k1_ge_storage *r, const secp256k1_ge *a)
static SECP256K1_INLINE void * checked_malloc(const secp256k1_callback *cb, size_t size)
Definition: util.h:68
static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context *ctx)
static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx)
#define SECP256K1_FLAGS_TYPE_COMPRESSION
Definition: secp256k1.h:153
int secp256k1_ecdsa_signature_parse_compact(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *input64)
Definition: secp256k1.c:232
secp256k1_context * secp256k1_context_create(unsigned int flags)
Definition: secp256k1.c:60
int secp256k1_ec_privkey_tweak_mul(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak)
Definition: secp256k1.c:480
static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s)
#define SECP256K1_FLAGS_BIT_COMPRESSION
Definition: secp256k1.h:157
int secp256k1_ecdsa_signature_normalize(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sigout, const secp256k1_ecdsa_signature *sigin)
Definition: secp256k1.c:278