diff --git a/test/evp_libctx_test.c b/test/evp_libctx_test.c index 2448c35a149f6..adc9848a61351 100644 --- a/test/evp_libctx_test.c +++ b/test/evp_libctx_test.c @@ -317,6 +317,7 @@ static int test_cipher_reinit(int test_id) int out1_len = 0, out2_len = 0, out3_len = 0; EVP_CIPHER *cipher = NULL; EVP_CIPHER_CTX *ctx = NULL; + OSSL_LIB_CTX *prev_libctx = NULL; unsigned char out1[256]; unsigned char out2[256]; unsigned char out3[256]; @@ -334,7 +335,11 @@ static int test_cipher_reinit(int test_id) 0x03, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, }; - unsigned char iv[16] = { + unsigned char iv[48] = { + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 }; @@ -364,6 +369,11 @@ static int test_cipher_reinit(int test_id) /* DES3-WRAP uses random every update - so it will give a different value */ diff = EVP_CIPHER_is_a(cipher, "DES3-WRAP"); + /* eNULL-HMAC- use implicit fetching of digest algo */ + if (EVP_CIPHER_is_a(cipher, "eNULL-HMAC-SHA256") + || EVP_CIPHER_is_a(cipher, "eNULL-HMAC-SHA384")) + prev_libctx = OSSL_LIB_CTX_set0_default(libctx); + if (!TEST_true(EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv)) || !TEST_true(EVP_EncryptUpdate(ctx, out1, &out1_len, in, sizeof(in))) || !TEST_true(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv)) @@ -389,6 +399,9 @@ static int test_cipher_reinit(int test_id) } ret = 1; err: + /* restore the old libctx */ + if (prev_libctx != NULL) + OSSL_LIB_CTX_set0_default(prev_libctx); EVP_CIPHER_free(cipher); EVP_CIPHER_CTX_free(ctx); return ret; @@ -406,6 +419,7 @@ static int test_cipher_reinit_partialupdate(int test_id) int out1_len = 0, out2_len = 0, out3_len = 0; EVP_CIPHER *cipher = NULL; EVP_CIPHER_CTX *ctx = NULL; + OSSL_LIB_CTX *prev_libctx = NULL; unsigned char out1[256]; unsigned char out2[256]; unsigned char out3[256]; @@ -425,7 +439,11 @@ static int test_cipher_reinit_partialupdate(int test_id) 0x03, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, }; - static const unsigned char iv[16] = { + static const unsigned char iv[48] = { + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 }; @@ -438,6 +456,11 @@ static int test_cipher_reinit_partialupdate(int test_id) if (!TEST_ptr(cipher = EVP_CIPHER_fetch(libctx, name, NULL))) goto err; + /* eNULL-HMAC- use implicit fetching of digest algo */ + if (EVP_CIPHER_is_a(cipher, "eNULL-HMAC-SHA256") + || EVP_CIPHER_is_a(cipher, "eNULL-HMAC-SHA384")) + prev_libctx = OSSL_LIB_CTX_set0_default(libctx); + in_len = EVP_CIPHER_get_block_size(cipher) / 2; /* skip any ciphers that don't allow partial updates */ @@ -469,6 +492,9 @@ static int test_cipher_reinit_partialupdate(int test_id) } ret = 1; err: + /* restore the old libctx */ + if (prev_libctx != NULL) + OSSL_LIB_CTX_set0_default(prev_libctx); EVP_CIPHER_free(cipher); EVP_CIPHER_CTX_free(ctx); return ret;