Fix case of new functions in error files.
[openssl.git] / crypto / crypto.c
1 /* crypto/crypto.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 /* If you are happy to use the assmbler version of bn/bn_mulw.c, define
60  * BN_ASM */
61 #ifndef BN_ASM
62 #undef BN_ASM
63 #define X86_ASM
64 #endif
65
66 #ifndef DES_ASM
67 #undef DES_ASM
68 #endif
69
70 #ifndef BF_ASM
71 #undef BF_ASM
72 #endif
73
74 /* The following defines are only to break the compiles into chunks.
75  * If you wish to not compile some sections, use the 'NO_XXX' macros
76  */
77 #ifndef CRYPTO_SUBSET
78 /* Define all subset symbols. */
79 #define CRYPTO_LIB_SUBSET
80 #define CRYPTO_ASN1_SUBSET
81 #define CRYPTO_BN_SUBSET
82 #define CRYPTO_BUFFER_SUBSET
83 #define CRYPTO_BIO_SUBSET
84 #define CRYPTO_CONF_SUBSET
85 #define CRYPTO_DES_SUBSET
86 #define CRYPTO_DH_SUBSET
87 #define CRYPTO_DSA_SUBSET
88 #define CRYPTO_ERROR_SUBSET
89 #define CRYPTO_EVP_SUBSET
90 #define CRYPTO_IDEA_SUBSET
91 #define CRYPTO_LHASH_SUBSET
92 #define CRYPTO_MD_SUBSET
93 #define CRYPTO_MDC2_SUBSET
94 #define CRYPTO_METH_SUBSET
95 #define CRYPTO_OBJECTS_SUBSET
96 #define CRYPTO_PEM_SUBSET
97 #define CRYPTO_RAND_SUBSET
98 #define CRYPTO_RC_SUBSET
99 #define CRYPTO_BLOWFISH_SUBSET
100 #define CRYPTO_CAST_SUBSET
101 #define CRYPTO_RSA_SUBSET
102 #define CRYPTO_SHA_SUBSET
103 #define CRYPTO_HMAC_SUBSET
104 #define CRYPTO_SHA1_SUBSET
105 #define CRYPTO_STACK_SUBSET
106 #define CRYPTO_TXT_DB_SUBSET
107 #define CRYPTO_X509_SUBSET
108 #define CRYPTO_PKCS7_SUBSET
109 #endif
110
111 #include <stdio.h>
112 #include <stdlib.h>
113 #include <string.h>
114
115 #define USE_SOCKETS
116 #include "../e_os.h"
117
118 #include "buffer.h"
119 #include "bio.h"
120 #include "stack.h"
121 #include "lhash.h"
122
123 #include "err.h"
124
125 #include "bn.h"
126 #include "evp.h"
127
128 #include "rand.h"
129 #include "conf.h"
130 #include "txt_db.h"
131
132 #include "x509.h"
133 #include "pkcs7.h"
134 #include "pem.h"
135 #include "asn1.h"
136 #include "objects.h"
137
138 #ifdef CRYPTO_LIB_SUBSET
139 #include "cryptlib.c"
140 #include "mem.c"
141 #include "cversion.c"
142 #endif
143
144 #ifdef CRYPTO_ASN1_SUBSET
145 #include "asn1/a_meth.c"
146 #include "asn1/a_bitstr.c"
147 #include "asn1/a_d2i_fp.c"
148 #include "asn1/a_dup.c"
149 #include "asn1/a_hdr.c"
150 #include "asn1/a_i2d_fp.c"
151 #include "asn1/a_int.c"
152 #include "asn1/a_bool.c"
153 #include "asn1/a_bytes.c"
154 #include "asn1/a_object.c"
155 #include "asn1/a_octet.c"
156 #include "asn1/a_print.c"
157 #include "asn1/a_set.c"
158 #include "asn1/a_sign.c"
159 #include "asn1/a_type.c"
160 #include "asn1/a_utctm.c"
161 #include "asn1/a_verify.c"
162 #include "asn1/a_digest.c"
163 #include "asn1/asn1_err.c"
164 #include "asn1/asn1_lib.c"
165 #include "asn1/asn1_par.c"
166 #ifndef NO_DH
167 #include "asn1/d2i_dhp.c"
168 #include "asn1/i2d_dhp.c"
169 #endif
170 #ifndef NO_DSA
171 #include "asn1/d2i_dsap.c"
172 #include "asn1/i2d_dsap.c"
173 #include "asn1/d2i_s_pr.c"
174 #include "asn1/i2d_s_pr.c"
175 #include "asn1/d2i_s_pu.c"
176 #include "asn1/i2d_s_pu.c"
177 #endif
178 #ifndef NO_RSA
179 #include "asn1/d2i_r_pr.c"
180 #include "asn1/i2d_r_pr.c"
181 #include "asn1/d2i_r_pu.c"
182 #include "asn1/i2d_r_pu.c"
183 #include "asn1/n_pkey.c"
184 #endif
185 #include "asn1/d2i_pr.c"
186 #include "asn1/d2i_pu.c"
187 #include "asn1/i2d_pr.c"
188 #include "asn1/i2d_pu.c"
189 #include "asn1/f_int.c"
190 #include "asn1/f_string.c"
191 #include "asn1/p7_dgst.c"
192 #include "asn1/p7_enc.c"
193 #include "asn1/p7_enc_c.c"
194 #include "asn1/p7_evp.c"
195 #include "asn1/p7_i_s.c"
196 #include "asn1/p7_lib.c"
197 #include "asn1/p7_recip.c"
198 #include "asn1/p7_s_e.c"
199 #include "asn1/p7_signd.c"
200 #include "asn1/p7_signi.c"
201 #include "asn1/t_pkey.c"
202 #include "asn1/t_req.c"
203 #include "asn1/t_x509.c"
204 #include "asn1/x_algor.c"
205 #include "asn1/x_attrib.c"
206 #include "asn1/x_exten.c"
207 #include "asn1/x_cinf.c"
208 #include "asn1/x_crl.c"
209 #include "asn1/x_info.c"
210 #include "asn1/x_name.c"
211 #include "asn1/x_pkey.c"
212 #include "asn1/x_pubkey.c"
213 #include "asn1/x_req.c"
214 #include "asn1/x_sig.c"
215 #include "asn1/x_spki.c"
216 #include "asn1/x_val.c"
217 #include "asn1/x_x509.c"
218 #endif
219
220 #ifdef CRYPTO_BN_SUBSET
221 #include "bn/bn_add.c"
222 #include "bn/bn_div.c"
223 #include "bn/bn_exp.c"
224 #include "bn/bn_mont.c"
225 #include "bn/bn_recp.c"
226 #include "bn/bn_gcd.c"
227 #include "bn/bn_lib.c"
228 #include "bn/bn_mod.c"
229 #include "bn/bn_mul.c"
230 #ifndef BN_ASM
231 #include "bn/bn_mulw.c"
232 #endif
233 #include "bn/bn_prime.c"
234 #include "bn/bn_rand.c"
235 #include "bn/bn_shift.c"
236 #include "bn/bn_sqr.c"
237 #include "bn/bn_sub.c"
238 #include "bn/bn_word.c"
239 #include "bn/bn_print.c"
240 #include "bn/bn_err.c"
241 #include "bn/bn_blind.c"
242 #endif
243
244 #ifdef CRYPTO_BIO_SUBSET
245 #include "bio/bf_buff.c"
246 #include "bio/bf_null.c"
247 #include "bio/bf_nbio.c"
248 #include "bio/bio_cb.c"
249 #include "bio/bio_lib.c"
250 #include "bio/bss_fd.c"
251 #include "bio/bss_file.c"
252 #include "bio/bss_mem.c"
253 #include "bio/bss_null.c"
254 #ifdef VMS
255 #include "bio/bss_rtcp.c"
256 #endif
257 #include "bio/bss_sock.c"
258 #include "bio/bss_conn.c"
259 #include "bio/bss_acpt.c"
260 #include "bio/b_sock.c"
261 #include "bio/b_print.c"
262 #include "bio/b_dump.c"
263 #include "bio/bio_err.c"
264 #endif
265
266 #ifdef CRYPTO_BUFFER_SUBSET
267 #include "buffer/buf_err.c"
268 #include "buffer/buffer.c"
269 #endif
270
271 #ifdef CRYPTO_CONF_SUBSET
272 #include "conf/conf.c"
273 #include "conf/conf_err.c"
274 #endif
275
276 #ifdef CRYPTO_DES_SUBSET
277 #include "des/read_pwd.c"
278 #ifndef NO_DES
279 #ifndef DES_ASM
280 #include "des/fcrypt_b.c"
281 #include "des/des_enc.c"
282 #endif
283 #include "des/cbc_cksm.c"
284 #include "des/xcbc_enc.c"
285 #include "des/cbc_enc.c"
286 #include "des/cfb64ede.c"
287 #include "des/cfb64enc.c"
288 #include "des/cfb_enc.c"
289 #include "des/ecb3_enc.c"
290 #include "des/ecb_enc.c"
291 #include "des/enc_read.c"
292 #include "des/enc_writ.c"
293 #include "des/fcrypt.c"
294 #include "des/ofb64ede.c"
295 #include "des/ofb64enc.c"
296 #include "des/ofb_enc.c"
297 #include "des/pcbc_enc.c"
298 #include "des/qud_cksm.c"
299 #include "des/rand_key.c"
300 #include "des/read2pwd.c"
301 #include "des/rpc_enc.c"
302 #include "des/set_key.c"
303 #include "des/str2key.c"
304 #include "des/supp.c"
305 #endif
306 #endif
307
308 #ifdef CRYPTO_DH_SUBSET
309 #ifndef NO_DH
310 #include "dh/dh_check.c"
311 #include "dh/dh_err.c"
312 #include "dh/dh_gen.c"
313 #include "dh/dh_key.c"
314 #include "dh/dh_lib.c"
315 #endif
316 #endif
317
318 #ifdef CRYPTO_DSA_SUBSET
319 #ifndef NO_DSA
320 #include "dsa/dsa_gen.c"
321 #include "dsa/dsa_key.c"
322 #include "dsa/dsa_lib.c"
323 #include "dsa/dsa_sign.c"
324 #include "dsa/dsa_vrf.c"
325 #include "dsa/dsa_err.c"
326 #endif
327 #endif
328
329 #ifdef CRYPTO_ERROR_SUBSET
330 #include "err/err.c"
331 #include "err/err_all.c"
332 #include "err/err_prn.c"
333 #endif
334
335 #ifdef CRYPTO_EVP_SUBSET
336 #include "evp/bio_md.c"
337 #include "evp/bio_b64.c"
338 #include "evp/bio_enc.c"
339 #include "evp/c_all.c"
340 #include "evp/digest.c"
341 #ifndef NO_DES
342 #include "evp/e_cbc_3d.c"
343 #include "evp/e_cfb_3d.c"
344 #include "evp/e_ecb_3d.c"
345 #include "evp/e_ofb_3d.c"
346 #include "evp/e_cbc_d.c"
347 #include "evp/e_cfb_d.c"
348 #include "evp/e_xcbc_d.c"
349 #include "evp/e_ecb_d.c"
350 #include "evp/e_ofb_d.c"
351 #endif
352 #ifndef NO_IDEA
353 #include "evp/e_cbc_i.c"
354 #include "evp/e_cfb_i.c"
355 #include "evp/e_ecb_i.c"
356 #include "evp/e_ofb_i.c"
357 #endif
358 #ifndef NO_RC2
359 #include "evp/e_cbc_r2.c"
360 #include "evp/e_cfb_r2.c"
361 #include "evp/e_ecb_r2.c"
362 #include "evp/e_ofb_r2.c"
363 #endif
364 #ifndef NO_BLOWFISH
365 #include "evp/e_cbc_bf.c"
366 #include "evp/e_cfb_bf.c"
367 #include "evp/e_ecb_bf.c"
368 #include "evp/e_ofb_bf.c"
369 #endif
370 #ifndef NO_CAST
371 #include "evp/e_cbc_c.c"
372 #include "evp/e_cfb_c.c"
373 #include "evp/e_ecb_c.c"
374 #include "evp/e_ofb_c.c"
375 #endif
376 #ifndef NO_RC4
377 #include "evp/e_rc4.c"
378 #endif
379 #include "evp/names.c"
380 #include "evp/e_null.c"
381 #include "evp/encode.c"
382 #include "evp/evp_enc.c"
383 #include "evp/evp_err.c"
384 #include "evp/evp_key.c"
385 #include "evp/m_null.c"
386 #include "evp/p_lib.c"
387 #ifndef NO_RSA
388 #include "evp/p_open.c"
389 #include "evp/p_seal.c"
390 #endif
391 #include "evp/p_sign.c"
392 #include "evp/p_verify.c"
393 #endif
394
395 #ifdef CRYPTO_IDEA_SUBSET
396 #ifndef NO_IDEA
397 #include "idea/i_cbc.c"
398 #include "idea/i_cfb64.c"
399 #include "idea/i_ecb.c"
400 #include "idea/i_ofb64.c"
401 #include "idea/i_skey.c"
402 #endif
403 #endif
404
405 #ifdef CRYPTO_BLOWFISH_SUBSET
406 #ifndef NO_BLOWFISH
407 #include "bf/bf_cfb64.c"
408 #include "bf/bf_ecb.c"
409 #ifndef BF_ASM
410 #include "bf/bf_enc.c"
411 #endif
412 #include "bf/bf_ofb64.c"
413 #include "bf/bf_skey.c"
414 #endif
415 #endif
416
417 #ifdef CRYPTO_CAST_SUBSET
418 #ifndef NO_CAST
419 #include "cast/c_cfb64.c"
420 #include "cast/c_ecb.c"
421 #ifndef CAST_ASM
422 #include "cast/c_enc.c"
423 #endif
424 #include "cast/c_ofb64.c"
425 #include "cast/c_skey.c"
426 #endif
427 #endif
428
429 #ifdef CRYPTO_LHASH_SUBSET
430 #include "lhash/lh_stats.c"
431 #include "lhash/lhash.c"
432 #endif
433
434 #ifdef CRYPTO_MD_SUBSET
435 #ifndef NO_MD2
436 #include "md2/md2_dgst.c"
437 #include "md2/md2_one.c"
438 #include "evp/m_md2.c"
439 #endif
440 #ifndef NO_MD5
441 #include "md5/md5_dgst.c"
442 #include "md5/md5_one.c"
443 #include "evp/m_md5.c"
444 #endif
445 #endif
446
447 #ifdef CRYPTO_MDC2_SUBSET
448 #ifndef NO_MDC2
449 #include "mdc2/mdc2dgst.c"
450 #include "mdc2/mdc2_one.c"
451 #include "evp/m_mdc2.c"
452 #endif
453 #endif
454
455 #ifdef CRYPTO_OBJECTS_SUBSET
456 #include "objects/obj_dat.c"
457 #include "objects/obj_err.c"
458 #include "objects/obj_lib.c"
459 #endif
460
461 #ifdef CRYPTO_PEM_SUBSET
462 #include "pem/pem_err.c"
463 #include "pem/pem_info.c"
464 #include "pem/pem_lib.c"
465 #include "pem/pem_all.c"
466 #ifndef NO_RSA
467 #include "pem/pem_seal.c"
468 #include "pem/pem_sign.c"
469 #endif
470 #endif
471
472 #ifdef CRYPTO_RAND_SUBSET
473 #include "rand/md_rand.c"
474 #include "rand/randfile.c"
475 #endif
476
477 #ifdef CRYPTO_RC_SUBSET
478 #ifndef NO_RC2
479 #include "rc2/rc2_cbc.c"
480 #include "rc2/rc2_ecb.c"
481 #include "rc2/rc2_skey.c"
482 #include "rc2/rc2cfb64.c"
483 #include "rc2/rc2ofb64.c"
484 #endif
485 #ifndef NO_RC4
486 #include "rc4/rc4_skey.c"
487 #ifndef RC4_ASM
488 #include "rc4/rc4_enc.c"
489 #endif
490 #endif
491 #endif
492
493 #ifdef CRYPTO_HMAC_SUBSET
494 #include "hmac/hmac.c"
495 #endif
496
497 #ifdef CRYPTO_RSA_SUBSET
498 #ifndef NO_RSA
499 #include "rsa/rsa_eay.c"
500 #include "rsa/rsa_err.c"
501 #include "rsa/rsa_gen.c"
502 #include "rsa/rsa_lib.c"
503 #include "rsa/rsa_sign.c"
504 #include "rsa/rsa_saos.c"
505 #endif
506 #endif
507
508 #ifdef CRYPTO_SHA1_SUBSET
509 #ifndef NO_SHA1
510 #include "sha/sha1_one.c"
511 #include "sha/sha1dgst.c"
512 #include "evp/m_dss1.c"
513 #include "evp/m_sha1.c"
514 #endif
515 #endif
516
517 #ifdef CRYPTO_SHA_SUBSET
518 #ifndef NO_SHA
519 #include "evp/m_dss.c"
520 #include "sha/sha_dgst.c"
521 #include "sha/sha_one.c"
522 #include "evp/m_sha.c"
523 #endif
524 #endif
525
526 #ifdef CRYPTO_STACK_SUBSET
527 #include "stack/stack.c"
528 #endif
529
530 #ifdef CRYPTO_TXT_DB_SUBSET
531 #include "txt_db/txt_db.c"
532 #endif
533
534 #ifdef CRYPTO_X509_SUBSET
535 #include "x509/x509_cmp.c"
536 #include "x509/x509_d2.c"
537 #include "x509/x509_def.c"
538 #include "x509/x509_err.c"
539 #include "x509/x509_ext.c"
540 #include "x509/x509_lu.c"
541 #include "x509/x509_obj.c"
542 #include "x509/x509_r2x.c"
543 #include "x509/x509_req.c"
544 #include "x509/x509_set.c"
545 #include "x509/x509_v3.c"
546 #include "x509/x509_vfy.c"
547 #include "x509/x509name.c"
548 #include "x509/x509pack.c"
549 #include "x509/x509rset.c"
550 #include "x509/x509type.c"
551 #include "x509/x_all.c"
552 #include "x509/x509_txt.c"
553 #include "x509/by_dir.c"
554 #include "x509/by_file.c"
555 #include "x509/v3_net.c"
556 #include "x509/v3_x509.c"
557 #endif
558
559
560 #ifdef CRYPTO_PKCS7_SUBSET /* I have an explicit removal of 7 lines */
561 #include "pkcs7/pk7_lib.c"
562 #include "pkcs7/pkcs7err.c"
563 #include "pkcs7/pk7_doit.c"
564 #endif /* CRYPTO_PKCS7_SUBSET */
565