27 #if defined(ASCON_TRNG_NONE)
29 #if defined(HAVE_CONFIG_H)
35 #if defined(HAVE_TIME_H)
38 #if defined(HAVE_SYS_TIME_H)
42 #warning "No system random number source found"
43 #if !defined(ASCON_TRNG_MIXER)
44 #error "Mixer is required if there is no known TRNG on the system"
68 #if defined(HAVE_THREAD_KEYWORD)
69 #define THREAD_LOCAL __thread
70 #elif defined(HAVE_THREAD_LOCAL_KEYWORD)
71 #define THREAD_LOCAL _Thread_local
80 static THREAD_LOCAL int volatile global_prng_initialized = 0;
82 #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETTIMEOFDAY) || \
85 static void ascon_trng_add_timespec
104 x[0] = (uint32_t)millis();
105 x[1] = (uint32_t)micros();
108 #elif defined(USE_HAL_DRIVER)
111 uint32_t x = HAL_GetTick();
114 #elif defined(HAVE_CLOCK_GETTIME)
118 #if defined(CLOCK_MONOTONIC)
119 clock_gettime(CLOCK_MONOTONIC, &ts);
120 ascon_trng_add_timespec
121 (
state, 0, (uint32_t)(ts.tv_sec), (uint32_t)(ts.tv_nsec));
123 clock_gettime(CLOCK_REALTIME, &ts);
124 ascon_trng_add_timespec
125 (
state, 8, (uint32_t)(ts.tv_sec), (uint32_t)(ts.tv_nsec));
128 #elif defined(HAVE_GETTIMEOFDAY)
132 gettimeofday(&tv, 0);
133 ascon_trng_add_timespec
134 (
state, 0, (uint32_t)(tv.tv_sec), (uint32_t)(tv.tv_usec));
137 #elif defined(HAVE_TIME)
139 ascon_trng_add_timespec(
state, 0, (uint32_t)time(0), 0);
153 static void ascon_trng_squeeze
156 while (outlen >= 8U) {
174 if (!global_prng_initialized) {
175 global_prng_initialized = 1;
188 ascon_trng_add_time(&global_prng);
198 ok = ascon_trng_global_init(seed);
199 ascon_trng_squeeze(&global_prng, out, outlen);
int ascon_trng_generate(unsigned char *out, size_t outlen)
Generates a buffer of bytes from the system TRNG source.
int ascon_trng_get_bytes(unsigned char *out, size_t outlen) __attribute__((weak))
Escape hatch that allows applications to provide their own interface to the system TRNG when the libr...
Access to the system's random number source.
#define ASCON_SYSTEM_SEED_SIZE
Number of bytes to request from the system TRNG to seed a PRNG.
void ascon_overwrite_with_zeroes(ascon_state_t *state, unsigned offset, unsigned size)
Overwrites a part of the ASCON state with zeroes.
void ascon_release(ascon_state_t *state)
Temporarily releases access to any shared hardware resources that a permutation state was using.
void ascon_extract_bytes(const ascon_state_t *state, uint8_t *data, unsigned offset, unsigned size)
Extracts bytes from the ASCON state.
void ascon_add_bytes(ascon_state_t *state, const uint8_t *data, unsigned offset, unsigned size)
Adds bytes to the ASCON state by XOR'ing them with existing bytes.
void ascon_acquire(ascon_state_t *state)
Re-acquires access to any shared hardware resources that a permutation state was using.
void ascon_init(ascon_state_t *state)
Initializes the words of the ASCON permutation state to zero.
#define ascon_permute6(state)
Permutes the ASCON state with 6 rounds of the permutation.
ascon_state_t state
[snippet_key]
Structure of the internal state of the ASCON permutation.
System utilities of use to applications that use ASCON.
void ascon_clean(void *buf, unsigned size)
Cleans a buffer that contains sensitive material.