From f15e3f3aa95df743f0da793da952f87370efb4ff Mon Sep 17 00:00:00 2001 From: Peiwei Hu Date: Tue, 24 May 2022 22:59:41 +0800 Subject: Fix the incorrect checks of EVP_CIPHER_CTX_rand_key Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/18397) --- apps/speed.c | 2 +- test/evp_libctx_test.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/speed.c b/apps/speed.c index 936107c5ef..c56f8e69f6 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -3602,7 +3602,7 @@ static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single, goto err; } key = app_malloc(keylen, "evp_cipher key"); - if (!EVP_CIPHER_CTX_rand_key(ctx, key)) + if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0) app_bail_out("failed to generate random cipher key\n"); if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL)) app_bail_out("failed to set cipher key\n"); diff --git a/test/evp_libctx_test.c b/test/evp_libctx_test.c index 65f5f694bf..2448c35a14 100644 --- a/test/evp_libctx_test.c +++ b/test/evp_libctx_test.c @@ -576,7 +576,7 @@ static int test_cipher_tdes_randkey(void) && TEST_int_ne(EVP_CIPHER_get_flags(tdes_cipher) & EVP_CIPH_RAND_KEY, 0) && TEST_ptr(ctx = EVP_CIPHER_CTX_new()) && TEST_true(EVP_CipherInit_ex(ctx, tdes_cipher, NULL, NULL, NULL, 1)) - && TEST_true(EVP_CIPHER_CTX_rand_key(ctx, key)); + && TEST_int_gt(EVP_CIPHER_CTX_rand_key(ctx, key), 0); EVP_CIPHER_CTX_free(ctx); EVP_CIPHER_free(tdes_cipher); -- cgit v1.2.3