7

I work with virtual machines a lot, and they seem to generally be low on entropy (no mouse or other entropy-generating inputs). A bug with my software has surfaced, and I think it's due to running out of entropy. I want to test it, but it only happens occasionally, and is hard to reproduce.

How can I empty out the entropy pool to test how my software behaves when it has run out?

(Note: I'm calling someone else's code that uses dev/random, so using dev/urandom instead to prevent blocking isn't an option.)

2 Answers2

4

First of all, you should make sure that it's really the depletion of the random pool that produces the bug in your software. You can run cat /proc/sys/kernel/random/entropy_avail to test the available entropy on your system and check if it hits zero.

Secondly, AFAIK (I haven't tested these commands) you can decrease the entropy pool by setting the appropriate variable in /proc. To set it to 32 bits:

echo 32 > /proc/sys/kernel/random/poolsize

or

sysctl -w kernel.random.poolsize=32

dr_
  • 29,602
  • 1
    "Make[ing] sure that it's really the depletion of the random pool" is exactly what I'm trying to do. :P Anyway, your commands both tell me permission denied, even as root. – AlbeyAmakiir May 05 '15 at 01:25
  • 1
    If you ran those commands, you'd find that they don't work at all. The pool size is hardcoded in /drivers/char/random.c:275 so you have to recompile the kernel to change it. – Navin Jan 28 '16 at 11:24
3

cat /dev/random will continuously use up entropy as it becomes available, keeping it at or near zero. It's not perfect, but it's simple.