mirror of
https://github.com/openssl/openssl.git
synced 2025-01-18 13:44:20 +08:00
Fix the checks of RAND_bytes
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Todd Short <todd.short@me.com> (Merged from https://github.com/openssl/openssl/pull/18424)
This commit is contained in:
parent
163bf682fd
commit
c2f7614fb7
@ -331,7 +331,7 @@ static int send_record(BIO *rbio, unsigned char type, uint64_t seqnr,
|
||||
} while (len % 16);
|
||||
|
||||
/* Generate IV, and encrypt */
|
||||
if (!TEST_true(RAND_bytes(iv, sizeof(iv)))
|
||||
if (!TEST_int_gt(RAND_bytes(iv, sizeof(iv)), 0)
|
||||
|| !TEST_ptr(enc_ctx = EVP_CIPHER_CTX_new())
|
||||
|| !TEST_true(EVP_CipherInit_ex(enc_ctx, EVP_aes_128_cbc(), NULL,
|
||||
enc_key, iv, 1))
|
||||
|
@ -531,7 +531,7 @@ static int test_rand_fork_safety(int i)
|
||||
success = 0;
|
||||
|
||||
/* request a single byte from each of the DRBGs before the next run */
|
||||
if (!TEST_true(RAND_bytes(random, 1) && RAND_priv_bytes(random, 1)))
|
||||
if (!TEST_int_gt(RAND_bytes(random, 1), 0) || !TEST_int_gt(RAND_priv_bytes(random, 1), 0))
|
||||
success = 0;
|
||||
|
||||
return success;
|
||||
|
@ -223,7 +223,7 @@ static int test_builtin(int n, int as)
|
||||
|
||||
if (!TEST_ptr(mctx = EVP_MD_CTX_new())
|
||||
/* get some random message data */
|
||||
|| !TEST_true(RAND_bytes(tbs, sizeof(tbs)))
|
||||
|| !TEST_int_gt(RAND_bytes(tbs, sizeof(tbs)), 0)
|
||||
/* real key */
|
||||
|| !TEST_ptr(eckey = EC_KEY_new_by_curve_name(nid))
|
||||
|| !TEST_true(EC_KEY_generate_key(eckey))
|
||||
|
@ -144,21 +144,21 @@ static int test_mod_exp(int round)
|
||||
|| !TEST_ptr(m = BN_new()))
|
||||
goto err;
|
||||
|
||||
if (!TEST_true(RAND_bytes(&c, 1)))
|
||||
if (!TEST_int_gt(RAND_bytes(&c, 1), 0))
|
||||
goto err;
|
||||
c = (c % BN_BITS) - BN_BITS2;
|
||||
if (!TEST_true(BN_rand(a, NUM_BITS + c, BN_RAND_TOP_ONE,
|
||||
BN_RAND_BOTTOM_ANY)))
|
||||
goto err;
|
||||
|
||||
if (!TEST_true(RAND_bytes(&c, 1)))
|
||||
if (!TEST_int_gt(RAND_bytes(&c, 1), 0))
|
||||
goto err;
|
||||
c = (c % BN_BITS) - BN_BITS2;
|
||||
if (!TEST_true(BN_rand(b, NUM_BITS + c, BN_RAND_TOP_ONE,
|
||||
BN_RAND_BOTTOM_ANY)))
|
||||
goto err;
|
||||
|
||||
if (!TEST_true(RAND_bytes(&c, 1)))
|
||||
if (!TEST_int_gt(RAND_bytes(&c, 1), 0))
|
||||
goto err;
|
||||
c = (c % BN_BITS) - BN_BITS2;
|
||||
if (!TEST_true(BN_rand(m, NUM_BITS + c, BN_RAND_TOP_ONE,
|
||||
|
@ -410,7 +410,7 @@ static int test_WPACKET_init_der(void)
|
||||
return cleanup(&pkt);
|
||||
|
||||
/* Generate random packet data for test */
|
||||
if (!TEST_true(RAND_bytes(&testdata2[3], sizeof(testdata2) - 3)))
|
||||
if (!TEST_int_gt(RAND_bytes(&testdata2[3], sizeof(testdata2) - 3), 0))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
@ -581,7 +581,7 @@ static int test_WPACKET_quic_vlint_random(void)
|
||||
PACKET read_pkt = {0};
|
||||
|
||||
for (i = 0; i < 10000; ++i) {
|
||||
if (!TEST_true(RAND_bytes(rand_data, sizeof(rand_data))))
|
||||
if (!TEST_int_gt(RAND_bytes(rand_data, sizeof(rand_data)), 0))
|
||||
return cleanup(&pkt);
|
||||
|
||||
expected = *(uint64_t*)rand_data;
|
||||
|
Loading…
Reference in New Issue
Block a user