linux - 是否有机会两次读取 16 字节/dev/urandom 数据,并获得相同的结果?

标签 linux math random

使用 Linux 3.2,我想使用 /dev/urandom 实现 UID 算法。

有可能两次读取 16 个随机字节,并得到相同的结果。但机会小到可以忽略不计吗?

最佳答案

/dev/urandom 应该是一个随机设备,应该看起来是均匀随机的,并且在均匀随机的序列中,您会期望找到重复的模式。然而,由于有 2128 个可能的 16 字节序列,这应该以 2-128 的概率发生,这个概率很小。

也就是说,/dev/urandom 的密码安全性并不为人所知,并且可能存在公开文献中没有的攻击来强制行为退化(也许某些政府机构知道如何例如,这样做)。来自man pages :

A read from the /dev/urandom device will not block waiting for more entropy. As a result, if there is not sufficient entropy in the entropy pool, the returned values are theoretically vulnerable to a cryptographic attack on the algorithms used by the driver. Knowledge of how to do this is not available in the current unclassified literature, but it is theoretically possible that such an attack may exist. If this is a concern in your application, use /dev/random instead.

(我的重点)因此,如果您试图获得密码安全性,我不会依赖它。

简而言之,如果您只需要随机值,这可能没问题。如果您想追求密码安全,我不建议您这样做。

希望这对您有所帮助!

关于linux - 是否有机会两次读取 16 字节/dev/urandom 数据,并获得相同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18970943/

相关文章:

javascript - 将限制拖放到 Angular

linux - 监听 netcat 工作但不能 grep'able(或其他几个实用程序)

python : easy way to do geometric mean in python?

linux - 使用“vi”编辑器的垃圾字符

java - 获取在 2D 平面上相互接触的对象的数量副本(Java 算法)

performance - 获得 10000+ 个唯一的随机数(性能)

r - 如何将伪随机变量与字符串关联?

javascript - 如何随机生成一个介于 -0.5 和 0.5 之间的数字?

linux - docker 的一个兼容性问题

应用程序已知/可见的 linux 驱动程序功能