156083Skris/* crypto/rsa/rsa.h */
256083Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
356083Skris * All rights reserved.
456083Skris *
556083Skris * This package is an SSL implementation written
656083Skris * by Eric Young (eay@cryptsoft.com).
756083Skris * The implementation was written so as to conform with Netscapes SSL.
8296465Sdelphij *
956083Skris * This library is free for commercial and non-commercial use as long as
1056083Skris * the following conditions are aheared to.  The following conditions
1156083Skris * apply to all code found in this distribution, be it the RC4, RSA,
1256083Skris * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1356083Skris * included with this distribution is covered by the same copyright terms
1456083Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15296465Sdelphij *
1656083Skris * Copyright remains Eric Young's, and as such any Copyright notices in
1756083Skris * the code are not to be removed.
1856083Skris * If this package is used in a product, Eric Young should be given attribution
1956083Skris * as the author of the parts of the library used.
2056083Skris * This can be in the form of a textual message at program startup or
2156083Skris * in documentation (online or textual) provided with the package.
22296465Sdelphij *
2356083Skris * Redistribution and use in source and binary forms, with or without
2456083Skris * modification, are permitted provided that the following conditions
2556083Skris * are met:
2656083Skris * 1. Redistributions of source code must retain the copyright
2756083Skris *    notice, this list of conditions and the following disclaimer.
2856083Skris * 2. Redistributions in binary form must reproduce the above copyright
2956083Skris *    notice, this list of conditions and the following disclaimer in the
3056083Skris *    documentation and/or other materials provided with the distribution.
3156083Skris * 3. All advertising materials mentioning features or use of this software
3256083Skris *    must display the following acknowledgement:
3356083Skris *    "This product includes cryptographic software written by
3456083Skris *     Eric Young (eay@cryptsoft.com)"
3556083Skris *    The word 'cryptographic' can be left out if the rouines from the library
3656083Skris *    being used are not cryptographic related :-).
37296465Sdelphij * 4. If you include any Windows specific code (or a derivative thereof) from
3856083Skris *    the apps directory (application code) you must include an acknowledgement:
3956083Skris *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40296465Sdelphij *
4156083Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4256083Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4356083Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4456083Skris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4556083Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4656083Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4756083Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4856083Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4956083Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5056083Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5156083Skris * SUCH DAMAGE.
52296465Sdelphij *
5356083Skris * The licence and distribution terms for any publically available version or
5456083Skris * derivative of this code cannot be changed.  i.e. this code cannot simply be
5556083Skris * copied and put under another distribution licence
5656083Skris * [including the GNU Public Licence.]
5756083Skris */
5856083Skris
5956083Skris#ifndef HEADER_RSA_H
60296465Sdelphij# define HEADER_RSA_H
6156083Skris
62296465Sdelphij# include <openssl/asn1.h>
63110007Smarkm
64296465Sdelphij# ifndef OPENSSL_NO_BIO
65296465Sdelphij#  include <openssl/bio.h>
66296465Sdelphij# endif
67296465Sdelphij# include <openssl/crypto.h>
68296465Sdelphij# include <openssl/ossl_typ.h>
69296465Sdelphij# ifndef OPENSSL_NO_DEPRECATED
70296465Sdelphij#  include <openssl/bn.h>
71296465Sdelphij# endif
7256083Skris
73296465Sdelphij# ifdef OPENSSL_NO_RSA
74296465Sdelphij#  error RSA is disabled.
75296465Sdelphij# endif
7656083Skris
77296465Sdelphij/*
78296465Sdelphij * If this flag is set the RSA method is FIPS compliant and can be used in
79296465Sdelphij * FIPS mode. This is set in the validated module method. If an application
80296465Sdelphij * sets this flag in its own methods it is its reposibility to ensure the
81296465Sdelphij * result is compliant.
82194206Ssimon */
83194206Ssimon
84296465Sdelphij# define RSA_FLAG_FIPS_METHOD                    0x0400
85194206Ssimon
86296465Sdelphij/*
87296465Sdelphij * If this flag is set the operations normally disabled in FIPS mode are
88194206Ssimon * permitted it is then the applications responsibility to ensure that the
89194206Ssimon * usage is compliant.
90194206Ssimon */
91194206Ssimon
92296465Sdelphij# define RSA_FLAG_NON_FIPS_ALLOW                 0x0400
93194206Ssimon
94296465Sdelphij# ifdef OPENSSL_FIPS
95296465Sdelphij#  define FIPS_RSA_SIZE_T int
96296465Sdelphij# endif
97194206Ssimon
9868654Skris#ifdef  __cplusplus
9968654Skrisextern "C" {
10068654Skris#endif
10168654Skris
102160817Ssimon/* Declared already in ossl_typ.h */
103160817Ssimon/* typedef struct rsa_st RSA; */
104160817Ssimon/* typedef struct rsa_meth_st RSA_METHOD; */
10556083Skris
106296465Sdelphijstruct rsa_meth_st {
107296465Sdelphij    const char *name;
108296465Sdelphij    int (*rsa_pub_enc) (int flen, const unsigned char *from,
109296465Sdelphij                        unsigned char *to, RSA *rsa, int padding);
110296465Sdelphij    int (*rsa_pub_dec) (int flen, const unsigned char *from,
111296465Sdelphij                        unsigned char *to, RSA *rsa, int padding);
112296465Sdelphij    int (*rsa_priv_enc) (int flen, const unsigned char *from,
113296465Sdelphij                         unsigned char *to, RSA *rsa, int padding);
114296465Sdelphij    int (*rsa_priv_dec) (int flen, const unsigned char *from,
115296465Sdelphij                         unsigned char *to, RSA *rsa, int padding);
116296465Sdelphij    /* Can be null */
117296465Sdelphij    int (*rsa_mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
118296465Sdelphij    /* Can be null */
119296465Sdelphij    int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
120296465Sdelphij                       const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
121296465Sdelphij    /* called at new */
122296465Sdelphij    int (*init) (RSA *rsa);
123296465Sdelphij    /* called at free */
124296465Sdelphij    int (*finish) (RSA *rsa);
125296465Sdelphij    /* RSA_METHOD_FLAG_* things */
126296465Sdelphij    int flags;
127296465Sdelphij    /* may be needed! */
128296465Sdelphij    char *app_data;
129296465Sdelphij    /*
130296465Sdelphij     * New sign and verify functions: some libraries don't allow arbitrary
131296465Sdelphij     * data to be signed/verified: this allows them to be used. Note: for
132296465Sdelphij     * this to work the RSA_public_decrypt() and RSA_private_encrypt() should
133296465Sdelphij     * *NOT* be used RSA_sign(), RSA_verify() should be used instead. Note:
134296465Sdelphij     * for backwards compatibility this functionality is only enabled if the
135296465Sdelphij     * RSA_FLAG_SIGN_VER option is set in 'flags'.
136296465Sdelphij     */
137296465Sdelphij    int (*rsa_sign) (int type,
138296465Sdelphij                     const unsigned char *m, unsigned int m_length,
139296465Sdelphij                     unsigned char *sigret, unsigned int *siglen,
140296465Sdelphij                     const RSA *rsa);
141296465Sdelphij    int (*rsa_verify) (int dtype, const unsigned char *m,
142296465Sdelphij                       unsigned int m_length, unsigned char *sigbuf,
143296465Sdelphij                       unsigned int siglen, const RSA *rsa);
144296465Sdelphij    /*
145296465Sdelphij     * If this callback is NULL, the builtin software RSA key-gen will be
146296465Sdelphij     * used. This is for behavioural compatibility whilst the code gets
147296465Sdelphij     * rewired, but one day it would be nice to assume there are no such
148296465Sdelphij     * things as "builtin software" implementations.
149296465Sdelphij     */
150296465Sdelphij    int (*rsa_keygen) (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
151296465Sdelphij};
152100931Snectar
153296465Sdelphijstruct rsa_st {
154296465Sdelphij    /*
155296465Sdelphij     * The first parameter is used to pickup errors where this is passed
156296465Sdelphij     * instead of aEVP_PKEY, it is set to 0
157296465Sdelphij     */
158296465Sdelphij    int pad;
159296465Sdelphij    long version;
160296465Sdelphij    const RSA_METHOD *meth;
161296465Sdelphij    /* functional reference if 'meth' is ENGINE-provided */
162296465Sdelphij    ENGINE *engine;
163296465Sdelphij    BIGNUM *n;
164296465Sdelphij    BIGNUM *e;
165296465Sdelphij    BIGNUM *d;
166296465Sdelphij    BIGNUM *p;
167296465Sdelphij    BIGNUM *q;
168296465Sdelphij    BIGNUM *dmp1;
169296465Sdelphij    BIGNUM *dmq1;
170296465Sdelphij    BIGNUM *iqmp;
171296465Sdelphij    /* be careful using this if the RSA structure is shared */
172296465Sdelphij    CRYPTO_EX_DATA ex_data;
173296465Sdelphij    int references;
174296465Sdelphij    int flags;
175296465Sdelphij    /* Used to cache montgomery values */
176296465Sdelphij    BN_MONT_CTX *_method_mod_n;
177296465Sdelphij    BN_MONT_CTX *_method_mod_p;
178296465Sdelphij    BN_MONT_CTX *_method_mod_q;
179296465Sdelphij    /*
180296465Sdelphij     * all BIGNUM values are actually in the following data, if it is not
181296465Sdelphij     * NULL
182296465Sdelphij     */
183296465Sdelphij    char *bignum_data;
184296465Sdelphij    BN_BLINDING *blinding;
185296465Sdelphij    BN_BLINDING *mt_blinding;
186296465Sdelphij};
18756083Skris
188296465Sdelphij# ifndef OPENSSL_RSA_MAX_MODULUS_BITS
189296465Sdelphij#  define OPENSSL_RSA_MAX_MODULUS_BITS   16384
190296465Sdelphij# endif
19156083Skris
192296465Sdelphij# define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 1024
19356083Skris
194296465Sdelphij# ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
195296465Sdelphij#  define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
196296465Sdelphij# endif
197296465Sdelphij# ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
198162914Ssimon
199296465Sdelphij/* exponent limit enforced for "large" modulus only */
200296465Sdelphij#  define OPENSSL_RSA_MAX_PUBEXP_BITS    64
201296465Sdelphij# endif
202194206Ssimon
203296465Sdelphij# define RSA_3   0x3L
204296465Sdelphij# define RSA_F4  0x10001L
205162914Ssimon
206296465Sdelphij# define RSA_METHOD_FLAG_NO_CHECK        0x0001/* don't check pub/private
207296465Sdelphij                                                * match */
20856083Skris
209296465Sdelphij# define RSA_FLAG_CACHE_PUBLIC           0x0002
210296465Sdelphij# define RSA_FLAG_CACHE_PRIVATE          0x0004
211296465Sdelphij# define RSA_FLAG_BLINDING               0x0008
212296465Sdelphij# define RSA_FLAG_THREAD_SAFE            0x0010
213296465Sdelphij/*
214296465Sdelphij * This flag means the private key operations will be handled by rsa_mod_exp
21556083Skris * and that they do not depend on the private key components being present:
216296465Sdelphij * for example a key stored in external hardware. Without this flag
217296465Sdelphij * bn_mod_exp gets called when private key components are absent.
21856083Skris */
219296465Sdelphij# define RSA_FLAG_EXT_PKEY               0x0020
22056083Skris
221296465Sdelphij/*
222296465Sdelphij * This flag in the RSA_METHOD enables the new rsa_sign, rsa_verify
223296465Sdelphij * functions.
22459194Skris */
225296465Sdelphij# define RSA_FLAG_SIGN_VER               0x0040
22659194Skris
227296465Sdelphij/*
228296465Sdelphij * new with 0.9.6j and 0.9.7b; the built-in
229296465Sdelphij * RSA implementation now uses blinding by
230296465Sdelphij * default (ignoring RSA_FLAG_BLINDING),
231296465Sdelphij * but other engines might not need it
232296465Sdelphij */
233296465Sdelphij# define RSA_FLAG_NO_BLINDING            0x0080
234296465Sdelphij/*
235296465Sdelphij * new with 0.9.8f; the built-in RSA
236296465Sdelphij * implementation now uses constant time
237296465Sdelphij * operations by default in private key operations,
238296465Sdelphij * e.g., constant time modular exponentiation,
239296465Sdelphij * modular inverse without leaking branches,
240296465Sdelphij * division without leaking branches. This
241296465Sdelphij * flag disables these constant time
242296465Sdelphij * operations and results in faster RSA
243296465Sdelphij * private key operations.
244296465Sdelphij */
245296465Sdelphij# define RSA_FLAG_NO_CONSTTIME           0x0100
246296465Sdelphij# ifdef OPENSSL_USE_DEPRECATED
247296465Sdelphij/* deprecated name for the flag*/
248296465Sdelphij/*
249296465Sdelphij * new with 0.9.7h; the built-in RSA
250296465Sdelphij * implementation now uses constant time
251296465Sdelphij * modular exponentiation for secret exponents
252296465Sdelphij * by default. This flag causes the
253296465Sdelphij * faster variable sliding window method to
254296465Sdelphij * be used for all exponents.
255296465Sdelphij */
256296465Sdelphij#  define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME
257296465Sdelphij# endif
258120635Snectar
259296465Sdelphij# define RSA_PKCS1_PADDING       1
260296465Sdelphij# define RSA_SSLV23_PADDING      2
261296465Sdelphij# define RSA_NO_PADDING          3
262296465Sdelphij# define RSA_PKCS1_OAEP_PADDING  4
263296465Sdelphij# define RSA_X931_PADDING        5
264194206Ssimon
265296465Sdelphij# define RSA_PKCS1_PADDING_SIZE  11
26656083Skris
267296465Sdelphij# define RSA_set_app_data(s,arg)         RSA_set_ex_data(s,0,arg)
268296465Sdelphij# define RSA_get_app_data(s)             RSA_get_ex_data(s,0)
269110007Smarkm
270296465SdelphijRSA *RSA_new(void);
271296465SdelphijRSA *RSA_new_method(ENGINE *engine);
272296465Sdelphijint RSA_size(const RSA *);
27356083Skris
274160817Ssimon/* Deprecated version */
275296465Sdelphij# ifndef OPENSSL_NO_DEPRECATED
276296465SdelphijRSA *RSA_generate_key(int bits, unsigned long e, void
277296465Sdelphij                       (*callback) (int, int, void *), void *cb_arg);
278296465Sdelphij# endif                         /* !defined(OPENSSL_NO_DEPRECATED) */
279160817Ssimon
280160817Ssimon/* New version */
281296465Sdelphijint RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
282296465Sdelphijint RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
283296465Sdelphij                       BIGNUM *q2, const BIGNUM *Xp1, const BIGNUM *Xp2,
284296465Sdelphij                       const BIGNUM *Xp, const BIGNUM *Xq1, const BIGNUM *Xq2,
285296465Sdelphij                       const BIGNUM *Xq, const BIGNUM *e, BN_GENCB *cb);
286296465Sdelphijint RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
287296465Sdelphij                             BN_GENCB *cb);
288160817Ssimon
289296465Sdelphijint RSA_check_key(const RSA *);
290296465Sdelphij        /* next 4 return -1 on error */
291296465Sdelphijint RSA_public_encrypt(int flen, const unsigned char *from,
292296465Sdelphij                       unsigned char *to, RSA *rsa, int padding);
293296465Sdelphijint RSA_private_encrypt(int flen, const unsigned char *from,
294296465Sdelphij                        unsigned char *to, RSA *rsa, int padding);
295296465Sdelphijint RSA_public_decrypt(int flen, const unsigned char *from,
296296465Sdelphij                       unsigned char *to, RSA *rsa, int padding);
297296465Sdelphijint RSA_private_decrypt(int flen, const unsigned char *from,
298296465Sdelphij                        unsigned char *to, RSA *rsa, int padding);
299296465Sdelphijvoid RSA_free(RSA *r);
300110007Smarkm/* "up" the RSA object's reference count */
301296465Sdelphijint RSA_up_ref(RSA *r);
30256083Skris
303296465Sdelphijint RSA_flags(const RSA *r);
30456083Skris
305296465Sdelphij# ifdef OPENSSL_FIPS
306194206SsimonRSA *FIPS_rsa_new(void);
307194206Ssimonvoid FIPS_rsa_free(RSA *r);
308296465Sdelphij# endif
309194206Ssimon
310110007Smarkmvoid RSA_set_default_method(const RSA_METHOD *meth);
311110007Smarkmconst RSA_METHOD *RSA_get_default_method(void);
312110007Smarkmconst RSA_METHOD *RSA_get_method(const RSA *rsa);
313110007Smarkmint RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
31456083Skris
31556083Skris/* This function needs the memory locking malloc callbacks to be installed */
31656083Skrisint RSA_memory_lock(RSA *r);
31756083Skris
31856083Skris/* these are the actual SSLeay RSA functions */
319110007Smarkmconst RSA_METHOD *RSA_PKCS1_SSLeay(void);
32056083Skris
321110007Smarkmconst RSA_METHOD *RSA_null_method(void);
32259194Skris
323110007SmarkmDECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey)
324110007SmarkmDECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey)
325110007Smarkm
326296465Sdelphij# ifndef OPENSSL_NO_FP_API
327296465Sdelphijint RSA_print_fp(FILE *fp, const RSA *r, int offset);
328296465Sdelphij# endif
32956083Skris
330296465Sdelphij# ifndef OPENSSL_NO_BIO
331296465Sdelphijint RSA_print(BIO *bp, const RSA *r, int offset);
332296465Sdelphij# endif
33356083Skris
334296465Sdelphij# ifndef OPENSSL_NO_RC4
335160817Ssimonint i2d_RSA_NET(const RSA *a, unsigned char **pp,
336296465Sdelphij                int (*cb) (char *buf, int len, const char *prompt,
337296465Sdelphij                           int verify), int sgckey);
338160817SsimonRSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length,
339296465Sdelphij                 int (*cb) (char *buf, int len, const char *prompt,
340296465Sdelphij                            int verify), int sgckey);
34168654Skris
342160817Ssimonint i2d_Netscape_RSA(const RSA *a, unsigned char **pp,
343296465Sdelphij                     int (*cb) (char *buf, int len, const char *prompt,
344296465Sdelphij                                int verify));
345160817SsimonRSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length,
346296465Sdelphij                      int (*cb) (char *buf, int len, const char *prompt,
347296465Sdelphij                                 int verify));
348296465Sdelphij# endif
34956083Skris
350296465Sdelphij/*
351296465Sdelphij * The following 2 functions sign and verify a X509_SIG ASN1 object inside
352296465Sdelphij * PKCS#1 padded RSA encryption
353296465Sdelphij */
354110007Smarkmint RSA_sign(int type, const unsigned char *m, unsigned int m_length,
355296465Sdelphij             unsigned char *sigret, unsigned int *siglen, RSA *rsa);
356110007Smarkmint RSA_verify(int type, const unsigned char *m, unsigned int m_length,
357296465Sdelphij               unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
35856083Skris
359296465Sdelphij/*
360296465Sdelphij * The following 2 function sign and verify a ASN1_OCTET_STRING object inside
361296465Sdelphij * PKCS#1 padded RSA encryption
362296465Sdelphij */
363110007Smarkmint RSA_sign_ASN1_OCTET_STRING(int type,
364296465Sdelphij                               const unsigned char *m, unsigned int m_length,
365296465Sdelphij                               unsigned char *sigret, unsigned int *siglen,
366296465Sdelphij                               RSA *rsa);
367296465Sdelphijint RSA_verify_ASN1_OCTET_STRING(int type, const unsigned char *m,
368296465Sdelphij                                 unsigned int m_length, unsigned char *sigbuf,
369296465Sdelphij                                 unsigned int siglen, RSA *rsa);
37056083Skris
37156083Skrisint RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
37256083Skrisvoid RSA_blinding_off(RSA *rsa);
373160817SsimonBN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx);
37456083Skris
375296465Sdelphijint RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
376296465Sdelphij                                 const unsigned char *f, int fl);
377296465Sdelphijint RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
378296465Sdelphij                                   const unsigned char *f, int fl,
379296465Sdelphij                                   int rsa_len);
380296465Sdelphijint RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
381296465Sdelphij                                 const unsigned char *f, int fl);
382296465Sdelphijint RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
383296465Sdelphij                                   const unsigned char *f, int fl,
384296465Sdelphij                                   int rsa_len);
385296465Sdelphijint PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed,
386296465Sdelphij               long seedlen, const EVP_MD *dgst);
387296465Sdelphijint RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
388296465Sdelphij                               const unsigned char *f, int fl,
389296465Sdelphij                               const unsigned char *p, int pl);
390296465Sdelphijint RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
391296465Sdelphij                                 const unsigned char *f, int fl, int rsa_len,
392296465Sdelphij                                 const unsigned char *p, int pl);
393296465Sdelphijint RSA_padding_add_SSLv23(unsigned char *to, int tlen,
394296465Sdelphij                           const unsigned char *f, int fl);
395296465Sdelphijint RSA_padding_check_SSLv23(unsigned char *to, int tlen,
396296465Sdelphij                             const unsigned char *f, int fl, int rsa_len);
397296465Sdelphijint RSA_padding_add_none(unsigned char *to, int tlen, const unsigned char *f,
398296465Sdelphij                         int fl);
399296465Sdelphijint RSA_padding_check_none(unsigned char *to, int tlen,
400296465Sdelphij                           const unsigned char *f, int fl, int rsa_len);
401296465Sdelphijint RSA_padding_add_X931(unsigned char *to, int tlen, const unsigned char *f,
402296465Sdelphij                         int fl);
403296465Sdelphijint RSA_padding_check_X931(unsigned char *to, int tlen,
404296465Sdelphij                           const unsigned char *f, int fl, int rsa_len);
405160817Ssimonint RSA_X931_hash_id(int nid);
40656083Skris
407160817Ssimonint RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
408296465Sdelphij                         const EVP_MD *Hash, const unsigned char *EM,
409296465Sdelphij                         int sLen);
410160817Ssimonint RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
411296465Sdelphij                              const unsigned char *mHash, const EVP_MD *Hash,
412296465Sdelphij                              int sLen);
413160817Ssimon
41459194Skrisint RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
415296465Sdelphij                         CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
416296465Sdelphijint RSA_set_ex_data(RSA *r, int idx, void *arg);
417110007Smarkmvoid *RSA_get_ex_data(const RSA *r, int idx);
41857971Skris
419110007SmarkmRSA *RSAPublicKey_dup(RSA *rsa);
420110007SmarkmRSA *RSAPrivateKey_dup(RSA *rsa);
421110007Smarkm
42256083Skris/* BEGIN ERROR CODES */
423296465Sdelphij/*
424296465Sdelphij * The following lines are auto generated by the script mkerr.pl. Any changes
42556083Skris * made after this point may be overwritten when the script is next run.
42656083Skris */
42789840Skrisvoid ERR_load_RSA_strings(void);
42856083Skris
42956083Skris/* Error codes for the RSA functions. */
43056083Skris
43156083Skris/* Function codes. */
432296465Sdelphij# define RSA_F_FIPS_RSA_SIGN                              140
433296465Sdelphij# define RSA_F_FIPS_RSA_VERIFY                            141
434296465Sdelphij# define RSA_F_MEMORY_LOCK                                100
435296465Sdelphij# define RSA_F_RSA_BUILTIN_KEYGEN                         129
436296465Sdelphij# define RSA_F_RSA_CHECK_KEY                              123
437296465Sdelphij# define RSA_F_RSA_EAY_PRIVATE_DECRYPT                    101
438296465Sdelphij# define RSA_F_RSA_EAY_PRIVATE_ENCRYPT                    102
439296465Sdelphij# define RSA_F_RSA_EAY_PUBLIC_DECRYPT                     103
440296465Sdelphij# define RSA_F_RSA_EAY_PUBLIC_ENCRYPT                     104
441296465Sdelphij# define RSA_F_RSA_GENERATE_KEY                           105
442296465Sdelphij# define RSA_F_RSA_MEMORY_LOCK                            130
443296465Sdelphij# define RSA_F_RSA_NEW_METHOD                             106
444296465Sdelphij# define RSA_F_RSA_NULL                                   124
445296465Sdelphij# define RSA_F_RSA_NULL_MOD_EXP                           131
446296465Sdelphij# define RSA_F_RSA_NULL_PRIVATE_DECRYPT                   132
447296465Sdelphij# define RSA_F_RSA_NULL_PRIVATE_ENCRYPT                   133
448296465Sdelphij# define RSA_F_RSA_NULL_PUBLIC_DECRYPT                    134
449296465Sdelphij# define RSA_F_RSA_NULL_PUBLIC_ENCRYPT                    135
450296465Sdelphij# define RSA_F_RSA_PADDING_ADD_NONE                       107
451296465Sdelphij# define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP                 121
452296465Sdelphij# define RSA_F_RSA_PADDING_ADD_PKCS1_PSS                  125
453296465Sdelphij# define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1               108
454296465Sdelphij# define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2               109
455296465Sdelphij# define RSA_F_RSA_PADDING_ADD_SSLV23                     110
456296465Sdelphij# define RSA_F_RSA_PADDING_ADD_X931                       127
457296465Sdelphij# define RSA_F_RSA_PADDING_CHECK_NONE                     111
458296465Sdelphij# define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP               122
459296465Sdelphij# define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1             112
460296465Sdelphij# define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2             113
461296465Sdelphij# define RSA_F_RSA_PADDING_CHECK_SSLV23                   114
462296465Sdelphij# define RSA_F_RSA_PADDING_CHECK_X931                     128
463296465Sdelphij# define RSA_F_RSA_PRINT                                  115
464296465Sdelphij# define RSA_F_RSA_PRINT_FP                               116
465296465Sdelphij# define RSA_F_RSA_PRIVATE_ENCRYPT                        137
466296465Sdelphij# define RSA_F_RSA_PUBLIC_DECRYPT                         138
467296465Sdelphij# define RSA_F_RSA_SETUP_BLINDING                         136
468296465Sdelphij# define RSA_F_RSA_SET_DEFAULT_METHOD                     139
469296465Sdelphij# define RSA_F_RSA_SET_METHOD                             142
470296465Sdelphij# define RSA_F_RSA_SIGN                                   117
471296465Sdelphij# define RSA_F_RSA_SIGN_ASN1_OCTET_STRING                 118
472296465Sdelphij# define RSA_F_RSA_VERIFY                                 119
473296465Sdelphij# define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING               120
474296465Sdelphij# define RSA_F_RSA_VERIFY_PKCS1_PSS                       126
47556083Skris
47656083Skris/* Reason codes. */
477296465Sdelphij# define RSA_R_ALGORITHM_MISMATCH                         100
478296465Sdelphij# define RSA_R_BAD_E_VALUE                                101
479296465Sdelphij# define RSA_R_BAD_FIXED_HEADER_DECRYPT                   102
480296465Sdelphij# define RSA_R_BAD_PAD_BYTE_COUNT                         103
481296465Sdelphij# define RSA_R_BAD_SIGNATURE                              104
482296465Sdelphij# define RSA_R_BLOCK_TYPE_IS_NOT_01                       106
483296465Sdelphij# define RSA_R_BLOCK_TYPE_IS_NOT_02                       107
484296465Sdelphij# define RSA_R_DATA_GREATER_THAN_MOD_LEN                  108
485296465Sdelphij# define RSA_R_DATA_TOO_LARGE                             109
486296465Sdelphij# define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE                110
487296465Sdelphij# define RSA_R_DATA_TOO_LARGE_FOR_MODULUS                 132
488296465Sdelphij# define RSA_R_DATA_TOO_SMALL                             111
489296465Sdelphij# define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE                122
490296465Sdelphij# define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY                 112
491296465Sdelphij# define RSA_R_DMP1_NOT_CONGRUENT_TO_D                    124
492296465Sdelphij# define RSA_R_DMQ1_NOT_CONGRUENT_TO_D                    125
493296465Sdelphij# define RSA_R_D_E_NOT_CONGRUENT_TO_1                     123
494296465Sdelphij# define RSA_R_FIRST_OCTET_INVALID                        133
495296465Sdelphij# define RSA_R_INVALID_HEADER                             137
496296465Sdelphij# define RSA_R_INVALID_MESSAGE_LENGTH                     131
497296465Sdelphij# define RSA_R_INVALID_PADDING                            138
498296465Sdelphij# define RSA_R_INVALID_TRAILER                            139
499296465Sdelphij# define RSA_R_IQMP_NOT_INVERSE_OF_Q                      126
500296465Sdelphij# define RSA_R_KEY_SIZE_TOO_SMALL                         120
501296465Sdelphij# define RSA_R_LAST_OCTET_INVALID                         134
502296465Sdelphij# define RSA_R_MODULUS_TOO_LARGE                          105
503296465Sdelphij# define RSA_R_NON_FIPS_METHOD                            141
504296465Sdelphij# define RSA_R_NO_PUBLIC_EXPONENT                         140
505296465Sdelphij# define RSA_R_NULL_BEFORE_BLOCK_MISSING                  113
506296465Sdelphij# define RSA_R_N_DOES_NOT_EQUAL_P_Q                       127
507296465Sdelphij# define RSA_R_OAEP_DECODING_ERROR                        121
508296465Sdelphij# define RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE         142
509296465Sdelphij# define RSA_R_PADDING_CHECK_FAILED                       114
510296465Sdelphij# define RSA_R_PKCS_DECODING_ERROR                        159
511296465Sdelphij# define RSA_R_P_NOT_PRIME                                128
512296465Sdelphij# define RSA_R_Q_NOT_PRIME                                129
513296465Sdelphij# define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED               130
514296465Sdelphij# define RSA_R_SLEN_CHECK_FAILED                          136
515296465Sdelphij# define RSA_R_SLEN_RECOVERY_FAILED                       135
516296465Sdelphij# define RSA_R_SSLV3_ROLLBACK_ATTACK                      115
517296465Sdelphij# define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
518296465Sdelphij# define RSA_R_UNKNOWN_ALGORITHM_TYPE                     117
519296465Sdelphij# define RSA_R_UNKNOWN_PADDING_TYPE                       118
520296465Sdelphij# define RSA_R_WRONG_SIGNATURE_LENGTH                     119
52156083Skris
52256083Skris#ifdef  __cplusplus
52356083Skris}
52456083Skris#endif
52556083Skris#endif
526