我如何耗尽/ dev / urandom进行测试?

时间:2012-10-22 17:59:56

标签: linux security ubuntu random entropy

我最近遇到了一个错误,当我的linux服务器上的熵太低而且/ dev / urandom的读取次数低于预期的字节数时,我没有正确处理。

如何通过测试重新创建?有没有办法降低系统上的熵或可靠地清空/ dev / urandom?

我希望能够进行回归测试来验证我的修复。我使用的是Ubuntu 12.04。

1 个答案:

答案 0 :(得分:8)

根据random(4)手册页,

read from the /dev/urandom device will not block

如果要阻止,请从/dev/random(没有任何u)读取大量字节。 (有多少是硬件和系统依赖的)。

所以你不能“exaust”/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位。