2 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
68 typedef struct rsa_meth_st
73 int (*rsa_priv_enc)();
74 int (*rsa_priv_dec)();
77 int (*init)(/* RSA * */); /* called at new */
78 int (*finish)(/* RSA * */); /* called at free */
83 /* The first parameter is used to pickup errors where
84 * this is passed instead of aEVP_PKEY, it is set to 0 */
96 /* be carefull using this if the RSA structure is shared */
102 #define RSA_F4 0x10001L
104 #define RSA_PKCS1_PADDING 11
105 #define RSA_SSLV23_PADDING 12
109 RSA * RSA_new_method(RSA_METHOD *method);
111 RSA * RSA_generate_key(int bits, unsigned long e,void
112 (*callback)(int,int));
113 /* next 4 return -1 on error */
114 int RSA_public_encrypt(int flen, unsigned char *from,
115 unsigned char *to, RSA *rsa,int padding);
116 int RSA_private_encrypt(int flen, unsigned char *from,
117 unsigned char *to, RSA *rsa,int padding);
118 int RSA_public_decrypt(int flen, unsigned char *from,
119 unsigned char *to, RSA *rsa,int padding);
120 int RSA_private_decrypt(int flen, unsigned char *from,
121 unsigned char *to, RSA *rsa,int padding);
122 void RSA_free (RSA *r);
124 void RSA_set_default_method(RSA_METHOD *meth);
126 /* If you have RSAref compiled in. */
127 /* RSA_METHOD *RSA_PKCS1_RSAref(void); */
129 /* these are the actual SSLeay RSA functions */
130 RSA_METHOD *RSA_PKCS1_SSLeay(void);
132 void ERR_load_RSA_strings(void );
134 RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length);
135 int i2d_RSAPublicKey(RSA *a, unsigned char **pp);
136 RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length);
137 int i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
139 int RSA_print_fp(FILE *fp, RSA *r,int offset);
143 int RSA_print(BIO *bp, RSA *r,int offset);
146 int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
147 RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
149 /* The following 2 functions sign and verify a X509_SIG ASN1 object
150 * inside PKCS#1 padded RSA encryption */
151 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
152 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
153 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
154 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
156 /* The following 2 function sign and verify a ASN1_OCTET_STRING
157 * object inside PKCS#1 padded RSA encryption */
158 int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
159 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
160 int RSA_verify_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
161 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
166 RSA * RSA_new_method();
168 RSA * RSA_generate_key();
169 int RSA_public_encrypt();
170 int RSA_private_encrypt();
171 int RSA_public_decrypt();
172 int RSA_private_decrypt();
175 void RSA_set_default_method();
177 /* RSA_METHOD *RSA_PKCS1_RSAref(); */
178 RSA_METHOD *RSA_PKCS1_SSLeay();
180 void ERR_load_RSA_strings();
182 RSA * d2i_RSAPublicKey();
183 int i2d_RSAPublicKey();
184 RSA * d2i_RSAPrivateKey();
185 int i2d_RSAPrivateKey();
192 int i2d_Netscape_RSA();
193 RSA *d2i_Netscape_RSA();
198 int RSA_sign_ASN1_OCTET_STRING();
199 int RSA_verify_ASN1_OCTET_STRING();
204 /* BEGIN ERROR CODES */
205 /* Error codes for the RSA functions. */
207 /* Function codes. */
208 #define RSA_F_RSA_EAY_PRIVATE_DECRYPT 100
209 #define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 101
210 #define RSA_F_RSA_EAY_PUBLIC_DECRYPT 102
211 #define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 103
212 #define RSA_F_RSA_GENERATE_KEY 104
213 #define RSA_F_RSA_NEW_METHOD 105
214 #define RSA_F_RSA_PRINT 106
215 #define RSA_F_RSA_PRINT_FP 107
216 #define RSA_F_RSA_SIGN 108
217 #define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 109
218 #define RSA_F_RSA_VERIFY 110
219 #define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 111
222 #define RSA_R_ALGORITHM_MISMATCH 100
223 #define RSA_R_BAD_E_VALUE 101
224 #define RSA_R_BAD_FIXED_HEADER_DECRYPT 102
225 #define RSA_R_BAD_PAD_BYTE_COUNT 103
226 #define RSA_R_BAD_SIGNATURE 104
227 #define RSA_R_BLOCK_TYPE_IS_NOT_01 105
228 #define RSA_R_BLOCK_TYPE_IS_NOT_02 106
229 #define RSA_R_DATA_GREATER_THAN_MOD_LEN 107
230 #define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 108
231 #define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 109
232 #define RSA_R_NULL_BEFORE_BLOCK_MISSING 110
233 #define RSA_R_SSLV3_ROLLBACK_ATTACK 111
234 #define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 112
235 #define RSA_R_UNKNOWN_ALGORITHM_TYPE 113
236 #define RSA_R_UNKNOWN_PADDING_TYPE 114
237 #define RSA_R_WRONG_SIGNATURE_LENGTH 115