add_mouse_randomness
PATCH 1/1 add_mouse_randomness
I do not know whether anybody cares, but the random driver is a little bit broken these days.
Long ago:
Keystrokes cause randomness added via add_keyboard_randomness. Mouse movements cause randomness added via add_mouse_randomness. Key repeat does not add randomness.
Today:
Every keypress and every key release causes two calls of add_mouse_randomness and one call of add_keyboard_randomness. Key repeat causes lots of calls of add_mouse_randomness.
The random driver contains a mechanism (delta, delta2, delta3) for estimating the amount of entropy in a stream of moments in time. But the fact that every event causes two calls, very quickly after each other, poisons this mechanism, and makes us overestimate.
I think it would be better to do something like the below.
Andries
[Note that the data in the call to add-X-randomness hardly matters. Accounted entropy comes from timing only.]
drivers/input/input.c +0 -3
@@ -15,7 +15,6 @@#include <linux/smp_lock.h> #include <linux/input.h> #include <linux/module.h> -#include <linux/random.h> #include <linux/major.h> #include <linux/pm.h> #include <linux/proc_fs.h>
@@ -66,8 +65,6 @@if (type >EV_MAX || !test_bit (type, dev->evbit))return ; -add_mouse_randomness ((type <<4 ) ^ code ^ (code >>4 ) ^ value); -switch (type) {case EV_SYN :
drivers/input/mouse/psmouse-base.c +4 -0
@@ -16,6 +16,7 @@#include <linux/interrupt.h> #include <linux/input.h> #include <linux/serio.h> +#include <linux/random.h> #include <linux/init.h> #include "psmouse.h" #include "synaptics.h"
@@ -139,6 +140,9 @@ psmouse->last = jiffies; psmouse->packet[psmouse->pktcnt++] = data; +if (psmouse->pktcnt ==1 ) +add_mouse_randomness (data); +if (psmouse->pktcnt ==3 + (psmouse->type >=PSMOUSE_GENPS )) {psmouse_process_packet (psmouse, regs); psmouse->pktcnt =0 ;
Quoted 13 lines · On Fri, Sep 05, 2003 at 12:51:54AM +0200, [email protected] wrote:
I do not know whether anybody cares, but the random driver is a little bit broken these days.
Long ago:
Keystrokes cause randomness added viaadd_keyboard_randomness. Mouse movements cause randomness added viaadd_mouse_randomness. Key repeat does not add randomness.Today:
Every keypress and every key release causes two calls ofadd_mouse_randomnessand one call ofadd_keyboard_randomness. Key repeat causes lots of calls ofadd_mouse_randomness.
Quoted 5 lines
The random driver contains a mechanism (delta, delta2, delta3) for estimating the amount of entropy in a stream of moments in time. But the fact that every event causes two calls, very quickly after each other, poisons this mechanism, and makes us overestimate.
The real problem is that the deltas are calculated from gigahertz cycle counters, but yes, we're calling too frequently and blowing away useful history. I've experimented with making the deltas per-source as well.
I'll put this on my todo list.
Signature · 1 line
Matt Mackall : http://www.selenic.com : of or relating to the moon