Bitcoin ABC  0.22.12
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 #include "include/secp256k1.h"
9 
10 #include "assumptions.h"
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 #include "scratch_impl.h"
23 #include "selftest.h"
24 
25 #if defined(VALGRIND)
26 # include <valgrind/memcheck.h>
27 #endif
28 
29 #define ARG_CHECK(cond) do { \
30  if (EXPECT(!(cond), 0)) { \
31  secp256k1_callback_call(&ctx->illegal_callback, #cond); \
32  return 0; \
33  } \
34 } while(0)
35 
36 #define ARG_CHECK_NO_RETURN(cond) do { \
37  if (EXPECT(!(cond), 0)) { \
38  secp256k1_callback_call(&ctx->illegal_callback, #cond); \
39  } \
40 } while(0)
41 
42 #ifndef USE_EXTERNAL_DEFAULT_CALLBACKS
43 #include <stdlib.h>
44 #include <stdio.h>
45 static void secp256k1_default_illegal_callback_fn(const char* str, void* data) {
46  (void)data;
47  fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str);
48  abort();
49 }
50 static void secp256k1_default_error_callback_fn(const char* str, void* data) {
51  (void)data;
52  fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
53  abort();
54 }
55 #else
56 void secp256k1_default_illegal_callback_fn(const char* str, void* data);
57 void secp256k1_default_error_callback_fn(const char* str, void* data);
58 #endif
59 
62  NULL
63 };
64 
67  NULL
68 };
69 
76 };
77 
79  { 0 },
80  { 0 },
83  0
84 };
86 
88  size_t ret = ROUND_TO_ALIGN(sizeof(secp256k1_context));
89  /* A return value of 0 is reserved as an indicator for errors when we call this function internally. */
90  VERIFY_CHECK(ret != 0);
91 
93  secp256k1_callback_call(&default_illegal_callback,
94  "Invalid flags");
95  return 0;
96  }
97 
100  }
103  }
104  return ret;
105 }
106 
108  size_t ret = ROUND_TO_ALIGN(sizeof(secp256k1_context));
109  VERIFY_CHECK(ctx != NULL);
112  }
115  }
116  return ret;
117 }
118 
120  void* const base = prealloc;
121  size_t prealloc_size;
122  secp256k1_context* ret;
123 
124  if (!secp256k1_selftest()) {
125  secp256k1_callback_call(&default_error_callback, "self test failed");
126  }
127 
128  prealloc_size = secp256k1_context_preallocated_size(flags);
129  if (prealloc_size == 0) {
130  return NULL;
131  }
132  VERIFY_CHECK(prealloc != NULL);
133  ret = (secp256k1_context*)manual_alloc(&prealloc, sizeof(secp256k1_context), base, prealloc_size);
136 
139 
140  /* Flags have been checked by secp256k1_context_preallocated_size. */
142  if (flags & SECP256K1_FLAGS_BIT_CONTEXT_SIGN) {
144  }
146  secp256k1_ecmult_context_build(&ret->ecmult_ctx, &prealloc);
147  }
149 
150  return (secp256k1_context*) ret;
151 }
152 
154  size_t const prealloc_size = secp256k1_context_preallocated_size(flags);
155  secp256k1_context* ctx = (secp256k1_context*)checked_malloc(&default_error_callback, prealloc_size);
156  if (EXPECT(secp256k1_context_preallocated_create(ctx, flags) == NULL, 0)) {
157  free(ctx);
158  return NULL;
159  }
160 
161  return ctx;
162 }
163 
165  size_t prealloc_size;
166  secp256k1_context* ret;
167  VERIFY_CHECK(ctx != NULL);
168  ARG_CHECK(prealloc != NULL);
169 
170  prealloc_size = secp256k1_context_preallocated_clone_size(ctx);
171  ret = (secp256k1_context*)prealloc;
172  memcpy(ret, ctx, prealloc_size);
175  return ret;
176 }
177 
179  secp256k1_context* ret;
180  size_t prealloc_size;
181 
182  VERIFY_CHECK(ctx != NULL);
183  prealloc_size = secp256k1_context_preallocated_clone_size(ctx);
184  ret = (secp256k1_context*)checked_malloc(&ctx->error_callback, prealloc_size);
185  ret = secp256k1_context_preallocated_clone(ctx, ret);
186  return ret;
187 }
188 
190  ARG_CHECK_NO_RETURN(ctx != secp256k1_context_no_precomp);
191  if (ctx != NULL) {
194  }
195 }
196 
198  if (ctx != NULL) {
200  free(ctx);
201  }
202 }
203 
204 void secp256k1_context_set_illegal_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
205  ARG_CHECK_NO_RETURN(ctx != secp256k1_context_no_precomp);
206  if (fun == NULL) {
208  }
209  ctx->illegal_callback.fn = fun;
210  ctx->illegal_callback.data = data;
211 }
212 
213 void secp256k1_context_set_error_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
214  ARG_CHECK_NO_RETURN(ctx != secp256k1_context_no_precomp);
215  if (fun == NULL) {
217  }
218  ctx->error_callback.fn = fun;
219  ctx->error_callback.data = data;
220 }
221 
223  VERIFY_CHECK(ctx != NULL);
224  return secp256k1_scratch_create(&ctx->error_callback, max_size);
225 }
226 
228  VERIFY_CHECK(ctx != NULL);
230 }
231 
232 /* Mark memory as no-longer-secret for the purpose of analysing constant-time behaviour
233  * of the software. This is setup for use with valgrind but could be substituted with
234  * the appropriate instrumentation for other analysis tools.
235  */
236 static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context* ctx, const void *p, size_t len) {
237 #if defined(VALGRIND)
238  if (EXPECT(ctx->declassify,0)) VALGRIND_MAKE_MEM_DEFINED(p, len);
239 #else
240  (void)ctx;
241  (void)p;
242  (void)len;
243 #endif
244 }
245 
246 static int secp256k1_pubkey_load(const secp256k1_context* ctx, secp256k1_ge* ge, const secp256k1_pubkey* pubkey) {
247  if (sizeof(secp256k1_ge_storage) == 64) {
248  /* When the secp256k1_ge_storage type is exactly 64 byte, use its
249  * representation inside secp256k1_pubkey, as conversion is very fast.
250  * Note that secp256k1_pubkey_save must use the same representation. */
252  memcpy(&s, &pubkey->data[0], sizeof(s));
254  } else {
255  /* Otherwise, fall back to 32-byte big endian for X and Y. */
256  secp256k1_fe x, y;
257  secp256k1_fe_set_b32(&x, pubkey->data);
258  secp256k1_fe_set_b32(&y, pubkey->data + 32);
259  secp256k1_ge_set_xy(ge, &x, &y);
260  }
262  return 1;
263 }
264 
266  if (sizeof(secp256k1_ge_storage) == 64) {
268  secp256k1_ge_to_storage(&s, ge);
269  memcpy(&pubkey->data[0], &s, sizeof(s));
270  } else {
274  secp256k1_fe_get_b32(pubkey->data, &ge->x);
275  secp256k1_fe_get_b32(pubkey->data + 32, &ge->y);
276  }
277 }
278 
279 int secp256k1_ec_pubkey_parse(const secp256k1_context* ctx, secp256k1_pubkey* pubkey, const unsigned char *input, size_t inputlen) {
280  secp256k1_ge Q;
281 
282  VERIFY_CHECK(ctx != NULL);
283  ARG_CHECK(pubkey != NULL);
284  memset(pubkey, 0, sizeof(*pubkey));
285  ARG_CHECK(input != NULL);
286  if (!secp256k1_eckey_pubkey_parse(&Q, input, inputlen)) {
287  return 0;
288  }
290  return 0;
291  }
292  secp256k1_pubkey_save(pubkey, &Q);
293  secp256k1_ge_clear(&Q);
294  return 1;
295 }
296 
297 int secp256k1_ec_pubkey_serialize(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey* pubkey, unsigned int flags) {
298  secp256k1_ge Q;
299  size_t len;
300  int ret = 0;
301 
302  VERIFY_CHECK(ctx != NULL);
303  ARG_CHECK(outputlen != NULL);
304  ARG_CHECK(*outputlen >= ((flags & SECP256K1_FLAGS_BIT_COMPRESSION) ? 33u : 65u));
305  len = *outputlen;
306  *outputlen = 0;
307  ARG_CHECK(output != NULL);
308  memset(output, 0, len);
309  ARG_CHECK(pubkey != NULL);
311  if (secp256k1_pubkey_load(ctx, &Q, pubkey)) {
312  ret = secp256k1_eckey_pubkey_serialize(&Q, output, &len, flags & SECP256K1_FLAGS_BIT_COMPRESSION);
313  if (ret) {
314  *outputlen = len;
315  }
316  }
317  return ret;
318 }
319 
321  (void)ctx;
322  if (sizeof(secp256k1_scalar) == 32) {
323  /* When the secp256k1_scalar type is exactly 32 byte, use its
324  * representation inside secp256k1_ecdsa_signature, as conversion is very fast.
325  * Note that secp256k1_ecdsa_signature_save must use the same representation. */
326  memcpy(r, &sig->data[0], 32);
327  memcpy(s, &sig->data[32], 32);
328  } else {
329  secp256k1_scalar_set_b32(r, &sig->data[0], NULL);
330  secp256k1_scalar_set_b32(s, &sig->data[32], NULL);
331  }
332 }
333 
335  if (sizeof(secp256k1_scalar) == 32) {
336  memcpy(&sig->data[0], r, 32);
337  memcpy(&sig->data[32], s, 32);
338  } else {
339  secp256k1_scalar_get_b32(&sig->data[0], r);
340  secp256k1_scalar_get_b32(&sig->data[32], s);
341  }
342 }
343 
344 int secp256k1_ecdsa_signature_parse_der(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
345  secp256k1_scalar r, s;
346 
347  VERIFY_CHECK(ctx != NULL);
348  ARG_CHECK(sig != NULL);
349  ARG_CHECK(input != NULL);
350 
351  if (secp256k1_ecdsa_sig_parse(&r, &s, input, inputlen)) {
352  secp256k1_ecdsa_signature_save(sig, &r, &s);
353  return 1;
354  } else {
355  memset(sig, 0, sizeof(*sig));
356  return 0;
357  }
358 }
359 
361  secp256k1_scalar r, s;
362  int ret = 1;
363  int overflow = 0;
364 
365  VERIFY_CHECK(ctx != NULL);
366  ARG_CHECK(sig != NULL);
367  ARG_CHECK(input64 != NULL);
368 
369  secp256k1_scalar_set_b32(&r, &input64[0], &overflow);
370  ret &= !overflow;
371  secp256k1_scalar_set_b32(&s, &input64[32], &overflow);
372  ret &= !overflow;
373  if (ret) {
374  secp256k1_ecdsa_signature_save(sig, &r, &s);
375  } else {
376  memset(sig, 0, sizeof(*sig));
377  }
378  return ret;
379 }
380 
381 int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature* sig) {
382  secp256k1_scalar r, s;
383 
384  VERIFY_CHECK(ctx != NULL);
385  ARG_CHECK(output != NULL);
386  ARG_CHECK(outputlen != NULL);
387  ARG_CHECK(sig != NULL);
388 
389  secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
390  return secp256k1_ecdsa_sig_serialize(output, outputlen, &r, &s);
391 }
392 
394  secp256k1_scalar r, s;
395 
396  VERIFY_CHECK(ctx != NULL);
397  ARG_CHECK(output64 != NULL);
398  ARG_CHECK(sig != NULL);
399 
400  secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
401  secp256k1_scalar_get_b32(&output64[0], &r);
402  secp256k1_scalar_get_b32(&output64[32], &s);
403  return 1;
404 }
405 
407  secp256k1_scalar r, s;
408  int ret = 0;
409 
410  VERIFY_CHECK(ctx != NULL);
411  ARG_CHECK(sigin != NULL);
412 
413  secp256k1_ecdsa_signature_load(ctx, &r, &s, sigin);
414  ret = secp256k1_scalar_is_high(&s);
415  if (sigout != NULL) {
416  if (ret) {
417  secp256k1_scalar_negate(&s, &s);
418  }
419  secp256k1_ecdsa_signature_save(sigout, &r, &s);
420  }
421 
422  return ret;
423 }
424 
425 int secp256k1_ecdsa_verify(const secp256k1_context* ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const secp256k1_pubkey *pubkey) {
426  secp256k1_ge q;
427  secp256k1_scalar r, s;
429  VERIFY_CHECK(ctx != NULL);
431  ARG_CHECK(msg32 != NULL);
432  ARG_CHECK(sig != NULL);
433  ARG_CHECK(pubkey != NULL);
434 
435  secp256k1_scalar_set_b32(&m, msg32, NULL);
436  secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
437  return (!secp256k1_scalar_is_high(&s) &&
438  secp256k1_pubkey_load(ctx, &q, pubkey) &&
439  secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &r, &s, &q, &m));
440 }
441 
442 static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *offset, const void *data, unsigned int len) {
443  memcpy(buf + *offset, data, len);
444  *offset += len;
445 }
446 
447 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) {
448  unsigned char keydata[112];
449  unsigned int offset = 0;
451  unsigned int i;
452  /* We feed a byte array to the PRNG as input, consisting of:
453  * - the private key (32 bytes) and message (32 bytes), see RFC 6979 3.2d.
454  * - optionally 32 extra bytes of data, see RFC 6979 3.6 Additional Data.
455  * - optionally 16 extra bytes with the algorithm name.
456  * Because the arguments have distinct fixed lengths it is not possible for
457  * different argument mixtures to emulate each other and result in the same
458  * nonces.
459  */
460  buffer_append(keydata, &offset, key32, 32);
461  buffer_append(keydata, &offset, msg32, 32);
462  if (data != NULL) {
463  buffer_append(keydata, &offset, data, 32);
464  }
465  if (algo16 != NULL) {
466  buffer_append(keydata, &offset, algo16, 16);
467  }
468  secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, offset);
469  memset(keydata, 0, sizeof(keydata));
470  for (i = 0; i <= counter; i++) {
471  secp256k1_rfc6979_hmac_sha256_generate(&rng, nonce32, 32);
472  }
474  return 1;
475 }
476 
479 
480 static int secp256k1_ecdsa_sign_inner(const secp256k1_context* ctx, secp256k1_scalar* r, secp256k1_scalar* s, int* recid, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const unsigned char algo16[17], const void* noncedata) {
481  secp256k1_scalar sec, non, msg;
482  int ret = 0;
483  int is_sec_valid;
484  unsigned char nonce32[32];
485  unsigned int count = 0;
486  /* Default initialization here is important so we won't pass uninit values to the cmov in the end */
489  if (recid) {
490  *recid = 0;
491  }
492  if (noncefp == NULL) {
494  }
495 
496  /* Fail if the secret key is invalid. */
497  is_sec_valid = secp256k1_scalar_set_b32_seckey(&sec, seckey);
498  secp256k1_scalar_cmov(&sec, &secp256k1_scalar_one, !is_sec_valid);
499  secp256k1_scalar_set_b32(&msg, msg32, NULL);
500  while (1) {
501  int is_nonce_valid;
502  ret = !!noncefp(nonce32, msg32, seckey, algo16, (void*)noncedata, count);
503  if (!ret) {
504  break;
505  }
506  is_nonce_valid = secp256k1_scalar_set_b32_seckey(&non, nonce32);
507  /* The nonce is still secret here, but it being invalid is is less likely than 1:2^255. */
508  secp256k1_declassify(ctx, &is_nonce_valid, sizeof(is_nonce_valid));
509  if (is_nonce_valid) {
510  ret = secp256k1_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, r, s, &sec, &msg, &non, recid);
511  /* The final signature is no longer a secret, nor is the fact that we were successful or not. */
512  secp256k1_declassify(ctx, &ret, sizeof(ret));
513  if (ret) {
514  break;
515  }
516  }
517  count++;
518  }
519  /* We don't want to declassify is_sec_valid and therefore the range of
520  * seckey. As a result is_sec_valid is included in ret only after ret was
521  * used as a branching variable. */
522  ret &= is_sec_valid;
523  memset(nonce32, 0, 32);
529  if (recid) {
530  const int zero = 0;
531  secp256k1_int_cmov(recid, &zero, !ret);
532  }
533  return ret;
534 }
535 
536 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) {
537  secp256k1_scalar r, s;
538  int ret;
539  const unsigned char secp256k1_ecdsa_der_algo16[17] = "ECDSA+DER ";
540  VERIFY_CHECK(ctx != NULL);
542  ARG_CHECK(msg32 != NULL);
543  ARG_CHECK(signature != NULL);
544  ARG_CHECK(seckey != NULL);
545 
546  ret = secp256k1_ecdsa_sign_inner(ctx, &r, &s, NULL, msg32, seckey, noncefp, secp256k1_ecdsa_der_algo16, noncedata);
547  secp256k1_ecdsa_signature_save(signature, &r, &s);
548  return ret;
549 }
550 
551 int secp256k1_ec_seckey_verify(const secp256k1_context* ctx, const unsigned char *seckey) {
552  secp256k1_scalar sec;
553  int ret;
554  VERIFY_CHECK(ctx != NULL);
555  ARG_CHECK(seckey != NULL);
556 
557  ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
559  return ret;
560 }
561 
562 static int secp256k1_ec_pubkey_create_helper(const secp256k1_ecmult_gen_context *ecmult_gen_ctx, secp256k1_scalar *seckey_scalar, secp256k1_ge *p, const unsigned char *seckey) {
563  secp256k1_gej pj;
564  int ret;
565 
566  ret = secp256k1_scalar_set_b32_seckey(seckey_scalar, seckey);
567  secp256k1_scalar_cmov(seckey_scalar, &secp256k1_scalar_one, !ret);
568 
569  secp256k1_ecmult_gen(ecmult_gen_ctx, &pj, seckey_scalar);
570  secp256k1_ge_set_gej(p, &pj);
571  return ret;
572 }
573 
574 int secp256k1_ec_pubkey_create(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) {
575  secp256k1_ge p;
576  secp256k1_scalar seckey_scalar;
577  int ret = 0;
578  VERIFY_CHECK(ctx != NULL);
579  ARG_CHECK(pubkey != NULL);
580  memset(pubkey, 0, sizeof(*pubkey));
582  ARG_CHECK(seckey != NULL);
583 
584  ret = secp256k1_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &seckey_scalar, &p, seckey);
585  secp256k1_pubkey_save(pubkey, &p);
586  memczero(pubkey, sizeof(*pubkey), !ret);
587 
588  secp256k1_scalar_clear(&seckey_scalar);
589  return ret;
590 }
591 
592 int secp256k1_ec_seckey_negate(const secp256k1_context* ctx, unsigned char *seckey) {
593  secp256k1_scalar sec;
594  int ret = 0;
595  VERIFY_CHECK(ctx != NULL);
596  ARG_CHECK(seckey != NULL);
597 
598  ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
600  secp256k1_scalar_negate(&sec, &sec);
601  secp256k1_scalar_get_b32(seckey, &sec);
602 
604  return ret;
605 }
606 
607 int secp256k1_ec_privkey_negate(const secp256k1_context* ctx, unsigned char *seckey) {
608  return secp256k1_ec_seckey_negate(ctx, seckey);
609 }
610 
612  int ret = 0;
613  secp256k1_ge p;
614  VERIFY_CHECK(ctx != NULL);
615  ARG_CHECK(pubkey != NULL);
616 
617  ret = secp256k1_pubkey_load(ctx, &p, pubkey);
618  memset(pubkey, 0, sizeof(*pubkey));
619  if (ret) {
620  secp256k1_ge_neg(&p, &p);
621  secp256k1_pubkey_save(pubkey, &p);
622  }
623  return ret;
624 }
625 
626 
627 static int secp256k1_ec_seckey_tweak_add_helper(secp256k1_scalar *sec, const unsigned char *tweak) {
628  secp256k1_scalar term;
629  int overflow = 0;
630  int ret = 0;
631 
632  secp256k1_scalar_set_b32(&term, tweak, &overflow);
633  ret = (!overflow) & secp256k1_eckey_privkey_tweak_add(sec, &term);
634  secp256k1_scalar_clear(&term);
635  return ret;
636 }
637 
638 int secp256k1_ec_seckey_tweak_add(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak) {
639  secp256k1_scalar sec;
640  int ret = 0;
641  VERIFY_CHECK(ctx != NULL);
642  ARG_CHECK(seckey != NULL);
643  ARG_CHECK(tweak != NULL);
644 
645  ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
646  ret &= secp256k1_ec_seckey_tweak_add_helper(&sec, tweak);
648  secp256k1_scalar_get_b32(seckey, &sec);
649 
651  return ret;
652 }
653 
654 int secp256k1_ec_privkey_tweak_add(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak) {
655  return secp256k1_ec_seckey_tweak_add(ctx, seckey, tweak);
656 }
657 
658 static int secp256k1_ec_pubkey_tweak_add_helper(const secp256k1_ecmult_context* ecmult_ctx, secp256k1_ge *p, const unsigned char *tweak) {
659  secp256k1_scalar term;
660  int overflow = 0;
661  secp256k1_scalar_set_b32(&term, tweak, &overflow);
662  return !overflow && secp256k1_eckey_pubkey_tweak_add(ecmult_ctx, p, &term);
663 }
664 
665 int secp256k1_ec_pubkey_tweak_add(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak) {
666  secp256k1_ge p;
667  int ret = 0;
668  VERIFY_CHECK(ctx != NULL);
670  ARG_CHECK(pubkey != NULL);
671  ARG_CHECK(tweak != NULL);
672 
673  ret = secp256k1_pubkey_load(ctx, &p, pubkey);
674  memset(pubkey, 0, sizeof(*pubkey));
675  ret = ret && secp256k1_ec_pubkey_tweak_add_helper(&ctx->ecmult_ctx, &p, tweak);
676  if (ret) {
677  secp256k1_pubkey_save(pubkey, &p);
678  }
679 
680  return ret;
681 }
682 
683 int secp256k1_ec_seckey_tweak_mul(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak) {
684  secp256k1_scalar factor;
685  secp256k1_scalar sec;
686  int ret = 0;
687  int overflow = 0;
688  VERIFY_CHECK(ctx != NULL);
689  ARG_CHECK(seckey != NULL);
690  ARG_CHECK(tweak != NULL);
691 
692  secp256k1_scalar_set_b32(&factor, tweak, &overflow);
693  ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
694  ret &= (!overflow) & secp256k1_eckey_privkey_tweak_mul(&sec, &factor);
696  secp256k1_scalar_get_b32(seckey, &sec);
697 
699  secp256k1_scalar_clear(&factor);
700  return ret;
701 }
702 
703 int secp256k1_ec_privkey_tweak_mul(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak) {
704  return secp256k1_ec_seckey_tweak_mul(ctx, seckey, tweak);
705 }
706 
707 int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak) {
708  secp256k1_ge p;
709  secp256k1_scalar factor;
710  int ret = 0;
711  int overflow = 0;
712  VERIFY_CHECK(ctx != NULL);
714  ARG_CHECK(pubkey != NULL);
715  ARG_CHECK(tweak != NULL);
716 
717  secp256k1_scalar_set_b32(&factor, tweak, &overflow);
718  ret = !overflow && secp256k1_pubkey_load(ctx, &p, pubkey);
719  memset(pubkey, 0, sizeof(*pubkey));
720  if (ret) {
721  if (secp256k1_eckey_pubkey_tweak_mul(&ctx->ecmult_ctx, &p, &factor)) {
722  secp256k1_pubkey_save(pubkey, &p);
723  } else {
724  ret = 0;
725  }
726  }
727 
728  return ret;
729 }
730 
731 int secp256k1_context_randomize(secp256k1_context* ctx, const unsigned char *seed32) {
732  VERIFY_CHECK(ctx != NULL);
735  }
736  return 1;
737 }
738 
739 int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey *pubnonce, const secp256k1_pubkey * const *pubnonces, size_t n) {
740  size_t i;
741  secp256k1_gej Qj;
742  secp256k1_ge Q;
743 
744  ARG_CHECK(pubnonce != NULL);
745  memset(pubnonce, 0, sizeof(*pubnonce));
746  ARG_CHECK(n >= 1);
747  ARG_CHECK(pubnonces != NULL);
748 
750 
751  for (i = 0; i < n; i++) {
752  secp256k1_pubkey_load(ctx, &Q, pubnonces[i]);
753  secp256k1_gej_add_ge(&Qj, &Qj, &Q);
754  }
755  if (secp256k1_gej_is_infinity(&Qj)) {
756  return 0;
757  }
758  secp256k1_ge_set_gej(&Q, &Qj);
759  secp256k1_pubkey_save(pubnonce, &Q);
760  return 1;
761 }
762 
763 #ifdef ENABLE_MODULE_ECDH
764 # include "modules/ecdh/main_impl.h"
765 #endif
766 
767 #ifdef ENABLE_MODULE_MULTISET
769 #endif
770 
771 #ifdef ENABLE_MODULE_RECOVERY
773 #endif
774 
775 #ifdef ENABLE_MODULE_SCHNORR
776 # include "modules/schnorr/main_impl.h"
777 #endif
778 
779 #ifdef ENABLE_MODULE_EXTRAKEYS
781 #endif
782 
783 #ifdef ENABLE_MODULE_SCHNORRSIG
785 #endif
static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx)
static int secp256k1_ge_is_infinity(const secp256k1_ge *a)
Check whether a group element is the point at infinity.
#define VERIFY_CHECK(cond)
Definition: util.h:68
int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature *sig)
Serialize an ECDSA signature in DER format.
Definition: secp256k1.c:381
static void secp256k1_ecmult_gen_context_finalize_memcpy(secp256k1_ecmult_gen_context *dst, const secp256k1_ecmult_gen_context *src)
static int secp256k1_gej_is_infinity(const secp256k1_gej *a)
Check whether a group element is the point at infinity.
#define SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY
Definition: secp256k1.h:165
static int secp256k1_fe_is_zero(const secp256k1_fe *a)
Verify whether a field element is zero.
static const secp256k1_callback default_illegal_callback
Definition: secp256k1.c:60
std::array< uint8_t, 64 > sig
Definition: processor.cpp:248
static void secp256k1_ge_neg(secp256k1_ge *r, const secp256k1_ge *a)
Set r equal to the inverse of a (i.e., mirrored around the X axis)
int secp256k1_ec_privkey_negate(const secp256k1_context *ctx, unsigned char *seckey)
Same as secp256k1_ec_seckey_negate, but DEPRECATED.
Definition: secp256k1.c:607
static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp256k1_gej *r, const secp256k1_scalar *a)
Multiply with the generator: R = a*G.
static void secp256k1_fe_normalize_var(secp256k1_fe *r)
Normalize a field element, without constant-time guarantee.
static void secp256k1_scratch_destroy(const secp256k1_callback *error_callback, secp256k1_scratch *scratch)
static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256 *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)
secp256k1_scratch_space * secp256k1_scratch_space_create(const secp256k1_context *ctx, size_t max_size)
Create a secp256k1 scratch space object.
Definition: secp256k1.c:222
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:447
void secp256k1_context_preallocated_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object that has been created in caller-provided memory.
Definition: secp256k1.c:189
int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags)
Serialize a pubkey object into a serialized byte sequence.
Definition: secp256k1.c:297
secp256k1_context * ctx
static int secp256k1_ec_pubkey_tweak_add_helper(const secp256k1_ecmult_context *ecmult_ctx, secp256k1_ge *p, const unsigned char *tweak)
Definition: secp256k1.c:658
unsigned char data[64]
Definition: secp256k1.h:81
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)
Compute the complement of a scalar (modulo the group order).
static int secp256k1_ec_seckey_tweak_add_helper(secp256k1_scalar *sec, const unsigned char *tweak)
Definition: secp256k1.c:627
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context *ctx, void **prealloc)
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 void secp256k1_default_error_callback_fn(const char *str, void *data)
Definition: secp256k1.c:50
int secp256k1_ecdsa_signature_parse_der(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *input, size_t inputlen)
Parse a DER ECDSA signature.
Definition: secp256k1.c:344
static void secp256k1_pubkey_save(secp256k1_pubkey *pubkey, secp256k1_ge *ge)
Definition: secp256k1.c:265
secp256k1_context * secp256k1_context_preallocated_create(void *prealloc, unsigned int flags)
Create a secp256k1 context object in caller-provided memory.
Definition: secp256k1.c:119
int secp256k1_ec_seckey_verify(const secp256k1_context *ctx, const unsigned char *seckey)
Verify an ECDSA secret key.
Definition: secp256k1.c:551
void(* fn)(const char *text, void *data)
Definition: util.h:20
static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *bin, int *overflow)
Set a scalar from a big endian byte array.
A group element of the secp256k1 curve, in jacobian coordinates.
Definition: group.h:24
static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak)
static const secp256k1_callback default_error_callback
Definition: secp256k1.c:65
secp256k1_context * secp256k1_context_preallocated_clone(const secp256k1_context *ctx, void *prealloc)
Copy a secp256k1 context object into caller-provided memory.
Definition: secp256k1.c:164
static void secp256k1_default_illegal_callback_fn(const char *str, void *data)
Definition: secp256k1.c:45
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ctx)
static SECP256K1_INLINE void * manual_alloc(void **prealloc_ptr, size_t alloc_size, void *base, size_t max_size)
Definition: util.h:134
static void secp256k1_ecdsa_signature_save(secp256k1_ecdsa_signature *sig, const secp256k1_scalar *r, const secp256k1_scalar *s)
Definition: secp256k1.c:334
#define SECP256K1_FLAGS_TYPE_CONTEXT
Definition: secp256k1.h:160
static int secp256k1_selftest(void)
Definition: selftest.h:28
static void secp256k1_gej_set_infinity(secp256k1_gej *r)
Set a group element (jacobian) equal to the point at infinity.
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size)
#define SECP256K1_FLAGS_TYPE_MASK
All flags&#39; lower 8 bits indicate what they&#39;re for.
Definition: secp256k1.h:159
const secp256k1_nonce_function secp256k1_nonce_function_rfc6979
An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function.
Definition: secp256k1.c:477
static const secp256k1_scalar secp256k1_scalar_zero
Definition: scalar_impl.h:32
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)
Create an ECDSA signature.
Definition: secp256k1.c:536
static int secp256k1_ecdsa_sign_inner(const secp256k1_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, int *recid, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const unsigned char algo16[17], const void *noncedata)
Definition: secp256k1.c:480
static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak)
#define SECP256K1_INLINE
Definition: secp256k1.h:124
static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context *ctx, const void *p, size_t len)
Definition: secp256k1.c:236
secp256k1_context * secp256k1_context_clone(const secp256k1_context *ctx)
Copy a secp256k1 context object (into dynamically allocated memory).
Definition: secp256k1.c:178
int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak)
Tweak a public key by multiplying it by a tweak value.
Definition: secp256k1.c:707
int secp256k1_ec_pubkey_combine(const secp256k1_context *ctx, secp256k1_pubkey *pubnonce, const secp256k1_pubkey *const *pubnonces, size_t n)
Add a number of public keys together.
Definition: secp256k1.c:739
static const secp256k1_context secp256k1_context_no_precomp_
Definition: secp256k1.c:78
secp256k1_ecmult_gen_context ecmult_gen_ctx
Definition: secp256k1.c:72
#define ARG_CHECK(cond)
Definition: secp256k1.c:29
int secp256k1_ecdsa_verify(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msg32, const secp256k1_pubkey *pubkey)
Verify an ECDSA signature.
Definition: secp256k1.c:425
static int secp256k1_ec_pubkey_create_helper(const secp256k1_ecmult_gen_context *ecmult_gen_ctx, secp256k1_scalar *seckey_scalar, secp256k1_ge *p, const unsigned char *seckey)
Definition: secp256k1.c:562
static void secp256k1_ge_set_gej(secp256k1_ge *r, secp256k1_gej *a)
Set a group element equal to another which is given in jacobian coordinates.
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx)
static int secp256k1_scalar_is_high(const secp256k1_scalar *a)
Check whether a scalar is higher than the group order divided by 2.
static int secp256k1_ge_is_in_correct_subgroup(const secp256k1_ge *ge)
Determine if a point (which is assumed to be on the curve) is in the correct (sub)group of the curve...
int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey)
Compute the public key for a secret key.
Definition: secp256k1.c:574
static int secp256k1_scalar_set_b32_seckey(secp256k1_scalar *r, const unsigned char *bin)
Set a scalar from a big endian byte array and returns 1 if it is a valid seckey and 0 otherwise...
void secp256k1_context_set_error_callback(secp256k1_context *ctx, void(*fun)(const char *message, void *data), const void *data)
Set a callback function to be called when an internal consistency check fails.
Definition: secp256k1.c:213
void secp256k1_context_set_illegal_callback(secp256k1_context *ctx, void(*fun)(const char *message, void *data), const void *data)
Set a callback function to be called when an illegal argument is passed to an API call...
Definition: secp256k1.c:204
#define ARG_CHECK_NO_RETURN(cond)
Definition: secp256k1.c:36
secp256k1_ecmult_context ecmult_ctx
Definition: secp256k1.c:71
static void secp256k1_scalar_clear(secp256k1_scalar *r)
Clear a scalar to prevent the leak of sensitive data.
static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak)
A group element of the secp256k1 curve, in affine coordinates.
Definition: group.h:14
Opaque data structured that holds a parsed ECDSA signature.
Definition: secp256k1.h:80
secp256k1_fe x
Definition: group.h:15
int secp256k1_ec_seckey_tweak_mul(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak)
Tweak a secret key by multiplying it by a tweak.
Definition: secp256k1.c:683
static void secp256k1_ge_clear(secp256k1_ge *r)
Clear a secp256k1_ge to prevent leaking sensitive information.
const secp256k1_nonce_function secp256k1_nonce_function_default
A default safe nonce generation function (currently equal to secp256k1_nonce_function_rfc6979).
Definition: secp256k1.c:478
A scalar modulo the group order of the secp256k1 curve.
Definition: scalar_4x64.h:13
secp256k1_callback illegal_callback
Definition: secp256k1.c:73
static void secp256k1_ecdsa_signature_load(const secp256k1_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, const secp256k1_ecdsa_signature *sig)
Definition: secp256k1.c:320
#define SECP256K1_FLAGS_BIT_CONTEXT_SIGN
Definition: secp256k1.h:164
#define EXPECT(x, c)
Definition: util.h:43
static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar *a)
Convert a scalar to a byte array.
int secp256k1_ec_pubkey_negate(const secp256k1_context *ctx, secp256k1_pubkey *pubkey)
Negates a public key in place.
Definition: secp256k1.c:611
static int secp256k1_fe_set_b32(secp256k1_fe *r, const unsigned char *a)
Set a field element equal to 32-byte big endian value.
int flags
Definition: bitcoin-tx.cpp:529
unsigned char data[64]
Definition: secp256k1.h:68
static void secp256k1_ge_set_xy(secp256k1_ge *r, const secp256k1_fe *x, const secp256k1_fe *y)
Set a group element equal to the point with given X and Y coordinates.
static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *offset, const void *data, unsigned int len)
Definition: secp256k1.c:442
int secp256k1_ec_pubkey_parse(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *input, size_t inputlen)
Parse a variable-length public key into the pubkey object.
Definition: secp256k1.c:279
#define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY
The higher bits contain the actual data.
Definition: secp256k1.h:163
int(* secp256k1_nonce_function)(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int attempt)
A pointer to a function to deterministically generate a nonce.
Definition: secp256k1.h:100
static void secp256k1_ecmult_context_finalize_memcpy(secp256k1_ecmult_context *dst, const secp256k1_ecmult_context *src)
static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context *ctx)
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)
int secp256k1_ec_seckey_tweak_add(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak)
Tweak a secret key by adding tweak to it.
Definition: secp256k1.c:638
static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback *const cb, const char *const text)
Definition: util.h:24
void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object (created in dynamically allocated memory).
Definition: secp256k1.c:197
int secp256k1_ecdsa_signature_serialize_compact(const secp256k1_context *ctx, unsigned char *output64, const secp256k1_ecdsa_signature *sig)
Serialize an ECDSA signature in compact (64 byte) format.
Definition: secp256k1.c:393
static void secp256k1_fe_get_b32(unsigned char *r, const secp256k1_fe *a)
Convert a field element to a 32-byte big endian value.
#define ROUND_TO_ALIGN(size)
Definition: util.h:116
static const size_t SECP256K1_ECMULT_CONTEXT_PREALLOCATED_SIZE
Definition: ecmult.h:21
static void secp256k1_gej_add_ge(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b)
Set r equal to the sum of a and b (with b given in affine coordinates, and not infinity).
static int count
Definition: tests.c:35
static int secp256k1_pubkey_load(const secp256k1_context *ctx, secp256k1_ge *ge, const secp256k1_pubkey *pubkey)
Definition: secp256k1.c:246
secp256k1_callback error_callback
Definition: secp256k1.c:74
static void secp256k1_ge_from_storage(secp256k1_ge *r, const secp256k1_ge_storage *a)
Convert a group element back from the storage type.
void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space *scratch)
Destroy a secp256k1 scratch space.
Definition: secp256k1.c:227
size_t secp256k1_context_preallocated_clone_size(const secp256k1_context *ctx)
Determine the memory size of a secp256k1 context object to be copied into caller-provided memory...
Definition: secp256k1.c:107
static const size_t SECP256K1_ECMULT_GEN_CONTEXT_PREALLOCATED_SIZE
Definition: ecmult_gen.h:38
const secp256k1_context * secp256k1_context_no_precomp
A simple secp256k1 context object with no precomputed tables.
Definition: secp256k1.c:85
const void * data
Definition: util.h:21
int secp256k1_ec_pubkey_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak)
Tweak a public key by adding tweak times the generator to it.
Definition: secp256k1.c:665
int secp256k1_ec_seckey_negate(const secp256k1_context *ctx, unsigned char *seckey)
Negates a secret key in place.
Definition: secp256k1.c:592
static SECP256K1_INLINE void secp256k1_int_cmov(int *r, const int *a, int flag)
If flag is true, set *r equal to *a; otherwise leave it.
Definition: util.h:238
static secp256k1_scratch * secp256k1_scratch_create(const secp256k1_callback *error_callback, size_t max_size)
int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32)
Updates the context randomization to protect against side-channel leakage.
Definition: secp256k1.c:731
secp256k1_fe y
Definition: group.h:16
int secp256k1_ec_privkey_tweak_add(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak)
Same as secp256k1_ec_seckey_tweak_add, but DEPRECATED.
Definition: secp256k1.c:654
static void secp256k1_scalar_cmov(secp256k1_scalar *r, const secp256k1_scalar *a, int flag)
If flag is true, set *r equal to *a; otherwise leave it.
static const secp256k1_scalar secp256k1_scalar_one
Definition: scalar_impl.h:31
size_t secp256k1_context_preallocated_size(unsigned int flags)
Determine the memory size of a secp256k1 context object to be created in caller-provided memory...
Definition: secp256k1.c:87
static void secp256k1_ge_to_storage(secp256k1_ge_storage *r, const secp256k1_ge *a)
Convert a group element to the storage type.
static SECP256K1_INLINE void memczero(void *s, size_t len, int flag)
Definition: util.h:205
static SECP256K1_INLINE void * checked_malloc(const secp256k1_callback *cb, size_t size)
Definition: util.h:91
static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, void **prealloc)
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:161
int secp256k1_ecdsa_signature_parse_compact(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *input64)
Parse an ECDSA signature in compact (64 bytes) format.
Definition: secp256k1.c:360
secp256k1_context * secp256k1_context_create(unsigned int flags)
Create a secp256k1 context object (in dynamically allocated memory).
Definition: secp256k1.c:153
static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256 *rng)
int secp256k1_ec_privkey_tweak_mul(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak)
Same as secp256k1_ec_seckey_tweak_mul, but DEPRECATED.
Definition: secp256k1.c:703
static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s)
Opaque data structure that holds a parsed and valid public key.
Definition: secp256k1.h:67
#define SECP256K1_FLAGS_BIT_COMPRESSION
Definition: secp256k1.h:166
static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen)
int secp256k1_ecdsa_signature_normalize(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sigout, const secp256k1_ecdsa_signature *sigin)
Convert a signature to a normalized lower-S form.
Definition: secp256k1.c:406