liboqs
Loading...
Searching...
No Matches
rand.h File Reference

Random number generator. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <oqs/common.h>

Go to the source code of this file.

Macros

#define OQS_RAND_alg_system   "system"
 
#define OQS_RAND_alg_openssl   "OpenSSL"
 

Functions

OQS_API OQS_STATUS OQS_randombytes_switch_algorithm (const char *algorithm)
 
OQS_API void OQS_randombytes_custom_algorithm (void(*algorithm_ptr)(uint8_t *, size_t))
 
OQS_API void OQS_randombytes (uint8_t *random_array, size_t bytes_to_read)
 

Detailed Description

Random number generator.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ OQS_RAND_alg_openssl

#define OQS_RAND_alg_openssl   "OpenSSL"

Algorithm identifier for using OpenSSL's PRNG.

◆ OQS_RAND_alg_system

#define OQS_RAND_alg_system   "system"

Algorithm identifier for system PRNG.

Function Documentation

◆ OQS_randombytes()

OQS_API void OQS_randombytes ( uint8_t * random_array,
size_t bytes_to_read )

Fills the given memory with the requested number of (pseudo)random bytes.

This implementation uses whichever algorithm has been selected by OQS_randombytes_switch_algorithm. The default is OQS_randombytes_system, which reads bytes from a system specific default source.

The caller is responsible for providing a buffer allocated with sufficient room.

Parameters
[out]random_arrayPointer to the memory to fill with (pseudo)random bytes
[in]bytes_to_readThe number of random bytes to read into memory

◆ OQS_randombytes_custom_algorithm()

OQS_API void OQS_randombytes_custom_algorithm ( void(* algorithm_ptr )(uint8_t *, size_t))

Switches OQS_randombytes to use the given function.

This allows additional custom RNGs besides the provided ones. The provided RNG function must have the same signature as OQS_randombytes.

Parameters
[in]algorithm_ptrPointer to the RNG function to use.

◆ OQS_randombytes_switch_algorithm()

OQS_API OQS_STATUS OQS_randombytes_switch_algorithm ( const char * algorithm)

Switches OQS_randombytes to use the specified algorithm.

Warning
In case you have set a custom algorithm using OQS_randombytes_custom_algorithm before, this function will overwrite it again. Hence, you have to set your custom algorithm again after calling this function.
Parameters
[in]algorithmThe name of the algorithm to use.
Returns
OQS_SUCCESS if algorithm is a supported algorithm name, OQS_ERROR otherwise.