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