diff options
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r-- | drivers/char/random.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index 315feb1f59f3..df3358ab5b99 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c | |||
@@ -125,11 +125,20 @@ | |||
125 | * The current exported interfaces for gathering environmental noise | 125 | * The current exported interfaces for gathering environmental noise |
126 | * from the devices are: | 126 | * from the devices are: |
127 | * | 127 | * |
128 | * void add_device_randomness(const void *buf, unsigned int size); | ||
128 | * void add_input_randomness(unsigned int type, unsigned int code, | 129 | * void add_input_randomness(unsigned int type, unsigned int code, |
129 | * unsigned int value); | 130 | * unsigned int value); |
130 | * void add_interrupt_randomness(int irq, int irq_flags); | 131 | * void add_interrupt_randomness(int irq, int irq_flags); |
131 | * void add_disk_randomness(struct gendisk *disk); | 132 | * void add_disk_randomness(struct gendisk *disk); |
132 | * | 133 | * |
134 | * add_device_randomness() is for adding data to the random pool that | ||
135 | * is likely to differ between two devices (or possibly even per boot). | ||
136 | * This would be things like MAC addresses or serial numbers, or the | ||
137 | * read-out of the RTC. This does *not* add any actual entropy to the | ||
138 | * pool, but it initializes the pool to different values for devices | ||
139 | * that might otherwise be identical and have very little entropy | ||
140 | * available to them (particularly common in the embedded world). | ||
141 | * | ||
133 | * add_input_randomness() uses the input layer interrupt timing, as well as | 142 | * add_input_randomness() uses the input layer interrupt timing, as well as |
134 | * the event type information from the hardware. | 143 | * the event type information from the hardware. |
135 | * | 144 | * |
@@ -646,6 +655,25 @@ static void set_timer_rand_state(unsigned int irq, | |||
646 | } | 655 | } |
647 | #endif | 656 | #endif |
648 | 657 | ||
658 | /* | ||
659 | * Add device- or boot-specific data to the input and nonblocking | ||
660 | * pools to help initialize them to unique values. | ||
661 | * | ||
662 | * None of this adds any entropy, it is meant to avoid the | ||
663 | * problem of the nonblocking pool having similar initial state | ||
664 | * across largely identical devices. | ||
665 | */ | ||
666 | void add_device_randomness(const void *buf, unsigned int size) | ||
667 | { | ||
668 | unsigned long time = get_cycles() ^ jiffies; | ||
669 | |||
670 | mix_pool_bytes(&input_pool, buf, size, NULL); | ||
671 | mix_pool_bytes(&input_pool, &time, sizeof(time), NULL); | ||
672 | mix_pool_bytes(&nonblocking_pool, buf, size, NULL); | ||
673 | mix_pool_bytes(&nonblocking_pool, &time, sizeof(time), NULL); | ||
674 | } | ||
675 | EXPORT_SYMBOL(add_device_randomness); | ||
676 | |||
649 | static struct timer_rand_state input_timer_state; | 677 | static struct timer_rand_state input_timer_state; |
650 | 678 | ||
651 | /* | 679 | /* |