From: Joshua Rogers Date: Sat, 4 Apr 2026 09:55:34 +0000 (+0800) Subject: evp_skey_test.c: Add test for EVP_SKEY_to_provider same-provider path X-Git-Tag: openssl-4.0.0~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=971a83d43e44b3b1738c203f55fd4cf49c77deb0;p=thirdparty%2Fopenssl.git evp_skey_test.c: Add test for EVP_SKEY_to_provider same-provider path Reviewed-by: Dmitry Belyavskiy Reviewed-by: Frederik Wedel-Heinen MergeDate: Wed Apr 8 10:27:03 2026 (Merged from https://github.com/openssl/openssl/pull/30650) (cherry picked from commit eaef6b20c7e7857df80af81b854e7c23823879fd) --- diff --git a/test/evp_skey_test.c b/test/evp_skey_test.c index 2e24123a494..f0e794ec7f6 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);