Bitcoin ABC 0.32.6
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#include "include/secp256k1.h"
17#include "assumptions.h"
18#include "util.h"
19#include "field_impl.h"
20#include "scalar_impl.h"
21#include "group_impl.h"
22#include "ecmult_gen_impl.h"
23
24static void default_error_callback_fn(const char* str, void* data) {
25 (void)data;
26 fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
27 abort();
28}
29
32 NULL
33};
34
35int main(int argc, char **argv) {
37 void *prealloc, *base;
38 int inner;
39 int outer;
40 FILE* fp;
41
42 (void)argc;
43 (void)argv;
44
45 fp = fopen("src/ecmult_static_context.h","w");
46 if (fp == NULL) {
47 fprintf(stderr, "Could not open src/ecmult_static_context.h for writing!\n");
48 return -1;
49 }
50
51 fprintf(fp, "#ifndef SECP256K1_ECMULT_STATIC_CONTEXT_H\n");
52 fprintf(fp, "#define SECP256K1_ECMULT_STATIC_CONTEXT_H\n");
53 fprintf(fp, "#include \"src/group.h\"\n");
54 fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n");
55 fprintf(fp, "#if ECMULT_GEN_PREC_N != %d || ECMULT_GEN_PREC_G != %d\n", ECMULT_GEN_PREC_N, ECMULT_GEN_PREC_G);
56 fprintf(fp, " #error configuration mismatch, invalid ECMULT_GEN_PREC_N, ECMULT_GEN_PREC_G. Try deleting ecmult_static_context.h before the build.\n");
57 fprintf(fp, "#endif\n");
58 fprintf(fp, "static const secp256k1_ge_storage secp256k1_ecmult_static_context[ECMULT_GEN_PREC_N][ECMULT_GEN_PREC_G] = {\n");
59
61 prealloc = base;
64 for(outer = 0; outer != ECMULT_GEN_PREC_N; outer++) {
65 fprintf(fp,"{\n");
66 for(inner = 0; inner != ECMULT_GEN_PREC_G; inner++) {
67 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]));
68 if (inner != ECMULT_GEN_PREC_G - 1) {
69 fprintf(fp,",\n");
70 } else {
71 fprintf(fp,"\n");
72 }
73 }
74 if (outer != ECMULT_GEN_PREC_N - 1) {
75 fprintf(fp,"},\n");
76 } else {
77 fprintf(fp,"}\n");
78 }
79 }
80 fprintf(fp,"};\n");
82 free(base);
83
84 fprintf(fp, "#undef SC\n");
85 fprintf(fp, "#endif\n");
86 fclose(fp);
87
88 return 0;
89}
secp256k1_context * ctx
#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:35
static const secp256k1_callback default_error_callback
Definition: gen_context.c:30
static void default_error_callback_fn(const char *str, void *data)
Definition: gen_context.c:24
#define SECP256K1_GE_STORAGE_CONST_GET(t)
Definition: group.h:40
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:30
static SECP256K1_INLINE void * checked_malloc(const secp256k1_callback *cb, size_t size)
Definition: util.h:91