Bitcoin Core  22.99.0
P2P Digital Currency
gen_ecmult_gen_static_prec_table.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 #include <inttypes.h>
8 #include <stdio.h>
9 
10 #include "../include/secp256k1.h"
11 #include "assumptions.h"
12 #include "util.h"
13 #include "group.h"
14 #include "ecmult_gen.h"
15 #include "ecmult_gen_prec_impl.h"
16 
17 int main(int argc, char **argv) {
18  const char outfile[] = "src/ecmult_gen_static_prec_table.h";
19  FILE* fp;
20  int bits;
21 
22  (void)argc;
23  (void)argv;
24 
25  fp = fopen(outfile, "w");
26  if (fp == NULL) {
27  fprintf(stderr, "Could not open %s for writing!\n", outfile);
28  return -1;
29  }
30 
31  fprintf(fp, "/* This file was automatically generated by gen_ecmult_gen_static_prec_table. */\n");
32  fprintf(fp, "/* See ecmult_gen_impl.h for details about the contents of this file. */\n");
33  fprintf(fp, "#ifndef SECP256K1_ECMULT_GEN_STATIC_PREC_TABLE_H\n");
34  fprintf(fp, "#define SECP256K1_ECMULT_GEN_STATIC_PREC_TABLE_H\n");
35 
36  fprintf(fp, "#include \"group.h\"\n");
37 
38  fprintf(fp, "#define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) "
39  "SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,"
40  "0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u)\n");
41 
42  fprintf(fp, "#ifdef EXHAUSTIVE_TEST_ORDER\n");
43  fprintf(fp, "static secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[ECMULT_GEN_PREC_N(ECMULT_GEN_PREC_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)];\n");
44  fprintf(fp, "#else\n");
45  fprintf(fp, "static const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[ECMULT_GEN_PREC_N(ECMULT_GEN_PREC_BITS)][ECMULT_GEN_PREC_G(ECMULT_GEN_PREC_BITS)] = {\n");
46 
47  for (bits = 2; bits <= 8; bits *= 2) {
48  int g = ECMULT_GEN_PREC_G(bits);
49  int n = ECMULT_GEN_PREC_N(bits);
50  int inner, outer;
51 
54 
55  fprintf(fp, "#if ECMULT_GEN_PREC_BITS == %d\n", bits);
56  for(outer = 0; outer != n; outer++) {
57  fprintf(fp,"{");
58  for(inner = 0; inner != g; inner++) {
59  fprintf(fp, "S(%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32
60  ",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32")",
61  SECP256K1_GE_STORAGE_CONST_GET(table[outer * g + inner]));
62  if (inner != g - 1) {
63  fprintf(fp,",\n");
64  }
65  }
66  if (outer != n - 1) {
67  fprintf(fp,"},\n");
68  } else {
69  fprintf(fp,"}\n");
70  }
71  }
72  fprintf(fp, "#endif\n");
73  free(table);
74  }
75 
76  fprintf(fp, "};\n");
77  fprintf(fp, "#endif /* EXHAUSTIVE_TEST_ORDER */\n");
78  fprintf(fp, "#undef SC\n");
79  fprintf(fp, "#endif /* SECP256K1_ECMULT_GEN_STATIC_PREC_TABLE_H */\n");
80  fclose(fp);
81 
82  return 0;
83 }
fsbridge::fopen
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:27
group.h
util.h
secp256k1_ecmult_gen_create_prec_table
static void secp256k1_ecmult_gen_create_prec_table(secp256k1_ge_storage *table, const secp256k1_ge *gen, int bits)
secp256k1_ge_const_g
static const secp256k1_ge secp256k1_ge_const_g
Definition: group_impl.h:62
assumptions.h
checked_malloc
static SECP256K1_INLINE void * checked_malloc(const secp256k1_callback *cb, size_t size)
Definition: util.h:118
secp256k1_ge_storage
Definition: group.h:33
main
int main(int argc, char **argv)
Definition: gen_ecmult_gen_static_prec_table.c:17
SECP256K1_GE_STORAGE_CONST_GET
#define SECP256K1_GE_STORAGE_CONST_GET(t)
Definition: group.h:40
ecmult_gen_prec_impl.h
ECMULT_GEN_PREC_N
#define ECMULT_GEN_PREC_N(bits)
Definition: ecmult_gen.h:17
ECMULT_GEN_PREC_G
#define ECMULT_GEN_PREC_G(bits)
Definition: ecmult_gen.h:16
ecmult_gen.h
ByteUnit::g
@ g
default_error_callback
static const secp256k1_callback default_error_callback
Definition: util.h:49