/*
* Note that cleanup order is important:
- * - rand_cleanup_int could call an ENGINE's RAND cleanup function so
+ * - ossl_rand_cleanup_int could call an ENGINE's RAND cleanup function so
* must be called before engine_cleanup_int()
* - ENGINEs use CRYPTO_EX_DATA and therefore, must be cleaned up
* before the ex data handlers are wiped during default ossl_lib_ctx deinit.
* - ENGINEs and additional EVP algorithms might use added OIDs names so
* obj_cleanup_int() must be called last
*/
- OSSL_TRACE(INIT, "OPENSSL_cleanup: rand_cleanup_int()\n");
- rand_cleanup_int();
+ OSSL_TRACE(INIT, "OPENSSL_cleanup: ossl_rand_cleanup_int()\n");
+ ossl_rand_cleanup_int();
OSSL_TRACE(INIT, "OPENSSL_cleanup: conf_modules_free_int()\n");
conf_modules_free_int();
size_t entropy_available;
RAND_POOL *pool;
- pool = rand_pool_new(entropy, 1, min_len, max_len);
+ pool = ossl_rand_pool_new(entropy, 1, min_len, max_len);
if (pool == NULL) {
ERR_raise(ERR_LIB_RAND, ERR_R_MALLOC_FAILURE);
return 0;
entropy_available = ossl_pool_acquire_entropy(pool);
if (entropy_available > 0) {
- ret = rand_pool_length(pool);
- *pout = rand_pool_detach(pool);
+ ret = ossl_rand_pool_length(pool);
+ *pout = ossl_rand_pool_detach(pool);
}
- rand_pool_free(pool);
+ ossl_rand_pool_free(pool);
return ret;
}
size_t ret = 0;
RAND_POOL *pool;
- pool = rand_pool_new(0, 0, min_len, max_len);
+ pool = ossl_rand_pool_new(0, 0, min_len, max_len);
if (pool == NULL) {
ERR_raise(ERR_LIB_RAND, ERR_R_MALLOC_FAILURE);
return 0;
if (!ossl_pool_add_nonce_data(pool))
goto err;
- if (salt != NULL && !rand_pool_add(pool, salt, salt_len, 0))
+ if (salt != NULL && !ossl_rand_pool_add(pool, salt, salt_len, 0))
goto err;
- ret = rand_pool_length(pool);
- *pout = rand_pool_detach(pool);
+ ret = ossl_rand_pool_length(pool);
+ *pout = ossl_rand_pool_detach(pool);
err:
- rand_pool_free(pool);
+ ossl_rand_pool_free(pool);
return ret;
}
goto err;
# endif
- if (!rand_pool_init())
+ if (!ossl_rand_pool_init())
goto err;
rand_inited = 1;
return 0;
}
-void rand_cleanup_int(void)
+void ossl_rand_cleanup_int(void)
{
# ifndef OPENSSL_NO_DEPRECATED_3_0
const RAND_METHOD *meth = default_RAND_meth;
meth->cleanup();
RAND_set_rand_method(NULL);
# endif
- rand_pool_cleanup();
+ ossl_rand_pool_cleanup();
# ifndef OPENSSL_NO_ENGINE
CRYPTO_THREAD_lock_free(rand_engine_lock);
rand_engine_lock = NULL;
void RAND_keep_random_devices_open(int keep)
{
if (RUN_ONCE(&rand_init, do_rand_init))
- rand_pool_keep_random_devices_open(keep);
+ ossl_rand_pool_keep_random_devices_open(keep);
}
/*
if (!ret) {
/* fill random pool and seed the current legacy RNG */
- RAND_POOL *pool = rand_pool_new(RAND_DRBG_STRENGTH, 1,
- (RAND_DRBG_STRENGTH + 7) / 8,
- RAND_POOL_MAX_LENGTH);
+ RAND_POOL *pool = ossl_rand_pool_new(RAND_DRBG_STRENGTH, 1,
+ (RAND_DRBG_STRENGTH + 7) / 8,
+ RAND_POOL_MAX_LENGTH);
if (pool == NULL)
return 0;
goto err;
if (meth->add == NULL
- || meth->add(rand_pool_buffer(pool),
- rand_pool_length(pool),
- (rand_pool_entropy(pool) / 8.0)) == 0)
+ || meth->add(ossl_rand_pool_buffer(pool),
+ ossl_rand_pool_length(pool),
+ (ossl_rand_pool_entropy(pool) / 8.0)) == 0)
goto err;
ret = 1;
err:
- rand_pool_free(pool);
+ ossl_rand_pool_free(pool);
}
return ret;
# else
default_RAND_meth = tmp_meth;
} else {
ENGINE_finish(e);
- default_RAND_meth = &rand_meth;
+ default_RAND_meth = &ossl_rand_meth;
}
# else
- default_RAND_meth = &rand_meth;
+ default_RAND_meth = &ossl_rand_meth;
# endif
}
tmp_meth = default_RAND_meth;
# define SECONDARY_RESEED_TIME_INTERVAL (7 * 60) /* 7 minutes */
/* The global RAND method, and the global buffer and DRBG instance. */
-extern RAND_METHOD rand_meth;
+extern RAND_METHOD ossl_rand_meth;
#endif
return EVP_RAND_generate(drbg, out, count, 0, 0, NULL, 0);
}
-RAND_METHOD rand_meth = {
+RAND_METHOD ossl_rand_meth = {
drbg_seed,
drbg_bytes,
NULL,
RAND_METHOD *RAND_OpenSSL(void)
{
#ifndef FIPS_MODULE
- return &rand_meth;
+ return &ossl_rand_meth;
#else
return NULL;
#endif
/*
* Allocate memory and initialize a new random pool
*/
-RAND_POOL *rand_pool_new(int entropy_requested, int secure,
- size_t min_len, size_t max_len)
+RAND_POOL *ossl_rand_pool_new(int entropy_requested, int secure,
+ size_t min_len, size_t max_len)
{
RAND_POOL *pool = OPENSSL_zalloc(sizeof(*pool));
size_t min_alloc_size = RAND_POOL_MIN_ALLOCATION(secure);
* This function is intended to be used only for feeding random data
* provided by RAND_add() and RAND_seed() into the <master> DRBG.
*/
-RAND_POOL *rand_pool_attach(const unsigned char *buffer, size_t len,
- size_t entropy)
+RAND_POOL *ossl_rand_pool_attach(const unsigned char *buffer, size_t len,
+ size_t entropy)
{
RAND_POOL *pool = OPENSSL_zalloc(sizeof(*pool));
/*
* Free |pool|, securely erasing its buffer.
*/
-void rand_pool_free(RAND_POOL *pool)
+void ossl_rand_pool_free(RAND_POOL *pool)
{
if (pool == NULL)
return;
/*
* Although it would be advisable from a cryptographical viewpoint,
* we are not allowed to clear attached buffers, since they are passed
- * to rand_pool_attach() as `const unsigned char*`.
- * (see corresponding comment in rand_pool_attach()).
+ * to ossl_rand_pool_attach() as `const unsigned char*`.
+ * (see corresponding comment in ossl_rand_pool_attach()).
*/
if (!pool->attached) {
if (pool->secure)
/*
* Return the |pool|'s buffer to the caller (readonly).
*/
-const unsigned char *rand_pool_buffer(RAND_POOL *pool)
+const unsigned char *ossl_rand_pool_buffer(RAND_POOL *pool)
{
return pool->buffer;
}
/*
* Return the |pool|'s entropy to the caller.
*/
-size_t rand_pool_entropy(RAND_POOL *pool)
+size_t ossl_rand_pool_entropy(RAND_POOL *pool)
{
return pool->entropy;
}
/*
* Return the |pool|'s buffer length to the caller.
*/
-size_t rand_pool_length(RAND_POOL *pool)
+size_t ossl_rand_pool_length(RAND_POOL *pool)
{
return pool->len;
}
* Detach the |pool| buffer and return it to the caller.
* It's the responsibility of the caller to free the buffer
* using OPENSSL_secure_clear_free() or to re-attach it
- * again to the pool using rand_pool_reattach().
+ * again to the pool using ossl_rand_pool_reattach().
*/
-unsigned char *rand_pool_detach(RAND_POOL *pool)
+unsigned char *ossl_rand_pool_detach(RAND_POOL *pool)
{
unsigned char *ret = pool->buffer;
pool->buffer = NULL;
* Re-attach the |pool| buffer. It is only allowed to pass
* the |buffer| which was previously detached from the same pool.
*/
-void rand_pool_reattach(RAND_POOL *pool, unsigned char *buffer)
+void ossl_rand_pool_reattach(RAND_POOL *pool, unsigned char *buffer)
{
pool->buffer = buffer;
OPENSSL_cleanse(pool->buffer, pool->len);
* |entropy| if the entropy count and buffer size is large enough
* 0 otherwise
*/
-size_t rand_pool_entropy_available(RAND_POOL *pool)
+size_t ossl_rand_pool_entropy_available(RAND_POOL *pool)
{
if (pool->entropy < pool->entropy_requested)
return 0;
* the random pool.
*/
-size_t rand_pool_entropy_needed(RAND_POOL *pool)
+size_t ossl_rand_pool_entropy_needed(RAND_POOL *pool)
{
if (pool->entropy < pool->entropy_requested)
return pool->entropy_requested - pool->entropy;
* In case of an error, 0 is returned.
*/
-size_t rand_pool_bytes_needed(RAND_POOL *pool, unsigned int entropy_factor)
+size_t ossl_rand_pool_bytes_needed(RAND_POOL *pool, unsigned int entropy_factor)
{
size_t bytes_needed;
- size_t entropy_needed = rand_pool_entropy_needed(pool);
+ size_t entropy_needed = ossl_rand_pool_entropy_needed(pool);
if (entropy_factor < 1) {
ERR_raise(ERR_LIB_RAND, RAND_R_ARGUMENT_OUT_OF_RANGE);
/*
* Make sure the buffer is large enough for the requested amount
* of data. This guarantees that existing code patterns where
- * rand_pool_add_begin, rand_pool_add_end or rand_pool_add
+ * ossl_rand_pool_add_begin, ossl_rand_pool_add_end or ossl_rand_pool_add
* are used to collect entropy data without any error handling
* whatsoever, continue to be valid.
* Furthermore if the allocation here fails once, make sure that
}
/* Returns the remaining number of bytes available */
-size_t rand_pool_bytes_remaining(RAND_POOL *pool)
+size_t ossl_rand_pool_bytes_remaining(RAND_POOL *pool)
{
return pool->max_len - pool->len;
}
*
* Returns 1 if the added amount is adequate, otherwise 0
*/
-int rand_pool_add(RAND_POOL *pool,
+int ossl_rand_pool_add(RAND_POOL *pool,
const unsigned char *buffer, size_t len, size_t entropy)
{
if (len > pool->max_len - pool->len) {
if (len > 0) {
/*
* This is to protect us from accidentally passing the buffer
- * returned from rand_pool_add_begin.
+ * returned from ossl_rand_pool_add_begin.
* The check for alloc_len makes sure we do not compare the
* address of the end of the allocated memory to something
* different, since that comparison would have an
* We have that only for cases when a pool is used to collect
* additional data.
* For entropy data, as long as the allocation request stays within
- * the limits given by rand_pool_bytes_needed this rand_pool_grow
+ * the limits given by ossl_rand_pool_bytes_needed this rand_pool_grow
* below is guaranteed to succeed, thus no allocation happens.
*/
if (!rand_pool_grow(pool, len))
* If |len| == 0 this is considered a no-op and a NULL pointer
* is returned without producing an error message.
*
- * After updating the buffer, rand_pool_add_end() needs to be called
+ * After updating the buffer, ossl_rand_pool_add_end() needs to be called
* to finish the update operation (see next comment).
*/
-unsigned char *rand_pool_add_begin(RAND_POOL *pool, size_t len)
+unsigned char *ossl_rand_pool_add_begin(RAND_POOL *pool, size_t len)
{
if (len == 0)
return NULL;
/*
* As long as the allocation request stays within the limits given
- * by rand_pool_bytes_needed this rand_pool_grow below is guaranteed
+ * by ossl_rand_pool_bytes_needed this rand_pool_grow below is guaranteed
* to succeed, thus no allocation happens.
* We have that only for cases when a pool is used to collect
* additional data. Then the buffer might need to grow here,
* Finish to add random bytes to the random pool in-place.
*
* Finishes an in-place update of the random pool started by
- * rand_pool_add_begin() (see previous comment).
+ * ossl_rand_pool_add_begin() (see previous comment).
* It is expected that |len| bytes of random input have been added
* to the buffer which contain at least |entropy| bits of randomness.
* It is allowed to add less bytes than originally reserved.
*/
-int rand_pool_add_end(RAND_POOL *pool, size_t len, size_t entropy)
+int ossl_rand_pool_add_end(RAND_POOL *pool, size_t len, size_t entropy)
{
if (len > pool->alloc_len - pool->len) {
ERR_raise(ERR_LIB_RAND, RAND_R_RANDOM_POOL_OVERFLOW);
# define DEVRANDOM_EGD "/var/run/egd-pool", "/dev/egd-pool", "/etc/egd-pool", "/etc/entropy"
#endif
-void rand_cleanup_int(void);
+void ossl_rand_cleanup_int(void);
/*
* Initialise the random pool reseeding sources.
*
* Returns 1 on success and 0 on failure.
*/
-int rand_pool_init(void);
+int ossl_rand_pool_init(void);
/*
* Finalise the random pool reseeding sources.
*/
-void rand_pool_cleanup(void);
+void ossl_rand_pool_cleanup(void);
/*
* Control the random pool use of open file descriptors.
*/
-void rand_pool_keep_random_devices_open(int keep);
+void ossl_rand_pool_keep_random_devices_open(int keep);
/*
* Configuration
*
* The max_len value for the buffer provided to the rand_drbg_get_entropy()
* callback is currently 2^31 bytes (2 gigabytes), if a derivation function
- * is used. Since this is much too large to be allocated, the rand_pool_new()
+ * is used. Since this is much too large to be allocated, the ossl_rand_pool_new()
* function chooses more modest values as default pool length, bounded
* by RAND_POOL_MIN_LENGTH and RAND_POOL_MAX_LENGTH
*
size_t entropy_requested; /* requested entropy count in bits */
} RAND_POOL;
-RAND_POOL *rand_pool_new(int entropy_requested, int secure,
- size_t min_len, size_t max_len);
-RAND_POOL *rand_pool_attach(const unsigned char *buffer, size_t len,
- size_t entropy);
-void rand_pool_free(RAND_POOL *pool);
+RAND_POOL *ossl_rand_pool_new(int entropy_requested, int secure,
+ size_t min_len, size_t max_len);
+RAND_POOL *ossl_rand_pool_attach(const unsigned char *buffer, size_t len,
+ size_t entropy);
+void ossl_rand_pool_free(RAND_POOL *pool);
-const unsigned char *rand_pool_buffer(RAND_POOL *pool);
-unsigned char *rand_pool_detach(RAND_POOL *pool);
-void rand_pool_reattach(RAND_POOL *pool, unsigned char *buffer);
+const unsigned char *ossl_rand_pool_buffer(RAND_POOL *pool);
+unsigned char *ossl_rand_pool_detach(RAND_POOL *pool);
+void ossl_rand_pool_reattach(RAND_POOL *pool, unsigned char *buffer);
-size_t rand_pool_entropy(RAND_POOL *pool);
-size_t rand_pool_length(RAND_POOL *pool);
+size_t ossl_rand_pool_entropy(RAND_POOL *pool);
+size_t ossl_rand_pool_length(RAND_POOL *pool);
-size_t rand_pool_entropy_available(RAND_POOL *pool);
-size_t rand_pool_entropy_needed(RAND_POOL *pool);
+size_t ossl_rand_pool_entropy_available(RAND_POOL *pool);
+size_t ossl_rand_pool_entropy_needed(RAND_POOL *pool);
/* |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);
-size_t rand_pool_bytes_remaining(RAND_POOL *pool);
+size_t ossl_rand_pool_bytes_needed(RAND_POOL *pool, unsigned int entropy_factor);
+size_t ossl_rand_pool_bytes_remaining(RAND_POOL *pool);
-int rand_pool_add(RAND_POOL *pool,
- const unsigned char *buffer, size_t len, size_t entropy);
-unsigned char *rand_pool_add_begin(RAND_POOL *pool, size_t len);
-int rand_pool_add_end(RAND_POOL *pool, size_t len, size_t entropy);
+int ossl_rand_pool_add(RAND_POOL *pool,
+ const unsigned char *buffer, size_t len, size_t entropy);
+unsigned char *ossl_rand_pool_add_begin(RAND_POOL *pool, size_t len);
+int ossl_rand_pool_add_end(RAND_POOL *pool, size_t len, size_t entropy);
#endif /* OSSL_PROVIDER_RAND_POOL_H */
#include "crypto/rand_pool.h"
/* Hardware-based seeding functions. */
-size_t prov_acquire_entropy_from_tsc(RAND_POOL *pool);
-size_t prov_acquire_entropy_from_cpu(RAND_POOL *pool);
-
-/* DRBG entropy callbacks. */
-size_t prov_drbg_get_additional_data(RAND_POOL *pool, unsigned char **pout);
-
-void prov_drbg_cleanup_additional_data(RAND_POOL *pool, unsigned char *out);
+size_t ossl_prov_acquire_entropy_from_tsc(RAND_POOL *pool);
+size_t ossl_prov_acquire_entropy_from_cpu(RAND_POOL *pool);
/*
* Add some platform specific additional data
*
* Returns 1 on success and 0 on failure.
*/
-int rand_pool_add_additional_data(RAND_POOL *pool);
+int ossl_rand_pool_add_additional_data(RAND_POOL *pool);
/*
* External seeding functions from the core dispatch table.
return 0;
}
- pool = rand_pool_new(strength, 1, outlen, outlen);
+ pool = ossl_rand_pool_new(strength, 1, outlen, outlen);
if (pool == NULL) {
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
return 0;
entropy_available = ossl_pool_acquire_entropy(pool);
if (entropy_available > 0)
- memcpy(out, rand_pool_buffer(pool), rand_pool_length(pool));
+ memcpy(out, ossl_rand_pool_buffer(pool), ossl_rand_pool_length(pool));
- rand_pool_free(pool);
+ ossl_rand_pool_free(pool);
return entropy_available > 0;
}
size_t bytes_needed;
unsigned char *buffer;
- bytes_needed = rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
+ bytes_needed = ossl_rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
if (bytes_needed > 0) {
- buffer = rand_pool_add_begin(pool, bytes_needed);
+ buffer = ossl_rand_pool_add_begin(pool, bytes_needed);
if (buffer != NULL) {
if (get_hardware_random_value(buffer, bytes_needed) == bytes_needed) {
- rand_pool_add_end(pool, bytes_needed, 8 * bytes_needed);
+ ossl_rand_pool_add_end(pool, bytes_needed, 8 * bytes_needed);
} else {
- rand_pool_add_end(pool, 0, 0);
+ ossl_rand_pool_add_end(pool, 0, 0);
}
}
}
- return rand_pool_entropy_available(pool);
+ return ossl_rand_pool_entropy_available(pool);
}
#if defined(OPENSSL_SYS_TANDEM) && defined(_TNS_X_TARGET)
* Returns the total entropy count, if it exceeds the requested
* entropy count. Otherwise, returns an entropy count of 0.
*/
-size_t prov_acquire_entropy_from_tsc(RAND_POOL *pool)
+size_t ossl_prov_acquire_entropy_from_tsc(RAND_POOL *pool)
{
unsigned char c;
int i;
if ((OPENSSL_ia32cap_P[0] & (1 << 4)) != 0) {
for (i = 0; i < TSC_READ_COUNT; i++) {
c = (unsigned char)(OPENSSL_rdtsc() & 0xFF);
- rand_pool_add(pool, &c, 1, 4);
+ ossl_rand_pool_add(pool, &c, 1, 4);
}
}
- return rand_pool_entropy_available(pool);
+ return ossl_rand_pool_entropy_available(pool);
}
#else
NON_EMPTY_TRANSLATION_UNIT
extern void s$sleep2(long long *_duration, short int *_code);
# endif
- bytes_needed = rand_pool_bytes_needed(pool, 4 /*entropy_factor*/);
+ bytes_needed = ossl_rand_pool_bytes_needed(pool, 4 /*entropy_factor*/);
for (i = 0; i < bytes_needed; i++) {
/*
/* Get wall clock time, take 8 bits. */
clock_gettime(CLOCK_REALTIME, &ts);
v = (unsigned char)(ts.tv_nsec & 0xFF);
- rand_pool_add(pool, arg, &v, sizeof(v) , 2);
+ ossl_rand_pool_add(pool, arg, &v, sizeof(v) , 2);
}
- return rand_pool_entropy_available(pool);
+ return ossl_rand_pool_entropy_available(pool);
}
-void rand_pool_cleanup(void)
+void ossl_rand_pool_cleanup(void)
{
}
-void rand_pool_keep_random_devices_open(int keep)
+void ossl_rand_pool_keep_random_devices_open(int keep)
{
}
rd->fd = -1;
}
-int rand_pool_init(void)
+int ossl_rand_pool_init(void)
{
size_t i;
return 1;
}
-void rand_pool_cleanup(void)
+void ossl_rand_pool_cleanup(void)
{
size_t i;
close_random_device(i);
}
-void rand_pool_keep_random_devices_open(int keep)
+void ossl_rand_pool_keep_random_devices_open(int keep)
{
if (!keep)
- rand_pool_cleanup();
+ ossl_rand_pool_cleanup();
keep_random_devices_open = keep;
}
# else /* !defined(OPENSSL_RAND_SEED_DEVRANDOM) */
-int rand_pool_init(void)
+int ossl_rand_pool_init(void)
{
return 1;
}
-void rand_pool_cleanup(void)
+void ossl_rand_pool_cleanup(void)
{
}
-void rand_pool_keep_random_devices_open(int keep)
+void ossl_rand_pool_keep_random_devices_open(int keep)
{
}
size_t ossl_pool_acquire_entropy(RAND_POOL *pool)
{
# if defined(OPENSSL_RAND_SEED_NONE)
- return rand_pool_entropy_available(pool);
+ return ossl_rand_pool_entropy_available(pool);
# else
size_t entropy_available = 0;
/* Maximum allowed number of consecutive unsuccessful attempts */
int attempts = 3;
- bytes_needed = rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
+ bytes_needed = ossl_rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
while (bytes_needed != 0 && attempts-- > 0) {
- buffer = rand_pool_add_begin(pool, bytes_needed);
+ buffer = ossl_rand_pool_add_begin(pool, bytes_needed);
bytes = syscall_random(buffer, bytes_needed);
if (bytes > 0) {
- rand_pool_add_end(pool, bytes, 8 * bytes);
+ ossl_rand_pool_add_end(pool, bytes, 8 * bytes);
bytes_needed -= bytes;
attempts = 3; /* reset counter after successful attempt */
} else if (bytes < 0 && errno != EINTR) {
}
}
}
- entropy_available = rand_pool_entropy_available(pool);
+ entropy_available = ossl_rand_pool_entropy_available(pool);
if (entropy_available > 0)
return entropy_available;
# endif
unsigned char *buffer;
size_t i;
- bytes_needed = rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
+ bytes_needed = ossl_rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
for (i = 0; bytes_needed > 0 && i < OSSL_NELEM(random_device_paths);
i++) {
ssize_t bytes = 0;
continue;
while (bytes_needed != 0 && attempts-- > 0) {
- buffer = rand_pool_add_begin(pool, bytes_needed);
+ buffer = ossl_rand_pool_add_begin(pool, bytes_needed);
bytes = read(fd, buffer, bytes_needed);
if (bytes > 0) {
- rand_pool_add_end(pool, bytes, 8 * bytes);
+ ossl_rand_pool_add_end(pool, bytes, 8 * bytes);
bytes_needed -= bytes;
attempts = 3; /* reset counter on successful attempt */
} else if (bytes < 0 && errno != EINTR) {
if (bytes < 0 || !keep_random_devices_open)
close_random_device(i);
- bytes_needed = rand_pool_bytes_needed(pool, 1);
+ bytes_needed = ossl_rand_pool_bytes_needed(pool, 1);
}
- entropy_available = rand_pool_entropy_available(pool);
+ entropy_available = ossl_rand_pool_entropy_available(pool);
if (entropy_available > 0)
return entropy_available;
}
# endif
# if defined(OPENSSL_RAND_SEED_RDTSC)
- entropy_available = prov_acquire_entropy_from_tsc(pool);
+ entropy_available = ossl_prov_acquire_entropy_from_tsc(pool);
if (entropy_available > 0)
return entropy_available;
# endif
# if defined(OPENSSL_RAND_SEED_RDCPU)
- entropy_available = prov_acquire_entropy_from_cpu(pool);
+ entropy_available = ossl_prov_acquire_entropy_from_cpu(pool);
if (entropy_available > 0)
return entropy_available;
# endif
unsigned char *buffer;
int i;
- bytes_needed = rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
+ bytes_needed = ossl_rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
for (i = 0; bytes_needed > 0 && paths[i] != NULL; i++) {
size_t bytes = 0;
int num;
- buffer = rand_pool_add_begin(pool, bytes_needed);
+ buffer = ossl_rand_pool_add_begin(pool, bytes_needed);
num = RAND_query_egd_bytes(paths[i],
buffer, (int)bytes_needed);
if (num == (int)bytes_needed)
bytes = bytes_needed;
- rand_pool_add_end(pool, bytes, 8 * bytes);
- bytes_needed = rand_pool_bytes_needed(pool, 1);
+ ossl_rand_pool_add_end(pool, bytes, 8 * bytes);
+ bytes_needed = ossl_rand_pool_bytes_needed(pool, 1);
}
- entropy_available = rand_pool_entropy_available(pool);
+ entropy_available = ossl_rand_pool_entropy_available(pool);
if (entropy_available > 0)
return entropy_available;
}
# endif
- return rand_pool_entropy_available(pool);
+ return ossl_rand_pool_entropy_available(pool);
# endif
}
# endif
data.tid = CRYPTO_THREAD_get_current_id();
data.time = get_time_stamp();
- return rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
+ return ossl_rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
}
-int rand_pool_add_additional_data(RAND_POOL *pool)
+int ossl_rand_pool_add_additional_data(RAND_POOL *pool)
{
struct {
int fork_id;
data.tid = CRYPTO_THREAD_get_current_id();
data.time = get_timer_bits();
- return rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
+ return ossl_rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
}
} data;
size_t total_elems = 0;
size_t total_length = 0;
- size_t bytes_needed = rand_pool_bytes_needed(pool, ENTROPY_FACTOR);
- size_t bytes_remaining = rand_pool_bytes_remaining(pool);
+ size_t bytes_needed = ossl_rand_pool_bytes_needed(pool, ENTROPY_FACTOR);
+ size_t bytes_remaining = ossl_rand_pool_bytes_remaining(pool);
/* Take all the 64-bit items first, to ensure proper alignment of data */
total_elems +=
total_length = bytes_remaining;
/* We give the pessimistic value for the amount of entropy */
- rand_pool_add(pool, (unsigned char *)data.buffer, total_length,
- 8 * total_length / ENTROPY_FACTOR);
- return rand_pool_entropy_available(pool);
+ ossl_rand_pool_add(pool, (unsigned char *)data.buffer, total_length,
+ 8 * total_length / ENTROPY_FACTOR);
+ return ossl_rand_pool_entropy_available(pool);
}
int ossl_pool_add_nonce_data(RAND_POOL *pool)
sys$gettim((void*)&data.time);
#endif
- return rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
+ return ossl_rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
}
/*
size_t bytes_to_get = 0;
uint32_t status;
- for (bytes_needed = rand_pool_bytes_needed(pool, 1);
+ for (bytes_needed = ossl_rand_pool_bytes_needed(pool, 1);
bytes_needed > 0;
bytes_needed -= bytes_to_get) {
bytes_to_get =
return 0;
}
- rand_pool_add(pool, buffer, bytes_to_get, 8 * bytes_to_get);
+ ossl_rand_pool_add(pool, buffer, bytes_to_get, 8 * bytes_to_get);
}
- return rand_pool_entropy_available(pool);
+ return ossl_rand_pool_entropy_available(pool);
}
/*
}
-int rand_pool_add_additional_data(RAND_POOL *pool)
+int ossl_rand_pool_add_additional_data(RAND_POOL *pool)
{
struct {
CRYPTO_THREAD_ID tid;
sys$gettim((void*)&data.time);
#endif
- return rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
+ return ossl_rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
}
-int rand_pool_init(void)
+int ossl_rand_pool_init(void)
{
return 1;
}
-void rand_pool_cleanup(void)
+void ossl_rand_pool_cleanup(void)
{
}
-void rand_pool_keep_random_devices_open(int keep)
+void ossl_rand_pool_keep_random_devices_open(int keep)
{
}
* empty implementation
* vxworks does not need to init/cleanup or keep open the random lib
*/
-int rand_pool_init(void)
+int ossl_rand_pool_init(void)
{
return 1;
}
-void rand_pool_cleanup(void)
+void ossl_rand_pool_cleanup(void)
{
}
-void rand_pool_keep_random_devices_open(int keep)
+void ossl_rand_pool_keep_random_devices_open(int keep)
{
}
-int rand_pool_add_additional_data(RAND_POOL *pool)
+int ossl_rand_pool_add_additional_data(RAND_POOL *pool)
{
struct {
CRYPTO_THREAD_ID tid;
data.tid = CRYPTO_THREAD_get_current_id();
data.time = get_timer_bits();
- return rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
+ return ossl_rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
}
int ossl_pool_add_nonce_data(RAND_POOL *pool)
data.tid = CRYPTO_THREAD_get_current_id();
data.time = get_time_stamp();
- return rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
+ return ossl_rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
}
size_t ossl_pool_acquire_entropy(RAND_POOL *pool)
/* vxRandLib based entropy method */
size_t bytes_needed;
- bytes_needed = rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
+ bytes_needed = ossl_rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
if (bytes_needed > 0)
{
int retryCount = 0;
STATUS result = ERROR;
unsigned char *buffer;
- buffer = rand_pool_add_begin(pool, bytes_needed);
+ buffer = ossl_rand_pool_add_begin(pool, bytes_needed);
while ((result != OK) && (retryCount < 10)) {
RANDOM_NUM_GEN_STATUS status = randStatus();
|| (status == RANDOM_NUM_GEN_MAX_ENTROPY) ) {
result = randBytes(buffer, bytes_needed);
if (result == OK)
- rand_pool_add_end(pool, bytes_needed, 8 * bytes_needed);
+ ossl_rand_pool_add_end(pool, bytes_needed, 8 * bytes_needed);
/*
* no else here: randStatus said ok, if randBytes failed
* it will result in another loop or no entropy
retryCount++;
}
}
- return rand_pool_entropy_available(pool);
+ return ossl_rand_pool_entropy_available(pool);
#else
/*
* SEED_NONE means none, without randlib we dont have entropy and
* rely on it being added externally
*/
- return rand_pool_entropy_available(pool);
+ return ossl_rand_pool_entropy_available(pool);
#endif /* defined(RAND_SEED_VXRANDLIB) */
}
# ifdef OPENSSL_RAND_SEED_RDTSC
- entropy_available = prov_acquire_entropy_from_tsc(pool);
+ entropy_available = ossl_prov_acquire_entropy_from_tsc(pool);
if (entropy_available > 0)
return entropy_available;
# endif
# ifdef OPENSSL_RAND_SEED_RDCPU
- entropy_available = prov_acquire_entropy_from_cpu(pool);
+ entropy_available = ossl_prov_acquire_entropy_from_cpu(pool);
if (entropy_available > 0)
return entropy_available;
# endif
# ifdef USE_BCRYPTGENRANDOM
- bytes_needed = rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
- buffer = rand_pool_add_begin(pool, bytes_needed);
+ bytes_needed = ossl_rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
+ buffer = ossl_rand_pool_add_begin(pool, bytes_needed);
if (buffer != NULL) {
size_t bytes = 0;
if (BCryptGenRandom(NULL, buffer, bytes_needed,
BCRYPT_USE_SYSTEM_PREFERRED_RNG) == STATUS_SUCCESS)
bytes = bytes_needed;
- rand_pool_add_end(pool, bytes, 8 * bytes);
- entropy_available = rand_pool_entropy_available(pool);
+ ossl_rand_pool_add_end(pool, bytes, 8 * bytes);
+ entropy_available = ossl_rand_pool_entropy_available(pool);
}
if (entropy_available > 0)
return entropy_available;
# else
- bytes_needed = rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
- buffer = rand_pool_add_begin(pool, bytes_needed);
+ bytes_needed = ossl_rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
+ buffer = ossl_rand_pool_add_begin(pool, bytes_needed);
if (buffer != NULL) {
size_t bytes = 0;
/* poll the CryptoAPI PRNG */
CryptReleaseContext(hProvider, 0);
}
- rand_pool_add_end(pool, bytes, 8 * bytes);
- entropy_available = rand_pool_entropy_available(pool);
+ ossl_rand_pool_add_end(pool, bytes, 8 * bytes);
+ entropy_available = ossl_rand_pool_entropy_available(pool);
}
if (entropy_available > 0)
return entropy_available;
- bytes_needed = rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
- buffer = rand_pool_add_begin(pool, bytes_needed);
+ bytes_needed = ossl_rand_pool_bytes_needed(pool, 1 /*entropy_factor*/);
+ buffer = ossl_rand_pool_add_begin(pool, bytes_needed);
if (buffer != NULL) {
size_t bytes = 0;
/* poll the Pentium PRG with CryptoAPI */
CryptReleaseContext(hProvider, 0);
}
- rand_pool_add_end(pool, bytes, 8 * bytes);
- entropy_available = rand_pool_entropy_available(pool);
+ ossl_rand_pool_add_end(pool, bytes, 8 * bytes);
+ entropy_available = ossl_rand_pool_entropy_available(pool);
}
if (entropy_available > 0)
return entropy_available;
# endif
- return rand_pool_entropy_available(pool);
+ return ossl_rand_pool_entropy_available(pool);
}
data.tid = GetCurrentThreadId();
GetSystemTimeAsFileTime(&data.time);
- return rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
+ return ossl_rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
}
-int rand_pool_add_additional_data(RAND_POOL *pool)
+int ossl_rand_pool_add_additional_data(RAND_POOL *pool)
{
struct {
DWORD tid;
*/
data.tid = GetCurrentThreadId();
QueryPerformanceCounter(&data.time);
- return rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
+ return ossl_rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0);
}
-int rand_pool_init(void)
+int ossl_rand_pool_init(void)
{
return 1;
}
-void rand_pool_cleanup(void)
+void ossl_rand_pool_cleanup(void)
{
}
-void rand_pool_keep_random_devices_open(int keep)
+void ossl_rand_pool_keep_random_devices_open(int keep)
{
}