@@ -64,6 +64,15 @@ void random_fe(secp256k1_fe *x) {
6464}
6565/** END stolen from tests.c */
6666
67+ static uint32_t num_cores = 1 ;
68+ static uint32_t this_core = 0 ;
69+
70+ SECP256K1_INLINE static int skip_section (uint64_t iter ) {
71+ if (num_cores == 1 ) return 0 ;
72+ iter *= 0xe7037ed1a0b428dbULL ;
73+ return ((((uint32_t )iter ^ (iter >> 32 )) * num_cores ) >> 32 ) != this_core ;
74+ }
75+
6776int secp256k1_nonce_function_smallint (unsigned char * nonce32 , const unsigned char * msg32 ,
6877 const unsigned char * key32 , const unsigned char * algo16 ,
6978 void * data , unsigned int attempt ) {
@@ -109,6 +118,7 @@ void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *gr
109118 /* Check all addition formulae */
110119 for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
111120 secp256k1_fe fe_inv ;
121+ if (skip_section (j )) continue ;
112122 secp256k1_fe_inv (& fe_inv , & groupj [j ].z );
113123 for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
114124 secp256k1_ge zless_gej ;
@@ -155,8 +165,10 @@ void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *gr
155165
156166void test_exhaustive_ecmult (const secp256k1_context * ctx , const secp256k1_ge * group , const secp256k1_gej * groupj ) {
157167 int i , j , r_log ;
168+ uint64_t iter = 0 ;
158169 for (r_log = 1 ; r_log < EXHAUSTIVE_TEST_ORDER ; r_log ++ ) {
159170 for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
171+ if (skip_section (iter ++ )) continue ;
160172 for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
161173 secp256k1_gej tmp ;
162174 secp256k1_scalar na , ng ;
@@ -189,11 +201,13 @@ static int ecmult_multi_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t
189201
190202void test_exhaustive_ecmult_multi (const secp256k1_context * ctx , const secp256k1_ge * group ) {
191203 int i , j , k , x , y ;
204+ uint64_t iter = 0 ;
192205 secp256k1_scratch * scratch = secp256k1_scratch_create (& ctx -> error_callback , 4096 );
193206 for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
194207 for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
195208 for (k = 0 ; k < EXHAUSTIVE_TEST_ORDER ; k ++ ) {
196209 for (x = 0 ; x < EXHAUSTIVE_TEST_ORDER ; x ++ ) {
210+ if (skip_section (iter ++ )) continue ;
197211 for (y = 0 ; y < EXHAUSTIVE_TEST_ORDER ; y ++ ) {
198212 secp256k1_gej tmp ;
199213 secp256k1_scalar g_sc ;
@@ -227,6 +241,7 @@ void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* overfl
227241
228242void test_exhaustive_verify (const secp256k1_context * ctx , const secp256k1_ge * group ) {
229243 int s , r , msg , key ;
244+ uint64_t iter = 0 ;
230245 for (s = 1 ; s < EXHAUSTIVE_TEST_ORDER ; s ++ ) {
231246 for (r = 1 ; r < EXHAUSTIVE_TEST_ORDER ; r ++ ) {
232247 for (msg = 1 ; msg < EXHAUSTIVE_TEST_ORDER ; msg ++ ) {
@@ -239,6 +254,8 @@ void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *gr
239254 int k , should_verify ;
240255 unsigned char msg32 [32 ];
241256
257+ if (skip_section (iter ++ )) continue ;
258+
242259 secp256k1_scalar_set_int (& s_s , s );
243260 secp256k1_scalar_set_int (& r_s , r );
244261 secp256k1_scalar_set_int (& msg_s , msg );
@@ -277,10 +294,12 @@ void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *gr
277294
278295void test_exhaustive_sign (const secp256k1_context * ctx , const secp256k1_ge * group ) {
279296 int i , j , k ;
297+ uint64_t iter = 0 ;
280298
281299 /* Loop */
282300 for (i = 1 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) { /* message */
283301 for (j = 1 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) { /* key */
302+ if (skip_section (iter ++ )) continue ;
284303 for (k = 1 ; k < EXHAUSTIVE_TEST_ORDER ; k ++ ) { /* nonce */
285304 const int starting_k = k ;
286305 secp256k1_ecdsa_signature sig ;
@@ -341,6 +360,17 @@ int main(int argc, char** argv) {
341360 /* find random seed */
342361 secp256k1_rand_init (argc > 2 ? argv [2 ] : NULL );
343362
363+ /* set up split processing */
364+ if (argc > 4 ) {
365+ num_cores = strtol (argv [3 ], NULL , 0 );
366+ this_core = strtol (argv [4 ], NULL , 0 );
367+ if (num_cores < 1 || this_core >= num_cores ) {
368+ fprintf (stderr , "Usage: %s [count] [seed] [numcores] [thiscore]" , argv [0 ]);
369+ return 1 ;
370+ }
371+ printf ("running tests for core %lu out of %lu\n" , (unsigned long )this_core , (unsigned long )num_cores );
372+ }
373+
344374 while (count -- ) {
345375 /* Build context */
346376 ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
0 commit comments