1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 17:38:39 +00:00
trezor-firmware/speed-stm32/rand.c

18 lines
343 B
C
Raw Normal View History

2013-08-18 18:54:18 +00:00
#include <libopencm3/stm32/f2/rng.h>
#include "rand.h"
void init_rand(void) {
2013-08-20 23:31:24 +00:00
RNG_CR |= RNG_CR_IE | RNG_CR_RNGEN;
2013-08-18 18:54:18 +00:00
}
uint32_t random32(void) {
static uint32_t last = 0, new = 0;
while (new == last) {
if (((RNG_SR & (RNG_SR_SEIS | RNG_SR_CEIS)) == 0) && ((RNG_SR & RNG_SR_DRDY) > 0)) {
new = RNG_DR;
}
}
last = new;
return new;
}