Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 320715
b: refs/heads/master
c: a2080a6
h: refs/heads/master
i:
  320713: c61d937
  320711: 1cd7719
v: v3
  • Loading branch information
Linus Torvalds authored and Theodore Ts'o committed Jul 15, 2012
1 parent fdf3c3f commit 9d8cc65
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 902c098a3663de3fa18639efbb71b6080f0bcd3c
refs/heads/master: a2080a67abe9e314f9e9c2cc3a4a176e8a8f8793
28 changes: 28 additions & 0 deletions trunk/drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,20 @@
* The current exported interfaces for gathering environmental noise
* from the devices are:
*
* void add_device_randomness(const void *buf, unsigned int size);
* void add_input_randomness(unsigned int type, unsigned int code,
* unsigned int value);
* void add_interrupt_randomness(int irq, int irq_flags);
* void add_disk_randomness(struct gendisk *disk);
*
* add_device_randomness() is for adding data to the random pool that
* is likely to differ between two devices (or possibly even per boot).
* This would be things like MAC addresses or serial numbers, or the
* read-out of the RTC. This does *not* add any actual entropy to the
* pool, but it initializes the pool to different values for devices
* that might otherwise be identical and have very little entropy
* available to them (particularly common in the embedded world).
*
* add_input_randomness() uses the input layer interrupt timing, as well as
* the event type information from the hardware.
*
Expand Down Expand Up @@ -646,6 +655,25 @@ static void set_timer_rand_state(unsigned int irq,
}
#endif

/*
* Add device- or boot-specific data to the input and nonblocking
* pools to help initialize them to unique values.
*
* None of this adds any entropy, it is meant to avoid the
* problem of the nonblocking pool having similar initial state
* across largely identical devices.
*/
void add_device_randomness(const void *buf, unsigned int size)
{
unsigned long time = get_cycles() ^ jiffies;

mix_pool_bytes(&input_pool, buf, size, NULL);
mix_pool_bytes(&input_pool, &time, sizeof(time), NULL);
mix_pool_bytes(&nonblocking_pool, buf, size, NULL);
mix_pool_bytes(&nonblocking_pool, &time, sizeof(time), NULL);
}
EXPORT_SYMBOL(add_device_randomness);

static struct timer_rand_state input_timer_state;

/*
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct rnd_state {

extern void rand_initialize_irq(int irq);

extern void add_device_randomness(const void *, unsigned int);
extern void add_input_randomness(unsigned int type, unsigned int code,
unsigned int value);
extern void add_interrupt_randomness(int irq, int irq_flags);
Expand Down

0 comments on commit 9d8cc65

Please sign in to comment.