summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>1999-10-10 21:32:03 +0000
committercvs2svn <admin@example.com>1999-10-10 21:32:03 +0000
commit14e61fef302fbc25ab63e38bd35445637ca68139 (patch)
treedae5e50679bccd1ed8d7d4041fbb9f3d96bbc98c /src/lib/libcrypto/evp
parent3ef9529fbf0c1f8f1c9da1172e92ad3370d5fcfe (diff)
downloadopenbsd-OPENBSD_2_6_BASE.tar.gz
openbsd-OPENBSD_2_6_BASE.tar.bz2
openbsd-OPENBSD_2_6_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_2_6_BASE'.OPENBSD_2_6_BASE
Diffstat (limited to 'src/lib/libcrypto/evp')
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c524
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c401
-rw-r--r--src/lib/libcrypto/evp/bio_md.c244
-rw-r--r--src/lib/libcrypto/evp/c_all.c193
-rw-r--r--src/lib/libcrypto/evp/digest.c92
-rw-r--r--src/lib/libcrypto/evp/e_null.c97
-rw-r--r--src/lib/libcrypto/evp/e_rc4.c115
-rw-r--r--src/lib/libcrypto/evp/e_xcbc_d.c112
-rw-r--r--src/lib/libcrypto/evp/encode.c427
-rw-r--r--src/lib/libcrypto/evp/evp.h720
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c270
-rw-r--r--src/lib/libcrypto/evp/evp_err.c136
-rw-r--r--src/lib/libcrypto/evp/evp_key.c156
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c138
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c134
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c298
-rw-r--r--src/lib/libcrypto/evp/m_dss.c83
-rw-r--r--src/lib/libcrypto/evp/m_dss1.c83
-rw-r--r--src/lib/libcrypto/evp/m_md5.c83
-rw-r--r--src/lib/libcrypto/evp/m_null.c88
-rw-r--r--src/lib/libcrypto/evp/m_ripemd.c84
-rw-r--r--src/lib/libcrypto/evp/m_sha1.c83
-rw-r--r--src/lib/libcrypto/evp/names.c118
-rw-r--r--src/lib/libcrypto/evp/p5_crpt.c146
-rw-r--r--src/lib/libcrypto/evp/p5_crpt2.c247
-rw-r--r--src/lib/libcrypto/evp/p_dec.c87
-rw-r--r--src/lib/libcrypto/evp/p_enc.c86
-rw-r--r--src/lib/libcrypto/evp/p_lib.c275
-rw-r--r--src/lib/libcrypto/evp/p_open.c113
-rw-r--r--src/lib/libcrypto/evp/p_seal.c108
-rw-r--r--src/lib/libcrypto/evp/p_sign.c112
-rw-r--r--src/lib/libcrypto/evp/p_verify.c99
32 files changed, 0 insertions, 5952 deletions
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c
deleted file mode 100644
index 84729119df..0000000000
--- a/src/lib/libcrypto/evp/bio_b64.c
+++ /dev/null
@@ -1,524 +0,0 @@
1/* crypto/evp/bio_b64.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65static int b64_write(BIO *h,char *buf,int num);
66static int b64_read(BIO *h,char *buf,int size);
67/*static int b64_puts(BIO *h,char *str); */
68/*static int b64_gets(BIO *h,char *str,int size); */
69static long b64_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int b64_new(BIO *h);
71static int b64_free(BIO *data);
72#define B64_BLOCK_SIZE 1024
73#define B64_BLOCK_SIZE2 768
74#define B64_NONE 0
75#define B64_ENCODE 1
76#define B64_DECODE 2
77
78typedef struct b64_struct
79 {
80 /*BIO *bio; moved to the BIO structure */
81 int buf_len;
82 int buf_off;
83 int tmp_len; /* used to find the start when decoding */
84 int tmp_nl; /* If true, scan until '\n' */
85 int encode;
86 int start; /* have we started decoding yet? */
87 int cont; /* <= 0 when finished */
88 EVP_ENCODE_CTX base64;
89 char buf[EVP_ENCODE_LENGTH(B64_BLOCK_SIZE)+10];
90 char tmp[B64_BLOCK_SIZE];
91 } BIO_B64_CTX;
92
93static BIO_METHOD methods_b64=
94 {
95 BIO_TYPE_BASE64,"base64 encoding",
96 b64_write,
97 b64_read,
98 NULL, /* b64_puts, */
99 NULL, /* b64_gets, */
100 b64_ctrl,
101 b64_new,
102 b64_free,
103 };
104
105BIO_METHOD *BIO_f_base64(void)
106 {
107 return(&methods_b64);
108 }
109
110static int b64_new(BIO *bi)
111 {
112 BIO_B64_CTX *ctx;
113
114 ctx=(BIO_B64_CTX *)Malloc(sizeof(BIO_B64_CTX));
115 if (ctx == NULL) return(0);
116
117 ctx->buf_len=0;
118 ctx->tmp_len=0;
119 ctx->tmp_nl=0;
120 ctx->buf_off=0;
121 ctx->cont=1;
122 ctx->start=1;
123 ctx->encode=0;
124
125 bi->init=1;
126 bi->ptr=(char *)ctx;
127 bi->flags=0;
128 return(1);
129 }
130
131static int b64_free(BIO *a)
132 {
133 if (a == NULL) return(0);
134 Free(a->ptr);
135 a->ptr=NULL;
136 a->init=0;
137 a->flags=0;
138 return(1);
139 }
140
141static int b64_read(BIO *b, char *out, int outl)
142 {
143 int ret=0,i,ii,j,k,x,n,num,ret_code=0;
144 BIO_B64_CTX *ctx;
145 unsigned char *p,*q;
146
147 if (out == NULL) return(0);
148 ctx=(BIO_B64_CTX *)b->ptr;
149
150 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
151
152 if (ctx->encode != B64_DECODE)
153 {
154 ctx->encode=B64_DECODE;
155 ctx->buf_len=0;
156 ctx->buf_off=0;
157 ctx->tmp_len=0;
158 EVP_DecodeInit(&(ctx->base64));
159 }
160
161 /* First check if there are bytes decoded/encoded */
162 if (ctx->buf_len > 0)
163 {
164 i=ctx->buf_len-ctx->buf_off;
165 if (i > outl) i=outl;
166 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
167 ret=i;
168 out+=i;
169 outl-=i;
170 ctx->buf_off+=i;
171 if (ctx->buf_len == ctx->buf_off)
172 {
173 ctx->buf_len=0;
174 ctx->buf_off=0;
175 }
176 }
177
178 /* At this point, we have room of outl bytes and an empty
179 * buffer, so we should read in some more. */
180
181 ret_code=0;
182 while (outl > 0)
183 {
184 if (ctx->cont <= 0) break;
185
186 i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]),
187 B64_BLOCK_SIZE-ctx->tmp_len);
188
189 if (i <= 0)
190 {
191 ret_code=i;
192
193 /* Should be continue next time we are called? */
194 if (!BIO_should_retry(b->next_bio))
195 ctx->cont=i;
196 /* else we should continue when called again */
197 break;
198 }
199 i+=ctx->tmp_len;
200
201 /* We need to scan, a line at a time until we
202 * have a valid line if we are starting. */
203 if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL))
204 {
205 /* ctx->start=1; */
206 ctx->tmp_len=0;
207 }
208 else if (ctx->start)
209 {
210 q=p=(unsigned char *)ctx->tmp;
211 for (j=0; j<i; j++)
212 {
213 if (*(q++) != '\n') continue;
214
215 /* due to a previous very long line,
216 * we need to keep on scanning for a '\n'
217 * before we even start looking for
218 * base64 encoded stuff. */
219 if (ctx->tmp_nl)
220 {
221 p=q;
222 ctx->tmp_nl=0;
223 continue;
224 }
225
226 k=EVP_DecodeUpdate(&(ctx->base64),
227 (unsigned char *)ctx->buf,
228 &num,p,q-p);
229 if ((k <= 0) && (num == 0) && (ctx->start))
230 EVP_DecodeInit(&ctx->base64);
231 else
232 {
233 if (p != (unsigned char *)
234 &(ctx->tmp[0]))
235 {
236 i-=(p- (unsigned char *)
237 &(ctx->tmp[0]));
238 for (x=0; x < i; x++)
239 ctx->tmp[x]=p[x];
240 EVP_DecodeInit(&ctx->base64);
241 }
242 ctx->start=0;
243 break;
244 }
245 p=q;
246 }
247
248 /* we fell off the end without starting */
249 if (j == i)
250 {
251 /* Is this is one long chunk?, if so, keep on
252 * reading until a new line. */
253 if (p == (unsigned char *)&(ctx->tmp[0]))
254 {
255 ctx->tmp_nl=1;
256 ctx->tmp_len=0;
257 }
258 else if (p != q) /* finished on a '\n' */
259 {
260 n=q-p;
261 for (ii=0; ii<n; ii++)
262 ctx->tmp[ii]=p[ii];
263 ctx->tmp_len=n;
264 }
265 /* else finished on a '\n' */
266 continue;
267 }
268 else
269 ctx->tmp_len=0;
270 }
271
272 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
273 {
274 int z,jj;
275
276 jj=(i>>2)<<2;
277 z=EVP_DecodeBlock((unsigned char *)ctx->buf,
278 (unsigned char *)ctx->tmp,jj);
279 if (jj > 2)
280 {
281 if (ctx->tmp[jj-1] == '=')
282 {
283 z--;
284 if (ctx->tmp[jj-2] == '=')
285 z--;
286 }
287 }
288 /* z is now number of output bytes and jj is the
289 * number consumed */
290 if (jj != i)
291 {
292 memcpy((unsigned char *)ctx->tmp,
293 (unsigned char *)&(ctx->tmp[jj]),i-jj);
294 ctx->tmp_len=i-jj;
295 }
296 ctx->buf_len=0;
297 if (z > 0)
298 {
299 ctx->buf_len=z;
300 i=1;
301 }
302 else
303 i=z;
304 }
305 else
306 {
307 i=EVP_DecodeUpdate(&(ctx->base64),
308 (unsigned char *)ctx->buf,&ctx->buf_len,
309 (unsigned char *)ctx->tmp,i);
310 }
311 ctx->cont=i;
312 ctx->buf_off=0;
313 if (i < 0)
314 {
315 ret_code=0;
316 ctx->buf_len=0;
317 break;
318 }
319
320 if (ctx->buf_len <= outl)
321 i=ctx->buf_len;
322 else
323 i=outl;
324
325 memcpy(out,ctx->buf,i);
326 ret+=i;
327 ctx->buf_off=i;
328 if (ctx->buf_off == ctx->buf_len)
329 {
330 ctx->buf_len=0;
331 ctx->buf_off=0;
332 }
333 outl-=i;
334 out+=i;
335 }
336 BIO_clear_retry_flags(b);
337 BIO_copy_next_retry(b);
338 return((ret == 0)?ret_code:ret);
339 }
340
341static int b64_write(BIO *b, char *in, int inl)
342 {
343 int ret=inl,n,i;
344 BIO_B64_CTX *ctx;
345
346 ctx=(BIO_B64_CTX *)b->ptr;
347 BIO_clear_retry_flags(b);
348
349 if (ctx->encode != B64_ENCODE)
350 {
351 ctx->encode=B64_ENCODE;
352 ctx->buf_len=0;
353 ctx->buf_off=0;
354 ctx->tmp_len=0;
355 EVP_EncodeInit(&(ctx->base64));
356 }
357
358 n=ctx->buf_len-ctx->buf_off;
359 while (n > 0)
360 {
361 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
362 if (i <= 0)
363 {
364 BIO_copy_next_retry(b);
365 return(i);
366 }
367 ctx->buf_off+=i;
368 n-=i;
369 }
370 /* at this point all pending data has been written */
371
372 if ((in == NULL) || (inl <= 0)) return(0);
373
374 ctx->buf_off=0;
375 while (inl > 0)
376 {
377 n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl;
378
379 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
380 {
381 if (ctx->tmp_len > 0)
382 {
383 n=3-ctx->tmp_len;
384 memcpy(&(ctx->tmp[ctx->tmp_len]),in,n);
385 ctx->tmp_len+=n;
386 n=ctx->tmp_len;
387 if (n < 3)
388 break;
389 ctx->buf_len=EVP_EncodeBlock(
390 (unsigned char *)ctx->buf,
391 (unsigned char *)ctx->tmp,n);
392 }
393 else
394 {
395 if (n < 3)
396 {
397 memcpy(&(ctx->tmp[0]),in,n);
398 ctx->tmp_len=n;
399 break;
400 }
401 n-=n%3;
402 ctx->buf_len=EVP_EncodeBlock(
403 (unsigned char *)ctx->buf,
404 (unsigned char *)in,n);
405 }
406 }
407 else
408 {
409 EVP_EncodeUpdate(&(ctx->base64),
410 (unsigned char *)ctx->buf,&ctx->buf_len,
411 (unsigned char *)in,n);
412 }
413 inl-=n;
414 in+=n;
415
416 ctx->buf_off=0;
417 n=ctx->buf_len;
418 while (n > 0)
419 {
420 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
421 if (i <= 0)
422 {
423 BIO_copy_next_retry(b);
424 return((ret == 0)?i:ret);
425 }
426 n-=i;
427 ctx->buf_off+=i;
428 }
429 ctx->buf_len=0;
430 ctx->buf_off=0;
431 }
432 return(ret);
433 }
434
435static long b64_ctrl(BIO *b, int cmd, long num, char *ptr)
436 {
437 BIO_B64_CTX *ctx;
438 long ret=1;
439 int i;
440
441 ctx=(BIO_B64_CTX *)b->ptr;
442
443 switch (cmd)
444 {
445 case BIO_CTRL_RESET:
446 ctx->cont=1;
447 ctx->start=1;
448 ctx->encode=B64_NONE;
449 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
450 break;
451 case BIO_CTRL_EOF: /* More to read */
452 if (ctx->cont <= 0)
453 ret=1;
454 else
455 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
456 break;
457 case BIO_CTRL_WPENDING: /* More to write in buffer */
458 ret=ctx->buf_len-ctx->buf_off;
459 if ((ret == 0) && (ctx->base64.num != 0))
460 ret=1;
461 else if (ret <= 0)
462 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
463 break;
464 case BIO_CTRL_PENDING: /* More to read in buffer */
465 ret=ctx->buf_len-ctx->buf_off;
466 if (ret <= 0)
467 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
468 break;
469 case BIO_CTRL_FLUSH:
470 /* do a final write */
471again:
472 while (ctx->buf_len != ctx->buf_off)
473 {
474 i=b64_write(b,NULL,0);
475 if (i < 0)
476 {
477 ret=i;
478 break;
479 }
480 }
481 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
482 {
483 if (ctx->tmp_len != 0)
484 {
485 ctx->buf_len=EVP_EncodeBlock(
486 (unsigned char *)ctx->buf,
487 (unsigned char *)ctx->tmp,
488 ctx->tmp_len);
489 ctx->buf_off=0;
490 ctx->tmp_len=0;
491 goto again;
492 }
493 }
494 else if (ctx->base64.num != 0)
495 {
496 ctx->buf_off=0;
497 EVP_EncodeFinal(&(ctx->base64),
498 (unsigned char *)ctx->buf,
499 &(ctx->buf_len));
500 /* push out the bytes */
501 goto again;
502 }
503 /* Finally flush the underlying BIO */
504 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
505 break;
506
507 case BIO_C_DO_STATE_MACHINE:
508 BIO_clear_retry_flags(b);
509 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
510 BIO_copy_next_retry(b);
511 break;
512
513 case BIO_CTRL_DUP:
514 break;
515 case BIO_CTRL_INFO:
516 case BIO_CTRL_GET:
517 case BIO_CTRL_SET:
518 default:
519 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
520 break;
521 }
522 return(ret);
523 }
524
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
deleted file mode 100644
index 0a7b1ecf07..0000000000
--- a/src/lib/libcrypto/evp/bio_enc.c
+++ /dev/null
@@ -1,401 +0,0 @@
1/* crypto/evp/bio_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65static int enc_write(BIO *h,char *buf,int num);
66static int enc_read(BIO *h,char *buf,int size);
67/*static int enc_puts(BIO *h,char *str); */
68/*static int enc_gets(BIO *h,char *str,int size); */
69static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int enc_new(BIO *h);
71static int enc_free(BIO *data);
72#define ENC_BLOCK_SIZE (1024*4)
73
74typedef struct enc_struct
75 {
76 int buf_len;
77 int buf_off;
78 int cont; /* <= 0 when finished */
79 int finished;
80 int ok; /* bad decrypt */
81 EVP_CIPHER_CTX cipher;
82 char buf[ENC_BLOCK_SIZE+10];
83 } BIO_ENC_CTX;
84
85static BIO_METHOD methods_enc=
86 {
87 BIO_TYPE_CIPHER,"cipher",
88 enc_write,
89 enc_read,
90 NULL, /* enc_puts, */
91 NULL, /* enc_gets, */
92 enc_ctrl,
93 enc_new,
94 enc_free,
95 };
96
97BIO_METHOD *BIO_f_cipher(void)
98 {
99 return(&methods_enc);
100 }
101
102static int enc_new(BIO *bi)
103 {
104 BIO_ENC_CTX *ctx;
105
106 ctx=(BIO_ENC_CTX *)Malloc(sizeof(BIO_ENC_CTX));
107 EVP_CIPHER_CTX_init(&ctx->cipher);
108 if (ctx == NULL) return(0);
109
110 ctx->buf_len=0;
111 ctx->buf_off=0;
112 ctx->cont=1;
113 ctx->finished=0;
114 ctx->ok=1;
115
116 bi->init=0;
117 bi->ptr=(char *)ctx;
118 bi->flags=0;
119 return(1);
120 }
121
122static int enc_free(BIO *a)
123 {
124 BIO_ENC_CTX *b;
125
126 if (a == NULL) return(0);
127 b=(BIO_ENC_CTX *)a->ptr;
128 EVP_CIPHER_CTX_cleanup(&(b->cipher));
129 memset(a->ptr,0,sizeof(BIO_ENC_CTX));
130 Free(a->ptr);
131 a->ptr=NULL;
132 a->init=0;
133 a->flags=0;
134 return(1);
135 }
136
137static int enc_read(BIO *b, char *out, int outl)
138 {
139 int ret=0,i;
140 BIO_ENC_CTX *ctx;
141
142 if (out == NULL) return(0);
143 ctx=(BIO_ENC_CTX *)b->ptr;
144
145 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
146
147 /* First check if there are bytes decoded/encoded */
148 if (ctx->buf_len > 0)
149 {
150 i=ctx->buf_len-ctx->buf_off;
151 if (i > outl) i=outl;
152 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
153 ret=i;
154 out+=i;
155 outl-=i;
156 ctx->buf_off+=i;
157 if (ctx->buf_len == ctx->buf_off)
158 {
159 ctx->buf_len=0;
160 ctx->buf_off=0;
161 }
162 }
163
164 /* At this point, we have room of outl bytes and an empty
165 * buffer, so we should read in some more. */
166
167 while (outl > 0)
168 {
169 if (ctx->cont <= 0) break;
170
171 /* read in at offset 8, read the EVP_Cipher
172 * documentation about why */
173 i=BIO_read(b->next_bio,&(ctx->buf[8]),ENC_BLOCK_SIZE);
174
175 if (i <= 0)
176 {
177 /* Should be continue next time we are called? */
178 if (!BIO_should_retry(b->next_bio))
179 {
180 ctx->cont=i;
181 i=EVP_CipherFinal(&(ctx->cipher),
182 (unsigned char *)ctx->buf,
183 &(ctx->buf_len));
184 ctx->ok=i;
185 ctx->buf_off=0;
186 }
187 else
188 ret=(ret == 0)?i:ret;
189 break;
190 }
191 else
192 {
193 EVP_CipherUpdate(&(ctx->cipher),
194 (unsigned char *)ctx->buf,&ctx->buf_len,
195 (unsigned char *)&(ctx->buf[8]),i);
196 ctx->cont=1;
197 }
198
199 if (ctx->buf_len <= outl)
200 i=ctx->buf_len;
201 else
202 i=outl;
203
204 if (i <= 0) break;
205 memcpy(out,ctx->buf,i);
206 ret+=i;
207 ctx->buf_off=i;
208 outl-=i;
209 out+=i;
210 }
211
212 BIO_clear_retry_flags(b);
213 BIO_copy_next_retry(b);
214 return((ret == 0)?ctx->cont:ret);
215 }
216
217static int enc_write(BIO *b, char *in, int inl)
218 {
219 int ret=0,n,i;
220 BIO_ENC_CTX *ctx;
221
222 ctx=(BIO_ENC_CTX *)b->ptr;
223 ret=inl;
224
225 BIO_clear_retry_flags(b);
226 n=ctx->buf_len-ctx->buf_off;
227 while (n > 0)
228 {
229 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
230 if (i <= 0)
231 {
232 BIO_copy_next_retry(b);
233 return(i);
234 }
235 ctx->buf_off+=i;
236 n-=i;
237 }
238 /* at this point all pending data has been written */
239
240 if ((in == NULL) || (inl <= 0)) return(0);
241
242 ctx->buf_off=0;
243 while (inl > 0)
244 {
245 n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
246 EVP_CipherUpdate(&(ctx->cipher),
247 (unsigned char *)ctx->buf,&ctx->buf_len,
248 (unsigned char *)in,n);
249 inl-=n;
250 in+=n;
251
252 ctx->buf_off=0;
253 n=ctx->buf_len;
254 while (n > 0)
255 {
256 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
257 if (i <= 0)
258 {
259 BIO_copy_next_retry(b);
260 return(i);
261 }
262 n-=i;
263 ctx->buf_off+=i;
264 }
265 ctx->buf_len=0;
266 ctx->buf_off=0;
267 }
268 BIO_copy_next_retry(b);
269 return(ret);
270 }
271
272static long enc_ctrl(BIO *b, int cmd, long num, char *ptr)
273 {
274 BIO *dbio;
275 BIO_ENC_CTX *ctx,*dctx;
276 long ret=1;
277 int i;
278 EVP_CIPHER_CTX **c_ctx;
279
280 ctx=(BIO_ENC_CTX *)b->ptr;
281
282 switch (cmd)
283 {
284 case BIO_CTRL_RESET:
285 ctx->ok=1;
286 ctx->finished=0;
287 EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL,
288 ctx->cipher.encrypt);
289 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
290 break;
291 case BIO_CTRL_EOF: /* More to read */
292 if (ctx->cont <= 0)
293 ret=1;
294 else
295 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
296 break;
297 case BIO_CTRL_WPENDING:
298 ret=ctx->buf_len-ctx->buf_off;
299 if (ret <= 0)
300 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
301 break;
302 case BIO_CTRL_PENDING: /* More to read in buffer */
303 ret=ctx->buf_len-ctx->buf_off;
304 if (ret <= 0)
305 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
306 break;
307 case BIO_CTRL_FLUSH:
308 /* do a final write */
309again:
310 while (ctx->buf_len != ctx->buf_off)
311 {
312 i=enc_write(b,NULL,0);
313 if (i < 0)
314 {
315 ret=i;
316 break;
317 }
318 }
319
320 if (!ctx->finished)
321 {
322 ctx->finished=1;
323 ctx->buf_off=0;
324 ret=EVP_CipherFinal(&(ctx->cipher),
325 (unsigned char *)ctx->buf,
326 &(ctx->buf_len));
327 ctx->ok=(int)ret;
328 if (ret <= 0) break;
329
330 /* push out the bytes */
331 goto again;
332 }
333
334 /* Finally flush the underlying BIO */
335 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
336 break;
337 case BIO_C_GET_CIPHER_STATUS:
338 ret=(long)ctx->ok;
339 break;
340 case BIO_C_DO_STATE_MACHINE:
341 BIO_clear_retry_flags(b);
342 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
343 BIO_copy_next_retry(b);
344 break;
345 case BIO_C_GET_CIPHER_CTX:
346 c_ctx=(EVP_CIPHER_CTX **)ptr;
347 (*c_ctx)= &(ctx->cipher);
348 b->init=1;
349 break;
350 case BIO_CTRL_DUP:
351 dbio=(BIO *)ptr;
352 dctx=(BIO_ENC_CTX *)dbio->ptr;
353 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
354 dbio->init=1;
355 break;
356 default:
357 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
358 break;
359 }
360 return(ret);
361 }
362
363/*
364void BIO_set_cipher_ctx(b,c)
365BIO *b;
366EVP_CIPHER_ctx *c;
367 {
368 if (b == NULL) return;
369
370 if ((b->callback != NULL) &&
371 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
372 return;
373
374 b->init=1;
375 ctx=(BIO_ENC_CTX *)b->ptr;
376 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
377
378 if (b->callback != NULL)
379 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
380 }
381*/
382
383void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k,
384 unsigned char *i, int e)
385 {
386 BIO_ENC_CTX *ctx;
387
388 if (b == NULL) return;
389
390 if ((b->callback != NULL) &&
391 (b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,0L) <= 0))
392 return;
393
394 b->init=1;
395 ctx=(BIO_ENC_CTX *)b->ptr;
396 EVP_CipherInit(&(ctx->cipher),c,k,i,e);
397
398 if (b->callback != NULL)
399 b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L);
400 }
401
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c
deleted file mode 100644
index 317167f9c4..0000000000
--- a/src/lib/libcrypto/evp/bio_md.c
+++ /dev/null
@@ -1,244 +0,0 @@
1/* crypto/evp/bio_md.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */
67
68static int md_write(BIO *h,char *buf,int num);
69static int md_read(BIO *h,char *buf,int size);
70/*static int md_puts(BIO *h,char *str); */
71static int md_gets(BIO *h,char *str,int size);
72static long md_ctrl(BIO *h,int cmd,long arg1,char *arg2);
73static int md_new(BIO *h);
74static int md_free(BIO *data);
75static BIO_METHOD methods_md=
76 {
77 BIO_TYPE_MD,"message digest",
78 md_write,
79 md_read,
80 NULL, /* md_puts, */
81 md_gets,
82 md_ctrl,
83 md_new,
84 md_free,
85 };
86
87BIO_METHOD *BIO_f_md(void)
88 {
89 return(&methods_md);
90 }
91
92static int md_new(BIO *bi)
93 {
94 EVP_MD_CTX *ctx;
95
96 ctx=(EVP_MD_CTX *)Malloc(sizeof(EVP_MD_CTX));
97 if (ctx == NULL) return(0);
98
99 bi->init=0;
100 bi->ptr=(char *)ctx;
101 bi->flags=0;
102 return(1);
103 }
104
105static int md_free(BIO *a)
106 {
107 if (a == NULL) return(0);
108 Free(a->ptr);
109 a->ptr=NULL;
110 a->init=0;
111 a->flags=0;
112 return(1);
113 }
114
115static int md_read(BIO *b, char *out, int outl)
116 {
117 int ret=0;
118 EVP_MD_CTX *ctx;
119
120 if (out == NULL) return(0);
121 ctx=(EVP_MD_CTX *)b->ptr;
122
123 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
124
125 ret=BIO_read(b->next_bio,out,outl);
126 if (b->init)
127 {
128 if (ret > 0)
129 {
130 EVP_DigestUpdate(ctx,(unsigned char *)out,
131 (unsigned int)ret);
132 }
133 }
134 BIO_clear_retry_flags(b);
135 BIO_copy_next_retry(b);
136 return(ret);
137 }
138
139static int md_write(BIO *b, char *in, int inl)
140 {
141 int ret=0;
142 EVP_MD_CTX *ctx;
143
144 if ((in == NULL) || (inl <= 0)) return(0);
145 ctx=(EVP_MD_CTX *)b->ptr;
146
147 if ((ctx != NULL) && (b->next_bio != NULL))
148 ret=BIO_write(b->next_bio,in,inl);
149 if (b->init)
150 {
151 if (ret > 0)
152 {
153 EVP_DigestUpdate(ctx,(unsigned char *)in,
154 (unsigned int)ret);
155 }
156 }
157 BIO_clear_retry_flags(b);
158 BIO_copy_next_retry(b);
159 return(ret);
160 }
161
162static long md_ctrl(BIO *b, int cmd, long num, char *ptr)
163 {
164 EVP_MD_CTX *ctx,*dctx,**pctx;
165 const EVP_MD **ppmd;
166 EVP_MD *md;
167 long ret=1;
168 BIO *dbio;
169
170 ctx=(EVP_MD_CTX *)b->ptr;
171
172 switch (cmd)
173 {
174 case BIO_CTRL_RESET:
175 if (b->init)
176 EVP_DigestInit(ctx,ctx->digest);
177 else
178 ret=0;
179 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
180 break;
181 case BIO_C_GET_MD:
182 if (b->init)
183 {
184 ppmd=(const EVP_MD **)ptr;
185 *ppmd=ctx->digest;
186 }
187 else
188 ret=0;
189 break;
190 case BIO_C_GET_MD_CTX:
191 if (b->init)
192 {
193 pctx=(EVP_MD_CTX **)ptr;
194 *pctx=ctx;
195 }
196 else
197 ret=0;
198 break;
199 case BIO_C_DO_STATE_MACHINE:
200 BIO_clear_retry_flags(b);
201 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
202 BIO_copy_next_retry(b);
203 break;
204
205 case BIO_C_SET_MD:
206 md=(EVP_MD *)ptr;
207 EVP_DigestInit(ctx,md);
208 b->init=1;
209 break;
210 case BIO_CTRL_DUP:
211 dbio=(BIO *)ptr;
212 dctx=(EVP_MD_CTX *)dbio->ptr;
213 memcpy(dctx,ctx,sizeof(ctx));
214 b->init=1;
215 break;
216 default:
217 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
218 break;
219 }
220 return(ret);
221 }
222
223static int md_gets(BIO *bp, char *buf, int size)
224 {
225 EVP_MD_CTX *ctx;
226 unsigned int ret;
227
228
229 ctx=(EVP_MD_CTX *)bp->ptr;
230 if (size < ctx->digest->md_size)
231 return(0);
232 EVP_DigestFinal(ctx,(unsigned char *)buf,&ret);
233 return((int)ret);
234 }
235
236/*
237static int md_puts(bp,str)
238BIO *bp;
239char *str;
240 {
241 return(-1);
242 }
243*/
244
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c
deleted file mode 100644
index a4d3b43fb9..0000000000
--- a/src/lib/libcrypto/evp/c_all.c
+++ /dev/null
@@ -1,193 +0,0 @@
1/* crypto/evp/c_all.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
64
65void SSLeay_add_all_algorithms(void)
66 {
67 SSLeay_add_all_ciphers();
68 SSLeay_add_all_digests();
69 }
70
71void SSLeay_add_all_ciphers(void)
72 {
73#ifndef NO_DES
74 EVP_add_cipher(EVP_des_cfb());
75 EVP_add_cipher(EVP_des_ede_cfb());
76 EVP_add_cipher(EVP_des_ede3_cfb());
77
78 EVP_add_cipher(EVP_des_ofb());
79 EVP_add_cipher(EVP_des_ede_ofb());
80 EVP_add_cipher(EVP_des_ede3_ofb());
81
82 EVP_add_cipher(EVP_desx_cbc());
83 EVP_add_cipher_alias(SN_desx_cbc,"DESX");
84 EVP_add_cipher_alias(SN_desx_cbc,"desx");
85
86 EVP_add_cipher(EVP_des_cbc());
87 EVP_add_cipher_alias(SN_des_cbc,"DES");
88 EVP_add_cipher_alias(SN_des_cbc,"des");
89 EVP_add_cipher(EVP_des_ede_cbc());
90 EVP_add_cipher(EVP_des_ede3_cbc());
91 EVP_add_cipher_alias(SN_des_ede3_cbc,"DES3");
92 EVP_add_cipher_alias(SN_des_ede3_cbc,"des3");
93
94 EVP_add_cipher(EVP_des_ecb());
95 EVP_add_cipher(EVP_des_ede());
96 EVP_add_cipher(EVP_des_ede3());
97#endif
98
99#ifndef NO_RC4
100 EVP_add_cipher(EVP_rc4());
101 EVP_add_cipher(EVP_rc4_40());
102#endif
103
104#ifndef NO_IDEA
105 EVP_add_cipher(EVP_idea_ecb());
106 EVP_add_cipher(EVP_idea_cfb());
107 EVP_add_cipher(EVP_idea_ofb());
108 EVP_add_cipher(EVP_idea_cbc());
109 EVP_add_cipher_alias(SN_idea_cbc,"IDEA");
110 EVP_add_cipher_alias(SN_idea_cbc,"idea");
111#endif
112
113#ifndef NO_RC2
114 EVP_add_cipher(EVP_rc2_ecb());
115 EVP_add_cipher(EVP_rc2_cfb());
116 EVP_add_cipher(EVP_rc2_ofb());
117 EVP_add_cipher(EVP_rc2_cbc());
118 EVP_add_cipher(EVP_rc2_40_cbc());
119 EVP_add_cipher(EVP_rc2_64_cbc());
120 EVP_add_cipher_alias(SN_rc2_cbc,"RC2");
121 EVP_add_cipher_alias(SN_rc2_cbc,"rc2");
122#endif
123
124#ifndef NO_BF
125 EVP_add_cipher(EVP_bf_ecb());
126 EVP_add_cipher(EVP_bf_cfb());
127 EVP_add_cipher(EVP_bf_ofb());
128 EVP_add_cipher(EVP_bf_cbc());
129 EVP_add_cipher_alias(SN_bf_cbc,"BF");
130 EVP_add_cipher_alias(SN_bf_cbc,"bf");
131 EVP_add_cipher_alias(SN_bf_cbc,"blowfish");
132#endif
133
134#ifndef NO_CAST
135 EVP_add_cipher(EVP_cast5_ecb());
136 EVP_add_cipher(EVP_cast5_cfb());
137 EVP_add_cipher(EVP_cast5_ofb());
138 EVP_add_cipher(EVP_cast5_cbc());
139 EVP_add_cipher_alias(SN_cast5_cbc,"CAST");
140 EVP_add_cipher_alias(SN_cast5_cbc,"cast");
141 EVP_add_cipher_alias(SN_cast5_cbc,"CAST-cbc");
142 EVP_add_cipher_alias(SN_cast5_cbc,"cast-cbc");
143#endif
144
145#ifndef NO_RC5
146 EVP_add_cipher(EVP_rc5_32_12_16_ecb());
147 EVP_add_cipher(EVP_rc5_32_12_16_cfb());
148 EVP_add_cipher(EVP_rc5_32_12_16_ofb());
149 EVP_add_cipher(EVP_rc5_32_12_16_cbc());
150 EVP_add_cipher_alias(SN_rc5_cbc,"rc5");
151 EVP_add_cipher_alias(SN_rc5_cbc,"RC5");
152#endif
153 }
154
155
156void SSLeay_add_all_digests(void)
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_digest_alias(SN_md5,"ssl2-md5");
164 EVP_add_digest_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_SHA
173 EVP_add_digest(EVP_sha1());
174 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
175 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
176#ifndef NO_DSA
177 EVP_add_digest(EVP_dss1());
178 EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
179 EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
180 EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
181#endif
182#endif
183#if !defined(NO_MDC2) && !defined(NO_DES)
184 EVP_add_digest(EVP_mdc2());
185#endif
186#ifndef NO_RIPEMD
187 EVP_add_digest(EVP_ripemd160());
188 EVP_add_digest_alias(SN_ripemd160,"ripemd");
189 EVP_add_digest_alias(SN_ripemd160,"rmd160");
190#endif
191 PKCS12_PBE_add();
192 PKCS5_PBE_add();
193 }
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
deleted file mode 100644
index c560733568..0000000000
--- a/src/lib/libcrypto/evp/digest.c
+++ /dev/null
@@ -1,92 +0,0 @@
1/* crypto/evp/digest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/objects.h>
62#include <openssl/evp.h>
63
64void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
65 {
66 ctx->digest=type;
67 type->init(&(ctx->md));
68 }
69
70void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
71 unsigned int count)
72 {
73 ctx->digest->update(&(ctx->md.base[0]),data,(unsigned long)count);
74 }
75
76void EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
77 {
78 ctx->digest->final(md,&(ctx->md.base[0]));
79 if (size != NULL)
80 *size=ctx->digest->md_size;
81 memset(&(ctx->md),0,sizeof(ctx->md));
82 }
83
84int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in)
85{
86 if ((in == NULL) || (in->digest == NULL)) {
87 EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED);
88 return 0;
89 }
90 memcpy((char *)out,(char *)in,in->digest->ctx_size);
91 return 1;
92}
diff --git a/src/lib/libcrypto/evp/e_null.c b/src/lib/libcrypto/evp/e_null.c
deleted file mode 100644
index 0a62c10aa9..0000000000
--- a/src/lib/libcrypto/evp/e_null.c
+++ /dev/null
@@ -1,97 +0,0 @@
1/* crypto/evp/e_null.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63
64static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
65 unsigned char *iv,int enc);
66static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
67 unsigned char *in, unsigned int inl);
68static EVP_CIPHER n_cipher=
69 {
70 NID_undef,
71 1,0,0,
72 null_init_key,
73 null_cipher,
74 NULL,
75 0,
76 NULL,
77 NULL,
78 };
79
80EVP_CIPHER *EVP_enc_null(void)
81 {
82 return(&n_cipher);
83 }
84
85static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
86 unsigned char *iv, int enc)
87 {
88 memset(&(ctx->c),0,sizeof(ctx->c));
89 }
90
91static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
92 unsigned char *in, unsigned int inl)
93 {
94 if (in != out)
95 memcpy((char *)out,(char *)in,(int)inl);
96 }
97
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c
deleted file mode 100644
index c7e58a75cc..0000000000
--- a/src/lib/libcrypto/evp/e_rc4.c
+++ /dev/null
@@ -1,115 +0,0 @@
1/* crypto/evp/e_rc4.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_RC4
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65
66static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
67 unsigned char *iv,int enc);
68static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
69 unsigned char *in, unsigned int inl);
70static EVP_CIPHER r4_cipher=
71 {
72 NID_rc4,
73 1,EVP_RC4_KEY_SIZE,0,
74 rc4_init_key,
75 rc4_cipher,
76 NULL,
77 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
78 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc4)),
79 NULL,
80 NULL,
81 };
82
83static EVP_CIPHER r4_40_cipher=
84 {
85 NID_rc4_40,
86 1,5 /* 40 bit */,0,
87 rc4_init_key,
88 rc4_cipher,
89 };
90
91EVP_CIPHER *EVP_rc4(void)
92 {
93 return(&r4_cipher);
94 }
95
96EVP_CIPHER *EVP_rc4_40(void)
97 {
98 return(&r4_40_cipher);
99 }
100
101static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
102 unsigned char *iv, int enc)
103 {
104 if (key != NULL)
105 memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx));
106 RC4_set_key(&(ctx->c.rc4.ks),EVP_CIPHER_CTX_key_length(ctx),
107 ctx->c.rc4.key);
108 }
109
110static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
111 unsigned char *in, unsigned int inl)
112 {
113 RC4(&(ctx->c.rc4.ks),inl,in,out);
114 }
115#endif
diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c
deleted file mode 100644
index 3a6628a75c..0000000000
--- a/src/lib/libcrypto/evp/e_xcbc_d.c
+++ /dev/null
@@ -1,112 +0,0 @@
1/* crypto/evp/e_xcbc_d.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_DES
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64
65static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc);
67static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
68 unsigned char *in, unsigned int inl);
69static EVP_CIPHER d_xcbc_cipher=
70 {
71 NID_desx_cbc,
72 8,24,8,
73 desx_cbc_init_key,
74 desx_cbc_cipher,
75 NULL,
76 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
77 sizeof((((EVP_CIPHER_CTX *)NULL)->c.desx_cbc)),
78 EVP_CIPHER_set_asn1_iv,
79 EVP_CIPHER_get_asn1_iv,
80 };
81
82EVP_CIPHER *EVP_desx_cbc(void)
83 {
84 return(&d_xcbc_cipher);
85 }
86
87static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
88 unsigned char *iv, int enc)
89 {
90 des_cblock *deskey = (des_cblock *)key;
91
92 if (iv != NULL)
93 memcpy(&(ctx->oiv[0]),iv,8);
94 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
95 if (deskey != NULL)
96 {
97 des_set_key(deskey,ctx->c.desx_cbc.ks);
98 memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8);
99 memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8);
100 }
101 }
102
103static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
104 unsigned char *in, unsigned int inl)
105 {
106 des_xcbc_encrypt(in,out,inl,ctx->c.desx_cbc.ks,
107 (des_cblock *)&(ctx->iv[0]),
108 &ctx->c.desx_cbc.inw,
109 &ctx->c.desx_cbc.outw,
110 ctx->encrypt);
111 }
112#endif
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c
deleted file mode 100644
index 0152624a76..0000000000
--- a/src/lib/libcrypto/evp/encode.c
+++ /dev/null
@@ -1,427 +0,0 @@
1/* crypto/evp/encode.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62
63#ifndef CHARSET_EBCDIC
64#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])
65#define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f])
66#else
67/* We assume that PEM encoded files are EBCDIC files
68 * (i.e., printable text files). Convert them here while decoding.
69 * When encoding, output is EBCDIC (text) format again.
70 * (No need for conversion in the conv_bin2ascii macro, as the
71 * underlying textstring data_bin2ascii[] is already EBCDIC)
72 */
73#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])
74#define conv_ascii2bin(a) (data_ascii2bin[os_toascii[a]&0x7f])
75#endif
76
77/* 64 char lines
78 * pad input with 0
79 * left over chars are set to =
80 * 1 byte => xx==
81 * 2 bytes => xxx=
82 * 3 bytes => xxxx
83 */
84#define BIN_PER_LINE (64/4*3)
85#define CHUNKS_PER_LINE (64/4)
86#define CHAR_PER_LINE (64+1)
87
88static unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\
89abcdefghijklmnopqrstuvwxyz0123456789+/";
90
91/* 0xF0 is a EOLN
92 * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing).
93 * 0xF2 is EOF
94 * 0xE0 is ignore at start of line.
95 * 0xFF is error
96 */
97
98#define B64_EOLN 0xF0
99#define B64_CR 0xF1
100#define B64_EOF 0xF2
101#define B64_WS 0xE0
102#define B64_ERROR 0xFF
103#define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3)
104
105static unsigned char data_ascii2bin[128]={
106 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
107 0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF,
108 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
109 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
110 0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
111 0xFF,0xFF,0xFF,0x3E,0xFF,0xF2,0xFF,0x3F,
112 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,
113 0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,
114 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06,
115 0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
116 0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,
117 0x17,0x18,0x19,0xFF,0xFF,0xFF,0xFF,0xFF,
118 0xFF,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,
119 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
120 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,
121 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF,
122 };
123
124void EVP_EncodeInit(EVP_ENCODE_CTX *ctx)
125 {
126 ctx->length=48;
127 ctx->num=0;
128 ctx->line_num=0;
129 }
130
131void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
132 unsigned char *in, int inl)
133 {
134 int i,j;
135 unsigned int total=0;
136
137 *outl=0;
138 if (inl == 0) return;
139 if ((ctx->num+inl) < ctx->length)
140 {
141 memcpy(&(ctx->enc_data[ctx->num]),in,inl);
142 ctx->num+=inl;
143 return;
144 }
145 if (ctx->num != 0)
146 {
147 i=ctx->length-ctx->num;
148 memcpy(&(ctx->enc_data[ctx->num]),in,i);
149 in+=i;
150 inl-=i;
151 j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length);
152 ctx->num=0;
153 out+=j;
154 *(out++)='\n';
155 *out='\0';
156 total=j+1;
157 }
158 while (inl >= ctx->length)
159 {
160 j=EVP_EncodeBlock(out,in,ctx->length);
161 in+=ctx->length;
162 inl-=ctx->length;
163 out+=j;
164 *(out++)='\n';
165 *out='\0';
166 total+=j+1;
167 }
168 if (inl != 0)
169 memcpy(&(ctx->enc_data[0]),in,inl);
170 ctx->num=inl;
171 *outl=total;
172 }
173
174void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
175 {
176 unsigned int ret=0;
177
178 if (ctx->num != 0)
179 {
180 ret=EVP_EncodeBlock(out,ctx->enc_data,ctx->num);
181 out[ret++]='\n';
182 out[ret]='\0';
183 ctx->num=0;
184 }
185 *outl=ret;
186 }
187
188int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int dlen)
189 {
190 int i,ret=0;
191 unsigned long l;
192
193 for (i=dlen; i > 0; i-=3)
194 {
195 if (i >= 3)
196 {
197 l= (((unsigned long)f[0])<<16L)|
198 (((unsigned long)f[1])<< 8L)|f[2];
199 *(t++)=conv_bin2ascii(l>>18L);
200 *(t++)=conv_bin2ascii(l>>12L);
201 *(t++)=conv_bin2ascii(l>> 6L);
202 *(t++)=conv_bin2ascii(l );
203 }
204 else
205 {
206 l=((unsigned long)f[0])<<16L;
207 if (i == 2) l|=((unsigned long)f[1]<<8L);
208
209 *(t++)=conv_bin2ascii(l>>18L);
210 *(t++)=conv_bin2ascii(l>>12L);
211 *(t++)=(i == 1)?'=':conv_bin2ascii(l>> 6L);
212 *(t++)='=';
213 }
214 ret+=4;
215 f+=3;
216 }
217
218 *t='\0';
219 return(ret);
220 }
221
222void EVP_DecodeInit(EVP_ENCODE_CTX *ctx)
223 {
224 ctx->length=30;
225 ctx->num=0;
226 ctx->line_num=0;
227 ctx->expect_nl=0;
228 }
229
230/* -1 for error
231 * 0 for last line
232 * 1 for full line
233 */
234int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
235 unsigned char *in, int inl)
236 {
237 int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl;
238 unsigned char *d;
239
240 n=ctx->num;
241 d=ctx->enc_data;
242 ln=ctx->line_num;
243 exp_nl=ctx->expect_nl;
244
245 /* last line of input. */
246 if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF)))
247 { rv=0; goto end; }
248
249 /* We parse the input data */
250 for (i=0; i<inl; i++)
251 {
252 /* If the current line is > 80 characters, scream alot */
253 if (ln >= 80) { rv= -1; goto end; }
254
255 /* Get char and put it into the buffer */
256 tmp= *(in++);
257 v=conv_ascii2bin(tmp);
258 /* only save the good data :-) */
259 if (!B64_NOT_BASE64(v))
260 {
261 d[n++]=tmp;
262 ln++;
263 }
264 else if (v == B64_ERROR)
265 {
266 rv= -1;
267 goto end;
268 }
269
270 /* have we seen a '=' which is 'definitly' the last
271 * input line. seof will point to the character that
272 * holds it. and eof will hold how many characters to
273 * chop off. */
274 if (tmp == '=')
275 {
276 if (seof == -1) seof=n;
277 eof++;
278 }
279
280 /* eoln */
281 if (v == B64_EOLN)
282 {
283 ln=0;
284 if (exp_nl)
285 {
286 exp_nl=0;
287 continue;
288 }
289 }
290 exp_nl=0;
291
292 /* If we are at the end of input and it looks like a
293 * line, process it. */
294 if (((i+1) == inl) && (((n&3) == 0) || eof))
295 v=B64_EOF;
296
297 if ((v == B64_EOF) || (n >= 64))
298 {
299 /* This is needed to work correctly on 64 byte input
300 * lines. We process the line and then need to
301 * accept the '\n' */
302 if ((v != B64_EOF) && (n >= 64)) exp_nl=1;
303 tmp2=v;
304 if (n > 0)
305 {
306 v=EVP_DecodeBlock(out,d,n);
307 if (v < 0) { rv=0; goto end; }
308 n=0;
309 ret+=(v-eof);
310 }
311 else
312 {
313 eof=1;
314 v=0;
315 }
316
317 /* This is the case where we have had a short
318 * but valid input line */
319 if ((v < ctx->length) && eof)
320 {
321 rv=0;
322 goto end;
323 }
324 else
325 ctx->length=v;
326
327 if (seof >= 0) { rv=0; goto end; }
328 out+=v;
329 }
330 }
331 rv=1;
332end:
333 *outl=ret;
334 ctx->num=n;
335 ctx->line_num=ln;
336 ctx->expect_nl=exp_nl;
337 return(rv);
338 }
339
340int EVP_DecodeBlock(unsigned char *t, unsigned char *f, int n)
341 {
342 int i,ret=0,a,b,c,d;
343 unsigned long l;
344
345 /* trim white space from the start of the line. */
346 while ((conv_ascii2bin(*f) == B64_WS) && (n > 0))
347 {
348 f++;
349 n--;
350 }
351
352 /* strip off stuff at the end of the line
353 * ascii2bin values B64_WS, B64_EOLN, B64_EOLN and B64_EOF */
354 while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n-1]))))
355 n--;
356
357 if (n%4 != 0) return(-1);
358
359 for (i=0; i<n; i+=4)
360 {
361 a=conv_ascii2bin(*(f++));
362 b=conv_ascii2bin(*(f++));
363 c=conv_ascii2bin(*(f++));
364 d=conv_ascii2bin(*(f++));
365 if ( (a & 0x80) || (b & 0x80) ||
366 (c & 0x80) || (d & 0x80))
367 return(-1);
368 l=( (((unsigned long)a)<<18L)|
369 (((unsigned long)b)<<12L)|
370 (((unsigned long)c)<< 6L)|
371 (((unsigned long)d) ));
372 *(t++)=(unsigned char)(l>>16L)&0xff;
373 *(t++)=(unsigned char)(l>> 8L)&0xff;
374 *(t++)=(unsigned char)(l )&0xff;
375 ret+=3;
376 }
377 return(ret);
378 }
379
380int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
381 {
382 int i;
383
384 *outl=0;
385 if (ctx->num != 0)
386 {
387 i=EVP_DecodeBlock(out,ctx->enc_data,ctx->num);
388 if (i < 0) return(-1);
389 ctx->num=0;
390 *outl=i;
391 return(1);
392 }
393 else
394 return(1);
395 }
396
397#ifdef undef
398int EVP_DecodeValid(unsigned char *buf, int len)
399 {
400 int i,num=0,bad=0;
401
402 if (len == 0) return(-1);
403 while (conv_ascii2bin(*buf) == B64_WS)
404 {
405 buf++;
406 len--;
407 if (len == 0) return(-1);
408 }
409
410 for (i=len; i >= 4; i-=4)
411 {
412 if ( (conv_ascii2bin(buf[0]) >= 0x40) ||
413 (conv_ascii2bin(buf[1]) >= 0x40) ||
414 (conv_ascii2bin(buf[2]) >= 0x40) ||
415 (conv_ascii2bin(buf[3]) >= 0x40))
416 return(-1);
417 buf+=4;
418 num+=1+(buf[2] != '=')+(buf[3] != '=');
419 }
420 if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN))
421 return(num);
422 if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) &&
423 (conv_ascii2bin(buf[0]) == B64_EOLN))
424 return(num);
425 return(1);
426 }
427#endif
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
deleted file mode 100644
index 570fe27d39..0000000000
--- a/src/lib/libcrypto/evp/evp.h
+++ /dev/null
@@ -1,720 +0,0 @@
1/* crypto/evp/evp.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_ENVELOPE_H
60#define HEADER_ENVELOPE_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifndef NO_MD2
67#include <openssl/md2.h>
68#endif
69#ifndef NO_MD5
70#include <openssl/md5.h>
71#endif
72#ifndef NO_SHA
73#include <openssl/sha.h>
74#endif
75#ifndef NO_RIPEMD
76#include <openssl/ripemd.h>
77#endif
78#ifndef NO_DES
79#include <openssl/des.h>
80#endif
81#ifndef NO_RC4
82#include <openssl/rc4.h>
83#endif
84#ifndef NO_RC2
85#include <openssl/rc2.h>
86#endif
87#ifndef NO_RC5
88#include <openssl/rc5.h>
89#endif
90#ifndef NO_BF
91#include <openssl/blowfish.h>
92#endif
93#ifndef NO_CAST
94#include <openssl/cast.h>
95#endif
96#ifndef NO_IDEA
97#include <openssl/idea.h>
98#endif
99#ifndef NO_MDC2
100#include <openssl/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#define PKCS5_SALT_LEN 8
113/* Default PKCS#5 iteration count */
114#define PKCS5_DEFAULT_ITER 2048
115
116#ifndef NO_RSA
117#include <openssl/rsa.h>
118#endif
119
120#ifndef NO_DSA
121#include <openssl/dsa.h>
122#endif
123
124#ifndef NO_DH
125#include <openssl/dh.h>
126#endif
127
128#include <openssl/objects.h>
129
130#define EVP_PK_RSA 0x0001
131#define EVP_PK_DSA 0x0002
132#define EVP_PK_DH 0x0004
133#define EVP_PKT_SIGN 0x0010
134#define EVP_PKT_ENC 0x0020
135#define EVP_PKT_EXCH 0x0040
136#define EVP_PKS_RSA 0x0100
137#define EVP_PKS_DSA 0x0200
138#define EVP_PKT_EXP 0x1000 /* <= 512 bit key */
139
140#define EVP_PKEY_NONE NID_undef
141#define EVP_PKEY_RSA NID_rsaEncryption
142#define EVP_PKEY_RSA2 NID_rsa
143#define EVP_PKEY_DSA NID_dsa
144#define EVP_PKEY_DSA1 NID_dsa_2
145#define EVP_PKEY_DSA2 NID_dsaWithSHA
146#define EVP_PKEY_DSA3 NID_dsaWithSHA1
147#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2
148#define EVP_PKEY_DH NID_dhKeyAgreement
149
150/* Type needs to be a bit field
151 * Sub-type needs to be for variations on the method, as in, can it do
152 * arbitary encryption.... */
153typedef struct evp_pkey_st
154 {
155 int type;
156 int save_type;
157 int references;
158 union {
159 char *ptr;
160#ifndef NO_RSA
161 struct rsa_st *rsa; /* RSA */
162#endif
163#ifndef NO_DSA
164 struct dsa_st *dsa; /* DSA */
165#endif
166#ifndef NO_DH
167 struct dh_st *dh; /* DH */
168#endif
169 } pkey;
170 int save_parameters;
171 STACK /*X509_ATTRIBUTE*/ *attributes; /* [ 0 ] */
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 associated with it.
187 * This can either be software or a token to provide the required low level
188 * routines.
189 */
190typedef 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
222typedef 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
248typedef 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
265
266#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0}
267
268#ifndef NO_DSA
269#define EVP_PKEY_DSA_method DSA_sign,DSA_verify, \
270 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \
271 EVP_PKEY_DSA4,0}
272#else
273#define EVP_PKEY_DSA_method EVP_PKEY_NULL_method
274#endif
275
276#ifndef NO_RSA
277#define EVP_PKEY_RSA_method RSA_sign,RSA_verify, \
278 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
279#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \
280 RSA_sign_ASN1_OCTET_STRING, \
281 RSA_verify_ASN1_OCTET_STRING, \
282 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
283#else
284#define EVP_PKEY_RSA_method EVP_PKEY_NULL_method
285#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method
286#endif
287
288#endif /* !EVP_MD */
289
290typedef struct env_md_ctx_st
291 {
292 const EVP_MD *digest;
293 union {
294 unsigned char base[4];
295#ifndef NO_MD2
296 MD2_CTX md2;
297#endif
298#ifndef NO_MD5
299 MD5_CTX md5;
300#endif
301#ifndef NO_RIPEMD
302 RIPEMD160_CTX ripemd160;
303#endif
304#ifndef NO_SHA
305 SHA_CTX sha;
306#endif
307#ifndef NO_MDC2
308 MDC2_CTX mdc2;
309#endif
310 } md;
311 } EVP_MD_CTX;
312
313typedef struct evp_cipher_st
314 {
315 int nid;
316 int block_size;
317 int key_len;
318 int iv_len;
319 void (*init)(); /* init for encryption */
320 void (*do_cipher)(); /* encrypt data */
321 void (*cleanup)(); /* used by cipher method */
322 int ctx_size; /* how big the ctx needs to be */
323 /* int set_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */
324 int (*set_asn1_parameters)(); /* Populate a ASN1_TYPE with parameters */
325 /* int get_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */
326 int (*get_asn1_parameters)(); /* Get parameters from a ASN1_TYPE */
327 } EVP_CIPHER;
328
329typedef struct evp_cipher_info_st
330 {
331 const EVP_CIPHER *cipher;
332 unsigned char iv[EVP_MAX_IV_LENGTH];
333 } EVP_CIPHER_INFO;
334
335typedef struct evp_cipher_ctx_st
336 {
337 const EVP_CIPHER *cipher;
338 int encrypt; /* encrypt or decrypt */
339 int buf_len; /* number we have left */
340
341 unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
342 unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
343 unsigned char buf[EVP_MAX_IV_LENGTH]; /* saved partial block */
344 int num; /* used by cfb/ofb mode */
345
346 char *app_data; /* aplication stuff */
347 union {
348#ifndef NO_RC4
349 struct
350 {
351 unsigned char key[EVP_RC4_KEY_SIZE];
352 RC4_KEY ks; /* working key */
353 } rc4;
354#endif
355#ifndef NO_DES
356 des_key_schedule des_ks;/* key schedule */
357 struct
358 {
359 des_key_schedule ks;/* key schedule */
360 des_cblock inw;
361 des_cblock outw;
362 } desx_cbc;
363 struct
364 {
365 des_key_schedule ks1;/* key schedule */
366 des_key_schedule ks2;/* key schedule (for ede) */
367 des_key_schedule ks3;/* key schedule (for ede3) */
368 } des_ede;
369#endif
370#ifndef NO_IDEA
371 IDEA_KEY_SCHEDULE idea_ks;/* key schedule */
372#endif
373#ifndef NO_RC2
374 RC2_KEY rc2_ks;/* key schedule */
375#endif
376#ifndef NO_RC5
377 RC5_32_KEY rc5_ks;/* key schedule */
378#endif
379#ifndef NO_BF
380 BF_KEY bf_ks;/* key schedule */
381#endif
382#ifndef NO_CAST
383 CAST_KEY cast_ks;/* key schedule */
384#endif
385 } c;
386 } EVP_CIPHER_CTX;
387
388typedef struct evp_Encode_Ctx_st
389 {
390 int num; /* number saved in a partial encode/decode */
391 int length; /* The length is either the output line length
392 * (in input bytes) or the shortest input line
393 * length that is ok. Once decoding begins,
394 * the length is adjusted up each time a longer
395 * line is decoded */
396 unsigned char enc_data[80]; /* data to encode */
397 int line_num; /* number read on current line */
398 int expect_nl;
399 } EVP_ENCODE_CTX;
400
401/* Password based encryption function */
402typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
403 ASN1_TYPE *param, EVP_CIPHER *cipher,
404 EVP_MD *md, int en_de);
405
406#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
407 (char *)(rsa))
408#define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
409 (char *)(dsa))
410#define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\
411 (char *)(dh))
412
413/* Add some extra combinations */
414#define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
415#define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
416#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
417#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
418
419#define EVP_MD_type(e) ((e)->type)
420#define EVP_MD_pkey_type(e) ((e)->pkey_type)
421#define EVP_MD_size(e) ((e)->md_size)
422#define EVP_MD_block_size(e) ((e)->block_size)
423
424#define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
425#define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
426#define EVP_MD_CTX_type(e) ((e)->digest)
427
428#define EVP_CIPHER_nid(e) ((e)->nid)
429#define EVP_CIPHER_block_size(e) ((e)->block_size)
430#define EVP_CIPHER_key_length(e) ((e)->key_len)
431#define EVP_CIPHER_iv_length(e) ((e)->iv_len)
432
433#define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
434#define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
435#define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
436#define EVP_CIPHER_CTX_key_length(e) ((e)->cipher->key_len)
437#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
438#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
439#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
440#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
441
442#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
443#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80)
444
445#define EVP_SignInit(a,b) EVP_DigestInit(a,b)
446#define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
447#define EVP_VerifyInit(a,b) EVP_DigestInit(a,b)
448#define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
449#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e)
450#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e)
451
452#ifdef CONST_STRICT
453void BIO_set_md(BIO *,const EVP_MD *md);
454#else
455# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md)
456#endif
457#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)
458#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)
459#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
460#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)
461
462#define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l))
463
464#define EVP_add_cipher_alias(n,alias) \
465 OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
466#define EVP_add_digest_alias(n,alias) \
467 OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))
468#define EVP_delete_cipher_alias(alias) \
469 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
470#define EVP_delete_digest_alias(alias) \
471 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
472
473
474int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);
475void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
476void EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
477 unsigned int cnt);
478void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
479
480int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify);
481void EVP_set_pw_prompt(char *prompt);
482char * EVP_get_pw_prompt(void);
483
484int EVP_BytesToKey(const EVP_CIPHER *type,EVP_MD *md,unsigned char *salt,
485 unsigned char *data, int datal, int count,
486 unsigned char *key,unsigned char *iv);
487
488void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
489 unsigned char *key, unsigned char *iv);
490void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
491 int *outl, unsigned char *in, int inl);
492void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
493
494void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
495 unsigned char *key, unsigned char *iv);
496void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
497 int *outl, unsigned char *in, int inl);
498int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
499
500void EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
501 unsigned char *key,unsigned char *iv,int enc);
502void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
503 int *outl, unsigned char *in, int inl);
504int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
505
506int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
507 EVP_PKEY *pkey);
508
509int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf,
510 unsigned int siglen,EVP_PKEY *pkey);
511
512int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek,
513 int ekl,unsigned char *iv,EVP_PKEY *priv);
514int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
515
516int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
517 int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk);
518void EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
519
520void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
521void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,
522 int *outl,unsigned char *in,int inl);
523void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
524int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int n);
525
526void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
527int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
528 unsigned char *in, int inl);
529int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
530 char *out, int *outl);
531int EVP_DecodeBlock(unsigned char *t, unsigned
532 char *f, int n);
533
534void ERR_load_EVP_strings(void );
535
536void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
537void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
538
539#ifdef HEADER_BIO_H
540BIO_METHOD *BIO_f_md(void);
541BIO_METHOD *BIO_f_base64(void);
542BIO_METHOD *BIO_f_cipher(void);
543BIO_METHOD *BIO_f_reliable(void);
544void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,unsigned char *k,
545 unsigned char *i, int enc);
546#endif
547
548EVP_MD *EVP_md_null(void);
549EVP_MD *EVP_md2(void);
550EVP_MD *EVP_md5(void);
551EVP_MD *EVP_sha(void);
552EVP_MD *EVP_sha1(void);
553EVP_MD *EVP_dss(void);
554EVP_MD *EVP_dss1(void);
555EVP_MD *EVP_mdc2(void);
556EVP_MD *EVP_ripemd160(void);
557
558EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */
559EVP_CIPHER *EVP_des_ecb(void);
560EVP_CIPHER *EVP_des_ede(void);
561EVP_CIPHER *EVP_des_ede3(void);
562EVP_CIPHER *EVP_des_cfb(void);
563EVP_CIPHER *EVP_des_ede_cfb(void);
564EVP_CIPHER *EVP_des_ede3_cfb(void);
565EVP_CIPHER *EVP_des_ofb(void);
566EVP_CIPHER *EVP_des_ede_ofb(void);
567EVP_CIPHER *EVP_des_ede3_ofb(void);
568EVP_CIPHER *EVP_des_cbc(void);
569EVP_CIPHER *EVP_des_ede_cbc(void);
570EVP_CIPHER *EVP_des_ede3_cbc(void);
571EVP_CIPHER *EVP_desx_cbc(void);
572EVP_CIPHER *EVP_rc4(void);
573EVP_CIPHER *EVP_rc4_40(void);
574EVP_CIPHER *EVP_idea_ecb(void);
575EVP_CIPHER *EVP_idea_cfb(void);
576EVP_CIPHER *EVP_idea_ofb(void);
577EVP_CIPHER *EVP_idea_cbc(void);
578EVP_CIPHER *EVP_rc2_ecb(void);
579EVP_CIPHER *EVP_rc2_cbc(void);
580EVP_CIPHER *EVP_rc2_40_cbc(void);
581EVP_CIPHER *EVP_rc2_64_cbc(void);
582EVP_CIPHER *EVP_rc2_cfb(void);
583EVP_CIPHER *EVP_rc2_ofb(void);
584EVP_CIPHER *EVP_bf_ecb(void);
585EVP_CIPHER *EVP_bf_cbc(void);
586EVP_CIPHER *EVP_bf_cfb(void);
587EVP_CIPHER *EVP_bf_ofb(void);
588EVP_CIPHER *EVP_cast5_ecb(void);
589EVP_CIPHER *EVP_cast5_cbc(void);
590EVP_CIPHER *EVP_cast5_cfb(void);
591EVP_CIPHER *EVP_cast5_ofb(void);
592EVP_CIPHER *EVP_rc5_32_12_16_cbc(void);
593EVP_CIPHER *EVP_rc5_32_12_16_ecb(void);
594EVP_CIPHER *EVP_rc5_32_12_16_cfb(void);
595EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);
596
597void SSLeay_add_all_algorithms(void);
598void SSLeay_add_all_ciphers(void);
599void SSLeay_add_all_digests(void);
600
601int EVP_add_cipher(EVP_CIPHER *cipher);
602int EVP_add_digest(EVP_MD *digest);
603
604const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
605const EVP_MD *EVP_get_digestbyname(const char *name);
606void EVP_cleanup(void);
607
608int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key,
609 int enc_key_len,EVP_PKEY *private_key);
610int EVP_PKEY_encrypt(unsigned char *enc_key,
611 unsigned char *key,int key_len,EVP_PKEY *pub_key);
612int EVP_PKEY_type(int type);
613int EVP_PKEY_bits(EVP_PKEY *pkey);
614int EVP_PKEY_size(EVP_PKEY *pkey);
615int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);
616EVP_PKEY * EVP_PKEY_new(void);
617void EVP_PKEY_free(EVP_PKEY *pkey);
618EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp,
619 long length);
620int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
621
622EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp,
623 long length);
624int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
625
626int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from);
627int EVP_PKEY_missing_parameters(EVP_PKEY *pkey);
628int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode);
629int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b);
630
631int EVP_CIPHER_type(const EVP_CIPHER *ctx);
632
633/* calls methods */
634int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
635int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
636
637/* These are used by EVP_CIPHER methods */
638int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
639int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
640
641/* PKCS5 password based encryption */
642int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
643 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
644 int en_de);
645int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
646 unsigned char *salt, int saltlen, int iter,
647 int keylen, unsigned char *out);
648int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
649 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
650 int en_de);
651
652void PKCS5_PBE_add(void);
653
654int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
655 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);
656int EVP_PBE_alg_add(int nid, EVP_CIPHER *cipher, EVP_MD *md,
657 EVP_PBE_KEYGEN *keygen);
658void EVP_PBE_cleanup(void);
659
660/* BEGIN ERROR CODES */
661/* The following lines are auto generated by the script mkerr.pl. Any changes
662 * made after this point may be overwritten when the script is next run.
663 */
664
665/* Error codes for the EVP functions. */
666
667/* Function codes. */
668#define EVP_F_D2I_PKEY 100
669#define EVP_F_EVP_DECRYPTFINAL 101
670#define EVP_F_EVP_MD_CTX_COPY 110
671#define EVP_F_EVP_OPENINIT 102
672#define EVP_F_EVP_PBE_ALG_ADD 115
673#define EVP_F_EVP_PBE_CIPHERINIT 116
674#define EVP_F_EVP_PKCS82PKEY 111
675#define EVP_F_EVP_PKCS8_SET_BROKEN 112
676#define EVP_F_EVP_PKEY2PKCS8 113
677#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
678#define EVP_F_EVP_PKEY_DECRYPT 104
679#define EVP_F_EVP_PKEY_ENCRYPT 105
680#define EVP_F_EVP_PKEY_NEW 106
681#define EVP_F_EVP_SIGNFINAL 107
682#define EVP_F_EVP_VERIFYFINAL 108
683#define EVP_F_PKCS5_PBE_KEYIVGEN 117
684#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118
685#define EVP_F_RC2_MAGIC_TO_METH 109
686
687/* Reason codes. */
688#define EVP_R_BAD_DECRYPT 100
689#define EVP_R_BN_DECODE_ERROR 112
690#define EVP_R_BN_PUBKEY_ERROR 113
691#define EVP_R_CIPHER_PARAMETER_ERROR 122
692#define EVP_R_DECODE_ERROR 114
693#define EVP_R_DIFFERENT_KEY_TYPES 101
694#define EVP_R_ENCODE_ERROR 115
695#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119
696#define EVP_R_INPUT_NOT_INITIALIZED 111
697#define EVP_R_IV_TOO_LARGE 102
698#define EVP_R_KEYGEN_FAILURE 120
699#define EVP_R_MISSING_PARMATERS 103
700#define EVP_R_NO_DSA_PARAMETERS 116
701#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
702#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
703#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117
704#define EVP_R_PUBLIC_KEY_NOT_RSA 106
705#define EVP_R_UNKNOWN_PBE_ALGORITHM 121
706#define EVP_R_UNSUPPORTED_CIPHER 107
707#define EVP_R_UNSUPPORTED_KEYLENGTH 123
708#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124
709#define EVP_R_UNSUPPORTED_KEY_SIZE 108
710#define EVP_R_UNSUPPORTED_PRF 125
711#define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118
712#define EVP_R_UNSUPPORTED_SALT_TYPE 126
713#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109
714#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110
715
716#ifdef __cplusplus
717}
718#endif
719#endif
720
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
deleted file mode 100644
index 5299a65b6a..0000000000
--- a/src/lib/libcrypto/evp/evp_enc.c
+++ /dev/null
@@ -1,270 +0,0 @@
1/* crypto/evp/evp_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62
63const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT;
64
65void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
66 {
67 memset(ctx,0,sizeof(EVP_CIPHER_CTX));
68 /* ctx->cipher=NULL; */
69 }
70
71void EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *data,
72 unsigned char *key, unsigned char *iv, int enc)
73 {
74 if (enc)
75 EVP_EncryptInit(ctx,data,key,iv);
76 else
77 EVP_DecryptInit(ctx,data,key,iv);
78 }
79
80void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
81 unsigned char *in, int inl)
82 {
83 if (ctx->encrypt)
84 EVP_EncryptUpdate(ctx,out,outl,in,inl);
85 else EVP_DecryptUpdate(ctx,out,outl,in,inl);
86 }
87
88int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
89 {
90 if (ctx->encrypt)
91 {
92 EVP_EncryptFinal(ctx,out,outl);
93 return(1);
94 }
95 else return(EVP_DecryptFinal(ctx,out,outl));
96 }
97
98void EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
99 unsigned char *key, unsigned char *iv)
100 {
101 if (cipher != NULL)
102 ctx->cipher=cipher;
103 ctx->cipher->init(ctx,key,iv,1);
104 ctx->encrypt=1;
105 ctx->buf_len=0;
106 }
107
108void EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
109 unsigned char *key, unsigned char *iv)
110 {
111 if (cipher != NULL)
112 ctx->cipher=cipher;
113 ctx->cipher->init(ctx,key,iv,0);
114 ctx->encrypt=0;
115 ctx->buf_len=0;
116 }
117
118
119void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
120 unsigned char *in, int inl)
121 {
122 int i,j,bl;
123
124 i=ctx->buf_len;
125 bl=ctx->cipher->block_size;
126 *outl=0;
127 if ((inl == 0) && (i != bl)) return;
128 if (i != 0)
129 {
130 if (i+inl < bl)
131 {
132 memcpy(&(ctx->buf[i]),in,inl);
133 ctx->buf_len+=inl;
134 return;
135 }
136 else
137 {
138 j=bl-i;
139 if (j != 0) memcpy(&(ctx->buf[i]),in,j);
140 ctx->cipher->do_cipher(ctx,out,ctx->buf,bl);
141 inl-=j;
142 in+=j;
143 out+=bl;
144 *outl+=bl;
145 }
146 }
147 i=inl%bl; /* how much is left */
148 inl-=i;
149 if (inl > 0)
150 {
151 ctx->cipher->do_cipher(ctx,out,in,inl);
152 *outl+=inl;
153 }
154
155 if (i != 0)
156 memcpy(ctx->buf,&(in[inl]),i);
157 ctx->buf_len=i;
158 }
159
160void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
161 {
162 int i,n,b,bl;
163
164 b=ctx->cipher->block_size;
165 if (b == 1)
166 {
167 *outl=0;
168 return;
169 }
170 bl=ctx->buf_len;
171 n=b-bl;
172 for (i=bl; i<b; i++)
173 ctx->buf[i]=n;
174 ctx->cipher->do_cipher(ctx,out,ctx->buf,b);
175 *outl=b;
176 }
177
178void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
179 unsigned char *in, int inl)
180 {
181 int b,bl,n;
182 int keep_last=0;
183
184 *outl=0;
185 if (inl == 0) return;
186
187 b=ctx->cipher->block_size;
188 if (b > 1)
189 {
190 /* Is the input a multiple of the block size? */
191 bl=ctx->buf_len;
192 n=inl+bl;
193 if (n%b == 0)
194 {
195 if (inl < b) /* must be 'just one' buff */
196 {
197 memcpy(&(ctx->buf[bl]),in,inl);
198 ctx->buf_len=b;
199 *outl=0;
200 return;
201 }
202 keep_last=1;
203 inl-=b; /* don't do the last block */
204 }
205 }
206 EVP_EncryptUpdate(ctx,out,outl,in,inl);
207
208 /* if we have 'decrypted' a multiple of block size, make sure
209 * we have a copy of this last block */
210 if (keep_last)
211 {
212 memcpy(&(ctx->buf[0]),&(in[inl]),b);
213#ifdef DEBUG
214 if (ctx->buf_len != 0)
215 {
216 abort();
217 }
218#endif
219 ctx->buf_len=b;
220 }
221 }
222
223int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
224 {
225 int i,b;
226 int n;
227
228 *outl=0;
229 b=ctx->cipher->block_size;
230 if (b > 1)
231 {
232 if (ctx->buf_len != b)
233 {
234 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
235 return(0);
236 }
237 EVP_EncryptUpdate(ctx,ctx->buf,&n,ctx->buf,0);
238 if (n != b)
239 return(0);
240 n=ctx->buf[b-1];
241 if (n > b)
242 {
243 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
244 return(0);
245 }
246 for (i=0; i<n; i++)
247 {
248 if (ctx->buf[--b] != n)
249 {
250 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
251 return(0);
252 }
253 }
254 n=ctx->cipher->block_size-n;
255 for (i=0; i<n; i++)
256 out[i]=ctx->buf[i];
257 *outl=n;
258 }
259 else
260 *outl=0;
261 return(1);
262 }
263
264void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
265 {
266 if ((c->cipher != NULL) && (c->cipher->cleanup != NULL))
267 c->cipher->cleanup(c);
268 memset(c,0,sizeof(EVP_CIPHER_CTX));
269 }
270
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c
deleted file mode 100644
index c61cc922e8..0000000000
--- a/src/lib/libcrypto/evp/evp_err.c
+++ /dev/null
@@ -1,136 +0,0 @@
1/* crypto/evp/evp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/evp.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA EVP_str_functs[]=
67 {
68{ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"},
69{ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"},
70{ERR_PACK(0,EVP_F_EVP_MD_CTX_COPY,0), "EVP_MD_CTX_copy"},
71{ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"},
72{ERR_PACK(0,EVP_F_EVP_PBE_ALG_ADD,0), "EVP_PBE_alg_add"},
73{ERR_PACK(0,EVP_F_EVP_PBE_CIPHERINIT,0), "EVP_PBE_CipherInit"},
74{ERR_PACK(0,EVP_F_EVP_PKCS82PKEY,0), "EVP_PKCS82PKEY"},
75{ERR_PACK(0,EVP_F_EVP_PKCS8_SET_BROKEN,0), "EVP_PKCS8_SET_BROKEN"},
76{ERR_PACK(0,EVP_F_EVP_PKEY2PKCS8,0), "EVP_PKEY2PKCS8"},
77{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"},
78{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"},
79{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"},
80{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"},
81{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"},
82{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"},
83{ERR_PACK(0,EVP_F_PKCS5_PBE_KEYIVGEN,0), "PKCS5_PBE_keyivgen"},
84{ERR_PACK(0,EVP_F_PKCS5_V2_PBE_KEYIVGEN,0), "PKCS5_v2_PBE_keyivgen"},
85{ERR_PACK(0,EVP_F_RC2_MAGIC_TO_METH,0), "RC2_MAGIC_TO_METH"},
86{0,NULL}
87 };
88
89static ERR_STRING_DATA EVP_str_reasons[]=
90 {
91{EVP_R_BAD_DECRYPT ,"bad decrypt"},
92{EVP_R_BN_DECODE_ERROR ,"bn decode error"},
93{EVP_R_BN_PUBKEY_ERROR ,"bn pubkey error"},
94{EVP_R_CIPHER_PARAMETER_ERROR ,"cipher parameter error"},
95{EVP_R_DECODE_ERROR ,"decode error"},
96{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"},
97{EVP_R_ENCODE_ERROR ,"encode error"},
98{EVP_R_EVP_PBE_CIPHERINIT_ERROR ,"evp pbe cipherinit error"},
99{EVP_R_INPUT_NOT_INITIALIZED ,"input not initialized"},
100{EVP_R_IV_TOO_LARGE ,"iv too large"},
101{EVP_R_KEYGEN_FAILURE ,"keygen failure"},
102{EVP_R_MISSING_PARMATERS ,"missing parmaters"},
103{EVP_R_NO_DSA_PARAMETERS ,"no dsa parameters"},
104{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"},
105{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"},
106{EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE ,"pkcs8 unknown broken type"},
107{EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
108{EVP_R_UNKNOWN_PBE_ALGORITHM ,"unknown pbe algorithm"},
109{EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
110{EVP_R_UNSUPPORTED_KEYLENGTH ,"unsupported keylength"},
111{EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION,"unsupported key derivation function"},
112{EVP_R_UNSUPPORTED_KEY_SIZE ,"unsupported key size"},
113{EVP_R_UNSUPPORTED_PRF ,"unsupported prf"},
114{EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM ,"unsupported private key algorithm"},
115{EVP_R_UNSUPPORTED_SALT_TYPE ,"unsupported salt type"},
116{EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"},
117{EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"},
118{0,NULL}
119 };
120
121#endif
122
123void ERR_load_EVP_strings(void)
124 {
125 static int init=1;
126
127 if (init)
128 {
129 init=0;
130#ifndef NO_ERR
131 ERR_load_strings(ERR_LIB_EVP,EVP_str_functs);
132 ERR_load_strings(ERR_LIB_EVP,EVP_str_reasons);
133#endif
134
135 }
136 }
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
deleted file mode 100644
index 21eda418bc..0000000000
--- a/src/lib/libcrypto/evp/evp_key.c
+++ /dev/null
@@ -1,156 +0,0 @@
1/* crypto/evp/evp_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64
65/* should be init to zeros. */
66static char prompt_string[80];
67
68void EVP_set_pw_prompt(char *prompt)
69 {
70 if (prompt == NULL)
71 prompt_string[0]='\0';
72 else
73 strncpy(prompt_string,prompt,79);
74 }
75
76char *EVP_get_pw_prompt(void)
77 {
78 if (prompt_string[0] == '\0')
79 return(NULL);
80 else
81 return(prompt_string);
82 }
83
84#ifdef NO_DES
85int des_read_pw_string(char *buf,int len,const char *prompt,int verify);
86#endif
87
88int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)
89 {
90 if ((prompt == NULL) && (prompt_string[0] != '\0'))
91 prompt=prompt_string;
92 return(des_read_pw_string(buf,len,prompt,verify));
93 }
94
95int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, unsigned char *salt,
96 unsigned char *data, int datal, int count, unsigned char *key,
97 unsigned char *iv)
98 {
99 EVP_MD_CTX c;
100 unsigned char md_buf[EVP_MAX_MD_SIZE];
101 int niv,nkey,addmd=0;
102 unsigned int mds=0,i;
103
104 nkey=type->key_len;
105 niv=type->iv_len;
106
107 if (data == NULL) return(nkey);
108
109 for (;;)
110 {
111 EVP_DigestInit(&c,md);
112 if (addmd++)
113 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
114 EVP_DigestUpdate(&c,data,datal);
115 if (salt != NULL)
116 EVP_DigestUpdate(&c,salt,8);
117 EVP_DigestFinal(&c,&(md_buf[0]),&mds);
118
119 for (i=1; i<(unsigned int)count; i++)
120 {
121 EVP_DigestInit(&c,md);
122 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
123 EVP_DigestFinal(&c,&(md_buf[0]),&mds);
124 }
125 i=0;
126 if (nkey)
127 {
128 for (;;)
129 {
130 if (nkey == 0) break;
131 if (i == mds) break;
132 if (key != NULL)
133 *(key++)=md_buf[i];
134 nkey--;
135 i++;
136 }
137 }
138 if (niv && (i != mds))
139 {
140 for (;;)
141 {
142 if (niv == 0) break;
143 if (i == mds) break;
144 if (iv != NULL)
145 *(iv++)=md_buf[i];
146 niv--;
147 i++;
148 }
149 }
150 if ((nkey == 0) && (niv == 0)) break;
151 }
152 memset(&c,0,sizeof(c));
153 memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE);
154 return(type->key_len);
155 }
156
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
deleted file mode 100644
index 3f9bf55828..0000000000
--- a/src/lib/libcrypto/evp/evp_lib.c
+++ /dev/null
@@ -1,138 +0,0 @@
1/* crypto/evp/evp_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63
64int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
65 {
66 int ret;
67
68 if (c->cipher->set_asn1_parameters != NULL)
69 ret=c->cipher->set_asn1_parameters(c,type);
70 else
71 ret=1;
72 return(ret);
73 }
74
75int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
76 {
77 int ret;
78
79 if (c->cipher->get_asn1_parameters != NULL)
80 ret=c->cipher->get_asn1_parameters(c,type);
81 else
82 ret=1;
83 return(ret);
84 }
85
86int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
87 {
88 int i=0,l;
89
90 if (type != NULL)
91 {
92 l=EVP_CIPHER_CTX_iv_length(c);
93 i=ASN1_TYPE_get_octetstring(type,c->oiv,l);
94 if (i != l)
95 return(-1);
96 else if (i > 0)
97 memcpy(c->iv,c->oiv,l);
98 }
99 return(i);
100 }
101
102int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
103 {
104 int i=0,j;
105
106 if (type != NULL)
107 {
108 j=EVP_CIPHER_CTX_iv_length(c);
109 i=ASN1_TYPE_set_octetstring(type,c->oiv,j);
110 }
111 return(i);
112 }
113
114/* Convert the various cipher NIDs and dummies to a proper OID NID */
115int EVP_CIPHER_type(const EVP_CIPHER *ctx)
116{
117 int nid;
118 nid = EVP_CIPHER_nid(ctx);
119
120 switch(nid) {
121
122 case NID_rc2_cbc:
123 case NID_rc2_64_cbc:
124 case NID_rc2_40_cbc:
125
126 return NID_rc2_cbc;
127
128 case NID_rc4:
129 case NID_rc4_40:
130
131 return NID_rc4;
132
133 default:
134
135 return nid;
136 }
137}
138
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c
deleted file mode 100644
index 353c3ad667..0000000000
--- a/src/lib/libcrypto/evp/evp_pbe.c
+++ /dev/null
@@ -1,134 +0,0 @@
1/* evp_pbe.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/evp.h>
61#include <openssl/x509.h>
62#include "cryptlib.h"
63
64/* Password based encryption (PBE) functions */
65
66static STACK *pbe_algs;
67
68/* Setup a cipher context from a PBE algorithm */
69
70typedef struct {
71int pbe_nid;
72EVP_CIPHER *cipher;
73EVP_MD *md;
74EVP_PBE_KEYGEN *keygen;
75} EVP_PBE_CTL;
76
77int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
78 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de)
79{
80
81 EVP_PBE_CTL *pbetmp, pbelu;
82 int i;
83 pbelu.pbe_nid = OBJ_obj2nid(pbe_obj);
84 if (pbelu.pbe_nid != NID_undef) i = sk_find(pbe_algs, (char *)&pbelu);
85 else i = -1;
86
87 if (i == -1) {
88 char obj_tmp[80];
89 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM);
90 if (!pbe_obj) strcpy (obj_tmp, "NULL");
91 else i2t_ASN1_OBJECT(obj_tmp, 80, pbe_obj);
92 ERR_add_error_data(2, "TYPE=", obj_tmp);
93 return 0;
94 }
95 if (passlen == -1) passlen = strlen(pass);
96 pbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i);
97 i = (*pbetmp->keygen)(ctx, pass, passlen, param, pbetmp->cipher,
98 pbetmp->md, en_de);
99 if (!i) {
100 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE);
101 return 0;
102 }
103 return 1;
104}
105
106static int pbe_cmp (EVP_PBE_CTL **pbe1, EVP_PBE_CTL **pbe2)
107{
108 return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid);
109}
110
111/* Add a PBE algorithm */
112
113int EVP_PBE_alg_add (int nid, EVP_CIPHER *cipher, EVP_MD *md,
114 EVP_PBE_KEYGEN *keygen)
115{
116 EVP_PBE_CTL *pbe_tmp;
117 if (!pbe_algs) pbe_algs = sk_new (pbe_cmp);
118 if (!(pbe_tmp = (EVP_PBE_CTL*) Malloc (sizeof(EVP_PBE_CTL)))) {
119 EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
120 return 0;
121 }
122 pbe_tmp->pbe_nid = nid;
123 pbe_tmp->cipher = cipher;
124 pbe_tmp->md = md;
125 pbe_tmp->keygen = keygen;
126 sk_push (pbe_algs, (char *)pbe_tmp);
127 return 1;
128}
129
130void EVP_PBE_cleanup(void)
131{
132 sk_pop_free(pbe_algs, FreeFunc);
133 pbe_algs = NULL;
134}
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
deleted file mode 100644
index 421e452db1..0000000000
--- a/src/lib/libcrypto/evp/evp_pkey.c
+++ /dev/null
@@ -1,298 +0,0 @@
1/* evp_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include "cryptlib.h"
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* Extract a private key from a PKCS8 structure */
66
67EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
68{
69 EVP_PKEY *pkey;
70#ifndef NO_RSA
71 RSA *rsa;
72#endif
73#ifndef NO_DSA
74 DSA *dsa;
75 ASN1_INTEGER *dsapriv;
76 STACK *ndsa;
77 BN_CTX *ctx;
78 int plen;
79#endif
80 X509_ALGOR *a;
81 unsigned char *p;
82 int pkeylen;
83 char obj_tmp[80];
84
85 switch (p8->broken) {
86 case PKCS8_OK:
87 p = p8->pkey->value.octet_string->data;
88 pkeylen = p8->pkey->value.octet_string->length;
89 break;
90
91 case PKCS8_NO_OCTET:
92 p = p8->pkey->value.sequence->data;
93 pkeylen = p8->pkey->value.sequence->length;
94 break;
95
96 default:
97 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
98 return NULL;
99 break;
100 }
101 if (!(pkey = EVP_PKEY_new())) {
102 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
103 return NULL;
104 }
105 a = p8->pkeyalg;
106 switch (OBJ_obj2nid(a->algorithm))
107 {
108#ifndef NO_RSA
109 case NID_rsaEncryption:
110 if (!(rsa = d2i_RSAPrivateKey (NULL, &p, pkeylen))) {
111 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
112 return NULL;
113 }
114 EVP_PKEY_assign_RSA (pkey, rsa);
115 break;
116#endif
117#ifndef NO_DSA
118 case NID_dsa:
119 /* PKCS#8 DSA is weird: you just get a private key integer
120 * and parameters in the AlgorithmIdentifier the pubkey must
121 * be recalculated.
122 */
123
124 /* Check for broken Netscape Database DSA PKCS#8, UGH! */
125 if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {
126 if(!(ndsa = ASN1_seq_unpack(p, pkeylen,
127 (char *(*)())d2i_ASN1_INTEGER,
128 ASN1_STRING_free))) {
129 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
130 return NULL;
131 }
132 if(sk_num(ndsa) != 2 ) {
133 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
134 sk_pop_free(ndsa, ASN1_STRING_free);
135 return NULL;
136 }
137 dsapriv = (ASN1_INTEGER *) sk_pop(ndsa);
138 sk_pop_free(ndsa, ASN1_STRING_free);
139 } else if (!(dsapriv=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {
140 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
141 return NULL;
142 }
143 /* Retrieve parameters */
144 if (a->parameter->type != V_ASN1_SEQUENCE) {
145 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_NO_DSA_PARAMETERS);
146 return NULL;
147 }
148 p = a->parameter->value.sequence->data;
149 plen = a->parameter->value.sequence->length;
150 if (!(dsa = d2i_DSAparams (NULL, &p, plen))) {
151 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
152 return NULL;
153 }
154 /* We have parameters now set private key */
155 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(dsapriv, NULL))) {
156 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);
157 DSA_free (dsa);
158 return NULL;
159 }
160 /* Calculate public key (ouch!) */
161 if (!(dsa->pub_key = BN_new())) {
162 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
163 DSA_free (dsa);
164 return NULL;
165 }
166 if (!(ctx = BN_CTX_new())) {
167 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
168 DSA_free (dsa);
169 return NULL;
170 }
171
172 if (!BN_mod_exp(dsa->pub_key, dsa->g,
173 dsa->priv_key, dsa->p, ctx)) {
174
175 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);
176 BN_CTX_free (ctx);
177 DSA_free (dsa);
178 return NULL;
179 }
180
181 EVP_PKEY_assign_DSA (pkey, dsa);
182 BN_CTX_free (ctx);
183 break;
184#endif
185 default:
186 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
187 if (!a->algorithm) strcpy (obj_tmp, "NULL");
188 else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);
189 ERR_add_error_data(2, "TYPE=", obj_tmp);
190 EVP_PKEY_free (pkey);
191 return NULL;
192 }
193 return pkey;
194}
195
196/* Turn a private key into a PKCS8 structure */
197
198PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
199{
200 PKCS8_PRIV_KEY_INFO *p8;
201#ifndef NO_DSA
202 ASN1_INTEGER *dpkey;
203 unsigned char *p, *q;
204 int len;
205#endif
206 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
207 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
208 return NULL;
209 }
210 ASN1_INTEGER_set (p8->version, 0);
211 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
212 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
213 PKCS8_PRIV_KEY_INFO_free (p8);
214 return NULL;
215 }
216 switch (EVP_PKEY_type(pkey->type)) {
217#ifndef NO_RSA
218 case EVP_PKEY_RSA:
219
220 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
221 p8->pkeyalg->parameter->type = V_ASN1_NULL;
222 if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,
223 &p8->pkey->value.octet_string)) {
224 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
225 PKCS8_PRIV_KEY_INFO_free (p8);
226 return NULL;
227 }
228 break;
229#endif
230#ifndef NO_DSA
231 case EVP_PKEY_DSA:
232 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
233
234 /* get paramaters and place in AlgorithmIdentifier */
235 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
236 if (!(p = Malloc(len))) {
237 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
238 PKCS8_PRIV_KEY_INFO_free (p8);
239 return NULL;
240 }
241 q = p;
242 i2d_DSAparams (pkey->pkey.dsa, &q);
243 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
244 p8->pkeyalg->parameter->value.sequence = ASN1_STRING_new();
245 ASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, len);
246 Free(p);
247 /* Get private key into an integer and pack */
248 if (!(dpkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
249 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
250 PKCS8_PRIV_KEY_INFO_free (p8);
251 return NULL;
252 }
253
254 if (!ASN1_pack_string((char *)dpkey, i2d_ASN1_INTEGER,
255 &p8->pkey->value.octet_string)) {
256 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
257 ASN1_INTEGER_free (dpkey);
258 PKCS8_PRIV_KEY_INFO_free (p8);
259 return NULL;
260 }
261 ASN1_INTEGER_free (dpkey);
262 break;
263#endif
264 default:
265 EVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
266 PKCS8_PRIV_KEY_INFO_free (p8);
267 return NULL;
268 }
269 p8->pkey->type = V_ASN1_OCTET_STRING;
270 RAND_seed (p8->pkey->value.octet_string->data,
271 p8->pkey->value.octet_string->length);
272 return p8;
273}
274
275PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
276{
277 switch (broken) {
278
279 case PKCS8_OK:
280 p8->broken = PKCS8_OK;
281 return p8;
282 break;
283
284 case PKCS8_NO_OCTET:
285 p8->broken = PKCS8_NO_OCTET;
286 p8->pkey->type = V_ASN1_SEQUENCE;
287 return p8;
288 break;
289
290 default:
291 EVPerr(EVP_F_EVP_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
292 return NULL;
293 break;
294
295 }
296}
297
298
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c
deleted file mode 100644
index 8ea826868e..0000000000
--- a/src/lib/libcrypto/evp/m_dss.c
+++ /dev/null
@@ -1,83 +0,0 @@
1/* crypto/evp/m_dss.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65#ifndef NO_SHA
66static EVP_MD dsa_md=
67 {
68 NID_dsaWithSHA,
69 NID_dsaWithSHA,
70 SHA_DIGEST_LENGTH,
71 SHA1_Init,
72 SHA1_Update,
73 SHA1_Final,
74 EVP_PKEY_DSA_method,
75 SHA_CBLOCK,
76 sizeof(EVP_MD *)+sizeof(SHA_CTX),
77 };
78
79EVP_MD *EVP_dss(void)
80 {
81 return(&dsa_md);
82 }
83#endif
diff --git a/src/lib/libcrypto/evp/m_dss1.c b/src/lib/libcrypto/evp/m_dss1.c
deleted file mode 100644
index 9d8d1ce23e..0000000000
--- a/src/lib/libcrypto/evp/m_dss1.c
+++ /dev/null
@@ -1,83 +0,0 @@
1/* crypto/evp/m_dss1.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_SHA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66static EVP_MD dss1_md=
67 {
68 NID_dsa,
69 NID_dsaWithSHA1,
70 SHA_DIGEST_LENGTH,
71 SHA1_Init,
72 SHA1_Update,
73 SHA1_Final,
74 EVP_PKEY_DSA_method,
75 SHA_CBLOCK,
76 sizeof(EVP_MD *)+sizeof(SHA_CTX),
77 };
78
79EVP_MD *EVP_dss1(void)
80 {
81 return(&dss1_md);
82 }
83#endif
diff --git a/src/lib/libcrypto/evp/m_md5.c b/src/lib/libcrypto/evp/m_md5.c
deleted file mode 100644
index 9fc9530127..0000000000
--- a/src/lib/libcrypto/evp/m_md5.c
+++ /dev/null
@@ -1,83 +0,0 @@
1/* crypto/evp/m_md5.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_MD5
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66static EVP_MD md5_md=
67 {
68 NID_md5,
69 NID_md5WithRSAEncryption,
70 MD5_DIGEST_LENGTH,
71 MD5_Init,
72 MD5_Update,
73 MD5_Final,
74 EVP_PKEY_RSA_method,
75 MD5_CBLOCK,
76 sizeof(EVP_MD *)+sizeof(MD5_CTX),
77 };
78
79EVP_MD *EVP_md5(void)
80 {
81 return(&md5_md);
82 }
83#endif
diff --git a/src/lib/libcrypto/evp/m_null.c b/src/lib/libcrypto/evp/m_null.c
deleted file mode 100644
index e2dadf3dab..0000000000
--- a/src/lib/libcrypto/evp/m_null.c
+++ /dev/null
@@ -1,88 +0,0 @@
1/* crypto/evp/m_null.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65static void function(void)
66 {
67 }
68
69static 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
83EVP_MD *EVP_md_null(void)
84 {
85 return(&null_md);
86 }
87
88
diff --git a/src/lib/libcrypto/evp/m_ripemd.c b/src/lib/libcrypto/evp/m_ripemd.c
deleted file mode 100644
index 3d781a4e8d..0000000000
--- a/src/lib/libcrypto/evp/m_ripemd.c
+++ /dev/null
@@ -1,84 +0,0 @@
1/* crypto/evp/m_ripemd.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_RIPEMD
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/ripemd.h>
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66
67static EVP_MD ripemd160_md=
68 {
69 NID_ripemd160,
70 NID_ripemd160WithRSA,
71 RIPEMD160_DIGEST_LENGTH,
72 RIPEMD160_Init,
73 RIPEMD160_Update,
74 RIPEMD160_Final,
75 EVP_PKEY_RSA_method,
76 RIPEMD160_CBLOCK,
77 sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX),
78 };
79
80EVP_MD *EVP_ripemd160(void)
81 {
82 return(&ripemd160_md);
83 }
84#endif
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c
deleted file mode 100644
index 57a1ab0cce..0000000000
--- a/src/lib/libcrypto/evp/m_sha1.c
+++ /dev/null
@@ -1,83 +0,0 @@
1/* crypto/evp/m_sha1.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_SHA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66static EVP_MD sha1_md=
67 {
68 NID_sha1,
69 NID_sha1WithRSAEncryption,
70 SHA_DIGEST_LENGTH,
71 SHA1_Init,
72 SHA1_Update,
73 SHA1_Final,
74 EVP_PKEY_RSA_method,
75 SHA_CBLOCK,
76 sizeof(EVP_MD *)+sizeof(SHA_CTX),
77 };
78
79EVP_MD *EVP_sha1(void)
80 {
81 return(&sha1_md);
82 }
83#endif
diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c
deleted file mode 100644
index 3e8f460328..0000000000
--- a/src/lib/libcrypto/evp/names.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/* crypto/evp/names.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65int EVP_add_cipher(EVP_CIPHER *c)
66 {
67 int r;
68
69 r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
70 if (r == 0) return(0);
71 r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
72 return(r);
73 }
74
75int EVP_add_digest(EVP_MD *md)
76 {
77 int r;
78 const char *name;
79
80 name=OBJ_nid2sn(md->type);
81 r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(char *)md);
82 if (r == 0) return(0);
83 r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(char *)md);
84 if (r == 0) return(0);
85
86 if (md->type != md->pkey_type)
87 {
88 r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type),
89 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
90 if (r == 0) return(0);
91 r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type),
92 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
93 }
94 return(r);
95 }
96
97const EVP_CIPHER *EVP_get_cipherbyname(const char *name)
98 {
99 const EVP_CIPHER *cp;
100
101 cp=(const EVP_CIPHER *)OBJ_NAME_get(name,OBJ_NAME_TYPE_CIPHER_METH);
102 return(cp);
103 }
104
105const EVP_MD *EVP_get_digestbyname(const char *name)
106 {
107 const EVP_MD *cp;
108
109 cp=(const EVP_MD *)OBJ_NAME_get(name,OBJ_NAME_TYPE_MD_METH);
110 return(cp);
111 }
112
113void EVP_cleanup(void)
114 {
115 OBJ_NAME_cleanup(OBJ_NAME_TYPE_CIPHER_METH);
116 OBJ_NAME_cleanup(OBJ_NAME_TYPE_MD_METH);
117 EVP_PBE_cleanup();
118 }
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c
deleted file mode 100644
index e3dae52d4d..0000000000
--- a/src/lib/libcrypto/evp/p5_crpt.c
+++ /dev/null
@@ -1,146 +0,0 @@
1/* p5_crpt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/x509.h>
62#include <openssl/evp.h>
63#include "cryptlib.h"
64
65/* PKCS#5 v1.5 compatible PBE functions: see PKCS#5 v2.0 for more info.
66 */
67
68void PKCS5_PBE_add(void)
69{
70#ifndef NO_DES
71# ifndef NO_MD5
72EVP_PBE_alg_add(NID_pbeWithMD5AndDES_CBC, EVP_des_cbc(), EVP_md5(),
73 PKCS5_PBE_keyivgen);
74# endif
75# ifndef NO_MD2
76EVP_PBE_alg_add(NID_pbeWithMD2AndDES_CBC, EVP_des_cbc(), EVP_md2(),
77 PKCS5_PBE_keyivgen);
78# endif
79# ifndef NO_SHA
80EVP_PBE_alg_add(NID_pbeWithSHA1AndDES_CBC, EVP_des_cbc(), EVP_sha1(),
81 PKCS5_PBE_keyivgen);
82# endif
83#endif
84#ifndef NO_RC2
85# ifndef NO_MD5
86EVP_PBE_alg_add(NID_pbeWithMD5AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md5(),
87 PKCS5_PBE_keyivgen);
88# endif
89# ifndef NO_MD2
90EVP_PBE_alg_add(NID_pbeWithMD2AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md2(),
91 PKCS5_PBE_keyivgen);
92# endif
93# ifndef NO_SHA
94EVP_PBE_alg_add(NID_pbeWithSHA1AndRC2_CBC, EVP_rc2_64_cbc(), EVP_sha1(),
95 PKCS5_PBE_keyivgen);
96# endif
97#endif
98#ifndef NO_HMAC
99EVP_PBE_alg_add(NID_pbes2, NULL, NULL, PKCS5_v2_PBE_keyivgen);
100#endif
101}
102
103int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
104 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
105 int en_de)
106{
107 EVP_MD_CTX ctx;
108 unsigned char md_tmp[EVP_MAX_MD_SIZE];
109 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
110 int i;
111 PBEPARAM *pbe;
112 int saltlen, iter;
113 unsigned char *salt, *pbuf;
114
115 /* Extract useful info from parameter */
116 pbuf = param->value.sequence->data;
117 if (!param || (param->type != V_ASN1_SEQUENCE) ||
118 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
119 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
120 return 0;
121 }
122
123 if (!pbe->iter) iter = 1;
124 else iter = ASN1_INTEGER_get (pbe->iter);
125 salt = pbe->salt->data;
126 saltlen = pbe->salt->length;
127
128 EVP_DigestInit (&ctx, md);
129 EVP_DigestUpdate (&ctx, pass, passlen);
130 EVP_DigestUpdate (&ctx, salt, saltlen);
131 PBEPARAM_free(pbe);
132 EVP_DigestFinal (&ctx, md_tmp, NULL);
133 for (i = 1; i < iter; i++) {
134 EVP_DigestInit(&ctx, md);
135 EVP_DigestUpdate(&ctx, md_tmp, EVP_MD_size(md));
136 EVP_DigestFinal (&ctx, md_tmp, NULL);
137 }
138 memcpy (key, md_tmp, EVP_CIPHER_key_length(cipher));
139 memcpy (iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)),
140 EVP_CIPHER_iv_length(cipher));
141 EVP_CipherInit(cctx, cipher, key, iv, en_de);
142 memset(md_tmp, 0, EVP_MAX_MD_SIZE);
143 memset(key, 0, EVP_MAX_KEY_LENGTH);
144 memset(iv, 0, EVP_MAX_IV_LENGTH);
145 return 1;
146}
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c
deleted file mode 100644
index 27a2c518be..0000000000
--- a/src/lib/libcrypto/evp/p5_crpt2.c
+++ /dev/null
@@ -1,247 +0,0 @@
1/* p5_crpt2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#if !defined(NO_HMAC) && !defined(NO_SHA)
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/x509.h>
62#include <openssl/evp.h>
63#include <openssl/hmac.h>
64#include "cryptlib.h"
65
66/* set this to print out info about the keygen algorithm */
67/* #define DEBUG_PKCS5V2 */
68
69#ifdef DEBUG_PKCS5V2
70 static void h__dump (const unsigned char *p, int len);
71#endif
72
73/* This is an implementation of PKCS#5 v2.0 password based encryption key
74 * derivation function PBKDF2 using the only currently defined function HMAC
75 * with SHA1. Verified against test vectors posted by Peter Gutmann
76 * <pgut001@cs.auckland.ac.nz> to the PKCS-TNG <pkcs-tng@rsa.com> mailing list.
77 */
78
79int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
80 unsigned char *salt, int saltlen, int iter,
81 int keylen, unsigned char *out)
82{
83 unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4];
84 int cplen, j, k, tkeylen;
85 unsigned long i = 1;
86 HMAC_CTX hctx;
87 p = out;
88 tkeylen = keylen;
89 if(passlen == -1) passlen = strlen(pass);
90 while(tkeylen) {
91 if(tkeylen > SHA_DIGEST_LENGTH) cplen = SHA_DIGEST_LENGTH;
92 else cplen = tkeylen;
93 /* We are unlikely to ever use more than 256 blocks (5120 bits!)
94 * but just in case...
95 */
96 itmp[0] = (unsigned char)((i >> 24) & 0xff);
97 itmp[1] = (unsigned char)((i >> 16) & 0xff);
98 itmp[2] = (unsigned char)((i >> 8) & 0xff);
99 itmp[3] = (unsigned char)(i & 0xff);
100 HMAC_Init(&hctx, pass, passlen, EVP_sha1());
101 HMAC_Update(&hctx, salt, saltlen);
102 HMAC_Update(&hctx, itmp, 4);
103 HMAC_Final(&hctx, digtmp, NULL);
104 memcpy(p, digtmp, cplen);
105 for(j = 1; j < iter; j++) {
106 HMAC(EVP_sha1(), pass, passlen,
107 digtmp, SHA_DIGEST_LENGTH, digtmp, NULL);
108 for(k = 0; k < cplen; k++) p[k] ^= digtmp[k];
109 }
110 tkeylen-= cplen;
111 i++;
112 p+= cplen;
113 }
114 HMAC_cleanup(&hctx);
115#ifdef DEBUG_PKCS5V2
116 fprintf(stderr, "Password:\n");
117 h__dump (pass, passlen);
118 fprintf(stderr, "Salt:\n");
119 h__dump (salt, saltlen);
120 fprintf(stderr, "Iteration count %d\n", iter);
121 fprintf(stderr, "Key:\n");
122 h__dump (out, keylen);
123#endif
124 return 1;
125}
126
127#ifdef DO_TEST
128main()
129{
130 unsigned char out[4];
131 unsigned char salt[] = {0x12, 0x34, 0x56, 0x78};
132 PKCS5_PBKDF2_HMAC_SHA1("password", -1, salt, 4, 5, 4, out);
133 fprintf(stderr, "Out %02X %02X %02X %02X\n",
134 out[0], out[1], out[2], out[3]);
135}
136
137#endif
138
139/* Now the key derivation function itself. This is a bit evil because
140 * it has to check the ASN1 parameters are valid: and there are quite a
141 * few of them...
142 */
143
144int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
145 ASN1_TYPE *param, EVP_CIPHER *c, EVP_MD *md,
146 int en_de)
147{
148 unsigned char *pbuf, *salt, key[EVP_MAX_KEY_LENGTH];
149 int saltlen, keylen, iter, plen;
150 PBE2PARAM *pbe2 = NULL;
151 const EVP_CIPHER *cipher;
152 PBKDF2PARAM *kdf = NULL;
153
154 pbuf = param->value.sequence->data;
155 plen = param->value.sequence->length;
156 if(!param || (param->type != V_ASN1_SEQUENCE) ||
157 !(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
158 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
159 return 0;
160 }
161
162 /* See if we recognise the key derivation function */
163
164 if(OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) {
165 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
166 EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION);
167 goto err;
168 }
169
170 /* lets see if we recognise the encryption algorithm.
171 */
172
173 cipher = EVP_get_cipherbyname(
174 OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm)));
175
176 if(!cipher) {
177 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
178 EVP_R_UNSUPPORTED_CIPHER);
179 goto err;
180 }
181
182 /* Fixup cipher based on AlgorithmIdentifier */
183 EVP_CipherInit(ctx, cipher, NULL, NULL, en_de);
184 if(EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) {
185 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
186 EVP_R_CIPHER_PARAMETER_ERROR);
187 goto err;
188 }
189 keylen = EVP_CIPHER_CTX_key_length(ctx);
190
191 /* Now decode key derivation function */
192
193 pbuf = pbe2->keyfunc->parameter->value.sequence->data;
194 plen = pbe2->keyfunc->parameter->value.sequence->length;
195 if(!pbe2->keyfunc->parameter ||
196 (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE) ||
197 !(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) {
198 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
199 goto err;
200 }
201
202 PBE2PARAM_free(pbe2);
203 pbe2 = NULL;
204
205 /* Now check the parameters of the kdf */
206
207 if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != keylen)){
208 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
209 EVP_R_UNSUPPORTED_KEYLENGTH);
210 goto err;
211 }
212
213 if(kdf->prf && (OBJ_obj2nid(kdf->prf->algorithm) != NID_hmacWithSHA1)) {
214 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
215 goto err;
216 }
217
218 if(kdf->salt->type != V_ASN1_OCTET_STRING) {
219 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
220 EVP_R_UNSUPPORTED_SALT_TYPE);
221 goto err;
222 }
223
224 /* it seems that its all OK */
225 salt = kdf->salt->value.octet_string->data;
226 saltlen = kdf->salt->value.octet_string->length;
227 iter = ASN1_INTEGER_get(kdf->iter);
228 PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key);
229 EVP_CipherInit(ctx, NULL, key, NULL, en_de);
230 memset(key, 0, keylen);
231 PBKDF2PARAM_free(kdf);
232 return 1;
233
234 err:
235 PBE2PARAM_free(pbe2);
236 PBKDF2PARAM_free(kdf);
237 return 0;
238}
239
240#ifdef DEBUG_PKCS5V2
241static void h__dump (const unsigned char *p, int len)
242{
243 for (; len --; p++) fprintf(stderr, "%02X ", *p);
244 fprintf(stderr, "\n");
245}
246#endif
247#endif
diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c
deleted file mode 100644
index 57b5daa453..0000000000
--- a/src/lib/libcrypto/evp/p_dec.c
+++ /dev/null
@@ -1,87 +0,0 @@
1/* crypto/evp/p_dec.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/rand.h>
62#ifndef NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_PKEY_decrypt(unsigned char *key, unsigned char *ek, int ekl,
70 EVP_PKEY *priv)
71 {
72 int ret= -1;
73
74#ifndef NO_RSA
75 if (priv->type != EVP_PKEY_RSA)
76 {
77#endif
78 EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
79#ifndef NO_RSA
80 goto err;
81 }
82
83 ret=RSA_private_decrypt(ekl,ek,key,priv->pkey.rsa,RSA_PKCS1_PADDING);
84err:
85#endif
86 return(ret);
87 }
diff --git a/src/lib/libcrypto/evp/p_enc.c b/src/lib/libcrypto/evp/p_enc.c
deleted file mode 100644
index 4cf6acaf5d..0000000000
--- a/src/lib/libcrypto/evp/p_enc.c
+++ /dev/null
@@ -1,86 +0,0 @@
1/* crypto/evp/p_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/rand.h>
62#ifndef NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_PKEY_encrypt(unsigned char *ek, unsigned char *key, int key_len,
70 EVP_PKEY *pubk)
71 {
72 int ret=0;
73
74#ifndef NO_RSA
75 if (pubk->type != EVP_PKEY_RSA)
76 {
77#endif
78 EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
79#ifndef NO_RSA
80 goto err;
81 }
82 ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING);
83err:
84#endif
85 return(ret);
86 }
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
deleted file mode 100644
index 3422b77de6..0000000000
--- a/src/lib/libcrypto/evp/p_lib.c
+++ /dev/null
@@ -1,275 +0,0 @@
1/* crypto/evp/p_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/objects.h>
62#include <openssl/evp.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509.h>
65
66static void EVP_PKEY_free_it(EVP_PKEY *x);
67int EVP_PKEY_bits(EVP_PKEY *pkey)
68 {
69#ifndef NO_RSA
70 if (pkey->type == EVP_PKEY_RSA)
71 return(BN_num_bits(pkey->pkey.rsa->n));
72 else
73#endif
74#ifndef NO_DSA
75 if (pkey->type == EVP_PKEY_DSA)
76 return(BN_num_bits(pkey->pkey.dsa->p));
77#endif
78 return(0);
79 }
80
81int EVP_PKEY_size(EVP_PKEY *pkey)
82 {
83 if (pkey == NULL)
84 return(0);
85#ifndef NO_RSA
86 if (pkey->type == EVP_PKEY_RSA)
87 return(RSA_size(pkey->pkey.rsa));
88 else
89#endif
90#ifndef NO_DSA
91 if (pkey->type == EVP_PKEY_DSA)
92 return(DSA_size(pkey->pkey.dsa));
93#endif
94 return(0);
95 }
96
97int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
98 {
99#ifndef NO_DSA
100 if (pkey->type == EVP_PKEY_DSA)
101 {
102 int ret=pkey->save_parameters=mode;
103
104 if (mode >= 0)
105 pkey->save_parameters=mode;
106 return(ret);
107 }
108#endif
109 return(0);
110 }
111
112int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from)
113 {
114 if (to->type != from->type)
115 {
116 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);
117 goto err;
118 }
119
120 if (EVP_PKEY_missing_parameters(from))
121 {
122 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARMATERS);
123 goto err;
124 }
125#ifndef NO_DSA
126 if (to->type == EVP_PKEY_DSA)
127 {
128 BIGNUM *a;
129
130 if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err;
131 if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p);
132 to->pkey.dsa->p=a;
133
134 if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err;
135 if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q);
136 to->pkey.dsa->q=a;
137
138 if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err;
139 if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g);
140 to->pkey.dsa->g=a;
141 }
142#endif
143 return(1);
144err:
145 return(0);
146 }
147
148int EVP_PKEY_missing_parameters(EVP_PKEY *pkey)
149 {
150#ifndef NO_DSA
151 if (pkey->type == EVP_PKEY_DSA)
152 {
153 DSA *dsa;
154
155 dsa=pkey->pkey.dsa;
156 if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
157 return(1);
158 }
159#endif
160 return(0);
161 }
162
163int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b)
164 {
165#ifndef NO_DSA
166 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
167 {
168 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
169 BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) ||
170 BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g))
171 return(0);
172 else
173 return(1);
174 }
175#endif
176 return(-1);
177 }
178
179EVP_PKEY *EVP_PKEY_new(void)
180 {
181 EVP_PKEY *ret;
182
183 ret=(EVP_PKEY *)Malloc(sizeof(EVP_PKEY));
184 if (ret == NULL)
185 {
186 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);
187 return(NULL);
188 }
189 ret->type=EVP_PKEY_NONE;
190 ret->references=1;
191 ret->pkey.ptr=NULL;
192 ret->attributes=NULL;
193 ret->save_parameters=1;
194 return(ret);
195 }
196
197int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
198 {
199 if (pkey == NULL) return(0);
200 if (pkey->pkey.ptr != NULL)
201 EVP_PKEY_free_it(pkey);
202 pkey->type=EVP_PKEY_type(type);
203 pkey->save_type=type;
204 pkey->pkey.ptr=key;
205 return(1);
206 }
207
208int EVP_PKEY_type(int type)
209 {
210 switch (type)
211 {
212 case EVP_PKEY_RSA:
213 case EVP_PKEY_RSA2:
214 return(EVP_PKEY_RSA);
215 case EVP_PKEY_DSA:
216 case EVP_PKEY_DSA1:
217 case EVP_PKEY_DSA2:
218 case EVP_PKEY_DSA3:
219 case EVP_PKEY_DSA4:
220 return(EVP_PKEY_DSA);
221 case EVP_PKEY_DH:
222 return(EVP_PKEY_DH);
223 default:
224 return(NID_undef);
225 }
226 }
227
228void EVP_PKEY_free(EVP_PKEY *x)
229 {
230 int i;
231
232 if (x == NULL) return;
233
234 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY);
235#ifdef REF_PRINT
236 REF_PRINT("EVP_PKEY",x);
237#endif
238 if (i > 0) return;
239#ifdef REF_CHECK
240 if (i < 0)
241 {
242 fprintf(stderr,"EVP_PKEY_free, bad reference count\n");
243 abort();
244 }
245#endif
246 EVP_PKEY_free_it(x);
247 Free((char *)x);
248 }
249
250static void EVP_PKEY_free_it(EVP_PKEY *x)
251 {
252 switch (x->type)
253 {
254#ifndef NO_RSA
255 case EVP_PKEY_RSA:
256 case EVP_PKEY_RSA2:
257 RSA_free(x->pkey.rsa);
258 break;
259#endif
260#ifndef NO_DSA
261 case EVP_PKEY_DSA:
262 case EVP_PKEY_DSA2:
263 case EVP_PKEY_DSA3:
264 case EVP_PKEY_DSA4:
265 DSA_free(x->pkey.dsa);
266 break;
267#endif
268#ifndef NO_DH
269 case EVP_PKEY_DH:
270 DH_free(x->pkey.dh);
271 break;
272#endif
273 }
274 }
275
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
deleted file mode 100644
index ddb9fd6942..0000000000
--- a/src/lib/libcrypto/evp/p_open.c
+++ /dev/null
@@ -1,113 +0,0 @@
1/* crypto/evp/p_open.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66int EVP_OpenInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char *ek,
67 int ekl, unsigned char *iv, EVP_PKEY *priv)
68 {
69 unsigned char *key=NULL;
70 int i,size=0,ret=0;
71
72 if (priv->type != EVP_PKEY_RSA)
73 {
74 EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA);
75 ret= -1;
76 goto err;
77 }
78
79 size=RSA_size(priv->pkey.rsa);
80 key=(unsigned char *)Malloc(size+2);
81 if (key == NULL)
82 {
83 /* ERROR */
84 EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE);
85 ret= -1;
86 goto err;
87 }
88
89 i=EVP_PKEY_decrypt(key,ek,ekl,priv);
90 if (i != type->key_len)
91 {
92 /* ERROR */
93 goto err;
94 }
95
96 EVP_CIPHER_CTX_init(ctx);
97 EVP_DecryptInit(ctx,type,key,iv);
98 ret=1;
99err:
100 if (key != NULL) memset(key,0,size);
101 Free(key);
102 return(ret);
103 }
104
105int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
106 {
107 int i;
108
109 i=EVP_DecryptFinal(ctx,out,outl);
110 EVP_DecryptInit(ctx,NULL,NULL,NULL);
111 return(i);
112 }
113#endif
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c
deleted file mode 100644
index 09b46f4b0e..0000000000
--- a/src/lib/libcrypto/evp/p_seal.c
+++ /dev/null
@@ -1,108 +0,0 @@
1/* crypto/evp/p_seal.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/rand.h>
62#ifndef NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
70 int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk)
71 {
72 unsigned char key[EVP_MAX_KEY_LENGTH];
73 int i;
74
75 if (npubk <= 0) return(0);
76 RAND_bytes(key,EVP_MAX_KEY_LENGTH);
77 if (type->iv_len > 0)
78 RAND_bytes(iv,type->iv_len);
79
80 EVP_CIPHER_CTX_init(ctx);
81 EVP_EncryptInit(ctx,type,key,iv);
82
83 for (i=0; i<npubk; i++)
84 {
85 ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_key_length(type),
86 pubk[i]);
87 if (ekl[i] <= 0) return(-1);
88 }
89 return(npubk);
90 }
91
92/* MACRO
93void EVP_SealUpdate(ctx,out,outl,in,inl)
94EVP_CIPHER_CTX *ctx;
95unsigned char *out;
96int *outl;
97unsigned char *in;
98int inl;
99 {
100 EVP_EncryptUpdate(ctx,out,outl,in,inl);
101 }
102*/
103
104void EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
105 {
106 EVP_EncryptFinal(ctx,out,outl);
107 EVP_EncryptInit(ctx,NULL,NULL,NULL);
108 }
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c
deleted file mode 100644
index 1fa32ac17e..0000000000
--- a/src/lib/libcrypto/evp/p_sign.c
+++ /dev/null
@@ -1,112 +0,0 @@
1/* crypto/evp/p_sign.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65#ifdef undef
66void EVP_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
67 {
68 EVP_DigestInit(ctx,type);
69 }
70
71void EVP_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data,
72 unsigned int count)
73 {
74 EVP_DigestUpdate(ctx,data,count);
75 }
76#endif
77
78int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
79 EVP_PKEY *pkey)
80 {
81 unsigned char m[EVP_MAX_MD_SIZE];
82 unsigned int m_len;
83 int i,ok=0,v;
84 MS_STATIC EVP_MD_CTX tmp_ctx;
85
86 *siglen=0;
87 EVP_MD_CTX_copy(&tmp_ctx,ctx);
88 EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len);
89 for (i=0; i<4; i++)
90 {
91 v=ctx->digest->required_pkey_type[i];
92 if (v == 0) break;
93 if (pkey->type == v)
94 {
95 ok=1;
96 break;
97 }
98 }
99 if (!ok)
100 {
101 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
102 return(0);
103 }
104 if (ctx->digest->sign == NULL)
105 {
106 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED);
107 return(0);
108 }
109 return(ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen,
110 pkey->pkey.ptr));
111 }
112
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c
deleted file mode 100644
index dcb54f3abb..0000000000
--- a/src/lib/libcrypto/evp/p_verify.c
+++ /dev/null
@@ -1,99 +0,0 @@
1/* crypto/evp/p_verify.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65int EVP_VerifyFinal(EVP_MD_CTX *ctx, unsigned char *sigbuf,
66 unsigned int siglen, EVP_PKEY *pkey)
67 {
68 unsigned char m[EVP_MAX_MD_SIZE];
69 unsigned int m_len;
70 int i,ok=0,v;
71 MS_STATIC EVP_MD_CTX tmp_ctx;
72
73 for (i=0; i<4; i++)
74 {
75 v=ctx->digest->required_pkey_type[i];
76 if (v == 0) break;
77 if (pkey->type == v)
78 {
79 ok=1;
80 break;
81 }
82 }
83 if (!ok)
84 {
85 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
86 return(-1);
87 }
88 EVP_MD_CTX_copy(&tmp_ctx,ctx);
89 EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len);
90 if (ctx->digest->verify == NULL)
91 {
92 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
93 return(0);
94 }
95
96 return(ctx->digest->verify(ctx->digest->type,m,m_len,
97 sigbuf,siglen,pkey->pkey.ptr));
98 }
99