2020-12-29 17:15:51 +00: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-10-26 14:54:21 +00:00
|
|
|
|
2021-06-14 14:55:38 +00: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. */
|
2020-08-26 17:35:27 +00:00
|
|
|
#if !defined(ECMULT_GEN_PREC_BITS)
|
|
|
|
#include "libsecp256k1-config.h"
|
|
|
|
#endif
|
|
|
|
|
2021-06-14 14:55:38 +00:00
|
|
|
/* We can't require the precomputed tables when creating them. */
|
|
|
|
#undef USE_ECMULT_STATIC_PRECOMPUTATION
|
|
|
|
|
|
|
|
/* In principle we could use external ASM, but this yields only a minor speedup in
|
|
|
|
build time and it's very complicated. In particular when cross-compiling, we'd
|
|
|
|
need to build the external ASM for the build and the host machine. */
|
|
|
|
#undef USE_EXTERNAL_ASM
|
|
|
|
|
|
|
|
#include "../include/secp256k1.h"
|
2020-08-26 17:35:27 +00:00
|
|
|
#include "assumptions.h"
|
2019-05-28 12:23:28 +00:00
|
|
|
#include "util.h"
|
2015-10-26 14:54:21 +00:00
|
|
|
#include "field_impl.h"
|
|
|
|
#include "scalar_impl.h"
|
|
|
|
#include "group_impl.h"
|
|
|
|
#include "ecmult_gen_impl.h"
|
|
|
|
|
|
|
|
static void default_error_callback_fn(const char* str, void* data) {
|
|
|
|
(void)data;
|
|
|
|
fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2021-06-14 14:55:38 +00:00
|
|
|
static const rustsecp256k1_v0_4_1_callback default_error_callback = {
|
2015-10-26 14:54:21 +00:00
|
|
|
default_error_callback_fn,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2021-06-14 14:55:38 +00:00
|
|
|
rustsecp256k1_v0_4_1_ecmult_gen_context ctx;
|
2019-05-28 12:23:28 +00:00
|
|
|
void *prealloc, *base;
|
2015-10-26 14:54:21 +00:00
|
|
|
int inner;
|
|
|
|
int outer;
|
|
|
|
FILE* fp;
|
|
|
|
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
|
|
|
|
fp = fopen("src/ecmult_static_context.h","w");
|
|
|
|
if (fp == NULL) {
|
|
|
|
fprintf(stderr, "Could not open src/ecmult_static_context.h for writing!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2019-05-28 12:23:28 +00:00
|
|
|
|
2021-06-14 14:55:38 +00:00
|
|
|
fprintf(fp, "#ifndef SECP256K1_ECMULT_STATIC_CONTEXT_H\n");
|
|
|
|
fprintf(fp, "#define SECP256K1_ECMULT_STATIC_CONTEXT_H\n");
|
2018-07-09 11:17:44 +00:00
|
|
|
fprintf(fp, "#include \"src/group.h\"\n");
|
2015-10-26 14:54:21 +00:00
|
|
|
fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n");
|
2020-08-26 17:35:27 +00:00
|
|
|
fprintf(fp, "#if ECMULT_GEN_PREC_N != %d || ECMULT_GEN_PREC_G != %d\n", ECMULT_GEN_PREC_N, ECMULT_GEN_PREC_G);
|
|
|
|
fprintf(fp, " #error configuration mismatch, invalid ECMULT_GEN_PREC_N, ECMULT_GEN_PREC_G. Try deleting ecmult_static_context.h before the build.\n");
|
|
|
|
fprintf(fp, "#endif\n");
|
2021-06-14 14:55:38 +00:00
|
|
|
fprintf(fp, "static const rustsecp256k1_v0_4_1_ge_storage rustsecp256k1_v0_4_1_ecmult_static_context[ECMULT_GEN_PREC_N][ECMULT_GEN_PREC_G] = {\n");
|
2015-10-26 14:54:21 +00:00
|
|
|
|
2019-05-28 12:23:28 +00:00
|
|
|
base = checked_malloc(&default_error_callback, SECP256K1_ECMULT_GEN_CONTEXT_PREALLOCATED_SIZE);
|
|
|
|
prealloc = base;
|
2021-06-14 14:55:38 +00:00
|
|
|
rustsecp256k1_v0_4_1_ecmult_gen_context_init(&ctx);
|
|
|
|
rustsecp256k1_v0_4_1_ecmult_gen_context_build(&ctx, &prealloc);
|
2020-08-26 17:35:27 +00:00
|
|
|
for(outer = 0; outer != ECMULT_GEN_PREC_N; outer++) {
|
2015-10-26 14:54:21 +00:00
|
|
|
fprintf(fp,"{\n");
|
2020-08-26 17:35:27 +00:00
|
|
|
for(inner = 0; inner != ECMULT_GEN_PREC_G; inner++) {
|
2015-10-26 14:54:21 +00:00
|
|
|
fprintf(fp," SC(%uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu)", SECP256K1_GE_STORAGE_CONST_GET((*ctx.prec)[outer][inner]));
|
2020-08-26 17:35:27 +00:00
|
|
|
if (inner != ECMULT_GEN_PREC_G - 1) {
|
2015-10-26 14:54:21 +00:00
|
|
|
fprintf(fp,",\n");
|
|
|
|
} else {
|
|
|
|
fprintf(fp,"\n");
|
|
|
|
}
|
|
|
|
}
|
2020-08-26 17:35:27 +00:00
|
|
|
if (outer != ECMULT_GEN_PREC_N - 1) {
|
2015-10-26 14:54:21 +00:00
|
|
|
fprintf(fp,"},\n");
|
|
|
|
} else {
|
|
|
|
fprintf(fp,"}\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(fp,"};\n");
|
2021-06-14 14:55:38 +00:00
|
|
|
rustsecp256k1_v0_4_1_ecmult_gen_context_clear(&ctx);
|
2019-05-28 12:23:28 +00:00
|
|
|
free(base);
|
|
|
|
|
2015-10-26 14:54:21 +00:00
|
|
|
fprintf(fp, "#undef SC\n");
|
|
|
|
fprintf(fp, "#endif\n");
|
|
|
|
fclose(fp);
|
2019-05-28 12:23:28 +00:00
|
|
|
|
2015-10-26 14:54:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|