sys/random: add hwrng as seed source (if available)

This commit is contained in:
Hauke Petersen 2019-02-08 14:41:57 +01:00 committed by PeterKietzmann
parent 8a135d3a43
commit 64489e8b44
2 changed files with 11 additions and 0 deletions

View File

@ -661,6 +661,10 @@ ifneq (,$(filter random,$(USEMODULE)))
USEMODULE += hashes USEMODULE += hashes
endif endif
ifeq (,$(filter puf_sram,$(USEMODULE)))
FEATURES_OPTIONAL += periph_hwrng
endif
USEMODULE += luid USEMODULE += luid
endif endif

View File

@ -1,5 +1,6 @@
/** /**
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de> * Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
* 2019 Freie Universität Berlin
* *
* This file is subject to the terms and conditions of the GNU Lesser * 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 * General Public License v2.1. See the file LICENSE in the top level
@ -14,6 +15,7 @@
* @brief PRNG seeding * @brief PRNG seeding
* *
* @author Kaspar Schleiser <kaspar@schleiser.de> * @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @} * @}
*/ */
@ -25,6 +27,9 @@
#ifdef MODULE_PUF_SRAM #ifdef MODULE_PUF_SRAM
#include "puf_sram.h" #include "puf_sram.h"
#endif #endif
#ifdef MODULE_PERIPH_HWRNG
#include "periph/hwrng.h"
#endif
#ifdef MODULE_PERIPH_CPUID #ifdef MODULE_PERIPH_CPUID
#include "periph/cpuid.h" #include "periph/cpuid.h"
#endif #endif
@ -41,6 +46,8 @@ void auto_init_random(void)
LOG_WARNING("random: PUF SEED not fresh\n"); LOG_WARNING("random: PUF SEED not fresh\n");
} }
seed = puf_sram_seed; seed = puf_sram_seed;
#elif defined (MODULE_PERIPH_HWRNG)
hwrng_read(&seed, 4);
#elif defined (MODULE_PERIPH_CPUID) #elif defined (MODULE_PERIPH_CPUID)
luid_get(&seed, 4); luid_get(&seed, 4);
#else #else