From 5106226991117da78f85ca88b7ea66c2ac8fe0b3 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Thu, 7 Oct 2021 16:54:03 +0200 Subject: [PATCH] exhaustive_tests: Fix with ecmult_gen table with custom generator --- src/gen_ecmult_gen_static_prec_table.c | 10 +++++++++- src/tests_exhaustive.c | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gen_ecmult_gen_static_prec_table.c b/src/gen_ecmult_gen_static_prec_table.c index 60eebc00499d6..3431d695582de 100644 --- a/src/gen_ecmult_gen_static_prec_table.c +++ b/src/gen_ecmult_gen_static_prec_table.c @@ -52,11 +52,18 @@ int main(int argc, char **argv) { fprintf(fp, "#ifndef SECP256K1_ECMULT_GEN_STATIC_PREC_TABLE_H\n"); fprintf(fp, "#define SECP256K1_ECMULT_GEN_STATIC_PREC_TABLE_H\n"); + fprintf(fp, "#include \"src/group.h\"\n"); + fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n"); + fprintf(fp, "#if ECMULT_GEN_PREC_N != %d || ECMULT_GEN_PREC_G != %d\n", ECMULT_GEN_PREC_N, ECMULT_GEN_PREC_G); fprintf(fp, " #error configuration mismatch, invalid ECMULT_GEN_PREC_N, ECMULT_GEN_PREC_G. Try deleting %s before the build.\n", outfile); fprintf(fp, "#endif\n"); + + fprintf(fp, "#ifdef EXHAUSTIVE_TEST_ORDER\n"); + fprintf(fp, "static secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[ECMULT_GEN_PREC_N][ECMULT_GEN_PREC_G];\n"); + fprintf(fp, "#else\n"); fprintf(fp, "static const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[ECMULT_GEN_PREC_N][ECMULT_GEN_PREC_G] = {\n"); table = checked_malloc(&default_error_callback, ECMULT_GEN_PREC_TABLE_SIZE); @@ -80,8 +87,9 @@ int main(int argc, char **argv) { fprintf(fp,"};\n"); free(table); + fprintf(fp, "#endif /* EXHAUSTIVE_TEST_ORDER */\n"); fprintf(fp, "#undef SC\n"); - fprintf(fp, "#endif\n"); + fprintf(fp, "#endif /* SECP256K1_ECMULT_GEN_STATIC_PREC_TABLE_H */\n"); fclose(fp); return 0; diff --git a/src/tests_exhaustive.c b/src/tests_exhaustive.c index f112758076713..1d025ac732ef5 100644 --- a/src/tests_exhaustive.c +++ b/src/tests_exhaustive.c @@ -22,6 +22,7 @@ #include "assumptions.h" #include "group.h" #include "testrand_impl.h" +#include "ecmult_gen_prec_impl.h" static int count = 2; @@ -388,6 +389,9 @@ int main(int argc, char** argv) { printf("running tests for core %lu (out of [0..%lu])\n", (unsigned long)this_core, (unsigned long)num_cores - 1); } + /* Recreate the ecmult_gen table using the right generator (as selected via EXHAUSTIVE_TEST_ORDER) */ + secp256k1_ecmult_gen_create_prec_table(&secp256k1_ecmult_gen_prec_table[0][0], &secp256k1_ge_const_g); + while (count--) { /* Build context */ ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);