1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
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.
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).
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.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
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)"
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
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.]
61 # include <openssl/opensslconf.h>
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>
75 /* The types RSA and RSA_METHOD are defined in ossl_typ.h */
77 # ifndef OPENSSL_RSA_MAX_MODULUS_BITS
78 # define OPENSSL_RSA_MAX_MODULUS_BITS 16384
81 # define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 1024
83 # ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
84 # define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
86 # ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
88 /* exponent limit enforced for "large" modulus only */
89 # define OPENSSL_RSA_MAX_PUBEXP_BITS 64
93 # define RSA_F4 0x10001L
95 # define RSA_METHOD_FLAG_NO_CHECK 0x0001/* don't check pub/private
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
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.
108 # define RSA_FLAG_EXT_PKEY 0x0020
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
116 # define RSA_FLAG_NO_BLINDING 0x0080
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.
128 # define RSA_FLAG_NO_CONSTTIME 0x0100
129 # if OPENSSL_API_COMPAT < 0x00908000L
130 /* deprecated name for the flag*/
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.
139 # define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME
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, \
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)
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, \
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, \
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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
219 # define RSA_PKCS1_PSS_PADDING 6
221 # define RSA_PKCS1_PADDING_SIZE 11
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)
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);
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);
244 /* Deprecated version */
245 DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void
246 (*callback) (int, int, void *),
250 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
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,
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);
274 int RSA_flags(const RSA *r);
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);
281 /* This function needs the memory locking malloc callbacks to be installed */
282 int RSA_memory_lock(RSA *r);
284 /* these are the actual RSA functions */
285 const RSA_METHOD *RSA_PKCS1_OpenSSL(void);
287 const RSA_METHOD *RSA_null_method(void);
289 DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey)
290 DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey)
292 typedef struct rsa_pss_params_st {
293 X509_ALGOR *hashAlgorithm;
294 X509_ALGOR *maskGenAlgorithm;
295 ASN1_INTEGER *saltLength;
296 ASN1_INTEGER *trailerField;
299 DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
301 typedef struct rsa_oaep_params_st {
302 X509_ALGOR *hashFunc;
303 X509_ALGOR *maskGenFunc;
304 X509_ALGOR *pSourceFunc;
307 DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS)
309 # ifndef OPENSSL_NO_STDIO
310 int RSA_print_fp(FILE *fp, const RSA *r, int offset);
313 int RSA_print(BIO *bp, const RSA *r, int offset);
316 * The following 2 functions sign and verify a X509_SIG ASN1 object inside
317 * PKCS#1 padded RSA encryption
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);
325 * The following 2 function sign and verify a ASN1_OCTET_STRING object inside
326 * PKCS#1 padded RSA encryption
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,
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);
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);
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,
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,
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,
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,
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);
381 int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
382 const EVP_MD *Hash, const unsigned char *EM,
384 int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
385 const unsigned char *mHash, const EVP_MD *Hash,
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);
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,
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);
402 RSA *RSAPublicKey_dup(RSA *rsa);
403 RSA *RSAPrivateKey_dup(RSA *rsa);
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.
412 # define RSA_FLAG_FIPS_METHOD 0x0400
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.
420 # define RSA_FLAG_NON_FIPS_ALLOW 0x0400
422 * Application has decided PRNG is good enough to generate a key: don't
425 # define RSA_FLAG_CHECKED 0x0800
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,
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,
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,
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,
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,
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,
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))
485 const unsigned char *m, unsigned int m_length,
486 unsigned char *sigret, unsigned int *siglen,
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,
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,
508 /* BEGIN ERROR CODES */
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.
513 void ERR_load_RSA_strings(void);
515 /* Error codes for the RSA functions. */
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
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