aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2011-07-31 16:54:50 -0400
committerH. Peter Anvin <hpa@zytor.com>2011-07-31 16:54:50 -0400
commit63d77173266c1791f1553e9e8ccea65dc87c4485 (patch)
tree81c69a2f30a9bd8302d690000215b474886d0152
parent02f8c6aee8df3cdc935e9bdd4f2d020306035dbe (diff)
random: Add support for architectural random hooks
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>
-rw-r--r--drivers/char/random.c25
-rw-r--r--include/linux/random.h13
2 files changed, 35 insertions, 3 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index d4ddeba56682..bb587127fb9d 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
@@ -1635,8 +1649,13 @@ DEFINE_PER_CPU(__u32 [4], get_random_int_hash);
1635unsigned int get_random_int(void) 1649unsigned int get_random_int(void)
1636{ 1650{
1637 struct keydata *keyptr; 1651 struct keydata *keyptr;
1638 __u32 *hash = get_cpu_var(get_random_int_hash); 1652 __u32 *hash;
1639 int ret; 1653 unsigned int ret;
1654
1655 if (arch_get_random_int(&ret))
1656 return ret;
1657
1658 hash = get_cpu_var(get_random_int_hash);
1640 1659
1641 keyptr = get_keyptr(); 1660 keyptr = get_keyptr();
1642 hash[0] += current->pid + jiffies + get_cycles(); 1661 hash[0] += current->pid + jiffies + get_cycles();
diff --git a/include/linux/random.h b/include/linux/random.h
index fb7ab9de5f36..079cbba39a28 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -102,6 +102,19 @@ static inline void prandom32_seed(struct rnd_state *state, u64 seed)
102 state->s3 = __seed(i, 15); 102 state->s3 = __seed(i, 15);
103} 103}
104 104
105#ifdef CONFIG_ARCH_RANDOM
106# include <asm/archrandom.h>
107#else
108static inline int arch_get_random_long(unsigned long *v)
109{
110 return 0;
111}
112static inline int arch_get_random_int(unsigned int *v)
113{
114 return 0;
115}
116#endif
117
105#endif /* __KERNEL___ */ 118#endif /* __KERNEL___ */
106 119
107#endif /* _LINUX_RANDOM_H */ 120#endif /* _LINUX_RANDOM_H */