Skip to content

Reduce key duplication by enabling hardware RNG#8803

Merged
jp-bennett merged 14 commits into
meshtastic:developfrom
Komzpa:nrf-rng
Apr 13, 2026
Merged

Reduce key duplication by enabling hardware RNG#8803
jp-bennett merged 14 commits into
meshtastic:developfrom
Komzpa:nrf-rng

Conversation

@Komzpa

@Komzpa Komzpa commented Nov 29, 2025

Copy link
Copy Markdown
Contributor

Summary

  • add portable HardwareRNG helper that taps NRF52 crypto RNG, ESP32/TRNG, RP2040 hwrand, Portduino host RNG, and modem-provided entropy as available
  • stir hardware bytes into CryptRNG during key generation to avoid repeated keys on NRF devices
  • route NRF52, Portduino, and RP2040 platform setup through the new helper so runtime random seeds also benefit
  • expose RadioLibInterface::randomBytes so modem entropy can be mixed in when radios are initialized

🤝 Attestations

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card
    • Other (please specify below)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 HardwareRNG namespace with fill() and seed() 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.

Comment thread src/mesh/RadioLibInterface.h
Comment thread src/platform/rp2xx0/main-rp2xx0.cpp Outdated
Comment thread src/platform/portduino/PortduinoGlue.cpp
Comment thread src/platform/portduino/PortduinoGlue.cpp
Comment thread src/mesh/RadioLibInterface.cpp
Comment thread src/mesh/HardwareRNG.cpp
Comment thread src/platform/nrf52/main-nrf52.cpp Outdated
Comment thread src/mesh/HardwareRNG.cpp
@jp-bennett

Copy link
Copy Markdown
Collaborator

I particularly like that this is just stirring in another potential randomness source. Will go through it in more detail as I am able.

@jp-bennett jp-bennett added the enhancement New feature or request label Nov 30, 2025
Comment thread src/platform/nrf52/main-nrf52.cpp Outdated
Comment thread src/mesh/HardwareRNG.cpp Outdated
Comment thread src/mesh/CryptoEngine.cpp
@github-actions github-actions Bot added the Stale Issues that will be closed if not triaged. label Jan 24, 2026
@github-actions github-actions Bot closed this Feb 3, 2026
@fifieldt fifieldt reopened this Feb 3, 2026
thebentern and others added 2 commits February 3, 2026 06:25
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions github-actions Bot removed the Stale Issues that will be closed if not triaged. label Feb 8, 2026
@Komzpa

Komzpa commented Feb 15, 2026

Copy link
Copy Markdown
Contributor Author

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

@github-actions github-actions Bot added the Stale Issues that will be closed if not triaged. label Apr 2, 2026
@jp-bennett

Copy link
Copy Markdown
Collaborator

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!

jp-bennett and others added 4 commits April 10, 2026 21:00
Use micros() for worst case random seed for nrf52

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jp-bennett jp-bennett merged commit 77f378d into meshtastic:develop Apr 13, 2026
75 of 78 checks passed
NomDeTom pushed a commit to NomDeTom/MeshtasticFirmware that referenced this pull request Apr 14, 2026
* 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>
cvaldess pushed a commit to cvaldess/firmware that referenced this pull request Apr 15, 2026
* 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>
thebentern added a commit that referenced this pull request Apr 21, 2026
* 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>
mariotti pushed a commit to mariotti/firmware that referenced this pull request May 6, 2026
* 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>
Evil8it pushed a commit to Evil8it/ME4TACTNK that referenced this pull request Jun 10, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Stale Issues that will be closed if not triaged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants