mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-23 07:58:09 +00:00
25 lines
493 B
C
25 lines
493 B
C
/*
|
|
* Copyright (c) Pavol Rusnak, SatoshiLabs
|
|
*
|
|
* Licensed under TREZOR License
|
|
* see LICENSE file for details
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "common.h"
|
|
#include "rng.h"
|
|
|
|
uint32_t rng_get(void)
|
|
{
|
|
static FILE *frand = NULL;
|
|
if (!frand) {
|
|
frand = fopen("/dev/urandom", "r");
|
|
}
|
|
ensure(sectrue * (frand != NULL), "fopen failed");
|
|
uint32_t r;
|
|
ensure(sectrue * (sizeof(r) == fread(&r, 1, sizeof(r), frand)), "fread failed");
|
|
return r;
|
|
}
|