21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

nbytes<br />

Number of bytes of entropy that should be written into the output buffer. You<br />

must be sure that the output buffer is sufficiently large to hold the requested<br />

data.<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 be not be specified here.<br />

The function PRNG_output( ) allows you to get byte strings of cryptographically random<br />

data. Its signature nearly matches that of spc_rand( ) from Recipe 11.2:<br />

void PRNG_output(prng_ctx *ctx, char *buf, int64 nbytes);<br />

This function has the following arguments:<br />

ctx<br />

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

buf<br />

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

nbytes<br />

Number of bytes of random data that should be written into the output buffer.<br />

You must be sure that the output buffer is sufficiently large to hold the requested<br />

data.<br />

The function egads_destroy( ) resets a PRNG context object. Before the memory for<br />

the context object is freed or goes out of scope (because it is statically allocated on<br />

the stack), egads_destroy( ) must be called on a successfully initialized context<br />

object. This ensures that the connection to the EGADS server or service is broken,<br />

and that any other memory or state maintained by EGADS that is associated with the<br />

context object is cleaned up.<br />

void egads_destroy(prngctx_t *ctx);<br />

This ctx argument is the successfully initialized PRNG context that is to be<br />

destroyed. It is the caller’s responsibility to free any memory used to allocate the<br />

object<br />

The rest of the EGADS API allows you to retrieve pseudo-random values of particular<br />

data types. All functions in this API take a final argument that, on completion of<br />

the call, contains the success or failure status. On failure, the error argument contains<br />

an integer error code. On success, it will be 0.<br />

void egads_randlong(prngctx_t *ctx, long *out, int *error);<br />

void egads_randulong(prngctx_t *ctx, unsigned long *out, int *error);<br />

void egads_randint(prngctx_t *ctx, int *out, int *error);<br />

void egads_randuint(prngctx_t *ctx, unsigned int *out, int *error);<br />

void egads_randrange(prngctx_t *ctx, int *out, int min, int max, int *error);<br />

Getting Entropy or Pseudo-Randomness Using EGADS | 601<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!