random(4): deduplicate explicit_bzero() in harvest

Pull the responsibility for zeroing events, which is general to any
conceivable implementation of a random device algorithm, out of the
algorithm-specific Fortuna code and into the callers.  Most callers
indirect through random_fortuna_process_event(), so add the logic there.
Most callers already explicitly bzeroed the events they provided, so the
logic in Fortuna was mostly redundant.

Add one missing bzero in randomdev_accumulate().  Also, remove a redundant
bzero in the same function -- randomdev_hash_finish() is obliged to bzero
the hash state.

Reviewed by:	delphij
Approved by:	secteam(delphij)
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D20318
This commit is contained in:
cem 2019-05-23 21:02:27 +00:00
parent 6d22450061
commit db6f8db5cc
3 changed files with 2 additions and 4 deletions

View File

@ -254,7 +254,6 @@ random_fortuna_process_event(struct harvest_event *event)
fortuna_state.fs_pool[pl].fsp_length = MIN(RANDOM_FORTUNA_MAXPOOLSIZE,
fortuna_state.fs_pool[pl].fsp_length +
sizeof(event->he_somecounter) + event->he_size);
explicit_bzero(event, sizeof(*event));
RANDOM_RESEED_UNLOCK();
}

View File

@ -163,6 +163,7 @@ random_harvestq_fast_process_event(struct harvest_event *event)
#if defined(RANDOM_LOADABLE)
RANDOM_CONFIG_S_UNLOCK();
#endif
explicit_bzero(event, sizeof(*event));
}
static void
@ -437,7 +438,6 @@ random_harvestq_prime(void *unused __unused)
harvest_context.hc_destination[RANDOM_CACHED]++;
memcpy(event.he_entropy, data + i, sizeof(event.he_entropy));
random_harvestq_fast_process_event(&event);
explicit_bzero(&event, sizeof(event));
}
explicit_bzero(data, size);
if (bootverbose)
@ -540,7 +540,6 @@ random_harvest_direct_(const void *entropy, u_int size, enum random_entropy_sour
event.he_destination = harvest_context.hc_destination[origin]++;
memcpy(event.he_entropy, entropy, size);
random_harvestq_fast_process_event(&event);
explicit_bzero(&event, sizeof(event));
}
void

View File

@ -321,7 +321,6 @@ randomdev_accumulate(uint8_t *buf, u_int count)
timestamp = (uint32_t)get_cyclecount();
randomdev_hash_iterate(&hash, &timestamp, sizeof(timestamp));
randomdev_hash_finish(&hash, entropy_data);
explicit_bzero(&hash, sizeof(hash));
for (i = 0; i < RANDOM_KEYSIZE_WORDS; i += sizeof(event.he_entropy)/sizeof(event.he_entropy[0])) {
event.he_somecounter = (uint32_t)get_cyclecount();
event.he_size = sizeof(event.he_entropy);
@ -330,6 +329,7 @@ randomdev_accumulate(uint8_t *buf, u_int count)
memcpy(event.he_entropy, entropy_data + i, sizeof(event.he_entropy));
p_random_alg_context->ra_event_processor(&event);
}
explicit_bzero(&event, sizeof(event));
explicit_bzero(entropy_data, sizeof(entropy_data));
}