Live data from Hacker News

Designing a New PRNG

tom-kaitchuck.medium.com

21–30 of 52 posts

Re: Designing a New PRNG

#21

Dumb question: Why not just use AES? Most platforms have hardware acceleration so it should be pretty fast. Then there's no worrying about output quality. (Is there an application for which AES is not fast enough? Has it been benchmarked for speed against the various PRNG options?)

Using AES-NI for small integer hashing in the Rust compiler was found to result in a measurable slowdown.

Re: Designing a New PRNG

#22

Earlier quoted context omitted.

If you want to design a cryptographic RNG that falls between LCGs and PCG in speed, please have a go at it. Meanwhile we'll use our small and fast PRNGs and strive to make them as good as they can possibly be for non-cryptographic uses.

Saving some weight by leaving the airbag out of your car doesn't mean that it going faster is a good thing.

There's no such thing as "a good thing". There are only goals, security is just a goal among other that not everyone have.

Re: Designing a New PRNG

#23

Earlier quoted context omitted.

If you want to design a cryptographic RNG that falls between LCGs and PCG in speed, please have a go at it. Meanwhile we'll use our small and fast PRNGs and strive to make them as good as they can possibly be for non-cryptographic uses.

I beg you to define what “good” means in a way that doesn’t imply security properties. And if you must demand security properties, god help you if you designed something that can’t provide them.

Say I want to numerically approximate a high dimensional integral with MC sampling, say in a computational fluid dynamics simulation, or in a ray traced render.

For this, I need consequent samples from a PRNG to be really uncorrelated and fast. But there is no adversary relationship, so I don't need cryptographic strength. I just cannot have any spurious correlations between samples, as they might throw off convergence speed or worse, introduce error.

Re: Designing a New PRNG

#24

Earlier quoted context omitted.

Saving some weight by leaving the airbag out of your car doesn't mean that it going faster is a good thing.

So did PCG or xoroshiro leave the airbag out of MCGs or what? Or are you one of those who pretend that there was never any legitimate use case for any non-cryptographic PRNG?

There are perfectly legitimate use case (in a tiny niche area) for non-cryptographic RNGs - however, three points:

1. Non-cryptographic RNGs, should they be incorporated in security-critical applications are dangerous. If you insist on manufacturing poisonous chemicals that look appetizing and say “Kool-Aid” on them, kids are going to drink them. And this is your damned fault.

2. Non-cryptographic RNGs should not be evaluated and improved so as to (appear to provide) security properties. Non-invertability is a security property. Anyone who needs this property probably wants something that has been properly evaluated by experts to provide it. This construction has not been, and it is appropriate to assume that against a sufficiently-motivated adversary it will not provide it. Assuming otherwise is stupid and dangerous.

3. People who can use a non-cryptographic RNG but can’t afford the compute of a full cryptographic RNG are a very small subset of all users with very specific computing limitations. If you must target them with something, you should justify your computing speedup.

My proposal is that this type of non-cryptographic RNG should have a name that is not easily confused with safe cryptographic PRNGs. Perhaps “statistical sequence generator”. Moreover, people designing these systems should not be playing with security properties. Do one thing or the other, but not both things badly.

The set of people who need fast statistical (but insecure) sequence generators is small. They know who they are and what they need. Stop littering the school yard with poisonous chemicals that say “Kool Aid” in an effort to reach a few hundred laboratory chemists who are perfectly capable of calling you and ordering exactly the ingredients they know they need.

Re: Designing a New PRNG

#25

Earlier quoted context omitted.

If you want to design a cryptographic RNG that falls between LCGs and PCG in speed, please have a go at it. Meanwhile we'll use our small and fast PRNGs and strive to make them as good as they can possibly be for non-cryptographic uses.

I beg you to define what “good” means in a way that doesn’t imply security properties. And if you must demand security properties, god help you if you designed something that can’t provide them.

You don't need to define good in an absolute sense to see how one thing can be better than another.

The flaws of an MCG or LCG are easily witnessed, so it's totally fair for someone to go find out if it's possible to do better (i.e. remove obvious patterns, fix low period of low order bits, improve statistical quality) without sacrificing much performance; and indeed perhaps making it faster than a large-state LCG of comparable quality would be.

