2 * Copyright 2019-2021 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
11 * RSA low level APIs are deprecated for public use, but still ok for
14 #include "internal/deprecated.h"
16 #include <openssl/core_dispatch.h>
17 #include <openssl/core_names.h>
18 #include <openssl/bn.h>
19 #include <openssl/err.h>
20 #include <openssl/rsa.h>
21 #include <openssl/evp.h>
22 #include "prov/implementations.h"
23 #include "prov/providercommon.h"
24 #include "prov/provider_ctx.h"
25 #include "crypto/rsa.h"
26 #include "crypto/cryptlib.h"
27 #include "internal/param_build_set.h"
29 static OSSL_FUNC_keymgmt_new_fn rsa_newdata
;
30 static OSSL_FUNC_keymgmt_new_fn rsapss_newdata
;
31 static OSSL_FUNC_keymgmt_gen_init_fn rsa_gen_init
;
32 static OSSL_FUNC_keymgmt_gen_init_fn rsapss_gen_init
;
33 static OSSL_FUNC_keymgmt_gen_set_params_fn rsa_gen_set_params
;
34 static OSSL_FUNC_keymgmt_gen_settable_params_fn rsa_gen_settable_params
;
35 static OSSL_FUNC_keymgmt_gen_settable_params_fn rsapss_gen_settable_params
;
36 static OSSL_FUNC_keymgmt_gen_fn rsa_gen
;
37 static OSSL_FUNC_keymgmt_gen_cleanup_fn rsa_gen_cleanup
;
38 static OSSL_FUNC_keymgmt_load_fn rsa_load
;
39 static OSSL_FUNC_keymgmt_free_fn rsa_freedata
;
40 static OSSL_FUNC_keymgmt_get_params_fn rsa_get_params
;
41 static OSSL_FUNC_keymgmt_gettable_params_fn rsa_gettable_params
;
42 static OSSL_FUNC_keymgmt_has_fn rsa_has
;
43 static OSSL_FUNC_keymgmt_match_fn rsa_match
;
44 static OSSL_FUNC_keymgmt_validate_fn rsa_validate
;
45 static OSSL_FUNC_keymgmt_import_fn rsa_import
;
46 static OSSL_FUNC_keymgmt_import_types_fn rsa_import_types
;
47 static OSSL_FUNC_keymgmt_export_fn rsa_export
;
48 static OSSL_FUNC_keymgmt_export_types_fn rsa_export_types
;
49 static OSSL_FUNC_keymgmt_query_operation_name_fn rsa_query_operation_name
;
51 #define RSA_DEFAULT_MD "SHA256"
52 #define RSA_PSS_DEFAULT_MD OSSL_DIGEST_NAME_SHA1
53 #define RSA_POSSIBLE_SELECTIONS \
54 (OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS)
56 DEFINE_STACK_OF(BIGNUM
)
57 DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const
, BIGNUM
)
59 static int pss_params_fromdata(RSA_PSS_PARAMS_30
*pss_params
, int *defaults_set
,
60 const OSSL_PARAM params
[], int rsa_type
,
63 if (!ossl_rsa_pss_params_30_fromdata(pss_params
, defaults_set
,
67 /* If not a PSS type RSA, sending us PSS parameters is wrong */
68 if (rsa_type
!= RSA_FLAG_TYPE_RSASSAPSS
69 && !ossl_rsa_pss_params_30_is_unrestricted(pss_params
))
75 static void *rsa_newdata(void *provctx
)
77 OSSL_LIB_CTX
*libctx
= PROV_LIBCTX_OF(provctx
);
80 if (!ossl_prov_is_running())
83 rsa
= ossl_rsa_new_with_ctx(libctx
);
85 RSA_clear_flags(rsa
, RSA_FLAG_TYPE_MASK
);
86 RSA_set_flags(rsa
, RSA_FLAG_TYPE_RSA
);
91 static void *rsapss_newdata(void *provctx
)
93 OSSL_LIB_CTX
*libctx
= PROV_LIBCTX_OF(provctx
);
96 if (!ossl_prov_is_running())
99 rsa
= ossl_rsa_new_with_ctx(libctx
);
101 RSA_clear_flags(rsa
, RSA_FLAG_TYPE_MASK
);
102 RSA_set_flags(rsa
, RSA_FLAG_TYPE_RSASSAPSS
);
107 static void rsa_freedata(void *keydata
)
112 static int rsa_has(const void *keydata
, int selection
)
114 const RSA
*rsa
= keydata
;
117 if (rsa
!= NULL
&& ossl_prov_is_running()) {
118 if ((selection
& RSA_POSSIBLE_SELECTIONS
) != 0)
121 if ((selection
& OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS
) != 0)
122 /* This will change with OAEP */
123 ok
= ok
&& (RSA_test_flags(rsa
, RSA_FLAG_TYPE_RSASSAPSS
) != 0);
124 if ((selection
& OSSL_KEYMGMT_SELECT_KEYPAIR
) != 0)
125 ok
= ok
&& (RSA_get0_e(rsa
) != NULL
);
126 if ((selection
& OSSL_KEYMGMT_SELECT_PUBLIC_KEY
) != 0)
127 ok
= ok
&& (RSA_get0_n(rsa
) != NULL
);
128 if ((selection
& OSSL_KEYMGMT_SELECT_PRIVATE_KEY
) != 0)
129 ok
= ok
&& (RSA_get0_d(rsa
) != NULL
);
134 static int rsa_match(const void *keydata1
, const void *keydata2
, int selection
)
136 const RSA
*rsa1
= keydata1
;
137 const RSA
*rsa2
= keydata2
;
140 if (!ossl_prov_is_running())
143 /* There is always an |e| */
144 ok
= ok
&& BN_cmp(RSA_get0_e(rsa1
), RSA_get0_e(rsa2
)) == 0;
145 if ((selection
& OSSL_KEYMGMT_SELECT_PUBLIC_KEY
) != 0)
146 ok
= ok
&& BN_cmp(RSA_get0_n(rsa1
), RSA_get0_n(rsa2
)) == 0;
147 if ((selection
& OSSL_KEYMGMT_SELECT_PRIVATE_KEY
) != 0)
148 ok
= ok
&& BN_cmp(RSA_get0_d(rsa1
), RSA_get0_d(rsa2
)) == 0;
152 static int rsa_import(void *keydata
, int selection
, const OSSL_PARAM params
[])
157 int pss_defaults_set
= 0;
159 if (!ossl_prov_is_running() || rsa
== NULL
)
162 if ((selection
& RSA_POSSIBLE_SELECTIONS
) == 0)
165 rsa_type
= RSA_test_flags(rsa
, RSA_FLAG_TYPE_MASK
);
167 /* TODO(3.0) OAEP should bring on parameters as well */
169 if ((selection
& OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS
) != 0)
170 ok
= ok
&& pss_params_fromdata(ossl_rsa_get0_pss_params_30(rsa
),
173 ossl_rsa_get0_libctx(rsa
));
174 if ((selection
& OSSL_KEYMGMT_SELECT_KEYPAIR
) != 0)
175 ok
= ok
&& ossl_rsa_fromdata(rsa
, params
);
180 static int rsa_export(void *keydata
, int selection
,
181 OSSL_CALLBACK
*param_callback
, void *cbarg
)
184 const RSA_PSS_PARAMS_30
*pss_params
= ossl_rsa_get0_pss_params_30(rsa
);
185 OSSL_PARAM_BLD
*tmpl
;
186 OSSL_PARAM
*params
= NULL
;
189 if (!ossl_prov_is_running() || rsa
== NULL
)
192 /* TODO(3.0) OAEP should bring on parameters */
194 tmpl
= OSSL_PARAM_BLD_new();
198 if ((selection
& OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS
) != 0)
199 ok
= ok
&& (ossl_rsa_pss_params_30_is_unrestricted(pss_params
)
200 || ossl_rsa_pss_params_30_todata(pss_params
, tmpl
, NULL
));
201 if ((selection
& OSSL_KEYMGMT_SELECT_KEYPAIR
) != 0)
202 ok
= ok
&& ossl_rsa_todata(rsa
, tmpl
, NULL
);
205 || (params
= OSSL_PARAM_BLD_to_param(tmpl
)) == NULL
)
208 ok
= param_callback(params
, cbarg
);
209 OSSL_PARAM_BLD_free_params(params
);
211 OSSL_PARAM_BLD_free(tmpl
);
216 /* In fips mode there are no multi-primes. */
217 # define RSA_KEY_MP_TYPES() \
218 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR1, NULL, 0), \
219 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR2, NULL, 0), \
220 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT1, NULL, 0), \
221 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT2, NULL, 0), \
222 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT1, NULL, 0),
225 * We allow up to 10 prime factors (starting with p, q).
226 * NOTE: there is only 9 OSSL_PKEY_PARAM_RSA_COEFFICIENT
228 # define RSA_KEY_MP_TYPES() \
229 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR1, NULL, 0), \
230 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR2, NULL, 0), \
231 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR3, NULL, 0), \
232 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR4, NULL, 0), \
233 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR5, NULL, 0), \
234 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR6, NULL, 0), \
235 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR7, NULL, 0), \
236 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR8, NULL, 0), \
237 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR9, NULL, 0), \
238 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR10, NULL, 0), \
239 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT1, NULL, 0), \
240 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT2, NULL, 0), \
241 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT3, NULL, 0), \
242 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT4, NULL, 0), \
243 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT5, NULL, 0), \
244 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT6, NULL, 0), \
245 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT7, NULL, 0), \
246 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT8, NULL, 0), \
247 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT9, NULL, 0), \
248 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT10, NULL, 0), \
249 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT1, NULL, 0), \
250 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT2, NULL, 0), \
251 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT3, NULL, 0), \
252 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT4, NULL, 0), \
253 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT5, NULL, 0), \
254 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT6, NULL, 0), \
255 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT7, NULL, 0), \
256 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT8, NULL, 0), \
257 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT9, NULL, 0),
260 #define RSA_KEY_TYPES() \
261 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_N, NULL, 0), \
262 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0), \
263 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_D, NULL, 0), \
267 * This provider can export everything in an RSA key, so we use the exact
268 * same type description for export as for import. Other providers might
269 * choose to import full keys, but only export the public parts, and will
270 * therefore have the importkey_types and importkey_types functions return
273 static const OSSL_PARAM rsa_key_types
[] = {
278 * We lied about the amount of factors, exponents and coefficients, the
279 * export and import functions can really deal with an infinite amount
280 * of these numbers. However, RSA keys with too many primes are futile,
281 * so we at least pretend to have some limits.
284 static const OSSL_PARAM
*rsa_imexport_types(int selection
)
286 if ((selection
& OSSL_KEYMGMT_SELECT_KEYPAIR
) != 0)
287 return rsa_key_types
;
291 static const OSSL_PARAM
*rsa_import_types(int selection
)
293 return rsa_imexport_types(selection
);
296 static const OSSL_PARAM
*rsa_export_types(int selection
)
298 return rsa_imexport_types(selection
);
301 static int rsa_get_params(void *key
, OSSL_PARAM params
[])
304 const RSA_PSS_PARAMS_30
*pss_params
= ossl_rsa_get0_pss_params_30(rsa
);
305 int rsa_type
= RSA_test_flags(rsa
, RSA_FLAG_TYPE_MASK
);
308 if ((p
= OSSL_PARAM_locate(params
, OSSL_PKEY_PARAM_BITS
)) != NULL
309 && !OSSL_PARAM_set_int(p
, RSA_bits(rsa
)))
311 if ((p
= OSSL_PARAM_locate(params
, OSSL_PKEY_PARAM_SECURITY_BITS
)) != NULL
312 && !OSSL_PARAM_set_int(p
, RSA_security_bits(rsa
)))
314 if ((p
= OSSL_PARAM_locate(params
, OSSL_PKEY_PARAM_MAX_SIZE
)) != NULL
315 && !OSSL_PARAM_set_int(p
, RSA_size(rsa
)))
319 * For restricted RSA-PSS keys, we ignore the default digest request.
320 * With RSA-OAEP keys, this may need to be amended.
322 if ((p
= OSSL_PARAM_locate(params
, OSSL_PKEY_PARAM_DEFAULT_DIGEST
)) != NULL
323 && (rsa_type
!= RSA_FLAG_TYPE_RSASSAPSS
324 || ossl_rsa_pss_params_30_is_unrestricted(pss_params
))) {
325 if (!OSSL_PARAM_set_utf8_string(p
, RSA_DEFAULT_MD
))
330 * For non-RSA-PSS keys, we ignore the mandatory digest request.
331 * With RSA-OAEP keys, this may need to be amended.
333 if ((p
= OSSL_PARAM_locate(params
,
334 OSSL_PKEY_PARAM_MANDATORY_DIGEST
)) != NULL
335 && rsa_type
== RSA_FLAG_TYPE_RSASSAPSS
336 && !ossl_rsa_pss_params_30_is_unrestricted(pss_params
)) {
338 ossl_rsa_oaeppss_nid2name(ossl_rsa_pss_params_30_hashalg(pss_params
));
340 if (mdname
== NULL
|| !OSSL_PARAM_set_utf8_string(p
, mdname
))
343 return (rsa_type
!= RSA_FLAG_TYPE_RSASSAPSS
344 || ossl_rsa_pss_params_30_todata(pss_params
, NULL
, params
))
345 && ossl_rsa_todata(rsa
, NULL
, params
);
348 static const OSSL_PARAM rsa_params
[] = {
349 OSSL_PARAM_int(OSSL_PKEY_PARAM_BITS
, NULL
),
350 OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_BITS
, NULL
),
351 OSSL_PARAM_int(OSSL_PKEY_PARAM_MAX_SIZE
, NULL
),
352 OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_DEFAULT_DIGEST
, NULL
, 0),
357 static const OSSL_PARAM
*rsa_gettable_params(void *provctx
)
362 static int rsa_validate(const void *keydata
, int selection
, int checktype
)
364 const RSA
*rsa
= keydata
;
367 if (!ossl_prov_is_running())
370 if ((selection
& RSA_POSSIBLE_SELECTIONS
) != 0)
373 /* If the whole key is selected, we do a pairwise validation */
374 if ((selection
& OSSL_KEYMGMT_SELECT_KEYPAIR
)
375 == OSSL_KEYMGMT_SELECT_KEYPAIR
) {
376 ok
= ok
&& ossl_rsa_validate_pairwise(rsa
);
378 if ((selection
& OSSL_KEYMGMT_SELECT_PRIVATE_KEY
) != 0)
379 ok
= ok
&& ossl_rsa_validate_private(rsa
);
380 if ((selection
& OSSL_KEYMGMT_SELECT_PUBLIC_KEY
) != 0)
381 ok
= ok
&& ossl_rsa_validate_public(rsa
);
387 OSSL_LIB_CTX
*libctx
;
397 RSA_PSS_PARAMS_30 pss_params
;
398 int pss_defaults_set
;
400 /* For generation callback */
404 #if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS)
405 /* ACVP test parameters */
406 OSSL_PARAM
*acvp_test_params
;
410 static int rsa_gencb(int p
, int n
, BN_GENCB
*cb
)
412 struct rsa_gen_ctx
*gctx
= BN_GENCB_get_arg(cb
);
413 OSSL_PARAM params
[] = { OSSL_PARAM_END
, OSSL_PARAM_END
, OSSL_PARAM_END
};
415 params
[0] = OSSL_PARAM_construct_int(OSSL_GEN_PARAM_POTENTIAL
, &p
);
416 params
[1] = OSSL_PARAM_construct_int(OSSL_GEN_PARAM_ITERATION
, &n
);
417 return gctx
->cb(params
, gctx
->cbarg
);
420 static void *gen_init(void *provctx
, int selection
, int rsa_type
)
422 OSSL_LIB_CTX
*libctx
= PROV_LIBCTX_OF(provctx
);
423 struct rsa_gen_ctx
*gctx
= NULL
;
425 if (!ossl_prov_is_running())
428 if ((selection
& OSSL_KEYMGMT_SELECT_KEYPAIR
) == 0)
431 if ((gctx
= OPENSSL_zalloc(sizeof(*gctx
))) != NULL
) {
432 gctx
->libctx
= libctx
;
433 if ((gctx
->pub_exp
= BN_new()) == NULL
434 || !BN_set_word(gctx
->pub_exp
, RSA_F4
)) {
435 BN_free(gctx
->pub_exp
);
440 gctx
->primes
= RSA_DEFAULT_PRIME_NUM
;
441 gctx
->rsa_type
= rsa_type
;
447 static void *rsa_gen_init(void *provctx
, int selection
)
449 return gen_init(provctx
, selection
, RSA_FLAG_TYPE_RSA
);
452 static void *rsapss_gen_init(void *provctx
, int selection
)
454 return gen_init(provctx
, selection
, RSA_FLAG_TYPE_RSASSAPSS
);
458 * This function is common for all RSA sub-types, to detect possible
459 * misuse, such as PSS parameters being passed when a plain RSA key
462 static int rsa_gen_set_params(void *genctx
, const OSSL_PARAM params
[])
464 struct rsa_gen_ctx
*gctx
= genctx
;
467 if ((p
= OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_BITS
)) != NULL
468 && !OSSL_PARAM_get_size_t(p
, &gctx
->nbits
))
470 if ((p
= OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_PRIMES
)) != NULL
471 && !OSSL_PARAM_get_size_t(p
, &gctx
->primes
))
473 if ((p
= OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_E
)) != NULL
474 && !OSSL_PARAM_get_BN(p
, &gctx
->pub_exp
))
476 /* Only attempt to get PSS parameters when generating an RSA-PSS key */
477 if (gctx
->rsa_type
== RSA_FLAG_TYPE_RSASSAPSS
478 && !pss_params_fromdata(&gctx
->pss_params
, &gctx
->pss_defaults_set
, params
,
479 gctx
->rsa_type
, gctx
->libctx
))
481 #if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS)
482 /* Any ACVP test related parameters are copied into a params[] */
483 if (!rsa_acvp_test_gen_params_new(&gctx
->acvp_test_params
, params
))
489 #define rsa_gen_basic \
490 OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_BITS, NULL), \
491 OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_PRIMES, NULL), \
492 OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0)
495 * The following must be kept in sync with ossl_rsa_pss_params_30_fromdata()
496 * in crypto/rsa/rsa_backend.c
498 #define rsa_gen_pss \
499 OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_DIGEST, NULL, 0), \
500 OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_DIGEST_PROPS, NULL, 0), \
501 OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_MASKGENFUNC, NULL, 0), \
502 OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_MGF1_DIGEST, NULL, 0), \
503 OSSL_PARAM_int(OSSL_PKEY_PARAM_RSA_PSS_SALTLEN, NULL)
505 static const OSSL_PARAM
*rsa_gen_settable_params(void *provctx
)
507 static OSSL_PARAM settable
[] = {
515 static const OSSL_PARAM
*rsapss_gen_settable_params(void *provctx
)
517 static OSSL_PARAM settable
[] = {
526 static void *rsa_gen(void *genctx
, OSSL_CALLBACK
*osslcb
, void *cbarg
)
528 struct rsa_gen_ctx
*gctx
= genctx
;
529 RSA
*rsa
= NULL
, *rsa_tmp
= NULL
;
530 BN_GENCB
*gencb
= NULL
;
532 if (!ossl_prov_is_running() || gctx
== NULL
)
535 switch (gctx
->rsa_type
) {
536 case RSA_FLAG_TYPE_RSA
:
537 /* For plain RSA keys, PSS parameters must not be set */
538 if (!ossl_rsa_pss_params_30_is_unrestricted(&gctx
->pss_params
))
541 case RSA_FLAG_TYPE_RSASSAPSS
:
543 * For plain RSA-PSS keys, PSS parameters may be set but don't have
548 /* Unsupported RSA key sub-type... */
552 if ((rsa_tmp
= ossl_rsa_new_with_ctx(gctx
->libctx
)) == NULL
)
557 gencb
= BN_GENCB_new();
559 BN_GENCB_set(gencb
, rsa_gencb
, genctx
);
561 #if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS)
562 if (gctx
->acvp_test_params
!= NULL
) {
563 if (!rsa_acvp_test_set_params(rsa_tmp
, gctx
->acvp_test_params
))
568 if (!RSA_generate_multi_prime_key(rsa_tmp
,
569 (int)gctx
->nbits
, (int)gctx
->primes
,
570 gctx
->pub_exp
, gencb
))
573 if (!ossl_rsa_pss_params_30_copy(ossl_rsa_get0_pss_params_30(rsa_tmp
),
577 RSA_clear_flags(rsa_tmp
, RSA_FLAG_TYPE_MASK
);
578 RSA_set_flags(rsa_tmp
, gctx
->rsa_type
);
583 BN_GENCB_free(gencb
);
588 static void rsa_gen_cleanup(void *genctx
)
590 struct rsa_gen_ctx
*gctx
= genctx
;
594 #if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS)
595 rsa_acvp_test_gen_params_free(gctx
->acvp_test_params
);
596 gctx
->acvp_test_params
= NULL
;
598 BN_clear_free(gctx
->pub_exp
);
602 void *rsa_load(const void *reference
, size_t reference_sz
)
606 if (ossl_prov_is_running() && reference_sz
== sizeof(rsa
)) {
607 /* The contents of the reference is the address to our object */
608 rsa
= *(RSA
**)reference
;
609 /* We grabbed, so we detach it */
610 *(RSA
**)reference
= NULL
;
616 /* For any RSA key, we use the "RSA" algorithms regardless of sub-type. */
617 static const char *rsa_query_operation_name(int operation_id
)
622 const OSSL_DISPATCH ossl_rsa_keymgmt_functions
[] = {
623 { OSSL_FUNC_KEYMGMT_NEW
, (void (*)(void))rsa_newdata
},
624 { OSSL_FUNC_KEYMGMT_GEN_INIT
, (void (*)(void))rsa_gen_init
},
625 { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS
,
626 (void (*)(void))rsa_gen_set_params
},
627 { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS
,
628 (void (*)(void))rsa_gen_settable_params
},
629 { OSSL_FUNC_KEYMGMT_GEN
, (void (*)(void))rsa_gen
},
630 { OSSL_FUNC_KEYMGMT_GEN_CLEANUP
, (void (*)(void))rsa_gen_cleanup
},
631 { OSSL_FUNC_KEYMGMT_LOAD
, (void (*)(void))rsa_load
},
632 { OSSL_FUNC_KEYMGMT_FREE
, (void (*)(void))rsa_freedata
},
633 { OSSL_FUNC_KEYMGMT_GET_PARAMS
, (void (*) (void))rsa_get_params
},
634 { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS
, (void (*) (void))rsa_gettable_params
},
635 { OSSL_FUNC_KEYMGMT_HAS
, (void (*)(void))rsa_has
},
636 { OSSL_FUNC_KEYMGMT_MATCH
, (void (*)(void))rsa_match
},
637 { OSSL_FUNC_KEYMGMT_VALIDATE
, (void (*)(void))rsa_validate
},
638 { OSSL_FUNC_KEYMGMT_IMPORT
, (void (*)(void))rsa_import
},
639 { OSSL_FUNC_KEYMGMT_IMPORT_TYPES
, (void (*)(void))rsa_import_types
},
640 { OSSL_FUNC_KEYMGMT_EXPORT
, (void (*)(void))rsa_export
},
641 { OSSL_FUNC_KEYMGMT_EXPORT_TYPES
, (void (*)(void))rsa_export_types
},
645 const OSSL_DISPATCH ossl_rsapss_keymgmt_functions
[] = {
646 { OSSL_FUNC_KEYMGMT_NEW
, (void (*)(void))rsapss_newdata
},
647 { OSSL_FUNC_KEYMGMT_GEN_INIT
, (void (*)(void))rsapss_gen_init
},
648 { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS
, (void (*)(void))rsa_gen_set_params
},
649 { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS
,
650 (void (*)(void))rsapss_gen_settable_params
},
651 { OSSL_FUNC_KEYMGMT_GEN
, (void (*)(void))rsa_gen
},
652 { OSSL_FUNC_KEYMGMT_GEN_CLEANUP
, (void (*)(void))rsa_gen_cleanup
},
653 { OSSL_FUNC_KEYMGMT_LOAD
, (void (*)(void))rsa_load
},
654 { OSSL_FUNC_KEYMGMT_FREE
, (void (*)(void))rsa_freedata
},
655 { OSSL_FUNC_KEYMGMT_GET_PARAMS
, (void (*) (void))rsa_get_params
},
656 { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS
, (void (*) (void))rsa_gettable_params
},
657 { OSSL_FUNC_KEYMGMT_HAS
, (void (*)(void))rsa_has
},
658 { OSSL_FUNC_KEYMGMT_MATCH
, (void (*)(void))rsa_match
},
659 { OSSL_FUNC_KEYMGMT_VALIDATE
, (void (*)(void))rsa_validate
},
660 { OSSL_FUNC_KEYMGMT_IMPORT
, (void (*)(void))rsa_import
},
661 { OSSL_FUNC_KEYMGMT_IMPORT_TYPES
, (void (*)(void))rsa_import_types
},
662 { OSSL_FUNC_KEYMGMT_EXPORT
, (void (*)(void))rsa_export
},
663 { OSSL_FUNC_KEYMGMT_EXPORT_TYPES
, (void (*)(void))rsa_export_types
},
664 { OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME
,
665 (void (*)(void))rsa_query_operation_name
},