Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/tests_exhaustive.c
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b) { | ||||
s2 = b->y; secp256k1_fe_normalize_weak(&s2); | s2 = b->y; secp256k1_fe_normalize_weak(&s2); | ||||
CHECK(secp256k1_fe_equal_var(&u1, &u2)); | CHECK(secp256k1_fe_equal_var(&u1, &u2)); | ||||
CHECK(secp256k1_fe_equal_var(&s1, &s2)); | CHECK(secp256k1_fe_equal_var(&s1, &s2)); | ||||
} | } | ||||
void random_fe(secp256k1_fe *x) { | void random_fe(secp256k1_fe *x) { | ||||
unsigned char bin[32]; | unsigned char bin[32]; | ||||
do { | do { | ||||
secp256k1_rand256(bin); | secp256k1_testrand256(bin); | ||||
if (secp256k1_fe_set_b32(x, bin)) { | if (secp256k1_fe_set_b32(x, bin)) { | ||||
return; | return; | ||||
} | } | ||||
} while(1); | } while(1); | ||||
} | } | ||||
/** END stolen from tests.c */ | /** END stolen from tests.c */ | ||||
static uint32_t num_cores = 1; | static uint32_t num_cores = 1; | ||||
▲ Show 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | int main(int argc, char** argv) { | ||||
/* find iteration count */ | /* find iteration count */ | ||||
if (argc > 1) { | if (argc > 1) { | ||||
count = strtol(argv[1], NULL, 0); | count = strtol(argv[1], NULL, 0); | ||||
} | } | ||||
printf("test count = %i\n", count); | printf("test count = %i\n", count); | ||||
/* find random seed */ | /* find random seed */ | ||||
secp256k1_rand_init(argc > 2 ? argv[2] : NULL); | secp256k1_testrand_init(argc > 2 ? argv[2] : NULL); | ||||
/* set up split processing */ | /* set up split processing */ | ||||
if (argc > 4) { | if (argc > 4) { | ||||
num_cores = strtol(argv[3], NULL, 0); | num_cores = strtol(argv[3], NULL, 0); | ||||
this_core = strtol(argv[4], NULL, 0); | this_core = strtol(argv[4], NULL, 0); | ||||
if (num_cores < 1 || this_core >= num_cores) { | if (num_cores < 1 || this_core >= num_cores) { | ||||
fprintf(stderr, "Usage: %s [count] [seed] [numcores] [thiscore]\n", argv[0]); | fprintf(stderr, "Usage: %s [count] [seed] [numcores] [thiscore]\n", argv[0]); | ||||
return 1; | return 1; | ||||
} | } | ||||
printf("running tests for core %lu (out of [0..%lu])\n", (unsigned long)this_core, (unsigned long)num_cores - 1); | printf("running tests for core %lu (out of [0..%lu])\n", (unsigned long)this_core, (unsigned long)num_cores - 1); | ||||
} | } | ||||
while (count--) { | while (count--) { | ||||
/* Build context */ | /* Build context */ | ||||
ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); | ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); | ||||
secp256k1_rand256(rand32); | secp256k1_testrand256(rand32); | ||||
CHECK(secp256k1_context_randomize(ctx, rand32)); | CHECK(secp256k1_context_randomize(ctx, rand32)); | ||||
/* Generate the entire group */ | /* Generate the entire group */ | ||||
secp256k1_gej_set_infinity(&groupj[0]); | secp256k1_gej_set_infinity(&groupj[0]); | ||||
secp256k1_ge_set_gej(&group[0], &groupj[0]); | secp256k1_ge_set_gej(&group[0], &groupj[0]); | ||||
for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { | for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { | ||||
secp256k1_gej_add_ge(&groupj[i], &groupj[i - 1], &secp256k1_ge_const_g); | secp256k1_gej_add_ge(&groupj[i], &groupj[i - 1], &secp256k1_ge_const_g); | ||||
secp256k1_ge_set_gej(&group[i], &groupj[i]); | secp256k1_ge_set_gej(&group[i], &groupj[i]); | ||||
Show All 40 Lines | |||||
#endif | #endif | ||||
#ifdef ENABLE_MODULE_SCHNORRSIG | #ifdef ENABLE_MODULE_SCHNORRSIG | ||||
test_exhaustive_schnorrsig(ctx); | test_exhaustive_schnorrsig(ctx); | ||||
#endif | #endif | ||||
secp256k1_context_destroy(ctx); | secp256k1_context_destroy(ctx); | ||||
} | } | ||||
secp256k1_rand_finish(); | secp256k1_testrand_finish(); | ||||
printf("no problems found\n"); | printf("no problems found\n"); | ||||
return 0; | return 0; | ||||
} | } |