@@ -66,6 +66,15 @@ void random_fe(secp256k1_fe *x) {
6666}
6767/** END stolen from tests.c */
6868
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+
6978int secp256k1_nonce_function_smallint (unsigned char * nonce32 , const unsigned char * msg32 ,
7079 const unsigned char * key32 , const unsigned char * algo16 ,
7180 void * data , unsigned int attempt ) {
@@ -99,6 +108,7 @@ void test_exhaustive_endomorphism(const secp256k1_ge *group) {
99108
100109void test_exhaustive_addition (const secp256k1_ge * group , const secp256k1_gej * groupj ) {
101110 int i , j ;
111+ uint64_t iter = 0 ;
102112
103113 /* Sanity-check (and check infinity functions) */
104114 CHECK (secp256k1_ge_is_infinity (& group [0 ]));
@@ -111,6 +121,7 @@ void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *gr
111121 /* Check all addition formulae */
112122 for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
113123 secp256k1_fe fe_inv ;
124+ if (skip_section (& iter )) continue ;
114125 secp256k1_fe_inv (& fe_inv , & groupj [j ].z );
115126 for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
116127 secp256k1_ge zless_gej ;
@@ -157,8 +168,10 @@ void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *gr
157168
158169void test_exhaustive_ecmult (const secp256k1_context * ctx , const secp256k1_ge * group , const secp256k1_gej * groupj ) {
159170 int i , j , r_log ;
171+ uint64_t iter = 0 ;
160172 for (r_log = 1 ; r_log < EXHAUSTIVE_TEST_ORDER ; r_log ++ ) {
161173 for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
174+ if (skip_section (& iter )) continue ;
162175 for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
163176 secp256k1_gej tmp ;
164177 secp256k1_scalar na , ng ;
@@ -191,11 +204,13 @@ static int ecmult_multi_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t
191204
192205void test_exhaustive_ecmult_multi (const secp256k1_context * ctx , const secp256k1_ge * group ) {
193206 int i , j , k , x , y ;
207+ uint64_t iter = 0 ;
194208 secp256k1_scratch * scratch = secp256k1_scratch_create (& ctx -> error_callback , 4096 );
195209 for (i = 0 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) {
196210 for (j = 0 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) {
197211 for (k = 0 ; k < EXHAUSTIVE_TEST_ORDER ; k ++ ) {
198212 for (x = 0 ; x < EXHAUSTIVE_TEST_ORDER ; x ++ ) {
213+ if (skip_section (& iter )) continue ;
199214 for (y = 0 ; y < EXHAUSTIVE_TEST_ORDER ; y ++ ) {
200215 secp256k1_gej tmp ;
201216 secp256k1_scalar g_sc ;
@@ -229,6 +244,7 @@ void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* overfl
229244
230245void test_exhaustive_verify (const secp256k1_context * ctx , const secp256k1_ge * group ) {
231246 int s , r , msg , key ;
247+ uint64_t iter = 0 ;
232248 for (s = 1 ; s < EXHAUSTIVE_TEST_ORDER ; s ++ ) {
233249 for (r = 1 ; r < EXHAUSTIVE_TEST_ORDER ; r ++ ) {
234250 for (msg = 1 ; msg < EXHAUSTIVE_TEST_ORDER ; msg ++ ) {
@@ -241,6 +257,8 @@ void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *gr
241257 int k , should_verify ;
242258 unsigned char msg32 [32 ];
243259
260+ if (skip_section (& iter )) continue ;
261+
244262 secp256k1_scalar_set_int (& s_s , s );
245263 secp256k1_scalar_set_int (& r_s , r );
246264 secp256k1_scalar_set_int (& msg_s , msg );
@@ -279,10 +297,12 @@ void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *gr
279297
280298void test_exhaustive_sign (const secp256k1_context * ctx , const secp256k1_ge * group ) {
281299 int i , j , k ;
300+ uint64_t iter = 0 ;
282301
283302 /* Loop */
284303 for (i = 1 ; i < EXHAUSTIVE_TEST_ORDER ; i ++ ) { /* message */
285304 for (j = 1 ; j < EXHAUSTIVE_TEST_ORDER ; j ++ ) { /* key */
305+ if (skip_section (& iter )) continue ;
286306 for (k = 1 ; k < EXHAUSTIVE_TEST_ORDER ; k ++ ) { /* nonce */
287307 const int starting_k = k ;
288308 secp256k1_ecdsa_signature sig ;
@@ -344,6 +364,17 @@ int main(int argc, char** argv) {
344364 /* find random seed */
345365 secp256k1_rand_init (argc > 2 ? argv [2 ] : NULL );
346366
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+
347378 while (count -- ) {
348379 /* Build context */
349380 ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
0 commit comments