TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Randomness in GNU/Linux

11 pointsby enyoneover 8 years ago

8 comments

tixzdkover 8 years ago
Important excerpt from random.c:<p><pre><code> * When random bytes are desired, they are obtained by taking the SHA * hash of the contents of the &quot;entropy pool&quot;. The SHA hash avoids * exposing the internal state of the entropy pool. It is believed to * be computationally infeasible to derive any useful information * about the input of SHA from its output. Even if it is possible to * analyze SHA in some clever way, as long as the amount of data * returned from the generator is less than the inherent entropy in * the pool, the output data is totally unpredictable. For this * reason, the routine decreases its internal estimate of how many * bits of &quot;true randomness&quot; are contained in the entropy pool as it * outputs random numbers. * * If this estimate goes to zero, the routine can still generate * random numbers; however, an attacker may (at least in theory) be * able to infer the future output of the generator from prior * outputs. This requires successful cryptanalysis of SHA, which is * not believed to be feasible, but there is a remote possibility. * Nonetheless, these numbers should be useful for the vast majority * of purposes. </code></pre> This is the same old story. &#x2F;dev&#x2F;urandom is what you should use, unless you believe that the hash function is broken
评论 #13350997 未加载
chowellsover 8 years ago
This is sort of accidentally technically correct.<p>It&#x27;s not <i>always</i> right to use &#x2F;dev&#x2F;urandom on Linux. During system startup, it does bad things if the entropy pool hasn&#x27;t been initialized yet. So yeah. You shouldn&#x27;t <i>always</i> use &#x2F;dev&#x2F;urandom, if you are writing code that&#x27;s designed to run during system startup.<p>In every other case, you should use &#x2F;dev&#x2F;urandom.<p>It&#x27;s a super-minor technicality preventing this article from being 100% wrong. Please don&#x27;t follow its advice.
评论 #13350765 未加载
Shoopover 8 years ago
For an alternative (and more widely accepted afaict) opinion, see <a href="http:&#x2F;&#x2F;www.2uo.de&#x2F;myths-about-urandom&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.2uo.de&#x2F;myths-about-urandom&#x2F;</a>
Rafertover 8 years ago
<p><pre><code> Majority of web pages and blog posts I’ve read suggests to use &#x2F;dev&#x2F;urandom </code></pre> Even the man page was updated to state that this is what you want unless under specific circumstances:<p><pre><code> The &#x2F;dev&#x2F;random interface is considered a legacy interface, and &#x2F;dev&#x2F;urandom is preferred and sufficient in all use cases, with the exception of applications which require randomness during early boot time; for these applications, getrandom(2) must be used instead, because it will block until the entropy pool is initialized.</code></pre>
notfedover 8 years ago
Yet another blogger spreading an ancient myth.<p>&quot;&#x2F;dev&#x2F;urandom gives lower quality randomness&quot; - Simply. Not. True.
the8472over 8 years ago
Or one could just use the syscall[0] which does the right thing™. If no flags are provided it only blocks at boot until the pool is properly seeded and then becomes nonblocking until shutdown.<p>[0] <a href="http:&#x2F;&#x2F;man7.org&#x2F;linux&#x2F;man-pages&#x2F;man2&#x2F;getrandom.2.html" rel="nofollow">http:&#x2F;&#x2F;man7.org&#x2F;linux&#x2F;man-pages&#x2F;man2&#x2F;getrandom.2.html</a>
jlouisover 8 years ago
The post lacks the term &quot;CSPRNG&quot;, which I would have thought to be there in a discussion about randomness. Especially in collaboration with the concept of security.<p>The long story short, a Pseudorandom sequence can be more than enough in a security setting, provided that the stream of bits follow certain rules. For instance, it should be impossible to guess the next bit based on known history of bits. If &#x2F;dev&#x2F;urandom is backed by such a generator, which it is in many modern operating systems, then it is arguably safer than what the claim of the post is.
GFK_of_xmaspastover 8 years ago
Why&#x27;s it GNU&#x2F;Linux when there&#x27;s no userspace involved?