1PROVIDER-RAND(7ossl)                OpenSSL               PROVIDER-RAND(7ossl)
2
3
4

NAME

6       provider-rand - The random number generation library <-> provider
7       functions
8

SYNOPSIS

10        #include <openssl/core_dispatch.h>
11        #include <openssl/core_names.h>
12
13        /*
14         * None of these are actual functions, but are displayed like this for
15         * the function signatures for functions that are offered as function
16         * pointers in OSSL_DISPATCH arrays.
17         */
18
19        /* Context management */
20        void *OSSL_FUNC_rand_newctx(void *provctx, void *parent,
21                                    const OSSL_DISPATCH *parent_calls);
22        void OSSL_FUNC_rand_freectx(void *ctx);
23
24        /* Random number generator functions: NIST */
25        int OSSL_FUNC_rand_instantiate(void *ctx, unsigned int strength,
26                                       int prediction_resistance,
27                                       const unsigned char *pstr, size_t pstr_len,
28                                       const OSSL_PARAM params[]);
29        int OSSL_FUNC_rand_uninstantiate(void *ctx);
30        int OSSL_FUNC_rand_generate(void *ctx, unsigned char *out, size_t outlen,
31                                    unsigned int strength, int prediction_resistance,
32                                    const unsigned char *addin, size_t addin_len);
33        int OSSL_FUNC_rand_reseed(void *ctx, int prediction_resistance,
34                                  const unsigned char *ent, size_t ent_len,
35                                  const unsigned char *addin, size_t addin_len);
36
37        /* Random number generator functions: additional */
38        size_t OSSL_FUNC_rand_nonce(void *ctx, unsigned char *out, size_t outlen,
39                                    int strength, size_t min_noncelen,
40                                    size_t max_noncelen);
41        size_t OSSL_FUNC_rand_get_seed(void *ctx, unsigned char **buffer,
42                                       int entropy, size_t min_len, size_t max_len,
43                                       int prediction_resistance,
44                                       const unsigned char *adin, size_t adin_len);
45        void OSSL_FUNC_rand_clear_seed(void *ctx, unsigned char *buffer, size_t b_len);
46        int OSSL_FUNC_rand_verify_zeroization(void *ctx);
47
48        /* Context Locking */
49        int OSSL_FUNC_rand_enable_locking(void *ctx);
50        int OSSL_FUNC_rand_lock(void *ctx);
51        void OSSL_FUNC_rand_unlock(void *ctx);
52
53        /* RAND parameter descriptors */
54        const OSSL_PARAM *OSSL_FUNC_rand_gettable_params(void *provctx);
55        const OSSL_PARAM *OSSL_FUNC_rand_gettable_ctx_params(void *ctx, void *provctx);
56        const OSSL_PARAM *OSSL_FUNC_rand_settable_ctx_params(void *ctx, void *provctx);
57
58        /* RAND parameters */
59        int OSSL_FUNC_rand_get_params(OSSL_PARAM params[]);
60        int OSSL_FUNC_rand_get_ctx_params(void *ctx, OSSL_PARAM params[]);
61        int OSSL_FUNC_rand_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
62

DESCRIPTION

