From nobody Sun Sep 22 07:36:39 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XBHxg4q8Jz5XYPl; Sun, 22 Sep 2024 07:36:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XBHxg3sftz44h4; Sun, 22 Sep 2024 07:36:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726990599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6LHW/8OIXSd/ckrdqmnuNirduzZNXZj+5Ad4hS0JJNY=; b=grFQsuKwEioENgjWdS76vr7Jir5WVTQDEwhYCkvGxcGbk4zHtcRviUArv4Rz+cs4i1ZzMw FFlfysXf8Agenh4CvEIAVT5zLY5ciVBqB5J9+EEFKPqlpyTnFrAgGaSqlFhUJMdOQBZI9V Mpkk96L6+7mR78PUk80bM6e0NHSxnN/LM4GfRmnqT7ejeZuK23JYD8gSiex8HZbd67DMMd GfMOqfeZfkZrMXx/nYicN4EpOo0qW4eltPdl9W8JqhCLbK12xnyTyW7xOTfBOQeBeTsubK EDA3fljDM60cfwZpvuDGDEl+V2UGgrJtm6WE7DcJjfetITGtP6PERk1P0vaJJA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726990599; a=rsa-sha256; cv=none; b=ZkNAauOjs7olyBnoobU1OQfvn4ZqUP0zZNYOve7nvU+Jj2pXSnGguOhPyS66UKdYhKAj+Q +/n63gmAXe8yXyKCRQijDtalrjy4dpMXMw3zTkXaqgb4zbEKyll/grW0QMH14rKTGChuNa VFJ+2OfxQr3FfqIMPcbcF7sSZ+0LIj9xa2eDwZjtnzkMI6EJHvWk7QR1SaehvkMpXgsdOo h8QigsdaMHDPxYutAYU1dDCDKKqsV/J/SzliNhpnt6ypIsF4o3mgzZkg/zWqv71tA8pJQ7 U3XE7AmoKeTui2rke308hbe/6TNwFi1zI5fTr6XOZ3JsuJaoGBxKom9+0uSKOg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726990599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6LHW/8OIXSd/ckrdqmnuNirduzZNXZj+5Ad4hS0JJNY=; b=SG8ps0HkaiXwIqM532HZJJDjIObvuVPPGfTu5KVU5y9YZ2HBVtPcXWlTi4Djrj48DOgrDu 4Yk+ECDQGBEFKEGVNsFckaXCsUNahnOmipabAfjHuWcCn9YZoDX6zC/Mqf4X/aFgue4mzk QMAFzaowc0/7sON2YkaQHNa1KiQlC1yYIT2GDlXwvA6D65sGdZj2sN9Q+Cb+AVxVKt8qp9 tCq8Ekah5nBUfjLUVPH+bOYTO3qm89kJqldRSFTN33CXckHFTRh0wk6WjsvqU0cmK404Zr DzepQOhUvOLFd7U0GidfxAxJDmscoc+rM6Ce+RemCvfYrj0Bbf50/O/XGjU0yA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XBHxg38hjz16fQ; Sun, 22 Sep 2024 07:36:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48M7adIl096990; Sun, 22 Sep 2024 07:36:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48M7ad03096987; Sun, 22 Sep 2024 07:36:39 GMT (envelope-from git) Date: Sun, 22 Sep 2024 07:36:39 GMT Message-Id: <202409220736.48M7ad03096987@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Colin Percival Subject: git: 32fce09268dd - main - random: Avoid magic numbers List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 32fce09268ddd97efb4412529ba57293554c5985 Auto-Submitted: auto-generated The branch main has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=32fce09268ddd97efb4412529ba57293554c5985 commit 32fce09268ddd97efb4412529ba57293554c5985 Author: Colin Percival AuthorDate: 2024-09-18 05:12:04 +0000 Commit: Colin Percival 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 /* 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 #include +#include #include #include #include @@ -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