From: Matt Mackall <mpm@selenic.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 05 of 12] random: improve variable naming, clear extract buffer
Date: Thu, 17 Jan 2008 20:33:47 -0600 [thread overview]
Message-ID: <42aa9f950f97a57c860d.1200623627@cinder.waste.org> (raw)
In-Reply-To: <patchbomb.1200623622@cinder.waste.org>
- 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>
diff -r 3e0b0226df90 -r 42aa9f950f97 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
@@ -766,9 +766,9 @@
static void extract_buf(struct entropy_store *r, __u8 *out)
{
int i;
- __u32 data[16], buf[5 + SHA_WORKSPACE_WORDS];
+ __u32 extract[16], hash[5], workspace[SHA_WORKSPACE_WORDS];
- sha_init(buf);
+ sha_init(hash);
/*
* As we hash the pool, we mix intermediate values of
* the hash back into the pool. This eliminates
@@ -779,9 +779,9 @@
*/
for (i = 0; i < r->poolinfo->poolwords; i += 16) {
/* hash blocks of 16 words = 512 bits */
- sha_transform(buf, (__u8 *)(r->pool + i), buf + 5);
+ sha_transform(hash, (__u8 *)(r->pool + i), workspace);
/* feed back portion of the resulting hash */
- add_entropy_words(r, &buf[i % 5], 1);
+ add_entropy_words(r, &hash[i % 5], 1);
}
/*
@@ -789,19 +789,21 @@
* portion of the pool while mixing, and hash one
* final time.
*/
- __add_entropy_words(r, &buf[i % 5], 1, data);
- sha_transform(buf, (__u8 *)data, buf + 5);
+ __add_entropy_words(r, &hash[i % 5], 1, extract);
+ sha_transform(hash, (__u8 *)extract, workspace);
+ memset(extract, 0, sizeof(extract));
+ memset(workspace, 0, sizeof(workspace));
/*
* In case the hash function has some recognizable
* output pattern, we fold it in half.
*/
- buf[0] ^= buf[3];
- buf[1] ^= buf[4];
- buf[2] ^= rol32(buf[2], 16);
- memcpy(out, buf, EXTRACT_SIZE);
- memset(buf, 0, sizeof(buf));
+ hash[0] ^= hash[3];
+ hash[1] ^= hash[4];
+ hash[2] ^= rol32(hash[2], 16);
+ memcpy(out, hash, EXTRACT_SIZE);
+ memset(hash, 0, sizeof(hash));
}
static ssize_t extract_entropy(struct entropy_store *r, void *buf,
next prev parent reply other threads:[~2008-01-18 2:38 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 ` Matt Mackall [this message]
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 ` [PATCH 10 of 12] random: simplify add_ptr logic Matt Mackall
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=42aa9f950f97a57c860d.1200623627@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®