iaik.security.random
Class FIPS140Test

java.lang.Object
  |
  +--iaik.security.random.FIPS140Test

public class FIPS140Test
extends Object

This class tests a Random number generator for randomness using statstical tests as defined in FIPS 140-1. Note that this is a statistical test only, it does not say anything about the predictability (and hence cryptographic strength) of a random number generator. FIPS 140-1 specifies four tests that are to be performed on 20000 bits of pseudo random output.

First generate a FIPS140Test object passing an instance of the Random object to be tested. Then, either call startTests() to conduct all the tests or call the individual tests yourself. You must first have the random bits generated by calling initTests(), startTests() does that automatically each time you call it.

NOTE: This *may* crash on the Symantec Visual Cafe 2.1 JIT, but it works fine with 2.5.

Version:
File Revision 13

Constructor Summary
FIPS140Test(InputStream randStream)
          Creates a FIPS140Test object that reads the data to be examined from the given stream.
FIPS140Test(Random random)
          Creates a FIPS140Test object that examines the given Random object.
 
Method Summary
 void initTests()
          Init the tests by generating the necessary amount of test data (20000 bits).
 boolean longRunsTest()
          Run the long runs test.
 boolean monoBitTest()
          Run the monobit test.
 boolean pokerTest()
          Run the poker test.
 boolean runsTest()
          Run the runs test.
 boolean runTests()
          Deprecated. use startTests() instead.
 void setDebugStream(PrintStream debugStream)
          Send debug output to the given stream.
 void setDebugStream(PrintWriter debugStream)
          Send debug output to the given writer.
 boolean startTests()
          Run all the tests.
 boolean startTests(boolean forceAll)
          Always run all the tests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FIPS140Test

public FIPS140Test(Random random)
Creates a FIPS140Test object that examines the given Random object. As SecureRandom is a subclass of Random, it can of course be used as well.

FIPS140Test

public FIPS140Test(InputStream randStream)
Creates a FIPS140Test object that reads the data to be examined from the given stream.
Method Detail

setDebugStream

public void setDebugStream(PrintStream debugStream)
Send debug output to the given stream. Set to null to disable debug output.

setDebugStream

public void setDebugStream(PrintWriter debugStream)
Send debug output to the given writer. Set to null to disable debug output.

monoBitTest

public boolean monoBitTest()
Run the monobit test. The monobit tests checks if there are the same amount of ones and zeros in the PRNG's output.

runsTest

public boolean runsTest()
Run the runs test. It verifies that the number of runs of length 1, 2, 3, 4, 5, and longer runs are within limits.

longRunsTest

public boolean longRunsTest()
Run the long runs test. This just checks that there are no runs longer than a maximum length (FIPS defines 34).

pokerTest

public boolean pokerTest()
Run the poker test. It checks if all possible 4 bit patterns occur about the same as often.

initTests

public void initTests()
               throws RandomException
Init the tests by generating the necessary amount of test data (20000 bits).
Throws:
RandomException - if there was an error reading the data

runTests

public boolean runTests()
Deprecated. use startTests() instead.

This method is deprecated and will be removed in the next major release.

startTests

public boolean startTests()
Run all the tests. It stops as soon as one test fails. This method does everything, including generating the test bits. It's all you really need.

startTests

public boolean startTests(boolean forceAll)
Always run all the tests. If forceAll is true, this method will continue to run the tests even if an earlier test already failed. Otherwise it will return false as soon as one test failed.

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK