From nobody Sun Sep 29 15:25:12 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 4XGp142KXwz5XpJn; Sun, 29 Sep 2024 15:25:12 +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 4XGp141kS7z4kcG; Sun, 29 Sep 2024 15:25:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727623512; 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=Lwr3LL1FodNBjkflKzWPYpr+O1blrZSyXQia6PBo7J4=; b=SlSRLpMnJWsYWRAu9/MLEU/DX7MZdzItLq+vFJhLUiaiBBS50xljrf3PozVCeAIRRQ1Jf+ NnVFyTdBVGvqwC4EsyZfgWI0Abfh037KWfM1nagvtTTgC3n7F7X9QJp8tc3I5i4GfXFs00 Iyq+gPrD42RTTednCKYTZiFmxBJcTRWnLGRZYIizOjeP09eGu6eRrSFHVzUoApKkmosHb7 EbK1UKDPk2AxNfk3Ar+Hde41Jb7HBulDus9g8RIdpI480tYDDXZ8BeInr9uilsGzXHE39V B10nbUYKoYscxc6HvpgSg3h6vF/4DEmV78EDHNqM0oSga8O2eCesVVX+j4m4VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727623512; 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=Lwr3LL1FodNBjkflKzWPYpr+O1blrZSyXQia6PBo7J4=; b=XNAdViMryxM9vq4Ad8uqGvACVCQQJyq5079RfUri/dY/28thY52UYFOD2dVq0urnZxXWkz SWU6zNOHb3kqZI7GY3nfL57+tZFmMPkiXGPP6YrogK5PpO0/icsaptnidRwENa22HEW9ov bRg+HyBayv66Yb4jJR6CrUeTqQaunpmV6Vu8vTPhd3gtkLLdAEmtweUEE777ljoADLmM5K jd4EbIwnGnoP8QDdeI+rcpIF3psav6I3ZFIVjLnBTBup6meytWL1wrvhdX9VE/7ztyQ1RV VZCAefWEk6I6t2b6Oz6lBYoT7QGkCe0U2bCdtGOBWT6Ud2aV8objm6UobmFy6g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727623512; a=rsa-sha256; cv=none; b=YTVMiD/iW3FQFJ45K3YVKzjkEjU8I66tqnl4kApiQNRhdI5dqe5jSuulvm0qLAZn9nj04w J2pG/knmzuxL/vbgg7ERZoCQlh6jGjxV5KqWXp2oeBqHe/F+XxH4nM+NEURJ/zfjiDTWEE XKqIc55PHLsVk+gwVmYOVZFNaR6HCVlirvHuYosv3Ni19d02vDvir3O6vNklCN0Byt57t4 ZpKntHwAIZNik4QAykwzMwO+theany+lJaxypmIjKbqPd6bOF8z7gm0HV1O5u+aTwZxDgb qY4tZnh7QbmSXZz8r7t58lJxVoIVGIU9Hy27Hxm7FVZJwGxeCfbw1+tdBIvUXA== 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 4XGp1417BqzF9p; Sun, 29 Sep 2024 15:25:12 +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 48TFPCFY030280; Sun, 29 Sep 2024 15:25:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48TFPCEu030276; Sun, 29 Sep 2024 15:25:12 GMT (envelope-from git) Date: Sun, 29 Sep 2024 15:25:12 GMT Message-Id: <202409291525.48TFPCEu030276@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Colin Percival Subject: git: 0e9cdcc5141e - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 0e9cdcc5141e82ac3d9fa8331c3a4ed19933afa9 Auto-Submitted: auto-generated The branch stable/14 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=0e9cdcc5141e82ac3d9fa8331c3a4ed19933afa9 commit 0e9cdcc5141e82ac3d9fa8331c3a4ed19933afa9 Author: Colin Percival AuthorDate: 2024-09-18 05:12:04 +0000 Commit: Colin Percival CommitDate: 2024-09-29 15:24:52 +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 (cherry picked from commit 32fce09268ddd97efb4412529ba57293554c5985) --- 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 11b2dcde1db8..ec27acc63b29 100644 --- a/sys/dev/random/fortuna.c +++ b/sys/dev/random/fortuna.c @@ -72,8 +72,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 09b81950281b..cb01f7b77195 100644 --- a/sys/dev/random/random_harvestq.c +++ b/sys/dev/random/random_harvestq.c @@ -55,6 +55,7 @@ #include #include +#include #include #include #include @@ -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