From 5571c8809c95b9a727ad640b0b89e76d228f1ba9 Mon Sep 17 00:00:00 2001 From: Mickey Malone Date: Fri, 12 Feb 2021 07:34:15 -0600 Subject: [PATCH] Tried using srand with rand to achieve more randomness. `sudo cat /dev/pico_rng | rngtest -c 1000` still says that it is not even close to being good enough. Although, if we feed this data into the kernel with the other data sources it should be FIPS 140-2 compliant. By itself it is not. --- firmware/pico_rng.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/firmware/pico_rng.c b/firmware/pico_rng.c index 0c13090..1398a5e 100644 --- a/firmware/pico_rng.c +++ b/firmware/pico_rng.c @@ -5,6 +5,7 @@ */ #include +#include // Pico #include "pico/stdlib.h" @@ -563,6 +564,23 @@ void get_random_data(char *buf, uint16_t len) { memcpy(&buf[i-1], (void*)&adc_result, 2); } + /** + * In an attempt to make the rng even more random this will slow down the amount of data the + * pico can generate. It appears to be more random, but not good enough for FIPS 140-2. + **/ + /** + //Use the ADC as a seed to the arm gnu stdlib random number generator + srand((int)(adc_read() | (adc_read() << 16))); + + memset(buf, 0, len); + int rand_result; + for(i = 0; i <= len-4; i=i+4) + { + rand_result = rand(); + memcpy(&buf[i], (void*)&rand_result, 4); + } + **/ + gpio_put(25, 0); }