Skip to content

Commit

Permalink
Merge pull request #10974 from haukepetersen/add_random_hwrngseed
Browse files Browse the repository at this point in the history
sys/random: use periph/hwrng as seed if available
  • Loading branch information
PeterKietzmann authored Feb 19, 2019
2 parents 621224d + 64489e8 commit 0e71c8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@ ifneq (,$(filter random,$(USEMODULE)))
USEMODULE += hashes
endif

ifeq (,$(filter puf_sram,$(USEMODULE)))
FEATURES_OPTIONAL += periph_hwrng
endif

USEMODULE += luid
endif

Expand Down
17 changes: 13 additions & 4 deletions sys/random/random.c
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
/**
* 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
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup sys_random
* @ingroup sys_random
* @{
* @file
*
* @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>
* @}
*/

#include <stdint.h>

#include "log.h"
#include "luid.h"
#include "periph/cpuid.h"
#include "random.h"
#ifdef MODULE_PUF_SRAM
#include "puf_sram.h"
#endif
#ifdef MODULE_PERIPH_HWRNG
#include "periph/hwrng.h"
#endif
#ifdef MODULE_PERIPH_CPUID
#include "periph/cpuid.h"
#endif

#define ENABLE_DEBUG (0)
#include "debug.h"
Expand All @@ -39,6 +46,8 @@ void auto_init_random(void)
LOG_WARNING("random: PUF SEED not fresh\n");
}
seed = puf_sram_seed;
#elif defined (MODULE_PERIPH_HWRNG)
hwrng_read(&seed, 4);
#elif defined (MODULE_PERIPH_CPUID)
luid_get(&seed, 4);
#else
Expand Down

0 comments on commit 0e71c8a

Please sign in to comment.