Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/tests_exhaustive.c
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | int secp256k1_nonce_function_smallint(unsigned char *nonce32, const unsigned char *msg32, | ||||
if (attempt > 0) { | if (attempt > 0) { | ||||
*idata = (*idata + 1) % EXHAUSTIVE_TEST_ORDER; | *idata = (*idata + 1) % EXHAUSTIVE_TEST_ORDER; | ||||
} | } | ||||
secp256k1_scalar_set_int(&s, *idata); | secp256k1_scalar_set_int(&s, *idata); | ||||
secp256k1_scalar_get_b32(nonce32, &s); | secp256k1_scalar_get_b32(nonce32, &s); | ||||
return 1; | return 1; | ||||
} | } | ||||
#ifdef USE_ENDOMORPHISM | |||||
void test_exhaustive_endomorphism(const secp256k1_ge *group) { | void test_exhaustive_endomorphism(const secp256k1_ge *group) { | ||||
int i; | int i; | ||||
for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { | for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { | ||||
secp256k1_ge res; | secp256k1_ge res; | ||||
secp256k1_ge_mul_lambda(&res, &group[i]); | secp256k1_ge_mul_lambda(&res, &group[i]); | ||||
ge_equals_ge(&group[i * EXHAUSTIVE_TEST_LAMBDA % EXHAUSTIVE_TEST_ORDER], &res); | ge_equals_ge(&group[i * EXHAUSTIVE_TEST_LAMBDA % EXHAUSTIVE_TEST_ORDER], &res); | ||||
} | } | ||||
} | } | ||||
#endif | |||||
void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *groupj) { | void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_gej *groupj) { | ||||
int i, j; | int i, j; | ||||
uint64_t iter = 0; | uint64_t iter = 0; | ||||
/* Sanity-check (and check infinity functions) */ | /* Sanity-check (and check infinity functions) */ | ||||
CHECK(secp256k1_ge_is_infinity(&group[0])); | CHECK(secp256k1_ge_is_infinity(&group[0])); | ||||
CHECK(secp256k1_gej_is_infinity(&groupj[0])); | CHECK(secp256k1_gej_is_infinity(&groupj[0])); | ||||
▲ Show 20 Lines • Show All 308 Lines • ▼ Show 20 Lines | while (count--) { | ||||
CHECK(group[i].infinity == 0); | CHECK(group[i].infinity == 0); | ||||
CHECK(generated.infinity == 0); | CHECK(generated.infinity == 0); | ||||
CHECK(secp256k1_fe_equal_var(&generated.x, &group[i].x)); | CHECK(secp256k1_fe_equal_var(&generated.x, &group[i].x)); | ||||
CHECK(secp256k1_fe_equal_var(&generated.y, &group[i].y)); | CHECK(secp256k1_fe_equal_var(&generated.y, &group[i].y)); | ||||
} | } | ||||
} | } | ||||
/* Run the tests */ | /* Run the tests */ | ||||
#ifdef USE_ENDOMORPHISM | |||||
test_exhaustive_endomorphism(group); | test_exhaustive_endomorphism(group); | ||||
#endif | |||||
test_exhaustive_addition(group, groupj); | test_exhaustive_addition(group, groupj); | ||||
test_exhaustive_ecmult(ctx, group, groupj); | test_exhaustive_ecmult(ctx, group, groupj); | ||||
test_exhaustive_ecmult_multi(ctx, group); | test_exhaustive_ecmult_multi(ctx, group); | ||||
test_exhaustive_sign(ctx, group); | test_exhaustive_sign(ctx, group); | ||||
test_exhaustive_verify(ctx, group); | test_exhaustive_verify(ctx, group); | ||||
#ifdef ENABLE_MODULE_RECOVERY | #ifdef ENABLE_MODULE_RECOVERY | ||||
test_exhaustive_recovery(ctx, group); | test_exhaustive_recovery(ctx, group); | ||||
Show All 16 Lines |