RAND: Rename the RAND_poll_ex() callback and its typedef

With the introduction of RAND_poll_ex(), the `RAND_add()` calls were
replaced by meaningless cb(...). This commit changes the 'cb(...)'
calls back to 'rand_add(...)' calls by changing the signature as follows:

-int RAND_poll_ex(RAND_poll_fn cb, void *arg);
+int RAND_poll_ex(RAND_poll_cb rand_add, void *arg);

Changed the function typedef name to 'RAND_poll_cb' to emphasize the fact
that the function type represents a callback function.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4266)
This commit is contained in:
Dr. Matthias St. Pierre 2017-08-25 22:39:33 +02:00 committed by Rich Salz
parent aa048aef0b
commit 4871fa49cd
8 changed files with 28 additions and 28 deletions

View File

@ -153,8 +153,8 @@ extern RAND_DRBG priv_drbg;
extern int rand_fork_count;
/* Hardware-based seeding functions. */
void rand_read_tsc(RAND_poll_fn cb, void *arg);
int rand_read_cpu(RAND_poll_fn cb, void *arg);
void rand_read_tsc(RAND_poll_cb rand_add, void *arg);
int rand_read_cpu(RAND_poll_cb rand_add, void *arg);
/* DRBG entropy callbacks. */
void drbg_release_entropy(RAND_DRBG *drbg, unsigned char *out);

View File

@ -42,7 +42,7 @@ int rand_fork_count;
* it's not sufficient to indicate whether or not the seeding was
* done.
*/
void rand_read_tsc(RAND_poll_fn cb, void *arg)
void rand_read_tsc(RAND_poll_cb rand_add, void *arg)
{
unsigned char c;
int i;
@ -50,7 +50,7 @@ void rand_read_tsc(RAND_poll_fn cb, void *arg)
if ((OPENSSL_ia32cap_P[0] & (1 << 4)) != 0) {
for (i = 0; i < TSC_READ_COUNT; i++) {
c = (unsigned char)(OPENSSL_rdtsc() & 0xFF);
cb(arg, &c, 1, 0.5);
rand_add(arg, &c, 1, 0.5);
}
}
}
@ -62,14 +62,14 @@ size_t OPENSSL_ia32_rdrand_bytes(char *buf, size_t len);
extern unsigned int OPENSSL_ia32cap_P[];
int rand_read_cpu(RAND_poll_fn cb, void *arg)
int rand_read_cpu(RAND_poll_cb rand_add, void *arg)
{
char buff[RANDOMNESS_NEEDED];
/* If RDSEED is available, use that. */
if ((OPENSSL_ia32cap_P[2] & (1 << 18)) != 0) {
if (OPENSSL_ia32_rdseed_bytes(buff, sizeof(buff)) == sizeof(buff)) {
cb(arg, buff, (int)sizeof(buff), sizeof(buff));
rand_add(arg, buff, (int)sizeof(buff), sizeof(buff));
return 1;
}
}
@ -77,7 +77,7 @@ int rand_read_cpu(RAND_poll_fn cb, void *arg)
/* Second choice is RDRAND. */
if ((OPENSSL_ia32cap_P[1] & (1 << (62 - 32))) != 0) {
if (OPENSSL_ia32_rdrand_bytes(buff, sizeof(buff)) == sizeof(buff)) {
cb(arg, buff, (int)sizeof(buff), sizeof(buff));
rand_add(arg, buff, (int)sizeof(buff), sizeof(buff));
return 1;
}
}

View File

@ -50,7 +50,7 @@
* As a precaution, we generate four times the required amount of seed
* data.
*/
int RAND_poll_ex(RAND_poll_fn cb, void *arg)
int RAND_poll_ex(RAND_poll_cb rand_add, void *arg)
{
short int code;
gid_t curr_gid;
@ -72,11 +72,11 @@ int RAND_poll_ex(RAND_poll_fn cb, void *arg)
* different processes.
*/
curr_gid = getgid();
cb(arg, &curr_gid, sizeof curr_gid, 0);
rand_add(arg, &curr_gid, sizeof curr_gid, 0);
curr_pid = getpid();
cb(arg, &curr_pid, sizeof curr_pid, 0);
rand_add(arg, &curr_pid, sizeof curr_pid, 0);
curr_uid = getuid();
cb(arg, &curr_uid, sizeof curr_uid, 0);
rand_add(arg, &curr_uid, sizeof curr_uid, 0);
for (i = 0; i < (RANDOMNESS_NEEDED * 4); i++) {
/*
@ -99,7 +99,7 @@ int RAND_poll_ex(RAND_poll_fn cb, void *arg)
/* Get wall clock time, take 8 bits. */
clock_gettime(CLOCK_REALTIME, &ts);
v = (unsigned char)(ts.tv_nsec & 0xFF);
cb(arg, &v, sizeof v, 1);
rand_add(arg, &v, sizeof v, 1);
}
return 1;
}
@ -130,7 +130,7 @@ int RAND_poll_ex(RAND_poll_fn cb, void *arg)
/*
* Try the various seeding methods in turn, exit when succesful.
*/
int RAND_poll_ex(RAND_poll_fn cb, void *arg)
int RAND_poll_ex(RAND_poll_cb rand_add, void *arg)
{
# ifdef OPENSSL_RAND_SEED_NONE
return 0;
@ -144,7 +144,7 @@ int RAND_poll_ex(RAND_poll_fn cb, void *arg)
int i = getrandom(temp, TEMPSIZE, 0);
if (i >= 0) {
cb(arg, temp, i, i);
rand_add(arg, temp, i, i);
if (i == TEMPSIZE)
goto done;
}
@ -168,7 +168,7 @@ int RAND_poll_ex(RAND_poll_fn cb, void *arg)
continue;
setbuf(fp, NULL);
if (fread(temp, 1, TEMPSIZE, fp) == TEMPSIZE) {
cb(arg, temp, TEMPSIZE, TEMPSIZE);
rand_add(arg, temp, TEMPSIZE, TEMPSIZE);
fclose(fp);
goto done;
}
@ -193,7 +193,7 @@ int RAND_poll_ex(RAND_poll_fn cb, void *arg)
for (i = 0; paths[i] != NULL; i++) {
if (RAND_query_egd_bytes(paths[i], temp, TEMPSIZE) == TEMPSIZE) {
cb(arg, temp, TEMPSIZE, TEMPSIZE);
rand_add(arg, temp, TEMPSIZE, TEMPSIZE);
goto done;
}
}

View File

@ -54,7 +54,7 @@ static struct items_data_st {
{0, 0}
};
int RAND_poll_ex(RAND_poll_fn cb, void *arg)
int RAND_poll_ex(RAND_poll_cb rand_add, void *arg)
{
/* determine the number of items in the JPI array */
struct items_data_st item_entry;
@ -113,7 +113,7 @@ int RAND_poll_ex(RAND_poll_fn cb, void *arg)
total_length += (tmp_length - 1);
/* size of seed is total_length*4 bytes (64bytes) */
cb(arg, (PTR_T)data_buffer, total_length * 4, total_length * 2);
rand_add(arg, (PTR_T)data_buffer, total_length * 4, total_length * 2);
return 1;
}

View File

@ -39,7 +39,7 @@
# define INTEL_DEF_PROV L"Intel Hardware Cryptographic Service Provider"
# endif
int RAND_poll_ex(RAND_poll_fn cb, void *arg)
int RAND_poll_ex(RAND_poll_cb rand_add, void *arg)
{
# ifndef USE_BCRYPTGENRANDOM
HCRYPTPROV hProvider;
@ -58,7 +58,7 @@ int RAND_poll_ex(RAND_poll_fn cb, void *arg)
# ifdef USE_BCRYPTGENRANDOM
if (BCryptGenRandom(NULL, buf, (ULONG)sizeof(buf),
BCRYPT_USE_SYSTEM_PREFERRED_RNG) == STATUS_SUCCESS) {
cb(arg, buf, sizeof(buf), sizeof(buf));
rand_add(arg, buf, sizeof(buf), sizeof(buf));
return 1;
}
# else
@ -66,7 +66,7 @@ int RAND_poll_ex(RAND_poll_fn cb, void *arg)
if (CryptAcquireContextW(&hProvider, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT) != 0) {
if (CryptGenRandom(hProvider, (DWORD)sizeof(buf), buf) != 0) {
cb(arg, buf, sizeof(buf), sizeof(buf));
rand_add(arg, buf, sizeof(buf), sizeof(buf));
ok = 1;
}
CryptReleaseContext(hProvider, 0);
@ -78,7 +78,7 @@ int RAND_poll_ex(RAND_poll_fn cb, void *arg)
if (CryptAcquireContextW(&hProvider, NULL, INTEL_DEF_PROV, PROV_INTEL_SEC,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT) != 0) {
if (CryptGenRandom(hProvider, (DWORD)sizeof(buf), buf) != 0) {
cb(arg, buf, sizeof(buf), sizeof(buf));
rand_add(arg, buf, sizeof(buf), sizeof(buf));
ok = 1;
}
CryptReleaseContext(hProvider, 0);

View File

@ -2,7 +2,7 @@
=head1 NAME
RAND_add, RAND_poll, RAND_poll_ex, RAND_poll_fn,
RAND_add, RAND_poll, RAND_poll_ex, RAND_poll_cb,
RAND_seed, RAND_status, RAND_event, RAND_screen
- add randomness to the PRNG or get its status
@ -12,9 +12,9 @@ RAND_seed, RAND_status, RAND_event, RAND_screen
int RAND_status(void);
typedef void (*RAND_poll_fn)(void *arg,
typedef void (*RAND_poll_cb)(void *arg,
const void *buf, int num, double randomness);
int RAND_poll_ex(RAND_poll_fn cb, void *arg);
int RAND_poll_ex(RAND_poll_cb cb, void *arg);
int RAND_poll();
void RAND_add(const void *buf, int num, double randomness);

View File

@ -61,10 +61,10 @@ int RAND_egd(const char *path);
int RAND_egd_bytes(const char *path, int bytes);
# endif
typedef void (*RAND_poll_fn)(void *arg,
typedef void (*RAND_poll_cb)(void *arg,
const void *buf, int num, double randomness);
int RAND_poll(void);
int RAND_poll_ex(RAND_poll_fn cb, void *arg);
int RAND_poll_ex(RAND_poll_cb rand_add, void *arg);
# if defined(_WIN32) && (defined(BASETYPES) || defined(_WINDEF_H))
/* application has to include <windows.h> in order to use these */

View File

@ -33,7 +33,7 @@ OSSL_STORE_error_fn datatype
OSSL_STORE_load_fn datatype
OSSL_STORE_open_fn datatype
OSSL_STORE_post_process_info_fn datatype
RAND_poll_fn datatype
RAND_poll_cb datatype
SSL_CTX_keylog_cb_func datatype
SSL_early_cb_fn datatype
SSL_psk_client_cb_func datatype