Commit eaef6b20c7 for openssl.org
commit eaef6b20c7e7857df80af81b854e7c23823879fd
Author: Joshua Rogers <MegaManSec@users.noreply.github.com>
Date: Sat Apr 4 17:55:34 2026 +0800
evp_skey_test.c: Add test for EVP_SKEY_to_provider same-provider path
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Frederik Wedel-Heinen <fwh.openssl@gmail.com>
MergeDate: Wed Apr 8 10:27:03 2026
(Merged from https://github.com/openssl/openssl/pull/30650)
diff --git a/test/evp_skey_test.c b/test/evp_skey_test.c
index c98abb8462..8f3d2e4707 100644
--- a/test/evp_skey_test.c
+++ b/test/evp_skey_test.c
@@ -336,6 +336,61 @@ end:
}
#endif
+static int test_skey_to_same_provider(void)
+{
+ OSSL_PROVIDER *fake_prov = NULL;
+ EVP_SKEY *key = NULL, *key2 = NULL;
+ OSSL_PARAM params[3];
+ unsigned char import_key[KEY_SIZE] = {
+ 0x53,
+ 0x4B,
+ 0x45,
+ 0x59,
+ 0x53,
+ 0x4B,
+ 0x45,
+ 0x59,
+ 0x53,
+ 0x4B,
+ 0x45,
+ 0x59,
+ 0x53,
+ 0x4B,
+ 0x45,
+ 0x59,
+ };
+ int ret = 0;
+
+ if (!TEST_ptr(fake_prov = fake_cipher_start(libctx)))
+ goto end;
+
+ params[0] = OSSL_PARAM_construct_utf8_string(FAKE_CIPHER_PARAM_KEY_NAME,
+ "fake key name", 0);
+ params[1] = OSSL_PARAM_construct_octet_string(OSSL_SKEY_PARAM_RAW_BYTES,
+ import_key, sizeof(import_key));
+ params[2] = OSSL_PARAM_construct_end();
+
+ if (!TEST_ptr(key = EVP_SKEY_import(libctx, "fake_cipher",
+ FAKE_CIPHER_FETCH_PROPS,
+ OSSL_SKEYMGMT_SELECT_ALL, params)))
+ goto end;
+
+ if (!TEST_ptr(key2 = EVP_SKEY_to_provider(key, libctx, fake_prov,
+ FAKE_CIPHER_FETCH_PROPS)))
+ goto end;
+
+ /* Same provider should return same object with bumped refcount */
+ if (!TEST_ptr_eq(key2, key))
+ goto end;
+
+ ret = 1;
+end:
+ EVP_SKEY_free(key2);
+ EVP_SKEY_free(key);
+ fake_cipher_finish(fake_prov);
+ return ret;
+}
+
int setup_tests(void)
{
libctx = OSSL_LIB_CTX_new();
@@ -345,6 +400,7 @@ int setup_tests(void)
ADD_TEST(test_skey_cipher);
ADD_TEST(test_skey_skeymgmt);
+ ADD_TEST(test_skey_to_same_provider);
ADD_TEST(test_aes_raw_skey);
#ifndef OPENSSL_NO_DES
ADD_TEST(test_des_raw_skey);