6 ms·
you should use your OS's CSPRNG (here, /dev/random) to the exclusion of any other RNG Bad advice. Use your OS's CSPRNG to get a seed, but work with your own P
by cperciva 13y ago
you should use your OS's CSPRNG (here, /dev/random) to the exclusion of any other RNG
Bad advice. Use your OS's CSPRNG to get a seed, but work with your own PRNG (say, HMAC_DRBG) internally. Going to the OS every time you want a few bits is both very slow and makes it far easier for local attackers to see when you're using entropy.
- tptacek 13y agoStrongest possible disagree. For instance, the Debian OpenSSL bug was an entirely unforced error stemming from applications that chose to use Debian OpenSSL's terrible CSPRNG on top of the OS's CSPRNG. The local attacker scenario you're talking about is a theoretical risk when there are attackers running code in the same OS as your CSPRNG; a far more likely concrete flaw is, for instance, a SecureRandom implementation that allows developers to specify insecure seed values. I'll go to bat on this disagreement. Don't use application-layer CSPRNGs. Use the one the OS provides, to the exclusion of alternatives.
- marshray 13y agoThe Debian OpenSSL bug was a result of Debian patching OpenSSL's RNG to make it utterly broken. Unless you're going to claim Debian couldn't have patched an equivalent bug into the kernel, you can't generalize this as support for the claim that kernel RNGs are inherently superior to library RNGs.
- tptacek 13y agoI'm saying the error was unforced because the effort the OpenSSL CSPRNG went through was duplicative.
- marshray 13y agoSo your position is that Debian didn't go far enough? They should have disabled OpenSSL's CSPRNG entirely and redirected its internal calls to perform IO operations on /dev/[u]random?
- tptacek 13y agoModulo the fact that Debian shouldn't be mucking with the inner workings of packages in the first place, sure; stubbing out OpenSSL's CSPRNG with calls to the OS CSPRNG seems like a reasonable plan. It is, by the way, part of the NaCL design too.
- marshray 13y agoLast I heard, there were still some "security oriented" OSes using RC4 for their /dev/random.
- tptacek 13y agoarc4random predates modern OS CSPRNGs.
- marshray 13y agoSo does OpenSSL. I think it's just not reasonable to expect a widely-portable crypto primitive and protocol library to judge the quality of the host /dev/[u]random and delegate to it. Of course, they seed from the host device and try to estimate the entropy it provides. Even that OS with the biased /dev/[u]random using RC4 because it was fast would keep a separate RC4 state in each process' libc to avoid the overhead of kernel calls.
- tptacek 13y agoSo then, you think NaCL's design decision to rely on /dev/urandom was a mistake?
- marshray 13y agoI think if NaCL ever gets popular that design decision will bite somebody, somewhere, on some OS. Our crypto libraries need to provide their own belt to wear with the OS-provided suspenders. Yes, I know about potential fork() bugs, but our modern VM-crazed deployments introduce that possibility at kernel level too. We need our good crypto implementers shipping good lightweight CSPRNGs, rather than the kernel developers who try to compensate with 6000 bit entropy pools.
- tedunangst 13y agoThis seems the complete opposite of your usual advice to use a library. You want every app developer to memorize the intricacies of which of random or urandom or srandom they should use on which OS and whether they need to worry about blocking or short reads and whether the entropy returned is good, or really good, or just good enough? You don't think people are going to dick that up? I'd trust the OpenSSL devs to figure this mess out before John Q. Random developer. Any day.
- tptacek 13y agoThe OS already provides a library for securely generating random numbers. On Unix, that library is called "the random driver". Its interface is file-descriptor based. You'd rather not be in a position to care about cryptographic randomness regardless. So, by all means, use high-level crypto libraries. But those libraries should also be using the random driver, instead of trying to bolt their own CSPRNG on top of it (or, god forbid, trying to avoid the random driver altogether).
- cperciva 13y agoStrongest possible disagree. Ok, we disagree. It wouldn't be the first time. ;-) the Debian OpenSSL bug was an entirely unforced error stemming from applications that chose to use Debian OpenSSL's terrible CSPRNG on top of the OS's CSPRNG I think the biggest problem was that OpenSSL used OpenSSL's CSPRNG after Debian broke it. Having applications all open+read+close /dev/random is not going to prevent that. a far more likely concrete flaw is, for instance, a SecureRandom implementation that allows developers to specify insecure seed values. A SecureRandom implementation should not allow the application to provide seed values except as additional input. It should always seed itself from the operating system entropy source, with no option to disable that. Aside from the issue of performance (which can be severe) and the timing information leakage to local spies, there's a very practical reason to avoid developers read from /dev/random: int fd; fd = open("/dev/random", O_RDONLY); read(fd, buf, buflen); close(fd); I've seen this on a number of occasions, and it works perfectly fine... until your server gets busy, the kernel entropy pool runs down, and /dev/random returns a short read. At that point, all hell breaks loose. To me, this scenario alone is enough to tell developers to use a library's automatically seeded CSPRNG instead of reading from the kernel.
- tptacek 13y agoLinux random/urandom is supposed to prevent short-reads for exactly this reason. You raise an interesting point, but I'm not persuaded that the risk of quietly failing to read from the random device is greater than the risks of adopting an entire new CSPRNG to sit on top of the OS's CSPRNG.
- cperciva 13y agoLinux random/urandom is supposed to prevent short-reads for exactly this reason. Oh great, yet another way that Linux developers are going to write broken code because they think the whole unix world behaves like Linux...
- fulafel 13y agoThe random/urandom devices do originate from Linux, other implementations should be careful about not making incompatible changes.