Add a DRBG to each SSL object
[openssl.git] / include / internal / rand.h
1 /*
2  * Copyright 2017 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 /* In CTR mode, use derivation function ctr_df */
14 #define RAND_DRBG_FLAG_CTR_USE_DF            0x2
15
16 /*
17  * Object lifetime functions.
18  */
19 RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent);
20 int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags);
21 int RAND_DRBG_instantiate(RAND_DRBG *drbg,
22                           const unsigned char *pers, size_t perslen);
23 int RAND_DRBG_uninstantiate(RAND_DRBG *drbg);
24 void RAND_DRBG_free(RAND_DRBG *drbg);
25
26 /*
27  * Object "use" functions.
28  */
29 int RAND_DRBG_reseed(RAND_DRBG *drbg,
30                      const unsigned char *adin, size_t adinlen);
31 int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,
32                        int prediction_resistance,
33                        const unsigned char *adin, size_t adinlen);
34 int RAND_DRBG_set_reseed_interval(RAND_DRBG *drbg, int interval);
35 RAND_DRBG *RAND_DRBG_get0_global(void);
36
37 /*
38  * EXDATA
39  */
40 #define RAND_DRBG_get_ex_new_index(l, p, newf, dupf, freef) \
41     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DRBG, l, p, newf, dupf, freef)
42 int RAND_DRBG_set_ex_data(RAND_DRBG *dctx, int idx, void *arg);
43 void *RAND_DRBG_get_ex_data(const RAND_DRBG *dctx, int idx);
44
45 /*
46  * Callback functions.  See comments in drbg_lib.c
47  */
48 typedef size_t (*RAND_DRBG_get_entropy_fn)(RAND_DRBG *ctx,
49                                            unsigned char **pout,
50                                            int entropy, size_t min_len,
51                                            size_t max_len);
52 typedef void (*RAND_DRBG_cleanup_entropy_fn)(RAND_DRBG *ctx,
53                                              unsigned char *out);
54 typedef size_t (*RAND_DRBG_get_nonce_fn)(RAND_DRBG *ctx, unsigned char **pout,
55                                          int entropy, size_t min_len,
56                                          size_t max_len);
57 typedef void (*RAND_DRBG_cleanup_nonce_fn)(RAND_DRBG *ctx, unsigned char *out);
58
59 int RAND_DRBG_set_callbacks(RAND_DRBG *dctx,
60                             RAND_DRBG_get_entropy_fn get_entropy,
61                             RAND_DRBG_cleanup_entropy_fn cleanup_entropy,
62                             RAND_DRBG_get_nonce_fn get_nonce,
63                             RAND_DRBG_cleanup_nonce_fn cleanup_nonce);
64
65 #endif