Simplify precompute_ecmult_print_*

This commit is contained in:
Pieter Wuille 2021-12-17 12:12:24 -05:00
parent 38cd84a0cb
commit bb36331412
1 changed files with 8 additions and 13 deletions

View File

@ -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));
}
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, "};\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");