From b8b2e6ab7f709b570e0eaec039e0a68aa5836bf9 Mon Sep 17 00:00:00 2001 From: Chad Attermann Date: Wed, 5 Jun 2024 16:26:08 -0600 Subject: [PATCH] WIP: Added a little RNG entropy for nrf52 installs --- platformio.ini | 2 +- src/Reticulum.cpp | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/platformio.ini b/platformio.ini index 75d33a1..4695013 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,7 +16,7 @@ platform = native build_flags = -std=c++11 -Wall - -Wextra + ;-Wextra -Wno-missing-field-initializers -Wno-format -Wno-unused-parameter diff --git a/src/Reticulum.cpp b/src/Reticulum.cpp index eb9c883..650c57d 100644 --- a/src/Reticulum.cpp +++ b/src/Reticulum.cpp @@ -3,11 +3,12 @@ #include "Transport.h" #include "Log.h" +//#include #include #ifdef ARDUINO +#include //#include -//#include #endif using namespace RNS; @@ -40,18 +41,43 @@ Reticulum::Reticulum() : _object(new Object()) { // Initialkize random number generator RNG.begin("Reticulum"); + extreme("RNG pre-seed random value: " + std::to_string(Cryptography::randomnum())); #ifdef ARDUINO - // Stir in the Ethernet MAC address. - //byte mac[6]; - //Ethernet.begin(mac); - // WiFi.macAddress(mac); - //RNG.stir(mac, sizeof(mac)); - int seed = analogRead(0); +/* + uint64_t testseed = 0; + uint64_t value; + + value = analogRead(A0); + extreme("A0 value: " + std::to_string(value)); + //RNG.stir((uint8_t*)&value, sizeof(value)); + testseed |= value; + + value = analogRead(A3); + extreme("A3 value: " + std::to_string(value)); + //RNG.stir((uint8_t*)&value, sizeof(value)); + testseed |= (value << 16); + + value = analogRead(A4); + extreme("A4 value: " + std::to_string(value)); + //RNG.stir((uint8_t*)&value, sizeof(value)); + testseed |= (value << 32); + + value = analogRead(A5); + extreme("A5 value: " + std::to_string(value)); + //RNG.stir((uint8_t*)&value, sizeof(value)); + testseed |= (value << 48); + + extreme("RNG testseed: " + std::to_string(testseed)); +*/ + + // Stir in some entropy (currently only adding entropy on nrf52 platform) + uint64_t seed = ((uint64_t)analogRead(A5) << 48) | ((uint64_t)analogRead(A4) << 32) | ((uint64_t)analogRead(A3) << 16) | (uint64_t)analogRead(A0); + extreme("RNG seed: " + std::to_string(seed)); RNG.stir((uint8_t*)&seed, sizeof(seed)); - - // Add the noise source to the list of sources known to RNG. + + // Add a noise source to the list of sources known to RNG. //RNG.addNoiseSource(noise); #endif