2016-05-17 19:38:09 +00:00
|
|
|
/*
|
2018-03-20 13:00:17 +00:00
|
|
|
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2016-05-17 19:38:09 +00:00
|
|
|
*
|
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
2016-04-06 10:19:55 +00:00
|
|
|
/*
|
|
|
|
* Licensed under the OpenSSL licenses, (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
* or in the file LICENSE in the source distribution.
|
|
|
|
*/
|
|
|
|
|
2018-03-05 22:45:44 +00:00
|
|
|
#ifndef HEADER_RAND_INT_H
|
|
|
|
# define HEADER_RAND_INT_H
|
|
|
|
|
|
|
|
# include <openssl/rand.h>
|
|
|
|
|
|
|
|
/* forward declaration */
|
|
|
|
typedef struct rand_pool_st RAND_POOL;
|
2016-04-06 10:19:55 +00:00
|
|
|
|
2016-04-12 11:20:16 +00:00
|
|
|
void rand_cleanup_int(void);
|
2017-08-31 21:16:22 +00:00
|
|
|
void rand_drbg_cleanup_int(void);
|
2018-03-07 18:25:55 +00:00
|
|
|
void drbg_delete_thread_state(void);
|
2017-08-06 22:12:28 +00:00
|
|
|
void rand_fork(void);
|
2018-03-05 22:45:44 +00:00
|
|
|
|
|
|
|
/* Hardware-based seeding functions. */
|
|
|
|
size_t rand_acquire_entropy_from_tsc(RAND_POOL *pool);
|
|
|
|
size_t rand_acquire_entropy_from_cpu(RAND_POOL *pool);
|
|
|
|
|
|
|
|
/* DRBG entropy callbacks. */
|
|
|
|
size_t rand_drbg_get_entropy(RAND_DRBG *drbg,
|
|
|
|
unsigned char **pout,
|
2018-02-18 18:26:55 +00:00
|
|
|
int entropy, size_t min_len, size_t max_len,
|
|
|
|
int prediction_resistance);
|
2018-03-05 22:45:44 +00:00
|
|
|
void rand_drbg_cleanup_entropy(RAND_DRBG *drbg,
|
|
|
|
unsigned char *out, size_t outlen);
|
2018-04-10 08:22:52 +00:00
|
|
|
size_t rand_drbg_get_nonce(RAND_DRBG *drbg,
|
|
|
|
unsigned char **pout,
|
|
|
|
int entropy, size_t min_len, size_t max_len);
|
|
|
|
void rand_drbg_cleanup_nonce(RAND_DRBG *drbg,
|
|
|
|
unsigned char *out, size_t outlen);
|
|
|
|
|
2018-10-27 09:31:21 +00:00
|
|
|
size_t rand_drbg_get_additional_data(RAND_POOL *pool, unsigned char **pout);
|
2018-03-05 22:45:44 +00:00
|
|
|
|
2018-10-27 09:31:21 +00:00
|
|
|
void rand_drbg_cleanup_additional_data(RAND_POOL *pool, unsigned char *out);
|
2018-03-05 22:45:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* RAND_POOL functions
|
|
|
|
*/
|
2019-07-23 13:14:14 +00:00
|
|
|
RAND_POOL *rand_pool_new(int entropy_requested, int secure,
|
|
|
|
size_t min_len, size_t max_len);
|
2018-10-09 23:53:29 +00:00
|
|
|
RAND_POOL *rand_pool_attach(const unsigned char *buffer, size_t len,
|
|
|
|
size_t entropy);
|
2018-03-05 22:45:44 +00:00
|
|
|
void rand_pool_free(RAND_POOL *pool);
|
|
|
|
|
|
|
|
const unsigned char *rand_pool_buffer(RAND_POOL *pool);
|
|
|
|
unsigned char *rand_pool_detach(RAND_POOL *pool);
|
2018-10-27 09:31:21 +00:00
|
|
|
void rand_pool_reattach(RAND_POOL *pool, unsigned char *buffer);
|
2018-03-05 22:45:44 +00:00
|
|
|
|
|
|
|
size_t rand_pool_entropy(RAND_POOL *pool);
|
|
|
|
size_t rand_pool_length(RAND_POOL *pool);
|
|
|
|
|
|
|
|
size_t rand_pool_entropy_available(RAND_POOL *pool);
|
|
|
|
size_t rand_pool_entropy_needed(RAND_POOL *pool);
|
2018-05-02 04:24:20 +00:00
|
|
|
/* |entropy_factor| expresses how many bits of data contain 1 bit of entropy */
|
|
|
|
size_t rand_pool_bytes_needed(RAND_POOL *pool, unsigned int entropy_factor);
|
2018-03-05 22:45:44 +00:00
|
|
|
size_t rand_pool_bytes_remaining(RAND_POOL *pool);
|
|
|
|
|
2018-04-04 18:17:50 +00:00
|
|
|
int rand_pool_add(RAND_POOL *pool,
|
|
|
|
const unsigned char *buffer, size_t len, size_t entropy);
|
2018-03-05 22:45:44 +00:00
|
|
|
unsigned char *rand_pool_add_begin(RAND_POOL *pool, size_t len);
|
2018-04-04 18:17:50 +00:00
|
|
|
int rand_pool_add_end(RAND_POOL *pool, size_t len, size_t entropy);
|
2018-03-05 22:45:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add random bytes to the pool to acquire requested amount of entropy
|
|
|
|
*
|
|
|
|
* This function is platform specific and tries to acquire the requested
|
|
|
|
* amount of entropy by polling platform specific entropy sources.
|
|
|
|
*
|
|
|
|
* If the function succeeds in acquiring at least |entropy_requested| bits
|
|
|
|
* of entropy, the total entropy count is returned. If it fails, it returns
|
|
|
|
* an entropy count of 0.
|
|
|
|
*/
|
|
|
|
size_t rand_pool_acquire_entropy(RAND_POOL *pool);
|
|
|
|
|
2018-04-10 08:22:52 +00:00
|
|
|
/*
|
|
|
|
* Add some application specific nonce data
|
|
|
|
*
|
|
|
|
* This function is platform specific and adds some application specific
|
|
|
|
* data to the nonce used for instantiating the drbg.
|
|
|
|
*
|
|
|
|
* This data currently consists of the process and thread id, and a high
|
|
|
|
* resolution timestamp. The data does not include an atomic counter,
|
|
|
|
* because that is added by the calling function rand_drbg_get_nonce().
|
|
|
|
*
|
|
|
|
* Returns 1 on success and 0 on failure.
|
|
|
|
*/
|
|
|
|
int rand_pool_add_nonce_data(RAND_POOL *pool);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add some platform specific additional data
|
|
|
|
*
|
|
|
|
* This function is platform specific and adds some random noise to the
|
|
|
|
* additional data used for generating random bytes and for reseeding
|
|
|
|
* the drbg.
|
|
|
|
*
|
|
|
|
* Returns 1 on success and 0 on failure.
|
|
|
|
*/
|
|
|
|
int rand_pool_add_additional_data(RAND_POOL *pool);
|
|
|
|
|
2018-06-06 23:31:44 +00:00
|
|
|
/*
|
|
|
|
* Initialise the random pool reseeding sources.
|
|
|
|
*
|
|
|
|
* Returns 1 on success and 0 on failure.
|
|
|
|
*/
|
|
|
|
int rand_pool_init(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finalise the random pool reseeding sources.
|
|
|
|
*/
|
|
|
|
void rand_pool_cleanup(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Control the random pool use of open file descriptors.
|
|
|
|
*/
|
|
|
|
void rand_pool_keep_random_devices_open(int keep);
|
|
|
|
|
2018-03-05 22:45:44 +00:00
|
|
|
#endif
|