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>
This commit is contained in:
parent
53c3f63e82
commit
ffd8d3fa58
|
@ -765,9 +765,9 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
|
||||||
static void extract_buf(struct entropy_store *r, __u8 *out)
|
static void extract_buf(struct entropy_store *r, __u8 *out)
|
||||||
{
|
{
|
||||||
int i;
|
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
|
* As we hash the pool, we mix intermediate values of
|
||||||
* the hash back into the pool. This eliminates
|
* the hash back into the pool. This eliminates
|
||||||
|
@ -778,9 +778,9 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < r->poolinfo->poolwords; i += 16) {
|
for (i = 0; i < r->poolinfo->poolwords; i += 16) {
|
||||||
/* hash blocks of 16 words = 512 bits */
|
/* 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 */
|
/* feed back portion of the resulting hash */
|
||||||
add_entropy_words(r, &buf[i % 5], 1);
|
add_entropy_words(r, &hash[i % 5], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -788,19 +788,21 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
|
||||||
* portion of the pool while mixing, and hash one
|
* portion of the pool while mixing, and hash one
|
||||||
* final time.
|
* final time.
|
||||||
*/
|
*/
|
||||||
__add_entropy_words(r, &buf[i % 5], 1, data);
|
__add_entropy_words(r, &hash[i % 5], 1, extract);
|
||||||
sha_transform(buf, (__u8 *)data, buf + 5);
|
sha_transform(hash, (__u8 *)extract, workspace);
|
||||||
|
memset(extract, 0, sizeof(extract));
|
||||||
|
memset(workspace, 0, sizeof(workspace));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In case the hash function has some recognizable
|
* In case the hash function has some recognizable
|
||||||
* output pattern, we fold it in half.
|
* output pattern, we fold it in half.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
buf[0] ^= buf[3];
|
hash[0] ^= hash[3];
|
||||||
buf[1] ^= buf[4];
|
hash[1] ^= hash[4];
|
||||||
buf[2] ^= rol32(buf[2], 16);
|
hash[2] ^= rol32(hash[2], 16);
|
||||||
memcpy(out, buf, EXTRACT_SIZE);
|
memcpy(out, hash, EXTRACT_SIZE);
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(hash, 0, sizeof(hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t extract_entropy(struct entropy_store *r, void *buf,
|
static ssize_t extract_entropy(struct entropy_store *r, void *buf,
|
||||||
|
|
Loading…
Reference in New Issue