random: fix error in entropy extraction

Fix cast error in entropy extraction.
Add comments explaining the magic 16.
Remove extra confusing loop variable.

Signed-off-by: Matt Mackall <mpm@selenic.com>
Acked-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Matt Mackall and committed by Linus Torvalds 602b6aee f717221b

+7 -5
+7 -5
drivers/char/random.c
··· 760 761 static void extract_buf(struct entropy_store *r, __u8 *out) 762 { 763 - int i, x; 764 __u32 data[16], buf[5 + SHA_WORKSPACE_WORDS]; 765 766 sha_init(buf); ··· 772 * attempts to find previous ouputs), unless the hash 773 * function can be inverted. 774 */ 775 - for (i = 0, x = 0; i < r->poolinfo->poolwords; i += 16, x+=2) { 776 - sha_transform(buf, (__u8 *)r->pool+i, buf + 5); 777 - add_entropy_words(r, &buf[x % 5], 1); 778 } 779 780 /* ··· 784 * portion of the pool while mixing, and hash one 785 * final time. 786 */ 787 - __add_entropy_words(r, &buf[x % 5], 1, data); 788 sha_transform(buf, (__u8 *)data, buf + 5); 789 790 /*
··· 760 761 static void extract_buf(struct entropy_store *r, __u8 *out) 762 { 763 + int i; 764 __u32 data[16], buf[5 + SHA_WORKSPACE_WORDS]; 765 766 sha_init(buf); ··· 772 * attempts to find previous ouputs), unless the hash 773 * function can be inverted. 774 */ 775 + for (i = 0; i < r->poolinfo->poolwords; i += 16) { 776 + /* hash blocks of 16 words = 512 bits */ 777 + sha_transform(buf, (__u8 *)(r->pool + i), buf + 5); 778 + /* feed back portion of the resulting hash */ 779 + add_entropy_words(r, &buf[i % 5], 1); 780 } 781 782 /* ··· 782 * portion of the pool while mixing, and hash one 783 * final time. 784 */ 785 + __add_entropy_words(r, &buf[i % 5], 1, data); 786 sha_transform(buf, (__u8 *)data, buf + 5); 787 788 /*