mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
random: Avoid magic numbers
Move RANDOM_FORTUNA_{NPOOLS,DEFPOOLSIZE} from fortuna.c to fortuna.h
and use RANDOM_FORTUNA_DEFPOOLSIZE in random_harvestq.c rather than
having a magic (albeit explained in a comment) number. The NPOOLS
value will be used in a later commit.
Reviewed by: cem
MFC after: 1 week
Sponsored by: Amazon
Differential Revision: https://reviews.freebsd.org/D46693
(cherry picked from commit 32fce09268ddd97efb4412529ba57293554c5985)
This commit is contained in:
parent
a112b062e0
commit
0e9cdcc514
3 changed files with 9 additions and 6 deletions
|
|
@ -72,8 +72,6 @@
|
|||
#include <dev/random/fortuna.h>
|
||||
|
||||
/* Defined in FS&K */
|
||||
#define RANDOM_FORTUNA_NPOOLS 32 /* The number of accumulation pools */
|
||||
#define RANDOM_FORTUNA_DEFPOOLSIZE 64 /* The default pool size/length for a (re)seed */
|
||||
#define RANDOM_FORTUNA_MAX_READ (1 << 20) /* Max bytes from AES before rekeying */
|
||||
#define RANDOM_FORTUNA_BLOCKS_PER_KEY (1 << 16) /* Max blocks from AES before rekeying */
|
||||
CTASSERT(RANDOM_FORTUNA_BLOCKS_PER_KEY * RANDOM_BLOCKSIZE ==
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@
|
|||
#ifndef SYS_DEV_RANDOM_FORTUNA_H_INCLUDED
|
||||
#define SYS_DEV_RANDOM_FORTUNA_H_INCLUDED
|
||||
|
||||
/* Defined in FS&K */
|
||||
#define RANDOM_FORTUNA_NPOOLS 32 /* The number of accumulation pools */
|
||||
#define RANDOM_FORTUNA_DEFPOOLSIZE 64 /* The default pool size/length for a (re)seed */
|
||||
|
||||
#ifdef _KERNEL
|
||||
typedef struct mtx mtx_t;
|
||||
#define RANDOM_RESEED_INIT_LOCK(x) mtx_init(&fortuna_state.fs_mtx, "reseed mutex", NULL, MTX_DEF)
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@
|
|||
#include <crypto/rijndael/rijndael-api-fst.h>
|
||||
#include <crypto/sha2/sha256.h>
|
||||
|
||||
#include <dev/random/fortuna.h>
|
||||
#include <dev/random/hash.h>
|
||||
#include <dev/random/randomdev.h>
|
||||
#include <dev/random/random_harvestq.h>
|
||||
|
|
@ -260,8 +261,8 @@ random_sources_feed(void)
|
|||
* stuck for a few seconds with random_kthread gradually collecting a
|
||||
* small chunk of entropy every 1 / RANDOM_KTHREAD_HZ seconds.
|
||||
*
|
||||
* The value 64 below is RANDOM_FORTUNA_DEFPOOLSIZE, i.e. chosen to
|
||||
* fill Fortuna's pools in the default configuration. With another
|
||||
* We collect RANDOM_FORTUNA_DEFPOOLSIZE bytes per pool, i.e. enough
|
||||
* to fill Fortuna's pools in the default configuration. With another
|
||||
* PRNG or smaller pools for Fortuna, we might collect more entropy
|
||||
* than needed to fill the pools, but this is harmless; alternatively,
|
||||
* a different PRNG, larger pools, or fast entropy sources which are
|
||||
|
|
@ -271,8 +272,8 @@ random_sources_feed(void)
|
|||
* try again for a large amount of entropy.
|
||||
*/
|
||||
if (!p_random_alg_context->ra_seeded())
|
||||
npools = howmany(p_random_alg_context->ra_poolcount * 64,
|
||||
sizeof(entropy));
|
||||
npools = howmany(p_random_alg_context->ra_poolcount *
|
||||
RANDOM_FORTUNA_DEFPOOLSIZE, sizeof(entropy));
|
||||
|
||||
/*
|
||||
* Step over all of live entropy sources, and feed their output
|
||||
|
|
|
|||
Loading…
Reference in a new issue