From bb36331412ed68999ac73c871d402e3b03f65700 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 17 Dec 2021 12:12:24 -0500 Subject: [PATCH] Simplify precompute_ecmult_print_* --- src/precompute_ecmult.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/precompute_ecmult.c b/src/precompute_ecmult.c index a585693..3e06251 100644 --- a/src/precompute_ecmult.c +++ b/src/precompute_ecmult.c @@ -21,7 +21,7 @@ #include "ecmult.h" #include "ecmult_compute_table_impl.h" -static void print_table(FILE *fp, const char *name, int window_g, const secp256k1_ge_storage* table, int with_conditionals) { +static void print_table(FILE *fp, const char *name, int window_g, const secp256k1_ge_storage* table) { int j; int i; @@ -32,36 +32,31 @@ static void print_table(FILE *fp, const char *name, int window_g, const secp256k j = 1; for(i = 3; i <= window_g; ++i) { - if (with_conditionals) { - fprintf(fp, "#if ECMULT_TABLE_SIZE(WINDOW_G) > %ld\n", ECMULT_TABLE_SIZE(i-1)); - } + fprintf(fp, "#if ECMULT_TABLE_SIZE(WINDOW_G) > %ld\n", ECMULT_TABLE_SIZE(i-1)); for(;j < ECMULT_TABLE_SIZE(i); ++j) { fprintf(fp, ",S(%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32 ",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32")\n", SECP256K1_GE_STORAGE_CONST_GET(table[j])); } - if (with_conditionals) { - fprintf(fp, "#endif\n"); - } + fprintf(fp, "#endif\n"); } fprintf(fp, "};\n"); } -static void print_two_tables(FILE *fp, int window_g, const secp256k1_ge *g, int with_conditionals) { +static void print_two_tables(FILE *fp, int window_g) { secp256k1_ge_storage* table = malloc(ECMULT_TABLE_SIZE(window_g) * sizeof(secp256k1_ge_storage)); secp256k1_ge_storage* table_128 = malloc(ECMULT_TABLE_SIZE(window_g) * sizeof(secp256k1_ge_storage)); - secp256k1_ecmult_compute_two_tables(table, table_128, window_g, g); + secp256k1_ecmult_compute_two_tables(table, table_128, window_g, &secp256k1_ge_const_g); - print_table(fp, "secp256k1_pre_g", window_g, table, with_conditionals); - print_table(fp, "secp256k1_pre_g_128", window_g, table_128, with_conditionals); + print_table(fp, "secp256k1_pre_g", window_g, table); + print_table(fp, "secp256k1_pre_g_128", window_g, table_128); free(table); free(table_128); } int main(void) { - const secp256k1_ge g = SECP256K1_G; const int window_g_13 = 4; const int window_g_199 = 8; FILE* fp; @@ -101,7 +96,7 @@ int main(void) { fprintf(fp, "#else /* !defined(EXHAUSTIVE_TEST_ORDER) */\n"); fprintf(fp, "#define WINDOW_G ECMULT_WINDOW_SIZE\n"); - print_two_tables(fp, ECMULT_WINDOW_SIZE, &g, 1); + print_two_tables(fp, ECMULT_WINDOW_SIZE); fprintf(fp, "#endif /* defined(EXHAUSTIVE_TEST_ORDER) */\n"); fprintf(fp, "#undef S\n");