]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/RAND_DRBG_set_callbacks.pod
PROV: Fix MSBLOB / PVK deserializer
[thirdparty/openssl.git] / doc / man3 / RAND_DRBG_set_callbacks.pod
CommitLineData
a73d990e
DMSP
1=pod
2
3=head1 NAME
4
5RAND_DRBG_set_callbacks,
30a9d5d1
DMSP
6RAND_DRBG_set_callback_data,
7RAND_DRBG_get_callback_data,
a73d990e
DMSP
8RAND_DRBG_get_entropy_fn,
9RAND_DRBG_cleanup_entropy_fn,
10RAND_DRBG_get_nonce_fn,
11RAND_DRBG_cleanup_nonce_fn
12- set callbacks for reseeding
13
14=head1 SYNOPSIS
15
16 #include <openssl/rand_drbg.h>
17
18
19 int RAND_DRBG_set_callbacks(RAND_DRBG *drbg,
20 RAND_DRBG_get_entropy_fn get_entropy,
21 RAND_DRBG_cleanup_entropy_fn cleanup_entropy,
22 RAND_DRBG_get_nonce_fn get_nonce,
23 RAND_DRBG_cleanup_nonce_fn cleanup_nonce);
24
30a9d5d1
DMSP
25 int RAND_DRBG_set_callback_data(RAND_DRBG *drbg, void *ctx);
26
27 void *RAND_DRBG_get_callback_data(RAND_DRBG *drbg);
a73d990e
DMSP
28
29=head2 Callback Functions
30
31 typedef size_t (*RAND_DRBG_get_entropy_fn)(
32 RAND_DRBG *drbg,
33 unsigned char **pout,
34 int entropy,
35 size_t min_len, size_t max_len,
36 int prediction_resistance);
37
38 typedef void (*RAND_DRBG_cleanup_entropy_fn)(
39 RAND_DRBG *drbg,
40 unsigned char *out, size_t outlen);
41
42 typedef size_t (*RAND_DRBG_get_nonce_fn)(
43 RAND_DRBG *drbg,
44 unsigned char **pout,
45 int entropy,
46 size_t min_len, size_t max_len);
47
48 typedef void (*RAND_DRBG_cleanup_nonce_fn)(
49 RAND_DRBG *drbg,
50 unsigned char *out, size_t outlen);
51
52
53
54=head1 DESCRIPTION
55
56RAND_DRBG_set_callbacks() sets the callbacks for obtaining fresh entropy and
57the nonce when reseeding the given B<drbg>.
58The callback functions are implemented and provided by the caller.
59Their parameter lists need to match the function prototypes above.
60
30a9d5d1
DMSP
61RAND_DRBG_set_callback_data() can be used to store a pointer to some context
62specific data, which can subsequently be retrieved by the entropy and nonce
63callbacks using RAND_DRBG_get_callback_data().
64The ownership of the context data remains with the caller, i.e., it is the
09066cf2 65caller's responsibility to keep it available as long as it is needed by the
30a9d5d1 66callbacks and free it after use.
8c1cbc72 67For more information about the callback data see the NOTES section.
30a9d5d1
DMSP
68
69Setting the callbacks or the callback data is allowed only if the DRBG has
70not been initialized yet.
a73d990e
DMSP
71Otherwise, the operation will fail.
72To change the settings for one of the three shared DRBGs it is necessary to call
73RAND_DRBG_uninstantiate() first.
74
75The B<get_entropy>() callback is called by the B<drbg> when it requests fresh
76random input.
77It is expected that the callback allocates and fills a random buffer of size
78B<min_len> <= size <= B<max_len> (in bytes) which contains at least B<entropy>
79bits of randomness.
80The B<prediction_resistance> flag indicates whether the reseeding was
81triggered by a prediction resistance request.
82
83The buffer's address is to be returned in *B<pout> and the number of collected
84randomness bytes as return value.
85
86If the callback fails to acquire at least B<entropy> bits of randomness,
87it must indicate an error by returning a buffer length of 0.
88
89If B<prediction_resistance> was requested and the random source of the DRBG
90does not satisfy the conditions requested by [NIST SP 800-90C], then
91it must also indicate an error by returning a buffer length of 0.
92See NOTES section for more details.
93
8c1cbc72 94The B<cleanup_entropy>() callback is called from the B<drbg> to clear and
a73d990e 95free the buffer allocated previously by get_entropy().
f7bef277 96The values B<out> and B<outlen> are the random buffer's address and length,
a73d990e
DMSP
97as returned by the get_entropy() callback.
98
99The B<get_nonce>() and B<cleanup_nonce>() callbacks are used to obtain a nonce
100and free it again. A nonce is only required for instantiation (not for reseeding)
101and only in the case where the DRBG uses a derivation function.
102The callbacks are analogous to get_entropy() and cleanup_entropy(),
103except for the missing prediction_resistance flag.
104
105If the derivation function is disabled, then no nonce is used for instantiation,
106and the B<get_nonce>() and B<cleanup_nonce>() callbacks can be omitted by
107setting them to NULL.
108
109
110=head1 RETURN VALUES
111
30a9d5d1
DMSP
112RAND_DRBG_set_callbacks() returns 1 on success, and 0 on failure.
113
114RAND_DRBG_set_callback_data() returns 1 on success, and 0 on failure.
115
116RAND_DRBG_get_callback_data() returns the pointer to the callback data,
117which is NULL if none has been set previously.
a73d990e
DMSP
118
119=head1 NOTES
120
121It is important that B<cleanup_entropy>() and B<cleanup_nonce>() clear the buffer
122contents safely before freeing it, in order not to leave sensitive information
123about the DRBG's state in memory.
124
125A request for prediction resistance can only be satisfied by pulling fresh
65175163
P
126entropy from a live entropy source (section 5.5.2 of [NIST SP 800-90C]).
127It is up to the user to ensure that a live entropy source is configured
128and is being used.
a73d990e 129
f000e828
P
130The derivation function is disabled by calling the RAND_DRBG_new_ex()
131function with the RAND_DRBG_FLAG_CTR_NO_DF flag. For more information on
132the derivation function and when it can be omitted, see [NIST SP 800-90A
133Rev. 1]. Roughly speaking it can be omitted if the random source has "full
dc4e74ef 134entropy", that is, it contains 8 bits of entropy per byte. In a FIPS context,
f000e828 135the derivation function can never be omitted.
a73d990e
DMSP
136
137Even if a nonce is required, the B<get_nonce>() and B<cleanup_nonce>()
138callbacks can be omitted by setting them to NULL.
139In this case the DRBG will automatically request an extra amount of entropy
140(using the B<get_entropy>() and B<cleanup_entropy>() callbacks) which it will
141utilize for the nonce, following the recommendations of [NIST SP 800-90A Rev. 1],
142section 8.6.7.
143
09066cf2 144The callback data is a rather specialized feature, because in general the
30a9d5d1
DMSP
145random sources don't (and in fact, they must not) depend on any state provided
146by the DRBG.
147There are however exceptional cases where this feature is useful, most notably
148for implementing known answer tests (KATs) or deterministic signatures like
149those specified in RFC6979, which require passing a specified entropy and nonce
150for instantiating the DRBG.
151
a73d990e
DMSP
152=head1 SEE ALSO
153
154L<RAND_DRBG_new(3)>,
155L<RAND_DRBG_reseed(3)>,
156L<RAND_DRBG(7)>
157
b5c4bbbe
JL
158=head1 HISTORY
159
160The RAND_DRBG functions were added in OpenSSL 1.1.1.
161
a73d990e
DMSP
162=head1 COPYRIGHT
163
33388b44 164Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
a73d990e 165
4746f25a 166Licensed under the Apache License 2.0 (the "License"). You may not use
a73d990e
DMSP
167this file except in compliance with the License. You can obtain a copy
168in the file LICENSE in the source distribution or at
169L<https://www.openssl.org/source/license.html>.
170
171=cut