diff options
| author | H. Peter Anvin <hpa@zytor.com> | 2011-07-31 16:54:50 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-15 15:04:11 -0400 |
| commit | 6133313b3bcbd0473feac85c8a8d7ef704ff2279 (patch) | |
| tree | 4bd67fe43b0e539eb14e4ace0890efd148accb61 /drivers | |
| parent | 7b1cad628030b9bbdaaa4bb8ff73cabaab6e82c9 (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.c | 23 |
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 | */ |
| 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]; |
