]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/rsa/rsa.h
Import of old SSLeay release: SSLeay 0.8.1b
[thirdparty/openssl.git] / crypto / rsa / rsa.h
1 /* crypto/rsa/rsa.h */
2 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59 #ifndef HEADER_RSA_H
60 #define HEADER_RSA_H
61
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65
66 #include "bn.h"
67
68 typedef struct rsa_meth_st
69 {
70 char *name;
71 int (*rsa_pub_enc)();
72 int (*rsa_pub_dec)();
73 int (*rsa_priv_enc)();
74 int (*rsa_priv_dec)();
75 int (*rsa_mod_exp)();
76 int (*bn_mod_exp)();
77 int (*init)(/* RSA * */); /* called at new */
78 int (*finish)(/* RSA * */); /* called at free */
79 } RSA_METHOD;
80
81 typedef struct rsa_st
82 {
83 /* The first parameter is used to pickup errors where
84 * this is passed instead of aEVP_PKEY, it is set to 0 */
85 int pad;
86 int version;
87 RSA_METHOD *meth;
88 BIGNUM *n;
89 BIGNUM *e;
90 BIGNUM *d;
91 BIGNUM *p;
92 BIGNUM *q;
93 BIGNUM *dmp1;
94 BIGNUM *dmq1;
95 BIGNUM *iqmp;
96 /* be carefull using this if the RSA structure is shared */
97 char *app_data;
98 int references;
99 } RSA;
100
101 #define RSA_3 0x3L
102 #define RSA_F4 0x10001L
103
104 #define RSA_PKCS1_PADDING 11
105 #define RSA_SSLV23_PADDING 12
106
107 #ifndef NOPROTO
108 RSA * RSA_new(void);
109 RSA * RSA_new_method(RSA_METHOD *method);
110 int RSA_size(RSA *);
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);
123
124 void RSA_set_default_method(RSA_METHOD *meth);
125
126 /* If you have RSAref compiled in. */
127 /* RSA_METHOD *RSA_PKCS1_RSAref(void); */
128
129 /* these are the actual SSLeay RSA functions */
130 RSA_METHOD *RSA_PKCS1_SSLeay(void);
131
132 void ERR_load_RSA_strings(void );
133
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);
138 #ifndef WIN16
139 int RSA_print_fp(FILE *fp, RSA *r,int offset);
140 #endif
141
142 #ifdef HEADER_BIO_H
143 int RSA_print(BIO *bp, RSA *r,int offset);
144 #endif
145
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)());
148
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);
155
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);
162
163 #else
164
165 RSA * RSA_new();
166 RSA * RSA_new_method();
167 int RSA_size();
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();
173 void RSA_free ();
174
175 void RSA_set_default_method();
176
177 /* RSA_METHOD *RSA_PKCS1_RSAref(); */
178 RSA_METHOD *RSA_PKCS1_SSLeay();
179
180 void ERR_load_RSA_strings();
181
182 RSA * d2i_RSAPublicKey();
183 int i2d_RSAPublicKey();
184 RSA * d2i_RSAPrivateKey();
185 int i2d_RSAPrivateKey();
186 #ifndef WIN16
187 int RSA_print_fp();
188 #endif
189
190 int RSA_print();
191
192 int i2d_Netscape_RSA();
193 RSA *d2i_Netscape_RSA();
194
195 int RSA_sign();
196 int RSA_verify();
197
198 int RSA_sign_ASN1_OCTET_STRING();
199 int RSA_verify_ASN1_OCTET_STRING();
200
201
202 #endif
203
204 /* BEGIN ERROR CODES */
205 /* Error codes for the RSA functions. */
206
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
220
221 /* Reason codes. */
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
238
239 #ifdef __cplusplus
240 }
241 #endif
242 #endif
243