diff options
author | ryker <> | 1998-10-05 20:13:15 +0000 |
---|---|---|
committer | ryker <> | 1998-10-05 20:13:15 +0000 |
commit | 9e77c62555877f9a64805c49d0dcd7dbfbb40f4e (patch) | |
tree | 2a6396b738ecede1e1dd3ad84c90e47e21d0bcbd /src/lib/libcrypto | |
parent | fe5d0717e2760d02faf23bf5a714f17b33ae4abb (diff) | |
parent | 536c76cbb863bab152f19842ab88772c01e922c7 (diff) | |
download | openbsd-9e77c62555877f9a64805c49d0dcd7dbfbb40f4e.tar.gz openbsd-9e77c62555877f9a64805c49d0dcd7dbfbb40f4e.tar.bz2 openbsd-9e77c62555877f9a64805c49d0dcd7dbfbb40f4e.zip |
This commit was generated by cvs2git to track changes on a CVS vendor
branch.
Diffstat (limited to 'src/lib/libcrypto')
158 files changed, 26957 insertions, 0 deletions
diff --git a/src/lib/libcrypto/Attic/Makefile b/src/lib/libcrypto/Attic/Makefile new file mode 100644 index 0000000000..eb49323ad5 --- /dev/null +++ b/src/lib/libcrypto/Attic/Makefile | |||
@@ -0,0 +1,133 @@ | |||
1 | LIB= crypto | ||
2 | CFLAGS+= -DNO_IDEA -DTERMIOS -DL_ENDIAN -DANSI_SOURCE | ||
3 | CFLAGS+= -I${.CURDIR}/../include | ||
4 | SRCS+= cryptlib.c mem.c cversion.c ex_data.c cpt_err.c | ||
5 | CFLAGS+= -I${.CURDIR}/md2 | ||
6 | SRCS+= md2_dgst.c md2_one.c | ||
7 | CFLAGS+= -I${.CURDIR}/md5 | ||
8 | SRCS+= md5_dgst.c md5_one.c | ||
9 | CFLAGS+= -I${.CURDIR}/sha | ||
10 | SRCS+= sha_dgst.c sha1dgst.c sha_one.c sha1_one.c | ||
11 | CFLAGS+= -I${.CURDIR}/mdc2 | ||
12 | SRCS+= mdc2dgst.c mdc2_one.c | ||
13 | CFLAGS+= -I${.CURDIR}/hmac | ||
14 | SRCS+= hmac.c | ||
15 | CFLAGS+= -I${.CURDIR}/ripemd | ||
16 | SRCS+= rmd_dgst.c rmd_one.c | ||
17 | CFLAGS+= -I${.CURDIR}/des | ||
18 | SRCS+= set_key.c ecb_enc.c cbc_enc.c ecb3_enc.c | ||
19 | SRCS+= cfb64enc.c cfb64ede.c cfb_enc.c ofb64ede.c | ||
20 | SRCS+= enc_read.c enc_writ.c ofb64enc.c ofb_enc.c | ||
21 | SRCS+= str2key.c pcbc_enc.c qud_cksm.c rand_key.c | ||
22 | SRCS+= read2pwd.c fcrypt.c xcbc_enc.c read_pwd.c | ||
23 | SRCS+= rpc_enc.c cbc_cksm.c supp.c | ||
24 | CFLAGS+= -I${.CURDIR}/rc2 | ||
25 | SRCS+= rc2_ecb.c rc2_skey.c rc2_cbc.c rc2cfb64.c | ||
26 | SRCS+= rc2ofb64.c | ||
27 | CFLAGS+= -I${.CURDIR}/rc4 | ||
28 | SRCS+= rc4_skey.c | ||
29 | CFLAGS+= -I${.CURDIR}/rc5 | ||
30 | SRCS+= rc5_skey.c rc5_ecb.c rc5cfb64.c rc5cfb64.c | ||
31 | SRCS+= rc5ofb64.c | ||
32 | CFLAGS+= -I${.CURDIR}/idea | ||
33 | SRCS+= i_cbc.c i_cfb64.c i_ofb64.c i_ecb.c | ||
34 | SRCS+= i_skey.c | ||
35 | CFLAGS+= -I${.CURDIR}/bf | ||
36 | SRCS+= bf_skey.c bf_ecb.c bf_cfb64.c bf_ofb64.c | ||
37 | CFLAGS+= -I${.CURDIR}/cast | ||
38 | SRCS+= c_skey.c c_ecb.c c_cfb64.c c_ofb64.c | ||
39 | CFLAGS+= -I${.CURDIR}/bn | ||
40 | SRCS+= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mod.c | ||
41 | SRCS+= bn_mul.c bn_print.c bn_rand.c bn_shift.c bn_sub.c | ||
42 | SRCS+= bn_word.c bn_blind.c bn_gcd.c bn_prime.c bn_err.c | ||
43 | SRCS+= bn_sqr.c bn_recp.c bn_mont.c bn_mpi.c | ||
44 | CFLAGS+= -I${.CURDIR}/rsa | ||
45 | SRCS+= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c | ||
46 | SRCS+= rsa_saos.c rsa_err.c rsa_pk1.c rsa_ssl.c | ||
47 | SRCS+= rsa_none.c | ||
48 | CFLAGS+= -I${.CURDIR}/dsa | ||
49 | SRCS+= dsa_gen.c dsa_key.c dsa_lib.c dsa_vrf.c | ||
50 | SRCS+= dsa_sign.c dsa_err.c | ||
51 | CFLAGS+= -I${.CURDIR}/dh | ||
52 | SRCS+= dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c | ||
53 | CFLAGS+= -I${.CURDIR}/buffer | ||
54 | SRCS+= buffer.c buf_err.c | ||
55 | CFLAGS+= -I${.CURDIR}/bio | ||
56 | SRCS+= bio_lib.c bio_cb.c bio_err.c bss_mem.c | ||
57 | SRCS+= bss_null.c bss_fd.c bss_file.c bss_sock.c | ||
58 | SRCS+= bss_conn.c bf_null.c bf_buff.c | ||
59 | SRCS+= b_print.c b_dump.c b_sock.c bss_acpt.c | ||
60 | SRCS+= bf_nbio.c | ||
61 | CFLAGS+= -I${.CURDIR}/stack | ||
62 | SRCS+= stack.c | ||
63 | CFLAGS+= -I${.CURDIR}/lhash | ||
64 | SRCS+= lhash.c lh_stats.c | ||
65 | CFLAGS+= -I${.CURDIR}/rand | ||
66 | SRCS+= md_rand.c randfile.c | ||
67 | CFLAGS+= -I${.CURDIR}/err | ||
68 | SRCS+= err.c err_all.c err_prn.c | ||
69 | CFLAGS+= -I${.CURDIR}/objects | ||
70 | SRCS+= obj_dat.c obj_lib.c obj_err.c | ||
71 | CFLAGS+= -I${.CURDIR}/evp | ||
72 | SRCS+= encode.c digest.c evp_enc.c evp_key.c | ||
73 | SRCS+= e_ecb_d.c e_cbc_d.c e_cfb_d.c e_ofb_d.c | ||
74 | SRCS+= e_ecb_i.c e_cbc_i.c e_cfb_i.c e_ofb_i.c | ||
75 | SRCS+= e_ecb_3d.c e_cbc_3d.c e_rc4.c names.c | ||
76 | SRCS+= e_cfb_3d.c e_ofb_3d.c e_xcbc_d.c e_ecb_r2.c | ||
77 | SRCS+= e_cbc_r2.c e_cfb_r2.c e_ofb_r2.c e_ecb_bf.c | ||
78 | SRCS+= e_cbc_bf.c e_cfb_bf.c e_ofb_bf.c e_ecb_c.c | ||
79 | SRCS+= e_cbc_c.c e_cfb_c.c e_ofb_c.c e_ecb_r5.c | ||
80 | SRCS+= e_cbc_r5.c e_cfb_r5.c e_ofb_r5.c m_null.c | ||
81 | SRCS+= m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c | ||
82 | SRCS+= m_dss1.c m_mdc2.c m_ripemd.c p_open.c | ||
83 | SRCS+= p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c | ||
84 | SRCS+= p_dec.c bio_md.c bio_b64.c bio_enc.c | ||
85 | SRCS+= evp_err.c e_null.c c_all.c evp_lib.c | ||
86 | CFLAGS+= -I${.CURDIR}/pem | ||
87 | SRCS+= pem_sign.c pem_seal.c pem_info.c pem_lib.c | ||
88 | SRCS+= pem_all.c pem_err.c | ||
89 | CFLAGS+= -I${.CURDIR}/asn1 | ||
90 | SRCS+= a_object.c a_bitstr.c a_utctm.c a_int.c | ||
91 | SRCS+= a_octet.c a_print.c a_type.c a_set.c | ||
92 | SRCS+= a_dup.c a_d2i_fp.c a_i2d_fp.c a_sign.c | ||
93 | SRCS+= a_digest.c a_verify.c x_algor.c x_val.c | ||
94 | SRCS+= x_pubkey.c x_sig.c x_req.c x_attrib.c | ||
95 | SRCS+= x_name.c x_cinf.c x_x509.c x_crl.c | ||
96 | SRCS+= x_info.c x_spki.c d2i_r_pr.c i2d_r_pr.c | ||
97 | SRCS+= d2i_r_pu.c i2d_r_pu.c d2i_s_pr.c i2d_s_pr.c | ||
98 | SRCS+= d2i_s_pu.c i2d_s_pu.c d2i_pu.c d2i_pr.c | ||
99 | SRCS+= i2d_pu.c i2d_pr.c t_req.c t_x509.c | ||
100 | SRCS+= t_pkey.c p7_i_s.c p7_signi.c p7_signd.c | ||
101 | SRCS+= p7_recip.c p7_enc_c.c p7_evp.c p7_dgst.c | ||
102 | SRCS+= p7_s_e.c p7_enc.c p7_lib.c f_int.c | ||
103 | SRCS+= f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c | ||
104 | SRCS+= d2i_dsap.c n_pkey.c a_hdr.c x_pkey.c | ||
105 | SRCS+= a_bool.c x_exten.c asn1_par.c asn1_lib.c | ||
106 | SRCS+= asn1_err.c a_meth.c a_bytes.c evp_asn1.c | ||
107 | CFLAGS+= -I${.CURDIR}/x509 | ||
108 | SRCS+= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c | ||
109 | SRCS+= x509_obj.c x509_req.c x509_vfy.c x509_set.c | ||
110 | SRCS+= x509rset.c x509_err.c x509name.c x509_v3.c | ||
111 | SRCS+= x509_ext.c x509pack.c x509type.c x509_lu.c | ||
112 | SRCS+= x_all.c x509_txt.c by_file.c by_dir.c | ||
113 | SRCS+= v3_net.c v3_x509.c | ||
114 | CFLAGS+= -I${.CURDIR}/conf | ||
115 | SRCS+= conf.c conf_err.c | ||
116 | CFLAGS+= -I${.CURDIR}/txt_db | ||
117 | SRCS+= txt_db.c | ||
118 | CFLAGS+= -I${.CURDIR}/pkcs7 | ||
119 | SRCS+= pk7_lib.c pkcs7err.c pk7_doit.c | ||
120 | |||
121 | .PATH: ${.CURDIR}/md2 ${.CURDIR}/md5 ${.CURDIR}/sha ${.CURDIR}/mdc2 \ | ||
122 | ${.CURDIR}/hmac ${.CURDIR}/ripemd ${.CURDIR}/des ${.CURDIR}/rc2 \ | ||
123 | ${.CURDIR}/rc4 ${.CURDIR}/rc5 ${.CURDIR}/idea ${.CURDIR}/bf \ | ||
124 | ${.CURDIR}/cast ${.CURDIR}/bn ${.CURDIR}/rsa ${.CURDIR}/dsa \ | ||
125 | ${.CURDIR}/dh ${.CURDIR}/buffer ${.CURDIR}/bio ${.CURDIR}/stack \ | ||
126 | ${.CURDIR}/lhash ${.CURDIR}/rand ${.CURDIR}/err ${.CURDIR}/objects \ | ||
127 | ${.CURDIR}/evp ${.CURDIR}/pem ${.CURDIR}/asn1 ${.CURDIR}/asn1 \ | ||
128 | ${.CURDIR}/x509 ${.CURDIR}/conf txt_db/txt_db.c ${.CURDIR}/pkcs7 \ | ||
129 | ${.CURDIR}/txt_db | ||
130 | |||
131 | .include <bsd.lib.mk> | ||
132 | |||
133 | |||
diff --git a/src/lib/libcrypto/asn1/a_hdr.c b/src/lib/libcrypto/asn1/a_hdr.c new file mode 100644 index 0000000000..4fb7a5fa75 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_hdr.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /* crypto/asn1/a_hdr.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 "asn1_mac.h" | ||
62 | #include "asn1.h" | ||
63 | |||
64 | /* | ||
65 | * ASN1err(ASN1_F_D2I_ASN1_HEADER,ASN1_R_LENGTH_MISMATCH); | ||
66 | * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT); | ||
67 | * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT); | ||
68 | * ASN1err(ASN1_F_ASN1_HEADER_NEW,ASN1_R_BAD_GET_OBJECT); | ||
69 | */ | ||
70 | |||
71 | int i2d_ASN1_HEADER(a,pp) | ||
72 | ASN1_HEADER *a; | ||
73 | unsigned char **pp; | ||
74 | { | ||
75 | M_ASN1_I2D_vars(a); | ||
76 | |||
77 | M_ASN1_I2D_len(a->header, i2d_ASN1_OCTET_STRING); | ||
78 | M_ASN1_I2D_len(a->data, a->meth->i2d); | ||
79 | |||
80 | M_ASN1_I2D_seq_total(); | ||
81 | |||
82 | M_ASN1_I2D_put(a->header, i2d_ASN1_OCTET_STRING); | ||
83 | M_ASN1_I2D_put(a->data, a->meth->i2d); | ||
84 | |||
85 | M_ASN1_I2D_finish(); | ||
86 | } | ||
87 | |||
88 | ASN1_HEADER *d2i_ASN1_HEADER(a,pp,length) | ||
89 | ASN1_HEADER **a; | ||
90 | unsigned char **pp; | ||
91 | long length; | ||
92 | { | ||
93 | M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new); | ||
94 | |||
95 | M_ASN1_D2I_Init(); | ||
96 | M_ASN1_D2I_start_sequence(); | ||
97 | M_ASN1_D2I_get(ret->header,d2i_ASN1_OCTET_STRING); | ||
98 | if (ret->meth != NULL) | ||
99 | { | ||
100 | M_ASN1_D2I_get(ret->data,ret->meth->d2i); | ||
101 | } | ||
102 | else | ||
103 | { | ||
104 | if (a != NULL) (*a)=ret; | ||
105 | return(ret); | ||
106 | } | ||
107 | M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER); | ||
108 | } | ||
109 | |||
110 | ASN1_HEADER *ASN1_HEADER_new() | ||
111 | { | ||
112 | ASN1_HEADER *ret=NULL; | ||
113 | |||
114 | M_ASN1_New_Malloc(ret,ASN1_HEADER); | ||
115 | M_ASN1_New(ret->header,ASN1_OCTET_STRING_new); | ||
116 | ret->meth=NULL; | ||
117 | ret->data=NULL; | ||
118 | return(ret); | ||
119 | M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW); | ||
120 | } | ||
121 | |||
122 | void ASN1_HEADER_free(a) | ||
123 | ASN1_HEADER *a; | ||
124 | { | ||
125 | if (a == NULL) return; | ||
126 | ASN1_OCTET_STRING_free(a->header); | ||
127 | if (a->meth != NULL) | ||
128 | a->meth->destroy(a->data); | ||
129 | Free((char *)a); | ||
130 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_meth.c b/src/lib/libcrypto/asn1/a_meth.c new file mode 100644 index 0000000000..513625c305 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_meth.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* crypto/asn1/a_meth.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 "buffer.h" | ||
62 | #include "x509.h" | ||
63 | |||
64 | static ASN1_METHOD ia5string_meth={ | ||
65 | (int (*)()) i2d_ASN1_IA5STRING, | ||
66 | (char *(*)()) d2i_ASN1_IA5STRING, | ||
67 | (char *(*)()) ASN1_STRING_new, | ||
68 | (void (*)()) ASN1_STRING_free}; | ||
69 | |||
70 | static ASN1_METHOD bit_string_meth={ | ||
71 | (int (*)()) i2d_ASN1_BIT_STRING, | ||
72 | (char *(*)()) d2i_ASN1_BIT_STRING, | ||
73 | (char *(*)()) ASN1_STRING_new, | ||
74 | (void (*)()) ASN1_STRING_free}; | ||
75 | |||
76 | ASN1_METHOD *ASN1_IA5STRING_asn1_meth() | ||
77 | { | ||
78 | return(&ia5string_meth); | ||
79 | } | ||
80 | |||
81 | ASN1_METHOD *ASN1_BIT_STRING_asn1_meth() | ||
82 | { | ||
83 | return(&bit_string_meth); | ||
84 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c new file mode 100644 index 0000000000..17a7abbb67 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_utctm.c | |||
@@ -0,0 +1,212 @@ | |||
1 | /* crypto/asn1/a_utctm.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 <time.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include "asn1.h" | ||
63 | |||
64 | /* ASN1err(ASN1_F_ASN1_UTCTIME_NEW,ASN1_R_UTCTIME_TOO_LONG); | ||
65 | * ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_EXPECTING_A_UTCTIME); | ||
66 | */ | ||
67 | |||
68 | int i2d_ASN1_UTCTIME(a,pp) | ||
69 | ASN1_UTCTIME *a; | ||
70 | unsigned char **pp; | ||
71 | { | ||
72 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | ||
73 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); | ||
74 | } | ||
75 | |||
76 | |||
77 | ASN1_UTCTIME *d2i_ASN1_UTCTIME(a, pp, length) | ||
78 | ASN1_UTCTIME **a; | ||
79 | unsigned char **pp; | ||
80 | long length; | ||
81 | { | ||
82 | ASN1_UTCTIME *ret=NULL; | ||
83 | |||
84 | ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, | ||
85 | V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); | ||
86 | if (ret == NULL) | ||
87 | { | ||
88 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_ERROR_STACK); | ||
89 | return(NULL); | ||
90 | } | ||
91 | if (!ASN1_UTCTIME_check(ret)) | ||
92 | { | ||
93 | ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); | ||
94 | goto err; | ||
95 | } | ||
96 | |||
97 | return(ret); | ||
98 | err: | ||
99 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
100 | ASN1_UTCTIME_free(ret); | ||
101 | return(NULL); | ||
102 | } | ||
103 | |||
104 | int ASN1_UTCTIME_check(d) | ||
105 | ASN1_UTCTIME *d; | ||
106 | { | ||
107 | static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; | ||
108 | static int max[8]={99,12,31,23,59,59,12,59}; | ||
109 | char *a; | ||
110 | int n,i,l,o; | ||
111 | |||
112 | if (d->type != V_ASN1_UTCTIME) return(0); | ||
113 | l=d->length; | ||
114 | a=(char *)d->data; | ||
115 | o=0; | ||
116 | |||
117 | if (l < 11) goto err; | ||
118 | for (i=0; i<6; i++) | ||
119 | { | ||
120 | if ((i == 5) && ((a[o] == 'Z') || | ||
121 | (a[o] == '+') || (a[o] == '-'))) | ||
122 | { i++; break; } | ||
123 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
124 | n= a[o]-'0'; | ||
125 | if (++o > l) goto err; | ||
126 | |||
127 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
128 | n=(n*10)+ a[o]-'0'; | ||
129 | if (++o > l) goto err; | ||
130 | |||
131 | if ((n < min[i]) || (n > max[i])) goto err; | ||
132 | } | ||
133 | if (a[o] == 'Z') | ||
134 | o++; | ||
135 | else if ((a[o] == '+') || (a[o] == '-')) | ||
136 | { | ||
137 | o++; | ||
138 | if (o+4 > l) goto err; | ||
139 | for (i=6; i<8; i++) | ||
140 | { | ||
141 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
142 | n= a[o]-'0'; | ||
143 | o++; | ||
144 | if ((a[o] < '0') || (a[o] > '9')) goto err; | ||
145 | n=(n*10)+ a[o]-'0'; | ||
146 | if ((n < min[i]) || (n > max[i])) goto err; | ||
147 | o++; | ||
148 | } | ||
149 | } | ||
150 | return(o == l); | ||
151 | err: | ||
152 | return(0); | ||
153 | } | ||
154 | |||
155 | int ASN1_UTCTIME_set_string(s,str) | ||
156 | ASN1_UTCTIME *s; | ||
157 | char *str; | ||
158 | { | ||
159 | ASN1_UTCTIME t; | ||
160 | |||
161 | t.type=V_ASN1_UTCTIME; | ||
162 | t.length=strlen(str); | ||
163 | t.data=(unsigned char *)str; | ||
164 | if (ASN1_UTCTIME_check(&t)) | ||
165 | { | ||
166 | if (s != NULL) | ||
167 | { | ||
168 | ASN1_STRING_set((ASN1_STRING *)s, | ||
169 | (unsigned char *)str,t.length); | ||
170 | } | ||
171 | return(1); | ||
172 | } | ||
173 | else | ||
174 | return(0); | ||
175 | } | ||
176 | |||
177 | ASN1_UTCTIME *ASN1_UTCTIME_set(s, t) | ||
178 | ASN1_UTCTIME *s; | ||
179 | time_t t; | ||
180 | { | ||
181 | char *p; | ||
182 | struct tm *ts; | ||
183 | #if defined(THREADS) | ||
184 | struct tm data; | ||
185 | #endif | ||
186 | |||
187 | if (s == NULL) | ||
188 | s=ASN1_UTCTIME_new(); | ||
189 | if (s == NULL) | ||
190 | return(NULL); | ||
191 | |||
192 | #if defined(THREADS) | ||
193 | ts=(struct tm *)gmtime_r(&t,&data); | ||
194 | #else | ||
195 | ts=(struct tm *)gmtime(&t); | ||
196 | #endif | ||
197 | p=(char *)s->data; | ||
198 | if ((p == NULL) || (s->length < 14)) | ||
199 | { | ||
200 | p=Malloc(20); | ||
201 | if (p == NULL) return(NULL); | ||
202 | if (s->data != NULL) | ||
203 | Free(s->data); | ||
204 | s->data=(unsigned char *)p; | ||
205 | } | ||
206 | |||
207 | sprintf(p,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, | ||
208 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); | ||
209 | s->length=strlen(p); | ||
210 | s->type=V_ASN1_UTCTIME; | ||
211 | return(s); | ||
212 | } | ||
diff --git a/src/lib/libcrypto/bf/asm/bf-686.pl b/src/lib/libcrypto/bf/asm/bf-686.pl new file mode 100644 index 0000000000..bed303d786 --- /dev/null +++ b/src/lib/libcrypto/bf/asm/bf-686.pl | |||
@@ -0,0 +1,128 @@ | |||
1 | #!/usr/bin/perl | ||
2 | #!/usr/local/bin/perl | ||
3 | |||
4 | push(@INC,"perlasm","../../perlasm"); | ||
5 | require "x86asm.pl"; | ||
6 | require "cbc.pl"; | ||
7 | |||
8 | &asm_init($ARGV[0],"bf-686.pl"); | ||
9 | |||
10 | $BF_ROUNDS=16; | ||
11 | $BF_OFF=($BF_ROUNDS+2)*4; | ||
12 | $L="ecx"; | ||
13 | $R="edx"; | ||
14 | $P="edi"; | ||
15 | $tot="esi"; | ||
16 | $tmp1="eax"; | ||
17 | $tmp2="ebx"; | ||
18 | $tmp3="ebp"; | ||
19 | |||
20 | &des_encrypt("BF_encrypt",1); | ||
21 | &des_encrypt("BF_decrypt",0); | ||
22 | &cbc("BF_cbc_encrypt","BF_encrypt","BF_decrypt",1,4,5,3,-1,-1); | ||
23 | |||
24 | &asm_finish(); | ||
25 | |||
26 | &file_end(); | ||
27 | |||
28 | sub des_encrypt | ||
29 | { | ||
30 | local($name,$enc)=@_; | ||
31 | |||
32 | &function_begin($name,""); | ||
33 | |||
34 | &comment(""); | ||
35 | &comment("Load the 2 words"); | ||
36 | &mov("eax",&wparam(0)); | ||
37 | &mov($L,&DWP(0,"eax","",0)); | ||
38 | &mov($R,&DWP(4,"eax","",0)); | ||
39 | |||
40 | &comment(""); | ||
41 | &comment("P pointer, s and enc flag"); | ||
42 | &mov($P,&wparam(1)); | ||
43 | |||
44 | &xor( $tmp1, $tmp1); | ||
45 | &xor( $tmp2, $tmp2); | ||
46 | |||
47 | # encrypting part | ||
48 | |||
49 | if ($enc) | ||
50 | { | ||
51 | &xor($L,&DWP(0,$P,"",0)); | ||
52 | for ($i=0; $i<$BF_ROUNDS; $i+=2) | ||
53 | { | ||
54 | &comment(""); | ||
55 | &comment("Round $i"); | ||
56 | &BF_ENCRYPT($i+1,$R,$L,$P,$tot,$tmp1,$tmp2,$tmp3); | ||
57 | |||
58 | &comment(""); | ||
59 | &comment("Round ".sprintf("%d",$i+1)); | ||
60 | &BF_ENCRYPT($i+2,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3); | ||
61 | } | ||
62 | &xor($R,&DWP(($BF_ROUNDS+1)*4,$P,"",0)); | ||
63 | |||
64 | &mov("eax",&wparam(0)); | ||
65 | &mov(&DWP(0,"eax","",0),$R); | ||
66 | &mov(&DWP(4,"eax","",0),$L); | ||
67 | &function_end_A($name); | ||
68 | } | ||
69 | else | ||
70 | { | ||
71 | &xor($L,&DWP(($BF_ROUNDS+1)*4,$P,"",0)); | ||
72 | for ($i=$BF_ROUNDS; $i>0; $i-=2) | ||
73 | { | ||
74 | &comment(""); | ||
75 | &comment("Round $i"); | ||
76 | &BF_ENCRYPT($i,$R,$L,$P,$tot,$tmp1,$tmp2,$tmp3); | ||
77 | &comment(""); | ||
78 | &comment("Round ".sprintf("%d",$i-1)); | ||
79 | &BF_ENCRYPT($i-1,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3); | ||
80 | } | ||
81 | &xor($R,&DWP(0,$P,"",0)); | ||
82 | |||
83 | &mov("eax",&wparam(0)); | ||
84 | &mov(&DWP(0,"eax","",0),$R); | ||
85 | &mov(&DWP(4,"eax","",0),$L); | ||
86 | &function_end_A($name); | ||
87 | } | ||
88 | |||
89 | &function_end_B($name); | ||
90 | } | ||
91 | |||
92 | sub BF_ENCRYPT | ||
93 | { | ||
94 | local($i,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3)=@_; | ||
95 | |||
96 | &rotr( $R, 16); | ||
97 | &mov( $tot, &DWP(&n2a($i*4),$P,"",0)); | ||
98 | |||
99 | &movb( &LB($tmp1), &HB($R)); | ||
100 | &movb( &LB($tmp2), &LB($R)); | ||
101 | |||
102 | &rotr( $R, 16); | ||
103 | &xor( $L, $tot); | ||
104 | |||
105 | &mov( $tot, &DWP(&n2a($BF_OFF+0x0000),$P,$tmp1,4)); | ||
106 | &mov( $tmp3, &DWP(&n2a($BF_OFF+0x0400),$P,$tmp2,4)); | ||
107 | |||
108 | &movb( &LB($tmp1), &HB($R)); | ||
109 | &movb( &LB($tmp2), &LB($R)); | ||
110 | |||
111 | &add( $tot, $tmp3); | ||
112 | &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0800),$P,$tmp1,4)); # delay | ||
113 | |||
114 | &xor( $tot, $tmp1); | ||
115 | &mov( $tmp3, &DWP(&n2a($BF_OFF+0x0C00),$P,$tmp2,4)); | ||
116 | |||
117 | &add( $tot, $tmp3); | ||
118 | &xor( $tmp1, $tmp1); | ||
119 | |||
120 | &xor( $L, $tot); | ||
121 | # delay | ||
122 | } | ||
123 | |||
124 | sub n2a | ||
125 | { | ||
126 | sprintf("%d",$_[0]); | ||
127 | } | ||
128 | |||
diff --git a/src/lib/libcrypto/bf/asm/readme b/src/lib/libcrypto/bf/asm/readme new file mode 100644 index 0000000000..2385fa3812 --- /dev/null +++ b/src/lib/libcrypto/bf/asm/readme | |||
@@ -0,0 +1,10 @@ | |||
1 | There are blowfish assembler generation scripts. | ||
2 | bf-586.pl version is for the pentium and | ||
3 | bf-686.pl is my original version, which is faster on the pentium pro. | ||
4 | |||
5 | When using a bf-586.pl, the pentium pro/II is %8 slower than using | ||
6 | bf-686.pl. When using a bf-686.pl, the pentium is %16 slower | ||
7 | than bf-586.pl | ||
8 | |||
9 | So the default is bf-586.pl | ||
10 | |||
diff --git a/src/lib/libcrypto/bf/bf_opts.c b/src/lib/libcrypto/bf/bf_opts.c new file mode 100644 index 0000000000..5cfa60c537 --- /dev/null +++ b/src/lib/libcrypto/bf/bf_opts.c | |||
@@ -0,0 +1,347 @@ | |||
1 | /* crypto/bf/bf_opts.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 | /* define PART1, PART2, PART3 or PART4 to build only with a few of the options. | ||
60 | * This is for machines with 64k code segment size restrictions. */ | ||
61 | |||
62 | #ifndef MSDOS | ||
63 | #define TIMES | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | #ifndef MSDOS | ||
68 | #include <unistd.h> | ||
69 | #else | ||
70 | #include <io.h> | ||
71 | extern void exit(); | ||
72 | #endif | ||
73 | #include <signal.h> | ||
74 | #ifndef VMS | ||
75 | #ifndef _IRIX | ||
76 | #include <time.h> | ||
77 | #endif | ||
78 | #ifdef TIMES | ||
79 | #include <sys/types.h> | ||
80 | #include <sys/times.h> | ||
81 | #endif | ||
82 | #else /* VMS */ | ||
83 | #include <types.h> | ||
84 | struct tms { | ||
85 | time_t tms_utime; | ||
86 | time_t tms_stime; | ||
87 | time_t tms_uchild; /* I dunno... */ | ||
88 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
89 | } | ||
90 | #endif | ||
91 | #ifndef TIMES | ||
92 | #include <sys/timeb.h> | ||
93 | #endif | ||
94 | |||
95 | #ifdef sun | ||
96 | #include <limits.h> | ||
97 | #include <sys/param.h> | ||
98 | #endif | ||
99 | |||
100 | #include "blowfish.h" | ||
101 | |||
102 | #define BF_DEFAULT_OPTIONS | ||
103 | |||
104 | #undef BF_ENC | ||
105 | #define BF_encrypt BF_encrypt_normal | ||
106 | #undef HEADER_BF_LOCL_H | ||
107 | #include "bf_enc.c" | ||
108 | |||
109 | #define BF_PTR | ||
110 | #undef BF_PTR2 | ||
111 | #undef BF_ENC | ||
112 | #undef BF_encrypt | ||
113 | #define BF_encrypt BF_encrypt_ptr | ||
114 | #undef HEADER_BF_LOCL_H | ||
115 | #include "bf_enc.c" | ||
116 | |||
117 | #undef BF_PTR | ||
118 | #define BF_PTR2 | ||
119 | #undef BF_ENC | ||
120 | #undef BF_encrypt | ||
121 | #define BF_encrypt BF_encrypt_ptr2 | ||
122 | #undef HEADER_BF_LOCL_H | ||
123 | #include "bf_enc.c" | ||
124 | |||
125 | /* The following if from times(3) man page. It may need to be changed */ | ||
126 | #ifndef HZ | ||
127 | # ifndef CLK_TCK | ||
128 | # ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ | ||
129 | # ifndef VMS | ||
130 | # define HZ 100.0 | ||
131 | # else /* VMS */ | ||
132 | # define HZ 100.0 | ||
133 | # endif | ||
134 | # else /* _BSD_CLK_TCK_ */ | ||
135 | # define HZ ((double)_BSD_CLK_TCK_) | ||
136 | # endif | ||
137 | # else /* CLK_TCK */ | ||
138 | # define HZ ((double)CLK_TCK) | ||
139 | # endif | ||
140 | #endif | ||
141 | |||
142 | #define BUFSIZE ((long)1024) | ||
143 | long run=0; | ||
144 | |||
145 | #ifndef NOPROTO | ||
146 | double Time_F(int s); | ||
147 | #else | ||
148 | double Time_F(); | ||
149 | #endif | ||
150 | |||
151 | #ifdef SIGALRM | ||
152 | #if defined(__STDC__) || defined(sgi) | ||
153 | #define SIGRETTYPE void | ||
154 | #else | ||
155 | #define SIGRETTYPE int | ||
156 | #endif | ||
157 | |||
158 | #ifndef NOPROTO | ||
159 | SIGRETTYPE sig_done(int sig); | ||
160 | #else | ||
161 | SIGRETTYPE sig_done(); | ||
162 | #endif | ||
163 | |||
164 | SIGRETTYPE sig_done(sig) | ||
165 | int sig; | ||
166 | { | ||
167 | signal(SIGALRM,sig_done); | ||
168 | run=0; | ||
169 | #ifdef LINT | ||
170 | sig=sig; | ||
171 | #endif | ||
172 | } | ||
173 | #endif | ||
174 | |||
175 | #define START 0 | ||
176 | #define STOP 1 | ||
177 | |||
178 | double Time_F(s) | ||
179 | int s; | ||
180 | { | ||
181 | double ret; | ||
182 | #ifdef TIMES | ||
183 | static struct tms tstart,tend; | ||
184 | |||
185 | if (s == START) | ||
186 | { | ||
187 | times(&tstart); | ||
188 | return(0); | ||
189 | } | ||
190 | else | ||
191 | { | ||
192 | times(&tend); | ||
193 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
194 | return((ret == 0.0)?1e-6:ret); | ||
195 | } | ||
196 | #else /* !times() */ | ||
197 | static struct timeb tstart,tend; | ||
198 | long i; | ||
199 | |||
200 | if (s == START) | ||
201 | { | ||
202 | ftime(&tstart); | ||
203 | return(0); | ||
204 | } | ||
205 | else | ||
206 | { | ||
207 | ftime(&tend); | ||
208 | i=(long)tend.millitm-(long)tstart.millitm; | ||
209 | ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; | ||
210 | return((ret == 0.0)?1e-6:ret); | ||
211 | } | ||
212 | #endif | ||
213 | } | ||
214 | |||
215 | #ifdef SIGALRM | ||
216 | #define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10); | ||
217 | #else | ||
218 | #define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb); | ||
219 | #endif | ||
220 | |||
221 | #define time_it(func,name,index) \ | ||
222 | print_name(name); \ | ||
223 | Time_F(START); \ | ||
224 | for (count=0,run=1; COND(cb); count+=4) \ | ||
225 | { \ | ||
226 | unsigned long d[2]; \ | ||
227 | func(d,&sch); \ | ||
228 | func(d,&sch); \ | ||
229 | func(d,&sch); \ | ||
230 | func(d,&sch); \ | ||
231 | } \ | ||
232 | tm[index]=Time_F(STOP); \ | ||
233 | fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \ | ||
234 | tm[index]=((double)COUNT(cb))/tm[index]; | ||
235 | |||
236 | #define print_it(name,index) \ | ||
237 | fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \ | ||
238 | tm[index]*8,1.0e6/tm[index]); | ||
239 | |||
240 | int main(argc,argv) | ||
241 | int argc; | ||
242 | char **argv; | ||
243 | { | ||
244 | long count; | ||
245 | static unsigned char buf[BUFSIZE]; | ||
246 | static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | ||
247 | 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; | ||
248 | BF_KEY sch; | ||
249 | double d,tm[16],max=0; | ||
250 | int rank[16]; | ||
251 | char *str[16]; | ||
252 | int max_idx=0,i,num=0,j; | ||
253 | #ifndef SIGALARM | ||
254 | long ca,cb,cc,cd,ce; | ||
255 | #endif | ||
256 | |||
257 | for (i=0; i<12; i++) | ||
258 | { | ||
259 | tm[i]=0.0; | ||
260 | rank[i]=0; | ||
261 | } | ||
262 | |||
263 | #ifndef TIMES | ||
264 | fprintf(stderr,"To get the most acurate results, try to run this\n"); | ||
265 | fprintf(stderr,"program when this computer is idle.\n"); | ||
266 | #endif | ||
267 | |||
268 | BF_set_key(&sch,16,key); | ||
269 | |||
270 | #ifndef SIGALRM | ||
271 | fprintf(stderr,"First we calculate the approximate speed ...\n"); | ||
272 | count=10; | ||
273 | do { | ||
274 | long i; | ||
275 | unsigned long data[2]; | ||
276 | |||
277 | count*=2; | ||
278 | Time_F(START); | ||
279 | for (i=count; i; i--) | ||
280 | BF_encrypt(data,&sch); | ||
281 | d=Time_F(STOP); | ||
282 | } while (d < 3.0); | ||
283 | ca=count; | ||
284 | cb=count*3; | ||
285 | cc=count*3*8/BUFSIZE+1; | ||
286 | cd=count*8/BUFSIZE+1; | ||
287 | |||
288 | ce=count/20+1; | ||
289 | #define COND(d) (count != (d)) | ||
290 | #define COUNT(d) (d) | ||
291 | #else | ||
292 | #define COND(c) (run) | ||
293 | #define COUNT(d) (count) | ||
294 | signal(SIGALRM,sig_done); | ||
295 | alarm(10); | ||
296 | #endif | ||
297 | |||
298 | time_it(BF_encrypt_normal, "BF_encrypt_normal ", 0); | ||
299 | time_it(BF_encrypt_ptr, "BF_encrypt_ptr ", 1); | ||
300 | time_it(BF_encrypt_ptr2, "BF_encrypt_ptr2 ", 2); | ||
301 | num+=3; | ||
302 | |||
303 | str[0]="<nothing>"; | ||
304 | print_it("BF_encrypt_normal ",0); | ||
305 | max=tm[0]; | ||
306 | max_idx=0; | ||
307 | str[1]="ptr "; | ||
308 | print_it("BF_encrypt_ptr ",1); | ||
309 | if (max < tm[1]) { max=tm[1]; max_idx=1; } | ||
310 | str[2]="ptr2 "; | ||
311 | print_it("BF_encrypt_ptr2 ",2); | ||
312 | if (max < tm[2]) { max=tm[2]; max_idx=2; } | ||
313 | |||
314 | printf("options BF ecb/s\n"); | ||
315 | printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]); | ||
316 | d=tm[max_idx]; | ||
317 | tm[max_idx]= -2.0; | ||
318 | max= -1.0; | ||
319 | for (;;) | ||
320 | { | ||
321 | for (i=0; i<3; i++) | ||
322 | { | ||
323 | if (max < tm[i]) { max=tm[i]; j=i; } | ||
324 | } | ||
325 | if (max < 0.0) break; | ||
326 | printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0); | ||
327 | tm[j]= -2.0; | ||
328 | max= -1.0; | ||
329 | } | ||
330 | |||
331 | switch (max_idx) | ||
332 | { | ||
333 | case 0: | ||
334 | printf("-DBF_DEFAULT_OPTIONS\n"); | ||
335 | break; | ||
336 | case 1: | ||
337 | printf("-DBF_PTR\n"); | ||
338 | break; | ||
339 | case 2: | ||
340 | printf("-DBF_PTR2\n"); | ||
341 | break; | ||
342 | } | ||
343 | exit(0); | ||
344 | #if defined(LINT) || defined(MSDOS) | ||
345 | return(0); | ||
346 | #endif | ||
347 | } | ||
diff --git a/src/lib/libcrypto/bf/bfs.cpp b/src/lib/libcrypto/bf/bfs.cpp new file mode 100644 index 0000000000..272ed2f978 --- /dev/null +++ b/src/lib/libcrypto/bf/bfs.cpp | |||
@@ -0,0 +1,67 @@ | |||
1 | // | ||
2 | // gettsc.inl | ||
3 | // | ||
4 | // gives access to the Pentium's (secret) cycle counter | ||
5 | // | ||
6 | // This software was written by Leonard Janke (janke@unixg.ubc.ca) | ||
7 | // in 1996-7 and is entered, by him, into the public domain. | ||
8 | |||
9 | #if defined(__WATCOMC__) | ||
10 | void GetTSC(unsigned long&); | ||
11 | #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; | ||
12 | #elif defined(__GNUC__) | ||
13 | inline | ||
14 | void GetTSC(unsigned long& tsc) | ||
15 | { | ||
16 | asm volatile(".byte 15, 49\n\t" | ||
17 | : "=eax" (tsc) | ||
18 | : | ||
19 | : "%edx", "%eax"); | ||
20 | } | ||
21 | #elif defined(_MSC_VER) | ||
22 | inline | ||
23 | void GetTSC(unsigned long& tsc) | ||
24 | { | ||
25 | unsigned long a; | ||
26 | __asm _emit 0fh | ||
27 | __asm _emit 31h | ||
28 | __asm mov a, eax; | ||
29 | tsc=a; | ||
30 | } | ||
31 | #endif | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include <stdlib.h> | ||
35 | #include "blowfish.h" | ||
36 | |||
37 | void main(int argc,char *argv[]) | ||
38 | { | ||
39 | BF_KEY key; | ||
40 | unsigned long s1,s2,e1,e2; | ||
41 | unsigned long data[2]; | ||
42 | int i,j; | ||
43 | |||
44 | for (j=0; j<6; j++) | ||
45 | { | ||
46 | for (i=0; i<1000; i++) /**/ | ||
47 | { | ||
48 | BF_encrypt(&data[0],&key); | ||
49 | GetTSC(s1); | ||
50 | BF_encrypt(&data[0],&key); | ||
51 | BF_encrypt(&data[0],&key); | ||
52 | BF_encrypt(&data[0],&key); | ||
53 | GetTSC(e1); | ||
54 | GetTSC(s2); | ||
55 | BF_encrypt(&data[0],&key); | ||
56 | BF_encrypt(&data[0],&key); | ||
57 | BF_encrypt(&data[0],&key); | ||
58 | BF_encrypt(&data[0],&key); | ||
59 | GetTSC(e2); | ||
60 | BF_encrypt(&data[0],&key); | ||
61 | } | ||
62 | |||
63 | printf("blowfish %d %d (%d)\n", | ||
64 | e1-s1,e2-s2,((e2-s2)-(e1-s1))); | ||
65 | } | ||
66 | } | ||
67 | |||
diff --git a/src/lib/libcrypto/bf/bfspeed.c b/src/lib/libcrypto/bf/bfspeed.c new file mode 100644 index 0000000000..640d820dd3 --- /dev/null +++ b/src/lib/libcrypto/bf/bfspeed.c | |||
@@ -0,0 +1,293 @@ | |||
1 | /* crypto/bf/bfspeed.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 | /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ | ||
60 | /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ | ||
61 | |||
62 | #ifndef MSDOS | ||
63 | #define TIMES | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | #ifndef MSDOS | ||
68 | #include <unistd.h> | ||
69 | #else | ||
70 | #include <io.h> | ||
71 | extern int exit(); | ||
72 | #endif | ||
73 | #include <signal.h> | ||
74 | #ifndef VMS | ||
75 | #ifndef _IRIX | ||
76 | #include <time.h> | ||
77 | #endif | ||
78 | #ifdef TIMES | ||
79 | #include <sys/types.h> | ||
80 | #include <sys/times.h> | ||
81 | #endif | ||
82 | #else /* VMS */ | ||
83 | #include <types.h> | ||
84 | struct tms { | ||
85 | time_t tms_utime; | ||
86 | time_t tms_stime; | ||
87 | time_t tms_uchild; /* I dunno... */ | ||
88 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
89 | } | ||
90 | #endif | ||
91 | #ifndef TIMES | ||
92 | #include <sys/timeb.h> | ||
93 | #endif | ||
94 | |||
95 | #ifdef sun | ||
96 | #include <limits.h> | ||
97 | #include <sys/param.h> | ||
98 | #endif | ||
99 | |||
100 | #include "blowfish.h" | ||
101 | |||
102 | /* The following if from times(3) man page. It may need to be changed */ | ||
103 | #ifndef HZ | ||
104 | #ifndef CLK_TCK | ||
105 | #ifndef VMS | ||
106 | #define HZ 100.0 | ||
107 | #else /* VMS */ | ||
108 | #define HZ 100.0 | ||
109 | #endif | ||
110 | #else /* CLK_TCK */ | ||
111 | #define HZ ((double)CLK_TCK) | ||
112 | #endif | ||
113 | #endif | ||
114 | |||
115 | #define BUFSIZE ((long)1024) | ||
116 | long run=0; | ||
117 | |||
118 | #ifndef NOPROTO | ||
119 | double Time_F(int s); | ||
120 | #else | ||
121 | double Time_F(); | ||
122 | #endif | ||
123 | |||
124 | #ifdef SIGALRM | ||
125 | #if defined(__STDC__) || defined(sgi) || defined(_AIX) | ||
126 | #define SIGRETTYPE void | ||
127 | #else | ||
128 | #define SIGRETTYPE int | ||
129 | #endif | ||
130 | |||
131 | #ifndef NOPROTO | ||
132 | SIGRETTYPE sig_done(int sig); | ||
133 | #else | ||
134 | SIGRETTYPE sig_done(); | ||
135 | #endif | ||
136 | |||
137 | SIGRETTYPE sig_done(sig) | ||
138 | int sig; | ||
139 | { | ||
140 | signal(SIGALRM,sig_done); | ||
141 | run=0; | ||
142 | #ifdef LINT | ||
143 | sig=sig; | ||
144 | #endif | ||
145 | } | ||
146 | #endif | ||
147 | |||
148 | #define START 0 | ||
149 | #define STOP 1 | ||
150 | |||
151 | double Time_F(s) | ||
152 | int s; | ||
153 | { | ||
154 | double ret; | ||
155 | #ifdef TIMES | ||
156 | static struct tms tstart,tend; | ||
157 | |||
158 | if (s == START) | ||
159 | { | ||
160 | times(&tstart); | ||
161 | return(0); | ||
162 | } | ||
163 | else | ||
164 | { | ||
165 | times(&tend); | ||
166 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
167 | return((ret == 0.0)?1e-6:ret); | ||
168 | } | ||
169 | #else /* !times() */ | ||
170 | static struct timeb tstart,tend; | ||
171 | long i; | ||
172 | |||
173 | if (s == START) | ||
174 | { | ||
175 | ftime(&tstart); | ||
176 | return(0); | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | ftime(&tend); | ||
181 | i=(long)tend.millitm-(long)tstart.millitm; | ||
182 | ret=((double)(tend.time-tstart.time))+((double)i)/1e3; | ||
183 | return((ret == 0.0)?1e-6:ret); | ||
184 | } | ||
185 | #endif | ||
186 | } | ||
187 | |||
188 | int main(argc,argv) | ||
189 | int argc; | ||
190 | char **argv; | ||
191 | { | ||
192 | long count; | ||
193 | static unsigned char buf[BUFSIZE]; | ||
194 | static unsigned char key[] ={ | ||
195 | 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | ||
196 | 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10, | ||
197 | }; | ||
198 | BF_KEY sch; | ||
199 | double a,b,c,d; | ||
200 | #ifndef SIGALRM | ||
201 | long ca,cb,cc; | ||
202 | #endif | ||
203 | |||
204 | #ifndef TIMES | ||
205 | printf("To get the most acurate results, try to run this\n"); | ||
206 | printf("program when this computer is idle.\n"); | ||
207 | #endif | ||
208 | |||
209 | #ifndef SIGALRM | ||
210 | printf("First we calculate the approximate speed ...\n"); | ||
211 | BF_set_key(&sch,16,key); | ||
212 | count=10; | ||
213 | do { | ||
214 | long i; | ||
215 | BF_LONG data[2]; | ||
216 | |||
217 | count*=2; | ||
218 | Time_F(START); | ||
219 | for (i=count; i; i--) | ||
220 | BF_encrypt(data,&sch); | ||
221 | d=Time_F(STOP); | ||
222 | } while (d < 3.0); | ||
223 | ca=count/512; | ||
224 | cb=count; | ||
225 | cc=count*8/BUFSIZE+1; | ||
226 | printf("Doing BF_set_key %ld times\n",ca); | ||
227 | #define COND(d) (count != (d)) | ||
228 | #define COUNT(d) (d) | ||
229 | #else | ||
230 | #define COND(c) (run) | ||
231 | #define COUNT(d) (count) | ||
232 | signal(SIGALRM,sig_done); | ||
233 | printf("Doing BF_set_key for 10 seconds\n"); | ||
234 | alarm(10); | ||
235 | #endif | ||
236 | |||
237 | Time_F(START); | ||
238 | for (count=0,run=1; COND(ca); count+=4) | ||
239 | { | ||
240 | BF_set_key(&sch,16,key); | ||
241 | BF_set_key(&sch,16,key); | ||
242 | BF_set_key(&sch,16,key); | ||
243 | BF_set_key(&sch,16,key); | ||
244 | } | ||
245 | d=Time_F(STOP); | ||
246 | printf("%ld BF_set_key's in %.2f seconds\n",count,d); | ||
247 | a=((double)COUNT(ca))/d; | ||
248 | |||
249 | #ifdef SIGALRM | ||
250 | printf("Doing BF_encrypt's for 10 seconds\n"); | ||
251 | alarm(10); | ||
252 | #else | ||
253 | printf("Doing BF_encrypt %ld times\n",cb); | ||
254 | #endif | ||
255 | Time_F(START); | ||
256 | for (count=0,run=1; COND(cb); count+=4) | ||
257 | { | ||
258 | BF_LONG data[2]; | ||
259 | |||
260 | BF_encrypt(data,&sch); | ||
261 | BF_encrypt(data,&sch); | ||
262 | BF_encrypt(data,&sch); | ||
263 | BF_encrypt(data,&sch); | ||
264 | } | ||
265 | d=Time_F(STOP); | ||
266 | printf("%ld BF_encrypt's in %.2f second\n",count,d); | ||
267 | b=((double)COUNT(cb)*8)/d; | ||
268 | |||
269 | #ifdef SIGALRM | ||
270 | printf("Doing BF_cbc_encrypt on %ld byte blocks for 10 seconds\n", | ||
271 | BUFSIZE); | ||
272 | alarm(10); | ||
273 | #else | ||
274 | printf("Doing BF_cbc_encrypt %ld times on %ld byte blocks\n",cc, | ||
275 | BUFSIZE); | ||
276 | #endif | ||
277 | Time_F(START); | ||
278 | for (count=0,run=1; COND(cc); count++) | ||
279 | BF_cbc_encrypt(buf,buf,BUFSIZE,&sch, | ||
280 | &(key[0]),BF_ENCRYPT); | ||
281 | d=Time_F(STOP); | ||
282 | printf("%ld BF_cbc_encrypt's of %ld byte blocks in %.2f second\n", | ||
283 | count,BUFSIZE,d); | ||
284 | c=((double)COUNT(cc)*BUFSIZE)/d; | ||
285 | |||
286 | printf("Blowfish set_key per sec = %12.3f (%9.3fuS)\n",a,1.0e6/a); | ||
287 | printf("Blowfish raw ecb bytes per sec = %12.3f (%9.3fuS)\n",b,8.0e6/b); | ||
288 | printf("Blowfish cbc bytes per sec = %12.3f (%9.3fuS)\n",c,8.0e6/c); | ||
289 | exit(0); | ||
290 | #if defined(LINT) || defined(MSDOS) | ||
291 | return(0); | ||
292 | #endif | ||
293 | } | ||
diff --git a/src/lib/libcrypto/bf/bftest.c b/src/lib/libcrypto/bf/bftest.c new file mode 100644 index 0000000000..9266cf813a --- /dev/null +++ b/src/lib/libcrypto/bf/bftest.c | |||
@@ -0,0 +1,521 @@ | |||
1 | /* crypto/bf/bftest.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 | /* This has been a quickly hacked 'ideatest.c'. When I add tests for other | ||
60 | * RC2 modes, more of the code will be uncommented. */ | ||
61 | |||
62 | #include <stdio.h> | ||
63 | #include <string.h> | ||
64 | #include <stdlib.h> | ||
65 | #include "blowfish.h" | ||
66 | |||
67 | char *bf_key[2]={ | ||
68 | "abcdefghijklmnopqrstuvwxyz", | ||
69 | "Who is John Galt?" | ||
70 | }; | ||
71 | |||
72 | /* big endian */ | ||
73 | BF_LONG bf_plain[2][2]={ | ||
74 | {0x424c4f57L,0x46495348L}, | ||
75 | {0xfedcba98L,0x76543210L} | ||
76 | }; | ||
77 | |||
78 | BF_LONG bf_cipher[2][2]={ | ||
79 | {0x324ed0feL,0xf413a203L}, | ||
80 | {0xcc91732bL,0x8022f684L} | ||
81 | }; | ||
82 | /************/ | ||
83 | |||
84 | /* Lets use the DES test vectors :-) */ | ||
85 | #define NUM_TESTS 34 | ||
86 | static unsigned char ecb_data[NUM_TESTS][8]={ | ||
87 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
88 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
89 | {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
90 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
91 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
92 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
93 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
94 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}, | ||
95 | {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57}, | ||
96 | {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E}, | ||
97 | {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86}, | ||
98 | {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E}, | ||
99 | {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6}, | ||
100 | {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE}, | ||
101 | {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6}, | ||
102 | {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE}, | ||
103 | {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16}, | ||
104 | {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F}, | ||
105 | {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46}, | ||
106 | {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E}, | ||
107 | {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76}, | ||
108 | {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07}, | ||
109 | {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F}, | ||
110 | {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7}, | ||
111 | {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF}, | ||
112 | {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6}, | ||
113 | {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF}, | ||
114 | {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, | ||
115 | {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E}, | ||
116 | {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, | ||
117 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
118 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
119 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
120 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}}; | ||
121 | |||
122 | static unsigned char plain_data[NUM_TESTS][8]={ | ||
123 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
124 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
125 | {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, | ||
126 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
127 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
128 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
129 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
130 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
131 | {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42}, | ||
132 | {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA}, | ||
133 | {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72}, | ||
134 | {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A}, | ||
135 | {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2}, | ||
136 | {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A}, | ||
137 | {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2}, | ||
138 | {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A}, | ||
139 | {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02}, | ||
140 | {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A}, | ||
141 | {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32}, | ||
142 | {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA}, | ||
143 | {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62}, | ||
144 | {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2}, | ||
145 | {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA}, | ||
146 | {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92}, | ||
147 | {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A}, | ||
148 | {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2}, | ||
149 | {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A}, | ||
150 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
151 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
152 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
153 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
154 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
155 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
156 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}; | ||
157 | |||
158 | static unsigned char cipher_data[NUM_TESTS][8]={ | ||
159 | {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78}, | ||
160 | {0x51,0x86,0x6F,0xD5,0xB8,0x5E,0xCB,0x8A}, | ||
161 | {0x7D,0x85,0x6F,0x9A,0x61,0x30,0x63,0xF2}, | ||
162 | {0x24,0x66,0xDD,0x87,0x8B,0x96,0x3C,0x9D}, | ||
163 | {0x61,0xF9,0xC3,0x80,0x22,0x81,0xB0,0x96}, | ||
164 | {0x7D,0x0C,0xC6,0x30,0xAF,0xDA,0x1E,0xC7}, | ||
165 | {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78}, | ||
166 | {0x0A,0xCE,0xAB,0x0F,0xC6,0xA0,0xA2,0x8D}, | ||
167 | {0x59,0xC6,0x82,0x45,0xEB,0x05,0x28,0x2B}, | ||
168 | {0xB1,0xB8,0xCC,0x0B,0x25,0x0F,0x09,0xA0}, | ||
169 | {0x17,0x30,0xE5,0x77,0x8B,0xEA,0x1D,0xA4}, | ||
170 | {0xA2,0x5E,0x78,0x56,0xCF,0x26,0x51,0xEB}, | ||
171 | {0x35,0x38,0x82,0xB1,0x09,0xCE,0x8F,0x1A}, | ||
172 | {0x48,0xF4,0xD0,0x88,0x4C,0x37,0x99,0x18}, | ||
173 | {0x43,0x21,0x93,0xB7,0x89,0x51,0xFC,0x98}, | ||
174 | {0x13,0xF0,0x41,0x54,0xD6,0x9D,0x1A,0xE5}, | ||
175 | {0x2E,0xED,0xDA,0x93,0xFF,0xD3,0x9C,0x79}, | ||
176 | {0xD8,0x87,0xE0,0x39,0x3C,0x2D,0xA6,0xE3}, | ||
177 | {0x5F,0x99,0xD0,0x4F,0x5B,0x16,0x39,0x69}, | ||
178 | {0x4A,0x05,0x7A,0x3B,0x24,0xD3,0x97,0x7B}, | ||
179 | {0x45,0x20,0x31,0xC1,0xE4,0xFA,0xDA,0x8E}, | ||
180 | {0x75,0x55,0xAE,0x39,0xF5,0x9B,0x87,0xBD}, | ||
181 | {0x53,0xC5,0x5F,0x9C,0xB4,0x9F,0xC0,0x19}, | ||
182 | {0x7A,0x8E,0x7B,0xFA,0x93,0x7E,0x89,0xA3}, | ||
183 | {0xCF,0x9C,0x5D,0x7A,0x49,0x86,0xAD,0xB5}, | ||
184 | {0xD1,0xAB,0xB2,0x90,0x65,0x8B,0xC7,0x78}, | ||
185 | {0x55,0xCB,0x37,0x74,0xD1,0x3E,0xF2,0x01}, | ||
186 | {0xFA,0x34,0xEC,0x48,0x47,0xB2,0x68,0xB2}, | ||
187 | {0xA7,0x90,0x79,0x51,0x08,0xEA,0x3C,0xAE}, | ||
188 | {0xC3,0x9E,0x07,0x2D,0x9F,0xAC,0x63,0x1D}, | ||
189 | {0x01,0x49,0x33,0xE0,0xCD,0xAF,0xF6,0xE4}, | ||
190 | {0xF2,0x1E,0x9A,0x77,0xB7,0x1C,0x49,0xBC}, | ||
191 | {0x24,0x59,0x46,0x88,0x57,0x54,0x36,0x9A}, | ||
192 | {0x6B,0x5C,0x5A,0x9C,0x5D,0x9E,0x0A,0x5A}, | ||
193 | }; | ||
194 | |||
195 | static unsigned char cbc_key [16]={ | ||
196 | 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, | ||
197 | 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; | ||
198 | static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; | ||
199 | static char cbc_data[40]="7654321 Now is the time for "; | ||
200 | static unsigned char cbc_ok[32]={ | ||
201 | 0x6B,0x77,0xB4,0xD6,0x30,0x06,0xDE,0xE6, | ||
202 | 0x05,0xB1,0x56,0xE2,0x74,0x03,0x97,0x93, | ||
203 | 0x58,0xDE,0xB9,0xE7,0x15,0x46,0x16,0xD9, | ||
204 | 0x59,0xF1,0x65,0x2B,0xD5,0xFF,0x92,0xCC}; | ||
205 | |||
206 | static unsigned char cfb64_ok[]={ | ||
207 | 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA, | ||
208 | 0xF2,0x6E,0xCF,0x6D,0x2E,0xB9,0xE7,0x6E, | ||
209 | 0x3D,0xA3,0xDE,0x04,0xD1,0x51,0x72,0x00, | ||
210 | 0x51,0x9D,0x57,0xA6,0xC3}; | ||
211 | |||
212 | static unsigned char ofb64_ok[]={ | ||
213 | 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA, | ||
214 | 0x62,0xB3,0x43,0xCC,0x5B,0x65,0x58,0x73, | ||
215 | 0x10,0xDD,0x90,0x8D,0x0C,0x24,0x1B,0x22, | ||
216 | 0x63,0xC2,0xCF,0x80,0xDA}; | ||
217 | |||
218 | #define KEY_TEST_NUM 25 | ||
219 | unsigned char key_test[KEY_TEST_NUM]={ | ||
220 | 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87, | ||
221 | 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f, | ||
222 | 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77, | ||
223 | 0x88}; | ||
224 | |||
225 | unsigned char key_data[8]= | ||
226 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}; | ||
227 | |||
228 | unsigned char key_out[KEY_TEST_NUM][8]={ | ||
229 | {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E}, | ||
230 | {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6}, | ||
231 | {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3}, | ||
232 | {0xBE,0x1E,0x63,0x94,0x08,0x64,0x0F,0x05}, | ||
233 | {0xB3,0x9E,0x44,0x48,0x1B,0xDB,0x1E,0x6E}, | ||
234 | {0x94,0x57,0xAA,0x83,0xB1,0x92,0x8C,0x0D}, | ||
235 | {0x8B,0xB7,0x70,0x32,0xF9,0x60,0x62,0x9D}, | ||
236 | {0xE8,0x7A,0x24,0x4E,0x2C,0xC8,0x5E,0x82}, | ||
237 | {0x15,0x75,0x0E,0x7A,0x4F,0x4E,0xC5,0x77}, | ||
238 | {0x12,0x2B,0xA7,0x0B,0x3A,0xB6,0x4A,0xE0}, | ||
239 | {0x3A,0x83,0x3C,0x9A,0xFF,0xC5,0x37,0xF6}, | ||
240 | {0x94,0x09,0xDA,0x87,0xA9,0x0F,0x6B,0xF2}, | ||
241 | {0x88,0x4F,0x80,0x62,0x50,0x60,0xB8,0xB4}, | ||
242 | {0x1F,0x85,0x03,0x1C,0x19,0xE1,0x19,0x68}, | ||
243 | {0x79,0xD9,0x37,0x3A,0x71,0x4C,0xA3,0x4F}, | ||
244 | {0x93,0x14,0x28,0x87,0xEE,0x3B,0xE1,0x5C}, | ||
245 | {0x03,0x42,0x9E,0x83,0x8C,0xE2,0xD1,0x4B}, | ||
246 | {0xA4,0x29,0x9E,0x27,0x46,0x9F,0xF6,0x7B}, | ||
247 | {0xAF,0xD5,0xAE,0xD1,0xC1,0xBC,0x96,0xA8}, | ||
248 | {0x10,0x85,0x1C,0x0E,0x38,0x58,0xDA,0x9F}, | ||
249 | {0xE6,0xF5,0x1E,0xD7,0x9B,0x9D,0xB2,0x1F}, | ||
250 | {0x64,0xA6,0xE1,0x4A,0xFD,0x36,0xB4,0x6F}, | ||
251 | {0x80,0xC7,0xD7,0xD4,0x5A,0x54,0x79,0xAD}, | ||
252 | {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80}, | ||
253 | }; | ||
254 | |||
255 | #ifndef NOPROTO | ||
256 | static int test(void ); | ||
257 | static int print_test_data(void ); | ||
258 | #else | ||
259 | static int test(); | ||
260 | static int print_test_data(); | ||
261 | #endif | ||
262 | |||
263 | int main(argc,argv) | ||
264 | int argc; | ||
265 | char *argv[]; | ||
266 | { | ||
267 | int ret; | ||
268 | |||
269 | if (argc > 1) | ||
270 | ret=print_test_data(); | ||
271 | else | ||
272 | ret=test(); | ||
273 | |||
274 | exit(ret); | ||
275 | return(0); | ||
276 | } | ||
277 | |||
278 | static int print_test_data() | ||
279 | { | ||
280 | unsigned int i,j; | ||
281 | |||
282 | printf("ecb test data\n"); | ||
283 | printf("key bytes\t\tclear bytes\t\tcipher bytes\n"); | ||
284 | for (i=0; i<NUM_TESTS; i++) | ||
285 | { | ||
286 | for (j=0; j<8; j++) | ||
287 | printf("%02X",ecb_data[i][j]); | ||
288 | printf("\t"); | ||
289 | for (j=0; j<8; j++) | ||
290 | printf("%02X",plain_data[i][j]); | ||
291 | printf("\t"); | ||
292 | for (j=0; j<8; j++) | ||
293 | printf("%02X",cipher_data[i][j]); | ||
294 | printf("\n"); | ||
295 | } | ||
296 | |||
297 | printf("set_key test data\n"); | ||
298 | printf("data[8]= "); | ||
299 | for (j=0; j<8; j++) | ||
300 | printf("%02X",key_data[j]); | ||
301 | printf("\n"); | ||
302 | for (i=0; i<KEY_TEST_NUM-1; i++) | ||
303 | { | ||
304 | printf("c="); | ||
305 | for (j=0; j<8; j++) | ||
306 | printf("%02X",key_out[i][j]); | ||
307 | printf(" k[%2d]=",i+1); | ||
308 | for (j=0; j<i+1; j++) | ||
309 | printf("%02X",key_test[j]); | ||
310 | printf("\n"); | ||
311 | } | ||
312 | |||
313 | printf("\nchaining mode test data\n"); | ||
314 | printf("key[16] = "); | ||
315 | for (j=0; j<16; j++) | ||
316 | printf("%02X",cbc_key[j]); | ||
317 | printf("\niv[8] = "); | ||
318 | for (j=0; j<8; j++) | ||
319 | printf("%02X",cbc_iv[j]); | ||
320 | printf("\ndata[%d] = '%s'",(int)strlen(cbc_data)+1,cbc_data); | ||
321 | printf("\ndata[%d] = ",(int)strlen(cbc_data)+1); | ||
322 | for (j=0; j<strlen(cbc_data)+1; j++) | ||
323 | printf("%02X",cbc_data[j]); | ||
324 | printf("\n"); | ||
325 | printf("cbc cipher text\n"); | ||
326 | printf("cipher[%d]= ",32); | ||
327 | for (j=0; j<32; j++) | ||
328 | printf("%02X",cbc_ok[j]); | ||
329 | printf("\n"); | ||
330 | |||
331 | printf("cfb64 cipher text\n"); | ||
332 | printf("cipher[%d]= ",(int)strlen(cbc_data)+1); | ||
333 | for (j=0; j<strlen(cbc_data)+1; j++) | ||
334 | printf("%02X",cfb64_ok[j]); | ||
335 | printf("\n"); | ||
336 | |||
337 | printf("ofb64 cipher text\n"); | ||
338 | printf("cipher[%d]= ",(int)strlen(cbc_data)+1); | ||
339 | for (j=0; j<strlen(cbc_data)+1; j++) | ||
340 | printf("%02X",ofb64_ok[j]); | ||
341 | printf("\n"); | ||
342 | return(0); | ||
343 | } | ||
344 | |||
345 | static int test() | ||
346 | { | ||
347 | unsigned char cbc_in[40],cbc_out[40],iv[8]; | ||
348 | int i,n,err=0; | ||
349 | BF_KEY key; | ||
350 | BF_LONG data[2]; | ||
351 | unsigned char out[8]; | ||
352 | BF_LONG len; | ||
353 | |||
354 | printf("testing blowfish in raw ecb mode\n"); | ||
355 | for (n=0; n<2; n++) | ||
356 | { | ||
357 | BF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]); | ||
358 | |||
359 | data[0]=bf_plain[n][0]; | ||
360 | data[1]=bf_plain[n][1]; | ||
361 | BF_encrypt(data,&key); | ||
362 | if (memcmp(&(bf_cipher[n][0]),&(data[0]),8) != 0) | ||
363 | { | ||
364 | printf("BF_encrypt error encrypting\n"); | ||
365 | printf("got :"); | ||
366 | for (i=0; i<2; i++) | ||
367 | printf("%08lX ",data[i]); | ||
368 | printf("\n"); | ||
369 | printf("expected:"); | ||
370 | for (i=0; i<2; i++) | ||
371 | printf("%08lX ",bf_cipher[n][i]); | ||
372 | err=1; | ||
373 | printf("\n"); | ||
374 | } | ||
375 | |||
376 | BF_decrypt(&(data[0]),&key); | ||
377 | if (memcmp(&(bf_plain[n][0]),&(data[0]),8) != 0) | ||
378 | { | ||
379 | printf("BF_encrypt error decrypting\n"); | ||
380 | printf("got :"); | ||
381 | for (i=0; i<2; i++) | ||
382 | printf("%08lX ",data[i]); | ||
383 | printf("\n"); | ||
384 | printf("expected:"); | ||
385 | for (i=0; i<2; i++) | ||
386 | printf("%08lX ",bf_plain[n][i]); | ||
387 | printf("\n"); | ||
388 | err=1; | ||
389 | } | ||
390 | } | ||
391 | |||
392 | printf("testing blowfish in ecb mode\n"); | ||
393 | |||
394 | for (n=0; n<NUM_TESTS; n++) | ||
395 | { | ||
396 | BF_set_key(&key,8,ecb_data[n]); | ||
397 | |||
398 | BF_ecb_encrypt(&(plain_data[n][0]),out,&key,BF_ENCRYPT); | ||
399 | if (memcmp(&(cipher_data[n][0]),out,8) != 0) | ||
400 | { | ||
401 | printf("BF_ecb_encrypt blowfish error encrypting\n"); | ||
402 | printf("got :"); | ||
403 | for (i=0; i<8; i++) | ||
404 | printf("%02X ",out[i]); | ||
405 | printf("\n"); | ||
406 | printf("expected:"); | ||
407 | for (i=0; i<8; i++) | ||
408 | printf("%02X ",cipher_data[n][i]); | ||
409 | err=1; | ||
410 | printf("\n"); | ||
411 | } | ||
412 | |||
413 | BF_ecb_encrypt(out,out,&key,BF_DECRYPT); | ||
414 | if (memcmp(&(plain_data[n][0]),out,8) != 0) | ||
415 | { | ||
416 | printf("BF_ecb_encrypt error decrypting\n"); | ||
417 | printf("got :"); | ||
418 | for (i=0; i<8; i++) | ||
419 | printf("%02X ",out[i]); | ||
420 | printf("\n"); | ||
421 | printf("expected:"); | ||
422 | for (i=0; i<8; i++) | ||
423 | printf("%02X ",plain_data[n][i]); | ||
424 | printf("\n"); | ||
425 | err=1; | ||
426 | } | ||
427 | } | ||
428 | |||
429 | printf("testing blowfish set_key\n"); | ||
430 | for (n=1; n<KEY_TEST_NUM; n++) | ||
431 | { | ||
432 | BF_set_key(&key,n,key_test); | ||
433 | BF_ecb_encrypt(key_data,out,&key,BF_ENCRYPT); | ||
434 | if (memcmp(out,&(key_out[n-1][0]),8) != 0) | ||
435 | { | ||
436 | printf("blowfish setkey error\n"); | ||
437 | err=1; | ||
438 | } | ||
439 | } | ||
440 | |||
441 | printf("testing blowfish in cbc mode\n"); | ||
442 | len=strlen(cbc_data)+1; | ||
443 | |||
444 | BF_set_key(&key,16,cbc_key); | ||
445 | memset(cbc_in,0,40); | ||
446 | memset(cbc_out,0,40); | ||
447 | memcpy(iv,cbc_iv,8); | ||
448 | BF_cbc_encrypt((unsigned char *)cbc_data,cbc_out,len, | ||
449 | &key,iv,BF_ENCRYPT); | ||
450 | if (memcmp(cbc_out,cbc_ok,32) != 0) | ||
451 | { | ||
452 | err=1; | ||
453 | printf("BF_cbc_encrypt encrypt error\n"); | ||
454 | for (i=0; i<32; i++) printf("0x%02X,",cbc_out[i]); | ||
455 | } | ||
456 | memcpy(iv,cbc_iv,8); | ||
457 | BF_cbc_encrypt(cbc_out,cbc_in,len, | ||
458 | &key,iv,BF_DECRYPT); | ||
459 | if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0) | ||
460 | { | ||
461 | printf("BF_cbc_encrypt decrypt error\n"); | ||
462 | err=1; | ||
463 | } | ||
464 | |||
465 | printf("testing blowfish in cfb64 mode\n"); | ||
466 | |||
467 | BF_set_key(&key,16,cbc_key); | ||
468 | memset(cbc_in,0,40); | ||
469 | memset(cbc_out,0,40); | ||
470 | memcpy(iv,cbc_iv,8); | ||
471 | n=0; | ||
472 | BF_cfb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13, | ||
473 | &key,iv,&n,BF_ENCRYPT); | ||
474 | BF_cfb64_encrypt((unsigned char *)&(cbc_data[13]),&(cbc_out[13]),len-13, | ||
475 | &key,iv,&n,BF_ENCRYPT); | ||
476 | if (memcmp(cbc_out,cfb64_ok,(int)len) != 0) | ||
477 | { | ||
478 | err=1; | ||
479 | printf("BF_cfb64_encrypt encrypt error\n"); | ||
480 | for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]); | ||
481 | } | ||
482 | n=0; | ||
483 | memcpy(iv,cbc_iv,8); | ||
484 | BF_cfb64_encrypt(cbc_out,cbc_in,17, | ||
485 | &key,iv,&n,BF_DECRYPT); | ||
486 | BF_cfb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17, | ||
487 | &key,iv,&n,BF_DECRYPT); | ||
488 | if (memcmp(cbc_in,cbc_data,(int)len) != 0) | ||
489 | { | ||
490 | printf("BF_cfb64_encrypt decrypt error\n"); | ||
491 | err=1; | ||
492 | } | ||
493 | |||
494 | printf("testing blowfish in ofb64\n"); | ||
495 | |||
496 | BF_set_key(&key,16,cbc_key); | ||
497 | memset(cbc_in,0,40); | ||
498 | memset(cbc_out,0,40); | ||
499 | memcpy(iv,cbc_iv,8); | ||
500 | n=0; | ||
501 | BF_ofb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,&key,iv,&n); | ||
502 | BF_ofb64_encrypt((unsigned char *)&(cbc_data[13]), | ||
503 | &(cbc_out[13]),len-13,&key,iv,&n); | ||
504 | if (memcmp(cbc_out,ofb64_ok,(int)len) != 0) | ||
505 | { | ||
506 | err=1; | ||
507 | printf("BF_ofb64_encrypt encrypt error\n"); | ||
508 | for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]); | ||
509 | } | ||
510 | n=0; | ||
511 | memcpy(iv,cbc_iv,8); | ||
512 | BF_ofb64_encrypt(cbc_out,cbc_in,17,&key,iv,&n); | ||
513 | BF_ofb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,&key,iv,&n); | ||
514 | if (memcmp(cbc_in,cbc_data,(int)len) != 0) | ||
515 | { | ||
516 | printf("BF_ofb64_encrypt decrypt error\n"); | ||
517 | err=1; | ||
518 | } | ||
519 | |||
520 | return(err); | ||
521 | } | ||
diff --git a/src/lib/libcrypto/bio/bss_rtcp.c b/src/lib/libcrypto/bio/bss_rtcp.c new file mode 100644 index 0000000000..6eb434dee8 --- /dev/null +++ b/src/lib/libcrypto/bio/bss_rtcp.c | |||
@@ -0,0 +1,297 @@ | |||
1 | /* crypto/bio/bss_rtcp.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 | /* Written by David L. Jones <jonesd@kcgl1.eng.ohio-state.edu> | ||
60 | * Date: 22-JUL-1996 | ||
61 | */ | ||
62 | /* VMS */ | ||
63 | #include <stdio.h> | ||
64 | #include <stdlib.h> | ||
65 | #include <string.h> | ||
66 | #include <errno.h> | ||
67 | #include "cryptlib.h" | ||
68 | #include "bio.h" | ||
69 | |||
70 | #include <iodef.h> /* VMS IO$_ definitions */ | ||
71 | extern int SYS$QIOW(); | ||
72 | typedef unsigned short io_channel; | ||
73 | /*************************************************************************/ | ||
74 | struct io_status { short status, count; long flags; }; | ||
75 | |||
76 | struct rpc_msg { /* Should have member alignment inhibited */ | ||
77 | char channel; /* 'A'-app data. 'R'-remote client 'G'-global */ | ||
78 | char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */ | ||
79 | unsigned short int length; /* Amount of data returned or max to return */ | ||
80 | char data[4092]; /* variable data */ | ||
81 | }; | ||
82 | #define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092) | ||
83 | |||
84 | struct rpc_ctx { | ||
85 | int filled, pos; | ||
86 | struct rpc_msg msg; | ||
87 | }; | ||
88 | |||
89 | static int rtcp_write(BIO *h,char *buf,int num); | ||
90 | static int rtcp_read(BIO *h,char *buf,int size); | ||
91 | static int rtcp_puts(BIO *h,char *str); | ||
92 | static int rtcp_gets(BIO *h,char *str,int size); | ||
93 | static long rtcp_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
94 | static int rtcp_new(BIO *h); | ||
95 | static int rtcp_free(BIO *data); | ||
96 | |||
97 | static BIO_METHOD rtcp_method= | ||
98 | { | ||
99 | BIO_TYPE_FD, | ||
100 | "RTCP", | ||
101 | rtcp_write, | ||
102 | rtcp_read, | ||
103 | rtcp_puts, | ||
104 | rtcp_gets, | ||
105 | rtcp_ctrl, | ||
106 | rtcp_new, | ||
107 | rtcp_free, | ||
108 | }; | ||
109 | |||
110 | BIO_METHOD *BIO_s_rtcp() | ||
111 | { | ||
112 | return(&rtcp_method); | ||
113 | } | ||
114 | /*****************************************************************************/ | ||
115 | /* Decnet I/O routines. | ||
116 | */ | ||
117 | static int get ( io_channel chan, char *buffer, int maxlen, int *length ) | ||
118 | { | ||
119 | int status; | ||
120 | struct io_status iosb; | ||
121 | status = SYS$QIOW ( 0, chan, IO$_READVBLK, &iosb, 0, 0, | ||
122 | buffer, maxlen, 0, 0, 0, 0 ); | ||
123 | if ( (status&1) == 1 ) status = iosb.status; | ||
124 | if ( (status&1) == 1 ) *length = iosb.count; | ||
125 | return status; | ||
126 | } | ||
127 | |||
128 | static int put ( io_channel chan, char *buffer, int length ) | ||
129 | { | ||
130 | int status; | ||
131 | struct io_status iosb; | ||
132 | status = SYS$QIOW ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, | ||
133 | buffer, length, 0, 0, 0, 0 ); | ||
134 | if ( (status&1) == 1 ) status = iosb.status; | ||
135 | return status; | ||
136 | } | ||
137 | /***************************************************************************/ | ||
138 | |||
139 | static int rtcp_new(bi) | ||
140 | BIO *bi; | ||
141 | { | ||
142 | struct rpc_ctx *ctx; | ||
143 | bi->init=1; | ||
144 | bi->num=0; | ||
145 | bi->flags = 0; | ||
146 | bi->ptr=Malloc(sizeof(struct rpc_ctx)); | ||
147 | ctx = (struct rpc_ctx *) bi->ptr; | ||
148 | ctx->filled = 0; | ||
149 | ctx->pos = 0; | ||
150 | return(1); | ||
151 | } | ||
152 | |||
153 | static int rtcp_free(a) | ||
154 | BIO *a; | ||
155 | { | ||
156 | if (a == NULL) return(0); | ||
157 | if ( a->ptr ) Free ( a->ptr ); | ||
158 | a->ptr = NULL; | ||
159 | return(1); | ||
160 | } | ||
161 | |||
162 | static int rtcp_read(b,out,outl) | ||
163 | BIO *b; | ||
164 | char *out; | ||
165 | int outl; | ||
166 | { | ||
167 | int status, length; | ||
168 | struct rpc_ctx *ctx; | ||
169 | /* | ||
170 | * read data, return existing. | ||
171 | */ | ||
172 | ctx = (struct rpc_ctx *) b->ptr; | ||
173 | if ( ctx->pos < ctx->filled ) { | ||
174 | length = ctx->filled - ctx->pos; | ||
175 | if ( length > outl ) length = outl; | ||
176 | memmove ( out, &ctx->msg.data[ctx->pos], length ); | ||
177 | ctx->pos += length; | ||
178 | return length; | ||
179 | } | ||
180 | /* | ||
181 | * Requst more data from R channel. | ||
182 | */ | ||
183 | ctx->msg.channel = 'R'; | ||
184 | ctx->msg.function = 'G'; | ||
185 | ctx->msg.length = sizeof(ctx->msg.data); | ||
186 | status = put ( b->num, (char *) &ctx->msg, RPC_HDR_SIZE ); | ||
187 | if ( (status&1) == 0 ) { | ||
188 | return -1; | ||
189 | } | ||
190 | /* | ||
191 | * Read. | ||
192 | */ | ||
193 | ctx->pos = ctx->filled = 0; | ||
194 | status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length ); | ||
195 | if ( (status&1) == 0 ) length = -1; | ||
196 | if ( ctx->msg.channel != 'R' || ctx->msg.function != 'C' ) { | ||
197 | length = -1; | ||
198 | } | ||
199 | ctx->filled = length - RPC_HDR_SIZE; | ||
200 | |||
201 | if ( ctx->pos < ctx->filled ) { | ||
202 | length = ctx->filled - ctx->pos; | ||
203 | if ( length > outl ) length = outl; | ||
204 | memmove ( out, ctx->msg.data, length ); | ||
205 | ctx->pos += length; | ||
206 | return length; | ||
207 | } | ||
208 | |||
209 | return length; | ||
210 | } | ||
211 | |||
212 | static int rtcp_write(b,in,inl) | ||
213 | BIO *b; | ||
214 | char *in; | ||
215 | int inl; | ||
216 | { | ||
217 | int status, i, segment, length; | ||
218 | struct rpc_ctx *ctx; | ||
219 | /* | ||
220 | * Output data, send in chunks no larger that sizeof(ctx->msg.data). | ||
221 | */ | ||
222 | ctx = (struct rpc_ctx *) b->ptr; | ||
223 | for ( i = 0; i < inl; i += segment ) { | ||
224 | segment = inl - i; | ||
225 | if ( segment > sizeof(ctx->msg.data) ) segment = sizeof(ctx->msg.data); | ||
226 | ctx->msg.channel = 'R'; | ||
227 | ctx->msg.function = 'P'; | ||
228 | ctx->msg.length = segment; | ||
229 | memmove ( ctx->msg.data, &in[i], segment ); | ||
230 | status = put ( b->num, (char *) &ctx->msg, segment + RPC_HDR_SIZE ); | ||
231 | if ((status&1) == 0 ) { i = -1; break; } | ||
232 | |||
233 | status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length ); | ||
234 | if ( ((status&1) == 0) || (length < RPC_HDR_SIZE) ) { i = -1; break; } | ||
235 | if ( (ctx->msg.channel != 'R') || (ctx->msg.function != 'C') ) { | ||
236 | printf("unexpected response when confirming put %c %c\n", | ||
237 | ctx->msg.channel, ctx->msg.function ); | ||
238 | |||
239 | } | ||
240 | } | ||
241 | return(i); | ||
242 | } | ||
243 | |||
244 | static long rtcp_ctrl(b,cmd,num,ptr) | ||
245 | BIO *b; | ||
246 | int cmd; | ||
247 | long num; | ||
248 | char *ptr; | ||
249 | { | ||
250 | long ret=1; | ||
251 | |||
252 | switch (cmd) | ||
253 | { | ||
254 | case BIO_CTRL_RESET: | ||
255 | case BIO_CTRL_EOF: | ||
256 | ret = 1; | ||
257 | break; | ||
258 | case BIO_CTRL_SET: | ||
259 | b->num = num; | ||
260 | ret = 1; | ||
261 | break; | ||
262 | case BIO_CTRL_SET_CLOSE: | ||
263 | case BIO_CTRL_FLUSH: | ||
264 | case BIO_CTRL_DUP: | ||
265 | ret=1; | ||
266 | break; | ||
267 | case BIO_CTRL_GET_CLOSE: | ||
268 | case BIO_CTRL_INFO: | ||
269 | case BIO_CTRL_GET: | ||
270 | case BIO_CTRL_PENDING: | ||
271 | case BIO_CTRL_WPENDING: | ||
272 | default: | ||
273 | ret=0; | ||
274 | break; | ||
275 | } | ||
276 | return(ret); | ||
277 | } | ||
278 | |||
279 | static int rtcp_gets(bp,buf,size) | ||
280 | BIO *bp; | ||
281 | char *buf; | ||
282 | int size; | ||
283 | { | ||
284 | return(0); | ||
285 | } | ||
286 | |||
287 | static int rtcp_puts(bp,str) | ||
288 | BIO *bp; | ||
289 | char *str; | ||
290 | { | ||
291 | int length; | ||
292 | if (str == NULL) return(0); | ||
293 | length = strlen ( str ); | ||
294 | if ( length == 0 ) return (0); | ||
295 | return rtcp_write ( bp,str, length ); | ||
296 | } | ||
297 | |||
diff --git a/src/lib/libcrypto/bn/asm/README b/src/lib/libcrypto/bn/asm/README new file mode 100644 index 0000000000..d93fbff77f --- /dev/null +++ b/src/lib/libcrypto/bn/asm/README | |||
@@ -0,0 +1,30 @@ | |||
1 | All assember in this directory are just version of the file | ||
2 | crypto/bn/bn_mulw.c. | ||
3 | |||
4 | Quite a few of these files are just the assember output from gcc since on | ||
5 | quite a few machines they are 2 times faster than the system compiler. | ||
6 | |||
7 | For the x86, I have hand written assember because of the bad job all | ||
8 | compilers seem to do on it. This normally gives a 2 time speed up in the RSA | ||
9 | routines. | ||
10 | |||
11 | For the DEC alpha, I also hand wrote the assember (except the division which | ||
12 | is just the output from the C compiler pasted on the end of the file). | ||
13 | On the 2 alpha C compilers I had access to, it was not possible to do | ||
14 | 64b x 64b -> 128b calculations (both long and the long long data types | ||
15 | were 64 bits). So the hand assember gives access to the 128 bit result and | ||
16 | a 2 times speedup :-). | ||
17 | |||
18 | The x86xxxx.obj files are the assembled version of x86xxxx.asm files. | ||
19 | I had such a hard time finding a macro assember for Microsoft, I decided to | ||
20 | include the object file to save others the hassle :-). | ||
21 | |||
22 | I have also included uu encoded versions of the .obj incase they get | ||
23 | trashed. | ||
24 | |||
25 | There are 2 versions of assember for the HP PA-RISC. | ||
26 | pa-risc.s is the origional one which works fine. | ||
27 | pa-risc2.s is a new version that often generates warnings but if the | ||
28 | tests pass, it gives performance that is over 2 times faster than | ||
29 | pa-risc.s. | ||
30 | Both were generated using gcc :-) | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.s b/src/lib/libcrypto/bn/asm/alpha.s new file mode 100644 index 0000000000..1d17b1d619 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/alpha.s | |||
@@ -0,0 +1,344 @@ | |||
1 | # DEC Alpha assember | ||
2 | # The bn_div64 is actually gcc output but the other parts are hand done. | ||
3 | # Thanks to tzeruch@ceddec.com for sending me the gcc output for | ||
4 | # bn_div64. | ||
5 | .file 1 "bn_mulw.c" | ||
6 | .set noat | ||
7 | gcc2_compiled.: | ||
8 | __gnu_compiled_c: | ||
9 | .text | ||
10 | .align 3 | ||
11 | .globl bn_mul_add_words | ||
12 | .ent bn_mul_add_words | ||
13 | bn_mul_add_words: | ||
14 | bn_mul_add_words..ng: | ||
15 | .frame $30,0,$26,0 | ||
16 | .prologue 0 | ||
17 | subq $18,2,$25 # num=-2 | ||
18 | bis $31,$31,$0 | ||
19 | blt $25,$42 | ||
20 | .align 5 | ||
21 | $142: | ||
22 | subq $18,2,$18 # num-=2 | ||
23 | subq $25,2,$25 # num-=2 | ||
24 | |||
25 | ldq $1,0($17) # a[0] | ||
26 | ldq $2,8($17) # a[1] | ||
27 | |||
28 | mulq $19,$1,$3 # a[0]*w low part r3 | ||
29 | umulh $19,$1,$1 # a[0]*w high part r1 | ||
30 | mulq $19,$2,$4 # a[1]*w low part r4 | ||
31 | umulh $19,$2,$2 # a[1]*w high part r2 | ||
32 | |||
33 | ldq $22,0($16) # r[0] r22 | ||
34 | ldq $23,8($16) # r[1] r23 | ||
35 | |||
36 | addq $3,$22,$3 # a0 low part + r[0] | ||
37 | addq $4,$23,$4 # a1 low part + r[1] | ||
38 | cmpult $3,$22,$5 # overflow? | ||
39 | cmpult $4,$23,$6 # overflow? | ||
40 | addq $5,$1,$1 # high part + overflow | ||
41 | addq $6,$2,$2 # high part + overflow | ||
42 | |||
43 | addq $3,$0,$3 # add c | ||
44 | cmpult $3,$0,$5 # overflow? | ||
45 | stq $3,0($16) | ||
46 | addq $5,$1,$0 # c=high part + overflow | ||
47 | |||
48 | addq $4,$0,$4 # add c | ||
49 | cmpult $4,$0,$5 # overflow? | ||
50 | stq $4,8($16) | ||
51 | addq $5,$2,$0 # c=high part + overflow | ||
52 | |||
53 | ble $18,$43 | ||
54 | |||
55 | addq $16,16,$16 | ||
56 | addq $17,16,$17 | ||
57 | blt $25,$42 | ||
58 | |||
59 | br $31,$142 | ||
60 | $42: | ||
61 | ldq $1,0($17) # a[0] | ||
62 | umulh $19,$1,$3 # a[0]*w high part | ||
63 | mulq $19,$1,$1 # a[0]*w low part | ||
64 | ldq $2,0($16) # r[0] | ||
65 | addq $1,$2,$1 # low part + r[0] | ||
66 | cmpult $1,$2,$4 # overflow? | ||
67 | addq $4,$3,$3 # high part + overflow | ||
68 | addq $1,$0,$1 # add c | ||
69 | cmpult $1,$0,$4 # overflow? | ||
70 | addq $4,$3,$0 # c=high part + overflow | ||
71 | stq $1,0($16) | ||
72 | |||
73 | .align 4 | ||
74 | $43: | ||
75 | ret $31,($26),1 | ||
76 | .end bn_mul_add_words | ||
77 | .align 3 | ||
78 | .globl bn_mul_words | ||
79 | .ent bn_mul_words | ||
80 | bn_mul_words: | ||
81 | bn_mul_words..ng: | ||
82 | .frame $30,0,$26,0 | ||
83 | .prologue 0 | ||
84 | subq $18,2,$25 # num=-2 | ||
85 | bis $31,$31,$0 | ||
86 | blt $25,$242 | ||
87 | .align 5 | ||
88 | $342: | ||
89 | subq $18,2,$18 # num-=2 | ||
90 | subq $25,2,$25 # num-=2 | ||
91 | |||
92 | ldq $1,0($17) # a[0] | ||
93 | ldq $2,8($17) # a[1] | ||
94 | |||
95 | mulq $19,$1,$3 # a[0]*w low part r3 | ||
96 | umulh $19,$1,$1 # a[0]*w high part r1 | ||
97 | mulq $19,$2,$4 # a[1]*w low part r4 | ||
98 | umulh $19,$2,$2 # a[1]*w high part r2 | ||
99 | |||
100 | addq $3,$0,$3 # add c | ||
101 | cmpult $3,$0,$5 # overflow? | ||
102 | stq $3,0($16) | ||
103 | addq $5,$1,$0 # c=high part + overflow | ||
104 | |||
105 | addq $4,$0,$4 # add c | ||
106 | cmpult $4,$0,$5 # overflow? | ||
107 | stq $4,8($16) | ||
108 | addq $5,$2,$0 # c=high part + overflow | ||
109 | |||
110 | ble $18,$243 | ||
111 | |||
112 | addq $16,16,$16 | ||
113 | addq $17,16,$17 | ||
114 | blt $25,$242 | ||
115 | |||
116 | br $31,$342 | ||
117 | $242: | ||
118 | ldq $1,0($17) # a[0] | ||
119 | umulh $19,$1,$3 # a[0]*w high part | ||
120 | mulq $19,$1,$1 # a[0]*w low part | ||
121 | addq $1,$0,$1 # add c | ||
122 | cmpult $1,$0,$4 # overflow? | ||
123 | addq $4,$3,$0 # c=high part + overflow | ||
124 | stq $1,0($16) | ||
125 | $243: | ||
126 | ret $31,($26),1 | ||
127 | .end bn_mul_words | ||
128 | .align 3 | ||
129 | .globl bn_sqr_words | ||
130 | .ent bn_sqr_words | ||
131 | bn_sqr_words: | ||
132 | bn_sqr_words..ng: | ||
133 | .frame $30,0,$26,0 | ||
134 | .prologue 0 | ||
135 | |||
136 | subq $18,2,$25 # num=-2 | ||
137 | blt $25,$442 | ||
138 | .align 5 | ||
139 | $542: | ||
140 | subq $18,2,$18 # num-=2 | ||
141 | subq $25,2,$25 # num-=2 | ||
142 | |||
143 | ldq $1,0($17) # a[0] | ||
144 | ldq $4,8($17) # a[1] | ||
145 | |||
146 | mulq $1,$1,$2 # a[0]*w low part r2 | ||
147 | umulh $1,$1,$3 # a[0]*w high part r3 | ||
148 | mulq $4,$4,$5 # a[1]*w low part r5 | ||
149 | umulh $4,$4,$6 # a[1]*w high part r6 | ||
150 | |||
151 | stq $2,0($16) # r[0] | ||
152 | stq $3,8($16) # r[1] | ||
153 | stq $5,16($16) # r[3] | ||
154 | stq $6,24($16) # r[4] | ||
155 | |||
156 | ble $18,$443 | ||
157 | |||
158 | addq $16,32,$16 | ||
159 | addq $17,16,$17 | ||
160 | blt $25,$442 | ||
161 | br $31,$542 | ||
162 | |||
163 | $442: | ||
164 | ldq $1,0($17) # a[0] | ||
165 | mulq $1,$1,$2 # a[0]*w low part r2 | ||
166 | umulh $1,$1,$3 # a[0]*w high part r3 | ||
167 | stq $2,0($16) # r[0] | ||
168 | stq $3,8($16) # r[1] | ||
169 | |||
170 | .align 4 | ||
171 | $443: | ||
172 | ret $31,($26),1 | ||
173 | .end bn_sqr_words | ||
174 | |||
175 | .align 3 | ||
176 | .globl bn_add_words | ||
177 | .ent bn_add_words | ||
178 | bn_add_words: | ||
179 | bn_add_words..ng: | ||
180 | .frame $30,0,$26,0 | ||
181 | .prologue 0 | ||
182 | |||
183 | bis $31,$31,$8 # carry = 0 | ||
184 | ble $19,$900 | ||
185 | $901: | ||
186 | ldq $0,0($17) # a[0] | ||
187 | ldq $1,0($18) # a[1] | ||
188 | |||
189 | addq $0,$1,$3 # c=a+b; | ||
190 | addq $17,8,$17 # a++ | ||
191 | |||
192 | cmpult $3,$1,$7 # did we overflow? | ||
193 | addq $18,8,$18 # b++ | ||
194 | |||
195 | addq $8,$3,$3 # c+=carry | ||
196 | |||
197 | cmpult $3,$8,$8 # did we overflow? | ||
198 | stq $3,($16) # r[0]=c | ||
199 | |||
200 | addq $7,$8,$8 # add into overflow | ||
201 | subq $19,1,$19 # loop-- | ||
202 | |||
203 | addq $16,8,$16 # r++ | ||
204 | bgt $19,$901 | ||
205 | $900: | ||
206 | bis $8,$8,$0 # return carry | ||
207 | ret $31,($26),1 | ||
208 | .end bn_add_words | ||
209 | |||
210 | # | ||
211 | # What follows was taken directly from the C compiler with a few | ||
212 | # hacks to redo the lables. | ||
213 | # | ||
214 | .text | ||
215 | .align 3 | ||
216 | .globl bn_div64 | ||
217 | .ent bn_div64 | ||
218 | bn_div64: | ||
219 | ldgp $29,0($27) | ||
220 | bn_div64..ng: | ||
221 | lda $30,-48($30) | ||
222 | .frame $30,48,$26,0 | ||
223 | stq $26,0($30) | ||
224 | stq $9,8($30) | ||
225 | stq $10,16($30) | ||
226 | stq $11,24($30) | ||
227 | stq $12,32($30) | ||
228 | stq $13,40($30) | ||
229 | .mask 0x4003e00,-48 | ||
230 | .prologue 1 | ||
231 | bis $16,$16,$9 | ||
232 | bis $17,$17,$10 | ||
233 | bis $18,$18,$11 | ||
234 | bis $31,$31,$13 | ||
235 | bis $31,2,$12 | ||
236 | bne $11,$119 | ||
237 | lda $0,-1 | ||
238 | br $31,$136 | ||
239 | .align 4 | ||
240 | $119: | ||
241 | bis $11,$11,$16 | ||
242 | jsr $26,BN_num_bits_word | ||
243 | ldgp $29,0($26) | ||
244 | subq $0,64,$1 | ||
245 | beq $1,$120 | ||
246 | bis $31,1,$1 | ||
247 | sll $1,$0,$1 | ||
248 | cmpule $9,$1,$1 | ||
249 | bne $1,$120 | ||
250 | # lda $16,_IO_stderr_ | ||
251 | # lda $17,$C32 | ||
252 | # bis $0,$0,$18 | ||
253 | # jsr $26,fprintf | ||
254 | # ldgp $29,0($26) | ||
255 | jsr $26,abort | ||
256 | ldgp $29,0($26) | ||
257 | .align 4 | ||
258 | $120: | ||
259 | bis $31,64,$3 | ||
260 | cmpult $9,$11,$2 | ||
261 | subq $3,$0,$1 | ||
262 | addl $1,$31,$0 | ||
263 | subq $9,$11,$1 | ||
264 | cmoveq $2,$1,$9 | ||
265 | beq $0,$122 | ||
266 | zapnot $0,15,$2 | ||
267 | subq $3,$0,$1 | ||
268 | sll $11,$2,$11 | ||
269 | sll $9,$2,$3 | ||
270 | srl $10,$1,$1 | ||
271 | sll $10,$2,$10 | ||
272 | bis $3,$1,$9 | ||
273 | $122: | ||
274 | srl $11,32,$5 | ||
275 | zapnot $11,15,$6 | ||
276 | lda $7,-1 | ||
277 | .align 5 | ||
278 | $123: | ||
279 | srl $9,32,$1 | ||
280 | subq $1,$5,$1 | ||
281 | bne $1,$126 | ||
282 | zapnot $7,15,$27 | ||
283 | br $31,$127 | ||
284 | .align 4 | ||
285 | $126: | ||
286 | bis $9,$9,$24 | ||
287 | bis $5,$5,$25 | ||
288 | divqu $24,$25,$27 | ||
289 | $127: | ||
290 | srl $10,32,$4 | ||
291 | .align 5 | ||
292 | $128: | ||
293 | mulq $27,$5,$1 | ||
294 | subq $9,$1,$3 | ||
295 | zapnot $3,240,$1 | ||
296 | bne $1,$129 | ||
297 | mulq $6,$27,$2 | ||
298 | sll $3,32,$1 | ||
299 | addq $1,$4,$1 | ||
300 | cmpule $2,$1,$2 | ||
301 | bne $2,$129 | ||
302 | subq $27,1,$27 | ||
303 | br $31,$128 | ||
304 | .align 4 | ||
305 | $129: | ||
306 | mulq $27,$6,$1 | ||
307 | mulq $27,$5,$4 | ||
308 | srl $1,32,$3 | ||
309 | sll $1,32,$1 | ||
310 | addq $4,$3,$4 | ||
311 | cmpult $10,$1,$2 | ||
312 | subq $10,$1,$10 | ||
313 | addq $2,$4,$2 | ||
314 | cmpult $9,$2,$1 | ||
315 | bis $2,$2,$4 | ||
316 | beq $1,$134 | ||
317 | addq $9,$11,$9 | ||
318 | subq $27,1,$27 | ||
319 | $134: | ||
320 | subl $12,1,$12 | ||
321 | subq $9,$4,$9 | ||
322 | beq $12,$124 | ||
323 | sll $27,32,$13 | ||
324 | sll $9,32,$2 | ||
325 | srl $10,32,$1 | ||
326 | sll $10,32,$10 | ||
327 | bis $2,$1,$9 | ||
328 | br $31,$123 | ||
329 | .align 4 | ||
330 | $124: | ||
331 | bis $13,$27,$0 | ||
332 | $136: | ||
333 | ldq $26,0($30) | ||
334 | ldq $9,8($30) | ||
335 | ldq $10,16($30) | ||
336 | ldq $11,24($30) | ||
337 | ldq $12,32($30) | ||
338 | ldq $13,40($30) | ||
339 | addq $30,48,$30 | ||
340 | ret $31,($26),1 | ||
341 | .end bn_div64 | ||
342 | .ident "GCC: (GNU) 2.7.2.1" | ||
343 | |||
344 | |||
diff --git a/src/lib/libcrypto/bn/asm/pa-risc.s b/src/lib/libcrypto/bn/asm/pa-risc.s new file mode 100644 index 0000000000..775130a191 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/pa-risc.s | |||
@@ -0,0 +1,710 @@ | |||
1 | .SPACE $PRIVATE$ | ||
2 | .SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31 | ||
3 | .SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82 | ||
4 | .SPACE $TEXT$ | ||
5 | .SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44 | ||
6 | .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY | ||
7 | .IMPORT $global$,DATA | ||
8 | .IMPORT $$dyncall,MILLICODE | ||
9 | ; gcc_compiled.: | ||
10 | .SPACE $TEXT$ | ||
11 | .SUBSPA $CODE$ | ||
12 | |||
13 | .align 4 | ||
14 | .EXPORT bn_mul_add_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR | ||
15 | bn_mul_add_words | ||
16 | .PROC | ||
17 | .CALLINFO FRAME=0,CALLS,SAVE_RP | ||
18 | .ENTRY | ||
19 | stw %r2,-20(0,%r30) | ||
20 | ldi 0,%r28 | ||
21 | extru %r23,31,16,%r2 | ||
22 | stw %r2,-16(0,%r30) | ||
23 | extru %r23,15,16,%r23 | ||
24 | ldil L'65536,%r31 | ||
25 | fldws -16(0,%r30),%fr11R | ||
26 | stw %r23,-16(0,%r30) | ||
27 | ldo 12(%r25),%r29 | ||
28 | ldo 12(%r26),%r23 | ||
29 | fldws -16(0,%r30),%fr11L | ||
30 | L$0002 | ||
31 | ldw 0(0,%r25),%r19 | ||
32 | extru %r19,31,16,%r20 | ||
33 | stw %r20,-16(0,%r30) | ||
34 | extru %r19,15,16,%r19 | ||
35 | fldws -16(0,%r30),%fr22L | ||
36 | stw %r19,-16(0,%r30) | ||
37 | xmpyu %fr22L,%fr11R,%fr8 | ||
38 | fldws -16(0,%r30),%fr22L | ||
39 | fstws %fr8R,-16(0,%r30) | ||
40 | xmpyu %fr11R,%fr22L,%fr10 | ||
41 | ldw -16(0,%r30),%r2 | ||
42 | stw %r20,-16(0,%r30) | ||
43 | xmpyu %fr22L,%fr11L,%fr9 | ||
44 | fldws -16(0,%r30),%fr22L | ||
45 | fstws %fr10R,-16(0,%r30) | ||
46 | copy %r2,%r22 | ||
47 | ldw -16(0,%r30),%r2 | ||
48 | fstws %fr9R,-16(0,%r30) | ||
49 | xmpyu %fr11L,%fr22L,%fr8 | ||
50 | copy %r2,%r19 | ||
51 | ldw -16(0,%r30),%r2 | ||
52 | fstws %fr8R,-16(0,%r30) | ||
53 | copy %r2,%r20 | ||
54 | ldw -16(0,%r30),%r2 | ||
55 | addl %r2,%r19,%r21 | ||
56 | comclr,<<= %r19,%r21,0 | ||
57 | addl %r20,%r31,%r20 | ||
58 | L$0005 | ||
59 | extru %r21,15,16,%r19 | ||
60 | addl %r20,%r19,%r20 | ||
61 | zdep %r21,15,16,%r19 | ||
62 | addl %r22,%r19,%r22 | ||
63 | comclr,<<= %r19,%r22,0 | ||
64 | addi,tr 1,%r20,%r19 | ||
65 | copy %r20,%r19 | ||
66 | addl %r22,%r28,%r20 | ||
67 | comclr,<<= %r28,%r20,0 | ||
68 | addi 1,%r19,%r19 | ||
69 | ldw 0(0,%r26),%r28 | ||
70 | addl %r20,%r28,%r20 | ||
71 | comclr,<<= %r28,%r20,0 | ||
72 | addi,tr 1,%r19,%r28 | ||
73 | copy %r19,%r28 | ||
74 | addib,= -1,%r24,L$0003 | ||
75 | stw %r20,0(0,%r26) | ||
76 | ldw -8(0,%r29),%r19 | ||
77 | extru %r19,31,16,%r20 | ||
78 | stw %r20,-16(0,%r30) | ||
79 | extru %r19,15,16,%r19 | ||
80 | fldws -16(0,%r30),%fr22L | ||
81 | stw %r19,-16(0,%r30) | ||
82 | xmpyu %fr22L,%fr11R,%fr8 | ||
83 | fldws -16(0,%r30),%fr22L | ||
84 | fstws %fr8R,-16(0,%r30) | ||
85 | xmpyu %fr11R,%fr22L,%fr10 | ||
86 | ldw -16(0,%r30),%r2 | ||
87 | stw %r20,-16(0,%r30) | ||
88 | xmpyu %fr22L,%fr11L,%fr9 | ||
89 | fldws -16(0,%r30),%fr22L | ||
90 | fstws %fr10R,-16(0,%r30) | ||
91 | copy %r2,%r22 | ||
92 | ldw -16(0,%r30),%r2 | ||
93 | fstws %fr9R,-16(0,%r30) | ||
94 | xmpyu %fr11L,%fr22L,%fr8 | ||
95 | copy %r2,%r19 | ||
96 | ldw -16(0,%r30),%r2 | ||
97 | fstws %fr8R,-16(0,%r30) | ||
98 | copy %r2,%r20 | ||
99 | ldw -16(0,%r30),%r2 | ||
100 | addl %r2,%r19,%r21 | ||
101 | comclr,<<= %r19,%r21,0 | ||
102 | addl %r20,%r31,%r20 | ||
103 | L$0010 | ||
104 | extru %r21,15,16,%r19 | ||
105 | addl %r20,%r19,%r20 | ||
106 | zdep %r21,15,16,%r19 | ||
107 | addl %r22,%r19,%r22 | ||
108 | comclr,<<= %r19,%r22,0 | ||
109 | addi,tr 1,%r20,%r19 | ||
110 | copy %r20,%r19 | ||
111 | addl %r22,%r28,%r20 | ||
112 | comclr,<<= %r28,%r20,0 | ||
113 | addi 1,%r19,%r19 | ||
114 | ldw -8(0,%r23),%r28 | ||
115 | addl %r20,%r28,%r20 | ||
116 | comclr,<<= %r28,%r20,0 | ||
117 | addi,tr 1,%r19,%r28 | ||
118 | copy %r19,%r28 | ||
119 | addib,= -1,%r24,L$0003 | ||
120 | stw %r20,-8(0,%r23) | ||
121 | ldw -4(0,%r29),%r19 | ||
122 | extru %r19,31,16,%r20 | ||
123 | stw %r20,-16(0,%r30) | ||
124 | extru %r19,15,16,%r19 | ||
125 | fldws -16(0,%r30),%fr22L | ||
126 | stw %r19,-16(0,%r30) | ||
127 | xmpyu %fr22L,%fr11R,%fr8 | ||
128 | fldws -16(0,%r30),%fr22L | ||
129 | fstws %fr8R,-16(0,%r30) | ||
130 | xmpyu %fr11R,%fr22L,%fr10 | ||
131 | ldw -16(0,%r30),%r2 | ||
132 | stw %r20,-16(0,%r30) | ||
133 | xmpyu %fr22L,%fr11L,%fr9 | ||
134 | fldws -16(0,%r30),%fr22L | ||
135 | fstws %fr10R,-16(0,%r30) | ||
136 | copy %r2,%r22 | ||
137 | ldw -16(0,%r30),%r2 | ||
138 | fstws %fr9R,-16(0,%r30) | ||
139 | xmpyu %fr11L,%fr22L,%fr8 | ||
140 | copy %r2,%r19 | ||
141 | ldw -16(0,%r30),%r2 | ||
142 | fstws %fr8R,-16(0,%r30) | ||
143 | copy %r2,%r20 | ||
144 | ldw -16(0,%r30),%r2 | ||
145 | addl %r2,%r19,%r21 | ||
146 | comclr,<<= %r19,%r21,0 | ||
147 | addl %r20,%r31,%r20 | ||
148 | L$0015 | ||
149 | extru %r21,15,16,%r19 | ||
150 | addl %r20,%r19,%r20 | ||
151 | zdep %r21,15,16,%r19 | ||
152 | addl %r22,%r19,%r22 | ||
153 | comclr,<<= %r19,%r22,0 | ||
154 | addi,tr 1,%r20,%r19 | ||
155 | copy %r20,%r19 | ||
156 | addl %r22,%r28,%r20 | ||
157 | comclr,<<= %r28,%r20,0 | ||
158 | addi 1,%r19,%r19 | ||
159 | ldw -4(0,%r23),%r28 | ||
160 | addl %r20,%r28,%r20 | ||
161 | comclr,<<= %r28,%r20,0 | ||
162 | addi,tr 1,%r19,%r28 | ||
163 | copy %r19,%r28 | ||
164 | addib,= -1,%r24,L$0003 | ||
165 | stw %r20,-4(0,%r23) | ||
166 | ldw 0(0,%r29),%r19 | ||
167 | extru %r19,31,16,%r20 | ||
168 | stw %r20,-16(0,%r30) | ||
169 | extru %r19,15,16,%r19 | ||
170 | fldws -16(0,%r30),%fr22L | ||
171 | stw %r19,-16(0,%r30) | ||
172 | xmpyu %fr22L,%fr11R,%fr8 | ||
173 | fldws -16(0,%r30),%fr22L | ||
174 | fstws %fr8R,-16(0,%r30) | ||
175 | xmpyu %fr11R,%fr22L,%fr10 | ||
176 | ldw -16(0,%r30),%r2 | ||
177 | stw %r20,-16(0,%r30) | ||
178 | xmpyu %fr22L,%fr11L,%fr9 | ||
179 | fldws -16(0,%r30),%fr22L | ||
180 | fstws %fr10R,-16(0,%r30) | ||
181 | copy %r2,%r22 | ||
182 | ldw -16(0,%r30),%r2 | ||
183 | fstws %fr9R,-16(0,%r30) | ||
184 | xmpyu %fr11L,%fr22L,%fr8 | ||
185 | copy %r2,%r19 | ||
186 | ldw -16(0,%r30),%r2 | ||
187 | fstws %fr8R,-16(0,%r30) | ||
188 | copy %r2,%r20 | ||
189 | ldw -16(0,%r30),%r2 | ||
190 | addl %r2,%r19,%r21 | ||
191 | comclr,<<= %r19,%r21,0 | ||
192 | addl %r20,%r31,%r20 | ||
193 | L$0020 | ||
194 | extru %r21,15,16,%r19 | ||
195 | addl %r20,%r19,%r20 | ||
196 | zdep %r21,15,16,%r19 | ||
197 | addl %r22,%r19,%r22 | ||
198 | comclr,<<= %r19,%r22,0 | ||
199 | addi,tr 1,%r20,%r19 | ||
200 | copy %r20,%r19 | ||
201 | addl %r22,%r28,%r20 | ||
202 | comclr,<<= %r28,%r20,0 | ||
203 | addi 1,%r19,%r19 | ||
204 | ldw 0(0,%r23),%r28 | ||
205 | addl %r20,%r28,%r20 | ||
206 | comclr,<<= %r28,%r20,0 | ||
207 | addi,tr 1,%r19,%r28 | ||
208 | copy %r19,%r28 | ||
209 | addib,= -1,%r24,L$0003 | ||
210 | stw %r20,0(0,%r23) | ||
211 | ldo 16(%r29),%r29 | ||
212 | ldo 16(%r25),%r25 | ||
213 | ldo 16(%r23),%r23 | ||
214 | bl L$0002,0 | ||
215 | ldo 16(%r26),%r26 | ||
216 | L$0003 | ||
217 | ldw -20(0,%r30),%r2 | ||
218 | bv,n 0(%r2) | ||
219 | .EXIT | ||
220 | .PROCEND | ||
221 | .align 4 | ||
222 | .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR | ||
223 | bn_mul_words | ||
224 | .PROC | ||
225 | .CALLINFO FRAME=0,CALLS,SAVE_RP | ||
226 | .ENTRY | ||
227 | stw %r2,-20(0,%r30) | ||
228 | ldi 0,%r28 | ||
229 | extru %r23,31,16,%r2 | ||
230 | stw %r2,-16(0,%r30) | ||
231 | extru %r23,15,16,%r23 | ||
232 | ldil L'65536,%r31 | ||
233 | fldws -16(0,%r30),%fr11R | ||
234 | stw %r23,-16(0,%r30) | ||
235 | ldo 12(%r26),%r29 | ||
236 | ldo 12(%r25),%r23 | ||
237 | fldws -16(0,%r30),%fr11L | ||
238 | L$0026 | ||
239 | ldw 0(0,%r25),%r19 | ||
240 | extru %r19,31,16,%r20 | ||
241 | stw %r20,-16(0,%r30) | ||
242 | extru %r19,15,16,%r19 | ||
243 | fldws -16(0,%r30),%fr22L | ||
244 | stw %r19,-16(0,%r30) | ||
245 | xmpyu %fr22L,%fr11R,%fr8 | ||
246 | fldws -16(0,%r30),%fr22L | ||
247 | fstws %fr8R,-16(0,%r30) | ||
248 | xmpyu %fr11R,%fr22L,%fr10 | ||
249 | ldw -16(0,%r30),%r2 | ||
250 | stw %r20,-16(0,%r30) | ||
251 | xmpyu %fr22L,%fr11L,%fr9 | ||
252 | fldws -16(0,%r30),%fr22L | ||
253 | fstws %fr10R,-16(0,%r30) | ||
254 | copy %r2,%r22 | ||
255 | ldw -16(0,%r30),%r2 | ||
256 | fstws %fr9R,-16(0,%r30) | ||
257 | xmpyu %fr11L,%fr22L,%fr8 | ||
258 | copy %r2,%r19 | ||
259 | ldw -16(0,%r30),%r2 | ||
260 | fstws %fr8R,-16(0,%r30) | ||
261 | copy %r2,%r20 | ||
262 | ldw -16(0,%r30),%r2 | ||
263 | addl %r2,%r19,%r21 | ||
264 | comclr,<<= %r19,%r21,0 | ||
265 | addl %r20,%r31,%r20 | ||
266 | L$0029 | ||
267 | extru %r21,15,16,%r19 | ||
268 | addl %r20,%r19,%r20 | ||
269 | zdep %r21,15,16,%r19 | ||
270 | addl %r22,%r19,%r22 | ||
271 | comclr,<<= %r19,%r22,0 | ||
272 | addi,tr 1,%r20,%r19 | ||
273 | copy %r20,%r19 | ||
274 | addl %r22,%r28,%r20 | ||
275 | comclr,<<= %r28,%r20,0 | ||
276 | addi,tr 1,%r19,%r28 | ||
277 | copy %r19,%r28 | ||
278 | addib,= -1,%r24,L$0027 | ||
279 | stw %r20,0(0,%r26) | ||
280 | ldw -8(0,%r23),%r19 | ||
281 | extru %r19,31,16,%r20 | ||
282 | stw %r20,-16(0,%r30) | ||
283 | extru %r19,15,16,%r19 | ||
284 | fldws -16(0,%r30),%fr22L | ||
285 | stw %r19,-16(0,%r30) | ||
286 | xmpyu %fr22L,%fr11R,%fr8 | ||
287 | fldws -16(0,%r30),%fr22L | ||
288 | fstws %fr8R,-16(0,%r30) | ||
289 | xmpyu %fr11R,%fr22L,%fr10 | ||
290 | ldw -16(0,%r30),%r2 | ||
291 | stw %r20,-16(0,%r30) | ||
292 | xmpyu %fr22L,%fr11L,%fr9 | ||
293 | fldws -16(0,%r30),%fr22L | ||
294 | fstws %fr10R,-16(0,%r30) | ||
295 | copy %r2,%r22 | ||
296 | ldw -16(0,%r30),%r2 | ||
297 | fstws %fr9R,-16(0,%r30) | ||
298 | xmpyu %fr11L,%fr22L,%fr8 | ||
299 | copy %r2,%r19 | ||
300 | ldw -16(0,%r30),%r2 | ||
301 | fstws %fr8R,-16(0,%r30) | ||
302 | copy %r2,%r20 | ||
303 | ldw -16(0,%r30),%r2 | ||
304 | addl %r2,%r19,%r21 | ||
305 | comclr,<<= %r19,%r21,0 | ||
306 | addl %r20,%r31,%r20 | ||
307 | L$0033 | ||
308 | extru %r21,15,16,%r19 | ||
309 | addl %r20,%r19,%r20 | ||
310 | zdep %r21,15,16,%r19 | ||
311 | addl %r22,%r19,%r22 | ||
312 | comclr,<<= %r19,%r22,0 | ||
313 | addi,tr 1,%r20,%r19 | ||
314 | copy %r20,%r19 | ||
315 | addl %r22,%r28,%r20 | ||
316 | comclr,<<= %r28,%r20,0 | ||
317 | addi,tr 1,%r19,%r28 | ||
318 | copy %r19,%r28 | ||
319 | addib,= -1,%r24,L$0027 | ||
320 | stw %r20,-8(0,%r29) | ||
321 | ldw -4(0,%r23),%r19 | ||
322 | extru %r19,31,16,%r20 | ||
323 | stw %r20,-16(0,%r30) | ||
324 | extru %r19,15,16,%r19 | ||
325 | fldws -16(0,%r30),%fr22L | ||
326 | stw %r19,-16(0,%r30) | ||
327 | xmpyu %fr22L,%fr11R,%fr8 | ||
328 | fldws -16(0,%r30),%fr22L | ||
329 | fstws %fr8R,-16(0,%r30) | ||
330 | xmpyu %fr11R,%fr22L,%fr10 | ||
331 | ldw -16(0,%r30),%r2 | ||
332 | stw %r20,-16(0,%r30) | ||
333 | xmpyu %fr22L,%fr11L,%fr9 | ||
334 | fldws -16(0,%r30),%fr22L | ||
335 | fstws %fr10R,-16(0,%r30) | ||
336 | copy %r2,%r22 | ||
337 | ldw -16(0,%r30),%r2 | ||
338 | fstws %fr9R,-16(0,%r30) | ||
339 | xmpyu %fr11L,%fr22L,%fr8 | ||
340 | copy %r2,%r19 | ||
341 | ldw -16(0,%r30),%r2 | ||
342 | fstws %fr8R,-16(0,%r30) | ||
343 | copy %r2,%r20 | ||
344 | ldw -16(0,%r30),%r2 | ||
345 | addl %r2,%r19,%r21 | ||
346 | comclr,<<= %r19,%r21,0 | ||
347 | addl %r20,%r31,%r20 | ||
348 | L$0037 | ||
349 | extru %r21,15,16,%r19 | ||
350 | addl %r20,%r19,%r20 | ||
351 | zdep %r21,15,16,%r19 | ||
352 | addl %r22,%r19,%r22 | ||
353 | comclr,<<= %r19,%r22,0 | ||
354 | addi,tr 1,%r20,%r19 | ||
355 | copy %r20,%r19 | ||
356 | addl %r22,%r28,%r20 | ||
357 | comclr,<<= %r28,%r20,0 | ||
358 | addi,tr 1,%r19,%r28 | ||
359 | copy %r19,%r28 | ||
360 | addib,= -1,%r24,L$0027 | ||
361 | stw %r20,-4(0,%r29) | ||
362 | ldw 0(0,%r23),%r19 | ||
363 | extru %r19,31,16,%r20 | ||
364 | stw %r20,-16(0,%r30) | ||
365 | extru %r19,15,16,%r19 | ||
366 | fldws -16(0,%r30),%fr22L | ||
367 | stw %r19,-16(0,%r30) | ||
368 | xmpyu %fr22L,%fr11R,%fr8 | ||
369 | fldws -16(0,%r30),%fr22L | ||
370 | fstws %fr8R,-16(0,%r30) | ||
371 | xmpyu %fr11R,%fr22L,%fr10 | ||
372 | ldw -16(0,%r30),%r2 | ||
373 | stw %r20,-16(0,%r30) | ||
374 | xmpyu %fr22L,%fr11L,%fr9 | ||
375 | fldws -16(0,%r30),%fr22L | ||
376 | fstws %fr10R,-16(0,%r30) | ||
377 | copy %r2,%r22 | ||
378 | ldw -16(0,%r30),%r2 | ||
379 | fstws %fr9R,-16(0,%r30) | ||
380 | xmpyu %fr11L,%fr22L,%fr8 | ||
381 | copy %r2,%r19 | ||
382 | ldw -16(0,%r30),%r2 | ||
383 | fstws %fr8R,-16(0,%r30) | ||
384 | copy %r2,%r20 | ||
385 | ldw -16(0,%r30),%r2 | ||
386 | addl %r2,%r19,%r21 | ||
387 | comclr,<<= %r19,%r21,0 | ||
388 | addl %r20,%r31,%r20 | ||
389 | L$0041 | ||
390 | extru %r21,15,16,%r19 | ||
391 | addl %r20,%r19,%r20 | ||
392 | zdep %r21,15,16,%r19 | ||
393 | addl %r22,%r19,%r22 | ||
394 | comclr,<<= %r19,%r22,0 | ||
395 | addi,tr 1,%r20,%r19 | ||
396 | copy %r20,%r19 | ||
397 | addl %r22,%r28,%r20 | ||
398 | comclr,<<= %r28,%r20,0 | ||
399 | addi,tr 1,%r19,%r28 | ||
400 | copy %r19,%r28 | ||
401 | addib,= -1,%r24,L$0027 | ||
402 | stw %r20,0(0,%r29) | ||
403 | ldo 16(%r23),%r23 | ||
404 | ldo 16(%r25),%r25 | ||
405 | ldo 16(%r29),%r29 | ||
406 | bl L$0026,0 | ||
407 | ldo 16(%r26),%r26 | ||
408 | L$0027 | ||
409 | ldw -20(0,%r30),%r2 | ||
410 | bv,n 0(%r2) | ||
411 | .EXIT | ||
412 | .PROCEND | ||
413 | .align 4 | ||
414 | .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR | ||
415 | bn_sqr_words | ||
416 | .PROC | ||
417 | .CALLINFO FRAME=0,NO_CALLS | ||
418 | .ENTRY | ||
419 | ldo 28(%r26),%r23 | ||
420 | ldo 12(%r25),%r28 | ||
421 | L$0046 | ||
422 | ldw 0(0,%r25),%r21 | ||
423 | extru %r21,31,16,%r22 | ||
424 | stw %r22,-16(0,%r30) | ||
425 | extru %r21,15,16,%r21 | ||
426 | fldws -16(0,%r30),%fr10L | ||
427 | stw %r21,-16(0,%r30) | ||
428 | fldws -16(0,%r30),%fr10R | ||
429 | xmpyu %fr10L,%fr10R,%fr8 | ||
430 | fstws %fr8R,-16(0,%r30) | ||
431 | ldw -16(0,%r30),%r29 | ||
432 | stw %r22,-16(0,%r30) | ||
433 | fldws -16(0,%r30),%fr10R | ||
434 | stw %r21,-16(0,%r30) | ||
435 | copy %r29,%r19 | ||
436 | xmpyu %fr10L,%fr10R,%fr8 | ||
437 | fldws -16(0,%r30),%fr10L | ||
438 | stw %r21,-16(0,%r30) | ||
439 | fldws -16(0,%r30),%fr10R | ||
440 | fstws %fr8R,-16(0,%r30) | ||
441 | extru %r19,16,17,%r20 | ||
442 | zdep %r19,14,15,%r19 | ||
443 | ldw -16(0,%r30),%r29 | ||
444 | xmpyu %fr10L,%fr10R,%fr9 | ||
445 | addl %r29,%r19,%r22 | ||
446 | stw %r22,0(0,%r26) | ||
447 | fstws %fr9R,-16(0,%r30) | ||
448 | ldw -16(0,%r30),%r29 | ||
449 | addl %r29,%r20,%r21 | ||
450 | comclr,<<= %r19,%r22,0 | ||
451 | addi 1,%r21,%r21 | ||
452 | addib,= -1,%r24,L$0057 | ||
453 | stw %r21,-24(0,%r23) | ||
454 | ldw -8(0,%r28),%r21 | ||
455 | extru %r21,31,16,%r22 | ||
456 | stw %r22,-16(0,%r30) | ||
457 | extru %r21,15,16,%r21 | ||
458 | fldws -16(0,%r30),%fr10L | ||
459 | stw %r21,-16(0,%r30) | ||
460 | fldws -16(0,%r30),%fr10R | ||
461 | xmpyu %fr10L,%fr10R,%fr8 | ||
462 | fstws %fr8R,-16(0,%r30) | ||
463 | ldw -16(0,%r30),%r29 | ||
464 | stw %r22,-16(0,%r30) | ||
465 | fldws -16(0,%r30),%fr10R | ||
466 | stw %r21,-16(0,%r30) | ||
467 | copy %r29,%r19 | ||
468 | xmpyu %fr10L,%fr10R,%fr8 | ||
469 | fldws -16(0,%r30),%fr10L | ||
470 | stw %r21,-16(0,%r30) | ||
471 | fldws -16(0,%r30),%fr10R | ||
472 | fstws %fr8R,-16(0,%r30) | ||
473 | extru %r19,16,17,%r20 | ||
474 | zdep %r19,14,15,%r19 | ||
475 | ldw -16(0,%r30),%r29 | ||
476 | xmpyu %fr10L,%fr10R,%fr9 | ||
477 | addl %r29,%r19,%r22 | ||
478 | stw %r22,-20(0,%r23) | ||
479 | fstws %fr9R,-16(0,%r30) | ||
480 | ldw -16(0,%r30),%r29 | ||
481 | addl %r29,%r20,%r21 | ||
482 | comclr,<<= %r19,%r22,0 | ||
483 | addi 1,%r21,%r21 | ||
484 | addib,= -1,%r24,L$0057 | ||
485 | stw %r21,-16(0,%r23) | ||
486 | ldw -4(0,%r28),%r21 | ||
487 | extru %r21,31,16,%r22 | ||
488 | stw %r22,-16(0,%r30) | ||
489 | extru %r21,15,16,%r21 | ||
490 | fldws -16(0,%r30),%fr10L | ||
491 | stw %r21,-16(0,%r30) | ||
492 | fldws -16(0,%r30),%fr10R | ||
493 | xmpyu %fr10L,%fr10R,%fr8 | ||
494 | fstws %fr8R,-16(0,%r30) | ||
495 | ldw -16(0,%r30),%r29 | ||
496 | stw %r22,-16(0,%r30) | ||
497 | fldws -16(0,%r30),%fr10R | ||
498 | stw %r21,-16(0,%r30) | ||
499 | copy %r29,%r19 | ||
500 | xmpyu %fr10L,%fr10R,%fr8 | ||
501 | fldws -16(0,%r30),%fr10L | ||
502 | stw %r21,-16(0,%r30) | ||
503 | fldws -16(0,%r30),%fr10R | ||
504 | fstws %fr8R,-16(0,%r30) | ||
505 | extru %r19,16,17,%r20 | ||
506 | zdep %r19,14,15,%r19 | ||
507 | ldw -16(0,%r30),%r29 | ||
508 | xmpyu %fr10L,%fr10R,%fr9 | ||
509 | addl %r29,%r19,%r22 | ||
510 | stw %r22,-12(0,%r23) | ||
511 | fstws %fr9R,-16(0,%r30) | ||
512 | ldw -16(0,%r30),%r29 | ||
513 | addl %r29,%r20,%r21 | ||
514 | comclr,<<= %r19,%r22,0 | ||
515 | addi 1,%r21,%r21 | ||
516 | addib,= -1,%r24,L$0057 | ||
517 | stw %r21,-8(0,%r23) | ||
518 | ldw 0(0,%r28),%r21 | ||
519 | extru %r21,31,16,%r22 | ||
520 | stw %r22,-16(0,%r30) | ||
521 | extru %r21,15,16,%r21 | ||
522 | fldws -16(0,%r30),%fr10L | ||
523 | stw %r21,-16(0,%r30) | ||
524 | fldws -16(0,%r30),%fr10R | ||
525 | xmpyu %fr10L,%fr10R,%fr8 | ||
526 | fstws %fr8R,-16(0,%r30) | ||
527 | ldw -16(0,%r30),%r29 | ||
528 | stw %r22,-16(0,%r30) | ||
529 | fldws -16(0,%r30),%fr10R | ||
530 | stw %r21,-16(0,%r30) | ||
531 | copy %r29,%r19 | ||
532 | xmpyu %fr10L,%fr10R,%fr8 | ||
533 | fldws -16(0,%r30),%fr10L | ||
534 | stw %r21,-16(0,%r30) | ||
535 | fldws -16(0,%r30),%fr10R | ||
536 | fstws %fr8R,-16(0,%r30) | ||
537 | extru %r19,16,17,%r20 | ||
538 | zdep %r19,14,15,%r19 | ||
539 | ldw -16(0,%r30),%r29 | ||
540 | xmpyu %fr10L,%fr10R,%fr9 | ||
541 | addl %r29,%r19,%r22 | ||
542 | stw %r22,-4(0,%r23) | ||
543 | fstws %fr9R,-16(0,%r30) | ||
544 | ldw -16(0,%r30),%r29 | ||
545 | addl %r29,%r20,%r21 | ||
546 | comclr,<<= %r19,%r22,0 | ||
547 | addi 1,%r21,%r21 | ||
548 | addib,= -1,%r24,L$0057 | ||
549 | stw %r21,0(0,%r23) | ||
550 | ldo 16(%r28),%r28 | ||
551 | ldo 16(%r25),%r25 | ||
552 | ldo 32(%r23),%r23 | ||
553 | bl L$0046,0 | ||
554 | ldo 32(%r26),%r26 | ||
555 | L$0057 | ||
556 | bv,n 0(%r2) | ||
557 | .EXIT | ||
558 | .PROCEND | ||
559 | .IMPORT BN_num_bits_word,CODE | ||
560 | .IMPORT fprintf,CODE | ||
561 | .IMPORT __iob,DATA | ||
562 | .SPACE $TEXT$ | ||
563 | .SUBSPA $LIT$ | ||
564 | |||
565 | .align 4 | ||
566 | L$C0000 | ||
567 | .STRING "Division would overflow\x0a\x00" | ||
568 | .IMPORT abort,CODE | ||
569 | .SPACE $TEXT$ | ||
570 | .SUBSPA $CODE$ | ||
571 | |||
572 | .align 4 | ||
573 | .EXPORT bn_div64,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR | ||
574 | bn_div64 | ||
575 | .PROC | ||
576 | .CALLINFO FRAME=128,CALLS,SAVE_RP,ENTRY_GR=8 | ||
577 | .ENTRY | ||
578 | stw %r2,-20(0,%r30) | ||
579 | stwm %r8,128(0,%r30) | ||
580 | stw %r7,-124(0,%r30) | ||
581 | stw %r4,-112(0,%r30) | ||
582 | stw %r3,-108(0,%r30) | ||
583 | copy %r26,%r3 | ||
584 | copy %r25,%r4 | ||
585 | stw %r6,-120(0,%r30) | ||
586 | ldi 0,%r7 | ||
587 | stw %r5,-116(0,%r30) | ||
588 | movb,<> %r24,%r5,L$0059 | ||
589 | ldi 2,%r6 | ||
590 | bl L$0076,0 | ||
591 | ldi -1,%r28 | ||
592 | L$0059 | ||
593 | .CALL ARGW0=GR | ||
594 | bl BN_num_bits_word,%r2 | ||
595 | copy %r5,%r26 | ||
596 | ldi 32,%r19 | ||
597 | comb,= %r19,%r28,L$0060 | ||
598 | subi 31,%r28,%r19 | ||
599 | mtsar %r19 | ||
600 | zvdepi 1,32,%r19 | ||
601 | comb,>>= %r19,%r3,L$0060 | ||
602 | addil LR'__iob-$global$+32,%r27 | ||
603 | ldo RR'__iob-$global$+32(%r1),%r26 | ||
604 | ldil LR'L$C0000,%r25 | ||
605 | .CALL ARGW0=GR,ARGW1=GR | ||
606 | bl fprintf,%r2 | ||
607 | ldo RR'L$C0000(%r25),%r25 | ||
608 | .CALL | ||
609 | bl abort,%r2 | ||
610 | nop | ||
611 | L$0060 | ||
612 | comb,>> %r5,%r3,L$0061 | ||
613 | subi 32,%r28,%r28 | ||
614 | sub %r3,%r5,%r3 | ||
615 | L$0061 | ||
616 | comib,= 0,%r28,L$0062 | ||
617 | subi 31,%r28,%r19 | ||
618 | mtsar %r19 | ||
619 | zvdep %r5,32,%r5 | ||
620 | zvdep %r3,32,%r21 | ||
621 | subi 32,%r28,%r20 | ||
622 | mtsar %r20 | ||
623 | vshd 0,%r4,%r20 | ||
624 | or %r21,%r20,%r3 | ||
625 | mtsar %r19 | ||
626 | zvdep %r4,32,%r4 | ||
627 | L$0062 | ||
628 | extru %r5,15,16,%r23 | ||
629 | extru %r5,31,16,%r28 | ||
630 | L$0063 | ||
631 | extru %r3,15,16,%r19 | ||
632 | comb,<> %r23,%r19,L$0066 | ||
633 | copy %r3,%r26 | ||
634 | bl L$0067,0 | ||
635 | zdepi -1,31,16,%r29 | ||
636 | L$0066 | ||
637 | .IMPORT $$divU,MILLICODE | ||
638 | bl $$divU,%r31 | ||
639 | copy %r23,%r25 | ||
640 | L$0067 | ||
641 | stw %r29,-16(0,%r30) | ||
642 | fldws -16(0,%r30),%fr10L | ||
643 | stw %r28,-16(0,%r30) | ||
644 | fldws -16(0,%r30),%fr10R | ||
645 | stw %r23,-16(0,%r30) | ||
646 | xmpyu %fr10L,%fr10R,%fr8 | ||
647 | fldws -16(0,%r30),%fr10R | ||
648 | fstws %fr8R,-16(0,%r30) | ||
649 | xmpyu %fr10L,%fr10R,%fr9 | ||
650 | ldw -16(0,%r30),%r8 | ||
651 | fstws %fr9R,-16(0,%r30) | ||
652 | copy %r8,%r22 | ||
653 | ldw -16(0,%r30),%r8 | ||
654 | extru %r4,15,16,%r24 | ||
655 | copy %r8,%r21 | ||
656 | L$0068 | ||
657 | sub %r3,%r21,%r20 | ||
658 | copy %r20,%r19 | ||
659 | depi 0,31,16,%r19 | ||
660 | comib,<> 0,%r19,L$0069 | ||
661 | zdep %r20,15,16,%r19 | ||
662 | addl %r19,%r24,%r19 | ||
663 | comb,>>= %r19,%r22,L$0069 | ||
664 | sub %r22,%r28,%r22 | ||
665 | sub %r21,%r23,%r21 | ||
666 | bl L$0068,0 | ||
667 | ldo -1(%r29),%r29 | ||
668 | L$0069 | ||
669 | stw %r29,-16(0,%r30) | ||
670 | fldws -16(0,%r30),%fr10L | ||
671 | stw %r28,-16(0,%r30) | ||
672 | fldws -16(0,%r30),%fr10R | ||
673 | xmpyu %fr10L,%fr10R,%fr8 | ||
674 | fstws %fr8R,-16(0,%r30) | ||
675 | ldw -16(0,%r30),%r8 | ||
676 | stw %r23,-16(0,%r30) | ||
677 | fldws -16(0,%r30),%fr10R | ||
678 | copy %r8,%r19 | ||
679 | xmpyu %fr10L,%fr10R,%fr8 | ||
680 | fstws %fr8R,-16(0,%r30) | ||
681 | extru %r19,15,16,%r20 | ||
682 | ldw -16(0,%r30),%r8 | ||
683 | zdep %r19,15,16,%r19 | ||
684 | addl %r8,%r20,%r20 | ||
685 | comclr,<<= %r19,%r4,0 | ||
686 | addi 1,%r20,%r20 | ||
687 | comb,<<= %r20,%r3,L$0074 | ||
688 | sub %r4,%r19,%r4 | ||
689 | addl %r3,%r5,%r3 | ||
690 | ldo -1(%r29),%r29 | ||
691 | L$0074 | ||
692 | addib,= -1,%r6,L$0064 | ||
693 | sub %r3,%r20,%r3 | ||
694 | zdep %r29,15,16,%r7 | ||
695 | shd %r3,%r4,16,%r3 | ||
696 | bl L$0063,0 | ||
697 | zdep %r4,15,16,%r4 | ||
698 | L$0064 | ||
699 | or %r7,%r29,%r28 | ||
700 | L$0076 | ||
701 | ldw -148(0,%r30),%r2 | ||
702 | ldw -124(0,%r30),%r7 | ||
703 | ldw -120(0,%r30),%r6 | ||
704 | ldw -116(0,%r30),%r5 | ||
705 | ldw -112(0,%r30),%r4 | ||
706 | ldw -108(0,%r30),%r3 | ||
707 | bv 0(%r2) | ||
708 | ldwm -128(0,%r30),%r8 | ||
709 | .EXIT | ||
710 | .PROCEND | ||
diff --git a/src/lib/libcrypto/bn/asm/r3000.s b/src/lib/libcrypto/bn/asm/r3000.s new file mode 100644 index 0000000000..e95269afa3 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/r3000.s | |||
@@ -0,0 +1,646 @@ | |||
1 | .file 1 "../bn_mulw.c" | ||
2 | .set nobopt | ||
3 | .option pic2 | ||
4 | |||
5 | # GNU C 2.6.3 [AL 1.1, MM 40] SGI running IRIX 5.0 compiled by GNU C | ||
6 | |||
7 | # Cc1 defaults: | ||
8 | # -mabicalls | ||
9 | |||
10 | # Cc1 arguments (-G value = 0, Cpu = 3000, ISA = 1): | ||
11 | # -quiet -dumpbase -O2 -o | ||
12 | |||
13 | gcc2_compiled.: | ||
14 | __gnu_compiled_c: | ||
15 | .rdata | ||
16 | |||
17 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
18 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x39,0x20 | ||
19 | .byte 0x24,0x0 | ||
20 | |||
21 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
22 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x33,0x34,0x20 | ||
23 | .byte 0x24,0x0 | ||
24 | |||
25 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
26 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x35,0x20,0x24 | ||
27 | .byte 0x0 | ||
28 | |||
29 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
30 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24 | ||
31 | .byte 0x0 | ||
32 | |||
33 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
34 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x33,0x20 | ||
35 | .byte 0x24,0x0 | ||
36 | |||
37 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
38 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x37,0x38,0x20 | ||
39 | .byte 0x24,0x0 | ||
40 | |||
41 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
42 | .byte 0x6e,0x3a,0x20,0x33,0x2e,0x37,0x30,0x20 | ||
43 | .byte 0x24,0x0 | ||
44 | |||
45 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
46 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x20,0x24 | ||
47 | .byte 0x0 | ||
48 | |||
49 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
50 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x20,0x24 | ||
51 | .byte 0x0 | ||
52 | |||
53 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
54 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24 | ||
55 | .byte 0x0 | ||
56 | .text | ||
57 | .align 2 | ||
58 | .globl bn_mul_add_words | ||
59 | .ent bn_mul_add_words | ||
60 | bn_mul_add_words: | ||
61 | .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0 | ||
62 | .mask 0x00000000,0 | ||
63 | .fmask 0x00000000,0 | ||
64 | .set noreorder | ||
65 | .cpload $25 | ||
66 | .set reorder | ||
67 | move $12,$4 | ||
68 | move $14,$5 | ||
69 | move $9,$6 | ||
70 | move $13,$7 | ||
71 | move $8,$0 | ||
72 | addu $10,$12,12 | ||
73 | addu $11,$14,12 | ||
74 | $L2: | ||
75 | lw $6,0($14) | ||
76 | #nop | ||
77 | multu $13,$6 | ||
78 | mfhi $6 | ||
79 | mflo $7 | ||
80 | #nop | ||
81 | move $5,$8 | ||
82 | move $4,$0 | ||
83 | lw $3,0($12) | ||
84 | addu $9,$9,-1 | ||
85 | move $2,$0 | ||
86 | addu $7,$7,$3 | ||
87 | sltu $8,$7,$3 | ||
88 | addu $6,$6,$2 | ||
89 | addu $6,$6,$8 | ||
90 | addu $7,$7,$5 | ||
91 | sltu $2,$7,$5 | ||
92 | addu $6,$6,$4 | ||
93 | addu $6,$6,$2 | ||
94 | srl $3,$6,0 | ||
95 | move $2,$0 | ||
96 | move $8,$3 | ||
97 | .set noreorder | ||
98 | .set nomacro | ||
99 | beq $9,$0,$L3 | ||
100 | sw $7,0($12) | ||
101 | .set macro | ||
102 | .set reorder | ||
103 | |||
104 | lw $6,-8($11) | ||
105 | #nop | ||
106 | multu $13,$6 | ||
107 | mfhi $6 | ||
108 | mflo $7 | ||
109 | #nop | ||
110 | move $5,$8 | ||
111 | move $4,$0 | ||
112 | lw $3,-8($10) | ||
113 | addu $9,$9,-1 | ||
114 | move $2,$0 | ||
115 | addu $7,$7,$3 | ||
116 | sltu $8,$7,$3 | ||
117 | addu $6,$6,$2 | ||
118 | addu $6,$6,$8 | ||
119 | addu $7,$7,$5 | ||
120 | sltu $2,$7,$5 | ||
121 | addu $6,$6,$4 | ||
122 | addu $6,$6,$2 | ||
123 | srl $3,$6,0 | ||
124 | move $2,$0 | ||
125 | move $8,$3 | ||
126 | .set noreorder | ||
127 | .set nomacro | ||
128 | beq $9,$0,$L3 | ||
129 | sw $7,-8($10) | ||
130 | .set macro | ||
131 | .set reorder | ||
132 | |||
133 | lw $6,-4($11) | ||
134 | #nop | ||
135 | multu $13,$6 | ||
136 | mfhi $6 | ||
137 | mflo $7 | ||
138 | #nop | ||
139 | move $5,$8 | ||
140 | move $4,$0 | ||
141 | lw $3,-4($10) | ||
142 | addu $9,$9,-1 | ||
143 | move $2,$0 | ||
144 | addu $7,$7,$3 | ||
145 | sltu $8,$7,$3 | ||
146 | addu $6,$6,$2 | ||
147 | addu $6,$6,$8 | ||
148 | addu $7,$7,$5 | ||
149 | sltu $2,$7,$5 | ||
150 | addu $6,$6,$4 | ||
151 | addu $6,$6,$2 | ||
152 | srl $3,$6,0 | ||
153 | move $2,$0 | ||
154 | move $8,$3 | ||
155 | .set noreorder | ||
156 | .set nomacro | ||
157 | beq $9,$0,$L3 | ||
158 | sw $7,-4($10) | ||
159 | .set macro | ||
160 | .set reorder | ||
161 | |||
162 | lw $6,0($11) | ||
163 | #nop | ||
164 | multu $13,$6 | ||
165 | mfhi $6 | ||
166 | mflo $7 | ||
167 | #nop | ||
168 | move $5,$8 | ||
169 | move $4,$0 | ||
170 | lw $3,0($10) | ||
171 | addu $9,$9,-1 | ||
172 | move $2,$0 | ||
173 | addu $7,$7,$3 | ||
174 | sltu $8,$7,$3 | ||
175 | addu $6,$6,$2 | ||
176 | addu $6,$6,$8 | ||
177 | addu $7,$7,$5 | ||
178 | sltu $2,$7,$5 | ||
179 | addu $6,$6,$4 | ||
180 | addu $6,$6,$2 | ||
181 | srl $3,$6,0 | ||
182 | move $2,$0 | ||
183 | move $8,$3 | ||
184 | .set noreorder | ||
185 | .set nomacro | ||
186 | beq $9,$0,$L3 | ||
187 | sw $7,0($10) | ||
188 | .set macro | ||
189 | .set reorder | ||
190 | |||
191 | addu $11,$11,16 | ||
192 | addu $14,$14,16 | ||
193 | addu $10,$10,16 | ||
194 | .set noreorder | ||
195 | .set nomacro | ||
196 | j $L2 | ||
197 | addu $12,$12,16 | ||
198 | .set macro | ||
199 | .set reorder | ||
200 | |||
201 | $L3: | ||
202 | .set noreorder | ||
203 | .set nomacro | ||
204 | j $31 | ||
205 | move $2,$8 | ||
206 | .set macro | ||
207 | .set reorder | ||
208 | |||
209 | .end bn_mul_add_words | ||
210 | .align 2 | ||
211 | .globl bn_mul_words | ||
212 | .ent bn_mul_words | ||
213 | bn_mul_words: | ||
214 | .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0 | ||
215 | .mask 0x00000000,0 | ||
216 | .fmask 0x00000000,0 | ||
217 | .set noreorder | ||
218 | .cpload $25 | ||
219 | .set reorder | ||
220 | move $11,$4 | ||
221 | move $12,$5 | ||
222 | move $8,$6 | ||
223 | move $6,$0 | ||
224 | addu $10,$11,12 | ||
225 | addu $9,$12,12 | ||
226 | $L10: | ||
227 | lw $4,0($12) | ||
228 | #nop | ||
229 | multu $7,$4 | ||
230 | mfhi $4 | ||
231 | mflo $5 | ||
232 | #nop | ||
233 | move $3,$6 | ||
234 | move $2,$0 | ||
235 | addu $8,$8,-1 | ||
236 | addu $5,$5,$3 | ||
237 | sltu $6,$5,$3 | ||
238 | addu $4,$4,$2 | ||
239 | addu $4,$4,$6 | ||
240 | srl $3,$4,0 | ||
241 | move $2,$0 | ||
242 | move $6,$3 | ||
243 | .set noreorder | ||
244 | .set nomacro | ||
245 | beq $8,$0,$L11 | ||
246 | sw $5,0($11) | ||
247 | .set macro | ||
248 | .set reorder | ||
249 | |||
250 | lw $4,-8($9) | ||
251 | #nop | ||
252 | multu $7,$4 | ||
253 | mfhi $4 | ||
254 | mflo $5 | ||
255 | #nop | ||
256 | move $3,$6 | ||
257 | move $2,$0 | ||
258 | addu $8,$8,-1 | ||
259 | addu $5,$5,$3 | ||
260 | sltu $6,$5,$3 | ||
261 | addu $4,$4,$2 | ||
262 | addu $4,$4,$6 | ||
263 | srl $3,$4,0 | ||
264 | move $2,$0 | ||
265 | move $6,$3 | ||
266 | .set noreorder | ||
267 | .set nomacro | ||
268 | beq $8,$0,$L11 | ||
269 | sw $5,-8($10) | ||
270 | .set macro | ||
271 | .set reorder | ||
272 | |||
273 | lw $4,-4($9) | ||
274 | #nop | ||
275 | multu $7,$4 | ||
276 | mfhi $4 | ||
277 | mflo $5 | ||
278 | #nop | ||
279 | move $3,$6 | ||
280 | move $2,$0 | ||
281 | addu $8,$8,-1 | ||
282 | addu $5,$5,$3 | ||
283 | sltu $6,$5,$3 | ||
284 | addu $4,$4,$2 | ||
285 | addu $4,$4,$6 | ||
286 | srl $3,$4,0 | ||
287 | move $2,$0 | ||
288 | move $6,$3 | ||
289 | .set noreorder | ||
290 | .set nomacro | ||
291 | beq $8,$0,$L11 | ||
292 | sw $5,-4($10) | ||
293 | .set macro | ||
294 | .set reorder | ||
295 | |||
296 | lw $4,0($9) | ||
297 | #nop | ||
298 | multu $7,$4 | ||
299 | mfhi $4 | ||
300 | mflo $5 | ||
301 | #nop | ||
302 | move $3,$6 | ||
303 | move $2,$0 | ||
304 | addu $8,$8,-1 | ||
305 | addu $5,$5,$3 | ||
306 | sltu $6,$5,$3 | ||
307 | addu $4,$4,$2 | ||
308 | addu $4,$4,$6 | ||
309 | srl $3,$4,0 | ||
310 | move $2,$0 | ||
311 | move $6,$3 | ||
312 | .set noreorder | ||
313 | .set nomacro | ||
314 | beq $8,$0,$L11 | ||
315 | sw $5,0($10) | ||
316 | .set macro | ||
317 | .set reorder | ||
318 | |||
319 | addu $9,$9,16 | ||
320 | addu $12,$12,16 | ||
321 | addu $10,$10,16 | ||
322 | .set noreorder | ||
323 | .set nomacro | ||
324 | j $L10 | ||
325 | addu $11,$11,16 | ||
326 | .set macro | ||
327 | .set reorder | ||
328 | |||
329 | $L11: | ||
330 | .set noreorder | ||
331 | .set nomacro | ||
332 | j $31 | ||
333 | move $2,$6 | ||
334 | .set macro | ||
335 | .set reorder | ||
336 | |||
337 | .end bn_mul_words | ||
338 | .align 2 | ||
339 | .globl bn_sqr_words | ||
340 | .ent bn_sqr_words | ||
341 | bn_sqr_words: | ||
342 | .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0 | ||
343 | .mask 0x00000000,0 | ||
344 | .fmask 0x00000000,0 | ||
345 | .set noreorder | ||
346 | .cpload $25 | ||
347 | .set reorder | ||
348 | move $9,$4 | ||
349 | addu $7,$9,28 | ||
350 | addu $8,$5,12 | ||
351 | $L18: | ||
352 | lw $2,0($5) | ||
353 | #nop | ||
354 | multu $2,$2 | ||
355 | mfhi $2 | ||
356 | mflo $3 | ||
357 | #nop | ||
358 | addu $6,$6,-1 | ||
359 | sw $3,0($9) | ||
360 | srl $3,$2,0 | ||
361 | move $2,$0 | ||
362 | .set noreorder | ||
363 | .set nomacro | ||
364 | beq $6,$0,$L19 | ||
365 | sw $3,-24($7) | ||
366 | .set macro | ||
367 | .set reorder | ||
368 | |||
369 | lw $2,-8($8) | ||
370 | #nop | ||
371 | multu $2,$2 | ||
372 | mfhi $2 | ||
373 | mflo $3 | ||
374 | #nop | ||
375 | addu $6,$6,-1 | ||
376 | sw $3,-20($7) | ||
377 | srl $3,$2,0 | ||
378 | move $2,$0 | ||
379 | .set noreorder | ||
380 | .set nomacro | ||
381 | beq $6,$0,$L19 | ||
382 | sw $3,-16($7) | ||
383 | .set macro | ||
384 | .set reorder | ||
385 | |||
386 | lw $2,-4($8) | ||
387 | #nop | ||
388 | multu $2,$2 | ||
389 | mfhi $2 | ||
390 | mflo $3 | ||
391 | #nop | ||
392 | addu $6,$6,-1 | ||
393 | sw $3,-12($7) | ||
394 | srl $3,$2,0 | ||
395 | move $2,$0 | ||
396 | .set noreorder | ||
397 | .set nomacro | ||
398 | beq $6,$0,$L19 | ||
399 | sw $3,-8($7) | ||
400 | .set macro | ||
401 | .set reorder | ||
402 | |||
403 | lw $2,0($8) | ||
404 | #nop | ||
405 | multu $2,$2 | ||
406 | mfhi $2 | ||
407 | mflo $3 | ||
408 | #nop | ||
409 | addu $6,$6,-1 | ||
410 | sw $3,-4($7) | ||
411 | srl $3,$2,0 | ||
412 | move $2,$0 | ||
413 | .set noreorder | ||
414 | .set nomacro | ||
415 | beq $6,$0,$L19 | ||
416 | sw $3,0($7) | ||
417 | .set macro | ||
418 | .set reorder | ||
419 | |||
420 | addu $8,$8,16 | ||
421 | addu $5,$5,16 | ||
422 | addu $7,$7,32 | ||
423 | .set noreorder | ||
424 | .set nomacro | ||
425 | j $L18 | ||
426 | addu $9,$9,32 | ||
427 | .set macro | ||
428 | .set reorder | ||
429 | |||
430 | $L19: | ||
431 | j $31 | ||
432 | .end bn_sqr_words | ||
433 | .rdata | ||
434 | .align 2 | ||
435 | $LC0: | ||
436 | |||
437 | .byte 0x44,0x69,0x76,0x69,0x73,0x69,0x6f,0x6e | ||
438 | .byte 0x20,0x77,0x6f,0x75,0x6c,0x64,0x20,0x6f | ||
439 | .byte 0x76,0x65,0x72,0x66,0x6c,0x6f,0x77,0xa | ||
440 | .byte 0x0 | ||
441 | .text | ||
442 | .align 2 | ||
443 | .globl bn_div64 | ||
444 | .ent bn_div64 | ||
445 | bn_div64: | ||
446 | .frame $sp,56,$31 # vars= 0, regs= 7/0, args= 16, extra= 8 | ||
447 | .mask 0x901f0000,-8 | ||
448 | .fmask 0x00000000,0 | ||
449 | .set noreorder | ||
450 | .cpload $25 | ||
451 | .set reorder | ||
452 | subu $sp,$sp,56 | ||
453 | .cprestore 16 | ||
454 | sw $16,24($sp) | ||
455 | move $16,$4 | ||
456 | sw $17,28($sp) | ||
457 | move $17,$5 | ||
458 | sw $18,32($sp) | ||
459 | move $18,$6 | ||
460 | sw $20,40($sp) | ||
461 | move $20,$0 | ||
462 | sw $19,36($sp) | ||
463 | li $19,0x00000002 # 2 | ||
464 | sw $31,48($sp) | ||
465 | .set noreorder | ||
466 | .set nomacro | ||
467 | bne $18,$0,$L26 | ||
468 | sw $28,44($sp) | ||
469 | .set macro | ||
470 | .set reorder | ||
471 | |||
472 | .set noreorder | ||
473 | .set nomacro | ||
474 | j $L43 | ||
475 | li $2,-1 # 0xffffffff | ||
476 | .set macro | ||
477 | .set reorder | ||
478 | |||
479 | $L26: | ||
480 | move $4,$18 | ||
481 | jal BN_num_bits_word | ||
482 | move $4,$2 | ||
483 | li $2,0x00000020 # 32 | ||
484 | .set noreorder | ||
485 | .set nomacro | ||
486 | beq $4,$2,$L27 | ||
487 | li $2,0x00000001 # 1 | ||
488 | .set macro | ||
489 | .set reorder | ||
490 | |||
491 | sll $2,$2,$4 | ||
492 | sltu $2,$2,$16 | ||
493 | .set noreorder | ||
494 | .set nomacro | ||
495 | beq $2,$0,$L44 | ||
496 | li $5,0x00000020 # 32 | ||
497 | .set macro | ||
498 | .set reorder | ||
499 | |||
500 | la $4,__iob+32 | ||
501 | la $5,$LC0 | ||
502 | jal fprintf | ||
503 | jal abort | ||
504 | $L27: | ||
505 | li $5,0x00000020 # 32 | ||
506 | $L44: | ||
507 | sltu $2,$16,$18 | ||
508 | .set noreorder | ||
509 | .set nomacro | ||
510 | bne $2,$0,$L28 | ||
511 | subu $4,$5,$4 | ||
512 | .set macro | ||
513 | .set reorder | ||
514 | |||
515 | subu $16,$16,$18 | ||
516 | $L28: | ||
517 | .set noreorder | ||
518 | .set nomacro | ||
519 | beq $4,$0,$L29 | ||
520 | li $10,-65536 # 0xffff0000 | ||
521 | .set macro | ||
522 | .set reorder | ||
523 | |||
524 | sll $18,$18,$4 | ||
525 | sll $3,$16,$4 | ||
526 | subu $2,$5,$4 | ||
527 | srl $2,$17,$2 | ||
528 | or $16,$3,$2 | ||
529 | sll $17,$17,$4 | ||
530 | $L29: | ||
531 | srl $7,$18,16 | ||
532 | andi $9,$18,0xffff | ||
533 | $L30: | ||
534 | srl $2,$16,16 | ||
535 | .set noreorder | ||
536 | .set nomacro | ||
537 | beq $2,$7,$L34 | ||
538 | li $6,0x0000ffff # 65535 | ||
539 | .set macro | ||
540 | .set reorder | ||
541 | |||
542 | divu $6,$16,$7 | ||
543 | $L34: | ||
544 | mult $6,$9 | ||
545 | mflo $5 | ||
546 | #nop | ||
547 | #nop | ||
548 | mult $6,$7 | ||
549 | and $2,$17,$10 | ||
550 | srl $8,$2,16 | ||
551 | mflo $4 | ||
552 | $L35: | ||
553 | subu $3,$16,$4 | ||
554 | and $2,$3,$10 | ||
555 | .set noreorder | ||
556 | .set nomacro | ||
557 | bne $2,$0,$L36 | ||
558 | sll $2,$3,16 | ||
559 | .set macro | ||
560 | .set reorder | ||
561 | |||
562 | addu $2,$2,$8 | ||
563 | sltu $2,$2,$5 | ||
564 | .set noreorder | ||
565 | .set nomacro | ||
566 | beq $2,$0,$L36 | ||
567 | subu $5,$5,$9 | ||
568 | .set macro | ||
569 | .set reorder | ||
570 | |||
571 | subu $4,$4,$7 | ||
572 | .set noreorder | ||
573 | .set nomacro | ||
574 | j $L35 | ||
575 | addu $6,$6,-1 | ||
576 | .set macro | ||
577 | .set reorder | ||
578 | |||
579 | $L36: | ||
580 | mult $6,$7 | ||
581 | mflo $5 | ||
582 | #nop | ||
583 | #nop | ||
584 | mult $6,$9 | ||
585 | mflo $4 | ||
586 | #nop | ||
587 | #nop | ||
588 | srl $3,$4,16 | ||
589 | sll $2,$4,16 | ||
590 | and $4,$2,$10 | ||
591 | sltu $2,$17,$4 | ||
592 | .set noreorder | ||
593 | .set nomacro | ||
594 | beq $2,$0,$L40 | ||
595 | addu $5,$5,$3 | ||
596 | .set macro | ||
597 | .set reorder | ||
598 | |||
599 | addu $5,$5,1 | ||
600 | $L40: | ||
601 | sltu $2,$16,$5 | ||
602 | .set noreorder | ||
603 | .set nomacro | ||
604 | beq $2,$0,$L41 | ||
605 | subu $17,$17,$4 | ||
606 | .set macro | ||
607 | .set reorder | ||
608 | |||
609 | addu $16,$16,$18 | ||
610 | addu $6,$6,-1 | ||
611 | $L41: | ||
612 | addu $19,$19,-1 | ||
613 | .set noreorder | ||
614 | .set nomacro | ||
615 | beq $19,$0,$L31 | ||
616 | subu $16,$16,$5 | ||
617 | .set macro | ||
618 | .set reorder | ||
619 | |||
620 | sll $20,$6,16 | ||
621 | sll $3,$16,16 | ||
622 | srl $2,$17,16 | ||
623 | or $16,$3,$2 | ||
624 | .set noreorder | ||
625 | .set nomacro | ||
626 | j $L30 | ||
627 | sll $17,$17,16 | ||
628 | .set macro | ||
629 | .set reorder | ||
630 | |||
631 | $L31: | ||
632 | or $2,$20,$6 | ||
633 | $L43: | ||
634 | lw $31,48($sp) | ||
635 | lw $20,40($sp) | ||
636 | lw $19,36($sp) | ||
637 | lw $18,32($sp) | ||
638 | lw $17,28($sp) | ||
639 | lw $16,24($sp) | ||
640 | addu $sp,$sp,56 | ||
641 | j $31 | ||
642 | .end bn_div64 | ||
643 | |||
644 | .globl abort .text | ||
645 | .globl fprintf .text | ||
646 | .globl BN_num_bits_word .text | ||
diff --git a/src/lib/libcrypto/bn/bnspeed.c b/src/lib/libcrypto/bn/bnspeed.c new file mode 100644 index 0000000000..f7c2790fff --- /dev/null +++ b/src/lib/libcrypto/bn/bnspeed.c | |||
@@ -0,0 +1,248 @@ | |||
1 | /* crypto/bn/bnspeed.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 | /* most of this code has been pilfered from my libdes speed.c program */ | ||
60 | |||
61 | #define BASENUM 1000000 | ||
62 | #undef PROG | ||
63 | #define PROG bnspeed_main | ||
64 | |||
65 | #include <stdio.h> | ||
66 | #include <stdlib.h> | ||
67 | #include <signal.h> | ||
68 | #include <string.h> | ||
69 | #include "crypto.h" | ||
70 | #include "err.h" | ||
71 | |||
72 | #ifndef MSDOS | ||
73 | #define TIMES | ||
74 | #endif | ||
75 | |||
76 | #ifndef VMS | ||
77 | #ifndef _IRIX | ||
78 | #include <time.h> | ||
79 | #endif | ||
80 | #ifdef TIMES | ||
81 | #include <sys/types.h> | ||
82 | #include <sys/times.h> | ||
83 | #endif | ||
84 | #else /* VMS */ | ||
85 | #include <types.h> | ||
86 | struct tms { | ||
87 | time_t tms_utime; | ||
88 | time_t tms_stime; | ||
89 | time_t tms_uchild; /* I dunno... */ | ||
90 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
91 | } | ||
92 | #endif | ||
93 | #ifndef TIMES | ||
94 | #include <sys/timeb.h> | ||
95 | #endif | ||
96 | |||
97 | #ifdef sun | ||
98 | #include <limits.h> | ||
99 | #include <sys/param.h> | ||
100 | #endif | ||
101 | |||
102 | #include "bn.h" | ||
103 | #include "x509.h" | ||
104 | |||
105 | /* The following if from times(3) man page. It may need to be changed */ | ||
106 | #ifndef HZ | ||
107 | # ifndef CLK_TCK | ||
108 | # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ | ||
109 | # ifndef VMS | ||
110 | # define HZ 100.0 | ||
111 | # else /* VMS */ | ||
112 | # define HZ 100.0 | ||
113 | # endif | ||
114 | # else /* _BSD_CLK_TCK_ */ | ||
115 | # define HZ ((double)_BSD_CLK_TCK_) | ||
116 | # endif | ||
117 | # else /* CLK_TCK */ | ||
118 | # define HZ ((double)CLK_TCK) | ||
119 | # endif | ||
120 | #endif | ||
121 | |||
122 | #undef BUFSIZE | ||
123 | #define BUFSIZE ((long)1024*8) | ||
124 | int run=0; | ||
125 | |||
126 | #ifndef NOPROTO | ||
127 | static double Time_F(int s); | ||
128 | #else | ||
129 | static double Time_F(); | ||
130 | #endif | ||
131 | |||
132 | #define START 0 | ||
133 | #define STOP 1 | ||
134 | |||
135 | static double Time_F(s) | ||
136 | int s; | ||
137 | { | ||
138 | double ret; | ||
139 | #ifdef TIMES | ||
140 | static struct tms tstart,tend; | ||
141 | |||
142 | if (s == START) | ||
143 | { | ||
144 | times(&tstart); | ||
145 | return(0); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | times(&tend); | ||
150 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
151 | return((ret < 1e-3)?1e-3:ret); | ||
152 | } | ||
153 | #else /* !times() */ | ||
154 | static struct timeb tstart,tend; | ||
155 | long i; | ||
156 | |||
157 | if (s == START) | ||
158 | { | ||
159 | ftime(&tstart); | ||
160 | return(0); | ||
161 | } | ||
162 | else | ||
163 | { | ||
164 | ftime(&tend); | ||
165 | i=(long)tend.millitm-(long)tstart.millitm; | ||
166 | ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; | ||
167 | return((ret < 0.001)?0.001:ret); | ||
168 | } | ||
169 | #endif | ||
170 | } | ||
171 | |||
172 | #define NUM_SIZES 5 | ||
173 | static int sizes[NUM_SIZES]={128,256,512,1024,2048}; | ||
174 | /*static int sizes[NUM_SIZES]={59,179,299,419,539}; */ | ||
175 | |||
176 | void do_mul(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx); | ||
177 | |||
178 | int main(argc,argv) | ||
179 | int argc; | ||
180 | char **argv; | ||
181 | { | ||
182 | BN_CTX *ctx; | ||
183 | BIGNUM *a,*b,*c,*r; | ||
184 | |||
185 | ctx=BN_CTX_new(); | ||
186 | a=BN_new(); | ||
187 | b=BN_new(); | ||
188 | c=BN_new(); | ||
189 | r=BN_new(); | ||
190 | |||
191 | do_mul(a,b,c,ctx); | ||
192 | } | ||
193 | |||
194 | void do_mul(r,a,b,ctx) | ||
195 | BIGNUM *r; | ||
196 | BIGNUM *a; | ||
197 | BIGNUM *b; | ||
198 | BN_CTX *ctx; | ||
199 | { | ||
200 | int i,j,k; | ||
201 | double tm; | ||
202 | long num; | ||
203 | |||
204 | for (i=0; i<NUM_SIZES; i++) | ||
205 | { | ||
206 | num=BASENUM; | ||
207 | if (i) num/=(i*3); | ||
208 | BN_rand(a,sizes[i],1,0); | ||
209 | for (j=i; j<NUM_SIZES; j++) | ||
210 | { | ||
211 | BN_rand(b,sizes[j],1,0); | ||
212 | Time_F(START); | ||
213 | for (k=0; k<num; k++) | ||
214 | BN_mul(r,b,a); | ||
215 | tm=Time_F(STOP); | ||
216 | printf("mul %4d x %4d -> %8.3fms\n",sizes[i],sizes[j],tm*1000.0/num); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | for (i=0; i<NUM_SIZES; i++) | ||
221 | { | ||
222 | num=BASENUM; | ||
223 | if (i) num/=(i*3); | ||
224 | BN_rand(a,sizes[i],1,0); | ||
225 | Time_F(START); | ||
226 | for (k=0; k<num; k++) | ||
227 | BN_sqr(r,a,ctx); | ||
228 | tm=Time_F(STOP); | ||
229 | printf("sqr %4d x %4d -> %8.3fms\n",sizes[i],sizes[i],tm*1000.0/num); | ||
230 | } | ||
231 | |||
232 | for (i=0; i<NUM_SIZES; i++) | ||
233 | { | ||
234 | num=BASENUM/10; | ||
235 | if (i) num/=(i*3); | ||
236 | BN_rand(a,sizes[i]-1,1,0); | ||
237 | for (j=i; j<NUM_SIZES; j++) | ||
238 | { | ||
239 | BN_rand(b,sizes[j],1,0); | ||
240 | Time_F(START); | ||
241 | for (k=0; k<100000; k++) | ||
242 | BN_div(r, NULL, b, a,ctx); | ||
243 | tm=Time_F(STOP); | ||
244 | printf("div %4d / %4d -> %8.3fms\n",sizes[j],sizes[i]-1,tm*1000.0/num); | ||
245 | } | ||
246 | } | ||
247 | } | ||
248 | |||
diff --git a/src/lib/libcrypto/bn/bntest.c b/src/lib/libcrypto/bn/bntest.c new file mode 100644 index 0000000000..9ebd68b429 --- /dev/null +++ b/src/lib/libcrypto/bn/bntest.c | |||
@@ -0,0 +1,777 @@ | |||
1 | /* crypto/bn/bntest.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 <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #include "e_os.h" | ||
63 | #include "bio.h" | ||
64 | #include "bn.h" | ||
65 | #include "rand.h" | ||
66 | #include "x509.h" | ||
67 | #include "err.h" | ||
68 | |||
69 | #ifdef WINDOWS | ||
70 | #include "../bio/bss_file.c" | ||
71 | #endif | ||
72 | |||
73 | #ifndef NOPROTO | ||
74 | int test_add (BIO *bp); | ||
75 | int test_sub (BIO *bp); | ||
76 | int test_lshift1 (BIO *bp); | ||
77 | int test_lshift (BIO *bp); | ||
78 | int test_rshift1 (BIO *bp); | ||
79 | int test_rshift (BIO *bp); | ||
80 | int test_div (BIO *bp,BN_CTX *ctx); | ||
81 | int test_mul (BIO *bp); | ||
82 | int test_sqr (BIO *bp,BN_CTX *ctx); | ||
83 | int test_mont (BIO *bp,BN_CTX *ctx); | ||
84 | int test_mod (BIO *bp,BN_CTX *ctx); | ||
85 | int test_mod_mul (BIO *bp,BN_CTX *ctx); | ||
86 | int test_mod_exp (BIO *bp,BN_CTX *ctx); | ||
87 | int rand_neg(void); | ||
88 | #else | ||
89 | int test_add (); | ||
90 | int test_sub (); | ||
91 | int test_lshift1 (); | ||
92 | int test_lshift (); | ||
93 | int test_rshift1 (); | ||
94 | int test_rshift (); | ||
95 | int test_div (); | ||
96 | int test_mul (); | ||
97 | int test_sqr (); | ||
98 | int test_mont (); | ||
99 | int test_mod (); | ||
100 | int test_mod_mul (); | ||
101 | int test_mod_exp (); | ||
102 | int rand_neg(); | ||
103 | #endif | ||
104 | |||
105 | static int results=0; | ||
106 | |||
107 | #ifdef NO_STDIO | ||
108 | #define APPS_WIN16 | ||
109 | #include "bss_file.c" | ||
110 | #endif | ||
111 | |||
112 | int main(argc,argv) | ||
113 | int argc; | ||
114 | char *argv[]; | ||
115 | { | ||
116 | BN_CTX *ctx; | ||
117 | BIO *out; | ||
118 | char *outfile=NULL; | ||
119 | |||
120 | srand((unsigned int)time(NULL)); | ||
121 | |||
122 | argc--; | ||
123 | argv++; | ||
124 | while (argc >= 1) | ||
125 | { | ||
126 | if (strcmp(*argv,"-results") == 0) | ||
127 | results=1; | ||
128 | else if (strcmp(*argv,"-out") == 0) | ||
129 | { | ||
130 | if (--argc < 1) break; | ||
131 | outfile= *(++argv); | ||
132 | } | ||
133 | argc--; | ||
134 | argv++; | ||
135 | } | ||
136 | |||
137 | |||
138 | ctx=BN_CTX_new(); | ||
139 | if (ctx == NULL) exit(1); | ||
140 | |||
141 | out=BIO_new(BIO_s_file()); | ||
142 | if (out == NULL) exit(1); | ||
143 | if (outfile == NULL) | ||
144 | { | ||
145 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | if (!BIO_write_filename(out,outfile)) | ||
150 | { | ||
151 | perror(outfile); | ||
152 | exit(1); | ||
153 | } | ||
154 | } | ||
155 | |||
156 | if (!results) | ||
157 | BIO_puts(out,"obase=16\nibase=16\n"); | ||
158 | |||
159 | fprintf(stderr,"test BN_add\n"); | ||
160 | if (!test_add(out)) goto err; | ||
161 | fflush(stdout); | ||
162 | |||
163 | fprintf(stderr,"test BN_sub\n"); | ||
164 | if (!test_sub(out)) goto err; | ||
165 | fflush(stdout); | ||
166 | |||
167 | fprintf(stderr,"test BN_lshift1\n"); | ||
168 | if (!test_lshift1(out)) goto err; | ||
169 | fflush(stdout); | ||
170 | |||
171 | fprintf(stderr,"test BN_lshift\n"); | ||
172 | if (!test_lshift(out)) goto err; | ||
173 | fflush(stdout); | ||
174 | |||
175 | fprintf(stderr,"test BN_rshift1\n"); | ||
176 | if (!test_rshift1(out)) goto err; | ||
177 | fflush(stdout); | ||
178 | |||
179 | fprintf(stderr,"test BN_rshift\n"); | ||
180 | if (!test_rshift(out)) goto err; | ||
181 | fflush(stdout); | ||
182 | |||
183 | fprintf(stderr,"test BN_sqr\n"); | ||
184 | if (!test_sqr(out,ctx)) goto err; | ||
185 | fflush(stdout); | ||
186 | |||
187 | fprintf(stderr,"test BN_mul\n"); | ||
188 | if (!test_mul(out)) goto err; | ||
189 | fflush(stdout); | ||
190 | |||
191 | fprintf(stderr,"test BN_div\n"); | ||
192 | if (!test_div(out,ctx)) goto err; | ||
193 | fflush(stdout); | ||
194 | |||
195 | fprintf(stderr,"test BN_mod\n"); | ||
196 | if (!test_mod(out,ctx)) goto err; | ||
197 | fflush(stdout); | ||
198 | |||
199 | fprintf(stderr,"test BN_mod_mul\n"); | ||
200 | if (!test_mod_mul(out,ctx)) goto err; | ||
201 | fflush(stdout); | ||
202 | |||
203 | /* | ||
204 | fprintf(stderr,"test BN_mont\n"); | ||
205 | if (!test_mont(out,ctx)) goto err; | ||
206 | fflush(stdout); | ||
207 | */ | ||
208 | fprintf(stderr,"test BN_mod_exp\n"); | ||
209 | if (!test_mod_exp(out,ctx)) goto err; | ||
210 | fflush(stdout); | ||
211 | |||
212 | /**/ | ||
213 | exit(0); | ||
214 | err: | ||
215 | ERR_load_crypto_strings(); | ||
216 | ERR_print_errors(out); | ||
217 | exit(1); | ||
218 | return(1); | ||
219 | } | ||
220 | |||
221 | int test_add(bp) | ||
222 | BIO *bp; | ||
223 | { | ||
224 | BIGNUM *a,*b,*c; | ||
225 | int i; | ||
226 | int j; | ||
227 | |||
228 | a=BN_new(); | ||
229 | b=BN_new(); | ||
230 | c=BN_new(); | ||
231 | |||
232 | BN_rand(a,512,0,0); | ||
233 | for (i=0; i<100; i++) | ||
234 | { | ||
235 | BN_rand(b,450+i,0,0); | ||
236 | a->neg=rand_neg(); | ||
237 | b->neg=rand_neg(); | ||
238 | if (bp == NULL) | ||
239 | for (j=0; j<10000; j++) | ||
240 | BN_add(c,a,b); | ||
241 | BN_add(c,a,b); | ||
242 | if (bp != NULL) | ||
243 | { | ||
244 | if (!results) | ||
245 | { | ||
246 | BN_print(bp,a); | ||
247 | BIO_puts(bp," + "); | ||
248 | BN_print(bp,b); | ||
249 | BIO_puts(bp," - "); | ||
250 | } | ||
251 | BN_print(bp,c); | ||
252 | BIO_puts(bp,"\n"); | ||
253 | } | ||
254 | } | ||
255 | BN_free(a); | ||
256 | BN_free(b); | ||
257 | BN_free(c); | ||
258 | return(1); | ||
259 | } | ||
260 | |||
261 | int test_sub(bp) | ||
262 | BIO *bp; | ||
263 | { | ||
264 | BIGNUM *a,*b,*c; | ||
265 | int i; | ||
266 | int j; | ||
267 | |||
268 | a=BN_new(); | ||
269 | b=BN_new(); | ||
270 | c=BN_new(); | ||
271 | |||
272 | BN_rand(a,512,0,0); | ||
273 | for (i=0; i<100; i++) | ||
274 | { | ||
275 | BN_rand(b,400+i,0,0); | ||
276 | a->neg=rand_neg(); | ||
277 | b->neg=rand_neg(); | ||
278 | if (bp == NULL) | ||
279 | for (j=0; j<10000; j++) | ||
280 | BN_sub(c,a,b); | ||
281 | BN_sub(c,a,b); | ||
282 | if (bp != NULL) | ||
283 | { | ||
284 | if (!results) | ||
285 | { | ||
286 | BN_print(bp,a); | ||
287 | BIO_puts(bp," - "); | ||
288 | BN_print(bp,b); | ||
289 | BIO_puts(bp," - "); | ||
290 | } | ||
291 | BN_print(bp,c); | ||
292 | BIO_puts(bp,"\n"); | ||
293 | } | ||
294 | } | ||
295 | BN_free(a); | ||
296 | BN_free(b); | ||
297 | BN_free(c); | ||
298 | return(1); | ||
299 | } | ||
300 | |||
301 | int test_div(bp,ctx) | ||
302 | BIO *bp; | ||
303 | BN_CTX *ctx; | ||
304 | { | ||
305 | BIGNUM *a,*b,*c,*d; | ||
306 | int i; | ||
307 | int j; | ||
308 | |||
309 | a=BN_new(); | ||
310 | b=BN_new(); | ||
311 | c=BN_new(); | ||
312 | d=BN_new(); | ||
313 | |||
314 | BN_rand(a,400,0,0); | ||
315 | for (i=0; i<100; i++) | ||
316 | { | ||
317 | BN_rand(b,50+i,0,0); | ||
318 | a->neg=rand_neg(); | ||
319 | b->neg=rand_neg(); | ||
320 | if (bp == NULL) | ||
321 | for (j=0; j<100; j++) | ||
322 | BN_div(d,c,a,b,ctx); | ||
323 | BN_div(d,c,a,b,ctx); | ||
324 | if (bp != NULL) | ||
325 | { | ||
326 | if (!results) | ||
327 | { | ||
328 | BN_print(bp,a); | ||
329 | BIO_puts(bp," / "); | ||
330 | BN_print(bp,b); | ||
331 | BIO_puts(bp," - "); | ||
332 | } | ||
333 | BN_print(bp,d); | ||
334 | BIO_puts(bp,"\n"); | ||
335 | |||
336 | if (!results) | ||
337 | { | ||
338 | BN_print(bp,a); | ||
339 | BIO_puts(bp," % "); | ||
340 | BN_print(bp,b); | ||
341 | BIO_puts(bp," - "); | ||
342 | } | ||
343 | BN_print(bp,c); | ||
344 | BIO_puts(bp,"\n"); | ||
345 | } | ||
346 | } | ||
347 | BN_free(a); | ||
348 | BN_free(b); | ||
349 | BN_free(c); | ||
350 | BN_free(d); | ||
351 | return(1); | ||
352 | } | ||
353 | |||
354 | int test_mul(bp) | ||
355 | BIO *bp; | ||
356 | { | ||
357 | BIGNUM *a,*b,*c; | ||
358 | int i; | ||
359 | int j; | ||
360 | |||
361 | a=BN_new(); | ||
362 | b=BN_new(); | ||
363 | c=BN_new(); | ||
364 | |||
365 | BN_rand(a,200,0,0); | ||
366 | for (i=0; i<100; i++) | ||
367 | { | ||
368 | BN_rand(b,250+i,0,0); | ||
369 | a->neg=rand_neg(); | ||
370 | b->neg=rand_neg(); | ||
371 | if (bp == NULL) | ||
372 | for (j=0; j<100; j++) | ||
373 | BN_mul(c,a,b); | ||
374 | BN_mul(c,a,b); | ||
375 | if (bp != NULL) | ||
376 | { | ||
377 | if (!results) | ||
378 | { | ||
379 | BN_print(bp,a); | ||
380 | BIO_puts(bp," * "); | ||
381 | BN_print(bp,b); | ||
382 | BIO_puts(bp," - "); | ||
383 | } | ||
384 | BN_print(bp,c); | ||
385 | BIO_puts(bp,"\n"); | ||
386 | } | ||
387 | } | ||
388 | BN_free(a); | ||
389 | BN_free(b); | ||
390 | BN_free(c); | ||
391 | return(1); | ||
392 | } | ||
393 | |||
394 | int test_sqr(bp,ctx) | ||
395 | BIO *bp; | ||
396 | BN_CTX *ctx; | ||
397 | { | ||
398 | BIGNUM *a,*c; | ||
399 | int i; | ||
400 | int j; | ||
401 | |||
402 | a=BN_new(); | ||
403 | c=BN_new(); | ||
404 | |||
405 | for (i=0; i<40; i++) | ||
406 | { | ||
407 | BN_rand(a,40+i*10,0,0); | ||
408 | a->neg=rand_neg(); | ||
409 | if (bp == NULL) | ||
410 | for (j=0; j<100; j++) | ||
411 | BN_sqr(c,a,ctx); | ||
412 | BN_sqr(c,a,ctx); | ||
413 | if (bp != NULL) | ||
414 | { | ||
415 | if (!results) | ||
416 | { | ||
417 | BN_print(bp,a); | ||
418 | BIO_puts(bp," * "); | ||
419 | BN_print(bp,a); | ||
420 | BIO_puts(bp," - "); | ||
421 | } | ||
422 | BN_print(bp,c); | ||
423 | BIO_puts(bp,"\n"); | ||
424 | } | ||
425 | } | ||
426 | BN_free(a); | ||
427 | BN_free(c); | ||
428 | return(1); | ||
429 | } | ||
430 | |||
431 | int test_mont(bp,ctx) | ||
432 | BIO *bp; | ||
433 | BN_CTX *ctx; | ||
434 | { | ||
435 | BIGNUM *a,*b,*c,*A,*B; | ||
436 | BIGNUM *n; | ||
437 | int i; | ||
438 | int j; | ||
439 | BN_MONT_CTX *mont; | ||
440 | |||
441 | a=BN_new(); | ||
442 | b=BN_new(); | ||
443 | c=BN_new(); | ||
444 | A=BN_new(); | ||
445 | B=BN_new(); | ||
446 | n=BN_new(); | ||
447 | |||
448 | mont=BN_MONT_CTX_new(); | ||
449 | |||
450 | BN_rand(a,100,0,0); /**/ | ||
451 | BN_rand(b,100,0,0); /**/ | ||
452 | for (i=0; i<10; i++) | ||
453 | { | ||
454 | BN_rand(n,(100%BN_BITS2+1)*BN_BITS2*i*BN_BITS2,0,1); /**/ | ||
455 | BN_MONT_CTX_set(mont,n,ctx); | ||
456 | |||
457 | BN_to_montgomery(A,a,mont,ctx); | ||
458 | BN_to_montgomery(B,b,mont,ctx); | ||
459 | |||
460 | if (bp == NULL) | ||
461 | for (j=0; j<100; j++) | ||
462 | BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/ | ||
463 | BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/ | ||
464 | BN_from_montgomery(A,c,mont,ctx);/**/ | ||
465 | if (bp != NULL) | ||
466 | { | ||
467 | if (!results) | ||
468 | { | ||
469 | #ifdef undef | ||
470 | fprintf(stderr,"%d * %d %% %d\n", | ||
471 | BN_num_bits(a), | ||
472 | BN_num_bits(b), | ||
473 | BN_num_bits(mont->N)); | ||
474 | #endif | ||
475 | BN_print(bp,a); | ||
476 | BIO_puts(bp," * "); | ||
477 | BN_print(bp,b); | ||
478 | BIO_puts(bp," % "); | ||
479 | BN_print(bp,mont->N); | ||
480 | BIO_puts(bp," - "); | ||
481 | } | ||
482 | BN_print(bp,A); | ||
483 | BIO_puts(bp,"\n"); | ||
484 | } | ||
485 | } | ||
486 | BN_MONT_CTX_free(mont); | ||
487 | BN_free(a); | ||
488 | BN_free(b); | ||
489 | BN_free(c); | ||
490 | return(1); | ||
491 | } | ||
492 | |||
493 | int test_mod(bp,ctx) | ||
494 | BIO *bp; | ||
495 | BN_CTX *ctx; | ||
496 | { | ||
497 | BIGNUM *a,*b,*c; | ||
498 | int i; | ||
499 | int j; | ||
500 | |||
501 | a=BN_new(); | ||
502 | b=BN_new(); | ||
503 | c=BN_new(); | ||
504 | |||
505 | BN_rand(a,1024,0,0); /**/ | ||
506 | for (i=0; i<20; i++) | ||
507 | { | ||
508 | BN_rand(b,450+i*10,0,0); /**/ | ||
509 | a->neg=rand_neg(); | ||
510 | b->neg=rand_neg(); | ||
511 | if (bp == NULL) | ||
512 | for (j=0; j<100; j++) | ||
513 | BN_mod(c,a,b,ctx);/**/ | ||
514 | BN_mod(c,a,b,ctx);/**/ | ||
515 | if (bp != NULL) | ||
516 | { | ||
517 | if (!results) | ||
518 | { | ||
519 | BN_print(bp,a); | ||
520 | BIO_puts(bp," % "); | ||
521 | BN_print(bp,b); | ||
522 | BIO_puts(bp," - "); | ||
523 | } | ||
524 | BN_print(bp,c); | ||
525 | BIO_puts(bp,"\n"); | ||
526 | } | ||
527 | } | ||
528 | BN_free(a); | ||
529 | BN_free(b); | ||
530 | BN_free(c); | ||
531 | return(1); | ||
532 | } | ||
533 | |||
534 | int test_mod_mul(bp,ctx) | ||
535 | BIO *bp; | ||
536 | BN_CTX *ctx; | ||
537 | { | ||
538 | BIGNUM *a,*b,*c,*d,*e; | ||
539 | int i; | ||
540 | |||
541 | a=BN_new(); | ||
542 | b=BN_new(); | ||
543 | c=BN_new(); | ||
544 | d=BN_new(); | ||
545 | e=BN_new(); | ||
546 | |||
547 | BN_rand(c,1024,0,0); /**/ | ||
548 | for (i=0; i<10; i++) | ||
549 | { | ||
550 | BN_rand(a,475+i*10,0,0); /**/ | ||
551 | BN_rand(b,425+i*10,0,0); /**/ | ||
552 | a->neg=rand_neg(); | ||
553 | b->neg=rand_neg(); | ||
554 | /* if (bp == NULL) | ||
555 | for (j=0; j<100; j++) | ||
556 | BN_mod_mul(d,a,b,c,ctx);*/ /**/ | ||
557 | |||
558 | if (!BN_mod_mul(e,a,b,c,ctx)) | ||
559 | { | ||
560 | unsigned long l; | ||
561 | |||
562 | while ((l=ERR_get_error())) | ||
563 | fprintf(stderr,"ERROR:%s\n", | ||
564 | ERR_error_string(l,NULL)); | ||
565 | exit(1); | ||
566 | } | ||
567 | if (bp != NULL) | ||
568 | { | ||
569 | if (!results) | ||
570 | { | ||
571 | BN_print(bp,a); | ||
572 | BIO_puts(bp," * "); | ||
573 | BN_print(bp,b); | ||
574 | BIO_puts(bp," % "); | ||
575 | BN_print(bp,c); | ||
576 | BIO_puts(bp," - "); | ||
577 | } | ||
578 | BN_print(bp,e); | ||
579 | BIO_puts(bp,"\n"); | ||
580 | } | ||
581 | } | ||
582 | BN_free(a); | ||
583 | BN_free(b); | ||
584 | BN_free(c); | ||
585 | BN_free(d); | ||
586 | BN_free(e); | ||
587 | return(1); | ||
588 | } | ||
589 | |||
590 | int test_mod_exp(bp,ctx) | ||
591 | BIO *bp; | ||
592 | BN_CTX *ctx; | ||
593 | { | ||
594 | BIGNUM *a,*b,*c,*d,*e; | ||
595 | int i; | ||
596 | |||
597 | a=BN_new(); | ||
598 | b=BN_new(); | ||
599 | c=BN_new(); | ||
600 | d=BN_new(); | ||
601 | e=BN_new(); | ||
602 | |||
603 | BN_rand(c,30,0,1); /* must be odd for montgomery */ | ||
604 | for (i=0; i<6; i++) | ||
605 | { | ||
606 | BN_rand(a,20+i*5,0,0); /**/ | ||
607 | BN_rand(b,2+i,0,0); /**/ | ||
608 | |||
609 | if (!BN_mod_exp(d,a,b,c,ctx)) | ||
610 | return(00); | ||
611 | |||
612 | if (bp != NULL) | ||
613 | { | ||
614 | if (!results) | ||
615 | { | ||
616 | BN_print(bp,a); | ||
617 | BIO_puts(bp," ^ "); | ||
618 | BN_print(bp,b); | ||
619 | BIO_puts(bp," % "); | ||
620 | BN_print(bp,c); | ||
621 | BIO_puts(bp," - "); | ||
622 | } | ||
623 | BN_print(bp,d); | ||
624 | BIO_puts(bp,"\n"); | ||
625 | } | ||
626 | } | ||
627 | BN_free(a); | ||
628 | BN_free(b); | ||
629 | BN_free(c); | ||
630 | BN_free(d); | ||
631 | BN_free(e); | ||
632 | return(1); | ||
633 | } | ||
634 | |||
635 | int test_lshift(bp) | ||
636 | BIO *bp; | ||
637 | { | ||
638 | BIGNUM *a,*b,*c; | ||
639 | int i; | ||
640 | |||
641 | a=BN_new(); | ||
642 | b=BN_new(); | ||
643 | c=BN_new(); | ||
644 | BN_one(c); | ||
645 | |||
646 | BN_rand(a,200,0,0); /**/ | ||
647 | a->neg=rand_neg(); | ||
648 | for (i=0; i<70; i++) | ||
649 | { | ||
650 | BN_lshift(b,a,i+1); | ||
651 | BN_add(c,c,c); | ||
652 | if (bp != NULL) | ||
653 | { | ||
654 | if (!results) | ||
655 | { | ||
656 | BN_print(bp,a); | ||
657 | BIO_puts(bp," * "); | ||
658 | BN_print(bp,c); | ||
659 | BIO_puts(bp," - "); | ||
660 | } | ||
661 | BN_print(bp,b); | ||
662 | BIO_puts(bp,"\n"); | ||
663 | } | ||
664 | } | ||
665 | BN_free(a); | ||
666 | BN_free(b); | ||
667 | BN_free(c); | ||
668 | return(1); | ||
669 | } | ||
670 | |||
671 | int test_lshift1(bp) | ||
672 | BIO *bp; | ||
673 | { | ||
674 | BIGNUM *a,*b; | ||
675 | int i; | ||
676 | |||
677 | a=BN_new(); | ||
678 | b=BN_new(); | ||
679 | |||
680 | BN_rand(a,200,0,0); /**/ | ||
681 | a->neg=rand_neg(); | ||
682 | for (i=0; i<70; i++) | ||
683 | { | ||
684 | BN_lshift1(b,a); | ||
685 | if (bp != NULL) | ||
686 | { | ||
687 | if (!results) | ||
688 | { | ||
689 | BN_print(bp,a); | ||
690 | BIO_puts(bp," * 2"); | ||
691 | BIO_puts(bp," - "); | ||
692 | } | ||
693 | BN_print(bp,b); | ||
694 | BIO_puts(bp,"\n"); | ||
695 | } | ||
696 | BN_copy(a,b); | ||
697 | } | ||
698 | BN_free(a); | ||
699 | BN_free(b); | ||
700 | return(1); | ||
701 | } | ||
702 | |||
703 | int test_rshift(bp) | ||
704 | BIO *bp; | ||
705 | { | ||
706 | BIGNUM *a,*b,*c; | ||
707 | int i; | ||
708 | |||
709 | a=BN_new(); | ||
710 | b=BN_new(); | ||
711 | c=BN_new(); | ||
712 | BN_one(c); | ||
713 | |||
714 | BN_rand(a,200,0,0); /**/ | ||
715 | a->neg=rand_neg(); | ||
716 | for (i=0; i<70; i++) | ||
717 | { | ||
718 | BN_rshift(b,a,i+1); | ||
719 | BN_add(c,c,c); | ||
720 | if (bp != NULL) | ||
721 | { | ||
722 | if (!results) | ||
723 | { | ||
724 | BN_print(bp,a); | ||
725 | BIO_puts(bp," / "); | ||
726 | BN_print(bp,c); | ||
727 | BIO_puts(bp," - "); | ||
728 | } | ||
729 | BN_print(bp,b); | ||
730 | BIO_puts(bp,"\n"); | ||
731 | } | ||
732 | } | ||
733 | BN_free(a); | ||
734 | BN_free(b); | ||
735 | BN_free(c); | ||
736 | return(1); | ||
737 | } | ||
738 | |||
739 | int test_rshift1(bp) | ||
740 | BIO *bp; | ||
741 | { | ||
742 | BIGNUM *a,*b; | ||
743 | int i; | ||
744 | |||
745 | a=BN_new(); | ||
746 | b=BN_new(); | ||
747 | |||
748 | BN_rand(a,200,0,0); /**/ | ||
749 | a->neg=rand_neg(); | ||
750 | for (i=0; i<70; i++) | ||
751 | { | ||
752 | BN_rshift1(b,a); | ||
753 | if (bp != NULL) | ||
754 | { | ||
755 | if (!results) | ||
756 | { | ||
757 | BN_print(bp,a); | ||
758 | BIO_puts(bp," / 2"); | ||
759 | BIO_puts(bp," - "); | ||
760 | } | ||
761 | BN_print(bp,b); | ||
762 | BIO_puts(bp,"\n"); | ||
763 | } | ||
764 | BN_copy(a,b); | ||
765 | } | ||
766 | BN_free(a); | ||
767 | BN_free(b); | ||
768 | return(1); | ||
769 | } | ||
770 | |||
771 | int rand_neg() | ||
772 | { | ||
773 | static unsigned int neg=0; | ||
774 | static int sign[8]={0,0,0,1,1,0,1,1}; | ||
775 | |||
776 | return(sign[(neg++)%8]); | ||
777 | } | ||
diff --git a/src/lib/libcrypto/bn/expspeed.c b/src/lib/libcrypto/bn/expspeed.c new file mode 100644 index 0000000000..344f883d35 --- /dev/null +++ b/src/lib/libcrypto/bn/expspeed.c | |||
@@ -0,0 +1,230 @@ | |||
1 | /* crypto/bn/expspeed.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 | /* most of this code has been pilfered from my libdes speed.c program */ | ||
60 | |||
61 | #define BASENUM 5000 | ||
62 | #undef PROG | ||
63 | #define PROG bnspeed_main | ||
64 | |||
65 | #include <stdio.h> | ||
66 | #include <stdlib.h> | ||
67 | #include <signal.h> | ||
68 | #include <string.h> | ||
69 | #include "crypto.h" | ||
70 | #include "err.h" | ||
71 | |||
72 | #ifndef MSDOS | ||
73 | #define TIMES | ||
74 | #endif | ||
75 | |||
76 | #ifndef VMS | ||
77 | #ifndef _IRIX | ||
78 | #include <time.h> | ||
79 | #endif | ||
80 | #ifdef TIMES | ||
81 | #include <sys/types.h> | ||
82 | #include <sys/times.h> | ||
83 | #endif | ||
84 | #else /* VMS */ | ||
85 | #include <types.h> | ||
86 | struct tms { | ||
87 | time_t tms_utime; | ||
88 | time_t tms_stime; | ||
89 | time_t tms_uchild; /* I dunno... */ | ||
90 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
91 | } | ||
92 | #endif | ||
93 | #ifndef TIMES | ||
94 | #include <sys/timeb.h> | ||
95 | #endif | ||
96 | |||
97 | #ifdef sun | ||
98 | #include <limits.h> | ||
99 | #include <sys/param.h> | ||
100 | #endif | ||
101 | |||
102 | #include "bn.h" | ||
103 | #include "x509.h" | ||
104 | |||
105 | /* The following if from times(3) man page. It may need to be changed */ | ||
106 | #ifndef HZ | ||
107 | # ifndef CLK_TCK | ||
108 | # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ | ||
109 | # ifndef VMS | ||
110 | # define HZ 100.0 | ||
111 | # else /* VMS */ | ||
112 | # define HZ 100.0 | ||
113 | # endif | ||
114 | # else /* _BSD_CLK_TCK_ */ | ||
115 | # define HZ ((double)_BSD_CLK_TCK_) | ||
116 | # endif | ||
117 | # else /* CLK_TCK */ | ||
118 | # define HZ ((double)CLK_TCK) | ||
119 | # endif | ||
120 | #endif | ||
121 | |||
122 | #undef BUFSIZE | ||
123 | #define BUFSIZE ((long)1024*8) | ||
124 | int run=0; | ||
125 | |||
126 | #ifndef NOPROTO | ||
127 | static double Time_F(int s); | ||
128 | #else | ||
129 | static double Time_F(); | ||
130 | #endif | ||
131 | |||
132 | #define START 0 | ||
133 | #define STOP 1 | ||
134 | |||
135 | static double Time_F(s) | ||
136 | int s; | ||
137 | { | ||
138 | double ret; | ||
139 | #ifdef TIMES | ||
140 | static struct tms tstart,tend; | ||
141 | |||
142 | if (s == START) | ||
143 | { | ||
144 | times(&tstart); | ||
145 | return(0); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | times(&tend); | ||
150 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
151 | return((ret < 1e-3)?1e-3:ret); | ||
152 | } | ||
153 | #else /* !times() */ | ||
154 | static struct timeb tstart,tend; | ||
155 | long i; | ||
156 | |||
157 | if (s == START) | ||
158 | { | ||
159 | ftime(&tstart); | ||
160 | return(0); | ||
161 | } | ||
162 | else | ||
163 | { | ||
164 | ftime(&tend); | ||
165 | i=(long)tend.millitm-(long)tstart.millitm; | ||
166 | ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; | ||
167 | return((ret < 0.001)?0.001:ret); | ||
168 | } | ||
169 | #endif | ||
170 | } | ||
171 | |||
172 | #define NUM_SIZES 6 | ||
173 | static int sizes[NUM_SIZES]={256,512,1024,2048,4096,8192}; | ||
174 | static int mul_c[NUM_SIZES]={8*8*8*8*8,8*8*8*8,8*8*8,8*8,8,1}; | ||
175 | /*static int sizes[NUM_SIZES]={59,179,299,419,539}; */ | ||
176 | |||
177 | void do_mul_exp(BIGNUM *r,BIGNUM *a,BIGNUM *b,BIGNUM *c,BN_CTX *ctx); | ||
178 | |||
179 | int main(argc,argv) | ||
180 | int argc; | ||
181 | char **argv; | ||
182 | { | ||
183 | BN_CTX *ctx; | ||
184 | BIGNUM *a,*b,*c,*r; | ||
185 | |||
186 | ctx=BN_CTX_new(); | ||
187 | a=BN_new(); | ||
188 | b=BN_new(); | ||
189 | c=BN_new(); | ||
190 | r=BN_new(); | ||
191 | |||
192 | do_mul_exp(r,a,b,c,ctx); | ||
193 | } | ||
194 | |||
195 | void do_mul_exp(r,a,b,c,ctx) | ||
196 | BIGNUM *r; | ||
197 | BIGNUM *a; | ||
198 | BIGNUM *b; | ||
199 | BIGNUM *c; | ||
200 | BN_CTX *ctx; | ||
201 | { | ||
202 | int i,k; | ||
203 | double tm; | ||
204 | long num; | ||
205 | BN_MONT_CTX m; | ||
206 | |||
207 | memset(&m,0,sizeof(m)); | ||
208 | |||
209 | num=BASENUM; | ||
210 | for (i=0; i<NUM_SIZES; i++) | ||
211 | { | ||
212 | BN_rand(a,sizes[i],1,0); | ||
213 | BN_rand(b,sizes[i],1,0); | ||
214 | BN_rand(c,sizes[i],1,1); | ||
215 | BN_mod(a,a,c,ctx); | ||
216 | BN_mod(b,b,c,ctx); | ||
217 | |||
218 | BN_MONT_CTX_set(&m,c,ctx); | ||
219 | |||
220 | Time_F(START); | ||
221 | for (k=0; k<num; k++) | ||
222 | BN_mod_exp_mont(r,a,b,c,ctx,&m); | ||
223 | tm=Time_F(STOP); | ||
224 | printf("mul %4d ^ %4d %% %d -> %8.3fms %5.1f\n",sizes[i],sizes[i],sizes[i],tm*1000.0/num,tm*mul_c[i]/num); | ||
225 | num/=7; | ||
226 | if (num <= 0) num=1; | ||
227 | } | ||
228 | |||
229 | } | ||
230 | |||
diff --git a/src/lib/libcrypto/bn/exptest.c b/src/lib/libcrypto/bn/exptest.c new file mode 100644 index 0000000000..67dc95d726 --- /dev/null +++ b/src/lib/libcrypto/bn/exptest.c | |||
@@ -0,0 +1,148 @@ | |||
1 | /* crypto/bn/exptest.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 <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #include "bio.h" | ||
63 | #include "bn.h" | ||
64 | #include "rand.h" | ||
65 | #include "err.h" | ||
66 | #ifdef WINDOWS | ||
67 | #include "../bio/bss_file.c" | ||
68 | #endif | ||
69 | |||
70 | #define NUM_BITS (BN_BITS*2) | ||
71 | |||
72 | int main(argc,argv) | ||
73 | int argc; | ||
74 | char *argv[]; | ||
75 | { | ||
76 | BN_CTX *ctx; | ||
77 | BIO *out=NULL; | ||
78 | int i,ret; | ||
79 | unsigned char c; | ||
80 | BIGNUM *r_mont,*r_recp,*a,*b,*m; | ||
81 | |||
82 | ctx=BN_CTX_new(); | ||
83 | if (ctx == NULL) exit(1); | ||
84 | r_mont=BN_new(); | ||
85 | r_recp=BN_new(); | ||
86 | a=BN_new(); | ||
87 | b=BN_new(); | ||
88 | m=BN_new(); | ||
89 | if ( (r_mont == NULL) || (r_recp == NULL) || | ||
90 | (a == NULL) || (b == NULL)) | ||
91 | goto err; | ||
92 | |||
93 | out=BIO_new(BIO_s_file()); | ||
94 | |||
95 | if (out == NULL) exit(1); | ||
96 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | ||
97 | |||
98 | for (i=0; i<200; i++) | ||
99 | { | ||
100 | RAND_bytes(&c,1); | ||
101 | c=(c%BN_BITS)-BN_BITS2; | ||
102 | BN_rand(a,NUM_BITS+c,0,0); | ||
103 | |||
104 | RAND_bytes(&c,1); | ||
105 | c=(c%BN_BITS)-BN_BITS2; | ||
106 | BN_rand(b,NUM_BITS+c,0,0); | ||
107 | |||
108 | RAND_bytes(&c,1); | ||
109 | c=(c%BN_BITS)-BN_BITS2; | ||
110 | BN_rand(m,NUM_BITS+c,0,1); | ||
111 | |||
112 | BN_mod(a,a,m,ctx); | ||
113 | BN_mod(b,b,m,ctx); | ||
114 | |||
115 | ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL); | ||
116 | if (ret <= 0) | ||
117 | { printf("BN_mod_exp_mont() problems\n"); exit(1); } | ||
118 | |||
119 | ret=BN_mod_exp_recp(r_recp,a,b,m,ctx); | ||
120 | if (ret <= 0) | ||
121 | { printf("BN_mod_exp_recp() problems\n"); exit(1); } | ||
122 | |||
123 | if (BN_cmp(r_mont,r_recp) != 0) | ||
124 | { | ||
125 | printf("\nmont and recp results differ\n"); | ||
126 | printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a); | ||
127 | printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b); | ||
128 | printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m); | ||
129 | printf("\nrecp ="); BN_print(out,r_recp); | ||
130 | printf("\nmont ="); BN_print(out,r_mont); | ||
131 | printf("\n"); | ||
132 | exit(1); | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | printf("."); | ||
137 | fflush(stdout); | ||
138 | } | ||
139 | } | ||
140 | printf(" done\n"); | ||
141 | exit(0); | ||
142 | err: | ||
143 | ERR_load_crypto_strings(); | ||
144 | ERR_print_errors(out); | ||
145 | exit(1); | ||
146 | return(1); | ||
147 | } | ||
148 | |||
diff --git a/src/lib/libcrypto/cast/asm/readme b/src/lib/libcrypto/cast/asm/readme new file mode 100644 index 0000000000..fbcd76289e --- /dev/null +++ b/src/lib/libcrypto/cast/asm/readme | |||
@@ -0,0 +1,7 @@ | |||
1 | There is a ppro flag in cast-586 which turns on/off | ||
2 | generation of pentium pro/II friendly code | ||
3 | |||
4 | This flag makes the inner loop one cycle longer, but generates | ||
5 | code that runs %30 faster on the pentium pro/II, while only %7 slower | ||
6 | on the pentium. By default, this flag is on. | ||
7 | |||
diff --git a/src/lib/libcrypto/cast/cast_spd.c b/src/lib/libcrypto/cast/cast_spd.c new file mode 100644 index 0000000000..ab75e65386 --- /dev/null +++ b/src/lib/libcrypto/cast/cast_spd.c | |||
@@ -0,0 +1,294 @@ | |||
1 | /* crypto/cast/cast_spd.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 | /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ | ||
60 | /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ | ||
61 | |||
62 | #ifndef MSDOS | ||
63 | #define TIMES | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | #ifndef MSDOS | ||
68 | #include <unistd.h> | ||
69 | #else | ||
70 | #include <io.h> | ||
71 | extern int exit(); | ||
72 | #endif | ||
73 | #include <signal.h> | ||
74 | #ifndef VMS | ||
75 | #ifndef _IRIX | ||
76 | #include <time.h> | ||
77 | #endif | ||
78 | #ifdef TIMES | ||
79 | #include <sys/types.h> | ||
80 | #include <sys/times.h> | ||
81 | #endif | ||
82 | #else /* VMS */ | ||
83 | #include <types.h> | ||
84 | struct tms { | ||
85 | time_t tms_utime; | ||
86 | time_t tms_stime; | ||
87 | time_t tms_uchild; /* I dunno... */ | ||
88 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
89 | } | ||
90 | #endif | ||
91 | #ifndef TIMES | ||
92 | #include <sys/timeb.h> | ||
93 | #endif | ||
94 | |||
95 | #ifdef sun | ||
96 | #include <limits.h> | ||
97 | #include <sys/param.h> | ||
98 | #endif | ||
99 | |||
100 | #include "cast.h" | ||
101 | |||
102 | /* The following if from times(3) man page. It may need to be changed */ | ||
103 | #ifndef HZ | ||
104 | #ifndef CLK_TCK | ||
105 | #ifndef VMS | ||
106 | #define HZ 100.0 | ||
107 | #else /* VMS */ | ||
108 | #define HZ 100.0 | ||
109 | #endif | ||
110 | #else /* CLK_TCK */ | ||
111 | #define HZ ((double)CLK_TCK) | ||
112 | #endif | ||
113 | #endif | ||
114 | |||
115 | #define BUFSIZE ((long)1024) | ||
116 | long run=0; | ||
117 | |||
118 | #ifndef NOPROTO | ||
119 | double Time_F(int s); | ||
120 | #else | ||
121 | double Time_F(); | ||
122 | #endif | ||
123 | |||
124 | #ifdef SIGALRM | ||
125 | #if defined(__STDC__) || defined(sgi) || defined(_AIX) | ||
126 | #define SIGRETTYPE void | ||
127 | #else | ||
128 | #define SIGRETTYPE int | ||
129 | #endif | ||
130 | |||
131 | #ifndef NOPROTO | ||
132 | SIGRETTYPE sig_done(int sig); | ||
133 | #else | ||
134 | SIGRETTYPE sig_done(); | ||
135 | #endif | ||
136 | |||
137 | SIGRETTYPE sig_done(sig) | ||
138 | int sig; | ||
139 | { | ||
140 | signal(SIGALRM,sig_done); | ||
141 | run=0; | ||
142 | #ifdef LINT | ||
143 | sig=sig; | ||
144 | #endif | ||
145 | } | ||
146 | #endif | ||
147 | |||
148 | #define START 0 | ||
149 | #define STOP 1 | ||
150 | |||
151 | double Time_F(s) | ||
152 | int s; | ||
153 | { | ||
154 | double ret; | ||
155 | #ifdef TIMES | ||
156 | static struct tms tstart,tend; | ||
157 | |||
158 | if (s == START) | ||
159 | { | ||
160 | times(&tstart); | ||
161 | return(0); | ||
162 | } | ||
163 | else | ||
164 | { | ||
165 | times(&tend); | ||
166 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
167 | return((ret == 0.0)?1e-6:ret); | ||
168 | } | ||
169 | #else /* !times() */ | ||
170 | static struct timeb tstart,tend; | ||
171 | long i; | ||
172 | |||
173 | if (s == START) | ||
174 | { | ||
175 | ftime(&tstart); | ||
176 | return(0); | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | ftime(&tend); | ||
181 | i=(long)tend.millitm-(long)tstart.millitm; | ||
182 | ret=((double)(tend.time-tstart.time))+((double)i)/1e3; | ||
183 | return((ret == 0.0)?1e-6:ret); | ||
184 | } | ||
185 | #endif | ||
186 | } | ||
187 | |||
188 | int main(argc,argv) | ||
189 | int argc; | ||
190 | char **argv; | ||
191 | { | ||
192 | long count; | ||
193 | static unsigned char buf[BUFSIZE]; | ||
194 | static unsigned char key[] ={ | ||
195 | 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | ||
196 | 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10, | ||
197 | }; | ||
198 | CAST_KEY sch; | ||
199 | double a,b,c,d; | ||
200 | #ifndef SIGALRM | ||
201 | long ca,cb,cc; | ||
202 | #endif | ||
203 | |||
204 | #ifndef TIMES | ||
205 | printf("To get the most acurate results, try to run this\n"); | ||
206 | printf("program when this computer is idle.\n"); | ||
207 | #endif | ||
208 | |||
209 | #ifndef SIGALRM | ||
210 | printf("First we calculate the approximate speed ...\n"); | ||
211 | CAST_set_key(&sch,16,key); | ||
212 | count=10; | ||
213 | do { | ||
214 | long i; | ||
215 | CAST_LONG data[2]; | ||
216 | |||
217 | count*=2; | ||
218 | Time_F(START); | ||
219 | for (i=count; i; i--) | ||
220 | CAST_encrypt(data,&sch); | ||
221 | d=Time_F(STOP); | ||
222 | } while (d < 3.0); | ||
223 | ca=count/512; | ||
224 | cb=count; | ||
225 | cc=count*8/BUFSIZE+1; | ||
226 | printf("Doing CAST_set_key %ld times\n",ca); | ||
227 | #define COND(d) (count != (d)) | ||
228 | #define COUNT(d) (d) | ||
229 | #else | ||
230 | #define COND(c) (run) | ||
231 | #define COUNT(d) (count) | ||
232 | signal(SIGALRM,sig_done); | ||
233 | printf("Doing CAST_set_key for 10 seconds\n"); | ||
234 | alarm(10); | ||
235 | #endif | ||
236 | |||
237 | Time_F(START); | ||
238 | for (count=0,run=1; COND(ca); count+=4) | ||
239 | { | ||
240 | CAST_set_key(&sch,16,key); | ||
241 | CAST_set_key(&sch,16,key); | ||
242 | CAST_set_key(&sch,16,key); | ||
243 | CAST_set_key(&sch,16,key); | ||
244 | } | ||
245 | d=Time_F(STOP); | ||
246 | printf("%ld cast set_key's in %.2f seconds\n",count,d); | ||
247 | a=((double)COUNT(ca))/d; | ||
248 | |||
249 | #ifdef SIGALRM | ||
250 | printf("Doing CAST_encrypt's for 10 seconds\n"); | ||
251 | alarm(10); | ||
252 | #else | ||
253 | printf("Doing CAST_encrypt %ld times\n",cb); | ||
254 | #endif | ||
255 | Time_F(START); | ||
256 | for (count=0,run=1; COND(cb); count+=4) | ||
257 | { | ||
258 | CAST_LONG data[2]; | ||
259 | |||
260 | CAST_encrypt(data,&sch); | ||
261 | CAST_encrypt(data,&sch); | ||
262 | CAST_encrypt(data,&sch); | ||
263 | CAST_encrypt(data,&sch); | ||
264 | } | ||
265 | d=Time_F(STOP); | ||
266 | printf("%ld CAST_encrypt's in %.2f second\n",count,d); | ||
267 | b=((double)COUNT(cb)*8)/d; | ||
268 | |||
269 | #ifdef SIGALRM | ||
270 | printf("Doing CAST_cbc_encrypt on %ld byte blocks for 10 seconds\n", | ||
271 | BUFSIZE); | ||
272 | alarm(10); | ||
273 | #else | ||
274 | printf("Doing CAST_cbc_encrypt %ld times on %ld byte blocks\n",cc, | ||
275 | BUFSIZE); | ||
276 | #endif | ||
277 | Time_F(START); | ||
278 | for (count=0,run=1; COND(cc); count++) | ||
279 | CAST_cbc_encrypt(buf,buf,BUFSIZE,&sch, | ||
280 | &(key[0]),CAST_ENCRYPT); | ||
281 | d=Time_F(STOP); | ||
282 | printf("%ld CAST_cbc_encrypt's of %ld byte blocks in %.2f second\n", | ||
283 | count,BUFSIZE,d); | ||
284 | c=((double)COUNT(cc)*BUFSIZE)/d; | ||
285 | |||
286 | printf("CAST set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a); | ||
287 | printf("CAST raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b); | ||
288 | printf("CAST cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c); | ||
289 | exit(0); | ||
290 | #if defined(LINT) || defined(MSDOS) | ||
291 | return(0); | ||
292 | #endif | ||
293 | } | ||
294 | |||
diff --git a/src/lib/libcrypto/cast/castopts.c b/src/lib/libcrypto/cast/castopts.c new file mode 100644 index 0000000000..68cf5a4a60 --- /dev/null +++ b/src/lib/libcrypto/cast/castopts.c | |||
@@ -0,0 +1,358 @@ | |||
1 | /* crypto/cast/castopts.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 | /* define PART1, PART2, PART3 or PART4 to build only with a few of the options. | ||
60 | * This is for machines with 64k code segment size restrictions. */ | ||
61 | |||
62 | #ifndef MSDOS | ||
63 | #define TIMES | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | #ifndef MSDOS | ||
68 | #include <unistd.h> | ||
69 | #else | ||
70 | #include <io.h> | ||
71 | extern void exit(); | ||
72 | #endif | ||
73 | #include <signal.h> | ||
74 | #ifndef VMS | ||
75 | #ifndef _IRIX | ||
76 | #include <time.h> | ||
77 | #endif | ||
78 | #ifdef TIMES | ||
79 | #include <sys/types.h> | ||
80 | #include <sys/times.h> | ||
81 | #endif | ||
82 | #else /* VMS */ | ||
83 | #include <types.h> | ||
84 | struct tms { | ||
85 | time_t tms_utime; | ||
86 | time_t tms_stime; | ||
87 | time_t tms_uchild; /* I dunno... */ | ||
88 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
89 | } | ||
90 | #endif | ||
91 | #ifndef TIMES | ||
92 | #include <sys/timeb.h> | ||
93 | #endif | ||
94 | |||
95 | #ifdef sun | ||
96 | #include <limits.h> | ||
97 | #include <sys/param.h> | ||
98 | #endif | ||
99 | |||
100 | #include "cast.h" | ||
101 | |||
102 | #define CAST_DEFAULT_OPTIONS | ||
103 | |||
104 | #undef E_CAST | ||
105 | #define CAST_encrypt CAST_encrypt_normal | ||
106 | #define CAST_decrypt CAST_decrypt_normal | ||
107 | #define CAST_cbc_encrypt CAST_cbc_encrypt_normal | ||
108 | #undef HEADER_CAST_LOCL_H | ||
109 | #include "c_enc.c" | ||
110 | |||
111 | #define CAST_PTR | ||
112 | #undef CAST_PTR2 | ||
113 | #undef E_CAST | ||
114 | #undef CAST_encrypt | ||
115 | #undef CAST_decrypt | ||
116 | #undef CAST_cbc_encrypt | ||
117 | #define CAST_encrypt CAST_encrypt_ptr | ||
118 | #define CAST_decrypt CAST_decrypt_ptr | ||
119 | #define CAST_cbc_encrypt CAST_cbc_encrypt_ptr | ||
120 | #undef HEADER_CAST_LOCL_H | ||
121 | #include "c_enc.c" | ||
122 | |||
123 | #undef CAST_PTR | ||
124 | #define CAST_PTR2 | ||
125 | #undef E_CAST | ||
126 | #undef CAST_encrypt | ||
127 | #undef CAST_decrypt | ||
128 | #undef CAST_cbc_encrypt | ||
129 | #define CAST_encrypt CAST_encrypt_ptr2 | ||
130 | #define CAST_decrypt CAST_decrypt_ptr2 | ||
131 | #define CAST_cbc_encrypt CAST_cbc_encrypt_ptr2 | ||
132 | #undef HEADER_CAST_LOCL_H | ||
133 | #include "c_enc.c" | ||
134 | |||
135 | /* The following if from times(3) man page. It may need to be changed */ | ||
136 | #ifndef HZ | ||
137 | # ifndef CLK_TCK | ||
138 | # ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ | ||
139 | # ifndef VMS | ||
140 | # define HZ 100.0 | ||
141 | # else /* VMS */ | ||
142 | # define HZ 100.0 | ||
143 | # endif | ||
144 | # else /* _BSD_CLK_TCK_ */ | ||
145 | # define HZ ((double)_BSD_CLK_TCK_) | ||
146 | # endif | ||
147 | # else /* CLK_TCK */ | ||
148 | # define HZ ((double)CLK_TCK) | ||
149 | # endif | ||
150 | #endif | ||
151 | |||
152 | #define BUFSIZE ((long)1024) | ||
153 | long run=0; | ||
154 | |||
155 | #ifndef NOPROTO | ||
156 | double Time_F(int s); | ||
157 | #else | ||
158 | double Time_F(); | ||
159 | #endif | ||
160 | |||
161 | #ifdef SIGALRM | ||
162 | #if defined(__STDC__) || defined(sgi) | ||
163 | #define SIGRETTYPE void | ||
164 | #else | ||
165 | #define SIGRETTYPE int | ||
166 | #endif | ||
167 | |||
168 | #ifndef NOPROTO | ||
169 | SIGRETTYPE sig_done(int sig); | ||
170 | #else | ||
171 | SIGRETTYPE sig_done(); | ||
172 | #endif | ||
173 | |||
174 | SIGRETTYPE sig_done(sig) | ||
175 | int sig; | ||
176 | { | ||
177 | signal(SIGALRM,sig_done); | ||
178 | run=0; | ||
179 | #ifdef LINT | ||
180 | sig=sig; | ||
181 | #endif | ||
182 | } | ||
183 | #endif | ||
184 | |||
185 | #define START 0 | ||
186 | #define STOP 1 | ||
187 | |||
188 | double Time_F(s) | ||
189 | int s; | ||
190 | { | ||
191 | double ret; | ||
192 | #ifdef TIMES | ||
193 | static struct tms tstart,tend; | ||
194 | |||
195 | if (s == START) | ||
196 | { | ||
197 | times(&tstart); | ||
198 | return(0); | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | times(&tend); | ||
203 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
204 | return((ret == 0.0)?1e-6:ret); | ||
205 | } | ||
206 | #else /* !times() */ | ||
207 | static struct timeb tstart,tend; | ||
208 | long i; | ||
209 | |||
210 | if (s == START) | ||
211 | { | ||
212 | ftime(&tstart); | ||
213 | return(0); | ||
214 | } | ||
215 | else | ||
216 | { | ||
217 | ftime(&tend); | ||
218 | i=(long)tend.millitm-(long)tstart.millitm; | ||
219 | ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; | ||
220 | return((ret == 0.0)?1e-6:ret); | ||
221 | } | ||
222 | #endif | ||
223 | } | ||
224 | |||
225 | #ifdef SIGALRM | ||
226 | #define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10); | ||
227 | #else | ||
228 | #define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb); | ||
229 | #endif | ||
230 | |||
231 | #define time_it(func,name,index) \ | ||
232 | print_name(name); \ | ||
233 | Time_F(START); \ | ||
234 | for (count=0,run=1; COND(cb); count+=4) \ | ||
235 | { \ | ||
236 | unsigned long d[2]; \ | ||
237 | func(d,&sch); \ | ||
238 | func(d,&sch); \ | ||
239 | func(d,&sch); \ | ||
240 | func(d,&sch); \ | ||
241 | } \ | ||
242 | tm[index]=Time_F(STOP); \ | ||
243 | fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \ | ||
244 | tm[index]=((double)COUNT(cb))/tm[index]; | ||
245 | |||
246 | #define print_it(name,index) \ | ||
247 | fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \ | ||
248 | tm[index]*8,1.0e6/tm[index]); | ||
249 | |||
250 | int main(argc,argv) | ||
251 | int argc; | ||
252 | char **argv; | ||
253 | { | ||
254 | long count; | ||
255 | static unsigned char buf[BUFSIZE]; | ||
256 | static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | ||
257 | 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; | ||
258 | CAST_KEY sch; | ||
259 | double d,tm[16],max=0; | ||
260 | int rank[16]; | ||
261 | char *str[16]; | ||
262 | int max_idx=0,i,num=0,j; | ||
263 | #ifndef SIGALARM | ||
264 | long ca,cb,cc,cd,ce; | ||
265 | #endif | ||
266 | |||
267 | for (i=0; i<12; i++) | ||
268 | { | ||
269 | tm[i]=0.0; | ||
270 | rank[i]=0; | ||
271 | } | ||
272 | |||
273 | #ifndef TIMES | ||
274 | fprintf(stderr,"To get the most acurate results, try to run this\n"); | ||
275 | fprintf(stderr,"program when this computer is idle.\n"); | ||
276 | #endif | ||
277 | |||
278 | CAST_set_key(&sch,16,key); | ||
279 | |||
280 | #ifndef SIGALRM | ||
281 | fprintf(stderr,"First we calculate the approximate speed ...\n"); | ||
282 | count=10; | ||
283 | do { | ||
284 | long i; | ||
285 | unsigned long data[2]; | ||
286 | |||
287 | count*=2; | ||
288 | Time_F(START); | ||
289 | for (i=count; i; i--) | ||
290 | CAST_encrypt(data,&sch); | ||
291 | d=Time_F(STOP); | ||
292 | } while (d < 3.0); | ||
293 | ca=count; | ||
294 | cb=count*3; | ||
295 | cc=count*3*8/BUFSIZE+1; | ||
296 | cd=count*8/BUFSIZE+1; | ||
297 | |||
298 | ce=count/20+1; | ||
299 | #define COND(d) (count != (d)) | ||
300 | #define COUNT(d) (d) | ||
301 | #else | ||
302 | #define COND(c) (run) | ||
303 | #define COUNT(d) (count) | ||
304 | signal(SIGALRM,sig_done); | ||
305 | alarm(10); | ||
306 | #endif | ||
307 | |||
308 | time_it(CAST_encrypt_normal, "CAST_encrypt_normal ", 0); | ||
309 | time_it(CAST_encrypt_ptr, "CAST_encrypt_ptr ", 1); | ||
310 | time_it(CAST_encrypt_ptr2, "CAST_encrypt_ptr2 ", 2); | ||
311 | num+=3; | ||
312 | |||
313 | str[0]="<nothing>"; | ||
314 | print_it("CAST_encrypt_normal ",0); | ||
315 | max=tm[0]; | ||
316 | max_idx=0; | ||
317 | str[1]="ptr "; | ||
318 | print_it("CAST_encrypt_ptr ",1); | ||
319 | if (max < tm[1]) { max=tm[1]; max_idx=1; } | ||
320 | str[2]="ptr2 "; | ||
321 | print_it("CAST_encrypt_ptr2 ",2); | ||
322 | if (max < tm[2]) { max=tm[2]; max_idx=2; } | ||
323 | |||
324 | printf("options CAST ecb/s\n"); | ||
325 | printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]); | ||
326 | d=tm[max_idx]; | ||
327 | tm[max_idx]= -2.0; | ||
328 | max= -1.0; | ||
329 | for (;;) | ||
330 | { | ||
331 | for (i=0; i<3; i++) | ||
332 | { | ||
333 | if (max < tm[i]) { max=tm[i]; j=i; } | ||
334 | } | ||
335 | if (max < 0.0) break; | ||
336 | printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0); | ||
337 | tm[j]= -2.0; | ||
338 | max= -1.0; | ||
339 | } | ||
340 | |||
341 | switch (max_idx) | ||
342 | { | ||
343 | case 0: | ||
344 | printf("-DCAST_DEFAULT_OPTIONS\n"); | ||
345 | break; | ||
346 | case 1: | ||
347 | printf("-DCAST_PTR\n"); | ||
348 | break; | ||
349 | case 2: | ||
350 | printf("-DCAST_PTR2\n"); | ||
351 | break; | ||
352 | } | ||
353 | exit(0); | ||
354 | #if defined(LINT) || defined(MSDOS) | ||
355 | return(0); | ||
356 | #endif | ||
357 | } | ||
358 | |||
diff --git a/src/lib/libcrypto/cast/casts.cpp b/src/lib/libcrypto/cast/casts.cpp new file mode 100644 index 0000000000..bac7be2c9c --- /dev/null +++ b/src/lib/libcrypto/cast/casts.cpp | |||
@@ -0,0 +1,70 @@ | |||
1 | // | ||
2 | // gettsc.inl | ||
3 | // | ||
4 | // gives access to the Pentium's (secret) cycle counter | ||
5 | // | ||
6 | // This software was written by Leonard Janke (janke@unixg.ubc.ca) | ||
7 | // in 1996-7 and is entered, by him, into the public domain. | ||
8 | |||
9 | #if defined(__WATCOMC__) | ||
10 | void GetTSC(unsigned long&); | ||
11 | #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; | ||
12 | #elif defined(__GNUC__) | ||
13 | inline | ||
14 | void GetTSC(unsigned long& tsc) | ||
15 | { | ||
16 | asm volatile(".byte 15, 49\n\t" | ||
17 | : "=eax" (tsc) | ||
18 | : | ||
19 | : "%edx", "%eax"); | ||
20 | } | ||
21 | #elif defined(_MSC_VER) | ||
22 | inline | ||
23 | void GetTSC(unsigned long& tsc) | ||
24 | { | ||
25 | unsigned long a; | ||
26 | __asm _emit 0fh | ||
27 | __asm _emit 31h | ||
28 | __asm mov a, eax; | ||
29 | tsc=a; | ||
30 | } | ||
31 | #endif | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include <stdlib.h> | ||
35 | #include "cast.h" | ||
36 | |||
37 | void main(int argc,char *argv[]) | ||
38 | { | ||
39 | CAST_KEY key; | ||
40 | unsigned long s1,s2,e1,e2; | ||
41 | unsigned long data[2]; | ||
42 | int i,j; | ||
43 | static unsigned char d[16]={0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; | ||
44 | |||
45 | CAST_set_key(&key, 16,d); | ||
46 | |||
47 | for (j=0; j<6; j++) | ||
48 | { | ||
49 | for (i=0; i<1000; i++) /**/ | ||
50 | { | ||
51 | CAST_encrypt(&data[0],&key); | ||
52 | GetTSC(s1); | ||
53 | CAST_encrypt(&data[0],&key); | ||
54 | CAST_encrypt(&data[0],&key); | ||
55 | CAST_encrypt(&data[0],&key); | ||
56 | GetTSC(e1); | ||
57 | GetTSC(s2); | ||
58 | CAST_encrypt(&data[0],&key); | ||
59 | CAST_encrypt(&data[0],&key); | ||
60 | CAST_encrypt(&data[0],&key); | ||
61 | CAST_encrypt(&data[0],&key); | ||
62 | GetTSC(e2); | ||
63 | CAST_encrypt(&data[0],&key); | ||
64 | } | ||
65 | |||
66 | printf("cast %d %d (%d)\n", | ||
67 | e1-s1,e2-s2,((e2-s2)-(e1-s1))); | ||
68 | } | ||
69 | } | ||
70 | |||
diff --git a/src/lib/libcrypto/cast/casttest.c b/src/lib/libcrypto/cast/casttest.c new file mode 100644 index 0000000000..8b009bc249 --- /dev/null +++ b/src/lib/libcrypto/cast/casttest.c | |||
@@ -0,0 +1,223 @@ | |||
1 | /* crypto/cast/casttest.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 <string.h> | ||
61 | #include <stdlib.h> | ||
62 | #include "cast.h" | ||
63 | |||
64 | /* #define FULL_TEST */ | ||
65 | |||
66 | unsigned char k[16]={ | ||
67 | 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, | ||
68 | 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A | ||
69 | }; | ||
70 | |||
71 | unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; | ||
72 | |||
73 | int k_len[3]={16,10}; | ||
74 | unsigned char c[3][8]={ | ||
75 | {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2}, | ||
76 | {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B}, | ||
77 | {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E}, | ||
78 | }; | ||
79 | unsigned char out[80]; | ||
80 | |||
81 | unsigned char in_a[16]={ | ||
82 | 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, | ||
83 | 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A}; | ||
84 | unsigned char in_b[16]={ | ||
85 | 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, | ||
86 | 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A}; | ||
87 | |||
88 | unsigned char c_a[16]={ | ||
89 | 0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6, | ||
90 | 0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92}; | ||
91 | unsigned char c_b[16]={ | ||
92 | 0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71, | ||
93 | 0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E}; | ||
94 | |||
95 | #if 0 | ||
96 | char *text="Hello to all people out there"; | ||
97 | |||
98 | static unsigned char cfb_key[16]={ | ||
99 | 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, | ||
100 | 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, | ||
101 | }; | ||
102 | static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; | ||
103 | static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; | ||
104 | #define CFB_TEST_SIZE 24 | ||
105 | static unsigned char plain[CFB_TEST_SIZE]= | ||
106 | { | ||
107 | 0x4e,0x6f,0x77,0x20,0x69,0x73, | ||
108 | 0x20,0x74,0x68,0x65,0x20,0x74, | ||
109 | 0x69,0x6d,0x65,0x20,0x66,0x6f, | ||
110 | 0x72,0x20,0x61,0x6c,0x6c,0x20 | ||
111 | }; | ||
112 | static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ | ||
113 | 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, | ||
114 | 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, | ||
115 | 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 | ||
116 | |||
117 | /* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, | ||
118 | 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, | ||
119 | 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ | ||
120 | }; | ||
121 | #endif | ||
122 | |||
123 | int main(argc,argv) | ||
124 | int argc; | ||
125 | char *argv[]; | ||
126 | { | ||
127 | #ifdef FULL_TEST | ||
128 | long l; | ||
129 | CAST_KEY key_b; | ||
130 | #endif | ||
131 | int i,z,err=0; | ||
132 | CAST_KEY key; | ||
133 | |||
134 | for (z=0; z<1; z++) | ||
135 | { | ||
136 | CAST_set_key(&key,k_len[z],k); | ||
137 | |||
138 | CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT); | ||
139 | if (memcmp(out,&(c[z][0]),8) != 0) | ||
140 | { | ||
141 | printf("ecb cast error encrypting\n"); | ||
142 | printf("got :"); | ||
143 | for (i=0; i<8; i++) | ||
144 | printf("%02X ",out[i]); | ||
145 | printf("\n"); | ||
146 | printf("expected:"); | ||
147 | for (i=0; i<8; i++) | ||
148 | printf("%02X ",c[z][i]); | ||
149 | err=20; | ||
150 | printf("\n"); | ||
151 | } | ||
152 | |||
153 | CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT); | ||
154 | if (memcmp(out,in,8) != 0) | ||
155 | { | ||
156 | printf("ecb cast error decrypting\n"); | ||
157 | printf("got :"); | ||
158 | for (i=0; i<8; i++) | ||
159 | printf("%02X ",out[i]); | ||
160 | printf("\n"); | ||
161 | printf("expected:"); | ||
162 | for (i=0; i<8; i++) | ||
163 | printf("%02X ",in[i]); | ||
164 | printf("\n"); | ||
165 | err=3; | ||
166 | } | ||
167 | } | ||
168 | if (err == 0) printf("ecb cast5 ok\n"); | ||
169 | |||
170 | #ifdef FULL_TEST | ||
171 | { | ||
172 | unsigned char out_a[16],out_b[16]; | ||
173 | static char *hex="0123456789ABCDEF"; | ||
174 | |||
175 | printf("This test will take some time...."); | ||
176 | fflush(stdout); | ||
177 | memcpy(out_a,in_a,sizeof(in_a)); | ||
178 | memcpy(out_b,in_b,sizeof(in_b)); | ||
179 | i=1; | ||
180 | |||
181 | for (l=0; l<1000000L; l++) | ||
182 | { | ||
183 | CAST_set_key(&key_b,16,out_b); | ||
184 | CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT); | ||
185 | CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT); | ||
186 | CAST_set_key(&key,16,out_a); | ||
187 | CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT); | ||
188 | CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT); | ||
189 | if ((l & 0xffff) == 0xffff) | ||
190 | { | ||
191 | printf("%c",hex[i&0x0f]); | ||
192 | fflush(stdout); | ||
193 | i++; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) || | ||
198 | (memcmp(out_b,c_b,sizeof(c_b)) != 0)) | ||
199 | { | ||
200 | printf("\n"); | ||
201 | printf("Error\n"); | ||
202 | |||
203 | printf("A out ="); | ||
204 | for (i=0; i<16; i++) printf("%02X ",out_a[i]); | ||
205 | printf("\nactual="); | ||
206 | for (i=0; i<16; i++) printf("%02X ",c_a[i]); | ||
207 | printf("\n"); | ||
208 | |||
209 | printf("B out ="); | ||
210 | for (i=0; i<16; i++) printf("%02X ",out_b[i]); | ||
211 | printf("\nactual="); | ||
212 | for (i=0; i<16; i++) printf("%02X ",c_b[i]); | ||
213 | printf("\n"); | ||
214 | } | ||
215 | else | ||
216 | printf(" ok\n"); | ||
217 | } | ||
218 | #endif | ||
219 | |||
220 | exit(err); | ||
221 | return(err); | ||
222 | } | ||
223 | |||
diff --git a/src/lib/libcrypto/conf/cnf_save.c b/src/lib/libcrypto/conf/cnf_save.c new file mode 100644 index 0000000000..c9018de10e --- /dev/null +++ b/src/lib/libcrypto/conf/cnf_save.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* crypto/conf/cnf_save.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 "conf.h" | ||
61 | |||
62 | void print_conf(CONF_VALUE *cv); | ||
63 | |||
64 | main() | ||
65 | { | ||
66 | LHASH *conf; | ||
67 | long l; | ||
68 | |||
69 | conf=CONF_load(NULL,"../../apps/ssleay.cnf",&l); | ||
70 | if (conf == NULL) | ||
71 | { | ||
72 | fprintf(stderr,"error loading config, line %ld\n",l); | ||
73 | exit(1); | ||
74 | } | ||
75 | |||
76 | lh_doall(conf,print_conf); | ||
77 | } | ||
78 | |||
79 | |||
80 | void print_conf(cv) | ||
81 | CONF_VALUE *cv; | ||
82 | { | ||
83 | int i; | ||
84 | CONF_VALUE *v; | ||
85 | char *section; | ||
86 | char *name; | ||
87 | char *value; | ||
88 | STACK *s; | ||
89 | |||
90 | /* If it is a single entry, return */ | ||
91 | |||
92 | if (cv->name != NULL) return; | ||
93 | |||
94 | printf("[ %s ]\n",cv->section); | ||
95 | s=(STACK *)cv->value; | ||
96 | |||
97 | for (i=0; i<sk_num(s); i++) | ||
98 | { | ||
99 | v=(CONF_VALUE *)sk_value(s,i); | ||
100 | section=(v->section == NULL)?"None":v->section; | ||
101 | name=(v->name == NULL)?"None":v->name; | ||
102 | value=(v->value == NULL)?"None":v->value; | ||
103 | printf("%s=%s\n",name,value); | ||
104 | } | ||
105 | printf("\n"); | ||
106 | } | ||
diff --git a/src/lib/libcrypto/conf/test.c b/src/lib/libcrypto/conf/test.c new file mode 100644 index 0000000000..899ee2a067 --- /dev/null +++ b/src/lib/libcrypto/conf/test.c | |||
@@ -0,0 +1,91 @@ | |||
1 | /* crypto/conf/test.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 <stdlib.h> | ||
61 | #include "conf.h" | ||
62 | |||
63 | main() | ||
64 | { | ||
65 | LHASH *conf; | ||
66 | long eline; | ||
67 | char *s,*s2; | ||
68 | |||
69 | conf=CONF_load(NULL,"ssleay.conf",&eline); | ||
70 | if (conf == NULL) | ||
71 | { | ||
72 | ERR_load_crypto_strings(); | ||
73 | printf("unable to load configuration, line %ld\n",eline); | ||
74 | ERR_print_errors_fp(stderr); | ||
75 | exit(1); | ||
76 | } | ||
77 | lh_stats(conf,stdout); | ||
78 | lh_node_stats(conf,stdout); | ||
79 | lh_node_usage_stats(conf,stdout); | ||
80 | |||
81 | s=CONF_get_string(conf,NULL,"init2"); | ||
82 | printf("init2=%s\n",(s == NULL)?"NULL":s); | ||
83 | |||
84 | s=CONF_get_string(conf,NULL,"cipher1"); | ||
85 | printf("cipher1=%s\n",(s == NULL)?"NULL":s); | ||
86 | |||
87 | s=CONF_get_string(conf,"s_client","cipher1"); | ||
88 | printf("s_client:cipher1=%s\n",(s == NULL)?"NULL":s); | ||
89 | |||
90 | exit(0); | ||
91 | } | ||
diff --git a/src/lib/libcrypto/des/DES.pm b/src/lib/libcrypto/des/DES.pm new file mode 100644 index 0000000000..6a175b6ca4 --- /dev/null +++ b/src/lib/libcrypto/des/DES.pm | |||
@@ -0,0 +1,19 @@ | |||
1 | package DES; | ||
2 | |||
3 | require Exporter; | ||
4 | require DynaLoader; | ||
5 | @ISA = qw(Exporter DynaLoader); | ||
6 | # Items to export into callers namespace by default | ||
7 | # (move infrequently used names to @EXPORT_OK below) | ||
8 | @EXPORT = qw( | ||
9 | ); | ||
10 | # Other items we are prepared to export if requested | ||
11 | @EXPORT_OK = qw( | ||
12 | crypt | ||
13 | ); | ||
14 | |||
15 | # Preloaded methods go here. Autoload methods go after __END__, and are | ||
16 | # processed by the autosplit program. | ||
17 | bootstrap DES; | ||
18 | 1; | ||
19 | __END__ | ||
diff --git a/src/lib/libcrypto/des/DES.xs b/src/lib/libcrypto/des/DES.xs new file mode 100644 index 0000000000..b8050b9edf --- /dev/null +++ b/src/lib/libcrypto/des/DES.xs | |||
@@ -0,0 +1,268 @@ | |||
1 | #include "EXTERN.h" | ||
2 | #include "perl.h" | ||
3 | #include "XSUB.h" | ||
4 | #include "des.h" | ||
5 | |||
6 | #define deschar char | ||
7 | static STRLEN len; | ||
8 | |||
9 | static int | ||
10 | not_here(s) | ||
11 | char *s; | ||
12 | { | ||
13 | croak("%s not implemented on this architecture", s); | ||
14 | return -1; | ||
15 | } | ||
16 | |||
17 | MODULE = DES PACKAGE = DES PREFIX = des_ | ||
18 | |||
19 | char * | ||
20 | des_crypt(buf,salt) | ||
21 | char * buf | ||
22 | char * salt | ||
23 | |||
24 | void | ||
25 | des_set_odd_parity(key) | ||
26 | des_cblock * key | ||
27 | PPCODE: | ||
28 | { | ||
29 | SV *s; | ||
30 | |||
31 | s=sv_newmortal(); | ||
32 | sv_setpvn(s,(char *)key,8); | ||
33 | des_set_odd_parity((des_cblock *)SvPV(s,na)); | ||
34 | PUSHs(s); | ||
35 | } | ||
36 | |||
37 | int | ||
38 | des_is_weak_key(key) | ||
39 | des_cblock * key | ||
40 | |||
41 | des_key_schedule | ||
42 | des_set_key(key) | ||
43 | des_cblock * key | ||
44 | CODE: | ||
45 | des_set_key(key,RETVAL); | ||
46 | OUTPUT: | ||
47 | RETVAL | ||
48 | |||
49 | des_cblock | ||
50 | des_ecb_encrypt(input,ks,encrypt) | ||
51 | des_cblock * input | ||
52 | des_key_schedule * ks | ||
53 | int encrypt | ||
54 | CODE: | ||
55 | des_ecb_encrypt(input,&RETVAL,*ks,encrypt); | ||
56 | OUTPUT: | ||
57 | RETVAL | ||
58 | |||
59 | void | ||
60 | des_cbc_encrypt(input,ks,ivec,encrypt) | ||
61 | char * input | ||
62 | des_key_schedule * ks | ||
63 | des_cblock * ivec | ||
64 | int encrypt | ||
65 | PPCODE: | ||
66 | { | ||
67 | SV *s; | ||
68 | STRLEN len,l; | ||
69 | char *c; | ||
70 | |||
71 | l=SvCUR(ST(0)); | ||
72 | len=((((unsigned long)l)+7)/8)*8; | ||
73 | s=sv_newmortal(); | ||
74 | sv_setpvn(s,"",0); | ||
75 | SvGROW(s,len); | ||
76 | SvCUR_set(s,len); | ||
77 | c=(char *)SvPV(s,na); | ||
78 | des_cbc_encrypt((des_cblock *)input,(des_cblock *)c, | ||
79 | l,*ks,ivec,encrypt); | ||
80 | sv_setpvn(ST(2),(char *)c[len-8],8); | ||
81 | PUSHs(s); | ||
82 | } | ||
83 | |||
84 | void | ||
85 | des_cbc3_encrypt(input,ks1,ks2,ivec1,ivec2,encrypt) | ||
86 | char * input | ||
87 | des_key_schedule * ks1 | ||
88 | des_key_schedule * ks2 | ||
89 | des_cblock * ivec1 | ||
90 | des_cblock * ivec2 | ||
91 | int encrypt | ||
92 | PPCODE: | ||
93 | { | ||
94 | SV *s; | ||
95 | STRLEN len,l; | ||
96 | |||
97 | l=SvCUR(ST(0)); | ||
98 | len=((((unsigned long)l)+7)/8)*8; | ||
99 | s=sv_newmortal(); | ||
100 | sv_setpvn(s,"",0); | ||
101 | SvGROW(s,len); | ||
102 | SvCUR_set(s,len); | ||
103 | des_3cbc_encrypt((des_cblock *)input,(des_cblock *)SvPV(s,na), | ||
104 | l,*ks1,*ks2,ivec1,ivec2,encrypt); | ||
105 | sv_setpvn(ST(3),(char *)ivec1,8); | ||
106 | sv_setpvn(ST(4),(char *)ivec2,8); | ||
107 | PUSHs(s); | ||
108 | } | ||
109 | |||
110 | void | ||
111 | des_cbc_cksum(input,ks,ivec) | ||
112 | char * input | ||
113 | des_key_schedule * ks | ||
114 | des_cblock * ivec | ||
115 | PPCODE: | ||
116 | { | ||
117 | SV *s1,*s2; | ||
118 | STRLEN len,l; | ||
119 | des_cblock c; | ||
120 | unsigned long i1,i2; | ||
121 | |||
122 | s1=sv_newmortal(); | ||
123 | s2=sv_newmortal(); | ||
124 | l=SvCUR(ST(0)); | ||
125 | des_cbc_cksum((des_cblock *)input,(des_cblock *)c, | ||
126 | l,*ks,ivec); | ||
127 | i1=c[4]|(c[5]<<8)|(c[6]<<16)|(c[7]<<24); | ||
128 | i2=c[0]|(c[1]<<8)|(c[2]<<16)|(c[3]<<24); | ||
129 | sv_setiv(s1,i1); | ||
130 | sv_setiv(s2,i2); | ||
131 | sv_setpvn(ST(2),(char *)c,8); | ||
132 | PUSHs(s1); | ||
133 | PUSHs(s2); | ||
134 | } | ||
135 | |||
136 | void | ||
137 | des_cfb_encrypt(input,numbits,ks,ivec,encrypt) | ||
138 | char * input | ||
139 | int numbits | ||
140 | des_key_schedule * ks | ||
141 | des_cblock * ivec | ||
142 | int encrypt | ||
143 | PPCODE: | ||
144 | { | ||
145 | SV *s; | ||
146 | STRLEN len; | ||
147 | char *c; | ||
148 | |||
149 | len=SvCUR(ST(0)); | ||
150 | s=sv_newmortal(); | ||
151 | sv_setpvn(s,"",0); | ||
152 | SvGROW(s,len); | ||
153 | SvCUR_set(s,len); | ||
154 | c=(char *)SvPV(s,na); | ||
155 | des_cfb_encrypt((unsigned char *)input,(unsigned char *)c, | ||
156 | (int)numbits,(long)len,*ks,ivec,encrypt); | ||
157 | sv_setpvn(ST(3),(char *)ivec,8); | ||
158 | PUSHs(s); | ||
159 | } | ||
160 | |||
161 | des_cblock * | ||
162 | des_ecb3_encrypt(input,ks1,ks2,encrypt) | ||
163 | des_cblock * input | ||
164 | des_key_schedule * ks1 | ||
165 | des_key_schedule * ks2 | ||
166 | int encrypt | ||
167 | CODE: | ||
168 | { | ||
169 | des_cblock c; | ||
170 | |||
171 | des_ecb3_encrypt((des_cblock *)input,(des_cblock *)&c, | ||
172 | *ks1,*ks2,encrypt); | ||
173 | RETVAL= &c; | ||
174 | } | ||
175 | OUTPUT: | ||
176 | RETVAL | ||
177 | |||
178 | void | ||
179 | des_ofb_encrypt(input,numbits,ks,ivec) | ||
180 | unsigned char * input | ||
181 | int numbits | ||
182 | des_key_schedule * ks | ||
183 | des_cblock * ivec | ||
184 | PPCODE: | ||
185 | { | ||
186 | SV *s; | ||
187 | STRLEN len,l; | ||
188 | unsigned char *c; | ||
189 | |||
190 | len=SvCUR(ST(0)); | ||
191 | s=sv_newmortal(); | ||
192 | sv_setpvn(s,"",0); | ||
193 | SvGROW(s,len); | ||
194 | SvCUR_set(s,len); | ||
195 | c=(unsigned char *)SvPV(s,na); | ||
196 | des_ofb_encrypt((unsigned char *)input,(unsigned char *)c, | ||
197 | numbits,len,*ks,ivec); | ||
198 | sv_setpvn(ST(3),(char *)ivec,8); | ||
199 | PUSHs(s); | ||
200 | } | ||
201 | |||
202 | void | ||
203 | des_pcbc_encrypt(input,ks,ivec,encrypt) | ||
204 | char * input | ||
205 | des_key_schedule * ks | ||
206 | des_cblock * ivec | ||
207 | int encrypt | ||
208 | PPCODE: | ||
209 | { | ||
210 | SV *s; | ||
211 | STRLEN len,l; | ||
212 | char *c; | ||
213 | |||
214 | l=SvCUR(ST(0)); | ||
215 | len=((((unsigned long)l)+7)/8)*8; | ||
216 | s=sv_newmortal(); | ||
217 | sv_setpvn(s,"",0); | ||
218 | SvGROW(s,len); | ||
219 | SvCUR_set(s,len); | ||
220 | c=(char *)SvPV(s,na); | ||
221 | des_pcbc_encrypt((des_cblock *)input,(des_cblock *)c, | ||
222 | l,*ks,ivec,encrypt); | ||
223 | sv_setpvn(ST(2),(char *)c[len-8],8); | ||
224 | PUSHs(s); | ||
225 | } | ||
226 | |||
227 | des_cblock * | ||
228 | des_random_key() | ||
229 | CODE: | ||
230 | { | ||
231 | des_cblock c; | ||
232 | |||
233 | des_random_key(c); | ||
234 | RETVAL=&c; | ||
235 | } | ||
236 | OUTPUT: | ||
237 | RETVAL | ||
238 | |||
239 | des_cblock * | ||
240 | des_string_to_key(str) | ||
241 | char * str | ||
242 | CODE: | ||
243 | { | ||
244 | des_cblock c; | ||
245 | |||
246 | des_string_to_key(str,&c); | ||
247 | RETVAL=&c; | ||
248 | } | ||
249 | OUTPUT: | ||
250 | RETVAL | ||
251 | |||
252 | void | ||
253 | des_string_to_2keys(str) | ||
254 | char * str | ||
255 | PPCODE: | ||
256 | { | ||
257 | des_cblock c1,c2; | ||
258 | SV *s1,*s2; | ||
259 | |||
260 | des_string_to_2keys(str,&c1,&c2); | ||
261 | EXTEND(sp,2); | ||
262 | s1=sv_newmortal(); | ||
263 | sv_setpvn(s1,(char *)c1,8); | ||
264 | s2=sv_newmortal(); | ||
265 | sv_setpvn(s2,(char *)c2,8); | ||
266 | PUSHs(s1); | ||
267 | PUSHs(s2); | ||
268 | } | ||
diff --git a/src/lib/libcrypto/des/INSTALL b/src/lib/libcrypto/des/INSTALL new file mode 100644 index 0000000000..32457d775c --- /dev/null +++ b/src/lib/libcrypto/des/INSTALL | |||
@@ -0,0 +1,69 @@ | |||
1 | Check the CC and CFLAGS lines in the makefile | ||
2 | |||
3 | If your C library does not support the times(3) function, change the | ||
4 | #define TIMES to | ||
5 | #undef TIMES in speed.c | ||
6 | If it does, check the HZ value for the times(3) function. | ||
7 | If your system does not define CLK_TCK it will be assumed to | ||
8 | be 100.0. | ||
9 | |||
10 | If possible use gcc v 2.7.? | ||
11 | Turn on the maximum optimising (normally '-O3 -fomit-frame-pointer' for gcc) | ||
12 | In recent times, some system compilers give better performace. | ||
13 | |||
14 | type 'make' | ||
15 | |||
16 | run './destest' to check things are ok. | ||
17 | run './rpw' to check the tty code for reading passwords works. | ||
18 | run './speed' to see how fast those optimisations make the library run :-) | ||
19 | run './des_opts' to determin the best compile time options. | ||
20 | |||
21 | The output from des_opts should be put in the makefile options and des_enc.c | ||
22 | should be rebuilt. For 64 bit computers, do not use the DES_PTR option. | ||
23 | For the DEC Alpha, edit des.h and change DES_LONG to 'unsigned int' | ||
24 | and then you can use the 'DES_PTR' option. | ||
25 | |||
26 | The file options.txt has the options listed for best speed on quite a | ||
27 | few systems. Look and the options (UNROLL, PTR, RISC2 etc) and then | ||
28 | turn on the relevent option in the Makefile | ||
29 | |||
30 | There are some special Makefile targets that make life easier. | ||
31 | make cc - standard cc build | ||
32 | make gcc - standard gcc build | ||
33 | make x86-elf - x86 assembler (elf), linux-elf. | ||
34 | make x86-out - x86 assembler (a.out), FreeBSD | ||
35 | make x86-solaris- x86 assembler | ||
36 | make x86-bsdi - x86 assembler (a.out with primative assembler). | ||
37 | |||
38 | If at all possible use the assembler (for Windows NT/95, use | ||
39 | asm/win32.obj to link with). The x86 assembler is very very fast. | ||
40 | |||
41 | A make install will by default install | ||
42 | libdes.a in /usr/local/lib/libdes.a | ||
43 | des in /usr/local/bin/des | ||
44 | des_crypt.man in /usr/local/man/man3/des_crypt.3 | ||
45 | des.man in /usr/local/man/man1/des.1 | ||
46 | des.h in /usr/include/des.h | ||
47 | |||
48 | des(1) should be compatible with sunOS's but I have been unable to | ||
49 | test it. | ||
50 | |||
51 | These routines should compile on MSDOS, most 32bit and 64bit version | ||
52 | of Unix (BSD and SYSV) and VMS, without modification. | ||
53 | The only problems should be #include files that are in the wrong places. | ||
54 | |||
55 | These routines can be compiled under MSDOS. | ||
56 | I have successfully encrypted files using des(1) under MSDOS and then | ||
57 | decrypted the files on a SparcStation. | ||
58 | I have been able to compile and test the routines with | ||
59 | Microsoft C v 5.1 and Turbo C v 2.0. | ||
60 | The code in this library is in no way optimised for the 16bit | ||
61 | operation of MSDOS. | ||
62 | |||
63 | When building for glibc, ignore all of the above and just unpack into | ||
64 | glibc-1.??/des and then gmake as per normal. | ||
65 | |||
66 | As a final note on performace. Certain CPUs like sparcs and Alpha often give | ||
67 | a %10 speed difference depending on the link order. It is rather anoying | ||
68 | when one program reports 'x' DES encrypts a second and another reports | ||
69 | 'x*0.9' the speed. | ||
diff --git a/src/lib/libcrypto/des/Imakefile b/src/lib/libcrypto/des/Imakefile new file mode 100644 index 0000000000..1b9b5629e1 --- /dev/null +++ b/src/lib/libcrypto/des/Imakefile | |||
@@ -0,0 +1,35 @@ | |||
1 | # This Imakefile has not been tested for a while but it should still | ||
2 | # work when placed in the correct directory in the kerberos v 4 distribution | ||
3 | |||
4 | SRCS= cbc_cksm.c cbc_enc.c ecb_enc.c pcbc_enc.c \ | ||
5 | qud_cksm.c rand_key.c read_pwd.c set_key.c str2key.c \ | ||
6 | enc_read.c enc_writ.c fcrypt.c cfb_enc.c \ | ||
7 | ecb3_enc.c ofb_enc.c ofb64enc.c | ||
8 | |||
9 | OBJS= cbc_cksm.o cbc_enc.o ecb_enc.o pcbc_enc.o \ | ||
10 | qud_cksm.o rand_key.o read_pwd.o set_key.o str2key.o \ | ||
11 | enc_read.o enc_writ.o fcrypt.o cfb_enc.o \ | ||
12 | ecb3_enc.o ofb_enc.o ofb64enc.o | ||
13 | |||
14 | GENERAL=COPYRIGHT FILES INSTALL Imakefile README VERSION makefile times \ | ||
15 | vms.com KERBEROS | ||
16 | DES= des.c des.man | ||
17 | TESTING=destest.c speed.c rpw.c | ||
18 | LIBDES= des_crypt.man des.h des_locl.h podd.h sk.h spr.h | ||
19 | |||
20 | PERL= des.pl testdes.pl doIP doPC1 doPC2 PC1 PC2 shifts.pl | ||
21 | |||
22 | CODE= $(GENERAL) $(DES) $(TESTING) $(SRCS) $(LIBDES) $(PERL) | ||
23 | |||
24 | SRCDIR=$(SRCTOP)/lib/des | ||
25 | |||
26 | DBG= -O | ||
27 | INCLUDE= -I$(SRCDIR) | ||
28 | CC= cc | ||
29 | |||
30 | library_obj_rule() | ||
31 | |||
32 | install_library_target(des,$(OBJS),$(SRCS),) | ||
33 | |||
34 | test(destest,libdes.a,) | ||
35 | test(rpw,libdes.a,) | ||
diff --git a/src/lib/libcrypto/des/KERBEROS b/src/lib/libcrypto/des/KERBEROS new file mode 100644 index 0000000000..f401b10014 --- /dev/null +++ b/src/lib/libcrypto/des/KERBEROS | |||
@@ -0,0 +1,41 @@ | |||
1 | [ This is an old file, I don't know if it is true anymore | ||
2 | but I will leave the file here - eay 21/11/95 ] | ||
3 | |||
4 | To use this library with Bones (kerberos without DES): | ||
5 | 1) Get my modified Bones - eBones. It can be found on | ||
6 | gondwana.ecr.mu.oz.au (128.250.1.63) /pub/athena/eBones-p9.tar.Z | ||
7 | and | ||
8 | nic.funet.fi (128.214.6.100) /pub/unix/security/Kerberos/eBones-p9.tar.Z | ||
9 | |||
10 | 2) Unpack this library in src/lib/des, makeing sure it is version | ||
11 | 3.00 or greater (libdes.tar.93-10-07.Z). This versions differences | ||
12 | from the version in comp.sources.misc volume 29 patchlevel2. | ||
13 | The primarily difference is that it should compile under kerberos :-). | ||
14 | It can be found at. | ||
15 | ftp.psy.uq.oz.au (130.102.32.1) /pub/DES/libdes.tar.93-10-07.Z | ||
16 | |||
17 | Now do a normal kerberos build and things should work. | ||
18 | |||
19 | One problem I found when I was build on my local sun. | ||
20 | --- | ||
21 | For sunOS 4.1.1 apply the following patch to src/util/ss/make_commands.c | ||
22 | |||
23 | *** make_commands.c.orig Fri Jul 3 04:18:35 1987 | ||
24 | --- make_commands.c Wed May 20 08:47:42 1992 | ||
25 | *************** | ||
26 | *** 98,104 **** | ||
27 | if (!rename(o_file, z_file)) { | ||
28 | if (!vfork()) { | ||
29 | chdir("/tmp"); | ||
30 | ! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r", "-n", | ||
31 | z_file+5, 0); | ||
32 | perror("/bin/ld"); | ||
33 | _exit(1); | ||
34 | --- 98,104 ---- | ||
35 | if (!rename(o_file, z_file)) { | ||
36 | if (!vfork()) { | ||
37 | chdir("/tmp"); | ||
38 | ! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r", | ||
39 | z_file+5, 0); | ||
40 | perror("/bin/ld"); | ||
41 | _exit(1); | ||
diff --git a/src/lib/libcrypto/des/README b/src/lib/libcrypto/des/README new file mode 100644 index 0000000000..621a5ab467 --- /dev/null +++ b/src/lib/libcrypto/des/README | |||
@@ -0,0 +1,54 @@ | |||
1 | |||
2 | libdes, Version 4.01 10-Jan-97 | ||
3 | |||
4 | Copyright (c) 1997, Eric Young | ||
5 | All rights reserved. | ||
6 | |||
7 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms specified in COPYRIGHT. | ||
9 | |||
10 | -- | ||
11 | The primary ftp site for this library is | ||
12 | ftp://ftp.psy.uq.oz.au/pub/Crypto/DES/libdes-x.xx.tar.gz | ||
13 | libdes is now also shipped with SSLeay. Primary ftp site of | ||
14 | ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL/SSLeay-x.x.x.tar.gz | ||
15 | |||
16 | The best way to build this library is to build it as part of SSLeay. | ||
17 | |||
18 | This kit builds a DES encryption library and a DES encryption program. | ||
19 | It supports ecb, cbc, ofb, cfb, triple ecb, triple cbc, triple ofb, | ||
20 | triple cfb, desx, and MIT's pcbc encryption modes and also has a fast | ||
21 | implementation of crypt(3). | ||
22 | It contains support routines to read keys from a terminal, | ||
23 | generate a random key, generate a key from an arbitrary length string, | ||
24 | read/write encrypted data from/to a file descriptor. | ||
25 | |||
26 | The implementation was written so as to conform with the manual entry | ||
27 | for the des_crypt(3) library routines from MIT's project Athena. | ||
28 | |||
29 | destest should be run after compilation to test the des routines. | ||
30 | rpw should be run after compilation to test the read password routines. | ||
31 | The des program is a replacement for the sun des command. I believe it | ||
32 | conforms to the sun version. | ||
33 | |||
34 | The Imakefile is setup for use in the kerberos distribution. | ||
35 | |||
36 | These routines are best compiled with gcc or any other good | ||
37 | optimising compiler. | ||
38 | Just turn you optimiser up to the highest settings and run destest | ||
39 | after the build to make sure everything works. | ||
40 | |||
41 | I believe these routines are close to the fastest and most portable DES | ||
42 | routines that use small lookup tables (4.5k) that are publicly available. | ||
43 | The fcrypt routine is faster than ufc's fcrypt (when compiling with | ||
44 | gcc2 -O2) on the sparc 2 (1410 vs 1270) but is not so good on other machines | ||
45 | (on a sun3/260 168 vs 336). It is a function of CPU on chip cache size. | ||
46 | [ 10-Jan-97 and a function of an incorrect speed testing program in | ||
47 | ufc which gave much better test figures that reality ]. | ||
48 | |||
49 | It is worth noting that on sparc and Alpha CPUs, performance of the DES | ||
50 | library can vary by upto %10 due to the positioning of files after application | ||
51 | linkage. | ||
52 | |||
53 | Eric Young (eay@cryptsoft.com) | ||
54 | |||
diff --git a/src/lib/libcrypto/des/VERSION b/src/lib/libcrypto/des/VERSION new file mode 100644 index 0000000000..f62d8bdac0 --- /dev/null +++ b/src/lib/libcrypto/des/VERSION | |||
@@ -0,0 +1,411 @@ | |||
1 | Defining SIGACTION causes sigaction() to be used instead of signal(). | ||
2 | SIGUSR1/SIGUSR2 are no longer mapped in the read tty stuff because it | ||
3 | can cause problems. This should hopefully not affect normal | ||
4 | applications. | ||
5 | |||
6 | Version 4.04 | ||
7 | Fixed a few tests in destest. Also added x86 assember for | ||
8 | des_ncbc_encrypt() which is the standard cbc mode function. | ||
9 | This makes a very very large performace difference. | ||
10 | Ariel Glenn ariel@columbia.edu reports that the terminal | ||
11 | 'turn echo off' can return (errno == EINVAL) under solaris | ||
12 | when redirection is used. So I now catch that as well as ENOTTY. | ||
13 | |||
14 | |||
15 | Version 4.03 | ||
16 | Left a static out of enc_write.c, which caused to buffer to be | ||
17 | continiously malloc()ed. Does anyone use these functions? I keep | ||
18 | on feeling like removing them since I only had these in there | ||
19 | for a version of kerberised login. Anyway, this was pointed out | ||
20 | by Theo de Raadt <deraadt@cvs.openbsd.org> | ||
21 | The 'n' bit ofb code was wrong, it was not shifting the shift | ||
22 | register. It worked correctly for n == 64. Thanks to | ||
23 | Gigi Ankeny <Gigi.Ankeny@Eng.Sun.COM> for pointing this one out. | ||
24 | |||
25 | Version 4.02 | ||
26 | I was doing 'if (memcmp(weak_keys[i],key,sizeof(key)) == 0)' | ||
27 | when checking for weak keys which is wrong :-(, pointed out by | ||
28 | Markus F.X.J. Oberhumer <markus.oberhumer@jk.uni-linz.ac.at>. | ||
29 | |||
30 | Version 4.01 | ||
31 | Even faster inner loop in the DES assembler for x86 and a modification | ||
32 | for IP/FP which is faster on x86. Both of these changes are | ||
33 | from Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>. His | ||
34 | changes make the assembler run %40 faster on a pentium. This is just | ||
35 | a case of getting the instruction sequence 'just right'. | ||
36 | All credit to 'Svend' :-) | ||
37 | Quite a few special x86 'make' targets. | ||
38 | A libdes-l (lite) distribution. | ||
39 | |||
40 | Version 4.00 | ||
41 | After a bit of a pause, I'll up the major version number since this | ||
42 | is mostly a performace release. I've added x86 assembler and | ||
43 | added more options for performance. A %28 speedup for gcc | ||
44 | on a pentium and the assembler is a %50 speedup. | ||
45 | MIPS CPU's, sparc and Alpha are the main CPU's with speedups. | ||
46 | Run des_opts to work out which options should be used. | ||
47 | DES_RISC1/DES_RISC2 use alternative inner loops which use | ||
48 | more registers but should give speedups on any CPU that does | ||
49 | dual issue (pentium). DES_UNROLL unrolls the inner loop, | ||
50 | which costs in code size. | ||
51 | |||
52 | Version 3.26 | ||
53 | I've finally removed one of the shifts in D_ENCRYPT. This | ||
54 | meant I've changed the des_SPtrans table (spr.h), the set_key() | ||
55 | function and some things in des_enc.c. This has definitly | ||
56 | made things faster :-). I've known about this one for some | ||
57 | time but I've been too lazy to follow it up :-). | ||
58 | Noticed that in the D_ENCRYPT() macro, we can just do L^=(..)^(..)^.. | ||
59 | instead of L^=((..)|(..)|(..).. This should save a register at | ||
60 | least. | ||
61 | Assember for x86. The file to replace is des_enc.c, which is replaced | ||
62 | by one of the assembler files found in asm. Look at des/asm/readme | ||
63 | for more info. | ||
64 | |||
65 | /* Modification to fcrypt so it can be compiled to support | ||
66 | HPUX 10.x's long password format, define -DLONGCRYPT to use this. | ||
67 | Thanks to Jens Kupferschmidt <bt1cu@hpboot.rz.uni-leipzig.de>. */ | ||
68 | |||
69 | SIGWINCH case put in des_read_passwd() so the function does not | ||
70 | 'exit' if this function is recieved. | ||
71 | |||
72 | Version 3.25 17/07/96 | ||
73 | Modified read_pwd.c so that stdin can be read if not a tty. | ||
74 | Thanks to Jeff Barber <jeffb@issl.atl.hp.com> for the patches. | ||
75 | des_init_random_number_generator() shortened due to VMS linker | ||
76 | limits. | ||
77 | Added RSA's DESX cbc mode. It is a form of cbc encryption, with 2 | ||
78 | 8 byte quantites xored before and after encryption. | ||
79 | des_xcbc_encryption() - the name is funny to preserve the des_ | ||
80 | prefix on all functions. | ||
81 | |||
82 | Version 3.24 20/04/96 | ||
83 | The DES_PTR macro option checked and used by SSLeay configuration | ||
84 | |||
85 | Version 3.23 11/04/96 | ||
86 | Added DES_LONG. If defined to 'unsigned int' on the DEC Alpha, | ||
87 | it gives a %20 speedup :-) | ||
88 | Fixed the problem with des.pl under perl5. The patches were | ||
89 | sent by Ed Kubaitis (ejk@uiuc.edu). | ||
90 | if fcrypt.c, changed values to handle illegal salt values the way | ||
91 | normal crypt() implementations do. Some programs apparently use | ||
92 | them :-(. The patch was sent by Bjorn Gronvall <bg@sics.se> | ||
93 | |||
94 | Version 3.22 29/11/95 | ||
95 | Bug in des(1), an error with the uuencoding stuff when the | ||
96 | 'data' is small, thanks to Geoff Keating <keagchon@mehta.anu.edu.au> | ||
97 | for the patch. | ||
98 | |||
99 | Version 3.21 22/11/95 | ||
100 | After some emailing back and forth with | ||
101 | Colin Plumb <colin@nyx10.cs.du.edu>, I've tweaked a few things | ||
102 | and in a future version I will probably put in some of the | ||
103 | optimisation he suggested for use with the DES_USE_PTR option. | ||
104 | Extra routines from Mark Murray <mark@grondar.za> for use in | ||
105 | freeBSD. They mostly involve random number generation for use | ||
106 | with kerberos. They involve evil machine specific system calls | ||
107 | etc so I would normally suggest pushing this stuff into the | ||
108 | application and/or using RAND_seed()/RAND_bytes() if you are | ||
109 | using this DES library as part of SSLeay. | ||
110 | Redone the read_pw() function so that it is cleaner and | ||
111 | supports termios, thanks to Sameer Parekh <sameer@c2.org> | ||
112 | for the initial patches for this. | ||
113 | Renamed 3ecb_encrypt() to ecb3_encrypt(). This has been | ||
114 | done just to make things more consistent. | ||
115 | I have also now added triple DES versions of cfb and ofb. | ||
116 | |||
117 | Version 3.20 | ||
118 | Damn, Damn, Damn, as pointed out by Mike_Spreitzer.PARC@xerox.com, | ||
119 | my des_random_seed() function was only copying 4 bytes of the | ||
120 | passed seed into the init structure. It is now fixed to copy 8. | ||
121 | My own suggestion is to used something like MD5 :-) | ||
122 | |||
123 | Version 3.19 | ||
124 | While looking at my code one day, I though, why do I keep on | ||
125 | calling des_encrypt(in,out,ks,enc) when every function that | ||
126 | calls it has in and out the same. So I dropped the 'out' | ||
127 | parameter, people should not be using this function. | ||
128 | |||
129 | Version 3.18 30/08/95 | ||
130 | Fixed a few bit with the distribution and the filenames. | ||
131 | 3.17 had been munged via a move to DOS and back again. | ||
132 | NO CODE CHANGES | ||
133 | |||
134 | Version 3.17 14/07/95 | ||
135 | Fixed ede3 cbc which I had broken in 3.16. I have also | ||
136 | removed some unneeded variables in 7-8 of the routines. | ||
137 | |||
138 | Version 3.16 26/06/95 | ||
139 | Added des_encrypt2() which does not use IP/FP, used by triple | ||
140 | des routines. Tweaked things a bit elsewhere. %13 speedup on | ||
141 | sparc and %6 on a R4400 for ede3 cbc mode. | ||
142 | |||
143 | Version 3.15 06/06/95 | ||
144 | Added des_ncbc_encrypt(), it is des_cbc mode except that it is | ||
145 | 'normal' and copies the new iv value back over the top of the | ||
146 | passed parameter. | ||
147 | CHANGED des_ede3_cbc_encrypt() so that it too now overwrites | ||
148 | the iv. THIS WILL BREAK EXISTING CODE, but since this function | ||
149 | only new, I feel I can change it, not so with des_cbc_encrypt :-(. | ||
150 | I need to update the documentation. | ||
151 | |||
152 | Version 3.14 31/05/95 | ||
153 | New release upon the world, as part of my SSL implementation. | ||
154 | New copyright and usage stuff. Basically free for all to use | ||
155 | as long as you say it came from me :-) | ||
156 | |||
157 | Version 3.13 31/05/95 | ||
158 | A fix in speed.c, if HZ is not defined, I set it to 100.0 | ||
159 | which is reasonable for most unixes except SunOS 4.x. | ||
160 | I now have a #ifdef sun but timing for SunOS 4.x looked very | ||
161 | good :-(. At my last job where I used SunOS 4.x, it was | ||
162 | defined to be 60.0 (look at the old INSTALL documentation), at | ||
163 | the last release had it changed to 100.0 since I now work with | ||
164 | Solaris2 and SVR4 boxes. | ||
165 | Thanks to Rory Chisholm <rchishol@math.ethz.ch> for pointing this | ||
166 | one out. | ||
167 | |||
168 | Version 3.12 08/05/95 | ||
169 | As pointed out by The Crypt Keeper <tck@bend.UCSD.EDU>, | ||
170 | my D_ENCRYPT macro in crypt() had an un-necessary variable. | ||
171 | It has been removed. | ||
172 | |||
173 | Version 3.11 03/05/95 | ||
174 | Added des_ede3_cbc_encrypt() which is cbc mode des with 3 keys | ||
175 | and one iv. It is a standard and I needed it for my SSL code. | ||
176 | It makes more sense to use this for triple DES than | ||
177 | 3cbc_encrypt(). I have also added (or should I say tested :-) | ||
178 | cfb64_encrypt() which is cfb64 but it will encrypt a partial | ||
179 | number of bytes - 3 bytes in 3 bytes out. Again this is for | ||
180 | my SSL library, as a form of encryption to use with SSL | ||
181 | telnet. | ||
182 | |||
183 | Version 3.10 22/03/95 | ||
184 | Fixed a bug in 3cbc_encrypt() :-(. When making repeated calls | ||
185 | to cbc3_encrypt, the 2 iv values that were being returned to | ||
186 | be used in the next call were reversed :-(. | ||
187 | Many thanks to Bill Wade <wade@Stoner.COM> for pointing out | ||
188 | this error. | ||
189 | |||
190 | Version 3.09 01/02/95 | ||
191 | Fixed des_random_key to far more random, it was rather feeble | ||
192 | with regards to picking the initial seed. The problem was | ||
193 | pointed out by Olaf Kirch <okir@monad.swb.de>. | ||
194 | |||
195 | Version 3.08 14/12/94 | ||
196 | Added Makefile.PL so libdes can be built into perl5. | ||
197 | Changed des_locl.h so RAND is always defined. | ||
198 | |||
199 | Version 3.07 05/12/94 | ||
200 | Added GNUmake and stuff so the library can be build with | ||
201 | glibc. | ||
202 | |||
203 | Version 3.06 30/08/94 | ||
204 | Added rpc_enc.c which contains _des_crypt. This is for use in | ||
205 | secure_rpc v 4.0 | ||
206 | Finally fixed the cfb_enc problems. | ||
207 | Fixed a few parameter parsing bugs in des (-3 and -b), thanks | ||
208 | to Rob McMillan <R.McMillan@its.gu.edu.au> | ||
209 | |||
210 | Version 3.05 21/04/94 | ||
211 | for unsigned long l; gcc does not produce ((l>>34) == 0) | ||
212 | This causes bugs in cfb_enc. | ||
213 | Thanks to Hadmut Danisch <danisch@ira.uka.de> | ||
214 | |||
215 | Version 3.04 20/04/94 | ||
216 | Added a version number to des.c and libdes.a | ||
217 | |||
218 | Version 3.03 12/01/94 | ||
219 | Fixed a bug in non zero iv in 3cbc_enc. | ||
220 | |||
221 | Version 3.02 29/10/93 | ||
222 | I now work in a place where there are 6+ architectures and 14+ | ||
223 | OS versions :-). | ||
224 | Fixed TERMIO definition so the most sys V boxes will work :-) | ||
225 | |||
226 | Release upon comp.sources.misc | ||
227 | Version 3.01 08/10/93 | ||
228 | Added des_3cbc_encrypt() | ||
229 | |||
230 | Version 3.00 07/10/93 | ||
231 | Fixed up documentation. | ||
232 | quad_cksum definitely compatible with MIT's now. | ||
233 | |||
234 | Version 2.30 24/08/93 | ||
235 | Triple DES now defaults to triple cbc but can do triple ecb | ||
236 | with the -b flag. | ||
237 | Fixed some MSDOS uuen/uudecoding problems, thanks to | ||
238 | Added prototypes. | ||
239 | |||
240 | Version 2.22 29/06/93 | ||
241 | Fixed a bug in des_is_weak_key() which stopped it working :-( | ||
242 | thanks to engineering@MorningStar.Com. | ||
243 | |||
244 | Version 2.21 03/06/93 | ||
245 | des(1) with no arguments gives quite a bit of help. | ||
246 | Added -c (generate ckecksum) flag to des(1). | ||
247 | Added -3 (triple DES) flag to des(1). | ||
248 | Added cfb and ofb routines to the library. | ||
249 | |||
250 | Version 2.20 11/03/93 | ||
251 | Added -u (uuencode) flag to des(1). | ||
252 | I have been playing with byte order in quad_cksum to make it | ||
253 | compatible with MIT's version. All I can say is avid this | ||
254 | function if possible since MIT's output is endian dependent. | ||
255 | |||
256 | Version 2.12 14/10/92 | ||
257 | Added MSDOS specific macro in ecb_encrypt which gives a %70 | ||
258 | speed up when the code is compiled with turbo C. | ||
259 | |||
260 | Version 2.11 12/10/92 | ||
261 | Speedup in set_key (recoding of PC-1) | ||
262 | I now do it in 47 simple operations, down from 60. | ||
263 | Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov) | ||
264 | for motivating me to look for a faster system :-) | ||
265 | The speedup is probably less that 1% but it is still 13 | ||
266 | instructions less :-). | ||
267 | |||
268 | Version 2.10 06/10/92 | ||
269 | The code now works on the 64bit ETA10 and CRAY without modifications or | ||
270 | #defines. I believe the code should work on any machine that | ||
271 | defines long, int or short to be 8 bytes long. | ||
272 | Thanks to Shabbir J. Safdar (shabby@mentor.cc.purdue.edu) | ||
273 | for helping me fix the code to run on 64bit machines (he had | ||
274 | access to an ETA10). | ||
275 | Thanks also to John Fletcher <john_fletcher@lccmail.ocf.llnl.gov> | ||
276 | for testing the routines on a CRAY. | ||
277 | read_password.c has been renamed to read_passwd.c | ||
278 | string_to_key.c has been renamed to string2key.c | ||
279 | |||
280 | Version 2.00 14/09/92 | ||
281 | Made mods so that the library should work on 64bit CPU's. | ||
282 | Removed all my uchar and ulong defs. To many different | ||
283 | versions of unix define them in their header files in too many | ||
284 | different combinations :-) | ||
285 | IRIX - Sillicon Graphics mods (mostly in read_password.c). | ||
286 | Thanks to Andrew Daviel (advax@erich.triumf.ca) | ||
287 | |||
288 | Version 1.99 26/08/92 | ||
289 | Fixed a bug or 2 in enc_read.c | ||
290 | Fixed a bug in enc_write.c | ||
291 | Fixed a pseudo bug in fcrypt.c (very obscure). | ||
292 | |||
293 | Version 1.98 31/07/92 | ||
294 | Support for the ETA10. This is a strange machine that defines | ||
295 | longs and ints as 8 bytes and shorts as 4 bytes. | ||
296 | Since I do evil things with long * that assume that they are 4 | ||
297 | bytes. Look in the Makefile for the option to compile for | ||
298 | this machine. quad_cksum appears to have problems but I | ||
299 | will don't have the time to fix it right now, and this is not | ||
300 | a function that uses DES and so will not effect the main uses | ||
301 | of the library. | ||
302 | |||
303 | Version 1.97 20/05/92 eay | ||
304 | Fixed the Imakefile and made some changes to des.h to fix some | ||
305 | problems when building this package with Kerberos v 4. | ||
306 | |||
307 | Version 1.96 18/05/92 eay | ||
308 | Fixed a small bug in string_to_key() where problems could | ||
309 | occur if des_check_key was set to true and the string | ||
310 | generated a weak key. | ||
311 | |||
312 | Patch2 posted to comp.sources.misc | ||
313 | Version 1.95 13/05/92 eay | ||
314 | Added an alternative version of the D_ENCRYPT macro in | ||
315 | ecb_encrypt and fcrypt. Depending on the compiler, one version or the | ||
316 | other will be faster. This was inspired by | ||
317 | Dana How <how@isl.stanford.edu>, and her pointers about doing the | ||
318 | *(ulong *)((uchar *)ptr+(value&0xfc)) | ||
319 | vs | ||
320 | ptr[value&0x3f] | ||
321 | to stop the C compiler doing a <<2 to convert the long array index. | ||
322 | |||
323 | Version 1.94 05/05/92 eay | ||
324 | Fixed an incompatibility between my string_to_key and the MIT | ||
325 | version. When the key is longer than 8 chars, I was wrapping | ||
326 | with a different method. To use the old version, define | ||
327 | OLD_STR_TO_KEY in the makefile. Thanks to | ||
328 | viktor@newsu.shearson.com (Viktor Dukhovni). | ||
329 | |||
330 | Version 1.93 28/04/92 eay | ||
331 | Fixed the VMS mods so that echo is now turned off in | ||
332 | read_password. Thanks again to brennan@coco.cchs.su.oz.AU. | ||
333 | MSDOS support added. The routines can be compiled with | ||
334 | Turbo C (v2.0) and MSC (v5.1). Make sure MSDOS is defined. | ||
335 | |||
336 | Patch1 posted to comp.sources.misc | ||
337 | Version 1.92 13/04/92 eay | ||
338 | Changed D_ENCRYPT so that the rotation of R occurs outside of | ||
339 | the loop. This required rotating all the longs in sp.h (now | ||
340 | called spr.h). Thanks to Richard Outerbridge <71755.204@CompuServe.COM> | ||
341 | speed.c has been changed so it will work without SIGALRM. If | ||
342 | times(3) is not present it will try to use ftime() instead. | ||
343 | |||
344 | Version 1.91 08/04/92 eay | ||
345 | Added -E/-D options to des(1) so it can use string_to_key. | ||
346 | Added SVR4 mods suggested by witr@rwwa.COM | ||
347 | Added VMS mods suggested by brennan@coco.cchs.su.oz.AU. If | ||
348 | anyone knows how to turn of tty echo in VMS please tell me or | ||
349 | implement it yourself :-). | ||
350 | Changed FILE *IN/*OUT to *DES_IN/*DES_OUT since it appears VMS | ||
351 | does not like IN/OUT being used. | ||
352 | |||
353 | Libdes posted to comp.sources.misc | ||
354 | Version 1.9 24/03/92 eay | ||
355 | Now contains a fast small crypt replacement. | ||
356 | Added des(1) command. | ||
357 | Added des_rw_mode so people can use cbc encryption with | ||
358 | enc_read and enc_write. | ||
359 | |||
360 | Version 1.8 15/10/91 eay | ||
361 | Bug in cbc_cksum. | ||
362 | Many thanks to Keith Reynolds (keithr@sco.COM) for pointing this | ||
363 | one out. | ||
364 | |||
365 | Version 1.7 24/09/91 eay | ||
366 | Fixed set_key :-) | ||
367 | set_key is 4 times faster and takes less space. | ||
368 | There are a few minor changes that could be made. | ||
369 | |||
370 | Version 1.6 19/09/1991 eay | ||
371 | Finally go IP and FP finished. | ||
372 | Now I need to fix set_key. | ||
373 | This version is quite a bit faster that 1.51 | ||
374 | |||
375 | Version 1.52 15/06/1991 eay | ||
376 | 20% speedup in ecb_encrypt by changing the E bit selection | ||
377 | to use 2 32bit words. This also required modification of the | ||
378 | sp table. There is still a way to speedup the IP and IP-1 | ||
379 | (hints from outer@sq.com) still working on this one :-(. | ||
380 | |||
381 | Version 1.51 07/06/1991 eay | ||
382 | Faster des_encrypt by loop unrolling | ||
383 | Fixed bug in quad_cksum.c (thanks to hughes@logos.ucs.indiana.edu) | ||
384 | |||
385 | Version 1.50 28/05/1991 eay | ||
386 | Optimised the code a bit more for the sparc. I have improved the | ||
387 | speed of the inner des_encrypt by speeding up the initial and | ||
388 | final permutations. | ||
389 | |||
390 | Version 1.40 23/10/1990 eay | ||
391 | Fixed des_random_key, it did not produce a random key :-( | ||
392 | |||
393 | Version 1.30 2/10/1990 eay | ||
394 | Have made des_quad_cksum the same as MIT's, the full package | ||
395 | should be compatible with MIT's | ||
396 | Have tested on a DECstation 3100 | ||
397 | Still need to fix des_set_key (make it faster). | ||
398 | Does des_cbc_encrypts at 70.5k/sec on a 3100. | ||
399 | |||
400 | Version 1.20 18/09/1990 eay | ||
401 | Fixed byte order dependencies. | ||
402 | Fixed (I hope) all the word alignment problems. | ||
403 | Speedup in des_ecb_encrypt. | ||
404 | |||
405 | Version 1.10 11/09/1990 eay | ||
406 | Added des_enc_read and des_enc_write. | ||
407 | Still need to fix des_quad_cksum. | ||
408 | Still need to document des_enc_read and des_enc_write. | ||
409 | |||
410 | Version 1.00 27/08/1990 eay | ||
411 | |||
diff --git a/src/lib/libcrypto/des/asm/des686.pl b/src/lib/libcrypto/des/asm/des686.pl new file mode 100644 index 0000000000..cf1a82fb5c --- /dev/null +++ b/src/lib/libcrypto/des/asm/des686.pl | |||
@@ -0,0 +1,230 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | $prog="des686.pl"; | ||
4 | |||
5 | # base code is in microsft | ||
6 | # op dest, source | ||
7 | # format. | ||
8 | # | ||
9 | |||
10 | # WILL NOT WORK ANYMORE WITH desboth.pl | ||
11 | require "desboth.pl"; | ||
12 | |||
13 | if ( ($ARGV[0] eq "elf")) | ||
14 | { require "x86unix.pl"; } | ||
15 | elsif ( ($ARGV[0] eq "a.out")) | ||
16 | { $aout=1; require "x86unix.pl"; } | ||
17 | elsif ( ($ARGV[0] eq "sol")) | ||
18 | { $sol=1; require "x86unix.pl"; } | ||
19 | elsif ( ($ARGV[0] eq "cpp")) | ||
20 | { $cpp=1; require "x86unix.pl"; } | ||
21 | elsif ( ($ARGV[0] eq "win32")) | ||
22 | { require "x86ms.pl"; } | ||
23 | else | ||
24 | { | ||
25 | print STDERR <<"EOF"; | ||
26 | Pick one target type from | ||
27 | elf - linux, FreeBSD etc | ||
28 | a.out - old linux | ||
29 | sol - x86 solaris | ||
30 | cpp - format so x86unix.cpp can be used | ||
31 | win32 - Windows 95/Windows NT | ||
32 | EOF | ||
33 | exit(1); | ||
34 | } | ||
35 | |||
36 | &comment("Don't even think of reading this code"); | ||
37 | &comment("It was automatically generated by $prog"); | ||
38 | &comment("Which is a perl program used to generate the x86 assember for"); | ||
39 | &comment("any of elf, a.out, Win32, or Solaris"); | ||
40 | &comment("It can be found in SSLeay 0.6.5+ or in libdes 3.26+"); | ||
41 | &comment("eric <eay\@cryptsoft.com>"); | ||
42 | &comment(""); | ||
43 | |||
44 | &file("dx86xxxx"); | ||
45 | |||
46 | $L="edi"; | ||
47 | $R="esi"; | ||
48 | |||
49 | &des_encrypt("des_encrypt",1); | ||
50 | &des_encrypt("des_encrypt2",0); | ||
51 | |||
52 | &des_encrypt3("des_encrypt3",1); | ||
53 | &des_encrypt3("des_decrypt3",0); | ||
54 | |||
55 | &file_end(); | ||
56 | |||
57 | sub des_encrypt | ||
58 | { | ||
59 | local($name,$do_ip)=@_; | ||
60 | |||
61 | &function_begin($name,"EXTRN _des_SPtrans:DWORD"); | ||
62 | |||
63 | &comment(""); | ||
64 | &comment("Load the 2 words"); | ||
65 | &mov("eax",&wparam(0)); | ||
66 | &mov($L,&DWP(0,"eax","",0)); | ||
67 | &mov($R,&DWP(4,"eax","",0)); | ||
68 | |||
69 | $ksp=&wparam(1); | ||
70 | |||
71 | if ($do_ip) | ||
72 | { | ||
73 | &comment(""); | ||
74 | &comment("IP"); | ||
75 | &IP_new($L,$R,"eax"); | ||
76 | } | ||
77 | |||
78 | &comment(""); | ||
79 | &comment("fixup rotate"); | ||
80 | &rotl($R,3); | ||
81 | &rotl($L,3); | ||
82 | &exch($L,$R); | ||
83 | |||
84 | &comment(""); | ||
85 | &comment("load counter, key_schedule and enc flag"); | ||
86 | &mov("eax",&wparam(2)); # get encrypt flag | ||
87 | &mov("ebp",&wparam(1)); # get ks | ||
88 | &cmp("eax","0"); | ||
89 | &je(&label("start_decrypt")); | ||
90 | |||
91 | # encrypting part | ||
92 | |||
93 | for ($i=0; $i<16; $i+=2) | ||
94 | { | ||
95 | &comment(""); | ||
96 | &comment("Round $i"); | ||
97 | &D_ENCRYPT($L,$R,$i*2,"ebp","des_SPtrans","ecx","edx","eax","ebx"); | ||
98 | |||
99 | &comment(""); | ||
100 | &comment("Round ".sprintf("%d",$i+1)); | ||
101 | &D_ENCRYPT($R,$L,($i+1)*2,"ebp","des_SPtrans","ecx","edx","eax","ebx"); | ||
102 | } | ||
103 | &jmp(&label("end")); | ||
104 | |||
105 | &set_label("start_decrypt"); | ||
106 | |||
107 | for ($i=15; $i>0; $i-=2) | ||
108 | { | ||
109 | &comment(""); | ||
110 | &comment("Round $i"); | ||
111 | &D_ENCRYPT($L,$R,$i*2,"ebp","des_SPtrans","ecx","edx","eax","ebx"); | ||
112 | &comment(""); | ||
113 | &comment("Round ".sprintf("%d",$i-1)); | ||
114 | &D_ENCRYPT($R,$L,($i-1)*2,"ebp","des_SPtrans","ecx","edx","eax","ebx"); | ||
115 | } | ||
116 | |||
117 | &set_label("end"); | ||
118 | |||
119 | &comment(""); | ||
120 | &comment("Fixup"); | ||
121 | &rotr($L,3); # r | ||
122 | &rotr($R,3); # l | ||
123 | |||
124 | if ($do_ip) | ||
125 | { | ||
126 | &comment(""); | ||
127 | &comment("FP"); | ||
128 | &FP_new($R,$L,"eax"); | ||
129 | } | ||
130 | |||
131 | &mov("eax",&wparam(0)); | ||
132 | &mov(&DWP(0,"eax","",0),$L); | ||
133 | &mov(&DWP(4,"eax","",0),$R); | ||
134 | |||
135 | &function_end($name); | ||
136 | } | ||
137 | |||
138 | |||
139 | # The logic is to load R into 2 registers and operate on both at the same time. | ||
140 | # We also load the 2 R's into 2 more registers so we can do the 'move word down a byte' | ||
141 | # while also masking the other copy and doing a lookup. We then also accumulate the | ||
142 | # L value in 2 registers then combine them at the end. | ||
143 | sub D_ENCRYPT | ||
144 | { | ||
145 | local($L,$R,$S,$ks,$desSP,$u,$t,$tmp1,$tmp2,$tmp3)=@_; | ||
146 | |||
147 | &mov( $u, &DWP(&n2a($S*4),$ks,"",0)); | ||
148 | &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0)); | ||
149 | &xor( $u, $R ); | ||
150 | &xor( $t, $R ); | ||
151 | &rotr( $t, 4 ); | ||
152 | |||
153 | # the numbers at the end of the line are origional instruction order | ||
154 | &mov( $tmp2, $u ); # 1 2 | ||
155 | &mov( $tmp1, $t ); # 1 1 | ||
156 | &and( $tmp2, "0xfc" ); # 1 4 | ||
157 | &and( $tmp1, "0xfc" ); # 1 3 | ||
158 | &shr( $t, 8 ); # 1 5 | ||
159 | &xor( $L, &DWP("0x100+$desSP",$tmp1,"",0)); # 1 7 | ||
160 | &shr( $u, 8 ); # 1 6 | ||
161 | &mov( $tmp1, &DWP(" $desSP",$tmp2,"",0)); # 1 8 | ||
162 | |||
163 | &mov( $tmp2, $u ); # 2 2 | ||
164 | &xor( $L, $tmp1 ); # 1 9 | ||
165 | &and( $tmp2, "0xfc" ); # 2 4 | ||
166 | &mov( $tmp1, $t ); # 2 1 | ||
167 | &and( $tmp1, "0xfc" ); # 2 3 | ||
168 | &shr( $t, 8 ); # 2 5 | ||
169 | &xor( $L, &DWP("0x300+$desSP",$tmp1,"",0)); # 2 7 | ||
170 | &shr( $u, 8 ); # 2 6 | ||
171 | &mov( $tmp1, &DWP("0x200+$desSP",$tmp2,"",0)); # 2 8 | ||
172 | &mov( $tmp2, $u ); # 3 2 | ||
173 | |||
174 | &xor( $L, $tmp1 ); # 2 9 | ||
175 | &and( $tmp2, "0xfc" ); # 3 4 | ||
176 | |||
177 | &mov( $tmp1, $t ); # 3 1 | ||
178 | &shr( $u, 8 ); # 3 6 | ||
179 | &and( $tmp1, "0xfc" ); # 3 3 | ||
180 | &shr( $t, 8 ); # 3 5 | ||
181 | &xor( $L, &DWP("0x500+$desSP",$tmp1,"",0)); # 3 7 | ||
182 | &mov( $tmp1, &DWP("0x400+$desSP",$tmp2,"",0)); # 3 8 | ||
183 | |||
184 | &and( $t, "0xfc" ); # 4 1 | ||
185 | &xor( $L, $tmp1 ); # 3 9 | ||
186 | |||
187 | &and( $u, "0xfc" ); # 4 2 | ||
188 | &xor( $L, &DWP("0x700+$desSP",$t,"",0)); # 4 3 | ||
189 | &xor( $L, &DWP("0x600+$desSP",$u,"",0)); # 4 4 | ||
190 | } | ||
191 | |||
192 | sub PERM_OP | ||
193 | { | ||
194 | local($a,$b,$tt,$shift,$mask)=@_; | ||
195 | |||
196 | &mov( $tt, $a ); | ||
197 | &shr( $tt, $shift ); | ||
198 | &xor( $tt, $b ); | ||
199 | &and( $tt, $mask ); | ||
200 | &xor( $b, $tt ); | ||
201 | &shl( $tt, $shift ); | ||
202 | &xor( $a, $tt ); | ||
203 | } | ||
204 | |||
205 | sub IP_new | ||
206 | { | ||
207 | local($l,$r,$tt)=@_; | ||
208 | |||
209 | &PERM_OP($r,$l,$tt, 4,"0x0f0f0f0f"); | ||
210 | &PERM_OP($l,$r,$tt,16,"0x0000ffff"); | ||
211 | &PERM_OP($r,$l,$tt, 2,"0x33333333"); | ||
212 | &PERM_OP($l,$r,$tt, 8,"0x00ff00ff"); | ||
213 | &PERM_OP($r,$l,$tt, 1,"0x55555555"); | ||
214 | } | ||
215 | |||
216 | sub FP_new | ||
217 | { | ||
218 | local($l,$r,$tt)=@_; | ||
219 | |||
220 | &PERM_OP($l,$r,$tt, 1,"0x55555555"); | ||
221 | &PERM_OP($r,$l,$tt, 8,"0x00ff00ff"); | ||
222 | &PERM_OP($l,$r,$tt, 2,"0x33333333"); | ||
223 | &PERM_OP($r,$l,$tt,16,"0x0000ffff"); | ||
224 | &PERM_OP($l,$r,$tt, 4,"0x0f0f0f0f"); | ||
225 | } | ||
226 | |||
227 | sub n2a | ||
228 | { | ||
229 | sprintf("%d",$_[0]); | ||
230 | } | ||
diff --git a/src/lib/libcrypto/des/asm/readme b/src/lib/libcrypto/des/asm/readme new file mode 100644 index 0000000000..f8529d9307 --- /dev/null +++ b/src/lib/libcrypto/des/asm/readme | |||
@@ -0,0 +1,131 @@ | |||
1 | First up, let me say I don't like writing in assembler. It is not portable, | ||
2 | dependant on the particular CPU architecture release and is generally a pig | ||
3 | to debug and get right. Having said that, the x86 architecture is probably | ||
4 | the most important for speed due to number of boxes and since | ||
5 | it appears to be the worst architecture to to get | ||
6 | good C compilers for. So due to this, I have lowered myself to do | ||
7 | assembler for the inner DES routines in libdes :-). | ||
8 | |||
9 | The file to implement in assembler is des_enc.c. Replace the following | ||
10 | 4 functions | ||
11 | des_encrypt(DES_LONG data[2],des_key_schedule ks, int encrypt); | ||
12 | des_encrypt2(DES_LONG data[2],des_key_schedule ks, int encrypt); | ||
13 | des_encrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3); | ||
14 | des_decrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3); | ||
15 | |||
16 | They encrypt/decrypt the 64 bits held in 'data' using | ||
17 | the 'ks' key schedules. The only difference between the 4 functions is that | ||
18 | des_encrypt2() does not perform IP() or FP() on the data (this is an | ||
19 | optimization for when doing triple DES and des_encrypt3() and des_decrypt3() | ||
20 | perform triple des. The triple DES routines are in here because it does | ||
21 | make a big difference to have them located near the des_encrypt2 function | ||
22 | at link time.. | ||
23 | |||
24 | Now as we all know, there are lots of different operating systems running on | ||
25 | x86 boxes, and unfortunately they normally try to make sure their assembler | ||
26 | formating is not the same as the other peoples. | ||
27 | The 4 main formats I know of are | ||
28 | Microsoft Windows 95/Windows NT | ||
29 | Elf Includes Linux and FreeBSD(?). | ||
30 | a.out The older Linux. | ||
31 | Solaris Same as Elf but different comments :-(. | ||
32 | |||
33 | Now I was not overly keen to write 4 different copies of the same code, | ||
34 | so I wrote a few perl routines to output the correct assembler, given | ||
35 | a target assembler type. This code is ugly and is just a hack. | ||
36 | The libraries are x86unix.pl and x86ms.pl. | ||
37 | des586.pl, des686.pl and des-som[23].pl are the programs to actually | ||
38 | generate the assembler. | ||
39 | |||
40 | So to generate elf assembler | ||
41 | perl des-som3.pl elf >dx86-elf.s | ||
42 | For Windows 95/NT | ||
43 | perl des-som2.pl win32 >win32.asm | ||
44 | |||
45 | [ update 4 Jan 1996 ] | ||
46 | I have added another way to do things. | ||
47 | perl des-som3.pl cpp >dx86-cpp.s | ||
48 | generates a file that will be included by dx86unix.cpp when it is compiled. | ||
49 | To build for elf, a.out, solaris, bsdi etc, | ||
50 | cc -E -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o | ||
51 | cc -E -DSOL asm/dx86unix.cpp | as -o asm/dx86-sol.o | ||
52 | cc -E -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o | ||
53 | cc -E -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o | ||
54 | This was done to cut down the number of files in the distribution. | ||
55 | |||
56 | Now the ugly part. I acquired my copy of Intels | ||
57 | "Optimization's For Intel's 32-Bit Processors" and found a few interesting | ||
58 | things. First, the aim of the exersize is to 'extract' one byte at a time | ||
59 | from a word and do an array lookup. This involves getting the byte from | ||
60 | the 4 locations in the word and moving it to a new word and doing the lookup. | ||
61 | The most obvious way to do this is | ||
62 | xor eax, eax # clear word | ||
63 | movb al, cl # get low byte | ||
64 | xor edi DWORD PTR 0x100+des_SP[eax] # xor in word | ||
65 | movb al, ch # get next byte | ||
66 | xor edi DWORD PTR 0x300+des_SP[eax] # xor in word | ||
67 | shr ecx 16 | ||
68 | which seems ok. For the pentium, this system appears to be the best. | ||
69 | One has to do instruction interleaving to keep both functional units | ||
70 | operating, but it is basically very efficient. | ||
71 | |||
72 | Now the crunch. When a full register is used after a partial write, eg. | ||
73 | mov al, cl | ||
74 | xor edi, DWORD PTR 0x100+des_SP[eax] | ||
75 | 386 - 1 cycle stall | ||
76 | 486 - 1 cycle stall | ||
77 | 586 - 0 cycle stall | ||
78 | 686 - at least 7 cycle stall (page 22 of the above mentioned document). | ||
79 | |||
80 | So the technique that produces the best results on a pentium, according to | ||
81 | the documentation, will produce hideous results on a pentium pro. | ||
82 | |||
83 | To get around this, des686.pl will generate code that is not as fast on | ||
84 | a pentium, should be very good on a pentium pro. | ||
85 | mov eax, ecx # copy word | ||
86 | shr ecx, 8 # line up next byte | ||
87 | and eax, 0fch # mask byte | ||
88 | xor edi DWORD PTR 0x100+des_SP[eax] # xor in array lookup | ||
89 | mov eax, ecx # get word | ||
90 | shr ecx 8 # line up next byte | ||
91 | and eax, 0fch # mask byte | ||
92 | xor edi DWORD PTR 0x300+des_SP[eax] # xor in array lookup | ||
93 | |||
94 | Due to the execution units in the pentium, this actually works quite well. | ||
95 | For a pentium pro it should be very good. This is the type of output | ||
96 | Visual C++ generates. | ||
97 | |||
98 | There is a third option. instead of using | ||
99 | mov al, ch | ||
100 | which is bad on the pentium pro, one may be able to use | ||
101 | movzx eax, ch | ||
102 | which may not incur the partial write penalty. On the pentium, | ||
103 | this instruction takes 4 cycles so is not worth using but on the | ||
104 | pentium pro it appears it may be worth while. I need access to one to | ||
105 | experiment :-). | ||
106 | |||
107 | eric (20 Oct 1996) | ||
108 | |||
109 | 22 Nov 1996 - I have asked people to run the 2 different version on pentium | ||
110 | pros and it appears that the intel documentation is wrong. The | ||
111 | mov al,bh is still faster on a pentium pro, so just use the des586.pl | ||
112 | install des686.pl | ||
113 | |||
114 | 3 Dec 1996 - I added des_encrypt3/des_decrypt3 because I have moved these | ||
115 | functions into des_enc.c because it does make a massive performance | ||
116 | difference on some boxes to have the functions code located close to | ||
117 | the des_encrypt2() function. | ||
118 | |||
119 | 9 Jan 1997 - des-som2.pl is now the correct perl script to use for | ||
120 | pentiums. It contains an inner loop from | ||
121 | Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> which does raw ecb DES calls at | ||
122 | 273,000 per second. He had a previous version at 250,000 and the best | ||
123 | I was able to get was 203,000. The content has not changed, this is all | ||
124 | due to instruction sequencing (and actual instructions choice) which is able | ||
125 | to keep both functional units of the pentium going. | ||
126 | We may have lost the ugly register usage restrictions when x86 went 32 bit | ||
127 | but for the pentium it has been replaced by evil instruction ordering tricks. | ||
128 | |||
129 | 13 Jan 1997 - des-som3.pl, more optimizations from Svend Olaf. | ||
130 | raw DES at 281,000 per second on a pentium 100. | ||
131 | |||
diff --git a/src/lib/libcrypto/des/cbc3_enc.c b/src/lib/libcrypto/des/cbc3_enc.c new file mode 100644 index 0000000000..92a78b05d6 --- /dev/null +++ b/src/lib/libcrypto/des/cbc3_enc.c | |||
@@ -0,0 +1,99 @@ | |||
1 | /* crypto/des/cbc3_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 "des_locl.h" | ||
60 | |||
61 | /* HAS BUGS? DON'T USE - this is only present for use in des.c */ | ||
62 | void des_3cbc_encrypt(input, output, length, ks1, ks2, iv1, iv2, enc) | ||
63 | des_cblock (*input); | ||
64 | des_cblock (*output); | ||
65 | long length; | ||
66 | des_key_schedule ks1; | ||
67 | des_key_schedule ks2; | ||
68 | des_cblock (*iv1); | ||
69 | des_cblock (*iv2); | ||
70 | int enc; | ||
71 | { | ||
72 | int off=((int)length-1)/8; | ||
73 | long l8=((length+7)/8)*8; | ||
74 | des_cblock niv1,niv2; | ||
75 | |||
76 | if (enc == DES_ENCRYPT) | ||
77 | { | ||
78 | des_cbc_encrypt(input,output,length,ks1,iv1,enc); | ||
79 | if (length >= sizeof(des_cblock)) | ||
80 | memcpy(niv1,output[off],sizeof(des_cblock)); | ||
81 | des_cbc_encrypt(output,output,l8,ks2,iv1,!enc); | ||
82 | des_cbc_encrypt(output,output,l8,ks1,iv2, enc); | ||
83 | if (length >= sizeof(des_cblock)) | ||
84 | memcpy(niv2,output[off],sizeof(des_cblock)); | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | if (length >= sizeof(des_cblock)) | ||
89 | memcpy(niv2,input[off],sizeof(des_cblock)); | ||
90 | des_cbc_encrypt(input,output,l8,ks1,iv2,enc); | ||
91 | des_cbc_encrypt(output,output,l8,ks2,iv1,!enc); | ||
92 | if (length >= sizeof(des_cblock)) | ||
93 | memcpy(niv1,output[off],sizeof(des_cblock)); | ||
94 | des_cbc_encrypt(output,output,length,ks1,iv1, enc); | ||
95 | } | ||
96 | memcpy(*iv1,niv1,sizeof(des_cblock)); | ||
97 | memcpy(*iv2,niv2,sizeof(des_cblock)); | ||
98 | } | ||
99 | |||
diff --git a/src/lib/libcrypto/des/des.c b/src/lib/libcrypto/des/des.c new file mode 100644 index 0000000000..c1e5005474 --- /dev/null +++ b/src/lib/libcrypto/des/des.c | |||
@@ -0,0 +1,964 @@ | |||
1 | /* crypto/des/des.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <stdlib.h> | ||
61 | #ifndef MSDOS | ||
62 | #include <unistd.h> | ||
63 | #else | ||
64 | #include <io.h> | ||
65 | #define RAND | ||
66 | #endif | ||
67 | |||
68 | #include <time.h> | ||
69 | #include "des_ver.h" | ||
70 | |||
71 | #ifdef VMS | ||
72 | #include <types.h> | ||
73 | #include <stat.h> | ||
74 | #else | ||
75 | #ifndef _IRIX | ||
76 | #include <sys/types.h> | ||
77 | #endif | ||
78 | #include <sys/stat.h> | ||
79 | #endif | ||
80 | #if defined(NOCONST) | ||
81 | #define const | ||
82 | #endif | ||
83 | #include "des.h" | ||
84 | |||
85 | #if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS) | ||
86 | #include <string.h> | ||
87 | #endif | ||
88 | |||
89 | #ifdef RAND | ||
90 | #define random rand | ||
91 | #define srandom(s) srand(s) | ||
92 | #endif | ||
93 | |||
94 | #ifndef NOPROTO | ||
95 | void usage(void); | ||
96 | void doencryption(void); | ||
97 | int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp); | ||
98 | void uufwriteEnd(FILE *fp); | ||
99 | int uufread(unsigned char *out,int size,unsigned int num,FILE *fp); | ||
100 | int uuencode(unsigned char *in,int num,unsigned char *out); | ||
101 | int uudecode(unsigned char *in,int num,unsigned char *out); | ||
102 | void des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length, | ||
103 | des_key_schedule sk1,des_key_schedule sk2, | ||
104 | des_cblock *ivec1,des_cblock *ivec2,int enc); | ||
105 | #else | ||
106 | void usage(); | ||
107 | void doencryption(); | ||
108 | int uufwrite(); | ||
109 | void uufwriteEnd(); | ||
110 | int uufread(); | ||
111 | int uuencode(); | ||
112 | int uudecode(); | ||
113 | void des_3cbc_encrypt(); | ||
114 | #endif | ||
115 | |||
116 | #ifdef VMS | ||
117 | #define EXIT(a) exit(a&0x10000000L) | ||
118 | #else | ||
119 | #define EXIT(a) exit(a) | ||
120 | #endif | ||
121 | |||
122 | #define BUFSIZE (8*1024) | ||
123 | #define VERIFY 1 | ||
124 | #define KEYSIZ 8 | ||
125 | #define KEYSIZB 1024 /* should hit tty line limit first :-) */ | ||
126 | char key[KEYSIZB+1]; | ||
127 | int do_encrypt,longk=0; | ||
128 | FILE *DES_IN,*DES_OUT,*CKSUM_OUT; | ||
129 | char uuname[200]; | ||
130 | unsigned char uubuf[50]; | ||
131 | int uubufnum=0; | ||
132 | #define INUUBUFN (45*100) | ||
133 | #define OUTUUBUF (65*100) | ||
134 | unsigned char b[OUTUUBUF]; | ||
135 | unsigned char bb[300]; | ||
136 | des_cblock cksum={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; | ||
137 | char cksumname[200]=""; | ||
138 | |||
139 | int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error; | ||
140 | |||
141 | int main(argc, argv) | ||
142 | int argc; | ||
143 | char **argv; | ||
144 | { | ||
145 | int i; | ||
146 | struct stat ins,outs; | ||
147 | char *p; | ||
148 | char *in=NULL,*out=NULL; | ||
149 | |||
150 | vflag=cflag=eflag=dflag=kflag=hflag=bflag=fflag=sflag=uflag=flag3=0; | ||
151 | error=0; | ||
152 | memset(key,0,sizeof(key)); | ||
153 | |||
154 | for (i=1; i<argc; i++) | ||
155 | { | ||
156 | p=argv[i]; | ||
157 | if ((p[0] == '-') && (p[1] != '\0')) | ||
158 | { | ||
159 | p++; | ||
160 | while (*p) | ||
161 | { | ||
162 | switch (*(p++)) | ||
163 | { | ||
164 | case '3': | ||
165 | flag3=1; | ||
166 | longk=1; | ||
167 | break; | ||
168 | case 'c': | ||
169 | cflag=1; | ||
170 | strncpy(cksumname,p,200); | ||
171 | p+=strlen(cksumname); | ||
172 | break; | ||
173 | case 'C': | ||
174 | cflag=1; | ||
175 | longk=1; | ||
176 | strncpy(cksumname,p,200); | ||
177 | p+=strlen(cksumname); | ||
178 | break; | ||
179 | case 'e': | ||
180 | eflag=1; | ||
181 | break; | ||
182 | case 'v': | ||
183 | vflag=1; | ||
184 | break; | ||
185 | case 'E': | ||
186 | eflag=1; | ||
187 | longk=1; | ||
188 | break; | ||
189 | case 'd': | ||
190 | dflag=1; | ||
191 | break; | ||
192 | case 'D': | ||
193 | dflag=1; | ||
194 | longk=1; | ||
195 | break; | ||
196 | case 'b': | ||
197 | bflag=1; | ||
198 | break; | ||
199 | case 'f': | ||
200 | fflag=1; | ||
201 | break; | ||
202 | case 's': | ||
203 | sflag=1; | ||
204 | break; | ||
205 | case 'u': | ||
206 | uflag=1; | ||
207 | strncpy(uuname,p,200); | ||
208 | p+=strlen(uuname); | ||
209 | break; | ||
210 | case 'h': | ||
211 | hflag=1; | ||
212 | break; | ||
213 | case 'k': | ||
214 | kflag=1; | ||
215 | if ((i+1) == argc) | ||
216 | { | ||
217 | fputs("must have a key with the -k option\n",stderr); | ||
218 | error=1; | ||
219 | } | ||
220 | else | ||
221 | { | ||
222 | int j; | ||
223 | |||
224 | i++; | ||
225 | strncpy(key,argv[i],KEYSIZB); | ||
226 | for (j=strlen(argv[i])-1; j>=0; j--) | ||
227 | argv[i][j]='\0'; | ||
228 | } | ||
229 | break; | ||
230 | default: | ||
231 | fprintf(stderr,"'%c' unknown flag\n",p[-1]); | ||
232 | error=1; | ||
233 | break; | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | else | ||
238 | { | ||
239 | if (in == NULL) | ||
240 | in=argv[i]; | ||
241 | else if (out == NULL) | ||
242 | out=argv[i]; | ||
243 | else | ||
244 | error=1; | ||
245 | } | ||
246 | } | ||
247 | if (error) usage(); | ||
248 | /* We either | ||
249 | * do checksum or | ||
250 | * do encrypt or | ||
251 | * do decrypt or | ||
252 | * do decrypt then ckecksum or | ||
253 | * do checksum then encrypt | ||
254 | */ | ||
255 | if (((eflag+dflag) == 1) || cflag) | ||
256 | { | ||
257 | if (eflag) do_encrypt=DES_ENCRYPT; | ||
258 | if (dflag) do_encrypt=DES_DECRYPT; | ||
259 | } | ||
260 | else | ||
261 | { | ||
262 | if (vflag) | ||
263 | { | ||
264 | #ifndef _Windows | ||
265 | fprintf(stderr,"des(1) built with %s\n",libdes_version); | ||
266 | #endif | ||
267 | EXIT(1); | ||
268 | } | ||
269 | else usage(); | ||
270 | } | ||
271 | |||
272 | #ifndef _Windows | ||
273 | if (vflag) fprintf(stderr,"des(1) built with %s\n",libdes_version); | ||
274 | #endif | ||
275 | if ( (in != NULL) && | ||
276 | (out != NULL) && | ||
277 | #ifndef MSDOS | ||
278 | (stat(in,&ins) != -1) && | ||
279 | (stat(out,&outs) != -1) && | ||
280 | (ins.st_dev == outs.st_dev) && | ||
281 | (ins.st_ino == outs.st_ino)) | ||
282 | #else /* MSDOS */ | ||
283 | (strcmp(in,out) == 0)) | ||
284 | #endif | ||
285 | { | ||
286 | fputs("input and output file are the same\n",stderr); | ||
287 | EXIT(3); | ||
288 | } | ||
289 | |||
290 | if (!kflag) | ||
291 | if (des_read_pw_string(key,KEYSIZB+1,"Enter key:",eflag?VERIFY:0)) | ||
292 | { | ||
293 | fputs("password error\n",stderr); | ||
294 | EXIT(2); | ||
295 | } | ||
296 | |||
297 | if (in == NULL) | ||
298 | DES_IN=stdin; | ||
299 | else if ((DES_IN=fopen(in,"r")) == NULL) | ||
300 | { | ||
301 | perror("opening input file"); | ||
302 | EXIT(4); | ||
303 | } | ||
304 | |||
305 | CKSUM_OUT=stdout; | ||
306 | if (out == NULL) | ||
307 | { | ||
308 | DES_OUT=stdout; | ||
309 | CKSUM_OUT=stderr; | ||
310 | } | ||
311 | else if ((DES_OUT=fopen(out,"w")) == NULL) | ||
312 | { | ||
313 | perror("opening output file"); | ||
314 | EXIT(5); | ||
315 | } | ||
316 | |||
317 | #ifdef MSDOS | ||
318 | /* This should set the file to binary mode. */ | ||
319 | { | ||
320 | #include <fcntl.h> | ||
321 | if (!(uflag && dflag)) | ||
322 | setmode(fileno(DES_IN),O_BINARY); | ||
323 | if (!(uflag && eflag)) | ||
324 | setmode(fileno(DES_OUT),O_BINARY); | ||
325 | } | ||
326 | #endif | ||
327 | |||
328 | doencryption(); | ||
329 | fclose(DES_IN); | ||
330 | fclose(DES_OUT); | ||
331 | EXIT(0); | ||
332 | } | ||
333 | |||
334 | void usage() | ||
335 | { | ||
336 | char **u; | ||
337 | static const char *Usage[]={ | ||
338 | "des <options> [input-file [output-file]]", | ||
339 | "options:", | ||
340 | "-v : des(1) version number", | ||
341 | "-e : encrypt using sunOS compatible user key to DES key conversion.", | ||
342 | "-E : encrypt ", | ||
343 | "-d : decrypt using sunOS compatible user key to DES key conversion.", | ||
344 | "-D : decrypt ", | ||
345 | "-c[ckname] : generate a cbc_cksum using sunOS compatible user key to", | ||
346 | " DES key conversion and output to ckname (stdout default,", | ||
347 | " stderr if data being output on stdout). The checksum is", | ||
348 | " generated before encryption and after decryption if used", | ||
349 | " in conjunction with -[eEdD].", | ||
350 | "-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].", | ||
351 | "-k key : use key 'key'", | ||
352 | "-h : the key that is entered will be a hexidecimal number", | ||
353 | " that is used directly as the des key", | ||
354 | "-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]", | ||
355 | " (uuname is the filename to put in the uuencode header).", | ||
356 | "-b : encrypt using DES in ecb encryption mode, the defaut is cbc mode.", | ||
357 | "-3 : encrypt using tripple DES encryption. This uses 2 keys", | ||
358 | " generated from the input key. If the input key is less", | ||
359 | " than 8 characters long, this is equivelent to normal", | ||
360 | " encryption. Default is tripple cbc, -b makes it tripple ecb.", | ||
361 | NULL | ||
362 | }; | ||
363 | for (u=(char **)Usage; *u; u++) | ||
364 | { | ||
365 | fputs(*u,stderr); | ||
366 | fputc('\n',stderr); | ||
367 | } | ||
368 | |||
369 | EXIT(1); | ||
370 | } | ||
371 | |||
372 | void doencryption() | ||
373 | { | ||
374 | #ifdef _LIBC | ||
375 | extern int srandom(); | ||
376 | extern int random(); | ||
377 | extern unsigned long time(); | ||
378 | #endif | ||
379 | |||
380 | register int i; | ||
381 | des_key_schedule ks,ks2; | ||
382 | unsigned char iv[8],iv2[8]; | ||
383 | char *p; | ||
384 | int num=0,j,k,l,rem,ll,len,last,ex=0; | ||
385 | des_cblock kk,k2; | ||
386 | FILE *O; | ||
387 | int Exit=0; | ||
388 | #ifndef MSDOS | ||
389 | static unsigned char buf[BUFSIZE+8],obuf[BUFSIZE+8]; | ||
390 | #else | ||
391 | static unsigned char *buf=NULL,*obuf=NULL; | ||
392 | |||
393 | if (buf == NULL) | ||
394 | { | ||
395 | if ( (( buf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL) || | ||
396 | ((obuf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL)) | ||
397 | { | ||
398 | fputs("Not enough memory\n",stderr); | ||
399 | Exit=10; | ||
400 | goto problems; | ||
401 | } | ||
402 | } | ||
403 | #endif | ||
404 | |||
405 | if (hflag) | ||
406 | { | ||
407 | j=(flag3?16:8); | ||
408 | p=key; | ||
409 | for (i=0; i<j; i++) | ||
410 | { | ||
411 | k=0; | ||
412 | if ((*p <= '9') && (*p >= '0')) | ||
413 | k=(*p-'0')<<4; | ||
414 | else if ((*p <= 'f') && (*p >= 'a')) | ||
415 | k=(*p-'a'+10)<<4; | ||
416 | else if ((*p <= 'F') && (*p >= 'A')) | ||
417 | k=(*p-'A'+10)<<4; | ||
418 | else | ||
419 | { | ||
420 | fputs("Bad hex key\n",stderr); | ||
421 | Exit=9; | ||
422 | goto problems; | ||
423 | } | ||
424 | p++; | ||
425 | if ((*p <= '9') && (*p >= '0')) | ||
426 | k|=(*p-'0'); | ||
427 | else if ((*p <= 'f') && (*p >= 'a')) | ||
428 | k|=(*p-'a'+10); | ||
429 | else if ((*p <= 'F') && (*p >= 'A')) | ||
430 | k|=(*p-'A'+10); | ||
431 | else | ||
432 | { | ||
433 | fputs("Bad hex key\n",stderr); | ||
434 | Exit=9; | ||
435 | goto problems; | ||
436 | } | ||
437 | p++; | ||
438 | if (i < 8) | ||
439 | kk[i]=k; | ||
440 | else | ||
441 | k2[i-8]=k; | ||
442 | } | ||
443 | des_set_key((C_Block *)k2,ks2); | ||
444 | memset(k2,0,sizeof(k2)); | ||
445 | } | ||
446 | else if (longk || flag3) | ||
447 | { | ||
448 | if (flag3) | ||
449 | { | ||
450 | des_string_to_2keys(key,(C_Block *)kk,(C_Block *)k2); | ||
451 | des_set_key((C_Block *)k2,ks2); | ||
452 | memset(k2,0,sizeof(k2)); | ||
453 | } | ||
454 | else | ||
455 | des_string_to_key(key,(C_Block *)kk); | ||
456 | } | ||
457 | else | ||
458 | for (i=0; i<KEYSIZ; i++) | ||
459 | { | ||
460 | l=0; | ||
461 | k=key[i]; | ||
462 | for (j=0; j<8; j++) | ||
463 | { | ||
464 | if (k&1) l++; | ||
465 | k>>=1; | ||
466 | } | ||
467 | if (l & 1) | ||
468 | kk[i]=key[i]&0x7f; | ||
469 | else | ||
470 | kk[i]=key[i]|0x80; | ||
471 | } | ||
472 | |||
473 | des_set_key((C_Block *)kk,ks); | ||
474 | memset(key,0,sizeof(key)); | ||
475 | memset(kk,0,sizeof(kk)); | ||
476 | /* woops - A bug that does not showup under unix :-( */ | ||
477 | memset(iv,0,sizeof(iv)); | ||
478 | memset(iv2,0,sizeof(iv2)); | ||
479 | |||
480 | l=1; | ||
481 | rem=0; | ||
482 | /* first read */ | ||
483 | if (eflag || (!dflag && cflag)) | ||
484 | { | ||
485 | for (;;) | ||
486 | { | ||
487 | num=l=fread(&(buf[rem]),1,BUFSIZE,DES_IN); | ||
488 | l+=rem; | ||
489 | num+=rem; | ||
490 | if (l < 0) | ||
491 | { | ||
492 | perror("read error"); | ||
493 | Exit=6; | ||
494 | goto problems; | ||
495 | } | ||
496 | |||
497 | rem=l%8; | ||
498 | len=l-rem; | ||
499 | if (feof(DES_IN)) | ||
500 | { | ||
501 | srandom((unsigned int)time(NULL)); | ||
502 | for (i=7-rem; i>0; i--) | ||
503 | buf[l++]=random()&0xff; | ||
504 | buf[l++]=rem; | ||
505 | ex=1; | ||
506 | len+=rem; | ||
507 | } | ||
508 | else | ||
509 | l-=rem; | ||
510 | |||
511 | if (cflag) | ||
512 | { | ||
513 | des_cbc_cksum((C_Block *)buf,(C_Block *)cksum, | ||
514 | (long)len,ks,(C_Block *)cksum); | ||
515 | if (!eflag) | ||
516 | { | ||
517 | if (feof(DES_IN)) break; | ||
518 | else continue; | ||
519 | } | ||
520 | } | ||
521 | |||
522 | if (bflag && !flag3) | ||
523 | for (i=0; i<l; i+=8) | ||
524 | des_ecb_encrypt( | ||
525 | (des_cblock *)&(buf[i]), | ||
526 | (des_cblock *)&(obuf[i]), | ||
527 | ks,do_encrypt); | ||
528 | else if (flag3 && bflag) | ||
529 | for (i=0; i<l; i+=8) | ||
530 | des_ecb2_encrypt( | ||
531 | (des_cblock *)&(buf[i]), | ||
532 | (des_cblock *)&(obuf[i]), | ||
533 | ks,ks2,do_encrypt); | ||
534 | else if (flag3 && !bflag) | ||
535 | { | ||
536 | char tmpbuf[8]; | ||
537 | |||
538 | if (rem) memcpy(tmpbuf,&(buf[l]), | ||
539 | (unsigned int)rem); | ||
540 | des_3cbc_encrypt( | ||
541 | (des_cblock *)buf,(des_cblock *)obuf, | ||
542 | (long)l,ks,ks2,(des_cblock *)iv, | ||
543 | (des_cblock *)iv2,do_encrypt); | ||
544 | if (rem) memcpy(&(buf[l]),tmpbuf, | ||
545 | (unsigned int)rem); | ||
546 | } | ||
547 | else | ||
548 | { | ||
549 | des_cbc_encrypt( | ||
550 | (des_cblock *)buf,(des_cblock *)obuf, | ||
551 | (long)l,ks,(des_cblock *)iv,do_encrypt); | ||
552 | if (l >= 8) memcpy(iv,&(obuf[l-8]),8); | ||
553 | } | ||
554 | if (rem) memcpy(buf,&(buf[l]),(unsigned int)rem); | ||
555 | |||
556 | i=0; | ||
557 | while (i < l) | ||
558 | { | ||
559 | if (uflag) | ||
560 | j=uufwrite(obuf,1,(unsigned int)l-i, | ||
561 | DES_OUT); | ||
562 | else | ||
563 | j=fwrite(obuf,1,(unsigned int)l-i, | ||
564 | DES_OUT); | ||
565 | if (j == -1) | ||
566 | { | ||
567 | perror("Write error"); | ||
568 | Exit=7; | ||
569 | goto problems; | ||
570 | } | ||
571 | i+=j; | ||
572 | } | ||
573 | if (feof(DES_IN)) | ||
574 | { | ||
575 | if (uflag) uufwriteEnd(DES_OUT); | ||
576 | break; | ||
577 | } | ||
578 | } | ||
579 | } | ||
580 | else /* decrypt */ | ||
581 | { | ||
582 | ex=1; | ||
583 | for (;;) | ||
584 | { | ||
585 | if (ex) { | ||
586 | if (uflag) | ||
587 | l=uufread(buf,1,BUFSIZE,DES_IN); | ||
588 | else | ||
589 | l=fread(buf,1,BUFSIZE,DES_IN); | ||
590 | ex=0; | ||
591 | rem=l%8; | ||
592 | l-=rem; | ||
593 | } | ||
594 | if (l < 0) | ||
595 | { | ||
596 | perror("read error"); | ||
597 | Exit=6; | ||
598 | goto problems; | ||
599 | } | ||
600 | |||
601 | if (bflag && !flag3) | ||
602 | for (i=0; i<l; i+=8) | ||
603 | des_ecb_encrypt( | ||
604 | (des_cblock *)&(buf[i]), | ||
605 | (des_cblock *)&(obuf[i]), | ||
606 | ks,do_encrypt); | ||
607 | else if (flag3 && bflag) | ||
608 | for (i=0; i<l; i+=8) | ||
609 | des_ecb2_encrypt( | ||
610 | (des_cblock *)&(buf[i]), | ||
611 | (des_cblock *)&(obuf[i]), | ||
612 | ks,ks2,do_encrypt); | ||
613 | else if (flag3 && !bflag) | ||
614 | { | ||
615 | des_3cbc_encrypt( | ||
616 | (des_cblock *)buf,(des_cblock *)obuf, | ||
617 | (long)l,ks,ks2,(des_cblock *)iv, | ||
618 | (des_cblock *)iv2,do_encrypt); | ||
619 | } | ||
620 | else | ||
621 | { | ||
622 | des_cbc_encrypt( | ||
623 | (des_cblock *)buf,(des_cblock *)obuf, | ||
624 | (long)l,ks,(des_cblock *)iv,do_encrypt); | ||
625 | if (l >= 8) memcpy(iv,&(buf[l-8]),8); | ||
626 | } | ||
627 | |||
628 | if (uflag) | ||
629 | ll=uufread(&(buf[rem]),1,BUFSIZE,DES_IN); | ||
630 | else | ||
631 | ll=fread(&(buf[rem]),1,BUFSIZE,DES_IN); | ||
632 | ll+=rem; | ||
633 | rem=ll%8; | ||
634 | ll-=rem; | ||
635 | if (feof(DES_IN) && (ll == 0)) | ||
636 | { | ||
637 | last=obuf[l-1]; | ||
638 | |||
639 | if ((last > 7) || (last < 0)) | ||
640 | { | ||
641 | fputs("The file was not decrypted correctly.\n", | ||
642 | stderr); | ||
643 | Exit=8; | ||
644 | last=0; | ||
645 | } | ||
646 | l=l-8+last; | ||
647 | } | ||
648 | i=0; | ||
649 | if (cflag) des_cbc_cksum((C_Block *)obuf, | ||
650 | (C_Block *)cksum,(long)l/8*8,ks, | ||
651 | (C_Block *)cksum); | ||
652 | while (i != l) | ||
653 | { | ||
654 | j=fwrite(obuf,1,(unsigned int)l-i,DES_OUT); | ||
655 | if (j == -1) | ||
656 | { | ||
657 | perror("Write error"); | ||
658 | Exit=7; | ||
659 | goto problems; | ||
660 | } | ||
661 | i+=j; | ||
662 | } | ||
663 | l=ll; | ||
664 | if ((l == 0) && feof(DES_IN)) break; | ||
665 | } | ||
666 | } | ||
667 | if (cflag) | ||
668 | { | ||
669 | l=0; | ||
670 | if (cksumname[0] != '\0') | ||
671 | { | ||
672 | if ((O=fopen(cksumname,"w")) != NULL) | ||
673 | { | ||
674 | CKSUM_OUT=O; | ||
675 | l=1; | ||
676 | } | ||
677 | } | ||
678 | for (i=0; i<8; i++) | ||
679 | fprintf(CKSUM_OUT,"%02X",cksum[i]); | ||
680 | fprintf(CKSUM_OUT,"\n"); | ||
681 | if (l) fclose(CKSUM_OUT); | ||
682 | } | ||
683 | problems: | ||
684 | memset(buf,0,sizeof(buf)); | ||
685 | memset(obuf,0,sizeof(obuf)); | ||
686 | memset(ks,0,sizeof(ks)); | ||
687 | memset(ks2,0,sizeof(ks2)); | ||
688 | memset(iv,0,sizeof(iv)); | ||
689 | memset(iv2,0,sizeof(iv2)); | ||
690 | memset(kk,0,sizeof(kk)); | ||
691 | memset(k2,0,sizeof(k2)); | ||
692 | memset(uubuf,0,sizeof(uubuf)); | ||
693 | memset(b,0,sizeof(b)); | ||
694 | memset(bb,0,sizeof(bb)); | ||
695 | memset(cksum,0,sizeof(cksum)); | ||
696 | if (Exit) EXIT(Exit); | ||
697 | } | ||
698 | |||
699 | int uufwrite(data, size, num, fp) | ||
700 | unsigned char *data; | ||
701 | int size; | ||
702 | unsigned int num; | ||
703 | FILE *fp; | ||
704 | |||
705 | /* We ignore this parameter but it should be > ~50 I believe */ | ||
706 | |||
707 | |||
708 | { | ||
709 | int i,j,left,rem,ret=num; | ||
710 | static int start=1; | ||
711 | |||
712 | if (start) | ||
713 | { | ||
714 | fprintf(fp,"begin 600 %s\n", | ||
715 | (uuname[0] == '\0')?"text.d":uuname); | ||
716 | start=0; | ||
717 | } | ||
718 | |||
719 | if (uubufnum) | ||
720 | { | ||
721 | if (uubufnum+num < 45) | ||
722 | { | ||
723 | memcpy(&(uubuf[uubufnum]),data,(unsigned int)num); | ||
724 | uubufnum+=num; | ||
725 | return(num); | ||
726 | } | ||
727 | else | ||
728 | { | ||
729 | i=45-uubufnum; | ||
730 | memcpy(&(uubuf[uubufnum]),data,(unsigned int)i); | ||
731 | j=uuencode((unsigned char *)uubuf,45,b); | ||
732 | fwrite(b,1,(unsigned int)j,fp); | ||
733 | uubufnum=0; | ||
734 | data+=i; | ||
735 | num-=i; | ||
736 | } | ||
737 | } | ||
738 | |||
739 | for (i=0; i<(((int)num)-INUUBUFN); i+=INUUBUFN) | ||
740 | { | ||
741 | j=uuencode(&(data[i]),INUUBUFN,b); | ||
742 | fwrite(b,1,(unsigned int)j,fp); | ||
743 | } | ||
744 | rem=(num-i)%45; | ||
745 | left=(num-i-rem); | ||
746 | if (left) | ||
747 | { | ||
748 | j=uuencode(&(data[i]),left,b); | ||
749 | fwrite(b,1,(unsigned int)j,fp); | ||
750 | i+=left; | ||
751 | } | ||
752 | if (i != num) | ||
753 | { | ||
754 | memcpy(uubuf,&(data[i]),(unsigned int)rem); | ||
755 | uubufnum=rem; | ||
756 | } | ||
757 | return(ret); | ||
758 | } | ||
759 | |||
760 | void uufwriteEnd(fp) | ||
761 | FILE *fp; | ||
762 | { | ||
763 | int j; | ||
764 | static const char *end=" \nend\n"; | ||
765 | |||
766 | if (uubufnum != 0) | ||
767 | { | ||
768 | uubuf[uubufnum]='\0'; | ||
769 | uubuf[uubufnum+1]='\0'; | ||
770 | uubuf[uubufnum+2]='\0'; | ||
771 | j=uuencode(uubuf,uubufnum,b); | ||
772 | fwrite(b,1,(unsigned int)j,fp); | ||
773 | } | ||
774 | fwrite(end,1,strlen(end),fp); | ||
775 | } | ||
776 | |||
777 | int uufread(out, size, num, fp) | ||
778 | unsigned char *out; | ||
779 | int size; /* should always be > ~ 60; I actually ignore this parameter :-) */ | ||
780 | unsigned int num; | ||
781 | FILE *fp; | ||
782 | { | ||
783 | int i,j,tot; | ||
784 | static int done=0; | ||
785 | static int valid=0; | ||
786 | static int start=1; | ||
787 | |||
788 | if (start) | ||
789 | { | ||
790 | for (;;) | ||
791 | { | ||
792 | b[0]='\0'; | ||
793 | fgets((char *)b,300,fp); | ||
794 | if (b[0] == '\0') | ||
795 | { | ||
796 | fprintf(stderr,"no 'begin' found in uuencoded input\n"); | ||
797 | return(-1); | ||
798 | } | ||
799 | if (strncmp((char *)b,"begin ",6) == 0) break; | ||
800 | } | ||
801 | start=0; | ||
802 | } | ||
803 | if (done) return(0); | ||
804 | tot=0; | ||
805 | if (valid) | ||
806 | { | ||
807 | memcpy(out,bb,(unsigned int)valid); | ||
808 | tot=valid; | ||
809 | valid=0; | ||
810 | } | ||
811 | for (;;) | ||
812 | { | ||
813 | b[0]='\0'; | ||
814 | fgets((char *)b,300,fp); | ||
815 | if (b[0] == '\0') break; | ||
816 | i=strlen((char *)b); | ||
817 | if ((b[0] == 'e') && (b[1] == 'n') && (b[2] == 'd')) | ||
818 | { | ||
819 | done=1; | ||
820 | while (!feof(fp)) | ||
821 | { | ||
822 | fgets((char *)b,300,fp); | ||
823 | } | ||
824 | break; | ||
825 | } | ||
826 | i=uudecode(b,i,bb); | ||
827 | if (i < 0) break; | ||
828 | if ((i+tot+8) > num) | ||
829 | { | ||
830 | /* num to copy to make it a multiple of 8 */ | ||
831 | j=(num/8*8)-tot-8; | ||
832 | memcpy(&(out[tot]),bb,(unsigned int)j); | ||
833 | tot+=j; | ||
834 | memcpy(bb,&(bb[j]),(unsigned int)i-j); | ||
835 | valid=i-j; | ||
836 | break; | ||
837 | } | ||
838 | memcpy(&(out[tot]),bb,(unsigned int)i); | ||
839 | tot+=i; | ||
840 | } | ||
841 | return(tot); | ||
842 | } | ||
843 | |||
844 | #define ccc2l(c,l) (l =((DES_LONG)(*((c)++)))<<16, \ | ||
845 | l|=((DES_LONG)(*((c)++)))<< 8, \ | ||
846 | l|=((DES_LONG)(*((c)++)))) | ||
847 | |||
848 | #define l2ccc(l,c) (*((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
849 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
850 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
851 | |||
852 | |||
853 | int uuencode(in, num, out) | ||
854 | unsigned char *in; | ||
855 | int num; | ||
856 | unsigned char *out; | ||
857 | { | ||
858 | int j,i,n,tot=0; | ||
859 | DES_LONG l; | ||
860 | register unsigned char *p; | ||
861 | p=out; | ||
862 | |||
863 | for (j=0; j<num; j+=45) | ||
864 | { | ||
865 | if (j+45 > num) | ||
866 | i=(num-j); | ||
867 | else i=45; | ||
868 | *(p++)=i+' '; | ||
869 | for (n=0; n<i; n+=3) | ||
870 | { | ||
871 | ccc2l(in,l); | ||
872 | *(p++)=((l>>18)&0x3f)+' '; | ||
873 | *(p++)=((l>>12)&0x3f)+' '; | ||
874 | *(p++)=((l>> 6)&0x3f)+' '; | ||
875 | *(p++)=((l )&0x3f)+' '; | ||
876 | tot+=4; | ||
877 | } | ||
878 | *(p++)='\n'; | ||
879 | tot+=2; | ||
880 | } | ||
881 | *p='\0'; | ||
882 | l=0; | ||
883 | return(tot); | ||
884 | } | ||
885 | |||
886 | int uudecode(in, num, out) | ||
887 | unsigned char *in; | ||
888 | int num; | ||
889 | unsigned char *out; | ||
890 | { | ||
891 | int j,i,k; | ||
892 | unsigned int n=0,space=0; | ||
893 | DES_LONG l; | ||
894 | DES_LONG w,x,y,z; | ||
895 | unsigned int blank=(unsigned int)'\n'-' '; | ||
896 | |||
897 | for (j=0; j<num; ) | ||
898 | { | ||
899 | n= *(in++)-' '; | ||
900 | if (n == blank) | ||
901 | { | ||
902 | n=0; | ||
903 | in--; | ||
904 | } | ||
905 | if (n > 60) | ||
906 | { | ||
907 | fprintf(stderr,"uuencoded line length too long\n"); | ||
908 | return(-1); | ||
909 | } | ||
910 | j++; | ||
911 | |||
912 | for (i=0; i<n; j+=4,i+=3) | ||
913 | { | ||
914 | /* the following is for cases where spaces are | ||
915 | * removed from lines. | ||
916 | */ | ||
917 | if (space) | ||
918 | { | ||
919 | w=x=y=z=0; | ||
920 | } | ||
921 | else | ||
922 | { | ||
923 | w= *(in++)-' '; | ||
924 | x= *(in++)-' '; | ||
925 | y= *(in++)-' '; | ||
926 | z= *(in++)-' '; | ||
927 | } | ||
928 | if ((w > 63) || (x > 63) || (y > 63) || (z > 63)) | ||
929 | { | ||
930 | k=0; | ||
931 | if (w == blank) k=1; | ||
932 | if (x == blank) k=2; | ||
933 | if (y == blank) k=3; | ||
934 | if (z == blank) k=4; | ||
935 | space=1; | ||
936 | switch (k) { | ||
937 | case 1: w=0; in--; | ||
938 | case 2: x=0; in--; | ||
939 | case 3: y=0; in--; | ||
940 | case 4: z=0; in--; | ||
941 | break; | ||
942 | case 0: | ||
943 | space=0; | ||
944 | fprintf(stderr,"bad uuencoded data values\n"); | ||
945 | w=x=y=z=0; | ||
946 | return(-1); | ||
947 | break; | ||
948 | } | ||
949 | } | ||
950 | l=(w<<18)|(x<<12)|(y<< 6)|(z ); | ||
951 | l2ccc(l,out); | ||
952 | } | ||
953 | if (*(in++) != '\n') | ||
954 | { | ||
955 | fprintf(stderr,"missing nl in uuencoded line\n"); | ||
956 | w=x=y=z=0; | ||
957 | return(-1); | ||
958 | } | ||
959 | j++; | ||
960 | } | ||
961 | *out='\0'; | ||
962 | w=x=y=z=0; | ||
963 | return(n); | ||
964 | } | ||
diff --git a/src/lib/libcrypto/des/des3s.cpp b/src/lib/libcrypto/des/des3s.cpp new file mode 100644 index 0000000000..9aff6494d9 --- /dev/null +++ b/src/lib/libcrypto/des/des3s.cpp | |||
@@ -0,0 +1,67 @@ | |||
1 | // | ||
2 | // gettsc.inl | ||
3 | // | ||
4 | // gives access to the Pentium's (secret) cycle counter | ||
5 | // | ||
6 | // This software was written by Leonard Janke (janke@unixg.ubc.ca) | ||
7 | // in 1996-7 and is entered, by him, into the public domain. | ||
8 | |||
9 | #if defined(__WATCOMC__) | ||
10 | void GetTSC(unsigned long&); | ||
11 | #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; | ||
12 | #elif defined(__GNUC__) | ||
13 | inline | ||
14 | void GetTSC(unsigned long& tsc) | ||
15 | { | ||
16 | asm volatile(".byte 15, 49\n\t" | ||
17 | : "=eax" (tsc) | ||
18 | : | ||
19 | : "%edx", "%eax"); | ||
20 | } | ||
21 | #elif defined(_MSC_VER) | ||
22 | inline | ||
23 | void GetTSC(unsigned long& tsc) | ||
24 | { | ||
25 | unsigned long a; | ||
26 | __asm _emit 0fh | ||
27 | __asm _emit 31h | ||
28 | __asm mov a, eax; | ||
29 | tsc=a; | ||
30 | } | ||
31 | #endif | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include <stdlib.h> | ||
35 | #include "des.h" | ||
36 | |||
37 | void main(int argc,char *argv[]) | ||
38 | { | ||
39 | des_key_schedule key1,key2,key3; | ||
40 | unsigned long s1,s2,e1,e2; | ||
41 | unsigned long data[2]; | ||
42 | int i,j; | ||
43 | |||
44 | for (j=0; j<6; j++) | ||
45 | { | ||
46 | for (i=0; i<1000; i++) /**/ | ||
47 | { | ||
48 | des_encrypt3(&data[0],key1,key2,key3); | ||
49 | GetTSC(s1); | ||
50 | des_encrypt3(&data[0],key1,key2,key3); | ||
51 | des_encrypt3(&data[0],key1,key2,key3); | ||
52 | des_encrypt3(&data[0],key1,key2,key3); | ||
53 | GetTSC(e1); | ||
54 | GetTSC(s2); | ||
55 | des_encrypt3(&data[0],key1,key2,key3); | ||
56 | des_encrypt3(&data[0],key1,key2,key3); | ||
57 | des_encrypt3(&data[0],key1,key2,key3); | ||
58 | des_encrypt3(&data[0],key1,key2,key3); | ||
59 | GetTSC(e2); | ||
60 | des_encrypt3(&data[0],key1,key2,key3); | ||
61 | } | ||
62 | |||
63 | printf("des %d %d (%d)\n", | ||
64 | e1-s1,e2-s2,((e2-s2)-(e1-s1))); | ||
65 | } | ||
66 | } | ||
67 | |||
diff --git a/src/lib/libcrypto/des/des_opts.c b/src/lib/libcrypto/des/des_opts.c new file mode 100644 index 0000000000..fdf0fbf461 --- /dev/null +++ b/src/lib/libcrypto/des/des_opts.c | |||
@@ -0,0 +1,620 @@ | |||
1 | /* crypto/des/des_opts.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 | /* define PART1, PART2, PART3 or PART4 to build only with a few of the options. | ||
60 | * This is for machines with 64k code segment size restrictions. */ | ||
61 | |||
62 | #ifndef MSDOS | ||
63 | #define TIMES | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | #ifndef MSDOS | ||
68 | #include <unistd.h> | ||
69 | #else | ||
70 | #include <io.h> | ||
71 | extern void exit(); | ||
72 | #endif | ||
73 | #include <signal.h> | ||
74 | #ifndef VMS | ||
75 | #ifndef _IRIX | ||
76 | #include <time.h> | ||
77 | #endif | ||
78 | #ifdef TIMES | ||
79 | #include <sys/types.h> | ||
80 | #include <sys/times.h> | ||
81 | #endif | ||
82 | #else /* VMS */ | ||
83 | #include <types.h> | ||
84 | struct tms { | ||
85 | time_t tms_utime; | ||
86 | time_t tms_stime; | ||
87 | time_t tms_uchild; /* I dunno... */ | ||
88 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
89 | } | ||
90 | #endif | ||
91 | #ifndef TIMES | ||
92 | #include <sys/timeb.h> | ||
93 | #endif | ||
94 | |||
95 | #ifdef sun | ||
96 | #include <limits.h> | ||
97 | #include <sys/param.h> | ||
98 | #endif | ||
99 | |||
100 | #include "des.h" | ||
101 | #include "spr.h" | ||
102 | |||
103 | #define DES_DEFAULT_OPTIONS | ||
104 | |||
105 | #if !defined(PART1) && !defined(PART2) && !defined(PART3) && !defined(PART4) | ||
106 | #define PART1 | ||
107 | #define PART2 | ||
108 | #define PART3 | ||
109 | #define PART4 | ||
110 | #endif | ||
111 | |||
112 | #ifdef PART1 | ||
113 | |||
114 | #undef DES_UNROLL | ||
115 | #undef DES_RISC1 | ||
116 | #undef DES_RISC2 | ||
117 | #undef DES_PTR | ||
118 | #undef D_ENCRYPT | ||
119 | #define des_encrypt des_encrypt_u4_cisc_idx | ||
120 | #define des_encrypt2 des_encrypt2_u4_cisc_idx | ||
121 | #define des_encrypt3 des_encrypt3_u4_cisc_idx | ||
122 | #define des_decrypt3 des_decrypt3_u4_cisc_idx | ||
123 | #undef HEADER_DES_LOCL_H | ||
124 | #include "des_enc.c" | ||
125 | |||
126 | #define DES_UNROLL | ||
127 | #undef DES_RISC1 | ||
128 | #undef DES_RISC2 | ||
129 | #undef DES_PTR | ||
130 | #undef D_ENCRYPT | ||
131 | #undef des_encrypt | ||
132 | #undef des_encrypt2 | ||
133 | #undef des_encrypt3 | ||
134 | #undef des_decrypt3 | ||
135 | #define des_encrypt des_encrypt_u16_cisc_idx | ||
136 | #define des_encrypt2 des_encrypt2_u16_cisc_idx | ||
137 | #define des_encrypt3 des_encrypt3_u16_cisc_idx | ||
138 | #define des_decrypt3 des_decrypt3_u16_cisc_idx | ||
139 | #undef HEADER_DES_LOCL_H | ||
140 | #include "des_enc.c" | ||
141 | |||
142 | #undef DES_UNROLL | ||
143 | #define DES_RISC1 | ||
144 | #undef DES_RISC2 | ||
145 | #undef DES_PTR | ||
146 | #undef D_ENCRYPT | ||
147 | #undef des_encrypt | ||
148 | #undef des_encrypt2 | ||
149 | #undef des_encrypt3 | ||
150 | #undef des_decrypt3 | ||
151 | #define des_encrypt des_encrypt_u4_risc1_idx | ||
152 | #define des_encrypt2 des_encrypt2_u4_risc1_idx | ||
153 | #define des_encrypt3 des_encrypt3_u4_risc1_idx | ||
154 | #define des_decrypt3 des_decrypt3_u4_risc1_idx | ||
155 | #undef HEADER_DES_LOCL_H | ||
156 | #include "des_enc.c" | ||
157 | |||
158 | #endif | ||
159 | |||
160 | #ifdef PART2 | ||
161 | |||
162 | #undef DES_UNROLL | ||
163 | #undef DES_RISC1 | ||
164 | #define DES_RISC2 | ||
165 | #undef DES_PTR | ||
166 | #undef D_ENCRYPT | ||
167 | #undef des_encrypt | ||
168 | #undef des_encrypt2 | ||
169 | #undef des_encrypt3 | ||
170 | #undef des_decrypt3 | ||
171 | #define des_encrypt des_encrypt_u4_risc2_idx | ||
172 | #define des_encrypt2 des_encrypt2_u4_risc2_idx | ||
173 | #define des_encrypt3 des_encrypt3_u4_risc2_idx | ||
174 | #define des_decrypt3 des_decrypt3_u4_risc2_idx | ||
175 | #undef HEADER_DES_LOCL_H | ||
176 | #include "des_enc.c" | ||
177 | |||
178 | #define DES_UNROLL | ||
179 | #define DES_RISC1 | ||
180 | #undef DES_RISC2 | ||
181 | #undef DES_PTR | ||
182 | #undef D_ENCRYPT | ||
183 | #undef des_encrypt | ||
184 | #undef des_encrypt2 | ||
185 | #undef des_encrypt3 | ||
186 | #undef des_decrypt3 | ||
187 | #define des_encrypt des_encrypt_u16_risc1_idx | ||
188 | #define des_encrypt2 des_encrypt2_u16_risc1_idx | ||
189 | #define des_encrypt3 des_encrypt3_u16_risc1_idx | ||
190 | #define des_decrypt3 des_decrypt3_u16_risc1_idx | ||
191 | #undef HEADER_DES_LOCL_H | ||
192 | #include "des_enc.c" | ||
193 | |||
194 | #define DES_UNROLL | ||
195 | #undef DES_RISC1 | ||
196 | #define DES_RISC2 | ||
197 | #undef DES_PTR | ||
198 | #undef D_ENCRYPT | ||
199 | #undef des_encrypt | ||
200 | #undef des_encrypt2 | ||
201 | #undef des_encrypt3 | ||
202 | #undef des_decrypt3 | ||
203 | #define des_encrypt des_encrypt_u16_risc2_idx | ||
204 | #define des_encrypt2 des_encrypt2_u16_risc2_idx | ||
205 | #define des_encrypt3 des_encrypt3_u16_risc2_idx | ||
206 | #define des_decrypt3 des_decrypt3_u16_risc2_idx | ||
207 | #undef HEADER_DES_LOCL_H | ||
208 | #include "des_enc.c" | ||
209 | |||
210 | #endif | ||
211 | |||
212 | #ifdef PART3 | ||
213 | |||
214 | #undef DES_UNROLL | ||
215 | #undef DES_RISC1 | ||
216 | #undef DES_RISC2 | ||
217 | #define DES_PTR | ||
218 | #undef D_ENCRYPT | ||
219 | #undef des_encrypt | ||
220 | #undef des_encrypt2 | ||
221 | #undef des_encrypt3 | ||
222 | #undef des_decrypt3 | ||
223 | #define des_encrypt des_encrypt_u4_cisc_ptr | ||
224 | #define des_encrypt2 des_encrypt2_u4_cisc_ptr | ||
225 | #define des_encrypt3 des_encrypt3_u4_cisc_ptr | ||
226 | #define des_decrypt3 des_decrypt3_u4_cisc_ptr | ||
227 | #undef HEADER_DES_LOCL_H | ||
228 | #include "des_enc.c" | ||
229 | |||
230 | #define DES_UNROLL | ||
231 | #undef DES_RISC1 | ||
232 | #undef DES_RISC2 | ||
233 | #define DES_PTR | ||
234 | #undef D_ENCRYPT | ||
235 | #undef des_encrypt | ||
236 | #undef des_encrypt2 | ||
237 | #undef des_encrypt3 | ||
238 | #undef des_decrypt3 | ||
239 | #define des_encrypt des_encrypt_u16_cisc_ptr | ||
240 | #define des_encrypt2 des_encrypt2_u16_cisc_ptr | ||
241 | #define des_encrypt3 des_encrypt3_u16_cisc_ptr | ||
242 | #define des_decrypt3 des_decrypt3_u16_cisc_ptr | ||
243 | #undef HEADER_DES_LOCL_H | ||
244 | #include "des_enc.c" | ||
245 | |||
246 | #undef DES_UNROLL | ||
247 | #define DES_RISC1 | ||
248 | #undef DES_RISC2 | ||
249 | #define DES_PTR | ||
250 | #undef D_ENCRYPT | ||
251 | #undef des_encrypt | ||
252 | #undef des_encrypt2 | ||
253 | #undef des_encrypt3 | ||
254 | #undef des_decrypt3 | ||
255 | #define des_encrypt des_encrypt_u4_risc1_ptr | ||
256 | #define des_encrypt2 des_encrypt2_u4_risc1_ptr | ||
257 | #define des_encrypt3 des_encrypt3_u4_risc1_ptr | ||
258 | #define des_decrypt3 des_decrypt3_u4_risc1_ptr | ||
259 | #undef HEADER_DES_LOCL_H | ||
260 | #include "des_enc.c" | ||
261 | |||
262 | #endif | ||
263 | |||
264 | #ifdef PART4 | ||
265 | |||
266 | #undef DES_UNROLL | ||
267 | #undef DES_RISC1 | ||
268 | #define DES_RISC2 | ||
269 | #define DES_PTR | ||
270 | #undef D_ENCRYPT | ||
271 | #undef des_encrypt | ||
272 | #undef des_encrypt2 | ||
273 | #undef des_encrypt3 | ||
274 | #undef des_decrypt3 | ||
275 | #define des_encrypt des_encrypt_u4_risc2_ptr | ||
276 | #define des_encrypt2 des_encrypt2_u4_risc2_ptr | ||
277 | #define des_encrypt3 des_encrypt3_u4_risc2_ptr | ||
278 | #define des_decrypt3 des_decrypt3_u4_risc2_ptr | ||
279 | #undef HEADER_DES_LOCL_H | ||
280 | #include "des_enc.c" | ||
281 | |||
282 | #define DES_UNROLL | ||
283 | #define DES_RISC1 | ||
284 | #undef DES_RISC2 | ||
285 | #define DES_PTR | ||
286 | #undef D_ENCRYPT | ||
287 | #undef des_encrypt | ||
288 | #undef des_encrypt2 | ||
289 | #undef des_encrypt3 | ||
290 | #undef des_decrypt3 | ||
291 | #define des_encrypt des_encrypt_u16_risc1_ptr | ||
292 | #define des_encrypt2 des_encrypt2_u16_risc1_ptr | ||
293 | #define des_encrypt3 des_encrypt3_u16_risc1_ptr | ||
294 | #define des_decrypt3 des_decrypt3_u16_risc1_ptr | ||
295 | #undef HEADER_DES_LOCL_H | ||
296 | #include "des_enc.c" | ||
297 | |||
298 | #define DES_UNROLL | ||
299 | #undef DES_RISC1 | ||
300 | #define DES_RISC2 | ||
301 | #define DES_PTR | ||
302 | #undef D_ENCRYPT | ||
303 | #undef des_encrypt | ||
304 | #undef des_encrypt2 | ||
305 | #undef des_encrypt3 | ||
306 | #undef des_decrypt3 | ||
307 | #define des_encrypt des_encrypt_u16_risc2_ptr | ||
308 | #define des_encrypt2 des_encrypt2_u16_risc2_ptr | ||
309 | #define des_encrypt3 des_encrypt3_u16_risc2_ptr | ||
310 | #define des_decrypt3 des_decrypt3_u16_risc2_ptr | ||
311 | #undef HEADER_DES_LOCL_H | ||
312 | #include "des_enc.c" | ||
313 | |||
314 | #endif | ||
315 | |||
316 | /* The following if from times(3) man page. It may need to be changed */ | ||
317 | #ifndef HZ | ||
318 | # ifndef CLK_TCK | ||
319 | # ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ | ||
320 | # ifndef VMS | ||
321 | # define HZ 100.0 | ||
322 | # else /* VMS */ | ||
323 | # define HZ 100.0 | ||
324 | # endif | ||
325 | # else /* _BSD_CLK_TCK_ */ | ||
326 | # define HZ ((double)_BSD_CLK_TCK_) | ||
327 | # endif | ||
328 | # else /* CLK_TCK */ | ||
329 | # define HZ ((double)CLK_TCK) | ||
330 | # endif | ||
331 | #endif | ||
332 | |||
333 | #define BUFSIZE ((long)1024) | ||
334 | long run=0; | ||
335 | |||
336 | #ifndef NOPROTO | ||
337 | double Time_F(int s); | ||
338 | #else | ||
339 | double Time_F(); | ||
340 | #endif | ||
341 | |||
342 | #ifdef SIGALRM | ||
343 | #if defined(__STDC__) || defined(sgi) | ||
344 | #define SIGRETTYPE void | ||
345 | #else | ||
346 | #define SIGRETTYPE int | ||
347 | #endif | ||
348 | |||
349 | #ifndef NOPROTO | ||
350 | SIGRETTYPE sig_done(int sig); | ||
351 | #else | ||
352 | SIGRETTYPE sig_done(); | ||
353 | #endif | ||
354 | |||
355 | SIGRETTYPE sig_done(sig) | ||
356 | int sig; | ||
357 | { | ||
358 | signal(SIGALRM,sig_done); | ||
359 | run=0; | ||
360 | #ifdef LINT | ||
361 | sig=sig; | ||
362 | #endif | ||
363 | } | ||
364 | #endif | ||
365 | |||
366 | #define START 0 | ||
367 | #define STOP 1 | ||
368 | |||
369 | double Time_F(s) | ||
370 | int s; | ||
371 | { | ||
372 | double ret; | ||
373 | #ifdef TIMES | ||
374 | static struct tms tstart,tend; | ||
375 | |||
376 | if (s == START) | ||
377 | { | ||
378 | times(&tstart); | ||
379 | return(0); | ||
380 | } | ||
381 | else | ||
382 | { | ||
383 | times(&tend); | ||
384 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
385 | return((ret == 0.0)?1e-6:ret); | ||
386 | } | ||
387 | #else /* !times() */ | ||
388 | static struct timeb tstart,tend; | ||
389 | long i; | ||
390 | |||
391 | if (s == START) | ||
392 | { | ||
393 | ftime(&tstart); | ||
394 | return(0); | ||
395 | } | ||
396 | else | ||
397 | { | ||
398 | ftime(&tend); | ||
399 | i=(long)tend.millitm-(long)tstart.millitm; | ||
400 | ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; | ||
401 | return((ret == 0.0)?1e-6:ret); | ||
402 | } | ||
403 | #endif | ||
404 | } | ||
405 | |||
406 | #ifdef SIGALRM | ||
407 | #define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10); | ||
408 | #else | ||
409 | #define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb); | ||
410 | #endif | ||
411 | |||
412 | #define time_it(func,name,index) \ | ||
413 | print_name(name); \ | ||
414 | Time_F(START); \ | ||
415 | for (count=0,run=1; COND(cb); count++) \ | ||
416 | { \ | ||
417 | unsigned long d[2]; \ | ||
418 | func(d,&(sch[0]),DES_ENCRYPT); \ | ||
419 | } \ | ||
420 | tm[index]=Time_F(STOP); \ | ||
421 | fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \ | ||
422 | tm[index]=((double)COUNT(cb))/tm[index]; | ||
423 | |||
424 | #define print_it(name,index) \ | ||
425 | fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \ | ||
426 | tm[index]*8,1.0e6/tm[index]); | ||
427 | |||
428 | int main(argc,argv) | ||
429 | int argc; | ||
430 | char **argv; | ||
431 | { | ||
432 | long count; | ||
433 | static unsigned char buf[BUFSIZE]; | ||
434 | static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; | ||
435 | static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; | ||
436 | static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; | ||
437 | des_key_schedule sch,sch2,sch3; | ||
438 | double d,tm[16],max=0; | ||
439 | int rank[16]; | ||
440 | char *str[16]; | ||
441 | int max_idx=0,i,num=0,j; | ||
442 | #ifndef SIGALARM | ||
443 | long ca,cb,cc,cd,ce; | ||
444 | #endif | ||
445 | |||
446 | for (i=0; i<12; i++) | ||
447 | { | ||
448 | tm[i]=0.0; | ||
449 | rank[i]=0; | ||
450 | } | ||
451 | |||
452 | #ifndef TIMES | ||
453 | fprintf(stderr,"To get the most acurate results, try to run this\n"); | ||
454 | fprintf(stderr,"program when this computer is idle.\n"); | ||
455 | #endif | ||
456 | |||
457 | des_set_key((C_Block *)key,sch); | ||
458 | des_set_key((C_Block *)key2,sch2); | ||
459 | des_set_key((C_Block *)key3,sch3); | ||
460 | |||
461 | #ifndef SIGALRM | ||
462 | fprintf(stderr,"First we calculate the approximate speed ...\n"); | ||
463 | des_set_key((C_Block *)key,sch); | ||
464 | count=10; | ||
465 | do { | ||
466 | long i; | ||
467 | unsigned long data[2]; | ||
468 | |||
469 | count*=2; | ||
470 | Time_F(START); | ||
471 | for (i=count; i; i--) | ||
472 | des_encrypt(data,&(sch[0]),DES_ENCRYPT); | ||
473 | d=Time_F(STOP); | ||
474 | } while (d < 3.0); | ||
475 | ca=count; | ||
476 | cb=count*3; | ||
477 | cc=count*3*8/BUFSIZE+1; | ||
478 | cd=count*8/BUFSIZE+1; | ||
479 | |||
480 | ce=count/20+1; | ||
481 | #define COND(d) (count != (d)) | ||
482 | #define COUNT(d) (d) | ||
483 | #else | ||
484 | #define COND(c) (run) | ||
485 | #define COUNT(d) (count) | ||
486 | signal(SIGALRM,sig_done); | ||
487 | alarm(10); | ||
488 | #endif | ||
489 | |||
490 | #ifdef PART1 | ||
491 | time_it(des_encrypt_u4_cisc_idx, "des_encrypt_u4_cisc_idx ", 0); | ||
492 | time_it(des_encrypt_u16_cisc_idx, "des_encrypt_u16_cisc_idx ", 1); | ||
493 | time_it(des_encrypt_u4_risc1_idx, "des_encrypt_u4_risc1_idx ", 2); | ||
494 | num+=3; | ||
495 | #endif | ||
496 | #ifdef PART2 | ||
497 | time_it(des_encrypt_u16_risc1_idx,"des_encrypt_u16_risc1_idx", 3); | ||
498 | time_it(des_encrypt_u4_risc2_idx, "des_encrypt_u4_risc2_idx ", 4); | ||
499 | time_it(des_encrypt_u16_risc2_idx,"des_encrypt_u16_risc2_idx", 5); | ||
500 | num+=3; | ||
501 | #endif | ||
502 | #ifdef PART3 | ||
503 | time_it(des_encrypt_u4_cisc_ptr, "des_encrypt_u4_cisc_ptr ", 6); | ||
504 | time_it(des_encrypt_u16_cisc_ptr, "des_encrypt_u16_cisc_ptr ", 7); | ||
505 | time_it(des_encrypt_u4_risc1_ptr, "des_encrypt_u4_risc1_ptr ", 8); | ||
506 | num+=3; | ||
507 | #endif | ||
508 | #ifdef PART4 | ||
509 | time_it(des_encrypt_u16_risc1_ptr,"des_encrypt_u16_risc1_ptr", 9); | ||
510 | time_it(des_encrypt_u4_risc2_ptr, "des_encrypt_u4_risc2_ptr ",10); | ||
511 | time_it(des_encrypt_u16_risc2_ptr,"des_encrypt_u16_risc2_ptr",11); | ||
512 | num+=3; | ||
513 | #endif | ||
514 | |||
515 | #ifdef PART1 | ||
516 | str[0]=" 4 c i"; | ||
517 | print_it("des_encrypt_u4_cisc_idx ",0); | ||
518 | max=tm[0]; | ||
519 | max_idx=0; | ||
520 | str[1]="16 c i"; | ||
521 | print_it("des_encrypt_u16_cisc_idx ",1); | ||
522 | if (max < tm[1]) { max=tm[1]; max_idx=1; } | ||
523 | str[2]=" 4 r1 i"; | ||
524 | print_it("des_encrypt_u4_risc1_idx ",2); | ||
525 | if (max < tm[2]) { max=tm[2]; max_idx=2; } | ||
526 | #endif | ||
527 | #ifdef PART2 | ||
528 | str[3]="16 r1 i"; | ||
529 | print_it("des_encrypt_u16_risc1_idx",3); | ||
530 | if (max < tm[3]) { max=tm[3]; max_idx=3; } | ||
531 | str[4]=" 4 r2 i"; | ||
532 | print_it("des_encrypt_u4_risc2_idx ",4); | ||
533 | if (max < tm[4]) { max=tm[4]; max_idx=4; } | ||
534 | str[5]="16 r2 i"; | ||
535 | print_it("des_encrypt_u16_risc2_idx",5); | ||
536 | if (max < tm[5]) { max=tm[5]; max_idx=5; } | ||
537 | #endif | ||
538 | #ifdef PART3 | ||
539 | str[6]=" 4 c p"; | ||
540 | print_it("des_encrypt_u4_cisc_ptr ",6); | ||
541 | if (max < tm[6]) { max=tm[6]; max_idx=6; } | ||
542 | str[7]="16 c p"; | ||
543 | print_it("des_encrypt_u16_cisc_ptr ",7); | ||
544 | if (max < tm[7]) { max=tm[7]; max_idx=7; } | ||
545 | str[8]=" 4 r1 p"; | ||
546 | print_it("des_encrypt_u4_risc1_ptr ",8); | ||
547 | if (max < tm[8]) { max=tm[8]; max_idx=8; } | ||
548 | #endif | ||
549 | #ifdef PART4 | ||
550 | str[9]="16 r1 p"; | ||
551 | print_it("des_encrypt_u16_risc1_ptr",9); | ||
552 | if (max < tm[9]) { max=tm[9]; max_idx=9; } | ||
553 | str[10]=" 4 r2 p"; | ||
554 | print_it("des_encrypt_u4_risc2_ptr ",10); | ||
555 | if (max < tm[10]) { max=tm[10]; max_idx=10; } | ||
556 | str[11]="16 r2 p"; | ||
557 | print_it("des_encrypt_u16_risc2_ptr",11); | ||
558 | if (max < tm[11]) { max=tm[11]; max_idx=11; } | ||
559 | #endif | ||
560 | printf("options des ecb/s\n"); | ||
561 | printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]); | ||
562 | d=tm[max_idx]; | ||
563 | tm[max_idx]= -2.0; | ||
564 | max= -1.0; | ||
565 | for (;;) | ||
566 | { | ||
567 | for (i=0; i<12; i++) | ||
568 | { | ||
569 | if (max < tm[i]) { max=tm[i]; j=i; } | ||
570 | } | ||
571 | if (max < 0.0) break; | ||
572 | printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0); | ||
573 | tm[j]= -2.0; | ||
574 | max= -1.0; | ||
575 | } | ||
576 | |||
577 | switch (max_idx) | ||
578 | { | ||
579 | case 0: | ||
580 | printf("-DDES_DEFAULT_OPTIONS\n"); | ||
581 | break; | ||
582 | case 1: | ||
583 | printf("-DDES_UNROLL\n"); | ||
584 | break; | ||
585 | case 2: | ||
586 | printf("-DDES_RISC1\n"); | ||
587 | break; | ||
588 | case 3: | ||
589 | printf("-DDES_UNROLL -DDES_RISC1\n"); | ||
590 | break; | ||
591 | case 4: | ||
592 | printf("-DDES_RISC2\n"); | ||
593 | break; | ||
594 | case 5: | ||
595 | printf("-DDES_UNROLL -DDES_RISC2\n"); | ||
596 | break; | ||
597 | case 6: | ||
598 | printf("-DDES_PTR\n"); | ||
599 | break; | ||
600 | case 7: | ||
601 | printf("-DDES_UNROLL -DDES_PTR\n"); | ||
602 | break; | ||
603 | case 8: | ||
604 | printf("-DDES_RISC1 -DDES_PTR\n"); | ||
605 | break; | ||
606 | case 9: | ||
607 | printf("-DDES_UNROLL -DDES_RISC1 -DDES_PTR\n"); | ||
608 | break; | ||
609 | case 10: | ||
610 | printf("-DDES_RISC2 -DDES_PTR\n"); | ||
611 | break; | ||
612 | case 11: | ||
613 | printf("-DDES_UNROLL -DDES_RISC2 -DDES_PTR\n"); | ||
614 | break; | ||
615 | } | ||
616 | exit(0); | ||
617 | #if defined(LINT) || defined(MSDOS) | ||
618 | return(0); | ||
619 | #endif | ||
620 | } | ||
diff --git a/src/lib/libcrypto/des/des_ver.h b/src/lib/libcrypto/des/des_ver.h new file mode 100644 index 0000000000..7041a9271d --- /dev/null +++ b/src/lib/libcrypto/des/des_ver.h | |||
@@ -0,0 +1,60 @@ | |||
1 | /* crypto/des/des_ver.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 | extern char *DES_version; /* SSLeay version string */ | ||
60 | extern char *libdes_version; /* old libdes version string */ | ||
diff --git a/src/lib/libcrypto/des/dess.cpp b/src/lib/libcrypto/des/dess.cpp new file mode 100644 index 0000000000..7fb5987314 --- /dev/null +++ b/src/lib/libcrypto/des/dess.cpp | |||
@@ -0,0 +1,67 @@ | |||
1 | // | ||
2 | // gettsc.inl | ||
3 | // | ||
4 | // gives access to the Pentium's (secret) cycle counter | ||
5 | // | ||
6 | // This software was written by Leonard Janke (janke@unixg.ubc.ca) | ||
7 | // in 1996-7 and is entered, by him, into the public domain. | ||
8 | |||
9 | #if defined(__WATCOMC__) | ||
10 | void GetTSC(unsigned long&); | ||
11 | #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; | ||
12 | #elif defined(__GNUC__) | ||
13 | inline | ||
14 | void GetTSC(unsigned long& tsc) | ||
15 | { | ||
16 | asm volatile(".byte 15, 49\n\t" | ||
17 | : "=eax" (tsc) | ||
18 | : | ||
19 | : "%edx", "%eax"); | ||
20 | } | ||
21 | #elif defined(_MSC_VER) | ||
22 | inline | ||
23 | void GetTSC(unsigned long& tsc) | ||
24 | { | ||
25 | unsigned long a; | ||
26 | __asm _emit 0fh | ||
27 | __asm _emit 31h | ||
28 | __asm mov a, eax; | ||
29 | tsc=a; | ||
30 | } | ||
31 | #endif | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include <stdlib.h> | ||
35 | #include "des.h" | ||
36 | |||
37 | void main(int argc,char *argv[]) | ||
38 | { | ||
39 | des_key_schedule key; | ||
40 | unsigned long s1,s2,e1,e2; | ||
41 | unsigned long data[2]; | ||
42 | int i,j; | ||
43 | |||
44 | for (j=0; j<6; j++) | ||
45 | { | ||
46 | for (i=0; i<1000; i++) /**/ | ||
47 | { | ||
48 | des_encrypt(&data[0],key,1); | ||
49 | GetTSC(s1); | ||
50 | des_encrypt(&data[0],key,1); | ||
51 | des_encrypt(&data[0],key,1); | ||
52 | des_encrypt(&data[0],key,1); | ||
53 | GetTSC(e1); | ||
54 | GetTSC(s2); | ||
55 | des_encrypt(&data[0],key,1); | ||
56 | des_encrypt(&data[0],key,1); | ||
57 | des_encrypt(&data[0],key,1); | ||
58 | des_encrypt(&data[0],key,1); | ||
59 | GetTSC(e2); | ||
60 | des_encrypt(&data[0],key,1); | ||
61 | } | ||
62 | |||
63 | printf("des %d %d (%d)\n", | ||
64 | e1-s1,e2-s2,((e2-s2)-(e1-s1))); | ||
65 | } | ||
66 | } | ||
67 | |||
diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c new file mode 100644 index 0000000000..620c13ba6f --- /dev/null +++ b/src/lib/libcrypto/des/destest.c | |||
@@ -0,0 +1,882 @@ | |||
1 | /* crypto/des/destest.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 defined(WIN32) || defined(WIN16) || defined(WINDOWS) | ||
60 | #ifndef MSDOS | ||
61 | #define MSDOS | ||
62 | #endif | ||
63 | #endif | ||
64 | |||
65 | #include <stdio.h> | ||
66 | #include <stdlib.h> | ||
67 | #ifndef MSDOS | ||
68 | #include <unistd.h> | ||
69 | #else | ||
70 | #include <io.h> | ||
71 | #endif | ||
72 | #include <string.h> | ||
73 | #include "des.h" | ||
74 | |||
75 | /* tisk tisk - the test keys don't all have odd parity :-( */ | ||
76 | /* test data */ | ||
77 | #define NUM_TESTS 34 | ||
78 | static unsigned char key_data[NUM_TESTS][8]={ | ||
79 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
80 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
81 | {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
82 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
83 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
84 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
85 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
86 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}, | ||
87 | {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57}, | ||
88 | {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E}, | ||
89 | {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86}, | ||
90 | {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E}, | ||
91 | {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6}, | ||
92 | {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE}, | ||
93 | {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6}, | ||
94 | {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE}, | ||
95 | {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16}, | ||
96 | {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F}, | ||
97 | {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46}, | ||
98 | {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E}, | ||
99 | {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76}, | ||
100 | {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07}, | ||
101 | {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F}, | ||
102 | {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7}, | ||
103 | {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF}, | ||
104 | {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6}, | ||
105 | {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF}, | ||
106 | {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, | ||
107 | {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E}, | ||
108 | {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, | ||
109 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
110 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
111 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
112 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}}; | ||
113 | |||
114 | static unsigned char plain_data[NUM_TESTS][8]={ | ||
115 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
116 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
117 | {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, | ||
118 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
119 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
120 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
121 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
122 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
123 | {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42}, | ||
124 | {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA}, | ||
125 | {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72}, | ||
126 | {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A}, | ||
127 | {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2}, | ||
128 | {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A}, | ||
129 | {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2}, | ||
130 | {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A}, | ||
131 | {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02}, | ||
132 | {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A}, | ||
133 | {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32}, | ||
134 | {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA}, | ||
135 | {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62}, | ||
136 | {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2}, | ||
137 | {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA}, | ||
138 | {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92}, | ||
139 | {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A}, | ||
140 | {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2}, | ||
141 | {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A}, | ||
142 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
143 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
144 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
145 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
146 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
147 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
148 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}; | ||
149 | |||
150 | static unsigned char cipher_data[NUM_TESTS][8]={ | ||
151 | {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7}, | ||
152 | {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58}, | ||
153 | {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B}, | ||
154 | {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33}, | ||
155 | {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D}, | ||
156 | {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD}, | ||
157 | {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7}, | ||
158 | {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4}, | ||
159 | {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B}, | ||
160 | {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71}, | ||
161 | {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A}, | ||
162 | {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A}, | ||
163 | {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95}, | ||
164 | {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B}, | ||
165 | {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09}, | ||
166 | {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A}, | ||
167 | {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F}, | ||
168 | {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88}, | ||
169 | {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77}, | ||
170 | {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A}, | ||
171 | {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56}, | ||
172 | {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56}, | ||
173 | {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56}, | ||
174 | {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC}, | ||
175 | {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A}, | ||
176 | {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41}, | ||
177 | {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93}, | ||
178 | {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00}, | ||
179 | {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06}, | ||
180 | {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7}, | ||
181 | {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51}, | ||
182 | {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE}, | ||
183 | {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D}, | ||
184 | {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}}; | ||
185 | |||
186 | static unsigned char cipher_ecb2[NUM_TESTS-1][8]={ | ||
187 | {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E}, | ||
188 | {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16}, | ||
189 | {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27}, | ||
190 | {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6}, | ||
191 | {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25}, | ||
192 | {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A}, | ||
193 | {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74}, | ||
194 | {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6}, | ||
195 | {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67}, | ||
196 | {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10}, | ||
197 | {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85}, | ||
198 | {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA}, | ||
199 | {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3}, | ||
200 | {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3}, | ||
201 | {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A}, | ||
202 | {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69}, | ||
203 | {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1}, | ||
204 | {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7}, | ||
205 | {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F}, | ||
206 | {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87}, | ||
207 | {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A}, | ||
208 | {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE}, | ||
209 | {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3}, | ||
210 | {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD}, | ||
211 | {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84}, | ||
212 | {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85}, | ||
213 | {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC}, | ||
214 | {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89}, | ||
215 | {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E}, | ||
216 | {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89}, | ||
217 | {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7}, | ||
218 | {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8}, | ||
219 | {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; | ||
220 | |||
221 | static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; | ||
222 | static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; | ||
223 | static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; | ||
224 | static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; | ||
225 | /* Changed the following text constant to binary so it will work on ebcdic | ||
226 | * machines :-) */ | ||
227 | /* static char cbc_data[40]="7654321 Now is the time for \0001"; */ | ||
228 | static char cbc_data[40]={ | ||
229 | 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20, | ||
230 | 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74, | ||
231 | 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20, | ||
232 | 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00, | ||
233 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
234 | }; | ||
235 | |||
236 | static unsigned char cbc_ok[32]={ | ||
237 | 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4, | ||
238 | 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb, | ||
239 | 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68, | ||
240 | 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; | ||
241 | |||
242 | static unsigned char xcbc_ok[32]={ | ||
243 | 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48, | ||
244 | 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD, | ||
245 | 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76, | ||
246 | 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2, | ||
247 | }; | ||
248 | |||
249 | static unsigned char cbc3_ok[32]={ | ||
250 | 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0, | ||
251 | 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC, | ||
252 | 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4, | ||
253 | 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75}; | ||
254 | |||
255 | static unsigned char pcbc_ok[32]={ | ||
256 | 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4, | ||
257 | 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15, | ||
258 | 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f, | ||
259 | 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88}; | ||
260 | |||
261 | static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; | ||
262 | static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}; | ||
263 | static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; | ||
264 | static unsigned char plain[24]= | ||
265 | { | ||
266 | 0x4e,0x6f,0x77,0x20,0x69,0x73, | ||
267 | 0x20,0x74,0x68,0x65,0x20,0x74, | ||
268 | 0x69,0x6d,0x65,0x20,0x66,0x6f, | ||
269 | 0x72,0x20,0x61,0x6c,0x6c,0x20 | ||
270 | }; | ||
271 | static unsigned char cfb_cipher8[24]= { | ||
272 | 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8, | ||
273 | 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 }; | ||
274 | static unsigned char cfb_cipher16[24]={ | ||
275 | 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70, | ||
276 | 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B }; | ||
277 | static unsigned char cfb_cipher32[24]={ | ||
278 | 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD, | ||
279 | 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 }; | ||
280 | static unsigned char cfb_cipher48[24]={ | ||
281 | 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85, | ||
282 | 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F }; | ||
283 | static unsigned char cfb_cipher64[24]={ | ||
284 | 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B, | ||
285 | 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 }; | ||
286 | |||
287 | static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; | ||
288 | static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}; | ||
289 | static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8]; | ||
290 | static unsigned char ofb_cipher[24]= | ||
291 | { | ||
292 | 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51, | ||
293 | 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f, | ||
294 | 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3 | ||
295 | }; | ||
296 | |||
297 | DES_LONG cbc_cksum_ret=0xB462FEF7L; | ||
298 | unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; | ||
299 | |||
300 | #ifndef NOPROTO | ||
301 | static char *pt(unsigned char *p); | ||
302 | static int cfb_test(int bits, unsigned char *cfb_cipher); | ||
303 | static int cfb64_test(unsigned char *cfb_cipher); | ||
304 | static int ede_cfb64_test(unsigned char *cfb_cipher); | ||
305 | #else | ||
306 | static char *pt(); | ||
307 | static int cfb_test(); | ||
308 | static int cfb64_test(); | ||
309 | static int ede_cfb64_test(); | ||
310 | #endif | ||
311 | |||
312 | int main(argc,argv) | ||
313 | int argc; | ||
314 | char *argv[]; | ||
315 | { | ||
316 | int i,j,err=0; | ||
317 | des_cblock in,out,outin,iv3; | ||
318 | des_key_schedule ks,ks2,ks3; | ||
319 | unsigned char cbc_in[40]; | ||
320 | unsigned char cbc_out[40]; | ||
321 | DES_LONG cs; | ||
322 | unsigned char qret[4][4],cret[8]; | ||
323 | DES_LONG lqret[4]; | ||
324 | int num; | ||
325 | char *str; | ||
326 | |||
327 | printf("Doing ecb\n"); | ||
328 | for (i=0; i<NUM_TESTS; i++) | ||
329 | { | ||
330 | if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0) | ||
331 | { | ||
332 | printf("Key error %2d:%d\n",i+1,j); | ||
333 | err=1; | ||
334 | } | ||
335 | memcpy(in,plain_data[i],8); | ||
336 | memset(out,0,8); | ||
337 | memset(outin,0,8); | ||
338 | des_ecb_encrypt((C_Block *)in,(C_Block *)out,ks,DES_ENCRYPT); | ||
339 | des_ecb_encrypt((C_Block *)out,(C_Block *)outin,ks,DES_DECRYPT); | ||
340 | |||
341 | if (memcmp(out,cipher_data[i],8) != 0) | ||
342 | { | ||
343 | printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n", | ||
344 | i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]), | ||
345 | pt(out)); | ||
346 | err=1; | ||
347 | } | ||
348 | if (memcmp(in,outin,8) != 0) | ||
349 | { | ||
350 | printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n", | ||
351 | i+1,pt(key_data[i]),pt(out),pt(in),pt(outin)); | ||
352 | err=1; | ||
353 | } | ||
354 | } | ||
355 | |||
356 | #ifndef LIBDES_LIT | ||
357 | printf("Doing ede ecb\n"); | ||
358 | for (i=0; i<(NUM_TESTS-1); i++) | ||
359 | { | ||
360 | if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0) | ||
361 | { | ||
362 | err=1; | ||
363 | printf("Key error %2d:%d\n",i+1,j); | ||
364 | } | ||
365 | if ((j=des_key_sched((C_Block *)(key_data[i+1]),ks2)) != 0) | ||
366 | { | ||
367 | printf("Key error %2d:%d\n",i+2,j); | ||
368 | err=1; | ||
369 | } | ||
370 | if ((j=des_key_sched((C_Block *)(key_data[i+2]),ks3)) != 0) | ||
371 | { | ||
372 | printf("Key error %2d:%d\n",i+3,j); | ||
373 | err=1; | ||
374 | } | ||
375 | memcpy(in,plain_data[i],8); | ||
376 | memset(out,0,8); | ||
377 | memset(outin,0,8); | ||
378 | des_ecb2_encrypt((C_Block *)in,(C_Block *)out,ks,ks2, | ||
379 | DES_ENCRYPT); | ||
380 | des_ecb2_encrypt((C_Block *)out,(C_Block *)outin,ks,ks2, | ||
381 | DES_DECRYPT); | ||
382 | |||
383 | if (memcmp(out,cipher_ecb2[i],8) != 0) | ||
384 | { | ||
385 | printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n", | ||
386 | i+1,pt(key_data[i]),pt(in),pt(cipher_ecb2[i]), | ||
387 | pt(out)); | ||
388 | err=1; | ||
389 | } | ||
390 | if (memcmp(in,outin,8) != 0) | ||
391 | { | ||
392 | printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n", | ||
393 | i+1,pt(key_data[i]),pt(out),pt(in),pt(outin)); | ||
394 | err=1; | ||
395 | } | ||
396 | } | ||
397 | #endif | ||
398 | |||
399 | printf("Doing cbc\n"); | ||
400 | if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) | ||
401 | { | ||
402 | printf("Key error %d\n",j); | ||
403 | err=1; | ||
404 | } | ||
405 | memset(cbc_out,0,40); | ||
406 | memset(cbc_in,0,40); | ||
407 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
408 | des_ncbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, | ||
409 | (long)strlen((char *)cbc_data)+1,ks, | ||
410 | (C_Block *)iv3,DES_ENCRYPT); | ||
411 | if (memcmp(cbc_out,cbc_ok,32) != 0) | ||
412 | printf("cbc_encrypt encrypt error\n"); | ||
413 | |||
414 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
415 | des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, | ||
416 | (long)strlen((char *)cbc_data)+1,ks, | ||
417 | (C_Block *)iv3,DES_DECRYPT); | ||
418 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0) | ||
419 | { | ||
420 | printf("cbc_encrypt decrypt error\n"); | ||
421 | err=1; | ||
422 | } | ||
423 | |||
424 | #ifndef LIBDES_LIT | ||
425 | printf("Doing desx cbc\n"); | ||
426 | if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) | ||
427 | { | ||
428 | printf("Key error %d\n",j); | ||
429 | err=1; | ||
430 | } | ||
431 | memset(cbc_out,0,40); | ||
432 | memset(cbc_in,0,40); | ||
433 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
434 | des_xcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, | ||
435 | (long)strlen((char *)cbc_data)+1,ks, | ||
436 | (C_Block *)iv3, | ||
437 | (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_ENCRYPT); | ||
438 | if (memcmp(cbc_out,xcbc_ok,32) != 0) | ||
439 | { | ||
440 | printf("des_xcbc_encrypt encrypt error\n"); | ||
441 | } | ||
442 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
443 | des_xcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, | ||
444 | (long)strlen((char *)cbc_data)+1,ks, | ||
445 | (C_Block *)iv3, | ||
446 | (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_DECRYPT); | ||
447 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) | ||
448 | { | ||
449 | printf("des_xcbc_encrypt decrypt error\n"); | ||
450 | err=1; | ||
451 | } | ||
452 | #endif | ||
453 | |||
454 | printf("Doing ede cbc\n"); | ||
455 | if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) | ||
456 | { | ||
457 | printf("Key error %d\n",j); | ||
458 | err=1; | ||
459 | } | ||
460 | if ((j=des_key_sched((C_Block *)cbc2_key,ks2)) != 0) | ||
461 | { | ||
462 | printf("Key error %d\n",j); | ||
463 | err=1; | ||
464 | } | ||
465 | if ((j=des_key_sched((C_Block *)cbc3_key,ks3)) != 0) | ||
466 | { | ||
467 | printf("Key error %d\n",j); | ||
468 | err=1; | ||
469 | } | ||
470 | memset(cbc_out,0,40); | ||
471 | memset(cbc_in,0,40); | ||
472 | i=strlen((char *)cbc_data)+1; | ||
473 | /* i=((i+7)/8)*8; */ | ||
474 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
475 | |||
476 | des_ede3_cbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, | ||
477 | 16L,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT); | ||
478 | des_ede3_cbc_encrypt((C_Block *)&(cbc_data[16]), | ||
479 | (C_Block *)&(cbc_out[16]), | ||
480 | (long)i-16,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT); | ||
481 | if (memcmp(cbc_out,cbc3_ok, | ||
482 | (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) | ||
483 | { | ||
484 | printf("des_ede3_cbc_encrypt encrypt error\n"); | ||
485 | err=1; | ||
486 | } | ||
487 | |||
488 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
489 | des_ede3_cbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, | ||
490 | (long)i,ks,ks2,ks3,(C_Block *)iv3,DES_DECRYPT); | ||
491 | if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0) | ||
492 | { | ||
493 | printf("des_ede3_cbc_encrypt decrypt error\n"); | ||
494 | err=1; | ||
495 | } | ||
496 | |||
497 | #ifndef LIBDES_LIT | ||
498 | printf("Doing pcbc\n"); | ||
499 | if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) | ||
500 | { | ||
501 | printf("Key error %d\n",j); | ||
502 | err=1; | ||
503 | } | ||
504 | memset(cbc_out,0,40); | ||
505 | memset(cbc_in,0,40); | ||
506 | des_pcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, | ||
507 | (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_ENCRYPT); | ||
508 | if (memcmp(cbc_out,pcbc_ok,32) != 0) | ||
509 | { | ||
510 | printf("pcbc_encrypt encrypt error\n"); | ||
511 | err=1; | ||
512 | } | ||
513 | des_pcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, | ||
514 | (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_DECRYPT); | ||
515 | if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0) | ||
516 | { | ||
517 | printf("pcbc_encrypt decrypt error\n"); | ||
518 | err=1; | ||
519 | } | ||
520 | |||
521 | printf("Doing "); | ||
522 | printf("cfb8 "); | ||
523 | err+=cfb_test(8,cfb_cipher8); | ||
524 | printf("cfb16 "); | ||
525 | err+=cfb_test(16,cfb_cipher16); | ||
526 | printf("cfb32 "); | ||
527 | err+=cfb_test(32,cfb_cipher32); | ||
528 | printf("cfb48 "); | ||
529 | err+=cfb_test(48,cfb_cipher48); | ||
530 | printf("cfb64 "); | ||
531 | err+=cfb_test(64,cfb_cipher64); | ||
532 | |||
533 | printf("cfb64() "); | ||
534 | err+=cfb64_test(cfb_cipher64); | ||
535 | |||
536 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
537 | for (i=0; i<sizeof(plain); i++) | ||
538 | des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]), | ||
539 | 8,(long)1,ks,(C_Block *)cfb_tmp,DES_ENCRYPT); | ||
540 | if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0) | ||
541 | { | ||
542 | printf("cfb_encrypt small encrypt error\n"); | ||
543 | err=1; | ||
544 | } | ||
545 | |||
546 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
547 | for (i=0; i<sizeof(plain); i++) | ||
548 | des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]), | ||
549 | 8,(long)1,ks,(C_Block *)cfb_tmp,DES_DECRYPT); | ||
550 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | ||
551 | { | ||
552 | printf("cfb_encrypt small decrypt error\n"); | ||
553 | err=1; | ||
554 | } | ||
555 | |||
556 | printf("ede_cfb64() "); | ||
557 | err+=ede_cfb64_test(cfb_cipher64); | ||
558 | |||
559 | printf("done\n"); | ||
560 | |||
561 | printf("Doing ofb\n"); | ||
562 | des_key_sched((C_Block *)ofb_key,ks); | ||
563 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
564 | des_ofb_encrypt(plain,ofb_buf1,64,(long)sizeof(plain)/8,ks, | ||
565 | (C_Block *)ofb_tmp); | ||
566 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) | ||
567 | { | ||
568 | printf("ofb_encrypt encrypt error\n"); | ||
569 | printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", | ||
570 | ofb_buf1[8+0], ofb_buf1[8+1], ofb_buf1[8+2], ofb_buf1[8+3], | ||
571 | ofb_buf1[8+4], ofb_buf1[8+5], ofb_buf1[8+6], ofb_buf1[8+7]); | ||
572 | printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", | ||
573 | ofb_buf1[8+0], ofb_cipher[8+1], ofb_cipher[8+2], ofb_cipher[8+3], | ||
574 | ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]); | ||
575 | err=1; | ||
576 | } | ||
577 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
578 | des_ofb_encrypt(ofb_buf1,ofb_buf2,64,(long)sizeof(ofb_buf1)/8,ks, | ||
579 | (C_Block *)ofb_tmp); | ||
580 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) | ||
581 | { | ||
582 | printf("ofb_encrypt decrypt error\n"); | ||
583 | printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", | ||
584 | ofb_buf2[8+0], ofb_buf2[8+1], ofb_buf2[8+2], ofb_buf2[8+3], | ||
585 | ofb_buf2[8+4], ofb_buf2[8+5], ofb_buf2[8+6], ofb_buf2[8+7]); | ||
586 | printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", | ||
587 | plain[8+0], plain[8+1], plain[8+2], plain[8+3], | ||
588 | plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | ||
589 | err=1; | ||
590 | } | ||
591 | |||
592 | printf("Doing ofb64\n"); | ||
593 | des_key_sched((C_Block *)ofb_key,ks); | ||
594 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
595 | memset(ofb_buf1,0,sizeof(ofb_buf1)); | ||
596 | memset(ofb_buf2,0,sizeof(ofb_buf1)); | ||
597 | num=0; | ||
598 | for (i=0; i<sizeof(plain); i++) | ||
599 | { | ||
600 | des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks, | ||
601 | (C_Block *)ofb_tmp,&num); | ||
602 | } | ||
603 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) | ||
604 | { | ||
605 | printf("ofb64_encrypt encrypt error\n"); | ||
606 | err=1; | ||
607 | } | ||
608 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
609 | num=0; | ||
610 | des_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks, | ||
611 | (C_Block *)ofb_tmp,&num); | ||
612 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) | ||
613 | { | ||
614 | printf("ofb64_encrypt decrypt error\n"); | ||
615 | err=1; | ||
616 | } | ||
617 | |||
618 | printf("Doing ede_ofb64\n"); | ||
619 | des_key_sched((C_Block *)ofb_key,ks); | ||
620 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
621 | memset(ofb_buf1,0,sizeof(ofb_buf1)); | ||
622 | memset(ofb_buf2,0,sizeof(ofb_buf1)); | ||
623 | num=0; | ||
624 | for (i=0; i<sizeof(plain); i++) | ||
625 | { | ||
626 | des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,ks, | ||
627 | (C_Block *)ofb_tmp,&num); | ||
628 | } | ||
629 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) | ||
630 | { | ||
631 | printf("ede_ofb64_encrypt encrypt error\n"); | ||
632 | err=1; | ||
633 | } | ||
634 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
635 | num=0; | ||
636 | des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks, | ||
637 | ks,ks,(C_Block *)ofb_tmp,&num); | ||
638 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) | ||
639 | { | ||
640 | printf("ede_ofb64_encrypt decrypt error\n"); | ||
641 | err=1; | ||
642 | } | ||
643 | |||
644 | printf("Doing cbc_cksum\n"); | ||
645 | des_key_sched((C_Block *)cbc_key,ks); | ||
646 | cs=des_cbc_cksum((C_Block *)cbc_data,(C_Block *)cret, | ||
647 | (long)strlen(cbc_data),ks,(C_Block *)cbc_iv); | ||
648 | if (cs != cbc_cksum_ret) | ||
649 | { | ||
650 | printf("bad return value (%08lX), should be %08lX\n", | ||
651 | (unsigned long)cs,(unsigned long)cbc_cksum_ret); | ||
652 | err=1; | ||
653 | } | ||
654 | if (memcmp(cret,cbc_cksum_data,8) != 0) | ||
655 | { | ||
656 | printf("bad cbc_cksum block returned\n"); | ||
657 | err=1; | ||
658 | } | ||
659 | |||
660 | printf("Doing quad_cksum\n"); | ||
661 | cs=quad_cksum((C_Block *)cbc_data,(C_Block *)qret, | ||
662 | (long)strlen(cbc_data),2,(C_Block *)cbc_iv); | ||
663 | j=sizeof(lqret[0])-4; | ||
664 | for (i=0; i<4; i++) | ||
665 | { | ||
666 | lqret[i]=0; | ||
667 | memcpy(&(lqret[i]),&(qret[i][0]),4); | ||
668 | if (j > 0) lqret[i]=lqret[i]>>(j*8); /* For Cray */ | ||
669 | } | ||
670 | { /* Big-endian fix */ | ||
671 | static DES_LONG l=1; | ||
672 | static unsigned char *c=(unsigned char *)&l; | ||
673 | DES_LONG ll; | ||
674 | |||
675 | if (!c[0]) | ||
676 | { | ||
677 | ll=lqret[0]^lqret[3]; | ||
678 | lqret[0]^=ll; | ||
679 | lqret[3]^=ll; | ||
680 | ll=lqret[1]^lqret[2]; | ||
681 | lqret[1]^=ll; | ||
682 | lqret[2]^=ll; | ||
683 | } | ||
684 | } | ||
685 | if (cs != 0x70d7a63aL) | ||
686 | { | ||
687 | printf("quad_cksum error, ret %08lx should be 70d7a63a\n", | ||
688 | (unsigned long)cs); | ||
689 | err=1; | ||
690 | } | ||
691 | if (lqret[0] != 0x327eba8dL) | ||
692 | { | ||
693 | printf("quad_cksum error, out[0] %08lx is not %08lx\n", | ||
694 | (unsigned long)lqret[0],0x327eba8dL); | ||
695 | err=1; | ||
696 | } | ||
697 | if (lqret[1] != 0x201a49ccL) | ||
698 | { | ||
699 | printf("quad_cksum error, out[1] %08lx is not %08lx\n", | ||
700 | (unsigned long)lqret[1],0x201a49ccL); | ||
701 | err=1; | ||
702 | } | ||
703 | if (lqret[2] != 0x70d7a63aL) | ||
704 | { | ||
705 | printf("quad_cksum error, out[2] %08lx is not %08lx\n", | ||
706 | (unsigned long)lqret[2],0x70d7a63aL); | ||
707 | err=1; | ||
708 | } | ||
709 | if (lqret[3] != 0x501c2c26L) | ||
710 | { | ||
711 | printf("quad_cksum error, out[3] %08lx is not %08lx\n", | ||
712 | (unsigned long)lqret[3],0x501c2c26L); | ||
713 | err=1; | ||
714 | } | ||
715 | #endif | ||
716 | |||
717 | printf("input word alignment test"); | ||
718 | for (i=0; i<4; i++) | ||
719 | { | ||
720 | printf(" %d",i); | ||
721 | des_ncbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in, | ||
722 | (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, | ||
723 | DES_ENCRYPT); | ||
724 | } | ||
725 | printf("\noutput word alignment test"); | ||
726 | for (i=0; i<4; i++) | ||
727 | { | ||
728 | printf(" %d",i); | ||
729 | des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]), | ||
730 | (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, | ||
731 | DES_ENCRYPT); | ||
732 | } | ||
733 | printf("\n"); | ||
734 | printf("fast crypt test "); | ||
735 | str=crypt("testing","ef"); | ||
736 | if (strcmp("efGnQx2725bI2",str) != 0) | ||
737 | { | ||
738 | printf("fast crypt error, %s should be efGnQx2725bI2\n",str); | ||
739 | err=1; | ||
740 | } | ||
741 | str=crypt("bca76;23","yA"); | ||
742 | if (strcmp("yA1Rp/1hZXIJk",str) != 0) | ||
743 | { | ||
744 | printf("fast crypt error, %s should be yA1Rp/1hZXIJk\n",str); | ||
745 | err=1; | ||
746 | } | ||
747 | printf("\n"); | ||
748 | exit(err); | ||
749 | return(0); | ||
750 | } | ||
751 | |||
752 | static char *pt(p) | ||
753 | unsigned char *p; | ||
754 | { | ||
755 | static char bufs[10][20]; | ||
756 | static int bnum=0; | ||
757 | char *ret; | ||
758 | int i; | ||
759 | static char *f="0123456789ABCDEF"; | ||
760 | |||
761 | ret= &(bufs[bnum++][0]); | ||
762 | bnum%=10; | ||
763 | for (i=0; i<8; i++) | ||
764 | { | ||
765 | ret[i*2]=f[(p[i]>>4)&0xf]; | ||
766 | ret[i*2+1]=f[p[i]&0xf]; | ||
767 | } | ||
768 | ret[16]='\0'; | ||
769 | return(ret); | ||
770 | } | ||
771 | |||
772 | #ifndef LIBDES_LIT | ||
773 | |||
774 | static int cfb_test(bits, cfb_cipher) | ||
775 | int bits; | ||
776 | unsigned char *cfb_cipher; | ||
777 | { | ||
778 | des_key_schedule ks; | ||
779 | int i,err=0; | ||
780 | |||
781 | des_key_sched((C_Block *)cfb_key,ks); | ||
782 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
783 | des_cfb_encrypt(plain,cfb_buf1,bits,(long)sizeof(plain),ks, | ||
784 | (C_Block *)cfb_tmp,DES_ENCRYPT); | ||
785 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) | ||
786 | { | ||
787 | err=1; | ||
788 | printf("cfb_encrypt encrypt error\n"); | ||
789 | for (i=0; i<24; i+=8) | ||
790 | printf("%s\n",pt(&(cfb_buf1[i]))); | ||
791 | } | ||
792 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
793 | des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,(long)sizeof(plain),ks, | ||
794 | (C_Block *)cfb_tmp,DES_DECRYPT); | ||
795 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | ||
796 | { | ||
797 | err=1; | ||
798 | printf("cfb_encrypt decrypt error\n"); | ||
799 | for (i=0; i<24; i+=8) | ||
800 | printf("%s\n",pt(&(cfb_buf1[i]))); | ||
801 | } | ||
802 | return(err); | ||
803 | } | ||
804 | |||
805 | static int cfb64_test(cfb_cipher) | ||
806 | unsigned char *cfb_cipher; | ||
807 | { | ||
808 | des_key_schedule ks; | ||
809 | int err=0,i,n; | ||
810 | |||
811 | des_key_sched((C_Block *)cfb_key,ks); | ||
812 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
813 | n=0; | ||
814 | des_cfb64_encrypt(plain,cfb_buf1,(long)12,ks, | ||
815 | (C_Block *)cfb_tmp,&n,DES_ENCRYPT); | ||
816 | des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), | ||
817 | (long)sizeof(plain)-12,ks, | ||
818 | (C_Block *)cfb_tmp,&n,DES_ENCRYPT); | ||
819 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) | ||
820 | { | ||
821 | err=1; | ||
822 | printf("cfb_encrypt encrypt error\n"); | ||
823 | for (i=0; i<24; i+=8) | ||
824 | printf("%s\n",pt(&(cfb_buf1[i]))); | ||
825 | } | ||
826 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
827 | n=0; | ||
828 | des_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks, | ||
829 | (C_Block *)cfb_tmp,&n,DES_DECRYPT); | ||
830 | des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), | ||
831 | (long)sizeof(plain)-17,ks, | ||
832 | (C_Block *)cfb_tmp,&n,DES_DECRYPT); | ||
833 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | ||
834 | { | ||
835 | err=1; | ||
836 | printf("cfb_encrypt decrypt error\n"); | ||
837 | for (i=0; i<24; i+=8) | ||
838 | printf("%s\n",pt(&(cfb_buf2[i]))); | ||
839 | } | ||
840 | return(err); | ||
841 | } | ||
842 | |||
843 | static int ede_cfb64_test(cfb_cipher) | ||
844 | unsigned char *cfb_cipher; | ||
845 | { | ||
846 | des_key_schedule ks; | ||
847 | int err=0,i,n; | ||
848 | |||
849 | des_key_sched((C_Block *)cfb_key,ks); | ||
850 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
851 | n=0; | ||
852 | des_ede3_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,ks,ks, | ||
853 | (C_Block *)cfb_tmp,&n,DES_ENCRYPT); | ||
854 | des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), | ||
855 | (long)sizeof(plain)-12,ks,ks,ks, | ||
856 | (C_Block *)cfb_tmp,&n,DES_ENCRYPT); | ||
857 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) | ||
858 | { | ||
859 | err=1; | ||
860 | printf("ede_cfb_encrypt encrypt error\n"); | ||
861 | for (i=0; i<24; i+=8) | ||
862 | printf("%s\n",pt(&(cfb_buf1[i]))); | ||
863 | } | ||
864 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
865 | n=0; | ||
866 | des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks, | ||
867 | (C_Block *)cfb_tmp,&n,DES_DECRYPT); | ||
868 | des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), | ||
869 | (long)sizeof(plain)-17,ks,ks,ks, | ||
870 | (C_Block *)cfb_tmp,&n,DES_DECRYPT); | ||
871 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | ||
872 | { | ||
873 | err=1; | ||
874 | printf("ede_cfb_encrypt decrypt error\n"); | ||
875 | for (i=0; i<24; i+=8) | ||
876 | printf("%s\n",pt(&(cfb_buf2[i]))); | ||
877 | } | ||
878 | return(err); | ||
879 | } | ||
880 | |||
881 | #endif | ||
882 | |||
diff --git a/src/lib/libcrypto/des/makefile.bc b/src/lib/libcrypto/des/makefile.bc new file mode 100644 index 0000000000..1fe6d4915a --- /dev/null +++ b/src/lib/libcrypto/des/makefile.bc | |||
@@ -0,0 +1,50 @@ | |||
1 | # | ||
2 | # Origional BC Makefile from Teun <Teun.Nijssen@kub.nl> | ||
3 | # | ||
4 | # | ||
5 | CC = bcc | ||
6 | TLIB = tlib /0 /C | ||
7 | # note: the -3 flag produces code for 386, 486, Pentium etc; omit it for 286s | ||
8 | OPTIMIZE= -3 -O2 | ||
9 | #WINDOWS= -W | ||
10 | CFLAGS = -c -ml -d $(OPTIMIZE) $(WINDOWS) -DMSDOS | ||
11 | LFLAGS = -ml $(WINDOWS) | ||
12 | |||
13 | .c.obj: | ||
14 | $(CC) $(CFLAGS) $*.c | ||
15 | |||
16 | .obj.exe: | ||
17 | $(CC) $(LFLAGS) -e$*.exe $*.obj libdes.lib | ||
18 | |||
19 | all: $(LIB) destest.exe rpw.exe des.exe speed.exe | ||
20 | |||
21 | # "make clean": use a directory containing only libdes .exe and .obj files... | ||
22 | clean: | ||
23 | del *.exe | ||
24 | del *.obj | ||
25 | del libdes.lib | ||
26 | del libdes.rsp | ||
27 | |||
28 | OBJS= cbc_cksm.obj cbc_enc.obj ecb_enc.obj pcbc_enc.obj \ | ||
29 | qud_cksm.obj rand_key.obj set_key.obj str2key.obj \ | ||
30 | enc_read.obj enc_writ.obj fcrypt.obj cfb_enc.obj \ | ||
31 | ecb3_enc.obj ofb_enc.obj cbc3_enc.obj read_pwd.obj\ | ||
32 | cfb64enc.obj ofb64enc.obj ede_enc.obj cfb64ede.obj\ | ||
33 | ofb64ede.obj supp.obj | ||
34 | |||
35 | LIB= libdes.lib | ||
36 | |||
37 | $(LIB): $(OBJS) | ||
38 | del $(LIB) | ||
39 | makersp "+%s &\n" &&| | ||
40 | $(OBJS) | ||
41 | | >libdes.rsp | ||
42 | $(TLIB) libdes.lib @libdes.rsp,nul | ||
43 | del libdes.rsp | ||
44 | |||
45 | destest.exe: destest.obj libdes.lib | ||
46 | rpw.exe: rpw.obj libdes.lib | ||
47 | speed.exe: speed.obj libdes.lib | ||
48 | des.exe: des.obj libdes.lib | ||
49 | |||
50 | |||
diff --git a/src/lib/libcrypto/des/options.txt b/src/lib/libcrypto/des/options.txt new file mode 100644 index 0000000000..6e2b50f765 --- /dev/null +++ b/src/lib/libcrypto/des/options.txt | |||
@@ -0,0 +1,39 @@ | |||
1 | Note that the UNROLL option makes the 'inner' des loop unroll all 16 rounds | ||
2 | instead of the default 4. | ||
3 | RISC1 and RISC2 are 2 alternatives for the inner loop and | ||
4 | PTR means to use pointers arithmatic instead of arrays. | ||
5 | |||
6 | FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - assembler 577,000 4620k/s | ||
7 | IRIX 6.2 - R10000 195mhz - cc (-O3 -n32) - UNROLL RISC2 PTR 496,000 3968k/s | ||
8 | solaris 2.5.1 usparc 167mhz?? - SC4.0 - UNROLL RISC1 PTR [1] 459,400 3672k/s | ||
9 | FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - UNROLL RISC1 433,000 3468k/s | ||
10 | solaris 2.5.1 usparc 167mhz?? - gcc 2.7.2 - UNROLL 380,000 3041k/s | ||
11 | linux - pentium 100mhz - gcc 2.7.0 - assembler 281,000 2250k/s | ||
12 | NT 4.0 - pentium 100mhz - VC 4.2 - assembler 281,000 2250k/s | ||
13 | AIX 4.1? - PPC604 100mhz - cc - UNROLL 275,000 2200k/s | ||
14 | IRIX 5.3 - R4400 200mhz - gcc 2.6.3 - UNROLL RISC2 PTR 235,300 1882k/s | ||
15 | IRIX 5.3 - R4400 200mhz - cc - UNROLL RISC2 PTR 233,700 1869k/s | ||
16 | NT 4.0 - pentium 100mhz - VC 4.2 - UNROLL RISC1 PTR 191,000 1528k/s | ||
17 | DEC Alpha 165mhz?? - cc - RISC2 PTR [2] 181,000 1448k/s | ||
18 | linux - pentium 100mhz - gcc 2.7.0 - UNROLL RISC1 PTR 158,500 1268k/s | ||
19 | HPUX 10 - 9000/887 - cc - UNROLL [3] 148,000 1190k/s | ||
20 | solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2 - UNROLL 123,600 989k/s | ||
21 | IRIX 5.3 - R4000 100mhz - cc - UNROLL RISC2 PTR 101,000 808k/s | ||
22 | DGUX - 88100 50mhz(?) - gcc 2.6.3 - UNROLL 81,000 648k/s | ||
23 | solaris 2.4 486 50mhz - gcc 2.6.3 - assembler 65,000 522k/s | ||
24 | HPUX 10 - 9000/887 - k&r cc (default compiler) - UNROLL PTR 76,000 608k/s | ||
25 | solaris 2.4 486 50mhz - gcc 2.6.3 - UNROLL RISC2 43,500 344k/s | ||
26 | AIX - old slow one :-) - cc - 39,000 312k/s | ||
27 | |||
28 | Notes. | ||
29 | [1] For the ultra sparc, SunC 4.0 | ||
30 | cc -xtarget=ultra -xarch=v8plus -Xa -xO5, running 'des_opts' | ||
31 | gives a speed of 344,000 des/s while 'speed' gives 459,000 des/s. | ||
32 | I'll record the higher since it is coming from the library but it | ||
33 | is all rather weird. | ||
34 | [2] Similar to the ultra sparc ([1]), 181,000 for 'des_opts' vs 175,000. | ||
35 | [3] I was unable to get access to this machine when it was not heavily loaded. | ||
36 | As such, my timing program was never able to get more that %30 of the CPU. | ||
37 | This would cause the program to give much lower speed numbers because | ||
38 | it would be 'fighting' to stay in the cache with the other CPU burning | ||
39 | processes. | ||
diff --git a/src/lib/libcrypto/des/read2pwd.c b/src/lib/libcrypto/des/read2pwd.c new file mode 100644 index 0000000000..a0d53793e4 --- /dev/null +++ b/src/lib/libcrypto/des/read2pwd.c | |||
@@ -0,0 +1,90 @@ | |||
1 | /* crypto/des/read2pwd.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 "des_locl.h" | ||
60 | |||
61 | int des_read_password(key, prompt, verify) | ||
62 | des_cblock (*key); | ||
63 | char *prompt; | ||
64 | int verify; | ||
65 | { | ||
66 | int ok; | ||
67 | char buf[BUFSIZ],buff[BUFSIZ]; | ||
68 | |||
69 | if ((ok=des_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0) | ||
70 | des_string_to_key(buf,key); | ||
71 | memset(buf,0,BUFSIZ); | ||
72 | memset(buff,0,BUFSIZ); | ||
73 | return(ok); | ||
74 | } | ||
75 | |||
76 | int des_read_2passwords(key1, key2, prompt, verify) | ||
77 | des_cblock (*key1); | ||
78 | des_cblock (*key2); | ||
79 | char *prompt; | ||
80 | int verify; | ||
81 | { | ||
82 | int ok; | ||
83 | char buf[BUFSIZ],buff[BUFSIZ]; | ||
84 | |||
85 | if ((ok=des_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0) | ||
86 | des_string_to_2keys(buf,key1,key2); | ||
87 | memset(buf,0,BUFSIZ); | ||
88 | memset(buff,0,BUFSIZ); | ||
89 | return(ok); | ||
90 | } | ||
diff --git a/src/lib/libcrypto/des/read_pwd.c b/src/lib/libcrypto/des/read_pwd.c new file mode 100644 index 0000000000..99920f2f86 --- /dev/null +++ b/src/lib/libcrypto/des/read_pwd.c | |||
@@ -0,0 +1,459 @@ | |||
1 | /* crypto/des/read_pwd.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 | /* #define SIGACTION */ /* Define this if you have sigaction() */ | ||
60 | #ifdef WIN16TTY | ||
61 | #undef WIN16 | ||
62 | #undef _WINDOWS | ||
63 | #include <graph.h> | ||
64 | #endif | ||
65 | |||
66 | /* 06-Apr-92 Luke Brennan Support for VMS */ | ||
67 | #include "des_locl.h" | ||
68 | #include <signal.h> | ||
69 | #include <string.h> | ||
70 | #include <setjmp.h> | ||
71 | #include <errno.h> | ||
72 | |||
73 | /* There are 5 types of terminal interface supported, | ||
74 | * TERMIO, TERMIOS, VMS, MSDOS and SGTTY | ||
75 | */ | ||
76 | |||
77 | #if defined(__sgi) && !defined(TERMIOS) | ||
78 | #define TERMIOS | ||
79 | #undef TERMIO | ||
80 | #undef SGTTY | ||
81 | #endif | ||
82 | |||
83 | #if defined(linux) && !defined(TERMIO) | ||
84 | #undef TERMIOS | ||
85 | #define TERMIO | ||
86 | #undef SGTTY | ||
87 | #endif | ||
88 | |||
89 | #ifdef _LIBC | ||
90 | #undef TERMIOS | ||
91 | #define TERMIO | ||
92 | #undef SGTTY | ||
93 | #endif | ||
94 | |||
95 | #if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS) | ||
96 | #undef TERMIOS | ||
97 | #undef TERMIO | ||
98 | #define SGTTY | ||
99 | #endif | ||
100 | |||
101 | #ifdef TERMIOS | ||
102 | #include <termios.h> | ||
103 | #define TTY_STRUCT struct termios | ||
104 | #define TTY_FLAGS c_lflag | ||
105 | #define TTY_get(tty,data) tcgetattr(tty,data) | ||
106 | #define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data) | ||
107 | #endif | ||
108 | |||
109 | #ifdef TERMIO | ||
110 | #include <termio.h> | ||
111 | #define TTY_STRUCT struct termio | ||
112 | #define TTY_FLAGS c_lflag | ||
113 | #define TTY_get(tty,data) ioctl(tty,TCGETA,data) | ||
114 | #define TTY_set(tty,data) ioctl(tty,TCSETA,data) | ||
115 | #endif | ||
116 | |||
117 | #ifdef SGTTY | ||
118 | #include <sgtty.h> | ||
119 | #define TTY_STRUCT struct sgttyb | ||
120 | #define TTY_FLAGS sg_flags | ||
121 | #define TTY_get(tty,data) ioctl(tty,TIOCGETP,data) | ||
122 | #define TTY_set(tty,data) ioctl(tty,TIOCSETP,data) | ||
123 | #endif | ||
124 | |||
125 | #if !defined(_LIBC) && !defined(MSDOS) && !defined(VMS) | ||
126 | #include <sys/ioctl.h> | ||
127 | #endif | ||
128 | |||
129 | #ifdef MSDOS | ||
130 | #include <conio.h> | ||
131 | #define fgets(a,b,c) noecho_fgets(a,b,c) | ||
132 | #endif | ||
133 | |||
134 | #ifdef VMS | ||
135 | #include <ssdef.h> | ||
136 | #include <iodef.h> | ||
137 | #include <ttdef.h> | ||
138 | #include <descrip.h> | ||
139 | struct IOSB { | ||
140 | short iosb$w_value; | ||
141 | short iosb$w_count; | ||
142 | long iosb$l_info; | ||
143 | }; | ||
144 | #endif | ||
145 | |||
146 | #ifndef NX509_SIG | ||
147 | #define NX509_SIG 32 | ||
148 | #endif | ||
149 | |||
150 | #ifndef NOPROTO | ||
151 | static void read_till_nl(FILE *); | ||
152 | static void recsig(int); | ||
153 | static void pushsig(void); | ||
154 | static void popsig(void); | ||
155 | #if defined(MSDOS) && !defined(WIN16) | ||
156 | static int noecho_fgets(char *buf, int size, FILE *tty); | ||
157 | #endif | ||
158 | #else | ||
159 | static void read_till_nl(); | ||
160 | static void recsig(); | ||
161 | static void pushsig(); | ||
162 | static void popsig(); | ||
163 | #if defined(MSDOS) && !defined(WIN16) | ||
164 | static int noecho_fgets(); | ||
165 | #endif | ||
166 | #endif | ||
167 | |||
168 | #ifdef SIGACTION | ||
169 | static struct sigaction savsig[NX509_SIG]; | ||
170 | #else | ||
171 | # ifndef NOPROTO | ||
172 | static void (*savsig[NX509_SIG])(int ); | ||
173 | # else | ||
174 | static void (*savsig[NX509_SIG])(); | ||
175 | # endif | ||
176 | #endif | ||
177 | static jmp_buf save; | ||
178 | |||
179 | int des_read_pw_string(buf, length, prompt, verify) | ||
180 | char *buf; | ||
181 | int length; | ||
182 | char *prompt; | ||
183 | int verify; | ||
184 | { | ||
185 | char buff[BUFSIZ]; | ||
186 | int ret; | ||
187 | |||
188 | ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify); | ||
189 | memset(buff,0,BUFSIZ); | ||
190 | return(ret); | ||
191 | } | ||
192 | |||
193 | #ifndef WIN16 | ||
194 | |||
195 | static void read_till_nl(in) | ||
196 | FILE *in; | ||
197 | { | ||
198 | #define SIZE 4 | ||
199 | char buf[SIZE+1]; | ||
200 | |||
201 | do { | ||
202 | fgets(buf,SIZE,in); | ||
203 | } while (strchr(buf,'\n') == NULL); | ||
204 | } | ||
205 | |||
206 | |||
207 | /* return 0 if ok, 1 (or -1) otherwise */ | ||
208 | int des_read_pw(buf, buff, size, prompt, verify) | ||
209 | char *buf; | ||
210 | char *buff; | ||
211 | int size; | ||
212 | char *prompt; | ||
213 | int verify; | ||
214 | { | ||
215 | #ifdef VMS | ||
216 | struct IOSB iosb; | ||
217 | $DESCRIPTOR(terminal,"TT"); | ||
218 | long tty_orig[3], tty_new[3]; | ||
219 | long status; | ||
220 | unsigned short channel = 0; | ||
221 | #else | ||
222 | #ifndef MSDOS | ||
223 | TTY_STRUCT tty_orig,tty_new; | ||
224 | #endif | ||
225 | #endif | ||
226 | int number=5; | ||
227 | int ok=0; | ||
228 | int ps=0; | ||
229 | int is_a_tty=1; | ||
230 | |||
231 | FILE *tty=NULL; | ||
232 | char *p; | ||
233 | |||
234 | #ifndef MSDOS | ||
235 | if ((tty=fopen("/dev/tty","r")) == NULL) | ||
236 | tty=stdin; | ||
237 | #else /* MSDOS */ | ||
238 | if ((tty=fopen("con","r")) == NULL) | ||
239 | tty=stdin; | ||
240 | #endif /* MSDOS */ | ||
241 | |||
242 | #if defined(TTY_get) && !defined(VMS) | ||
243 | if (TTY_get(fileno(tty),&tty_orig) == -1) | ||
244 | { | ||
245 | #ifdef ENOTTY | ||
246 | if (errno == ENOTTY) | ||
247 | is_a_tty=0; | ||
248 | else | ||
249 | #endif | ||
250 | #ifdef EINVAL | ||
251 | /* Ariel Glenn ariel@columbia.edu reports that solaris | ||
252 | * can return EINVAL instead. This should be ok */ | ||
253 | if (errno == EINVAL) | ||
254 | is_a_tty=0; | ||
255 | else | ||
256 | #endif | ||
257 | return(-1); | ||
258 | } | ||
259 | memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); | ||
260 | #endif | ||
261 | #ifdef VMS | ||
262 | status = SYS$ASSIGN(&terminal,&channel,0,0); | ||
263 | if (status != SS$_NORMAL) | ||
264 | return(-1); | ||
265 | status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0); | ||
266 | if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) | ||
267 | return(-1); | ||
268 | #endif | ||
269 | |||
270 | if (setjmp(save)) | ||
271 | { | ||
272 | ok=0; | ||
273 | goto error; | ||
274 | } | ||
275 | pushsig(); | ||
276 | ps=1; | ||
277 | |||
278 | #ifdef TTY_FLAGS | ||
279 | tty_new.TTY_FLAGS &= ~ECHO; | ||
280 | #endif | ||
281 | |||
282 | #if defined(TTY_set) && !defined(VMS) | ||
283 | if (is_a_tty && (TTY_set(fileno(tty),&tty_new) == -1)) | ||
284 | return(-1); | ||
285 | #endif | ||
286 | #ifdef VMS | ||
287 | tty_new[0] = tty_orig[0]; | ||
288 | tty_new[1] = tty_orig[1] | TT$M_NOECHO; | ||
289 | tty_new[2] = tty_orig[2]; | ||
290 | status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0); | ||
291 | if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) | ||
292 | return(-1); | ||
293 | #endif | ||
294 | ps=2; | ||
295 | |||
296 | while ((!ok) && (number--)) | ||
297 | { | ||
298 | fputs(prompt,stderr); | ||
299 | fflush(stderr); | ||
300 | |||
301 | buf[0]='\0'; | ||
302 | fgets(buf,size,tty); | ||
303 | if (feof(tty)) goto error; | ||
304 | if (ferror(tty)) goto error; | ||
305 | if ((p=(char *)strchr(buf,'\n')) != NULL) | ||
306 | *p='\0'; | ||
307 | else read_till_nl(tty); | ||
308 | if (verify) | ||
309 | { | ||
310 | fprintf(stderr,"\nVerifying password - %s",prompt); | ||
311 | fflush(stderr); | ||
312 | buff[0]='\0'; | ||
313 | fgets(buff,size,tty); | ||
314 | if (feof(tty)) goto error; | ||
315 | if ((p=(char *)strchr(buff,'\n')) != NULL) | ||
316 | *p='\0'; | ||
317 | else read_till_nl(tty); | ||
318 | |||
319 | if (strcmp(buf,buff) != 0) | ||
320 | { | ||
321 | fprintf(stderr,"\nVerify failure"); | ||
322 | fflush(stderr); | ||
323 | break; | ||
324 | /* continue; */ | ||
325 | } | ||
326 | } | ||
327 | ok=1; | ||
328 | } | ||
329 | |||
330 | error: | ||
331 | fprintf(stderr,"\n"); | ||
332 | #ifdef DEBUG | ||
333 | perror("fgets(tty)"); | ||
334 | #endif | ||
335 | /* What can we do if there is an error? */ | ||
336 | #if defined(TTY_set) && !defined(VMS) | ||
337 | if (ps >= 2) TTY_set(fileno(tty),&tty_orig); | ||
338 | #endif | ||
339 | #ifdef VMS | ||
340 | if (ps >= 2) | ||
341 | status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0 | ||
342 | ,tty_orig,12,0,0,0,0); | ||
343 | #endif | ||
344 | |||
345 | if (ps >= 1) popsig(); | ||
346 | if (stdin != tty) fclose(tty); | ||
347 | #ifdef VMS | ||
348 | status = SYS$DASSGN(channel); | ||
349 | #endif | ||
350 | return(!ok); | ||
351 | } | ||
352 | |||
353 | #else /* WIN16 */ | ||
354 | |||
355 | int des_read_pw(buf, buff, size, prompt, verify) | ||
356 | char *buf; | ||
357 | char *buff; | ||
358 | int size; | ||
359 | char *prompt; | ||
360 | int verify; | ||
361 | { | ||
362 | memset(buf,0,size); | ||
363 | memset(buff,0,size); | ||
364 | return(0); | ||
365 | } | ||
366 | |||
367 | #endif | ||
368 | |||
369 | static void pushsig() | ||
370 | { | ||
371 | int i; | ||
372 | |||
373 | for (i=1; i<NX509_SIG; i++) | ||
374 | { | ||
375 | #ifdef SIGUSR1 | ||
376 | if (i == SIGUSR1) | ||
377 | continue; | ||
378 | #endif | ||
379 | #ifdef SIGUSR2 | ||
380 | if (i == SIGUSR2) | ||
381 | continue; | ||
382 | #endif | ||
383 | #ifdef SIGACTION | ||
384 | sigaction(i,NULL,&savsig[i]); | ||
385 | #else | ||
386 | savsig[i]=signal(i,recsig); | ||
387 | #endif | ||
388 | } | ||
389 | |||
390 | #ifdef SIGWINCH | ||
391 | signal(SIGWINCH,SIG_DFL); | ||
392 | #endif | ||
393 | } | ||
394 | |||
395 | static void popsig() | ||
396 | { | ||
397 | int i; | ||
398 | |||
399 | for (i=1; i<NX509_SIG; i++) | ||
400 | { | ||
401 | #ifdef SIGUSR1 | ||
402 | if (i == SIGUSR1) | ||
403 | continue; | ||
404 | #endif | ||
405 | #ifdef SIGUSR2 | ||
406 | if (i == SIGUSR2) | ||
407 | continue; | ||
408 | #endif | ||
409 | #ifdef SIGACTION | ||
410 | sigaction(i,&savsig[i],NULL); | ||
411 | #else | ||
412 | signal(i,savsig[i]); | ||
413 | #endif | ||
414 | } | ||
415 | } | ||
416 | |||
417 | static void recsig(i) | ||
418 | int i; | ||
419 | { | ||
420 | longjmp(save,1); | ||
421 | #ifdef LINT | ||
422 | i=i; | ||
423 | #endif | ||
424 | } | ||
425 | |||
426 | #if defined(MSDOS) && !defined(WIN16) | ||
427 | static int noecho_fgets(buf,size,tty) | ||
428 | char *buf; | ||
429 | int size; | ||
430 | FILE *tty; | ||
431 | { | ||
432 | int i; | ||
433 | char *p; | ||
434 | |||
435 | p=buf; | ||
436 | for (;;) | ||
437 | { | ||
438 | if (size == 0) | ||
439 | { | ||
440 | *p='\0'; | ||
441 | break; | ||
442 | } | ||
443 | size--; | ||
444 | #ifdef WIN16TTY | ||
445 | i=_inchar(); | ||
446 | #else | ||
447 | i=getch(); | ||
448 | #endif | ||
449 | if (i == '\r') i='\n'; | ||
450 | *(p++)=i; | ||
451 | if (i == '\n') | ||
452 | { | ||
453 | *p='\0'; | ||
454 | break; | ||
455 | } | ||
456 | } | ||
457 | return(strlen(buf)); | ||
458 | } | ||
459 | #endif | ||
diff --git a/src/lib/libcrypto/des/rpc_des.h b/src/lib/libcrypto/des/rpc_des.h new file mode 100644 index 0000000000..4cbb4d2dcd --- /dev/null +++ b/src/lib/libcrypto/des/rpc_des.h | |||
@@ -0,0 +1,131 @@ | |||
1 | /* crypto/des/rpc_des.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 | /* @(#)des.h 2.2 88/08/10 4.0 RPCSRC; from 2.7 88/02/08 SMI */ | ||
60 | /* | ||
61 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | ||
62 | * unrestricted use provided that this legend is included on all tape | ||
63 | * media and as a part of the software program in whole or part. Users | ||
64 | * may copy or modify Sun RPC without charge, but are not authorized | ||
65 | * to license or distribute it to anyone else except as part of a product or | ||
66 | * program developed by the user. | ||
67 | * | ||
68 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | ||
69 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | ||
70 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | ||
71 | * | ||
72 | * Sun RPC is provided with no support and without any obligation on the | ||
73 | * part of Sun Microsystems, Inc. to assist in its use, correction, | ||
74 | * modification or enhancement. | ||
75 | * | ||
76 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | ||
77 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | ||
78 | * OR ANY PART THEREOF. | ||
79 | * | ||
80 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | ||
81 | * or profits or other special, indirect and consequential damages, even if | ||
82 | * Sun has been advised of the possibility of such damages. | ||
83 | * | ||
84 | * Sun Microsystems, Inc. | ||
85 | * 2550 Garcia Avenue | ||
86 | * Mountain View, California 94043 | ||
87 | */ | ||
88 | /* | ||
89 | * Generic DES driver interface | ||
90 | * Keep this file hardware independent! | ||
91 | * Copyright (c) 1986 by Sun Microsystems, Inc. | ||
92 | */ | ||
93 | |||
94 | #define DES_MAXLEN 65536 /* maximum # of bytes to encrypt */ | ||
95 | #define DES_QUICKLEN 16 /* maximum # of bytes to encrypt quickly */ | ||
96 | |||
97 | #ifdef HEADER_DES_H | ||
98 | #undef ENCRYPT | ||
99 | #undef DECRYPT | ||
100 | #endif | ||
101 | |||
102 | enum desdir { ENCRYPT, DECRYPT }; | ||
103 | enum desmode { CBC, ECB }; | ||
104 | |||
105 | /* | ||
106 | * parameters to ioctl call | ||
107 | */ | ||
108 | struct desparams { | ||
109 | unsigned char des_key[8]; /* key (with low bit parity) */ | ||
110 | enum desdir des_dir; /* direction */ | ||
111 | enum desmode des_mode; /* mode */ | ||
112 | unsigned char des_ivec[8]; /* input vector */ | ||
113 | unsigned des_len; /* number of bytes to crypt */ | ||
114 | union { | ||
115 | unsigned char UDES_data[DES_QUICKLEN]; | ||
116 | unsigned char *UDES_buf; | ||
117 | } UDES; | ||
118 | # define des_data UDES.UDES_data /* direct data here if quick */ | ||
119 | # define des_buf UDES.UDES_buf /* otherwise, pointer to data */ | ||
120 | }; | ||
121 | |||
122 | /* | ||
123 | * Encrypt an arbitrary sized buffer | ||
124 | */ | ||
125 | #define DESIOCBLOCK _IOWR(d, 6, struct desparams) | ||
126 | |||
127 | /* | ||
128 | * Encrypt of small amount of data, quickly | ||
129 | */ | ||
130 | #define DESIOCQUICK _IOWR(d, 7, struct desparams) | ||
131 | |||
diff --git a/src/lib/libcrypto/des/rpc_enc.c b/src/lib/libcrypto/des/rpc_enc.c new file mode 100644 index 0000000000..7c1da1f538 --- /dev/null +++ b/src/lib/libcrypto/des/rpc_enc.c | |||
@@ -0,0 +1,107 @@ | |||
1 | /* crypto/des/rpc_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 "rpc_des.h" | ||
60 | #include "des_locl.h" | ||
61 | #include "des_ver.h" | ||
62 | |||
63 | #ifndef NOPROTO | ||
64 | int _des_crypt(char *buf,int len,struct desparams *desp); | ||
65 | #else | ||
66 | int _des_crypt(); | ||
67 | #endif | ||
68 | |||
69 | int _des_crypt(buf, len, desp) | ||
70 | char *buf; | ||
71 | int len; | ||
72 | struct desparams *desp; | ||
73 | { | ||
74 | des_key_schedule ks; | ||
75 | int enc; | ||
76 | |||
77 | des_set_key((des_cblock *)desp->des_key,ks); | ||
78 | enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT; | ||
79 | |||
80 | if (desp->des_mode == CBC) | ||
81 | des_ecb_encrypt((des_cblock *)desp->UDES.UDES_buf, | ||
82 | (des_cblock *)desp->UDES.UDES_buf,ks,enc); | ||
83 | else | ||
84 | { | ||
85 | des_ncbc_encrypt((des_cblock *)desp->UDES.UDES_buf, | ||
86 | (des_cblock *)desp->UDES.UDES_buf, | ||
87 | (long)len,ks, | ||
88 | (des_cblock *)desp->des_ivec,enc); | ||
89 | #ifdef undef | ||
90 | /* len will always be %8 if called from common_crypt | ||
91 | * in secure_rpc. | ||
92 | * Libdes's cbc encrypt does not copy back the iv, | ||
93 | * so we have to do it here. */ | ||
94 | /* It does now :-) eay 20/09/95 */ | ||
95 | |||
96 | a=(char *)&(desp->UDES.UDES_buf[len-8]); | ||
97 | b=(char *)&(desp->des_ivec[0]); | ||
98 | |||
99 | *(a++)= *(b++); *(a++)= *(b++); | ||
100 | *(a++)= *(b++); *(a++)= *(b++); | ||
101 | *(a++)= *(b++); *(a++)= *(b++); | ||
102 | *(a++)= *(b++); *(a++)= *(b++); | ||
103 | #endif | ||
104 | } | ||
105 | return(1); | ||
106 | } | ||
107 | |||
diff --git a/src/lib/libcrypto/des/rpw.c b/src/lib/libcrypto/des/rpw.c new file mode 100644 index 0000000000..6447ed9cf0 --- /dev/null +++ b/src/lib/libcrypto/des/rpw.c | |||
@@ -0,0 +1,101 @@ | |||
1 | /* crypto/des/rpw.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 "des.h" | ||
61 | |||
62 | int main(argc,argv) | ||
63 | int argc; | ||
64 | char *argv[]; | ||
65 | { | ||
66 | des_cblock k,k1; | ||
67 | int i; | ||
68 | |||
69 | printf("read passwd\n"); | ||
70 | if ((i=des_read_password((C_Block *)k,"Enter password:",0)) == 0) | ||
71 | { | ||
72 | printf("password = "); | ||
73 | for (i=0; i<8; i++) | ||
74 | printf("%02x ",k[i]); | ||
75 | } | ||
76 | else | ||
77 | printf("error %d\n",i); | ||
78 | printf("\n"); | ||
79 | printf("read 2passwds and verify\n"); | ||
80 | if ((i=des_read_2passwords((C_Block *)k,(C_Block *)k1, | ||
81 | "Enter verified password:",1)) == 0) | ||
82 | { | ||
83 | printf("password1 = "); | ||
84 | for (i=0; i<8; i++) | ||
85 | printf("%02x ",k[i]); | ||
86 | printf("\n"); | ||
87 | printf("password2 = "); | ||
88 | for (i=0; i<8; i++) | ||
89 | printf("%02x ",k1[i]); | ||
90 | printf("\n"); | ||
91 | exit(1); | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | printf("error %d\n",i); | ||
96 | exit(0); | ||
97 | } | ||
98 | #ifdef LINT | ||
99 | return(0); | ||
100 | #endif | ||
101 | } | ||
diff --git a/src/lib/libcrypto/des/speed.c b/src/lib/libcrypto/des/speed.c new file mode 100644 index 0000000000..5bbe8b01d6 --- /dev/null +++ b/src/lib/libcrypto/des/speed.c | |||
@@ -0,0 +1,329 @@ | |||
1 | /* crypto/des/speed.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 | /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ | ||
60 | /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ | ||
61 | |||
62 | #ifndef MSDOS | ||
63 | #define TIMES | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | #ifndef MSDOS | ||
68 | #include <unistd.h> | ||
69 | #else | ||
70 | #include <io.h> | ||
71 | extern int exit(); | ||
72 | #endif | ||
73 | #include <signal.h> | ||
74 | #ifndef VMS | ||
75 | #ifndef _IRIX | ||
76 | #include <time.h> | ||
77 | #endif | ||
78 | #ifdef TIMES | ||
79 | #include <sys/types.h> | ||
80 | #include <sys/times.h> | ||
81 | #endif | ||
82 | #else /* VMS */ | ||
83 | #include <types.h> | ||
84 | struct tms { | ||
85 | time_t tms_utime; | ||
86 | time_t tms_stime; | ||
87 | time_t tms_uchild; /* I dunno... */ | ||
88 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
89 | } | ||
90 | #endif | ||
91 | #ifndef TIMES | ||
92 | #include <sys/timeb.h> | ||
93 | #endif | ||
94 | |||
95 | #ifdef sun | ||
96 | #include <limits.h> | ||
97 | #include <sys/param.h> | ||
98 | #endif | ||
99 | |||
100 | #include "des.h" | ||
101 | |||
102 | /* The following if from times(3) man page. It may need to be changed */ | ||
103 | #ifndef HZ | ||
104 | # ifndef CLK_TCK | ||
105 | # ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ | ||
106 | # ifndef VMS | ||
107 | # define HZ 100.0 | ||
108 | # else /* VMS */ | ||
109 | # define HZ 100.0 | ||
110 | # endif | ||
111 | # else /* _BSD_CLK_TCK_ */ | ||
112 | # define HZ ((double)_BSD_CLK_TCK_) | ||
113 | # endif | ||
114 | # else /* CLK_TCK */ | ||
115 | # define HZ ((double)CLK_TCK) | ||
116 | # endif | ||
117 | #endif | ||
118 | |||
119 | #define BUFSIZE ((long)1024) | ||
120 | long run=0; | ||
121 | |||
122 | #ifndef NOPROTO | ||
123 | double Time_F(int s); | ||
124 | #else | ||
125 | double Time_F(); | ||
126 | #endif | ||
127 | |||
128 | #ifdef SIGALRM | ||
129 | #if defined(__STDC__) || defined(sgi) || defined(_AIX) | ||
130 | #define SIGRETTYPE void | ||
131 | #else | ||
132 | #define SIGRETTYPE int | ||
133 | #endif | ||
134 | |||
135 | #ifndef NOPROTO | ||
136 | SIGRETTYPE sig_done(int sig); | ||
137 | #else | ||
138 | SIGRETTYPE sig_done(); | ||
139 | #endif | ||
140 | |||
141 | SIGRETTYPE sig_done(sig) | ||
142 | int sig; | ||
143 | { | ||
144 | signal(SIGALRM,sig_done); | ||
145 | run=0; | ||
146 | #ifdef LINT | ||
147 | sig=sig; | ||
148 | #endif | ||
149 | } | ||
150 | #endif | ||
151 | |||
152 | #define START 0 | ||
153 | #define STOP 1 | ||
154 | |||
155 | double Time_F(s) | ||
156 | int s; | ||
157 | { | ||
158 | double ret; | ||
159 | #ifdef TIMES | ||
160 | static struct tms tstart,tend; | ||
161 | |||
162 | if (s == START) | ||
163 | { | ||
164 | times(&tstart); | ||
165 | return(0); | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | times(&tend); | ||
170 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
171 | return((ret == 0.0)?1e-6:ret); | ||
172 | } | ||
173 | #else /* !times() */ | ||
174 | static struct timeb tstart,tend; | ||
175 | long i; | ||
176 | |||
177 | if (s == START) | ||
178 | { | ||
179 | ftime(&tstart); | ||
180 | return(0); | ||
181 | } | ||
182 | else | ||
183 | { | ||
184 | ftime(&tend); | ||
185 | i=(long)tend.millitm-(long)tstart.millitm; | ||
186 | ret=((double)(tend.time-tstart.time))+((double)i)/1e3; | ||
187 | return((ret == 0.0)?1e-6:ret); | ||
188 | } | ||
189 | #endif | ||
190 | } | ||
191 | |||
192 | int main(argc,argv) | ||
193 | int argc; | ||
194 | char **argv; | ||
195 | { | ||
196 | long count; | ||
197 | static unsigned char buf[BUFSIZE]; | ||
198 | static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; | ||
199 | static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; | ||
200 | static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; | ||
201 | des_key_schedule sch,sch2,sch3; | ||
202 | double a,b,c,d,e; | ||
203 | #ifndef SIGALRM | ||
204 | long ca,cb,cc,cd,ce; | ||
205 | #endif | ||
206 | |||
207 | #ifndef TIMES | ||
208 | printf("To get the most acurate results, try to run this\n"); | ||
209 | printf("program when this computer is idle.\n"); | ||
210 | #endif | ||
211 | |||
212 | des_set_key((C_Block *)key2,sch2); | ||
213 | des_set_key((C_Block *)key3,sch3); | ||
214 | |||
215 | #ifndef SIGALRM | ||
216 | printf("First we calculate the approximate speed ...\n"); | ||
217 | des_set_key((C_Block *)key,sch); | ||
218 | count=10; | ||
219 | do { | ||
220 | long i; | ||
221 | DES_LONG data[2]; | ||
222 | |||
223 | count*=2; | ||
224 | Time_F(START); | ||
225 | for (i=count; i; i--) | ||
226 | des_encrypt(data,&(sch[0]),DES_ENCRYPT); | ||
227 | d=Time_F(STOP); | ||
228 | } while (d < 3.0); | ||
229 | ca=count; | ||
230 | cb=count*3; | ||
231 | cc=count*3*8/BUFSIZE+1; | ||
232 | cd=count*8/BUFSIZE+1; | ||
233 | ce=count/20+1; | ||
234 | printf("Doing set_key %ld times\n",ca); | ||
235 | #define COND(d) (count != (d)) | ||
236 | #define COUNT(d) (d) | ||
237 | #else | ||
238 | #define COND(c) (run) | ||
239 | #define COUNT(d) (count) | ||
240 | signal(SIGALRM,sig_done); | ||
241 | printf("Doing set_key for 10 seconds\n"); | ||
242 | alarm(10); | ||
243 | #endif | ||
244 | |||
245 | Time_F(START); | ||
246 | for (count=0,run=1; COND(ca); count++) | ||
247 | des_set_key((C_Block *)key,sch); | ||
248 | d=Time_F(STOP); | ||
249 | printf("%ld set_key's in %.2f seconds\n",count,d); | ||
250 | a=((double)COUNT(ca))/d; | ||
251 | |||
252 | #ifdef SIGALRM | ||
253 | printf("Doing des_encrypt's for 10 seconds\n"); | ||
254 | alarm(10); | ||
255 | #else | ||
256 | printf("Doing des_encrypt %ld times\n",cb); | ||
257 | #endif | ||
258 | Time_F(START); | ||
259 | for (count=0,run=1; COND(cb); count++) | ||
260 | { | ||
261 | DES_LONG data[2]; | ||
262 | |||
263 | des_encrypt(data,&(sch[0]),DES_ENCRYPT); | ||
264 | } | ||
265 | d=Time_F(STOP); | ||
266 | printf("%ld des_encrypt's in %.2f second\n",count,d); | ||
267 | b=((double)COUNT(cb)*8)/d; | ||
268 | |||
269 | #ifdef SIGALRM | ||
270 | printf("Doing des_cbc_encrypt on %ld byte blocks for 10 seconds\n", | ||
271 | BUFSIZE); | ||
272 | alarm(10); | ||
273 | #else | ||
274 | printf("Doing des_cbc_encrypt %ld times on %ld byte blocks\n",cc, | ||
275 | BUFSIZE); | ||
276 | #endif | ||
277 | Time_F(START); | ||
278 | for (count=0,run=1; COND(cc); count++) | ||
279 | des_ncbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,&(sch[0]), | ||
280 | (C_Block *)&(key[0]),DES_ENCRYPT); | ||
281 | d=Time_F(STOP); | ||
282 | printf("%ld des_cbc_encrypt's of %ld byte blocks in %.2f second\n", | ||
283 | count,BUFSIZE,d); | ||
284 | c=((double)COUNT(cc)*BUFSIZE)/d; | ||
285 | |||
286 | #ifdef SIGALRM | ||
287 | printf("Doing des_ede_cbc_encrypt on %ld byte blocks for 10 seconds\n", | ||
288 | BUFSIZE); | ||
289 | alarm(10); | ||
290 | #else | ||
291 | printf("Doing des_ede_cbc_encrypt %ld times on %ld byte blocks\n",cd, | ||
292 | BUFSIZE); | ||
293 | #endif | ||
294 | Time_F(START); | ||
295 | for (count=0,run=1; COND(cd); count++) | ||
296 | des_ede3_cbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE, | ||
297 | &(sch[0]), | ||
298 | &(sch2[0]), | ||
299 | &(sch3[0]), | ||
300 | (C_Block *)&(key[0]), | ||
301 | DES_ENCRYPT); | ||
302 | d=Time_F(STOP); | ||
303 | printf("%ld des_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n", | ||
304 | count,BUFSIZE,d); | ||
305 | d=((double)COUNT(cd)*BUFSIZE)/d; | ||
306 | |||
307 | #ifdef SIGALRM | ||
308 | printf("Doing crypt for 10 seconds\n"); | ||
309 | alarm(10); | ||
310 | #else | ||
311 | printf("Doing crypt %ld times\n",ce); | ||
312 | #endif | ||
313 | Time_F(START); | ||
314 | for (count=0,run=1; COND(ce); count++) | ||
315 | crypt("testing1","ef"); | ||
316 | e=Time_F(STOP); | ||
317 | printf("%ld crypts in %.2f second\n",count,e); | ||
318 | e=((double)COUNT(ce))/e; | ||
319 | |||
320 | printf("set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a); | ||
321 | printf("DES raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b); | ||
322 | printf("DES cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c); | ||
323 | printf("DES ede cbc bytes per sec = %12.2f (%9.3fuS)\n",d,8.0e6/d); | ||
324 | printf("crypt per sec = %12.2f (%9.3fuS)\n",e,1.0e6/e); | ||
325 | exit(0); | ||
326 | #if defined(LINT) || defined(MSDOS) | ||
327 | return(0); | ||
328 | #endif | ||
329 | } | ||
diff --git a/src/lib/libcrypto/des/t/test b/src/lib/libcrypto/des/t/test new file mode 100644 index 0000000000..97acd0552e --- /dev/null +++ b/src/lib/libcrypto/des/t/test | |||
@@ -0,0 +1,27 @@ | |||
1 | #!./perl | ||
2 | |||
3 | BEGIN { push(@INC, qw(../../../lib ../../lib ../lib lib)); } | ||
4 | |||
5 | use DES; | ||
6 | |||
7 | $key='00000000'; | ||
8 | $ks=DES::set_key($key); | ||
9 | @a=split(//,$ks); | ||
10 | foreach (@a) { printf "%02x-",ord($_); } | ||
11 | print "\n"; | ||
12 | |||
13 | |||
14 | $key=DES::random_key(); | ||
15 | print "($_)\n"; | ||
16 | @a=split(//,$key); | ||
17 | foreach (@a) { printf "%02x-",ord($_); } | ||
18 | print "\n"; | ||
19 | $str="this is and again into the breach"; | ||
20 | ($k1,$k2)=DES::string_to_2keys($str); | ||
21 | @a=split(//,$k1); | ||
22 | foreach (@a) { printf "%02x-",ord($_); } | ||
23 | print "\n"; | ||
24 | @a=split(//,$k2); | ||
25 | foreach (@a) { printf "%02x-",ord($_); } | ||
26 | print "\n"; | ||
27 | |||
diff --git a/src/lib/libcrypto/des/times/486-50.sol b/src/lib/libcrypto/des/times/486-50.sol new file mode 100644 index 0000000000..0de62d6db3 --- /dev/null +++ b/src/lib/libcrypto/des/times/486-50.sol | |||
@@ -0,0 +1,16 @@ | |||
1 | Solaris 2.4, 486 50mhz, gcc 2.6.3 | ||
2 | options des ecb/s | ||
3 | 16 r2 i 43552.51 100.0% | ||
4 | 16 r1 i 43487.45 99.9% | ||
5 | 16 c p 43003.23 98.7% | ||
6 | 16 r2 p 42339.00 97.2% | ||
7 | 16 c i 41900.91 96.2% | ||
8 | 16 r1 p 41360.64 95.0% | ||
9 | 4 c i 38728.48 88.9% | ||
10 | 4 c p 38225.63 87.8% | ||
11 | 4 r1 i 38085.79 87.4% | ||
12 | 4 r2 i 37825.64 86.9% | ||
13 | 4 r2 p 34611.00 79.5% | ||
14 | 4 r1 p 31802.00 73.0% | ||
15 | -DDES_UNROLL -DDES_RISC2 | ||
16 | |||
diff --git a/src/lib/libcrypto/des/times/586-100.lnx b/src/lib/libcrypto/des/times/586-100.lnx new file mode 100644 index 0000000000..4323914a11 --- /dev/null +++ b/src/lib/libcrypto/des/times/586-100.lnx | |||
@@ -0,0 +1,20 @@ | |||
1 | Pentium 100 | ||
2 | Linux 2 kernel | ||
3 | gcc 2.7.0 -O3 -fomit-frame-pointer | ||
4 | No X server running, just a console, it makes the top speed jump from 151,000 | ||
5 | to 158,000 :-). | ||
6 | options des ecb/s | ||
7 | assember 281000.00 177.1% | ||
8 | 16 r1 p 158667.40 100.0% | ||
9 | 16 r1 i 148471.70 93.6% | ||
10 | 16 r2 p 143961.80 90.7% | ||
11 | 16 r2 i 141689.20 89.3% | ||
12 | 4 r1 i 140100.00 88.3% | ||
13 | 4 r2 i 134049.40 84.5% | ||
14 | 16 c i 124145.20 78.2% | ||
15 | 16 c p 121584.20 76.6% | ||
16 | 4 c i 118116.00 74.4% | ||
17 | 4 r2 p 117977.90 74.4% | ||
18 | 4 c p 114971.40 72.5% | ||
19 | 4 r1 p 114578.40 72.2% | ||
20 | -DDES_UNROLL -DDES_RISC1 -DDES_PTR | ||
diff --git a/src/lib/libcrypto/des/times/686-200.fre b/src/lib/libcrypto/des/times/686-200.fre new file mode 100644 index 0000000000..7d83f6adee --- /dev/null +++ b/src/lib/libcrypto/des/times/686-200.fre | |||
@@ -0,0 +1,18 @@ | |||
1 | Pentium 100 | ||
2 | Free BSD 2.1.5 kernel | ||
3 | gcc 2.7.2.2 -O3 -fomit-frame-pointer | ||
4 | options des ecb/s | ||
5 | assember 578000.00 133.1% | ||
6 | 16 r2 i 434454.80 100.0% | ||
7 | 16 r1 i 433621.43 99.8% | ||
8 | 16 r2 p 431375.69 99.3% | ||
9 | 4 r1 i 423722.30 97.5% | ||
10 | 4 r2 i 422399.40 97.2% | ||
11 | 16 r1 p 421739.40 97.1% | ||
12 | 16 c i 399027.94 91.8% | ||
13 | 16 c p 372251.70 85.7% | ||
14 | 4 c i 365118.35 84.0% | ||
15 | 4 c p 352880.51 81.2% | ||
16 | 4 r2 p 255104.90 58.7% | ||
17 | 4 r1 p 251289.18 57.8% | ||
18 | -DDES_UNROLL -DDES_RISC2 | ||
diff --git a/src/lib/libcrypto/des/times/aix.cc b/src/lib/libcrypto/des/times/aix.cc new file mode 100644 index 0000000000..d96b74e2ce --- /dev/null +++ b/src/lib/libcrypto/des/times/aix.cc | |||
@@ -0,0 +1,26 @@ | |||
1 | From: Paco Garcia <pgarcia@cam.es> | ||
2 | |||
3 | This machine is a Bull Estrella Minitower Model MT604-100 | ||
4 | Processor : PPC604 | ||
5 | P.Speed : 100Mhz | ||
6 | Data/Instr Cache : 16 K | ||
7 | L2 Cache : 256 K | ||
8 | PCI BUS Speed : 33 Mhz | ||
9 | TransfRate PCI : 132 MB/s | ||
10 | Memory : 96 MB | ||
11 | |||
12 | options des ecb/s | ||
13 | 4 c p 275118.61 100.0% | ||
14 | 4 c i 273545.07 99.4% | ||
15 | 4 r2 p 270441.02 98.3% | ||
16 | 4 r1 p 253052.15 92.0% | ||
17 | 4 r2 i 240842.97 87.5% | ||
18 | 4 r1 i 240556.66 87.4% | ||
19 | 16 c i 224603.99 81.6% | ||
20 | 16 c p 224483.98 81.6% | ||
21 | 16 r2 p 215691.19 78.4% | ||
22 | 16 r1 p 208332.83 75.7% | ||
23 | 16 r1 i 199206.50 72.4% | ||
24 | 16 r2 i 198963.70 72.3% | ||
25 | -DDES_PTR | ||
26 | |||
diff --git a/src/lib/libcrypto/des/times/alpha.cc b/src/lib/libcrypto/des/times/alpha.cc new file mode 100644 index 0000000000..95c17efae7 --- /dev/null +++ b/src/lib/libcrypto/des/times/alpha.cc | |||
@@ -0,0 +1,18 @@ | |||
1 | cc -O2 | ||
2 | DES_LONG is 'unsigned int' | ||
3 | |||
4 | options des ecb/s | ||
5 | 4 r2 p 181146.14 100.0% | ||
6 | 16 r2 p 172102.94 95.0% | ||
7 | 4 r2 i 165424.11 91.3% | ||
8 | 16 c p 160468.64 88.6% | ||
9 | 4 c p 156653.59 86.5% | ||
10 | 4 c i 155245.18 85.7% | ||
11 | 4 r1 p 154729.68 85.4% | ||
12 | 16 r2 i 154137.69 85.1% | ||
13 | 16 r1 p 152357.96 84.1% | ||
14 | 16 c i 148743.91 82.1% | ||
15 | 4 r1 i 146695.59 81.0% | ||
16 | 16 r1 i 144961.00 80.0% | ||
17 | -DDES_RISC2 -DDES_PTR | ||
18 | |||
diff --git a/src/lib/libcrypto/des/times/hpux.cc b/src/lib/libcrypto/des/times/hpux.cc new file mode 100644 index 0000000000..3de856ddac --- /dev/null +++ b/src/lib/libcrypto/des/times/hpux.cc | |||
@@ -0,0 +1,17 @@ | |||
1 | HPUX 10 - 9000/887 - cc -D_HPUX_SOURCE -Aa +ESlit +O2 -Wl,-a,archive | ||
2 | |||
3 | options des ecb/s | ||
4 | 16 c i 149448.90 100.0% | ||
5 | 4 c i 145861.79 97.6% | ||
6 | 16 r2 i 141710.96 94.8% | ||
7 | 16 r1 i 139455.33 93.3% | ||
8 | 4 r2 i 138800.00 92.9% | ||
9 | 4 r1 i 136692.65 91.5% | ||
10 | 16 r2 p 110228.17 73.8% | ||
11 | 16 r1 p 109397.07 73.2% | ||
12 | 16 c p 109209.89 73.1% | ||
13 | 4 c p 108014.71 72.3% | ||
14 | 4 r2 p 107873.88 72.2% | ||
15 | 4 r1 p 107685.83 72.1% | ||
16 | -DDES_UNROLL | ||
17 | |||
diff --git a/src/lib/libcrypto/des/times/sparc.gcc b/src/lib/libcrypto/des/times/sparc.gcc new file mode 100644 index 0000000000..8eaa042104 --- /dev/null +++ b/src/lib/libcrypto/des/times/sparc.gcc | |||
@@ -0,0 +1,17 @@ | |||
1 | solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2 | ||
2 | |||
3 | options des ecb/s | ||
4 | 16 c i 124382.70 100.0% | ||
5 | 4 c i 118884.68 95.6% | ||
6 | 16 c p 112261.20 90.3% | ||
7 | 16 r2 i 111777.10 89.9% | ||
8 | 16 r2 p 108896.30 87.5% | ||
9 | 16 r1 p 108791.59 87.5% | ||
10 | 4 c p 107290.10 86.3% | ||
11 | 4 r1 p 104583.80 84.1% | ||
12 | 16 r1 i 104206.20 83.8% | ||
13 | 4 r2 p 103709.80 83.4% | ||
14 | 4 r2 i 98306.43 79.0% | ||
15 | 4 r1 i 91525.80 73.6% | ||
16 | -DDES_UNROLL | ||
17 | |||
diff --git a/src/lib/libcrypto/des/times/usparc.cc b/src/lib/libcrypto/des/times/usparc.cc new file mode 100644 index 0000000000..f6ec8e8831 --- /dev/null +++ b/src/lib/libcrypto/des/times/usparc.cc | |||
@@ -0,0 +1,31 @@ | |||
1 | solaris 2.5.1 usparc 167mhz?? - SC4.0 cc -fast -Xa -xO5 | ||
2 | |||
3 | For the ultra sparc, SunC 4.0 cc -fast -Xa -xO5, running 'des_opts' | ||
4 | gives a speed of 475,000 des/s while 'speed' gives 417,000 des/s. | ||
5 | I belive the difference is tied up in optimisation that the compiler | ||
6 | is able to perform when the code is 'inlined'. For 'speed', the DES | ||
7 | routines are being linked from a library. I'll record the higher | ||
8 | speed since if performance is everything, you can always inline | ||
9 | 'des_enc.c'. | ||
10 | |||
11 | [ 16-Jan-06 - I've been playing with the | ||
12 | '-xtarget=ultra -xarch=v8plus -Xa -xO5 -Xa' | ||
13 | and while it makes the des_opts numbers much slower, it makes the | ||
14 | actual 'speed' numbers look better which is a realistic version of | ||
15 | using the libraries. ] | ||
16 | |||
17 | options des ecb/s | ||
18 | 16 r1 p 475516.90 100.0% | ||
19 | 16 r2 p 439388.10 92.4% | ||
20 | 16 c i 427001.40 89.8% | ||
21 | 16 c p 419516.50 88.2% | ||
22 | 4 r2 p 409491.70 86.1% | ||
23 | 4 r1 p 404266.90 85.0% | ||
24 | 4 c p 398121.00 83.7% | ||
25 | 4 c i 370588.40 77.9% | ||
26 | 4 r1 i 362742.20 76.3% | ||
27 | 16 r2 i 331275.50 69.7% | ||
28 | 16 r1 i 324730.60 68.3% | ||
29 | 4 r2 i 63535.10 13.4% <-- very very weird, must be cache problems. | ||
30 | -DDES_UNROLL -DDES_RISC1 -DDES_PTR | ||
31 | |||
diff --git a/src/lib/libcrypto/des/typemap b/src/lib/libcrypto/des/typemap new file mode 100644 index 0000000000..a524f53634 --- /dev/null +++ b/src/lib/libcrypto/des/typemap | |||
@@ -0,0 +1,34 @@ | |||
1 | # | ||
2 | # DES SECTION | ||
3 | # | ||
4 | deschar * T_DESCHARP | ||
5 | des_cblock * T_CBLOCK | ||
6 | des_cblock T_CBLOCK | ||
7 | des_key_schedule T_SCHEDULE | ||
8 | des_key_schedule * T_SCHEDULE | ||
9 | |||
10 | INPUT | ||
11 | T_CBLOCK | ||
12 | $var=(des_cblock *)SvPV($arg,len); | ||
13 | if (len < DES_KEY_SZ) | ||
14 | { | ||
15 | croak(\"$var needs to be at least %u bytes long\",DES_KEY_SZ); | ||
16 | } | ||
17 | |||
18 | T_SCHEDULE | ||
19 | $var=(des_key_schedule *)SvPV($arg,len); | ||
20 | if (len < DES_SCHEDULE_SZ) | ||
21 | { | ||
22 | croak(\"$var needs to be at least %u bytes long\", | ||
23 | DES_SCHEDULE_SZ); | ||
24 | } | ||
25 | |||
26 | OUTPUT | ||
27 | T_CBLOCK | ||
28 | sv_setpvn($arg,(char *)$var,DES_KEY_SZ); | ||
29 | |||
30 | T_SCHEDULE | ||
31 | sv_setpvn($arg,(char *)$var,DES_SCHEDULE_SZ); | ||
32 | |||
33 | T_DESCHARP | ||
34 | sv_setpvn($arg,(char *)$var,len); | ||
diff --git a/src/lib/libcrypto/dh/dh1024.pem b/src/lib/libcrypto/dh/dh1024.pem new file mode 100644 index 0000000000..81d43f6a3e --- /dev/null +++ b/src/lib/libcrypto/dh/dh1024.pem | |||
@@ -0,0 +1,5 @@ | |||
1 | -----BEGIN DH PARAMETERS----- | ||
2 | MIGHAoGBAJf2QmHKtQXdKCjhPx1ottPb0PMTBH9A6FbaWMsTuKG/K3g6TG1Z1fkq | ||
3 | /Gz/PWk/eLI9TzFgqVAuPvr3q14a1aZeVUMTgo2oO5/y2UHe6VaJ+trqCTat3xlx | ||
4 | /mNbIK9HA2RgPC3gWfVLZQrY+gz3ASHHR5nXWHEyvpuZm7m3h+irAgEC | ||
5 | -----END DH PARAMETERS----- | ||
diff --git a/src/lib/libcrypto/dh/dh192.pem b/src/lib/libcrypto/dh/dh192.pem new file mode 100644 index 0000000000..521c07271d --- /dev/null +++ b/src/lib/libcrypto/dh/dh192.pem | |||
@@ -0,0 +1,3 @@ | |||
1 | -----BEGIN DH PARAMETERS----- | ||
2 | MB4CGQDUoLoCULb9LsYm5+/WN992xxbiLQlEuIsCAQM= | ||
3 | -----END DH PARAMETERS----- | ||
diff --git a/src/lib/libcrypto/dh/dh2048.pem b/src/lib/libcrypto/dh/dh2048.pem new file mode 100644 index 0000000000..295460f508 --- /dev/null +++ b/src/lib/libcrypto/dh/dh2048.pem | |||
@@ -0,0 +1,16 @@ | |||
1 | -----BEGIN DH PARAMETERS----- | ||
2 | MIIBCAKCAQEA7ZKJNYJFVcs7+6J2WmkEYb8h86tT0s0h2v94GRFS8Q7B4lW9aG9o | ||
3 | AFO5Imov5Jo0H2XMWTKKvbHbSe3fpxJmw/0hBHAY8H/W91hRGXKCeyKpNBgdL8sh | ||
4 | z22SrkO2qCnHJ6PLAMXy5fsKpFmFor2tRfCzrfnggTXu2YOzzK7q62bmqVdmufEo | ||
5 | pT8igNcLpvZxk5uBDvhakObMym9mX3rAEBoe8PwttggMYiiw7NuJKO4MqD1llGkW | ||
6 | aVM8U2ATsCun1IKHrRxynkE1/MJ86VHeYYX8GZt2YA8z+GuzylIOKcMH6JAWzMwA | ||
7 | Gbatw6QwizOhr9iMjZ0B26TE3X8LvW84wwIBAg== | ||
8 | -----END DH PARAMETERS----- | ||
9 | -----BEGIN DH PARAMETERS----- | ||
10 | MIIBCAKCAQEArtA3w73zP6Lu3EOQtwogiXt3AXXpuS6yD4BhzNS1pZFyPHk0/an5 | ||
11 | 8ydEkPhQZHKDW+BZJxxPLANaTudWo2YT8TgtvUdN6KSgMiEi6McwqDw+SADuvW+F | ||
12 | SKUYFxG6VFIxyEP6xBdf+vhJxEDbRG2EYsHDRRtJ76gp9cSKTHusf2R+4AAVGqnt | ||
13 | gRAbNqtcOar/7FSj+Pl8G3v0Bty0LcCSpbqgYlnv6z+rErQmmC6PPvSz97TDMCok | ||
14 | yKpCE9hFA1zkqK3TH4FmFvGeIaXJUIBZf4mArWuBTjWFW3nmhESRUn1VK3K3x42N | ||
15 | a5k6c2+EhrMFiLjxuH6JZoqL0/E93FF9SwIBAg== | ||
16 | -----END DH PARAMETERS----- | ||
diff --git a/src/lib/libcrypto/dh/dh4096.pem b/src/lib/libcrypto/dh/dh4096.pem new file mode 100644 index 0000000000..390943a21d --- /dev/null +++ b/src/lib/libcrypto/dh/dh4096.pem | |||
@@ -0,0 +1,14 @@ | |||
1 | -----BEGIN DH PARAMETERS----- | ||
2 | MIICCAKCAgEA/urRnb6vkPYc/KEGXWnbCIOaKitq7ySIq9dTH7s+Ri59zs77zty7 | ||
3 | vfVlSe6VFTBWgYjD2XKUFmtqq6CqXMhVX5ElUDoYDpAyTH85xqNFLzFC7nKrff/H | ||
4 | TFKNttp22cZE9V0IPpzedPfnQkE7aUdmF9JnDyv21Z/818O93u1B4r0szdnmEvEF | ||
5 | bKuIxEHX+bp0ZR7RqE1AeifXGJX3d6tsd2PMAObxwwsv55RGkn50vHO4QxtTARr1 | ||
6 | rRUV5j3B3oPMgC7Offxx+98Xn45B1/G0Prp11anDsR1PGwtaCYipqsvMwQUSJtyE | ||
7 | EOQWk+yFkeMe4vWv367eEi0Sd/wnC+TSXBE3pYvpYerJ8n1MceI5GQTdarJ77OW9 | ||
8 | bGTHmxRsLSCM1jpLdPja5jjb4siAa6EHc4qN9c/iFKS3PQPJEnX7pXKBRs5f7AF3 | ||
9 | W3RIGt+G9IVNZfXaS7Z/iCpgzgvKCs0VeqN38QsJGtC1aIkwOeyjPNy2G6jJ4yqH | ||
10 | ovXYt/0mc00vCWeSNS1wren0pR2EiLxX0ypjjgsU1mk/Z3b/+zVf7fZSIB+nDLjb | ||
11 | NPtUlJCVGnAeBK1J1nG3TQicqowOXoM6ISkdaXj5GPJdXHab2+S7cqhKGv5qC7rR | ||
12 | jT6sx7RUr0CNTxzLI7muV2/a4tGmj0PSdXQdsZ7tw7gbXlaWT1+MM2MCAQI= | ||
13 | -----END DH PARAMETERS----- | ||
14 | |||
diff --git a/src/lib/libcrypto/dh/dh512.pem b/src/lib/libcrypto/dh/dh512.pem new file mode 100644 index 0000000000..0a4d863ebe --- /dev/null +++ b/src/lib/libcrypto/dh/dh512.pem | |||
@@ -0,0 +1,4 @@ | |||
1 | -----BEGIN DH PARAMETERS----- | ||
2 | MEYCQQDaWDwW2YUiidDkr3VvTMqS3UvlM7gE+w/tlO+cikQD7VdGUNNpmdsp13Yn | ||
3 | a6LT1BLiGPTdHghM9tgAPnxHdOgzAgEC | ||
4 | -----END DH PARAMETERS----- | ||
diff --git a/src/lib/libcrypto/dh/dhtest.c b/src/lib/libcrypto/dh/dhtest.c new file mode 100644 index 0000000000..488f10fd41 --- /dev/null +++ b/src/lib/libcrypto/dh/dhtest.c | |||
@@ -0,0 +1,188 @@ | |||
1 | /* crypto/dh/dhtest.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 <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #ifdef WINDOWS | ||
63 | #include "../bio/bss_file.c" | ||
64 | #endif | ||
65 | #include "crypto.h" | ||
66 | #include "bio.h" | ||
67 | #include "bn.h" | ||
68 | #include "dh.h" | ||
69 | |||
70 | #ifdef WIN16 | ||
71 | #define MS_CALLBACK _far _loadds | ||
72 | #else | ||
73 | #define MS_CALLBACK | ||
74 | #endif | ||
75 | |||
76 | #ifndef NOPROTO | ||
77 | static void MS_CALLBACK cb(int p, int n, char *arg); | ||
78 | #else | ||
79 | static void MS_CALLBACK cb(); | ||
80 | #endif | ||
81 | |||
82 | #ifdef NO_STDIO | ||
83 | #define APPS_WIN16 | ||
84 | #include "bss_file.c" | ||
85 | #endif | ||
86 | |||
87 | BIO *out=NULL; | ||
88 | |||
89 | int main(argc,argv) | ||
90 | int argc; | ||
91 | char *argv[]; | ||
92 | { | ||
93 | DH *a,*b; | ||
94 | char buf[12]; | ||
95 | unsigned char *abuf=NULL,*bbuf=NULL; | ||
96 | int i,alen,blen,aout,bout,ret=1; | ||
97 | |||
98 | #ifdef WIN32 | ||
99 | CRYPTO_malloc_init(); | ||
100 | #endif | ||
101 | |||
102 | out=BIO_new(BIO_s_file()); | ||
103 | if (out == NULL) exit(1); | ||
104 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | ||
105 | |||
106 | a=DH_generate_parameters(64,DH_GENERATOR_5,cb,(char *)out); | ||
107 | if (a == NULL) goto err; | ||
108 | |||
109 | BIO_puts(out,"\np ="); | ||
110 | BN_print(out,a->p); | ||
111 | BIO_puts(out,"\ng ="); | ||
112 | BN_print(out,a->g); | ||
113 | BIO_puts(out,"\n"); | ||
114 | |||
115 | b=DH_new(); | ||
116 | if (b == NULL) goto err; | ||
117 | |||
118 | b->p=BN_dup(a->p); | ||
119 | b->g=BN_dup(a->g); | ||
120 | if ((b->p == NULL) || (b->g == NULL)) goto err; | ||
121 | |||
122 | if (!DH_generate_key(a)) goto err; | ||
123 | BIO_puts(out,"pri 1="); | ||
124 | BN_print(out,a->priv_key); | ||
125 | BIO_puts(out,"\npub 1="); | ||
126 | BN_print(out,a->pub_key); | ||
127 | BIO_puts(out,"\n"); | ||
128 | |||
129 | if (!DH_generate_key(b)) goto err; | ||
130 | BIO_puts(out,"pri 2="); | ||
131 | BN_print(out,b->priv_key); | ||
132 | BIO_puts(out,"\npub 2="); | ||
133 | BN_print(out,b->pub_key); | ||
134 | BIO_puts(out,"\n"); | ||
135 | |||
136 | alen=DH_size(a); | ||
137 | abuf=(unsigned char *)Malloc(alen); | ||
138 | aout=DH_compute_key(abuf,b->pub_key,a); | ||
139 | |||
140 | BIO_puts(out,"key1 ="); | ||
141 | for (i=0; i<aout; i++) | ||
142 | { | ||
143 | sprintf(buf,"%02X",abuf[i]); | ||
144 | BIO_puts(out,buf); | ||
145 | } | ||
146 | BIO_puts(out,"\n"); | ||
147 | |||
148 | blen=DH_size(b); | ||
149 | bbuf=(unsigned char *)Malloc(blen); | ||
150 | bout=DH_compute_key(bbuf,a->pub_key,b); | ||
151 | |||
152 | BIO_puts(out,"key2 ="); | ||
153 | for (i=0; i<bout; i++) | ||
154 | { | ||
155 | sprintf(buf,"%02X",bbuf[i]); | ||
156 | BIO_puts(out,buf); | ||
157 | } | ||
158 | BIO_puts(out,"\n"); | ||
159 | if ((aout < 4) || (bout != aout) || (memcmp(abuf,bbuf,aout) != 0)) | ||
160 | { | ||
161 | fprintf(stderr,"Error in DH routines\n"); | ||
162 | ret=1; | ||
163 | } | ||
164 | else | ||
165 | ret=0; | ||
166 | err: | ||
167 | if (abuf != NULL) Free(abuf); | ||
168 | if (bbuf != NULL) Free(bbuf); | ||
169 | exit(ret); | ||
170 | return(ret); | ||
171 | } | ||
172 | |||
173 | static void MS_CALLBACK cb(p, n,arg) | ||
174 | int p; | ||
175 | int n; | ||
176 | char *arg; | ||
177 | { | ||
178 | char c='*'; | ||
179 | |||
180 | if (p == 0) c='.'; | ||
181 | if (p == 1) c='+'; | ||
182 | if (p == 2) c='*'; | ||
183 | if (p == 3) c='\n'; | ||
184 | BIO_write((BIO *)arg,&c,1); | ||
185 | #ifdef LINT | ||
186 | p=n; | ||
187 | #endif | ||
188 | } | ||
diff --git a/src/lib/libcrypto/dh/example b/src/lib/libcrypto/dh/example new file mode 100644 index 0000000000..16a33d2910 --- /dev/null +++ b/src/lib/libcrypto/dh/example | |||
@@ -0,0 +1,50 @@ | |||
1 | From owner-cypherpunks@toad.com Mon Sep 25 10:50:51 1995 | ||
2 | Received: from minbne.mincom.oz.au by orb.mincom.oz.au with SMTP id AA10562 | ||
3 | (5.65c/IDA-1.4.4 for eay); Wed, 27 Sep 1995 19:41:55 +1000 | ||
4 | Received: by minbne.mincom.oz.au id AA19958 | ||
5 | (5.65c/IDA-1.4.4 for eay@orb.mincom.oz.au); Wed, 27 Sep 1995 19:34:59 +1000 | ||
6 | Received: from relay3.UU.NET by bunyip.cc.uq.oz.au with SMTP (PP); | ||
7 | Wed, 27 Sep 1995 19:13:05 +1000 | ||
8 | Received: from toad.com by relay3.UU.NET with SMTP id QQzizb16156; | ||
9 | Wed, 27 Sep 1995 04:48:46 -0400 | ||
10 | Received: by toad.com id AA07905; Tue, 26 Sep 95 06:31:45 PDT | ||
11 | Received: from by toad.com id AB07851; Tue, 26 Sep 95 06:31:40 PDT | ||
12 | Received: from servo.qualcomm.com (servo.qualcomm.com [129.46.128.14]) | ||
13 | by cygnus.com (8.6.12/8.6.9) with ESMTP id RAA18442 | ||
14 | for <cypherpunks@toad.com>; Mon, 25 Sep 1995 17:52:47 -0700 | ||
15 | Received: (karn@localhost) by servo.qualcomm.com (8.6.12/QC-BSD-2.5.1) | ||
16 | id RAA14732; Mon, 25 Sep 1995 17:50:51 -0700 | ||
17 | Date: Mon, 25 Sep 1995 17:50:51 -0700 | ||
18 | From: Phil Karn <karn@qualcomm.com> | ||
19 | Message-Id: <199509260050.RAA14732@servo.qualcomm.com> | ||
20 | To: cypherpunks@toad.com, ipsec-dev@eit.com | ||
21 | Subject: Primality verification needed | ||
22 | Sender: owner-cypherpunks@toad.com | ||
23 | Precedence: bulk | ||
24 | Status: RO | ||
25 | X-Status: | ||
26 | |||
27 | Hi. I've generated a 2047-bit "strong" prime number that I would like to | ||
28 | use with Diffie-Hellman key exchange. I assert that not only is this number | ||
29 | 'p' prime, but so is (p-1)/2. | ||
30 | |||
31 | I've used the mpz_probab_prime() function in the Gnu Math Package (GMP) version | ||
32 | 1.3.2 to test this number. This function uses the Miller-Rabin primality test. | ||
33 | However, to increase my confidence that this number really is a strong prime, | ||
34 | I'd like to ask others to confirm it with other tests. Here's the number in hex: | ||
35 | |||
36 | 72a925f760b2f954ed287f1b0953f3e6aef92e456172f9fe86fdd8822241b9c9788fbc289982743e | ||
37 | fbcd2ccf062b242d7a567ba8bbb40d79bca7b8e0b6c05f835a5b938d985816bc648985adcff5402a | ||
38 | a76756b36c845a840a1d059ce02707e19cf47af0b5a882f32315c19d1b86a56c5389c5e9bee16b65 | ||
39 | fde7b1a8d74a7675de9b707d4c5a4633c0290c95ff30a605aeb7ae864ff48370f13cf01d49adb9f2 | ||
40 | 3d19a439f753ee7703cf342d87f431105c843c78ca4df639931f3458fae8a94d1687e99a76ed99d0 | ||
41 | ba87189f42fd31ad8262c54a8cf5914ae6c28c540d714a5f6087a171fb74f4814c6f968d72386ef3 | ||
42 | 56a05180c3bec7ddd5ef6fe76b1f717b | ||
43 | |||
44 | The generator, g, for this prime is 2. | ||
45 | |||
46 | Thanks! | ||
47 | |||
48 | Phil Karn | ||
49 | |||
50 | |||
diff --git a/src/lib/libcrypto/dh/generate b/src/lib/libcrypto/dh/generate new file mode 100644 index 0000000000..5d407231df --- /dev/null +++ b/src/lib/libcrypto/dh/generate | |||
@@ -0,0 +1,65 @@ | |||
1 | From: stewarts@ix.netcom.com (Bill Stewart) | ||
2 | Newsgroups: sci.crypt | ||
3 | Subject: Re: Diffie-Hellman key exchange | ||
4 | Date: Wed, 11 Oct 1995 23:08:28 GMT | ||
5 | Organization: Freelance Information Architect | ||
6 | Lines: 32 | ||
7 | Message-ID: <45hir2$7l8@ixnews7.ix.netcom.com> | ||
8 | References: <458rhn$76m$1@mhadf.production.compuserve.com> | ||
9 | NNTP-Posting-Host: ix-pl4-16.ix.netcom.com | ||
10 | X-NETCOM-Date: Wed Oct 11 4:09:22 PM PDT 1995 | ||
11 | X-Newsreader: Forte Free Agent 1.0.82 | ||
12 | |||
13 | Kent Briggs <72124.3234@CompuServe.COM> wrote: | ||
14 | |||
15 | >I have a copy of the 1976 IEEE article describing the | ||
16 | >Diffie-Hellman public key exchange algorithm: y=a^x mod q. I'm | ||
17 | >looking for sources that give examples of secure a,q pairs and | ||
18 | >possible some source code that I could examine. | ||
19 | |||
20 | q should be prime, and ideally should be a "strong prime", | ||
21 | which means it's of the form 2n+1 where n is also prime. | ||
22 | q also needs to be long enough to prevent the attacks LaMacchia and | ||
23 | Odlyzko described (some variant on a factoring attack which generates | ||
24 | a large pile of simultaneous equations and then solves them); | ||
25 | long enough is about the same size as factoring, so 512 bits may not | ||
26 | be secure enough for most applications. (The 192 bits used by | ||
27 | "secure NFS" was certainly not long enough.) | ||
28 | |||
29 | a should be a generator for q, which means it needs to be | ||
30 | relatively prime to q-1. Usually a small prime like 2, 3 or 5 will | ||
31 | work. | ||
32 | |||
33 | .... | ||
34 | |||
35 | Date: Tue, 26 Sep 1995 13:52:36 MST | ||
36 | From: "Richard Schroeppel" <rcs@cs.arizona.edu> | ||
37 | To: karn | ||
38 | Cc: ho@cs.arizona.edu | ||
39 | Subject: random large primes | ||
40 | |||
41 | Since your prime is really random, proving it is hard. | ||
42 | My personal limit on rigorously proved primes is ~350 digits. | ||
43 | If you really want a proof, we should talk to Francois Morain, | ||
44 | or the Australian group. | ||
45 | |||
46 | If you want 2 to be a generator (mod P), then you need it | ||
47 | to be a non-square. If (P-1)/2 is also prime, then | ||
48 | non-square == primitive-root for bases << P. | ||
49 | |||
50 | In the case at hand, this means 2 is a generator iff P = 11 (mod 24). | ||
51 | If you want this, you should restrict your sieve accordingly. | ||
52 | |||
53 | 3 is a generator iff P = 5 (mod 12). | ||
54 | |||
55 | 5 is a generator iff P = 3 or 7 (mod 10). | ||
56 | |||
57 | 2 is perfectly usable as a base even if it's a non-generator, since | ||
58 | it still covers half the space of possible residues. And an | ||
59 | eavesdropper can always determine the low-bit of your exponent for | ||
60 | a generator anyway. | ||
61 | |||
62 | Rich rcs@cs.arizona.edu | ||
63 | |||
64 | |||
65 | |||
diff --git a/src/lib/libcrypto/dh/p1024.c b/src/lib/libcrypto/dh/p1024.c new file mode 100644 index 0000000000..0c50c24cfb --- /dev/null +++ b/src/lib/libcrypto/dh/p1024.c | |||
@@ -0,0 +1,92 @@ | |||
1 | /* crypto/dh/p1024.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 "bn.h" | ||
61 | #include "asn1.h" | ||
62 | #include "dh.h" | ||
63 | #include "pem.h" | ||
64 | |||
65 | unsigned char data[]={0x97,0xF6,0x42,0x61,0xCA,0xB5,0x05,0xDD, | ||
66 | 0x28,0x28,0xE1,0x3F,0x1D,0x68,0xB6,0xD3, | ||
67 | 0xDB,0xD0,0xF3,0x13,0x04,0x7F,0x40,0xE8, | ||
68 | 0x56,0xDA,0x58,0xCB,0x13,0xB8,0xA1,0xBF, | ||
69 | 0x2B,0x78,0x3A,0x4C,0x6D,0x59,0xD5,0xF9, | ||
70 | 0x2A,0xFC,0x6C,0xFF,0x3D,0x69,0x3F,0x78, | ||
71 | 0xB2,0x3D,0x4F,0x31,0x60,0xA9,0x50,0x2E, | ||
72 | 0x3E,0xFA,0xF7,0xAB,0x5E,0x1A,0xD5,0xA6, | ||
73 | 0x5E,0x55,0x43,0x13,0x82,0x8D,0xA8,0x3B, | ||
74 | 0x9F,0xF2,0xD9,0x41,0xDE,0xE9,0x56,0x89, | ||
75 | 0xFA,0xDA,0xEA,0x09,0x36,0xAD,0xDF,0x19, | ||
76 | 0x71,0xFE,0x63,0x5B,0x20,0xAF,0x47,0x03, | ||
77 | 0x64,0x60,0x3C,0x2D,0xE0,0x59,0xF5,0x4B, | ||
78 | 0x65,0x0A,0xD8,0xFA,0x0C,0xF7,0x01,0x21, | ||
79 | 0xC7,0x47,0x99,0xD7,0x58,0x71,0x32,0xBE, | ||
80 | 0x9B,0x99,0x9B,0xB9,0xB7,0x87,0xE8,0xAB, | ||
81 | }; | ||
82 | |||
83 | main() | ||
84 | { | ||
85 | DH *dh; | ||
86 | |||
87 | dh=DH_new(); | ||
88 | dh->p=BN_bin2bn(data,sizeof(data),NULL); | ||
89 | dh->g=BN_new(); | ||
90 | BN_set_word(dh->g,2); | ||
91 | PEM_write_DHparams(stdout,dh); | ||
92 | } | ||
diff --git a/src/lib/libcrypto/dh/p192.c b/src/lib/libcrypto/dh/p192.c new file mode 100644 index 0000000000..881908169a --- /dev/null +++ b/src/lib/libcrypto/dh/p192.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /* crypto/dh/p192.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 "bn.h" | ||
61 | #include "asn1.h" | ||
62 | #include "dh.h" | ||
63 | #include "pem.h" | ||
64 | |||
65 | unsigned char data[]={ | ||
66 | 0xD4,0xA0,0xBA,0x02,0x50,0xB6,0xFD,0x2E, | ||
67 | 0xC6,0x26,0xE7,0xEF,0xD6,0x37,0xDF,0x76, | ||
68 | 0xC7,0x16,0xE2,0x2D,0x09,0x44,0xB8,0x8B, | ||
69 | }; | ||
70 | |||
71 | main() | ||
72 | { | ||
73 | DH *dh; | ||
74 | |||
75 | dh=DH_new(); | ||
76 | dh->p=BN_bin2bn(data,sizeof(data),NULL); | ||
77 | dh->g=BN_new(); | ||
78 | BN_set_word(dh->g,3); | ||
79 | PEM_write_DHparams(stdout,dh); | ||
80 | } | ||
diff --git a/src/lib/libcrypto/dh/p512.c b/src/lib/libcrypto/dh/p512.c new file mode 100644 index 0000000000..cc84e8e50e --- /dev/null +++ b/src/lib/libcrypto/dh/p512.c | |||
@@ -0,0 +1,85 @@ | |||
1 | /* crypto/dh/p512.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 "bn.h" | ||
61 | #include "asn1.h" | ||
62 | #include "dh.h" | ||
63 | #include "pem.h" | ||
64 | |||
65 | unsigned char data[]={ | ||
66 | 0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89, | ||
67 | 0xD0,0xE4,0xAF,0x75,0x6F,0x4C,0xCA,0x92, | ||
68 | 0xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F, | ||
69 | 0xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED, | ||
70 | 0x57,0x46,0x50,0xD3,0x69,0x99,0xDB,0x29, | ||
71 | 0xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12, | ||
72 | 0xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6, | ||
73 | 0xD8,0x00,0x3E,0x7C,0x47,0x74,0xE8,0x33, | ||
74 | }; | ||
75 | |||
76 | main() | ||
77 | { | ||
78 | DH *dh; | ||
79 | |||
80 | dh=DH_new(); | ||
81 | dh->p=BN_bin2bn(data,sizeof(data),NULL); | ||
82 | dh->g=BN_new(); | ||
83 | BN_set_word(dh->g,2); | ||
84 | PEM_write_DHparams(stdout,dh); | ||
85 | } | ||
diff --git a/src/lib/libcrypto/dsa/README b/src/lib/libcrypto/dsa/README new file mode 100644 index 0000000000..6a7e9c170a --- /dev/null +++ b/src/lib/libcrypto/dsa/README | |||
@@ -0,0 +1,4 @@ | |||
1 | The stuff in here is based on patches supplied to me by | ||
2 | Steven Schoch <schoch@sheba.arc.nasa.gov> to do DSS. | ||
3 | I have since modified a them a little but a debt of gratitude | ||
4 | is due for doing the initial work. | ||
diff --git a/src/lib/libcrypto/dsa/dsagen.c b/src/lib/libcrypto/dsa/dsagen.c new file mode 100644 index 0000000000..20335de250 --- /dev/null +++ b/src/lib/libcrypto/dsa/dsagen.c | |||
@@ -0,0 +1,112 @@ | |||
1 | /* crypto/dsa/dsagen.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 "dsa.h" | ||
61 | |||
62 | #define TEST | ||
63 | #define GENUINE_DSA | ||
64 | |||
65 | #ifdef GENUINE_DSA | ||
66 | #define LAST_VALUE 0xbd | ||
67 | #else | ||
68 | #define LAST_VALUE 0xd3 | ||
69 | #endif | ||
70 | |||
71 | #ifdef TEST | ||
72 | unsigned char seed[20]={ | ||
73 | 0xd5,0x01,0x4e,0x4b, | ||
74 | 0x60,0xef,0x2b,0xa8, | ||
75 | 0xb6,0x21,0x1b,0x40, | ||
76 | 0x62,0xba,0x32,0x24, | ||
77 | 0xe0,0x42,0x7d,LAST_VALUE}; | ||
78 | #endif | ||
79 | |||
80 | int cb(p,n) | ||
81 | int p,n; | ||
82 | { | ||
83 | char c='*'; | ||
84 | |||
85 | if (p == 0) c='.'; | ||
86 | if (p == 1) c='+'; | ||
87 | if (p == 2) c='*'; | ||
88 | if (p == 3) c='\n'; | ||
89 | printf("%c",c); | ||
90 | fflush(stdout); | ||
91 | } | ||
92 | |||
93 | main() | ||
94 | { | ||
95 | int i; | ||
96 | BIGNUM *n; | ||
97 | BN_CTX *ctx; | ||
98 | unsigned char seed_buf[20]; | ||
99 | DSA *dsa; | ||
100 | int counter,h; | ||
101 | BIO *bio_err=NULL; | ||
102 | |||
103 | if (bio_err == NULL) | ||
104 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); | ||
105 | |||
106 | memcpy(seed_buf,seed,20); | ||
107 | dsa=DSA_generate_parameters(1024,seed,20,&counter,&h,cb); | ||
108 | |||
109 | if (dsa == NULL) | ||
110 | DSA_print(bio_err,dsa,0); | ||
111 | } | ||
112 | |||
diff --git a/src/lib/libcrypto/dsa/dsatest.c b/src/lib/libcrypto/dsa/dsatest.c new file mode 100644 index 0000000000..39bb712c4a --- /dev/null +++ b/src/lib/libcrypto/dsa/dsatest.c | |||
@@ -0,0 +1,214 @@ | |||
1 | /* crypto/dsa/dsatest.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 <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #include <sys/types.h> | ||
63 | #include <sys/stat.h> | ||
64 | #include "crypto.h" | ||
65 | #include "rand.h" | ||
66 | #include "bio.h" | ||
67 | #include "err.h" | ||
68 | #include "dsa.h" | ||
69 | #ifdef WINDOWS | ||
70 | #include "../bio/bss_file.c" | ||
71 | #endif | ||
72 | |||
73 | #ifdef WIN16 | ||
74 | #define MS_CALLBACK _far _loadds | ||
75 | #else | ||
76 | #define MS_CALLBACK | ||
77 | #endif | ||
78 | |||
79 | #ifndef NOPROTO | ||
80 | static void MS_CALLBACK dsa_cb(int p, int n, char *arg); | ||
81 | #else | ||
82 | static void MS_CALLBACK dsa_cb(); | ||
83 | #endif | ||
84 | |||
85 | static unsigned char seed[20]={ | ||
86 | 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, | ||
87 | 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, | ||
88 | }; | ||
89 | |||
90 | static unsigned char out_p[]={ | ||
91 | 0x8d,0xf2,0xa4,0x94,0x49,0x22,0x76,0xaa, | ||
92 | 0x3d,0x25,0x75,0x9b,0xb0,0x68,0x69,0xcb, | ||
93 | 0xea,0xc0,0xd8,0x3a,0xfb,0x8d,0x0c,0xf7, | ||
94 | 0xcb,0xb8,0x32,0x4f,0x0d,0x78,0x82,0xe5, | ||
95 | 0xd0,0x76,0x2f,0xc5,0xb7,0x21,0x0e,0xaf, | ||
96 | 0xc2,0xe9,0xad,0xac,0x32,0xab,0x7a,0xac, | ||
97 | 0x49,0x69,0x3d,0xfb,0xf8,0x37,0x24,0xc2, | ||
98 | 0xec,0x07,0x36,0xee,0x31,0xc8,0x02,0x91, | ||
99 | }; | ||
100 | |||
101 | static unsigned char out_q[]={ | ||
102 | 0xc7,0x73,0x21,0x8c,0x73,0x7e,0xc8,0xee, | ||
103 | 0x99,0x3b,0x4f,0x2d,0xed,0x30,0xf4,0x8e, | ||
104 | 0xda,0xce,0x91,0x5f, | ||
105 | }; | ||
106 | |||
107 | static unsigned char out_g[]={ | ||
108 | 0x62,0x6d,0x02,0x78,0x39,0xea,0x0a,0x13, | ||
109 | 0x41,0x31,0x63,0xa5,0x5b,0x4c,0xb5,0x00, | ||
110 | 0x29,0x9d,0x55,0x22,0x95,0x6c,0xef,0xcb, | ||
111 | 0x3b,0xff,0x10,0xf3,0x99,0xce,0x2c,0x2e, | ||
112 | 0x71,0xcb,0x9d,0xe5,0xfa,0x24,0xba,0xbf, | ||
113 | 0x58,0xe5,0xb7,0x95,0x21,0x92,0x5c,0x9c, | ||
114 | 0xc4,0x2e,0x9f,0x6f,0x46,0x4b,0x08,0x8c, | ||
115 | 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02, | ||
116 | }; | ||
117 | |||
118 | static BIO *bio_err=NULL; | ||
119 | |||
120 | int main(argc, argv) | ||
121 | int argc; | ||
122 | char **argv; | ||
123 | { | ||
124 | DSA *dsa=NULL; | ||
125 | int counter,ret=0,i,j; | ||
126 | unsigned char buf[256]; | ||
127 | unsigned long h; | ||
128 | |||
129 | if (bio_err == NULL) | ||
130 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); | ||
131 | |||
132 | BIO_printf(bio_err,"test generation of DSA parameters\n"); | ||
133 | BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n"); | ||
134 | dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb, | ||
135 | (char *)bio_err); | ||
136 | |||
137 | BIO_printf(bio_err,"seed\n"); | ||
138 | for (i=0; i<20; i+=4) | ||
139 | { | ||
140 | BIO_printf(bio_err,"%02X%02X%02X%02X ", | ||
141 | seed[i],seed[i+1],seed[i+2],seed[i+3]); | ||
142 | } | ||
143 | BIO_printf(bio_err,"\ncounter=%d h=%d\n",counter,h); | ||
144 | |||
145 | if (dsa == NULL) goto end; | ||
146 | DSA_print(bio_err,dsa,0); | ||
147 | if (counter != 105) | ||
148 | { | ||
149 | BIO_printf(bio_err,"counter should be 105\n"); | ||
150 | goto end; | ||
151 | } | ||
152 | if (h != 2) | ||
153 | { | ||
154 | BIO_printf(bio_err,"h should be 2\n"); | ||
155 | goto end; | ||
156 | } | ||
157 | |||
158 | i=BN_bn2bin(dsa->q,buf); | ||
159 | j=sizeof(out_q); | ||
160 | if ((i != j) || (memcmp(buf,out_q,i) != 0)) | ||
161 | { | ||
162 | BIO_printf(bio_err,"q value is wrong\n"); | ||
163 | goto end; | ||
164 | } | ||
165 | |||
166 | i=BN_bn2bin(dsa->p,buf); | ||
167 | j=sizeof(out_p); | ||
168 | if ((i != j) || (memcmp(buf,out_p,i) != 0)) | ||
169 | { | ||
170 | BIO_printf(bio_err,"p value is wrong\n"); | ||
171 | goto end; | ||
172 | } | ||
173 | |||
174 | i=BN_bn2bin(dsa->g,buf); | ||
175 | j=sizeof(out_g); | ||
176 | if ((i != j) || (memcmp(buf,out_g,i) != 0)) | ||
177 | { | ||
178 | BIO_printf(bio_err,"g value is wrong\n"); | ||
179 | goto end; | ||
180 | } | ||
181 | |||
182 | ret=1; | ||
183 | end: | ||
184 | if (!ret) | ||
185 | ERR_print_errors(bio_err); | ||
186 | if (bio_err != NULL) BIO_free(bio_err); | ||
187 | if (dsa != NULL) DSA_free(dsa); | ||
188 | exit(!ret); | ||
189 | return(0); | ||
190 | } | ||
191 | |||
192 | static void MS_CALLBACK dsa_cb(p, n, arg) | ||
193 | int p; | ||
194 | int n; | ||
195 | char *arg; | ||
196 | { | ||
197 | char c='*'; | ||
198 | static int ok=0,num=0; | ||
199 | |||
200 | if (p == 0) { c='.'; num++; }; | ||
201 | if (p == 1) c='+'; | ||
202 | if (p == 2) { c='*'; ok++; } | ||
203 | if (p == 3) c='\n'; | ||
204 | BIO_write((BIO *)arg,&c,1); | ||
205 | BIO_flush((BIO *)arg); | ||
206 | |||
207 | if (!ok && (p == 0) && (num > 1)) | ||
208 | { | ||
209 | BIO_printf((BIO *)arg,"error in dsatest\n"); | ||
210 | exit(1); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | |||
diff --git a/src/lib/libcrypto/dsa/fips186a.txt b/src/lib/libcrypto/dsa/fips186a.txt new file mode 100644 index 0000000000..3a2e0a0d51 --- /dev/null +++ b/src/lib/libcrypto/dsa/fips186a.txt | |||
@@ -0,0 +1,122 @@ | |||
1 | The origional FIPE 180 used SHA-0 (FIPS 180) for its appendix 5 | ||
2 | examples. This is an updated version that uses SHA-1 (FIPS 180-1) | ||
3 | supplied to me by Wei Dai | ||
4 | -- | ||
5 | APPENDIX 5. EXAMPLE OF THE DSA | ||
6 | |||
7 | |||
8 | This appendix is for informational purposes only and is not required to meet | ||
9 | the standard. | ||
10 | |||
11 | Let L = 512 (size of p). The values in this example are expressed in | ||
12 | hexadecimal notation. The p and q given here were generated by the prime | ||
13 | generation standard described in appendix 2 using the 160-bit SEED: | ||
14 | |||
15 | d5014e4b 60ef2ba8 b6211b40 62ba3224 e0427dd3 | ||
16 | |||
17 | With this SEED, the algorithm found p and q when the counter was at 105. | ||
18 | |||
19 | x was generated by the algorithm described in appendix 3, section 3.1, using | ||
20 | the SHA to construct G (as in appendix 3, section 3.3) and a 160-bit XSEED: | ||
21 | |||
22 | XSEED = | ||
23 | |||
24 | bd029bbe 7f51960b cf9edb2b 61f06f0f eb5a38b6 | ||
25 | |||
26 | t = | ||
27 | 67452301 EFCDAB89 98BADCFE 10325476 C3D2E1F0 | ||
28 | |||
29 | x = G(t,XSEED) mod q | ||
30 | |||
31 | k was generated by the algorithm described in appendix 3, section 3.2, using | ||
32 | the SHA to construct G (as in appendix 3, section 3.3) and a 160-bit KSEED: | ||
33 | |||
34 | KSEED = | ||
35 | |||
36 | 687a66d9 0648f993 867e121f 4ddf9ddb 01205584 | ||
37 | |||
38 | t = | ||
39 | EFCDAB89 98BADCFE 10325476 C3D2E1F0 67452301 | ||
40 | |||
41 | k = G(t,KSEED) mod q | ||
42 | |||
43 | Finally: | ||
44 | |||
45 | h = 2 | ||
46 | |||
47 | p = | ||
48 | 8df2a494 492276aa 3d25759b b06869cb eac0d83a fb8d0cf7 | ||
49 | cbb8324f 0d7882e5 d0762fc5 b7210eaf c2e9adac 32ab7aac | ||
50 | 49693dfb f83724c2 ec0736ee 31c80291 | ||
51 | |||
52 | |||
53 | q = | ||
54 | c773218c 737ec8ee 993b4f2d ed30f48e dace915f | ||
55 | |||
56 | |||
57 | g = | ||
58 | 626d0278 39ea0a13 413163a5 5b4cb500 299d5522 956cefcb | ||
59 | 3bff10f3 99ce2c2e 71cb9de5 fa24babf 58e5b795 21925c9c | ||
60 | c42e9f6f 464b088c c572af53 e6d78802 | ||
61 | |||
62 | |||
63 | x = | ||
64 | 2070b322 3dba372f de1c0ffc 7b2e3b49 8b260614 | ||
65 | |||
66 | |||
67 | k = | ||
68 | 358dad57 1462710f 50e254cf 1a376b2b deaadfbf | ||
69 | |||
70 | |||
71 | kinv = | ||
72 | |||
73 | 0d516729 8202e49b 4116ac10 4fc3f415 ae52f917 | ||
74 | |||
75 | M = ASCII form of "abc" (See FIPS PUB 180-1, Appendix A) | ||
76 | |||
77 | SHA(M) = | ||
78 | |||
79 | a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d | ||
80 | |||
81 | |||
82 | y = | ||
83 | |||
84 | 19131871 d75b1612 a819f29d 78d1b0d7 346f7aa7 7bb62a85 | ||
85 | 9bfd6c56 75da9d21 2d3a36ef 1672ef66 0b8c7c25 5cc0ec74 | ||
86 | 858fba33 f44c0669 9630a76b 030ee333 | ||
87 | |||
88 | |||
89 | r = | ||
90 | 8bac1ab6 6410435c b7181f95 b16ab97c 92b341c0 | ||
91 | |||
92 | s = | ||
93 | 41e2345f 1f56df24 58f426d1 55b4ba2d b6dcd8c8 | ||
94 | |||
95 | |||
96 | w = | ||
97 | 9df4ece5 826be95f ed406d41 b43edc0b 1c18841b | ||
98 | |||
99 | |||
100 | u1 = | ||
101 | bf655bd0 46f0b35e c791b004 804afcbb 8ef7d69d | ||
102 | |||
103 | |||
104 | u2 = | ||
105 | 821a9263 12e97ade abcc8d08 2b527897 8a2df4b0 | ||
106 | |||
107 | |||
108 | gu1 mod p = | ||
109 | |||
110 | 51b1bf86 7888e5f3 af6fb476 9dd016bc fe667a65 aafc2753 | ||
111 | 9063bd3d 2b138b4c e02cc0c0 2ec62bb6 7306c63e 4db95bbf | ||
112 | 6f96662a 1987a21b e4ec1071 010b6069 | ||
113 | |||
114 | |||
115 | yu2 mod p = | ||
116 | |||
117 | 8b510071 2957e950 50d6b8fd 376a668e 4b0d633c 1e46e665 | ||
118 | 5c611a72 e2b28483 be52c74d 4b30de61 a668966e dc307a67 | ||
119 | c19441f4 22bf3c34 08aeba1f 0a4dbec7 | ||
120 | |||
121 | v = | ||
122 | 8bac1ab6 6410435c b7181f95 b16ab97c 92b341c0 | ||
diff --git a/src/lib/libcrypto/evp/e_dsa.c b/src/lib/libcrypto/evp/e_dsa.c new file mode 100644 index 0000000000..6715c3e95e --- /dev/null +++ b/src/lib/libcrypto/evp/e_dsa.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* crypto/evp/e_dsa.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | static EVP_PKEY_METHOD dss_method= | ||
66 | { | ||
67 | DSA_sign, | ||
68 | DSA_verify, | ||
69 | {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3,NULL}, | ||
70 | }; | ||
71 | |||
diff --git a/src/lib/libcrypto/evp/m_md2.c b/src/lib/libcrypto/evp/m_md2.c new file mode 100644 index 0000000000..2209416142 --- /dev/null +++ b/src/lib/libcrypto/evp/m_md2.c | |||
@@ -0,0 +1,82 @@ | |||
1 | /* crypto/evp/m_md2.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | static EVP_MD md2_md= | ||
66 | { | ||
67 | NID_md2, | ||
68 | NID_md2WithRSAEncryption, | ||
69 | MD2_DIGEST_LENGTH, | ||
70 | MD2_Init, | ||
71 | MD2_Update, | ||
72 | MD2_Final, | ||
73 | EVP_PKEY_RSA_method, | ||
74 | MD2_BLOCK, | ||
75 | sizeof(EVP_MD *)+sizeof(MD2_CTX), | ||
76 | }; | ||
77 | |||
78 | EVP_MD *EVP_md2() | ||
79 | { | ||
80 | return(&md2_md); | ||
81 | } | ||
82 | |||
diff --git a/src/lib/libcrypto/evp/m_mdc2.c b/src/lib/libcrypto/evp/m_mdc2.c new file mode 100644 index 0000000000..64a853eb7f --- /dev/null +++ b/src/lib/libcrypto/evp/m_mdc2.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /* crypto/evp/m_mdc2.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | static EVP_MD mdc2_md= | ||
66 | { | ||
67 | NID_mdc2, | ||
68 | NID_mdc2WithRSA, | ||
69 | MDC2_DIGEST_LENGTH, | ||
70 | MDC2_Init, | ||
71 | MDC2_Update, | ||
72 | MDC2_Final, | ||
73 | EVP_PKEY_RSA_ASN1_OCTET_STRING_method, | ||
74 | MDC2_BLOCK, | ||
75 | sizeof(EVP_MD *)+sizeof(MDC2_CTX), | ||
76 | }; | ||
77 | |||
78 | EVP_MD *EVP_mdc2() | ||
79 | { | ||
80 | return(&mdc2_md); | ||
81 | } | ||
diff --git a/src/lib/libcrypto/evp/m_sha.c b/src/lib/libcrypto/evp/m_sha.c new file mode 100644 index 0000000000..af4e434a22 --- /dev/null +++ b/src/lib/libcrypto/evp/m_sha.c | |||
@@ -0,0 +1,82 @@ | |||
1 | /* crypto/evp/m_sha.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "objects.h" | ||
63 | #include "x509.h" | ||
64 | |||
65 | static EVP_MD sha_md= | ||
66 | { | ||
67 | NID_sha, | ||
68 | NID_shaWithRSAEncryption, | ||
69 | SHA_DIGEST_LENGTH, | ||
70 | SHA_Init, | ||
71 | SHA_Update, | ||
72 | SHA_Final, | ||
73 | EVP_PKEY_RSA_method, | ||
74 | SHA_CBLOCK, | ||
75 | sizeof(EVP_MD *)+sizeof(SHA_CTX), | ||
76 | }; | ||
77 | |||
78 | EVP_MD *EVP_sha() | ||
79 | { | ||
80 | return(&sha_md); | ||
81 | } | ||
82 | |||
diff --git a/src/lib/libcrypto/hmac/hmactest.c b/src/lib/libcrypto/hmac/hmactest.c new file mode 100644 index 0000000000..5938e375dc --- /dev/null +++ b/src/lib/libcrypto/hmac/hmactest.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /* crypto/hmac/hmactest.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 <string.h> | ||
61 | #include <stdlib.h> | ||
62 | #include "hmac.h" | ||
63 | |||
64 | struct test_st | ||
65 | { | ||
66 | unsigned char key[16]; | ||
67 | int key_len; | ||
68 | unsigned char data[64]; | ||
69 | int data_len; | ||
70 | unsigned char *digest; | ||
71 | } test[4]={ | ||
72 | { "", | ||
73 | 0, | ||
74 | "More text test vectors to stuff up EBCDIC machines :-)", | ||
75 | 54, | ||
76 | (unsigned char *)"e9139d1e6ee064ef8cf514fc7dc83e86", | ||
77 | },{ {0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b, | ||
78 | 0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,}, | ||
79 | 16, | ||
80 | "Hi There", | ||
81 | 8, | ||
82 | (unsigned char *)"9294727a3638bb1c13f48ef8158bfc9d", | ||
83 | },{ "Jefe", | ||
84 | 4, | ||
85 | "what do ya want for nothing?", | ||
86 | 28, | ||
87 | (unsigned char *)"750c783e6ab0b503eaa86e310a5db738", | ||
88 | },{ | ||
89 | {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa, | ||
90 | 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,}, | ||
91 | 16, | ||
92 | {0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
93 | 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
94 | 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
95 | 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
96 | 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
97 | 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
98 | 0xdd,0xdd}, | ||
99 | 50, | ||
100 | (unsigned char *)"56be34521d144c88dbb8c733f0e8b3f6", | ||
101 | }, | ||
102 | }; | ||
103 | |||
104 | |||
105 | #ifndef NOPROTO | ||
106 | static char *pt(unsigned char *md); | ||
107 | #else | ||
108 | static char *pt(); | ||
109 | #endif | ||
110 | |||
111 | int main(argc,argv) | ||
112 | int argc; | ||
113 | char *argv[]; | ||
114 | { | ||
115 | int i,err=0; | ||
116 | char *p; | ||
117 | |||
118 | for (i=0; i<4; i++) | ||
119 | { | ||
120 | p=pt(HMAC(EVP_md5(), | ||
121 | test[i].key, test[i].key_len, | ||
122 | test[i].data, test[i].data_len, | ||
123 | NULL,NULL)); | ||
124 | |||
125 | if (strcmp(p,(char *)test[i].digest) != 0) | ||
126 | { | ||
127 | printf("error calculating HMAC on %d entry'\n",i); | ||
128 | printf("got %s instead of %s\n",p,test[i].digest); | ||
129 | err++; | ||
130 | } | ||
131 | else | ||
132 | printf("test %d ok\n",i); | ||
133 | } | ||
134 | exit(err); | ||
135 | return(0); | ||
136 | } | ||
137 | |||
138 | static char *pt(md) | ||
139 | unsigned char *md; | ||
140 | { | ||
141 | int i; | ||
142 | static char buf[80]; | ||
143 | |||
144 | for (i=0; i<MD5_DIGEST_LENGTH; i++) | ||
145 | sprintf(&(buf[i*2]),"%02x",md[i]); | ||
146 | return(buf); | ||
147 | } | ||
diff --git a/src/lib/libcrypto/lhash/lh_test.c b/src/lib/libcrypto/lhash/lh_test.c new file mode 100644 index 0000000000..294b42bc82 --- /dev/null +++ b/src/lib/libcrypto/lhash/lh_test.c | |||
@@ -0,0 +1,89 @@ | |||
1 | /* crypto/lhash/lh_test.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 <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #include "lhash.h" | ||
63 | |||
64 | main() | ||
65 | { | ||
66 | LHASH *conf; | ||
67 | char buf[256]; | ||
68 | int i; | ||
69 | |||
70 | conf=lh_new(lh_strhash,strcmp); | ||
71 | for (;;) | ||
72 | { | ||
73 | char *p; | ||
74 | |||
75 | buf[0]='\0'; | ||
76 | fgets(buf,256,stdin); | ||
77 | if (buf[0] == '\0') break; | ||
78 | buf[256]='\0'; | ||
79 | i=strlen(buf); | ||
80 | p=Malloc(i+1); | ||
81 | memcpy(p,buf,i+1); | ||
82 | lh_insert(conf,p); | ||
83 | } | ||
84 | |||
85 | lh_node_stats(conf,stdout); | ||
86 | lh_stats(conf,stdout); | ||
87 | lh_node_usage_stats(conf,stdout); | ||
88 | exit(0); | ||
89 | } | ||
diff --git a/src/lib/libcrypto/lhash/num.pl b/src/lib/libcrypto/lhash/num.pl new file mode 100644 index 0000000000..4d937c1f90 --- /dev/null +++ b/src/lib/libcrypto/lhash/num.pl | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | #node 10 -> 4 | ||
4 | |||
5 | while (<>) | ||
6 | { | ||
7 | next unless /^node/; | ||
8 | chop; | ||
9 | @a=split; | ||
10 | $num{$a[3]}++; | ||
11 | } | ||
12 | |||
13 | @a=sort {$a <=> $b } keys %num; | ||
14 | foreach (0 .. $a[$#a]) | ||
15 | { | ||
16 | printf "%4d:%4d\n",$_,$num{$_}; | ||
17 | } | ||
diff --git a/src/lib/libcrypto/md2/md2.c b/src/lib/libcrypto/md2/md2.c new file mode 100644 index 0000000000..7f3ab64a43 --- /dev/null +++ b/src/lib/libcrypto/md2/md2.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /* crypto/md2/md2.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 <stdlib.h> | ||
61 | #include "md2.h" | ||
62 | |||
63 | #define BUFSIZE 1024*16 | ||
64 | |||
65 | #ifndef NOPROTO | ||
66 | void do_fp(FILE *f); | ||
67 | void pt(unsigned char *md); | ||
68 | int read(int, void *, unsigned int); | ||
69 | void exit(int); | ||
70 | #else | ||
71 | void do_fp(); | ||
72 | void pt(); | ||
73 | int read(); | ||
74 | void exit(); | ||
75 | #endif | ||
76 | |||
77 | int main(argc, argv) | ||
78 | int argc; | ||
79 | char *argv[]; | ||
80 | { | ||
81 | int i,err=0; | ||
82 | FILE *IN; | ||
83 | |||
84 | if (argc == 1) | ||
85 | { | ||
86 | do_fp(stdin); | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | for (i=1; i<argc; i++) | ||
91 | { | ||
92 | IN=fopen(argv[i],"r"); | ||
93 | if (IN == NULL) | ||
94 | { | ||
95 | perror(argv[i]); | ||
96 | err++; | ||
97 | continue; | ||
98 | } | ||
99 | printf("MD2(%s)= ",argv[i]); | ||
100 | do_fp(IN); | ||
101 | fclose(IN); | ||
102 | } | ||
103 | } | ||
104 | exit(err); | ||
105 | return(err); | ||
106 | } | ||
107 | |||
108 | void do_fp(f) | ||
109 | FILE *f; | ||
110 | { | ||
111 | MD2_CTX c; | ||
112 | unsigned char md[MD2_DIGEST_LENGTH]; | ||
113 | int fd,i; | ||
114 | static unsigned char buf[BUFSIZE]; | ||
115 | |||
116 | fd=fileno(f); | ||
117 | MD2_Init(&c); | ||
118 | for (;;) | ||
119 | { | ||
120 | i=read(fd,buf,BUFSIZE); | ||
121 | if (i <= 0) break; | ||
122 | MD2_Update(&c,buf,(unsigned long)i); | ||
123 | } | ||
124 | MD2_Final(&(md[0]),&c); | ||
125 | pt(md); | ||
126 | } | ||
127 | |||
128 | void pt(md) | ||
129 | unsigned char *md; | ||
130 | { | ||
131 | int i; | ||
132 | |||
133 | for (i=0; i<MD2_DIGEST_LENGTH; i++) | ||
134 | printf("%02x",md[i]); | ||
135 | printf("\n"); | ||
136 | } | ||
diff --git a/src/lib/libcrypto/md2/md2_dgst.c b/src/lib/libcrypto/md2/md2_dgst.c new file mode 100644 index 0000000000..5cbd36f3fe --- /dev/null +++ b/src/lib/libcrypto/md2/md2_dgst.c | |||
@@ -0,0 +1,235 @@ | |||
1 | /* crypto/md2/md2_dgst.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 <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #include "md2.h" | ||
63 | |||
64 | char *MD2_version="MD2 part of SSLeay 0.9.0b 29-Jun-1998"; | ||
65 | |||
66 | /* Implemented from RFC1319 The MD2 Message-Digest Algorithm | ||
67 | */ | ||
68 | |||
69 | #define UCHAR unsigned char | ||
70 | |||
71 | #ifndef NOPROTO | ||
72 | static void md2_block(MD2_CTX *c, unsigned char *d); | ||
73 | #else | ||
74 | static void md2_block(); | ||
75 | #endif | ||
76 | |||
77 | /* The magic S table - I have converted it to hex since it is | ||
78 | * basicaly just a random byte string. */ | ||
79 | static MD2_INT S[256]={ | ||
80 | 0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01, | ||
81 | 0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13, | ||
82 | 0x62, 0xA7, 0x05, 0xF3, 0xC0, 0xC7, 0x73, 0x8C, | ||
83 | 0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C, 0x82, 0xCA, | ||
84 | 0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16, | ||
85 | 0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12, | ||
86 | 0xBE, 0x4E, 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49, | ||
87 | 0xA0, 0xFB, 0xF5, 0x8E, 0xBB, 0x2F, 0xEE, 0x7A, | ||
88 | 0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2, 0x07, 0x3F, | ||
89 | 0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21, | ||
90 | 0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27, | ||
91 | 0x35, 0x3E, 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03, | ||
92 | 0xFF, 0x19, 0x30, 0xB3, 0x48, 0xA5, 0xB5, 0xD1, | ||
93 | 0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56, 0xAA, 0xC6, | ||
94 | 0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6, | ||
95 | 0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1, | ||
96 | 0x45, 0x9D, 0x70, 0x59, 0x64, 0x71, 0x87, 0x20, | ||
97 | 0x86, 0x5B, 0xCF, 0x65, 0xE6, 0x2D, 0xA8, 0x02, | ||
98 | 0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0, 0xB9, 0xF6, | ||
99 | 0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F, | ||
100 | 0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A, | ||
101 | 0xC3, 0x5C, 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26, | ||
102 | 0x2C, 0x53, 0x0D, 0x6E, 0x85, 0x28, 0x84, 0x09, | ||
103 | 0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81, 0x4D, 0x52, | ||
104 | 0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA, | ||
105 | 0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A, | ||
106 | 0x78, 0x88, 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D, | ||
107 | 0xE9, 0xCB, 0xD5, 0xFE, 0x3B, 0x00, 0x1D, 0x39, | ||
108 | 0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, 0xD0, 0xE4, | ||
109 | 0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A, | ||
110 | 0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A, | ||
111 | 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14, | ||
112 | }; | ||
113 | |||
114 | char *MD2_options() | ||
115 | { | ||
116 | if (sizeof(MD2_INT) == 1) | ||
117 | return("md2(char)"); | ||
118 | else | ||
119 | return("md2(int)"); | ||
120 | } | ||
121 | |||
122 | void MD2_Init(c) | ||
123 | MD2_CTX *c; | ||
124 | { | ||
125 | c->num=0; | ||
126 | memset(c->state,0,MD2_BLOCK*sizeof(MD2_INT)); | ||
127 | memset(c->cksm,0,MD2_BLOCK*sizeof(MD2_INT)); | ||
128 | memset(c->data,0,MD2_BLOCK); | ||
129 | } | ||
130 | |||
131 | void MD2_Update(c, data, len) | ||
132 | MD2_CTX *c; | ||
133 | register unsigned char *data; | ||
134 | unsigned long len; | ||
135 | { | ||
136 | register UCHAR *p; | ||
137 | |||
138 | if (len == 0) return; | ||
139 | |||
140 | p=c->data; | ||
141 | if (c->num != 0) | ||
142 | { | ||
143 | if ((c->num+len) >= MD2_BLOCK) | ||
144 | { | ||
145 | memcpy(&(p[c->num]),data,MD2_BLOCK-c->num); | ||
146 | md2_block(c,c->data); | ||
147 | data+=(MD2_BLOCK - c->num); | ||
148 | len-=(MD2_BLOCK - c->num); | ||
149 | c->num=0; | ||
150 | /* drop through and do the rest */ | ||
151 | } | ||
152 | else | ||
153 | { | ||
154 | memcpy(&(p[c->num]),data,(int)len); | ||
155 | /* data+=len; */ | ||
156 | c->num+=(int)len; | ||
157 | return; | ||
158 | } | ||
159 | } | ||
160 | /* we now can process the input data in blocks of MD2_BLOCK | ||
161 | * chars and save the leftovers to c->data. */ | ||
162 | while (len >= MD2_BLOCK) | ||
163 | { | ||
164 | md2_block(c,data); | ||
165 | data+=MD2_BLOCK; | ||
166 | len-=MD2_BLOCK; | ||
167 | } | ||
168 | memcpy(p,data,(int)len); | ||
169 | c->num=(int)len; | ||
170 | } | ||
171 | |||
172 | static void md2_block(c, d) | ||
173 | MD2_CTX *c; | ||
174 | unsigned char *d; | ||
175 | { | ||
176 | register MD2_INT t,*sp1,*sp2; | ||
177 | register int i,j; | ||
178 | MD2_INT state[48]; | ||
179 | |||
180 | sp1=c->state; | ||
181 | sp2=c->cksm; | ||
182 | j=sp2[MD2_BLOCK-1]; | ||
183 | for (i=0; i<16; i++) | ||
184 | { | ||
185 | state[i]=sp1[i]; | ||
186 | state[i+16]=t=d[i]; | ||
187 | state[i+32]=(t^sp1[i]); | ||
188 | j=sp2[i]^=S[t^j]; | ||
189 | } | ||
190 | t=0; | ||
191 | for (i=0; i<18; i++) | ||
192 | { | ||
193 | for (j=0; j<48; j+=8) | ||
194 | { | ||
195 | t= state[j+ 0]^=S[t]; | ||
196 | t= state[j+ 1]^=S[t]; | ||
197 | t= state[j+ 2]^=S[t]; | ||
198 | t= state[j+ 3]^=S[t]; | ||
199 | t= state[j+ 4]^=S[t]; | ||
200 | t= state[j+ 5]^=S[t]; | ||
201 | t= state[j+ 6]^=S[t]; | ||
202 | t= state[j+ 7]^=S[t]; | ||
203 | } | ||
204 | t=(t+i)&0xff; | ||
205 | } | ||
206 | memcpy(sp1,state,16*sizeof(MD2_INT)); | ||
207 | memset(state,0,48*sizeof(MD2_INT)); | ||
208 | } | ||
209 | |||
210 | void MD2_Final(md, c) | ||
211 | unsigned char *md; | ||
212 | MD2_CTX *c; | ||
213 | { | ||
214 | int i,v; | ||
215 | register UCHAR *cp; | ||
216 | register MD2_INT *p1,*p2; | ||
217 | |||
218 | cp=c->data; | ||
219 | p1=c->state; | ||
220 | p2=c->cksm; | ||
221 | v=MD2_BLOCK-c->num; | ||
222 | for (i=c->num; i<MD2_BLOCK; i++) | ||
223 | cp[i]=(UCHAR)v; | ||
224 | |||
225 | md2_block(c,cp); | ||
226 | |||
227 | for (i=0; i<MD2_BLOCK; i++) | ||
228 | cp[i]=(UCHAR)p2[i]; | ||
229 | md2_block(c,cp); | ||
230 | |||
231 | for (i=0; i<16; i++) | ||
232 | md[i]=(UCHAR)(p1[i]&0xff); | ||
233 | memset((char *)&c,0,sizeof(c)); | ||
234 | } | ||
235 | |||
diff --git a/src/lib/libcrypto/md2/md2_one.c b/src/lib/libcrypto/md2/md2_one.c new file mode 100644 index 0000000000..513bf62fdb --- /dev/null +++ b/src/lib/libcrypto/md2/md2_one.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /* crypto/md2/md2_one.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 "md2.h" | ||
62 | |||
63 | /* This is a separate file so that #defines in cryptlib.h can | ||
64 | * map my MD functions to different names */ | ||
65 | |||
66 | unsigned char *MD2(d, n, md) | ||
67 | unsigned char *d; | ||
68 | unsigned long n; | ||
69 | unsigned char *md; | ||
70 | { | ||
71 | MD2_CTX c; | ||
72 | static unsigned char m[MD2_DIGEST_LENGTH]; | ||
73 | |||
74 | if (md == NULL) md=m; | ||
75 | MD2_Init(&c); | ||
76 | MD2_Update(&c,d,n); | ||
77 | MD2_Final(md,&c); | ||
78 | memset(&c,0,sizeof(c)); /* Security consideration */ | ||
79 | return(md); | ||
80 | } | ||
diff --git a/src/lib/libcrypto/md2/md2test.c b/src/lib/libcrypto/md2/md2test.c new file mode 100644 index 0000000000..55924d44cd --- /dev/null +++ b/src/lib/libcrypto/md2/md2test.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /* crypto/md2/md2test.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 <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #include "md2.h" | ||
63 | |||
64 | char *test[]={ | ||
65 | "", | ||
66 | "a", | ||
67 | "abc", | ||
68 | "message digest", | ||
69 | "abcdefghijklmnopqrstuvwxyz", | ||
70 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | ||
71 | "12345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
72 | NULL, | ||
73 | }; | ||
74 | |||
75 | char *ret[]={ | ||
76 | "8350e5a3e24c153df2275c9f80692773", | ||
77 | "32ec01ec4a6dac72c0ab96fb34c0b5d1", | ||
78 | "da853b0d3f88d99b30283a69e6ded6bb", | ||
79 | "ab4f496bfb2a530b219ff33031fe06b0", | ||
80 | "4e8ddff3650292ab5a4108c3aa47940b", | ||
81 | "da33def2a42df13975352846c30338cd", | ||
82 | "d5976f79d83d3a0dc9806c3c66f3efd8", | ||
83 | }; | ||
84 | |||
85 | #ifndef NOPROTO | ||
86 | static char *pt(unsigned char *md); | ||
87 | #else | ||
88 | static char *pt(); | ||
89 | #endif | ||
90 | |||
91 | int main(argc,argv) | ||
92 | int argc; | ||
93 | char *argv[]; | ||
94 | { | ||
95 | int i,err=0; | ||
96 | char **P,**R; | ||
97 | char *p; | ||
98 | |||
99 | P=test; | ||
100 | R=ret; | ||
101 | i=1; | ||
102 | while (*P != NULL) | ||
103 | { | ||
104 | p=pt(MD2((unsigned char *)*P,(unsigned long)strlen(*P),NULL)); | ||
105 | if (strcmp(p,*R) != 0) | ||
106 | { | ||
107 | printf("error calculating MD2 on '%s'\n",*P); | ||
108 | printf("got %s instead of %s\n",p,*R); | ||
109 | err++; | ||
110 | } | ||
111 | else | ||
112 | printf("test %d ok\n",i); | ||
113 | i++; | ||
114 | R++; | ||
115 | P++; | ||
116 | } | ||
117 | exit(err); | ||
118 | return(0); | ||
119 | } | ||
120 | |||
121 | static char *pt(md) | ||
122 | unsigned char *md; | ||
123 | { | ||
124 | int i; | ||
125 | static char buf[80]; | ||
126 | |||
127 | for (i=0; i<MD2_DIGEST_LENGTH; i++) | ||
128 | sprintf(&(buf[i*2]),"%02x",md[i]); | ||
129 | return(buf); | ||
130 | } | ||
diff --git a/src/lib/libcrypto/md5/md5.c b/src/lib/libcrypto/md5/md5.c new file mode 100644 index 0000000000..9d6f5a6003 --- /dev/null +++ b/src/lib/libcrypto/md5/md5.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /* crypto/md5/md5.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <stdlib.h> | ||
61 | #include "md5.h" | ||
62 | |||
63 | #define BUFSIZE 1024*16 | ||
64 | |||
65 | #ifndef NOPROTO | ||
66 | void do_fp(FILE *f); | ||
67 | void pt(unsigned char *md); | ||
68 | int read(int, void *, unsigned int); | ||
69 | #else | ||
70 | void do_fp(); | ||
71 | void pt(); | ||
72 | int read(); | ||
73 | #endif | ||
74 | |||
75 | int main(argc, argv) | ||
76 | int argc; | ||
77 | char **argv; | ||
78 | { | ||
79 | int i,err=0; | ||
80 | FILE *IN; | ||
81 | |||
82 | if (argc == 1) | ||
83 | { | ||
84 | do_fp(stdin); | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | for (i=1; i<argc; i++) | ||
89 | { | ||
90 | IN=fopen(argv[i],"r"); | ||
91 | if (IN == NULL) | ||
92 | { | ||
93 | perror(argv[i]); | ||
94 | err++; | ||
95 | continue; | ||
96 | } | ||
97 | printf("MD5(%s)= ",argv[i]); | ||
98 | do_fp(IN); | ||
99 | fclose(IN); | ||
100 | } | ||
101 | } | ||
102 | exit(err); | ||
103 | } | ||
104 | |||
105 | void do_fp(f) | ||
106 | FILE *f; | ||
107 | { | ||
108 | MD5_CTX c; | ||
109 | unsigned char md[MD5_DIGEST_LENGTH]; | ||
110 | int fd; | ||
111 | int i; | ||
112 | static unsigned char buf[BUFSIZE]; | ||
113 | |||
114 | fd=fileno(f); | ||
115 | MD5_Init(&c); | ||
116 | for (;;) | ||
117 | { | ||
118 | i=read(fd,buf,BUFSIZE); | ||
119 | if (i <= 0) break; | ||
120 | MD5_Update(&c,buf,(unsigned long)i); | ||
121 | } | ||
122 | MD5_Final(&(md[0]),&c); | ||
123 | pt(md); | ||
124 | } | ||
125 | |||
126 | void pt(md) | ||
127 | unsigned char *md; | ||
128 | { | ||
129 | int i; | ||
130 | |||
131 | for (i=0; i<MD5_DIGEST_LENGTH; i++) | ||
132 | printf("%02x",md[i]); | ||
133 | printf("\n"); | ||
134 | } | ||
135 | |||
diff --git a/src/lib/libcrypto/md5/md5s.cpp b/src/lib/libcrypto/md5/md5s.cpp new file mode 100644 index 0000000000..ef8e175df0 --- /dev/null +++ b/src/lib/libcrypto/md5/md5s.cpp | |||
@@ -0,0 +1,78 @@ | |||
1 | // | ||
2 | // gettsc.inl | ||
3 | // | ||
4 | // gives access to the Pentium's (secret) cycle counter | ||
5 | // | ||
6 | // This software was written by Leonard Janke (janke@unixg.ubc.ca) | ||
7 | // in 1996-7 and is entered, by him, into the public domain. | ||
8 | |||
9 | #if defined(__WATCOMC__) | ||
10 | void GetTSC(unsigned long&); | ||
11 | #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; | ||
12 | #elif defined(__GNUC__) | ||
13 | inline | ||
14 | void GetTSC(unsigned long& tsc) | ||
15 | { | ||
16 | asm volatile(".byte 15, 49\n\t" | ||
17 | : "=eax" (tsc) | ||
18 | : | ||
19 | : "%edx", "%eax"); | ||
20 | } | ||
21 | #elif defined(_MSC_VER) | ||
22 | inline | ||
23 | void GetTSC(unsigned long& tsc) | ||
24 | { | ||
25 | unsigned long a; | ||
26 | __asm _emit 0fh | ||
27 | __asm _emit 31h | ||
28 | __asm mov a, eax; | ||
29 | tsc=a; | ||
30 | } | ||
31 | #endif | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include <stdlib.h> | ||
35 | #include "md5.h" | ||
36 | |||
37 | extern "C" { | ||
38 | void md5_block_x86(MD5_CTX *ctx, unsigned char *buffer,int num); | ||
39 | } | ||
40 | |||
41 | void main(int argc,char *argv[]) | ||
42 | { | ||
43 | unsigned char buffer[64*256]; | ||
44 | MD5_CTX ctx; | ||
45 | unsigned long s1,s2,e1,e2; | ||
46 | unsigned char k[16]; | ||
47 | unsigned long data[2]; | ||
48 | unsigned char iv[8]; | ||
49 | int i,num=0,numm; | ||
50 | int j=0; | ||
51 | |||
52 | if (argc >= 2) | ||
53 | num=atoi(argv[1]); | ||
54 | |||
55 | if (num == 0) num=16; | ||
56 | if (num > 250) num=16; | ||
57 | numm=num+2; | ||
58 | num*=64; | ||
59 | numm*=64; | ||
60 | |||
61 | for (j=0; j<6; j++) | ||
62 | { | ||
63 | for (i=0; i<10; i++) /**/ | ||
64 | { | ||
65 | md5_block_x86(&ctx,buffer,numm); | ||
66 | GetTSC(s1); | ||
67 | md5_block_x86(&ctx,buffer,numm); | ||
68 | GetTSC(e1); | ||
69 | GetTSC(s2); | ||
70 | md5_block_x86(&ctx,buffer,num); | ||
71 | GetTSC(e2); | ||
72 | md5_block_x86(&ctx,buffer,num); | ||
73 | } | ||
74 | printf("md5 (%d bytes) %d %d (%.2f)\n",num, | ||
75 | e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2); | ||
76 | } | ||
77 | } | ||
78 | |||
diff --git a/src/lib/libcrypto/md5/md5test.c b/src/lib/libcrypto/md5/md5test.c new file mode 100644 index 0000000000..74b84bc67f --- /dev/null +++ b/src/lib/libcrypto/md5/md5test.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /* crypto/md5/md5test.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 <string.h> | ||
61 | #include <stdlib.h> | ||
62 | #include "md5.h" | ||
63 | |||
64 | char *test[]={ | ||
65 | "", | ||
66 | "a", | ||
67 | "abc", | ||
68 | "message digest", | ||
69 | "abcdefghijklmnopqrstuvwxyz", | ||
70 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | ||
71 | "12345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
72 | NULL, | ||
73 | }; | ||
74 | |||
75 | char *ret[]={ | ||
76 | "d41d8cd98f00b204e9800998ecf8427e", | ||
77 | "0cc175b9c0f1b6a831c399e269772661", | ||
78 | "900150983cd24fb0d6963f7d28e17f72", | ||
79 | "f96b697d7cb7938d525a2f31aaf161d0", | ||
80 | "c3fcd3d76192e4007dfb496cca67e13b", | ||
81 | "d174ab98d277d9f5a5611c2c9f419d9f", | ||
82 | "57edf4a22be3c955ac49da2e2107b67a", | ||
83 | }; | ||
84 | |||
85 | #ifndef NOPROTO | ||
86 | static char *pt(unsigned char *md); | ||
87 | #else | ||
88 | static char *pt(); | ||
89 | #endif | ||
90 | |||
91 | int main(argc,argv) | ||
92 | int argc; | ||
93 | char *argv[]; | ||
94 | { | ||
95 | int i,err=0; | ||
96 | unsigned char **P,**R; | ||
97 | char *p; | ||
98 | |||
99 | P=(unsigned char **)test; | ||
100 | R=(unsigned char **)ret; | ||
101 | i=1; | ||
102 | while (*P != NULL) | ||
103 | { | ||
104 | p=pt(MD5(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL)); | ||
105 | if (strcmp(p,(char *)*R) != 0) | ||
106 | { | ||
107 | printf("error calculating MD5 on '%s'\n",*P); | ||
108 | printf("got %s instead of %s\n",p,*R); | ||
109 | err++; | ||
110 | } | ||
111 | else | ||
112 | printf("test %d ok\n",i); | ||
113 | i++; | ||
114 | R++; | ||
115 | P++; | ||
116 | } | ||
117 | exit(err); | ||
118 | return(0); | ||
119 | } | ||
120 | |||
121 | static char *pt(md) | ||
122 | unsigned char *md; | ||
123 | { | ||
124 | int i; | ||
125 | static char buf[80]; | ||
126 | |||
127 | for (i=0; i<MD5_DIGEST_LENGTH; i++) | ||
128 | sprintf(&(buf[i*2]),"%02x",md[i]); | ||
129 | return(buf); | ||
130 | } | ||
diff --git a/src/lib/libcrypto/mdc2/mdc2.h b/src/lib/libcrypto/mdc2/mdc2.h new file mode 100644 index 0000000000..0b104be184 --- /dev/null +++ b/src/lib/libcrypto/mdc2/mdc2.h | |||
@@ -0,0 +1,100 @@ | |||
1 | /* crypto/mdc2/mdc2.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_MDC2_H | ||
60 | #define HEADER_MDC2_H | ||
61 | |||
62 | #ifdef __cplusplus | ||
63 | extern "C" { | ||
64 | #endif | ||
65 | |||
66 | #include "des.h" | ||
67 | |||
68 | #define MDC2_BLOCK 8 | ||
69 | #define MDC2_DIGEST_LENGTH 16 | ||
70 | |||
71 | typedef struct mdc2_ctx_st | ||
72 | { | ||
73 | int num; | ||
74 | unsigned char data[MDC2_BLOCK]; | ||
75 | des_cblock h,hh; | ||
76 | int pad_type; /* either 1 or 2, default 1 */ | ||
77 | } MDC2_CTX; | ||
78 | |||
79 | #ifndef NOPROTO | ||
80 | |||
81 | void MDC2_Init(MDC2_CTX *c); | ||
82 | void MDC2_Update(MDC2_CTX *c, unsigned char *data, unsigned long len); | ||
83 | void MDC2_Final(unsigned char *md, MDC2_CTX *c); | ||
84 | unsigned char *MDC2(unsigned char *d, unsigned long n, unsigned char *md); | ||
85 | |||
86 | #else | ||
87 | |||
88 | void MDC2_Init(); | ||
89 | void MDC2_Update(); | ||
90 | void MDC2_Final(); | ||
91 | unsigned char *MDC2(); | ||
92 | |||
93 | #endif | ||
94 | |||
95 | #ifdef __cplusplus | ||
96 | } | ||
97 | #endif | ||
98 | |||
99 | #endif | ||
100 | |||
diff --git a/src/lib/libcrypto/mem.c b/src/lib/libcrypto/mem.c new file mode 100644 index 0000000000..72e501ad0f --- /dev/null +++ b/src/lib/libcrypto/mem.c | |||
@@ -0,0 +1,353 @@ | |||
1 | /* crypto/mem.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 <stdlib.h> | ||
61 | #include "buffer.h" | ||
62 | #include "bio.h" | ||
63 | #include "lhash.h" | ||
64 | #include "cryptlib.h" | ||
65 | |||
66 | static int mh_mode=CRYPTO_MEM_CHECK_OFF; | ||
67 | static unsigned long order=0; | ||
68 | |||
69 | static LHASH *mh=NULL; | ||
70 | |||
71 | typedef struct mem_st | ||
72 | { | ||
73 | char *addr; | ||
74 | int num; | ||
75 | char *file; | ||
76 | int line; | ||
77 | unsigned long order; | ||
78 | } MEM; | ||
79 | |||
80 | int CRYPTO_mem_ctrl(mode) | ||
81 | int mode; | ||
82 | { | ||
83 | int ret=mh_mode; | ||
84 | |||
85 | CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); | ||
86 | switch (mode) | ||
87 | { | ||
88 | case CRYPTO_MEM_CHECK_ON: | ||
89 | mh_mode|=CRYPTO_MEM_CHECK_ON; | ||
90 | break; | ||
91 | case CRYPTO_MEM_CHECK_OFF: | ||
92 | mh_mode&= ~CRYPTO_MEM_CHECK_ON; | ||
93 | break; | ||
94 | default: | ||
95 | break; | ||
96 | } | ||
97 | CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); | ||
98 | return(ret); | ||
99 | } | ||
100 | |||
101 | static int mem_cmp(a,b) | ||
102 | MEM *a,*b; | ||
103 | { | ||
104 | return(a->addr - b->addr); | ||
105 | } | ||
106 | |||
107 | static unsigned long mem_hash(a) | ||
108 | MEM *a; | ||
109 | { | ||
110 | unsigned long ret; | ||
111 | |||
112 | ret=(unsigned long)a->addr; | ||
113 | |||
114 | ret=ret*17851+(ret>>14)*7+(ret>>4)*251; | ||
115 | return(ret); | ||
116 | } | ||
117 | |||
118 | static char *(*malloc_func)()= (char *(*)())malloc; | ||
119 | static char *(*realloc_func)()= (char *(*)())realloc; | ||
120 | static void (*free_func)()= (void (*)())free; | ||
121 | |||
122 | void CRYPTO_set_mem_functions(m,r,f) | ||
123 | char *(*m)(); | ||
124 | char *(*r)(); | ||
125 | void (*f)(); | ||
126 | { | ||
127 | if ((m == NULL) || (r == NULL) || (f == NULL)) return; | ||
128 | malloc_func=m; | ||
129 | realloc_func=r; | ||
130 | free_func=f; | ||
131 | } | ||
132 | |||
133 | void CRYPTO_get_mem_functions(m,r,f) | ||
134 | char *(**m)(); | ||
135 | char *(**r)(); | ||
136 | void (**f)(); | ||
137 | { | ||
138 | if (m != NULL) *m=malloc_func; | ||
139 | if (r != NULL) *r=realloc_func; | ||
140 | if (f != NULL) *f=free_func; | ||
141 | } | ||
142 | |||
143 | char *CRYPTO_malloc(num) | ||
144 | int num; | ||
145 | { | ||
146 | return(malloc_func(num)); | ||
147 | } | ||
148 | |||
149 | char *CRYPTO_realloc(str,num) | ||
150 | char *str; | ||
151 | int num; | ||
152 | { | ||
153 | return(realloc_func(str,num)); | ||
154 | } | ||
155 | |||
156 | void CRYPTO_free(str) | ||
157 | char *str; | ||
158 | { | ||
159 | free_func(str); | ||
160 | } | ||
161 | |||
162 | char *CRYPTO_dbg_malloc(num,file,line) | ||
163 | int num; | ||
164 | char *file; | ||
165 | int line; | ||
166 | { | ||
167 | char *ret; | ||
168 | MEM *m,*mm; | ||
169 | |||
170 | if ((ret=malloc_func(num)) == NULL) | ||
171 | return(NULL); | ||
172 | |||
173 | if (mh_mode & CRYPTO_MEM_CHECK_ON) | ||
174 | { | ||
175 | if ((m=(MEM *)malloc(sizeof(MEM))) == NULL) | ||
176 | { | ||
177 | free(ret); | ||
178 | return(NULL); | ||
179 | } | ||
180 | CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); | ||
181 | if (mh == NULL) | ||
182 | { | ||
183 | if ((mh=lh_new(mem_hash,mem_cmp)) == NULL) | ||
184 | { | ||
185 | free(ret); | ||
186 | free(m); | ||
187 | return(NULL); | ||
188 | } | ||
189 | } | ||
190 | |||
191 | m->addr=ret; | ||
192 | m->file=file; | ||
193 | m->line=line; | ||
194 | m->num=num; | ||
195 | m->order=order++; | ||
196 | if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL) | ||
197 | { | ||
198 | /* Not good, but don't sweat it */ | ||
199 | free(mm); | ||
200 | } | ||
201 | CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); | ||
202 | } | ||
203 | return(ret); | ||
204 | } | ||
205 | |||
206 | void CRYPTO_dbg_free(addr) | ||
207 | char *addr; | ||
208 | { | ||
209 | MEM m,*mp; | ||
210 | |||
211 | if ((mh_mode & CRYPTO_MEM_CHECK_ON) && (mh != NULL)) | ||
212 | { | ||
213 | CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); | ||
214 | m.addr=addr; | ||
215 | mp=(MEM *)lh_delete(mh,(char *)&m); | ||
216 | if (mp != NULL) | ||
217 | free(mp); | ||
218 | CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); | ||
219 | } | ||
220 | free_func(addr); | ||
221 | } | ||
222 | |||
223 | char *CRYPTO_dbg_realloc(addr,num,file,line) | ||
224 | char *addr; | ||
225 | int num; | ||
226 | char *file; | ||
227 | int line; | ||
228 | { | ||
229 | char *ret; | ||
230 | MEM m,*mp; | ||
231 | |||
232 | ret=realloc_func(addr,num); | ||
233 | if (ret == addr) return(ret); | ||
234 | |||
235 | if (mh_mode & CRYPTO_MEM_CHECK_ON) | ||
236 | { | ||
237 | if (ret == NULL) return(NULL); | ||
238 | m.addr=addr; | ||
239 | CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); | ||
240 | mp=(MEM *)lh_delete(mh,(char *)&m); | ||
241 | if (mp != NULL) | ||
242 | { | ||
243 | mp->addr=ret; | ||
244 | lh_insert(mh,(char *)mp); | ||
245 | } | ||
246 | CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); | ||
247 | } | ||
248 | return(ret); | ||
249 | } | ||
250 | |||
251 | char *CRYPTO_remalloc(a,n) | ||
252 | char *a; | ||
253 | int n; | ||
254 | { | ||
255 | if (a != NULL) Free(a); | ||
256 | a=(char *)Malloc(n); | ||
257 | return(a); | ||
258 | } | ||
259 | |||
260 | char *CRYPTO_dbg_remalloc(a,n,file,line) | ||
261 | char *a; | ||
262 | int n; | ||
263 | char *file; | ||
264 | int line; | ||
265 | { | ||
266 | if (a != NULL) CRYPTO_dbg_free(a); | ||
267 | a=(char *)CRYPTO_dbg_malloc(n,file,line); | ||
268 | return(a); | ||
269 | } | ||
270 | |||
271 | |||
272 | typedef struct mem_leak_st | ||
273 | { | ||
274 | BIO *bio; | ||
275 | int chunks; | ||
276 | long bytes; | ||
277 | } MEM_LEAK; | ||
278 | |||
279 | static void print_leak(m,l) | ||
280 | MEM *m; | ||
281 | MEM_LEAK *l; | ||
282 | { | ||
283 | char buf[128]; | ||
284 | |||
285 | sprintf(buf,"%5ld file=%s, line=%d, number=%d, address=%08lX\n", | ||
286 | m->order,m->file,m->line,m->num,(long)m->addr); | ||
287 | BIO_puts(l->bio,buf); | ||
288 | l->chunks++; | ||
289 | l->bytes+=m->num; | ||
290 | } | ||
291 | |||
292 | void CRYPTO_mem_leaks(b) | ||
293 | BIO *b; | ||
294 | { | ||
295 | MEM_LEAK ml; | ||
296 | char buf[80]; | ||
297 | |||
298 | if (mh == NULL) return; | ||
299 | ml.bio=b; | ||
300 | ml.bytes=0; | ||
301 | ml.chunks=0; | ||
302 | CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); | ||
303 | lh_doall_arg(mh,(void (*)())print_leak,(char *)&ml); | ||
304 | CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); | ||
305 | if (ml.chunks != 0) | ||
306 | { | ||
307 | sprintf(buf,"%ld bytes leaked in %d chunks\n", | ||
308 | ml.bytes,ml.chunks); | ||
309 | BIO_puts(b,buf); | ||
310 | } | ||
311 | /* | ||
312 | lh_stats_bio(mh,b); | ||
313 | lh_node_stats_bio(mh,b); | ||
314 | lh_node_usage_stats_bio(mh,b); | ||
315 | */ | ||
316 | } | ||
317 | |||
318 | static void (*mem_cb)()=NULL; | ||
319 | |||
320 | static void cb_leak(m,cb) | ||
321 | MEM *m; | ||
322 | char *cb; | ||
323 | { | ||
324 | void (*mem_callback)()=(void (*)())cb; | ||
325 | mem_callback(m->order,m->file,m->line,m->num,m->addr); | ||
326 | } | ||
327 | |||
328 | void CRYPTO_mem_leaks_cb(cb) | ||
329 | void (*cb)(); | ||
330 | { | ||
331 | if (mh == NULL) return; | ||
332 | CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); | ||
333 | mem_cb=cb; | ||
334 | lh_doall_arg(mh,(void (*)())cb_leak,(char *)mem_cb); | ||
335 | mem_cb=NULL; | ||
336 | CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); | ||
337 | } | ||
338 | |||
339 | #ifndef NO_FP_API | ||
340 | void CRYPTO_mem_leaks_fp(fp) | ||
341 | FILE *fp; | ||
342 | { | ||
343 | BIO *b; | ||
344 | |||
345 | if (mh == NULL) return; | ||
346 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
347 | return; | ||
348 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
349 | CRYPTO_mem_leaks(b); | ||
350 | BIO_free(b); | ||
351 | } | ||
352 | #endif | ||
353 | |||
diff --git a/src/lib/libcrypto/objects/obj_dat.h b/src/lib/libcrypto/objects/obj_dat.h new file mode 100644 index 0000000000..48143ae3c7 --- /dev/null +++ b/src/lib/libcrypto/objects/obj_dat.h | |||
@@ -0,0 +1,656 @@ | |||
1 | /* lib/obj/obj_dat.h */ | ||
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* THIS FILE IS GENERATED FROM Objects.h by obj_dat.pl via the | ||
60 | * following command: | ||
61 | * perl obj_dat.pl < objects.h > obj_dat.h | ||
62 | */ | ||
63 | |||
64 | #define NUM_NID 124 | ||
65 | #define NUM_SN 95 | ||
66 | #define NUM_LN 122 | ||
67 | #define NUM_OBJ 95 | ||
68 | |||
69 | static unsigned char lvalues[600]={ | ||
70 | 0x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 0] OBJ_rsadsi */ | ||
71 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 6] OBJ_pkcs */ | ||
72 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 13] OBJ_md2 */ | ||
73 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x05, /* [ 21] OBJ_md5 */ | ||
74 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x04, /* [ 29] OBJ_rc4 */ | ||
75 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,/* [ 37] OBJ_rsaEncryption */ | ||
76 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,/* [ 46] OBJ_md2WithRSAEncryption */ | ||
77 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x04,/* [ 55] OBJ_md5WithRSAEncryption */ | ||
78 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x01,/* [ 64] OBJ_pbeWithMD2AndDES_CBC */ | ||
79 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x03,/* [ 73] OBJ_pbeWithMD5AndDES_CBC */ | ||
80 | 0x55, /* [ 82] OBJ_X500 */ | ||
81 | 0x55,0x04, /* [ 83] OBJ_X509 */ | ||
82 | 0x55,0x04,0x03, /* [ 85] OBJ_commonName */ | ||
83 | 0x55,0x04,0x06, /* [ 88] OBJ_countryName */ | ||
84 | 0x55,0x04,0x07, /* [ 91] OBJ_localityName */ | ||
85 | 0x55,0x04,0x08, /* [ 94] OBJ_stateOrProvinceName */ | ||
86 | 0x55,0x04,0x0A, /* [ 97] OBJ_organizationName */ | ||
87 | 0x55,0x04,0x0B, /* [100] OBJ_organizationalUnitName */ | ||
88 | 0x55,0x08,0x01,0x01, /* [103] OBJ_rsa */ | ||
89 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07, /* [107] OBJ_pkcs7 */ | ||
90 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x01,/* [115] OBJ_pkcs7_data */ | ||
91 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x02,/* [124] OBJ_pkcs7_signed */ | ||
92 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x03,/* [133] OBJ_pkcs7_enveloped */ | ||
93 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x04,/* [142] OBJ_pkcs7_signedAndEnveloped */ | ||
94 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x05,/* [151] OBJ_pkcs7_digest */ | ||
95 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x06,/* [160] OBJ_pkcs7_encrypted */ | ||
96 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03, /* [169] OBJ_pkcs3 */ | ||
97 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03,0x01,/* [177] OBJ_dhKeyAgreement */ | ||
98 | 0x2B,0x0E,0x03,0x02,0x06, /* [186] OBJ_des_ecb */ | ||
99 | 0x2B,0x0E,0x03,0x02,0x09, /* [191] OBJ_des_cfb64 */ | ||
100 | 0x2B,0x0E,0x03,0x02,0x07, /* [196] OBJ_des_cbc */ | ||
101 | 0x2B,0x0E,0x03,0x02,0x11, /* [201] OBJ_des_ede */ | ||
102 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x02, /* [206] OBJ_rc2_cbc */ | ||
103 | 0x2B,0x0E,0x03,0x02,0x12, /* [214] OBJ_sha */ | ||
104 | 0x2B,0x0E,0x03,0x02,0x0F, /* [219] OBJ_shaWithRSAEncryption */ | ||
105 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x07, /* [224] OBJ_des_ede3_cbc */ | ||
106 | 0x2B,0x0E,0x03,0x02,0x08, /* [232] OBJ_des_ofb64 */ | ||
107 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09, /* [237] OBJ_pkcs9 */ | ||
108 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x01,/* [245] OBJ_pkcs9_emailAddress */ | ||
109 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x02,/* [254] OBJ_pkcs9_unstructuredName */ | ||
110 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x03,/* [263] OBJ_pkcs9_contentType */ | ||
111 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x04,/* [272] OBJ_pkcs9_messageDigest */ | ||
112 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x05,/* [281] OBJ_pkcs9_signingTime */ | ||
113 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x06,/* [290] OBJ_pkcs9_countersignature */ | ||
114 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x07,/* [299] OBJ_pkcs9_challengePassword */ | ||
115 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x08,/* [308] OBJ_pkcs9_unstructuredAddress */ | ||
116 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x09,/* [317] OBJ_pkcs9_extCertAttributes */ | ||
117 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42, /* [326] OBJ_netscape */ | ||
118 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01, /* [333] OBJ_netscape_cert_extension */ | ||
119 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02, /* [341] OBJ_netscape_data_type */ | ||
120 | 0x2B,0x0E,0x03,0x02,0x1A, /* [349] OBJ_sha1 */ | ||
121 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,/* [354] OBJ_sha1WithRSAEncryption */ | ||
122 | 0x2B,0x0E,0x03,0x02,0x0D, /* [363] OBJ_dsaWithSHA */ | ||
123 | 0x2B,0x0E,0x03,0x02,0x0C, /* [368] OBJ_dsa_2 */ | ||
124 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0B,/* [373] OBJ_pbeWithSHA1AndRC2_CBC */ | ||
125 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0C,/* [382] OBJ_pbeWithSHA1AndRC4 */ | ||
126 | 0x2B,0x0E,0x03,0x02,0x1B, /* [391] OBJ_dsaWithSHA1_2 */ | ||
127 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x01,/* [396] OBJ_netscape_cert_type */ | ||
128 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x02,/* [405] OBJ_netscape_base_url */ | ||
129 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x03,/* [414] OBJ_netscape_revocation_url */ | ||
130 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x04,/* [423] OBJ_netscape_ca_revocation_url */ | ||
131 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x07,/* [432] OBJ_netscape_renewal_url */ | ||
132 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x08,/* [441] OBJ_netscape_ca_policy_url */ | ||
133 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0C,/* [450] OBJ_netscape_ssl_server_name */ | ||
134 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0D,/* [459] OBJ_netscape_comment */ | ||
135 | 0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02,0x05,/* [468] OBJ_netscape_cert_sequence */ | ||
136 | 0x55,0x1D, /* [477] OBJ_ld_ce */ | ||
137 | 0x55,0x1D,0x0E, /* [479] OBJ_subject_key_identifier */ | ||
138 | 0x55,0x1D,0x0F, /* [482] OBJ_key_usage */ | ||
139 | 0x55,0x1D,0x10, /* [485] OBJ_private_key_usage_period */ | ||
140 | 0x55,0x1D,0x11, /* [488] OBJ_subject_alt_name */ | ||
141 | 0x55,0x1D,0x12, /* [491] OBJ_issuer_alt_name */ | ||
142 | 0x55,0x1D,0x13, /* [494] OBJ_basic_constraints */ | ||
143 | 0x55,0x1D,0x14, /* [497] OBJ_crl_number */ | ||
144 | 0x55,0x1D,0x20, /* [500] OBJ_certificate_policies */ | ||
145 | 0x55,0x1D,0x23, /* [503] OBJ_authority_key_identifier */ | ||
146 | 0x55,0x08,0x03,0x65, /* [506] OBJ_mdc2 */ | ||
147 | 0x55,0x08,0x03,0x64, /* [510] OBJ_mdc2WithRSA */ | ||
148 | 0x55,0x04,0x2A, /* [514] OBJ_givenName */ | ||
149 | 0x55,0x04,0x04, /* [517] OBJ_surname */ | ||
150 | 0x55,0x04,0x2B, /* [520] OBJ_initials */ | ||
151 | 0x55,0x04,0x2D, /* [523] OBJ_uniqueIdentifier */ | ||
152 | 0x55,0x1D,0x1F, /* [526] OBJ_crl_distribution_points */ | ||
153 | 0x2B,0x0E,0x03,0x02,0x03, /* [529] OBJ_md5WithRSA */ | ||
154 | 0x55,0x04,0x05, /* [534] OBJ_serialNumber */ | ||
155 | 0x55,0x04,0x0C, /* [537] OBJ_title */ | ||
156 | 0x55,0x04,0x0D, /* [540] OBJ_description */ | ||
157 | 0x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0A,/* [543] OBJ_cast5_cbc */ | ||
158 | 0x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0C,/* [552] OBJ_pbeWithMD5AndCast5_CBC */ | ||
159 | 0x2A,0x86,0x48,0xCE,0x38,0x04,0x03, /* [561] OBJ_dsaWithSHA1 */ | ||
160 | 0x2B,0x0E,0x03,0x02,0x1D, /* [568] OBJ_sha1WithRSA */ | ||
161 | 0x2A,0x86,0x48,0xCE,0x38,0x04,0x01, /* [573] OBJ_dsa */ | ||
162 | 0x2B,0x24,0x03,0x02,0x01, /* [580] OBJ_ripemd160 */ | ||
163 | 0x2B,0x24,0x03,0x03,0x01,0x02, /* [585] OBJ_ripemd160WithRSA */ | ||
164 | 0x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x08, /* [591] OBJ_rc5_cbc */ | ||
165 | }; | ||
166 | |||
167 | static ASN1_OBJECT nid_objs[NUM_NID]={ | ||
168 | {"UNDEF","undefined",NID_undef,0,NULL}, | ||
169 | {"rsadsi","rsadsi",NID_rsadsi,6,&(lvalues[0]),0}, | ||
170 | {"pkcs","pkcs",NID_pkcs,7,&(lvalues[6]),0}, | ||
171 | {"MD2","md2",NID_md2,8,&(lvalues[13]),0}, | ||
172 | {"MD5","md5",NID_md5,8,&(lvalues[21]),0}, | ||
173 | {"RC4","rc4",NID_rc4,8,&(lvalues[29]),0}, | ||
174 | {"rsaEncryption","rsaEncryption",NID_rsaEncryption,9,&(lvalues[37]),0}, | ||
175 | {"RSA-MD2","md2WithRSAEncryption",NID_md2WithRSAEncryption,9, | ||
176 | &(lvalues[46]),0}, | ||
177 | {"RSA-MD5","md5WithRSAEncryption",NID_md5WithRSAEncryption,9, | ||
178 | &(lvalues[55]),0}, | ||
179 | {"pbeWithMD2AndDES-CBC","pbeWithMD2AndDES-CBC", | ||
180 | NID_pbeWithMD2AndDES_CBC,9,&(lvalues[64]),0}, | ||
181 | {"pbeWithMD5AndDES-CBC","pbeWithMD5AndDES-CBC", | ||
182 | NID_pbeWithMD5AndDES_CBC,9,&(lvalues[73]),0}, | ||
183 | {"X500","X500",NID_X500,1,&(lvalues[82]),0}, | ||
184 | {"X509","X509",NID_X509,2,&(lvalues[83]),0}, | ||
185 | {"CN","commonName",NID_commonName,3,&(lvalues[85]),0}, | ||
186 | {"C","countryName",NID_countryName,3,&(lvalues[88]),0}, | ||
187 | {"L","localityName",NID_localityName,3,&(lvalues[91]),0}, | ||
188 | {"ST","stateOrProvinceName",NID_stateOrProvinceName,3,&(lvalues[94]),0}, | ||
189 | {"O","organizationName",NID_organizationName,3,&(lvalues[97]),0}, | ||
190 | {"OU","organizationalUnitName",NID_organizationalUnitName,3, | ||
191 | &(lvalues[100]),0}, | ||
192 | {"RSA","rsa",NID_rsa,4,&(lvalues[103]),0}, | ||
193 | {"pkcs7","pkcs7",NID_pkcs7,8,&(lvalues[107]),0}, | ||
194 | {"pkcs7-data","pkcs7-data",NID_pkcs7_data,9,&(lvalues[115]),0}, | ||
195 | {"pkcs7-signedData","pkcs7-signedData",NID_pkcs7_signed,9, | ||
196 | &(lvalues[124]),0}, | ||
197 | {"pkcs7-envelopedData","pkcs7-envelopedData",NID_pkcs7_enveloped,9, | ||
198 | &(lvalues[133]),0}, | ||
199 | {"pkcs7-signedAndEnvelopedData","pkcs7-signedAndEnvelopedData", | ||
200 | NID_pkcs7_signedAndEnveloped,9,&(lvalues[142]),0}, | ||
201 | {"pkcs7-digestData","pkcs7-digestData",NID_pkcs7_digest,9, | ||
202 | &(lvalues[151]),0}, | ||
203 | {"pkcs7-encryptedData","pkcs7-encryptedData",NID_pkcs7_encrypted,9, | ||
204 | &(lvalues[160]),0}, | ||
205 | {"pkcs3","pkcs3",NID_pkcs3,8,&(lvalues[169]),0}, | ||
206 | {"dhKeyAgreement","dhKeyAgreement",NID_dhKeyAgreement,9, | ||
207 | &(lvalues[177]),0}, | ||
208 | {"DES-ECB","des-ecb",NID_des_ecb,5,&(lvalues[186]),0}, | ||
209 | {"DES-CFB","des-cfb",NID_des_cfb64,5,&(lvalues[191]),0}, | ||
210 | {"DES-CBC","des-cbc",NID_des_cbc,5,&(lvalues[196]),0}, | ||
211 | {"DES-EDE","des-ede",NID_des_ede,5,&(lvalues[201]),0}, | ||
212 | {"DES-EDE3","des-ede3",NID_des_ede3,0,NULL}, | ||
213 | {"IDEA-CBC","idea-cbc",NID_idea_cbc,0,NULL}, | ||
214 | {"IDEA-CFB","idea-cfb",NID_idea_cfb64,0,NULL}, | ||
215 | {"IDEA-ECB","idea-ecb",NID_idea_ecb,0,NULL}, | ||
216 | {"RC2-CBC","rc2-cbc",NID_rc2_cbc,8,&(lvalues[206]),0}, | ||
217 | {"RC2-ECB","rc2-ecb",NID_rc2_ecb,0,NULL}, | ||
218 | {"RC2-CFB","rc2-cfb",NID_rc2_cfb64,0,NULL}, | ||
219 | {"RC2-OFB","rc2-ofb",NID_rc2_ofb64,0,NULL}, | ||
220 | {"SHA","sha",NID_sha,5,&(lvalues[214]),0}, | ||
221 | {"RSA-SHA","shaWithRSAEncryption",NID_shaWithRSAEncryption,5, | ||
222 | &(lvalues[219]),0}, | ||
223 | {"DES-EDE-CBC","des-ede-cbc",NID_des_ede_cbc,0,NULL}, | ||
224 | {"DES-EDE3-CBC","des-ede3-cbc",NID_des_ede3_cbc,8,&(lvalues[224]),0}, | ||
225 | {"DES-OFB","des-ofb",NID_des_ofb64,5,&(lvalues[232]),0}, | ||
226 | {"IDEA-OFB","idea-ofb",NID_idea_ofb64,0,NULL}, | ||
227 | {"pkcs9","pkcs9",NID_pkcs9,8,&(lvalues[237]),0}, | ||
228 | {"Email","emailAddress",NID_pkcs9_emailAddress,9,&(lvalues[245]),0}, | ||
229 | {"unstructuredName","unstructuredName",NID_pkcs9_unstructuredName,9, | ||
230 | &(lvalues[254]),0}, | ||
231 | {"contentType","contentType",NID_pkcs9_contentType,9,&(lvalues[263]),0}, | ||
232 | {"messageDigest","messageDigest",NID_pkcs9_messageDigest,9, | ||
233 | &(lvalues[272]),0}, | ||
234 | {"signingTime","signingTime",NID_pkcs9_signingTime,9,&(lvalues[281]),0}, | ||
235 | {"countersignature","countersignature",NID_pkcs9_countersignature,9, | ||
236 | &(lvalues[290]),0}, | ||
237 | {"challengePassword","challengePassword",NID_pkcs9_challengePassword, | ||
238 | 9,&(lvalues[299]),0}, | ||
239 | {"unstructuredAddress","unstructuredAddress", | ||
240 | NID_pkcs9_unstructuredAddress,9,&(lvalues[308]),0}, | ||
241 | {"extendedCertificateAttributes","extendedCertificateAttributes", | ||
242 | NID_pkcs9_extCertAttributes,9,&(lvalues[317]),0}, | ||
243 | {"Netscape","Netscape Communications Corp.",NID_netscape,7, | ||
244 | &(lvalues[326]),0}, | ||
245 | {"nsCertExt","Netscape Certificate Extension", | ||
246 | NID_netscape_cert_extension,8,&(lvalues[333]),0}, | ||
247 | {"nsDataType","Netscape Data Type",NID_netscape_data_type,8, | ||
248 | &(lvalues[341]),0}, | ||
249 | {"DES-EDE-CFB","des-ede-cfb",NID_des_ede_cfb64,0,NULL}, | ||
250 | {"DES-EDE3-CFB","des-ede3-cfb",NID_des_ede3_cfb64,0,NULL}, | ||
251 | {"DES-EDE-OFB","des-ede-ofb",NID_des_ede_ofb64,0,NULL}, | ||
252 | {"DES-EDE3-OFB","des-ede3-ofb",NID_des_ede3_ofb64,0,NULL}, | ||
253 | {"SHA1","sha1",NID_sha1,5,&(lvalues[349]),0}, | ||
254 | {"RSA-SHA1","sha1WithRSAEncryption",NID_sha1WithRSAEncryption,9, | ||
255 | &(lvalues[354]),0}, | ||
256 | {"DSA-SHA","dsaWithSHA",NID_dsaWithSHA,5,&(lvalues[363]),0}, | ||
257 | {"DSA-old","dsaEncryption-old",NID_dsa_2,5,&(lvalues[368]),0}, | ||
258 | {"pbeWithSHA1AndRC2-CBC","pbeWithSHA1AndRC2-CBC", | ||
259 | NID_pbeWithSHA1AndRC2_CBC,9,&(lvalues[373]),0}, | ||
260 | {"pbeWithSHA1AndRC4","pbeWithSHA1AndRC4",NID_pbeWithSHA1AndRC4,9, | ||
261 | &(lvalues[382]),0}, | ||
262 | {"DSA-SHA1-old","dsaWithSHA1",NID_dsaWithSHA1_2,5,&(lvalues[391]),0}, | ||
263 | {"nsCertType","Netscape Cert Type",NID_netscape_cert_type,9, | ||
264 | &(lvalues[396]),0}, | ||
265 | {"nsBaseUrl","Netscape Base Url",NID_netscape_base_url,9, | ||
266 | &(lvalues[405]),0}, | ||
267 | {"nsRevocationUrl","Netscape Revocation Url", | ||
268 | NID_netscape_revocation_url,9,&(lvalues[414]),0}, | ||
269 | {"nsCaRevocationUrl","Netscape CA Revocation Url", | ||
270 | NID_netscape_ca_revocation_url,9,&(lvalues[423]),0}, | ||
271 | {"nsRenewalUrl","Netscape Renewal Url",NID_netscape_renewal_url,9, | ||
272 | &(lvalues[432]),0}, | ||
273 | {"nsCaPolicyUrl","Netscape CA Policy Url",NID_netscape_ca_policy_url, | ||
274 | 9,&(lvalues[441]),0}, | ||
275 | {"nsSslServerName","Netscape SSL Server Name", | ||
276 | NID_netscape_ssl_server_name,9,&(lvalues[450]),0}, | ||
277 | {"nsComment","Netscape Comment",NID_netscape_comment,9,&(lvalues[459]),0}, | ||
278 | {"nsCertSequence","Netscape Certificate Sequence", | ||
279 | NID_netscape_cert_sequence,9,&(lvalues[468]),0}, | ||
280 | {"DESX-CBC","desx-cbc",NID_desx_cbc,0,NULL}, | ||
281 | {"ld-ce","ld-ce",NID_ld_ce,2,&(lvalues[477]),0}, | ||
282 | {"subjectKeyIdentifier","X509v3 Subject Key Identifier", | ||
283 | NID_subject_key_identifier,3,&(lvalues[479]),0}, | ||
284 | {"keyUsage","X509v3 Key Usage",NID_key_usage,3,&(lvalues[482]),0}, | ||
285 | {"privateKeyUsagePeriod","X509v3 Private Key Usage Period", | ||
286 | NID_private_key_usage_period,3,&(lvalues[485]),0}, | ||
287 | {"subjectAltName","X509v3 Subject Alternative Name", | ||
288 | NID_subject_alt_name,3,&(lvalues[488]),0}, | ||
289 | {"issuerAltName","X509v3 Issuer Alternative Name",NID_issuer_alt_name, | ||
290 | 3,&(lvalues[491]),0}, | ||
291 | {"basicConstraints","X509v3 Basic Constraints",NID_basic_constraints, | ||
292 | 3,&(lvalues[494]),0}, | ||
293 | {"crlNumber","X509v3 CRL Number",NID_crl_number,3,&(lvalues[497]),0}, | ||
294 | {"certificatePolicies","X509v3 Certificate Policies", | ||
295 | NID_certificate_policies,3,&(lvalues[500]),0}, | ||
296 | {"authorityKeyIdentifier","X509v3 Authority Key Identifier", | ||
297 | NID_authority_key_identifier,3,&(lvalues[503]),0}, | ||
298 | {"BF-CBC","bf-cbc",NID_bf_cbc,0,NULL}, | ||
299 | {"BF-ECB","bf-ecb",NID_bf_ecb,0,NULL}, | ||
300 | {"BF-CFB","bf-cfb",NID_bf_cfb64,0,NULL}, | ||
301 | {"BF-OFB","bf-ofb",NID_bf_ofb64,0,NULL}, | ||
302 | {"MDC2","mdc2",NID_mdc2,4,&(lvalues[506]),0}, | ||
303 | {"RSA-MDC2","mdc2withRSA",NID_mdc2WithRSA,4,&(lvalues[510]),0}, | ||
304 | {"RC4-40","rc4-40",NID_rc4_40,0,NULL}, | ||
305 | {"RC2-40-CBC","rc2-40-cbc",NID_rc2_40_cbc,0,NULL}, | ||
306 | {"G","givenName",NID_givenName,3,&(lvalues[514]),0}, | ||
307 | {"S","surname",NID_surname,3,&(lvalues[517]),0}, | ||
308 | {"I","initials",NID_initials,3,&(lvalues[520]),0}, | ||
309 | {"UID","uniqueIdentifier",NID_uniqueIdentifier,3,&(lvalues[523]),0}, | ||
310 | {"crlDistributionPoints","X509v3 CRL Distribution Points", | ||
311 | NID_crl_distribution_points,3,&(lvalues[526]),0}, | ||
312 | {"RSA-NP-MD5","md5WithRSA",NID_md5WithRSA,5,&(lvalues[529]),0}, | ||
313 | {"SN","serialNumber",NID_serialNumber,3,&(lvalues[534]),0}, | ||
314 | {"T","title",NID_title,3,&(lvalues[537]),0}, | ||
315 | {"D","description",NID_description,3,&(lvalues[540]),0}, | ||
316 | {"CAST5-CBC","cast5-cbc",NID_cast5_cbc,9,&(lvalues[543]),0}, | ||
317 | {"CAST5-ECB","cast5-ecb",NID_cast5_ecb,0,NULL}, | ||
318 | {"CAST5-CFB","cast5-cfb",NID_cast5_cfb64,0,NULL}, | ||
319 | {"CAST5-OFB","cast5-ofb",NID_cast5_ofb64,0,NULL}, | ||
320 | {"pbeWithMD5AndCast5CBC","pbeWithMD5AndCast5CBC", | ||
321 | NID_pbeWithMD5AndCast5_CBC,9,&(lvalues[552]),0}, | ||
322 | {"DSA-SHA1","dsaWithSHA1",NID_dsaWithSHA1,7,&(lvalues[561]),0}, | ||
323 | {"MD5-SHA1","md5-sha1",NID_md5_sha1,0,NULL}, | ||
324 | {"RSA-SHA1-2","sha1WithRSA",NID_sha1WithRSA,5,&(lvalues[568]),0}, | ||
325 | {"DSA","dsaEncryption",NID_dsa,7,&(lvalues[573]),0}, | ||
326 | {"RIPEMD160","ripemd160",NID_ripemd160,5,&(lvalues[580]),0}, | ||
327 | {NULL,NULL,NID_undef,0,NULL}, | ||
328 | {"RSA-RIPEMD160","ripemd160WithRSA",NID_ripemd160WithRSA,6, | ||
329 | &(lvalues[585]),0}, | ||
330 | {"RC5-CBC","rc5-cbc",NID_rc5_cbc,8,&(lvalues[591]),0}, | ||
331 | {"RC5-ECB","rc5-ecb",NID_rc5_ecb,0,NULL}, | ||
332 | {"RC5-CFB","rc5-cfb",NID_rc5_cfb64,0,NULL}, | ||
333 | {"RC5-OFB","rc5-ofb",NID_rc5_ofb64,0,NULL}, | ||
334 | }; | ||
335 | |||
336 | static ASN1_OBJECT *sn_objs[NUM_SN]={ | ||
337 | &(nid_objs[91]),/* "BF-CBC" */ | ||
338 | &(nid_objs[93]),/* "BF-CFB" */ | ||
339 | &(nid_objs[92]),/* "BF-ECB" */ | ||
340 | &(nid_objs[94]),/* "BF-OFB" */ | ||
341 | &(nid_objs[14]),/* "C" */ | ||
342 | &(nid_objs[108]),/* "CAST5-CBC" */ | ||
343 | &(nid_objs[110]),/* "CAST5-CFB" */ | ||
344 | &(nid_objs[109]),/* "CAST5-ECB" */ | ||
345 | &(nid_objs[111]),/* "CAST5-OFB" */ | ||
346 | &(nid_objs[13]),/* "CN" */ | ||
347 | &(nid_objs[107]),/* "D" */ | ||
348 | &(nid_objs[31]),/* "DES-CBC" */ | ||
349 | &(nid_objs[30]),/* "DES-CFB" */ | ||
350 | &(nid_objs[29]),/* "DES-ECB" */ | ||
351 | &(nid_objs[32]),/* "DES-EDE" */ | ||
352 | &(nid_objs[43]),/* "DES-EDE-CBC" */ | ||
353 | &(nid_objs[60]),/* "DES-EDE-CFB" */ | ||
354 | &(nid_objs[62]),/* "DES-EDE-OFB" */ | ||
355 | &(nid_objs[33]),/* "DES-EDE3" */ | ||
356 | &(nid_objs[44]),/* "DES-EDE3-CBC" */ | ||
357 | &(nid_objs[61]),/* "DES-EDE3-CFB" */ | ||
358 | &(nid_objs[63]),/* "DES-EDE3-OFB" */ | ||
359 | &(nid_objs[45]),/* "DES-OFB" */ | ||
360 | &(nid_objs[80]),/* "DESX-CBC" */ | ||
361 | &(nid_objs[116]),/* "DSA" */ | ||
362 | &(nid_objs[66]),/* "DSA-SHA" */ | ||
363 | &(nid_objs[113]),/* "DSA-SHA1" */ | ||
364 | &(nid_objs[70]),/* "DSA-SHA1-old" */ | ||
365 | &(nid_objs[67]),/* "DSA-old" */ | ||
366 | &(nid_objs[48]),/* "Email" */ | ||
367 | &(nid_objs[99]),/* "G" */ | ||
368 | &(nid_objs[101]),/* "I" */ | ||
369 | &(nid_objs[34]),/* "IDEA-CBC" */ | ||
370 | &(nid_objs[35]),/* "IDEA-CFB" */ | ||
371 | &(nid_objs[36]),/* "IDEA-ECB" */ | ||
372 | &(nid_objs[46]),/* "IDEA-OFB" */ | ||
373 | &(nid_objs[15]),/* "L" */ | ||
374 | &(nid_objs[ 3]),/* "MD2" */ | ||
375 | &(nid_objs[ 4]),/* "MD5" */ | ||
376 | &(nid_objs[114]),/* "MD5-SHA1" */ | ||
377 | &(nid_objs[95]),/* "MDC2" */ | ||
378 | &(nid_objs[57]),/* "Netscape" */ | ||
379 | &(nid_objs[17]),/* "O" */ | ||
380 | &(nid_objs[18]),/* "OU" */ | ||
381 | &(nid_objs[98]),/* "RC2-40-CBC" */ | ||
382 | &(nid_objs[37]),/* "RC2-CBC" */ | ||
383 | &(nid_objs[39]),/* "RC2-CFB" */ | ||
384 | &(nid_objs[38]),/* "RC2-ECB" */ | ||
385 | &(nid_objs[40]),/* "RC2-OFB" */ | ||
386 | &(nid_objs[ 5]),/* "RC4" */ | ||
387 | &(nid_objs[97]),/* "RC4-40" */ | ||
388 | &(nid_objs[120]),/* "RC5-CBC" */ | ||
389 | &(nid_objs[122]),/* "RC5-CFB" */ | ||
390 | &(nid_objs[121]),/* "RC5-ECB" */ | ||
391 | &(nid_objs[123]),/* "RC5-OFB" */ | ||
392 | &(nid_objs[117]),/* "RIPEMD160" */ | ||
393 | &(nid_objs[19]),/* "RSA" */ | ||
394 | &(nid_objs[ 7]),/* "RSA-MD2" */ | ||
395 | &(nid_objs[ 8]),/* "RSA-MD5" */ | ||
396 | &(nid_objs[96]),/* "RSA-MDC2" */ | ||
397 | &(nid_objs[104]),/* "RSA-NP-MD5" */ | ||
398 | &(nid_objs[119]),/* "RSA-RIPEMD160" */ | ||
399 | &(nid_objs[42]),/* "RSA-SHA" */ | ||
400 | &(nid_objs[65]),/* "RSA-SHA1" */ | ||
401 | &(nid_objs[115]),/* "RSA-SHA1-2" */ | ||
402 | &(nid_objs[100]),/* "S" */ | ||
403 | &(nid_objs[41]),/* "SHA" */ | ||
404 | &(nid_objs[64]),/* "SHA1" */ | ||
405 | &(nid_objs[105]),/* "SN" */ | ||
406 | &(nid_objs[16]),/* "ST" */ | ||
407 | &(nid_objs[106]),/* "T" */ | ||
408 | &(nid_objs[102]),/* "UID" */ | ||
409 | &(nid_objs[ 0]),/* "UNDEF" */ | ||
410 | &(nid_objs[90]),/* "authorityKeyIdentifier" */ | ||
411 | &(nid_objs[87]),/* "basicConstraints" */ | ||
412 | &(nid_objs[89]),/* "certificatePolicies" */ | ||
413 | &(nid_objs[103]),/* "crlDistributionPoints" */ | ||
414 | &(nid_objs[88]),/* "crlNumber" */ | ||
415 | &(nid_objs[86]),/* "issuerAltName" */ | ||
416 | &(nid_objs[83]),/* "keyUsage" */ | ||
417 | &(nid_objs[81]),/* "ld-ce" */ | ||
418 | &(nid_objs[72]),/* "nsBaseUrl" */ | ||
419 | &(nid_objs[76]),/* "nsCaPolicyUrl" */ | ||
420 | &(nid_objs[74]),/* "nsCaRevocationUrl" */ | ||
421 | &(nid_objs[58]),/* "nsCertExt" */ | ||
422 | &(nid_objs[79]),/* "nsCertSequence" */ | ||
423 | &(nid_objs[71]),/* "nsCertType" */ | ||
424 | &(nid_objs[78]),/* "nsComment" */ | ||
425 | &(nid_objs[59]),/* "nsDataType" */ | ||
426 | &(nid_objs[75]),/* "nsRenewalUrl" */ | ||
427 | &(nid_objs[73]),/* "nsRevocationUrl" */ | ||
428 | &(nid_objs[77]),/* "nsSslServerName" */ | ||
429 | &(nid_objs[84]),/* "privateKeyUsagePeriod" */ | ||
430 | &(nid_objs[85]),/* "subjectAltName" */ | ||
431 | &(nid_objs[82]),/* "subjectKeyIdentifier" */ | ||
432 | }; | ||
433 | |||
434 | static ASN1_OBJECT *ln_objs[NUM_LN]={ | ||
435 | &(nid_objs[72]),/* "Netscape Base Url" */ | ||
436 | &(nid_objs[76]),/* "Netscape CA Policy Url" */ | ||
437 | &(nid_objs[74]),/* "Netscape CA Revocation Url" */ | ||
438 | &(nid_objs[71]),/* "Netscape Cert Type" */ | ||
439 | &(nid_objs[58]),/* "Netscape Certificate Extension" */ | ||
440 | &(nid_objs[79]),/* "Netscape Certificate Sequence" */ | ||
441 | &(nid_objs[78]),/* "Netscape Comment" */ | ||
442 | &(nid_objs[57]),/* "Netscape Communications Corp." */ | ||
443 | &(nid_objs[59]),/* "Netscape Data Type" */ | ||
444 | &(nid_objs[75]),/* "Netscape Renewal Url" */ | ||
445 | &(nid_objs[73]),/* "Netscape Revocation Url" */ | ||
446 | &(nid_objs[77]),/* "Netscape SSL Server Name" */ | ||
447 | &(nid_objs[11]),/* "X500" */ | ||
448 | &(nid_objs[12]),/* "X509" */ | ||
449 | &(nid_objs[90]),/* "X509v3 Authority Key Identifier" */ | ||
450 | &(nid_objs[87]),/* "X509v3 Basic Constraints" */ | ||
451 | &(nid_objs[103]),/* "X509v3 CRL Distribution Points" */ | ||
452 | &(nid_objs[88]),/* "X509v3 CRL Number" */ | ||
453 | &(nid_objs[89]),/* "X509v3 Certificate Policies" */ | ||
454 | &(nid_objs[86]),/* "X509v3 Issuer Alternative Name" */ | ||
455 | &(nid_objs[83]),/* "X509v3 Key Usage" */ | ||
456 | &(nid_objs[84]),/* "X509v3 Private Key Usage Period" */ | ||
457 | &(nid_objs[85]),/* "X509v3 Subject Alternative Name" */ | ||
458 | &(nid_objs[82]),/* "X509v3 Subject Key Identifier" */ | ||
459 | &(nid_objs[91]),/* "bf-cbc" */ | ||
460 | &(nid_objs[93]),/* "bf-cfb" */ | ||
461 | &(nid_objs[92]),/* "bf-ecb" */ | ||
462 | &(nid_objs[94]),/* "bf-ofb" */ | ||
463 | &(nid_objs[108]),/* "cast5-cbc" */ | ||
464 | &(nid_objs[110]),/* "cast5-cfb" */ | ||
465 | &(nid_objs[109]),/* "cast5-ecb" */ | ||
466 | &(nid_objs[111]),/* "cast5-ofb" */ | ||
467 | &(nid_objs[54]),/* "challengePassword" */ | ||
468 | &(nid_objs[13]),/* "commonName" */ | ||
469 | &(nid_objs[50]),/* "contentType" */ | ||
470 | &(nid_objs[53]),/* "countersignature" */ | ||
471 | &(nid_objs[14]),/* "countryName" */ | ||
472 | &(nid_objs[31]),/* "des-cbc" */ | ||
473 | &(nid_objs[30]),/* "des-cfb" */ | ||
474 | &(nid_objs[29]),/* "des-ecb" */ | ||
475 | &(nid_objs[32]),/* "des-ede" */ | ||
476 | &(nid_objs[43]),/* "des-ede-cbc" */ | ||
477 | &(nid_objs[60]),/* "des-ede-cfb" */ | ||
478 | &(nid_objs[62]),/* "des-ede-ofb" */ | ||
479 | &(nid_objs[33]),/* "des-ede3" */ | ||
480 | &(nid_objs[44]),/* "des-ede3-cbc" */ | ||
481 | &(nid_objs[61]),/* "des-ede3-cfb" */ | ||
482 | &(nid_objs[63]),/* "des-ede3-ofb" */ | ||
483 | &(nid_objs[45]),/* "des-ofb" */ | ||
484 | &(nid_objs[107]),/* "description" */ | ||
485 | &(nid_objs[80]),/* "desx-cbc" */ | ||
486 | &(nid_objs[28]),/* "dhKeyAgreement" */ | ||
487 | &(nid_objs[116]),/* "dsaEncryption" */ | ||
488 | &(nid_objs[67]),/* "dsaEncryption-old" */ | ||
489 | &(nid_objs[66]),/* "dsaWithSHA" */ | ||
490 | &(nid_objs[113]),/* "dsaWithSHA1" */ | ||
491 | &(nid_objs[70]),/* "dsaWithSHA1" */ | ||
492 | &(nid_objs[48]),/* "emailAddress" */ | ||
493 | &(nid_objs[56]),/* "extendedCertificateAttributes" */ | ||
494 | &(nid_objs[99]),/* "givenName" */ | ||
495 | &(nid_objs[34]),/* "idea-cbc" */ | ||
496 | &(nid_objs[35]),/* "idea-cfb" */ | ||
497 | &(nid_objs[36]),/* "idea-ecb" */ | ||
498 | &(nid_objs[46]),/* "idea-ofb" */ | ||
499 | &(nid_objs[101]),/* "initials" */ | ||
500 | &(nid_objs[15]),/* "localityName" */ | ||
501 | &(nid_objs[ 3]),/* "md2" */ | ||
502 | &(nid_objs[ 7]),/* "md2WithRSAEncryption" */ | ||
503 | &(nid_objs[ 4]),/* "md5" */ | ||
504 | &(nid_objs[114]),/* "md5-sha1" */ | ||
505 | &(nid_objs[104]),/* "md5WithRSA" */ | ||
506 | &(nid_objs[ 8]),/* "md5WithRSAEncryption" */ | ||
507 | &(nid_objs[95]),/* "mdc2" */ | ||
508 | &(nid_objs[96]),/* "mdc2withRSA" */ | ||
509 | &(nid_objs[51]),/* "messageDigest" */ | ||
510 | &(nid_objs[17]),/* "organizationName" */ | ||
511 | &(nid_objs[18]),/* "organizationalUnitName" */ | ||
512 | &(nid_objs[ 9]),/* "pbeWithMD2AndDES-CBC" */ | ||
513 | &(nid_objs[112]),/* "pbeWithMD5AndCast5CBC" */ | ||
514 | &(nid_objs[10]),/* "pbeWithMD5AndDES-CBC" */ | ||
515 | &(nid_objs[68]),/* "pbeWithSHA1AndRC2-CBC" */ | ||
516 | &(nid_objs[69]),/* "pbeWithSHA1AndRC4" */ | ||
517 | &(nid_objs[ 2]),/* "pkcs" */ | ||
518 | &(nid_objs[27]),/* "pkcs3" */ | ||
519 | &(nid_objs[20]),/* "pkcs7" */ | ||
520 | &(nid_objs[21]),/* "pkcs7-data" */ | ||
521 | &(nid_objs[25]),/* "pkcs7-digestData" */ | ||
522 | &(nid_objs[26]),/* "pkcs7-encryptedData" */ | ||
523 | &(nid_objs[23]),/* "pkcs7-envelopedData" */ | ||
524 | &(nid_objs[24]),/* "pkcs7-signedAndEnvelopedData" */ | ||
525 | &(nid_objs[22]),/* "pkcs7-signedData" */ | ||
526 | &(nid_objs[47]),/* "pkcs9" */ | ||
527 | &(nid_objs[98]),/* "rc2-40-cbc" */ | ||
528 | &(nid_objs[37]),/* "rc2-cbc" */ | ||
529 | &(nid_objs[39]),/* "rc2-cfb" */ | ||
530 | &(nid_objs[38]),/* "rc2-ecb" */ | ||
531 | &(nid_objs[40]),/* "rc2-ofb" */ | ||
532 | &(nid_objs[ 5]),/* "rc4" */ | ||
533 | &(nid_objs[97]),/* "rc4-40" */ | ||
534 | &(nid_objs[120]),/* "rc5-cbc" */ | ||
535 | &(nid_objs[122]),/* "rc5-cfb" */ | ||
536 | &(nid_objs[121]),/* "rc5-ecb" */ | ||
537 | &(nid_objs[123]),/* "rc5-ofb" */ | ||
538 | &(nid_objs[117]),/* "ripemd160" */ | ||
539 | &(nid_objs[119]),/* "ripemd160WithRSA" */ | ||
540 | &(nid_objs[19]),/* "rsa" */ | ||
541 | &(nid_objs[ 6]),/* "rsaEncryption" */ | ||
542 | &(nid_objs[ 1]),/* "rsadsi" */ | ||
543 | &(nid_objs[105]),/* "serialNumber" */ | ||
544 | &(nid_objs[41]),/* "sha" */ | ||
545 | &(nid_objs[64]),/* "sha1" */ | ||
546 | &(nid_objs[115]),/* "sha1WithRSA" */ | ||
547 | &(nid_objs[65]),/* "sha1WithRSAEncryption" */ | ||
548 | &(nid_objs[42]),/* "shaWithRSAEncryption" */ | ||
549 | &(nid_objs[52]),/* "signingTime" */ | ||
550 | &(nid_objs[16]),/* "stateOrProvinceName" */ | ||
551 | &(nid_objs[100]),/* "surname" */ | ||
552 | &(nid_objs[106]),/* "title" */ | ||
553 | &(nid_objs[ 0]),/* "undefined" */ | ||
554 | &(nid_objs[102]),/* "uniqueIdentifier" */ | ||
555 | &(nid_objs[55]),/* "unstructuredAddress" */ | ||
556 | &(nid_objs[49]),/* "unstructuredName" */ | ||
557 | }; | ||
558 | |||
559 | static ASN1_OBJECT *obj_objs[NUM_OBJ]={ | ||
560 | &(nid_objs[11]),/* OBJ_X500 2 5 */ | ||
561 | &(nid_objs[12]),/* OBJ_X509 2 5 4 */ | ||
562 | &(nid_objs[81]),/* OBJ_ld_ce 2 5 29 */ | ||
563 | &(nid_objs[13]),/* OBJ_commonName 2 5 4 3 */ | ||
564 | &(nid_objs[100]),/* OBJ_surname 2 5 4 4 */ | ||
565 | &(nid_objs[105]),/* OBJ_serialNumber 2 5 4 5 */ | ||
566 | &(nid_objs[14]),/* OBJ_countryName 2 5 4 6 */ | ||
567 | &(nid_objs[15]),/* OBJ_localityName 2 5 4 7 */ | ||
568 | &(nid_objs[16]),/* OBJ_stateOrProvinceName 2 5 4 8 */ | ||
569 | &(nid_objs[17]),/* OBJ_organizationName 2 5 4 10 */ | ||
570 | &(nid_objs[18]),/* OBJ_organizationalUnitName 2 5 4 11 */ | ||
571 | &(nid_objs[106]),/* OBJ_title 2 5 4 12 */ | ||
572 | &(nid_objs[107]),/* OBJ_description 2 5 4 13 */ | ||
573 | &(nid_objs[99]),/* OBJ_givenName 2 5 4 42 */ | ||
574 | &(nid_objs[101]),/* OBJ_initials 2 5 4 43 */ | ||
575 | &(nid_objs[102]),/* OBJ_uniqueIdentifier 2 5 4 45 */ | ||
576 | &(nid_objs[82]),/* OBJ_subject_key_identifier 2 5 29 14 */ | ||
577 | &(nid_objs[83]),/* OBJ_key_usage 2 5 29 15 */ | ||
578 | &(nid_objs[84]),/* OBJ_private_key_usage_period 2 5 29 16 */ | ||
579 | &(nid_objs[85]),/* OBJ_subject_alt_name 2 5 29 17 */ | ||
580 | &(nid_objs[86]),/* OBJ_issuer_alt_name 2 5 29 18 */ | ||
581 | &(nid_objs[87]),/* OBJ_basic_constraints 2 5 29 19 */ | ||
582 | &(nid_objs[88]),/* OBJ_crl_number 2 5 29 20 */ | ||
583 | &(nid_objs[103]),/* OBJ_crl_distribution_points 2 5 29 31 */ | ||
584 | &(nid_objs[89]),/* OBJ_certificate_policies 2 5 29 32 */ | ||
585 | &(nid_objs[90]),/* OBJ_authority_key_identifier 2 5 29 35 */ | ||
586 | &(nid_objs[19]),/* OBJ_rsa 2 5 8 1 1 */ | ||
587 | &(nid_objs[96]),/* OBJ_mdc2WithRSA 2 5 8 3 100 */ | ||
588 | &(nid_objs[95]),/* OBJ_mdc2 2 5 8 3 101 */ | ||
589 | &(nid_objs[104]),/* OBJ_md5WithRSA 1 3 14 3 2 3 */ | ||
590 | &(nid_objs[29]),/* OBJ_des_ecb 1 3 14 3 2 6 */ | ||
591 | &(nid_objs[31]),/* OBJ_des_cbc 1 3 14 3 2 7 */ | ||
592 | &(nid_objs[45]),/* OBJ_des_ofb64 1 3 14 3 2 8 */ | ||
593 | &(nid_objs[30]),/* OBJ_des_cfb64 1 3 14 3 2 9 */ | ||
594 | &(nid_objs[67]),/* OBJ_dsa_2 1 3 14 3 2 12 */ | ||
595 | &(nid_objs[66]),/* OBJ_dsaWithSHA 1 3 14 3 2 13 */ | ||
596 | &(nid_objs[42]),/* OBJ_shaWithRSAEncryption 1 3 14 3 2 15 */ | ||
597 | &(nid_objs[32]),/* OBJ_des_ede 1 3 14 3 2 17 */ | ||
598 | &(nid_objs[41]),/* OBJ_sha 1 3 14 3 2 18 */ | ||
599 | &(nid_objs[64]),/* OBJ_sha1 1 3 14 3 2 26 */ | ||
600 | &(nid_objs[70]),/* OBJ_dsaWithSHA1_2 1 3 14 3 2 27 */ | ||
601 | &(nid_objs[115]),/* OBJ_sha1WithRSA 1 3 14 3 2 29 */ | ||
602 | &(nid_objs[117]),/* OBJ_ripemd160 1 3 36 3 2 1 */ | ||
603 | &(nid_objs[ 1]),/* OBJ_rsadsi 1 2 840 113549 */ | ||
604 | &(nid_objs[119]),/* OBJ_ripemd160WithRSA 1 3 36 3 3 1 2 */ | ||
605 | &(nid_objs[ 2]),/* OBJ_pkcs 1 2 840 113549 1 */ | ||
606 | &(nid_objs[116]),/* OBJ_dsa 1 2 840 10040 4 1 */ | ||
607 | &(nid_objs[113]),/* OBJ_dsaWithSHA1 1 2 840 10040 4 3 */ | ||
608 | &(nid_objs[57]),/* OBJ_netscape 2 16 840 1 113730 */ | ||
609 | &(nid_objs[27]),/* OBJ_pkcs3 1 2 840 113549 1 3 */ | ||
610 | &(nid_objs[20]),/* OBJ_pkcs7 1 2 840 113549 1 7 */ | ||
611 | &(nid_objs[47]),/* OBJ_pkcs9 1 2 840 113549 1 9 */ | ||
612 | &(nid_objs[ 3]),/* OBJ_md2 1 2 840 113549 2 2 */ | ||
613 | &(nid_objs[ 4]),/* OBJ_md5 1 2 840 113549 2 5 */ | ||
614 | &(nid_objs[37]),/* OBJ_rc2_cbc 1 2 840 113549 3 2 */ | ||
615 | &(nid_objs[ 5]),/* OBJ_rc4 1 2 840 113549 3 4 */ | ||
616 | &(nid_objs[44]),/* OBJ_des_ede3_cbc 1 2 840 113549 3 7 */ | ||
617 | &(nid_objs[120]),/* OBJ_rc5_cbc 1 2 840 113549 3 8 */ | ||
618 | &(nid_objs[58]),/* OBJ_netscape_cert_extension 2 16 840 1 113730 1 */ | ||
619 | &(nid_objs[59]),/* OBJ_netscape_data_type 2 16 840 1 113730 2 */ | ||
620 | &(nid_objs[108]),/* OBJ_cast5_cbc 1 2 840 113533 7 66 10 */ | ||
621 | &(nid_objs[112]),/* OBJ_pbeWithMD5AndCast5_CBC 1 2 840 113533 7 66 12 */ | ||
622 | &(nid_objs[ 6]),/* OBJ_rsaEncryption 1 2 840 113549 1 1 1 */ | ||
623 | &(nid_objs[ 7]),/* OBJ_md2WithRSAEncryption 1 2 840 113549 1 1 2 */ | ||
624 | &(nid_objs[ 8]),/* OBJ_md5WithRSAEncryption 1 2 840 113549 1 1 4 */ | ||
625 | &(nid_objs[65]),/* OBJ_sha1WithRSAEncryption 1 2 840 113549 1 1 5 */ | ||
626 | &(nid_objs[28]),/* OBJ_dhKeyAgreement 1 2 840 113549 1 3 1 */ | ||
627 | &(nid_objs[ 9]),/* OBJ_pbeWithMD2AndDES_CBC 1 2 840 113549 1 5 1 */ | ||
628 | &(nid_objs[10]),/* OBJ_pbeWithMD5AndDES_CBC 1 2 840 113549 1 5 3 */ | ||
629 | &(nid_objs[68]),/* OBJ_pbeWithSHA1AndRC2_CBC 1 2 840 113549 1 5 11 */ | ||
630 | &(nid_objs[69]),/* OBJ_pbeWithSHA1AndRC4 1 2 840 113549 1 5 12 */ | ||
631 | &(nid_objs[21]),/* OBJ_pkcs7_data 1 2 840 113549 1 7 1 */ | ||
632 | &(nid_objs[22]),/* OBJ_pkcs7_signed 1 2 840 113549 1 7 2 */ | ||
633 | &(nid_objs[23]),/* OBJ_pkcs7_enveloped 1 2 840 113549 1 7 3 */ | ||
634 | &(nid_objs[24]),/* OBJ_pkcs7_signedAndEnveloped 1 2 840 113549 1 7 4 */ | ||
635 | &(nid_objs[25]),/* OBJ_pkcs7_digest 1 2 840 113549 1 7 5 */ | ||
636 | &(nid_objs[26]),/* OBJ_pkcs7_encrypted 1 2 840 113549 1 7 6 */ | ||
637 | &(nid_objs[48]),/* OBJ_pkcs9_emailAddress 1 2 840 113549 1 9 1 */ | ||
638 | &(nid_objs[49]),/* OBJ_pkcs9_unstructuredName 1 2 840 113549 1 9 2 */ | ||
639 | &(nid_objs[50]),/* OBJ_pkcs9_contentType 1 2 840 113549 1 9 3 */ | ||
640 | &(nid_objs[51]),/* OBJ_pkcs9_messageDigest 1 2 840 113549 1 9 4 */ | ||
641 | &(nid_objs[52]),/* OBJ_pkcs9_signingTime 1 2 840 113549 1 9 5 */ | ||
642 | &(nid_objs[53]),/* OBJ_pkcs9_countersignature 1 2 840 113549 1 9 6 */ | ||
643 | &(nid_objs[54]),/* OBJ_pkcs9_challengePassword 1 2 840 113549 1 9 7 */ | ||
644 | &(nid_objs[55]),/* OBJ_pkcs9_unstructuredAddress 1 2 840 113549 1 9 8 */ | ||
645 | &(nid_objs[56]),/* OBJ_pkcs9_extCertAttributes 1 2 840 113549 1 9 9 */ | ||
646 | &(nid_objs[71]),/* OBJ_netscape_cert_type 2 16 840 1 113730 1 1 */ | ||
647 | &(nid_objs[72]),/* OBJ_netscape_base_url 2 16 840 1 113730 1 2 */ | ||
648 | &(nid_objs[73]),/* OBJ_netscape_revocation_url 2 16 840 1 113730 1 3 */ | ||
649 | &(nid_objs[74]),/* OBJ_netscape_ca_revocation_url 2 16 840 1 113730 1 4 */ | ||
650 | &(nid_objs[75]),/* OBJ_netscape_renewal_url 2 16 840 1 113730 1 7 */ | ||
651 | &(nid_objs[76]),/* OBJ_netscape_ca_policy_url 2 16 840 1 113730 1 8 */ | ||
652 | &(nid_objs[77]),/* OBJ_netscape_ssl_server_name 2 16 840 1 113730 1 12 */ | ||
653 | &(nid_objs[78]),/* OBJ_netscape_comment 2 16 840 1 113730 1 13 */ | ||
654 | &(nid_objs[79]),/* OBJ_netscape_cert_sequence 2 16 840 1 113730 2 5 */ | ||
655 | }; | ||
656 | |||
diff --git a/src/lib/libcrypto/perlasm/x86ms.pl b/src/lib/libcrypto/perlasm/x86ms.pl new file mode 100644 index 0000000000..893b50b1a4 --- /dev/null +++ b/src/lib/libcrypto/perlasm/x86ms.pl | |||
@@ -0,0 +1,348 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | package x86ms; | ||
4 | |||
5 | $label="L000"; | ||
6 | |||
7 | %lb=( 'eax', 'al', | ||
8 | 'ebx', 'bl', | ||
9 | 'ecx', 'cl', | ||
10 | 'edx', 'dl', | ||
11 | 'ax', 'al', | ||
12 | 'bx', 'bl', | ||
13 | 'cx', 'cl', | ||
14 | 'dx', 'dl', | ||
15 | ); | ||
16 | |||
17 | %hb=( 'eax', 'ah', | ||
18 | 'ebx', 'bh', | ||
19 | 'ecx', 'ch', | ||
20 | 'edx', 'dh', | ||
21 | 'ax', 'ah', | ||
22 | 'bx', 'bh', | ||
23 | 'cx', 'ch', | ||
24 | 'dx', 'dh', | ||
25 | ); | ||
26 | |||
27 | sub main'asm_init_output { @out=(); } | ||
28 | sub main'asm_get_output { return(@out); } | ||
29 | sub main'get_labels { return(@labels); } | ||
30 | sub main'external_label { push(@labels,@_); } | ||
31 | |||
32 | sub main'LB | ||
33 | { | ||
34 | (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n"; | ||
35 | return($lb{$_[0]}); | ||
36 | } | ||
37 | |||
38 | sub main'HB | ||
39 | { | ||
40 | (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n"; | ||
41 | return($hb{$_[0]}); | ||
42 | } | ||
43 | |||
44 | sub main'BP | ||
45 | { | ||
46 | &get_mem("BYTE",@_); | ||
47 | } | ||
48 | |||
49 | sub main'DWP | ||
50 | { | ||
51 | &get_mem("DWORD",@_); | ||
52 | } | ||
53 | |||
54 | sub main'stack_push | ||
55 | { | ||
56 | local($num)=@_; | ||
57 | $stack+=$num*4; | ||
58 | &main'sub("esp",$num*4); | ||
59 | } | ||
60 | |||
61 | sub main'stack_pop | ||
62 | { | ||
63 | local($num)=@_; | ||
64 | $stack-=$num*4; | ||
65 | &main'add("esp",$num*4); | ||
66 | } | ||
67 | |||
68 | sub get_mem | ||
69 | { | ||
70 | local($size,$addr,$reg1,$reg2,$idx)=@_; | ||
71 | local($t,$post); | ||
72 | local($ret)="$size PTR "; | ||
73 | |||
74 | $addr =~ s/^\s+//; | ||
75 | if ($addr =~ /^(.+)\+(.+)$/) | ||
76 | { | ||
77 | $reg2=&conv($1); | ||
78 | $addr="_$2"; | ||
79 | } | ||
80 | elsif ($addr =~ /^[_a-zA-Z]/) | ||
81 | { | ||
82 | $addr="_$addr"; | ||
83 | } | ||
84 | |||
85 | $reg1="$regs{$reg1}" if defined($regs{$reg1}); | ||
86 | $reg2="$regs{$reg2}" if defined($regs{$reg2}); | ||
87 | if (($addr ne "") && ($addr ne 0)) | ||
88 | { | ||
89 | if ($addr !~ /^-/) | ||
90 | { $ret.=$addr; } | ||
91 | else { $post=$addr; } | ||
92 | } | ||
93 | if ($reg2 ne "") | ||
94 | { | ||
95 | $t=""; | ||
96 | $t="*$idx" if ($idx != 0); | ||
97 | $reg1="+".$reg1 if ("$reg1$post" ne ""); | ||
98 | $ret.="[$reg2$t$reg1$post]"; | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | $ret.="[$reg1$post]" | ||
103 | } | ||
104 | return($ret); | ||
105 | } | ||
106 | |||
107 | sub main'mov { &out2("mov",@_); } | ||
108 | sub main'movb { &out2("mov",@_); } | ||
109 | sub main'and { &out2("and",@_); } | ||
110 | sub main'or { &out2("or",@_); } | ||
111 | sub main'shl { &out2("shl",@_); } | ||
112 | sub main'shr { &out2("shr",@_); } | ||
113 | sub main'xor { &out2("xor",@_); } | ||
114 | sub main'xorb { &out2("xor",@_); } | ||
115 | sub main'add { &out2("add",@_); } | ||
116 | sub main'adc { &out2("adc",@_); } | ||
117 | sub main'sub { &out2("sub",@_); } | ||
118 | sub main'rotl { &out2("rol",@_); } | ||
119 | sub main'rotr { &out2("ror",@_); } | ||
120 | sub main'exch { &out2("xchg",@_); } | ||
121 | sub main'cmp { &out2("cmp",@_); } | ||
122 | sub main'lea { &out2("lea",@_); } | ||
123 | sub main'mul { &out1("mul",@_); } | ||
124 | sub main'div { &out1("div",@_); } | ||
125 | sub main'dec { &out1("dec",@_); } | ||
126 | sub main'inc { &out1("inc",@_); } | ||
127 | sub main'jmp { &out1("jmp",@_); } | ||
128 | sub main'jmp_ptr { &out1p("jmp",@_); } | ||
129 | sub main'je { &out1("je",@_); } | ||
130 | sub main'jle { &out1("jle",@_); } | ||
131 | sub main'jz { &out1("jz",@_); } | ||
132 | sub main'jge { &out1("jge",@_); } | ||
133 | sub main'jl { &out1("jl",@_); } | ||
134 | sub main'jb { &out1("jb",@_); } | ||
135 | sub main'jc { &out1("jc",@_); } | ||
136 | sub main'jnc { &out1("jnc",@_); } | ||
137 | sub main'jnz { &out1("jnz",@_); } | ||
138 | sub main'jne { &out1("jne",@_); } | ||
139 | sub main'jno { &out1("jno",@_); } | ||
140 | sub main'push { &out1("push",@_); $stack+=4; } | ||
141 | sub main'pop { &out1("pop",@_); $stack-=4; } | ||
142 | sub main'bswap { &out1("bswap",@_); &using486(); } | ||
143 | sub main'not { &out1("not",@_); } | ||
144 | sub main'call { &out1("call",'_'.$_[0]); } | ||
145 | sub main'ret { &out0("ret"); } | ||
146 | sub main'nop { &out0("nop"); } | ||
147 | |||
148 | sub out2 | ||
149 | { | ||
150 | local($name,$p1,$p2)=@_; | ||
151 | local($l,$t); | ||
152 | |||
153 | push(@out,"\t$name\t"); | ||
154 | $t=&conv($p1).","; | ||
155 | $l=length($t); | ||
156 | push(@out,$t); | ||
157 | $l=4-($l+9)/8; | ||
158 | push(@out,"\t" x $l); | ||
159 | push(@out,&conv($p2)); | ||
160 | push(@out,"\n"); | ||
161 | } | ||
162 | |||
163 | sub out0 | ||
164 | { | ||
165 | local($name)=@_; | ||
166 | |||
167 | push(@out,"\t$name\n"); | ||
168 | } | ||
169 | |||
170 | sub out1 | ||
171 | { | ||
172 | local($name,$p1)=@_; | ||
173 | local($l,$t); | ||
174 | |||
175 | push(@out,"\t$name\t".&conv($p1)."\n"); | ||
176 | } | ||
177 | |||
178 | sub conv | ||
179 | { | ||
180 | local($p)=@_; | ||
181 | |||
182 | $p =~ s/0x([0-9A-Fa-f]+)/0$1h/; | ||
183 | return $p; | ||
184 | } | ||
185 | |||
186 | sub using486 | ||
187 | { | ||
188 | return if $using486; | ||
189 | $using486++; | ||
190 | grep(s/\.386/\.486/,@out); | ||
191 | } | ||
192 | |||
193 | sub main'file | ||
194 | { | ||
195 | local($file)=@_; | ||
196 | |||
197 | local($tmp)=<<"EOF"; | ||
198 | TITLE $file.asm | ||
199 | .386 | ||
200 | .model FLAT | ||
201 | EOF | ||
202 | push(@out,$tmp); | ||
203 | } | ||
204 | |||
205 | sub main'function_begin | ||
206 | { | ||
207 | local($func,$extra)=@_; | ||
208 | |||
209 | push(@labels,$func); | ||
210 | |||
211 | local($tmp)=<<"EOF"; | ||
212 | _TEXT SEGMENT | ||
213 | PUBLIC _$func | ||
214 | $extra | ||
215 | _$func PROC NEAR | ||
216 | push ebp | ||
217 | push ebx | ||
218 | push esi | ||
219 | push edi | ||
220 | EOF | ||
221 | push(@out,$tmp); | ||
222 | $stack=20; | ||
223 | } | ||
224 | |||
225 | sub main'function_begin_B | ||
226 | { | ||
227 | local($func,$extra)=@_; | ||
228 | |||
229 | local($tmp)=<<"EOF"; | ||
230 | _TEXT SEGMENT | ||
231 | PUBLIC _$func | ||
232 | $extra | ||
233 | _$func PROC NEAR | ||
234 | EOF | ||
235 | push(@out,$tmp); | ||
236 | $stack=4; | ||
237 | } | ||
238 | |||
239 | sub main'function_end | ||
240 | { | ||
241 | local($func)=@_; | ||
242 | |||
243 | local($tmp)=<<"EOF"; | ||
244 | pop edi | ||
245 | pop esi | ||
246 | pop ebx | ||
247 | pop ebp | ||
248 | ret | ||
249 | _$func ENDP | ||
250 | _TEXT ENDS | ||
251 | EOF | ||
252 | push(@out,$tmp); | ||
253 | $stack=0; | ||
254 | %label=(); | ||
255 | } | ||
256 | |||
257 | sub main'function_end_B | ||
258 | { | ||
259 | local($func)=@_; | ||
260 | |||
261 | local($tmp)=<<"EOF"; | ||
262 | _$func ENDP | ||
263 | _TEXT ENDS | ||
264 | EOF | ||
265 | push(@out,$tmp); | ||
266 | $stack=0; | ||
267 | %label=(); | ||
268 | } | ||
269 | |||
270 | sub main'function_end_A | ||
271 | { | ||
272 | local($func)=@_; | ||
273 | |||
274 | local($tmp)=<<"EOF"; | ||
275 | pop edi | ||
276 | pop esi | ||
277 | pop ebx | ||
278 | pop ebp | ||
279 | ret | ||
280 | EOF | ||
281 | push(@out,$tmp); | ||
282 | } | ||
283 | |||
284 | sub main'file_end | ||
285 | { | ||
286 | push(@out,"END\n"); | ||
287 | } | ||
288 | |||
289 | sub main'wparam | ||
290 | { | ||
291 | local($num)=@_; | ||
292 | |||
293 | return(&main'DWP($stack+$num*4,"esp","",0)); | ||
294 | } | ||
295 | |||
296 | sub main'swtmp | ||
297 | { | ||
298 | return(&main'DWP($_[0]*4,"esp","",0)); | ||
299 | } | ||
300 | |||
301 | # Should use swtmp, which is above esp. Linix can trash the stack above esp | ||
302 | #sub main'wtmp | ||
303 | # { | ||
304 | # local($num)=@_; | ||
305 | # | ||
306 | # return(&main'DWP(-(($num+1)*4),"esp","",0)); | ||
307 | # } | ||
308 | |||
309 | sub main'comment | ||
310 | { | ||
311 | foreach (@_) | ||
312 | { | ||
313 | push(@out,"\t; $_\n"); | ||
314 | } | ||
315 | } | ||
316 | |||
317 | sub main'label | ||
318 | { | ||
319 | if (!defined($label{$_[0]})) | ||
320 | { | ||
321 | $label{$_[0]}="\$${label}${_[0]}"; | ||
322 | $label++; | ||
323 | } | ||
324 | return($label{$_[0]}); | ||
325 | } | ||
326 | |||
327 | sub main'set_label | ||
328 | { | ||
329 | if (!defined($label{$_[0]})) | ||
330 | { | ||
331 | $label{$_[0]}="${label}${_[0]}"; | ||
332 | $label++; | ||
333 | } | ||
334 | push(@out,"$label{$_[0]}:\n"); | ||
335 | } | ||
336 | |||
337 | sub main'data_word | ||
338 | { | ||
339 | push(@out,"\tDD\t$_[0]\n"); | ||
340 | } | ||
341 | |||
342 | sub out1p | ||
343 | { | ||
344 | local($name,$p1)=@_; | ||
345 | local($l,$t); | ||
346 | |||
347 | push(@out,"\t$name\t ".&conv($p1)."\n"); | ||
348 | } | ||
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl new file mode 100644 index 0000000000..6ee4dd3245 --- /dev/null +++ b/src/lib/libcrypto/perlasm/x86unix.pl | |||
@@ -0,0 +1,429 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | # Because the bswapl instruction is not supported for old assembers | ||
4 | # (it was a new instruction for the 486), I've added .byte xxxx code | ||
5 | # to put it in. | ||
6 | # eric 24-Apr-1998 | ||
7 | # | ||
8 | |||
9 | package x86unix; | ||
10 | |||
11 | $label="L000"; | ||
12 | |||
13 | $align=($main'aout)?"4":"16"; | ||
14 | $under=($main'aout)?"_":""; | ||
15 | $com_start=($main'sol)?"/":"#"; | ||
16 | |||
17 | sub main'asm_init_output { @out=(); } | ||
18 | sub main'asm_get_output { return(@out); } | ||
19 | sub main'get_labels { return(@labels); } | ||
20 | sub main'external_label { push(@labels,@_); } | ||
21 | |||
22 | if ($main'cpp) | ||
23 | { | ||
24 | $align="ALIGN"; | ||
25 | $under=""; | ||
26 | $com_start='/*'; | ||
27 | $com_end='*/'; | ||
28 | } | ||
29 | |||
30 | %lb=( 'eax', '%al', | ||
31 | 'ebx', '%bl', | ||
32 | 'ecx', '%cl', | ||
33 | 'edx', '%dl', | ||
34 | 'ax', '%al', | ||
35 | 'bx', '%bl', | ||
36 | 'cx', '%cl', | ||
37 | 'dx', '%dl', | ||
38 | ); | ||
39 | |||
40 | %hb=( 'eax', '%ah', | ||
41 | 'ebx', '%bh', | ||
42 | 'ecx', '%ch', | ||
43 | 'edx', '%dh', | ||
44 | 'ax', '%ah', | ||
45 | 'bx', '%bh', | ||
46 | 'cx', '%ch', | ||
47 | 'dx', '%dh', | ||
48 | ); | ||
49 | |||
50 | %regs=( 'eax', '%eax', | ||
51 | 'ebx', '%ebx', | ||
52 | 'ecx', '%ecx', | ||
53 | 'edx', '%edx', | ||
54 | 'esi', '%esi', | ||
55 | 'edi', '%edi', | ||
56 | 'ebp', '%ebp', | ||
57 | 'esp', '%esp', | ||
58 | ); | ||
59 | |||
60 | %reg_val=( | ||
61 | 'eax', 0x00, | ||
62 | 'ebx', 0x03, | ||
63 | 'ecx', 0x01, | ||
64 | 'edx', 0x02, | ||
65 | 'esi', 0x06, | ||
66 | 'edi', 0x07, | ||
67 | 'ebp', 0x05, | ||
68 | 'esp', 0x04, | ||
69 | ); | ||
70 | |||
71 | sub main'LB | ||
72 | { | ||
73 | (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n"; | ||
74 | return($lb{$_[0]}); | ||
75 | } | ||
76 | |||
77 | sub main'HB | ||
78 | { | ||
79 | (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n"; | ||
80 | return($hb{$_[0]}); | ||
81 | } | ||
82 | |||
83 | sub main'DWP | ||
84 | { | ||
85 | local($addr,$reg1,$reg2,$idx)=@_; | ||
86 | |||
87 | $ret=""; | ||
88 | $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/; | ||
89 | $reg1="$regs{$reg1}" if defined($regs{$reg1}); | ||
90 | $reg2="$regs{$reg2}" if defined($regs{$reg2}); | ||
91 | $ret.=$addr if ($addr ne "") && ($addr ne 0); | ||
92 | if ($reg2 ne "") | ||
93 | { $ret.="($reg1,$reg2,$idx)"; } | ||
94 | else | ||
95 | { $ret.="($reg1)" } | ||
96 | return($ret); | ||
97 | } | ||
98 | |||
99 | sub main'BP | ||
100 | { | ||
101 | return(&main'DWP(@_)); | ||
102 | } | ||
103 | |||
104 | #sub main'BP | ||
105 | # { | ||
106 | # local($addr,$reg1,$reg2,$idx)=@_; | ||
107 | # | ||
108 | # $ret=""; | ||
109 | # | ||
110 | # $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/; | ||
111 | # $reg1="$regs{$reg1}" if defined($regs{$reg1}); | ||
112 | # $reg2="$regs{$reg2}" if defined($regs{$reg2}); | ||
113 | # $ret.=$addr if ($addr ne "") && ($addr ne 0); | ||
114 | # if ($reg2 ne "") | ||
115 | # { $ret.="($reg1,$reg2,$idx)"; } | ||
116 | # else | ||
117 | # { $ret.="($reg1)" } | ||
118 | # return($ret); | ||
119 | # } | ||
120 | |||
121 | sub main'mov { &out2("movl",@_); } | ||
122 | sub main'movb { &out2("movb",@_); } | ||
123 | sub main'and { &out2("andl",@_); } | ||
124 | sub main'or { &out2("orl",@_); } | ||
125 | sub main'shl { &out2("sall",@_); } | ||
126 | sub main'shr { &out2("shrl",@_); } | ||
127 | sub main'xor { &out2("xorl",@_); } | ||
128 | sub main'xorb { &out2("xorb",@_); } | ||
129 | sub main'add { &out2("addl",@_); } | ||
130 | sub main'adc { &out2("adcl",@_); } | ||
131 | sub main'sub { &out2("subl",@_); } | ||
132 | sub main'rotl { &out2("roll",@_); } | ||
133 | sub main'rotr { &out2("rorl",@_); } | ||
134 | sub main'exch { &out2("xchg",@_); } | ||
135 | sub main'cmp { &out2("cmpl",@_); } | ||
136 | sub main'lea { &out2("leal",@_); } | ||
137 | sub main'mul { &out1("mull",@_); } | ||
138 | sub main'div { &out1("divl",@_); } | ||
139 | sub main'jmp { &out1("jmp",@_); } | ||
140 | sub main'jmp_ptr { &out1p("jmp",@_); } | ||
141 | sub main'je { &out1("je",@_); } | ||
142 | sub main'jle { &out1("jle",@_); } | ||
143 | sub main'jne { &out1("jne",@_); } | ||
144 | sub main'jnz { &out1("jnz",@_); } | ||
145 | sub main'jz { &out1("jz",@_); } | ||
146 | sub main'jge { &out1("jge",@_); } | ||
147 | sub main'jl { &out1("jl",@_); } | ||
148 | sub main'jb { &out1("jb",@_); } | ||
149 | sub main'jc { &out1("jc",@_); } | ||
150 | sub main'jnc { &out1("jnc",@_); } | ||
151 | sub main'jno { &out1("jno",@_); } | ||
152 | sub main'dec { &out1("decl",@_); } | ||
153 | sub main'inc { &out1("incl",@_); } | ||
154 | sub main'push { &out1("pushl",@_); $stack+=4; } | ||
155 | sub main'pop { &out1("popl",@_); $stack-=4; } | ||
156 | sub main'bswap { &out1("bswapl",@_); } | ||
157 | sub main'not { &out1("notl",@_); } | ||
158 | sub main'call { &out1("call",$under.$_[0]); } | ||
159 | sub main'ret { &out0("ret"); } | ||
160 | sub main'nop { &out0("nop"); } | ||
161 | |||
162 | sub out2 | ||
163 | { | ||
164 | local($name,$p1,$p2)=@_; | ||
165 | local($l,$ll,$t); | ||
166 | local(%special)=( "roll",0xD1C0,"rorl",0xD1C8, | ||
167 | "rcll",0xD1D0,"rcrl",0xD1D8, | ||
168 | "shll",0xD1E0,"shrl",0xD1E8, | ||
169 | "sarl",0xD1F8); | ||
170 | |||
171 | if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1)) | ||
172 | { | ||
173 | $op=$special{$name}|$reg_val{$p1}; | ||
174 | $tmp1=sprintf(".byte %d\n",($op>>8)&0xff); | ||
175 | $tmp2=sprintf(".byte %d\t",$op &0xff); | ||
176 | push(@out,$tmp1); | ||
177 | push(@out,$tmp2); | ||
178 | |||
179 | $p2=&conv($p2); | ||
180 | $p1=&conv($p1); | ||
181 | &main'comment("$name $p2 $p1"); | ||
182 | return; | ||
183 | } | ||
184 | |||
185 | push(@out,"\t$name\t"); | ||
186 | $t=&conv($p2).","; | ||
187 | $l=length($t); | ||
188 | push(@out,$t); | ||
189 | $ll=4-($l+9)/8; | ||
190 | $tmp1=sprintf("\t" x $ll); | ||
191 | push(@out,$tmp1); | ||
192 | push(@out,&conv($p1)."\n"); | ||
193 | } | ||
194 | |||
195 | sub out1 | ||
196 | { | ||
197 | local($name,$p1)=@_; | ||
198 | local($l,$t); | ||
199 | local(%special)=("bswapl",0x0FC8); | ||
200 | |||
201 | if ((defined($special{$name})) && defined($regs{$p1})) | ||
202 | { | ||
203 | $op=$special{$name}|$reg_val{$p1}; | ||
204 | $tmp1=sprintf(".byte %d\n",($op>>8)&0xff); | ||
205 | $tmp2=sprintf(".byte %d\t",$op &0xff); | ||
206 | push(@out,$tmp1); | ||
207 | push(@out,$tmp2); | ||
208 | |||
209 | $p2=&conv($p2); | ||
210 | $p1=&conv($p1); | ||
211 | &main'comment("$name $p2 $p1"); | ||
212 | return; | ||
213 | } | ||
214 | |||
215 | push(@out,"\t$name\t".&conv($p1)."\n"); | ||
216 | } | ||
217 | |||
218 | sub out1p | ||
219 | { | ||
220 | local($name,$p1)=@_; | ||
221 | local($l,$t); | ||
222 | |||
223 | push(@out,"\t$name\t*".&conv($p1)."\n"); | ||
224 | } | ||
225 | |||
226 | sub out0 | ||
227 | { | ||
228 | push(@out,"\t$_[0]\n"); | ||
229 | } | ||
230 | |||
231 | sub conv | ||
232 | { | ||
233 | local($p)=@_; | ||
234 | |||
235 | # $p =~ s/0x([0-9A-Fa-f]+)/0$1h/; | ||
236 | |||
237 | $p=$regs{$p} if (defined($regs{$p})); | ||
238 | |||
239 | $p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/; | ||
240 | $p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/; | ||
241 | return $p; | ||
242 | } | ||
243 | |||
244 | sub main'file | ||
245 | { | ||
246 | local($file)=@_; | ||
247 | |||
248 | local($tmp)=<<"EOF"; | ||
249 | .file "$file.s" | ||
250 | .version "01.01" | ||
251 | gcc2_compiled.: | ||
252 | EOF | ||
253 | push(@out,$tmp); | ||
254 | } | ||
255 | |||
256 | sub main'function_begin | ||
257 | { | ||
258 | local($func)=@_; | ||
259 | |||
260 | &main'external_label($func); | ||
261 | $func=$under.$func; | ||
262 | |||
263 | local($tmp)=<<"EOF"; | ||
264 | .text | ||
265 | .align $align | ||
266 | .globl $func | ||
267 | EOF | ||
268 | push(@out,$tmp); | ||
269 | if ($main'cpp) | ||
270 | { $tmp=push(@out,"\tTYPE($func,\@function)\n"); } | ||
271 | else { $tmp=push(@out,"\t.type\t$func,\@function\n"); } | ||
272 | push(@out,"$func:\n"); | ||
273 | $tmp=<<"EOF"; | ||
274 | pushl %ebp | ||
275 | pushl %ebx | ||
276 | pushl %esi | ||
277 | pushl %edi | ||
278 | |||
279 | EOF | ||
280 | push(@out,$tmp); | ||
281 | $stack=20; | ||
282 | } | ||
283 | |||
284 | sub main'function_begin_B | ||
285 | { | ||
286 | local($func,$extra)=@_; | ||
287 | |||
288 | &main'external_label($func); | ||
289 | $func=$under.$func; | ||
290 | |||
291 | local($tmp)=<<"EOF"; | ||
292 | .text | ||
293 | .align $align | ||
294 | .globl $func | ||
295 | EOF | ||
296 | push(@out,$tmp); | ||
297 | if ($main'cpp) | ||
298 | { push(@out,"\tTYPE($func,\@function)\n"); } | ||
299 | else { push(@out,"\t.type $func,\@function\n"); } | ||
300 | push(@out,"$func:\n"); | ||
301 | $stack=4; | ||
302 | } | ||
303 | |||
304 | sub main'function_end | ||
305 | { | ||
306 | local($func)=@_; | ||
307 | |||
308 | $func=$under.$func; | ||
309 | |||
310 | local($tmp)=<<"EOF"; | ||
311 | popl %edi | ||
312 | popl %esi | ||
313 | popl %ebx | ||
314 | popl %ebp | ||
315 | ret | ||
316 | .${func}_end: | ||
317 | EOF | ||
318 | push(@out,$tmp); | ||
319 | if ($main'cpp) | ||
320 | { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); } | ||
321 | else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); } | ||
322 | push(@out,".ident \"$func\"\n"); | ||
323 | $stack=0; | ||
324 | %label=(); | ||
325 | } | ||
326 | |||
327 | sub main'function_end_A | ||
328 | { | ||
329 | local($func)=@_; | ||
330 | |||
331 | local($tmp)=<<"EOF"; | ||
332 | popl %edi | ||
333 | popl %esi | ||
334 | popl %ebx | ||
335 | popl %ebp | ||
336 | ret | ||
337 | EOF | ||
338 | push(@out,$tmp); | ||
339 | } | ||
340 | |||
341 | sub main'function_end_B | ||
342 | { | ||
343 | local($func)=@_; | ||
344 | |||
345 | $func=$under.$func; | ||
346 | |||
347 | push(@out,".${func}_end:\n"); | ||
348 | if ($main'cpp) | ||
349 | { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); } | ||
350 | else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); } | ||
351 | push(@out,".ident \"desasm.pl\"\n"); | ||
352 | $stack=0; | ||
353 | %label=(); | ||
354 | } | ||
355 | |||
356 | sub main'wparam | ||
357 | { | ||
358 | local($num)=@_; | ||
359 | |||
360 | return(&main'DWP($stack+$num*4,"esp","",0)); | ||
361 | } | ||
362 | |||
363 | sub main'stack_push | ||
364 | { | ||
365 | local($num)=@_; | ||
366 | $stack+=$num*4; | ||
367 | &main'sub("esp",$num*4); | ||
368 | } | ||
369 | |||
370 | sub main'stack_pop | ||
371 | { | ||
372 | local($num)=@_; | ||
373 | $stack-=$num*4; | ||
374 | &main'add("esp",$num*4); | ||
375 | } | ||
376 | |||
377 | sub main'swtmp | ||
378 | { | ||
379 | return(&main'DWP($_[0]*4,"esp","",0)); | ||
380 | } | ||
381 | |||
382 | # Should use swtmp, which is above esp. Linix can trash the stack above esp | ||
383 | #sub main'wtmp | ||
384 | # { | ||
385 | # local($num)=@_; | ||
386 | # | ||
387 | # return(&main'DWP(-($num+1)*4,"esp","",0)); | ||
388 | # } | ||
389 | |||
390 | sub main'comment | ||
391 | { | ||
392 | foreach (@_) | ||
393 | { | ||
394 | if (/^\s*$/) | ||
395 | { push(@out,"\n"); } | ||
396 | else | ||
397 | { push(@out,"\t$com_start $_ $com_end\n"); } | ||
398 | } | ||
399 | } | ||
400 | |||
401 | sub main'label | ||
402 | { | ||
403 | if (!defined($label{$_[0]})) | ||
404 | { | ||
405 | $label{$_[0]}=".${label}${_[0]}"; | ||
406 | $label++; | ||
407 | } | ||
408 | return($label{$_[0]}); | ||
409 | } | ||
410 | |||
411 | sub main'set_label | ||
412 | { | ||
413 | if (!defined($label{$_[0]})) | ||
414 | { | ||
415 | $label{$_[0]}=".${label}${_[0]}"; | ||
416 | $label++; | ||
417 | } | ||
418 | push(@out,".align $align\n") if ($_[1] != 0); | ||
419 | push(@out,"$label{$_[0]}:\n"); | ||
420 | } | ||
421 | |||
422 | sub main'file_end | ||
423 | { | ||
424 | } | ||
425 | |||
426 | sub main'data_word | ||
427 | { | ||
428 | push(@out,"\t.long $_[0]\n"); | ||
429 | } | ||
diff --git a/src/lib/libcrypto/pkcs7/doc b/src/lib/libcrypto/pkcs7/doc new file mode 100644 index 0000000000..d2e8b7b2a3 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/doc | |||
@@ -0,0 +1,24 @@ | |||
1 | int PKCS7_set_content_type(PKCS7 *p7, int type); | ||
2 | Call to set the type of PKCS7 object we are working on | ||
3 | |||
4 | int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, | ||
5 | EVP_MD *dgst); | ||
6 | Use this to setup a signer info | ||
7 | There will also be functions to add signed and unsigned attributes. | ||
8 | |||
9 | int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i); | ||
10 | Add a signer info to the content. | ||
11 | |||
12 | int PKCS7_add_certificae(PKCS7 *p7, X509 *x509); | ||
13 | int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509); | ||
14 | |||
15 | ---- | ||
16 | |||
17 | p7=PKCS7_new(); | ||
18 | PKCS7_set_content_type(p7,NID_pkcs7_signed); | ||
19 | |||
20 | signer=PKCS7_SINGNER_INFO_new(); | ||
21 | PKCS7_SIGNER_INFO_set(signer,x509,pkey,EVP_md5()); | ||
22 | PKCS7_add_signer(py,signer); | ||
23 | |||
24 | we are now setup. | ||
diff --git a/src/lib/libcrypto/pkcs7/enc.c b/src/lib/libcrypto/pkcs7/enc.c new file mode 100644 index 0000000000..625a7c2285 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/enc.c | |||
@@ -0,0 +1,144 @@ | |||
1 | /* crypto/pkcs7/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 | #include <stdio.h> | ||
59 | #include "bio.h" | ||
60 | #include "x509.h" | ||
61 | #include "pem.h" | ||
62 | |||
63 | main(argc,argv) | ||
64 | int argc; | ||
65 | char *argv[]; | ||
66 | { | ||
67 | X509 *x509; | ||
68 | EVP_PKEY *pkey; | ||
69 | PKCS7 *p7; | ||
70 | PKCS7 *p7_data; | ||
71 | PKCS7_SIGNER_INFO *si; | ||
72 | BIO *in; | ||
73 | BIO *data,*p7bio; | ||
74 | char buf[1024*4]; | ||
75 | int i,j; | ||
76 | int nodetach=0; | ||
77 | |||
78 | EVP_add_digest(EVP_sha1()); | ||
79 | EVP_add_cipher(EVP_des_cbc()); | ||
80 | |||
81 | data=BIO_new(BIO_s_file()); | ||
82 | again: | ||
83 | if (argc > 1) | ||
84 | { | ||
85 | if (strcmp(argv[1],"-nd") == 0) | ||
86 | { | ||
87 | nodetach=1; | ||
88 | argv++; argc--; | ||
89 | goto again; | ||
90 | } | ||
91 | if (!BIO_read_filename(data,argv[1])) | ||
92 | goto err; | ||
93 | } | ||
94 | else | ||
95 | BIO_set_fp(data,stdin,BIO_NOCLOSE); | ||
96 | |||
97 | if ((in=BIO_new_file("server.pem","r")) == NULL) goto err; | ||
98 | if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err; | ||
99 | BIO_reset(in); | ||
100 | if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err; | ||
101 | BIO_free(in); | ||
102 | |||
103 | p7=PKCS7_new(); | ||
104 | PKCS7_set_type(p7,NID_pkcs7_signedAndEnveloped); | ||
105 | |||
106 | if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err; | ||
107 | |||
108 | if (!PKCS7_set_cipher(p7,EVP_des_cbc())) goto err; | ||
109 | if (PKCS7_add_recipient(p7,x509) == NULL) goto err; | ||
110 | |||
111 | /* we may want to add more */ | ||
112 | PKCS7_add_certificate(p7,x509); | ||
113 | |||
114 | |||
115 | /* Set the content of the signed to 'data' */ | ||
116 | /* PKCS7_content_new(p7,NID_pkcs7_data); not used in envelope */ | ||
117 | |||
118 | /* could be used, but not in this version :-) | ||
119 | if (!nodetach) PKCS7_set_detached(p7,1); | ||
120 | */ | ||
121 | |||
122 | if ((p7bio=PKCS7_dataInit(p7,NULL)) == NULL) goto err; | ||
123 | |||
124 | for (;;) | ||
125 | { | ||
126 | i=BIO_read(data,buf,sizeof(buf)); | ||
127 | if (i <= 0) break; | ||
128 | BIO_write(p7bio,buf,i); | ||
129 | } | ||
130 | BIO_flush(p7bio); | ||
131 | |||
132 | if (!PKCS7_dataSign(p7,p7bio)) goto err; | ||
133 | BIO_free(p7bio); | ||
134 | |||
135 | PEM_write_PKCS7(stdout,p7); | ||
136 | PKCS7_free(p7); | ||
137 | |||
138 | exit(0); | ||
139 | err: | ||
140 | ERR_load_crypto_strings(); | ||
141 | ERR_print_errors_fp(stderr); | ||
142 | exit(1); | ||
143 | } | ||
144 | |||
diff --git a/src/lib/libcrypto/pkcs7/p7/a1 b/src/lib/libcrypto/pkcs7/p7/a1 new file mode 100644 index 0000000000..56ca943762 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/p7/a1 | |||
@@ -0,0 +1,2 @@ | |||
1 | j,H>_æá_DôzEîLœ VJ³ß觬¤””E3ûáYäx%_Àk | ||
2 | 3ê)DLScñ8%ôM \ No newline at end of file | ||
diff --git a/src/lib/libcrypto/pkcs7/p7/a2 b/src/lib/libcrypto/pkcs7/p7/a2 new file mode 100644 index 0000000000..23d8fb5e93 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/p7/a2 | |||
@@ -0,0 +1 @@ | |||
k~@a”,NâM͹¼ <O( KP—é¨ ¤K²>×U¿o_½BqrmÎ?Ù t?t÷ÏéId2‰Š \ No newline at end of file | |||
diff --git a/src/lib/libcrypto/pkcs7/p7/cert.p7c b/src/lib/libcrypto/pkcs7/p7/cert.p7c new file mode 100644 index 0000000000..2b75ec05f7 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/p7/cert.p7c | |||
Binary files differ | |||
diff --git a/src/lib/libcrypto/pkcs7/p7/smime.p7m b/src/lib/libcrypto/pkcs7/p7/smime.p7m new file mode 100644 index 0000000000..2b6e6f82ba --- /dev/null +++ b/src/lib/libcrypto/pkcs7/p7/smime.p7m | |||
Binary files differ | |||
diff --git a/src/lib/libcrypto/pkcs7/p7/smime.p7s b/src/lib/libcrypto/pkcs7/p7/smime.p7s new file mode 100644 index 0000000000..2b5d4fb0e3 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/p7/smime.p7s | |||
Binary files differ | |||
diff --git a/src/lib/libcrypto/pkcs7/pk7_dgst.c b/src/lib/libcrypto/pkcs7/pk7_dgst.c new file mode 100644 index 0000000000..7769abeb1e --- /dev/null +++ b/src/lib/libcrypto/pkcs7/pk7_dgst.c | |||
@@ -0,0 +1,66 @@ | |||
1 | /* crypto/pkcs7/pk7_dgst.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "rand.h" | ||
63 | #include "objects.h" | ||
64 | #include "x509.h" | ||
65 | #include "pkcs7.h" | ||
66 | |||
diff --git a/src/lib/libcrypto/pkcs7/pk7_enc.c b/src/lib/libcrypto/pkcs7/pk7_enc.c new file mode 100644 index 0000000000..a5b6dc463f --- /dev/null +++ b/src/lib/libcrypto/pkcs7/pk7_enc.c | |||
@@ -0,0 +1,76 @@ | |||
1 | /* crypto/pkcs7/pk7_enc.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "evp.h" | ||
62 | #include "rand.h" | ||
63 | #include "objects.h" | ||
64 | #include "x509.h" | ||
65 | #include "pkcs7.h" | ||
66 | |||
67 | PKCS7_in_bio(PKCS7 *p7,BIO *in); | ||
68 | PKCS7_out_bio(PKCS7 *p7,BIO *out); | ||
69 | |||
70 | PKCS7_add_signer(PKCS7 *p7,X509 *cert,EVP_PKEY *key); | ||
71 | PKCS7_cipher(PKCS7 *p7,EVP_CIPHER *cipher); | ||
72 | |||
73 | PKCS7_Init(PKCS7 *p7); | ||
74 | PKCS7_Update(PKCS7 *p7); | ||
75 | PKCS7_Finish(PKCS7 *p7); | ||
76 | |||
diff --git a/src/lib/libcrypto/pkcs7/server.pem b/src/lib/libcrypto/pkcs7/server.pem new file mode 100644 index 0000000000..750aac2094 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/server.pem | |||
@@ -0,0 +1,24 @@ | |||
1 | issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit) | ||
2 | subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Server test cert (512 bit) | ||
3 | -----BEGIN CERTIFICATE----- | ||
4 | MIIB6TCCAVICAQAwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV | ||
5 | BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD | ||
6 | VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNOTcwNjA5MTM1NzQ2WhcNOTgwNjA5 | ||
7 | MTM1NzQ2WjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG | ||
8 | A1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxIzAhBgNVBAMTGlNlcnZlciB0ZXN0IGNl | ||
9 | cnQgKDUxMiBiaXQpMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ+zw4Qnlf8SMVIP | ||
10 | Fe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVDTGiXav6ooKXfX3j/7tdkuD8Ey2// | ||
11 | Kv7+ue0CAwEAATANBgkqhkiG9w0BAQQFAAOBgQB4TMR2CvacKE9wAsu9jyCX8YiW | ||
12 | mgCM+YoP6kt4Zkj2z5IRfm7WrycKsnpnOR+tGeqAjkCeZ6/36o9l91RvPnN1VJ/i | ||
13 | xQv2df0KFeMr00IkDdTNAdIWqFkSsZTAY2QAdgenb7MB1joejquYzO2DQIO7+wpH | ||
14 | irObpESxAZLySCmPPg== | ||
15 | -----END CERTIFICATE----- | ||
16 | -----BEGIN RSA PRIVATE KEY----- | ||
17 | MIIBPAIBAAJBAJ+zw4Qnlf8SMVIPFe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVD | ||
18 | TGiXav6ooKXfX3j/7tdkuD8Ey2//Kv7+ue0CAwEAAQJAN6W31vDEP2DjdqhzCDDu | ||
19 | OA4NACqoiFqyblo7yc2tM4h4xMbC3Yx5UKMN9ZkCtX0gzrz6DyF47bdKcWBzNWCj | ||
20 | gQIhANEoojVt7hq+SQ6MCN6FTAysGgQf56Q3TYoJMoWvdiXVAiEAw3e3rc+VJpOz | ||
21 | rHuDo6bgpjUAAXM+v3fcpsfZSNO6V7kCIQCtbVjanpUwvZkMI9by02oUk9taki3b | ||
22 | PzPfAfNPYAbCJQIhAJXNQDWyqwn/lGmR11cqY2y9nZ1+5w3yHGatLrcDnQHxAiEA | ||
23 | vnlEGo8K85u+KwIOimM48ZG8oTk7iFdkqLJR1utT3aU= | ||
24 | -----END RSA PRIVATE KEY----- | ||
diff --git a/src/lib/libcrypto/pkcs7/sign.c b/src/lib/libcrypto/pkcs7/sign.c new file mode 100644 index 0000000000..ead1cb65ca --- /dev/null +++ b/src/lib/libcrypto/pkcs7/sign.c | |||
@@ -0,0 +1,140 @@ | |||
1 | /* crypto/pkcs7/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 | #include <stdio.h> | ||
59 | #include "bio.h" | ||
60 | #include "x509.h" | ||
61 | #include "pem.h" | ||
62 | |||
63 | main(argc,argv) | ||
64 | int argc; | ||
65 | char *argv[]; | ||
66 | { | ||
67 | X509 *x509; | ||
68 | EVP_PKEY *pkey; | ||
69 | PKCS7 *p7; | ||
70 | PKCS7 *p7_data; | ||
71 | PKCS7_SIGNER_INFO *si; | ||
72 | BIO *in; | ||
73 | BIO *data,*p7bio; | ||
74 | char buf[1024*4]; | ||
75 | int i,j; | ||
76 | int nodetach=0; | ||
77 | |||
78 | EVP_add_digest(EVP_md2()); | ||
79 | EVP_add_digest(EVP_md5()); | ||
80 | EVP_add_digest(EVP_sha1()); | ||
81 | EVP_add_digest(EVP_mdc2()); | ||
82 | |||
83 | data=BIO_new(BIO_s_file()); | ||
84 | again: | ||
85 | if (argc > 1) | ||
86 | { | ||
87 | if (strcmp(argv[1],"-nd") == 0) | ||
88 | { | ||
89 | nodetach=1; | ||
90 | argv++; argc--; | ||
91 | goto again; | ||
92 | } | ||
93 | if (!BIO_read_filename(data,argv[1])) | ||
94 | goto err; | ||
95 | } | ||
96 | else | ||
97 | BIO_set_fp(data,stdin,BIO_NOCLOSE); | ||
98 | |||
99 | if ((in=BIO_new_file("server.pem","r")) == NULL) goto err; | ||
100 | if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err; | ||
101 | BIO_reset(in); | ||
102 | if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err; | ||
103 | BIO_free(in); | ||
104 | |||
105 | p7=PKCS7_new(); | ||
106 | PKCS7_set_type(p7,NID_pkcs7_signed); | ||
107 | |||
108 | if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err; | ||
109 | |||
110 | /* we may want to add more */ | ||
111 | PKCS7_add_certificate(p7,x509); | ||
112 | |||
113 | /* Set the content of the signed to 'data' */ | ||
114 | PKCS7_content_new(p7,NID_pkcs7_data); | ||
115 | |||
116 | if (!nodetach) | ||
117 | PKCS7_set_detached(p7,1); | ||
118 | |||
119 | if ((p7bio=PKCS7_dataInit(p7,NULL)) == NULL) goto err; | ||
120 | |||
121 | for (;;) | ||
122 | { | ||
123 | i=BIO_read(data,buf,sizeof(buf)); | ||
124 | if (i <= 0) break; | ||
125 | BIO_write(p7bio,buf,i); | ||
126 | } | ||
127 | |||
128 | if (!PKCS7_dataSign(p7,p7bio)) goto err; | ||
129 | BIO_free(p7bio); | ||
130 | |||
131 | PEM_write_PKCS7(stdout,p7); | ||
132 | PKCS7_free(p7); | ||
133 | |||
134 | exit(0); | ||
135 | err: | ||
136 | ERR_load_crypto_strings(); | ||
137 | ERR_print_errors_fp(stderr); | ||
138 | exit(1); | ||
139 | } | ||
140 | |||
diff --git a/src/lib/libcrypto/pkcs7/verify.c b/src/lib/libcrypto/pkcs7/verify.c new file mode 100644 index 0000000000..0e1c1b26dc --- /dev/null +++ b/src/lib/libcrypto/pkcs7/verify.c | |||
@@ -0,0 +1,238 @@ | |||
1 | /* crypto/pkcs7/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 | #include <stdio.h> | ||
59 | #include "asn1.h" | ||
60 | #include "bio.h" | ||
61 | #include "x509.h" | ||
62 | #include "pem.h" | ||
63 | |||
64 | int verify_callback(int ok, X509_STORE_CTX *ctx); | ||
65 | |||
66 | BIO *bio_err=NULL; | ||
67 | |||
68 | main(argc,argv) | ||
69 | int argc; | ||
70 | char *argv[]; | ||
71 | { | ||
72 | X509 *x509,*x; | ||
73 | PKCS7 *p7; | ||
74 | PKCS7_SIGNED *s; | ||
75 | PKCS7_SIGNER_INFO *si; | ||
76 | PKCS7_ISSUER_AND_SERIAL *ias; | ||
77 | X509_STORE_CTX cert_ctx; | ||
78 | X509_STORE *cert_store=NULL; | ||
79 | X509_LOOKUP *lookup=NULL; | ||
80 | BIO *data,*detached=NULL,*p7bio=NULL; | ||
81 | char buf[1024*4]; | ||
82 | unsigned char *p,*pp; | ||
83 | int i,j,printit=0; | ||
84 | STACK *sk; | ||
85 | |||
86 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); | ||
87 | EVP_add_digest(EVP_md2()); | ||
88 | EVP_add_digest(EVP_md5()); | ||
89 | EVP_add_digest(EVP_sha1()); | ||
90 | EVP_add_digest(EVP_mdc2()); | ||
91 | |||
92 | data=BIO_new(BIO_s_file()); | ||
93 | again: | ||
94 | pp=NULL; | ||
95 | while (argc > 1) | ||
96 | { | ||
97 | argc--; | ||
98 | argv++; | ||
99 | if (strcmp(argv[0],"-p") == 0) | ||
100 | { | ||
101 | printit=1; | ||
102 | } | ||
103 | else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2)) | ||
104 | { | ||
105 | detached=BIO_new(BIO_s_file()); | ||
106 | if (!BIO_read_filename(detached,argv[1])) | ||
107 | goto err; | ||
108 | argc--; | ||
109 | argv++; | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | pp=argv[0]; | ||
114 | if (!BIO_read_filename(data,argv[0])) | ||
115 | goto err; | ||
116 | } | ||
117 | } | ||
118 | |||
119 | if (pp == NULL) | ||
120 | BIO_set_fp(data,stdin,BIO_NOCLOSE); | ||
121 | |||
122 | |||
123 | /* Load the PKCS7 object from a file */ | ||
124 | if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL)) == NULL) goto err; | ||
125 | |||
126 | /* This stuff is being setup for certificate verification. | ||
127 | * When using SSL, it could be replaced with a | ||
128 | * cert_stre=SSL_CTX_get_cert_store(ssl_ctx); */ | ||
129 | cert_store=X509_STORE_new(); | ||
130 | X509_STORE_set_default_paths(cert_store); | ||
131 | X509_STORE_load_locations(cert_store,NULL,"../../certs"); | ||
132 | X509_STORE_set_verify_cb_func(cert_store,verify_callback); | ||
133 | |||
134 | ERR_clear_errors(); | ||
135 | |||
136 | /* We need to process the data */ | ||
137 | if (PKCS7_get_detached(p7)) | ||
138 | { | ||
139 | if (detached == NULL) | ||
140 | { | ||
141 | printf("no data to verify the signature on\n"); | ||
142 | exit(1); | ||
143 | } | ||
144 | else | ||
145 | p7bio=PKCS7_dataInit(p7,detached); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | p7bio=PKCS7_dataInit(p7,NULL); | ||
150 | } | ||
151 | |||
152 | /* We now have to 'read' from p7bio to calculate digests etc. */ | ||
153 | for (;;) | ||
154 | { | ||
155 | i=BIO_read(p7bio,buf,sizeof(buf)); | ||
156 | /* print it? */ | ||
157 | if (i <= 0) break; | ||
158 | } | ||
159 | |||
160 | /* We can now verify signatures */ | ||
161 | sk=PKCS7_get_signer_info(p7); | ||
162 | if (sk == NULL) | ||
163 | { | ||
164 | printf("there are no signatures on this data\n"); | ||
165 | exit(1); | ||
166 | } | ||
167 | |||
168 | /* Ok, first we need to, for each subject entry, see if we can verify */ | ||
169 | for (i=0; i<sk_num(sk); i++) | ||
170 | { | ||
171 | si=(PKCS7_SIGNER_INFO *)sk_value(sk,i); | ||
172 | i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si); | ||
173 | if (i <= 0) | ||
174 | goto err; | ||
175 | } | ||
176 | |||
177 | X509_STORE_free(cert_store); | ||
178 | |||
179 | printf("done\n"); | ||
180 | exit(0); | ||
181 | err: | ||
182 | ERR_load_crypto_strings(); | ||
183 | ERR_print_errors_fp(stderr); | ||
184 | exit(1); | ||
185 | } | ||
186 | |||
187 | /* should be X509 * but we can just have them as char *. */ | ||
188 | int verify_callback(ok, ctx) | ||
189 | int ok; | ||
190 | X509_STORE_CTX *ctx; | ||
191 | { | ||
192 | char buf[256]; | ||
193 | X509 *err_cert; | ||
194 | int err,depth; | ||
195 | |||
196 | err_cert=X509_STORE_CTX_get_current_cert(ctx); | ||
197 | err= X509_STORE_CTX_get_error(ctx); | ||
198 | depth= X509_STORE_CTX_get_error_depth(ctx); | ||
199 | |||
200 | X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256); | ||
201 | BIO_printf(bio_err,"depth=%d %s\n",depth,buf); | ||
202 | if (!ok) | ||
203 | { | ||
204 | BIO_printf(bio_err,"verify error:num=%d:%s\n",err, | ||
205 | X509_verify_cert_error_string(err)); | ||
206 | if (depth < 6) | ||
207 | { | ||
208 | ok=1; | ||
209 | X509_STORE_CTX_set_error(ctx,X509_V_OK); | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | ok=0; | ||
214 | X509_STORE_CTX_set_error(ctx,X509_V_ERR_CERT_CHAIN_TOO_LONG); | ||
215 | } | ||
216 | } | ||
217 | switch (ctx->error) | ||
218 | { | ||
219 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: | ||
220 | X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256); | ||
221 | BIO_printf(bio_err,"issuer= %s\n",buf); | ||
222 | break; | ||
223 | case X509_V_ERR_CERT_NOT_YET_VALID: | ||
224 | case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: | ||
225 | BIO_printf(bio_err,"notBefore="); | ||
226 | ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert)); | ||
227 | BIO_printf(bio_err,"\n"); | ||
228 | break; | ||
229 | case X509_V_ERR_CERT_HAS_EXPIRED: | ||
230 | case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: | ||
231 | BIO_printf(bio_err,"notAfter="); | ||
232 | ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert)); | ||
233 | BIO_printf(bio_err,"\n"); | ||
234 | break; | ||
235 | } | ||
236 | BIO_printf(bio_err,"verify return:%d\n",ok); | ||
237 | return(ok); | ||
238 | } | ||
diff --git a/src/lib/libcrypto/rand/md_rand.c b/src/lib/libcrypto/rand/md_rand.c new file mode 100644 index 0000000000..f44b36a8b9 --- /dev/null +++ b/src/lib/libcrypto/rand/md_rand.c | |||
@@ -0,0 +1,405 @@ | |||
1 | /* crypto/rand/md_rand.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 <sys/types.h> | ||
62 | #include <time.h> | ||
63 | |||
64 | #if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND) | ||
65 | #ifndef NO_MD5 | ||
66 | #define USE_MD5_RAND | ||
67 | #elif !defined(NO_SHA1) | ||
68 | #define USE_SHA1_RAND | ||
69 | #elif !defined(NO_MDC2) | ||
70 | #define USE_MDC2_RAND | ||
71 | #elif !defined(NO_MD2) | ||
72 | #define USE_MD2_RAND | ||
73 | #else | ||
74 | We need a message digest of some type | ||
75 | #endif | ||
76 | #endif | ||
77 | |||
78 | /* Changed how the state buffer used. I now attempt to 'wrap' such | ||
79 | * that I don't run over the same locations the next time go through | ||
80 | * the 1023 bytes - many thanks to | ||
81 | * Robert J. LeBlanc <rjl@renaissoft.com> for his comments | ||
82 | */ | ||
83 | |||
84 | #if defined(USE_MD5_RAND) | ||
85 | #include "md5.h" | ||
86 | #define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH | ||
87 | #define MD_CTX MD5_CTX | ||
88 | #define MD_Init(a) MD5_Init(a) | ||
89 | #define MD_Update(a,b,c) MD5_Update(a,b,c) | ||
90 | #define MD_Final(a,b) MD5_Final(a,b) | ||
91 | #elif defined(USE_SHA1_RAND) | ||
92 | #include "sha.h" | ||
93 | #define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH | ||
94 | #define MD_CTX SHA_CTX | ||
95 | #define MD_Init(a) SHA1_Init(a) | ||
96 | #define MD_Update(a,b,c) SHA1_Update(a,b,c) | ||
97 | #define MD_Final(a,b) SHA1_Final(a,b) | ||
98 | #elif defined(USE_MDC2_RAND) | ||
99 | #include "mdc2.h" | ||
100 | #define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH | ||
101 | #define MD_CTX MDC2_CTX | ||
102 | #define MD_Init(a) MDC2_Init(a) | ||
103 | #define MD_Update(a,b,c) MDC2_Update(a,b,c) | ||
104 | #define MD_Final(a,b) MDC2_Final(a,b) | ||
105 | #elif defined(USE_MD2_RAND) | ||
106 | #include "md2.h" | ||
107 | #define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH | ||
108 | #define MD_CTX MD2_CTX | ||
109 | #define MD_Init(a) MD2_Init(a) | ||
110 | #define MD_Update(a,b,c) MD2_Update(a,b,c) | ||
111 | #define MD_Final(a,b) MD2_Final(a,b) | ||
112 | #endif | ||
113 | |||
114 | #include "rand.h" | ||
115 | |||
116 | /*#define NORAND 1 */ | ||
117 | /*#define PREDICT 1 */ | ||
118 | |||
119 | #define STATE_SIZE 1023 | ||
120 | static int state_num=0,state_index=0; | ||
121 | static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH]; | ||
122 | static unsigned char md[MD_DIGEST_LENGTH]; | ||
123 | static int md_count=0; | ||
124 | |||
125 | char *RAND_version="RAND part of SSLeay 0.9.0b 29-Jun-1998"; | ||
126 | |||
127 | void RAND_cleanup() | ||
128 | { | ||
129 | memset(state,0,sizeof(state)); | ||
130 | state_num=0; | ||
131 | state_index=0; | ||
132 | memset(md,0,MD_DIGEST_LENGTH); | ||
133 | md_count=0; | ||
134 | } | ||
135 | |||
136 | void RAND_seed(buf,num) | ||
137 | unsigned char *buf; | ||
138 | int num; | ||
139 | { | ||
140 | int i,j,k,st_idx,st_num; | ||
141 | MD_CTX m; | ||
142 | |||
143 | #ifdef NORAND | ||
144 | return; | ||
145 | #endif | ||
146 | |||
147 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); | ||
148 | st_idx=state_index; | ||
149 | st_num=state_num; | ||
150 | |||
151 | state_index=(state_index+num); | ||
152 | if (state_index >= STATE_SIZE) | ||
153 | { | ||
154 | state_index%=STATE_SIZE; | ||
155 | state_num=STATE_SIZE; | ||
156 | } | ||
157 | else if (state_num < STATE_SIZE) | ||
158 | { | ||
159 | if (state_index > state_num) | ||
160 | state_num=state_index; | ||
161 | } | ||
162 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | ||
163 | |||
164 | for (i=0; i<num; i+=MD_DIGEST_LENGTH) | ||
165 | { | ||
166 | j=(num-i); | ||
167 | j=(j > MD_DIGEST_LENGTH)?MD_DIGEST_LENGTH:j; | ||
168 | |||
169 | MD_Init(&m); | ||
170 | MD_Update(&m,md,MD_DIGEST_LENGTH); | ||
171 | k=(st_idx+j)-STATE_SIZE; | ||
172 | if (k > 0) | ||
173 | { | ||
174 | MD_Update(&m,&(state[st_idx]),j-k); | ||
175 | MD_Update(&m,&(state[0]),k); | ||
176 | } | ||
177 | else | ||
178 | MD_Update(&m,&(state[st_idx]),j); | ||
179 | |||
180 | MD_Update(&m,buf,j); | ||
181 | MD_Final(md,&m); | ||
182 | |||
183 | buf+=j; | ||
184 | |||
185 | for (k=0; k<j; k++) | ||
186 | { | ||
187 | state[st_idx++]^=md[k]; | ||
188 | if (st_idx >= STATE_SIZE) | ||
189 | { | ||
190 | st_idx=0; | ||
191 | st_num=STATE_SIZE; | ||
192 | } | ||
193 | } | ||
194 | } | ||
195 | memset((char *)&m,0,sizeof(m)); | ||
196 | } | ||
197 | |||
198 | void RAND_bytes(buf,num) | ||
199 | unsigned char *buf; | ||
200 | int num; | ||
201 | { | ||
202 | int i,j,k,st_num,st_idx; | ||
203 | MD_CTX m; | ||
204 | static int init=1; | ||
205 | unsigned long l; | ||
206 | #ifdef DEVRANDOM | ||
207 | FILE *fh; | ||
208 | #endif | ||
209 | |||
210 | #ifdef PREDICT | ||
211 | { | ||
212 | static unsigned char val=0; | ||
213 | |||
214 | for (i=0; i<num; i++) | ||
215 | buf[i]=val++; | ||
216 | return; | ||
217 | } | ||
218 | #endif | ||
219 | |||
220 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); | ||
221 | |||
222 | if (init) | ||
223 | { | ||
224 | init=0; | ||
225 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | ||
226 | /* put in some default random data, we need more than | ||
227 | * just this */ | ||
228 | RAND_seed((unsigned char *)&m,sizeof(m)); | ||
229 | #ifndef MSDOS | ||
230 | l=getpid(); | ||
231 | RAND_seed((unsigned char *)&l,sizeof(l)); | ||
232 | l=getuid(); | ||
233 | RAND_seed((unsigned char *)&l,sizeof(l)); | ||
234 | #endif | ||
235 | l=time(NULL); | ||
236 | RAND_seed((unsigned char *)&l,sizeof(l)); | ||
237 | |||
238 | /* #ifdef DEVRANDOM */ | ||
239 | /* | ||
240 | * Use a random entropy pool device. | ||
241 | * Linux 1.3.x and FreeBSD-Current has | ||
242 | * this. Use /dev/urandom if you can | ||
243 | * as /dev/random will block if it runs out | ||
244 | * of random entries. | ||
245 | */ | ||
246 | if ((fh = fopen(DEVRANDOM, "r")) != NULL) | ||
247 | { | ||
248 | unsigned char tmpbuf[32]; | ||
249 | |||
250 | fread((unsigned char *)tmpbuf,1,32,fh); | ||
251 | /* we don't care how many bytes we read, | ||
252 | * we will just copy the 'stack' if there is | ||
253 | * nothing else :-) */ | ||
254 | fclose(fh); | ||
255 | RAND_seed(tmpbuf,32); | ||
256 | memset(tmpbuf,0,32); | ||
257 | } | ||
258 | /* #endif */ | ||
259 | #ifdef PURIFY | ||
260 | memset(state,0,STATE_SIZE); | ||
261 | memset(md,0,MD_DIGEST_LENGTH); | ||
262 | #endif | ||
263 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); | ||
264 | } | ||
265 | |||
266 | st_idx=state_index; | ||
267 | st_num=state_num; | ||
268 | state_index+=num; | ||
269 | if (state_index > state_num) | ||
270 | state_index=(state_index%state_num); | ||
271 | |||
272 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | ||
273 | |||
274 | while (num > 0) | ||
275 | { | ||
276 | j=(num >= MD_DIGEST_LENGTH/2)?MD_DIGEST_LENGTH/2:num; | ||
277 | num-=j; | ||
278 | MD_Init(&m); | ||
279 | MD_Update(&m,&(md[MD_DIGEST_LENGTH/2]),MD_DIGEST_LENGTH/2); | ||
280 | #ifndef PURIFY | ||
281 | MD_Update(&m,buf,j); /* purify complains */ | ||
282 | #endif | ||
283 | k=(st_idx+j)-st_num; | ||
284 | if (k > 0) | ||
285 | { | ||
286 | MD_Update(&m,&(state[st_idx]),j-k); | ||
287 | MD_Update(&m,&(state[0]),k); | ||
288 | } | ||
289 | else | ||
290 | MD_Update(&m,&(state[st_idx]),j); | ||
291 | MD_Final(md,&m); | ||
292 | |||
293 | for (i=0; i<j; i++) | ||
294 | { | ||
295 | if (st_idx >= st_num) | ||
296 | st_idx=0; | ||
297 | state[st_idx++]^=md[i]; | ||
298 | *(buf++)=md[i+MD_DIGEST_LENGTH/2]; | ||
299 | } | ||
300 | } | ||
301 | |||
302 | MD_Init(&m); | ||
303 | MD_Update(&m,(unsigned char *)&md_count,sizeof(md_count)); md_count++; | ||
304 | MD_Update(&m,md,MD_DIGEST_LENGTH); | ||
305 | MD_Final(md,&m); | ||
306 | memset(&m,0,sizeof(m)); | ||
307 | } | ||
308 | |||
309 | #ifdef WINDOWS | ||
310 | #include <windows.h> | ||
311 | #include <rand.h> | ||
312 | |||
313 | /***************************************************************************** | ||
314 | * Initialisation function for the SSL random generator. Takes the contents | ||
315 | * of the screen as random seed. | ||
316 | * | ||
317 | * Created 960901 by Gertjan van Oosten, gertjan@West.NL, West Consulting B.V. | ||
318 | * | ||
319 | * Code adapted from | ||
320 | * <URL:http://www.microsoft.com/kb/developr/win_dk/q97193.htm>; | ||
321 | * the original copyright message is: | ||
322 | * | ||
323 | // (C) Copyright Microsoft Corp. 1993. All rights reserved. | ||
324 | // | ||
325 | // You have a royalty-free right to use, modify, reproduce and | ||
326 | // distribute the Sample Files (and/or any modified version) in | ||
327 | // any way you find useful, provided that you agree that | ||
328 | // Microsoft has no warranty obligations or liability for any | ||
329 | // Sample Application Files which are modified. | ||
330 | */ | ||
331 | /* | ||
332 | * I have modified the loading of bytes via RAND_seed() mechanism since | ||
333 | * the origional would have been very very CPU intensive since RAND_seed() | ||
334 | * does an MD5 per 16 bytes of input. The cost to digest 16 bytes is the same | ||
335 | * as that to digest 56 bytes. So under the old system, a screen of | ||
336 | * 1024*768*256 would have been CPU cost of approximatly 49,000 56 byte MD5 | ||
337 | * digests or digesting 2.7 mbytes. What I have put in place would | ||
338 | * be 48 16k MD5 digests, or efectivly 48*16+48 MD5 bytes or 816 kbytes | ||
339 | * or about 3.5 times as much. | ||
340 | * - eric | ||
341 | */ | ||
342 | void RAND_screen(void) | ||
343 | { | ||
344 | HDC hScrDC; /* screen DC */ | ||
345 | HDC hMemDC; /* memory DC */ | ||
346 | HBITMAP hBitmap; /* handle for our bitmap */ | ||
347 | HBITMAP hOldBitmap; /* handle for previous bitmap */ | ||
348 | BITMAP bm; /* bitmap properties */ | ||
349 | unsigned int size; /* size of bitmap */ | ||
350 | char *bmbits; /* contents of bitmap */ | ||
351 | int w; /* screen width */ | ||
352 | int h; /* screen height */ | ||
353 | int y; /* y-coordinate of screen lines to grab */ | ||
354 | int n = 16; /* number of screen lines to grab at a time */ | ||
355 | |||
356 | /* Create a screen DC and a memory DC compatible to screen DC */ | ||
357 | hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL); | ||
358 | hMemDC = CreateCompatibleDC(hScrDC); | ||
359 | |||
360 | /* Get screen resolution */ | ||
361 | w = GetDeviceCaps(hScrDC, HORZRES); | ||
362 | h = GetDeviceCaps(hScrDC, VERTRES); | ||
363 | |||
364 | /* Create a bitmap compatible with the screen DC */ | ||
365 | hBitmap = CreateCompatibleBitmap(hScrDC, w, n); | ||
366 | |||
367 | /* Select new bitmap into memory DC */ | ||
368 | hOldBitmap = SelectObject(hMemDC, hBitmap); | ||
369 | |||
370 | /* Get bitmap properties */ | ||
371 | GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm); | ||
372 | size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes; | ||
373 | |||
374 | bmbits = Malloc(size); | ||
375 | if (bmbits) { | ||
376 | /* Now go through the whole screen, repeatedly grabbing n lines */ | ||
377 | for (y = 0; y < h-n; y += n) | ||
378 | { | ||
379 | unsigned char md[MD_DIGEST_LENGTH]; | ||
380 | |||
381 | /* Bitblt screen DC to memory DC */ | ||
382 | BitBlt(hMemDC, 0, 0, w, n, hScrDC, 0, y, SRCCOPY); | ||
383 | |||
384 | /* Copy bitmap bits from memory DC to bmbits */ | ||
385 | GetBitmapBits(hBitmap, size, bmbits); | ||
386 | |||
387 | /* Get the MD5 of the bitmap */ | ||
388 | MD5(bmbits,size,md); | ||
389 | |||
390 | /* Seed the random generator with the MD5 digest */ | ||
391 | RAND_seed(md, MD_DIGEST_LENGTH); | ||
392 | } | ||
393 | |||
394 | Free(bmbits); | ||
395 | } | ||
396 | |||
397 | /* Select old bitmap back into memory DC */ | ||
398 | hBitmap = SelectObject(hMemDC, hOldBitmap); | ||
399 | |||
400 | /* Clean up */ | ||
401 | DeleteObject(hBitmap); | ||
402 | DeleteDC(hMemDC); | ||
403 | DeleteDC(hScrDC); | ||
404 | } | ||
405 | #endif | ||
diff --git a/src/lib/libcrypto/rand/randtest.c b/src/lib/libcrypto/rand/randtest.c new file mode 100644 index 0000000000..e0ba61e123 --- /dev/null +++ b/src/lib/libcrypto/rand/randtest.c | |||
@@ -0,0 +1,207 @@ | |||
1 | /* crypto/rand/randtest.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 <stdlib.h> | ||
61 | #include "rand.h" | ||
62 | |||
63 | /* some FIPS 140-1 random number test */ | ||
64 | /* some simple tests */ | ||
65 | |||
66 | int main() | ||
67 | { | ||
68 | unsigned char buf[2500]; | ||
69 | int i,j,k,s,sign,nsign,err=0; | ||
70 | unsigned long n1; | ||
71 | unsigned long n2[16]; | ||
72 | unsigned long runs[2][34]; | ||
73 | /*double d; */ | ||
74 | long d; | ||
75 | |||
76 | RAND_bytes(buf,2500); | ||
77 | |||
78 | n1=0; | ||
79 | for (i=0; i<16; i++) n2[i]=0; | ||
80 | for (i=0; i<34; i++) runs[0][i]=runs[1][i]=0; | ||
81 | |||
82 | /* test 1 and 2 */ | ||
83 | sign=0; | ||
84 | nsign=0; | ||
85 | for (i=0; i<2500; i++) | ||
86 | { | ||
87 | j=buf[i]; | ||
88 | |||
89 | n2[j&0x0f]++; | ||
90 | n2[(j>>4)&0x0f]++; | ||
91 | |||
92 | for (k=0; k<8; k++) | ||
93 | { | ||
94 | s=(j&0x01); | ||
95 | if (s == sign) | ||
96 | nsign++; | ||
97 | else | ||
98 | { | ||
99 | if (nsign > 34) nsign=34; | ||
100 | if (nsign != 0) | ||
101 | { | ||
102 | runs[sign][nsign-1]++; | ||
103 | if (nsign > 6) | ||
104 | runs[sign][5]++; | ||
105 | } | ||
106 | sign=s; | ||
107 | nsign=1; | ||
108 | } | ||
109 | |||
110 | if (s) n1++; | ||
111 | j>>=1; | ||
112 | } | ||
113 | } | ||
114 | if (nsign > 34) nsign=34; | ||
115 | if (nsign != 0) runs[sign][nsign-1]++; | ||
116 | |||
117 | /* test 1 */ | ||
118 | if (!((9654 < n1) && (n1 < 10346))) | ||
119 | { | ||
120 | printf("test 1 failed, X=%ld\n",n1); | ||
121 | err++; | ||
122 | } | ||
123 | printf("test 1 done\n"); | ||
124 | |||
125 | /* test 2 */ | ||
126 | #ifdef undef | ||
127 | d=0; | ||
128 | for (i=0; i<16; i++) | ||
129 | d+=n2[i]*n2[i]; | ||
130 | d=d*16.0/5000.0-5000.0; | ||
131 | if (!((1.03 < d) && (d < 57.4))) | ||
132 | { | ||
133 | printf("test 2 failed, X=%.2f\n",d); | ||
134 | err++; | ||
135 | } | ||
136 | #endif | ||
137 | d=0; | ||
138 | for (i=0; i<16; i++) | ||
139 | d+=n2[i]*n2[i]; | ||
140 | d=(d*8)/25-500000; | ||
141 | if (!((103 < d) && (d < 5740))) | ||
142 | { | ||
143 | printf("test 2 failed, X=%ld.%02ld\n",d/100L,d%100L); | ||
144 | err++; | ||
145 | } | ||
146 | printf("test 2 done\n"); | ||
147 | |||
148 | /* test 3 */ | ||
149 | for (i=0; i<2; i++) | ||
150 | { | ||
151 | if (!((2267 < runs[i][0]) && (runs[i][0] < 2733))) | ||
152 | { | ||
153 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | ||
154 | i,1,runs[i][0]); | ||
155 | err++; | ||
156 | } | ||
157 | if (!((1079 < runs[i][1]) && (runs[i][1] < 1421))) | ||
158 | { | ||
159 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | ||
160 | i,2,runs[i][1]); | ||
161 | err++; | ||
162 | } | ||
163 | if (!(( 502 < runs[i][2]) && (runs[i][2] < 748))) | ||
164 | { | ||
165 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | ||
166 | i,3,runs[i][2]); | ||
167 | err++; | ||
168 | } | ||
169 | if (!(( 223 < runs[i][3]) && (runs[i][3] < 402))) | ||
170 | { | ||
171 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | ||
172 | i,4,runs[i][3]); | ||
173 | err++; | ||
174 | } | ||
175 | if (!(( 90 < runs[i][4]) && (runs[i][4] < 223))) | ||
176 | { | ||
177 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | ||
178 | i,5,runs[i][4]); | ||
179 | err++; | ||
180 | } | ||
181 | if (!(( 90 < runs[i][5]) && (runs[i][5] < 223))) | ||
182 | { | ||
183 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | ||
184 | i,6,runs[i][5]); | ||
185 | err++; | ||
186 | } | ||
187 | } | ||
188 | printf("test 3 done\n"); | ||
189 | |||
190 | /* test 4 */ | ||
191 | if (runs[0][33] != 0) | ||
192 | { | ||
193 | printf("test 4 failed, bit=%d run=%d num=%ld\n", | ||
194 | 0,34,runs[0][33]); | ||
195 | err++; | ||
196 | } | ||
197 | if (runs[1][33] != 0) | ||
198 | { | ||
199 | printf("test 4 failed, bit=%d run=%d num=%ld\n", | ||
200 | 1,34,runs[1][33]); | ||
201 | err++; | ||
202 | } | ||
203 | printf("test 4 done\n"); | ||
204 | err=((err)?1:0); | ||
205 | exit(err); | ||
206 | return(err); | ||
207 | } | ||
diff --git a/src/lib/libcrypto/rc2/rc2speed.c b/src/lib/libcrypto/rc2/rc2speed.c new file mode 100644 index 0000000000..6cd8ea8f27 --- /dev/null +++ b/src/lib/libcrypto/rc2/rc2speed.c | |||
@@ -0,0 +1,293 @@ | |||
1 | /* crypto/rc2/rc2speed.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 | /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ | ||
60 | /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ | ||
61 | |||
62 | #ifndef MSDOS | ||
63 | #define TIMES | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | #ifndef MSDOS | ||
68 | #include <unistd.h> | ||
69 | #else | ||
70 | #include <io.h> | ||
71 | extern int exit(); | ||
72 | #endif | ||
73 | #include <signal.h> | ||
74 | #ifndef VMS | ||
75 | #ifndef _IRIX | ||
76 | #include <time.h> | ||
77 | #endif | ||
78 | #ifdef TIMES | ||
79 | #include <sys/types.h> | ||
80 | #include <sys/times.h> | ||
81 | #endif | ||
82 | #else /* VMS */ | ||
83 | #include <types.h> | ||
84 | struct tms { | ||
85 | time_t tms_utime; | ||
86 | time_t tms_stime; | ||
87 | time_t tms_uchild; /* I dunno... */ | ||
88 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
89 | } | ||
90 | #endif | ||
91 | #ifndef TIMES | ||
92 | #include <sys/timeb.h> | ||
93 | #endif | ||
94 | |||
95 | #ifdef sun | ||
96 | #include <limits.h> | ||
97 | #include <sys/param.h> | ||
98 | #endif | ||
99 | |||
100 | #include "rc2.h" | ||
101 | |||
102 | /* The following if from times(3) man page. It may need to be changed */ | ||
103 | #ifndef HZ | ||
104 | #ifndef CLK_TCK | ||
105 | #ifndef VMS | ||
106 | #define HZ 100.0 | ||
107 | #else /* VMS */ | ||
108 | #define HZ 100.0 | ||
109 | #endif | ||
110 | #else /* CLK_TCK */ | ||
111 | #define HZ ((double)CLK_TCK) | ||
112 | #endif | ||
113 | #endif | ||
114 | |||
115 | #define BUFSIZE ((long)1024) | ||
116 | long run=0; | ||
117 | |||
118 | #ifndef NOPROTO | ||
119 | double Time_F(int s); | ||
120 | #else | ||
121 | double Time_F(); | ||
122 | #endif | ||
123 | |||
124 | #ifdef SIGALRM | ||
125 | #if defined(__STDC__) || defined(sgi) || defined(_AIX) | ||
126 | #define SIGRETTYPE void | ||
127 | #else | ||
128 | #define SIGRETTYPE int | ||
129 | #endif | ||
130 | |||
131 | #ifndef NOPROTO | ||
132 | SIGRETTYPE sig_done(int sig); | ||
133 | #else | ||
134 | SIGRETTYPE sig_done(); | ||
135 | #endif | ||
136 | |||
137 | SIGRETTYPE sig_done(sig) | ||
138 | int sig; | ||
139 | { | ||
140 | signal(SIGALRM,sig_done); | ||
141 | run=0; | ||
142 | #ifdef LINT | ||
143 | sig=sig; | ||
144 | #endif | ||
145 | } | ||
146 | #endif | ||
147 | |||
148 | #define START 0 | ||
149 | #define STOP 1 | ||
150 | |||
151 | double Time_F(s) | ||
152 | int s; | ||
153 | { | ||
154 | double ret; | ||
155 | #ifdef TIMES | ||
156 | static struct tms tstart,tend; | ||
157 | |||
158 | if (s == START) | ||
159 | { | ||
160 | times(&tstart); | ||
161 | return(0); | ||
162 | } | ||
163 | else | ||
164 | { | ||
165 | times(&tend); | ||
166 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
167 | return((ret == 0.0)?1e-6:ret); | ||
168 | } | ||
169 | #else /* !times() */ | ||
170 | static struct timeb tstart,tend; | ||
171 | long i; | ||
172 | |||
173 | if (s == START) | ||
174 | { | ||
175 | ftime(&tstart); | ||
176 | return(0); | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | ftime(&tend); | ||
181 | i=(long)tend.millitm-(long)tstart.millitm; | ||
182 | ret=((double)(tend.time-tstart.time))+((double)i)/1e3; | ||
183 | return((ret == 0.0)?1e-6:ret); | ||
184 | } | ||
185 | #endif | ||
186 | } | ||
187 | |||
188 | int main(argc,argv) | ||
189 | int argc; | ||
190 | char **argv; | ||
191 | { | ||
192 | long count; | ||
193 | static unsigned char buf[BUFSIZE]; | ||
194 | static unsigned char key[] ={ | ||
195 | 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | ||
196 | 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10, | ||
197 | }; | ||
198 | RC2_KEY sch; | ||
199 | double a,b,c,d; | ||
200 | #ifndef SIGALRM | ||
201 | long ca,cb,cc; | ||
202 | #endif | ||
203 | |||
204 | #ifndef TIMES | ||
205 | printf("To get the most acurate results, try to run this\n"); | ||
206 | printf("program when this computer is idle.\n"); | ||
207 | #endif | ||
208 | |||
209 | #ifndef SIGALRM | ||
210 | printf("First we calculate the approximate speed ...\n"); | ||
211 | RC2_set_key(&sch,16,key,128); | ||
212 | count=10; | ||
213 | do { | ||
214 | long i; | ||
215 | unsigned long data[2]; | ||
216 | |||
217 | count*=2; | ||
218 | Time_F(START); | ||
219 | for (i=count; i; i--) | ||
220 | RC2_encrypt(data,&sch); | ||
221 | d=Time_F(STOP); | ||
222 | } while (d < 3.0); | ||
223 | ca=count/512; | ||
224 | cb=count; | ||
225 | cc=count*8/BUFSIZE+1; | ||
226 | printf("Doing RC2_set_key %ld times\n",ca); | ||
227 | #define COND(d) (count != (d)) | ||
228 | #define COUNT(d) (d) | ||
229 | #else | ||
230 | #define COND(c) (run) | ||
231 | #define COUNT(d) (count) | ||
232 | signal(SIGALRM,sig_done); | ||
233 | printf("Doing RC2_set_key for 10 seconds\n"); | ||
234 | alarm(10); | ||
235 | #endif | ||
236 | |||
237 | Time_F(START); | ||
238 | for (count=0,run=1; COND(ca); count+=4) | ||
239 | { | ||
240 | RC2_set_key(&sch,16,key,128); | ||
241 | RC2_set_key(&sch,16,key,128); | ||
242 | RC2_set_key(&sch,16,key,128); | ||
243 | RC2_set_key(&sch,16,key,128); | ||
244 | } | ||
245 | d=Time_F(STOP); | ||
246 | printf("%ld RC2_set_key's in %.2f seconds\n",count,d); | ||
247 | a=((double)COUNT(ca))/d; | ||
248 | |||
249 | #ifdef SIGALRM | ||
250 | printf("Doing RC2_encrypt's for 10 seconds\n"); | ||
251 | alarm(10); | ||
252 | #else | ||
253 | printf("Doing RC2_encrypt %ld times\n",cb); | ||
254 | #endif | ||
255 | Time_F(START); | ||
256 | for (count=0,run=1; COND(cb); count+=4) | ||
257 | { | ||
258 | unsigned long data[2]; | ||
259 | |||
260 | RC2_encrypt(data,&sch); | ||
261 | RC2_encrypt(data,&sch); | ||
262 | RC2_encrypt(data,&sch); | ||
263 | RC2_encrypt(data,&sch); | ||
264 | } | ||
265 | d=Time_F(STOP); | ||
266 | printf("%ld RC2_encrypt's in %.2f second\n",count,d); | ||
267 | b=((double)COUNT(cb)*8)/d; | ||
268 | |||
269 | #ifdef SIGALRM | ||
270 | printf("Doing RC2_cbc_encrypt on %ld byte blocks for 10 seconds\n", | ||
271 | BUFSIZE); | ||
272 | alarm(10); | ||
273 | #else | ||
274 | printf("Doing RC2_cbc_encrypt %ld times on %ld byte blocks\n",cc, | ||
275 | BUFSIZE); | ||
276 | #endif | ||
277 | Time_F(START); | ||
278 | for (count=0,run=1; COND(cc); count++) | ||
279 | RC2_cbc_encrypt(buf,buf,BUFSIZE,&sch, | ||
280 | &(key[0]),RC2_ENCRYPT); | ||
281 | d=Time_F(STOP); | ||
282 | printf("%ld RC2_cbc_encrypt's of %ld byte blocks in %.2f second\n", | ||
283 | count,BUFSIZE,d); | ||
284 | c=((double)COUNT(cc)*BUFSIZE)/d; | ||
285 | |||
286 | printf("RC2 set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a); | ||
287 | printf("RC2 raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b); | ||
288 | printf("RC2 cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c); | ||
289 | exit(0); | ||
290 | #if defined(LINT) || defined(MSDOS) | ||
291 | return(0); | ||
292 | #endif | ||
293 | } | ||
diff --git a/src/lib/libcrypto/rc2/rc2test.c b/src/lib/libcrypto/rc2/rc2test.c new file mode 100644 index 0000000000..9d0f8016ec --- /dev/null +++ b/src/lib/libcrypto/rc2/rc2test.c | |||
@@ -0,0 +1,270 @@ | |||
1 | /* crypto/rc2/rc2test.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 | /* This has been a quickly hacked 'ideatest.c'. When I add tests for other | ||
60 | * RC2 modes, more of the code will be uncommented. */ | ||
61 | |||
62 | #include <stdio.h> | ||
63 | #include <string.h> | ||
64 | #include <stdlib.h> | ||
65 | #include "rc2.h" | ||
66 | |||
67 | unsigned char RC2key[4][16]={ | ||
68 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
69 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
70 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
71 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, | ||
72 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
73 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
74 | {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, | ||
75 | 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F}, | ||
76 | }; | ||
77 | |||
78 | unsigned char RC2plain[4][8]={ | ||
79 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
80 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
81 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
82 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
83 | }; | ||
84 | |||
85 | unsigned char RC2cipher[4][8]={ | ||
86 | {0x1C,0x19,0x8A,0x83,0x8D,0xF0,0x28,0xB7}, | ||
87 | {0x21,0x82,0x9C,0x78,0xA9,0xF9,0xC0,0x74}, | ||
88 | {0x13,0xDB,0x35,0x17,0xD3,0x21,0x86,0x9E}, | ||
89 | {0x50,0xDC,0x01,0x62,0xBD,0x75,0x7F,0x31}, | ||
90 | }; | ||
91 | /************/ | ||
92 | #ifdef undef | ||
93 | unsigned char k[16]={ | ||
94 | 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04, | ||
95 | 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08}; | ||
96 | |||
97 | unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03}; | ||
98 | unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5}; | ||
99 | unsigned char out[80]; | ||
100 | |||
101 | char *text="Hello to all people out there"; | ||
102 | |||
103 | static unsigned char cfb_key[16]={ | ||
104 | 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, | ||
105 | 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, | ||
106 | }; | ||
107 | static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; | ||
108 | static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; | ||
109 | #define CFB_TEST_SIZE 24 | ||
110 | static unsigned char plain[CFB_TEST_SIZE]= | ||
111 | { | ||
112 | 0x4e,0x6f,0x77,0x20,0x69,0x73, | ||
113 | 0x20,0x74,0x68,0x65,0x20,0x74, | ||
114 | 0x69,0x6d,0x65,0x20,0x66,0x6f, | ||
115 | 0x72,0x20,0x61,0x6c,0x6c,0x20 | ||
116 | }; | ||
117 | static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ | ||
118 | 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, | ||
119 | 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, | ||
120 | 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 | ||
121 | |||
122 | /* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, | ||
123 | 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, | ||
124 | 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ | ||
125 | }; | ||
126 | |||
127 | |||
128 | #ifndef NOPROTO | ||
129 | /*static int cfb64_test(unsigned char *cfb_cipher);*/ | ||
130 | static char *pt(unsigned char *p); | ||
131 | #else | ||
132 | /*static int cfb64_test(); */ | ||
133 | static char *pt(); | ||
134 | #endif | ||
135 | |||
136 | #endif | ||
137 | |||
138 | int main(argc,argv) | ||
139 | int argc; | ||
140 | char *argv[]; | ||
141 | { | ||
142 | int i,n,err=0; | ||
143 | RC2_KEY key; | ||
144 | unsigned char buf[8],buf2[8]; | ||
145 | |||
146 | for (n=0; n<4; n++) | ||
147 | { | ||
148 | RC2_set_key(&key,16,&(RC2key[n][0]),0 /* or 1024 */); | ||
149 | |||
150 | RC2_ecb_encrypt(&(RC2plain[n][0]),buf,&key,RC2_ENCRYPT); | ||
151 | if (memcmp(&(RC2cipher[n][0]),buf,8) != 0) | ||
152 | { | ||
153 | printf("ecb rc2 error encrypting\n"); | ||
154 | printf("got :"); | ||
155 | for (i=0; i<8; i++) | ||
156 | printf("%02X ",buf[i]); | ||
157 | printf("\n"); | ||
158 | printf("expected:"); | ||
159 | for (i=0; i<8; i++) | ||
160 | printf("%02X ",RC2cipher[n][i]); | ||
161 | err=20; | ||
162 | printf("\n"); | ||
163 | } | ||
164 | |||
165 | RC2_ecb_encrypt(buf,buf2,&key,RC2_DECRYPT); | ||
166 | if (memcmp(&(RC2plain[n][0]),buf2,8) != 0) | ||
167 | { | ||
168 | printf("ecb RC2 error decrypting\n"); | ||
169 | printf("got :"); | ||
170 | for (i=0; i<8; i++) | ||
171 | printf("%02X ",buf[i]); | ||
172 | printf("\n"); | ||
173 | printf("expected:"); | ||
174 | for (i=0; i<8; i++) | ||
175 | printf("%02X ",RC2plain[n][i]); | ||
176 | printf("\n"); | ||
177 | err=3; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | if (err == 0) printf("ecb RC2 ok\n"); | ||
182 | #ifdef undef | ||
183 | memcpy(iv,k,8); | ||
184 | idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1); | ||
185 | memcpy(iv,k,8); | ||
186 | idea_cbc_encrypt(out,out,8,&dkey,iv,0); | ||
187 | idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0); | ||
188 | if (memcmp(text,out,strlen(text)+1) != 0) | ||
189 | { | ||
190 | printf("cbc idea bad\n"); | ||
191 | err=4; | ||
192 | } | ||
193 | else | ||
194 | printf("cbc idea ok\n"); | ||
195 | |||
196 | printf("cfb64 idea "); | ||
197 | if (cfb64_test(cfb_cipher64)) | ||
198 | { | ||
199 | printf("bad\n"); | ||
200 | err=5; | ||
201 | } | ||
202 | else | ||
203 | printf("ok\n"); | ||
204 | #endif | ||
205 | |||
206 | exit(err); | ||
207 | return(err); | ||
208 | } | ||
209 | |||
210 | #ifdef undef | ||
211 | static int cfb64_test(cfb_cipher) | ||
212 | unsigned char *cfb_cipher; | ||
213 | { | ||
214 | IDEA_KEY_SCHEDULE eks,dks; | ||
215 | int err=0,i,n; | ||
216 | |||
217 | idea_set_encrypt_key(cfb_key,&eks); | ||
218 | idea_set_decrypt_key(&eks,&dks); | ||
219 | memcpy(cfb_tmp,cfb_iv,8); | ||
220 | n=0; | ||
221 | idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks, | ||
222 | cfb_tmp,&n,IDEA_ENCRYPT); | ||
223 | idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), | ||
224 | (long)CFB_TEST_SIZE-12,&eks, | ||
225 | cfb_tmp,&n,IDEA_ENCRYPT); | ||
226 | if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0) | ||
227 | { | ||
228 | err=1; | ||
229 | printf("idea_cfb64_encrypt encrypt error\n"); | ||
230 | for (i=0; i<CFB_TEST_SIZE; i+=8) | ||
231 | printf("%s\n",pt(&(cfb_buf1[i]))); | ||
232 | } | ||
233 | memcpy(cfb_tmp,cfb_iv,8); | ||
234 | n=0; | ||
235 | idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&eks, | ||
236 | cfb_tmp,&n,IDEA_DECRYPT); | ||
237 | idea_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), | ||
238 | (long)CFB_TEST_SIZE-17,&dks, | ||
239 | cfb_tmp,&n,IDEA_DECRYPT); | ||
240 | if (memcmp(plain,cfb_buf2,CFB_TEST_SIZE) != 0) | ||
241 | { | ||
242 | err=1; | ||
243 | printf("idea_cfb_encrypt decrypt error\n"); | ||
244 | for (i=0; i<24; i+=8) | ||
245 | printf("%s\n",pt(&(cfb_buf2[i]))); | ||
246 | } | ||
247 | return(err); | ||
248 | } | ||
249 | |||
250 | static char *pt(p) | ||
251 | unsigned char *p; | ||
252 | { | ||
253 | static char bufs[10][20]; | ||
254 | static int bnum=0; | ||
255 | char *ret; | ||
256 | int i; | ||
257 | static char *f="0123456789ABCDEF"; | ||
258 | |||
259 | ret= &(bufs[bnum++][0]); | ||
260 | bnum%=10; | ||
261 | for (i=0; i<8; i++) | ||
262 | { | ||
263 | ret[i*2]=f[(p[i]>>4)&0xf]; | ||
264 | ret[i*2+1]=f[p[i]&0xf]; | ||
265 | } | ||
266 | ret[16]='\0'; | ||
267 | return(ret); | ||
268 | } | ||
269 | |||
270 | #endif | ||
diff --git a/src/lib/libcrypto/rc4/rc4.c b/src/lib/libcrypto/rc4/rc4.c new file mode 100644 index 0000000000..127e8a5093 --- /dev/null +++ b/src/lib/libcrypto/rc4/rc4.c | |||
@@ -0,0 +1,194 @@ | |||
1 | /* crypto/rc4/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 | #include <stdio.h> | ||
60 | #include <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #include "rc4.h" | ||
63 | |||
64 | char *usage[]={ | ||
65 | "usage: rc4 args\n", | ||
66 | "\n", | ||
67 | " -in arg - input file - default stdin\n", | ||
68 | " -out arg - output file - default stdout\n", | ||
69 | " -key key - password\n", | ||
70 | NULL | ||
71 | }; | ||
72 | |||
73 | int main(argc, argv) | ||
74 | int argc; | ||
75 | char *argv[]; | ||
76 | { | ||
77 | FILE *in=NULL,*out=NULL; | ||
78 | char *infile=NULL,*outfile=NULL,*keystr=NULL; | ||
79 | RC4_KEY key; | ||
80 | char buf[BUFSIZ]; | ||
81 | int badops=0,i; | ||
82 | char **pp; | ||
83 | unsigned char md[MD5_DIGEST_LENGTH]; | ||
84 | |||
85 | argc--; | ||
86 | argv++; | ||
87 | while (argc >= 1) | ||
88 | { | ||
89 | if (strcmp(*argv,"-in") == 0) | ||
90 | { | ||
91 | if (--argc < 1) goto bad; | ||
92 | infile= *(++argv); | ||
93 | } | ||
94 | else if (strcmp(*argv,"-out") == 0) | ||
95 | { | ||
96 | if (--argc < 1) goto bad; | ||
97 | outfile= *(++argv); | ||
98 | } | ||
99 | else if (strcmp(*argv,"-key") == 0) | ||
100 | { | ||
101 | if (--argc < 1) goto bad; | ||
102 | keystr= *(++argv); | ||
103 | } | ||
104 | else | ||
105 | { | ||
106 | fprintf(stderr,"unknown option %s\n",*argv); | ||
107 | badops=1; | ||
108 | break; | ||
109 | } | ||
110 | argc--; | ||
111 | argv++; | ||
112 | } | ||
113 | |||
114 | if (badops) | ||
115 | { | ||
116 | bad: | ||
117 | for (pp=usage; (*pp != NULL); pp++) | ||
118 | fprintf(stderr,*pp); | ||
119 | exit(1); | ||
120 | } | ||
121 | |||
122 | if (infile == NULL) | ||
123 | in=stdin; | ||
124 | else | ||
125 | { | ||
126 | in=fopen(infile,"r"); | ||
127 | if (in == NULL) | ||
128 | { | ||
129 | perror("open"); | ||
130 | exit(1); | ||
131 | } | ||
132 | |||
133 | } | ||
134 | if (outfile == NULL) | ||
135 | out=stdout; | ||
136 | else | ||
137 | { | ||
138 | out=fopen(outfile,"w"); | ||
139 | if (out == NULL) | ||
140 | { | ||
141 | perror("open"); | ||
142 | exit(1); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | #ifdef MSDOS | ||
147 | /* This should set the file to binary mode. */ | ||
148 | { | ||
149 | #include <fcntl.h> | ||
150 | setmode(fileno(in),O_BINARY); | ||
151 | setmode(fileno(out),O_BINARY); | ||
152 | } | ||
153 | #endif | ||
154 | |||
155 | if (keystr == NULL) | ||
156 | { /* get key */ | ||
157 | i=EVP_read_pw_string(buf,BUFSIZ,"Enter RC4 password:",0); | ||
158 | if (i != 0) | ||
159 | { | ||
160 | memset(buf,0,BUFSIZ); | ||
161 | fprintf(stderr,"bad password read\n"); | ||
162 | exit(1); | ||
163 | } | ||
164 | keystr=buf; | ||
165 | } | ||
166 | |||
167 | MD5((unsigned char *)keystr,(unsigned long)strlen(keystr),md); | ||
168 | memset(keystr,0,strlen(keystr)); | ||
169 | RC4_set_key(&key,MD5_DIGEST_LENGTH,md); | ||
170 | |||
171 | for(;;) | ||
172 | { | ||
173 | i=fread(buf,1,BUFSIZ,in); | ||
174 | if (i == 0) break; | ||
175 | if (i < 0) | ||
176 | { | ||
177 | perror("read"); | ||
178 | exit(1); | ||
179 | } | ||
180 | RC4(&key,(unsigned int)i,(unsigned char *)buf, | ||
181 | (unsigned char *)buf); | ||
182 | i=fwrite(buf,(unsigned int)i,1,out); | ||
183 | if (i != 1) | ||
184 | { | ||
185 | perror("write"); | ||
186 | exit(1); | ||
187 | } | ||
188 | } | ||
189 | fclose(out); | ||
190 | fclose(in); | ||
191 | exit(0); | ||
192 | return(1); | ||
193 | } | ||
194 | |||
diff --git a/src/lib/libcrypto/rc4/rc4s.cpp b/src/lib/libcrypto/rc4/rc4s.cpp new file mode 100644 index 0000000000..39f1727dd3 --- /dev/null +++ b/src/lib/libcrypto/rc4/rc4s.cpp | |||
@@ -0,0 +1,73 @@ | |||
1 | // | ||
2 | // gettsc.inl | ||
3 | // | ||
4 | // gives access to the Pentium's (secret) cycle counter | ||
5 | // | ||
6 | // This software was written by Leonard Janke (janke@unixg.ubc.ca) | ||
7 | // in 1996-7 and is entered, by him, into the public domain. | ||
8 | |||
9 | #if defined(__WATCOMC__) | ||
10 | void GetTSC(unsigned long&); | ||
11 | #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; | ||
12 | #elif defined(__GNUC__) | ||
13 | inline | ||
14 | void GetTSC(unsigned long& tsc) | ||
15 | { | ||
16 | asm volatile(".byte 15, 49\n\t" | ||
17 | : "=eax" (tsc) | ||
18 | : | ||
19 | : "%edx", "%eax"); | ||
20 | } | ||
21 | #elif defined(_MSC_VER) | ||
22 | inline | ||
23 | void GetTSC(unsigned long& tsc) | ||
24 | { | ||
25 | unsigned long a; | ||
26 | __asm _emit 0fh | ||
27 | __asm _emit 31h | ||
28 | __asm mov a, eax; | ||
29 | tsc=a; | ||
30 | } | ||
31 | #endif | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include <stdlib.h> | ||
35 | #include "rc4.h" | ||
36 | |||
37 | void main(int argc,char *argv[]) | ||
38 | { | ||
39 | unsigned char buffer[1024]; | ||
40 | RC4_KEY ctx; | ||
41 | unsigned long s1,s2,e1,e2; | ||
42 | unsigned char k[16]; | ||
43 | unsigned long data[2]; | ||
44 | unsigned char iv[8]; | ||
45 | int i,num=64,numm; | ||
46 | int j=0; | ||
47 | |||
48 | if (argc >= 2) | ||
49 | num=atoi(argv[1]); | ||
50 | |||
51 | if (num == 0) num=256; | ||
52 | if (num > 1024-16) num=1024-16; | ||
53 | numm=num+8; | ||
54 | |||
55 | for (j=0; j<6; j++) | ||
56 | { | ||
57 | for (i=0; i<10; i++) /**/ | ||
58 | { | ||
59 | RC4(&ctx,numm,buffer,buffer); | ||
60 | GetTSC(s1); | ||
61 | RC4(&ctx,numm,buffer,buffer); | ||
62 | GetTSC(e1); | ||
63 | GetTSC(s2); | ||
64 | RC4(&ctx,num,buffer,buffer); | ||
65 | GetTSC(e2); | ||
66 | RC4(&ctx,num,buffer,buffer); | ||
67 | } | ||
68 | |||
69 | printf("RC4 (%d bytes) %d %d (%d) - 8 bytes\n",num, | ||
70 | e1-s1,e2-s2,(e1-s1)-(e2-s2)); | ||
71 | } | ||
72 | } | ||
73 | |||
diff --git a/src/lib/libcrypto/rc4/rc4speed.c b/src/lib/libcrypto/rc4/rc4speed.c new file mode 100644 index 0000000000..5298dad6d0 --- /dev/null +++ b/src/lib/libcrypto/rc4/rc4speed.c | |||
@@ -0,0 +1,269 @@ | |||
1 | /* crypto/rc4/rc4speed.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 | /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ | ||
60 | /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ | ||
61 | |||
62 | #ifndef MSDOS | ||
63 | #define TIMES | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | #ifndef MSDOS | ||
68 | #include <unistd.h> | ||
69 | #else | ||
70 | #include <io.h> | ||
71 | extern int exit(); | ||
72 | #endif | ||
73 | #include <signal.h> | ||
74 | #ifndef VMS | ||
75 | #ifndef _IRIX | ||
76 | #include <time.h> | ||
77 | #endif | ||
78 | #ifdef TIMES | ||
79 | #include <sys/types.h> | ||
80 | #include <sys/times.h> | ||
81 | #endif | ||
82 | #else /* VMS */ | ||
83 | #include <types.h> | ||
84 | struct tms { | ||
85 | time_t tms_utime; | ||
86 | time_t tms_stime; | ||
87 | time_t tms_uchild; /* I dunno... */ | ||
88 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
89 | } | ||
90 | #endif | ||
91 | #ifndef TIMES | ||
92 | #include <sys/timeb.h> | ||
93 | #endif | ||
94 | |||
95 | #ifdef sun | ||
96 | #include <limits.h> | ||
97 | #include <sys/param.h> | ||
98 | #endif | ||
99 | |||
100 | #include "rc4.h" | ||
101 | |||
102 | /* The following if from times(3) man page. It may need to be changed */ | ||
103 | #ifndef HZ | ||
104 | #ifndef CLK_TCK | ||
105 | #ifndef VMS | ||
106 | #define HZ 100.0 | ||
107 | #else /* VMS */ | ||
108 | #define HZ 100.0 | ||
109 | #endif | ||
110 | #else /* CLK_TCK */ | ||
111 | #define HZ ((double)CLK_TCK) | ||
112 | #endif | ||
113 | #endif | ||
114 | |||
115 | #define BUFSIZE ((long)1024) | ||
116 | long run=0; | ||
117 | |||
118 | #ifndef NOPROTO | ||
119 | double Time_F(int s); | ||
120 | #else | ||
121 | double Time_F(); | ||
122 | #endif | ||
123 | |||
124 | #ifdef SIGALRM | ||
125 | #if defined(__STDC__) || defined(sgi) || defined(_AIX) | ||
126 | #define SIGRETTYPE void | ||
127 | #else | ||
128 | #define SIGRETTYPE int | ||
129 | #endif | ||
130 | |||
131 | #ifndef NOPROTO | ||
132 | SIGRETTYPE sig_done(int sig); | ||
133 | #else | ||
134 | SIGRETTYPE sig_done(); | ||
135 | #endif | ||
136 | |||
137 | SIGRETTYPE sig_done(sig) | ||
138 | int sig; | ||
139 | { | ||
140 | signal(SIGALRM,sig_done); | ||
141 | run=0; | ||
142 | #ifdef LINT | ||
143 | sig=sig; | ||
144 | #endif | ||
145 | } | ||
146 | #endif | ||
147 | |||
148 | #define START 0 | ||
149 | #define STOP 1 | ||
150 | |||
151 | double Time_F(s) | ||
152 | int s; | ||
153 | { | ||
154 | double ret; | ||
155 | #ifdef TIMES | ||
156 | static struct tms tstart,tend; | ||
157 | |||
158 | if (s == START) | ||
159 | { | ||
160 | times(&tstart); | ||
161 | return(0); | ||
162 | } | ||
163 | else | ||
164 | { | ||
165 | times(&tend); | ||
166 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
167 | return((ret == 0.0)?1e-6:ret); | ||
168 | } | ||
169 | #else /* !times() */ | ||
170 | static struct timeb tstart,tend; | ||
171 | long i; | ||
172 | |||
173 | if (s == START) | ||
174 | { | ||
175 | ftime(&tstart); | ||
176 | return(0); | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | ftime(&tend); | ||
181 | i=(long)tend.millitm-(long)tstart.millitm; | ||
182 | ret=((double)(tend.time-tstart.time))+((double)i)/1e3; | ||
183 | return((ret == 0.0)?1e-6:ret); | ||
184 | } | ||
185 | #endif | ||
186 | } | ||
187 | |||
188 | int main(argc,argv) | ||
189 | int argc; | ||
190 | char **argv; | ||
191 | { | ||
192 | long count; | ||
193 | static unsigned char buf[BUFSIZE]; | ||
194 | static unsigned char key[] ={ | ||
195 | 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | ||
196 | 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10, | ||
197 | }; | ||
198 | RC4_KEY sch; | ||
199 | double a,b,c,d; | ||
200 | #ifndef SIGALRM | ||
201 | long ca,cb,cc; | ||
202 | #endif | ||
203 | |||
204 | #ifndef TIMES | ||
205 | printf("To get the most acurate results, try to run this\n"); | ||
206 | printf("program when this computer is idle.\n"); | ||
207 | #endif | ||
208 | |||
209 | #ifndef SIGALRM | ||
210 | printf("First we calculate the approximate speed ...\n"); | ||
211 | RC4_set_key(&sch,16,key); | ||
212 | count=10; | ||
213 | do { | ||
214 | long i; | ||
215 | unsigned long data[2]; | ||
216 | |||
217 | count*=2; | ||
218 | Time_F(START); | ||
219 | for (i=count; i; i--) | ||
220 | RC4(&sch,8,buf,buf); | ||
221 | d=Time_F(STOP); | ||
222 | } while (d < 3.0); | ||
223 | ca=count/512; | ||
224 | cc=count*8/BUFSIZE+1; | ||
225 | printf("Doing RC4_set_key %ld times\n",ca); | ||
226 | #define COND(d) (count != (d)) | ||
227 | #define COUNT(d) (d) | ||
228 | #else | ||
229 | #define COND(c) (run) | ||
230 | #define COUNT(d) (count) | ||
231 | signal(SIGALRM,sig_done); | ||
232 | printf("Doing RC4_set_key for 10 seconds\n"); | ||
233 | alarm(10); | ||
234 | #endif | ||
235 | |||
236 | Time_F(START); | ||
237 | for (count=0,run=1; COND(ca); count+=4) | ||
238 | { | ||
239 | RC4_set_key(&sch,16,key); | ||
240 | RC4_set_key(&sch,16,key); | ||
241 | RC4_set_key(&sch,16,key); | ||
242 | RC4_set_key(&sch,16,key); | ||
243 | } | ||
244 | d=Time_F(STOP); | ||
245 | printf("%ld RC4_set_key's in %.2f seconds\n",count,d); | ||
246 | a=((double)COUNT(ca))/d; | ||
247 | |||
248 | #ifdef SIGALRM | ||
249 | printf("Doing RC4 on %ld byte blocks for 10 seconds\n",BUFSIZE); | ||
250 | alarm(10); | ||
251 | #else | ||
252 | printf("Doing RC4 %ld times on %ld byte blocks\n",cc,BUFSIZE); | ||
253 | #endif | ||
254 | Time_F(START); | ||
255 | for (count=0,run=1; COND(cc); count++) | ||
256 | RC4(&sch,BUFSIZE,buf,buf); | ||
257 | d=Time_F(STOP); | ||
258 | printf("%ld RC4's of %ld byte blocks in %.2f second\n", | ||
259 | count,BUFSIZE,d); | ||
260 | c=((double)COUNT(cc)*BUFSIZE)/d; | ||
261 | |||
262 | printf("RC4 set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a); | ||
263 | printf("RC4 bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c); | ||
264 | exit(0); | ||
265 | #if defined(LINT) || defined(MSDOS) | ||
266 | return(0); | ||
267 | #endif | ||
268 | } | ||
269 | |||
diff --git a/src/lib/libcrypto/rc4/rc4test.c b/src/lib/libcrypto/rc4/rc4test.c new file mode 100644 index 0000000000..041e1aff95 --- /dev/null +++ b/src/lib/libcrypto/rc4/rc4test.c | |||
@@ -0,0 +1,195 @@ | |||
1 | /* crypto/rc4/rc4test.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 <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #include "rc4.h" | ||
63 | |||
64 | unsigned char keys[7][30]={ | ||
65 | {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, | ||
66 | {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, | ||
67 | {8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
68 | {4,0xef,0x01,0x23,0x45}, | ||
69 | {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, | ||
70 | {4,0xef,0x01,0x23,0x45}, | ||
71 | }; | ||
72 | |||
73 | unsigned char data_len[7]={8,8,8,20,28,10}; | ||
74 | unsigned char data[7][30]={ | ||
75 | {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xff}, | ||
76 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, | ||
77 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, | ||
78 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
79 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
80 | 0x00,0x00,0x00,0x00,0xff}, | ||
81 | {0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, | ||
82 | 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, | ||
83 | 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, | ||
84 | 0x12,0x34,0x56,0x78,0xff}, | ||
85 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, | ||
86 | {0}, | ||
87 | }; | ||
88 | |||
89 | unsigned char output[7][30]={ | ||
90 | {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96,0x00}, | ||
91 | {0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79,0x00}, | ||
92 | {0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a,0x00}, | ||
93 | {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf, | ||
94 | 0xbd,0x61,0x5a,0x11,0x62,0xe1,0xc7,0xba, | ||
95 | 0x36,0xb6,0x78,0x58,0x00}, | ||
96 | {0x66,0xa0,0x94,0x9f,0x8a,0xf7,0xd6,0x89, | ||
97 | 0x1f,0x7f,0x83,0x2b,0xa8,0x33,0xc0,0x0c, | ||
98 | 0x89,0x2e,0xbe,0x30,0x14,0x3c,0xe2,0x87, | ||
99 | 0x40,0x01,0x1e,0xcf,0x00}, | ||
100 | {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,0xbd,0x61,0x00}, | ||
101 | {0}, | ||
102 | }; | ||
103 | |||
104 | int main(argc,argv) | ||
105 | int argc; | ||
106 | char *argv[]; | ||
107 | { | ||
108 | int i,err=0; | ||
109 | int j; | ||
110 | unsigned char *p; | ||
111 | RC4_KEY key; | ||
112 | unsigned char buf[512],obuf[512]; | ||
113 | |||
114 | for (i=0; i<512; i++) buf[i]=0x01; | ||
115 | |||
116 | for (i=0; i<6; i++) | ||
117 | { | ||
118 | RC4_set_key(&key,keys[i][0],&(keys[i][1])); | ||
119 | memset(obuf,0x00,sizeof(obuf)); | ||
120 | RC4(&key,data_len[i],&(data[i][0]),obuf); | ||
121 | if (memcmp(obuf,output[i],data_len[i]+1) != 0) | ||
122 | { | ||
123 | printf("error calculating RC4\n"); | ||
124 | printf("output:"); | ||
125 | for (j=0; j<data_len[i]+1; j++) | ||
126 | printf(" %02x",obuf[j]); | ||
127 | printf("\n"); | ||
128 | printf("expect:"); | ||
129 | p= &(output[i][0]); | ||
130 | for (j=0; j<data_len[i]+1; j++) | ||
131 | printf(" %02x",*(p++)); | ||
132 | printf("\n"); | ||
133 | err++; | ||
134 | } | ||
135 | else | ||
136 | printf("test %d ok\n",i); | ||
137 | } | ||
138 | printf("test end processing "); | ||
139 | for (i=0; i<data_len[3]; i++) | ||
140 | { | ||
141 | RC4_set_key(&key,keys[3][0],&(keys[3][1])); | ||
142 | memset(obuf,0x00,sizeof(obuf)); | ||
143 | RC4(&key,i,&(data[3][0]),obuf); | ||
144 | if ((memcmp(obuf,output[3],i) != 0) || (obuf[i] != 0)) | ||
145 | { | ||
146 | printf("error in RC4 length processing\n"); | ||
147 | printf("output:"); | ||
148 | for (j=0; j<i+1; j++) | ||
149 | printf(" %02x",obuf[j]); | ||
150 | printf("\n"); | ||
151 | printf("expect:"); | ||
152 | p= &(output[3][0]); | ||
153 | for (j=0; j<i; j++) | ||
154 | printf(" %02x",*(p++)); | ||
155 | printf(" 00\n"); | ||
156 | err++; | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | printf("."); | ||
161 | fflush(stdout); | ||
162 | } | ||
163 | } | ||
164 | printf("done\n"); | ||
165 | printf("test multi-call "); | ||
166 | for (i=0; i<data_len[3]; i++) | ||
167 | { | ||
168 | RC4_set_key(&key,keys[3][0],&(keys[3][1])); | ||
169 | memset(obuf,0x00,sizeof(obuf)); | ||
170 | RC4(&key,i,&(data[3][0]),obuf); | ||
171 | RC4(&key,data_len[3]-i,&(data[3][i]),&(obuf[i])); | ||
172 | if (memcmp(obuf,output[3],data_len[3]+1) != 0) | ||
173 | { | ||
174 | printf("error in RC4 multi-call processing\n"); | ||
175 | printf("output:"); | ||
176 | for (j=0; j<data_len[3]+1; j++) | ||
177 | printf(" %02x",obuf[j]); | ||
178 | printf("\n"); | ||
179 | printf("expect:"); | ||
180 | p= &(output[3][0]); | ||
181 | for (j=0; j<data_len[3]+1; j++) | ||
182 | printf(" %02x",*(p++)); | ||
183 | err++; | ||
184 | } | ||
185 | else | ||
186 | { | ||
187 | printf("."); | ||
188 | fflush(stdout); | ||
189 | } | ||
190 | } | ||
191 | printf("done\n"); | ||
192 | exit(err); | ||
193 | return(0); | ||
194 | } | ||
195 | |||
diff --git a/src/lib/libcrypto/rc4/rrc4.doc b/src/lib/libcrypto/rc4/rrc4.doc new file mode 100644 index 0000000000..2f9a953c12 --- /dev/null +++ b/src/lib/libcrypto/rc4/rrc4.doc | |||
@@ -0,0 +1,278 @@ | |||
1 | Newsgroups: sci.crypt,alt.security,comp.security.misc,alt.privacy | ||
2 | Path: ghost.dsi.unimi.it!univ-lyon1.fr!jussieu.fr!zaphod.crihan.fr!warwick!clyde.open.ac.uk!strath-cs!bnr.co.uk!bt!pipex!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!yeshua.marcam.com!charnel.ecst.csuchico.edu!csusac!csus.edu!netcom.com!sterndark | ||
3 | From: sterndark@netcom.com (David Sterndark) | ||
4 | Subject: RC4 Algorithm revealed. | ||
5 | Message-ID: <sternCvKL4B.Hyy@netcom.com> | ||
6 | Sender: sterndark@netcom.com | ||
7 | Organization: NETCOM On-line Communication Services (408 261-4700 guest) | ||
8 | X-Newsreader: TIN [version 1.2 PL1] | ||
9 | Date: Wed, 14 Sep 1994 06:35:31 GMT | ||
10 | Lines: 263 | ||
11 | Xref: ghost.dsi.unimi.it sci.crypt:27332 alt.security:14732 comp.security.misc:11701 alt.privacy:16026 | ||
12 | |||
13 | I am shocked, shocked, I tell you, shocked, to discover | ||
14 | that the cypherpunks have illegaly and criminally revealed | ||
15 | a crucial RSA trade secret and harmed the security of | ||
16 | America by reverse engineering the RC4 algorithm and | ||
17 | publishing it to the world. | ||
18 | |||
19 | On Saturday morning an anonymous cypherpunk wrote: | ||
20 | |||
21 | |||
22 | SUBJECT: RC4 Source Code | ||
23 | |||
24 | |||
25 | I've tested this. It is compatible with the RC4 object module | ||
26 | that comes in the various RSA toolkits. | ||
27 | |||
28 | /* rc4.h */ | ||
29 | typedef struct rc4_key | ||
30 | { | ||
31 | unsigned char state[256]; | ||
32 | unsigned char x; | ||
33 | unsigned char y; | ||
34 | } rc4_key; | ||
35 | void prepare_key(unsigned char *key_data_ptr,int key_data_len, | ||
36 | rc4_key *key); | ||
37 | void rc4(unsigned char *buffer_ptr,int buffer_len,rc4_key * key); | ||
38 | |||
39 | |||
40 | /*rc4.c */ | ||
41 | #include "rc4.h" | ||
42 | static void swap_byte(unsigned char *a, unsigned char *b); | ||
43 | void prepare_key(unsigned char *key_data_ptr, int key_data_len, | ||
44 | rc4_key *key) | ||
45 | { | ||
46 | unsigned char swapByte; | ||
47 | unsigned char index1; | ||
48 | unsigned char index2; | ||
49 | unsigned char* state; | ||
50 | short counter; | ||
51 | |||
52 | state = &key->state[0]; | ||
53 | for(counter = 0; counter < 256; counter++) | ||
54 | state[counter] = counter; | ||
55 | key->x = 0; | ||
56 | key->y = 0; | ||
57 | index1 = 0; | ||
58 | index2 = 0; | ||
59 | for(counter = 0; counter < 256; counter++) | ||
60 | { | ||
61 | index2 = (key_data_ptr[index1] + state[counter] + | ||
62 | index2) % 256; | ||
63 | swap_byte(&state[counter], &state[index2]); | ||
64 | |||
65 | index1 = (index1 + 1) % key_data_len; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | void rc4(unsigned char *buffer_ptr, int buffer_len, rc4_key *key) | ||
70 | { | ||
71 | unsigned char x; | ||
72 | unsigned char y; | ||
73 | unsigned char* state; | ||
74 | unsigned char xorIndex; | ||
75 | short counter; | ||
76 | |||
77 | x = key->x; | ||
78 | y = key->y; | ||
79 | |||
80 | state = &key->state[0]; | ||
81 | for(counter = 0; counter < buffer_len; counter ++) | ||
82 | { | ||
83 | x = (x + 1) % 256; | ||
84 | y = (state[x] + y) % 256; | ||
85 | swap_byte(&state[x], &state[y]); | ||
86 | |||
87 | xorIndex = (state[x] + state[y]) % 256; | ||
88 | |||
89 | buffer_ptr[counter] ^= state[xorIndex]; | ||
90 | } | ||
91 | key->x = x; | ||
92 | key->y = y; | ||
93 | } | ||
94 | |||
95 | static void swap_byte(unsigned char *a, unsigned char *b) | ||
96 | { | ||
97 | unsigned char swapByte; | ||
98 | |||
99 | swapByte = *a; | ||
100 | *a = *b; | ||
101 | *b = swapByte; | ||
102 | } | ||
103 | |||
104 | |||
105 | |||
106 | Another cypherpunk, this one not anonymous, tested the | ||
107 | output from this algorithm against the output from | ||
108 | official RC4 object code | ||
109 | |||
110 | |||
111 | Date: Tue, 13 Sep 94 18:37:56 PDT | ||
112 | From: ekr@eit.COM (Eric Rescorla) | ||
113 | Message-Id: <9409140137.AA17743@eitech.eit.com> | ||
114 | Subject: RC4 compatibility testing | ||
115 | Cc: cypherpunks@toad.com | ||
116 | |||
117 | One data point: | ||
118 | |||
119 | I can't say anything about the internals of RC4 versus the | ||
120 | algorithm that Bill Sommerfeld is rightly calling 'Alleged RC4', | ||
121 | since I don't know anything about RC4's internals. | ||
122 | |||
123 | However, I do have a (legitimately acquired) copy of BSAFE2 and | ||
124 | so I'm able to compare the output of this algorithm to the output | ||
125 | of genuine RC4 as found in BSAFE. I chose a set of test vectors | ||
126 | and ran them through both algorithms. The algorithms appear to | ||
127 | give identical results, at least with these key/plaintext pairs. | ||
128 | |||
129 | I note that this is the algorithm _without_ Hal Finney's | ||
130 | proposed modification | ||
131 | |||
132 | (see <199409130605.XAA24133@jobe.shell.portal.com>). | ||
133 | |||
134 | The vectors I used (together with the ciphertext they produce) | ||
135 | follow at the end of this message. | ||
136 | |||
137 | -Ekr | ||
138 | |||
139 | Disclaimer: This posting does not reflect the opinions of EIT. | ||
140 | |||
141 | --------------------results follow-------------- | ||
142 | Test vector 0 | ||
143 | Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef | ||
144 | Input: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef | ||
145 | 0 Output: 0x75 0xb7 0x87 0x80 0x99 0xe0 0xc5 0x96 | ||
146 | |||
147 | Test vector 1 | ||
148 | Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef | ||
149 | Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 | ||
150 | 0 Output: 0x74 0x94 0xc2 0xe7 0x10 0x4b 0x08 0x79 | ||
151 | |||
152 | Test vector 2 | ||
153 | Key: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 | ||
154 | Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 | ||
155 | 0 Output: 0xde 0x18 0x89 0x41 0xa3 0x37 0x5d 0x3a | ||
156 | |||
157 | Test vector 3 | ||
158 | Key: 0xef 0x01 0x23 0x45 | ||
159 | Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 | ||
160 | 0 Output: 0xd6 0xa1 0x41 0xa7 0xec 0x3c 0x38 0xdf 0xbd 0x61 | ||
161 | |||
162 | Test vector 4 | ||
163 | Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef | ||
164 | Input: 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
165 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
166 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
167 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
168 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
169 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
170 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
171 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
172 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
173 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
174 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
175 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
176 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
177 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
178 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
179 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
180 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
181 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
182 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
183 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
184 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
185 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
186 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
187 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
188 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
189 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
190 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
191 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
192 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
193 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
194 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
195 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
196 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
197 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
198 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
199 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
200 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
201 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
202 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
203 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
204 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
205 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
206 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
207 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
208 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
209 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
210 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
211 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
212 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
213 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
214 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 | ||
215 | 0x01 | ||
216 | 0 Output: 0x75 0x95 0xc3 0xe6 0x11 0x4a 0x09 0x78 0x0c 0x4a 0xd4 | ||
217 | 0x52 0x33 0x8e 0x1f 0xfd 0x9a 0x1b 0xe9 0x49 0x8f | ||
218 | 0x81 0x3d 0x76 0x53 0x34 0x49 0xb6 0x77 0x8d 0xca | ||
219 | 0xd8 0xc7 0x8a 0x8d 0x2b 0xa9 0xac 0x66 0x08 0x5d | ||
220 | 0x0e 0x53 0xd5 0x9c 0x26 0xc2 0xd1 0xc4 0x90 0xc1 | ||
221 | 0xeb 0xbe 0x0c 0xe6 0x6d 0x1b 0x6b 0x1b 0x13 0xb6 | ||
222 | 0xb9 0x19 0xb8 0x47 0xc2 0x5a 0x91 0x44 0x7a 0x95 | ||
223 | 0xe7 0x5e 0x4e 0xf1 0x67 0x79 0xcd 0xe8 0xbf 0x0a | ||
224 | 0x95 0x85 0x0e 0x32 0xaf 0x96 0x89 0x44 0x4f 0xd3 | ||
225 | 0x77 0x10 0x8f 0x98 0xfd 0xcb 0xd4 0xe7 0x26 0x56 | ||
226 | 0x75 0x00 0x99 0x0b 0xcc 0x7e 0x0c 0xa3 0xc4 0xaa | ||
227 | 0xa3 0x04 0xa3 0x87 0xd2 0x0f 0x3b 0x8f 0xbb 0xcd | ||
228 | 0x42 0xa1 0xbd 0x31 0x1d 0x7a 0x43 0x03 0xdd 0xa5 | ||
229 | 0xab 0x07 0x88 0x96 0xae 0x80 0xc1 0x8b 0x0a 0xf6 | ||
230 | 0x6d 0xff 0x31 0x96 0x16 0xeb 0x78 0x4e 0x49 0x5a | ||
231 | 0xd2 0xce 0x90 0xd7 0xf7 0x72 0xa8 0x17 0x47 0xb6 | ||
232 | 0x5f 0x62 0x09 0x3b 0x1e 0x0d 0xb9 0xe5 0xba 0x53 | ||
233 | 0x2f 0xaf 0xec 0x47 0x50 0x83 0x23 0xe6 0x71 0x32 | ||
234 | 0x7d 0xf9 0x44 0x44 0x32 0xcb 0x73 0x67 0xce 0xc8 | ||
235 | 0x2f 0x5d 0x44 0xc0 0xd0 0x0b 0x67 0xd6 0x50 0xa0 | ||
236 | 0x75 0xcd 0x4b 0x70 0xde 0xdd 0x77 0xeb 0x9b 0x10 | ||
237 | 0x23 0x1b 0x6b 0x5b 0x74 0x13 0x47 0x39 0x6d 0x62 | ||
238 | 0x89 0x74 0x21 0xd4 0x3d 0xf9 0xb4 0x2e 0x44 0x6e | ||
239 | 0x35 0x8e 0x9c 0x11 0xa9 0xb2 0x18 0x4e 0xcb 0xef | ||
240 | 0x0c 0xd8 0xe7 0xa8 0x77 0xef 0x96 0x8f 0x13 0x90 | ||
241 | 0xec 0x9b 0x3d 0x35 0xa5 0x58 0x5c 0xb0 0x09 0x29 | ||
242 | 0x0e 0x2f 0xcd 0xe7 0xb5 0xec 0x66 0xd9 0x08 0x4b | ||
243 | 0xe4 0x40 0x55 0xa6 0x19 0xd9 0xdd 0x7f 0xc3 0x16 | ||
244 | 0x6f 0x94 0x87 0xf7 0xcb 0x27 0x29 0x12 0x42 0x64 | ||
245 | 0x45 0x99 0x85 0x14 0xc1 0x5d 0x53 0xa1 0x8c 0x86 | ||
246 | 0x4c 0xe3 0xa2 0xb7 0x55 0x57 0x93 0x98 0x81 0x26 | ||
247 | 0x52 0x0e 0xac 0xf2 0xe3 0x06 0x6e 0x23 0x0c 0x91 | ||
248 | 0xbe 0xe4 0xdd 0x53 0x04 0xf5 0xfd 0x04 0x05 0xb3 | ||
249 | 0x5b 0xd9 0x9c 0x73 0x13 0x5d 0x3d 0x9b 0xc3 0x35 | ||
250 | 0xee 0x04 0x9e 0xf6 0x9b 0x38 0x67 0xbf 0x2d 0x7b | ||
251 | 0xd1 0xea 0xa5 0x95 0xd8 0xbf 0xc0 0x06 0x6f 0xf8 | ||
252 | 0xd3 0x15 0x09 0xeb 0x0c 0x6c 0xaa 0x00 0x6c 0x80 | ||
253 | 0x7a 0x62 0x3e 0xf8 0x4c 0x3d 0x33 0xc1 0x95 0xd2 | ||
254 | 0x3e 0xe3 0x20 0xc4 0x0d 0xe0 0x55 0x81 0x57 0xc8 | ||
255 | 0x22 0xd4 0xb8 0xc5 0x69 0xd8 0x49 0xae 0xd5 0x9d | ||
256 | 0x4e 0x0f 0xd7 0xf3 0x79 0x58 0x6b 0x4b 0x7f 0xf6 | ||
257 | 0x84 0xed 0x6a 0x18 0x9f 0x74 0x86 0xd4 0x9b 0x9c | ||
258 | 0x4b 0xad 0x9b 0xa2 0x4b 0x96 0xab 0xf9 0x24 0x37 | ||
259 | 0x2c 0x8a 0x8f 0xff 0xb1 0x0d 0x55 0x35 0x49 0x00 | ||
260 | 0xa7 0x7a 0x3d 0xb5 0xf2 0x05 0xe1 0xb9 0x9f 0xcd | ||
261 | 0x86 0x60 0x86 0x3a 0x15 0x9a 0xd4 0xab 0xe4 0x0f | ||
262 | 0xa4 0x89 0x34 0x16 0x3d 0xdd 0xe5 0x42 0xa6 0x58 | ||
263 | 0x55 0x40 0xfd 0x68 0x3c 0xbf 0xd8 0xc0 0x0f 0x12 | ||
264 | 0x12 0x9a 0x28 0x4d 0xea 0xcc 0x4c 0xde 0xfe 0x58 | ||
265 | 0xbe 0x71 0x37 0x54 0x1c 0x04 0x71 0x26 0xc8 0xd4 | ||
266 | 0x9e 0x27 0x55 0xab 0x18 0x1a 0xb7 0xe9 0x40 0xb0 | ||
267 | 0xc0 | ||
268 | |||
269 | |||
270 | |||
271 | -- | ||
272 | --------------------------------------------------------------------- | ||
273 | We have the right to defend ourselves and our | ||
274 | property, because of the kind of animals that we James A. Donald | ||
275 | are. True law derives from this right, not from | ||
276 | the arbitrary power of the omnipotent state. jamesd@netcom.com | ||
277 | |||
278 | |||
diff --git a/src/lib/libcrypto/rc5/rc5.h b/src/lib/libcrypto/rc5/rc5.h new file mode 100644 index 0000000000..5fd64e3f10 --- /dev/null +++ b/src/lib/libcrypto/rc5/rc5.h | |||
@@ -0,0 +1,122 @@ | |||
1 | /* crypto/rc5/rc5.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_RC5_H | ||
60 | #define HEADER_RC5_H | ||
61 | |||
62 | #ifdef __cplusplus | ||
63 | extern "C" { | ||
64 | #endif | ||
65 | |||
66 | #define RC5_ENCRYPT 1 | ||
67 | #define RC5_DECRYPT 0 | ||
68 | |||
69 | /* 32 bit. For Alpha, things may get weird */ | ||
70 | #define RC5_32_INT unsigned long | ||
71 | |||
72 | #define RC5_32_BLOCK 8 | ||
73 | #define RC5_32_KEY_LENGTH 16 /* This is a default, max is 255 */ | ||
74 | |||
75 | /* This are the only values supported. Tweak the code if you want more | ||
76 | * The most supported modes will be | ||
77 | * RC5-32/12/16 | ||
78 | * RC5-32/16/8 | ||
79 | */ | ||
80 | #define RC5_8_ROUNDS 8 | ||
81 | #define RC5_12_ROUNDS 12 | ||
82 | #define RC5_16_ROUNDS 16 | ||
83 | |||
84 | typedef struct rc5_key_st | ||
85 | { | ||
86 | /* Number of rounds */ | ||
87 | int rounds; | ||
88 | RC5_32_INT data[2*(RC5_16_ROUNDS+1)]; | ||
89 | } RC5_32_KEY; | ||
90 | |||
91 | #ifndef NOPROTO | ||
92 | |||
93 | void RC5_32_set_key(RC5_32_KEY *key, int len, unsigned char *data, | ||
94 | int rounds); | ||
95 | void RC5_32_ecb_encrypt(unsigned char *in,unsigned char *out,RC5_32_KEY *key, | ||
96 | int enc); | ||
97 | void RC5_32_encrypt(unsigned long *data,RC5_32_KEY *key); | ||
98 | void RC5_32_decrypt(unsigned long *data,RC5_32_KEY *key); | ||
99 | void RC5_32_cbc_encrypt(unsigned char *in, unsigned char *out, long length, | ||
100 | RC5_32_KEY *ks, unsigned char *iv, int enc); | ||
101 | void RC5_32_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, | ||
102 | RC5_32_KEY *schedule, unsigned char *ivec, int *num, int enc); | ||
103 | void RC5_32_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, | ||
104 | RC5_32_KEY *schedule, unsigned char *ivec, int *num); | ||
105 | |||
106 | #else | ||
107 | |||
108 | void RC5_32_set_key(); | ||
109 | void RC5_32_ecb_encrypt(); | ||
110 | void RC5_32_encrypt(); | ||
111 | void RC5_32_decrypt(); | ||
112 | void RC5_32_cbc_encrypt(); | ||
113 | void RC5_32_cfb64_encrypt(); | ||
114 | void RC5_32_ofb64_encrypt(); | ||
115 | |||
116 | #endif | ||
117 | |||
118 | #ifdef __cplusplus | ||
119 | } | ||
120 | #endif | ||
121 | |||
122 | #endif | ||
diff --git a/src/lib/libcrypto/ripemd/asm/rips.cpp b/src/lib/libcrypto/ripemd/asm/rips.cpp new file mode 100644 index 0000000000..78a933c448 --- /dev/null +++ b/src/lib/libcrypto/ripemd/asm/rips.cpp | |||
@@ -0,0 +1,78 @@ | |||
1 | // | ||
2 | // gettsc.inl | ||
3 | // | ||
4 | // gives access to the Pentium's (secret) cycle counter | ||
5 | // | ||
6 | // This software was written by Leonard Janke (janke@unixg.ubc.ca) | ||
7 | // in 1996-7 and is entered, by him, into the public domain. | ||
8 | |||
9 | #if defined(__WATCOMC__) | ||
10 | void GetTSC(unsigned long&); | ||
11 | #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; | ||
12 | #elif defined(__GNUC__) | ||
13 | inline | ||
14 | void GetTSC(unsigned long& tsc) | ||
15 | { | ||
16 | asm volatile(".byte 15, 49\n\t" | ||
17 | : "=eax" (tsc) | ||
18 | : | ||
19 | : "%edx", "%eax"); | ||
20 | } | ||
21 | #elif defined(_MSC_VER) | ||
22 | inline | ||
23 | void GetTSC(unsigned long& tsc) | ||
24 | { | ||
25 | unsigned long a; | ||
26 | __asm _emit 0fh | ||
27 | __asm _emit 31h | ||
28 | __asm mov a, eax; | ||
29 | tsc=a; | ||
30 | } | ||
31 | #endif | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include <stdlib.h> | ||
35 | #include "ripemd.h" | ||
36 | |||
37 | extern "C" { | ||
38 | void ripemd160_block_x86(RIPEMD160_CTX *ctx, unsigned char *buffer,int num); | ||
39 | } | ||
40 | |||
41 | void main(int argc,char *argv[]) | ||
42 | { | ||
43 | unsigned char buffer[64*256]; | ||
44 | RIPEMD160_CTX ctx; | ||
45 | unsigned long s1,s2,e1,e2; | ||
46 | unsigned char k[16]; | ||
47 | unsigned long data[2]; | ||
48 | unsigned char iv[8]; | ||
49 | int i,num=0,numm; | ||
50 | int j=0; | ||
51 | |||
52 | if (argc >= 2) | ||
53 | num=atoi(argv[1]); | ||
54 | |||
55 | if (num == 0) num=16; | ||
56 | if (num > 250) num=16; | ||
57 | numm=num+2; | ||
58 | num*=64; | ||
59 | numm*=64; | ||
60 | |||
61 | for (j=0; j<6; j++) | ||
62 | { | ||
63 | for (i=0; i<10; i++) /**/ | ||
64 | { | ||
65 | ripemd160_block_x86(&ctx,buffer,numm); | ||
66 | GetTSC(s1); | ||
67 | ripemd160_block_x86(&ctx,buffer,numm); | ||
68 | GetTSC(e1); | ||
69 | GetTSC(s2); | ||
70 | ripemd160_block_x86(&ctx,buffer,num); | ||
71 | GetTSC(e2); | ||
72 | ripemd160_block_x86(&ctx,buffer,num); | ||
73 | } | ||
74 | printf("ripemd160 (%d bytes) %d %d (%.2f)\n",num, | ||
75 | e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2); | ||
76 | } | ||
77 | } | ||
78 | |||
diff --git a/src/lib/libcrypto/ripemd/rmd160.c b/src/lib/libcrypto/ripemd/rmd160.c new file mode 100644 index 0000000000..3fa1b8096e --- /dev/null +++ b/src/lib/libcrypto/ripemd/rmd160.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /* crypto/ripemd/rmd160.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 <stdlib.h> | ||
61 | #include "ripemd.h" | ||
62 | |||
63 | #define BUFSIZE 1024*16 | ||
64 | |||
65 | #ifndef NOPROTO | ||
66 | void do_fp(FILE *f); | ||
67 | void pt(unsigned char *md); | ||
68 | int read(int, void *, unsigned int); | ||
69 | #else | ||
70 | void do_fp(); | ||
71 | void pt(); | ||
72 | int read(); | ||
73 | #endif | ||
74 | |||
75 | int main(argc, argv) | ||
76 | int argc; | ||
77 | char **argv; | ||
78 | { | ||
79 | int i,err=0; | ||
80 | FILE *IN; | ||
81 | |||
82 | if (argc == 1) | ||
83 | { | ||
84 | do_fp(stdin); | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | for (i=1; i<argc; i++) | ||
89 | { | ||
90 | IN=fopen(argv[i],"r"); | ||
91 | if (IN == NULL) | ||
92 | { | ||
93 | perror(argv[i]); | ||
94 | err++; | ||
95 | continue; | ||
96 | } | ||
97 | printf("RIPEMD160(%s)= ",argv[i]); | ||
98 | do_fp(IN); | ||
99 | fclose(IN); | ||
100 | } | ||
101 | } | ||
102 | exit(err); | ||
103 | } | ||
104 | |||
105 | void do_fp(f) | ||
106 | FILE *f; | ||
107 | { | ||
108 | RIPEMD160_CTX c; | ||
109 | unsigned char md[RIPEMD160_DIGEST_LENGTH]; | ||
110 | int fd; | ||
111 | int i; | ||
112 | static unsigned char buf[BUFSIZE]; | ||
113 | |||
114 | fd=fileno(f); | ||
115 | RIPEMD160_Init(&c); | ||
116 | for (;;) | ||
117 | { | ||
118 | i=read(fd,buf,BUFSIZE); | ||
119 | if (i <= 0) break; | ||
120 | RIPEMD160_Update(&c,buf,(unsigned long)i); | ||
121 | } | ||
122 | RIPEMD160_Final(&(md[0]),&c); | ||
123 | pt(md); | ||
124 | } | ||
125 | |||
126 | void pt(md) | ||
127 | unsigned char *md; | ||
128 | { | ||
129 | int i; | ||
130 | |||
131 | for (i=0; i<RIPEMD160_DIGEST_LENGTH; i++) | ||
132 | printf("%02x",md[i]); | ||
133 | printf("\n"); | ||
134 | } | ||
135 | |||
diff --git a/src/lib/libcrypto/ripemd/rmdtest.c b/src/lib/libcrypto/ripemd/rmdtest.c new file mode 100644 index 0000000000..6a0297f975 --- /dev/null +++ b/src/lib/libcrypto/ripemd/rmdtest.c | |||
@@ -0,0 +1,133 @@ | |||
1 | /* crypto/ripemd/rmdtest.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 <string.h> | ||
61 | #include <stdlib.h> | ||
62 | #include "ripemd.h" | ||
63 | |||
64 | char *test[]={ | ||
65 | "", | ||
66 | "a", | ||
67 | "abc", | ||
68 | "message digest", | ||
69 | "abcdefghijklmnopqrstuvwxyz", | ||
70 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | ||
71 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | ||
72 | "12345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
73 | NULL, | ||
74 | }; | ||
75 | |||
76 | char *ret[]={ | ||
77 | "9c1185a5c5e9fc54612808977ee8f548b2258d31", | ||
78 | "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", | ||
79 | "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", | ||
80 | "5d0689ef49d2fae572b881b123a85ffa21595f36", | ||
81 | "f71c27109c692c1b56bbdceb5b9d2865b3708dbc", | ||
82 | "12a053384a9c0c88e405a06c27dcf49ada62eb2b", | ||
83 | "b0e20b6e3116640286ed3a87a5713079b21f5189", | ||
84 | "9b752e45573d4b39f4dbd3323cab82bf63326bfb", | ||
85 | }; | ||
86 | |||
87 | #ifndef NOPROTO | ||
88 | static char *pt(unsigned char *md); | ||
89 | #else | ||
90 | static char *pt(); | ||
91 | #endif | ||
92 | |||
93 | int main(argc,argv) | ||
94 | int argc; | ||
95 | char *argv[]; | ||
96 | { | ||
97 | int i,err=0; | ||
98 | unsigned char **P,**R; | ||
99 | char *p; | ||
100 | |||
101 | P=(unsigned char **)test; | ||
102 | R=(unsigned char **)ret; | ||
103 | i=1; | ||
104 | while (*P != NULL) | ||
105 | { | ||
106 | p=pt(RIPEMD160(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL)); | ||
107 | if (strcmp(p,(char *)*R) != 0) | ||
108 | { | ||
109 | printf("error calculating RIPEMD160 on '%s'\n",*P); | ||
110 | printf("got %s instead of %s\n",p,*R); | ||
111 | err++; | ||
112 | } | ||
113 | else | ||
114 | printf("test %d ok\n",i); | ||
115 | i++; | ||
116 | R++; | ||
117 | P++; | ||
118 | } | ||
119 | exit(err); | ||
120 | return(0); | ||
121 | } | ||
122 | |||
123 | static char *pt(md) | ||
124 | unsigned char *md; | ||
125 | { | ||
126 | int i; | ||
127 | static char buf[80]; | ||
128 | |||
129 | for (i=0; i<RIPEMD160_DIGEST_LENGTH; i++) | ||
130 | sprintf(&(buf[i*2]),"%02x",md[i]); | ||
131 | return(buf); | ||
132 | } | ||
133 | |||
diff --git a/src/lib/libcrypto/sha/asm/README b/src/lib/libcrypto/sha/asm/README new file mode 100644 index 0000000000..b7e755765f --- /dev/null +++ b/src/lib/libcrypto/sha/asm/README | |||
@@ -0,0 +1 @@ | |||
C2.pl works | |||
diff --git a/src/lib/libcrypto/sha/sha.c b/src/lib/libcrypto/sha/sha.c new file mode 100644 index 0000000000..713fec3610 --- /dev/null +++ b/src/lib/libcrypto/sha/sha.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /* crypto/sha/sha.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 <stdlib.h> | ||
61 | #include "sha.h" | ||
62 | |||
63 | #define BUFSIZE 1024*16 | ||
64 | |||
65 | #ifndef NOPROTO | ||
66 | void do_fp(FILE *f); | ||
67 | void pt(unsigned char *md); | ||
68 | int read(int, void *, unsigned int); | ||
69 | #else | ||
70 | void do_fp(); | ||
71 | void pt(); | ||
72 | int read(); | ||
73 | #endif | ||
74 | |||
75 | int main(argc, argv) | ||
76 | int argc; | ||
77 | char **argv; | ||
78 | { | ||
79 | int i,err=0; | ||
80 | FILE *IN; | ||
81 | |||
82 | if (argc == 1) | ||
83 | { | ||
84 | do_fp(stdin); | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | for (i=1; i<argc; i++) | ||
89 | { | ||
90 | IN=fopen(argv[i],"r"); | ||
91 | if (IN == NULL) | ||
92 | { | ||
93 | perror(argv[i]); | ||
94 | err++; | ||
95 | continue; | ||
96 | } | ||
97 | printf("SHA(%s)= ",argv[i]); | ||
98 | do_fp(IN); | ||
99 | fclose(IN); | ||
100 | } | ||
101 | } | ||
102 | exit(err); | ||
103 | } | ||
104 | |||
105 | void do_fp(f) | ||
106 | FILE *f; | ||
107 | { | ||
108 | SHA_CTX c; | ||
109 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
110 | int fd; | ||
111 | int i; | ||
112 | unsigned char buf[BUFSIZE]; | ||
113 | |||
114 | fd=fileno(f); | ||
115 | SHA_Init(&c); | ||
116 | for (;;) | ||
117 | { | ||
118 | i=read(fd,buf,BUFSIZE); | ||
119 | if (i <= 0) break; | ||
120 | SHA_Update(&c,buf,(unsigned long)i); | ||
121 | } | ||
122 | SHA_Final(&(md[0]),&c); | ||
123 | pt(md); | ||
124 | } | ||
125 | |||
126 | void pt(md) | ||
127 | unsigned char *md; | ||
128 | { | ||
129 | int i; | ||
130 | |||
131 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
132 | printf("%02x",md[i]); | ||
133 | printf("\n"); | ||
134 | } | ||
135 | |||
diff --git a/src/lib/libcrypto/sha/sha1.c b/src/lib/libcrypto/sha/sha1.c new file mode 100644 index 0000000000..a4739ac9fd --- /dev/null +++ b/src/lib/libcrypto/sha/sha1.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /* crypto/sha/sha1.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <stdlib.h> | ||
61 | #include "sha.h" | ||
62 | |||
63 | #define BUFSIZE 1024*16 | ||
64 | |||
65 | #ifndef NOPROTO | ||
66 | void do_fp(FILE *f); | ||
67 | void pt(unsigned char *md); | ||
68 | int read(int, void *, unsigned int); | ||
69 | #else | ||
70 | void do_fp(); | ||
71 | void pt(); | ||
72 | int read(); | ||
73 | #endif | ||
74 | |||
75 | int main(argc, argv) | ||
76 | int argc; | ||
77 | char **argv; | ||
78 | { | ||
79 | int i,err=0; | ||
80 | FILE *IN; | ||
81 | |||
82 | if (argc == 1) | ||
83 | { | ||
84 | do_fp(stdin); | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | for (i=1; i<argc; i++) | ||
89 | { | ||
90 | IN=fopen(argv[i],"r"); | ||
91 | if (IN == NULL) | ||
92 | { | ||
93 | perror(argv[i]); | ||
94 | err++; | ||
95 | continue; | ||
96 | } | ||
97 | printf("SHA1(%s)= ",argv[i]); | ||
98 | do_fp(IN); | ||
99 | fclose(IN); | ||
100 | } | ||
101 | } | ||
102 | exit(err); | ||
103 | } | ||
104 | |||
105 | void do_fp(f) | ||
106 | FILE *f; | ||
107 | { | ||
108 | SHA_CTX c; | ||
109 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
110 | int fd; | ||
111 | int i; | ||
112 | unsigned char buf[BUFSIZE]; | ||
113 | |||
114 | fd=fileno(f); | ||
115 | SHA1_Init(&c); | ||
116 | for (;;) | ||
117 | { | ||
118 | i=read(fd,buf,BUFSIZE); | ||
119 | if (i <= 0) break; | ||
120 | SHA1_Update(&c,buf,(unsigned long)i); | ||
121 | } | ||
122 | SHA1_Final(&(md[0]),&c); | ||
123 | pt(md); | ||
124 | } | ||
125 | |||
126 | void pt(md) | ||
127 | unsigned char *md; | ||
128 | { | ||
129 | int i; | ||
130 | |||
131 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
132 | printf("%02x",md[i]); | ||
133 | printf("\n"); | ||
134 | } | ||
135 | |||
diff --git a/src/lib/libcrypto/sha/sha1s.cpp b/src/lib/libcrypto/sha/sha1s.cpp new file mode 100644 index 0000000000..0163377de6 --- /dev/null +++ b/src/lib/libcrypto/sha/sha1s.cpp | |||
@@ -0,0 +1,79 @@ | |||
1 | // | ||
2 | // gettsc.inl | ||
3 | // | ||
4 | // gives access to the Pentium's (secret) cycle counter | ||
5 | // | ||
6 | // This software was written by Leonard Janke (janke@unixg.ubc.ca) | ||
7 | // in 1996-7 and is entered, by him, into the public domain. | ||
8 | |||
9 | #if defined(__WATCOMC__) | ||
10 | void GetTSC(unsigned long&); | ||
11 | #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; | ||
12 | #elif defined(__GNUC__) | ||
13 | inline | ||
14 | void GetTSC(unsigned long& tsc) | ||
15 | { | ||
16 | asm volatile(".byte 15, 49\n\t" | ||
17 | : "=eax" (tsc) | ||
18 | : | ||
19 | : "%edx", "%eax"); | ||
20 | } | ||
21 | #elif defined(_MSC_VER) | ||
22 | inline | ||
23 | void GetTSC(unsigned long& tsc) | ||
24 | { | ||
25 | unsigned long a; | ||
26 | __asm _emit 0fh | ||
27 | __asm _emit 31h | ||
28 | __asm mov a, eax; | ||
29 | tsc=a; | ||
30 | } | ||
31 | #endif | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include <stdlib.h> | ||
35 | #include "sha.h" | ||
36 | |||
37 | extern "C" { | ||
38 | void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num); | ||
39 | } | ||
40 | |||
41 | void main(int argc,char *argv[]) | ||
42 | { | ||
43 | unsigned char buffer[64*256]; | ||
44 | SHA_CTX ctx; | ||
45 | unsigned long s1,s2,e1,e2; | ||
46 | unsigned char k[16]; | ||
47 | unsigned long data[2]; | ||
48 | unsigned char iv[8]; | ||
49 | int i,num=0,numm; | ||
50 | int j=0; | ||
51 | |||
52 | if (argc >= 2) | ||
53 | num=atoi(argv[1]); | ||
54 | |||
55 | if (num == 0) num=16; | ||
56 | if (num > 250) num=16; | ||
57 | numm=num+2; | ||
58 | num*=64; | ||
59 | numm*=64; | ||
60 | |||
61 | for (j=0; j<6; j++) | ||
62 | { | ||
63 | for (i=0; i<10; i++) /**/ | ||
64 | { | ||
65 | sha1_block_x86(&ctx,buffer,numm); | ||
66 | GetTSC(s1); | ||
67 | sha1_block_x86(&ctx,buffer,numm); | ||
68 | GetTSC(e1); | ||
69 | GetTSC(s2); | ||
70 | sha1_block_x86(&ctx,buffer,num); | ||
71 | GetTSC(e2); | ||
72 | sha1_block_x86(&ctx,buffer,num); | ||
73 | } | ||
74 | |||
75 | printf("sha1 (%d bytes) %d %d (%.2f)\n",num, | ||
76 | e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2); | ||
77 | } | ||
78 | } | ||
79 | |||
diff --git a/src/lib/libcrypto/sha/sha1test.c b/src/lib/libcrypto/sha/sha1test.c new file mode 100644 index 0000000000..3c62a218b4 --- /dev/null +++ b/src/lib/libcrypto/sha/sha1test.c | |||
@@ -0,0 +1,155 @@ | |||
1 | /* crypto/sha/sha1test.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 <string.h> | ||
61 | #include <stdlib.h> | ||
62 | #include "sha.h" | ||
63 | |||
64 | #undef SHA_0 /* FIPS 180 */ | ||
65 | #define SHA_1 /* FIPS 180-1 */ | ||
66 | |||
67 | char *test[]={ | ||
68 | "abc", | ||
69 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | ||
70 | NULL, | ||
71 | }; | ||
72 | |||
73 | #ifdef SHA_0 | ||
74 | char *ret[]={ | ||
75 | "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", | ||
76 | "d2516ee1acfa5baf33dfc1c471e438449ef134c8", | ||
77 | }; | ||
78 | char *bigret= | ||
79 | "3232affa48628a26653b5aaa44541fd90d690603"; | ||
80 | #endif | ||
81 | #ifdef SHA_1 | ||
82 | char *ret[]={ | ||
83 | "a9993e364706816aba3e25717850c26c9cd0d89d", | ||
84 | "84983e441c3bd26ebaae4aa1f95129e5e54670f1", | ||
85 | }; | ||
86 | char *bigret= | ||
87 | "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; | ||
88 | #endif | ||
89 | |||
90 | #ifndef NOPROTO | ||
91 | static char *pt(unsigned char *md); | ||
92 | #else | ||
93 | static char *pt(); | ||
94 | #endif | ||
95 | |||
96 | int main(argc,argv) | ||
97 | int argc; | ||
98 | char *argv[]; | ||
99 | { | ||
100 | int i,err=0; | ||
101 | unsigned char **P,**R; | ||
102 | static unsigned char buf[1000]; | ||
103 | char *p,*r; | ||
104 | SHA_CTX c; | ||
105 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
106 | |||
107 | P=(unsigned char **)test; | ||
108 | R=(unsigned char **)ret; | ||
109 | i=1; | ||
110 | while (*P != NULL) | ||
111 | { | ||
112 | p=pt(SHA1(*P,(unsigned long)strlen((char *)*P),NULL)); | ||
113 | if (strcmp(p,(char *)*R) != 0) | ||
114 | { | ||
115 | printf("error calculating SHA1 on '%s'\n",*P); | ||
116 | printf("got %s instead of %s\n",p,*R); | ||
117 | err++; | ||
118 | } | ||
119 | else | ||
120 | printf("test %d ok\n",i); | ||
121 | i++; | ||
122 | R++; | ||
123 | P++; | ||
124 | } | ||
125 | |||
126 | memset(buf,'a',1000); | ||
127 | SHA1_Init(&c); | ||
128 | for (i=0; i<1000; i++) | ||
129 | SHA1_Update(&c,buf,1000); | ||
130 | SHA1_Final(md,&c); | ||
131 | p=pt(md); | ||
132 | |||
133 | r=bigret; | ||
134 | if (strcmp(p,r) != 0) | ||
135 | { | ||
136 | printf("error calculating SHA1 on 'a' * 1000\n"); | ||
137 | printf("got %s instead of %s\n",p,r); | ||
138 | err++; | ||
139 | } | ||
140 | else | ||
141 | printf("test 3 ok\n"); | ||
142 | exit(err); | ||
143 | return(0); | ||
144 | } | ||
145 | |||
146 | static char *pt(md) | ||
147 | unsigned char *md; | ||
148 | { | ||
149 | int i; | ||
150 | static char buf[80]; | ||
151 | |||
152 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
153 | sprintf(&(buf[i*2]),"%02x",md[i]); | ||
154 | return(buf); | ||
155 | } | ||
diff --git a/src/lib/libcrypto/sha/sha_dgst.c b/src/lib/libcrypto/sha/sha_dgst.c new file mode 100644 index 0000000000..8ed533ea26 --- /dev/null +++ b/src/lib/libcrypto/sha/sha_dgst.c | |||
@@ -0,0 +1,442 @@ | |||
1 | /* crypto/sha/sha_dgst.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 <string.h> | ||
61 | #define SHA_0 | ||
62 | #undef SHA_1 | ||
63 | #include "sha.h" | ||
64 | #include "sha_locl.h" | ||
65 | |||
66 | char *SHA_version="SHA part of SSLeay 0.9.0b 29-Jun-1998"; | ||
67 | |||
68 | /* Implemented from SHA-0 document - The Secure Hash Algorithm | ||
69 | */ | ||
70 | |||
71 | #define INIT_DATA_h0 (unsigned long)0x67452301L | ||
72 | #define INIT_DATA_h1 (unsigned long)0xefcdab89L | ||
73 | #define INIT_DATA_h2 (unsigned long)0x98badcfeL | ||
74 | #define INIT_DATA_h3 (unsigned long)0x10325476L | ||
75 | #define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L | ||
76 | |||
77 | #define K_00_19 0x5a827999L | ||
78 | #define K_20_39 0x6ed9eba1L | ||
79 | #define K_40_59 0x8f1bbcdcL | ||
80 | #define K_60_79 0xca62c1d6L | ||
81 | |||
82 | #ifndef NOPROTO | ||
83 | void sha_block(SHA_CTX *c, register unsigned long *p, int num); | ||
84 | #else | ||
85 | void sha_block(); | ||
86 | #endif | ||
87 | |||
88 | #define M_c2nl c2nl | ||
89 | #define M_p_c2nl p_c2nl | ||
90 | #define M_c2nl_p c2nl_p | ||
91 | #define M_p_c2nl_p p_c2nl_p | ||
92 | #define M_nl2c nl2c | ||
93 | |||
94 | void SHA_Init(c) | ||
95 | SHA_CTX *c; | ||
96 | { | ||
97 | c->h0=INIT_DATA_h0; | ||
98 | c->h1=INIT_DATA_h1; | ||
99 | c->h2=INIT_DATA_h2; | ||
100 | c->h3=INIT_DATA_h3; | ||
101 | c->h4=INIT_DATA_h4; | ||
102 | c->Nl=0; | ||
103 | c->Nh=0; | ||
104 | c->num=0; | ||
105 | } | ||
106 | |||
107 | void SHA_Update(c, data, len) | ||
108 | SHA_CTX *c; | ||
109 | register unsigned char *data; | ||
110 | unsigned long len; | ||
111 | { | ||
112 | register ULONG *p; | ||
113 | int ew,ec,sw,sc; | ||
114 | ULONG l; | ||
115 | |||
116 | if (len == 0) return; | ||
117 | |||
118 | l=(c->Nl+(len<<3))&0xffffffffL; | ||
119 | if (l < c->Nl) /* overflow */ | ||
120 | c->Nh++; | ||
121 | c->Nh+=(len>>29); | ||
122 | c->Nl=l; | ||
123 | |||
124 | if (c->num != 0) | ||
125 | { | ||
126 | p=c->data; | ||
127 | sw=c->num>>2; | ||
128 | sc=c->num&0x03; | ||
129 | |||
130 | if ((c->num+len) >= SHA_CBLOCK) | ||
131 | { | ||
132 | l= p[sw]; | ||
133 | M_p_c2nl(data,l,sc); | ||
134 | p[sw++]=l; | ||
135 | for (; sw<SHA_LBLOCK; sw++) | ||
136 | { | ||
137 | M_c2nl(data,l); | ||
138 | p[sw]=l; | ||
139 | } | ||
140 | len-=(SHA_CBLOCK-c->num); | ||
141 | |||
142 | sha_block(c,p,64); | ||
143 | c->num=0; | ||
144 | /* drop through and do the rest */ | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | c->num+=(int)len; | ||
149 | if ((sc+len) < 4) /* ugly, add char's to a word */ | ||
150 | { | ||
151 | l= p[sw]; | ||
152 | M_p_c2nl_p(data,l,sc,len); | ||
153 | p[sw]=l; | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | ew=(c->num>>2); | ||
158 | ec=(c->num&0x03); | ||
159 | l= p[sw]; | ||
160 | M_p_c2nl(data,l,sc); | ||
161 | p[sw++]=l; | ||
162 | for (; sw < ew; sw++) | ||
163 | { M_c2nl(data,l); p[sw]=l; } | ||
164 | if (ec) | ||
165 | { | ||
166 | M_c2nl_p(data,l,ec); | ||
167 | p[sw]=l; | ||
168 | } | ||
169 | } | ||
170 | return; | ||
171 | } | ||
172 | } | ||
173 | /* We can only do the following code for assember, the reason | ||
174 | * being that the sha_block 'C' version changes the values | ||
175 | * in the 'data' array. The assember code avoids this and | ||
176 | * copies it to a local array. I should be able to do this for | ||
177 | * the C version as well.... | ||
178 | */ | ||
179 | #if 1 | ||
180 | #if defined(B_ENDIAN) || defined(SHA_ASM) | ||
181 | if ((((unsigned int)data)%sizeof(ULONG)) == 0) | ||
182 | { | ||
183 | sw=len/SHA_CBLOCK; | ||
184 | if (sw) | ||
185 | { | ||
186 | sw*=SHA_CBLOCK; | ||
187 | sha_block(c,(ULONG *)data,sw); | ||
188 | data+=sw; | ||
189 | len-=sw; | ||
190 | } | ||
191 | } | ||
192 | #endif | ||
193 | #endif | ||
194 | /* we now can process the input data in blocks of SHA_CBLOCK | ||
195 | * chars and save the leftovers to c->data. */ | ||
196 | p=c->data; | ||
197 | while (len >= SHA_CBLOCK) | ||
198 | { | ||
199 | #if defined(B_ENDIAN) || defined(L_ENDIAN) | ||
200 | if (p != (unsigned long *)data) | ||
201 | memcpy(p,data,SHA_CBLOCK); | ||
202 | data+=SHA_CBLOCK; | ||
203 | # ifdef L_ENDIAN | ||
204 | # ifndef SHA_ASM /* Will not happen */ | ||
205 | for (sw=(SHA_LBLOCK/4); sw; sw--) | ||
206 | { | ||
207 | Endian_Reverse32(p[0]); | ||
208 | Endian_Reverse32(p[1]); | ||
209 | Endian_Reverse32(p[2]); | ||
210 | Endian_Reverse32(p[3]); | ||
211 | p+=4; | ||
212 | } | ||
213 | p=c->data; | ||
214 | # endif | ||
215 | # endif | ||
216 | #else | ||
217 | for (sw=(SHA_BLOCK/4); sw; sw--) | ||
218 | { | ||
219 | M_c2nl(data,l); *(p++)=l; | ||
220 | M_c2nl(data,l); *(p++)=l; | ||
221 | M_c2nl(data,l); *(p++)=l; | ||
222 | M_c2nl(data,l); *(p++)=l; | ||
223 | } | ||
224 | p=c->data; | ||
225 | #endif | ||
226 | sha_block(c,p,64); | ||
227 | len-=SHA_CBLOCK; | ||
228 | } | ||
229 | ec=(int)len; | ||
230 | c->num=ec; | ||
231 | ew=(ec>>2); | ||
232 | ec&=0x03; | ||
233 | |||
234 | for (sw=0; sw < ew; sw++) | ||
235 | { M_c2nl(data,l); p[sw]=l; } | ||
236 | M_c2nl_p(data,l,ec); | ||
237 | p[sw]=l; | ||
238 | } | ||
239 | |||
240 | void SHA_Transform(c,b) | ||
241 | SHA_CTX *c; | ||
242 | unsigned char *b; | ||
243 | { | ||
244 | ULONG p[16]; | ||
245 | #if !defined(B_ENDIAN) | ||
246 | ULONG *q; | ||
247 | int i; | ||
248 | #endif | ||
249 | |||
250 | #if defined(B_ENDIAN) || defined(L_ENDIAN) | ||
251 | memcpy(p,b,64); | ||
252 | #ifdef L_ENDIAN | ||
253 | q=p; | ||
254 | for (i=(SHA_LBLOCK/4); i; i--) | ||
255 | { | ||
256 | Endian_Reverse32(q[0]); | ||
257 | Endian_Reverse32(q[1]); | ||
258 | Endian_Reverse32(q[2]); | ||
259 | Endian_Reverse32(q[3]); | ||
260 | q+=4; | ||
261 | } | ||
262 | #endif | ||
263 | #else | ||
264 | q=p; | ||
265 | for (i=(SHA_LBLOCK/4); i; i--) | ||
266 | { | ||
267 | ULONG l; | ||
268 | c2nl(b,l); *(q++)=l; | ||
269 | c2nl(b,l); *(q++)=l; | ||
270 | c2nl(b,l); *(q++)=l; | ||
271 | c2nl(b,l); *(q++)=l; | ||
272 | } | ||
273 | #endif | ||
274 | sha_block(c,p,64); | ||
275 | } | ||
276 | |||
277 | void sha_block(c, W, num) | ||
278 | SHA_CTX *c; | ||
279 | register unsigned long *W; | ||
280 | int num; | ||
281 | { | ||
282 | register ULONG A,B,C,D,E,T; | ||
283 | ULONG X[16]; | ||
284 | |||
285 | A=c->h0; | ||
286 | B=c->h1; | ||
287 | C=c->h2; | ||
288 | D=c->h3; | ||
289 | E=c->h4; | ||
290 | |||
291 | for (;;) | ||
292 | { | ||
293 | BODY_00_15( 0,A,B,C,D,E,T,W); | ||
294 | BODY_00_15( 1,T,A,B,C,D,E,W); | ||
295 | BODY_00_15( 2,E,T,A,B,C,D,W); | ||
296 | BODY_00_15( 3,D,E,T,A,B,C,W); | ||
297 | BODY_00_15( 4,C,D,E,T,A,B,W); | ||
298 | BODY_00_15( 5,B,C,D,E,T,A,W); | ||
299 | BODY_00_15( 6,A,B,C,D,E,T,W); | ||
300 | BODY_00_15( 7,T,A,B,C,D,E,W); | ||
301 | BODY_00_15( 8,E,T,A,B,C,D,W); | ||
302 | BODY_00_15( 9,D,E,T,A,B,C,W); | ||
303 | BODY_00_15(10,C,D,E,T,A,B,W); | ||
304 | BODY_00_15(11,B,C,D,E,T,A,W); | ||
305 | BODY_00_15(12,A,B,C,D,E,T,W); | ||
306 | BODY_00_15(13,T,A,B,C,D,E,W); | ||
307 | BODY_00_15(14,E,T,A,B,C,D,W); | ||
308 | BODY_00_15(15,D,E,T,A,B,C,W); | ||
309 | BODY_16_19(16,C,D,E,T,A,B,W,W,W,W); | ||
310 | BODY_16_19(17,B,C,D,E,T,A,W,W,W,W); | ||
311 | BODY_16_19(18,A,B,C,D,E,T,W,W,W,W); | ||
312 | BODY_16_19(19,T,A,B,C,D,E,W,W,W,X); | ||
313 | |||
314 | BODY_20_31(20,E,T,A,B,C,D,W,W,W,X); | ||
315 | BODY_20_31(21,D,E,T,A,B,C,W,W,W,X); | ||
316 | BODY_20_31(22,C,D,E,T,A,B,W,W,W,X); | ||
317 | BODY_20_31(23,B,C,D,E,T,A,W,W,W,X); | ||
318 | BODY_20_31(24,A,B,C,D,E,T,W,W,X,X); | ||
319 | BODY_20_31(25,T,A,B,C,D,E,W,W,X,X); | ||
320 | BODY_20_31(26,E,T,A,B,C,D,W,W,X,X); | ||
321 | BODY_20_31(27,D,E,T,A,B,C,W,W,X,X); | ||
322 | BODY_20_31(28,C,D,E,T,A,B,W,W,X,X); | ||
323 | BODY_20_31(29,B,C,D,E,T,A,W,W,X,X); | ||
324 | BODY_20_31(30,A,B,C,D,E,T,W,X,X,X); | ||
325 | BODY_20_31(31,T,A,B,C,D,E,W,X,X,X); | ||
326 | BODY_32_39(32,E,T,A,B,C,D,X); | ||
327 | BODY_32_39(33,D,E,T,A,B,C,X); | ||
328 | BODY_32_39(34,C,D,E,T,A,B,X); | ||
329 | BODY_32_39(35,B,C,D,E,T,A,X); | ||
330 | BODY_32_39(36,A,B,C,D,E,T,X); | ||
331 | BODY_32_39(37,T,A,B,C,D,E,X); | ||
332 | BODY_32_39(38,E,T,A,B,C,D,X); | ||
333 | BODY_32_39(39,D,E,T,A,B,C,X); | ||
334 | |||
335 | BODY_40_59(40,C,D,E,T,A,B,X); | ||
336 | BODY_40_59(41,B,C,D,E,T,A,X); | ||
337 | BODY_40_59(42,A,B,C,D,E,T,X); | ||
338 | BODY_40_59(43,T,A,B,C,D,E,X); | ||
339 | BODY_40_59(44,E,T,A,B,C,D,X); | ||
340 | BODY_40_59(45,D,E,T,A,B,C,X); | ||
341 | BODY_40_59(46,C,D,E,T,A,B,X); | ||
342 | BODY_40_59(47,B,C,D,E,T,A,X); | ||
343 | BODY_40_59(48,A,B,C,D,E,T,X); | ||
344 | BODY_40_59(49,T,A,B,C,D,E,X); | ||
345 | BODY_40_59(50,E,T,A,B,C,D,X); | ||
346 | BODY_40_59(51,D,E,T,A,B,C,X); | ||
347 | BODY_40_59(52,C,D,E,T,A,B,X); | ||
348 | BODY_40_59(53,B,C,D,E,T,A,X); | ||
349 | BODY_40_59(54,A,B,C,D,E,T,X); | ||
350 | BODY_40_59(55,T,A,B,C,D,E,X); | ||
351 | BODY_40_59(56,E,T,A,B,C,D,X); | ||
352 | BODY_40_59(57,D,E,T,A,B,C,X); | ||
353 | BODY_40_59(58,C,D,E,T,A,B,X); | ||
354 | BODY_40_59(59,B,C,D,E,T,A,X); | ||
355 | |||
356 | BODY_60_79(60,A,B,C,D,E,T,X); | ||
357 | BODY_60_79(61,T,A,B,C,D,E,X); | ||
358 | BODY_60_79(62,E,T,A,B,C,D,X); | ||
359 | BODY_60_79(63,D,E,T,A,B,C,X); | ||
360 | BODY_60_79(64,C,D,E,T,A,B,X); | ||
361 | BODY_60_79(65,B,C,D,E,T,A,X); | ||
362 | BODY_60_79(66,A,B,C,D,E,T,X); | ||
363 | BODY_60_79(67,T,A,B,C,D,E,X); | ||
364 | BODY_60_79(68,E,T,A,B,C,D,X); | ||
365 | BODY_60_79(69,D,E,T,A,B,C,X); | ||
366 | BODY_60_79(70,C,D,E,T,A,B,X); | ||
367 | BODY_60_79(71,B,C,D,E,T,A,X); | ||
368 | BODY_60_79(72,A,B,C,D,E,T,X); | ||
369 | BODY_60_79(73,T,A,B,C,D,E,X); | ||
370 | BODY_60_79(74,E,T,A,B,C,D,X); | ||
371 | BODY_60_79(75,D,E,T,A,B,C,X); | ||
372 | BODY_60_79(76,C,D,E,T,A,B,X); | ||
373 | BODY_60_79(77,B,C,D,E,T,A,X); | ||
374 | BODY_60_79(78,A,B,C,D,E,T,X); | ||
375 | BODY_60_79(79,T,A,B,C,D,E,X); | ||
376 | |||
377 | c->h0=(c->h0+E)&0xffffffffL; | ||
378 | c->h1=(c->h1+T)&0xffffffffL; | ||
379 | c->h2=(c->h2+A)&0xffffffffL; | ||
380 | c->h3=(c->h3+B)&0xffffffffL; | ||
381 | c->h4=(c->h4+C)&0xffffffffL; | ||
382 | |||
383 | num-=64; | ||
384 | if (num <= 0) break; | ||
385 | |||
386 | A=c->h0; | ||
387 | B=c->h1; | ||
388 | C=c->h2; | ||
389 | D=c->h3; | ||
390 | E=c->h4; | ||
391 | |||
392 | W+=16; | ||
393 | } | ||
394 | } | ||
395 | |||
396 | void SHA_Final(md, c) | ||
397 | unsigned char *md; | ||
398 | SHA_CTX *c; | ||
399 | { | ||
400 | register int i,j; | ||
401 | register ULONG l; | ||
402 | register ULONG *p; | ||
403 | static unsigned char end[4]={0x80,0x00,0x00,0x00}; | ||
404 | unsigned char *cp=end; | ||
405 | |||
406 | /* c->num should definitly have room for at least one more byte. */ | ||
407 | p=c->data; | ||
408 | j=c->num; | ||
409 | i=j>>2; | ||
410 | #ifdef PURIFY | ||
411 | if ((j&0x03) == 0) p[i]=0; | ||
412 | #endif | ||
413 | l=p[i]; | ||
414 | M_p_c2nl(cp,l,j&0x03); | ||
415 | p[i]=l; | ||
416 | i++; | ||
417 | /* i is the next 'undefined word' */ | ||
418 | if (c->num >= SHA_LAST_BLOCK) | ||
419 | { | ||
420 | for (; i<SHA_LBLOCK; i++) | ||
421 | p[i]=0; | ||
422 | sha_block(c,p,64); | ||
423 | i=0; | ||
424 | } | ||
425 | for (; i<(SHA_LBLOCK-2); i++) | ||
426 | p[i]=0; | ||
427 | p[SHA_LBLOCK-2]=c->Nh; | ||
428 | p[SHA_LBLOCK-1]=c->Nl; | ||
429 | sha_block(c,p,64); | ||
430 | cp=md; | ||
431 | l=c->h0; nl2c(l,cp); | ||
432 | l=c->h1; nl2c(l,cp); | ||
433 | l=c->h2; nl2c(l,cp); | ||
434 | l=c->h3; nl2c(l,cp); | ||
435 | l=c->h4; nl2c(l,cp); | ||
436 | |||
437 | /* clear stuff, sha_block may be leaving some stuff on the stack | ||
438 | * but I'm not worried :-) */ | ||
439 | c->num=0; | ||
440 | /* memset((char *)&c,0,sizeof(c));*/ | ||
441 | } | ||
442 | |||
diff --git a/src/lib/libcrypto/sha/sha_one.c b/src/lib/libcrypto/sha/sha_one.c new file mode 100644 index 0000000000..18ab7f61bc --- /dev/null +++ b/src/lib/libcrypto/sha/sha_one.c | |||
@@ -0,0 +1,77 @@ | |||
1 | /* crypto/sha/sha_one.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 <string.h> | ||
61 | #include "sha.h" | ||
62 | |||
63 | unsigned char *SHA(d, n, md) | ||
64 | unsigned char *d; | ||
65 | unsigned long n; | ||
66 | unsigned char *md; | ||
67 | { | ||
68 | SHA_CTX c; | ||
69 | static unsigned char m[SHA_DIGEST_LENGTH]; | ||
70 | |||
71 | if (md == NULL) md=m; | ||
72 | SHA_Init(&c); | ||
73 | SHA_Update(&c,d,n); | ||
74 | SHA_Final(md,&c); | ||
75 | memset(&c,0,sizeof(c)); | ||
76 | return(md); | ||
77 | } | ||
diff --git a/src/lib/libcrypto/sha/shatest.c b/src/lib/libcrypto/sha/shatest.c new file mode 100644 index 0000000000..03816e9b39 --- /dev/null +++ b/src/lib/libcrypto/sha/shatest.c | |||
@@ -0,0 +1,155 @@ | |||
1 | /* crypto/sha/shatest.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 <string.h> | ||
61 | #include <stdlib.h> | ||
62 | #include "sha.h" | ||
63 | |||
64 | #define SHA_0 /* FIPS 180 */ | ||
65 | #undef SHA_1 /* FIPS 180-1 */ | ||
66 | |||
67 | char *test[]={ | ||
68 | "abc", | ||
69 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | ||
70 | NULL, | ||
71 | }; | ||
72 | |||
73 | #ifdef SHA_0 | ||
74 | char *ret[]={ | ||
75 | "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", | ||
76 | "d2516ee1acfa5baf33dfc1c471e438449ef134c8", | ||
77 | }; | ||
78 | char *bigret= | ||
79 | "3232affa48628a26653b5aaa44541fd90d690603"; | ||
80 | #endif | ||
81 | #ifdef SHA_1 | ||
82 | char *ret[]={ | ||
83 | "a9993e364706816aba3e25717850c26c9cd0d89d", | ||
84 | "84983e441c3bd26ebaae4aa1f95129e5e54670f1", | ||
85 | }; | ||
86 | char *bigret= | ||
87 | "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; | ||
88 | #endif | ||
89 | |||
90 | #ifndef NOPROTO | ||
91 | static char *pt(unsigned char *md); | ||
92 | #else | ||
93 | static char *pt(); | ||
94 | #endif | ||
95 | |||
96 | int main(argc,argv) | ||
97 | int argc; | ||
98 | char *argv[]; | ||
99 | { | ||
100 | int i,err=0; | ||
101 | unsigned char **P,**R; | ||
102 | static unsigned char buf[1000]; | ||
103 | char *p,*r; | ||
104 | SHA_CTX c; | ||
105 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
106 | |||
107 | P=(unsigned char **)test; | ||
108 | R=(unsigned char **)ret; | ||
109 | i=1; | ||
110 | while (*P != NULL) | ||
111 | { | ||
112 | p=pt(SHA(*P,(unsigned long)strlen((char *)*P),NULL)); | ||
113 | if (strcmp(p,(char *)*R) != 0) | ||
114 | { | ||
115 | printf("error calculating SHA on '%s'\n",*P); | ||
116 | printf("got %s instead of %s\n",p,*R); | ||
117 | err++; | ||
118 | } | ||
119 | else | ||
120 | printf("test %d ok\n",i); | ||
121 | i++; | ||
122 | R++; | ||
123 | P++; | ||
124 | } | ||
125 | |||
126 | memset(buf,'a',1000); | ||
127 | SHA_Init(&c); | ||
128 | for (i=0; i<1000; i++) | ||
129 | SHA_Update(&c,buf,1000); | ||
130 | SHA_Final(md,&c); | ||
131 | p=pt(md); | ||
132 | |||
133 | r=bigret; | ||
134 | if (strcmp(p,r) != 0) | ||
135 | { | ||
136 | printf("error calculating SHA on '%s'\n",p); | ||
137 | printf("got %s instead of %s\n",p,r); | ||
138 | err++; | ||
139 | } | ||
140 | else | ||
141 | printf("test 3 ok\n"); | ||
142 | exit(err); | ||
143 | return(0); | ||
144 | } | ||
145 | |||
146 | static char *pt(md) | ||
147 | unsigned char *md; | ||
148 | { | ||
149 | int i; | ||
150 | static char buf[80]; | ||
151 | |||
152 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
153 | sprintf(&(buf[i*2]),"%02x",md[i]); | ||
154 | return(buf); | ||
155 | } | ||
diff --git a/src/lib/libcrypto/threads/mttest.c b/src/lib/libcrypto/threads/mttest.c new file mode 100644 index 0000000000..be395f2bc4 --- /dev/null +++ b/src/lib/libcrypto/threads/mttest.c | |||
@@ -0,0 +1,1115 @@ | |||
1 | /* crypto/threads/mttest.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 <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #include <errno.h> | ||
63 | #ifdef LINUX | ||
64 | #include <typedefs.h> | ||
65 | #endif | ||
66 | #ifdef WIN32 | ||
67 | #include <windows.h> | ||
68 | #endif | ||
69 | #ifdef SOLARIS | ||
70 | #include <synch.h> | ||
71 | #include <thread.h> | ||
72 | #endif | ||
73 | #ifdef IRIX | ||
74 | #include <ulocks.h> | ||
75 | #include <sys/prctl.h> | ||
76 | #endif | ||
77 | #include "lhash.h" | ||
78 | #include "crypto.h" | ||
79 | #include "buffer.h" | ||
80 | #include "../e_os.h" | ||
81 | #include "x509.h" | ||
82 | #include "ssl.h" | ||
83 | #include "err.h" | ||
84 | |||
85 | #ifdef NO_FP_API | ||
86 | #define APPS_WIN16 | ||
87 | #include "../crypto/buffer/bss_file.c" | ||
88 | #endif | ||
89 | |||
90 | #define TEST_SERVER_CERT "../apps/server.pem" | ||
91 | #define TEST_CLIENT_CERT "../apps/client.pem" | ||
92 | |||
93 | #define MAX_THREAD_NUMBER 100 | ||
94 | |||
95 | #ifndef NOPROTO | ||
96 | int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, | ||
97 | int error,char *arg); | ||
98 | void thread_setup(void); | ||
99 | void thread_cleanup(void); | ||
100 | void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx); | ||
101 | |||
102 | void irix_locking_callback(int mode,int type,char *file,int line); | ||
103 | void solaris_locking_callback(int mode,int type,char *file,int line); | ||
104 | void win32_locking_callback(int mode,int type,char *file,int line); | ||
105 | void pthreads_locking_callback(int mode,int type,char *file,int line); | ||
106 | |||
107 | unsigned long irix_thread_id(void ); | ||
108 | unsigned long solaris_thread_id(void ); | ||
109 | unsigned long pthreads_thread_id(void ); | ||
110 | |||
111 | #else | ||
112 | int MS_CALLBACK verify_callback(); | ||
113 | void thread_setup(); | ||
114 | void thread_cleanup(); | ||
115 | void do_threads(); | ||
116 | |||
117 | void irix_locking_callback(); | ||
118 | void solaris_locking_callback(); | ||
119 | void win32_locking_callback(); | ||
120 | void pthreads_locking_callback(); | ||
121 | |||
122 | unsigned long irix_thread_id(); | ||
123 | unsigned long solaris_thread_id(); | ||
124 | unsigned long pthreads_thread_id(); | ||
125 | |||
126 | #endif | ||
127 | |||
128 | BIO *bio_err=NULL; | ||
129 | BIO *bio_stdout=NULL; | ||
130 | |||
131 | static char *cipher=NULL; | ||
132 | int verbose=0; | ||
133 | #ifdef FIONBIO | ||
134 | static int s_nbio=0; | ||
135 | #endif | ||
136 | |||
137 | int thread_number=10; | ||
138 | int number_of_loops=10; | ||
139 | int reconnect=0; | ||
140 | int cache_stats=0; | ||
141 | |||
142 | #ifndef NOPROTO | ||
143 | int doit(char *ctx[4]); | ||
144 | #else | ||
145 | int doit(); | ||
146 | #endif | ||
147 | |||
148 | static void print_stats(fp,ctx) | ||
149 | FILE *fp; | ||
150 | SSL_CTX *ctx; | ||
151 | { | ||
152 | fprintf(fp,"%4ld items in the session cache\n", | ||
153 | SSL_CTX_sess_number(ctx)); | ||
154 | fprintf(fp,"%4d client connects (SSL_connect())\n", | ||
155 | SSL_CTX_sess_connect(ctx)); | ||
156 | fprintf(fp,"%4d client connects that finished\n", | ||
157 | SSL_CTX_sess_connect_good(ctx)); | ||
158 | fprintf(fp,"%4d server connects (SSL_accept())\n", | ||
159 | SSL_CTX_sess_accept(ctx)); | ||
160 | fprintf(fp,"%4d server connects that finished\n", | ||
161 | SSL_CTX_sess_accept_good(ctx)); | ||
162 | fprintf(fp,"%4d session cache hits\n",SSL_CTX_sess_hits(ctx)); | ||
163 | fprintf(fp,"%4d session cache misses\n",SSL_CTX_sess_misses(ctx)); | ||
164 | fprintf(fp,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ctx)); | ||
165 | } | ||
166 | |||
167 | static void sv_usage() | ||
168 | { | ||
169 | fprintf(stderr,"usage: ssltest [args ...]\n"); | ||
170 | fprintf(stderr,"\n"); | ||
171 | fprintf(stderr," -server_auth - check server certificate\n"); | ||
172 | fprintf(stderr," -client_auth - do client authentication\n"); | ||
173 | fprintf(stderr," -v - more output\n"); | ||
174 | fprintf(stderr," -CApath arg - PEM format directory of CA's\n"); | ||
175 | fprintf(stderr," -CAfile arg - PEM format file of CA's\n"); | ||
176 | fprintf(stderr," -threads arg - number of threads\n"); | ||
177 | fprintf(stderr," -loops arg - number of 'connections', per thread\n"); | ||
178 | fprintf(stderr," -reconnect - reuse session-id's\n"); | ||
179 | fprintf(stderr," -stats - server session-id cache stats\n"); | ||
180 | fprintf(stderr," -cert arg - server certificate/key\n"); | ||
181 | fprintf(stderr," -ccert arg - client certificate/key\n"); | ||
182 | fprintf(stderr," -ssl3 - just SSLv3n\n"); | ||
183 | } | ||
184 | |||
185 | int main(argc, argv) | ||
186 | int argc; | ||
187 | char *argv[]; | ||
188 | { | ||
189 | char *CApath=NULL,*CAfile=NULL; | ||
190 | int badop=0; | ||
191 | int ret=1; | ||
192 | int client_auth=0; | ||
193 | int server_auth=0; | ||
194 | SSL_CTX *s_ctx=NULL; | ||
195 | SSL_CTX *c_ctx=NULL; | ||
196 | char *scert=TEST_SERVER_CERT; | ||
197 | char *ccert=TEST_CLIENT_CERT; | ||
198 | SSL_METHOD *ssl_method=SSLv23_method(); | ||
199 | |||
200 | if (bio_err == NULL) | ||
201 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); | ||
202 | if (bio_stdout == NULL) | ||
203 | bio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE); | ||
204 | argc--; | ||
205 | argv++; | ||
206 | |||
207 | while (argc >= 1) | ||
208 | { | ||
209 | if (strcmp(*argv,"-server_auth") == 0) | ||
210 | server_auth=1; | ||
211 | else if (strcmp(*argv,"-client_auth") == 0) | ||
212 | client_auth=1; | ||
213 | else if (strcmp(*argv,"-reconnect") == 0) | ||
214 | reconnect=1; | ||
215 | else if (strcmp(*argv,"-stats") == 0) | ||
216 | cache_stats=1; | ||
217 | else if (strcmp(*argv,"-ssl3") == 0) | ||
218 | ssl_method=SSLv3_method(); | ||
219 | else if (strcmp(*argv,"-ssl2") == 0) | ||
220 | ssl_method=SSLv2_method(); | ||
221 | else if (strcmp(*argv,"-CApath") == 0) | ||
222 | { | ||
223 | if (--argc < 1) goto bad; | ||
224 | CApath= *(++argv); | ||
225 | } | ||
226 | else if (strcmp(*argv,"-CAfile") == 0) | ||
227 | { | ||
228 | if (--argc < 1) goto bad; | ||
229 | CAfile= *(++argv); | ||
230 | } | ||
231 | else if (strcmp(*argv,"-cert") == 0) | ||
232 | { | ||
233 | if (--argc < 1) goto bad; | ||
234 | scert= *(++argv); | ||
235 | } | ||
236 | else if (strcmp(*argv,"-ccert") == 0) | ||
237 | { | ||
238 | if (--argc < 1) goto bad; | ||
239 | ccert= *(++argv); | ||
240 | } | ||
241 | else if (strcmp(*argv,"-threads") == 0) | ||
242 | { | ||
243 | if (--argc < 1) goto bad; | ||
244 | thread_number= atoi(*(++argv)); | ||
245 | if (thread_number == 0) thread_number=1; | ||
246 | if (thread_number > MAX_THREAD_NUMBER) | ||
247 | thread_number=MAX_THREAD_NUMBER; | ||
248 | } | ||
249 | else if (strcmp(*argv,"-loops") == 0) | ||
250 | { | ||
251 | if (--argc < 1) goto bad; | ||
252 | number_of_loops= atoi(*(++argv)); | ||
253 | if (number_of_loops == 0) number_of_loops=1; | ||
254 | } | ||
255 | else | ||
256 | { | ||
257 | fprintf(stderr,"unknown option %s\n",*argv); | ||
258 | badop=1; | ||
259 | break; | ||
260 | } | ||
261 | argc--; | ||
262 | argv++; | ||
263 | } | ||
264 | if (badop) | ||
265 | { | ||
266 | bad: | ||
267 | sv_usage(); | ||
268 | goto end; | ||
269 | } | ||
270 | |||
271 | if (cipher == NULL) cipher=getenv("SSL_CIPHER"); | ||
272 | |||
273 | SSL_load_error_strings(); | ||
274 | SSLeay_add_ssl_algorithms(); | ||
275 | |||
276 | c_ctx=SSL_CTX_new(ssl_method); | ||
277 | s_ctx=SSL_CTX_new(ssl_method); | ||
278 | if ((c_ctx == NULL) || (s_ctx == NULL)) | ||
279 | { | ||
280 | ERR_print_errors(bio_err); | ||
281 | goto end; | ||
282 | } | ||
283 | |||
284 | SSL_CTX_set_session_cache_mode(s_ctx, | ||
285 | SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER); | ||
286 | SSL_CTX_set_session_cache_mode(c_ctx, | ||
287 | SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER); | ||
288 | |||
289 | SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM); | ||
290 | SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM); | ||
291 | |||
292 | if (client_auth) | ||
293 | { | ||
294 | SSL_CTX_use_certificate_file(c_ctx,ccert, | ||
295 | SSL_FILETYPE_PEM); | ||
296 | SSL_CTX_use_RSAPrivateKey_file(c_ctx,ccert, | ||
297 | SSL_FILETYPE_PEM); | ||
298 | } | ||
299 | |||
300 | if ( (!SSL_CTX_load_verify_locations(s_ctx,CAfile,CApath)) || | ||
301 | (!SSL_CTX_set_default_verify_paths(s_ctx)) || | ||
302 | (!SSL_CTX_load_verify_locations(c_ctx,CAfile,CApath)) || | ||
303 | (!SSL_CTX_set_default_verify_paths(c_ctx))) | ||
304 | { | ||
305 | fprintf(stderr,"SSL_load_verify_locations\n"); | ||
306 | ERR_print_errors(bio_err); | ||
307 | goto end; | ||
308 | } | ||
309 | |||
310 | if (client_auth) | ||
311 | { | ||
312 | fprintf(stderr,"client authentication\n"); | ||
313 | SSL_CTX_set_verify(s_ctx, | ||
314 | SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, | ||
315 | verify_callback); | ||
316 | } | ||
317 | if (server_auth) | ||
318 | { | ||
319 | fprintf(stderr,"server authentication\n"); | ||
320 | SSL_CTX_set_verify(c_ctx,SSL_VERIFY_PEER, | ||
321 | verify_callback); | ||
322 | } | ||
323 | |||
324 | thread_setup(); | ||
325 | do_threads(s_ctx,c_ctx); | ||
326 | thread_cleanup(); | ||
327 | end: | ||
328 | |||
329 | if (c_ctx != NULL) | ||
330 | { | ||
331 | fprintf(stderr,"Client SSL_CTX stats then free it\n"); | ||
332 | print_stats(stderr,c_ctx); | ||
333 | SSL_CTX_free(c_ctx); | ||
334 | } | ||
335 | if (s_ctx != NULL) | ||
336 | { | ||
337 | fprintf(stderr,"Server SSL_CTX stats then free it\n"); | ||
338 | print_stats(stderr,s_ctx); | ||
339 | if (cache_stats) | ||
340 | { | ||
341 | fprintf(stderr,"-----\n"); | ||
342 | lh_stats(SSL_CTX_sessions(s_ctx),stderr); | ||
343 | fprintf(stderr,"-----\n"); | ||
344 | /* lh_node_stats(SSL_CTX_sessions(s_ctx),stderr); | ||
345 | fprintf(stderr,"-----\n"); */ | ||
346 | lh_node_usage_stats(SSL_CTX_sessions(s_ctx),stderr); | ||
347 | fprintf(stderr,"-----\n"); | ||
348 | } | ||
349 | SSL_CTX_free(s_ctx); | ||
350 | fprintf(stderr,"done free\n"); | ||
351 | } | ||
352 | exit(ret); | ||
353 | return(0); | ||
354 | } | ||
355 | |||
356 | #define W_READ 1 | ||
357 | #define W_WRITE 2 | ||
358 | #define C_DONE 1 | ||
359 | #define S_DONE 2 | ||
360 | |||
361 | int ndoit(ssl_ctx) | ||
362 | SSL_CTX *ssl_ctx[2]; | ||
363 | { | ||
364 | int i; | ||
365 | int ret; | ||
366 | char *ctx[4]; | ||
367 | |||
368 | ctx[0]=(char *)ssl_ctx[0]; | ||
369 | ctx[1]=(char *)ssl_ctx[1]; | ||
370 | |||
371 | if (reconnect) | ||
372 | { | ||
373 | ctx[2]=(char *)SSL_new(ssl_ctx[0]); | ||
374 | ctx[3]=(char *)SSL_new(ssl_ctx[1]); | ||
375 | } | ||
376 | else | ||
377 | { | ||
378 | ctx[2]=NULL; | ||
379 | ctx[3]=NULL; | ||
380 | } | ||
381 | |||
382 | fprintf(stdout,"started thread %lu\n",CRYPTO_thread_id()); | ||
383 | for (i=0; i<number_of_loops; i++) | ||
384 | { | ||
385 | /* fprintf(stderr,"%4d %2d ctx->ref (%3d,%3d)\n", | ||
386 | CRYPTO_thread_id(),i, | ||
387 | ssl_ctx[0]->references, | ||
388 | ssl_ctx[1]->references); */ | ||
389 | /* pthread_delay_np(&tm);*/ | ||
390 | |||
391 | ret=doit(ctx); | ||
392 | if (ret != 0) | ||
393 | { | ||
394 | fprintf(stdout,"error[%d] %lu - %d\n", | ||
395 | i,CRYPTO_thread_id(),ret); | ||
396 | return(ret); | ||
397 | } | ||
398 | } | ||
399 | fprintf(stdout,"DONE %lu\n",CRYPTO_thread_id()); | ||
400 | if (reconnect) | ||
401 | { | ||
402 | SSL_free((SSL *)ctx[2]); | ||
403 | SSL_free((SSL *)ctx[3]); | ||
404 | } | ||
405 | return(0); | ||
406 | } | ||
407 | |||
408 | int doit(ctx) | ||
409 | char *ctx[4]; | ||
410 | { | ||
411 | SSL_CTX *s_ctx,*c_ctx; | ||
412 | static char cbuf[200],sbuf[200]; | ||
413 | SSL *c_ssl=NULL; | ||
414 | SSL *s_ssl=NULL; | ||
415 | BIO *c_to_s=NULL; | ||
416 | BIO *s_to_c=NULL; | ||
417 | BIO *c_bio=NULL; | ||
418 | BIO *s_bio=NULL; | ||
419 | int c_r,c_w,s_r,s_w; | ||
420 | int c_want,s_want; | ||
421 | int i; | ||
422 | int done=0; | ||
423 | int c_write,s_write; | ||
424 | int do_server=0,do_client=0; | ||
425 | |||
426 | s_ctx=(SSL_CTX *)ctx[0]; | ||
427 | c_ctx=(SSL_CTX *)ctx[1]; | ||
428 | |||
429 | if (ctx[2] != NULL) | ||
430 | s_ssl=(SSL *)ctx[2]; | ||
431 | else | ||
432 | s_ssl=SSL_new(s_ctx); | ||
433 | |||
434 | if (ctx[3] != NULL) | ||
435 | c_ssl=(SSL *)ctx[3]; | ||
436 | else | ||
437 | c_ssl=SSL_new(c_ctx); | ||
438 | |||
439 | if ((s_ssl == NULL) || (c_ssl == NULL)) goto err; | ||
440 | |||
441 | c_to_s=BIO_new(BIO_s_mem()); | ||
442 | s_to_c=BIO_new(BIO_s_mem()); | ||
443 | if ((s_to_c == NULL) || (c_to_s == NULL)) goto err; | ||
444 | |||
445 | c_bio=BIO_new(BIO_f_ssl()); | ||
446 | s_bio=BIO_new(BIO_f_ssl()); | ||
447 | if ((c_bio == NULL) || (s_bio == NULL)) goto err; | ||
448 | |||
449 | SSL_set_connect_state(c_ssl); | ||
450 | SSL_set_bio(c_ssl,s_to_c,c_to_s); | ||
451 | BIO_set_ssl(c_bio,c_ssl,(ctx[2] == NULL)?BIO_CLOSE:BIO_NOCLOSE); | ||
452 | |||
453 | SSL_set_accept_state(s_ssl); | ||
454 | SSL_set_bio(s_ssl,c_to_s,s_to_c); | ||
455 | BIO_set_ssl(s_bio,s_ssl,(ctx[3] == NULL)?BIO_CLOSE:BIO_NOCLOSE); | ||
456 | |||
457 | c_r=0; s_r=1; | ||
458 | c_w=1; s_w=0; | ||
459 | c_want=W_WRITE; | ||
460 | s_want=0; | ||
461 | c_write=1,s_write=0; | ||
462 | |||
463 | /* We can always do writes */ | ||
464 | for (;;) | ||
465 | { | ||
466 | do_server=0; | ||
467 | do_client=0; | ||
468 | |||
469 | i=(int)BIO_pending(s_bio); | ||
470 | if ((i && s_r) || s_w) do_server=1; | ||
471 | |||
472 | i=(int)BIO_pending(c_bio); | ||
473 | if ((i && c_r) || c_w) do_client=1; | ||
474 | |||
475 | if (do_server && verbose) | ||
476 | { | ||
477 | if (SSL_in_init(s_ssl)) | ||
478 | printf("server waiting in SSL_accept - %s\n", | ||
479 | SSL_state_string_long(s_ssl)); | ||
480 | else if (s_write) | ||
481 | printf("server:SSL_write()\n"); | ||
482 | else | ||
483 | printf("server:SSL_read()\n"); | ||
484 | } | ||
485 | |||
486 | if (do_client && verbose) | ||
487 | { | ||
488 | if (SSL_in_init(c_ssl)) | ||
489 | printf("client waiting in SSL_connect - %s\n", | ||
490 | SSL_state_string_long(c_ssl)); | ||
491 | else if (c_write) | ||
492 | printf("client:SSL_write()\n"); | ||
493 | else | ||
494 | printf("client:SSL_read()\n"); | ||
495 | } | ||
496 | |||
497 | if (!do_client && !do_server) | ||
498 | { | ||
499 | fprintf(stdout,"ERROR IN STARTUP\n"); | ||
500 | break; | ||
501 | } | ||
502 | if (do_client && !(done & C_DONE)) | ||
503 | { | ||
504 | if (c_write) | ||
505 | { | ||
506 | i=BIO_write(c_bio,"hello from client\n",18); | ||
507 | if (i < 0) | ||
508 | { | ||
509 | c_r=0; | ||
510 | c_w=0; | ||
511 | if (BIO_should_retry(c_bio)) | ||
512 | { | ||
513 | if (BIO_should_read(c_bio)) | ||
514 | c_r=1; | ||
515 | if (BIO_should_write(c_bio)) | ||
516 | c_w=1; | ||
517 | } | ||
518 | else | ||
519 | { | ||
520 | fprintf(stderr,"ERROR in CLIENT\n"); | ||
521 | return(1); | ||
522 | } | ||
523 | } | ||
524 | else if (i == 0) | ||
525 | { | ||
526 | fprintf(stderr,"SSL CLIENT STARTUP FAILED\n"); | ||
527 | return(1); | ||
528 | } | ||
529 | else | ||
530 | { | ||
531 | /* ok */ | ||
532 | c_write=0; | ||
533 | } | ||
534 | } | ||
535 | else | ||
536 | { | ||
537 | i=BIO_read(c_bio,cbuf,100); | ||
538 | if (i < 0) | ||
539 | { | ||
540 | c_r=0; | ||
541 | c_w=0; | ||
542 | if (BIO_should_retry(c_bio)) | ||
543 | { | ||
544 | if (BIO_should_read(c_bio)) | ||
545 | c_r=1; | ||
546 | if (BIO_should_write(c_bio)) | ||
547 | c_w=1; | ||
548 | } | ||
549 | else | ||
550 | { | ||
551 | fprintf(stderr,"ERROR in CLIENT\n"); | ||
552 | return(1); | ||
553 | } | ||
554 | } | ||
555 | else if (i == 0) | ||
556 | { | ||
557 | fprintf(stderr,"SSL CLIENT STARTUP FAILED\n"); | ||
558 | return(1); | ||
559 | } | ||
560 | else | ||
561 | { | ||
562 | done|=C_DONE; | ||
563 | #ifdef undef | ||
564 | fprintf(stdout,"CLIENT:from server:"); | ||
565 | fwrite(cbuf,1,i,stdout); | ||
566 | fflush(stdout); | ||
567 | #endif | ||
568 | } | ||
569 | } | ||
570 | } | ||
571 | |||
572 | if (do_server && !(done & S_DONE)) | ||
573 | { | ||
574 | if (!s_write) | ||
575 | { | ||
576 | i=BIO_read(s_bio,sbuf,100); | ||
577 | if (i < 0) | ||
578 | { | ||
579 | s_r=0; | ||
580 | s_w=0; | ||
581 | if (BIO_should_retry(s_bio)) | ||
582 | { | ||
583 | if (BIO_should_read(s_bio)) | ||
584 | s_r=1; | ||
585 | if (BIO_should_write(s_bio)) | ||
586 | s_w=1; | ||
587 | } | ||
588 | else | ||
589 | { | ||
590 | fprintf(stderr,"ERROR in SERVER\n"); | ||
591 | ERR_print_errors_fp(stderr); | ||
592 | return(1); | ||
593 | } | ||
594 | } | ||
595 | else if (i == 0) | ||
596 | { | ||
597 | fprintf(stderr,"SSL SERVER STARTUP FAILED\n"); | ||
598 | return(1); | ||
599 | } | ||
600 | else | ||
601 | { | ||
602 | s_write=1; | ||
603 | s_w=1; | ||
604 | #ifdef undef | ||
605 | fprintf(stdout,"SERVER:from client:"); | ||
606 | fwrite(sbuf,1,i,stdout); | ||
607 | fflush(stdout); | ||
608 | #endif | ||
609 | } | ||
610 | } | ||
611 | else | ||
612 | { | ||
613 | i=BIO_write(s_bio,"hello from server\n",18); | ||
614 | if (i < 0) | ||
615 | { | ||
616 | s_r=0; | ||
617 | s_w=0; | ||
618 | if (BIO_should_retry(s_bio)) | ||
619 | { | ||
620 | if (BIO_should_read(s_bio)) | ||
621 | s_r=1; | ||
622 | if (BIO_should_write(s_bio)) | ||
623 | s_w=1; | ||
624 | } | ||
625 | else | ||
626 | { | ||
627 | fprintf(stderr,"ERROR in SERVER\n"); | ||
628 | ERR_print_errors_fp(stderr); | ||
629 | return(1); | ||
630 | } | ||
631 | } | ||
632 | else if (i == 0) | ||
633 | { | ||
634 | fprintf(stderr,"SSL SERVER STARTUP FAILED\n"); | ||
635 | return(1); | ||
636 | } | ||
637 | else | ||
638 | { | ||
639 | s_write=0; | ||
640 | s_r=1; | ||
641 | done|=S_DONE; | ||
642 | } | ||
643 | } | ||
644 | } | ||
645 | |||
646 | if ((done & S_DONE) && (done & C_DONE)) break; | ||
647 | } | ||
648 | |||
649 | SSL_set_shutdown(c_ssl,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); | ||
650 | SSL_set_shutdown(s_ssl,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); | ||
651 | |||
652 | #ifdef undef | ||
653 | fprintf(stdout,"DONE\n"); | ||
654 | #endif | ||
655 | err: | ||
656 | /* We have to set the BIO's to NULL otherwise they will be | ||
657 | * free()ed twice. Once when th s_ssl is SSL_free()ed and | ||
658 | * again when c_ssl is SSL_free()ed. | ||
659 | * This is a hack required because s_ssl and c_ssl are sharing the same | ||
660 | * BIO structure and SSL_set_bio() and SSL_free() automatically | ||
661 | * BIO_free non NULL entries. | ||
662 | * You should not normally do this or be required to do this */ | ||
663 | |||
664 | if (s_ssl != NULL) | ||
665 | { | ||
666 | s_ssl->rbio=NULL; | ||
667 | s_ssl->wbio=NULL; | ||
668 | } | ||
669 | if (c_ssl != NULL) | ||
670 | { | ||
671 | c_ssl->rbio=NULL; | ||
672 | c_ssl->wbio=NULL; | ||
673 | } | ||
674 | |||
675 | /* The SSL's are optionally freed in the following calls */ | ||
676 | if (c_to_s != NULL) BIO_free(c_to_s); | ||
677 | if (s_to_c != NULL) BIO_free(s_to_c); | ||
678 | |||
679 | if (c_bio != NULL) BIO_free(c_bio); | ||
680 | if (s_bio != NULL) BIO_free(s_bio); | ||
681 | return(0); | ||
682 | } | ||
683 | |||
684 | int MS_CALLBACK verify_callback(ok, xs, xi, depth, error, arg) | ||
685 | int ok; | ||
686 | X509 *xs; | ||
687 | X509 *xi; | ||
688 | int depth; | ||
689 | int error; | ||
690 | char *arg; | ||
691 | { | ||
692 | char buf[256]; | ||
693 | |||
694 | if (verbose) | ||
695 | { | ||
696 | X509_NAME_oneline(X509_get_subject_name(xs),buf,256); | ||
697 | if (ok) | ||
698 | fprintf(stderr,"depth=%d %s\n",depth,buf); | ||
699 | else | ||
700 | fprintf(stderr,"depth=%d error=%d %s\n",depth,error,buf); | ||
701 | } | ||
702 | return(ok); | ||
703 | } | ||
704 | |||
705 | #define THREAD_STACK_SIZE (16*1024) | ||
706 | |||
707 | #ifdef WIN32 | ||
708 | |||
709 | static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; | ||
710 | |||
711 | void thread_setup() | ||
712 | { | ||
713 | int i; | ||
714 | |||
715 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
716 | { | ||
717 | lock_cs[i]=CreateMutex(NULL,FALSE,NULL); | ||
718 | } | ||
719 | |||
720 | CRYPTO_set_locking_callback((void (*)(int,int,char *,int))win32_locking_callback); | ||
721 | /* id callback defined */ | ||
722 | } | ||
723 | |||
724 | void thread_cleanup() | ||
725 | { | ||
726 | int i; | ||
727 | |||
728 | CRYPTO_set_locking_callback(NULL); | ||
729 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
730 | CloseHandle(lock_cs[i]); | ||
731 | } | ||
732 | |||
733 | void win32_locking_callback(mode,type,file,line) | ||
734 | int mode; | ||
735 | int type; | ||
736 | char *file; | ||
737 | int line; | ||
738 | { | ||
739 | if (mode & CRYPTO_LOCK) | ||
740 | { | ||
741 | WaitForSingleObject(lock_cs[type],INFINITE); | ||
742 | } | ||
743 | else | ||
744 | { | ||
745 | ReleaseMutex(lock_cs[type]); | ||
746 | } | ||
747 | } | ||
748 | |||
749 | void do_threads(s_ctx,c_ctx) | ||
750 | SSL_CTX *s_ctx,*c_ctx; | ||
751 | { | ||
752 | double ret; | ||
753 | SSL_CTX *ssl_ctx[2]; | ||
754 | DWORD thread_id[MAX_THREAD_NUMBER]; | ||
755 | HANDLE thread_handle[MAX_THREAD_NUMBER]; | ||
756 | int i; | ||
757 | SYSTEMTIME start,end; | ||
758 | |||
759 | ssl_ctx[0]=s_ctx; | ||
760 | ssl_ctx[1]=c_ctx; | ||
761 | |||
762 | GetSystemTime(&start); | ||
763 | for (i=0; i<thread_number; i++) | ||
764 | { | ||
765 | thread_handle[i]=CreateThread(NULL, | ||
766 | THREAD_STACK_SIZE, | ||
767 | (LPTHREAD_START_ROUTINE)ndoit, | ||
768 | (void *)ssl_ctx, | ||
769 | 0L, | ||
770 | &(thread_id[i])); | ||
771 | } | ||
772 | |||
773 | printf("reaping\n"); | ||
774 | for (i=0; i<thread_number; i+=50) | ||
775 | { | ||
776 | int j; | ||
777 | |||
778 | j=(thread_number < (i+50))?(thread_number-i):50; | ||
779 | |||
780 | if (WaitForMultipleObjects(j, | ||
781 | (CONST HANDLE *)&(thread_handle[i]),TRUE,INFINITE) | ||
782 | == WAIT_FAILED) | ||
783 | { | ||
784 | fprintf(stderr,"WaitForMultipleObjects failed:%d\n",GetLastError()); | ||
785 | exit(1); | ||
786 | } | ||
787 | } | ||
788 | GetSystemTime(&end); | ||
789 | |||
790 | if (start.wDayOfWeek > end.wDayOfWeek) end.wDayOfWeek+=7; | ||
791 | ret=(end.wDayOfWeek-start.wDayOfWeek)*24; | ||
792 | |||
793 | ret=(ret+end.wHour-start.wHour)*60; | ||
794 | ret=(ret+end.wMinute-start.wMinute)*60; | ||
795 | ret=(ret+end.wSecond-start.wSecond); | ||
796 | ret+=(end.wMilliseconds-start.wMilliseconds)/1000.0; | ||
797 | |||
798 | printf("win32 threads done - %.3f seconds\n",ret); | ||
799 | } | ||
800 | |||
801 | #endif /* WIN32 */ | ||
802 | |||
803 | #ifdef SOLARIS | ||
804 | |||
805 | static mutex_t lock_cs[CRYPTO_NUM_LOCKS]; | ||
806 | /*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */ | ||
807 | static long lock_count[CRYPTO_NUM_LOCKS]; | ||
808 | |||
809 | void thread_setup() | ||
810 | { | ||
811 | int i; | ||
812 | |||
813 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
814 | { | ||
815 | lock_count[i]=0; | ||
816 | /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */ | ||
817 | mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL); | ||
818 | } | ||
819 | |||
820 | CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id); | ||
821 | CRYPTO_set_locking_callback((void (*)())solaris_locking_callback); | ||
822 | } | ||
823 | |||
824 | void thread_cleanup() | ||
825 | { | ||
826 | int i; | ||
827 | |||
828 | CRYPTO_set_locking_callback(NULL); | ||
829 | fprintf(stderr,"cleanup\n"); | ||
830 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
831 | { | ||
832 | /* rwlock_destroy(&(lock_cs[i])); */ | ||
833 | mutex_destroy(&(lock_cs[i])); | ||
834 | fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i)); | ||
835 | } | ||
836 | fprintf(stderr,"done cleanup\n"); | ||
837 | } | ||
838 | |||
839 | void solaris_locking_callback(mode,type,file,line) | ||
840 | int mode; | ||
841 | int type; | ||
842 | char *file; | ||
843 | int line; | ||
844 | { | ||
845 | #ifdef undef | ||
846 | fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", | ||
847 | CRYPTO_thread_id(), | ||
848 | (mode&CRYPTO_LOCK)?"l":"u", | ||
849 | (type&CRYPTO_READ)?"r":"w",file,line); | ||
850 | #endif | ||
851 | |||
852 | /* | ||
853 | if (CRYPTO_LOCK_SSL_CERT == type) | ||
854 | fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", | ||
855 | CRYPTO_thread_id(), | ||
856 | mode,file,line); | ||
857 | */ | ||
858 | if (mode & CRYPTO_LOCK) | ||
859 | { | ||
860 | /* if (mode & CRYPTO_READ) | ||
861 | rw_rdlock(&(lock_cs[type])); | ||
862 | else | ||
863 | rw_wrlock(&(lock_cs[type])); */ | ||
864 | |||
865 | mutex_lock(&(lock_cs[type])); | ||
866 | lock_count[type]++; | ||
867 | } | ||
868 | else | ||
869 | { | ||
870 | /* rw_unlock(&(lock_cs[type])); */ | ||
871 | mutex_unlock(&(lock_cs[type])); | ||
872 | } | ||
873 | } | ||
874 | |||
875 | void do_threads(s_ctx,c_ctx) | ||
876 | SSL_CTX *s_ctx,*c_ctx; | ||
877 | { | ||
878 | SSL_CTX *ssl_ctx[2]; | ||
879 | thread_t thread_ctx[MAX_THREAD_NUMBER]; | ||
880 | int i; | ||
881 | |||
882 | ssl_ctx[0]=s_ctx; | ||
883 | ssl_ctx[1]=c_ctx; | ||
884 | |||
885 | thr_setconcurrency(thread_number); | ||
886 | for (i=0; i<thread_number; i++) | ||
887 | { | ||
888 | thr_create(NULL, THREAD_STACK_SIZE, | ||
889 | (void *(*)())ndoit, | ||
890 | (void *)ssl_ctx, | ||
891 | 0L, | ||
892 | &(thread_ctx[i])); | ||
893 | } | ||
894 | |||
895 | printf("reaping\n"); | ||
896 | for (i=0; i<thread_number; i++) | ||
897 | { | ||
898 | thr_join(thread_ctx[i],NULL,NULL); | ||
899 | } | ||
900 | |||
901 | printf("solaris threads done (%d,%d)\n", | ||
902 | s_ctx->references,c_ctx->references); | ||
903 | } | ||
904 | |||
905 | unsigned long solaris_thread_id() | ||
906 | { | ||
907 | unsigned long ret; | ||
908 | |||
909 | ret=(unsigned long)thr_self(); | ||
910 | return(ret); | ||
911 | } | ||
912 | #endif /* SOLARIS */ | ||
913 | |||
914 | #ifdef IRIX | ||
915 | |||
916 | |||
917 | static usptr_t *arena; | ||
918 | static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; | ||
919 | |||
920 | void thread_setup() | ||
921 | { | ||
922 | int i; | ||
923 | char filename[20]; | ||
924 | |||
925 | strcpy(filename,"/tmp/mttest.XXXXXX"); | ||
926 | mktemp(filename); | ||
927 | |||
928 | usconfig(CONF_STHREADIOOFF); | ||
929 | usconfig(CONF_STHREADMALLOCOFF); | ||
930 | usconfig(CONF_INITUSERS,100); | ||
931 | usconfig(CONF_LOCKTYPE,US_DEBUGPLUS); | ||
932 | arena=usinit(filename); | ||
933 | unlink(filename); | ||
934 | |||
935 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
936 | { | ||
937 | lock_cs[i]=usnewsema(arena,1); | ||
938 | } | ||
939 | |||
940 | CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id); | ||
941 | CRYPTO_set_locking_callback((void (*)())irix_locking_callback); | ||
942 | } | ||
943 | |||
944 | void thread_cleanup() | ||
945 | { | ||
946 | int i; | ||
947 | |||
948 | CRYPTO_set_locking_callback(NULL); | ||
949 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
950 | { | ||
951 | char buf[10]; | ||
952 | |||
953 | sprintf(buf,"%2d:",i); | ||
954 | usdumpsema(lock_cs[i],stdout,buf); | ||
955 | usfreesema(lock_cs[i],arena); | ||
956 | } | ||
957 | } | ||
958 | |||
959 | void irix_locking_callback(mode,type,file,line) | ||
960 | int mode; | ||
961 | int type; | ||
962 | char *file; | ||
963 | int line; | ||
964 | { | ||
965 | if (mode & CRYPTO_LOCK) | ||
966 | { | ||
967 | printf("lock %d\n",type); | ||
968 | uspsema(lock_cs[type]); | ||
969 | } | ||
970 | else | ||
971 | { | ||
972 | printf("unlock %d\n",type); | ||
973 | usvsema(lock_cs[type]); | ||
974 | } | ||
975 | } | ||
976 | |||
977 | void do_threads(s_ctx,c_ctx) | ||
978 | SSL_CTX *s_ctx,*c_ctx; | ||
979 | { | ||
980 | SSL_CTX *ssl_ctx[2]; | ||
981 | int thread_ctx[MAX_THREAD_NUMBER]; | ||
982 | int i; | ||
983 | |||
984 | ssl_ctx[0]=s_ctx; | ||
985 | ssl_ctx[1]=c_ctx; | ||
986 | |||
987 | for (i=0; i<thread_number; i++) | ||
988 | { | ||
989 | thread_ctx[i]=sproc((void (*)())ndoit, | ||
990 | PR_SADDR|PR_SFDS,(void *)ssl_ctx); | ||
991 | } | ||
992 | |||
993 | printf("reaping\n"); | ||
994 | for (i=0; i<thread_number; i++) | ||
995 | { | ||
996 | wait(NULL); | ||
997 | } | ||
998 | |||
999 | printf("irix threads done (%d,%d)\n", | ||
1000 | s_ctx->references,c_ctx->references); | ||
1001 | } | ||
1002 | |||
1003 | unsigned long irix_thread_id() | ||
1004 | { | ||
1005 | unsigned long ret; | ||
1006 | |||
1007 | ret=(unsigned long)getpid(); | ||
1008 | return(ret); | ||
1009 | } | ||
1010 | #endif /* IRIX */ | ||
1011 | |||
1012 | #ifdef PTHREADS | ||
1013 | |||
1014 | static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; | ||
1015 | static long lock_count[CRYPTO_NUM_LOCKS]; | ||
1016 | |||
1017 | void thread_setup() | ||
1018 | { | ||
1019 | int i; | ||
1020 | |||
1021 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
1022 | { | ||
1023 | lock_count[i]=0; | ||
1024 | pthread_mutex_init(&(lock_cs[i]),NULL); | ||
1025 | } | ||
1026 | |||
1027 | CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id); | ||
1028 | CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback); | ||
1029 | } | ||
1030 | |||
1031 | void thread_cleanup() | ||
1032 | { | ||
1033 | int i; | ||
1034 | |||
1035 | CRYPTO_set_locking_callback(NULL); | ||
1036 | fprintf(stderr,"cleanup\n"); | ||
1037 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
1038 | { | ||
1039 | pthread_mutex_destroy(&(lock_cs[i])); | ||
1040 | fprintf(stderr,"%8ld:%s\n",lock_count[i], | ||
1041 | CRYPTO_get_lock_name(i)); | ||
1042 | } | ||
1043 | fprintf(stderr,"done cleanup\n"); | ||
1044 | } | ||
1045 | |||
1046 | void pthreads_locking_callback(mode,type,file,line) | ||
1047 | int mode; | ||
1048 | int type; | ||
1049 | char *file; | ||
1050 | int line; | ||
1051 | { | ||
1052 | #ifdef undef | ||
1053 | fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", | ||
1054 | CRYPTO_thread_id(), | ||
1055 | (mode&CRYPTO_LOCK)?"l":"u", | ||
1056 | (type&CRYPTO_READ)?"r":"w",file,line); | ||
1057 | #endif | ||
1058 | /* | ||
1059 | if (CRYPTO_LOCK_SSL_CERT == type) | ||
1060 | fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", | ||
1061 | CRYPTO_thread_id(), | ||
1062 | mode,file,line); | ||
1063 | */ | ||
1064 | if (mode & CRYPTO_LOCK) | ||
1065 | { | ||
1066 | pthread_mutex_lock(&(lock_cs[type])); | ||
1067 | lock_count[type]++; | ||
1068 | } | ||
1069 | else | ||
1070 | { | ||
1071 | pthread_mutex_unlock(&(lock_cs[type])); | ||
1072 | } | ||
1073 | } | ||
1074 | |||
1075 | void do_threads(s_ctx,c_ctx) | ||
1076 | SSL_CTX *s_ctx,*c_ctx; | ||
1077 | { | ||
1078 | SSL_CTX *ssl_ctx[2]; | ||
1079 | pthread_t thread_ctx[MAX_THREAD_NUMBER]; | ||
1080 | int i; | ||
1081 | |||
1082 | ssl_ctx[0]=s_ctx; | ||
1083 | ssl_ctx[1]=c_ctx; | ||
1084 | |||
1085 | /* | ||
1086 | thr_setconcurrency(thread_number); | ||
1087 | */ | ||
1088 | for (i=0; i<thread_number; i++) | ||
1089 | { | ||
1090 | pthread_create(&(thread_ctx[i]), NULL, | ||
1091 | (void *(*)())ndoit, (void *)ssl_ctx); | ||
1092 | } | ||
1093 | |||
1094 | printf("reaping\n"); | ||
1095 | for (i=0; i<thread_number; i++) | ||
1096 | { | ||
1097 | pthread_join(thread_ctx[i],NULL); | ||
1098 | } | ||
1099 | |||
1100 | printf("pthreads threads done (%d,%d)\n", | ||
1101 | s_ctx->references,c_ctx->references); | ||
1102 | } | ||
1103 | |||
1104 | unsigned long pthreads_thread_id() | ||
1105 | { | ||
1106 | unsigned long ret; | ||
1107 | |||
1108 | ret=(unsigned long)pthread_self(); | ||
1109 | return(ret); | ||
1110 | } | ||
1111 | |||
1112 | #endif /* PTHREADS */ | ||
1113 | |||
1114 | |||
1115 | |||
diff --git a/src/lib/libcrypto/threads/th-lock.c b/src/lib/libcrypto/threads/th-lock.c new file mode 100644 index 0000000000..039022446d --- /dev/null +++ b/src/lib/libcrypto/threads/th-lock.c | |||
@@ -0,0 +1,399 @@ | |||
1 | /* crypto/threads/th-lock.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 <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #include <errno.h> | ||
63 | #ifdef LINUX | ||
64 | #include <typedefs.h> | ||
65 | #endif | ||
66 | #ifdef WIN32 | ||
67 | #include <windows.h> | ||
68 | #endif | ||
69 | #ifdef SOLARIS | ||
70 | #include <synch.h> | ||
71 | #include <thread.h> | ||
72 | #endif | ||
73 | #ifdef IRIX | ||
74 | #include <ulocks.h> | ||
75 | #include <sys/prctl.h> | ||
76 | #endif | ||
77 | #include "lhash.h" | ||
78 | #include "crypto.h" | ||
79 | #include "buffer.h" | ||
80 | #include "e_os.h" | ||
81 | #include "x509.h" | ||
82 | #include "ssl.h" | ||
83 | #include "err.h" | ||
84 | |||
85 | #ifndef NOPROTO | ||
86 | int CRYPTO_thread_setup(void); | ||
87 | void CRYPTO_thread_cleanup(void); | ||
88 | |||
89 | static void irix_locking_callback(int mode,int type,char *file,int line); | ||
90 | static void solaris_locking_callback(int mode,int type,char *file,int line); | ||
91 | static void win32_locking_callback(int mode,int type,char *file,int line); | ||
92 | static void pthreads_locking_callback(int mode,int type,char *file,int line); | ||
93 | |||
94 | static unsigned long irix_thread_id(void ); | ||
95 | static unsigned long solaris_thread_id(void ); | ||
96 | static unsigned long pthreads_thread_id(void ); | ||
97 | |||
98 | #else | ||
99 | int CRYPOTO_thread_setup(); | ||
100 | void CRYPTO_cleanup(); | ||
101 | |||
102 | static void irix_locking_callback(); | ||
103 | static void solaris_locking_callback(); | ||
104 | static void win32_locking_callback(); | ||
105 | static void pthreads_locking_callback(); | ||
106 | |||
107 | static unsigned long irix_thread_id(); | ||
108 | static unsigned long solaris_thread_id(); | ||
109 | static unsigned long pthreads_thread_id(); | ||
110 | |||
111 | #endif | ||
112 | |||
113 | /* usage: | ||
114 | * CRYPTO_thread_setup(); | ||
115 | * applicaion code | ||
116 | * CRYPTO_thread_cleanup(); | ||
117 | */ | ||
118 | |||
119 | #define THREAD_STACK_SIZE (16*1024) | ||
120 | |||
121 | #ifdef WIN32 | ||
122 | |||
123 | static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; | ||
124 | |||
125 | int CRYPTO_thread_setup() | ||
126 | { | ||
127 | int i; | ||
128 | |||
129 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
130 | { | ||
131 | lock_cs[i]=CreateMutex(NULL,FALSE,NULL); | ||
132 | } | ||
133 | |||
134 | CRYPTO_set_locking_callback((void (*)(int,int,char *,int))win32_locking_callback); | ||
135 | /* id callback defined */ | ||
136 | return(1); | ||
137 | } | ||
138 | |||
139 | static void CRYPTO_thread_cleanup() | ||
140 | { | ||
141 | int i; | ||
142 | |||
143 | CRYPTO_set_locking_callback(NULL); | ||
144 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
145 | CloseHandle(lock_cs[i]); | ||
146 | } | ||
147 | |||
148 | void win32_locking_callback(mode,type,file,line) | ||
149 | int mode; | ||
150 | int type; | ||
151 | char *file; | ||
152 | int line; | ||
153 | { | ||
154 | if (mode & CRYPTO_LOCK) | ||
155 | { | ||
156 | WaitForSingleObject(lock_cs[type],INFINITE); | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | ReleaseMutex(lock_cs[type]); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | #endif /* WIN32 */ | ||
165 | |||
166 | #ifdef SOLARIS | ||
167 | |||
168 | #define USE_MUTEX | ||
169 | |||
170 | static mutex_t lock_cs[CRYPTO_NUM_LOCKS]; | ||
171 | #ifdef USE_MUTEX | ||
172 | static long lock_count[CRYPTO_NUM_LOCKS]; | ||
173 | #else | ||
174 | static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; | ||
175 | #endif | ||
176 | |||
177 | void CRYPTO_thread_setup() | ||
178 | { | ||
179 | int i; | ||
180 | |||
181 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
182 | { | ||
183 | lock_count[i]=0; | ||
184 | #ifdef USE_MUTEX | ||
185 | mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL); | ||
186 | #else | ||
187 | rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); | ||
188 | #endif | ||
189 | } | ||
190 | |||
191 | CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id); | ||
192 | CRYPTO_set_locking_callback((void (*)())solaris_locking_callback); | ||
193 | } | ||
194 | |||
195 | void CRYPTO_thread_cleanup() | ||
196 | { | ||
197 | int i; | ||
198 | |||
199 | CRYPTO_set_locking_callback(NULL); | ||
200 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
201 | { | ||
202 | #ifdef USE_MUTEX | ||
203 | mutex_destroy(&(lock_cs[i])); | ||
204 | #else | ||
205 | rwlock_destroy(&(lock_cs[i])); | ||
206 | #endif | ||
207 | } | ||
208 | } | ||
209 | |||
210 | void solaris_locking_callback(mode,type,file,line) | ||
211 | int mode; | ||
212 | int type; | ||
213 | char *file; | ||
214 | int line; | ||
215 | { | ||
216 | #if 0 | ||
217 | fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", | ||
218 | CRYPTO_thread_id(), | ||
219 | (mode&CRYPTO_LOCK)?"l":"u", | ||
220 | (type&CRYPTO_READ)?"r":"w",file,line); | ||
221 | #endif | ||
222 | |||
223 | #if 0 | ||
224 | if (CRYPTO_LOCK_SSL_CERT == type) | ||
225 | fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", | ||
226 | CRYPTO_thread_id(), | ||
227 | mode,file,line); | ||
228 | #endif | ||
229 | if (mode & CRYPTO_LOCK) | ||
230 | { | ||
231 | #ifdef USE_MUTEX | ||
232 | mutex_lock(&(lock_cs[type])); | ||
233 | #else | ||
234 | if (mode & CRYPTO_READ) | ||
235 | rw_rdlock(&(lock_cs[type])); | ||
236 | else | ||
237 | rw_wrlock(&(lock_cs[type])); | ||
238 | #endif | ||
239 | lock_count[type]++; | ||
240 | } | ||
241 | else | ||
242 | { | ||
243 | #ifdef USE_MUTEX | ||
244 | mutex_unlock(&(lock_cs[type])); | ||
245 | #else | ||
246 | rw_unlock(&(lock_cs[type])); | ||
247 | #endif | ||
248 | } | ||
249 | } | ||
250 | |||
251 | unsigned long solaris_thread_id() | ||
252 | { | ||
253 | unsigned long ret; | ||
254 | |||
255 | ret=(unsigned long)thr_self(); | ||
256 | return(ret); | ||
257 | } | ||
258 | #endif /* SOLARIS */ | ||
259 | |||
260 | #ifdef IRIX | ||
261 | /* I don't think this works..... */ | ||
262 | |||
263 | static usptr_t *arena; | ||
264 | static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; | ||
265 | |||
266 | void CRYPTO_thread_setup() | ||
267 | { | ||
268 | int i; | ||
269 | char filename[20]; | ||
270 | |||
271 | strcpy(filename,"/tmp/mttest.XXXXXX"); | ||
272 | mktemp(filename); | ||
273 | |||
274 | usconfig(CONF_STHREADIOOFF); | ||
275 | usconfig(CONF_STHREADMALLOCOFF); | ||
276 | usconfig(CONF_INITUSERS,100); | ||
277 | usconfig(CONF_LOCKTYPE,US_DEBUGPLUS); | ||
278 | arena=usinit(filename); | ||
279 | unlink(filename); | ||
280 | |||
281 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
282 | { | ||
283 | lock_cs[i]=usnewsema(arena,1); | ||
284 | } | ||
285 | |||
286 | CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id); | ||
287 | CRYPTO_set_locking_callback((void (*)())irix_locking_callback); | ||
288 | } | ||
289 | |||
290 | void CRYPTO_thread_cleanup() | ||
291 | { | ||
292 | int i; | ||
293 | |||
294 | CRYPTO_set_locking_callback(NULL); | ||
295 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
296 | { | ||
297 | char buf[10]; | ||
298 | |||
299 | sprintf(buf,"%2d:",i); | ||
300 | usdumpsema(lock_cs[i],stdout,buf); | ||
301 | usfreesema(lock_cs[i],arena); | ||
302 | } | ||
303 | } | ||
304 | |||
305 | void irix_locking_callback(mode,type,file,line) | ||
306 | int mode; | ||
307 | int type; | ||
308 | char *file; | ||
309 | int line; | ||
310 | { | ||
311 | if (mode & CRYPTO_LOCK) | ||
312 | { | ||
313 | uspsema(lock_cs[type]); | ||
314 | } | ||
315 | else | ||
316 | { | ||
317 | usvsema(lock_cs[type]); | ||
318 | } | ||
319 | } | ||
320 | |||
321 | unsigned long irix_thread_id() | ||
322 | { | ||
323 | unsigned long ret; | ||
324 | |||
325 | ret=(unsigned long)getpid(); | ||
326 | return(ret); | ||
327 | } | ||
328 | #endif /* IRIX */ | ||
329 | |||
330 | /* Linux and a few others */ | ||
331 | #ifdef PTHREADS | ||
332 | |||
333 | static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; | ||
334 | static long lock_count[CRYPTO_NUM_LOCKS]; | ||
335 | |||
336 | void CRYPTO_thread_setup() | ||
337 | { | ||
338 | int i; | ||
339 | |||
340 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
341 | { | ||
342 | lock_count[i]=0; | ||
343 | pthread_mutex_init(&(lock_cs[i]),NULL); | ||
344 | } | ||
345 | |||
346 | CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id); | ||
347 | CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback); | ||
348 | } | ||
349 | |||
350 | void thread_cleanup() | ||
351 | { | ||
352 | int i; | ||
353 | |||
354 | CRYPTO_set_locking_callback(NULL); | ||
355 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | ||
356 | { | ||
357 | pthread_mutex_destroy(&(lock_cs[i])); | ||
358 | } | ||
359 | } | ||
360 | |||
361 | void pthreads_locking_callback(mode,type,file,line) | ||
362 | int mode; | ||
363 | int type; | ||
364 | char *file; | ||
365 | int line; | ||
366 | { | ||
367 | #if 0 | ||
368 | fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", | ||
369 | CRYPTO_thread_id(), | ||
370 | (mode&CRYPTO_LOCK)?"l":"u", | ||
371 | (type&CRYPTO_READ)?"r":"w",file,line); | ||
372 | #endif | ||
373 | #if 0 | ||
374 | if (CRYPTO_LOCK_SSL_CERT == type) | ||
375 | fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", | ||
376 | CRYPTO_thread_id(), | ||
377 | mode,file,line); | ||
378 | #endif | ||
379 | if (mode & CRYPTO_LOCK) | ||
380 | { | ||
381 | pthread_mutex_lock(&(lock_cs[type])); | ||
382 | lock_count[type]++; | ||
383 | } | ||
384 | else | ||
385 | { | ||
386 | pthread_mutex_unlock(&(lock_cs[type])); | ||
387 | } | ||
388 | } | ||
389 | |||
390 | unsigned long pthreads_thread_id() | ||
391 | { | ||
392 | unsigned long ret; | ||
393 | |||
394 | ret=(unsigned long)pthread_self(); | ||
395 | return(ret); | ||
396 | } | ||
397 | |||
398 | #endif /* PTHREADS */ | ||
399 | |||
diff --git a/src/lib/libcrypto/tmdiff.c b/src/lib/libcrypto/tmdiff.c new file mode 100644 index 0000000000..b93799fc03 --- /dev/null +++ b/src/lib/libcrypto/tmdiff.c | |||
@@ -0,0 +1,217 @@ | |||
1 | /* crypto/tmdiff.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 | #include <stdio.h> | ||
59 | #include <stdlib.h> | ||
60 | |||
61 | #ifndef MSDOS | ||
62 | # ifndef WIN32 | ||
63 | # define TIMES | ||
64 | # endif | ||
65 | #endif | ||
66 | |||
67 | #ifndef VMS | ||
68 | # ifndef _IRIX | ||
69 | # include <time.h> | ||
70 | # endif | ||
71 | # ifdef TIMES | ||
72 | # include <sys/types.h> | ||
73 | # include <sys/times.h> | ||
74 | # endif | ||
75 | #else /* VMS */ | ||
76 | # include <types.h> | ||
77 | struct tms { | ||
78 | time_t tms_utime; | ||
79 | time_t tms_stime; | ||
80 | time_t tms_uchild; /* I dunno... */ | ||
81 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
82 | } | ||
83 | #endif /* VMS */ | ||
84 | |||
85 | #ifdef sun | ||
86 | #include <limits.h> | ||
87 | #include <sys/param.h> | ||
88 | #endif | ||
89 | |||
90 | #ifndef TIMES | ||
91 | #include <sys/timeb.h> | ||
92 | #endif | ||
93 | |||
94 | #ifdef WIN32 | ||
95 | #include <windows.h> | ||
96 | #endif | ||
97 | |||
98 | /* The following if from times(3) man page. It may need to be changed */ | ||
99 | #ifndef HZ | ||
100 | # ifndef CLK_TCK | ||
101 | # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ | ||
102 | # ifndef VMS | ||
103 | # define HZ 100.0 | ||
104 | # else /* VMS */ | ||
105 | # define HZ 100.0 | ||
106 | # endif | ||
107 | # else /* _BSD_CLK_TCK_ */ | ||
108 | # define HZ ((double)_BSD_CLK_TCK_) | ||
109 | # endif | ||
110 | # else /* CLK_TCK */ | ||
111 | # define HZ ((double)CLK_TCK) | ||
112 | # endif | ||
113 | #endif | ||
114 | |||
115 | typedef struct ms_tm | ||
116 | { | ||
117 | #ifdef TIMES | ||
118 | struct tms ms_tms; | ||
119 | #else | ||
120 | # ifdef WIN32 | ||
121 | HANDLE thread_id; | ||
122 | FILETIME ms_win32; | ||
123 | # else | ||
124 | struct timeb ms_timeb; | ||
125 | # endif | ||
126 | #endif | ||
127 | } MS_TM; | ||
128 | |||
129 | char *ms_time_init() | ||
130 | { | ||
131 | MS_TM *ret; | ||
132 | |||
133 | ret=malloc(sizeof(MS_TM)); | ||
134 | if (ret == NULL) | ||
135 | return(NULL); | ||
136 | memset(ret,0,sizeof(MS_TM)); | ||
137 | #ifdef WIN32 | ||
138 | ret->thread_id=GetCurrentThread(); | ||
139 | #endif | ||
140 | return((char *)ret); | ||
141 | } | ||
142 | |||
143 | void ms_time_final(a) | ||
144 | char *a; | ||
145 | { | ||
146 | if (a != NULL) | ||
147 | free(a); | ||
148 | } | ||
149 | |||
150 | void ms_time_get(a) | ||
151 | char *a; | ||
152 | { | ||
153 | MS_TM *tm=(MS_TM *)a; | ||
154 | FILETIME tmpa,tmpb,tmpc; | ||
155 | |||
156 | #ifdef TIMES | ||
157 | printf("AAA\n"); | ||
158 | times(&tm->ms_tms); | ||
159 | #else | ||
160 | # ifdef WIN32 | ||
161 | GetThreadTimes(tm->thread_id,&tmpa,&tmpb,&tmpc,&(tm->ms_win32)); | ||
162 | # else | ||
163 | printf("CCC\n"); | ||
164 | ftime(tm->ms_timeb); | ||
165 | # endif | ||
166 | #endif | ||
167 | } | ||
168 | |||
169 | double ms_time_diff(ap,bp) | ||
170 | char *ap,*bp; | ||
171 | { | ||
172 | MS_TM *a=(MS_TM *)ap; | ||
173 | MS_TM *b=(MS_TM *)bp; | ||
174 | double ret; | ||
175 | |||
176 | #ifdef TIMES | ||
177 | ret=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ; | ||
178 | #else | ||
179 | # ifdef WIN32 | ||
180 | ret =(double)(b->ms_win32.dwHighDateTime&0x000fffff)*10+ | ||
181 | b->ms_win32.dwLowDateTime/1e7; | ||
182 | ret-=(double)(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7; | ||
183 | # else | ||
184 | ret= (double)(b->time-a->time)+ | ||
185 | ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0; | ||
186 | # endif | ||
187 | #endif | ||
188 | return((ret < 0.0000001)?0.0000001:ret); | ||
189 | } | ||
190 | |||
191 | int ms_time_cmp(ap,bp) | ||
192 | char *ap,*bp; | ||
193 | { | ||
194 | MS_TM *a=(MS_TM *)ap,*b=(MS_TM *)bp; | ||
195 | double d; | ||
196 | int ret; | ||
197 | |||
198 | #ifdef TIMES | ||
199 | d=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ; | ||
200 | #else | ||
201 | # ifdef WIN32 | ||
202 | d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7; | ||
203 | d-=(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7; | ||
204 | # else | ||
205 | d= (double)(b->time-a->time)+ | ||
206 | ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0; | ||
207 | # endif | ||
208 | #endif | ||
209 | if (d == 0.0) | ||
210 | ret=0; | ||
211 | else if (d < 0) | ||
212 | ret= -1; | ||
213 | else | ||
214 | ret=1; | ||
215 | return(ret); | ||
216 | } | ||
217 | |||
diff --git a/src/lib/libcrypto/util/FreeBSD.sh b/src/lib/libcrypto/util/FreeBSD.sh new file mode 100644 index 0000000000..db8edfc6aa --- /dev/null +++ b/src/lib/libcrypto/util/FreeBSD.sh | |||
@@ -0,0 +1,6 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | perl util/perlpath.pl /usr/bin | ||
4 | perl util/ssldir.pl /usr/local | ||
5 | perl util/mk1mf.pl FreeBSD >Makefile.FreeBSD | ||
6 | perl Configure FreeBSD | ||
diff --git a/src/lib/libcrypto/util/add_cr.pl b/src/lib/libcrypto/util/add_cr.pl new file mode 100644 index 0000000000..ddd6d61e2d --- /dev/null +++ b/src/lib/libcrypto/util/add_cr.pl | |||
@@ -0,0 +1,123 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # This adds a copyright message to a souce code file. | ||
4 | # It also gets the file name correct. | ||
5 | # | ||
6 | # perl util/add_cr.pl *.[ch] */*.[ch] */*/*.[ch] | ||
7 | # | ||
8 | |||
9 | foreach (@ARGV) | ||
10 | { | ||
11 | &dofile($_); | ||
12 | } | ||
13 | |||
14 | sub dofile | ||
15 | { | ||
16 | local($file)=@_; | ||
17 | |||
18 | open(IN,"<$file") || die "unable to open $file:$!\n"; | ||
19 | |||
20 | print STDERR "doing $file\n"; | ||
21 | @in=<IN>; | ||
22 | |||
23 | return(1) if ($in[0] =~ / NOCW /); | ||
24 | |||
25 | @out=(); | ||
26 | open(OUT,">$file.out") || die "unable to open $file.$$:$!\n"; | ||
27 | push(@out,"/* $file */\n"); | ||
28 | if (($in[1] !~ /^\/\* Copyright \(C\) [0-9-]+ Eric Young \(eay\@cryptsoft.com\)/)) | ||
29 | { | ||
30 | push(@out,&Copyright); | ||
31 | $i=2; | ||
32 | @a=grep(/ Copyright \(C\) /,@in); | ||
33 | if ($#a >= 0) | ||
34 | { | ||
35 | while (($i <= $#in) && ($in[$i] ne " */\n")) | ||
36 | { $i++; } | ||
37 | $i++ if ($in[$i] eq " */\n"); | ||
38 | |||
39 | while (($i <= $#in) && ($in[$i] =~ /^\s*$/)) | ||
40 | { $i++; } | ||
41 | |||
42 | push(@out,"\n"); | ||
43 | for ( ; $i <= $#in; $i++) | ||
44 | { push(@out,$in[$i]); } | ||
45 | } | ||
46 | else | ||
47 | { push(@out,@in); } | ||
48 | } | ||
49 | else | ||
50 | { | ||
51 | shift(@in); | ||
52 | push(@out,@in); | ||
53 | } | ||
54 | print OUT @out; | ||
55 | close(IN); | ||
56 | close(OUT); | ||
57 | rename("$file","$file.orig") || die "unable to rename $file:$!\n"; | ||
58 | rename("$file.out",$file) || die "unable to rename $file.out:$!\n"; | ||
59 | } | ||
60 | |||
61 | |||
62 | |||
63 | sub Copyright | ||
64 | { | ||
65 | return <<'EOF'; | ||
66 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
67 | * All rights reserved. | ||
68 | * | ||
69 | * This package is an SSL implementation written | ||
70 | * by Eric Young (eay@cryptsoft.com). | ||
71 | * The implementation was written so as to conform with Netscapes SSL. | ||
72 | * | ||
73 | * This library is free for commercial and non-commercial use as long as | ||
74 | * the following conditions are aheared to. The following conditions | ||
75 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
76 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
77 | * included with this distribution is covered by the same copyright terms | ||
78 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
79 | * | ||
80 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
81 | * the code are not to be removed. | ||
82 | * If this package is used in a product, Eric Young should be given attribution | ||
83 | * as the author of the parts of the library used. | ||
84 | * This can be in the form of a textual message at program startup or | ||
85 | * in documentation (online or textual) provided with the package. | ||
86 | * | ||
87 | * Redistribution and use in source and binary forms, with or without | ||
88 | * modification, are permitted provided that the following conditions | ||
89 | * are met: | ||
90 | * 1. Redistributions of source code must retain the copyright | ||
91 | * notice, this list of conditions and the following disclaimer. | ||
92 | * 2. Redistributions in binary form must reproduce the above copyright | ||
93 | * notice, this list of conditions and the following disclaimer in the | ||
94 | * documentation and/or other materials provided with the distribution. | ||
95 | * 3. All advertising materials mentioning features or use of this software | ||
96 | * must display the following acknowledgement: | ||
97 | * "This product includes cryptographic software written by | ||
98 | * Eric Young (eay@cryptsoft.com)" | ||
99 | * The word 'cryptographic' can be left out if the rouines from the library | ||
100 | * being used are not cryptographic related :-). | ||
101 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
102 | * the apps directory (application code) you must include an acknowledgement: | ||
103 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
104 | * | ||
105 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
106 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
107 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
108 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
109 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
110 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
111 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
112 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
113 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
114 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
115 | * SUCH DAMAGE. | ||
116 | * | ||
117 | * The licence and distribution terms for any publically available version or | ||
118 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
119 | * copied and put under another distribution licence | ||
120 | * [including the GNU Public Licence.] | ||
121 | */ | ||
122 | EOF | ||
123 | } | ||
diff --git a/src/lib/libcrypto/util/bat.sh b/src/lib/libcrypto/util/bat.sh new file mode 100644 index 0000000000..c6f48e8a7b --- /dev/null +++ b/src/lib/libcrypto/util/bat.sh | |||
@@ -0,0 +1,132 @@ | |||
1 | #!/usr/local/bin/perl | ||
2 | |||
3 | $infile="/home/eay/ssl/SSLeay/MINFO"; | ||
4 | |||
5 | open(IN,"<$infile") || die "unable to open $infile:$!\n"; | ||
6 | $_=<IN>; | ||
7 | for (;;) | ||
8 | { | ||
9 | chop; | ||
10 | |||
11 | ($key,$val)=/^([^=]+)=(.*)/; | ||
12 | if ($key eq "RELATIVE_DIRECTORY") | ||
13 | { | ||
14 | if ($lib ne "") | ||
15 | { | ||
16 | $uc=$lib; | ||
17 | $uc =~ s/^lib(.*)\.a/$1/; | ||
18 | $uc =~ tr/a-z/A-Z/; | ||
19 | $lib_nam{$uc}=$uc; | ||
20 | $lib_obj{$uc}.=$libobj." "; | ||
21 | } | ||
22 | last if ($val eq "FINISHED"); | ||
23 | $lib=""; | ||
24 | $libobj=""; | ||
25 | $dir=$val; | ||
26 | } | ||
27 | |||
28 | if ($key eq "TEST") | ||
29 | { $test.=&var_add($dir,$val); } | ||
30 | |||
31 | if (($key eq "PROGS") || ($key eq "E_OBJ")) | ||
32 | { $e_exe.=&var_add($dir,$val); } | ||
33 | |||
34 | if ($key eq "LIB") | ||
35 | { | ||
36 | $lib=$val; | ||
37 | $lib =~ s/^.*\/([^\/]+)$/$1/; | ||
38 | } | ||
39 | |||
40 | if ($key eq "EXHEADER") | ||
41 | { $exheader.=&var_add($dir,$val); } | ||
42 | |||
43 | if ($key eq "HEADER") | ||
44 | { $header.=&var_add($dir,$val); } | ||
45 | |||
46 | if ($key eq "LIBSRC") | ||
47 | { $libsrc.=&var_add($dir,$val); } | ||
48 | |||
49 | if (!($_=<IN>)) | ||
50 | { $_="RELATIVE_DIRECTORY=FINISHED\n"; } | ||
51 | } | ||
52 | close(IN); | ||
53 | |||
54 | @a=split(/\s+/,$libsrc); | ||
55 | foreach (@a) | ||
56 | { | ||
57 | print "${_}.c\n"; | ||
58 | } | ||
59 | |||
60 | sub var_add | ||
61 | { | ||
62 | local($dir,$val)=@_; | ||
63 | local(@a,$_,$ret); | ||
64 | |||
65 | return("") if $no_idea && $dir =~ /\/idea/; | ||
66 | return("") if $no_rc2 && $dir =~ /\/rc2/; | ||
67 | return("") if $no_rc4 && $dir =~ /\/rc4/; | ||
68 | return("") if $no_rsa && $dir =~ /\/rsa/; | ||
69 | return("") if $no_rsa && $dir =~ /^rsaref/; | ||
70 | return("") if $no_dsa && $dir =~ /\/dsa/; | ||
71 | return("") if $no_dh && $dir =~ /\/dh/; | ||
72 | if ($no_des && $dir =~ /\/des/) | ||
73 | { | ||
74 | if ($val =~ /read_pwd/) | ||
75 | { return("$dir/read_pwd "); } | ||
76 | else | ||
77 | { return(""); } | ||
78 | } | ||
79 | return("") if $no_mdc2 && $dir =~ /\/mdc2/; | ||
80 | return("") if $no_sock && $dir =~ /\/proxy/; | ||
81 | return("") if $no_bf && $dir =~ /\/bf/; | ||
82 | return("") if $no_cast && $dir =~ /\/cast/; | ||
83 | |||
84 | $val =~ s/^\s*(.*)\s*$/$1/; | ||
85 | @a=split(/\s+/,$val); | ||
86 | grep(s/\.[och]$//,@a); | ||
87 | |||
88 | @a=grep(!/^e_.*_3d$/,@a) if $no_des; | ||
89 | @a=grep(!/^e_.*_d$/,@a) if $no_des; | ||
90 | @a=grep(!/^e_.*_i$/,@a) if $no_idea; | ||
91 | @a=grep(!/^e_.*_r2$/,@a) if $no_rc2; | ||
92 | @a=grep(!/^e_.*_bf$/,@a) if $no_bf; | ||
93 | @a=grep(!/^e_.*_c$/,@a) if $no_cast; | ||
94 | @a=grep(!/^e_rc4$/,@a) if $no_rc4; | ||
95 | |||
96 | @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2; | ||
97 | @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3; | ||
98 | |||
99 | @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock; | ||
100 | |||
101 | @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2; | ||
102 | @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5; | ||
103 | |||
104 | @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa; | ||
105 | @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa; | ||
106 | @a=grep(!/(^pem_seal$)/,@a) if $no_rsa; | ||
107 | |||
108 | @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa; | ||
109 | @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa; | ||
110 | |||
111 | @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4; | ||
112 | |||
113 | @a=grep(!/_dhp$/,@a) if $no_dh; | ||
114 | |||
115 | @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha; | ||
116 | @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1; | ||
117 | @a=grep(!/_mdc2$/,@a) if $no_mdc2; | ||
118 | |||
119 | @a=grep(!/(^rsa$)|(^genrsa$)|(^req$)|(^ca$)/,@a) if $no_rsa; | ||
120 | @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa; | ||
121 | @a=grep(!/^gendsa$/,@a) if $no_sha1; | ||
122 | @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh; | ||
123 | |||
124 | @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1; | ||
125 | |||
126 | grep($_="$dir/$_",@a); | ||
127 | @a=grep(!/(^|\/)s_/,@a) if $no_sock; | ||
128 | @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock; | ||
129 | $ret=join(' ',@a)." "; | ||
130 | return($ret); | ||
131 | } | ||
132 | |||
diff --git a/src/lib/libcrypto/util/ck_errf.pl b/src/lib/libcrypto/util/ck_errf.pl new file mode 100644 index 0000000000..c5764e40df --- /dev/null +++ b/src/lib/libcrypto/util/ck_errf.pl | |||
@@ -0,0 +1,44 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # This is just a quick script to scan for cases where the 'error' | ||
4 | # function name in a XXXerr() macro is wrong. | ||
5 | # | ||
6 | # Run in the top level by going | ||
7 | # perl util/ck_errf.pl */*.c */*/*.c | ||
8 | # | ||
9 | |||
10 | foreach $file (@ARGV) | ||
11 | { | ||
12 | open(IN,"<$file") || die "unable to open $file\n"; | ||
13 | $func=""; | ||
14 | while (<IN>) | ||
15 | { | ||
16 | if (/^[a-zA-Z].+[\s*]([A-Za-z_0-9]+)\(.*\)/) | ||
17 | { | ||
18 | $func=$1; | ||
19 | $func =~ tr/A-Z/a-z/; | ||
20 | } | ||
21 | if (/([A-Z0-9]+)err\(([^,]+)/) | ||
22 | { | ||
23 | next if ($func eq ""); | ||
24 | $errlib=$1; | ||
25 | $n=$2; | ||
26 | if ($n !~ /([^_]+)_F_(.+)$/) | ||
27 | { | ||
28 | # print "check -$file:$.:$func:$n\n"; | ||
29 | next; | ||
30 | } | ||
31 | $lib=$1; | ||
32 | $n=$2; | ||
33 | |||
34 | if ($lib ne $errlib) | ||
35 | { print "$file:$.:$func:$n\n"; next; } | ||
36 | |||
37 | $n =~ tr/A-Z/a-z/; | ||
38 | if (($n ne $func) && ($errlib ne "SYS")) | ||
39 | { print "$file:$.:$func:$n\n"; next; } | ||
40 | # print "$func:$1\n"; | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | |||
diff --git a/src/lib/libcrypto/util/deleof.pl b/src/lib/libcrypto/util/deleof.pl new file mode 100644 index 0000000000..04f30f0e47 --- /dev/null +++ b/src/lib/libcrypto/util/deleof.pl | |||
@@ -0,0 +1,7 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | while (<>) | ||
4 | { | ||
5 | |||
6 | last if (/^# DO NOT DELETE THIS LINE/); | ||
7 | } | ||
diff --git a/src/lib/libcrypto/util/do_ms.sh b/src/lib/libcrypto/util/do_ms.sh new file mode 100644 index 0000000000..f498d842b7 --- /dev/null +++ b/src/lib/libcrypto/util/do_ms.sh | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # generate the Microsoft makefiles and .def files | ||
4 | # | ||
5 | |||
6 | PATH=util:../util:$PATH | ||
7 | |||
8 | # perl util/mk1mf.pl VC-MSDOS no-sock >ms/msdos.mak | ||
9 | # perl util/mk1mf.pl VC-W31-32 >ms/w31.mak | ||
10 | perl util/mk1mf.pl VC-WIN16 dll >ms/w31dll.mak | ||
11 | # perl util/mk1mf.pl VC-WIN32 >ms/nt.mak | ||
12 | perl util/mk1mf.pl VC-WIN32 dll >ms/ntdll.mak | ||
13 | |||
14 | perl util/mkdef.pl 16 libeay > ms/libeay16.def | ||
15 | perl util/mkdef.pl 32 libeay > ms/libeay32.def | ||
16 | perl util/mkdef.pl 16 ssleay > ms/ssleay16.def | ||
17 | perl util/mkdef.pl 32 ssleay > ms/ssleay32.def | ||
diff --git a/src/lib/libcrypto/util/err-ins.pl b/src/lib/libcrypto/util/err-ins.pl new file mode 100644 index 0000000000..db1bb48275 --- /dev/null +++ b/src/lib/libcrypto/util/err-ins.pl | |||
@@ -0,0 +1,33 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # tack error codes onto the end of a file | ||
4 | # | ||
5 | |||
6 | open(ERR,$ARGV[0]) || die "unable to open error file '$ARGV[0]':$!\n"; | ||
7 | @err=<ERR>; | ||
8 | close(ERR); | ||
9 | |||
10 | open(IN,$ARGV[1]) || die "unable to open header file '$ARGV[1]':$!\n"; | ||
11 | |||
12 | @out=""; | ||
13 | while (<IN>) | ||
14 | { | ||
15 | push(@out,$_); | ||
16 | last if /BEGIN ERROR CODES/; | ||
17 | } | ||
18 | close(IN); | ||
19 | |||
20 | open(OUT,">$ARGV[1]") || die "unable to open header file '$ARGV[1]':$1\n"; | ||
21 | print OUT @out; | ||
22 | print OUT @err; | ||
23 | print OUT <<"EOF"; | ||
24 | |||
25 | #ifdef __cplusplus | ||
26 | } | ||
27 | #endif | ||
28 | #endif | ||
29 | |||
30 | EOF | ||
31 | close(OUT); | ||
32 | |||
33 | |||
diff --git a/src/lib/libcrypto/util/files.pl b/src/lib/libcrypto/util/files.pl new file mode 100644 index 0000000000..bf3b7effdc --- /dev/null +++ b/src/lib/libcrypto/util/files.pl | |||
@@ -0,0 +1,61 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # used to generate the file MINFO for use by util/mk1mf.pl | ||
4 | # It is basically a list of all variables from the passed makefile | ||
5 | # | ||
6 | |||
7 | $s=""; | ||
8 | while (<>) | ||
9 | { | ||
10 | chop; | ||
11 | s/#.*//; | ||
12 | if (/^(\S+)\s*=\s*(.*)$/) | ||
13 | { | ||
14 | $o=""; | ||
15 | ($s,$b)=($1,$2); | ||
16 | for (;;) | ||
17 | { | ||
18 | if ($b =~ /\\$/) | ||
19 | { | ||
20 | chop($b); | ||
21 | $o.=$b." "; | ||
22 | $b=<>; | ||
23 | chop($b); | ||
24 | } | ||
25 | else | ||
26 | { | ||
27 | $o.=$b." "; | ||
28 | last; | ||
29 | } | ||
30 | } | ||
31 | $o =~ s/^\s+//; | ||
32 | $o =~ s/\s+$//; | ||
33 | $o =~ s/\s+/ /g; | ||
34 | |||
35 | $o =~ s/\$[({]([^)}]+)[)}]/$sym{$1}/g; | ||
36 | $sym{$s}=$o; | ||
37 | } | ||
38 | } | ||
39 | |||
40 | $pwd=`pwd`; chop($pwd); | ||
41 | |||
42 | if ($sym{'TOP'} eq ".") | ||
43 | { | ||
44 | $n=0; | ||
45 | $dir="."; | ||
46 | } | ||
47 | else { | ||
48 | $n=split(/\//,$sym{'TOP'}); | ||
49 | @_=split(/\//,$pwd); | ||
50 | $z=$#_-$n+1; | ||
51 | foreach $i ($z .. $#_) { $dir.=$_[$i]."/"; } | ||
52 | chop($dir); | ||
53 | } | ||
54 | |||
55 | print "RELATIVE_DIRECTORY=$dir\n"; | ||
56 | |||
57 | foreach (sort keys %sym) | ||
58 | { | ||
59 | print "$_=$sym{$_}\n"; | ||
60 | } | ||
61 | print "RELATIVE_DIRECTORY=\n"; | ||
diff --git a/src/lib/libcrypto/util/fixNT.sh b/src/lib/libcrypto/util/fixNT.sh new file mode 100644 index 0000000000..ce4f19299b --- /dev/null +++ b/src/lib/libcrypto/util/fixNT.sh | |||
@@ -0,0 +1,14 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # clean up the mess that NT makes of my source tree | ||
4 | # | ||
5 | |||
6 | if [ -f makefile.ssl -a ! -f Makefile.ssl ]; then | ||
7 | /bin/mv makefile.ssl Makefile.ssl | ||
8 | fi | ||
9 | chmod +x Configure util/* | ||
10 | echo cleaning | ||
11 | /bin/rm -f `find . -name '*.$$$' -print` 2>/dev/null >/dev/null | ||
12 | echo 'removing those damn ^M' | ||
13 | perl -pi -e 's/\015//' `find . -type 'f' -print |grep -v '.obj$' |grep -v '.der$' |grep -v '.gz'` | ||
14 | make -f Makefile.ssl links | ||
diff --git a/src/lib/libcrypto/util/install.sh b/src/lib/libcrypto/util/install.sh new file mode 100644 index 0000000000..e1d0c982df --- /dev/null +++ b/src/lib/libcrypto/util/install.sh | |||
@@ -0,0 +1,108 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # install - install a program, script, or datafile | ||
4 | # This comes from X11R5; it is not part of GNU. | ||
5 | # | ||
6 | # $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $ | ||
7 | # | ||
8 | # This script is compatible with the BSD install script, but was written | ||
9 | # from scratch. | ||
10 | # | ||
11 | |||
12 | |||
13 | # set DOITPROG to echo to test this script | ||
14 | |||
15 | doit="${DOITPROG:-}" | ||
16 | |||
17 | |||
18 | # put in absolute paths if you don't have them in your path; or use env. vars. | ||
19 | |||
20 | mvprog="${MVPROG:-mv}" | ||
21 | cpprog="${CPPROG:-cp}" | ||
22 | chmodprog="${CHMODPROG:-chmod}" | ||
23 | chownprog="${CHOWNPROG:-chown}" | ||
24 | chgrpprog="${CHGRPPROG:-chgrp}" | ||
25 | stripprog="${STRIPPROG:-strip}" | ||
26 | rmprog="${RMPROG:-rm}" | ||
27 | |||
28 | instcmd="$mvprog" | ||
29 | chmodcmd="" | ||
30 | chowncmd="" | ||
31 | chgrpcmd="" | ||
32 | stripcmd="" | ||
33 | rmcmd="$rmprog -f" | ||
34 | src="" | ||
35 | dst="" | ||
36 | |||
37 | while [ x"$1" != x ]; do | ||
38 | case $1 in | ||
39 | -c) instcmd="$cpprog" | ||
40 | shift | ||
41 | continue;; | ||
42 | |||
43 | -m) chmodcmd="$chmodprog $2" | ||
44 | shift | ||
45 | shift | ||
46 | continue;; | ||
47 | |||
48 | -o) chowncmd="$chownprog $2" | ||
49 | shift | ||
50 | shift | ||
51 | continue;; | ||
52 | |||
53 | -g) chgrpcmd="$chgrpprog $2" | ||
54 | shift | ||
55 | shift | ||
56 | continue;; | ||
57 | |||
58 | -s) stripcmd="$stripprog" | ||
59 | shift | ||
60 | continue;; | ||
61 | |||
62 | *) if [ x"$src" = x ] | ||
63 | then | ||
64 | src=$1 | ||
65 | else | ||
66 | dst=$1 | ||
67 | fi | ||
68 | shift | ||
69 | continue;; | ||
70 | esac | ||
71 | done | ||
72 | |||
73 | if [ x"$src" = x ] | ||
74 | then | ||
75 | echo "install: no input file specified" | ||
76 | exit 1 | ||
77 | fi | ||
78 | |||
79 | if [ x"$dst" = x ] | ||
80 | then | ||
81 | echo "install: no destination specified" | ||
82 | exit 1 | ||
83 | fi | ||
84 | |||
85 | |||
86 | # if destination is a directory, append the input filename; if your system | ||
87 | # does not like double slashes in filenames, you may need to add some logic | ||
88 | |||
89 | if [ -d $dst ] | ||
90 | then | ||
91 | dst="$dst"/`basename $src` | ||
92 | fi | ||
93 | |||
94 | |||
95 | # get rid of the old one and mode the new one in | ||
96 | |||
97 | $doit $rmcmd $dst | ||
98 | $doit $instcmd $src $dst | ||
99 | |||
100 | |||
101 | # and set any options; do chmod last to preserve setuid bits | ||
102 | |||
103 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; fi | ||
104 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; fi | ||
105 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; fi | ||
106 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; fi | ||
107 | |||
108 | exit 0 | ||
diff --git a/src/lib/libcrypto/util/libeay.num b/src/lib/libcrypto/util/libeay.num new file mode 100644 index 0000000000..fcaf254287 --- /dev/null +++ b/src/lib/libcrypto/util/libeay.num | |||
@@ -0,0 +1,1065 @@ | |||
1 | SSLeay 1 | ||
2 | SSLeay_version 2 | ||
3 | ASN1_BIT_STRING_asn1_meth 3 | ||
4 | ASN1_HEADER_free 4 | ||
5 | ASN1_HEADER_new 5 | ||
6 | ASN1_IA5STRING_asn1_meth 6 | ||
7 | ASN1_INTEGER_get 7 | ||
8 | ASN1_INTEGER_set 8 | ||
9 | ASN1_INTEGER_to_BN 9 | ||
10 | ASN1_OBJECT_create 10 | ||
11 | ASN1_OBJECT_free 11 | ||
12 | ASN1_OBJECT_new 12 | ||
13 | ASN1_PRINTABLE_type 13 | ||
14 | ASN1_STRING_cmp 14 | ||
15 | ASN1_STRING_dup 15 | ||
16 | ASN1_STRING_free 16 | ||
17 | ASN1_STRING_new 17 | ||
18 | ASN1_STRING_print 18 | ||
19 | ASN1_STRING_set 19 | ||
20 | ASN1_STRING_type_new 20 | ||
21 | ASN1_TYPE_free 21 | ||
22 | ASN1_TYPE_new 22 | ||
23 | ASN1_UNIVERSALSTRING_to_string 23 | ||
24 | ASN1_UTCTIME_check 24 | ||
25 | ASN1_UTCTIME_print 25 | ||
26 | ASN1_UTCTIME_set 26 | ||
27 | ASN1_check_infinite_end 27 | ||
28 | ASN1_d2i_bio 28 | ||
29 | ASN1_d2i_fp 29 | ||
30 | ASN1_digest 30 | ||
31 | ASN1_dup 31 | ||
32 | ASN1_get_object 32 | ||
33 | ASN1_i2d_bio 33 | ||
34 | ASN1_i2d_fp 34 | ||
35 | ASN1_object_size 35 | ||
36 | ASN1_parse 36 | ||
37 | ASN1_put_object 37 | ||
38 | ASN1_sign 38 | ||
39 | ASN1_verify 39 | ||
40 | BF_cbc_encrypt 40 | ||
41 | BF_cfb64_encrypt 41 | ||
42 | BF_ecb_encrypt 42 | ||
43 | BF_encrypt 43 | ||
44 | BF_ofb64_encrypt 44 | ||
45 | BF_options 45 | ||
46 | BF_set_key 46 | ||
47 | BIO_CONNECT_free 47 | ||
48 | BIO_CONNECT_new 48 | ||
49 | BIO_accept 51 | ||
50 | BIO_ctrl 52 | ||
51 | BIO_int_ctrl 53 | ||
52 | BIO_debug_callback 54 | ||
53 | BIO_dump 55 | ||
54 | BIO_dup_chain 56 | ||
55 | BIO_f_base64 57 | ||
56 | BIO_f_buffer 58 | ||
57 | BIO_f_cipher 59 | ||
58 | BIO_f_md 60 | ||
59 | BIO_f_null 61 | ||
60 | BIO_f_proxy_server 62 | ||
61 | BIO_fd_non_fatal_error 63 | ||
62 | BIO_fd_should_retry 64 | ||
63 | BIO_find_type 65 | ||
64 | BIO_free 66 | ||
65 | BIO_free_all 67 | ||
66 | BIO_get_accept_socket 69 | ||
67 | BIO_get_filter_bio 70 | ||
68 | BIO_get_host_ip 71 | ||
69 | BIO_get_port 72 | ||
70 | BIO_get_retry_BIO 73 | ||
71 | BIO_get_retry_reason 74 | ||
72 | BIO_gethostbyname 75 | ||
73 | BIO_gets 76 | ||
74 | BIO_new 78 | ||
75 | BIO_new_accept 79 | ||
76 | BIO_new_connect 80 | ||
77 | BIO_new_fd 81 | ||
78 | BIO_new_file 82 | ||
79 | BIO_new_fp 83 | ||
80 | BIO_new_socket 84 | ||
81 | BIO_pop 85 | ||
82 | BIO_printf 86 | ||
83 | BIO_push 87 | ||
84 | BIO_puts 88 | ||
85 | BIO_read 89 | ||
86 | BIO_s_accept 90 | ||
87 | BIO_s_connect 91 | ||
88 | BIO_s_fd 92 | ||
89 | BIO_s_file 93 | ||
90 | BIO_s_mem 95 | ||
91 | BIO_s_null 96 | ||
92 | BIO_s_proxy_client 97 | ||
93 | BIO_s_socket 98 | ||
94 | BIO_set 100 | ||
95 | BIO_set_cipher 101 | ||
96 | BIO_set_tcp_ndelay 102 | ||
97 | BIO_sock_cleanup 103 | ||
98 | BIO_sock_error 104 | ||
99 | BIO_sock_init 105 | ||
100 | BIO_sock_non_fatal_error 106 | ||
101 | BIO_sock_should_retry 107 | ||
102 | BIO_socket_ioctl 108 | ||
103 | BIO_write 109 | ||
104 | BN_CTX_free 110 | ||
105 | BN_CTX_new 111 | ||
106 | BN_MONT_CTX_free 112 | ||
107 | BN_MONT_CTX_new 113 | ||
108 | BN_MONT_CTX_set 114 | ||
109 | BN_add 115 | ||
110 | BN_add_word 116 | ||
111 | BN_hex2bn 117 | ||
112 | BN_bin2bn 118 | ||
113 | BN_bn2hex 119 | ||
114 | BN_bn2bin 120 | ||
115 | BN_clear 121 | ||
116 | BN_clear_bit 122 | ||
117 | BN_clear_free 123 | ||
118 | BN_cmp 124 | ||
119 | BN_copy 125 | ||
120 | BN_div 126 | ||
121 | BN_div_word 127 | ||
122 | BN_dup 128 | ||
123 | BN_free 129 | ||
124 | BN_from_montgomery 130 | ||
125 | BN_gcd 131 | ||
126 | BN_generate_prime 132 | ||
127 | BN_get_word 133 | ||
128 | BN_is_bit_set 134 | ||
129 | BN_is_prime 135 | ||
130 | BN_lshift 136 | ||
131 | BN_lshift1 137 | ||
132 | BN_mask_bits 138 | ||
133 | BN_mod 139 | ||
134 | BN_mod_exp 140 | ||
135 | BN_mod_exp_mont 141 | ||
136 | BN_mod_exp_recp 142 | ||
137 | BN_mod_exp_simple 143 | ||
138 | BN_mod_inverse 144 | ||
139 | BN_mod_mul 145 | ||
140 | BN_mod_mul_montgomery 146 | ||
141 | BN_mod_mul_reciprocal 147 | ||
142 | BN_mod_word 148 | ||
143 | BN_mul 149 | ||
144 | BN_new 150 | ||
145 | BN_num_bits 151 | ||
146 | BN_num_bits_word 152 | ||
147 | BN_options 153 | ||
148 | BN_print 154 | ||
149 | BN_print_fp 155 | ||
150 | BN_rand 156 | ||
151 | BN_reciprocal 157 | ||
152 | BN_rshift 158 | ||
153 | BN_rshift1 159 | ||
154 | BN_set_bit 160 | ||
155 | BN_set_word 161 | ||
156 | BN_sqr 162 | ||
157 | BN_sub 163 | ||
158 | BN_to_ASN1_INTEGER 164 | ||
159 | BN_ucmp 165 | ||
160 | BN_value_one 166 | ||
161 | BUF_MEM_free 167 | ||
162 | BUF_MEM_grow 168 | ||
163 | BUF_MEM_new 169 | ||
164 | BUF_strdup 170 | ||
165 | CONF_free 171 | ||
166 | CONF_get_number 172 | ||
167 | CONF_get_section 173 | ||
168 | CONF_get_string 174 | ||
169 | CONF_load 175 | ||
170 | CRYPTO_add_lock 176 | ||
171 | CRYPTO_dbg_free 177 | ||
172 | CRYPTO_dbg_malloc 178 | ||
173 | CRYPTO_dbg_realloc 179 | ||
174 | CRYPTO_dbg_remalloc 180 | ||
175 | CRYPTO_free 181 | ||
176 | CRYPTO_get_add_lock_callback 182 | ||
177 | CRYPTO_get_id_callback 183 | ||
178 | CRYPTO_get_lock_name 184 | ||
179 | CRYPTO_get_locking_callback 185 | ||
180 | CRYPTO_get_mem_functions 186 | ||
181 | CRYPTO_lock 187 | ||
182 | CRYPTO_malloc 188 | ||
183 | CRYPTO_mem_ctrl 189 | ||
184 | CRYPTO_mem_leaks 190 | ||
185 | CRYPTO_mem_leaks_cb 191 | ||
186 | CRYPTO_mem_leaks_fp 192 | ||
187 | CRYPTO_realloc 193 | ||
188 | CRYPTO_remalloc 194 | ||
189 | CRYPTO_set_add_lock_callback 195 | ||
190 | CRYPTO_set_id_callback 196 | ||
191 | CRYPTO_set_locking_callback 197 | ||
192 | CRYPTO_set_mem_functions 198 | ||
193 | CRYPTO_thread_id 199 | ||
194 | DH_check 200 | ||
195 | DH_compute_key 201 | ||
196 | DH_free 202 | ||
197 | DH_generate_key 203 | ||
198 | DH_generate_parameters 204 | ||
199 | DH_new 205 | ||
200 | DH_size 206 | ||
201 | DHparams_print 207 | ||
202 | DHparams_print_fp 208 | ||
203 | DSA_free 209 | ||
204 | DSA_generate_key 210 | ||
205 | DSA_generate_parameters 211 | ||
206 | DSA_is_prime 212 | ||
207 | DSA_new 213 | ||
208 | DSA_print 214 | ||
209 | DSA_print_fp 215 | ||
210 | DSA_sign 216 | ||
211 | DSA_sign_setup 217 | ||
212 | DSA_size 218 | ||
213 | DSA_verify 219 | ||
214 | DSAparams_print 220 | ||
215 | DSAparams_print_fp 221 | ||
216 | ERR_clear_error 222 | ||
217 | ERR_error_string 223 | ||
218 | ERR_free_strings 224 | ||
219 | ERR_func_error_string 225 | ||
220 | ERR_get_err_state_table 226 | ||
221 | ERR_get_error 227 | ||
222 | ERR_get_error_line 228 | ||
223 | ERR_get_state 229 | ||
224 | ERR_get_string_table 230 | ||
225 | ERR_lib_error_string 231 | ||
226 | ERR_load_ASN1_strings 232 | ||
227 | ERR_load_BIO_strings 233 | ||
228 | ERR_load_BN_strings 234 | ||
229 | ERR_load_BUF_strings 235 | ||
230 | ERR_load_CONF_strings 236 | ||
231 | ERR_load_DH_strings 237 | ||
232 | ERR_load_DSA_strings 238 | ||
233 | ERR_load_ERR_strings 239 | ||
234 | ERR_load_EVP_strings 240 | ||
235 | ERR_load_OBJ_strings 241 | ||
236 | ERR_load_PEM_strings 242 | ||
237 | ERR_load_PROXY_strings 243 | ||
238 | ERR_load_RSA_strings 244 | ||
239 | ERR_load_X509_strings 245 | ||
240 | ERR_load_crypto_strings 246 | ||
241 | ERR_load_strings 247 | ||
242 | ERR_peek_error 248 | ||
243 | ERR_peek_error_line 249 | ||
244 | ERR_print_errors 250 | ||
245 | ERR_print_errors_fp 251 | ||
246 | ERR_put_error 252 | ||
247 | ERR_reason_error_string 253 | ||
248 | ERR_remove_state 254 | ||
249 | EVP_BytesToKey 255 | ||
250 | EVP_CIPHER_CTX_cleanup 256 | ||
251 | EVP_CipherFinal 257 | ||
252 | EVP_CipherInit 258 | ||
253 | EVP_CipherUpdate 259 | ||
254 | EVP_DecodeBlock 260 | ||
255 | EVP_DecodeFinal 261 | ||
256 | EVP_DecodeInit 262 | ||
257 | EVP_DecodeUpdate 263 | ||
258 | EVP_DecryptFinal 264 | ||
259 | EVP_DecryptInit 265 | ||
260 | EVP_DecryptUpdate 266 | ||
261 | EVP_DigestFinal 267 | ||
262 | EVP_DigestInit 268 | ||
263 | EVP_DigestUpdate 269 | ||
264 | EVP_EncodeBlock 270 | ||
265 | EVP_EncodeFinal 271 | ||
266 | EVP_EncodeInit 272 | ||
267 | EVP_EncodeUpdate 273 | ||
268 | EVP_EncryptFinal 274 | ||
269 | EVP_EncryptInit 275 | ||
270 | EVP_EncryptUpdate 276 | ||
271 | EVP_OpenFinal 277 | ||
272 | EVP_OpenInit 278 | ||
273 | EVP_PKEY_assign 279 | ||
274 | EVP_PKEY_copy_parameters 280 | ||
275 | EVP_PKEY_free 281 | ||
276 | EVP_PKEY_missing_parameters 282 | ||
277 | EVP_PKEY_new 283 | ||
278 | EVP_PKEY_save_parameters 284 | ||
279 | EVP_PKEY_size 285 | ||
280 | EVP_PKEY_type 286 | ||
281 | EVP_SealFinal 287 | ||
282 | EVP_SealInit 288 | ||
283 | EVP_SignFinal 289 | ||
284 | EVP_VerifyFinal 290 | ||
285 | EVP_add_alias 291 | ||
286 | EVP_add_cipher 292 | ||
287 | EVP_add_digest 293 | ||
288 | EVP_bf_cbc 294 | ||
289 | EVP_bf_cfb 295 | ||
290 | EVP_bf_ecb 296 | ||
291 | EVP_bf_ofb 297 | ||
292 | EVP_cleanup 298 | ||
293 | EVP_des_cbc 299 | ||
294 | EVP_des_cfb 300 | ||
295 | EVP_des_ecb 301 | ||
296 | EVP_des_ede 302 | ||
297 | EVP_des_ede3 303 | ||
298 | EVP_des_ede3_cbc 304 | ||
299 | EVP_des_ede3_cfb 305 | ||
300 | EVP_des_ede3_ofb 306 | ||
301 | EVP_des_ede_cbc 307 | ||
302 | EVP_des_ede_cfb 308 | ||
303 | EVP_des_ede_ofb 309 | ||
304 | EVP_des_ofb 310 | ||
305 | EVP_desx_cbc 311 | ||
306 | EVP_dss 312 | ||
307 | EVP_dss1 313 | ||
308 | EVP_enc_null 314 | ||
309 | EVP_get_cipherbyname 315 | ||
310 | EVP_get_digestbyname 316 | ||
311 | EVP_get_pw_prompt 317 | ||
312 | EVP_idea_cbc 318 | ||
313 | EVP_idea_cfb 319 | ||
314 | EVP_idea_ecb 320 | ||
315 | EVP_idea_ofb 321 | ||
316 | EVP_md2 322 | ||
317 | EVP_md5 323 | ||
318 | EVP_md_null 324 | ||
319 | EVP_rc2_cbc 325 | ||
320 | EVP_rc2_cfb 326 | ||
321 | EVP_rc2_ecb 327 | ||
322 | EVP_rc2_ofb 328 | ||
323 | EVP_rc4 329 | ||
324 | EVP_read_pw_string 330 | ||
325 | EVP_set_pw_prompt 331 | ||
326 | EVP_sha 332 | ||
327 | EVP_sha1 333 | ||
328 | MD2 334 | ||
329 | MD2_Final 335 | ||
330 | MD2_Init 336 | ||
331 | MD2_Update 337 | ||
332 | MD2_options 338 | ||
333 | MD5 339 | ||
334 | MD5_Final 340 | ||
335 | MD5_Init 341 | ||
336 | MD5_Update 342 | ||
337 | MDC2 343 | ||
338 | MDC2_Final 344 | ||
339 | MDC2_Init 345 | ||
340 | MDC2_Update 346 | ||
341 | NETSCAPE_SPKAC_free 347 | ||
342 | NETSCAPE_SPKAC_new 348 | ||
343 | NETSCAPE_SPKI_free 349 | ||
344 | NETSCAPE_SPKI_new 350 | ||
345 | NETSCAPE_SPKI_sign 351 | ||
346 | NETSCAPE_SPKI_verify 352 | ||
347 | OBJ_add_object 353 | ||
348 | OBJ_bsearch 354 | ||
349 | OBJ_cleanup 355 | ||
350 | OBJ_cmp 356 | ||
351 | OBJ_create 357 | ||
352 | OBJ_dup 358 | ||
353 | OBJ_ln2nid 359 | ||
354 | OBJ_new_nid 360 | ||
355 | OBJ_nid2ln 361 | ||
356 | OBJ_nid2obj 362 | ||
357 | OBJ_nid2sn 363 | ||
358 | OBJ_obj2nid 364 | ||
359 | OBJ_sn2nid 365 | ||
360 | OBJ_txt2nid 366 | ||
361 | PEM_ASN1_read 367 | ||
362 | PEM_ASN1_read_bio 368 | ||
363 | PEM_ASN1_write 369 | ||
364 | PEM_ASN1_write_bio 370 | ||
365 | PEM_SealFinal 371 | ||
366 | PEM_SealInit 372 | ||
367 | PEM_SealUpdate 373 | ||
368 | PEM_SignFinal 374 | ||
369 | PEM_SignInit 375 | ||
370 | PEM_SignUpdate 376 | ||
371 | PEM_X509_INFO_read 377 | ||
372 | PEM_X509_INFO_read_bio 378 | ||
373 | PEM_X509_INFO_write_bio 379 | ||
374 | PEM_dek_info 380 | ||
375 | PEM_do_header 381 | ||
376 | PEM_get_EVP_CIPHER_INFO 382 | ||
377 | PEM_proc_type 383 | ||
378 | PEM_read 384 | ||
379 | PEM_read_DHparams 385 | ||
380 | PEM_read_DSAPrivateKey 386 | ||
381 | PEM_read_DSAparams 387 | ||
382 | PEM_read_PKCS7 388 | ||
383 | PEM_read_PrivateKey 389 | ||
384 | PEM_read_RSAPrivateKey 390 | ||
385 | PEM_read_X509 391 | ||
386 | PEM_read_X509_CRL 392 | ||
387 | PEM_read_X509_REQ 393 | ||
388 | PEM_read_bio 394 | ||
389 | PEM_read_bio_DHparams 395 | ||
390 | PEM_read_bio_DSAPrivateKey 396 | ||
391 | PEM_read_bio_DSAparams 397 | ||
392 | PEM_read_bio_PKCS7 398 | ||
393 | PEM_read_bio_PrivateKey 399 | ||
394 | PEM_read_bio_RSAPrivateKey 400 | ||
395 | PEM_read_bio_X509 401 | ||
396 | PEM_read_bio_X509_CRL 402 | ||
397 | PEM_read_bio_X509_REQ 403 | ||
398 | PEM_write 404 | ||
399 | PEM_write_DHparams 405 | ||
400 | PEM_write_DSAPrivateKey 406 | ||
401 | PEM_write_DSAparams 407 | ||
402 | PEM_write_PKCS7 408 | ||
403 | PEM_write_PrivateKey 409 | ||
404 | PEM_write_RSAPrivateKey 410 | ||
405 | PEM_write_X509 411 | ||
406 | PEM_write_X509_CRL 412 | ||
407 | PEM_write_X509_REQ 413 | ||
408 | PEM_write_bio 414 | ||
409 | PEM_write_bio_DHparams 415 | ||
410 | PEM_write_bio_DSAPrivateKey 416 | ||
411 | PEM_write_bio_DSAparams 417 | ||
412 | PEM_write_bio_PKCS7 418 | ||
413 | PEM_write_bio_PrivateKey 419 | ||
414 | PEM_write_bio_RSAPrivateKey 420 | ||
415 | PEM_write_bio_X509 421 | ||
416 | PEM_write_bio_X509_CRL 422 | ||
417 | PEM_write_bio_X509_REQ 423 | ||
418 | PKCS7_DIGEST_free 424 | ||
419 | PKCS7_DIGEST_new 425 | ||
420 | PKCS7_ENCRYPT_free 426 | ||
421 | PKCS7_ENCRYPT_new 427 | ||
422 | PKCS7_ENC_CONTENT_free 428 | ||
423 | PKCS7_ENC_CONTENT_new 429 | ||
424 | PKCS7_ENVELOPE_free 430 | ||
425 | PKCS7_ENVELOPE_new 431 | ||
426 | PKCS7_ISSUER_AND_SERIAL_digest 432 | ||
427 | PKCS7_ISSUER_AND_SERIAL_free 433 | ||
428 | PKCS7_ISSUER_AND_SERIAL_new 434 | ||
429 | PKCS7_RECIP_INFO_free 435 | ||
430 | PKCS7_RECIP_INFO_new 436 | ||
431 | PKCS7_SIGNED_free 437 | ||
432 | PKCS7_SIGNED_new 438 | ||
433 | PKCS7_SIGNER_INFO_free 439 | ||
434 | PKCS7_SIGNER_INFO_new 440 | ||
435 | PKCS7_SIGN_ENVELOPE_free 441 | ||
436 | PKCS7_SIGN_ENVELOPE_new 442 | ||
437 | PKCS7_dup 443 | ||
438 | PKCS7_free 444 | ||
439 | PKCS7_new 445 | ||
440 | PROXY_ENTRY_add_noproxy 446 | ||
441 | PROXY_ENTRY_clear_noproxy 447 | ||
442 | PROXY_ENTRY_free 448 | ||
443 | PROXY_ENTRY_get_noproxy 449 | ||
444 | PROXY_ENTRY_new 450 | ||
445 | PROXY_ENTRY_set_server 451 | ||
446 | PROXY_add_noproxy 452 | ||
447 | PROXY_add_server 453 | ||
448 | PROXY_check_by_host 454 | ||
449 | PROXY_check_url 455 | ||
450 | PROXY_clear_noproxy 456 | ||
451 | PROXY_free 457 | ||
452 | PROXY_get_noproxy 458 | ||
453 | PROXY_get_proxies 459 | ||
454 | PROXY_get_proxy_entry 460 | ||
455 | PROXY_load_conf 461 | ||
456 | PROXY_new 462 | ||
457 | PROXY_print 463 | ||
458 | RAND_bytes 464 | ||
459 | RAND_cleanup 465 | ||
460 | RAND_file_name 466 | ||
461 | RAND_load_file 467 | ||
462 | RAND_screen 468 | ||
463 | RAND_seed 469 | ||
464 | RAND_write_file 470 | ||
465 | RC2_cbc_encrypt 471 | ||
466 | RC2_cfb64_encrypt 472 | ||
467 | RC2_ecb_encrypt 473 | ||
468 | RC2_encrypt 474 | ||
469 | RC2_ofb64_encrypt 475 | ||
470 | RC2_set_key 476 | ||
471 | RC4 477 | ||
472 | RC4_options 478 | ||
473 | RC4_set_key 479 | ||
474 | RSAPrivateKey_asn1_meth 480 | ||
475 | RSAPrivateKey_dup 481 | ||
476 | RSAPublicKey_dup 482 | ||
477 | RSA_PKCS1_SSLeay 483 | ||
478 | RSA_free 484 | ||
479 | RSA_generate_key 485 | ||
480 | RSA_new 486 | ||
481 | RSA_new_method 487 | ||
482 | RSA_print 488 | ||
483 | RSA_print_fp 489 | ||
484 | RSA_private_decrypt 490 | ||
485 | RSA_private_encrypt 491 | ||
486 | RSA_public_decrypt 492 | ||
487 | RSA_public_encrypt 493 | ||
488 | RSA_set_default_method 494 | ||
489 | RSA_sign 495 | ||
490 | RSA_sign_ASN1_OCTET_STRING 496 | ||
491 | RSA_size 497 | ||
492 | RSA_verify 498 | ||
493 | RSA_verify_ASN1_OCTET_STRING 499 | ||
494 | SHA 500 | ||
495 | SHA1 501 | ||
496 | SHA1_Final 502 | ||
497 | SHA1_Init 503 | ||
498 | SHA1_Update 504 | ||
499 | SHA_Final 505 | ||
500 | SHA_Init 506 | ||
501 | SHA_Update 507 | ||
502 | SSLeay_add_all_algorithms 508 | ||
503 | SSLeay_add_all_ciphers 509 | ||
504 | SSLeay_add_all_digests 510 | ||
505 | TXT_DB_create_index 511 | ||
506 | TXT_DB_free 512 | ||
507 | TXT_DB_get_by_index 513 | ||
508 | TXT_DB_insert 514 | ||
509 | TXT_DB_read 515 | ||
510 | TXT_DB_write 516 | ||
511 | X509_ALGOR_free 517 | ||
512 | X509_ALGOR_new 518 | ||
513 | X509_ATTRIBUTE_free 519 | ||
514 | X509_ATTRIBUTE_new 520 | ||
515 | X509_CINF_free 521 | ||
516 | X509_CINF_new 522 | ||
517 | X509_CRL_INFO_free 523 | ||
518 | X509_CRL_INFO_new 524 | ||
519 | X509_CRL_add_ext 525 | ||
520 | X509_CRL_cmp 526 | ||
521 | X509_CRL_delete_ext 527 | ||
522 | X509_CRL_dup 528 | ||
523 | X509_CRL_free 529 | ||
524 | X509_CRL_get_ext 530 | ||
525 | X509_CRL_get_ext_by_NID 531 | ||
526 | X509_CRL_get_ext_by_OBJ 532 | ||
527 | X509_CRL_get_ext_by_critical 533 | ||
528 | X509_CRL_get_ext_count 534 | ||
529 | X509_CRL_new 535 | ||
530 | X509_CRL_sign 536 | ||
531 | X509_CRL_verify 537 | ||
532 | X509_EXTENSION_create_by_NID 538 | ||
533 | X509_EXTENSION_create_by_OBJ 539 | ||
534 | X509_EXTENSION_dup 540 | ||
535 | X509_EXTENSION_free 541 | ||
536 | X509_EXTENSION_get_critical 542 | ||
537 | X509_EXTENSION_get_data 543 | ||
538 | X509_EXTENSION_get_object 544 | ||
539 | X509_EXTENSION_new 545 | ||
540 | X509_EXTENSION_set_critical 546 | ||
541 | X509_EXTENSION_set_data 547 | ||
542 | X509_EXTENSION_set_object 548 | ||
543 | X509_INFO_free 549 | ||
544 | X509_INFO_new 550 | ||
545 | X509_LOOKUP_by_alias 551 | ||
546 | X509_LOOKUP_by_fingerprint 552 | ||
547 | X509_LOOKUP_by_issuer_serial 553 | ||
548 | X509_LOOKUP_by_subject 554 | ||
549 | X509_LOOKUP_ctrl 555 | ||
550 | X509_LOOKUP_file 556 | ||
551 | X509_LOOKUP_free 557 | ||
552 | X509_LOOKUP_hash_dir 558 | ||
553 | X509_LOOKUP_init 559 | ||
554 | X509_LOOKUP_new 560 | ||
555 | X509_LOOKUP_shutdown 561 | ||
556 | X509_NAME_ENTRY_create_by_NID 562 | ||
557 | X509_NAME_ENTRY_create_by_OBJ 563 | ||
558 | X509_NAME_ENTRY_dup 564 | ||
559 | X509_NAME_ENTRY_free 565 | ||
560 | X509_NAME_ENTRY_get_data 566 | ||
561 | X509_NAME_ENTRY_get_object 567 | ||
562 | X509_NAME_ENTRY_new 568 | ||
563 | X509_NAME_ENTRY_set_data 569 | ||
564 | X509_NAME_ENTRY_set_object 570 | ||
565 | X509_NAME_add_entry 571 | ||
566 | X509_NAME_cmp 572 | ||
567 | X509_NAME_delete_entry 573 | ||
568 | X509_NAME_digest 574 | ||
569 | X509_NAME_dup 575 | ||
570 | X509_NAME_entry_count 576 | ||
571 | X509_NAME_free 577 | ||
572 | X509_NAME_get_entry 578 | ||
573 | X509_NAME_get_index_by_NID 579 | ||
574 | X509_NAME_get_index_by_OBJ 580 | ||
575 | X509_NAME_get_text_by_NID 581 | ||
576 | X509_NAME_get_text_by_OBJ 582 | ||
577 | X509_NAME_hash 583 | ||
578 | X509_NAME_new 584 | ||
579 | X509_NAME_oneline 585 | ||
580 | X509_NAME_print 586 | ||
581 | X509_NAME_set 587 | ||
582 | X509_OBJECT_free_contents 588 | ||
583 | X509_OBJECT_retrive_by_subject 589 | ||
584 | X509_OBJECT_up_ref_count 590 | ||
585 | X509_PKEY_free 591 | ||
586 | X509_PKEY_new 592 | ||
587 | X509_PUBKEY_free 593 | ||
588 | X509_PUBKEY_get 594 | ||
589 | X509_PUBKEY_new 595 | ||
590 | X509_PUBKEY_set 596 | ||
591 | X509_REQ_INFO_free 597 | ||
592 | X509_REQ_INFO_new 598 | ||
593 | X509_REQ_dup 599 | ||
594 | X509_REQ_free 600 | ||
595 | X509_REQ_get_pubkey 601 | ||
596 | X509_REQ_new 602 | ||
597 | X509_REQ_print 603 | ||
598 | X509_REQ_print_fp 604 | ||
599 | X509_REQ_set_pubkey 605 | ||
600 | X509_REQ_set_subject_name 606 | ||
601 | X509_REQ_set_version 607 | ||
602 | X509_REQ_sign 608 | ||
603 | X509_REQ_to_X509 609 | ||
604 | X509_REQ_verify 610 | ||
605 | X509_REVOKED_add_ext 611 | ||
606 | X509_REVOKED_delete_ext 612 | ||
607 | X509_REVOKED_free 613 | ||
608 | X509_REVOKED_get_ext 614 | ||
609 | X509_REVOKED_get_ext_by_NID 615 | ||
610 | X509_REVOKED_get_ext_by_OBJ 616 | ||
611 | X509_REVOKED_get_ext_by_critical 617 | ||
612 | X509_REVOKED_get_ext_count 618 | ||
613 | X509_REVOKED_new 619 | ||
614 | X509_SIG_free 620 | ||
615 | X509_SIG_new 621 | ||
616 | X509_STORE_CTX_cleanup 622 | ||
617 | X509_STORE_CTX_init 623 | ||
618 | X509_STORE_add_cert 624 | ||
619 | X509_STORE_add_lookup 625 | ||
620 | X509_STORE_free 626 | ||
621 | X509_STORE_get_by_subject 627 | ||
622 | X509_STORE_load_locations 628 | ||
623 | X509_STORE_new 629 | ||
624 | X509_STORE_set_default_paths 630 | ||
625 | X509_VAL_free 631 | ||
626 | X509_VAL_new 632 | ||
627 | X509_add_ext 633 | ||
628 | X509_asn1_meth 634 | ||
629 | X509_certificate_type 635 | ||
630 | X509_check_private_key 636 | ||
631 | X509_cmp_current_time 637 | ||
632 | X509_delete_ext 638 | ||
633 | X509_digest 639 | ||
634 | X509_dup 640 | ||
635 | X509_free 641 | ||
636 | X509_get_default_cert_area 642 | ||
637 | X509_get_default_cert_dir 643 | ||
638 | X509_get_default_cert_dir_env 644 | ||
639 | X509_get_default_cert_file 645 | ||
640 | X509_get_default_cert_file_env 646 | ||
641 | X509_get_default_private_dir 647 | ||
642 | X509_get_ext 648 | ||
643 | X509_get_ext_by_NID 649 | ||
644 | X509_get_ext_by_OBJ 650 | ||
645 | X509_get_ext_by_critical 651 | ||
646 | X509_get_ext_count 652 | ||
647 | X509_get_issuer_name 653 | ||
648 | X509_get_pubkey 654 | ||
649 | X509_get_pubkey_parameters 655 | ||
650 | X509_get_serialNumber 656 | ||
651 | X509_get_subject_name 657 | ||
652 | X509_gmtime_adj 658 | ||
653 | X509_issuer_and_serial_cmp 659 | ||
654 | X509_issuer_and_serial_hash 660 | ||
655 | X509_issuer_name_cmp 661 | ||
656 | X509_issuer_name_hash 662 | ||
657 | X509_load_cert_file 663 | ||
658 | X509_new 664 | ||
659 | X509_print 665 | ||
660 | X509_print_fp 666 | ||
661 | X509_set_issuer_name 667 | ||
662 | X509_set_notAfter 668 | ||
663 | X509_set_notBefore 669 | ||
664 | X509_set_pubkey 670 | ||
665 | X509_set_serialNumber 671 | ||
666 | X509_set_subject_name 672 | ||
667 | X509_set_version 673 | ||
668 | X509_sign 674 | ||
669 | X509_subject_name_cmp 675 | ||
670 | X509_subject_name_hash 676 | ||
671 | X509_to_X509_REQ 677 | ||
672 | X509_verify 678 | ||
673 | X509_verify_cert 679 | ||
674 | X509_verify_cert_error_string 680 | ||
675 | X509v3_add_ext 681 | ||
676 | X509v3_add_extension 682 | ||
677 | X509v3_add_netscape_extensions 683 | ||
678 | X509v3_add_standard_extensions 684 | ||
679 | X509v3_cleanup_extensions 685 | ||
680 | X509v3_data_type_by_NID 686 | ||
681 | X509v3_data_type_by_OBJ 687 | ||
682 | X509v3_delete_ext 688 | ||
683 | X509v3_get_ext 689 | ||
684 | X509v3_get_ext_by_NID 690 | ||
685 | X509v3_get_ext_by_OBJ 691 | ||
686 | X509v3_get_ext_by_critical 692 | ||
687 | X509v3_get_ext_count 693 | ||
688 | X509v3_pack_string 694 | ||
689 | X509v3_pack_type_by_NID 695 | ||
690 | X509v3_pack_type_by_OBJ 696 | ||
691 | X509v3_unpack_string 697 | ||
692 | _des_crypt 698 | ||
693 | a2d_ASN1_OBJECT 699 | ||
694 | a2i_ASN1_INTEGER 700 | ||
695 | a2i_ASN1_STRING 701 | ||
696 | asn1_Finish 702 | ||
697 | asn1_GetSequence 703 | ||
698 | bn_div64 704 | ||
699 | bn_expand2 705 | ||
700 | bn_mul_add_words 706 | ||
701 | bn_mul_words 707 | ||
702 | bn_qadd 708 | ||
703 | bn_qsub 709 | ||
704 | bn_sqr_words 710 | ||
705 | crypt 711 | ||
706 | d2i_ASN1_BIT_STRING 712 | ||
707 | d2i_ASN1_BOOLEAN 713 | ||
708 | d2i_ASN1_HEADER 714 | ||
709 | d2i_ASN1_IA5STRING 715 | ||
710 | d2i_ASN1_INTEGER 716 | ||
711 | d2i_ASN1_OBJECT 717 | ||
712 | d2i_ASN1_OCTET_STRING 718 | ||
713 | d2i_ASN1_PRINTABLE 719 | ||
714 | d2i_ASN1_PRINTABLESTRING 720 | ||
715 | d2i_ASN1_SET 721 | ||
716 | d2i_ASN1_T61STRING 722 | ||
717 | d2i_ASN1_TYPE 723 | ||
718 | d2i_ASN1_UTCTIME 724 | ||
719 | d2i_ASN1_bytes 725 | ||
720 | d2i_ASN1_type_bytes 726 | ||
721 | d2i_DHparams 727 | ||
722 | d2i_DSAPrivateKey 728 | ||
723 | d2i_DSAPrivateKey_bio 729 | ||
724 | d2i_DSAPrivateKey_fp 730 | ||
725 | d2i_DSAPublicKey 731 | ||
726 | d2i_DSAparams 732 | ||
727 | d2i_NETSCAPE_SPKAC 733 | ||
728 | d2i_NETSCAPE_SPKI 734 | ||
729 | d2i_Netscape_RSA 735 | ||
730 | d2i_PKCS7 736 | ||
731 | d2i_PKCS7_DIGEST 737 | ||
732 | d2i_PKCS7_ENCRYPT 738 | ||
733 | d2i_PKCS7_ENC_CONTENT 739 | ||
734 | d2i_PKCS7_ENVELOPE 740 | ||
735 | d2i_PKCS7_ISSUER_AND_SERIAL 741 | ||
736 | d2i_PKCS7_RECIP_INFO 742 | ||
737 | d2i_PKCS7_SIGNED 743 | ||
738 | d2i_PKCS7_SIGNER_INFO 744 | ||
739 | d2i_PKCS7_SIGN_ENVELOPE 745 | ||
740 | d2i_PKCS7_bio 746 | ||
741 | d2i_PKCS7_fp 747 | ||
742 | d2i_PrivateKey 748 | ||
743 | d2i_PublicKey 749 | ||
744 | d2i_RSAPrivateKey 750 | ||
745 | d2i_RSAPrivateKey_bio 751 | ||
746 | d2i_RSAPrivateKey_fp 752 | ||
747 | d2i_RSAPublicKey 753 | ||
748 | d2i_X509 754 | ||
749 | d2i_X509_ALGOR 755 | ||
750 | d2i_X509_ATTRIBUTE 756 | ||
751 | d2i_X509_CINF 757 | ||
752 | d2i_X509_CRL 758 | ||
753 | d2i_X509_CRL_INFO 759 | ||
754 | d2i_X509_CRL_bio 760 | ||
755 | d2i_X509_CRL_fp 761 | ||
756 | d2i_X509_EXTENSION 762 | ||
757 | d2i_X509_NAME 763 | ||
758 | d2i_X509_NAME_ENTRY 764 | ||
759 | d2i_X509_PKEY 765 | ||
760 | d2i_X509_PUBKEY 766 | ||
761 | d2i_X509_REQ 767 | ||
762 | d2i_X509_REQ_INFO 768 | ||
763 | d2i_X509_REQ_bio 769 | ||
764 | d2i_X509_REQ_fp 770 | ||
765 | d2i_X509_REVOKED 771 | ||
766 | d2i_X509_SIG 772 | ||
767 | d2i_X509_VAL 773 | ||
768 | d2i_X509_bio 774 | ||
769 | d2i_X509_fp 775 | ||
770 | des_cbc_cksum 777 | ||
771 | des_cbc_encrypt 778 | ||
772 | des_cblock_print_file 779 | ||
773 | des_cfb64_encrypt 780 | ||
774 | des_cfb_encrypt 781 | ||
775 | des_decrypt3 782 | ||
776 | des_ecb3_encrypt 783 | ||
777 | des_ecb_encrypt 784 | ||
778 | des_ede3_cbc_encrypt 785 | ||
779 | des_ede3_cfb64_encrypt 786 | ||
780 | des_ede3_ofb64_encrypt 787 | ||
781 | des_enc_read 788 | ||
782 | des_enc_write 789 | ||
783 | des_encrypt 790 | ||
784 | des_encrypt2 791 | ||
785 | des_encrypt3 792 | ||
786 | des_fcrypt 793 | ||
787 | des_is_weak_key 794 | ||
788 | des_key_sched 795 | ||
789 | des_ncbc_encrypt 796 | ||
790 | des_ofb64_encrypt 797 | ||
791 | des_ofb_encrypt 798 | ||
792 | des_options 799 | ||
793 | des_pcbc_encrypt 800 | ||
794 | des_quad_cksum 801 | ||
795 | des_random_key 802 | ||
796 | des_random_seed 803 | ||
797 | des_read_2passwords 804 | ||
798 | des_read_password 805 | ||
799 | des_read_pw 806 | ||
800 | des_read_pw_string 807 | ||
801 | des_set_key 808 | ||
802 | des_set_odd_parity 809 | ||
803 | des_string_to_2keys 810 | ||
804 | des_string_to_key 811 | ||
805 | des_xcbc_encrypt 812 | ||
806 | des_xwhite_in2out 813 | ||
807 | fcrypt_body 814 | ||
808 | i2a_ASN1_INTEGER 815 | ||
809 | i2a_ASN1_OBJECT 816 | ||
810 | i2a_ASN1_STRING 817 | ||
811 | i2d_ASN1_BIT_STRING 818 | ||
812 | i2d_ASN1_BOOLEAN 819 | ||
813 | i2d_ASN1_HEADER 820 | ||
814 | i2d_ASN1_IA5STRING 821 | ||
815 | i2d_ASN1_INTEGER 822 | ||
816 | i2d_ASN1_OBJECT 823 | ||
817 | i2d_ASN1_OCTET_STRING 824 | ||
818 | i2d_ASN1_PRINTABLE 825 | ||
819 | i2d_ASN1_SET 826 | ||
820 | i2d_ASN1_TYPE 827 | ||
821 | i2d_ASN1_UTCTIME 828 | ||
822 | i2d_ASN1_bytes 829 | ||
823 | i2d_DHparams 830 | ||
824 | i2d_DSAPrivateKey 831 | ||
825 | i2d_DSAPrivateKey_bio 832 | ||
826 | i2d_DSAPrivateKey_fp 833 | ||
827 | i2d_DSAPublicKey 834 | ||
828 | i2d_DSAparams 835 | ||
829 | i2d_NETSCAPE_SPKAC 836 | ||
830 | i2d_NETSCAPE_SPKI 837 | ||
831 | i2d_Netscape_RSA 838 | ||
832 | i2d_PKCS7 839 | ||
833 | i2d_PKCS7_DIGEST 840 | ||
834 | i2d_PKCS7_ENCRYPT 841 | ||
835 | i2d_PKCS7_ENC_CONTENT 842 | ||
836 | i2d_PKCS7_ENVELOPE 843 | ||
837 | i2d_PKCS7_ISSUER_AND_SERIAL 844 | ||
838 | i2d_PKCS7_RECIP_INFO 845 | ||
839 | i2d_PKCS7_SIGNED 846 | ||
840 | i2d_PKCS7_SIGNER_INFO 847 | ||
841 | i2d_PKCS7_SIGN_ENVELOPE 848 | ||
842 | i2d_PKCS7_bio 849 | ||
843 | i2d_PKCS7_fp 850 | ||
844 | i2d_PrivateKey 851 | ||
845 | i2d_PublicKey 852 | ||
846 | i2d_RSAPrivateKey 853 | ||
847 | i2d_RSAPrivateKey_bio 854 | ||
848 | i2d_RSAPrivateKey_fp 855 | ||
849 | i2d_RSAPublicKey 856 | ||
850 | i2d_X509 857 | ||
851 | i2d_X509_ALGOR 858 | ||
852 | i2d_X509_ATTRIBUTE 859 | ||
853 | i2d_X509_CINF 860 | ||
854 | i2d_X509_CRL 861 | ||
855 | i2d_X509_CRL_INFO 862 | ||
856 | i2d_X509_CRL_bio 863 | ||
857 | i2d_X509_CRL_fp 864 | ||
858 | i2d_X509_EXTENSION 865 | ||
859 | i2d_X509_NAME 866 | ||
860 | i2d_X509_NAME_ENTRY 867 | ||
861 | i2d_X509_PKEY 868 | ||
862 | i2d_X509_PUBKEY 869 | ||
863 | i2d_X509_REQ 870 | ||
864 | i2d_X509_REQ_INFO 871 | ||
865 | i2d_X509_REQ_bio 872 | ||
866 | i2d_X509_REQ_fp 873 | ||
867 | i2d_X509_REVOKED 874 | ||
868 | i2d_X509_SIG 875 | ||
869 | i2d_X509_VAL 876 | ||
870 | i2d_X509_bio 877 | ||
871 | i2d_X509_fp 878 | ||
872 | idea_cbc_encrypt 879 | ||
873 | idea_cfb64_encrypt 880 | ||
874 | idea_ecb_encrypt 881 | ||
875 | idea_encrypt 882 | ||
876 | idea_ofb64_encrypt 883 | ||
877 | idea_options 884 | ||
878 | idea_set_decrypt_key 885 | ||
879 | idea_set_encrypt_key 886 | ||
880 | lh_delete 887 | ||
881 | lh_doall 888 | ||
882 | lh_doall_arg 889 | ||
883 | lh_free 890 | ||
884 | lh_insert 891 | ||
885 | lh_new 892 | ||
886 | lh_node_stats 893 | ||
887 | lh_node_stats_bio 894 | ||
888 | lh_node_usage_stats 895 | ||
889 | lh_node_usage_stats_bio 896 | ||
890 | lh_retrieve 897 | ||
891 | lh_stats 898 | ||
892 | lh_stats_bio 899 | ||
893 | lh_strhash 900 | ||
894 | sk_delete 901 | ||
895 | sk_delete_ptr 902 | ||
896 | sk_dup 903 | ||
897 | sk_find 904 | ||
898 | sk_free 905 | ||
899 | sk_insert 906 | ||
900 | sk_new 907 | ||
901 | sk_pop 908 | ||
902 | sk_pop_free 909 | ||
903 | sk_push 910 | ||
904 | sk_set_cmp_func 911 | ||
905 | sk_shift 912 | ||
906 | sk_unshift 913 | ||
907 | sk_zero 914 | ||
908 | BIO_f_nbio_test 915 | ||
909 | ASN1_TYPE_get 916 | ||
910 | ASN1_TYPE_set 917 | ||
911 | PKCS7_content_free 918 | ||
912 | ERR_load_PKCS7_strings 919 | ||
913 | X509_find_by_issuer_and_serial 920 | ||
914 | X509_find_by_subject 921 | ||
915 | PKCS7_ctrl 927 | ||
916 | PKCS7_set_type 928 | ||
917 | PKCS7_set_content 929 | ||
918 | PKCS7_SIGNER_INFO_set 930 | ||
919 | PKCS7_add_signer 931 | ||
920 | PKCS7_add_certificate 932 | ||
921 | PKCS7_add_crl 933 | ||
922 | PKCS7_content_new 934 | ||
923 | PKCS7_dataSign 935 | ||
924 | PKCS7_dataVerify 936 | ||
925 | PKCS7_dataInit 937 | ||
926 | PKCS7_add_signature 938 | ||
927 | PKCS7_cert_from_signer_info 939 | ||
928 | PKCS7_get_signer_info 940 | ||
929 | EVP_delete_alias 941 | ||
930 | EVP_mdc2 942 | ||
931 | PEM_read_bio_RSAPublicKey 943 | ||
932 | PEM_write_bio_RSAPublicKey 944 | ||
933 | d2i_RSAPublicKey_bio 945 | ||
934 | i2d_RSAPublicKey_bio 946 | ||
935 | PEM_read_RSAPublicKey 947 | ||
936 | PEM_write_RSAPublicKey 949 | ||
937 | d2i_RSAPublicKey_fp 952 | ||
938 | i2d_RSAPublicKey_fp 954 | ||
939 | BIO_copy_next_retry 955 | ||
940 | RSA_flags 956 | ||
941 | X509_STORE_add_crl 957 | ||
942 | X509_load_crl_file 958 | ||
943 | EVP_rc2_40_cbc 959 | ||
944 | EVP_rc4_40 960 | ||
945 | EVP_CIPHER_CTX_init 961 | ||
946 | HMAC 962 | ||
947 | HMAC_Init 963 | ||
948 | HMAC_Update 964 | ||
949 | HMAC_Final 965 | ||
950 | ERR_get_next_error_library 966 | ||
951 | EVP_PKEY_cmp_parameters 967 | ||
952 | HMAC_cleanup 968 | ||
953 | BIO_ptr_ctrl 969 | ||
954 | BIO_new_file_internal 970 | ||
955 | BIO_new_fp_internal 971 | ||
956 | BIO_s_file_internal 972 | ||
957 | BN_BLINDING_convert 973 | ||
958 | BN_BLINDING_invert 974 | ||
959 | BN_BLINDING_update 975 | ||
960 | RSA_blinding_on 977 | ||
961 | RSA_blinding_off 978 | ||
962 | i2t_ASN1_OBJECT 979 | ||
963 | BN_BLINDING_new 980 | ||
964 | BN_BLINDING_free 981 | ||
965 | EVP_cast5_cbc 983 | ||
966 | EVP_cast5_cfb 984 | ||
967 | EVP_cast5_ecb 985 | ||
968 | EVP_cast5_ofb 986 | ||
969 | BF_decrypt 987 | ||
970 | CAST_set_key 988 | ||
971 | CAST_encrypt 989 | ||
972 | CAST_decrypt 990 | ||
973 | CAST_ecb_encrypt 991 | ||
974 | CAST_cbc_encrypt 992 | ||
975 | CAST_cfb64_encrypt 993 | ||
976 | CAST_ofb64_encrypt 994 | ||
977 | RC2_decrypt 995 | ||
978 | OBJ_create_objects 997 | ||
979 | BN_exp 998 | ||
980 | BN_mul_word 999 | ||
981 | BN_sub_word 1000 | ||
982 | BN_dec2bn 1001 | ||
983 | BN_bn2dec 1002 | ||
984 | BIO_ghbn_ctrl 1003 | ||
985 | CRYPTO_free_ex_data 1004 | ||
986 | CRYPTO_get_ex_data 1005 | ||
987 | CRYPTO_set_ex_data 1007 | ||
988 | ERR_load_CRYPTO_strings 1009 | ||
989 | ERR_load_CRYPTOlib_strings 1009 | ||
990 | EVP_PKEY_bits 1010 | ||
991 | MD5_Transform 1011 | ||
992 | SHA1_Transform 1012 | ||
993 | SHA_Transform 1013 | ||
994 | X509_STORE_CTX_get_chain 1014 | ||
995 | X509_STORE_CTX_get_current_cert 1015 | ||
996 | X509_STORE_CTX_get_error 1016 | ||
997 | X509_STORE_CTX_get_error_depth 1017 | ||
998 | X509_STORE_CTX_get_ex_data 1018 | ||
999 | X509_STORE_CTX_set_cert 1020 | ||
1000 | X509_STORE_CTX_set_chain 1021 | ||
1001 | X509_STORE_CTX_set_error 1022 | ||
1002 | X509_STORE_CTX_set_ex_data 1023 | ||
1003 | CRYPTO_dup_ex_data 1025 | ||
1004 | CRYPTO_get_new_lockid 1026 | ||
1005 | CRYPTO_new_ex_data 1027 | ||
1006 | RSA_set_ex_data 1028 | ||
1007 | RSA_get_ex_data 1029 | ||
1008 | RSA_get_ex_new_index 1030 | ||
1009 | RSA_padding_add_PKCS1_type_1 1031 | ||
1010 | RSA_padding_add_PKCS1_type_2 1032 | ||
1011 | RSA_padding_add_SSLv23 1033 | ||
1012 | RSA_padding_add_none 1034 | ||
1013 | RSA_padding_check_PKCS1_type_1 1035 | ||
1014 | RSA_padding_check_PKCS1_type_2 1036 | ||
1015 | RSA_padding_check_SSLv23 1037 | ||
1016 | RSA_padding_check_none 1038 | ||
1017 | bn_add_words 1039 | ||
1018 | d2i_Netscape_RSA_2 1040 | ||
1019 | CRYPTO_get_ex_new_index 1041 | ||
1020 | RIPEMD160_Init 1042 | ||
1021 | RIPEMD160_Update 1043 | ||
1022 | RIPEMD160_Final 1044 | ||
1023 | RIPEMD160 1045 | ||
1024 | RIPEMD160_Transform 1046 | ||
1025 | RC5_32_set_key 1047 | ||
1026 | RC5_32_ecb_encrypt 1048 | ||
1027 | RC5_32_encrypt 1049 | ||
1028 | RC5_32_decrypt 1050 | ||
1029 | RC5_32_cbc_encrypt 1051 | ||
1030 | RC5_32_cfb64_encrypt 1052 | ||
1031 | RC5_32_ofb64_encrypt 1053 | ||
1032 | BN_bn2mpi 1058 | ||
1033 | BN_mpi2bn 1059 | ||
1034 | ASN1_BIT_STRING_get_bit 1060 | ||
1035 | ASN1_BIT_STRING_set_bit 1061 | ||
1036 | BIO_get_ex_data 1062 | ||
1037 | BIO_get_ex_new_index 1063 | ||
1038 | BIO_set_ex_data 1064 | ||
1039 | X509_STORE_CTX_get_ex_new_index 1065 | ||
1040 | X509v3_get_key_usage 1066 | ||
1041 | X509v3_set_key_usage 1067 | ||
1042 | a2i_X509v3_key_usage 1068 | ||
1043 | i2a_X509v3_key_usage 1069 | ||
1044 | EVP_PKEY_decrypt 1070 | ||
1045 | EVP_PKEY_encrypt 1071 | ||
1046 | PKCS7_RECIP_INFO_set 1072 | ||
1047 | PKCS7_add_recipient 1073 | ||
1048 | PKCS7_add_recipient_info 1074 | ||
1049 | PKCS7_set_cipher 1075 | ||
1050 | ASN1_TYPE_get_int_octetstring 1076 | ||
1051 | ASN1_TYPE_get_octetstring 1077 | ||
1052 | ASN1_TYPE_set_int_octetstring 1078 | ||
1053 | ASN1_TYPE_set_octetstring 1079 | ||
1054 | ASN1_UTCTIME_set_string 1080 | ||
1055 | ERR_add_error_data 1081 | ||
1056 | ERR_set_error_data 1082 | ||
1057 | EVP_CIPHER_asn1_to_param 1083 | ||
1058 | EVP_CIPHER_param_to_asn1 1084 | ||
1059 | EVP_CIPHER_get_asn1_iv 1085 | ||
1060 | EVP_CIPHER_set_asn1_iv 1086 | ||
1061 | EVP_rc5_32_12_16_cbc 1087 | ||
1062 | EVP_rc5_32_12_16_cfb 1088 | ||
1063 | EVP_rc5_32_12_16_ecb 1089 | ||
1064 | EVP_rc5_32_12_16_ofb 1090 | ||
1065 | asn1_add_error 1091 | ||
diff --git a/src/lib/libcrypto/util/mk1mf.pl b/src/lib/libcrypto/util/mk1mf.pl new file mode 100644 index 0000000000..149a0f4f80 --- /dev/null +++ b/src/lib/libcrypto/util/mk1mf.pl | |||
@@ -0,0 +1,793 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # A bit of an evil hack but it post processes the file ../MINFO which | ||
3 | # is generated by `make files` in the top directory. | ||
4 | # This script outputs one mega makefile that has no shell stuff or any | ||
5 | # funny stuff | ||
6 | # | ||
7 | |||
8 | $INSTALLTOP="/usr/local/ssl"; | ||
9 | |||
10 | $ssl_version="0.8.2"; | ||
11 | |||
12 | $infile="MINFO"; | ||
13 | |||
14 | %ops=( | ||
15 | "VC-WIN32", "Microsoft Visual C++ 4.[01] - Windows NT [34].x", | ||
16 | "VC-W31-16", "Microsoft Visual C++ 1.52 - Windows 3.1 - 286", | ||
17 | "VC-WIN16", "Alias for VC-W31-32", | ||
18 | "VC-W31-32", "Microsoft Visual C++ 1.52 - Windows 3.1 - 386+", | ||
19 | "VC-MSDOS","Microsoft Visual C++ 1.52 - MSDOS", | ||
20 | "BC-NT", "Borland C++ 4.5 - Windows NT - PROBABLY NOT WORKING", | ||
21 | "BC-W31", "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING", | ||
22 | "BC-MSDOS","Borland C++ 4.5 - MSDOS", | ||
23 | "linux-elf","Linux elf", | ||
24 | "FreeBSD","FreeBSD distribution", | ||
25 | "default","cc under unix", | ||
26 | ); | ||
27 | |||
28 | $type=""; | ||
29 | foreach (@ARGV) | ||
30 | { | ||
31 | if (/^no-rc2$/) { $no_rc2=1; } | ||
32 | elsif (/^no-rc4$/) { $no_rc4=1; } | ||
33 | elsif (/^no-rc5$/) { $no_rc5=1; } | ||
34 | elsif (/^no-idea$/) { $no_idea=1; } | ||
35 | elsif (/^no-des$/) { $no_des=1; } | ||
36 | elsif (/^no-bf$/) { $no_bf=1; } | ||
37 | elsif (/^no-cast$/) { $no_cast=1; } | ||
38 | elsif (/^no-md2$/) { $no_md2=1; } | ||
39 | elsif (/^no-md5$/) { $no_md5=1; } | ||
40 | elsif (/^no-sha$/) { $no_sha=1; } | ||
41 | elsif (/^no-sha1$/) { $no_sha1=1; } | ||
42 | elsif (/^no-rmd160$/) { $no_rmd160=1; } | ||
43 | elsif (/^no-mdc2$/) { $no_mdc2=1; } | ||
44 | elsif (/^no-patents$/) { $no_rc2=$no_rc4=$no_rc5=$no_idea=$no_rsa=1; } | ||
45 | elsif (/^no-rsa$/) { $no_rsa=1; } | ||
46 | elsif (/^no-dsa$/) { $no_dsa=1; } | ||
47 | elsif (/^no-dh$/) { $no_dh=1; } | ||
48 | elsif (/^no-asm$/) { $no_asm=1; } | ||
49 | elsif (/^no-ssl2$/) { $no_ssl2=1; } | ||
50 | elsif (/^no-ssl3$/) { $no_ssl3=1; } | ||
51 | elsif (/^no-err$/) { $no_err=1; } | ||
52 | elsif (/^no-sock$/) { $no_sock=1; } | ||
53 | |||
54 | elsif (/^just-ssl$/) { $no_rc2=$no_idea=$no_des=$no_bf=$no_cast=1; | ||
55 | $no_md2=$no_sha=$no_mdc2=$no_dsa=$no_dh=1; | ||
56 | $no_ssl2=$no_err=1; } | ||
57 | |||
58 | elsif (/^rsaref$/) { $rsaref=1; } | ||
59 | elsif (/^gcc$/) { $gcc=1; } | ||
60 | elsif (/^debug$/) { $debug=1; } | ||
61 | elsif (/^shlib$/) { $shlib=1; } | ||
62 | elsif (/^dll$/) { $shlib=1; } | ||
63 | elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; } | ||
64 | elsif (/^-[lL].*$/) { $l_flags.="$_ "; } | ||
65 | elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/) | ||
66 | { $c_flags.="$_ "; } | ||
67 | else | ||
68 | { | ||
69 | if (!defined($ops{$_})) | ||
70 | { | ||
71 | print STDERR "unknown option - $_\n"; | ||
72 | print STDERR "usage: perl mk1mf.pl [system] [options]\n"; | ||
73 | print STDERR "\nwhere [system] can be one of the following\n"; | ||
74 | foreach $i (sort keys %ops) | ||
75 | { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; } | ||
76 | print STDERR <<"EOF"; | ||
77 | and [options] can be one of | ||
78 | no-md2 no-md5 no-sha no-sha1 no-mdc2 no-rmd160 - Skip this digest | ||
79 | no-rc2 no-rc4 no-idea no-des no-bf no-cast - Skip this symetric cipher | ||
80 | no-rc5 | ||
81 | no-rsa no-dsa no-dh - Skip this public key cipher | ||
82 | no-ssl2 no-ssl3 - Skip this version of SSL | ||
83 | just-ssl - remove all non-ssl keys/digest | ||
84 | no-asm - No x86 asm | ||
85 | no-socks - No socket code | ||
86 | no-err - No error strings | ||
87 | dll/shlib - Build shared libraries (MS) | ||
88 | debug - Debug build | ||
89 | gcc - Use Gcc (unix) | ||
90 | rsaref - Build to require RSAref | ||
91 | |||
92 | Values that can be set | ||
93 | TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler | ||
94 | |||
95 | -L<ex_lib_path> -l<ex_lib> - extra library flags (unix) | ||
96 | -<ex_cc_flags> - extra 'cc' flags, | ||
97 | added (MS), or replace (unix) | ||
98 | EOF | ||
99 | exit(1); | ||
100 | } | ||
101 | $type=$_; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | $no_mdc2=1 if ($no_des); | ||
106 | |||
107 | $no_ssl3=1 if ($no_md5 || $no_sha1); | ||
108 | $no_ssl3=1 if ($no_rsa && $no_dh); | ||
109 | |||
110 | $no_ssl2=1 if ($no_md5 || $no_rsa); | ||
111 | $no_ssl2=1 if ($no_rsa); | ||
112 | |||
113 | $out_def="out"; | ||
114 | $inc_def="outinc"; | ||
115 | $tmp_def="tmp"; | ||
116 | |||
117 | |||
118 | ($ssl,$crypto)=("ssl","crypto"); | ||
119 | $RSAglue="RSAglue"; | ||
120 | $ranlib="echo ranlib"; | ||
121 | |||
122 | $cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc'; | ||
123 | $src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.'; | ||
124 | $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:''; | ||
125 | |||
126 | # $bin_dir.=$o causes a core dump on my sparc :-( | ||
127 | |||
128 | push(@INC,"util/pl","pl"); | ||
129 | if ($type eq "VC-MSDOS") | ||
130 | { | ||
131 | $asmbits=16; | ||
132 | $msdos=1; | ||
133 | require 'VC-16.pl'; | ||
134 | } | ||
135 | elsif ($type eq "VC-W31-16") | ||
136 | { | ||
137 | $asmbits=16; | ||
138 | $msdos=1; $win16=1; | ||
139 | require 'VC-16.pl'; | ||
140 | } | ||
141 | elsif (($type eq "VC-W31-32") || ($type eq "VC-WIN16")) | ||
142 | { | ||
143 | $asmbits=32; | ||
144 | $msdos=1; $win16=1; | ||
145 | require 'VC-16.pl'; | ||
146 | } | ||
147 | elsif (($type eq "VC-WIN32") || ($type eq "VC-NT")) | ||
148 | { | ||
149 | require 'VC-32.pl'; | ||
150 | } | ||
151 | elsif ($type eq "BC-NT") | ||
152 | { | ||
153 | $bc=1; | ||
154 | require 'BC-32.pl'; | ||
155 | } | ||
156 | elsif ($type eq "BC-W31") | ||
157 | { | ||
158 | $bc=1; | ||
159 | $msdos=1; $w16=1; | ||
160 | require 'BC-16.pl'; | ||
161 | } | ||
162 | elsif ($type eq "BC-Q16") | ||
163 | { | ||
164 | $msdos=1; $w16=1; $shlib=0; $qw=1; | ||
165 | require 'BC-16.pl'; | ||
166 | } | ||
167 | elsif ($type eq "BC-MSDOS") | ||
168 | { | ||
169 | $asmbits=16; | ||
170 | $msdos=1; | ||
171 | require 'BC-16.pl'; | ||
172 | } | ||
173 | elsif ($type eq "FreeBSD") | ||
174 | { | ||
175 | require 'unix.pl'; | ||
176 | $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer'; | ||
177 | } | ||
178 | elsif ($type eq "linux-elf") | ||
179 | { | ||
180 | require "unix.pl"; | ||
181 | require "linux.pl"; | ||
182 | $unix=1; | ||
183 | } | ||
184 | else | ||
185 | { | ||
186 | require "unix.pl"; | ||
187 | |||
188 | $unix=1; | ||
189 | $cflags.=' -DTERMIO'; | ||
190 | } | ||
191 | |||
192 | $out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":""); | ||
193 | $tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":""); | ||
194 | $inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def; | ||
195 | |||
196 | $bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq '')); | ||
197 | |||
198 | $cflags.=" -DNO_IDEA" if $no_idea; | ||
199 | $cflags.=" -DNO_RC2" if $no_rc2; | ||
200 | $cflags.=" -DNO_RC4" if $no_rc4; | ||
201 | $cflags.=" -DNO_RC5" if $no_rc5; | ||
202 | $cflags.=" -DNO_MD2" if $no_md2; | ||
203 | $cflags.=" -DNO_MD5" if $no_md5; | ||
204 | $cflags.=" -DNO_SHA" if $no_sha; | ||
205 | $cflags.=" -DNO_SHA1" if $no_sha1; | ||
206 | $cflags.=" -DNO_RMD160" if $no_rmd160; | ||
207 | $cflags.=" -DNO_MDC2" if $no_mdc2; | ||
208 | $cflags.=" -DNO_BLOWFISH" if $no_bf; | ||
209 | $cflags.=" -DNO_CAST" if $no_cast; | ||
210 | $cflags.=" -DNO_DES" if $no_des; | ||
211 | $cflags.=" -DNO_RSA" if $no_rsa; | ||
212 | $cflags.=" -DNO_DSA" if $no_dsa; | ||
213 | $cflags.=" -DNO_DH" if $no_dh; | ||
214 | $cflags.=" -DNO_SOCK" if $no_sock; | ||
215 | $cflags.=" -DNO_SSL2" if $no_ssl2; | ||
216 | $cflags.=" -DNO_SSL3" if $no_ssl3; | ||
217 | $cflags.=" -DNO_ERR" if $no_err; | ||
218 | $cflags.=" -DRSAref" if $rsaref ne ""; | ||
219 | |||
220 | if ($unix) | ||
221 | { $cflags="$c_flags" if ($c_flags ne ""); } | ||
222 | else { $cflags="$c_flags$cflags" if ($c_flags ne ""); } | ||
223 | |||
224 | $ex_libs="$l_flags$ex_libs" if ($l_flags ne ""); | ||
225 | |||
226 | if ($ranlib ne "") | ||
227 | { | ||
228 | $ranlib="\$(SRC_D)$o$ranlib"; | ||
229 | } | ||
230 | |||
231 | if ($msdos) | ||
232 | { | ||
233 | $banner ="\t\@echo Make sure you have run 'perl Configure $type' in the\n"; | ||
234 | $banner.="\t\@echo top level directory, if you don't have perl, you will\n"; | ||
235 | $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n"; | ||
236 | $banner.="\t\@echo documentation for details.\n"; | ||
237 | } | ||
238 | |||
239 | # have to do this to allow $(CC) under unix | ||
240 | $link="$bin_dir$link" if ($link !~ /^\$/); | ||
241 | |||
242 | $INSTALLTOP =~ s|/|$o|g; | ||
243 | |||
244 | $defs= <<"EOF"; | ||
245 | # This makefile has been automatically generated from the SSLeay distribution. | ||
246 | # This single makefile will build the complete SSLeay distribution and | ||
247 | # by default leave the 'intertesting' output files in .${o}out and the stuff | ||
248 | # that needs deleting in .${o}tmp. | ||
249 | # The file was generated by running 'make makefile.one', which | ||
250 | # does a 'make files', which writes all the environment variables from all | ||
251 | # the makefiles to the file call MINFO. This file is used by | ||
252 | # util${o}mk1mf.pl to generate makefile.one. | ||
253 | # The 'makefile per directory' system suites me when developing this | ||
254 | # library and also so I can 'distribute' indervidual library sections. | ||
255 | # The one monster makefile better suits building in non-unix | ||
256 | # environments. | ||
257 | |||
258 | INSTALLTOP=$INSTALLTOP | ||
259 | |||
260 | # Set your compiler options | ||
261 | CC=$bin_dir${cc} | ||
262 | CFLAG=$cflags | ||
263 | APP_CFLAG=$app_cflag | ||
264 | LIB_CFLAG=$lib_cflag | ||
265 | SHLIB_CFLAG=$shl_cflag | ||
266 | APP_EX_OBJ=$app_ex_obj | ||
267 | SHLIB_EX_OBJ=$shlib_ex_obj | ||
268 | # add extra libraries to this define, for solaris -lsocket -lnsl would | ||
269 | # be added | ||
270 | EX_LIBS=$ex_libs | ||
271 | |||
272 | # The SSLeay directory | ||
273 | SRC_D=$src_dir | ||
274 | |||
275 | LINK=$link | ||
276 | LFLAGS=$lflags | ||
277 | |||
278 | BN_MULW_OBJ=$bn_mulw_obj | ||
279 | BN_MULW_SRC=$bn_mulw_src | ||
280 | DES_ENC_OBJ=$des_enc_obj | ||
281 | DES_ENC_SRC=$des_enc_src | ||
282 | DES_CRYPT_OBJ=$des_crypt_obj | ||
283 | DES_CRYPT_SRC=$des_crypt_src | ||
284 | BF_ENC_OBJ=$bf_enc_obj | ||
285 | BF_ENC_SRC=$bf_enc_src | ||
286 | CAST_ENC_OBJ=$cast_enc_obj | ||
287 | CAST_ENC_SRC=$cast_enc_src | ||
288 | RC4_ENC_OBJ=$rc4_enc_obj | ||
289 | RC4_ENC_SRC=$rc4_enc_src | ||
290 | RC5_ENC_OBJ=$rc5_enc_obj | ||
291 | RC5_ENC_SRC=$rc5_enc_src | ||
292 | MD5_ASM_OBJ=$md5_asm_obj | ||
293 | MD5_ASM_SRC=$md5_asm_src | ||
294 | SHA1_ASM_OBJ=$sha1_asm_obj | ||
295 | SHA1_ASM_SRC=$sha1_asm_src | ||
296 | RMD160_ASM_OBJ=$rmd160_asm_obj | ||
297 | RMD160_ASM_SRC=$rmd160_asm_src | ||
298 | |||
299 | # The output directory for everything intersting | ||
300 | OUT_D=$out_dir | ||
301 | # The output directory for all the temporary muck | ||
302 | TMP_D=$tmp_dir | ||
303 | # The output directory for the header files | ||
304 | INC_D=$inc_dir | ||
305 | |||
306 | CP=$cp | ||
307 | RM=$rm | ||
308 | RANLIB=$ranlib | ||
309 | MKDIR=mkdir | ||
310 | MKLIB=$bin_dir$mklib | ||
311 | MLFLAGS=$mlflags | ||
312 | ASM=$bin_dir$asm | ||
313 | |||
314 | ###################################################### | ||
315 | # You should not need to touch anything below this point | ||
316 | ###################################################### | ||
317 | |||
318 | E_EXE=ssleay | ||
319 | SSL=$ssl | ||
320 | CRYPTO=$crypto | ||
321 | RSAGLUE=$RSAglue | ||
322 | |||
323 | # BIN_D - Binary output directory | ||
324 | # TEST_D - Binary test file output directory | ||
325 | # LIB_D - library output directory | ||
326 | BIN_D=\$(OUT_D) | ||
327 | TEST_D=\$(OUT_D) | ||
328 | LIB_D=\$(OUT_D) | ||
329 | |||
330 | # INCL_D - local library directory | ||
331 | # OBJ_D - temp object file directory | ||
332 | OBJ_D=\$(TMP_D) | ||
333 | INCL_D=\$(TMP_D) | ||
334 | |||
335 | O_SSL= \$(LIB_D)$o$plib\$(SSL)$shlibp | ||
336 | O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp | ||
337 | O_RSAGLUE= \$(LIB_D)$o$plib\$(RSAGLUE)$libp | ||
338 | SO_SSL= $plib\$(SSL)$so_shlibp | ||
339 | SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp | ||
340 | L_SSL= \$(LIB_D)$o\$(SSL)$libp | ||
341 | L_CRYPTO= \$(LIB_D)$o\$(CRYPTO)$libp | ||
342 | |||
343 | L_LIBS= \$(L_SSL) \$(L_CRYPTO) | ||
344 | #L_LIBS= \$(O_SSL) \$(O_RSAGLUE) -lrsaref \$(O_CRYPTO) | ||
345 | |||
346 | ###################################################### | ||
347 | # Don't touch anything below this point | ||
348 | ###################################################### | ||
349 | |||
350 | INC=-I\$(INC_D) -I\$(INCL_D) | ||
351 | APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG) | ||
352 | LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) | ||
353 | SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG) | ||
354 | LIBS_DEP=\$(O_CRYPTO) \$(O_RSAGLUE) \$(O_SSL) | ||
355 | |||
356 | ############################################# | ||
357 | EOF | ||
358 | |||
359 | $rules=<<"EOF"; | ||
360 | all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INC_D) headers lib exe | ||
361 | |||
362 | banner: | ||
363 | $banner | ||
364 | |||
365 | \$(TMP_D): | ||
366 | \$(MKDIR) \$(TMP_D) | ||
367 | |||
368 | \$(BIN_D): | ||
369 | \$(MKDIR) \$(BIN_D) | ||
370 | |||
371 | \$(TEST_D): | ||
372 | \$(MKDIR) \$(TEST_D) | ||
373 | |||
374 | \$(LIB_D): | ||
375 | \$(MKDIR) \$(LIB_D) | ||
376 | |||
377 | \$(INC_D): | ||
378 | \$(MKDIR) \$(INC_D) | ||
379 | |||
380 | headers: \$(HEADER) \$(EXHEADER) | ||
381 | |||
382 | lib: \$(LIBS_DEP) | ||
383 | |||
384 | exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep | ||
385 | |||
386 | install: | ||
387 | \$(MKDIR) \$(INSTALLTOP) | ||
388 | \$(MKDIR) \$(INSTALLTOP)${o}bin | ||
389 | \$(MKDIR) \$(INSTALLTOP)${o}include | ||
390 | \$(MKDIR) \$(INSTALLTOP)${o}lib | ||
391 | \$(CP) \$(INC_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include | ||
392 | \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin | ||
393 | \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib | ||
394 | \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib | ||
395 | |||
396 | clean: | ||
397 | \$(RM) \$(TMP_D)$o*.* | ||
398 | |||
399 | vclean: | ||
400 | \$(RM) \$(TMP_D)$o*.* | ||
401 | \$(RM) \$(OUT_D)$o*.* | ||
402 | |||
403 | EOF | ||
404 | |||
405 | ############################################# | ||
406 | # We parse in input file and 'store' info for later printing. | ||
407 | open(IN,"<$infile") || die "unable to open $infile:$!\n"; | ||
408 | $_=<IN>; | ||
409 | for (;;) | ||
410 | { | ||
411 | chop; | ||
412 | |||
413 | ($key,$val)=/^([^=]+)=(.*)/; | ||
414 | if ($key eq "RELATIVE_DIRECTORY") | ||
415 | { | ||
416 | if ($lib ne "") | ||
417 | { | ||
418 | $uc=$lib; | ||
419 | $uc =~ s/^lib(.*)\.a/$1/; | ||
420 | $uc =~ tr/a-z/A-Z/; | ||
421 | $lib_nam{$uc}=$uc; | ||
422 | $lib_obj{$uc}.=$libobj." "; | ||
423 | } | ||
424 | last if ($val eq "FINISHED"); | ||
425 | $lib=""; | ||
426 | $libobj=""; | ||
427 | $dir=$val; | ||
428 | } | ||
429 | |||
430 | if ($key eq "TEST") | ||
431 | { $test.=&var_add($dir,$val); } | ||
432 | |||
433 | if (($key eq "PROGS") || ($key eq "E_OBJ")) | ||
434 | { $e_exe.=&var_add($dir,$val); } | ||
435 | |||
436 | if ($key eq "LIB") | ||
437 | { | ||
438 | $lib=$val; | ||
439 | $lib =~ s/^.*\/([^\/]+)$/$1/; | ||
440 | } | ||
441 | |||
442 | if ($key eq "EXHEADER") | ||
443 | { $exheader.=&var_add($dir,$val); } | ||
444 | |||
445 | if ($key eq "HEADER") | ||
446 | { $header.=&var_add($dir,$val); } | ||
447 | |||
448 | if ($key eq "LIBOBJ") | ||
449 | { $libobj=&var_add($dir,$val); } | ||
450 | |||
451 | if (!($_=<IN>)) | ||
452 | { $_="RELATIVE_DIRECTORY=FINISHED\n"; } | ||
453 | } | ||
454 | close(IN); | ||
455 | |||
456 | # Strip of trailing ' ' | ||
457 | foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); } | ||
458 | $test=&clean_up_ws($test); | ||
459 | $e_exe=&clean_up_ws($e_exe); | ||
460 | $exheader=&clean_up_ws($exheader); | ||
461 | $header=&clean_up_ws($header); | ||
462 | |||
463 | # First we strip the exheaders from the headers list | ||
464 | foreach (split(/\s+/,$exheader)){ $h{$_}=1; } | ||
465 | foreach (split(/\s+/,$header)) { $h.=$_." " unless $h{$_}; } | ||
466 | chop($h); $header=$h; | ||
467 | |||
468 | $defs.=&do_defs("HEADER",$header,"\$(INCL_D)",".h"); | ||
469 | $rules.=&do_copy_rule("\$(INCL_D)",$header,".h"); | ||
470 | |||
471 | $defs.=&do_defs("EXHEADER",$exheader,"\$(INC_D)",".h"); | ||
472 | $rules.=&do_copy_rule("\$(INC_D)",$exheader,".h"); | ||
473 | |||
474 | $defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj); | ||
475 | $rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)"); | ||
476 | |||
477 | $defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj); | ||
478 | $rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)'); | ||
479 | |||
480 | foreach (values %lib_nam) | ||
481 | { | ||
482 | $lib_obj=$lib_obj{$_}; | ||
483 | local($slib)=$shlib; | ||
484 | |||
485 | $slib=0 if ($_ eq "RSAGLUE"); | ||
486 | |||
487 | if (($_ eq "SSL") && $no_ssl2 && $no_ssl3) | ||
488 | { | ||
489 | $rules.="\$(O_SSL):\n\n"; | ||
490 | next; | ||
491 | } | ||
492 | |||
493 | if (($_ eq "RSAGLUE") && $no_rsa) | ||
494 | { | ||
495 | $rules.="\$(O_RSAGLUE):\n\n"; | ||
496 | next; | ||
497 | } | ||
498 | |||
499 | if (($bn_mulw_obj ne "") && ($_ eq "CRYPTO")) | ||
500 | { | ||
501 | $lib_obj =~ s/\s\S*\/bn_mulw\S*/ \$(BN_MULW_OBJ)/; | ||
502 | $rules.=&do_asm_rule($bn_mulw_obj,$bn_mulw_src); | ||
503 | } | ||
504 | if (($des_enc_obj ne "") && ($_ eq "CRYPTO")) | ||
505 | { | ||
506 | $lib_obj =~ s/\s\S*des_enc\S*/ \$(DES_ENC_OBJ)/; | ||
507 | $lib_obj =~ s/\s\S*\/fcrypt_b\S*\s*/ /; | ||
508 | $rules.=&do_asm_rule($des_enc_obj,$des_enc_src); | ||
509 | } | ||
510 | if (($bf_enc_obj ne "") && ($_ eq "CRYPTO")) | ||
511 | { | ||
512 | $lib_obj =~ s/\s\S*\/bf_enc\S*/ \$(BF_ENC_OBJ)/; | ||
513 | $rules.=&do_asm_rule($bf_enc_obj,$bf_enc_src); | ||
514 | } | ||
515 | if (($cast_enc_obj ne "") && ($_ eq "CRYPTO")) | ||
516 | { | ||
517 | $lib_obj =~ s/(\s\S*\/c_enc\S*)/ \$(CAST_ENC_OBJ)/; | ||
518 | $rules.=&do_asm_rule($cast_enc_obj,$cast_enc_src); | ||
519 | } | ||
520 | if (($rc4_enc_obj ne "") && ($_ eq "CRYPTO")) | ||
521 | { | ||
522 | $lib_obj =~ s/\s\S*\/rc4_enc\S*/ \$(RC4_ENC_OBJ)/; | ||
523 | $rules.=&do_asm_rule($rc4_enc_obj,$rc4_enc_src); | ||
524 | } | ||
525 | if (($rc5_enc_obj ne "") && ($_ eq "CRYPTO")) | ||
526 | { | ||
527 | $lib_obj =~ s/\s\S*\/rc5_enc\S*/ \$(RC5_ENC_OBJ)/; | ||
528 | $rules.=&do_asm_rule($rc5_enc_obj,$rc5_enc_src); | ||
529 | } | ||
530 | if (($md5_asm_obj ne "") && ($_ eq "CRYPTO")) | ||
531 | { | ||
532 | $lib_obj =~ s/\s(\S*\/md5_dgst\S*)/ $1 \$(MD5_ASM_OBJ)/; | ||
533 | $rules.=&do_asm_rule($md5_asm_obj,$md5_asm_src); | ||
534 | } | ||
535 | if (($sha1_asm_obj ne "") && ($_ eq "CRYPTO")) | ||
536 | { | ||
537 | $lib_obj =~ s/\s(\S*\/sha1dgst\S*)/ $1 \$(SHA1_ASM_OBJ)/; | ||
538 | $rules.=&do_asm_rule($sha1_asm_obj,$sha1_asm_src); | ||
539 | } | ||
540 | if (($rmd160_asm_obj ne "") && ($_ eq "CRYPTO")) | ||
541 | { | ||
542 | $lib_obj =~ s/\s(\S*\/rmd_dgst\S*)/ $1 \$(RMD160_ASM_OBJ)/; | ||
543 | $rules.=&do_asm_rule($rmd160_asm_obj,$rmd160_asm_src); | ||
544 | } | ||
545 | $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj); | ||
546 | $lib=($slib)?" \$(SHLIB_CFLAGS)":" \$(LIB_CFLAGS)"; | ||
547 | $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib); | ||
548 | } | ||
549 | |||
550 | $defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep); | ||
551 | foreach (split(/\s+/,$test)) | ||
552 | { | ||
553 | $t=&bname($_); | ||
554 | $tt="\$(OBJ_D)${o}$t${obj}"; | ||
555 | $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)"); | ||
556 | } | ||
557 | |||
558 | $rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)"); | ||
559 | $rules.= &do_lib_rule("\$(RSAGLUEOBJ)","\$(O_RSAGLUE)",$RSAglue,0,"") | ||
560 | unless $no_rsa; | ||
561 | $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)"); | ||
562 | |||
563 | $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)"); | ||
564 | |||
565 | print $defs; | ||
566 | print "###################################################################\n"; | ||
567 | print $rules; | ||
568 | |||
569 | ############################################### | ||
570 | # strip off any trailing .[och] and append the relative directory | ||
571 | # also remembering to do nothing if we are in one of the dropped | ||
572 | # directories | ||
573 | sub var_add | ||
574 | { | ||
575 | local($dir,$val)=@_; | ||
576 | local(@a,$_,$ret); | ||
577 | |||
578 | return("") if $no_idea && $dir =~ /\/idea/; | ||
579 | return("") if $no_rc2 && $dir =~ /\/rc2/; | ||
580 | return("") if $no_rc4 && $dir =~ /\/rc4/; | ||
581 | return("") if $no_rc5 && $dir =~ /\/rc5/; | ||
582 | return("") if $no_rsa && $dir =~ /\/rsa/; | ||
583 | return("") if $no_rsa && $dir =~ /^rsaref/; | ||
584 | return("") if $no_dsa && $dir =~ /\/dsa/; | ||
585 | return("") if $no_dh && $dir =~ /\/dh/; | ||
586 | if ($no_des && $dir =~ /\/des/) | ||
587 | { | ||
588 | if ($val =~ /read_pwd/) | ||
589 | { return("$dir/read_pwd "); } | ||
590 | else | ||
591 | { return(""); } | ||
592 | } | ||
593 | return("") if $no_mdc2 && $dir =~ /\/mdc2/; | ||
594 | return("") if $no_sock && $dir =~ /\/proxy/; | ||
595 | return("") if $no_bf && $dir =~ /\/bf/; | ||
596 | return("") if $no_cast && $dir =~ /\/cast/; | ||
597 | |||
598 | $val =~ s/^\s*(.*)\s*$/$1/; | ||
599 | @a=split(/\s+/,$val); | ||
600 | grep(s/\.[och]$//,@a); | ||
601 | |||
602 | @a=grep(!/^e_.*_3d$/,@a) if $no_des; | ||
603 | @a=grep(!/^e_.*_d$/,@a) if $no_des; | ||
604 | @a=grep(!/^e_.*_i$/,@a) if $no_idea; | ||
605 | @a=grep(!/^e_.*_r2$/,@a) if $no_rc2; | ||
606 | @a=grep(!/^e_.*_r5$/,@a) if $no_rc5; | ||
607 | @a=grep(!/^e_.*_bf$/,@a) if $no_bf; | ||
608 | @a=grep(!/^e_.*_c$/,@a) if $no_cast; | ||
609 | @a=grep(!/^e_rc4$/,@a) if $no_rc4; | ||
610 | |||
611 | @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2; | ||
612 | @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3; | ||
613 | |||
614 | @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock; | ||
615 | |||
616 | @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2; | ||
617 | @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5; | ||
618 | |||
619 | @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa; | ||
620 | @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa; | ||
621 | @a=grep(!/(^pem_seal$)/,@a) if $no_rsa; | ||
622 | |||
623 | @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa; | ||
624 | @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa; | ||
625 | |||
626 | @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4; | ||
627 | |||
628 | @a=grep(!/_dhp$/,@a) if $no_dh; | ||
629 | |||
630 | @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha; | ||
631 | @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1; | ||
632 | @a=grep(!/_mdc2$/,@a) if $no_mdc2; | ||
633 | |||
634 | @a=grep(!/(^rsa$)|(^genrsa$)|(^req$)|(^ca$)/,@a) if $no_rsa; | ||
635 | @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa; | ||
636 | @a=grep(!/^gendsa$/,@a) if $no_sha1; | ||
637 | @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh; | ||
638 | |||
639 | @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1; | ||
640 | |||
641 | grep($_="$dir/$_",@a); | ||
642 | @a=grep(!/(^|\/)s_/,@a) if $no_sock; | ||
643 | @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock; | ||
644 | $ret=join(' ',@a)." "; | ||
645 | return($ret); | ||
646 | } | ||
647 | |||
648 | # change things so that each 'token' is only separated by one space | ||
649 | sub clean_up_ws | ||
650 | { | ||
651 | local($w)=@_; | ||
652 | |||
653 | $w =~ s/^\s*(.*)\s*$/$1/; | ||
654 | $w =~ s/\s+/ /g; | ||
655 | return($w); | ||
656 | } | ||
657 | |||
658 | sub do_defs | ||
659 | { | ||
660 | local($var,$files,$location,$postfix)=@_; | ||
661 | local($_,$ret,$pf); | ||
662 | local(*OUT,$tmp,$t); | ||
663 | |||
664 | $files =~ s/\//$o/g if $o ne '/'; | ||
665 | $ret="$var="; | ||
666 | $n=1; | ||
667 | $Vars{$var}.=""; | ||
668 | foreach (split(/ /,$files)) | ||
669 | { | ||
670 | $orig=$_; | ||
671 | $_=&bname($_) unless /^\$/; | ||
672 | if ($n++ == 2) | ||
673 | { | ||
674 | $n=0; | ||
675 | $ret.="\\\n\t"; | ||
676 | } | ||
677 | if (($_ =~ /bss_file/) && ($postfix eq ".h")) | ||
678 | { $pf=".c"; } | ||
679 | else { $pf=$postfix; } | ||
680 | if ($_ =~ /BN_MULW/) { $t="$_ "; } | ||
681 | elsif ($_ =~ /DES_ENC/) { $t="$_ "; } | ||
682 | elsif ($_ =~ /BF_ENC/) { $t="$_ "; } | ||
683 | elsif ($_ =~ /CAST_ENC/){ $t="$_ "; } | ||
684 | elsif ($_ =~ /RC4_ENC/) { $t="$_ "; } | ||
685 | elsif ($_ =~ /RC5_ENC/) { $t="$_ "; } | ||
686 | elsif ($_ =~ /MD5_ASM/) { $t="$_ "; } | ||
687 | elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; } | ||
688 | elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; } | ||
689 | else { $t="$location${o}$_$pf "; } | ||
690 | |||
691 | $Vars{$var}.="$t "; | ||
692 | $ret.=$t; | ||
693 | } | ||
694 | chop($ret); | ||
695 | $ret.="\n\n"; | ||
696 | return($ret); | ||
697 | } | ||
698 | |||
699 | # return the name with the leading path removed | ||
700 | sub bname | ||
701 | { | ||
702 | local($ret)=@_; | ||
703 | $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/; | ||
704 | return($ret); | ||
705 | } | ||
706 | |||
707 | # do a rule for each file that says 'copy' to new direcory on change | ||
708 | sub do_copy_rule | ||
709 | { | ||
710 | local($to,$files,$p)=@_; | ||
711 | local($ret,$_,$n,$pp); | ||
712 | |||
713 | $files =~ s/\//$o/g if $o ne '/'; | ||
714 | foreach (split(/\s+/,$files)) | ||
715 | { | ||
716 | $n=&bname($_); | ||
717 | if ($n =~ /bss_file/) | ||
718 | { $pp=".c"; } | ||
719 | else { $pp=$p; } | ||
720 | $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \$(SRC_D)$o$_$pp $to${o}$n$pp\n\n"; | ||
721 | } | ||
722 | return($ret); | ||
723 | } | ||
724 | |||
725 | ############################################################## | ||
726 | # do a rule for each file that says 'compile' to new direcory | ||
727 | # compile the files in '$files' into $to | ||
728 | sub do_compile_rule | ||
729 | { | ||
730 | local($to,$files,$ex)=@_; | ||
731 | local($ret,$_,$n); | ||
732 | |||
733 | $files =~ s/\//$o/g if $o ne '/'; | ||
734 | foreach (split(/\s+/,$files)) | ||
735 | { | ||
736 | $n=&bname($_); | ||
737 | $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex) | ||
738 | } | ||
739 | return($ret); | ||
740 | } | ||
741 | |||
742 | ############################################################## | ||
743 | # do a rule for each file that says 'compile' to new direcory | ||
744 | sub cc_compile_target | ||
745 | { | ||
746 | local($target,$source,$ex_flags)=@_; | ||
747 | local($ret); | ||
748 | |||
749 | # EAY EAY | ||
750 | $ex_flags.=' -DCFLAGS="\"$(CC) $(CFLAG)\""' if ($source =~ /cversion/); | ||
751 | $target =~ s/\//$o/g if $o ne "/"; | ||
752 | $source =~ s/\//$o/g if $o ne "/"; | ||
753 | $ret ="$target: \$(SRC_D)$o$source\n\t"; | ||
754 | $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n"; | ||
755 | return($ret); | ||
756 | } | ||
757 | |||
758 | ############################################################## | ||
759 | sub do_asm_rule | ||
760 | { | ||
761 | local($target,$src)=@_; | ||
762 | local($ret,@s,@t,$i); | ||
763 | |||
764 | $target =~ s/\//$o/g if $o ne "/"; | ||
765 | $src =~ s/\//$o/g if $o ne "/"; | ||
766 | |||
767 | @s=split(/\s+/,$src); | ||
768 | @t=split(/\s+/,$target); | ||
769 | |||
770 | for ($i=0; $i<=$#s; $i++) | ||
771 | { | ||
772 | $ret.="$t[$i]: $s[$i]\n"; | ||
773 | $ret.="\t\$(ASM) $afile$t[$i] \$(SRC_D)$o$s[$i]\n\n"; | ||
774 | } | ||
775 | return($ret); | ||
776 | } | ||
777 | |||
778 | sub do_shlib_rule | ||
779 | { | ||
780 | local($n,$def)=@_; | ||
781 | local($ret,$nn); | ||
782 | local($t); | ||
783 | |||
784 | ($nn=$n) =~ tr/a-z/A-Z/; | ||
785 | $ret.="$n.dll: \$(${nn}OBJ)\n"; | ||
786 | if ($vc && $w32) | ||
787 | { | ||
788 | $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n \$(${nn}OBJ_F)\n<<\n"; | ||
789 | } | ||
790 | $ret.="\n"; | ||
791 | return($ret); | ||
792 | } | ||
793 | |||
diff --git a/src/lib/libcrypto/util/mkcerts.sh b/src/lib/libcrypto/util/mkcerts.sh new file mode 100644 index 0000000000..5f8a1dae73 --- /dev/null +++ b/src/lib/libcrypto/util/mkcerts.sh | |||
@@ -0,0 +1,220 @@ | |||
1 | #!bin/sh | ||
2 | |||
3 | # This script will re-make all the required certs. | ||
4 | # cd apps | ||
5 | # sh ../util/mkcerts.sh | ||
6 | # mv ca-cert.pem pca-cert.pem ../certs | ||
7 | # cd .. | ||
8 | # cat certs/*.pem >>apps/server.pem | ||
9 | # cat certs/*.pem >>apps/server2.pem | ||
10 | # SSLEAY=`pwd`/apps/ssleay; export SSLEAY | ||
11 | # sh tools/c_rehash certs | ||
12 | # | ||
13 | |||
14 | CAbits=1024 | ||
15 | SSLEAY="../apps/ssleay" | ||
16 | CONF="-config ../apps/ssleay.cnf" | ||
17 | |||
18 | # create pca request. | ||
19 | echo creating $CAbits bit PCA cert request | ||
20 | $SSLEAY req $CONF \ | ||
21 | -new -md5 -newkey $CAbits \ | ||
22 | -keyout pca-key.pem \ | ||
23 | -out pca-req.pem -nodes >/dev/null <<EOF | ||
24 | AU | ||
25 | Queensland | ||
26 | . | ||
27 | CryptSoft Pty Ltd | ||
28 | . | ||
29 | Test PCA (1024 bit) | ||
30 | |||
31 | |||
32 | |||
33 | EOF | ||
34 | |||
35 | if [ $? != 0 ]; then | ||
36 | echo problems generating PCA request | ||
37 | exit 1 | ||
38 | fi | ||
39 | |||
40 | #sign it. | ||
41 | echo | ||
42 | echo self signing PCA | ||
43 | $SSLEAY x509 -md5 -days 1461 \ | ||
44 | -req -signkey pca-key.pem \ | ||
45 | -CAcreateserial -CAserial pca-cert.srl \ | ||
46 | -in pca-req.pem -out pca-cert.pem | ||
47 | |||
48 | if [ $? != 0 ]; then | ||
49 | echo problems self signing PCA cert | ||
50 | exit 1 | ||
51 | fi | ||
52 | echo | ||
53 | |||
54 | # create ca request. | ||
55 | echo creating $CAbits bit CA cert request | ||
56 | $SSLEAY req $CONF \ | ||
57 | -new -md5 -newkey $CAbits \ | ||
58 | -keyout ca-key.pem \ | ||
59 | -out ca-req.pem -nodes >/dev/null <<EOF | ||
60 | AU | ||
61 | Queensland | ||
62 | . | ||
63 | CryptSoft Pty Ltd | ||
64 | . | ||
65 | Test CA (1024 bit) | ||
66 | |||
67 | |||
68 | |||
69 | EOF | ||
70 | |||
71 | if [ $? != 0 ]; then | ||
72 | echo problems generating CA request | ||
73 | exit 1 | ||
74 | fi | ||
75 | |||
76 | #sign it. | ||
77 | echo | ||
78 | echo signing CA | ||
79 | $SSLEAY x509 -md5 -days 1461 \ | ||
80 | -req \ | ||
81 | -CAcreateserial -CAserial pca-cert.srl \ | ||
82 | -CA pca-cert.pem -CAkey pca-key.pem \ | ||
83 | -in ca-req.pem -out ca-cert.pem | ||
84 | |||
85 | if [ $? != 0 ]; then | ||
86 | echo problems signing CA cert | ||
87 | exit 1 | ||
88 | fi | ||
89 | echo | ||
90 | |||
91 | # create server request. | ||
92 | echo creating 512 bit server cert request | ||
93 | $SSLEAY req $CONF \ | ||
94 | -new -md5 -newkey 512 \ | ||
95 | -keyout s512-key.pem \ | ||
96 | -out s512-req.pem -nodes >/dev/null <<EOF | ||
97 | AU | ||
98 | Queensland | ||
99 | . | ||
100 | CryptSoft Pty Ltd | ||
101 | . | ||
102 | Server test cert (512 bit) | ||
103 | |||
104 | |||
105 | |||
106 | EOF | ||
107 | |||
108 | if [ $? != 0 ]; then | ||
109 | echo problems generating 512 bit server cert request | ||
110 | exit 1 | ||
111 | fi | ||
112 | |||
113 | #sign it. | ||
114 | echo | ||
115 | echo signing 512 bit server cert | ||
116 | $SSLEAY x509 -md5 -days 365 \ | ||
117 | -req \ | ||
118 | -CAcreateserial -CAserial ca-cert.srl \ | ||
119 | -CA ca-cert.pem -CAkey ca-key.pem \ | ||
120 | -in s512-req.pem -out server.pem | ||
121 | |||
122 | if [ $? != 0 ]; then | ||
123 | echo problems signing 512 bit server cert | ||
124 | exit 1 | ||
125 | fi | ||
126 | echo | ||
127 | |||
128 | # create 1024 bit server request. | ||
129 | echo creating 1024 bit server cert request | ||
130 | $SSLEAY req $CONF \ | ||
131 | -new -md5 -newkey 1024 \ | ||
132 | -keyout s1024key.pem \ | ||
133 | -out s1024req.pem -nodes >/dev/null <<EOF | ||
134 | AU | ||
135 | Queensland | ||
136 | . | ||
137 | CryptSoft Pty Ltd | ||
138 | . | ||
139 | Server test cert (1024 bit) | ||
140 | |||
141 | |||
142 | |||
143 | EOF | ||
144 | |||
145 | if [ $? != 0 ]; then | ||
146 | echo problems generating 1024 bit server cert request | ||
147 | exit 1 | ||
148 | fi | ||
149 | |||
150 | #sign it. | ||
151 | echo | ||
152 | echo signing 1024 bit server cert | ||
153 | $SSLEAY x509 -md5 -days 365 \ | ||
154 | -req \ | ||
155 | -CAcreateserial -CAserial ca-cert.srl \ | ||
156 | -CA ca-cert.pem -CAkey ca-key.pem \ | ||
157 | -in s1024req.pem -out server2.pem | ||
158 | |||
159 | if [ $? != 0 ]; then | ||
160 | echo problems signing 1024 bit server cert | ||
161 | exit 1 | ||
162 | fi | ||
163 | echo | ||
164 | |||
165 | # create 512 bit client request. | ||
166 | echo creating 512 bit client cert request | ||
167 | $SSLEAY req $CONF \ | ||
168 | -new -md5 -newkey 512 \ | ||
169 | -keyout c512-key.pem \ | ||
170 | -out c512-req.pem -nodes >/dev/null <<EOF | ||
171 | AU | ||
172 | Queensland | ||
173 | . | ||
174 | CryptSoft Pty Ltd | ||
175 | . | ||
176 | Client test cert (512 bit) | ||
177 | |||
178 | |||
179 | |||
180 | EOF | ||
181 | |||
182 | if [ $? != 0 ]; then | ||
183 | echo problems generating 512 bit client cert request | ||
184 | exit 1 | ||
185 | fi | ||
186 | |||
187 | #sign it. | ||
188 | echo | ||
189 | echo signing 512 bit client cert | ||
190 | $SSLEAY x509 -md5 -days 365 \ | ||
191 | -req \ | ||
192 | -CAcreateserial -CAserial ca-cert.srl \ | ||
193 | -CA ca-cert.pem -CAkey ca-key.pem \ | ||
194 | -in c512-req.pem -out client.pem | ||
195 | |||
196 | if [ $? != 0 ]; then | ||
197 | echo problems signing 512 bit client cert | ||
198 | exit 1 | ||
199 | fi | ||
200 | |||
201 | echo cleanup | ||
202 | |||
203 | cat pca-key.pem >> pca-cert.pem | ||
204 | cat ca-key.pem >> ca-cert.pem | ||
205 | cat s512-key.pem >> server.pem | ||
206 | cat s1024key.pem >> server2.pem | ||
207 | cat c512-key.pem >> client.pem | ||
208 | |||
209 | for i in pca-cert.pem ca-cert.pem server.pem server2.pem client.pem | ||
210 | do | ||
211 | $SSLEAY x509 -issuer -subject -in $i -noout >$$ | ||
212 | cat $$ | ||
213 | /bin/cat $i >>$$ | ||
214 | /bin/mv $$ $i | ||
215 | done | ||
216 | |||
217 | #/bin/rm -f *key.pem *req.pem *.srl | ||
218 | |||
219 | echo Finished | ||
220 | |||
diff --git a/src/lib/libcrypto/util/mkdef.pl b/src/lib/libcrypto/util/mkdef.pl new file mode 100644 index 0000000000..8124f11292 --- /dev/null +++ b/src/lib/libcrypto/util/mkdef.pl | |||
@@ -0,0 +1,292 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # generate a .def file | ||
4 | # | ||
5 | # It does this by parsing the header files and looking for the | ||
6 | # non-prototyped functions. | ||
7 | # | ||
8 | |||
9 | $crypto_num="util/libeay.num"; | ||
10 | $ssl_num= "util/ssleay.num"; | ||
11 | |||
12 | $NT=1; | ||
13 | foreach (@ARGV) | ||
14 | { | ||
15 | $NT=1 if $_ eq "32"; | ||
16 | $NT=0 if $_ eq "16"; | ||
17 | $do_ssl=1 if $_ eq "ssleay"; | ||
18 | $do_crypto=1 if $_ eq "libeay"; | ||
19 | } | ||
20 | |||
21 | if (!$do_ssl && !$do_crypto) | ||
22 | { | ||
23 | print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 ]\n"; | ||
24 | exit(1); | ||
25 | } | ||
26 | |||
27 | %ssl_list=&load_numbers($ssl_num); | ||
28 | %crypto_list=&load_numbers($crypto_num); | ||
29 | |||
30 | $ssl="ssl/ssl.h"; | ||
31 | |||
32 | $crypto ="crypto/crypto.h"; | ||
33 | $crypto.=" crypto/des/des.h"; | ||
34 | $crypto.=" crypto/idea/idea.h"; | ||
35 | $crypto.=" crypto/rc4/rc4.h"; | ||
36 | $crypto.=" crypto/rc5/rc5.h"; | ||
37 | $crypto.=" crypto/rc2/rc2.h"; | ||
38 | $crypto.=" crypto/bf/blowfish.h"; | ||
39 | $crypto.=" crypto/cast/cast.h"; | ||
40 | $crypto.=" crypto/md2/md2.h"; | ||
41 | $crypto.=" crypto/md5/md5.h"; | ||
42 | $crypto.=" crypto/mdc2/mdc2.h"; | ||
43 | $crypto.=" crypto/sha/sha.h"; | ||
44 | $crypto.=" crypto/ripemd/ripemd.h"; | ||
45 | |||
46 | $crypto.=" crypto/bn/bn.h"; | ||
47 | $crypto.=" crypto/rsa/rsa.h"; | ||
48 | $crypto.=" crypto/dsa/dsa.h"; | ||
49 | $crypto.=" crypto/dh/dh.h"; | ||
50 | |||
51 | $crypto.=" crypto/stack/stack.h"; | ||
52 | $crypto.=" crypto/buffer/buffer.h"; | ||
53 | $crypto.=" crypto/bio/bio.h"; | ||
54 | $crypto.=" crypto/lhash/lhash.h"; | ||
55 | $crypto.=" crypto/conf/conf.h"; | ||
56 | $crypto.=" crypto/txt_db/txt_db.h"; | ||
57 | |||
58 | $crypto.=" crypto/evp/evp.h"; | ||
59 | $crypto.=" crypto/objects/objects.h"; | ||
60 | $crypto.=" crypto/pem/pem.h"; | ||
61 | #$crypto.=" crypto/meth/meth.h"; | ||
62 | $crypto.=" crypto/asn1/asn1.h"; | ||
63 | $crypto.=" crypto/asn1/asn1_mac.h"; | ||
64 | $crypto.=" crypto/err/err.h"; | ||
65 | $crypto.=" crypto/pkcs7/pkcs7.h"; | ||
66 | $crypto.=" crypto/x509/x509.h"; | ||
67 | $crypto.=" crypto/x509/x509_vfy.h"; | ||
68 | $crypto.=" crypto/rand/rand.h"; | ||
69 | $crypto.=" crypto/hmac/hmac.h"; | ||
70 | |||
71 | $match{'NOPROTO'}=1; | ||
72 | $match2{'PERL5'}=1; | ||
73 | |||
74 | &print_def_file(*STDOUT,"SSLEAY",*ssl_list,&do_defs("SSLEAY",$ssl)) | ||
75 | if $do_ssl == 1; | ||
76 | |||
77 | &print_def_file(*STDOUT,"LIBEAY",*crypto_list,&do_defs("LIBEAY",$crypto)) | ||
78 | if $do_crypto == 1; | ||
79 | |||
80 | sub do_defs | ||
81 | { | ||
82 | local($name,$files)=@_; | ||
83 | local(@ret); | ||
84 | |||
85 | $off=-1; | ||
86 | foreach $file (split(/\s+/,$files)) | ||
87 | { | ||
88 | # print STDERR "reading $file\n"; | ||
89 | open(IN,"<$file") || die "unable to open $file:$!\n"; | ||
90 | $depth=0; | ||
91 | $pr=-1; | ||
92 | @np=""; | ||
93 | $/=undef; | ||
94 | $a=<IN>; | ||
95 | while (($i=index($a,"/*")) >= 0) | ||
96 | { | ||
97 | $j=index($a,"*/"); | ||
98 | break unless ($j >= 0); | ||
99 | $a=substr($a,0,$i).substr($a,$j+2); | ||
100 | # print "$i $j\n"; | ||
101 | } | ||
102 | foreach (split("\n",$a)) | ||
103 | { | ||
104 | if (/^\#\s*ifndef (.*)/) | ||
105 | { | ||
106 | push(@tag,$1); | ||
107 | $tag{$1}=-1; | ||
108 | next; | ||
109 | } | ||
110 | elsif (/^\#\s*if !defined\(([^\)]+)\)/) | ||
111 | { | ||
112 | push(@tag,$1); | ||
113 | $tag{$1}=-1; | ||
114 | next; | ||
115 | } | ||
116 | elsif (/^\#\s*ifdef (.*)/) | ||
117 | { | ||
118 | push(@tag,$1); | ||
119 | $tag{$1}=1; | ||
120 | next; | ||
121 | } | ||
122 | elsif (/^\#\s*if defined(.*)/) | ||
123 | { | ||
124 | push(@tag,$1); | ||
125 | $tag{$1}=1; | ||
126 | next; | ||
127 | } | ||
128 | elsif (/^\#\s*endif/) | ||
129 | { | ||
130 | $tag{$tag[$#tag]}=0; | ||
131 | pop(@tag); | ||
132 | next; | ||
133 | } | ||
134 | elsif (/^\#\s*else/) | ||
135 | { | ||
136 | $t=$tag[$#tag]; | ||
137 | $tag{$t}= -$tag{$t}; | ||
138 | next; | ||
139 | } | ||
140 | #printf STDERR "$_\n%2d %2d %2d %2d %2d $NT\n", | ||
141 | #$tag{'NOPROTO'},$tag{'FreeBSD'},$tag{'WIN16'},$tag{'PERL5'},$tag{'NO_FP_API'}; | ||
142 | |||
143 | $t=undef; | ||
144 | if (/^extern .*;$/) | ||
145 | { $t=&do_extern($name,$_); } | ||
146 | elsif ( ($tag{'NOPROTO'} == 1) && | ||
147 | ($tag{'FreeBSD'} != 1) && | ||
148 | (($NT && ($tag{'WIN16'} != 1)) || | ||
149 | (!$NT && ($tag{'WIN16'} != -1))) && | ||
150 | ($tag{'PERL5'} != 1) && | ||
151 | # ($tag{'_WINDLL'} != -1) && | ||
152 | ((!$NT && $tag{'_WINDLL'} != -1) || | ||
153 | ($NT && $tag{'_WINDLL'} != 1)) && | ||
154 | ((($tag{'NO_FP_API'} != 1) && $NT) || | ||
155 | (($tag{'NO_FP_API'} != -1) && !$NT))) | ||
156 | { $t=&do_line($name,$_); } | ||
157 | else | ||
158 | { $t=undef; } | ||
159 | if (($t ne undef) && (!$done{$name,$t})) | ||
160 | { | ||
161 | $done{$name,$t}++; | ||
162 | push(@ret,$t); | ||
163 | #printf STDERR "one:$t\n" if $t =~ /BIO_/; | ||
164 | } | ||
165 | } | ||
166 | close(IN); | ||
167 | } | ||
168 | return(@ret); | ||
169 | } | ||
170 | |||
171 | sub do_line | ||
172 | { | ||
173 | local($file,$_)=@_; | ||
174 | local($n); | ||
175 | |||
176 | return(undef) if /^$/; | ||
177 | return(undef) if /^\s/; | ||
178 | #printf STDERR "two:$_\n" if $_ =~ /BIO_/; | ||
179 | if (/(CRYPTO_get_locking_callback)/) | ||
180 | { return($1); } | ||
181 | elsif (/(CRYPTO_get_id_callback)/) | ||
182 | { return($1); } | ||
183 | elsif (/(CRYPTO_get_add_lock_callback)/) | ||
184 | { return($1); } | ||
185 | elsif (/(SSL_CTX_get_verify_callback)/) | ||
186 | { return($1); } | ||
187 | elsif (/(SSL_get_info_callback)/) | ||
188 | { return($1); } | ||
189 | elsif ((!$NT) && /(ERR_load_CRYPTO_strings)/) | ||
190 | { return("ERR_load_CRYPTOlib_strings"); } | ||
191 | elsif (!$NT && /BIO_s_file/) | ||
192 | { return(undef); } | ||
193 | elsif (!$NT && /BIO_new_file/) | ||
194 | { return(undef); } | ||
195 | elsif (!$NT && /BIO_new_fp/) | ||
196 | { return(undef); } | ||
197 | elsif ($NT && /BIO_s_file_internal/) | ||
198 | { return(undef); } | ||
199 | elsif ($NT && /BIO_new_file_internal/) | ||
200 | { return(undef); } | ||
201 | elsif ($NT && /BIO_new_fp_internal/) | ||
202 | { return(undef); } | ||
203 | else | ||
204 | { | ||
205 | /\s\**(\S+)\s*\(/; | ||
206 | return($1); | ||
207 | } | ||
208 | } | ||
209 | |||
210 | sub do_extern | ||
211 | { | ||
212 | local($file,$_)=@_; | ||
213 | local($n); | ||
214 | |||
215 | /\s\**(\S+);$/; | ||
216 | return($1); | ||
217 | } | ||
218 | |||
219 | sub print_def_file | ||
220 | { | ||
221 | local(*OUT,$name,*nums,@functions)=@_; | ||
222 | local($n)=1; | ||
223 | |||
224 | if ($NT) | ||
225 | { $name.="32"; } | ||
226 | else | ||
227 | { $name.="16"; } | ||
228 | |||
229 | print OUT <<"EOF"; | ||
230 | ; | ||
231 | ; Definition file for the DDL version of the $name library from SSLeay | ||
232 | ; | ||
233 | |||
234 | LIBRARY $name | ||
235 | |||
236 | DESCRIPTION 'SSLeay $name - eay\@cryptsoft.com' | ||
237 | |||
238 | EOF | ||
239 | |||
240 | if (!$NT) | ||
241 | { | ||
242 | print <<"EOF"; | ||
243 | CODE PRELOAD MOVEABLE | ||
244 | DATA PRELOAD MOVEABLE SINGLE | ||
245 | |||
246 | EXETYPE WINDOWS | ||
247 | |||
248 | HEAPSIZE 4096 | ||
249 | STACKSIZE 8192 | ||
250 | |||
251 | EOF | ||
252 | } | ||
253 | |||
254 | print "EXPORTS\n"; | ||
255 | |||
256 | |||
257 | (@e)=grep(/^SSLeay/,@functions); | ||
258 | (@r)=grep(!/^SSLeay/,@functions); | ||
259 | @functions=((sort @e),(sort @r)); | ||
260 | |||
261 | foreach $func (@functions) | ||
262 | { | ||
263 | if (!defined($nums{$func})) | ||
264 | { | ||
265 | printf STDERR "$func does not have a number assigned\n"; | ||
266 | } | ||
267 | else | ||
268 | { | ||
269 | $n=$nums{$func}; | ||
270 | printf OUT " %s%-35s@%d\n",($NT)?"":"_",$func,$n; | ||
271 | } | ||
272 | } | ||
273 | printf OUT "\n"; | ||
274 | } | ||
275 | |||
276 | sub load_numbers | ||
277 | { | ||
278 | local($name)=@_; | ||
279 | local($j,@a,%ret); | ||
280 | |||
281 | open(IN,"<$name") || die "unable to open $name:$!\n"; | ||
282 | while (<IN>) | ||
283 | { | ||
284 | chop; | ||
285 | s/#.*$//; | ||
286 | next if /^\s*$/; | ||
287 | @a=split; | ||
288 | $ret{$a[0]}=$a[1]; | ||
289 | } | ||
290 | close(IN); | ||
291 | return(%ret); | ||
292 | } | ||
diff --git a/src/lib/libcrypto/util/perlpath.pl b/src/lib/libcrypto/util/perlpath.pl new file mode 100644 index 0000000000..9e57e10ad4 --- /dev/null +++ b/src/lib/libcrypto/util/perlpath.pl | |||
@@ -0,0 +1,30 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # modify the '#!/usr/local/bin/perl' | ||
4 | # line in all scripts that rely on perl. | ||
5 | # | ||
6 | |||
7 | require "find.pl"; | ||
8 | |||
9 | $#ARGV == 0 || print STDERR "usage: perlpath newpath (eg /usr/bin)\n"; | ||
10 | &find("."); | ||
11 | |||
12 | sub wanted | ||
13 | { | ||
14 | return unless /\.pl$/ || /^[Cc]onfigur/; | ||
15 | |||
16 | open(IN,"<$_") || die "unable to open $dir/$_:$!\n"; | ||
17 | @a=<IN>; | ||
18 | close(IN); | ||
19 | |||
20 | $a[0]="#!$ARGV[0]/perl\n"; | ||
21 | |||
22 | # Playing it safe... | ||
23 | $new="$_.new"; | ||
24 | open(OUT,">$new") || die "unable to open $dir/$new:$!\n"; | ||
25 | print OUT @a; | ||
26 | close(OUT); | ||
27 | |||
28 | rename($new,$_) || die "unable to rename $dir/$new:$!\n"; | ||
29 | chmod(0755,$_) || die "unable to chmod $dir/$new:$!\n"; | ||
30 | } | ||
diff --git a/src/lib/libcrypto/util/pl/BC-16.pl b/src/lib/libcrypto/util/pl/BC-16.pl new file mode 100644 index 0000000000..7c3fdb68f4 --- /dev/null +++ b/src/lib/libcrypto/util/pl/BC-16.pl | |||
@@ -0,0 +1,146 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries | ||
3 | # | ||
4 | |||
5 | $o='\\'; | ||
6 | $cp='copy'; | ||
7 | $rm='del'; | ||
8 | |||
9 | # C compiler stuff | ||
10 | $cc='bcc'; | ||
11 | |||
12 | if ($debug) | ||
13 | { $op="-v "; } | ||
14 | else { $op="-O "; } | ||
15 | |||
16 | $cflags="-d -ml $op -DL_ENDIAN"; | ||
17 | # I add the stack opt | ||
18 | $base_lflags="/c /C"; | ||
19 | $lflags="$base_lflags"; | ||
20 | |||
21 | if ($win16) | ||
22 | { | ||
23 | $shlib=1; | ||
24 | $cflags.=" -DWINDOWS -DWIN16"; | ||
25 | $app_cflag="-W"; | ||
26 | $lib_cflag="-WD"; | ||
27 | $lflags.="/Twe"; | ||
28 | } | ||
29 | else | ||
30 | { | ||
31 | $cflags.=" -DMSDOS"; | ||
32 | $lflags.=" /Tde"; | ||
33 | } | ||
34 | |||
35 | if ($shlib) | ||
36 | { | ||
37 | $mlflags=" /Twd $base_lflags"; # stack if defined in .def file | ||
38 | $libs="libw ldllcew"; | ||
39 | $no_asm=1; | ||
40 | } | ||
41 | else | ||
42 | { $mlflags=''; } | ||
43 | |||
44 | $obj='.obj'; | ||
45 | $ofile="-o"; | ||
46 | |||
47 | # EXE linking stuff | ||
48 | $link="tlink"; | ||
49 | $efile=""; | ||
50 | $exep='.exe'; | ||
51 | $ex_libs="CL"; | ||
52 | $ex_libs.=$no_sock?"":" winsock.lib"; | ||
53 | |||
54 | $app_ex_obj="C0L.obj "; | ||
55 | $shlib_ex_obj="" if ($shlib); | ||
56 | |||
57 | # static library stuff | ||
58 | $mklib='tlib'; | ||
59 | $ranlib='echo no ranlib'; | ||
60 | $plib=""; | ||
61 | $libp=".lib"; | ||
62 | $shlibp=($shlib)?".dll":".lib"; | ||
63 | $lfile=''; | ||
64 | |||
65 | $asm='bcc -c -B -Tml'; | ||
66 | $afile='/o'; | ||
67 | if ($no_asm) | ||
68 | { | ||
69 | $bn_mulw_obj=''; | ||
70 | $bn_mulw_src=''; | ||
71 | } | ||
72 | elsif ($asmbits == 32) | ||
73 | { | ||
74 | $bn_mulw_obj='crypto\bn\asm\x86w32.obj'; | ||
75 | $bn_mulw_src='crypto\bn\asm\x86w32.asm'; | ||
76 | } | ||
77 | else | ||
78 | { | ||
79 | $bn_mulw_obj='crypto\bn\asm\x86w16.obj'; | ||
80 | $bn_mulw_src='crypto\bn\asm\x86w16.asm'; | ||
81 | } | ||
82 | |||
83 | sub do_lib_rule | ||
84 | { | ||
85 | local($target,$name,$shlib)=@_; | ||
86 | local($ret,$Name); | ||
87 | |||
88 | $taget =~ s/\//$o/g if $o ne '/'; | ||
89 | ($Name=$name) =~ tr/a-z/A-Z/; | ||
90 | |||
91 | $ret.="$target: \$(${Name}OBJ)\n"; | ||
92 | $ret.="\t\$(RM) \$(O_$Name)\n"; | ||
93 | |||
94 | # Due to a pathetic line length limit, I unwrap the args. | ||
95 | local($lib_names)=""; | ||
96 | local($dll_names)=""; | ||
97 | foreach $_ (sort split(/\s+/,$Vars{"${Name}OBJ"})) | ||
98 | { | ||
99 | $lib_names.=" +$_ &\n"; | ||
100 | $dll_names.=" $_\n"; | ||
101 | } | ||
102 | |||
103 | if (!$shlib) | ||
104 | { | ||
105 | $ret.="\t\$(MKLIB) $target & <<|\n$lib_names\n,\n|\n"; | ||
106 | } | ||
107 | else | ||
108 | { | ||
109 | local($ex)=($Name eq "SSL")?' $(L_CRYPTO) winsock':""; | ||
110 | $ret.="\t\$(LINK) \$(MLFLAGS) @&&|\n"; | ||
111 | $ret.=$dll_names; | ||
112 | $ret.="\n $target\n\n $ex $libs\nms$o${name}16.def;\n|\n"; | ||
113 | ($out_lib=$target) =~ s/O_/L_/; | ||
114 | $ret.="\timplib /nowep $out_lib $target\n\n"; | ||
115 | } | ||
116 | $ret.="\n"; | ||
117 | return($ret); | ||
118 | } | ||
119 | |||
120 | sub do_link_rule | ||
121 | { | ||
122 | local($target,$files,$dep_libs,$libs)=@_; | ||
123 | local($ret,$f,$_,@f); | ||
124 | |||
125 | $file =~ s/\//$o/g if $o ne '/'; | ||
126 | $n=&bname($targer); | ||
127 | $ret.="$target: $files $dep_libs\n"; | ||
128 | $ret.=" \$(LINK) @&&|"; | ||
129 | |||
130 | # Due to a pathetic line length limit, I have to unwrap the args. | ||
131 | $ret.=" \$(LFLAGS) "; | ||
132 | if ($files =~ /\(([^)]*)\)$/) | ||
133 | { | ||
134 | $ret.=" \$(APP_EX_OBJ)"; | ||
135 | foreach $_ (sort split(/\s+/,$Vars{$1})) | ||
136 | { $ret.="\n $r $_ +"; } | ||
137 | chop($ret); | ||
138 | $ret.="\n"; | ||
139 | } | ||
140 | else | ||
141 | { $ret.="\n $r \$(APP_EX_OBJ) $files\n"; } | ||
142 | $ret.=" $target\n\n $libs\n\n|\n\n"; | ||
143 | return($ret); | ||
144 | } | ||
145 | |||
146 | 1; | ||
diff --git a/src/lib/libcrypto/util/pl/BC-32.pl b/src/lib/libcrypto/util/pl/BC-32.pl new file mode 100644 index 0000000000..3898d16f61 --- /dev/null +++ b/src/lib/libcrypto/util/pl/BC-32.pl | |||
@@ -0,0 +1,135 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries | ||
3 | # | ||
4 | |||
5 | $o='\\'; | ||
6 | $cp='copy'; | ||
7 | $rm='del'; | ||
8 | |||
9 | # C compiler stuff | ||
10 | $cc='bcc32'; | ||
11 | |||
12 | if ($debug) | ||
13 | { $op="-v "; } | ||
14 | else { $op="-O "; } | ||
15 | |||
16 | $cflags="-d $op -DL_ENDIAN "; | ||
17 | # I add the stack opt | ||
18 | $base_lflags="-c"; | ||
19 | $lflags="$base_lflags"; | ||
20 | |||
21 | $cflags.=" -DWINDOWS -DWIN32"; | ||
22 | $app_cflag="-WC"; | ||
23 | $lib_cflag="-WC"; | ||
24 | $lflags.=" -Tpe"; | ||
25 | |||
26 | if ($shlib) | ||
27 | { | ||
28 | $mlflags="$base_lflags -Tpe"; # stack if defined in .def file | ||
29 | $libs="libw ldllcew"; | ||
30 | } | ||
31 | else | ||
32 | { $mlflags=''; } | ||
33 | |||
34 | $obj='.obj'; | ||
35 | $ofile="-o"; | ||
36 | |||
37 | # EXE linking stuff | ||
38 | $link="tlink32"; | ||
39 | $efile=""; | ||
40 | $exep='.exe'; | ||
41 | $ex_libs="CW32.LIB IMPORT32.LIB"; | ||
42 | $ex_libs.=$no_sock?"":" wsock32.lib"; | ||
43 | $shlib_ex_obj="" if $shlib; | ||
44 | $app_ex_obj="C0X32.OBJ"; | ||
45 | |||
46 | # static library stuff | ||
47 | $mklib='tlib'; | ||
48 | $ranlib=''; | ||
49 | $plib=""; | ||
50 | $libp=".lib"; | ||
51 | $shlibp=($shlib)?".dll":".lib"; | ||
52 | $lfile=''; | ||
53 | |||
54 | $asm='ml /Cp /c /Cx'; | ||
55 | $afile='/Fo'; | ||
56 | if ($noasm) | ||
57 | { | ||
58 | $bn_mulw_obj=''; | ||
59 | $bn_mulw_src=''; | ||
60 | } | ||
61 | else | ||
62 | { | ||
63 | $bn_mulw_obj='crypto\bn\asm\x86b32.obj'; | ||
64 | $bn_mulw_src='crypto\bn\asm\x86m32.asm'; | ||
65 | } | ||
66 | |||
67 | sub do_lib_rule | ||
68 | { | ||
69 | local($target,$name,$shlib)=@_; | ||
70 | local($ret,$Name); | ||
71 | |||
72 | $taget =~ s/\//$o/g if $o ne '/'; | ||
73 | ($Name=$name) =~ tr/a-z/A-Z/; | ||
74 | |||
75 | $ret.="$target: \$(${Name}OBJ)\n"; | ||
76 | $ret.="\t\$(RM) \$(O_$Name)\n"; | ||
77 | |||
78 | # Due to a pathetic line length limit, I unwrap the args. | ||
79 | local($lib_names)=""; | ||
80 | local($dll_names)=""; | ||
81 | foreach $_ (sort split(/\s+/,$Vars{"${Name}OBJ"})) | ||
82 | { | ||
83 | $lib_names.=" +$_ &\n"; | ||
84 | $dll_names.=" $_\n"; | ||
85 | } | ||
86 | |||
87 | if (!$shlib) | ||
88 | { | ||
89 | $ret.="\t\$(MKLIB) $target & <<|\n$lib_names\n,\n|\n"; | ||
90 | } | ||
91 | else | ||
92 | { | ||
93 | # $(SHLIB_EX_OBJ) | ||
94 | local($ex)=($Name eq "SSL")?' $(L_CRYPTO) winsock':""; | ||
95 | $ret.="\t\$(LINK) \$(MLFLAGS) @&&|\n"; | ||
96 | $ret.=$dll_names; | ||
97 | $ret.="\n $target\n\n $ex $libs\nms$o${name}16.def;\n|\n"; | ||
98 | ($out_lib=$target) =~ s/O_/L_/; | ||
99 | $ret.="\timplib /nowep $out_lib $target\n\n"; | ||
100 | } | ||
101 | $ret.="\n"; | ||
102 | return($ret); | ||
103 | } | ||
104 | |||
105 | sub do_link_rule | ||
106 | { | ||
107 | local($target,$files,$dep_libs,$libs)=@_; | ||
108 | local($ret,$f,$_,@f); | ||
109 | |||
110 | $file =~ s/\//$o/g if $o ne '/'; | ||
111 | $n=&bname($targer); | ||
112 | $ret.="$target: $files $dep_libs\n"; | ||
113 | $ret.=" \$(LINK) @&&|"; | ||
114 | |||
115 | # Due to a pathetic line length limit, I have to unwrap the args. | ||
116 | $r=" \$(LFLAGS) "; | ||
117 | if ($files =~ /\(([^)]*)\)$/) | ||
118 | { | ||
119 | @a=('$(APP_EX_OBJ)'); | ||
120 | push(@a,sort split(/\s+/,$Vars{$1})); | ||
121 | foreach $_ (@a) | ||
122 | { | ||
123 | $ret.="\n $r $_ +"; | ||
124 | $r=""; | ||
125 | } | ||
126 | chop($ret); | ||
127 | $ret.="\n"; | ||
128 | } | ||
129 | else | ||
130 | { $ret.="\n $r \$(APP_EX_OBJ) $files\n"; } | ||
131 | $ret.=" $target\n\n $libs\n\n|\n\n"; | ||
132 | return($ret); | ||
133 | } | ||
134 | |||
135 | 1; | ||
diff --git a/src/lib/libcrypto/util/pl/VC-16.pl b/src/lib/libcrypto/util/pl/VC-16.pl new file mode 100644 index 0000000000..a6e6c0241c --- /dev/null +++ b/src/lib/libcrypto/util/pl/VC-16.pl | |||
@@ -0,0 +1,173 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries | ||
3 | # | ||
4 | |||
5 | $ssl= "ssleay16"; | ||
6 | $crypto="libeay16"; | ||
7 | $RSAref="RSAref16"; | ||
8 | |||
9 | $o='\\'; | ||
10 | $cp='copy'; | ||
11 | $rm='del'; | ||
12 | |||
13 | # C compiler stuff | ||
14 | $cc='cl'; | ||
15 | |||
16 | $out_def="out16"; | ||
17 | $tmp_def="tmp16"; | ||
18 | $inc_def="inc16"; | ||
19 | |||
20 | if ($debug) | ||
21 | { | ||
22 | $op="/Od /Zi /Zd"; | ||
23 | $base_lflags="/CO"; | ||
24 | } | ||
25 | else { | ||
26 | $op="/G2 /f- /Ocgnotb2"; | ||
27 | } | ||
28 | $base_lflags.=" /FARCALL /NOLOGO /NOD /SEG:1024 /ONERROR:NOEXE /NOE /PACKC:60000"; | ||
29 | if ($win16) { $base_lflags.=" /PACKD:60000"; } | ||
30 | |||
31 | $cflags="/ALw /Gx- /Gt256 /Gf $op /W3 /WX -DL_ENDIAN /nologo"; | ||
32 | # I add the stack opt | ||
33 | $lflags="$base_lflags /STACK:20000"; | ||
34 | |||
35 | if ($win16) | ||
36 | { | ||
37 | $cflags.=" -DWINDOWS -DWIN16"; | ||
38 | $app_cflag="/Gw /FPi87"; | ||
39 | $lib_cflag="/Gw"; | ||
40 | $lib_cflag.=" -D_WINDLL -D_DLL" if $shlib; | ||
41 | $lib_cflag.=" -DWIN16TTY" if !$shlib; | ||
42 | $lflags.=" /ALIGN:256"; | ||
43 | $ex_libs.="oldnames llibcewq libw"; | ||
44 | } | ||
45 | else | ||
46 | { | ||
47 | $no_sock=1; | ||
48 | $cflags.=" -DMSDOS"; | ||
49 | $lflags.=" /EXEPACK"; | ||
50 | $ex_libs.="oldnames.lib llibce.lib"; | ||
51 | } | ||
52 | |||
53 | if ($shlib) | ||
54 | { | ||
55 | $mlflags="$base_lflags"; | ||
56 | $libs="oldnames ldllcew libw"; | ||
57 | $shlib_ex_obj=""; | ||
58 | # $no_asm=1; | ||
59 | $out_def="out16dll"; | ||
60 | $tmp_def="tmp16dll"; | ||
61 | } | ||
62 | else | ||
63 | { $mlflags=''; } | ||
64 | |||
65 | $app_ex_obj="setargv.obj"; | ||
66 | |||
67 | $obj='.obj'; | ||
68 | $ofile="/Fo"; | ||
69 | |||
70 | # EXE linking stuff | ||
71 | $link="link"; | ||
72 | $efile=""; | ||
73 | $exep='.exe'; | ||
74 | $ex_libs.=$no_sock?"":" winsock"; | ||
75 | |||
76 | # static library stuff | ||
77 | $mklib='lib /PAGESIZE:1024'; | ||
78 | $ranlib=''; | ||
79 | $plib=""; | ||
80 | $libp=".lib"; | ||
81 | $shlibp=($shlib)?".dll":".lib"; | ||
82 | $lfile=''; | ||
83 | |||
84 | $asm='ml /Cp /c /Cx'; | ||
85 | $afile='/Fo'; | ||
86 | |||
87 | $bn_mulw_obj=''; | ||
88 | $bn_mulw_src=''; | ||
89 | $des_enc_obj=''; | ||
90 | $des_enc_src=''; | ||
91 | $bf_enc_obj=''; | ||
92 | $bf_enc_src=''; | ||
93 | |||
94 | if (!$no_asm) | ||
95 | { | ||
96 | if ($asmbits == 32) | ||
97 | { | ||
98 | $bn_mulw_obj='crypto\bn\asm\x86w32.obj'; | ||
99 | $bn_mulw_src='crypto\bn\asm\x86w32.asm'; | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | $bn_mulw_obj='crypto\bn\asm\x86w16.obj'; | ||
104 | $bn_mulw_src='crypto\bn\asm\x86w16.asm'; | ||
105 | } | ||
106 | } | ||
107 | |||
108 | sub do_lib_rule | ||
109 | { | ||
110 | local($objs,$target,$name,$shlib)=@_; | ||
111 | local($ret,$Name); | ||
112 | |||
113 | $taget =~ s/\//$o/g if $o ne '/'; | ||
114 | ($Name=$name) =~ tr/a-z/A-Z/; | ||
115 | |||
116 | # $target="\$(LIB_D)$o$target"; | ||
117 | $ret.="$target: $objs\n"; | ||
118 | # $ret.="\t\$(RM) \$(O_$Name)\n"; | ||
119 | |||
120 | # Due to a pathetic line length limit, I unwrap the args. | ||
121 | local($lib_names)=""; | ||
122 | local($dll_names)=" \$(SHLIB_EX_OBJ) +\n"; | ||
123 | ($obj)= ($objs =~ /\((.*)\)/); | ||
124 | foreach $_ (sort split(/\s+/,$Vars{$obj})) | ||
125 | { | ||
126 | $lib_names.="+$_ &\n"; | ||
127 | $dll_names.=" $_ +\n"; | ||
128 | } | ||
129 | |||
130 | if (!$shlib) | ||
131 | { | ||
132 | $ret.="\tdel $target\n"; | ||
133 | $ret.="\t\$(MKLIB) @<<\n$target\ny\n$lib_names\n\n<<\n"; | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | local($ex)=($target =~ /O_SSL/)?'$(L_CRYPTO)':""; | ||
138 | $ex.=' winsock'; | ||
139 | $ret.="\t\$(LINK) \$(MLFLAGS) @<<\n"; | ||
140 | $ret.=$dll_names; | ||
141 | $ret.="\n $target\n\n $ex $libs\nms$o${name}.def;\n<<\n"; | ||
142 | ($out_lib=$target) =~ s/O_/L_/; | ||
143 | $ret.="\timplib /noignorecase /nowep $out_lib $target\n"; | ||
144 | } | ||
145 | $ret.="\n"; | ||
146 | return($ret); | ||
147 | } | ||
148 | |||
149 | sub do_link_rule | ||
150 | { | ||
151 | local($target,$files,$dep_libs,$libs)=@_; | ||
152 | local($ret,$f,$_,@f); | ||
153 | |||
154 | $file =~ s/\//$o/g if $o ne '/'; | ||
155 | $n=&bname($targer); | ||
156 | $ret.="$target: $files $dep_libs\n"; | ||
157 | $ret.=" \$(LINK) \$(LFLAGS) @<<\n"; | ||
158 | |||
159 | # Due to a pathetic line length limit, I have to unwrap the args. | ||
160 | if ($files =~ /\(([^)]*)\)$/) | ||
161 | { | ||
162 | @a=('$(APP_EX_OBJ)'); | ||
163 | push(@a,sort split(/\s+/,$Vars{$1})); | ||
164 | for $_ (@a) | ||
165 | { $ret.=" $_ +\n"; } | ||
166 | } | ||
167 | else | ||
168 | { $ret.=" \$(APP_EX_OBJ) $files"; } | ||
169 | $ret.="\n $target\n\n $libs\n\n<<\n\n"; | ||
170 | return($ret); | ||
171 | } | ||
172 | |||
173 | 1; | ||
diff --git a/src/lib/libcrypto/util/pl/VC-32.pl b/src/lib/libcrypto/util/pl/VC-32.pl new file mode 100644 index 0000000000..701e282c33 --- /dev/null +++ b/src/lib/libcrypto/util/pl/VC-32.pl | |||
@@ -0,0 +1,133 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # VCw32lib.pl - the file for Visual C++ 4.[01] for windows NT, static libraries | ||
3 | # | ||
4 | |||
5 | $ssl= "ssleay32"; | ||
6 | $crypto="libeay32"; | ||
7 | $RSAref="RSAref32"; | ||
8 | |||
9 | $o='\\'; | ||
10 | $cp='copy'; | ||
11 | $rm='del'; | ||
12 | |||
13 | # C compiler stuff | ||
14 | $cc='cl'; | ||
15 | $cflags=' /MD /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN'; | ||
16 | $lflags="/nologo /subsystem:console /machine:I386 /opt:ref"; | ||
17 | $mlflags=''; | ||
18 | |||
19 | $out_def="out32"; | ||
20 | $tmp_def="tmp32"; | ||
21 | $inc_def="inc32"; | ||
22 | |||
23 | if ($debug) | ||
24 | { | ||
25 | $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DWINDOWS -DWIN32 -D_DEBUG -DL_ENDIAN"; | ||
26 | $lflags.=" /debug"; | ||
27 | $mlflags.=' /debug'; | ||
28 | } | ||
29 | |||
30 | $obj='.obj'; | ||
31 | $ofile="/Fo"; | ||
32 | |||
33 | # EXE linking stuff | ||
34 | $link="link"; | ||
35 | $efile="/out:"; | ||
36 | $exep='.exe'; | ||
37 | if ($no_sock) | ||
38 | { $ex_libs=""; } | ||
39 | else { $ex_libs="wsock32.lib user32.lib gdi32.lib"; } | ||
40 | |||
41 | # static library stuff | ||
42 | $mklib='lib'; | ||
43 | $ranlib=''; | ||
44 | $plib=""; | ||
45 | $libp=".lib"; | ||
46 | $shlibp=($shlib)?".dll":".lib"; | ||
47 | $lfile='/out:'; | ||
48 | |||
49 | $shlib_ex_obj=""; | ||
50 | $app_ex_obj="setargv.obj"; | ||
51 | |||
52 | $asm='ml /Cp /coff /c /Cx'; | ||
53 | $asm.=" /Zi" if $debug; | ||
54 | $afile='/Fo'; | ||
55 | |||
56 | $bn_mulw_obj=''; | ||
57 | $bn_mulw_src=''; | ||
58 | $des_enc_obj=''; | ||
59 | $des_enc_src=''; | ||
60 | $bf_enc_obj=''; | ||
61 | $bf_enc_src=''; | ||
62 | |||
63 | if (!$no_asm) | ||
64 | { | ||
65 | $bn_mulw_obj='crypto\bn\asm\bn-win32.obj'; | ||
66 | $bn_mulw_src='crypto\bn\asm\bn-win32.asm'; | ||
67 | $des_enc_obj='crypto\des\asm\d-win32.obj crypto\des\asm\y-win32.obj'; | ||
68 | $des_enc_src='crypto\des\asm\d-win32.asm crypto\des\asm\y-win32.asm'; | ||
69 | $bf_enc_obj='crypto\bf\asm\b-win32.obj'; | ||
70 | $bf_enc_src='crypto\bf\asm\b-win32.asm'; | ||
71 | $cast_enc_obj='crypto\cast\asm\c-win32.obj'; | ||
72 | $cast_enc_src='crypto\cast\asm\c-win32.asm'; | ||
73 | $rc4_enc_obj='crypto\rc4\asm\r4-win32.obj'; | ||
74 | $rc4_enc_src='crypto\rc4\asm\r4-win32.asm'; | ||
75 | $rc5_enc_obj='crypto\rc5\asm\r5-win32.obj'; | ||
76 | $rc5_enc_src='crypto\rc5\asm\r5-win32.asm'; | ||
77 | $md5_asm_obj='crypto\md5\asm\m5-win32.obj'; | ||
78 | $md5_asm_src='crypto\md5\asm\m5-win32.asm'; | ||
79 | $sha1_asm_obj='crypto\sha\asm\s1-win32.obj'; | ||
80 | $sha1_asm_src='crypto\sha\asm\s1-win32.asm'; | ||
81 | $rmd160_asm_obj='crypto\ripemd\asm\rm-win32.obj'; | ||
82 | $rmd160_asm_src='crypto\ripemd\asm\rm-win32.asm'; | ||
83 | $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM"; | ||
84 | } | ||
85 | |||
86 | if ($shlib) | ||
87 | { | ||
88 | $mlflags.=" $lflags /dll"; | ||
89 | # $cflags =~ s| /MD| /MT|; | ||
90 | $lib_cflag=" /GD -D_WINDLL -D_DLL"; | ||
91 | $out_def="out32dll"; | ||
92 | $tmp_def="tmp32dll"; | ||
93 | } | ||
94 | |||
95 | sub do_lib_rule | ||
96 | { | ||
97 | local($objs,$target,$name,$shlib)=@_; | ||
98 | local($ret,$Name); | ||
99 | |||
100 | $taget =~ s/\//$o/g if $o ne '/'; | ||
101 | ($Name=$name) =~ tr/a-z/A-Z/; | ||
102 | |||
103 | # $target="\$(LIB_D)$o$target"; | ||
104 | $ret.="$target: $objs\n"; | ||
105 | if (!$shlib) | ||
106 | { | ||
107 | # $ret.="\t\$(RM) \$(O_$Name)\n"; | ||
108 | $ret.="\t\$(MKLIB) $lfile$target @<<\n $objs\n<<\n"; | ||
109 | } | ||
110 | else | ||
111 | { | ||
112 | local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':''; | ||
113 | $ex.=' wsock32.lib gdi32.lib'; | ||
114 | $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n"; | ||
115 | } | ||
116 | $ret.="\n"; | ||
117 | return($ret); | ||
118 | } | ||
119 | |||
120 | sub do_link_rule | ||
121 | { | ||
122 | local($target,$files,$dep_libs,$libs)=@_; | ||
123 | local($ret,$_); | ||
124 | |||
125 | $file =~ s/\//$o/g if $o ne '/'; | ||
126 | $n=&bname($targer); | ||
127 | $ret.="$target: $files $dep_libs\n"; | ||
128 | $ret.=" \$(LINK) \$(LFLAGS) $efile$target @<<\n"; | ||
129 | $ret.=" \$(APP_EX_OBJ) $files $libs\n<<\n\n"; | ||
130 | return($ret); | ||
131 | } | ||
132 | |||
133 | 1; | ||
diff --git a/src/lib/libcrypto/util/pl/linux.pl b/src/lib/libcrypto/util/pl/linux.pl new file mode 100644 index 0000000000..2b13da1bfc --- /dev/null +++ b/src/lib/libcrypto/util/pl/linux.pl | |||
@@ -0,0 +1,96 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # linux.pl - the standard unix makefile stuff. | ||
4 | # | ||
5 | |||
6 | $o='/'; | ||
7 | $cp='/bin/cp'; | ||
8 | $rm='/bin/rm -f'; | ||
9 | |||
10 | # C compiler stuff | ||
11 | |||
12 | $cc='gcc'; | ||
13 | if ($debug) | ||
14 | { $cflags="-g2 -ggdb -DREF_CHECK -DCRYPTO_MDEBUG"; } | ||
15 | else | ||
16 | { $cflags="-O3 -fomit-frame-pointer"; } | ||
17 | |||
18 | if (!$no_asm) | ||
19 | { | ||
20 | $bn_mulw_obj='$(OBJ_D)/bn86-elf.o'; | ||
21 | $bn_mulw_src='crypto/bn/asm/bn86unix.cpp'; | ||
22 | $des_enc_obj='$(OBJ_D)/dx86-elf.o $(OBJ_D)/yx86-elf.o'; | ||
23 | $des_enc_src='crypto/des/asm/dx86unix.cpp crypto/des/asm/yx86unix.cpp'; | ||
24 | $bf_enc_obj='$(OBJ_D)/bx86-elf.o'; | ||
25 | $bf_enc_src='crypto/bf/asm/bx86unix.cpp'; | ||
26 | $cast_enc_obj='$(OBJ_D)/cx86-elf.o'; | ||
27 | $cast_enc_src='crypto/cast/asm/cx86unix.cpp'; | ||
28 | $rc4_enc_obj='$(OBJ_D)/rx86-elf.o'; | ||
29 | $rc4_enc_src='crypto/rc4/asm/rx86unix.cpp'; | ||
30 | $md5_asm_obj='$(OBJ_D)/mx86-elf.o'; | ||
31 | $md5_asm_src='crypto/md5/asm/mx86unix.cpp'; | ||
32 | $sha1_asm_obj='$(OBJ_D)/sx86-elf.o'; | ||
33 | $sha1_asm_src='crypto/sha/asm/sx86unix.cpp'; | ||
34 | $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM"; | ||
35 | } | ||
36 | |||
37 | $cflags.=" -DTERMIO -DL_ENDIAN -m486 -Wall"; | ||
38 | |||
39 | if ($shlib) | ||
40 | { | ||
41 | $shl_cflag=" -DPIC -fpic"; | ||
42 | $shlibp=".so.$ssl_version"; | ||
43 | $so_shlibp=".so"; | ||
44 | } | ||
45 | |||
46 | sub do_shlib_rule | ||
47 | { | ||
48 | local($obj,$target,$name,$shlib,$so_name)=@_; | ||
49 | local($ret,$_,$Name); | ||
50 | |||
51 | $target =~ s/\//$o/g if $o ne '/'; | ||
52 | ($Name=$name) =~ tr/a-z/A-Z/; | ||
53 | |||
54 | $ret.="\$(LIB_D)$o$target: \$(${Name}OBJ)\n"; | ||
55 | $ret.="\t\$(RM) \$(LIB_D)$o$target\n"; | ||
56 | $ret.="\tgcc \${CFLAGS} -shared -Wl,-soname,$target -o \$(LIB_D)$o$target \$(${Name}OBJ)\n"; | ||
57 | ($t=$target) =~ s/(^.*)\/[^\/]*$/$1/; | ||
58 | if ($so_name ne "") | ||
59 | { | ||
60 | $ret.="\t\$(RM) \$(LIB_D)$o$so_name\n"; | ||
61 | $ret.="\tln -s $target \$(LIB_D)$o$so_name\n\n"; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | sub do_link_rule | ||
66 | { | ||
67 | local($target,$files,$dep_libs,$libs)=@_; | ||
68 | local($ret,$_); | ||
69 | |||
70 | $file =~ s/\//$o/g if $o ne '/'; | ||
71 | $n=&bname($target); | ||
72 | $ret.="$target: $files $dep_libs\n"; | ||
73 | $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n"; | ||
74 | return($ret); | ||
75 | } | ||
76 | |||
77 | sub do_asm_rule | ||
78 | { | ||
79 | local($target,$src)=@_; | ||
80 | local($ret,@s,@t,$i); | ||
81 | |||
82 | $target =~ s/\//$o/g if $o ne "/"; | ||
83 | $src =~ s/\//$o/g if $o ne "/"; | ||
84 | |||
85 | @s=split(/\s+/,$src); | ||
86 | @t=split(/\s+/,$target); | ||
87 | |||
88 | for ($i=0; $i<=$#s; $i++) | ||
89 | { | ||
90 | $ret.="$t[$i]: $s[$i]\n"; | ||
91 | $ret.="\tgcc -E -DELF \$(SRC_D)$o$s[$i]|\$(AS) $afile$t[$i]\n\n"; | ||
92 | } | ||
93 | return($ret); | ||
94 | } | ||
95 | |||
96 | 1; | ||
diff --git a/src/lib/libcrypto/util/pl/unix.pl b/src/lib/libcrypto/util/pl/unix.pl new file mode 100644 index 0000000000..ab4978fd20 --- /dev/null +++ b/src/lib/libcrypto/util/pl/unix.pl | |||
@@ -0,0 +1,83 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # unix.pl - the standard unix makefile stuff. | ||
4 | # | ||
5 | |||
6 | $o='/'; | ||
7 | $cp='/bin/cp'; | ||
8 | $rm='/bin/rm -f'; | ||
9 | |||
10 | # C compiler stuff | ||
11 | |||
12 | if ($gcc) | ||
13 | { | ||
14 | $cc='gcc'; | ||
15 | if ($debug) | ||
16 | { $cflags="-g2 -ggdb"; } | ||
17 | else | ||
18 | { $cflags="-O3 -fomit-frame-pointer"; } | ||
19 | } | ||
20 | else | ||
21 | { | ||
22 | $cc='cc'; | ||
23 | if ($debug) | ||
24 | { $cflags="-g"; } | ||
25 | else | ||
26 | { $cflags="-O"; } | ||
27 | } | ||
28 | $obj='.o'; | ||
29 | $ofile='-o '; | ||
30 | |||
31 | # EXE linking stuff | ||
32 | $link='${CC}'; | ||
33 | $lflags='${CFLAGS}'; | ||
34 | $efile='-o '; | ||
35 | $exep=''; | ||
36 | $ex_libs=""; | ||
37 | |||
38 | # static library stuff | ||
39 | $mklib='ar r'; | ||
40 | $mlflags=''; | ||
41 | $ranlib='util/ranlib.sh'; | ||
42 | $plib='lib'; | ||
43 | $libp=".a"; | ||
44 | $shlibp=".a"; | ||
45 | $lfile=''; | ||
46 | |||
47 | $asm='as'; | ||
48 | $afile='-o '; | ||
49 | $bn_mulw_obj=""; | ||
50 | $bn_mulw_src=""; | ||
51 | $des_enc_obj=""; | ||
52 | $des_enc_src=""; | ||
53 | $bf_enc_obj=""; | ||
54 | $bf_enc_src=""; | ||
55 | |||
56 | sub do_lib_rule | ||
57 | { | ||
58 | local($obj,$target,$name,$shlib)=@_; | ||
59 | local($ret,$_,$Name); | ||
60 | |||
61 | $target =~ s/\//$o/g if $o ne '/'; | ||
62 | $target="\$(LIB_D)$o$target"; | ||
63 | ($Name=$name) =~ tr/a-z/A-Z/; | ||
64 | |||
65 | $ret.="$target: \$(${Name}OBJ)\n"; | ||
66 | $ret.="\t\$(RM) $target\n"; | ||
67 | $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n"; | ||
68 | $ret.="\t\$(RANLIB) $target\n\n"; | ||
69 | } | ||
70 | |||
71 | sub do_link_rule | ||
72 | { | ||
73 | local($target,$files,$dep_libs,$libs)=@_; | ||
74 | local($ret,$_); | ||
75 | |||
76 | $file =~ s/\//$o/g if $o ne '/'; | ||
77 | $n=&bname($target); | ||
78 | $ret.="$target: $files $dep_libs\n"; | ||
79 | $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n"; | ||
80 | return($ret); | ||
81 | } | ||
82 | |||
83 | 1; | ||
diff --git a/src/lib/libcrypto/util/point.sh b/src/lib/libcrypto/util/point.sh new file mode 100644 index 0000000000..92c12e8282 --- /dev/null +++ b/src/lib/libcrypto/util/point.sh | |||
@@ -0,0 +1,4 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | /bin/rm -f $2 | ||
4 | ln -s $1 $2 | ||
diff --git a/src/lib/libcrypto/util/sp-diff.pl b/src/lib/libcrypto/util/sp-diff.pl new file mode 100644 index 0000000000..2c88336858 --- /dev/null +++ b/src/lib/libcrypto/util/sp-diff.pl | |||
@@ -0,0 +1,80 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # This file takes as input, the files that have been output from | ||
4 | # ssleay speed. | ||
5 | # It prints a table of the relative differences with %100 being 'no difference' | ||
6 | # | ||
7 | |||
8 | ($#ARGV == 1) || die "$0 speedout1 speedout2\n"; | ||
9 | |||
10 | %one=&loadfile($ARGV[0]); | ||
11 | %two=&loadfile($ARGV[1]); | ||
12 | |||
13 | $line=0; | ||
14 | foreach $a ("md2","md5","sha","sha1","rc4","des cfb","des cbc","des ede3", | ||
15 | "idea cfb","idea cbc","rc2 cfb","rc2 cbc","blowfish cbc","cast cbc") | ||
16 | { | ||
17 | if (defined($one{$a,8}) && defined($two{$a,8})) | ||
18 | { | ||
19 | print "type 8 byte% 64 byte% 256 byte% 1024 byte% 8192 byte%\n" | ||
20 | unless $line; | ||
21 | $line++; | ||
22 | printf "%-12s ",$a; | ||
23 | foreach $b (8,64,256,1024,8192) | ||
24 | { | ||
25 | $r=$two{$a,$b}/$one{$a,$b}*100; | ||
26 | printf "%12.2f",$r; | ||
27 | } | ||
28 | print "\n"; | ||
29 | } | ||
30 | } | ||
31 | |||
32 | foreach $a ( | ||
33 | "rsa 512","rsa 1024","rsa 2048","rsa 4096", | ||
34 | "dsa 512","dsa 1024","dsa 2048", | ||
35 | ) | ||
36 | { | ||
37 | if (defined($one{$a,1}) && defined($two{$a,1})) | ||
38 | { | ||
39 | $r1=($one{$a,1}/$two{$a,1})*100; | ||
40 | $r2=($one{$a,2}/$two{$a,2})*100; | ||
41 | printf "$a bits %% %6.2f %% %6.2f\n",$r1,$r2; | ||
42 | } | ||
43 | } | ||
44 | |||
45 | sub loadfile | ||
46 | { | ||
47 | local($file)=@_; | ||
48 | local($_,%ret); | ||
49 | |||
50 | open(IN,"<$file") || die "unable to open '$file' for input\n"; | ||
51 | $header=1; | ||
52 | while (<IN>) | ||
53 | { | ||
54 | $header=0 if /^[dr]sa/; | ||
55 | if (/^type/) { $header=0; next; } | ||
56 | next if $header; | ||
57 | chop; | ||
58 | @a=split; | ||
59 | if ($a[0] =~ /^[dr]sa$/) | ||
60 | { | ||
61 | ($n,$t1,$t2)=($_ =~ /^([dr]sa\s+\d+)\s+bits\s+([.\d]+)s\s+([.\d]+)/); | ||
62 | $ret{$n,1}=$t1; | ||
63 | $ret{$n,2}=$t2; | ||
64 | } | ||
65 | else | ||
66 | { | ||
67 | $n=join(' ',grep(/[^k]$/,@a)); | ||
68 | @k=grep(s/k$//,@a); | ||
69 | |||
70 | $ret{$n, 8}=$k[0]; | ||
71 | $ret{$n, 64}=$k[1]; | ||
72 | $ret{$n, 256}=$k[2]; | ||
73 | $ret{$n,1024}=$k[3]; | ||
74 | $ret{$n,8192}=$k[4]; | ||
75 | } | ||
76 | } | ||
77 | close(IN); | ||
78 | return(%ret); | ||
79 | } | ||
80 | |||
diff --git a/src/lib/libcrypto/util/speed.sh b/src/lib/libcrypto/util/speed.sh new file mode 100644 index 0000000000..f489706197 --- /dev/null +++ b/src/lib/libcrypto/util/speed.sh | |||
@@ -0,0 +1,39 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # | ||
4 | # This is a ugly script use, in conjuction with editing the 'b' | ||
5 | # configuration in the $(TOP)/Configure script which will | ||
6 | # output when finished a file called speed.log which is the | ||
7 | # timings of SSLeay with various options turned on or off. | ||
8 | # | ||
9 | # from the $(TOP) directory | ||
10 | # Edit Configure, modifying things to do with the b/bl-4c-2c etc | ||
11 | # configurations. | ||
12 | # | ||
13 | |||
14 | make clean | ||
15 | perl Configure b | ||
16 | make | ||
17 | apps/ssleay version -v -b -f >speed.1 | ||
18 | apps/ssleay speed >speed.1l | ||
19 | |||
20 | perl Configure bl-4c-2c | ||
21 | /bin/rm -f crypto/rc4/*.o crypto/bn/bn*.o crypto/md2/md2_dgst.o | ||
22 | make | ||
23 | apps/ssleay speed rc4 rsa md2 >speed.2l | ||
24 | |||
25 | perl Configure bl-4c-ri | ||
26 | /bin/rm -f crypto/rc4/rc4*.o | ||
27 | make | ||
28 | apps/ssleay speed rc4 >speed.3l | ||
29 | |||
30 | perl Configure b2-is-ri-dp | ||
31 | /bin/rm -f crypto/idea/i_*.o crypto/rc4/*.o crypto/des/ecb_enc.o crypto/bn/bn*.o | ||
32 | apps/ssleay speed rsa rc4 idea des >speed.4l | ||
33 | |||
34 | cat speed.1 >speed.log | ||
35 | cat speed.1l >>speed.log | ||
36 | perl util/sp-diff.pl speed.1l speed.2l >>speed.log | ||
37 | perl util/sp-diff.pl speed.1l speed.3l >>speed.log | ||
38 | perl util/sp-diff.pl speed.1l speed.4l >>speed.log | ||
39 | |||
diff --git a/src/lib/libcrypto/util/src-dep.pl b/src/lib/libcrypto/util/src-dep.pl new file mode 100644 index 0000000000..91242f7bb6 --- /dev/null +++ b/src/lib/libcrypto/util/src-dep.pl | |||
@@ -0,0 +1,147 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | # we make up an array of | ||
4 | # $file{function_name}=filename; | ||
5 | # $unres{filename}="func1 func2 ...." | ||
6 | $debug=1; | ||
7 | #$nm_func="parse_linux"; | ||
8 | $nm_func="parse_solaris"; | ||
9 | |||
10 | foreach (@ARGV) | ||
11 | { | ||
12 | &$nm_func($_); | ||
13 | } | ||
14 | |||
15 | foreach $file (sort keys %unres) | ||
16 | { | ||
17 | @a=split(/\s+/,$unres{$file}); | ||
18 | %ff=(); | ||
19 | foreach $func (@a) | ||
20 | { | ||
21 | $f=$file{$func}; | ||
22 | $ff{$f}=1 if $f ne ""; | ||
23 | } | ||
24 | |||
25 | foreach $a (keys %ff) | ||
26 | { $we_need{$file}.="$a "; } | ||
27 | } | ||
28 | |||
29 | foreach $file (sort keys %we_need) | ||
30 | { | ||
31 | # print " $file $we_need{$file}\n"; | ||
32 | foreach $bit (split(/\s+/,$we_need{$file})) | ||
33 | { push(@final,&walk($bit)); } | ||
34 | |||
35 | foreach (@final) { $fin{$_}=1; } | ||
36 | @final=""; | ||
37 | foreach (sort keys %fin) | ||
38 | { push(@final,$_); } | ||
39 | |||
40 | print "$file: @final\n"; | ||
41 | } | ||
42 | |||
43 | sub walk | ||
44 | { | ||
45 | local($f)=@_; | ||
46 | local(@a,%seen,@ret,$r); | ||
47 | |||
48 | @ret=""; | ||
49 | $f =~ s/^\s+//; | ||
50 | $f =~ s/\s+$//; | ||
51 | return "" if ($f =~ "^\s*$"); | ||
52 | |||
53 | return(split(/\s/,$done{$f})) if defined ($done{$f}); | ||
54 | |||
55 | return if $in{$f} > 0; | ||
56 | $in{$f}++; | ||
57 | push(@ret,$f); | ||
58 | foreach $r (split(/\s+/,$we_need{$f})) | ||
59 | { | ||
60 | push(@ret,&walk($r)); | ||
61 | } | ||
62 | $in{$f}--; | ||
63 | $done{$f}=join(" ",@ret); | ||
64 | return(@ret); | ||
65 | } | ||
66 | |||
67 | sub parse_linux | ||
68 | { | ||
69 | local($name)=@_; | ||
70 | |||
71 | open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n"; | ||
72 | while (<IN>) | ||
73 | { | ||
74 | chop; | ||
75 | next if /^\s*$/; | ||
76 | if (/^[^[](.*):$/) | ||
77 | { | ||
78 | $file=$1; | ||
79 | $file="$1.c" if /\[(.*).o\]/; | ||
80 | print STDERR "$file\n"; | ||
81 | $we_need{$file}=" "; | ||
82 | next; | ||
83 | } | ||
84 | |||
85 | @a=split(/\s*\|\s*/); | ||
86 | next unless $#a == 7; | ||
87 | next unless $a[4] eq "GLOB"; | ||
88 | if ($a[6] eq "UNDEF") | ||
89 | { | ||
90 | $unres{$file}.=$a[7]." "; | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | if ($file{$a[7]} ne "") | ||
95 | { | ||
96 | print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n"; | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | $file{$a[7]}=$file; | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | close(IN); | ||
105 | } | ||
106 | |||
107 | sub parse_solaris | ||
108 | { | ||
109 | local($name)=@_; | ||
110 | |||
111 | open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n"; | ||
112 | while (<IN>) | ||
113 | { | ||
114 | chop; | ||
115 | next if /^\s*$/; | ||
116 | if (/^(\S+):$/) | ||
117 | { | ||
118 | $file=$1; | ||
119 | #$file="$1.c" if $file =~ /^(.*).o$/; | ||
120 | print STDERR "$file\n"; | ||
121 | $we_need{$file}=" "; | ||
122 | next; | ||
123 | } | ||
124 | @a=split(/\s*\|\s*/); | ||
125 | next unless $#a == 7; | ||
126 | next unless $a[4] eq "GLOB"; | ||
127 | if ($a[6] eq "UNDEF") | ||
128 | { | ||
129 | $unres{$file}.=$a[7]." "; | ||
130 | print STDERR "$file needs $a[7]\n" if $debug; | ||
131 | } | ||
132 | else | ||
133 | { | ||
134 | if ($file{$a[7]} ne "") | ||
135 | { | ||
136 | print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n"; | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | $file{$a[7]}=$file; | ||
141 | print STDERR "$file has $a[7]\n" if $debug; | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | close(IN); | ||
146 | } | ||
147 | |||
diff --git a/src/lib/libcrypto/util/ssleay.num b/src/lib/libcrypto/util/ssleay.num new file mode 100644 index 0000000000..359fa15df1 --- /dev/null +++ b/src/lib/libcrypto/util/ssleay.num | |||
@@ -0,0 +1,156 @@ | |||
1 | ERR_load_SSL_strings 1 | ||
2 | SSL_CIPHER_description 2 | ||
3 | SSL_CTX_add_client_CA 3 | ||
4 | SSL_CTX_add_session 4 | ||
5 | SSL_CTX_check_private_key 5 | ||
6 | SSL_CTX_ctrl 6 | ||
7 | SSL_CTX_flush_sessions 7 | ||
8 | SSL_CTX_free 8 | ||
9 | SSL_CTX_get_client_CA_list 9 | ||
10 | SSL_CTX_get_verify_callback 10 | ||
11 | SSL_CTX_get_verify_mode 11 | ||
12 | SSL_CTX_new 12 | ||
13 | SSL_CTX_remove_session 13 | ||
14 | SSL_CTX_set_cert_verify_cb 14 | ||
15 | SSL_CTX_set_cipher_list 15 | ||
16 | SSL_CTX_set_client_CA_list 16 | ||
17 | SSL_CTX_set_default_passwd_cb 17 | ||
18 | SSL_CTX_set_ssl_version 19 | ||
19 | SSL_CTX_set_verify 21 | ||
20 | SSL_CTX_use_PrivateKey 22 | ||
21 | SSL_CTX_use_PrivateKey_ASN1 23 | ||
22 | SSL_CTX_use_PrivateKey_file 24 | ||
23 | SSL_CTX_use_RSAPrivateKey 25 | ||
24 | SSL_CTX_use_RSAPrivateKey_ASN1 26 | ||
25 | SSL_CTX_use_RSAPrivateKey_file 27 | ||
26 | SSL_CTX_use_certificate 28 | ||
27 | SSL_CTX_use_certificate_ASN1 29 | ||
28 | SSL_CTX_use_certificate_file 30 | ||
29 | SSL_SESSION_free 31 | ||
30 | SSL_SESSION_new 32 | ||
31 | SSL_SESSION_print 33 | ||
32 | SSL_SESSION_print_fp 34 | ||
33 | SSL_accept 35 | ||
34 | SSL_add_client_CA 36 | ||
35 | SSL_alert_desc_string 37 | ||
36 | SSL_alert_desc_string_long 38 | ||
37 | SSL_alert_type_string 39 | ||
38 | SSL_alert_type_string_long 40 | ||
39 | SSL_check_private_key 41 | ||
40 | SSL_clear 42 | ||
41 | SSL_connect 43 | ||
42 | SSL_copy_session_id 44 | ||
43 | SSL_ctrl 45 | ||
44 | SSL_dup 46 | ||
45 | SSL_dup_CA_list 47 | ||
46 | SSL_free 48 | ||
47 | SSL_get_certificate 49 | ||
48 | SSL_get_cipher_list 52 | ||
49 | SSL_get_ciphers 55 | ||
50 | SSL_get_client_CA_list 56 | ||
51 | SSL_get_default_timeout 57 | ||
52 | SSL_get_error 58 | ||
53 | SSL_get_fd 59 | ||
54 | SSL_get_peer_cert_chain 60 | ||
55 | SSL_get_peer_certificate 61 | ||
56 | SSL_get_rbio 63 | ||
57 | SSL_get_read_ahead 64 | ||
58 | SSL_get_shared_ciphers 65 | ||
59 | SSL_get_ssl_method 66 | ||
60 | SSL_get_verify_callback 69 | ||
61 | SSL_get_verify_mode 70 | ||
62 | SSL_get_version 71 | ||
63 | SSL_get_wbio 72 | ||
64 | SSL_load_client_CA_file 73 | ||
65 | SSL_load_error_strings 74 | ||
66 | SSL_new 75 | ||
67 | SSL_peek 76 | ||
68 | SSL_pending 77 | ||
69 | SSL_read 78 | ||
70 | SSL_renegotiate 79 | ||
71 | SSL_rstate_string 80 | ||
72 | SSL_rstate_string_long 81 | ||
73 | SSL_set_accept_state 82 | ||
74 | SSL_set_bio 83 | ||
75 | SSL_set_cipher_list 84 | ||
76 | SSL_set_client_CA_list 85 | ||
77 | SSL_set_connect_state 86 | ||
78 | SSL_set_fd 87 | ||
79 | SSL_set_read_ahead 88 | ||
80 | SSL_set_rfd 89 | ||
81 | SSL_set_session 90 | ||
82 | SSL_set_ssl_method 91 | ||
83 | SSL_set_verify 94 | ||
84 | SSL_set_wfd 95 | ||
85 | SSL_shutdown 96 | ||
86 | SSL_state_string 97 | ||
87 | SSL_state_string_long 98 | ||
88 | SSL_use_PrivateKey 99 | ||
89 | SSL_use_PrivateKey_ASN1 100 | ||
90 | SSL_use_PrivateKey_file 101 | ||
91 | SSL_use_RSAPrivateKey 102 | ||
92 | SSL_use_RSAPrivateKey_ASN1 103 | ||
93 | SSL_use_RSAPrivateKey_file 104 | ||
94 | SSL_use_certificate 105 | ||
95 | SSL_use_certificate_ASN1 106 | ||
96 | SSL_use_certificate_file 107 | ||
97 | SSL_write 108 | ||
98 | SSLeay_add_ssl_algorithms 109 | ||
99 | SSLv23_client_method 110 | ||
100 | SSLv23_method 111 | ||
101 | SSLv23_server_method 112 | ||
102 | SSLv2_client_method 113 | ||
103 | SSLv2_method 114 | ||
104 | SSLv2_server_method 115 | ||
105 | SSLv3_client_method 116 | ||
106 | SSLv3_method 117 | ||
107 | SSLv3_server_method 118 | ||
108 | d2i_SSL_SESSION 119 | ||
109 | i2d_SSL_SESSION 120 | ||
110 | BIO_f_ssl 121 | ||
111 | BIO_new_ssl 122 | ||
112 | BIO_proxy_ssl_copy_session_id 123 | ||
113 | BIO_ssl_copy_session_id 124 | ||
114 | SSL_do_handshake 125 | ||
115 | SSL_get_privatekey 126 | ||
116 | SSL_get_current_cipher 127 | ||
117 | SSL_CIPHER_get_bits 128 | ||
118 | SSL_CIPHER_get_version 129 | ||
119 | SSL_CIPHER_get_name 130 | ||
120 | BIO_ssl_shutdown 131 | ||
121 | SSL_SESSION_cmp 132 | ||
122 | SSL_SESSION_hash 133 | ||
123 | SSL_SESSION_get_time 134 | ||
124 | SSL_SESSION_set_time 135 | ||
125 | SSL_SESSION_get_timeout 136 | ||
126 | SSL_SESSION_set_timeout 137 | ||
127 | SSL_CTX_get_ex_data 138 | ||
128 | SSL_CTX_get_quiet_shutdown 140 | ||
129 | SSL_CTX_load_verify_locations 141 | ||
130 | SSL_CTX_set_default_verify_paths 142 | ||
131 | SSL_CTX_set_ex_data 143 | ||
132 | SSL_CTX_set_quiet_shutdown 145 | ||
133 | SSL_SESSION_get_ex_data 146 | ||
134 | SSL_SESSION_set_ex_data 148 | ||
135 | SSL_get_SSL_CTX 150 | ||
136 | SSL_get_ex_data 151 | ||
137 | SSL_get_quiet_shutdown 153 | ||
138 | SSL_get_session 154 | ||
139 | SSL_get_shutdown 155 | ||
140 | SSL_get_verify_result 157 | ||
141 | SSL_set_ex_data 158 | ||
142 | SSL_set_info_callback 160 | ||
143 | SSL_set_quiet_shutdown 161 | ||
144 | SSL_set_shutdown 162 | ||
145 | SSL_set_verify_result 163 | ||
146 | SSL_version 164 | ||
147 | SSL_get_info_callback 165 | ||
148 | SSL_state 166 | ||
149 | SSL_CTX_get_ex_new_index 167 | ||
150 | SSL_SESSION_get_ex_new_index 168 | ||
151 | SSL_get_ex_new_index 169 | ||
152 | TLSv1_method 170 | ||
153 | TLSv1_server_method 171 | ||
154 | TLSv1_client_method 172 | ||
155 | BIO_new_buffer_ssl_connect 173 | ||
156 | BIO_new_ssl_connect 174 | ||
diff --git a/src/lib/libcrypto/util/tab_num.pl b/src/lib/libcrypto/util/tab_num.pl new file mode 100644 index 0000000000..77b591d92f --- /dev/null +++ b/src/lib/libcrypto/util/tab_num.pl | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | $num=1; | ||
4 | $width=40; | ||
5 | |||
6 | while (<>) | ||
7 | { | ||
8 | chop; | ||
9 | |||
10 | $i=length($_); | ||
11 | |||
12 | $n=$width-$i; | ||
13 | $i=int(($n+7)/8); | ||
14 | print $_.("\t" x $i).$num."\n"; | ||
15 | $num++; | ||
16 | } | ||
17 | |||
diff --git a/src/lib/libcrypto/util/x86asm.sh b/src/lib/libcrypto/util/x86asm.sh new file mode 100644 index 0000000000..81d3289860 --- /dev/null +++ b/src/lib/libcrypto/util/x86asm.sh | |||
@@ -0,0 +1,42 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | echo Generating x86 assember | ||
4 | echo Bignum | ||
5 | (cd crypto/bn/asm; perl bn-586.pl cpp > bn86unix.cpp) | ||
6 | (cd crypto/bn/asm; perl bn-586.pl win32 > bn-win32.asm) | ||
7 | |||
8 | echo DES | ||
9 | (cd crypto/des/asm; perl des-586.pl cpp > dx86unix.cpp) | ||
10 | (cd crypto/des/asm; perl des-586.pl win32 > d-win32.asm) | ||
11 | |||
12 | echo "crypt(3)" | ||
13 | (cd crypto/des/asm; perl crypt586.pl cpp > yx86unix.cpp) | ||
14 | (cd crypto/des/asm; perl crypt586.pl win32 > y-win32.asm) | ||
15 | |||
16 | echo Blowfish | ||
17 | (cd crypto/bf/asm; perl bf-586.pl cpp > bx86unix.cpp) | ||
18 | (cd crypto/bf/asm; perl bf-586.pl win32 > b-win32.asm) | ||
19 | |||
20 | echo CAST5 | ||
21 | (cd crypto/cast/asm; perl cast-586.pl cpp > cx86unix.cpp) | ||
22 | (cd crypto/cast/asm; perl cast-586.pl win32 > c-win32.asm) | ||
23 | |||
24 | echo RC4 | ||
25 | (cd crypto/rc4/asm; perl rc4-586.pl cpp > rx86unix.cpp) | ||
26 | (cd crypto/rc4/asm; perl rc4-586.pl win32 > r4-win32.asm) | ||
27 | |||
28 | echo MD5 | ||
29 | (cd crypto/md5/asm; perl md5-586.pl cpp > mx86unix.cpp) | ||
30 | (cd crypto/md5/asm; perl md5-586.pl win32 > m5-win32.asm) | ||
31 | |||
32 | echo SHA1 | ||
33 | (cd crypto/sha/asm; perl sha1-586.pl cpp > sx86unix.cpp) | ||
34 | (cd crypto/sha/asm; perl sha1-586.pl win32 > s1-win32.asm) | ||
35 | |||
36 | echo RIPEMD160 | ||
37 | (cd crypto/ripemd/asm; perl rmd-586.pl cpp > rm86unix.cpp) | ||
38 | (cd crypto/ripemd/asm; perl rmd-586.pl win32 > rm-win32.asm) | ||
39 | |||
40 | echo RC5/32 | ||
41 | (cd crypto/rc5/asm; perl rc5-586.pl cpp > r586unix.cpp) | ||
42 | (cd crypto/rc5/asm; perl rc5-586.pl win32 > r5-win32.asm) | ||