mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jörg-Volker Peetz" <jvpeetz@web.de>
To: "Theodore Ts'o" <tytso@mit.edu>, "Jörn Engel" <joern@logfs.org>,
	"John Stultz" <john.stultz@linaro.org>,
	"Stephan Mueller" <smueller@chronox.de>,
	LKML <linux-kernel@vger.kernel.org>,
	dave.taht@bufferbloat.net,
	"Frederic Weisbecker" <fweisbec@gmail.com>,
	"Thomas Gleixner" <tglx@linutronix.de>
Subject: Re: [PATCH,RFC] random: make fast_mix() honor its name
Date: Mon, 23 Sep 2013 09:39:43 +0200	[thread overview]
Message-ID: <523FF03F.3040208@web.de> (raw)
In-Reply-To: <20130922212752.GB7321@thunk.org>

Thanks for your patience and elaborated answer.

Theodore Ts'o wrote, on 09/22/2013 23:27:
> On Sun, Sep 22, 2013 at 11:01:42PM +0200, Jörg-Volker Peetz wrote:
>> just out of interest I would like to ask why this mixing function has to be that
>> complicated. For example, even if the input is always 0 and the pool is seeded
>> with pool[0] = 1 (as in your test program) this algorithm generates some
>> (predictable) pseudo-random numbers in the pool. Is this necessary?
>>
>> To just mix in some random input filling the whole pool (seeded again with
>> pool[0] = 1) something as "simple" as
>>
>>           f->pool[0] = rol32(input[0], f->pool[2] & 31) ^ f->pool[1];
>>           f->pool[1] = rol32(input[1], f->pool[3] & 31) ^ f->pool[2];
>>           f->pool[2] = rol32(input[2], f->pool[0] & 31) ^ f->pool[3];
>>           f->pool[3] = rol32(input[3], f->pool[1] & 31) ^ f->pool[0];
>>
>> would suffice, although I didn't do any statistical tests.
> 
> The structure of the mixing functions in /dev/random has been well
> studied, and validatetd in a number of different academic papers.  So
> I prefer to stick with the basic architecture, even as it is scaled
> down for speed reasons and beause the pool is smaller.

I'm not arguing so much for speed but for simplicity and comprehensibility of
code. As far as I understand the task of fast_mix() is just to collect random
bits in a small buffer separated from the random pool?
Once in a while these collected bits are then mixed into the main random pool.
For that purpose, justifiably, a strong mixing function is used.

> One of the important things about the mixing function is that if the
> attacker knows the input values (of which the simplest example for
> analytic purposes is if the input values are all zero), we want there
> to be ample mixing across the pool.
> 
> If you look at your proposed mixing function, in the case where the
> input values are all zero, it devolves into:
> 
>            f->pool[0] = f->pool[1];
>            f->pool[1] = f->pool[2];
>            f->pool[2] = f->pool[3];
>            f->pool[3] = f->pool[0];
> 
> Yes, I know the input values will never be all zero, but in the case
> where the attacker knows what the input values are[1], but does not know
> the contents of the entropy pool, a very simplistic mixing function
> becomes relatively easy to analyze in the case where attacker knows
> the inputs and then outputs, and is trying to determine the internal
> state of the random driver.
> 
> Measuring the speed of the fast_mix function which I put together,
> it's already been speeded up compard to the original fast_mix function
> by a factor of six.  On my x86 laptop, I can run 10 million
> iterations in 0.14 seconds, so that translates to 14ns per fast_mix
> call.   (The original fast_mix function runs in 84 nanoseconds.)
> 
> So there is a cost-benefit tradeoff that we need to balance here.  If
> you have a system with 100k interrupts per second, performance is
> going to be poor no matter what, and it's not clear how common such
> systems really are.  Most modern hardware do have some kind of NAPI or
> other interrupt mitigation in place --- heck, even back in 1980's
> people had figured out how to improve the 8250 UART with the 16550A
> UART, which introdued a FIFO to decrease the interrupt load caused by
> serial ports, and things have only gotten better since then.
> 
> Out of curiosity, on your profiles, how many nanonseconds total is the
> total interrupt code path chewing up per interrupt?
> 
> Regards,
> 
> 						- Ted
> 
> [1] And on systems where we don't have get_cycles() or
> random_get_entropy(), it becomes much easier for the attacker to guess
> what at least half of the input values will be!
> 


  parent reply	other threads:[~2013-09-23  7:39 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-10 11:31 [PATCH] /dev/random: Insufficient of entropy on many architectures 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 [this message]
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
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=523FF03F.3040208@web.de \
    --to=jvpeetz@web.de \
    --cc=dave.taht@bufferbloat.net \
    --cc=fweisbec@gmail.com \
    --cc=joern@logfs.org \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=smueller@chronox.de \
    --cc=tglx@linutronix.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

Powered by JetHome