Commit e249566980 for openssl.org

commit e249566980232cfe7f2d9b9b48e5102b3005eddb
Author: Joshua Rogers <MegaManSec@users.noreply.github.com>
Date:   Sat Apr 4 18:28:46 2026 +0800

    evp_skey_test.c: Add test for EVP_SKEY_to_provider cross-provider transfer

    Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
    Reviewed-by: Frederik Wedel-Heinen <fwh.openssl@gmail.com>
    MergeDate: Wed Apr  8 10:27:04 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 8f3d2e4707..3a1f4fcd5f 100644
--- a/test/evp_skey_test.c
+++ b/test/evp_skey_test.c
@@ -391,6 +391,64 @@ end:
     return ret;
 }

+static int test_skey_to_diff_provider(void)
+{
+    OSSL_PROVIDER *fake_prov = NULL;
+    EVP_SKEY *key = NULL, *key2 = NULL;
+    const unsigned char *export_key = NULL;
+    size_t export_len;
+    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;
+
+    deflprov = OSSL_PROVIDER_load(libctx, "default");
+    if (!TEST_ptr(deflprov))
+        return 0;
+
+    if (!TEST_ptr(fake_prov = fake_cipher_start(libctx)))
+        goto end;
+
+    if (!TEST_ptr(key = EVP_SKEY_import_raw_key(libctx, OSSL_SKEY_TYPE_GENERIC,
+                      import_key, sizeof(import_key), NULL)))
+        goto end;
+
+    if (!TEST_ptr(key2 = EVP_SKEY_to_provider(key, libctx, fake_prov,
+                      FAKE_CIPHER_FETCH_PROPS)))
+        goto end;
+
+    /* Different provider must return a different object */
+    if (!TEST_ptr_ne(key2, key))
+        goto end;
+
+    if (!TEST_int_gt(EVP_SKEY_get0_raw_key(key2, &export_key, &export_len), 0)
+        || !TEST_mem_eq(import_key, sizeof(import_key), export_key, export_len))
+        goto end;
+
+    ret = 1;
+end:
+    EVP_SKEY_free(key2);
+    EVP_SKEY_free(key);
+    fake_cipher_finish(fake_prov);
+    OSSL_PROVIDER_unload(deflprov);
+    return ret;
+}
+
 int setup_tests(void)
 {
     libctx = OSSL_LIB_CTX_new();
@@ -401,6 +459,7 @@ int setup_tests(void)
     ADD_TEST(test_skey_skeymgmt);

     ADD_TEST(test_skey_to_same_provider);
+    ADD_TEST(test_skey_to_diff_provider);
     ADD_TEST(test_aes_raw_skey);
 #ifndef OPENSSL_NO_DES
     ADD_TEST(test_des_raw_skey);
diff --git a/test/fake_cipherprov.c b/test/fake_cipherprov.c
index 2306f29e4e..16fde61221 100644
--- a/test/fake_cipherprov.c
+++ b/test/fake_cipherprov.c
@@ -110,6 +110,7 @@ static const OSSL_DISPATCH fake_skeymgmt_funcs[] = {

 static const OSSL_ALGORITHM fake_skeymgmt_algs[] = {
     { "fake_cipher", FAKE_CIPHER_FETCH_PROPS, fake_skeymgmt_funcs, "Fake Cipher Key Management" },
+    { OSSL_SKEY_TYPE_GENERIC, FAKE_CIPHER_FETCH_PROPS, fake_skeymgmt_funcs, "Fake Generic Key Management" },
     { NULL, NULL, NULL, NULL }
 };
 static OSSL_FUNC_cipher_newctx_fn fake_newctx;