Bitcoin ABC 0.33.3
P2P Digital Currency
tests_exhaustive.c
Go to the documentation of this file.
1/***********************************************************************
2 * Copyright (c) 2016 Andrew Poelstra *
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#include <stdio.h>
8#include <stdlib.h>
9#include <time.h>
10
11#ifndef EXHAUSTIVE_TEST_ORDER
12/* see group_impl.h for allowable values */
13#define EXHAUSTIVE_TEST_ORDER 13
14#endif
15
16#ifdef USE_EXTERNAL_DEFAULT_CALLBACKS
17 #pragma message("Ignoring USE_EXTERNAL_CALLBACKS in exhaustive_tests.")
18 #undef USE_EXTERNAL_DEFAULT_CALLBACKS
19#endif
20#include "secp256k1.c"
21
22#include "../include/secp256k1.h"
23#include "assumptions.h"
24#include "group.h"
25#include "testrand_impl.h"
28#include "util.h"
29
30static int count = 2;
31
33static void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b) {
34 CHECK(a->infinity == b->infinity);
35 if (a->infinity) {
36 return;
37 }
40}
41
42static void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b) {
43 secp256k1_fe z2s;
44 secp256k1_fe u1, u2, s1, s2;
45 CHECK(a->infinity == b->infinity);
46 if (a->infinity) {
47 return;
48 }
49 /* Check a.x * b.z^2 == b.x && a.y * b.z^3 == b.y, to avoid inverses. */
50 secp256k1_fe_sqr(&z2s, &b->z);
51 secp256k1_fe_mul(&u1, &a->x, &z2s);
52 u2 = b->x; secp256k1_fe_normalize_weak(&u2);
53 secp256k1_fe_mul(&s1, &a->y, &z2s); secp256k1_fe_mul(&s1, &s1, &b->z);
54 s2 = b->y; secp256k1_fe_normalize_weak(&s2);
57}
58
59static void random_fe(secp256k1_fe *x) {
60 unsigned char bin[32];
61 do {
63 if (secp256k1_fe_set_b32_limit(x, bin)) {
64 return;
65 }
66 } while(1);
67}
68
70 int tries = 10;
71 while (--tries >= 0) {
72 random_fe(nz);
74 if (!secp256k1_fe_is_zero(nz)) {
75 break;
76 }
77 }
78 /* Infinitesimal probability of spurious failure here */
79 CHECK(tries >= 0);
80}
83static uint32_t num_cores = 1;
84static uint32_t this_core = 0;
85
86SECP256K1_INLINE static int skip_section(uint64_t* iter) {
87 if (num_cores == 1) return 0;
88 *iter += 0xe7037ed1a0b428dbULL;
89 return ((((uint32_t)*iter ^ (*iter >> 32)) * num_cores) >> 32) != this_core;
90}
91
92static int secp256k1_nonce_function_smallint(unsigned char *nonce32, const unsigned char *msg32,
93 const unsigned char *key32, const unsigned char *algo16,
94 void *data, unsigned int attempt) {
96 int *idata = data;
97 (void)msg32;
98 (void)key32;
99 (void)algo16;
100 /* Some nonces cannot be used because they'd cause s and/or r to be zero.
101 * The signing function has retry logic here that just re-calls the nonce
102 * function with an increased `attempt`. So if attempt > 0 this means we
103 * need to change the nonce to avoid an infinite loop. */
104 if (attempt > 0) {
105 *idata = (*idata + 1) % EXHAUSTIVE_TEST_ORDER;
106 }
107 secp256k1_scalar_set_int(&s, *idata);
108 secp256k1_scalar_get_b32(nonce32, &s);
109 return 1;
110}
111
113 int i;
114 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
115 secp256k1_ge res;
117 ge_equals_ge(&group[i * EXHAUSTIVE_TEST_LAMBDA % EXHAUSTIVE_TEST_ORDER], &res);
118 }
119}
120
121static void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *groupj) {
122 int i, j;
123 uint64_t iter = 0;
124
125 /* Sanity-check (and check infinity functions) */
127 CHECK(secp256k1_gej_is_infinity(&groupj[0]));
128 for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) {
130 CHECK(!secp256k1_gej_is_infinity(&groupj[i]));
131 }
132
133 /* Check all addition formulae */
134 for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) {
135 secp256k1_fe fe_inv;
136 if (skip_section(&iter)) continue;
137 secp256k1_fe_inv(&fe_inv, &groupj[j].z);
138 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
139 secp256k1_ge zless_gej;
140 secp256k1_gej tmp;
141 /* add_var */
142 secp256k1_gej_add_var(&tmp, &groupj[i], &groupj[j], NULL);
143 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
144 /* add_ge */
145 if (j > 0) {
146 secp256k1_gej_add_ge(&tmp, &groupj[i], &group[j]);
147 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
148 }
149 /* add_ge_var */
150 secp256k1_gej_add_ge_var(&tmp, &groupj[i], &group[j], NULL);
151 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
152 /* add_zinv_var */
153 zless_gej.infinity = groupj[j].infinity;
154 zless_gej.x = groupj[j].x;
155 zless_gej.y = groupj[j].y;
156 secp256k1_gej_add_zinv_var(&tmp, &groupj[i], &zless_gej, &fe_inv);
157 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
158 }
159 }
160
161 /* Check doubling */
162 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
163 secp256k1_gej tmp;
164 secp256k1_gej_double(&tmp, &groupj[i]);
165 ge_equals_gej(&group[(2 * i) % EXHAUSTIVE_TEST_ORDER], &tmp);
166 secp256k1_gej_double_var(&tmp, &groupj[i], NULL);
167 ge_equals_gej(&group[(2 * i) % EXHAUSTIVE_TEST_ORDER], &tmp);
168 }
169
170 /* Check negation */
171 for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) {
172 secp256k1_ge tmp;
173 secp256k1_gej tmpj;
174 secp256k1_ge_neg(&tmp, &group[i]);
176 secp256k1_gej_neg(&tmpj, &groupj[i]);
178 }
179}
180
181static void test_exhaustive_ecmult(const secp256k1_ge *group, const secp256k1_gej *groupj) {
182 int i, j, r_log;
183 uint64_t iter = 0;
184 for (r_log = 1; r_log < EXHAUSTIVE_TEST_ORDER; r_log++) {
185 for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) {
186 if (skip_section(&iter)) continue;
187 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
188 secp256k1_gej tmp;
189 secp256k1_scalar na, ng;
192
193 secp256k1_ecmult(&tmp, &groupj[r_log], &na, &ng);
194 ge_equals_gej(&group[(i * r_log + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
195
196 }
197 }
198 }
199
200 for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) {
201 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
202 int ret;
203 secp256k1_gej tmp;
204 secp256k1_fe xn, xd, tmpf;
206
207 if (skip_section(&iter)) continue;
208
210
211 /* Test secp256k1_ecmult_const. */
212 secp256k1_ecmult_const(&tmp, &group[i], &ng);
213 ge_equals_gej(&group[(i * j) % EXHAUSTIVE_TEST_ORDER], &tmp);
214
215 if (i != 0 && j != 0) {
216 /* Test secp256k1_ecmult_const_xonly with all curve X coordinates, and xd=NULL. */
217 ret = secp256k1_ecmult_const_xonly(&tmpf, &group[i].x, NULL, &ng, 0);
218 CHECK(ret);
220
221 /* Test secp256k1_ecmult_const_xonly with all curve X coordinates, with random xd. */
223 secp256k1_fe_mul(&xn, &xd, &group[i].x);
224 ret = secp256k1_ecmult_const_xonly(&tmpf, &xn, &xd, &ng, 0);
225 CHECK(ret);
227 }
228 }
229 }
230}
231
232typedef struct {
236
237static int ecmult_multi_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *cbdata) {
238 ecmult_multi_data *data = (ecmult_multi_data*) cbdata;
239 *sc = data->sc[idx];
240 *pt = data->pt[idx];
241 return 1;
242}
243
245 int i, j, k, x, y;
246 uint64_t iter = 0;
248 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
249 for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) {
250 for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) {
251 for (x = 0; x < EXHAUSTIVE_TEST_ORDER; x++) {
252 if (skip_section(&iter)) continue;
253 for (y = 0; y < EXHAUSTIVE_TEST_ORDER; y++) {
254 secp256k1_gej tmp;
255 secp256k1_scalar g_sc;
257
258 secp256k1_scalar_set_int(&data.sc[0], i);
259 secp256k1_scalar_set_int(&data.sc[1], j);
260 secp256k1_scalar_set_int(&g_sc, k);
261 data.pt[0] = group[x];
262 data.pt[1] = group[y];
263
264 secp256k1_ecmult_multi_var(&ctx->error_callback, scratch, &tmp, &g_sc, ecmult_multi_callback, &data, 2);
265 ge_equals_gej(&group[(i * x + j * y + k) % EXHAUSTIVE_TEST_ORDER], &tmp);
266 }
267 }
268 }
269 }
270 }
272}
273
274static void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* overflow) {
275 secp256k1_fe x;
276 unsigned char x_bin[32];
278 x = group[k].x;
280 secp256k1_fe_get_b32(x_bin, &x);
281 secp256k1_scalar_set_b32(r, x_bin, overflow);
282}
283
285 int s, r, msg, key;
286 uint64_t iter = 0;
287 for (s = 1; s < EXHAUSTIVE_TEST_ORDER; s++) {
288 for (r = 1; r < EXHAUSTIVE_TEST_ORDER; r++) {
289 for (msg = 1; msg < EXHAUSTIVE_TEST_ORDER; msg++) {
290 for (key = 1; key < EXHAUSTIVE_TEST_ORDER; key++) {
291 secp256k1_ge nonconst_ge;
294 secp256k1_scalar sk_s, msg_s, r_s, s_s;
295 secp256k1_scalar s_times_k_s, msg_plus_r_times_sk_s;
296 int k, should_verify;
297 unsigned char msg32[32];
298
299 if (skip_section(&iter)) continue;
300
304 secp256k1_scalar_set_int(&sk_s, key);
305
306 /* Verify by hand */
307 /* Run through every k value that gives us this r and check that *one* works.
308 * Note there could be none, there could be multiple, ECDSA is weird. */
309 should_verify = 0;
310 for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) {
311 secp256k1_scalar check_x_s;
312 r_from_k(&check_x_s, group, k, NULL);
313 if (r_s == check_x_s) {
314 secp256k1_scalar_set_int(&s_times_k_s, k);
315 secp256k1_scalar_mul(&s_times_k_s, &s_times_k_s, &s_s);
316 secp256k1_scalar_mul(&msg_plus_r_times_sk_s, &r_s, &sk_s);
317 secp256k1_scalar_add(&msg_plus_r_times_sk_s, &msg_plus_r_times_sk_s, &msg_s);
318 should_verify |= secp256k1_scalar_eq(&s_times_k_s, &msg_plus_r_times_sk_s);
319 }
320 }
321 /* nb we have a "high s" rule */
322 should_verify &= !secp256k1_scalar_is_high(&s_s);
323
324 /* Verify by calling verify */
326 memcpy(&nonconst_ge, &group[sk_s], sizeof(nonconst_ge));
327 secp256k1_pubkey_save(&pk, &nonconst_ge);
328 secp256k1_scalar_get_b32(msg32, &msg_s);
329 CHECK(should_verify ==
330 secp256k1_ecdsa_verify(ctx, &sig, msg32, &pk));
331 }
332 }
333 }
334 }
335}
336
338 int i, j, k;
339 uint64_t iter = 0;
340
341 /* Loop */
342 for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { /* message */
343 for (j = 1; j < EXHAUSTIVE_TEST_ORDER; j++) { /* key */
344 if (skip_section(&iter)) continue;
345 for (k = 1; k < EXHAUSTIVE_TEST_ORDER; k++) { /* nonce */
346 const int starting_k = k;
347 int ret;
349 secp256k1_scalar sk, msg, r, s, expected_r;
350 unsigned char sk32[32], msg32[32];
353 secp256k1_scalar_get_b32(sk32, &sk);
355
357 CHECK(ret == 1);
358
360 /* Note that we compute expected_r *after* signing -- this is important
361 * because our nonce-computing function function might change k during
362 * signing. */
363 r_from_k(&expected_r, group, k, NULL);
364 CHECK(r == expected_r);
365 CHECK((k * s) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER ||
367
368 /* Overflow means we've tried every possible nonce */
369 if (k < starting_k) {
370 break;
371 }
372 }
373 }
374 }
375
376 /* We would like to verify zero-knowledge here by counting how often every
377 * possible (s, r) tuple appears, but because the group order is larger
378 * than the field order, when coercing the x-values to scalar values, some
379 * appear more often than others, so we are actually not zero-knowledge.
380 * (This effect also appears in the real code, but the difference is on the
381 * order of 1/2^128th the field order, so the deviation is not useful to a
382 * computationally bounded attacker.)
383 */
384}
385
386#ifdef ENABLE_MODULE_RECOVERY
388#endif
389
390#ifdef ENABLE_MODULE_EXTRAKEYS
392#endif
393
394#ifdef ENABLE_MODULE_SCHNORRSIG
396#endif
397
398int main(int argc, char** argv) {
399 int i;
402 unsigned char rand32[32];
404
405 /* Disable buffering for stdout to improve reliability of getting
406 * diagnostic information. Happens right at the start of main because
407 * setbuf must be used before any other operation on the stream. */
408 setbuf(stdout, NULL);
409 /* Also disable buffering for stderr because it's not guaranteed that it's
410 * unbuffered on all systems. */
411 setbuf(stderr, NULL);
412
413 printf("Exhaustive tests for order %lu\n", (unsigned long)EXHAUSTIVE_TEST_ORDER);
414
415 /* find iteration count */
416 if (argc > 1) {
417 count = strtol(argv[1], NULL, 0);
418 }
419 printf("test count = %i\n", count);
420
421 /* find random seed */
422 secp256k1_testrand_init(argc > 2 ? argv[2] : NULL);
423
424 /* set up split processing */
425 if (argc > 4) {
426 num_cores = strtol(argv[3], NULL, 0);
427 this_core = strtol(argv[4], NULL, 0);
428 if (num_cores < 1 || this_core >= num_cores) {
429 fprintf(stderr, "Usage: %s [count] [seed] [numcores] [thiscore]\n", argv[0]);
430 return 1;
431 }
432 printf("running tests for core %lu (out of [0..%lu])\n", (unsigned long)this_core, (unsigned long)num_cores - 1);
433 }
434
435 /* Recreate the ecmult{,_gen} tables using the right generator (as selected via EXHAUSTIVE_TEST_ORDER) */
438
439 while (count--) {
440 /* Build context */
442 secp256k1_testrand256(rand32);
444
445 /* Generate the entire group */
446 secp256k1_gej_set_infinity(&groupj[0]);
447 secp256k1_ge_set_gej(&group[0], &groupj[0]);
448 for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) {
449 secp256k1_gej_add_ge(&groupj[i], &groupj[i - 1], &secp256k1_ge_const_g);
450 secp256k1_ge_set_gej(&group[i], &groupj[i]);
451 if (count != 0) {
452 /* Set a different random z-value for each Jacobian point, except z=1
453 is used in the last iteration. */
454 secp256k1_fe z;
455 random_fe(&z);
456 secp256k1_gej_rescale(&groupj[i], &z);
457 }
458
459 /* Verify against ecmult_gen */
460 {
461 secp256k1_scalar scalar_i;
462 secp256k1_gej generatedj;
463 secp256k1_ge generated;
464
465 secp256k1_scalar_set_int(&scalar_i, i);
466 secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &generatedj, &scalar_i);
467 secp256k1_ge_set_gej(&generated, &generatedj);
468
469 CHECK(group[i].infinity == 0);
470 CHECK(generated.infinity == 0);
471 CHECK(secp256k1_fe_equal_var(&generated.x, &group[i].x));
472 CHECK(secp256k1_fe_equal_var(&generated.y, &group[i].y));
473 }
474 }
475
476 /* Run the tests */
483
484#ifdef ENABLE_MODULE_RECOVERY
486#endif
487#ifdef ENABLE_MODULE_EXTRAKEYS
489#endif
490#ifdef ENABLE_MODULE_SCHNORRSIG
492#endif
493
495 }
496
498
499 printf("no problems found\n");
500 return 0;
501}
static int secp256k1_ecmult_multi_var(const secp256k1_callback *error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n)
Multi-multiply: R = inp_g_sc * G + sum_i ni * Ai.
static void secp256k1_ecmult(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng)
Double multiply: R = na*A + ng*G.
static void secp256k1_ecmult_compute_two_tables(secp256k1_ge_storage *table, secp256k1_ge_storage *table_128, int window_g, const secp256k1_ge *gen)
static int secp256k1_ecmult_const_xonly(secp256k1_fe *r, const secp256k1_fe *n, const secp256k1_fe *d, const secp256k1_scalar *q, int known_on_curve)
Same as secp256k1_ecmult_const, but takes in an x coordinate of the base point only,...
static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q)
Multiply: R = q*A (in constant-time for q)
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.
#define ECMULT_GEN_PREC_BITS
Definition: ecmult_gen.h:14
static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage *table, const secp256k1_ge *gen, int bits)
static void test_exhaustive_extrakeys(const secp256k1_context *ctx, const secp256k1_ge *group)
static int secp256k1_fe_equal_var(const secp256k1_fe *a, const secp256k1_fe *b)
Determine whether two field elements are equal, without constant-time guarantee.
#define secp256k1_fe_normalize_weak
Definition: field.h:79
#define secp256k1_fe_mul
Definition: field.h:94
#define secp256k1_fe_is_zero
Definition: field.h:85
#define secp256k1_fe_set_b32_limit
Definition: field.h:89
#define secp256k1_fe_get_b32
Definition: field.h:90
#define secp256k1_fe_inv
Definition: field.h:99
#define secp256k1_fe_sqr
Definition: field.h:95
#define secp256k1_fe_normalize
Definition: field.h:78
static void secp256k1_gej_double_var(secp256k1_gej *r, const secp256k1_gej *a, secp256k1_fe *rzr)
Set r equal to the double of a.
static void secp256k1_gej_add_zinv_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b, const secp256k1_fe *bzinv)
Set r equal to the sum of a and b (with the inverse of b's Z coordinate passed as bzinv).
static void secp256k1_ge_mul_lambda(secp256k1_ge *r, const secp256k1_ge *a)
Set r to be equal to lambda times a, where lambda is chosen in a way such that this is very fast.
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_gej_add_ge_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b, secp256k1_fe *rzr)
Set r equal to the sum of a and b (with b given in affine 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_gej_add_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_gej *b, secp256k1_fe *rzr)
Set r equal to the sum of a and b.
static void secp256k1_gej_rescale(secp256k1_gej *r, const secp256k1_fe *b)
Rescale a jacobian point by b which must be non-zero.
static void secp256k1_ge_set_gej(secp256k1_ge *r, secp256k1_gej *a)
Set a group element equal to another which is given in jacobian coordinates.
static void secp256k1_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_gej_double(secp256k1_gej *r, const secp256k1_gej *a)
Set r equal to the double of a.
static void secp256k1_gej_neg(secp256k1_gej *r, const secp256k1_gej *a)
Set r equal to the inverse of a (i.e., mirrored around the X axis)
static const secp256k1_ge secp256k1_ge_const_g
Definition: group_impl.h:70
secp256k1_context * ctx
Definition: bench_impl.h:13
void printf(const char *fmt, const Args &...args)
Format list of arguments to std::cout, according to the given format string.
Definition: tinyformat.h:1126
const secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)]
const secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)]
#define WINDOW_G
const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[ECMULT_GEN_PREC_N(ECMULT_GEN_PREC_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)]
SchnorrSig sig
Definition: processor.cpp:537
static void test_exhaustive_recovery(const secp256k1_context *ctx, const secp256k1_ge *group)
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 void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v)
Set a scalar to an unsigned integer.
static int secp256k1_scalar_eq(const secp256k1_scalar *a, const secp256k1_scalar *b)
Compare two scalars.
static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar *a)
Convert a scalar to a byte array.
static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Add two scalars together (modulo the group order).
static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Multiply two scalars (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 test_exhaustive_schnorrsig(const secp256k1_context *ctx)
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)
#define SECP256K1_INLINE
Definition: util.h:48
#define CHECK(cond)
Definition: util.h:115
static void secp256k1_ecdsa_signature_save(secp256k1_ecdsa_signature *sig, const secp256k1_scalar *r, const secp256k1_scalar *s)
Definition: secp256k1.c:353
static void secp256k1_pubkey_save(secp256k1_pubkey *pubkey, secp256k1_ge *ge)
Definition: secp256k1.c:258
static void secp256k1_ecdsa_signature_load(const secp256k1_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, const secp256k1_ecdsa_signature *sig)
Definition: secp256k1.c:339
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
Destroy a secp256k1 context object (created in dynamically allocated memory).
Definition: secp256k1.c:186
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32) SECP256K1_ARG_NONNULL(1)
Randomizes the context to provide enhanced protection against side-channel leakage.
Definition: secp256k1.c:751
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object (in dynamically allocated memory).
Definition: secp256k1.c:140
SECP256K1_API int secp256k1_ecdsa_sign(const secp256k1_context *ctx, secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void *ndata) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Create an ECDSA signature.
Definition: secp256k1.c:558
#define SECP256K1_CONTEXT_NONE
Context flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size,...
Definition: secp256k1.h:178
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(const secp256k1_context *ctx, const secp256k1_ecdsa_signature *sig, const unsigned char *msghash32, const secp256k1_pubkey *pubkey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Verify an ECDSA signature.
Definition: secp256k1.c:444
secp256k1_scalar * sc
Definition: tests.c:4621
secp256k1_ge * pt
Definition: tests.c:4622
secp256k1_callback error_callback
Definition: secp256k1.c:63
secp256k1_ecmult_gen_context ecmult_gen_ctx
Definition: secp256k1.c:61
Opaque data structured that holds a parsed ECDSA signature.
Definition: secp256k1.h:74
This field implementation represents the value as 10 uint32_t limbs in base 2^26.
Definition: field_10x26.h:14
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
Definition: group.h:16
int infinity
Definition: group.h:19
secp256k1_fe x
Definition: group.h:17
secp256k1_fe y
Definition: group.h:18
A group element of the secp256k1 curve, in jacobian coordinates.
Definition: group.h:28
secp256k1_fe y
Definition: group.h:30
secp256k1_fe x
Definition: group.h:29
int infinity
Definition: group.h:32
secp256k1_fe z
Definition: group.h:31
Opaque data structure that holds a parsed and valid public key.
Definition: secp256k1.h:61
A scalar modulo the group order of the secp256k1 curve.
Definition: scalar_4x64.h:13
static void secp256k1_testrand256(unsigned char *b32)
Generate a pseudorandom 32-byte array.
static void secp256k1_testrand_init(const char *hexseed)
Initialize the test RNG using (hex encoded) array up to 16 bytes, or randomly if hexseed is NULL.
static void secp256k1_testrand_finish(void)
Print final test information.
static void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b)
stolen from tests.c
static void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *group)
static void test_exhaustive_endomorphism(const secp256k1_ge *group)
static void test_exhaustive_ecmult(const secp256k1_ge *group, const secp256k1_gej *groupj)
static uint32_t this_core
static void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b)
static SECP256K1_INLINE int skip_section(uint64_t *iter)
int main(int argc, char **argv)
static void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int *overflow)
static void test_exhaustive_ecmult_multi(const secp256k1_context *ctx, const secp256k1_ge *group)
static void random_fe(secp256k1_fe *x)
static void random_fe_non_zero(secp256k1_fe *nz)
static void test_exhaustive_sign(const secp256k1_context *ctx, const secp256k1_ge *group)
static uint32_t num_cores
END stolen from tests.c.
static int ecmult_multi_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *cbdata)
static int count
static void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *groupj)
#define EXHAUSTIVE_TEST_ORDER
static int secp256k1_nonce_function_smallint(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int attempt)