Bitcoin Core 22.99.0
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 https://www.opensource.org/licenses/mit-license.php.*
5 ***********************************************************************/
6
7#define SECP256K1_BUILD
8
9#include "../include/secp256k1.h"
10#include "../include/secp256k1_preallocated.h"
11
12#include "assumptions.h"
13#include "util.h"
14#include "field_impl.h"
15#include "scalar_impl.h"
16#include "group_impl.h"
17#include "ecmult_impl.h"
18#include "ecmult_const_impl.h"
19#include "ecmult_gen_impl.h"
20#include "ecdsa_impl.h"
21#include "eckey_impl.h"
22#include "hash_impl.h"
23#include "scratch_impl.h"
24#include "selftest.h"
25
26#ifdef SECP256K1_NO_BUILD
27# error "secp256k1.h processed without SECP256K1_BUILD defined while building secp256k1.c"
28#endif
29
30#if defined(VALGRIND)
31# include <valgrind/memcheck.h>
32#endif
33
34#define ARG_CHECK(cond) do { \
35 if (EXPECT(!(cond), 0)) { \
36 secp256k1_callback_call(&ctx->illegal_callback, #cond); \
37 return 0; \
38 } \
39} while(0)
40
41#define ARG_CHECK_NO_RETURN(cond) do { \
42 if (EXPECT(!(cond), 0)) { \
43 secp256k1_callback_call(&ctx->illegal_callback, #cond); \
44 } \
45} while(0)
46
47#ifndef USE_EXTERNAL_DEFAULT_CALLBACKS
48#include <stdlib.h>
49#include <stdio.h>
50static void secp256k1_default_illegal_callback_fn(const char* str, void* data) {
51 (void)data;
52 fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str);
53 abort();
54}
55static void secp256k1_default_error_callback_fn(const char* str, void* data) {
56 (void)data;
57 fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
58 abort();
59}
60#else
61void secp256k1_default_illegal_callback_fn(const char* str, void* data);
62void secp256k1_default_error_callback_fn(const char* str, void* data);
63#endif
64
67 NULL
68};
69
72 NULL
73};
74
81};
82
84 { 0 },
85 { 0 },
88 0
89};
91
93 size_t ret = ROUND_TO_ALIGN(sizeof(secp256k1_context));
94 /* A return value of 0 is reserved as an indicator for errors when we call this function internally. */
95 VERIFY_CHECK(ret != 0);
96
99 "Invalid flags");
100 return 0;
101 }
102
105 }
108 }
109 return ret;
110}
111
113 size_t ret = ROUND_TO_ALIGN(sizeof(secp256k1_context));
114 VERIFY_CHECK(ctx != NULL);
117 }
120 }
121 return ret;
122}
123
125 void* const base = prealloc;
126 size_t prealloc_size;
128
129 if (!secp256k1_selftest()) {
131 }
132
134 if (prealloc_size == 0) {
135 return NULL;
136 }
137 VERIFY_CHECK(prealloc != NULL);
138 ret = (secp256k1_context*)manual_alloc(&prealloc, sizeof(secp256k1_context), base, prealloc_size);
141
144
145 /* Flags have been checked by secp256k1_context_preallocated_size. */
149 }
152 }
154
155 return (secp256k1_context*) ret;
156}
157
159 size_t const prealloc_size = secp256k1_context_preallocated_size(flags);
162 free(ctx);
163 return NULL;
164 }
165
166 return ctx;
167}
168
170 size_t prealloc_size;
172 VERIFY_CHECK(ctx != NULL);
173 ARG_CHECK(prealloc != NULL);
174
176 ret = (secp256k1_context*)prealloc;
177 memcpy(ret, ctx, prealloc_size);
180 return ret;
181}
182
185 size_t prealloc_size;
186
187 VERIFY_CHECK(ctx != NULL);
189 ret = (secp256k1_context*)checked_malloc(&ctx->error_callback, prealloc_size);
191 return ret;
192}
193
196 if (ctx != NULL) {
199 }
200}
201
203 if (ctx != NULL) {
205 free(ctx);
206 }
207}
208
209void secp256k1_context_set_illegal_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
211 if (fun == NULL) {
213 }
214 ctx->illegal_callback.fn = fun;
215 ctx->illegal_callback.data = data;
216}
217
218void secp256k1_context_set_error_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
220 if (fun == NULL) {
222 }
223 ctx->error_callback.fn = fun;
224 ctx->error_callback.data = data;
225}
226
228 VERIFY_CHECK(ctx != NULL);
229 return secp256k1_scratch_create(&ctx->error_callback, max_size);
230}
231
233 VERIFY_CHECK(ctx != NULL);
235}
236
237/* Mark memory as no-longer-secret for the purpose of analysing constant-time behaviour
238 * of the software. This is setup for use with valgrind but could be substituted with
239 * the appropriate instrumentation for other analysis tools.
240 */
241static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context* ctx, const void *p, size_t len) {
242#if defined(VALGRIND)
243 if (EXPECT(ctx->declassify,0)) VALGRIND_MAKE_MEM_DEFINED(p, len);
244#else
245 (void)ctx;
246 (void)p;
247 (void)len;
248#endif
249}
250
252 if (sizeof(secp256k1_ge_storage) == 64) {
253 /* When the secp256k1_ge_storage type is exactly 64 byte, use its
254 * representation inside secp256k1_pubkey, as conversion is very fast.
255 * Note that secp256k1_pubkey_save must use the same representation. */
257 memcpy(&s, &pubkey->data[0], sizeof(s));
259 } else {
260 /* Otherwise, fall back to 32-byte big endian for X and Y. */
261 secp256k1_fe x, y;
262 secp256k1_fe_set_b32(&x, pubkey->data);
263 secp256k1_fe_set_b32(&y, pubkey->data + 32);
264 secp256k1_ge_set_xy(ge, &x, &y);
265 }
267 return 1;
268}
269
271 if (sizeof(secp256k1_ge_storage) == 64) {
274 memcpy(&pubkey->data[0], &s, sizeof(s));
275 } else {
279 secp256k1_fe_get_b32(pubkey->data, &ge->x);
280 secp256k1_fe_get_b32(pubkey->data + 32, &ge->y);
281 }
282}
283
284int secp256k1_ec_pubkey_parse(const secp256k1_context* ctx, secp256k1_pubkey* pubkey, const unsigned char *input, size_t inputlen) {
285 secp256k1_ge Q;
286
287 VERIFY_CHECK(ctx != NULL);
288 ARG_CHECK(pubkey != NULL);
289 memset(pubkey, 0, sizeof(*pubkey));
290 ARG_CHECK(input != NULL);
291 if (!secp256k1_eckey_pubkey_parse(&Q, input, inputlen)) {
292 return 0;
293 }
295 return 0;
296 }
297 secp256k1_pubkey_save(pubkey, &Q);
299 return 1;
300}
301
302int secp256k1_ec_pubkey_serialize(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey* pubkey, unsigned int flags) {
303 secp256k1_ge Q;
304 size_t len;
305 int ret = 0;
306
307 VERIFY_CHECK(ctx != NULL);
308 ARG_CHECK(outputlen != NULL);
309 ARG_CHECK(*outputlen >= ((flags & SECP256K1_FLAGS_BIT_COMPRESSION) ? 33u : 65u));
310 len = *outputlen;
311 *outputlen = 0;
312 ARG_CHECK(output != NULL);
313 memset(output, 0, len);
314 ARG_CHECK(pubkey != NULL);
316 if (secp256k1_pubkey_load(ctx, &Q, pubkey)) {
318 if (ret) {
319 *outputlen = len;
320 }
321 }
322 return ret;
323}
324
326 unsigned char out[2][33];
327 const secp256k1_pubkey* pk[2];
328 int i;
329
330 VERIFY_CHECK(ctx != NULL);
331 pk[0] = pubkey0; pk[1] = pubkey1;
332 for (i = 0; i < 2; i++) {
333 size_t out_size = sizeof(out[i]);
334 /* If the public key is NULL or invalid, ec_pubkey_serialize will call
335 * the illegal_callback and return 0. In that case we will serialize the
336 * key as all zeros which is less than any valid public key. This
337 * results in consistent comparisons even if NULL or invalid pubkeys are
338 * involved and prevents edge cases such as sorting algorithms that use
339 * this function and do not terminate as a result. */
340 if (!secp256k1_ec_pubkey_serialize(ctx, out[i], &out_size, pk[i], SECP256K1_EC_COMPRESSED)) {
341 /* Note that ec_pubkey_serialize should already set the output to
342 * zero in that case, but it's not guaranteed by the API, we can't
343 * test it and writing a VERIFY_CHECK is more complex than
344 * explicitly memsetting (again). */
345 memset(out[i], 0, sizeof(out[i]));
346 }
347 }
348 return secp256k1_memcmp_var(out[0], out[1], sizeof(out[0]));
349}
350
352 (void)ctx;
353 if (sizeof(secp256k1_scalar) == 32) {
354 /* When the secp256k1_scalar type is exactly 32 byte, use its
355 * representation inside secp256k1_ecdsa_signature, as conversion is very fast.
356 * Note that secp256k1_ecdsa_signature_save must use the same representation. */
357 memcpy(r, &sig->data[0], 32);
358 memcpy(s, &sig->data[32], 32);
359 } else {
360 secp256k1_scalar_set_b32(r, &sig->data[0], NULL);
361 secp256k1_scalar_set_b32(s, &sig->data[32], NULL);
362 }
363}
364
366 if (sizeof(secp256k1_scalar) == 32) {
367 memcpy(&sig->data[0], r, 32);
368 memcpy(&sig->data[32], s, 32);
369 } else {
370 secp256k1_scalar_get_b32(&sig->data[0], r);
371 secp256k1_scalar_get_b32(&sig->data[32], s);
372 }
373}
374
375int secp256k1_ecdsa_signature_parse_der(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
376 secp256k1_scalar r, s;
377
378 VERIFY_CHECK(ctx != NULL);
379 ARG_CHECK(sig != NULL);
380 ARG_CHECK(input != NULL);
381
382 if (secp256k1_ecdsa_sig_parse(&r, &s, input, inputlen)) {
384 return 1;
385 } else {
386 memset(sig, 0, sizeof(*sig));
387 return 0;
388 }
389}
390
392 secp256k1_scalar r, s;
393 int ret = 1;
394 int overflow = 0;
395
396 VERIFY_CHECK(ctx != NULL);
397 ARG_CHECK(sig != NULL);
398 ARG_CHECK(input64 != NULL);
399
400 secp256k1_scalar_set_b32(&r, &input64[0], &overflow);
401 ret &= !overflow;
402 secp256k1_scalar_set_b32(&s, &input64[32], &overflow);
403 ret &= !overflow;
404 if (ret) {
406 } else {
407 memset(sig, 0, sizeof(*sig));
408 }
409 return ret;
410}
411
412int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature* sig) {
413 secp256k1_scalar r, s;
414
415 VERIFY_CHECK(ctx != NULL);
416 ARG_CHECK(output != NULL);
417 ARG_CHECK(outputlen != NULL);
418 ARG_CHECK(sig != NULL);
419
421 return secp256k1_ecdsa_sig_serialize(output, outputlen, &r, &s);
422}
423
425 secp256k1_scalar r, s;
426
427 VERIFY_CHECK(ctx != NULL);
428 ARG_CHECK(output64 != NULL);
429 ARG_CHECK(sig != NULL);
430
432 secp256k1_scalar_get_b32(&output64[0], &r);
433 secp256k1_scalar_get_b32(&output64[32], &s);
434 return 1;
435}
436
438 secp256k1_scalar r, s;
439 int ret = 0;
440
441 VERIFY_CHECK(ctx != NULL);
442 ARG_CHECK(sigin != NULL);
443
444 secp256k1_ecdsa_signature_load(ctx, &r, &s, sigin);
445 ret = secp256k1_scalar_is_high(&s);
446 if (sigout != NULL) {
447 if (ret) {
449 }
450 secp256k1_ecdsa_signature_save(sigout, &r, &s);
451 }
452
453 return ret;
454}
455
456int secp256k1_ecdsa_verify(const secp256k1_context* ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, const secp256k1_pubkey *pubkey) {
457 secp256k1_ge q;
458 secp256k1_scalar r, s;
460 VERIFY_CHECK(ctx != NULL);
462 ARG_CHECK(msghash32 != NULL);
463 ARG_CHECK(sig != NULL);
464 ARG_CHECK(pubkey != NULL);
465
466 secp256k1_scalar_set_b32(&m, msghash32, NULL);
468 return (!secp256k1_scalar_is_high(&s) &&
469 secp256k1_pubkey_load(ctx, &q, pubkey) &&
470 secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &r, &s, &q, &m));
471}
472
473static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *offset, const void *data, unsigned int len) {
474 memcpy(buf + *offset, data, len);
475 *offset += len;
476}
477
478static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) {
479 unsigned char keydata[112];
480 unsigned int offset = 0;
482 unsigned int i;
483 /* We feed a byte array to the PRNG as input, consisting of:
484 * - the private key (32 bytes) and message (32 bytes), see RFC 6979 3.2d.
485 * - optionally 32 extra bytes of data, see RFC 6979 3.6 Additional Data.
486 * - optionally 16 extra bytes with the algorithm name.
487 * Because the arguments have distinct fixed lengths it is not possible for
488 * different argument mixtures to emulate each other and result in the same
489 * nonces.
490 */
491 buffer_append(keydata, &offset, key32, 32);
492 buffer_append(keydata, &offset, msg32, 32);
493 if (data != NULL) {
494 buffer_append(keydata, &offset, data, 32);
495 }
496 if (algo16 != NULL) {
497 buffer_append(keydata, &offset, algo16, 16);
498 }
499 secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, offset);
500 memset(keydata, 0, sizeof(keydata));
501 for (i = 0; i <= counter; i++) {
503 }
505 return 1;
506}
507
510
511static 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 void* noncedata) {
512 secp256k1_scalar sec, non, msg;
513 int ret = 0;
514 int is_sec_valid;
515 unsigned char nonce32[32];
516 unsigned int count = 0;
517 /* Default initialization here is important so we won't pass uninit values to the cmov in the end */
520 if (recid) {
521 *recid = 0;
522 }
523 if (noncefp == NULL) {
525 }
526
527 /* Fail if the secret key is invalid. */
528 is_sec_valid = secp256k1_scalar_set_b32_seckey(&sec, seckey);
529 secp256k1_scalar_cmov(&sec, &secp256k1_scalar_one, !is_sec_valid);
530 secp256k1_scalar_set_b32(&msg, msg32, NULL);
531 while (1) {
532 int is_nonce_valid;
533 ret = !!noncefp(nonce32, msg32, seckey, NULL, (void*)noncedata, count);
534 if (!ret) {
535 break;
536 }
537 is_nonce_valid = secp256k1_scalar_set_b32_seckey(&non, nonce32);
538 /* The nonce is still secret here, but it being invalid is is less likely than 1:2^255. */
539 secp256k1_declassify(ctx, &is_nonce_valid, sizeof(is_nonce_valid));
540 if (is_nonce_valid) {
541 ret = secp256k1_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, r, s, &sec, &msg, &non, recid);
542 /* The final signature is no longer a secret, nor is the fact that we were successful or not. */
543 secp256k1_declassify(ctx, &ret, sizeof(ret));
544 if (ret) {
545 break;
546 }
547 }
548 count++;
549 }
550 /* We don't want to declassify is_sec_valid and therefore the range of
551 * seckey. As a result is_sec_valid is included in ret only after ret was
552 * used as a branching variable. */
553 ret &= is_sec_valid;
554 memset(nonce32, 0, 32);
560 if (recid) {
561 const int zero = 0;
562 secp256k1_int_cmov(recid, &zero, !ret);
563 }
564 return ret;
565}
566
567int secp256k1_ecdsa_sign(const secp256k1_context* ctx, secp256k1_ecdsa_signature *signature, const unsigned char *msghash32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void* noncedata) {
568 secp256k1_scalar r, s;
569 int ret;
570 VERIFY_CHECK(ctx != NULL);
572 ARG_CHECK(msghash32 != NULL);
573 ARG_CHECK(signature != NULL);
574 ARG_CHECK(seckey != NULL);
575
576 ret = secp256k1_ecdsa_sign_inner(ctx, &r, &s, NULL, msghash32, seckey, noncefp, noncedata);
577 secp256k1_ecdsa_signature_save(signature, &r, &s);
578 return ret;
579}
580
581int secp256k1_ec_seckey_verify(const secp256k1_context* ctx, const unsigned char *seckey) {
583 int ret;
584 VERIFY_CHECK(ctx != NULL);
585 ARG_CHECK(seckey != NULL);
586
587 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
589 return ret;
590}
591
592static 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) {
593 secp256k1_gej pj;
594 int ret;
595
596 ret = secp256k1_scalar_set_b32_seckey(seckey_scalar, seckey);
597 secp256k1_scalar_cmov(seckey_scalar, &secp256k1_scalar_one, !ret);
598
599 secp256k1_ecmult_gen(ecmult_gen_ctx, &pj, seckey_scalar);
600 secp256k1_ge_set_gej(p, &pj);
601 return ret;
602}
603
604int secp256k1_ec_pubkey_create(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) {
605 secp256k1_ge p;
606 secp256k1_scalar seckey_scalar;
607 int ret = 0;
608 VERIFY_CHECK(ctx != NULL);
609 ARG_CHECK(pubkey != NULL);
610 memset(pubkey, 0, sizeof(*pubkey));
612 ARG_CHECK(seckey != NULL);
613
614 ret = secp256k1_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &seckey_scalar, &p, seckey);
615 secp256k1_pubkey_save(pubkey, &p);
616 secp256k1_memczero(pubkey, sizeof(*pubkey), !ret);
617
618 secp256k1_scalar_clear(&seckey_scalar);
619 return ret;
620}
621
622int secp256k1_ec_seckey_negate(const secp256k1_context* ctx, unsigned char *seckey) {
624 int ret = 0;
625 VERIFY_CHECK(ctx != NULL);
626 ARG_CHECK(seckey != NULL);
627
628 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
630 secp256k1_scalar_negate(&sec, &sec);
631 secp256k1_scalar_get_b32(seckey, &sec);
632
634 return ret;
635}
636
637int secp256k1_ec_privkey_negate(const secp256k1_context* ctx, unsigned char *seckey) {
638 return secp256k1_ec_seckey_negate(ctx, seckey);
639}
640
642 int ret = 0;
643 secp256k1_ge p;
644 VERIFY_CHECK(ctx != NULL);
645 ARG_CHECK(pubkey != NULL);
646
647 ret = secp256k1_pubkey_load(ctx, &p, pubkey);
648 memset(pubkey, 0, sizeof(*pubkey));
649 if (ret) {
650 secp256k1_ge_neg(&p, &p);
651 secp256k1_pubkey_save(pubkey, &p);
652 }
653 return ret;
654}
655
656
657static int secp256k1_ec_seckey_tweak_add_helper(secp256k1_scalar *sec, const unsigned char *tweak32) {
658 secp256k1_scalar term;
659 int overflow = 0;
660 int ret = 0;
661
662 secp256k1_scalar_set_b32(&term, tweak32, &overflow);
663 ret = (!overflow) & secp256k1_eckey_privkey_tweak_add(sec, &term);
665 return ret;
666}
667
668int secp256k1_ec_seckey_tweak_add(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {
670 int ret = 0;
671 VERIFY_CHECK(ctx != NULL);
672 ARG_CHECK(seckey != NULL);
673 ARG_CHECK(tweak32 != NULL);
674
675 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
676 ret &= secp256k1_ec_seckey_tweak_add_helper(&sec, tweak32);
678 secp256k1_scalar_get_b32(seckey, &sec);
679
681 return ret;
682}
683
684int secp256k1_ec_privkey_tweak_add(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {
685 return secp256k1_ec_seckey_tweak_add(ctx, seckey, tweak32);
686}
687
688static int secp256k1_ec_pubkey_tweak_add_helper(const secp256k1_ecmult_context* ecmult_ctx, secp256k1_ge *p, const unsigned char *tweak32) {
689 secp256k1_scalar term;
690 int overflow = 0;
691 secp256k1_scalar_set_b32(&term, tweak32, &overflow);
692 return !overflow && secp256k1_eckey_pubkey_tweak_add(ecmult_ctx, p, &term);
693}
694
695int secp256k1_ec_pubkey_tweak_add(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) {
696 secp256k1_ge p;
697 int ret = 0;
698 VERIFY_CHECK(ctx != NULL);
700 ARG_CHECK(pubkey != NULL);
701 ARG_CHECK(tweak32 != NULL);
702
703 ret = secp256k1_pubkey_load(ctx, &p, pubkey);
704 memset(pubkey, 0, sizeof(*pubkey));
705 ret = ret && secp256k1_ec_pubkey_tweak_add_helper(&ctx->ecmult_ctx, &p, tweak32);
706 if (ret) {
707 secp256k1_pubkey_save(pubkey, &p);
708 }
709
710 return ret;
711}
712
713int secp256k1_ec_seckey_tweak_mul(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {
714 secp256k1_scalar factor;
716 int ret = 0;
717 int overflow = 0;
718 VERIFY_CHECK(ctx != NULL);
719 ARG_CHECK(seckey != NULL);
720 ARG_CHECK(tweak32 != NULL);
721
722 secp256k1_scalar_set_b32(&factor, tweak32, &overflow);
723 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
724 ret &= (!overflow) & secp256k1_eckey_privkey_tweak_mul(&sec, &factor);
726 secp256k1_scalar_get_b32(seckey, &sec);
727
729 secp256k1_scalar_clear(&factor);
730 return ret;
731}
732
733int secp256k1_ec_privkey_tweak_mul(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {
734 return secp256k1_ec_seckey_tweak_mul(ctx, seckey, tweak32);
735}
736
737int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) {
738 secp256k1_ge p;
739 secp256k1_scalar factor;
740 int ret = 0;
741 int overflow = 0;
742 VERIFY_CHECK(ctx != NULL);
744 ARG_CHECK(pubkey != NULL);
745 ARG_CHECK(tweak32 != NULL);
746
747 secp256k1_scalar_set_b32(&factor, tweak32, &overflow);
748 ret = !overflow && secp256k1_pubkey_load(ctx, &p, pubkey);
749 memset(pubkey, 0, sizeof(*pubkey));
750 if (ret) {
751 if (secp256k1_eckey_pubkey_tweak_mul(&ctx->ecmult_ctx, &p, &factor)) {
752 secp256k1_pubkey_save(pubkey, &p);
753 } else {
754 ret = 0;
755 }
756 }
757
758 return ret;
759}
760
761int secp256k1_context_randomize(secp256k1_context* ctx, const unsigned char *seed32) {
762 VERIFY_CHECK(ctx != NULL);
765 }
766 return 1;
767}
768
769int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey *pubnonce, const secp256k1_pubkey * const *pubnonces, size_t n) {
770 size_t i;
771 secp256k1_gej Qj;
772 secp256k1_ge Q;
773
774 ARG_CHECK(pubnonce != NULL);
775 memset(pubnonce, 0, sizeof(*pubnonce));
776 ARG_CHECK(n >= 1);
777 ARG_CHECK(pubnonces != NULL);
778
780
781 for (i = 0; i < n; i++) {
782 secp256k1_pubkey_load(ctx, &Q, pubnonces[i]);
783 secp256k1_gej_add_ge(&Qj, &Qj, &Q);
784 }
785 if (secp256k1_gej_is_infinity(&Qj)) {
786 return 0;
787 }
788 secp256k1_ge_set_gej(&Q, &Qj);
789 secp256k1_pubkey_save(pubnonce, &Q);
790 return 1;
791}
792
793int secp256k1_tagged_sha256(const secp256k1_context* ctx, unsigned char *hash32, const unsigned char *tag, size_t taglen, const unsigned char *msg, size_t msglen) {
795 VERIFY_CHECK(ctx != NULL);
796 ARG_CHECK(hash32 != NULL);
797 ARG_CHECK(tag != NULL);
798 ARG_CHECK(msg != NULL);
799
800 secp256k1_sha256_initialize_tagged(&sha, tag, taglen);
801 secp256k1_sha256_write(&sha, msg, msglen);
802 secp256k1_sha256_finalize(&sha, hash32);
803 return 1;
804}
805
806#ifdef ENABLE_MODULE_ECDH
807# include "modules/ecdh/main_impl.h"
808#endif
809
810#ifdef ENABLE_MODULE_RECOVERY
812#endif
813
814#ifdef ENABLE_MODULE_EXTRAKEYS
816#endif
817
818#ifdef ENABLE_MODULE_SCHNORRSIG
820#endif
int flags
Definition: bitcoin-tx.cpp:525
static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s)
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_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 int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size)
static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak)
static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak)
static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak)
static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak)
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size)
static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed)
static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx)
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx)
static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx)
static void secp256k1_ecmult_context_finalize_memcpy(secp256k1_ecmult_context *dst, const secp256k1_ecmult_context *src)
static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, void **prealloc)
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ctx)
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_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const unsigned char *seed32)
static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context *ctx)
static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context *ctx)
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context *ctx, void **prealloc)
static void secp256k1_ecmult_gen_context_finalize_memcpy(secp256k1_ecmult_gen_context *dst, const secp256k1_ecmult_gen_context *src)
static const size_t SECP256K1_ECMULT_GEN_CONTEXT_PREALLOCATED_SIZE
static const size_t SECP256K1_ECMULT_CONTEXT_PREALLOCATED_SIZE
Definition: ecmult_impl.h:302
static void secp256k1_fe_normalize_var(secp256k1_fe *r)
Normalize a field element, without constant-time guarantee.
static int secp256k1_fe_set_b32(secp256k1_fe *r, const unsigned char *a)
Set a field element equal to 32-byte big endian value.
static int secp256k1_fe_is_zero(const secp256k1_fe *a)
Verify whether a field element is zero.
static void secp256k1_fe_get_b32(unsigned char *r, const secp256k1_fe *a)
Convert a field element to a 32-byte big endian value.
static void secp256k1_gej_set_infinity(secp256k1_gej *r)
Set a group element (jacobian) equal to the point at infinity.
static int secp256k1_gej_is_infinity(const secp256k1_gej *a)
Check whether a group element is the point at infinity.
static void secp256k1_ge_clear(secp256k1_ge *r)
Clear a secp256k1_ge to prevent leaking sensitive information.
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 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 void secp256k1_ge_from_storage(secp256k1_ge *r, const secp256k1_ge_storage *a)
Convert a group element back from the storage type.
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 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.
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)
static int secp256k1_ge_is_infinity(const secp256k1_ge *a)
Check whether a group element is the point at infinity.
static void secp256k1_ge_to_storage(secp256k1_ge_storage *r, const secp256k1_ge *a)
Convert a group element to the storage type.
static void secp256k1_sha256_initialize_tagged(secp256k1_sha256 *hash, const unsigned char *tag, size_t taglen)
Definition: hash_impl.h:169
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 void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *bin, int *overflow)
Set a scalar from a big endian byte array.
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.
static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar *a)
Convert a scalar to a byte array.
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_scalar_is_high(const secp256k1_scalar *a)
Check whether a scalar is higher than the group order divided by 2.
static void secp256k1_scalar_clear(secp256k1_scalar *r)
Clear a scalar to prevent the leak of sensitive data.
static const secp256k1_scalar secp256k1_scalar_zero
Definition: scalar_impl.h:32
static const secp256k1_scalar secp256k1_scalar_one
Definition: scalar_impl.h:31
static void secp256k1_scratch_destroy(const secp256k1_callback *error_callback, secp256k1_scratch *scratch)
static secp256k1_scratch * secp256k1_scratch_create(const secp256k1_callback *error_callback, size_t max_size)
static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen)
static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out32)
static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256 *rng, const unsigned char *key, size_t keylen)
static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256 *rng)
static void secp256k1_sha256_write(secp256k1_sha256 *hash, const unsigned char *data, size_t size)
static SECP256K1_INLINE int secp256k1_memcmp_var(const void *s1, const void *s2, size_t n)
Semantics like memcmp.
Definition: util.h:224
static SECP256K1_INLINE void * manual_alloc(void **prealloc_ptr, size_t alloc_size, void *base, size_t max_size)
Definition: util.h:134
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
#define EXPECT(x, c)
Definition: util.h:43
#define ROUND_TO_ALIGN(size)
Definition: util.h:116
#define VERIFY_CHECK(cond)
Definition: util.h:68
static SECP256K1_INLINE void * checked_malloc(const secp256k1_callback *cb, size_t size)
Definition: util.h:91
static SECP256K1_INLINE void secp256k1_memczero(void *s, size_t len, int flag)
Definition: util.h:205
static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback *const cb, const char *const text)
Definition: util.h:24
int secp256k1_ec_privkey_tweak_add(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak32)
Same as secp256k1_ec_seckey_tweak_add, but DEPRECATED.
Definition: secp256k1.c:684
int secp256k1_ec_privkey_negate(const secp256k1_context *ctx, unsigned char *seckey)
Same as secp256k1_ec_seckey_negate, but DEPRECATED.
Definition: secp256k1.c:637
const secp256k1_nonce_function secp256k1_nonce_function_default
A default safe nonce generation function (currently equal to secp256k1_nonce_function_rfc6979).
Definition: secp256k1.c:509
secp256k1_context * secp256k1_context_preallocated_clone(const secp256k1_context *ctx, void *prealloc)
Copy a secp256k1 context object into caller-provided memory.
Definition: secp256k1.c:169
const secp256k1_nonce_function secp256k1_nonce_function_rfc6979
An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function.
Definition: secp256k1.c:508
int secp256k1_tagged_sha256(const secp256k1_context *ctx, unsigned char *hash32, const unsigned char *tag, size_t taglen, const unsigned char *msg, size_t msglen)
Compute a tagged hash as defined in BIP-340.
Definition: secp256k1.c:793
int secp256k1_ec_pubkey_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32)
Tweak a public key by adding tweak times the generator to it.
Definition: secp256k1.c:695
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:302
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:412
static int secp256k1_ec_seckey_tweak_add_helper(secp256k1_scalar *sec, const unsigned char *tweak32)
Definition: secp256k1.c:657
int secp256k1_ec_seckey_tweak_mul(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak32)
Tweak a secret key by multiplying it by a tweak.
Definition: secp256k1.c:713
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:284
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:112
static void secp256k1_default_error_callback_fn(const char *str, void *data)
Definition: secp256k1.c:55
int secp256k1_ec_seckey_verify(const secp256k1_context *ctx, const unsigned char *seckey)
Verify an ECDSA secret key.
Definition: secp256k1.c:581
const secp256k1_context * secp256k1_context_no_precomp
A simple secp256k1 context object with no precomputed tables.
Definition: secp256k1.c:90
int secp256k1_ec_seckey_tweak_add(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak32)
Tweak a secret key by adding tweak to it.
Definition: secp256k1.c:668
void secp256k1_context_preallocated_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object that has been created in caller-provided memory.
Definition: secp256k1.c:194
#define ARG_CHECK(cond)
Definition: secp256k1.c:34
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:592
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:437
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:218
static const secp256k1_callback default_error_callback
Definition: secp256k1.c:70
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:375
static int secp256k1_ec_pubkey_tweak_add_helper(const secp256k1_ecmult_context *ecmult_ctx, secp256k1_ge *p, const unsigned char *tweak32)
Definition: secp256k1.c:688
static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context *ctx, const void *p, size_t len)
Definition: secp256k1.c:241
secp256k1_context * secp256k1_context_create(unsigned int flags)
Create a secp256k1 context object (in dynamically allocated memory).
Definition: secp256k1.c:158
int secp256k1_ec_seckey_negate(const secp256k1_context *ctx, unsigned char *seckey)
Negates a secret key in place.
Definition: secp256k1.c:622
int secp256k1_ec_pubkey_cmp(const secp256k1_context *ctx, const secp256k1_pubkey *pubkey0, const secp256k1_pubkey *pubkey1)
Compare two public keys using lexicographic (of compressed serialization) order.
Definition: secp256k1.c:325
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:769
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:391
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:209
static void secp256k1_ecdsa_signature_save(secp256k1_ecdsa_signature *sig, const secp256k1_scalar *r, const secp256k1_scalar *s)
Definition: secp256k1.c:365
static int secp256k1_pubkey_load(const secp256k1_context *ctx, secp256k1_ge *ge, const secp256k1_pubkey *pubkey)
Definition: secp256k1.c:251
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:92
static void secp256k1_pubkey_save(secp256k1_pubkey *pubkey, secp256k1_ge *ge)
Definition: secp256k1.c:270
static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *offset, const void *data, unsigned int len)
Definition: secp256k1.c:473
static void secp256k1_default_illegal_callback_fn(const char *str, void *data)
Definition: secp256k1.c:50
#define ARG_CHECK_NO_RETURN(cond)
Definition: secp256k1.c:41
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:478
static const secp256k1_context secp256k1_context_no_precomp_
Definition: secp256k1.c:83
int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32)
Updates the context randomization to protect against side-channel leakage.
Definition: secp256k1.c:761
secp256k1_scratch_space * secp256k1_scratch_space_create(const secp256k1_context *ctx, size_t max_size)
Create a secp256k1 scratch space object.
Definition: secp256k1.c:227
int secp256k1_ecdsa_verify(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, const secp256k1_pubkey *pubkey)
Verify an ECDSA signature.
Definition: secp256k1.c:456
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:424
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:604
void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object (created in dynamically allocated memory).
Definition: secp256k1.c:202
secp256k1_context * secp256k1_context_clone(const secp256k1_context *ctx)
Copy a secp256k1 context object (into dynamically allocated memory).
Definition: secp256k1.c:183
void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space *scratch)
Destroy a secp256k1 scratch space.
Definition: secp256k1.c:232
int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32)
Tweak a public key by multiplying it by a tweak value.
Definition: secp256k1.c:737
static void secp256k1_ecdsa_signature_load(const secp256k1_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, const secp256k1_ecdsa_signature *sig)
Definition: secp256k1.c:351
secp256k1_context * secp256k1_context_preallocated_create(void *prealloc, unsigned int flags)
Create a secp256k1 context object in caller-provided memory.
Definition: secp256k1.c:124
int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *signature, const unsigned char *msghash32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *noncedata)
Create an ECDSA signature.
Definition: secp256k1.c:567
static const secp256k1_callback default_illegal_callback
Definition: secp256k1.c:65
int secp256k1_ec_pubkey_negate(const secp256k1_context *ctx, secp256k1_pubkey *pubkey)
Negates a public key in place.
Definition: secp256k1.c:641
int secp256k1_ec_privkey_tweak_mul(const secp256k1_context *ctx, unsigned char *seckey, const unsigned char *tweak32)
Same as secp256k1_ec_seckey_tweak_mul, but DEPRECATED.
Definition: secp256k1.c:733
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 void *noncedata)
Definition: secp256k1.c:511
#define SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY
Definition: secp256k1.h:179
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:103
#define SECP256K1_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize.
Definition: secp256k1.h:190
#define SECP256K1_INLINE
Definition: secp256k1.h:127
#define SECP256K1_FLAGS_BIT_CONTEXT_VERIFY
The higher bits contain the actual data.
Definition: secp256k1.h:177
#define SECP256K1_FLAGS_TYPE_MASK
All flags' lower 8 bits indicate what they're for.
Definition: secp256k1.h:173
#define SECP256K1_FLAGS_BIT_CONTEXT_SIGN
Definition: secp256k1.h:178
#define SECP256K1_FLAGS_BIT_COMPRESSION
Definition: secp256k1.h:180
#define SECP256K1_FLAGS_TYPE_CONTEXT
Definition: secp256k1.h:174
#define SECP256K1_FLAGS_TYPE_COMPRESSION
Definition: secp256k1.h:175
static int secp256k1_selftest(void)
Definition: selftest.h:28
void(* fn)(const char *text, void *data)
Definition: util.h:20
const void * data
Definition: util.h:21
secp256k1_callback illegal_callback
Definition: secp256k1.c:78
secp256k1_callback error_callback
Definition: secp256k1.c:79
secp256k1_ecmult_gen_context ecmult_gen_ctx
Definition: secp256k1.c:77
secp256k1_ecmult_context ecmult_ctx
Definition: secp256k1.c:76
Opaque data structured that holds a parsed ECDSA signature.
Definition: secp256k1.h:83
unsigned char data[64]
Definition: secp256k1.h:84
A group element of the secp256k1 curve, in affine coordinates.
Definition: group.h:13
secp256k1_fe x
Definition: group.h:14
secp256k1_fe y
Definition: group.h:15
A group element of the secp256k1 curve, in jacobian coordinates.
Definition: group.h:23
Opaque data structure that holds a parsed and valid public key.
Definition: secp256k1.h:70
unsigned char data[64]
Definition: secp256k1.h:71
A scalar modulo the group order of the secp256k1 curve.
Definition: scalar_4x64.h:13
static secp256k1_context * ctx
Definition: tests.c:42
static int count
Definition: tests.c:41