Replace the public RAND_DRBG_USED_FLAGS #define by an internal constant
[oweals/openssl.git] / include / openssl / rand_drbg.h
1 /*
2  * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #ifndef HEADER_DRBG_RAND_H
11 # define HEADER_DRBG_RAND_H
12
13 # include <time.h>
14 # include <openssl/ossl_typ.h>
15
16 /*
17  * RAND_DRBG  flags
18  *
19  * Note: if new flags are added, the constant `rand_drbg_used_flags`
20  *       in drbg_lib.c needs to be updated accordingly.
21  */
22
23 /* In CTR mode, disable derivation function ctr_df */
24 # define RAND_DRBG_FLAG_CTR_NO_DF            0x1
25
26
27 # if OPENSSL_API_COMPAT < 0x10200000L
28 /* This #define was replaced by an internal constant and should not be used. */
29 #  define RAND_DRBG_USED_FLAGS  (RAND_DRBG_FLAG_CTR_NO_DF)
30 # endif
31
32 /*
33  * Default security strength (in the sense of [NIST SP 800-90Ar1])
34  *
35  * NIST SP 800-90Ar1 supports the strength of the DRBG being smaller than that
36  * of the cipher by collecting less entropy. The current DRBG implemantion does
37  * not take RAND_DRBG_STRENGTH into account and sets the strength of the DRBG
38  * to that of the cipher.
39  *
40  * RAND_DRBG_STRENGTH is currently only used for the legacy RAND
41  * implementation.
42  *
43  * Currently supported ciphers are: NID_aes_128_ctr, NID_aes_192_ctr and
44  * NID_aes_256_ctr
45  */
46 # define RAND_DRBG_STRENGTH             256
47 # define RAND_DRBG_TYPE                 NID_aes_256_ctr
48 # define RAND_DRBG_FLAGS                0
49
50
51 # ifdef  __cplusplus
52 extern "C" {
53 # endif
54
55 /*
56  * Object lifetime functions.
57  */
58 RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent);
59 RAND_DRBG *RAND_DRBG_secure_new(int type, unsigned int flags, RAND_DRBG *parent);
60 int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags);
61 int RAND_DRBG_set_defaults(int type, unsigned int flags);
62 int RAND_DRBG_instantiate(RAND_DRBG *drbg,
63                           const unsigned char *pers, size_t perslen);
64 int RAND_DRBG_uninstantiate(RAND_DRBG *drbg);
65 void RAND_DRBG_free(RAND_DRBG *drbg);
66
67 /*
68  * Object "use" functions.
69  */
70 int RAND_DRBG_reseed(RAND_DRBG *drbg,
71                      const unsigned char *adin, size_t adinlen,
72                      int prediction_resistance);
73 int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,
74                        int prediction_resistance,
75                        const unsigned char *adin, size_t adinlen);
76 int RAND_DRBG_bytes(RAND_DRBG *drbg, unsigned char *out, size_t outlen);
77
78 int RAND_DRBG_set_reseed_interval(RAND_DRBG *drbg, unsigned int interval);
79 int RAND_DRBG_set_reseed_time_interval(RAND_DRBG *drbg, time_t interval);
80
81 int RAND_DRBG_set_reseed_defaults(
82                                   unsigned int master_reseed_interval,
83                                   unsigned int slave_reseed_interval,
84                                   time_t master_reseed_time_interval,
85                                   time_t slave_reseed_time_interval
86                                   );
87
88 RAND_DRBG *RAND_DRBG_get0_master(void);
89 RAND_DRBG *RAND_DRBG_get0_public(void);
90 RAND_DRBG *RAND_DRBG_get0_private(void);
91
92 /*
93  * EXDATA
94  */
95 # define RAND_DRBG_get_ex_new_index(l, p, newf, dupf, freef) \
96     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DRBG, l, p, newf, dupf, freef)
97 int RAND_DRBG_set_ex_data(RAND_DRBG *drbg, int idx, void *arg);
98 void *RAND_DRBG_get_ex_data(const RAND_DRBG *drbg, int idx);
99
100 /*
101  * Callback function typedefs
102  */
103 typedef size_t (*RAND_DRBG_get_entropy_fn)(RAND_DRBG *drbg,
104                                            unsigned char **pout,
105                                            int entropy, size_t min_len,
106                                            size_t max_len,
107                                            int prediction_resistance);
108 typedef void (*RAND_DRBG_cleanup_entropy_fn)(RAND_DRBG *ctx,
109                                              unsigned char *out, size_t outlen);
110 typedef size_t (*RAND_DRBG_get_nonce_fn)(RAND_DRBG *drbg, unsigned char **pout,
111                                          int entropy, size_t min_len,
112                                          size_t max_len);
113 typedef void (*RAND_DRBG_cleanup_nonce_fn)(RAND_DRBG *drbg,
114                                            unsigned char *out, size_t outlen);
115
116 int RAND_DRBG_set_callbacks(RAND_DRBG *drbg,
117                             RAND_DRBG_get_entropy_fn get_entropy,
118                             RAND_DRBG_cleanup_entropy_fn cleanup_entropy,
119                             RAND_DRBG_get_nonce_fn get_nonce,
120                             RAND_DRBG_cleanup_nonce_fn cleanup_nonce);
121
122
123 # ifdef  __cplusplus
124 }
125 # endif
126
127 #endif