ASCON Suite
ascon-random.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #include <ascon/random.h>
24 #include <ascon/utility.h>
25 #include "random/ascon-trng.h"
26 
27 int ascon_random(unsigned char *out, size_t outlen)
28 {
30  unsigned char seed[ASCON_SYSTEM_SEED_SIZE];
31  int ok = ascon_trng_generate(seed, sizeof(seed));
32  ascon_xof_init_fixed(&xof, outlen);
33  ascon_xof_absorb(&xof, seed, sizeof(seed));
34  ascon_xof_squeeze(&xof, out, outlen);
36  ascon_clean(seed, sizeof(seed));
37  return ok ? 1 : 0;
38 }
int ascon_random(unsigned char *out, size_t outlen)
Gets a block of random data from the system.
Definition: ascon-random.c:27
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.
#define ASCON_SYSTEM_SEED_SIZE
Number of bytes to request from the system TRNG to seed a PRNG.
Definition: ascon-trng.h:58
xof_with_output_length< 0 > xof
ASCON-XOF object with arbitrary-length output.
Definition: xof.h:928
Pseudorandom number generator (PRNG) built around ASCON.
State information for ASCON-XOF incremental mode.
Definition: xof.h:61
System utilities of use to applications that use ASCON.
void ascon_clean(void *buf, unsigned size)
Cleans a buffer that contains sensitive material.
Definition: ascon-clean.c:38
void ascon_xof_free(ascon_xof_state_t *state)
Frees the ASCON-XOF state and destroys any sensitive material.
Definition: ascon-xof.c:218
void ascon_xof_absorb(ascon_xof_state_t *state, const unsigned char *in, size_t inlen)
Absorbs more input data into an ASCON-XOF state.
Definition: ascon-xof.c:229
void ascon_xof_squeeze(ascon_xof_state_t *state, unsigned char *out, size_t outlen)
Squeezes output data from an ASCON-XOF state.
Definition: ascon-xof.c:279
void ascon_xof_init_fixed(ascon_xof_state_t *state, size_t outlen)
Initializes the state for an incremental ASCON-XOF operation, with a fixed output length.
Definition: ascon-xof.c:74