Bitcoin Core 22.99.0
P2P Digital Currency
gen_context.c
Go to the documentation of this file.
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 ***********************************************************************/
6
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"
11#endif
12
13/* We can't require the precomputed tables when creating them. */
14#undef USE_ECMULT_STATIC_PRECOMPUTATION
15
16/* In principle we could use 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 ASM for the build and the host machine. */
19#undef USE_EXTERNAL_ASM
20#undef USE_ASM_X86_64
21
22#include "../include/secp256k1.h"
23#include "assumptions.h"
24#include "util.h"
25#include "field_impl.h"
26#include "scalar_impl.h"
27#include "group_impl.h"
28#include "ecmult_gen_impl.h"
29
30static void default_error_callback_fn(const char* str, void* data) {
31 (void)data;
32 fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
33 abort();
34}
35
38 NULL
39};
40
41int main(int argc, char **argv) {
43 void *prealloc, *base;
44 int inner;
45 int outer;
46 FILE* fp;
47
48 (void)argc;
49 (void)argv;
50
51 fp = fopen("src/ecmult_static_context.h","w");
52 if (fp == NULL) {
53 fprintf(stderr, "Could not open src/ecmult_static_context.h for writing!\n");
54 return -1;
55 }
56
57 fprintf(fp, "#ifndef SECP256K1_ECMULT_STATIC_CONTEXT_H\n");
58 fprintf(fp, "#define SECP256K1_ECMULT_STATIC_CONTEXT_H\n");
59 fprintf(fp, "#include \"src/group.h\"\n");
60 fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n");
61 fprintf(fp, "#if ECMULT_GEN_PREC_N != %d || ECMULT_GEN_PREC_G != %d\n", ECMULT_GEN_PREC_N, ECMULT_GEN_PREC_G);
62 fprintf(fp, " #error configuration mismatch, invalid ECMULT_GEN_PREC_N, ECMULT_GEN_PREC_G. Try deleting ecmult_static_context.h before the build.\n");
63 fprintf(fp, "#endif\n");
64 fprintf(fp, "static const secp256k1_ge_storage secp256k1_ecmult_static_context[ECMULT_GEN_PREC_N][ECMULT_GEN_PREC_G] = {\n");
65
67 prealloc = base;
70 for(outer = 0; outer != ECMULT_GEN_PREC_N; outer++) {
71 fprintf(fp,"{\n");
72 for(inner = 0; inner != ECMULT_GEN_PREC_G; inner++) {
73 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]));
74 if (inner != ECMULT_GEN_PREC_G - 1) {
75 fprintf(fp,",\n");
76 } else {
77 fprintf(fp,"\n");
78 }
79 }
80 if (outer != ECMULT_GEN_PREC_N - 1) {
81 fprintf(fp,"},\n");
82 } else {
83 fprintf(fp,"}\n");
84 }
85 }
86 fprintf(fp,"};\n");
88 free(base);
89
90 fprintf(fp, "#undef SC\n");
91 fprintf(fp, "#endif\n");
92 fclose(fp);
93
94 return 0;
95}
#define ECMULT_GEN_PREC_G
Definition: ecmult_gen.h:17
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ctx)
static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context *ctx)
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context *ctx, void **prealloc)
#define ECMULT_GEN_PREC_N
Definition: ecmult_gen.h:18
static const size_t SECP256K1_ECMULT_GEN_CONTEXT_PREALLOCATED_SIZE
int main(int argc, char **argv)
Definition: gen_context.c:41
static const secp256k1_callback default_error_callback
Definition: gen_context.c:36
static void default_error_callback_fn(const char *str, void *data)
Definition: gen_context.c:30
#define SECP256K1_GE_STORAGE_CONST_GET(t)
Definition: group.h:40
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:25
static SECP256K1_INLINE void * checked_malloc(const secp256k1_callback *cb, size_t size)
Definition: util.h:91
static secp256k1_context * ctx
Definition: tests.c:42