Simplify precompute_ecmult_print_*
This commit is contained in:
parent
38cd84a0cb
commit
bb36331412
|
@ -21,7 +21,7 @@
|
||||||
#include "ecmult.h"
|
#include "ecmult.h"
|
||||||
#include "ecmult_compute_table_impl.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 j;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -32,36 +32,31 @@ static void print_table(FILE *fp, const char *name, int window_g, const secp256k
|
||||||
|
|
||||||
j = 1;
|
j = 1;
|
||||||
for(i = 3; i <= window_g; ++i) {
|
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) {
|
for(;j < ECMULT_TABLE_SIZE(i); ++j) {
|
||||||
fprintf(fp, ",S(%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32
|
fprintf(fp, ",S(%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32
|
||||||
",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32")\n",
|
",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32")\n",
|
||||||
SECP256K1_GE_STORAGE_CONST_GET(table[j]));
|
SECP256K1_GE_STORAGE_CONST_GET(table[j]));
|
||||||
}
|
}
|
||||||
if (with_conditionals) {
|
|
||||||
fprintf(fp, "#endif\n");
|
fprintf(fp, "#endif\n");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
fprintf(fp, "};\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 = 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_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", window_g, table);
|
||||||
print_table(fp, "secp256k1_pre_g_128", window_g, table_128, with_conditionals);
|
print_table(fp, "secp256k1_pre_g_128", window_g, table_128);
|
||||||
|
|
||||||
free(table);
|
free(table);
|
||||||
free(table_128);
|
free(table_128);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
const secp256k1_ge g = SECP256K1_G;
|
|
||||||
const int window_g_13 = 4;
|
const int window_g_13 = 4;
|
||||||
const int window_g_199 = 8;
|
const int window_g_199 = 8;
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
|
@ -101,7 +96,7 @@ int main(void) {
|
||||||
fprintf(fp, "#else /* !defined(EXHAUSTIVE_TEST_ORDER) */\n");
|
fprintf(fp, "#else /* !defined(EXHAUSTIVE_TEST_ORDER) */\n");
|
||||||
fprintf(fp, "#define WINDOW_G ECMULT_WINDOW_SIZE\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, "#endif /* defined(EXHAUSTIVE_TEST_ORDER) */\n");
|
||||||
fprintf(fp, "#undef S\n");
|
fprintf(fp, "#undef S\n");
|
||||||
|
|
Loading…
Reference in New Issue