Make the RSA_METHOD structure opaque
[openssl.git] / include / openssl / rsa.h
1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young (eay@cryptsoft.com).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to.  The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  *    must display the following acknowledgement:
32  *    "This product includes cryptographic software written by
33  *     Eric Young (eay@cryptsoft.com)"
34  *    The word 'cryptographic' can be left out if the rouines from the library
35  *    being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  *    the apps directory (application code) you must include an acknowledgement:
38  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed.  i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.]
56  */
57
58 #ifndef HEADER_RSA_H
59 # define HEADER_RSA_H
60
61 # include <openssl/opensslconf.h>
62
63 # ifndef OPENSSL_NO_RSA
64 # include <openssl/asn1.h>
65 # include <openssl/bio.h>
66 # include <openssl/crypto.h>
67 # include <openssl/ossl_typ.h>
68 # if OPENSSL_API_COMPAT < 0x10100000L
69 #  include <openssl/bn.h>
70 # endif
71 # ifdef  __cplusplus
72 extern "C" {
73 # endif
74
75 /* The types RSA and RSA_METHOD are defined in ossl_typ.h */
76
77 # ifndef OPENSSL_RSA_MAX_MODULUS_BITS
78 #  define OPENSSL_RSA_MAX_MODULUS_BITS   16384
79 # endif
80
81 # define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 1024
82
83 # ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
84 #  define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
85 # endif
86 # ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
87
88 /* exponent limit enforced for "large" modulus only */
89 #  define OPENSSL_RSA_MAX_PUBEXP_BITS    64
90 # endif
91
92 # define RSA_3   0x3L
93 # define RSA_F4  0x10001L
94
95 # define RSA_METHOD_FLAG_NO_CHECK        0x0001/* don't check pub/private
96                                                 * match */
97
98 # define RSA_FLAG_CACHE_PUBLIC           0x0002
99 # define RSA_FLAG_CACHE_PRIVATE          0x0004
100 # define RSA_FLAG_BLINDING               0x0008
101 # define RSA_FLAG_THREAD_SAFE            0x0010
102 /*
103  * This flag means the private key operations will be handled by rsa_mod_exp
104  * and that they do not depend on the private key components being present:
105  * for example a key stored in external hardware. Without this flag
106  * bn_mod_exp gets called when private key components are absent.
107  */
108 # define RSA_FLAG_EXT_PKEY               0x0020
109
110 /*
111  * new with 0.9.6j and 0.9.7b; the built-in
112  * RSA implementation now uses blinding by
113  * default (ignoring RSA_FLAG_BLINDING),
114  * but other engines might not need it
115  */
116 # define RSA_FLAG_NO_BLINDING            0x0080
117 /*
118  * new with 0.9.8f; the built-in RSA
119  * implementation now uses constant time
120  * operations by default in private key operations,
121  * e.g., constant time modular exponentiation,
122  * modular inverse without leaking branches,
123  * division without leaking branches. This
124  * flag disables these constant time
125  * operations and results in faster RSA
126  * private key operations.
127  */
128 # define RSA_FLAG_NO_CONSTTIME           0x0100
129 # if OPENSSL_API_COMPAT < 0x00908000L
130 /* deprecated name for the flag*/
131 /*
132  * new with 0.9.7h; the built-in RSA
133  * implementation now uses constant time
134  * modular exponentiation for secret exponents
135  * by default. This flag causes the
136  * faster variable sliding window method to
137  * be used for all exponents.
138  */
139 #  define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME
140 # endif
141
142 # define EVP_PKEY_CTX_set_rsa_padding(ctx, pad) \
143         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, -1, EVP_PKEY_CTRL_RSA_PADDING, \
144                                 pad, NULL)
145
146 # define EVP_PKEY_CTX_get_rsa_padding(ctx, ppad) \
147         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, -1, \
148                                 EVP_PKEY_CTRL_GET_RSA_PADDING, 0, ppad)
149
150 # define EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, len) \
151         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
152                                 (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \
153                                 EVP_PKEY_CTRL_RSA_PSS_SALTLEN, \
154                                 len, NULL)
155
156 # define EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, plen) \
157         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
158                                 (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \
159                                 EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN, \
160                                 0, plen)
161
162 # define EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) \
163         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \
164                                 EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, NULL)
165
166 # define EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, pubexp) \
167         EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \
168                                 EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp)
169
170 # define  EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md)  \
171                 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
172                         EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \
173                                 EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)md)
174
175 # define  EVP_PKEY_CTX_set_rsa_oaep_md(ctx, md)  \
176                 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT,  \
177                                 EVP_PKEY_CTRL_RSA_OAEP_MD, 0, (void *)md)
178
179 # define  EVP_PKEY_CTX_get_rsa_mgf1_md(ctx, pmd) \
180                 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
181                         EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \
182                                 EVP_PKEY_CTRL_GET_RSA_MGF1_MD, 0, (void *)pmd)
183
184 # define  EVP_PKEY_CTX_get_rsa_oaep_md(ctx, pmd) \
185                 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT,  \
186                                 EVP_PKEY_CTRL_GET_RSA_OAEP_MD, 0, (void *)pmd)
187
188 # define  EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, l, llen) \
189                 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT,  \
190                                 EVP_PKEY_CTRL_RSA_OAEP_LABEL, llen, (void *)l)
191
192 # define  EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, l)       \
193                 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT,  \
194                                 EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, 0, (void *)l)
195
196 # define EVP_PKEY_CTRL_RSA_PADDING       (EVP_PKEY_ALG_CTRL + 1)
197 # define EVP_PKEY_CTRL_RSA_PSS_SALTLEN   (EVP_PKEY_ALG_CTRL + 2)
198
199 # define EVP_PKEY_CTRL_RSA_KEYGEN_BITS   (EVP_PKEY_ALG_CTRL + 3)
200 # define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4)
201 # define EVP_PKEY_CTRL_RSA_MGF1_MD       (EVP_PKEY_ALG_CTRL + 5)
202
203 # define EVP_PKEY_CTRL_GET_RSA_PADDING           (EVP_PKEY_ALG_CTRL + 6)
204 # define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN       (EVP_PKEY_ALG_CTRL + 7)
205 # define EVP_PKEY_CTRL_GET_RSA_MGF1_MD           (EVP_PKEY_ALG_CTRL + 8)
206
207 # define EVP_PKEY_CTRL_RSA_OAEP_MD       (EVP_PKEY_ALG_CTRL + 9)
208 # define EVP_PKEY_CTRL_RSA_OAEP_LABEL    (EVP_PKEY_ALG_CTRL + 10)
209
210 # define EVP_PKEY_CTRL_GET_RSA_OAEP_MD   (EVP_PKEY_ALG_CTRL + 11)
211 # define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12)
212
213 # define RSA_PKCS1_PADDING       1
214 # define RSA_SSLV23_PADDING      2
215 # define RSA_NO_PADDING          3
216 # define RSA_PKCS1_OAEP_PADDING  4
217 # define RSA_X931_PADDING        5
218 /* EVP_PKEY_ only */
219 # define RSA_PKCS1_PSS_PADDING   6
220
221 # define RSA_PKCS1_PADDING_SIZE  11
222
223 # define RSA_set_app_data(s,arg)         RSA_set_ex_data(s,0,arg)
224 # define RSA_get_app_data(s)             RSA_get_ex_data(s,0)
225
226 RSA *RSA_new(void);
227 RSA *RSA_new_method(ENGINE *engine);
228 int RSA_bits(const RSA *rsa);
229 int RSA_size(const RSA *rsa);
230 int RSA_security_bits(const RSA *rsa);
231
232 int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
233 int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
234 int RSA_set0_crt_params(RSA *r,BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
235 void RSA_get0_key(const RSA *r, BIGNUM **n, BIGNUM **e, BIGNUM **d);
236 void RSA_get0_factors(const RSA *r, BIGNUM **p, BIGNUM **q);
237 void RSA_get0_crt_params(const RSA *r,
238                          BIGNUM **dmp1, BIGNUM **dmq1, BIGNUM **iqmp);
239 void RSA_clear_flags(RSA *r, int flags);
240 int RSA_test_flags(const RSA *r, int flags);
241 void RSA_set_flags(RSA *r, int flags);
242 ENGINE *RSA_get0_engine(RSA *r);
243
244 /* Deprecated version */
245 DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void
246                                          (*callback) (int, int, void *),
247                                          void *cb_arg))
248
249 /* New version */
250 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
251
252 int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
253                        BIGNUM *q2, const BIGNUM *Xp1, const BIGNUM *Xp2,
254                        const BIGNUM *Xp, const BIGNUM *Xq1, const BIGNUM *Xq2,
255                        const BIGNUM *Xq, const BIGNUM *e, BN_GENCB *cb);
256 int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
257                              BN_GENCB *cb);
258
259 int RSA_check_key(const RSA *);
260 int RSA_check_key_ex(const RSA *, BN_GENCB *cb);
261         /* next 4 return -1 on error */
262 int RSA_public_encrypt(int flen, const unsigned char *from,
263                        unsigned char *to, RSA *rsa, int padding);
264 int RSA_private_encrypt(int flen, const unsigned char *from,
265                         unsigned char *to, RSA *rsa, int padding);
266 int RSA_public_decrypt(int flen, const unsigned char *from,
267                        unsigned char *to, RSA *rsa, int padding);
268 int RSA_private_decrypt(int flen, const unsigned char *from,
269                         unsigned char *to, RSA *rsa, int padding);
270 void RSA_free(RSA *r);
271 /* "up" the RSA object's reference count */
272 int RSA_up_ref(RSA *r);
273
274 int RSA_flags(const RSA *r);
275
276 void RSA_set_default_method(const RSA_METHOD *meth);
277 const RSA_METHOD *RSA_get_default_method(void);
278 const RSA_METHOD *RSA_get_method(const RSA *rsa);
279 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
280
281 /* This function needs the memory locking malloc callbacks to be installed */
282 int RSA_memory_lock(RSA *r);
283
284 /* these are the actual RSA functions */
285 const RSA_METHOD *RSA_PKCS1_OpenSSL(void);
286
287 const RSA_METHOD *RSA_null_method(void);
288
289 DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey)
290 DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey)
291
292 typedef struct rsa_pss_params_st {
293     X509_ALGOR *hashAlgorithm;
294     X509_ALGOR *maskGenAlgorithm;
295     ASN1_INTEGER *saltLength;
296     ASN1_INTEGER *trailerField;
297 } RSA_PSS_PARAMS;
298
299 DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
300
301 typedef struct rsa_oaep_params_st {
302     X509_ALGOR *hashFunc;
303     X509_ALGOR *maskGenFunc;
304     X509_ALGOR *pSourceFunc;
305 } RSA_OAEP_PARAMS;
306
307 DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS)
308
309 # ifndef OPENSSL_NO_STDIO
310 int RSA_print_fp(FILE *fp, const RSA *r, int offset);
311 # endif
312
313 int RSA_print(BIO *bp, const RSA *r, int offset);
314
315 /*
316  * The following 2 functions sign and verify a X509_SIG ASN1 object inside
317  * PKCS#1 padded RSA encryption
318  */
319 int RSA_sign(int type, const unsigned char *m, unsigned int m_length,
320              unsigned char *sigret, unsigned int *siglen, RSA *rsa);
321 int RSA_verify(int type, const unsigned char *m, unsigned int m_length,
322                const unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
323
324 /*
325  * The following 2 function sign and verify a ASN1_OCTET_STRING object inside
326  * PKCS#1 padded RSA encryption
327  */
328 int RSA_sign_ASN1_OCTET_STRING(int type,
329                                const unsigned char *m, unsigned int m_length,
330                                unsigned char *sigret, unsigned int *siglen,
331                                RSA *rsa);
332 int RSA_verify_ASN1_OCTET_STRING(int type, const unsigned char *m,
333                                  unsigned int m_length, unsigned char *sigbuf,
334                                  unsigned int siglen, RSA *rsa);
335
336 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
337 void RSA_blinding_off(RSA *rsa);
338 BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx);
339
340 int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
341                                  const unsigned char *f, int fl);
342 int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
343                                    const unsigned char *f, int fl,
344                                    int rsa_len);
345 int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
346                                  const unsigned char *f, int fl);
347 int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
348                                    const unsigned char *f, int fl,
349                                    int rsa_len);
350 int PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed,
351                long seedlen, const EVP_MD *dgst);
352 int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
353                                const unsigned char *f, int fl,
354                                const unsigned char *p, int pl);
355 int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
356                                  const unsigned char *f, int fl, int rsa_len,
357                                  const unsigned char *p, int pl);
358 int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
359                                     const unsigned char *from, int flen,
360                                     const unsigned char *param, int plen,
361                                     const EVP_MD *md, const EVP_MD *mgf1md);
362 int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
363                                       const unsigned char *from, int flen,
364                                       int num, const unsigned char *param,
365                                       int plen, const EVP_MD *md,
366                                       const EVP_MD *mgf1md);
367 int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
368                            const unsigned char *f, int fl);
369 int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
370                              const unsigned char *f, int fl, int rsa_len);
371 int RSA_padding_add_none(unsigned char *to, int tlen, const unsigned char *f,
372                          int fl);
373 int RSA_padding_check_none(unsigned char *to, int tlen,
374                            const unsigned char *f, int fl, int rsa_len);
375 int RSA_padding_add_X931(unsigned char *to, int tlen, const unsigned char *f,
376                          int fl);
377 int RSA_padding_check_X931(unsigned char *to, int tlen,
378                            const unsigned char *f, int fl, int rsa_len);
379 int RSA_X931_hash_id(int nid);
380
381 int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
382                          const EVP_MD *Hash, const unsigned char *EM,
383                          int sLen);
384 int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
385                               const unsigned char *mHash, const EVP_MD *Hash,
386                               int sLen);
387
388 int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
389                               const EVP_MD *Hash, const EVP_MD *mgf1Hash,
390                               const unsigned char *EM, int sLen);
391
392 int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
393                                    const unsigned char *mHash,
394                                    const EVP_MD *Hash, const EVP_MD *mgf1Hash,
395                                    int sLen);
396
397 #define RSA_get_ex_new_index(l, p, newf, dupf, freef) \
398     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef)
399 int RSA_set_ex_data(RSA *r, int idx, void *arg);
400 void *RSA_get_ex_data(const RSA *r, int idx);
401
402 RSA *RSAPublicKey_dup(RSA *rsa);
403 RSA *RSAPrivateKey_dup(RSA *rsa);
404
405 /*
406  * If this flag is set the RSA method is FIPS compliant and can be used in
407  * FIPS mode. This is set in the validated module method. If an application
408  * sets this flag in its own methods it is its responsibility to ensure the
409  * result is compliant.
410  */
411
412 # define RSA_FLAG_FIPS_METHOD                    0x0400
413
414 /*
415  * If this flag is set the operations normally disabled in FIPS mode are
416  * permitted it is then the applications responsibility to ensure that the
417  * usage is compliant.
418  */
419
420 # define RSA_FLAG_NON_FIPS_ALLOW                 0x0400
421 /*
422  * Application has decided PRNG is good enough to generate a key: don't
423  * check.
424  */
425 # define RSA_FLAG_CHECKED                        0x0800
426
427 RSA_METHOD *RSA_meth_new(const char *name, int flags);
428 void RSA_meth_free(RSA_METHOD *meth);
429 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
430 const char *RSA_meth_get0_name(const RSA_METHOD *meth);
431 int RSA_meth_set1_name(RSA_METHOD *meth, const char *name);
432 int RSA_meth_get_flags(RSA_METHOD *meth);
433 int RSA_meth_set_flags(RSA_METHOD *meth, int flags);
434 void *RSA_meth_get0_app_data(const RSA_METHOD *meth);
435 int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data);
436 int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth))
437     (int flen, const unsigned char *from,
438      unsigned char *to, RSA *rsa, int padding);
439 int RSA_meth_set_pub_enc(RSA_METHOD *rsa,
440                          int (*pub_enc) (int flen, const unsigned char *from,
441                                          unsigned char *to, RSA *rsa,
442                                          int padding));
443 int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth))
444     (int flen, const unsigned char *from,
445      unsigned char *to, RSA *rsa, int padding);
446 int RSA_meth_set_pub_dec(RSA_METHOD *rsa,
447                          int (*pub_dec) (int flen, const unsigned char *from,
448                                          unsigned char *to, RSA *rsa,
449                                          int padding));
450 int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))
451     (int flen, const unsigned char *from,
452      unsigned char *to, RSA *rsa, int padding);
453 int RSA_meth_set_priv_enc(RSA_METHOD *rsa,
454                           int (*priv_enc) (int flen, const unsigned char *from,
455                                            unsigned char *to, RSA *rsa,
456                                            int padding));
457 int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
458     (int flen, const unsigned char *from,
459      unsigned char *to, RSA *rsa, int padding);
460 int RSA_meth_set_priv_dec(RSA_METHOD *rsa,
461                           int (*priv_dec) (int flen, const unsigned char *from,
462                                            unsigned char *to, RSA *rsa,
463                                            int padding));
464 int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))
465     (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
466 int RSA_meth_set_mod_exp(RSA_METHOD *rsa,
467                          int (*mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa,
468                                          BN_CTX *ctx));
469 int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))
470     (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
471      const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
472 int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa,
473                             int (*bn_mod_exp) (BIGNUM *r,
474                                                const BIGNUM *a,
475                                                const BIGNUM *p,
476                                                const BIGNUM *m,
477                                                BN_CTX *ctx,
478                                                BN_MONT_CTX *m_ctx));
479 int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa);
480 int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa));
481 int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa);
482 int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa));
483 int (*RSA_meth_get_sign(const RSA_METHOD *meth))
484     (int type,
485      const unsigned char *m, unsigned int m_length,
486      unsigned char *sigret, unsigned int *siglen,
487      const RSA *rsa);
488 int RSA_meth_set_sign(RSA_METHOD *rsa,
489                       int (*sign) (int type, const unsigned char *m,
490                                    unsigned int m_length,
491                                    unsigned char *sigret, unsigned int *siglen,
492                                    const RSA *rsa));
493 int (*RSA_meth_get_verify(const RSA_METHOD *meth))
494     (int dtype, const unsigned char *m,
495      unsigned int m_length, const unsigned char *sigbuf,
496      unsigned int siglen, const RSA *rsa);
497 int RSA_meth_set_verify(RSA_METHOD *rsa,
498                         int (*verify) (int dtype, const unsigned char *m,
499                                        unsigned int m_length,
500                                        const unsigned char *sigbuf,
501                                        unsigned int siglen, const RSA *rsa));
502 int (*RSA_meth_get_keygen(const RSA_METHOD *meth))
503     (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
504 int RSA_meth_set_keygen(RSA_METHOD *rsa,
505                         int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
506                                        BN_GENCB *cb));
507
508 /* BEGIN ERROR CODES */
509 /*
510  * The following lines are auto generated by the script mkerr.pl. Any changes
511  * made after this point may be overwritten when the script is next run.
512  */
513 void ERR_load_RSA_strings(void);
514
515 /* Error codes for the RSA functions. */
516
517 /* Function codes. */
518 # define RSA_F_CHECK_PADDING_MD                           140
519 # define RSA_F_DO_RSA_PRINT                               146
520 # define RSA_F_FIPS_RSA_SIGN_DIGEST                       149
521 # define RSA_F_FIPS_RSA_VERIFY                            150
522 # define RSA_F_FIPS_RSA_VERIFY_DIGEST                     151
523 # define RSA_F_INT_RSA_VERIFY                             145
524 # define RSA_F_MEMORY_LOCK                                100
525 # define RSA_F_OLD_RSA_PRIV_DECODE                        147
526 # define RSA_F_PKEY_RSA_CTRL                              143
527 # define RSA_F_PKEY_RSA_CTRL_STR                          144
528 # define RSA_F_PKEY_RSA_SIGN                              142
529 # define RSA_F_PKEY_RSA_VERIFYRECOVER                     141
530 # define RSA_F_RSA_ALGOR_TO_MD                            156
531 # define RSA_F_RSA_BUILTIN_KEYGEN                         129
532 # define RSA_F_RSA_CHECK_KEY                              123
533 # define RSA_F_RSA_CHECK_KEY_EX                           160
534 # define RSA_F_RSA_CMS_DECRYPT                            159
535 # define RSA_F_RSA_OSSL_PRIVATE_DECRYPT                   101
536 # define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT                   102
537 # define RSA_F_RSA_OSSL_PUBLIC_DECRYPT                    103
538 # define RSA_F_RSA_OSSL_PUBLIC_ENCRYPT                    104
539 # define RSA_F_RSA_GENERATE_KEY                           105
540 # define RSA_F_RSA_ITEM_VERIFY                            148
541 # define RSA_F_RSA_MEMORY_LOCK                            130
542 # define RSA_F_RSA_MGF1_TO_MD                             157
543 # define RSA_F_RSA_NEW_METHOD                             106
544 # define RSA_F_RSA_NULL                                   124
545 # define RSA_F_RSA_NULL_MOD_EXP                           131
546 # define RSA_F_RSA_NULL_PRIVATE_DECRYPT                   132
547 # define RSA_F_RSA_NULL_PRIVATE_ENCRYPT                   133
548 # define RSA_F_RSA_NULL_PUBLIC_DECRYPT                    134
549 # define RSA_F_RSA_NULL_PUBLIC_ENCRYPT                    135
550 # define RSA_F_RSA_OAEP_TO_CTX                            158
551 # define RSA_F_RSA_PADDING_ADD_NONE                       107
552 # define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP                 121
553 # define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP_MGF1            154
554 # define RSA_F_RSA_PADDING_ADD_PKCS1_PSS                  125
555 # define RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1             152
556 # define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1               108
557 # define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2               109
558 # define RSA_F_RSA_PADDING_ADD_SSLV23                     110
559 # define RSA_F_RSA_PADDING_ADD_X931                       127
560 # define RSA_F_RSA_PADDING_CHECK_NONE                     111
561 # define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP               122
562 # define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1          153
563 # define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1             112
564 # define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2             113
565 # define RSA_F_RSA_PADDING_CHECK_SSLV23                   114
566 # define RSA_F_RSA_PADDING_CHECK_X931                     128
567 # define RSA_F_RSA_PRINT                                  115
568 # define RSA_F_RSA_PRINT_FP                               116
569 # define RSA_F_RSA_PRIV_DECODE                            137
570 # define RSA_F_RSA_PRIV_ENCODE                            138
571 # define RSA_F_RSA_PSS_TO_CTX                             155
572 # define RSA_F_RSA_PUB_DECODE                             139
573 # define RSA_F_RSA_SETUP_BLINDING                         136
574 # define RSA_F_RSA_SIGN                                   117
575 # define RSA_F_RSA_SIGN_ASN1_OCTET_STRING                 118
576 # define RSA_F_RSA_VERIFY                                 119
577 # define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING               120
578 # define RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1                  126
579
580 /* Reason codes. */
581 # define RSA_R_ALGORITHM_MISMATCH                         100
582 # define RSA_R_BAD_E_VALUE                                101
583 # define RSA_R_BAD_FIXED_HEADER_DECRYPT                   102
584 # define RSA_R_BAD_PAD_BYTE_COUNT                         103
585 # define RSA_R_BAD_SIGNATURE                              104
586 # define RSA_R_BLOCK_TYPE_IS_NOT_01                       106
587 # define RSA_R_BLOCK_TYPE_IS_NOT_02                       107
588 # define RSA_R_DATA_GREATER_THAN_MOD_LEN                  108
589 # define RSA_R_DATA_TOO_LARGE                             109
590 # define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE                110
591 # define RSA_R_DATA_TOO_LARGE_FOR_MODULUS                 132
592 # define RSA_R_DATA_TOO_SMALL                             111
593 # define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE                122
594 # define RSA_R_DIGEST_DOES_NOT_MATCH                      158
595 # define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY                 112
596 # define RSA_R_DMP1_NOT_CONGRUENT_TO_D                    124
597 # define RSA_R_DMQ1_NOT_CONGRUENT_TO_D                    125
598 # define RSA_R_D_E_NOT_CONGRUENT_TO_1                     123
599 # define RSA_R_FIRST_OCTET_INVALID                        133
600 # define RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE        144
601 # define RSA_R_INVALID_DIGEST                             157
602 # define RSA_R_INVALID_DIGEST_LENGTH                      143
603 # define RSA_R_INVALID_HEADER                             137
604 # define RSA_R_INVALID_KEYBITS                            145
605 # define RSA_R_INVALID_LABEL                              160
606 # define RSA_R_INVALID_MESSAGE_LENGTH                     131
607 # define RSA_R_INVALID_MGF1_MD                            156
608 # define RSA_R_INVALID_OAEP_PARAMETERS                    161
609 # define RSA_R_INVALID_PADDING                            138
610 # define RSA_R_INVALID_PADDING_MODE                       141
611 # define RSA_R_INVALID_PSS_PARAMETERS                     149
612 # define RSA_R_INVALID_PSS_SALTLEN                        146
613 # define RSA_R_INVALID_SALT_LENGTH                        150
614 # define RSA_R_INVALID_TRAILER                            139
615 # define RSA_R_INVALID_X931_DIGEST                        142
616 # define RSA_R_IQMP_NOT_INVERSE_OF_Q                      126
617 # define RSA_R_KEY_SIZE_TOO_SMALL                         120
618 # define RSA_R_LAST_OCTET_INVALID                         134
619 # define RSA_R_MODULUS_TOO_LARGE                          105
620 # define RSA_R_NO_PUBLIC_EXPONENT                         140
621 # define RSA_R_NULL_BEFORE_BLOCK_MISSING                  113
622 # define RSA_R_N_DOES_NOT_EQUAL_P_Q                       127
623 # define RSA_R_OAEP_DECODING_ERROR                        121
624 # define RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE   148
625 # define RSA_R_PADDING_CHECK_FAILED                       114
626 # define RSA_R_PKCS_DECODING_ERROR                        159
627 # define RSA_R_P_NOT_PRIME                                128
628 # define RSA_R_Q_NOT_PRIME                                129
629 # define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED               130
630 # define RSA_R_SLEN_CHECK_FAILED                          136
631 # define RSA_R_SLEN_RECOVERY_FAILED                       135
632 # define RSA_R_SSLV3_ROLLBACK_ATTACK                      115
633 # define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
634 # define RSA_R_UNKNOWN_ALGORITHM_TYPE                     117
635 # define RSA_R_UNKNOWN_DIGEST                             166
636 # define RSA_R_UNKNOWN_MASK_DIGEST                        151
637 # define RSA_R_UNKNOWN_PADDING_TYPE                       118
638 # define RSA_R_UNKNOWN_PSS_DIGEST                         152
639 # define RSA_R_UNSUPPORTED_ENCRYPTION_TYPE                162
640 # define RSA_R_UNSUPPORTED_LABEL_SOURCE                   163
641 # define RSA_R_UNSUPPORTED_MASK_ALGORITHM                 153
642 # define RSA_R_UNSUPPORTED_MASK_PARAMETER                 154
643 # define RSA_R_UNSUPPORTED_SIGNATURE_TYPE                 155
644 # define RSA_R_VALUE_MISSING                              147
645 # define RSA_R_WRONG_SIGNATURE_LENGTH                     119
646
647 # ifdef  __cplusplus
648 }
649 # endif
650 # endif
651
652 #endif