mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] add_mouse_randomness
@ 2003-09-04 22:51 Andries.Brouwer
  2003-09-05  3:21 ` Matt Mackall
  0 siblings, 1 reply; 4+ messages in thread
From: Andries.Brouwer @ 2003-09-04 22:51 UTC (permalink / raw)
  To: linux-kernel

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.]


diff -u --recursive --new-file -X /linux/dontdiff a/drivers/input/input.c b/drivers/input/input.c
--- a/drivers/input/input.c	Sat Aug 23 13:30:03 2003
+++ b/drivers/input/input.c	Thu Sep  4 23:51:25 2003
@@ -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:
diff -u --recursive --new-file -X /linux/dontdiff a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
--- a/drivers/input/mouse/psmouse-base.c	Mon Jun 23 04:43:33 2003
+++ b/drivers/input/mouse/psmouse-base.c	Thu Sep  4 23:51:57 2003
@@ -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;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] add_mouse_randomness
  2003-09-04 22:51 [PATCH] add_mouse_randomness Andries.Brouwer
@ 2003-09-05  3:21 ` Matt Mackall
  0 siblings, 0 replies; 4+ messages in thread
From: Matt Mackall @ 2003-09-05  3:21 UTC (permalink / raw)
  To: Andries.Brouwer; +Cc: linux-kernel

On Fri, Sep 05, 2003 at 12:51:54AM +0200, Andries.Brouwer@cwi.nl 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 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.

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.

-- 
Matt Mackall : http://www.selenic.com : of or relating to the moon

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] add_mouse_randomness
  2003-09-05  9:16 Andries.Brouwer
@ 2003-09-05 17:05 ` Matt Mackall
  0 siblings, 0 replies; 4+ messages in thread
From: Matt Mackall @ 2003-09-05 17:05 UTC (permalink / raw)
  To: Andries.Brouwer; +Cc: linux-kernel

On Fri, Sep 05, 2003 at 11:16:05AM +0200, Andries.Brouwer@cwi.nl wrote:
>     From oxymoron@waste.org  Fri Sep  5 07:01:30 2003
>     From: Matt Mackall <mpm@selenic.com>
> 
>     > 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.
> 
>     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 wouldnt know what is wrong with using gigahertz cycle counters.
> The deltas are already per-source.

Actually, they're only per-class. So if you have multiple mice,
keyboards, drives, etc., they interfere with each other's deltas and
increase the entropy estimates overall.

-- 
Matt Mackall : http://www.selenic.com : of or relating to the moon

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] add_mouse_randomness
@ 2003-09-05  9:16 Andries.Brouwer
  2003-09-05 17:05 ` Matt Mackall
  0 siblings, 1 reply; 4+ messages in thread
From: Andries.Brouwer @ 2003-09-05  9:16 UTC (permalink / raw)
  To: Andries.Brouwer, mpm; +Cc: linux-kernel

    From oxymoron@waste.org  Fri Sep  5 07:01:30 2003
    From: Matt Mackall <mpm@selenic.com>

    > 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.

    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 wouldnt know what is wrong with using gigahertz cycle counters.
The deltas are already per-source.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-09-05 17:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-04 22:51 [PATCH] add_mouse_randomness Andries.Brouwer
2003-09-05  3:21 ` Matt Mackall
2003-09-05  9:16 Andries.Brouwer
2003-09-05 17:05 ` Matt Mackall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®