linux – 是否有机会两次读取16字节/ dev / urandom数据,并获得相同的结果?教程
使用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.
(我的重点)因此,如果你想要加密安全性,我不会依赖于此.
简而言之,如果你只需要随机值,这可能就好了.如果你想要加密安全性,我不建议这样做.
希望这可以帮助!