QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
secrand.h File Reference

Secure pseudo-random generator (PRNG) function definitions. More...

#include "common.h"
#include "csg.h"

Go to the source code of this file.

Data Structures

struct  qsc_secrand_state
 The internal secrand state array. More...
 

Macros

#define QSC_SECRAND_SEED_SIZE   32ULL
 The input seed size.
 
#define QSC_SECRAND_CACHE_SIZE   1024ULL
 The internal cache size of the generator.
 

Functions

QSC_EXPORT_API int8_t qsc_secrand_next_char (void)
 Generate a signed 8-bit random integer.
 
QSC_EXPORT_API uint8_t qsc_secrand_next_uchar (void)
 Generate an unsigned 8-bit random integer.
 
QSC_EXPORT_API double qsc_secrand_next_double (void)
 Generate a random double-precision floating-point number.
 
QSC_EXPORT_API int16_t qsc_secrand_next_int16 (void)
 Generate a signed 16-bit random integer.
 
QSC_EXPORT_API int16_t qsc_secrand_next_int16_max (int16_t maximum)
 Generate a signed 16-bit random integer of a maximum value.
 
QSC_EXPORT_API int16_t qsc_secrand_next_int16_maxmin (int16_t maximum, int16_t minimum)
 Generate a signed 16-bit random integer of a maximum and minimum value.
 
QSC_EXPORT_API uint16_t qsc_secrand_next_uint16 (void)
 Generate an unsigned 16-bit random integer.
 
QSC_EXPORT_API uint16_t qsc_secrand_next_uint16_max (uint16_t maximum)
 Generate an unsigned 16-bit random integer of a maximum value.
 
QSC_EXPORT_API uint16_t qsc_secrand_next_uint16_maxmin (uint16_t maximum, uint16_t minimum)
 Generate an unsigned 16-bit random integer of a maximum and minimum value.
 
QSC_EXPORT_API int32_t qsc_secrand_next_int32 (void)
 Generate a signed 32-bit random integer.
 
QSC_EXPORT_API int32_t qsc_secrand_next_int32_max (int32_t maximum)
 Generate a signed 32-bit random integer of a maximum value.
 
QSC_EXPORT_API int32_t qsc_secrand_next_int32_maxmin (int32_t maximum, int32_t minimum)
 Generate a signed 32-bit random integer of a maximum and minimum value.
 
QSC_EXPORT_API uint32_t qsc_secrand_next_uint32 (void)
 Generate an unsigned 32-bit random integer.
 
QSC_EXPORT_API uint32_t qsc_secrand_next_uint32_max (uint32_t maximum)
 Generate an unsigned 32-bit random integer of a maximum value.
 
QSC_EXPORT_API uint32_t qsc_secrand_next_uint32_maxmin (uint32_t maximum, uint32_t minimum)
 Generate an unsigned 32-bit random integer of a maximum and minimum value.
 
QSC_EXPORT_API int64_t qsc_secrand_next_int64 (void)
 Generate a signed 64-bit random integer.
 
QSC_EXPORT_API int64_t qsc_secrand_next_int64_max (int64_t maximum)
 Generate a signed 64-bit random integer of a maximum value.
 
QSC_EXPORT_API int64_t qsc_secrand_next_int64_maxmin (int64_t maximum, int64_t minimum)
 Generate a signed 64-bit random integer of a maximum and minimum value.
 
QSC_EXPORT_API uint64_t qsc_secrand_next_uint64 (void)
 Generate an unsigned 64-bit random integer.
 
QSC_EXPORT_API uint64_t qsc_secrand_next_uint64_max (uint64_t maximum)
 Generate an unsigned 64-bit random integer of a maximum value.
 
QSC_EXPORT_API uint64_t qsc_secrand_next_uint64_maxmin (uint64_t maximum, uint64_t minimum)
 Generate an unsigned 64-bit random integer of a maximum and minimum value.
 
QSC_EXPORT_API void qsc_secrand_dispose (void)
 Clear the buffer and destroy the internal state.
 
QSC_EXPORT_API void qsc_secrand_initialize (const uint8_t *seed, size_t seedlen, const uint8_t *custom, size_t custlen)
 Initialize the random generator with a seed and optional customization array.
 
