2 * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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
11 #include <openssl/evp.h>
13 static ENGINE_TABLE
*pkey_meth_table
= NULL
;
15 void ENGINE_unregister_pkey_meths(ENGINE
*e
)
17 engine_table_unregister(&pkey_meth_table
, e
);
20 static void engine_unregister_all_pkey_meths(void)
22 engine_table_cleanup(&pkey_meth_table
);
25 int ENGINE_register_pkey_meths(ENGINE
*e
)
29 int num_nids
= e
->pkey_meths(e
, NULL
, &nids
, 0);
31 return engine_table_register(&pkey_meth_table
,
32 engine_unregister_all_pkey_meths
, e
,
38 void ENGINE_register_all_pkey_meths()
42 for (e
= ENGINE_get_first(); e
; e
= ENGINE_get_next(e
))
43 ENGINE_register_pkey_meths(e
);
46 int ENGINE_set_default_pkey_meths(ENGINE
*e
)
50 int num_nids
= e
->pkey_meths(e
, NULL
, &nids
, 0);
52 return engine_table_register(&pkey_meth_table
,
53 engine_unregister_all_pkey_meths
, e
,
60 * Exposed API function to get a functional reference from the implementation
61 * table (ie. try to get a functional reference from the tabled structural
62 * references) for a given pkey_meth 'nid'
64 ENGINE
*ENGINE_get_pkey_meth_engine(int nid
)
66 return engine_table_select(&pkey_meth_table
, nid
);
69 /* Obtains a pkey_meth implementation from an ENGINE functional reference */
70 const EVP_PKEY_METHOD
*ENGINE_get_pkey_meth(ENGINE
*e
, int nid
)
73 ENGINE_PKEY_METHS_PTR fn
= ENGINE_get_pkey_meths(e
);
74 if (!fn
|| !fn(e
, &ret
, NULL
, nid
)) {
75 ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_METH
,
76 ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD
);
82 /* Gets the pkey_meth callback from an ENGINE structure */
83 ENGINE_PKEY_METHS_PTR
ENGINE_get_pkey_meths(const ENGINE
*e
)
88 /* Sets the pkey_meth callback in an ENGINE structure */
89 int ENGINE_set_pkey_meths(ENGINE
*e
, ENGINE_PKEY_METHS_PTR f
)
96 * Internal function to free up EVP_PKEY_METHOD structures before an ENGINE
100 void engine_pkey_meths_free(ENGINE
*e
)
103 EVP_PKEY_METHOD
*pkm
;
107 npknids
= e
->pkey_meths(e
, NULL
, &pknids
, 0);
108 for (i
= 0; i
< npknids
; i
++) {
109 if (e
->pkey_meths(e
, &pkm
, NULL
, pknids
[i
])) {
110 EVP_PKEY_meth_free(pkm
);