64       This documentation is primarily aimed at provider authors. See
65       provider(7) for further information.
66
67       The RAND operation enables providers to implement random number
68       generation algorithms and random number sources and make them available
69       to applications via the API function EVP_RAND(3).
70
71   Context Management Functions
72       OSSL_FUNC_rand_newctx() should create and return a pointer to a
73       provider side structure for holding context information during a rand
74       operation.  A pointer to this context will be passed back in a number
75       of the other rand operation function calls.  The parameter provctx is
76       the provider context generated during provider initialisation (see
77       provider(7)).  The parameter parent specifies another rand instance to
78       be used for seeding purposes.  If NULL and the specific instance
79       supports it, the operating system will be used for seeding.  The
80       parameter parent_calls points to the dispatch table for parent.  Thus,
81       the parent need not be from the same provider as the new instance.
82
83       OSSL_FUNC_rand_freectx() is passed a pointer to the provider side rand
84       context in the mctx parameter.  If it receives NULL as ctx value, it
85       should not do anything other than return.  This function should free
86       any resources associated with that context.
87
88   Random Number Generator Functions: NIST
89       These functions correspond to those defined in NIST SP 800-90A and SP
90       800-90C.
91
92       OSSL_FUNC_rand_instantiate() is used to instantiate the DRBG ctx at a
93       requested security strength.  In addition, prediction_resistance can be
94       requested.  Additional input addin of length addin_len bytes can
95       optionally be provided.  The parameters specified in params configure
96       the DRBG and these should be processed before instantiation.
97
98       OSSL_FUNC_rand_uninstantiate() is used to uninstantiate the DRBG ctx.
99       After being uninstantiated, a DRBG is unable to produce output until it
100       is instantiated anew.
101
102       OSSL_FUNC_rand_generate() is used to generate random bytes from the
103       DRBG ctx.  It will generate outlen bytes placing them into the buffer
104       pointed to by out.  The generated bytes will meet the specified
105       security strength and, if prediction_resistance is true, the bytes will
106       be produced after reseeding from a live entropy source.  Additional
107       input addin of length addin_len bytes can optionally be provided.
108
109   Random Number Generator Functions: Additional
110       OSSL_FUNC_rand_nonce() is used to generate a nonce of the given
111       strength with a length from min_noncelen to max_noncelen. If the output
112       buffer out is NULL, the length of the nonce should be returned.
113
114       OSSL_FUNC_rand_get_seed() is used by deterministic generators to obtain
115       their seeding material from their parent.  The seed bytes will meet the
116       specified security level of entropy bits and there will be between
117       min_len and max_len inclusive bytes in total.  If prediction_resistance
118       is true, the bytes will be produced from a live entropy source.
119       Additional input addin of length addin_len bytes can optionally be
120       provided.  A pointer to the seed material is returned in *buffer and
121       this must be freed by a later call to OSSL_FUNC_rand_clear_seed().
122
123       OSSL_FUNC_rand_clear_seed() frees a seed buffer of length b_len bytes
124       which was previously allocated by OSSL_FUNC_rand_get_seed().
125
126       OSSL_FUNC_rand_verify_zeroization() is used to determine if the
127       internal state of the DRBG is zero.  This capability is mandated by
128       NIST as part of the self tests, it is unlikely to be useful in other
129       circumstances.
130
131   Context Locking
132       When DRBGs are used by multiple threads, there must be locking employed
133       to ensure their proper operation.  Because locking introduces an
134       overhead, it is disabled by default.
135
136       OSSL_FUNC_rand_enable_locking() allows locking to be turned on for a
137       DRBG and all of its parent DRBGs.  From this call onwards, the DRBG can
138       be used in a thread safe manner.
139
140       OSSL_FUNC_rand_lock() is used to lock a DRBG.  Once locked, exclusive
141       access is guaranteed.
142
143       OSSL_FUNC_rand_unlock() is used to unlock a DRBG.
144
145   Rand Parameters
146       See OSSL_PARAM(3) for further details on the parameters structure used
147       by these functions.
148
149       OSSL_FUNC_rand_get_params() gets details of parameter values associated
150       with the provider algorithm and stores them in params.
151
152       OSSL_FUNC_rand_set_ctx_params() sets rand parameters associated with
153       the given provider side rand context ctx to params.  Any parameter
154       settings are additional to any that were previously set.  Passing NULL
155       for params should return true.
156
157       OSSL_FUNC_rand_get_ctx_params() gets details of currently set parameter
158       values associated with the given provider side rand context ctx and
159       stores them in params.  Passing NULL for params should return true.
160
161       OSSL_FUNC_rand_gettable_params(), OSSL_FUNC_rand_gettable_ctx_params(),
162       and OSSL_FUNC_rand_settable_ctx_params() all return constant OSSL_PARAM
163       arrays as descriptors of the parameters that
164       OSSL_FUNC_rand_get_params(), OSSL_FUNC_rand_get_ctx_params(), and
165       OSSL_FUNC_rand_set_ctx_params() can handle, respectively.
166       OSSL_FUNC_rand_gettable_ctx_params() and
167       OSSL_FUNC_rand_settable_ctx_params() will return the parameters
168       associated with the provider side context ctx in its current state if
169       it is not NULL.  Otherwise, they return the parameters associated with
170       the provider side algorithm provctx.
171
172       Parameters currently recognised by built-in rands are as follows. Not
173       all parameters are relevant to, or are understood by all rands:
174
175       "state" (OSSL_RAND_PARAM_STATE) <integer>
176           Returns the state of the random number generator.
177
178       "strength" (OSSL_RAND_PARAM_STRENGTH) <unsigned integer>
179           Returns the bit strength of the random number generator.
180
181       For rands that are also deterministic random bit generators (DRBGs),
182       these additional parameters are recognised. Not all parameters are
183       relevant to, or are understood by all DRBG rands:
184
185       "reseed_requests" (OSSL_DRBG_PARAM_RESEED_REQUESTS) <unsigned integer>
186           Reads or set the number of generate requests before reseeding the
187           associated RAND ctx.
188
189       "reseed_time_interval" (OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL) <integer>
190           Reads or set the number of elapsed seconds before reseeding the
191           associated RAND ctx.
192
193       "max_request" (OSSL_DRBG_PARAM_RESEED_REQUESTS) <unsigned integer>
194           Specifies the maximum number of bytes that can be generated in a
195           single call to OSSL_FUNC_rand_generate.
196
197       "min_entropylen" (OSSL_DRBG_PARAM_MIN_ENTROPYLEN) <unsigned integer>
198       "max_entropylen" (OSSL_DRBG_PARAM_MAX_ENTROPYLEN) <unsigned integer>
199           Specify the minimum and maximum number of bytes of random material
200           that can be used to seed the DRBG.
201
202       "min_noncelen" (OSSL_DRBG_PARAM_MIN_NONCELEN) <unsigned integer>
203       "max_noncelen" (OSSL_DRBG_PARAM_MAX_NONCELEN) <unsigned integer>
204           Specify the minimum and maximum number of bytes of nonce that can
205           be used to instantiate the DRBG.
206
207       "max_perslen" (OSSL_DRBG_PARAM_MAX_PERSLEN) <unsigned integer>
208       "max_adinlen" (OSSL_DRBG_PARAM_MAX_ADINLEN) <unsigned integer>
209           Specify the minimum and maximum number of bytes of personalisation
210           string that can be used with the DRBG.
211
212       "reseed_counter" (OSSL_DRBG_PARAM_RESEED_COUNTER) <unsigned integer>
213           Specifies the number of times the DRBG has been seeded or reseeded.
214
215       "digest" (OSSL_DRBG_PARAM_DIGEST) <UTF8 string>
216       "cipher" (OSSL_DRBG_PARAM_CIPHER) <UTF8 string>
217       "mac" (OSSL_DRBG_PARAM_MAC) <UTF8 string>
218           Sets the name of the underlying cipher, digest or MAC to be used.
219           It must name a suitable algorithm for the DRBG that's being used.
220
221       "properties" (OSSL_DRBG_PARAM_PROPERTIES) <UTF8 string>
222           Sets the properties to be queried when trying to fetch an
223           underlying algorithm.  This must be given together with the
224           algorithm naming parameter to be considered valid.
225

