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.

number of bits of entropy has been collected. A progress bar is also displayed that<br />

shows how much more entropy needs to be collected.<br />

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

#include <br />

#define SPC_MOUSE_DLGID 102<br />

#define SPC_PROGRESS_BARID 1000<br />

#define SPC_MOUSE_COLLECTID 1002<br />

#define SPC_MOUSE_STATIC 1003<br />

SPC_MOUSE_DLGID DIALOG DISCARDABLE 0, 0, 287, 166<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,125,275,14<br />

LTEXT "Please move your mouse over this dialog until the progress \<br />

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

SPC_MOUSE_STATIC,5,5,275,20<br />

PUSHBUTTON "OK",IDOK,230,145,50,14,WS_DISABLED<br />

CONTROL "",SPC_MOUSE_COLLECTID,"Static",SS_LEFTNOWORDWRAP |<br />

SS_SUNKEN | WS_BORDER | WS_GROUP,5,35,275,80<br />

END<br />

Call the function SpcGatherMouseEntropy( )to begin the process of collecting entropy.<br />

It has the same signature as SpcGatherKeyboardEntropy( ) from Recipe 11.20. This<br />

function has the following arguments:<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 />

SpcGatherMouseEntropy( ) uses the CryptoAPI to hash the data collected from the<br />

mouse. It first acquires a context object, then creates a hash object. After the arguments<br />

are validated, the dialog resource is loaded by calling DialogBoxParam( ), which<br />

Gathering Entropy from Mouse Events on Windows | 639<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!