ASCON Suite
|
Pseudorandom number generator (PRNG) built around ASCON. More...
#include <ascon/xof.h>
Go to the source code of this file.
Classes | |
struct | ascon_random_state_t |
State information for a pseudorandom number generator. More... | |
Functions | |
int | ascon_random (unsigned char *out, size_t outlen) |
Gets a block of random data from the system. More... | |
int | ascon_random_init (ascon_random_state_t *state) |
Initializes a pseudorandom number generator from the system random number source. More... | |
void | ascon_random_free (ascon_random_state_t *state) |
Frees a pseudorandom number generator and destroys any sensitive values. More... | |
void | ascon_random_fetch (ascon_random_state_t *state, unsigned char *out, size_t outlen) |
Fetches data from a pseudorandom number generator. More... | |
int | ascon_random_reseed (ascon_random_state_t *state) |
Explicitly re-seeds a pseudorandom number generator from the system random number source. More... | |
void | ascon_random_feed (ascon_random_state_t *state, const unsigned char *entropy, size_t size) |
Feeds entropy into a pseudorandom number generator. More... | |
Pseudorandom number generator (PRNG) built around ASCON.
This PRNG implementation uses the SpongePRNG construction with ASCON as the sponge permutation.
Reference: "Sponge-based pseudo-random number generators", Guido Bertoni et al, https://keccak.team/files/SpongePRNG.pdf
Definition in file random.h.
int ascon_random | ( | unsigned char * | out, |
size_t | outlen | ||
) |
Gets a block of random data from the system.
out | Buffer to fill with the random data. |
outlen | Number of bytes of random data to generate. |
In the case of a zero return, the returned data may be predictable so the application should probably avoid using it.
This function does not directly return the output of the system random number source. It will process the output with ASCON-XOF to remove any watermarks or bias from untrustworthy TRNG's. And it will spread the entropy uniformly throughout the returned data.
This function is suitable for relatively rare events such as the generation of session keys or password salts. If you need a large amount of continuous random data, then use ascon_random_init() instead.
Definition at line 27 of file ascon-random.c.
void ascon_random_feed | ( | ascon_random_state_t * | state, |
const unsigned char * | entropy, | ||
size_t | size | ||
) |
Feeds entropy into a pseudorandom number generator.
state | The pseudorandom number generator to feed the entropy into. |
entropy | Points to a buffer containing the entropy. |
size | Number of bytes of entropy to add, which can be zero to "stir" the random pool but not introduce any new entropy. |
This API does not keep track of how much entropy has been collected. Estimating the amount of entropy contained in noise sources is difficult and would make the API very complex.
The application can keep track of "entropy credits" itself if that is important. And then only call ascon_random_fetch() when it judges that the entropy pool is sufficiently populated.
Definition at line 135 of file ascon-prng.c.
void ascon_random_fetch | ( | ascon_random_state_t * | state, |
unsigned char * | out, | ||
size_t | outlen | ||
) |
Fetches data from a pseudorandom number generator.
state | The pseudorandom number generator state to use. |
out | Points to a buffer to receive the random data. |
outlen | Number of bytes of random data to fetch. |
Definition at line 90 of file ascon-prng.c.
void ascon_random_free | ( | ascon_random_state_t * | state | ) |
Frees a pseudorandom number generator and destroys any sensitive values.
state | The pseudorandom number generator state to free. |
Definition at line 82 of file ascon-prng.c.
int ascon_random_init | ( | ascon_random_state_t * | state | ) |
Initializes a pseudorandom number generator from the system random number source.
state | The pseudorandom number generator state to initialize. |
In the case of a zero return, the returned data may be predictable so the application should avoid using the pseudorandom number generator unless it has some other source of entropy it can use.
Definition at line 66 of file ascon-prng.c.
int ascon_random_reseed | ( | ascon_random_state_t * | state | ) |
Explicitly re-seeds a pseudorandom number generator from the system random number source.
state | The pseudorandom number generator to re-seed. |
The pseudorandom number generator will be re-seeded periodically by ascon_random_fetch() but the application can choose to re-seed more often if it needs fresh random data.
Definition at line 116 of file ascon-prng.c.