diff options
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_eay.c')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_eay.c | 288 |
1 files changed, 0 insertions, 288 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c deleted file mode 100644 index 776324860c..0000000000 --- a/src/lib/libcrypto/rsa/rsa_eay.c +++ /dev/null | |||
@@ -1,288 +0,0 @@ | |||
1 | |||
2 | /* This file has been explicitly broken by ryker for OpenBSD, July | ||
3 | * 1, 1998. In spite of the title, there is no implementation of the | ||
4 | * RSA algorithm left in this file. All these routines will return an | ||
5 | * error and fail when called. They exist as stubs and can be | ||
6 | * ressurected from the bit bucket by someone in the free world once | ||
7 | * the RSA algorithm is no longer subject to patent problems. Eric | ||
8 | * Young's original copyright is below. | ||
9 | */ | ||
10 | |||
11 | /* crypto/rsa/rsa_eay.c */ | ||
12 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
13 | * All rights reserved. | ||
14 | * | ||
15 | * This package is an SSL implementation written | ||
16 | * by Eric Young (eay@cryptsoft.com). | ||
17 | * The implementation was written so as to conform with Netscapes SSL. | ||
18 | * | ||
19 | * This library is free for commercial and non-commercial use as long as | ||
20 | * the following conditions are aheared to. The following conditions | ||
21 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
22 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
23 | * included with this distribution is covered by the same copyright terms | ||
24 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
25 | * | ||
26 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
27 | * the code are not to be removed. | ||
28 | * If this package is used in a product, Eric Young should be given attribution | ||
29 | * as the author of the parts of the library used. | ||
30 | * This can be in the form of a textual message at program startup or | ||
31 | * in documentation (online or textual) provided with the package. | ||
32 | * | ||
33 | * Redistribution and use in source and binary forms, with or without | ||
34 | * modification, are permitted provided that the following conditions | ||
35 | * are met: | ||
36 | * 1. Redistributions of source code must retain the copyright | ||
37 | * notice, this list of conditions and the following disclaimer. | ||
38 | * 2. Redistributions in binary form must reproduce the above copyright | ||
39 | * notice, this list of conditions and the following disclaimer in the | ||
40 | * documentation and/or other materials provided with the distribution. | ||
41 | * 3. All advertising materials mentioning features or use of this software | ||
42 | * must display the following acknowledgement: | ||
43 | * "This product includes cryptographic software written by | ||
44 | * Eric Young (eay@cryptsoft.com)" | ||
45 | * The word 'cryptographic' can be left out if the rouines from the library | ||
46 | * being used are not cryptographic related :-). | ||
47 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
48 | * the apps directory (application code) you must include an acknowledgement: | ||
49 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
50 | * | ||
51 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
52 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
61 | * SUCH DAMAGE. | ||
62 | * | ||
63 | * The licence and distribution terms for any publically available version or | ||
64 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
65 | * copied and put under another distribution licence | ||
66 | * [including the GNU Public Licence.] | ||
67 | */ | ||
68 | |||
69 | #include <stdio.h> | ||
70 | #include "cryptlib.h" | ||
71 | #include <openssl/bn.h> | ||
72 | #include <openssl/rsa.h> | ||
73 | #include <openssl/rand.h> | ||
74 | |||
75 | static int RSA_eay_public_encrypt(int flen, unsigned char *from, | ||
76 | unsigned char *to, RSA *rsa,int padding); | ||
77 | static int RSA_eay_private_encrypt(int flen, unsigned char *from, | ||
78 | unsigned char *to, RSA *rsa,int padding); | ||
79 | static int RSA_eay_public_decrypt(int flen, unsigned char *from, | ||
80 | unsigned char *to, RSA *rsa,int padding); | ||
81 | static int RSA_eay_private_decrypt(int flen, unsigned char *from, | ||
82 | unsigned char *to, RSA *rsa,int padding); | ||
83 | static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa); | ||
84 | static int RSA_eay_init(RSA *rsa); | ||
85 | static int RSA_eay_finish(RSA *rsa); | ||
86 | static RSA_METHOD rsa_pkcs1_eay_meth={ | ||
87 | "Eric Young's PKCS#1 RSA", | ||
88 | RSA_eay_public_encrypt, | ||
89 | RSA_eay_public_decrypt, | ||
90 | RSA_eay_private_encrypt, | ||
91 | RSA_eay_private_decrypt, | ||
92 | RSA_eay_mod_exp, | ||
93 | BN_mod_exp_mont, | ||
94 | RSA_eay_init, | ||
95 | RSA_eay_finish, | ||
96 | 0, | ||
97 | NULL, | ||
98 | }; | ||
99 | |||
100 | RSA_METHOD *RSA_PKCS1_SSLeay(void) | ||
101 | { | ||
102 | return(&rsa_pkcs1_eay_meth); | ||
103 | } | ||
104 | |||
105 | static int RSA_eay_public_encrypt(int flen, unsigned char *from, | ||
106 | unsigned char *to, RSA *rsa, int padding) | ||
107 | { | ||
108 | BIGNUM f,ret; | ||
109 | int i,j,k,num=0,r= -1; | ||
110 | unsigned char *buf=NULL; | ||
111 | BN_CTX *ctx=NULL; | ||
112 | |||
113 | BN_init(&f); | ||
114 | BN_init(&ret); | ||
115 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
116 | num=BN_num_bytes(rsa->n); | ||
117 | if ((buf=(unsigned char *)Malloc(num)) == NULL) | ||
118 | { | ||
119 | RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE); | ||
120 | goto err; | ||
121 | } | ||
122 | |||
123 | switch (padding) | ||
124 | { | ||
125 | case RSA_PKCS1_PADDING: | ||
126 | i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen); | ||
127 | break; | ||
128 | #ifndef NO_SHA | ||
129 | case RSA_PKCS1_OAEP_PADDING: | ||
130 | i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0); | ||
131 | break; | ||
132 | #endif | ||
133 | case RSA_SSLV23_PADDING: | ||
134 | i=RSA_padding_add_SSLv23(buf,num,from,flen); | ||
135 | break; | ||
136 | case RSA_NO_PADDING: | ||
137 | i=RSA_padding_add_none(buf,num,from,flen); | ||
138 | break; | ||
139 | default: | ||
140 | RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE); | ||
141 | goto err; | ||
142 | } | ||
143 | if (i <= 0) goto err; | ||
144 | |||
145 | if (BN_bin2bn(buf,num,&f) == NULL) goto err; | ||
146 | |||
147 | if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC)) | ||
148 | { | ||
149 | if ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL) | ||
150 | if (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx)) | ||
151 | goto err; | ||
152 | } | ||
153 | |||
154 | if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, | ||
155 | rsa->_method_mod_n)) goto err; | ||
156 | |||
157 | /* put in leading 0 bytes if the number is less than the | ||
158 | * length of the modulus */ | ||
159 | j=BN_num_bytes(&ret); | ||
160 | i=BN_bn2bin(&ret,&(to[num-j])); | ||
161 | for (k=0; k<(num-i); k++) | ||
162 | to[k]=0; | ||
163 | |||
164 | r=num; | ||
165 | err: | ||
166 | if (ctx != NULL) BN_CTX_free(ctx); | ||
167 | BN_clear_free(&f); | ||
168 | BN_clear_free(&ret); | ||
169 | if (buf != NULL) | ||
170 | { | ||
171 | memset(buf,0,num); | ||
172 | Free(buf); | ||
173 | } | ||
174 | return(r); | ||
175 | } | ||
176 | |||
177 | static int RSA_eay_private_encrypt(int flen, unsigned char *from, | ||
178 | unsigned char *to, RSA *rsa, int padding) | ||
179 | { | ||
180 | BIGNUM f,ret; | ||
181 | int i,j,k,num=0,r= -1; | ||
182 | unsigned char *buf=NULL; | ||
183 | BN_CTX *ctx=NULL; | ||
184 | |||
185 | /* Body of this routine removed for OpenBSD - will return | ||
186 | * when the RSA patent expires | ||
187 | */ | ||
188 | |||
189 | err: | ||
190 | if (ctx != NULL) BN_CTX_free(ctx); | ||
191 | BN_clear_free(&ret); | ||
192 | BN_clear_free(&f); | ||
193 | if (buf != NULL) | ||
194 | { | ||
195 | memset(buf,0,num); | ||
196 | Free(buf); | ||
197 | } | ||
198 | return(r); | ||
199 | } | ||
200 | |||
201 | static int RSA_eay_private_decrypt(int flen, unsigned char *from, | ||
202 | unsigned char *to, RSA *rsa, int padding) | ||
203 | { | ||
204 | BIGNUM f,ret; | ||
205 | int j,num=0,r= -1; | ||
206 | unsigned char *p; | ||
207 | unsigned char *buf=NULL; | ||
208 | BN_CTX *ctx=NULL; | ||
209 | |||
210 | /* Body of this routine removed for OpenBSD - will return | ||
211 | * when the RSA patent expires | ||
212 | */ | ||
213 | |||
214 | err: | ||
215 | if (ctx != NULL) BN_CTX_free(ctx); | ||
216 | BN_clear_free(&f); | ||
217 | BN_clear_free(&ret); | ||
218 | if (buf != NULL) | ||
219 | { | ||
220 | memset(buf,0,num); | ||
221 | Free(buf); | ||
222 | } | ||
223 | return(r); | ||
224 | } | ||
225 | |||
226 | static int RSA_eay_public_decrypt(int flen, unsigned char *from, | ||
227 | unsigned char *to, RSA *rsa, int padding) | ||
228 | { | ||
229 | BIGNUM f,ret; | ||
230 | int i,num=0,r= -1; | ||
231 | unsigned char *p; | ||
232 | unsigned char *buf=NULL; | ||
233 | BN_CTX *ctx=NULL; | ||
234 | |||
235 | /* Body of this routine removed for OpenBSD - will return | ||
236 | * when the RSA patent expires | ||
237 | */ | ||
238 | |||
239 | err: | ||
240 | if (ctx != NULL) BN_CTX_free(ctx); | ||
241 | BN_clear_free(&f); | ||
242 | BN_clear_free(&ret); | ||
243 | if (buf != NULL) | ||
244 | { | ||
245 | memset(buf,0,num); | ||
246 | Free(buf); | ||
247 | } | ||
248 | return(r); | ||
249 | } | ||
250 | |||
251 | static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa) | ||
252 | { | ||
253 | BIGNUM r1,m1; | ||
254 | int ret=0; | ||
255 | BN_CTX *ctx; | ||
256 | |||
257 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
258 | BN_init(&m1); | ||
259 | BN_init(&r1); | ||
260 | |||
261 | /* Body of this routine removed for OpenBSD - will return | ||
262 | * when the RSA patent expires | ||
263 | */ | ||
264 | err: | ||
265 | BN_clear_free(&m1); | ||
266 | BN_clear_free(&r1); | ||
267 | BN_CTX_free(ctx); | ||
268 | return(ret); | ||
269 | } | ||
270 | |||
271 | static int RSA_eay_init(RSA *rsa) | ||
272 | { | ||
273 | rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE; | ||
274 | return(1); | ||
275 | } | ||
276 | |||
277 | static int RSA_eay_finish(RSA *rsa) | ||
278 | { | ||
279 | if (rsa->_method_mod_n != NULL) | ||
280 | BN_MONT_CTX_free(rsa->_method_mod_n); | ||
281 | if (rsa->_method_mod_p != NULL) | ||
282 | BN_MONT_CTX_free(rsa->_method_mod_p); | ||
283 | if (rsa->_method_mod_q != NULL) | ||
284 | BN_MONT_CTX_free(rsa->_method_mod_q); | ||
285 | return(1); | ||
286 | } | ||
287 | |||
288 | |||