【问题标题】:How random is urandom?urandom有多随机?
【发布时间】:2009-12-08 18:34:41
【问题描述】:

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

还有可能得到一个 1 的流吗?

【问题讨论】:

  • “它被认为是安全的吗?” 什么安全?答案完全取决于上下文。

标签: linux random entropy


【解决方案1】:

注意 4.5 年后:这是个坏建议。有关详细信息,请参阅theselinks 之一。

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

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

【讨论】:

  • +1,尽管收集自己的熵通常比等待阻塞的 /dev/random 更容易、更快。在进行蒙特卡罗模拟时,我以这种方式填充大文件以获得“瓶装”熵,敲击键和移动鼠标比等待 /dev/random 快得多
  • 我很困惑:这怎么比使用 /dev/urandom 更好?
  • 上次我在 linux 上查看 /dev/urandom 返回与 /dev/random 相同的输出只要池中有熵,因为它们都使用池。不同之处在于,当没有存储熵时,urandom 将使用普通的重新散列算法,而 random 将等到添加了新的熵。
  • 另见this article,它主张专门使用/dev/urandom
  • 没错,我不再相信自己的答案。我也喜欢this article
【解决方案2】:

请查看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.

【讨论】:

  • 但是可以说你是从随机或随机抽取的。系统就坐在那里,让我们说一张现场CD。每次发生相同情况时,熵不会相似吗?
  • 这是一个 BSD 手册页的链接,在这种情况下,Linux 的行为是不同的:/dev/random 比 /dev/urandom “强”。
【解决方案3】:

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

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

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

如果在早期启动有疑问,您是否收集了足够的熵。请改用系统调用getrandom()。 [1] 它两全其美,它会阻塞直到(仅一次!)收集到足够的熵,之后它将永远不会再次阻塞。

[1]git kernel commit

【讨论】:

    猜你喜欢
    • 2012-05-07
    • 1970-01-01
    • 2016-09-01
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多