Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random

Pull /dev/random changes from Ted Ts'o:
"These patches are designed to enable improvements to /dev/random for
non-x86 platforms, in particular MIPS and ARM"

* tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random:
random: allow architectures to optionally define random_get_entropy()
random: run random_int_secret_init() run after all late_initcalls

+22 -6
+5 -6
drivers/char/random.c
··· 640 640 */ 641 641 void add_device_randomness(const void *buf, unsigned int size) 642 642 { 643 - unsigned long time = get_cycles() ^ jiffies; 643 + unsigned long time = random_get_entropy() ^ jiffies; 644 644 645 645 mix_pool_bytes(&input_pool, buf, size, NULL); 646 646 mix_pool_bytes(&input_pool, &time, sizeof(time), NULL); ··· 677 677 goto out; 678 678 679 679 sample.jiffies = jiffies; 680 - sample.cycles = get_cycles(); 680 + sample.cycles = random_get_entropy(); 681 681 sample.num = num; 682 682 mix_pool_bytes(&input_pool, &sample, sizeof(sample), NULL); 683 683 ··· 744 744 struct fast_pool *fast_pool = &__get_cpu_var(irq_randomness); 745 745 struct pt_regs *regs = get_irq_regs(); 746 746 unsigned long now = jiffies; 747 - __u32 input[4], cycles = get_cycles(); 747 + __u32 input[4], cycles = random_get_entropy(); 748 748 749 749 input[0] = cycles ^ jiffies; 750 750 input[1] = irq; ··· 1459 1459 1460 1460 static u32 random_int_secret[MD5_MESSAGE_BYTES / 4] ____cacheline_aligned; 1461 1461 1462 - static int __init random_int_secret_init(void) 1462 + int random_int_secret_init(void) 1463 1463 { 1464 1464 get_random_bytes(random_int_secret, sizeof(random_int_secret)); 1465 1465 return 0; 1466 1466 } 1467 - late_initcall(random_int_secret_init); 1468 1467 1469 1468 /* 1470 1469 * Get a random word for internal kernel use only. Similar to urandom but ··· 1482 1483 1483 1484 hash = get_cpu_var(get_random_int_hash); 1484 1485 1485 - hash[0] += current->pid + jiffies + get_cycles(); 1486 + hash[0] += current->pid + jiffies + random_get_entropy(); 1486 1487 md5_transform(hash, random_int_secret); 1487 1488 ret = hash[0]; 1488 1489 put_cpu_var(get_random_int_hash);
+1
include/linux/random.h
··· 17 17 extern void get_random_bytes(void *buf, int nbytes); 18 18 extern void get_random_bytes_arch(void *buf, int nbytes); 19 19 void generate_random_uuid(unsigned char uuid_out[16]); 20 + extern int random_int_secret_init(void); 20 21 21 22 #ifndef MODULE 22 23 extern const struct file_operations random_fops, urandom_fops;
+14
include/linux/timex.h
··· 64 64 65 65 #include <asm/timex.h> 66 66 67 + #ifndef random_get_entropy 68 + /* 69 + * The random_get_entropy() function is used by the /dev/random driver 70 + * in order to extract entropy via the relative unpredictability of 71 + * when an interrupt takes places versus a high speed, fine-grained 72 + * timing source or cycle counter. Since it will be occurred on every 73 + * single interrupt, it must have a very low cost/overhead. 74 + * 75 + * By default we use get_cycles() for this purpose, but individual 76 + * architectures may override this in their asm/timex.h header file. 77 + */ 78 + #define random_get_entropy() get_cycles() 79 + #endif 80 + 67 81 /* 68 82 * SHIFT_PLL is used as a dampening factor to define how much we 69 83 * adjust the frequency correction for a given offset in PLL mode.
+2
init/main.c
··· 76 76 #include <linux/elevator.h> 77 77 #include <linux/sched_clock.h> 78 78 #include <linux/context_tracking.h> 79 + #include <linux/random.h> 79 80 80 81 #include <asm/io.h> 81 82 #include <asm/bugs.h> ··· 781 780 do_ctors(); 782 781 usermodehelper_enable(); 783 782 do_initcalls(); 783 + random_int_secret_init(); 784 784 } 785 785 786 786 static void __init do_pre_smp_initcalls(void)