* ESPNOW: now using hardware RNG for radio_new_identity()

This commit is contained in:
Scott Powell
2025-04-24 10:59:01 +10:00
parent 10df19d3a3
commit 00f0bb7471
4 changed files with 15 additions and 5 deletions

View File

@@ -22,7 +22,7 @@ static void OnDataRecv(const uint8_t *mac, const uint8_t *data, int len) {
last_rx_len = len; last_rx_len = len;
} }
void ESPNOWRadio::begin() { void ESPNOWRadio::init() {
// Set device as a Wi-Fi Station // Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
// Long Range mode // Long Range mode

View File

@@ -9,7 +9,7 @@ protected:
public: public:
ESPNOWRadio() { n_recv = n_sent = 0; } ESPNOWRadio() { n_recv = n_sent = 0; }
void begin() override; void init();
int recvRaw(uint8_t* bytes, int sz) override; int recvRaw(uint8_t* bytes, int sz) override;
uint32_t getEstAirtimeFor(int len_bytes) override; uint32_t getEstAirtimeFor(int len_bytes) override;
void startSendRaw(const uint8_t* bytes, int len) override; void startSendRaw(const uint8_t* bytes, int len) override;

View File

@@ -19,7 +19,7 @@ build_flags =
; -D MESH_PACKET_LOGGING=1 ; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1 ; -D MESH_DEBUG=1
build_src_filter = ${esp32_base.build_src_filter} build_src_filter = ${esp32_base.build_src_filter}
+<helpers/esp32/ESPNowRadio.cpp> +<helpers/esp32/ESPNOWRadio.cpp>
+<../variants/generic_espnow> +<../variants/generic_espnow>
[env:Generic_ESPNOW_terminal_chat] [env:Generic_ESPNOW_terminal_chat]

View File

@@ -11,7 +11,8 @@ ESP32RTCClock rtc_clock;
bool radio_init() { bool radio_init() {
rtc_clock.begin(); rtc_clock.begin();
// NOTE: radio_driver.begin() is called by Dispatcher::begin(), so not needed here radio_driver.init();
return true; // success return true; // success
} }
@@ -27,7 +28,16 @@ void radio_set_tx_power(uint8_t dbm) {
radio_driver.setTxPower(dbm); radio_driver.setTxPower(dbm);
} }
// NOTE: as we are using the WiFi radio, the ESP_IDF will have enabled hardware RNG:
// https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/random.html
class ESP_RNG : public mesh::RNG {
public:
void random(uint8_t* dest, size_t sz) override {
esp_fill_random(dest, sz);
}
};
mesh::LocalIdentity radio_new_identity() { mesh::LocalIdentity radio_new_identity() {
StdRNG rng; // TODO: need stronger True-RNG here ESP_RNG rng;
return mesh::LocalIdentity(&rng); // create new random identity return mesh::LocalIdentity(&rng); // create new random identity
} }