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.

}<br />

int cur_val, i, j, runsz;<br />

unsigned char curr;<br />

for (cur_val = i = runsz = 0; i < FIPS_NUMBYTES; i++) {<br />

curr = data[i];<br />

for (j = 0; j < 8; j++) {<br />

/* Check to see if the current bit is the same as the last one */<br />

if ((curr & 0x01) ^ cur_val) {<br />

/* The bits are different. A run is over, and a new run of 1 has begun */<br />

if (runsz >= FIPS_LONGRUN) return 0;<br />

if (runsz > 6) runsz = 6;<br />

runs[cur_val][runsz]++;<br />

runsz = 1;<br />

cur_val = (cur_val + 1) & 1; /* Switch the value. */<br />

} else runsz++;<br />

curr >>= 1;<br />

}<br />

}<br />

return (runs[0][1] > FIPS_RUNS_1_LO && runs[0][1] < FIPS_RUNS_1_HI &&<br />

runs[0][2] > FIPS_RUNS_2_LO && runs[0][2] < FIPS_RUNS_2_HI &&<br />

runs[0][3] > FIPS_RUNS_3_LO && runs[0][3] < FIPS_RUNS_3_HI &&<br />

runs[0][4] > FIPS_RUNS_4_LO && runs[0][4] < FIPS_RUNS_4_HI &&<br />

runs[0][5] > FIPS_RUNS_5_LO && runs[0][5] < FIPS_RUNS_5_HI &&<br />

runs[0][6] > FIPS_RUNS_6_LO && runs[0][6] < FIPS_RUNS_6_HI &&<br />

runs[1][1] > FIPS_RUNS_1_LO && runs[1][1] < FIPS_RUNS_1_HI &&<br />

runs[1][2] > FIPS_RUNS_2_LO && runs[1][2] < FIPS_RUNS_2_HI &&<br />

runs[1][3] > FIPS_RUNS_3_LO && runs[1][3] < FIPS_RUNS_3_HI &&<br />

runs[1][4] > FIPS_RUNS_4_LO && runs[1][4] < FIPS_RUNS_4_HI &&<br />

runs[1][5] > FIPS_RUNS_5_LO && runs[1][5] < FIPS_RUNS_5_HI &&<br />

runs[1][6] > FIPS_RUNS_6_LO && runs[1][6] < FIPS_RUNS_6_HI);<br />

The FIPS continuous output test<br />

The FIPS continuous output test requires that random number generators (which<br />

would include both entropy sources and PRNGs) have the data they are going to<br />

produce broken up into “blocks” of at least 16 bytes. If the generator has a “natural”<br />

block size of greater than 16 bytes, that should always get used. Otherwise,<br />

any size 16 bytes or greater can be used. We recommend never using blocks larger<br />

than 16 bytes (unless required) because the underlying generator uses larger blocks<br />

naturally. *<br />

This test collects the first block of output and never gives it to anyone. Instead, it is<br />

compared against the second block of output and thrown away. The second block<br />

may be output if it is not identical to the first block; otherwise, the system must fail.<br />

* Usually, entropy sources do not have a natural block size that large, if they have one at all (there is usually a<br />

somewhat artificial block size, such as the width of the memory you read to query the source).<br />

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