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.

Most simpler compression methods are not going to do as good a job at preserving<br />

entropy. For example, suppose that your compression function is simply XOR. More<br />

concretely, suppose you need a 128-bit seed, and you XOR data in 16-byte chunks<br />

into a single buffer. Suppose also that you believe you have collected 128 bits of<br />

entropy from numerous calls to a 128-bit timestamp operation.<br />

In any particular timestamp function, all of the entropy is going to live in a few of the<br />

least significant bits. Now suppose that only two or three of those bits are likely to<br />

contain any entropy. The XOR-everything strategy will leave well over 120 bits of the<br />

result trivial to guess. The remaining eight bits can be attacked via brute force.<br />

Therefore, even if the input had 128 bits of entropy, the XOR-based compression<br />

algorithm destroyed most of the entropy.<br />

SHA1 is good for these purposes. See Recipe 6.5 for how to use SHA1.<br />

See Also<br />

Recipes 6.5, 11.19<br />

11.17 Getting Entropy at Startup<br />

<strong>Problem</strong><br />

You want to be able to seed a cryptographic pseudo-random number generator<br />

securely as soon as a machine boots, without having to wait for interaction from the<br />

user or other typical sources of entropy.<br />

Solution<br />

If you have never been able to seed the generator securely, prompt for entropy on<br />

install or first use (see Recipes 11.20 and 11.21).<br />

Otherwise, before shutting down the generator, have it output enough material to<br />

reseed itself to a file located in a secure part of the filesystem. The next time the generator<br />

starts, read the seed file and use the data to reseed, as discussed in Recipe 11.6.<br />

Discussion<br />

It can take a noticeable amount of time for a PRNG to gather enough entropy that it<br />

is safe to begin outputting random data. On some systems with /dev/random as the<br />

entropy source, users could be forced to sit around indefinitely, not knowing how to<br />

get more entropy into the system.<br />

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