mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 12:00:59 +00:00
rand: add a reseed function to be used in tests
This commit is contained in:
parent
b9e8adc160
commit
c34e8ab3bd
11
rand.c
11
rand.c
@ -25,8 +25,7 @@
|
||||
|
||||
#ifndef RAND_PLATFORM_INDEPENDENT
|
||||
|
||||
|
||||
#pragma message("NOT SUITABLE FOR PRODUCTION USE! Replace random8() and random32() functions with your own secure code.")
|
||||
#pragma message("NOT SUITABLE FOR PRODUCTION USE! Replace random32() function with your own secure code.")
|
||||
|
||||
// The following code is not supposed to be used in a production environment.
|
||||
// It's included only to make the library testable.
|
||||
@ -35,11 +34,17 @@
|
||||
// You are supposed to replace the random8() and random32() function with your own secure code.
|
||||
// There is also a possibility to replace the random_buffer() function as it is defined as a weak symbol.
|
||||
|
||||
static uint32_t seed = 0;
|
||||
|
||||
void random_reseed(const uint32_t value)
|
||||
{
|
||||
seed = value;
|
||||
}
|
||||
|
||||
uint32_t random32(void)
|
||||
{
|
||||
// Linear congruential generator from Numerical Recipes
|
||||
// https://en.wikipedia.org/wiki/Linear_congruential_generator
|
||||
static uint32_t seed = 0;
|
||||
seed = 1664525 * seed + 1013904223;
|
||||
return seed;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user