diff options
Diffstat (limited to 'src/lib/libcrypto/engine/tb_pkmeth.c')
-rw-r--r-- | src/lib/libcrypto/engine/tb_pkmeth.c | 114 |
1 files changed, 60 insertions, 54 deletions
diff --git a/src/lib/libcrypto/engine/tb_pkmeth.c b/src/lib/libcrypto/engine/tb_pkmeth.c index 7a59744102..7834a22599 100644 --- a/src/lib/libcrypto/engine/tb_pkmeth.c +++ b/src/lib/libcrypto/engine/tb_pkmeth.c | |||
@@ -6,7 +6,7 @@ | |||
6 | * are met: | 6 | * are met: |
7 | * | 7 | * |
8 | * 1. Redistributions of source code must retain the above copyright | 8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. | 9 | * notice, this list of conditions and the following disclaimer. |
10 | * | 10 | * |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in | 12 | * notice, this list of conditions and the following disclaimer in |
@@ -62,106 +62,112 @@ | |||
62 | 62 | ||
63 | static ENGINE_TABLE *pkey_meth_table = NULL; | 63 | static ENGINE_TABLE *pkey_meth_table = NULL; |
64 | 64 | ||
65 | void ENGINE_unregister_pkey_meths(ENGINE *e) | 65 | void |
66 | { | 66 | ENGINE_unregister_pkey_meths(ENGINE *e) |
67 | { | ||
67 | engine_table_unregister(&pkey_meth_table, e); | 68 | engine_table_unregister(&pkey_meth_table, e); |
68 | } | 69 | } |
69 | 70 | ||
70 | static void engine_unregister_all_pkey_meths(void) | 71 | static void |
71 | { | 72 | engine_unregister_all_pkey_meths(void) |
73 | { | ||
72 | engine_table_cleanup(&pkey_meth_table); | 74 | engine_table_cleanup(&pkey_meth_table); |
73 | } | 75 | } |
74 | 76 | ||
75 | int ENGINE_register_pkey_meths(ENGINE *e) | 77 | int |
76 | { | 78 | ENGINE_register_pkey_meths(ENGINE *e) |
77 | if(e->pkey_meths) | 79 | { |
78 | { | 80 | if (e->pkey_meths) { |
79 | const int *nids; | 81 | const int *nids; |
80 | int num_nids = e->pkey_meths(e, NULL, &nids, 0); | 82 | int num_nids = e->pkey_meths(e, NULL, &nids, 0); |
81 | if(num_nids > 0) | 83 | if (num_nids > 0) |
82 | return engine_table_register(&pkey_meth_table, | 84 | return engine_table_register(&pkey_meth_table, |
83 | engine_unregister_all_pkey_meths, e, nids, | 85 | engine_unregister_all_pkey_meths, e, nids, |
84 | num_nids, 0); | 86 | num_nids, 0); |
85 | } | ||
86 | return 1; | ||
87 | } | 87 | } |
88 | return 1; | ||
89 | } | ||
88 | 90 | ||
89 | void ENGINE_register_all_pkey_meths(void) | 91 | void |
90 | { | 92 | ENGINE_register_all_pkey_meths(void) |
93 | { | ||
91 | ENGINE *e; | 94 | ENGINE *e; |
92 | 95 | ||
93 | for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) | 96 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) |
94 | ENGINE_register_pkey_meths(e); | 97 | ENGINE_register_pkey_meths(e); |
95 | } | 98 | } |
96 | 99 | ||
97 | int ENGINE_set_default_pkey_meths(ENGINE *e) | 100 | int |
98 | { | 101 | ENGINE_set_default_pkey_meths(ENGINE *e) |
99 | if(e->pkey_meths) | 102 | { |
100 | { | 103 | if (e->pkey_meths) { |
101 | const int *nids; | 104 | const int *nids; |
102 | int num_nids = e->pkey_meths(e, NULL, &nids, 0); | 105 | int num_nids = e->pkey_meths(e, NULL, &nids, 0); |
103 | if(num_nids > 0) | 106 | if (num_nids > 0) |
104 | return engine_table_register(&pkey_meth_table, | 107 | return engine_table_register(&pkey_meth_table, |
105 | engine_unregister_all_pkey_meths, e, nids, | 108 | engine_unregister_all_pkey_meths, e, nids, |
106 | num_nids, 1); | 109 | num_nids, 1); |
107 | } | ||
108 | return 1; | ||
109 | } | 110 | } |
111 | return 1; | ||
112 | } | ||
110 | 113 | ||
111 | /* Exposed API function to get a functional reference from the implementation | 114 | /* Exposed API function to get a functional reference from the implementation |
112 | * table (ie. try to get a functional reference from the tabled structural | 115 | * table (ie. try to get a functional reference from the tabled structural |
113 | * references) for a given pkey_meth 'nid' */ | 116 | * references) for a given pkey_meth 'nid' */ |
114 | ENGINE *ENGINE_get_pkey_meth_engine(int nid) | 117 | ENGINE * |
115 | { | 118 | ENGINE_get_pkey_meth_engine(int nid) |
119 | { | ||
116 | return engine_table_select(&pkey_meth_table, nid); | 120 | return engine_table_select(&pkey_meth_table, nid); |
117 | } | 121 | } |
118 | 122 | ||
119 | /* Obtains a pkey_meth implementation from an ENGINE functional reference */ | 123 | /* Obtains a pkey_meth implementation from an ENGINE functional reference */ |
120 | const EVP_PKEY_METHOD *ENGINE_get_pkey_meth(ENGINE *e, int nid) | 124 | const EVP_PKEY_METHOD * |
121 | { | 125 | ENGINE_get_pkey_meth(ENGINE *e, int nid) |
126 | { | ||
122 | EVP_PKEY_METHOD *ret; | 127 | EVP_PKEY_METHOD *ret; |
123 | ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e); | 128 | ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e); |
124 | if(!fn || !fn(e, &ret, NULL, nid)) | 129 | |
125 | { | 130 | if (!fn || !fn(e, &ret, NULL, nid)) { |
126 | ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_METH, | 131 | ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_METH, |
127 | ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD); | 132 | ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD); |
128 | return NULL; | 133 | return NULL; |
129 | } | ||
130 | return ret; | ||
131 | } | 134 | } |
135 | return ret; | ||
136 | } | ||
132 | 137 | ||
133 | /* Gets the pkey_meth callback from an ENGINE structure */ | 138 | /* Gets the pkey_meth callback from an ENGINE structure */ |
134 | ENGINE_PKEY_METHS_PTR ENGINE_get_pkey_meths(const ENGINE *e) | 139 | ENGINE_PKEY_METHS_PTR |
135 | { | 140 | ENGINE_get_pkey_meths(const ENGINE *e) |
141 | { | ||
136 | return e->pkey_meths; | 142 | return e->pkey_meths; |
137 | } | 143 | } |
138 | 144 | ||
139 | /* Sets the pkey_meth callback in an ENGINE structure */ | 145 | /* Sets the pkey_meth callback in an ENGINE structure */ |
140 | int ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f) | 146 | int |
141 | { | 147 | ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f) |
148 | { | ||
142 | e->pkey_meths = f; | 149 | e->pkey_meths = f; |
143 | return 1; | 150 | return 1; |
144 | } | 151 | } |
145 | 152 | ||
146 | /* Internal function to free up EVP_PKEY_METHOD structures before an | 153 | /* Internal function to free up EVP_PKEY_METHOD structures before an |
147 | * ENGINE is destroyed | 154 | * ENGINE is destroyed |
148 | */ | 155 | */ |
149 | 156 | ||
150 | void engine_pkey_meths_free(ENGINE *e) | 157 | void |
151 | { | 158 | engine_pkey_meths_free(ENGINE *e) |
159 | { | ||
152 | int i; | 160 | int i; |
153 | EVP_PKEY_METHOD *pkm; | 161 | EVP_PKEY_METHOD *pkm; |
154 | if (e->pkey_meths) | 162 | |
155 | { | 163 | if (e->pkey_meths) { |
156 | const int *pknids; | 164 | const int *pknids; |
157 | int npknids; | 165 | int npknids; |
158 | npknids = e->pkey_meths(e, NULL, &pknids, 0); | 166 | npknids = e->pkey_meths(e, NULL, &pknids, 0); |
159 | for (i = 0; i < npknids; i++) | 167 | for (i = 0; i < npknids; i++) { |
160 | { | 168 | if (e->pkey_meths(e, &pkm, NULL, pknids[i])) { |
161 | if (e->pkey_meths(e, &pkm, NULL, pknids[i])) | ||
162 | { | ||
163 | EVP_PKEY_meth_free(pkm); | 169 | EVP_PKEY_meth_free(pkm); |
164 | } | ||
165 | } | 170 | } |
166 | } | 171 | } |
167 | } | 172 | } |
173 | } | ||