.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "PROVIDER-RAND 7" .TH PROVIDER-RAND 7 "2023-08-01" "3.0.10" "OpenSSL" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" provider\-rand \- The random number generation library <\-> provider functions .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& #include \& #include \& \& /* \& * 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[]); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This documentation is primarily aimed at provider authors. See \fBprovider\fR\|(7) for further information. .PP The \s-1RAND\s0 operation enables providers to implement random number generation algorithms and random number sources and make them available to applications via the \s-1API\s0 function \s-1\fBEVP_RAND\s0\fR\|(3). .SS "Context Management Functions" .IX Subsection "Context Management Functions" \&\fBOSSL_FUNC_rand_newctx()\fR should create and return a pointer to a provider side structure for holding context information during a rand operation. A pointer to this context will be passed back in a number of the other rand operation function calls. The parameter \fIprovctx\fR is the provider context generated during provider initialisation (see \fBprovider\fR\|(7)). The parameter \fIparent\fR specifies another rand instance to be used for seeding purposes. If \s-1NULL\s0 and the specific instance supports it, the operating system will be used for seeding. The parameter \fIparent_calls\fR points to the dispatch table for \fIparent\fR. Thus, the parent need not be from the same provider as the new instance. .PP \&\fBOSSL_FUNC_rand_freectx()\fR is passed a pointer to the provider side rand context in the \fImctx\fR parameter. If it receives \s-1NULL\s0 as \fIctx\fR value, it should not do anything other than return. This function should free any resources associated with that context. .SS "Random Number Generator Functions: \s-1NIST\s0" .IX Subsection "Random Number Generator Functions: NIST" These functions correspond to those defined in \s-1NIST SP 800\-90A\s0 and \s-1SP 800\-90C.\s0 .PP \&\fBOSSL_FUNC_rand_instantiate()\fR is used to instantiate the \s-1DRBG\s0 \fIctx\fR at a requested security \fIstrength\fR. In addition, \fIprediction_resistance\fR can be requested. Additional input \fIaddin\fR of length \fIaddin_len\fR bytes can optionally be provided. The parameters specified in \fIparams\fR configure the \s-1DRBG\s0 and these should be processed before instantiation. .PP \&\fBOSSL_FUNC_rand_uninstantiate()\fR is used to uninstantiate the \s-1DRBG\s0 \fIctx\fR. After being uninstantiated, a \s-1DRBG\s0 is unable to produce output until it is instantiated anew. .PP \&\fBOSSL_FUNC_rand_generate()\fR is used to generate random bytes from the \s-1DRBG\s0 \fIctx\fR. It will generate \fIoutlen\fR bytes placing them into the buffer pointed to by \&\fIout\fR. The generated bytes will meet the specified security \fIstrength\fR and, if \fIprediction_resistance\fR is true, the bytes will be produced after reseeding from a live entropy source. Additional input \fIaddin\fR of length \fIaddin_len\fR bytes can optionally be provided. .SS "Random Number Generator Functions: Additional" .IX Subsection "Random Number Generator Functions: Additional" \&\fBOSSL_FUNC_rand_nonce()\fR is used to generate a nonce of the given \fIstrength\fR with a length from \fImin_noncelen\fR to \fImax_noncelen\fR. If the output buffer \fIout\fR is \&\s-1NULL,\s0 the length of the nonce should be returned. .PP \&\fBOSSL_FUNC_rand_get_seed()\fR is used by deterministic generators to obtain their seeding material from their parent. The seed bytes will meet the specified security level of \fIentropy\fR bits and there will be between \fImin_len\fR and \fImax_len\fR inclusive bytes in total. If \fIprediction_resistance\fR is true, the bytes will be produced from a live entropy source. Additional input \fIaddin\fR of length \fIaddin_len\fR bytes can optionally be provided. A pointer to the seed material is returned in \fI*buffer\fR and this must be freed by a later call to \fBOSSL_FUNC_rand_clear_seed()\fR. .PP \&\fBOSSL_FUNC_rand_clear_seed()\fR frees a seed \fIbuffer\fR of length \fIb_len\fR bytes which was previously allocated by \fBOSSL_FUNC_rand_get_seed()\fR. .PP \&\fBOSSL_FUNC_rand_verify_zeroization()\fR is used to determine if the internal state of the \&\s-1DRBG\s0 is zero. This capability is mandated by \s-1NIST\s0 as part of the self tests, it is unlikely to be useful in other circumstances. .SS "Context Locking" .IX Subsection "Context Locking" When DRBGs are used by multiple threads, there must be locking employed to ensure their proper operation. Because locking introduces an overhead, it is disabled by default. .PP \&\fBOSSL_FUNC_rand_enable_locking()\fR allows locking to be turned on for a \s-1DRBG\s0 and all of its parent DRBGs. From this call onwards, the \s-1DRBG\s0 can be used in a thread safe manner. .PP \&\fBOSSL_FUNC_rand_lock()\fR is used to lock a \s-1DRBG.\s0 Once locked, exclusive access is guaranteed. .PP \&\fBOSSL_FUNC_rand_unlock()\fR is used to unlock a \s-1DRBG.\s0 .SS "Rand Parameters" .IX Subsection "Rand Parameters" See \s-1\fBOSSL_PARAM\s0\fR\|(3) for further details on the parameters structure used by these functions. .PP \&\fBOSSL_FUNC_rand_get_params()\fR gets details of parameter values associated with the provider algorithm and stores them in \fIparams\fR. .PP \&\fBOSSL_FUNC_rand_set_ctx_params()\fR sets rand parameters associated with the given provider side rand context \fIctx\fR to \fIparams\fR. Any parameter settings are additional to any that were previously set. Passing \s-1NULL\s0 for \fIparams\fR should return true. .PP \&\fBOSSL_FUNC_rand_get_ctx_params()\fR gets details of currently set parameter values associated with the given provider side rand context \fIctx\fR and stores them in \fIparams\fR. Passing \s-1NULL\s0 for \fIparams\fR should return true. .PP \&\fBOSSL_FUNC_rand_gettable_params()\fR, \fBOSSL_FUNC_rand_gettable_ctx_params()\fR, and \fBOSSL_FUNC_rand_settable_ctx_params()\fR all return constant \s-1\fBOSSL_PARAM\s0\fR\|(3) arrays as descriptors of the parameters that \fBOSSL_FUNC_rand_get_params()\fR, \&\fBOSSL_FUNC_rand_get_ctx_params()\fR, and \fBOSSL_FUNC_rand_set_ctx_params()\fR can handle, respectively. \fBOSSL_FUNC_rand_gettable_ctx_params()\fR and \fBOSSL_FUNC_rand_settable_ctx_params()\fR will return the parameters associated with the provider side context \fIctx\fR in its current state if it is not \s-1NULL.\s0 Otherwise, they return the parameters associated with the provider side algorithm \fIprovctx\fR. .PP Parameters currently recognised by built-in rands are as follows. Not all parameters are relevant to, or are understood by all rands: .ie n .IP """state"" (\fB\s-1OSSL_RAND_PARAM_STATE\s0\fR) " 4 .el .IP "``state'' (\fB\s-1OSSL_RAND_PARAM_STATE\s0\fR) " 4 .IX Item "state (OSSL_RAND_PARAM_STATE) " Returns the state of the random number generator. .ie n .IP """strength"" (\fB\s-1OSSL_RAND_PARAM_STRENGTH\s0\fR) " 4 .el .IP "``strength'' (\fB\s-1OSSL_RAND_PARAM_STRENGTH\s0\fR) " 4 .IX Item "strength (OSSL_RAND_PARAM_STRENGTH) " Returns the bit strength of the random number generator. .PP For rands that are also deterministic random bit generators (DRBGs), these additional parameters are recognised. Not all parameters are relevant to, or are understood by all \s-1DRBG\s0 rands: .ie n .IP """reseed_requests"" (\fB\s-1OSSL_DRBG_PARAM_RESEED_REQUESTS\s0\fR) " 4 .el .IP "``reseed_requests'' (\fB\s-1OSSL_DRBG_PARAM_RESEED_REQUESTS\s0\fR) " 4 .IX Item "reseed_requests (OSSL_DRBG_PARAM_RESEED_REQUESTS) " Reads or set the number of generate requests before reseeding the associated \s-1RAND\s0 ctx. .ie n .IP """reseed_time_interval"" (\fB\s-1OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL\s0\fR) " 4 .el .IP "``reseed_time_interval'' (\fB\s-1OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL\s0\fR) " 4 .IX Item "reseed_time_interval (OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL) " Reads or set the number of elapsed seconds before reseeding the associated \s-1RAND\s0 ctx. .ie n .IP """max_request"" (\fB\s-1OSSL_DRBG_PARAM_RESEED_REQUESTS\s0\fR) " 4 .el .IP "``max_request'' (\fB\s-1OSSL_DRBG_PARAM_RESEED_REQUESTS\s0\fR) " 4 .IX Item "max_request (OSSL_DRBG_PARAM_RESEED_REQUESTS) " Specifies the maximum number of bytes that can be generated in a single call to OSSL_FUNC_rand_generate. .ie n .IP """min_entropylen"" (\fB\s-1OSSL_DRBG_PARAM_MIN_ENTROPYLEN\s0\fR) " 4 .el .IP "``min_entropylen'' (\fB\s-1OSSL_DRBG_PARAM_MIN_ENTROPYLEN\s0\fR) " 4 .IX Item "min_entropylen (OSSL_DRBG_PARAM_MIN_ENTROPYLEN) " .PD 0 .ie n .IP """max_entropylen"" (\fB\s-1OSSL_DRBG_PARAM_MAX_ENTROPYLEN\s0\fR) " 4 .el .IP "``max_entropylen'' (\fB\s-1OSSL_DRBG_PARAM_MAX_ENTROPYLEN\s0\fR) " 4 .IX Item "max_entropylen (OSSL_DRBG_PARAM_MAX_ENTROPYLEN) " .PD Specify the minimum and maximum number of bytes of random material that can be used to seed the \s-1DRBG.\s0 .ie n .IP """min_noncelen"" (\fB\s-1OSSL_DRBG_PARAM_MIN_NONCELEN\s0\fR) " 4 .el .IP "``min_noncelen'' (\fB\s-1OSSL_DRBG_PARAM_MIN_NONCELEN\s0\fR) " 4 .IX Item "min_noncelen (OSSL_DRBG_PARAM_MIN_NONCELEN) " .PD 0 .ie n .IP """max_noncelen"" (\fB\s-1OSSL_DRBG_PARAM_MAX_NONCELEN\s0\fR) " 4 .el .IP "``max_noncelen'' (\fB\s-1OSSL_DRBG_PARAM_MAX_NONCELEN\s0\fR) " 4 .IX Item "max_noncelen (OSSL_DRBG_PARAM_MAX_NONCELEN) " .PD Specify the minimum and maximum number of bytes of nonce that can be used to instantiate the \s-1DRBG.\s0 .ie n .IP """max_perslen"" (\fB\s-1OSSL_DRBG_PARAM_MAX_PERSLEN\s0\fR) " 4 .el .IP "``max_perslen'' (\fB\s-1OSSL_DRBG_PARAM_MAX_PERSLEN\s0\fR) " 4 .IX Item "max_perslen (OSSL_DRBG_PARAM_MAX_PERSLEN) " .PD 0 .ie n .IP """max_adinlen"" (\fB\s-1OSSL_DRBG_PARAM_MAX_ADINLEN\s0\fR) " 4 .el .IP "``max_adinlen'' (\fB\s-1OSSL_DRBG_PARAM_MAX_ADINLEN\s0\fR) " 4 .IX Item "max_adinlen (OSSL_DRBG_PARAM_MAX_ADINLEN) " .PD Specify the minimum and maximum number of bytes of personalisation string that can be used with the \s-1DRBG.\s0 .ie n .IP """reseed_counter"" (\fB\s-1OSSL_DRBG_PARAM_RESEED_COUNTER\s0\fR) " 4 .el .IP "``reseed_counter'' (\fB\s-1OSSL_DRBG_PARAM_RESEED_COUNTER\s0\fR) " 4 .IX Item "reseed_counter (OSSL_DRBG_PARAM_RESEED_COUNTER) " Specifies the number of times the \s-1DRBG\s0 has been seeded or reseeded. .ie n .IP """digest"" (\fB\s-1OSSL_DRBG_PARAM_DIGEST\s0\fR) <\s-1UTF8\s0 string>" 4 .el .IP "``digest'' (\fB\s-1OSSL_DRBG_PARAM_DIGEST\s0\fR) <\s-1UTF8\s0 string>" 4 .IX Item "digest (OSSL_DRBG_PARAM_DIGEST) " .PD 0 .ie n .IP """cipher"" (\fB\s-1OSSL_DRBG_PARAM_CIPHER\s0\fR) <\s-1UTF8\s0 string>" 4 .el .IP "``cipher'' (\fB\s-1OSSL_DRBG_PARAM_CIPHER\s0\fR) <\s-1UTF8\s0 string>" 4 .IX Item "cipher (OSSL_DRBG_PARAM_CIPHER) " .ie n .IP """mac"" (\fB\s-1OSSL_DRBG_PARAM_MAC\s0\fR) <\s-1UTF8\s0 string>" 4 .el .IP "``mac'' (\fB\s-1OSSL_DRBG_PARAM_MAC\s0\fR) <\s-1UTF8\s0 string>" 4 .IX Item "mac (OSSL_DRBG_PARAM_MAC) " .PD Sets the name of the underlying cipher, digest or \s-1MAC\s0 to be used. It must name a suitable algorithm for the \s-1DRBG\s0 that's being used. .ie n .IP """properties"" (\fB\s-1OSSL_DRBG_PARAM_PROPERTIES\s0\fR) <\s-1UTF8\s0 string>" 4 .el .IP "``properties'' (\fB\s-1OSSL_DRBG_PARAM_PROPERTIES\s0\fR) <\s-1UTF8\s0 string>" 4 .IX Item "properties (OSSL_DRBG_PARAM_PROPERTIES) " 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. .SH "RETURN VALUES" .IX Header "RETURN VALUES" \&\fBOSSL_FUNC_rand_newctx()\fR should return the newly created provider side rand context, or \s-1NULL\s0 on failure. .PP \&\fBOSSL_FUNC_rand_gettable_params()\fR, \fBOSSL_FUNC_rand_gettable_ctx_params()\fR and \&\fBOSSL_FUNC_rand_settable_ctx_params()\fR should return a constant \s-1\fBOSSL_PARAM\s0\fR\|(3) array, or \s-1NULL\s0 if none is offered. .PP \&\fBOSSL_FUNC_rand_nonce()\fR returns the size of the generated nonce, or 0 on error. .PP \&\fBOSSL_FUNC_rand_get_seed()\fR returns the size of the generated seed, or 0 on error. .PP All of the remaining functions should return 1 for success or 0 on error. .SH "NOTES" .IX Header "NOTES" The \s-1RAND\s0 life-cycle is described in \fBlife_cycle\-rand\fR\|(7). Providers should ensure that the various transitions listed there are supported. At some point the \s-1EVP\s0 layer will begin enforcing the listed transitions. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBprovider\fR\|(7), \&\s-1\fBRAND\s0\fR\|(7), \&\s-1\fBEVP_RAND\s0\fR\|(7), \&\fBlife_cycle\-rand\fR\|(7), \&\s-1\fBEVP_RAND\s0\fR\|(3) .SH "HISTORY" .IX Header "HISTORY" The provider \s-1RAND\s0 interface was introduced in OpenSSL 3.0. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2020\-2021 The OpenSSL Project Authors. All Rights Reserved. .PP Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at .