QSC_EXPORT_API bool qsc_secrand_generate (uint8_t *output, size_t length)
 Generate an array of pseudo-random bytes.
 

Detailed Description

Secure pseudo-random generator (PRNG) function definitions.

This module implements a secure pseudo-random generator that must be pre-keyed using the qsc_secrand_initialize() function before any random output is generated. The generator provides functions to generate random numbers of various data types (signed/unsigned integers of 8, 16, 32, and 64 bits, as well as double-precision floating point numbers) and to generate arbitrary arrays of random bytes. It relies on the underlying CSG (Custom SHAKE Generator) for cryptographic strength.

Reference Links:

Function Documentation

◆ qsc_secrand_generate()

QSC_EXPORT_API bool qsc_secrand_generate ( uint8_t * output,
size_t length )

Generate an array of pseudo-random bytes.

Parameters
output[uint8_t*] The destination array.
length[size_t] The number of bytes to generate.
Returns
[bool] Returns true if the operation succeeded.

◆ qsc_secrand_initialize()

QSC_EXPORT_API void qsc_secrand_initialize ( const uint8_t * seed,
size_t seedlen,
const uint8_t * custom,
size_t custlen )

Initialize the random generator with a seed and optional customization array.

Parameters
seed[const uint8_t*] The primary seed; must be 32 or 64 bytes in length.
seedlen[size_t] The byte length of the seed.
custom[const uint8_t*] The optional customization parameter (can be NULL).
custlen[size_t] The length of the customization array.

◆ qsc_secrand_next_char()

QSC_EXPORT_API int8_t qsc_secrand_next_char ( void )

Generate a signed 8-bit random integer.

Returns
[int8_t] Returns a signed 8-bit random integer.

◆ qsc_secrand_next_double()

QSC_EXPORT_API double qsc_secrand_next_double ( void )

Generate a random double-precision floating-point number.

Returns
[double] Returns a random double value.

◆ qsc_secrand_next_int16()

QSC_EXPORT_API int16_t qsc_secrand_next_int16 ( void )

Generate a signed 16-bit random integer.

Returns
[int16_t] Returns a signed 16-bit random integer.

◆ qsc_secrand_next_int16_max()

QSC_EXPORT_API int16_t qsc_secrand_next_int16_max ( int16_t maximum)

Generate a signed 16-bit random integer of a maximum value.

Parameters
maximum[int16_t] The maximum value of the integer.
Returns
[int16_t] Returns a signed 16-bit random integer in the range [0, maximum].

◆ qsc_secrand_next_int16_maxmin()

QSC_EXPORT_API int16_t qsc_secrand_next_int16_maxmin ( int16_t maximum,
int16_t minimum )

Generate a signed 16-bit random integer of a maximum and minimum value.

Parameters
maximum[int16_t] The maximum value of the integer.
minimum[int16_t] The minimum value of the integer.
Returns
[int16_t] Returns a signed 16-bit random integer in the range [minimum, maximum].

◆ qsc_secrand_next_int32()

QSC_EXPORT_API int32_t qsc_secrand_next_int32 ( void )

Generate a signed 32-bit random integer.

Returns
[int32_t] Returns a signed 32-bit random integer.

◆ qsc_secrand_next_int32_max()

QSC_EXPORT_API int32_t qsc_secrand_next_int32_max ( int32_t maximum)

Generate a signed 32-bit random integer of a maximum value.

Parameters
maximum[int32_t] The maximum value of the integer.
Returns
[int32_t] Returns a signed 32-bit random integer in the range [0, maximum].

◆ qsc_secrand_next_int32_maxmin()

QSC_EXPORT_API int32_t qsc_secrand_next_int32_maxmin ( int32_t maximum,
int32_t minimum )

Generate a signed 32-bit random integer of a maximum and minimum value.

Parameters
maximum[int32_t] The maximum value of the integer.
minimum[int32_t] The minimum value of the integer.
Returns
[int32_t] Returns a signed 32-bit random integer in the range [minimum, maximum].

◆ qsc_secrand_next_int64()

QSC_EXPORT_API int64_t qsc_secrand_next_int64 ( void )

Generate a signed 64-bit random integer.

Returns
[int64_t] Returns a signed 64-bit random integer.

◆ qsc_secrand_next_int64_max()

QSC_EXPORT_API int64_t qsc_secrand_next_int64_max ( int64_t maximum)

