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