mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 10:52:44 +01:00
Merge pull request #14453 from benpicco/sys/random-hwrng
sys/random: add option to use HWRNG as source of randomness
This commit is contained in:
commit
908ec472ce
@ -786,6 +786,10 @@ ifneq (,$(filter random,$(USEMODULE)))
|
||||
USEMODULE += hashes
|
||||
endif
|
||||
|
||||
ifneq (,$(filter prng_hwrng,$(USEMODULE)))
|
||||
FEATURES_REQUIRED += periph_hwrng
|
||||
endif
|
||||
|
||||
ifeq (,$(filter puf_sram,$(USEMODULE)))
|
||||
FEATURES_OPTIONAL += periph_hwrng
|
||||
endif
|
||||
|
@ -22,6 +22,9 @@
|
||||
* - Simple Park-Miller PRNG
|
||||
* - Musl C PRNG
|
||||
* - Fortuna (CS)PRNG
|
||||
* - Hardware Random Number Generator (non-seedable)
|
||||
* HWRNG differ in how they generate random numbers and may not use a PRNG internally.
|
||||
* Refer to the manual of your MCU for details.
|
||||
*/
|
||||
|
||||
#ifndef RANDOM_H
|
||||
|
38
sys/random/hwrng.c
Normal file
38
sys/random/hwrng.c
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright (C) 2020 ML!PA Consulting GmbH
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup sys_random
|
||||
* @{
|
||||
* @file
|
||||
*
|
||||
* @brief Use the HWRNG as source of randomness
|
||||
*
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "kernel_defines.h"
|
||||
#include "periph/hwrng.h"
|
||||
#include "random.h"
|
||||
|
||||
uint32_t random_uint32(void)
|
||||
{
|
||||
uint32_t rnd;
|
||||
hwrng_read(&rnd, sizeof(rnd));
|
||||
return rnd;
|
||||
}
|
||||
|
||||
void random_init(uint32_t val)
|
||||
{
|
||||
(void) val;
|
||||
|
||||
if (!IS_ACTIVE(MODULE_PERIPH_INIT_HWRNG)) {
|
||||
hwrng_init();
|
||||
}
|
||||
}
|
@ -65,6 +65,8 @@ static void test_init(char *name)
|
||||
puts("Tiny Mersenne Twister PRNG.\n");
|
||||
#elif MODULE_PRNG_XORSHIFT
|
||||
puts("XOR Shift PRNG.\n");
|
||||
#elif MODULE_PRNG_HWRNG
|
||||
puts("Hardware RNG.\n");
|
||||
#else
|
||||
puts("unknown PRNG.\n");
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user