LWN: Comments on "Uniting the Linux random-number devices" https://lwn.net/Articles/884875/ This is a special feed containing comments posted to the individual LWN article titled "Uniting the Linux random-number devices". en-us Fri, 29 Aug 2025 13:09:20 +0000 Fri, 29 Aug 2025 13:09:20 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Uniting the Linux random-number devices https://lwn.net/Articles/886441/ https://lwn.net/Articles/886441/ neggles <p>Under the current behaviour, /dev/random will block if the CSPRNG has not yet been fully seeded, and /dev/urandom will not. For 99.9% of use cases in userspace there's no functional difference between the two; by the time your program is running, the CSPRNG will almost certainly be fully seeded. on a systemd system it definitely will be.</p> <p> systemd and other initsystems are just about the only place where the distinction between "blocks until fully seeded" and "gives you the best numbers it can even if they suck" - as Lennart mentioned <a href="https://lore.kernel.org/lkml/Ygps2W6MfxKkP5eD@gardel-login/">here,</a> systemd uses the non-blocking source during early boot to seed some hash tables; the quality of that randomness is not important since they'll be reseeded later if collisions occur, but it can't carry on with boot until it's got <i>something</i> to work with. </p> <p> In other words, the distinction only really matters if you're writing an initsystem. </p> Tue, 01 Mar 2022 11:07:27 +0000 Uniting the Linux random-number devices https://lwn.net/Articles/886422/ https://lwn.net/Articles/886422/ mpr22 <div class="FormattedComment"> Now? When it disappearing would break a userspace program you don&#x27;t want to (or lack the means to) recompile.<br> </div> Mon, 28 Feb 2022 23:17:53 +0000 Uniting the Linux random-number devices https://lwn.net/Articles/886421/ https://lwn.net/Articles/886421/ koh <div class="FormattedComment"> So exactly when do I want /dev/random in contrast to /dev/urandom?<br> </div> Mon, 28 Feb 2022 22:57:17 +0000 Uniting the Linux random-number devices https://lwn.net/Articles/886312/ https://lwn.net/Articles/886312/ nybble41 <div class="FormattedComment"> <font class="QuotedText">&gt; before I could assume that /dev/random gives to me whatever the hardware generates</font><br> <p> That has not been the case in any version of /dev/random in Linux since the feature was first implemented as a mix of sources of hardware entropy based on secure hashes in 1994. The notable differences since then are (a) using better mixing functions, (b) adding more sources of entropy, and (c) no longer limiting the amount of data read (after initialization) based on a flawed interpretation of entropy.<br> <p> If you want &quot;raw&quot; random data from hardware then you want /dev/hwrng, not /dev/random.<br> </div> Mon, 28 Feb 2022 04:06:31 +0000 Uniting the Linux random-number devices https://lwn.net/Articles/886257/ https://lwn.net/Articles/886257/ koh <div class="FormattedComment"> <font class="QuotedText">&gt; If you have found a vulnerability in the BLAKE2 hash function</font><br> <p> well, that&#x27;s cheap; of course not and it&#x27;s beside the point.<br> <p> <font class="QuotedText">&gt; that makes this distinction remotely meaningful in any way</font><br> <p> This is more to the point: before I could assume that /dev/random gives to me whatever the hardware generates - meaning, I can test the acquired data itself, develop and test hardware based on it and even find out when there is not enough data. I realize that the last point was meant to be fixed, but it does constitute a quite substantial shift in semantics I honestly see no reason for - if you want unlimited &quot;randomness&quot; go for /dev/urandom. Hiding the distinction between the two devices is a step in the wrong direction.<br> </div> Sun, 27 Feb 2022 00:28:42 +0000 Uniting the Linux random-number devices https://lwn.net/Articles/885742/ https://lwn.net/Articles/885742/ atnot <div class="FormattedComment"> If you have found a vulnerability in the BLAKE2 hash function that makes this distinction remotely meaningful in any way I&#x27;d encourage you to publish that research as soon as possible.<br> </div> Tue, 22 Feb 2022 08:30:27 +0000 Uniting the Linux random-number devices https://lwn.net/Articles/885734/ https://lwn.net/Articles/885734/ koh <div class="FormattedComment"> Unfortunately - or fortunately - the fact that /dev/random and /dev/urandom use the same CRNG implies that /dev/random no longer behaves as the name suggests: you get crypto-strength random bits, but not random bits. It&#x27;s clear that you didn&#x27;t get random bits before they&#x27;ve been made the same, but that could&#x27;ve been considered a bug: preprocessing the hardware source&#x27;s output may be necessary, but algorithmically modifying output and thereby decreasing entropy (necessarily) for hardware RNGs is suboptimal at best when you&#x27;re after random numbers (opposed to crypto-strength random numbers).<br> <p> While that change may have been motivated by practical reasons, it nonetheless means you now get a filtered view on random bits - filtered through the eyes of crypto-strength. It may easily not be what an application wants to receive. This blurring of semantics concerns me.<br> </div> Mon, 21 Feb 2022 23:40:28 +0000 Uniting the nethack random-number devices https://lwn.net/Articles/885666/ https://lwn.net/Articles/885666/ error27 <div class="FormattedComment"> I used to use Chrysalis BBS (Dallas TX 1997). It had a bunch of games but hacking the RNG was always the real game. Good times.<br> </div> Mon, 21 Feb 2022 14:33:21 +0000 Uniting the Linux random-number devices https://lwn.net/Articles/885473/ https://lwn.net/Articles/885473/ ianmcc <div class="FormattedComment"> Currently /dev/urandom doesn&#x27;t block. This means there is a window once the machine has booted where you can draw numbers from /dev/urandom and it isn&#x27;t properly seeded. /dev/random will block until it is properly seeded. Other than that, since 2020 they are equivalent, and /dev/random won&#x27;t ever block after it has been seeded.<br> <p> Once /dev/urandom is properly seeded (or you read from /dev/random), if you&#x27;re an attacker and you draw 1 billion numbers, ... it doesn&#x27;t help you because you can&#x27;t crack the crypto in the PRNG. (well, if you *can*, you&#x27;ve made a breakthrough in crypto that will make you as famous as you&#x27;ll be infamous).<br> <p> In the old days (well, I think prior to 2020? So not so old), /dev/random would remove N bits of entropy from the pool for every N bits read from /dev/random, and if there isn&#x27;t N bits of entropy available then it would block until there is. This was based on a misunderstanding that you need to consume entropy to generate cryptographically secure random numbers. But if you use a cryptographically secure PRNG, then you only need enough bits of entropy for the seed of the PRNG, and you can generate as many secure random bits as you like. Predicting the next number in the sequence requires determining the internal state of the PRNG, which isn&#x27;t possible from examining the prior output (as long as the crypto algorithm doesn&#x27;t contain any flaws). So there is an assumption that the crypto is strong and won&#x27;t be broken.<br> </div> Sat, 19 Feb 2022 14:37:39 +0000 Uniting the nethack random-number devices https://lwn.net/Articles/885366/ https://lwn.net/Articles/885366/ ejr <div class="FormattedComment"> sssshhhh... Don&#x27;t spoil assigned homework.<br> </div> Fri, 18 Feb 2022 17:45:18 +0000 Uniting the Linux random-number devices https://lwn.net/Articles/885355/ https://lwn.net/Articles/885355/ derobert <div class="FormattedComment"> That&#x27;s not right. Both give you bits from a CSPRNG, they work exactly the same. It has to be that way — the entropy collected from most sources isn&#x27;t fully random, so you need some process to extract the entropy from it and a CSPRNG is a good way to do that.<br> <p> Originally /dev/random made some guess of when entropy was &quot;depleted&quot;, but that didn&#x27;t really make sense — one effect of a PRNG being cryptography secure is it doesn&#x27;t deplete the entropy. So a while back, that was removed.<br> <p> An attacker can gain no knowledge of the CSPRNG&#x27;s state from its output (well, at least not without an impossible number of them, like 2^128). It doesn&#x27;t matter if they have a few billion or trillion. <br> <p> And Linux keeps mixing in new entropy, so the internal state changes over time.<br> <p> </div> Fri, 18 Feb 2022 16:58:14 +0000 Uniting the Linux random-number devices https://lwn.net/Articles/885239/ https://lwn.net/Articles/885239/ Otus <div class="FormattedComment"> No, other than initial blocking behavior they are the same already, they use the same entropy pool and the same crng algorithm. If there is not yet enough entropy one blocks while the other warns and returns possibly-not-random data.<br> </div> Fri, 18 Feb 2022 05:59:18 +0000 Uniting the Linux random-number devices https://lwn.net/Articles/885235/ https://lwn.net/Articles/885235/ developer122 <div class="FormattedComment"> Let me get this straight:<br> <p> At the moment, both /dev/random and /dev/urandom block, until they have enough entropy. However their entropy sources differ. /dev/random draws from &quot;truly random, crpto-ready&quot; bits that came directly from a hardware source of some kind, where as /dev/urandom draws from a PRNG that is seeded from /dev/random&#x27;s hardware-backed bits.<br> <p> But we don&#x27;t care, because the bits that have passed through the pseudo-RNG have like 99% of the randomness of the hardware bits and are &quot;good enough&quot; for crypto to rely on? (even though they might be a little stale if it&#x27;s been a while since the PRNG was re-seeded)<br> <p> I _suppose_ that drawing from /dev/urandom right after it&#x27;s been seeded the first time with bits from /dev/random might be just as good as drawing from /dev/urandom, but what&#x27;s the difference in their worst case? ie. if I&#x27;m an attacker and later I draw 1 billion numbers from the PRNG before the next time it&#x27;s re-seeded.<br> </div> Fri, 18 Feb 2022 03:08:39 +0000 Uniting the nethack random-number devices https://lwn.net/Articles/885229/ https://lwn.net/Articles/885229/ qys <div class="FormattedComment"> Someone actually did a really fast ascension by manipulating its RNG. &lt;<a href="https://pellsson.github.io/">https://pellsson.github.io/</a>&gt;<br> </div> Fri, 18 Feb 2022 01:33:20 +0000 v1 posted https://lwn.net/Articles/885185/ https://lwn.net/Articles/885185/ zx2c4 <div class="FormattedComment"> Thanks for this summary. Encouraged by your read on the discussion, I wound up submitting a real v1 of the patch: <a href="https://lore.kernel.org/lkml/20220217162848.303601-1-Jason@zx2c4.com/">https://lore.kernel.org/lkml/20220217162848.303601-1-Jaso...</a><br> <p> </div> Thu, 17 Feb 2022 16:33:32 +0000 Uniting the nethack random-number devices https://lwn.net/Articles/885184/ https://lwn.net/Articles/885184/ ballombe <div class="FormattedComment"> The irony is that nethack internal RNG is very weak so is easy to bruteforce even if the kernel RNG was perfect.<br> &lt;<a href="https://nethackwiki.com/wiki/Random_number_generator">https://nethackwiki.com/wiki/Random_number_generator</a>&gt;<br> </div> Thu, 17 Feb 2022 16:30:56 +0000