If you admit that there are any legitimate uses for non-cryptographic PRNGs then I guess a 32 bit MCG (or "42") is just perfect for you (otherwise you'd know what's better and you don't need to ask anyone to define good). You're easy to please.

If you think there are no legitimate use cases for these fast generators at all, then I'm sorry but a lot of people disagree and they will never rewrite their sims, noise generators, world generators, etcetra to use a CSPRNG no matter how much you whine about it.

Re: Designing a New PRNG

#26

Earlier quoted context omitted.

So did PCG or xoroshiro leave the airbag out of MCGs or what? Or are you one of those who pretend that there was never any legitimate use case for any non-cryptographic PRNG?

There are perfectly legitimate use case (in a tiny niche area) for non-cryptographic RNGs - however, three points: 1. Non-cryptographic RNGs, should they be incorporated in security-critical applications are dangerous . If you insist on manufacturing poisonous chemicals that look appetizing and say “Kool-Aid” on them, kids are going to drink them. And this is your damned fault. 2. Non-cryptographic RNGs should not be…

I agree on all three points. I might even agree on the proposed name; not that I care too much.

All I'm saying is that I'm happy the state of art of fast (but insecure) generators is improving and people have better options than cranky old LCGs or Mersenne Twister (ugh!).

I don't know why they brought up non-invertibility. But, at a glance, I see a new RNG that might be at least twice as fast as a comparable variant of PCG while offering similar or better statistical performance. That's exactly the kind of development I like to see.

Re: Designing a New PRNG

#27

Seriously. Cut this shit out. Design a cryptographic RNG or decide precisely how you intend to justify a non-cryptographic RNG that has cryptographic security properties (but like, not all of them.)

The interesting angle here is 2x performance vs pcg64_fast or xoshiro256++, with competitive quality in that space. It’s a simulation PRNG, not a CSPRNG. I agree the introduction to the article is somewhat confused (i.e., mentioning invertibility), but it never claims to be a CSPRNG.

The vast majority of the article is pretty interesting, if you can get past the first couple paragraphs and some typos.

The context is Rust’s SmallRng[1]. The top-level description of that is:

> A small-state, fast non-crypto PRNG

[1]: https://docs.rs/rand/0.8.4/rand/rngs/struct.SmallRng.html

Re: Designing a New PRNG

#28
> After some minor optimizing, on my laptop here are benchmarks on filling a 1kb byte array: > > Mwc-256-X-X-A-64 (This algorithm): 100.98 ns

That comes to 10 GB/s. For comparison, I think ChaCha8 implemented with AVX-512 should run at a similar speed. Maybe a bit faster in short-ish, single-threaded benchmarks.

To be clear, there are plenty of caveats in making this comparison: ChaCha8 won't hit that throughput on any output size smaller than 1 KiB. AVX-512 requires a very recent processor. Most library implementations don't include AVX-512 support. Power usage will be high. Downclocking will be an issue, especially with multithreading. Etc. etc.

But in exchange, you get all the security properties.

I think one takeaway here is that the gap between cryptographic and non-cryptographic is smaller than many people think, which argues in favor of secure defaults. (Though to be clear, I don't think OP or anyone in this thread is opposed to secure defaults.) Another takeaway is that a lot of these blockers, like hardware and library support, will continue to improve over time. So if you find that a CSPRNG isn't fast enough for your use case today, make sure to check again in a few years. And of course, as always, it's important to benchmark your specific use case if you're worried about performance.

Re: Designing a New PRNG

#29

Earlier quoted context omitted.

So did PCG or xoroshiro leave the airbag out of MCGs or what? Or are you one of those who pretend that there was never any legitimate use case for any non-cryptographic PRNG?

There are perfectly legitimate use case (in a tiny niche area) for non-cryptographic RNGs - however, three points: 1. Non-cryptographic RNGs, should they be incorporated in security-critical applications are dangerous . If you insist on manufacturing poisonous chemicals that look appetizing and say “Kool-Aid” on them, kids are going to drink them. And this is your damned fault. 2. Non-cryptographic RNGs should not be…

[deleted]

Re: Designing a New PRNG

#30

Dumb question: Why not just use AES? Most platforms have hardware acceleration so it should be pretty fast. Then there's no worrying about output quality. (Is there an application for which AES is not fast enough? Has it been benchmarked for speed against the various PRNG options?)

Using AES-NI for small integer hashing in the Rust compiler was found to result in a measurable slowdown.

I think the biggest gains from AES-NI are when you can use the vectorized versions. So random byte generation would benefit, but small integer hashing probably not? (Unless you could arrange to hash a vector of integers at once.) But this isn't something I've tried myself.
Post reply on HN