summaryrefslogtreecommitdiffstats
path: root/test/destest.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2023-02-06 23:29:57 +0100
committerPauli <pauli@openssl.org>2023-02-08 11:54:24 +0100
commit587e0407803af330c0b04238fcbce78521ce35d7 (patch)
treebeb4a8ffb8f31e880c09bf6b149f29ef9ec6bdde /test/destest.c
parentFix more VMS inclusions (diff)
downloadopenssl-587e0407803af330c0b04238fcbce78521ce35d7.tar.xz
openssl-587e0407803af330c0b04238fcbce78521ce35d7.zip
des: prevent error when using two key triple DES with a random key
Two key 3DES only sets two keys and the random generation errors out if fewer than three keys are required. It shouldn't. Fixes #20212 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20224)
Diffstat (limited to '')
-rw-r--r--test/destest.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/destest.c b/test/destest.c
index e0c4b30f90..41977ff6e0 100644
--- a/test/destest.c
+++ b/test/destest.c
@@ -838,6 +838,29 @@ static int test_des_check_bad_parity(int n)
return TEST_int_eq(DES_check_key_parity(key), bad_parity_keys[n].expect);
}
+
+/* Test that two key 3DES can generate a random key without error */
+static int test_des_two_key(void)
+{
+ int res = 0;
+ EVP_CIPHER *cipher = NULL;
+ EVP_CIPHER_CTX *ctx = NULL;
+ unsigned char key[16];
+
+ if (!TEST_ptr(cipher = EVP_CIPHER_fetch(NULL, "DES-EDE-ECB", NULL))
+ || !TEST_ptr(ctx = EVP_CIPHER_CTX_new())
+ || !EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, 1)
+ || !EVP_CIPHER_CTX_set_key_length(ctx, sizeof(key))
+ || !EVP_CIPHER_CTX_rand_key(ctx, key))
+ goto err;
+
+ res = 1;
+ err:
+ EVP_CIPHER_free(cipher);
+ EVP_CIPHER_CTX_free(ctx);
+ return res;
+}
+
#endif
int setup_tests(void)
@@ -866,6 +889,7 @@ int setup_tests(void)
ADD_ALL_TESTS(test_des_key_wrap, OSSL_NELEM(test_des_key_wrap_sizes));
ADD_ALL_TESTS(test_des_weak_keys, OSSL_NELEM(weak_keys));
ADD_ALL_TESTS(test_des_check_bad_parity, OSSL_NELEM(bad_parity_keys));
+ ADD_TEST(test_des_two_key);
#endif
return 1;
}