6f32ec422f2531765249af906eec6c556e493578
[openssl.git] / include / crypto / rsa.h
1 /*
2  * Copyright 2019-2020 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 #ifndef OSSL_INTERNAL_RSA_H
11 # define OSSL_INTERNAL_RSA_H
12
13 #include <openssl/core.h>
14 #include <openssl/rsa.h>
15
16 typedef struct rsa_pss_params_30_st {
17     int hash_algorithm_nid;
18     struct {
19         int algorithm_nid;       /* Currently always NID_mgf1 */
20         int hash_algorithm_nid;
21     } mask_gen;
22     unsigned int salt_len;
23     unsigned int trailer_field;
24 } RSA_PSS_PARAMS_30;
25
26 RSA_PSS_PARAMS_30 *rsa_get0_pss_params_30(RSA *r);
27 int rsa_pss_params_30_set_defaults(RSA_PSS_PARAMS_30 *rsa_pss_params);
28 int rsa_pss_params_30_copy(RSA_PSS_PARAMS_30 *to,
29                            const RSA_PSS_PARAMS_30 *from);
30 int rsa_pss_params_30_is_unrestricted(const RSA_PSS_PARAMS_30 *rsa_pss_params);
31 int rsa_pss_params_30_set_hashalg(RSA_PSS_PARAMS_30 *rsa_pss_params,
32                                   int hashalg_nid);
33 int rsa_pss_params_30_set_maskgenalg(RSA_PSS_PARAMS_30 *rsa_pss_params,
34                                      int maskgenalg_nid);
35 int rsa_pss_params_30_set_maskgenhashalg(RSA_PSS_PARAMS_30 *rsa_pss_params,
36                                          int maskgenhashalg_nid);
37 int rsa_pss_params_30_set_saltlen(RSA_PSS_PARAMS_30 *rsa_pss_params,
38                                   int saltlen);
39 int rsa_pss_params_30_set_trailerfield(RSA_PSS_PARAMS_30 *rsa_pss_params,
40                                        int trailerfield);
41 int rsa_pss_params_30_hashalg(const RSA_PSS_PARAMS_30 *rsa_pss_params);
42 int rsa_pss_params_30_maskgenalg(const RSA_PSS_PARAMS_30 *rsa_pss_params);
43 int rsa_pss_params_30_maskgenhashalg(const RSA_PSS_PARAMS_30 *rsa_pss_params);
44 int rsa_pss_params_30_saltlen(const RSA_PSS_PARAMS_30 *rsa_pss_params);
45 int rsa_pss_params_30_trailerfield(const RSA_PSS_PARAMS_30 *rsa_pss_params);
46
47 const char *rsa_mgf_nid2name(int mgf);
48 int rsa_oaeppss_md2nid(const EVP_MD *md);
49 const char *rsa_oaeppss_nid2name(int md);
50
51 RSA *rsa_new_with_ctx(OPENSSL_CTX *libctx);
52 OPENSSL_CTX *rsa_get0_libctx(RSA *r);
53
54 int rsa_set0_all_params(RSA *r, const STACK_OF(BIGNUM) *primes,
55                         const STACK_OF(BIGNUM) *exps,
56                         const STACK_OF(BIGNUM) *coeffs);
57 int rsa_get0_all_params(RSA *r, STACK_OF(BIGNUM_const) *primes,
58                         STACK_OF(BIGNUM_const) *exps,
59                         STACK_OF(BIGNUM_const) *coeffs);
60
61 int rsa_todata(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[]);
62 int rsa_fromdata(RSA *rsa, const OSSL_PARAM params[]);
63 int rsa_pss_params_30_todata(const RSA_PSS_PARAMS_30 *pss, const char *propq,
64                              OSSL_PARAM_BLD *bld, OSSL_PARAM params[]);
65 int rsa_pss_params_30_fromdata(RSA_PSS_PARAMS_30 *pss_params,
66                                const OSSL_PARAM params[], OPENSSL_CTX *libctx);
67
68 int rsa_padding_check_PKCS1_type_2_TLS(OPENSSL_CTX *ctx, unsigned char *to,
69                                        size_t tlen, const unsigned char *from,
70                                        size_t flen, int client_version,
71                                        int alt_version);
72
73 int rsa_validate_public(const RSA *key);
74 int rsa_validate_private(const RSA *key);
75 int rsa_validate_pairwise(const RSA *key);
76
77 int int_rsa_verify(int dtype, const unsigned char *m,
78                    unsigned int m_len, unsigned char *rm,
79                    size_t *prm_len, const unsigned char *sigbuf,
80                    size_t siglen, RSA *rsa);
81
82 const unsigned char *rsa_digestinfo_encoding(int md_nid, size_t *len);
83 const unsigned char *rsa_algorithmidentifier_encoding(int md_nid, size_t *len);
84
85 extern const char *rsa_mp_factor_names[];
86 extern const char *rsa_mp_exp_names[];
87 extern const char *rsa_mp_coeff_names[];
88
89 #endif