7#ifndef SECP256K1_TESTRAND_IMPL_H
8#define SECP256K1_TESTRAND_IMPL_H
21 static const unsigned char PREFIX[] = {
's',
'e',
'c',
'p',
'2',
'5',
'6',
'k',
'1',
' ',
't',
'e',
's',
't',
' ',
'i',
'n',
'i',
't'};
22 unsigned char out32[32];
32 for (i = 0; i < 4; ++i) {
35 for (
j = 0;
j < 8; ++
j) s = (s << 8) |
out32[8*i +
j];
41 return (x <<
k) | (x >> (64 -
k));
58 if (bits == 0)
return 0;
75 mask = (mask << 1) | 1U;
81 if (val <= range)
return val;
87 for (i = 0; i < 4; ++i) {
104 while (bits < len * 8) {
109 while (now > 0 && bits < len * 8) {
110 bytes[bits / 8] |= val << (bits % 8);
126 unsigned char seed16[16] = {0};
140 FILE *
frand = fopen(
"/dev/urandom",
"rb");
143 fprintf(
stderr,
"WARNING: could not read 16 bytes from /dev/urandom; falling back to insecure PRNG\n");
158 printf(
"random seed = %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
seed16[0],
seed16[1],
seed16[2],
seed16[3],
seed16[4],
seed16[5],
seed16[6],
seed16[7],
seed16[8],
seed16[9],
seed16[10],
seed16[11],
seed16[12],
seed16[13],
seed16[14],
seed16[15]);
static void secp256k1_sha256_finalize(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *hash, unsigned char *out32)
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash)
static void secp256k1_sha256_write(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *hash, const unsigned char *data, size_t size)
#define VERIFY_CHECK(cond)
SECP256K1_API const secp256k1_context *const secp256k1_context_static
A built-in constant secp256k1 context object with static storage duration, to be used in conjunction ...
secp256k1_hash_ctx hash_ctx
static void testrand_flip(unsigned char *b, size_t len)
static void testrand256_test(unsigned char *b32)
static SECP256K1_INLINE uint64_t testrand64(void)
static void testrand256(unsigned char *b32)
static SECP256K1_INLINE uint32_t testrand32(void)
static SECP256K1_INLINE uint64_t testrand_bits(int bits)
static uint64_t secp256k1_test_state[4]
static uint32_t testrand_int(uint32_t range)
static SECP256K1_INLINE void testrand_seed(const unsigned char *seed16)
static void testrand_init(const char *hexseed)
static SECP256K1_INLINE uint64_t rotl(const uint64_t x, int k)
static void testrand_bytes_test(unsigned char *bytes, size_t len)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.