29 points · by e1ven · 12y ago · 61 comments
If you use Python, read from os.urandom, which is a wrapper to the system's CSPRNG. Don't use random.randint or random.getrandbits...
I don't know what you're talking about. Sodium does the same thing as NaCl, while also being more portable.
NaCl:
https://gist.github.com/anonymous/9234738
libsodium:
https://github.com/jedisct1/libsodium/blob/master/src/libsod...
I should also point out that randombytes is technically not part of NaCl. The authors maintain that random byte generation is out of scope for NaCl, and what actually happens is that randombytes.o is bundled separately from libnacl.a [1]. In TweetNacl the randombytes implementation is completely omitted.
[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=20;bug=694...
I read this: "So I'm the maintainer for Linux's /dev/random driver. "... "The main thing which I am much more worried about is that on various embedded systems, which do not have a fine-grained clock, and which is reading from flash which has a much more deterministic timing for their operations, is that when userspace tries to generate long-term public keys immediately after the machine is taken out of the box and plugged in, that there isn't a sufficient amount of entropy, and since most userspace applications use /dev/urandom since they don't want to block, that they end up with keys that aren't very random." - https://www.schneier.com/blog/archives/2013/10/insecurities_...
Is that out of date?
Why so insistent? Why not provide reasons that people can openly verify?
So the problem here is, if you're on a solid state embedded system that doesn't generate enough entropy to drive urandom, you're not doing enough to drive /dev/random either --- except, owing to a design flaw in Linux, on first-boot-ever, where /dev/random's entropy estimator gate saves from you from the bug that is Linux's willingness to give you output from an unseeded RNG. It shouldn't do that. FreeBSD doesn't. But if you're worried about that problem, the correct fix is to explicitly seed urandom from /dev/random on boot, not to use /dev/random in your code!
Once the CSPRNG is seeded, the idea of a "sufficient amount of entropy" is silly. Think of a CSPRNG as a stream cipher. Think of its output as you would the keystream of that cipher. What does it mean, within reason (ie, not hundreds of terabytes) for a keystream to have "sufficient" key in it? Because that's essentially the same question the maintainer for /dev/random is asking.
urandom simply isn't guaranteed to be random enough for cryptographic keys. Misusing it for this causes real-world problems.
You are telling people to write insecure software. That it could be secure if Linux worked differently from how it actually works is completely irrelevant and bordering on denialism.
If you want to fix Linux to be more like the other systems, great! Then /dev/random will be non-blocking and everyone can use that. Meanwhile, I'd much rather block than find myself sharing prime factors with random strangers.
On the other, you have HN's 'tveita, saying that urandom "isn't guaranteed to be random enough for cryptographic keys".
I could continue the argument, but since the whole post you're commenting on is that argument, I'd be repeating myself. So instead, I'll just ask: what specific assertion in that post do you disagree with?
Wait what? I thought I wanted actually random numbers.
Yup, entropy sources may even have a particular bias to bits valued 0 or 1.
Normally you need at least a whitening technique to get something looking
like a random number. Feeding that as a seed into a PRNG is certainly
helping to get the right quality. Be careful not to confuse a source of
entropy with a secure random number generator.
[1] http://crypto.stackexchange.com/questions/726/what-is-the-us...