summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorIngo Franzki <ifranzki@linux.ibm.com>2023-02-08 17:26:20 +0100
committerMatt Caswell <matt@openssl.org>2023-02-24 09:53:07 +0000
commit5e3b84505e44377b183e7529dab7585674b83936 (patch)
treecad04fa7b51ef890a101b905b56789ff1ffa3b59 /test
parent65def9de8088ae39d8f251e0b57f1a0f204daa14 (diff)
Add OSSL_FUNC_keymgmt_im/export_types function that gets the provider context
The provider functions OSSL_FUNC_keymgmt_import_types() and OSSL_FUNC_keymgmt_export_types() do not get the provider context passed. This makes it difficult for providers to implement these functions unless its a static implementation returning a truly constant OSSL_PARAM array. Some providers may have a need to return an OSSL_PARAM array that is dependent on the provider configuration, or anything else that is contained in its provider context. Add extended variants of these functions that get the provider context passed. The functions should still return a static and constant OSSL_PARAM array, but may use the provider context to select the array to return dependent on its context. The returned array must be constant at least until the provider is unloaded. Providers can implement only the original functions, or only the extended functions, or both. Implementing at least one of those functions is required if also the respective OSSL_FUNC_keymgmt_import() or OSSL_FUNC_keymgmt_export() function is implemented. If an extended function is available, it is called by evp_keymgmt_import_types() or evp_keymgmt_export_types(), otherwise the original function is called. This makes the code backward compatible. Existing providers will only implement the original functions, so these functions will continued to be called. Newer providers can choose to implement the extended functions, and thus can benefit from the provider context being passed to the implementation. Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20255)
Diffstat (limited to 'test')
-rw-r--r--test/tls-provider.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/tls-provider.c b/test/tls-provider.c
index c2cf583d35..8146b99bb9 100644
--- a/test/tls-provider.c
+++ b/test/tls-provider.c
@@ -47,8 +47,10 @@
static OSSL_FUNC_keymgmt_import_fn xor_import;
static OSSL_FUNC_keymgmt_import_types_fn xor_import_types;
+static OSSL_FUNC_keymgmt_import_types_ex_fn xor_import_types_ex;
static OSSL_FUNC_keymgmt_export_fn xor_export;
static OSSL_FUNC_keymgmt_export_types_fn xor_export_types;
+static OSSL_FUNC_keymgmt_export_types_ex_fn xor_export_types_ex;
int tls_provider_init(const OSSL_CORE_HANDLE *handle,
const OSSL_DISPATCH *in,
@@ -1061,11 +1063,27 @@ static const OSSL_PARAM *xor_import_types(int select)
return (select & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0 ? xor_key_types : NULL;
}
+static const OSSL_PARAM *xor_import_types_ex(void *provctx, int select)
+{
+ if (provctx == NULL)
+ return NULL;
+
+ return xor_import_types(select);
+}
+
static const OSSL_PARAM *xor_export_types(int select)
{
return (select & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0 ? xor_key_types : NULL;
}
+static const OSSL_PARAM *xor_export_types_ex(void *provctx, int select)
+{
+ if (provctx == NULL)
+ return NULL;
+
+ return xor_export_types(select);
+}
+
static void xor_gen_cleanup(void *genctx)
{
OPENSSL_free(genctx);
@@ -1088,8 +1106,10 @@ static const OSSL_DISPATCH xor_keymgmt_functions[] = {
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))xor_freekey },
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))xor_import },
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))xor_import_types },
+ { OSSL_FUNC_KEYMGMT_IMPORT_TYPES_EX, (void (*)(void))xor_import_types_ex },
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))xor_export },
{ OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))xor_export_types },
+ { OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX, (void (*)(void))xor_export_types_ex },
{ 0, NULL }
};