Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions doc/dox_comments/header_files/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ int wc_FreeNetRandom(void);
MAX_REQUEST_LEN
\return DRBG_CONT_FIPS_E wc_RNG_GenerateBlock: Hash_gen returned
DRBG_CONT_FAILURE
\return ENTROPY_RT_E or ENTROPY_APT_E wc_InitRng: the SP 800-90B seed
health test rejected the entropy gathered to instantiate
\return RNG_FAILURE_E wc_RNG_GenerateBlock: Default error. rng’s
status originally not ok, or set to DRBG_FAILED
\return BAD_MUTEX_E the lock that lets threads share this rng could not
Expand Down Expand Up @@ -157,6 +159,8 @@ int wc_InitRng(WC_RNG* rng);
\return 0 on success
\return BAD_FUNC_ARG an input is null or sz exceeds MAX_REQUEST_LEN
\return DRBG_CONT_FIPS_E Hash_gen returned DRBG_CONT_FAILURE
\return ENTROPY_RT_E or ENTROPY_APT_E the SP 800-90B seed health test
rejected the entropy gathered for a reseed
\return RNG_FAILURE_E Default error. rng’s status originally not
ok, or set to DRBG_FAILED
\return BAD_MUTEX_E the rng's lock could not be taken
Expand Down Expand Up @@ -544,7 +548,6 @@ int wc_RNG_DRBG_Reseed(WC_RNG* rng, const byte* seed, word32 seedSz);
\return BAD_FUNC_ARG If seed is NULL
\return ENTROPY_RT_E || ENTROPY_APT_E Validation failed
\return ENTROPY_APT_E The adaptive proportion test failed.
\return MEMORY_E Allocation failed.

\param seed Seed to test
\param seedSz Seed size
Expand Down Expand Up @@ -1009,6 +1012,9 @@ int wc_RNG_DRBG_ScheduleReseed(WC_RNG* rng);
\return DRBG_CONT_FIPS_E The continuous test failed; the DRBG is out of
service.
\return RNG_FAILURE_E The DRBG is out of service or reseeding failed.
\return ENTROPY_RT_E or ENTROPY_APT_E The SP 800-90B seed health test
rejected the gathered seed; the reseed did not happen and the instance
remains usable until its reseed interval is reached.

\param rng The RNG object to reseed.
\param nonce Optional additional input.
Expand Down Expand Up @@ -1303,7 +1309,8 @@ int wc_RNG_DRBG_GetNextSeedRBGCStratum(const WC_RNG* rng);

\return 0 Bytes were banked (bank may or may not yet be complete).
\return ALREADY_E The bank is ready or being consumed.
\return NOT_READY_E The health test could not run; simply retry.
\return ENTROPY_RT_E or ENTROPY_APT_E The SP 800-90B seed health test
rejected the banked material, which is burned.
\return BAD_FUNC_ARG rng is null or n is 0.
\return MISSING_RNG_E rng has no DRBG (RDRAND et al.).

Expand Down Expand Up @@ -1334,7 +1341,8 @@ int wc_RNG_DRBG_NextSeedGenerate(WC_RNG* rng, word32 n);

\return 0 Bytes were banked.
\return ALREADY_E The bank is ready or being consumed.
\return NOT_READY_E The health test could not run; simply retry.
\return ENTROPY_RT_E or ENTROPY_APT_E The SP 800-90B seed health test
rejected the banked material, which is burned.
\return BAD_FUNC_ARG rng or root is null, or n is 0.
\return MISSING_RNG_E rng has no DRBG (RDRAND et al.).
\return SEQ_OVERFLOW_E root's stratum is at the representable maximum.
Expand Down Expand Up @@ -1388,6 +1396,8 @@ int wc_RNG_DRBG_NextSeedCurrent(WC_RNG* rng, WC_ATOMIC_INT_ARG* n);
\return NOT_READY_E No bank is ready.
\return BAD_FUNC_ARG rng is null.
\return MISSING_RNG_E rng has no DRBG (RDRAND et al.).
\return ENTROPY_RT_E or ENTROPY_APT_E A seed health test failed on
the reseed this performs; the instance is condemned.

\param rng The RNG object to reseed.

Expand Down Expand Up @@ -1417,6 +1427,8 @@ int wc_RNG_DRBG_NextSeedNow(WC_RNG* rng);
\return NOT_READY_E No bank is ready.
\return BAD_FUNC_ARG rng is null, or nonce is null with nonceSz nonzero.
\return MISSING_RNG_E rng has no DRBG (RDRAND et al.).
\return ENTROPY_RT_E or ENTROPY_APT_E A seed health test failed on
the reseed this performs; the instance is condemned.
\return DRBG_CONT_FIPS_E The continuous test failed; the DRBG is out of
service.
\return RNG_FAILURE_E The DRBG is out of service.
Expand Down
6 changes: 4 additions & 2 deletions doc/dox_comments/header_files/rng_bank.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ int wc_rng_bank_get_inst_id(struct wc_rng_bank_inst *rng_inst);

