diff options
Diffstat (limited to 'src/lib/libcrypto/evp')
40 files changed, 0 insertions, 7362 deletions
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c deleted file mode 100644 index af6fa2ae8f..0000000000 --- a/src/lib/libcrypto/evp/bio_b64.c +++ /dev/null | |||
@@ -1,547 +0,0 @@ | |||
1 | /* crypto/evp/bio_b64.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include <errno.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/buffer.h> | ||
63 | #include <openssl/evp.h> | ||
64 | |||
65 | static int b64_write(BIO *h, const char *buf, int num); | ||
66 | static int b64_read(BIO *h, char *buf, int size); | ||
67 | /*static int b64_puts(BIO *h, const char *str); */ | ||
68 | /*static int b64_gets(BIO *h, char *str, int size); */ | ||
69 | static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
70 | static int b64_new(BIO *h); | ||
71 | static int b64_free(BIO *data); | ||
72 | static long b64_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp); | ||
73 | #define B64_BLOCK_SIZE 1024 | ||
74 | #define B64_BLOCK_SIZE2 768 | ||
75 | #define B64_NONE 0 | ||
76 | #define B64_ENCODE 1 | ||
77 | #define B64_DECODE 2 | ||
78 | |||
79 | typedef struct b64_struct | ||
80 | { | ||
81 | /*BIO *bio; moved to the BIO structure */ | ||
82 | int buf_len; | ||
83 | int buf_off; | ||
84 | int tmp_len; /* used to find the start when decoding */ | ||
85 | int tmp_nl; /* If true, scan until '\n' */ | ||
86 | int encode; | ||
87 | int start; /* have we started decoding yet? */ | ||
88 | int cont; /* <= 0 when finished */ | ||
89 | EVP_ENCODE_CTX base64; | ||
90 | char buf[EVP_ENCODE_LENGTH(B64_BLOCK_SIZE)+10]; | ||
91 | char tmp[B64_BLOCK_SIZE]; | ||
92 | } BIO_B64_CTX; | ||
93 | |||
94 | static BIO_METHOD methods_b64= | ||
95 | { | ||
96 | BIO_TYPE_BASE64,"base64 encoding", | ||
97 | b64_write, | ||
98 | b64_read, | ||
99 | NULL, /* b64_puts, */ | ||
100 | NULL, /* b64_gets, */ | ||
101 | b64_ctrl, | ||
102 | b64_new, | ||
103 | b64_free, | ||
104 | b64_callback_ctrl, | ||
105 | }; | ||
106 | |||
107 | BIO_METHOD *BIO_f_base64(void) | ||
108 | { | ||
109 | return(&methods_b64); | ||
110 | } | ||
111 | |||
112 | static int b64_new(BIO *bi) | ||
113 | { | ||
114 | BIO_B64_CTX *ctx; | ||
115 | |||
116 | ctx=(BIO_B64_CTX *)OPENSSL_malloc(sizeof(BIO_B64_CTX)); | ||
117 | if (ctx == NULL) return(0); | ||
118 | |||
119 | ctx->buf_len=0; | ||
120 | ctx->tmp_len=0; | ||
121 | ctx->tmp_nl=0; | ||
122 | ctx->buf_off=0; | ||
123 | ctx->cont=1; | ||
124 | ctx->start=1; | ||
125 | ctx->encode=0; | ||
126 | |||
127 | bi->init=1; | ||
128 | bi->ptr=(char *)ctx; | ||
129 | bi->flags=0; | ||
130 | return(1); | ||
131 | } | ||
132 | |||
133 | static int b64_free(BIO *a) | ||
134 | { | ||
135 | if (a == NULL) return(0); | ||
136 | OPENSSL_free(a->ptr); | ||
137 | a->ptr=NULL; | ||
138 | a->init=0; | ||
139 | a->flags=0; | ||
140 | return(1); | ||
141 | } | ||
142 | |||
143 | static int b64_read(BIO *b, char *out, int outl) | ||
144 | { | ||
145 | int ret=0,i,ii,j,k,x,n,num,ret_code=0; | ||
146 | BIO_B64_CTX *ctx; | ||
147 | unsigned char *p,*q; | ||
148 | |||
149 | if (out == NULL) return(0); | ||
150 | ctx=(BIO_B64_CTX *)b->ptr; | ||
151 | |||
152 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
153 | |||
154 | if (ctx->encode != B64_DECODE) | ||
155 | { | ||
156 | ctx->encode=B64_DECODE; | ||
157 | ctx->buf_len=0; | ||
158 | ctx->buf_off=0; | ||
159 | ctx->tmp_len=0; | ||
160 | EVP_DecodeInit(&(ctx->base64)); | ||
161 | } | ||
162 | |||
163 | /* First check if there are bytes decoded/encoded */ | ||
164 | if (ctx->buf_len > 0) | ||
165 | { | ||
166 | i=ctx->buf_len-ctx->buf_off; | ||
167 | if (i > outl) i=outl; | ||
168 | memcpy(out,&(ctx->buf[ctx->buf_off]),i); | ||
169 | ret=i; | ||
170 | out+=i; | ||
171 | outl-=i; | ||
172 | ctx->buf_off+=i; | ||
173 | if (ctx->buf_len == ctx->buf_off) | ||
174 | { | ||
175 | ctx->buf_len=0; | ||
176 | ctx->buf_off=0; | ||
177 | } | ||
178 | } | ||
179 | |||
180 | /* At this point, we have room of outl bytes and an empty | ||
181 | * buffer, so we should read in some more. */ | ||
182 | |||
183 | ret_code=0; | ||
184 | while (outl > 0) | ||
185 | { | ||
186 | if (ctx->cont <= 0) break; | ||
187 | |||
188 | i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]), | ||
189 | B64_BLOCK_SIZE-ctx->tmp_len); | ||
190 | |||
191 | if (i <= 0) | ||
192 | { | ||
193 | ret_code=i; | ||
194 | |||
195 | /* Should be continue next time we are called? */ | ||
196 | if (!BIO_should_retry(b->next_bio)) | ||
197 | ctx->cont=i; | ||
198 | /* else we should continue when called again */ | ||
199 | break; | ||
200 | } | ||
201 | i+=ctx->tmp_len; | ||
202 | |||
203 | /* We need to scan, a line at a time until we | ||
204 | * have a valid line if we are starting. */ | ||
205 | if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)) | ||
206 | { | ||
207 | /* ctx->start=1; */ | ||
208 | ctx->tmp_len=0; | ||
209 | } | ||
210 | else if (ctx->start) | ||
211 | { | ||
212 | q=p=(unsigned char *)ctx->tmp; | ||
213 | for (j=0; j<i; j++) | ||
214 | { | ||
215 | if (*(q++) != '\n') continue; | ||
216 | |||
217 | /* due to a previous very long line, | ||
218 | * we need to keep on scanning for a '\n' | ||
219 | * before we even start looking for | ||
220 | * base64 encoded stuff. */ | ||
221 | if (ctx->tmp_nl) | ||
222 | { | ||
223 | p=q; | ||
224 | ctx->tmp_nl=0; | ||
225 | continue; | ||
226 | } | ||
227 | |||
228 | k=EVP_DecodeUpdate(&(ctx->base64), | ||
229 | (unsigned char *)ctx->buf, | ||
230 | &num,p,q-p); | ||
231 | if ((k <= 0) && (num == 0) && (ctx->start)) | ||
232 | EVP_DecodeInit(&ctx->base64); | ||
233 | else | ||
234 | { | ||
235 | if (p != (unsigned char *) | ||
236 | &(ctx->tmp[0])) | ||
237 | { | ||
238 | i-=(p- (unsigned char *) | ||
239 | &(ctx->tmp[0])); | ||
240 | for (x=0; x < i; x++) | ||
241 | ctx->tmp[x]=p[x]; | ||
242 | } | ||
243 | EVP_DecodeInit(&ctx->base64); | ||
244 | ctx->start=0; | ||
245 | break; | ||
246 | } | ||
247 | p=q; | ||
248 | } | ||
249 | |||
250 | /* we fell off the end without starting */ | ||
251 | if (j == i) | ||
252 | { | ||
253 | /* Is this is one long chunk?, if so, keep on | ||
254 | * reading until a new line. */ | ||
255 | if (p == (unsigned char *)&(ctx->tmp[0])) | ||
256 | { | ||
257 | ctx->tmp_nl=1; | ||
258 | ctx->tmp_len=0; | ||
259 | } | ||
260 | else if (p != q) /* finished on a '\n' */ | ||
261 | { | ||
262 | n=q-p; | ||
263 | for (ii=0; ii<n; ii++) | ||
264 | ctx->tmp[ii]=p[ii]; | ||
265 | ctx->tmp_len=n; | ||
266 | } | ||
267 | /* else finished on a '\n' */ | ||
268 | continue; | ||
269 | } | ||
270 | else | ||
271 | ctx->tmp_len=0; | ||
272 | } | ||
273 | |||
274 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | ||
275 | { | ||
276 | int z,jj; | ||
277 | |||
278 | jj=(i>>2)<<2; | ||
279 | z=EVP_DecodeBlock((unsigned char *)ctx->buf, | ||
280 | (unsigned char *)ctx->tmp,jj); | ||
281 | if (jj > 2) | ||
282 | { | ||
283 | if (ctx->tmp[jj-1] == '=') | ||
284 | { | ||
285 | z--; | ||
286 | if (ctx->tmp[jj-2] == '=') | ||
287 | z--; | ||
288 | } | ||
289 | } | ||
290 | /* z is now number of output bytes and jj is the | ||
291 | * number consumed */ | ||
292 | if (jj != i) | ||
293 | { | ||
294 | memcpy((unsigned char *)ctx->tmp, | ||
295 | (unsigned char *)&(ctx->tmp[jj]),i-jj); | ||
296 | ctx->tmp_len=i-jj; | ||
297 | } | ||
298 | ctx->buf_len=0; | ||
299 | if (z > 0) | ||
300 | { | ||
301 | ctx->buf_len=z; | ||
302 | i=1; | ||
303 | } | ||
304 | else | ||
305 | i=z; | ||
306 | } | ||
307 | else | ||
308 | { | ||
309 | i=EVP_DecodeUpdate(&(ctx->base64), | ||
310 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
311 | (unsigned char *)ctx->tmp,i); | ||
312 | } | ||
313 | ctx->cont=i; | ||
314 | ctx->buf_off=0; | ||
315 | if (i < 0) | ||
316 | { | ||
317 | ret_code=0; | ||
318 | ctx->buf_len=0; | ||
319 | break; | ||
320 | } | ||
321 | |||
322 | if (ctx->buf_len <= outl) | ||
323 | i=ctx->buf_len; | ||
324 | else | ||
325 | i=outl; | ||
326 | |||
327 | memcpy(out,ctx->buf,i); | ||
328 | ret+=i; | ||
329 | ctx->buf_off=i; | ||
330 | if (ctx->buf_off == ctx->buf_len) | ||
331 | { | ||
332 | ctx->buf_len=0; | ||
333 | ctx->buf_off=0; | ||
334 | } | ||
335 | outl-=i; | ||
336 | out+=i; | ||
337 | } | ||
338 | BIO_clear_retry_flags(b); | ||
339 | BIO_copy_next_retry(b); | ||
340 | return((ret == 0)?ret_code:ret); | ||
341 | } | ||
342 | |||
343 | static int b64_write(BIO *b, const char *in, int inl) | ||
344 | { | ||
345 | int ret=inl,n,i; | ||
346 | BIO_B64_CTX *ctx; | ||
347 | |||
348 | ctx=(BIO_B64_CTX *)b->ptr; | ||
349 | BIO_clear_retry_flags(b); | ||
350 | |||
351 | if (ctx->encode != B64_ENCODE) | ||
352 | { | ||
353 | ctx->encode=B64_ENCODE; | ||
354 | ctx->buf_len=0; | ||
355 | ctx->buf_off=0; | ||
356 | ctx->tmp_len=0; | ||
357 | EVP_EncodeInit(&(ctx->base64)); | ||
358 | } | ||
359 | |||
360 | n=ctx->buf_len-ctx->buf_off; | ||
361 | while (n > 0) | ||
362 | { | ||
363 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
364 | if (i <= 0) | ||
365 | { | ||
366 | BIO_copy_next_retry(b); | ||
367 | return(i); | ||
368 | } | ||
369 | ctx->buf_off+=i; | ||
370 | n-=i; | ||
371 | } | ||
372 | /* at this point all pending data has been written */ | ||
373 | ctx->buf_off=0; | ||
374 | ctx->buf_len=0; | ||
375 | |||
376 | if ((in == NULL) || (inl <= 0)) return(0); | ||
377 | |||
378 | while (inl > 0) | ||
379 | { | ||
380 | n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl; | ||
381 | |||
382 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | ||
383 | { | ||
384 | if (ctx->tmp_len > 0) | ||
385 | { | ||
386 | n=3-ctx->tmp_len; | ||
387 | /* There's a teoretical possibility for this */ | ||
388 | if (n > inl) | ||
389 | n=inl; | ||
390 | memcpy(&(ctx->tmp[ctx->tmp_len]),in,n); | ||
391 | ctx->tmp_len+=n; | ||
392 | if (ctx->tmp_len < 3) | ||
393 | break; | ||
394 | ctx->buf_len=EVP_EncodeBlock( | ||
395 | (unsigned char *)ctx->buf, | ||
396 | (unsigned char *)ctx->tmp, | ||
397 | ctx->tmp_len); | ||
398 | /* Since we're now done using the temporary | ||
399 | buffer, the length should be 0'd */ | ||
400 | ctx->tmp_len=0; | ||
401 | } | ||
402 | else | ||
403 | { | ||
404 | if (n < 3) | ||
405 | { | ||
406 | memcpy(&(ctx->tmp[0]),in,n); | ||
407 | ctx->tmp_len=n; | ||
408 | break; | ||
409 | } | ||
410 | n-=n%3; | ||
411 | ctx->buf_len=EVP_EncodeBlock( | ||
412 | (unsigned char *)ctx->buf, | ||
413 | (unsigned char *)in,n); | ||
414 | } | ||
415 | } | ||
416 | else | ||
417 | { | ||
418 | EVP_EncodeUpdate(&(ctx->base64), | ||
419 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
420 | (unsigned char *)in,n); | ||
421 | } | ||
422 | inl-=n; | ||
423 | in+=n; | ||
424 | |||
425 | ctx->buf_off=0; | ||
426 | n=ctx->buf_len; | ||
427 | while (n > 0) | ||
428 | { | ||
429 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
430 | if (i <= 0) | ||
431 | { | ||
432 | BIO_copy_next_retry(b); | ||
433 | return((ret == 0)?i:ret); | ||
434 | } | ||
435 | n-=i; | ||
436 | ctx->buf_off+=i; | ||
437 | } | ||
438 | ctx->buf_len=0; | ||
439 | ctx->buf_off=0; | ||
440 | } | ||
441 | return(ret); | ||
442 | } | ||
443 | |||
444 | static long b64_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
445 | { | ||
446 | BIO_B64_CTX *ctx; | ||
447 | long ret=1; | ||
448 | int i; | ||
449 | |||
450 | ctx=(BIO_B64_CTX *)b->ptr; | ||
451 | |||
452 | switch (cmd) | ||
453 | { | ||
454 | case BIO_CTRL_RESET: | ||
455 | ctx->cont=1; | ||
456 | ctx->start=1; | ||
457 | ctx->encode=B64_NONE; | ||
458 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
459 | break; | ||
460 | case BIO_CTRL_EOF: /* More to read */ | ||
461 | if (ctx->cont <= 0) | ||
462 | ret=1; | ||
463 | else | ||
464 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
465 | break; | ||
466 | case BIO_CTRL_WPENDING: /* More to write in buffer */ | ||
467 | ret=ctx->buf_len-ctx->buf_off; | ||
468 | if ((ret == 0) && (ctx->base64.num != 0)) | ||
469 | ret=1; | ||
470 | else if (ret <= 0) | ||
471 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
472 | break; | ||
473 | case BIO_CTRL_PENDING: /* More to read in buffer */ | ||
474 | ret=ctx->buf_len-ctx->buf_off; | ||
475 | if (ret <= 0) | ||
476 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
477 | break; | ||
478 | case BIO_CTRL_FLUSH: | ||
479 | /* do a final write */ | ||
480 | again: | ||
481 | while (ctx->buf_len != ctx->buf_off) | ||
482 | { | ||
483 | i=b64_write(b,NULL,0); | ||
484 | if (i < 0) | ||
485 | { | ||
486 | ret=i; | ||
487 | break; | ||
488 | } | ||
489 | } | ||
490 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | ||
491 | { | ||
492 | if (ctx->tmp_len != 0) | ||
493 | { | ||
494 | ctx->buf_len=EVP_EncodeBlock( | ||
495 | (unsigned char *)ctx->buf, | ||
496 | (unsigned char *)ctx->tmp, | ||
497 | ctx->tmp_len); | ||
498 | ctx->buf_off=0; | ||
499 | ctx->tmp_len=0; | ||
500 | goto again; | ||
501 | } | ||
502 | } | ||
503 | else if (ctx->base64.num != 0) | ||
504 | { | ||
505 | ctx->buf_off=0; | ||
506 | EVP_EncodeFinal(&(ctx->base64), | ||
507 | (unsigned char *)ctx->buf, | ||
508 | &(ctx->buf_len)); | ||
509 | /* push out the bytes */ | ||
510 | goto again; | ||
511 | } | ||
512 | /* Finally flush the underlying BIO */ | ||
513 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
514 | break; | ||
515 | |||
516 | case BIO_C_DO_STATE_MACHINE: | ||
517 | BIO_clear_retry_flags(b); | ||
518 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
519 | BIO_copy_next_retry(b); | ||
520 | break; | ||
521 | |||
522 | case BIO_CTRL_DUP: | ||
523 | break; | ||
524 | case BIO_CTRL_INFO: | ||
525 | case BIO_CTRL_GET: | ||
526 | case BIO_CTRL_SET: | ||
527 | default: | ||
528 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
529 | break; | ||
530 | } | ||
531 | return(ret); | ||
532 | } | ||
533 | |||
534 | static long b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | ||
535 | { | ||
536 | long ret=1; | ||
537 | |||
538 | if (b->next_bio == NULL) return(0); | ||
539 | switch (cmd) | ||
540 | { | ||
541 | default: | ||
542 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | ||
543 | break; | ||
544 | } | ||
545 | return(ret); | ||
546 | } | ||
547 | |||
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c deleted file mode 100644 index 831c71a2b5..0000000000 --- a/src/lib/libcrypto/evp/bio_enc.c +++ /dev/null | |||
@@ -1,425 +0,0 @@ | |||
1 | /* crypto/evp/bio_enc.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include <errno.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/buffer.h> | ||
63 | #include <openssl/evp.h> | ||
64 | |||
65 | static int enc_write(BIO *h, const char *buf, int num); | ||
66 | static int enc_read(BIO *h, char *buf, int size); | ||
67 | /*static int enc_puts(BIO *h, const char *str); */ | ||
68 | /*static int enc_gets(BIO *h, char *str, int size); */ | ||
69 | static long enc_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
70 | static int enc_new(BIO *h); | ||
71 | static int enc_free(BIO *data); | ||
72 | static long enc_callback_ctrl(BIO *h, int cmd, bio_info_cb *fps); | ||
73 | #define ENC_BLOCK_SIZE (1024*4) | ||
74 | |||
75 | typedef struct enc_struct | ||
76 | { | ||
77 | int buf_len; | ||
78 | int buf_off; | ||
79 | int cont; /* <= 0 when finished */ | ||
80 | int finished; | ||
81 | int ok; /* bad decrypt */ | ||
82 | EVP_CIPHER_CTX cipher; | ||
83 | char buf[ENC_BLOCK_SIZE+10]; | ||
84 | } BIO_ENC_CTX; | ||
85 | |||
86 | static BIO_METHOD methods_enc= | ||
87 | { | ||
88 | BIO_TYPE_CIPHER,"cipher", | ||
89 | enc_write, | ||
90 | enc_read, | ||
91 | NULL, /* enc_puts, */ | ||
92 | NULL, /* enc_gets, */ | ||
93 | enc_ctrl, | ||
94 | enc_new, | ||
95 | enc_free, | ||
96 | enc_callback_ctrl, | ||
97 | }; | ||
98 | |||
99 | BIO_METHOD *BIO_f_cipher(void) | ||
100 | { | ||
101 | return(&methods_enc); | ||
102 | } | ||
103 | |||
104 | static int enc_new(BIO *bi) | ||
105 | { | ||
106 | BIO_ENC_CTX *ctx; | ||
107 | |||
108 | ctx=(BIO_ENC_CTX *)OPENSSL_malloc(sizeof(BIO_ENC_CTX)); | ||
109 | EVP_CIPHER_CTX_init(&ctx->cipher); | ||
110 | if (ctx == NULL) return(0); | ||
111 | |||
112 | ctx->buf_len=0; | ||
113 | ctx->buf_off=0; | ||
114 | ctx->cont=1; | ||
115 | ctx->finished=0; | ||
116 | ctx->ok=1; | ||
117 | |||
118 | bi->init=0; | ||
119 | bi->ptr=(char *)ctx; | ||
120 | bi->flags=0; | ||
121 | return(1); | ||
122 | } | ||
123 | |||
124 | static int enc_free(BIO *a) | ||
125 | { | ||
126 | BIO_ENC_CTX *b; | ||
127 | |||
128 | if (a == NULL) return(0); | ||
129 | b=(BIO_ENC_CTX *)a->ptr; | ||
130 | EVP_CIPHER_CTX_cleanup(&(b->cipher)); | ||
131 | memset(a->ptr,0,sizeof(BIO_ENC_CTX)); | ||
132 | OPENSSL_free(a->ptr); | ||
133 | a->ptr=NULL; | ||
134 | a->init=0; | ||
135 | a->flags=0; | ||
136 | return(1); | ||
137 | } | ||
138 | |||
139 | static int enc_read(BIO *b, char *out, int outl) | ||
140 | { | ||
141 | int ret=0,i; | ||
142 | BIO_ENC_CTX *ctx; | ||
143 | |||
144 | if (out == NULL) return(0); | ||
145 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
146 | |||
147 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
148 | |||
149 | /* First check if there are bytes decoded/encoded */ | ||
150 | if (ctx->buf_len > 0) | ||
151 | { | ||
152 | i=ctx->buf_len-ctx->buf_off; | ||
153 | if (i > outl) i=outl; | ||
154 | memcpy(out,&(ctx->buf[ctx->buf_off]),i); | ||
155 | ret=i; | ||
156 | out+=i; | ||
157 | outl-=i; | ||
158 | ctx->buf_off+=i; | ||
159 | if (ctx->buf_len == ctx->buf_off) | ||
160 | { | ||
161 | ctx->buf_len=0; | ||
162 | ctx->buf_off=0; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | /* At this point, we have room of outl bytes and an empty | ||
167 | * buffer, so we should read in some more. */ | ||
168 | |||
169 | while (outl > 0) | ||
170 | { | ||
171 | if (ctx->cont <= 0) break; | ||
172 | |||
173 | /* read in at offset 8, read the EVP_Cipher | ||
174 | * documentation about why */ | ||
175 | i=BIO_read(b->next_bio,&(ctx->buf[8]),ENC_BLOCK_SIZE); | ||
176 | |||
177 | if (i <= 0) | ||
178 | { | ||
179 | /* Should be continue next time we are called? */ | ||
180 | if (!BIO_should_retry(b->next_bio)) | ||
181 | { | ||
182 | ctx->cont=i; | ||
183 | i=EVP_CipherFinal(&(ctx->cipher), | ||
184 | (unsigned char *)ctx->buf, | ||
185 | &(ctx->buf_len)); | ||
186 | ctx->ok=i; | ||
187 | ctx->buf_off=0; | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | ret=(ret == 0)?i:ret; | ||
192 | break; | ||
193 | } | ||
194 | } | ||
195 | else | ||
196 | { | ||
197 | EVP_CipherUpdate(&(ctx->cipher), | ||
198 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
199 | (unsigned char *)&(ctx->buf[8]),i); | ||
200 | ctx->cont=1; | ||
201 | /* Note: it is possible for EVP_CipherUpdate to | ||
202 | * decrypt zero bytes because this is or looks like | ||
203 | * the final block: if this happens we should retry | ||
204 | * and either read more data or decrypt the final | ||
205 | * block | ||
206 | */ | ||
207 | if(ctx->buf_len == 0) continue; | ||
208 | } | ||
209 | |||
210 | if (ctx->buf_len <= outl) | ||
211 | i=ctx->buf_len; | ||
212 | else | ||
213 | i=outl; | ||
214 | if (i <= 0) break; | ||
215 | memcpy(out,ctx->buf,i); | ||
216 | ret+=i; | ||
217 | ctx->buf_off=i; | ||
218 | outl-=i; | ||
219 | out+=i; | ||
220 | } | ||
221 | |||
222 | BIO_clear_retry_flags(b); | ||
223 | BIO_copy_next_retry(b); | ||
224 | return((ret == 0)?ctx->cont:ret); | ||
225 | } | ||
226 | |||
227 | static int enc_write(BIO *b, const char *in, int inl) | ||
228 | { | ||
229 | int ret=0,n,i; | ||
230 | BIO_ENC_CTX *ctx; | ||
231 | |||
232 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
233 | ret=inl; | ||
234 | |||
235 | BIO_clear_retry_flags(b); | ||
236 | n=ctx->buf_len-ctx->buf_off; | ||
237 | while (n > 0) | ||
238 | { | ||
239 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
240 | if (i <= 0) | ||
241 | { | ||
242 | BIO_copy_next_retry(b); | ||
243 | return(i); | ||
244 | } | ||
245 | ctx->buf_off+=i; | ||
246 | n-=i; | ||
247 | } | ||
248 | /* at this point all pending data has been written */ | ||
249 | |||
250 | if ((in == NULL) || (inl <= 0)) return(0); | ||
251 | |||
252 | ctx->buf_off=0; | ||
253 | while (inl > 0) | ||
254 | { | ||
255 | n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl; | ||
256 | EVP_CipherUpdate(&(ctx->cipher), | ||
257 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
258 | (unsigned char *)in,n); | ||
259 | inl-=n; | ||
260 | in+=n; | ||
261 | |||
262 | ctx->buf_off=0; | ||
263 | n=ctx->buf_len; | ||
264 | while (n > 0) | ||
265 | { | ||
266 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
267 | if (i <= 0) | ||
268 | { | ||
269 | BIO_copy_next_retry(b); | ||
270 | return(i); | ||
271 | } | ||
272 | n-=i; | ||
273 | ctx->buf_off+=i; | ||
274 | } | ||
275 | ctx->buf_len=0; | ||
276 | ctx->buf_off=0; | ||
277 | } | ||
278 | BIO_copy_next_retry(b); | ||
279 | return(ret); | ||
280 | } | ||
281 | |||
282 | static long enc_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
283 | { | ||
284 | BIO *dbio; | ||
285 | BIO_ENC_CTX *ctx,*dctx; | ||
286 | long ret=1; | ||
287 | int i; | ||
288 | EVP_CIPHER_CTX **c_ctx; | ||
289 | |||
290 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
291 | |||
292 | switch (cmd) | ||
293 | { | ||
294 | case BIO_CTRL_RESET: | ||
295 | ctx->ok=1; | ||
296 | ctx->finished=0; | ||
297 | EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL, | ||
298 | ctx->cipher.encrypt); | ||
299 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
300 | break; | ||
301 | case BIO_CTRL_EOF: /* More to read */ | ||
302 | if (ctx->cont <= 0) | ||
303 | ret=1; | ||
304 | else | ||
305 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
306 | break; | ||
307 | case BIO_CTRL_WPENDING: | ||
308 | ret=ctx->buf_len-ctx->buf_off; | ||
309 | if (ret <= 0) | ||
310 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
311 | break; | ||
312 | case BIO_CTRL_PENDING: /* More to read in buffer */ | ||
313 | ret=ctx->buf_len-ctx->buf_off; | ||
314 | if (ret <= 0) | ||
315 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
316 | break; | ||
317 | case BIO_CTRL_FLUSH: | ||
318 | /* do a final write */ | ||
319 | again: | ||
320 | while (ctx->buf_len != ctx->buf_off) | ||
321 | { | ||
322 | i=enc_write(b,NULL,0); | ||
323 | if (i < 0) | ||
324 | { | ||
325 | ret=i; | ||
326 | break; | ||
327 | } | ||
328 | } | ||
329 | |||
330 | if (!ctx->finished) | ||
331 | { | ||
332 | ctx->finished=1; | ||
333 | ctx->buf_off=0; | ||
334 | ret=EVP_CipherFinal(&(ctx->cipher), | ||
335 | (unsigned char *)ctx->buf, | ||
336 | &(ctx->buf_len)); | ||
337 | ctx->ok=(int)ret; | ||
338 | if (ret <= 0) break; | ||
339 | |||
340 | /* push out the bytes */ | ||
341 | goto again; | ||
342 | } | ||
343 | |||
344 | /* Finally flush the underlying BIO */ | ||
345 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
346 | break; | ||
347 | case BIO_C_GET_CIPHER_STATUS: | ||
348 | ret=(long)ctx->ok; | ||
349 | break; | ||
350 | case BIO_C_DO_STATE_MACHINE: | ||
351 | BIO_clear_retry_flags(b); | ||
352 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
353 | BIO_copy_next_retry(b); | ||
354 | break; | ||
355 | case BIO_C_GET_CIPHER_CTX: | ||
356 | c_ctx=(EVP_CIPHER_CTX **)ptr; | ||
357 | (*c_ctx)= &(ctx->cipher); | ||
358 | b->init=1; | ||
359 | break; | ||
360 | case BIO_CTRL_DUP: | ||
361 | dbio=(BIO *)ptr; | ||
362 | dctx=(BIO_ENC_CTX *)dbio->ptr; | ||
363 | memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher)); | ||
364 | dbio->init=1; | ||
365 | break; | ||
366 | default: | ||
367 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
368 | break; | ||
369 | } | ||
370 | return(ret); | ||
371 | } | ||
372 | |||
373 | static long enc_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | ||
374 | { | ||
375 | long ret=1; | ||
376 | |||
377 | if (b->next_bio == NULL) return(0); | ||
378 | switch (cmd) | ||
379 | { | ||
380 | default: | ||
381 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | ||
382 | break; | ||
383 | } | ||
384 | return(ret); | ||
385 | } | ||
386 | |||
387 | /* | ||
388 | void BIO_set_cipher_ctx(b,c) | ||
389 | BIO *b; | ||
390 | EVP_CIPHER_ctx *c; | ||
391 | { | ||
392 | if (b == NULL) return; | ||
393 | |||
394 | if ((b->callback != NULL) && | ||
395 | (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0)) | ||
396 | return; | ||
397 | |||
398 | b->init=1; | ||
399 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
400 | memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX)); | ||
401 | |||
402 | if (b->callback != NULL) | ||
403 | b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L); | ||
404 | } | ||
405 | */ | ||
406 | |||
407 | void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k, | ||
408 | unsigned char *i, int e) | ||
409 | { | ||
410 | BIO_ENC_CTX *ctx; | ||
411 | |||
412 | if (b == NULL) return; | ||
413 | |||
414 | if ((b->callback != NULL) && | ||
415 | (b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,0L) <= 0)) | ||
416 | return; | ||
417 | |||
418 | b->init=1; | ||
419 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
420 | EVP_CipherInit(&(ctx->cipher),c,k,i,e); | ||
421 | |||
422 | if (b->callback != NULL) | ||
423 | b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L); | ||
424 | } | ||
425 | |||
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c deleted file mode 100644 index 2373c247d8..0000000000 --- a/src/lib/libcrypto/evp/bio_md.c +++ /dev/null | |||
@@ -1,261 +0,0 @@ | |||
1 | /* crypto/evp/bio_md.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include <errno.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/buffer.h> | ||
63 | #include <openssl/evp.h> | ||
64 | |||
65 | /* BIO_put and BIO_get both add to the digest, | ||
66 | * BIO_gets returns the digest */ | ||
67 | |||
68 | static int md_write(BIO *h, char const *buf, int num); | ||
69 | static int md_read(BIO *h, char *buf, int size); | ||
70 | /*static int md_puts(BIO *h, const char *str); */ | ||
71 | static int md_gets(BIO *h, char *str, int size); | ||
72 | static long md_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
73 | static int md_new(BIO *h); | ||
74 | static int md_free(BIO *data); | ||
75 | static long md_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp); | ||
76 | |||
77 | static BIO_METHOD methods_md= | ||
78 | { | ||
79 | BIO_TYPE_MD,"message digest", | ||
80 | md_write, | ||
81 | md_read, | ||
82 | NULL, /* md_puts, */ | ||
83 | md_gets, | ||
84 | md_ctrl, | ||
85 | md_new, | ||
86 | md_free, | ||
87 | md_callback_ctrl, | ||
88 | }; | ||
89 | |||
90 | BIO_METHOD *BIO_f_md(void) | ||
91 | { | ||
92 | return(&methods_md); | ||
93 | } | ||
94 | |||
95 | static int md_new(BIO *bi) | ||
96 | { | ||
97 | EVP_MD_CTX *ctx; | ||
98 | |||
99 | ctx=(EVP_MD_CTX *)OPENSSL_malloc(sizeof(EVP_MD_CTX)); | ||
100 | if (ctx == NULL) return(0); | ||
101 | |||
102 | bi->init=0; | ||
103 | bi->ptr=(char *)ctx; | ||
104 | bi->flags=0; | ||
105 | return(1); | ||
106 | } | ||
107 | |||
108 | static int md_free(BIO *a) | ||
109 | { | ||
110 | if (a == NULL) return(0); | ||
111 | OPENSSL_free(a->ptr); | ||
112 | a->ptr=NULL; | ||
113 | a->init=0; | ||
114 | a->flags=0; | ||
115 | return(1); | ||
116 | } | ||
117 | |||
118 | static int md_read(BIO *b, char *out, int outl) | ||
119 | { | ||
120 | int ret=0; | ||
121 | EVP_MD_CTX *ctx; | ||
122 | |||
123 | if (out == NULL) return(0); | ||
124 | ctx=(EVP_MD_CTX *)b->ptr; | ||
125 | |||
126 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
127 | |||
128 | ret=BIO_read(b->next_bio,out,outl); | ||
129 | if (b->init) | ||
130 | { | ||
131 | if (ret > 0) | ||
132 | { | ||
133 | EVP_DigestUpdate(ctx,(unsigned char *)out, | ||
134 | (unsigned int)ret); | ||
135 | } | ||
136 | } | ||
137 | BIO_clear_retry_flags(b); | ||
138 | BIO_copy_next_retry(b); | ||
139 | return(ret); | ||
140 | } | ||
141 | |||
142 | static int md_write(BIO *b, const char *in, int inl) | ||
143 | { | ||
144 | int ret=0; | ||
145 | EVP_MD_CTX *ctx; | ||
146 | |||
147 | if ((in == NULL) || (inl <= 0)) return(0); | ||
148 | ctx=(EVP_MD_CTX *)b->ptr; | ||
149 | |||
150 | if ((ctx != NULL) && (b->next_bio != NULL)) | ||
151 | ret=BIO_write(b->next_bio,in,inl); | ||
152 | if (b->init) | ||
153 | { | ||
154 | if (ret > 0) | ||
155 | { | ||
156 | EVP_DigestUpdate(ctx,(unsigned char *)in, | ||
157 | (unsigned int)ret); | ||
158 | } | ||
159 | } | ||
160 | BIO_clear_retry_flags(b); | ||
161 | BIO_copy_next_retry(b); | ||
162 | return(ret); | ||
163 | } | ||
164 | |||
165 | static long md_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
166 | { | ||
167 | EVP_MD_CTX *ctx,*dctx,**pctx; | ||
168 | const EVP_MD **ppmd; | ||
169 | EVP_MD *md; | ||
170 | long ret=1; | ||
171 | BIO *dbio; | ||
172 | |||
173 | ctx=(EVP_MD_CTX *)b->ptr; | ||
174 | |||
175 | switch (cmd) | ||
176 | { | ||
177 | case BIO_CTRL_RESET: | ||
178 | if (b->init) | ||
179 | EVP_DigestInit(ctx,ctx->digest); | ||
180 | else | ||
181 | ret=0; | ||
182 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
183 | break; | ||
184 | case BIO_C_GET_MD: | ||
185 | if (b->init) | ||
186 | { | ||
187 | ppmd=(const EVP_MD **)ptr; | ||
188 | *ppmd=ctx->digest; | ||
189 | } | ||
190 | else | ||
191 | ret=0; | ||
192 | break; | ||
193 | case BIO_C_GET_MD_CTX: | ||
194 | if (b->init) | ||
195 | { | ||
196 | pctx=(EVP_MD_CTX **)ptr; | ||
197 | *pctx=ctx; | ||
198 | } | ||
199 | else | ||
200 | ret=0; | ||
201 | break; | ||
202 | case BIO_C_DO_STATE_MACHINE: | ||
203 | BIO_clear_retry_flags(b); | ||
204 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
205 | BIO_copy_next_retry(b); | ||
206 | break; | ||
207 | |||
208 | case BIO_C_SET_MD: | ||
209 | md=(EVP_MD *)ptr; | ||
210 | EVP_DigestInit(ctx,md); | ||
211 | b->init=1; | ||
212 | break; | ||
213 | case BIO_CTRL_DUP: | ||
214 | dbio=(BIO *)ptr; | ||
215 | dctx=(EVP_MD_CTX *)dbio->ptr; | ||
216 | memcpy(dctx,ctx,sizeof(ctx)); | ||
217 | b->init=1; | ||
218 | break; | ||
219 | default: | ||
220 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
221 | break; | ||
222 | } | ||
223 | return(ret); | ||
224 | } | ||
225 | |||
226 | static long md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | ||
227 | { | ||
228 | long ret=1; | ||
229 | |||
230 | if (b->next_bio == NULL) return(0); | ||
231 | switch (cmd) | ||
232 | { | ||
233 | default: | ||
234 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | ||
235 | break; | ||
236 | } | ||
237 | return(ret); | ||
238 | } | ||
239 | |||
240 | static int md_gets(BIO *bp, char *buf, int size) | ||
241 | { | ||
242 | EVP_MD_CTX *ctx; | ||
243 | unsigned int ret; | ||
244 | |||
245 | |||
246 | ctx=(EVP_MD_CTX *)bp->ptr; | ||
247 | if (size < ctx->digest->md_size) | ||
248 | return(0); | ||
249 | EVP_DigestFinal(ctx,(unsigned char *)buf,&ret); | ||
250 | return((int)ret); | ||
251 | } | ||
252 | |||
253 | /* | ||
254 | static int md_puts(bp,str) | ||
255 | BIO *bp; | ||
256 | char *str; | ||
257 | { | ||
258 | return(-1); | ||
259 | } | ||
260 | */ | ||
261 | |||
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c deleted file mode 100644 index 1e185830a3..0000000000 --- a/src/lib/libcrypto/evp/c_all.c +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | /* crypto/evp/c_all.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | |||
63 | void OpenSSL_add_all_algorithms(void) | ||
64 | { | ||
65 | OpenSSL_add_all_ciphers(); | ||
66 | OpenSSL_add_all_digests(); | ||
67 | } | ||
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c deleted file mode 100644 index c560733568..0000000000 --- a/src/lib/libcrypto/evp/digest.c +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | /* crypto/evp/digest.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/objects.h> | ||
62 | #include <openssl/evp.h> | ||
63 | |||
64 | void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) | ||
65 | { | ||
66 | ctx->digest=type; | ||
67 | type->init(&(ctx->md)); | ||
68 | } | ||
69 | |||
70 | void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, | ||
71 | unsigned int count) | ||
72 | { | ||
73 | ctx->digest->update(&(ctx->md.base[0]),data,(unsigned long)count); | ||
74 | } | ||
75 | |||
76 | void EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) | ||
77 | { | ||
78 | ctx->digest->final(md,&(ctx->md.base[0])); | ||
79 | if (size != NULL) | ||
80 | *size=ctx->digest->md_size; | ||
81 | memset(&(ctx->md),0,sizeof(ctx->md)); | ||
82 | } | ||
83 | |||
84 | int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in) | ||
85 | { | ||
86 | if ((in == NULL) || (in->digest == NULL)) { | ||
87 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); | ||
88 | return 0; | ||
89 | } | ||
90 | memcpy((char *)out,(char *)in,in->digest->ctx_size); | ||
91 | return 1; | ||
92 | } | ||
diff --git a/src/lib/libcrypto/evp/e_bf.c b/src/lib/libcrypto/evp/e_bf.c deleted file mode 100644 index 53559b0b65..0000000000 --- a/src/lib/libcrypto/evp/e_bf.c +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | /* crypto/evp/e_bf.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_BF | ||
60 | #include <stdio.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/evp.h> | ||
63 | #include "evp_locl.h" | ||
64 | #include <openssl/objects.h> | ||
65 | |||
66 | static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
67 | const unsigned char *iv, int enc); | ||
68 | |||
69 | IMPLEMENT_BLOCK_CIPHER(bf, bf_ks, BF, bf_ks, NID_bf, 8, 16, 8, | ||
70 | EVP_CIPH_VARIABLE_LENGTH, bf_init_key, NULL, | ||
71 | EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL) | ||
72 | |||
73 | static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
74 | const unsigned char *iv, int enc) | ||
75 | { | ||
76 | BF_set_key(&(ctx->c.bf_ks),EVP_CIPHER_CTX_key_length(ctx),key); | ||
77 | return 1; | ||
78 | } | ||
79 | |||
80 | #endif | ||
diff --git a/src/lib/libcrypto/evp/e_cast.c b/src/lib/libcrypto/evp/e_cast.c deleted file mode 100644 index e5af7fb4ed..0000000000 --- a/src/lib/libcrypto/evp/e_cast.c +++ /dev/null | |||
@@ -1,82 +0,0 @@ | |||
1 | /* crypto/evp/e_cast.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_CAST | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include <openssl/evp.h> | ||
64 | #include <openssl/objects.h> | ||
65 | #include "evp_locl.h" | ||
66 | |||
67 | static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
68 | const unsigned char *iv,int enc); | ||
69 | |||
70 | IMPLEMENT_BLOCK_CIPHER(cast5, cast_ks, CAST, cast_ks, | ||
71 | NID_cast5, 8, EVP_CAST5_KEY_SIZE, 8, | ||
72 | EVP_CIPH_VARIABLE_LENGTH, cast_init_key, NULL, | ||
73 | EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL) | ||
74 | |||
75 | static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
76 | const unsigned char *iv, int enc) | ||
77 | { | ||
78 | CAST_set_key(&(ctx->c.cast_ks),EVP_CIPHER_CTX_key_length(ctx),key); | ||
79 | return 1; | ||
80 | } | ||
81 | |||
82 | #endif | ||
diff --git a/src/lib/libcrypto/evp/e_des.c b/src/lib/libcrypto/evp/e_des.c deleted file mode 100644 index f4e998b81c..0000000000 --- a/src/lib/libcrypto/evp/e_des.c +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | /* crypto/evp/e_des.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_DES | ||
60 | #include <stdio.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include "evp_locl.h" | ||
65 | |||
66 | static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
67 | const unsigned char *iv, int enc); | ||
68 | |||
69 | /* Because of various casts and different names can't use IMPLEMENT_BLOCK_CIPHER */ | ||
70 | |||
71 | static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
72 | const unsigned char *in, unsigned int inl) | ||
73 | { | ||
74 | BLOCK_CIPHER_ecb_loop() | ||
75 | des_ecb_encrypt((des_cblock *)(in + i), (des_cblock *)(out + i), ctx->c.des_ks, ctx->encrypt); | ||
76 | return 1; | ||
77 | } | ||
78 | |||
79 | static int des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
80 | const unsigned char *in, unsigned int inl) | ||
81 | { | ||
82 | des_ofb64_encrypt(in, out, (long)inl, ctx->c.des_ks, (des_cblock *)ctx->iv, &ctx->num); | ||
83 | return 1; | ||
84 | } | ||
85 | |||
86 | static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
87 | const unsigned char *in, unsigned int inl) | ||
88 | { | ||
89 | des_ncbc_encrypt(in, out, (long)inl, ctx->c.des_ks, | ||
90 | (des_cblock *)ctx->iv, ctx->encrypt); | ||
91 | return 1; | ||
92 | } | ||
93 | |||
94 | static int des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
95 | const unsigned char *in, unsigned int inl) | ||
96 | { | ||
97 | des_cfb64_encrypt(in, out, (long)inl, ctx->c.des_ks, | ||
98 | (des_cblock *)ctx->iv, &ctx->num, ctx->encrypt); | ||
99 | return 1; | ||
100 | } | ||
101 | |||
102 | BLOCK_CIPHER_defs(des, des_ks, NID_des, 8, 8, 8, | ||
103 | 0, des_init_key, NULL, | ||
104 | EVP_CIPHER_set_asn1_iv, | ||
105 | EVP_CIPHER_get_asn1_iv, | ||
106 | NULL) | ||
107 | |||
108 | |||
109 | static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
110 | const unsigned char *iv, int enc) | ||
111 | { | ||
112 | des_cblock *deskey = (des_cblock *)key; | ||
113 | |||
114 | des_set_key_unchecked(deskey,ctx->c.des_ks); | ||
115 | return 1; | ||
116 | } | ||
117 | |||
118 | #endif | ||
diff --git a/src/lib/libcrypto/evp/e_des3.c b/src/lib/libcrypto/evp/e_des3.c deleted file mode 100644 index a9aba4ae70..0000000000 --- a/src/lib/libcrypto/evp/e_des3.c +++ /dev/null | |||
@@ -1,165 +0,0 @@ | |||
1 | /* crypto/evp/e_des3.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_DES | ||
60 | #include <stdio.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include "evp_locl.h" | ||
65 | |||
66 | static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
67 | const unsigned char *iv,int enc); | ||
68 | |||
69 | static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
70 | const unsigned char *iv,int enc); | ||
71 | |||
72 | /* Because of various casts and different args can't use IMPLEMENT_BLOCK_CIPHER */ | ||
73 | |||
74 | static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
75 | const unsigned char *in, unsigned int inl) | ||
76 | { | ||
77 | BLOCK_CIPHER_ecb_loop() | ||
78 | des_ecb3_encrypt((des_cblock *)(in + i), (des_cblock *)(out + i), | ||
79 | ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, | ||
80 | ctx->encrypt); | ||
81 | return 1; | ||
82 | } | ||
83 | |||
84 | static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
85 | const unsigned char *in, unsigned int inl) | ||
86 | { | ||
87 | des_ede3_ofb64_encrypt(in, out, (long)inl, | ||
88 | ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, | ||
89 | (des_cblock *)ctx->iv, &ctx->num); | ||
90 | return 1; | ||
91 | } | ||
92 | |||
93 | static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
94 | const unsigned char *in, unsigned int inl) | ||
95 | { | ||
96 | des_ede3_cbc_encrypt(in, out, (long)inl, | ||
97 | ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, | ||
98 | (des_cblock *)ctx->iv, ctx->encrypt); | ||
99 | return 1; | ||
100 | } | ||
101 | |||
102 | static int des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
103 | const unsigned char *in, unsigned int inl) | ||
104 | { | ||
105 | des_ede3_cfb64_encrypt(in, out, (long)inl, | ||
106 | ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, | ||
107 | (des_cblock *)ctx->iv, &ctx->num, ctx->encrypt); | ||
108 | return 1; | ||
109 | } | ||
110 | |||
111 | #define NID_des_ede_ecb NID_des_ede | ||
112 | |||
113 | BLOCK_CIPHER_defs(des_ede, des_ede, NID_des_ede, 8, 16, 8, | ||
114 | 0, des_ede_init_key, NULL, | ||
115 | EVP_CIPHER_set_asn1_iv, | ||
116 | EVP_CIPHER_get_asn1_iv, | ||
117 | NULL) | ||
118 | |||
119 | #define NID_des_ede3_ecb NID_des_ede3 | ||
120 | #define des_ede3_cfb_cipher des_ede_cfb_cipher | ||
121 | #define des_ede3_ofb_cipher des_ede_ofb_cipher | ||
122 | #define des_ede3_cbc_cipher des_ede_cbc_cipher | ||
123 | #define des_ede3_ecb_cipher des_ede_ecb_cipher | ||
124 | |||
125 | BLOCK_CIPHER_defs(des_ede3, des_ede, NID_des_ede3, 8, 24, 8, | ||
126 | 0, des_ede3_init_key, NULL, | ||
127 | EVP_CIPHER_set_asn1_iv, | ||
128 | EVP_CIPHER_get_asn1_iv, | ||
129 | NULL) | ||
130 | |||
131 | static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
132 | const unsigned char *iv, int enc) | ||
133 | { | ||
134 | des_cblock *deskey = (des_cblock *)key; | ||
135 | |||
136 | des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1); | ||
137 | des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2); | ||
138 | memcpy( (char *)ctx->c.des_ede.ks3, | ||
139 | (char *)ctx->c.des_ede.ks1, | ||
140 | sizeof(ctx->c.des_ede.ks1)); | ||
141 | return 1; | ||
142 | } | ||
143 | |||
144 | static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
145 | const unsigned char *iv, int enc) | ||
146 | { | ||
147 | des_cblock *deskey = (des_cblock *)key; | ||
148 | |||
149 | des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1); | ||
150 | des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2); | ||
151 | des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3); | ||
152 | |||
153 | return 1; | ||
154 | } | ||
155 | |||
156 | EVP_CIPHER *EVP_des_ede(void) | ||
157 | { | ||
158 | return &des_ede_ecb; | ||
159 | } | ||
160 | |||
161 | EVP_CIPHER *EVP_des_ede3(void) | ||
162 | { | ||
163 | return &des_ede3_ecb; | ||
164 | } | ||
165 | #endif | ||
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c deleted file mode 100644 index 8d3c88deb7..0000000000 --- a/src/lib/libcrypto/evp/e_idea.c +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | /* crypto/evp/e_idea.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_IDEA | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include <openssl/evp.h> | ||
64 | #include <openssl/objects.h> | ||
65 | #include "evp_locl.h" | ||
66 | |||
67 | static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
68 | const unsigned char *iv,int enc); | ||
69 | |||
70 | /* NB idea_ecb_encrypt doesn't take an 'encrypt' argument so we treat it as a special | ||
71 | * case | ||
72 | */ | ||
73 | |||
74 | static int idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
75 | const unsigned char *in, unsigned int inl) | ||
76 | { | ||
77 | BLOCK_CIPHER_ecb_loop() | ||
78 | idea_ecb_encrypt(in + i, out + i, &ctx->c.idea_ks); | ||
79 | return 1; | ||
80 | } | ||
81 | |||
82 | /* Can't use IMPLEMENT_BLOCK_CIPHER because idea_ecb_encrypt is different */ | ||
83 | |||
84 | BLOCK_CIPHER_func_cbc(idea, idea, idea_ks) | ||
85 | BLOCK_CIPHER_func_ofb(idea, idea, idea_ks) | ||
86 | BLOCK_CIPHER_func_cfb(idea, idea, idea_ks) | ||
87 | |||
88 | BLOCK_CIPHER_defs(idea, idea_ks, NID_idea, 8, 16, 8, | ||
89 | 0, idea_init_key, NULL, | ||
90 | EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL) | ||
91 | |||
92 | static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
93 | const unsigned char *iv, int enc) | ||
94 | { | ||
95 | if(!enc) { | ||
96 | if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE) enc = 1; | ||
97 | else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE) enc = 1; | ||
98 | } | ||
99 | if (enc) idea_set_encrypt_key(key,&(ctx->c.idea_ks)); | ||
100 | else | ||
101 | { | ||
102 | IDEA_KEY_SCHEDULE tmp; | ||
103 | |||
104 | idea_set_encrypt_key(key,&tmp); | ||
105 | idea_set_decrypt_key(&tmp,&(ctx->c.idea_ks)); | ||
106 | memset((unsigned char *)&tmp,0, | ||
107 | sizeof(IDEA_KEY_SCHEDULE)); | ||
108 | } | ||
109 | return 1; | ||
110 | } | ||
111 | |||
112 | #endif | ||
diff --git a/src/lib/libcrypto/evp/e_null.c b/src/lib/libcrypto/evp/e_null.c deleted file mode 100644 index e0702cf818..0000000000 --- a/src/lib/libcrypto/evp/e_null.c +++ /dev/null | |||
@@ -1,101 +0,0 @@ | |||
1 | /* crypto/evp/e_null.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/objects.h> | ||
63 | |||
64 | static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
65 | const unsigned char *iv,int enc); | ||
66 | static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
67 | const unsigned char *in, unsigned int inl); | ||
68 | static EVP_CIPHER n_cipher= | ||
69 | { | ||
70 | NID_undef, | ||
71 | 1,0,0, | ||
72 | 0, | ||
73 | null_init_key, | ||
74 | null_cipher, | ||
75 | NULL, | ||
76 | 0, | ||
77 | NULL, | ||
78 | NULL, | ||
79 | NULL | ||
80 | }; | ||
81 | |||
82 | EVP_CIPHER *EVP_enc_null(void) | ||
83 | { | ||
84 | return(&n_cipher); | ||
85 | } | ||
86 | |||
87 | static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
88 | const unsigned char *iv, int enc) | ||
89 | { | ||
90 | memset(&(ctx->c),0,sizeof(ctx->c)); | ||
91 | return 1; | ||
92 | } | ||
93 | |||
94 | static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
95 | const unsigned char *in, unsigned int inl) | ||
96 | { | ||
97 | if (in != out) | ||
98 | memcpy((char *)out,(char *)in,(int)inl); | ||
99 | return 1; | ||
100 | } | ||
101 | |||
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c deleted file mode 100644 index 3955c3ef84..0000000000 --- a/src/lib/libcrypto/evp/e_rc2.c +++ /dev/null | |||
@@ -1,222 +0,0 @@ | |||
1 | /* crypto/evp/e_rc2.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_RC2 | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include <openssl/evp.h> | ||
64 | #include <openssl/objects.h> | ||
65 | #include "evp_locl.h" | ||
66 | |||
67 | static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
68 | const unsigned char *iv,int enc); | ||
69 | static int rc2_meth_to_magic(EVP_CIPHER_CTX *ctx); | ||
70 | static int rc2_magic_to_meth(int i); | ||
71 | static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
72 | static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
73 | static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); | ||
74 | |||
75 | IMPLEMENT_BLOCK_CIPHER(rc2, rc2.ks, RC2, rc2, NID_rc2, | ||
76 | 8, | ||
77 | EVP_RC2_KEY_SIZE, 8, | ||
78 | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT, | ||
79 | rc2_init_key, NULL, | ||
80 | rc2_set_asn1_type_and_iv, rc2_get_asn1_type_and_iv, | ||
81 | rc2_ctrl) | ||
82 | |||
83 | #define RC2_40_MAGIC 0xa0 | ||
84 | #define RC2_64_MAGIC 0x78 | ||
85 | #define RC2_128_MAGIC 0x3a | ||
86 | |||
87 | static EVP_CIPHER r2_64_cbc_cipher= | ||
88 | { | ||
89 | NID_rc2_64_cbc, | ||
90 | 8,8 /* 64 bit */,8, | ||
91 | EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT, | ||
92 | rc2_init_key, | ||
93 | rc2_cbc_cipher, | ||
94 | NULL, | ||
95 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ | ||
96 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2)), | ||
97 | rc2_set_asn1_type_and_iv, | ||
98 | rc2_get_asn1_type_and_iv, | ||
99 | rc2_ctrl, | ||
100 | NULL | ||
101 | }; | ||
102 | |||
103 | static EVP_CIPHER r2_40_cbc_cipher= | ||
104 | { | ||
105 | NID_rc2_40_cbc, | ||
106 | 8,5 /* 40 bit */,8, | ||
107 | EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT, | ||
108 | rc2_init_key, | ||
109 | rc2_cbc_cipher, | ||
110 | NULL, | ||
111 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ | ||
112 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2)), | ||
113 | rc2_set_asn1_type_and_iv, | ||
114 | rc2_get_asn1_type_and_iv, | ||
115 | rc2_ctrl, | ||
116 | NULL | ||
117 | }; | ||
118 | |||
119 | EVP_CIPHER *EVP_rc2_64_cbc(void) | ||
120 | { | ||
121 | return(&r2_64_cbc_cipher); | ||
122 | } | ||
123 | |||
124 | EVP_CIPHER *EVP_rc2_40_cbc(void) | ||
125 | { | ||
126 | return(&r2_40_cbc_cipher); | ||
127 | } | ||
128 | |||
129 | static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
130 | const unsigned char *iv, int enc) | ||
131 | { | ||
132 | RC2_set_key(&(ctx->c.rc2.ks),EVP_CIPHER_CTX_key_length(ctx), | ||
133 | key,ctx->c.rc2.key_bits); | ||
134 | return 1; | ||
135 | } | ||
136 | |||
137 | static int rc2_meth_to_magic(EVP_CIPHER_CTX *e) | ||
138 | { | ||
139 | int i; | ||
140 | |||
141 | EVP_CIPHER_CTX_ctrl(e, EVP_CTRL_GET_RC2_KEY_BITS, 0, &i); | ||
142 | if (i == 128) return(RC2_128_MAGIC); | ||
143 | else if (i == 64) return(RC2_64_MAGIC); | ||
144 | else if (i == 40) return(RC2_40_MAGIC); | ||
145 | else return(0); | ||
146 | } | ||
147 | |||
148 | static int rc2_magic_to_meth(int i) | ||
149 | { | ||
150 | if (i == RC2_128_MAGIC) return 128; | ||
151 | else if (i == RC2_64_MAGIC) return 64; | ||
152 | else if (i == RC2_40_MAGIC) return 40; | ||
153 | else | ||
154 | { | ||
155 | EVPerr(EVP_F_RC2_MAGIC_TO_METH,EVP_R_UNSUPPORTED_KEY_SIZE); | ||
156 | return(0); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | ||
161 | { | ||
162 | long num=0; | ||
163 | int i=0,l; | ||
164 | int key_bits; | ||
165 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
166 | |||
167 | if (type != NULL) | ||
168 | { | ||
169 | l=EVP_CIPHER_CTX_iv_length(c); | ||
170 | i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l); | ||
171 | if (i != l) | ||
172 | return(-1); | ||
173 | key_bits =rc2_magic_to_meth((int)num); | ||
174 | if (!key_bits) | ||
175 | return(-1); | ||
176 | if(i > 0) EVP_CipherInit(c, NULL, NULL, iv, -1); | ||
177 | EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL); | ||
178 | EVP_CIPHER_CTX_set_key_length(c, key_bits / 8); | ||
179 | } | ||
180 | return(i); | ||
181 | } | ||
182 | |||
183 | static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | ||
184 | { | ||
185 | long num; | ||
186 | int i=0,j; | ||
187 | |||
188 | if (type != NULL) | ||
189 | { | ||
190 | num=rc2_meth_to_magic(c); | ||
191 | j=EVP_CIPHER_CTX_iv_length(c); | ||
192 | i=ASN1_TYPE_set_int_octetstring(type,num,c->oiv,j); | ||
193 | } | ||
194 | return(i); | ||
195 | } | ||
196 | |||
197 | static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | ||
198 | { | ||
199 | switch(type) { | ||
200 | |||
201 | case EVP_CTRL_INIT: | ||
202 | c->c.rc2.key_bits = EVP_CIPHER_CTX_key_length(c) * 8; | ||
203 | return 1; | ||
204 | |||
205 | case EVP_CTRL_GET_RC2_KEY_BITS: | ||
206 | *(int *)ptr = c->c.rc2.key_bits; | ||
207 | return 1; | ||
208 | |||
209 | |||
210 | case EVP_CTRL_SET_RC2_KEY_BITS: | ||
211 | if(arg > 0) { | ||
212 | c->c.rc2.key_bits = arg; | ||
213 | return 1; | ||
214 | } | ||
215 | return 0; | ||
216 | |||
217 | default: | ||
218 | return -1; | ||
219 | } | ||
220 | } | ||
221 | |||
222 | #endif | ||
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c deleted file mode 100644 index 1c1e3b3857..0000000000 --- a/src/lib/libcrypto/evp/e_rc4.c +++ /dev/null | |||
@@ -1,125 +0,0 @@ | |||
1 | /* crypto/evp/e_rc4.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_RC4 | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include <openssl/evp.h> | ||
64 | #include <openssl/objects.h> | ||
65 | |||
66 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
67 | const unsigned char *iv,int enc); | ||
68 | static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
69 | const unsigned char *in, unsigned int inl); | ||
70 | static EVP_CIPHER r4_cipher= | ||
71 | { | ||
72 | NID_rc4, | ||
73 | 1,EVP_RC4_KEY_SIZE,0, | ||
74 | EVP_CIPH_VARIABLE_LENGTH, | ||
75 | rc4_init_key, | ||
76 | rc4_cipher, | ||
77 | NULL, | ||
78 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ | ||
79 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc4)), | ||
80 | NULL, | ||
81 | NULL, | ||
82 | NULL | ||
83 | }; | ||
84 | |||
85 | static EVP_CIPHER r4_40_cipher= | ||
86 | { | ||
87 | NID_rc4_40, | ||
88 | 1,5 /* 40 bit */,0, | ||
89 | EVP_CIPH_VARIABLE_LENGTH, | ||
90 | rc4_init_key, | ||
91 | rc4_cipher, | ||
92 | NULL, | ||
93 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ | ||
94 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc4)), | ||
95 | NULL, | ||
96 | NULL, | ||
97 | NULL | ||
98 | }; | ||
99 | |||
100 | EVP_CIPHER *EVP_rc4(void) | ||
101 | { | ||
102 | return(&r4_cipher); | ||
103 | } | ||
104 | |||
105 | EVP_CIPHER *EVP_rc4_40(void) | ||
106 | { | ||
107 | return(&r4_40_cipher); | ||
108 | } | ||
109 | |||
110 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
111 | const unsigned char *iv, int enc) | ||
112 | { | ||
113 | memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx)); | ||
114 | RC4_set_key(&(ctx->c.rc4.ks),EVP_CIPHER_CTX_key_length(ctx), | ||
115 | ctx->c.rc4.key); | ||
116 | return 1; | ||
117 | } | ||
118 | |||
119 | static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
120 | const unsigned char *in, unsigned int inl) | ||
121 | { | ||
122 | RC4(&(ctx->c.rc4.ks),inl,in,out); | ||
123 | return 1; | ||
124 | } | ||
125 | #endif | ||
diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c deleted file mode 100644 index e5b15acc7d..0000000000 --- a/src/lib/libcrypto/evp/e_xcbc_d.c +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
1 | /* crypto/evp/e_xcbc_d.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_DES | ||
60 | #include <stdio.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | |||
65 | static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
66 | const unsigned char *iv,int enc); | ||
67 | static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
68 | const unsigned char *in, unsigned int inl); | ||
69 | static EVP_CIPHER d_xcbc_cipher= | ||
70 | { | ||
71 | NID_desx_cbc, | ||
72 | 8,24,8, | ||
73 | EVP_CIPH_CBC_MODE, | ||
74 | desx_cbc_init_key, | ||
75 | desx_cbc_cipher, | ||
76 | NULL, | ||
77 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ | ||
78 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.desx_cbc)), | ||
79 | EVP_CIPHER_set_asn1_iv, | ||
80 | EVP_CIPHER_get_asn1_iv, | ||
81 | NULL | ||
82 | }; | ||
83 | |||
84 | EVP_CIPHER *EVP_desx_cbc(void) | ||
85 | { | ||
86 | return(&d_xcbc_cipher); | ||
87 | } | ||
88 | |||
89 | static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
90 | const unsigned char *iv, int enc) | ||
91 | { | ||
92 | des_cblock *deskey = (des_cblock *)key; | ||
93 | |||
94 | des_set_key_unchecked(deskey,ctx->c.desx_cbc.ks); | ||
95 | memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8); | ||
96 | memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8); | ||
97 | |||
98 | return 1; | ||
99 | } | ||
100 | |||
101 | static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
102 | const unsigned char *in, unsigned int inl) | ||
103 | { | ||
104 | des_xcbc_encrypt(in,out,inl,ctx->c.desx_cbc.ks, | ||
105 | (des_cblock *)&(ctx->iv[0]), | ||
106 | &ctx->c.desx_cbc.inw, | ||
107 | &ctx->c.desx_cbc.outw, | ||
108 | ctx->encrypt); | ||
109 | return 1; | ||
110 | } | ||
111 | #endif | ||
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c deleted file mode 100644 index 6ff9c1783c..0000000000 --- a/src/lib/libcrypto/evp/encode.c +++ /dev/null | |||
@@ -1,437 +0,0 @@ | |||
1 | /* crypto/evp/encode.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | |||
63 | #ifndef CHARSET_EBCDIC | ||
64 | #define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f]) | ||
65 | #define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f]) | ||
66 | #else | ||
67 | /* We assume that PEM encoded files are EBCDIC files | ||
68 | * (i.e., printable text files). Convert them here while decoding. | ||
69 | * When encoding, output is EBCDIC (text) format again. | ||
70 | * (No need for conversion in the conv_bin2ascii macro, as the | ||
71 | * underlying textstring data_bin2ascii[] is already EBCDIC) | ||
72 | */ | ||
73 | #define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f]) | ||
74 | #define conv_ascii2bin(a) (data_ascii2bin[os_toascii[a]&0x7f]) | ||
75 | #endif | ||
76 | |||
77 | /* 64 char lines | ||
78 | * pad input with 0 | ||
79 | * left over chars are set to = | ||
80 | * 1 byte => xx== | ||
81 | * 2 bytes => xxx= | ||
82 | * 3 bytes => xxxx | ||
83 | */ | ||
84 | #define BIN_PER_LINE (64/4*3) | ||
85 | #define CHUNKS_PER_LINE (64/4) | ||
86 | #define CHAR_PER_LINE (64+1) | ||
87 | |||
88 | static unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\ | ||
89 | abcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
90 | |||
91 | /* 0xF0 is a EOLN | ||
92 | * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing). | ||
93 | * 0xF2 is EOF | ||
94 | * 0xE0 is ignore at start of line. | ||
95 | * 0xFF is error | ||
96 | */ | ||
97 | |||
98 | #define B64_EOLN 0xF0 | ||
99 | #define B64_CR 0xF1 | ||
100 | #define B64_EOF 0xF2 | ||
101 | #define B64_WS 0xE0 | ||
102 | #define B64_ERROR 0xFF | ||
103 | #define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3) | ||
104 | |||
105 | static unsigned char data_ascii2bin[128]={ | ||
106 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
107 | 0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF, | ||
108 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
109 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
110 | 0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
111 | 0xFF,0xFF,0xFF,0x3E,0xFF,0xF2,0xFF,0x3F, | ||
112 | 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B, | ||
113 | 0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF, | ||
114 | 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06, | ||
115 | 0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E, | ||
116 | 0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16, | ||
117 | 0x17,0x18,0x19,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
118 | 0xFF,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20, | ||
119 | 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28, | ||
120 | 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30, | ||
121 | 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
122 | }; | ||
123 | |||
124 | void EVP_EncodeInit(EVP_ENCODE_CTX *ctx) | ||
125 | { | ||
126 | ctx->length=48; | ||
127 | ctx->num=0; | ||
128 | ctx->line_num=0; | ||
129 | } | ||
130 | |||
131 | void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, | ||
132 | unsigned char *in, int inl) | ||
133 | { | ||
134 | int i,j; | ||
135 | unsigned int total=0; | ||
136 | |||
137 | *outl=0; | ||
138 | if (inl == 0) return; | ||
139 | if ((ctx->num+inl) < ctx->length) | ||
140 | { | ||
141 | memcpy(&(ctx->enc_data[ctx->num]),in,inl); | ||
142 | ctx->num+=inl; | ||
143 | return; | ||
144 | } | ||
145 | if (ctx->num != 0) | ||
146 | { | ||
147 | i=ctx->length-ctx->num; | ||
148 | memcpy(&(ctx->enc_data[ctx->num]),in,i); | ||
149 | in+=i; | ||
150 | inl-=i; | ||
151 | j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length); | ||
152 | ctx->num=0; | ||
153 | out+=j; | ||
154 | *(out++)='\n'; | ||
155 | *out='\0'; | ||
156 | total=j+1; | ||
157 | } | ||
158 | while (inl >= ctx->length) | ||
159 | { | ||
160 | j=EVP_EncodeBlock(out,in,ctx->length); | ||
161 | in+=ctx->length; | ||
162 | inl-=ctx->length; | ||
163 | out+=j; | ||
164 | *(out++)='\n'; | ||
165 | *out='\0'; | ||
166 | total+=j+1; | ||
167 | } | ||
168 | if (inl != 0) | ||
169 | memcpy(&(ctx->enc_data[0]),in,inl); | ||
170 | ctx->num=inl; | ||
171 | *outl=total; | ||
172 | } | ||
173 | |||
174 | void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl) | ||
175 | { | ||
176 | unsigned int ret=0; | ||
177 | |||
178 | if (ctx->num != 0) | ||
179 | { | ||
180 | ret=EVP_EncodeBlock(out,ctx->enc_data,ctx->num); | ||
181 | out[ret++]='\n'; | ||
182 | out[ret]='\0'; | ||
183 | ctx->num=0; | ||
184 | } | ||
185 | *outl=ret; | ||
186 | } | ||
187 | |||
188 | int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int dlen) | ||
189 | { | ||
190 | int i,ret=0; | ||
191 | unsigned long l; | ||
192 | |||
193 | for (i=dlen; i > 0; i-=3) | ||
194 | { | ||
195 | if (i >= 3) | ||
196 | { | ||
197 | l= (((unsigned long)f[0])<<16L)| | ||
198 | (((unsigned long)f[1])<< 8L)|f[2]; | ||
199 | *(t++)=conv_bin2ascii(l>>18L); | ||
200 | *(t++)=conv_bin2ascii(l>>12L); | ||
201 | *(t++)=conv_bin2ascii(l>> 6L); | ||
202 | *(t++)=conv_bin2ascii(l ); | ||
203 | } | ||
204 | else | ||
205 | { | ||
206 | l=((unsigned long)f[0])<<16L; | ||
207 | if (i == 2) l|=((unsigned long)f[1]<<8L); | ||
208 | |||
209 | *(t++)=conv_bin2ascii(l>>18L); | ||
210 | *(t++)=conv_bin2ascii(l>>12L); | ||
211 | *(t++)=(i == 1)?'=':conv_bin2ascii(l>> 6L); | ||
212 | *(t++)='='; | ||
213 | } | ||
214 | ret+=4; | ||
215 | f+=3; | ||
216 | } | ||
217 | |||
218 | *t='\0'; | ||
219 | return(ret); | ||
220 | } | ||
221 | |||
222 | void EVP_DecodeInit(EVP_ENCODE_CTX *ctx) | ||
223 | { | ||
224 | ctx->length=30; | ||
225 | ctx->num=0; | ||
226 | ctx->line_num=0; | ||
227 | ctx->expect_nl=0; | ||
228 | } | ||
229 | |||
230 | /* -1 for error | ||
231 | * 0 for last line | ||
232 | * 1 for full line | ||
233 | */ | ||
234 | int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, | ||
235 | unsigned char *in, int inl) | ||
236 | { | ||
237 | int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl; | ||
238 | unsigned char *d; | ||
239 | |||
240 | n=ctx->num; | ||
241 | d=ctx->enc_data; | ||
242 | ln=ctx->line_num; | ||
243 | exp_nl=ctx->expect_nl; | ||
244 | |||
245 | /* last line of input. */ | ||
246 | if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF))) | ||
247 | { rv=0; goto end; } | ||
248 | |||
249 | /* We parse the input data */ | ||
250 | for (i=0; i<inl; i++) | ||
251 | { | ||
252 | /* If the current line is > 80 characters, scream alot */ | ||
253 | if (ln >= 80) { rv= -1; goto end; } | ||
254 | |||
255 | /* Get char and put it into the buffer */ | ||
256 | tmp= *(in++); | ||
257 | v=conv_ascii2bin(tmp); | ||
258 | /* only save the good data :-) */ | ||
259 | if (!B64_NOT_BASE64(v)) | ||
260 | { | ||
261 | d[n++]=tmp; | ||
262 | ln++; | ||
263 | } | ||
264 | else if (v == B64_ERROR) | ||
265 | { | ||
266 | rv= -1; | ||
267 | goto end; | ||
268 | } | ||
269 | |||
270 | /* have we seen a '=' which is 'definitly' the last | ||
271 | * input line. seof will point to the character that | ||
272 | * holds it. and eof will hold how many characters to | ||
273 | * chop off. */ | ||
274 | if (tmp == '=') | ||
275 | { | ||
276 | if (seof == -1) seof=n; | ||
277 | eof++; | ||
278 | } | ||
279 | |||
280 | /* eoln */ | ||
281 | if (v == B64_EOLN) | ||
282 | { | ||
283 | ln=0; | ||
284 | if (exp_nl) | ||
285 | { | ||
286 | exp_nl=0; | ||
287 | continue; | ||
288 | } | ||
289 | } | ||
290 | exp_nl=0; | ||
291 | |||
292 | /* If we are at the end of input and it looks like a | ||
293 | * line, process it. */ | ||
294 | if (((i+1) == inl) && (((n&3) == 0) || eof)) | ||
295 | { | ||
296 | v=B64_EOF; | ||
297 | /* In case things were given us in really small | ||
298 | records (so two '=' were given in separate | ||
299 | updates), eof may contain the incorrect number | ||
300 | of ending bytes to skip, so let's redo the count */ | ||
301 | eof = 0; | ||
302 | if (d[n-1] == '=') eof++; | ||
303 | if (d[n-2] == '=') eof++; | ||
304 | /* There will never be more than two '=' */ | ||
305 | } | ||
306 | |||
307 | if ((v == B64_EOF) || (n >= 64)) | ||
308 | { | ||
309 | /* This is needed to work correctly on 64 byte input | ||
310 | * lines. We process the line and then need to | ||
311 | * accept the '\n' */ | ||
312 | if ((v != B64_EOF) && (n >= 64)) exp_nl=1; | ||
313 | tmp2=v; | ||
314 | if (n > 0) | ||
315 | { | ||
316 | v=EVP_DecodeBlock(out,d,n); | ||
317 | if (v < 0) { rv=0; goto end; } | ||
318 | n=0; | ||
319 | ret+=(v-eof); | ||
320 | } | ||
321 | else | ||
322 | { | ||
323 | eof=1; | ||
324 | v=0; | ||
325 | } | ||
326 | |||
327 | /* This is the case where we have had a short | ||
328 | * but valid input line */ | ||
329 | if ((v < ctx->length) && eof) | ||
330 | { | ||
331 | rv=0; | ||
332 | goto end; | ||
333 | } | ||
334 | else | ||
335 | ctx->length=v; | ||
336 | |||
337 | if (seof >= 0) { rv=0; goto end; } | ||
338 | out+=v; | ||
339 | } | ||
340 | } | ||
341 | rv=1; | ||
342 | end: | ||
343 | *outl=ret; | ||
344 | ctx->num=n; | ||
345 | ctx->line_num=ln; | ||
346 | ctx->expect_nl=exp_nl; | ||
347 | return(rv); | ||
348 | } | ||
349 | |||
350 | int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n) | ||
351 | { | ||
352 | int i,ret=0,a,b,c,d; | ||
353 | unsigned long l; | ||
354 | |||
355 | /* trim white space from the start of the line. */ | ||
356 | while ((conv_ascii2bin(*f) == B64_WS) && (n > 0)) | ||
357 | { | ||
358 | f++; | ||
359 | n--; | ||
360 | } | ||
361 | |||
362 | /* strip off stuff at the end of the line | ||
363 | * ascii2bin values B64_WS, B64_EOLN, B64_EOLN and B64_EOF */ | ||
364 | while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n-1])))) | ||
365 | n--; | ||
366 | |||
367 | if (n%4 != 0) return(-1); | ||
368 | |||
369 | for (i=0; i<n; i+=4) | ||
370 | { | ||
371 | a=conv_ascii2bin(*(f++)); | ||
372 | b=conv_ascii2bin(*(f++)); | ||
373 | c=conv_ascii2bin(*(f++)); | ||
374 | d=conv_ascii2bin(*(f++)); | ||
375 | if ( (a & 0x80) || (b & 0x80) || | ||
376 | (c & 0x80) || (d & 0x80)) | ||
377 | return(-1); | ||
378 | l=( (((unsigned long)a)<<18L)| | ||
379 | (((unsigned long)b)<<12L)| | ||
380 | (((unsigned long)c)<< 6L)| | ||
381 | (((unsigned long)d) )); | ||
382 | *(t++)=(unsigned char)(l>>16L)&0xff; | ||
383 | *(t++)=(unsigned char)(l>> 8L)&0xff; | ||
384 | *(t++)=(unsigned char)(l )&0xff; | ||
385 | ret+=3; | ||
386 | } | ||
387 | return(ret); | ||
388 | } | ||
389 | |||
390 | int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl) | ||
391 | { | ||
392 | int i; | ||
393 | |||
394 | *outl=0; | ||
395 | if (ctx->num != 0) | ||
396 | { | ||
397 | i=EVP_DecodeBlock(out,ctx->enc_data,ctx->num); | ||
398 | if (i < 0) return(-1); | ||
399 | ctx->num=0; | ||
400 | *outl=i; | ||
401 | return(1); | ||
402 | } | ||
403 | else | ||
404 | return(1); | ||
405 | } | ||
406 | |||
407 | #ifdef undef | ||
408 | int EVP_DecodeValid(unsigned char *buf, int len) | ||
409 | { | ||
410 | int i,num=0,bad=0; | ||
411 | |||
412 | if (len == 0) return(-1); | ||
413 | while (conv_ascii2bin(*buf) == B64_WS) | ||
414 | { | ||
415 | buf++; | ||
416 | len--; | ||
417 | if (len == 0) return(-1); | ||
418 | } | ||
419 | |||
420 | for (i=len; i >= 4; i-=4) | ||
421 | { | ||
422 | if ( (conv_ascii2bin(buf[0]) >= 0x40) || | ||
423 | (conv_ascii2bin(buf[1]) >= 0x40) || | ||
424 | (conv_ascii2bin(buf[2]) >= 0x40) || | ||
425 | (conv_ascii2bin(buf[3]) >= 0x40)) | ||
426 | return(-1); | ||
427 | buf+=4; | ||
428 | num+=1+(buf[2] != '=')+(buf[3] != '='); | ||
429 | } | ||
430 | if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN)) | ||
431 | return(num); | ||
432 | if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) && | ||
433 | (conv_ascii2bin(buf[0]) == B64_EOLN)) | ||
434 | return(num); | ||
435 | return(1); | ||
436 | } | ||
437 | #endif | ||
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h deleted file mode 100644 index fd43127092..0000000000 --- a/src/lib/libcrypto/evp/evp.h +++ /dev/null | |||
@@ -1,851 +0,0 @@ | |||
1 | /* crypto/evp/evp.h */ | ||
2 | /* Copyright (C) 1995-1998 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_ENVELOPE_H | ||
60 | #define HEADER_ENVELOPE_H | ||
61 | |||
62 | #ifdef OPENSSL_ALGORITHM_DEFINES | ||
63 | # include <openssl/opensslconf.h> | ||
64 | #else | ||
65 | # define OPENSSL_ALGORITHM_DEFINES | ||
66 | # include <openssl/opensslconf.h> | ||
67 | # undef OPENSSL_ALGORITHM_DEFINES | ||
68 | #endif | ||
69 | |||
70 | #ifndef NO_BIO | ||
71 | #include <openssl/bio.h> | ||
72 | #endif | ||
73 | #ifndef NO_MD2 | ||
74 | #include <openssl/md2.h> | ||
75 | #endif | ||
76 | #ifndef NO_MD4 | ||
77 | #include <openssl/md4.h> | ||
78 | #endif | ||
79 | #ifndef NO_MD5 | ||
80 | #include <openssl/md5.h> | ||
81 | #endif | ||
82 | #ifndef NO_SHA | ||
83 | #include <openssl/sha.h> | ||
84 | #endif | ||
85 | #ifndef NO_RIPEMD | ||
86 | #include <openssl/ripemd.h> | ||
87 | #endif | ||
88 | #ifndef NO_DES | ||
89 | #include <openssl/des.h> | ||
90 | #endif | ||
91 | #ifndef NO_RC4 | ||
92 | #include <openssl/rc4.h> | ||
93 | #endif | ||
94 | #ifndef NO_RC2 | ||
95 | #include <openssl/rc2.h> | ||
96 | #endif | ||
97 | #ifndef NO_RC5 | ||
98 | #include <openssl/rc5.h> | ||
99 | #endif | ||
100 | #ifndef NO_BF | ||
101 | #include <openssl/blowfish.h> | ||
102 | #endif | ||
103 | #ifndef NO_CAST | ||
104 | #include <openssl/cast.h> | ||
105 | #endif | ||
106 | #ifndef NO_IDEA | ||
107 | #include <openssl/idea.h> | ||
108 | #endif | ||
109 | #ifndef NO_MDC2 | ||
110 | #include <openssl/mdc2.h> | ||
111 | #endif | ||
112 | |||
113 | #define EVP_RC2_KEY_SIZE 16 | ||
114 | #define EVP_RC4_KEY_SIZE 16 | ||
115 | #define EVP_BLOWFISH_KEY_SIZE 16 | ||
116 | #define EVP_CAST5_KEY_SIZE 16 | ||
117 | #define EVP_RC5_32_12_16_KEY_SIZE 16 | ||
118 | #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */ | ||
119 | #define EVP_MAX_KEY_LENGTH 24 | ||
120 | #define EVP_MAX_IV_LENGTH 8 | ||
121 | |||
122 | #define PKCS5_SALT_LEN 8 | ||
123 | /* Default PKCS#5 iteration count */ | ||
124 | #define PKCS5_DEFAULT_ITER 2048 | ||
125 | |||
126 | #ifndef NO_RSA | ||
127 | #include <openssl/rsa.h> | ||
128 | #endif | ||
129 | |||
130 | #ifndef NO_DSA | ||
131 | #include <openssl/dsa.h> | ||
132 | #endif | ||
133 | |||
134 | #ifndef NO_DH | ||
135 | #include <openssl/dh.h> | ||
136 | #endif | ||
137 | |||
138 | #include <openssl/objects.h> | ||
139 | |||
140 | #define EVP_PK_RSA 0x0001 | ||
141 | #define EVP_PK_DSA 0x0002 | ||
142 | #define EVP_PK_DH 0x0004 | ||
143 | #define EVP_PKT_SIGN 0x0010 | ||
144 | #define EVP_PKT_ENC 0x0020 | ||
145 | #define EVP_PKT_EXCH 0x0040 | ||
146 | #define EVP_PKS_RSA 0x0100 | ||
147 | #define EVP_PKS_DSA 0x0200 | ||
148 | #define EVP_PKT_EXP 0x1000 /* <= 512 bit key */ | ||
149 | |||
150 | #define EVP_PKEY_NONE NID_undef | ||
151 | #define EVP_PKEY_RSA NID_rsaEncryption | ||
152 | #define EVP_PKEY_RSA2 NID_rsa | ||
153 | #define EVP_PKEY_DSA NID_dsa | ||
154 | #define EVP_PKEY_DSA1 NID_dsa_2 | ||
155 | #define EVP_PKEY_DSA2 NID_dsaWithSHA | ||
156 | #define EVP_PKEY_DSA3 NID_dsaWithSHA1 | ||
157 | #define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 | ||
158 | #define EVP_PKEY_DH NID_dhKeyAgreement | ||
159 | |||
160 | #ifdef __cplusplus | ||
161 | extern "C" { | ||
162 | #endif | ||
163 | |||
164 | /* Type needs to be a bit field | ||
165 | * Sub-type needs to be for variations on the method, as in, can it do | ||
166 | * arbitrary encryption.... */ | ||
167 | typedef struct evp_pkey_st | ||
168 | { | ||
169 | int type; | ||
170 | int save_type; | ||
171 | int references; | ||
172 | union { | ||
173 | char *ptr; | ||
174 | #ifndef NO_RSA | ||
175 | struct rsa_st *rsa; /* RSA */ | ||
176 | #endif | ||
177 | #ifndef NO_DSA | ||
178 | struct dsa_st *dsa; /* DSA */ | ||
179 | #endif | ||
180 | #ifndef NO_DH | ||
181 | struct dh_st *dh; /* DH */ | ||
182 | #endif | ||
183 | } pkey; | ||
184 | int save_parameters; | ||
185 | STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ | ||
186 | } EVP_PKEY; | ||
187 | |||
188 | #define EVP_PKEY_MO_SIGN 0x0001 | ||
189 | #define EVP_PKEY_MO_VERIFY 0x0002 | ||
190 | #define EVP_PKEY_MO_ENCRYPT 0x0004 | ||
191 | #define EVP_PKEY_MO_DECRYPT 0x0008 | ||
192 | |||
193 | #if 0 | ||
194 | /* This structure is required to tie the message digest and signing together. | ||
195 | * The lookup can be done by md/pkey_method, oid, oid/pkey_method, or | ||
196 | * oid, md and pkey. | ||
197 | * This is required because for various smart-card perform the digest and | ||
198 | * signing/verification on-board. To handle this case, the specific | ||
199 | * EVP_MD and EVP_PKEY_METHODs need to be closely associated. | ||
200 | * When a PKEY is created, it will have a EVP_PKEY_METHOD associated with it. | ||
201 | * This can either be software or a token to provide the required low level | ||
202 | * routines. | ||
203 | */ | ||
204 | typedef struct evp_pkey_md_st | ||
205 | { | ||
206 | int oid; | ||
207 | EVP_MD *md; | ||
208 | EVP_PKEY_METHOD *pkey; | ||
209 | } EVP_PKEY_MD; | ||
210 | |||
211 | #define EVP_rsa_md2() \ | ||
212 | EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\ | ||
213 | EVP_rsa_pkcs1(),EVP_md2()) | ||
214 | #define EVP_rsa_md5() \ | ||
215 | EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\ | ||
216 | EVP_rsa_pkcs1(),EVP_md5()) | ||
217 | #define EVP_rsa_sha0() \ | ||
218 | EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\ | ||
219 | EVP_rsa_pkcs1(),EVP_sha()) | ||
220 | #define EVP_rsa_sha1() \ | ||
221 | EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\ | ||
222 | EVP_rsa_pkcs1(),EVP_sha1()) | ||
223 | #define EVP_rsa_ripemd160() \ | ||
224 | EVP_PKEY_MD_add(NID_ripemd160WithRSA,\ | ||
225 | EVP_rsa_pkcs1(),EVP_ripemd160()) | ||
226 | #define EVP_rsa_mdc2() \ | ||
227 | EVP_PKEY_MD_add(NID_mdc2WithRSA,\ | ||
228 | EVP_rsa_octet_string(),EVP_mdc2()) | ||
229 | #define EVP_dsa_sha() \ | ||
230 | EVP_PKEY_MD_add(NID_dsaWithSHA,\ | ||
231 | EVP_dsa(),EVP_mdc2()) | ||
232 | #define EVP_dsa_sha1() \ | ||
233 | EVP_PKEY_MD_add(NID_dsaWithSHA1,\ | ||
234 | EVP_dsa(),EVP_sha1()) | ||
235 | |||
236 | typedef struct evp_pkey_method_st | ||
237 | { | ||
238 | char *name; | ||
239 | int flags; | ||
240 | int type; /* RSA, DSA, an SSLeay specific constant */ | ||
241 | int oid; /* For the pub-key type */ | ||
242 | int encrypt_oid; /* pub/priv key encryption */ | ||
243 | |||
244 | int (*sign)(); | ||
245 | int (*verify)(); | ||
246 | struct { | ||
247 | int (*set)(); /* get and/or set the underlying type */ | ||
248 | int (*get)(); | ||
249 | int (*encrypt)(); | ||
250 | int (*decrypt)(); | ||
251 | int (*i2d)(); | ||
252 | int (*d2i)(); | ||
253 | int (*dup)(); | ||
254 | } pub,priv; | ||
255 | int (*set_asn1_parameters)(); | ||
256 | int (*get_asn1_parameters)(); | ||
257 | } EVP_PKEY_METHOD; | ||
258 | #endif | ||
259 | |||
260 | #ifndef EVP_MD | ||
261 | typedef struct env_md_st | ||
262 | { | ||
263 | int type; | ||
264 | int pkey_type; | ||
265 | int md_size; | ||
266 | void (*init)(); | ||
267 | void (*update)(); | ||
268 | void (*final)(); | ||
269 | |||
270 | int (*sign)(); | ||
271 | int (*verify)(); | ||
272 | int required_pkey_type[5]; /*EVP_PKEY_xxx */ | ||
273 | int block_size; | ||
274 | int ctx_size; /* how big does the ctx need to be */ | ||
275 | } EVP_MD; | ||
276 | |||
277 | |||
278 | |||
279 | #define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0} | ||
280 | |||
281 | #ifndef NO_DSA | ||
282 | #define EVP_PKEY_DSA_method DSA_sign,DSA_verify, \ | ||
283 | {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \ | ||
284 | EVP_PKEY_DSA4,0} | ||
285 | #else | ||
286 | #define EVP_PKEY_DSA_method EVP_PKEY_NULL_method | ||
287 | #endif | ||
288 | |||
289 | #ifndef NO_RSA | ||
290 | #define EVP_PKEY_RSA_method RSA_sign,RSA_verify, \ | ||
291 | {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} | ||
292 | #define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \ | ||
293 | RSA_sign_ASN1_OCTET_STRING, \ | ||
294 | RSA_verify_ASN1_OCTET_STRING, \ | ||
295 | {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} | ||
296 | #else | ||
297 | #define EVP_PKEY_RSA_method EVP_PKEY_NULL_method | ||
298 | #define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method | ||
299 | #endif | ||
300 | |||
301 | #endif /* !EVP_MD */ | ||
302 | |||
303 | typedef struct env_md_ctx_st | ||
304 | { | ||
305 | const EVP_MD *digest; | ||
306 | union { | ||
307 | unsigned char base[4]; | ||
308 | #ifndef NO_MD2 | ||
309 | MD2_CTX md2; | ||
310 | #endif | ||
311 | #ifndef NO_MD5 | ||
312 | MD5_CTX md5; | ||
313 | #endif | ||
314 | #ifndef NO_MD4 | ||
315 | MD4_CTX md4; | ||
316 | #endif | ||
317 | #ifndef NO_RIPEMD | ||
318 | RIPEMD160_CTX ripemd160; | ||
319 | #endif | ||
320 | #ifndef NO_SHA | ||
321 | SHA_CTX sha; | ||
322 | #endif | ||
323 | #ifndef NO_MDC2 | ||
324 | MDC2_CTX mdc2; | ||
325 | #endif | ||
326 | } md; | ||
327 | } EVP_MD_CTX; | ||
328 | |||
329 | typedef struct evp_cipher_st EVP_CIPHER; | ||
330 | typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX; | ||
331 | |||
332 | struct evp_cipher_st | ||
333 | { | ||
334 | int nid; | ||
335 | int block_size; | ||
336 | int key_len; /* Default value for variable length ciphers */ | ||
337 | int iv_len; | ||
338 | unsigned long flags; /* Various flags */ | ||
339 | int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
340 | const unsigned char *iv, int enc); /* init key */ | ||
341 | int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
342 | const unsigned char *in, unsigned int inl);/* encrypt/decrypt data */ | ||
343 | int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */ | ||
344 | int ctx_size; /* how big the ctx needs to be */ | ||
345 | int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */ | ||
346 | int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */ | ||
347 | int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */ | ||
348 | void *app_data; /* Application data */ | ||
349 | }; | ||
350 | |||
351 | /* Values for cipher flags */ | ||
352 | |||
353 | /* Modes for ciphers */ | ||
354 | |||
355 | #define EVP_CIPH_STREAM_CIPHER 0x0 | ||
356 | #define EVP_CIPH_ECB_MODE 0x1 | ||
357 | #define EVP_CIPH_CBC_MODE 0x2 | ||
358 | #define EVP_CIPH_CFB_MODE 0x3 | ||
359 | #define EVP_CIPH_OFB_MODE 0x4 | ||
360 | #define EVP_CIPH_MODE 0x7 | ||
361 | /* Set if variable length cipher */ | ||
362 | #define EVP_CIPH_VARIABLE_LENGTH 0x8 | ||
363 | /* Set if the iv handling should be done by the cipher itself */ | ||
364 | #define EVP_CIPH_CUSTOM_IV 0x10 | ||
365 | /* Set if the cipher's init() function should be called if key is NULL */ | ||
366 | #define EVP_CIPH_ALWAYS_CALL_INIT 0x20 | ||
367 | /* Call ctrl() to init cipher parameters */ | ||
368 | #define EVP_CIPH_CTRL_INIT 0x40 | ||
369 | /* Don't use standard key length function */ | ||
370 | #define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80 | ||
371 | |||
372 | /* ctrl() values */ | ||
373 | |||
374 | #define EVP_CTRL_INIT 0x0 | ||
375 | #define EVP_CTRL_SET_KEY_LENGTH 0x1 | ||
376 | #define EVP_CTRL_GET_RC2_KEY_BITS 0x2 | ||
377 | #define EVP_CTRL_SET_RC2_KEY_BITS 0x3 | ||
378 | #define EVP_CTRL_GET_RC5_ROUNDS 0x4 | ||
379 | #define EVP_CTRL_SET_RC5_ROUNDS 0x5 | ||
380 | |||
381 | typedef struct evp_cipher_info_st | ||
382 | { | ||
383 | const EVP_CIPHER *cipher; | ||
384 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
385 | } EVP_CIPHER_INFO; | ||
386 | |||
387 | struct evp_cipher_ctx_st | ||
388 | { | ||
389 | const EVP_CIPHER *cipher; | ||
390 | int encrypt; /* encrypt or decrypt */ | ||
391 | int buf_len; /* number we have left */ | ||
392 | |||
393 | unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */ | ||
394 | unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */ | ||
395 | unsigned char buf[EVP_MAX_IV_LENGTH]; /* saved partial block */ | ||
396 | int num; /* used by cfb/ofb mode */ | ||
397 | |||
398 | void *app_data; /* application stuff */ | ||
399 | int key_len; /* May change for variable length cipher */ | ||
400 | union { | ||
401 | #ifndef NO_RC4 | ||
402 | struct | ||
403 | { | ||
404 | unsigned char key[EVP_RC4_KEY_SIZE]; | ||
405 | RC4_KEY ks; /* working key */ | ||
406 | } rc4; | ||
407 | #endif | ||
408 | #ifndef NO_DES | ||
409 | des_key_schedule des_ks;/* key schedule */ | ||
410 | struct | ||
411 | { | ||
412 | des_key_schedule ks;/* key schedule */ | ||
413 | des_cblock inw; | ||
414 | des_cblock outw; | ||
415 | } desx_cbc; | ||
416 | struct | ||
417 | { | ||
418 | des_key_schedule ks1;/* key schedule */ | ||
419 | des_key_schedule ks2;/* key schedule (for ede) */ | ||
420 | des_key_schedule ks3;/* key schedule (for ede3) */ | ||
421 | } des_ede; | ||
422 | #endif | ||
423 | #ifndef NO_IDEA | ||
424 | IDEA_KEY_SCHEDULE idea_ks;/* key schedule */ | ||
425 | #endif | ||
426 | #ifndef NO_RC2 | ||
427 | struct { | ||
428 | int key_bits; /* effective key bits */ | ||
429 | RC2_KEY ks;/* key schedule */ | ||
430 | } rc2; | ||
431 | #endif | ||
432 | #ifndef NO_RC5 | ||
433 | struct { | ||
434 | int rounds; /* number of rounds */ | ||
435 | RC5_32_KEY ks;/* key schedule */ | ||
436 | } rc5; | ||
437 | #endif | ||
438 | #ifndef NO_BF | ||
439 | BF_KEY bf_ks;/* key schedule */ | ||
440 | #endif | ||
441 | #ifndef NO_CAST | ||
442 | CAST_KEY cast_ks;/* key schedule */ | ||
443 | #endif | ||
444 | } c; | ||
445 | }; | ||
446 | |||
447 | typedef struct evp_Encode_Ctx_st | ||
448 | { | ||
449 | int num; /* number saved in a partial encode/decode */ | ||
450 | int length; /* The length is either the output line length | ||
451 | * (in input bytes) or the shortest input line | ||
452 | * length that is ok. Once decoding begins, | ||
453 | * the length is adjusted up each time a longer | ||
454 | * line is decoded */ | ||
455 | unsigned char enc_data[80]; /* data to encode */ | ||
456 | int line_num; /* number read on current line */ | ||
457 | int expect_nl; | ||
458 | } EVP_ENCODE_CTX; | ||
459 | |||
460 | /* Password based encryption function */ | ||
461 | typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | ||
462 | ASN1_TYPE *param, EVP_CIPHER *cipher, | ||
463 | EVP_MD *md, int en_de); | ||
464 | |||
465 | #ifndef NO_RSA | ||
466 | #define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ | ||
467 | (char *)(rsa)) | ||
468 | #endif | ||
469 | |||
470 | #ifndef NO_DSA | ||
471 | #define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\ | ||
472 | (char *)(dsa)) | ||
473 | #endif | ||
474 | |||
475 | #ifndef NO_DH | ||
476 | #define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\ | ||
477 | (char *)(dh)) | ||
478 | #endif | ||
479 | |||
480 | /* Add some extra combinations */ | ||
481 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) | ||
482 | #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) | ||
483 | #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) | ||
484 | #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) | ||
485 | |||
486 | #define EVP_MD_type(e) ((e)->type) | ||
487 | #define EVP_MD_pkey_type(e) ((e)->pkey_type) | ||
488 | #define EVP_MD_size(e) ((e)->md_size) | ||
489 | #define EVP_MD_block_size(e) ((e)->block_size) | ||
490 | |||
491 | #define EVP_MD_CTX_md(e) ((e)->digest) | ||
492 | #define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest) | ||
493 | #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest) | ||
494 | #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest) | ||
495 | |||
496 | #define EVP_CIPHER_nid(e) ((e)->nid) | ||
497 | #define EVP_CIPHER_block_size(e) ((e)->block_size) | ||
498 | #define EVP_CIPHER_key_length(e) ((e)->key_len) | ||
499 | #define EVP_CIPHER_iv_length(e) ((e)->iv_len) | ||
500 | #define EVP_CIPHER_flags(e) ((e)->flags) | ||
501 | #define EVP_CIPHER_mode(e) ((e)->flags) & EVP_CIPH_MODE) | ||
502 | |||
503 | #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher) | ||
504 | #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid) | ||
505 | #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size) | ||
506 | #define EVP_CIPHER_CTX_key_length(e) ((e)->key_len) | ||
507 | #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len) | ||
508 | #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | ||
509 | #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) | ||
510 | #define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) | ||
511 | #define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags) | ||
512 | #define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE) | ||
513 | |||
514 | #define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80) | ||
515 | #define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80) | ||
516 | |||
517 | #define EVP_SignInit(a,b) EVP_DigestInit(a,b) | ||
518 | #define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c) | ||
519 | #define EVP_VerifyInit(a,b) EVP_DigestInit(a,b) | ||
520 | #define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c) | ||
521 | #define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e) | ||
522 | #define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e) | ||
523 | |||
524 | #ifdef CONST_STRICT | ||
525 | void BIO_set_md(BIO *,const EVP_MD *md); | ||
526 | #else | ||
527 | # define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md) | ||
528 | #endif | ||
529 | #define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp) | ||
530 | #define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp) | ||
531 | #define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL) | ||
532 | #define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp) | ||
533 | |||
534 | #define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l)) | ||
535 | |||
536 | #define EVP_add_cipher_alias(n,alias) \ | ||
537 | OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n)) | ||
538 | #define EVP_add_digest_alias(n,alias) \ | ||
539 | OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n)) | ||
540 | #define EVP_delete_cipher_alias(alias) \ | ||
541 | OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS); | ||
542 | #define EVP_delete_digest_alias(alias) \ | ||
543 | OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS); | ||
544 | |||
545 | |||
546 | int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in); | ||
547 | void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); | ||
548 | void EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d, | ||
549 | unsigned int cnt); | ||
550 | void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); | ||
551 | |||
552 | int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify); | ||
553 | void EVP_set_pw_prompt(char *prompt); | ||
554 | char * EVP_get_pw_prompt(void); | ||
555 | |||
556 | int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, | ||
557 | const unsigned char *salt, const unsigned char *data, int datal, | ||
558 | int count, unsigned char *key, unsigned char *iv); | ||
559 | |||
560 | int EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, | ||
561 | unsigned char *key, unsigned char *iv); | ||
562 | int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
563 | int *outl, unsigned char *in, int inl); | ||
564 | int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); | ||
565 | |||
566 | int EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, | ||
567 | unsigned char *key, unsigned char *iv); | ||
568 | int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
569 | int *outl, unsigned char *in, int inl); | ||
570 | int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); | ||
571 | |||
572 | int EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, | ||
573 | unsigned char *key,unsigned char *iv,int enc); | ||
574 | int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
575 | int *outl, unsigned char *in, int inl); | ||
576 | int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); | ||
577 | |||
578 | int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s, | ||
579 | EVP_PKEY *pkey); | ||
580 | |||
581 | int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf, | ||
582 | unsigned int siglen,EVP_PKEY *pkey); | ||
583 | |||
584 | int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek, | ||
585 | int ekl,unsigned char *iv,EVP_PKEY *priv); | ||
586 | int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); | ||
587 | |||
588 | int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek, | ||
589 | int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk); | ||
590 | void EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl); | ||
591 | |||
592 | void EVP_EncodeInit(EVP_ENCODE_CTX *ctx); | ||
593 | void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out, | ||
594 | int *outl,unsigned char *in,int inl); | ||
595 | void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl); | ||
596 | int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n); | ||
597 | |||
598 | void EVP_DecodeInit(EVP_ENCODE_CTX *ctx); | ||
599 | int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl, | ||
600 | unsigned char *in, int inl); | ||
601 | int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned | ||
602 | char *out, int *outl); | ||
603 | int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n); | ||
604 | |||
605 | void ERR_load_EVP_strings(void ); | ||
606 | |||
607 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a); | ||
608 | int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); | ||
609 | int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen); | ||
610 | int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr); | ||
611 | |||
612 | #ifndef NO_BIO | ||
613 | BIO_METHOD *BIO_f_md(void); | ||
614 | BIO_METHOD *BIO_f_base64(void); | ||
615 | BIO_METHOD *BIO_f_cipher(void); | ||
616 | BIO_METHOD *BIO_f_reliable(void); | ||
617 | void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,unsigned char *k, | ||
618 | unsigned char *i, int enc); | ||
619 | #endif | ||
620 | |||
621 | EVP_MD *EVP_md_null(void); | ||
622 | #ifndef NO_MD2 | ||
623 | EVP_MD *EVP_md2(void); | ||
624 | #endif | ||
625 | #ifndef NO_MD4 | ||
626 | EVP_MD *EVP_md4(void); | ||
627 | #endif | ||
628 | #ifndef NO_MD5 | ||
629 | EVP_MD *EVP_md5(void); | ||
630 | #endif | ||
631 | #ifndef NO_SHA | ||
632 | EVP_MD *EVP_sha(void); | ||
633 | EVP_MD *EVP_sha1(void); | ||
634 | EVP_MD *EVP_dss(void); | ||
635 | EVP_MD *EVP_dss1(void); | ||
636 | #endif | ||
637 | #ifndef NO_MDC2 | ||
638 | EVP_MD *EVP_mdc2(void); | ||
639 | #endif | ||
640 | #ifndef NO_RIPEMD | ||
641 | EVP_MD *EVP_ripemd160(void); | ||
642 | #endif | ||
643 | EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ | ||
644 | #ifndef NO_DES | ||
645 | EVP_CIPHER *EVP_des_ecb(void); | ||
646 | EVP_CIPHER *EVP_des_ede(void); | ||
647 | EVP_CIPHER *EVP_des_ede3(void); | ||
648 | EVP_CIPHER *EVP_des_cfb(void); | ||
649 | EVP_CIPHER *EVP_des_ede_cfb(void); | ||
650 | EVP_CIPHER *EVP_des_ede3_cfb(void); | ||
651 | EVP_CIPHER *EVP_des_ofb(void); | ||
652 | EVP_CIPHER *EVP_des_ede_ofb(void); | ||
653 | EVP_CIPHER *EVP_des_ede3_ofb(void); | ||
654 | EVP_CIPHER *EVP_des_cbc(void); | ||
655 | EVP_CIPHER *EVP_des_ede_cbc(void); | ||
656 | EVP_CIPHER *EVP_des_ede3_cbc(void); | ||
657 | EVP_CIPHER *EVP_desx_cbc(void); | ||
658 | #endif | ||
659 | #ifndef NO_RC4 | ||
660 | EVP_CIPHER *EVP_rc4(void); | ||
661 | EVP_CIPHER *EVP_rc4_40(void); | ||
662 | #endif | ||
663 | #ifndef NO_IDEA | ||
664 | EVP_CIPHER *EVP_idea_ecb(void); | ||
665 | EVP_CIPHER *EVP_idea_cfb(void); | ||
666 | EVP_CIPHER *EVP_idea_ofb(void); | ||
667 | EVP_CIPHER *EVP_idea_cbc(void); | ||
668 | #endif | ||
669 | #ifndef NO_RC2 | ||
670 | EVP_CIPHER *EVP_rc2_ecb(void); | ||
671 | EVP_CIPHER *EVP_rc2_cbc(void); | ||
672 | EVP_CIPHER *EVP_rc2_40_cbc(void); | ||
673 | EVP_CIPHER *EVP_rc2_64_cbc(void); | ||
674 | EVP_CIPHER *EVP_rc2_cfb(void); | ||
675 | EVP_CIPHER *EVP_rc2_ofb(void); | ||
676 | #endif | ||
677 | #ifndef NO_BF | ||
678 | EVP_CIPHER *EVP_bf_ecb(void); | ||
679 | EVP_CIPHER *EVP_bf_cbc(void); | ||
680 | EVP_CIPHER *EVP_bf_cfb(void); | ||
681 | EVP_CIPHER *EVP_bf_ofb(void); | ||
682 | #endif | ||
683 | #ifndef NO_CAST | ||
684 | EVP_CIPHER *EVP_cast5_ecb(void); | ||
685 | EVP_CIPHER *EVP_cast5_cbc(void); | ||
686 | EVP_CIPHER *EVP_cast5_cfb(void); | ||
687 | EVP_CIPHER *EVP_cast5_ofb(void); | ||
688 | #endif | ||
689 | #ifndef NO_RC5 | ||
690 | EVP_CIPHER *EVP_rc5_32_12_16_cbc(void); | ||
691 | EVP_CIPHER *EVP_rc5_32_12_16_ecb(void); | ||
692 | EVP_CIPHER *EVP_rc5_32_12_16_cfb(void); | ||
693 | EVP_CIPHER *EVP_rc5_32_12_16_ofb(void); | ||
694 | #endif | ||
695 | void OpenSSL_add_all_algorithms(void); | ||
696 | void OpenSSL_add_all_ciphers(void); | ||
697 | void OpenSSL_add_all_digests(void); | ||
698 | #define SSLeay_add_all_algorithms() OpenSSL_add_all_algorithms() | ||
699 | #define SSLeay_add_all_ciphers() OpenSSL_add_all_ciphers() | ||
700 | #define SSLeay_add_all_digests() OpenSSL_add_all_digests() | ||
701 | |||
702 | int EVP_add_cipher(EVP_CIPHER *cipher); | ||
703 | int EVP_add_digest(EVP_MD *digest); | ||
704 | |||
705 | const EVP_CIPHER *EVP_get_cipherbyname(const char *name); | ||
706 | const EVP_MD *EVP_get_digestbyname(const char *name); | ||
707 | void EVP_cleanup(void); | ||
708 | |||
709 | int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key, | ||
710 | int enc_key_len,EVP_PKEY *private_key); | ||
711 | int EVP_PKEY_encrypt(unsigned char *enc_key, | ||
712 | unsigned char *key,int key_len,EVP_PKEY *pub_key); | ||
713 | int EVP_PKEY_type(int type); | ||
714 | int EVP_PKEY_bits(EVP_PKEY *pkey); | ||
715 | int EVP_PKEY_size(EVP_PKEY *pkey); | ||
716 | int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key); | ||
717 | #ifndef NO_RSA | ||
718 | int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,RSA *key); | ||
719 | RSA * EVP_PKEY_get1_RSA(EVP_PKEY *pkey); | ||
720 | #endif | ||
721 | #ifndef NO_DSA | ||
722 | int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,DSA *key); | ||
723 | DSA * EVP_PKEY_get1_DSA(EVP_PKEY *pkey); | ||
724 | #endif | ||
725 | #ifndef NO_DH | ||
726 | int EVP_PKEY_set1_DH(EVP_PKEY *pkey,DH *key); | ||
727 | DH * EVP_PKEY_get1_DH(EVP_PKEY *pkey); | ||
728 | #endif | ||
729 | EVP_PKEY * EVP_PKEY_new(void); | ||
730 | void EVP_PKEY_free(EVP_PKEY *pkey); | ||
731 | EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp, | ||
732 | long length); | ||
733 | int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp); | ||
734 | |||
735 | EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp, | ||
736 | long length); | ||
737 | EVP_PKEY * d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp, | ||
738 | long length); | ||
739 | int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp); | ||
740 | |||
741 | int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from); | ||
742 | int EVP_PKEY_missing_parameters(EVP_PKEY *pkey); | ||
743 | int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode); | ||
744 | int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b); | ||
745 | |||
746 | int EVP_CIPHER_type(const EVP_CIPHER *ctx); | ||
747 | |||
748 | /* calls methods */ | ||
749 | int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
750 | int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
751 | |||
752 | /* These are used by EVP_CIPHER methods */ | ||
753 | int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); | ||
754 | int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); | ||
755 | |||
756 | /* PKCS5 password based encryption */ | ||
757 | int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | ||
758 | ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md, | ||
759 | int en_de); | ||
760 | int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, | ||
761 | unsigned char *salt, int saltlen, int iter, | ||
762 | int keylen, unsigned char *out); | ||
763 | int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | ||
764 | ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md, | ||
765 | int en_de); | ||
766 | |||
767 | void PKCS5_PBE_add(void); | ||
768 | |||
769 | int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen, | ||
770 | ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de); | ||
771 | int EVP_PBE_alg_add(int nid, EVP_CIPHER *cipher, EVP_MD *md, | ||
772 | EVP_PBE_KEYGEN *keygen); | ||
773 | void EVP_PBE_cleanup(void); | ||
774 | |||
775 | /* BEGIN ERROR CODES */ | ||
776 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
777 | * made after this point may be overwritten when the script is next run. | ||
778 | */ | ||
779 | |||
780 | /* Error codes for the EVP functions. */ | ||
781 | |||
782 | /* Function codes. */ | ||
783 | #define EVP_F_D2I_PKEY 100 | ||
784 | #define EVP_F_EVP_CIPHERINIT 123 | ||
785 | #define EVP_F_EVP_CIPHER_CTX_CTRL 124 | ||
786 | #define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122 | ||
787 | #define EVP_F_EVP_DECRYPTFINAL 101 | ||
788 | #define EVP_F_EVP_MD_CTX_COPY 110 | ||
789 | #define EVP_F_EVP_OPENINIT 102 | ||
790 | #define EVP_F_EVP_PBE_ALG_ADD 115 | ||
791 | #define EVP_F_EVP_PBE_CIPHERINIT 116 | ||
792 | #define EVP_F_EVP_PKCS82PKEY 111 | ||
793 | #define EVP_F_EVP_PKCS8_SET_BROKEN 112 | ||
794 | #define EVP_F_EVP_PKEY2PKCS8 113 | ||
795 | #define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 | ||
796 | #define EVP_F_EVP_PKEY_DECRYPT 104 | ||
797 | #define EVP_F_EVP_PKEY_ENCRYPT 105 | ||
798 | #define EVP_F_EVP_PKEY_GET1_DH 119 | ||
799 | #define EVP_F_EVP_PKEY_GET1_DSA 120 | ||
800 | #define EVP_F_EVP_PKEY_GET1_RSA 121 | ||
801 | #define EVP_F_EVP_PKEY_NEW 106 | ||
802 | #define EVP_F_EVP_SIGNFINAL 107 | ||
803 | #define EVP_F_EVP_VERIFYFINAL 108 | ||
804 | #define EVP_F_PKCS5_PBE_KEYIVGEN 117 | ||
805 | #define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118 | ||
806 | #define EVP_F_RC2_MAGIC_TO_METH 109 | ||
807 | #define EVP_F_RC5_CTRL 125 | ||
808 | |||
809 | /* Reason codes. */ | ||
810 | #define EVP_R_BAD_DECRYPT 100 | ||
811 | #define EVP_R_BN_DECODE_ERROR 112 | ||
812 | #define EVP_R_BN_PUBKEY_ERROR 113 | ||
813 | #define EVP_R_CIPHER_PARAMETER_ERROR 122 | ||
814 | #define EVP_R_CTRL_NOT_IMPLEMENTED 132 | ||
815 | #define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133 | ||
816 | #define EVP_R_DECODE_ERROR 114 | ||
817 | #define EVP_R_DIFFERENT_KEY_TYPES 101 | ||
818 | #define EVP_R_ENCODE_ERROR 115 | ||
819 | #define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119 | ||
820 | #define EVP_R_EXPECTING_AN_RSA_KEY 127 | ||
821 | #define EVP_R_EXPECTING_A_DH_KEY 128 | ||
822 | #define EVP_R_EXPECTING_A_DSA_KEY 129 | ||
823 | #define EVP_R_INITIALIZATION_ERROR 134 | ||
824 | #define EVP_R_INPUT_NOT_INITIALIZED 111 | ||
825 | #define EVP_R_INVALID_KEY_LENGTH 130 | ||
826 | #define EVP_R_IV_TOO_LARGE 102 | ||
827 | #define EVP_R_KEYGEN_FAILURE 120 | ||
828 | #define EVP_R_MISSING_PARAMETERS 103 | ||
829 | #define EVP_R_NO_CIPHER_SET 131 | ||
830 | #define EVP_R_NO_DSA_PARAMETERS 116 | ||
831 | #define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104 | ||
832 | #define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105 | ||
833 | #define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117 | ||
834 | #define EVP_R_PUBLIC_KEY_NOT_RSA 106 | ||
835 | #define EVP_R_UNKNOWN_PBE_ALGORITHM 121 | ||
836 | #define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS 135 | ||
837 | #define EVP_R_UNSUPPORTED_CIPHER 107 | ||
838 | #define EVP_R_UNSUPPORTED_KEYLENGTH 123 | ||
839 | #define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124 | ||
840 | #define EVP_R_UNSUPPORTED_KEY_SIZE 108 | ||
841 | #define EVP_R_UNSUPPORTED_PRF 125 | ||
842 | #define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118 | ||
843 | #define EVP_R_UNSUPPORTED_SALT_TYPE 126 | ||
844 | #define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109 | ||
845 | #define EVP_R_WRONG_PUBLIC_KEY_TYPE 110 | ||
846 | |||
847 | #ifdef __cplusplus | ||
848 | } | ||
849 | #endif | ||
850 | #endif | ||
851 | |||
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c deleted file mode 100644 index e2687f9879..0000000000 --- a/src/lib/libcrypto/evp/evp_enc.c +++ /dev/null | |||
@@ -1,341 +0,0 @@ | |||
1 | /* crypto/evp/evp_enc.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include "evp_locl.h" | ||
64 | |||
65 | const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT; | ||
66 | |||
67 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) | ||
68 | { | ||
69 | memset(ctx,0,sizeof(EVP_CIPHER_CTX)); | ||
70 | /* ctx->cipher=NULL; */ | ||
71 | } | ||
72 | |||
73 | int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, | ||
74 | unsigned char *key, unsigned char *iv, int enc) | ||
75 | { | ||
76 | if(enc && (enc != -1)) enc = 1; | ||
77 | if (cipher) { | ||
78 | ctx->cipher=cipher; | ||
79 | ctx->key_len = cipher->key_len; | ||
80 | if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT) { | ||
81 | if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) { | ||
82 | EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR); | ||
83 | return 0; | ||
84 | } | ||
85 | } | ||
86 | } else if(!ctx->cipher) { | ||
87 | EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET); | ||
88 | return 0; | ||
89 | } | ||
90 | if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) { | ||
91 | switch(EVP_CIPHER_CTX_mode(ctx)) { | ||
92 | |||
93 | case EVP_CIPH_STREAM_CIPHER: | ||
94 | case EVP_CIPH_ECB_MODE: | ||
95 | break; | ||
96 | |||
97 | case EVP_CIPH_CFB_MODE: | ||
98 | case EVP_CIPH_OFB_MODE: | ||
99 | |||
100 | ctx->num = 0; | ||
101 | |||
102 | case EVP_CIPH_CBC_MODE: | ||
103 | |||
104 | if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); | ||
105 | memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); | ||
106 | break; | ||
107 | |||
108 | default: | ||
109 | return 0; | ||
110 | break; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) { | ||
115 | if(!ctx->cipher->init(ctx,key,iv,enc)) return 0; | ||
116 | } | ||
117 | if(enc != -1) ctx->encrypt=enc; | ||
118 | ctx->buf_len=0; | ||
119 | return 1; | ||
120 | } | ||
121 | |||
122 | int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | ||
123 | unsigned char *in, int inl) | ||
124 | { | ||
125 | if (ctx->encrypt) | ||
126 | return EVP_EncryptUpdate(ctx,out,outl,in,inl); | ||
127 | else return EVP_DecryptUpdate(ctx,out,outl,in,inl); | ||
128 | } | ||
129 | |||
130 | int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | ||
131 | { | ||
132 | if (ctx->encrypt) | ||
133 | return EVP_EncryptFinal(ctx,out,outl); | ||
134 | else return(EVP_DecryptFinal(ctx,out,outl)); | ||
135 | } | ||
136 | |||
137 | int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, | ||
138 | unsigned char *key, unsigned char *iv) | ||
139 | { | ||
140 | return EVP_CipherInit(ctx, cipher, key, iv, 1); | ||
141 | } | ||
142 | |||
143 | int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, | ||
144 | unsigned char *key, unsigned char *iv) | ||
145 | { | ||
146 | return EVP_CipherInit(ctx, cipher, key, iv, 0); | ||
147 | } | ||
148 | |||
149 | |||
150 | int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | ||
151 | unsigned char *in, int inl) | ||
152 | { | ||
153 | int i,j,bl; | ||
154 | |||
155 | i=ctx->buf_len; | ||
156 | bl=ctx->cipher->block_size; | ||
157 | *outl=0; | ||
158 | if ((inl == 0) && (i != bl)) return 1; | ||
159 | if (i != 0) | ||
160 | { | ||
161 | if (i+inl < bl) | ||
162 | { | ||
163 | memcpy(&(ctx->buf[i]),in,inl); | ||
164 | ctx->buf_len+=inl; | ||
165 | return 1; | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | j=bl-i; | ||
170 | if (j != 0) memcpy(&(ctx->buf[i]),in,j); | ||
171 | if(!ctx->cipher->do_cipher(ctx,out,ctx->buf,bl)) return 0; | ||
172 | inl-=j; | ||
173 | in+=j; | ||
174 | out+=bl; | ||
175 | *outl+=bl; | ||
176 | } | ||
177 | } | ||
178 | i=inl%bl; /* how much is left */ | ||
179 | inl-=i; | ||
180 | if (inl > 0) | ||
181 | { | ||
182 | if(!ctx->cipher->do_cipher(ctx,out,in,inl)) return 0; | ||
183 | *outl+=inl; | ||
184 | } | ||
185 | |||
186 | if (i != 0) | ||
187 | memcpy(ctx->buf,&(in[inl]),i); | ||
188 | ctx->buf_len=i; | ||
189 | return 1; | ||
190 | } | ||
191 | |||
192 | int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | ||
193 | { | ||
194 | int i,n,b,bl; | ||
195 | |||
196 | b=ctx->cipher->block_size; | ||
197 | if (b == 1) | ||
198 | { | ||
199 | *outl=0; | ||
200 | return 1; | ||
201 | } | ||
202 | bl=ctx->buf_len; | ||
203 | n=b-bl; | ||
204 | for (i=bl; i<b; i++) | ||
205 | ctx->buf[i]=n; | ||
206 | if(!ctx->cipher->do_cipher(ctx,out,ctx->buf,b)) return 0; | ||
207 | *outl=b; | ||
208 | return 1; | ||
209 | } | ||
210 | |||
211 | int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | ||
212 | unsigned char *in, int inl) | ||
213 | { | ||
214 | int b,bl,n; | ||
215 | int keep_last=0; | ||
216 | |||
217 | *outl=0; | ||
218 | if (inl == 0) return 1; | ||
219 | |||
220 | b=ctx->cipher->block_size; | ||
221 | if (b > 1) | ||
222 | { | ||
223 | /* Is the input a multiple of the block size? */ | ||
224 | bl=ctx->buf_len; | ||
225 | n=inl+bl; | ||
226 | if (n%b == 0) | ||
227 | { | ||
228 | if (inl < b) /* must be 'just one' buff */ | ||
229 | { | ||
230 | memcpy(&(ctx->buf[bl]),in,inl); | ||
231 | ctx->buf_len=b; | ||
232 | *outl=0; | ||
233 | return 1; | ||
234 | } | ||
235 | keep_last=1; | ||
236 | inl-=b; /* don't do the last block */ | ||
237 | } | ||
238 | } | ||
239 | if(!EVP_EncryptUpdate(ctx,out,outl,in,inl)) return 0; | ||
240 | |||
241 | /* if we have 'decrypted' a multiple of block size, make sure | ||
242 | * we have a copy of this last block */ | ||
243 | if (keep_last) | ||
244 | { | ||
245 | memcpy(&(ctx->buf[0]),&(in[inl]),b); | ||
246 | #ifdef DEBUG | ||
247 | if (ctx->buf_len != 0) | ||
248 | { | ||
249 | abort(); | ||
250 | } | ||
251 | #endif | ||
252 | ctx->buf_len=b; | ||
253 | } | ||
254 | return 1; | ||
255 | } | ||
256 | |||
257 | int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | ||
258 | { | ||
259 | int i,b; | ||
260 | int n; | ||
261 | |||
262 | *outl=0; | ||
263 | b=ctx->cipher->block_size; | ||
264 | if (b > 1) | ||
265 | { | ||
266 | if (ctx->buf_len != b) | ||
267 | { | ||
268 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); | ||
269 | return(0); | ||
270 | } | ||
271 | if(!EVP_EncryptUpdate(ctx,ctx->buf,&n,ctx->buf,0)) return 0; | ||
272 | if (n != b) | ||
273 | return(0); | ||
274 | n=ctx->buf[b-1]; | ||
275 | if (n > b) | ||
276 | { | ||
277 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT); | ||
278 | return(0); | ||
279 | } | ||
280 | for (i=0; i<n; i++) | ||
281 | { | ||
282 | if (ctx->buf[--b] != n) | ||
283 | { | ||
284 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT); | ||
285 | return(0); | ||
286 | } | ||
287 | } | ||
288 | n=ctx->cipher->block_size-n; | ||
289 | for (i=0; i<n; i++) | ||
290 | out[i]=ctx->buf[i]; | ||
291 | *outl=n; | ||
292 | } | ||
293 | else | ||
294 | *outl=0; | ||
295 | return(1); | ||
296 | } | ||
297 | |||
298 | int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) | ||
299 | { | ||
300 | if ((c->cipher != NULL) && (c->cipher->cleanup != NULL)) | ||
301 | { | ||
302 | if(!c->cipher->cleanup(c)) return 0; | ||
303 | } | ||
304 | memset(c,0,sizeof(EVP_CIPHER_CTX)); | ||
305 | return 1; | ||
306 | } | ||
307 | |||
308 | int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen) | ||
309 | { | ||
310 | if(c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH) | ||
311 | return EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_KEY_LENGTH, keylen, NULL); | ||
312 | if(c->key_len == keylen) return 1; | ||
313 | if((keylen > 0) && (c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) | ||
314 | { | ||
315 | c->key_len = keylen; | ||
316 | return 1; | ||
317 | } | ||
318 | EVPerr(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH,EVP_R_INVALID_KEY_LENGTH); | ||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) | ||
323 | { | ||
324 | int ret; | ||
325 | if(!ctx->cipher) { | ||
326 | EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_NO_CIPHER_SET); | ||
327 | return 0; | ||
328 | } | ||
329 | |||
330 | if(!ctx->cipher->ctrl) { | ||
331 | EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED); | ||
332 | return 0; | ||
333 | } | ||
334 | |||
335 | ret = ctx->cipher->ctrl(ctx, type, arg, ptr); | ||
336 | if(ret == -1) { | ||
337 | EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED); | ||
338 | return 0; | ||
339 | } | ||
340 | return ret; | ||
341 | } | ||
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c deleted file mode 100644 index a01412a07c..0000000000 --- a/src/lib/libcrypto/evp/evp_err.c +++ /dev/null | |||
@@ -1,153 +0,0 @@ | |||
1 | /* crypto/evp/evp_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/evp.h> | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef NO_ERR | ||
67 | static ERR_STRING_DATA EVP_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"}, | ||
70 | {ERR_PACK(0,EVP_F_EVP_CIPHERINIT,0), "EVP_CipherInit"}, | ||
71 | {ERR_PACK(0,EVP_F_EVP_CIPHER_CTX_CTRL,0), "EVP_CIPHER_CTX_ctrl"}, | ||
72 | {ERR_PACK(0,EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH,0), "EVP_CIPHER_CTX_set_key_length"}, | ||
73 | {ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"}, | ||
74 | {ERR_PACK(0,EVP_F_EVP_MD_CTX_COPY,0), "EVP_MD_CTX_copy"}, | ||
75 | {ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"}, | ||
76 | {ERR_PACK(0,EVP_F_EVP_PBE_ALG_ADD,0), "EVP_PBE_alg_add"}, | ||
77 | {ERR_PACK(0,EVP_F_EVP_PBE_CIPHERINIT,0), "EVP_PBE_CipherInit"}, | ||
78 | {ERR_PACK(0,EVP_F_EVP_PKCS82PKEY,0), "EVP_PKCS82PKEY"}, | ||
79 | {ERR_PACK(0,EVP_F_EVP_PKCS8_SET_BROKEN,0), "EVP_PKCS8_SET_BROKEN"}, | ||
80 | {ERR_PACK(0,EVP_F_EVP_PKEY2PKCS8,0), "EVP_PKEY2PKCS8"}, | ||
81 | {ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"}, | ||
82 | {ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"}, | ||
83 | {ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"}, | ||
84 | {ERR_PACK(0,EVP_F_EVP_PKEY_GET1_DH,0), "EVP_PKEY_get1_DH"}, | ||
85 | {ERR_PACK(0,EVP_F_EVP_PKEY_GET1_DSA,0), "EVP_PKEY_get1_DSA"}, | ||
86 | {ERR_PACK(0,EVP_F_EVP_PKEY_GET1_RSA,0), "EVP_PKEY_get1_RSA"}, | ||
87 | {ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"}, | ||
88 | {ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"}, | ||
89 | {ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"}, | ||
90 | {ERR_PACK(0,EVP_F_PKCS5_PBE_KEYIVGEN,0), "PKCS5_PBE_keyivgen"}, | ||
91 | {ERR_PACK(0,EVP_F_PKCS5_V2_PBE_KEYIVGEN,0), "PKCS5_v2_PBE_keyivgen"}, | ||
92 | {ERR_PACK(0,EVP_F_RC2_MAGIC_TO_METH,0), "RC2_MAGIC_TO_METH"}, | ||
93 | {ERR_PACK(0,EVP_F_RC5_CTRL,0), "RC5_CTRL"}, | ||
94 | {0,NULL} | ||
95 | }; | ||
96 | |||
97 | static ERR_STRING_DATA EVP_str_reasons[]= | ||
98 | { | ||
99 | {EVP_R_BAD_DECRYPT ,"bad decrypt"}, | ||
100 | {EVP_R_BN_DECODE_ERROR ,"bn decode error"}, | ||
101 | {EVP_R_BN_PUBKEY_ERROR ,"bn pubkey error"}, | ||
102 | {EVP_R_CIPHER_PARAMETER_ERROR ,"cipher parameter error"}, | ||
103 | {EVP_R_CTRL_NOT_IMPLEMENTED ,"ctrl not implemented"}, | ||
104 | {EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED ,"ctrl operation not implemented"}, | ||
105 | {EVP_R_DECODE_ERROR ,"decode error"}, | ||
106 | {EVP_R_DIFFERENT_KEY_TYPES ,"different key types"}, | ||
107 | {EVP_R_ENCODE_ERROR ,"encode error"}, | ||
108 | {EVP_R_EVP_PBE_CIPHERINIT_ERROR ,"evp pbe cipherinit error"}, | ||
109 | {EVP_R_EXPECTING_AN_RSA_KEY ,"expecting an rsa key"}, | ||
110 | {EVP_R_EXPECTING_A_DH_KEY ,"expecting a dh key"}, | ||
111 | {EVP_R_EXPECTING_A_DSA_KEY ,"expecting a dsa key"}, | ||
112 | {EVP_R_INITIALIZATION_ERROR ,"initialization error"}, | ||
113 | {EVP_R_INPUT_NOT_INITIALIZED ,"input not initialized"}, | ||
114 | {EVP_R_INVALID_KEY_LENGTH ,"invalid key length"}, | ||
115 | {EVP_R_IV_TOO_LARGE ,"iv too large"}, | ||
116 | {EVP_R_KEYGEN_FAILURE ,"keygen failure"}, | ||
117 | {EVP_R_MISSING_PARAMETERS ,"missing parameters"}, | ||
118 | {EVP_R_NO_CIPHER_SET ,"no cipher set"}, | ||
119 | {EVP_R_NO_DSA_PARAMETERS ,"no dsa parameters"}, | ||
120 | {EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"}, | ||
121 | {EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"}, | ||
122 | {EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE ,"pkcs8 unknown broken type"}, | ||
123 | {EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"}, | ||
124 | {EVP_R_UNKNOWN_PBE_ALGORITHM ,"unknown pbe algorithm"}, | ||
125 | {EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS ,"unsuported number of rounds"}, | ||
126 | {EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, | ||
127 | {EVP_R_UNSUPPORTED_KEYLENGTH ,"unsupported keylength"}, | ||
128 | {EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION,"unsupported key derivation function"}, | ||
129 | {EVP_R_UNSUPPORTED_KEY_SIZE ,"unsupported key size"}, | ||
130 | {EVP_R_UNSUPPORTED_PRF ,"unsupported prf"}, | ||
131 | {EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM ,"unsupported private key algorithm"}, | ||
132 | {EVP_R_UNSUPPORTED_SALT_TYPE ,"unsupported salt type"}, | ||
133 | {EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"}, | ||
134 | {EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"}, | ||
135 | {0,NULL} | ||
136 | }; | ||
137 | |||
138 | #endif | ||
139 | |||
140 | void ERR_load_EVP_strings(void) | ||
141 | { | ||
142 | static int init=1; | ||
143 | |||
144 | if (init) | ||
145 | { | ||
146 | init=0; | ||
147 | #ifndef NO_ERR | ||
148 | ERR_load_strings(ERR_LIB_EVP,EVP_str_functs); | ||
149 | ERR_load_strings(ERR_LIB_EVP,EVP_str_reasons); | ||
150 | #endif | ||
151 | |||
152 | } | ||
153 | } | ||
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c deleted file mode 100644 index e7434ef9b2..0000000000 --- a/src/lib/libcrypto/evp/evp_key.c +++ /dev/null | |||
@@ -1,159 +0,0 @@ | |||
1 | /* crypto/evp/evp_key.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/x509.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/evp.h> | ||
64 | |||
65 | /* should be init to zeros. */ | ||
66 | static char prompt_string[80]; | ||
67 | |||
68 | void EVP_set_pw_prompt(char *prompt) | ||
69 | { | ||
70 | if (prompt == NULL) | ||
71 | prompt_string[0]='\0'; | ||
72 | else | ||
73 | strncpy(prompt_string,prompt,79); | ||
74 | } | ||
75 | |||
76 | char *EVP_get_pw_prompt(void) | ||
77 | { | ||
78 | if (prompt_string[0] == '\0') | ||
79 | return(NULL); | ||
80 | else | ||
81 | return(prompt_string); | ||
82 | } | ||
83 | |||
84 | /* For historical reasons, the standard function for reading passwords is | ||
85 | * in the DES library -- if someone ever wants to disable DES, | ||
86 | * this function will fail */ | ||
87 | int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify) | ||
88 | { | ||
89 | #ifndef NO_DES | ||
90 | if ((prompt == NULL) && (prompt_string[0] != '\0')) | ||
91 | prompt=prompt_string; | ||
92 | return(des_read_pw_string(buf,len,prompt,verify)); | ||
93 | #else | ||
94 | return -1; | ||
95 | #endif | ||
96 | } | ||
97 | |||
98 | int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, | ||
99 | const unsigned char *salt, const unsigned char *data, int datal, | ||
100 | int count, unsigned char *key, unsigned char *iv) | ||
101 | { | ||
102 | EVP_MD_CTX c; | ||
103 | unsigned char md_buf[EVP_MAX_MD_SIZE]; | ||
104 | int niv,nkey,addmd=0; | ||
105 | unsigned int mds=0,i; | ||
106 | |||
107 | nkey=type->key_len; | ||
108 | niv=type->iv_len; | ||
109 | |||
110 | if (data == NULL) return(nkey); | ||
111 | |||
112 | for (;;) | ||
113 | { | ||
114 | EVP_DigestInit(&c,md); | ||
115 | if (addmd++) | ||
116 | EVP_DigestUpdate(&c,&(md_buf[0]),mds); | ||
117 | EVP_DigestUpdate(&c,data,datal); | ||
118 | if (salt != NULL) | ||
119 | EVP_DigestUpdate(&c,salt,PKCS5_SALT_LEN); | ||
120 | EVP_DigestFinal(&c,&(md_buf[0]),&mds); | ||
121 | |||
122 | for (i=1; i<(unsigned int)count; i++) | ||
123 | { | ||
124 | EVP_DigestInit(&c,md); | ||
125 | EVP_DigestUpdate(&c,&(md_buf[0]),mds); | ||
126 | EVP_DigestFinal(&c,&(md_buf[0]),&mds); | ||
127 | } | ||
128 | i=0; | ||
129 | if (nkey) | ||
130 | { | ||
131 | for (;;) | ||
132 | { | ||
133 | if (nkey == 0) break; | ||
134 | if (i == mds) break; | ||
135 | if (key != NULL) | ||
136 | *(key++)=md_buf[i]; | ||
137 | nkey--; | ||
138 | i++; | ||
139 | } | ||
140 | } | ||
141 | if (niv && (i != mds)) | ||
142 | { | ||
143 | for (;;) | ||
144 | { | ||
145 | if (niv == 0) break; | ||
146 | if (i == mds) break; | ||
147 | if (iv != NULL) | ||
148 | *(iv++)=md_buf[i]; | ||
149 | niv--; | ||
150 | i++; | ||
151 | } | ||
152 | } | ||
153 | if ((nkey == 0) && (niv == 0)) break; | ||
154 | } | ||
155 | memset(&c,0,sizeof(c)); | ||
156 | memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE); | ||
157 | return(type->key_len); | ||
158 | } | ||
159 | |||
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c deleted file mode 100644 index a431945ef5..0000000000 --- a/src/lib/libcrypto/evp/evp_lib.c +++ /dev/null | |||
@@ -1,142 +0,0 @@ | |||
1 | /* crypto/evp/evp_lib.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/objects.h> | ||
63 | |||
64 | int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | ||
65 | { | ||
66 | int ret; | ||
67 | |||
68 | if (c->cipher->set_asn1_parameters != NULL) | ||
69 | ret=c->cipher->set_asn1_parameters(c,type); | ||
70 | else | ||
71 | ret=1; | ||
72 | return(ret); | ||
73 | } | ||
74 | |||
75 | int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | ||
76 | { | ||
77 | int ret; | ||
78 | |||
79 | if (c->cipher->get_asn1_parameters != NULL) | ||
80 | ret=c->cipher->get_asn1_parameters(c,type); | ||
81 | else | ||
82 | ret=1; | ||
83 | return(ret); | ||
84 | } | ||
85 | |||
86 | int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | ||
87 | { | ||
88 | int i=0,l; | ||
89 | |||
90 | if (type != NULL) | ||
91 | { | ||
92 | l=EVP_CIPHER_CTX_iv_length(c); | ||
93 | i=ASN1_TYPE_get_octetstring(type,c->oiv,l); | ||
94 | if (i != l) | ||
95 | return(-1); | ||
96 | else if (i > 0) | ||
97 | memcpy(c->iv,c->oiv,l); | ||
98 | } | ||
99 | return(i); | ||
100 | } | ||
101 | |||
102 | int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | ||
103 | { | ||
104 | int i=0,j; | ||
105 | |||
106 | if (type != NULL) | ||
107 | { | ||
108 | j=EVP_CIPHER_CTX_iv_length(c); | ||
109 | i=ASN1_TYPE_set_octetstring(type,c->oiv,j); | ||
110 | } | ||
111 | return(i); | ||
112 | } | ||
113 | |||
114 | /* Convert the various cipher NIDs and dummies to a proper OID NID */ | ||
115 | int EVP_CIPHER_type(const EVP_CIPHER *ctx) | ||
116 | { | ||
117 | int nid; | ||
118 | ASN1_OBJECT *otmp; | ||
119 | nid = EVP_CIPHER_nid(ctx); | ||
120 | |||
121 | switch(nid) { | ||
122 | |||
123 | case NID_rc2_cbc: | ||
124 | case NID_rc2_64_cbc: | ||
125 | case NID_rc2_40_cbc: | ||
126 | |||
127 | return NID_rc2_cbc; | ||
128 | |||
129 | case NID_rc4: | ||
130 | case NID_rc4_40: | ||
131 | |||
132 | return NID_rc4; | ||
133 | |||
134 | default: | ||
135 | /* Check it has an OID and it is valid */ | ||
136 | otmp = OBJ_nid2obj(nid); | ||
137 | if(!otmp || !otmp->data) nid = NID_undef; | ||
138 | ASN1_OBJECT_free(otmp); | ||
139 | return nid; | ||
140 | } | ||
141 | } | ||
142 | |||
diff --git a/src/lib/libcrypto/evp/evp_locl.h b/src/lib/libcrypto/evp/evp_locl.h deleted file mode 100644 index ce49d5b7d8..0000000000 --- a/src/lib/libcrypto/evp/evp_locl.h +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
1 | /* evp_locl.h */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | /* Macros to code block cipher wrappers */ | ||
60 | |||
61 | /* Wrapper functions for each cipher mode */ | ||
62 | |||
63 | #define BLOCK_CIPHER_ecb_loop() \ | ||
64 | unsigned int i; \ | ||
65 | if(inl < 8) return 1;\ | ||
66 | inl -= 8; \ | ||
67 | for(i=0; i <= inl; i+=8) \ | ||
68 | |||
69 | #define BLOCK_CIPHER_func_ecb(cname, cprefix, kname) \ | ||
70 | static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \ | ||
71 | {\ | ||
72 | BLOCK_CIPHER_ecb_loop() \ | ||
73 | cprefix##_ecb_encrypt(in + i, out + i, &ctx->c.kname, ctx->encrypt);\ | ||
74 | return 1;\ | ||
75 | } | ||
76 | |||
77 | #define BLOCK_CIPHER_func_ofb(cname, cprefix, kname) \ | ||
78 | static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \ | ||
79 | {\ | ||
80 | cprefix##_ofb64_encrypt(in, out, (long)inl, &ctx->c.kname, ctx->iv, &ctx->num);\ | ||
81 | return 1;\ | ||
82 | } | ||
83 | |||
84 | #define BLOCK_CIPHER_func_cbc(cname, cprefix, kname) \ | ||
85 | static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \ | ||
86 | {\ | ||
87 | cprefix##_cbc_encrypt(in, out, (long)inl, &ctx->c.kname, ctx->iv, ctx->encrypt);\ | ||
88 | return 1;\ | ||
89 | } | ||
90 | |||
91 | #define BLOCK_CIPHER_func_cfb(cname, cprefix, kname) \ | ||
92 | static int cname##_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \ | ||
93 | {\ | ||
94 | cprefix##_cfb64_encrypt(in, out, (long)inl, &ctx->c.kname, ctx->iv, &ctx->num, ctx->encrypt);\ | ||
95 | return 1;\ | ||
96 | } | ||
97 | |||
98 | #define BLOCK_CIPHER_all_funcs(cname, cprefix, kname) \ | ||
99 | BLOCK_CIPHER_func_cbc(cname, cprefix, kname) \ | ||
100 | BLOCK_CIPHER_func_cfb(cname, cprefix, kname) \ | ||
101 | BLOCK_CIPHER_func_ecb(cname, cprefix, kname) \ | ||
102 | BLOCK_CIPHER_func_ofb(cname, cprefix, kname) | ||
103 | |||
104 | #define BLOCK_CIPHER_defs(cname, kstruct, \ | ||
105 | nid, block_size, key_len, iv_len, flags,\ | ||
106 | init_key, cleanup, set_asn1, get_asn1, ctrl)\ | ||
107 | static EVP_CIPHER cname##_cbc = {\ | ||
108 | nid##_cbc, block_size, key_len, iv_len, \ | ||
109 | flags | EVP_CIPH_CBC_MODE,\ | ||
110 | init_key,\ | ||
111 | cname##_cbc_cipher,\ | ||
112 | cleanup,\ | ||
113 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\ | ||
114 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\ | ||
115 | set_asn1, get_asn1,\ | ||
116 | ctrl, \ | ||
117 | NULL \ | ||
118 | };\ | ||
119 | EVP_CIPHER *EVP_##cname##_cbc(void) { return &cname##_cbc; }\ | ||
120 | static EVP_CIPHER cname##_cfb = {\ | ||
121 | nid##_cfb64, 1, key_len, iv_len, \ | ||
122 | flags | EVP_CIPH_CFB_MODE,\ | ||
123 | init_key,\ | ||
124 | cname##_cfb_cipher,\ | ||
125 | cleanup,\ | ||
126 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\ | ||
127 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\ | ||
128 | set_asn1, get_asn1,\ | ||
129 | ctrl,\ | ||
130 | NULL \ | ||
131 | };\ | ||
132 | EVP_CIPHER *EVP_##cname##_cfb(void) { return &cname##_cfb; }\ | ||
133 | static EVP_CIPHER cname##_ofb = {\ | ||
134 | nid##_ofb64, 1, key_len, iv_len, \ | ||
135 | flags | EVP_CIPH_OFB_MODE,\ | ||
136 | init_key,\ | ||
137 | cname##_ofb_cipher,\ | ||
138 | cleanup,\ | ||
139 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\ | ||
140 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\ | ||
141 | set_asn1, get_asn1,\ | ||
142 | ctrl,\ | ||
143 | NULL \ | ||
144 | };\ | ||
145 | EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\ | ||
146 | static EVP_CIPHER cname##_ecb = {\ | ||
147 | nid##_ecb, block_size, key_len, iv_len, \ | ||
148 | flags | EVP_CIPH_ECB_MODE,\ | ||
149 | init_key,\ | ||
150 | cname##_ecb_cipher,\ | ||
151 | cleanup,\ | ||
152 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\ | ||
153 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\ | ||
154 | set_asn1, get_asn1,\ | ||
155 | ctrl,\ | ||
156 | NULL \ | ||
157 | };\ | ||
158 | EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; } | ||
159 | |||
160 | |||
161 | |||
162 | #define IMPLEMENT_BLOCK_CIPHER(cname, kname, cprefix, kstruct, \ | ||
163 | nid, block_size, key_len, iv_len, flags, \ | ||
164 | init_key, cleanup, set_asn1, get_asn1, ctrl) \ | ||
165 | BLOCK_CIPHER_all_funcs(cname, cprefix, kname) \ | ||
166 | BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len, flags,\ | ||
167 | init_key, cleanup, set_asn1, get_asn1, ctrl) | ||
168 | |||
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c deleted file mode 100644 index 224a422b12..0000000000 --- a/src/lib/libcrypto/evp/evp_pbe.c +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | /* evp_pbe.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/evp.h> | ||
61 | #include <openssl/x509.h> | ||
62 | #include "cryptlib.h" | ||
63 | |||
64 | /* Password based encryption (PBE) functions */ | ||
65 | |||
66 | static STACK *pbe_algs; | ||
67 | |||
68 | /* Setup a cipher context from a PBE algorithm */ | ||
69 | |||
70 | typedef struct { | ||
71 | int pbe_nid; | ||
72 | EVP_CIPHER *cipher; | ||
73 | EVP_MD *md; | ||
74 | EVP_PBE_KEYGEN *keygen; | ||
75 | } EVP_PBE_CTL; | ||
76 | |||
77 | int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen, | ||
78 | ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de) | ||
79 | { | ||
80 | |||
81 | EVP_PBE_CTL *pbetmp, pbelu; | ||
82 | int i; | ||
83 | pbelu.pbe_nid = OBJ_obj2nid(pbe_obj); | ||
84 | if (pbelu.pbe_nid != NID_undef) i = sk_find(pbe_algs, (char *)&pbelu); | ||
85 | else i = -1; | ||
86 | |||
87 | if (i == -1) { | ||
88 | char obj_tmp[80]; | ||
89 | EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM); | ||
90 | if (!pbe_obj) strcpy (obj_tmp, "NULL"); | ||
91 | else i2t_ASN1_OBJECT(obj_tmp, 80, pbe_obj); | ||
92 | ERR_add_error_data(2, "TYPE=", obj_tmp); | ||
93 | return 0; | ||
94 | } | ||
95 | if(!pass) passlen = 0; | ||
96 | else if (passlen == -1) passlen = strlen(pass); | ||
97 | pbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i); | ||
98 | i = (*pbetmp->keygen)(ctx, pass, passlen, param, pbetmp->cipher, | ||
99 | pbetmp->md, en_de); | ||
100 | if (!i) { | ||
101 | EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE); | ||
102 | return 0; | ||
103 | } | ||
104 | return 1; | ||
105 | } | ||
106 | |||
107 | static int pbe_cmp(const char * const *a, const char * const *b) | ||
108 | { | ||
109 | EVP_PBE_CTL **pbe1 = (EVP_PBE_CTL **) a, **pbe2 = (EVP_PBE_CTL **)b; | ||
110 | return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid); | ||
111 | } | ||
112 | |||
113 | /* Add a PBE algorithm */ | ||
114 | |||
115 | int EVP_PBE_alg_add (int nid, EVP_CIPHER *cipher, EVP_MD *md, | ||
116 | EVP_PBE_KEYGEN *keygen) | ||
117 | { | ||
118 | EVP_PBE_CTL *pbe_tmp; | ||
119 | if (!pbe_algs) pbe_algs = sk_new(pbe_cmp); | ||
120 | if (!(pbe_tmp = (EVP_PBE_CTL*) OPENSSL_malloc (sizeof(EVP_PBE_CTL)))) { | ||
121 | EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE); | ||
122 | return 0; | ||
123 | } | ||
124 | pbe_tmp->pbe_nid = nid; | ||
125 | pbe_tmp->cipher = cipher; | ||
126 | pbe_tmp->md = md; | ||
127 | pbe_tmp->keygen = keygen; | ||
128 | sk_push (pbe_algs, (char *)pbe_tmp); | ||
129 | return 1; | ||
130 | } | ||
131 | |||
132 | void EVP_PBE_cleanup(void) | ||
133 | { | ||
134 | sk_pop_free(pbe_algs, OPENSSL_freeFunc); | ||
135 | pbe_algs = NULL; | ||
136 | } | ||
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c deleted file mode 100644 index 8df2874f3c..0000000000 --- a/src/lib/libcrypto/evp/evp_pkey.c +++ /dev/null | |||
@@ -1,408 +0,0 @@ | |||
1 | /* evp_pkey.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <stdlib.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/x509.h> | ||
63 | #include <openssl/rand.h> | ||
64 | |||
65 | static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey); | ||
66 | |||
67 | /* Extract a private key from a PKCS8 structure */ | ||
68 | |||
69 | EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8) | ||
70 | { | ||
71 | EVP_PKEY *pkey = NULL; | ||
72 | #ifndef NO_RSA | ||
73 | RSA *rsa = NULL; | ||
74 | #endif | ||
75 | #ifndef NO_DSA | ||
76 | DSA *dsa = NULL; | ||
77 | ASN1_INTEGER *privkey; | ||
78 | ASN1_TYPE *t1, *t2, *param = NULL; | ||
79 | STACK_OF(ASN1_TYPE) *ndsa = NULL; | ||
80 | BN_CTX *ctx = NULL; | ||
81 | int plen; | ||
82 | #endif | ||
83 | X509_ALGOR *a; | ||
84 | unsigned char *p; | ||
85 | int pkeylen; | ||
86 | char obj_tmp[80]; | ||
87 | |||
88 | if(p8->pkey->type == V_ASN1_OCTET_STRING) { | ||
89 | p8->broken = PKCS8_OK; | ||
90 | p = p8->pkey->value.octet_string->data; | ||
91 | pkeylen = p8->pkey->value.octet_string->length; | ||
92 | } else { | ||
93 | p8->broken = PKCS8_NO_OCTET; | ||
94 | p = p8->pkey->value.sequence->data; | ||
95 | pkeylen = p8->pkey->value.sequence->length; | ||
96 | } | ||
97 | if (!(pkey = EVP_PKEY_new())) { | ||
98 | EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE); | ||
99 | return NULL; | ||
100 | } | ||
101 | a = p8->pkeyalg; | ||
102 | switch (OBJ_obj2nid(a->algorithm)) | ||
103 | { | ||
104 | #ifndef NO_RSA | ||
105 | case NID_rsaEncryption: | ||
106 | if (!(rsa = d2i_RSAPrivateKey (NULL, &p, pkeylen))) { | ||
107 | EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); | ||
108 | return NULL; | ||
109 | } | ||
110 | EVP_PKEY_assign_RSA (pkey, rsa); | ||
111 | break; | ||
112 | #endif | ||
113 | #ifndef NO_DSA | ||
114 | case NID_dsa: | ||
115 | /* PKCS#8 DSA is weird: you just get a private key integer | ||
116 | * and parameters in the AlgorithmIdentifier the pubkey must | ||
117 | * be recalculated. | ||
118 | */ | ||
119 | |||
120 | /* Check for broken DSA PKCS#8, UGH! */ | ||
121 | if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) { | ||
122 | if(!(ndsa = ASN1_seq_unpack_ASN1_TYPE(p, pkeylen, | ||
123 | d2i_ASN1_TYPE, | ||
124 | ASN1_TYPE_free))) { | ||
125 | EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); | ||
126 | goto dsaerr; | ||
127 | } | ||
128 | if(sk_ASN1_TYPE_num(ndsa) != 2 ) { | ||
129 | EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); | ||
130 | goto dsaerr; | ||
131 | } | ||
132 | /* Handle Two broken types: | ||
133 | * SEQUENCE {parameters, priv_key} | ||
134 | * SEQUENCE {pub_key, priv_key} | ||
135 | */ | ||
136 | |||
137 | t1 = sk_ASN1_TYPE_value(ndsa, 0); | ||
138 | t2 = sk_ASN1_TYPE_value(ndsa, 1); | ||
139 | if(t1->type == V_ASN1_SEQUENCE) { | ||
140 | p8->broken = PKCS8_EMBEDDED_PARAM; | ||
141 | param = t1; | ||
142 | } else if(a->parameter->type == V_ASN1_SEQUENCE) { | ||
143 | p8->broken = PKCS8_NS_DB; | ||
144 | param = a->parameter; | ||
145 | } else { | ||
146 | EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); | ||
147 | goto dsaerr; | ||
148 | } | ||
149 | |||
150 | if(t2->type != V_ASN1_INTEGER) { | ||
151 | EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); | ||
152 | goto dsaerr; | ||
153 | } | ||
154 | privkey = t2->value.integer; | ||
155 | } else { | ||
156 | if (!(privkey=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) { | ||
157 | EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); | ||
158 | goto dsaerr; | ||
159 | } | ||
160 | param = p8->pkeyalg->parameter; | ||
161 | } | ||
162 | if (!param || (param->type != V_ASN1_SEQUENCE)) { | ||
163 | EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); | ||
164 | goto dsaerr; | ||
165 | } | ||
166 | p = param->value.sequence->data; | ||
167 | plen = param->value.sequence->length; | ||
168 | if (!(dsa = d2i_DSAparams (NULL, &p, plen))) { | ||
169 | EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); | ||
170 | goto dsaerr; | ||
171 | } | ||
172 | /* We have parameters now set private key */ | ||
173 | if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) { | ||
174 | EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR); | ||
175 | goto dsaerr; | ||
176 | } | ||
177 | /* Calculate public key (ouch!) */ | ||
178 | if (!(dsa->pub_key = BN_new())) { | ||
179 | EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE); | ||
180 | goto dsaerr; | ||
181 | } | ||
182 | if (!(ctx = BN_CTX_new())) { | ||
183 | EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE); | ||
184 | goto dsaerr; | ||
185 | } | ||
186 | |||
187 | if (!BN_mod_exp(dsa->pub_key, dsa->g, | ||
188 | dsa->priv_key, dsa->p, ctx)) { | ||
189 | |||
190 | EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR); | ||
191 | goto dsaerr; | ||
192 | } | ||
193 | |||
194 | EVP_PKEY_assign_DSA(pkey, dsa); | ||
195 | BN_CTX_free (ctx); | ||
196 | if(ndsa) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
197 | else ASN1_INTEGER_free(privkey); | ||
198 | break; | ||
199 | dsaerr: | ||
200 | BN_CTX_free (ctx); | ||
201 | sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
202 | DSA_free(dsa); | ||
203 | EVP_PKEY_free(pkey); | ||
204 | return NULL; | ||
205 | break; | ||
206 | #endif | ||
207 | default: | ||
208 | EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM); | ||
209 | if (!a->algorithm) strcpy (obj_tmp, "NULL"); | ||
210 | else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm); | ||
211 | ERR_add_error_data(2, "TYPE=", obj_tmp); | ||
212 | EVP_PKEY_free (pkey); | ||
213 | return NULL; | ||
214 | } | ||
215 | return pkey; | ||
216 | } | ||
217 | |||
218 | PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey) | ||
219 | { | ||
220 | return EVP_PKEY2PKCS8_broken(pkey, PKCS8_OK); | ||
221 | } | ||
222 | |||
223 | /* Turn a private key into a PKCS8 structure */ | ||
224 | |||
225 | PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken) | ||
226 | { | ||
227 | PKCS8_PRIV_KEY_INFO *p8; | ||
228 | |||
229 | if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) { | ||
230 | EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); | ||
231 | return NULL; | ||
232 | } | ||
233 | p8->broken = broken; | ||
234 | ASN1_INTEGER_set (p8->version, 0); | ||
235 | if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) { | ||
236 | EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); | ||
237 | PKCS8_PRIV_KEY_INFO_free (p8); | ||
238 | return NULL; | ||
239 | } | ||
240 | p8->pkey->type = V_ASN1_OCTET_STRING; | ||
241 | switch (EVP_PKEY_type(pkey->type)) { | ||
242 | #ifndef NO_RSA | ||
243 | case EVP_PKEY_RSA: | ||
244 | |||
245 | if(p8->broken == PKCS8_NO_OCTET) p8->pkey->type = V_ASN1_SEQUENCE; | ||
246 | |||
247 | p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption); | ||
248 | p8->pkeyalg->parameter->type = V_ASN1_NULL; | ||
249 | if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey, | ||
250 | &p8->pkey->value.octet_string)) { | ||
251 | EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); | ||
252 | PKCS8_PRIV_KEY_INFO_free (p8); | ||
253 | return NULL; | ||
254 | } | ||
255 | break; | ||
256 | #endif | ||
257 | #ifndef NO_DSA | ||
258 | case EVP_PKEY_DSA: | ||
259 | if(!dsa_pkey2pkcs8(p8, pkey)) { | ||
260 | PKCS8_PRIV_KEY_INFO_free (p8); | ||
261 | return NULL; | ||
262 | } | ||
263 | |||
264 | break; | ||
265 | #endif | ||
266 | default: | ||
267 | EVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM); | ||
268 | PKCS8_PRIV_KEY_INFO_free (p8); | ||
269 | return NULL; | ||
270 | } | ||
271 | RAND_add(p8->pkey->value.octet_string->data, | ||
272 | p8->pkey->value.octet_string->length, 0); | ||
273 | return p8; | ||
274 | } | ||
275 | |||
276 | PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken) | ||
277 | { | ||
278 | switch (broken) { | ||
279 | |||
280 | case PKCS8_OK: | ||
281 | p8->broken = PKCS8_OK; | ||
282 | return p8; | ||
283 | break; | ||
284 | |||
285 | case PKCS8_NO_OCTET: | ||
286 | p8->broken = PKCS8_NO_OCTET; | ||
287 | p8->pkey->type = V_ASN1_SEQUENCE; | ||
288 | return p8; | ||
289 | break; | ||
290 | |||
291 | default: | ||
292 | EVPerr(EVP_F_EVP_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE); | ||
293 | return NULL; | ||
294 | break; | ||
295 | |||
296 | } | ||
297 | } | ||
298 | |||
299 | #ifndef NO_DSA | ||
300 | static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey) | ||
301 | { | ||
302 | ASN1_STRING *params; | ||
303 | ASN1_INTEGER *prkey; | ||
304 | ASN1_TYPE *ttmp; | ||
305 | STACK_OF(ASN1_TYPE) *ndsa; | ||
306 | unsigned char *p, *q; | ||
307 | int len; | ||
308 | |||
309 | p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa); | ||
310 | len = i2d_DSAparams (pkey->pkey.dsa, NULL); | ||
311 | if (!(p = OPENSSL_malloc(len))) { | ||
312 | EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); | ||
313 | PKCS8_PRIV_KEY_INFO_free (p8); | ||
314 | return 0; | ||
315 | } | ||
316 | q = p; | ||
317 | i2d_DSAparams (pkey->pkey.dsa, &q); | ||
318 | params = ASN1_STRING_new(); | ||
319 | ASN1_STRING_set(params, p, len); | ||
320 | OPENSSL_free(p); | ||
321 | /* Get private key into integer */ | ||
322 | if (!(prkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) { | ||
323 | EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR); | ||
324 | return 0; | ||
325 | } | ||
326 | |||
327 | switch(p8->broken) { | ||
328 | |||
329 | case PKCS8_OK: | ||
330 | case PKCS8_NO_OCTET: | ||
331 | |||
332 | if (!ASN1_pack_string((char *)prkey, i2d_ASN1_INTEGER, | ||
333 | &p8->pkey->value.octet_string)) { | ||
334 | EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); | ||
335 | M_ASN1_INTEGER_free (prkey); | ||
336 | return 0; | ||
337 | } | ||
338 | |||
339 | M_ASN1_INTEGER_free (prkey); | ||
340 | p8->pkeyalg->parameter->value.sequence = params; | ||
341 | p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE; | ||
342 | |||
343 | break; | ||
344 | |||
345 | case PKCS8_NS_DB: | ||
346 | |||
347 | p8->pkeyalg->parameter->value.sequence = params; | ||
348 | p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE; | ||
349 | ndsa = sk_ASN1_TYPE_new_null(); | ||
350 | ttmp = ASN1_TYPE_new(); | ||
351 | if (!(ttmp->value.integer = BN_to_ASN1_INTEGER (pkey->pkey.dsa->pub_key, NULL))) { | ||
352 | EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR); | ||
353 | PKCS8_PRIV_KEY_INFO_free(p8); | ||
354 | return 0; | ||
355 | } | ||
356 | ttmp->type = V_ASN1_INTEGER; | ||
357 | sk_ASN1_TYPE_push(ndsa, ttmp); | ||
358 | |||
359 | ttmp = ASN1_TYPE_new(); | ||
360 | ttmp->value.integer = prkey; | ||
361 | ttmp->type = V_ASN1_INTEGER; | ||
362 | sk_ASN1_TYPE_push(ndsa, ttmp); | ||
363 | |||
364 | p8->pkey->value.octet_string = ASN1_OCTET_STRING_new(); | ||
365 | |||
366 | if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE, | ||
367 | &p8->pkey->value.octet_string->data, | ||
368 | &p8->pkey->value.octet_string->length)) { | ||
369 | |||
370 | EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); | ||
371 | sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
372 | M_ASN1_INTEGER_free(prkey); | ||
373 | return 0; | ||
374 | } | ||
375 | sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
376 | break; | ||
377 | |||
378 | case PKCS8_EMBEDDED_PARAM: | ||
379 | |||
380 | p8->pkeyalg->parameter->type = V_ASN1_NULL; | ||
381 | ndsa = sk_ASN1_TYPE_new_null(); | ||
382 | ttmp = ASN1_TYPE_new(); | ||
383 | ttmp->value.sequence = params; | ||
384 | ttmp->type = V_ASN1_SEQUENCE; | ||
385 | sk_ASN1_TYPE_push(ndsa, ttmp); | ||
386 | |||
387 | ttmp = ASN1_TYPE_new(); | ||
388 | ttmp->value.integer = prkey; | ||
389 | ttmp->type = V_ASN1_INTEGER; | ||
390 | sk_ASN1_TYPE_push(ndsa, ttmp); | ||
391 | |||
392 | p8->pkey->value.octet_string = ASN1_OCTET_STRING_new(); | ||
393 | |||
394 | if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE, | ||
395 | &p8->pkey->value.octet_string->data, | ||
396 | &p8->pkey->value.octet_string->length)) { | ||
397 | |||
398 | EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); | ||
399 | sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
400 | M_ASN1_INTEGER_free (prkey); | ||
401 | return 0; | ||
402 | } | ||
403 | sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
404 | break; | ||
405 | } | ||
406 | return 1; | ||
407 | } | ||
408 | #endif | ||
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c deleted file mode 100644 index 8ea826868e..0000000000 --- a/src/lib/libcrypto/evp/m_dss.c +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | /* crypto/evp/m_dss.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/x509.h> | ||
64 | |||
65 | #ifndef NO_SHA | ||
66 | static EVP_MD dsa_md= | ||
67 | { | ||
68 | NID_dsaWithSHA, | ||
69 | NID_dsaWithSHA, | ||
70 | SHA_DIGEST_LENGTH, | ||
71 | SHA1_Init, | ||
72 | SHA1_Update, | ||
73 | SHA1_Final, | ||
74 | EVP_PKEY_DSA_method, | ||
75 | SHA_CBLOCK, | ||
76 | sizeof(EVP_MD *)+sizeof(SHA_CTX), | ||
77 | }; | ||
78 | |||
79 | EVP_MD *EVP_dss(void) | ||
80 | { | ||
81 | return(&dsa_md); | ||
82 | } | ||
83 | #endif | ||
diff --git a/src/lib/libcrypto/evp/m_dss1.c b/src/lib/libcrypto/evp/m_dss1.c deleted file mode 100644 index 9d8d1ce23e..0000000000 --- a/src/lib/libcrypto/evp/m_dss1.c +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | /* crypto/evp/m_dss1.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_SHA | ||
60 | #include <stdio.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/x509.h> | ||
65 | |||
66 | static EVP_MD dss1_md= | ||
67 | { | ||
68 | NID_dsa, | ||
69 | NID_dsaWithSHA1, | ||
70 | SHA_DIGEST_LENGTH, | ||
71 | SHA1_Init, | ||
72 | SHA1_Update, | ||
73 | SHA1_Final, | ||
74 | EVP_PKEY_DSA_method, | ||
75 | SHA_CBLOCK, | ||
76 | sizeof(EVP_MD *)+sizeof(SHA_CTX), | ||
77 | }; | ||
78 | |||
79 | EVP_MD *EVP_dss1(void) | ||
80 | { | ||
81 | return(&dss1_md); | ||
82 | } | ||
83 | #endif | ||
diff --git a/src/lib/libcrypto/evp/m_md4.c b/src/lib/libcrypto/evp/m_md4.c deleted file mode 100644 index 6a24ceb86d..0000000000 --- a/src/lib/libcrypto/evp/m_md4.c +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | /* crypto/evp/m_md4.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_MD4 | ||
60 | #include <stdio.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/x509.h> | ||
65 | |||
66 | static EVP_MD md4_md= | ||
67 | { | ||
68 | NID_md4, | ||
69 | 0, | ||
70 | MD4_DIGEST_LENGTH, | ||
71 | MD4_Init, | ||
72 | MD4_Update, | ||
73 | MD4_Final, | ||
74 | EVP_PKEY_RSA_method, | ||
75 | MD4_CBLOCK, | ||
76 | sizeof(EVP_MD *)+sizeof(MD4_CTX), | ||
77 | }; | ||
78 | |||
79 | EVP_MD *EVP_md4(void) | ||
80 | { | ||
81 | return(&md4_md); | ||
82 | } | ||
83 | #endif | ||
diff --git a/src/lib/libcrypto/evp/m_md5.c b/src/lib/libcrypto/evp/m_md5.c deleted file mode 100644 index 9fc9530127..0000000000 --- a/src/lib/libcrypto/evp/m_md5.c +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | /* crypto/evp/m_md5.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_MD5 | ||
60 | #include <stdio.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/x509.h> | ||
65 | |||
66 | static EVP_MD md5_md= | ||
67 | { | ||
68 | NID_md5, | ||
69 | NID_md5WithRSAEncryption, | ||
70 | MD5_DIGEST_LENGTH, | ||
71 | MD5_Init, | ||
72 | MD5_Update, | ||
73 | MD5_Final, | ||
74 | EVP_PKEY_RSA_method, | ||
75 | MD5_CBLOCK, | ||
76 | sizeof(EVP_MD *)+sizeof(MD5_CTX), | ||
77 | }; | ||
78 | |||
79 | EVP_MD *EVP_md5(void) | ||
80 | { | ||
81 | return(&md5_md); | ||
82 | } | ||
83 | #endif | ||
diff --git a/src/lib/libcrypto/evp/m_null.c b/src/lib/libcrypto/evp/m_null.c deleted file mode 100644 index e2dadf3dab..0000000000 --- a/src/lib/libcrypto/evp/m_null.c +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | /* crypto/evp/m_null.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/x509.h> | ||
64 | |||
65 | static void function(void) | ||
66 | { | ||
67 | } | ||
68 | |||
69 | static EVP_MD null_md= | ||
70 | { | ||
71 | NID_undef, | ||
72 | NID_undef, | ||
73 | 0, | ||
74 | function, | ||
75 | function, | ||
76 | function, | ||
77 | |||
78 | EVP_PKEY_NULL_method, | ||
79 | 0, | ||
80 | sizeof(EVP_MD *), | ||
81 | }; | ||
82 | |||
83 | EVP_MD *EVP_md_null(void) | ||
84 | { | ||
85 | return(&null_md); | ||
86 | } | ||
87 | |||
88 | |||
diff --git a/src/lib/libcrypto/evp/m_ripemd.c b/src/lib/libcrypto/evp/m_ripemd.c deleted file mode 100644 index 3d781a4e8d..0000000000 --- a/src/lib/libcrypto/evp/m_ripemd.c +++ /dev/null | |||
@@ -1,84 +0,0 @@ | |||
1 | /* crypto/evp/m_ripemd.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_RIPEMD | ||
60 | #include <stdio.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/ripemd.h> | ||
63 | #include <openssl/evp.h> | ||
64 | #include <openssl/objects.h> | ||
65 | #include <openssl/x509.h> | ||
66 | |||
67 | static EVP_MD ripemd160_md= | ||
68 | { | ||
69 | NID_ripemd160, | ||
70 | NID_ripemd160WithRSA, | ||
71 | RIPEMD160_DIGEST_LENGTH, | ||
72 | RIPEMD160_Init, | ||
73 | RIPEMD160_Update, | ||
74 | RIPEMD160_Final, | ||
75 | EVP_PKEY_RSA_method, | ||
76 | RIPEMD160_CBLOCK, | ||
77 | sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX), | ||
78 | }; | ||
79 | |||
80 | EVP_MD *EVP_ripemd160(void) | ||
81 | { | ||
82 | return(&ripemd160_md); | ||
83 | } | ||
84 | #endif | ||
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c deleted file mode 100644 index 57a1ab0cce..0000000000 --- a/src/lib/libcrypto/evp/m_sha1.c +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | /* crypto/evp/m_sha1.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_SHA | ||
60 | #include <stdio.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/x509.h> | ||
65 | |||
66 | static EVP_MD sha1_md= | ||
67 | { | ||
68 | NID_sha1, | ||
69 | NID_sha1WithRSAEncryption, | ||
70 | SHA_DIGEST_LENGTH, | ||
71 | SHA1_Init, | ||
72 | SHA1_Update, | ||
73 | SHA1_Final, | ||
74 | EVP_PKEY_RSA_method, | ||
75 | SHA_CBLOCK, | ||
76 | sizeof(EVP_MD *)+sizeof(SHA_CTX), | ||
77 | }; | ||
78 | |||
79 | EVP_MD *EVP_sha1(void) | ||
80 | { | ||
81 | return(&sha1_md); | ||
82 | } | ||
83 | #endif | ||
diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c deleted file mode 100644 index 620f43feaa..0000000000 --- a/src/lib/libcrypto/evp/names.c +++ /dev/null | |||
@@ -1,123 +0,0 @@ | |||
1 | /* crypto/evp/names.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/x509.h> | ||
64 | |||
65 | int EVP_add_cipher(EVP_CIPHER *c) | ||
66 | { | ||
67 | int r; | ||
68 | |||
69 | r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c); | ||
70 | if (r == 0) return(0); | ||
71 | r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c); | ||
72 | return(r); | ||
73 | } | ||
74 | |||
75 | int EVP_add_digest(EVP_MD *md) | ||
76 | { | ||
77 | int r; | ||
78 | const char *name; | ||
79 | |||
80 | name=OBJ_nid2sn(md->type); | ||
81 | r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(char *)md); | ||
82 | if (r == 0) return(0); | ||
83 | r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(char *)md); | ||
84 | if (r == 0) return(0); | ||
85 | |||
86 | if (md->type != md->pkey_type) | ||
87 | { | ||
88 | r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type), | ||
89 | OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name); | ||
90 | if (r == 0) return(0); | ||
91 | r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type), | ||
92 | OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name); | ||
93 | } | ||
94 | return(r); | ||
95 | } | ||
96 | |||
97 | const EVP_CIPHER *EVP_get_cipherbyname(const char *name) | ||
98 | { | ||
99 | const EVP_CIPHER *cp; | ||
100 | |||
101 | cp=(const EVP_CIPHER *)OBJ_NAME_get(name,OBJ_NAME_TYPE_CIPHER_METH); | ||
102 | return(cp); | ||
103 | } | ||
104 | |||
105 | const EVP_MD *EVP_get_digestbyname(const char *name) | ||
106 | { | ||
107 | const EVP_MD *cp; | ||
108 | |||
109 | cp=(const EVP_MD *)OBJ_NAME_get(name,OBJ_NAME_TYPE_MD_METH); | ||
110 | return(cp); | ||
111 | } | ||
112 | |||
113 | void EVP_cleanup(void) | ||
114 | { | ||
115 | OBJ_NAME_cleanup(OBJ_NAME_TYPE_CIPHER_METH); | ||
116 | OBJ_NAME_cleanup(OBJ_NAME_TYPE_MD_METH); | ||
117 | /* The above calls will only clean out the contents of the name | ||
118 | hash table, but not the hash table itself. The following line | ||
119 | does that part. -- Richard Levitte */ | ||
120 | OBJ_NAME_cleanup(-1); | ||
121 | |||
122 | EVP_PBE_cleanup(); | ||
123 | } | ||
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c deleted file mode 100644 index 6bfa2c5acb..0000000000 --- a/src/lib/libcrypto/evp/p5_crpt.c +++ /dev/null | |||
@@ -1,149 +0,0 @@ | |||
1 | /* p5_crpt.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <stdlib.h> | ||
61 | #include <openssl/x509.h> | ||
62 | #include <openssl/evp.h> | ||
63 | #include "cryptlib.h" | ||
64 | |||
65 | /* PKCS#5 v1.5 compatible PBE functions: see PKCS#5 v2.0 for more info. | ||
66 | */ | ||
67 | |||
68 | void PKCS5_PBE_add(void) | ||
69 | { | ||
70 | #ifndef NO_DES | ||
71 | # ifndef NO_MD5 | ||
72 | EVP_PBE_alg_add(NID_pbeWithMD5AndDES_CBC, EVP_des_cbc(), EVP_md5(), | ||
73 | PKCS5_PBE_keyivgen); | ||
74 | # endif | ||
75 | # ifndef NO_MD2 | ||
76 | EVP_PBE_alg_add(NID_pbeWithMD2AndDES_CBC, EVP_des_cbc(), EVP_md2(), | ||
77 | PKCS5_PBE_keyivgen); | ||
78 | # endif | ||
79 | # ifndef NO_SHA | ||
80 | EVP_PBE_alg_add(NID_pbeWithSHA1AndDES_CBC, EVP_des_cbc(), EVP_sha1(), | ||
81 | PKCS5_PBE_keyivgen); | ||
82 | # endif | ||
83 | #endif | ||
84 | #ifndef NO_RC2 | ||
85 | # ifndef NO_MD5 | ||
86 | EVP_PBE_alg_add(NID_pbeWithMD5AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md5(), | ||
87 | PKCS5_PBE_keyivgen); | ||
88 | # endif | ||
89 | # ifndef NO_MD2 | ||
90 | EVP_PBE_alg_add(NID_pbeWithMD2AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md2(), | ||
91 | PKCS5_PBE_keyivgen); | ||
92 | # endif | ||
93 | # ifndef NO_SHA | ||
94 | EVP_PBE_alg_add(NID_pbeWithSHA1AndRC2_CBC, EVP_rc2_64_cbc(), EVP_sha1(), | ||
95 | PKCS5_PBE_keyivgen); | ||
96 | # endif | ||
97 | #endif | ||
98 | #ifndef NO_HMAC | ||
99 | EVP_PBE_alg_add(NID_pbes2, NULL, NULL, PKCS5_v2_PBE_keyivgen); | ||
100 | #endif | ||
101 | } | ||
102 | |||
103 | int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen, | ||
104 | ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md, | ||
105 | int en_de) | ||
106 | { | ||
107 | EVP_MD_CTX ctx; | ||
108 | unsigned char md_tmp[EVP_MAX_MD_SIZE]; | ||
109 | unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH]; | ||
110 | int i; | ||
111 | PBEPARAM *pbe; | ||
112 | int saltlen, iter; | ||
113 | unsigned char *salt, *pbuf; | ||
114 | |||
115 | /* Extract useful info from parameter */ | ||
116 | pbuf = param->value.sequence->data; | ||
117 | if (!param || (param->type != V_ASN1_SEQUENCE) || | ||
118 | !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) { | ||
119 | EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR); | ||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | if (!pbe->iter) iter = 1; | ||
124 | else iter = ASN1_INTEGER_get (pbe->iter); | ||
125 | salt = pbe->salt->data; | ||
126 | saltlen = pbe->salt->length; | ||
127 | |||
128 | if(!pass) passlen = 0; | ||
129 | else if(passlen == -1) passlen = strlen(pass); | ||
130 | |||
131 | EVP_DigestInit (&ctx, md); | ||
132 | EVP_DigestUpdate (&ctx, pass, passlen); | ||
133 | EVP_DigestUpdate (&ctx, salt, saltlen); | ||
134 | PBEPARAM_free(pbe); | ||
135 | EVP_DigestFinal (&ctx, md_tmp, NULL); | ||
136 | for (i = 1; i < iter; i++) { | ||
137 | EVP_DigestInit(&ctx, md); | ||
138 | EVP_DigestUpdate(&ctx, md_tmp, EVP_MD_size(md)); | ||
139 | EVP_DigestFinal (&ctx, md_tmp, NULL); | ||
140 | } | ||
141 | memcpy (key, md_tmp, EVP_CIPHER_key_length(cipher)); | ||
142 | memcpy (iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)), | ||
143 | EVP_CIPHER_iv_length(cipher)); | ||
144 | EVP_CipherInit(cctx, cipher, key, iv, en_de); | ||
145 | memset(md_tmp, 0, EVP_MAX_MD_SIZE); | ||
146 | memset(key, 0, EVP_MAX_KEY_LENGTH); | ||
147 | memset(iv, 0, EVP_MAX_IV_LENGTH); | ||
148 | return 1; | ||
149 | } | ||
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c deleted file mode 100644 index 717fad68ca..0000000000 --- a/src/lib/libcrypto/evp/p5_crpt2.c +++ /dev/null | |||
@@ -1,248 +0,0 @@ | |||
1 | /* p5_crpt2.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | #if !defined(NO_HMAC) && !defined(NO_SHA) | ||
59 | #include <stdio.h> | ||
60 | #include <stdlib.h> | ||
61 | #include <openssl/x509.h> | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/hmac.h> | ||
64 | #include "cryptlib.h" | ||
65 | |||
66 | /* set this to print out info about the keygen algorithm */ | ||
67 | /* #define DEBUG_PKCS5V2 */ | ||
68 | |||
69 | #ifdef DEBUG_PKCS5V2 | ||
70 | static void h__dump (const unsigned char *p, int len); | ||
71 | #endif | ||
72 | |||
73 | /* This is an implementation of PKCS#5 v2.0 password based encryption key | ||
74 | * derivation function PBKDF2 using the only currently defined function HMAC | ||
75 | * with SHA1. Verified against test vectors posted by Peter Gutmann | ||
76 | * <pgut001@cs.auckland.ac.nz> to the PKCS-TNG <pkcs-tng@rsa.com> mailing list. | ||
77 | */ | ||
78 | |||
79 | int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, | ||
80 | unsigned char *salt, int saltlen, int iter, | ||
81 | int keylen, unsigned char *out) | ||
82 | { | ||
83 | unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4]; | ||
84 | int cplen, j, k, tkeylen; | ||
85 | unsigned long i = 1; | ||
86 | HMAC_CTX hctx; | ||
87 | p = out; | ||
88 | tkeylen = keylen; | ||
89 | if(!pass) passlen = 0; | ||
90 | else if(passlen == -1) passlen = strlen(pass); | ||
91 | while(tkeylen) { | ||
92 | if(tkeylen > SHA_DIGEST_LENGTH) cplen = SHA_DIGEST_LENGTH; | ||
93 | else cplen = tkeylen; | ||
94 | /* We are unlikely to ever use more than 256 blocks (5120 bits!) | ||
95 | * but just in case... | ||
96 | */ | ||
97 | itmp[0] = (unsigned char)((i >> 24) & 0xff); | ||
98 | itmp[1] = (unsigned char)((i >> 16) & 0xff); | ||
99 | itmp[2] = (unsigned char)((i >> 8) & 0xff); | ||
100 | itmp[3] = (unsigned char)(i & 0xff); | ||
101 | HMAC_Init(&hctx, pass, passlen, EVP_sha1()); | ||
102 | HMAC_Update(&hctx, salt, saltlen); | ||
103 | HMAC_Update(&hctx, itmp, 4); | ||
104 | HMAC_Final(&hctx, digtmp, NULL); | ||
105 | memcpy(p, digtmp, cplen); | ||
106 | for(j = 1; j < iter; j++) { | ||
107 | HMAC(EVP_sha1(), pass, passlen, | ||
108 | digtmp, SHA_DIGEST_LENGTH, digtmp, NULL); | ||
109 | for(k = 0; k < cplen; k++) p[k] ^= digtmp[k]; | ||
110 | } | ||
111 | tkeylen-= cplen; | ||
112 | i++; | ||
113 | p+= cplen; | ||
114 | } | ||
115 | HMAC_cleanup(&hctx); | ||
116 | #ifdef DEBUG_PKCS5V2 | ||
117 | fprintf(stderr, "Password:\n"); | ||
118 | h__dump (pass, passlen); | ||
119 | fprintf(stderr, "Salt:\n"); | ||
120 | h__dump (salt, saltlen); | ||
121 | fprintf(stderr, "Iteration count %d\n", iter); | ||
122 | fprintf(stderr, "Key:\n"); | ||
123 | h__dump (out, keylen); | ||
124 | #endif | ||
125 | return 1; | ||
126 | } | ||
127 | |||
128 | #ifdef DO_TEST | ||
129 | main() | ||
130 | { | ||
131 | unsigned char out[4]; | ||
132 | unsigned char salt[] = {0x12, 0x34, 0x56, 0x78}; | ||
133 | PKCS5_PBKDF2_HMAC_SHA1("password", -1, salt, 4, 5, 4, out); | ||
134 | fprintf(stderr, "Out %02X %02X %02X %02X\n", | ||
135 | out[0], out[1], out[2], out[3]); | ||
136 | } | ||
137 | |||
138 | #endif | ||
139 | |||
140 | /* Now the key derivation function itself. This is a bit evil because | ||
141 | * it has to check the ASN1 parameters are valid: and there are quite a | ||
142 | * few of them... | ||
143 | */ | ||
144 | |||
145 | int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | ||
146 | ASN1_TYPE *param, EVP_CIPHER *c, EVP_MD *md, | ||
147 | int en_de) | ||
148 | { | ||
149 | unsigned char *pbuf, *salt, key[EVP_MAX_KEY_LENGTH]; | ||
150 | int saltlen, keylen, iter, plen; | ||
151 | PBE2PARAM *pbe2 = NULL; | ||
152 | const EVP_CIPHER *cipher; | ||
153 | PBKDF2PARAM *kdf = NULL; | ||
154 | |||
155 | pbuf = param->value.sequence->data; | ||
156 | plen = param->value.sequence->length; | ||
157 | if(!param || (param->type != V_ASN1_SEQUENCE) || | ||
158 | !(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) { | ||
159 | EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR); | ||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | /* See if we recognise the key derivation function */ | ||
164 | |||
165 | if(OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) { | ||
166 | EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, | ||
167 | EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION); | ||
168 | goto err; | ||
169 | } | ||
170 | |||
171 | /* lets see if we recognise the encryption algorithm. | ||
172 | */ | ||
173 | |||
174 | cipher = EVP_get_cipherbyname( | ||
175 | OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm))); | ||
176 | |||
177 | if(!cipher) { | ||
178 | EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, | ||
179 | EVP_R_UNSUPPORTED_CIPHER); | ||
180 | goto err; | ||
181 | } | ||
182 | |||
183 | /* Fixup cipher based on AlgorithmIdentifier */ | ||
184 | EVP_CipherInit(ctx, cipher, NULL, NULL, en_de); | ||
185 | if(EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) { | ||
186 | EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, | ||
187 | EVP_R_CIPHER_PARAMETER_ERROR); | ||
188 | goto err; | ||
189 | } | ||
190 | keylen = EVP_CIPHER_CTX_key_length(ctx); | ||
191 | |||
192 | /* Now decode key derivation function */ | ||
193 | |||
194 | pbuf = pbe2->keyfunc->parameter->value.sequence->data; | ||
195 | plen = pbe2->keyfunc->parameter->value.sequence->length; | ||
196 | if(!pbe2->keyfunc->parameter || | ||
197 | (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE) || | ||
198 | !(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) { | ||
199 | EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR); | ||
200 | goto err; | ||
201 | } | ||
202 | |||
203 | PBE2PARAM_free(pbe2); | ||
204 | pbe2 = NULL; | ||
205 | |||
206 | /* Now check the parameters of the kdf */ | ||
207 | |||
208 | if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != keylen)){ | ||
209 | EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, | ||
210 | EVP_R_UNSUPPORTED_KEYLENGTH); | ||
211 | goto err; | ||
212 | } | ||
213 | |||
214 | if(kdf->prf && (OBJ_obj2nid(kdf->prf->algorithm) != NID_hmacWithSHA1)) { | ||
215 | EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF); | ||
216 | goto err; | ||
217 | } | ||
218 | |||
219 | if(kdf->salt->type != V_ASN1_OCTET_STRING) { | ||
220 | EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, | ||
221 | EVP_R_UNSUPPORTED_SALT_TYPE); | ||
222 | goto err; | ||
223 | } | ||
224 | |||
225 | /* it seems that its all OK */ | ||
226 | salt = kdf->salt->value.octet_string->data; | ||
227 | saltlen = kdf->salt->value.octet_string->length; | ||
228 | iter = ASN1_INTEGER_get(kdf->iter); | ||
229 | PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key); | ||
230 | EVP_CipherInit(ctx, NULL, key, NULL, en_de); | ||
231 | memset(key, 0, keylen); | ||
232 | PBKDF2PARAM_free(kdf); | ||
233 | return 1; | ||
234 | |||
235 | err: | ||
236 | PBE2PARAM_free(pbe2); | ||
237 | PBKDF2PARAM_free(kdf); | ||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | #ifdef DEBUG_PKCS5V2 | ||
242 | static void h__dump (const unsigned char *p, int len) | ||
243 | { | ||
244 | for (; len --; p++) fprintf(stderr, "%02X ", *p); | ||
245 | fprintf(stderr, "\n"); | ||
246 | } | ||
247 | #endif | ||
248 | #endif | ||
diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c deleted file mode 100644 index 57b5daa453..0000000000 --- a/src/lib/libcrypto/evp/p_dec.c +++ /dev/null | |||
@@ -1,87 +0,0 @@ | |||
1 | /* crypto/evp/p_dec.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/rand.h> | ||
62 | #ifndef NO_RSA | ||
63 | #include <openssl/rsa.h> | ||
64 | #endif | ||
65 | #include <openssl/evp.h> | ||
66 | #include <openssl/objects.h> | ||
67 | #include <openssl/x509.h> | ||
68 | |||
69 | int EVP_PKEY_decrypt(unsigned char *key, unsigned char *ek, int ekl, | ||
70 | EVP_PKEY *priv) | ||
71 | { | ||
72 | int ret= -1; | ||
73 | |||
74 | #ifndef NO_RSA | ||
75 | if (priv->type != EVP_PKEY_RSA) | ||
76 | { | ||
77 | #endif | ||
78 | EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA); | ||
79 | #ifndef NO_RSA | ||
80 | goto err; | ||
81 | } | ||
82 | |||
83 | ret=RSA_private_decrypt(ekl,ek,key,priv->pkey.rsa,RSA_PKCS1_PADDING); | ||
84 | err: | ||
85 | #endif | ||
86 | return(ret); | ||
87 | } | ||
diff --git a/src/lib/libcrypto/evp/p_enc.c b/src/lib/libcrypto/evp/p_enc.c deleted file mode 100644 index 4cf6acaf5d..0000000000 --- a/src/lib/libcrypto/evp/p_enc.c +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | /* crypto/evp/p_enc.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/rand.h> | ||
62 | #ifndef NO_RSA | ||
63 | #include <openssl/rsa.h> | ||
64 | #endif | ||
65 | #include <openssl/evp.h> | ||
66 | #include <openssl/objects.h> | ||
67 | #include <openssl/x509.h> | ||
68 | |||
69 | int EVP_PKEY_encrypt(unsigned char *ek, unsigned char *key, int key_len, | ||
70 | EVP_PKEY *pubk) | ||
71 | { | ||
72 | int ret=0; | ||
73 | |||
74 | #ifndef NO_RSA | ||
75 | if (pubk->type != EVP_PKEY_RSA) | ||
76 | { | ||
77 | #endif | ||
78 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA); | ||
79 | #ifndef NO_RSA | ||
80 | goto err; | ||
81 | } | ||
82 | ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING); | ||
83 | err: | ||
84 | #endif | ||
85 | return(ret); | ||
86 | } | ||
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c deleted file mode 100644 index 62398ed74d..0000000000 --- a/src/lib/libcrypto/evp/p_lib.c +++ /dev/null | |||
@@ -1,333 +0,0 @@ | |||
1 | /* crypto/evp/p_lib.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/objects.h> | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/asn1_mac.h> | ||
64 | #include <openssl/x509.h> | ||
65 | |||
66 | static void EVP_PKEY_free_it(EVP_PKEY *x); | ||
67 | int EVP_PKEY_bits(EVP_PKEY *pkey) | ||
68 | { | ||
69 | #ifndef NO_RSA | ||
70 | if (pkey->type == EVP_PKEY_RSA) | ||
71 | return(BN_num_bits(pkey->pkey.rsa->n)); | ||
72 | else | ||
73 | #endif | ||
74 | #ifndef NO_DSA | ||
75 | if (pkey->type == EVP_PKEY_DSA) | ||
76 | return(BN_num_bits(pkey->pkey.dsa->p)); | ||
77 | #endif | ||
78 | return(0); | ||
79 | } | ||
80 | |||
81 | int EVP_PKEY_size(EVP_PKEY *pkey) | ||
82 | { | ||
83 | if (pkey == NULL) | ||
84 | return(0); | ||
85 | #ifndef NO_RSA | ||
86 | if (pkey->type == EVP_PKEY_RSA) | ||
87 | return(RSA_size(pkey->pkey.rsa)); | ||
88 | else | ||
89 | #endif | ||
90 | #ifndef NO_DSA | ||
91 | if (pkey->type == EVP_PKEY_DSA) | ||
92 | return(DSA_size(pkey->pkey.dsa)); | ||
93 | #endif | ||
94 | return(0); | ||
95 | } | ||
96 | |||
97 | int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode) | ||
98 | { | ||
99 | #ifndef NO_DSA | ||
100 | if (pkey->type == EVP_PKEY_DSA) | ||
101 | { | ||
102 | int ret=pkey->save_parameters=mode; | ||
103 | |||
104 | if (mode >= 0) | ||
105 | pkey->save_parameters=mode; | ||
106 | return(ret); | ||
107 | } | ||
108 | #endif | ||
109 | return(0); | ||
110 | } | ||
111 | |||
112 | int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from) | ||
113 | { | ||
114 | if (to->type != from->type) | ||
115 | { | ||
116 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES); | ||
117 | goto err; | ||
118 | } | ||
119 | |||
120 | if (EVP_PKEY_missing_parameters(from)) | ||
121 | { | ||
122 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS); | ||
123 | goto err; | ||
124 | } | ||
125 | #ifndef NO_DSA | ||
126 | if (to->type == EVP_PKEY_DSA) | ||
127 | { | ||
128 | BIGNUM *a; | ||
129 | |||
130 | if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err; | ||
131 | if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p); | ||
132 | to->pkey.dsa->p=a; | ||
133 | |||
134 | if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err; | ||
135 | if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q); | ||
136 | to->pkey.dsa->q=a; | ||
137 | |||
138 | if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err; | ||
139 | if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g); | ||
140 | to->pkey.dsa->g=a; | ||
141 | } | ||
142 | #endif | ||
143 | return(1); | ||
144 | err: | ||
145 | return(0); | ||
146 | } | ||
147 | |||
148 | int EVP_PKEY_missing_parameters(EVP_PKEY *pkey) | ||
149 | { | ||
150 | #ifndef NO_DSA | ||
151 | if (pkey->type == EVP_PKEY_DSA) | ||
152 | { | ||
153 | DSA *dsa; | ||
154 | |||
155 | dsa=pkey->pkey.dsa; | ||
156 | if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL)) | ||
157 | return(1); | ||
158 | } | ||
159 | #endif | ||
160 | return(0); | ||
161 | } | ||
162 | |||
163 | int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b) | ||
164 | { | ||
165 | #ifndef NO_DSA | ||
166 | if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA)) | ||
167 | { | ||
168 | if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) || | ||
169 | BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) || | ||
170 | BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g)) | ||
171 | return(0); | ||
172 | else | ||
173 | return(1); | ||
174 | } | ||
175 | #endif | ||
176 | return(-1); | ||
177 | } | ||
178 | |||
179 | EVP_PKEY *EVP_PKEY_new(void) | ||
180 | { | ||
181 | EVP_PKEY *ret; | ||
182 | |||
183 | ret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY)); | ||
184 | if (ret == NULL) | ||
185 | { | ||
186 | EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE); | ||
187 | return(NULL); | ||
188 | } | ||
189 | ret->type=EVP_PKEY_NONE; | ||
190 | ret->references=1; | ||
191 | ret->pkey.ptr=NULL; | ||
192 | ret->attributes=NULL; | ||
193 | ret->save_parameters=1; | ||
194 | return(ret); | ||
195 | } | ||
196 | |||
197 | int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key) | ||
198 | { | ||
199 | if (pkey == NULL) return(0); | ||
200 | if (pkey->pkey.ptr != NULL) | ||
201 | EVP_PKEY_free_it(pkey); | ||
202 | pkey->type=EVP_PKEY_type(type); | ||
203 | pkey->save_type=type; | ||
204 | pkey->pkey.ptr=key; | ||
205 | return(key != NULL); | ||
206 | } | ||
207 | |||
208 | #ifndef NO_RSA | ||
209 | int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key) | ||
210 | { | ||
211 | int ret = EVP_PKEY_assign_RSA(pkey, key); | ||
212 | if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_RSA); | ||
213 | return ret; | ||
214 | } | ||
215 | |||
216 | RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey) | ||
217 | { | ||
218 | if(pkey->type != EVP_PKEY_RSA) { | ||
219 | EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY); | ||
220 | return NULL; | ||
221 | } | ||
222 | CRYPTO_add(&pkey->pkey.rsa->references, 1, CRYPTO_LOCK_RSA); | ||
223 | return pkey->pkey.rsa; | ||
224 | } | ||
225 | #endif | ||
226 | |||
227 | #ifndef NO_DSA | ||
228 | int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key) | ||
229 | { | ||
230 | int ret = EVP_PKEY_assign_DSA(pkey, key); | ||
231 | if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_DSA); | ||
232 | return ret; | ||
233 | } | ||
234 | |||
235 | DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey) | ||
236 | { | ||
237 | if(pkey->type != EVP_PKEY_DSA) { | ||
238 | EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY); | ||
239 | return NULL; | ||
240 | } | ||
241 | CRYPTO_add(&pkey->pkey.dsa->references, 1, CRYPTO_LOCK_DSA); | ||
242 | return pkey->pkey.dsa; | ||
243 | } | ||
244 | #endif | ||
245 | |||
246 | #ifndef NO_DH | ||
247 | |||
248 | int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key) | ||
249 | { | ||
250 | int ret = EVP_PKEY_assign_DH(pkey, key); | ||
251 | if(ret) CRYPTO_add(&key->references, 1, CRYPTO_LOCK_DH); | ||
252 | return ret; | ||
253 | } | ||
254 | |||
255 | DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey) | ||
256 | { | ||
257 | if(pkey->type != EVP_PKEY_DH) { | ||
258 | EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY); | ||
259 | return NULL; | ||
260 | } | ||
261 | CRYPTO_add(&pkey->pkey.dh->references, 1, CRYPTO_LOCK_DH); | ||
262 | return pkey->pkey.dh; | ||
263 | } | ||
264 | #endif | ||
265 | |||
266 | int EVP_PKEY_type(int type) | ||
267 | { | ||
268 | switch (type) | ||
269 | { | ||
270 | case EVP_PKEY_RSA: | ||
271 | case EVP_PKEY_RSA2: | ||
272 | return(EVP_PKEY_RSA); | ||
273 | case EVP_PKEY_DSA: | ||
274 | case EVP_PKEY_DSA1: | ||
275 | case EVP_PKEY_DSA2: | ||
276 | case EVP_PKEY_DSA3: | ||
277 | case EVP_PKEY_DSA4: | ||
278 | return(EVP_PKEY_DSA); | ||
279 | case EVP_PKEY_DH: | ||
280 | return(EVP_PKEY_DH); | ||
281 | default: | ||
282 | return(NID_undef); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | void EVP_PKEY_free(EVP_PKEY *x) | ||
287 | { | ||
288 | int i; | ||
289 | |||
290 | if (x == NULL) return; | ||
291 | |||
292 | i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY); | ||
293 | #ifdef REF_PRINT | ||
294 | REF_PRINT("EVP_PKEY",x); | ||
295 | #endif | ||
296 | if (i > 0) return; | ||
297 | #ifdef REF_CHECK | ||
298 | if (i < 0) | ||
299 | { | ||
300 | fprintf(stderr,"EVP_PKEY_free, bad reference count\n"); | ||
301 | abort(); | ||
302 | } | ||
303 | #endif | ||
304 | EVP_PKEY_free_it(x); | ||
305 | OPENSSL_free(x); | ||
306 | } | ||
307 | |||
308 | static void EVP_PKEY_free_it(EVP_PKEY *x) | ||
309 | { | ||
310 | switch (x->type) | ||
311 | { | ||
312 | #ifndef NO_RSA | ||
313 | case EVP_PKEY_RSA: | ||
314 | case EVP_PKEY_RSA2: | ||
315 | RSA_free(x->pkey.rsa); | ||
316 | break; | ||
317 | #endif | ||
318 | #ifndef NO_DSA | ||
319 | case EVP_PKEY_DSA: | ||
320 | case EVP_PKEY_DSA2: | ||
321 | case EVP_PKEY_DSA3: | ||
322 | case EVP_PKEY_DSA4: | ||
323 | DSA_free(x->pkey.dsa); | ||
324 | break; | ||
325 | #endif | ||
326 | #ifndef NO_DH | ||
327 | case EVP_PKEY_DH: | ||
328 | DH_free(x->pkey.dh); | ||
329 | break; | ||
330 | #endif | ||
331 | } | ||
332 | } | ||
333 | |||
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c deleted file mode 100644 index 2760c00fec..0000000000 --- a/src/lib/libcrypto/evp/p_open.c +++ /dev/null | |||
@@ -1,123 +0,0 @@ | |||
1 | /* crypto/evp/p_open.c */ | ||
2 | /* Copyright (C) 1995-1998 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 NO_RSA | ||
60 | #include <stdio.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/x509.h> | ||
65 | |||
66 | int EVP_OpenInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char *ek, | ||
67 | int ekl, unsigned char *iv, EVP_PKEY *priv) | ||
68 | { | ||
69 | unsigned char *key=NULL; | ||
70 | int i,size=0,ret=0; | ||
71 | |||
72 | if(type) { | ||
73 | EVP_CIPHER_CTX_init(ctx); | ||
74 | if(!EVP_DecryptInit(ctx,type,NULL,NULL)) return 0; | ||
75 | } | ||
76 | |||
77 | if(!priv) return 1; | ||
78 | |||
79 | if (priv->type != EVP_PKEY_RSA) | ||
80 | { | ||
81 | EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA); | ||
82 | goto err; | ||
83 | } | ||
84 | |||
85 | size=RSA_size(priv->pkey.rsa); | ||
86 | key=(unsigned char *)OPENSSL_malloc(size+2); | ||
87 | if (key == NULL) | ||
88 | { | ||
89 | /* ERROR */ | ||
90 | EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE); | ||
91 | goto err; | ||
92 | } | ||
93 | |||
94 | i=EVP_PKEY_decrypt(key,ek,ekl,priv); | ||
95 | if ((i <= 0) || !EVP_CIPHER_CTX_set_key_length(ctx, i)) | ||
96 | { | ||
97 | /* ERROR */ | ||
98 | goto err; | ||
99 | } | ||
100 | if(!EVP_DecryptInit(ctx,NULL,key,iv)) goto err; | ||
101 | |||
102 | ret=1; | ||
103 | err: | ||
104 | if (key != NULL) memset(key,0,size); | ||
105 | OPENSSL_free(key); | ||
106 | return(ret); | ||
107 | } | ||
108 | |||
109 | int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | ||
110 | { | ||
111 | int i; | ||
112 | |||
113 | i=EVP_DecryptFinal(ctx,out,outl); | ||
114 | EVP_DecryptInit(ctx,NULL,NULL,NULL); | ||
115 | return(i); | ||
116 | } | ||
117 | #else /* !NO_RSA */ | ||
118 | |||
119 | # ifdef PEDANTIC | ||
120 | static void *dummy=&dummy; | ||
121 | # endif | ||
122 | |||
123 | #endif | ||
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c deleted file mode 100644 index 2fd1d7e0c2..0000000000 --- a/src/lib/libcrypto/evp/p_seal.c +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | /* crypto/evp/p_seal.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/rand.h> | ||
62 | #ifndef NO_RSA | ||
63 | #include <openssl/rsa.h> | ||
64 | #endif | ||
65 | #include <openssl/evp.h> | ||
66 | #include <openssl/objects.h> | ||
67 | #include <openssl/x509.h> | ||
68 | |||
69 | int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek, | ||
70 | int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk) | ||
71 | { | ||
72 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
73 | int i; | ||
74 | |||
75 | if(type) { | ||
76 | EVP_CIPHER_CTX_init(ctx); | ||
77 | if(!EVP_EncryptInit(ctx,type,NULL,NULL)) return 0; | ||
78 | } | ||
79 | if (npubk <= 0) return(0); | ||
80 | if (RAND_bytes(key,EVP_MAX_KEY_LENGTH) <= 0) | ||
81 | return(0); | ||
82 | if (EVP_CIPHER_CTX_iv_length(ctx)) | ||
83 | RAND_pseudo_bytes(iv,EVP_CIPHER_CTX_iv_length(ctx)); | ||
84 | |||
85 | if(!EVP_EncryptInit(ctx,NULL,key,iv)) return 0; | ||
86 | |||
87 | for (i=0; i<npubk; i++) | ||
88 | { | ||
89 | ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_CTX_key_length(ctx), | ||
90 | pubk[i]); | ||
91 | if (ekl[i] <= 0) return(-1); | ||
92 | } | ||
93 | return(npubk); | ||
94 | } | ||
95 | |||
96 | /* MACRO | ||
97 | void EVP_SealUpdate(ctx,out,outl,in,inl) | ||
98 | EVP_CIPHER_CTX *ctx; | ||
99 | unsigned char *out; | ||
100 | int *outl; | ||
101 | unsigned char *in; | ||
102 | int inl; | ||
103 | { | ||
104 | EVP_EncryptUpdate(ctx,out,outl,in,inl); | ||
105 | } | ||
106 | */ | ||
107 | |||
108 | void EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | ||
109 | { | ||
110 | EVP_EncryptFinal(ctx,out,outl); | ||
111 | EVP_EncryptInit(ctx,NULL,NULL,NULL); | ||
112 | } | ||
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c deleted file mode 100644 index 1fa32ac17e..0000000000 --- a/src/lib/libcrypto/evp/p_sign.c +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | /* crypto/evp/p_sign.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/x509.h> | ||
64 | |||
65 | #ifdef undef | ||
66 | void EVP_SignInit(EVP_MD_CTX *ctx, EVP_MD *type) | ||
67 | { | ||
68 | EVP_DigestInit(ctx,type); | ||
69 | } | ||
70 | |||
71 | void EVP_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data, | ||
72 | unsigned int count) | ||
73 | { | ||
74 | EVP_DigestUpdate(ctx,data,count); | ||
75 | } | ||
76 | #endif | ||
77 | |||
78 | int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, | ||
79 | EVP_PKEY *pkey) | ||
80 | { | ||
81 | unsigned char m[EVP_MAX_MD_SIZE]; | ||
82 | unsigned int m_len; | ||
83 | int i,ok=0,v; | ||
84 | MS_STATIC EVP_MD_CTX tmp_ctx; | ||
85 | |||
86 | *siglen=0; | ||
87 | EVP_MD_CTX_copy(&tmp_ctx,ctx); | ||
88 | EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); | ||
89 | for (i=0; i<4; i++) | ||
90 | { | ||
91 | v=ctx->digest->required_pkey_type[i]; | ||
92 | if (v == 0) break; | ||
93 | if (pkey->type == v) | ||
94 | { | ||
95 | ok=1; | ||
96 | break; | ||
97 | } | ||
98 | } | ||
99 | if (!ok) | ||
100 | { | ||
101 | EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); | ||
102 | return(0); | ||
103 | } | ||
104 | if (ctx->digest->sign == NULL) | ||
105 | { | ||
106 | EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED); | ||
107 | return(0); | ||
108 | } | ||
109 | return(ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen, | ||
110 | pkey->pkey.ptr)); | ||
111 | } | ||
112 | |||
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c deleted file mode 100644 index dcb54f3abb..0000000000 --- a/src/lib/libcrypto/evp/p_verify.c +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | /* crypto/evp/p_verify.c */ | ||
2 | /* Copyright (C) 1995-1998 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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/x509.h> | ||
64 | |||
65 | int EVP_VerifyFinal(EVP_MD_CTX *ctx, unsigned char *sigbuf, | ||
66 | unsigned int siglen, EVP_PKEY *pkey) | ||
67 | { | ||
68 | unsigned char m[EVP_MAX_MD_SIZE]; | ||
69 | unsigned int m_len; | ||
70 | int i,ok=0,v; | ||
71 | MS_STATIC EVP_MD_CTX tmp_ctx; | ||
72 | |||
73 | for (i=0; i<4; i++) | ||
74 | { | ||
75 | v=ctx->digest->required_pkey_type[i]; | ||
76 | if (v == 0) break; | ||
77 | if (pkey->type == v) | ||
78 | { | ||
79 | ok=1; | ||
80 | break; | ||
81 | } | ||
82 | } | ||
83 | if (!ok) | ||
84 | { | ||
85 | EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); | ||
86 | return(-1); | ||
87 | } | ||
88 | EVP_MD_CTX_copy(&tmp_ctx,ctx); | ||
89 | EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); | ||
90 | if (ctx->digest->verify == NULL) | ||
91 | { | ||
92 | EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED); | ||
93 | return(0); | ||
94 | } | ||
95 | |||
96 | return(ctx->digest->verify(ctx->digest->type,m,m_len, | ||
97 | sigbuf,siglen,pkey->pkey.ptr)); | ||
98 | } | ||
99 | |||