Commit 17d2208b authored by Matt Mackall's avatar Matt Mackall Committed by Linus Torvalds

[PATCH] random: add_input_randomness

The input layer wants to send us an entropy event per input event and who are
we to argue?  Create add_input_randomness with an input-friendly interface and
kill the remaining two keyboard and mouse sources.

This eliminates lots of duplicate entropy events while covering all the input
bases nicely.  We now get two events per keystroke as we should, one down and
one up.
Signed-off-by: default avatarMatt Mackall <mpm@selenic.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 257fd23f
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <linux/tty_flip.h> #include <linux/tty_flip.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/random.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -1031,9 +1030,6 @@ void kbd_keycode(unsigned int keycode, int down, int hw_raw, struct pt_regs *reg ...@@ -1031,9 +1030,6 @@ void kbd_keycode(unsigned int keycode, int down, int hw_raw, struct pt_regs *reg
struct tty_struct *tty; struct tty_struct *tty;
int shift_final; int shift_final;
if (down != 2)
add_keyboard_randomness((keycode << 1) ^ down);
tty = vc->vc_tty; tty = vc->vc_tty;
if (tty && (!tty->driver_data)) { if (tty && (!tty->driver_data)) {
......
...@@ -69,7 +69,6 @@ ...@@ -69,7 +69,6 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/kbd_ll.h> #include <linux/kbd_ll.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/random.h>
#include <linux/poll.h> #include <linux/poll.h>
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -442,7 +441,6 @@ static inline void handle_mouse_event(unsigned char scancode) ...@@ -442,7 +441,6 @@ static inline void handle_mouse_event(unsigned char scancode)
return; return;
} }
add_mouse_randomness(scancode);
if (aux_count) { if (aux_count) {
int head = queue->head; int head = queue->head;
......
...@@ -125,15 +125,12 @@ ...@@ -125,15 +125,12 @@
* The current exported interfaces for gathering environmental noise * The current exported interfaces for gathering environmental noise
* from the devices are: * from the devices are:
* *
* void add_keyboard_randomness(unsigned char scancode); * void add_input_randomness(unsigned int type, unsigned int code,
* void add_mouse_randomness(__u32 mouse_data); * unsigned int value);
* void add_interrupt_randomness(int irq); * void add_interrupt_randomness(int irq);
* *
* add_keyboard_randomness() uses the inter-keypress timing, as well as the * add_input_randomness() uses the input layer interrupt timing, as well as
* scancode as random inputs into the "entropy pool". * the event type information from the hardware.
*
* add_mouse_randomness() uses the mouse interrupt timing, as well as
* the reported position of the mouse from the hardware.
* *
* add_interrupt_randomness() uses the inter-interrupt timing as random * add_interrupt_randomness() uses the inter-interrupt timing as random
* inputs to the entropy pool. Note that not all interrupts are good * inputs to the entropy pool. Note that not all interrupts are good
...@@ -788,8 +785,7 @@ struct timer_rand_state { ...@@ -788,8 +785,7 @@ struct timer_rand_state {
unsigned dont_count_entropy:1; unsigned dont_count_entropy:1;
}; };
static struct timer_rand_state keyboard_timer_state; static struct timer_rand_state input_timer_state;
static struct timer_rand_state mouse_timer_state;
static struct timer_rand_state extract_timer_state; static struct timer_rand_state extract_timer_state;
static struct timer_rand_state *irq_timer_state[NR_IRQS]; static struct timer_rand_state *irq_timer_state[NR_IRQS];
...@@ -869,24 +865,20 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num) ...@@ -869,24 +865,20 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
preempt_enable(); preempt_enable();
} }
void add_keyboard_randomness(unsigned char scancode) extern void add_input_randomness(unsigned int type, unsigned int code,
unsigned int value)
{ {
static unsigned char last_scancode; static unsigned char last_value;
/* ignore autorepeat (multiple key down w/o key up) */
DEBUG_ENT("keyboard event\n");
if (scancode != last_scancode) {
last_scancode = scancode;
add_timer_randomness(&keyboard_timer_state, scancode);
}
}
void add_mouse_randomness(__u32 mouse_data) /* ignore autorepeat and the like */
{ if (value == last_value)
DEBUG_ENT("mouse event\n"); return;
add_timer_randomness(&mouse_timer_state, mouse_data);
}
EXPORT_SYMBOL(add_mouse_randomness); DEBUG_ENT("input event\n");
last_value = value;
add_timer_randomness(&input_timer_state,
(type << 4) ^ code ^ (code >> 4) ^ value);
}
void add_interrupt_randomness(int irq) void add_interrupt_randomness(int irq)
{ {
...@@ -1550,8 +1542,7 @@ static int __init rand_initialize(void) ...@@ -1550,8 +1542,7 @@ static int __init rand_initialize(void)
#endif #endif
for (i = 0; i < NR_IRQS; i++) for (i = 0; i < NR_IRQS; i++)
irq_timer_state[i] = NULL; irq_timer_state[i] = NULL;
memset(&keyboard_timer_state, 0, sizeof(struct timer_rand_state)); memset(&input_timer_state, 0, sizeof(struct timer_rand_state));
memset(&mouse_timer_state, 0, sizeof(struct timer_rand_state));
memset(&extract_timer_state, 0, sizeof(struct timer_rand_state)); memset(&extract_timer_state, 0, sizeof(struct timer_rand_state));
extract_timer_state.dont_count_entropy = 1; extract_timer_state.dont_count_entropy = 1;
return 0; return 0;
......
...@@ -69,7 +69,7 @@ void input_event(struct input_dev *dev, unsigned int type, unsigned int code, in ...@@ -69,7 +69,7 @@ void input_event(struct input_dev *dev, unsigned int type, unsigned int code, in
if (type > EV_MAX || !test_bit(type, dev->evbit)) if (type > EV_MAX || !test_bit(type, dev->evbit))
return; return;
add_mouse_randomness((type << 4) ^ code ^ (code >> 4) ^ value); add_input_randomness(type, code, value);
switch (type) { switch (type) {
......
...@@ -44,8 +44,8 @@ struct rand_pool_info { ...@@ -44,8 +44,8 @@ struct rand_pool_info {
extern void rand_initialize_irq(int irq); extern void rand_initialize_irq(int irq);
extern void add_keyboard_randomness(unsigned char scancode); extern void add_input_randomness(unsigned int type, unsigned int code,
extern void add_mouse_randomness(__u32 mouse_data); unsigned int value);
extern void add_interrupt_randomness(int irq); extern void add_interrupt_randomness(int irq);
extern void get_random_bytes(void *buf, int nbytes); extern void get_random_bytes(void *buf, int nbytes);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment