git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Ramsay Jones <ramsay@ramsayjones.plus.com>
Cc: GIT Mailing-list <git@vger.kernel.org>,
	 Patrick Steinhardt <ps@pks.im>,
	Adam Dinwoodie <git@dinwoodie.org>
Subject: Re: [PATCH v3 13/13] config.mak.uname: set CSPRNG_METHOD to getrandom on Linux
Date: Thu, 17 Apr 2025 06:55:52 -0700	[thread overview]
Message-ID: <xmqq4iymgadz.fsf@gitster.g> (raw)
In-Reply-To: <20250416231835.2492562-14-ramsay@ramsayjones.plus.com> (Ramsay Jones's message of "Thu, 17 Apr 2025 00:18:34 +0100")

Ramsay Jones <ramsay@ramsayjones.plus.com> writes:

> Commit 05cd988dce ("wrapper: add a helper to generate numbers from a
> CSPRNG", 2022-01-17) added a csprng_bytes() function which used one
> of several interfaces to provide a source of cryptographically secure
> pseudorandom numbers. The CSPRNG_METHOD make variable was provided to
> determine the choice of available 'backends' for the source of random
> bytes.
>
> Commit 05cd988dce did not set CSPRNG_METHOD in the Linux section of
> the config.mak.uname file, so it defaults to using '/dev/urandom' as
> the source of random bytes. The 'backend' values which could be used
> on Linux are 'arc4random', 'getrandom' or 'getentropy' ('openssl' is
> an option, but seems to be discouraged).
>
> The arc4random routines (ar4random_buf() is the one actually used) were

arc4random_buf(), if I am not mistaken?

> added to glibc in version 2.36, while both getrandom() and getentropy()
> were included in 2.25. So, some of the more up-to-date distributions of
> Linux (eg Debian 12, Ubuntu 24.04) would be able to use the 'arc4random'
> setting. All currently supported distributions have glibc 2.25 or later
> (RHEL 8 has v2.28) and, therefore, have support for the 'getrandom' and
> 'getentropy' settings.

OK.  This explains that getrandom/getentropy have better
availability than arc4random.

> The arc4random routines on the *BSDs (along with cygwin) implement the
> ChaCha20 stream cipher algorithm (see RFC8439) in userspace, rather than
> as a system call, and are thus somewhat faster (having avoided a context
> switch to the kernel). In contrast, on Linux all three functions are
> simple wrappers around the same kernel CSPRNG syscall.

OK.  With this and the previous paragraph, we establish that there
is no reason to use arc4random on Linux, while on BSDs and Cygwin,
it is a natural choice.

Very clearly explained.  Thanks.

> If the meson build system is used on a newer platform, then they will be
> configured to use 'arc4random', whereas the make build will currently
> default to using '/dev/urandom' on Linux.



> Since there is no advantage,
> in terms of performance, to the 'arc4random' setting, the 'getrandom'
> setting should be preferred from an availability perspective. (Also, the
> current uses of csprng_bytes() are not in any hot path).
>
> In order to set an appropriate default, set the CSPRNG_METHOD build
> variable to 'getrandom' in the Linux section of the 'config.mak.uname'
> file.
>
> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
> ---
>  config.mak.uname | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/config.mak.uname b/config.mak.uname
> index 330741eb5a..db22a8fb31 100644
> --- a/config.mak.uname
> +++ b/config.mak.uname
> @@ -50,6 +50,7 @@ ifeq ($(uname_S),Linux)
>  	HAVE_ALLOCA_H = YesPlease
>  	# override in config.mak if you have glibc >= 2.38
>  	NO_STRLCPY = YesPlease
> +	CSPRNG_METHOD = getrandom
>  	HAVE_PATHS_H = YesPlease
>  	LIBC_CONTAINS_LIBINTL = YesPlease
>  	HAVE_DEV_TTY = YesPlease

  reply	other threads:[~2025-04-17 13:55 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-15  2:46 [PATCH 00/12] miscellaneous build mods (part 1) Ramsay Jones
2025-04-06 19:38 ` [PATCH v2 00/13] " Ramsay Jones
2025-04-06 19:38   ` [PATCH v2 01/13] meson.build: remove -DCURL_DISABLE_TYPECHECK Ramsay Jones
2025-04-06 19:38   ` [PATCH v2 02/13] Makefile: only set some BASIC_CFLAGS when RUNTIME_PREFIX is set Ramsay Jones
2025-04-14  7:54     ` Patrick Steinhardt
2025-04-06 19:38   ` [PATCH v2 03/13] meson.build: only set build variables for non-default values Ramsay Jones
2025-04-06 19:49     ` Ramsay Jones
2025-04-14  7:54       ` Patrick Steinhardt
2025-04-14 19:19         ` [-SPAM-] " Ramsay Jones
2025-04-15  5:59           ` Patrick Steinhardt
2025-04-06 19:38   ` [PATCH v2 04/13] meson.build: set default help format to html on windows Ramsay Jones
2025-04-06 20:16     ` Ramsay Jones
2025-04-14  7:54       ` Patrick Steinhardt
2025-04-06 19:38   ` [PATCH v2 05/13] Makefile: remove NEEDS_LIBRT build variable Ramsay Jones
2025-04-06 19:38   ` [PATCH v2 06/13] config.mak.uname: add a note about NO_STRLCPY for Linux Ramsay Jones
2025-04-06 19:38   ` [PATCH v2 07/13] config.mak.uname: only set NO_REGEX on cygwin for v1.7 Ramsay Jones
2025-04-14  7:55     ` Patrick Steinhardt
2025-04-14 20:03       ` [-SPAM-] " Ramsay Jones
2025-04-15  5:59         ` Patrick Steinhardt
2025-04-15 15:05           ` Junio C Hamano
2025-04-06 19:38   ` [PATCH v2 08/13] config.mak.uname: add HAVE_GETDELIM to the cygwin section Ramsay Jones
2025-04-06 19:38   ` [PATCH v2 09/13] config.mak.uname: add clock_gettime() to the cygwin build Ramsay Jones
2025-04-14  7:55     ` Patrick Steinhardt
2025-04-14 20:05       ` [-SPAM-] " Ramsay Jones
2025-04-06 19:38   ` [PATCH v2 10/13] builtin/gc.c: correct RAM calculation when using sysinfo Ramsay Jones
2025-04-14  7:55     ` Patrick Steinhardt
2025-04-14 20:11       ` [-SPAM-] " Ramsay Jones
2025-04-06 19:38   ` [PATCH v2 11/13] config.mak.uname: add sysinfo() configuration for cygwin Ramsay Jones
2025-04-14  7:55     ` Patrick Steinhardt
2025-04-06 19:38   ` [PATCH v2 12/13] config.mak.uname: add arc4random to the cygwin build Ramsay Jones
2025-04-06 19:38   ` [PATCH v2 13/13] config.mak.uname: set CSPRNG_METHOD to getrandom on Linux Ramsay Jones
2025-04-16 23:18   ` [PATCH v3 00/13] miscellaneous build mods (part 1) Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 01/13] meson.build: remove -DCURL_DISABLE_TYPECHECK Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 02/13] Makefile: only set some BASIC_CFLAGS when RUNTIME_PREFIX is set Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 03/13] meson.build: only set build variables for non-default values Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 04/13] meson.build: set default help format to html on windows Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 05/13] Makefile: remove NEEDS_LIBRT build variable Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 06/13] config.mak.uname: add a note about NO_STRLCPY for Linux Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 07/13] config.mak.uname: only set NO_REGEX on cygwin for v1.7 Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 08/13] config.mak.uname: add HAVE_GETDELIM to the cygwin section Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 09/13] config.mak.uname: add clock_gettime() to the cygwin build Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 10/13] builtin/gc.c: correct RAM calculation when using sysinfo Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 11/13] config.mak.uname: add sysinfo() configuration for cygwin Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 12/13] config.mak.uname: add arc4random to the cygwin build Ramsay Jones
2025-04-16 23:18     ` [PATCH v3 13/13] config.mak.uname: set CSPRNG_METHOD to getrandom on Linux Ramsay Jones
2025-04-17 13:55       ` Junio C Hamano [this message]
2025-04-17 18:27         ` Ramsay Jones
2025-04-17 20:13           ` Junio C Hamano
2025-04-17 22:06             ` Ramsay Jones
2025-04-17  3:45     ` [PATCH v3 00/13] miscellaneous build mods (part 1) Junio C Hamano
2025-04-17  8:36       ` Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq4iymgadz.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@dinwoodie.org \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    --cc=ramsay@ramsayjones.plus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).