Reduce key duplication by enabling hardware RNG#8803
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a portable HardwareRNG helper to improve random number generation across platforms by tapping into hardware RNG sources (NRF52 crypto RNG, ESP32 TRNG, RP2040 hwrand, Portduino host RNG) and optionally mixing in modem-provided entropy. The goal is to reduce key duplication issues on NRF devices by stirring hardware bytes into CryptRNG during key generation.
Key changes:
- Added
HardwareRNGnamespace withfill()andseed()functions for platform-agnostic hardware entropy access - Integrated hardware entropy into
CryptoEngine::generateKeyPair()to strengthen key generation - Exposed
RadioLibInterface::randomBytes()to allow modem entropy mixing when radios are initialized - Updated NRF52, RP2040, and Portduino platform initialization to use the new
HardwareRNG::seed()helper
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
src/mesh/HardwareRNG.h |
New header defining the HardwareRNG interface with fill() and seed() functions |
src/mesh/HardwareRNG.cpp |
Implementation providing platform-specific hardware RNG access with optional radio entropy mixing |
src/mesh/RadioLibInterface.h |
Added public randomBytes() method declaration for exposing modem entropy |
src/mesh/RadioLibInterface.cpp |
Implemented randomBytes() to fetch entropy from LoRa modem via RadioLib API |
src/mesh/CryptoEngine.cpp |
Integrated HardwareRNG to stir 64 bytes of hardware entropy into CryptRNG during key generation |
src/platform/nrf52/main-nrf52.cpp |
Replaced direct nRFCrypto RNG calls with HardwareRNG::seed() |
src/platform/rp2xx0/main-rp2xx0.cpp |
Added HardwareRNG::seed() call alongside existing hwrand32 usage |
src/platform/portduino/PortduinoGlue.cpp |
Added HardwareRNG::seed() calls in both simulated and native modes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I particularly like that this is just stirring in another potential randomness source. Will go through it in more detail as I am able. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
I'll be happy if someone can take over this and get it live - we've got three new same-pubkey NRFs in the town nowadays |
I like basically about this approach, and it's clearly needed. I'll take over and get it pushed across the line. Thanks! |
Use micros() for worst case random seed for nrf52 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Reduce key duplication by enabling hardware RNG * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Use micros() for worst case random seed for nrf52 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Minor cleanup, remove dead code and clarify comment * trunk * Add useRadioEntropy bool, default false. --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
* Reduce key duplication by enabling hardware RNG * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Use micros() for worst case random seed for nrf52 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Minor cleanup, remove dead code and clarify comment * trunk * Add useRadioEntropy bool, default false. --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
* Reduce key duplication by enabling hardware RNG * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Use micros() for worst case random seed for nrf52 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Minor cleanup, remove dead code and clarify comment * trunk * Add useRadioEntropy bool, default false. --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
* Reduce key duplication by enabling hardware RNG * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Use micros() for worst case random seed for nrf52 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Minor cleanup, remove dead code and clarify comment * trunk * Add useRadioEntropy bool, default false. --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
* Reduce key duplication by enabling hardware RNG * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Use micros() for worst case random seed for nrf52 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Minor cleanup, remove dead code and clarify comment * trunk * Add useRadioEntropy bool, default false. --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
Summary
🤝 Attestations