PROVIDER-RAND(7ossl)
π PROVIDER-RAND(7ossl) π
okay so bestie, welcome to the OpenSSL manual page for provider-rand β that's the 7ossl one, iykyk. this page is literally about the random number generation library <-> provider functions, and the vibe is very "function pointer dispatch table main character energy." no cap.
β¨ NAME β¨
provider-rand - The random number generation library <-> provider functions
slay, that's the whole name. it's giving randomness provider realness π
π¦ SYNOPSIS π¦
here's the synopsis, and it's important: none of these are actual functions β they're displayed like this for the function signatures for functions that are offered as function pointers in OSSL_DISPATCH arrays. literally the comment says it, so we're keeping it exact.
#include <openssl/core_dispatch.h>
#include <openssl/core_names.h>
/*
* None of these are actual functions, but are displayed like this for
* the function signatures for functions that are offered as function
* pointers in OSSL_DISPATCH arrays.
*/
/* Context management */
void *OSSL_FUNC_rand_newctx(void *provctx, void *parent,
const OSSL_DISPATCH *parent_calls);
void OSSL_FUNC_rand_freectx(void *ctx);
/* Random number generator functions: NIST */
int OSSL_FUNC_rand_instantiate(void *ctx, unsigned int strength,
int prediction_resistance,
const unsigned char *pstr, size_t pstr_len,
const OSSL_PARAM params[]);
int OSSL_FUNC_rand_uninstantiate(void *ctx);
int OSSL_FUNC_rand_generate(void *ctx, unsigned char *out, size_t outlen,
unsigned int strength, int prediction_resistance,
const unsigned char *addin, size_t addin_len);
int OSSL_FUNC_rand_reseed(void *ctx, int prediction_resistance,
const unsigned char *ent, size_t ent_len,
const unsigned char *addin, size_t addin_len);
/* Random number generator functions: additional */
size_t OSSL_FUNC_rand_nonce(void *ctx, unsigned char *out, size_t outlen,
int strength, size_t min_noncelen,
size_t max_noncelen);
size_t OSSL_FUNC_rand_get_seed(void *ctx, unsigned char **buffer,
int entropy, size_t min_len, size_t max_len,
int prediction_resistance,
const unsigned char *adin, size_t adin_len);
void OSSL_FUNC_rand_clear_seed(void *ctx, unsigned char *buffer, size_t b_len);
int OSSL_FUNC_rand_verify_zeroization(void *ctx);
/* Context Locking */
int OSSL_FUNC_rand_enable_locking(void *ctx);
int OSSL_FUNC_rand_lock(void *ctx);
void OSSL_FUNC_rand_unlock(void *ctx);
/* RAND parameter descriptors */
const OSSL_PARAM *OSSL_FUNC_rand_gettable_params(void *provctx);
const OSSL_PARAM *OSSL_FUNC_rand_gettable_ctx_params(void *ctx, void *provctx);
const OSSL_PARAM *OSSL_FUNC_rand_settable_ctx_params(void *ctx, void *provctx);
/* RAND parameters */
int OSSL_FUNC_rand_get_params(OSSL_PARAM params[]);
int OSSL_FUNC_rand_get_ctx_params(void *ctx, OSSL_PARAM params[]);
int OSSL_FUNC_rand_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
π« DESCRIPTION π«
ok so real talk: this page is mainly for provider authors, bestie. if that's not you, go peek at provider(7) first, k?
The RAND operation is what lets providers implement random number generation algorithms and random number sources and then hand them to applications through the API function EVP_RAND(3). it's giving very much the plug that makes randomness happen β¨
π Context Management Functions π
OSSL_FUNC_rand_newctx()β should create and return a pointer to a provider side structure that holds context information during a rand operation. that pointer gets passed back in a bunch of the other rand operation function calls, so likeβ¦ keep track of it π- the
provctxparameter is the provider context that was generated during provider initialisation (seeprovider(7)). - the
parentparameter specifies another rand instance to be used for seeding purposes. if it'sNULLand the specific instance supports it, the operating system will be used for seeding. π«Ά - the
parent_callsparameter points to the dispatch table forparent. so the parent does not need to come from the same provider as the new instance β cross-provider collab era π
- the
OSSL_FUNC_rand_freectx()β is passed a pointer to the provider side rand context in themctxparameter. if it receivesNULLas thectxvalue, it should not do anything other than return (like, just leave, no drama π). this function should free any resources associated with that context.
π₯ Random Number Generator Functions: NIST π₯
these functions correspond to those defined in NIST SP 800-90A and SP 800-90C. very official, very secure, we love to see it.
OSSL_FUNC_rand_instantiate()β used to instantiate the DRBGctxat a requested security strength. plus,prediction_resistancecan be requested. additional inputaddinof lengthaddin_lenbytes can optionally be provided. the parameters specified inparamsconfigure the DRBG, and these should be processed before instantiation. β¨OSSL_FUNC_rand_uninstantiate()β used to uninstantiate the DRBGctx. after being uninstantiated, a DRBG is unable to produce output until it is instantiated anew. so like, it's on a break. no output for you πOSSL_FUNC_rand_generate()β used to generate random bytes from the DRBGctx. it will generateoutlenbytes and place them into the buffer pointed to byout. the generated bytes will meet the specified security strength and, ifprediction_resistanceis true, the bytes will be produced after reseeding from a live entropy source. additional inputaddinof lengthaddin_lenbytes can optionally be provided. slay π
πΈ Random Number Generator Functions: Additional πΈ
OSSL_FUNC_rand_nonce()β used to generate a nonce of the given strength with a length frommin_noncelentomax_noncelen. if the output bufferoutisNULL, the length of the nonce should be returned. iykyk πOSSL_FUNC_rand_get_seed()β used by deterministic generators to obtain their seeding material from their parent. the seed bytes will meet the specified security level of entropy bits and there will be betweenmin_lenandmax_leninclusive bytes in total. ifprediction_resistanceis true, the bytes will be produced from a live entropy source. additional inputaddinof lengthaddin_lenbytes can optionally be provided. a pointer to the seed material is returned in*buffer, and this must be freed by a later call toOSSL_FUNC_rand_clear_seed(). don't forget, bestie, that's a leak otherwise πOSSL_FUNC_rand_clear_seed()β frees a seed buffer of lengthb_lenbytes which was previously allocated byOSSL_FUNC_rand_get_seed(). the cleanup queen we deserve πOSSL_FUNC_rand_verify_zeroization()β used to determine if the internal state of the DRBG is zero. this capability is mandated by NIST as part of the self tests, and it is unlikely to be useful in other circumstances. so like, it's a vibe check that only NIST asked for π
π Context Locking π
when DRBGs are used by multiple threads, there must be locking employed to ensure their proper operation. but because locking introduces an overhead, it is disabled by default. tradeoffs, bestie, tradeoffs.
OSSL_FUNC_rand_enable_locking()β allows locking to be turned on for a DRBG and all of its parent DRBGs. from this call onwards, the DRBG can be used in a thread safe manner. it's giving main character energy for your multithreaded app β¨OSSL_FUNC_rand_lock()β used to lock a DRBG. once locked, exclusive access is guaranteed. no sharing, no interruptions πOSSL_FUNC_rand_unlock()β used to unlock a DRBG. ok you can come back in now π«Ά
π¦ Rand Parameters π¦
see OSSL_PARAM(3) for further details on the parameters structure these functions use.
OSSL_FUNC_rand_get_params()β gets details of parameter values associated with the provider algorithm and stores them inparams.OSSL_FUNC_rand_set_ctx_params()β sets rand parameters associated with the given provider side rand contextctxtoparams. any parameter settings are additional to any that were previously set (so it's additive, not a reset, ok?). passingNULLforparamsshould return true. β¨OSSL_FUNC_rand_get_ctx_params()β gets details of currently set parameter values associated with the given provider side rand contextctxand stores them inparams. passingNULLforparamsshould return true. πOSSL_FUNC_rand_gettable_params(),OSSL_FUNC_rand_gettable_ctx_params(), andOSSL_FUNC_rand_settable_ctx_params()β all return constantOSSL_PARAM(3)arrays as descriptors of the parameters thatOSSL_FUNC_rand_get_params(),OSSL_FUNC_rand_get_ctx_params(), andOSSL_FUNC_rand_set_ctx_params()can handle, respectively.OSSL_FUNC_rand_gettable_ctx_params()andOSSL_FUNC_rand_settable_ctx_params()will return the parameters associated with the provider side contextctxin its current state if it is notNULL. otherwise, they return the parameters associated with the provider side algorithmprovctx.
parameters currently recognised by built-in rands are as follows. not all parameters are relevant to, or are understood by all rands, so don't assume, bestie:
"state"(OSSL_RAND_PARAM_STATE)<integer>β returns the state of the random number generator. π"strength"(OSSL_RAND_PARAM_STRENGTH)<unsigned integer>β returns the bit strength of the random number generator."fips-indicator"(OSSL_RAND_PARAM_FIPS_APPROVED_INDICATOR)<integer>β a getter that returns1if the operation is FIPS approved, or0otherwise. this option is used by the OpenSSL FIPS provider and is not supported by allEVP_RANDsources.
for rands that are also deterministic random bit generators (DRBGs), these additional parameters are recognised. again, not all parameters are relevant to, or are understood by all DRBG rands:
"reseed_requests"(OSSL_DRBG_PARAM_RESEED_REQUESTS)<unsigned integer>β reads or set the number of generate requests before reseeding the associated RANDctx."reseed_time_interval"(OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL)<integer>β reads or set the number of elapsed seconds before reseeding the associated RANDctx. β°"max_request"(OSSL_DRBG_PARAM_RESEED_REQUESTS)<unsigned integer>β specifies the maximum number of bytes that can be generated in a single call toOSSL_FUNC_rand_generate."min_entropylen"(OSSL_DRBG_PARAM_MIN_ENTROPYLEN)<unsigned integer>and"max_entropylen"(OSSL_DRBG_PARAM_MAX_ENTROPYLEN)<unsigned integer>β specify the minimum and maximum number of bytes of random material that can be used to seed the DRBG."min_noncelen"(OSSL_DRBG_PARAM_MIN_NONCELEN)<unsigned integer>and"max_noncelen"(OSSL_DRBG_PARAM_MAX_NONCELEN)<unsigned integer>β specify the minimum and maximum number of bytes of nonce that can be used to instantiate the DRBG."max_perslen"(OSSL_DRBG_PARAM_MAX_PERSLEN)<unsigned integer>and"max_adinlen"(OSSL_DRBG_PARAM_MAX_ADINLEN)<unsigned integer>β specify the minimum and maximum number of bytes of personalisation string that can be used with the DRBG."reseed_counter"(OSSL_DRBG_PARAM_RESEED_COUNTER)<unsigned integer>β specifies the number of times the DRBG has been seeded or reseeded. π"digest"(OSSL_DRBG_PARAM_DIGEST)<UTF8 string>,"cipher"(OSSL_DRBG_PARAM_CIPHER)<UTF8 string>,"mac"(OSSL_DRBG_PARAM_MAC)<UTF8 string>β sets the name of the underlying cipher, digest or MAC to be used. it must name a suitable algorithm for the DRBG that's being used. no random picks, ok? π"properties"(OSSL_DRBG_PARAM_PROPERTIES)<UTF8 string>β sets the properties to be queried when trying to fetch an underlying algorithm. this must be given together with the algorithm naming parameter to be considered valid. they're a package deal π«Ά
the OpenSSL FIPS provider also supports the following parameters:
"fips-indicator"(OSSL_DRBG_PARAM_FIPS_APPROVED_INDICATOR)<integer>β a getter that returns1if the operation is FIPS approved, or0otherwise. this may be used after callingOSSL_FUNC_rand_generate(). it may return0if the"digest-check"is set to0."digest-check"(OSSL_DRBG_PARAM_FIPS_DIGEST_CHECK)<integer>β if required this parameter should be set before the digest is set. the default value of1causes an error when the digest is set if the digest is not FIPS approved (e.g. truncated digests). setting this to0will ignore the error and set the approved"fips-indicator"to0.
β οΈ heads up bestie: this option breaks FIPS compliance if it causes the approved"fips-indicator"to return0. like, actually. be careful.
β RETURN VALUES β
OSSL_FUNC_rand_newctx()β should return the newly created provider side rand context, orNULLon failure.OSSL_FUNC_rand_gettable_params(),OSSL_FUNC_rand_gettable_ctx_params()andOSSL_FUNC_rand_settable_ctx_params()β should return a constantOSSL_PARAM(3)array, orNULLif none is offered.OSSL_FUNC_rand_nonce()β returns the size of the generated nonce, or0on error.OSSL_FUNC_rand_get_seed()β returns the size of the generated seed, or0on error.- all of the remaining functions β should return
1for success or0on error. classic β
π§ NOTES π§
the RAND life-cycle is described in life_cycle-rand(7). providers should ensure that the various transitions listed there are supported π«Ά. at some point the EVP layer will begin enforcing the listed transitions, so likeβ¦ get on that.
π SEE ALSO π
provider(7), RAND(7), EVP_RAND(7), life_cycle-rand(7), EVP_RAND(3)
π HISTORY π
the provider RAND interface was introduced in OpenSSL 3.0. the Rand Parameters "fips-indicator" and "digest-check" were added in OpenSSL 3.4. glow-up confirmed β¨
π COPYRIGHT π
Copyright 2020-2024 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
sooo that's the whole page, bestie π this was PROVIDER-RAND(7ossl), version 3.5.6, dated 2026-04-07 β go forth and generate randomness responsibly, ily, bye ππ¦β¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms