From 6573c08f656f8ec305a2db801d57bfe6441e83e0 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Mon, 8 Nov 2021 20:08:16 +0100 Subject: [PATCH] ecmult_gen: Tidy precomputed file and save space --- src/gen_ecmult_gen_static_prec_table.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/gen_ecmult_gen_static_prec_table.c b/src/gen_ecmult_gen_static_prec_table.c index 997b444..8236a52 100644 --- a/src/gen_ecmult_gen_static_prec_table.c +++ b/src/gen_ecmult_gen_static_prec_table.c @@ -4,6 +4,9 @@ * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ +#include +#include + /* In principle we could use ASM, but this yields only a minor speedup in build time and it's very complicated. In particular when cross-compiling, we'd need to build the ASM for the build and the host machine. */ @@ -31,12 +34,16 @@ int main(int argc, char **argv) { return -1; } + fprintf(fp, "/* This file was automatically generated by gen_ecmult_gen_static_prec_table. */\n"); + fprintf(fp, "/* See ecmult_gen_impl.h for details about the contents of this file. */\n"); 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, "#include \"group.h\"\n"); - fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n"); + fprintf(fp, "#define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) " + "SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u," + "0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u)\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_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)];\n"); @@ -53,14 +60,14 @@ int main(int argc, char **argv) { fprintf(fp, "#if ECMULT_GEN_PREC_BITS == %d\n", bits); for(outer = 0; outer != n; outer++) { - fprintf(fp,"{\n"); + fprintf(fp,"{"); for(inner = 0; inner != g; inner++) { - fprintf(fp," SC(%uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu)", SECP256K1_GE_STORAGE_CONST_GET(table[outer * g + inner])); + fprintf(fp, "S(%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32 + ",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32")", + SECP256K1_GE_STORAGE_CONST_GET(table[outer * g + inner])); if (inner != g - 1) { fprintf(fp,",\n"); - } else { - fprintf(fp,"\n"); - } + } } if (outer != n - 1) { fprintf(fp,"},\n");