2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

protect isc_entropy_stats() with a lock, and use a static dumpstats() internally when a lock is already held, for debugging. Add isc_entropy_putdata() which can be used to prime the pool.

This commit is contained in:
Michael Graff 2000-06-17 00:43:11 +00:00
parent 0c21ac7de1
commit 9ceb50ed04
2 changed files with 40 additions and 9 deletions

View File

@ -206,8 +206,22 @@ isc_entropy_getdata(isc_entropy_t *ent, void *data, unsigned int length,
* sources.
*/
void
isc_entropy_putdata(isc_entropy_t *ent, void *data, unsigned int length,
isc_uint32_t entropy);
/*
* Add "length" bytes in "data" to the entropy pool, incrementing the pool's
* entropy count by "entropy."
*
* These bytes will prime the pseudorandom portion even no entropy is actually
* added.
*/
void
isc_entropy_stats(isc_entropy_t *ent, FILE *out);
/*
* Dump some (trivial) stats to the stdio stream "out".
*/
ISC_LANG_ENDDECLS

View File

@ -278,6 +278,7 @@ entropypool_adddata(isc_entropy_t *ent, void *p, unsigned int len,
}
add_entropy(ent, entropy);
subtract_pseudo(ent, entropy);
}
static isc_uint32_t
@ -436,11 +437,6 @@ fillpool(isc_entropy_t *ent, unsigned int needed, isc_boolean_t blocking) {
goto again;
}
/*
* Adjust counts.
*/
subtract_pseudo(ent, added);
/*
* Mark as initialized if we've added enough data.
*/
@ -967,13 +963,22 @@ isc_entropy_addsample(isc_entropysource_t *source, isc_uint32_t sample,
UNLOCK(&ent->lock);
}
/*
* This function ignores locking. Use at your own risk.
*/
void
isc_entropy_stats(isc_entropy_t *ent, FILE *out) {
isc_entropy_putdata(isc_entropy_t *ent, void *data, unsigned int length,
isc_uint32_t entropy)
{
REQUIRE(VALID_ENTROPY(ent));
LOCK(&ent->lock);
entropypool_adddata(ent, data, length, entropy);
if (ent->initialized < THRESHOLD_BITS)
ent->initialized = THRESHOLD_BITS;
UNLOCK(&ent->lock);
}
static void
dumpstats(isc_entropy_t *ent, FILE *out) {
fprintf(out,
"Entropy pool %p: refcnt %u"
" cursor %u, rotate %u entropy %u pseudo %u nsources %u"
@ -984,6 +989,18 @@ isc_entropy_stats(isc_entropy_t *ent, FILE *out) {
ent->nsources, ent->nextsource, ent->initialized);
}
/*
* This function ignores locking. Use at your own risk.
*/
void
isc_entropy_stats(isc_entropy_t *ent, FILE *out) {
REQUIRE(VALID_ENTROPY(ent));
LOCK(&ent->lock);
dumpstats(ent, out);
UNLOCK(&ent->lock);
}
void
isc_entropy_attach(isc_entropy_t *ent, isc_entropy_t **entp) {
REQUIRE(VALID_ENTROPY(ent));