random: Fix handing of arch_get_random_long in get_random_bytes()
[pandora-kernel.git] / drivers / char / random.c
index c35a785..6035ab8 100644 (file)
@@ -932,7 +932,21 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
  */
 void get_random_bytes(void *buf, int nbytes)
 {
-       extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0);
+       char *p = buf;
+
+       while (nbytes) {
+               unsigned long v;
+               int chunk = min(nbytes, (int)sizeof(unsigned long));
+               
+               if (!arch_get_random_long(&v))
+                       break;
+               
+               memcpy(p, &v, chunk);
+               p += chunk;
+               nbytes -= chunk;
+       }
+
+       extract_entropy(&nonblocking_pool, p, nbytes, 0, 0);
 }
 EXPORT_SYMBOL(get_random_bytes);
 
@@ -1318,9 +1332,14 @@ late_initcall(random_int_secret_init);
 DEFINE_PER_CPU(__u32 [MD5_DIGEST_WORDS], get_random_int_hash);
 unsigned int get_random_int(void)
 {
-       __u32 *hash = get_cpu_var(get_random_int_hash);
+       __u32 *hash;
        unsigned int ret;
 
+       if (arch_get_random_int(&ret))
+               return ret;
+
+       hash = get_cpu_var(get_random_int_hash);
+
        hash[0] += current->pid + jiffies + get_cycles();
        md5_transform(hash, random_int_secret);
        ret = hash[0];