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.

For this reason, we think the full suite of FIPS 140-1 tests is the way to go any time<br />

you really want to test whether an entropy source is producing good data, and it is a<br />

good idea to run these tests on startup, and then periodically, when feasible. You<br />

should always support the continuous test that FIPS 140-2 mandates whenever you<br />

are using hardware random number generators that could possibly be prone to disastrous<br />

failure, because it might help you detect such a failure.<br />

FIPS 140-1 power-up and on-demand tests<br />

The FIPS 140-1 standard specifies four statistical tests that operate on 20,000 consecutive<br />

bits of output (2,500 bytes).<br />

In the first test, the “Monobit” test, the number of bits set to 1 are counted. The test<br />

passes if the number of bits set to 1 is within a reasonable proximity to 10,000. The<br />

function spc_fips_monobit( ), implemented as follows, performs this test, returning 1<br />

on success, and 0 on failure.<br />

#define FIPS_NUMBYTES 2500<br />

#define FIPS_MONO_LOBOUND 9654<br />

#define FIPS_MONO_HIBOUND 10346<br />

/* For each of the 256 possible bit values, how many 1 bits are set? */<br />

static char nb_tbl[256] = {<br />

0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3,<br />

4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4,<br />

4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2,<br />

3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5,<br />

4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3,<br />

4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3,<br />

3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5,<br />

6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,<br />

4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5,<br />

6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8<br />

};<br />

int spc_fips_monobit(unsigned char data[FIPS_NUMBYTES]) {<br />

int i, result;<br />

for (i = result = 0; i < FIPS_NUMBYTES; i++)<br />

result += nb_tbl[data[i]];<br />

return (result > FIPS_MONO_LOBOUND && result < FIPS_MONO_HIBOUND);<br />

}<br />

The second test is the “Poker” test, in which the data is broken down into consecutive<br />

4-bit values to determine how many times each of the 16 possible 4-bit values appears.<br />

The square of each result is then added together and scaled to see whether the result<br />

falls in a particular range. If so, the test passes. The function spc_fips_poker( ), implemented<br />

as follows, performs this test, returning 1 on success and 0 on failure:<br />

#define FIPS_NUMBYTES 2500<br />

#define FIPS_POKER_LOBOUND 1.03<br />

Statistically Testing Random Numbers | 617<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!