26 #if defined(ASCON_TRNG_DUE)
30 static int volatile due_init_done = 0;
32 static inline void ascon_trng_init_internal(
void)
36 pmc_enable_periph_clk(ID_TRNG);
37 REG_TRNG_CR = TRNG_CR_KEY(0x524E47) | TRNG_CR_ENABLE;
38 REG_TRNG_IDR = TRNG_IDR_DATRDY;
43 static inline int ascon_trng_generate_word(uint32_t *x)
48 while ((REG_TRNG_ISR & TRNG_ISR_DATRDY) == 0) {
62 ascon_trng_init_internal();
63 while (outlen >=
sizeof(x)) {
64 if (!ascon_trng_generate_word(&x))
66 memcpy(out, &x,
sizeof(x));
71 if (!ascon_trng_generate_word(&x))
73 memcpy(out, &x, outlen);
83 ascon_trng_init_internal();
86 return ascon_trng_generate_word(&x);
98 ascon_trng_generate_word(&word);
106 ascon_trng_generate_word(&low);
107 ascon_trng_generate_word(&high);
108 return ((uint64_t)low) | (((uint64_t)high) << 32);
uint32_t ascon_trng_generate_32(ascon_trng_state_t *state)
Generates a 32-bit random value for masking operations.
uint64_t ascon_trng_generate_64(ascon_trng_state_t *state)
Generates a 64-bit random value for masking operations.
int ascon_trng_init(ascon_trng_state_t *state)
Initializes the random number source for generating a sequence of masking material at high speed.
int ascon_trng_reseed(ascon_trng_state_t *state)
Reseeds the random number source.
void ascon_trng_free(ascon_trng_state_t *state)
Frees the random number source and destroys any sensitive material.
int ascon_trng_generate(unsigned char *out, size_t outlen)
Generates a buffer of bytes from the system TRNG source.
Access to the system's random number source.
ascon_state_t state
[snippet_key]
State of the random number source.