The branch main has been updated by cperciva:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=32fce09268ddd97efb4412529ba57293554c5985

commit 32fce09268ddd97efb4412529ba57293554c5985
Author:     Colin Percival <cperc...@freebsd.org>
AuthorDate: 2024-09-18 05:12:04 +0000
Commit:     Colin Percival <cperc...@freebsd.org>
CommitDate: 2024-09-22 07:35:47 +0000

    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
---
 sys/dev/random/fortuna.c         | 2 --
 sys/dev/random/fortuna.h         | 4 ++++
 sys/dev/random/random_harvestq.c | 9 +++++----
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/sys/dev/random/fortuna.c b/sys/dev/random/fortuna.c
index 53b629ac378c..c4282c723a44 100644
--- a/sys/dev/random/fortuna.c
+++ b/sys/dev/random/fortuna.c
@@ -71,8 +71,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 ==
diff --git a/sys/dev/random/fortuna.h b/sys/dev/random/fortuna.h
index cb4683514989..7378edb9238c 100644
--- a/sys/dev/random/fortuna.h
+++ b/sys/dev/random/fortuna.h
@@ -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)
diff --git a/sys/dev/random/random_harvestq.c b/sys/dev/random/random_harvestq.c
index 4605d811a239..a8ccabd1a902 100644
--- a/sys/dev/random/random_harvestq.c
+++ b/sys/dev/random/random_harvestq.c
@@ -54,6 +54,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>
@@ -259,8 +260,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
@@ -270,8 +271,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

Reply via email to