Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/companion_radio/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,10 @@ void MyMesh::begin(bool has_display) {
BaseChatMesh::begin();

if (!_store->loadMainIdentity(self_id)) {
self_id = radio_new_identity(); // create new random identity
self_id = mesh::LocalIdentity(getRNG()); // create new random identity
int count = 0;
while (count < 10 && (self_id.pub_key[0] == 0x00 || self_id.pub_key[0] == 0xFF)) { // reserved id hashes
self_id = radio_new_identity();
self_id = mesh::LocalIdentity(getRNG());
count++;
}
_store->saveMainIdentity(self_id);
Expand Down Expand Up @@ -911,8 +911,7 @@ void MyMesh::begin(bool has_display) {
if (_prefs.ble_pin == 0) {
#ifdef DISPLAY_CLASS
if (has_display && BLE_PIN_CODE == 123456) {
StdRNG rng;
_active_ble_pin = rng.nextInt(100000, 999999); // random pin each session
_active_ble_pin = getRNG()->nextInt(100000, 999999); // random pin each session
} else {
_active_ble_pin = BLE_PIN_CODE; // otherwise static pin
}
Expand Down
22 changes: 18 additions & 4 deletions examples/companion_radio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ void halt() {
while (1) ;
}

#ifndef PIO_UNIT_TESTING
void setup() {
Serial.begin(115200);

board.begin();
mesh::initHardwareRNG();

#ifdef DISPLAY_CLASS
DisplayDriver* disp = NULL;
Expand All @@ -123,12 +125,13 @@ void setup() {
}
#endif

if (!radio_init()) { halt(); }

fast_rng.begin(radio_get_rng_seed());

#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
InternalFS.begin();
fast_rng.attachPersistence(InternalFS, "/seed.rng");
fast_rng.setRadioEntropySource(radio_driver);
fast_rng.begin();
mesh::deinitHardwareRNG();
if (!radio_init()) { halt(); }
#if defined(QSPIFLASH)
if (!QSPIFlash.begin()) {
// debug output might not be available at this point, might be too early. maybe should fall back to InternalFS here?
Expand Down Expand Up @@ -158,6 +161,11 @@ void setup() {
the_mesh.startInterface(serial_interface);
#elif defined(RP2040_PLATFORM)
LittleFS.begin();
fast_rng.attachPersistence(LittleFS, "/seed.rng");
fast_rng.setRadioEntropySource(radio_driver);
fast_rng.begin();
mesh::deinitHardwareRNG();
if (!radio_init()) { halt(); }
store.begin();
the_mesh.begin(
#ifdef DISPLAY_CLASS
Expand All @@ -184,6 +192,11 @@ void setup() {
the_mesh.startInterface(serial_interface);
#elif defined(ESP32)
SPIFFS.begin(true);
fast_rng.attachPersistence(SPIFFS, "/seed.rng");
fast_rng.setRadioEntropySource(radio_driver);
fast_rng.begin();
mesh::deinitHardwareRNG();
if (!radio_init()) { halt(); }
store.begin();
the_mesh.begin(
#ifdef DISPLAY_CLASS
Expand Down Expand Up @@ -230,3 +243,4 @@ void loop() {
#endif
rtc_clock.tick();
}
#endif
20 changes: 15 additions & 5 deletions examples/kiss_modem/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,29 @@ void halt() {
}

void loadOrCreateIdentity() {
FILESYSTEM* fs;
#if defined(NRF52_PLATFORM)
InternalFS.begin();
fs = &InternalFS;
IdentityStore store(InternalFS, "");
#elif defined(ESP32)
SPIFFS.begin(true);
fs = &SPIFFS;
IdentityStore store(SPIFFS, "/identity");
#elif defined(RP2040_PLATFORM)
LittleFS.begin();
fs = &LittleFS;
IdentityStore store(LittleFS, "/identity");
store.begin();
#else
#error "Filesystem not defined"
#endif
rng.attachPersistence(*fs, "/seed.rng");

if (!store.load("_main", identity)) {
identity = radio_new_identity();
identity = mesh::LocalIdentity(&rng);
while (identity.pub_key[0] == 0x00 || identity.pub_key[0] == 0xFF) {
identity = radio_new_identity();
identity = mesh::LocalIdentity(&rng);
}
store.save("_main", identity);
}
Expand All @@ -70,18 +75,22 @@ void onGetStats(uint32_t* rx, uint32_t* tx, uint32_t* errors) {
*errors = radio_driver.getPacketsRecvErrors();
}

#ifndef PIO_UNIT_TESTING
void setup() {
board.begin();
mesh::initHardwareRNG();

loadOrCreateIdentity();
rng.setRadioEntropySource(radio_driver);
rng.begin();
mesh::deinitHardwareRNG();

if (!radio_init()) {
halt();
}

radio_driver.begin();

rng.begin(radio_get_rng_seed());
loadOrCreateIdentity();

sensors.begin();

#if defined(KISS_UART_RX) && defined(KISS_UART_TX)
Expand Down Expand Up @@ -144,3 +153,4 @@ void loop() {
}
radio_driver.loop();
}
#endif
24 changes: 15 additions & 9 deletions examples/simple_repeater/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ static unsigned long userBtnDownAt = 0;
#define USER_BTN_HOLD_OFF_MILLIS 1500
#endif

#ifndef PIO_UNIT_TESTING
void setup() {
Serial.begin(115200);
delay(1000);

board.begin();
mesh::initHardwareRNG();

#if defined(MESH_DEBUG) && defined(NRF52_PLATFORM)
// give some extra time for serial to settle so
Expand All @@ -52,13 +54,6 @@ void setup() {
}
#endif

if (!radio_init()) {
MESH_DEBUG_PRINTLN("Radio init failed!");
halt();
}

fast_rng.begin(radio_get_rng_seed());

FILESYSTEM* fs;
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
InternalFS.begin();
Expand All @@ -76,12 +71,22 @@ void setup() {
#else
#error "need to define filesystem"
#endif
fast_rng.attachPersistence(*fs, "/seed.rng");
fast_rng.setRadioEntropySource(radio_driver);
fast_rng.begin();
mesh::deinitHardwareRNG();

if (!radio_init()) {
MESH_DEBUG_PRINTLN("Radio init failed!");
halt();
}

if (!store.load("_main", the_mesh.self_id)) {
MESH_DEBUG_PRINTLN("Generating new keypair");
the_mesh.self_id = radio_new_identity(); // create new random identity
the_mesh.self_id = mesh::LocalIdentity(the_mesh.getRNG()); // create new random identity
int count = 0;
while (count < 10 && (the_mesh.self_id.pub_key[0] == 0x00 || the_mesh.self_id.pub_key[0] == 0xFF)) { // reserved id hashes
the_mesh.self_id = radio_new_identity(); count++;
the_mesh.self_id = mesh::LocalIdentity(the_mesh.getRNG()); count++;
}
store.save("_main", the_mesh.self_id);
}
Expand Down Expand Up @@ -168,3 +173,4 @@ void loop() {
#endif
}
}
#endif
18 changes: 12 additions & 6 deletions examples/simple_room_server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ void halt() {

static char command[MAX_POST_TEXT_LEN+1];

#ifndef PIO_UNIT_TESTING
void setup() {
Serial.begin(115200);
delay(1000);

board.begin();
mesh::initHardwareRNG();

#ifdef DISPLAY_CLASS
if (display.begin()) {
Expand All @@ -33,10 +35,6 @@ void setup() {
}
#endif

if (!radio_init()) { halt(); }

fast_rng.begin(radio_get_rng_seed());

FILESYSTEM* fs;
#if defined(NRF52_PLATFORM)
InternalFS.begin();
Expand All @@ -54,11 +52,18 @@ void setup() {
#else
#error "need to define filesystem"
#endif
fast_rng.attachPersistence(*fs, "/seed.rng");
fast_rng.setRadioEntropySource(radio_driver);
fast_rng.begin();
mesh::deinitHardwareRNG();

if (!radio_init()) { halt(); }

if (!store.load("_main", the_mesh.self_id)) {
the_mesh.self_id = radio_new_identity(); // create new random identity
the_mesh.self_id = mesh::LocalIdentity(the_mesh.getRNG()); // create new random identity
int count = 0;
while (count < 10 && (the_mesh.self_id.pub_key[0] == 0x00 || the_mesh.self_id.pub_key[0] == 0xFF)) { // reserved id hashes
the_mesh.self_id = radio_new_identity(); count++;
the_mesh.self_id = mesh::LocalIdentity(the_mesh.getRNG()); count++;
}
store.save("_main", the_mesh.self_id);
}
Expand Down Expand Up @@ -114,3 +119,4 @@ void loop() {
#endif
rtc_clock.tick();
}
#endif
31 changes: 17 additions & 14 deletions examples/simple_secure_chat/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,6 @@ class MyMesh : public BaseChatMesh, ContactVisitor {
IdentityStore store(fs, "/identity");
#endif
if (!store.load("_main", self_id, _prefs.node_name, sizeof(_prefs.node_name))) { // legacy: node_name was from identity file
// Need way to get some entropy to seed RNG
Serial.println("Press ENTER to generate key:");
char c = 0;
while (c != '\n') { // wait for ENTER to be pressed
if (Serial.available()) c = Serial.read();
}
((StdRNG *)getRNG())->begin(millis());

self_id = mesh::LocalIdentity(getRNG()); // create new random identity
int count = 0;
while (count < 10 && (self_id.pub_key[0] == 0x00 || self_id.pub_key[0] == 0xFF)) { // reserved id hashes
Expand Down Expand Up @@ -555,27 +547,37 @@ void halt() {
while (1) ;
}

#ifndef PIO_UNIT_TESTING
void setup() {
Serial.begin(115200);

board.begin();
mesh::initHardwareRNG();

if (!radio_init()) { halt(); }

fast_rng.begin(radio_get_rng_seed());
FILESYSTEM* fs;

#if defined(NRF52_PLATFORM)
InternalFS.begin();
the_mesh.begin(InternalFS);
fs = &InternalFS;
fast_rng.attachPersistence(InternalFS, "/seed.rng");
#elif defined(RP2040_PLATFORM)
LittleFS.begin();
the_mesh.begin(LittleFS);
fs = &LittleFS;
fast_rng.attachPersistence(LittleFS, "/seed.rng");
#elif defined(ESP32)
SPIFFS.begin(true);
the_mesh.begin(SPIFFS);
fs = &SPIFFS;
fast_rng.attachPersistence(SPIFFS, "/seed.rng");
#else
#error "need to define filesystem"
#endif
fast_rng.setRadioEntropySource(radio_driver);
fast_rng.begin();
mesh::deinitHardwareRNG();

if (!radio_init()) { halt(); }

the_mesh.begin(*fs);

radio_set_params(the_mesh.getFreqPref(), LORA_BW, LORA_SF, LORA_CR);
radio_set_tx_power(the_mesh.getTxPowerPref());
Expand All @@ -592,3 +594,4 @@ void loop() {
the_mesh.loop();
rtc_clock.tick();
}
#endif
18 changes: 12 additions & 6 deletions examples/simple_sensor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ void halt() {

static char command[160];

#ifndef PIO_UNIT_TESTING
void setup() {
Serial.begin(115200);
delay(1000);

board.begin();
mesh::initHardwareRNG();

#ifdef DISPLAY_CLASS
if (display.begin()) {
Expand All @@ -66,10 +68,6 @@ void setup() {
}
#endif

if (!radio_init()) { halt(); }

fast_rng.begin(radio_get_rng_seed());

FILESYSTEM* fs;
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
InternalFS.begin();
Expand All @@ -87,12 +85,19 @@ void setup() {
#else
#error "need to define filesystem"
#endif
fast_rng.attachPersistence(*fs, "/seed.rng");
fast_rng.setRadioEntropySource(radio_driver);
fast_rng.begin();
mesh::deinitHardwareRNG();

if (!radio_init()) { halt(); }

if (!store.load("_main", the_mesh.self_id)) {
MESH_DEBUG_PRINTLN("Generating new keypair");
the_mesh.self_id = radio_new_identity(); // create new random identity
the_mesh.self_id = mesh::LocalIdentity(the_mesh.getRNG()); // create new random identity
int count = 0;
while (count < 10 && (the_mesh.self_id.pub_key[0] == 0x00 || the_mesh.self_id.pub_key[0] == 0xFF)) { // reserved id hashes
the_mesh.self_id = radio_new_identity(); count++;
the_mesh.self_id = mesh::LocalIdentity(the_mesh.getRNG()); count++;
}
store.save("_main", the_mesh.self_id);
}
Expand Down Expand Up @@ -148,3 +153,4 @@ void loop() {
#endif
rtc_clock.tick();
}
#endif
5 changes: 5 additions & 0 deletions lib/ascon/api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define CRYPTO_VERSION "1.3.0"
#define CRYPTO_BYTES 64
#define ASCON_HASH_BYTES 0 /* XOF */
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you search the PR for this, we get conflicting definitions. lib/ascon/api.h defines 0, lib/ascon/config.h defines 1, lib/ascon/library.json sets flag =1.

Obviously it's working, but it's brittle. Probably we should let this file be authoritative.

#define ASCON_HASH_ROUNDS 12
#define ASCON_VARIANT 3
Loading
Loading