1 /***********************************************************************
2 * Copyright (c) 2013, 2014, 2015 Thomas Daede, Cory Fields *
3 * Distributed under the MIT software license, see the accompanying *
4 * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 ***********************************************************************/
7 /* Autotools creates libsecp256k1-config.h, of which ECMULT_GEN_PREC_BITS is needed.
8 ifndef guard so downstream users can define their own if they do not use autotools. */
9 #if !defined(ECMULT_GEN_PREC_BITS)
10 #include "libsecp256k1-config.h"
13 /* We can't require the precomputed tables when creating them. */
14 #undef USE_ECMULT_STATIC_PRECOMPUTATION
16 /* In principle we could use external ASM, but this yields only a minor speedup in
17 build time and it's very complicated. In particular when cross-compiling, we'd
18 need to build the external ASM for the build and the host machine. */
19 #undef USE_EXTERNAL_ASM
21 #include "../include/secp256k1.h"
22 #include "assumptions.h"
24 #include "field_impl.h"
25 #include "scalar_impl.h"
26 #include "group_impl.h"
27 #include "ecmult_gen_impl.h"
29 static void default_error_callback_fn(const char* str, void* data) {
31 fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
35 static const secp256k1_callback default_error_callback = {
36 default_error_callback_fn,
40 int main(int argc, char **argv) {
41 secp256k1_ecmult_gen_context ctx;
42 void *prealloc, *base;
50 fp = fopen("src/ecmult_static_context.h","w");
52 fprintf(stderr, "Could not open src/ecmult_static_context.h for writing!\n");
56 fprintf(fp, "#ifndef SECP256K1_ECMULT_STATIC_CONTEXT_H\n");
57 fprintf(fp, "#define SECP256K1_ECMULT_STATIC_CONTEXT_H\n");
58 fprintf(fp, "#include \"src/group.h\"\n");
59 fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n");
60 fprintf(fp, "#if ECMULT_GEN_PREC_N != %d || ECMULT_GEN_PREC_G != %d\n", ECMULT_GEN_PREC_N, ECMULT_GEN_PREC_G);
61 fprintf(fp, " #error configuration mismatch, invalid ECMULT_GEN_PREC_N, ECMULT_GEN_PREC_G. Try deleting ecmult_static_context.h before the build.\n");
62 fprintf(fp, "#endif\n");
63 fprintf(fp, "static const secp256k1_ge_storage secp256k1_ecmult_static_context[ECMULT_GEN_PREC_N][ECMULT_GEN_PREC_G] = {\n");
65 base = checked_malloc(&default_error_callback, SECP256K1_ECMULT_GEN_CONTEXT_PREALLOCATED_SIZE);
67 secp256k1_ecmult_gen_context_init(&ctx);
68 secp256k1_ecmult_gen_context_build(&ctx, &prealloc);
69 for(outer = 0; outer != ECMULT_GEN_PREC_N; outer++) {
71 for(inner = 0; inner != ECMULT_GEN_PREC_G; inner++) {
72 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]));
73 if (inner != ECMULT_GEN_PREC_G - 1) {
79 if (outer != ECMULT_GEN_PREC_N - 1) {
86 secp256k1_ecmult_gen_context_clear(&ctx);
89 fprintf(fp, "#undef SC\n");
90 fprintf(fp, "#endif\n");