aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2011-07-31 16:54:50 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-15 15:04:11 -0400
commit6133313b3bcbd0473feac85c8a8d7ef704ff2279 (patch)
tree4bd67fe43b0e539eb14e4ace0890efd148accb61 /drivers
parent7b1cad628030b9bbdaaa4bb8ff73cabaab6e82c9 (diff)
random: Add support for architectural random hooks
commit 63d77173266c1791f1553e9e8ccea65dc87c4485 upstream. Add support for architecture-specific hooks into the kernel-directed random number generator interfaces. This patchset does not use the architecture random number generator interfaces for the userspace-directed interfaces (/dev/random and /dev/urandom), thus eliminating the need to distinguish between them based on a pool pointer. Changes in version 3: - Moved the hooks from extract_entropy() to get_random_bytes(). - Changes the hooks to inlines. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Matt Mackall <mpm@selenic.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: "Theodore Ts'o" <tytso@mit.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
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..154eeda26db 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 */
933void get_random_bytes(void *buf, int nbytes) 933void 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}
937EXPORT_SYMBOL(get_random_bytes); 951EXPORT_SYMBOL(get_random_bytes);
938 952
@@ -1318,9 +1332,14 @@ late_initcall(random_int_secret_init);
1318DEFINE_PER_CPU(__u32 [MD5_DIGEST_WORDS], get_random_int_hash); 1332DEFINE_PER_CPU(__u32 [MD5_DIGEST_WORDS], get_random_int_hash);
1319unsigned int get_random_int(void) 1333unsigned 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];