mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thorsten Glaser <tg@mirbsd.de>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] /dev/random: Insufficient of entropy on many architectures
Date: Fri, 13 Sep 2013 11:54:40 +0000 (UTC)	[thread overview]
Message-ID: <loom.20130913T134347-937@post.gmane.org> (raw)
In-Reply-To: <1974157.PE35U8AyTG@tauon>

Stephan Mueller <smueller <at> chronox.de> writes:

> And here the RNG theory breaks: a whitening function (crypto function) 
> like the used SHA1 does not add entropy. Thus, the SHA1 just spreads out 
> the entropy evenly over the output buffer. As entropy can be considered 

That’s why you also use a (faster, less powerful) mixing function
on input.

I was wondering: why not use Jenkins’ one-at-a-time hash there?
I’ve worked with it a bit, and it has good avalanche behaviour;
I didn’t measure any cycles though.

Basically, h be an uint32_t register (usually loaded from a
memory location and stored to one afterwards), then you do:

    (h) += (uint8_t)(b);
#ifdef with_mirabilos_changes
    ++(h);
#endif
    (h) += (h) << 10;
    (h) ^= (h) >> 6;

I’m adding 1 after the first step (adding the byte) in order
to make even NUL bytes make up a difference.

I’m toying with code that has 32 such uint32_t values, making
for a total of 128 Bytes of state, and when asked to add some
memory content into that pool, just distribute the bytes over
the values array, incrementing a counter.

(One could probably do something with cmpxchg to make that
lockless, but I’m not doing any parallel programming myself.)

Then, every once in a while, you’d run the finish function
on every value, which is:

#ifdef with_mirabilos_changes
    (h) += (h) << 10;
    (h) ^= (h) >> 6;
#endif
    (h) += (h) << 3;
    (h) ^= (h) >> 11;
    (h) += (h) << 15;

My change here is because Jenkins’ OAAT has good avalanche
except for the last input byte, so I just fake adding NUL
(which doesn’t get avalanched so well, but doesn’t matter)
to get the last actual data byte avalanched.

Then I write those finialised hash values back to the
128-Byte-buffer then I add that into the main pool using
a cryptographic (hash, or stream cipher rekey) function.
(In my case, arc4random, if someone wonders.)

> >It doesn't matter if you collect predictable data - it neither helps
> 
> Oh yes, it hurts, if you update the entropy estimator on those 
> predictable bits. Because then you get a deterministic RNG like 

I’ve seen Theodore apply exponential backoff to any estimation,
which is probably a good thing. But yes, you probably will want
to guess the entropy of the bytes added and not count things
where you’re not too sure of. (In the interrupt case, we have
jiffies, cycles and num, so we’d probably best estimate how
often interrupts are called, base a number of “timing” bits
on that, and account for num; this may very well be less than
8 bit “credited” for a long and two u_int added to the pool,
but as long as you get that right and don’t blindly credit
a byte as 8 bit, you’re safe. To quote the author of RANDOM.SYS
for DOS: “Every bit counts.” It adds uncertainty to the pool,
at least by stirring around the already-existing entropy without
adding any new (creditable) entropy.)

bye,
//mirabilos


  reply	other threads:[~2013-09-13 11:55 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-10 11:31 Stephan Mueller
2013-09-10 11:46 ` Geert Uytterhoeven
2013-09-10 15:04 ` Theodore Ts'o
2013-09-10 16:54   ` Stephan Mueller
2013-09-10 18:25     ` Theodore Ts'o
2013-09-10 19:15       ` Stephan Mueller
2013-10-10  6:50       ` Pavel Machek
2013-10-14 21:13         ` Theodore Ts'o
2013-09-10 20:48   ` Geert Uytterhoeven
2013-09-10 21:14     ` Theodore Ts'o
2013-09-11  6:49       ` Stephan Mueller
2013-09-12 11:59         ` Geert Uytterhoeven
2013-09-12 12:08           ` Stephan Mueller
2013-09-12 12:15             ` Geert Uytterhoeven
2013-09-12 12:35               ` Stephan Mueller
2013-09-12 12:47                 ` Geert Uytterhoeven
2013-09-12 12:57                   ` Stephan Mueller
2013-09-12 21:18               ` Jörn Engel
2013-09-13 11:33             ` Thorsten Glaser
2013-09-12 14:25           ` Theodore Ts'o
2013-09-10 19:38 ` John Stultz
2013-09-10 19:44   ` John Stultz
2013-09-10 19:47   ` Stephan Mueller
2013-09-10 20:35     ` John Stultz
2013-09-10 20:38   ` Theodore Ts'o
2013-09-10 20:46     ` John Stultz
2013-09-10 21:10       ` Theodore Ts'o
2013-09-10 22:08         ` John Stultz
2013-09-10 22:33           ` Theodore Ts'o
2013-09-11  0:31             ` John Stultz
2013-09-11  0:50               ` Theodore Ts'o
2013-09-11  1:14                 ` John Stultz
2013-09-12 20:46                 ` H. Peter Anvin
2013-09-12 21:07                 ` Jörn Engel
2013-09-12 23:31                   ` Theodore Ts'o
2013-09-12 23:35                     ` Jörn Engel
2013-09-13  0:00                       ` Jörn Engel
2013-09-16 15:40                     ` [PATCH,RFC] random: make fast_mix() honor its name Jörn Engel
2013-09-21 21:25                       ` Theodore Ts'o
2013-09-21 21:41                         ` Theodore Ts'o
2013-09-22  3:05                           ` Theodore Ts'o
2013-09-22 21:01                             ` Jörg-Volker Peetz
2013-09-22 21:27                               ` Theodore Ts'o
2013-09-22 20:53                                 ` Jörn Engel
2013-09-22 23:36                                   ` Theodore Ts'o
2013-09-23  0:16                                     ` Jörn Engel
2013-09-23  2:43                                       ` Theodore Ts'o
2013-09-23 15:02                                         ` Jörn Engel
2013-09-23  7:39                                 ` Jörg-Volker Peetz
2013-09-22 20:31                           ` Jörn Engel
2013-09-22 20:14                         ` Jörn Engel
2013-09-12 21:31           ` [PATCH] /dev/random: Insufficient of entropy on many architectures Jörn Engel
2013-09-13  5:36             ` Stephan Mueller
2013-09-13 11:54               ` Thorsten Glaser [this message]
2013-09-13 19:29                 ` Theodore Ts'o
2013-09-13 15:26               ` Jörn Engel
2013-09-13 18:59               ` Theodore Ts'o
2013-09-15 11:12                 ` Stephan Mueller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20130913T134347-937@post.gmane.org \
    --to=tg@mirbsd.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome