4

I have access to genuine random numbers - random.org, for example.

I have a number of processes using /dev/random and my value for /proc/sys/kernel/random/entropy_avail is 143, which is pretty low.

I'd like to have a process that monitors /proc/sys/kernel/random/entropy_avail and, when it drops below about 3000, tops it up.

How can I incorporate the random numbers from random.org into /dev/random so that entropy_avail increases?

2 Answers 2

4

Do not use an online source of entropy!

If your system currently has insufficient entropy, then it will not be able to make a secure connection to random.org and any material you download from it will not be secret. Furthermore, you should not be using the blocking device anyway. It's perfectly fine to use /dev/urandom, no matter how low the entropy estimate is. If for whatever reason you are using a program that is foolishly using the blocking device, you can keep it topped off by installing haveged, a daemon that attempts to generate random data from memory latency. Please see https://www.2uo.de/myths-about-urandom for more.

If you still want to shoot yourself in the foot, then you can use an IOCTL on the random character device to adjust the entropy estimate. From random(4), the RNDADDENTROPY IOCTL is what you want:

RNDADDENTROPY
       Add some additional entropy to the input pool, incrementing
       the entropy count.  This differs from writing to /dev/random
       or /dev/urandom, which only adds some data but does not incre‐
       ment the entropy count.  The following structure is used:

           struct rand_pool_info {
               int    entropy_count;
               int    buf_size;
               __u32  buf[0];
           };

       Here entropy_count is the value added to (or subtracted from)
       the entropy count, and buf is the buffer of size buf_size
       which gets added to the entropy pool.

This IOCTL requires the CAP_SYS_ADMIN capability to function.


Very related:

2
  • 1
    Adding online entropy source probably doesn't really warrant such a strongly worded warning. AFAIU it doesn't really hurt to add entropy from an online source of entropy, at worst it'll just give you fuzzy feeling because your entropy_avail value appears higher, but it shouldn't cause the output of your /dev/(u)random to be any less unpredictable. So while it may be useless if the attacker controls one of your entropy source, it wouldn't really be harmful?
    – Lie Ryan
    Commented Feb 27, 2019 at 11:06
  • @LieRyan You're correct, but only because of how a quirk of the Linux kernel random driver works. Generally, getting random data from an online source is a terrible idea. It's for the same reason that I would warn strongly against homebrew crypto even if OP is planning on cascading it with AES.
    – forest
    Commented Feb 27, 2019 at 11:07
1

Given that the only existing answer to this question explains things that aren't viable, here are a couple of options which might be viable:

  1. haveged - https://github.com/jirka-h/haveged, which uses the HAVEGE algorithm described at https://www.irisa.fr/caps/projects/hipsor/; available on Debian/Ubuntu in the package of the same name.
  2. rng-tools - uses built-in hardware entropy sources and (optionally) the Intel/AMD RDRAND instruction; available in Debian/Ubuntu in the packages rng-tools-debian and rng-tools5.

This is not an endorsement of the options listed above, just a note that there may be usable options. Evaluating their security or randomness quality is an exercise left to the reader. :-)

Note also that in Linux kernel 5.x, changes to the entropy generation in the kernel mean that an algorithm similar to HAVEGE is built in, and /dev/random is no longer blocking. (See the links in the haveged README for details.)

2
  • 1
    Actually HAVEGE is not built in, it's a similar algorithm called Jitterentropy (although that's not what's responsible for it being non-blocking). But yeah, haveged works. It uses RNDADDENTROPY to increase the entropy count.
    – forest
    Commented Dec 14, 2022 at 7:33
  • Updated answer to reflect that a bit better.
    – Paul Gear
    Commented Dec 15, 2022 at 11:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .