1
0
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:
Tomas Susanka 2019-01-02 14:22:37 +01:00 committed by Pavol Rusnak
parent b9e8adc160
commit c34e8ab3bd
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 9 additions and 3 deletions

11
rand.c
View File

@ -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;
}

1
rand.h
View File

@ -27,6 +27,7 @@
#include <stdint.h>
#include <stdlib.h>
void random_reseed(const uint32_t value);
uint32_t random32(void);
void random_buffer(uint8_t *buf, size_t len);