diff --git a/rand.c b/rand.c index 70743ae6fc..411c755a31 100644 --- a/rand.c +++ b/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; } diff --git a/rand.h b/rand.h index 175bd96079..49d9cfaf21 100644 --- a/rand.h +++ b/rand.h @@ -27,6 +27,7 @@ #include #include +void random_reseed(const uint32_t value); uint32_t random32(void); void random_buffer(uint8_t *buf, size_t len);