]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
evp_skey_test.c: Add test for EVP_SKEY_to_provider same-provider path
authorJoshua Rogers <MegaManSec@users.noreply.github.com>
Sat, 4 Apr 2026 09:55:34 +0000 (17:55 +0800)
committerTomas Mraz <tomas@openssl.foundation>
Wed, 8 Apr 2026 10:27:43 +0000 (12:27 +0200)
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)

(cherry picked from commit eaef6b20c7e7857df80af81b854e7c23823879fd)

test/evp_skey_test.c

index 2e24123a494b8f09e0cd4e80c1c6fd7c4334366a..f0e794ec7f615c76a36403a749d6b6971042a79d 100644 (file)
@@ -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);