mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-09-26 14:07:58 +00:00
Fix fallback RNG seed for recoverable Companions
This commit is contained in:
@@ -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 <esp_heap_caps.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_CC310_HW_CRYPTO
|
||||
#include <helpers/NRF52Crypto.h>
|
||||
#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<uint8_t*>(&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();
|
||||
|
||||
Reference in New Issue
Block a user