diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-28 08:29:07 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-28 08:29:07 -0400 |
commit | 8e6d539e0fd0c2124a20a207da70f2af7a9ae52c (patch) | |
tree | 73016c1bdb5005125cdb5d60d48f73ab4300be64 /drivers/char | |
parent | 8237eb946a1a23c600fb289cf8dd3b399b10604e (diff) | |
parent | 49d859d78c5aeb998b6936fcb5f288f78d713489 (diff) |
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/char')
-rw-r--r-- | drivers/char/random.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index c35a785005b0..63e19ba56bbe 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, | |||
932 | */ | 932 | */ |
933 | void get_random_bytes(void *buf, int nbytes) | 933 | void get_random_bytes(void *buf, int nbytes) |
934 | { | 934 | { |
935 | extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0); | 935 | char *p = buf; |
936 | |||
937 | while (nbytes) { | ||
938 | unsigned long v; | ||
939 | int chunk = min(nbytes, (int)sizeof(unsigned long)); | ||
940 | |||
941 | if (!arch_get_random_long(&v)) | ||
942 | break; | ||
943 | |||
944 | memcpy(buf, &v, chunk); | ||
945 | p += chunk; | ||
946 | nbytes -= chunk; | ||
947 | } | ||
948 | |||
949 | extract_entropy(&nonblocking_pool, p, nbytes, 0, 0); | ||
936 | } | 950 | } |
937 | EXPORT_SYMBOL(get_random_bytes); | 951 | EXPORT_SYMBOL(get_random_bytes); |
938 | 952 | ||
@@ -1318,9 +1332,14 @@ late_initcall(random_int_secret_init); | |||
1318 | DEFINE_PER_CPU(__u32 [MD5_DIGEST_WORDS], get_random_int_hash); | 1332 | DEFINE_PER_CPU(__u32 [MD5_DIGEST_WORDS], get_random_int_hash); |
1319 | unsigned int get_random_int(void) | 1333 | unsigned int get_random_int(void) |
1320 | { | 1334 | { |
1321 | __u32 *hash = get_cpu_var(get_random_int_hash); | 1335 | __u32 *hash; |
1322 | unsigned int ret; | 1336 | unsigned int ret; |
1323 | 1337 | ||
1338 | if (arch_get_random_int(&ret)) | ||
1339 | return ret; | ||
1340 | |||
1341 | hash = get_cpu_var(get_random_int_hash); | ||
1342 | |||
1324 | hash[0] += current->pid + jiffies + get_cycles(); | 1343 | hash[0] += current->pid + jiffies + get_cycles(); |
1325 | md5_transform(hash, random_int_secret); | 1344 | md5_transform(hash, random_int_secret); |
1326 | ret = hash[0]; | 1345 | ret = hash[0]; |