public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Jonny Grant <jg@jguk.org>
To: "Alejandro Colomar" <alx.manpages@gmail.com>,
	"Cristian Rodríguez" <crrodriguez@opensuse.org>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>,
	linux-man <linux-man@vger.kernel.org>,
	GNU C Library <libc-alpha@sourceware.org>,
	Florian Weimer <fweimer@redhat.com>
Subject: Re: [PATCH] Add example to rand.3
Date: Wed, 28 Dec 2022 21:19:58 +0000	[thread overview]
Message-ID: <59b2c1b3-4a53-a497-673a-c4e53647a74f@jguk.org> (raw)
In-Reply-To: <d1fcf042-6032-5000-af6b-96bd5b256616@gmail.com>



On 28/12/2022 21:11, Alejandro Colomar wrote:
> Hi Cristian,
> 
> On 12/28/22 22:04, Cristian Rodríguez wrote:
>> On Wed, Dec 28, 2022 at 5:57 PM Alejandro Colomar via Libc-alpha
>> <libc-alpha@sourceware.org> wrote:
>>
>>> Ahh, I didn't connect the dots the other day!  We don't need to wait for glibc.
>>> libbsd already provides arc4random on GNU/Linux systems, so I can already
>>> recommend using arc4random to seed srand(3).
>>>
>>> I'll prepare a patch...
>>>
>>
>> I would suggest avoiding that, as it suffers from all the problems
>> previously discussed on this list , on the relevant arc4random thread
>>
>> tl;dr , it can't be safe without kernel support, as you need to know
>> when to drop the buffer. (on fork, on resume plus on $deity knows
>> condition for which there is no kernel notification about)
> 
> I don't consider rand(3) anything safe or really random, but rather a tool for simulations or debugging where repeatability matters more than anything else.
> 
> For anything where randomness matters, arc4random(3) is the way to go.  But randomness is not always what you want.  What would you recommend for some software where you need to test/simulate many different cases, where you want to be able to repeat the tests?

Can generate our stream of randomness values in a file and then the software can just run with those (like a one-time pad (OTP)).
 
> Maybe we should make clear that rand(3) should never be used unless you want repeatable results.  And when randomness matters in some cases, you could add a macro wrapping both rand(3) and arc4random(3), and use the appropriate one.

Sounds reasonable to have the ability to run both ways if useful.
Jonny


  reply	other threads:[~2022-12-28 21:20 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <105835f5-359c-2646-f609-e73459ee2d3b@jguk.org>
2022-12-26 22:29 ` Alejandro Colomar
2022-12-27 13:07   ` Cristian Rodríguez
2022-12-27 23:33     ` Alejandro Colomar
2022-12-28  0:00       ` G. Branden Robinson
2022-12-28  0:41         ` Alejandro Colomar
2022-12-28 12:21           ` Cristian Rodríguez
2022-12-30 18:15             ` Joseph Myers
2022-12-30 18:20               ` Alejandro Colomar
2022-12-30 18:50                 ` Joseph Myers
2022-12-30 18:58                   ` Alejandro Colomar
2022-12-30 19:11               ` Cristian Rodríguez
2022-12-30 21:08                 ` Joseph Myers
2022-12-30 21:15                   ` Internal organization of "the implementation" (was: [PATCH] Add example to rand.3) Alejandro Colomar
2022-12-30 21:50                     ` Joseph Myers
2022-12-27 21:37   ` [PATCH] Add example to rand.3 Jonny Grant
2022-12-27 23:11     ` Alejandro Colomar
2022-12-28 20:51       ` Jonny Grant
2022-12-28 20:56         ` Alejandro Colomar
2022-12-28 21:03           ` Alejandro Colomar
2022-12-28 21:04             ` Alejandro Colomar
2022-12-28 21:25               ` Jonny Grant
2022-12-28 21:32                 ` Alejandro Colomar
2022-12-28 21:04           ` Cristian Rodríguez
2022-12-28 21:11             ` Alejandro Colomar
2022-12-28 21:19               ` Jonny Grant [this message]
2022-12-28 21:18             ` Alejandro Colomar

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=59b2c1b3-4a53-a497-673a-c4e53647a74f@jguk.org \
    --to=jg@jguk.org \
    --cc=alx.manpages@gmail.com \
    --cc=crrodriguez@opensuse.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.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 read-only IMAP folder(s) and NNTP newsgroup(s).