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