• TESTU01 source for PRNG test reading from STDIN

    From Karl.Frank@21:1/5 to All on Mon May 1 20:46:34 2017
    I have uploaded a short ANSI-C source code that can test the output of
    any PRNG using the TESTU01 test battery by reading in 32bit values from
    STDIN. This way it's not necessary to implement your PRNG algorithm into TESTU01 because you can simply pipe the output of any PRNG written in
    the programming language you favour to the test battery.

    Perhaps someone might find it useful. Comments are welcome.


    At http://www.freecx.co.uk/crypto/cryptanalysis/TestTools/TestU01/
    you find all needed sources as well as some example PRNG source codes.

    The original source code and explanation of TestU01 used in my
    implementation is located here
    http://simul.iro.umontreal.ca/testu01/tu01.html


    Running the given example PRNGs mentioned above against TESTU01_stdin we
    get the following results.

    As expected a very basic LCG PRNG fails badly just the SmallCrush test

    ./LCG_stdio 0x2ddd6a2c 0xfffffffe | ./TestU01_stdin -s

    ========= Summary results of SmallCrush =========

    Version: TestU01 1.2.3
    Generator: 32-bit stdin
    Number of statistics: 15
    Total CPU time: 00:00:24.80
    The following tests gave p-values outside [0.001, 0.9990]:
    (eps means a value < 1.0e-300):
    (eps1 means a value < 1.0e-15):

    Test p-value
    ----------------------------------------------
    1 BirthdaySpacings eps
    2 Collision 1 - eps1
    3 Gap eps
    4 SimpPoker eps
    5 CouponCollector eps
    7 WeightDistrib eps
    8 MatrixRank eps
    9 HammingIndep eps
    10 RandomWalk1 H eps
    10 RandomWalk1 M eps
    10 RandomWalk1 J 7.8e-7
    10 RandomWalk1 R eps
    10 RandomWalk1 C eps
    ----------------------------------------------
    All other tests were passed



    Not that terribly bad as the above LCG does the systems Rand PRNG on the SmallCrush test

    ./C_Rand_stdio 0x2ddd6a2c 0xfffffffe | ./TestU01_stdin -s

    ========= Summary results of SmallCrush =========

    Version: TestU01 1.2.3
    Generator: 32-bit stdin
    Number of statistics: 15
    Total CPU time: 00:00:25.71
    The following tests gave p-values outside [0.001, 0.9990]:
    (eps means a value < 1.0e-300):
    (eps1 means a value < 1.0e-15):

    Test p-value
    ----------------------------------------------
    1 BirthdaySpacings eps
    2 Collision eps
    6 MaxOft eps
    6 MaxOft AD 1 - eps1
    10 RandomWalk1 H eps
    10 RandomWalk1 M eps
    10 RandomWalk1 J eps
    10 RandomWalk1 R eps
    10 RandomWalk1 C eps
    ----------------------------------------------
    All other tests were passed



    While a good PRNG however clearly pass the SmallCrush test

    ./bcd32_keystream 0x2ddd6a2c 0xfffffffe | ./TestU01_stdin -s


    ========= Summary results of SmallCrush =========

    Version: TestU01 1.2.3
    Generator: 32-bit stdin
    Number of statistics: 15
    Total CPU time: 00:00:26.17

    All tests were passed


    --
    cHNiMUBACG0HAAAAAAAAAAAAAABIZVbDdKVM0w1kM9vxQHw+bkLxsY/Z0czY0uv8/Ks6WULxJVua zjvpoYvtEwDVhP7RGTCBVlzZ+VBWPHg5rqmKWvtzsuVmMSDxAIS6Db6YhtzT+RStzoG9ForBcG8k G97Q3Jml/aBun8Kyf+XOBHpl5gNW4YqhiM0=

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Outerbridge@21:1/5 to Karl.Frank on Sun May 7 02:25:31 2017
    On 2017-05-01 18:46:34 +0000, Karl.Frank said:

    I have uploaded a short ANSI-C source code that can test the output of
    any PRNG using the TESTU01 test battery by reading in 32bit values from STDIN.

    This is pretty handy, especially if one already has TestU01 installed.

    The only suggestion I have is to add a warning about how many samples are required for each test: the tests will always fail without enough input.

    For example, in my own testing I found that the SmallCrush test consumed 226969476 32-bit samples; the Crush test wanted 33842890314; and the BigCrush test chewed through 357112958428 32-bit samples.

    Otherwise, pretty neat. Thanks.
    __outer

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Karl.Frank@21:1/5 to Richard Outerbridge on Mon May 8 14:08:58 2017
    On 07.05.17 08:25, Richard Outerbridge wrote:
    On 2017-05-01 18:46:34 +0000, Karl.Frank said:

    I have uploaded a short ANSI-C source code that can test the output of
    any PRNG using the TESTU01 test battery by reading in 32bit values from
    STDIN.

    This is pretty handy, especially if one already has TestU01 installed.

    The only suggestion I have is to add a warning about how many samples are required for each test: the tests will always fail without enough input.

    For example, in my own testing I found that the SmallCrush test consumed 226969476 32-bit samples; the Crush test wanted 33842890314; and the
    BigCrush
    test chewed through 357112958428 32-bit samples.

    Otherwise, pretty neat. Thanks.
    __outer


    Many thanks for you kind feedback, I'm pleased that you find it useful.

    The problem you mentioned on how many samples to pipe in is not an easy
    to estimate parameter. In the source code examples I suggested that one
    should at least pass 4294967294 (0xfffffffe) samples

    ./LCG_stdio 0x2ddd6a2c 0xfffffffe | ./TestU01_stdin -s

    But I figured out right now that even 72057594037927934 samples are not
    enough if you run the Crush test on the sample LCG_stdio. After quite a
    while TestU01 will get stuck with the error


    ./C_Rand_stdio 0x2ddd6a2c 0xfffffffffffffe | ./TestU01_stdin -c

    [...]

    32-bit stdin


    snpair_ClosePairs test:
    -----------------------------------------------
    N = 10, n = 2000000, r = 0, t = 2, p = 0, m = 30, Torus = TRUE

    ********* WARNING in file snpair.c on line 294
    ********* res->NumClose > 50000


    As it sems a PRNG that will not survice the SmallCrush is not worth a
    Crush test run, let alone BigCrush.


    Although this Crush test got through

    ./bcd32_keystream 2ddd6a2c 0xfffffffffffffe | ./TestU01_stdin -c

    finished processing and analysing 33842649805 samples.

    If have added a sample counter to the source TestU01_stdin.c so finally
    one can read how many samples actually were needed for a certain PRNG
    and test run.


    Depending on the implementation of RAND for example one might get
    different amounts of samples, like this summary below show

    ========= Summary results of SmallCrush =========

    (x86_64)
    ========

    ./C_Rand_stdio 0x2ddd6a2c 0xfffffffe | ./TestU01_stdin -s
    Total processed 32Bit Samples = 226934364

    ./LCG_stdio 0x2ddd6a2c 0xfffffffe | ./TestU01_stdin -s
    Total processed 32Bit Samples = 218199913

    ./bcd32_keystream 2ddd6a2c 0xfffffffe | ./TestU01_stdin -s
    Total processed 32Bit Samples = 226901346



    (i686)
    ======
    ./C_Rand_stdio 0x2ddd6a2c 0xfffffffe | ./TestU01_stdin -s
    Total processed 32Bit Samples = 226792340

    ./LCG_stdio 0x2ddd6a2c 0xfffffffe | ./TestU01_stdin -s
    Total processed 32Bit Samples = 218199913

    ./bcd32_keystream 2ddd6a2c 0xfffffffe | ./TestU01_stdin -s
    Total processed 32Bit Samples = 226901346



    In regards of installing TestU01 in the first place I have added some
    very basic instruction on top of the updated source code, which
    essentially read

    Compile Instructions
    =====================
    unzip TestU01.zip

    cd TestU01-1.2.3/

    ./configure --prefix=/opt/testu01/
    make && make install

    now add to your ~/.profile or ~/.bashrc

    # TestU01
    export LD_LIBRARY_PATH=/opt/testu01/lib:${LD_LIBRARY_PATH}
    export LIBRARY_PATH=/opt/testu01/lib:${LIBRARY_PATH}
    export C_INCLUDE_PATH=/opt/testu01/include:${C_INCLUDE_PATH}

    now activate by

    source ~/.profile or ~/.bashrc

    I prefer /opt/testu01/ as prefix because in case I'd like to delete
    TestU01 for same reason later I need just remove the testu01 folder in /opt


    By the way, on which PRNG did you perform the test runs?
    Did it survive SmallCrush, Crush and BigCrush?

    Updated source code over here http://www.freecx.co.uk/crypto/cryptanalysis/TestTools/TestU01/

    or here
    http://paste.debian.net/931418

    Cheers,
    Karl-Uwe




    --
    cHNiMUBACG0HAAAAAAAAAAAAAABIZVbDdKVM0w1kM9vxQHw+bkLxsY/Z0czY0uv8/Ks6WULxJVua zjvpoYvtEwDVhP7RGTCBVlzZ+VBWPHg5rqmKWvtzsuVmMSDxAIS6Db6YhtzT+RStzoG9ForBcG8k G97Q3Jml/aBun8Kyf+XOBHpl5gNW4YqhiM0=

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Outerbridge@21:1/5 to Karl.Frank on Mon May 8 17:51:55 2017
    On 2017-05-08 12:08:58 +0000, Karl.Frank said:

    On 07.05.17 08:25, Richard Outerbridge wrote:
    On 2017-05-01 18:46:34 +0000, Karl.Frank said:

    I have uploaded a short ANSI-C source code that can test the output of
    any PRNG using the TESTU01 test battery by reading in 32bit values from
    STDIN.

    This is pretty handy, especially if one already has TestU01 installed.

    [....]

    The problem you mentioned on how many samples to pipe in is not an easy
    to estimate parameter.

    [....]

    Yes, you're right, the input requirements of the TestU01 Crush tests seem
    to vary according to the actual contents of the stream under test. So the limit would seem to be how many samples (4,294,967,295 single bytes or even better 17,179,869,180 bytes as 4,294,967,295 32Bit chunks) you can instruct
    the generator to produce.

    By the way, on which PRNG did you perform the test runs?
    Did it survive SmallCrush, Crush and BigCrush?

    On my own, of course :) And yes, after 18 hours, it eventually did. This
    was using a bespoke interface (the generator was integrated with the tests). __outer

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Karl.Frank@21:1/5 to Richard Outerbridge on Tue May 9 22:39:00 2017
    On 08.05.17 23:51, Richard Outerbridge wrote:
    On 2017-05-08 12:08:58 +0000, Karl.Frank said:

    On 07.05.17 08:25, Richard Outerbridge wrote:
    On 2017-05-01 18:46:34 +0000, Karl.Frank said:

    I have uploaded a short ANSI-C source code that can test the output of >>>> any PRNG using the TESTU01 test battery by reading in 32bit values from >>>> STDIN.

    This is pretty handy, especially if one already has TestU01 installed.

    [....]

    The problem you mentioned on how many samples to pipe in is not an easy
    to estimate parameter.

    [....]

    Yes, you're right, the input requirements of the TestU01 Crush tests seem
    to vary according to the actual contents of the stream under test. So the limit would seem to be how many samples (4,294,967,295 single bytes or even better 17,179,869,180 bytes as 4,294,967,295 32Bit chunks) you can instruct the generator to produce.

    I figured out that passing 0xfffffffe as 32bit samples for a SmallCrush
    and 0xfffffffffffffe for Crush should suffice to run both tests with a
    piped input. TestU01_stdin simply stops when all needed samples are
    processed and analysed. Yet I suppose 0xfffffffffffffffe samples might
    be needed for the BigCrush.

    The recently mentioned error origin to the fact that the machine running
    the Crush test does not has sufficient RAM.

    snpair_ClosePairs test:
    -----------------------------------------------
    N = 10, n = 2000000, r = 0, t = 2, p = 0, m = 30, Torus = TRUE

    ********* WARNING in file snpair.c on line 294
    ********* res->NumClose > 50000

    On a quick check it becomes evident that the Crush test consumes up to
    800MB of RAM and round about 750MB virtual Memory. Not yet tested the
    RAM needed for BigCrush.


    By the way, on which PRNG did you perform the test runs?
    Did it survive SmallCrush, Crush and BigCrush?

    On my own, of course :) And yes, after 18 hours, it eventually did. This
    was using a bespoke interface (the generator was integrated with the
    tests).
    __outer

    Well, essentially one could easily replace the function stdin32bit() on
    top of the source code with his own PRNG algorithm. That's what I did in
    the first place when publishing my PRNG algorithms alongside the
    TestU01 results. But piping the keystream is more flexible, for example
    if you like to check the randomness quality of a stream cipher or even a
    hash function ;-)

    Did you already publish your PRNG algorithm?



    --
    cHNiMUBACG0HAAAAAAAAAAAAAABIZVbDdKVM0w1kM9vxQHw+bkLxsY/Z0czY0uv8/Ks6WULxJVua zjvpoYvtEwDVhP7RGTCBVlzZ+VBWPHg5rqmKWvtzsuVmMSDxAIS6Db6YhtzT+RStzoG9ForBcG8k G97Q3Jml/aBun8Kyf+XOBHpl5gNW4YqhiM0=

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Outerbridge@21:1/5 to Karl.Frank on Sat May 13 19:29:24 2017
    On 2017-05-09 20:39:00 +0000, Karl.Frank said:

    On 08.05.17 23:51, Richard Outerbridge wrote:
    On 2017-05-08 12:08:58 +0000, Karl.Frank said:

    On 07.05.17 08:25, Richard Outerbridge wrote:
    On 2017-05-01 18:46:34 +0000, Karl.Frank said:

    [....]

    By the way, on which PRNG did you perform the test runs?
    Did it survive SmallCrush, Crush and BigCrush?

    On my own, of course :) And yes, after 18 hours, it eventually did. This
    was using a bespoke interface (the generator was integrated with the
    tests).
    __outer

    Well, essentially one could easily replace the function stdin32bit() on
    top of the source code with his own PRNG algorithm. That's what I did in
    the first place when publishing my PRNG algorithms alongside the
    TestU01 results. But piping the keystream is more flexible, for example
    if you like to check the randomness quality of a stream cipher or even a
    hash function ;-)

    Did you already publish your PRNG algorithm?

    It's been exposed for public ridicule, yes. Send me an email, why not?
    __outer

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)