aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/random.c
diff options
context:
space:
mode:
authorMatt Mackall <mpm@selenic.com>2008-04-29 04:03:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-29 11:06:25 -0400
commit993ba2114c554c1561a018e5c63a771ec8e1c469 (patch)
tree75df2f882845b12b698c305625f01dc6ef227147 /drivers/char/random.c
parent6d38b827400d7c02bce391f90d044e4c57d5bc1e (diff)
random: simplify add_ptr logic
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> Cc: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r--drivers/char/random.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index a754132336ba..ba0d70305384 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -454,7 +454,7 @@ static void __add_entropy_words(struct entropy_store *r, const __u32 *in,
454 static __u32 const twist_table[8] = { 454 static __u32 const twist_table[8] = {
455 0x00000000, 0x3b6e20c8, 0x76dc4190, 0x4db26158, 455 0x00000000, 0x3b6e20c8, 0x76dc4190, 0x4db26158,
456 0xedb88320, 0xd6d6a3e8, 0x9b64c2b0, 0xa00ae278 }; 456 0xedb88320, 0xd6d6a3e8, 0x9b64c2b0, 0xa00ae278 };
457 unsigned long i, add_ptr, tap1, tap2, tap3, tap4, tap5; 457 unsigned long i, j, tap1, tap2, tap3, tap4, tap5;
458 int input_rotate; 458 int input_rotate;
459 int wordmask = r->poolinfo->poolwords - 1; 459 int wordmask = r->poolinfo->poolwords - 1;
460 __u32 w; 460 __u32 w;
@@ -469,19 +469,21 @@ static void __add_entropy_words(struct entropy_store *r, const __u32 *in,
469 469
470 spin_lock_irqsave(&r->lock, flags); 470 spin_lock_irqsave(&r->lock, flags);
471 input_rotate = r->input_rotate; 471 input_rotate = r->input_rotate;
472 add_ptr = r->add_ptr; 472 i = r->add_ptr;
473 473
474 while (nwords--) { 474 while (nwords--) {
475 w = rol32(*in++, input_rotate & 31); 475 w = rol32(*in++, input_rotate & 31);
476 i = add_ptr = (add_ptr - 1) & wordmask; 476 i = (i - 1) & wordmask;
477 477
478 /* XOR in the various taps */ 478 /* XOR in the various taps */
479 w ^= r->pool[i];
479 w ^= r->pool[(i + tap1) & wordmask]; 480 w ^= r->pool[(i + tap1) & wordmask];
480 w ^= r->pool[(i + tap2) & wordmask]; 481 w ^= r->pool[(i + tap2) & wordmask];
481 w ^= r->pool[(i + tap3) & wordmask]; 482 w ^= r->pool[(i + tap3) & wordmask];
482 w ^= r->pool[(i + tap4) & wordmask]; 483 w ^= r->pool[(i + tap4) & wordmask];
483 w ^= r->pool[(i + tap5) & wordmask]; 484 w ^= r->pool[(i + tap5) & wordmask];
484 w ^= r->pool[i]; 485
486 /* Mix the result back in with a twist */
485 r->pool[i] = (w >> 3) ^ twist_table[w & 7]; 487 r->pool[i] = (w >> 3) ^ twist_table[w & 7];
486 488
487 /* 489 /*
@@ -494,14 +496,11 @@ static void __add_entropy_words(struct entropy_store *r, const __u32 *in,
494 } 496 }
495 497
496 r->input_rotate = input_rotate; 498 r->input_rotate = input_rotate;
497 r->add_ptr = add_ptr; 499 r->add_ptr = i;
498 500
499 if (out) { 501 if (out)
500 for (i = 0; i < 16; i++) { 502 for (j = 0; j < 16; j++)
501 out[i] = r->pool[add_ptr]; 503 out[j] = r->pool[(i - j) & wordmask];
502 add_ptr = (add_ptr - 1) & wordmask;
503 }
504 }
505 504
506 spin_unlock_irqrestore(&r->lock, flags); 505 spin_unlock_irqrestore(&r->lock, flags);
507} 506}