summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto
diff options
context:
space:
mode:
authorryker <>1998-10-05 20:13:15 +0000
committerryker <>1998-10-05 20:13:15 +0000
commit9e77c62555877f9a64805c49d0dcd7dbfbb40f4e (patch)
tree2a6396b738ecede1e1dd3ad84c90e47e21d0bcbd /src/lib/libcrypto
parentfe5d0717e2760d02faf23bf5a714f17b33ae4abb (diff)
parent536c76cbb863bab152f19842ab88772c01e922c7 (diff)
downloadopenbsd-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')
-rw-r--r--src/lib/libcrypto/Attic/Makefile133
-rw-r--r--src/lib/libcrypto/asn1/a_hdr.c130
-rw-r--r--src/lib/libcrypto/asn1/a_meth.c84
-rw-r--r--src/lib/libcrypto/asn1/a_utctm.c212
-rw-r--r--src/lib/libcrypto/bf/asm/bf-686.pl128
-rw-r--r--src/lib/libcrypto/bf/asm/readme10
-rw-r--r--src/lib/libcrypto/bf/bf_opts.c347
-rw-r--r--src/lib/libcrypto/bf/bfs.cpp67
-rw-r--r--src/lib/libcrypto/bf/bfspeed.c293
-rw-r--r--src/lib/libcrypto/bf/bftest.c521
-rw-r--r--src/lib/libcrypto/bio/bss_rtcp.c297
-rw-r--r--src/lib/libcrypto/bn/asm/README30
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.s344
-rw-r--r--src/lib/libcrypto/bn/asm/pa-risc.s710
-rw-r--r--src/lib/libcrypto/bn/asm/r3000.s646
-rw-r--r--src/lib/libcrypto/bn/bnspeed.c248
-rw-r--r--src/lib/libcrypto/bn/bntest.c777
-rw-r--r--src/lib/libcrypto/bn/expspeed.c230
-rw-r--r--src/lib/libcrypto/bn/exptest.c148
-rw-r--r--src/lib/libcrypto/cast/asm/readme7
-rw-r--r--src/lib/libcrypto/cast/cast_spd.c294
-rw-r--r--src/lib/libcrypto/cast/castopts.c358
-rw-r--r--src/lib/libcrypto/cast/casts.cpp70
-rw-r--r--src/lib/libcrypto/cast/casttest.c223
-rw-r--r--src/lib/libcrypto/conf/cnf_save.c106
-rw-r--r--src/lib/libcrypto/conf/test.c91
-rw-r--r--src/lib/libcrypto/des/DES.pm19
-rw-r--r--src/lib/libcrypto/des/DES.xs268
-rw-r--r--src/lib/libcrypto/des/INSTALL69
-rw-r--r--src/lib/libcrypto/des/Imakefile35
-rw-r--r--src/lib/libcrypto/des/KERBEROS41
-rw-r--r--src/lib/libcrypto/des/README54
-rw-r--r--src/lib/libcrypto/des/VERSION411
-rw-r--r--src/lib/libcrypto/des/asm/des686.pl230
-rw-r--r--src/lib/libcrypto/des/asm/readme131
-rw-r--r--src/lib/libcrypto/des/cbc3_enc.c99
-rw-r--r--src/lib/libcrypto/des/des.c964
-rw-r--r--src/lib/libcrypto/des/des3s.cpp67
-rw-r--r--src/lib/libcrypto/des/des_opts.c620
-rw-r--r--src/lib/libcrypto/des/des_ver.h60
-rw-r--r--src/lib/libcrypto/des/dess.cpp67
-rw-r--r--src/lib/libcrypto/des/destest.c882
-rw-r--r--src/lib/libcrypto/des/makefile.bc50
-rw-r--r--src/lib/libcrypto/des/options.txt39
-rw-r--r--src/lib/libcrypto/des/read2pwd.c90
-rw-r--r--src/lib/libcrypto/des/read_pwd.c459
-rw-r--r--src/lib/libcrypto/des/rpc_des.h131
-rw-r--r--src/lib/libcrypto/des/rpc_enc.c107
-rw-r--r--src/lib/libcrypto/des/rpw.c101
-rw-r--r--src/lib/libcrypto/des/speed.c329
-rw-r--r--src/lib/libcrypto/des/t/test27
-rw-r--r--src/lib/libcrypto/des/times/486-50.sol16
-rw-r--r--src/lib/libcrypto/des/times/586-100.lnx20
-rw-r--r--src/lib/libcrypto/des/times/686-200.fre18
-rw-r--r--src/lib/libcrypto/des/times/aix.cc26
-rw-r--r--src/lib/libcrypto/des/times/alpha.cc18
-rw-r--r--src/lib/libcrypto/des/times/hpux.cc17
-rw-r--r--src/lib/libcrypto/des/times/sparc.gcc17
-rw-r--r--src/lib/libcrypto/des/times/usparc.cc31
-rw-r--r--src/lib/libcrypto/des/typemap34
-rw-r--r--src/lib/libcrypto/dh/dh1024.pem5
-rw-r--r--src/lib/libcrypto/dh/dh192.pem3
-rw-r--r--src/lib/libcrypto/dh/dh2048.pem16
-rw-r--r--src/lib/libcrypto/dh/dh4096.pem14
-rw-r--r--src/lib/libcrypto/dh/dh512.pem4
-rw-r--r--src/lib/libcrypto/dh/dhtest.c188
-rw-r--r--src/lib/libcrypto/dh/example50
-rw-r--r--src/lib/libcrypto/dh/generate65
-rw-r--r--src/lib/libcrypto/dh/p1024.c92
-rw-r--r--src/lib/libcrypto/dh/p192.c80
-rw-r--r--src/lib/libcrypto/dh/p512.c85
-rw-r--r--src/lib/libcrypto/dsa/README4
-rw-r--r--src/lib/libcrypto/dsa/dsagen.c112
-rw-r--r--src/lib/libcrypto/dsa/dsatest.c214
-rw-r--r--src/lib/libcrypto/dsa/fips186a.txt122
-rw-r--r--src/lib/libcrypto/evp/e_dsa.c71
-rw-r--r--src/lib/libcrypto/evp/m_md2.c82
-rw-r--r--src/lib/libcrypto/evp/m_mdc2.c81
-rw-r--r--src/lib/libcrypto/evp/m_sha.c82
-rw-r--r--src/lib/libcrypto/hmac/hmactest.c147
-rw-r--r--src/lib/libcrypto/lhash/lh_test.c89
-rw-r--r--src/lib/libcrypto/lhash/num.pl17
-rw-r--r--src/lib/libcrypto/md2/md2.c136
-rw-r--r--src/lib/libcrypto/md2/md2_dgst.c235
-rw-r--r--src/lib/libcrypto/md2/md2_one.c80
-rw-r--r--src/lib/libcrypto/md2/md2test.c130
-rw-r--r--src/lib/libcrypto/md5/md5.c135
-rw-r--r--src/lib/libcrypto/md5/md5s.cpp78
-rw-r--r--src/lib/libcrypto/md5/md5test.c130
-rw-r--r--src/lib/libcrypto/mdc2/mdc2.h100
-rw-r--r--src/lib/libcrypto/mem.c353
-rw-r--r--src/lib/libcrypto/objects/obj_dat.h656
-rw-r--r--src/lib/libcrypto/perlasm/x86ms.pl348
-rw-r--r--src/lib/libcrypto/perlasm/x86unix.pl429
-rw-r--r--src/lib/libcrypto/pkcs7/doc24
-rw-r--r--src/lib/libcrypto/pkcs7/enc.c144
-rw-r--r--src/lib/libcrypto/pkcs7/p7/a12
-rw-r--r--src/lib/libcrypto/pkcs7/p7/a21
-rw-r--r--src/lib/libcrypto/pkcs7/p7/cert.p7cbin0 -> 1728 bytes
-rw-r--r--src/lib/libcrypto/pkcs7/p7/smime.p7mbin0 -> 4894 bytes
-rw-r--r--src/lib/libcrypto/pkcs7/p7/smime.p7sbin0 -> 2625 bytes
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_dgst.c66
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_enc.c76
-rw-r--r--src/lib/libcrypto/pkcs7/server.pem24
-rw-r--r--src/lib/libcrypto/pkcs7/sign.c140
-rw-r--r--src/lib/libcrypto/pkcs7/verify.c238
-rw-r--r--src/lib/libcrypto/rand/md_rand.c405
-rw-r--r--src/lib/libcrypto/rand/randtest.c207
-rw-r--r--src/lib/libcrypto/rc2/rc2speed.c293
-rw-r--r--src/lib/libcrypto/rc2/rc2test.c270
-rw-r--r--src/lib/libcrypto/rc4/rc4.c194
-rw-r--r--src/lib/libcrypto/rc4/rc4s.cpp73
-rw-r--r--src/lib/libcrypto/rc4/rc4speed.c269
-rw-r--r--src/lib/libcrypto/rc4/rc4test.c195
-rw-r--r--src/lib/libcrypto/rc4/rrc4.doc278
-rw-r--r--src/lib/libcrypto/rc5/rc5.h122
-rw-r--r--src/lib/libcrypto/ripemd/asm/rips.cpp78
-rw-r--r--src/lib/libcrypto/ripemd/rmd160.c135
-rw-r--r--src/lib/libcrypto/ripemd/rmdtest.c133
-rw-r--r--src/lib/libcrypto/sha/asm/README1
-rw-r--r--src/lib/libcrypto/sha/sha.c135
-rw-r--r--src/lib/libcrypto/sha/sha1.c135
-rw-r--r--src/lib/libcrypto/sha/sha1s.cpp79
-rw-r--r--src/lib/libcrypto/sha/sha1test.c155
-rw-r--r--src/lib/libcrypto/sha/sha_dgst.c442
-rw-r--r--src/lib/libcrypto/sha/sha_one.c77
-rw-r--r--src/lib/libcrypto/sha/shatest.c155
-rw-r--r--src/lib/libcrypto/threads/mttest.c1115
-rw-r--r--src/lib/libcrypto/threads/th-lock.c399
-rw-r--r--src/lib/libcrypto/tmdiff.c217
-rw-r--r--src/lib/libcrypto/util/FreeBSD.sh6
-rw-r--r--src/lib/libcrypto/util/add_cr.pl123
-rw-r--r--src/lib/libcrypto/util/bat.sh132
-rw-r--r--src/lib/libcrypto/util/ck_errf.pl44
-rw-r--r--src/lib/libcrypto/util/deleof.pl7
-rw-r--r--src/lib/libcrypto/util/do_ms.sh17
-rw-r--r--src/lib/libcrypto/util/err-ins.pl33
-rw-r--r--src/lib/libcrypto/util/files.pl61
-rw-r--r--src/lib/libcrypto/util/fixNT.sh14
-rw-r--r--src/lib/libcrypto/util/install.sh108
-rw-r--r--src/lib/libcrypto/util/libeay.num1065
-rw-r--r--src/lib/libcrypto/util/mk1mf.pl793
-rw-r--r--src/lib/libcrypto/util/mkcerts.sh220
-rw-r--r--src/lib/libcrypto/util/mkdef.pl292
-rw-r--r--src/lib/libcrypto/util/perlpath.pl30
-rw-r--r--src/lib/libcrypto/util/pl/BC-16.pl146
-rw-r--r--src/lib/libcrypto/util/pl/BC-32.pl135
-rw-r--r--src/lib/libcrypto/util/pl/VC-16.pl173
-rw-r--r--src/lib/libcrypto/util/pl/VC-32.pl133
-rw-r--r--src/lib/libcrypto/util/pl/linux.pl96
-rw-r--r--src/lib/libcrypto/util/pl/unix.pl83
-rw-r--r--src/lib/libcrypto/util/point.sh4
-rw-r--r--src/lib/libcrypto/util/sp-diff.pl80
-rw-r--r--src/lib/libcrypto/util/speed.sh39
-rw-r--r--src/lib/libcrypto/util/src-dep.pl147
-rw-r--r--src/lib/libcrypto/util/ssleay.num156
-rw-r--r--src/lib/libcrypto/util/tab_num.pl17
-rw-r--r--src/lib/libcrypto/util/x86asm.sh42
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 @@
1LIB= crypto
2CFLAGS+= -DNO_IDEA -DTERMIOS -DL_ENDIAN -DANSI_SOURCE
3CFLAGS+= -I${.CURDIR}/../include
4SRCS+= cryptlib.c mem.c cversion.c ex_data.c cpt_err.c
5CFLAGS+= -I${.CURDIR}/md2
6SRCS+= md2_dgst.c md2_one.c
7CFLAGS+= -I${.CURDIR}/md5
8SRCS+= md5_dgst.c md5_one.c
9CFLAGS+= -I${.CURDIR}/sha
10SRCS+= sha_dgst.c sha1dgst.c sha_one.c sha1_one.c
11CFLAGS+= -I${.CURDIR}/mdc2
12SRCS+= mdc2dgst.c mdc2_one.c
13CFLAGS+= -I${.CURDIR}/hmac
14SRCS+= hmac.c
15CFLAGS+= -I${.CURDIR}/ripemd
16SRCS+= rmd_dgst.c rmd_one.c
17CFLAGS+= -I${.CURDIR}/des
18SRCS+= set_key.c ecb_enc.c cbc_enc.c ecb3_enc.c
19SRCS+= cfb64enc.c cfb64ede.c cfb_enc.c ofb64ede.c
20SRCS+= enc_read.c enc_writ.c ofb64enc.c ofb_enc.c
21SRCS+= str2key.c pcbc_enc.c qud_cksm.c rand_key.c
22SRCS+= read2pwd.c fcrypt.c xcbc_enc.c read_pwd.c
23SRCS+= rpc_enc.c cbc_cksm.c supp.c
24CFLAGS+= -I${.CURDIR}/rc2
25SRCS+= rc2_ecb.c rc2_skey.c rc2_cbc.c rc2cfb64.c
26SRCS+= rc2ofb64.c
27CFLAGS+= -I${.CURDIR}/rc4
28SRCS+= rc4_skey.c
29CFLAGS+= -I${.CURDIR}/rc5
30SRCS+= rc5_skey.c rc5_ecb.c rc5cfb64.c rc5cfb64.c
31SRCS+= rc5ofb64.c
32CFLAGS+= -I${.CURDIR}/idea
33SRCS+= i_cbc.c i_cfb64.c i_ofb64.c i_ecb.c
34SRCS+= i_skey.c
35CFLAGS+= -I${.CURDIR}/bf
36SRCS+= bf_skey.c bf_ecb.c bf_cfb64.c bf_ofb64.c
37CFLAGS+= -I${.CURDIR}/cast
38SRCS+= c_skey.c c_ecb.c c_cfb64.c c_ofb64.c
39CFLAGS+= -I${.CURDIR}/bn
40SRCS+= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mod.c
41SRCS+= bn_mul.c bn_print.c bn_rand.c bn_shift.c bn_sub.c
42SRCS+= bn_word.c bn_blind.c bn_gcd.c bn_prime.c bn_err.c
43SRCS+= bn_sqr.c bn_recp.c bn_mont.c bn_mpi.c
44CFLAGS+= -I${.CURDIR}/rsa
45SRCS+= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c
46SRCS+= rsa_saos.c rsa_err.c rsa_pk1.c rsa_ssl.c
47SRCS+= rsa_none.c
48CFLAGS+= -I${.CURDIR}/dsa
49SRCS+= dsa_gen.c dsa_key.c dsa_lib.c dsa_vrf.c
50SRCS+= dsa_sign.c dsa_err.c
51CFLAGS+= -I${.CURDIR}/dh
52SRCS+= dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c
53CFLAGS+= -I${.CURDIR}/buffer
54SRCS+= buffer.c buf_err.c
55CFLAGS+= -I${.CURDIR}/bio
56SRCS+= bio_lib.c bio_cb.c bio_err.c bss_mem.c
57SRCS+= bss_null.c bss_fd.c bss_file.c bss_sock.c
58SRCS+= bss_conn.c bf_null.c bf_buff.c
59SRCS+= b_print.c b_dump.c b_sock.c bss_acpt.c
60SRCS+= bf_nbio.c
61CFLAGS+= -I${.CURDIR}/stack
62SRCS+= stack.c
63CFLAGS+= -I${.CURDIR}/lhash
64SRCS+= lhash.c lh_stats.c
65CFLAGS+= -I${.CURDIR}/rand
66SRCS+= md_rand.c randfile.c
67CFLAGS+= -I${.CURDIR}/err
68SRCS+= err.c err_all.c err_prn.c
69CFLAGS+= -I${.CURDIR}/objects
70SRCS+= obj_dat.c obj_lib.c obj_err.c
71CFLAGS+= -I${.CURDIR}/evp
72SRCS+= encode.c digest.c evp_enc.c evp_key.c
73SRCS+= e_ecb_d.c e_cbc_d.c e_cfb_d.c e_ofb_d.c
74SRCS+= e_ecb_i.c e_cbc_i.c e_cfb_i.c e_ofb_i.c
75SRCS+= e_ecb_3d.c e_cbc_3d.c e_rc4.c names.c
76SRCS+= e_cfb_3d.c e_ofb_3d.c e_xcbc_d.c e_ecb_r2.c
77SRCS+= e_cbc_r2.c e_cfb_r2.c e_ofb_r2.c e_ecb_bf.c
78SRCS+= e_cbc_bf.c e_cfb_bf.c e_ofb_bf.c e_ecb_c.c
79SRCS+= e_cbc_c.c e_cfb_c.c e_ofb_c.c e_ecb_r5.c
80SRCS+= e_cbc_r5.c e_cfb_r5.c e_ofb_r5.c m_null.c
81SRCS+= m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c
82SRCS+= m_dss1.c m_mdc2.c m_ripemd.c p_open.c
83SRCS+= p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c
84SRCS+= p_dec.c bio_md.c bio_b64.c bio_enc.c
85SRCS+= evp_err.c e_null.c c_all.c evp_lib.c
86CFLAGS+= -I${.CURDIR}/pem
87SRCS+= pem_sign.c pem_seal.c pem_info.c pem_lib.c
88SRCS+= pem_all.c pem_err.c
89CFLAGS+= -I${.CURDIR}/asn1
90SRCS+= a_object.c a_bitstr.c a_utctm.c a_int.c
91SRCS+= a_octet.c a_print.c a_type.c a_set.c
92SRCS+= a_dup.c a_d2i_fp.c a_i2d_fp.c a_sign.c
93SRCS+= a_digest.c a_verify.c x_algor.c x_val.c
94SRCS+= x_pubkey.c x_sig.c x_req.c x_attrib.c
95SRCS+= x_name.c x_cinf.c x_x509.c x_crl.c
96SRCS+= x_info.c x_spki.c d2i_r_pr.c i2d_r_pr.c
97SRCS+= d2i_r_pu.c i2d_r_pu.c d2i_s_pr.c i2d_s_pr.c
98SRCS+= d2i_s_pu.c i2d_s_pu.c d2i_pu.c d2i_pr.c
99SRCS+= i2d_pu.c i2d_pr.c t_req.c t_x509.c
100SRCS+= t_pkey.c p7_i_s.c p7_signi.c p7_signd.c
101SRCS+= p7_recip.c p7_enc_c.c p7_evp.c p7_dgst.c
102SRCS+= p7_s_e.c p7_enc.c p7_lib.c f_int.c
103SRCS+= f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c
104SRCS+= d2i_dsap.c n_pkey.c a_hdr.c x_pkey.c
105SRCS+= a_bool.c x_exten.c asn1_par.c asn1_lib.c
106SRCS+= asn1_err.c a_meth.c a_bytes.c evp_asn1.c
107CFLAGS+= -I${.CURDIR}/x509
108SRCS+= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c
109SRCS+= x509_obj.c x509_req.c x509_vfy.c x509_set.c
110SRCS+= x509rset.c x509_err.c x509name.c x509_v3.c
111SRCS+= x509_ext.c x509pack.c x509type.c x509_lu.c
112SRCS+= x_all.c x509_txt.c by_file.c by_dir.c
113SRCS+= v3_net.c v3_x509.c
114CFLAGS+= -I${.CURDIR}/conf
115SRCS+= conf.c conf_err.c
116CFLAGS+= -I${.CURDIR}/txt_db
117SRCS+= txt_db.c
118CFLAGS+= -I${.CURDIR}/pkcs7
119SRCS+= 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
71int i2d_ASN1_HEADER(a,pp)
72ASN1_HEADER *a;
73unsigned 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
88ASN1_HEADER *d2i_ASN1_HEADER(a,pp,length)
89ASN1_HEADER **a;
90unsigned char **pp;
91long 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
110ASN1_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
122void ASN1_HEADER_free(a)
123ASN1_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
64static 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
70static 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
76ASN1_METHOD *ASN1_IA5STRING_asn1_meth()
77 {
78 return(&ia5string_meth);
79 }
80
81ASN1_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
68int i2d_ASN1_UTCTIME(a,pp)
69ASN1_UTCTIME *a;
70unsigned char **pp;
71 {
72 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
73 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL));
74 }
75
76
77ASN1_UTCTIME *d2i_ASN1_UTCTIME(a, pp, length)
78ASN1_UTCTIME **a;
79unsigned char **pp;
80long 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);
98err:
99 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
100 ASN1_UTCTIME_free(ret);
101 return(NULL);
102 }
103
104int ASN1_UTCTIME_check(d)
105ASN1_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);
151err:
152 return(0);
153 }
154
155int ASN1_UTCTIME_set_string(s,str)
156ASN1_UTCTIME *s;
157char *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
177ASN1_UTCTIME *ASN1_UTCTIME_set(s, t)
178ASN1_UTCTIME *s;
179time_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
4push(@INC,"perlasm","../../perlasm");
5require "x86asm.pl";
6require "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
28sub 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
92sub 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
124sub 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 @@
1There are blowfish assembler generation scripts.
2bf-586.pl version is for the pentium and
3bf-686.pl is my original version, which is faster on the pentium pro.
4
5When using a bf-586.pl, the pentium pro/II is %8 slower than using
6bf-686.pl. When using a bf-686.pl, the pentium is %16 slower
7than bf-586.pl
8
9So 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>
71extern 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>
84struct 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)
143long run=0;
144
145#ifndef NOPROTO
146double Time_F(int s);
147#else
148double 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
159SIGRETTYPE sig_done(int sig);
160#else
161SIGRETTYPE sig_done();
162#endif
163
164SIGRETTYPE sig_done(sig)
165int 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
178double Time_F(s)
179int 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
240int main(argc,argv)
241int argc;
242char **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__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void 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)
22inline
23void 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
37void 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>
71extern 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>
84struct 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)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double 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
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int 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
151double Time_F(s)
152int 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
188int main(argc,argv)
189int argc;
190char **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
67char *bf_key[2]={
68 "abcdefghijklmnopqrstuvwxyz",
69 "Who is John Galt?"
70 };
71
72/* big endian */
73BF_LONG bf_plain[2][2]={
74 {0x424c4f57L,0x46495348L},
75 {0xfedcba98L,0x76543210L}
76 };
77
78BF_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
86static 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
122static 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
158static 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
195static unsigned char cbc_key [16]={
196 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
197 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
198static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
199static char cbc_data[40]="7654321 Now is the time for ";
200static 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
206static 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
212static 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
219unsigned 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
225unsigned char key_data[8]=
226 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10};
227
228unsigned 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
256static int test(void );
257static int print_test_data(void );
258#else
259static int test();
260static int print_test_data();
261#endif
262
263int main(argc,argv)
264int argc;
265char *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
278static 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
345static 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 */
71extern int SYS$QIOW();
72typedef unsigned short io_channel;
73/*************************************************************************/
74struct io_status { short status, count; long flags; };
75
76struct 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
84struct rpc_ctx {
85 int filled, pos;
86 struct rpc_msg msg;
87};
88
89static int rtcp_write(BIO *h,char *buf,int num);
90static int rtcp_read(BIO *h,char *buf,int size);
91static int rtcp_puts(BIO *h,char *str);
92static int rtcp_gets(BIO *h,char *str,int size);
93static long rtcp_ctrl(BIO *h,int cmd,long arg1,char *arg2);
94static int rtcp_new(BIO *h);
95static int rtcp_free(BIO *data);
96
97static 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
110BIO_METHOD *BIO_s_rtcp()
111 {
112 return(&rtcp_method);
113 }
114/*****************************************************************************/
115/* Decnet I/O routines.
116 */
117static 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
128static 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
139static int rtcp_new(bi)
140BIO *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
153static int rtcp_free(a)
154BIO *a;
155{
156 if (a == NULL) return(0);
157 if ( a->ptr ) Free ( a->ptr );
158 a->ptr = NULL;
159 return(1);
160}
161
162static int rtcp_read(b,out,outl)
163BIO *b;
164char *out;
165int 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
212static int rtcp_write(b,in,inl)
213BIO *b;
214char *in;
215int 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
244static long rtcp_ctrl(b,cmd,num,ptr)
245BIO *b;
246int cmd;
247long num;
248char *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
279static int rtcp_gets(bp,buf,size)
280BIO *bp;
281char *buf;
282int size;
283 {
284 return(0);
285 }
286
287static int rtcp_puts(bp,str)
288BIO *bp;
289char *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 @@
1All assember in this directory are just version of the file
2crypto/bn/bn_mulw.c.
3
4Quite a few of these files are just the assember output from gcc since on
5quite a few machines they are 2 times faster than the system compiler.
6
7For the x86, I have hand written assember because of the bad job all
8compilers seem to do on it. This normally gives a 2 time speed up in the RSA
9routines.
10
11For the DEC alpha, I also hand wrote the assember (except the division which
12is just the output from the C compiler pasted on the end of the file).
13On the 2 alpha C compilers I had access to, it was not possible to do
1464b x 64b -> 128b calculations (both long and the long long data types
15were 64 bits). So the hand assember gives access to the 128 bit result and
16a 2 times speedup :-).
17
18The x86xxxx.obj files are the assembled version of x86xxxx.asm files.
19I had such a hard time finding a macro assember for Microsoft, I decided to
20include the object file to save others the hassle :-).
21
22I have also included uu encoded versions of the .obj incase they get
23trashed.
24
25There are 2 versions of assember for the HP PA-RISC.
26pa-risc.s is the origional one which works fine.
27pa-risc2.s is a new version that often generates warnings but if the
28tests pass, it gives performance that is over 2 times faster than
29pa-risc.s.
30Both 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
7gcc2_compiled.:
8__gnu_compiled_c:
9 .text
10 .align 3
11 .globl bn_mul_add_words
12 .ent bn_mul_add_words
13bn_mul_add_words:
14bn_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
80bn_mul_words:
81bn_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
131bn_sqr_words:
132bn_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
178bn_add_words:
179bn_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
218bn_div64:
219 ldgp $29,0($27)
220bn_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
15bn_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
30L$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
58L$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
103L$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
148L$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
193L$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
216L$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
223bn_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
238L$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
266L$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
307L$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
348L$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
389L$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
408L$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
415bn_sqr_words
416 .PROC
417 .CALLINFO FRAME=0,NO_CALLS
418 .ENTRY
419 ldo 28(%r26),%r23
420 ldo 12(%r25),%r28
421L$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
555L$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
566L$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
574bn_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
592L$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
611L$0060
612 comb,>> %r5,%r3,L$0061
613 subi 32,%r28,%r28
614 sub %r3,%r5,%r3
615L$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
627L$0062
628 extru %r5,15,16,%r23
629 extru %r5,31,16,%r28
630L$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
636L$0066
637 .IMPORT $$divU,MILLICODE
638 bl $$divU,%r31
639 copy %r23,%r25
640L$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
656L$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
668L$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
691L$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
698L$0064
699 or %r7,%r29,%r28
700L$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
13gcc2_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
60bn_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
213bn_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
341bn_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
445bn_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>
86struct 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)
124int run=0;
125
126#ifndef NOPROTO
127static double Time_F(int s);
128#else
129static double Time_F();
130#endif
131
132#define START 0
133#define STOP 1
134
135static double Time_F(s)
136int 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
173static int sizes[NUM_SIZES]={128,256,512,1024,2048};
174/*static int sizes[NUM_SIZES]={59,179,299,419,539}; */
175
176void do_mul(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx);
177
178int main(argc,argv)
179int argc;
180char **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
194void do_mul(r,a,b,ctx)
195BIGNUM *r;
196BIGNUM *a;
197BIGNUM *b;
198BN_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
74int test_add (BIO *bp);
75int test_sub (BIO *bp);
76int test_lshift1 (BIO *bp);
77int test_lshift (BIO *bp);
78int test_rshift1 (BIO *bp);
79int test_rshift (BIO *bp);
80int test_div (BIO *bp,BN_CTX *ctx);
81int test_mul (BIO *bp);
82int test_sqr (BIO *bp,BN_CTX *ctx);
83int test_mont (BIO *bp,BN_CTX *ctx);
84int test_mod (BIO *bp,BN_CTX *ctx);
85int test_mod_mul (BIO *bp,BN_CTX *ctx);
86int test_mod_exp (BIO *bp,BN_CTX *ctx);
87int rand_neg(void);
88#else
89int test_add ();
90int test_sub ();
91int test_lshift1 ();
92int test_lshift ();
93int test_rshift1 ();
94int test_rshift ();
95int test_div ();
96int test_mul ();
97int test_sqr ();
98int test_mont ();
99int test_mod ();
100int test_mod_mul ();
101int test_mod_exp ();
102int rand_neg();
103#endif
104
105static int results=0;
106
107#ifdef NO_STDIO
108#define APPS_WIN16
109#include "bss_file.c"
110#endif
111
112int main(argc,argv)
113int argc;
114char *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);
214err:
215 ERR_load_crypto_strings();
216 ERR_print_errors(out);
217 exit(1);
218 return(1);
219 }
220
221int test_add(bp)
222BIO *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
261int test_sub(bp)
262BIO *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
301int test_div(bp,ctx)
302BIO *bp;
303BN_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
354int test_mul(bp)
355BIO *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
394int test_sqr(bp,ctx)
395BIO *bp;
396BN_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
431int test_mont(bp,ctx)
432BIO *bp;
433BN_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
470fprintf(stderr,"%d * %d %% %d\n",
471BN_num_bits(a),
472BN_num_bits(b),
473BN_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
493int test_mod(bp,ctx)
494BIO *bp;
495BN_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
534int test_mod_mul(bp,ctx)
535BIO *bp;
536BN_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
590int test_mod_exp(bp,ctx)
591BIO *bp;
592BN_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
635int test_lshift(bp)
636BIO *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
671int test_lshift1(bp)
672BIO *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
703int test_rshift(bp)
704BIO *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
739int test_rshift1(bp)
740BIO *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
771int 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>
86struct 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)
124int run=0;
125
126#ifndef NOPROTO
127static double Time_F(int s);
128#else
129static double Time_F();
130#endif
131
132#define START 0
133#define STOP 1
134
135static double Time_F(s)
136int 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
173static int sizes[NUM_SIZES]={256,512,1024,2048,4096,8192};
174static 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
177void do_mul_exp(BIGNUM *r,BIGNUM *a,BIGNUM *b,BIGNUM *c,BN_CTX *ctx);
178
179int main(argc,argv)
180int argc;
181char **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
195void do_mul_exp(r,a,b,c,ctx)
196BIGNUM *r;
197BIGNUM *a;
198BIGNUM *b;
199BIGNUM *c;
200BN_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
72int main(argc,argv)
73int argc;
74char *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);
142err:
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 @@
1There is a ppro flag in cast-586 which turns on/off
2generation of pentium pro/II friendly code
3
4This flag makes the inner loop one cycle longer, but generates
5code that runs %30 faster on the pentium pro/II, while only %7 slower
6on 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>
71extern 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>
84struct 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)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double 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
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int 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
151double Time_F(s)
152int 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
188int main(argc,argv)
189int argc;
190char **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>
71extern 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>
84struct 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)
153long run=0;
154
155#ifndef NOPROTO
156double Time_F(int s);
157#else
158double 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
169SIGRETTYPE sig_done(int sig);
170#else
171SIGRETTYPE sig_done();
172#endif
173
174SIGRETTYPE sig_done(sig)
175int 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
188double Time_F(s)
189int 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
250int main(argc,argv)
251int argc;
252char **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__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void 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)
22inline
23void 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
37void 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
66unsigned char k[16]={
67 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
68 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A
69 };
70
71unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
72
73int k_len[3]={16,10};
74unsigned 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 };
79unsigned char out[80];
80
81unsigned char in_a[16]={
82 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
83 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
84unsigned char in_b[16]={
85 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
86 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
87
88unsigned char c_a[16]={
89 0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6,
90 0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92};
91unsigned 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
96char *text="Hello to all people out there";
97
98static unsigned char cfb_key[16]={
99 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
100 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
101 };
102static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
103static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
104#define CFB_TEST_SIZE 24
105static 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 };
112static 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
123int main(argc,argv)
124int argc;
125char *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
62void print_conf(CONF_VALUE *cv);
63
64main()
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
80void print_conf(cv)
81CONF_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
63main()
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 @@
1package DES;
2
3require Exporter;
4require 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(
12crypt
13);
14
15# Preloaded methods go here. Autoload methods go after __END__, and are
16# processed by the autosplit program.
17bootstrap DES;
181;
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
7static STRLEN len;
8
9static int
10not_here(s)
11char *s;
12{
13 croak("%s not implemented on this architecture", s);
14 return -1;
15}
16
17MODULE = DES PACKAGE = DES PREFIX = des_
18
19char *
20des_crypt(buf,salt)
21 char * buf
22 char * salt
23
24void
25des_set_odd_parity(key)
26 des_cblock * key
27PPCODE:
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
37int
38des_is_weak_key(key)
39 des_cblock * key
40
41des_key_schedule
42des_set_key(key)
43 des_cblock * key
44CODE:
45 des_set_key(key,RETVAL);
46OUTPUT:
47RETVAL
48
49des_cblock
50des_ecb_encrypt(input,ks,encrypt)
51 des_cblock * input
52 des_key_schedule * ks
53 int encrypt
54CODE:
55 des_ecb_encrypt(input,&RETVAL,*ks,encrypt);
56OUTPUT:
57RETVAL
58
59void
60des_cbc_encrypt(input,ks,ivec,encrypt)
61 char * input
62 des_key_schedule * ks
63 des_cblock * ivec
64 int encrypt
65PPCODE:
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
84void
85des_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
92PPCODE:
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
110void
111des_cbc_cksum(input,ks,ivec)
112 char * input
113 des_key_schedule * ks
114 des_cblock * ivec
115PPCODE:
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
136void
137des_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
143PPCODE:
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
161des_cblock *
162des_ecb3_encrypt(input,ks1,ks2,encrypt)
163 des_cblock * input
164 des_key_schedule * ks1
165 des_key_schedule * ks2
166 int encrypt
167CODE:
168 {
169 des_cblock c;
170
171 des_ecb3_encrypt((des_cblock *)input,(des_cblock *)&c,
172 *ks1,*ks2,encrypt);
173 RETVAL= &c;
174 }
175OUTPUT:
176RETVAL
177
178void
179des_ofb_encrypt(input,numbits,ks,ivec)
180 unsigned char * input
181 int numbits
182 des_key_schedule * ks
183 des_cblock * ivec
184PPCODE:
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
202void
203des_pcbc_encrypt(input,ks,ivec,encrypt)
204 char * input
205 des_key_schedule * ks
206 des_cblock * ivec
207 int encrypt
208PPCODE:
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
227des_cblock *
228des_random_key()
229CODE:
230 {
231 des_cblock c;
232
233 des_random_key(c);
234 RETVAL=&c;
235 }
236OUTPUT:
237RETVAL
238
239des_cblock *
240des_string_to_key(str)
241char * str
242CODE:
243 {
244 des_cblock c;
245
246 des_string_to_key(str,&c);
247 RETVAL=&c;
248 }
249OUTPUT:
250RETVAL
251
252void
253des_string_to_2keys(str)
254char * str
255PPCODE:
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 @@
1Check the CC and CFLAGS lines in the makefile
2
3If your C library does not support the times(3) function, change the
4#define TIMES to
5#undef TIMES in speed.c
6If it does, check the HZ value for the times(3) function.
7If your system does not define CLK_TCK it will be assumed to
8be 100.0.
9
10If possible use gcc v 2.7.?
11Turn on the maximum optimising (normally '-O3 -fomit-frame-pointer' for gcc)
12In recent times, some system compilers give better performace.
13
14type 'make'
15
16run './destest' to check things are ok.
17run './rpw' to check the tty code for reading passwords works.
18run './speed' to see how fast those optimisations make the library run :-)
19run './des_opts' to determin the best compile time options.
20
21The output from des_opts should be put in the makefile options and des_enc.c
22should be rebuilt. For 64 bit computers, do not use the DES_PTR option.
23For the DEC Alpha, edit des.h and change DES_LONG to 'unsigned int'
24and then you can use the 'DES_PTR' option.
25
26The file options.txt has the options listed for best speed on quite a
27few systems. Look and the options (UNROLL, PTR, RISC2 etc) and then
28turn on the relevent option in the Makefile
29
30There are some special Makefile targets that make life easier.
31make cc - standard cc build
32make gcc - standard gcc build
33make x86-elf - x86 assembler (elf), linux-elf.
34make x86-out - x86 assembler (a.out), FreeBSD
35make x86-solaris- x86 assembler
36make x86-bsdi - x86 assembler (a.out with primative assembler).
37
38If at all possible use the assembler (for Windows NT/95, use
39asm/win32.obj to link with). The x86 assembler is very very fast.
40
41A make install will by default install
42libdes.a in /usr/local/lib/libdes.a
43des in /usr/local/bin/des
44des_crypt.man in /usr/local/man/man3/des_crypt.3
45des.man in /usr/local/man/man1/des.1
46des.h in /usr/include/des.h
47
48des(1) should be compatible with sunOS's but I have been unable to
49test it.
50
51These routines should compile on MSDOS, most 32bit and 64bit version
52of Unix (BSD and SYSV) and VMS, without modification.
53The only problems should be #include files that are in the wrong places.
54
55These routines can be compiled under MSDOS.
56I have successfully encrypted files using des(1) under MSDOS and then
57decrypted the files on a SparcStation.
58I have been able to compile and test the routines with
59Microsoft C v 5.1 and Turbo C v 2.0.
60The code in this library is in no way optimised for the 16bit
61operation of MSDOS.
62
63When building for glibc, ignore all of the above and just unpack into
64glibc-1.??/des and then gmake as per normal.
65
66As a final note on performace. Certain CPUs like sparcs and Alpha often give
67a %10 speed difference depending on the link order. It is rather anoying
68when 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
4SRCS= 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
9OBJS= 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
14GENERAL=COPYRIGHT FILES INSTALL Imakefile README VERSION makefile times \
15 vms.com KERBEROS
16DES= des.c des.man
17TESTING=destest.c speed.c rpw.c
18LIBDES= des_crypt.man des.h des_locl.h podd.h sk.h spr.h
19
20PERL= des.pl testdes.pl doIP doPC1 doPC2 PC1 PC2 shifts.pl
21
22CODE= $(GENERAL) $(DES) $(TESTING) $(SRCS) $(LIBDES) $(PERL)
23
24SRCDIR=$(SRCTOP)/lib/des
25
26DBG= -O
27INCLUDE= -I$(SRCDIR)
28CC= cc
29
30library_obj_rule()
31
32install_library_target(des,$(OBJS),$(SRCS),)
33
34test(destest,libdes.a,)
35test(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
4To use this library with Bones (kerberos without DES):
51) 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
102) 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
17Now do a normal kerberos build and things should work.
18
19One problem I found when I was build on my local sun.
20---
21For 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--
11The primary ftp site for this library is
12ftp://ftp.psy.uq.oz.au/pub/Crypto/DES/libdes-x.xx.tar.gz
13libdes is now also shipped with SSLeay. Primary ftp site of
14ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL/SSLeay-x.x.x.tar.gz
15
16The best way to build this library is to build it as part of SSLeay.
17
18This kit builds a DES encryption library and a DES encryption program.
19It supports ecb, cbc, ofb, cfb, triple ecb, triple cbc, triple ofb,
20triple cfb, desx, and MIT's pcbc encryption modes and also has a fast
21implementation of crypt(3).
22It contains support routines to read keys from a terminal,
23generate a random key, generate a key from an arbitrary length string,
24read/write encrypted data from/to a file descriptor.
25
26The implementation was written so as to conform with the manual entry
27for the des_crypt(3) library routines from MIT's project Athena.
28
29destest should be run after compilation to test the des routines.
30rpw should be run after compilation to test the read password routines.
31The des program is a replacement for the sun des command. I believe it
32conforms to the sun version.
33
34The Imakefile is setup for use in the kerberos distribution.
35
36These routines are best compiled with gcc or any other good
37optimising compiler.
38Just turn you optimiser up to the highest settings and run destest
39after the build to make sure everything works.
40
41I believe these routines are close to the fastest and most portable DES
42routines that use small lookup tables (4.5k) that are publicly available.
43The fcrypt routine is faster than ufc's fcrypt (when compiling with
44gcc2 -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
49It is worth noting that on sparc and Alpha CPUs, performance of the DES
50library can vary by upto %10 due to the positioning of files after application
51linkage.
52
53Eric 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
6Version 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
15Version 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
25Version 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
30Version 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
40Version 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
52Version 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
72Version 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
82Version 3.24 20/04/96
83 The DES_PTR macro option checked and used by SSLeay configuration
84
85Version 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
94Version 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
99Version 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
117Version 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
123Version 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
129Version 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
134Version 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
138Version 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
143Version 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
152Version 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
157Version 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
168Version 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
173Version 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
183Version 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
190Version 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
195Version 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
199Version 3.07 05/12/94
200 Added GNUmake and stuff so the library can be build with
201 glibc.
202
203Version 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
210Version 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
215Version 3.04 20/04/94
216 Added a version number to des.c and libdes.a
217
218Version 3.03 12/01/94
219 Fixed a bug in non zero iv in 3cbc_enc.
220
221Version 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
226Release upon comp.sources.misc
227Version 3.01 08/10/93
228 Added des_3cbc_encrypt()
229
230Version 3.00 07/10/93
231 Fixed up documentation.
232 quad_cksum definitely compatible with MIT's now.
233
234Version 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
240Version 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
244Version 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
250Version 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
256Version 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
260Version 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
268Version 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
280Version 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
288Version 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
293Version 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
303Version 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
307Version 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
312Patch2 posted to comp.sources.misc
313Version 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
323Version 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
330Version 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
336Patch1 posted to comp.sources.misc
337Version 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
344Version 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
353Libdes posted to comp.sources.misc
354Version 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
360Version 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
365Version 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
370Version 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
375Version 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
381Version 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
385Version 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
390Version 1.40 23/10/1990 eay
391 Fixed des_random_key, it did not produce a random key :-(
392
393Version 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
400Version 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
405Version 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
410Version 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
11require "desboth.pl";
12
13if ( ($ARGV[0] eq "elf"))
14 { require "x86unix.pl"; }
15elsif ( ($ARGV[0] eq "a.out"))
16 { $aout=1; require "x86unix.pl"; }
17elsif ( ($ARGV[0] eq "sol"))
18 { $sol=1; require "x86unix.pl"; }
19elsif ( ($ARGV[0] eq "cpp"))
20 { $cpp=1; require "x86unix.pl"; }
21elsif ( ($ARGV[0] eq "win32"))
22 { require "x86ms.pl"; }
23else
24 {
25 print STDERR <<"EOF";
26Pick 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
32EOF
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
57sub 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.
143sub 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
192sub 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
205sub 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
216sub 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
227sub 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 @@
1First up, let me say I don't like writing in assembler. It is not portable,
2dependant on the particular CPU architecture release and is generally a pig
3to debug and get right. Having said that, the x86 architecture is probably
4the most important for speed due to number of boxes and since
5it appears to be the worst architecture to to get
6good C compilers for. So due to this, I have lowered myself to do
7assembler for the inner DES routines in libdes :-).
8
9The file to implement in assembler is des_enc.c. Replace the following
104 functions
11des_encrypt(DES_LONG data[2],des_key_schedule ks, int encrypt);
12des_encrypt2(DES_LONG data[2],des_key_schedule ks, int encrypt);
13des_encrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
14des_decrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
15
16They encrypt/decrypt the 64 bits held in 'data' using
17the 'ks' key schedules. The only difference between the 4 functions is that
18des_encrypt2() does not perform IP() or FP() on the data (this is an
19optimization for when doing triple DES and des_encrypt3() and des_decrypt3()
20perform triple des. The triple DES routines are in here because it does
21make a big difference to have them located near the des_encrypt2 function
22at link time..
23
24Now as we all know, there are lots of different operating systems running on
25x86 boxes, and unfortunately they normally try to make sure their assembler
26formating is not the same as the other peoples.
27The 4 main formats I know of are
28Microsoft Windows 95/Windows NT
29Elf Includes Linux and FreeBSD(?).
30a.out The older Linux.
31Solaris Same as Elf but different comments :-(.
32
33Now I was not overly keen to write 4 different copies of the same code,
34so I wrote a few perl routines to output the correct assembler, given
35a target assembler type. This code is ugly and is just a hack.
36The libraries are x86unix.pl and x86ms.pl.
37des586.pl, des686.pl and des-som[23].pl are the programs to actually
38generate the assembler.
39
40So to generate elf assembler
41perl des-som3.pl elf >dx86-elf.s
42For Windows 95/NT
43perl des-som2.pl win32 >win32.asm
44
45[ update 4 Jan 1996 ]
46I have added another way to do things.
47perl des-som3.pl cpp >dx86-cpp.s
48generates a file that will be included by dx86unix.cpp when it is compiled.
49To build for elf, a.out, solaris, bsdi etc,
50cc -E -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o
51cc -E -DSOL asm/dx86unix.cpp | as -o asm/dx86-sol.o
52cc -E -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o
53cc -E -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o
54This was done to cut down the number of files in the distribution.
55
56Now the ugly part. I acquired my copy of Intels
57"Optimization's For Intel's 32-Bit Processors" and found a few interesting
58things. First, the aim of the exersize is to 'extract' one byte at a time
59from a word and do an array lookup. This involves getting the byte from
60the 4 locations in the word and moving it to a new word and doing the lookup.
61The most obvious way to do this is
62xor eax, eax # clear word
63movb al, cl # get low byte
64xor edi DWORD PTR 0x100+des_SP[eax] # xor in word
65movb al, ch # get next byte
66xor edi DWORD PTR 0x300+des_SP[eax] # xor in word
67shr ecx 16
68which seems ok. For the pentium, this system appears to be the best.
69One has to do instruction interleaving to keep both functional units
70operating, but it is basically very efficient.
71
72Now the crunch. When a full register is used after a partial write, eg.
73mov al, cl
74xor edi, DWORD PTR 0x100+des_SP[eax]
75386 - 1 cycle stall
76486 - 1 cycle stall
77586 - 0 cycle stall
78686 - at least 7 cycle stall (page 22 of the above mentioned document).
79
80So the technique that produces the best results on a pentium, according to
81the documentation, will produce hideous results on a pentium pro.
82
83To get around this, des686.pl will generate code that is not as fast on
84a pentium, should be very good on a pentium pro.
85mov eax, ecx # copy word
86shr ecx, 8 # line up next byte
87and eax, 0fch # mask byte
88xor edi DWORD PTR 0x100+des_SP[eax] # xor in array lookup
89mov eax, ecx # get word
90shr ecx 8 # line up next byte
91and eax, 0fch # mask byte
92xor edi DWORD PTR 0x300+des_SP[eax] # xor in array lookup
93
94Due to the execution units in the pentium, this actually works quite well.
95For a pentium pro it should be very good. This is the type of output
96Visual C++ generates.
97
98There is a third option. instead of using
99mov al, ch
100which is bad on the pentium pro, one may be able to use
101movzx eax, ch
102which may not incur the partial write penalty. On the pentium,
103this instruction takes 4 cycles so is not worth using but on the
104pentium pro it appears it may be worth while. I need access to one to
105experiment :-).
106
107eric (20 Oct 1996)
108
10922 Nov 1996 - I have asked people to run the 2 different version on pentium
110pros and it appears that the intel documentation is wrong. The
111mov al,bh is still faster on a pentium pro, so just use the des586.pl
112install des686.pl
113
1143 Dec 1996 - I added des_encrypt3/des_decrypt3 because I have moved these
115functions into des_enc.c because it does make a massive performance
116difference on some boxes to have the functions code located close to
117the des_encrypt2() function.
118
1199 Jan 1997 - des-som2.pl is now the correct perl script to use for
120pentiums. It contains an inner loop from
121Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> which does raw ecb DES calls at
122273,000 per second. He had a previous version at 250,000 and the best
123I was able to get was 203,000. The content has not changed, this is all
124due to instruction sequencing (and actual instructions choice) which is able
125to keep both functional units of the pentium going.
126We may have lost the ugly register usage restrictions when x86 went 32 bit
127but for the pentium it has been replaced by evil instruction ordering tricks.
128
12913 Jan 1997 - des-som3.pl, more optimizations from Svend Olaf.
130raw 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 */
62void des_3cbc_encrypt(input, output, length, ks1, ks2, iv1, iv2, enc)
63des_cblock (*input);
64des_cblock (*output);
65long length;
66des_key_schedule ks1;
67des_key_schedule ks2;
68des_cblock (*iv1);
69des_cblock (*iv2);
70int 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
95void usage(void);
96void doencryption(void);
97int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp);
98void uufwriteEnd(FILE *fp);
99int uufread(unsigned char *out,int size,unsigned int num,FILE *fp);
100int uuencode(unsigned char *in,int num,unsigned char *out);
101int uudecode(unsigned char *in,int num,unsigned char *out);
102void 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
106void usage();
107void doencryption();
108int uufwrite();
109void uufwriteEnd();
110int uufread();
111int uuencode();
112int uudecode();
113void 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 :-) */
126char key[KEYSIZB+1];
127int do_encrypt,longk=0;
128FILE *DES_IN,*DES_OUT,*CKSUM_OUT;
129char uuname[200];
130unsigned char uubuf[50];
131int uubufnum=0;
132#define INUUBUFN (45*100)
133#define OUTUUBUF (65*100)
134unsigned char b[OUTUUBUF];
135unsigned char bb[300];
136des_cblock cksum={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
137char cksumname[200]="";
138
139int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error;
140
141int main(argc, argv)
142int argc;
143char **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
334void 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.",
361NULL
362};
363 for (u=(char **)Usage; *u; u++)
364 {
365 fputs(*u,stderr);
366 fputc('\n',stderr);
367 }
368
369 EXIT(1);
370 }
371
372void 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 }
683problems:
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
699int uufwrite(data, size, num, fp)
700unsigned char *data;
701int size;
702unsigned int num;
703FILE *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
760void uufwriteEnd(fp)
761FILE *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
777int uufread(out, size, num, fp)
778unsigned char *out;
779int size; /* should always be > ~ 60; I actually ignore this parameter :-) */
780unsigned int num;
781FILE *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
853int uuencode(in, num, out)
854unsigned char *in;
855int num;
856unsigned 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
886int uudecode(in, num, out)
887unsigned char *in;
888int num;
889unsigned 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__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void 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)
22inline
23void 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
37void 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>
71extern 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>
84struct 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)
334long run=0;
335
336#ifndef NOPROTO
337double Time_F(int s);
338#else
339double 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
350SIGRETTYPE sig_done(int sig);
351#else
352SIGRETTYPE sig_done();
353#endif
354
355SIGRETTYPE sig_done(sig)
356int 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
369double Time_F(s)
370int 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
428int main(argc,argv)
429int argc;
430char **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
59extern char *DES_version; /* SSLeay version string */
60extern 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__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void 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)
22inline
23void 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
37void 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
78static 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
114static 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
150static 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
186static 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
221static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
222static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
223static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
224static 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"; */
228static 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
236static 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
242static 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
249static 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
255static 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
261static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
262static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
263static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
264static 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 };
271static 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 };
274static 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 };
277static 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 };
280static 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 };
283static 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
287static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
288static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
289static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8];
290static 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
297DES_LONG cbc_cksum_ret=0xB462FEF7L;
298unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
299
300#ifndef NOPROTO
301static char *pt(unsigned char *p);
302static int cfb_test(int bits, unsigned char *cfb_cipher);
303static int cfb64_test(unsigned char *cfb_cipher);
304static int ede_cfb64_test(unsigned char *cfb_cipher);
305#else
306static char *pt();
307static int cfb_test();
308static int cfb64_test();
309static int ede_cfb64_test();
310#endif
311
312int main(argc,argv)
313int argc;
314char *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");
569printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
570ofb_buf1[8+0], ofb_buf1[8+1], ofb_buf1[8+2], ofb_buf1[8+3],
571ofb_buf1[8+4], ofb_buf1[8+5], ofb_buf1[8+6], ofb_buf1[8+7]);
572printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
573ofb_buf1[8+0], ofb_cipher[8+1], ofb_cipher[8+2], ofb_cipher[8+3],
574ofb_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");
583printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
584ofb_buf2[8+0], ofb_buf2[8+1], ofb_buf2[8+2], ofb_buf2[8+3],
585ofb_buf2[8+4], ofb_buf2[8+5], ofb_buf2[8+6], ofb_buf2[8+7]);
586printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
587plain[8+0], plain[8+1], plain[8+2], plain[8+3],
588plain[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
752static char *pt(p)
753unsigned 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
774static int cfb_test(bits, cfb_cipher)
775int bits;
776unsigned 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
805static int cfb64_test(cfb_cipher)
806unsigned 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
843static int ede_cfb64_test(cfb_cipher)
844unsigned 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#
5CC = bcc
6TLIB = tlib /0 /C
7# note: the -3 flag produces code for 386, 486, Pentium etc; omit it for 286s
8OPTIMIZE= -3 -O2
9#WINDOWS= -W
10CFLAGS = -c -ml -d $(OPTIMIZE) $(WINDOWS) -DMSDOS
11LFLAGS = -ml $(WINDOWS)
12
13.c.obj:
14 $(CC) $(CFLAGS) $*.c
15
16.obj.exe:
17 $(CC) $(LFLAGS) -e$*.exe $*.obj libdes.lib
18
19all: $(LIB) destest.exe rpw.exe des.exe speed.exe
20
21# "make clean": use a directory containing only libdes .exe and .obj files...
22clean:
23 del *.exe
24 del *.obj
25 del libdes.lib
26 del libdes.rsp
27
28OBJS= 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
35LIB= 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
45destest.exe: destest.obj libdes.lib
46rpw.exe: rpw.obj libdes.lib
47speed.exe: speed.obj libdes.lib
48des.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 @@
1Note that the UNROLL option makes the 'inner' des loop unroll all 16 rounds
2instead of the default 4.
3RISC1 and RISC2 are 2 alternatives for the inner loop and
4PTR means to use pointers arithmatic instead of arrays.
5
6FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - assembler 577,000 4620k/s
7IRIX 6.2 - R10000 195mhz - cc (-O3 -n32) - UNROLL RISC2 PTR 496,000 3968k/s
8solaris 2.5.1 usparc 167mhz?? - SC4.0 - UNROLL RISC1 PTR [1] 459,400 3672k/s
9FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - UNROLL RISC1 433,000 3468k/s
10solaris 2.5.1 usparc 167mhz?? - gcc 2.7.2 - UNROLL 380,000 3041k/s
11linux - pentium 100mhz - gcc 2.7.0 - assembler 281,000 2250k/s
12NT 4.0 - pentium 100mhz - VC 4.2 - assembler 281,000 2250k/s
13AIX 4.1? - PPC604 100mhz - cc - UNROLL 275,000 2200k/s
14IRIX 5.3 - R4400 200mhz - gcc 2.6.3 - UNROLL RISC2 PTR 235,300 1882k/s
15IRIX 5.3 - R4400 200mhz - cc - UNROLL RISC2 PTR 233,700 1869k/s
16NT 4.0 - pentium 100mhz - VC 4.2 - UNROLL RISC1 PTR 191,000 1528k/s
17DEC Alpha 165mhz?? - cc - RISC2 PTR [2] 181,000 1448k/s
18linux - pentium 100mhz - gcc 2.7.0 - UNROLL RISC1 PTR 158,500 1268k/s
19HPUX 10 - 9000/887 - cc - UNROLL [3] 148,000 1190k/s
20solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2 - UNROLL 123,600 989k/s
21IRIX 5.3 - R4000 100mhz - cc - UNROLL RISC2 PTR 101,000 808k/s
22DGUX - 88100 50mhz(?) - gcc 2.6.3 - UNROLL 81,000 648k/s
23solaris 2.4 486 50mhz - gcc 2.6.3 - assembler 65,000 522k/s
24HPUX 10 - 9000/887 - k&r cc (default compiler) - UNROLL PTR 76,000 608k/s
25solaris 2.4 486 50mhz - gcc 2.6.3 - UNROLL RISC2 43,500 344k/s
26AIX - old slow one :-) - cc - 39,000 312k/s
27
28Notes.
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
61int des_read_password(key, prompt, verify)
62des_cblock (*key);
63char *prompt;
64int 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
76int des_read_2passwords(key1, key2, prompt, verify)
77des_cblock (*key1);
78des_cblock (*key2);
79char *prompt;
80int 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>
139struct 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
151static void read_till_nl(FILE *);
152static void recsig(int);
153static void pushsig(void);
154static void popsig(void);
155#if defined(MSDOS) && !defined(WIN16)
156static int noecho_fgets(char *buf, int size, FILE *tty);
157#endif
158#else
159static void read_till_nl();
160static void recsig();
161static void pushsig();
162static void popsig();
163#if defined(MSDOS) && !defined(WIN16)
164static 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
177static jmp_buf save;
178
179int des_read_pw_string(buf, length, prompt, verify)
180char *buf;
181int length;
182char *prompt;
183int 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
195static void read_till_nl(in)
196FILE *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 */
208int des_read_pw(buf, buff, size, prompt, verify)
209char *buf;
210char *buff;
211int size;
212char *prompt;
213int 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
330error:
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
355int des_read_pw(buf, buff, size, prompt, verify)
356char *buf;
357char *buff;
358int size;
359char *prompt;
360int verify;
361 {
362 memset(buf,0,size);
363 memset(buff,0,size);
364 return(0);
365 }
366
367#endif
368
369static 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
395static 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
417static void recsig(i)
418int i;
419 {
420 longjmp(save,1);
421#ifdef LINT
422 i=i;
423#endif
424 }
425
426#if defined(MSDOS) && !defined(WIN16)
427static int noecho_fgets(buf,size,tty)
428char *buf;
429int size;
430FILE *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
102enum desdir { ENCRYPT, DECRYPT };
103enum desmode { CBC, ECB };
104
105/*
106 * parameters to ioctl call
107 */
108struct 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
64int _des_crypt(char *buf,int len,struct desparams *desp);
65#else
66int _des_crypt();
67#endif
68
69int _des_crypt(buf, len, desp)
70char *buf;
71int len;
72struct 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
62int main(argc,argv)
63int argc;
64char *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>
71extern 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>
84struct 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)
120long run=0;
121
122#ifndef NOPROTO
123double Time_F(int s);
124#else
125double 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
136SIGRETTYPE sig_done(int sig);
137#else
138SIGRETTYPE sig_done();
139#endif
140
141SIGRETTYPE sig_done(sig)
142int 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
155double Time_F(s)
156int 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
192int main(argc,argv)
193int argc;
194char **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
3BEGIN { push(@INC, qw(../../../lib ../../lib ../lib lib)); }
4
5use DES;
6
7$key='00000000';
8$ks=DES::set_key($key);
9@a=split(//,$ks);
10foreach (@a) { printf "%02x-",ord($_); }
11print "\n";
12
13
14$key=DES::random_key();
15print "($_)\n";
16@a=split(//,$key);
17foreach (@a) { printf "%02x-",ord($_); }
18print "\n";
19$str="this is and again into the breach";
20($k1,$k2)=DES::string_to_2keys($str);
21@a=split(//,$k1);
22foreach (@a) { printf "%02x-",ord($_); }
23print "\n";
24@a=split(//,$k2);
25foreach (@a) { printf "%02x-",ord($_); }
26print "\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 @@
1Solaris 2.4, 486 50mhz, gcc 2.6.3
2options des ecb/s
316 r2 i 43552.51 100.0%
416 r1 i 43487.45 99.9%
516 c p 43003.23 98.7%
616 r2 p 42339.00 97.2%
716 c i 41900.91 96.2%
816 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 @@
1Pentium 100
2Linux 2 kernel
3gcc 2.7.0 -O3 -fomit-frame-pointer
4No X server running, just a console, it makes the top speed jump from 151,000
5to 158,000 :-).
6options des ecb/s
7assember 281000.00 177.1%
816 r1 p 158667.40 100.0%
916 r1 i 148471.70 93.6%
1016 r2 p 143961.80 90.7%
1116 r2 i 141689.20 89.3%
12 4 r1 i 140100.00 88.3%
13 4 r2 i 134049.40 84.5%
1416 c i 124145.20 78.2%
1516 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 @@
1Pentium 100
2Free BSD 2.1.5 kernel
3gcc 2.7.2.2 -O3 -fomit-frame-pointer
4options des ecb/s
5assember 578000.00 133.1%
616 r2 i 434454.80 100.0%
716 r1 i 433621.43 99.8%
816 r2 p 431375.69 99.3%
9 4 r1 i 423722.30 97.5%
10 4 r2 i 422399.40 97.2%
1116 r1 p 421739.40 97.1%
1216 c i 399027.94 91.8%
1316 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 @@
1From: Paco Garcia <pgarcia@cam.es>
2
3This machine is a Bull Estrella Minitower Model MT604-100
4Processor : PPC604
5P.Speed : 100Mhz
6Data/Instr Cache : 16 K
7L2 Cache : 256 K
8PCI BUS Speed : 33 Mhz
9TransfRate PCI : 132 MB/s
10Memory : 96 MB
11
12options 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%
1916 c i 224603.99 81.6%
2016 c p 224483.98 81.6%
2116 r2 p 215691.19 78.4%
2216 r1 p 208332.83 75.7%
2316 r1 i 199206.50 72.4%
2416 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 @@
1cc -O2
2DES_LONG is 'unsigned int'
3
4options des ecb/s
5 4 r2 p 181146.14 100.0%
616 r2 p 172102.94 95.0%
7 4 r2 i 165424.11 91.3%
816 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%
1216 r2 i 154137.69 85.1%
1316 r1 p 152357.96 84.1%
1416 c i 148743.91 82.1%
15 4 r1 i 146695.59 81.0%
1616 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 @@
1HPUX 10 - 9000/887 - cc -D_HPUX_SOURCE -Aa +ESlit +O2 -Wl,-a,archive
2
3options des ecb/s
416 c i 149448.90 100.0%
5 4 c i 145861.79 97.6%
616 r2 i 141710.96 94.8%
716 r1 i 139455.33 93.3%
8 4 r2 i 138800.00 92.9%
9 4 r1 i 136692.65 91.5%
1016 r2 p 110228.17 73.8%
1116 r1 p 109397.07 73.2%
1216 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 @@
1solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2
2
3options des ecb/s
416 c i 124382.70 100.0%
5 4 c i 118884.68 95.6%
616 c p 112261.20 90.3%
716 r2 i 111777.10 89.9%
816 r2 p 108896.30 87.5%
916 r1 p 108791.59 87.5%
10 4 c p 107290.10 86.3%
11 4 r1 p 104583.80 84.1%
1216 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 @@
1solaris 2.5.1 usparc 167mhz?? - SC4.0 cc -fast -Xa -xO5
2
3For the ultra sparc, SunC 4.0 cc -fast -Xa -xO5, running 'des_opts'
4gives a speed of 475,000 des/s while 'speed' gives 417,000 des/s.
5I belive the difference is tied up in optimisation that the compiler
6is able to perform when the code is 'inlined'. For 'speed', the DES
7routines are being linked from a library. I'll record the higher
8speed 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
17options des ecb/s
1816 r1 p 475516.90 100.0%
1916 r2 p 439388.10 92.4%
2016 c i 427001.40 89.8%
2116 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%
2716 r2 i 331275.50 69.7%
2816 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#
4deschar * T_DESCHARP
5des_cblock * T_CBLOCK
6des_cblock T_CBLOCK
7des_key_schedule T_SCHEDULE
8des_key_schedule * T_SCHEDULE
9
10INPUT
11T_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
18T_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
26OUTPUT
27T_CBLOCK
28 sv_setpvn($arg,(char *)$var,DES_KEY_SZ);
29
30T_SCHEDULE
31 sv_setpvn($arg,(char *)$var,DES_SCHEDULE_SZ);
32
33T_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-----
2MIGHAoGBAJf2QmHKtQXdKCjhPx1ottPb0PMTBH9A6FbaWMsTuKG/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-----
2MB4CGQDUoLoCULb9LsYm5+/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-----
2MIIBCAKCAQEA7ZKJNYJFVcs7+6J2WmkEYb8h86tT0s0h2v94GRFS8Q7B4lW9aG9o
3AFO5Imov5Jo0H2XMWTKKvbHbSe3fpxJmw/0hBHAY8H/W91hRGXKCeyKpNBgdL8sh
4z22SrkO2qCnHJ6PLAMXy5fsKpFmFor2tRfCzrfnggTXu2YOzzK7q62bmqVdmufEo
5pT8igNcLpvZxk5uBDvhakObMym9mX3rAEBoe8PwttggMYiiw7NuJKO4MqD1llGkW
6aVM8U2ATsCun1IKHrRxynkE1/MJ86VHeYYX8GZt2YA8z+GuzylIOKcMH6JAWzMwA
7Gbatw6QwizOhr9iMjZ0B26TE3X8LvW84wwIBAg==
8-----END DH PARAMETERS-----
9-----BEGIN DH PARAMETERS-----
10MIIBCAKCAQEArtA3w73zP6Lu3EOQtwogiXt3AXXpuS6yD4BhzNS1pZFyPHk0/an5
118ydEkPhQZHKDW+BZJxxPLANaTudWo2YT8TgtvUdN6KSgMiEi6McwqDw+SADuvW+F
12SKUYFxG6VFIxyEP6xBdf+vhJxEDbRG2EYsHDRRtJ76gp9cSKTHusf2R+4AAVGqnt
13gRAbNqtcOar/7FSj+Pl8G3v0Bty0LcCSpbqgYlnv6z+rErQmmC6PPvSz97TDMCok
14yKpCE9hFA1zkqK3TH4FmFvGeIaXJUIBZf4mArWuBTjWFW3nmhESRUn1VK3K3x42N
15a5k6c2+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-----
2MIICCAKCAgEA/urRnb6vkPYc/KEGXWnbCIOaKitq7ySIq9dTH7s+Ri59zs77zty7
3vfVlSe6VFTBWgYjD2XKUFmtqq6CqXMhVX5ElUDoYDpAyTH85xqNFLzFC7nKrff/H
4TFKNttp22cZE9V0IPpzedPfnQkE7aUdmF9JnDyv21Z/818O93u1B4r0szdnmEvEF
5bKuIxEHX+bp0ZR7RqE1AeifXGJX3d6tsd2PMAObxwwsv55RGkn50vHO4QxtTARr1
6rRUV5j3B3oPMgC7Offxx+98Xn45B1/G0Prp11anDsR1PGwtaCYipqsvMwQUSJtyE
7EOQWk+yFkeMe4vWv367eEi0Sd/wnC+TSXBE3pYvpYerJ8n1MceI5GQTdarJ77OW9
8bGTHmxRsLSCM1jpLdPja5jjb4siAa6EHc4qN9c/iFKS3PQPJEnX7pXKBRs5f7AF3
9W3RIGt+G9IVNZfXaS7Z/iCpgzgvKCs0VeqN38QsJGtC1aIkwOeyjPNy2G6jJ4yqH
10ovXYt/0mc00vCWeSNS1wren0pR2EiLxX0ypjjgsU1mk/Z3b/+zVf7fZSIB+nDLjb
11NPtUlJCVGnAeBK1J1nG3TQicqowOXoM6ISkdaXj5GPJdXHab2+S7cqhKGv5qC7rR
12jT6sx7RUr0CNTxzLI7muV2/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-----
2MEYCQQDaWDwW2YUiidDkr3VvTMqS3UvlM7gE+w/tlO+cikQD7VdGUNNpmdsp13Yn
3a6LT1BLiGPTdHghM9tgAPnxHdOgzAgEC
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
77static void MS_CALLBACK cb(int p, int n, char *arg);
78#else
79static void MS_CALLBACK cb();
80#endif
81
82#ifdef NO_STDIO
83#define APPS_WIN16
84#include "bss_file.c"
85#endif
86
87BIO *out=NULL;
88
89int main(argc,argv)
90int argc;
91char *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;
166err:
167 if (abuf != NULL) Free(abuf);
168 if (bbuf != NULL) Free(bbuf);
169 exit(ret);
170 return(ret);
171 }
172
173static void MS_CALLBACK cb(p, n,arg)
174int p;
175int n;
176char *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 @@
1From owner-cypherpunks@toad.com Mon Sep 25 10:50:51 1995
2Received: 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
4Received: 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
6Received: from relay3.UU.NET by bunyip.cc.uq.oz.au with SMTP (PP);
7 Wed, 27 Sep 1995 19:13:05 +1000
8Received: from toad.com by relay3.UU.NET with SMTP id QQzizb16156;
9 Wed, 27 Sep 1995 04:48:46 -0400
10Received: by toad.com id AA07905; Tue, 26 Sep 95 06:31:45 PDT
11Received: from by toad.com id AB07851; Tue, 26 Sep 95 06:31:40 PDT
12Received: 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
15Received: (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
17Date: Mon, 25 Sep 1995 17:50:51 -0700
18From: Phil Karn <karn@qualcomm.com>
19Message-Id: <199509260050.RAA14732@servo.qualcomm.com>
20To: cypherpunks@toad.com, ipsec-dev@eit.com
21Subject: Primality verification needed
22Sender: owner-cypherpunks@toad.com
23Precedence: bulk
24Status: RO
25X-Status:
26
27Hi. I've generated a 2047-bit "strong" prime number that I would like to
28use with Diffie-Hellman key exchange. I assert that not only is this number
29'p' prime, but so is (p-1)/2.
30
31I've used the mpz_probab_prime() function in the Gnu Math Package (GMP) version
321.3.2 to test this number. This function uses the Miller-Rabin primality test.
33However, to increase my confidence that this number really is a strong prime,
34I'd like to ask others to confirm it with other tests. Here's the number in hex:
35
3672a925f760b2f954ed287f1b0953f3e6aef92e456172f9fe86fdd8822241b9c9788fbc289982743e
37fbcd2ccf062b242d7a567ba8bbb40d79bca7b8e0b6c05f835a5b938d985816bc648985adcff5402a
38a76756b36c845a840a1d059ce02707e19cf47af0b5a882f32315c19d1b86a56c5389c5e9bee16b65
39fde7b1a8d74a7675de9b707d4c5a4633c0290c95ff30a605aeb7ae864ff48370f13cf01d49adb9f2
403d19a439f753ee7703cf342d87f431105c843c78ca4df639931f3458fae8a94d1687e99a76ed99d0
41ba87189f42fd31ad8262c54a8cf5914ae6c28c540d714a5f6087a171fb74f4814c6f968d72386ef3
4256a05180c3bec7ddd5ef6fe76b1f717b
43
44The generator, g, for this prime is 2.
45
46Thanks!
47
48Phil 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 @@
1From: stewarts@ix.netcom.com (Bill Stewart)
2Newsgroups: sci.crypt
3Subject: Re: Diffie-Hellman key exchange
4Date: Wed, 11 Oct 1995 23:08:28 GMT
5Organization: Freelance Information Architect
6Lines: 32
7Message-ID: <45hir2$7l8@ixnews7.ix.netcom.com>
8References: <458rhn$76m$1@mhadf.production.compuserve.com>
9NNTP-Posting-Host: ix-pl4-16.ix.netcom.com
10X-NETCOM-Date: Wed Oct 11 4:09:22 PM PDT 1995
11X-Newsreader: Forte Free Agent 1.0.82
12
13Kent 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
20q should be prime, and ideally should be a "strong prime",
21which means it's of the form 2n+1 where n is also prime.
22q also needs to be long enough to prevent the attacks LaMacchia and
23Odlyzko described (some variant on a factoring attack which generates
24a large pile of simultaneous equations and then solves them);
25long enough is about the same size as factoring, so 512 bits may not
26be secure enough for most applications. (The 192 bits used by
27"secure NFS" was certainly not long enough.)
28
29a should be a generator for q, which means it needs to be
30relatively prime to q-1. Usually a small prime like 2, 3 or 5 will
31work.
32
33....
34
35Date: Tue, 26 Sep 1995 13:52:36 MST
36From: "Richard Schroeppel" <rcs@cs.arizona.edu>
37To: karn
38Cc: ho@cs.arizona.edu
39Subject: random large primes
40
41Since your prime is really random, proving it is hard.
42My personal limit on rigorously proved primes is ~350 digits.
43If you really want a proof, we should talk to Francois Morain,
44or the Australian group.
45
46If you want 2 to be a generator (mod P), then you need it
47to be a non-square. If (P-1)/2 is also prime, then
48non-square == primitive-root for bases << P.
49
50In the case at hand, this means 2 is a generator iff P = 11 (mod 24).
51If you want this, you should restrict your sieve accordingly.
52
533 is a generator iff P = 5 (mod 12).
54
555 is a generator iff P = 3 or 7 (mod 10).
56
572 is perfectly usable as a base even if it's a non-generator, since
58it still covers half the space of possible residues. And an
59eavesdropper can always determine the low-bit of your exponent for
60a generator anyway.
61
62Rich 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
65unsigned 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
83main()
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
65unsigned char data[]={
660xD4,0xA0,0xBA,0x02,0x50,0xB6,0xFD,0x2E,
670xC6,0x26,0xE7,0xEF,0xD6,0x37,0xDF,0x76,
680xC7,0x16,0xE2,0x2D,0x09,0x44,0xB8,0x8B,
69 };
70
71main()
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
65unsigned char data[]={
660xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,
670xD0,0xE4,0xAF,0x75,0x6F,0x4C,0xCA,0x92,
680xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
690xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,
700x57,0x46,0x50,0xD3,0x69,0x99,0xDB,0x29,
710xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
720xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,
730xD8,0x00,0x3E,0x7C,0x47,0x74,0xE8,0x33,
74 };
75
76main()
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 @@
1The stuff in here is based on patches supplied to me by
2Steven Schoch <schoch@sheba.arc.nasa.gov> to do DSS.
3I have since modified a them a little but a debt of gratitude
4is 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
72unsigned 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
80int cb(p,n)
81int 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
93main()
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
80static void MS_CALLBACK dsa_cb(int p, int n, char *arg);
81#else
82static void MS_CALLBACK dsa_cb();
83#endif
84
85static 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
90static 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
101static 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
107static 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
118static BIO *bio_err=NULL;
119
120int main(argc, argv)
121int argc;
122char **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;
183end:
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
192static void MS_CALLBACK dsa_cb(p, n, arg)
193int p;
194int n;
195char *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 @@
1The origional FIPE 180 used SHA-0 (FIPS 180) for its appendix 5
2examples. This is an updated version that uses SHA-1 (FIPS 180-1)
3supplied to me by Wei Dai
4--
5 APPENDIX 5. EXAMPLE OF THE DSA
6
7
8This appendix is for informational purposes only and is not required to meet
9the standard.
10
11Let L = 512 (size of p). The values in this example are expressed in
12hexadecimal notation. The p and q given here were generated by the prime
13generation standard described in appendix 2 using the 160-bit SEED:
14
15 d5014e4b 60ef2ba8 b6211b40 62ba3224 e0427dd3
16
17With this SEED, the algorithm found p and q when the counter was at 105.
18
19x was generated by the algorithm described in appendix 3, section 3.1, using
20the SHA to construct G (as in appendix 3, section 3.3) and a 160-bit XSEED:
21
22XSEED =
23
24 bd029bbe 7f51960b cf9edb2b 61f06f0f eb5a38b6
25
26t =
27 67452301 EFCDAB89 98BADCFE 10325476 C3D2E1F0
28
29x = G(t,XSEED) mod q
30
31k was generated by the algorithm described in appendix 3, section 3.2, using
32the SHA to construct G (as in appendix 3, section 3.3) and a 160-bit KSEED:
33
34KSEED =
35
36 687a66d9 0648f993 867e121f 4ddf9ddb 01205584
37
38t =
39 EFCDAB89 98BADCFE 10325476 C3D2E1F0 67452301
40
41k = G(t,KSEED) mod q
42
43Finally:
44
45h = 2
46
47p =
48 8df2a494 492276aa 3d25759b b06869cb eac0d83a fb8d0cf7
49 cbb8324f 0d7882e5 d0762fc5 b7210eaf c2e9adac 32ab7aac
50 49693dfb f83724c2 ec0736ee 31c80291
51
52
53q =
54 c773218c 737ec8ee 993b4f2d ed30f48e dace915f
55
56
57g =
58 626d0278 39ea0a13 413163a5 5b4cb500 299d5522 956cefcb
59 3bff10f3 99ce2c2e 71cb9de5 fa24babf 58e5b795 21925c9c
60 c42e9f6f 464b088c c572af53 e6d78802
61
62
63x =
64 2070b322 3dba372f de1c0ffc 7b2e3b49 8b260614
65
66
67k =
68 358dad57 1462710f 50e254cf 1a376b2b deaadfbf
69
70
71kinv =
72
73 0d516729 8202e49b 4116ac10 4fc3f415 ae52f917
74
75M = ASCII form of "abc" (See FIPS PUB 180-1, Appendix A)
76
77SHA(M) =
78
79 a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d
80
81
82y =
83
84 19131871 d75b1612 a819f29d 78d1b0d7 346f7aa7 7bb62a85
85 9bfd6c56 75da9d21 2d3a36ef 1672ef66 0b8c7c25 5cc0ec74
86 858fba33 f44c0669 9630a76b 030ee333
87
88
89r =
90 8bac1ab6 6410435c b7181f95 b16ab97c 92b341c0
91
92s =
93 41e2345f 1f56df24 58f426d1 55b4ba2d b6dcd8c8
94
95
96w =
97 9df4ece5 826be95f ed406d41 b43edc0b 1c18841b
98
99
100u1 =
101 bf655bd0 46f0b35e c791b004 804afcbb 8ef7d69d
102
103
104u2 =
105 821a9263 12e97ade abcc8d08 2b527897 8a2df4b0
106
107
108gu1 mod p =
109
110 51b1bf86 7888e5f3 af6fb476 9dd016bc fe667a65 aafc2753
111 9063bd3d 2b138b4c e02cc0c0 2ec62bb6 7306c63e 4db95bbf
112 6f96662a 1987a21b e4ec1071 010b6069
113
114
115yu2 mod p =
116
117 8b510071 2957e950 50d6b8fd 376a668e 4b0d633c 1e46e665
118 5c611a72 e2b28483 be52c74d 4b30de61 a668966e dc307a67
119 c19441f4 22bf3c34 08aeba1f 0a4dbec7
120
121v =
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
65static 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
65static 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
78EVP_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
65static 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
78EVP_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
65static 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
78EVP_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
64struct 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
106static char *pt(unsigned char *md);
107#else
108static char *pt();
109#endif
110
111int main(argc,argv)
112int argc;
113char *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
138static char *pt(md)
139unsigned 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
64main()
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
5while (<>)
6 {
7 next unless /^node/;
8 chop;
9 @a=split;
10 $num{$a[3]}++;
11 }
12
13@a=sort {$a <=> $b } keys %num;
14foreach (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
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69void exit(int);
70#else
71void do_fp();
72void pt();
73int read();
74void exit();
75#endif
76
77int main(argc, argv)
78int argc;
79char *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
108void do_fp(f)
109FILE *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
128void pt(md)
129unsigned 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
64char *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
72static void md2_block(MD2_CTX *c, unsigned char *d);
73#else
74static 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. */
79static 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
114char *MD2_options()
115 {
116 if (sizeof(MD2_INT) == 1)
117 return("md2(char)");
118 else
119 return("md2(int)");
120 }
121
122void MD2_Init(c)
123MD2_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
131void MD2_Update(c, data, len)
132MD2_CTX *c;
133register unsigned char *data;
134unsigned 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
172static void md2_block(c, d)
173MD2_CTX *c;
174unsigned 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
210void MD2_Final(md, c)
211unsigned char *md;
212MD2_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
66unsigned char *MD2(d, n, md)
67unsigned char *d;
68unsigned long n;
69unsigned 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
64char *test[]={
65 "",
66 "a",
67 "abc",
68 "message digest",
69 "abcdefghijklmnopqrstuvwxyz",
70 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
71 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
72 NULL,
73 };
74
75char *ret[]={
76 "8350e5a3e24c153df2275c9f80692773",
77 "32ec01ec4a6dac72c0ab96fb34c0b5d1",
78 "da853b0d3f88d99b30283a69e6ded6bb",
79 "ab4f496bfb2a530b219ff33031fe06b0",
80 "4e8ddff3650292ab5a4108c3aa47940b",
81 "da33def2a42df13975352846c30338cd",
82 "d5976f79d83d3a0dc9806c3c66f3efd8",
83 };
84
85#ifndef NOPROTO
86static char *pt(unsigned char *md);
87#else
88static char *pt();
89#endif
90
91int main(argc,argv)
92int argc;
93char *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
121static char *pt(md)
122unsigned 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
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **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
105void do_fp(f)
106FILE *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
126void pt(md)
127unsigned 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__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void 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)
22inline
23void 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
37extern "C" {
38void md5_block_x86(MD5_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void 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
64char *test[]={
65 "",
66 "a",
67 "abc",
68 "message digest",
69 "abcdefghijklmnopqrstuvwxyz",
70 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
71 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
72 NULL,
73 };
74
75char *ret[]={
76 "d41d8cd98f00b204e9800998ecf8427e",
77 "0cc175b9c0f1b6a831c399e269772661",
78 "900150983cd24fb0d6963f7d28e17f72",
79 "f96b697d7cb7938d525a2f31aaf161d0",
80 "c3fcd3d76192e4007dfb496cca67e13b",
81 "d174ab98d277d9f5a5611c2c9f419d9f",
82 "57edf4a22be3c955ac49da2e2107b67a",
83 };
84
85#ifndef NOPROTO
86static char *pt(unsigned char *md);
87#else
88static char *pt();
89#endif
90
91int main(argc,argv)
92int argc;
93char *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
121static char *pt(md)
122unsigned 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
63extern "C" {
64#endif
65
66#include "des.h"
67
68#define MDC2_BLOCK 8
69#define MDC2_DIGEST_LENGTH 16
70
71typedef 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
81void MDC2_Init(MDC2_CTX *c);
82void MDC2_Update(MDC2_CTX *c, unsigned char *data, unsigned long len);
83void MDC2_Final(unsigned char *md, MDC2_CTX *c);
84unsigned char *MDC2(unsigned char *d, unsigned long n, unsigned char *md);
85
86#else
87
88void MDC2_Init();
89void MDC2_Update();
90void MDC2_Final();
91unsigned 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
66static int mh_mode=CRYPTO_MEM_CHECK_OFF;
67static unsigned long order=0;
68
69static LHASH *mh=NULL;
70
71typedef struct mem_st
72 {
73 char *addr;
74 int num;
75 char *file;
76 int line;
77 unsigned long order;
78 } MEM;
79
80int CRYPTO_mem_ctrl(mode)
81int 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
101static int mem_cmp(a,b)
102MEM *a,*b;
103 {
104 return(a->addr - b->addr);
105 }
106
107static unsigned long mem_hash(a)
108MEM *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
118static char *(*malloc_func)()= (char *(*)())malloc;
119static char *(*realloc_func)()= (char *(*)())realloc;
120static void (*free_func)()= (void (*)())free;
121
122void CRYPTO_set_mem_functions(m,r,f)
123char *(*m)();
124char *(*r)();
125void (*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
133void CRYPTO_get_mem_functions(m,r,f)
134char *(**m)();
135char *(**r)();
136void (**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
143char *CRYPTO_malloc(num)
144int num;
145 {
146 return(malloc_func(num));
147 }
148
149char *CRYPTO_realloc(str,num)
150char *str;
151int num;
152 {
153 return(realloc_func(str,num));
154 }
155
156void CRYPTO_free(str)
157char *str;
158 {
159 free_func(str);
160 }
161
162char *CRYPTO_dbg_malloc(num,file,line)
163int num;
164char *file;
165int 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
206void CRYPTO_dbg_free(addr)
207char *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
223char *CRYPTO_dbg_realloc(addr,num,file,line)
224char *addr;
225int num;
226char *file;
227int 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
251char *CRYPTO_remalloc(a,n)
252char *a;
253int n;
254 {
255 if (a != NULL) Free(a);
256 a=(char *)Malloc(n);
257 return(a);
258 }
259
260char *CRYPTO_dbg_remalloc(a,n,file,line)
261char *a;
262int n;
263char *file;
264int 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
272typedef struct mem_leak_st
273 {
274 BIO *bio;
275 int chunks;
276 long bytes;
277 } MEM_LEAK;
278
279static void print_leak(m,l)
280MEM *m;
281MEM_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
292void CRYPTO_mem_leaks(b)
293BIO *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
318static void (*mem_cb)()=NULL;
319
320static void cb_leak(m,cb)
321MEM *m;
322char *cb;
323 {
324 void (*mem_callback)()=(void (*)())cb;
325 mem_callback(m->order,m->file,m->line,m->num,m->addr);
326 }
327
328void CRYPTO_mem_leaks_cb(cb)
329void (*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
340void CRYPTO_mem_leaks_fp(fp)
341FILE *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
69static unsigned char lvalues[600]={
700x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 0] OBJ_rsadsi */
710x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 6] OBJ_pkcs */
720x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 13] OBJ_md2 */
730x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x05, /* [ 21] OBJ_md5 */
740x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x04, /* [ 29] OBJ_rc4 */
750x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,/* [ 37] OBJ_rsaEncryption */
760x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,/* [ 46] OBJ_md2WithRSAEncryption */
770x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x04,/* [ 55] OBJ_md5WithRSAEncryption */
780x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x01,/* [ 64] OBJ_pbeWithMD2AndDES_CBC */
790x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x03,/* [ 73] OBJ_pbeWithMD5AndDES_CBC */
800x55, /* [ 82] OBJ_X500 */
810x55,0x04, /* [ 83] OBJ_X509 */
820x55,0x04,0x03, /* [ 85] OBJ_commonName */
830x55,0x04,0x06, /* [ 88] OBJ_countryName */
840x55,0x04,0x07, /* [ 91] OBJ_localityName */
850x55,0x04,0x08, /* [ 94] OBJ_stateOrProvinceName */
860x55,0x04,0x0A, /* [ 97] OBJ_organizationName */
870x55,0x04,0x0B, /* [100] OBJ_organizationalUnitName */
880x55,0x08,0x01,0x01, /* [103] OBJ_rsa */
890x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07, /* [107] OBJ_pkcs7 */
900x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x01,/* [115] OBJ_pkcs7_data */
910x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x02,/* [124] OBJ_pkcs7_signed */
920x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x03,/* [133] OBJ_pkcs7_enveloped */
930x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x04,/* [142] OBJ_pkcs7_signedAndEnveloped */
940x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x05,/* [151] OBJ_pkcs7_digest */
950x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x06,/* [160] OBJ_pkcs7_encrypted */
960x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03, /* [169] OBJ_pkcs3 */
970x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03,0x01,/* [177] OBJ_dhKeyAgreement */
980x2B,0x0E,0x03,0x02,0x06, /* [186] OBJ_des_ecb */
990x2B,0x0E,0x03,0x02,0x09, /* [191] OBJ_des_cfb64 */
1000x2B,0x0E,0x03,0x02,0x07, /* [196] OBJ_des_cbc */
1010x2B,0x0E,0x03,0x02,0x11, /* [201] OBJ_des_ede */
1020x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x02, /* [206] OBJ_rc2_cbc */
1030x2B,0x0E,0x03,0x02,0x12, /* [214] OBJ_sha */
1040x2B,0x0E,0x03,0x02,0x0F, /* [219] OBJ_shaWithRSAEncryption */
1050x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x07, /* [224] OBJ_des_ede3_cbc */
1060x2B,0x0E,0x03,0x02,0x08, /* [232] OBJ_des_ofb64 */
1070x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09, /* [237] OBJ_pkcs9 */
1080x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x01,/* [245] OBJ_pkcs9_emailAddress */
1090x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x02,/* [254] OBJ_pkcs9_unstructuredName */
1100x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x03,/* [263] OBJ_pkcs9_contentType */
1110x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x04,/* [272] OBJ_pkcs9_messageDigest */
1120x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x05,/* [281] OBJ_pkcs9_signingTime */
1130x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x06,/* [290] OBJ_pkcs9_countersignature */
1140x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x07,/* [299] OBJ_pkcs9_challengePassword */
1150x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x08,/* [308] OBJ_pkcs9_unstructuredAddress */
1160x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x09,/* [317] OBJ_pkcs9_extCertAttributes */
1170x60,0x86,0x48,0x01,0x86,0xF8,0x42, /* [326] OBJ_netscape */
1180x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01, /* [333] OBJ_netscape_cert_extension */
1190x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02, /* [341] OBJ_netscape_data_type */
1200x2B,0x0E,0x03,0x02,0x1A, /* [349] OBJ_sha1 */
1210x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,/* [354] OBJ_sha1WithRSAEncryption */
1220x2B,0x0E,0x03,0x02,0x0D, /* [363] OBJ_dsaWithSHA */
1230x2B,0x0E,0x03,0x02,0x0C, /* [368] OBJ_dsa_2 */
1240x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0B,/* [373] OBJ_pbeWithSHA1AndRC2_CBC */
1250x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0C,/* [382] OBJ_pbeWithSHA1AndRC4 */
1260x2B,0x0E,0x03,0x02,0x1B, /* [391] OBJ_dsaWithSHA1_2 */
1270x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x01,/* [396] OBJ_netscape_cert_type */
1280x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x02,/* [405] OBJ_netscape_base_url */
1290x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x03,/* [414] OBJ_netscape_revocation_url */
1300x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x04,/* [423] OBJ_netscape_ca_revocation_url */
1310x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x07,/* [432] OBJ_netscape_renewal_url */
1320x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x08,/* [441] OBJ_netscape_ca_policy_url */
1330x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0C,/* [450] OBJ_netscape_ssl_server_name */
1340x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0D,/* [459] OBJ_netscape_comment */
1350x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02,0x05,/* [468] OBJ_netscape_cert_sequence */
1360x55,0x1D, /* [477] OBJ_ld_ce */
1370x55,0x1D,0x0E, /* [479] OBJ_subject_key_identifier */
1380x55,0x1D,0x0F, /* [482] OBJ_key_usage */
1390x55,0x1D,0x10, /* [485] OBJ_private_key_usage_period */
1400x55,0x1D,0x11, /* [488] OBJ_subject_alt_name */
1410x55,0x1D,0x12, /* [491] OBJ_issuer_alt_name */
1420x55,0x1D,0x13, /* [494] OBJ_basic_constraints */
1430x55,0x1D,0x14, /* [497] OBJ_crl_number */
1440x55,0x1D,0x20, /* [500] OBJ_certificate_policies */
1450x55,0x1D,0x23, /* [503] OBJ_authority_key_identifier */
1460x55,0x08,0x03,0x65, /* [506] OBJ_mdc2 */
1470x55,0x08,0x03,0x64, /* [510] OBJ_mdc2WithRSA */
1480x55,0x04,0x2A, /* [514] OBJ_givenName */
1490x55,0x04,0x04, /* [517] OBJ_surname */
1500x55,0x04,0x2B, /* [520] OBJ_initials */
1510x55,0x04,0x2D, /* [523] OBJ_uniqueIdentifier */
1520x55,0x1D,0x1F, /* [526] OBJ_crl_distribution_points */
1530x2B,0x0E,0x03,0x02,0x03, /* [529] OBJ_md5WithRSA */
1540x55,0x04,0x05, /* [534] OBJ_serialNumber */
1550x55,0x04,0x0C, /* [537] OBJ_title */
1560x55,0x04,0x0D, /* [540] OBJ_description */
1570x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0A,/* [543] OBJ_cast5_cbc */
1580x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0C,/* [552] OBJ_pbeWithMD5AndCast5_CBC */
1590x2A,0x86,0x48,0xCE,0x38,0x04,0x03, /* [561] OBJ_dsaWithSHA1 */
1600x2B,0x0E,0x03,0x02,0x1D, /* [568] OBJ_sha1WithRSA */
1610x2A,0x86,0x48,0xCE,0x38,0x04,0x01, /* [573] OBJ_dsa */
1620x2B,0x24,0x03,0x02,0x01, /* [580] OBJ_ripemd160 */
1630x2B,0x24,0x03,0x03,0x01,0x02, /* [585] OBJ_ripemd160WithRSA */
1640x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x08, /* [591] OBJ_rc5_cbc */
165};
166
167static 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
336static 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
434static 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
559static 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
3package 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
27sub main'asm_init_output { @out=(); }
28sub main'asm_get_output { return(@out); }
29sub main'get_labels { return(@labels); }
30sub main'external_label { push(@labels,@_); }
31
32sub main'LB
33 {
34 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
35 return($lb{$_[0]});
36 }
37
38sub main'HB
39 {
40 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
41 return($hb{$_[0]});
42 }
43
44sub main'BP
45 {
46 &get_mem("BYTE",@_);
47 }
48
49sub main'DWP
50 {
51 &get_mem("DWORD",@_);
52 }
53
54sub main'stack_push
55 {
56 local($num)=@_;
57 $stack+=$num*4;
58 &main'sub("esp",$num*4);
59 }
60
61sub main'stack_pop
62 {
63 local($num)=@_;
64 $stack-=$num*4;
65 &main'add("esp",$num*4);
66 }
67
68sub 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
107sub main'mov { &out2("mov",@_); }
108sub main'movb { &out2("mov",@_); }
109sub main'and { &out2("and",@_); }
110sub main'or { &out2("or",@_); }
111sub main'shl { &out2("shl",@_); }
112sub main'shr { &out2("shr",@_); }
113sub main'xor { &out2("xor",@_); }
114sub main'xorb { &out2("xor",@_); }
115sub main'add { &out2("add",@_); }
116sub main'adc { &out2("adc",@_); }
117sub main'sub { &out2("sub",@_); }
118sub main'rotl { &out2("rol",@_); }
119sub main'rotr { &out2("ror",@_); }
120sub main'exch { &out2("xchg",@_); }
121sub main'cmp { &out2("cmp",@_); }
122sub main'lea { &out2("lea",@_); }
123sub main'mul { &out1("mul",@_); }
124sub main'div { &out1("div",@_); }
125sub main'dec { &out1("dec",@_); }
126sub main'inc { &out1("inc",@_); }
127sub main'jmp { &out1("jmp",@_); }
128sub main'jmp_ptr { &out1p("jmp",@_); }
129sub main'je { &out1("je",@_); }
130sub main'jle { &out1("jle",@_); }
131sub main'jz { &out1("jz",@_); }
132sub main'jge { &out1("jge",@_); }
133sub main'jl { &out1("jl",@_); }
134sub main'jb { &out1("jb",@_); }
135sub main'jc { &out1("jc",@_); }
136sub main'jnc { &out1("jnc",@_); }
137sub main'jnz { &out1("jnz",@_); }
138sub main'jne { &out1("jne",@_); }
139sub main'jno { &out1("jno",@_); }
140sub main'push { &out1("push",@_); $stack+=4; }
141sub main'pop { &out1("pop",@_); $stack-=4; }
142sub main'bswap { &out1("bswap",@_); &using486(); }
143sub main'not { &out1("not",@_); }
144sub main'call { &out1("call",'_'.$_[0]); }
145sub main'ret { &out0("ret"); }
146sub main'nop { &out0("nop"); }
147
148sub 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
163sub out0
164 {
165 local($name)=@_;
166
167 push(@out,"\t$name\n");
168 }
169
170sub out1
171 {
172 local($name,$p1)=@_;
173 local($l,$t);
174
175 push(@out,"\t$name\t".&conv($p1)."\n");
176 }
177
178sub conv
179 {
180 local($p)=@_;
181
182 $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
183 return $p;
184 }
185
186sub using486
187 {
188 return if $using486;
189 $using486++;
190 grep(s/\.386/\.486/,@out);
191 }
192
193sub main'file
194 {
195 local($file)=@_;
196
197 local($tmp)=<<"EOF";
198 TITLE $file.asm
199 .386
200.model FLAT
201EOF
202 push(@out,$tmp);
203 }
204
205sub main'function_begin
206 {
207 local($func,$extra)=@_;
208
209 push(@labels,$func);
210
211 local($tmp)=<<"EOF";
212_TEXT SEGMENT
213PUBLIC _$func
214$extra
215_$func PROC NEAR
216 push ebp
217 push ebx
218 push esi
219 push edi
220EOF
221 push(@out,$tmp);
222 $stack=20;
223 }
224
225sub main'function_begin_B
226 {
227 local($func,$extra)=@_;
228
229 local($tmp)=<<"EOF";
230_TEXT SEGMENT
231PUBLIC _$func
232$extra
233_$func PROC NEAR
234EOF
235 push(@out,$tmp);
236 $stack=4;
237 }
238
239sub 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
251EOF
252 push(@out,$tmp);
253 $stack=0;
254 %label=();
255 }
256
257sub main'function_end_B
258 {
259 local($func)=@_;
260
261 local($tmp)=<<"EOF";
262_$func ENDP
263_TEXT ENDS
264EOF
265 push(@out,$tmp);
266 $stack=0;
267 %label=();
268 }
269
270sub 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
280EOF
281 push(@out,$tmp);
282 }
283
284sub main'file_end
285 {
286 push(@out,"END\n");
287 }
288
289sub main'wparam
290 {
291 local($num)=@_;
292
293 return(&main'DWP($stack+$num*4,"esp","",0));
294 }
295
296sub 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
309sub main'comment
310 {
311 foreach (@_)
312 {
313 push(@out,"\t; $_\n");
314 }
315 }
316
317sub main'label
318 {
319 if (!defined($label{$_[0]}))
320 {
321 $label{$_[0]}="\$${label}${_[0]}";
322 $label++;
323 }
324 return($label{$_[0]});
325 }
326
327sub 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
337sub main'data_word
338 {
339 push(@out,"\tDD\t$_[0]\n");
340 }
341
342sub 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
9package x86unix;
10
11$label="L000";
12
13$align=($main'aout)?"4":"16";
14$under=($main'aout)?"_":"";
15$com_start=($main'sol)?"/":"#";
16
17sub main'asm_init_output { @out=(); }
18sub main'asm_get_output { return(@out); }
19sub main'get_labels { return(@labels); }
20sub main'external_label { push(@labels,@_); }
21
22if ($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
71sub main'LB
72 {
73 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
74 return($lb{$_[0]});
75 }
76
77sub main'HB
78 {
79 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
80 return($hb{$_[0]});
81 }
82
83sub 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
99sub 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
121sub main'mov { &out2("movl",@_); }
122sub main'movb { &out2("movb",@_); }
123sub main'and { &out2("andl",@_); }
124sub main'or { &out2("orl",@_); }
125sub main'shl { &out2("sall",@_); }
126sub main'shr { &out2("shrl",@_); }
127sub main'xor { &out2("xorl",@_); }
128sub main'xorb { &out2("xorb",@_); }
129sub main'add { &out2("addl",@_); }
130sub main'adc { &out2("adcl",@_); }
131sub main'sub { &out2("subl",@_); }
132sub main'rotl { &out2("roll",@_); }
133sub main'rotr { &out2("rorl",@_); }
134sub main'exch { &out2("xchg",@_); }
135sub main'cmp { &out2("cmpl",@_); }
136sub main'lea { &out2("leal",@_); }
137sub main'mul { &out1("mull",@_); }
138sub main'div { &out1("divl",@_); }
139sub main'jmp { &out1("jmp",@_); }
140sub main'jmp_ptr { &out1p("jmp",@_); }
141sub main'je { &out1("je",@_); }
142sub main'jle { &out1("jle",@_); }
143sub main'jne { &out1("jne",@_); }
144sub main'jnz { &out1("jnz",@_); }
145sub main'jz { &out1("jz",@_); }
146sub main'jge { &out1("jge",@_); }
147sub main'jl { &out1("jl",@_); }
148sub main'jb { &out1("jb",@_); }
149sub main'jc { &out1("jc",@_); }
150sub main'jnc { &out1("jnc",@_); }
151sub main'jno { &out1("jno",@_); }
152sub main'dec { &out1("decl",@_); }
153sub main'inc { &out1("incl",@_); }
154sub main'push { &out1("pushl",@_); $stack+=4; }
155sub main'pop { &out1("popl",@_); $stack-=4; }
156sub main'bswap { &out1("bswapl",@_); }
157sub main'not { &out1("notl",@_); }
158sub main'call { &out1("call",$under.$_[0]); }
159sub main'ret { &out0("ret"); }
160sub main'nop { &out0("nop"); }
161
162sub 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
195sub 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
218sub out1p
219 {
220 local($name,$p1)=@_;
221 local($l,$t);
222
223 push(@out,"\t$name\t*".&conv($p1)."\n");
224 }
225
226sub out0
227 {
228 push(@out,"\t$_[0]\n");
229 }
230
231sub 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
244sub main'file
245 {
246 local($file)=@_;
247
248 local($tmp)=<<"EOF";
249 .file "$file.s"
250 .version "01.01"
251gcc2_compiled.:
252EOF
253 push(@out,$tmp);
254 }
255
256sub 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
267EOF
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
279EOF
280 push(@out,$tmp);
281 $stack=20;
282 }
283
284sub 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
295EOF
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
304sub 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:
317EOF
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
327sub 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
337EOF
338 push(@out,$tmp);
339 }
340
341sub 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
356sub main'wparam
357 {
358 local($num)=@_;
359
360 return(&main'DWP($stack+$num*4,"esp","",0));
361 }
362
363sub main'stack_push
364 {
365 local($num)=@_;
366 $stack+=$num*4;
367 &main'sub("esp",$num*4);
368 }
369
370sub main'stack_pop
371 {
372 local($num)=@_;
373 $stack-=$num*4;
374 &main'add("esp",$num*4);
375 }
376
377sub 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
390sub 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
401sub main'label
402 {
403 if (!defined($label{$_[0]}))
404 {
405 $label{$_[0]}=".${label}${_[0]}";
406 $label++;
407 }
408 return($label{$_[0]});
409 }
410
411sub 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
422sub main'file_end
423 {
424 }
425
426sub 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 @@
1int PKCS7_set_content_type(PKCS7 *p7, int type);
2Call to set the type of PKCS7 object we are working on
3
4int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
5 EVP_MD *dgst);
6Use this to setup a signer info
7There will also be functions to add signed and unsigned attributes.
8
9int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
10Add a signer info to the content.
11
12int PKCS7_add_certificae(PKCS7 *p7, X509 *x509);
13int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
14
15----
16
17p7=PKCS7_new();
18PKCS7_set_content_type(p7,NID_pkcs7_signed);
19
20signer=PKCS7_SINGNER_INFO_new();
21PKCS7_SIGNER_INFO_set(signer,x509,pkey,EVP_md5());
22PKCS7_add_signer(py,signer);
23
24we 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
63main(argc,argv)
64int argc;
65char *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());
82again:
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);
139err:
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 @@
1j,H>_æá_­DôzEîLœ VJ³ß觬¤””E3ûáYäx%_Àk
23ê)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
67PKCS7_in_bio(PKCS7 *p7,BIO *in);
68PKCS7_out_bio(PKCS7 *p7,BIO *out);
69
70PKCS7_add_signer(PKCS7 *p7,X509 *cert,EVP_PKEY *key);
71PKCS7_cipher(PKCS7 *p7,EVP_CIPHER *cipher);
72
73PKCS7_Init(PKCS7 *p7);
74PKCS7_Update(PKCS7 *p7);
75PKCS7_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 @@
1issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
2subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Server test cert (512 bit)
3-----BEGIN CERTIFICATE-----
4MIIB6TCCAVICAQAwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV
5BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD
6VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNOTcwNjA5MTM1NzQ2WhcNOTgwNjA5
7MTM1NzQ2WjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG
8A1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxIzAhBgNVBAMTGlNlcnZlciB0ZXN0IGNl
9cnQgKDUxMiBiaXQpMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ+zw4Qnlf8SMVIP
10Fe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVDTGiXav6ooKXfX3j/7tdkuD8Ey2//
11Kv7+ue0CAwEAATANBgkqhkiG9w0BAQQFAAOBgQB4TMR2CvacKE9wAsu9jyCX8YiW
12mgCM+YoP6kt4Zkj2z5IRfm7WrycKsnpnOR+tGeqAjkCeZ6/36o9l91RvPnN1VJ/i
13xQv2df0KFeMr00IkDdTNAdIWqFkSsZTAY2QAdgenb7MB1joejquYzO2DQIO7+wpH
14irObpESxAZLySCmPPg==
15-----END CERTIFICATE-----
16-----BEGIN RSA PRIVATE KEY-----
17MIIBPAIBAAJBAJ+zw4Qnlf8SMVIPFe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVD
18TGiXav6ooKXfX3j/7tdkuD8Ey2//Kv7+ue0CAwEAAQJAN6W31vDEP2DjdqhzCDDu
19OA4NACqoiFqyblo7yc2tM4h4xMbC3Yx5UKMN9ZkCtX0gzrz6DyF47bdKcWBzNWCj
20gQIhANEoojVt7hq+SQ6MCN6FTAysGgQf56Q3TYoJMoWvdiXVAiEAw3e3rc+VJpOz
21rHuDo6bgpjUAAXM+v3fcpsfZSNO6V7kCIQCtbVjanpUwvZkMI9by02oUk9taki3b
22PzPfAfNPYAbCJQIhAJXNQDWyqwn/lGmR11cqY2y9nZ1+5w3yHGatLrcDnQHxAiEA
23vnlEGo8K85u+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
63main(argc,argv)
64int argc;
65char *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());
84again:
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);
135err:
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
64int verify_callback(int ok, X509_STORE_CTX *ctx);
65
66BIO *bio_err=NULL;
67
68main(argc,argv)
69int argc;
70char *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());
93again:
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);
181err:
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 *. */
188int verify_callback(ok, ctx)
189int ok;
190X509_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
74We 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
120static int state_num=0,state_index=0;
121static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH];
122static unsigned char md[MD_DIGEST_LENGTH];
123static int md_count=0;
124
125char *RAND_version="RAND part of SSLeay 0.9.0b 29-Jun-1998";
126
127void 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
136void RAND_seed(buf,num)
137unsigned char *buf;
138int 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
198void RAND_bytes(buf,num)
199unsigned char *buf;
200int 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 */
342void 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
66int 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>
71extern 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>
84struct 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)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double 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
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int 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
151double Time_F(s)
152int 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
188int main(argc,argv)
189int argc;
190char **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
67unsigned 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
78unsigned 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
85unsigned 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
93unsigned char k[16]={
94 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04,
95 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08};
96
97unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03};
98unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5};
99unsigned char out[80];
100
101char *text="Hello to all people out there";
102
103static unsigned char cfb_key[16]={
104 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
105 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
106 };
107static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
108static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
109#define CFB_TEST_SIZE 24
110static 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 };
117static 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);*/
130static char *pt(unsigned char *p);
131#else
132/*static int cfb64_test(); */
133static char *pt();
134#endif
135
136#endif
137
138int main(argc,argv)
139int argc;
140char *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
211static int cfb64_test(cfb_cipher)
212unsigned 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
250static char *pt(p)
251unsigned 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
64char *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",
70NULL
71};
72
73int main(argc, argv)
74int argc;
75char *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 {
116bad:
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__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void 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)
22inline
23void 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
37void 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>
71extern 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>
84struct 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)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double 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
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int 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
151double Time_F(s)
152int 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
188int main(argc,argv)
189int argc;
190char **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
64unsigned 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
73unsigned char data_len[7]={8,8,8,20,28,10};
74unsigned 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
89unsigned 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
104int main(argc,argv)
105int argc;
106char *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 @@
1Newsgroups: sci.crypt,alt.security,comp.security.misc,alt.privacy
2Path: 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
3From: sterndark@netcom.com (David Sterndark)
4Subject: RC4 Algorithm revealed.
5Message-ID: <sternCvKL4B.Hyy@netcom.com>
6Sender: sterndark@netcom.com
7Organization: NETCOM On-line Communication Services (408 261-4700 guest)
8X-Newsreader: TIN [version 1.2 PL1]
9Date: Wed, 14 Sep 1994 06:35:31 GMT
10Lines: 263
11Xref: ghost.dsi.unimi.it sci.crypt:27332 alt.security:14732 comp.security.misc:11701 alt.privacy:16026
12
13I am shocked, shocked, I tell you, shocked, to discover
14that the cypherpunks have illegaly and criminally revealed
15a crucial RSA trade secret and harmed the security of
16America by reverse engineering the RC4 algorithm and
17publishing it to the world.
18
19On 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
106Another cypherpunk, this one not anonymous, tested the
107output from this algorithm against the output from
108official 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 ---------------------------------------------------------------------
273We have the right to defend ourselves and our
274property, because of the kind of animals that we James A. Donald
275are. True law derives from this right, not from
276the 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
63extern "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
84typedef 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
93void RC5_32_set_key(RC5_32_KEY *key, int len, unsigned char *data,
94 int rounds);
95void RC5_32_ecb_encrypt(unsigned char *in,unsigned char *out,RC5_32_KEY *key,
96 int enc);
97void RC5_32_encrypt(unsigned long *data,RC5_32_KEY *key);
98void RC5_32_decrypt(unsigned long *data,RC5_32_KEY *key);
99void RC5_32_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
100 RC5_32_KEY *ks, unsigned char *iv, int enc);
101void RC5_32_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
102 RC5_32_KEY *schedule, unsigned char *ivec, int *num, int enc);
103void 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
108void RC5_32_set_key();
109void RC5_32_ecb_encrypt();
110void RC5_32_encrypt();
111void RC5_32_decrypt();
112void RC5_32_cbc_encrypt();
113void RC5_32_cfb64_encrypt();
114void 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__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void 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)
22inline
23void 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
37extern "C" {
38void ripemd160_block_x86(RIPEMD160_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void 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
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **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
105void do_fp(f)
106FILE *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
126void pt(md)
127unsigned 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
64char *test[]={
65 "",
66 "a",
67 "abc",
68 "message digest",
69 "abcdefghijklmnopqrstuvwxyz",
70 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
71 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
72 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
73 NULL,
74 };
75
76char *ret[]={
77 "9c1185a5c5e9fc54612808977ee8f548b2258d31",
78 "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",
79 "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
80 "5d0689ef49d2fae572b881b123a85ffa21595f36",
81 "f71c27109c692c1b56bbdceb5b9d2865b3708dbc",
82 "12a053384a9c0c88e405a06c27dcf49ada62eb2b",
83 "b0e20b6e3116640286ed3a87a5713079b21f5189",
84 "9b752e45573d4b39f4dbd3323cab82bf63326bfb",
85 };
86
87#ifndef NOPROTO
88static char *pt(unsigned char *md);
89#else
90static char *pt();
91#endif
92
93int main(argc,argv)
94int argc;
95char *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
123static char *pt(md)
124unsigned 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
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **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
105void do_fp(f)
106FILE *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
126void pt(md)
127unsigned 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
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **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
105void do_fp(f)
106FILE *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
126void pt(md)
127unsigned 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__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void 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)
22inline
23void 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
37extern "C" {
38void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void 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
67char *test[]={
68 "abc",
69 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
70 NULL,
71 };
72
73#ifdef SHA_0
74char *ret[]={
75 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
76 "d2516ee1acfa5baf33dfc1c471e438449ef134c8",
77 };
78char *bigret=
79 "3232affa48628a26653b5aaa44541fd90d690603";
80#endif
81#ifdef SHA_1
82char *ret[]={
83 "a9993e364706816aba3e25717850c26c9cd0d89d",
84 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
85 };
86char *bigret=
87 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
88#endif
89
90#ifndef NOPROTO
91static char *pt(unsigned char *md);
92#else
93static char *pt();
94#endif
95
96int main(argc,argv)
97int argc;
98char *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
146static char *pt(md)
147unsigned 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
66char *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
94void SHA_Init(c)
95SHA_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
107void SHA_Update(c, data, len)
108SHA_CTX *c;
109register unsigned char *data;
110unsigned 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
240void SHA_Transform(c,b)
241SHA_CTX *c;
242unsigned 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
277void sha_block(c, W, num)
278SHA_CTX *c;
279register unsigned long *W;
280int 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
396void SHA_Final(md, c)
397unsigned char *md;
398SHA_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
63unsigned char *SHA(d, n, md)
64unsigned char *d;
65unsigned long n;
66unsigned 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
67char *test[]={
68 "abc",
69 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
70 NULL,
71 };
72
73#ifdef SHA_0
74char *ret[]={
75 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
76 "d2516ee1acfa5baf33dfc1c471e438449ef134c8",
77 };
78char *bigret=
79 "3232affa48628a26653b5aaa44541fd90d690603";
80#endif
81#ifdef SHA_1
82char *ret[]={
83 "a9993e364706816aba3e25717850c26c9cd0d89d",
84 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
85 };
86char *bigret=
87 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
88#endif
89
90#ifndef NOPROTO
91static char *pt(unsigned char *md);
92#else
93static char *pt();
94#endif
95
96int main(argc,argv)
97int argc;
98char *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
146static char *pt(md)
147unsigned 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
96int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth,
97 int error,char *arg);
98void thread_setup(void);
99void thread_cleanup(void);
100void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx);
101
102void irix_locking_callback(int mode,int type,char *file,int line);
103void solaris_locking_callback(int mode,int type,char *file,int line);
104void win32_locking_callback(int mode,int type,char *file,int line);
105void pthreads_locking_callback(int mode,int type,char *file,int line);
106
107unsigned long irix_thread_id(void );
108unsigned long solaris_thread_id(void );
109unsigned long pthreads_thread_id(void );
110
111#else
112int MS_CALLBACK verify_callback();
113void thread_setup();
114void thread_cleanup();
115void do_threads();
116
117void irix_locking_callback();
118void solaris_locking_callback();
119void win32_locking_callback();
120void pthreads_locking_callback();
121
122unsigned long irix_thread_id();
123unsigned long solaris_thread_id();
124unsigned long pthreads_thread_id();
125
126#endif
127
128BIO *bio_err=NULL;
129BIO *bio_stdout=NULL;
130
131static char *cipher=NULL;
132int verbose=0;
133#ifdef FIONBIO
134static int s_nbio=0;
135#endif
136
137int thread_number=10;
138int number_of_loops=10;
139int reconnect=0;
140int cache_stats=0;
141
142#ifndef NOPROTO
143int doit(char *ctx[4]);
144#else
145int doit();
146#endif
147
148static void print_stats(fp,ctx)
149FILE *fp;
150SSL_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
167static 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
185int main(argc, argv)
186int argc;
187char *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 {
266bad:
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();
327end:
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
361int ndoit(ssl_ctx)
362SSL_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
408int doit(ctx)
409char *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
655err:
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
684int MS_CALLBACK verify_callback(ok, xs, xi, depth, error, arg)
685int ok;
686X509 *xs;
687X509 *xi;
688int depth;
689int error;
690char *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
709static HANDLE lock_cs[CRYPTO_NUM_LOCKS];
710
711void 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
724void 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
733void win32_locking_callback(mode,type,file,line)
734int mode;
735int type;
736char *file;
737int 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
749void do_threads(s_ctx,c_ctx)
750SSL_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
805static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
806/*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */
807static long lock_count[CRYPTO_NUM_LOCKS];
808
809void 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
824void thread_cleanup()
825 {
826 int i;
827
828 CRYPTO_set_locking_callback(NULL);
829fprintf(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 }
836fprintf(stderr,"done cleanup\n");
837 }
838
839void solaris_locking_callback(mode,type,file,line)
840int mode;
841int type;
842char *file;
843int line;
844 {
845#ifdef undef
846fprintf(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/*
853if (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
875void do_threads(s_ctx,c_ctx)
876SSL_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
905unsigned 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
917static usptr_t *arena;
918static usema_t *lock_cs[CRYPTO_NUM_LOCKS];
919
920void 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
944void 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
959void irix_locking_callback(mode,type,file,line)
960int mode;
961int type;
962char *file;
963int 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
977void do_threads(s_ctx,c_ctx)
978SSL_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
1003unsigned 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
1014static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS];
1015static long lock_count[CRYPTO_NUM_LOCKS];
1016
1017void 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
1031void 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
1046void pthreads_locking_callback(mode,type,file,line)
1047int mode;
1048int type;
1049char *file;
1050int 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
1075void do_threads(s_ctx,c_ctx)
1076SSL_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
1104unsigned 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
86int CRYPTO_thread_setup(void);
87void CRYPTO_thread_cleanup(void);
88
89static void irix_locking_callback(int mode,int type,char *file,int line);
90static void solaris_locking_callback(int mode,int type,char *file,int line);
91static void win32_locking_callback(int mode,int type,char *file,int line);
92static void pthreads_locking_callback(int mode,int type,char *file,int line);
93
94static unsigned long irix_thread_id(void );
95static unsigned long solaris_thread_id(void );
96static unsigned long pthreads_thread_id(void );
97
98#else
99int CRYPOTO_thread_setup();
100void CRYPTO_cleanup();
101
102static void irix_locking_callback();
103static void solaris_locking_callback();
104static void win32_locking_callback();
105static void pthreads_locking_callback();
106
107static unsigned long irix_thread_id();
108static unsigned long solaris_thread_id();
109static 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
123static HANDLE lock_cs[CRYPTO_NUM_LOCKS];
124
125int 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
139static 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
148void win32_locking_callback(mode,type,file,line)
149int mode;
150int type;
151char *file;
152int 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
170static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
171#ifdef USE_MUTEX
172static long lock_count[CRYPTO_NUM_LOCKS];
173#else
174static rwlock_t lock_cs[CRYPTO_NUM_LOCKS];
175#endif
176
177void 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
195void 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
210void solaris_locking_callback(mode,type,file,line)
211int mode;
212int type;
213char *file;
214int 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
251unsigned 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
263static usptr_t *arena;
264static usema_t *lock_cs[CRYPTO_NUM_LOCKS];
265
266void 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
290void 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
305void irix_locking_callback(mode,type,file,line)
306int mode;
307int type;
308char *file;
309int 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
321unsigned 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
333static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS];
334static long lock_count[CRYPTO_NUM_LOCKS];
335
336void 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
350void 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
361void pthreads_locking_callback(mode,type,file,line)
362int mode;
363int type;
364char *file;
365int 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
390unsigned 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
115typedef 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
129char *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
143void ms_time_final(a)
144char *a;
145 {
146 if (a != NULL)
147 free(a);
148 }
149
150void ms_time_get(a)
151char *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
169double ms_time_diff(ap,bp)
170char *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
191int ms_time_cmp(ap,bp)
192char *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
3perl util/perlpath.pl /usr/bin
4perl util/ssldir.pl /usr/local
5perl util/mk1mf.pl FreeBSD >Makefile.FreeBSD
6perl 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
9foreach (@ARGV)
10 {
11 &dofile($_);
12 }
13
14sub 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
63sub 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 */
122EOF
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
5open(IN,"<$infile") || die "unable to open $infile:$!\n";
6$_=<IN>;
7for (;;)
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 }
52close(IN);
53
54@a=split(/\s+/,$libsrc);
55foreach (@a)
56 {
57 print "${_}.c\n";
58 }
59
60sub 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
10foreach $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
3while (<>)
4 {
5 print
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
6PATH=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
10perl util/mk1mf.pl VC-WIN16 dll >ms/w31dll.mak
11# perl util/mk1mf.pl VC-WIN32 >ms/nt.mak
12perl util/mk1mf.pl VC-WIN32 dll >ms/ntdll.mak
13
14perl util/mkdef.pl 16 libeay > ms/libeay16.def
15perl util/mkdef.pl 32 libeay > ms/libeay32.def
16perl util/mkdef.pl 16 ssleay > ms/ssleay16.def
17perl 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
6open(ERR,$ARGV[0]) || die "unable to open error file '$ARGV[0]':$!\n";
7@err=<ERR>;
8close(ERR);
9
10open(IN,$ARGV[1]) || die "unable to open header file '$ARGV[1]':$!\n";
11
12@out="";
13while (<IN>)
14 {
15 push(@out,$_);
16 last if /BEGIN ERROR CODES/;
17 }
18close(IN);
19
20open(OUT,">$ARGV[1]") || die "unable to open header file '$ARGV[1]':$1\n";
21print OUT @out;
22print OUT @err;
23print OUT <<"EOF";
24
25#ifdef __cplusplus
26}
27#endif
28#endif
29
30EOF
31close(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="";
8while (<>)
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
42if ($sym{'TOP'} eq ".")
43 {
44 $n=0;
45 $dir=".";
46 }
47else {
48 $n=split(/\//,$sym{'TOP'});
49 @_=split(/\//,$pwd);
50 $z=$#_-$n+1;
51 foreach $i ($z .. $#_) { $dir.=$_[$i]."/"; }
52 chop($dir);
53 }
54
55print "RELATIVE_DIRECTORY=$dir\n";
56
57foreach (sort keys %sym)
58 {
59 print "$_=$sym{$_}\n";
60 }
61print "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
6if [ -f makefile.ssl -a ! -f Makefile.ssl ]; then
7 /bin/mv makefile.ssl Makefile.ssl
8fi
9chmod +x Configure util/*
10echo cleaning
11/bin/rm -f `find . -name '*.$$$' -print` 2>/dev/null >/dev/null
12echo 'removing those damn ^M'
13perl -pi -e 's/\015//' `find . -type 'f' -print |grep -v '.obj$' |grep -v '.der$' |grep -v '.gz'`
14make -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
15doit="${DOITPROG:-}"
16
17
18# put in absolute paths if you don't have them in your path; or use env. vars.
19
20mvprog="${MVPROG:-mv}"
21cpprog="${CPPROG:-cp}"
22chmodprog="${CHMODPROG:-chmod}"
23chownprog="${CHOWNPROG:-chown}"
24chgrpprog="${CHGRPPROG:-chgrp}"
25stripprog="${STRIPPROG:-strip}"
26rmprog="${RMPROG:-rm}"
27
28instcmd="$mvprog"
29chmodcmd=""
30chowncmd=""
31chgrpcmd=""
32stripcmd=""
33rmcmd="$rmprog -f"
34src=""
35dst=""
36
37while [ 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
71done
72
73if [ x"$src" = x ]
74then
75 echo "install: no input file specified"
76 exit 1
77fi
78
79if [ x"$dst" = x ]
80then
81 echo "install: no destination specified"
82 exit 1
83fi
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
89if [ -d $dst ]
90then
91 dst="$dst"/`basename $src`
92fi
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
103if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; fi
104if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; fi
105if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; fi
106if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; fi
107
108exit 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 @@
1SSLeay 1
2SSLeay_version 2
3ASN1_BIT_STRING_asn1_meth 3
4ASN1_HEADER_free 4
5ASN1_HEADER_new 5
6ASN1_IA5STRING_asn1_meth 6
7ASN1_INTEGER_get 7
8ASN1_INTEGER_set 8
9ASN1_INTEGER_to_BN 9
10ASN1_OBJECT_create 10
11ASN1_OBJECT_free 11
12ASN1_OBJECT_new 12
13ASN1_PRINTABLE_type 13
14ASN1_STRING_cmp 14
15ASN1_STRING_dup 15
16ASN1_STRING_free 16
17ASN1_STRING_new 17
18ASN1_STRING_print 18
19ASN1_STRING_set 19
20ASN1_STRING_type_new 20
21ASN1_TYPE_free 21
22ASN1_TYPE_new 22
23ASN1_UNIVERSALSTRING_to_string 23
24ASN1_UTCTIME_check 24
25ASN1_UTCTIME_print 25
26ASN1_UTCTIME_set 26
27ASN1_check_infinite_end 27
28ASN1_d2i_bio 28
29ASN1_d2i_fp 29
30ASN1_digest 30
31ASN1_dup 31
32ASN1_get_object 32
33ASN1_i2d_bio 33
34ASN1_i2d_fp 34
35ASN1_object_size 35
36ASN1_parse 36
37ASN1_put_object 37
38ASN1_sign 38
39ASN1_verify 39
40BF_cbc_encrypt 40
41BF_cfb64_encrypt 41
42BF_ecb_encrypt 42
43BF_encrypt 43
44BF_ofb64_encrypt 44
45BF_options 45
46BF_set_key 46
47BIO_CONNECT_free 47
48BIO_CONNECT_new 48
49BIO_accept 51
50BIO_ctrl 52
51BIO_int_ctrl 53
52BIO_debug_callback 54
53BIO_dump 55
54BIO_dup_chain 56
55BIO_f_base64 57
56BIO_f_buffer 58
57BIO_f_cipher 59
58BIO_f_md 60
59BIO_f_null 61
60BIO_f_proxy_server 62
61BIO_fd_non_fatal_error 63
62BIO_fd_should_retry 64
63BIO_find_type 65
64BIO_free 66
65BIO_free_all 67
66BIO_get_accept_socket 69
67BIO_get_filter_bio 70
68BIO_get_host_ip 71
69BIO_get_port 72
70BIO_get_retry_BIO 73
71BIO_get_retry_reason 74
72BIO_gethostbyname 75
73BIO_gets 76
74BIO_new 78
75BIO_new_accept 79
76BIO_new_connect 80
77BIO_new_fd 81
78BIO_new_file 82
79BIO_new_fp 83
80BIO_new_socket 84
81BIO_pop 85
82BIO_printf 86
83BIO_push 87
84BIO_puts 88
85BIO_read 89
86BIO_s_accept 90
87BIO_s_connect 91
88BIO_s_fd 92
89BIO_s_file 93
90BIO_s_mem 95
91BIO_s_null 96
92BIO_s_proxy_client 97
93BIO_s_socket 98
94BIO_set 100
95BIO_set_cipher 101
96BIO_set_tcp_ndelay 102
97BIO_sock_cleanup 103
98BIO_sock_error 104
99BIO_sock_init 105
100BIO_sock_non_fatal_error 106
101BIO_sock_should_retry 107
102BIO_socket_ioctl 108
103BIO_write 109
104BN_CTX_free 110
105BN_CTX_new 111
106BN_MONT_CTX_free 112
107BN_MONT_CTX_new 113
108BN_MONT_CTX_set 114
109BN_add 115
110BN_add_word 116
111BN_hex2bn 117
112BN_bin2bn 118
113BN_bn2hex 119
114BN_bn2bin 120
115BN_clear 121
116BN_clear_bit 122
117BN_clear_free 123
118BN_cmp 124
119BN_copy 125
120BN_div 126
121BN_div_word 127
122BN_dup 128
123BN_free 129
124BN_from_montgomery 130
125BN_gcd 131
126BN_generate_prime 132
127BN_get_word 133
128BN_is_bit_set 134
129BN_is_prime 135
130BN_lshift 136
131BN_lshift1 137
132BN_mask_bits 138
133BN_mod 139
134BN_mod_exp 140
135BN_mod_exp_mont 141
136BN_mod_exp_recp 142
137BN_mod_exp_simple 143
138BN_mod_inverse 144
139BN_mod_mul 145
140BN_mod_mul_montgomery 146
141BN_mod_mul_reciprocal 147
142BN_mod_word 148
143BN_mul 149
144BN_new 150
145BN_num_bits 151
146BN_num_bits_word 152
147BN_options 153
148BN_print 154
149BN_print_fp 155
150BN_rand 156
151BN_reciprocal 157
152BN_rshift 158
153BN_rshift1 159
154BN_set_bit 160
155BN_set_word 161
156BN_sqr 162
157BN_sub 163
158BN_to_ASN1_INTEGER 164
159BN_ucmp 165
160BN_value_one 166
161BUF_MEM_free 167
162BUF_MEM_grow 168
163BUF_MEM_new 169
164BUF_strdup 170
165CONF_free 171
166CONF_get_number 172
167CONF_get_section 173
168CONF_get_string 174
169CONF_load 175
170CRYPTO_add_lock 176
171CRYPTO_dbg_free 177
172CRYPTO_dbg_malloc 178
173CRYPTO_dbg_realloc 179
174CRYPTO_dbg_remalloc 180
175CRYPTO_free 181
176CRYPTO_get_add_lock_callback 182
177CRYPTO_get_id_callback 183
178CRYPTO_get_lock_name 184
179CRYPTO_get_locking_callback 185
180CRYPTO_get_mem_functions 186
181CRYPTO_lock 187
182CRYPTO_malloc 188
183CRYPTO_mem_ctrl 189
184CRYPTO_mem_leaks 190
185CRYPTO_mem_leaks_cb 191
186CRYPTO_mem_leaks_fp 192
187CRYPTO_realloc 193
188CRYPTO_remalloc 194
189CRYPTO_set_add_lock_callback 195
190CRYPTO_set_id_callback 196
191CRYPTO_set_locking_callback 197
192CRYPTO_set_mem_functions 198
193CRYPTO_thread_id 199
194DH_check 200
195DH_compute_key 201
196DH_free 202
197DH_generate_key 203
198DH_generate_parameters 204
199DH_new 205
200DH_size 206
201DHparams_print 207
202DHparams_print_fp 208
203DSA_free 209
204DSA_generate_key 210
205DSA_generate_parameters 211
206DSA_is_prime 212
207DSA_new 213
208DSA_print 214
209DSA_print_fp 215
210DSA_sign 216
211DSA_sign_setup 217
212DSA_size 218
213DSA_verify 219
214DSAparams_print 220
215DSAparams_print_fp 221
216ERR_clear_error 222
217ERR_error_string 223
218ERR_free_strings 224
219ERR_func_error_string 225
220ERR_get_err_state_table 226
221ERR_get_error 227
222ERR_get_error_line 228
223ERR_get_state 229
224ERR_get_string_table 230
225ERR_lib_error_string 231
226ERR_load_ASN1_strings 232
227ERR_load_BIO_strings 233
228ERR_load_BN_strings 234
229ERR_load_BUF_strings 235
230ERR_load_CONF_strings 236
231ERR_load_DH_strings 237
232ERR_load_DSA_strings 238
233ERR_load_ERR_strings 239
234ERR_load_EVP_strings 240
235ERR_load_OBJ_strings 241
236ERR_load_PEM_strings 242
237ERR_load_PROXY_strings 243
238ERR_load_RSA_strings 244
239ERR_load_X509_strings 245
240ERR_load_crypto_strings 246
241ERR_load_strings 247
242ERR_peek_error 248
243ERR_peek_error_line 249
244ERR_print_errors 250
245ERR_print_errors_fp 251
246ERR_put_error 252
247ERR_reason_error_string 253
248ERR_remove_state 254
249EVP_BytesToKey 255
250EVP_CIPHER_CTX_cleanup 256
251EVP_CipherFinal 257
252EVP_CipherInit 258
253EVP_CipherUpdate 259
254EVP_DecodeBlock 260
255EVP_DecodeFinal 261
256EVP_DecodeInit 262
257EVP_DecodeUpdate 263
258EVP_DecryptFinal 264
259EVP_DecryptInit 265
260EVP_DecryptUpdate 266
261EVP_DigestFinal 267
262EVP_DigestInit 268
263EVP_DigestUpdate 269
264EVP_EncodeBlock 270
265EVP_EncodeFinal 271
266EVP_EncodeInit 272
267EVP_EncodeUpdate 273
268EVP_EncryptFinal 274
269EVP_EncryptInit 275
270EVP_EncryptUpdate 276
271EVP_OpenFinal 277
272EVP_OpenInit 278
273EVP_PKEY_assign 279
274EVP_PKEY_copy_parameters 280
275EVP_PKEY_free 281
276EVP_PKEY_missing_parameters 282
277EVP_PKEY_new 283
278EVP_PKEY_save_parameters 284
279EVP_PKEY_size 285
280EVP_PKEY_type 286
281EVP_SealFinal 287
282EVP_SealInit 288
283EVP_SignFinal 289
284EVP_VerifyFinal 290
285EVP_add_alias 291
286EVP_add_cipher 292
287EVP_add_digest 293
288EVP_bf_cbc 294
289EVP_bf_cfb 295
290EVP_bf_ecb 296
291EVP_bf_ofb 297
292EVP_cleanup 298
293EVP_des_cbc 299
294EVP_des_cfb 300
295EVP_des_ecb 301
296EVP_des_ede 302
297EVP_des_ede3 303
298EVP_des_ede3_cbc 304
299EVP_des_ede3_cfb 305
300EVP_des_ede3_ofb 306
301EVP_des_ede_cbc 307
302EVP_des_ede_cfb 308
303EVP_des_ede_ofb 309
304EVP_des_ofb 310
305EVP_desx_cbc 311
306EVP_dss 312
307EVP_dss1 313
308EVP_enc_null 314
309EVP_get_cipherbyname 315
310EVP_get_digestbyname 316
311EVP_get_pw_prompt 317
312EVP_idea_cbc 318
313EVP_idea_cfb 319
314EVP_idea_ecb 320
315EVP_idea_ofb 321
316EVP_md2 322
317EVP_md5 323
318EVP_md_null 324
319EVP_rc2_cbc 325
320EVP_rc2_cfb 326
321EVP_rc2_ecb 327
322EVP_rc2_ofb 328
323EVP_rc4 329
324EVP_read_pw_string 330
325EVP_set_pw_prompt 331
326EVP_sha 332
327EVP_sha1 333
328MD2 334
329MD2_Final 335
330MD2_Init 336
331MD2_Update 337
332MD2_options 338
333MD5 339
334MD5_Final 340
335MD5_Init 341
336MD5_Update 342
337MDC2 343
338MDC2_Final 344
339MDC2_Init 345
340MDC2_Update 346
341NETSCAPE_SPKAC_free 347
342NETSCAPE_SPKAC_new 348
343NETSCAPE_SPKI_free 349
344NETSCAPE_SPKI_new 350
345NETSCAPE_SPKI_sign 351
346NETSCAPE_SPKI_verify 352
347OBJ_add_object 353
348OBJ_bsearch 354
349OBJ_cleanup 355
350OBJ_cmp 356
351OBJ_create 357
352OBJ_dup 358
353OBJ_ln2nid 359
354OBJ_new_nid 360
355OBJ_nid2ln 361
356OBJ_nid2obj 362
357OBJ_nid2sn 363
358OBJ_obj2nid 364
359OBJ_sn2nid 365
360OBJ_txt2nid 366
361PEM_ASN1_read 367
362PEM_ASN1_read_bio 368
363PEM_ASN1_write 369
364PEM_ASN1_write_bio 370
365PEM_SealFinal 371
366PEM_SealInit 372
367PEM_SealUpdate 373
368PEM_SignFinal 374
369PEM_SignInit 375
370PEM_SignUpdate 376
371PEM_X509_INFO_read 377
372PEM_X509_INFO_read_bio 378
373PEM_X509_INFO_write_bio 379
374PEM_dek_info 380
375PEM_do_header 381
376PEM_get_EVP_CIPHER_INFO 382
377PEM_proc_type 383
378PEM_read 384
379PEM_read_DHparams 385
380PEM_read_DSAPrivateKey 386
381PEM_read_DSAparams 387
382PEM_read_PKCS7 388
383PEM_read_PrivateKey 389
384PEM_read_RSAPrivateKey 390
385PEM_read_X509 391
386PEM_read_X509_CRL 392
387PEM_read_X509_REQ 393
388PEM_read_bio 394
389PEM_read_bio_DHparams 395
390PEM_read_bio_DSAPrivateKey 396
391PEM_read_bio_DSAparams 397
392PEM_read_bio_PKCS7 398
393PEM_read_bio_PrivateKey 399
394PEM_read_bio_RSAPrivateKey 400
395PEM_read_bio_X509 401
396PEM_read_bio_X509_CRL 402
397PEM_read_bio_X509_REQ 403
398PEM_write 404
399PEM_write_DHparams 405
400PEM_write_DSAPrivateKey 406
401PEM_write_DSAparams 407
402PEM_write_PKCS7 408
403PEM_write_PrivateKey 409
404PEM_write_RSAPrivateKey 410
405PEM_write_X509 411
406PEM_write_X509_CRL 412
407PEM_write_X509_REQ 413
408PEM_write_bio 414
409PEM_write_bio_DHparams 415
410PEM_write_bio_DSAPrivateKey 416
411PEM_write_bio_DSAparams 417
412PEM_write_bio_PKCS7 418
413PEM_write_bio_PrivateKey 419
414PEM_write_bio_RSAPrivateKey 420
415PEM_write_bio_X509 421
416PEM_write_bio_X509_CRL 422
417PEM_write_bio_X509_REQ 423
418PKCS7_DIGEST_free 424
419PKCS7_DIGEST_new 425
420PKCS7_ENCRYPT_free 426
421PKCS7_ENCRYPT_new 427
422PKCS7_ENC_CONTENT_free 428
423PKCS7_ENC_CONTENT_new 429
424PKCS7_ENVELOPE_free 430
425PKCS7_ENVELOPE_new 431
426PKCS7_ISSUER_AND_SERIAL_digest 432
427PKCS7_ISSUER_AND_SERIAL_free 433
428PKCS7_ISSUER_AND_SERIAL_new 434
429PKCS7_RECIP_INFO_free 435
430PKCS7_RECIP_INFO_new 436
431PKCS7_SIGNED_free 437
432PKCS7_SIGNED_new 438
433PKCS7_SIGNER_INFO_free 439
434PKCS7_SIGNER_INFO_new 440
435PKCS7_SIGN_ENVELOPE_free 441
436PKCS7_SIGN_ENVELOPE_new 442
437PKCS7_dup 443
438PKCS7_free 444
439PKCS7_new 445
440PROXY_ENTRY_add_noproxy 446
441PROXY_ENTRY_clear_noproxy 447
442PROXY_ENTRY_free 448
443PROXY_ENTRY_get_noproxy 449
444PROXY_ENTRY_new 450
445PROXY_ENTRY_set_server 451
446PROXY_add_noproxy 452
447PROXY_add_server 453
448PROXY_check_by_host 454
449PROXY_check_url 455
450PROXY_clear_noproxy 456
451PROXY_free 457
452PROXY_get_noproxy 458
453PROXY_get_proxies 459
454PROXY_get_proxy_entry 460
455PROXY_load_conf 461
456PROXY_new 462
457PROXY_print 463
458RAND_bytes 464
459RAND_cleanup 465
460RAND_file_name 466
461RAND_load_file 467
462RAND_screen 468
463RAND_seed 469
464RAND_write_file 470
465RC2_cbc_encrypt 471
466RC2_cfb64_encrypt 472
467RC2_ecb_encrypt 473
468RC2_encrypt 474
469RC2_ofb64_encrypt 475
470RC2_set_key 476
471RC4 477
472RC4_options 478
473RC4_set_key 479
474RSAPrivateKey_asn1_meth 480
475RSAPrivateKey_dup 481
476RSAPublicKey_dup 482
477RSA_PKCS1_SSLeay 483
478RSA_free 484
479RSA_generate_key 485
480RSA_new 486
481RSA_new_method 487
482RSA_print 488
483RSA_print_fp 489
484RSA_private_decrypt 490
485RSA_private_encrypt 491
486RSA_public_decrypt 492
487RSA_public_encrypt 493
488RSA_set_default_method 494
489RSA_sign 495
490RSA_sign_ASN1_OCTET_STRING 496
491RSA_size 497
492RSA_verify 498
493RSA_verify_ASN1_OCTET_STRING 499
494SHA 500
495SHA1 501
496SHA1_Final 502
497SHA1_Init 503
498SHA1_Update 504
499SHA_Final 505
500SHA_Init 506
501SHA_Update 507
502SSLeay_add_all_algorithms 508
503SSLeay_add_all_ciphers 509
504SSLeay_add_all_digests 510
505TXT_DB_create_index 511
506TXT_DB_free 512
507TXT_DB_get_by_index 513
508TXT_DB_insert 514
509TXT_DB_read 515
510TXT_DB_write 516
511X509_ALGOR_free 517
512X509_ALGOR_new 518
513X509_ATTRIBUTE_free 519
514X509_ATTRIBUTE_new 520
515X509_CINF_free 521
516X509_CINF_new 522
517X509_CRL_INFO_free 523
518X509_CRL_INFO_new 524
519X509_CRL_add_ext 525
520X509_CRL_cmp 526
521X509_CRL_delete_ext 527
522X509_CRL_dup 528
523X509_CRL_free 529
524X509_CRL_get_ext 530
525X509_CRL_get_ext_by_NID 531
526X509_CRL_get_ext_by_OBJ 532
527X509_CRL_get_ext_by_critical 533
528X509_CRL_get_ext_count 534
529X509_CRL_new 535
530X509_CRL_sign 536
531X509_CRL_verify 537
532X509_EXTENSION_create_by_NID 538
533X509_EXTENSION_create_by_OBJ 539
534X509_EXTENSION_dup 540
535X509_EXTENSION_free 541
536X509_EXTENSION_get_critical 542
537X509_EXTENSION_get_data 543
538X509_EXTENSION_get_object 544
539X509_EXTENSION_new 545
540X509_EXTENSION_set_critical 546
541X509_EXTENSION_set_data 547
542X509_EXTENSION_set_object 548
543X509_INFO_free 549
544X509_INFO_new 550
545X509_LOOKUP_by_alias 551
546X509_LOOKUP_by_fingerprint 552
547X509_LOOKUP_by_issuer_serial 553
548X509_LOOKUP_by_subject 554
549X509_LOOKUP_ctrl 555
550X509_LOOKUP_file 556
551X509_LOOKUP_free 557
552X509_LOOKUP_hash_dir 558
553X509_LOOKUP_init 559
554X509_LOOKUP_new 560
555X509_LOOKUP_shutdown 561
556X509_NAME_ENTRY_create_by_NID 562
557X509_NAME_ENTRY_create_by_OBJ 563
558X509_NAME_ENTRY_dup 564
559X509_NAME_ENTRY_free 565
560X509_NAME_ENTRY_get_data 566
561X509_NAME_ENTRY_get_object 567
562X509_NAME_ENTRY_new 568
563X509_NAME_ENTRY_set_data 569
564X509_NAME_ENTRY_set_object 570
565X509_NAME_add_entry 571
566X509_NAME_cmp 572
567X509_NAME_delete_entry 573
568X509_NAME_digest 574
569X509_NAME_dup 575
570X509_NAME_entry_count 576
571X509_NAME_free 577
572X509_NAME_get_entry 578
573X509_NAME_get_index_by_NID 579
574X509_NAME_get_index_by_OBJ 580
575X509_NAME_get_text_by_NID 581
576X509_NAME_get_text_by_OBJ 582
577X509_NAME_hash 583
578X509_NAME_new 584
579X509_NAME_oneline 585
580X509_NAME_print 586
581X509_NAME_set 587
582X509_OBJECT_free_contents 588
583X509_OBJECT_retrive_by_subject 589
584X509_OBJECT_up_ref_count 590
585X509_PKEY_free 591
586X509_PKEY_new 592
587X509_PUBKEY_free 593
588X509_PUBKEY_get 594
589X509_PUBKEY_new 595
590X509_PUBKEY_set 596
591X509_REQ_INFO_free 597
592X509_REQ_INFO_new 598
593X509_REQ_dup 599
594X509_REQ_free 600
595X509_REQ_get_pubkey 601
596X509_REQ_new 602
597X509_REQ_print 603
598X509_REQ_print_fp 604
599X509_REQ_set_pubkey 605
600X509_REQ_set_subject_name 606
601X509_REQ_set_version 607
602X509_REQ_sign 608
603X509_REQ_to_X509 609
604X509_REQ_verify 610
605X509_REVOKED_add_ext 611
606X509_REVOKED_delete_ext 612
607X509_REVOKED_free 613
608X509_REVOKED_get_ext 614
609X509_REVOKED_get_ext_by_NID 615
610X509_REVOKED_get_ext_by_OBJ 616
611X509_REVOKED_get_ext_by_critical 617
612X509_REVOKED_get_ext_count 618
613X509_REVOKED_new 619
614X509_SIG_free 620
615X509_SIG_new 621
616X509_STORE_CTX_cleanup 622
617X509_STORE_CTX_init 623
618X509_STORE_add_cert 624
619X509_STORE_add_lookup 625
620X509_STORE_free 626
621X509_STORE_get_by_subject 627
622X509_STORE_load_locations 628
623X509_STORE_new 629
624X509_STORE_set_default_paths 630
625X509_VAL_free 631
626X509_VAL_new 632
627X509_add_ext 633
628X509_asn1_meth 634
629X509_certificate_type 635
630X509_check_private_key 636
631X509_cmp_current_time 637
632X509_delete_ext 638
633X509_digest 639
634X509_dup 640
635X509_free 641
636X509_get_default_cert_area 642
637X509_get_default_cert_dir 643
638X509_get_default_cert_dir_env 644
639X509_get_default_cert_file 645
640X509_get_default_cert_file_env 646
641X509_get_default_private_dir 647
642X509_get_ext 648
643X509_get_ext_by_NID 649
644X509_get_ext_by_OBJ 650
645X509_get_ext_by_critical 651
646X509_get_ext_count 652
647X509_get_issuer_name 653
648X509_get_pubkey 654
649X509_get_pubkey_parameters 655
650X509_get_serialNumber 656
651X509_get_subject_name 657
652X509_gmtime_adj 658
653X509_issuer_and_serial_cmp 659
654X509_issuer_and_serial_hash 660
655X509_issuer_name_cmp 661
656X509_issuer_name_hash 662
657X509_load_cert_file 663
658X509_new 664
659X509_print 665
660X509_print_fp 666
661X509_set_issuer_name 667
662X509_set_notAfter 668
663X509_set_notBefore 669
664X509_set_pubkey 670
665X509_set_serialNumber 671
666X509_set_subject_name 672
667X509_set_version 673
668X509_sign 674
669X509_subject_name_cmp 675
670X509_subject_name_hash 676
671X509_to_X509_REQ 677
672X509_verify 678
673X509_verify_cert 679
674X509_verify_cert_error_string 680
675X509v3_add_ext 681
676X509v3_add_extension 682
677X509v3_add_netscape_extensions 683
678X509v3_add_standard_extensions 684
679X509v3_cleanup_extensions 685
680X509v3_data_type_by_NID 686
681X509v3_data_type_by_OBJ 687
682X509v3_delete_ext 688
683X509v3_get_ext 689
684X509v3_get_ext_by_NID 690
685X509v3_get_ext_by_OBJ 691
686X509v3_get_ext_by_critical 692
687X509v3_get_ext_count 693
688X509v3_pack_string 694
689X509v3_pack_type_by_NID 695
690X509v3_pack_type_by_OBJ 696
691X509v3_unpack_string 697
692_des_crypt 698
693a2d_ASN1_OBJECT 699
694a2i_ASN1_INTEGER 700
695a2i_ASN1_STRING 701
696asn1_Finish 702
697asn1_GetSequence 703
698bn_div64 704
699bn_expand2 705
700bn_mul_add_words 706
701bn_mul_words 707
702bn_qadd 708
703bn_qsub 709
704bn_sqr_words 710
705crypt 711
706d2i_ASN1_BIT_STRING 712
707d2i_ASN1_BOOLEAN 713
708d2i_ASN1_HEADER 714
709d2i_ASN1_IA5STRING 715
710d2i_ASN1_INTEGER 716
711d2i_ASN1_OBJECT 717
712d2i_ASN1_OCTET_STRING 718
713d2i_ASN1_PRINTABLE 719
714d2i_ASN1_PRINTABLESTRING 720
715d2i_ASN1_SET 721
716d2i_ASN1_T61STRING 722
717d2i_ASN1_TYPE 723
718d2i_ASN1_UTCTIME 724
719d2i_ASN1_bytes 725
720d2i_ASN1_type_bytes 726
721d2i_DHparams 727
722d2i_DSAPrivateKey 728
723d2i_DSAPrivateKey_bio 729
724d2i_DSAPrivateKey_fp 730
725d2i_DSAPublicKey 731
726d2i_DSAparams 732
727d2i_NETSCAPE_SPKAC 733
728d2i_NETSCAPE_SPKI 734
729d2i_Netscape_RSA 735
730d2i_PKCS7 736
731d2i_PKCS7_DIGEST 737
732d2i_PKCS7_ENCRYPT 738
733d2i_PKCS7_ENC_CONTENT 739
734d2i_PKCS7_ENVELOPE 740
735d2i_PKCS7_ISSUER_AND_SERIAL 741
736d2i_PKCS7_RECIP_INFO 742
737d2i_PKCS7_SIGNED 743
738d2i_PKCS7_SIGNER_INFO 744
739d2i_PKCS7_SIGN_ENVELOPE 745
740d2i_PKCS7_bio 746
741d2i_PKCS7_fp 747
742d2i_PrivateKey 748
743d2i_PublicKey 749
744d2i_RSAPrivateKey 750
745d2i_RSAPrivateKey_bio 751
746d2i_RSAPrivateKey_fp 752
747d2i_RSAPublicKey 753
748d2i_X509 754
749d2i_X509_ALGOR 755
750d2i_X509_ATTRIBUTE 756
751d2i_X509_CINF 757
752d2i_X509_CRL 758
753d2i_X509_CRL_INFO 759
754d2i_X509_CRL_bio 760
755d2i_X509_CRL_fp 761
756d2i_X509_EXTENSION 762
757d2i_X509_NAME 763
758d2i_X509_NAME_ENTRY 764
759d2i_X509_PKEY 765
760d2i_X509_PUBKEY 766
761d2i_X509_REQ 767
762d2i_X509_REQ_INFO 768
763d2i_X509_REQ_bio 769
764d2i_X509_REQ_fp 770
765d2i_X509_REVOKED 771
766d2i_X509_SIG 772
767d2i_X509_VAL 773
768d2i_X509_bio 774
769d2i_X509_fp 775
770des_cbc_cksum 777
771des_cbc_encrypt 778
772des_cblock_print_file 779
773des_cfb64_encrypt 780
774des_cfb_encrypt 781
775des_decrypt3 782
776des_ecb3_encrypt 783
777des_ecb_encrypt 784
778des_ede3_cbc_encrypt 785
779des_ede3_cfb64_encrypt 786
780des_ede3_ofb64_encrypt 787
781des_enc_read 788
782des_enc_write 789
783des_encrypt 790
784des_encrypt2 791
785des_encrypt3 792
786des_fcrypt 793
787des_is_weak_key 794
788des_key_sched 795
789des_ncbc_encrypt 796
790des_ofb64_encrypt 797
791des_ofb_encrypt 798
792des_options 799
793des_pcbc_encrypt 800
794des_quad_cksum 801
795des_random_key 802
796des_random_seed 803
797des_read_2passwords 804
798des_read_password 805
799des_read_pw 806
800des_read_pw_string 807
801des_set_key 808
802des_set_odd_parity 809
803des_string_to_2keys 810
804des_string_to_key 811
805des_xcbc_encrypt 812
806des_xwhite_in2out 813
807fcrypt_body 814
808i2a_ASN1_INTEGER 815
809i2a_ASN1_OBJECT 816
810i2a_ASN1_STRING 817
811i2d_ASN1_BIT_STRING 818
812i2d_ASN1_BOOLEAN 819
813i2d_ASN1_HEADER 820
814i2d_ASN1_IA5STRING 821
815i2d_ASN1_INTEGER 822
816i2d_ASN1_OBJECT 823
817i2d_ASN1_OCTET_STRING 824
818i2d_ASN1_PRINTABLE 825
819i2d_ASN1_SET 826
820i2d_ASN1_TYPE 827
821i2d_ASN1_UTCTIME 828
822i2d_ASN1_bytes 829
823i2d_DHparams 830
824i2d_DSAPrivateKey 831
825i2d_DSAPrivateKey_bio 832
826i2d_DSAPrivateKey_fp 833
827i2d_DSAPublicKey 834
828i2d_DSAparams 835
829i2d_NETSCAPE_SPKAC 836
830i2d_NETSCAPE_SPKI 837
831i2d_Netscape_RSA 838
832i2d_PKCS7 839
833i2d_PKCS7_DIGEST 840
834i2d_PKCS7_ENCRYPT 841
835i2d_PKCS7_ENC_CONTENT 842
836i2d_PKCS7_ENVELOPE 843
837i2d_PKCS7_ISSUER_AND_SERIAL 844
838i2d_PKCS7_RECIP_INFO 845
839i2d_PKCS7_SIGNED 846
840i2d_PKCS7_SIGNER_INFO 847
841i2d_PKCS7_SIGN_ENVELOPE 848
842i2d_PKCS7_bio 849
843i2d_PKCS7_fp 850
844i2d_PrivateKey 851
845i2d_PublicKey 852
846i2d_RSAPrivateKey 853
847i2d_RSAPrivateKey_bio 854
848i2d_RSAPrivateKey_fp 855
849i2d_RSAPublicKey 856
850i2d_X509 857
851i2d_X509_ALGOR 858
852i2d_X509_ATTRIBUTE 859
853i2d_X509_CINF 860
854i2d_X509_CRL 861
855i2d_X509_CRL_INFO 862
856i2d_X509_CRL_bio 863
857i2d_X509_CRL_fp 864
858i2d_X509_EXTENSION 865
859i2d_X509_NAME 866
860i2d_X509_NAME_ENTRY 867
861i2d_X509_PKEY 868
862i2d_X509_PUBKEY 869
863i2d_X509_REQ 870
864i2d_X509_REQ_INFO 871
865i2d_X509_REQ_bio 872
866i2d_X509_REQ_fp 873
867i2d_X509_REVOKED 874
868i2d_X509_SIG 875
869i2d_X509_VAL 876
870i2d_X509_bio 877
871i2d_X509_fp 878
872idea_cbc_encrypt 879
873idea_cfb64_encrypt 880
874idea_ecb_encrypt 881
875idea_encrypt 882
876idea_ofb64_encrypt 883
877idea_options 884
878idea_set_decrypt_key 885
879idea_set_encrypt_key 886
880lh_delete 887
881lh_doall 888
882lh_doall_arg 889
883lh_free 890
884lh_insert 891
885lh_new 892
886lh_node_stats 893
887lh_node_stats_bio 894
888lh_node_usage_stats 895
889lh_node_usage_stats_bio 896
890lh_retrieve 897
891lh_stats 898
892lh_stats_bio 899
893lh_strhash 900
894sk_delete 901
895sk_delete_ptr 902
896sk_dup 903
897sk_find 904
898sk_free 905
899sk_insert 906
900sk_new 907
901sk_pop 908
902sk_pop_free 909
903sk_push 910
904sk_set_cmp_func 911
905sk_shift 912
906sk_unshift 913
907sk_zero 914
908BIO_f_nbio_test 915
909ASN1_TYPE_get 916
910ASN1_TYPE_set 917
911PKCS7_content_free 918
912ERR_load_PKCS7_strings 919
913X509_find_by_issuer_and_serial 920
914X509_find_by_subject 921
915PKCS7_ctrl 927
916PKCS7_set_type 928
917PKCS7_set_content 929
918PKCS7_SIGNER_INFO_set 930
919PKCS7_add_signer 931
920PKCS7_add_certificate 932
921PKCS7_add_crl 933
922PKCS7_content_new 934
923PKCS7_dataSign 935
924PKCS7_dataVerify 936
925PKCS7_dataInit 937
926PKCS7_add_signature 938
927PKCS7_cert_from_signer_info 939
928PKCS7_get_signer_info 940
929EVP_delete_alias 941
930EVP_mdc2 942
931PEM_read_bio_RSAPublicKey 943
932PEM_write_bio_RSAPublicKey 944
933d2i_RSAPublicKey_bio 945
934i2d_RSAPublicKey_bio 946
935PEM_read_RSAPublicKey 947
936PEM_write_RSAPublicKey 949
937d2i_RSAPublicKey_fp 952
938i2d_RSAPublicKey_fp 954
939BIO_copy_next_retry 955
940RSA_flags 956
941X509_STORE_add_crl 957
942X509_load_crl_file 958
943EVP_rc2_40_cbc 959
944EVP_rc4_40 960
945EVP_CIPHER_CTX_init 961
946HMAC 962
947HMAC_Init 963
948HMAC_Update 964
949HMAC_Final 965
950ERR_get_next_error_library 966
951EVP_PKEY_cmp_parameters 967
952HMAC_cleanup 968
953BIO_ptr_ctrl 969
954BIO_new_file_internal 970
955BIO_new_fp_internal 971
956BIO_s_file_internal 972
957BN_BLINDING_convert 973
958BN_BLINDING_invert 974
959BN_BLINDING_update 975
960RSA_blinding_on 977
961RSA_blinding_off 978
962i2t_ASN1_OBJECT 979
963BN_BLINDING_new 980
964BN_BLINDING_free 981
965EVP_cast5_cbc 983
966EVP_cast5_cfb 984
967EVP_cast5_ecb 985
968EVP_cast5_ofb 986
969BF_decrypt 987
970CAST_set_key 988
971CAST_encrypt 989
972CAST_decrypt 990
973CAST_ecb_encrypt 991
974CAST_cbc_encrypt 992
975CAST_cfb64_encrypt 993
976CAST_ofb64_encrypt 994
977RC2_decrypt 995
978OBJ_create_objects 997
979BN_exp 998
980BN_mul_word 999
981BN_sub_word 1000
982BN_dec2bn 1001
983BN_bn2dec 1002
984BIO_ghbn_ctrl 1003
985CRYPTO_free_ex_data 1004
986CRYPTO_get_ex_data 1005
987CRYPTO_set_ex_data 1007
988ERR_load_CRYPTO_strings 1009
989ERR_load_CRYPTOlib_strings 1009
990EVP_PKEY_bits 1010
991MD5_Transform 1011
992SHA1_Transform 1012
993SHA_Transform 1013
994X509_STORE_CTX_get_chain 1014
995X509_STORE_CTX_get_current_cert 1015
996X509_STORE_CTX_get_error 1016
997X509_STORE_CTX_get_error_depth 1017
998X509_STORE_CTX_get_ex_data 1018
999X509_STORE_CTX_set_cert 1020
1000X509_STORE_CTX_set_chain 1021
1001X509_STORE_CTX_set_error 1022
1002X509_STORE_CTX_set_ex_data 1023
1003CRYPTO_dup_ex_data 1025
1004CRYPTO_get_new_lockid 1026
1005CRYPTO_new_ex_data 1027
1006RSA_set_ex_data 1028
1007RSA_get_ex_data 1029
1008RSA_get_ex_new_index 1030
1009RSA_padding_add_PKCS1_type_1 1031
1010RSA_padding_add_PKCS1_type_2 1032
1011RSA_padding_add_SSLv23 1033
1012RSA_padding_add_none 1034
1013RSA_padding_check_PKCS1_type_1 1035
1014RSA_padding_check_PKCS1_type_2 1036
1015RSA_padding_check_SSLv23 1037
1016RSA_padding_check_none 1038
1017bn_add_words 1039
1018d2i_Netscape_RSA_2 1040
1019CRYPTO_get_ex_new_index 1041
1020RIPEMD160_Init 1042
1021RIPEMD160_Update 1043
1022RIPEMD160_Final 1044
1023RIPEMD160 1045
1024RIPEMD160_Transform 1046
1025RC5_32_set_key 1047
1026RC5_32_ecb_encrypt 1048
1027RC5_32_encrypt 1049
1028RC5_32_decrypt 1050
1029RC5_32_cbc_encrypt 1051
1030RC5_32_cfb64_encrypt 1052
1031RC5_32_ofb64_encrypt 1053
1032BN_bn2mpi 1058
1033BN_mpi2bn 1059
1034ASN1_BIT_STRING_get_bit 1060
1035ASN1_BIT_STRING_set_bit 1061
1036BIO_get_ex_data 1062
1037BIO_get_ex_new_index 1063
1038BIO_set_ex_data 1064
1039X509_STORE_CTX_get_ex_new_index 1065
1040X509v3_get_key_usage 1066
1041X509v3_set_key_usage 1067
1042a2i_X509v3_key_usage 1068
1043i2a_X509v3_key_usage 1069
1044EVP_PKEY_decrypt 1070
1045EVP_PKEY_encrypt 1071
1046PKCS7_RECIP_INFO_set 1072
1047PKCS7_add_recipient 1073
1048PKCS7_add_recipient_info 1074
1049PKCS7_set_cipher 1075
1050ASN1_TYPE_get_int_octetstring 1076
1051ASN1_TYPE_get_octetstring 1077
1052ASN1_TYPE_set_int_octetstring 1078
1053ASN1_TYPE_set_octetstring 1079
1054ASN1_UTCTIME_set_string 1080
1055ERR_add_error_data 1081
1056ERR_set_error_data 1082
1057EVP_CIPHER_asn1_to_param 1083
1058EVP_CIPHER_param_to_asn1 1084
1059EVP_CIPHER_get_asn1_iv 1085
1060EVP_CIPHER_set_asn1_iv 1086
1061EVP_rc5_32_12_16_cbc 1087
1062EVP_rc5_32_12_16_cfb 1088
1063EVP_rc5_32_12_16_ecb 1089
1064EVP_rc5_32_12_16_ofb 1090
1065asn1_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="";
29foreach (@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";
77and [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
92Values that can be set
93TMP=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)
98EOF
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
128push(@INC,"util/pl","pl");
129if ($type eq "VC-MSDOS")
130 {
131 $asmbits=16;
132 $msdos=1;
133 require 'VC-16.pl';
134 }
135elsif ($type eq "VC-W31-16")
136 {
137 $asmbits=16;
138 $msdos=1; $win16=1;
139 require 'VC-16.pl';
140 }
141elsif (($type eq "VC-W31-32") || ($type eq "VC-WIN16"))
142 {
143 $asmbits=32;
144 $msdos=1; $win16=1;
145 require 'VC-16.pl';
146 }
147elsif (($type eq "VC-WIN32") || ($type eq "VC-NT"))
148 {
149 require 'VC-32.pl';
150 }
151elsif ($type eq "BC-NT")
152 {
153 $bc=1;
154 require 'BC-32.pl';
155 }
156elsif ($type eq "BC-W31")
157 {
158 $bc=1;
159 $msdos=1; $w16=1;
160 require 'BC-16.pl';
161 }
162elsif ($type eq "BC-Q16")
163 {
164 $msdos=1; $w16=1; $shlib=0; $qw=1;
165 require 'BC-16.pl';
166 }
167elsif ($type eq "BC-MSDOS")
168 {
169 $asmbits=16;
170 $msdos=1;
171 require 'BC-16.pl';
172 }
173elsif ($type eq "FreeBSD")
174 {
175 require 'unix.pl';
176 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
177 }
178elsif ($type eq "linux-elf")
179 {
180 require "unix.pl";
181 require "linux.pl";
182 $unix=1;
183 }
184else
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
220if ($unix)
221 { $cflags="$c_flags" if ($c_flags ne ""); }
222else { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
223
224$ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
225
226if ($ranlib ne "")
227 {
228 $ranlib="\$(SRC_D)$o$ranlib";
229 }
230
231if ($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
258INSTALLTOP=$INSTALLTOP
259
260# Set your compiler options
261CC=$bin_dir${cc}
262CFLAG=$cflags
263APP_CFLAG=$app_cflag
264LIB_CFLAG=$lib_cflag
265SHLIB_CFLAG=$shl_cflag
266APP_EX_OBJ=$app_ex_obj
267SHLIB_EX_OBJ=$shlib_ex_obj
268# add extra libraries to this define, for solaris -lsocket -lnsl would
269# be added
270EX_LIBS=$ex_libs
271
272# The SSLeay directory
273SRC_D=$src_dir
274
275LINK=$link
276LFLAGS=$lflags
277
278BN_MULW_OBJ=$bn_mulw_obj
279BN_MULW_SRC=$bn_mulw_src
280DES_ENC_OBJ=$des_enc_obj
281DES_ENC_SRC=$des_enc_src
282DES_CRYPT_OBJ=$des_crypt_obj
283DES_CRYPT_SRC=$des_crypt_src
284BF_ENC_OBJ=$bf_enc_obj
285BF_ENC_SRC=$bf_enc_src
286CAST_ENC_OBJ=$cast_enc_obj
287CAST_ENC_SRC=$cast_enc_src
288RC4_ENC_OBJ=$rc4_enc_obj
289RC4_ENC_SRC=$rc4_enc_src
290RC5_ENC_OBJ=$rc5_enc_obj
291RC5_ENC_SRC=$rc5_enc_src
292MD5_ASM_OBJ=$md5_asm_obj
293MD5_ASM_SRC=$md5_asm_src
294SHA1_ASM_OBJ=$sha1_asm_obj
295SHA1_ASM_SRC=$sha1_asm_src
296RMD160_ASM_OBJ=$rmd160_asm_obj
297RMD160_ASM_SRC=$rmd160_asm_src
298
299# The output directory for everything intersting
300OUT_D=$out_dir
301# The output directory for all the temporary muck
302TMP_D=$tmp_dir
303# The output directory for the header files
304INC_D=$inc_dir
305
306CP=$cp
307RM=$rm
308RANLIB=$ranlib
309MKDIR=mkdir
310MKLIB=$bin_dir$mklib
311MLFLAGS=$mlflags
312ASM=$bin_dir$asm
313
314######################################################
315# You should not need to touch anything below this point
316######################################################
317
318E_EXE=ssleay
319SSL=$ssl
320CRYPTO=$crypto
321RSAGLUE=$RSAglue
322
323# BIN_D - Binary output directory
324# TEST_D - Binary test file output directory
325# LIB_D - library output directory
326BIN_D=\$(OUT_D)
327TEST_D=\$(OUT_D)
328LIB_D=\$(OUT_D)
329
330# INCL_D - local library directory
331# OBJ_D - temp object file directory
332OBJ_D=\$(TMP_D)
333INCL_D=\$(TMP_D)
334
335O_SSL= \$(LIB_D)$o$plib\$(SSL)$shlibp
336O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
337O_RSAGLUE= \$(LIB_D)$o$plib\$(RSAGLUE)$libp
338SO_SSL= $plib\$(SSL)$so_shlibp
339SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
340L_SSL= \$(LIB_D)$o\$(SSL)$libp
341L_CRYPTO= \$(LIB_D)$o\$(CRYPTO)$libp
342
343L_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
350INC=-I\$(INC_D) -I\$(INCL_D)
351APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
352LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
353SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
354LIBS_DEP=\$(O_CRYPTO) \$(O_RSAGLUE) \$(O_SSL)
355
356#############################################
357EOF
358
359$rules=<<"EOF";
360all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INC_D) headers lib exe
361
362banner:
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
380headers: \$(HEADER) \$(EXHEADER)
381
382lib: \$(LIBS_DEP)
383
384exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
385
386install:
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
396clean:
397 \$(RM) \$(TMP_D)$o*.*
398
399vclean:
400 \$(RM) \$(TMP_D)$o*.*
401 \$(RM) \$(OUT_D)$o*.*
402
403EOF
404
405#############################################
406# We parse in input file and 'store' info for later printing.
407open(IN,"<$infile") || die "unable to open $infile:$!\n";
408$_=<IN>;
409for (;;)
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 }
454close(IN);
455
456# Strip of trailing ' '
457foreach (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
464foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
465foreach (split(/\s+/,$header)) { $h.=$_." " unless $h{$_}; }
466chop($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
480foreach (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);
551foreach (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
565print $defs;
566print "###################################################################\n";
567print $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
573sub 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
649sub clean_up_ws
650 {
651 local($w)=@_;
652
653 $w =~ s/^\s*(.*)\s*$/$1/;
654 $w =~ s/\s+/ /g;
655 return($w);
656 }
657
658sub 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
700sub 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
708sub 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
728sub 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
744sub 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##############################################################
759sub 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
778sub 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
14CAbits=1024
15SSLEAY="../apps/ssleay"
16CONF="-config ../apps/ssleay.cnf"
17
18# create pca request.
19echo 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
24AU
25Queensland
26.
27CryptSoft Pty Ltd
28.
29Test PCA (1024 bit)
30
31
32
33EOF
34
35if [ $? != 0 ]; then
36 echo problems generating PCA request
37 exit 1
38fi
39
40#sign it.
41echo
42echo 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
48if [ $? != 0 ]; then
49 echo problems self signing PCA cert
50 exit 1
51fi
52echo
53
54# create ca request.
55echo 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
60AU
61Queensland
62.
63CryptSoft Pty Ltd
64.
65Test CA (1024 bit)
66
67
68
69EOF
70
71if [ $? != 0 ]; then
72 echo problems generating CA request
73 exit 1
74fi
75
76#sign it.
77echo
78echo 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
85if [ $? != 0 ]; then
86 echo problems signing CA cert
87 exit 1
88fi
89echo
90
91# create server request.
92echo 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
97AU
98Queensland
99.
100CryptSoft Pty Ltd
101.
102Server test cert (512 bit)
103
104
105
106EOF
107
108if [ $? != 0 ]; then
109 echo problems generating 512 bit server cert request
110 exit 1
111fi
112
113#sign it.
114echo
115echo 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
122if [ $? != 0 ]; then
123 echo problems signing 512 bit server cert
124 exit 1
125fi
126echo
127
128# create 1024 bit server request.
129echo 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
134AU
135Queensland
136.
137CryptSoft Pty Ltd
138.
139Server test cert (1024 bit)
140
141
142
143EOF
144
145if [ $? != 0 ]; then
146 echo problems generating 1024 bit server cert request
147 exit 1
148fi
149
150#sign it.
151echo
152echo 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
159if [ $? != 0 ]; then
160 echo problems signing 1024 bit server cert
161 exit 1
162fi
163echo
164
165# create 512 bit client request.
166echo 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
171AU
172Queensland
173.
174CryptSoft Pty Ltd
175.
176Client test cert (512 bit)
177
178
179
180EOF
181
182if [ $? != 0 ]; then
183 echo problems generating 512 bit client cert request
184 exit 1
185fi
186
187#sign it.
188echo
189echo 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
196if [ $? != 0 ]; then
197 echo problems signing 512 bit client cert
198 exit 1
199fi
200
201echo cleanup
202
203cat pca-key.pem >> pca-cert.pem
204cat ca-key.pem >> ca-cert.pem
205cat s512-key.pem >> server.pem
206cat s1024key.pem >> server2.pem
207cat c512-key.pem >> client.pem
208
209for i in pca-cert.pem ca-cert.pem server.pem server2.pem client.pem
210do
211$SSLEAY x509 -issuer -subject -in $i -noout >$$
212cat $$
213/bin/cat $i >>$$
214/bin/mv $$ $i
215done
216
217#/bin/rm -f *key.pem *req.pem *.srl
218
219echo 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;
13foreach (@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
21if (!$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
80sub 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
171sub 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
210sub do_extern
211 {
212 local($file,$_)=@_;
213 local($n);
214
215 /\s\**(\S+);$/;
216 return($1);
217 }
218
219sub 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
234LIBRARY $name
235
236DESCRIPTION 'SSLeay $name - eay\@cryptsoft.com'
237
238EOF
239
240 if (!$NT)
241 {
242 print <<"EOF";
243CODE PRELOAD MOVEABLE
244DATA PRELOAD MOVEABLE SINGLE
245
246EXETYPE WINDOWS
247
248HEAPSIZE 4096
249STACKSIZE 8192
250
251EOF
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
276sub 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
7require "find.pl";
8
9$#ARGV == 0 || print STDERR "usage: perlpath newpath (eg /usr/bin)\n";
10&find(".");
11
12sub 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
12if ($debug)
13 { $op="-v "; }
14else { $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
21if ($win16)
22 {
23 $shlib=1;
24 $cflags.=" -DWINDOWS -DWIN16";
25 $app_cflag="-W";
26 $lib_cflag="-WD";
27 $lflags.="/Twe";
28 }
29else
30 {
31 $cflags.=" -DMSDOS";
32 $lflags.=" /Tde";
33 }
34
35if ($shlib)
36 {
37 $mlflags=" /Twd $base_lflags"; # stack if defined in .def file
38 $libs="libw ldllcew";
39 $no_asm=1;
40 }
41else
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';
67if ($no_asm)
68 {
69 $bn_mulw_obj='';
70 $bn_mulw_src='';
71 }
72elsif ($asmbits == 32)
73 {
74 $bn_mulw_obj='crypto\bn\asm\x86w32.obj';
75 $bn_mulw_src='crypto\bn\asm\x86w32.asm';
76 }
77else
78 {
79 $bn_mulw_obj='crypto\bn\asm\x86w16.obj';
80 $bn_mulw_src='crypto\bn\asm\x86w16.asm';
81 }
82
83sub 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
120sub 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
1461;
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
12if ($debug)
13 { $op="-v "; }
14else { $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
26if ($shlib)
27 {
28 $mlflags="$base_lflags -Tpe"; # stack if defined in .def file
29 $libs="libw ldllcew";
30 }
31else
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';
56if ($noasm)
57 {
58 $bn_mulw_obj='';
59 $bn_mulw_src='';
60 }
61else
62 {
63 $bn_mulw_obj='crypto\bn\asm\x86b32.obj';
64 $bn_mulw_src='crypto\bn\asm\x86m32.asm';
65 }
66
67sub 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
105sub 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
1351;
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
20if ($debug)
21 {
22 $op="/Od /Zi /Zd";
23 $base_lflags="/CO";
24 }
25else {
26 $op="/G2 /f- /Ocgnotb2";
27 }
28$base_lflags.=" /FARCALL /NOLOGO /NOD /SEG:1024 /ONERROR:NOEXE /NOE /PACKC:60000";
29if ($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
35if ($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 }
45else
46 {
47 $no_sock=1;
48 $cflags.=" -DMSDOS";
49 $lflags.=" /EXEPACK";
50 $ex_libs.="oldnames.lib llibce.lib";
51 }
52
53if ($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 }
62else
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
94if (!$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
108sub 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
149sub 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
1731;
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
23if ($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';
37if ($no_sock)
38 { $ex_libs=""; }
39else { $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
63if (!$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
86if ($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
95sub 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
120sub 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
1331;
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';
13if ($debug)
14 { $cflags="-g2 -ggdb -DREF_CHECK -DCRYPTO_MDEBUG"; }
15else
16 { $cflags="-O3 -fomit-frame-pointer"; }
17
18if (!$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
39if ($shlib)
40 {
41 $shl_cflag=" -DPIC -fpic";
42 $shlibp=".so.$ssl_version";
43 $so_shlibp=".so";
44 }
45
46sub 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
65sub 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
77sub 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
961;
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
12if ($gcc)
13 {
14 $cc='gcc';
15 if ($debug)
16 { $cflags="-g2 -ggdb"; }
17 else
18 { $cflags="-O3 -fomit-frame-pointer"; }
19 }
20else
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
56sub 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
71sub 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
831;
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
4ln -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;
14foreach $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
32foreach $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
45sub 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
14make clean
15perl Configure b
16make
17apps/ssleay version -v -b -f >speed.1
18apps/ssleay speed >speed.1l
19
20perl Configure bl-4c-2c
21/bin/rm -f crypto/rc4/*.o crypto/bn/bn*.o crypto/md2/md2_dgst.o
22make
23apps/ssleay speed rc4 rsa md2 >speed.2l
24
25perl Configure bl-4c-ri
26/bin/rm -f crypto/rc4/rc4*.o
27make
28apps/ssleay speed rc4 >speed.3l
29
30perl 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
32apps/ssleay speed rsa rc4 idea des >speed.4l
33
34cat speed.1 >speed.log
35cat speed.1l >>speed.log
36perl util/sp-diff.pl speed.1l speed.2l >>speed.log
37perl util/sp-diff.pl speed.1l speed.3l >>speed.log
38perl 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
10foreach (@ARGV)
11 {
12 &$nm_func($_);
13 }
14
15foreach $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
29foreach $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
43sub 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
67sub 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
107sub 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 @@
1ERR_load_SSL_strings 1
2SSL_CIPHER_description 2
3SSL_CTX_add_client_CA 3
4SSL_CTX_add_session 4
5SSL_CTX_check_private_key 5
6SSL_CTX_ctrl 6
7SSL_CTX_flush_sessions 7
8SSL_CTX_free 8
9SSL_CTX_get_client_CA_list 9
10SSL_CTX_get_verify_callback 10
11SSL_CTX_get_verify_mode 11
12SSL_CTX_new 12
13SSL_CTX_remove_session 13
14SSL_CTX_set_cert_verify_cb 14
15SSL_CTX_set_cipher_list 15
16SSL_CTX_set_client_CA_list 16
17SSL_CTX_set_default_passwd_cb 17
18SSL_CTX_set_ssl_version 19
19SSL_CTX_set_verify 21
20SSL_CTX_use_PrivateKey 22
21SSL_CTX_use_PrivateKey_ASN1 23
22SSL_CTX_use_PrivateKey_file 24
23SSL_CTX_use_RSAPrivateKey 25
24SSL_CTX_use_RSAPrivateKey_ASN1 26
25SSL_CTX_use_RSAPrivateKey_file 27
26SSL_CTX_use_certificate 28
27SSL_CTX_use_certificate_ASN1 29
28SSL_CTX_use_certificate_file 30
29SSL_SESSION_free 31
30SSL_SESSION_new 32
31SSL_SESSION_print 33
32SSL_SESSION_print_fp 34
33SSL_accept 35
34SSL_add_client_CA 36
35SSL_alert_desc_string 37
36SSL_alert_desc_string_long 38
37SSL_alert_type_string 39
38SSL_alert_type_string_long 40
39SSL_check_private_key 41
40SSL_clear 42
41SSL_connect 43
42SSL_copy_session_id 44
43SSL_ctrl 45
44SSL_dup 46
45SSL_dup_CA_list 47
46SSL_free 48
47SSL_get_certificate 49
48SSL_get_cipher_list 52
49SSL_get_ciphers 55
50SSL_get_client_CA_list 56
51SSL_get_default_timeout 57
52SSL_get_error 58
53SSL_get_fd 59
54SSL_get_peer_cert_chain 60
55SSL_get_peer_certificate 61
56SSL_get_rbio 63
57SSL_get_read_ahead 64
58SSL_get_shared_ciphers 65
59SSL_get_ssl_method 66
60SSL_get_verify_callback 69
61SSL_get_verify_mode 70
62SSL_get_version 71
63SSL_get_wbio 72
64SSL_load_client_CA_file 73
65SSL_load_error_strings 74
66SSL_new 75
67SSL_peek 76
68SSL_pending 77
69SSL_read 78
70SSL_renegotiate 79
71SSL_rstate_string 80
72SSL_rstate_string_long 81
73SSL_set_accept_state 82
74SSL_set_bio 83
75SSL_set_cipher_list 84
76SSL_set_client_CA_list 85
77SSL_set_connect_state 86
78SSL_set_fd 87
79SSL_set_read_ahead 88
80SSL_set_rfd 89
81SSL_set_session 90
82SSL_set_ssl_method 91
83SSL_set_verify 94
84SSL_set_wfd 95
85SSL_shutdown 96
86SSL_state_string 97
87SSL_state_string_long 98
88SSL_use_PrivateKey 99
89SSL_use_PrivateKey_ASN1 100
90SSL_use_PrivateKey_file 101
91SSL_use_RSAPrivateKey 102
92SSL_use_RSAPrivateKey_ASN1 103
93SSL_use_RSAPrivateKey_file 104
94SSL_use_certificate 105
95SSL_use_certificate_ASN1 106
96SSL_use_certificate_file 107
97SSL_write 108
98SSLeay_add_ssl_algorithms 109
99SSLv23_client_method 110
100SSLv23_method 111
101SSLv23_server_method 112
102SSLv2_client_method 113
103SSLv2_method 114
104SSLv2_server_method 115
105SSLv3_client_method 116
106SSLv3_method 117
107SSLv3_server_method 118
108d2i_SSL_SESSION 119
109i2d_SSL_SESSION 120
110BIO_f_ssl 121
111BIO_new_ssl 122
112BIO_proxy_ssl_copy_session_id 123
113BIO_ssl_copy_session_id 124
114SSL_do_handshake 125
115SSL_get_privatekey 126
116SSL_get_current_cipher 127
117SSL_CIPHER_get_bits 128
118SSL_CIPHER_get_version 129
119SSL_CIPHER_get_name 130
120BIO_ssl_shutdown 131
121SSL_SESSION_cmp 132
122SSL_SESSION_hash 133
123SSL_SESSION_get_time 134
124SSL_SESSION_set_time 135
125SSL_SESSION_get_timeout 136
126SSL_SESSION_set_timeout 137
127SSL_CTX_get_ex_data 138
128SSL_CTX_get_quiet_shutdown 140
129SSL_CTX_load_verify_locations 141
130SSL_CTX_set_default_verify_paths 142
131SSL_CTX_set_ex_data 143
132SSL_CTX_set_quiet_shutdown 145
133SSL_SESSION_get_ex_data 146
134SSL_SESSION_set_ex_data 148
135SSL_get_SSL_CTX 150
136SSL_get_ex_data 151
137SSL_get_quiet_shutdown 153
138SSL_get_session 154
139SSL_get_shutdown 155
140SSL_get_verify_result 157
141SSL_set_ex_data 158
142SSL_set_info_callback 160
143SSL_set_quiet_shutdown 161
144SSL_set_shutdown 162
145SSL_set_verify_result 163
146SSL_version 164
147SSL_get_info_callback 165
148SSL_state 166
149SSL_CTX_get_ex_new_index 167
150SSL_SESSION_get_ex_new_index 168
151SSL_get_ex_new_index 169
152TLSv1_method 170
153TLSv1_server_method 171
154TLSv1_client_method 172
155BIO_new_buffer_ssl_connect 173
156BIO_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
6while (<>)
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
3echo Generating x86 assember
4echo 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
8echo 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
12echo "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
16echo 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
20echo 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
24echo 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
28echo 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
32echo 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
36echo 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
40echo 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)