Bitcoin Core 22.99.0
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#if defined HAVE_CONFIG_H
9#endif
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <time.h>
14
15#undef USE_ECMULT_STATIC_PRECOMPUTATION
16
17#ifndef EXHAUSTIVE_TEST_ORDER
18/* see group_impl.h for allowable values */
19#define EXHAUSTIVE_TEST_ORDER 13
20#endif
21
22#include "secp256k1.c"
23#include "../include/secp256k1.h"
24#include "assumptions.h"
25#include "group.h"
26#include "testrand_impl.h"
27
28static int count = 2;
29
31void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b) {
32 CHECK(a->infinity == b->infinity);
33 if (a->infinity) {
34 return;
35 }
38}
39
40void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b) {
41 secp256k1_fe z2s;
42 secp256k1_fe u1, u2, s1, s2;
43 CHECK(a->infinity == b->infinity);
44 if (a->infinity) {
45 return;
46 }
47 /* Check a.x * b.z^2 == b.x && a.y * b.z^3 == b.y, to avoid inverses. */
48 secp256k1_fe_sqr(&z2s, &b->z);
49 secp256k1_fe_mul(&u1, &a->x, &z2s);
50 u2 = b->x; secp256k1_fe_normalize_weak(&u2);
51 secp256k1_fe_mul(&s1, &a->y, &z2s); secp256k1_fe_mul(&s1, &s1, &b->z);
52 s2 = b->y; secp256k1_fe_normalize_weak(&s2);
55}
56
58 unsigned char bin[32];
59 do {
61 if (secp256k1_fe_set_b32(x, bin)) {
62 return;
63 }
64 } while(1);
65}
68static uint32_t num_cores = 1;
69static uint32_t this_core = 0;
70
71SECP256K1_INLINE static int skip_section(uint64_t* iter) {
72 if (num_cores == 1) return 0;
73 *iter += 0xe7037ed1a0b428dbULL;
74 return ((((uint32_t)*iter ^ (*iter >> 32)) * num_cores) >> 32) != this_core;
75}
76
77int secp256k1_nonce_function_smallint(unsigned char *nonce32, const unsigned char *msg32,
78 const unsigned char *key32, const unsigned char *algo16,
79 void *data, unsigned int attempt) {
81 int *idata = data;
82 (void)msg32;
83 (void)key32;
84 (void)algo16;
85 /* Some nonces cannot be used because they'd cause s and/or r to be zero.
86 * The signing function has retry logic here that just re-calls the nonce
87 * function with an increased `attempt`. So if attempt > 0 this means we
88 * need to change the nonce to avoid an infinite loop. */
89 if (attempt > 0) {
90 *idata = (*idata + 1) % EXHAUSTIVE_TEST_ORDER;
91 }
92 secp256k1_scalar_set_int(&s, *idata);
93 secp256k1_scalar_get_b32(nonce32, &s);
94 return 1;
95}
96
98 int i;
99 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
100 secp256k1_ge res;
101 secp256k1_ge_mul_lambda(&res, &group[i]);
102 ge_equals_ge(&group[i * EXHAUSTIVE_TEST_LAMBDA % EXHAUSTIVE_TEST_ORDER], &res);
103 }
104}
105
106void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *groupj) {
107 int i, j;
108 uint64_t iter = 0;
109
110 /* Sanity-check (and check infinity functions) */
112 CHECK(secp256k1_gej_is_infinity(&groupj[0]));
113 for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) {
114 CHECK(!secp256k1_ge_is_infinity(&group[i]));
115 CHECK(!secp256k1_gej_is_infinity(&groupj[i]));
116 }
117
118 /* Check all addition formulae */
119 for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) {
120 secp256k1_fe fe_inv;
121 if (skip_section(&iter)) continue;
122 secp256k1_fe_inv(&fe_inv, &groupj[j].z);
123 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
124 secp256k1_ge zless_gej;
125 secp256k1_gej tmp;
126 /* add_var */
127 secp256k1_gej_add_var(&tmp, &groupj[i], &groupj[j], NULL);
128 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
129 /* add_ge */
130 if (j > 0) {
131 secp256k1_gej_add_ge(&tmp, &groupj[i], &group[j]);
132 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
133 }
134 /* add_ge_var */
135 secp256k1_gej_add_ge_var(&tmp, &groupj[i], &group[j], NULL);
136 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
137 /* add_zinv_var */
138 zless_gej.infinity = groupj[j].infinity;
139 zless_gej.x = groupj[j].x;
140 zless_gej.y = groupj[j].y;
141 secp256k1_gej_add_zinv_var(&tmp, &groupj[i], &zless_gej, &fe_inv);
142 ge_equals_gej(&group[(i + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
143 }
144 }
145
146 /* Check doubling */
147 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
148 secp256k1_gej tmp;
149 secp256k1_gej_double(&tmp, &groupj[i]);
150 ge_equals_gej(&group[(2 * i) % EXHAUSTIVE_TEST_ORDER], &tmp);
151 secp256k1_gej_double_var(&tmp, &groupj[i], NULL);
152 ge_equals_gej(&group[(2 * i) % EXHAUSTIVE_TEST_ORDER], &tmp);
153 }
154
155 /* Check negation */
156 for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) {
157 secp256k1_ge tmp;
158 secp256k1_gej tmpj;
159 secp256k1_ge_neg(&tmp, &group[i]);
160 ge_equals_ge(&group[EXHAUSTIVE_TEST_ORDER - i], &tmp);
161 secp256k1_gej_neg(&tmpj, &groupj[i]);
162 ge_equals_gej(&group[EXHAUSTIVE_TEST_ORDER - i], &tmpj);
163 }
164}
165
166void test_exhaustive_ecmult(const secp256k1_context *ctx, const secp256k1_ge *group, const secp256k1_gej *groupj) {
167 int i, j, r_log;
168 uint64_t iter = 0;
169 for (r_log = 1; r_log < EXHAUSTIVE_TEST_ORDER; r_log++) {
170 for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) {
171 if (skip_section(&iter)) continue;
172 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
173 secp256k1_gej tmp;
174 secp256k1_scalar na, ng;
177
178 secp256k1_ecmult(&ctx->ecmult_ctx, &tmp, &groupj[r_log], &na, &ng);
179 ge_equals_gej(&group[(i * r_log + j) % EXHAUSTIVE_TEST_ORDER], &tmp);
180
181 if (i > 0) {
182 secp256k1_ecmult_const(&tmp, &group[i], &ng, 256);
183 ge_equals_gej(&group[(i * j) % EXHAUSTIVE_TEST_ORDER], &tmp);
184 }
185 }
186 }
187 }
188}
189
190typedef struct {
194
195static int ecmult_multi_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *cbdata) {
196 ecmult_multi_data *data = (ecmult_multi_data*) cbdata;
197 *sc = data->sc[idx];
198 *pt = data->pt[idx];
199 return 1;
200}
201
203 int i, j, k, x, y;
204 uint64_t iter = 0;
206 for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) {
207 for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) {
208 for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) {
209 for (x = 0; x < EXHAUSTIVE_TEST_ORDER; x++) {
210 if (skip_section(&iter)) continue;
211 for (y = 0; y < EXHAUSTIVE_TEST_ORDER; y++) {
212 secp256k1_gej tmp;
213 secp256k1_scalar g_sc;
215
216 secp256k1_scalar_set_int(&data.sc[0], i);
217 secp256k1_scalar_set_int(&data.sc[1], j);
218 secp256k1_scalar_set_int(&g_sc, k);
219 data.pt[0] = group[x];
220 data.pt[1] = group[y];
221
223 ge_equals_gej(&group[(i * x + j * y + k) % EXHAUSTIVE_TEST_ORDER], &tmp);
224 }
225 }
226 }
227 }
228 }
230}
231
232void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* overflow) {
233 secp256k1_fe x;
234 unsigned char x_bin[32];
236 x = group[k].x;
238 secp256k1_fe_get_b32(x_bin, &x);
239 secp256k1_scalar_set_b32(r, x_bin, overflow);
240}
241
243 int s, r, msg, key;
244 uint64_t iter = 0;
245 for (s = 1; s < EXHAUSTIVE_TEST_ORDER; s++) {
246 for (r = 1; r < EXHAUSTIVE_TEST_ORDER; r++) {
247 for (msg = 1; msg < EXHAUSTIVE_TEST_ORDER; msg++) {
248 for (key = 1; key < EXHAUSTIVE_TEST_ORDER; key++) {
249 secp256k1_ge nonconst_ge;
252 secp256k1_scalar sk_s, msg_s, r_s, s_s;
253 secp256k1_scalar s_times_k_s, msg_plus_r_times_sk_s;
254 int k, should_verify;
255 unsigned char msg32[32];
256
257 if (skip_section(&iter)) continue;
258
261 secp256k1_scalar_set_int(&msg_s, msg);
262 secp256k1_scalar_set_int(&sk_s, key);
263
264 /* Verify by hand */
265 /* Run through every k value that gives us this r and check that *one* works.
266 * Note there could be none, there could be multiple, ECDSA is weird. */
267 should_verify = 0;
268 for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) {
269 secp256k1_scalar check_x_s;
270 r_from_k(&check_x_s, group, k, NULL);
271 if (r_s == check_x_s) {
272 secp256k1_scalar_set_int(&s_times_k_s, k);
273 secp256k1_scalar_mul(&s_times_k_s, &s_times_k_s, &s_s);
274 secp256k1_scalar_mul(&msg_plus_r_times_sk_s, &r_s, &sk_s);
275 secp256k1_scalar_add(&msg_plus_r_times_sk_s, &msg_plus_r_times_sk_s, &msg_s);
276 should_verify |= secp256k1_scalar_eq(&s_times_k_s, &msg_plus_r_times_sk_s);
277 }
278 }
279 /* nb we have a "high s" rule */
280 should_verify &= !secp256k1_scalar_is_high(&s_s);
281
282 /* Verify by calling verify */
283 secp256k1_ecdsa_signature_save(&sig, &r_s, &s_s);
284 memcpy(&nonconst_ge, &group[sk_s], sizeof(nonconst_ge));
285 secp256k1_pubkey_save(&pk, &nonconst_ge);
286 secp256k1_scalar_get_b32(msg32, &msg_s);
287 CHECK(should_verify ==
288 secp256k1_ecdsa_verify(ctx, &sig, msg32, &pk));
289 }
290 }
291 }
292 }
293}
294
296 int i, j, k;
297 uint64_t iter = 0;
298
299 /* Loop */
300 for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { /* message */
301 for (j = 1; j < EXHAUSTIVE_TEST_ORDER; j++) { /* key */
302 if (skip_section(&iter)) continue;
303 for (k = 1; k < EXHAUSTIVE_TEST_ORDER; k++) { /* nonce */
304 const int starting_k = k;
305 int ret;
307 secp256k1_scalar sk, msg, r, s, expected_r;
308 unsigned char sk32[32], msg32[32];
311 secp256k1_scalar_get_b32(sk32, &sk);
312 secp256k1_scalar_get_b32(msg32, &msg);
313
314 ret = secp256k1_ecdsa_sign(ctx, &sig, msg32, sk32, secp256k1_nonce_function_smallint, &k);
315 CHECK(ret == 1);
316
317 secp256k1_ecdsa_signature_load(ctx, &r, &s, &sig);
318 /* Note that we compute expected_r *after* signing -- this is important
319 * because our nonce-computing function function might change k during
320 * signing. */
321 r_from_k(&expected_r, group, k, NULL);
322 CHECK(r == expected_r);
323 CHECK((k * s) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER ||
325
326 /* Overflow means we've tried every possible nonce */
327 if (k < starting_k) {
328 break;
329 }
330 }
331 }
332 }
333
334 /* We would like to verify zero-knowledge here by counting how often every
335 * possible (s, r) tuple appears, but because the group order is larger
336 * than the field order, when coercing the x-values to scalar values, some
337 * appear more often than others, so we are actually not zero-knowledge.
338 * (This effect also appears in the real code, but the difference is on the
339 * order of 1/2^128th the field order, so the deviation is not useful to a
340 * computationally bounded attacker.)
341 */
342}
343
344#ifdef ENABLE_MODULE_RECOVERY
346#endif
347
348#ifdef ENABLE_MODULE_EXTRAKEYS
350#endif
351
352#ifdef ENABLE_MODULE_SCHNORRSIG
354#endif
355
356int main(int argc, char** argv) {
357 int i;
360 unsigned char rand32[32];
362
363 /* Disable buffering for stdout to improve reliability of getting
364 * diagnostic information. Happens right at the start of main because
365 * setbuf must be used before any other operation on the stream. */
366 setbuf(stdout, NULL);
367 /* Also disable buffering for stderr because it's not guaranteed that it's
368 * unbuffered on all systems. */
369 setbuf(stderr, NULL);
370
371 printf("Exhaustive tests for order %lu\n", (unsigned long)EXHAUSTIVE_TEST_ORDER);
372
373 /* find iteration count */
374 if (argc > 1) {
375 count = strtol(argv[1], NULL, 0);
376 }
377 printf("test count = %i\n", count);
378
379 /* find random seed */
380 secp256k1_testrand_init(argc > 2 ? argv[2] : NULL);
381
382 /* set up split processing */
383 if (argc > 4) {
384 num_cores = strtol(argv[3], NULL, 0);
385 this_core = strtol(argv[4], NULL, 0);
386 if (num_cores < 1 || this_core >= num_cores) {
387 fprintf(stderr, "Usage: %s [count] [seed] [numcores] [thiscore]\n", argv[0]);
388 return 1;
389 }
390 printf("running tests for core %lu (out of [0..%lu])\n", (unsigned long)this_core, (unsigned long)num_cores - 1);
391 }
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(ctx, 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 void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng)
Double multiply: R = na*A + ng*G.
static int secp256k1_ecmult_multi_var(const secp256k1_callback *error_callback, const secp256k1_ecmult_context *ctx, 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_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.
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)
Field element module.
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
Generator for secp256k1, value 'g' defined in "Standards for Efficient Cryptography" (SEC2) 2....
Definition: group_impl.h:52
void printf(const char *fmt, const Args &... args)
Format list of arguments to std::cout, according to the given format string.
Definition: tinyformat.h:1079
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:53
static void secp256k1_ecdsa_signature_save(secp256k1_ecdsa_signature *sig, const secp256k1_scalar *r, const secp256k1_scalar *s)
Definition: secp256k1.c:365
static void secp256k1_pubkey_save(secp256k1_pubkey *pubkey, secp256k1_ge *ge)
Definition: secp256k1.c:270
static void secp256k1_ecdsa_signature_load(const secp256k1_context *ctx, secp256k1_scalar *r, secp256k1_scalar *s, const secp256k1_ecdsa_signature *sig)
Definition: secp256k1.c:351
#define SECP256K1_CONTEXT_SIGN
Definition: secp256k1.h:185
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_context_randomize(secp256k1_context *ctx, const unsigned char *seed32) SECP256K1_ARG_NONNULL(1)
Updates the context randomization to protect against side-channel leakage.
Definition: secp256k1.c:761
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:158
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:567
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:456
#define SECP256K1_INLINE
Definition: secp256k1.h:127
#define SECP256K1_CONTEXT_VERIFY
Flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size, and secp256k1_context...
Definition: secp256k1.h:184
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object (created in dynamically allocated memory).
Definition: secp256k1.c:202
secp256k1_scalar * sc
Definition: tests.c:3723
secp256k1_ge * pt
Definition: tests.c:3724
secp256k1_callback error_callback
Definition: secp256k1.c:79
secp256k1_ecmult_gen_context ecmult_gen_ctx
Definition: secp256k1.c:77
secp256k1_ecmult_context ecmult_ctx
Definition: secp256k1.c:76
Opaque data structured that holds a parsed ECDSA signature.
Definition: secp256k1.h:83
A group element of the secp256k1 curve, in affine coordinates.
Definition: group.h:13
int infinity
Definition: group.h:16
secp256k1_fe x
Definition: group.h:14
secp256k1_fe y
Definition: group.h:15
A group element of the secp256k1 curve, in jacobian coordinates.
Definition: group.h:23
secp256k1_fe y
Definition: group.h:25
secp256k1_fe x
Definition: group.h:24
int infinity
Definition: group.h:27
secp256k1_fe z
Definition: group.h:26
Opaque data structure that holds a parsed and valid public key.
Definition: secp256k1.h:70
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 secp256k1_context * ctx
Definition: tests.c:42
void test_exhaustive_ecmult_multi(const secp256k1_context *ctx, const secp256k1_ge *group)
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)
void test_exhaustive_ecmult(const secp256k1_context *ctx, const secp256k1_ge *group, const secp256k1_gej *groupj)
#define EXHAUSTIVE_TEST_ORDER