Switch from ossl_rand to DRBG rand
[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
36 /*
37  * EXDATA
38  */
39 #define RAND_DRBG_get_ex_new_index(l, p, newf, dupf, freef) \
40     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DRBG, l, p, newf, dupf, freef)
41 int RAND_DRBG_set_ex_data(RAND_DRBG *dctx, int idx, void *arg);
42 void *RAND_DRBG_get_ex_data(const RAND_DRBG *dctx, int idx);
43
44 /*
45  * Callback functions.  See comments in drbg_lib.c
46  */
47 typedef size_t (*RAND_DRBG_get_entropy_fn)(RAND_DRBG *ctx,
48                                            unsigned char **pout,
49                                            int entropy, size_t min_len,
50                                            size_t max_len);
51 typedef void (*RAND_DRBG_cleanup_entropy_fn)(RAND_DRBG *ctx,
52                                              unsigned char *out);
53 typedef size_t (*RAND_DRBG_get_nonce_fn)(RAND_DRBG *ctx, unsigned char **pout,
54                                          int entropy, size_t min_len,
55                                          size_t max_len);
56 typedef void (*RAND_DRBG_cleanup_nonce_fn)(RAND_DRBG *ctx, unsigned char *out);
57
58 int RAND_DRBG_set_callbacks(RAND_DRBG *dctx,
59                             RAND_DRBG_get_entropy_fn get_entropy,
60                             RAND_DRBG_cleanup_entropy_fn cleanup_entropy,
61                             RAND_DRBG_get_nonce_fn get_nonce,
62                             RAND_DRBG_cleanup_nonce_fn cleanup_nonce);
63
64 #endif