2

I'm developing a shell script that only uses /dev/random in the following manner:

dd if=/dev/random of=%{outputFile} count=512 bs=1 2>/dev/null

I explicitly do not want to use /dev/urandom, even though it is better to use for a variety of reasons, because I want to test a particular piece of hardware random number generator that I purchased for my computer and would like to rely on /dev/random entirely.

Now, I know I can check entropy_avail and poolsize but, how exactly should I go about ensuring to the best of my ability that performing my dd call won't block? For some reason I feel like doing a simple if check on the size of entropy_avail isn't sufficient because entropy_avail doesn't necessarily tell me exactly how many bits are available to be used by /dev/random.

How should I go about safely checking if performing dd on /dev/random is going to block?

  • I'm curious. Why would you purchase a specialized random number generator? Wouldn't it be easier (and cheaper) to make a sha512 hash of the webcam picture (or microphone). Thanks to random noise on the sensor, even if you the webcam takes a picture of a wall, it should still be quite random. – Benjamin Jun 21 at 21:15
  • I’ll see if I can dig up the link but I seem to recall from the security stack exchange that the common advice about random vs. urandom is outdated. – Wildcard Jun 21 at 21:30
  • 1
    @roaima, here is the link I was referring to; however I see that in this case the Original Poster specifically wants to test a hardware number generator (otherwise urandom would be fine). – Wildcard Jun 21 at 23:47
  • @Wildcard i'm just a hobbyist :) looking to do some very amateur data collection on various medium of randomness. – John Locke Jun 24 at 13:36
3

If using GNU dd, you can use

dd if=/dev/random iflag=nonblock

for it to read up to 512 bytes without blocking (so returning fewer bytes if fewer are available).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.