]>
Commit | Line | Data |
---|---|---|
12fb8c3d | 1 | /* |
6738bf14 | 2 | * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. |
12fb8c3d RS |
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 | ||
6decf943 DMSP |
13 | # include <time.h> |
14 | # include <openssl/ossl_typ.h> | |
cf3d6ef7 | 15 | # include <openssl/obj_mac.h> |
6decf943 | 16 | |
c402e943 DMSP |
17 | /* |
18 | * RAND_DRBG flags | |
19 | * | |
20 | * Note: if new flags are added, the constant `rand_drbg_used_flags` | |
21 | * in drbg_lib.c needs to be updated accordingly. | |
22 | */ | |
6decf943 | 23 | |
8164d91d | 24 | /* In CTR mode, disable derivation function ctr_df */ |
6decf943 | 25 | # define RAND_DRBG_FLAG_CTR_NO_DF 0x1 |
8bf36651 SL |
26 | /* |
27 | * This flag is only used when a digest NID is specified (i.e: not a CTR cipher) | |
28 | * Selects DRBG_HMAC if this is set otherwise use DRBG_HASH. | |
29 | */ | |
30 | # define RAND_DRBG_FLAG_HMAC 0x2 | |
12fb8c3d | 31 | |
8bf36651 SL |
32 | /* Used by RAND_DRBG_set_defaults() to set the master DRBG type and flags. */ |
33 | # define RAND_DRBG_FLAG_MASTER 0x4 | |
34 | /* Used by RAND_DRBG_set_defaults() to set the public DRBG type and flags. */ | |
35 | # define RAND_DRBG_FLAG_PUBLIC 0x8 | |
36 | /* Used by RAND_DRBG_set_defaults() to set the private DRBG type and flags. */ | |
37 | # define RAND_DRBG_FLAG_PRIVATE 0x10 | |
c402e943 DMSP |
38 | |
39 | # if OPENSSL_API_COMPAT < 0x10200000L | |
40 | /* This #define was replaced by an internal constant and should not be used. */ | |
41 | # define RAND_DRBG_USED_FLAGS (RAND_DRBG_FLAG_CTR_NO_DF) | |
42 | # endif | |
31393fd9 | 43 | |
c16de9d8 DMSP |
44 | /* |
45 | * Default security strength (in the sense of [NIST SP 800-90Ar1]) | |
c16de9d8 | 46 | * |
32bda2b2 | 47 | * NIST SP 800-90Ar1 supports the strength of the DRBG being smaller than that |
8bf36651 SL |
48 | * of the cipher by collecting less entropy. The current DRBG implementation |
49 | * does not take RAND_DRBG_STRENGTH into account and sets the strength of the | |
50 | * DRBG to that of the cipher. | |
c16de9d8 | 51 | * |
32bda2b2 KR |
52 | * RAND_DRBG_STRENGTH is currently only used for the legacy RAND |
53 | * implementation. | |
54 | * | |
55 | * Currently supported ciphers are: NID_aes_128_ctr, NID_aes_192_ctr and | |
8bf36651 SL |
56 | * NID_aes_256_ctr. |
57 | * The digest types for DRBG_hash or DRBG_hmac are: NID_sha1, NID_sha224, | |
58 | * NID_sha256, NID_sha384, NID_sha512, NID_sha512_224, NID_sha512_256, | |
59 | * NID_sha3_224, NID_sha3_256, NID_sha3_384 and NID_sha3_512. | |
c16de9d8 | 60 | */ |
32bda2b2 | 61 | # define RAND_DRBG_STRENGTH 256 |
8bf36651 | 62 | /* Default drbg type */ |
31393fd9 | 63 | # define RAND_DRBG_TYPE NID_aes_256_ctr |
8bf36651 | 64 | /* Default drbg flags */ |
31393fd9 | 65 | # define RAND_DRBG_FLAGS 0 |
c16de9d8 | 66 | |
6decf943 DMSP |
67 | |
68 | # ifdef __cplusplus | |
69 | extern "C" { | |
70 | # endif | |
71 | ||
75e2c877 RS |
72 | /* |
73 | * Object lifetime functions. | |
74 | */ | |
75 | RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent); | |
4f9dabbf | 76 | RAND_DRBG *RAND_DRBG_secure_new(int type, unsigned int flags, RAND_DRBG *parent); |
75e2c877 | 77 | int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags); |
31393fd9 | 78 | int RAND_DRBG_set_defaults(int type, unsigned int flags); |
75e2c877 | 79 | int RAND_DRBG_instantiate(RAND_DRBG *drbg, |
12fb8c3d | 80 | const unsigned char *pers, size_t perslen); |
75e2c877 RS |
81 | int RAND_DRBG_uninstantiate(RAND_DRBG *drbg); |
82 | void RAND_DRBG_free(RAND_DRBG *drbg); | |
83 | ||
84 | /* | |
85 | * Object "use" functions. | |
86 | */ | |
87 | int RAND_DRBG_reseed(RAND_DRBG *drbg, | |
eb238134 KR |
88 | const unsigned char *adin, size_t adinlen, |
89 | int prediction_resistance); | |
75e2c877 | 90 | int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen, |
12fb8c3d RS |
91 | int prediction_resistance, |
92 | const unsigned char *adin, size_t adinlen); | |
20928ff6 KR |
93 | int RAND_DRBG_bytes(RAND_DRBG *drbg, unsigned char *out, size_t outlen); |
94 | ||
a93ba405 | 95 | int RAND_DRBG_set_reseed_interval(RAND_DRBG *drbg, unsigned int interval); |
08a65d96 | 96 | int RAND_DRBG_set_reseed_time_interval(RAND_DRBG *drbg, time_t interval); |
a93ba405 | 97 | |
4917e911 DMSP |
98 | int RAND_DRBG_set_reseed_defaults( |
99 | unsigned int master_reseed_interval, | |
100 | unsigned int slave_reseed_interval, | |
101 | time_t master_reseed_time_interval, | |
102 | time_t slave_reseed_time_interval | |
103 | ); | |
104 | ||
a93ba405 DMSP |
105 | RAND_DRBG *RAND_DRBG_get0_master(void); |
106 | RAND_DRBG *RAND_DRBG_get0_public(void); | |
107 | RAND_DRBG *RAND_DRBG_get0_private(void); | |
75e2c877 RS |
108 | |
109 | /* | |
110 | * EXDATA | |
111 | */ | |
6decf943 | 112 | # define RAND_DRBG_get_ex_new_index(l, p, newf, dupf, freef) \ |
75e2c877 | 113 | CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DRBG, l, p, newf, dupf, freef) |
a73d990e DMSP |
114 | int RAND_DRBG_set_ex_data(RAND_DRBG *drbg, int idx, void *arg); |
115 | void *RAND_DRBG_get_ex_data(const RAND_DRBG *drbg, int idx); | |
12fb8c3d | 116 | |
75e2c877 | 117 | /* |
6decf943 | 118 | * Callback function typedefs |
75e2c877 | 119 | */ |
a73d990e | 120 | typedef size_t (*RAND_DRBG_get_entropy_fn)(RAND_DRBG *drbg, |
75e2c877 | 121 | unsigned char **pout, |
16960a9b | 122 | int entropy, size_t min_len, |
eb238134 KR |
123 | size_t max_len, |
124 | int prediction_resistance); | |
75e2c877 | 125 | typedef void (*RAND_DRBG_cleanup_entropy_fn)(RAND_DRBG *ctx, |
6969a3f4 | 126 | unsigned char *out, size_t outlen); |
a73d990e | 127 | typedef size_t (*RAND_DRBG_get_nonce_fn)(RAND_DRBG *drbg, unsigned char **pout, |
16960a9b BK |
128 | int entropy, size_t min_len, |
129 | size_t max_len); | |
a73d990e | 130 | typedef void (*RAND_DRBG_cleanup_nonce_fn)(RAND_DRBG *drbg, |
6969a3f4 | 131 | unsigned char *out, size_t outlen); |
16960a9b | 132 | |
a73d990e | 133 | int RAND_DRBG_set_callbacks(RAND_DRBG *drbg, |
16960a9b BK |
134 | RAND_DRBG_get_entropy_fn get_entropy, |
135 | RAND_DRBG_cleanup_entropy_fn cleanup_entropy, | |
136 | RAND_DRBG_get_nonce_fn get_nonce, | |
137 | RAND_DRBG_cleanup_nonce_fn cleanup_nonce); | |
12fb8c3d | 138 | |
c16de9d8 | 139 | |
6decf943 DMSP |
140 | # ifdef __cplusplus |
141 | } | |
142 | # endif | |
c16de9d8 | 143 | |
12fb8c3d | 144 | #endif |