@@ -66,6 +66,15 @@ void random_fe(secp256k1_fe *x) {
66
66
}
67
67
/** END stolen from tests.c */
68
68
69
+ static uint32_t num_cores = 1 ;
70
+ static uint32_t this_core = 0 ;
71
+
72
+ SECP256K1_INLINE static int skip_section (uint64_t * iter ) {
73
+ if (num_cores == 1 ) return 0 ;
74
+ * iter += 0xe7037ed1a0b428dbULL ;
75
+ return ((((uint32_t )* iter ^ (* iter >> 32 )) * num_cores ) >> 32 ) != this_core ;
76
+ }
77
+
69
78
int secp256k1_nonce_function_smallint (unsigned char * nonce32 , const unsigned char * msg32 ,
70
79
const unsigned char * key32 , const unsigned char * algo16 ,
71
80
void * data , unsigned int attempt ) {
@@ -99,6 +108,7 @@ void test_exhaustive_endomorphism(const secp256k1_ge *group) {
99
108
100
109
void test_exhaustive_addition (const secp256k1_ge * group , const secp256k1_gej * groupj ) {
101
110
int i , j ;
111
+ uint64_t iter = 0 ;
102
112
103
113
/* Sanity-check (and check infinity functions) */
104
114
CHECK (secp256k1_ge_is_infinity (& group [0 ]));
@@ -111,6 +121,7 @@ void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *gr
111
121
/* Check all addition formulae */
112
122
for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
113
123
secp256k1_fe fe_inv ;
124
+ if (skip_section (& iter )) continue ;
114
125
secp256k1_fe_inv (& fe_inv , & groupj [j ].z );
115
126
for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
116
127
secp256k1_ge zless_gej ;
@@ -157,8 +168,10 @@ void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *gr
157
168
158
169
void test_exhaustive_ecmult (const secp256k1_context * ctx , const secp256k1_ge * group , const secp256k1_gej * groupj ) {
159
170
int i , j , r_log ;
171
+ uint64_t iter = 0 ;
160
172
for (r_log = 1 ; r_log < EXHAUSTIVE_TEST_ORDER ; r_log ++ ) {
161
173
for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
174
+ if (skip_section (& iter )) continue ;
162
175
for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
163
176
secp256k1_gej tmp ;
164
177
secp256k1_scalar na , ng ;
@@ -191,11 +204,13 @@ static int ecmult_multi_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t
191
204
192
205
void test_exhaustive_ecmult_multi (const secp256k1_context * ctx , const secp256k1_ge * group ) {
193
206
int i , j , k , x , y ;
207
+ uint64_t iter = 0 ;
194
208
secp256k1_scratch * scratch = secp256k1_scratch_create (& ctx -> error_callback , 4096 );
195
209
for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
196
210
for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
197
211
for (k = 0 ; k < EXHAUSTIVE_TEST_ORDER ; k ++ ) {
198
212
for (x = 0 ; x < EXHAUSTIVE_TEST_ORDER ; x ++ ) {
213
+ if (skip_section (& iter )) continue ;
199
214
for (y = 0 ; y < EXHAUSTIVE_TEST_ORDER ; y ++ ) {
200
215
secp256k1_gej tmp ;
201
216
secp256k1_scalar g_sc ;
@@ -229,6 +244,7 @@ void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* overfl
229
244
230
245
void test_exhaustive_verify (const secp256k1_context * ctx , const secp256k1_ge * group ) {
231
246
int s , r , msg , key ;
247
+ uint64_t iter = 0 ;
232
248
for (s = 1 ; s < EXHAUSTIVE_TEST_ORDER ; s ++ ) {
233
249
for (r = 1 ; r < EXHAUSTIVE_TEST_ORDER ; r ++ ) {
234
250
for (msg = 1 ; msg < EXHAUSTIVE_TEST_ORDER ; msg ++ ) {
@@ -241,6 +257,8 @@ void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *gr
241
257
int k , should_verify ;
242
258
unsigned char msg32 [32 ];
243
259
260
+ if (skip_section (& iter )) continue ;
261
+
244
262
secp256k1_scalar_set_int (& s_s , s );
245
263
secp256k1_scalar_set_int (& r_s , r );
246
264
secp256k1_scalar_set_int (& msg_s , msg );
@@ -279,10 +297,12 @@ void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *gr
279
297
280
298
void test_exhaustive_sign (const secp256k1_context * ctx , const secp256k1_ge * group ) {
281
299
int i , j , k ;
300
+ uint64_t iter = 0 ;
282
301
283
302
/* Loop */
284
303
for (i = 1 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) { /* message */
285
304
for (j = 1 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) { /* key */
305
+ if (skip_section (& iter )) continue ;
286
306
for (k = 1 ; k < EXHAUSTIVE_TEST_ORDER ; k ++ ) { /* nonce */
287
307
const int starting_k = k ;
288
308
secp256k1_ecdsa_signature sig ;
@@ -344,6 +364,17 @@ int main(int argc, char** argv) {
344
364
/* find random seed */
345
365
secp256k1_rand_init (argc > 2 ? argv [2 ] : NULL );
346
366
367
+ /* set up split processing */
368
+ if (argc > 4 ) {
369
+ num_cores = strtol (argv [3 ], NULL , 0 );
370
+ this_core = strtol (argv [4 ], NULL , 0 );
371
+ if (num_cores < 1 || this_core >= num_cores ) {
372
+ fprintf (stderr , "Usage: %s [count] [seed] [numcores] [thiscore]\n" , argv [0 ]);
373
+ return 1 ;
374
+ }
375
+ printf ("running tests for core %lu (out of [0..%lu])\n" , (unsigned long )this_core , (unsigned long )num_cores - 1 );
376
+ }
377
+
347
378
while (count -- ) {
348
379
/* Build context */
349
380
ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
0 commit comments