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.

Collecting entropy from the keyboard on Windows<br />

To collect entropy from the keyboard on Windows, we will start by building a dialog<br />

that displays a brief message advising the user to type random characters on the<br />

keyboard until enough entropy has been collected. The dialog will also contain a<br />

progress bar and an OK button that is initially disabled. As entropy is collected, the<br />

progress bar will be updated to report the progress of the collection. When enough<br />

entropy has been collected, the OK button will be enabled. Clicking the OK button<br />

will dismiss the dialog.<br />

Here is the resource definition for the dialog:<br />

#include <br />

#define SPC_KEYBOARD_DLGID 101<br />

#define SPC_PROGRESS_BARID 1000<br />

#define SPC_KEYBOARD_STATIC 1001<br />

SPC_KEYBOARD_DLGID DIALOG DISCARDABLE 0, 0, 186, 95<br />

STYLE DS_MODALFRAME | DS_NOIDLEMSG | DS_CENTER | WS_POPUP | WS_VISIBLE |<br />

WS_CAPTION<br />

FONT 8, "MS Sans Serif"<br />

BEGIN<br />

CONTROL "Progress1",SPC_PROGRESS_BARID,"msctls_progress32",<br />

PBS_SMOOTH | WS_BORDER,5,40,175,14<br />

LTEXT "Please type random characters on your keyboard until the \<br />

progress bar reports 100% and the OK button becomes active.",<br />

SPC_KEYBOARD_STATIC,5,5,175,25<br />

PUSHBUTTON "OK",IDOK,130,70,50,14,WS_DISABLED<br />

END<br />

Call the function SpcGatherKeyboardEntropy( ) to begin the process of collecting<br />

entropy. It requires two additional arguments to its Unix counterpart, spc_gather_<br />

keyboard_entropy( ):<br />

hInstance<br />

Application instance handle normally obtained from the first argument to<br />

WinMain( ), the program’s entry point.<br />

hWndParent<br />

Handle to the dialog’s parent window. It may be specified as NULL, in which case<br />

the dialog will have no parent.<br />

pbOutput<br />

Buffer into which the collected entropy will be placed.<br />

cbOutput<br />

Number of bytes of entropy to place into the output buffer. The output buffer<br />

must be sufficiently large to hold the requested amount of entropy. The number<br />

of bytes of entropy requested should not exceed the size of the hash function<br />

used, which is SHA1 in the code provided. SHA1 produces a 160-bit or 20-byte<br />

hash. If the requested entropy is smaller than the hash function’s output, the<br />

hash function’s output will be truncated.<br />

634 | 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!