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

Cryptographic System Entropy Provider Header. More...

#include "common.h"

Go to the source code of this file.

Macros

#define QSC_CSP_SEED_MAX   1024000ULL
 The maximum number of seed bytes that can be extracted from a single generate call.
 

Functions

QSC_EXPORT_API bool qsc_csp_generate (uint8_t *output, size_t length)
 Retrieve pseudo-random bytes from the system entropy provider.
 
QSC_EXPORT_API uint16_t qsc_csp_uint16 (void)
 Generate a random 16-bit unsigned integer.
 
QSC_EXPORT_API uint32_t qsc_csp_uint32 (void)
 Generate a random 32-bit unsigned integer.
 
QSC_EXPORT_API uint64_t qsc_csp_uint64 (void)
 Generate a random 64-bit unsigned integer.
 

Detailed Description

Cryptographic System Entropy Provider Header.

This header provides the interface for the Cryptographic System Entropy Provider. It offers access to pseudo-random data generated by the system's entropy source. On Windows systems, the provider uses the CryptGenRandom API; on POSIX systems, it reads from the /dev/urandom device. In environments where arc4random_buf is available, that function is used directly.

Example Usage:

#include "csp.h"
uint8_t buffer[64];
if (qsc_csp_generate(buffer, sizeof(buffer)))
{
// buffer now contains 64 bytes of pseudo-random data.
}
uint32_t randomValue = qsc_csp_uint32();
Cryptographic System Entropy Provider Header.
QSC_EXPORT_API bool qsc_csp_generate(uint8_t *output, size_t length)
Retrieve pseudo-random bytes from the system entropy provider.
Definition csp.c:27

This provider is recommended to be combined with additional entropy sources to ensure robust randomness.

Reference Links

Function Documentation

◆ qsc_csp_generate()

QSC_EXPORT_API bool qsc_csp_generate ( uint8_t * output,
size_t length )

Retrieve pseudo-random bytes from the system entropy provider.

This function fills the provided output array with pseudo-random bytes sourced from the operating system's entropy mechanism. On Windows systems, it utilizes the CryptGenRandom function from the Windows API, whereas on Posix systems it reads from the /dev/urandom device. In environments supporting arc4random_buf, that function is used directly.

Parameters
output[uint8_t*] Pointer to the byte array where the random data will be stored.
length[size_t] The number of random bytes to generate. Must not exceed QSC_CSP_SEED_MAX.
Returns
[bool] Returns true if the random data was successfully generated; otherwise, false.
See also
qsc_csp_uint16(), qsc_csp_uint32(), qsc_csp_uint64()

◆ qsc_csp_uint16()

QSC_EXPORT_API uint16_t qsc_csp_uint16 ( void )

Generate a random 16-bit unsigned integer.

This function generates a pseudo-random 16-bit unsigned integer by retrieving the appropriate number of bytes from the system entropy provider.

Returns
[uint16_t] Returns the pseudo-random 16-bit unsigned integer.
See also
qsc_csp_generate()

◆ qsc_csp_uint32()

QSC_EXPORT_API uint32_t qsc_csp_uint32 ( void )

Generate a random 32-bit unsigned integer.

This function generates a pseudo-random 32-bit unsigned integer by retrieving the appropriate number of bytes from the system entropy provider.

Returns
[uint32_t] Returns the pseudo-random 32-bit unsigned integer.
See also
qsc_csp_generate()

◆ qsc_csp_uint64()

QSC_EXPORT_API uint64_t qsc_csp_uint64 ( void )

Generate a random 64-bit unsigned integer.

This function generates a pseudo-random 64-bit unsigned integer by retrieving the appropriate number of bytes from the system entropy provider.

Returns
[uint64_t] Returns the pseudo-random 64-bit unsigned integer.
See also
qsc_csp_generate()