I'm not really interested in this PRNG. I'm more interested in understanding what it takes to fail the security threshold for cryptographic applications. I'm taking the C PRNG as an example.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
unsigned int random;
srand(1);
for (;;) {
random = rand();
fwrite(&random, sizeof random, 1, stdout);
}
}
Here's the summary of a small crush by TestU01:
========= Summary results of SmallCrush =========
Version: TestU01 1.2.3
Generator: crand
Number of statistics: 15
Total CPU time: 00:00:21.67
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 1.1e-14
2 Collision eps
3 Gap 4.2e-9
6 MaxOft eps
6 MaxOft AD 1 - eps1
7 WeightDistrib eps
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
Is this enough to make me steer clear from C's rand()
? What if it had failed only a single test?
rand()
isn't necessarily always the same algorithm, so even if it is found to be cryptographically safe on your current system it might not be on another system your code is later compile on. Never assume something has properties that it doesn't make any claim to have: the standards forrand()
make no claim or requirement for the algorithm used to meet any cryptographically relevant standard. – David Spillett Nov 15 '18 at 10:46