Commit 4871fa49 authored by Dr. Matthias St. Pierre's avatar Dr. Matthias St. Pierre Committed by Rich Salz
Browse files

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: default avatarPaul Dale <paul.dale@oracle.com>
Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4266)
parent aa048aef
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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);
+5 −5
Original line number Diff line number Diff line
@@ -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;
        }
    }
+9 −9
Original line number Diff line number Diff line
@@ -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;
            }
        }
+2 −2
Original line number Diff line number Diff line
@@ -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;
}

+4 −4
Original line number Diff line number Diff line
@@ -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);
Loading