Date: Thu, 23 May 2019 21:02:27 +0000 (UTC) From: Conrad Meyer <cem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r348199 - head/sys/dev/random Message-ID: <201905232102.x4NL2RDC049069@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: cem Date: Thu May 23 21:02:27 2019 New Revision: 348199 URL: https://svnweb.freebsd.org/changeset/base/348199 Log: 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 Modified: head/sys/dev/random/fortuna.c head/sys/dev/random/random_harvestq.c head/sys/dev/random/randomdev.c Modified: head/sys/dev/random/fortuna.c ============================================================================== --- head/sys/dev/random/fortuna.c Thu May 23 20:18:46 2019 (r348198) +++ head/sys/dev/random/fortuna.c Thu May 23 21:02:27 2019 (r348199) @@ -254,7 +254,6 @@ random_fortuna_process_event(struct harvest_event *eve 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(); } Modified: head/sys/dev/random/random_harvestq.c ============================================================================== --- head/sys/dev/random/random_harvestq.c Thu May 23 20:18:46 2019 (r348198) +++ head/sys/dev/random/random_harvestq.c Thu May 23 21:02:27 2019 (r348199) @@ -163,6 +163,7 @@ random_harvestq_fast_process_event(struct harvest_even #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 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 Modified: head/sys/dev/random/randomdev.c ============================================================================== --- head/sys/dev/random/randomdev.c Thu May 23 20:18:46 2019 (r348198) +++ head/sys/dev/random/randomdev.c Thu May 23 21:02:27 2019 (r348199) @@ -321,7 +321,6 @@ randomdev_accumulate(uint8_t *buf, u_int count) timestamp = (uint32_t)get_cyclecount(); randomdev_hash_iterate(&hash, ×tamp, 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)); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905232102.x4NL2RDC049069>