Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to disable RSSI-based random number generator in radio.c #621

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zsellera
Copy link

@zsellera zsellera commented Nov 5, 2020

This PR allows library users to disable the random number generator in radio.c and replace it with a custom one.

LoRaWAN 1.0 specs requires DevNonce to be a random number. The specs asks specifically a high quality random and proposes the wideband RSSI measurement as a random source ("The DevNonce can be extracted by issuing a sequence of RSSI measurements under the assumption that the quality of randomness fulfills the criteria of true randomness").

LMIC library implements exactly that. The implementation seeds its random number generator with 120 random bits using RSSI measurement and von Neumann random extraction technique. This requires at least, on average 480 SPI read operations to LORARegRssiWideband register, while the radio is kept in RXMODE_RSSI.

On my implementation (STM32L4 + ST-provided HAL functions for SPI) seeding the RNG takes about 150ms. As the radio is kept powered down by default, it is a huge burden on each re-init, especially since many MCU's have built-in true-RNGs (which completes in my case in ~50 CPU cycles).

What changed?

  • added a new flag (LMIC_DISABLE_RADIO_RAND) to completely disable the random number generator in radio.c
  • re-organised the code in oslmic.h, moved u1_t radio_rand1 (void); from a seemingly random location next to other os/radio related definitions.
  • #define os_getRndU1() radio_rand1() moved next to other os defines, in a similar manner as the rest os-related defines are created
  • fixed some typos meanwhile + added comment where I felt missing.

- introduced flag LMIC_DISABLE_RADIO_RAND
- which disabled randbuf and related code in radio.c
- minor cleanup in oslmic.h supporting this change
@terrillmoore
Copy link
Member

Thanks for your contribution. This needs to be coordinated with the secure-element support. You can take a look at the branch, or wait for me to merge. There are also RNGs in the secure element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants