Link Search Menu Expand Document

src/common/rand/rand.h

Random number generator.

SPDX-License-Identifier: MIT



Includes


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

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)
OQS_API void OQS_randombytes_nist_kat_init_256bit(const uint8_t *entropy_input, const uint8_t *personalization_string)

OQS_randombytes_switch_algorithm

OQS_API OQS_STATUS OQS_randombytes_switch_algorithm(const char *algorithm)

Switches OQS_randombytes to use the specified algorithm.

Parameters

const char * algorithm

The name of the algorithm to use.

Returns

OQS_SUCCESS if algorithm is a supported algorithm name, OQS_ERROR otherwise.


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

void(*)(uint8_t *, size_t) algorithm_ptr

Pointer to the RNG function to use.


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 directly from /dev/urandom.

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

Parameters

uint8_t * random_array

Pointer to the memory to fill with (pseudo)random bytes

size_t bytes_to_read

The number of random bytes to read into memory


OQS_randombytes_nist_kat_init_256bit

OQS_API void OQS_randombytes_nist_kat_init_256bit(const uint8_t *entropy_input, const uint8_t *personalization_string)

Initializes the NIST DRBG with a given seed and with 256-bit security.

Parameters

const uint8_t * entropy_input

The seed; must be exactly 48 bytes

const uint8_t * personalization_string

An optional personalization string; may be NULL; if not NULL, must be at least 48 bytes long




Macros

#define OQS_RAND_alg_system "system"

Algorithm identifier for system PRNG.

#define OQS_RAND_alg_nist_kat "NIST-KAT"

Algorithm identifier for NIST deterministic RNG for KATs.

#define OQS_RAND_alg_openssl "OpenSSL"

Algorithm identifier for using OpenSSL's PRNG.








Copyright © 2017-2020 The Open Quantum Safe Project.
This site uses Just the Docs, a documentation theme for Jekyll. Background image by Rick Doble.