Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/random/randomdev.c
Show First 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | READ_RANDOM(void *random_buf, u_int len) | ||||
u_int read_directly_len; | u_int read_directly_len; | ||||
KASSERT(random_buf != NULL, ("No suitable random buffer in %s", __func__)); | KASSERT(random_buf != NULL, ("No suitable random buffer in %s", __func__)); | ||||
p_random_alg_context->ra_pre_read(); | p_random_alg_context->ra_pre_read(); | ||||
if (len == 0) | if (len == 0) | ||||
return; | return; | ||||
#ifdef INVARIANTS | |||||
if ((curthread->td_pflags & TDP_RNG_SEEDED) == 0) | |||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, | |||||
"read_random may block once"); | |||||
#endif | |||||
/* (Un)Blocking logic */ | /* (Un)Blocking logic */ | ||||
if (__predict_false(!p_random_alg_context->ra_seeded())) { | if (__predict_false(!p_random_alg_context->ra_seeded())) { | ||||
if (random_bypass_before_seeding) { | if (random_bypass_before_seeding) { | ||||
if (!read_random_bypassed_before_seeding) { | if (!read_random_bypassed_before_seeding) { | ||||
if (!random_bypass_disable_warnings) | if (!random_bypass_disable_warnings) | ||||
printf("read_random: WARNING: bypassing" | printf("read_random: WARNING: bypassing" | ||||
" request for random data because " | " request for random data because " | ||||
"the random device is not yet " | "the random device is not yet " | ||||
Show All 27 Lines | if (read_directly_len < len) { | ||||
explicit_bzero(remainder_buf, sizeof(remainder_buf)); | explicit_bzero(remainder_buf, sizeof(remainder_buf)); | ||||
} | } | ||||
} | } | ||||
bool | bool | ||||
IS_RANDOM_SEEDED(void) | IS_RANDOM_SEEDED(void) | ||||
{ | { | ||||
return (p_random_alg_context->ra_seeded()); | bool seeded; | ||||
seeded = p_random_alg_context->ra_seeded(); | |||||
#ifdef INVARIANTS | |||||
/* | |||||
* Mute false-positive WITNESS_WARNs for threads that have already | |||||
* confirmed seeded status. | |||||
*/ | |||||
if (seeded) | |||||
curthread->td_pflags |= TDP_RNG_SEEDED; | |||||
#endif | |||||
return (seeded); | |||||
} | } | ||||
static __inline void | static __inline void | ||||
randomdev_accumulate(uint8_t *buf, u_int count) | randomdev_accumulate(uint8_t *buf, u_int count) | ||||
{ | { | ||||
static u_int destination = 0; | static u_int destination = 0; | ||||
static struct harvest_event event; | static struct harvest_event event; | ||||
static struct randomdev_hash hash; | static struct randomdev_hash hash; | ||||
▲ Show 20 Lines • Show All 185 Lines • Show Last 20 Lines |