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.

The seed should be at least as large as the key size of the cipher, because it will be<br />

used to key a block cipher. In addition, it is useful to have additional seed data that<br />

sets the first plaintext (counter) value.<br />

Our implementation is based on the code in Recipe 5.5 and has two exported routines.<br />

The first initializes a random number generator:<br />

void spc_bcprng_init(SPC_BCPRNG_CTX *prng, unsigned char *key, int kl,<br />

unsigned char *x, int xl);<br />

This function has the following arguments:<br />

prng<br />

Pointer to a context object that holds the state for a block cipher–based PRNG.<br />

The caller may allocate the context object either dynamically or statically; this<br />

function will initialize it.<br />

key<br />

kl<br />

x<br />

xl<br />

Buffer that should contain entropic data. This data is used to key the block<br />

cipher, and it is the required portion of the seed to the generator.<br />

Length of the key buffer in bytes; must be a valid value for the algorithm in use.<br />

Buffer that may contain extra seed data, which we recommend you use if you have<br />

available entropy. If the specified size of this buffer is zero, this argument will be<br />

ignored. Note that if the buffer is larger than SPC_BLOCK_LEN (see Recipe 5.5) any<br />

additional data in the buffer will be ignored. Therefore, if you have sparse<br />

amounts of entropy, compress it to the right length before calling this function, as<br />

discussed in Recipe 11.16.<br />

Length of the extra seed buffer in bytes. It may be specified as zero to indicate<br />

that there is no extra seed data.<br />

Once you have an instantiated generator, you can get cryptographically strong<br />

pseudo-random data from it with the following function:<br />

unsigned char *spc_bcprng_rand(SPC_BCPRNG_CTX *prng, unsigned char *buf, size_t l);<br />

This function has the following arguments:<br />

prng<br />

Pointer to the generator’s context object.<br />

buf<br />

Buffer into which the random data will be written.<br />

l<br />

Number of bytes that should be placed into the output buffer.<br />

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