https://github.com/mupq/pqm4
Raw File
Tip revision: 8110b02a789d7969145230a1d43a2b21c3c182b6 authored by Matthias J. Kannwischer on 27 July 2020, 02:15:28 UTC
instead of sending more markers; just add delay in hal_setup
Tip revision: 8110b02
randombytes.c
#include "randombytes.h"
#include "em_chip.h"
#include "em_device.h"

int randombytes(uint8_t *buf, size_t len)
{
    union
    {
        uint8_t aschar[4];
        uint32_t asint;
    } random;

    while (len > 4)
    {
        while (!TRNG0->FIFOLEVEL)
            ;
        random.asint = TRNG0->FIFO;
        *buf++ = random.aschar[0];
        *buf++ = random.aschar[1];
        *buf++ = random.aschar[2];
        *buf++ = random.aschar[3];
        len -= 4;
    }
    if (len > 0)
    {
        while (!TRNG0->FIFOLEVEL)
            ;
        random.asint = TRNG0->FIFO;
        for (; len > 0; len--)
        {
            *buf++ = random.aschar[len - 1];
        }
    }
    return 0;
}
back to top