5 ms·
I agree that in many cases a much simpler API would suffice, but it strikes me as odd to suggest adding a convenient but insufficient-for-security API to the sa
by anp 7y ago
I agree that in many cases a much simpler API would suffice, but it strikes me as odd to suggest adding a convenient but insufficient-for-security API to the same standard library that protects HashMap against DoS.
- Dylan16807 7y agoHaving a very simple API is not at odds with security, though. A simple API could automatically seed from the OS and then run a tiny loop with sha2 or sha3, for example.
- vunie 7y agoSHA2 is not designed to be used as a RNG. SHA3 might be a little bit better with its "streaming" modes, but there are many far better and faster ways to get random bits.
- Dylan16807 7y agoIt doesn't have to be the absolute fastest, it just has to work. What is far better and faster than SHA3? And while SHA2 wasn't designed for that use, it's easy to make simple and provably correct constructs that turn a secure hash into a secure RNG.
- heavenlyblue 7y agoYou’re speculating to prove a point. I would definitely not want my std to be designed this way.
- Dylan16807 7y ago1. It was just an example. 2. You definitely don't want your std to be designed with a simple API to a fast, secure, and popular crypto primitive? Pretend I named your favorite one, to avoid bikeshedding issues.
- edflsafoiewq 7y agoChaCha20 is widely used for CSRNG.
- Dylan16807 7y agoAgreed, that would work fine. But for a generic RNG function, I feel like the difference between 3 and 7 cycles per byte isn't too impactful.
- vunie 7y agoThe request here is for a simpler API. I and many others would be more than happy to get a function that returns a random u64. No traits, no crippling commitments to a specific API design.
- anp 7y agoThe API you describe, IIUC, can’t be serviced faithfully on the OSes targeted by std while being backed by real entropy.
- Macha 7y agoWhich is fine. Not everything needs SecureRandom. I'd wager more code using random numbers is for A/B tests, sample data generation or video games than people implementing crypto. I get that security people don't want non-secure RNGs to exist out of fear that someone might try implement security related functions out of them but why should I care if I just want to choose between 3 types of enemies this wave?
- ChrisSD 7y agoBut the std hashmap implementation[0] already depends on a PRNG via the rand crate[1], and thus OS random (for the initial seed). So it's in the standard library even if you can't use it directly. Which is what makes me think this is an API issue, not an implementation one. [0]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html https://doc.rust-lang.org/std/collections/hash_map/struct.Ra... [1]: https://docs.rs/rand/0.7.0/rand/rngs/struct.ThreadRng.html https://docs.rs/rand/0.7.0/rand/rngs/struct.ThreadRng.html
- anp 7y ago(past edit window) This was written with hostility I don’t feel. Sorry Raph!
- raphlinus 7y agoNo worries, it was read with offense I didn't take. I agree, designing a good random number API is in fact hard. I just think we can give developers a better out-of-the-box experience.