Microchip developed the RNG90 chip per NIST specifications and certified the device working with a NIST-certified laboratory. The chip uses a physical non-deterministic noise source (NRBG producing an entropy bit stream) seeding a deterministic algorithm (DRBG). It generates a 256-bit random number that has a security strength of 128 bits each time the Random command is executed.
The Arduino code works, but is probably not the best way to generate 32 bytes of random numbers. The first execution of the random command excludes the wire.write of the i2c-address (0x40). The second run of the random command the wire.write 0x40 is included and that produces the 32 bytes output. Why? I don't know. I also discard the first byte being 35 (0x23) each time around.
>>> Arduino Uno code to read rng90 microchip <<<
The next arduino sketch uses the same hardware setup, but the code generates random numbers using the watchdog timer interrupt and combines the output with the numbers of the rng90 applying XOR. The watchdog timer has a different oscillator (128KHz) than the other timers. It also seems to be less accurate. The timer's drift produces randomness, especially looking at the lower byte of timer TCNT1.
I saw the writing to file gets slower over time, because after every close datafile a new open datafile has to find the end of a large file. It works better not closing the file at all, but just flush the data after writing a line.
do { char c = n % base; n /= base; *--str = c < 10 ? c + '0' : c + 'A' - 10; cnt++; // added } while(n); // added if (base == 2) { while (cnt++ % 8) *--str = '0'; } else if (base == 16) { if (cnt++ % 2) *--str = '0'; }>>> Arduino Nano serial output <<<
NIST Computer Security Resource Center
offers a statistical test suite for the validation of Random Number Generators and Pseudo Random Number Generators for Cryptographic Applications.
Link to the software sts-2_1_2.zip
Link to the documentation pdf (including installation & usage Chapter 5)
Image is just an illustration.
Next section is part of "1.1.5 Testing" of the above mentioned documentation.
Statistical hypothesis testing is a conclusion-generation procedure that has two possible outcomes, either accept H0 (the data is random) or accept Ha (the data is non-random). The following 2 by 2 table relates the true (unknown) status of the data at hand to the conclusion arrived at using the testing procedure.
True situation | Conclusion | |
---|---|---|
Accept H0 | Accept Ha (reject H0) | |
Data is random (H0 is true) | No error | Type I error |
Data is not random (Ha is true) | Type II error | No error |
#include <stdio.h> #include "unif01.h" #include "bbattery.h" FILE *input_file; unsigned long cnt=0; unsigned int file_random(void) { unsigned int num; if (fscanf(input_file, "%u", &num) != 1) { // If we reach end of file, rewind to the beginning rewind(input_file); fscanf(input_file, "%u", &num); } cnt++; return num; } unif01_Gen *create_file_generator(const char *filename) { input_file = fopen(filename, "r"); if (input_file == NULL) { printf("Error opening file %s\n", filename); return NULL; } return unif01_CreateExternGenBits("File Random Number Generator", file_random); } int main() { unif01_Gen *gen = create_file_generator("my_random_numbers.txt"); if (gen == NULL) return 1; // Run the Small Crush battery of tests bbattery_SmallCrush(gen); // Optionally, run more extensive test batteries: // bbattery_Crush(gen); // bbattery_BigCrush(gen); // Clean up unif01_DeleteExternGenBits(gen); printf("numbers read: %lu\n", cnt); fclose(input_file); return 0; } To compile the file "file_rng_test.c" useWhen you see "eps" in TestU01 results, it means the random number generator being tested performed very poorly on that specific test, showing strong statistical patterns or biases that a high-quality RNG shouldn't exhibit.
gcc -o file_rng_test file_rng_test.c -ltestu01 -lprobdist -lmylib -lm Next run the file ./file_rng_test