1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys: random: use luid to generate random seed

This commit is contained in:
Kaspar Schleiser 2017-08-31 00:50:25 +02:00
parent ac2e2e2165
commit ccf704bab8
4 changed files with 47 additions and 5 deletions

View File

@ -656,6 +656,8 @@ ifneq (,$(filter random,$(USEMODULE)))
ifneq (,$(filter prng_tinymt32,$(USEMODULE)))
USEMODULE += tinymt32
endif
USEMODULE += luid
endif
ifneq (,$(filter openthread_contrib,$(USEMODULE)))

View File

@ -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");

View File

@ -1,3 +1,5 @@
SRC := seed.c
BASE_MODULE := prng
SUBMODULES := 1

41
sys/random/seed.c Normal file
View 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 = 1;
#endif
DEBUG("random: using seed value %u\n", (unsigned)seed);
random_init(seed);
}