/src/openssl36/providers/implementations/keymgmt/dh_kmgmt.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2019-2026 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
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 |
8 | | */ |
9 | | |
10 | | /* |
11 | | * DH low level APIs are deprecated for public use, but still ok for |
12 | | * internal use. |
13 | | */ |
14 | | #include "internal/deprecated.h" |
15 | | #include "internal/common.h" |
16 | | |
17 | | #include <string.h> /* strcmp */ |
18 | | #include <openssl/core_dispatch.h> |
19 | | #include <openssl/core_names.h> |
20 | | #include <openssl/bn.h> |
21 | | #include <openssl/err.h> |
22 | | #include <openssl/proverr.h> |
23 | | #include <openssl/self_test.h> |
24 | | #include "prov/implementations.h" |
25 | | #include "prov/providercommon.h" |
26 | | #include "prov/provider_ctx.h" |
27 | | #include "crypto/dh.h" |
28 | | #include "internal/fips.h" |
29 | | #include "internal/sizes.h" |
30 | | #include "providers/implementations/keymgmt/keymgmtcommon.inc" |
31 | | |
32 | | static OSSL_FUNC_keymgmt_new_fn dh_newdata; |
33 | | static OSSL_FUNC_keymgmt_free_fn dh_freedata; |
34 | | static OSSL_FUNC_keymgmt_gen_init_fn dh_gen_init; |
35 | | static OSSL_FUNC_keymgmt_gen_init_fn dhx_gen_init; |
36 | | static OSSL_FUNC_keymgmt_gen_set_template_fn dh_gen_set_template; |
37 | | static OSSL_FUNC_keymgmt_gen_set_params_fn dh_gen_set_params; |
38 | | static OSSL_FUNC_keymgmt_gen_settable_params_fn dh_gen_settable_params; |
39 | | static OSSL_FUNC_keymgmt_gen_fn dh_gen; |
40 | | static OSSL_FUNC_keymgmt_gen_cleanup_fn dh_gen_cleanup; |
41 | | static OSSL_FUNC_keymgmt_load_fn dh_load; |
42 | | static OSSL_FUNC_keymgmt_get_params_fn dh_get_params; |
43 | | static OSSL_FUNC_keymgmt_gettable_params_fn dh_gettable_params; |
44 | | static OSSL_FUNC_keymgmt_set_params_fn dh_set_params; |
45 | | static OSSL_FUNC_keymgmt_settable_params_fn dh_settable_params; |
46 | | static OSSL_FUNC_keymgmt_has_fn dh_has; |
47 | | static OSSL_FUNC_keymgmt_match_fn dh_match; |
48 | | static OSSL_FUNC_keymgmt_validate_fn dh_validate; |
49 | | static OSSL_FUNC_keymgmt_import_fn dh_import; |
50 | | static OSSL_FUNC_keymgmt_import_types_fn dh_import_types; |
51 | | static OSSL_FUNC_keymgmt_export_fn dh_export; |
52 | | static OSSL_FUNC_keymgmt_export_types_fn dh_export_types; |
53 | | static OSSL_FUNC_keymgmt_dup_fn dh_dup; |
54 | | |
55 | | #define DH_POSSIBLE_SELECTIONS \ |
56 | 67.7k | (OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) |
57 | | |
58 | | struct dh_gen_ctx { |
59 | | OSSL_LIB_CTX *libctx; |
60 | | |
61 | | FFC_PARAMS *ffc_params; |
62 | | int selection; |
63 | | /* All these parameters are used for parameter generation only */ |
64 | | /* If there is a group name then the remaining parameters are not needed */ |
65 | | int group_nid; |
66 | | size_t pbits; |
67 | | size_t qbits; |
68 | | unsigned char *seed; /* optional FIPS186-4 param for testing */ |
69 | | size_t seedlen; |
70 | | int gindex; /* optional FIPS186-4 generator index (ignored if -1) */ |
71 | | int gen_type; /* see dhtype2id */ |
72 | | int generator; /* Used by DH_PARAMGEN_TYPE_GENERATOR in non fips mode only */ |
73 | | int pcounter; |
74 | | int hindex; |
75 | | int priv_len; |
76 | | |
77 | | char *mdname; |
78 | | char *mdprops; |
79 | | OSSL_CALLBACK *cb; |
80 | | void *cbarg; |
81 | | int dh_type; |
82 | | }; |
83 | | |
84 | | static int dh_gen_type_name2id_w_default(const char *name, int type) |
85 | 0 | { |
86 | 0 | if (strcmp(name, "default") == 0) { |
87 | | #ifdef FIPS_MODULE |
88 | | if (type == DH_FLAG_TYPE_DHX) |
89 | | return DH_PARAMGEN_TYPE_FIPS_186_4; |
90 | | |
91 | | return DH_PARAMGEN_TYPE_GROUP; |
92 | | #else |
93 | 0 | if (type == DH_FLAG_TYPE_DHX) |
94 | 0 | return DH_PARAMGEN_TYPE_FIPS_186_2; |
95 | | |
96 | 0 | return DH_PARAMGEN_TYPE_GENERATOR; |
97 | 0 | #endif |
98 | 0 | } |
99 | | |
100 | 0 | return ossl_dh_gen_type_name2id(name, type); |
101 | 0 | } |
102 | | |
103 | | static void *dh_newdata(void *provctx) |
104 | 5.46k | { |
105 | 5.46k | DH *dh = NULL; |
106 | | |
107 | 5.46k | if (ossl_prov_is_running()) { |
108 | 5.46k | dh = ossl_dh_new_ex(PROV_LIBCTX_OF(provctx)); |
109 | 5.46k | if (dh != NULL) { |
110 | 5.46k | DH_clear_flags(dh, DH_FLAG_TYPE_MASK); |
111 | 5.46k | DH_set_flags(dh, DH_FLAG_TYPE_DH); |
112 | 5.46k | } |
113 | 5.46k | } |
114 | 5.46k | return dh; |
115 | 5.46k | } |
116 | | |
117 | | static void *dhx_newdata(void *provctx) |
118 | 0 | { |
119 | 0 | DH *dh = NULL; |
120 | |
|
121 | 0 | dh = ossl_dh_new_ex(PROV_LIBCTX_OF(provctx)); |
122 | 0 | if (dh != NULL) { |
123 | 0 | DH_clear_flags(dh, DH_FLAG_TYPE_MASK); |
124 | 0 | DH_set_flags(dh, DH_FLAG_TYPE_DHX); |
125 | 0 | } |
126 | 0 | return dh; |
127 | 0 | } |
128 | | |
129 | | static void dh_freedata(void *keydata) |
130 | 79.0k | { |
131 | 79.0k | DH_free(keydata); |
132 | 79.0k | } |
133 | | |
134 | | static int dh_has(const void *keydata, int selection) |
135 | 9.04k | { |
136 | 9.04k | const DH *dh = keydata; |
137 | 9.04k | int ok = 1; |
138 | | |
139 | 9.04k | if (!ossl_prov_is_running() || dh == NULL) |
140 | 918 | return 0; |
141 | 8.12k | if ((selection & DH_POSSIBLE_SELECTIONS) == 0) |
142 | 0 | return 1; /* the selection is not missing */ |
143 | | |
144 | 8.12k | if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) |
145 | 7.00k | ok = ok && (DH_get0_pub_key(dh) != NULL); |
146 | 8.12k | if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) |
147 | 82 | ok = ok && (DH_get0_priv_key(dh) != NULL); |
148 | 8.12k | if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) |
149 | 1.03k | ok = ok && (DH_get0_p(dh) != NULL && DH_get0_g(dh) != NULL); |
150 | 8.12k | return ok; |
151 | 8.12k | } |
152 | | |
153 | | static int dh_match(const void *keydata1, const void *keydata2, int selection) |
154 | 6.60k | { |
155 | 6.60k | const DH *dh1 = keydata1; |
156 | 6.60k | const DH *dh2 = keydata2; |
157 | 6.60k | int ok = 1; |
158 | | |
159 | 6.60k | if (!ossl_prov_is_running()) |
160 | 0 | return 0; |
161 | | |
162 | 6.60k | if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { |
163 | 6.60k | int key_checked = 0; |
164 | | |
165 | 6.60k | if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { |
166 | 6.60k | const BIGNUM *pa = DH_get0_pub_key(dh1); |
167 | 6.60k | const BIGNUM *pb = DH_get0_pub_key(dh2); |
168 | | |
169 | 6.60k | if (pa != NULL && pb != NULL) { |
170 | 405 | ok = ok && BN_cmp(pa, pb) == 0; |
171 | 405 | key_checked = 1; |
172 | 405 | } |
173 | 6.60k | } |
174 | 6.60k | if (!key_checked |
175 | 6.19k | && (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { |
176 | 6.19k | const BIGNUM *pa = DH_get0_priv_key(dh1); |
177 | 6.19k | const BIGNUM *pb = DH_get0_priv_key(dh2); |
178 | | |
179 | 6.19k | if (pa != NULL && pb != NULL) { |
180 | 0 | ok = ok && BN_cmp(pa, pb) == 0; |
181 | 0 | key_checked = 1; |
182 | 0 | } |
183 | 6.19k | } |
184 | 6.60k | ok = ok && key_checked; |
185 | 6.60k | } |
186 | 6.60k | if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) { |
187 | 6.60k | FFC_PARAMS *dhparams1 = ossl_dh_get0_params((DH *)dh1); |
188 | 6.60k | FFC_PARAMS *dhparams2 = ossl_dh_get0_params((DH *)dh2); |
189 | | |
190 | 6.60k | ok = ok && ossl_ffc_params_cmp(dhparams1, dhparams2, 1); |
191 | 6.60k | } |
192 | 6.60k | return ok; |
193 | 6.60k | } |
194 | | |
195 | | static int dh_import(void *keydata, int selection, const OSSL_PARAM params[]) |
196 | 10.2k | { |
197 | 10.2k | DH *dh = keydata; |
198 | 10.2k | int ok = 1; |
199 | | |
200 | 10.2k | if (!ossl_prov_is_running() || dh == NULL) |
201 | 0 | return 0; |
202 | | |
203 | 10.2k | if ((selection & DH_POSSIBLE_SELECTIONS) == 0) |
204 | 0 | return 0; |
205 | | |
206 | | /* a key without parameters is meaningless */ |
207 | 10.2k | ok = ok && ossl_dh_params_fromdata(dh, params); |
208 | | |
209 | 10.2k | if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { |
210 | 10.2k | int include_private = selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0; |
211 | | |
212 | 10.2k | ok = ok && ossl_dh_key_fromdata(dh, params, include_private); |
213 | 10.2k | } |
214 | | |
215 | 10.2k | return ok; |
216 | 10.2k | } |
217 | | |
218 | | static int dh_export(void *keydata, int selection, OSSL_CALLBACK *param_cb, |
219 | | void *cbarg) |
220 | 0 | { |
221 | 0 | DH *dh = keydata; |
222 | 0 | OSSL_PARAM_BLD *tmpl = NULL; |
223 | 0 | OSSL_PARAM *params = NULL; |
224 | 0 | int ok = 1; |
225 | |
|
226 | 0 | if (!ossl_prov_is_running() || dh == NULL) |
227 | 0 | return 0; |
228 | | |
229 | 0 | if ((selection & DH_POSSIBLE_SELECTIONS) == 0) |
230 | 0 | return 0; |
231 | | |
232 | 0 | tmpl = OSSL_PARAM_BLD_new(); |
233 | 0 | if (tmpl == NULL) |
234 | 0 | return 0; |
235 | | |
236 | 0 | if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) |
237 | 0 | ok = ok && ossl_dh_params_todata(dh, tmpl, NULL); |
238 | |
|
239 | 0 | if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { |
240 | 0 | int include_private = selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0; |
241 | |
|
242 | 0 | ok = ok && ossl_dh_key_todata(dh, tmpl, NULL, include_private); |
243 | 0 | } |
244 | |
|
245 | 0 | if (!ok || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) { |
246 | 0 | ok = 0; |
247 | 0 | goto err; |
248 | 0 | } |
249 | | |
250 | 0 | ok = param_cb(params, cbarg); |
251 | 0 | OSSL_PARAM_free(params); |
252 | 0 | err: |
253 | 0 | OSSL_PARAM_BLD_free(tmpl); |
254 | 0 | return ok; |
255 | 0 | } |
256 | | |
257 | | /* IMEXPORT = IMPORT + EXPORT */ |
258 | | |
259 | | #define DH_IMEXPORTABLE_PARAMETERS \ |
260 | | OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_P, NULL, 0), \ |
261 | | OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_Q, NULL, 0), \ |
262 | | OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_G, NULL, 0), \ |
263 | | OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_COFACTOR, NULL, 0), \ |
264 | | OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_GINDEX, NULL), \ |
265 | | OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_PCOUNTER, NULL), \ |
266 | | OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_H, NULL), \ |
267 | | OSSL_PARAM_int(OSSL_PKEY_PARAM_DH_PRIV_LEN, NULL), \ |
268 | | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_FFC_SEED, NULL, 0), \ |
269 | | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, NULL, 0) |
270 | | #define DH_IMEXPORTABLE_PUBLIC_KEY \ |
271 | | OSSL_PARAM_BN(OSSL_PKEY_PARAM_PUB_KEY, NULL, 0) |
272 | | #define DH_IMEXPORTABLE_PRIVATE_KEY \ |
273 | | OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0) |
274 | | static const OSSL_PARAM dh_all_types[] = { |
275 | | DH_IMEXPORTABLE_PARAMETERS, |
276 | | DH_IMEXPORTABLE_PUBLIC_KEY, |
277 | | DH_IMEXPORTABLE_PRIVATE_KEY, |
278 | | OSSL_PARAM_END |
279 | | }; |
280 | | static const OSSL_PARAM dh_parameter_types[] = { |
281 | | DH_IMEXPORTABLE_PARAMETERS, |
282 | | OSSL_PARAM_END |
283 | | }; |
284 | | static const OSSL_PARAM dh_key_types[] = { |
285 | | DH_IMEXPORTABLE_PUBLIC_KEY, |
286 | | DH_IMEXPORTABLE_PRIVATE_KEY, |
287 | | OSSL_PARAM_END |
288 | | }; |
289 | | static const OSSL_PARAM *dh_types[] = { |
290 | | NULL, /* Index 0 = none of them */ |
291 | | dh_parameter_types, /* Index 1 = parameter types */ |
292 | | dh_key_types, /* Index 2 = key types */ |
293 | | dh_all_types /* Index 3 = 1 + 2 */ |
294 | | }; |
295 | | |
296 | | static const OSSL_PARAM *dh_imexport_types(int selection) |
297 | 0 | { |
298 | 0 | int type_select = 0; |
299 | |
|
300 | 0 | if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) |
301 | 0 | type_select += 1; |
302 | 0 | if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) |
303 | 0 | type_select += 2; |
304 | 0 | return dh_types[type_select]; |
305 | 0 | } |
306 | | |
307 | | static const OSSL_PARAM *dh_import_types(int selection) |
308 | 0 | { |
309 | 0 | return dh_imexport_types(selection); |
310 | 0 | } |
311 | | |
312 | | static const OSSL_PARAM *dh_export_types(int selection) |
313 | 0 | { |
314 | 0 | return dh_imexport_types(selection); |
315 | 0 | } |
316 | | |
317 | | static ossl_inline int dh_get_params(void *key, OSSL_PARAM params[]) |
318 | 15.0k | { |
319 | 15.0k | DH *dh = key; |
320 | 15.0k | OSSL_PARAM *p; |
321 | | |
322 | 15.0k | if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_BITS)) != NULL |
323 | 13.5k | && !OSSL_PARAM_set_int(p, DH_bits(dh))) |
324 | 0 | return 0; |
325 | 15.0k | if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_SECURITY_BITS)) != NULL |
326 | 13.5k | && !OSSL_PARAM_set_int(p, DH_security_bits(dh))) |
327 | 0 | return 0; |
328 | 15.0k | if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_MAX_SIZE)) != NULL |
329 | 13.5k | && !OSSL_PARAM_set_int(p, DH_size(dh))) |
330 | 0 | return 0; |
331 | 15.0k | if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY)) != NULL) { |
332 | 1.46k | if (p->data_type != OSSL_PARAM_OCTET_STRING) |
333 | 0 | return 0; |
334 | 1.46k | p->return_size = ossl_dh_key2buf(dh, (unsigned char **)&p->data, |
335 | 1.46k | p->data_size, 0); |
336 | 1.46k | if (p->return_size == 0) |
337 | 0 | return 0; |
338 | 1.46k | } |
339 | 15.0k | if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_SECURITY_CATEGORY)) != NULL) |
340 | 13.5k | if (!OSSL_PARAM_set_int(p, 0)) |
341 | 0 | return 0; |
342 | | |
343 | 15.0k | return ossl_dh_params_todata(dh, NULL, params) |
344 | 15.0k | && ossl_dh_key_todata(dh, NULL, params, 1); |
345 | 15.0k | } |
346 | | |
347 | | static const OSSL_PARAM dh_params[] = { |
348 | | OSSL_PARAM_int(OSSL_PKEY_PARAM_BITS, NULL), |
349 | | OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_BITS, NULL), |
350 | | OSSL_PARAM_int(OSSL_PKEY_PARAM_MAX_SIZE, NULL), |
351 | | OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_CATEGORY, NULL), |
352 | | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, NULL, 0), |
353 | | DH_IMEXPORTABLE_PARAMETERS, |
354 | | DH_IMEXPORTABLE_PUBLIC_KEY, |
355 | | DH_IMEXPORTABLE_PRIVATE_KEY, |
356 | | OSSL_PARAM_END |
357 | | }; |
358 | | |
359 | | static const OSSL_PARAM *dh_gettable_params(void *provctx) |
360 | 0 | { |
361 | 0 | return dh_params; |
362 | 0 | } |
363 | | |
364 | | static const OSSL_PARAM dh_known_settable_params[] = { |
365 | | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, NULL, 0), |
366 | | OSSL_PARAM_END |
367 | | }; |
368 | | |
369 | | static const OSSL_PARAM *dh_settable_params(void *provctx) |
370 | 0 | { |
371 | 0 | return dh_known_settable_params; |
372 | 0 | } |
373 | | |
374 | | static int dh_set_params(void *key, const OSSL_PARAM params[]) |
375 | 549 | { |
376 | 549 | DH *dh = key; |
377 | 549 | const OSSL_PARAM *p; |
378 | | |
379 | 549 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY); |
380 | 549 | if (p != NULL |
381 | 549 | && (p->data_type != OSSL_PARAM_OCTET_STRING |
382 | 549 | || !ossl_dh_buf2key(dh, p->data, p->data_size))) |
383 | 18 | return 0; |
384 | | |
385 | 531 | return 1; |
386 | 549 | } |
387 | | |
388 | | static int dh_validate_public(const DH *dh, int checktype) |
389 | 26.0k | { |
390 | 26.0k | const BIGNUM *pub_key = NULL; |
391 | 26.0k | int res = 0; |
392 | | |
393 | 26.0k | DH_get0_key(dh, &pub_key, NULL); |
394 | 26.0k | if (pub_key == NULL) |
395 | 12.3k | return 0; |
396 | | |
397 | | /* |
398 | | * The partial test is only valid for named group's with q = (p - 1) / 2 |
399 | | * but for that case it is also fully sufficient to check the key validity. |
400 | | */ |
401 | 13.7k | if (ossl_dh_is_named_safe_prime_group(dh)) |
402 | 1.31k | return ossl_dh_check_pub_key_partial(dh, pub_key, &res); |
403 | | |
404 | 12.4k | return DH_check_pub_key_ex(dh, pub_key); |
405 | 13.7k | } |
406 | | |
407 | | static int dh_validate_private(const DH *dh) |
408 | 6.58k | { |
409 | 6.58k | int status = 0; |
410 | 6.58k | const BIGNUM *priv_key = NULL; |
411 | | |
412 | 6.58k | DH_get0_key(dh, NULL, &priv_key); |
413 | 6.58k | if (priv_key == NULL) |
414 | 6.54k | return 0; |
415 | 46 | return ossl_dh_check_priv_key(dh, priv_key, &status); |
416 | 6.58k | } |
417 | | |
418 | | static int dh_validate(const void *keydata, int selection, int checktype) |
419 | 49.4k | { |
420 | 49.4k | const DH *dh = keydata; |
421 | 49.4k | int ok = 1; |
422 | | |
423 | 49.4k | if (!ossl_prov_is_running()) |
424 | 0 | return 0; |
425 | | |
426 | 49.4k | if ((selection & DH_POSSIBLE_SELECTIONS) == 0) |
427 | 0 | return 1; /* nothing to validate */ |
428 | | |
429 | 49.4k | if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) { |
430 | | /* |
431 | | * Both of these functions check parameters. DH_check_params_ex() |
432 | | * performs a lightweight check (e.g. it does not check that p is a |
433 | | * safe prime) |
434 | | */ |
435 | 16.7k | if (checktype == OSSL_KEYMGMT_VALIDATE_QUICK_CHECK) |
436 | 10.2k | ok = ok && DH_check_params_ex(dh); |
437 | 6.53k | else |
438 | 6.53k | ok = ok && DH_check_ex(dh); |
439 | 16.7k | } |
440 | | |
441 | 49.4k | if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) |
442 | 26.0k | ok = ok && dh_validate_public(dh, checktype); |
443 | | |
444 | 49.4k | if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) |
445 | 13.1k | ok = ok && dh_validate_private(dh); |
446 | | |
447 | 49.4k | if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) |
448 | 49.4k | == OSSL_KEYMGMT_SELECT_KEYPAIR) |
449 | 6.55k | ok = ok && ossl_dh_check_pairwise(dh, 0); |
450 | 49.4k | return ok; |
451 | 49.4k | } |
452 | | |
453 | | static void *dh_gen_init_base(void *provctx, int selection, |
454 | | const OSSL_PARAM params[], int type) |
455 | 7.34k | { |
456 | 7.34k | OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(provctx); |
457 | 7.34k | struct dh_gen_ctx *gctx = NULL; |
458 | | |
459 | 7.34k | if (!ossl_prov_is_running()) |
460 | 0 | return NULL; |
461 | | |
462 | 7.34k | if ((selection & (OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS)) == 0) |
463 | 0 | return NULL; |
464 | | |
465 | 7.34k | if ((gctx = OPENSSL_zalloc(sizeof(*gctx))) != NULL) { |
466 | 7.34k | gctx->selection = selection; |
467 | 7.34k | gctx->libctx = libctx; |
468 | 7.34k | gctx->pbits = 2048; |
469 | 7.34k | gctx->qbits = 224; |
470 | 7.34k | gctx->mdname = NULL; |
471 | | #ifdef FIPS_MODULE |
472 | | gctx->gen_type = (type == DH_FLAG_TYPE_DHX) |
473 | | ? DH_PARAMGEN_TYPE_FIPS_186_4 |
474 | | : DH_PARAMGEN_TYPE_GROUP; |
475 | | #else |
476 | 7.34k | gctx->gen_type = (type == DH_FLAG_TYPE_DHX) |
477 | 7.34k | ? DH_PARAMGEN_TYPE_FIPS_186_2 |
478 | 7.34k | : DH_PARAMGEN_TYPE_GENERATOR; |
479 | 7.34k | #endif |
480 | 7.34k | gctx->gindex = -1; |
481 | 7.34k | gctx->hindex = 0; |
482 | 7.34k | gctx->pcounter = -1; |
483 | 7.34k | gctx->generator = DH_GENERATOR_2; |
484 | 7.34k | gctx->dh_type = type; |
485 | 7.34k | } |
486 | 7.34k | if (!dh_gen_set_params(gctx, params)) { |
487 | 0 | OPENSSL_free(gctx); |
488 | 0 | gctx = NULL; |
489 | 0 | } |
490 | 7.34k | return gctx; |
491 | 7.34k | } |
492 | | |
493 | | static void *dh_gen_init(void *provctx, int selection, |
494 | | const OSSL_PARAM params[]) |
495 | 7.34k | { |
496 | 7.34k | return dh_gen_init_base(provctx, selection, params, DH_FLAG_TYPE_DH); |
497 | 7.34k | } |
498 | | |
499 | | static void *dhx_gen_init(void *provctx, int selection, |
500 | | const OSSL_PARAM params[]) |
501 | 0 | { |
502 | 0 | return dh_gen_init_base(provctx, selection, params, DH_FLAG_TYPE_DHX); |
503 | 0 | } |
504 | | |
505 | | static int dh_gen_set_template(void *genctx, void *templ) |
506 | 4.48k | { |
507 | 4.48k | struct dh_gen_ctx *gctx = genctx; |
508 | 4.48k | DH *dh = templ; |
509 | | |
510 | 4.48k | if (!ossl_prov_is_running() || gctx == NULL || dh == NULL) |
511 | 0 | return 0; |
512 | 4.48k | gctx->ffc_params = ossl_dh_get0_params(dh); |
513 | 4.48k | return 1; |
514 | 4.48k | } |
515 | | |
516 | | static int dh_set_gen_seed(struct dh_gen_ctx *gctx, unsigned char *seed, |
517 | | size_t seedlen) |
518 | 0 | { |
519 | 0 | OPENSSL_clear_free(gctx->seed, gctx->seedlen); |
520 | 0 | gctx->seed = NULL; |
521 | 0 | gctx->seedlen = 0; |
522 | 0 | if (seed != NULL && seedlen > 0) { |
523 | 0 | gctx->seed = OPENSSL_memdup(seed, seedlen); |
524 | 0 | if (gctx->seed == NULL) |
525 | 0 | return 0; |
526 | 0 | gctx->seedlen = seedlen; |
527 | 0 | } |
528 | 0 | return 1; |
529 | 0 | } |
530 | | |
531 | | static int dh_gen_common_set_params(void *genctx, const OSSL_PARAM params[]) |
532 | 2.46k | { |
533 | 2.46k | struct dh_gen_ctx *gctx = genctx; |
534 | 2.46k | const OSSL_PARAM *p; |
535 | 2.46k | int gen_type = -1; |
536 | | |
537 | 2.46k | if (gctx == NULL) |
538 | 0 | return 0; |
539 | 2.46k | if (ossl_param_is_empty(params)) |
540 | 2.07k | return 1; |
541 | | |
542 | 389 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_TYPE); |
543 | 389 | if (p != NULL) { |
544 | 0 | if (p->data_type != OSSL_PARAM_UTF8_STRING |
545 | 0 | || ((gen_type = dh_gen_type_name2id_w_default(p->data, gctx->dh_type)) == -1)) { |
546 | 0 | ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); |
547 | 0 | return 0; |
548 | 0 | } |
549 | 0 | if (gen_type != -1) |
550 | 0 | gctx->gen_type = gen_type; |
551 | 0 | } |
552 | 389 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_GROUP_NAME); |
553 | 389 | if (p != NULL) { |
554 | 389 | const DH_NAMED_GROUP *group = NULL; |
555 | | |
556 | 389 | if (p->data_type != OSSL_PARAM_UTF8_STRING |
557 | 389 | || p->data == NULL |
558 | 389 | || (group = ossl_ffc_name_to_dh_named_group(p->data)) == NULL |
559 | 389 | || ((gctx->group_nid = ossl_ffc_named_group_get_uid(group)) == NID_undef)) { |
560 | 0 | ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); |
561 | 0 | return 0; |
562 | 0 | } |
563 | 389 | } |
564 | 389 | if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_PBITS)) != NULL |
565 | 0 | && !OSSL_PARAM_get_size_t(p, &gctx->pbits)) |
566 | 0 | return 0; |
567 | 389 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DH_PRIV_LEN); |
568 | 389 | if (p != NULL && !OSSL_PARAM_get_int(p, &gctx->priv_len)) |
569 | 0 | return 0; |
570 | 389 | return 1; |
571 | 389 | } |
572 | | |
573 | | static const OSSL_PARAM *dh_gen_settable_params(ossl_unused void *genctx, |
574 | | ossl_unused void *provctx) |
575 | 0 | { |
576 | 0 | static const OSSL_PARAM dh_gen_settable[] = { |
577 | 0 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_FFC_TYPE, NULL, 0), |
578 | 0 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, NULL, 0), |
579 | 0 | OSSL_PARAM_int(OSSL_PKEY_PARAM_DH_PRIV_LEN, NULL), |
580 | 0 | OSSL_PARAM_size_t(OSSL_PKEY_PARAM_FFC_PBITS, NULL), |
581 | 0 | OSSL_PARAM_int(OSSL_PKEY_PARAM_DH_GENERATOR, NULL), |
582 | 0 | OSSL_PARAM_END |
583 | 0 | }; |
584 | 0 | return dh_gen_settable; |
585 | 0 | } |
586 | | |
587 | | static const OSSL_PARAM *dhx_gen_settable_params(ossl_unused void *genctx, |
588 | | ossl_unused void *provctx) |
589 | 0 | { |
590 | 0 | static const OSSL_PARAM dhx_gen_settable[] = { |
591 | 0 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_FFC_TYPE, NULL, 0), |
592 | 0 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, NULL, 0), |
593 | 0 | OSSL_PARAM_int(OSSL_PKEY_PARAM_DH_PRIV_LEN, NULL), |
594 | 0 | OSSL_PARAM_size_t(OSSL_PKEY_PARAM_FFC_PBITS, NULL), |
595 | 0 | OSSL_PARAM_size_t(OSSL_PKEY_PARAM_FFC_QBITS, NULL), |
596 | 0 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_FFC_DIGEST, NULL, 0), |
597 | 0 | OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_FFC_DIGEST_PROPS, NULL, 0), |
598 | 0 | OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_GINDEX, NULL), |
599 | 0 | OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_FFC_SEED, NULL, 0), |
600 | 0 | OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_PCOUNTER, NULL), |
601 | 0 | OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_H, NULL), |
602 | 0 | OSSL_PARAM_END |
603 | 0 | }; |
604 | 0 | return dhx_gen_settable; |
605 | 0 | } |
606 | | |
607 | | static int dhx_gen_set_params(void *genctx, const OSSL_PARAM params[]) |
608 | 0 | { |
609 | 0 | struct dh_gen_ctx *gctx = genctx; |
610 | 0 | const OSSL_PARAM *p; |
611 | |
|
612 | 0 | if (!dh_gen_common_set_params(genctx, params)) |
613 | 0 | return 0; |
614 | | |
615 | | /* Parameters related to fips186-4 and fips186-2 */ |
616 | 0 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_GINDEX); |
617 | 0 | if (p != NULL && !OSSL_PARAM_get_int(p, &gctx->gindex)) |
618 | 0 | return 0; |
619 | 0 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_PCOUNTER); |
620 | 0 | if (p != NULL && !OSSL_PARAM_get_int(p, &gctx->pcounter)) |
621 | 0 | return 0; |
622 | 0 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_H); |
623 | 0 | if (p != NULL && !OSSL_PARAM_get_int(p, &gctx->hindex)) |
624 | 0 | return 0; |
625 | 0 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_SEED); |
626 | 0 | if (p != NULL |
627 | 0 | && (p->data_type != OSSL_PARAM_OCTET_STRING |
628 | 0 | || !dh_set_gen_seed(gctx, p->data, p->data_size))) |
629 | 0 | return 0; |
630 | 0 | if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_QBITS)) != NULL |
631 | 0 | && !OSSL_PARAM_get_size_t(p, &gctx->qbits)) |
632 | 0 | return 0; |
633 | 0 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST); |
634 | 0 | if (p != NULL) { |
635 | 0 | if (p->data_type != OSSL_PARAM_UTF8_STRING) |
636 | 0 | return 0; |
637 | 0 | OPENSSL_free(gctx->mdname); |
638 | 0 | gctx->mdname = OPENSSL_strdup(p->data); |
639 | 0 | if (gctx->mdname == NULL) |
640 | 0 | return 0; |
641 | 0 | } |
642 | 0 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST_PROPS); |
643 | 0 | if (p != NULL) { |
644 | 0 | if (p->data_type != OSSL_PARAM_UTF8_STRING) |
645 | 0 | return 0; |
646 | 0 | OPENSSL_free(gctx->mdprops); |
647 | 0 | gctx->mdprops = OPENSSL_strdup(p->data); |
648 | 0 | if (gctx->mdprops == NULL) |
649 | 0 | return 0; |
650 | 0 | } |
651 | | |
652 | | /* Parameters that are not allowed for DHX */ |
653 | 0 | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DH_GENERATOR); |
654 | 0 | if (p != NULL) { |
655 | 0 | ERR_raise(ERR_LIB_PROV, ERR_R_UNSUPPORTED); |
656 | 0 | return 0; |
657 | 0 | } |
658 | 0 | return 1; |
659 | 0 | } |
660 | | |
661 | | static int dh_gen_set_params(void *genctx, const OSSL_PARAM params[]) |
662 | 3.51k | { |
663 | 3.51k | struct dh_gen_ctx *gctx = genctx; |
664 | 3.51k | const OSSL_PARAM *p; |
665 | | |
666 | 3.51k | if (!dh_gen_common_set_params(genctx, params)) |
667 | 0 | return 0; |
668 | | |
669 | 3.51k | p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DH_GENERATOR); |
670 | 3.51k | if (p != NULL && !OSSL_PARAM_get_int(p, &gctx->generator)) |
671 | 0 | return 0; |
672 | | |
673 | | /* Parameters that are not allowed for DH */ |
674 | 3.51k | if (OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_GINDEX) != NULL |
675 | 3.51k | || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_PCOUNTER) != NULL |
676 | 3.51k | || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_H) != NULL |
677 | 3.51k | || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_SEED) != NULL |
678 | 3.51k | || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_QBITS) != NULL |
679 | 3.51k | || OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST) != NULL |
680 | 3.51k | || OSSL_PARAM_locate_const(params, |
681 | 3.51k | OSSL_PKEY_PARAM_FFC_DIGEST_PROPS) |
682 | 3.51k | != NULL) { |
683 | 0 | ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); |
684 | 0 | return 0; |
685 | 0 | } |
686 | 3.51k | return 1; |
687 | 3.51k | } |
688 | | |
689 | | static int dh_gencb(int p, int n, BN_GENCB *cb) |
690 | 0 | { |
691 | 0 | struct dh_gen_ctx *gctx = BN_GENCB_get_arg(cb); |
692 | 0 | OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END, OSSL_PARAM_END }; |
693 | |
|
694 | 0 | params[0] = OSSL_PARAM_construct_int(OSSL_GEN_PARAM_POTENTIAL, &p); |
695 | 0 | params[1] = OSSL_PARAM_construct_int(OSSL_GEN_PARAM_ITERATION, &n); |
696 | |
|
697 | 0 | return gctx->cb(params, gctx->cbarg); |
698 | 0 | } |
699 | | |
700 | | static void *dh_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg) |
701 | 7.34k | { |
702 | 7.34k | int ret = 0; |
703 | 7.34k | struct dh_gen_ctx *gctx = genctx; |
704 | 7.34k | DH *dh = NULL; |
705 | 7.34k | BN_GENCB *gencb = NULL; |
706 | 7.34k | FFC_PARAMS *ffc; |
707 | | |
708 | 7.34k | if (!ossl_prov_is_running() || gctx == NULL) |
709 | 0 | return NULL; |
710 | | |
711 | | /* |
712 | | * If a group name is selected then the type is group regardless of what |
713 | | * the user selected. This overrides rather than errors for backwards |
714 | | * compatibility. |
715 | | */ |
716 | 7.34k | if (gctx->group_nid != NID_undef) |
717 | 2.86k | gctx->gen_type = DH_PARAMGEN_TYPE_GROUP; |
718 | | |
719 | | /* |
720 | | * Do a bounds check on context gen_type. Must be in range: |
721 | | * DH_PARAMGEN_TYPE_GENERATOR <= gen_type <= DH_PARAMGEN_TYPE_GROUP |
722 | | * Noted here as this needs to be adjusted if a new group type is |
723 | | * added. |
724 | | */ |
725 | 7.34k | if (!ossl_assert((gctx->gen_type >= DH_PARAMGEN_TYPE_GENERATOR) |
726 | 7.34k | && (gctx->gen_type <= DH_PARAMGEN_TYPE_GROUP))) { |
727 | 0 | ERR_raise_data(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR, |
728 | 0 | "gen_type set to unsupported value %d", gctx->gen_type); |
729 | 0 | return NULL; |
730 | 0 | } |
731 | | |
732 | | /* For parameter generation - If there is a group name just create it */ |
733 | 7.34k | if (gctx->gen_type == DH_PARAMGEN_TYPE_GROUP |
734 | 2.86k | && gctx->ffc_params == NULL) { |
735 | | /* Select a named group if there is not one already */ |
736 | 2.86k | if (gctx->group_nid == NID_undef) |
737 | 0 | gctx->group_nid = ossl_dh_get_named_group_uid_from_size((int)gctx->pbits); |
738 | 2.86k | if (gctx->group_nid == NID_undef) |
739 | 0 | return NULL; |
740 | 2.86k | dh = ossl_dh_new_by_nid_ex(gctx->libctx, gctx->group_nid); |
741 | 2.86k | if (dh == NULL) |
742 | 0 | return NULL; |
743 | 2.86k | ffc = ossl_dh_get0_params(dh); |
744 | 4.48k | } else { |
745 | 4.48k | dh = ossl_dh_new_ex(gctx->libctx); |
746 | 4.48k | if (dh == NULL) |
747 | 0 | return NULL; |
748 | 4.48k | ffc = ossl_dh_get0_params(dh); |
749 | | |
750 | | /* Copy the template value if one was passed */ |
751 | 4.48k | if (gctx->ffc_params != NULL |
752 | 4.48k | && !ossl_ffc_params_copy(ffc, gctx->ffc_params)) |
753 | 0 | goto end; |
754 | | |
755 | 4.48k | if (!ossl_ffc_params_set_seed(ffc, gctx->seed, gctx->seedlen)) |
756 | 0 | goto end; |
757 | 4.48k | if (gctx->gindex != -1) { |
758 | 0 | ossl_ffc_params_set_gindex(ffc, gctx->gindex); |
759 | 0 | if (gctx->pcounter != -1) |
760 | 0 | ossl_ffc_params_set_pcounter(ffc, gctx->pcounter); |
761 | 4.48k | } else if (gctx->hindex != 0) { |
762 | 0 | ossl_ffc_params_set_h(ffc, gctx->hindex); |
763 | 0 | } |
764 | 4.48k | if (gctx->mdname != NULL) |
765 | 0 | ossl_ffc_set_digest(ffc, gctx->mdname, gctx->mdprops); |
766 | 4.48k | gctx->cb = osslcb; |
767 | 4.48k | gctx->cbarg = cbarg; |
768 | 4.48k | gencb = BN_GENCB_new(); |
769 | 4.48k | if (gencb != NULL) |
770 | 4.48k | BN_GENCB_set(gencb, dh_gencb, genctx); |
771 | | |
772 | 4.48k | if ((gctx->selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) { |
773 | | /* |
774 | | * NOTE: The old safe prime generator code is not used in fips mode, |
775 | | * (i.e internally it ignores the generator and chooses a named |
776 | | * group based on pbits. |
777 | | */ |
778 | 0 | if (gctx->gen_type == DH_PARAMGEN_TYPE_GENERATOR) |
779 | 0 | ret = DH_generate_parameters_ex(dh, (int)gctx->pbits, |
780 | 0 | gctx->generator, gencb); |
781 | 0 | else |
782 | 0 | ret = ossl_dh_generate_ffc_parameters(dh, gctx->gen_type, |
783 | 0 | (int)gctx->pbits, |
784 | 0 | (int)gctx->qbits, gencb); |
785 | 0 | if (ret <= 0) |
786 | 0 | goto end; |
787 | 0 | } |
788 | 4.48k | } |
789 | | |
790 | 7.34k | if ((gctx->selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { |
791 | 6.39k | if (ffc->p == NULL || ffc->g == NULL) |
792 | 0 | goto end; |
793 | 6.39k | if (gctx->priv_len > 0) |
794 | 0 | DH_set_length(dh, (long)gctx->priv_len); |
795 | 6.39k | ossl_ffc_params_enable_flags(ffc, FFC_PARAM_FLAG_VALIDATE_LEGACY, |
796 | 6.39k | gctx->gen_type == DH_PARAMGEN_TYPE_FIPS_186_2); |
797 | 6.39k | if (DH_generate_key(dh) <= 0) |
798 | 0 | goto end; |
799 | | #ifdef FIPS_MODULE |
800 | | if (!ossl_fips_self_testing()) { |
801 | | ret = ossl_dh_check_pairwise(dh, 0); |
802 | | if (ret <= 0) |
803 | | goto end; |
804 | | } |
805 | | #endif /* FIPS_MODULE */ |
806 | 6.39k | } |
807 | 7.34k | DH_clear_flags(dh, DH_FLAG_TYPE_MASK); |
808 | 7.34k | DH_set_flags(dh, gctx->dh_type); |
809 | | |
810 | 7.34k | ret = 1; |
811 | 7.34k | end: |
812 | 7.34k | if (ret <= 0) { |
813 | 0 | DH_free(dh); |
814 | 0 | dh = NULL; |
815 | 0 | } |
816 | 7.34k | BN_GENCB_free(gencb); |
817 | 7.34k | return dh; |
818 | 7.34k | } |
819 | | |
820 | | static void dh_gen_cleanup(void *genctx) |
821 | 7.34k | { |
822 | 7.34k | struct dh_gen_ctx *gctx = genctx; |
823 | | |
824 | 7.34k | if (gctx == NULL) |
825 | 0 | return; |
826 | | |
827 | 7.34k | OPENSSL_free(gctx->mdname); |
828 | 7.34k | OPENSSL_free(gctx->mdprops); |
829 | 7.34k | OPENSSL_clear_free(gctx->seed, gctx->seedlen); |
830 | 7.34k | OPENSSL_free(gctx); |
831 | 7.34k | } |
832 | | |
833 | | static void *dh_load(const void *reference, size_t reference_sz) |
834 | 53.9k | { |
835 | 53.9k | DH *dh = NULL; |
836 | | |
837 | 53.9k | if (ossl_prov_is_running() && reference_sz == sizeof(dh)) { |
838 | | /* The contents of the reference is the address to our object */ |
839 | 53.9k | dh = *(DH **)reference; |
840 | | /* We grabbed, so we detach it */ |
841 | 53.9k | *(DH **)reference = NULL; |
842 | 53.9k | return dh; |
843 | 53.9k | } |
844 | 0 | return NULL; |
845 | 53.9k | } |
846 | | |
847 | | static void *dh_dup(const void *keydata_from, int selection) |
848 | 7.51k | { |
849 | 7.51k | if (ossl_prov_is_running()) |
850 | 7.51k | return ossl_dh_dup(keydata_from, selection); |
851 | 0 | return NULL; |
852 | 7.51k | } |
853 | | |
854 | | const OSSL_DISPATCH ossl_dh_keymgmt_functions[] = { |
855 | | { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))dh_newdata }, |
856 | | { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))dh_gen_init }, |
857 | | { OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE, (void (*)(void))dh_gen_set_template }, |
858 | | { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))dh_gen_set_params }, |
859 | | { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS, |
860 | | (void (*)(void))dh_gen_settable_params }, |
861 | | { OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))dh_gen }, |
862 | | { OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))dh_gen_cleanup }, |
863 | | { OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))dh_load }, |
864 | | { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))dh_freedata }, |
865 | | { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))dh_get_params }, |
866 | | { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))dh_gettable_params }, |
867 | | { OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))dh_set_params }, |
868 | | { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*)(void))dh_settable_params }, |
869 | | { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))dh_has }, |
870 | | { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))dh_match }, |
871 | | { OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))dh_validate }, |
872 | | { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))dh_import }, |
873 | | { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))dh_import_types }, |
874 | | { OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))dh_export }, |
875 | | { OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))dh_export_types }, |
876 | | { OSSL_FUNC_KEYMGMT_DUP, (void (*)(void))dh_dup }, |
877 | | OSSL_KEYMGMT_FIPS_APPROVED_GEN_DISPATCH_END |
878 | | }; |
879 | | |
880 | | /* For any DH key, we use the "DH" algorithms regardless of sub-type. */ |
881 | | static const char *dhx_query_operation_name(int operation_id) |
882 | 31 | { |
883 | 31 | return "DH"; |
884 | 31 | } |
885 | | |
886 | | const OSSL_DISPATCH ossl_dhx_keymgmt_functions[] = { |
887 | | { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))dhx_newdata }, |
888 | | { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))dhx_gen_init }, |
889 | | { OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE, (void (*)(void))dh_gen_set_template }, |
890 | | { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))dhx_gen_set_params }, |
891 | | { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS, |
892 | | (void (*)(void))dhx_gen_settable_params }, |
893 | | { OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))dh_gen }, |
894 | | { OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))dh_gen_cleanup }, |
895 | | { OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))dh_load }, |
896 | | { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))dh_freedata }, |
897 | | { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))dh_get_params }, |
898 | | { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))dh_gettable_params }, |
899 | | { OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))dh_set_params }, |
900 | | { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*)(void))dh_settable_params }, |
901 | | { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))dh_has }, |
902 | | { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))dh_match }, |
903 | | { OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))dh_validate }, |
904 | | { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))dh_import }, |
905 | | { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))dh_import_types }, |
906 | | { OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))dh_export }, |
907 | | { OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))dh_export_types }, |
908 | | { OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME, |
909 | | (void (*)(void))dhx_query_operation_name }, |
910 | | { OSSL_FUNC_KEYMGMT_DUP, (void (*)(void))dh_dup }, |
911 | | OSSL_KEYMGMT_FIPS_APPROVED_GEN_DISPATCH_END |
912 | | }; |