Bitcoin Core 31.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/* This is a C project. It should not be compiled with a C++ compiler,
8 * and we error out if we detect one.
9 *
10 * We still want to be able to test the project with a C++ compiler
11 * because it is still good to know if this will lead to real trouble, so
12 * there is a possibility to override the check. But be warned that
13 * compiling with a C++ compiler is not supported. */
14#if defined(__cplusplus) && !defined(SECP256K1_CPLUSPLUS_TEST_OVERRIDE)
15#error Trying to compile a C project with a C++ compiler.
16#endif
17
18#define SECP256K1_BUILD
19
20#include "../include/secp256k1.h"
21#include "../include/secp256k1_preallocated.h"
22
23#include "assumptions.h"
24#include "checkmem.h"
25#include "util.h"
26
27#include "field_impl.h"
28#include "scalar_impl.h"
29#include "group_impl.h"
30#include "ecmult_impl.h"
31#include "ecmult_const_impl.h"
32#include "ecmult_gen_impl.h"
33#include "ecdsa_impl.h"
34#include "eckey_impl.h"
35#include "hash_impl.h"
36#include "int128_impl.h"
37#include "scratch_impl.h"
38#include "selftest.h"
39#include "hsort_impl.h"
40
41#ifdef SECP256K1_NO_BUILD
42# error "secp256k1.h processed without SECP256K1_BUILD defined while building secp256k1.c"
43#endif
44
45#define ARG_CHECK(cond) do { \
46 if (EXPECT(!(cond), 0)) { \
47 secp256k1_callback_call(&ctx->illegal_callback, #cond); \
48 return 0; \
49 } \
50} while(0)
51
52#define ARG_CHECK_VOID(cond) do { \
53 if (EXPECT(!(cond), 0)) { \
54 secp256k1_callback_call(&ctx->illegal_callback, #cond); \
55 return; \
56 } \
57} while(0)
58
59/* Note that whenever you change the context struct, you must also change the
60 * context_eq function. */
67};
68
70 { 0 },
74 0
75};
77
78/* Helper function that determines if a context is proper, i.e., is not the static context or a copy thereof.
79 *
80 * This is intended for "context" functions such as secp256k1_context_clone. Functions that need specific
81 * features of a context should still check for these features directly. For example, a function that needs
82 * ecmult_gen should directly check for the existence of the ecmult_gen context. */
85}
86
90 }
91}
92
94 size_t ret = sizeof(secp256k1_context);
95 /* A return value of 0 is reserved as an indicator for errors when we call this function internally. */
96 VERIFY_CHECK(ret != 0);
97
100 "Invalid flags");
101 return 0;
102 }
103
106 "Declassify flag requires running with memory checking");
107 return 0;
108 }
109
110 return ret;
111}
112
114 VERIFY_CHECK(ctx != NULL);
116 return sizeof(secp256k1_context);
117}
118
120 size_t prealloc_size;
122
124
126 if (prealloc_size == 0) {
127 return NULL;
128 }
129 VERIFY_CHECK(prealloc != NULL);
130 ret = (secp256k1_context*)prealloc;
131 ret->illegal_callback = default_illegal_callback;
132 ret->error_callback = default_error_callback;
133 secp256k1_hash_ctx_init(&ret->hash_ctx);
134
135 /* Flags have been checked by secp256k1_context_preallocated_size. */
137 secp256k1_ecmult_gen_context_build(&ret->ecmult_gen_ctx, &ret->hash_ctx);
139
140 return ret;
141}
142
144 size_t const prealloc_size = secp256k1_context_preallocated_size(flags);
146 if (EXPECT(secp256k1_context_preallocated_create(ctx, flags) == NULL, 0)) {
147 free(ctx);
148 return NULL;
149 }
150
151 return ctx;
152}
153
156 VERIFY_CHECK(ctx != NULL);
157 ARG_CHECK(prealloc != NULL);
159
160 ret = (secp256k1_context*)prealloc;
161 *ret = *ctx;
162 return ret;
163}
164
167 size_t prealloc_size;
168
169 VERIFY_CHECK(ctx != NULL);
171
173 ret = checked_malloc(&ctx->error_callback, prealloc_size);
175 return ret;
176}
177
179 ARG_CHECK_VOID(ctx == NULL || secp256k1_context_is_proper(ctx));
180
181 /* Defined as noop */
182 if (ctx == NULL) {
183 return;
184 }
185
187}
188
190 ARG_CHECK_VOID(ctx == NULL || secp256k1_context_is_proper(ctx));
191
192 /* Defined as noop */
193 if (ctx == NULL) {
194 return;
195 }
196
198 free(ctx);
199}
200
201void secp256k1_context_set_illegal_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
202 /* We compare pointers instead of checking secp256k1_context_is_proper() here
203 because setting callbacks is allowed on *copies* of the static context:
204 it's harmless and makes testing easier. */
206 if (fun == NULL) {
208 }
209 ctx->illegal_callback.fn = fun;
211}
212
213void secp256k1_context_set_error_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
214 /* We compare pointers instead of checking secp256k1_context_is_proper() here
215 because setting callbacks is allowed on *copies* of the static context:
216 it's harmless and makes testing easier. */
218 if (fun == NULL) {
220 }
221 ctx->error_callback.fn = fun;
222 ctx->error_callback.data = data;
223}
224
226 VERIFY_CHECK(ctx != NULL);
228 if (!fn_compression) { /* Reset hash context */
230 return;
231 }
232 /* Check and set */
234 ctx->hash_ctx.fn_sha256_compression = fn_compression;
235}
236
238 return &ctx->hash_ctx;
239}
240
242 VERIFY_CHECK(ctx != NULL);
243 return secp256k1_scratch_create(&ctx->error_callback, max_size);
244}
245
247 VERIFY_CHECK(ctx != NULL);
249}
250
251/* Mark memory as no-longer-secret for the purpose of analysing constant-time behaviour
252 * of the software.
253 */
254static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context* ctx, const void *p, size_t len) {
255 if (EXPECT(ctx->declassify, 0)) SECP256K1_CHECKMEM_DEFINE(p, len);
256}
257
258static int secp256k1_pubkey_load(const secp256k1_context* ctx, secp256k1_ge* ge, const secp256k1_pubkey* pubkey) {
259 secp256k1_ge_from_bytes(ge, pubkey->data);
261 return 1;
262}
263
265 secp256k1_ge_to_bytes(pubkey->data, ge);
266}
267
268int secp256k1_ec_pubkey_parse(const secp256k1_context* ctx, secp256k1_pubkey* pubkey, const unsigned char *input, size_t inputlen) {
269 secp256k1_ge Q;
270
271 VERIFY_CHECK(ctx != NULL);
272 ARG_CHECK(pubkey != NULL);
273 memset(pubkey, 0, sizeof(*pubkey));
274 ARG_CHECK(input != NULL);
275 if (!secp256k1_eckey_pubkey_parse(&Q, input, inputlen)) {
276 return 0;
277 }
279 return 0;
280 }
281 secp256k1_pubkey_save(pubkey, &Q);
283 return 1;
284}
285
286int secp256k1_ec_pubkey_serialize(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey* pubkey, unsigned int flags) {
287 secp256k1_ge Q;
288 size_t len;
289
290 VERIFY_CHECK(ctx != NULL);
291 ARG_CHECK(outputlen != NULL);
292 ARG_CHECK(*outputlen >= ((flags & SECP256K1_FLAGS_BIT_COMPRESSION) ? 33u : 65u));
293 len = *outputlen;
294 *outputlen = 0;
295 ARG_CHECK(output != NULL);
296 memset(output, 0, len);
297 ARG_CHECK(pubkey != NULL);
299 if (secp256k1_pubkey_load(ctx, &Q, pubkey)) {
302 *outputlen = 33;
303 } else {
305 *outputlen = 65;
306 }
307 return 1;
308 }
309 return 0;
310}
311
312int secp256k1_ec_pubkey_cmp(const secp256k1_context* ctx, const secp256k1_pubkey* pubkey0, const secp256k1_pubkey* pubkey1) {
313 unsigned char out[2][33];
314 const secp256k1_pubkey* pk[2];
315 int i;
316
317 VERIFY_CHECK(ctx != NULL);
318 pk[0] = pubkey0; pk[1] = pubkey1;
319 for (i = 0; i < 2; i++) {
320 size_t out_size = sizeof(out[i]);
321 /* If the public key is NULL or invalid, ec_pubkey_serialize will call
322 * the illegal_callback and return 0. In that case we will serialize the
323 * key as all zeros which is less than any valid public key. This
324 * results in consistent comparisons even if NULL or invalid pubkeys are
325 * involved and prevents edge cases such as sorting algorithms that use
326 * this function and do not terminate as a result. */
327 if (!secp256k1_ec_pubkey_serialize(ctx, out[i], &out_size, pk[i], SECP256K1_EC_COMPRESSED)) {
328 /* Note that ec_pubkey_serialize should already set the output to
329 * zero in that case, but it's not guaranteed by the API, we can't
330 * test it and writing a VERIFY_CHECK is more complex than
331 * explicitly memsetting (again). */
332 memset(out[i], 0, sizeof(out[i]));
333 }
334 }
335 return secp256k1_memcmp_var(out[0], out[1], sizeof(out[0]));
336}
337
338static int secp256k1_ec_pubkey_sort_cmp(const void* pk1, const void* pk2, void *ctx) {
340 *(secp256k1_pubkey **)pk1,
341 *(secp256k1_pubkey **)pk2);
342}
343
344int secp256k1_ec_pubkey_sort(const secp256k1_context* ctx, const secp256k1_pubkey **pubkeys, size_t n_pubkeys) {
345 size_t i;
346
347 VERIFY_CHECK(ctx != NULL);
348 ARG_CHECK(pubkeys != NULL);
349 for (i = 0; i < n_pubkeys; i++) {
350 ARG_CHECK(pubkeys[i] != NULL);
351 }
352
353 /* Suppress wrong warning (fixed in MSVC 19.33) */
354 #if defined(_MSC_VER) && (_MSC_VER < 1933)
355 #pragma warning(push)
356 #pragma warning(disable: 4090)
357 #endif
358
359 /* Casting away const is fine because neither secp256k1_hsort nor
360 * secp256k1_ec_pubkey_sort_cmp modify the data pointed to by the cmp_data
361 * argument. */
362 secp256k1_hsort(pubkeys, n_pubkeys, sizeof(*pubkeys), secp256k1_ec_pubkey_sort_cmp, (void *)ctx);
363
364 #if defined(_MSC_VER) && (_MSC_VER < 1933)
365 #pragma warning(pop)
366 #endif
367
368 return 1;
369}
370
372 (void)ctx;
373 if (sizeof(secp256k1_scalar) == 32) {
374 /* When the secp256k1_scalar type is exactly 32 byte, use its
375 * representation inside secp256k1_ecdsa_signature, as conversion is very fast.
376 * Note that secp256k1_ecdsa_signature_save must use the same representation. */
377 memcpy(r, &sig->data[0], 32);
378 memcpy(s, &sig->data[32], 32);
379 } else {
380 secp256k1_scalar_set_b32(r, &sig->data[0], NULL);
381 secp256k1_scalar_set_b32(s, &sig->data[32], NULL);
382 }
383}
384
386 if (sizeof(secp256k1_scalar) == 32) {
387 memcpy(&sig->data[0], r, 32);
388 memcpy(&sig->data[32], s, 32);
389 } else {
390 secp256k1_scalar_get_b32(&sig->data[0], r);
391 secp256k1_scalar_get_b32(&sig->data[32], s);
392 }
393}
394
395int secp256k1_ecdsa_signature_parse_der(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
397
398 VERIFY_CHECK(ctx != NULL);
399 ARG_CHECK(sig != NULL);
400 ARG_CHECK(input != NULL);
401
402 if (secp256k1_ecdsa_sig_parse(&r, &s, input, inputlen)) {
404 return 1;
405 } else {
406 memset(sig, 0, sizeof(*sig));
407 return 0;
408 }
409}
410
413 int ret = 1;
414 int overflow = 0;
415
416 VERIFY_CHECK(ctx != NULL);
417 ARG_CHECK(sig != NULL);
418 ARG_CHECK(input64 != NULL);
419
420 secp256k1_scalar_set_b32(&r, &input64[0], &overflow);
421 ret &= !overflow;
422 secp256k1_scalar_set_b32(&s, &input64[32], &overflow);
423 ret &= !overflow;
424 if (ret) {
426 } else {
427 memset(sig, 0, sizeof(*sig));
428 }
429 return ret;
430}
431
432int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature* sig) {
434
435 VERIFY_CHECK(ctx != NULL);
436 ARG_CHECK(output != NULL);
437 ARG_CHECK(outputlen != NULL);
438 ARG_CHECK(sig != NULL);
439
440 secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
441 return secp256k1_ecdsa_sig_serialize(output, outputlen, &r, &s);
442}
443
446
447 VERIFY_CHECK(ctx != NULL);
448 ARG_CHECK(output64 != NULL);
449 ARG_CHECK(sig != NULL);
450
451 secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
452 secp256k1_scalar_get_b32(&output64[0], &r);
453 secp256k1_scalar_get_b32(&output64[32], &s);
454 return 1;
455}
456
459 int ret = 0;
460
461 VERIFY_CHECK(ctx != NULL);
462 ARG_CHECK(sigin != NULL);
463
464 secp256k1_ecdsa_signature_load(ctx, &r, &s, sigin);
466 if (sigout != NULL) {
467 if (ret) {
469 }
470 secp256k1_ecdsa_signature_save(sigout, &r, &s);
471 }
472
473 return ret;
474}
475
476int secp256k1_ecdsa_verify(const secp256k1_context* ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, const secp256k1_pubkey *pubkey) {
477 secp256k1_ge q;
480 VERIFY_CHECK(ctx != NULL);
481 ARG_CHECK(msghash32 != NULL);
482 ARG_CHECK(sig != NULL);
483 ARG_CHECK(pubkey != NULL);
484
485 secp256k1_scalar_set_b32(&m, msghash32, NULL);
486 secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
487 return (!secp256k1_scalar_is_high(&s) &&
488 secp256k1_pubkey_load(ctx, &q, pubkey) &&
489 secp256k1_ecdsa_sig_verify(&r, &s, &q, &m));
490}
491
492static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *offset, const void *data, unsigned int len) {
493 memcpy(buf + *offset, data, len);
494 *offset += len;
495}
496
497static int nonce_function_rfc6979_impl(const secp256k1_hash_ctx *hash_ctx, unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) {
498 unsigned char keydata[112];
499 unsigned int offset = 0;
501 unsigned int i;
503 unsigned char msgmod32[32];
504 secp256k1_scalar_set_b32(&msg, msg32, NULL);
505 secp256k1_scalar_get_b32(msgmod32, &msg);
506 /* We feed a byte array to the PRNG as input, consisting of:
507 * - the private key (32 bytes) and reduced message (32 bytes), see RFC 6979 3.2d.
508 * - optionally 32 extra bytes of data, see RFC 6979 3.6 Additional Data.
509 * - optionally 16 extra bytes with the algorithm name.
510 * Because the arguments have distinct fixed lengths it is not possible for
511 * different argument mixtures to emulate each other and result in the same
512 * nonces.
513 */
514 buffer_append(keydata, &offset, key32, 32);
515 buffer_append(keydata, &offset, msgmod32, 32);
516 if (data != NULL) {
517 buffer_append(keydata, &offset, data, 32);
518 }
519 if (algo16 != NULL) {
520 buffer_append(keydata, &offset, algo16, 16);
521 }
522 secp256k1_rfc6979_hmac_sha256_initialize(hash_ctx, &rng, keydata, offset);
523 for (i = 0; ; i++) {
524 secp256k1_rfc6979_hmac_sha256_generate(hash_ctx, &rng, nonce32, 32);
525 if (i == counter) break;
526 }
528
529 secp256k1_memclear_explicit(keydata, sizeof(keydata));
531 return 1;
532}
533
534static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) {
535 return nonce_function_rfc6979_impl(secp256k1_get_hash_context(secp256k1_context_static), nonce32, msg32, key32, algo16, data, counter);
536}
537
540
541static 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) {
542 secp256k1_scalar sec, non, msg;
543 int ret = 0;
544 int is_sec_valid;
545 unsigned char nonce32[32];
546 unsigned int count = 0;
547 /* Default initialization here is important so we won't pass uninit values to the cmov in the end */
550 if (recid) {
551 *recid = 0;
552 }
553
554 /* Fail if the secret key is invalid. */
555 is_sec_valid = secp256k1_scalar_set_b32_seckey(&sec, seckey);
556 secp256k1_scalar_cmov(&sec, &secp256k1_scalar_one, !is_sec_valid);
557 secp256k1_scalar_set_b32(&msg, msg32, NULL);
558 while (1) {
559 int is_nonce_valid;
560
561 if (noncefp == NULL || noncefp == secp256k1_nonce_function_rfc6979) {
562 /* Use ctx-aware function by default */
563 ret = nonce_function_rfc6979_impl(secp256k1_get_hash_context(ctx), nonce32, msg32, seckey, NULL, (void*)noncedata, count);
564 } else {
565 ret = !!noncefp(nonce32, msg32, seckey, NULL, (void*)noncedata, count);
566 }
567
568 if (!ret) {
569 break;
570 }
571 is_nonce_valid = secp256k1_scalar_set_b32_seckey(&non, nonce32);
572 /* The nonce is still secret here, but it being invalid is less likely than 1:2^255. */
573 secp256k1_declassify(ctx, &is_nonce_valid, sizeof(is_nonce_valid));
574 if (is_nonce_valid) {
575 ret = secp256k1_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, r, s, &sec, &msg, &non, recid);
576 /* The final signature is no longer a secret, nor is the fact that we were successful or not. */
577 secp256k1_declassify(ctx, &ret, sizeof(ret));
578 if (ret) {
579 break;
580 }
581 }
582 count++;
583 }
584 /* We don't want to declassify is_sec_valid and therefore the range of
585 * seckey. As a result is_sec_valid is included in ret only after ret was
586 * used as a branching variable. */
587 ret &= is_sec_valid;
588 secp256k1_memclear_explicit(nonce32, sizeof(nonce32));
594 if (recid) {
595 const int zero = 0;
596 secp256k1_int_cmov(recid, &zero, !ret);
597 }
598 return ret;
599}
600
601int 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) {
603 int ret;
604 VERIFY_CHECK(ctx != NULL);
606 ARG_CHECK(msghash32 != NULL);
607 ARG_CHECK(signature != NULL);
608 ARG_CHECK(seckey != NULL);
609
610 ret = secp256k1_ecdsa_sign_inner(ctx, &r, &s, NULL, msghash32, seckey, noncefp, noncedata);
611 secp256k1_ecdsa_signature_save(signature, &r, &s);
612 return ret;
613}
614
615int secp256k1_ec_seckey_verify(const secp256k1_context* ctx, const unsigned char *seckey) {
617 int ret;
618 VERIFY_CHECK(ctx != NULL);
619 ARG_CHECK(seckey != NULL);
620
621 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
623 return ret;
624}
625
626static 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) {
627 int ret;
628
629 ret = secp256k1_scalar_set_b32_seckey(seckey_scalar, seckey);
631
632 secp256k1_ecmult_gen_ge(ecmult_gen_ctx, p, seckey_scalar);
633 return ret;
634}
635
636int secp256k1_ec_pubkey_create(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) {
637 secp256k1_ge p;
638 secp256k1_scalar seckey_scalar;
639 int ret = 0;
640 VERIFY_CHECK(ctx != NULL);
641 ARG_CHECK(pubkey != NULL);
642 memset(pubkey, 0, sizeof(*pubkey));
644 ARG_CHECK(seckey != NULL);
645
646 ret = secp256k1_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &seckey_scalar, &p, seckey);
647 secp256k1_pubkey_save(pubkey, &p);
648 secp256k1_memczero(pubkey, sizeof(*pubkey), !ret);
649
650 secp256k1_scalar_clear(&seckey_scalar);
651 return ret;
652}
653
654int secp256k1_ec_seckey_negate(const secp256k1_context* ctx, unsigned char *seckey) {
656 int ret = 0;
657 VERIFY_CHECK(ctx != NULL);
658 ARG_CHECK(seckey != NULL);
659
660 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
662 secp256k1_scalar_negate(&sec, &sec);
663 secp256k1_scalar_get_b32(seckey, &sec);
664
666 return ret;
667}
668
670 int ret = 0;
671 secp256k1_ge p;
672 VERIFY_CHECK(ctx != NULL);
673 ARG_CHECK(pubkey != NULL);
674
675 ret = secp256k1_pubkey_load(ctx, &p, pubkey);
676 memset(pubkey, 0, sizeof(*pubkey));
677 if (ret) {
678 secp256k1_ge_neg(&p, &p);
679 secp256k1_pubkey_save(pubkey, &p);
680 }
681 return ret;
682}
683
684
685static int secp256k1_ec_seckey_tweak_add_helper(secp256k1_scalar *sec, const unsigned char *tweak32) {
686 secp256k1_scalar term;
687 int overflow = 0;
688 int ret = 0;
689
690 secp256k1_scalar_set_b32(&term, tweak32, &overflow);
691 ret = (!overflow) & secp256k1_eckey_privkey_tweak_add(sec, &term);
693 return ret;
694}
695
696int secp256k1_ec_seckey_tweak_add(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {
698 int ret = 0;
699 VERIFY_CHECK(ctx != NULL);
700 ARG_CHECK(seckey != NULL);
701 ARG_CHECK(tweak32 != NULL);
702
703 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
706 secp256k1_scalar_get_b32(seckey, &sec);
707
709 return ret;
710}
711
712static int secp256k1_ec_pubkey_tweak_add_helper(secp256k1_ge *p, const unsigned char *tweak32) {
713 secp256k1_scalar term;
714 int overflow = 0;
715 secp256k1_scalar_set_b32(&term, tweak32, &overflow);
716 return !overflow && secp256k1_eckey_pubkey_tweak_add(p, &term);
717}
718
719int secp256k1_ec_pubkey_tweak_add(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) {
720 secp256k1_ge p;
721 int ret = 0;
722 VERIFY_CHECK(ctx != NULL);
723 ARG_CHECK(pubkey != NULL);
724 ARG_CHECK(tweak32 != NULL);
725
726 ret = secp256k1_pubkey_load(ctx, &p, pubkey);
727 memset(pubkey, 0, sizeof(*pubkey));
729 if (ret) {
730 secp256k1_pubkey_save(pubkey, &p);
731 }
732
733 return ret;
734}
735
736int secp256k1_ec_seckey_tweak_mul(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {
737 secp256k1_scalar factor;
739 int ret = 0;
740 int overflow = 0;
741 VERIFY_CHECK(ctx != NULL);
742 ARG_CHECK(seckey != NULL);
743 ARG_CHECK(tweak32 != NULL);
744
745 secp256k1_scalar_set_b32(&factor, tweak32, &overflow);
746 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
747 ret &= (!overflow) & secp256k1_eckey_privkey_tweak_mul(&sec, &factor);
749 secp256k1_scalar_get_b32(seckey, &sec);
750
752 secp256k1_scalar_clear(&factor);
753 return ret;
754}
755
756int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) {
757 secp256k1_ge p;
758 secp256k1_scalar factor;
759 int ret = 0;
760 int overflow = 0;
761 VERIFY_CHECK(ctx != NULL);
762 ARG_CHECK(pubkey != NULL);
763 ARG_CHECK(tweak32 != NULL);
764
765 secp256k1_scalar_set_b32(&factor, tweak32, &overflow);
766 ret = !overflow && secp256k1_pubkey_load(ctx, &p, pubkey);
767 memset(pubkey, 0, sizeof(*pubkey));
768 if (ret) {
769 if (secp256k1_eckey_pubkey_tweak_mul(&p, &factor)) {
770 secp256k1_pubkey_save(pubkey, &p);
771 } else {
772 ret = 0;
773 }
774 }
775
776 return ret;
777}
778
779int secp256k1_context_randomize(secp256k1_context* ctx, const unsigned char *seed32) {
780 VERIFY_CHECK(ctx != NULL);
782
785 }
786 return 1;
787}
788
789int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey *pubnonce, const secp256k1_pubkey * const *pubnonces, size_t n) {
790 size_t i;
791 secp256k1_gej Qj;
792 secp256k1_ge Q;
793
794 VERIFY_CHECK(ctx != NULL);
795 ARG_CHECK(pubnonce != NULL);
796 memset(pubnonce, 0, sizeof(*pubnonce));
797 ARG_CHECK(n >= 1);
798 ARG_CHECK(pubnonces != NULL);
799
801
802 for (i = 0; i < n; i++) {
803 ARG_CHECK(pubnonces[i] != NULL);
804 secp256k1_pubkey_load(ctx, &Q, pubnonces[i]);
805 secp256k1_gej_add_ge(&Qj, &Qj, &Q);
806 }
807 if (secp256k1_gej_is_infinity(&Qj)) {
808 return 0;
809 }
810 secp256k1_ge_set_gej(&Q, &Qj);
811 secp256k1_pubkey_save(pubnonce, &Q);
812 return 1;
813}
814
815int secp256k1_tagged_sha256(const secp256k1_context* ctx, unsigned char *hash32, const unsigned char *tag, size_t taglen, const unsigned char *msg, size_t msglen) {
817 VERIFY_CHECK(ctx != NULL);
818 ARG_CHECK(hash32 != NULL);
819 ARG_CHECK(tag != NULL);
820 ARG_CHECK(msg != NULL);
821
826 return 1;
827}
828
829#ifdef ENABLE_MODULE_ECDH
830# include "modules/ecdh/main_impl.h"
831#endif
832
833#ifdef ENABLE_MODULE_RECOVERY
835#endif
836
837#ifdef ENABLE_MODULE_EXTRAKEYS
839#endif
840
841#ifdef ENABLE_MODULE_SCHNORRSIG
843#endif
844
845#ifdef ENABLE_MODULE_MUSIG
847#endif
848
849#ifdef ENABLE_MODULE_ELLSWIFT
851#endif
852
853#ifdef ENABLE_MODULE_SILENTPAYMENTS
855#endif
int ret
int flags
Definition: bitcoin-tx.cpp:530
#define SECP256K1_CHECKMEM_DEFINE(p, len)
Definition: checkmem.h:106
#define SECP256K1_CHECKMEM_RUNNING()
Definition: checkmem.h:108
static const PrecomputedData data
Precomputed COutPoint and CCoins values.
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_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size)
static int secp256k1_ecdsa_sig_verify(const secp256k1_scalar *r, const secp256k1_scalar *s, const secp256k1_ge *pubkey, const secp256k1_scalar *message)
static void secp256k1_eckey_pubkey_serialize65(secp256k1_ge *elem, unsigned char *pub65)
Serialize a group element (that is not allowed to be infinity) to an uncompressed public key (65 byte...
static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak)
static int secp256k1_eckey_pubkey_tweak_mul(secp256k1_ge *key, const secp256k1_scalar *tweak)
static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak)
static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak)
static void secp256k1_eckey_pubkey_serialize33(secp256k1_ge *elem, unsigned char *pub33)
Serialize a group element (that is not allowed to be infinity) to a compressed public key (33 bytes).
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size)
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ctx)
static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const secp256k1_hash_ctx *hash_ctx, const unsigned char *seed32)
static void secp256k1_ecmult_gen_ge(const secp256k1_ecmult_gen_context *ctx, secp256k1_ge *r, const secp256k1_scalar *a)
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context *ctx, const secp256k1_hash_ctx *hash_ctx)
static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context *ctx)
#define secp256k1_fe_is_zero
Definition: field.h:84
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_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_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 void secp256k1_ge_to_bytes(unsigned char *buf, const secp256k1_ge *a)
Convert a group element that is not infinity to a 64-byte array.
static void secp256k1_ge_from_bytes(secp256k1_ge *r, const unsigned char *buf)
Convert a 64-byte array into group element.
static void secp256k1_sha256_transform(uint32_t *state, const unsigned char *blocks64, size_t n_blocks)
Definition: hash_impl.h:133
static void secp256k1_sha256_initialize_tagged(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *hash, const unsigned char *tag, size_t taglen)
Definition: hash_impl.h:261
static void secp256k1_hsort(void *ptr, size_t count, size_t size, int(*cmp)(const void *, const void *, void *), void *cmp_data)
struct secp256k1_context_struct secp256k1_context
Definition: key.h:19
#define EXPECT(x, c)
Definition: util.h:26
static void secp256k1_scalar_cmov(secp256k1_scalar *r, const secp256k1_scalar *a, int flag)
If flag is 1, set *r equal to *a; if flag is 0, 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:28
static const secp256k1_scalar secp256k1_scalar_one
Definition: scalar_impl.h:27
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_sha256_finalize(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *hash, unsigned char *out32)
static void secp256k1_hash_ctx_init(secp256k1_hash_ctx *hash_ctx)
static void secp256k1_rfc6979_hmac_sha256_clear(secp256k1_rfc6979_hmac_sha256 *rng)
static void secp256k1_rfc6979_hmac_sha256_generate(const secp256k1_hash_ctx *hash_ctx, secp256k1_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen)
static void secp256k1_rfc6979_hmac_sha256_initialize(const secp256k1_hash_ctx *hash_ctx, 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(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *hash, const unsigned char *data, size_t size)
static void secp256k1_sha256_clear(secp256k1_sha256 *hash)
static SECP256K1_INLINE void secp256k1_memclear_explicit(void *ptr, size_t len)
Definition: util.h:268
static SECP256K1_INLINE int secp256k1_memcmp_var(const void *s1, const void *s2, size_t n)
Semantics like memcmp.
Definition: util.h:281
static SECP256K1_INLINE void secp256k1_int_cmov(int *r, const int *a, int flag)
If flag is 1, set *r equal to *a; if flag is 0, leave it.
Definition: util.h:312
static void secp256k1_default_error_callback_fn(const char *str, void *data)
Definition: util.h:112
static const secp256k1_callback default_error_callback
Definition: util.h:127
#define SECP256K1_INLINE
Definition: util.h:53
static void secp256k1_default_illegal_callback_fn(const char *str, void *data)
Definition: util.h:107
#define VERIFY_CHECK(cond)
Definition: util.h:169
static SECP256K1_INLINE void * checked_malloc(const secp256k1_callback *cb, size_t size)
Definition: util.h:172
static SECP256K1_INLINE void secp256k1_memczero(void *s, size_t len, int flag)
Definition: util.h:220
static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback *const cb, const char *const text)
Definition: util.h:102
static const secp256k1_callback default_illegal_callback
Definition: util.h:122
void secp256k1_context_set_sha256_compression(secp256k1_context *ctx, secp256k1_sha256_compression_function fn_compression)
Set a callback function to override the internal SHA256 compression function.
Definition: secp256k1.c:225
const secp256k1_nonce_function secp256k1_nonce_function_default
Definition: secp256k1.c:539
secp256k1_context * secp256k1_context_preallocated_clone(const secp256k1_context *ctx, void *prealloc)
Copy a secp256k1 context object into caller-provided memory.
Definition: secp256k1.c:154
const secp256k1_nonce_function secp256k1_nonce_function_rfc6979
Definition: secp256k1.c:538
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:815
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:719
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:286
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:432
static int secp256k1_ec_seckey_tweak_add_helper(secp256k1_scalar *sec, const unsigned char *tweak32)
Definition: secp256k1.c:685
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:736
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:268
static void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space *scratch)
Definition: secp256k1.c:246
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:113
int secp256k1_ec_seckey_verify(const secp256k1_context *ctx, const unsigned char *seckey)
Verify an elliptic curve secret key.
Definition: secp256k1.c:615
static int secp256k1_context_is_proper(const secp256k1_context *ctx)
Definition: secp256k1.c:83
int secp256k1_ec_pubkey_sort(const secp256k1_context *ctx, const secp256k1_pubkey **pubkeys, size_t n_pubkeys)
Sort public keys using lexicographic (of compressed serialization) order.
Definition: secp256k1.c:344
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:696
void secp256k1_context_preallocated_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object that has been created in caller-provided memory.
Definition: secp256k1.c:178
static int nonce_function_rfc6979_impl(const secp256k1_hash_ctx *hash_ctx, unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter)
Definition: secp256k1.c:497
#define ARG_CHECK(cond)
Definition: secp256k1.c:45
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:626
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:457
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
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:395
static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context *ctx, const void *p, size_t len)
Definition: secp256k1.c:254
secp256k1_context * secp256k1_context_create(unsigned int flags)
Create a secp256k1 context object (in dynamically allocated memory).
Definition: secp256k1.c:143
int secp256k1_ec_seckey_negate(const secp256k1_context *ctx, unsigned char *seckey)
Negates a secret key in place.
Definition: secp256k1.c:654
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:312
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:789
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:411
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:201
static void secp256k1_ecdsa_signature_save(secp256k1_ecdsa_signature *sig, const secp256k1_scalar *r, const secp256k1_scalar *s)
Definition: secp256k1.c:385
static secp256k1_scratch_space * secp256k1_scratch_space_create(const secp256k1_context *ctx, size_t max_size)
Definition: secp256k1.c:241
static int secp256k1_pubkey_load(const secp256k1_context *ctx, secp256k1_ge *ge, const secp256k1_pubkey *pubkey)
Definition: secp256k1.c:258
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:93
static void secp256k1_pubkey_save(secp256k1_pubkey *pubkey, secp256k1_ge *ge)
Definition: secp256k1.c:264
static SECP256K1_INLINE const secp256k1_hash_ctx * secp256k1_get_hash_context(const secp256k1_context *ctx)
Definition: secp256k1.c:237
static int secp256k1_ec_pubkey_sort_cmp(const void *pk1, const void *pk2, void *ctx)
Definition: secp256k1.c:338
static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *offset, const void *data, unsigned int len)
Definition: secp256k1.c:492
static int secp256k1_ec_pubkey_tweak_add_helper(secp256k1_ge *p, const unsigned char *tweak32)
Definition: secp256k1.c:712
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:534
int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32)
Randomizes the context to provide enhanced protection against side-channel leakage.
Definition: secp256k1.c:779
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:476
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:444
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:636
void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object (created in dynamically allocated memory).
Definition: secp256k1.c:189
void secp256k1_selftest(void)
Perform basic self tests (to be used in conjunction with secp256k1_context_static)
Definition: secp256k1.c:87
secp256k1_context * secp256k1_context_clone(const secp256k1_context *ctx)
Copy a secp256k1 context object (into dynamically allocated memory).
Definition: secp256k1.c:165
static const secp256k1_context secp256k1_context_static_
Definition: secp256k1.c:69
const secp256k1_context *const secp256k1_context_static
Definition: secp256k1.c:76
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:756
static void secp256k1_ecdsa_signature_load(const secp256k1_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, const secp256k1_ecdsa_signature *sig)
Definition: secp256k1.c:371
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_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:601
int secp256k1_ec_pubkey_negate(const secp256k1_context *ctx, secp256k1_pubkey *pubkey)
Negates a public key in place.
Definition: secp256k1.c:669
#define ARG_CHECK_VOID(cond)
Definition: secp256k1.c:52
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:541
#define SECP256K1_FLAGS_BIT_CONTEXT_DECLASSIFY
Definition: secp256k1.h:201
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:95
#define SECP256K1_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize.
Definition: secp256k1.h:216
void(* secp256k1_sha256_compression_function)(uint32_t *state, const unsigned char *blocks64, size_t n_blocks)
A pointer to a function implementing SHA256's internal compression function.
Definition: secp256k1.h:407
#define SECP256K1_FLAGS_TYPE_MASK
Definition: secp256k1.h:195
#define SECP256K1_FLAGS_BIT_COMPRESSION
Definition: secp256k1.h:202
#define SECP256K1_FLAGS_TYPE_CONTEXT
Definition: secp256k1.h:196
#define SECP256K1_FLAGS_TYPE_COMPRESSION
Definition: secp256k1.h:197
static int secp256k1_selftest_sha256(secp256k1_sha256_compression_function fn_compression)
Definition: selftest.h:14
static int secp256k1_selftest_passes(void)
Definition: selftest.h:36
void(* fn)(const char *text, void *data)
Definition: util.h:98
const void * data
Definition: util.h:99
secp256k1_callback illegal_callback
Definition: secp256k1.c:64
secp256k1_callback error_callback
Definition: secp256k1.c:65
secp256k1_ecmult_gen_context ecmult_gen_ctx
Definition: secp256k1.c:62
secp256k1_hash_ctx hash_ctx
Definition: secp256k1.c:63
Opaque data structure that holds a parsed ECDSA signature.
Definition: secp256k1.h:75
unsigned char data[64]
Definition: secp256k1.h:76
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
Definition: group.h:16
secp256k1_fe x
Definition: group.h:17
A group element of the secp256k1 curve, in jacobian coordinates.
Definition: group.h:28
secp256k1_sha256_compression_function fn_sha256_compression
Definition: hash.h:16
Opaque data structure that holds a parsed and valid public key.
Definition: secp256k1.h:62
unsigned char data[64]
Definition: secp256k1.h:63
A scalar modulo the group order of the secp256k1 curve.
Definition: scalar_4x64.h:13
FastRandomContext rng
Definition: dbwrapper.cpp:413
static int count