diff options
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 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]; |