From: Matt Mackall <mpm@selenic.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 10 of 12] random: simplify add_ptr logic
Date: Thu, 17 Jan 2008 20:33:52 -0600 [thread overview]
Message-ID: <8f286e22c84dfb98a8b9.1200623632@cinder.waste.org> (raw)
In-Reply-To: <patchbomb.1200623622@cinder.waste.org>
The add_ptr variable wasn't used in a sensible way, use only i instead.
i got reused later for a different purpose, use j instead.
While we're here, put tap0 first in the tap list and add a comment.
Signed-off-by: Matt Mackall <mpm@selenic.com>
diff -r bc31fa097d34 -r 8f286e22c84d drivers/char/random.c
--- a/drivers/char/random.c Thu Jan 17 20:25:23 2008 -0600
+++ b/drivers/char/random.c Thu Jan 17 20:25:23 2008 -0600
@@ -454,7 +454,7 @@
static __u32 const twist_table[8] = {
0x00000000, 0x3b6e20c8, 0x76dc4190, 0x4db26158,
0xedb88320, 0xd6d6a3e8, 0x9b64c2b0, 0xa00ae278 };
- unsigned long i, add_ptr, tap1, tap2, tap3, tap4, tap5;
+ unsigned long i, j, tap1, tap2, tap3, tap4, tap5;
int input_rotate;
int wordmask = r->poolinfo->poolwords - 1;
__u32 w;
@@ -469,19 +469,21 @@
spin_lock_irqsave(&r->lock, flags);
input_rotate = r->input_rotate;
- add_ptr = r->add_ptr;
+ i = r->add_ptr;
while (nwords--) {
w = rol32(*in++, input_rotate & 31);
- i = add_ptr = (add_ptr - 1) & wordmask;
+ i = (i - 1) & wordmask;
/* XOR in the various taps */
+ w ^= r->pool[i];
w ^= r->pool[(i + tap1) & wordmask];
w ^= r->pool[(i + tap2) & wordmask];
w ^= r->pool[(i + tap3) & wordmask];
w ^= r->pool[(i + tap4) & wordmask];
w ^= r->pool[(i + tap5) & wordmask];
- w ^= r->pool[i];
+
+ /* Mix the result back in with a twist */
r->pool[i] = (w >> 3) ^ twist_table[w & 7];
/*
@@ -494,14 +496,11 @@
}
r->input_rotate = input_rotate;
- r->add_ptr = add_ptr;
+ r->add_ptr = i;
- if (out) {
- for (i = 0; i < 16; i++) {
- out[i] = r->pool[add_ptr];
- add_ptr = (add_ptr - 1) & wordmask;
- }
- }
+ if (out)
+ for (j = 0; j < 16; j++)
+ out[j] = r->pool[(i - j) & wordmask];
spin_unlock_irqrestore(&r->lock, flags);
}
next prev parent reply other threads:[~2008-01-18 2:40 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-18 2:33 [PATCH 00 of 12] random cleanups for 2.6.25 Matt Mackall
2008-01-18 2:33 ` [PATCH 01 of 12] random: clean up checkpatch complaints Matt Mackall
2008-01-18 2:33 ` [PATCH 02 of 12] random: consolidate wakeup logic Matt Mackall
2008-01-18 2:33 ` [PATCH 03 of 12] random: use unlocked_ioctl Matt Mackall
2008-01-18 2:33 ` [PATCH 04 of 12] random: reuse rand_initialize Matt Mackall
2008-01-18 2:33 ` [PATCH 05 of 12] random: improve variable naming, clear extract buffer Matt Mackall
2008-01-18 2:33 ` [PATCH 06 of 12] random: make backtracking attacks harder Matt Mackall
2008-01-18 2:33 ` [PATCH 07 of 12] random: remove cacheline alignment for locks Matt Mackall
2008-01-18 2:33 ` [PATCH 08 of 12] random: eliminate redundant new_rotate variable Matt Mackall
2008-01-18 2:33 ` [PATCH 09 of 12] random: remove some prefetch logic Matt Mackall
2008-01-18 2:33 ` Matt Mackall [this message]
2008-01-18 2:33 ` [PATCH 11 of 12] random: make mixing interface byte-oriented Matt Mackall
2008-01-18 2:33 ` [PATCH 12 of 12] random: simplify and rename credit_entropy_store 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=8f286e22c84dfb98a8b9.1200623632@cinder.waste.org \
--to=mpm@selenic.com \
--cc=akpm@linux-foundation.org \
--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
all inboxes | Powered by JetHome®