From: "George Spelvin" <linux@horizon.com>
To: linux@horizon.com, smueller@chronox.de
Cc: herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org, sandyinchina@gmail.com,
tytso@mit.edu
Subject: Re: random(4) changes
Date: 26 Apr 2016 20:23:46 -0400 [thread overview]
Message-ID: <20160427002346.12354.qmail@ns.horizon.com> (raw)
In-Reply-To: <25204908.NQ7XpImiHx@positron.chronox.de>
> And considering that I only want to have 0.9 bits of entropy, why
> should I not collapse it? The XOR operation does not destroy the existing
> entropy, it only caps it to at most one bit of information theoretical
> entropy.
No. Absolutely, demonstrably false.
The XOR operation certainly *does* destroy entropy.
If you have 0.9 bits of entropy to start, you will have less
after the XOR. It does NOT return min(input, 1) bits.
In rare cases, the XOR won't destroy entropy, but that's statistically
unlikely.
Here's a proof:
If there are only two possible inputs (timings), and those inputs have
opposite parities, then the XOR will cause no collisions and no entropy
is destroyed.
If you have at least three possibilities, hashing down to one bit (by
XOR or any other algorithm) must cause a collision, and that collision
will lose entropy.
Just as an example, let me use a 3-option distribution with roughly 0.5
bit of Shannon entropy: probabilities 90%, 9% and 1%. Then list all
the possible collisions, and the Shannon and min-entropy in each case:
% Shannon Min
90/9/1 0.5159 0.1520
90/10 0.4690 (91%) 0.1520 (100%)
91/9 0.4365 (85%) 0.1361 (90%)
99/1 0.0808 (16%) 0.0145 (10%)
100 0 0
If you reduce the number of cases to 2, you lose Shannon entropy, always.
Min-entropy is preserved 1/4 of the time if you get lucky and none of the
less-likely options collide with the most-likely.
If the 4 possible collision cases are equally likely (which is the
case if the hashing to one bit is a random function), then you expect
to retain half of the input entropy.
If there are more than three possible inputs, the situation gets worse,
and the likelihood of no loss of min-entropy falls.
In a case of particular interest to an RNG, consider the min-entropy when
there are a large number of possible input measurements. The min-entropy is
simply -log2(p(max)), where p(max) is the probability of the most likely
outcome. If p(max) > 50%, then the input min-entropy is less than 1 bit.
In this case we can assume that, when collapsing to a single bit, the
less likely cases will be distributed uniformly between colliding and
not colliding with the most likely alternative.
Thus, the probability of the most likely increases from p to
p + (1-p)/2 = (1+p)/2, and the min-entropy correspondingly
decreases from -log2(p) to -log2((1+p)/2).
The ratio of output to input min-entropy varies from 50% near 0 bits to
45.7% at 0.5 bits to 41.5% at 1 bit input.
In this case, which I think is a plausible case for /dev/random
measurements, you're throwing away half the entropy.
Beyond 1 bit of input entropy, the ratio gets worse as the output
asymptotically approaches 1 bit of entropy. Specifically, in order to
get 0.9 bits of min-entropy in the output (p(max) = 0.5358), you need
3.8 bits (p(max) = 0.07177 = 1/14) in the input!
I'm sorry, but collapsing individual samples to 1 bit is a Bad Design,
full stop. It's not the algorithm used to do the reduction, it's the
reduction itself.
next prev parent reply other threads:[~2016-04-27 0:23 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <5279345.Lo7T948V4W@positron.chronox.de>
2016-04-26 20:43 ` George Spelvin
2016-04-26 21:01 ` Stephan Mueller
2016-04-27 0:23 ` George Spelvin [this message]
2016-04-27 18:03 ` George Spelvin
2016-04-28 20:15 ` Stephan Mueller
2016-04-29 7:29 ` George Spelvin
2016-04-29 8:02 ` Stephan Mueller
2016-04-29 9:34 ` George Spelvin
2016-04-29 9:53 ` Stephan Mueller
2016-04-29 11:04 ` George Spelvin
2016-04-29 11:18 ` Stephan Mueller
2016-04-29 18:02 ` George Spelvin
2016-04-29 18:41 ` Stephan Mueller
2016-04-29 20:08 ` George Spelvin
2016-04-29 21:54 ` Stephan Mueller
2016-04-29 22:32 ` George Spelvin
2016-04-29 0:47 ` George Spelvin
2016-04-22 22:27 Sandy Harris
2016-04-23 7:52 ` Stephan Mueller
2016-04-24 2:03 ` Theodore Ts'o
2016-04-24 8:03 ` Stephan Mueller
2016-04-26 3:07 ` Theodore Ts'o
2016-04-26 11:04 ` Herbert Xu
2016-04-26 20:47 ` Andi Kleen
2016-04-27 4:23 ` Herbert Xu
2016-04-26 18:24 ` Stephan Mueller
2016-04-26 18:44 ` Pavel Machek
2016-04-26 18:55 ` Stephan Mueller
2016-04-26 19:41 ` Pavel Machek
2016-04-25 16:06 ` Andi Kleen
2016-04-25 17:25 ` Stephan Mueller
2016-04-25 17:38 ` Andi Kleen
2016-04-25 17:56 ` Stephan Mueller
2016-04-25 19:35 ` Andi Kleen
2016-04-26 12:01 ` Stephan Mueller
2016-04-27 17:47 ` Stephan Mueller
2016-04-26 1:00 ` Theodore Ts'o
2016-04-26 12:42 ` Sandy Harris
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=20160427002346.12354.qmail@ns.horizon.com \
--to=linux@horizon.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sandyinchina@gmail.com \
--cc=smueller@chronox.de \
--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®