最近我遇到了一个bug,当我的Linux服务器上的熵值过低时,我没有正确处理/dev/urandom读取返回比预期少的字节数。
我该如何通过测试来重现这个问题?有什么方法可以降低系统的熵值或可靠地清空/dev/urandom?
我想能够进行回归测试来验证我的修复。我正在使用Ubuntu 12.04。
根据random(4)手册,
read from the /dev/urandom device will not block
/dev/random
(没有任何u
)中读取大量字节(具体数量取决于硬件和系统)。因此,您无法 “耗尽” /dev/urandom
。
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.
我认为你应该使用/dev/random
,它确实可能会被阻塞而用尽。但是你不应该从中读取超过大约256位的内容。
/proc/sys/kernel/random/
中读取当前熵水平。 - TJD