21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

11.21 Gathering Entropy from Mouse Events on<br />

Windows<br />

<strong>Problem</strong><br />

You need entropy in a low-entropy environment and can prompt the user to move<br />

the mouse to collect it.<br />

Solution<br />

On Windows, process all mouse events. Mix into an entropy pool the current position<br />

of the mouse pointer on the screen, along with the timestamp at which each<br />

event was processed. Estimate entropy based upon your operating environment; see<br />

the considerations in Recipe 11.19.<br />

Discussion<br />

There can be a reasonable amount of entropy in mouse movement. The entropy<br />

comes not just from where the mouse pointer is on the screen, but from when each<br />

movement was made. In fact, the mouse pointer’s position on the screen can have<br />

very little entropy in it, particularly in an environment where there may be very little<br />

interaction from a local user. Most of the entropy will come from the exact timing of<br />

the mouse movements.<br />

The basic methodology is to mix the on-screen position of the mouse pointer, along<br />

with a timestamp, into the entropy pool. We will provide an example implementation<br />

in this section, where that operation is merely hashing the data into a running<br />

SHA1 context.<br />

The big issue is in estimating the amount of entropy in each mouse movement. The<br />

first worry is that it is common for Windows to send multiple mouse event messages<br />

with the same mouse pointer position. That is easy to thwart, though. You simply do<br />

not measure any entropy at all, unless the mouse pointer has actually changed position.<br />

Ultimately, the amount of entropy you estimate getting from each mouse movement<br />

should be related to the resolution of the clock you use to measure mouse movements.<br />

In addition, you must consider whether other processes on the system may be<br />

recording similar information. (See Recipe 11.19 for a detailed discussion of entropy<br />

estimation.)<br />

The following code captures mouse events, hashes mouse pointer positions and<br />

timestamps into a SHA1 context, and repeats until it is believed that the requested<br />

638 | Chapter 11: Random Numbers<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!