random: Use arch-specific RNG to initialize the entropy store
authorTheodore Ts'o <tytso@mit.edu>
Thu, 22 Dec 2011 21:28:01 +0000 (16:28 -0500)
committerH. Peter Anvin <hpa@linux.intel.com>
Mon, 16 Jan 2012 19:18:21 +0000 (11:18 -0800)
If there is an architecture-specific random number generator (such as
RDRAND for Intel architectures), use it to initialize /dev/random's
entropy stores.  Even in the worst case, if RDRAND is something like
AES(NSA_KEY, counter++), it won't hurt, and it will definitely help
against any other adversaries.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Link: http://lkml.kernel.org/r/1324589281-31931-1-git-send-email-tytso@mit.edu
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
drivers/char/random.c

index 85da874..3079477 100644 (file)
@@ -965,6 +965,7 @@ EXPORT_SYMBOL(get_random_bytes);
  */
 static void init_std_data(struct entropy_store *r)
 {
+       int i;
        ktime_t now;
        unsigned long flags;
 
@@ -974,6 +975,11 @@ static void init_std_data(struct entropy_store *r)
 
        now = ktime_get_real();
        mix_pool_bytes(r, &now, sizeof(now));
+       for (i = r->poolinfo->poolwords; i; i--) {
+               if (!arch_get_random_long(&flags))
+                       break;
+               mix_pool_bytes(r, &flags, sizeof(flags));
+       }
        mix_pool_bytes(r, utsname(), sizeof(*(utsname())));
 }