Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:49

0001 /*
0002  * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
0003  *
0004  * Licensed under the Apache License 2.0 (the "License").  You may not use
0005  * this file except in compliance with the License.  You can obtain a copy
0006  * in the file LICENSE in the source distribution or at
0007  * https://www.openssl.org/source/license.html
0008  */
0009 
0010 #ifndef OPENSSL_RSA_H
0011 # define OPENSSL_RSA_H
0012 # pragma once
0013 
0014 # include <openssl/macros.h>
0015 # ifndef OPENSSL_NO_DEPRECATED_3_0
0016 #  define HEADER_RSA_H
0017 # endif
0018 
0019 # include <openssl/opensslconf.h>
0020 
0021 # include <openssl/asn1.h>
0022 # include <openssl/bio.h>
0023 # include <openssl/crypto.h>
0024 # include <openssl/types.h>
0025 # ifndef OPENSSL_NO_DEPRECATED_1_1_0
0026 #  include <openssl/bn.h>
0027 # endif
0028 # include <openssl/rsaerr.h>
0029 # include <openssl/safestack.h>
0030 # ifndef OPENSSL_NO_STDIO
0031 #  include <stdio.h>
0032 # endif
0033 
0034 # ifdef  __cplusplus
0035 extern "C" {
0036 # endif
0037 
0038 # ifndef OPENSSL_RSA_MAX_MODULUS_BITS
0039 #  define OPENSSL_RSA_MAX_MODULUS_BITS   16384
0040 # endif
0041 
0042 # define RSA_3   0x3L
0043 # define RSA_F4  0x10001L
0044 
0045 # ifndef OPENSSL_NO_DEPRECATED_3_0
0046 /* The types RSA and RSA_METHOD are defined in ossl_typ.h */
0047 
0048 #  define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 2048
0049 
0050 #  ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
0051 #   define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
0052 #  endif
0053 
0054 /* exponent limit enforced for "large" modulus only */
0055 #  ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
0056 #   define OPENSSL_RSA_MAX_PUBEXP_BITS    64
0057 #  endif
0058 /* based on RFC 8017 appendix A.1.2 */
0059 #  define RSA_ASN1_VERSION_DEFAULT        0
0060 #  define RSA_ASN1_VERSION_MULTI          1
0061 
0062 #  define RSA_DEFAULT_PRIME_NUM           2
0063 
0064 #  define RSA_METHOD_FLAG_NO_CHECK        0x0001
0065 #  define RSA_FLAG_CACHE_PUBLIC           0x0002
0066 #  define RSA_FLAG_CACHE_PRIVATE          0x0004
0067 #  define RSA_FLAG_BLINDING               0x0008
0068 #  define RSA_FLAG_THREAD_SAFE            0x0010
0069 /*
0070  * This flag means the private key operations will be handled by rsa_mod_exp
0071  * and that they do not depend on the private key components being present:
0072  * for example a key stored in external hardware. Without this flag
0073  * bn_mod_exp gets called when private key components are absent.
0074  */
0075 #  define RSA_FLAG_EXT_PKEY               0x0020
0076 
0077 /*
0078  * new with 0.9.6j and 0.9.7b; the built-in
0079  * RSA implementation now uses blinding by
0080  * default (ignoring RSA_FLAG_BLINDING),
0081  * but other engines might not need it
0082  */
0083 #  define RSA_FLAG_NO_BLINDING            0x0080
0084 # endif /* OPENSSL_NO_DEPRECATED_3_0 */
0085 /*
0086  * Does nothing. Previously this switched off constant time behaviour.
0087  */
0088 # ifndef OPENSSL_NO_DEPRECATED_1_1_0
0089 #  define RSA_FLAG_NO_CONSTTIME           0x0000
0090 # endif
0091 /* deprecated name for the flag*/
0092 /*
0093  * new with 0.9.7h; the built-in RSA
0094  * implementation now uses constant time
0095  * modular exponentiation for secret exponents
0096  * by default. This flag causes the
0097  * faster variable sliding window method to
0098  * be used for all exponents.
0099  */
0100 # ifndef OPENSSL_NO_DEPRECATED_0_9_8
0101 #  define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME
0102 # endif
0103 
0104 /*-
0105  * New with 3.0: use part of the flags to denote exact type of RSA key,
0106  * some of which are limited to specific signature and encryption schemes.
0107  * These different types share the same RSA structure, but indicate the
0108  * use of certain fields in that structure.
0109  * Currently known are:
0110  * RSA          - this is the "normal" unlimited RSA structure (typenum 0)
0111  * RSASSA-PSS   - indicates that the PSS parameters are used.
0112  * RSAES-OAEP   - no specific field used for the moment, but OAEP padding
0113  *                is expected.  (currently unused)
0114  *
0115  * 4 bits allow for 16 types
0116  */
0117 # define RSA_FLAG_TYPE_MASK            0xF000
0118 # define RSA_FLAG_TYPE_RSA             0x0000
0119 # define RSA_FLAG_TYPE_RSASSAPSS       0x1000
0120 # define RSA_FLAG_TYPE_RSAESOAEP       0x2000
0121 
0122 int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad_mode);
0123 int EVP_PKEY_CTX_get_rsa_padding(EVP_PKEY_CTX *ctx, int *pad_mode);
0124 
0125 int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int saltlen);
0126 int EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int *saltlen);
0127 
0128 int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX *ctx, int bits);
0129 int EVP_PKEY_CTX_set1_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp);
0130 int EVP_PKEY_CTX_set_rsa_keygen_primes(EVP_PKEY_CTX *ctx, int primes);
0131 int EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(EVP_PKEY_CTX *ctx, int saltlen);
0132 # ifndef OPENSSL_NO_DEPRECATED_3_0
0133 OSSL_DEPRECATEDIN_3_0
0134 int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp);
0135 # endif
0136 
0137 /* Salt length matches digest */
0138 # define RSA_PSS_SALTLEN_DIGEST -1
0139 /* Verify only: auto detect salt length */
0140 # define RSA_PSS_SALTLEN_AUTO   -2
0141 /* Set salt length to maximum possible */
0142 # define RSA_PSS_SALTLEN_MAX    -3
0143 /* Auto-detect on verify, set salt length to min(maximum possible, digest
0144  * length) on sign */
0145 # define RSA_PSS_SALTLEN_AUTO_DIGEST_MAX  -4
0146 /* Old compatible max salt length for sign only */
0147 # define RSA_PSS_SALTLEN_MAX_SIGN    -2
0148 
0149 int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
0150 int EVP_PKEY_CTX_set_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, const char *mdname,
0151                                       const char *mdprops);
0152 int EVP_PKEY_CTX_get_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD **md);
0153 int EVP_PKEY_CTX_get_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, char *name,
0154                                       size_t namelen);
0155 int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
0156 int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md_name(EVP_PKEY_CTX *ctx,
0157                                                  const char *mdname);
0158 
0159 int EVP_PKEY_CTX_set_rsa_pss_keygen_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
0160 int EVP_PKEY_CTX_set_rsa_pss_keygen_md_name(EVP_PKEY_CTX *ctx,
0161                                             const char *mdname,
0162                                             const char *mdprops);
0163 
0164 int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
0165 int EVP_PKEY_CTX_set_rsa_oaep_md_name(EVP_PKEY_CTX *ctx, const char *mdname,
0166                                       const char *mdprops);
0167 int EVP_PKEY_CTX_get_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD **md);
0168 int EVP_PKEY_CTX_get_rsa_oaep_md_name(EVP_PKEY_CTX *ctx, char *name,
0169                                       size_t namelen);
0170 int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, void *label, int llen);
0171 int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx, unsigned char **label);
0172 
0173 # define EVP_PKEY_CTRL_RSA_PADDING       (EVP_PKEY_ALG_CTRL + 1)
0174 # define EVP_PKEY_CTRL_RSA_PSS_SALTLEN   (EVP_PKEY_ALG_CTRL + 2)
0175 
0176 # define EVP_PKEY_CTRL_RSA_KEYGEN_BITS   (EVP_PKEY_ALG_CTRL + 3)
0177 # define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4)
0178 # define EVP_PKEY_CTRL_RSA_MGF1_MD       (EVP_PKEY_ALG_CTRL + 5)
0179 
0180 # define EVP_PKEY_CTRL_GET_RSA_PADDING           (EVP_PKEY_ALG_CTRL + 6)
0181 # define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN       (EVP_PKEY_ALG_CTRL + 7)
0182 # define EVP_PKEY_CTRL_GET_RSA_MGF1_MD           (EVP_PKEY_ALG_CTRL + 8)
0183 
0184 # define EVP_PKEY_CTRL_RSA_OAEP_MD       (EVP_PKEY_ALG_CTRL + 9)
0185 # define EVP_PKEY_CTRL_RSA_OAEP_LABEL    (EVP_PKEY_ALG_CTRL + 10)
0186 
0187 # define EVP_PKEY_CTRL_GET_RSA_OAEP_MD   (EVP_PKEY_ALG_CTRL + 11)
0188 # define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12)
0189 
0190 # define EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES  (EVP_PKEY_ALG_CTRL + 13)
0191 
0192 # define EVP_PKEY_CTRL_RSA_IMPLICIT_REJECTION (EVP_PKEY_ALG_CTRL + 14)
0193 
0194 # define RSA_PKCS1_PADDING          1
0195 # define RSA_NO_PADDING             3
0196 # define RSA_PKCS1_OAEP_PADDING     4
0197 # define RSA_X931_PADDING           5
0198 
0199 /* EVP_PKEY_ only */
0200 # define RSA_PKCS1_PSS_PADDING      6
0201 # define RSA_PKCS1_WITH_TLS_PADDING 7
0202 
0203 /* internal RSA_ only */
0204 # define RSA_PKCS1_NO_IMPLICIT_REJECT_PADDING 8
0205 
0206 # define RSA_PKCS1_PADDING_SIZE    11
0207 
0208 # define RSA_set_app_data(s,arg)         RSA_set_ex_data(s,0,arg)
0209 # define RSA_get_app_data(s)             RSA_get_ex_data(s,0)
0210 
0211 # ifndef OPENSSL_NO_DEPRECATED_3_0
0212 OSSL_DEPRECATEDIN_3_0 RSA *RSA_new(void);
0213 OSSL_DEPRECATEDIN_3_0 RSA *RSA_new_method(ENGINE *engine);
0214 OSSL_DEPRECATEDIN_3_0 int RSA_bits(const RSA *rsa);
0215 OSSL_DEPRECATEDIN_3_0 int RSA_size(const RSA *rsa);
0216 OSSL_DEPRECATEDIN_3_0 int RSA_security_bits(const RSA *rsa);
0217 
0218 OSSL_DEPRECATEDIN_3_0 int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
0219 OSSL_DEPRECATEDIN_3_0 int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
0220 OSSL_DEPRECATEDIN_3_0 int RSA_set0_crt_params(RSA *r,
0221                                               BIGNUM *dmp1, BIGNUM *dmq1,
0222                                               BIGNUM *iqmp);
0223 OSSL_DEPRECATEDIN_3_0 int RSA_set0_multi_prime_params(RSA *r,
0224                                                       BIGNUM *primes[],
0225                                                       BIGNUM *exps[],
0226                                                       BIGNUM *coeffs[],
0227                                                       int pnum);
0228 OSSL_DEPRECATEDIN_3_0 void RSA_get0_key(const RSA *r,
0229                                         const BIGNUM **n, const BIGNUM **e,
0230                                         const BIGNUM **d);
0231 OSSL_DEPRECATEDIN_3_0 void RSA_get0_factors(const RSA *r,
0232                                             const BIGNUM **p, const BIGNUM **q);
0233 OSSL_DEPRECATEDIN_3_0 int RSA_get_multi_prime_extra_count(const RSA *r);
0234 OSSL_DEPRECATEDIN_3_0 int RSA_get0_multi_prime_factors(const RSA *r,
0235                                                        const BIGNUM *primes[]);
0236 OSSL_DEPRECATEDIN_3_0 void RSA_get0_crt_params(const RSA *r,
0237                                                const BIGNUM **dmp1,
0238                                                const BIGNUM **dmq1,
0239                                                const BIGNUM **iqmp);
0240 OSSL_DEPRECATEDIN_3_0
0241 int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[],
0242                                     const BIGNUM *coeffs[]);
0243 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_n(const RSA *d);
0244 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_e(const RSA *d);
0245 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_d(const RSA *d);
0246 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_p(const RSA *d);
0247 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_q(const RSA *d);
0248 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_dmp1(const RSA *r);
0249 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_dmq1(const RSA *r);
0250 OSSL_DEPRECATEDIN_3_0 const BIGNUM *RSA_get0_iqmp(const RSA *r);
0251 OSSL_DEPRECATEDIN_3_0 const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r);
0252 OSSL_DEPRECATEDIN_3_0 void RSA_clear_flags(RSA *r, int flags);
0253 OSSL_DEPRECATEDIN_3_0 int RSA_test_flags(const RSA *r, int flags);
0254 OSSL_DEPRECATEDIN_3_0 void RSA_set_flags(RSA *r, int flags);
0255 OSSL_DEPRECATEDIN_3_0 int RSA_get_version(RSA *r);
0256 OSSL_DEPRECATEDIN_3_0 ENGINE *RSA_get0_engine(const RSA *r);
0257 # endif  /* !OPENSSL_NO_DEPRECATED_3_0 */
0258 
0259 # define EVP_RSA_gen(bits) \
0260     EVP_PKEY_Q_keygen(NULL, NULL, "RSA", (size_t)(0 + (bits)))
0261 
0262 /* Deprecated version */
0263 # ifndef OPENSSL_NO_DEPRECATED_0_9_8
0264 OSSL_DEPRECATEDIN_0_9_8 RSA *RSA_generate_key(int bits, unsigned long e, void
0265                                               (*callback) (int, int, void *),
0266                                               void *cb_arg);
0267 # endif
0268 
0269 /* New version */
0270 # ifndef OPENSSL_NO_DEPRECATED_3_0
0271 OSSL_DEPRECATEDIN_3_0 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e,
0272                                               BN_GENCB *cb);
0273 /* Multi-prime version */
0274 OSSL_DEPRECATEDIN_3_0 int RSA_generate_multi_prime_key(RSA *rsa, int bits,
0275                                                        int primes, BIGNUM *e,
0276                                                        BN_GENCB *cb);
0277 
0278 OSSL_DEPRECATEDIN_3_0
0279 int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2,
0280                        BIGNUM *q1, BIGNUM *q2,
0281                        const BIGNUM *Xp1, const BIGNUM *Xp2,
0282                        const BIGNUM *Xp, const BIGNUM *Xq1,
0283                        const BIGNUM *Xq2, const BIGNUM *Xq,
0284                        const BIGNUM *e, BN_GENCB *cb);
0285 OSSL_DEPRECATEDIN_3_0 int RSA_X931_generate_key_ex(RSA *rsa, int bits,
0286                                                    const BIGNUM *e,
0287                                                    BN_GENCB *cb);
0288 
0289 OSSL_DEPRECATEDIN_3_0 int RSA_check_key(const RSA *);
0290 OSSL_DEPRECATEDIN_3_0 int RSA_check_key_ex(const RSA *, BN_GENCB *cb);
0291         /* next 4 return -1 on error */
0292 OSSL_DEPRECATEDIN_3_0
0293 int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
0294                        RSA *rsa, int padding);
0295 OSSL_DEPRECATEDIN_3_0
0296 int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
0297                         RSA *rsa, int padding);
0298 OSSL_DEPRECATEDIN_3_0
0299 int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
0300                        RSA *rsa, int padding);
0301 OSSL_DEPRECATEDIN_3_0
0302 int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
0303                         RSA *rsa, int padding);
0304 OSSL_DEPRECATEDIN_3_0 void RSA_free(RSA *r);
0305 /* "up" the RSA object's reference count */
0306 OSSL_DEPRECATEDIN_3_0 int RSA_up_ref(RSA *r);
0307 OSSL_DEPRECATEDIN_3_0 int RSA_flags(const RSA *r);
0308 
0309 OSSL_DEPRECATEDIN_3_0 void RSA_set_default_method(const RSA_METHOD *meth);
0310 OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_get_default_method(void);
0311 OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_null_method(void);
0312 OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_get_method(const RSA *rsa);
0313 OSSL_DEPRECATEDIN_3_0 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
0314 
0315 /* these are the actual RSA functions */
0316 OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_PKCS1_OpenSSL(void);
0317 
0318 DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(OSSL_DEPRECATEDIN_3_0,
0319                                         RSA, RSAPublicKey)
0320 DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(OSSL_DEPRECATEDIN_3_0,
0321                                         RSA, RSAPrivateKey)
0322 # endif  /* !OPENSSL_NO_DEPRECATED_3_0 */
0323 
0324 int RSA_pkey_ctx_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2);
0325 
0326 struct rsa_pss_params_st {
0327     X509_ALGOR *hashAlgorithm;
0328     X509_ALGOR *maskGenAlgorithm;
0329     ASN1_INTEGER *saltLength;
0330     ASN1_INTEGER *trailerField;
0331     /* Decoded hash algorithm from maskGenAlgorithm */
0332     X509_ALGOR *maskHash;
0333 };
0334 
0335 DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
0336 DECLARE_ASN1_DUP_FUNCTION(RSA_PSS_PARAMS)
0337 
0338 typedef struct rsa_oaep_params_st {
0339     X509_ALGOR *hashFunc;
0340     X509_ALGOR *maskGenFunc;
0341     X509_ALGOR *pSourceFunc;
0342     /* Decoded hash algorithm from maskGenFunc */
0343     X509_ALGOR *maskHash;
0344 } RSA_OAEP_PARAMS;
0345 
0346 DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS)
0347 
0348 # ifndef OPENSSL_NO_DEPRECATED_3_0
0349 #  ifndef OPENSSL_NO_STDIO
0350 OSSL_DEPRECATEDIN_3_0 int RSA_print_fp(FILE *fp, const RSA *r, int offset);
0351 #  endif
0352 
0353 OSSL_DEPRECATEDIN_3_0 int RSA_print(BIO *bp, const RSA *r, int offset);
0354 
0355 /*
0356  * The following 2 functions sign and verify a X509_SIG ASN1 object inside
0357  * PKCS#1 padded RSA encryption
0358  */
0359 OSSL_DEPRECATEDIN_3_0 int RSA_sign(int type, const unsigned char *m,
0360                                    unsigned int m_length, unsigned char *sigret,
0361                                    unsigned int *siglen, RSA *rsa);
0362 OSSL_DEPRECATEDIN_3_0 int RSA_verify(int type, const unsigned char *m,
0363                                      unsigned int m_length,
0364                                      const unsigned char *sigbuf,
0365                                      unsigned int siglen, RSA *rsa);
0366 
0367 /*
0368  * The following 2 function sign and verify a ASN1_OCTET_STRING object inside
0369  * PKCS#1 padded RSA encryption
0370  */
0371 OSSL_DEPRECATEDIN_3_0
0372 int RSA_sign_ASN1_OCTET_STRING(int type,
0373                                const unsigned char *m, unsigned int m_length,
0374                                unsigned char *sigret, unsigned int *siglen,
0375                                RSA *rsa);
0376 OSSL_DEPRECATEDIN_3_0
0377 int RSA_verify_ASN1_OCTET_STRING(int type,
0378                                  const unsigned char *m, unsigned int m_length,
0379                                  unsigned char *sigbuf, unsigned int siglen,
0380                                  RSA *rsa);
0381 
0382 OSSL_DEPRECATEDIN_3_0 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
0383 OSSL_DEPRECATEDIN_3_0 void RSA_blinding_off(RSA *rsa);
0384 OSSL_DEPRECATEDIN_3_0 BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx);
0385 
0386 OSSL_DEPRECATEDIN_3_0
0387 int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
0388                                  const unsigned char *f, int fl);
0389 OSSL_DEPRECATEDIN_3_0
0390 int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
0391                                    const unsigned char *f, int fl,
0392                                    int rsa_len);
0393 OSSL_DEPRECATEDIN_3_0
0394 int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
0395                                  const unsigned char *f, int fl);
0396 OSSL_DEPRECATEDIN_3_0
0397 int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
0398                                    const unsigned char *f, int fl,
0399                                    int rsa_len);
0400 OSSL_DEPRECATEDIN_3_0 int PKCS1_MGF1(unsigned char *mask, long len,
0401                                      const unsigned char *seed, long seedlen,
0402                                      const EVP_MD *dgst);
0403 OSSL_DEPRECATEDIN_3_0
0404 int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
0405                                const unsigned char *f, int fl,
0406                                const unsigned char *p, int pl);
0407 OSSL_DEPRECATEDIN_3_0
0408 int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
0409                                  const unsigned char *f, int fl, int rsa_len,
0410                                  const unsigned char *p, int pl);
0411 OSSL_DEPRECATEDIN_3_0
0412 int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
0413                                     const unsigned char *from, int flen,
0414                                     const unsigned char *param, int plen,
0415                                     const EVP_MD *md, const EVP_MD *mgf1md);
0416 OSSL_DEPRECATEDIN_3_0
0417 int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
0418                                       const unsigned char *from, int flen,
0419                                       int num,
0420                                       const unsigned char *param, int plen,
0421                                       const EVP_MD *md, const EVP_MD *mgf1md);
0422 OSSL_DEPRECATEDIN_3_0 int RSA_padding_add_none(unsigned char *to, int tlen,
0423                                                const unsigned char *f, int fl);
0424 OSSL_DEPRECATEDIN_3_0 int RSA_padding_check_none(unsigned char *to, int tlen,
0425                                                  const unsigned char *f, int fl,
0426                                                  int rsa_len);
0427 OSSL_DEPRECATEDIN_3_0 int RSA_padding_add_X931(unsigned char *to, int tlen,
0428                                                const unsigned char *f, int fl);
0429 OSSL_DEPRECATEDIN_3_0 int RSA_padding_check_X931(unsigned char *to, int tlen,
0430                                                  const unsigned char *f, int fl,
0431                                                  int rsa_len);
0432 OSSL_DEPRECATEDIN_3_0 int RSA_X931_hash_id(int nid);
0433 
0434 OSSL_DEPRECATEDIN_3_0
0435 int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
0436                          const EVP_MD *Hash, const unsigned char *EM,
0437                          int sLen);
0438 OSSL_DEPRECATEDIN_3_0
0439 int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
0440                               const unsigned char *mHash, const EVP_MD *Hash,
0441                               int sLen);
0442 
0443 OSSL_DEPRECATEDIN_3_0
0444 int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
0445                               const EVP_MD *Hash, const EVP_MD *mgf1Hash,
0446                               const unsigned char *EM, int sLen);
0447 
0448 OSSL_DEPRECATEDIN_3_0
0449 int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
0450                                    const unsigned char *mHash,
0451                                    const EVP_MD *Hash, const EVP_MD *mgf1Hash,
0452                                    int sLen);
0453 
0454 # define RSA_get_ex_new_index(l, p, newf, dupf, freef) \
0455     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef)
0456 OSSL_DEPRECATEDIN_3_0 int RSA_set_ex_data(RSA *r, int idx, void *arg);
0457 OSSL_DEPRECATEDIN_3_0 void *RSA_get_ex_data(const RSA *r, int idx);
0458 
0459 DECLARE_ASN1_DUP_FUNCTION_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPublicKey)
0460 DECLARE_ASN1_DUP_FUNCTION_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPrivateKey)
0461 
0462 /*
0463  * If this flag is set the RSA method is FIPS compliant and can be used in
0464  * FIPS mode. This is set in the validated module method. If an application
0465  * sets this flag in its own methods it is its responsibility to ensure the
0466  * result is compliant.
0467  */
0468 
0469 #  define RSA_FLAG_FIPS_METHOD                    0x0400
0470 
0471 /*
0472  * If this flag is set the operations normally disabled in FIPS mode are
0473  * permitted it is then the applications responsibility to ensure that the
0474  * usage is compliant.
0475  */
0476 
0477 #  define RSA_FLAG_NON_FIPS_ALLOW                 0x0400
0478 /*
0479  * Application has decided PRNG is good enough to generate a key: don't
0480  * check.
0481  */
0482 #  define RSA_FLAG_CHECKED                        0x0800
0483 
0484 OSSL_DEPRECATEDIN_3_0 RSA_METHOD *RSA_meth_new(const char *name, int flags);
0485 OSSL_DEPRECATEDIN_3_0 void RSA_meth_free(RSA_METHOD *meth);
0486 OSSL_DEPRECATEDIN_3_0 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
0487 OSSL_DEPRECATEDIN_3_0 const char *RSA_meth_get0_name(const RSA_METHOD *meth);
0488 OSSL_DEPRECATEDIN_3_0 int RSA_meth_set1_name(RSA_METHOD *meth,
0489                                              const char *name);
0490 OSSL_DEPRECATEDIN_3_0 int RSA_meth_get_flags(const RSA_METHOD *meth);
0491 OSSL_DEPRECATEDIN_3_0 int RSA_meth_set_flags(RSA_METHOD *meth, int flags);
0492 OSSL_DEPRECATEDIN_3_0 void *RSA_meth_get0_app_data(const RSA_METHOD *meth);
0493 OSSL_DEPRECATEDIN_3_0 int RSA_meth_set0_app_data(RSA_METHOD *meth,
0494                                                  void *app_data);
0495 OSSL_DEPRECATEDIN_3_0
0496 int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth)) (int flen,
0497                                                      const unsigned char *from,
0498                                                      unsigned char *to,
0499                                                      RSA *rsa, int padding);
0500 OSSL_DEPRECATEDIN_3_0
0501 int RSA_meth_set_pub_enc(RSA_METHOD *rsa,
0502                          int (*pub_enc) (int flen, const unsigned char *from,
0503                                          unsigned char *to, RSA *rsa,
0504                                          int padding));
0505 OSSL_DEPRECATEDIN_3_0
0506 int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth)) (int flen,
0507                                                      const unsigned char *from,
0508                                                      unsigned char *to,
0509                                                      RSA *rsa, int padding);
0510 OSSL_DEPRECATEDIN_3_0
0511 int RSA_meth_set_pub_dec(RSA_METHOD *rsa,
0512                          int (*pub_dec) (int flen, const unsigned char *from,
0513                                          unsigned char *to, RSA *rsa,
0514                                          int padding));
0515 OSSL_DEPRECATEDIN_3_0
0516 int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth)) (int flen,
0517                                                       const unsigned char *from,
0518                                                       unsigned char *to,
0519                                                       RSA *rsa, int padding);
0520 OSSL_DEPRECATEDIN_3_0
0521 int RSA_meth_set_priv_enc(RSA_METHOD *rsa,
0522                           int (*priv_enc) (int flen, const unsigned char *from,
0523                                            unsigned char *to, RSA *rsa,
0524                                            int padding));
0525 OSSL_DEPRECATEDIN_3_0
0526 int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth)) (int flen,
0527                                                       const unsigned char *from,
0528                                                       unsigned char *to,
0529                                                       RSA *rsa, int padding);
0530 OSSL_DEPRECATEDIN_3_0
0531 int RSA_meth_set_priv_dec(RSA_METHOD *rsa,
0532                           int (*priv_dec) (int flen, const unsigned char *from,
0533                                            unsigned char *to, RSA *rsa,
0534                                            int padding));
0535 OSSL_DEPRECATEDIN_3_0
0536 int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth)) (BIGNUM *r0,
0537                                                      const BIGNUM *i,
0538                                                      RSA *rsa, BN_CTX *ctx);
0539 OSSL_DEPRECATEDIN_3_0
0540 int RSA_meth_set_mod_exp(RSA_METHOD *rsa,
0541                          int (*mod_exp) (BIGNUM *r0, const BIGNUM *i, RSA *rsa,
0542                                          BN_CTX *ctx));
0543 OSSL_DEPRECATEDIN_3_0
0544 int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth)) (BIGNUM *r,
0545                                                         const BIGNUM *a,
0546                                                         const BIGNUM *p,
0547                                                         const BIGNUM *m,
0548                                                         BN_CTX *ctx,
0549                                                         BN_MONT_CTX *m_ctx);
0550 OSSL_DEPRECATEDIN_3_0
0551 int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa,
0552                             int (*bn_mod_exp) (BIGNUM *r,
0553                                                const BIGNUM *a,
0554                                                const BIGNUM *p,
0555                                                const BIGNUM *m,
0556                                                BN_CTX *ctx,
0557                                                BN_MONT_CTX *m_ctx));
0558 OSSL_DEPRECATEDIN_3_0
0559 int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa);
0560 OSSL_DEPRECATEDIN_3_0
0561 int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa));
0562 OSSL_DEPRECATEDIN_3_0
0563 int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa);
0564 OSSL_DEPRECATEDIN_3_0
0565 int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa));
0566 OSSL_DEPRECATEDIN_3_0
0567 int (*RSA_meth_get_sign(const RSA_METHOD *meth)) (int type,
0568                                                   const unsigned char *m,
0569                                                   unsigned int m_length,
0570                                                   unsigned char *sigret,
0571                                                   unsigned int *siglen,
0572                                                   const RSA *rsa);
0573 OSSL_DEPRECATEDIN_3_0
0574 int RSA_meth_set_sign(RSA_METHOD *rsa,
0575                       int (*sign) (int type, const unsigned char *m,
0576                                    unsigned int m_length,
0577                                    unsigned char *sigret, unsigned int *siglen,
0578                                    const RSA *rsa));
0579 OSSL_DEPRECATEDIN_3_0
0580 int (*RSA_meth_get_verify(const RSA_METHOD *meth)) (int dtype,
0581                                                     const unsigned char *m,
0582                                                     unsigned int m_length,
0583                                                     const unsigned char *sigbuf,
0584                                                     unsigned int siglen,
0585                                                     const RSA *rsa);
0586 OSSL_DEPRECATEDIN_3_0
0587 int RSA_meth_set_verify(RSA_METHOD *rsa,
0588                         int (*verify) (int dtype, const unsigned char *m,
0589                                        unsigned int m_length,
0590                                        const unsigned char *sigbuf,
0591                                        unsigned int siglen, const RSA *rsa));
0592 OSSL_DEPRECATEDIN_3_0
0593 int (*RSA_meth_get_keygen(const RSA_METHOD *meth)) (RSA *rsa, int bits,
0594                                                     BIGNUM *e, BN_GENCB *cb);
0595 OSSL_DEPRECATEDIN_3_0
0596 int RSA_meth_set_keygen(RSA_METHOD *rsa,
0597                         int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
0598                                        BN_GENCB *cb));
0599 OSSL_DEPRECATEDIN_3_0
0600 int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD *meth)) (RSA *rsa,
0601                                                                 int bits,
0602                                                                 int primes,
0603                                                                 BIGNUM *e,
0604                                                                 BN_GENCB *cb);
0605 OSSL_DEPRECATEDIN_3_0
0606 int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth,
0607                                     int (*keygen) (RSA *rsa, int bits,
0608                                                    int primes, BIGNUM *e,
0609                                                    BN_GENCB *cb));
0610 #endif  /* !OPENSSL_NO_DEPRECATED_3_0 */
0611 
0612 # ifdef  __cplusplus
0613 }
0614 # endif
0615 #endif