diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 35a89380..9121059e 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -13,6 +13,7 @@ #include "esp_bt.h" #include "esp_pm.h" #include "esp_sleep.h" +#include "esp_system.h" #if defined(CONFIG_PM_ENABLE) && CONFIG_PM_ENABLE #define COMPANION_IDF_PM_AVAILABLE 1 #else @@ -29,6 +30,10 @@ #include #endif #endif + +#ifdef USE_CC310_HW_CRYPTO +#include +#endif // Believe it or not, this std C function is busted on some platforms! static uint32_t _atoi(const char* sp) { uint32_t n = 0; @@ -435,6 +440,21 @@ static bool companion_radio_available = true; static unsigned long companion_radio_retry_at = 0; static const unsigned long COMPANION_RADIO_RETRY_MS = 60000UL; +static uint32_t companionFallbackRngSeed() { +#if defined(ESP32_PLATFORM) + return esp_random(); +#else + uint32_t seed = micros(); +#if defined(NRF52_PLATFORM) + seed ^= NRF_FICR->DEVICEID[0] ^ NRF_FICR->DEVICEID[1]; +#endif +#ifdef USE_CC310_HW_CRYPTO + mesh::mixCC310Random(reinterpret_cast(&seed), sizeof(seed)); +#endif + return seed; +#endif +} + static void serviceCompanionRadioRecovery() { if (companion_radio_available || (long)(millis() - companion_radio_retry_at) < 0) return; @@ -2768,7 +2788,7 @@ void setup() { companion_radio_available = radio_available; companion_radio_retry_at = millis() + COMPANION_RADIO_RETRY_MS; fast_rng.begin(radio_available ? radio_driver.getRngSeed() - : radio_fallback_rng_seed()); + : companionFallbackRngSeed()); #ifdef DISPLAY_CLASS if (!radio_available && disp != NULL) { disp->startFrame();