mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-25 15:58:08 +00:00
rand: switch to 'Numerical Recipes' constants and remove random8 to increase period
This commit is contained in:
parent
c5227fdb96
commit
54727e6650
17
rand.c
17
rand.c
@ -35,22 +35,13 @@
|
|||||||
// You are supposed to replace the random8() and random32() function with your own secure code.
|
// 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.
|
// There is also a possibility to replace the random_buffer() function as it is defined as a weak symbol.
|
||||||
|
|
||||||
static uint8_t random8(void)
|
uint32_t random32(void)
|
||||||
{
|
{
|
||||||
// Linear congruential generator used in glibc
|
// Linear congruential generator used in glibc
|
||||||
// https://en.wikipedia.org/wiki/Linear_congruential_generator
|
// https://en.wikipedia.org/wiki/Linear_congruential_generator
|
||||||
static int seed = 0;
|
static uint32_t seed = 0;
|
||||||
seed = (1103515245 * seed + 12345) & 0x7FFFFFFF;
|
seed = 1664525 * seed + 1013904223;
|
||||||
return seed & 0xFF;
|
return seed;
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t random32(void)
|
|
||||||
{
|
|
||||||
uint32_t r1 = random8();
|
|
||||||
uint32_t r2 = random8();
|
|
||||||
uint32_t r3 = random8();
|
|
||||||
uint32_t r4 = random8();
|
|
||||||
return ((r1 << 24) | (r2 << 16) | (r3 << 8) | r4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* RAND_PLATFORM_INDEPENDENT */
|
#endif /* RAND_PLATFORM_INDEPENDENT */
|
||||||
|
Loading…
Reference in New Issue
Block a user