18 ms·
/dev/random – a new approach
- rwmj 11y agoAlso, should we use /dev/urandom (on the host) to seed the CSPRNG in virtual machines? https://lists.gnu.org/archive/html/qemu-devel/2016-04/threads.html#02486 https://lists.gnu.org/archive/html/qemu-devel/2016-04/thread...
- ryuuchin 11y agoIt should probably just be using /dev/urandom in the first place.
- Natanael_L 11y agoMost likely yes.
- strcat 11y agoThe getrandom() call should be used if it's available, and /dev/urandom on legacy systems. The system call blocks once when the system starts until the RNG is initialized with enough entropy, and then never again.
- mikepurvis 11y agoThe linked PDF: http://www.chronox.de/lrng/doc/lrng.pdf http://www.chronox.de/lrng/doc/lrng.pdf Page 4: "The new approach implements the modeling of a slow noise source within the LRNG based on the timing of interrupts and allowing other, even fast operating noise sources to contribute entropy. As discussed above for the legacy /dev/random, only the high-resolution time stamps deliver entropy for hardware events and other information processed by the legacy /dev/random implementation hardly have any entropy. This identification is used as a basis that solely the timing of interrupts is used."
- acqq 11y ago"The cryptographic processing of the entropic data is implemented with a well-known and well-studied deterministic random number generator: an SP800-90A DRBG as defined in [2] – naturally excluding the NSA-sponsored Dual-EC DRBG." "The concept of the LRNG allows the selection of the used DRBG and the backend cipher implementations at compile time." Is SP800-90A DRBG really state of the art? According to Wikipedia "the publication contains the specification for four cryptographically secure pseudorandom number generators for use in cryptography." Without Dual-EC it's still three different DRBGs. How good are they? Is there anything better?
- tptacek 11y agoThey're fine. They're sane, straightforward, relatively simple constructions based on hashes, HMAC, and ciphers running in CTR mode. You could make a CSPRNG more complicated, but there's not much reason to. The stuff that extends the "state of the art" beyond SP800-90A tends to be system-specific and feature-based. For instance, the "estimators" in the LRNG are an extension to SP800-90A (and a bad idea). Rolling over seed files are another extension.
- Cyph0n 11y agoThe Linux kernel is not using the true RNG circuitry included with all modern microprocessors (this is not entirely correct - see /u/matt_wulfeck's comment). As far as I know, this is because the kernel devs fear that the RNG circuit can be backdoored, allowing an unwanted entity to control the output of the random bitstream. This is an issue I've been thinking about quite a bit. Is there a way to somehow sign a circuit design on silicon and allow devs to check the circuit's integrity? For example, in the case of a TRNG, the developer can add a "verify" instruction to ensure that the TRNG on the user's CPU is not compromised before executing the RAND instruction. Of course, that's what the dev does, but the signing itself is much more complex. I've been looking through the literature and I haven't found much to go on. I know it's likely impossible to do given how many layers there are between silicon and machine code, but I'd like to at least give it a try.
- Nrsolis 11y agoI'd venture there isn't. The problem of verifying the integrity of embedded silicon (at the microcircuitry level) is one that hasn't really been solved yet. This has been a problem for the DoD since forever. THEY solved it partially by using US-sourced parts and working with industry to make sure the designs weren't sabotaged or otherwise backdoored. It's still an active concern though. http://www.dtic.mil/ndia/2014system/16990WedTrack1Shanahan.pdf http://www.dtic.mil/ndia/2014system/16990WedTrack1Shanahan.p...
- Cyph0n 11y agoI've never heard about the DoD initiative. Thanks for the link!
- Nrsolis 11y agoYeah. This has been something they've been looking into for a while now. Read all of the updates. It's turtles all the way down. https://www.schneier.com/blog/archives/2012/05/backdoor_found.html https://www.schneier.com/blog/archives/2012/05/backdoor_foun...
- 11y ago
- Tomte 11y agoIf I read this correctly, this new suggestion also keeps the entropy estimation voodoo: "By using the primary DRBG to serve /dev/random, the LRNG ensures that each random number generated by the primary DRBG must be backed by an equal amount of entropy that seeded the DRBG. Hence, the data derived from /dev/random is backed by information theoretical entropy." (page 21 of the PDF documentation)
- twic 11y agoFor an explanation of the voodoo nature of the blocking /dev/random, see: http://www.2uo.de/myths-about-urandom/ http://www.2uo.de/myths-about-urandom/ EDIT: or read tptacek's root comment on this very page.
- cesarb 11y agoI used to think that entropy estimation was nonsense, but last year I finally understood it. Copying my comment at https://lwn.net/Articles/642839/ https://lwn.net/Articles/642839/: Think of the pool's entropy as a "measure of unpredictability". If the entropy is ten bits, for instance, you'd need at most 1024 guesses to find the pool state. You should think of the random generator as having two separate and independent parts: the pool itself and the output function. Inputs are mixed into the pool using a cryptographic function which takes two values: the previous pool state and the input value, and outputs the new pool state. This function thoroughly mixes its inputs, such that a one-bit difference on any of them would result on average to half of the output bits changing, and other than by guessing it's not possible to get from the output back to the inputs. Suppose you start with the pool containing only zeros. You add to it an input containing one bit of entropy. Around half of the pool bits will flip, and you can't easily reverse the function to get back the input, but since it's only one bit of entropy you can make two guesses and find one which matches the new pool state. Each new bit of entropy added doubles the number of guesses you need to make; but due to the pigeonhole principle, you can't have more entropy than the number of bits in the pool. To read from the pool, you use the second part, the output function. It again is a cryptographic function which takes the whole pool as its input, mixes it together, and outputs a number. Other than by guessing, it's not possible to get from this output to the pool state. Now let's go back to the one-bit example. The pool started with zero entropy (a fixed initial state), and got one bit of entropy added. It can now be in one of two possible states. It goes through the output function, which prevents one reading the output from getting back to the pool state. However, since there were only two possible states (one bit of entropy), you can try both and see which one would generate the output you got... and now the pool state is completely predictable, that is, it now has zero bits of entropy again! By reading from the pool, even with the protection of the output function, you reduced its entropy. Not only that, but there were only two possible outputs, so the output itself had only one bit of entropy, no matter how many bits you had asked for. Now if you read a 32-bit number from a pool with 33 bits of entropy, you can make many guesses and find out a possible pool state. However, again due to the pigeonhole principle, there's on average two possible pool states which will generate the same 32-bit output. Two pool states = one bit. So by reading 32 bits, you reduced the remaining entropy to one bit. This is important because if you can predict the pool state, you can predict what it will output next, which is obviously bad. ---- Now, why isn't the situation that bad in practice? First, the input entropy counter tends to underestimate the entropy being added (by design, since it's better to underestimate than to overestimate). Second, "by guessing" can take a long enough time to be impractical. Suppose you have a 1024-bit pool, and read 1023 bits from it. In theory, the pool state should be almost completely predictable: there should be only two possible states. In practice, you would have to do more than 2^1000 guesses (a ridiculously large number) before you could actually make it that predictable. However, that only applies after the pool got unpredictable enough. That's why the new getrandom() system call (which you should use instead of reading /dev/random or /dev/urandom) will always block (or return failure in non-blocking mode) until the pool has gotten enough entropy at least once.
- matt_wulfeck 11y agoI didn't RTFA, but I'm wondering why Fortuna[1] hasn't seen better adoption or excitement. I think the BSD team made the right approach of making /dev/random|urandom both a CSPRNG, which if seeded and mixed is an unlimited source of high quality entropy. Fortuna also has the benefit of mitigating damage from a compromised generator. If the generator is compromised it's very difficult to rewind the RNG output and perform a history attack (is that even the right word for such a thing?). [1] https://www.schneier.com/cryptography/fortuna/ https://www.schneier.com/cryptography/fortuna/
- X86BSD 11y ago+1 This! Again I think this illustrates the echo chamber some camps can't seem to depart. But I agree with your thinking.
- tptacek 11y agoEvery kernel CSPRNG that continually collects entropy is effectively mitigating damage from a compromised generator. This isn't something specific to Fortuna.
- nshepperd 11y agoSo, more half-assed entropy estimation voodoo neither verified nor endorsed by actual cryptographers? For goodness' sake, Fortuna already exists. What happened to "don't invent your own cryptography"?
- acqq 11y agoIf I understood it, this change is supposed to be fully compatible with the existing interfaces and assumptions, it just claims to give more bits faster, using Fortuna would mean more changes at once and would mean the client code would have to change. Which is easier for OpenBSD to do than it is for Linux.
- twic 11y agoHow would it change the client code? If you use Fortuna to implement /dev/{u,}random, then the client code can just carry on opening that and reading as many bytes as it needs.
- tptacek 11y agoReplacing the LRNG with Yarrow or Fortuna or something like it would not break any client code, because no sane client code can rely on when /dev/random decides to block --- even by the LRNG's broken definition, that blocking happens at random, and could be deferred indefinitely if enough "entropy" were available.
- ape4 11y agoIf a machine is land locked without good sources of entropy, maybe it can go out to the internet for some nice randomness.
- twic 11y agoPerhaps some lovely clean Irish randomness: https://www.random.org/ https://www.random.org/ Sadly, LavaRand, the connoisseur's choice of internet randomness, is no longer with us: http://web.archive.org/web/20010926221159/http://lavarand.sgi.com/ http://web.archive.org/web/20010926221159/http://lavarand.sg...
- ts4z 11y agoSee lavarnd.org for a modernized (2003) version.
- cpeterso 11y agoIf the machine truly has little entropy to start, it might have trouble establishing a secure TLS connection to the remote source. That said, here is my little "wwwrand" script, that assumes Google News will return unpredictable and unrepeatable content. You could also throttle curl using --limit-rate to generate more interrupts for strace to log. nice -n 19 strace -CTiv -ttt curl -LNv https://news.google.com https://news.google.com 2>&1 | shasum -a 512
- tptacek 11y agoThis proposed design comprehensively ratifies Linux's nonsensical legacy random/urandom division; for instance, it maintains a "512 bit emergency entropy level" in case urandom becomes "stressed". It appears to be motivated principally by concerns about the quality of entropy being fed continually into the LRNG --- which is a nonproblem. This is silly. There are three problems a kernel CSPRNG needs to address: 1. It needs to seed itself reliably and not provide output when it's not securely seeded. 2. It needs to re-key itself regularly to provide forward secrecy and recovery from attacks. 3. It needs to be performant enough to be used in applications to the exclusion of all other RNGs. That's it. Once problem (1) is addressed, there is never again for the uptime of the system a concern about the quality or "level" of entropy in the LRNG. DRBGs like this document proposes are effectively stream ciphers (in fact: Salsa20, the new hotness in bulk cipher designs, is essentially a hash DRBG --- and, in the BSDs, a [crappy] stream cipher was the RNG). "Entropy" keys the cipher. The idea that you can "run low" on entropy is the same as the idea that you can "run low" on key. No. Kernel CSPRNGs do need continually updated entropy pools. But not because their original entropy is depleted! Rather: you want your RNG to be updated so that its "key" changes regularly, so that if your system is compromised transiently, you'll recover. And, of course, the division between /dev/random and /dev/urandom sabotages goal (3) --- arguably the most important goal. Almost every time you've read about some crypto randomness catastrophe --- from Debian commenting out their RNG and reducing SSH key space to 16 bits, to Bitcoin wallets coughing up private keys by repeating nonces --- you've been reading about userspace RNG failures. People use userspace RNGs because they think the kernel RNG is too slow. And they think the kernel RNG is too slow because they use /dev/random, which obstinately refuses to provide output when --- wait, I'm not dignifying /dev/random: it refuses to provide output at random.
- ianmiers 11y agoLinux RNGs: where refusing to XOR in additional hardware randomness into the output stream is not just a defensible opinion, but the dominant one.
- Natanael_L 11y agoRefusing to XOR it in is sensible. That RNG hardware might know too much about your existing entropy pool (either malicious bias or design flaws). Rejecting to mix it in cryptographically is however dumb.
- matt_wulfeck 11y agoCan someone help me understand why intel has both the rdrand and rdseed instruction set? If your device outputs high quality random data, why would it need two outlets?
- JoshTriplett 11y agohttps://software.intel.com/en-us/blogs/2012/11/17/the-difference-between-rdrand-and-rdseed https://software.intel.com/en-us/blogs/2012/11/17/the-differ... rdseed directly gives you the output of a hardware RNG, limited by the rate that hardware RNG produces random bits. rdrand gives you CSPRNG output seeded by rdseed.
- ryuuchin 11y agoBecause the DRNG (Digital RNG) on Intel processors filter the data through a DRNG (Deterministic RNG) (i.e. NIST 800-90)[1] which is constantly reseeded. The rdseed instruction was added later to allow for accessing the hardware generator directly (or the bits from the AES CBC-MAC conditioner directly). I don't know why rdseed was added a generation after rdrand. Whatever the case is you can guarantee that rdrand's internal generator gets reseeded by calling it a certain number of times[2]. You can also wait some amount of time between calls but it's likely faster just to generate more data to force the reseed. [1] Like Windows it uses AES-256 (AFAIK) in CTR mode as specified in NIST 800-90 or whatever the latest version of that standard is. [2] the DRNG reseeds automatically after generating 511 128-bit samples (from Intel's drng_samples source package)
- ryuuchin 11y agoSo this makes /dev/urandom more like Window's CryptGenRandom (aka RtlGenRandom) which is using AES256 running in CTR mode as a DRNG. I'm curious why there still needs to be a distinct /dev/random though. Hasn't history shown that they should really just both point to the same thing? Is there really a need for the difference here? Ditto with the entropy estimation, why is this still a thing?
- nullc 11y agoGah. Another brain-damaged system that implements complex (and, no doubt, broken) "entropy estimation" with a goal of delivering "information theoretic" security that doesn't even have a structure where information theoretic security could actually be proven. To the extent that any applications exist where a information theoretic RNG was required, this scheme does not provide one. Instead, it continues the to offer an interface that causes confusion and insecurity without an apparent benefit.
- apeace 11y agoHas anyone offered a better patch? I'm genuinely curious and don't know.
- tptacek 11y agoWhat's "a better patch"? We need to have a shared understanding of the problem before we can evaluate solutions.
- jwilkins 11y agoUnpredictable and unbiased source of bytes, even on server machines and virtualized hardware at boot time.
- zackelan 11y agoA patch [0] that added Fortuna [1] support to Linux was offered over 10 years ago. Fortuna specifically addresses the problems of entropy estimation that the grandparent comment brings up: "making any kind of estimate of the amount of entropy is extremely difficult, if not impossible. It depends heavily on how much the attacker knows or can know, but that information is not available to the developers during the design phase." "Fortuna solves the problem of having to define entropy estimators by getting rid of them." 0: https://jlcooke.ca/random/ https://jlcooke.ca/random/ 1: https://www.schneier.com/cryptography/paperfiles/fortuna.pdf https://www.schneier.com/cryptography/paperfiles/fortuna.pdf
- gajjanag 11y ago
- hsivonen 11y agoIs there a good reason not to copy what OpenBSD does in this area?
- brohee 11y agoNIH
- jwilkins 11y ago/dev/urandom while entropy available is low: $ rngtest -c 200000 -b 2000 < /dev/urandom ..... rngtest: bits received from input: 4000000032 rngtest: FIPS 140-2 successes: 199848 rngtest: FIPS 140-2 failures: 152 rngtest: FIPS 140-2(2001-10-10) Monobit: 24 rngtest: FIPS 140-2(2001-10-10) Poker: 15 rngtest: FIPS 140-2(2001-10-10) Runs: 60 rngtest: FIPS 140-2(2001-10-10) Long run: 54 rngtest: FIPS 140-2(2001-10-10) Continuous run: 0 rngtest: input channel speed: (min=3.782; avg=63.752; max=82.928)Mibits/s rngtest: FIPS tests speed: (min=4.559; avg=158.909; max=194.627)Mibits/s rngtest: Program run time: 83882495 microseconds It gets much worse.