Add EVP_PKEY_supports_digest_nid()
[openssl.git] / doc / man3 / RAND_DRBG_set_callbacks.pod
1 =pod
2
3 =head1 NAME
4
5 RAND_DRBG_set_callbacks,
6 RAND_DRBG_get_entropy_fn,
7 RAND_DRBG_cleanup_entropy_fn,
8 RAND_DRBG_get_nonce_fn,
9 RAND_DRBG_cleanup_nonce_fn
10 - set callbacks for reseeding
11
12 =head1 SYNOPSIS
13
14  #include <openssl/rand_drbg.h>
15
16
17  int RAND_DRBG_set_callbacks(RAND_DRBG *drbg,
18                              RAND_DRBG_get_entropy_fn get_entropy,
19                              RAND_DRBG_cleanup_entropy_fn cleanup_entropy,
20                              RAND_DRBG_get_nonce_fn get_nonce,
21                              RAND_DRBG_cleanup_nonce_fn cleanup_nonce);
22
23
24 =head2 Callback Functions
25
26  typedef size_t (*RAND_DRBG_get_entropy_fn)(
27                        RAND_DRBG *drbg,
28                        unsigned char **pout,
29                        int entropy,
30                        size_t min_len, size_t max_len,
31                        int prediction_resistance);
32
33  typedef void (*RAND_DRBG_cleanup_entropy_fn)(
34                      RAND_DRBG *drbg,
35                      unsigned char *out, size_t outlen);
36
37  typedef size_t (*RAND_DRBG_get_nonce_fn)(
38                        RAND_DRBG *drbg,
39                        unsigned char **pout,
40                        int entropy,
41                        size_t min_len, size_t max_len);
42
43  typedef void (*RAND_DRBG_cleanup_nonce_fn)(
44                      RAND_DRBG *drbg,
45                      unsigned char *out, size_t outlen);
46
47
48
49 =head1 DESCRIPTION
50
51 RAND_DRBG_set_callbacks() sets the callbacks for obtaining fresh entropy and
52 the nonce when reseeding the given B<drbg>.
53 The callback functions are implemented and provided by the caller.
54 Their parameter lists need to match the function prototypes above.
55
56 Setting the callbacks is allowed only if the DRBG has not been initialized yet.
57 Otherwise, the operation will fail.
58 To change the settings for one of the three shared DRBGs it is necessary to call
59 RAND_DRBG_uninstantiate() first.
60
61 The B<get_entropy>() callback is called by the B<drbg> when it requests fresh
62 random input.
63 It is expected that the callback allocates and fills a random buffer of size
64 B<min_len> <= size <= B<max_len> (in bytes) which contains at least B<entropy>
65 bits of randomness.
66 The B<prediction_resistance> flag indicates whether the reseeding was
67 triggered by a prediction resistance request.
68
69 The buffer's address is to be returned in *B<pout> and the number of collected
70 randomness bytes as return value.
71
72 If the callback fails to acquire at least B<entropy> bits of randomness,
73 it must indicate an error by returning a buffer length of 0.
74
75 If B<prediction_resistance> was requested and the random source of the DRBG
76 does not satisfy the conditions requested by [NIST SP 800-90C], then
77 it must also indicate an error by returning a buffer length of 0.
78 See NOTES section for more details.
79
80 The B<cleanup_entropy>() callback is called from the B<drbg> to to clear and
81 free the buffer allocated previously by get_entropy().
82 The values B<out> and B<outlen> are the random buffer's address and length,
83 as returned by the get_entropy() callback.
84
85 The B<get_nonce>() and B<cleanup_nonce>() callbacks are used to obtain a nonce
86 and free it again. A nonce is only required for instantiation (not for reseeding)
87 and only in the case where the DRBG uses a derivation function.
88 The callbacks are analogous to get_entropy() and cleanup_entropy(),
89 except for the missing prediction_resistance flag.
90
91 If the derivation function is disabled, then no nonce is used for instantiation,
92 and the B<get_nonce>() and B<cleanup_nonce>() callbacks can be omitted by
93 setting them to NULL.
94
95
96 =head1 RETURN VALUES
97
98 RAND_DRBG_set_callbacks() return 1 on success, and 0 on failure
99
100 =head1 NOTES
101
102 It is important that B<cleanup_entropy>() and B<cleanup_nonce>() clear the buffer
103 contents safely before freeing it, in order not to leave sensitive information
104 about the DRBG's state in memory.
105
106 A request for prediction resistance can only be satisfied by pulling fresh
107 entropy from one of the approved entropy sources listed in section 5.5.2 of
108 [NIST SP 800-90C].
109 Since the default implementation of the get_entropy callback does not have access
110 to such an approved entropy source, a request for prediction resistance will
111 always fail.
112 In other words, prediction resistance is currently not supported yet by the DRBG.
113
114 The derivation function is disabled during initialization by calling the
115 RAND_DRBG_set() function with the RAND_DRBG_FLAG_CTR_NO_DF flag.
116 For more information on the derivation function and when it can be omitted,
117 see [NIST SP 800-90A Rev. 1]. Roughly speeking it can be omitted if the random
118 source has "full entropy", i.e., contains 8 bits of entropy per byte.
119
120 Even if a nonce is required, the B<get_nonce>() and B<cleanup_nonce>()
121 callbacks can be omitted by setting them to NULL.
122 In this case the DRBG will automatically request an extra amount of entropy
123 (using the B<get_entropy>() and B<cleanup_entropy>() callbacks) which it will
124 utilize for the nonce, following the recommendations of [NIST SP 800-90A Rev. 1],
125 section 8.6.7.
126
127
128 =head1 HISTORY
129
130 The RAND_DRBG functions were added in OpenSSL 1.1.1.
131
132 =head1 SEE ALSO
133
134 L<RAND_DRBG_new(3)>,
135 L<RAND_DRBG_reseed(3)>,
136 L<RAND_DRBG(7)>
137
138 =head1 COPYRIGHT
139
140 Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
141
142 Licensed under the OpenSSL license (the "License").  You may not use
143 this file except in compliance with the License.  You can obtain a copy
144 in the file LICENSE in the source distribution or at
145 L<https://www.openssl.org/source/license.html>.
146
147 =cut