32#define min(a,b) ((a) < (b) ? (a) : (b))
34#define APR_RANDOM_DEFAULT_POOLS 32
35#define APR_RANDOM_DEFAULT_REHASH_SIZE 1024
36#define APR_RANDOM_DEFAULT_RESEED_SIZE 32
37#define APR_RANDOM_DEFAULT_HASH_SECRET_SIZE 32
38#define APR_RANDOM_DEFAULT_G_FOR_INSECURE 32
39#define APR_RANDOM_DEFAULT_G_FOR_SECURE 320
47#define hash_init(h) (h)->init(h)
48#define hash_add(h,b,n) (h)->add(h,b,n)
49#define hash_finish(h,r) (h)->finish(h,r)
51#define hash(h,r,b,n) hash_init(h),hash_add(h,b,n),hash_finish(h,r)
53#define crypt_setkey(c,k) (c)->set_key((c)->data,k)
54#define crypt_crypt(c,out,in) (c)->crypt((c)->date,out,in)
66#define K_size(g) ((g)->key_hash->size)
68#define B_size(g) ((g)->prng_hash->size)
72#define H_size(g) (B_size(g)+K_size(g))
73#define H_current(g) (((g)->insecure_started && !(g)->secure_started) \
74 ? (g)->H_waiting : (g)->H)
121 for (
n = 0;
n <
g->npools; ++
n) {
122 g->pools[
n].bytes =
g->pools[
n].pool_size = 0;
131 g->rehash_size = ((
g->rehash_size+2*
g->pool_hash->size-1)/
g->pool_hash->size
132 /2)*
g->pool_hash->size*2;
144 g->secure_started =
g->insecure_started = 0;
204 for (
n = 0 ;
n <
g->npools && (
n == 0 ||
g->generation&(1 << (
n-1)))
207 g->pools[
n].bytes = 0;
212 if (!
g->insecure_started &&
g->generation >
g->g_for_insecure) {
213 g->insecure_started = 1;
214 if (!
g->secure_started) {
216 g->secure_base =
g->generation;
220 if (!
g->secure_started &&
g->generation >
g->secure_base+
g->g_for_secure) {
221 g->secure_started = 1;
235 if (++
g->next_pool ==
g->npools)
238 if (
p->pool_size <
p->bytes+1) {
243 p->pool_size = (
p->bytes+1)*2;
247 if (
p->bytes ==
g->rehash_size) {
250 for (
r = 0;
r <
p->bytes/2;
r+=
g->pool_hash->size)
251 hash(
g->pool_hash,
p->pool+
r,
p->pool+
r*2,
g->pool_hash->size*2);
257 if (
g->pools[0].bytes >=
g->reseed_size)
277 if (
g->random_bytes == 0) {
292 if (!
g->secure_started)
302 if (!
g->insecure_started)
310 g->secure_started = 0;
311 g->secure_base =
g->generation;
316 if (!
r->secure_started)
323 if (!
r->insecure_started)
static apr_random_t * all_random
#define hash_finish(h, r)
static void mix_pid(apr_random_t *g, unsigned char *H, pid_t pid)
#define APR_RANDOM_DEFAULT_RESEED_SIZE
#define hash_add(h, b, n)
static void rekey(apr_random_t *g)
#define APR_RANDOM_DEFAULT_G_FOR_SECURE
#define APR_RANDOM_DEFAULT_G_FOR_INSECURE
static void mixer(apr_random_t *g, pid_t pid)
#define APR_RANDOM_DEFAULT_REHASH_SIZE
#define APR_RANDOM_DEFAULT_POOLS
static apr_status_t random_cleanup(void *data)
static void apr_random_block(apr_random_t *g, unsigned char *random)
static void apr_random_bytes(apr_random_t *g, unsigned char *random, apr_size_t bytes)
APR Thread and Process Library.
#define APR_ENOTENOUGHENTROPY
#define apr_pcalloc(p, size)
const void apr_size_t bytes
apr_pool_t apr_crypto_hash_t * pool_hash
apr_pool_t apr_crypto_hash_t apr_crypto_hash_t * key_hash
apr_pool_t apr_crypto_hash_t apr_crypto_hash_t apr_crypto_hash_t * prng_hash
apr_crypto_hash_t * prng_hash
unsigned int g_for_secure
unsigned char * H_waiting
apr_random_pool_t * pools
apr_crypto_hash_t * pool_hash
unsigned int insecure_started
unsigned int secure_started
apr_crypto_hash_t * key_hash
unsigned char * randomness
unsigned int g_for_insecure