@@ -307,14 +307,6 @@ class MyMesh : public BaseChatMesh, ContactVisitor {
307307 IdentityStore store (fs, " /identity" );
308308 #endif
309309 if (!store.load (" _main" , self_id, _prefs.node_name , sizeof (_prefs.node_name ))) { // legacy: node_name was from identity file
310- // Need way to get some entropy to seed RNG
311- Serial.println (" Press ENTER to generate key:" );
312- char c = 0 ;
313- while (c != ' \n ' ) { // wait for ENTER to be pressed
314- if (Serial.available ()) c = Serial.read ();
315- }
316- ((StdRNG *)getRNG ())->begin (millis ());
317-
318310 self_id = mesh::LocalIdentity (getRNG ()); // create new random identity
319311 int count = 0 ;
320312 while (count < 10 && (self_id.pub_key [0 ] == 0x00 || self_id.pub_key [0 ] == 0xFF )) { // reserved id hashes
@@ -559,23 +551,32 @@ void setup() {
559551 Serial.begin (115200 );
560552
561553 board.begin ();
554+ mesh::initHardwareRNG ();
562555
563- if (!radio_init ()) { halt (); }
564-
565- fast_rng.begin (radio_get_rng_seed ());
556+ FILESYSTEM* fs;
566557
567558#if defined(NRF52_PLATFORM)
568559 InternalFS.begin ();
569- the_mesh.begin (InternalFS);
560+ fs = &InternalFS;
561+ fast_rng.attachPersistence (InternalFS, " /seed.rng" );
570562#elif defined(RP2040_PLATFORM)
571563 LittleFS.begin ();
572- the_mesh.begin (LittleFS);
564+ fs = &LittleFS;
565+ fast_rng.attachPersistence (LittleFS, " /seed.rng" );
573566#elif defined(ESP32)
574567 SPIFFS.begin (true );
575- the_mesh.begin (SPIFFS);
568+ fs = &SPIFFS;
569+ fast_rng.attachPersistence (SPIFFS, " /seed.rng" );
576570#else
577571 #error "need to define filesystem"
578572#endif
573+ fast_rng.setRadioEntropySource (radio_driver);
574+ fast_rng.begin ();
575+ mesh::deinitHardwareRNG ();
576+
577+ if (!radio_init ()) { halt (); }
578+
579+ the_mesh.begin (*fs);
579580
580581 radio_set_params (the_mesh.getFreqPref (), LORA_BW, LORA_SF, LORA_CR);
581582 radio_set_tx_power (the_mesh.getTxPowerPref ());
0 commit comments