aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2013-12-17 21:16:39 -0500
committerTheodore Ts'o <tytso@mit.edu>2014-03-19 22:18:52 -0400
commit46884442fc5bb81a896f7245bd850fde9b435509 (patch)
treee0954b5941c39132dbb1914006d91672e9724b58 /drivers/char
parent2132a96f66b6b4d865113e7d4cb56d5f7c6e3cdf (diff)
random: use the architectural HWRNG for the SHA's IV in extract_buf()
To help assuage the fears of those who think the NSA can introduce a massive hack into the instruction decode and out of order execution engine in the CPU without hundreds of Intel engineers knowing about it (only one of which woud need to have the conscience and courage of Edward Snowden to spill the beans to the public), use the HWRNG to initialize the SHA starting value, instead of xor'ing it in afterwards. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/random.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 8cc7d6515676..d07575c99a5f 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1012,23 +1012,23 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
1012 __u8 extract[64]; 1012 __u8 extract[64];
1013 unsigned long flags; 1013 unsigned long flags;
1014 1014
1015 /* Generate a hash across the pool, 16 words (512 bits) at a time */
1016 sha_init(hash.w);
1017 spin_lock_irqsave(&r->lock, flags);
1018 for (i = 0; i < r->poolinfo->poolwords; i += 16)
1019 sha_transform(hash.w, (__u8 *)(r->pool + i), workspace);
1020
1021 /* 1015 /*
1022 * If we have an architectural hardware random number 1016 * If we have an architectural hardware random number
1023 * generator, mix that in, too. 1017 * generator, use it for SHA's initial vector
1024 */ 1018 */
1019 sha_init(hash.w);
1025 for (i = 0; i < LONGS(20); i++) { 1020 for (i = 0; i < LONGS(20); i++) {
1026 unsigned long v; 1021 unsigned long v;
1027 if (!arch_get_random_long(&v)) 1022 if (!arch_get_random_long(&v))
1028 break; 1023 break;
1029 hash.l[i] ^= v; 1024 hash.l[i] = v;
1030 } 1025 }
1031 1026
1027 /* Generate a hash across the pool, 16 words (512 bits) at a time */
1028 spin_lock_irqsave(&r->lock, flags);
1029 for (i = 0; i < r->poolinfo->poolwords; i += 16)
1030 sha_transform(hash.w, (__u8 *)(r->pool + i), workspace);
1031
1032 /* 1032 /*
1033 * We mix the hash back into the pool to prevent backtracking 1033 * We mix the hash back into the pool to prevent backtracking
1034 * attacks (where the attacker knows the state of the pool 1034 * attacks (where the attacker knows the state of the pool