#ifndef OSSL_CRYPTO_RAND_H
#define OSSL_CRYPTO_RAND_H
#pragma once
#include <openssl/rand.h>
#include "crypto/rand_pool.h"
#if defined(__APPLE__) && !defined(OPENSSL_NO_APPLE_CRYPTO_RANDOM)
#include <Availability.h>
#if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000)
#define OPENSSL_APPLE_CRYPTO_RANDOM 1
#include <CommonCrypto/CommonCryptoError.h>
#include <CommonCrypto/CommonRandom.h>
#endif
#endif
#ifndef DEVRANDOM
#define DEVRANDOM "/dev/urandom", "/dev/random", "/dev/hwrng", "/dev/srandom"
#if defined(__linux) && !defined(__ANDROID__)
#ifndef DEVRANDOM_WAIT
#define DEVRANDOM_WAIT "/dev/random"
#endif
#ifndef DEVRANDOM_SAFE_KERNEL
#define DEVRANDOM_SAFE_KERNEL 4, 8
#endif
#ifndef DEVRANDM_WAIT_USE_SELECT
#define DEVRANDM_WAIT_USE_SELECT 1
#endif
#ifndef OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID
#define OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID 114
#endif
#endif
#endif
#if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
#define DEVRANDOM_EGD "/var/run/egd-pool", "/dev/egd-pool", "/etc/egd-pool", "/etc/entropy"
#endif
void ossl_rand_cleanup_int(void);
int ossl_rand_pool_init(void);
void ossl_rand_pool_cleanup(void);
void ossl_rand_pool_keep_random_devices_open(int keep);
void ossl_random_add_conf_module(void);
size_t ossl_rand_get_entropy(OSSL_LIB_CTX *ctx,
unsigned char **pout, int entropy,
size_t min_len, size_t max_len);
size_t ossl_rand_get_user_entropy(OSSL_LIB_CTX *ctx,
unsigned char **pout, int entropy,
size_t min_len, size_t max_len);
void ossl_rand_cleanup_entropy(OSSL_LIB_CTX *ctx,
unsigned char *buf, size_t len);
void ossl_rand_cleanup_user_entropy(OSSL_LIB_CTX *ctx,
unsigned char *buf, size_t len);
size_t ossl_rand_get_nonce(OSSL_LIB_CTX *ctx,
unsigned char **pout, size_t min_len, size_t max_len,
const void *salt, size_t salt_len);
size_t ossl_rand_get_user_nonce(OSSL_LIB_CTX *ctx, unsigned char **pout,
size_t min_len, size_t max_len,
const void *salt, size_t salt_len);
void ossl_rand_cleanup_nonce(OSSL_LIB_CTX *ctx,
unsigned char *buf, size_t len);
void ossl_rand_cleanup_user_nonce(OSSL_LIB_CTX *ctx,
unsigned char *buf, size_t len);
size_t ossl_pool_acquire_entropy(RAND_POOL *pool);
int ossl_pool_add_nonce_data(RAND_POOL *pool);
#ifdef FIPS_MODULE
EVP_RAND_CTX *ossl_rand_get0_private_noncreating(OSSL_LIB_CTX *ctx);
#else
EVP_RAND_CTX *ossl_rand_get0_seed_noncreating(OSSL_LIB_CTX *ctx);
#endif
uint32_t ossl_rand_uniform_uint32(OSSL_LIB_CTX *ctx, uint32_t upper, int *err);
uint32_t ossl_rand_range_uint32(OSSL_LIB_CTX *ctx, uint32_t lower, uint32_t upper,
int *err);
#ifndef FIPS_MODULE
int ossl_rand_check_random_provider_on_load(OSSL_LIB_CTX *ctx,
OSSL_PROVIDER *prov);
int ossl_rand_check_random_provider_on_unload(OSSL_LIB_CTX *ctx,
OSSL_PROVIDER *prov);
#endif
#endif