Skip to content

Commit

Permalink
precompute_ecmult: Always compute all tables up to default WINDOW_G
Browse files Browse the repository at this point in the history
Also simplify #ifdefs in generated file.
  • Loading branch information
real-or-random committed Dec 20, 2021
1 parent be6944a commit 10461d8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
8 changes: 5 additions & 3 deletions src/precompute_ecmult.c
Expand Up @@ -32,7 +32,7 @@ static void print_table(FILE *fp, const char *name, int window_g, const secp256k

j = 1;
for(i = 3; i <= window_g; ++i) {
fprintf(fp, "#if ECMULT_TABLE_SIZE(WINDOW_G) > %ld\n", ECMULT_TABLE_SIZE(i-1));
fprintf(fp, "#if WINDOW_G > %d\n", 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",
Expand All @@ -57,6 +57,8 @@ static void print_two_tables(FILE *fp, int window_g) {
}

int main(void) {
/* Always compute all tables for window sizes up to 15. */
int window_g = (ECMULT_WINDOW_SIZE < 15) ? 15 : ECMULT_WINDOW_SIZE;
FILE* fp;

fp = fopen("src/precomputed_ecmult.c","w");
Expand All @@ -77,15 +79,15 @@ int main(void) {
fprintf(fp, "#include \"ecmult.h\"\n");
fprintf(fp, "#include \"precomputed_ecmult.h\"\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, "#if ECMULT_TABLE_SIZE(ECMULT_WINDOW_SIZE) > %ld\n", ECMULT_TABLE_SIZE(ECMULT_WINDOW_SIZE));
fprintf(fp, "#if ECMULT_WINDOW_SIZE > %d\n", window_g);
fprintf(fp, " #error configuration mismatch, invalid ECMULT_WINDOW_SIZE. Try deleting precomputed_ecmult.c before the build.\n");
fprintf(fp, "#endif\n");
fprintf(fp, "#ifdef EXHAUSTIVE_TEST_ORDER\n");
fprintf(fp, "# error Cannot compile precomputed_ecmult.c in exhaustive test mode\n");
fprintf(fp, "#endif /* EXHAUSTIVE_TEST_ORDER */\n");
fprintf(fp, "#define WINDOW_G ECMULT_WINDOW_SIZE\n");

print_two_tables(fp, ECMULT_WINDOW_SIZE);
print_two_tables(fp, window_g);

fprintf(fp, "#undef S\n");
fclose(fp);
Expand Down

0 comments on commit 10461d8

Please sign in to comment.