git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 13/13] config.mak.uname: set CSPRNG_METHOD to getrandom on Linux

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 17, 2025, 13:55 UTC
Message-ID
<xmqq4iymgadz.fsf@gitster.g>
In-Reply-To
<20250416231835.2492562-14-ramsay@ramsayjones.plus.com>
Ramsay Jones <ramsay@ramsayjones.plus.com> writes:
Show 14 quoted lines
> 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?
Show 6 quoted lines
> 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.

Show 5 quoted lines
> 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.
Show 26 quoted lines
> 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
Previous: Ramsay JonesNext: Ramsay Jones
Message 46 of 51 in “miscellaneous build mods (part 1)”
  1. 00/12 miscellaneous build mods (part 1)Ramsay Jones, Mar 15, 2025
  2. 00/13 miscellaneous build mods (part 1)Ramsay Jones, Apr 6, 2025
  3. 06/13 config.mak.uname: add a note about NO_STRLCPY for LinuxRamsay Jones, Apr 6, 2025
  4. 07/13 config.mak.uname: only set NO_REGEX on cygwin for v1.7Ramsay Jones, Apr 6, 2025
  5. Patrick SteinhardtApr 14, 2025
  6. Ramsay JonesApr 14, 2025
  7. Patrick SteinhardtApr 15, 2025
  8. Junio C HamanoApr 15, 2025
  9. 08/13 config.mak.uname: add HAVE_GETDELIM to the cygwin sectionRamsay Jones, Apr 6, 2025
  10. 09/13 config.mak.uname: add clock_gettime() to the cygwin buildRamsay Jones, Apr 6, 2025
  11. Patrick SteinhardtApr 14, 2025
  12. Ramsay JonesApr 14, 2025
  13. 10/13 builtin/gc.c: correct RAM calculation when using sysinfoRamsay Jones, Apr 6, 2025
  14. Patrick SteinhardtApr 14, 2025
  15. Ramsay JonesApr 14, 2025
  16. 11/13 config.mak.uname: add sysinfo() configuration for cygwinRamsay Jones, Apr 6, 2025
  17. Patrick SteinhardtApr 14, 2025
  18. 12/13 config.mak.uname: add arc4random to the cygwin buildRamsay Jones, Apr 6, 2025
  19. 13/13 config.mak.uname: set CSPRNG_METHOD to getrandom on LinuxRamsay Jones, Apr 6, 2025
  20. 01/13 meson.build: remove -DCURL_DISABLE_TYPECHECKRamsay Jones, Apr 6, 2025
  21. 02/13 Makefile: only set some BASIC_CFLAGS when RUNTIME_PREFIX is setRamsay Jones, Apr 6, 2025
  22. Patrick SteinhardtApr 14, 2025
  23. 03/13 meson.build: only set build variables for non-default valuesRamsay Jones, Apr 6, 2025
  24. Ramsay JonesApr 6, 2025
  25. Patrick SteinhardtApr 14, 2025
  26. Ramsay JonesApr 14, 2025
  27. Patrick SteinhardtApr 15, 2025
  28. 04/13 meson.build: set default help format to html on windowsRamsay Jones, Apr 6, 2025
  29. Ramsay JonesApr 6, 2025
  30. Patrick SteinhardtApr 14, 2025
  31. 05/13 Makefile: remove NEEDS_LIBRT build variableRamsay Jones, Apr 6, 2025
  32. 00/13 miscellaneous build mods (part 1)Ramsay Jones, Apr 16, 2025
  33. 01/13 meson.build: remove -DCURL_DISABLE_TYPECHECKRamsay Jones, Apr 16, 2025
  34. 02/13 Makefile: only set some BASIC_CFLAGS when RUNTIME_PREFIX is setRamsay Jones, Apr 16, 2025
  35. 03/13 meson.build: only set build variables for non-default valuesRamsay Jones, Apr 16, 2025
  36. 04/13 meson.build: set default help format to html on windowsRamsay Jones, Apr 16, 2025
  37. 05/13 Makefile: remove NEEDS_LIBRT build variableRamsay Jones, Apr 16, 2025
  38. 06/13 config.mak.uname: add a note about NO_STRLCPY for LinuxRamsay Jones, Apr 16, 2025
  39. 07/13 config.mak.uname: only set NO_REGEX on cygwin for v1.7Ramsay Jones, Apr 16, 2025
  40. 08/13 config.mak.uname: add HAVE_GETDELIM to the cygwin sectionRamsay Jones, Apr 16, 2025
  41. 09/13 config.mak.uname: add clock_gettime() to the cygwin buildRamsay Jones, Apr 16, 2025
  42. 10/13 builtin/gc.c: correct RAM calculation when using sysinfoRamsay Jones, Apr 16, 2025
  43. 11/13 config.mak.uname: add sysinfo() configuration for cygwinRamsay Jones, Apr 16, 2025
  44. 12/13 config.mak.uname: add arc4random to the cygwin buildRamsay Jones, Apr 16, 2025
  45. 13/13 config.mak.uname: set CSPRNG_METHOD to getrandom on LinuxRamsay Jones, Apr 16, 2025
  46. Junio C HamanoApr 17, 2025
  47. Ramsay JonesApr 17, 2025
  48. Junio C HamanoApr 17, 2025
  49. Ramsay JonesApr 17, 2025
  50. Junio C HamanoApr 17, 2025
  51. Patrick SteinhardtApr 17, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.