@@ -64,6 +64,14 @@ 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+ return ((((iter * 0xe7037ed1a0b428dbULL ) >> 32 ) * num_cores ) >> 32 ) != this_core ;
73+ }
74+
6775int secp256k1_nonce_function_smallint (unsigned char * nonce32 , const unsigned char * msg32 ,
6876 const unsigned char * key32 , const unsigned char * algo16 ,
6977 void * data , unsigned int attempt ) {
@@ -109,6 +117,7 @@ void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *gr
109117 /* Check all addition formulae */
110118 for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
111119 secp256k1_fe fe_inv ;
120+ if (skip_section (j )) continue ;
112121 secp256k1_fe_inv (& fe_inv , & groupj [j ].z );
113122 for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
114123 secp256k1_ge zless_gej ;
@@ -155,8 +164,10 @@ void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *gr
155164
156165void test_exhaustive_ecmult (const secp256k1_context * ctx , const secp256k1_ge * group , const secp256k1_gej * groupj ) {
157166 int i , j , r_log ;
167+ uint64_t iter = 0 ;
158168 for (r_log = 1 ; r_log < EXHAUSTIVE_TEST_ORDER ; r_log ++ ) {
159169 for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
170+ if (skip_section (iter ++ )) continue ;
160171 for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
161172 secp256k1_gej tmp ;
162173 secp256k1_scalar na , ng ;
@@ -189,11 +200,13 @@ static int ecmult_multi_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t
189200
190201void test_exhaustive_ecmult_multi (const secp256k1_context * ctx , const secp256k1_ge * group ) {
191202 int i , j , k , x , y ;
203+ uint64_t iter = 0 ;
192204 secp256k1_scratch * scratch = secp256k1_scratch_create (& ctx -> error_callback , 4096 );
193205 for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
194206 for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
195207 for (k = 0 ; k < EXHAUSTIVE_TEST_ORDER ; k ++ ) {
196208 for (x = 0 ; x < EXHAUSTIVE_TEST_ORDER ; x ++ ) {
209+ if (skip_section (iter ++ )) continue ;
197210 for (y = 0 ; y < EXHAUSTIVE_TEST_ORDER ; y ++ ) {
198211 secp256k1_gej tmp ;
199212 secp256k1_scalar g_sc ;
@@ -227,6 +240,7 @@ void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* overfl
227240
228241void test_exhaustive_verify (const secp256k1_context * ctx , const secp256k1_ge * group ) {
229242 int s , r , msg , key ;
243+ uint64_t iter = 0 ;
230244 for (s = 1 ; s < EXHAUSTIVE_TEST_ORDER ; s ++ ) {
231245 for (r = 1 ; r < EXHAUSTIVE_TEST_ORDER ; r ++ ) {
232246 for (msg = 1 ; msg < EXHAUSTIVE_TEST_ORDER ; msg ++ ) {
@@ -239,6 +253,8 @@ void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *gr
239253 int k , should_verify ;
240254 unsigned char msg32 [32 ];
241255
256+ if (skip_section (iter ++ )) continue ;
257+
242258 secp256k1_scalar_set_int (& s_s , s );
243259 secp256k1_scalar_set_int (& r_s , r );
244260 secp256k1_scalar_set_int (& msg_s , msg );
@@ -277,10 +293,12 @@ void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *gr
277293
278294void test_exhaustive_sign (const secp256k1_context * ctx , const secp256k1_ge * group ) {
279295 int i , j , k ;
296+ uint64_t iter = 0 ;
280297
281298 /* Loop */
282299 for (i = 1 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) { /* message */
283300 for (j = 1 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) { /* key */
301+ if (skip_section (iter ++ )) continue ;
284302 for (k = 1 ; k < EXHAUSTIVE_TEST_ORDER ; k ++ ) { /* nonce */
285303 const int starting_k = k ;
286304 secp256k1_ecdsa_signature sig ;
@@ -341,6 +359,17 @@ int main(int argc, char** argv) {
341359 /* find random seed */
342360 secp256k1_rand_init (argc > 2 ? argv [2 ] : NULL );
343361
362+ /* set up split processing */
363+ if (argc > 4 ) {
364+ num_cores = strtol (argv [3 ], NULL , 0 );
365+ this_core = strtol (argv [4 ], NULL , 0 );
366+ if (num_cores < 1 || this_core >= num_cores ) {
367+ fprintf (stderr , "Usage: %s [count] [seed] [numcores] [thiscore]" , argv [0 ]);
368+ return 1 ;
369+ }
370+ printf ("running tests for core %lu out of %lu\n" , (unsigned long )this_core , (unsigned long )num_cores );
371+ }
372+
344373 while (count -- ) {
345374 /* Build context */
346375 ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
0 commit comments