2 * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
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
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.
18 #ifndef HEADER_RAND_INT_H
19 # define HEADER_RAND_INT_H
21 # include <openssl/rand.h>
23 /* forward declaration */
24 typedef struct rand_pool_st RAND_POOL;
26 void rand_cleanup_int(void);
27 void rand_drbg_cleanup_int(void);
28 void drbg_delete_thread_state(void);
31 /* Hardware-based seeding functions. */
32 size_t rand_acquire_entropy_from_tsc(RAND_POOL *pool);
33 size_t rand_acquire_entropy_from_cpu(RAND_POOL *pool);
35 /* DRBG entropy callbacks. */
36 size_t rand_drbg_get_entropy(RAND_DRBG *drbg,
38 int entropy, size_t min_len, size_t max_len,
39 int prediction_resistance);
40 void rand_drbg_cleanup_entropy(RAND_DRBG *drbg,
41 unsigned char *out, size_t outlen);
42 size_t rand_drbg_get_nonce(RAND_DRBG *drbg,
44 int entropy, size_t min_len, size_t max_len);
45 void rand_drbg_cleanup_nonce(RAND_DRBG *drbg,
46 unsigned char *out, size_t outlen);
48 size_t rand_drbg_get_additional_data(RAND_POOL *pool, unsigned char **pout);
50 void rand_drbg_cleanup_additional_data(RAND_POOL *pool, unsigned char *out);
55 RAND_POOL *rand_pool_new(int entropy_requested, int secure,
56 size_t min_len, size_t max_len);
57 RAND_POOL *rand_pool_attach(const unsigned char *buffer, size_t len,
59 void rand_pool_free(RAND_POOL *pool);
61 const unsigned char *rand_pool_buffer(RAND_POOL *pool);
62 unsigned char *rand_pool_detach(RAND_POOL *pool);
63 void rand_pool_reattach(RAND_POOL *pool, unsigned char *buffer);
65 size_t rand_pool_entropy(RAND_POOL *pool);
66 size_t rand_pool_length(RAND_POOL *pool);
68 size_t rand_pool_entropy_available(RAND_POOL *pool);
69 size_t rand_pool_entropy_needed(RAND_POOL *pool);
70 /* |entropy_factor| expresses how many bits of data contain 1 bit of entropy */
71 size_t rand_pool_bytes_needed(RAND_POOL *pool, unsigned int entropy_factor);
72 size_t rand_pool_bytes_remaining(RAND_POOL *pool);
74 int rand_pool_add(RAND_POOL *pool,
75 const unsigned char *buffer, size_t len, size_t entropy);
76 unsigned char *rand_pool_add_begin(RAND_POOL *pool, size_t len);
77 int rand_pool_add_end(RAND_POOL *pool, size_t len, size_t entropy);
81 * Add random bytes to the pool to acquire requested amount of entropy
83 * This function is platform specific and tries to acquire the requested
84 * amount of entropy by polling platform specific entropy sources.
86 * If the function succeeds in acquiring at least |entropy_requested| bits
87 * of entropy, the total entropy count is returned. If it fails, it returns
88 * an entropy count of 0.
90 size_t rand_pool_acquire_entropy(RAND_POOL *pool);
93 * Add some application specific nonce data
95 * This function is platform specific and adds some application specific
96 * data to the nonce used for instantiating the drbg.
98 * This data currently consists of the process and thread id, and a high
99 * resolution timestamp. The data does not include an atomic counter,
100 * because that is added by the calling function rand_drbg_get_nonce().
102 * Returns 1 on success and 0 on failure.
104 int rand_pool_add_nonce_data(RAND_POOL *pool);
108 * Add some platform specific additional data
110 * This function is platform specific and adds some random noise to the
111 * additional data used for generating random bytes and for reseeding
114 * Returns 1 on success and 0 on failure.
116 int rand_pool_add_additional_data(RAND_POOL *pool);
119 * Initialise the random pool reseeding sources.
121 * Returns 1 on success and 0 on failure.
123 int rand_pool_init(void);
126 * Finalise the random pool reseeding sources.
128 void rand_pool_cleanup(void);
131 * Control the random pool use of open file descriptors.
133 void rand_pool_keep_random_devices_open(int keep);