Bitcoin ABC 0.32.10
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#include "secp256k1.c"
17#include "../include/secp256k1.h"
18#include "assumptions.h"
19#include "group.h"
20#include "testrand_impl.h"
23
24static int count = 2;
25
27void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b) {
28 CHECK(a->infinity == b->infinity);
29 if (a->infinity) {
30 return;
31 }
34}
35
36void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b) {
37 secp256k1_fe z2s;
38 secp256k1_fe u1, u2, s1, s2;
39 CHECK(a->infinity == b->infinity);
40 if (a->infinity) {
41 return;
42 }
43 /* Check a.x * b.z^2 == b.x && a.y * b.z^3 == b.y, to avoid inverses. */
44 secp256k1_fe_sqr(&z2s, &b->z);
45 secp256k1_fe_mul(&u1, &a->x, &z2s);
46 u2 = b->x; secp256k1_fe_normalize_weak(&u2);
47 secp256k1_fe_mul(&s1, &a->y, &z2s); secp256k1_fe_mul(&s1, &s1, &b->z);
48 s2 = b->y; secp256k1_fe_normalize_weak(&s2);
51}
52
54 unsigned char bin[32];
55 do {
57 if (secp256k1_fe_set_b32(x, bin)) {
58 return;
59 }
60 } while(1);
61}
64static uint32_t num_cores = 1;
65static uint32_t this_core = 0;
66
67SECP256K1_INLINE static int skip_section(uint64_t* iter) {
68 if (num_cores == 1) return 0;
69 *iter += 0xe7037ed1a0b428dbULL;
70 return ((((uint32_t)*iter ^ (*iter >> 32)) * num_cores) >> 32) != this_core;
71}
72
73int secp256k1_nonce_function_smallint(unsigned char *nonce32, const unsigned char *msg32,
74 const unsigned char *key32, const unsigned char *algo16,
75 void *data, unsigned int attempt) {
77 int *idata = data;
78 (void)msg32;
79 (void)key32;
80 (void)algo16;
81 /* Some nonces cannot be used because they'd cause s and/or r to be zero.
82 * The signing function has retry logic here that just re-calls the nonce
83 * function with an increased `attempt`. So if attempt > 0 this means we
84 * need to change the nonce to avoid an infinite loop. */
85 if (attempt > 0) {
86 *idata = (*idata + 1) % EXHAUSTIVE_TEST_ORDER;
87 }
88 secp256k1_scalar_set_int(&s, *idata);
89 secp256k1_scalar_get_b32(nonce32, &s);
90 return 1;
91}
92
94 int i;
95 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
96 secp256k1_ge res;
97 secp256k1_ge_mul_lambda(&res, &group[i]);
98 ge_equals_ge(&group[i * EXHAUSTIVE_TEST_LAMBDA % EXHAUSTIVE_TEST_ORDER], &res);
99 }
100}
101
102void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *groupj) {
103 int i, j;
104 uint64_t iter = 0;
105
106 /* Sanity-check (and check infinity functions) */
108 CHECK(secp256k1_gej_is_infinity(&groupj[0]));
109 for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) {
110 CHECK(!secp256k1_ge_is_infinity(&group[i]));
111 CHECK(!secp256k1_gej_is_infinity(&groupj[i]));
112 }
113
114 /* Check all addition formulae */
115 for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) {
116 secp256k1_fe fe_inv;
117 if (skip_section(&iter)) continue;
118 secp256k1_fe_inv(&fe_inv, &groupj[j].z);
119 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
120 secp256k1_ge zless_gej;
121 secp256k1_gej tmp;
122 /* add_var */
123 secp256k1_gej_add_var(&tmp, &groupj[i], &groupj[j], NULL);
124 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
125 /* add_ge */
126 if (j > 0) {
127 secp256k1_gej_add_ge(&tmp, &groupj[i], &group[j]);
128 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
129 }
130 /* add_ge_var */
131 secp256k1_gej_add_ge_var(&tmp, &groupj[i], &group[j], NULL);
132 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
133 /* add_zinv_var */
134 zless_gej.infinity = groupj[j].infinity;
135 zless_gej.x = groupj[j].x;
136 zless_gej.y = groupj[j].y;
137 secp256k1_gej_add_zinv_var(&tmp, &groupj[i], &zless_gej, &fe_inv);
138 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
139 }
140 }
141
142 /* Check doubling */
143 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
144 secp256k1_gej tmp;
145 secp256k1_gej_double(&tmp, &groupj[i]);
146 ge_equals_gej(&group[(2 * i) % EXHAUSTIVE_TEST_ORDER], &tmp);
147 secp256k1_gej_double_var(&tmp, &groupj[i], NULL);
148 ge_equals_gej(&group[(2 * i) % EXHAUSTIVE_TEST_ORDER], &tmp);
149 }
150
151 /* Check negation */
152 for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) {
153 secp256k1_ge tmp;
154 secp256k1_gej tmpj;
155 secp256k1_ge_neg(&tmp, &group[i]);
156 ge_equals_ge(&group[EXHAUSTIVE_TEST_ORDER - i], &tmp);
157 secp256k1_gej_neg(&tmpj, &groupj[i]);
158 ge_equals_gej(&group[EXHAUSTIVE_TEST_ORDER - i], &tmpj);
159 }
160}
161
162void test_exhaustive_ecmult(const secp256k1_ge *group, const secp256k1_gej *groupj) {
163 int i, j, r_log;
164 uint64_t iter = 0;
165 for (r_log = 1; r_log < EXHAUSTIVE_TEST_ORDER; r_log++) {
166 for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) {
167 if (skip_section(&iter)) continue;
168 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
169 secp256k1_gej tmp;
170 secp256k1_scalar na, ng;
173
174 secp256k1_ecmult(&tmp, &groupj[r_log], &na, &ng);
175 ge_equals_gej(&group[(i * r_log + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
176
177 if (i > 0) {
178 secp256k1_ecmult_const(&tmp, &group[i], &ng, 256);
179 ge_equals_gej(&group[(i * j) % EXHAUSTIVE_TEST_ORDER], &tmp);
180 }
181 }
182 }
183 }
184}
185
186typedef struct {
190
191static int ecmult_multi_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *cbdata) {
192 ecmult_multi_data *data = (ecmult_multi_data*) cbdata;
193 *sc = data->sc[idx];
194 *pt = data->pt[idx];
195 return 1;
196}
197
199 int i, j, k, x, y;
200 uint64_t iter = 0;
202 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
203 for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) {
204 for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) {
205 for (x = 0; x < EXHAUSTIVE_TEST_ORDER; x++) {
206 if (skip_section(&iter)) continue;
207 for (y = 0; y < EXHAUSTIVE_TEST_ORDER; y++) {
208 secp256k1_gej tmp;
209 secp256k1_scalar g_sc;
211
212 secp256k1_scalar_set_int(&data.sc[0], i);
213 secp256k1_scalar_set_int(&data.sc[1], j);
214 secp256k1_scalar_set_int(&g_sc, k);
215 data.pt[0] = group[x];
216 data.pt[1] = group[y];
217
218 secp256k1_ecmult_multi_var(&ctx->error_callback, scratch, &tmp, &g_sc, ecmult_multi_callback, &data, 2);
219 ge_equals_gej(&group[(i * x + j * y + k) % EXHAUSTIVE_TEST_ORDER], &tmp);
220 }
221 }
222 }
223 }
224 }
226}
227
228void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* overflow) {
229 secp256k1_fe x;
230 unsigned char x_bin[32];
232 x = group[k].x;
234 secp256k1_fe_get_b32(x_bin, &x);
235 secp256k1_scalar_set_b32(r, x_bin, overflow);
236}
237
239 int s, r, msg, key;
240 uint64_t iter = 0;
241 for (s = 1; s < EXHAUSTIVE_TEST_ORDER; s++) {
242 for (r = 1; r < EXHAUSTIVE_TEST_ORDER; r++) {
243 for (msg = 1; msg < EXHAUSTIVE_TEST_ORDER; msg++) {
244 for (key = 1; key < EXHAUSTIVE_TEST_ORDER; key++) {
245 secp256k1_ge nonconst_ge;
248 secp256k1_scalar sk_s, msg_s, r_s, s_s;
249 secp256k1_scalar s_times_k_s, msg_plus_r_times_sk_s;
250 int k, should_verify;
251 unsigned char msg32[32];
252
253 if (skip_section(&iter)) continue;
254
257 secp256k1_scalar_set_int(&msg_s, msg);
258 secp256k1_scalar_set_int(&sk_s, key);
259
260 /* Verify by hand */
261 /* Run through every k value that gives us this r and check that *one* works.
262 * Note there could be none, there could be multiple, ECDSA is weird. */
263 should_verify = 0;
264 for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) {
265 secp256k1_scalar check_x_s;
266 r_from_k(&check_x_s, group, k, NULL);
267 if (r_s == check_x_s) {
268 secp256k1_scalar_set_int(&s_times_k_s, k);
269 secp256k1_scalar_mul(&s_times_k_s, &s_times_k_s, &s_s);
270 secp256k1_scalar_mul(&msg_plus_r_times_sk_s, &r_s, &sk_s);
271 secp256k1_scalar_add(&msg_plus_r_times_sk_s, &msg_plus_r_times_sk_s, &msg_s);
272 should_verify |= secp256k1_scalar_eq(&s_times_k_s, &msg_plus_r_times_sk_s);
273 }
274 }
275 /* nb we have a "high s" rule */
276 should_verify &= !secp256k1_scalar_is_high(&s_s);
277
278 /* Verify by calling verify */
280 memcpy(&nonconst_ge, &group[sk_s], sizeof(nonconst_ge));
281 secp256k1_pubkey_save(&pk, &nonconst_ge);
282 secp256k1_scalar_get_b32(msg32, &msg_s);
283 CHECK(should_verify ==
284 secp256k1_ecdsa_verify(ctx, &sig, msg32, &pk));
285 }
286 }
287 }
288 }
289}
290
292 int i, j, k;
293 uint64_t iter = 0;
294
295 /* Loop */
296 for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { /* message */
297 for (j = 1; j < EXHAUSTIVE_TEST_ORDER; j++) { /* key */
298 if (skip_section(&iter)) continue;
299 for (k = 1; k < EXHAUSTIVE_TEST_ORDER; k++) { /* nonce */
300 const int starting_k = k;
301 int ret;
303 secp256k1_scalar sk, msg, r, s, expected_r;
304 unsigned char sk32[32], msg32[32];
307 secp256k1_scalar_get_b32(sk32, &sk);
308 secp256k1_scalar_get_b32(msg32, &msg);
309
311 CHECK(ret == 1);
312
314 /* Note that we compute expected_r *after* signing -- this is important
315 * because our nonce-computing function function might change k during
316 * signing. */
317 r_from_k(&expected_r, group, k, NULL);
318 CHECK(r == expected_r);
319 CHECK((k * s) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER ||
321
322 /* Overflow means we've tried every possible nonce */
323 if (k < starting_k) {
324 break;
325 }
326 }
327 }
328 }
329
330 /* We would like to verify zero-knowledge here by counting how often every
331 * possible (s, r) tuple appears, but because the group order is larger
332 * than the field order, when coercing the x-values to scalar values, some
333 * appear more often than others, so we are actually not zero-knowledge.
334 * (This effect also appears in the real code, but the difference is on the
335 * order of 1/2^128th the field order, so the deviation is not useful to a
336 * computationally bounded attacker.)
337 */
338}
339
340#ifdef ENABLE_MODULE_RECOVERY
342#endif
343
344#ifdef ENABLE_MODULE_EXTRAKEYS
346#endif
347
348#ifdef ENABLE_MODULE_SCHNORRSIG
350#endif
351
352int main(int argc, char** argv) {
353 int i;
356 unsigned char rand32[32];
358
359 /* Disable buffering for stdout to improve reliability of getting
360 * diagnostic information. Happens right at the start of main because
361 * setbuf must be used before any other operation on the stream. */
362 setbuf(stdout, NULL);
363 /* Also disable buffering for stderr because it's not guaranteed that it's
364 * unbuffered on all systems. */
365 setbuf(stderr, NULL);
366
367 printf("Exhaustive tests for order %lu\n", (unsigned long)EXHAUSTIVE_TEST_ORDER);
368
369 /* find iteration count */
370 if (argc > 1) {
371 count = strtol(argv[1], NULL, 0);
372 }
373 printf("test count = %i\n", count);
374
375 /* find random seed */
376 secp256k1_testrand_init(argc > 2 ? argv[2] : NULL);
377
378 /* set up split processing */
379 if (argc > 4) {
380 num_cores = strtol(argv[3], NULL, 0);
381 this_core = strtol(argv[4], NULL, 0);
382 if (num_cores < 1 || this_core >= num_cores) {
383 fprintf(stderr, "Usage: %s [count] [seed] [numcores] [thiscore]\n", argv[0]);
384 return 1;
385 }
386 printf("running tests for core %lu (out of [0..%lu])\n", (unsigned long)this_core, (unsigned long)num_cores - 1);
387 }
388
389 /* Recreate the ecmult{,_gen} tables using the right generator (as selected via EXHAUSTIVE_TEST_ORDER) */
392
393 while (count--) {
394 /* Build context */
396 secp256k1_testrand256(rand32);
398
399 /* Generate the entire group */
400 secp256k1_gej_set_infinity(&groupj[0]);
401 secp256k1_ge_set_gej(&group[0], &groupj[0]);
402 for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) {
403 secp256k1_gej_add_ge(&groupj[i], &groupj[i - 1], &secp256k1_ge_const_g);
404 secp256k1_ge_set_gej(&group[i], &groupj[i]);
405 if (count != 0) {
406 /* Set a different random z-value for each Jacobian point, except z=1
407 is used in the last iteration. */
408 secp256k1_fe z;
409 random_fe(&z);
410 secp256k1_gej_rescale(&groupj[i], &z);
411 }
412
413 /* Verify against ecmult_gen */
414 {
415 secp256k1_scalar scalar_i;
416 secp256k1_gej generatedj;
417 secp256k1_ge generated;
418
419 secp256k1_scalar_set_int(&scalar_i, i);
420 secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &generatedj, &scalar_i);
421 secp256k1_ge_set_gej(&generated, &generatedj);
422
423 CHECK(group[i].infinity == 0);
424 CHECK(generated.infinity == 0);
425 CHECK(secp256k1_fe_equal_var(&generated.x, &group[i].x));
426 CHECK(secp256k1_fe_equal_var(&generated.y, &group[i].y));
427 }
428 }
429
430 /* Run the tests */
432 test_exhaustive_addition(group, groupj);
433 test_exhaustive_ecmult(group, groupj);
437
438#ifdef ENABLE_MODULE_RECOVERY
440#endif
441#ifdef ENABLE_MODULE_EXTRAKEYS
443#endif
444#ifdef ENABLE_MODULE_SCHNORRSIG
446#endif
447
449 }
450
452
453 printf("no problems found\n");
454 return 0;
455}
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 void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q, int bits)
Multiply: R = q*A (in constant-time) Here bits should be set to the maximum bitlength of the absolute...
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 void secp256k1_fe_normalize_weak(secp256k1_fe *r)
Weakly normalize a field element: reduce its magnitude to 1, but don't fully normalize.
static int secp256k1_fe_equal_var(const secp256k1_fe *a, const secp256k1_fe *b)
Same as secp256k1_fe_equal, but may be variable time.
static void secp256k1_fe_inv(secp256k1_fe *r, const secp256k1_fe *a)
Sets a field element to be the (modular) inverse of another.
static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe *SECP256K1_RESTRICT b)
Sets a field element to be the product of two others.
static int secp256k1_fe_set_b32(secp256k1_fe *r, const unsigned char *a)
Set a field element equal to 32-byte big endian value.
static void secp256k1_fe_sqr(secp256k1_fe *r, const secp256k1_fe *a)
Sets a field element to be the square of another.
static void secp256k1_fe_normalize(secp256k1_fe *r)
Normalize a field element.
static void secp256k1_fe_get_b32(unsigned char *r, const secp256k1_fe *a)
Convert a field element to a 32-byte big endian value.
static void secp256k1_gej_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:62
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:523
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 CHECK(cond)
Definition: util.h:81
static void secp256k1_ecdsa_signature_save(secp256k1_ecdsa_signature *sig, const secp256k1_scalar *r, const secp256k1_scalar *s)
Definition: secp256k1.c:345
static void secp256k1_pubkey_save(secp256k1_pubkey *pubkey, secp256k1_ge *ge)
Definition: secp256k1.c:250
static void secp256k1_ecdsa_signature_load(const secp256k1_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, const secp256k1_ecdsa_signature *sig)
Definition: secp256k1.c:331
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:176
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:743
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:137
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:550
#define SECP256K1_CONTEXT_NONE
Context flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size,...
Definition: secp256k1.h:203
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:436
#define SECP256K1_INLINE
Definition: secp256k1.h:131
secp256k1_scalar * sc
Definition: tests.c:4349
secp256k1_ge * pt
Definition: tests.c:4350
secp256k1_callback error_callback
Definition: secp256k1.c:66
secp256k1_ecmult_gen_context ecmult_gen_ctx
Definition: secp256k1.c:64
Opaque data structured that holds a parsed ECDSA signature.
Definition: secp256k1.h:87
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:74
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.
void test_exhaustive_ecmult_multi(const secp256k1_context *ctx, const secp256k1_ge *group)
void test_exhaustive_ecmult(const secp256k1_ge *group, const secp256k1_gej *groupj)
void test_exhaustive_sign(const secp256k1_context *ctx, const secp256k1_ge *group)
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)
static uint32_t this_core
static SECP256K1_INLINE int skip_section(uint64_t *iter)
int main(int argc, char **argv)
void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b)
stolen from tests.c
void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b)
void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int *overflow)
void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *groupj)
void test_exhaustive_verify(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)
void test_exhaustive_endomorphism(const secp256k1_ge *group)
static int count
void random_fe(secp256k1_fe *x)
#define EXHAUSTIVE_TEST_ORDER