entropy-saver.c to seed real entropy
![](https://secure.gravatar.com/avatar/1ca32cb0045674589d3d6488c2463260.jpg?s=120&d=mm&r=g)
In short: Linux uses a diverse random system, with an internal pool that is not exposed and the ones which are fed by that one which actually serve user requests. One lengthy examination has been produced by the German BSI: [1] The problem occurred to me once AlpineLinux switched from kernel 4.14 to 4.19: i had hanging boots of half an hour and such on the server VM, as the RNG would not unlock; even on a CoreDuo laptop i saw this: [ 15.706636] random: dnsmasq: uninitialized urandom read (128 bytes read) [ 183.806112] random: crng init done But likely only because i hit a key... I looked around and saw other people with the same problem using the haveged daemon, which is kind of strange as it can generate thousands of bits of hard randomness in a second.Anyway, shortly before Christmas on the LUGA (Linux User Austria) ML that came up again via a Debian user, and that made me write an entropy saver. Because, the thing is, that "writing data to urandom" does no(t) (longer) do anything to /proc/sys/kernel/random/entropy_avail, but that is the value which control locking state of the RNG. As far as i know there is no way to make that happen via the shell. Modern CPUs may offer things, and it may be that on some CPUs Linux offers random.trust_cpu, yet i have no system where that is true. My 8th generation i5 has RDRAND and RDSEED, but still the entropy-saver as attached helps here. What it does is just the same as is done to urandom seed, so i have in /etc/rc # Load random seed /bin/cat /var/lib/urandom/seed > /dev/urandom /sbin/entropy-saver load /var/lib/urandom/entropy and in /etc/rc.shutdown # Save random seed /bin/dd if=/dev/urandom of=/var/lib/urandom/seed count=1 2> /dev/null /sbin/entropy-saver save /var/lib/urandom/entropy So just in case someone sees boot hangs, that will help to unlock the RNG, by not wasting prescious entropy collected during uptime. It has been posted to LUGA and openssl-users in the past, a little bit of feedback i had and is in. [1] https://www.bsi.bund.de/SharedDocs/Downloads/EN/BSI/Publications/Studies/LinuxRNG/LinuxRNG_EN.pdf?__blob=publicationFile&v=7 --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)
![](https://secure.gravatar.com/avatar/5ea1a7e62e5bd89d1a5e25411c7b5a08.jpg?s=120&d=mm&r=g)
I think you can already do this with rngd. rngd -r <your entropy dump> -o /dev/random
![](https://secure.gravatar.com/avatar/1ca32cb0045674589d3d6488c2463260.jpg?s=120&d=mm&r=g)
Hey. Don Cupp wrote in <1152876777.449542.1560380336620@mail.yahoo.com>: |I think you can already do this with rngd. | |rngd -r <your entropy dump> -o /dev/random Well i have never said i made a brilliant discovery or something. Hm, i did not know about rngd until you mentioned it (i was grown in BSD land), but looking at the manual -r requires a random producing hardware device .. so does looking at the code. That i do not have around. Maybe you too, then you now have a little helper. I personally think it is kind of overengineering and silly that i as the owner of my box cannot simply store away and feed back in entropy via the shell, just as via that urandom seed stuff. In fact that entire RNG issue makes me sick, eh, a pool of noise protected by two chained expensive math algorithms, going into a second pool which does ditto or something, on a box that does so much stuff, with (hopefully) hooks sitting on top of all the virtual file system and network and input device and time counters which add some further noise, all the time, why am i not allowed to simply feed in some collected random data to unlock that mess. Terrible. That is: i remember i creating PGP keys with hammering less than five minutes on my keyboard alone. The difference in the amount of random is as large as the universe. Howdy. --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)
![](https://secure.gravatar.com/avatar/96ad16d1aebdf40079e2c719e257f827.jpg?s=120&d=mm&r=g)
I suspect you could also purchase a hardware entropy generator. I saw one the other day for sale from an EU store. https://store.vikings.net/chaoskey
![](https://secure.gravatar.com/avatar/1ca32cb0045674589d3d6488c2463260.jpg?s=120&d=mm&r=g)
James Buren wrote in <620c5011-3fdb-3c4c-3d08-6d4dc283d7ec@ryuo.xyz>: |I suspect you could also purchase a hardware entropy generator. I saw |one the other day for sale from an EU store. | |https://store.vikings.net/chaoskey 50 Euro. Yes :) --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)
![](https://secure.gravatar.com/avatar/9a41e13d619ad0fbd1b30f7b4f4ce48f.jpg?s=120&d=mm&r=g)
On Wed, 12 Jun 2019 21:52:58 +0200 Steffen Nurpmeso wrote: <snip>
But likely only because i hit a key... I looked around and saw other people with the same problem using the haveged daemon, which is kind of strange as it can generate thousands of bits of hard randomness in a second.> <snip>
Would you explain what you mean by this? I've been using haveged for years, without issues, afaict. Pedja
![](https://secure.gravatar.com/avatar/1ca32cb0045674589d3d6488c2463260.jpg?s=120&d=mm&r=g)
Predrag Ivanović wrote in <20190613011357.04ac80c9@deus>: |On Wed, 12 Jun 2019 21:52:58 +0200 |Steffen Nurpmeso wrote: It seems this little program is a huge success. ^_^ |<snip> |>But likely only because i hit a key... I looked around and saw |>other people with the same problem using the haveged daemon, which |>is kind of strange as it can generate thousands of bits of hard |>randomness in a second.> |<snip> | |Would you explain what you mean by this? |I've been using haveged for years, without issues, afaict. I use it too on the server, in addition to the entropy server. I have to use mailman, and that somehow consumes randomness like grazy even in idle state, which is a big pity, as it can drive down all the other programs which sometimes use randomness. (Python people and mathematics ..., me thinks.) My provider does not feed in random into the VM, so i would be lost without it. This is especially a pity with the current OpenSSL which turns to blocking mode at least when its used the first time, until unlocked. (This is what caused the openssl-users thread one or two weeks ago; i think they might change that again.) Now i do not know whether multi-process servers reinit their OpenSSL state machine for each and every connection, or take the prepared one with the fork(2)ed child. Yeah, i mean, i shortly looked at haveged code last year and it does some things which should cause randomness; but of course the quality cannot be that high, if i compare that to all the things that go on in a system, with application I/O, logging, file system, network, and other interrupts, whatever, which counts for 3 bits or what per second here, and about one on the server (iirc), whereas that little "math from nowhere" produces a thousand bits or more in the same time. --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)
participants (4)
-
Don Cupp
-
James Buren
-
Predrag Ivanović
-
Steffen Nurpmeso