使用 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/