Add missing EBCDIC strings
[openssl.git] / crypto / include / internal / rand_int.h
1 /*
2  * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (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 /*
11  * Licensed under the Apache License 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  * https://www.openssl.org/source/license.html
15  * or in the file LICENSE in the source distribution.
16  */
17
18 #ifndef HEADER_RAND_INT_H
19 # define HEADER_RAND_INT_H
20
21 # include <openssl/rand.h>
22
23 /* forward declaration */
24 typedef struct rand_pool_st RAND_POOL;
25
26 void rand_cleanup_int(void);
27 void rand_fork(void);
28
29 /* Hardware-based seeding functions. */
30 size_t rand_acquire_entropy_from_tsc(RAND_POOL *pool);
31 size_t rand_acquire_entropy_from_cpu(RAND_POOL *pool);
32
33 /* DRBG entropy callbacks. */
34 size_t rand_drbg_get_entropy(RAND_DRBG *drbg,
35                              unsigned char **pout,
36                              int entropy, size_t min_len, size_t max_len,
37                              int prediction_resistance);
38 void rand_drbg_cleanup_entropy(RAND_DRBG *drbg,
39                                unsigned char *out, size_t outlen);
40 size_t rand_drbg_get_nonce(RAND_DRBG *drbg,
41                            unsigned char **pout,
42                            int entropy, size_t min_len, size_t max_len);
43 void rand_drbg_cleanup_nonce(RAND_DRBG *drbg,
44                              unsigned char *out, size_t outlen);
45
46 size_t rand_drbg_get_additional_data(RAND_POOL *pool, unsigned char **pout);
47
48 void rand_drbg_cleanup_additional_data(RAND_POOL *pool, unsigned char *out);
49
50 /* CRNG test entropy filter callbacks. */
51 size_t rand_crngt_get_entropy(RAND_DRBG *drbg,
52                               unsigned char **pout,
53                               int entropy, size_t min_len, size_t max_len,
54                               int prediction_resistance);
55 void rand_crngt_cleanup_entropy(RAND_DRBG *drbg,
56                                 unsigned char *out, size_t outlen);
57
58 /*
59  * RAND_POOL functions
60  */
61 RAND_POOL *rand_pool_new(int entropy_requested, int secure,
62                          size_t min_len, size_t max_len);
63 RAND_POOL *rand_pool_attach(const unsigned char *buffer, size_t len,
64                             size_t entropy);
65 void rand_pool_free(RAND_POOL *pool);
66
67 const unsigned char *rand_pool_buffer(RAND_POOL *pool);
68 unsigned char *rand_pool_detach(RAND_POOL *pool);
69 void rand_pool_reattach(RAND_POOL *pool, unsigned char *buffer);
70
71 size_t rand_pool_entropy(RAND_POOL *pool);
72 size_t rand_pool_length(RAND_POOL *pool);
73
74 size_t rand_pool_entropy_available(RAND_POOL *pool);
75 size_t rand_pool_entropy_needed(RAND_POOL *pool);
76 /* |entropy_factor| expresses how many bits of data contain 1 bit of entropy */
77 size_t rand_pool_bytes_needed(RAND_POOL *pool, unsigned int entropy_factor);
78 size_t rand_pool_bytes_remaining(RAND_POOL *pool);
79
80 int rand_pool_add(RAND_POOL *pool,
81                   const unsigned char *buffer, size_t len, size_t entropy);
82 unsigned char *rand_pool_add_begin(RAND_POOL *pool, size_t len);
83 int rand_pool_add_end(RAND_POOL *pool, size_t len, size_t entropy);
84
85
86 /*
87  * Add random bytes to the pool to acquire requested amount of entropy
88  *
89  * This function is platform specific and tries to acquire the requested
90  * amount of entropy by polling platform specific entropy sources.
91  *
92  * If the function succeeds in acquiring at least |entropy_requested| bits
93  * of entropy, the total entropy count is returned. If it fails, it returns
94  * an entropy count of 0.
95  */
96 size_t rand_pool_acquire_entropy(RAND_POOL *pool);
97
98 /*
99  * Add some application specific nonce data
100  *
101  * This function is platform specific and adds some application specific
102  * data to the nonce used for instantiating the drbg.
103  *
104  * This data currently consists of the process and thread id, and a high
105  * resolution timestamp. The data does not include an atomic counter,
106  * because that is added by the calling function rand_drbg_get_nonce().
107  *
108  * Returns 1 on success and 0 on failure.
109  */
110 int rand_pool_add_nonce_data(RAND_POOL *pool);
111
112
113 /*
114  * Add some platform specific additional data
115  *
116  * This function is platform specific and adds some random noise to the
117  * additional data used for generating random bytes and for reseeding
118  * the drbg.
119  *
120  * Returns 1 on success and 0 on failure.
121  */
122 int rand_pool_add_additional_data(RAND_POOL *pool);
123
124 /*
125  * Initialise the random pool reseeding sources.
126  *
127  * Returns 1 on success and 0 on failure.
128  */
129 int rand_pool_init(void);
130
131 /*
132  * Finalise the random pool reseeding sources.
133  */
134 void rand_pool_cleanup(void);
135
136 /*
137  * Control the random pool use of open file descriptors.
138  */
139 void rand_pool_keep_random_devices_open(int keep);
140
141 /* Equivalent of RAND_priv_bytes() but additionally taking an OPENSSL_CTX */
142 int rand_priv_bytes_ex(OPENSSL_CTX *ctx, unsigned char *buf, int num);
143
144 /* Equivalent of RAND_bytes() but additionally taking an OPENSSL_CTX */
145 int rand_bytes_ex(OPENSSL_CTX *ctx, unsigned char *buf, int num);
146
147 #endif