\return 0 Bytes were banked.
\return ALREADY_E The instance's bank is ready or being consumed.
\return NOT_READY_E The health test could not run; simply retry.
\return ENTROPY_RT_E or ENTROPY_APT_E The SP 800-90B seed health test
rejected the banked material, which is burned.
\return BAD_FUNC_ARG bank is null, inst_offset is out of range, or n
is 0.

Expand Down Expand Up @@ -437,7 +438,8 @@ int wc_rng_bank_next_seed_generate(struct wc_rng_bank *bank, int inst_offset,

\return 0 Bytes were banked.
\return ALREADY_E The instance's bank is ready or being consumed.
\return NOT_READY_E The health test could not run; simply retry.
\return ENTROPY_RT_E or ENTROPY_APT_E The SP 800-90B seed health test
rejected the banked material, which is burned.
\return BAD_FUNC_ARG bank or root is null, inst_offset is out of range,
or n is 0.

Expand Down
31 changes: 21 additions & 10 deletions linuxkm/lkcapi_sha_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2747,10 +2747,6 @@ static void wc_linuxkm_vmgenid_poll_teardown(
* draining nextSeeds as fast as it can. Per-turn classification of
* wc_rng_bank_next_seed_generate() returns:
* 0 gathered/published -- progress;
* NOT_READY_E transient (incl. a burned bank, which is refill-eligible
* now, and an environmental TestSeed miss with the aperture
* preserved) -- progress, so a forced burn can never induce
* a nap;
* ALREADY_E ready or consuming -- no work on this instance;
* BUSY_E instance-op gate held by a reinit -- no progress here,
* but the gate holder is making it;
Expand Down Expand Up @@ -3219,7 +3215,7 @@ static int wc_linuxkm_entropy_daemon(void *arg)

ret = wc_rng_bank_next_seed_generate(
bank, i, WC_LINUXKM_ENTROPY_DAEMON_GRANULE);
if ((ret == 0) || (ret == WC_NO_ERR_TRACE(NOT_READY_E))) {
if (ret == 0) {
progress = 1;
}
else if ((ret == WC_NO_ERR_TRACE(ALREADY_E)) ||
Expand Down Expand Up @@ -3729,6 +3725,16 @@ WC_MAYBE_UNUSED static int linuxkm_InitRng_DefaultRef(WC_RNG* rng) {
#define WC_LINUXKM_DRBG_SMALL_LIMIT 8
#endif

/* Reinstantiations attempted when a generate keeps failing. Each one gathers
* a fresh seed and health tests it, so this never re-judges rejected data. */
#ifndef WC_LINUXKM_DRBG_REINIT_TRIES
#define WC_LINUXKM_DRBG_REINIT_TRIES 3
#endif
/* Zero would silently turn off recovery rather than bounding it. */
#if WC_LINUXKM_DRBG_REINIT_TRIES < 1
#error WC_LINUXKM_DRBG_REINIT_TRIES must be at least 1
#endif

#ifdef WC_RNG_HAVE_POOL
wc_static_assert(WC_LINUXKM_DRBG_SMALL_LIMIT <= WC_LINUXKM_RNG_POOL_SIZE);
#endif
Expand Down Expand Up @@ -3956,13 +3962,18 @@ static int wc_linuxkm_drbg_generate(struct wc_rng_bank *ctx,
if (ret == 0)
continue;

if (unlikely(ret == WC_NO_ERR_TRACE(RNG_FAILURE_E))) {
/* A seed health-test alarm now arrives as its own SP 800-90B code;
* it is the same recoverable condition as RNG_FAILURE_E. */
if (unlikely((ret == WC_NO_ERR_TRACE(RNG_FAILURE_E)) ||
(ret == WC_NO_ERR_TRACE(ENTROPY_RT_E)) ||
(ret == WC_NO_ERR_TRACE(ENTROPY_APT_E))))
{
if (slen > 0)
break;

if (retried)
if (retried >= WC_LINUXKM_DRBG_REINIT_TRIES)
break;
retried = 1;
++retried;
Comment thread
kaleb-himes marked this conversation as resolved.

if (! can_wait)
break;
Expand Down Expand Up @@ -4035,13 +4046,13 @@ static int wc_linuxkm_drbg_generate(struct wc_rng_bank *ctx,

if (ret == 0) {
pr_warn_ratelimited("WARNING: reinitialized DRBG #%d after "
"RNG_FAILURE_E from wc_RNG_GenerateBlock().\n",
"a seed health or RNG failure from wc_RNG_GenerateBlock().\n",
wc_rng_bank_get_inst_id(drbg));
continue;
}
else {
pr_err_ratelimited("ERROR: reinitialization of DRBG #%d after "
"RNG_FAILURE_E failed with ret %d.\n",
"a seed health or RNG failure failed with ret %d.\n",
wc_rng_bank_get_inst_id(drbg), ret);
break;
}
Expand Down
Loading
Loading