2 * Copyright 2006-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 /* We need to use some deprecated APIs */
11 #include "internal/deprecated.h"
13 #include "eng_local.h"
14 #include <openssl/evp.h>
16 static ENGINE_TABLE *pkey_meth_table = NULL;
18 void ENGINE_unregister_pkey_meths(ENGINE *e)
20 engine_table_unregister(&pkey_meth_table, e);
23 static void engine_unregister_all_pkey_meths(void)
25 engine_table_cleanup(&pkey_meth_table);
28 int ENGINE_register_pkey_meths(ENGINE *e)
32 int num_nids = e->pkey_meths(e, NULL, &nids, 0);
34 return engine_table_register(&pkey_meth_table,
35 engine_unregister_all_pkey_meths, e,
41 void ENGINE_register_all_pkey_meths(void)
45 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
46 ENGINE_register_pkey_meths(e);
49 int ENGINE_set_default_pkey_meths(ENGINE *e)
53 int num_nids = e->pkey_meths(e, NULL, &nids, 0);
55 return engine_table_register(&pkey_meth_table,
56 engine_unregister_all_pkey_meths, e,
63 * Exposed API function to get a functional reference from the implementation
64 * table (ie. try to get a functional reference from the tabled structural
65 * references) for a given pkey_meth 'nid'
67 ENGINE *ENGINE_get_pkey_meth_engine(int nid)
69 return ossl_engine_table_select(&pkey_meth_table, nid,
70 OPENSSL_FILE, OPENSSL_LINE);
73 /* Obtains a pkey_meth implementation from an ENGINE functional reference */
74 const EVP_PKEY_METHOD *ENGINE_get_pkey_meth(ENGINE *e, int nid)
77 ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e);
78 if (!fn || !fn(e, &ret, NULL, nid)) {
79 ERR_raise(ERR_LIB_ENGINE, ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
85 /* Gets the pkey_meth callback from an ENGINE structure */
86 ENGINE_PKEY_METHS_PTR ENGINE_get_pkey_meths(const ENGINE *e)
91 /* Sets the pkey_meth callback in an ENGINE structure */
92 int ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f)
99 * Internal function to free up EVP_PKEY_METHOD structures before an ENGINE
103 void engine_pkey_meths_free(ENGINE *e)
106 EVP_PKEY_METHOD *pkm;
110 npknids = e->pkey_meths(e, NULL, &pknids, 0);
111 for (i = 0; i < npknids; i++) {
112 if (e->pkey_meths(e, &pkm, NULL, pknids[i])) {
113 EVP_PKEY_meth_free(pkm);