2020-12-17 08:33:49 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Copyright (c) 2013, 2014, 2015 Thomas Daede, Cory Fields *
|
|
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
|
|
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
|
|
|
|
***********************************************************************/
|
2015-05-19 17:32:35 -07:00
|
|
|
|
2021-01-02 15:15:21 +01:00
|
|
|
/* Autotools creates libsecp256k1-config.h, of which ECMULT_GEN_PREC_BITS is needed.
|
|
|
|
ifndef guard so downstream users can define their own if they do not use autotools. */
|
2015-10-18 10:35:16 +02:00
|
|
|
#if !defined(ECMULT_GEN_PREC_BITS)
|
|
|
|
#include "libsecp256k1-config.h"
|
|
|
|
#endif
|
2021-04-15 16:17:53 +02:00
|
|
|
|
2021-07-14 11:12:41 +02:00
|
|
|
/* In principle we could use ASM, but this yields only a minor speedup in
|
2021-05-03 14:11:08 +02:00
|
|
|
build time and it's very complicated. In particular when cross-compiling, we'd
|
2021-07-14 11:12:41 +02:00
|
|
|
need to build the ASM for the build and the host machine. */
|
2021-05-03 14:11:08 +02:00
|
|
|
#undef USE_EXTERNAL_ASM
|
2021-07-14 11:12:41 +02:00
|
|
|
#undef USE_ASM_X86_64
|
2021-05-03 14:11:08 +02:00
|
|
|
|
2021-05-04 13:19:33 -04:00
|
|
|
#include "../include/secp256k1.h"
|
2020-08-12 15:52:20 -07:00
|
|
|
#include "assumptions.h"
|
2018-10-22 16:25:26 +02:00
|
|
|
#include "util.h"
|
2021-09-09 16:46:19 +02:00
|
|
|
#include "group.h"
|
|
|
|
#include "ecmult_gen.h"
|
|
|
|
#include "ecmult_gen_prec_impl.h"
|
2015-05-19 17:32:35 -07:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2021-11-09 11:24:56 +01:00
|
|
|
secp256k1_ge_storage* table;
|
2015-05-19 17:32:35 -07:00
|
|
|
int inner;
|
|
|
|
int outer;
|
2021-10-07 18:27:11 +02:00
|
|
|
const char outfile[] = "src/ecmult_gen_static_prec_table.h";
|
2015-05-19 17:32:35 -07:00
|
|
|
FILE* fp;
|
|
|
|
|
2021-09-08 18:49:06 +02:00
|
|
|
int bits = ECMULT_GEN_PREC_BITS;
|
|
|
|
int g = ECMULT_GEN_PREC_G(bits);
|
|
|
|
int n = ECMULT_GEN_PREC_N(bits);
|
|
|
|
table = checked_malloc(&default_error_callback, n * g * sizeof(secp256k1_ge_storage));
|
|
|
|
|
2015-05-19 17:32:35 -07:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
|
2021-10-07 18:27:11 +02:00
|
|
|
fp = fopen(outfile, "w");
|
2015-05-19 17:32:35 -07:00
|
|
|
if (fp == NULL) {
|
2021-10-07 18:27:11 +02:00
|
|
|
fprintf(stderr, "Could not open %s for writing!\n", outfile);
|
2015-05-19 17:32:35 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2018-10-22 16:25:26 +02:00
|
|
|
|
2021-10-07 18:27:11 +02:00
|
|
|
fprintf(fp, "#ifndef SECP256K1_ECMULT_GEN_STATIC_PREC_TABLE_H\n");
|
|
|
|
fprintf(fp, "#define SECP256K1_ECMULT_GEN_STATIC_PREC_TABLE_H\n");
|
2021-10-07 16:54:03 +02:00
|
|
|
|
2017-09-27 15:13:38 -07:00
|
|
|
fprintf(fp, "#include \"src/group.h\"\n");
|
2021-10-07 16:54:03 +02:00
|
|
|
|
2015-05-19 17:32:35 -07:00
|
|
|
fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n");
|
2021-10-07 16:54:03 +02:00
|
|
|
|
2021-09-08 18:49:06 +02:00
|
|
|
fprintf(fp, "#if ECMULT_GEN_PREC_BITS != %d\n", bits);
|
|
|
|
fprintf(fp, " #error configuration mismatch, invalid ECMULT_GEN_PREC_BITS. Try deleting ecmult_static_context.h before the build.\n");
|
2015-10-18 10:35:16 +02:00
|
|
|
fprintf(fp, "#endif\n");
|
2021-10-07 16:54:03 +02:00
|
|
|
|
|
|
|
fprintf(fp, "#ifdef EXHAUSTIVE_TEST_ORDER\n");
|
2021-09-08 18:49:06 +02:00
|
|
|
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");
|
2021-10-07 16:54:03 +02:00
|
|
|
fprintf(fp, "#else\n");
|
2021-09-08 18:49:06 +02:00
|
|
|
fprintf(fp, "static const 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");
|
|
|
|
|
|
|
|
secp256k1_ecmult_gen_create_prec_table(table, &secp256k1_ge_const_g, bits);
|
2015-05-19 17:32:35 -07:00
|
|
|
|
2021-09-08 18:49:06 +02:00
|
|
|
for(outer = 0; outer != n; outer++) {
|
2015-05-19 17:32:35 -07:00
|
|
|
fprintf(fp,"{\n");
|
2021-09-08 18:49:06 +02:00
|
|
|
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]));
|
|
|
|
if (inner != g - 1) {
|
2015-05-19 17:32:35 -07:00
|
|
|
fprintf(fp,",\n");
|
|
|
|
} else {
|
|
|
|
fprintf(fp,"\n");
|
|
|
|
}
|
|
|
|
}
|
2021-09-08 18:49:06 +02:00
|
|
|
if (outer != n - 1) {
|
2015-05-19 17:32:35 -07:00
|
|
|
fprintf(fp,"},\n");
|
|
|
|
} else {
|
|
|
|
fprintf(fp,"}\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(fp,"};\n");
|
2021-11-09 11:24:56 +01:00
|
|
|
free(table);
|
2018-10-22 16:25:26 +02:00
|
|
|
|
2021-10-07 16:54:03 +02:00
|
|
|
fprintf(fp, "#endif /* EXHAUSTIVE_TEST_ORDER */\n");
|
2015-05-19 17:32:35 -07:00
|
|
|
fprintf(fp, "#undef SC\n");
|
2021-10-07 16:54:03 +02:00
|
|
|
fprintf(fp, "#endif /* SECP256K1_ECMULT_GEN_STATIC_PREC_TABLE_H */\n");
|
2015-05-19 17:32:35 -07:00
|
|
|
fclose(fp);
|
2018-10-22 16:25:26 +02:00
|
|
|
|
2015-05-19 17:32:35 -07:00
|
|
|
return 0;
|
|
|
|
}
|