Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/tests_exhaustive.c
Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | for (r_log = 1; r_log < order; r_log++) { | ||||
secp256k1_ecmult_const(&tmp, &group[i], &ng); | secp256k1_ecmult_const(&tmp, &group[i], &ng); | ||||
ge_equals_gej(&group[(i * j) % order], &tmp); | ge_equals_gej(&group[(i * j) % order], &tmp); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
typedef struct { | |||||
secp256k1_scalar sc[2]; | |||||
secp256k1_ge pt[2]; | |||||
} ecmult_multi_data; | |||||
static int ecmult_multi_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *cbdata) { | |||||
ecmult_multi_data *data = (ecmult_multi_data*) cbdata; | |||||
*sc = data->sc[idx]; | |||||
*pt = data->pt[idx]; | |||||
return 1; | |||||
} | |||||
void test_exhaustive_ecmult_multi(const secp256k1_context *ctx, const secp256k1_ge *group, int order) { | |||||
int i, j, k, x, y; | |||||
secp256k1_scratch *scratch = secp256k1_scratch_create(&ctx->error_callback, 1024, 4096); | |||||
for (i = 0; i < order; i++) { | |||||
for (j = 0; j < order; j++) { | |||||
for (k = 0; k < order; k++) { | |||||
for (x = 0; x < order; x++) { | |||||
for (y = 0; y < order; y++) { | |||||
secp256k1_gej tmp; | |||||
secp256k1_scalar g_sc; | |||||
ecmult_multi_data data; | |||||
secp256k1_scalar_set_int(&data.sc[0], i); | |||||
secp256k1_scalar_set_int(&data.sc[1], j); | |||||
secp256k1_scalar_set_int(&g_sc, k); | |||||
data.pt[0] = group[x]; | |||||
data.pt[1] = group[y]; | |||||
secp256k1_ecmult_multi_var(&ctx->ecmult_ctx, scratch, &tmp, &g_sc, ecmult_multi_callback, &data, 2); | |||||
ge_equals_gej(&group[(i * x + j * y + k) % order], &tmp); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
secp256k1_scratch_destroy(scratch); | |||||
} | |||||
void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k) { | void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k) { | ||||
secp256k1_fe x; | secp256k1_fe x; | ||||
unsigned char x_bin[32]; | unsigned char x_bin[32]; | ||||
k %= EXHAUSTIVE_TEST_ORDER; | k %= EXHAUSTIVE_TEST_ORDER; | ||||
x = group[k].x; | x = group[k].x; | ||||
secp256k1_fe_normalize(&x); | secp256k1_fe_normalize(&x); | ||||
secp256k1_fe_get_b32(x_bin, &x); | secp256k1_fe_get_b32(x_bin, &x); | ||||
secp256k1_scalar_set_b32(r, x_bin, NULL); | secp256k1_scalar_set_b32(r, x_bin, NULL); | ||||
▲ Show 20 Lines • Show All 258 Lines • ▼ Show 20 Lines | int main(void) { | ||||
} | } | ||||
/* Run the tests */ | /* Run the tests */ | ||||
#ifdef USE_ENDOMORPHISM | #ifdef USE_ENDOMORPHISM | ||||
test_exhaustive_endomorphism(group, EXHAUSTIVE_TEST_ORDER); | test_exhaustive_endomorphism(group, EXHAUSTIVE_TEST_ORDER); | ||||
#endif | #endif | ||||
test_exhaustive_addition(group, groupj, EXHAUSTIVE_TEST_ORDER); | test_exhaustive_addition(group, groupj, EXHAUSTIVE_TEST_ORDER); | ||||
test_exhaustive_ecmult(ctx, group, groupj, EXHAUSTIVE_TEST_ORDER); | test_exhaustive_ecmult(ctx, group, groupj, EXHAUSTIVE_TEST_ORDER); | ||||
test_exhaustive_ecmult_multi(ctx, group, EXHAUSTIVE_TEST_ORDER); | |||||
test_exhaustive_sign(ctx, group, EXHAUSTIVE_TEST_ORDER); | test_exhaustive_sign(ctx, group, EXHAUSTIVE_TEST_ORDER); | ||||
test_exhaustive_verify(ctx, group, EXHAUSTIVE_TEST_ORDER); | test_exhaustive_verify(ctx, group, EXHAUSTIVE_TEST_ORDER); | ||||
#ifdef ENABLE_MODULE_RECOVERY | #ifdef ENABLE_MODULE_RECOVERY | ||||
test_exhaustive_recovery_sign(ctx, group, EXHAUSTIVE_TEST_ORDER); | test_exhaustive_recovery_sign(ctx, group, EXHAUSTIVE_TEST_ORDER); | ||||
test_exhaustive_recovery_verify(ctx, group, EXHAUSTIVE_TEST_ORDER); | test_exhaustive_recovery_verify(ctx, group, EXHAUSTIVE_TEST_ORDER); | ||||
#endif | #endif | ||||
secp256k1_context_destroy(ctx); | secp256k1_context_destroy(ctx); | ||||
return 0; | return 0; | ||||
} | } | ||||