4

i want to test the entropy of my seed generator: in my case is /dev/urandom. I've read that this operation is non useful because it is the result of CSPRNG (normally not accessible).

But what i obtain from urandom is the seed for my RBG algorithm and than it is the real seed for me.

Do you think the test can be useful or not? Do you have any suggestion on how it should be performed?

e-sushi
  • 17,891
  • 12
  • 83
  • 229
user44580
  • 51
  • 2

2 Answers2

9

Bear in mind that entropy is measured against a source using a model. It is unlikely you will find any model or attack against /dev/urandom that worked purely by analysing its output - from that perspective it will have "perfect" entropy by any realistic measure. However, so would Mersenne Twister unless you knew how to build a model that extracted its state . . . in which case you could reduce that to zero entropy after 624 measurements.

In short, measuring "entropy" of any RNG with a generic model is unlikely to show you anything. If you don't take care, even very bad RNGs will pass tests such as compressibility or naive checks for patterns.

There are tools that allow you to check that a source is statistically random in various ways. I could suggest Dieharder as it provides a command-line interface which is easy to connect via a *nix pipe. This will run a variety of simulations and pattern-detection algorithms against a source of alleged random bytes.

A test against /dev/urandom should look like this:

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

. . . and may take a few hours to complete, since the tests consume large amounts of source data.

Caveats:

  • Proving something is "random" is not easy. At best you get a probability of getting the same result from a theoretical truly random source. If you run hundreds of tests (like Dieharder does), then some will probably end up reporting a low $p$ value - e.g. 0.01 or less. This is not necessarily bad. RNGs that really fail Dieharder tend to do so very dramatically with $p < 0.000001$ in multiple related tests.

  • If you find that a source is statistically random, that does not mean it is secure, just that it has demonstrated one desirable property of a secure system.

Neil Slater
  • 1,119
  • 8
  • 20
3

Testing the output of /dev/urandom is of little use, because it can only catch gross errors in the implementation of its CSPRNG part (and then only a fraction of these). Such test will fail to catch implementation mistakes in the generator's seeding, which matters, is much more likely to be faulty, and has historically been a major source of problems (like insufficient entropy in the generation of a machine's key at setup).

fgrieu
  • 140,762
  • 12
  • 307
  • 587