0aeab1560a370bf4aa1146e528aa951238776d85
[openssl.git] / include / openssl / rsa.h
1 /*
2  * Copyright 1995-2021 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 OPENSSL_RSA_H
11 # define OPENSSL_RSA_H
12 # pragma once
13
14 # include <openssl/macros.h>
15 # ifndef OPENSSL_NO_DEPRECATED_3_0
16 #  define HEADER_RSA_H
17 # endif
18
19 # include <openssl/opensslconf.h>
20
21 # include <openssl/asn1.h>
22 # include <openssl/bio.h>
23 # include <openssl/crypto.h>
24 # include <openssl/types.h>
25 # ifndef OPENSSL_NO_DEPRECATED_1_1_0
26 #  include <openssl/bn.h>
27 # endif
28 # include <openssl/rsaerr.h>
29 # include <openssl/safestack.h>
30
31 # ifdef  __cplusplus
32 extern "C" {
33 # endif
34
35 # ifndef OPENSSL_RSA_MAX_MODULUS_BITS
36 #  define OPENSSL_RSA_MAX_MODULUS_BITS   16384
37 # endif
38
39 # define RSA_3   0x3L
40 # define RSA_F4  0x10001L
41
42 # ifndef OPENSSL_NO_DEPRECATED_3_0
43 /* The types RSA and RSA_METHOD are defined in ossl_typ.h */
44
45 #  define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 2048
46
47 #  ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
48 #   define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
49 #  endif
50
51 /* exponent limit enforced for "large" modulus only */
52 #  ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
53 #   define OPENSSL_RSA_MAX_PUBEXP_BITS    64
54 #  endif
55 /* based on RFC 8017 appendix A.1.2 */
56 #  define RSA_ASN1_VERSION_DEFAULT        0
57 #  define RSA_ASN1_VERSION_MULTI          1
58
59 #  define RSA_DEFAULT_PRIME_NUM           2
60
61 #  define RSA_METHOD_FLAG_NO_CHECK        0x0001
62 #  define RSA_FLAG_CACHE_PUBLIC           0x0002
63 #  define RSA_FLAG_CACHE_PRIVATE          0x0004
64 #  define RSA_FLAG_BLINDING               0x0008
65 #  define RSA_FLAG_THREAD_SAFE            0x0010
66 /*
67  * This flag means the private key operations will be handled by rsa_mod_exp
68  * and that they do not depend on the private key components being present:
69  * for example a key stored in external hardware. Without this flag
70  * bn_mod_exp gets called when private key components are absent.
71  */
72 #  define RSA_FLAG_EXT_PKEY               0x0020
73
74 /*
75  * new with 0.9.6j and 0.9.7b; the built-in
76  * RSA implementation now uses blinding by
77  * default (ignoring RSA_FLAG_BLINDING),
78  * but other engines might not need it
79  */
80 #  define RSA_FLAG_NO_BLINDING            0x0080
81 # endif /* OPENSSL_NO_DEPRECATED_3_0 */
82 /*
83  * Does nothing. Previously this switched off constant time behaviour.
84  */
85 # ifndef OPENSSL_NO_DEPRECATED_1_1_0
86 #  define RSA_FLAG_NO_CONSTTIME           0x0000
87 # endif
88 /* deprecated name for the flag*/
89 /*
90  * new with 0.9.7h; the built-in RSA
91  * implementation now uses constant time
92  * modular exponentiation for secret exponents
93  * by default. This flag causes the
94  * faster variable sliding window method to
95  * be used for all exponents.
96  */
97 # ifndef OPENSSL_NO_DEPRECATED_0_9_8
98 #  define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME
99 # endif
100
101 /*-
102  * New with 3.0: use part of the flags to denote exact type of RSA key,
103  * some of which are limited to specific signature and encryption schemes.
104  * These different types share the same RSA structure, but indicate the
105  * use of certain fields in that structure.
106  * Currently known are:
107  * RSA          - this is the "normal" unlimited RSA structure (typenum 0)
108  * RSASSA-PSS   - indicates that the PSS parameters are used.
109  * RSAES-OAEP   - no specific field used for the moment, but OAEP padding
110  *                is expected.  (currently unused)
111  *
112  * 4 bits allow for 16 types
113  */
114 # define RSA_FLAG_TYPE_MASK            0xF000
115 # define RSA_FLAG_TYPE_RSA             0x0000
116 # define RSA_FLAG_TYPE_RSASSAPSS       0x1000
117 # define RSA_FLAG_TYPE_RSAESOAEP       0x2000
118
119 int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad_mode);
120 int EVP_PKEY_CTX_get_rsa_padding(EVP_PKEY_CTX *ctx, int *pad_mode);
121
122 int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int saltlen);
123 int EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int *saltlen);
124
125 int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX *ctx, int bits);
126 int EVP_PKEY_CTX_set1_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp);
127 int EVP_PKEY_CTX_set_rsa_keygen_primes(EVP_PKEY_CTX *ctx, int primes);
128 int EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(EVP_PKEY_CTX *ctx, int saltlen);
129 # ifndef OPENSSL_NO_DEPRECATED_3_0
130 OSSL_DEPRECATEDIN_3_0
131 int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp);
132 # endif
133
134 /* Salt length matches digest */
135 # define RSA_PSS_SALTLEN_DIGEST -1
136 /* Verify only: auto detect salt length */
137 # define RSA_PSS_SALTLEN_AUTO   -2
138 /* Set salt length to maximum possible */
139 # define RSA_PSS_SALTLEN_MAX    -3
140 /* Old compatible max salt length for sign only */
141 # define RSA_PSS_SALTLEN_MAX_SIGN    -2
142
143 int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
144 int EVP_PKEY_CTX_set_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, const char *mdname,
145                                       const char *mdprops);
146 int EVP_PKEY_CTX_get_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD **md);
147 int EVP_PKEY_CTX_get_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, char *name,
148                                       size_t namelen);
149 int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
150 int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md_name(EVP_PKEY_CTX *ctx,
151                                                  const char *mdname);
152
153 int EVP_PKEY_CTX_set_rsa_pss_keygen_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
154 int EVP_PKEY_CTX_set_rsa_pss_keygen_md_name(EVP_PKEY_CTX *ctx,
155                                             const char *mdname,
156                                             const char *mdprops);
157
158 int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
159 int EVP_PKEY_CTX_set_rsa_oaep_md_name(EVP_PKEY_CTX *ctx, const char *mdname,
160                                       const char *mdprops);
161 int EVP_PKEY_CTX_get_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD **md);
162 int EVP_PKEY_CTX_get_rsa_oaep_md_name(EVP_PKEY_CTX *ctx, char *name,
163                                       size_t namelen);
164 int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, void *label, int llen);
165 int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx, unsigned char **label);
166
167 # define EVP_PKEY_CTRL_RSA_PADDING       (EVP_PKEY_ALG_CTRL + 1)
168 # define EVP_PKEY_CTRL_RSA_PSS_SALTLEN   (EVP_PKEY_ALG_CTRL + 2)
169
170 # define EVP_PKEY_CTRL_RSA_KEYGEN_BITS   (EVP_PKEY_ALG_CTRL + 3)
171 # define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4)
172 # define EVP_PKEY_CTRL_RSA_MGF1_MD       (EVP_PKEY_ALG_CTRL + 5)
173
174 # define EVP_PKEY_CTRL_GET_RSA_PADDING           (EVP_PKEY_ALG_CTRL + 6)
175 # define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN       (EVP_PKEY_ALG_CTRL + 7)
176 # define EVP_PKEY_CTRL_GET_RSA_MGF1_MD           (EVP_PKEY_ALG_CTRL + 8)
177
178 # define EVP_PKEY_CTRL_RSA_OAEP_MD       (EVP_PKEY_ALG_CTRL + 9)
179 # define EVP_PKEY_CTRL_RSA_OAEP_LABEL    (EVP_PKEY_ALG_CTRL + 10)
180
181 # define EVP_PKEY_CTRL_GET_RSA_OAEP_MD   (EVP_PKEY_ALG_CTRL + 11)
182 # define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12)
183
184 # define EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES  (EVP_PKEY_ALG_CTRL + 13)
185
186 # define RSA_PKCS1_PADDING          1
187 # define RSA_SSLV23_PADDING         2
188 # define RSA_NO_PADDING             3
189 # define RSA_PKCS1_OAEP_PADDING     4
190 # define RSA_X931_PADDING           5
191
192 /* EVP_PKEY_ only */
193 # define RSA_PKCS1_PSS_PADDING      6
194 # define RSA_PKCS1_WITH_TLS_PADDING 7
195
196 # define RSA_PKCS1_PADDING_SIZE    11
197
198 # define RSA_set_app_data(s,arg)         RSA_set_ex_data(s,0,arg)
199 # define RSA_get_app_data(s)             RSA_get_ex_data(s,0)
200
201 # ifndef OPENSSL_NO_DEPRECATED_3_0
202 OSSL_DEPRECATEDIN_3_0 RSA *RSA_new(void);
203 OSSL_DEPRECATEDIN_3_0 RSA *RSA_new_method(ENGINE *engine);
204 OSSL_DEPRECATEDIN_3_0 int RSA_bits(const RSA *rsa);
205 OSSL_DEPRECATEDIN_3_0 int RSA_size(const RSA *rsa);
206 OSSL_DEPRECATEDIN_3_0 int RSA_security_bits(const RSA *rsa);
207
208 OSSL_DEPRECATEDIN_3_0 int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
209 OSSL_DEPRECATEDIN_3_0 int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
210 OSSL_DEPRECATEDIN_3_0 int RSA_set0_crt_params(RSA *r,
211                                               BIGNUM *dmp1, BIGNUM *dmq1,
212                                               BIGNUM *iqmp);
213 OSSL_DEPRECATEDIN_3_0 int RSA_set0_multi_prime_params(RSA *r,
214                                                       BIGNUM *primes[],
215                                                       BIGNUM *exps[],
216                                                       BIGNUM *coeffs[],
217                                                       int pnum);
218 OSSL_DEPRECATEDIN_3_0 void RSA_get0_key(const RSA *r,
219                                         const BIGNUM **n, const BIGNUM **e,
220                                         const BIGNUM **d);
221 OSSL_DEPRECATEDIN_3_0 void RSA_get0_factors(const RSA *r,
222                                             const BIGNUM **p, const BIGNUM **q);
223 OSSL_DEPRECATEDIN_3_0 int RSA_get_multi_prime_extra_count(const RSA *r);
224 OSSL_DEPRECATEDIN_3_0 int RSA_get0_multi_prime_factors(const RSA *r,
225                                                        const BIGNUM *primes[]);
226 OSSL_DEPRECATEDIN_3_0 void RSA_get0_crt_params(const RSA *r,
227                                                const BIGNUM **dmp1,
228                                                const BIGNUM **dmq1,
229                                                const BIGNUM **iqmp);
230 OSSL_DEPRECATEDIN_3_0
231 int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[],
232                                     const BIGNUM *coeffs[]);
233 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_n(const RSA *d);
234 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_e(const RSA *d);
235 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_d(const RSA *d);
236 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_p(const RSA *d);
237 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_q(const RSA *d);
238 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_dmp1(const RSA *r);
239 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_dmq1(const RSA *r);
240 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_iqmp(const RSA *r);
241 OSSL_DEPRECATEDIN_3_0 const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r);
242 OSSL_DEPRECATEDIN_3_0 void RSA_clear_flags(RSA *r, int flags);
243 OSSL_DEPRECATEDIN_3_0 int RSA_test_flags(const RSA *r, int flags);
244 OSSL_DEPRECATEDIN_3_0 void RSA_set_flags(RSA *r, int flags);
245 OSSL_DEPRECATEDIN_3_0 int RSA_get_version(RSA *r);
246 OSSL_DEPRECATEDIN_3_0 ENGINE *RSA_get0_engine(const RSA *r);
247 # endif  /* !OPENSSL_NO_DEPRECATED_3_0 */
248
249 /* Deprecated version */
250 # ifndef OPENSSL_NO_DEPRECATED_0_9_8
251 OSSL_DEPRECATEDIN_0_9_8 RSA *RSA_generate_key(int bits, unsigned long e, void
252                                               (*callback) (int, int, void *),
253                                               void *cb_arg);
254 # endif
255
256 /* New version */
257 # ifndef OPENSSL_NO_DEPRECATED_3_0
258 OSSL_DEPRECATEDIN_3_0 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e,
259                                               BN_GENCB *cb);
260 /* Multi-prime version */
261 OSSL_DEPRECATEDIN_3_0 int RSA_generate_multi_prime_key(RSA *rsa, int bits,
262                                                        int primes, BIGNUM *e,
263                                                        BN_GENCB *cb);
264
265 OSSL_DEPRECATEDIN_3_0
266 int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2,
267                        BIGNUM *q1, BIGNUM *q2,
268                        const BIGNUM *Xp1, const BIGNUM *Xp2,
269                        const BIGNUM *Xp, const BIGNUM *Xq1,
270                        const BIGNUM *Xq2, const BIGNUM *Xq,
271                        const BIGNUM *e, BN_GENCB *cb);
272 OSSL_DEPRECATEDIN_3_0 int RSA_X931_generate_key_ex(RSA *rsa, int bits,
273                                                    const BIGNUM *e,
274                                                    BN_GENCB *cb);
275
276 OSSL_DEPRECATEDIN_3_0 int RSA_check_key(const RSA *);
277 OSSL_DEPRECATEDIN_3_0 int RSA_check_key_ex(const RSA *, BN_GENCB *cb);
278         /* next 4 return -1 on error */
279 OSSL_DEPRECATEDIN_3_0
280 int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
281                        RSA *rsa, int padding);
282 OSSL_DEPRECATEDIN_3_0
283 int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
284                         RSA *rsa, int padding);
285 OSSL_DEPRECATEDIN_3_0
286 int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
287                        RSA *rsa, int padding);
288 OSSL_DEPRECATEDIN_3_0
289 int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
290                         RSA *rsa, int padding);
291 OSSL_DEPRECATEDIN_3_0 void RSA_free(RSA *r);
292 /* "up" the RSA object's reference count */
293 OSSL_DEPRECATEDIN_3_0 int RSA_up_ref(RSA *r);
294 OSSL_DEPRECATEDIN_3_0 int RSA_flags(const RSA *r);
295
296 OSSL_DEPRECATEDIN_3_0 void RSA_set_default_method(const RSA_METHOD *meth);
297 OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_get_default_method(void);
298 OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_null_method(void);
299 OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_get_method(const RSA *rsa);
300 OSSL_DEPRECATEDIN_3_0 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
301
302 /* these are the actual RSA functions */
303 OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_PKCS1_OpenSSL(void);
304
305 DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(OSSL_DEPRECATEDIN_3_0,
306                                         RSA, RSAPublicKey)
307 DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(OSSL_DEPRECATEDIN_3_0,
308                                         RSA, RSAPrivateKey)
309 # endif  /* !OPENSSL_NO_DEPRECATED_3_0 */
310
311 int RSA_pkey_ctx_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2);
312
313 struct rsa_pss_params_st {
314     X509_ALGOR *hashAlgorithm;
315     X509_ALGOR *maskGenAlgorithm;
316     ASN1_INTEGER *saltLength;
317     ASN1_INTEGER *trailerField;
318     /* Decoded hash algorithm from maskGenAlgorithm */
319     X509_ALGOR *maskHash;
320 };
321
322 DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
323
324 typedef struct rsa_oaep_params_st {
325     X509_ALGOR *hashFunc;
326     X509_ALGOR *maskGenFunc;
327     X509_ALGOR *pSourceFunc;
328     /* Decoded hash algorithm from maskGenFunc */
329     X509_ALGOR *maskHash;
330 } RSA_OAEP_PARAMS;
331
332 DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS)
333
334 # ifndef OPENSSL_NO_DEPRECATED_3_0
335 #  ifndef OPENSSL_NO_STDIO
336 OSSL_DEPRECATEDIN_3_0 int RSA_print_fp(FILE *fp, const RSA *r, int offset);
337 #  endif
338
339 OSSL_DEPRECATEDIN_3_0 int RSA_print(BIO *bp, const RSA *r, int offset);
340
341 /*
342  * The following 2 functions sign and verify a X509_SIG ASN1 object inside
343  * PKCS#1 padded RSA encryption
344  */
345 OSSL_DEPRECATEDIN_3_0 int RSA_sign(int type, const unsigned char *m,
346                                    unsigned int m_length, unsigned char *sigret,
347                                    unsigned int *siglen, RSA *rsa);
348 OSSL_DEPRECATEDIN_3_0 int RSA_verify(int type, const unsigned char *m,
349                                      unsigned int m_length,
350                                      const unsigned char *sigbuf,
351                                      unsigned int siglen, RSA *rsa);
352
353 /*
354  * The following 2 function sign and verify a ASN1_OCTET_STRING object inside
355  * PKCS#1 padded RSA encryption
356  */
357 OSSL_DEPRECATEDIN_3_0
358 int RSA_sign_ASN1_OCTET_STRING(int type,
359                                const unsigned char *m, unsigned int m_length,
360                                unsigned char *sigret, unsigned int *siglen,
361                                RSA *rsa);
362 OSSL_DEPRECATEDIN_3_0
363 int RSA_verify_ASN1_OCTET_STRING(int type,
364                                  const unsigned char *m, unsigned int m_length,
365                                  unsigned char *sigbuf, unsigned int siglen,
366                                  RSA *rsa);
367
368 OSSL_DEPRECATEDIN_3_0 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
369 OSSL_DEPRECATEDIN_3_0 void RSA_blinding_off(RSA *rsa);
370 OSSL_DEPRECATEDIN_3_0 BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx);
371
372 OSSL_DEPRECATEDIN_3_0
373 int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
374                                  const unsigned char *f, int fl);
375 OSSL_DEPRECATEDIN_3_0
376 int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
377                                    const unsigned char *f, int fl,
378                                    int rsa_len);
379 OSSL_DEPRECATEDIN_3_0
380 int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
381                                  const unsigned char *f, int fl);
382 OSSL_DEPRECATEDIN_3_0
383 int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
384                                    const unsigned char *f, int fl,
385                                    int rsa_len);
386 OSSL_DEPRECATEDIN_3_0 int PKCS1_MGF1(unsigned char *mask, long len,
387                                      const unsigned char *seed, long seedlen,
388                                      const EVP_MD *dgst);
389 OSSL_DEPRECATEDIN_3_0
390 int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
391                                const unsigned char *f, int fl,
392                                const unsigned char *p, int pl);
393 OSSL_DEPRECATEDIN_3_0
394 int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
395                                  const unsigned char *f, int fl, int rsa_len,
396                                  const unsigned char *p, int pl);
397 OSSL_DEPRECATEDIN_3_0
398 int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
399                                     const unsigned char *from, int flen,
400                                     const unsigned char *param, int plen,
401                                     const EVP_MD *md, const EVP_MD *mgf1md);
402 OSSL_DEPRECATEDIN_3_0
403 int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
404                                       const unsigned char *from, int flen,
405                                       int num,
406                                       const unsigned char *param, int plen,
407                                       const EVP_MD *md, const EVP_MD *mgf1md);
408 OSSL_DEPRECATEDIN_3_0
409 int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
410                            const unsigned char *f, int fl);
411 OSSL_DEPRECATEDIN_3_0
412 int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
413                              const unsigned char *f, int fl,
414                              int rsa_len);
415 OSSL_DEPRECATEDIN_3_0 int RSA_padding_add_none(unsigned char *to, int tlen,
416                                                const unsigned char *f, int fl);
417 OSSL_DEPRECATEDIN_3_0 int RSA_padding_check_none(unsigned char *to, int tlen,
418                                                  const unsigned char *f, int fl,
419                                                  int rsa_len);
420 OSSL_DEPRECATEDIN_3_0 int RSA_padding_add_X931(unsigned char *to, int tlen,
421                                                const unsigned char *f, int fl);
422 OSSL_DEPRECATEDIN_3_0 int RSA_padding_check_X931(unsigned char *to, int tlen,
423                                                  const unsigned char *f, int fl,
424                                                  int rsa_len);
425 OSSL_DEPRECATEDIN_3_0 int RSA_X931_hash_id(int nid);
426
427 OSSL_DEPRECATEDIN_3_0
428 int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
429                          const EVP_MD *Hash, const unsigned char *EM,
430                          int sLen);
431 OSSL_DEPRECATEDIN_3_0
432 int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
433                               const unsigned char *mHash, const EVP_MD *Hash,
434                               int sLen);
435
436 OSSL_DEPRECATEDIN_3_0
437 int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
438                               const EVP_MD *Hash, const EVP_MD *mgf1Hash,
439                               const unsigned char *EM, int sLen);
440
441 OSSL_DEPRECATEDIN_3_0
442 int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
443                                    const unsigned char *mHash,
444                                    const EVP_MD *Hash, const EVP_MD *mgf1Hash,
445                                    int sLen);
446
447 # define RSA_get_ex_new_index(l, p, newf, dupf, freef) \
448     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef)
449 OSSL_DEPRECATEDIN_3_0 int RSA_set_ex_data(RSA *r, int idx, void *arg);
450 OSSL_DEPRECATEDIN_3_0 void *RSA_get_ex_data(const RSA *r, int idx);
451
452 DECLARE_ASN1_DUP_FUNCTION_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPublicKey)
453 DECLARE_ASN1_DUP_FUNCTION_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPrivateKey)
454
455 /*
456  * If this flag is set the RSA method is FIPS compliant and can be used in
457  * FIPS mode. This is set in the validated module method. If an application
458  * sets this flag in its own methods it is its responsibility to ensure the
459  * result is compliant.
460  */
461
462 #  define RSA_FLAG_FIPS_METHOD                    0x0400
463
464 /*
465  * If this flag is set the operations normally disabled in FIPS mode are
466  * permitted it is then the applications responsibility to ensure that the
467  * usage is compliant.
468  */
469
470 #  define RSA_FLAG_NON_FIPS_ALLOW                 0x0400
471 /*
472  * Application has decided PRNG is good enough to generate a key: don't
473  * check.
474  */
475 #  define RSA_FLAG_CHECKED                        0x0800
476
477 OSSL_DEPRECATEDIN_3_0 RSA_METHOD *RSA_meth_new(const char *name, int flags);
478 OSSL_DEPRECATEDIN_3_0 void RSA_meth_free(RSA_METHOD *meth);
479 OSSL_DEPRECATEDIN_3_0 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
480 OSSL_DEPRECATEDIN_3_0 const char *RSA_meth_get0_name(const RSA_METHOD *meth);
481 OSSL_DEPRECATEDIN_3_0 int RSA_meth_set1_name(RSA_METHOD *meth,
482                                              const char *name);
483 OSSL_DEPRECATEDIN_3_0 int RSA_meth_get_flags(const RSA_METHOD *meth);
484 OSSL_DEPRECATEDIN_3_0 int RSA_meth_set_flags(RSA_METHOD *meth, int flags);
485 OSSL_DEPRECATEDIN_3_0 void *RSA_meth_get0_app_data(const RSA_METHOD *meth);
486 OSSL_DEPRECATEDIN_3_0 int RSA_meth_set0_app_data(RSA_METHOD *meth,
487                                                  void *app_data);
488 OSSL_DEPRECATEDIN_3_0
489 int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth)) (int flen,
490                                                      const unsigned char *from,
491                                                      unsigned char *to,
492                                                      RSA *rsa, int padding);
493 OSSL_DEPRECATEDIN_3_0
494 int RSA_meth_set_pub_enc(RSA_METHOD *rsa,
495                          int (*pub_enc) (int flen, const unsigned char *from,
496                                          unsigned char *to, RSA *rsa,
497                                          int padding));
498 OSSL_DEPRECATEDIN_3_0
499 int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth)) (int flen,
500                                                      const unsigned char *from,
501                                                      unsigned char *to,
502                                                      RSA *rsa, int padding);
503 OSSL_DEPRECATEDIN_3_0
504 int RSA_meth_set_pub_dec(RSA_METHOD *rsa,
505                          int (*pub_dec) (int flen, const unsigned char *from,
506                                          unsigned char *to, RSA *rsa,
507                                          int padding));
508 OSSL_DEPRECATEDIN_3_0
509 int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth)) (int flen,
510                                                       const unsigned char *from,
511                                                       unsigned char *to,
512                                                       RSA *rsa, int padding);
513 OSSL_DEPRECATEDIN_3_0
514 int RSA_meth_set_priv_enc(RSA_METHOD *rsa,
515                           int (*priv_enc) (int flen, const unsigned char *from,
516                                            unsigned char *to, RSA *rsa,
517                                            int padding));
518 OSSL_DEPRECATEDIN_3_0
519 int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth)) (int flen,
520                                                       const unsigned char *from,
521                                                       unsigned char *to,
522                                                       RSA *rsa, int padding);
523 OSSL_DEPRECATEDIN_3_0
524 int RSA_meth_set_priv_dec(RSA_METHOD *rsa,
525                           int (*priv_dec) (int flen, const unsigned char *from,
526                                            unsigned char *to, RSA *rsa,
527                                            int padding));
528 OSSL_DEPRECATEDIN_3_0
529 int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth)) (BIGNUM *r0,
530                                                      const BIGNUM *i,
531                                                      RSA *rsa, BN_CTX *ctx);
532 OSSL_DEPRECATEDIN_3_0
533 int RSA_meth_set_mod_exp(RSA_METHOD *rsa,
534                          int (*mod_exp) (BIGNUM *r0, const BIGNUM *i, RSA *rsa,
535                                          BN_CTX *ctx));
536 OSSL_DEPRECATEDIN_3_0
537 int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth)) (BIGNUM *r,
538                                                         const BIGNUM *a,
539                                                         const BIGNUM *p,
540                                                         const BIGNUM *m,
541                                                         BN_CTX *ctx,
542                                                         BN_MONT_CTX *m_ctx);
543 OSSL_DEPRECATEDIN_3_0
544 int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa,
545                             int (*bn_mod_exp) (BIGNUM *r,
546                                                const BIGNUM *a,
547                                                const BIGNUM *p,
548                                                const BIGNUM *m,
549                                                BN_CTX *ctx,
550                                                BN_MONT_CTX *m_ctx));
551 OSSL_DEPRECATEDIN_3_0
552 int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa);
553 OSSL_DEPRECATEDIN_3_0
554 int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa));
555 OSSL_DEPRECATEDIN_3_0
556 int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa);
557 OSSL_DEPRECATEDIN_3_0
558 int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa));
559 OSSL_DEPRECATEDIN_3_0
560 int (*RSA_meth_get_sign(const RSA_METHOD *meth)) (int type,
561                                                   const unsigned char *m,
562                                                   unsigned int m_length,
563                                                   unsigned char *sigret,
564                                                   unsigned int *siglen,
565                                                   const RSA *rsa);
566 OSSL_DEPRECATEDIN_3_0
567 int RSA_meth_set_sign(RSA_METHOD *rsa,
568                       int (*sign) (int type, const unsigned char *m,
569                                    unsigned int m_length,
570                                    unsigned char *sigret, unsigned int *siglen,
571                                    const RSA *rsa));
572 OSSL_DEPRECATEDIN_3_0
573 int (*RSA_meth_get_verify(const RSA_METHOD *meth)) (int dtype,
574                                                     const unsigned char *m,
575                                                     unsigned int m_length,
576                                                     const unsigned char *sigbuf,
577                                                     unsigned int siglen,
578                                                     const RSA *rsa);
579 OSSL_DEPRECATEDIN_3_0
580 int RSA_meth_set_verify(RSA_METHOD *rsa,
581                         int (*verify) (int dtype, const unsigned char *m,
582                                        unsigned int m_length,
583                                        const unsigned char *sigbuf,
584                                        unsigned int siglen, const RSA *rsa));
585 OSSL_DEPRECATEDIN_3_0
586 int (*RSA_meth_get_keygen(const RSA_METHOD *meth)) (RSA *rsa, int bits,
587                                                     BIGNUM *e, BN_GENCB *cb);
588 OSSL_DEPRECATEDIN_3_0
589 int RSA_meth_set_keygen(RSA_METHOD *rsa,
590                         int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
591                                        BN_GENCB *cb));
592 OSSL_DEPRECATEDIN_3_0
593 int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD *meth)) (RSA *rsa,
594                                                                 int bits,
595                                                                 int primes,
596                                                                 BIGNUM *e,
597                                                                 BN_GENCB *cb);
598 OSSL_DEPRECATEDIN_3_0
599 int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth,
600                                     int (*keygen) (RSA *rsa, int bits,
601                                                    int primes, BIGNUM *e,
602                                                    BN_GENCB *cb));
603 #endif  /* !OPENSSL_NO_DEPRECATED_3_0 */
604
605 # ifdef  __cplusplus
606 }
607 # endif
608 #endif