1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 06:48:16 +00:00

rand.c: platform depedenant code can be removed using CPP flag

This commit is contained in:
Peter D. Gray 2018-01-12 13:17:58 -05:00 committed by Pavol Rusnak
parent cb8c910a0c
commit 65e976d70c

22
rand.c
View File

@ -30,6 +30,8 @@
#include "rand.h" #include "rand.h"
#ifndef RAND_PLATFORM_INDEPENDANT
static FILE *frand = NULL; static FILE *frand = NULL;
int finalize_rand(void) int finalize_rand(void)
@ -62,13 +64,6 @@ uint32_t random32(void)
#endif #endif
} }
uint32_t random_uniform(uint32_t n)
{
uint32_t x, max = 0xFFFFFFFF - (0xFFFFFFFF % n);
while ((x = random32()) >= max);
return x / (max / n);
}
void random_buffer(uint8_t *buf, size_t len) void random_buffer(uint8_t *buf, size_t len)
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -87,6 +82,19 @@ void random_buffer(uint8_t *buf, size_t len)
#endif #endif
} }
#endif /* RAND_PLATFORM_INDEPENDANT */
//
// Following code should be platform independant
//
uint32_t random_uniform(uint32_t n)
{
uint32_t x, max = 0xFFFFFFFF - (0xFFFFFFFF % n);
while ((x = random32()) >= max);
return x / (max / n);
}
void random_permute(char *str, size_t len) void random_permute(char *str, size_t len)
{ {
int i, j; int i, j;