mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #7547 from kaspar030/use_luid_for_random_init
sys: random: use luid for random seed initalization
This commit is contained in:
commit
68976f8f17
@ -652,6 +652,8 @@ ifneq (,$(filter random,$(USEMODULE)))
|
||||
ifneq (,$(filter prng_tinymt32,$(USEMODULE)))
|
||||
USEMODULE += tinymt32
|
||||
endif
|
||||
|
||||
USEMODULE += luid
|
||||
endif
|
||||
|
||||
ifneq (,$(filter openthread_contrib,$(USEMODULE)))
|
||||
@ -711,6 +713,10 @@ USEPKG += nanocoap
|
||||
USEMODULE += gnrc_sock_udp
|
||||
endif
|
||||
|
||||
ifneq (,$(filter luid,$(USEMODULE)))
|
||||
FEATURES_OPTIONAL += periph_cpuid
|
||||
endif
|
||||
|
||||
# always select gpio (until explicit dependencies are sorted out)
|
||||
FEATURES_OPTIONAL += periph_gpio
|
||||
|
||||
|
@ -80,10 +80,6 @@
|
||||
#include "net/fib.h"
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_PRNG
|
||||
#include "random.h"
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_GCOAP
|
||||
#include "net/gcoap.h"
|
||||
#endif
|
||||
@ -99,7 +95,8 @@
|
||||
void auto_init(void)
|
||||
{
|
||||
#ifdef MODULE_PRNG
|
||||
random_init(0);
|
||||
void auto_init_random(void);
|
||||
auto_init_random();
|
||||
#endif
|
||||
#ifdef MODULE_XTIMER
|
||||
DEBUG("Auto init xtimer module.\n");
|
||||
|
@ -32,6 +32,14 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef RANDOM_SEED_DEFAULT
|
||||
/**
|
||||
* @brief Seed selected when all tries to collect seeds from a random source
|
||||
* failed
|
||||
*/
|
||||
#define RANDOM_SEED_DEFAULT (1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables support for floating point random number generation
|
||||
*/
|
||||
|
@ -1,3 +1,5 @@
|
||||
SRC := seed.c
|
||||
|
||||
BASE_MODULE := prng
|
||||
SUBMODULES := 1
|
||||
|
||||
|
41
sys/random/seed.c
Normal file
41
sys/random/seed.c
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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 PRNG seeding
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "luid.h"
|
||||
#include "periph/cpuid.h"
|
||||
#include "random.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
void auto_init_random(void)
|
||||
{
|
||||
uint32_t seed;
|
||||
#ifdef MODULE_PERIPH_CPUID
|
||||
luid_get(&seed, 4);
|
||||
#else
|
||||
LOG_WARNING("random: NO SEED AVAILABLE!\n");
|
||||
seed = RANDOM_SEED_DEFAULT;
|
||||
#endif
|
||||
DEBUG("random: using seed value %u\n", (unsigned)seed);
|
||||
random_init(seed);
|
||||
}
|
Loading…
Reference in New Issue
Block a user