Add prediction resistance capability to the DRBG reseeding process.
[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 a live entropy source (section 5.5.2 of [NIST SP 800-90C]).
108 It is up to the user to ensure that a live entropy source is configured
109 and is being used.
110
111 The derivation function is disabled during initialization by calling the
112 RAND_DRBG_set() function with the RAND_DRBG_FLAG_CTR_NO_DF flag.
113 For more information on the derivation function and when it can be omitted,
114 see [NIST SP 800-90A Rev. 1]. Roughly speeking it can be omitted if the random
115 source has "full entropy", i.e., contains 8 bits of entropy per byte.
116
117 Even if a nonce is required, the B<get_nonce>() and B<cleanup_nonce>()
118 callbacks can be omitted by setting them to NULL.
119 In this case the DRBG will automatically request an extra amount of entropy
120 (using the B<get_entropy>() and B<cleanup_entropy>() callbacks) which it will
121 utilize for the nonce, following the recommendations of [NIST SP 800-90A Rev. 1],
122 section 8.6.7.
123
124
125 =head1 HISTORY
126
127 The RAND_DRBG functions were added in OpenSSL 1.1.1.
128
129 =head1 SEE ALSO
130
131 L<RAND_DRBG_new(3)>,
132 L<RAND_DRBG_reseed(3)>,
133 L<RAND_DRBG(7)>
134
135 =head1 COPYRIGHT
136
137 Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
138
139 Licensed under the Apache License 2.0 (the "License").  You may not use
140 this file except in compliance with the License.  You can obtain a copy
141 in the file LICENSE in the source distribution or at
142 L<https://www.openssl.org/source/license.html>.
143
144 =cut