summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2023-10-16 14:42:12 +0900
committerTomas Mraz <tomas@openssl.org>2023-10-18 16:26:17 +0200
commit86f3fae5f8fb4d9cb96ea9b34250cd3abc3038ef (patch)
tree1ecf1aef3617479c4e34eff967546e7c33901efb /test
parenta9c69e0e70d7fcf1bd7b55754894d5ebf7ae5aad (diff)
rsa: Accept NULL OAEP label for backward compatibility
According to the manual page, EVP_PKEY_CTX_set0_rsa_oaep_label() should accept NULL as the label argument, though the function currently rejects it while setting the corresponding octet string parameter with OSSL_PARAM_construct_octet_string, which expects non-NULL input. This adds a workaround to the caller for backward compatibility. Signed-off-by: Daiki Ueno <dueno@redhat.com> Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22397) (cherry picked from commit 21b98da9d80c561b6273b0c51c259196d6740e70)
Diffstat (limited to 'test')
-rw-r--r--test/evp_extra_test.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c
index 2899c69b19..cfffa21350 100644
--- a/test/evp_extra_test.c
+++ b/test/evp_extra_test.c
@@ -2912,6 +2912,36 @@ static int test_RSA_OAEP_set_get_params(void)
return ret;
}
+/* https://github.com/openssl/openssl/issues/21288 */
+static int test_RSA_OAEP_set_null_label(void)
+{
+ int ret = 0;
+ EVP_PKEY *key = NULL;
+ EVP_PKEY_CTX *key_ctx = NULL;
+
+ if (!TEST_ptr(key = load_example_rsa_key())
+ || !TEST_ptr(key_ctx = EVP_PKEY_CTX_new_from_pkey(testctx, key, NULL))
+ || !TEST_true(EVP_PKEY_encrypt_init(key_ctx)))
+ goto err;
+
+ if (!TEST_true(EVP_PKEY_CTX_set_rsa_padding(key_ctx, RSA_PKCS1_OAEP_PADDING)))
+ goto err;
+
+ if (!TEST_true(EVP_PKEY_CTX_set0_rsa_oaep_label(key_ctx, OPENSSL_strdup("foo"), 0)))
+ goto err;
+
+ if (!TEST_true(EVP_PKEY_CTX_set0_rsa_oaep_label(key_ctx, NULL, 0)))
+ goto err;
+
+ ret = 1;
+
+ err:
+ EVP_PKEY_free(key);
+ EVP_PKEY_CTX_free(key_ctx);
+
+ return ret;
+}
+
#if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
static int test_decrypt_null_chunks(void)
{
@@ -4899,6 +4929,7 @@ int setup_tests(void)
#endif
ADD_TEST(test_RSA_get_set_params);
ADD_TEST(test_RSA_OAEP_set_get_params);
+ ADD_TEST(test_RSA_OAEP_set_null_label);
#if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
ADD_TEST(test_decrypt_null_chunks);
#endif