Skip to content

Commit

Permalink
Simplify precompute_ecmult_print_*
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Dec 18, 2021
1 parent 38cd84a commit bb36331
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/precompute_ecmult.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit bb36331

Please sign in to comment.