public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH v6 10/10] manual: Add documentation for arc4random functions
Date: Tue, 28 Jun 2022 14:09:40 +0200	[thread overview]
Message-ID: <87czetf0qj.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20220518191424.3630729-11-adhemerval.zanella@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Wed, 18 May 2022 16:14:24 -0300")

* Adhemerval Zanella via Libc-alpha:

> +@node High Quality Random
> +@subsection High Quality Random Number Functions
> +
> +This section describes the random number functions provided as a GNU
> +extension, based on OpenBSD interfaces.
> +
> +@Theglibc{} uses kernel entropy obtained either through @code{getrandom}
> +or by reading @file{/dev/urandom} to seed and periodically re-seed the
> +internal state.  A per-thread data pool is used, which allows fast output
> +generation.
> +
> +Although these functions provide higher random quality than ISO, BSD, and
> +SVID functions, these still use a Pseudo-Random generator and should not
> +be used in cryptographic contexts.
> +
> +The internal state is cleared and reseed with kernel entropy on @code{fork}
> +and @code{_Fork} (it is not cleared for either direct @code{clone} syscall
> +or through glibc wrapper).

“or when using @theglibc{} @code{syscall} funcition”?

> +The prototypes for these functions are in @file{stdlib.h}.
> +@pindex stdlib.h
> +
> +@deftypefun int32_t arc4random (void)
> +@standards{GNU, stdlib.h}

Should be BSD, I think.  Likewise below.

> +@safety{@mtsafe{}@asunsafe{@asucorrupt{}}@acsafe{}}
> +This function returns a single 32-bit value in the range of 0 to 2^32−1,
> +which is twice the range of @code{rand} and @code{random}.
> +@end deftypefun

Can we use @math for the exponent?  And please say that the range is
inclusive.

> +@deftypefun uint32_t arc4random_uniform (uint32_t @var{upper_bound})
> +@standards{GNU, stdlib.h}
> +@safety{@mtsafe{}@asunsafe{@asucorrupt{}}@acsafe{}}
> +This function returns a single 32-bit value, uniformly distributed but
> +less than the @var{upper_bound}.  It avoids the @w{modulo bias} when the
> +upper bound is not a power of two.
> +
> +The algorithm obtains the exact sampling of a discrete uniform variable
> +using an optimal number of random bits for any range @var{upper_bounds},
> +allowing to consume as less as possible data from the per-thread entropy
> +pool.

I think this overspecifies the implementation.  And we obtain randomness
in blocks of 8 bits, IIRC, so it's not optimal in our implementation.

Thanks,
Florian


  reply	other threads:[~2022-06-28 12:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-18 19:14 [PATCH v6 00/10] Add arc4random support Adhemerval Zanella
2022-05-18 19:14 ` [PATCH v6 01/10] stdlib: Add arc4random, arc4random_buf, and arc4random_uniform (BZ #4417) Adhemerval Zanella
2022-06-02  9:44   ` Yann Droneaud
2022-06-10 17:26     ` Adhemerval Zanella
2022-05-18 19:14 ` [PATCH v6 02/10] stdlib: Add arc4random tests Adhemerval Zanella
2022-06-28 11:59   ` Florian Weimer
2022-06-28 16:58     ` Adhemerval Zanella
2022-05-18 19:14 ` [PATCH v6 03/10] benchtests: Add arc4random benchtest Adhemerval Zanella
2022-06-28 12:01   ` Florian Weimer
2022-06-28 17:06     ` Adhemerval Zanella
2022-06-28 17:13   ` Noah Goldstein
2022-06-28 17:14     ` Noah Goldstein
2022-06-28 17:22       ` Adhemerval Zanella
2022-05-18 19:14 ` [PATCH v6 04/10] aarch64: Add optimized chacha20 Adhemerval Zanella
2022-06-28 12:03   ` Florian Weimer
2022-06-28 17:39     ` Adhemerval Zanella
2022-05-18 19:14 ` [PATCH v6 05/10] x86: Add SSE2 " Adhemerval Zanella
2022-05-18 20:44   ` Noah Goldstein
2022-05-18 19:14 ` [PATCH v6 06/10] x86: Add AVX2 " Adhemerval Zanella
2022-05-18 19:14 ` [PATCH v6 07/10] powerpc64: Add " Adhemerval Zanella
2022-05-18 19:14 ` [PATCH v6 08/10] s390x: " Adhemerval Zanella
2022-05-18 19:14 ` [PATCH v6 09/10] stdlib: Add TLS optimization to arc4random Adhemerval Zanella
2022-06-28 12:19   ` Florian Weimer
2022-06-28 19:45     ` Adhemerval Zanella
2022-05-18 19:14 ` [PATCH v6 10/10] manual: Add documentation for arc4random functions Adhemerval Zanella
2022-06-28 12:09   ` Florian Weimer [this message]
2022-06-28 19:15     ` Adhemerval Zanella

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=87czetf0qj.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).