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.

process. While EGADS implements the EGD interface, it ignores the entropy estimate<br />

supplied by the user. It does mix the entropy into its state, but it assumes that it<br />

contains no entropy.<br />

The following code implements the spc_entropy( ) and spc_keygen( ) functions<br />

from Recipe 11.2 using the EGD interface. We omit spc_rand( ) but assume that it<br />

exists (it is called by spc_keygen( ) when appropriate). To implement spc_rand( ),<br />

see Recipe 11.5.<br />

When implementing spc_entropy( ) and spc_keygen( ), we do not cryptographically<br />

postprocess the entropy to thwart statistical analysis if we do not have as much<br />

entropy as estimated, as you can generally expect servers implementing the EGD<br />

interface to do this (EGADS certainly does). If you want to be absolutely sure, you<br />

can do your own cryptographic postprocessing, as shown in Recipe 11.16.<br />

Note that the following code requires you to know in advance the file on the filesystem<br />

that implements the EGD interface. There is no standard place to look for EGD<br />

sockets, so you could either make the location of the socket something the user can<br />

configure, or require the user to run the collector in such a way that the socket lives<br />

in a particular place on the filesystem.<br />

Of course, the socket should live in a “safe” directory, where only the user running<br />

the entropy system can write files (see Recipe 2.4). Clearly, any user who needs to be<br />

able to use the server must have read access to the socket.<br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#define EGD_SOCKET_PATH "/home/egd/socket"<br />

/* NOTE: this needs to be augmented with whatever you need to do in order to seed<br />

* your application-level generator. Clearly, seed that generator after you've<br />

* initialized the connection with the entropy server.<br />

*/<br />

static int spc_egd_fd = -1;<br />

void spc_rand_init(void) {<br />

struct sockaddr_un a;<br />

if ((spc_egd_fd = socket(PF_UNIX, SOCK_STREAM, 0)) = = -1) {<br />

perror("Entropy server connection failed");<br />

exit(-1);<br />

}<br />

a.sun_len = sizeof(a);<br />

a.sun_family = AF_UNIX;<br />

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