Răsfoiți Sursa

* ESPNOW: now using hardware RNG for radio_new_identity()

Scott Powell 1 an în urmă
părinte
comite
00f0bb7471

+ 1 - 1
src/helpers/esp32/ESPNOWRadio.cpp

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

+ 1 - 1
src/helpers/esp32/ESPNOWRadio.h

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

+ 1 - 1
variants/generic_espnow/platformio.ini

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

+ 12 - 2
variants/generic_espnow/target.cpp

@@ -11,7 +11,8 @@ ESP32RTCClock rtc_clock;
 bool radio_init() {
   rtc_clock.begin();
 
-  // NOTE: radio_driver.begin() is called by Dispatcher::begin(), so not needed here
+  radio_driver.init();
+
   return true;  // success
 }
 
@@ -27,7 +28,16 @@ void radio_set_tx_power(uint8_t 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() {
-  StdRNG  rng;  // TODO: need stronger True-RNG here
+  ESP_RNG rng;
   return mesh::LocalIdentity(&rng);  // create new random identity
 }