Generate a signed 64-bit random integer of a maximum value.

Parameters
maximum[int64_t] The maximum value of the integer.
Returns
[int64_t] Returns a signed 64-bit random integer in the range [0, maximum].

◆ qsc_secrand_next_int64_maxmin()

QSC_EXPORT_API int64_t qsc_secrand_next_int64_maxmin ( int64_t maximum,
int64_t minimum )

Generate a signed 64-bit random integer of a maximum and minimum value.

Parameters
maximum[int64_t] The maximum value of the integer.
minimum[int64_t] The minimum value of the integer.
Returns
[int64_t] Returns a signed 64-bit random integer in the range [minimum, maximum].

◆ qsc_secrand_next_uchar()

QSC_EXPORT_API uint8_t qsc_secrand_next_uchar ( void )

Generate an unsigned 8-bit random integer.

Returns
[uint8_t] Returns an unsigned 8-bit random integer.

◆ qsc_secrand_next_uint16()

QSC_EXPORT_API uint16_t qsc_secrand_next_uint16 ( void )

Generate an unsigned 16-bit random integer.

Returns
[uint16_t] Returns an unsigned 16-bit random integer.

◆ qsc_secrand_next_uint16_max()

QSC_EXPORT_API uint16_t qsc_secrand_next_uint16_max ( uint16_t maximum)

Generate an unsigned 16-bit random integer of a maximum value.

Parameters
maximum[uint16_t] The maximum value of the integer.
Returns
[uint16_t] Returns an unsigned 16-bit random integer in the range [0, maximum].

◆ qsc_secrand_next_uint16_maxmin()

QSC_EXPORT_API uint16_t qsc_secrand_next_uint16_maxmin ( uint16_t maximum,
uint16_t minimum )

Generate an unsigned 16-bit random integer of a maximum and minimum value.

Parameters
maximum[uint16_t] The maximum value of the integer.
minimum[uint16_t] The minimum value of the integer.
Returns
[uint16_t] Returns an unsigned 16-bit random integer in the range [minimum, maximum].

◆ qsc_secrand_next_uint32()

QSC_EXPORT_API uint32_t qsc_secrand_next_uint32 ( void )

Generate an unsigned 32-bit random integer.

Returns
[uint32_t] Returns an unsigned 32-bit random integer.

◆ qsc_secrand_next_uint32_max()

QSC_EXPORT_API uint32_t qsc_secrand_next_uint32_max ( uint32_t maximum)

Generate an unsigned 32-bit random integer of a maximum value.

Parameters
maximum[uint32_t] The maximum value of the integer.
Returns
[uint32_t] Returns an unsigned 32-bit random integer in the range [0, maximum].

◆ qsc_secrand_next_uint32_maxmin()

QSC_EXPORT_API uint32_t qsc_secrand_next_uint32_maxmin ( uint32_t maximum,
uint32_t minimum )

Generate an unsigned 32-bit random integer of a maximum and minimum value.

Parameters
maximum[uint32_t] The maximum value of the integer.
minimum[uint32_t] The minimum value of the integer.
Returns
[uint32_t] Returns an unsigned 32-bit random integer in the range [minimum, maximum].

◆ qsc_secrand_next_uint64()

QSC_EXPORT_API uint64_t qsc_secrand_next_uint64 ( void )

Generate an unsigned 64-bit random integer.

Returns
[uint64_t] Returns an unsigned 64-bit random integer.

◆ qsc_secrand_next_uint64_max()

QSC_EXPORT_API uint64_t qsc_secrand_next_uint64_max ( uint64_t maximum)

Generate an unsigned 64-bit random integer of a maximum value.

Parameters
maximum[uint64_t] The maximum value of the integer.
Returns
[uint64_t] Returns an unsigned 64-bit random integer in the range [0, maximum].

◆ qsc_secrand_next_uint64_maxmin()

QSC_EXPORT_API uint64_t qsc_secrand_next_uint64_maxmin ( uint64_t maximum,
uint64_t minimum )

Generate an unsigned 64-bit random integer of a maximum and minimum value.

Parameters
maximum[uint64_t] The maximum value of the integer.
minimum[uint64_t] The minimum value of the integer.
Returns
[uint64_t] Returns an unsigned 64-bit random integer in the range [minimum, maximum].