aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Mackall <mpm@selenic.com>2008-04-29 04:02:59 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-29 11:06:24 -0400
commitffd8d3fa5813430fe3926fe950fde23630f6b1a0 (patch)
treec5ea8d040ef61603a84b9d3b0a7ca944f24f9d7f
parent53c3f63e824764da23676e5c718755ff4aac9b63 (diff)
random: improve variable naming, clear extract buffer
- split the SHA variables apart into hash and workspace - rename data to extract - wipe extract and workspace after hashing 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>
-rw-r--r--drivers/char/random.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index a2329a11e139..d125a4b792d0 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -765,9 +765,9 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
765static void extract_buf(struct entropy_store *r, __u8 *out) 765static void extract_buf(struct entropy_store *r, __u8 *out)
766{ 766{
767 int i; 767 int i;
768 __u32 data[16], buf[5 + SHA_WORKSPACE_WORDS]; 768 __u32 extract[16], hash[5], workspace[SHA_WORKSPACE_WORDS];
769 769
770 sha_init(buf); 770 sha_init(hash);
771 /* 771 /*
772 * As we hash the pool, we mix intermediate values of 772 * As we hash the pool, we mix intermediate values of
773 * the hash back into the pool. This eliminates 773 * the hash back into the pool. This eliminates
@@ -778,9 +778,9 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
778 */ 778 */
779 for (i = 0; i < r->poolinfo->poolwords; i += 16) { 779 for (i = 0; i < r->poolinfo->poolwords; i += 16) {
780 /* hash blocks of 16 words = 512 bits */ 780 /* hash blocks of 16 words = 512 bits */
781 sha_transform(buf, (__u8 *)(r->pool + i), buf + 5); 781 sha_transform(hash, (__u8 *)(r->pool + i), workspace);
782 /* feed back portion of the resulting hash */ 782 /* feed back portion of the resulting hash */
783 add_entropy_words(r, &buf[i % 5], 1); 783 add_entropy_words(r, &hash[i % 5], 1);
784 } 784 }
785 785
786 /* 786 /*
@@ -788,19 +788,21 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
788 * portion of the pool while mixing, and hash one 788 * portion of the pool while mixing, and hash one
789 * final time. 789 * final time.
790 */ 790 */
791 __add_entropy_words(r, &buf[i % 5], 1, data); 791 __add_entropy_words(r, &hash[i % 5], 1, extract);
792 sha_transform(buf, (__u8 *)data, buf + 5); 792 sha_transform(hash, (__u8 *)extract, workspace);
793 memset(extract, 0, sizeof(extract));
794 memset(workspace, 0, sizeof(workspace));
793 795
794 /* 796 /*
795 * In case the hash function has some recognizable 797 * In case the hash function has some recognizable
796 * output pattern, we fold it in half. 798 * output pattern, we fold it in half.
797 */ 799 */
798 800
799 buf[0] ^= buf[3]; 801 hash[0] ^= hash[3];
800 buf[1] ^= buf[4]; 802 hash[1] ^= hash[4];
801 buf[2] ^= rol32(buf[2], 16); 803 hash[2] ^= rol32(hash[2], 16);
802 memcpy(out, buf, EXTRACT_SIZE); 804 memcpy(out, hash, EXTRACT_SIZE);
803 memset(buf, 0, sizeof(buf)); 805 memset(hash, 0, sizeof(hash));
804} 806}
805 807
806static ssize_t extract_entropy(struct entropy_store *r, void *buf, 808static ssize_t extract_entropy(struct entropy_store *r, void *buf,