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.

on the strength of the AES cryptographic algorithm. EGADS does a good job of protecting<br />

against compromised entropy sources, which other PRNGs tend not to do. It<br />

also provides a good amount of protection against backtracking attacks, meaning<br />

that if the internal generator state does get compromised, few if any of the previous<br />

generator outputs will be recoverable.<br />

To use EGADS, you must install the package, start up the server that comes with it,<br />

include egads.h, and link against the correct library, which will typically be libegads.so<br />

on Unix (libegads.dyld on Darwin) and egads.lib on Windows.<br />

Before you can use any of the functions in the EGADS package, you must first initialize<br />

a PRNG context by calling egads_init( ):<br />

void egads_init(prngctx_t *ctx, char *sockname, char *rfile, int *err);<br />

This function has the following arguments:<br />

ctx<br />

PRNG context object that is to be initialized. The caller should allocate the<br />

object either statically or dynamically.<br />

sockname<br />

If not specified as NULL, this is the address of the server. On Unix, this is the<br />

name of the Unix domain socket created by the EGADS server. On Windows,<br />

this is the name of the mailslot object created by the EGADS service. If specified<br />

as NULL, which is normally how it should be specified, the compiled-in default<br />

will be used.<br />

rfile<br />

Name of a file from which entropy can be read. On Unix, this defaults to /dev/<br />

random if it is specified as NULL. This argument is always ignored on Windows.<br />

err<br />

If any error occurs, an error code will be stored in this argument. A value of 0<br />

indicates that no error occurred; otherwise, one of the RERR_* constants defined<br />

in egads.h will be returned. NULL may not be specified here.<br />

The function egads_entropy( ) establishes a connection to the entropy gateway and<br />

obtains the requested number of bytes of raw entropy. If not enough entropy is currently<br />

available to satisfy the request, this function will block until there is. Its signature<br />

nearly matches that of spc_entropy( ) from Recipe 11.2:<br />

void egads_entropy(prngctx_t *ctx, char *buf, int nbytes, int *err);<br />

This function has the following arguments:<br />

ctx<br />

PRNG context object that has been initialized.<br />

out<br />

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

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