urandom是多么随机?

时间:2009-12-08 18:34:41

标签: linux random entropy

在Linux中,/dev/urandom/的随机性如何?它被认为是安全的吗?

还可以获得1的流吗?

3 个答案:

答案 0 :(得分:9)

注意4。5年后:这是不好的建议。有关详细信息,请参阅these links之一。

如果您在Linux上生成加密密钥,则需要/dev/random,即使它阻止了 - 您也不需要那么多位。

对于其他任何事情,例如生成随机测试数据或不可预测的会话ID,/dev/urandom都可以。在大多数系统中有足够的熵源(键盘和鼠标事件的时间,网络数据包等),输出将是不可预测的。

答案 1 :(得分:4)

请查看man page

Yarrow is a fairly resilient algorithm, and is believed to be resistant
     to non-root.  The quality of its output is however dependent on regular
     addition of appropriate entropy. If the SecurityServer system daemon
     fails for any reason, output quality will suffer over time without any
     explicit indication from the random device itself.

     Paranoid programmers can counteract this risk somewhat by collecting
     entropy of their choice (e.g. from keystroke or mouse timings) and seed-
     ing it into random directly before obtaining important random numbers.

答案 2 :(得分:1)

使用/ dev / urandom,它的加密安全。

好读:http://www.2uo.de/myths-about-urandom/

"如果您不确定是否应该使用/ dev / random或/ dev / urandom,那么可能您想使用后者。"

如果在早期开机时有疑问,那么你就会收集到足够的熵。请改用系统调用getrandom()。 [1] 它是两个世界中最好的,它阻止(只有一次!)足够的熵被收集,之后它永远不会再阻塞。

[1] git kernel commit