2 * Copyright 2019-2020 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
10 #ifndef OSSL_INTERNAL_RSA_H
11 # define OSSL_INTERNAL_RSA_H
13 # include <openssl/core.h>
14 # include <openssl/rsa.h>
15 # include "crypto/types.h"
17 typedef struct rsa_pss_params_30_st
{
18 int hash_algorithm_nid
;
20 int algorithm_nid
; /* Currently always NID_mgf1 */
21 int hash_algorithm_nid
;
27 RSA_PSS_PARAMS_30
*ossl_rsa_get0_pss_params_30(RSA
*r
);
28 int ossl_rsa_pss_params_30_set_defaults(RSA_PSS_PARAMS_30
*rsa_pss_params
);
29 int ossl_rsa_pss_params_30_copy(RSA_PSS_PARAMS_30
*to
,
30 const RSA_PSS_PARAMS_30
*from
);
31 int ossl_rsa_pss_params_30_is_unrestricted(const RSA_PSS_PARAMS_30
*rsa_pss_params
);
32 int ossl_rsa_pss_params_30_set_hashalg(RSA_PSS_PARAMS_30
*rsa_pss_params
,
34 int ossl_rsa_pss_params_30_set_maskgenalg(RSA_PSS_PARAMS_30
*rsa_pss_params
,
36 int ossl_rsa_pss_params_30_set_maskgenhashalg(RSA_PSS_PARAMS_30
*rsa_pss_params
,
37 int maskgenhashalg_nid
);
38 int ossl_rsa_pss_params_30_set_saltlen(RSA_PSS_PARAMS_30
*rsa_pss_params
,
40 int ossl_rsa_pss_params_30_set_trailerfield(RSA_PSS_PARAMS_30
*rsa_pss_params
,
42 int ossl_rsa_pss_params_30_hashalg(const RSA_PSS_PARAMS_30
*rsa_pss_params
);
43 int ossl_rsa_pss_params_30_maskgenalg(const RSA_PSS_PARAMS_30
*rsa_pss_params
);
44 int ossl_rsa_pss_params_30_maskgenhashalg(const RSA_PSS_PARAMS_30
*rsa_pss_params
);
45 int ossl_rsa_pss_params_30_saltlen(const RSA_PSS_PARAMS_30
*rsa_pss_params
);
46 int ossl_rsa_pss_params_30_trailerfield(const RSA_PSS_PARAMS_30
*rsa_pss_params
);
48 const char *ossl_rsa_mgf_nid2name(int mgf
);
49 int ossl_rsa_oaeppss_md2nid(const EVP_MD
*md
);
50 const char *ossl_rsa_oaeppss_nid2name(int md
);
52 RSA
*ossl_rsa_new_with_ctx(OSSL_LIB_CTX
*libctx
);
53 OSSL_LIB_CTX
*ossl_rsa_get0_libctx(RSA
*r
);
55 int ossl_rsa_set0_all_params(RSA
*r
, const STACK_OF(BIGNUM
) *primes
,
56 const STACK_OF(BIGNUM
) *exps
,
57 const STACK_OF(BIGNUM
) *coeffs
);
58 int ossl_rsa_get0_all_params(RSA
*r
, STACK_OF(BIGNUM_const
) *primes
,
59 STACK_OF(BIGNUM_const
) *exps
,
60 STACK_OF(BIGNUM_const
) *coeffs
);
62 int ossl_rsa_todata(RSA
*rsa
, OSSL_PARAM_BLD
*bld
, OSSL_PARAM params
[]);
63 int ossl_rsa_fromdata(RSA
*rsa
, const OSSL_PARAM params
[]);
64 int ossl_rsa_pss_params_30_todata(const RSA_PSS_PARAMS_30
*pss
,
65 OSSL_PARAM_BLD
*bld
, OSSL_PARAM params
[]);
66 int ossl_rsa_pss_params_30_fromdata(RSA_PSS_PARAMS_30
*pss_params
,
67 const OSSL_PARAM params
[],
68 OSSL_LIB_CTX
*libctx
);
70 int ossl_rsa_padding_check_PKCS1_type_2_TLS(OSSL_LIB_CTX
*ctx
, unsigned char *to
,
72 const unsigned char *from
,
73 size_t flen
, int client_version
,
75 int ossl_rsa_padding_add_PKCS1_OAEP_mgf1_ex(OSSL_LIB_CTX
*libctx
,
76 unsigned char *to
, int tlen
,
77 const unsigned char *from
, int flen
,
78 const unsigned char *param
,
79 int plen
, const EVP_MD
*md
,
80 const EVP_MD
*mgf1md
);
82 int ossl_rsa_validate_public(const RSA
*key
);
83 int ossl_rsa_validate_private(const RSA
*key
);
84 int ossl_rsa_validate_pairwise(const RSA
*key
);
86 int int_rsa_verify(int dtype
, const unsigned char *m
,
87 unsigned int m_len
, unsigned char *rm
,
88 size_t *prm_len
, const unsigned char *sigbuf
,
89 size_t siglen
, RSA
*rsa
);
91 const unsigned char *ossl_rsa_digestinfo_encoding(int md_nid
, size_t *len
);
93 extern const char *ossl_rsa_mp_factor_names
[];
94 extern const char *ossl_rsa_mp_exp_names
[];
95 extern const char *ossl_rsa_mp_coeff_names
[];
97 ASN1_STRING
*ossl_rsa_ctx_to_pss_string(EVP_PKEY_CTX
*pkctx
);
98 int ossl_rsa_pss_to_ctx(EVP_MD_CTX
*ctx
, EVP_PKEY_CTX
*pkctx
,
99 const X509_ALGOR
*sigalg
, EVP_PKEY
*pkey
);
101 # if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS)
102 int rsa_acvp_test_gen_params_new(OSSL_PARAM
**dst
, const OSSL_PARAM src
[]);
103 void rsa_acvp_test_gen_params_free(OSSL_PARAM
*dst
);
105 int rsa_acvp_test_set_params(RSA
*r
, const OSSL_PARAM params
[]);
106 int rsa_acvp_test_get_params(RSA
*r
, OSSL_PARAM params
[]);
107 typedef struct rsa_acvp_test_st RSA_ACVP_TEST
;
108 void rsa_acvp_test_free(RSA_ACVP_TEST
*t
);
110 # define RSA_ACVP_TEST void