UltrafastSecp256k1
3.50.0
Ultra high-performance secp256k1 elliptic curve cryptography library
Loading...
Searching...
No Matches
init.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <iostream>
4
#include <cstdlib>
5
#include <mutex>
6
7
namespace
secp256k1::fast
{
8
9
// External selftest function from library
10
extern
bool
Selftest
(
bool
verbose);
11
12
// Auto-run selftest on first library use
13
// Call this at the start of every application's main()
14
inline
bool
ensure_library_integrity
(
bool
verbose =
false
) {
15
static
std::once_flag flag;
16
static
bool
result =
true
;
17
18
std::call_once(flag, [verbose]() {
19
if
(verbose) {
20
std::cout <<
"[*] Running library integrity check...\n"
<< std::flush;
21
}
22
23
result =
Selftest
(verbose);
24
25
if
(!result) {
26
std::cerr <<
"\n[FAIL] CRITICAL: Library integrity check FAILED!\n"
;
27
std::cerr <<
" The secp256k1 library has failed self-validation.\n"
;
28
std::cerr <<
" This application cannot continue safely.\n"
<< std::flush;
29
std::abort();
30
}
31
32
if
(verbose) {
33
std::cout <<
"[OK] Library integrity verified\n\n"
<< std::flush;
34
}
35
});
36
37
return
result;
38
}
39
40
// Macro to automatically run selftest at program startup
41
// Usage: Add SECP256K1_INIT(); as the first line in main()
42
#define SECP256K1_INIT() \
43
secp256k1::fast::ensure_library_integrity(false)
44
45
#define SECP256K1_INIT_VERBOSE() \
46
secp256k1::fast::ensure_library_integrity(true)
47
48
}
// namespace secp256k1::fast
secp256k1::fast
Definition
batch_add_affine.hpp:8
secp256k1::fast::ensure_library_integrity
bool ensure_library_integrity(bool verbose=false)
Definition
init.hpp:14
secp256k1::fast::Selftest
bool Selftest(bool verbose)
cpu
include
secp256k1
init.hpp
Generated by
1.9.8