Publish the RAND_DRBG API
[openssl.git] / crypto / include / internal / rand_int.h
1 /*
2  * Copyright 2016 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 /*
11  * Licensed under the OpenSSL licenses, (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_drbg_cleanup_int(void);
28 void rand_fork(void);
29
30 /* Hardware-based seeding functions. */
31 size_t rand_acquire_entropy_from_tsc(RAND_POOL *pool);
32 size_t rand_acquire_entropy_from_cpu(RAND_POOL *pool);
33
34 /* DRBG entropy callbacks. */
35 size_t rand_drbg_get_entropy(RAND_DRBG *drbg,
36                              unsigned char **pout,
37                              int entropy, size_t min_len, size_t max_len);
38 void rand_drbg_cleanup_entropy(RAND_DRBG *drbg,
39                                unsigned char *out, size_t outlen);
40 size_t rand_drbg_get_additional_data(unsigned char **pout, size_t max_len);
41
42
43 /*
44  * RAND_POOL functions
45  */
46 RAND_POOL *rand_pool_new(int entropy_requested, size_t min_len, size_t max_len);
47 void rand_pool_free(RAND_POOL *pool);
48
49 const unsigned char *rand_pool_buffer(RAND_POOL *pool);
50 unsigned char *rand_pool_detach(RAND_POOL *pool);
51
52 size_t rand_pool_entropy(RAND_POOL *pool);
53 size_t rand_pool_length(RAND_POOL *pool);
54
55 size_t rand_pool_entropy_available(RAND_POOL *pool);
56 size_t rand_pool_entropy_needed(RAND_POOL *pool);
57 size_t rand_pool_bytes_needed(RAND_POOL *pool, unsigned int entropy_per_byte);
58 size_t rand_pool_bytes_remaining(RAND_POOL *pool);
59
60 size_t rand_pool_add(RAND_POOL *pool,
61                      const unsigned char *buffer, size_t len, size_t entropy);
62 unsigned char *rand_pool_add_begin(RAND_POOL *pool, size_t len);
63 size_t rand_pool_add_end(RAND_POOL *pool, size_t len, size_t entropy);
64
65
66 /*
67  * Add random bytes to the pool to acquire requested amount of entropy
68  *
69  * This function is platform specific and tries to acquire the requested
70  * amount of entropy by polling platform specific entropy sources.
71  *
72  * If the function succeeds in acquiring at least |entropy_requested| bits
73  * of entropy, the total entropy count is returned. If it fails, it returns
74  * an entropy count of 0.
75  */
76 size_t rand_pool_acquire_entropy(RAND_POOL *pool);
77
78 #endif