diff options
author | ryker <> | 1998-10-05 20:13:14 +0000 |
---|---|---|
committer | ryker <> | 1998-10-05 20:13:14 +0000 |
commit | aeeae06a79815dc190061534d47236cec09f9e32 (patch) | |
tree | 851692b9c2f9c04f077666855641900f19fdb217 /src/lib/libcrypto/evp | |
parent | a4f79641824cbf9f60ca9d1168d1fcc46717a82a (diff) | |
download | openbsd-aeeae06a79815dc190061534d47236cec09f9e32.tar.gz openbsd-aeeae06a79815dc190061534d47236cec09f9e32.tar.bz2 openbsd-aeeae06a79815dc190061534d47236cec09f9e32.zip |
Import of SSLeay-0.9.0b with RSA and IDEA stubbed + OpenBSD build
functionality for shared libs.
Note that routines such as sslv2_init and friends that use RSA will
not work due to lack of RSA in this library.
Needs documentation and help from ports for easy upgrade to full
functionality where legally possible.
Diffstat (limited to 'src/lib/libcrypto/evp')
28 files changed, 5498 insertions, 0 deletions
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c new file mode 100644 index 0000000000..73172b9a07 --- /dev/null +++ b/src/lib/libcrypto/evp/bio_b64.c | |||
@@ -0,0 +1,547 @@ | |||
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 "buffer.h" | ||
63 | #include "evp.h" | ||
64 | |||
65 | #ifndef NOPROTO | ||
66 | static int b64_write(BIO *h,char *buf,int num); | ||
67 | static int b64_read(BIO *h,char *buf,int size); | ||
68 | /*static int b64_puts(BIO *h,char *str); */ | ||
69 | /*static int b64_gets(BIO *h,char *str,int size); */ | ||
70 | static long b64_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
71 | static int b64_new(BIO *h); | ||
72 | static int b64_free(BIO *data); | ||
73 | #else | ||
74 | static int b64_write(); | ||
75 | static int b64_read(); | ||
76 | /*static int b64_puts(); */ | ||
77 | /*static int b64_gets(); */ | ||
78 | static long b64_ctrl(); | ||
79 | static int b64_new(); | ||
80 | static int b64_free(); | ||
81 | #endif | ||
82 | |||
83 | #define B64_BLOCK_SIZE 1024 | ||
84 | #define B64_BLOCK_SIZE2 768 | ||
85 | #define B64_NONE 0 | ||
86 | #define B64_ENCODE 1 | ||
87 | #define B64_DECODE 2 | ||
88 | |||
89 | typedef struct b64_struct | ||
90 | { | ||
91 | /*BIO *bio; moved to the BIO structure */ | ||
92 | int buf_len; | ||
93 | int buf_off; | ||
94 | int tmp_len; /* used to find the start when decoding */ | ||
95 | int tmp_nl; /* If true, scan until '\n' */ | ||
96 | int encode; | ||
97 | int start; /* have we started decoding yet? */ | ||
98 | int cont; /* <= 0 when finished */ | ||
99 | EVP_ENCODE_CTX base64; | ||
100 | char buf[EVP_ENCODE_LENGTH(B64_BLOCK_SIZE)+10]; | ||
101 | char tmp[B64_BLOCK_SIZE]; | ||
102 | } BIO_B64_CTX; | ||
103 | |||
104 | static BIO_METHOD methods_b64= | ||
105 | { | ||
106 | BIO_TYPE_BASE64,"base64 encoding", | ||
107 | b64_write, | ||
108 | b64_read, | ||
109 | NULL, /* b64_puts, */ | ||
110 | NULL, /* b64_gets, */ | ||
111 | b64_ctrl, | ||
112 | b64_new, | ||
113 | b64_free, | ||
114 | }; | ||
115 | |||
116 | BIO_METHOD *BIO_f_base64() | ||
117 | { | ||
118 | return(&methods_b64); | ||
119 | } | ||
120 | |||
121 | static int b64_new(bi) | ||
122 | BIO *bi; | ||
123 | { | ||
124 | BIO_B64_CTX *ctx; | ||
125 | |||
126 | ctx=(BIO_B64_CTX *)Malloc(sizeof(BIO_B64_CTX)); | ||
127 | if (ctx == NULL) return(0); | ||
128 | |||
129 | ctx->buf_len=0; | ||
130 | ctx->tmp_len=0; | ||
131 | ctx->tmp_nl=0; | ||
132 | ctx->buf_off=0; | ||
133 | ctx->cont=1; | ||
134 | ctx->start=1; | ||
135 | ctx->encode=0; | ||
136 | |||
137 | bi->init=1; | ||
138 | bi->ptr=(char *)ctx; | ||
139 | bi->flags=0; | ||
140 | return(1); | ||
141 | } | ||
142 | |||
143 | static int b64_free(a) | ||
144 | BIO *a; | ||
145 | { | ||
146 | if (a == NULL) return(0); | ||
147 | Free(a->ptr); | ||
148 | a->ptr=NULL; | ||
149 | a->init=0; | ||
150 | a->flags=0; | ||
151 | return(1); | ||
152 | } | ||
153 | |||
154 | static int b64_read(b,out,outl) | ||
155 | BIO *b; | ||
156 | char *out; | ||
157 | int outl; | ||
158 | { | ||
159 | int ret=0,i,ii,j,k,x,n,num,ret_code=0; | ||
160 | BIO_B64_CTX *ctx; | ||
161 | unsigned char *p,*q; | ||
162 | |||
163 | if (out == NULL) return(0); | ||
164 | ctx=(BIO_B64_CTX *)b->ptr; | ||
165 | |||
166 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
167 | |||
168 | if (ctx->encode != B64_DECODE) | ||
169 | { | ||
170 | ctx->encode=B64_DECODE; | ||
171 | ctx->buf_len=0; | ||
172 | ctx->buf_off=0; | ||
173 | ctx->tmp_len=0; | ||
174 | EVP_DecodeInit(&(ctx->base64)); | ||
175 | } | ||
176 | |||
177 | /* First check if there are bytes decoded/encoded */ | ||
178 | if (ctx->buf_len > 0) | ||
179 | { | ||
180 | i=ctx->buf_len-ctx->buf_off; | ||
181 | if (i > outl) i=outl; | ||
182 | memcpy(out,&(ctx->buf[ctx->buf_off]),i); | ||
183 | ret=i; | ||
184 | out+=i; | ||
185 | outl-=i; | ||
186 | ctx->buf_off+=i; | ||
187 | if (ctx->buf_len == ctx->buf_off) | ||
188 | { | ||
189 | ctx->buf_len=0; | ||
190 | ctx->buf_off=0; | ||
191 | } | ||
192 | } | ||
193 | |||
194 | /* At this point, we have room of outl bytes and an empty | ||
195 | * buffer, so we should read in some more. */ | ||
196 | |||
197 | ret_code=0; | ||
198 | while (outl > 0) | ||
199 | { | ||
200 | if (ctx->cont <= 0) break; | ||
201 | |||
202 | i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]), | ||
203 | B64_BLOCK_SIZE-ctx->tmp_len); | ||
204 | |||
205 | if (i <= 0) | ||
206 | { | ||
207 | ret_code=i; | ||
208 | |||
209 | /* Should be continue next time we are called? */ | ||
210 | if (!BIO_should_retry(b->next_bio)) | ||
211 | ctx->cont=i; | ||
212 | /* else we should continue when called again */ | ||
213 | break; | ||
214 | } | ||
215 | i+=ctx->tmp_len; | ||
216 | |||
217 | /* We need to scan, a line at a time until we | ||
218 | * have a valid line if we are starting. */ | ||
219 | if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)) | ||
220 | { | ||
221 | /* ctx->start=1; */ | ||
222 | ctx->tmp_len=0; | ||
223 | } | ||
224 | else if (ctx->start) | ||
225 | { | ||
226 | q=p=(unsigned char *)ctx->tmp; | ||
227 | for (j=0; j<i; j++) | ||
228 | { | ||
229 | if (*(q++) != '\n') continue; | ||
230 | |||
231 | /* due to a previous very long line, | ||
232 | * we need to keep on scanning for a '\n' | ||
233 | * before we even start looking for | ||
234 | * base64 encoded stuff. */ | ||
235 | if (ctx->tmp_nl) | ||
236 | { | ||
237 | p=q; | ||
238 | ctx->tmp_nl=0; | ||
239 | continue; | ||
240 | } | ||
241 | |||
242 | k=EVP_DecodeUpdate(&(ctx->base64), | ||
243 | (unsigned char *)ctx->buf, | ||
244 | &num,p,q-p); | ||
245 | if ((k <= 0) && (num == 0) && (ctx->start)) | ||
246 | EVP_DecodeInit(&ctx->base64); | ||
247 | else | ||
248 | { | ||
249 | if (p != (unsigned char *) | ||
250 | &(ctx->tmp[0])) | ||
251 | { | ||
252 | i-=(p- (unsigned char *) | ||
253 | &(ctx->tmp[0])); | ||
254 | for (x=0; x < i; x++) | ||
255 | ctx->tmp[x]=p[x]; | ||
256 | EVP_DecodeInit(&ctx->base64); | ||
257 | } | ||
258 | ctx->start=0; | ||
259 | break; | ||
260 | } | ||
261 | p=q; | ||
262 | } | ||
263 | |||
264 | /* we fell off the end without starting */ | ||
265 | if (j == i) | ||
266 | { | ||
267 | /* Is this is one long chunk?, if so, keep on | ||
268 | * reading until a new line. */ | ||
269 | if (p == (unsigned char *)&(ctx->tmp[0])) | ||
270 | { | ||
271 | ctx->tmp_nl=1; | ||
272 | ctx->tmp_len=0; | ||
273 | } | ||
274 | else if (p != q) /* finished on a '\n' */ | ||
275 | { | ||
276 | n=q-p; | ||
277 | for (ii=0; ii<n; ii++) | ||
278 | ctx->tmp[ii]=p[ii]; | ||
279 | ctx->tmp_len=n; | ||
280 | } | ||
281 | /* else finished on a '\n' */ | ||
282 | continue; | ||
283 | } | ||
284 | else | ||
285 | ctx->tmp_len=0; | ||
286 | } | ||
287 | |||
288 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | ||
289 | { | ||
290 | int z,jj; | ||
291 | |||
292 | jj=(i>>2)<<2; | ||
293 | z=EVP_DecodeBlock((unsigned char *)ctx->buf, | ||
294 | (unsigned char *)ctx->tmp,jj); | ||
295 | if (jj > 2) | ||
296 | { | ||
297 | if (ctx->tmp[jj-1] == '=') | ||
298 | { | ||
299 | z--; | ||
300 | if (ctx->tmp[jj-2] == '=') | ||
301 | z--; | ||
302 | } | ||
303 | } | ||
304 | /* z is now number of output bytes and jj is the | ||
305 | * number consumed */ | ||
306 | if (jj != i) | ||
307 | { | ||
308 | memcpy((unsigned char *)ctx->tmp, | ||
309 | (unsigned char *)&(ctx->tmp[jj]),i-jj); | ||
310 | ctx->tmp_len=i-jj; | ||
311 | } | ||
312 | ctx->buf_len=0; | ||
313 | if (z > 0) | ||
314 | { | ||
315 | ctx->buf_len=z; | ||
316 | i=1; | ||
317 | } | ||
318 | else | ||
319 | i=z; | ||
320 | } | ||
321 | else | ||
322 | { | ||
323 | i=EVP_DecodeUpdate(&(ctx->base64), | ||
324 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
325 | (unsigned char *)ctx->tmp,i); | ||
326 | } | ||
327 | ctx->cont=i; | ||
328 | ctx->buf_off=0; | ||
329 | if (i < 0) | ||
330 | { | ||
331 | ret_code=0; | ||
332 | ctx->buf_len=0; | ||
333 | break; | ||
334 | } | ||
335 | |||
336 | if (ctx->buf_len <= outl) | ||
337 | i=ctx->buf_len; | ||
338 | else | ||
339 | i=outl; | ||
340 | |||
341 | memcpy(out,ctx->buf,i); | ||
342 | ret+=i; | ||
343 | ctx->buf_off=i; | ||
344 | if (ctx->buf_off == ctx->buf_len) | ||
345 | { | ||
346 | ctx->buf_len=0; | ||
347 | ctx->buf_off=0; | ||
348 | } | ||
349 | outl-=i; | ||
350 | out+=i; | ||
351 | } | ||
352 | BIO_clear_retry_flags(b); | ||
353 | BIO_copy_next_retry(b); | ||
354 | return((ret == 0)?ret_code:ret); | ||
355 | } | ||
356 | |||
357 | static int b64_write(b,in,inl) | ||
358 | BIO *b; | ||
359 | char *in; | ||
360 | int inl; | ||
361 | { | ||
362 | int ret=inl,n,i; | ||
363 | BIO_B64_CTX *ctx; | ||
364 | |||
365 | ctx=(BIO_B64_CTX *)b->ptr; | ||
366 | BIO_clear_retry_flags(b); | ||
367 | |||
368 | if (ctx->encode != B64_ENCODE) | ||
369 | { | ||
370 | ctx->encode=B64_ENCODE; | ||
371 | ctx->buf_len=0; | ||
372 | ctx->buf_off=0; | ||
373 | ctx->tmp_len=0; | ||
374 | EVP_EncodeInit(&(ctx->base64)); | ||
375 | } | ||
376 | |||
377 | n=ctx->buf_len-ctx->buf_off; | ||
378 | while (n > 0) | ||
379 | { | ||
380 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
381 | if (i <= 0) | ||
382 | { | ||
383 | BIO_copy_next_retry(b); | ||
384 | return(i); | ||
385 | } | ||
386 | ctx->buf_off+=i; | ||
387 | n-=i; | ||
388 | } | ||
389 | /* at this point all pending data has been written */ | ||
390 | |||
391 | if ((in == NULL) || (inl <= 0)) return(0); | ||
392 | |||
393 | ctx->buf_off=0; | ||
394 | while (inl > 0) | ||
395 | { | ||
396 | n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl; | ||
397 | |||
398 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | ||
399 | { | ||
400 | if (ctx->tmp_len > 0) | ||
401 | { | ||
402 | n=3-ctx->tmp_len; | ||
403 | memcpy(&(ctx->tmp[ctx->tmp_len]),in,n); | ||
404 | ctx->tmp_len+=n; | ||
405 | n=ctx->tmp_len; | ||
406 | if (n < 3) | ||
407 | break; | ||
408 | ctx->buf_len=EVP_EncodeBlock( | ||
409 | (unsigned char *)ctx->buf, | ||
410 | (unsigned char *)ctx->tmp,n); | ||
411 | } | ||
412 | else | ||
413 | { | ||
414 | if (n < 3) | ||
415 | { | ||
416 | memcpy(&(ctx->tmp[0]),in,n); | ||
417 | ctx->tmp_len=n; | ||
418 | break; | ||
419 | } | ||
420 | n-=n%3; | ||
421 | ctx->buf_len=EVP_EncodeBlock( | ||
422 | (unsigned char *)ctx->buf, | ||
423 | (unsigned char *)in,n); | ||
424 | } | ||
425 | } | ||
426 | else | ||
427 | { | ||
428 | EVP_EncodeUpdate(&(ctx->base64), | ||
429 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
430 | (unsigned char *)in,n); | ||
431 | } | ||
432 | inl-=n; | ||
433 | in+=n; | ||
434 | |||
435 | ctx->buf_off=0; | ||
436 | n=ctx->buf_len; | ||
437 | while (n > 0) | ||
438 | { | ||
439 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
440 | if (i <= 0) | ||
441 | { | ||
442 | BIO_copy_next_retry(b); | ||
443 | return((ret == 0)?i:ret); | ||
444 | } | ||
445 | n-=i; | ||
446 | ctx->buf_off+=i; | ||
447 | } | ||
448 | ctx->buf_len=0; | ||
449 | ctx->buf_off=0; | ||
450 | } | ||
451 | return(ret); | ||
452 | } | ||
453 | |||
454 | static long b64_ctrl(b,cmd,num,ptr) | ||
455 | BIO *b; | ||
456 | int cmd; | ||
457 | long num; | ||
458 | char *ptr; | ||
459 | { | ||
460 | BIO_B64_CTX *ctx; | ||
461 | long ret=1; | ||
462 | int i; | ||
463 | |||
464 | ctx=(BIO_B64_CTX *)b->ptr; | ||
465 | |||
466 | switch (cmd) | ||
467 | { | ||
468 | case BIO_CTRL_RESET: | ||
469 | ctx->cont=1; | ||
470 | ctx->start=1; | ||
471 | ctx->encode=B64_NONE; | ||
472 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
473 | break; | ||
474 | case BIO_CTRL_EOF: /* More to read */ | ||
475 | if (ctx->cont <= 0) | ||
476 | ret=1; | ||
477 | else | ||
478 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
479 | break; | ||
480 | case BIO_CTRL_WPENDING: /* More to write in buffer */ | ||
481 | ret=ctx->buf_len-ctx->buf_off; | ||
482 | if ((ret == 0) && (ctx->base64.num != 0)) | ||
483 | ret=1; | ||
484 | else if (ret <= 0) | ||
485 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
486 | break; | ||
487 | case BIO_CTRL_PENDING: /* More to read in buffer */ | ||
488 | ret=ctx->buf_len-ctx->buf_off; | ||
489 | if (ret <= 0) | ||
490 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
491 | break; | ||
492 | case BIO_CTRL_FLUSH: | ||
493 | /* do a final write */ | ||
494 | again: | ||
495 | while (ctx->buf_len != ctx->buf_off) | ||
496 | { | ||
497 | i=b64_write(b,NULL,0); | ||
498 | if (i < 0) | ||
499 | { | ||
500 | ret=i; | ||
501 | break; | ||
502 | } | ||
503 | } | ||
504 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | ||
505 | { | ||
506 | if (ctx->tmp_len != 0) | ||
507 | { | ||
508 | ctx->buf_len=EVP_EncodeBlock( | ||
509 | (unsigned char *)ctx->buf, | ||
510 | (unsigned char *)ctx->tmp, | ||
511 | ctx->tmp_len); | ||
512 | ctx->buf_off=0; | ||
513 | ctx->tmp_len=0; | ||
514 | goto again; | ||
515 | } | ||
516 | } | ||
517 | else if (ctx->base64.num != 0) | ||
518 | { | ||
519 | ctx->buf_off=0; | ||
520 | EVP_EncodeFinal(&(ctx->base64), | ||
521 | (unsigned char *)ctx->buf, | ||
522 | &(ctx->buf_len)); | ||
523 | /* push out the bytes */ | ||
524 | goto again; | ||
525 | } | ||
526 | /* Finally flush the underlying BIO */ | ||
527 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
528 | break; | ||
529 | |||
530 | case BIO_C_DO_STATE_MACHINE: | ||
531 | BIO_clear_retry_flags(b); | ||
532 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
533 | BIO_copy_next_retry(b); | ||
534 | break; | ||
535 | |||
536 | case BIO_CTRL_DUP: | ||
537 | break; | ||
538 | case BIO_CTRL_INFO: | ||
539 | case BIO_CTRL_GET: | ||
540 | case BIO_CTRL_SET: | ||
541 | default: | ||
542 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
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 new file mode 100644 index 0000000000..6c30ddfc54 --- /dev/null +++ b/src/lib/libcrypto/evp/bio_enc.c | |||
@@ -0,0 +1,423 @@ | |||
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 "buffer.h" | ||
63 | #include "evp.h" | ||
64 | |||
65 | #ifndef NOPROTO | ||
66 | static int enc_write(BIO *h,char *buf,int num); | ||
67 | static int enc_read(BIO *h,char *buf,int size); | ||
68 | /*static int enc_puts(BIO *h,char *str); */ | ||
69 | /*static int enc_gets(BIO *h,char *str,int size); */ | ||
70 | static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
71 | static int enc_new(BIO *h); | ||
72 | static int enc_free(BIO *data); | ||
73 | #else | ||
74 | static int enc_write(); | ||
75 | static int enc_read(); | ||
76 | /*static int enc_puts(); */ | ||
77 | /*static int enc_gets(); */ | ||
78 | static long enc_ctrl(); | ||
79 | static int enc_new(); | ||
80 | static int enc_free(); | ||
81 | #endif | ||
82 | |||
83 | #define ENC_BLOCK_SIZE (1024*4) | ||
84 | |||
85 | typedef struct enc_struct | ||
86 | { | ||
87 | int buf_len; | ||
88 | int buf_off; | ||
89 | int cont; /* <= 0 when finished */ | ||
90 | int finished; | ||
91 | int ok; /* bad decrypt */ | ||
92 | EVP_CIPHER_CTX cipher; | ||
93 | char buf[ENC_BLOCK_SIZE+10]; | ||
94 | } BIO_ENC_CTX; | ||
95 | |||
96 | static BIO_METHOD methods_enc= | ||
97 | { | ||
98 | BIO_TYPE_CIPHER,"cipher", | ||
99 | enc_write, | ||
100 | enc_read, | ||
101 | NULL, /* enc_puts, */ | ||
102 | NULL, /* enc_gets, */ | ||
103 | enc_ctrl, | ||
104 | enc_new, | ||
105 | enc_free, | ||
106 | }; | ||
107 | |||
108 | BIO_METHOD *BIO_f_cipher() | ||
109 | { | ||
110 | return(&methods_enc); | ||
111 | } | ||
112 | |||
113 | static int enc_new(bi) | ||
114 | BIO *bi; | ||
115 | { | ||
116 | BIO_ENC_CTX *ctx; | ||
117 | |||
118 | ctx=(BIO_ENC_CTX *)Malloc(sizeof(BIO_ENC_CTX)); | ||
119 | EVP_CIPHER_CTX_init(&ctx->cipher); | ||
120 | if (ctx == NULL) return(0); | ||
121 | |||
122 | ctx->buf_len=0; | ||
123 | ctx->buf_off=0; | ||
124 | ctx->cont=1; | ||
125 | ctx->finished=0; | ||
126 | ctx->ok=1; | ||
127 | |||
128 | bi->init=0; | ||
129 | bi->ptr=(char *)ctx; | ||
130 | bi->flags=0; | ||
131 | return(1); | ||
132 | } | ||
133 | |||
134 | static int enc_free(a) | ||
135 | BIO *a; | ||
136 | { | ||
137 | BIO_ENC_CTX *b; | ||
138 | |||
139 | if (a == NULL) return(0); | ||
140 | b=(BIO_ENC_CTX *)a->ptr; | ||
141 | EVP_CIPHER_CTX_cleanup(&(b->cipher)); | ||
142 | memset(a->ptr,0,sizeof(BIO_ENC_CTX)); | ||
143 | Free(a->ptr); | ||
144 | a->ptr=NULL; | ||
145 | a->init=0; | ||
146 | a->flags=0; | ||
147 | return(1); | ||
148 | } | ||
149 | |||
150 | static int enc_read(b,out,outl) | ||
151 | BIO *b; | ||
152 | char *out; | ||
153 | int outl; | ||
154 | { | ||
155 | int ret=0,i; | ||
156 | BIO_ENC_CTX *ctx; | ||
157 | |||
158 | if (out == NULL) return(0); | ||
159 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
160 | |||
161 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
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 | while (outl > 0) | ||
184 | { | ||
185 | if (ctx->cont <= 0) break; | ||
186 | |||
187 | /* read in at offset 8, read the EVP_Cipher | ||
188 | * documentation about why */ | ||
189 | i=BIO_read(b->next_bio,&(ctx->buf[8]),ENC_BLOCK_SIZE); | ||
190 | |||
191 | if (i <= 0) | ||
192 | { | ||
193 | /* Should be continue next time we are called? */ | ||
194 | if (!BIO_should_retry(b->next_bio)) | ||
195 | { | ||
196 | ctx->cont=i; | ||
197 | i=EVP_CipherFinal(&(ctx->cipher), | ||
198 | (unsigned char *)ctx->buf, | ||
199 | &(ctx->buf_len)); | ||
200 | ctx->ok=i; | ||
201 | ctx->buf_off=0; | ||
202 | } | ||
203 | else | ||
204 | ret=(ret == 0)?i:ret; | ||
205 | break; | ||
206 | } | ||
207 | else | ||
208 | { | ||
209 | EVP_CipherUpdate(&(ctx->cipher), | ||
210 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
211 | (unsigned char *)&(ctx->buf[8]),i); | ||
212 | ctx->cont=1; | ||
213 | } | ||
214 | |||
215 | if (ctx->buf_len <= outl) | ||
216 | i=ctx->buf_len; | ||
217 | else | ||
218 | i=outl; | ||
219 | |||
220 | if (i <= 0) break; | ||
221 | memcpy(out,ctx->buf,i); | ||
222 | ret+=i; | ||
223 | ctx->buf_off=i; | ||
224 | outl-=i; | ||
225 | out+=i; | ||
226 | } | ||
227 | |||
228 | BIO_clear_retry_flags(b); | ||
229 | BIO_copy_next_retry(b); | ||
230 | return((ret == 0)?ctx->cont:ret); | ||
231 | } | ||
232 | |||
233 | static int enc_write(b,in,inl) | ||
234 | BIO *b; | ||
235 | char *in; | ||
236 | int inl; | ||
237 | { | ||
238 | int ret=0,n,i; | ||
239 | BIO_ENC_CTX *ctx; | ||
240 | |||
241 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
242 | ret=inl; | ||
243 | |||
244 | BIO_clear_retry_flags(b); | ||
245 | n=ctx->buf_len-ctx->buf_off; | ||
246 | while (n > 0) | ||
247 | { | ||
248 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
249 | if (i <= 0) | ||
250 | { | ||
251 | BIO_copy_next_retry(b); | ||
252 | return(i); | ||
253 | } | ||
254 | ctx->buf_off+=i; | ||
255 | n-=i; | ||
256 | } | ||
257 | /* at this point all pending data has been written */ | ||
258 | |||
259 | if ((in == NULL) || (inl <= 0)) return(0); | ||
260 | |||
261 | ctx->buf_off=0; | ||
262 | while (inl > 0) | ||
263 | { | ||
264 | n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl; | ||
265 | EVP_CipherUpdate(&(ctx->cipher), | ||
266 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
267 | (unsigned char *)in,n); | ||
268 | inl-=n; | ||
269 | in+=n; | ||
270 | |||
271 | ctx->buf_off=0; | ||
272 | n=ctx->buf_len; | ||
273 | while (n > 0) | ||
274 | { | ||
275 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
276 | if (i <= 0) | ||
277 | { | ||
278 | BIO_copy_next_retry(b); | ||
279 | return(i); | ||
280 | } | ||
281 | n-=i; | ||
282 | ctx->buf_off+=i; | ||
283 | } | ||
284 | ctx->buf_len=0; | ||
285 | ctx->buf_off=0; | ||
286 | } | ||
287 | BIO_copy_next_retry(b); | ||
288 | return(ret); | ||
289 | } | ||
290 | |||
291 | static long enc_ctrl(b,cmd,num,ptr) | ||
292 | BIO *b; | ||
293 | int cmd; | ||
294 | long num; | ||
295 | char *ptr; | ||
296 | { | ||
297 | BIO *dbio; | ||
298 | BIO_ENC_CTX *ctx,*dctx; | ||
299 | long ret=1; | ||
300 | int i; | ||
301 | |||
302 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
303 | |||
304 | switch (cmd) | ||
305 | { | ||
306 | case BIO_CTRL_RESET: | ||
307 | ctx->ok=1; | ||
308 | ctx->finished=0; | ||
309 | EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL, | ||
310 | ctx->cipher.encrypt); | ||
311 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
312 | break; | ||
313 | case BIO_CTRL_EOF: /* More to read */ | ||
314 | if (ctx->cont <= 0) | ||
315 | ret=1; | ||
316 | else | ||
317 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
318 | break; | ||
319 | case BIO_CTRL_WPENDING: | ||
320 | ret=ctx->buf_len-ctx->buf_off; | ||
321 | if (ret <= 0) | ||
322 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
323 | break; | ||
324 | case BIO_CTRL_PENDING: /* More to read in buffer */ | ||
325 | ret=ctx->buf_len-ctx->buf_off; | ||
326 | if (ret <= 0) | ||
327 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
328 | break; | ||
329 | case BIO_CTRL_FLUSH: | ||
330 | /* do a final write */ | ||
331 | again: | ||
332 | while (ctx->buf_len != ctx->buf_off) | ||
333 | { | ||
334 | i=enc_write(b,NULL,0); | ||
335 | if (i < 0) | ||
336 | { | ||
337 | ret=i; | ||
338 | break; | ||
339 | } | ||
340 | } | ||
341 | |||
342 | if (!ctx->finished) | ||
343 | { | ||
344 | ctx->finished=1; | ||
345 | ctx->buf_off=0; | ||
346 | ret=EVP_CipherFinal(&(ctx->cipher), | ||
347 | (unsigned char *)ctx->buf, | ||
348 | &(ctx->buf_len)); | ||
349 | ctx->ok=(int)ret; | ||
350 | if (ret <= 0) break; | ||
351 | |||
352 | /* push out the bytes */ | ||
353 | goto again; | ||
354 | } | ||
355 | |||
356 | /* Finally flush the underlying BIO */ | ||
357 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
358 | break; | ||
359 | case BIO_C_GET_CIPHER_STATUS: | ||
360 | ret=(long)ctx->ok; | ||
361 | break; | ||
362 | case BIO_C_DO_STATE_MACHINE: | ||
363 | BIO_clear_retry_flags(b); | ||
364 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
365 | BIO_copy_next_retry(b); | ||
366 | break; | ||
367 | |||
368 | case BIO_CTRL_DUP: | ||
369 | dbio=(BIO *)ptr; | ||
370 | dctx=(BIO_ENC_CTX *)dbio->ptr; | ||
371 | memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher)); | ||
372 | dbio->init=1; | ||
373 | break; | ||
374 | default: | ||
375 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
376 | break; | ||
377 | } | ||
378 | return(ret); | ||
379 | } | ||
380 | |||
381 | /* | ||
382 | void BIO_set_cipher_ctx(b,c) | ||
383 | BIO *b; | ||
384 | EVP_CIPHER_ctx *c; | ||
385 | { | ||
386 | if (b == NULL) return; | ||
387 | |||
388 | if ((b->callback != NULL) && | ||
389 | (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0)) | ||
390 | return; | ||
391 | |||
392 | b->init=1; | ||
393 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
394 | memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX)); | ||
395 | |||
396 | if (b->callback != NULL) | ||
397 | b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L); | ||
398 | } | ||
399 | */ | ||
400 | |||
401 | void BIO_set_cipher(b,c,k,i,e) | ||
402 | BIO *b; | ||
403 | EVP_CIPHER *c; | ||
404 | unsigned char *k; | ||
405 | unsigned char *i; | ||
406 | int e; | ||
407 | { | ||
408 | BIO_ENC_CTX *ctx; | ||
409 | |||
410 | if (b == NULL) return; | ||
411 | |||
412 | if ((b->callback != NULL) && | ||
413 | (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0)) | ||
414 | return; | ||
415 | |||
416 | b->init=1; | ||
417 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
418 | EVP_CipherInit(&(ctx->cipher),c,k,i,e); | ||
419 | |||
420 | if (b->callback != NULL) | ||
421 | b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L); | ||
422 | } | ||
423 | |||
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c new file mode 100644 index 0000000000..fa5fdc055b --- /dev/null +++ b/src/lib/libcrypto/evp/bio_md.c | |||
@@ -0,0 +1,270 @@ | |||
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 "buffer.h" | ||
63 | #include "evp.h" | ||
64 | |||
65 | /* BIO_put and BIO_get both add to the digest, | ||
66 | * BIO_gets returns the digest */ | ||
67 | |||
68 | #ifndef NOPROTO | ||
69 | static int md_write(BIO *h,char *buf,int num); | ||
70 | static int md_read(BIO *h,char *buf,int size); | ||
71 | /*static int md_puts(BIO *h,char *str); */ | ||
72 | static int md_gets(BIO *h,char *str,int size); | ||
73 | static long md_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
74 | static int md_new(BIO *h); | ||
75 | static int md_free(BIO *data); | ||
76 | #else | ||
77 | static int md_write(); | ||
78 | static int md_read(); | ||
79 | /*static int md_puts(); */ | ||
80 | static int md_gets(); | ||
81 | static long md_ctrl(); | ||
82 | static int md_new(); | ||
83 | static int md_free(); | ||
84 | #endif | ||
85 | |||
86 | static BIO_METHOD methods_md= | ||
87 | { | ||
88 | BIO_TYPE_MD,"message digest", | ||
89 | md_write, | ||
90 | md_read, | ||
91 | NULL, /* md_puts, */ | ||
92 | md_gets, | ||
93 | md_ctrl, | ||
94 | md_new, | ||
95 | md_free, | ||
96 | }; | ||
97 | |||
98 | BIO_METHOD *BIO_f_md() | ||
99 | { | ||
100 | return(&methods_md); | ||
101 | } | ||
102 | |||
103 | static int md_new(bi) | ||
104 | BIO *bi; | ||
105 | { | ||
106 | EVP_MD_CTX *ctx; | ||
107 | |||
108 | ctx=(EVP_MD_CTX *)Malloc(sizeof(EVP_MD_CTX)); | ||
109 | if (ctx == NULL) return(0); | ||
110 | |||
111 | bi->init=0; | ||
112 | bi->ptr=(char *)ctx; | ||
113 | bi->flags=0; | ||
114 | return(1); | ||
115 | } | ||
116 | |||
117 | static int md_free(a) | ||
118 | BIO *a; | ||
119 | { | ||
120 | if (a == NULL) return(0); | ||
121 | Free(a->ptr); | ||
122 | a->ptr=NULL; | ||
123 | a->init=0; | ||
124 | a->flags=0; | ||
125 | return(1); | ||
126 | } | ||
127 | |||
128 | static int md_read(b,out,outl) | ||
129 | BIO *b; | ||
130 | char *out; | ||
131 | int outl; | ||
132 | { | ||
133 | int ret=0; | ||
134 | EVP_MD_CTX *ctx; | ||
135 | |||
136 | if (out == NULL) return(0); | ||
137 | ctx=(EVP_MD_CTX *)b->ptr; | ||
138 | |||
139 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
140 | |||
141 | ret=BIO_read(b->next_bio,out,outl); | ||
142 | if (b->init) | ||
143 | { | ||
144 | if (ret > 0) | ||
145 | { | ||
146 | EVP_DigestUpdate(ctx,(unsigned char *)out, | ||
147 | (unsigned int)ret); | ||
148 | } | ||
149 | } | ||
150 | BIO_clear_retry_flags(b); | ||
151 | BIO_copy_next_retry(b); | ||
152 | return(ret); | ||
153 | } | ||
154 | |||
155 | static int md_write(b,in,inl) | ||
156 | BIO *b; | ||
157 | char *in; | ||
158 | int inl; | ||
159 | { | ||
160 | int ret=0; | ||
161 | EVP_MD_CTX *ctx; | ||
162 | |||
163 | if ((in == NULL) || (inl <= 0)) return(0); | ||
164 | ctx=(EVP_MD_CTX *)b->ptr; | ||
165 | |||
166 | if ((ctx != NULL) && (b->next_bio != NULL)) | ||
167 | ret=BIO_write(b->next_bio,in,inl); | ||
168 | if (b->init) | ||
169 | { | ||
170 | if (ret > 0) | ||
171 | { | ||
172 | EVP_DigestUpdate(ctx,(unsigned char *)in, | ||
173 | (unsigned int)ret); | ||
174 | } | ||
175 | } | ||
176 | BIO_clear_retry_flags(b); | ||
177 | BIO_copy_next_retry(b); | ||
178 | return(ret); | ||
179 | } | ||
180 | |||
181 | static long md_ctrl(b,cmd,num,ptr) | ||
182 | BIO *b; | ||
183 | int cmd; | ||
184 | long num; | ||
185 | char *ptr; | ||
186 | { | ||
187 | EVP_MD_CTX *ctx,*dctx,**pctx; | ||
188 | EVP_MD **ppmd; | ||
189 | EVP_MD *md; | ||
190 | long ret=1; | ||
191 | BIO *dbio; | ||
192 | |||
193 | ctx=(EVP_MD_CTX *)b->ptr; | ||
194 | |||
195 | switch (cmd) | ||
196 | { | ||
197 | case BIO_CTRL_RESET: | ||
198 | if (b->init) | ||
199 | EVP_DigestInit(ctx,ctx->digest); | ||
200 | else | ||
201 | ret=0; | ||
202 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
203 | break; | ||
204 | case BIO_C_GET_MD: | ||
205 | if (b->init) | ||
206 | { | ||
207 | ppmd=(EVP_MD **)ptr; | ||
208 | *ppmd=ctx->digest; | ||
209 | } | ||
210 | else | ||
211 | ret=0; | ||
212 | break; | ||
213 | case BIO_C_GET_MD_CTX: | ||
214 | if (b->init) | ||
215 | { | ||
216 | pctx=(EVP_MD_CTX **)ptr; | ||
217 | *pctx=ctx; | ||
218 | } | ||
219 | else | ||
220 | ret=0; | ||
221 | break; | ||
222 | case BIO_C_DO_STATE_MACHINE: | ||
223 | BIO_clear_retry_flags(b); | ||
224 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
225 | BIO_copy_next_retry(b); | ||
226 | break; | ||
227 | |||
228 | case BIO_C_SET_MD: | ||
229 | md=(EVP_MD *)ptr; | ||
230 | EVP_DigestInit(ctx,md); | ||
231 | b->init=1; | ||
232 | break; | ||
233 | case BIO_CTRL_DUP: | ||
234 | dbio=(BIO *)ptr; | ||
235 | dctx=(EVP_MD_CTX *)dbio->ptr; | ||
236 | memcpy(dctx,ctx,sizeof(ctx)); | ||
237 | b->init=1; | ||
238 | break; | ||
239 | default: | ||
240 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
241 | break; | ||
242 | } | ||
243 | return(ret); | ||
244 | } | ||
245 | |||
246 | static int md_gets(bp,buf,size) | ||
247 | BIO *bp; | ||
248 | char *buf; | ||
249 | int size; | ||
250 | { | ||
251 | EVP_MD_CTX *ctx; | ||
252 | unsigned int ret; | ||
253 | |||
254 | |||
255 | ctx=(EVP_MD_CTX *)bp->ptr; | ||
256 | if (size < ctx->digest->md_size) | ||
257 | return(0); | ||
258 | EVP_DigestFinal(ctx,(unsigned char *)buf,&ret); | ||
259 | return((int)ret); | ||
260 | } | ||
261 | |||
262 | /* | ||
263 | static int md_puts(bp,str) | ||
264 | BIO *bp; | ||
265 | char *str; | ||
266 | { | ||
267 | return(-1); | ||
268 | } | ||
269 | */ | ||
270 | |||
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c new file mode 100644 index 0000000000..e77d1c896b --- /dev/null +++ b/src/lib/libcrypto/evp/c_all.c | |||
@@ -0,0 +1,190 @@ | |||
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 "evp.h" | ||
62 | #include "objects.h" | ||
63 | |||
64 | void SSLeay_add_all_algorithms() | ||
65 | { | ||
66 | SSLeay_add_all_ciphers(); | ||
67 | SSLeay_add_all_digests(); | ||
68 | } | ||
69 | |||
70 | void SSLeay_add_all_ciphers() | ||
71 | { | ||
72 | #ifndef NO_DES | ||
73 | EVP_add_cipher(EVP_des_cfb()); | ||
74 | EVP_add_cipher(EVP_des_ede_cfb()); | ||
75 | EVP_add_cipher(EVP_des_ede3_cfb()); | ||
76 | |||
77 | EVP_add_cipher(EVP_des_ofb()); | ||
78 | EVP_add_cipher(EVP_des_ede_ofb()); | ||
79 | EVP_add_cipher(EVP_des_ede3_ofb()); | ||
80 | |||
81 | EVP_add_cipher(EVP_desx_cbc()); | ||
82 | EVP_add_alias(SN_desx_cbc,"DESX"); | ||
83 | EVP_add_alias(SN_desx_cbc,"desx"); | ||
84 | |||
85 | EVP_add_cipher(EVP_des_cbc()); | ||
86 | EVP_add_alias(SN_des_cbc,"DES"); | ||
87 | EVP_add_alias(SN_des_cbc,"des"); | ||
88 | EVP_add_cipher(EVP_des_ede_cbc()); | ||
89 | EVP_add_cipher(EVP_des_ede3_cbc()); | ||
90 | EVP_add_alias(SN_des_ede3_cbc,"DES3"); | ||
91 | EVP_add_alias(SN_des_ede3_cbc,"des3"); | ||
92 | |||
93 | EVP_add_cipher(EVP_des_ecb()); | ||
94 | EVP_add_cipher(EVP_des_ede()); | ||
95 | EVP_add_cipher(EVP_des_ede3()); | ||
96 | #endif | ||
97 | |||
98 | #ifndef NO_RC4 | ||
99 | EVP_add_cipher(EVP_rc4()); | ||
100 | EVP_add_cipher(EVP_rc4_40()); | ||
101 | #endif | ||
102 | |||
103 | #ifndef NO_IDEA | ||
104 | EVP_add_cipher(EVP_idea_ecb()); | ||
105 | EVP_add_cipher(EVP_idea_cfb()); | ||
106 | EVP_add_cipher(EVP_idea_ofb()); | ||
107 | EVP_add_cipher(EVP_idea_cbc()); | ||
108 | EVP_add_alias(SN_idea_cbc,"IDEA"); | ||
109 | EVP_add_alias(SN_idea_cbc,"idea"); | ||
110 | #endif | ||
111 | |||
112 | #ifndef NO_RC2 | ||
113 | EVP_add_cipher(EVP_rc2_ecb()); | ||
114 | EVP_add_cipher(EVP_rc2_cfb()); | ||
115 | EVP_add_cipher(EVP_rc2_ofb()); | ||
116 | EVP_add_cipher(EVP_rc2_cbc()); | ||
117 | EVP_add_cipher(EVP_rc2_40_cbc()); | ||
118 | EVP_add_alias(SN_rc2_cbc,"RC2"); | ||
119 | EVP_add_alias(SN_rc2_cbc,"rc2"); | ||
120 | #endif | ||
121 | |||
122 | #ifndef NO_BLOWFISH | ||
123 | EVP_add_cipher(EVP_bf_ecb()); | ||
124 | EVP_add_cipher(EVP_bf_cfb()); | ||
125 | EVP_add_cipher(EVP_bf_ofb()); | ||
126 | EVP_add_cipher(EVP_bf_cbc()); | ||
127 | EVP_add_alias(SN_bf_cbc,"BF"); | ||
128 | EVP_add_alias(SN_bf_cbc,"bf"); | ||
129 | EVP_add_alias(SN_bf_cbc,"blowfish"); | ||
130 | #endif | ||
131 | |||
132 | #ifndef NO_CAST | ||
133 | EVP_add_cipher(EVP_cast5_ecb()); | ||
134 | EVP_add_cipher(EVP_cast5_cfb()); | ||
135 | EVP_add_cipher(EVP_cast5_ofb()); | ||
136 | EVP_add_cipher(EVP_cast5_cbc()); | ||
137 | EVP_add_alias(SN_cast5_cbc,"CAST"); | ||
138 | EVP_add_alias(SN_cast5_cbc,"cast"); | ||
139 | EVP_add_alias(SN_cast5_cbc,"CAST-cbc"); | ||
140 | EVP_add_alias(SN_cast5_cbc,"cast-cbc"); | ||
141 | #endif | ||
142 | |||
143 | #ifndef NO_RC5 | ||
144 | EVP_add_cipher(EVP_rc5_32_12_16_ecb()); | ||
145 | EVP_add_cipher(EVP_rc5_32_12_16_cfb()); | ||
146 | EVP_add_cipher(EVP_rc5_32_12_16_ofb()); | ||
147 | EVP_add_cipher(EVP_rc5_32_12_16_cbc()); | ||
148 | EVP_add_alias(SN_rc5_cbc,"rc5"); | ||
149 | EVP_add_alias(SN_rc5_cbc,"RC5"); | ||
150 | EVP_add_alias(SN_rc5_cbc,"rc5-cbc"); | ||
151 | EVP_add_alias(SN_rc5_cbc,"RC5-cbc"); | ||
152 | #endif | ||
153 | } | ||
154 | |||
155 | |||
156 | void SSLeay_add_all_digests() | ||
157 | { | ||
158 | #ifndef NO_MD2 | ||
159 | EVP_add_digest(EVP_md2()); | ||
160 | #endif | ||
161 | #ifndef NO_MD5 | ||
162 | EVP_add_digest(EVP_md5()); | ||
163 | EVP_add_alias(SN_md5,"ssl2-md5"); | ||
164 | EVP_add_alias(SN_md5,"ssl3-md5"); | ||
165 | #endif | ||
166 | #ifndef NO_SHA | ||
167 | EVP_add_digest(EVP_sha()); | ||
168 | #ifndef NO_DSA | ||
169 | EVP_add_digest(EVP_dss()); | ||
170 | #endif | ||
171 | #endif | ||
172 | #ifndef NO_SHA1 | ||
173 | EVP_add_digest(EVP_sha1()); | ||
174 | EVP_add_alias(SN_sha1,"ssl3-sha1"); | ||
175 | #ifndef NO_DSA | ||
176 | EVP_add_digest(EVP_dss1()); | ||
177 | EVP_add_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2); | ||
178 | EVP_add_alias(SN_dsaWithSHA1,"DSS1"); | ||
179 | EVP_add_alias(SN_dsaWithSHA1,"dss1"); | ||
180 | #endif | ||
181 | #endif | ||
182 | #if !defined(NO_MDC2) && !defined(NO_DES) | ||
183 | EVP_add_digest(EVP_mdc2()); | ||
184 | #endif | ||
185 | #ifndef NO_RIPEMD160 | ||
186 | EVP_add_digest(EVP_ripemd160()); | ||
187 | EVP_add_alias(SN_ripemd160,"ripemd"); | ||
188 | EVP_add_alias(SN_ripemd160,"rmd160"); | ||
189 | #endif | ||
190 | } | ||
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c new file mode 100644 index 0000000000..d65f0036f7 --- /dev/null +++ b/src/lib/libcrypto/evp/digest.c | |||
@@ -0,0 +1,89 @@ | |||
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 "objects.h" | ||
62 | #include "evp.h" | ||
63 | |||
64 | void EVP_DigestInit(ctx,type) | ||
65 | EVP_MD_CTX *ctx; | ||
66 | EVP_MD *type; | ||
67 | { | ||
68 | ctx->digest=type; | ||
69 | type->init(&(ctx->md)); | ||
70 | } | ||
71 | |||
72 | void EVP_DigestUpdate(ctx,data,count) | ||
73 | EVP_MD_CTX *ctx; | ||
74 | unsigned char *data; | ||
75 | unsigned int count; | ||
76 | { | ||
77 | ctx->digest->update(&(ctx->md.base[0]),data,(unsigned long)count); | ||
78 | } | ||
79 | |||
80 | void EVP_DigestFinal(ctx,md,size) | ||
81 | EVP_MD_CTX *ctx; | ||
82 | unsigned char *md; | ||
83 | unsigned int *size; | ||
84 | { | ||
85 | ctx->digest->final(md,&(ctx->md.base[0])); | ||
86 | if (size != NULL) | ||
87 | *size=ctx->digest->md_size; | ||
88 | memset(&(ctx->md),0,sizeof(ctx->md)); | ||
89 | } | ||
diff --git a/src/lib/libcrypto/evp/e_null.c b/src/lib/libcrypto/evp/e_null.c new file mode 100644 index 0000000000..e4e7ca7606 --- /dev/null +++ b/src/lib/libcrypto/evp/e_null.c | |||
@@ -0,0 +1,109 @@ | |||
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 "evp.h" | ||
62 | #include "objects.h" | ||
63 | |||
64 | #ifndef NOPROTO | ||
65 | static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, | ||
66 | unsigned char *iv,int enc); | ||
67 | static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
68 | unsigned char *in, unsigned int inl); | ||
69 | #else | ||
70 | static void null_init_key(); | ||
71 | static void null_cipher(); | ||
72 | #endif | ||
73 | |||
74 | static EVP_CIPHER n_cipher= | ||
75 | { | ||
76 | NID_undef, | ||
77 | 1,0,0, | ||
78 | null_init_key, | ||
79 | null_cipher, | ||
80 | NULL, | ||
81 | 0, | ||
82 | NULL, | ||
83 | NULL, | ||
84 | }; | ||
85 | |||
86 | EVP_CIPHER *EVP_enc_null() | ||
87 | { | ||
88 | return(&n_cipher); | ||
89 | } | ||
90 | |||
91 | static void null_init_key(ctx,key,iv,enc) | ||
92 | EVP_CIPHER_CTX *ctx; | ||
93 | unsigned char *key; | ||
94 | unsigned char *iv; | ||
95 | int enc; | ||
96 | { | ||
97 | memset(&(ctx->c),0,sizeof(ctx->c)); | ||
98 | } | ||
99 | |||
100 | static void null_cipher(ctx,out,in,inl) | ||
101 | EVP_CIPHER_CTX *ctx; | ||
102 | unsigned char *out; | ||
103 | unsigned char *in; | ||
104 | unsigned int inl; | ||
105 | { | ||
106 | if (in != out) | ||
107 | memcpy((char *)out,(char *)in,(int)inl); | ||
108 | } | ||
109 | |||
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c new file mode 100644 index 0000000000..7e9790a94c --- /dev/null +++ b/src/lib/libcrypto/evp/e_rc4.c | |||
@@ -0,0 +1,127 @@ | |||
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 "evp.h" | ||
64 | #include "objects.h" | ||
65 | |||
66 | #ifndef NOPROTO | ||
67 | static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, | ||
68 | unsigned char *iv,int enc); | ||
69 | static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
70 | unsigned char *in, unsigned int inl); | ||
71 | #else | ||
72 | static void rc4_init_key(); | ||
73 | static void rc4_cipher(); | ||
74 | #endif | ||
75 | |||
76 | static EVP_CIPHER r4_cipher= | ||
77 | { | ||
78 | NID_rc4, | ||
79 | 1,EVP_RC4_KEY_SIZE,0, | ||
80 | rc4_init_key, | ||
81 | rc4_cipher, | ||
82 | NULL, | ||
83 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ | ||
84 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc4)), | ||
85 | NULL, | ||
86 | NULL, | ||
87 | }; | ||
88 | |||
89 | static EVP_CIPHER r4_40_cipher= | ||
90 | { | ||
91 | NID_rc4_40, | ||
92 | 1,5 /* 40 bit */,0, | ||
93 | rc4_init_key, | ||
94 | rc4_cipher, | ||
95 | }; | ||
96 | |||
97 | EVP_CIPHER *EVP_rc4() | ||
98 | { | ||
99 | return(&r4_cipher); | ||
100 | } | ||
101 | |||
102 | EVP_CIPHER *EVP_rc4_40() | ||
103 | { | ||
104 | return(&r4_40_cipher); | ||
105 | } | ||
106 | |||
107 | static void rc4_init_key(ctx,key,iv,enc) | ||
108 | EVP_CIPHER_CTX *ctx; | ||
109 | unsigned char *key; | ||
110 | unsigned char *iv; | ||
111 | int enc; | ||
112 | { | ||
113 | if (key != NULL) | ||
114 | memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx)); | ||
115 | RC4_set_key(&(ctx->c.rc4.ks),EVP_CIPHER_CTX_key_length(ctx), | ||
116 | ctx->c.rc4.key); | ||
117 | } | ||
118 | |||
119 | static void rc4_cipher(ctx,out,in,inl) | ||
120 | EVP_CIPHER_CTX *ctx; | ||
121 | unsigned char *out; | ||
122 | unsigned char *in; | ||
123 | unsigned int inl; | ||
124 | { | ||
125 | RC4(&(ctx->c.rc4.ks),inl,in,out); | ||
126 | } | ||
127 | #endif | ||
diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c new file mode 100644 index 0000000000..0d7fda0c47 --- /dev/null +++ b/src/lib/libcrypto/evp/e_xcbc_d.c | |||
@@ -0,0 +1,122 @@ | |||
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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "objects.h" | ||
63 | |||
64 | #ifndef NOPROTO | ||
65 | static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, | ||
66 | unsigned char *iv,int enc); | ||
67 | static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
68 | unsigned char *in, unsigned int inl); | ||
69 | #else | ||
70 | static void desx_cbc_init_key(); | ||
71 | static void desx_cbc_cipher(); | ||
72 | #endif | ||
73 | |||
74 | static EVP_CIPHER d_xcbc_cipher= | ||
75 | { | ||
76 | NID_desx_cbc, | ||
77 | 8,24,8, | ||
78 | desx_cbc_init_key, | ||
79 | desx_cbc_cipher, | ||
80 | NULL, | ||
81 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ | ||
82 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.desx_cbc)), | ||
83 | EVP_CIPHER_set_asn1_iv, | ||
84 | EVP_CIPHER_get_asn1_iv, | ||
85 | }; | ||
86 | |||
87 | EVP_CIPHER *EVP_desx_cbc() | ||
88 | { | ||
89 | return(&d_xcbc_cipher); | ||
90 | } | ||
91 | |||
92 | static void desx_cbc_init_key(ctx,key,iv,enc) | ||
93 | EVP_CIPHER_CTX *ctx; | ||
94 | unsigned char *key; | ||
95 | unsigned char *iv; | ||
96 | int enc; | ||
97 | { | ||
98 | if (iv != NULL) | ||
99 | memcpy(&(ctx->oiv[0]),iv,8); | ||
100 | memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); | ||
101 | if (key != NULL) | ||
102 | { | ||
103 | des_set_key((des_cblock *)key,ctx->c.desx_cbc.ks); | ||
104 | memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8); | ||
105 | memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | static void desx_cbc_cipher(ctx,out,in,inl) | ||
110 | EVP_CIPHER_CTX *ctx; | ||
111 | unsigned char *out; | ||
112 | unsigned char *in; | ||
113 | unsigned int inl; | ||
114 | { | ||
115 | des_xcbc_encrypt( | ||
116 | (des_cblock *)in,(des_cblock *)out, | ||
117 | (long)inl, ctx->c.desx_cbc.ks, | ||
118 | (des_cblock *)&(ctx->iv[0]), | ||
119 | (des_cblock *)&(ctx->c.desx_cbc.inw[0]), | ||
120 | (des_cblock *)&(ctx->c.desx_cbc.outw[0]), | ||
121 | ctx->encrypt); | ||
122 | } | ||
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c new file mode 100644 index 0000000000..14d47c1eed --- /dev/null +++ b/src/lib/libcrypto/evp/encode.c | |||
@@ -0,0 +1,438 @@ | |||
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 "evp.h" | ||
62 | |||
63 | #define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f]) | ||
64 | #define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f]) | ||
65 | |||
66 | /* 64 char lines | ||
67 | * pad input with 0 | ||
68 | * left over chars are set to = | ||
69 | * 1 byte => xx== | ||
70 | * 2 bytes => xxx= | ||
71 | * 3 bytes => xxxx | ||
72 | */ | ||
73 | #define BIN_PER_LINE (64/4*3) | ||
74 | #define CHUNKS_PER_LINE (64/4) | ||
75 | #define CHAR_PER_LINE (64+1) | ||
76 | |||
77 | static unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\ | ||
78 | abcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
79 | |||
80 | /* 0xF0 is a EOLN | ||
81 | * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing). | ||
82 | * 0xF2 is EOF | ||
83 | * 0xE0 is ignore at start of line. | ||
84 | * 0xFF is error | ||
85 | */ | ||
86 | |||
87 | #define B64_EOLN 0xF0 | ||
88 | #define B64_CR 0xF1 | ||
89 | #define B64_EOF 0xF2 | ||
90 | #define B64_WS 0xE0 | ||
91 | #define B64_ERROR 0xFF | ||
92 | #define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3) | ||
93 | |||
94 | static unsigned char data_ascii2bin[128]={ | ||
95 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
96 | 0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF, | ||
97 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
98 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
99 | 0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
100 | 0xFF,0xFF,0xFF,0x3E,0xFF,0xF2,0xFF,0x3F, | ||
101 | 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B, | ||
102 | 0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF, | ||
103 | 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06, | ||
104 | 0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E, | ||
105 | 0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16, | ||
106 | 0x17,0x18,0x19,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
107 | 0xFF,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20, | ||
108 | 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28, | ||
109 | 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30, | ||
110 | 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
111 | }; | ||
112 | |||
113 | void EVP_EncodeInit(ctx) | ||
114 | EVP_ENCODE_CTX *ctx; | ||
115 | { | ||
116 | ctx->length=48; | ||
117 | ctx->num=0; | ||
118 | ctx->line_num=0; | ||
119 | } | ||
120 | |||
121 | void EVP_EncodeUpdate(ctx,out,outl,in,inl) | ||
122 | EVP_ENCODE_CTX *ctx; | ||
123 | unsigned char *out; | ||
124 | int *outl; | ||
125 | unsigned char *in; | ||
126 | int inl; | ||
127 | { | ||
128 | int i,j; | ||
129 | unsigned int total=0; | ||
130 | |||
131 | *outl=0; | ||
132 | if (inl == 0) return; | ||
133 | if ((ctx->num+inl) < ctx->length) | ||
134 | { | ||
135 | memcpy(&(ctx->enc_data[ctx->num]),in,inl); | ||
136 | ctx->num+=inl; | ||
137 | return; | ||
138 | } | ||
139 | if (ctx->num != 0) | ||
140 | { | ||
141 | i=ctx->length-ctx->num; | ||
142 | memcpy(&(ctx->enc_data[ctx->num]),in,i); | ||
143 | in+=i; | ||
144 | inl-=i; | ||
145 | j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length); | ||
146 | ctx->num=0; | ||
147 | out+=j; | ||
148 | *(out++)='\n'; | ||
149 | *out='\0'; | ||
150 | total=j+1; | ||
151 | } | ||
152 | while (inl >= ctx->length) | ||
153 | { | ||
154 | j=EVP_EncodeBlock(out,in,ctx->length); | ||
155 | in+=ctx->length; | ||
156 | inl-=ctx->length; | ||
157 | out+=j; | ||
158 | *(out++)='\n'; | ||
159 | *out='\0'; | ||
160 | total+=j+1; | ||
161 | } | ||
162 | if (inl != 0) | ||
163 | memcpy(&(ctx->enc_data[0]),in,inl); | ||
164 | ctx->num=inl; | ||
165 | *outl=total; | ||
166 | } | ||
167 | |||
168 | void EVP_EncodeFinal(ctx,out,outl) | ||
169 | EVP_ENCODE_CTX *ctx; | ||
170 | unsigned char *out; | ||
171 | int *outl; | ||
172 | { | ||
173 | unsigned int ret=0; | ||
174 | |||
175 | if (ctx->num != 0) | ||
176 | { | ||
177 | ret=EVP_EncodeBlock(out,ctx->enc_data,ctx->num); | ||
178 | out[ret++]='\n'; | ||
179 | out[ret]='\0'; | ||
180 | ctx->num=0; | ||
181 | } | ||
182 | *outl=ret; | ||
183 | } | ||
184 | |||
185 | int EVP_EncodeBlock(t,f,dlen) | ||
186 | unsigned char *t,*f; | ||
187 | int dlen; | ||
188 | { | ||
189 | int i,ret=0; | ||
190 | unsigned long l; | ||
191 | |||
192 | for (i=dlen; i > 0; i-=3) | ||
193 | { | ||
194 | if (i >= 3) | ||
195 | { | ||
196 | l= (((unsigned long)f[0])<<16L)| | ||
197 | (((unsigned long)f[1])<< 8L)|f[2]; | ||
198 | *(t++)=conv_bin2ascii(l>>18L); | ||
199 | *(t++)=conv_bin2ascii(l>>12L); | ||
200 | *(t++)=conv_bin2ascii(l>> 6L); | ||
201 | *(t++)=conv_bin2ascii(l ); | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | l=((unsigned long)f[0])<<16L; | ||
206 | if (i == 2) l|=((unsigned long)f[1]<<8L); | ||
207 | |||
208 | *(t++)=conv_bin2ascii(l>>18L); | ||
209 | *(t++)=conv_bin2ascii(l>>12L); | ||
210 | *(t++)=(i == 1)?'=':conv_bin2ascii(l>> 6L); | ||
211 | *(t++)='='; | ||
212 | } | ||
213 | ret+=4; | ||
214 | f+=3; | ||
215 | } | ||
216 | |||
217 | *t='\0'; | ||
218 | return(ret); | ||
219 | } | ||
220 | |||
221 | void EVP_DecodeInit(ctx) | ||
222 | 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(ctx,out,outl,in,inl) | ||
235 | EVP_ENCODE_CTX *ctx; | ||
236 | unsigned char *out; | ||
237 | int *outl; | ||
238 | unsigned char *in; | ||
239 | int inl; | ||
240 | { | ||
241 | int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl; | ||
242 | unsigned char *d; | ||
243 | |||
244 | n=ctx->num; | ||
245 | d=ctx->enc_data; | ||
246 | ln=ctx->line_num; | ||
247 | exp_nl=ctx->expect_nl; | ||
248 | |||
249 | /* last line of input. */ | ||
250 | if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF))) | ||
251 | { rv=0; goto end; } | ||
252 | |||
253 | /* We parse the input data */ | ||
254 | for (i=0; i<inl; i++) | ||
255 | { | ||
256 | /* If the current line is > 80 characters, scream alot */ | ||
257 | if (ln >= 80) { rv= -1; goto end; } | ||
258 | |||
259 | /* Get char and put it into the buffer */ | ||
260 | tmp= *(in++); | ||
261 | v=conv_ascii2bin(tmp); | ||
262 | /* only save the good data :-) */ | ||
263 | if (!B64_NOT_BASE64(v)) | ||
264 | { | ||
265 | d[n++]=tmp; | ||
266 | ln++; | ||
267 | } | ||
268 | else if (v == B64_ERROR) | ||
269 | { | ||
270 | rv= -1; | ||
271 | goto end; | ||
272 | } | ||
273 | |||
274 | /* have we seen a '=' which is 'definitly' the last | ||
275 | * input line. seof will point to the character that | ||
276 | * holds it. and eof will hold how many characters to | ||
277 | * chop off. */ | ||
278 | if (tmp == '=') | ||
279 | { | ||
280 | if (seof == -1) seof=n; | ||
281 | eof++; | ||
282 | } | ||
283 | |||
284 | /* eoln */ | ||
285 | if (v == B64_EOLN) | ||
286 | { | ||
287 | ln=0; | ||
288 | if (exp_nl) | ||
289 | { | ||
290 | exp_nl=0; | ||
291 | continue; | ||
292 | } | ||
293 | } | ||
294 | exp_nl=0; | ||
295 | |||
296 | /* If we are at the end of input and it looks like a | ||
297 | * line, process it. */ | ||
298 | if (((i+1) == inl) && (((n&3) == 0) || eof)) | ||
299 | v=B64_EOF; | ||
300 | |||
301 | if ((v == B64_EOF) || (n >= 64)) | ||
302 | { | ||
303 | /* This is needed to work correctly on 64 byte input | ||
304 | * lines. We process the line and then need to | ||
305 | * accept the '\n' */ | ||
306 | if ((v != B64_EOF) && (n >= 64)) exp_nl=1; | ||
307 | tmp2=v; | ||
308 | if (n > 0) | ||
309 | { | ||
310 | v=EVP_DecodeBlock(out,d,n); | ||
311 | if (v < 0) { rv=0; goto end; } | ||
312 | n=0; | ||
313 | ret+=(v-eof); | ||
314 | } | ||
315 | else | ||
316 | { | ||
317 | eof=1; | ||
318 | v=0; | ||
319 | } | ||
320 | |||
321 | /* This is the case where we have had a short | ||
322 | * but valid input line */ | ||
323 | if ((v < ctx->length) && eof) | ||
324 | { | ||
325 | rv=0; | ||
326 | goto end; | ||
327 | } | ||
328 | else | ||
329 | ctx->length=v; | ||
330 | |||
331 | if (seof >= 0) { rv=0; goto end; } | ||
332 | out+=v; | ||
333 | } | ||
334 | } | ||
335 | rv=1; | ||
336 | end: | ||
337 | *outl=ret; | ||
338 | ctx->num=n; | ||
339 | ctx->line_num=ln; | ||
340 | ctx->expect_nl=exp_nl; | ||
341 | return(rv); | ||
342 | } | ||
343 | |||
344 | int EVP_DecodeBlock(t,f,n) | ||
345 | unsigned char *t,*f; | ||
346 | int n; | ||
347 | { | ||
348 | int i,ret=0,a,b,c,d; | ||
349 | unsigned long l; | ||
350 | |||
351 | /* trim white space from the start of the line. */ | ||
352 | while ((conv_ascii2bin(*f) == B64_WS) && (n > 0)) | ||
353 | { | ||
354 | f++; | ||
355 | n--; | ||
356 | } | ||
357 | |||
358 | /* strip off stuff at the end of the line | ||
359 | * ascii2bin values B64_WS, B64_EOLN, B64_EOLN and B64_EOF */ | ||
360 | while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n-1])))) | ||
361 | n--; | ||
362 | |||
363 | if (n%4 != 0) return(-1); | ||
364 | |||
365 | for (i=0; i<n; i+=4) | ||
366 | { | ||
367 | a=conv_ascii2bin(*(f++)); | ||
368 | b=conv_ascii2bin(*(f++)); | ||
369 | c=conv_ascii2bin(*(f++)); | ||
370 | d=conv_ascii2bin(*(f++)); | ||
371 | if ( (a & 0x80) || (b & 0x80) || | ||
372 | (c & 0x80) || (d & 0x80)) | ||
373 | return(-1); | ||
374 | l=( (((unsigned long)a)<<18L)| | ||
375 | (((unsigned long)b)<<12L)| | ||
376 | (((unsigned long)c)<< 6L)| | ||
377 | (((unsigned long)d) )); | ||
378 | *(t++)=(unsigned char)(l>>16L)&0xff; | ||
379 | *(t++)=(unsigned char)(l>> 8L)&0xff; | ||
380 | *(t++)=(unsigned char)(l )&0xff; | ||
381 | ret+=3; | ||
382 | } | ||
383 | return(ret); | ||
384 | } | ||
385 | |||
386 | int EVP_DecodeFinal(ctx,out,outl) | ||
387 | EVP_ENCODE_CTX *ctx; | ||
388 | unsigned char *out; | ||
389 | int *outl; | ||
390 | { | ||
391 | int i; | ||
392 | |||
393 | *outl=0; | ||
394 | if (ctx->num != 0) | ||
395 | { | ||
396 | i=EVP_DecodeBlock(out,ctx->enc_data,ctx->num); | ||
397 | if (i < 0) return(-1); | ||
398 | ctx->num=0; | ||
399 | *outl=i; | ||
400 | return(1); | ||
401 | } | ||
402 | else | ||
403 | return(1); | ||
404 | } | ||
405 | |||
406 | #ifdef undef | ||
407 | int EVP_DecodeValid(buf,len) | ||
408 | unsigned char *buf; | ||
409 | int len; | ||
410 | { | ||
411 | int i,num=0,bad=0; | ||
412 | |||
413 | if (len == 0) return(-1); | ||
414 | while (conv_ascii2bin(*buf) == B64_WS) | ||
415 | { | ||
416 | buf++; | ||
417 | len--; | ||
418 | if (len == 0) return(-1); | ||
419 | } | ||
420 | |||
421 | for (i=len; i >= 4; i-=4) | ||
422 | { | ||
423 | if ( (conv_ascii2bin(buf[0]) >= 0x40) || | ||
424 | (conv_ascii2bin(buf[1]) >= 0x40) || | ||
425 | (conv_ascii2bin(buf[2]) >= 0x40) || | ||
426 | (conv_ascii2bin(buf[3]) >= 0x40)) | ||
427 | return(-1); | ||
428 | buf+=4; | ||
429 | num+=1+(buf[2] != '=')+(buf[3] != '='); | ||
430 | } | ||
431 | if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN)) | ||
432 | return(num); | ||
433 | if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) && | ||
434 | (conv_ascii2bin(buf[0]) == B64_EOLN)) | ||
435 | return(num); | ||
436 | return(1); | ||
437 | } | ||
438 | #endif | ||
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h new file mode 100644 index 0000000000..b39fad93a4 --- /dev/null +++ b/src/lib/libcrypto/evp/evp.h | |||
@@ -0,0 +1,793 @@ | |||
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 __cplusplus | ||
63 | extern "C" { | ||
64 | #endif | ||
65 | |||
66 | #ifndef NO_MD2 | ||
67 | #include "md2.h" | ||
68 | #endif | ||
69 | #ifndef NO_MD5 | ||
70 | #include "md5.h" | ||
71 | #endif | ||
72 | #if !defined(NO_SHA) || !defined(NO_SHA1) | ||
73 | #include "sha.h" | ||
74 | #endif | ||
75 | #ifndef NO_RIPEMD | ||
76 | #include "ripemd.h" | ||
77 | #endif | ||
78 | #ifndef NO_DES | ||
79 | #include "des.h" | ||
80 | #endif | ||
81 | #ifndef NO_RC4 | ||
82 | #include "rc4.h" | ||
83 | #endif | ||
84 | #ifndef NO_RC2 | ||
85 | #include "rc2.h" | ||
86 | #endif | ||
87 | #ifndef NO_RC5 | ||
88 | #include "rc5.h" | ||
89 | #endif | ||
90 | #ifndef NO_BLOWFISH | ||
91 | #include "blowfish.h" | ||
92 | #endif | ||
93 | #ifndef NO_CAST | ||
94 | #include "cast.h" | ||
95 | #endif | ||
96 | #ifndef NO_IDEA | ||
97 | #include "idea.h" | ||
98 | #endif | ||
99 | #ifndef NO_MDC2 | ||
100 | #include "mdc2.h" | ||
101 | #endif | ||
102 | |||
103 | #define EVP_RC2_KEY_SIZE 16 | ||
104 | #define EVP_RC4_KEY_SIZE 16 | ||
105 | #define EVP_BLOWFISH_KEY_SIZE 16 | ||
106 | #define EVP_CAST5_KEY_SIZE 16 | ||
107 | #define EVP_RC5_32_12_16_KEY_SIZE 16 | ||
108 | #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */ | ||
109 | #define EVP_MAX_KEY_LENGTH 24 | ||
110 | #define EVP_MAX_IV_LENGTH 8 | ||
111 | |||
112 | #ifndef NO_RSA | ||
113 | #include "rsa.h" | ||
114 | #else | ||
115 | #define RSA long | ||
116 | #endif | ||
117 | |||
118 | #ifndef NO_DSA | ||
119 | #include "dsa.h" | ||
120 | #else | ||
121 | #define DSA long | ||
122 | #endif | ||
123 | |||
124 | #ifndef NO_DH | ||
125 | #include "dh.h" | ||
126 | #else | ||
127 | #define DH long | ||
128 | #endif | ||
129 | |||
130 | #include "objects.h" | ||
131 | |||
132 | #define EVP_PK_RSA 0x0001 | ||
133 | #define EVP_PK_DSA 0x0002 | ||
134 | #define EVP_PK_DH 0x0004 | ||
135 | #define EVP_PKT_SIGN 0x0010 | ||
136 | #define EVP_PKT_ENC 0x0020 | ||
137 | #define EVP_PKT_EXCH 0x0040 | ||
138 | #define EVP_PKS_RSA 0x0100 | ||
139 | #define EVP_PKS_DSA 0x0200 | ||
140 | #define EVP_PKT_EXP 0x1000 /* <= 512 bit key */ | ||
141 | |||
142 | #define EVP_PKEY_NONE NID_undef | ||
143 | #define EVP_PKEY_RSA NID_rsaEncryption | ||
144 | #define EVP_PKEY_RSA2 NID_rsa | ||
145 | #define EVP_PKEY_DSA NID_dsa | ||
146 | #define EVP_PKEY_DSA1 NID_dsa_2 | ||
147 | #define EVP_PKEY_DSA2 NID_dsaWithSHA | ||
148 | #define EVP_PKEY_DSA3 NID_dsaWithSHA1 | ||
149 | #define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 | ||
150 | #define EVP_PKEY_DH NID_dhKeyAgreement | ||
151 | |||
152 | /* Type needs to be a bit field | ||
153 | * Sub-type needs to be for variations on the method, as in, can it do | ||
154 | * arbitary encryption.... */ | ||
155 | typedef struct evp_pkey_st | ||
156 | { | ||
157 | int type; | ||
158 | int save_type; | ||
159 | int references; | ||
160 | union { | ||
161 | char *ptr; | ||
162 | struct rsa_st *rsa; /* RSA */ | ||
163 | struct dsa_st *dsa; /* DSA */ | ||
164 | struct dh_st *dh; /* DH */ | ||
165 | } pkey; | ||
166 | int save_parameters; | ||
167 | #ifdef HEADER_STACK_H | ||
168 | STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */ | ||
169 | #else | ||
170 | char /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */ | ||
171 | #endif | ||
172 | } EVP_PKEY; | ||
173 | |||
174 | #define EVP_PKEY_MO_SIGN 0x0001 | ||
175 | #define EVP_PKEY_MO_VERIFY 0x0002 | ||
176 | #define EVP_PKEY_MO_ENCRYPT 0x0004 | ||
177 | #define EVP_PKEY_MO_DECRYPT 0x0008 | ||
178 | |||
179 | #if 0 | ||
180 | /* This structure is required to tie the message digest and signing together. | ||
181 | * The lookup can be done by md/pkey_method, oid, oid/pkey_method, or | ||
182 | * oid, md and pkey. | ||
183 | * This is required because for various smart-card perform the digest and | ||
184 | * signing/verification on-board. To handle this case, the specific | ||
185 | * EVP_MD and EVP_PKEY_METHODs need to be closely associated. | ||
186 | * When a PKEY is created, it will have a EVP_PKEY_METHOD ossociated with it. | ||
187 | * This can either be software or a token to provide the required low level | ||
188 | * routines. | ||
189 | */ | ||
190 | typedef struct evp_pkey_md_st | ||
191 | { | ||
192 | int oid; | ||
193 | EVP_MD *md; | ||
194 | EVP_PKEY_METHOD *pkey; | ||
195 | } EVP_PKEY_MD; | ||
196 | |||
197 | #define EVP_rsa_md2() | ||
198 | EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\ | ||
199 | EVP_rsa_pkcs1(),EVP_md2()) | ||
200 | #define EVP_rsa_md5() | ||
201 | EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\ | ||
202 | EVP_rsa_pkcs1(),EVP_md5()) | ||
203 | #define EVP_rsa_sha0() | ||
204 | EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\ | ||
205 | EVP_rsa_pkcs1(),EVP_sha()) | ||
206 | #define EVP_rsa_sha1() | ||
207 | EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\ | ||
208 | EVP_rsa_pkcs1(),EVP_sha1()) | ||
209 | #define EVP_rsa_ripemd160() | ||
210 | EVP_PKEY_MD_add(NID_ripemd160WithRSA,\ | ||
211 | EVP_rsa_pkcs1(),EVP_ripemd160()) | ||
212 | #define EVP_rsa_mdc2() | ||
213 | EVP_PKEY_MD_add(NID_mdc2WithRSA,\ | ||
214 | EVP_rsa_octet_string(),EVP_mdc2()) | ||
215 | #define EVP_dsa_sha() | ||
216 | EVP_PKEY_MD_add(NID_dsaWithSHA,\ | ||
217 | EVP_dsa(),EVP_mdc2()) | ||
218 | #define EVP_dsa_sha1() | ||
219 | EVP_PKEY_MD_add(NID_dsaWithSHA1,\ | ||
220 | EVP_dsa(),EVP_sha1()) | ||
221 | |||
222 | typedef struct evp_pkey_method_st | ||
223 | { | ||
224 | char *name; | ||
225 | int flags; | ||
226 | int type; /* RSA, DSA, an SSLeay specific constant */ | ||
227 | int oid; /* For the pub-key type */ | ||
228 | int encrypt_oid; /* pub/priv key encryption */ | ||
229 | |||
230 | int (*sign)(); | ||
231 | int (*verify)(); | ||
232 | struct { | ||
233 | int | ||
234 | int (*set)(); /* get and/or set the underlying type */ | ||
235 | int (*get)(); | ||
236 | int (*encrypt)(); | ||
237 | int (*decrypt)(); | ||
238 | int (*i2d)(); | ||
239 | int (*d2i)(); | ||
240 | int (*dup)(); | ||
241 | } pub,priv; | ||
242 | int (*set_asn1_parameters)(); | ||
243 | int (*get_asn1_parameters)(); | ||
244 | } EVP_PKEY_METHOD; | ||
245 | #endif | ||
246 | |||
247 | #ifndef EVP_MD | ||
248 | typedef struct env_md_st | ||
249 | { | ||
250 | int type; | ||
251 | int pkey_type; | ||
252 | int md_size; | ||
253 | void (*init)(); | ||
254 | void (*update)(); | ||
255 | void (*final)(); | ||
256 | |||
257 | int (*sign)(); | ||
258 | int (*verify)(); | ||
259 | int required_pkey_type[5]; /*EVP_PKEY_xxx */ | ||
260 | int block_size; | ||
261 | int ctx_size; /* how big does the ctx need to be */ | ||
262 | } EVP_MD; | ||
263 | |||
264 | #define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0} | ||
265 | |||
266 | #ifndef NO_DSA | ||
267 | #define EVP_PKEY_DSA_method DSA_sign,DSA_verify, \ | ||
268 | {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \ | ||
269 | EVP_PKEY_DSA4,0} | ||
270 | #else | ||
271 | #define EVP_PKEY_DSA_method EVP_PKEY_NULL_method | ||
272 | #endif | ||
273 | |||
274 | #ifndef NO_RSA | ||
275 | #define EVP_PKEY_RSA_method RSA_sign,RSA_verify, \ | ||
276 | {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} | ||
277 | #define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \ | ||
278 | RSA_sign_ASN1_OCTET_STRING, \ | ||
279 | RSA_verify_ASN1_OCTET_STRING, \ | ||
280 | {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} | ||
281 | #else | ||
282 | #define EVP_PKEY_RSA_method EVP_PKEY_NULL_method | ||
283 | #define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method | ||
284 | #endif | ||
285 | |||
286 | #endif /* !EVP_MD */ | ||
287 | |||
288 | typedef struct env_md_ctx_st | ||
289 | { | ||
290 | EVP_MD *digest; | ||
291 | union { | ||
292 | unsigned char base[4]; | ||
293 | #ifndef NO_MD2 | ||
294 | MD2_CTX md2; | ||
295 | #endif | ||
296 | #ifndef NO_MD5 | ||
297 | MD5_CTX md5; | ||
298 | #endif | ||
299 | #ifndef NO_MD5 | ||
300 | RIPEMD160_CTX ripemd160; | ||
301 | #endif | ||
302 | #if !defined(NO_SHA) || !defined(NO_SHA1) | ||
303 | SHA_CTX sha; | ||
304 | #endif | ||
305 | #ifndef NO_MDC2 | ||
306 | MDC2_CTX mdc2; | ||
307 | #endif | ||
308 | } md; | ||
309 | } EVP_MD_CTX; | ||
310 | |||
311 | typedef struct evp_cipher_st | ||
312 | { | ||
313 | int nid; | ||
314 | int block_size; | ||
315 | int key_len; | ||
316 | int iv_len; | ||
317 | void (*init)(); /* init for encryption */ | ||
318 | void (*do_cipher)(); /* encrypt data */ | ||
319 | void (*cleanup)(); /* used by cipher method */ | ||
320 | int ctx_size; /* how big the ctx needs to be */ | ||
321 | /* int set_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */ | ||
322 | int (*set_asn1_parameters)(); /* Populate a ASN1_TYPE with parameters */ | ||
323 | /* int get_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */ | ||
324 | int (*get_asn1_parameters)(); /* Get parameters from a ASN1_TYPE */ | ||
325 | } EVP_CIPHER; | ||
326 | |||
327 | typedef struct evp_cipher_info_st | ||
328 | { | ||
329 | EVP_CIPHER *cipher; | ||
330 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
331 | } EVP_CIPHER_INFO; | ||
332 | |||
333 | typedef struct evp_cipher_ctx_st | ||
334 | { | ||
335 | EVP_CIPHER *cipher; | ||
336 | int encrypt; /* encrypt or decrypt */ | ||
337 | int buf_len; /* number we have left */ | ||
338 | |||
339 | unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */ | ||
340 | unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */ | ||
341 | unsigned char buf[EVP_MAX_IV_LENGTH]; /* saved partial block */ | ||
342 | int num; /* used by cfb/ofb mode */ | ||
343 | |||
344 | char *app_data; /* aplication stuff */ | ||
345 | union { | ||
346 | #ifndef NO_RC4 | ||
347 | struct | ||
348 | { | ||
349 | unsigned char key[EVP_RC4_KEY_SIZE]; | ||
350 | RC4_KEY ks; /* working key */ | ||
351 | } rc4; | ||
352 | #endif | ||
353 | #ifndef NO_DES | ||
354 | des_key_schedule des_ks;/* key schedule */ | ||
355 | struct | ||
356 | { | ||
357 | des_key_schedule ks;/* key schedule */ | ||
358 | C_Block inw; | ||
359 | C_Block outw; | ||
360 | } desx_cbc; | ||
361 | struct | ||
362 | { | ||
363 | des_key_schedule ks1;/* key schedule */ | ||
364 | des_key_schedule ks2;/* key schedule (for ede) */ | ||
365 | des_key_schedule ks3;/* key schedule (for ede3) */ | ||
366 | } des_ede; | ||
367 | #endif | ||
368 | #ifndef NO_IDEA | ||
369 | IDEA_KEY_SCHEDULE idea_ks;/* key schedule */ | ||
370 | #endif | ||
371 | #ifndef NO_RC2 | ||
372 | RC2_KEY rc2_ks;/* key schedule */ | ||
373 | #endif | ||
374 | #ifndef NO_RC5 | ||
375 | RC5_32_KEY rc5_ks;/* key schedule */ | ||
376 | #endif | ||
377 | #ifndef NO_BLOWFISH | ||
378 | BF_KEY bf_ks;/* key schedule */ | ||
379 | #endif | ||
380 | #ifndef NO_CAST | ||
381 | CAST_KEY cast_ks;/* key schedule */ | ||
382 | #endif | ||
383 | } c; | ||
384 | } EVP_CIPHER_CTX; | ||
385 | |||
386 | typedef struct evp_Encode_Ctx_st | ||
387 | { | ||
388 | int num; /* number saved in a partial encode/decode */ | ||
389 | int length; /* The length is either the output line length | ||
390 | * (in input bytes) or the shortest input line | ||
391 | * length that is ok. Once decoding begins, | ||
392 | * the length is adjusted up each time a longer | ||
393 | * line is decoded */ | ||
394 | unsigned char enc_data[80]; /* data to encode */ | ||
395 | int line_num; /* number read on current line */ | ||
396 | int expect_nl; | ||
397 | } EVP_ENCODE_CTX; | ||
398 | |||
399 | #define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ | ||
400 | (char *)(rsa)) | ||
401 | #define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\ | ||
402 | (char *)(dsa)) | ||
403 | #define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\ | ||
404 | (char *)(dh)) | ||
405 | |||
406 | /* Add some extra combinations */ | ||
407 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) | ||
408 | #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) | ||
409 | #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) | ||
410 | #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) | ||
411 | |||
412 | #define EVP_MD_type(e) ((e)->type) | ||
413 | #define EVP_MD_pkey_type(e) ((e)->pkey_type) | ||
414 | #define EVP_MD_size(e) ((e)->md_size) | ||
415 | #define EVP_MD_block_size(e) ((e)->block_size) | ||
416 | |||
417 | #define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest) | ||
418 | #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest) | ||
419 | #define EVP_MD_CTX_type(e) ((e)->digest) | ||
420 | |||
421 | #define EVP_CIPHER_nid(e) ((e)->nid) | ||
422 | #define EVP_CIPHER_block_size(e) ((e)->block_size) | ||
423 | #define EVP_CIPHER_key_length(e) ((e)->key_len) | ||
424 | #define EVP_CIPHER_iv_length(e) ((e)->iv_len) | ||
425 | |||
426 | #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher) | ||
427 | #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid) | ||
428 | #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size) | ||
429 | #define EVP_CIPHER_CTX_key_length(e) ((e)->cipher->key_len) | ||
430 | #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len) | ||
431 | #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | ||
432 | #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) | ||
433 | |||
434 | #define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80) | ||
435 | #define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80) | ||
436 | |||
437 | #define EVP_SignInit(a,b) EVP_DigestInit(a,b) | ||
438 | #define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c) | ||
439 | #define EVP_VerifyInit(a,b) EVP_DigestInit(a,b) | ||
440 | #define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c) | ||
441 | #define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e) | ||
442 | #define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e) | ||
443 | |||
444 | #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md) | ||
445 | #define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp) | ||
446 | #define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp) | ||
447 | #define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL) | ||
448 | |||
449 | #define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l)) | ||
450 | |||
451 | #ifndef NOPROTO | ||
452 | |||
453 | void EVP_DigestInit(EVP_MD_CTX *ctx, EVP_MD *type); | ||
454 | void EVP_DigestUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); | ||
455 | void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); | ||
456 | |||
457 | int EVP_read_pw_string(char *buf,int length,char *prompt,int verify); | ||
458 | void EVP_set_pw_prompt(char *prompt); | ||
459 | char * EVP_get_pw_prompt(void); | ||
460 | |||
461 | int EVP_BytesToKey(EVP_CIPHER *type,EVP_MD *md,unsigned char *salt, | ||
462 | unsigned char *data, int datal, int count, | ||
463 | unsigned char *key,unsigned char *iv); | ||
464 | |||
465 | EVP_CIPHER *EVP_get_cipherbyname(char *name); | ||
466 | |||
467 | void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, | ||
468 | unsigned char *key, unsigned char *iv); | ||
469 | void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
470 | int *outl, unsigned char *in, int inl); | ||
471 | void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); | ||
472 | |||
473 | void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, | ||
474 | unsigned char *key, unsigned char *iv); | ||
475 | void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
476 | int *outl, unsigned char *in, int inl); | ||
477 | int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); | ||
478 | |||
479 | void EVP_CipherInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, unsigned char *key, | ||
480 | unsigned char *iv,int enc); | ||
481 | void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
482 | int *outl, unsigned char *in, int inl); | ||
483 | int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); | ||
484 | |||
485 | int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s, | ||
486 | EVP_PKEY *pkey); | ||
487 | |||
488 | int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf, | ||
489 | unsigned int siglen,EVP_PKEY *pkey); | ||
490 | |||
491 | int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek, | ||
492 | int ekl,unsigned char *iv,EVP_PKEY *priv); | ||
493 | int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); | ||
494 | |||
495 | int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek, | ||
496 | int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk); | ||
497 | void EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl); | ||
498 | |||
499 | void EVP_EncodeInit(EVP_ENCODE_CTX *ctx); | ||
500 | void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out, | ||
501 | int *outl,unsigned char *in,int inl); | ||
502 | void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl); | ||
503 | int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int n); | ||
504 | |||
505 | void EVP_DecodeInit(EVP_ENCODE_CTX *ctx); | ||
506 | int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl, | ||
507 | unsigned char *in, int inl); | ||
508 | int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned | ||
509 | char *out, int *outl); | ||
510 | int EVP_DecodeBlock(unsigned char *t, unsigned | ||
511 | char *f, int n); | ||
512 | |||
513 | void ERR_load_EVP_strings(void ); | ||
514 | |||
515 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a); | ||
516 | void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); | ||
517 | |||
518 | #ifdef HEADER_BIO_H | ||
519 | BIO_METHOD *BIO_f_md(void); | ||
520 | BIO_METHOD *BIO_f_base64(void); | ||
521 | BIO_METHOD *BIO_f_cipher(void); | ||
522 | void BIO_set_cipher(BIO *b,EVP_CIPHER *c,unsigned char *k, | ||
523 | unsigned char *i, int enc); | ||
524 | #endif | ||
525 | |||
526 | EVP_MD *EVP_md_null(void); | ||
527 | EVP_MD *EVP_md2(void); | ||
528 | EVP_MD *EVP_md5(void); | ||
529 | EVP_MD *EVP_sha(void); | ||
530 | EVP_MD *EVP_sha1(void); | ||
531 | EVP_MD *EVP_dss(void); | ||
532 | EVP_MD *EVP_dss1(void); | ||
533 | EVP_MD *EVP_mdc2(void); | ||
534 | EVP_MD *EVP_ripemd160(void); | ||
535 | |||
536 | EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ | ||
537 | EVP_CIPHER *EVP_des_ecb(void); | ||
538 | EVP_CIPHER *EVP_des_ede(void); | ||
539 | EVP_CIPHER *EVP_des_ede3(void); | ||
540 | EVP_CIPHER *EVP_des_cfb(void); | ||
541 | EVP_CIPHER *EVP_des_ede_cfb(void); | ||
542 | EVP_CIPHER *EVP_des_ede3_cfb(void); | ||
543 | EVP_CIPHER *EVP_des_ofb(void); | ||
544 | EVP_CIPHER *EVP_des_ede_ofb(void); | ||
545 | EVP_CIPHER *EVP_des_ede3_ofb(void); | ||
546 | EVP_CIPHER *EVP_des_cbc(void); | ||
547 | EVP_CIPHER *EVP_des_ede_cbc(void); | ||
548 | EVP_CIPHER *EVP_des_ede3_cbc(void); | ||
549 | EVP_CIPHER *EVP_desx_cbc(void); | ||
550 | EVP_CIPHER *EVP_rc4(void); | ||
551 | EVP_CIPHER *EVP_rc4_40(void); | ||
552 | EVP_CIPHER *EVP_idea_ecb(void); | ||
553 | EVP_CIPHER *EVP_idea_cfb(void); | ||
554 | EVP_CIPHER *EVP_idea_ofb(void); | ||
555 | EVP_CIPHER *EVP_idea_cbc(void); | ||
556 | EVP_CIPHER *EVP_rc2_ecb(void); | ||
557 | EVP_CIPHER *EVP_rc2_cbc(void); | ||
558 | EVP_CIPHER *EVP_rc2_40_cbc(void); | ||
559 | EVP_CIPHER *EVP_rc2_cfb(void); | ||
560 | EVP_CIPHER *EVP_rc2_ofb(void); | ||
561 | EVP_CIPHER *EVP_bf_ecb(void); | ||
562 | EVP_CIPHER *EVP_bf_cbc(void); | ||
563 | EVP_CIPHER *EVP_bf_cfb(void); | ||
564 | EVP_CIPHER *EVP_bf_ofb(void); | ||
565 | EVP_CIPHER *EVP_cast5_ecb(void); | ||
566 | EVP_CIPHER *EVP_cast5_cbc(void); | ||
567 | EVP_CIPHER *EVP_cast5_cfb(void); | ||
568 | EVP_CIPHER *EVP_cast5_ofb(void); | ||
569 | EVP_CIPHER *EVP_rc5_32_12_16_cbc(void); | ||
570 | EVP_CIPHER *EVP_rc5_32_12_16_ecb(void); | ||
571 | EVP_CIPHER *EVP_rc5_32_12_16_cfb(void); | ||
572 | EVP_CIPHER *EVP_rc5_32_12_16_ofb(void); | ||
573 | |||
574 | void SSLeay_add_all_algorithms(void); | ||
575 | void SSLeay_add_all_ciphers(void); | ||
576 | void SSLeay_add_all_digests(void); | ||
577 | |||
578 | int EVP_add_cipher(EVP_CIPHER *cipher); | ||
579 | int EVP_add_digest(EVP_MD *digest); | ||
580 | int EVP_add_alias(char *name,char *alias); | ||
581 | int EVP_delete_alias(char *name); | ||
582 | |||
583 | EVP_CIPHER *EVP_get_cipherbyname(char *name); | ||
584 | EVP_MD *EVP_get_digestbyname(char *name); | ||
585 | void EVP_cleanup(void); | ||
586 | |||
587 | int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key, | ||
588 | int enc_key_len,EVP_PKEY *private_key); | ||
589 | int EVP_PKEY_encrypt(unsigned char *enc_key, | ||
590 | unsigned char *key,int key_len,EVP_PKEY *pub_key); | ||
591 | int EVP_PKEY_type(int type); | ||
592 | int EVP_PKEY_bits(EVP_PKEY *pkey); | ||
593 | int EVP_PKEY_size(EVP_PKEY *pkey); | ||
594 | int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key); | ||
595 | EVP_PKEY * EVP_PKEY_new(void); | ||
596 | void EVP_PKEY_free(EVP_PKEY *pkey); | ||
597 | EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp, | ||
598 | long length); | ||
599 | int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp); | ||
600 | |||
601 | EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp, | ||
602 | long length); | ||
603 | int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp); | ||
604 | |||
605 | int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from); | ||
606 | int EVP_PKEY_missing_parameters(EVP_PKEY *pkey); | ||
607 | int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode); | ||
608 | int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b); | ||
609 | |||
610 | /* calls methods */ | ||
611 | int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
612 | int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
613 | |||
614 | /* These are used by EVP_CIPHER methods */ | ||
615 | int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); | ||
616 | int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); | ||
617 | |||
618 | #else | ||
619 | |||
620 | void EVP_DigestInit(); | ||
621 | void EVP_DigestUpdate(); | ||
622 | void EVP_DigestFinal(); | ||
623 | |||
624 | int EVP_read_pw_string(); | ||
625 | void EVP_set_pw_prompt(); | ||
626 | char * EVP_get_pw_prompt(); | ||
627 | |||
628 | int EVP_BytesToKey(); | ||
629 | |||
630 | EVP_CIPHER *EVP_get_cipherbyname(); | ||
631 | |||
632 | void EVP_EncryptInit(); | ||
633 | void EVP_EncryptUpdate(); | ||
634 | void EVP_EncryptFinal(); | ||
635 | |||
636 | void EVP_DecryptInit(); | ||
637 | void EVP_DecryptUpdate(); | ||
638 | int EVP_DecryptFinal(); | ||
639 | |||
640 | void EVP_CipherInit(); | ||
641 | void EVP_CipherUpdate(); | ||
642 | int EVP_CipherFinal(); | ||
643 | |||
644 | int EVP_SignFinal(); | ||
645 | |||
646 | int EVP_VerifyFinal(); | ||
647 | |||
648 | int EVP_OpenInit(); | ||
649 | int EVP_OpenFinal(); | ||
650 | |||
651 | int EVP_SealInit(); | ||
652 | void EVP_SealFinal(); | ||
653 | |||
654 | void EVP_EncodeInit(); | ||
655 | void EVP_EncodeUpdate(); | ||
656 | void EVP_EncodeFinal(); | ||
657 | int EVP_EncodeBlock(); | ||
658 | |||
659 | void EVP_DecodeInit(); | ||
660 | int EVP_DecodeUpdate(); | ||
661 | int EVP_DecodeFinal(); | ||
662 | int EVP_DecodeBlock(); | ||
663 | |||
664 | void ERR_load_EVP_strings(); | ||
665 | |||
666 | void EVP_CIPHER_CTX_init(); | ||
667 | void EVP_CIPHER_CTX_cleanup(); | ||
668 | |||
669 | #ifdef HEADER_BIO_H | ||
670 | BIO_METHOD *BIO_f_md(); | ||
671 | BIO_METHOD *BIO_f_base64(); | ||
672 | BIO_METHOD *BIO_f_cipher(); | ||
673 | void BIO_set_cipher(); | ||
674 | #endif | ||
675 | |||
676 | EVP_MD *EVP_md_null(); | ||
677 | EVP_MD *EVP_md2(); | ||
678 | EVP_MD *EVP_md5(); | ||
679 | EVP_MD *EVP_sha(); | ||
680 | EVP_MD *EVP_sha1(); | ||
681 | EVP_MD *EVP_dss(); | ||
682 | EVP_MD *EVP_dss1(); | ||
683 | EVP_MD *EVP_mdc2(); | ||
684 | |||
685 | EVP_CIPHER *EVP_enc_null(); | ||
686 | EVP_CIPHER *EVP_des_ecb(); | ||
687 | EVP_CIPHER *EVP_des_ede(); | ||
688 | EVP_CIPHER *EVP_des_ede3(); | ||
689 | EVP_CIPHER *EVP_des_cfb(); | ||
690 | EVP_CIPHER *EVP_des_ede_cfb(); | ||
691 | EVP_CIPHER *EVP_des_ede3_cfb(); | ||
692 | EVP_CIPHER *EVP_des_ofb(); | ||
693 | EVP_CIPHER *EVP_des_ede_ofb(); | ||
694 | EVP_CIPHER *EVP_des_ede3_ofb(); | ||
695 | EVP_CIPHER *EVP_des_cbc(); | ||
696 | EVP_CIPHER *EVP_des_ede_cbc(); | ||
697 | EVP_CIPHER *EVP_des_ede3_cbc(); | ||
698 | EVP_CIPHER *EVP_desx_cbc(); | ||
699 | EVP_CIPHER *EVP_rc4(); | ||
700 | EVP_CIPHER *EVP_rc4_40(); | ||
701 | EVP_CIPHER *EVP_idea_ecb(); | ||
702 | EVP_CIPHER *EVP_idea_cfb(); | ||
703 | EVP_CIPHER *EVP_idea_ofb(); | ||
704 | EVP_CIPHER *EVP_idea_cbc(); | ||
705 | EVP_CIPHER *EVP_rc2_ecb(); | ||
706 | EVP_CIPHER *EVP_rc2_cbc(); | ||
707 | EVP_CIPHER *EVP_rc2_40_cbc(); | ||
708 | EVP_CIPHER *EVP_rc2_cfb(); | ||
709 | EVP_CIPHER *EVP_rc2_ofb(); | ||
710 | EVP_CIPHER *EVP_bf_ecb(); | ||
711 | EVP_CIPHER *EVP_bf_cbc(); | ||
712 | EVP_CIPHER *EVP_bf_cfb(); | ||
713 | EVP_CIPHER *EVP_bf_ofb(); | ||
714 | EVP_CIPHER *EVP_cast5_ecb(); | ||
715 | EVP_CIPHER *EVP_cast5_cbc(); | ||
716 | EVP_CIPHER *EVP_cast5_cfb(); | ||
717 | EVP_CIPHER *EVP_cast5_ofb(); | ||
718 | EVP_CIPHER *EVP_rc5_32_12_16_cbc(); | ||
719 | EVP_CIPHER *EVP_rc5_32_12_16_ecb(); | ||
720 | EVP_CIPHER *EVP_rc5_32_12_16_cfb(); | ||
721 | EVP_CIPHER *EVP_rc5_32_12_16_ofb(); | ||
722 | |||
723 | void SSLeay_add_all_algorithms(); | ||
724 | void SSLeay_add_all_ciphers(); | ||
725 | void SSLeay_add_all_digests(); | ||
726 | |||
727 | int EVP_add_cipher(); | ||
728 | int EVP_add_digest(); | ||
729 | int EVP_add_alias(); | ||
730 | int EVP_delete_alias(); | ||
731 | |||
732 | EVP_CIPHER *EVP_get_cipherbyname(); | ||
733 | EVP_MD *EVP_get_digestbyname(); | ||
734 | void EVP_cleanup(); | ||
735 | |||
736 | int EVP_PKEY_decrypt(); | ||
737 | int EVP_PKEY_encrypt(); | ||
738 | int EVP_PKEY_type(); | ||
739 | int EVP_PKEY_bits(); | ||
740 | int EVP_PKEY_size(); | ||
741 | int EVP_PKEY_assign(); | ||
742 | EVP_PKEY * EVP_PKEY_new(); | ||
743 | void EVP_PKEY_free(); | ||
744 | EVP_PKEY * d2i_PublicKey(); | ||
745 | int i2d_PublicKey(); | ||
746 | |||
747 | EVP_PKEY * d2i_PrivateKey(); | ||
748 | int i2d_PrivateKey(); | ||
749 | |||
750 | int EVP_PKEY_copy_parameters(); | ||
751 | int EVP_PKEY_missing_parameters(); | ||
752 | int EVP_PKEY_save_parameters(); | ||
753 | int EVP_PKEY_cmp_parameters(); | ||
754 | |||
755 | int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
756 | int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
757 | |||
758 | int EVP_CIPHER_set_asn1_iv(); | ||
759 | int EVP_CIPHER_get_asn1_iv(); | ||
760 | |||
761 | #endif | ||
762 | |||
763 | /* BEGIN ERROR CODES */ | ||
764 | /* Error codes for the EVP functions. */ | ||
765 | |||
766 | /* Function codes. */ | ||
767 | #define EVP_F_D2I_PKEY 100 | ||
768 | #define EVP_F_EVP_DECRYPTFINAL 101 | ||
769 | #define EVP_F_EVP_OPENINIT 102 | ||
770 | #define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 | ||
771 | #define EVP_F_EVP_PKEY_DECRYPT 104 | ||
772 | #define EVP_F_EVP_PKEY_ENCRYPT 105 | ||
773 | #define EVP_F_EVP_PKEY_NEW 106 | ||
774 | #define EVP_F_EVP_SIGNFINAL 107 | ||
775 | #define EVP_F_EVP_VERIFYFINAL 108 | ||
776 | |||
777 | /* Reason codes. */ | ||
778 | #define EVP_R_BAD_DECRYPT 100 | ||
779 | #define EVP_R_DIFFERENT_KEY_TYPES 101 | ||
780 | #define EVP_R_IV_TOO_LARGE 102 | ||
781 | #define EVP_R_MISSING_PARMATERS 103 | ||
782 | #define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104 | ||
783 | #define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105 | ||
784 | #define EVP_R_PUBLIC_KEY_NOT_RSA 106 | ||
785 | #define EVP_R_UNSUPPORTED_CIPHER 107 | ||
786 | #define EVP_R_WRONG_FINAL_BLOCK_LENGTH 108 | ||
787 | #define EVP_R_WRONG_PUBLIC_KEY_TYPE 109 | ||
788 | |||
789 | #ifdef __cplusplus | ||
790 | } | ||
791 | #endif | ||
792 | #endif | ||
793 | |||
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c new file mode 100644 index 0000000000..93cc3a9464 --- /dev/null +++ b/src/lib/libcrypto/evp/evp_enc.c | |||
@@ -0,0 +1,303 @@ | |||
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 "evp.h" | ||
62 | |||
63 | char *EVP_version="EVP part of SSLeay 0.9.0b 29-Jun-1998"; | ||
64 | |||
65 | void EVP_CIPHER_CTX_init(ctx) | ||
66 | EVP_CIPHER_CTX *ctx; | ||
67 | { | ||
68 | memset(ctx,0,sizeof(EVP_CIPHER_CTX)); | ||
69 | /* ctx->cipher=NULL; */ | ||
70 | } | ||
71 | |||
72 | void EVP_CipherInit(ctx,data,key,iv,enc) | ||
73 | EVP_CIPHER_CTX *ctx; | ||
74 | EVP_CIPHER *data; | ||
75 | unsigned char *key; | ||
76 | unsigned char *iv; | ||
77 | int enc; | ||
78 | { | ||
79 | if (enc) | ||
80 | EVP_EncryptInit(ctx,data,key,iv); | ||
81 | else | ||
82 | EVP_DecryptInit(ctx,data,key,iv); | ||
83 | } | ||
84 | |||
85 | void EVP_CipherUpdate(ctx,out,outl,in,inl) | ||
86 | EVP_CIPHER_CTX *ctx; | ||
87 | unsigned char *out; | ||
88 | int *outl; | ||
89 | unsigned char *in; | ||
90 | int inl; | ||
91 | { | ||
92 | if (ctx->encrypt) | ||
93 | EVP_EncryptUpdate(ctx,out,outl,in,inl); | ||
94 | else EVP_DecryptUpdate(ctx,out,outl,in,inl); | ||
95 | } | ||
96 | |||
97 | int EVP_CipherFinal(ctx,out,outl) | ||
98 | EVP_CIPHER_CTX *ctx; | ||
99 | unsigned char *out; | ||
100 | int *outl; | ||
101 | { | ||
102 | if (ctx->encrypt) | ||
103 | { | ||
104 | EVP_EncryptFinal(ctx,out,outl); | ||
105 | return(1); | ||
106 | } | ||
107 | else return(EVP_DecryptFinal(ctx,out,outl)); | ||
108 | } | ||
109 | |||
110 | void EVP_EncryptInit(ctx,cipher,key,iv) | ||
111 | EVP_CIPHER_CTX *ctx; | ||
112 | EVP_CIPHER *cipher; | ||
113 | unsigned char *key; | ||
114 | unsigned char *iv; | ||
115 | { | ||
116 | if (cipher != NULL) | ||
117 | ctx->cipher=cipher; | ||
118 | ctx->cipher->init(ctx,key,iv,1); | ||
119 | ctx->encrypt=1; | ||
120 | ctx->buf_len=0; | ||
121 | } | ||
122 | |||
123 | void EVP_DecryptInit(ctx,cipher,key,iv) | ||
124 | EVP_CIPHER_CTX *ctx; | ||
125 | EVP_CIPHER *cipher; | ||
126 | unsigned char *key; | ||
127 | unsigned char *iv; | ||
128 | { | ||
129 | if (cipher != NULL) | ||
130 | ctx->cipher=cipher; | ||
131 | ctx->cipher->init(ctx,key,iv,0); | ||
132 | ctx->encrypt=0; | ||
133 | ctx->buf_len=0; | ||
134 | } | ||
135 | |||
136 | |||
137 | void EVP_EncryptUpdate(ctx,out,outl,in,inl) | ||
138 | EVP_CIPHER_CTX *ctx; | ||
139 | unsigned char *out; | ||
140 | int *outl; | ||
141 | unsigned char *in; | ||
142 | int inl; | ||
143 | { | ||
144 | int i,j,bl; | ||
145 | |||
146 | i=ctx->buf_len; | ||
147 | bl=ctx->cipher->block_size; | ||
148 | *outl=0; | ||
149 | if ((inl == 0) && (i != bl)) return; | ||
150 | if (i != 0) | ||
151 | { | ||
152 | if (i+inl < bl) | ||
153 | { | ||
154 | memcpy(&(ctx->buf[i]),in,inl); | ||
155 | ctx->buf_len+=inl; | ||
156 | return; | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | j=bl-i; | ||
161 | if (j != 0) memcpy(&(ctx->buf[i]),in,j); | ||
162 | ctx->cipher->do_cipher(ctx,out,ctx->buf,bl); | ||
163 | inl-=j; | ||
164 | in+=j; | ||
165 | out+=bl; | ||
166 | *outl+=bl; | ||
167 | } | ||
168 | } | ||
169 | i=inl%bl; /* how much is left */ | ||
170 | inl-=i; | ||
171 | if (inl > 0) | ||
172 | { | ||
173 | ctx->cipher->do_cipher(ctx,out,in,inl); | ||
174 | *outl+=inl; | ||
175 | } | ||
176 | |||
177 | if (i != 0) | ||
178 | memcpy(ctx->buf,&(in[inl]),i); | ||
179 | ctx->buf_len=i; | ||
180 | } | ||
181 | |||
182 | void EVP_EncryptFinal(ctx,out,outl) | ||
183 | EVP_CIPHER_CTX *ctx; | ||
184 | unsigned char *out; | ||
185 | int *outl; | ||
186 | { | ||
187 | int i,n,b,bl; | ||
188 | |||
189 | b=ctx->cipher->block_size; | ||
190 | if (b == 1) | ||
191 | { | ||
192 | *outl=0; | ||
193 | return; | ||
194 | } | ||
195 | bl=ctx->buf_len; | ||
196 | n=b-bl; | ||
197 | for (i=bl; i<b; i++) | ||
198 | ctx->buf[i]=n; | ||
199 | ctx->cipher->do_cipher(ctx,out,ctx->buf,b); | ||
200 | *outl=b; | ||
201 | } | ||
202 | |||
203 | void EVP_DecryptUpdate(ctx,out,outl,in,inl) | ||
204 | EVP_CIPHER_CTX *ctx; | ||
205 | unsigned char *out; | ||
206 | int *outl; | ||
207 | unsigned char *in; | ||
208 | int inl; | ||
209 | { | ||
210 | int b,bl,n; | ||
211 | int keep_last=0; | ||
212 | |||
213 | *outl=0; | ||
214 | if (inl == 0) return; | ||
215 | |||
216 | b=ctx->cipher->block_size; | ||
217 | if (b > 1) | ||
218 | { | ||
219 | /* Is the input a multiple of the block size? */ | ||
220 | bl=ctx->buf_len; | ||
221 | n=inl+bl; | ||
222 | if (n%b == 0) | ||
223 | { | ||
224 | if (inl < b) /* must be 'just one' buff */ | ||
225 | { | ||
226 | memcpy(&(ctx->buf[bl]),in,inl); | ||
227 | ctx->buf_len=b; | ||
228 | *outl=0; | ||
229 | return; | ||
230 | } | ||
231 | keep_last=1; | ||
232 | inl-=b; /* don't do the last block */ | ||
233 | } | ||
234 | } | ||
235 | EVP_EncryptUpdate(ctx,out,outl,in,inl); | ||
236 | |||
237 | /* if we have 'decrypted' a multiple of block size, make sure | ||
238 | * we have a copy of this last block */ | ||
239 | if (keep_last) | ||
240 | { | ||
241 | memcpy(&(ctx->buf[0]),&(in[inl]),b); | ||
242 | #ifdef DEBUG | ||
243 | if (ctx->buf_len != 0) | ||
244 | { | ||
245 | abort(); | ||
246 | } | ||
247 | #endif | ||
248 | ctx->buf_len=b; | ||
249 | } | ||
250 | } | ||
251 | |||
252 | int EVP_DecryptFinal(ctx,out,outl) | ||
253 | EVP_CIPHER_CTX *ctx; | ||
254 | unsigned char *out; | ||
255 | int *outl; | ||
256 | { | ||
257 | int i,b; | ||
258 | int n; | ||
259 | |||
260 | *outl=0; | ||
261 | b=ctx->cipher->block_size; | ||
262 | if (b > 1) | ||
263 | { | ||
264 | if (ctx->buf_len != b) | ||
265 | { | ||
266 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); | ||
267 | return(0); | ||
268 | } | ||
269 | EVP_EncryptUpdate(ctx,ctx->buf,&n,ctx->buf,0); | ||
270 | if (n != b) | ||
271 | return(0); | ||
272 | n=ctx->buf[b-1]; | ||
273 | if (n > b) | ||
274 | { | ||
275 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT); | ||
276 | return(0); | ||
277 | } | ||
278 | for (i=0; i<n; i++) | ||
279 | { | ||
280 | if (ctx->buf[--b] != n) | ||
281 | { | ||
282 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT); | ||
283 | return(0); | ||
284 | } | ||
285 | } | ||
286 | n=ctx->cipher->block_size-n; | ||
287 | for (i=0; i<n; i++) | ||
288 | out[i]=ctx->buf[i]; | ||
289 | *outl=n; | ||
290 | } | ||
291 | else | ||
292 | *outl=0; | ||
293 | return(1); | ||
294 | } | ||
295 | |||
296 | void EVP_CIPHER_CTX_cleanup(c) | ||
297 | EVP_CIPHER_CTX *c; | ||
298 | { | ||
299 | if ((c->cipher != NULL) && (c->cipher->cleanup != NULL)) | ||
300 | c->cipher->cleanup(c); | ||
301 | memset(c,0,sizeof(EVP_CIPHER_CTX)); | ||
302 | } | ||
303 | |||
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c new file mode 100644 index 0000000000..2b0a0ab93f --- /dev/null +++ b/src/lib/libcrypto/evp/evp_err.c | |||
@@ -0,0 +1,108 @@ | |||
1 | /* lib/evp/evp_err.c */ | ||
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | #include <stdio.h> | ||
59 | #include "err.h" | ||
60 | #include "evp.h" | ||
61 | |||
62 | /* BEGIN ERROR CODES */ | ||
63 | #ifndef NO_ERR | ||
64 | static ERR_STRING_DATA EVP_str_functs[]= | ||
65 | { | ||
66 | {ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"}, | ||
67 | {ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"}, | ||
68 | {ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"}, | ||
69 | {ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"}, | ||
70 | {ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"}, | ||
71 | {ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"}, | ||
72 | {ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"}, | ||
73 | {ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"}, | ||
74 | {ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"}, | ||
75 | {0,NULL}, | ||
76 | }; | ||
77 | |||
78 | static ERR_STRING_DATA EVP_str_reasons[]= | ||
79 | { | ||
80 | {EVP_R_BAD_DECRYPT ,"bad decrypt"}, | ||
81 | {EVP_R_DIFFERENT_KEY_TYPES ,"different key types"}, | ||
82 | {EVP_R_IV_TOO_LARGE ,"iv too large"}, | ||
83 | {EVP_R_MISSING_PARMATERS ,"missing parmaters"}, | ||
84 | {EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"}, | ||
85 | {EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"}, | ||
86 | {EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"}, | ||
87 | {EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, | ||
88 | {EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"}, | ||
89 | {EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"}, | ||
90 | {0,NULL}, | ||
91 | }; | ||
92 | |||
93 | #endif | ||
94 | |||
95 | void ERR_load_EVP_strings() | ||
96 | { | ||
97 | static int init=1; | ||
98 | |||
99 | if (init); | ||
100 | {; | ||
101 | init=0; | ||
102 | #ifndef NO_ERR | ||
103 | ERR_load_strings(ERR_LIB_EVP,EVP_str_functs); | ||
104 | ERR_load_strings(ERR_LIB_EVP,EVP_str_reasons); | ||
105 | #endif | ||
106 | |||
107 | } | ||
108 | } | ||
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c new file mode 100644 index 0000000000..dafa686f64 --- /dev/null +++ b/src/lib/libcrypto/evp/evp_key.c | |||
@@ -0,0 +1,167 @@ | |||
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 "x509.h" | ||
62 | #include "objects.h" | ||
63 | #include "evp.h" | ||
64 | |||
65 | /* should be init to zeros. */ | ||
66 | static char prompt_string[80]; | ||
67 | |||
68 | void EVP_set_pw_prompt(prompt) | ||
69 | char *prompt; | ||
70 | { | ||
71 | if (prompt == NULL) | ||
72 | prompt_string[0]='\0'; | ||
73 | else | ||
74 | strncpy(prompt_string,prompt,79); | ||
75 | } | ||
76 | |||
77 | char *EVP_get_pw_prompt() | ||
78 | { | ||
79 | if (prompt_string[0] == '\0') | ||
80 | return(NULL); | ||
81 | else | ||
82 | return(prompt_string); | ||
83 | } | ||
84 | |||
85 | #ifdef NO_DES | ||
86 | int des_read_pw_string(char *buf,int len,char *prompt,int verify); | ||
87 | #endif | ||
88 | |||
89 | int EVP_read_pw_string(buf,len,prompt,verify) | ||
90 | char *buf; | ||
91 | int len; | ||
92 | char *prompt; | ||
93 | int verify; | ||
94 | { | ||
95 | if ((prompt == NULL) && (prompt_string[0] != '\0')) | ||
96 | prompt=prompt_string; | ||
97 | return(des_read_pw_string(buf,len,prompt,verify)); | ||
98 | } | ||
99 | |||
100 | int EVP_BytesToKey(type,md,salt,data,datal,count,key,iv) | ||
101 | EVP_CIPHER *type; | ||
102 | EVP_MD *md; | ||
103 | unsigned char *salt; | ||
104 | unsigned char *data; | ||
105 | int datal; | ||
106 | int count; | ||
107 | unsigned char *key; | ||
108 | unsigned char *iv; | ||
109 | { | ||
110 | EVP_MD_CTX c; | ||
111 | unsigned char md_buf[EVP_MAX_MD_SIZE]; | ||
112 | int niv,nkey,addmd=0; | ||
113 | unsigned int mds=0,i; | ||
114 | |||
115 | nkey=type->key_len; | ||
116 | niv=type->iv_len; | ||
117 | |||
118 | if (data == NULL) return(nkey); | ||
119 | |||
120 | for (;;) | ||
121 | { | ||
122 | EVP_DigestInit(&c,md); | ||
123 | if (addmd++) | ||
124 | EVP_DigestUpdate(&c,&(md_buf[0]),mds); | ||
125 | EVP_DigestUpdate(&c,data,datal); | ||
126 | if (salt != NULL) | ||
127 | EVP_DigestUpdate(&c,salt,8); | ||
128 | EVP_DigestFinal(&c,&(md_buf[0]),&mds); | ||
129 | |||
130 | for (i=1; i<(unsigned int)count; i++) | ||
131 | { | ||
132 | EVP_DigestInit(&c,md); | ||
133 | EVP_DigestUpdate(&c,&(md_buf[0]),mds); | ||
134 | EVP_DigestFinal(&c,&(md_buf[0]),&mds); | ||
135 | } | ||
136 | i=0; | ||
137 | if (nkey) | ||
138 | { | ||
139 | for (;;) | ||
140 | { | ||
141 | if (nkey == 0) break; | ||
142 | if (i == mds) break; | ||
143 | if (key != NULL) | ||
144 | *(key++)=md_buf[i]; | ||
145 | nkey--; | ||
146 | i++; | ||
147 | } | ||
148 | } | ||
149 | if (niv && (i != mds)) | ||
150 | { | ||
151 | for (;;) | ||
152 | { | ||
153 | if (niv == 0) break; | ||
154 | if (i == mds) break; | ||
155 | if (iv != NULL) | ||
156 | *(iv++)=md_buf[i]; | ||
157 | niv--; | ||
158 | i++; | ||
159 | } | ||
160 | } | ||
161 | if ((nkey == 0) && (niv == 0)) break; | ||
162 | } | ||
163 | memset(&c,0,sizeof(c)); | ||
164 | memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE); | ||
165 | return(type->key_len); | ||
166 | } | ||
167 | |||
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c new file mode 100644 index 0000000000..69784eb555 --- /dev/null +++ b/src/lib/libcrypto/evp/evp_lib.c | |||
@@ -0,0 +1,117 @@ | |||
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 "evp.h" | ||
62 | #include "objects.h" | ||
63 | |||
64 | int EVP_CIPHER_param_to_asn1(c,type) | ||
65 | EVP_CIPHER_CTX *c; | ||
66 | ASN1_TYPE *type; | ||
67 | { | ||
68 | int ret; | ||
69 | |||
70 | if (c->cipher->set_asn1_parameters != NULL) | ||
71 | ret=c->cipher->set_asn1_parameters(c,type); | ||
72 | else | ||
73 | ret=1; | ||
74 | return(ret); | ||
75 | } | ||
76 | |||
77 | int EVP_CIPHER_asn1_to_param(c,type) | ||
78 | EVP_CIPHER_CTX *c; | ||
79 | ASN1_TYPE *type; | ||
80 | { | ||
81 | int ret; | ||
82 | |||
83 | if (c->cipher->get_asn1_parameters != NULL) | ||
84 | ret=c->cipher->get_asn1_parameters(c,type); | ||
85 | else | ||
86 | ret=1; | ||
87 | return(ret); | ||
88 | } | ||
89 | |||
90 | int EVP_CIPHER_get_asn1_iv(c,type) | ||
91 | EVP_CIPHER_CTX *c; | ||
92 | ASN1_TYPE *type; | ||
93 | { | ||
94 | int i=0,l; | ||
95 | |||
96 | if (type != NULL) | ||
97 | { | ||
98 | l=EVP_CIPHER_CTX_iv_length(c); | ||
99 | i=ASN1_TYPE_get_octetstring(type,c->oiv,l); | ||
100 | memcpy(c->iv,c->oiv,l); | ||
101 | } | ||
102 | return(i); | ||
103 | } | ||
104 | |||
105 | int EVP_CIPHER_set_asn1_iv(c,type) | ||
106 | EVP_CIPHER_CTX *c; | ||
107 | ASN1_TYPE *type; | ||
108 | { | ||
109 | int i=0,j; | ||
110 | |||
111 | if (type != NULL) | ||
112 | { | ||
113 | j=EVP_CIPHER_CTX_iv_length(c); | ||
114 | i=ASN1_TYPE_set_octetstring(type,c->oiv,j); | ||
115 | } | ||
116 | return(i); | ||
117 | } | ||
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c new file mode 100644 index 0000000000..3549b1699c --- /dev/null +++ b/src/lib/libcrypto/evp/m_dss.c | |||
@@ -0,0 +1,82 @@ | |||
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 "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | static EVP_MD dsa_md= | ||
66 | { | ||
67 | NID_dsaWithSHA, | ||
68 | NID_dsaWithSHA, | ||
69 | SHA_DIGEST_LENGTH, | ||
70 | SHA1_Init, | ||
71 | SHA1_Update, | ||
72 | SHA1_Final, | ||
73 | EVP_PKEY_DSA_method, | ||
74 | SHA_CBLOCK, | ||
75 | sizeof(EVP_MD *)+sizeof(SHA_CTX), | ||
76 | }; | ||
77 | |||
78 | EVP_MD *EVP_dss() | ||
79 | { | ||
80 | return(&dsa_md); | ||
81 | } | ||
82 | |||
diff --git a/src/lib/libcrypto/evp/m_dss1.c b/src/lib/libcrypto/evp/m_dss1.c new file mode 100644 index 0000000000..ff256b7b20 --- /dev/null +++ b/src/lib/libcrypto/evp/m_dss1.c | |||
@@ -0,0 +1,81 @@ | |||
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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | static EVP_MD dss1_md= | ||
66 | { | ||
67 | NID_dsa, | ||
68 | NID_dsaWithSHA1, | ||
69 | SHA_DIGEST_LENGTH, | ||
70 | SHA1_Init, | ||
71 | SHA1_Update, | ||
72 | SHA1_Final, | ||
73 | EVP_PKEY_DSA_method, | ||
74 | SHA_CBLOCK, | ||
75 | sizeof(EVP_MD *)+sizeof(SHA_CTX), | ||
76 | }; | ||
77 | |||
78 | EVP_MD *EVP_dss1() | ||
79 | { | ||
80 | return(&dss1_md); | ||
81 | } | ||
diff --git a/src/lib/libcrypto/evp/m_md5.c b/src/lib/libcrypto/evp/m_md5.c new file mode 100644 index 0000000000..d65db9aa1d --- /dev/null +++ b/src/lib/libcrypto/evp/m_md5.c | |||
@@ -0,0 +1,81 @@ | |||
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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | static EVP_MD md5_md= | ||
66 | { | ||
67 | NID_md5, | ||
68 | NID_md5WithRSAEncryption, | ||
69 | MD5_DIGEST_LENGTH, | ||
70 | MD5_Init, | ||
71 | MD5_Update, | ||
72 | MD5_Final, | ||
73 | EVP_PKEY_RSA_method, | ||
74 | MD5_CBLOCK, | ||
75 | sizeof(EVP_MD *)+sizeof(MD5_CTX), | ||
76 | }; | ||
77 | |||
78 | EVP_MD *EVP_md5() | ||
79 | { | ||
80 | return(&md5_md); | ||
81 | } | ||
diff --git a/src/lib/libcrypto/evp/m_null.c b/src/lib/libcrypto/evp/m_null.c new file mode 100644 index 0000000000..6d80560df2 --- /dev/null +++ b/src/lib/libcrypto/evp/m_null.c | |||
@@ -0,0 +1,88 @@ | |||
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 "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | static void function() | ||
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() | ||
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 new file mode 100644 index 0000000000..04c5d8897b --- /dev/null +++ b/src/lib/libcrypto/evp/m_ripemd.c | |||
@@ -0,0 +1,81 @@ | |||
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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | static EVP_MD ripemd160_md= | ||
66 | { | ||
67 | NID_ripemd160, | ||
68 | NID_ripemd160WithRSA, | ||
69 | RIPEMD160_DIGEST_LENGTH, | ||
70 | RIPEMD160_Init, | ||
71 | RIPEMD160_Update, | ||
72 | RIPEMD160_Final, | ||
73 | EVP_PKEY_RSA_method, | ||
74 | RIPEMD160_CBLOCK, | ||
75 | sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX), | ||
76 | }; | ||
77 | |||
78 | EVP_MD *EVP_ripemd160() | ||
79 | { | ||
80 | return(&ripemd160_md); | ||
81 | } | ||
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c new file mode 100644 index 0000000000..87135a9cf2 --- /dev/null +++ b/src/lib/libcrypto/evp/m_sha1.c | |||
@@ -0,0 +1,81 @@ | |||
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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | static EVP_MD sha1_md= | ||
66 | { | ||
67 | NID_sha1, | ||
68 | NID_sha1WithRSAEncryption, | ||
69 | SHA_DIGEST_LENGTH, | ||
70 | SHA1_Init, | ||
71 | SHA1_Update, | ||
72 | SHA1_Final, | ||
73 | EVP_PKEY_RSA_method, | ||
74 | SHA_CBLOCK, | ||
75 | sizeof(EVP_MD *)+sizeof(SHA_CTX), | ||
76 | }; | ||
77 | |||
78 | EVP_MD *EVP_sha1() | ||
79 | { | ||
80 | return(&sha1_md); | ||
81 | } | ||
diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c new file mode 100644 index 0000000000..e0774da20d --- /dev/null +++ b/src/lib/libcrypto/evp/names.c | |||
@@ -0,0 +1,285 @@ | |||
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 "evp.h" | ||
62 | #include "objects.h" | ||
63 | |||
64 | typedef struct aliases_st { | ||
65 | char *alias; | ||
66 | /* This must be the last field becaue I will allocate things | ||
67 | * so they go off the end of it */ | ||
68 | char name[4]; | ||
69 | } ALIASES; | ||
70 | |||
71 | static STACK /* ALIASES */ *aliases=NULL; | ||
72 | static STACK /* EVP_CIPHERS */ *ciphers=NULL; | ||
73 | static STACK /* EVP_MD */ *digests=NULL; | ||
74 | |||
75 | static int cipher_nid_cmp(a,b) | ||
76 | EVP_CIPHER **a,**b; | ||
77 | { return((*a)->nid - (*b)->nid); } | ||
78 | |||
79 | static int digest_type_cmp(a,b) | ||
80 | EVP_MD **a,**b; | ||
81 | { return((*a)->pkey_type - (*b)->pkey_type); } | ||
82 | |||
83 | int EVP_add_cipher(c) | ||
84 | EVP_CIPHER *c; | ||
85 | { | ||
86 | int i; | ||
87 | |||
88 | if (ciphers == NULL) | ||
89 | { | ||
90 | ciphers=sk_new(cipher_nid_cmp); | ||
91 | if (ciphers == NULL) return(0); | ||
92 | } | ||
93 | if ((i=sk_find(ciphers,(char *)c)) >= 0) | ||
94 | { | ||
95 | if (sk_value(ciphers,i) == (char *)c) | ||
96 | return(1); | ||
97 | sk_delete(ciphers,i); | ||
98 | } | ||
99 | return(sk_push(ciphers,(char *)c)); | ||
100 | } | ||
101 | |||
102 | int EVP_add_digest(md) | ||
103 | EVP_MD *md; | ||
104 | { | ||
105 | int i; | ||
106 | char *n; | ||
107 | |||
108 | if (digests == NULL) | ||
109 | { | ||
110 | digests=sk_new(digest_type_cmp); | ||
111 | if (digests == NULL) return(0); | ||
112 | } | ||
113 | if ((i=sk_find(digests,(char *)md)) >= 0) | ||
114 | { | ||
115 | if (sk_value(digests,i) == (char *)md) | ||
116 | return(1); | ||
117 | sk_delete(digests,i); | ||
118 | } | ||
119 | if (md->type != md->pkey_type) | ||
120 | { | ||
121 | n=OBJ_nid2sn(md->pkey_type); | ||
122 | EVP_add_alias(n,OBJ_nid2sn(md->type)); | ||
123 | EVP_add_alias(n,OBJ_nid2ln(md->type)); | ||
124 | } | ||
125 | sk_push(digests,(char *)md); | ||
126 | return(1); | ||
127 | } | ||
128 | |||
129 | static int alias_cmp(a,b) | ||
130 | ALIASES **a,**b; | ||
131 | { | ||
132 | return(strcmp((*a)->alias,(*b)->alias)); | ||
133 | } | ||
134 | |||
135 | int EVP_add_alias(name,aname) | ||
136 | char *name; | ||
137 | char *aname; | ||
138 | { | ||
139 | int l1,l2,i; | ||
140 | ALIASES *a; | ||
141 | char *p; | ||
142 | |||
143 | if ((name == NULL) || (aname == NULL)) return(0); | ||
144 | l1=strlen(name)+1; | ||
145 | l2=strlen(aname)+1; | ||
146 | i=sizeof(ALIASES)+l1+l2; | ||
147 | if ((a=(ALIASES *)Malloc(i)) == NULL) | ||
148 | return(0); | ||
149 | strcpy(a->name,name); | ||
150 | p= &(a->name[l1]); | ||
151 | strcpy(p,aname); | ||
152 | a->alias=p; | ||
153 | |||
154 | if (aliases == NULL) | ||
155 | { | ||
156 | aliases=sk_new(alias_cmp); | ||
157 | if (aliases == NULL) goto err; | ||
158 | } | ||
159 | |||
160 | if ((i=sk_find(aliases,(char *)a)) >= 0) | ||
161 | { | ||
162 | Free(sk_delete(aliases,i)); | ||
163 | } | ||
164 | if (!sk_push(aliases,(char *)a)) goto err; | ||
165 | return(1); | ||
166 | err: | ||
167 | return(0); | ||
168 | } | ||
169 | |||
170 | int EVP_delete_alias(name) | ||
171 | char *name; | ||
172 | { | ||
173 | ALIASES a; | ||
174 | int i; | ||
175 | |||
176 | if (aliases != NULL) | ||
177 | { | ||
178 | a.alias=name; | ||
179 | if ((i=sk_find(aliases,(char *)&a)) >= 0) | ||
180 | { | ||
181 | Free(sk_delete(aliases,i)); | ||
182 | return(1); | ||
183 | } | ||
184 | } | ||
185 | return(0); | ||
186 | } | ||
187 | |||
188 | EVP_CIPHER *EVP_get_cipherbyname(name) | ||
189 | char *name; | ||
190 | { | ||
191 | int nid,num=6,i; | ||
192 | EVP_CIPHER c,*cp; | ||
193 | ALIASES a,*ap; | ||
194 | |||
195 | if (ciphers == NULL) return(NULL); | ||
196 | for (;;) | ||
197 | { | ||
198 | if (num-- <= 0) return(NULL); | ||
199 | if (aliases != NULL) | ||
200 | { | ||
201 | a.alias=name; | ||
202 | i=sk_find(aliases,(char *)&a); | ||
203 | if (i >= 0) | ||
204 | { | ||
205 | ap=(ALIASES *)sk_value(aliases,i); | ||
206 | name=ap->name; | ||
207 | continue; | ||
208 | } | ||
209 | } | ||
210 | |||
211 | nid=OBJ_txt2nid(name); | ||
212 | if (nid == NID_undef) return(NULL); | ||
213 | c.nid=nid; | ||
214 | i=sk_find(ciphers,(char *)&c); | ||
215 | if (i >= 0) | ||
216 | { | ||
217 | cp=(EVP_CIPHER *)sk_value(ciphers,i); | ||
218 | return(cp); | ||
219 | } | ||
220 | else | ||
221 | return(NULL); | ||
222 | } | ||
223 | } | ||
224 | |||
225 | EVP_MD *EVP_get_digestbyname(name) | ||
226 | char *name; | ||
227 | { | ||
228 | int nid,num=6,i; | ||
229 | EVP_MD c,*cp; | ||
230 | ALIASES a,*ap; | ||
231 | |||
232 | if (digests == NULL) return(NULL); | ||
233 | |||
234 | for (;;) | ||
235 | { | ||
236 | if (num-- <= 0) return(NULL); | ||
237 | |||
238 | if (aliases != NULL) | ||
239 | { | ||
240 | a.alias=name; | ||
241 | i=sk_find(aliases,(char *)&a); | ||
242 | if (i >= 0) | ||
243 | { | ||
244 | ap=(ALIASES *)sk_value(aliases,i); | ||
245 | name=ap->name; | ||
246 | continue; | ||
247 | } | ||
248 | } | ||
249 | |||
250 | nid=OBJ_txt2nid(name); | ||
251 | if (nid == NID_undef) return(NULL); | ||
252 | c.pkey_type=nid; | ||
253 | i=sk_find(digests,(char *)&c); | ||
254 | if (i >= 0) | ||
255 | { | ||
256 | cp=(EVP_MD *)sk_value(digests,i); | ||
257 | return(cp); | ||
258 | } | ||
259 | else | ||
260 | return(NULL); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | void EVP_cleanup() | ||
265 | { | ||
266 | int i; | ||
267 | |||
268 | if (aliases != NULL) | ||
269 | { | ||
270 | for (i=0; i<sk_num(aliases); i++) | ||
271 | Free(sk_value(aliases,i)); | ||
272 | sk_free(aliases); | ||
273 | aliases=NULL; | ||
274 | } | ||
275 | if (ciphers != NULL) | ||
276 | { | ||
277 | sk_free(ciphers); | ||
278 | ciphers=NULL; | ||
279 | } | ||
280 | if (digests != NULL) | ||
281 | { | ||
282 | sk_free(digests); | ||
283 | digests=NULL; | ||
284 | } | ||
285 | } | ||
diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c new file mode 100644 index 0000000000..e845ce70c7 --- /dev/null +++ b/src/lib/libcrypto/evp/p_dec.c | |||
@@ -0,0 +1,84 @@ | |||
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 "rand.h" | ||
62 | #include "rsa.h" | ||
63 | #include "evp.h" | ||
64 | #include "objects.h" | ||
65 | #include "x509.h" | ||
66 | |||
67 | int EVP_PKEY_decrypt(key,ek,ekl,priv) | ||
68 | unsigned char *key; | ||
69 | unsigned char *ek; | ||
70 | int ekl; | ||
71 | EVP_PKEY *priv; | ||
72 | { | ||
73 | int ret= -1; | ||
74 | |||
75 | if (priv->type != EVP_PKEY_RSA) | ||
76 | { | ||
77 | EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA); | ||
78 | goto err; | ||
79 | } | ||
80 | |||
81 | ret=RSA_private_decrypt(ekl,ek,key,priv->pkey.rsa,RSA_PKCS1_PADDING); | ||
82 | err: | ||
83 | return(ret); | ||
84 | } | ||
diff --git a/src/lib/libcrypto/evp/p_enc.c b/src/lib/libcrypto/evp/p_enc.c new file mode 100644 index 0000000000..a26bfad02a --- /dev/null +++ b/src/lib/libcrypto/evp/p_enc.c | |||
@@ -0,0 +1,83 @@ | |||
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 "rand.h" | ||
62 | #include "rsa.h" | ||
63 | #include "evp.h" | ||
64 | #include "objects.h" | ||
65 | #include "x509.h" | ||
66 | |||
67 | int EVP_PKEY_encrypt(ek,key,key_len,pubk) | ||
68 | unsigned char *ek; | ||
69 | unsigned char *key; | ||
70 | int key_len; | ||
71 | EVP_PKEY *pubk; | ||
72 | { | ||
73 | int ret=0; | ||
74 | |||
75 | if (pubk->type != EVP_PKEY_RSA) | ||
76 | { | ||
77 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA); | ||
78 | goto err; | ||
79 | } | ||
80 | ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING); | ||
81 | err: | ||
82 | return(ret); | ||
83 | } | ||
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c new file mode 100644 index 0000000000..395351b373 --- /dev/null +++ b/src/lib/libcrypto/evp/p_lib.c | |||
@@ -0,0 +1,294 @@ | |||
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 "objects.h" | ||
62 | #include "evp.h" | ||
63 | #include "asn1_mac.h" | ||
64 | #include "x509.h" | ||
65 | |||
66 | /* EVPerr(EVP_F_D2I_PKEY,EVP_R_UNSUPPORTED_CIPHER); */ | ||
67 | /* EVPerr(EVP_F_D2I_PKEY,EVP_R_IV_TOO_LARGE); */ | ||
68 | |||
69 | #ifndef NOPROTO | ||
70 | static void EVP_PKEY_free_it(EVP_PKEY *x); | ||
71 | #else | ||
72 | static void EVP_PKEY_free_it(); | ||
73 | #endif | ||
74 | |||
75 | int EVP_PKEY_bits(pkey) | ||
76 | EVP_PKEY *pkey; | ||
77 | { | ||
78 | #ifndef NO_RSA | ||
79 | if (pkey->type == EVP_PKEY_RSA) | ||
80 | return(BN_num_bits(pkey->pkey.rsa->n)); | ||
81 | else | ||
82 | #endif | ||
83 | #ifndef NO_DSA | ||
84 | if (pkey->type == EVP_PKEY_DSA) | ||
85 | return(BN_num_bits(pkey->pkey.dsa->p)); | ||
86 | #endif | ||
87 | return(0); | ||
88 | } | ||
89 | |||
90 | int EVP_PKEY_size(pkey) | ||
91 | EVP_PKEY *pkey; | ||
92 | { | ||
93 | #ifndef NO_RSA | ||
94 | if (pkey->type == EVP_PKEY_RSA) | ||
95 | return(RSA_size(pkey->pkey.rsa)); | ||
96 | else | ||
97 | #endif | ||
98 | #ifndef NO_DSA | ||
99 | if (pkey->type == EVP_PKEY_DSA) | ||
100 | return(DSA_size(pkey->pkey.dsa)); | ||
101 | #endif | ||
102 | return(0); | ||
103 | } | ||
104 | |||
105 | int EVP_PKEY_save_parameters(pkey,mode) | ||
106 | EVP_PKEY *pkey; | ||
107 | int mode; | ||
108 | { | ||
109 | #ifndef NO_DSA | ||
110 | if (pkey->type == EVP_PKEY_DSA) | ||
111 | { | ||
112 | int ret=pkey->save_parameters=mode; | ||
113 | |||
114 | if (mode >= 0) | ||
115 | pkey->save_parameters=mode; | ||
116 | return(ret); | ||
117 | } | ||
118 | #endif | ||
119 | return(0); | ||
120 | } | ||
121 | |||
122 | int EVP_PKEY_copy_parameters(to,from) | ||
123 | EVP_PKEY *to,*from; | ||
124 | { | ||
125 | if (to->type != from->type) | ||
126 | { | ||
127 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES); | ||
128 | goto err; | ||
129 | } | ||
130 | |||
131 | if (EVP_PKEY_missing_parameters(from)) | ||
132 | { | ||
133 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARMATERS); | ||
134 | goto err; | ||
135 | } | ||
136 | #ifndef NO_DSA | ||
137 | if (to->type == EVP_PKEY_DSA) | ||
138 | { | ||
139 | BIGNUM *a; | ||
140 | |||
141 | if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err; | ||
142 | if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p); | ||
143 | to->pkey.dsa->p=a; | ||
144 | |||
145 | if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err; | ||
146 | if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q); | ||
147 | to->pkey.dsa->q=a; | ||
148 | |||
149 | if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err; | ||
150 | if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g); | ||
151 | to->pkey.dsa->g=a; | ||
152 | } | ||
153 | #endif | ||
154 | return(1); | ||
155 | err: | ||
156 | return(0); | ||
157 | } | ||
158 | |||
159 | int EVP_PKEY_missing_parameters(pkey) | ||
160 | EVP_PKEY *pkey; | ||
161 | { | ||
162 | #ifndef NO_DSA | ||
163 | if (pkey->type == EVP_PKEY_DSA) | ||
164 | { | ||
165 | DSA *dsa; | ||
166 | |||
167 | dsa=pkey->pkey.dsa; | ||
168 | if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL)) | ||
169 | return(1); | ||
170 | } | ||
171 | #endif | ||
172 | return(0); | ||
173 | } | ||
174 | |||
175 | int EVP_PKEY_cmp_parameters(a,b) | ||
176 | EVP_PKEY *a,*b; | ||
177 | { | ||
178 | #ifndef NO_DSA | ||
179 | if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA)) | ||
180 | { | ||
181 | if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) || | ||
182 | BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) || | ||
183 | BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g)) | ||
184 | return(0); | ||
185 | else | ||
186 | return(1); | ||
187 | } | ||
188 | #endif | ||
189 | return(-1); | ||
190 | } | ||
191 | |||
192 | EVP_PKEY *EVP_PKEY_new() | ||
193 | { | ||
194 | EVP_PKEY *ret; | ||
195 | |||
196 | ret=(EVP_PKEY *)Malloc(sizeof(EVP_PKEY)); | ||
197 | if (ret == NULL) | ||
198 | { | ||
199 | EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE); | ||
200 | return(NULL); | ||
201 | } | ||
202 | ret->type=EVP_PKEY_NONE; | ||
203 | ret->references=1; | ||
204 | ret->pkey.ptr=NULL; | ||
205 | ret->attributes=NULL; | ||
206 | ret->save_parameters=1; | ||
207 | return(ret); | ||
208 | } | ||
209 | |||
210 | int EVP_PKEY_assign(pkey,type,key) | ||
211 | EVP_PKEY *pkey; | ||
212 | int type; | ||
213 | char *key; | ||
214 | { | ||
215 | if (pkey == NULL) return(0); | ||
216 | if (pkey->pkey.ptr != NULL) | ||
217 | EVP_PKEY_free_it(pkey); | ||
218 | pkey->type=EVP_PKEY_type(type); | ||
219 | pkey->save_type=type; | ||
220 | pkey->pkey.ptr=key; | ||
221 | return(1); | ||
222 | } | ||
223 | |||
224 | int EVP_PKEY_type(type) | ||
225 | int type; | ||
226 | { | ||
227 | switch (type) | ||
228 | { | ||
229 | case EVP_PKEY_RSA: | ||
230 | case EVP_PKEY_RSA2: | ||
231 | return(EVP_PKEY_RSA); | ||
232 | case EVP_PKEY_DSA: | ||
233 | case EVP_PKEY_DSA1: | ||
234 | case EVP_PKEY_DSA2: | ||
235 | case EVP_PKEY_DSA3: | ||
236 | case EVP_PKEY_DSA4: | ||
237 | return(EVP_PKEY_DSA); | ||
238 | case EVP_PKEY_DH: | ||
239 | return(EVP_PKEY_DH); | ||
240 | default: | ||
241 | return(NID_undef); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | void EVP_PKEY_free(x) | ||
246 | EVP_PKEY *x; | ||
247 | { | ||
248 | int i; | ||
249 | |||
250 | if (x == NULL) return; | ||
251 | |||
252 | i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY); | ||
253 | #ifdef REF_PRINT | ||
254 | REF_PRINT("EVP_PKEY",x); | ||
255 | #endif | ||
256 | if (i > 0) return; | ||
257 | #ifdef REF_CHECK | ||
258 | if (i < 0) | ||
259 | { | ||
260 | fprintf(stderr,"EVP_PKEY_free, bad reference count\n"); | ||
261 | abort(); | ||
262 | } | ||
263 | #endif | ||
264 | EVP_PKEY_free_it(x); | ||
265 | Free((char *)x); | ||
266 | } | ||
267 | |||
268 | static void EVP_PKEY_free_it(x) | ||
269 | EVP_PKEY *x; | ||
270 | { | ||
271 | switch (x->type) | ||
272 | { | ||
273 | #ifndef NO_RSA | ||
274 | case EVP_PKEY_RSA: | ||
275 | case EVP_PKEY_RSA2: | ||
276 | RSA_free(x->pkey.rsa); | ||
277 | break; | ||
278 | #endif | ||
279 | #ifndef NO_DSA | ||
280 | case EVP_PKEY_DSA: | ||
281 | case EVP_PKEY_DSA2: | ||
282 | case EVP_PKEY_DSA3: | ||
283 | case EVP_PKEY_DSA4: | ||
284 | DSA_free(x->pkey.dsa); | ||
285 | break; | ||
286 | #endif | ||
287 | #ifndef NO_DH | ||
288 | case EVP_PKEY_DH: | ||
289 | DH_free(x->pkey.dh); | ||
290 | break; | ||
291 | #endif | ||
292 | } | ||
293 | } | ||
294 | |||
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c new file mode 100644 index 0000000000..28a8e02252 --- /dev/null +++ b/src/lib/libcrypto/evp/p_open.c | |||
@@ -0,0 +1,119 @@ | |||
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 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | int EVP_OpenInit(ctx,type,ek,ekl,iv,priv) | ||
66 | EVP_CIPHER_CTX *ctx; | ||
67 | EVP_CIPHER *type; | ||
68 | unsigned char *ek; | ||
69 | int ekl; | ||
70 | unsigned char *iv; | ||
71 | EVP_PKEY *priv; | ||
72 | { | ||
73 | unsigned char *key=NULL; | ||
74 | int i,size=0,ret=0; | ||
75 | |||
76 | if (priv->type != EVP_PKEY_RSA) | ||
77 | { | ||
78 | EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA); | ||
79 | ret= -1; | ||
80 | goto err; | ||
81 | } | ||
82 | |||
83 | size=RSA_size(priv->pkey.rsa); | ||
84 | key=(unsigned char *)Malloc(size+2); | ||
85 | if (key == NULL) | ||
86 | { | ||
87 | /* ERROR */ | ||
88 | EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE); | ||
89 | ret= -1; | ||
90 | goto err; | ||
91 | } | ||
92 | |||
93 | i=EVP_PKEY_decrypt(key,ek,ekl,priv); | ||
94 | if (i != type->key_len) | ||
95 | { | ||
96 | /* ERROR */ | ||
97 | goto err; | ||
98 | } | ||
99 | |||
100 | EVP_CIPHER_CTX_init(ctx); | ||
101 | EVP_DecryptInit(ctx,type,key,iv); | ||
102 | ret=1; | ||
103 | err: | ||
104 | if (key != NULL) memset(key,0,size); | ||
105 | Free(key); | ||
106 | return(ret); | ||
107 | } | ||
108 | |||
109 | int EVP_OpenFinal(ctx,out,outl) | ||
110 | EVP_CIPHER_CTX *ctx; | ||
111 | unsigned char *out; | ||
112 | int *outl; | ||
113 | { | ||
114 | int i; | ||
115 | |||
116 | i=EVP_DecryptFinal(ctx,out,outl); | ||
117 | EVP_DecryptInit(ctx,NULL,NULL,NULL); | ||
118 | return(i); | ||
119 | } | ||
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c new file mode 100644 index 0000000000..09a408de35 --- /dev/null +++ b/src/lib/libcrypto/evp/p_seal.c | |||
@@ -0,0 +1,115 @@ | |||
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 "rand.h" | ||
62 | #include "rsa.h" | ||
63 | #include "evp.h" | ||
64 | #include "objects.h" | ||
65 | #include "x509.h" | ||
66 | |||
67 | int EVP_SealInit(ctx,type,ek,ekl,iv,pubk,npubk) | ||
68 | EVP_CIPHER_CTX *ctx; | ||
69 | EVP_CIPHER *type; | ||
70 | unsigned char **ek; | ||
71 | int *ekl; | ||
72 | unsigned char *iv; | ||
73 | EVP_PKEY **pubk; | ||
74 | int npubk; | ||
75 | { | ||
76 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
77 | int i; | ||
78 | |||
79 | if (npubk <= 0) return(0); | ||
80 | RAND_bytes(key,EVP_MAX_KEY_LENGTH); | ||
81 | if (type->iv_len > 0) | ||
82 | RAND_bytes(iv,type->iv_len); | ||
83 | |||
84 | EVP_CIPHER_CTX_init(ctx); | ||
85 | EVP_EncryptInit(ctx,type,key,iv); | ||
86 | |||
87 | for (i=0; i<npubk; i++) | ||
88 | { | ||
89 | ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_key_length(type), | ||
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(ctx,out,outl) | ||
109 | EVP_CIPHER_CTX *ctx; | ||
110 | unsigned char *out; | ||
111 | int *outl; | ||
112 | { | ||
113 | EVP_EncryptFinal(ctx,out,outl); | ||
114 | EVP_EncryptInit(ctx,NULL,NULL,NULL); | ||
115 | } | ||
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c new file mode 100644 index 0000000000..073270ce31 --- /dev/null +++ b/src/lib/libcrypto/evp/p_sign.c | |||
@@ -0,0 +1,119 @@ | |||
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 "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | #ifdef undef | ||
66 | void EVP_SignInit(ctx,type) | ||
67 | EVP_MD_CTX *ctx; | ||
68 | EVP_MD *type; | ||
69 | { | ||
70 | EVP_DigestInit(ctx,type); | ||
71 | } | ||
72 | |||
73 | void EVP_SignUpdate(ctx,data,count) | ||
74 | EVP_MD_CTX *ctx; | ||
75 | unsigned char *data; | ||
76 | unsigned int count; | ||
77 | { | ||
78 | EVP_DigestUpdate(ctx,data,count); | ||
79 | } | ||
80 | #endif | ||
81 | |||
82 | int EVP_SignFinal(ctx,sigret,siglen,pkey) | ||
83 | EVP_MD_CTX *ctx; | ||
84 | unsigned char *sigret; | ||
85 | unsigned int *siglen; | ||
86 | EVP_PKEY *pkey; | ||
87 | { | ||
88 | unsigned char m[EVP_MAX_MD_SIZE]; | ||
89 | unsigned int m_len; | ||
90 | int i,ok=0,v; | ||
91 | MS_STATIC EVP_MD_CTX tmp_ctx; | ||
92 | |||
93 | *siglen=0; | ||
94 | memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX)); | ||
95 | EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); | ||
96 | for (i=0; i<4; i++) | ||
97 | { | ||
98 | v=ctx->digest->required_pkey_type[i]; | ||
99 | if (v == 0) break; | ||
100 | if (pkey->type == v) | ||
101 | { | ||
102 | ok=1; | ||
103 | break; | ||
104 | } | ||
105 | } | ||
106 | if (!ok) | ||
107 | { | ||
108 | EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); | ||
109 | return(0); | ||
110 | } | ||
111 | if (ctx->digest->sign == NULL) | ||
112 | { | ||
113 | EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED); | ||
114 | return(0); | ||
115 | } | ||
116 | return(ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen, | ||
117 | pkey->pkey.ptr)); | ||
118 | } | ||
119 | |||
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c new file mode 100644 index 0000000000..8d727d8f02 --- /dev/null +++ b/src/lib/libcrypto/evp/p_verify.c | |||
@@ -0,0 +1,102 @@ | |||
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 "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | int EVP_VerifyFinal(ctx,sigbuf,siglen,pkey) | ||
66 | EVP_MD_CTX *ctx; | ||
67 | unsigned char *sigbuf; | ||
68 | unsigned int siglen; | ||
69 | EVP_PKEY *pkey; | ||
70 | { | ||
71 | unsigned char m[EVP_MAX_MD_SIZE]; | ||
72 | unsigned int m_len; | ||
73 | int i,ok=0,v; | ||
74 | MS_STATIC EVP_MD_CTX tmp_ctx; | ||
75 | |||
76 | for (i=0; i<4; i++) | ||
77 | { | ||
78 | v=ctx->digest->required_pkey_type[i]; | ||
79 | if (v == 0) break; | ||
80 | if (pkey->type == v) | ||
81 | { | ||
82 | ok=1; | ||
83 | break; | ||
84 | } | ||
85 | } | ||
86 | if (!ok) | ||
87 | { | ||
88 | EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); | ||
89 | return(-1); | ||
90 | } | ||
91 | memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX)); | ||
92 | EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); | ||
93 | if (ctx->digest->verify == NULL) | ||
94 | { | ||
95 | EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED); | ||
96 | return(0); | ||
97 | } | ||
98 | |||
99 | return(ctx->digest->verify(ctx->digest->type,m,m_len, | ||
100 | sigbuf,siglen,pkey->pkey.ptr)); | ||
101 | } | ||
102 | |||