sys/random: add option to use HWRNG as source of randomness#14453
sys/random: add option to use HWRNG as source of randomness#14453miri64 merged 2 commits intoRIOT-OS:masterfrom
Conversation
|
Isn't this what #14324 is already trying? |
| USEMODULE += hashes | ||
| endif | ||
|
|
||
| ifneq (,$(filter prng_hwrng,$(USEMODULE))) |
There was a problem hiding this comment.
Is it really a PRNG if it is generating random numbers from hardware? ;-)
There was a problem hiding this comment.
Yea that feels like a hack - we could rename them all prng_% -> rng_impl_%
Having a single API for randomness in random.h makes sense - the caller doesn't care if that randomness is provided by a PRNG or a HWRNG
There was a problem hiding this comment.
They might, when it comes to timing, or when the deterministic behavior of a PRNG is actually required for some reason.
There was a problem hiding this comment.
They might, when it comes to timing
In most cases the HWRNG will be plenty fast. It could be faster (#11924 😉), but hardly noticeable.
or when the deterministic behavior of a PRNG is actually required
Then the application should use a private instance of a PRNG.
The system RNG will be called by 'everyone', thereby severely hampering determinism.
Also mind you, this is just an option. An application developer can chose to select the HWRNG for everything and will get
- cryptographically sound randomness
- reduced code size
if they accept the drawbacks you mentioned.
There was a problem hiding this comment.
if they accept the drawbacks you mentioned.
Perfect call-in for a documentation upgrade ;-).
There was a problem hiding this comment.
I would add it to the documentation about the characteristics of the different PRNG implementations, but I couldn't find those either.
There was a problem hiding this comment.
For most PRNG you can look it up in literature just searching for the name. This is not the case for the HWNRG.
|
I only skimmed #14324, but it looks like a replacement for when no HWRNG is available. |
|
#14324 focuses entropy collection from alternative sources than a HWRNG, likely used for PRNG seeding. It is very unlikely however, that anyone would use them for more than seed generation due to the resource overhead. I like the idea of this PR as an option to connect the HWRNG directly to IMO we miss separation between entropy sources, seed values, standard PRNGs and crypto PRNGs in RIOT and I am planning on improving the situation step by step. Back to this specific PR, I don't have a concrete opinion by now. |
| * - Simple Park-Miller PRNG | ||
| * - Musl C PRNG | ||
| * - Fortuna (CS)PRNG | ||
| * - Hardware Random Number Generator (non-seedable) |
There was a problem hiding this comment.
I would add it to the documentation about the characteristics of the different PRNG implementations, but I couldn't find those either.
I would just add it here with all the implications @PeterKietzmann mentioned with regards to true randomness and pseudo-randomness.
There was a problem hiding this comment.
Hm, is there more to add than 'read the data sheet of your MCU' 😃 ?
There was a problem hiding this comment.
At least that the HWNRGs vary in how they generate random numbers and that not all are pseudo-number random generators but provide true randomness should also be added as a note.
There was a problem hiding this comment.
A bit off-topic but anyway: One could spend a note here but IMO the HWRNG implementation should as well indicate its hardware random technology.
miri64
left a comment
There was a problem hiding this comment.
Getting an error when trying to compile:
$ USEMODULE=prng_hwnrg BOARD=iotlab-m3 IOTLAB_NODES=1 make -C tests/rng/ iotlab-exp
make: Entering directory '/home/mlenders/Repositories/RIOT-OS/RIOT/tests/rng'
Building application "tests_rng" for "iotlab-m3" with MCU "stm32".
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/boards/iotlab-m3
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/boards/common/iotlab
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/core
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/cpu/stm32
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/cpu/cortexm_common
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/cpu/cortexm_common/periph
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/cpu/stm32/bootloader
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/cpu/stm32/periph
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/cpu/stm32/stmclk
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/cpu/stm32/vectors
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/drivers
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/drivers/periph_common
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/auto_init
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/div
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/fmt
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/isrpipe
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/luid
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/newlib_syscalls_default
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/pm_layered
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/random
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/shell
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/stdio_uart
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/test_utils/interactive_sync
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/tsrb
"make" -C /home/mlenders/Repositories/RIOT-OS/RIOT/sys/xtimer
/usr/lib/gcc/arm-none-eabi/10.1.0/../../../../arm-none-eabi/bin/ld: /home/mlenders/Repositories/RIOT-OS/RIOT/tests/rng/bin/iotlab-m3/application_tests_rng/test.o: in function `test_init':
/home/mlenders/Repositories/RIOT-OS/RIOT/tests/rng/test.c:42: undefined reference to `random_init'
/usr/lib/gcc/arm-none-eabi/10.1.0/../../../../arm-none-eabi/bin/ld: /home/mlenders/Repositories/RIOT-OS/RIOT/tests/rng/bin/iotlab-m3/application_tests_rng/test.o: in function `test_get_uint32':
/home/mlenders/Repositories/RIOT-OS/RIOT/tests/rng/test.c:88: undefined reference to `random_uint32'
/usr/lib/gcc/arm-none-eabi/10.1.0/../../../../arm-none-eabi/bin/ld: /home/mlenders/Repositories/RIOT-OS/RIOT/tests/rng/bin/iotlab-m3/random/random.o: in function `auto_init_random':
/home/mlenders/Repositories/RIOT-OS/RIOT/sys/random/random.c:60: undefined reference to `random_init'
/usr/lib/gcc/arm-none-eabi/10.1.0/../../../../arm-none-eabi/bin/ld: /home/mlenders/Repositories/RIOT-OS/RIOT/tests/rng/bin/iotlab-m3/random/random.o: in function `random_uint32_range':
/home/mlenders/Repositories/RIOT-OS/RIOT/sys/random/random.c:99: undefined reference to `random_uint32'
collect2: error: ld returned 1 exit status
make: *** [/home/mlenders/Repositories/RIOT-OS/RIOT/tests/rng/../../Makefile.include:572: /home/mlenders/Repositories/RIOT-OS/RIOT/tests/rng/bin/iotlab-m3/tests_rng.elf] Error 1
make: Leaving directory '/home/mlenders/Repositories/RIOT-OS/RIOT/tests/rng'
|
When I add |
I assumed the IoT-LAB has that feature. However, from how the module is structured, the linker should at least find the |
|
|
|
Ok, now I get the more expected result: |
|
Then let's use |
|
Please squash! |
Add the `prng_hwrng` module to enable the HWRNG as source of all randomness, not just for seeding a PRNG. saves ~260 bytes compared to using tinymt32.
1330b18 to
2f42347
Compare
|
I tried on |
Contribution description
Add the
prng_hwrngmodule to enable the HWRNG as source of all randomness, not just for seeding a PRNG.saves ~260 bytes compared to using tinymt32.
Testing procedure
add
USEMODULE += prng_hwrngto any application that uses therandommodule.Issues/PRs references