Live data from Hacker News

Need a PRNG? Use a CSPRNG

sortingsearching.com

51–60 of 105 posts

Re: Need a PRNG? Use a CSPRNG

#51
There's one big scenario where PRNGs are good: reproducibility. I have a lot of tests that are deterministic given a seed, and if the test fails then I can grab the seed and replay the test.

CSPRNG is designed to be cryptographically secure, and thus I somewhat agree that it should be the default choice. But there are many cases where reproducibility is a good thing, and that's where you need seeded rngs.

EDIT: I was under the (wrong) impression that CSPRNGs were non-deterministic.

Re: Need a PRNG? Use a CSPRNG

#52

Earlier quoted context omitted.

I haven't paid close attention recently but that doesn't seem that far off of performance available via (hardware accelerated) AES? Looking at https://eprint.iacr.org/2018/392.pdf , it seems like: - Intel CPUs can use AESNI to do AES at 0.64 cpb - AMD Zen cores have two AESNI cores and can achieve 0.31 cpb - Vectorized AES instructions (supposed to ship in Ice Lake five years ago, but maybe a casualty of Intel's AVX5…

Yeah, chacha was an odd choice because AES is a lot faster on CPUs with acceleration. Just doing a few AES rounds would be a pretty fast, good PRNG.

For those interested in using AES with reduced rounds as a PRNG, it is covered in the paper "Parallel Random Numbers: As Easy as 1, 2, 3" by John Salmon et al.

https://www.thesalmons.org/john/random123/papers/random123sc...

Re: Need a PRNG? Use a CSPRNG

#53

There's one big scenario where PRNGs are good: reproducibility. I have a lot of tests that are deterministic given a seed, and if the test fails then I can grab the seed and replay the test. CSPRNG is designed to be cryptographically secure , and thus I somewhat agree that it should be the default choice. But there are many cases where reproducibility is a good thing, and that's where you need seeded rngs. EDIT: I wa…

The same is true for CSPRNG. Same seed -> same output.

Re: Need a PRNG? Use a CSPRNG

#54
post #29

Earlier quoted context omitted.

I simply don't trust NSA people and those who take their money. Why would you? We've seen nothing but shady moves from them in this space.

What are you talking about? Jason Donenfeld is the author of WireGuard, the extraordinarily popular VPN protocol that cannot use NIST cryptography (it does no negotiation, and is built on a version of Noise that uses ChaPoly and 25519). The change that was just described to you was a shift from NIST cryptography to non-NIST cryptography.

> that cannot use NIST cryptography

Do you mean as a matter of Donenfeld's engineering decisions (that those algorithms are unavailable in WireGuard)?

Re: Need a PRNG? Use a CSPRNG

#55
This is pretty reasonable, I think, but can it be applied to GPU code?

The fundamental challenge of CSPRNGs is that they tend to have high latency and each thread produces a lot of randomness at once, while typically you only need a little bit at a time. So either you throw away the extra bits, effectively wasting ALU, or you keep them around in storage somewhere, which is expensive as well.

I would love to see a CSPRNG that is designed to leverage subgroup/wave ops. (Hmm, now that I think about it, perhaps ChaCha can be spread reasonably across 4 lanes? That would give 4 dwords per thread and potentially cut latency quite a bit, much better tradeoff overall for most GPU applications)

Re: Need a PRNG? Use a CSPRNG

#57
post #8
post #2

It's been over a decade since I looked at this, but in real-time Monte Carlo path tracing the speed of your RNG is material. In simple enough scenes, probably something like 5-10% IIRC when using MT. I appreciate that you had a note about performance, but you were pretty quick to dismiss that there's a large quality difference between rand() and any modern PRNG. Plenty of these are fine enough and paying for a CSPRNG…

There are several PRNGs that are faster and more random than Mersenne Twister.

Some example benchmarks which compare MT against other newer algorithms in a couple of blog posts here:

https://nullprogram.com/blog/2017/09/21/

https://pixelesque.net/blog/2020/08/prng-evaluation-and-benc...

Re: Need a PRNG? Use a CSPRNG

#58
post #53

There's one big scenario where PRNGs are good: reproducibility. I have a lot of tests that are deterministic given a seed, and if the test fails then I can grab the seed and replay the test. CSPRNG is designed to be cryptographically secure , and thus I somewhat agree that it should be the default choice. But there are many cases where reproducibility is a good thing, and that's where you need seeded rngs. EDIT: I wa…

The same is true for CSPRNG. Same seed -> same output.

I'm confused; if you can predict the output, then isn't it by definition not secure? Or is the seed so hard to brute force that it's equivalent to breaking the underlying cryptography.

Re: Need a PRNG? Use a CSPRNG

#60
post #48
post #34

There are lots of cases where a PRNG is more appropriate than a CSPRNG. Wiping disks is one of them, as the CSPRNG becomes the bottleneck with large arrays. Testing i/o or network throughput is another; you don’t want your algorithm tainting the results. I like the thrust of the article but if you’re going to be particular, you should also be correct. CSPRNGs are not suitable replacements in 100% of cases. Engineerin…

If a predictable PRNG is sufficient for wiping disks, why do we care that the data is random at all? How about writing 0, 1, 2, ..., 255, 0, 1, 2, ... to consecutive bytes? Or -- generate 1 kb of good quality random data, and write the same 1 Kb repeatedly? It's not clear to me what we're trying to achieve in this scenario.

Because it is conceivable that you could extract patterns from the underlying data because you know what the highly correlated, short-cycle writing pattern was.

In reality, genuinely writing (as opposed to just pretending it was written which is a hazard on any modern storage) any single byte (even just all 0 or all 255) to every position on the disk seems to be more than sufficient to thwart even the NSA.

Post reply on HN