Esempio n. 1
0
uint32_t hw_rand(void)
{
    uint32_t rng;
#ifdef FREESCALE_KSDK_BM
    TRNG_GetRandomData(TRNG0, &rng, sizeof(rng));
#else
    while((RNG->SR & RNG_SR_OREG_LVL(0xF)) == 0) {}; /* Wait until FIFO has a value available */
    rng = RNG->OR; /* Return next value in FIFO output register */
#endif
    return rng;
}
Esempio n. 2
0
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
{
    status_t result;

    result = TRNG_GetRandomData(TRNG0, output, length);

    if (result == kStatus_Success) {
        *output_length = length;
        return 0;
    } else {
        return -1;
    }
}