aboutsummaryrefslogtreecommitdiffstats
path: root/test/evp_libctx_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/evp_libctx_test.c')
-rw-r--r--test/evp_libctx_test.c49
1 files changed, 44 insertions, 5 deletions
diff --git a/test/evp_libctx_test.c b/test/evp_libctx_test.c
index 2448c35a14..224e16b398 100644
--- a/test/evp_libctx_test.c
+++ b/test/evp_libctx_test.c
@@ -71,6 +71,37 @@ static const char *getname(int id)
}
#endif
+static int test_evp_cipher_api_safety(void)
+{
+ int ret = 0;
+ EVP_CIPHER_CTX *ctx = NULL;
+
+ ctx = EVP_CIPHER_CTX_new();
+
+ if (!TEST_ptr(ctx))
+ goto err;
+
+ /*
+ * Ensure that EVP_CIPHER_get_block_size returns 0
+ * if we haven't initalized the cipher in this context
+ */
+ if (!TEST_int_eq(EVP_CIPHER_CTX_get_block_size(ctx), 0))
+ goto err_free;
+
+ /*
+ * Ensure that EVP_CIPHER_get_iv_length returns 0
+ * if we haven't initalized the cipher in this context
+ */
+ if (!TEST_int_eq(EVP_CIPHER_CTX_get_iv_length(ctx), 0))
+ goto err_free;
+
+ ret = 1;
+err_free:
+ EVP_CIPHER_CTX_free(ctx);
+err:
+ return ret;
+}
+
/*
* We're using some DH specific values in this test, so we skip compilation if
* we're in a no-dh build.
@@ -438,7 +469,11 @@ static int test_cipher_reinit_partialupdate(int test_id)
if (!TEST_ptr(cipher = EVP_CIPHER_fetch(libctx, name, NULL)))
goto err;
- in_len = EVP_CIPHER_get_block_size(cipher) / 2;
+ in_len = EVP_CIPHER_get_block_size(cipher);
+ if (!TEST_int_gt(in_len, 0))
+ goto err;
+ if (in_len > 1)
+ in_len /= 2;
/* skip any ciphers that don't allow partial updates */
if (((EVP_CIPHER_get_flags(cipher)
@@ -456,16 +491,18 @@ static int test_cipher_reinit_partialupdate(int test_id)
|| !TEST_true(EVP_EncryptUpdate(ctx, out2, &out2_len, in, in_len)))
goto err;
- if (!TEST_mem_eq(out1, out1_len, out2, out2_len))
- goto err;
+ if (EVP_CIPHER_get_iv_length(cipher) != 0)
+ if (!TEST_mem_eq(out1, out1_len, out2, out2_len))
+ goto err;
if (EVP_CIPHER_get_mode(cipher) != EVP_CIPH_SIV_MODE) {
if (!TEST_true(EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv))
|| !TEST_true(EVP_EncryptUpdate(ctx, out3, &out3_len, in, in_len)))
goto err;
- if (!TEST_mem_eq(out1, out1_len, out3, out3_len))
- goto err;
+ if (EVP_CIPHER_get_iv_length(cipher) != 0)
+ if (!TEST_mem_eq(out1, out1_len, out3, out3_len))
+ goto err;
}
ret = 1;
err:
@@ -725,6 +762,8 @@ int setup_tests(void)
if (!test_get_libctx(&libctx, &nullprov, config_file, &libprov, prov_name))
return 0;
+ ADD_TEST(test_evp_cipher_api_safety);
+
#if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DH)
ADD_ALL_TESTS(test_dsa_param_keygen, 3 * 3 * 3);
#endif