summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-10-28 05:29:07 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-28 05:29:07 -0700
commit8e6d539e0fd0c2124a20a207da70f2af7a9ae52c (patch)
tree73016c1bdb5005125cdb5d60d48f73ab4300be64 /drivers
parent8237eb946a1a23c600fb289cf8dd3b399b10604e (diff)
parent49d859d78c5aeb998b6936fcb5f288f78d713489 (diff)
downloadlinux-3.10-8e6d539e0fd0c2124a20a207da70f2af7a9ae52c.tar.gz
linux-3.10-8e6d539e0fd0c2124a20a207da70f2af7a9ae52c.tar.bz2
linux-3.10-8e6d539e0fd0c2124a20a207da70f2af7a9ae52c.zip
Merge branch 'x86-rdrand-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
* 'x86-rdrand-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86, random: Verify RDRAND functionality and allow it to be disabled x86, random: Architectural inlines to get random integers with RDRAND random: Add support for architectural random hooks Fix up trivial conflicts in drivers/char/random.c: the architectural random hooks touched "get_random_int()" that was simplified to use MD5 and not do the keyptr thing any more (see commit 6e5714eaf77d: "net: Compute protocol sequence numbers and fragment IDs using MD5").
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/random.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index c35a785005b..63e19ba56bb 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -932,7 +932,21 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
*/
void get_random_bytes(void *buf, int nbytes)
{
- extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0);
+ char *p = buf;
+
+ while (nbytes) {
+ unsigned long v;
+ int chunk = min(nbytes, (int)sizeof(unsigned long));
+
+ if (!arch_get_random_long(&v))
+ break;
+
+ memcpy(buf, &v, chunk);
+ p += chunk;
+ nbytes -= chunk;
+ }
+
+ extract_entropy(&nonblocking_pool, p, nbytes, 0, 0);
}
EXPORT_SYMBOL(get_random_bytes);
@@ -1318,9 +1332,14 @@ late_initcall(random_int_secret_init);
DEFINE_PER_CPU(__u32 [MD5_DIGEST_WORDS], get_random_int_hash);
unsigned int get_random_int(void)
{
- __u32 *hash = get_cpu_var(get_random_int_hash);
+ __u32 *hash;
unsigned int ret;
+ if (arch_get_random_int(&ret))
+ return ret;
+
+ hash = get_cpu_var(get_random_int_hash);
+
hash[0] += current->pid + jiffies + get_cycles();
md5_transform(hash, random_int_secret);
ret = hash[0];