linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Theodore Tso <tytso@mit.edu>
To: Matt Mackall <mpm@selenic.com>
Cc: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/6] random: use xor for mixing
Date: Sat, 8 Dec 2007 19:01:04 -0500	[thread overview]
Message-ID: <20071209000103.GS17037@thunk.org> (raw)
In-Reply-To: <3.753618428@selenic.com>

On Sat, Dec 08, 2007 at 05:20:16PM -0600, Matt Mackall wrote:
> random: use xor for mixing
> 
> With direct assignment, we can determine the twist table element used
> for mixing (the high 3 bits of the table are unique) and reverse a
> single step of mixing. Instead, use xor, which should also help
> preserve entropy in a given pool slot.
> 
> Signed-off-by: Matt Mackall <mpm@selenic.com>
> 
> diff -r bc336762cfdb drivers/char/random.c
> --- a/drivers/char/random.c	Wed Dec 05 17:20:02 2007 -0600
> +++ b/drivers/char/random.c	Sat Dec 08 13:27:34 2007 -0600
> @@ -496,7 +496,7 @@ static void __add_entropy_words(struct e
>  		w ^= r->pool[(i + tap4) & wordmask];
>  		w ^= r->pool[(i + tap5) & wordmask];
>  		w ^= r->pool[i];
> -		r->pool[i] = (w >> 3) ^ twist_table[w & 7];
> +		r->pool[i] ^= (w >> 3) ^ twist_table[w & 7];
>  	}

In the original design of add_entropy_words(), in order to provably
not lose any entropy, you want add_entropy_words() to be reversible if
you mix in all zero's.  So the fact that you can determine the twist
table element used from looking at the high bits was deliberate.  The
mixing done in add_entropy_words() is *not* intended to be
cryptographic, but merely to smear the bits around as they are added
and then to permute the pool so that when you use SHA in the output
stage, enough bits are changing that even if there are weaknesses
discovered in the crypto hash algorithm, it won't help the attacker.

The internals of the pool are never exposed, so an attacker should
never gain direct access to the entropy pool; hence worry about
whether someone can "reverse" the mixing isn't particuarly a worry;
indeed, in order to make sure we preserve entropy, the whole *point*
of the mixing algorithm is that it is reversible.

(note: credit for this design should go to Colin Plumb, who worked
with me on this aspect of the design.  Colin was responsible for the
original random number generator in PGP....)

					- Ted

       reply	other threads:[~2007-12-09  0:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2.753618428@selenic.com>
     [not found] ` <3.753618428@selenic.com>
2007-12-09  0:01   ` Theodore Tso [this message]
2007-12-09  0:40     ` [PATCH 2/6] random: use xor for mixing Matt Mackall
2007-12-09  2:08       ` Theodore Tso
2007-12-09 13:33         ` Alan Cox
2007-12-19 21:09         ` Bill Davidsen
     [not found] ` <4.753618428@selenic.com>
2007-12-09  0:35   ` [PATCH 3/6] random: do extraction before mixing Theodore Tso
2007-12-09  7:12     ` Matt Mackall
     [not found] ` <5.753618428@selenic.com>
2007-12-09  1:45   ` [PATCH 4/6] random: make backtracking attacks harder Theodore Tso
2007-12-09  5:43     ` Matt Mackall
2007-12-09 13:33       ` Theodore Tso
2007-12-09 17:05         ` Matt Mackall
2007-12-10 13:37           ` Theodore Tso
     [not found] ` <6.753618428@selenic.com>
2007-12-09  1:48   ` [PATCH 5/6] random: step more rapidly through the pool when adding and extracting Theodore Tso
2007-12-09  4:00     ` Andrew Morton
2007-12-09  4:22       ` Matt Mackall
2007-12-09 12:55         ` Theodore Tso
2007-12-09 17:08           ` Matt Mackall
     [not found] ` <7.753618428@selenic.com>
2007-12-09  1:51   ` [PATCH 6/6] random: improve variable naming, clear extract buffer Theodore Tso
2007-12-09  5:08     ` Matt Mackall

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=20071209000103.GS17037@thunk.org \
    --to=tytso@mit.edu \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpm@selenic.com \
    /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;
as well as URLs for NNTP newsgroup(s).