How can I exhaust /dev/urandom for testing?

六月ゝ 毕业季﹏ 提交于 2019-12-23 17:24:50

问题


I recently had a bug where I didn't properly handle when the entropy on my linux server got too low and a read of /dev/urandom returned less than the number of bytes expected.

How can I recreate this with a test? Is there a way to lower the entropy on a system or to reliably empty /dev/urandom?

I'd like to be able to have a regression test that will verify my fix. I'm using Ubuntu 12.04.


回答1:


According to random(4) man page,

read from the /dev/urandom device will not block

You should read a lot of bytes from /dev/random (without any u) if you want it to block. (How many is hardware and system dependent).

So you cannot "exaust" /dev/urandom, since

 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.

I believe you should use /dev/random which indeed can be exhausted, by blocking. But you should not read more than about 256 bits from it.



来源:https://stackoverflow.com/questions/13017023/how-can-i-exhaust-dev-urandom-for-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!