int rndtest_buf(unsigned char *buf) { struct rndtest_state rsp; memset(&rsp, 0, sizeof(rsp)); rsp.rs_buf = buf; rndtest_test(&rsp); return(rsp.rs_discard); }
void rndtest_harvest(struct rndtest_state *rsp, void *buf, u_int len) { size_t i; /* * If enabled, collect data and run tests when we have enough. */ if (rsp->rs_collect) { for (i = 0; i < len; i++) { *rsp->rs_current = ((u_char *) buf)[i]; if (++rsp->rs_current == rsp->rs_end) { rndtest_test(rsp); rsp->rs_current = rsp->rs_begin; /* * If tests passed, turn off collection and * schedule another test. Otherwise we keep * testing until the data looks ok. */ if (!rsp->rs_discard && rndtest_retest != 0) { rsp->rs_collect = 0; callout_reset(&rsp->rs_to, hz * rndtest_retest, rndtest_timeout, rsp); break; } } } } /* * Only stir entropy that passes muster into the pool. */ if (rsp->rs_discard) rndstats.rst_discard += len; else { #if __FreeBSD_version < 500000 /* XXX verify buffer is word aligned */ u_int32_t *p = buf; for (len /= sizeof (u_int32_t); len; len--) add_true_randomness(*p++); #else random_harvest(buf, len, len*NBBY, 0, RANDOM_PURE); #endif } }
void rndtest_harvest(struct rndtest_state *rsp, void *buf, u_int len) { size_t i; /* * If enabled, collect data and run tests when we have enough. */ if (rsp->rs_collect) { for (i = 0; i < len; i++) { *rsp->rs_current = ((u_char *) buf)[i]; if (++rsp->rs_current == rsp->rs_end) { rndtest_test(rsp); rsp->rs_current = rsp->rs_begin; /* * If tests passed, turn off collection and * schedule another test. Otherwise we keep * testing until the data looks ok. */ if (!rsp->rs_discard && rndtest_retest != 0) { rsp->rs_collect = 0; callout_reset(&rsp->rs_to, hz * rndtest_retest, rndtest_timeout, rsp); break; } } } } /* * Only stir entropy that passes muster into the pool. */ if (rsp->rs_discard) rndstats.rst_discard += len; else /* MarkM: FIX!! Check that this does not swamp the harvester! */ random_harvest_queue(buf, len, RANDOM_PURE_RNDTEST); }