From d0cc4dd2c9b23e326eb52fc87b7d43cce9bba473 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Fri, 30 Apr 2021 23:01:08 -0700 Subject: [PATCH] use the radio RSSI for a source... we may want to shorten this as it takes 3-4 seconds to gather all this... need to add a blinking light to this so it's clear that it's still starting.. --- main.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index 76b492f..6984274 100644 --- a/main.c +++ b/main.c @@ -182,6 +182,26 @@ process_line(char *start, char *end) usb_printf("line: %.*s", end - start, start); } +/* + * Seed the randomness from the radio. This is not a great + * seed, and is hard to gauge how much randomness is really + * there. Assuming about 1 bit per 8 bits looks pretty safe, + * so add 256 * 8 / 32 words. + */ +static void +radio_seed_rng(void) +{ +#if 1 + uint32_t v; + int i; + + for (i = 0; i < 256 * 8 / 32; i++) { + v = Radio.Random(); + strobe_seed_prng((uint8_t *)&v, sizeof v); + } +#endif +} + int main(void) { @@ -191,6 +211,10 @@ main(void) BoardInitMcu(); + Radio.Init(&revents); + + radio_seed_rng(); + strobe_rng_save(); /* turn on LED */ @@ -206,17 +230,8 @@ main(void) usb_printf("\r\n"); #endif - Radio.Init(&revents); - uint32_t v; - v = Radio.Random(); - usb_printf("rr: %#x\r\n", v); - v = Radio.Random(); - usb_printf("rr: %#x\r\n", v); - v = Radio.Random(); - usb_printf("rr: %#x\r\n", v); - usb_printf("gs: %#x\r\n", Radio.GetStatus()); usb_printf("set modem\r\n");