Commit 05200ee5 authored by Matt Caswell's avatar Matt Caswell
Browse files

Change usage of RAND_pseudo_bytes to RAND_bytes



RAND_pseudo_bytes() allows random data to be returned even in low entropy
conditions. Sometimes this is ok. Many times it is not. For the avoidance
of any doubt, replace existing usage of RAND_pseudo_bytes() with
RAND_bytes().

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
parent 3681a455
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -509,7 +509,7 @@ int MAIN(int argc, char **argv)
                            BIO_printf(bio_err, "invalid hex salt value\n");
                            goto end;
                        }
                    } else if (RAND_pseudo_bytes(salt, sizeof salt) < 0)
                    } else if (RAND_bytes(salt, sizeof salt) <= 0)
                        goto end;
                    /*
                     * If -P option then don't bother writing
+2 −2
Original line number Diff line number Diff line
@@ -416,7 +416,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
                if (*salt_malloc_p == NULL)
                    goto err;
            }
            if (RAND_pseudo_bytes((unsigned char *)*salt_p, 2) < 0)
            if (RAND_bytes((unsigned char *)*salt_p, 2) <= 0)
                goto err;
            (*salt_p)[0] = cov_2char[(*salt_p)[0] & 0x3f]; /* 6 bits */
            (*salt_p)[1] = cov_2char[(*salt_p)[1] & 0x3f]; /* 6 bits */
@@ -437,7 +437,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
                if (*salt_malloc_p == NULL)
                    goto err;
            }
            if (RAND_pseudo_bytes((unsigned char *)*salt_p, 8) < 0)
            if (RAND_bytes((unsigned char *)*salt_p, 8) <= 0)
                goto err;

            for (i = 0; i < 8; i++)
+1 −1
Original line number Diff line number Diff line
@@ -2968,7 +2968,7 @@ static int generate_session_id(const SSL *ssl, unsigned char *id,
{
    unsigned int count = 0;
    do {
        if (RAND_pseudo_bytes(id, *id_len) < 0)
        if (RAND_bytes(id, *id_len) <= 0)
            return 0;
        /*
         * Prefix the session_id with the required prefix. NB: If our prefix
+1 −1
Original line number Diff line number Diff line
@@ -289,7 +289,7 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
    if ((flags & SMIME_DETACHED) && data) {
        /* We want multipart/signed */
        /* Generate a random boundary */
        if (RAND_pseudo_bytes((unsigned char *)bound, 32) < 0)
        if (RAND_bytes((unsigned char *)bound, 32) <= 0)
            return 0;
        for (i = 0; i < 32; i++) {
            c = bound[i] & 0xf;
+1 −1
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
    sstr = ASN1_STRING_data(pbe->salt);
    if (salt)
        memcpy(sstr, salt, saltlen);
    else if (RAND_pseudo_bytes(sstr, saltlen) < 0)
    else if (RAND_bytes(sstr, saltlen) <= 0)
        goto err;

    if (!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) {
Loading