Dieharder Tests on a qemu VM – 1: Setup

Diehard suite is a collection of tests for random number generators. I recently used it on a virtual machine feeding on the /dev/urandom of it’s host.

The Setup:

Used Debian 7.2 as both the host and the guest. The virtio-rng-pci virtual device allows feeding entropy from the host to the guest since qemu 1.3.

Invoking qemu with

-device virtio-rng-pci

attaches host:/dev/random to guest:/dev/hwrng. This is usually slow (tried it; too slow on my laptop), because /dev/random blocks. So I used the following:

$ qemu-system-x86_64 debian.qcow -L pc-bios -enable-kvm \
  -object rng-random,filename=/dev/urandom,id=rng0 \
  -device virtio-rng-pci,rng=rng0

which ties the host:/dev/urandom to the guest:/dev/hwrng. To verify that this is happening, run

$ cat /sys/devices/virtual/misc/hw_random/rng_available
$ cat /sys/devices/virtual/misc/hw_random/rng_current

These should return `virtio`

Now that guest:/dev/hwrng is available, it can be used to feed other sources of entropy on the guest. This can be done using rngd – a daemon available with the rng-tools package. The file /etc/default/rng-tools lets you provide the source of input to rngd. Adding


to the file and restarting the daemon

$ /etc/init.d/rng-tools start

begins mixing entropy into the kernel’s pool. If you were running low on entropy, there is a noticeable rise in guest:entropy_avail sometime after this, host:entropy_avail falls a little.

You can find an opensource implementation of the diehard tests here.

$ cat /dev/urandom | dieharder -a -g 200

begins dieharder with all (-a) tests on the data obtained from stdin (-g 200), i.e. the data piped from /dev/urandom

Keep looking at entropy_avail and notice a drop. (Reading from it too much also depletes entropy, so read less often).



1 thought on “Dieharder Tests on a qemu VM – 1: Setup”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s