RETURN VALUES

227       OSSL_FUNC_rand_newctx() should return the newly created provider side
228       rand context, or NULL on failure.
229
230       OSSL_FUNC_rand_gettable_params(), OSSL_FUNC_rand_gettable_ctx_params()
231       and OSSL_FUNC_rand_settable_ctx_params() should return a constant
232       OSSL_PARAM array, or NULL if none is offered.
233
234       OSSL_FUNC_rand_nonce() returns the size of the generated nonce, or 0 on
235       error.
236
237       OSSL_FUNC_rand_get_seed() returns the size of the generated seed, or 0
238       on error.
239
240       All of the remaining functions should return 1 for success or 0 on
241       error.
242

NOTES

244       The RAND life-cycle is described in life_cycle-rand(7).  Providers
245       should ensure that the various transitions listed there are supported.
246       At some point the EVP layer will begin enforcing the listed
247       transitions.
248

SEE ALSO

250       provider(7), RAND(7), EVP_RAND(7), life_cycle-rand(7), EVP_RAND(3)
251

HISTORY

253       The provider RAND interface was introduced in OpenSSL 3.0.
254
256       Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
257
258       Licensed under the Apache License 2.0 (the "License").  You may not use
259       this file except in compliance with the License.  You can obtain a copy
260       in the file LICENSE in the source distribution or at
261       <https://www.openssl.org/source/license.html>.
262
263
264
2653.0.5                             2022-07-05              PROVIDER-RAND(7ossl)
Impressum