Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
precompute_ecmult_gen.c File Reference
#include <inttypes.h>
#include <stdio.h>
#include "../include/secp256k1.h"
#include "assumptions.h"
#include "util.h"
#include "group.h"
#include "ecmult_gen.h"
#include "ecmult_gen_compute_table_impl.h"
Include dependency graph for precompute_ecmult_gen.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 17 of file precompute_ecmult_gen.c.

17 {
18 const char outfile[] = "src/precomputed_ecmult_gen.c";
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 precompute_ecmult_gen. */\n");
32 fprintf(fp, "/* See ecmult_gen_impl.h for details about the contents of this file. */\n");
33 fprintf(fp, "#if defined HAVE_CONFIG_H\n");
34 fprintf(fp, "# include \"libsecp256k1-config.h\"\n");
35 fprintf(fp, "#endif\n");
36 fprintf(fp, "#include \"../include/secp256k1.h\"\n");
37 fprintf(fp, "#include \"group.h\"\n");
38 fprintf(fp, "#include \"ecmult_gen.h\"\n");
39 fprintf(fp, "#include \"precomputed_ecmult_gen.h\"\n");
40 fprintf(fp, "#ifdef EXHAUSTIVE_TEST_ORDER\n");
41 fprintf(fp, "# error Cannot compile precomputed_ecmult_gen.c in exhaustive test mode\n");
42 fprintf(fp, "#endif /* EXHAUSTIVE_TEST_ORDER */\n");
43 fprintf(fp, "#define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) 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,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");
44 fprintf(fp, "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");
45
46 for (bits = 2; bits <= 8; bits *= 2) {
47 int g = ECMULT_GEN_PREC_G(bits);
48 int n = ECMULT_GEN_PREC_N(bits);
49 int inner, outer;
50
51 secp256k1_ge_storage* table = checked_malloc(&default_error_callback, n * g * sizeof(secp256k1_ge_storage));
52 secp256k1_ecmult_gen_compute_table(table, &secp256k1_ge_const_g, bits);
53
54 fprintf(fp, "#if ECMULT_GEN_PREC_BITS == %d\n", bits);
55 for(outer = 0; outer != n; outer++) {
56 fprintf(fp,"{");
57 for(inner = 0; inner != g; inner++) {
58 fprintf(fp, "S(%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32
59 ",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32")",
60 SECP256K1_GE_STORAGE_CONST_GET(table[outer * g + inner]));
61 if (inner != g - 1) {
62 fprintf(fp,",\n");
63 }
64 }
65 if (outer != n - 1) {
66 fprintf(fp,"},\n");
67 } else {
68 fprintf(fp,"}\n");
69 }
70 }
71 fprintf(fp, "#endif\n");
72 free(table);
73 }
74
75 fprintf(fp, "};\n");
76 fprintf(fp, "#undef S\n");
77 fclose(fp);
78
79 return 0;
80}
#define ECMULT_GEN_PREC_G(bits)
Definition ecmult_gen.h:16
#define ECMULT_GEN_PREC_N(bits)
Definition ecmult_gen.h:17
#define SECP256K1_GE_STORAGE_CONST_GET(t)
Definition group.h:45
char ** argv
#define PRIx32
Definition inttypes.h:130