2 * Copyright 2020-2022 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"
17 #include <openssl/core_names.h>
18 #include <openssl/params.h>
19 #include <openssl/err.h>
20 #include <openssl/evp.h>
22 # include <openssl/x509.h>
23 # include "crypto/asn1.h"
25 #include "internal/sizes.h"
26 #include "internal/param_build_set.h"
27 #include "crypto/rsa.h"
28 #include "rsa_local.h"
31 * The intention with the "backend" source file is to offer backend support
32 * for legacy backends (EVP_PKEY_ASN1_METHOD and EVP_PKEY_METHOD) and provider
33 * implementations alike.
36 DEFINE_STACK_OF(BIGNUM
)
38 static int collect_numbers(STACK_OF(BIGNUM
) *numbers
,
39 const OSSL_PARAM params
[], const char *names
[])
41 const OSSL_PARAM
*p
= NULL
;
47 for (i
= 0; names
[i
] != NULL
; i
++) {
48 p
= OSSL_PARAM_locate_const(params
, names
[i
]);
52 if (!OSSL_PARAM_get_BN(p
, &tmp
))
54 if (sk_BIGNUM_push(numbers
, tmp
) == 0) {
64 int ossl_rsa_fromdata(RSA
*rsa
, const OSSL_PARAM params
[], int include_private
)
66 const OSSL_PARAM
*param_n
, *param_e
, *param_d
= NULL
;
67 const OSSL_PARAM
*param_p
, *param_q
= NULL
;
68 const OSSL_PARAM
*param_derive
= NULL
;
69 BIGNUM
*p
= NULL
, *q
= NULL
, *n
= NULL
, *e
= NULL
, *d
= NULL
;
70 STACK_OF(BIGNUM
) *factors
= NULL
, *exps
= NULL
, *coeffs
= NULL
;
72 int derive_from_pq
= 0;
78 param_n
= OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_N
);
79 param_e
= OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_E
);
81 if ((param_n
== NULL
|| !OSSL_PARAM_get_BN(param_n
, &n
))
82 || (param_e
== NULL
|| !OSSL_PARAM_get_BN(param_e
, &e
))) {
83 ERR_raise(ERR_LIB_RSA
, ERR_R_PASSED_NULL_PARAMETER
);
87 if (include_private
) {
89 param_derive
= OSSL_PARAM_locate_const(params
,
90 OSSL_PKEY_PARAM_RSA_DERIVE_FROM_PQ
);
91 if ((param_derive
!= NULL
)
92 && !OSSL_PARAM_get_int(param_derive
, &derive_from_pq
))
95 param_d
= OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_D
);
96 if (param_d
!= NULL
&& !OSSL_PARAM_get_BN(param_d
, &d
)) {
97 ERR_raise(ERR_LIB_RSA
, ERR_R_PASSED_NULL_PARAMETER
);
101 if (derive_from_pq
) {
102 ctx
= BN_CTX_new_ex(rsa
->libctx
);
106 /* we need at minimum p, q */
107 param_p
= OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_FACTOR1
);
108 param_q
= OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_FACTOR2
);
109 if ((param_p
== NULL
|| !OSSL_PARAM_get_BN(param_p
, &p
))
110 || (param_q
== NULL
|| !OSSL_PARAM_get_BN(param_q
, &q
))) {
111 ERR_raise(ERR_LIB_RSA
, ERR_R_PASSED_NULL_PARAMETER
);
118 is_private
= (d
!= NULL
);
120 if (!RSA_set0_key(rsa
, n
, e
, d
))
125 if (!collect_numbers(factors
= sk_BIGNUM_new_null(), params
,
126 ossl_rsa_mp_factor_names
)
127 || !collect_numbers(exps
= sk_BIGNUM_new_null(), params
,
128 ossl_rsa_mp_exp_names
)
129 || !collect_numbers(coeffs
= sk_BIGNUM_new_null(), params
,
130 ossl_rsa_mp_coeff_names
))
133 if (derive_from_pq
&& sk_BIGNUM_num(exps
) == 0
134 && sk_BIGNUM_num(coeffs
) == 0) {
136 * If we want to use crt to derive our exponents/coefficients, we
137 * need to have at least 2 factors
139 if (sk_BIGNUM_num(factors
) < 2) {
140 ERR_raise(ERR_LIB_RSA
, ERR_R_PASSED_NULL_PARAMETER
);
145 * if we have more than two factors, n and d must also have
148 if (sk_BIGNUM_num(factors
) > 2
149 && (param_n
== NULL
|| param_d
== NULL
)) {
150 ERR_raise(ERR_LIB_RSA
, ERR_R_PASSED_NULL_PARAMETER
);
154 /* build our exponents and coefficients here */
155 if (sk_BIGNUM_num(factors
) == 2) {
156 /* for 2 factors we can use the sp800 functions to do this */
157 if (!RSA_set0_factors(rsa
, sk_BIGNUM_value(factors
, 0),
158 sk_BIGNUM_value(factors
, 1))) {
159 ERR_raise(ERR_LIB_RSA
, ERR_R_INTERNAL_ERROR
);
163 * once consumed by RSA_set0_factors, pop those off the stack
164 * so we don't free them below
166 sk_BIGNUM_pop(factors
);
167 sk_BIGNUM_pop(factors
);
170 * Note: Because we only have 2 factors here, there will be no
171 * additional pinfo fields to hold additional factors, and
172 * since we set our key and 2 factors above we can skip
173 * the call to ossl_rsa_set0_all_params
175 if (!ossl_rsa_sp800_56b_derive_params_from_pq(rsa
,
178 ERR_raise(ERR_LIB_RSA
, ERR_R_INTERNAL_ERROR
);
184 * in the multiprime case we have to generate exps/coeffs here
185 * for each additional prime
187 if (!ossl_rsa_multiprime_derive(rsa
, RSA_bits(rsa
),
188 sk_BIGNUM_num(factors
),
189 rsa
->e
, factors
, exps
,
191 ERR_raise(ERR_LIB_RSA
, ERR_R_INTERNAL_ERROR
);
196 * Now we should have all our factors, exponents and
199 if (!ossl_rsa_set0_all_params(rsa
, factors
, exps
, coeffs
)) {
200 ERR_raise(ERR_LIB_RSA
, ERR_R_INTERNAL_ERROR
);
205 /* multiprime case is disallowed in FIPS mode, raise an error */
206 ERR_raise(ERR_LIB_RSA
, ERR_R_UNSUPPORTED
);
213 * It's ok if this private key just has n, e and d
214 * but only if we're not using derive_from_pq
216 if (sk_BIGNUM_num(factors
) != 0
217 && !ossl_rsa_set0_all_params(rsa
, factors
, exps
, coeffs
))
220 /* sanity check to ensure we used everything in our stacks */
221 if (sk_BIGNUM_num(factors
) != 0
222 || sk_BIGNUM_num(exps
) != 0
223 || sk_BIGNUM_num(coeffs
) != 0) {
224 ERR_raise_data(ERR_LIB_RSA
, ERR_R_INTERNAL_ERROR
,
225 "There are %d, %d, %d elements left on our factors, exps, coeffs stacks\n",
226 sk_BIGNUM_num(factors
), sk_BIGNUM_num(exps
),
227 sk_BIGNUM_num(coeffs
));
234 sk_BIGNUM_free(factors
);
235 sk_BIGNUM_free(exps
);
236 sk_BIGNUM_free(coeffs
);
244 sk_BIGNUM_pop_free(factors
, BN_clear_free
);
245 sk_BIGNUM_pop_free(exps
, BN_clear_free
);
246 sk_BIGNUM_pop_free(coeffs
, BN_clear_free
);
251 DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const
, BIGNUM
)
253 int ossl_rsa_todata(RSA
*rsa
, OSSL_PARAM_BLD
*bld
, OSSL_PARAM params
[],
257 const BIGNUM
*rsa_d
= NULL
, *rsa_n
= NULL
, *rsa_e
= NULL
;
258 STACK_OF(BIGNUM_const
) *factors
= sk_BIGNUM_const_new_null();
259 STACK_OF(BIGNUM_const
) *exps
= sk_BIGNUM_const_new_null();
260 STACK_OF(BIGNUM_const
) *coeffs
= sk_BIGNUM_const_new_null();
262 if (rsa
== NULL
|| factors
== NULL
|| exps
== NULL
|| coeffs
== NULL
)
265 RSA_get0_key(rsa
, &rsa_n
, &rsa_e
, &rsa_d
);
266 ossl_rsa_get0_all_params(rsa
, factors
, exps
, coeffs
);
268 if (!ossl_param_build_set_bn(bld
, params
, OSSL_PKEY_PARAM_RSA_N
, rsa_n
)
269 || !ossl_param_build_set_bn(bld
, params
, OSSL_PKEY_PARAM_RSA_E
, rsa_e
))
272 /* Check private key data integrity */
273 if (include_private
&& rsa_d
!= NULL
) {
275 if (!ossl_param_build_set_bn(bld
, params
, OSSL_PKEY_PARAM_RSA_D
,
277 || !ossl_param_build_set_multi_key_bn(bld
, params
,
278 ossl_rsa_mp_factor_names
,
280 || !ossl_param_build_set_multi_key_bn(bld
, params
,
281 ossl_rsa_mp_exp_names
, exps
)
282 || !ossl_param_build_set_multi_key_bn(bld
, params
,
283 ossl_rsa_mp_coeff_names
,
288 #if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS)
289 /* The acvp test results are not meant for export so check for bld == NULL */
291 ossl_rsa_acvp_test_get_params(rsa
, params
);
295 sk_BIGNUM_const_free(factors
);
296 sk_BIGNUM_const_free(exps
);
297 sk_BIGNUM_const_free(coeffs
);
301 int ossl_rsa_pss_params_30_todata(const RSA_PSS_PARAMS_30
*pss
,
302 OSSL_PARAM_BLD
*bld
, OSSL_PARAM params
[])
304 if (!ossl_rsa_pss_params_30_is_unrestricted(pss
)) {
305 int hashalg_nid
= ossl_rsa_pss_params_30_hashalg(pss
);
306 int maskgenalg_nid
= ossl_rsa_pss_params_30_maskgenalg(pss
);
307 int maskgenhashalg_nid
= ossl_rsa_pss_params_30_maskgenhashalg(pss
);
308 int saltlen
= ossl_rsa_pss_params_30_saltlen(pss
);
309 int default_hashalg_nid
= ossl_rsa_pss_params_30_hashalg(NULL
);
310 int default_maskgenalg_nid
= ossl_rsa_pss_params_30_maskgenalg(NULL
);
311 int default_maskgenhashalg_nid
=
312 ossl_rsa_pss_params_30_maskgenhashalg(NULL
);
314 (hashalg_nid
== default_hashalg_nid
315 ? NULL
: ossl_rsa_oaeppss_nid2name(hashalg_nid
));
316 const char *mgfname
=
317 (maskgenalg_nid
== default_maskgenalg_nid
318 ? NULL
: ossl_rsa_oaeppss_nid2name(maskgenalg_nid
));
319 const char *mgf1mdname
=
320 (maskgenhashalg_nid
== default_maskgenhashalg_nid
321 ? NULL
: ossl_rsa_oaeppss_nid2name(maskgenhashalg_nid
));
322 const char *key_md
= OSSL_PKEY_PARAM_RSA_DIGEST
;
323 const char *key_mgf
= OSSL_PKEY_PARAM_RSA_MASKGENFUNC
;
324 const char *key_mgf1_md
= OSSL_PKEY_PARAM_RSA_MGF1_DIGEST
;
325 const char *key_saltlen
= OSSL_PKEY_PARAM_RSA_PSS_SALTLEN
;
328 * To ensure that the key isn't seen as unrestricted by the recipient,
329 * we make sure that at least one PSS-related parameter is passed, even
330 * if it has a default value; saltlen.
333 && !ossl_param_build_set_utf8_string(bld
, params
, key_md
, mdname
))
335 && !ossl_param_build_set_utf8_string(bld
, params
,
337 || (mgf1mdname
!= NULL
338 && !ossl_param_build_set_utf8_string(bld
, params
,
339 key_mgf1_md
, mgf1mdname
))
340 || (!ossl_param_build_set_int(bld
, params
, key_saltlen
, saltlen
)))
346 int ossl_rsa_pss_params_30_fromdata(RSA_PSS_PARAMS_30
*pss_params
,
348 const OSSL_PARAM params
[],
349 OSSL_LIB_CTX
*libctx
)
351 const OSSL_PARAM
*param_md
, *param_mgf
, *param_mgf1md
, *param_saltlen
;
352 const OSSL_PARAM
*param_propq
;
353 const char *propq
= NULL
;
354 EVP_MD
*md
= NULL
, *mgf1md
= NULL
;
358 if (pss_params
== NULL
)
361 OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_DIGEST_PROPS
);
363 OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_DIGEST
);
365 OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_MASKGENFUNC
);
367 OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_MGF1_DIGEST
);
369 OSSL_PARAM_locate_const(params
, OSSL_PKEY_PARAM_RSA_PSS_SALTLEN
);
371 if (param_propq
!= NULL
) {
372 if (param_propq
->data_type
== OSSL_PARAM_UTF8_STRING
)
373 propq
= param_propq
->data
;
376 * If we get any of the parameters, we know we have at least some
377 * restrictions, so we start by setting default values, and let each
378 * parameter override their specific restriction data.
381 && (param_md
!= NULL
|| param_mgf
!= NULL
|| param_mgf1md
!= NULL
382 || param_saltlen
!= NULL
)) {
383 if (!ossl_rsa_pss_params_30_set_defaults(pss_params
))
388 if (param_mgf
!= NULL
) {
389 int default_maskgenalg_nid
= ossl_rsa_pss_params_30_maskgenalg(NULL
);
390 const char *mgfname
= NULL
;
392 if (param_mgf
->data_type
== OSSL_PARAM_UTF8_STRING
)
393 mgfname
= param_mgf
->data
;
394 else if (!OSSL_PARAM_get_utf8_ptr(param_mgf
, &mgfname
))
397 if (OPENSSL_strcasecmp(param_mgf
->data
,
398 ossl_rsa_mgf_nid2name(default_maskgenalg_nid
)) != 0)
403 * We're only interested in the NIDs that correspond to the MDs, so the
404 * exact propquery is unimportant in the EVP_MD_fetch() calls below.
407 if (param_md
!= NULL
) {
408 const char *mdname
= NULL
;
410 if (param_md
->data_type
== OSSL_PARAM_UTF8_STRING
)
411 mdname
= param_md
->data
;
412 else if (!OSSL_PARAM_get_utf8_ptr(param_mgf
, &mdname
))
415 if ((md
= EVP_MD_fetch(libctx
, mdname
, propq
)) == NULL
416 || !ossl_rsa_pss_params_30_set_hashalg(pss_params
,
417 ossl_rsa_oaeppss_md2nid(md
)))
421 if (param_mgf1md
!= NULL
) {
422 const char *mgf1mdname
= NULL
;
424 if (param_mgf1md
->data_type
== OSSL_PARAM_UTF8_STRING
)
425 mgf1mdname
= param_mgf1md
->data
;
426 else if (!OSSL_PARAM_get_utf8_ptr(param_mgf
, &mgf1mdname
))
429 if ((mgf1md
= EVP_MD_fetch(libctx
, mgf1mdname
, propq
)) == NULL
430 || !ossl_rsa_pss_params_30_set_maskgenhashalg(
431 pss_params
, ossl_rsa_oaeppss_md2nid(mgf1md
)))
435 if (param_saltlen
!= NULL
) {
436 if (!OSSL_PARAM_get_int(param_saltlen
, &saltlen
)
437 || !ossl_rsa_pss_params_30_set_saltlen(pss_params
, saltlen
))
449 int ossl_rsa_is_foreign(const RSA
*rsa
)
452 if (rsa
->engine
!= NULL
|| RSA_get_method(rsa
) != RSA_PKCS1_OpenSSL())
458 static ossl_inline
int rsa_bn_dup_check(BIGNUM
**out
, const BIGNUM
*f
)
460 if (f
!= NULL
&& (*out
= BN_dup(f
)) == NULL
)
465 RSA
*ossl_rsa_dup(const RSA
*rsa
, int selection
)
472 /* Do not try to duplicate foreign RSA keys */
473 if (ossl_rsa_is_foreign(rsa
))
476 if ((dupkey
= ossl_rsa_new_with_ctx(rsa
->libctx
)) == NULL
)
480 if ((selection
& OSSL_KEYMGMT_SELECT_KEYPAIR
) != 0) {
481 if (!rsa_bn_dup_check(&dupkey
->n
, rsa
->n
))
483 if (!rsa_bn_dup_check(&dupkey
->e
, rsa
->e
))
487 if ((selection
& OSSL_KEYMGMT_SELECT_PRIVATE_KEY
) != 0) {
490 if (!rsa_bn_dup_check(&dupkey
->d
, rsa
->d
))
493 /* factors and crt params */
494 if (!rsa_bn_dup_check(&dupkey
->p
, rsa
->p
))
496 if (!rsa_bn_dup_check(&dupkey
->q
, rsa
->q
))
498 if (!rsa_bn_dup_check(&dupkey
->dmp1
, rsa
->dmp1
))
500 if (!rsa_bn_dup_check(&dupkey
->dmq1
, rsa
->dmq1
))
502 if (!rsa_bn_dup_check(&dupkey
->iqmp
, rsa
->iqmp
))
506 dupkey
->version
= rsa
->version
;
507 dupkey
->flags
= rsa
->flags
;
508 /* we always copy the PSS parameters regardless of selection */
509 dupkey
->pss_params
= rsa
->pss_params
;
513 if ((selection
& OSSL_KEYMGMT_SELECT_PRIVATE_KEY
) != 0
514 && (pnum
= sk_RSA_PRIME_INFO_num(rsa
->prime_infos
)) > 0) {
515 dupkey
->prime_infos
= sk_RSA_PRIME_INFO_new_reserve(NULL
, pnum
);
516 if (dupkey
->prime_infos
== NULL
)
518 for (i
= 0; i
< pnum
; i
++) {
519 const RSA_PRIME_INFO
*pinfo
= NULL
;
520 RSA_PRIME_INFO
*duppinfo
= NULL
;
522 if ((duppinfo
= OPENSSL_zalloc(sizeof(*duppinfo
))) == NULL
)
524 /* push first so cleanup in error case works */
525 (void)sk_RSA_PRIME_INFO_push(dupkey
->prime_infos
, duppinfo
);
527 pinfo
= sk_RSA_PRIME_INFO_value(rsa
->prime_infos
, i
);
528 if (!rsa_bn_dup_check(&duppinfo
->r
, pinfo
->r
))
530 if (!rsa_bn_dup_check(&duppinfo
->d
, pinfo
->d
))
532 if (!rsa_bn_dup_check(&duppinfo
->t
, pinfo
->t
))
535 if (!ossl_rsa_multip_calc_product(dupkey
))
539 if (rsa
->pss
!= NULL
) {
540 dupkey
->pss
= RSA_PSS_PARAMS_dup(rsa
->pss
);
541 if (rsa
->pss
->maskGenAlgorithm
!= NULL
542 && dupkey
->pss
->maskGenAlgorithm
== NULL
) {
543 dupkey
->pss
->maskHash
= ossl_x509_algor_mgf1_decode(rsa
->pss
->maskGenAlgorithm
);
544 if (dupkey
->pss
->maskHash
== NULL
)
548 if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_RSA
,
549 &dupkey
->ex_data
, &rsa
->ex_data
))
561 RSA_PSS_PARAMS
*ossl_rsa_pss_decode(const X509_ALGOR
*alg
)
565 pss
= ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(RSA_PSS_PARAMS
),
571 if (pss
->maskGenAlgorithm
!= NULL
) {
572 pss
->maskHash
= ossl_x509_algor_mgf1_decode(pss
->maskGenAlgorithm
);
573 if (pss
->maskHash
== NULL
) {
574 RSA_PSS_PARAMS_free(pss
);
582 static int ossl_rsa_sync_to_pss_params_30(RSA
*rsa
)
584 const RSA_PSS_PARAMS
*legacy_pss
= NULL
;
585 RSA_PSS_PARAMS_30
*pss
= NULL
;
588 && (legacy_pss
= RSA_get0_pss_params(rsa
)) != NULL
589 && (pss
= ossl_rsa_get0_pss_params_30(rsa
)) != NULL
) {
590 const EVP_MD
*md
= NULL
, *mgf1md
= NULL
;
591 int md_nid
, mgf1md_nid
, saltlen
, trailerField
;
592 RSA_PSS_PARAMS_30 pss_params
;
595 * We don't care about the validity of the fields here, we just
596 * want to synchronise values. Verifying here makes it impossible
597 * to even read a key with invalid values, making it hard to test
600 * Other routines use ossl_rsa_pss_get_param(), so the values will
601 * be checked, eventually.
603 if (!ossl_rsa_pss_get_param_unverified(legacy_pss
, &md
, &mgf1md
,
604 &saltlen
, &trailerField
))
606 md_nid
= EVP_MD_get_type(md
);
607 mgf1md_nid
= EVP_MD_get_type(mgf1md
);
608 if (!ossl_rsa_pss_params_30_set_defaults(&pss_params
)
609 || !ossl_rsa_pss_params_30_set_hashalg(&pss_params
, md_nid
)
610 || !ossl_rsa_pss_params_30_set_maskgenhashalg(&pss_params
,
612 || !ossl_rsa_pss_params_30_set_saltlen(&pss_params
, saltlen
)
613 || !ossl_rsa_pss_params_30_set_trailerfield(&pss_params
,
621 int ossl_rsa_pss_get_param_unverified(const RSA_PSS_PARAMS
*pss
,
622 const EVP_MD
**pmd
, const EVP_MD
**pmgf1md
,
623 int *psaltlen
, int *ptrailerField
)
625 RSA_PSS_PARAMS_30 pss_params
;
627 /* Get the defaults from the ONE place */
628 (void)ossl_rsa_pss_params_30_set_defaults(&pss_params
);
632 *pmd
= ossl_x509_algor_get_md(pss
->hashAlgorithm
);
635 *pmgf1md
= ossl_x509_algor_get_md(pss
->maskHash
);
636 if (*pmgf1md
== NULL
)
639 *psaltlen
= ASN1_INTEGER_get(pss
->saltLength
);
641 *psaltlen
= ossl_rsa_pss_params_30_saltlen(&pss_params
);
642 if (pss
->trailerField
)
643 *ptrailerField
= ASN1_INTEGER_get(pss
->trailerField
);
645 *ptrailerField
= ossl_rsa_pss_params_30_trailerfield(&pss_params
);
650 int ossl_rsa_param_decode(RSA
*rsa
, const X509_ALGOR
*alg
)
653 const ASN1_OBJECT
*algoid
;
657 X509_ALGOR_get0(&algoid
, &algptype
, &algp
, alg
);
658 if (OBJ_obj2nid(algoid
) != EVP_PKEY_RSA_PSS
)
660 if (algptype
== V_ASN1_UNDEF
)
662 if (algptype
!= V_ASN1_SEQUENCE
) {
663 ERR_raise(ERR_LIB_RSA
, RSA_R_INVALID_PSS_PARAMETERS
);
666 if ((pss
= ossl_rsa_pss_decode(alg
)) == NULL
667 || !ossl_rsa_set0_pss_params(rsa
, pss
)) {
668 RSA_PSS_PARAMS_free(pss
);
671 if (!ossl_rsa_sync_to_pss_params_30(rsa
))
676 RSA
*ossl_rsa_key_from_pkcs8(const PKCS8_PRIV_KEY_INFO
*p8inf
,
677 OSSL_LIB_CTX
*libctx
, const char *propq
)
679 const unsigned char *p
;
682 const X509_ALGOR
*alg
;
684 if (!PKCS8_pkey_get0(NULL
, &p
, &pklen
, &alg
, p8inf
))
686 rsa
= d2i_RSAPrivateKey(NULL
, &p
, pklen
);
688 ERR_raise(ERR_LIB_RSA
, ERR_R_RSA_LIB
);
691 if (!ossl_rsa_param_decode(rsa
, alg
)) {
696 RSA_clear_flags(rsa
, RSA_FLAG_TYPE_MASK
);
697 switch (OBJ_obj2nid(alg
->algorithm
)) {
699 RSA_set_flags(rsa
, RSA_FLAG_TYPE_RSA
);
701 case EVP_PKEY_RSA_PSS
:
702 RSA_set_flags(rsa
, RSA_FLAG_TYPE_RSASSAPSS
);
705 /* Leave the type bits zero */