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