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 VERIFY_CHECK(ctx != NULL);
239 return secp256k1_scratch_create(&ctx->error_callback, max_size);
240}
241
243 VERIFY_CHECK(ctx != NULL);
245}
246
247/* Mark memory as no-longer-secret for the purpose of analysing constant-time behaviour
248 * of the software.
249 */
250static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context* ctx, const void *p, size_t len) {
251 if (EXPECT(ctx->declassify, 0)) SECP256K1_CHECKMEM_DEFINE(p, len);
252}
253
254static int secp256k1_pubkey_load(const secp256k1_context* ctx, secp256k1_ge* ge, const secp256k1_pubkey* pubkey) {
255 secp256k1_ge_from_bytes(ge, pubkey->data);
257 return 1;
258}
259
261 secp256k1_ge_to_bytes(pubkey->data, ge);
262}
263
264int secp256k1_ec_pubkey_parse(const secp256k1_context* ctx, secp256k1_pubkey* pubkey, const unsigned char *input, size_t inputlen) {
265 secp256k1_ge Q;
266
267 VERIFY_CHECK(ctx != NULL);
268 ARG_CHECK(pubkey != NULL);
269 memset(pubkey, 0, sizeof(*pubkey));
270 ARG_CHECK(input != NULL);
271 if (!secp256k1_ge_parse(&Q, input, inputlen)) {
272 return 0;
273 }
275 return 0;
276 }
277 secp256k1_pubkey_save(pubkey, &Q);
279 return 1;
280}
281
282int secp256k1_ec_pubkey_serialize(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey* pubkey, unsigned int flags) {
283 secp256k1_ge Q;
284 size_t len;
285
286 VERIFY_CHECK(ctx != NULL);
287 ARG_CHECK(outputlen != NULL);
288 ARG_CHECK(*outputlen >= ((flags & SECP256K1_FLAGS_BIT_COMPRESSION) ? 33u : 65u));
289 len = *outputlen;
290 *outputlen = 0;
291 ARG_CHECK(output != NULL);
292 memset(output, 0, len);
293 ARG_CHECK(pubkey != NULL);
295 if (secp256k1_pubkey_load(ctx, &Q, pubkey)) {
297 secp256k1_ge_serialize33(&Q, output);
298 *outputlen = 33;
299 } else {
300 secp256k1_ge_serialize65(&Q, output);
301 *outputlen = 65;
302 }
303 return 1;
304 }
305 return 0;
306}
307
308int secp256k1_ec_pubkey_cmp(const secp256k1_context* ctx, const secp256k1_pubkey* pubkey0, const secp256k1_pubkey* pubkey1) {
309 unsigned char out[2][33];
310 const secp256k1_pubkey* pk[2];
311 int i;
312
313 VERIFY_CHECK(ctx != NULL);
314 pk[0] = pubkey0; pk[1] = pubkey1;
315 for (i = 0; i < 2; i++) {
316 size_t out_size = sizeof(out[i]);
317 /* If the public key is NULL or invalid, ec_pubkey_serialize will call
318 * the illegal_callback and return 0. In that case we will serialize the
319 * key as all zeros which is less than any valid public key. This
320 * results in consistent comparisons even if NULL or invalid pubkeys are
321 * involved and prevents edge cases such as sorting algorithms that use
322 * this function and do not terminate as a result. */
323 if (!secp256k1_ec_pubkey_serialize(ctx, out[i], &out_size, pk[i], SECP256K1_EC_COMPRESSED)) {
324 /* Note that ec_pubkey_serialize should already set the output to
325 * zero in that case, but it's not guaranteed by the API, we can't
326 * test it and writing a VERIFY_CHECK is more complex than
327 * explicitly memsetting (again). */
328 memset(out[i], 0, sizeof(out[i]));
329 }
330 }
331 return secp256k1_memcmp_var(out[0], out[1], sizeof(out[0]));
332}
333
334static int secp256k1_ec_pubkey_sort_cmp(const void* pk1, const void* pk2, void *ctx) {
336 *(secp256k1_pubkey **)pk1,
337 *(secp256k1_pubkey **)pk2);
338}
339
340int secp256k1_ec_pubkey_sort(const secp256k1_context* ctx, const secp256k1_pubkey **pubkeys, size_t n_pubkeys) {
341 size_t i;
342
343 VERIFY_CHECK(ctx != NULL);
344 ARG_CHECK(pubkeys != NULL);
345 for (i = 0; i < n_pubkeys; i++) {
346 ARG_CHECK(pubkeys[i] != NULL);
347 }
348
349 /* Suppress wrong warning (fixed in MSVC 19.33) */
350 #if defined(_MSC_VER) && (_MSC_VER < 1933)
351 #pragma warning(push)
352 #pragma warning(disable: 4090)
353 #endif
354
355 /* Casting away const is fine because neither secp256k1_hsort nor
356 * secp256k1_ec_pubkey_sort_cmp modify the data pointed to by the cmp_data
357 * argument. */
358 secp256k1_hsort(pubkeys, n_pubkeys, sizeof(*pubkeys), secp256k1_ec_pubkey_sort_cmp, (void *)ctx);
359
360 #if defined(_MSC_VER) && (_MSC_VER < 1933)
361 #pragma warning(pop)
362 #endif
363
364 return 1;
365}
366
368 (void)ctx;
369 if (sizeof(secp256k1_scalar) == 32) {
370 /* When the secp256k1_scalar type is exactly 32 byte, use its
371 * representation inside secp256k1_ecdsa_signature, as conversion is very fast.
372 * Note that secp256k1_ecdsa_signature_save must use the same representation. */
373 memcpy(r, &sig->data[0], 32);
374 memcpy(s, &sig->data[32], 32);
375 } else {
376 secp256k1_scalar_set_b32(r, &sig->data[0], NULL);
377 secp256k1_scalar_set_b32(s, &sig->data[32], NULL);
378 }
379}
380
382 if (sizeof(secp256k1_scalar) == 32) {
383 memcpy(&sig->data[0], r, 32);
384 memcpy(&sig->data[32], s, 32);
385 } else {
386 secp256k1_scalar_get_b32(&sig->data[0], r);
387 secp256k1_scalar_get_b32(&sig->data[32], s);
388 }
389}
390
391int secp256k1_ecdsa_signature_parse_der(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
393
394 VERIFY_CHECK(ctx != NULL);
395 ARG_CHECK(sig != NULL);
396 ARG_CHECK(input != NULL);
397
398 if (secp256k1_ecdsa_sig_parse(&r, &s, input, inputlen)) {
400 return 1;
401 } else {
402 memset(sig, 0, sizeof(*sig));
403 return 0;
404 }
405}
406
409 int ret = 1;
410 int overflow = 0;
411
412 VERIFY_CHECK(ctx != NULL);
413 ARG_CHECK(sig != NULL);
414 ARG_CHECK(input64 != NULL);
415
416 secp256k1_scalar_set_b32(&r, &input64[0], &overflow);
417 ret &= !overflow;
418 secp256k1_scalar_set_b32(&s, &input64[32], &overflow);
419 ret &= !overflow;
420 if (ret) {
422 } else {
423 memset(sig, 0, sizeof(*sig));
424 }
425 return ret;
426}
427
428int secp256k1_ecdsa_signature_serialize_der(const secp256k1_context* ctx, unsigned char *output, size_t *outputlen, const secp256k1_ecdsa_signature* sig) {
430
431 VERIFY_CHECK(ctx != NULL);
432 ARG_CHECK(output != NULL);
433 ARG_CHECK(outputlen != NULL);
434 ARG_CHECK(sig != NULL);
435
436 secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
437 return secp256k1_ecdsa_sig_serialize(output, outputlen, &r, &s);
438}
439
442
443 VERIFY_CHECK(ctx != NULL);
444 ARG_CHECK(output64 != NULL);
445 ARG_CHECK(sig != NULL);
446
447 secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
448 secp256k1_scalar_get_b32(&output64[0], &r);
449 secp256k1_scalar_get_b32(&output64[32], &s);
450 return 1;
451}
452
455 int ret = 0;
456
457 VERIFY_CHECK(ctx != NULL);
458 ARG_CHECK(sigin != NULL);
459
460 secp256k1_ecdsa_signature_load(ctx, &r, &s, sigin);
462 if (sigout != NULL) {
463 if (ret) {
465 }
466 secp256k1_ecdsa_signature_save(sigout, &r, &s);
467 }
468
469 return ret;
470}
471
472int secp256k1_ecdsa_verify(const secp256k1_context* ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, const secp256k1_pubkey *pubkey) {
473 secp256k1_ge q;
476 VERIFY_CHECK(ctx != NULL);
477 ARG_CHECK(msghash32 != NULL);
478 ARG_CHECK(sig != NULL);
479 ARG_CHECK(pubkey != NULL);
480
481 secp256k1_scalar_set_b32(&m, msghash32, NULL);
482 secp256k1_ecdsa_signature_load(ctx, &r, &s, sig);
483 return (!secp256k1_scalar_is_high(&s) &&
484 secp256k1_pubkey_load(ctx, &q, pubkey) &&
485 secp256k1_ecdsa_sig_verify(&r, &s, &q, &m));
486}
487
488static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *offset, const void *data, unsigned int len) {
489 memcpy(buf + *offset, data, len);
490 *offset += len;
491}
492
493static 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) {
494 unsigned char keydata[112];
495 unsigned int offset = 0;
497 unsigned int i;
499 unsigned char msgmod32[32];
500 secp256k1_scalar_set_b32(&msg, msg32, NULL);
501 secp256k1_scalar_get_b32(msgmod32, &msg);
502 /* We feed a byte array to the PRNG as input, consisting of:
503 * - the private key (32 bytes) and reduced message (32 bytes), see RFC 6979 3.2d.
504 * - optionally 32 extra bytes of data, see RFC 6979 3.6 Additional Data.
505 * - optionally 16 extra bytes with the algorithm name.
506 * Because the arguments have distinct fixed lengths it is not possible for
507 * different argument mixtures to emulate each other and result in the same
508 * nonces.
509 */
510 buffer_append(keydata, &offset, key32, 32);
511 buffer_append(keydata, &offset, msgmod32, 32);
512 if (data != NULL) {
513 buffer_append(keydata, &offset, data, 32);
514 }
515 if (algo16 != NULL) {
516 buffer_append(keydata, &offset, algo16, 16);
517 }
518 secp256k1_rfc6979_hmac_sha256_initialize(hash_ctx, &rng, keydata, offset);
519 for (i = 0; ; i++) {
520 secp256k1_rfc6979_hmac_sha256_generate(hash_ctx, &rng, nonce32, 32);
521 if (i == counter) break;
522 }
524
525 secp256k1_memclear_explicit(keydata, sizeof(keydata));
527 return 1;
528}
529
530static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) {
531 return nonce_function_rfc6979_impl(&secp256k1_context_static->hash_ctx, nonce32, msg32, key32, algo16, data, counter);
532}
533
536
537static 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) {
538 secp256k1_scalar sec, non, msg;
539 int ret = 0;
540 int is_sec_valid;
541 unsigned char nonce32[32];
542 unsigned int count = 0;
543 /* Default initialization here is important so we won't pass uninit values to the cmov in the end */
546 if (recid) {
547 *recid = 0;
548 }
549
550 /* Fail if the secret key is invalid. */
551 is_sec_valid = secp256k1_scalar_set_b32_seckey(&sec, seckey);
552 secp256k1_scalar_cmov(&sec, &secp256k1_scalar_one, !is_sec_valid);
553 secp256k1_scalar_set_b32(&msg, msg32, NULL);
554 while (1) {
555 int is_nonce_valid;
556
557 if (noncefp == NULL || noncefp == secp256k1_nonce_function_rfc6979) {
558 /* Use ctx-aware function by default */
559 ret = nonce_function_rfc6979_impl(&ctx->hash_ctx, nonce32, msg32, seckey, NULL, (void*)noncedata, count);
560 } else {
561 ret = !!noncefp(nonce32, msg32, seckey, NULL, (void*)noncedata, count);
562 }
563
564 if (!ret) {
565 break;
566 }
567 is_nonce_valid = secp256k1_scalar_set_b32_seckey(&non, nonce32);
568 /* The nonce is still secret here, but it being invalid is less likely than 1:2^255. */
569 secp256k1_declassify(ctx, &is_nonce_valid, sizeof(is_nonce_valid));
570 if (is_nonce_valid) {
571 ret = secp256k1_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, r, s, &sec, &msg, &non, recid);
572 /* The final signature is no longer a secret, nor is the fact that we were successful or not. */
573 secp256k1_declassify(ctx, &ret, sizeof(ret));
574 if (ret) {
575 break;
576 }
577 }
578 count++;
579 }
580 /* We don't want to declassify is_sec_valid and therefore the range of
581 * seckey. As a result is_sec_valid is included in ret only after ret was
582 * used as a branching variable. */
583 ret &= is_sec_valid;
584 secp256k1_memclear_explicit(nonce32, sizeof(nonce32));
590 if (recid) {
591 const int zero = 0;
592 secp256k1_int_cmov(recid, &zero, !ret);
593 }
594 return ret;
595}
596
597int 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) {
599 int ret;
600 VERIFY_CHECK(ctx != NULL);
602 ARG_CHECK(msghash32 != NULL);
603 ARG_CHECK(signature != NULL);
604 ARG_CHECK(seckey != NULL);
605
606 ret = secp256k1_ecdsa_sign_inner(ctx, &r, &s, NULL, msghash32, seckey, noncefp, noncedata);
607 secp256k1_ecdsa_signature_save(signature, &r, &s);
608 return ret;
609}
610
611int secp256k1_ec_seckey_verify(const secp256k1_context* ctx, const unsigned char *seckey) {
613 int ret;
614 VERIFY_CHECK(ctx != NULL);
615 ARG_CHECK(seckey != NULL);
616
617 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
619 return ret;
620}
621
622static 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) {
623 int ret;
624
625 ret = secp256k1_scalar_set_b32_seckey(seckey_scalar, seckey);
627
628 secp256k1_ecmult_gen_ge(ecmult_gen_ctx, p, seckey_scalar);
629 return ret;
630}
631
632int secp256k1_ec_pubkey_create(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) {
633 secp256k1_ge p;
634 secp256k1_scalar seckey_scalar;
635 int ret = 0;
636 VERIFY_CHECK(ctx != NULL);
637 ARG_CHECK(pubkey != NULL);
638 memset(pubkey, 0, sizeof(*pubkey));
640 ARG_CHECK(seckey != NULL);
641
642 ret = secp256k1_ec_pubkey_create_helper(&ctx->ecmult_gen_ctx, &seckey_scalar, &p, seckey);
643 secp256k1_pubkey_save(pubkey, &p);
644 secp256k1_memczero(pubkey, sizeof(*pubkey), !ret);
645
646 secp256k1_scalar_clear(&seckey_scalar);
647 return ret;
648}
649
650int secp256k1_ec_seckey_negate(const secp256k1_context* ctx, unsigned char *seckey) {
652 int ret = 0;
653 VERIFY_CHECK(ctx != NULL);
654 ARG_CHECK(seckey != NULL);
655
656 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
658 secp256k1_scalar_negate(&sec, &sec);
659 secp256k1_scalar_get_b32(seckey, &sec);
660
662 return ret;
663}
664
666 int ret = 0;
667 secp256k1_ge p;
668 VERIFY_CHECK(ctx != NULL);
669 ARG_CHECK(pubkey != NULL);
670
671 ret = secp256k1_pubkey_load(ctx, &p, pubkey);
672 memset(pubkey, 0, sizeof(*pubkey));
673 if (ret) {
674 secp256k1_ge_neg(&p, &p);
675 secp256k1_pubkey_save(pubkey, &p);
676 }
677 return ret;
678}
679
680
681static int secp256k1_ec_seckey_tweak_add_helper(secp256k1_scalar *sec, const unsigned char *tweak32) {
682 secp256k1_scalar term;
683 int overflow = 0;
684 int ret = 0;
685
686 secp256k1_scalar_set_b32(&term, tweak32, &overflow);
687 ret = (!overflow) & secp256k1_eckey_seckey_tweak_add(sec, &term);
689 return ret;
690}
691
692int secp256k1_ec_seckey_tweak_add(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {
694 int ret = 0;
695 VERIFY_CHECK(ctx != NULL);
696 ARG_CHECK(seckey != NULL);
697 ARG_CHECK(tweak32 != NULL);
698
699 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
702 secp256k1_scalar_get_b32(seckey, &sec);
703
705 return ret;
706}
707
708static int secp256k1_ec_pubkey_tweak_add_helper(secp256k1_ge *p, const unsigned char *tweak32) {
709 secp256k1_scalar term;
710 int overflow = 0;
711 secp256k1_scalar_set_b32(&term, tweak32, &overflow);
712 return !overflow && secp256k1_eckey_pubkey_tweak_add(p, &term);
713}
714
715int secp256k1_ec_pubkey_tweak_add(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) {
716 secp256k1_ge p;
717 int ret = 0;
718 VERIFY_CHECK(ctx != NULL);
719 ARG_CHECK(pubkey != NULL);
720 ARG_CHECK(tweak32 != NULL);
721
722 ret = secp256k1_pubkey_load(ctx, &p, pubkey);
723 memset(pubkey, 0, sizeof(*pubkey));
725 if (ret) {
726 secp256k1_pubkey_save(pubkey, &p);
727 }
728
729 return ret;
730}
731
732int secp256k1_ec_seckey_tweak_mul(const secp256k1_context* ctx, unsigned char *seckey, const unsigned char *tweak32) {
733 secp256k1_scalar factor;
735 int ret = 0;
736 int overflow = 0;
737 VERIFY_CHECK(ctx != NULL);
738 ARG_CHECK(seckey != NULL);
739 ARG_CHECK(tweak32 != NULL);
740
741 secp256k1_scalar_set_b32(&factor, tweak32, &overflow);
742 ret = secp256k1_scalar_set_b32_seckey(&sec, seckey);
743 ret &= (!overflow) & secp256k1_eckey_seckey_tweak_mul(&sec, &factor);
745 secp256k1_scalar_get_b32(seckey, &sec);
746
748 secp256k1_scalar_clear(&factor);
749 return ret;
750}
751
752int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context* ctx, secp256k1_pubkey *pubkey, const unsigned char *tweak32) {
753 secp256k1_ge p;
754 secp256k1_scalar factor;
755 int ret = 0;
756 int overflow = 0;
757 VERIFY_CHECK(ctx != NULL);
758 ARG_CHECK(pubkey != NULL);
759 ARG_CHECK(tweak32 != NULL);
760
761 secp256k1_scalar_set_b32(&factor, tweak32, &overflow);
762 ret = !overflow && secp256k1_pubkey_load(ctx, &p, pubkey);
763 memset(pubkey, 0, sizeof(*pubkey));
764 if (ret) {
765 if (secp256k1_eckey_pubkey_tweak_mul(&p, &factor)) {
766 secp256k1_pubkey_save(pubkey, &p);
767 } else {
768 ret = 0;
769 }
770 }
771
772 return ret;
773}
774
775int secp256k1_context_randomize(secp256k1_context* ctx, const unsigned char *seed32) {
776 VERIFY_CHECK(ctx != NULL);
778
781 }
782 return 1;
783}
784
785int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey *pubnonce, const secp256k1_pubkey * const *pubnonces, size_t n) {
786 size_t i;
787 secp256k1_gej Qj;
788 secp256k1_ge Q;
789
790 VERIFY_CHECK(ctx != NULL);
791 ARG_CHECK(pubnonce != NULL);
792 memset(pubnonce, 0, sizeof(*pubnonce));
793 ARG_CHECK(n >= 1);
794 ARG_CHECK(pubnonces != NULL);
795
797
798 for (i = 0; i < n; i++) {
799 ARG_CHECK(pubnonces[i] != NULL);
800 secp256k1_pubkey_load(ctx, &Q, pubnonces[i]);
801 secp256k1_gej_add_ge(&Qj, &Qj, &Q);
802 }
803 if (secp256k1_gej_is_infinity(&Qj)) {
804 return 0;
805 }
806 secp256k1_ge_set_gej(&Q, &Qj);
807 secp256k1_pubkey_save(pubnonce, &Q);
808 return 1;
809}
810
811int secp256k1_tagged_sha256(const secp256k1_context* ctx, unsigned char *hash32, const unsigned char *tag, size_t taglen, const unsigned char *msg, size_t msglen) {
813 VERIFY_CHECK(ctx != NULL);
814 ARG_CHECK(hash32 != NULL);
815 ARG_CHECK(tag != NULL);
816 ARG_CHECK(msg != NULL);
817
818 secp256k1_sha256_initialize_tagged(&ctx->hash_ctx, &sha, tag, taglen);
819 secp256k1_sha256_write(&ctx->hash_ctx, &sha, msg, msglen);
820 secp256k1_sha256_finalize(&ctx->hash_ctx, &sha, hash32);
822 return 1;
823}
824
825#ifdef ENABLE_MODULE_ECDH
826# include "modules/ecdh/main_impl.h"
827#endif
828
829#ifdef ENABLE_MODULE_RECOVERY
831#endif
832
833#ifdef ENABLE_MODULE_EXTRAKEYS
835#endif
836
837#ifdef ENABLE_MODULE_SCHNORRSIG
839#endif
840
841#ifdef ENABLE_MODULE_MUSIG
843#endif
844
845#ifdef ENABLE_MODULE_ELLSWIFT
847#endif
848
849#ifdef ENABLE_MODULE_SILENTPAYMENTS
851#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 *ecmult_gen_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 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_seckey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak)
static int secp256k1_eckey_seckey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak)
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ecmult_gen_ctx)
static void secp256k1_ecmult_gen_ge(const secp256k1_ecmult_gen_context *ecmult_gen_ctx, secp256k1_ge *r, const secp256k1_scalar *a)
static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ecmult_gen_ctx, const secp256k1_hash_ctx *hash_ctx, const unsigned char *seed32)
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context *ecmult_gen_ctx, const secp256k1_hash_ctx *hash_ctx)
static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context *ecmult_gen_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 void secp256k1_ge_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_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_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 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_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size)
Parse a group element from a 33-byte compressed or 65-byte uncompressed public key.
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:22
#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:535
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:534
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:811
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:715
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:282
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:428
static int secp256k1_ec_seckey_tweak_add_helper(secp256k1_scalar *sec, const unsigned char *tweak32)
Definition: secp256k1.c:681
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:732
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:264
static void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space *scratch)
Definition: secp256k1.c:242
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:611
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:340
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:692
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:493
#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:622
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:453
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:391
static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context *ctx, const void *p, size_t len)
Definition: secp256k1.c:250
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:650
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:308
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:785
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:407
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:381
static secp256k1_scratch_space * secp256k1_scratch_space_create(const secp256k1_context *ctx, size_t max_size)
Definition: secp256k1.c:237
static int secp256k1_pubkey_load(const secp256k1_context *ctx, secp256k1_ge *ge, const secp256k1_pubkey *pubkey)
Definition: secp256k1.c:254
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:260
static int secp256k1_ec_pubkey_sort_cmp(const void *pk1, const void *pk2, void *ctx)
Definition: secp256k1.c:334
static SECP256K1_INLINE void buffer_append(unsigned char *buf, unsigned int *offset, const void *data, unsigned int len)
Definition: secp256k1.c:488
static int secp256k1_ec_pubkey_tweak_add_helper(secp256k1_ge *p, const unsigned char *tweak32)
Definition: secp256k1.c:708
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:530
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:775
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:472
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:440
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:632
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:752
static void secp256k1_ecdsa_signature_load(const secp256k1_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, const secp256k1_ecdsa_signature *sig)
Definition: secp256k1.c:367
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:597
int secp256k1_ec_pubkey_negate(const secp256k1_context *ctx, secp256k1_pubkey *pubkey)
Negates a public key in place.
Definition: secp256k1.c:665
#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:537
#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