Revert "Add OPENSSL_VERSION_AT_LEAST"
[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 /* In CTR mode, disable derivation function ctr_df */
18 # define RAND_DRBG_FLAG_CTR_NO_DF            0x1
19
20 /* A logical OR of all used flag bits (currently there is only one) */
21 # define RAND_DRBG_USED_FLAGS  ( \
22     RAND_DRBG_FLAG_CTR_NO_DF \
23                                  )
24
25 /*
26  * Default security strength (in the sense of [NIST SP 800-90Ar1])
27  *
28  * NIST SP 800-90Ar1 supports the strength of the DRBG being smaller than that
29  * of the cipher by collecting less entropy. The current DRBG implemantion does
30  * not take RAND_DRBG_STRENGTH into account and sets the strength of the DRBG
31  * to that of the cipher.
32  *
33  * RAND_DRBG_STRENGTH is currently only used for the legacy RAND
34  * implementation.
35  *
36  * Currently supported ciphers are: NID_aes_128_ctr, NID_aes_192_ctr and
37  * NID_aes_256_ctr
38  */
39 # define RAND_DRBG_STRENGTH             256
40 # define RAND_DRBG_TYPE                 NID_aes_256_ctr
41 # define RAND_DRBG_FLAGS                0
42
43
44 # ifdef  __cplusplus
45 extern "C" {
46 # endif
47
48 /*
49  * Object lifetime functions.
50  */
51 RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent);
52 RAND_DRBG *RAND_DRBG_secure_new(int type, unsigned int flags, RAND_DRBG *parent);
53 int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags);
54 int RAND_DRBG_set_defaults(int type, unsigned int flags);
55 int RAND_DRBG_instantiate(RAND_DRBG *drbg,
56                           const unsigned char *pers, size_t perslen);
57 int RAND_DRBG_uninstantiate(RAND_DRBG *drbg);
58 void RAND_DRBG_free(RAND_DRBG *drbg);
59
60 /*
61  * Object "use" functions.
62  */
63 int RAND_DRBG_reseed(RAND_DRBG *drbg,
64                      const unsigned char *adin, size_t adinlen,
65                      int prediction_resistance);
66 int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,
67                        int prediction_resistance,
68                        const unsigned char *adin, size_t adinlen);
69 int RAND_DRBG_bytes(RAND_DRBG *drbg, unsigned char *out, size_t outlen);
70
71 int RAND_DRBG_set_reseed_interval(RAND_DRBG *drbg, unsigned int interval);
72 int RAND_DRBG_set_reseed_time_interval(RAND_DRBG *drbg, time_t interval);
73
74 int RAND_DRBG_set_reseed_defaults(
75                                   unsigned int master_reseed_interval,
76                                   unsigned int slave_reseed_interval,
77                                   time_t master_reseed_time_interval,
78                                   time_t slave_reseed_time_interval
79                                   );
80
81 RAND_DRBG *RAND_DRBG_get0_master(void);
82 RAND_DRBG *RAND_DRBG_get0_public(void);
83 RAND_DRBG *RAND_DRBG_get0_private(void);
84
85 /*
86  * EXDATA
87  */
88 # define RAND_DRBG_get_ex_new_index(l, p, newf, dupf, freef) \
89     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DRBG, l, p, newf, dupf, freef)
90 int RAND_DRBG_set_ex_data(RAND_DRBG *drbg, int idx, void *arg);
91 void *RAND_DRBG_get_ex_data(const RAND_DRBG *drbg, int idx);
92
93 /*
94  * Callback function typedefs
95  */
96 typedef size_t (*RAND_DRBG_get_entropy_fn)(RAND_DRBG *drbg,
97                                            unsigned char **pout,
98                                            int entropy, size_t min_len,
99                                            size_t max_len,
100                                            int prediction_resistance);
101 typedef void (*RAND_DRBG_cleanup_entropy_fn)(RAND_DRBG *ctx,
102                                              unsigned char *out, size_t outlen);
103 typedef size_t (*RAND_DRBG_get_nonce_fn)(RAND_DRBG *drbg, unsigned char **pout,
104                                          int entropy, size_t min_len,
105                                          size_t max_len);
106 typedef void (*RAND_DRBG_cleanup_nonce_fn)(RAND_DRBG *drbg,
107                                            unsigned char *out, size_t outlen);
108
109 int RAND_DRBG_set_callbacks(RAND_DRBG *drbg,
110                             RAND_DRBG_get_entropy_fn get_entropy,
111                             RAND_DRBG_cleanup_entropy_fn cleanup_entropy,
112                             RAND_DRBG_get_nonce_fn get_nonce,
113                             RAND_DRBG_cleanup_nonce_fn cleanup_nonce);
114
115
116 # ifdef  __cplusplus
117 }
118 # endif
119
120 #endif