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];
31 for (i = 0; i < 4; ++i) {
34 for (j = 0; j < 8; ++j)
s = (
s << 8) | out32[8*i + j];
40 return (x <<
k) | (x >> (64 -
k));
57 if (bits == 0)
return 0;
74 mask = (mask << 1) | 1U;
80 if (val <= range)
return val;
86 for (i = 0; i < 4; ++i) {
102 memset(bytes, 0, len);
103 while (bits < len * 8) {
108 while (now > 0 && bits < len * 8) {
109 bytes[bits / 8] |= val << (bits % 8);
125 unsigned char seed16[16] = {0};
126 if (hexseed && strlen(hexseed) != 0) {
128 while (pos < 16 && hexseed[0] != 0 && hexseed[1] != 0) {
130 if ((sscanf(hexseed,
"%2hx", &sh)) == 1) {
139 FILE *frand =
fopen(
"/dev/urandom",
"rb");
140 if ((frand == NULL) || fread(&seed16, 1,
sizeof(seed16), frand) !=
sizeof(seed16)) {
141 uint64_t
t = time(NULL) * (uint64_t)1337;
142 fprintf(stderr,
"WARNING: could not read 16 bytes from /dev/urandom; falling back to insecure PRNG\n");
145 seed16[2] ^=
t >> 16;
146 seed16[3] ^=
t >> 24;
147 seed16[4] ^=
t >> 32;
148 seed16[5] ^=
t >> 40;
149 seed16[6] ^=
t >> 48;
150 seed16[7] ^=
t >> 56;
157 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]);
162 unsigned char run32[32];
164 printf(
"random run = %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", run32[0], run32[1], run32[2], run32[3], run32[4], run32[5], run32[6], run32[7], run32[8], run32[9], run32[10], run32[11], run32[12], run32[13], run32[14], run32[15]);
FILE * fopen(const fs::path &p, const char *mode)
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash)
static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out32)
static void secp256k1_sha256_write(secp256k1_sha256 *hash, const unsigned char *data, size_t size)
#define VERIFY_CHECK(cond)
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)
static void testrand_finish(void)