Hacker News
points by ubutler 1 day ago | 0 comments
Rule #1 of rolling your own RNG: don’t.

Rule #2? Please don’t.

[–] Mikhail_Edoshin 21 hours ago
This translates into "trust some authority", which is also a task. And it does not work when the canned solution does not quite fit, e. g. involves a bulky lib. The true answer should be "use your software engineering textbook and the standard reference of RNGs". Thing is, there is no such reference.
[–] 1718627440 2 hours ago
> Thing is, there is no such reference.

man encrypt works. info /encrypt works too.

[–] mik1998 20 hours ago
Handbook of Applied Cryptography is a good reference for implementing classic cryptographic algorythms.
[–] j16sdiz 1 day ago
That's why we use the system RNG !
[–] cowlevel 1 day ago
Be careful to use the cryptographic one, not rand(3)

And if you're a sysadmin, be extremely careful when generating keys in VMs or embedded devices. They tend to overestimate their entropy sources - it's possible that every clone of a VM generates the same keys. In some cases (cough ECDSA) generating the same key and nonce to sign two different messages is catastrophic - it immediately leaks the private key.

[–] saidnooneever 1 day ago
good point about VMs. if you run some VPS your provider could just link in a shitty rng into the thing and not give access to the correct hardware rng. U'd really need to dig into that to find out :/.

-object rng-random,id=objrng0,filename=/dev/null

or maybe just a file that contains 4 :O

[–] Novosell 1 day ago
As long as the 4 is random!
[–] saidnooneever 22 hours ago
cat /dev/random | grep 4
[–] flanz_10 1 day ago
btw, the idea that the system rng isnt good enough, or "runs out" or whatever, is no longer true on pretty much every modern, widely used os.

btw... im sure there's some legacy rng in windows or some shit that isnt good. read the docs but if it's the blessed system rng, you're probably fine!

although... i suppose if this is news to you (the person reading this), then you probably shouldn't be implementing whatever you are that really requires prng. ask a friend for help. im not trying to be a jerk, i just want to make sure you dont hurt yourself!

[–] ahartmetz 1 day ago
Rule 3: Use as many bits of randomness as the key size.

Rule 3b: Failing rule 3, disclose motivations and full list of employers and / or customers

[–] timerol 1 day ago
Rule 3c: At least as many bits. Bits tend to not be as random as you think they are