From: Greg Price <price@MIT.EDU>
To: "Theodore Ts'o" <tytso@MIT.EDU>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 07/14] random: exploit any extra entropy too when reseeding
Date: Sat, 14 Dec 2013 21:01:21 -0500 [thread overview]
Message-ID: <20131215020121.GG27191@athena.dialup.mit.edu> (raw)
In-Reply-To: <cover.1387067223.git.price@mit.edu>
When extracting from the input pool to feed one of the output
pools, extracting more bytes can't hurt the reseed, and it can
help if there happens to be more entropy than we estimated. We
deliberately try to be conservative in our estimates -- for
example, mixing in the cycle counter on each event but estimating
based on the low-resolution clock -- so this situation is likely.
For example, the authors of http://eprint.iacr.org/2012/251.pdf
found in a multi-week run on a desktop that the actual entropy
from add_input_randomness was much higher than our estimates,
at 9.69 bits min-entropy per event from the cycle counters alone
vs. 1.85 bits estimated.
The only reason to hold back is that we have to debit the input
pool's entropy estimate for every byte we extract, which may delay
us the next time we want to extract from the input pool. But if
we're already leaving the pool practically empty, this isn't much
of a cost. So go ahead and suck up two full extractions, 160 bits.
If we have even more than that and didn't know it, this should
still be a good solid seed.
We just have to make sure not to give ourselves credit for more
entropy than our sober estimates allow. The credit_bits output
parameter takes care of that.
Signed-off-by: Greg Price <price@mit.edu>
---
drivers/char/random.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index c11281551..c2428ecb2 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1001,6 +1001,13 @@ retry:
ibytes = 0;
if (credit_bits != NULL)
*credit_bits = ibytes * 8;
+ if (dest != NULL && ibytes && ibytes == have_bytes) {
+ /* When a reseed drains the pool, we might as well
+ * suck up any underestimated entropy as well as what
+ * we estimate is there. */
+ WARN_ON(credit_bits == NULL);
+ ibytes = max_t(size_t, ibytes, 2*EXTRACT_SIZE);
+ }
entropy_count = max_t(int, 0,
entropy_count - (ibytes << (ENTROPY_SHIFT + 3)));
if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
--
1.8.3.2
next prev parent reply other threads:[~2013-12-15 2:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-15 2:00 [PATCH 00/14] random: rework reseeding Greg Price
2013-12-15 2:00 ` [PATCH 01/14] random: fix signedness bug Greg Price
2013-12-15 2:00 ` [PATCH 02/14] random: fix a (harmless) overflow Greg Price
2013-12-15 2:01 ` [PATCH 03/14] random: reserve for /dev/random only once /dev/urandom seeded Greg Price
2013-12-15 2:01 ` [PATCH 04/14] random: accept small seeds early on Greg Price
2013-12-15 2:01 ` [PATCH 05/14] random: move transfer accounting into account() helper Greg Price
2013-12-15 2:01 ` [PATCH 06/14] random: separate quantity of bytes extracted and entropy to credit Greg Price
2013-12-15 2:01 ` Greg Price [this message]
2013-12-15 2:01 ` [PATCH 08/14] random: rate-limit reseeding only after properly seeded Greg Price
2013-12-15 2:01 ` [PATCH 09/14] random: reserve entropy for nonblocking pool early on Greg Price
2013-12-15 2:01 ` [PATCH 10/14] random: direct all routine input via input pool Greg Price
2013-12-15 2:01 ` [PATCH 11/14] random: separate entropy since auto-push from entropy_total Greg Price
2013-12-15 2:01 ` [PATCH 12/14] random: separate minimum reseed size from minimum /dev/random read Greg Price
2013-12-15 2:01 ` [PATCH 13/14] random: count only catastrophic reseeds for initialization Greg Price
2013-12-15 2:02 ` [PATCH 14/14] random: target giant reseeds, to be conservative Greg Price
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=20131215020121.GG27191@athena.dialup.mit.edu \
--to=price@mit.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@MIT.EDU \
/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
all inboxes | Powered by JetHome®