]> git.ipfire.org Git - thirdparty/openssl.git/blob - doc/man7/provider-rand.pod
Update copyright year
[thirdparty/openssl.git] / doc / man7 / provider-rand.pod
1 =pod
2
3 =head1 NAME
4
5 provider-rand - The random number generation library E<lt>-E<gt> provider
6 functions
7
8 =head1 SYNOPSIS
9
10 =for openssl multiple includes
11
12 #include <openssl/core_dispatch.h>
13 #include <openssl/core_names.h>
14
15 /*
16 * None of these are actual functions, but are displayed like this for
17 * the function signatures for functions that are offered as function
18 * pointers in OSSL_DISPATCH arrays.
19 */
20
21 /* Context management */
22 void *OSSL_FUNC_rand_newctx(void *provctx, void *parent,
23 const OSSL_DISPATCH *parent_calls);
24 void OSSL_FUNC_rand_freectx(void *ctx);
25
26 /* Random number generator functions: NIST */
27 int OSSL_FUNC_rand_instantiate(void *ctx, unsigned int strength,
28 int prediction_resistance,
29 const unsigned char *pstr, size_t pstr_len);
30 int OSSL_FUNC_rand_uninstantiate(void *ctx);
31 int OSSL_FUNC_rand_generate(void *ctx, unsigned char *out, size_t outlen,
32 unsigned int strength, int prediction_resistance,
33 const unsigned char *addin, size_t addin_len);
34 int OSSL_FUNC_rand_reseed(void *ctx, int prediction_resistance,
35 const unsigned char *ent, size_t ent_len,
36 const unsigned char *addin, size_t addin_len);
37
38 /* Random number generator functions: additional */
39 size_t OSSL_FUNC_rand_nonce(void *ctx, unsigned char *out, size_t outlen,
40 int strength, size_t min_noncelen,
41 size_t max_noncelen);
42 size_t OSSL_FUNC_rand_get_seed(void *ctx, unsigned char **buffer,
43 int entropy, size_t min_len, size_t max_len,
44 int prediction_resistance,
45 const unsigned char *adin, size_t adin_len);
46 void OSSL_FUNC_rand_clear_seed(void *ctx, unsigned char *buffer, size_t b_len);
47 int OSSL_FUNC_rand_verify_zeroization(void *ctx);
48
49 /* Context Locking */
50 int OSSL_FUNC_rand_enable_locking(void *ctx);
51 int OSSL_FUNC_rand_lock(void *ctx);
52 void OSSL_FUNC_rand_unlock(void *ctx);
53
54 /* RAND parameter descriptors */
55 const OSSL_PARAM *OSSL_FUNC_rand_gettable_params(void *provctx);
56 const OSSL_PARAM *OSSL_FUNC_rand_gettable_ctx_params(void *provctx);
57 const OSSL_PARAM *OSSL_FUNC_rand_settable_ctx_params(void *provctx);
58
59 /* RAND parameters */
60 int OSSL_FUNC_rand_get_params(OSSL_PARAM params[]);
61 int OSSL_FUNC_rand_get_ctx_params(void *ctx, OSSL_PARAM params[]);
62 int OSSL_FUNC_rand_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
63
64 =head1 DESCRIPTION
65
66 This documentation is primarily aimed at provider authors. See L<provider(7)>
67 for further information.
68
69 The RAND operation enables providers to implement random number generation
70 algorithms and random number sources and make
71 them available to applications via the API function L<EVP_RAND(3)>.
72
73 =head2 Context Management Functions
74
75 OSSL_FUNC_rand_newctx() should create and return a pointer to a provider side
76 structure for holding context information during a rand operation.
77 A pointer to this context will be passed back in a number of the other rand
78 operation function calls.
79 The parameter I<provctx> is the provider context generated during provider
80 initialisation (see L<provider(7)>).
81 The parameter I<parent> specifies another rand instance to be used for
82 seeding purposes. If NULL and the specific instance supports it, the
83 operating system will be used for seeding.
84 The parameter I<parent_calls> points to the dispatch table for I<parent>.
85 Thus, the parent need not be from the same provider as the new instance.
86
87 OSSL_FUNC_rand_freectx() is passed a pointer to the provider side rand context in
88 the I<mctx> parameter.
89 If it receives NULL as I<ctx> value, it should not do anything other than
90 return.
91 This function should free any resources associated with that context.
92
93 =head2 Random Number Generator Functions: NIST
94
95 These functions correspond to those defined in NIST SP 800-90A and SP 800-90C.
96
97 OSSL_FUNC_rand_instantiate() is used to instantiate the DRBG I<ctx> at a requested
98 security I<strength>. In addition, I<prediction_resistance> can be requested.
99 Additional input I<addin> of length I<addin_len> bytes can optionally
100 be provided.
101
102 OSSL_FUNC_rand_uninstantiate() is used to uninstantiate the DRBG I<ctx>. After being
103 uninstantiated, a DRBG is unable to produce output until it is instantiated
104 anew.
105
106 OSSL_FUNC_rand_generate() is used to generate random bytes from the DRBG I<ctx>.
107 It will generate I<outlen> bytes placing them into the buffer pointed to by
108 I<out>. The generated bytes will meet the specified security I<strength> and,
109 if I<prediction_resistance> is true, the bytes will be produced after reseeding
110 from a live entropy source. Additional input I<addin> of length I<addin_len>
111 bytes can optionally be provided.
112
113 =head2 Random Number Generator Functions: Additional
114
115 OSSL_FUNC_rand_nonce() is used to generate a nonce of the given I<strength> with a
116 length from I<min_noncelen> to I<max_noncelen>. If the output buffer I<out> is
117 NULL, the length of the nonce should be returned.
118
119 OSSL_FUNC_rand_get_seed() is used by deterministic generators to obtain their
120 seeding material from their parent. The seed bytes will meet the specified
121 security level of I<entropy> bits and there will be between I<min_len>
122 and I<max_len> inclusive bytes in total. If I<prediction_resistance> is
123 true, the bytes will be produced from a live entropy source. Additional
124 input I<addin> of length I<addin_len> bytes can optionally be provided.
125 A pointer to the seed material is returned in I<*buffer> and this must be
126 freed by a later call to OSSL_FUNC_rand_clear_seed().
127
128 OSSL_FUNC_rand_clear_seed() frees a seed I<buffer> of length I<b_len> bytes
129 which was previously allocated by OSSL_FUNC_rand_get_seed().
130
131 OSSL_FUNC_rand_verify_zeroization() is used to determine if the internal state of the
132 DRBG is zero. This capability is mandated by NIST as part of the self
133 tests, it is unlikely to be useful in other circumstances.
134
135 =head2 Context Locking
136
137 When DRBGs are used by multiple threads, there must be locking employed to
138 ensure their proper operation. Because locking introduces an overhead, it
139 is disabled by default.
140
141 OSSL_FUNC_rand_enable_locking() allows locking to be turned on for a DRBG and all of
142 its parent DRBGs. From this call onwards, the DRBG can be used in a thread
143 safe manner.
144
145 OSSL_FUNC_rand_lock() is used to lock a DRBG. Once locked, exclusive access
146 is guaranteed.
147
148 OSSL_FUNC_rand_unlock() is used to unlock a DRBG.
149
150 =head2 Rand Parameters
151
152 See L<OSSL_PARAM(3)> for further details on the parameters structure used by
153 these functions.
154
155 OSSL_FUNC_rand_get_params() gets details of parameter values associated with the
156 provider algorithm and stores them in I<params>.
157
158 OSSL_FUNC_rand_set_ctx_params() sets rand parameters associated with the given
159 provider side rand context I<ctx> to I<params>.
160 Any parameter settings are additional to any that were previously set.
161
162 OSSL_FUNC_rand_get_ctx_params() gets details of currently set parameter values
163 associated with the given provider side rand context I<ctx> and stores them
164 in I<params>.
165
166 OSSL_FUNC_rand_gettable_params(), OSSL_FUNC_rand_gettable_ctx_params(), and
167 OSSL_FUNC_rand_settable_ctx_params() all return constant B<OSSL_PARAM> arrays
168 as descriptors of the parameters that OSSL_FUNC_rand_get_params(),
169 OSSL_FUNC_rand_get_ctx_params(), and OSSL_FUNC_rand_set_ctx_params() can handle,
170 respectively.
171
172 Parameters currently recognised by built-in rands are as follows. Not all
173 parameters are relevant to, or are understood by all rands:
174
175 =over 4
176
177 =item "state" (B<OSSL_RAND_PARAM_STATE>) <integer>
178
179 Returns the state of the random number generator.
180
181 =item "strength" (B<OSSL_RAND_PARAM_STRENGTH>) <unsigned integer>
182
183 Returns the bit strength of the random number generator.
184
185 =back
186
187 For rands that are also deterministic random bit generators (DRBGs), these
188 additional parameters are recognised. Not all
189 parameters are relevant to, or are understood by all DRBG rands:
190
191 =over 4
192
193 =item "reseed_requests" (B<OSSL_DRBG_PARAM_RESEED_REQUESTS>) <unsigned integer>
194
195 Reads or set the number of generate requests before reseeding the
196 associated RAND ctx.
197
198 =item "reseed_time_interval" (B<OSSL_DRBG_PARAM_RESEED_TIME_INTERVAL>) <integer>
199
200 Reads or set the number of elapsed seconds before reseeding the
201 associated RAND ctx.
202
203 =item "max_request" (B<OSSL_DRBG_PARAM_RESEED_REQUESTS>) <unsigned integer>
204
205 Specifies the maximum number of bytes that can be generated in a single
206 call to OSSL_FUNC_rand_generate.
207
208 =item "min_entropylen" (B<OSSL_DRBG_PARAM_MIN_ENTROPYLEN>) <unsigned integer>
209
210 =item "max_entropylen" (B<OSSL_DRBG_PARAM_MAX_ENTROPYLEN>) <unsigned integer>
211
212 Specify the minimum and maximum number of bytes of random material that
213 can be used to seed the DRBG.
214
215 =item "min_noncelen" (B<OSSL_DRBG_PARAM_MIN_NONCELEN>) <unsigned integer>
216
217 =item "max_noncelen" (B<OSSL_DRBG_PARAM_MAX_NONCELEN>) <unsigned integer>
218
219 Specify the minimum and maximum number of bytes of nonce that can be used to
220 instantiate the DRBG.
221
222 =item "max_perslen" (B<OSSL_DRBG_PARAM_MAX_PERSLEN>) <unsigned integer>
223
224 =item "max_adinlen" (B<OSSL_DRBG_PARAM_MAX_ADINLEN>) <unsigned integer>
225
226 Specify the minimum and maximum number of bytes of personalisation string
227 that can be used with the DRBG.
228
229 =item "reseed_counter" (B<OSSL_DRBG_PARAM_RESEED_COUNTER>) <unsigned integer>
230
231 Specifies the number of times the DRBG has been seeded or reseeded.
232
233 =item "digest" (B<OSSL_DRBG_PARAM_DIGEST>) <UTF8 string>
234
235 =item "cipher" (B<OSSL_DRBG_PARAM_CIPHER>) <UTF8 string>
236
237 =item "mac" (B<OSSL_DRBG_PARAM_MAC>) <UTF8 string>
238
239 Sets the name of the underlying cipher, digest or MAC to be used.
240 It must name a suitable algorithm for the DRBG that's being used.
241
242 =item "properties" (B<OSSL_DRBG_PARAM_PROPERTIES>) <UTF8 string>
243
244 Sets the properties to be queried when trying to fetch an underlying algorithm.
245 This must be given together with the algorithm naming parameter to be
246 considered valid.
247
248 =back
249
250 =head1 RETURN VALUES
251
252 OSSL_FUNC_rand_newctx() should return the newly created
253 provider side rand context, or NULL on failure.
254
255 OSSL_FUNC_rand_gettable_params(), OSSL_FUNC_rand_gettable_ctx_params() and
256 OSSL_FUNC_rand_settable_ctx_params() should return a constant B<OSSL_PARAM>
257 array, or NULL if none is offered.
258
259 OSSL_FUNC_rand_nonce() returns the size of the generated nonce, or 0 on error.
260
261 OSSL_FUNC_rand_get_seed() returns the size of the generated seed, or 0 on
262 error.
263
264 All of the remaining functions should return 1 for success or 0 on error.
265
266 =head1 SEE ALSO
267
268 L<provider(7)>,
269 L<RAND(7)>,
270 L<EVP_RAND(7)>
271
272 =head1 HISTORY
273
274 The provider RAND interface was introduced in OpenSSL 3.0.
275
276 =head1 COPYRIGHT
277
278 Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
279
280 Licensed under the Apache License 2.0 (the "License"). You may not use
281 this file except in compliance with the License. You can obtain a copy
282 in the file LICENSE in the source distribution or at
283 L<https://www.openssl.org/source/license.html>.
284
285 =cut