2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/core.h>
12 #include "endecoder_local.h"
14 OSSL_FUNC_keymgmt_new_fn *
15 ossl_prov_get_keymgmt_new(const OSSL_DISPATCH *fns)
17 /* Pilfer the keymgmt dispatch table */
18 for (; fns->function_id != 0; fns++)
19 if (fns->function_id == OSSL_FUNC_KEYMGMT_NEW)
20 return OSSL_FUNC_keymgmt_new(fns);
25 OSSL_FUNC_keymgmt_free_fn *
26 ossl_prov_get_keymgmt_free(const OSSL_DISPATCH *fns)
28 /* Pilfer the keymgmt dispatch table */
29 for (; fns->function_id != 0; fns++)
30 if (fns->function_id == OSSL_FUNC_KEYMGMT_FREE)
31 return OSSL_FUNC_keymgmt_free(fns);
36 OSSL_FUNC_keymgmt_import_fn *
37 ossl_prov_get_keymgmt_import(const OSSL_DISPATCH *fns)
39 /* Pilfer the keymgmt dispatch table */
40 for (; fns->function_id != 0; fns++)
41 if (fns->function_id == OSSL_FUNC_KEYMGMT_IMPORT)
42 return OSSL_FUNC_keymgmt_import(fns);
47 OSSL_FUNC_keymgmt_export_fn *
48 ossl_prov_get_keymgmt_export(const OSSL_DISPATCH *fns)
50 /* Pilfer the keymgmt dispatch table */
51 for (; fns->function_id != 0; fns++)
52 if (fns->function_id == OSSL_FUNC_KEYMGMT_EXPORT)
53 return OSSL_FUNC_keymgmt_export(fns);
58 void *ossl_prov_import_key(const OSSL_DISPATCH *fns, void *provctx,
59 int selection, const OSSL_PARAM params[])
61 OSSL_FUNC_keymgmt_new_fn *kmgmt_new = ossl_prov_get_keymgmt_new(fns);
62 OSSL_FUNC_keymgmt_free_fn *kmgmt_free = ossl_prov_get_keymgmt_free(fns);
63 OSSL_FUNC_keymgmt_import_fn *kmgmt_import =
64 ossl_prov_get_keymgmt_import(fns);
67 if (kmgmt_new != NULL && kmgmt_import != NULL && kmgmt_free != NULL) {
68 if ((key = kmgmt_new(provctx)) == NULL
69 || !kmgmt_import(key, selection, params)) {
77 void ossl_prov_free_key(const OSSL_DISPATCH *fns, void *key)
79 OSSL_FUNC_keymgmt_free_fn *kmgmt_free = ossl_prov_get_keymgmt_free(fns);
81 if (kmgmt_free != NULL)