News for hackers. Stuff that matters.
Re:Random Number Generator Recommendations for Applications by some_furry on Tuesday May 30, 2023 @04:29PM (#36130301)
In PHP, at least, random_bytes() is faster than their "high quality" example.
Re:Random Number Generator Recommendations for Applications by jagged-chisel on Tuesday May 30, 2023 @05:05PM (#36130786)
How does the quality of random_bytes() compare?
Re:Random Number Generator Recommendations for Applications by djbusby on Tuesday May 30, 2023 @05:30PM (#36131148)
The manual says it uses high-quality sources

https://www.php.net/manual/en/function.random-bytes.php

Edit: the PHP docs seem to meet the requirements from the article but, the article has a different recommendation (odd?, Maybe I missed something)

Re:Random Number Generator Recommendations for Applications by some_furry on Tuesday May 30, 2023 @10:39PM (#36133858)
It uses the OS's cryptographic RNG.
Re:Random Number Generator Recommendations for Applications by rootw0rm on Tuesday May 30, 2023 @04:52PM (#36130599)
nanorand for rust!

edit: now after reading about rand_xoshiro i'm curious to try it out

Re:Random Number Generator Recommendations for Applications by djbusby on Tuesday May 30, 2023 @05:32PM (#36131173)
If I'm using the random routines from libsodium is that good enough?
Re:Random Number Generator Recommendations for Applications by tptacek on Tuesday May 30, 2023 @07:32PM (#36132618)
Yes.
Re:Random Number Generator Recommendations for Applications by wepple on Tuesday May 30, 2023 @06:44PM (#36132125)
This article fails to explain why someone should explicitly reach for an RNG over PRNG.

It also suggests os.urandom as a Python RNG which (as the name suggests) uses /dev/urandom or the getrandom() syscall, both of which are PRNGs

Re:Random Number Generator Recommendations for Applications by gregmac on Tuesday May 30, 2023 @08:27PM (#36133035)
What do you mean by just "RNG"? Hardware ("true")?
Re:Random Number Generator Recommendations for Applications by cbsmith on Tuesday May 30, 2023 @08:43PM (#36133153)
> This article fails to explain why someone should explicitly reach for an RNG over PRNG.

There aren't a lot of cases where you need to explicitly reach for a non-PRNG over a PRNG, and if you do need it, you most likely know it. What does often make a lot of sense is using a PRNG that is seeded from a non-PRNG.

> It also suggests os.urandom as a Python RNG which (as the name suggests) uses /dev/urandom or the getrandom() syscall, both of which are PRNGs

So, that's not ENTIRELY accurate. At least on Linux, while /dev/urandom uses a PRNG, but it is fed from the entropy pool. So unless you consume the entropy pool of a system, it has all the randomness of /dev/random. The difference is that /dev/random blocks when you run out of entropy, while /dev/urandom will just keep feeding output generated purely from the PRNG until more entropy becomes available.

There are some notable exceptions, but in most cases pulling from /dev/urandom is the right choice.

Re:Random Number Generator Recommendations for Applications by tptacek on Tuesday May 30, 2023 @09:53PM (#36133603)
I don't think this "PRNG" vs. "RNG" distinction is doing us much good. There's no meaningful difference in the mechanics of how urandom and random serve unpredictable bits. There is also no such thing as "running out of entropy".
Re:Random Number Generator Recommendations for Applications by cbsmith on Wednesday May 31, 2023 @12:01PM (#36139898)
What do you interpret the output of `cat /proc/sys/kernel/random/entropy_avail` to mean?
Re:Random Number Generator Recommendations for Applications by tptacek on Wednesday May 31, 2023 @12:18PM (#36140106)
Nothing.
Re:Random Number Generator Recommendations for Applications by cryptonector on Wednesday May 31, 2023 @12:43PM (#36140415)
> There is also no such thing as "running out of entropy".

Hear hear. There is, indeed, no such thing as running out of entropy in a modern PRNG's state.

> I don't think this "PRNG" vs. "RNG" distinction is doing us much good.

But it's still nice to seed and periodically reseed a PRNG w/ entropy from an RNG. So there is a distinction between PRNG and RNG to be made, and we should make it. What we really want is to always have an RNG-seeded PRNG, and to always use the PRNG not the RNG.

Re:Random Number Generator Recommendations for Applications by cbsmith on Wednesday May 31, 2023 @01:12PM (#36140805)
> Hear hear. There is, indeed, no such thing as running out of entropy in a modern PRNG's state.

Yes, of course. PRNG's are about producing random data from a seed. But /dev/random & /dev/urandom isn't just a PRNG.

> What we really want is to always have an RNG-seeded PRNG, and to always use the PRNG not the RNG.

Which is effectively what is going on with /dev/random & /dev/urandom

Re:Random Number Generator Recommendations for Applications by tptacek on Wednesday May 31, 2023 @02:08PM (#36141593)
At the point where you're simply equating /dev/random and /dev/urandom, you're no longer really disagreeing with anybody here. The only difference between the two is that /dev/random keeps a metric on how many bits its vended, and blocks waiting for rekeying when that metric gets too high. That's more or less a nonsensical thing to do.
Re:Random Number Generator Recommendations for Applications by cbsmith on Wednesday May 31, 2023 @06:01PM (#36144973)
I'm definitely not saying what /dev/random does makes sense. ;-)
Re:Random Number Generator Recommendations for Applications by cbsmith on Wednesday May 31, 2023 @01:46PM (#36141250)
I think I understand what you were getting at by "there is no such thing as running out of entropy". Would you say there is such thing as "not having adequate entropy"?
Re:Random Number Generator Recommendations for Applications by tptacek on Wednesday May 31, 2023 @02:06PM (#36141573)
Not really. A CSPRNG is either initialized properly or it isn't. Once it is, entropy has ceased to be a concern. The original LRNG design misapprehends the purpose of continuous "entropy collection", which is about post-compromise security (it's essentially a rekeying operation), and not about any kind of cryptographic exhaustion.
Re:Random Number Generator Recommendations for Applications by cbsmith on Wednesday May 31, 2023 @06:01PM (#36144958)
But /dev/urandom will provide you with random numbers even if initialization has not completed, whereas /dev/random will not.
Re:Random Number Generator Recommendations for Applications by tptacek on Thursday June 01, 2023 @02:09PM (#36155026)
It's best to think of this as an OS/distro detail; if you can reasonably expect /dev/urandom to give you insecure bits, your distro has a vulnerability.

That said: today you'd just use some variant of getrandom.

Re:Random Number Generator Recommendations for Applications by cbsmith on Friday June 02, 2023 @03:34AM (#36162207)
> It's best to think of this as an OS/distro detail; if you can reasonably expect /dev/urandom to give you insecure bits, your distro has a vulnerability.

Isn't that more a function of hardware than software? The hardware random number generators on modern CPUs pretty much eliminate the need to worry about entropy...

Re:Random Number Generator Recommendations for Applications by tptacek on Friday June 02, 2023 @10:42AM (#36165753)
No, this has nothing at all to do with hardware; the state of play is the same on machines that don't have instructions like RDRAND.
Re:Random Number Generator Recommendations for Applications by cbsmith on Friday June 02, 2023 @02:20PM (#36168846)
I think I still don't understand. Can you explain why it is not a hypothetical problem on a deterministic virtual machine?
Re:Random Number Generator Recommendations for Applications by jameswryan on Tuesday May 30, 2023 @10:46PM (#36133912)
/dev/random does not block when 'out of entropy'. 'Running out of entropy' isn't something that can happen, and /dev/random will only block if the RNG hasn't been initialized (short enough after boot to not matter).

See Jason Donenfeld's authoritative talk on the Linux RNG for details: https://youtu.be/-_yzaSp2xtY

Re:Random Number Generator Recommendations for Applications by cbsmith on Wednesday May 31, 2023 @11:59AM (#36139870)
I'll have to look at the talk, but I've had first hand experience with that behaviour from /dev/random. Perhaps it has changed over time.
Re:Random Number Generator Recommendations for Applications by cbsmith on Wednesday May 31, 2023 @01:16PM (#36140873)
I just checked the source code, and it appears that the entropy pool is alive and well and that /dev/random still waits for enough entropy to collect in the pool before providing more data for consumption.

https://github.com/torvalds/linux/blob/48b1320a674e1ff5de2fa...

The "wait_for_random_bytes" function is still there: https://github.com/torvalds/linux/blob/48b1320a674e1ff5de2fa...

Re:Random Number Generator Recommendations for Applications by wepple on Wednesday May 31, 2023 @02:27PM (#36141919)
Sure, I maybe should’ve noted that. But my key point is that the article tells you that you should use an RNG (without reason) rather than a PRNG, but then ends up listing something that is an (RNG-initialized) PRNG in the RNG section.

TL;DR he article has glaring inconsistencies and shouldn’t be regarded reliable

Re:Random Number Generator Recommendations for Applications by cbsmith on Wednesday May 31, 2023 @06:38PM (#36145359)
It was indeed a little... bizarre.
Re:Random Number Generator Recommendations for Applications by fastneutron on Tuesday May 30, 2023 @06:57PM (#36132264)
All this, and the nuclear business is still using variants of LCGs from 60 years ago [1] for Monte Carlo simulations.

In this case, their speed, repeatability and “good enough” statistical properties haven’t motivated much to change.

1. https://www.osti.gov/biblio/976209

Re:Random Number Generator Recommendations for Applications by berkut on Tuesday May 30, 2023 @10:52PM (#36133954)
Which is interesting, because for MC simulations for rendering (path tracing for example) fast and high quality random numbers are very important...

Although there are alternatives like using low discrepancy sequences (Halton, Sobol) which don't explicitly need the random number values generated from a PRNG itself which are used as well...

Re:Random Number Generator Recommendations for Applications by 0cf8612b2e1e on Tuesday May 30, 2023 @08:10PM (#36132922)
I am trying and failing to find an article where a poker website published their source code, including how they shuffled cards and seeded their randomness. The seed was the current timestamp. Someone realized an efficient way to reduce the search space, assuming vaguely accurate clocks, and predict every card distributed at the table after viewing only a small number of cards.
Re:Random Number Generator Recommendations for Applications by charcircuit on Wednesday May 31, 2023 @12:15AM (#36134382)
This sounds similar https://github.com/ech0ii/forceitbox

Also for an example of exploiting a gambling site that used javascript's Math.random https://jonasnick.github.io/blog/2015/07/08/exploiting-csgoj...

Re:Random Number Generator Recommendations for Applications by Tangurena2 on Tuesday June 06, 2023 @10:30AM (#36213375)
This is probably the article you are looking for: https://www.developer.com/guides/how-we-learned-to-cheat-at-...

The timestamp was down to a fraction of a second, so instead of having 52! possible decks (about 2^226) there were only 2^32 possible decks that could be generated by the algorithm.

Also: https://blog.codinghorror.com/shuffling/

Re:Random Number Generator Recommendations for Applications by local_crmdgeon on Tuesday May 30, 2023 @08:20PM (#36132984)
I wish the table of recommendations contained links. Searching some of those packages gives me sketchy deps I would not trust.
Re:Random Number Generator Recommendations for Applications by FabHK on Tuesday May 30, 2023 @11:17PM (#36134100)
Useful.

One thing to keep in mind: there’s been a bit of a feud in the PRNG space between the Vigna camp [1] with xoroshiro and newcomer O’Neill [2] with PCG.

This website seems stay on the traditional side and shy away from recommending PCG. I’m not really qualified to judge on that dispute [3], but I think both options are better, smaller, faster than the good old Mersenne Twister, so it’s time that we moved on from that [4] and pick one of the latest generation PRNGs.

FWIW, Julia now uses xoshiro256++ by default [5], and they investigated their choice quite thoroughly, I believe.

[1] https://prng.di.unimi.it/

[2] https://www.pcg-random.org/

[3] https://pcg.di.unimi.it/pcg.php

And the reply https://www.pcg-random.org/posts/on-vignas-pcg-critique.html

[4] https://arxiv.org/abs/1910.06437

[5] https://docs.julialang.org/en/v1/stdlib/Random/

Re:Random Number Generator Recommendations for Applications by adgjlsfhk1 on Wednesday May 31, 2023 @12:31AM (#36134480)
we're also considering moving to a 192 bit combination of xoshiro128++ with pcg64 (early stages, PR doesn't exist yet). this would have the advantage that you could do really cheap rng splitting by modifying the pcg state while avoiding the 128 bit multiplies that make bigger pcg slow. also it would mean both sides of the fued would be mad at us :)