summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/des')
-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/FILES096
-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/Makefile314
-rw-r--r--src/lib/libcrypto/des/Makefile.ssl316
-rw-r--r--src/lib/libcrypto/des/README54
-rw-r--r--src/lib/libcrypto/des/VERSION412
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl12
-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-lib.com1003
-rw-r--r--src/lib/libcrypto/des/des.c932
-rw-r--r--src/lib/libcrypto/des/des.h6
-rw-r--r--src/lib/libcrypto/des/des.pod217
-rw-r--r--src/lib/libcrypto/des/des3s.cpp67
-rw-r--r--src/lib/libcrypto/des/des_enc.c2
-rw-r--r--src/lib/libcrypto/des/des_locl.h2
-rw-r--r--src/lib/libcrypto/des/des_old.c271
-rw-r--r--src/lib/libcrypto/des/des_old.h441
-rw-r--r--src/lib/libcrypto/des/des_old2.c82
-rw-r--r--src/lib/libcrypto/des/des_opts.c604
-rw-r--r--src/lib/libcrypto/des/des_ver.h71
-rw-r--r--src/lib/libcrypto/des/dess.cpp67
-rw-r--r--src/lib/libcrypto/des/destest.c948
-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.c139
-rw-r--r--src/lib/libcrypto/des/read_pwd.c521
-rw-r--r--src/lib/libcrypto/des/rpc_des.h131
-rw-r--r--src/lib/libcrypto/des/rpc_enc.c98
-rw-r--r--src/lib/libcrypto/des/rpw.c99
-rw-r--r--src/lib/libcrypto/des/speed.c310
-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
46 files changed, 8413 insertions, 7 deletions
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/FILES0 b/src/lib/libcrypto/des/FILES0
new file mode 100644
index 0000000000..1c2e1f75b9
--- /dev/null
+++ b/src/lib/libcrypto/des/FILES0
@@ -0,0 +1,96 @@
1/* General stuff */
2COPYRIGHT - Copyright info.
3MODES.DES - A description of the features of the different modes of DES.
4FILES - This file.
5INSTALL - How to make things compile.
6Imakefile - For use with kerberos.
7README - What this package is.
8VERSION - Which version this is and what was changed.
9KERBEROS - Kerberos version 4 notes.
10Makefile.PL - An old makefile to build with perl5, not current.
11Makefile - The SSLeay makefile
12Makefile.uni - The normal unix makefile.
13GNUmakefile - The makefile for use with glibc.
14makefile.bc - A Borland C makefile
15times - Some outputs from 'speed' on some machines.
16vms.com - For use when compiling under VMS
17
18/* My SunOS des(1) replacement */
19des.c - des(1) source code.
20des.man - des(1) manual.
21
22/* Testing and timing programs. */
23destest.c - Source for libdes.a test program.
24speed.c - Source for libdes.a timing program.
25rpw.c - Source for libdes.a testing password reading routines.
26
27/* libdes.a source code */
28des_crypt.man - libdes.a manual page.
29des.h - Public libdes.a header file.
30ecb_enc.c - des_ecb_encrypt() source, this contains the basic DES code.
31ecb3_enc.c - des_ecb3_encrypt() source.
32cbc_ckm.c - des_cbc_cksum() source.
33cbc_enc.c - des_cbc_encrypt() source.
34ncbc_enc.c - des_cbc_encrypt() that is 'normal' in that it copies
35 the new iv values back in the passed iv vector.
36ede_enc.c - des_ede3_cbc_encrypt() cbc mode des using triple DES.
37cbc3_enc.c - des_3cbc_encrypt() source, don't use this function.
38cfb_enc.c - des_cfb_encrypt() source.
39cfb64enc.c - des_cfb64_encrypt() cfb in 64 bit mode but setup to be
40 used as a stream cipher.
41cfb64ede.c - des_ede3_cfb64_encrypt() cfb in 64 bit mode but setup to be
42 used as a stream cipher and using triple DES.
43ofb_enc.c - des_cfb_encrypt() source.
44ofb64_enc.c - des_ofb_encrypt() ofb in 64 bit mode but setup to be
45 used as a stream cipher.
46ofb64ede.c - des_ede3_ofb64_encrypt() ofb in 64 bit mode but setup to be
47 used as a stream cipher and using triple DES.
48enc_read.c - des_enc_read() source.
49enc_writ.c - des_enc_write() source.
50pcbc_enc.c - des_pcbc_encrypt() source.
51qud_cksm.c - quad_cksum() source.
52rand_key.c - des_random_key() source.
53read_pwd.c - Source for des_read_password() plus related functions.
54set_key.c - Source for des_set_key().
55str2key.c - Covert a string of any length into a key.
56fcrypt.c - A small, fast version of crypt(3).
57des_locl.h - Internal libdes.a header file.
58podd.h - Odd parity tables - used in des_set_key().
59sk.h - Lookup tables used in des_set_key().
60spr.h - What is left of the S tables - used in ecb_encrypt().
61des_ver.h - header file for the external definition of the
62 version string.
63des.doc - SSLeay documentation for the library.
64
65/* The perl scripts - you can ignore these files they are only
66 * included for the curious */
67des.pl - des in perl anyone? des_set_key and des_ecb_encrypt
68 both done in a perl library.
69testdes.pl - Testing program for des.pl
70doIP - Perl script used to develop IP xor/shift code.
71doPC1 - Perl script used to develop PC1 xor/shift code.
72doPC2 - Generates sk.h.
73PC1 - Output of doPC1 should be the same as output from PC1.
74PC2 - used in development of doPC2.
75shifts.pl - Perl library used by my perl scripts.
76
77/* I started making a perl5 dynamic library for libdes
78 * but did not fully finish, these files are part of that effort. */
79DES.pm
80DES.pod
81DES.xs
82t
83typemap
84
85/* The following are for use with sun RPC implementaions. */
86rpc_des.h
87rpc_enc.c
88
89/* The following are contibuted by Mark Murray <mark@grondar.za>. They
90 * are not normally built into libdes due to machine specific routines
91 * contained in them. They are for use in the most recent incarnation of
92 * export kerberos v 4 (eBones). */
93supp.c
94new_rkey.c
95
96
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/Makefile b/src/lib/libcrypto/des/Makefile
new file mode 100644
index 0000000000..800af0b123
--- /dev/null
+++ b/src/lib/libcrypto/des/Makefile
@@ -0,0 +1,314 @@
1#
2# OpenSSL/crypto/des/Makefile
3#
4
5DIR= des
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=-I$(TOP) -I../../include
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile
17AR= ar r
18RANLIB= ranlib
19DES_ENC= des_enc.o fcrypt_b.o
20# or use
21#DES_ENC= dx86-elf.o yx86-elf.o
22
23CFLAGS= $(INCLUDES) $(CFLAG)
24ASFLAGS= $(INCLUDES) $(ASFLAG)
25
26GENERAL=Makefile
27TEST=destest.c
28APPS=
29
30LIB=$(TOP)/libcrypto.a
31LIBSRC= cbc_cksm.c cbc_enc.c cfb64enc.c cfb_enc.c \
32 ecb3_enc.c ecb_enc.c enc_read.c enc_writ.c \
33 fcrypt.c ofb64enc.c ofb_enc.c pcbc_enc.c \
34 qud_cksm.c rand_key.c rpc_enc.c set_key.c \
35 des_enc.c fcrypt_b.c \
36 xcbc_enc.c \
37 str2key.c cfb64ede.c ofb64ede.c ede_cbcm_enc.c des_old.c des_old2.c \
38 read2pwd.c
39
40LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \
41 ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \
42 enc_read.o enc_writ.o ofb64enc.o \
43 ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \
44 ${DES_ENC} \
45 fcrypt.o xcbc_enc.o rpc_enc.o cbc_cksm.o \
46 ede_cbcm_enc.o des_old.o des_old2.o read2pwd.o
47
48SRC= $(LIBSRC)
49
50EXHEADER= des.h des_old.h
51HEADER= des_locl.h rpc_des.h spr.h des_ver.h $(EXHEADER)
52
53ALL= $(GENERAL) $(SRC) $(HEADER)
54
55top:
56 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
57
58all: lib
59
60lib: $(LIBOBJ)
61 $(AR) $(LIB) $(LIBOBJ)
62 $(RANLIB) $(LIB) || echo Never mind.
63 @touch lib
64
65des: des.o cbc3_enc.o lib
66 $(CC) $(CFLAGS) -o des des.o cbc3_enc.o $(LIB)
67
68# elf
69asm/dx86-elf.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
70 (cd asm; $(PERL) des-586.pl elf $(CFLAGS) > dx86-elf.s)
71
72asm/yx86-elf.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
73 (cd asm; $(PERL) crypt586.pl elf $(CFLAGS) > yx86-elf.s)
74
75# a.out
76asm/dx86-out.o: asm/dx86unix.cpp
77 $(CPP) -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o
78
79asm/yx86-out.o: asm/yx86unix.cpp
80 $(CPP) -DOUT asm/yx86unix.cpp | as -o asm/yx86-out.o
81
82# bsdi
83asm/dx86bsdi.o: asm/dx86unix.cpp
84 $(CPP) -DBSDI asm/dx86unix.cpp | sed 's/ :/:/' | as -o asm/dx86bsdi.o
85
86asm/yx86bsdi.o: asm/yx86unix.cpp
87 $(CPP) -DBSDI asm/yx86unix.cpp | sed 's/ :/:/' | as -o asm/yx86bsdi.o
88
89asm/dx86unix.cpp: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
90 (cd asm; $(PERL) des-586.pl cpp >dx86unix.cpp)
91
92asm/yx86unix.cpp: asm/crypt586.pl ../perlasm/x86asm.pl
93 (cd asm; $(PERL) crypt586.pl cpp >yx86unix.cpp)
94
95files:
96 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
97
98links:
99 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
100 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
101 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
102
103install: installs
104
105installs:
106 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
107 do \
108 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
109 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
110 done;
111
112tags:
113 ctags $(SRC)
114
115tests:
116
117lint:
118 lint -DLINT $(INCLUDES) $(SRC)>fluff
119
120depend:
121 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
122
123dclean:
124 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
125 mv -f Makefile.new $(MAKEFILE)
126
127clean:
128 rm -f asm/dx86unix.cpp asm/yx86unix.cpp asm/*-elf.* *.o asm/*.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff
129
130# DO NOT DELETE THIS LINE -- make depend depends on it.
131
132cbc_cksm.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
133cbc_cksm.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
134cbc_cksm.o: ../../include/openssl/opensslconf.h
135cbc_cksm.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
136cbc_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
137cbc_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
138cbc_cksm.o: cbc_cksm.c des_locl.h
139cbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
140cbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
141cbc_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
142cbc_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
143cbc_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
144cbc_enc.o: ../../include/openssl/ui_compat.h cbc_enc.c des_locl.h ncbc_enc.c
145cfb64ede.o: ../../e_os.h ../../include/openssl/crypto.h
146cfb64ede.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
147cfb64ede.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
148cfb64ede.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
149cfb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
150cfb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
151cfb64ede.o: cfb64ede.c des_locl.h
152cfb64enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
153cfb64enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
154cfb64enc.o: ../../include/openssl/opensslconf.h
155cfb64enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
156cfb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
157cfb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
158cfb64enc.o: cfb64enc.c des_locl.h
159cfb_enc.o: ../../e_os.h ../../include/openssl/crypto.h
160cfb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
161cfb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
162cfb_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
163cfb_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
164cfb_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
165cfb_enc.o: cfb_enc.c des_locl.h
166des_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
167des_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
168des_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
169des_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
170des_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
171des_enc.o: ../../include/openssl/ui_compat.h des_enc.c des_locl.h ncbc_enc.c
172des_old.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
173des_old.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
174des_old.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
175des_old.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
176des_old.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
177des_old.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
178des_old.o: ../../include/openssl/ui_compat.h des_old.c
179des_old2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
180des_old2.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
181des_old2.o: ../../include/openssl/opensslconf.h
182des_old2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
183des_old2.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
184des_old2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
185des_old2.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
186des_old2.o: des_old2.c
187ecb3_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
188ecb3_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
189ecb3_enc.o: ../../include/openssl/opensslconf.h
190ecb3_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
191ecb3_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
192ecb3_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
193ecb3_enc.o: des_locl.h ecb3_enc.c
194ecb_enc.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
195ecb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
196ecb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
197ecb_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
198ecb_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
199ecb_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
200ecb_enc.o: des_locl.h des_ver.h ecb_enc.c spr.h
201ede_cbcm_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
202ede_cbcm_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
203ede_cbcm_enc.o: ../../include/openssl/opensslconf.h
204ede_cbcm_enc.o: ../../include/openssl/opensslv.h
205ede_cbcm_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
206ede_cbcm_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
207ede_cbcm_enc.o: ../../include/openssl/ui_compat.h des_locl.h ede_cbcm_enc.c
208enc_read.o: ../../e_os.h ../../include/openssl/bio.h
209enc_read.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
210enc_read.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
211enc_read.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
212enc_read.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
213enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
214enc_read.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
215enc_read.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
216enc_read.o: ../cryptlib.h des_locl.h enc_read.c
217enc_writ.o: ../../e_os.h ../../include/openssl/bio.h
218enc_writ.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
219enc_writ.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
220enc_writ.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
221enc_writ.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
222enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
223enc_writ.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
224enc_writ.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
225enc_writ.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
226enc_writ.o: ../cryptlib.h des_locl.h enc_writ.c
227fcrypt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
228fcrypt.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
229fcrypt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
230fcrypt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
231fcrypt.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
232fcrypt.o: ../../include/openssl/ui_compat.h des_locl.h fcrypt.c
233fcrypt_b.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
234fcrypt_b.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
235fcrypt_b.o: ../../include/openssl/opensslconf.h
236fcrypt_b.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
237fcrypt_b.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
238fcrypt_b.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
239fcrypt_b.o: des_locl.h fcrypt_b.c
240ofb64ede.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
241ofb64ede.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
242ofb64ede.o: ../../include/openssl/opensslconf.h
243ofb64ede.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
244ofb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
245ofb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
246ofb64ede.o: des_locl.h ofb64ede.c
247ofb64enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
248ofb64enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
249ofb64enc.o: ../../include/openssl/opensslconf.h
250ofb64enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
251ofb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
252ofb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
253ofb64enc.o: des_locl.h ofb64enc.c
254ofb_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
255ofb_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
256ofb_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
257ofb_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
258ofb_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
259ofb_enc.o: ../../include/openssl/ui_compat.h des_locl.h ofb_enc.c
260pcbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
261pcbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
262pcbc_enc.o: ../../include/openssl/opensslconf.h
263pcbc_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
264pcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
265pcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
266pcbc_enc.o: des_locl.h pcbc_enc.c
267qud_cksm.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
268qud_cksm.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
269qud_cksm.o: ../../include/openssl/opensslconf.h
270qud_cksm.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
271qud_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
272qud_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
273qud_cksm.o: des_locl.h qud_cksm.c
274rand_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
275rand_key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
276rand_key.o: ../../include/openssl/opensslconf.h
277rand_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
278rand_key.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
279rand_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
280rand_key.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
281rand_key.o: rand_key.c
282read2pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
283read2pwd.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
284read2pwd.o: ../../include/openssl/opensslconf.h
285read2pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
286read2pwd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
287read2pwd.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
288read2pwd.o: read2pwd.c
289rpc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
290rpc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
291rpc_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
292rpc_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
293rpc_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
294rpc_enc.o: ../../include/openssl/ui_compat.h des_locl.h des_ver.h rpc_des.h
295rpc_enc.o: rpc_enc.c
296set_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
297set_key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
298set_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
299set_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
300set_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
301set_key.o: ../../include/openssl/ui_compat.h des_locl.h set_key.c
302str2key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
303str2key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
304str2key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
305str2key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
306str2key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
307str2key.o: ../../include/openssl/ui_compat.h des_locl.h str2key.c
308xcbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
309xcbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
310xcbc_enc.o: ../../include/openssl/opensslconf.h
311xcbc_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
312xcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
313xcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
314xcbc_enc.o: des_locl.h xcbc_enc.c
diff --git a/src/lib/libcrypto/des/Makefile.ssl b/src/lib/libcrypto/des/Makefile.ssl
new file mode 100644
index 0000000000..0d9ba2b42f
--- /dev/null
+++ b/src/lib/libcrypto/des/Makefile.ssl
@@ -0,0 +1,316 @@
1#
2# SSLeay/crypto/des/Makefile
3#
4
5DIR= des
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=-I$(TOP) -I../../include
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19RANLIB= ranlib
20DES_ENC= des_enc.o fcrypt_b.o
21# or use
22#DES_ENC= dx86-elf.o yx86-elf.o
23
24CFLAGS= $(INCLUDES) $(CFLAG)
25ASFLAGS= $(INCLUDES) $(ASFLAG)
26
27GENERAL=Makefile
28TEST=destest.c
29APPS=
30
31LIB=$(TOP)/libcrypto.a
32LIBSRC= cbc_cksm.c cbc_enc.c cfb64enc.c cfb_enc.c \
33 ecb3_enc.c ecb_enc.c enc_read.c enc_writ.c \
34 fcrypt.c ofb64enc.c ofb_enc.c pcbc_enc.c \
35 qud_cksm.c rand_key.c rpc_enc.c set_key.c \
36 des_enc.c fcrypt_b.c \
37 xcbc_enc.c \
38 str2key.c cfb64ede.c ofb64ede.c ede_cbcm_enc.c des_old.c des_old2.c \
39 read2pwd.c
40
41LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \
42 ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \
43 enc_read.o enc_writ.o ofb64enc.o \
44 ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \
45 ${DES_ENC} \
46 fcrypt.o xcbc_enc.o rpc_enc.o cbc_cksm.o \
47 ede_cbcm_enc.o des_old.o des_old2.o read2pwd.o
48
49SRC= $(LIBSRC)
50
51EXHEADER= des.h des_old.h
52HEADER= des_locl.h rpc_des.h spr.h des_ver.h $(EXHEADER)
53
54ALL= $(GENERAL) $(SRC) $(HEADER)
55
56top:
57 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
58
59all: lib
60
61lib: $(LIBOBJ)
62 $(AR) $(LIB) $(LIBOBJ)
63 $(RANLIB) $(LIB) || echo Never mind.
64 @touch lib
65
66des: des.o cbc3_enc.o lib
67 $(CC) $(CFLAGS) -o des des.o cbc3_enc.o $(LIB)
68
69# elf
70asm/dx86-elf.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
71 (cd asm; $(PERL) des-586.pl elf $(CFLAGS) > dx86-elf.s)
72
73asm/yx86-elf.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
74 (cd asm; $(PERL) crypt586.pl elf $(CFLAGS) > yx86-elf.s)
75
76# a.out
77asm/dx86-out.o: asm/dx86unix.cpp
78 $(CPP) -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o
79
80asm/yx86-out.o: asm/yx86unix.cpp
81 $(CPP) -DOUT asm/yx86unix.cpp | as -o asm/yx86-out.o
82
83# bsdi
84asm/dx86bsdi.o: asm/dx86unix.cpp
85 $(CPP) -DBSDI asm/dx86unix.cpp | sed 's/ :/:/' | as -o asm/dx86bsdi.o
86
87asm/yx86bsdi.o: asm/yx86unix.cpp
88 $(CPP) -DBSDI asm/yx86unix.cpp | sed 's/ :/:/' | as -o asm/yx86bsdi.o
89
90asm/dx86unix.cpp: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
91 (cd asm; $(PERL) des-586.pl cpp >dx86unix.cpp)
92
93asm/yx86unix.cpp: asm/crypt586.pl ../perlasm/x86asm.pl
94 (cd asm; $(PERL) crypt586.pl cpp >yx86unix.cpp)
95
96files:
97 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
98
99links:
100 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
101 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
102 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
103 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
104
105install: installs
106
107installs:
108 @for i in $(EXHEADER) ; \
109 do \
110 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
111 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
112 done;
113
114tags:
115 ctags $(SRC)
116
117tests:
118
119lint:
120 lint -DLINT $(INCLUDES) $(SRC)>fluff
121
122depend:
123 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
124
125dclean:
126 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
127 mv -f Makefile.new $(MAKEFILE)
128
129clean:
130 rm -f asm/dx86unix.cpp asm/yx86unix.cpp asm/*-elf.* *.o asm/*.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff
131
132# DO NOT DELETE THIS LINE -- make depend depends on it.
133
134cbc_cksm.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
135cbc_cksm.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
136cbc_cksm.o: ../../include/openssl/opensslconf.h
137cbc_cksm.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
138cbc_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
139cbc_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
140cbc_cksm.o: cbc_cksm.c des_locl.h
141cbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
142cbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
143cbc_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
144cbc_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
145cbc_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
146cbc_enc.o: ../../include/openssl/ui_compat.h cbc_enc.c des_locl.h ncbc_enc.c
147cfb64ede.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
148cfb64ede.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
149cfb64ede.o: ../../include/openssl/opensslconf.h
150cfb64ede.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
151cfb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
152cfb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
153cfb64ede.o: cfb64ede.c des_locl.h
154cfb64enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
155cfb64enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
156cfb64enc.o: ../../include/openssl/opensslconf.h
157cfb64enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
158cfb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
159cfb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
160cfb64enc.o: cfb64enc.c des_locl.h
161cfb_enc.o: ../../e_os.h ../../include/openssl/crypto.h
162cfb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
163cfb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
164cfb_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
165cfb_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
166cfb_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
167cfb_enc.o: cfb_enc.c des_locl.h
168des_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
169des_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
170des_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
171des_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
172des_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
173des_enc.o: ../../include/openssl/ui_compat.h des_enc.c des_locl.h ncbc_enc.c
174des_old.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
175des_old.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
176des_old.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
177des_old.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
178des_old.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
179des_old.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
180des_old.o: ../../include/openssl/ui_compat.h des_old.c
181des_old2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
182des_old2.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
183des_old2.o: ../../include/openssl/opensslconf.h
184des_old2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
185des_old2.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
186des_old2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
187des_old2.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
188des_old2.o: des_old2.c
189ecb3_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
190ecb3_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
191ecb3_enc.o: ../../include/openssl/opensslconf.h
192ecb3_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
193ecb3_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
194ecb3_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
195ecb3_enc.o: des_locl.h ecb3_enc.c
196ecb_enc.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
197ecb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
198ecb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
199ecb_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
200ecb_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
201ecb_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
202ecb_enc.o: des_locl.h des_ver.h ecb_enc.c spr.h
203ede_cbcm_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
204ede_cbcm_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
205ede_cbcm_enc.o: ../../include/openssl/opensslconf.h
206ede_cbcm_enc.o: ../../include/openssl/opensslv.h
207ede_cbcm_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
208ede_cbcm_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
209ede_cbcm_enc.o: ../../include/openssl/ui_compat.h des_locl.h ede_cbcm_enc.c
210enc_read.o: ../../e_os.h ../../include/openssl/bio.h
211enc_read.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
212enc_read.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
213enc_read.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
214enc_read.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
215enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
216enc_read.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
217enc_read.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
218enc_read.o: ../cryptlib.h des_locl.h enc_read.c
219enc_writ.o: ../../e_os.h ../../include/openssl/bio.h
220enc_writ.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
221enc_writ.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
222enc_writ.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
223enc_writ.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
224enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
225enc_writ.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
226enc_writ.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
227enc_writ.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
228enc_writ.o: ../cryptlib.h des_locl.h enc_writ.c
229fcrypt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
230fcrypt.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
231fcrypt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
232fcrypt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
233fcrypt.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
234fcrypt.o: ../../include/openssl/ui_compat.h des_locl.h fcrypt.c
235fcrypt_b.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
236fcrypt_b.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
237fcrypt_b.o: ../../include/openssl/opensslconf.h
238fcrypt_b.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
239fcrypt_b.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
240fcrypt_b.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
241fcrypt_b.o: des_locl.h fcrypt_b.c
242ofb64ede.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
243ofb64ede.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
244ofb64ede.o: ../../include/openssl/opensslconf.h
245ofb64ede.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
246ofb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
247ofb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
248ofb64ede.o: des_locl.h ofb64ede.c
249ofb64enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
250ofb64enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
251ofb64enc.o: ../../include/openssl/opensslconf.h
252ofb64enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
253ofb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
254ofb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
255ofb64enc.o: des_locl.h ofb64enc.c
256ofb_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
257ofb_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
258ofb_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
259ofb_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
260ofb_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
261ofb_enc.o: ../../include/openssl/ui_compat.h des_locl.h ofb_enc.c
262pcbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
263pcbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
264pcbc_enc.o: ../../include/openssl/opensslconf.h
265pcbc_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
266pcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
267pcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
268pcbc_enc.o: des_locl.h pcbc_enc.c
269qud_cksm.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
270qud_cksm.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
271qud_cksm.o: ../../include/openssl/opensslconf.h
272qud_cksm.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
273qud_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
274qud_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
275qud_cksm.o: des_locl.h qud_cksm.c
276rand_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
277rand_key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
278rand_key.o: ../../include/openssl/opensslconf.h
279rand_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
280rand_key.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
281rand_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
282rand_key.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
283rand_key.o: rand_key.c
284read2pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
285read2pwd.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
286read2pwd.o: ../../include/openssl/opensslconf.h
287read2pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
288read2pwd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
289read2pwd.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
290read2pwd.o: read2pwd.c
291rpc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
292rpc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
293rpc_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
294rpc_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
295rpc_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
296rpc_enc.o: ../../include/openssl/ui_compat.h des_locl.h des_ver.h rpc_des.h
297rpc_enc.o: rpc_enc.c
298set_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
299set_key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
300set_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
301set_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
302set_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
303set_key.o: ../../include/openssl/ui_compat.h des_locl.h set_key.c
304str2key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
305str2key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
306str2key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
307str2key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
308str2key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
309str2key.o: ../../include/openssl/ui_compat.h des_locl.h str2key.c
310xcbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
311xcbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
312xcbc_enc.o: ../../include/openssl/opensslconf.h
313xcbc_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
314xcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
315xcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
316xcbc_enc.o: des_locl.h xcbc_enc.c
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..c7d01542bc
--- /dev/null
+++ b/src/lib/libcrypto/des/VERSION
@@ -0,0 +1,412 @@
1 Fixed the weak key values which were wrong :-(
2 Defining SIGACTION causes sigaction() to be used instead of signal().
3 SIGUSR1/SIGUSR2 are no longer mapped in the read tty stuff because it
4 can cause problems. This should hopefully not affect normal
5 applications.
6
7Version 4.04
8 Fixed a few tests in destest. Also added x86 assember for
9 des_ncbc_encrypt() which is the standard cbc mode function.
10 This makes a very very large performace difference.
11 Ariel Glenn ariel@columbia.edu reports that the terminal
12 'turn echo off' can return (errno == EINVAL) under solaris
13 when redirection is used. So I now catch that as well as ENOTTY.
14
15
16Version 4.03
17 Left a static out of enc_write.c, which caused to buffer to be
18 continiously malloc()ed. Does anyone use these functions? I keep
19 on feeling like removing them since I only had these in there
20 for a version of kerberised login. Anyway, this was pointed out
21 by Theo de Raadt <deraadt@cvs.openbsd.org>
22 The 'n' bit ofb code was wrong, it was not shifting the shift
23 register. It worked correctly for n == 64. Thanks to
24 Gigi Ankeny <Gigi.Ankeny@Eng.Sun.COM> for pointing this one out.
25
26Version 4.02
27 I was doing 'if (memcmp(weak_keys[i],key,sizeof(key)) == 0)'
28 when checking for weak keys which is wrong :-(, pointed out by
29 Markus F.X.J. Oberhumer <markus.oberhumer@jk.uni-linz.ac.at>.
30
31Version 4.01
32 Even faster inner loop in the DES assembler for x86 and a modification
33 for IP/FP which is faster on x86. Both of these changes are
34 from Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>. His
35 changes make the assembler run %40 faster on a pentium. This is just
36 a case of getting the instruction sequence 'just right'.
37 All credit to 'Svend' :-)
38 Quite a few special x86 'make' targets.
39 A libdes-l (lite) distribution.
40
41Version 4.00
42 After a bit of a pause, I'll up the major version number since this
43 is mostly a performace release. I've added x86 assembler and
44 added more options for performance. A %28 speedup for gcc
45 on a pentium and the assembler is a %50 speedup.
46 MIPS CPU's, sparc and Alpha are the main CPU's with speedups.
47 Run des_opts to work out which options should be used.
48 DES_RISC1/DES_RISC2 use alternative inner loops which use
49 more registers but should give speedups on any CPU that does
50 dual issue (pentium). DES_UNROLL unrolls the inner loop,
51 which costs in code size.
52
53Version 3.26
54 I've finally removed one of the shifts in D_ENCRYPT. This
55 meant I've changed the des_SPtrans table (spr.h), the set_key()
56 function and some things in des_enc.c. This has definitly
57 made things faster :-). I've known about this one for some
58 time but I've been too lazy to follow it up :-).
59 Noticed that in the D_ENCRYPT() macro, we can just do L^=(..)^(..)^..
60 instead of L^=((..)|(..)|(..).. This should save a register at
61 least.
62 Assember for x86. The file to replace is des_enc.c, which is replaced
63 by one of the assembler files found in asm. Look at des/asm/readme
64 for more info.
65
66 /* Modification to fcrypt so it can be compiled to support
67 HPUX 10.x's long password format, define -DLONGCRYPT to use this.
68 Thanks to Jens Kupferschmidt <bt1cu@hpboot.rz.uni-leipzig.de>. */
69
70 SIGWINCH case put in des_read_passwd() so the function does not
71 'exit' if this function is recieved.
72
73Version 3.25 17/07/96
74 Modified read_pwd.c so that stdin can be read if not a tty.
75 Thanks to Jeff Barber <jeffb@issl.atl.hp.com> for the patches.
76 des_init_random_number_generator() shortened due to VMS linker
77 limits.
78 Added RSA's DESX cbc mode. It is a form of cbc encryption, with 2
79 8 byte quantites xored before and after encryption.
80 des_xcbc_encryption() - the name is funny to preserve the des_
81 prefix on all functions.
82
83Version 3.24 20/04/96
84 The DES_PTR macro option checked and used by SSLeay configuration
85
86Version 3.23 11/04/96
87 Added DES_LONG. If defined to 'unsigned int' on the DEC Alpha,
88 it gives a %20 speedup :-)
89 Fixed the problem with des.pl under perl5. The patches were
90 sent by Ed Kubaitis (ejk@uiuc.edu).
91 if fcrypt.c, changed values to handle illegal salt values the way
92 normal crypt() implementations do. Some programs apparently use
93 them :-(. The patch was sent by Bjorn Gronvall <bg@sics.se>
94
95Version 3.22 29/11/95
96 Bug in des(1), an error with the uuencoding stuff when the
97 'data' is small, thanks to Geoff Keating <keagchon@mehta.anu.edu.au>
98 for the patch.
99
100Version 3.21 22/11/95
101 After some emailing back and forth with
102 Colin Plumb <colin@nyx10.cs.du.edu>, I've tweaked a few things
103 and in a future version I will probably put in some of the
104 optimisation he suggested for use with the DES_USE_PTR option.
105 Extra routines from Mark Murray <mark@grondar.za> for use in
106 freeBSD. They mostly involve random number generation for use
107 with kerberos. They involve evil machine specific system calls
108 etc so I would normally suggest pushing this stuff into the
109 application and/or using RAND_seed()/RAND_bytes() if you are
110 using this DES library as part of SSLeay.
111 Redone the read_pw() function so that it is cleaner and
112 supports termios, thanks to Sameer Parekh <sameer@c2.org>
113 for the initial patches for this.
114 Renamed 3ecb_encrypt() to ecb3_encrypt(). This has been
115 done just to make things more consistent.
116 I have also now added triple DES versions of cfb and ofb.
117
118Version 3.20
119 Damn, Damn, Damn, as pointed out by Mike_Spreitzer.PARC@xerox.com,
120 my des_random_seed() function was only copying 4 bytes of the
121 passed seed into the init structure. It is now fixed to copy 8.
122 My own suggestion is to used something like MD5 :-)
123
124Version 3.19
125 While looking at my code one day, I though, why do I keep on
126 calling des_encrypt(in,out,ks,enc) when every function that
127 calls it has in and out the same. So I dropped the 'out'
128 parameter, people should not be using this function.
129
130Version 3.18 30/08/95
131 Fixed a few bit with the distribution and the filenames.
132 3.17 had been munged via a move to DOS and back again.
133 NO CODE CHANGES
134
135Version 3.17 14/07/95
136 Fixed ede3 cbc which I had broken in 3.16. I have also
137 removed some unneeded variables in 7-8 of the routines.
138
139Version 3.16 26/06/95
140 Added des_encrypt2() which does not use IP/FP, used by triple
141 des routines. Tweaked things a bit elsewhere. %13 speedup on
142 sparc and %6 on a R4400 for ede3 cbc mode.
143
144Version 3.15 06/06/95
145 Added des_ncbc_encrypt(), it is des_cbc mode except that it is
146 'normal' and copies the new iv value back over the top of the
147 passed parameter.
148 CHANGED des_ede3_cbc_encrypt() so that it too now overwrites
149 the iv. THIS WILL BREAK EXISTING CODE, but since this function
150 only new, I feel I can change it, not so with des_cbc_encrypt :-(.
151 I need to update the documentation.
152
153Version 3.14 31/05/95
154 New release upon the world, as part of my SSL implementation.
155 New copyright and usage stuff. Basically free for all to use
156 as long as you say it came from me :-)
157
158Version 3.13 31/05/95
159 A fix in speed.c, if HZ is not defined, I set it to 100.0
160 which is reasonable for most unixes except SunOS 4.x.
161 I now have a #ifdef sun but timing for SunOS 4.x looked very
162 good :-(. At my last job where I used SunOS 4.x, it was
163 defined to be 60.0 (look at the old INSTALL documentation), at
164 the last release had it changed to 100.0 since I now work with
165 Solaris2 and SVR4 boxes.
166 Thanks to Rory Chisholm <rchishol@math.ethz.ch> for pointing this
167 one out.
168
169Version 3.12 08/05/95
170 As pointed out by The Crypt Keeper <tck@bend.UCSD.EDU>,
171 my D_ENCRYPT macro in crypt() had an un-necessary variable.
172 It has been removed.
173
174Version 3.11 03/05/95
175 Added des_ede3_cbc_encrypt() which is cbc mode des with 3 keys
176 and one iv. It is a standard and I needed it for my SSL code.
177 It makes more sense to use this for triple DES than
178 3cbc_encrypt(). I have also added (or should I say tested :-)
179 cfb64_encrypt() which is cfb64 but it will encrypt a partial
180 number of bytes - 3 bytes in 3 bytes out. Again this is for
181 my SSL library, as a form of encryption to use with SSL
182 telnet.
183
184Version 3.10 22/03/95
185 Fixed a bug in 3cbc_encrypt() :-(. When making repeated calls
186 to cbc3_encrypt, the 2 iv values that were being returned to
187 be used in the next call were reversed :-(.
188 Many thanks to Bill Wade <wade@Stoner.COM> for pointing out
189 this error.
190
191Version 3.09 01/02/95
192 Fixed des_random_key to far more random, it was rather feeble
193 with regards to picking the initial seed. The problem was
194 pointed out by Olaf Kirch <okir@monad.swb.de>.
195
196Version 3.08 14/12/94
197 Added Makefile.PL so libdes can be built into perl5.
198 Changed des_locl.h so RAND is always defined.
199
200Version 3.07 05/12/94
201 Added GNUmake and stuff so the library can be build with
202 glibc.
203
204Version 3.06 30/08/94
205 Added rpc_enc.c which contains _des_crypt. This is for use in
206 secure_rpc v 4.0
207 Finally fixed the cfb_enc problems.
208 Fixed a few parameter parsing bugs in des (-3 and -b), thanks
209 to Rob McMillan <R.McMillan@its.gu.edu.au>
210
211Version 3.05 21/04/94
212 for unsigned long l; gcc does not produce ((l>>34) == 0)
213 This causes bugs in cfb_enc.
214 Thanks to Hadmut Danisch <danisch@ira.uka.de>
215
216Version 3.04 20/04/94
217 Added a version number to des.c and libdes.a
218
219Version 3.03 12/01/94
220 Fixed a bug in non zero iv in 3cbc_enc.
221
222Version 3.02 29/10/93
223 I now work in a place where there are 6+ architectures and 14+
224 OS versions :-).
225 Fixed TERMIO definition so the most sys V boxes will work :-)
226
227Release upon comp.sources.misc
228Version 3.01 08/10/93
229 Added des_3cbc_encrypt()
230
231Version 3.00 07/10/93
232 Fixed up documentation.
233 quad_cksum definitely compatible with MIT's now.
234
235Version 2.30 24/08/93
236 Triple DES now defaults to triple cbc but can do triple ecb
237 with the -b flag.
238 Fixed some MSDOS uuen/uudecoding problems, thanks to
239 Added prototypes.
240
241Version 2.22 29/06/93
242 Fixed a bug in des_is_weak_key() which stopped it working :-(
243 thanks to engineering@MorningStar.Com.
244
245Version 2.21 03/06/93
246 des(1) with no arguments gives quite a bit of help.
247 Added -c (generate ckecksum) flag to des(1).
248 Added -3 (triple DES) flag to des(1).
249 Added cfb and ofb routines to the library.
250
251Version 2.20 11/03/93
252 Added -u (uuencode) flag to des(1).
253 I have been playing with byte order in quad_cksum to make it
254 compatible with MIT's version. All I can say is avid this
255 function if possible since MIT's output is endian dependent.
256
257Version 2.12 14/10/92
258 Added MSDOS specific macro in ecb_encrypt which gives a %70
259 speed up when the code is compiled with turbo C.
260
261Version 2.11 12/10/92
262 Speedup in set_key (recoding of PC-1)
263 I now do it in 47 simple operations, down from 60.
264 Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
265 for motivating me to look for a faster system :-)
266 The speedup is probably less that 1% but it is still 13
267 instructions less :-).
268
269Version 2.10 06/10/92
270 The code now works on the 64bit ETA10 and CRAY without modifications or
271 #defines. I believe the code should work on any machine that
272 defines long, int or short to be 8 bytes long.
273 Thanks to Shabbir J. Safdar (shabby@mentor.cc.purdue.edu)
274 for helping me fix the code to run on 64bit machines (he had
275 access to an ETA10).
276 Thanks also to John Fletcher <john_fletcher@lccmail.ocf.llnl.gov>
277 for testing the routines on a CRAY.
278 read_password.c has been renamed to read_passwd.c
279 string_to_key.c has been renamed to string2key.c
280
281Version 2.00 14/09/92
282 Made mods so that the library should work on 64bit CPU's.
283 Removed all my uchar and ulong defs. To many different
284 versions of unix define them in their header files in too many
285 different combinations :-)
286 IRIX - Sillicon Graphics mods (mostly in read_password.c).
287 Thanks to Andrew Daviel (advax@erich.triumf.ca)
288
289Version 1.99 26/08/92
290 Fixed a bug or 2 in enc_read.c
291 Fixed a bug in enc_write.c
292 Fixed a pseudo bug in fcrypt.c (very obscure).
293
294Version 1.98 31/07/92
295 Support for the ETA10. This is a strange machine that defines
296 longs and ints as 8 bytes and shorts as 4 bytes.
297 Since I do evil things with long * that assume that they are 4
298 bytes. Look in the Makefile for the option to compile for
299 this machine. quad_cksum appears to have problems but I
300 will don't have the time to fix it right now, and this is not
301 a function that uses DES and so will not effect the main uses
302 of the library.
303
304Version 1.97 20/05/92 eay
305 Fixed the Imakefile and made some changes to des.h to fix some
306 problems when building this package with Kerberos v 4.
307
308Version 1.96 18/05/92 eay
309 Fixed a small bug in string_to_key() where problems could
310 occur if des_check_key was set to true and the string
311 generated a weak key.
312
313Patch2 posted to comp.sources.misc
314Version 1.95 13/05/92 eay
315 Added an alternative version of the D_ENCRYPT macro in
316 ecb_encrypt and fcrypt. Depending on the compiler, one version or the
317 other will be faster. This was inspired by
318 Dana How <how@isl.stanford.edu>, and her pointers about doing the
319 *(ulong *)((uchar *)ptr+(value&0xfc))
320 vs
321 ptr[value&0x3f]
322 to stop the C compiler doing a <<2 to convert the long array index.
323
324Version 1.94 05/05/92 eay
325 Fixed an incompatibility between my string_to_key and the MIT
326 version. When the key is longer than 8 chars, I was wrapping
327 with a different method. To use the old version, define
328 OLD_STR_TO_KEY in the makefile. Thanks to
329 viktor@newsu.shearson.com (Viktor Dukhovni).
330
331Version 1.93 28/04/92 eay
332 Fixed the VMS mods so that echo is now turned off in
333 read_password. Thanks again to brennan@coco.cchs.su.oz.AU.
334 MSDOS support added. The routines can be compiled with
335 Turbo C (v2.0) and MSC (v5.1). Make sure MSDOS is defined.
336
337Patch1 posted to comp.sources.misc
338Version 1.92 13/04/92 eay
339 Changed D_ENCRYPT so that the rotation of R occurs outside of
340 the loop. This required rotating all the longs in sp.h (now
341 called spr.h). Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
342 speed.c has been changed so it will work without SIGALRM. If
343 times(3) is not present it will try to use ftime() instead.
344
345Version 1.91 08/04/92 eay
346 Added -E/-D options to des(1) so it can use string_to_key.
347 Added SVR4 mods suggested by witr@rwwa.COM
348 Added VMS mods suggested by brennan@coco.cchs.su.oz.AU. If
349 anyone knows how to turn of tty echo in VMS please tell me or
350 implement it yourself :-).
351 Changed FILE *IN/*OUT to *DES_IN/*DES_OUT since it appears VMS
352 does not like IN/OUT being used.
353
354Libdes posted to comp.sources.misc
355Version 1.9 24/03/92 eay
356 Now contains a fast small crypt replacement.
357 Added des(1) command.
358 Added des_rw_mode so people can use cbc encryption with
359 enc_read and enc_write.
360
361Version 1.8 15/10/91 eay
362 Bug in cbc_cksum.
363 Many thanks to Keith Reynolds (keithr@sco.COM) for pointing this
364 one out.
365
366Version 1.7 24/09/91 eay
367 Fixed set_key :-)
368 set_key is 4 times faster and takes less space.
369 There are a few minor changes that could be made.
370
371Version 1.6 19/09/1991 eay
372 Finally go IP and FP finished.
373 Now I need to fix set_key.
374 This version is quite a bit faster that 1.51
375
376Version 1.52 15/06/1991 eay
377 20% speedup in ecb_encrypt by changing the E bit selection
378 to use 2 32bit words. This also required modification of the
379 sp table. There is still a way to speedup the IP and IP-1
380 (hints from outer@sq.com) still working on this one :-(.
381
382Version 1.51 07/06/1991 eay
383 Faster des_encrypt by loop unrolling
384 Fixed bug in quad_cksum.c (thanks to hughes@logos.ucs.indiana.edu)
385
386Version 1.50 28/05/1991 eay
387 Optimised the code a bit more for the sparc. I have improved the
388 speed of the inner des_encrypt by speeding up the initial and
389 final permutations.
390
391Version 1.40 23/10/1990 eay
392 Fixed des_random_key, it did not produce a random key :-(
393
394Version 1.30 2/10/1990 eay
395 Have made des_quad_cksum the same as MIT's, the full package
396 should be compatible with MIT's
397 Have tested on a DECstation 3100
398 Still need to fix des_set_key (make it faster).
399 Does des_cbc_encrypts at 70.5k/sec on a 3100.
400
401Version 1.20 18/09/1990 eay
402 Fixed byte order dependencies.
403 Fixed (I hope) all the word alignment problems.
404 Speedup in des_ecb_encrypt.
405
406Version 1.10 11/09/1990 eay
407 Added des_enc_read and des_enc_write.
408 Still need to fix des_quad_cksum.
409 Still need to document des_enc_read and des_enc_write.
410
411Version 1.00 27/08/1990 eay
412
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl
index b75d3c6b3a..60d577cc8d 100644
--- a/src/lib/libcrypto/des/asm/des-586.pl
+++ b/src/lib/libcrypto/des/asm/des-586.pl
@@ -22,10 +22,14 @@ $R="esi";
22&external_label("DES_SPtrans"); 22&external_label("DES_SPtrans");
23&DES_encrypt("DES_encrypt1",1); 23&DES_encrypt("DES_encrypt1",1);
24&DES_encrypt("DES_encrypt2",0); 24&DES_encrypt("DES_encrypt2",0);
25&DES_encrypt3("DES_encrypt3",1); 25
26&DES_encrypt3("DES_decrypt3",0); 26if (!$main'openbsd)
27&cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1); 27 {
28&cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5); 28 &DES_encrypt3("DES_encrypt3",1);
29 &DES_encrypt3("DES_decrypt3",0);
30 &cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
31 &cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
32 }
29 33
30&asm_finish(); 34&asm_finish();
31 35
diff --git a/src/lib/libcrypto/des/asm/des686.pl b/src/lib/libcrypto/des/asm/des686.pl
new file mode 100644
index 0000000000..d3ad5d5edd
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/des686.pl
@@ -0,0 +1,230 @@
1#!/usr/local/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_encrypt1",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..1beafe253b
--- /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_encrypt1(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..b5db4e14f7
--- /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(DES_cblock *input, DES_cblock *output, long length,
63 DES_key_schedule ks1, DES_key_schedule ks2, DES_cblock *iv1,
64 DES_cblock *iv2, int enc)
65 {
66 int off=((int)length-1)/8;
67 long l8=((length+7)/8)*8;
68 DES_cblock niv1,niv2;
69
70 if (enc == DES_ENCRYPT)
71 {
72 DES_cbc_encrypt((unsigned char*)input,
73 (unsigned char*)output,length,&ks1,iv1,enc);
74 if (length >= sizeof(DES_cblock))
75 memcpy(niv1,output[off],sizeof(DES_cblock));
76 DES_cbc_encrypt((unsigned char*)output,
77 (unsigned char*)output,l8,&ks2,iv1,!enc);
78 DES_cbc_encrypt((unsigned char*)output,
79 (unsigned char*)output,l8,&ks1,iv2,enc);
80 if (length >= sizeof(DES_cblock))
81 memcpy(niv2,output[off],sizeof(DES_cblock));
82 }
83 else
84 {
85 if (length >= sizeof(DES_cblock))
86 memcpy(niv2,input[off],sizeof(DES_cblock));
87 DES_cbc_encrypt((unsigned char*)input,
88 (unsigned char*)output,l8,&ks1,iv2,enc);
89 DES_cbc_encrypt((unsigned char*)output,
90 (unsigned char*)output,l8,&ks2,iv1,!enc);
91 if (length >= sizeof(DES_cblock))
92 memcpy(niv1,output[off],sizeof(DES_cblock));
93 DES_cbc_encrypt((unsigned char*)output,
94 (unsigned char*)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-lib.com b/src/lib/libcrypto/des/des-lib.com
new file mode 100644
index 0000000000..fc2c35a1ce
--- /dev/null
+++ b/src/lib/libcrypto/des/des-lib.com
@@ -0,0 +1,1003 @@
1$!
2$! DES-LIB.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$! Changes by Richard Levitte <richard@levitte.org>
9$!
10$! This command files compiles and creates the
11$! "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" library. The "xxx" denotes the machine
12$! architecture of AXP or VAX.
13$!
14$! It was re-written to try to determine which "C" compiler to try to use
15$! or the user can specify a compiler in P3.
16$!
17$! Specify one of the following to build just that part, specify "ALL" to
18$! just build everything.
19$!
20$! ALL To Just Build "Everything".
21$! LIBRARY To Just Build The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library.
22$! DESTEST To Just Build The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program.
23$! SPEED To Just Build The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program.
24$! RPW To Just Build The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program.
25$! DES To Just Build The [.xxx.EXE.CRYPTO.DES]DES.EXE Program.
26$! DES_OPTS To Just Build The [.xxx.EXE.CRYPTO.DES]DES_OPTS.EXE Program.
27$!
28$! Specify either DEBUG or NODEBUG as P2 to compile with or without
29$! debugging information.
30$!
31$! Specify which compiler at P3 to try to compile under.
32$!
33$! VAXC For VAX C.
34$! DECC For DEC C.
35$! GNUC For GNU C.
36$!
37$! If you don't speficy a compiler, it will try to determine which
38$! "C" compiler to try to use.
39$!
40$! P4, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
41$!
42$!
43$! Make sure we know what architecture we run on.
44$!
45$!
46$! Check Which Architecture We Are Using.
47$!
48$ IF (F$GETSYI("CPU").GE.128)
49$ THEN
50$!
51$! The Architecture Is AXP.
52$!
53$ ARCH := AXP
54$!
55$! Else...
56$!
57$ ELSE
58$!
59$! The Architecture Is VAX.
60$!
61$ ARCH := VAX
62$!
63$! End The Architecture Check.
64$!
65$ ENDIF
66$!
67$! Check To Make Sure We Have Valid Command Line Parameters.
68$!
69$ GOSUB CHECK_OPTIONS
70$!
71$! Tell The User What Kind of Machine We Run On.
72$!
73$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
74$!
75$! Define The OBJ Directory Name.
76$!
77$ OBJ_DIR := SYS$DISK:[--.'ARCH'.OBJ.CRYPTO.DES]
78$!
79$! Check To See If The Architecture Specific OBJ Directory Exists.
80$!
81$ IF (F$PARSE(OBJ_DIR).EQS."")
82$ THEN
83$!
84$! It Dosen't Exist, So Create It.
85$!
86$ CREATE/DIR 'OBJ_DIR'
87$!
88$! End The Architecture Specific OBJ Directory Check.
89$!
90$ ENDIF
91$!
92$! Define The EXE Directory Name.
93$!
94$ EXE_DIR :== SYS$DISK:[--.'ARCH'.EXE.CRYPTO.DES]
95$!
96$! Check To See If The Architecture Specific Directory Exists.
97$!
98$ IF (F$PARSE(EXE_DIR).EQS."")
99$ THEN
100$!
101$! It Dosen't Exist, So Create It.
102$!
103$ CREATE/DIR 'EXE_DIR'
104$!
105$! End The Architecture Specific Directory Check.
106$!
107$ ENDIF
108$!
109$! Define The Library Name.
110$!
111$ LIB_NAME := 'EXE_DIR'LIBDES.OLB
112$!
113$! Check To See What We Are To Do.
114$!
115$ IF (BUILDALL.EQS."TRUE")
116$ THEN
117$!
118$! Since Nothing Special Was Specified, Do Everything.
119$!
120$ GOSUB LIBRARY
121$ GOSUB DESTEST
122$ GOSUB SPEED
123$ GOSUB RPW
124$ GOSUB DES
125$ GOSUB DES_OPTS
126$!
127$! Else...
128$!
129$ ELSE
130$!
131$! Build Just What The User Wants Us To Build.
132$!
133$ GOSUB 'BUILDALL'
134$!
135$! End The BUILDALL Check.
136$!
137$ ENDIF
138$!
139$! Time To EXIT.
140$!
141$ EXIT
142$ LIBRARY:
143$!
144$! Tell The User That We Are Compiling.
145$!
146$ WRITE SYS$OUTPUT "Compiling The ",LIB_NAME," Files."
147$!
148$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" Library...
149$!
150$ IF (F$SEARCH(LIB_NAME).EQS."")
151$ THEN
152$!
153$! Guess Not, Create The Library.
154$!
155$ LIBRARY/CREATE/OBJECT 'LIB_NAME'
156$!
157$! End The Library Exist Check.
158$!
159$ ENDIF
160$!
161$! Define The DES Library Files.
162$!
163$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ -
164 "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ -
165 "enc_read,enc_writ,ofb64enc,"+ -
166 "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ -
167 "des_enc,fcrypt_b,read2pwd,"+ -
168 "fcrypt,xcbc_enc,read_pwd,rpc_enc,cbc_cksm,supp"
169$!
170$! Define A File Counter And Set It To "0".
171$!
172$ FILE_COUNTER = 0
173$!
174$! Top Of The File Loop.
175$!
176$ NEXT_FILE:
177$!
178$! O.K, Extract The File Name From The File List.
179$!
180$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",LIB_DES)
181$!
182$! Check To See If We Are At The End Of The File List.
183$!
184$ IF (FILE_NAME.EQS.",") THEN GOTO FILE_DONE
185$!
186$! Increment The Counter.
187$!
188$ FILE_COUNTER = FILE_COUNTER + 1
189$!
190$! Create The Source File Name.
191$!
192$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME + ".C"
193$!
194$! Tell The User We Are Compiling The Source File.
195$!
196$ WRITE SYS$OUTPUT " ",FILE_NAME,".C"
197$!
198$! Create The Object File Name.
199$!
200$ OBJECT_FILE = OBJ_DIR + FILE_NAME + "." + ARCH + "OBJ"
201$ ON WARNING THEN GOTO NEXT_FILE
202$!
203$! Check To See If The File We Want To Compile Actually Exists.
204$!
205$ IF (F$SEARCH(SOURCE_FILE).EQS."")
206$ THEN
207$!
208$! Tell The User That The File Dosen't Exist.
209$!
210$ WRITE SYS$OUTPUT ""
211$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
212$ WRITE SYS$OUTPUT ""
213$!
214$! Exit The Build.
215$!
216$ EXIT
217$!
218$! End The File Exists Check.
219$!
220$ ENDIF
221$!
222$! Compile The File.
223$!
224$ ON ERROR THEN GOTO NEXT_FILE
225$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
226$!
227$! Add It To The Library.
228$!
229$ LIBRARY/REPLACE/OBJECT 'LIB_NAME' 'OBJECT_FILE'
230$!
231$! Time To Clean Up The Object File.
232$!
233$ DELETE 'OBJECT_FILE';*
234$!
235$! Go Back And Do It Again.
236$!
237$ GOTO NEXT_FILE
238$!
239$! All Done With This Library Part.
240$!
241$ FILE_DONE:
242$!
243$! Tell The User That We Are All Done.
244$!
245$ WRITE SYS$OUTPUT "Library ",LIB_NAME," Built."
246$!
247$! All Done, Time To Return.
248$!
249$ RETURN
250$!
251$! Compile The DESTEST Program.
252$!
253$ DESTEST:
254$!
255$! Check To See If We Have The Proper Libraries.
256$!
257$ GOSUB LIB_CHECK
258$!
259$! Check To See If We Have A Linker Option File.
260$!
261$ GOSUB CHECK_OPT_FILE
262$!
263$! Check To See If The File We Want To Compile Actually Exists.
264$!
265$ IF (F$SEARCH("SYS$DISK:[]DESTEST.C").EQS."")
266$ THEN
267$!
268$! Tell The User That The File Dosen't Exist.
269$!
270$ WRITE SYS$OUTPUT ""
271$ WRITE SYS$OUTPUT "The File DESTEST.C Dosen't Exist."
272$ WRITE SYS$OUTPUT ""
273$!
274$! Exit The Build.
275$!
276$ EXIT
277$!
278$! End The DESTEST.C File Check.
279$!
280$ ENDIF
281$!
282$! Tell The User What We Are Building.
283$!
284$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DESTEST.EXE"
285$!
286$! Compile The DESTEST Program.
287$!
288$ CC/OBJECT='OBJ_DIR'DESTEST.OBJ SYS$DISK:[]DESTEST.C
289$!
290$! Link The DESTEST Program.
291$!
292$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DESTEST.EXE -
293 'OBJ_DIR'DESTEST.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
294$!
295$! All Done, Time To Return.
296$!
297$ RETURN
298$!
299$! Compile The SPEED Program.
300$!
301$ SPEED:
302$!
303$! Check To See If We Have The Proper Libraries.
304$!
305$ GOSUB LIB_CHECK
306$!
307$! Check To See If We Have A Linker Option File.
308$!
309$ GOSUB CHECK_OPT_FILE
310$!
311$! Check To See If The File We Want To Compile Actually Exists.
312$!
313$ IF (F$SEARCH("SYS$DISK:[]SPEED.C").EQS."")
314$ THEN
315$!
316$! Tell The User That The File Dosen't Exist.
317$!
318$ WRITE SYS$OUTPUT ""
319$ WRITE SYS$OUTPUT "The File SPEED.C Dosen't Exist."
320$ WRITE SYS$OUTPUT ""
321$!
322$! Exit The Build.
323$!
324$ EXIT
325$!
326$! End The SPEED.C File Check.
327$!
328$ ENDIF
329$!
330$! Tell The User What We Are Building.
331$!
332$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"SPEED.EXE"
333$!
334$! Compile The SPEED Program.
335$!
336$ CC/OBJECT='OBJ_DIR'SPEED.OBJ SYS$DISK:[]SPEED.C
337$!
338$! Link The SPEED Program.
339$!
340$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'SPEED.EXE -
341 'OBJ_DIR'SPEED.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
342$!
343$! All Done, Time To Return.
344$!
345$ RETURN
346$!
347$! Compile The RPW Program.
348$!
349$ RPW:
350$!
351$! Check To See If We Have The Proper Libraries.
352$!
353$ GOSUB LIB_CHECK
354$!
355$! Check To See If We Have A Linker Option File.
356$!
357$ GOSUB CHECK_OPT_FILE
358$!
359$! Check To See If The File We Want To Compile Actually Exists.
360$!
361$ IF (F$SEARCH("SYS$DISK:[]RPW.C").EQS."")
362$ THEN
363$!
364$! Tell The User That The File Dosen't Exist.
365$!
366$ WRITE SYS$OUTPUT ""
367$ WRITE SYS$OUTPUT "The File RPW.C Dosen't Exist."
368$ WRITE SYS$OUTPUT ""
369$!
370$! Exit The Build.
371$!
372$ EXIT
373$!
374$! End The RPW.C File Check.
375$!
376$ ENDIF
377$!
378$! Tell The User What We Are Building.
379$!
380$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"RPW.EXE"
381$!
382$! Compile The RPW Program.
383$!
384$ CC/OBJECT='OBJ_DIR'RPW.OBJ SYS$DISK:[]RPW.C
385$!
386$! Link The RPW Program.
387$!
388$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'RPW.EXE -
389 'OBJ_DIR'RPW.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
390$!
391$! All Done, Time To Return.
392$!
393$ RETURN
394$!
395$! Compile The DES Program.
396$!
397$ DES:
398$!
399$! Check To See If We Have The Proper Libraries.
400$!
401$ GOSUB LIB_CHECK
402$!
403$! Check To See If We Have A Linker Option File.
404$!
405$ GOSUB CHECK_OPT_FILE
406$!
407$! Check To See If The File We Want To Compile Actually Exists.
408$!
409$ IF (F$SEARCH("SYS$DISK:[]DES.C").EQS."")
410$ THEN
411$!
412$! Tell The User That The File Dosen't Exist.
413$!
414$ WRITE SYS$OUTPUT ""
415$ WRITE SYS$OUTPUT "The File DES.C Dosen't Exist."
416$ WRITE SYS$OUTPUT ""
417$!
418$! Exit The Build.
419$!
420$ EXIT
421$!
422$! End The DES.C File Check.
423$!
424$ ENDIF
425$!
426$! Tell The User What We Are Building.
427$!
428$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES.EXE"
429$!
430$! Compile The DES Program.
431$!
432$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]DES.C
433$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]CBC3_ENC.C
434$!
435$! Link The DES Program.
436$!
437$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES.EXE -
438 'OBJ_DIR'DES.OBJ,'OBJ_DIR'CBC3_ENC.OBJ,-
439 'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
440$!
441$! All Done, Time To Return.
442$!
443$ RETURN
444$!
445$! Compile The DES_OPTS Program.
446$!
447$ DES_OPTS:
448$!
449$! Check To See If We Have The Proper Libraries.
450$!
451$ GOSUB LIB_CHECK
452$!
453$! Check To See If We Have A Linker Option File.
454$!
455$ GOSUB CHECK_OPT_FILE
456$!
457$! Check To See If The File We Want To Compile Actually Exists.
458$!
459$ IF (F$SEARCH("SYS$DISK:[]DES_OPTS.C").EQS."")
460$ THEN
461$!
462$! Tell The User That The File Dosen't Exist.
463$!
464$ WRITE SYS$OUTPUT ""
465$ WRITE SYS$OUTPUT "The File DES_OPTS.C Dosen't Exist."
466$ WRITE SYS$OUTPUT ""
467$!
468$! Exit The Build.
469$!
470$ EXIT
471$!
472$! End The DES_OPTS.C File Check.
473$!
474$ ENDIF
475$!
476$! Tell The User What We Are Building.
477$!
478$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES_OPTS.EXE"
479$!
480$! Compile The DES_OPTS Program.
481$!
482$ CC/OBJECT='OBJ_DIR'DES_OPTS.OBJ SYS$DISK:[]DES_OPTS.C
483$!
484$! Link The DES_OPTS Program.
485$!
486$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES_OPTS.EXE -
487 'OBJ_DIR'DES_OPTS.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
488$!
489$! All Done, Time To Return.
490$!
491$ RETURN
492$ EXIT
493$!
494$! Check For The Link Option FIle.
495$!
496$ CHECK_OPT_FILE:
497$!
498$! Check To See If We Need To Make A VAX C Option File.
499$!
500$ IF (COMPILER.EQS."VAXC")
501$ THEN
502$!
503$! Check To See If We Already Have A VAX C Linker Option File.
504$!
505$ IF (F$SEARCH(OPT_FILE).EQS."")
506$ THEN
507$!
508$! We Need A VAX C Linker Option File.
509$!
510$ CREATE 'OPT_FILE'
511$DECK
512!
513! Default System Options File To Link Agianst
514! The Sharable VAX C Runtime Library.
515!
516SYS$SHARE:VAXCRTL.EXE/SHARE
517$EOD
518$!
519$! End The Option File Check.
520$!
521$ ENDIF
522$!
523$! End The VAXC Check.
524$!
525$ ENDIF
526$!
527$! Check To See If We Need A GNU C Option File.
528$!
529$ IF (COMPILER.EQS."GNUC")
530$ THEN
531$!
532$! Check To See If We Already Have A GNU C Linker Option File.
533$!
534$ IF (F$SEARCH(OPT_FILE).EQS."")
535$ THEN
536$!
537$! We Need A GNU C Linker Option File.
538$!
539$ CREATE 'OPT_FILE'
540$DECK
541!
542! Default System Options File To Link Agianst
543! The Sharable C Runtime Library.
544!
545GNU_CC:[000000]GCCLIB/LIBRARY
546SYS$SHARE:VAXCRTL/SHARE
547$EOD
548$!
549$! End The Option File Check.
550$!
551$ ENDIF
552$!
553$! End The GNU C Check.
554$!
555$ ENDIF
556$!
557$! Check To See If We Need A DEC C Option File.
558$!
559$ IF (COMPILER.EQS."DECC")
560$ THEN
561$!
562$! Check To See If We Already Have A DEC C Linker Option File.
563$!
564$ IF (F$SEARCH(OPT_FILE).EQS."")
565$ THEN
566$!
567$! Figure Out If We Need An AXP Or A VAX Linker Option File.
568$!
569$ IF (F$GETSYI("CPU").LT.128)
570$ THEN
571$!
572$! We Need A DEC C Linker Option File For VAX.
573$!
574$ CREATE 'OPT_FILE'
575$DECK
576!
577! Default System Options File To Link Agianst
578! The Sharable DEC C Runtime Library.
579!
580SYS$SHARE:DECC$SHR.EXE/SHARE
581$EOD
582$!
583$! Else...
584$!
585$ ELSE
586$!
587$! Create The AXP Linker Option File.
588$!
589$ CREATE 'OPT_FILE'
590$DECK
591!
592! Default System Options File For AXP To Link Agianst
593! The Sharable C Runtime Library.
594!
595SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
596SYS$SHARE:CMA$OPEN_RTL/SHARE
597$EOD
598$!
599$! End The VAX/AXP DEC C Option File Check.
600$!
601$ ENDIF
602$!
603$! End The Option File Search.
604$!
605$ ENDIF
606$!
607$! End The DEC C Check.
608$!
609$ ENDIF
610$!
611$! Tell The User What Linker Option File We Are Using.
612$!
613$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
614$!
615$! Time To RETURN.
616$!
617$ RETURN
618$!
619$! Library Check.
620$!
621$ LIB_CHECK:
622$!
623$! Look For The Library LIBDES.OLB.
624$!
625$ IF (F$SEARCH(LIB_NAME).EQS."")
626$ THEN
627$!
628$! Tell The User We Can't Find The [.xxx.CRYPTO.DES]LIBDES.OLB Library.
629$!
630$ WRITE SYS$OUTPUT ""
631$ WRITE SYS$OUTPUT "Can't Find The Library ",LIB_NAME,"."
632$ WRITE SYS$OUTPUT "We Can't Link Without It."
633$ WRITE SYS$OUTPUT ""
634$!
635$! Since We Can't Link Without It, Exit.
636$!
637$ EXIT
638$ ENDIF
639$!
640$! Time To Return.
641$!
642$ RETURN
643$!
644$! Check The User's Options.
645$!
646$ CHECK_OPTIONS:
647$!
648$! Check To See If We Are To "Just Build Everything".
649$!
650$ IF (P1.EQS."ALL")
651$ THEN
652$!
653$! P1 Is "ALL", So Build Everything.
654$!
655$ BUILDALL = "TRUE"
656$!
657$! Else...
658$!
659$ ELSE
660$!
661$! Else, Check To See If P1 Has A Valid Arguement.
662$!
663$ IF (P1.EQS."LIBRARY").OR.(P1.EQS."DESTEST").OR.(P1.EQS."SPEED") -
664 .OR.(P1.EQS."RPW").OR.(P1.EQS."DES").OR.(P1.EQS."DES_OPTS")
665$ THEN
666$!
667$! A Valid Arguement.
668$!
669$ BUILDALL = P1
670$!
671$! Else...
672$!
673$ ELSE
674$!
675$! Tell The User We Don't Know What They Want.
676$!
677$ WRITE SYS$OUTPUT ""
678$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
679$ WRITE SYS$OUTPUT ""
680$ WRITE SYS$OUTPUT " ALL : Just Build Everything.
681$ WRITE SYS$OUTPUT " LIBRARY : To Compile Just The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library."
682$ WRITE SYS$OUTPUT " DESTEST : To Compile Just The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program."
683$ WRITE SYS$OUTPUT " SPEED : To Compile Just The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program."
684$ WRITE SYS$OUTPUT " RPW : To Compile Just The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program."
685$ WRITE SYS$OUTPUT " DES : To Compile Just The [.xxx.EXE.CRYPTO.DES]DES.EXE Program."
686$ WRITE SYS$OUTPUT " DES_OPTS : To Compile Just The [.xxx.EXE.CRYTPO.DES]DES_OPTS.EXE Program."
687$ WRITE SYS$OUTPUT ""
688$ WRITE SYS$OUTPUT " Where 'xxx' Stands For: "
689$ WRITE SYS$OUTPUT ""
690$ WRITE SYS$OUTPUT " AXP : Alpha Architecture."
691$ WRITE SYS$OUTPUT " VAX : VAX Architecture."
692$ WRITE SYS$OUTPUT ""
693$!
694$! Time To EXIT.
695$!
696$ EXIT
697$!
698$! End The Valid Arguement Check.
699$!
700$ ENDIF
701$!
702$! End The P1 Check.
703$!
704$ ENDIF
705$!
706$! Check To See If We Are To Compile Without Debugger Information.
707$!
708$ IF (P2.EQS."NODEBUG")
709$ THEN
710$!
711$! P2 Is Blank, So Compile Without Debugger Information.
712$!
713$ DEBUGGER = "NODEBUG"
714$ TRACEBACK = "NOTRACEBACK"
715$ GCC_OPTIMIZE = "OPTIMIZE"
716$ CC_OPTIMIZE = "OPTIMIZE"
717$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
718$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
719$!
720$! Else...
721$!
722$ ELSE
723$!
724$! Check To See If We Are To Compile With Debugger Information.
725$!
726$ IF (P2.EQS."DEBUG")
727$ THEN
728$!
729$! Compile With Debugger Information.
730$!
731$ DEBUGGER = "DEBUG"
732$ TRACEBACK = "TRACEBACK"
733$ GCC_OPTIMIZE = "NOOPTIMIZE"
734$ CC_OPTIMIZE = "NOOPTIMIZE"
735$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
736$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
737$!
738$! Else...
739$!
740$ ELSE
741$!
742$! Tell The User Entered An Invalid Option..
743$!
744$ WRITE SYS$OUTPUT ""
745$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
746$ WRITE SYS$OUTPUT ""
747$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
748$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
749$ WRITE SYS$OUTPUT ""
750$!
751$! Time To EXIT.
752$!
753$ EXIT
754$!
755$! End The Valid Arguement Check.
756$!
757$ ENDIF
758$!
759$! End The P2 Check.
760$!
761$ ENDIF
762$!
763$! Special Threads For OpenVMS v7.1 Or Later.
764$!
765$! Written By: Richard Levitte
766$! richard@levitte.org
767$!
768$!
769$! Check To See If We Have A Option For P4.
770$!
771$ IF (P4.EQS."")
772$ THEN
773$!
774$! Get The Version Of VMS We Are Using.
775$!
776$ ISSEVEN := ""
777$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
778$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
779$!
780$! Check To See If The VMS Version Is v7.1 Or Later.
781$!
782$ IF (TMP.GE.71)
783$ THEN
784$!
785$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
786$!
787$ ISSEVEN := ,PTHREAD_USE_D4
788$!
789$! End The VMS Version Check.
790$!
791$ ENDIF
792$!
793$! End The P4 Check.
794$!
795$ ENDIF
796$!
797$! Check To See If P3 Is Blank.
798$!
799$ IF (P3.EQS."")
800$ THEN
801$!
802$! O.K., The User Didn't Specify A Compiler, Let's Try To
803$! Find Out Which One To Use.
804$!
805$! Check To See If We Have GNU C.
806$!
807$ IF (F$TRNLNM("GNU_CC").NES."")
808$ THEN
809$!
810$! Looks Like GNUC, Set To Use GNUC.
811$!
812$ P3 = "GNUC"
813$!
814$! Else...
815$!
816$ ELSE
817$!
818$! Check To See If We Have VAXC Or DECC.
819$!
820$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
821$ THEN
822$!
823$! Looks Like DECC, Set To Use DECC.
824$!
825$ P3 = "DECC"
826$!
827$! Else...
828$!
829$ ELSE
830$!
831$! Looks Like VAXC, Set To Use VAXC.
832$!
833$ P3 = "VAXC"
834$!
835$! End The VAXC Compiler Check.
836$!
837$ ENDIF
838$!
839$! End The DECC & VAXC Compiler Check.
840$!
841$ ENDIF
842$!
843$! End The Compiler Check.
844$!
845$ ENDIF
846$!
847$! Set Up Initial CC Definitions, Possibly With User Ones
848$!
849$ CCDEFS = ""
850$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = USER_CCDEFS
851$ CCEXTRAFLAGS = ""
852$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
853$ CCDISABLEWARNINGS = ""
854$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
855 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS
856$!
857$! Check To See If The User Entered A Valid Paramter.
858$!
859$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
860$ THEN
861$!
862$! Check To See If The User Wanted DECC.
863$!
864$ IF (P3.EQS."DECC")
865$ THEN
866$!
867$! Looks Like DECC, Set To Use DECC.
868$!
869$ COMPILER = "DECC"
870$!
871$! Tell The User We Are Using DECC.
872$!
873$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
874$!
875$! Use DECC...
876$!
877$ CC = "CC"
878$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
879 THEN CC = "CC/DECC"
880$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
881 "/NOLIST/PREFIX=ALL" + CCEXTRAFLAGS
882$!
883$! Define The Linker Options File Name.
884$!
885$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
886$!
887$! End DECC Check.
888$!
889$ ENDIF
890$!
891$! Check To See If We Are To Use VAXC.
892$!
893$ IF (P3.EQS."VAXC")
894$ THEN
895$!
896$! Looks Like VAXC, Set To Use VAXC.
897$!
898$ COMPILER = "VAXC"
899$!
900$! Tell The User We Are Using VAX C.
901$!
902$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
903$!
904$! Compile Using VAXC.
905$!
906$ CC = "CC"
907$ IF ARCH.EQS."AXP"
908$ THEN
909$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
910$ EXIT
911$ ENDIF
912$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
913$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
914$ CCDEFS = """VAXC""," + CCDEFS
915$!
916$! Define <sys> As SYS$COMMON:[SYSLIB]
917$!
918$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
919$!
920$! Define The Linker Options File Name.
921$!
922$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
923$!
924$! End VAXC Check
925$!
926$ ENDIF
927$!
928$! Check To See If We Are To Use GNU C.
929$!
930$ IF (P3.EQS."GNUC")
931$ THEN
932$!
933$! Looks Like GNUC, Set To Use GNUC.
934$!
935$ COMPILER = "GNUC"
936$!
937$! Tell The User We Are Using GNUC.
938$!
939$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
940$!
941$! Use GNU C...
942$!
943$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
944$!
945$! Define The Linker Options File Name.
946$!
947$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
948$!
949$! End The GNU C Check.
950$!
951$ ENDIF
952$!
953$! Set up default defines
954$!
955$ CCDEFS = """FLAT_INC=1""," + CCDEFS
956$!
957$! Finish up the definition of CC.
958$!
959$ IF COMPILER .EQS. "DECC"
960$ THEN
961$ IF CCDISABLEWARNINGS .EQS. ""
962$ THEN
963$ CC4DISABLEWARNINGS = "DOLLARID"
964$ ELSE
965$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
966$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
967$ ENDIF
968$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
969$ ELSE
970$ CCDISABLEWARNINGS = ""
971$ CC4DISABLEWARNINGS = ""
972$ ENDIF
973$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
974$!
975$! Show user the result
976$!
977$ WRITE SYS$OUTPUT "Main Compiling Command: ",CC
978$!
979$! Else The User Entered An Invalid Arguement.
980$!
981$ ELSE
982$!
983$! Tell The User We Don't Know What They Want.
984$!
985$ WRITE SYS$OUTPUT ""
986$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
987$ WRITE SYS$OUTPUT ""
988$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
989$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
990$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
991$ WRITE SYS$OUTPUT ""
992$!
993$! Time To EXIT.
994$!
995$ EXIT
996$!
997$! End The P3 Check.
998$!
999$ ENDIF
1000$!
1001$! Time To RETURN...
1002$!
1003$ RETURN
diff --git a/src/lib/libcrypto/des/des.c b/src/lib/libcrypto/des/des.c
new file mode 100644
index 0000000000..343135ff9e
--- /dev/null
+++ b/src/lib/libcrypto/des/des.c
@@ -0,0 +1,932 @@
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#include <string.h>
62#include <openssl/opensslconf.h>
63#ifndef OPENSSL_SYS_MSDOS
64#ifndef OPENSSL_SYS_VMS
65#include OPENSSL_UNISTD
66#else /* OPENSSL_SYS_VMS */
67#ifdef __DECC
68#include <unistd.h>
69#else /* not __DECC */
70#include <math.h>
71#endif /* __DECC */
72#endif /* OPENSSL_SYS_VMS */
73#else /* OPENSSL_SYS_MSDOS */
74#include <io.h>
75#endif
76
77#include <time.h>
78#include "des_ver.h"
79
80#ifdef OPENSSL_SYS_VMS
81#include <types.h>
82#include <stat.h>
83#else
84#ifndef _IRIX
85#include <sys/types.h>
86#endif
87#include <sys/stat.h>
88#endif
89#include <openssl/des.h>
90#include <openssl/rand.h>
91#include <openssl/ui_compat.h>
92
93void usage(void);
94void doencryption(void);
95int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp);
96void uufwriteEnd(FILE *fp);
97int uufread(unsigned char *out,int size,unsigned int num,FILE *fp);
98int uuencode(unsigned char *in,int num,unsigned char *out);
99int uudecode(unsigned char *in,int num,unsigned char *out);
100void DES_3cbc_encrypt(DES_cblock *input,DES_cblock *output,long length,
101 DES_key_schedule sk1,DES_key_schedule sk2,
102 DES_cblock *ivec1,DES_cblock *ivec2,int enc);
103#ifdef OPENSSL_SYS_VMS
104#define EXIT(a) exit(a&0x10000000L)
105#else
106#define EXIT(a) exit(a)
107#endif
108
109#define BUFSIZE (8*1024)
110#define VERIFY 1
111#define KEYSIZ 8
112#define KEYSIZB 1024 /* should hit tty line limit first :-) */
113char key[KEYSIZB+1];
114int do_encrypt,longk=0;
115FILE *DES_IN,*DES_OUT,*CKSUM_OUT;
116char uuname[200];
117unsigned char uubuf[50];
118int uubufnum=0;
119#define INUUBUFN (45*100)
120#define OUTUUBUF (65*100)
121unsigned char b[OUTUUBUF];
122unsigned char bb[300];
123DES_cblock cksum={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
124char cksumname[200]="";
125
126int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error;
127
128int main(int argc, char **argv)
129 {
130 int i;
131 struct stat ins,outs;
132 char *p;
133 char *in=NULL,*out=NULL;
134
135 vflag=cflag=eflag=dflag=kflag=hflag=bflag=fflag=sflag=uflag=flag3=0;
136 error=0;
137 memset(key,0,sizeof(key));
138
139 for (i=1; i<argc; i++)
140 {
141 p=argv[i];
142 if ((p[0] == '-') && (p[1] != '\0'))
143 {
144 p++;
145 while (*p)
146 {
147 switch (*(p++))
148 {
149 case '3':
150 flag3=1;
151 longk=1;
152 break;
153 case 'c':
154 cflag=1;
155 strncpy(cksumname,p,200);
156 cksumname[sizeof(cksumname)-1]='\0';
157 p+=strlen(cksumname);
158 break;
159 case 'C':
160 cflag=1;
161 longk=1;
162 strncpy(cksumname,p,200);
163 cksumname[sizeof(cksumname)-1]='\0';
164 p+=strlen(cksumname);
165 break;
166 case 'e':
167 eflag=1;
168 break;
169 case 'v':
170 vflag=1;
171 break;
172 case 'E':
173 eflag=1;
174 longk=1;
175 break;
176 case 'd':
177 dflag=1;
178 break;
179 case 'D':
180 dflag=1;
181 longk=1;
182 break;
183 case 'b':
184 bflag=1;
185 break;
186 case 'f':
187 fflag=1;
188 break;
189 case 's':
190 sflag=1;
191 break;
192 case 'u':
193 uflag=1;
194 strncpy(uuname,p,200);
195 uuname[sizeof(uuname)-1]='\0';
196 p+=strlen(uuname);
197 break;
198 case 'h':
199 hflag=1;
200 break;
201 case 'k':
202 kflag=1;
203 if ((i+1) == argc)
204 {
205 fputs("must have a key with the -k option\n",stderr);
206 error=1;
207 }
208 else
209 {
210 int j;
211
212 i++;
213 strncpy(key,argv[i],KEYSIZB);
214 for (j=strlen(argv[i])-1; j>=0; j--)
215 argv[i][j]='\0';
216 }
217 break;
218 default:
219 fprintf(stderr,"'%c' unknown flag\n",p[-1]);
220 error=1;
221 break;
222 }
223 }
224 }
225 else
226 {
227 if (in == NULL)
228 in=argv[i];
229 else if (out == NULL)
230 out=argv[i];
231 else
232 error=1;
233 }
234 }
235 if (error) usage();
236 /* We either
237 * do checksum or
238 * do encrypt or
239 * do decrypt or
240 * do decrypt then ckecksum or
241 * do checksum then encrypt
242 */
243 if (((eflag+dflag) == 1) || cflag)
244 {
245 if (eflag) do_encrypt=DES_ENCRYPT;
246 if (dflag) do_encrypt=DES_DECRYPT;
247 }
248 else
249 {
250 if (vflag)
251 {
252#ifndef _Windows
253 fprintf(stderr,"des(1) built with %s\n",libdes_version);
254#endif
255 EXIT(1);
256 }
257 else usage();
258 }
259
260#ifndef _Windows
261 if (vflag) fprintf(stderr,"des(1) built with %s\n",libdes_version);
262#endif
263 if ( (in != NULL) &&
264 (out != NULL) &&
265#ifndef OPENSSL_SYS_MSDOS
266 (stat(in,&ins) != -1) &&
267 (stat(out,&outs) != -1) &&
268 (ins.st_dev == outs.st_dev) &&
269 (ins.st_ino == outs.st_ino))
270#else /* OPENSSL_SYS_MSDOS */
271 (strcmp(in,out) == 0))
272#endif
273 {
274 fputs("input and output file are the same\n",stderr);
275 EXIT(3);
276 }
277
278 if (!kflag)
279 if (des_read_pw_string(key,KEYSIZB+1,"Enter key:",eflag?VERIFY:0))
280 {
281 fputs("password error\n",stderr);
282 EXIT(2);
283 }
284
285 if (in == NULL)
286 DES_IN=stdin;
287 else if ((DES_IN=fopen(in,"r")) == NULL)
288 {
289 perror("opening input file");
290 EXIT(4);
291 }
292
293 CKSUM_OUT=stdout;
294 if (out == NULL)
295 {
296 DES_OUT=stdout;
297 CKSUM_OUT=stderr;
298 }
299 else if ((DES_OUT=fopen(out,"w")) == NULL)
300 {
301 perror("opening output file");
302 EXIT(5);
303 }
304
305#ifdef OPENSSL_SYS_MSDOS
306 /* This should set the file to binary mode. */
307 {
308#include <fcntl.h>
309 if (!(uflag && dflag))
310 setmode(fileno(DES_IN),O_BINARY);
311 if (!(uflag && eflag))
312 setmode(fileno(DES_OUT),O_BINARY);
313 }
314#endif
315
316 doencryption();
317 fclose(DES_IN);
318 fclose(DES_OUT);
319 EXIT(0);
320 }
321
322void usage(void)
323 {
324 char **u;
325 static const char *Usage[]={
326"des <options> [input-file [output-file]]",
327"options:",
328"-v : des(1) version number",
329"-e : encrypt using SunOS compatible user key to DES key conversion.",
330"-E : encrypt ",
331"-d : decrypt using SunOS compatible user key to DES key conversion.",
332"-D : decrypt ",
333"-c[ckname] : generate a cbc_cksum using SunOS compatible user key to",
334" DES key conversion and output to ckname (stdout default,",
335" stderr if data being output on stdout). The checksum is",
336" generated before encryption and after decryption if used",
337" in conjunction with -[eEdD].",
338"-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].",
339"-k key : use key 'key'",
340"-h : the key that is entered will be a hexadecimal number",
341" that is used directly as the des key",
342"-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]",
343" (uuname is the filename to put in the uuencode header).",
344"-b : encrypt using DES in ecb encryption mode, the default is cbc mode.",
345"-3 : encrypt using triple DES encryption. This uses 2 keys",
346" generated from the input key. If the input key is less",
347" than 8 characters long, this is equivalent to normal",
348" encryption. Default is triple cbc, -b makes it triple ecb.",
349NULL
350};
351 for (u=(char **)Usage; *u; u++)
352 {
353 fputs(*u,stderr);
354 fputc('\n',stderr);
355 }
356
357 EXIT(1);
358 }
359
360void doencryption(void)
361 {
362#ifdef _LIBC
363 extern unsigned long time();
364#endif
365
366 register int i;
367 DES_key_schedule ks,ks2;
368 DES_cblock iv,iv2;
369 char *p;
370 int num=0,j,k,l,rem,ll,len,last,ex=0;
371 DES_cblock kk,k2;
372 FILE *O;
373 int Exit=0;
374#ifndef OPENSSL_SYS_MSDOS
375 static unsigned char buf[BUFSIZE+8],obuf[BUFSIZE+8];
376#else
377 static unsigned char *buf=NULL,*obuf=NULL;
378
379 if (buf == NULL)
380 {
381 if ( (( buf=OPENSSL_malloc(BUFSIZE+8)) == NULL) ||
382 ((obuf=OPENSSL_malloc(BUFSIZE+8)) == NULL))
383 {
384 fputs("Not enough memory\n",stderr);
385 Exit=10;
386 goto problems;
387 }
388 }
389#endif
390
391 if (hflag)
392 {
393 j=(flag3?16:8);
394 p=key;
395 for (i=0; i<j; i++)
396 {
397 k=0;
398 if ((*p <= '9') && (*p >= '0'))
399 k=(*p-'0')<<4;
400 else if ((*p <= 'f') && (*p >= 'a'))
401 k=(*p-'a'+10)<<4;
402 else if ((*p <= 'F') && (*p >= 'A'))
403 k=(*p-'A'+10)<<4;
404 else
405 {
406 fputs("Bad hex key\n",stderr);
407 Exit=9;
408 goto problems;
409 }
410 p++;
411 if ((*p <= '9') && (*p >= '0'))
412 k|=(*p-'0');
413 else if ((*p <= 'f') && (*p >= 'a'))
414 k|=(*p-'a'+10);
415 else if ((*p <= 'F') && (*p >= 'A'))
416 k|=(*p-'A'+10);
417 else
418 {
419 fputs("Bad hex key\n",stderr);
420 Exit=9;
421 goto problems;
422 }
423 p++;
424 if (i < 8)
425 kk[i]=k;
426 else
427 k2[i-8]=k;
428 }
429 DES_set_key_unchecked(&k2,&ks2);
430 OPENSSL_cleanse(k2,sizeof(k2));
431 }
432 else if (longk || flag3)
433 {
434 if (flag3)
435 {
436 DES_string_to_2keys(key,&kk,&k2);
437 DES_set_key_unchecked(&k2,&ks2);
438 OPENSSL_cleanse(k2,sizeof(k2));
439 }
440 else
441 DES_string_to_key(key,&kk);
442 }
443 else
444 for (i=0; i<KEYSIZ; i++)
445 {
446 l=0;
447 k=key[i];
448 for (j=0; j<8; j++)
449 {
450 if (k&1) l++;
451 k>>=1;
452 }
453 if (l & 1)
454 kk[i]=key[i]&0x7f;
455 else
456 kk[i]=key[i]|0x80;
457 }
458
459 DES_set_key_unchecked(&kk,&ks);
460 OPENSSL_cleanse(key,sizeof(key));
461 OPENSSL_cleanse(kk,sizeof(kk));
462 /* woops - A bug that does not showup under unix :-( */
463 memset(iv,0,sizeof(iv));
464 memset(iv2,0,sizeof(iv2));
465
466 l=1;
467 rem=0;
468 /* first read */
469 if (eflag || (!dflag && cflag))
470 {
471 for (;;)
472 {
473 num=l=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
474 l+=rem;
475 num+=rem;
476 if (l < 0)
477 {
478 perror("read error");
479 Exit=6;
480 goto problems;
481 }
482
483 rem=l%8;
484 len=l-rem;
485 if (feof(DES_IN))
486 {
487 for (i=7-rem; i>0; i--)
488 RAND_pseudo_bytes(buf + l++, 1);
489 buf[l++]=rem;
490 ex=1;
491 len+=rem;
492 }
493 else
494 l-=rem;
495
496 if (cflag)
497 {
498 DES_cbc_cksum(buf,&cksum,
499 (long)len,&ks,&cksum);
500 if (!eflag)
501 {
502 if (feof(DES_IN)) break;
503 else continue;
504 }
505 }
506
507 if (bflag && !flag3)
508 for (i=0; i<l; i+=8)
509 DES_ecb_encrypt(
510 (DES_cblock *)&(buf[i]),
511 (DES_cblock *)&(obuf[i]),
512 &ks,do_encrypt);
513 else if (flag3 && bflag)
514 for (i=0; i<l; i+=8)
515 DES_ecb2_encrypt(
516 (DES_cblock *)&(buf[i]),
517 (DES_cblock *)&(obuf[i]),
518 &ks,&ks2,do_encrypt);
519 else if (flag3 && !bflag)
520 {
521 char tmpbuf[8];
522
523 if (rem) memcpy(tmpbuf,&(buf[l]),
524 (unsigned int)rem);
525 DES_3cbc_encrypt(
526 (DES_cblock *)buf,(DES_cblock *)obuf,
527 (long)l,ks,ks2,&iv,
528 &iv2,do_encrypt);
529 if (rem) memcpy(&(buf[l]),tmpbuf,
530 (unsigned int)rem);
531 }
532 else
533 {
534 DES_cbc_encrypt(
535 buf,obuf,
536 (long)l,&ks,&iv,do_encrypt);
537 if (l >= 8) memcpy(iv,&(obuf[l-8]),8);
538 }
539 if (rem) memcpy(buf,&(buf[l]),(unsigned int)rem);
540
541 i=0;
542 while (i < l)
543 {
544 if (uflag)
545 j=uufwrite(obuf,1,(unsigned int)l-i,
546 DES_OUT);
547 else
548 j=fwrite(obuf,1,(unsigned int)l-i,
549 DES_OUT);
550 if (j == -1)
551 {
552 perror("Write error");
553 Exit=7;
554 goto problems;
555 }
556 i+=j;
557 }
558 if (feof(DES_IN))
559 {
560 if (uflag) uufwriteEnd(DES_OUT);
561 break;
562 }
563 }
564 }
565 else /* decrypt */
566 {
567 ex=1;
568 for (;;)
569 {
570 if (ex) {
571 if (uflag)
572 l=uufread(buf,1,BUFSIZE,DES_IN);
573 else
574 l=fread(buf,1,BUFSIZE,DES_IN);
575 ex=0;
576 rem=l%8;
577 l-=rem;
578 }
579 if (l < 0)
580 {
581 perror("read error");
582 Exit=6;
583 goto problems;
584 }
585
586 if (bflag && !flag3)
587 for (i=0; i<l; i+=8)
588 DES_ecb_encrypt(
589 (DES_cblock *)&(buf[i]),
590 (DES_cblock *)&(obuf[i]),
591 &ks,do_encrypt);
592 else if (flag3 && bflag)
593 for (i=0; i<l; i+=8)
594 DES_ecb2_encrypt(
595 (DES_cblock *)&(buf[i]),
596 (DES_cblock *)&(obuf[i]),
597 &ks,&ks2,do_encrypt);
598 else if (flag3 && !bflag)
599 {
600 DES_3cbc_encrypt(
601 (DES_cblock *)buf,(DES_cblock *)obuf,
602 (long)l,ks,ks2,&iv,
603 &iv2,do_encrypt);
604 }
605 else
606 {
607 DES_cbc_encrypt(
608 buf,obuf,
609 (long)l,&ks,&iv,do_encrypt);
610 if (l >= 8) memcpy(iv,&(buf[l-8]),8);
611 }
612
613 if (uflag)
614 ll=uufread(&(buf[rem]),1,BUFSIZE,DES_IN);
615 else
616 ll=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
617 ll+=rem;
618 rem=ll%8;
619 ll-=rem;
620 if (feof(DES_IN) && (ll == 0))
621 {
622 last=obuf[l-1];
623
624 if ((last > 7) || (last < 0))
625 {
626 fputs("The file was not decrypted correctly.\n",
627 stderr);
628 Exit=8;
629 last=0;
630 }
631 l=l-8+last;
632 }
633 i=0;
634 if (cflag) DES_cbc_cksum(obuf,
635 (DES_cblock *)cksum,(long)l/8*8,&ks,
636 (DES_cblock *)cksum);
637 while (i != l)
638 {
639 j=fwrite(obuf,1,(unsigned int)l-i,DES_OUT);
640 if (j == -1)
641 {
642 perror("Write error");
643 Exit=7;
644 goto problems;
645 }
646 i+=j;
647 }
648 l=ll;
649 if ((l == 0) && feof(DES_IN)) break;
650 }
651 }
652 if (cflag)
653 {
654 l=0;
655 if (cksumname[0] != '\0')
656 {
657 if ((O=fopen(cksumname,"w")) != NULL)
658 {
659 CKSUM_OUT=O;
660 l=1;
661 }
662 }
663 for (i=0; i<8; i++)
664 fprintf(CKSUM_OUT,"%02X",cksum[i]);
665 fprintf(CKSUM_OUT,"\n");
666 if (l) fclose(CKSUM_OUT);
667 }
668problems:
669 OPENSSL_cleanse(buf,sizeof(buf));
670 OPENSSL_cleanse(obuf,sizeof(obuf));
671 OPENSSL_cleanse(&ks,sizeof(ks));
672 OPENSSL_cleanse(&ks2,sizeof(ks2));
673 OPENSSL_cleanse(iv,sizeof(iv));
674 OPENSSL_cleanse(iv2,sizeof(iv2));
675 OPENSSL_cleanse(kk,sizeof(kk));
676 OPENSSL_cleanse(k2,sizeof(k2));
677 OPENSSL_cleanse(uubuf,sizeof(uubuf));
678 OPENSSL_cleanse(b,sizeof(b));
679 OPENSSL_cleanse(bb,sizeof(bb));
680 OPENSSL_cleanse(cksum,sizeof(cksum));
681 if (Exit) EXIT(Exit);
682 }
683
684/* We ignore this parameter but it should be > ~50 I believe */
685int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp)
686 {
687 int i,j,left,rem,ret=num;
688 static int start=1;
689
690 if (start)
691 {
692 fprintf(fp,"begin 600 %s\n",
693 (uuname[0] == '\0')?"text.d":uuname);
694 start=0;
695 }
696
697 if (uubufnum)
698 {
699 if (uubufnum+num < 45)
700 {
701 memcpy(&(uubuf[uubufnum]),data,(unsigned int)num);
702 uubufnum+=num;
703 return(num);
704 }
705 else
706 {
707 i=45-uubufnum;
708 memcpy(&(uubuf[uubufnum]),data,(unsigned int)i);
709 j=uuencode((unsigned char *)uubuf,45,b);
710 fwrite(b,1,(unsigned int)j,fp);
711 uubufnum=0;
712 data+=i;
713 num-=i;
714 }
715 }
716
717 for (i=0; i<(((int)num)-INUUBUFN); i+=INUUBUFN)
718 {
719 j=uuencode(&(data[i]),INUUBUFN,b);
720 fwrite(b,1,(unsigned int)j,fp);
721 }
722 rem=(num-i)%45;
723 left=(num-i-rem);
724 if (left)
725 {
726 j=uuencode(&(data[i]),left,b);
727 fwrite(b,1,(unsigned int)j,fp);
728 i+=left;
729 }
730 if (i != num)
731 {
732 memcpy(uubuf,&(data[i]),(unsigned int)rem);
733 uubufnum=rem;
734 }
735 return(ret);
736 }
737
738void uufwriteEnd(FILE *fp)
739 {
740 int j;
741 static const char *end=" \nend\n";
742
743 if (uubufnum != 0)
744 {
745 uubuf[uubufnum]='\0';
746 uubuf[uubufnum+1]='\0';
747 uubuf[uubufnum+2]='\0';
748 j=uuencode(uubuf,uubufnum,b);
749 fwrite(b,1,(unsigned int)j,fp);
750 }
751 fwrite(end,1,strlen(end),fp);
752 }
753
754/* int size: should always be > ~ 60; I actually ignore this parameter :-) */
755int uufread(unsigned char *out, int size, unsigned int num, FILE *fp)
756 {
757 int i,j,tot;
758 static int done=0;
759 static int valid=0;
760 static int start=1;
761
762 if (start)
763 {
764 for (;;)
765 {
766 b[0]='\0';
767 fgets((char *)b,300,fp);
768 if (b[0] == '\0')
769 {
770 fprintf(stderr,"no 'begin' found in uuencoded input\n");
771 return(-1);
772 }
773 if (strncmp((char *)b,"begin ",6) == 0) break;
774 }
775 start=0;
776 }
777 if (done) return(0);
778 tot=0;
779 if (valid)
780 {
781 memcpy(out,bb,(unsigned int)valid);
782 tot=valid;
783 valid=0;
784 }
785 for (;;)
786 {
787 b[0]='\0';
788 fgets((char *)b,300,fp);
789 if (b[0] == '\0') break;
790 i=strlen((char *)b);
791 if ((b[0] == 'e') && (b[1] == 'n') && (b[2] == 'd'))
792 {
793 done=1;
794 while (!feof(fp))
795 {
796 fgets((char *)b,300,fp);
797 }
798 break;
799 }
800 i=uudecode(b,i,bb);
801 if (i < 0) break;
802 if ((i+tot+8) > num)
803 {
804 /* num to copy to make it a multiple of 8 */
805 j=(num/8*8)-tot-8;
806 memcpy(&(out[tot]),bb,(unsigned int)j);
807 tot+=j;
808 memcpy(bb,&(bb[j]),(unsigned int)i-j);
809 valid=i-j;
810 break;
811 }
812 memcpy(&(out[tot]),bb,(unsigned int)i);
813 tot+=i;
814 }
815 return(tot);
816 }
817
818#define ccc2l(c,l) (l =((DES_LONG)(*((c)++)))<<16, \
819 l|=((DES_LONG)(*((c)++)))<< 8, \
820 l|=((DES_LONG)(*((c)++))))
821
822#define l2ccc(l,c) (*((c)++)=(unsigned char)(((l)>>16)&0xff), \
823 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
824 *((c)++)=(unsigned char)(((l) )&0xff))
825
826
827int uuencode(unsigned char *in, int num, unsigned char *out)
828 {
829 int j,i,n,tot=0;
830 DES_LONG l;
831 register unsigned char *p;
832 p=out;
833
834 for (j=0; j<num; j+=45)
835 {
836 if (j+45 > num)
837 i=(num-j);
838 else i=45;
839 *(p++)=i+' ';
840 for (n=0; n<i; n+=3)
841 {
842 ccc2l(in,l);
843 *(p++)=((l>>18)&0x3f)+' ';
844 *(p++)=((l>>12)&0x3f)+' ';
845 *(p++)=((l>> 6)&0x3f)+' ';
846 *(p++)=((l )&0x3f)+' ';
847 tot+=4;
848 }
849 *(p++)='\n';
850 tot+=2;
851 }
852 *p='\0';
853 l=0;
854 return(tot);
855 }
856
857int uudecode(unsigned char *in, int num, unsigned char *out)
858 {
859 int j,i,k;
860 unsigned int n=0,space=0;
861 DES_LONG l;
862 DES_LONG w,x,y,z;
863 unsigned int blank=(unsigned int)'\n'-' ';
864
865 for (j=0; j<num; )
866 {
867 n= *(in++)-' ';
868 if (n == blank)
869 {
870 n=0;
871 in--;
872 }
873 if (n > 60)
874 {
875 fprintf(stderr,"uuencoded line length too long\n");
876 return(-1);
877 }
878 j++;
879
880 for (i=0; i<n; j+=4,i+=3)
881 {
882 /* the following is for cases where spaces are
883 * removed from lines.
884 */
885 if (space)
886 {
887 w=x=y=z=0;
888 }
889 else
890 {
891 w= *(in++)-' ';
892 x= *(in++)-' ';
893 y= *(in++)-' ';
894 z= *(in++)-' ';
895 }
896 if ((w > 63) || (x > 63) || (y > 63) || (z > 63))
897 {
898 k=0;
899 if (w == blank) k=1;
900 if (x == blank) k=2;
901 if (y == blank) k=3;
902 if (z == blank) k=4;
903 space=1;
904 switch (k) {
905 case 1: w=0; in--;
906 case 2: x=0; in--;
907 case 3: y=0; in--;
908 case 4: z=0; in--;
909 break;
910 case 0:
911 space=0;
912 fprintf(stderr,"bad uuencoded data values\n");
913 w=x=y=z=0;
914 return(-1);
915 break;
916 }
917 }
918 l=(w<<18)|(x<<12)|(y<< 6)|(z );
919 l2ccc(l,out);
920 }
921 if (*(in++) != '\n')
922 {
923 fprintf(stderr,"missing nl in uuencoded line\n");
924 w=x=y=z=0;
925 return(-1);
926 }
927 j++;
928 }
929 *out='\0';
930 w=x=y=z=0;
931 return(n);
932 }
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
index c5df1c9c7b..81bd874edd 100644
--- a/src/lib/libcrypto/des/des.h
+++ b/src/lib/libcrypto/des/des.h
@@ -56,8 +56,8 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef HEADER_NEW_DES_H 59#ifndef HEADER_DES_H
60#define HEADER_NEW_DES_H 60#define HEADER_DES_H
61 61
62#ifdef OPENSSL_NO_DES 62#ifdef OPENSSL_NO_DES
63#error DES is disabled. 63#error DES is disabled.
@@ -71,6 +71,8 @@
71# define OPENSSL_EXTERN OPENSSL_EXPORT 71# define OPENSSL_EXTERN OPENSSL_EXPORT
72#endif 72#endif
73 73
74#define des_SPtrans DES_SPtrans
75
74#ifdef __cplusplus 76#ifdef __cplusplus
75extern "C" { 77extern "C" {
76#endif 78#endif
diff --git a/src/lib/libcrypto/des/des.pod b/src/lib/libcrypto/des/des.pod
new file mode 100644
index 0000000000..bf479e83d2
--- /dev/null
+++ b/src/lib/libcrypto/des/des.pod
@@ -0,0 +1,217 @@
1=pod
2
3=head1 NAME
4
5des - encrypt or decrypt data using Data Encryption Standard
6
7=head1 SYNOPSIS
8
9B<des>
10(
11B<-e>
12|
13B<-E>
14) | (
15B<-d>
16|
17B<-D>
18) | (
19B<->[B<cC>][B<ckname>]
20) |
21[
22B<-b3hfs>
23] [
24B<-k>
25I<key>
26]
27] [
28B<-u>[I<uuname>]
29[
30I<input-file>
31[
32I<output-file>
33] ]
34
35=head1 NOTE
36
37This page describes the B<des> stand-alone program, not the B<openssl des>
38command.
39
40=head1 DESCRIPTION
41
42B<des>
43encrypts and decrypts data using the
44Data Encryption Standard algorithm.
45One of
46B<-e>, B<-E>
47(for encrypt) or
48B<-d>, B<-D>
49(for decrypt) must be specified.
50It is also possible to use
51B<-c>
52or
53B<-C>
54in conjunction or instead of the a encrypt/decrypt option to generate
55a 16 character hexadecimal checksum, generated via the
56I<des_cbc_cksum>.
57
58Two standard encryption modes are supported by the
59B<des>
60program, Cipher Block Chaining (the default) and Electronic Code Book
61(specified with
62B<-b>).
63
64The key used for the DES
65algorithm is obtained by prompting the user unless the
66B<-k>
67I<key>
68option is given.
69If the key is an argument to the
70B<des>
71command, it is potentially visible to users executing
72ps(1)
73or a derivative. To minimise this possibility,
74B<des>
75takes care to destroy the key argument immediately upon entry.
76If your shell keeps a history file be careful to make sure it is not
77world readable.
78
79Since this program attempts to maintain compatibility with sunOS's
80des(1) command, there are 2 different methods used to convert the user
81supplied key to a des key.
82Whenever and one or more of
83B<-E>, B<-D>, B<-C>
84or
85B<-3>
86options are used, the key conversion procedure will not be compatible
87with the sunOS des(1) version but will use all the user supplied
88character to generate the des key.
89B<des>
90command reads from standard input unless
91I<input-file>
92is specified and writes to standard output unless
93I<output-file>
94is given.
95
96=head1 OPTIONS
97
98=over 4
99
100=item B<-b>
101
102Select ECB
103(eight bytes at a time) encryption mode.
104
105=item B<-3>
106
107Encrypt using triple encryption.
108By default triple cbc encryption is used but if the
109B<-b>
110option is used then triple ECB encryption is performed.
111If the key is less than 8 characters long, the flag has no effect.
112
113=item B<-e>
114
115Encrypt data using an 8 byte key in a manner compatible with sunOS
116des(1).
117
118=item B<-E>
119
120Encrypt data using a key of nearly unlimited length (1024 bytes).
121This will product a more secure encryption.
122
123=item B<-d>
124
125Decrypt data that was encrypted with the B<-e> option.
126
127=item B<-D>
128
129Decrypt data that was encrypted with the B<-E> option.
130
131=item B<-c>
132
133Generate a 16 character hexadecimal cbc checksum and output this to
134stderr.
135If a filename was specified after the
136B<-c>
137option, the checksum is output to that file.
138The checksum is generated using a key generated in a sunOS compatible
139manner.
140
141=item B<-C>
142
143A cbc checksum is generated in the same manner as described for the
144B<-c>
145option but the DES key is generated in the same manner as used for the
146B<-E>
147and
148B<-D>
149options
150
151=item B<-f>
152
153Does nothing - allowed for compatibility with sunOS des(1) command.
154
155=item B<-s>
156
157Does nothing - allowed for compatibility with sunOS des(1) command.
158
159=item B<-k> I<key>
160
161Use the encryption
162I<key>
163specified.
164
165=item B<-h>
166
167The
168I<key>
169is assumed to be a 16 character hexadecimal number.
170If the
171B<-3>
172option is used the key is assumed to be a 32 character hexadecimal
173number.
174
175=item B<-u>
176
177This flag is used to read and write uuencoded files. If decrypting,
178the input file is assumed to contain uuencoded, DES encrypted data.
179If encrypting, the characters following the B<-u> are used as the name of
180the uuencoded file to embed in the begin line of the uuencoded
181output. If there is no name specified after the B<-u>, the name text.des
182will be embedded in the header.
183
184=head1 SEE ALSO
185
186ps(1),
187L<des_crypt(3)|des_crypt(3)>
188
189=head1 BUGS
190
191The problem with using the
192B<-e>
193option is the short key length.
194It would be better to use a real 56-bit key rather than an
195ASCII-based 56-bit pattern. Knowing that the key was derived from ASCII
196radically reduces the time necessary for a brute-force cryptographic attack.
197My attempt to remove this problem is to add an alternative text-key to
198DES-key function. This alternative function (accessed via
199B<-E>, B<-D>, B<-S>
200and
201B<-3>)
202uses DES to help generate the key.
203
204Be carefully when using the B<-u> option. Doing B<des -ud> I<filename> will
205not decrypt filename (the B<-u> option will gobble the B<-d> option).
206
207The VMS operating system operates in a world where files are always a
208multiple of 512 bytes. This causes problems when encrypted data is
209send from Unix to VMS since a 88 byte file will suddenly be padded
210with 424 null bytes. To get around this problem, use the B<-u> option
211to uuencode the data before it is send to the VMS system.
212
213=head1 AUTHOR
214
215Eric Young (eay@cryptsoft.com)
216
217=cut
diff --git a/src/lib/libcrypto/des/des3s.cpp b/src/lib/libcrypto/des/des3s.cpp
new file mode 100644
index 0000000000..02d527c057
--- /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 <openssl/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_enc.c b/src/lib/libcrypto/des/des_enc.c
index 72be2d98d7..6a49ec4a55 100644
--- a/src/lib/libcrypto/des/des_enc.c
+++ b/src/lib/libcrypto/des/des_enc.c
@@ -59,6 +59,7 @@
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61#ifndef OPENSSL_FIPS 61#ifndef OPENSSL_FIPS
62#ifndef OPENBSD_DES_ASM
62 63
63void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc) 64void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
64 { 65 {
@@ -248,6 +249,7 @@ void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
248 data[1]=ROTATE(r,3)&0xffffffffL; 249 data[1]=ROTATE(r,3)&0xffffffffL;
249 l=r=t=u=0; 250 l=r=t=u=0;
250 } 251 }
252#endif
251 253
252void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, 254void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
253 DES_key_schedule *ks2, DES_key_schedule *ks3) 255 DES_key_schedule *ks2, DES_key_schedule *ks3)
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
index 8f04b18c50..e44e8e98b2 100644
--- a/src/lib/libcrypto/des/des_locl.h
+++ b/src/lib/libcrypto/des/des_locl.h
@@ -421,7 +421,7 @@
421 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \ 421 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
422 } 422 }
423 423
424extern const DES_LONG DES_SPtrans[8][64]; 424OPENSSL_EXTERN const DES_LONG DES_SPtrans[8][64];
425 425
426void fcrypt_body(DES_LONG *out,DES_key_schedule *ks, 426void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
427 DES_LONG Eswap0, DES_LONG Eswap1); 427 DES_LONG Eswap0, DES_LONG Eswap1);
diff --git a/src/lib/libcrypto/des/des_old.c b/src/lib/libcrypto/des/des_old.c
new file mode 100644
index 0000000000..88e9802aad
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old.c
@@ -0,0 +1,271 @@
1/* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with libdes. OpenSSL now provides
7 * functions where "des_" has been replaced with "DES_" in the names,
8 * to make it possible to make incompatible changes that are needed
9 * for C type security and other stuff.
10 *
11 * Please consider starting to use the DES_ functions rather than the
12 * des_ ones. The des_ functions will dissapear completely before
13 * OpenSSL 1.0!
14 *
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16 */
17
18/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
19 * project 2001.
20 */
21/* ====================================================================
22 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 *
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 *
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 *
36 * 3. All advertising materials mentioning features or use of this
37 * software must display the following acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40 *
41 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42 * endorse or promote products derived from this software without
43 * prior written permission. For written permission, please contact
44 * openssl-core@openssl.org.
45 *
46 * 5. Products derived from this software may not be called "OpenSSL"
47 * nor may "OpenSSL" appear in their names without prior written
48 * permission of the OpenSSL Project.
49 *
50 * 6. Redistributions of any form whatsoever must retain the following
51 * acknowledgment:
52 * "This product includes software developed by the OpenSSL Project
53 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66 * OF THE POSSIBILITY OF SUCH DAMAGE.
67 * ====================================================================
68 *
69 * This product includes cryptographic software written by Eric Young
70 * (eay@cryptsoft.com). This product includes software written by Tim
71 * Hudson (tjh@cryptsoft.com).
72 *
73 */
74
75#define OPENSSL_DES_LIBDES_COMPATIBILITY
76#include <openssl/des.h>
77#include <openssl/rand.h>
78
79const char *_ossl_old_des_options(void)
80 {
81 return DES_options();
82 }
83void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
84 des_key_schedule ks1,des_key_schedule ks2,
85 des_key_schedule ks3, int enc)
86 {
87 DES_ecb3_encrypt((const unsigned char *)input, (unsigned char *)output,
88 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
89 (DES_key_schedule *)ks3, enc);
90 }
91DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
92 long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec)
93 {
94 return DES_cbc_cksum((unsigned char *)input, output, length,
95 (DES_key_schedule *)schedule, ivec);
96 }
97void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
98 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
99 {
100 DES_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
101 length, (DES_key_schedule *)schedule, ivec, enc);
102 }
103void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
104 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
105 {
106 DES_ncbc_encrypt((unsigned char *)input, (unsigned char *)output,
107 length, (DES_key_schedule *)schedule, ivec, enc);
108 }
109void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
110 des_key_schedule schedule,_ossl_old_des_cblock *ivec,
111 _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc)
112 {
113 DES_xcbc_encrypt((unsigned char *)input, (unsigned char *)output,
114 length, (DES_key_schedule *)schedule, ivec, inw, outw, enc);
115 }
116void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
117 long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
118 {
119 DES_cfb_encrypt(in, out, numbits, length,
120 (DES_key_schedule *)schedule, ivec, enc);
121 }
122void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
123 des_key_schedule ks,int enc)
124 {
125 DES_ecb_encrypt(input, output, (DES_key_schedule *)ks, enc);
126 }
127void _ossl_old_des_encrypt(DES_LONG *data,des_key_schedule ks, int enc)
128 {
129 DES_encrypt1(data, (DES_key_schedule *)ks, enc);
130 }
131void _ossl_old_des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc)
132 {
133 DES_encrypt2(data, (DES_key_schedule *)ks, enc);
134 }
135void _ossl_old_des_encrypt3(DES_LONG *data, des_key_schedule ks1,
136 des_key_schedule ks2, des_key_schedule ks3)
137 {
138 DES_encrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
139 (DES_key_schedule *)ks3);
140 }
141void _ossl_old_des_decrypt3(DES_LONG *data, des_key_schedule ks1,
142 des_key_schedule ks2, des_key_schedule ks3)
143 {
144 DES_decrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
145 (DES_key_schedule *)ks3);
146 }
147void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output,
148 long length, des_key_schedule ks1, des_key_schedule ks2,
149 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc)
150 {
151 DES_ede3_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
152 length, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
153 (DES_key_schedule *)ks3, ivec, enc);
154 }
155void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
156 long length, des_key_schedule ks1, des_key_schedule ks2,
157 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc)
158 {
159 DES_ede3_cfb64_encrypt(in, out, length,
160 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
161 (DES_key_schedule *)ks3, ivec, num, enc);
162 }
163void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
164 long length, des_key_schedule ks1, des_key_schedule ks2,
165 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num)
166 {
167 DES_ede3_ofb64_encrypt(in, out, length,
168 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
169 (DES_key_schedule *)ks3, ivec, num);
170 }
171
172void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
173 _ossl_old_des_cblock (*out_white))
174 {
175 DES_xwhite_in2out(des_key, in_white, out_white);
176 }
177
178int _ossl_old_des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
179 _ossl_old_des_cblock *iv)
180 {
181 return DES_enc_read(fd, buf, len, (DES_key_schedule *)sched, iv);
182 }
183int _ossl_old_des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
184 _ossl_old_des_cblock *iv)
185 {
186 return DES_enc_write(fd, buf, len, (DES_key_schedule *)sched, iv);
187 }
188char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret)
189 {
190 return DES_fcrypt(buf, salt, ret);
191 }
192char *_ossl_old_des_crypt(const char *buf,const char *salt)
193 {
194 return DES_crypt(buf, salt);
195 }
196char *_ossl_old_crypt(const char *buf,const char *salt)
197 {
198 return DES_crypt(buf, salt);
199 }
200void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
201 int numbits,long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec)
202 {
203 DES_ofb_encrypt(in, out, numbits, length, (DES_key_schedule *)schedule,
204 ivec);
205 }
206void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
207 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
208 {
209 DES_pcbc_encrypt((unsigned char *)input, (unsigned char *)output,
210 length, (DES_key_schedule *)schedule, ivec, enc);
211 }
212DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
213 long length,int out_count,_ossl_old_des_cblock *seed)
214 {
215 return DES_quad_cksum((unsigned char *)input, output, length,
216 out_count, seed);
217 }
218void _ossl_old_des_random_seed(_ossl_old_des_cblock key)
219 {
220 RAND_seed(key, sizeof(_ossl_old_des_cblock));
221 }
222void _ossl_old_des_random_key(_ossl_old_des_cblock ret)
223 {
224 DES_random_key((DES_cblock *)ret);
225 }
226int _ossl_old_des_read_password(_ossl_old_des_cblock *key, const char *prompt,
227 int verify)
228 {
229 return DES_read_password(key, prompt, verify);
230 }
231int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1, _ossl_old_des_cblock *key2,
232 const char *prompt, int verify)
233 {
234 return DES_read_2passwords(key1, key2, prompt, verify);
235 }
236void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key)
237 {
238 DES_set_odd_parity(key);
239 }
240int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key)
241 {
242 return DES_is_weak_key(key);
243 }
244int _ossl_old_des_set_key(_ossl_old_des_cblock *key,des_key_schedule schedule)
245 {
246 return DES_set_key(key, (DES_key_schedule *)schedule);
247 }
248int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,des_key_schedule schedule)
249 {
250 return DES_key_sched(key, (DES_key_schedule *)schedule);
251 }
252void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key)
253 {
254 DES_string_to_key(str, key);
255 }
256void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2)
257 {
258 DES_string_to_2keys(str, key1, key2);
259 }
260void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
261 des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc)
262 {
263 DES_cfb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
264 ivec, num, enc);
265 }
266void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
267 des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num)
268 {
269 DES_ofb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
270 ivec, num);
271 }
diff --git a/src/lib/libcrypto/des/des_old.h b/src/lib/libcrypto/des/des_old.h
new file mode 100644
index 0000000000..1d8bf65101
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old.h
@@ -0,0 +1,441 @@
1/* crypto/des/des_old.h -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with openssl 0.9.6 and older as
7 * well as libdes. OpenSSL now provides functions where "des_" has
8 * been replaced with "DES_" in the names, to make it possible to
9 * make incompatible changes that are needed for C type security and
10 * other stuff.
11 *
12 * This include files has two compatibility modes:
13 *
14 * - If OPENSSL_DES_LIBDES_COMPATIBILITY is defined, you get an API
15 * that is compatible with libdes and SSLeay.
16 * - If OPENSSL_DES_LIBDES_COMPATIBILITY isn't defined, you get an
17 * API that is compatible with OpenSSL 0.9.5x to 0.9.6x.
18 *
19 * Note that these modes break earlier snapshots of OpenSSL, where
20 * libdes compatibility was the only available mode or (later on) the
21 * prefered compatibility mode. However, after much consideration
22 * (and more or less violent discussions with external parties), it
23 * was concluded that OpenSSL should be compatible with earlier versions
24 * of itself before anything else. Also, in all honesty, libdes is
25 * an old beast that shouldn't really be used any more.
26 *
27 * Please consider starting to use the DES_ functions rather than the
28 * des_ ones. The des_ functions will disappear completely before
29 * OpenSSL 1.0!
30 *
31 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
32 */
33
34/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
35 * project 2001.
36 */
37/* ====================================================================
38 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 *
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in
49 * the documentation and/or other materials provided with the
50 * distribution.
51 *
52 * 3. All advertising materials mentioning features or use of this
53 * software must display the following acknowledgment:
54 * "This product includes software developed by the OpenSSL Project
55 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
56 *
57 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
58 * endorse or promote products derived from this software without
59 * prior written permission. For written permission, please contact
60 * openssl-core@openssl.org.
61 *
62 * 5. Products derived from this software may not be called "OpenSSL"
63 * nor may "OpenSSL" appear in their names without prior written
64 * permission of the OpenSSL Project.
65 *
66 * 6. Redistributions of any form whatsoever must retain the following
67 * acknowledgment:
68 * "This product includes software developed by the OpenSSL Project
69 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
70 *
71 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
72 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
74 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
75 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
76 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
77 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
78 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
79 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
80 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
81 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
82 * OF THE POSSIBILITY OF SUCH DAMAGE.
83 * ====================================================================
84 *
85 * This product includes cryptographic software written by Eric Young
86 * (eay@cryptsoft.com). This product includes software written by Tim
87 * Hudson (tjh@cryptsoft.com).
88 *
89 */
90
91#ifndef HEADER_DES_OLD_H
92#define HEADER_DES_OLD_H
93
94#ifdef OPENSSL_NO_DES
95#error DES is disabled.
96#endif
97
98#ifndef HEADER_DES_H
99#error You must include des.h, not des_old.h directly.
100#endif
101
102#ifdef _KERBEROS_DES_H
103#error <openssl/des_old.h> replaces <kerberos/des.h>.
104#endif
105
106#include <openssl/opensslconf.h> /* DES_LONG */
107#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
108#include <openssl/symhacks.h>
109
110#ifdef OPENSSL_BUILD_SHLIBCRYPTO
111# undef OPENSSL_EXTERN
112# define OPENSSL_EXTERN OPENSSL_EXPORT
113#endif
114
115#ifdef __cplusplus
116extern "C" {
117#endif
118
119typedef unsigned char _ossl_old_des_cblock[8];
120typedef struct _ossl_old_des_ks_struct
121 {
122 union {
123 _ossl_old_des_cblock _;
124 /* make sure things are correct size on machines with
125 * 8 byte longs */
126 DES_LONG pad[2];
127 } ks;
128 } _ossl_old_des_key_schedule[16];
129
130#ifndef OPENSSL_DES_LIBDES_COMPATIBILITY
131#define des_cblock DES_cblock
132#define const_des_cblock const_DES_cblock
133#define des_key_schedule DES_key_schedule
134#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
135 DES_ecb3_encrypt((i),(o),&(k1),&(k2),&(k3),(e))
136#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
137 DES_ede3_cbc_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(e))
138#define des_ede3_cbcm_encrypt(i,o,l,k1,k2,k3,iv1,iv2,e)\
139 DES_ede3_cbcm_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv1),(iv2),(e))
140#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
141 DES_ede3_cfb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n),(e))
142#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
143 DES_ede3_ofb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n))
144#define des_options()\
145 DES_options()
146#define des_cbc_cksum(i,o,l,k,iv)\
147 DES_cbc_cksum((i),(o),(l),&(k),(iv))
148#define des_cbc_encrypt(i,o,l,k,iv,e)\
149 DES_cbc_encrypt((i),(o),(l),&(k),(iv),(e))
150#define des_ncbc_encrypt(i,o,l,k,iv,e)\
151 DES_ncbc_encrypt((i),(o),(l),&(k),(iv),(e))
152#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
153 DES_xcbc_encrypt((i),(o),(l),&(k),(iv),(inw),(outw),(e))
154#define des_cfb_encrypt(i,o,n,l,k,iv,e)\
155 DES_cfb_encrypt((i),(o),(n),(l),&(k),(iv),(e))
156#define des_ecb_encrypt(i,o,k,e)\
157 DES_ecb_encrypt((i),(o),&(k),(e))
158#define des_encrypt1(d,k,e)\
159 DES_encrypt1((d),&(k),(e))
160#define des_encrypt2(d,k,e)\
161 DES_encrypt2((d),&(k),(e))
162#define des_encrypt3(d,k1,k2,k3)\
163 DES_encrypt3((d),&(k1),&(k2),&(k3))
164#define des_decrypt3(d,k1,k2,k3)\
165 DES_decrypt3((d),&(k1),&(k2),&(k3))
166#define des_xwhite_in2out(k,i,o)\
167 DES_xwhite_in2out((k),(i),(o))
168#define des_enc_read(f,b,l,k,iv)\
169 DES_enc_read((f),(b),(l),&(k),(iv))
170#define des_enc_write(f,b,l,k,iv)\
171 DES_enc_write((f),(b),(l),&(k),(iv))
172#define des_fcrypt(b,s,r)\
173 DES_fcrypt((b),(s),(r))
174#define des_crypt(b,s)\
175 DES_crypt((b),(s))
176#if 0
177#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT) && !defined(__OpenBSD__)
178#define crypt(b,s)\
179 DES_crypt((b),(s))
180#endif
181#endif
182#define des_ofb_encrypt(i,o,n,l,k,iv)\
183 DES_ofb_encrypt((i),(o),(n),(l),&(k),(iv))
184#define des_pcbc_encrypt(i,o,l,k,iv,e)\
185 DES_pcbc_encrypt((i),(o),(l),&(k),(iv),(e))
186#define des_quad_cksum(i,o,l,c,s)\
187 DES_quad_cksum((i),(o),(l),(c),(s))
188#define des_random_seed(k)\
189 _ossl_096_des_random_seed((k))
190#define des_random_key(r)\
191 DES_random_key((r))
192#define des_read_password(k,p,v) \
193 DES_read_password((k),(p),(v))
194#define des_read_2passwords(k1,k2,p,v) \
195 DES_read_2passwords((k1),(k2),(p),(v))
196#define des_set_odd_parity(k)\
197 DES_set_odd_parity((k))
198#define des_check_key_parity(k)\
199 DES_check_key_parity((k))
200#define des_is_weak_key(k)\
201 DES_is_weak_key((k))
202#define des_set_key(k,ks)\
203 DES_set_key((k),&(ks))
204#define des_key_sched(k,ks)\
205 DES_key_sched((k),&(ks))
206#define des_set_key_checked(k,ks)\
207 DES_set_key_checked((k),&(ks))
208#define des_set_key_unchecked(k,ks)\
209 DES_set_key_unchecked((k),&(ks))
210#define des_string_to_key(s,k)\
211 DES_string_to_key((s),(k))
212#define des_string_to_2keys(s,k1,k2)\
213 DES_string_to_2keys((s),(k1),(k2))
214#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
215 DES_cfb64_encrypt((i),(o),(l),&(ks),(iv),(n),(e))
216#define des_ofb64_encrypt(i,o,l,ks,iv,n)\
217 DES_ofb64_encrypt((i),(o),(l),&(ks),(iv),(n))
218
219
220#define des_ecb2_encrypt(i,o,k1,k2,e) \
221 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
222
223#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
224 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
225
226#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
227 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
228
229#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
230 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
231
232#define des_check_key DES_check_key
233#define des_rw_mode DES_rw_mode
234#else /* libdes compatibility */
235/* Map all symbol names to _ossl_old_des_* form, so we avoid all
236 clashes with libdes */
237#define des_cblock _ossl_old_des_cblock
238#define des_key_schedule _ossl_old_des_key_schedule
239#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
240 _ossl_old_des_ecb3_encrypt((i),(o),(k1),(k2),(k3),(e))
241#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
242 _ossl_old_des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))
243#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
244 _ossl_old_des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n),(e))
245#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
246 _ossl_old_des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n))
247#define des_options()\
248 _ossl_old_des_options()
249#define des_cbc_cksum(i,o,l,k,iv)\
250 _ossl_old_des_cbc_cksum((i),(o),(l),(k),(iv))
251#define des_cbc_encrypt(i,o,l,k,iv,e)\
252 _ossl_old_des_cbc_encrypt((i),(o),(l),(k),(iv),(e))
253#define des_ncbc_encrypt(i,o,l,k,iv,e)\
254 _ossl_old_des_ncbc_encrypt((i),(o),(l),(k),(iv),(e))
255#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
256 _ossl_old_des_xcbc_encrypt((i),(o),(l),(k),(iv),(inw),(outw),(e))
257#define des_cfb_encrypt(i,o,n,l,k,iv,e)\
258 _ossl_old_des_cfb_encrypt((i),(o),(n),(l),(k),(iv),(e))
259#define des_ecb_encrypt(i,o,k,e)\
260 _ossl_old_des_ecb_encrypt((i),(o),(k),(e))
261#define des_encrypt(d,k,e)\
262 _ossl_old_des_encrypt((d),(k),(e))
263#define des_encrypt2(d,k,e)\
264 _ossl_old_des_encrypt2((d),(k),(e))
265#define des_encrypt3(d,k1,k2,k3)\
266 _ossl_old_des_encrypt3((d),(k1),(k2),(k3))
267#define des_decrypt3(d,k1,k2,k3)\
268 _ossl_old_des_decrypt3((d),(k1),(k2),(k3))
269#define des_xwhite_in2out(k,i,o)\
270 _ossl_old_des_xwhite_in2out((k),(i),(o))
271#define des_enc_read(f,b,l,k,iv)\
272 _ossl_old_des_enc_read((f),(b),(l),(k),(iv))
273#define des_enc_write(f,b,l,k,iv)\
274 _ossl_old_des_enc_write((f),(b),(l),(k),(iv))
275#define des_fcrypt(b,s,r)\
276 _ossl_old_des_fcrypt((b),(s),(r))
277#define des_crypt(b,s)\
278 _ossl_old_des_crypt((b),(s))
279#if 0
280#define crypt(b,s)\
281 _ossl_old_crypt((b),(s))
282#endif
283#define des_ofb_encrypt(i,o,n,l,k,iv)\
284 _ossl_old_des_ofb_encrypt((i),(o),(n),(l),(k),(iv))
285#define des_pcbc_encrypt(i,o,l,k,iv,e)\
286 _ossl_old_des_pcbc_encrypt((i),(o),(l),(k),(iv),(e))
287#define des_quad_cksum(i,o,l,c,s)\
288 _ossl_old_des_quad_cksum((i),(o),(l),(c),(s))
289#define des_random_seed(k)\
290 _ossl_old_des_random_seed((k))
291#define des_random_key(r)\
292 _ossl_old_des_random_key((r))
293#define des_read_password(k,p,v) \
294 _ossl_old_des_read_password((k),(p),(v))
295#define des_read_2passwords(k1,k2,p,v) \
296 _ossl_old_des_read_2passwords((k1),(k2),(p),(v))
297#define des_set_odd_parity(k)\
298 _ossl_old_des_set_odd_parity((k))
299#define des_is_weak_key(k)\
300 _ossl_old_des_is_weak_key((k))
301#define des_set_key(k,ks)\
302 _ossl_old_des_set_key((k),(ks))
303#define des_key_sched(k,ks)\
304 _ossl_old_des_key_sched((k),(ks))
305#define des_string_to_key(s,k)\
306 _ossl_old_des_string_to_key((s),(k))
307#define des_string_to_2keys(s,k1,k2)\
308 _ossl_old_des_string_to_2keys((s),(k1),(k2))
309#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
310 _ossl_old_des_cfb64_encrypt((i),(o),(l),(ks),(iv),(n),(e))
311#define des_ofb64_encrypt(i,o,l,ks,iv,n)\
312 _ossl_old_des_ofb64_encrypt((i),(o),(l),(ks),(iv),(n))
313
314
315#define des_ecb2_encrypt(i,o,k1,k2,e) \
316 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
317
318#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
319 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
320
321#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
322 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
323
324#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
325 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
326
327#define des_check_key DES_check_key
328#define des_rw_mode DES_rw_mode
329#endif
330
331const char *_ossl_old_des_options(void);
332void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
333 _ossl_old_des_key_schedule ks1,_ossl_old_des_key_schedule ks2,
334 _ossl_old_des_key_schedule ks3, int enc);
335DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
336 long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
337void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
338 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
339void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
340 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
341void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
342 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,
343 _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc);
344void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
345 long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
346void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
347 _ossl_old_des_key_schedule ks,int enc);
348void _ossl_old_des_encrypt(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
349void _ossl_old_des_encrypt2(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
350void _ossl_old_des_encrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
351 _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
352void _ossl_old_des_decrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
353 _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
354void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output,
355 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
356 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc);
357void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
358 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
359 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc);
360void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
361 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
362 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num);
363
364void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
365 _ossl_old_des_cblock (*out_white));
366
367int _ossl_old_des_enc_read(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
368 _ossl_old_des_cblock *iv);
369int _ossl_old_des_enc_write(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
370 _ossl_old_des_cblock *iv);
371char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret);
372char *_ossl_old_des_crypt(const char *buf,const char *salt);
373#if !defined(PERL5) && !defined(NeXT)
374char *_ossl_old_crypt(const char *buf,const char *salt);
375#endif
376void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
377 int numbits,long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
378void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
379 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
380DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
381 long length,int out_count,_ossl_old_des_cblock *seed);
382void _ossl_old_des_random_seed(_ossl_old_des_cblock key);
383void _ossl_old_des_random_key(_ossl_old_des_cblock ret);
384int _ossl_old_des_read_password(_ossl_old_des_cblock *key,const char *prompt,int verify);
385int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2,
386 const char *prompt,int verify);
387void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key);
388int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key);
389int _ossl_old_des_set_key(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
390int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
391void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key);
392void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2);
393void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
394 _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc);
395void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
396 _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num);
397
398void _ossl_096_des_random_seed(des_cblock *key);
399
400/* The following definitions provide compatibility with the MIT Kerberos
401 * library. The _ossl_old_des_key_schedule structure is not binary compatible. */
402
403#define _KERBEROS_DES_H
404
405#define KRBDES_ENCRYPT DES_ENCRYPT
406#define KRBDES_DECRYPT DES_DECRYPT
407
408#ifdef KERBEROS
409# define ENCRYPT DES_ENCRYPT
410# define DECRYPT DES_DECRYPT
411#endif
412
413#ifndef NCOMPAT
414# define C_Block des_cblock
415# define Key_schedule des_key_schedule
416# define KEY_SZ DES_KEY_SZ
417# define string_to_key des_string_to_key
418# define read_pw_string des_read_pw_string
419# define random_key des_random_key
420# define pcbc_encrypt des_pcbc_encrypt
421# define set_key des_set_key
422# define key_sched des_key_sched
423# define ecb_encrypt des_ecb_encrypt
424# define cbc_encrypt des_cbc_encrypt
425# define ncbc_encrypt des_ncbc_encrypt
426# define xcbc_encrypt des_xcbc_encrypt
427# define cbc_cksum des_cbc_cksum
428# define quad_cksum des_quad_cksum
429# define check_parity des_check_key_parity
430#endif
431
432#define des_fixup_key_parity DES_fixup_key_parity
433
434#ifdef __cplusplus
435}
436#endif
437
438/* for DES_read_pw_string et al */
439#include <openssl/ui_compat.h>
440
441#endif
diff --git a/src/lib/libcrypto/des/des_old2.c b/src/lib/libcrypto/des/des_old2.c
new file mode 100644
index 0000000000..c8fa3ee135
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old2.c
@@ -0,0 +1,82 @@
1/* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with OpenSSL 0.9.6c. OpenSSL now
7 * provides functions where "des_" has been replaced with "DES_" in
8 * the names, to make it possible to make incompatible changes that
9 * are needed for C type security and other stuff.
10 *
11 * Please consider starting to use the DES_ functions rather than the
12 * des_ ones. The des_ functions will dissapear completely before
13 * OpenSSL 1.0!
14 *
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16 */
17
18/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
19 * project 2001.
20 */
21/* ====================================================================
22 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 *
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 *
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 *
36 * 3. All advertising materials mentioning features or use of this
37 * software must display the following acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40 *
41 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42 * endorse or promote products derived from this software without
43 * prior written permission. For written permission, please contact
44 * openssl-core@openssl.org.
45 *
46 * 5. Products derived from this software may not be called "OpenSSL"
47 * nor may "OpenSSL" appear in their names without prior written
48 * permission of the OpenSSL Project.
49 *
50 * 6. Redistributions of any form whatsoever must retain the following
51 * acknowledgment:
52 * "This product includes software developed by the OpenSSL Project
53 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66 * OF THE POSSIBILITY OF SUCH DAMAGE.
67 * ====================================================================
68 *
69 * This product includes cryptographic software written by Eric Young
70 * (eay@cryptsoft.com). This product includes software written by Tim
71 * Hudson (tjh@cryptsoft.com).
72 *
73 */
74
75#undef OPENSSL_DES_LIBDES_COMPATIBILITY
76#include <openssl/des.h>
77#include <openssl/rand.h>
78
79void _ossl_096_des_random_seed(DES_cblock *key)
80 {
81 RAND_seed(key, sizeof(DES_cblock));
82 }
diff --git a/src/lib/libcrypto/des/des_opts.c b/src/lib/libcrypto/des/des_opts.c
new file mode 100644
index 0000000000..79278b920e
--- /dev/null
+++ b/src/lib/libcrypto/des/des_opts.c
@@ -0,0 +1,604 @@
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#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef OPENSSL_SYS_MSDOS
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD
70#else
71#include <io.h>
72extern void exit();
73#endif
74#include <signal.h>
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
83/* Depending on the VMS version, the tms structure is perhaps defined.
84 The __TMS macro will show if it was. If it wasn't defined, we should
85 undefine TIMES, since that tells the rest of the program how things
86 should be handled. -- Richard Levitte */
87#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
88#undef TIMES
89#endif
90
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95
96#if defined(sun) || defined(__ultrix)
97#define _POSIX_SOURCE
98#include <limits.h>
99#include <sys/param.h>
100#endif
101
102#include <openssl/des.h>
103#include "spr.h"
104
105#define DES_DEFAULT_OPTIONS
106
107#if !defined(PART1) && !defined(PART2) && !defined(PART3) && !defined(PART4)
108#define PART1
109#define PART2
110#define PART3
111#define PART4
112#endif
113
114#ifdef PART1
115
116#undef DES_UNROLL
117#undef DES_RISC1
118#undef DES_RISC2
119#undef DES_PTR
120#undef D_ENCRYPT
121#define DES_encrypt1 des_encrypt_u4_cisc_idx
122#define DES_encrypt2 des_encrypt2_u4_cisc_idx
123#define DES_encrypt3 des_encrypt3_u4_cisc_idx
124#define DES_decrypt3 des_decrypt3_u4_cisc_idx
125#undef HEADER_DES_LOCL_H
126#include "des_enc.c"
127
128#define DES_UNROLL
129#undef DES_RISC1
130#undef DES_RISC2
131#undef DES_PTR
132#undef D_ENCRYPT
133#undef DES_encrypt1
134#undef DES_encrypt2
135#undef DES_encrypt3
136#undef DES_decrypt3
137#define DES_encrypt1 des_encrypt_u16_cisc_idx
138#define DES_encrypt2 des_encrypt2_u16_cisc_idx
139#define DES_encrypt3 des_encrypt3_u16_cisc_idx
140#define DES_decrypt3 des_decrypt3_u16_cisc_idx
141#undef HEADER_DES_LOCL_H
142#include "des_enc.c"
143
144#undef DES_UNROLL
145#define DES_RISC1
146#undef DES_RISC2
147#undef DES_PTR
148#undef D_ENCRYPT
149#undef DES_encrypt1
150#undef DES_encrypt2
151#undef DES_encrypt3
152#undef DES_decrypt3
153#define DES_encrypt1 des_encrypt_u4_risc1_idx
154#define DES_encrypt2 des_encrypt2_u4_risc1_idx
155#define DES_encrypt3 des_encrypt3_u4_risc1_idx
156#define DES_decrypt3 des_decrypt3_u4_risc1_idx
157#undef HEADER_DES_LOCL_H
158#include "des_enc.c"
159
160#endif
161
162#ifdef PART2
163
164#undef DES_UNROLL
165#undef DES_RISC1
166#define DES_RISC2
167#undef DES_PTR
168#undef D_ENCRYPT
169#undef DES_encrypt1
170#undef DES_encrypt2
171#undef DES_encrypt3
172#undef DES_decrypt3
173#define DES_encrypt1 des_encrypt_u4_risc2_idx
174#define DES_encrypt2 des_encrypt2_u4_risc2_idx
175#define DES_encrypt3 des_encrypt3_u4_risc2_idx
176#define DES_decrypt3 des_decrypt3_u4_risc2_idx
177#undef HEADER_DES_LOCL_H
178#include "des_enc.c"
179
180#define DES_UNROLL
181#define DES_RISC1
182#undef DES_RISC2
183#undef DES_PTR
184#undef D_ENCRYPT
185#undef DES_encrypt1
186#undef DES_encrypt2
187#undef DES_encrypt3
188#undef DES_decrypt3
189#define DES_encrypt1 des_encrypt_u16_risc1_idx
190#define DES_encrypt2 des_encrypt2_u16_risc1_idx
191#define DES_encrypt3 des_encrypt3_u16_risc1_idx
192#define DES_decrypt3 des_decrypt3_u16_risc1_idx
193#undef HEADER_DES_LOCL_H
194#include "des_enc.c"
195
196#define DES_UNROLL
197#undef DES_RISC1
198#define DES_RISC2
199#undef DES_PTR
200#undef D_ENCRYPT
201#undef DES_encrypt1
202#undef DES_encrypt2
203#undef DES_encrypt3
204#undef DES_decrypt3
205#define DES_encrypt1 des_encrypt_u16_risc2_idx
206#define DES_encrypt2 des_encrypt2_u16_risc2_idx
207#define DES_encrypt3 des_encrypt3_u16_risc2_idx
208#define DES_decrypt3 des_decrypt3_u16_risc2_idx
209#undef HEADER_DES_LOCL_H
210#include "des_enc.c"
211
212#endif
213
214#ifdef PART3
215
216#undef DES_UNROLL
217#undef DES_RISC1
218#undef DES_RISC2
219#define DES_PTR
220#undef D_ENCRYPT
221#undef DES_encrypt1
222#undef DES_encrypt2
223#undef DES_encrypt3
224#undef DES_decrypt3
225#define DES_encrypt1 des_encrypt_u4_cisc_ptr
226#define DES_encrypt2 des_encrypt2_u4_cisc_ptr
227#define DES_encrypt3 des_encrypt3_u4_cisc_ptr
228#define DES_decrypt3 des_decrypt3_u4_cisc_ptr
229#undef HEADER_DES_LOCL_H
230#include "des_enc.c"
231
232#define DES_UNROLL
233#undef DES_RISC1
234#undef DES_RISC2
235#define DES_PTR
236#undef D_ENCRYPT
237#undef DES_encrypt1
238#undef DES_encrypt2
239#undef DES_encrypt3
240#undef DES_decrypt3
241#define DES_encrypt1 des_encrypt_u16_cisc_ptr
242#define DES_encrypt2 des_encrypt2_u16_cisc_ptr
243#define DES_encrypt3 des_encrypt3_u16_cisc_ptr
244#define DES_decrypt3 des_decrypt3_u16_cisc_ptr
245#undef HEADER_DES_LOCL_H
246#include "des_enc.c"
247
248#undef DES_UNROLL
249#define DES_RISC1
250#undef DES_RISC2
251#define DES_PTR
252#undef D_ENCRYPT
253#undef DES_encrypt1
254#undef DES_encrypt2
255#undef DES_encrypt3
256#undef DES_decrypt3
257#define DES_encrypt1 des_encrypt_u4_risc1_ptr
258#define DES_encrypt2 des_encrypt2_u4_risc1_ptr
259#define DES_encrypt3 des_encrypt3_u4_risc1_ptr
260#define DES_decrypt3 des_decrypt3_u4_risc1_ptr
261#undef HEADER_DES_LOCL_H
262#include "des_enc.c"
263
264#endif
265
266#ifdef PART4
267
268#undef DES_UNROLL
269#undef DES_RISC1
270#define DES_RISC2
271#define DES_PTR
272#undef D_ENCRYPT
273#undef DES_encrypt1
274#undef DES_encrypt2
275#undef DES_encrypt3
276#undef DES_decrypt3
277#define DES_encrypt1 des_encrypt_u4_risc2_ptr
278#define DES_encrypt2 des_encrypt2_u4_risc2_ptr
279#define DES_encrypt3 des_encrypt3_u4_risc2_ptr
280#define DES_decrypt3 des_decrypt3_u4_risc2_ptr
281#undef HEADER_DES_LOCL_H
282#include "des_enc.c"
283
284#define DES_UNROLL
285#define DES_RISC1
286#undef DES_RISC2
287#define DES_PTR
288#undef D_ENCRYPT
289#undef DES_encrypt1
290#undef DES_encrypt2
291#undef DES_encrypt3
292#undef DES_decrypt3
293#define DES_encrypt1 des_encrypt_u16_risc1_ptr
294#define DES_encrypt2 des_encrypt2_u16_risc1_ptr
295#define DES_encrypt3 des_encrypt3_u16_risc1_ptr
296#define DES_decrypt3 des_decrypt3_u16_risc1_ptr
297#undef HEADER_DES_LOCL_H
298#include "des_enc.c"
299
300#define DES_UNROLL
301#undef DES_RISC1
302#define DES_RISC2
303#define DES_PTR
304#undef D_ENCRYPT
305#undef DES_encrypt1
306#undef DES_encrypt2
307#undef DES_encrypt3
308#undef DES_decrypt3
309#define DES_encrypt1 des_encrypt_u16_risc2_ptr
310#define DES_encrypt2 des_encrypt2_u16_risc2_ptr
311#define DES_encrypt3 des_encrypt3_u16_risc2_ptr
312#define DES_decrypt3 des_decrypt3_u16_risc2_ptr
313#undef HEADER_DES_LOCL_H
314#include "des_enc.c"
315
316#endif
317
318/* The following if from times(3) man page. It may need to be changed */
319#ifndef HZ
320# ifndef CLK_TCK
321# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
322# define HZ 100.0
323# else /* _BSD_CLK_TCK_ */
324# define HZ ((double)_BSD_CLK_TCK_)
325# endif
326# else /* CLK_TCK */
327# define HZ ((double)CLK_TCK)
328# endif
329#endif
330
331#define BUFSIZE ((long)1024)
332long run=0;
333
334double Time_F(int s);
335#ifdef SIGALRM
336#if defined(__STDC__) || defined(sgi)
337#define SIGRETTYPE void
338#else
339#define SIGRETTYPE int
340#endif
341
342SIGRETTYPE sig_done(int sig);
343SIGRETTYPE sig_done(int sig)
344 {
345 signal(SIGALRM,sig_done);
346 run=0;
347#ifdef LINT
348 sig=sig;
349#endif
350 }
351#endif
352
353#define START 0
354#define STOP 1
355
356double Time_F(int s)
357 {
358 double ret;
359#ifdef TIMES
360 static struct tms tstart,tend;
361
362 if (s == START)
363 {
364 times(&tstart);
365 return(0);
366 }
367 else
368 {
369 times(&tend);
370 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
371 return((ret == 0.0)?1e-6:ret);
372 }
373#else /* !times() */
374 static struct timeb tstart,tend;
375 long i;
376
377 if (s == START)
378 {
379 ftime(&tstart);
380 return(0);
381 }
382 else
383 {
384 ftime(&tend);
385 i=(long)tend.millitm-(long)tstart.millitm;
386 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
387 return((ret == 0.0)?1e-6:ret);
388 }
389#endif
390 }
391
392#ifdef SIGALRM
393#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
394#else
395#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
396#endif
397
398#define time_it(func,name,index) \
399 print_name(name); \
400 Time_F(START); \
401 for (count=0,run=1; COND(cb); count++) \
402 { \
403 unsigned long d[2]; \
404 func(d,&sch,DES_ENCRYPT); \
405 } \
406 tm[index]=Time_F(STOP); \
407 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
408 tm[index]=((double)COUNT(cb))/tm[index];
409
410#define print_it(name,index) \
411 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
412 tm[index]*8,1.0e6/tm[index]);
413
414int main(int argc, char **argv)
415 {
416 long count;
417 static unsigned char buf[BUFSIZE];
418 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
419 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
420 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
421 DES_key_schedule sch,sch2,sch3;
422 double d,tm[16],max=0;
423 int rank[16];
424 char *str[16];
425 int max_idx=0,i,num=0,j;
426#ifndef SIGALARM
427 long ca,cb,cc,cd,ce;
428#endif
429
430 for (i=0; i<12; i++)
431 {
432 tm[i]=0.0;
433 rank[i]=0;
434 }
435
436#ifndef TIMES
437 fprintf(stderr,"To get the most accurate results, try to run this\n");
438 fprintf(stderr,"program when this computer is idle.\n");
439#endif
440
441 DES_set_key_unchecked(&key,&sch);
442 DES_set_key_unchecked(&key2,&sch2);
443 DES_set_key_unchecked(&key3,&sch3);
444
445#ifndef SIGALRM
446 fprintf(stderr,"First we calculate the approximate speed ...\n");
447 DES_set_key_unchecked(&key,sch);
448 count=10;
449 do {
450 long i;
451 unsigned long data[2];
452
453 count*=2;
454 Time_F(START);
455 for (i=count; i; i--)
456 DES_encrypt1(data,&(sch[0]),DES_ENCRYPT);
457 d=Time_F(STOP);
458 } while (d < 3.0);
459 ca=count;
460 cb=count*3;
461 cc=count*3*8/BUFSIZE+1;
462 cd=count*8/BUFSIZE+1;
463
464 ce=count/20+1;
465#define COND(d) (count != (d))
466#define COUNT(d) (d)
467#else
468#define COND(c) (run)
469#define COUNT(d) (count)
470 signal(SIGALRM,sig_done);
471 alarm(10);
472#endif
473
474#ifdef PART1
475 time_it(des_encrypt_u4_cisc_idx, "des_encrypt_u4_cisc_idx ", 0);
476 time_it(des_encrypt_u16_cisc_idx, "des_encrypt_u16_cisc_idx ", 1);
477 time_it(des_encrypt_u4_risc1_idx, "des_encrypt_u4_risc1_idx ", 2);
478 num+=3;
479#endif
480#ifdef PART2
481 time_it(des_encrypt_u16_risc1_idx,"des_encrypt_u16_risc1_idx", 3);
482 time_it(des_encrypt_u4_risc2_idx, "des_encrypt_u4_risc2_idx ", 4);
483 time_it(des_encrypt_u16_risc2_idx,"des_encrypt_u16_risc2_idx", 5);
484 num+=3;
485#endif
486#ifdef PART3
487 time_it(des_encrypt_u4_cisc_ptr, "des_encrypt_u4_cisc_ptr ", 6);
488 time_it(des_encrypt_u16_cisc_ptr, "des_encrypt_u16_cisc_ptr ", 7);
489 time_it(des_encrypt_u4_risc1_ptr, "des_encrypt_u4_risc1_ptr ", 8);
490 num+=3;
491#endif
492#ifdef PART4
493 time_it(des_encrypt_u16_risc1_ptr,"des_encrypt_u16_risc1_ptr", 9);
494 time_it(des_encrypt_u4_risc2_ptr, "des_encrypt_u4_risc2_ptr ",10);
495 time_it(des_encrypt_u16_risc2_ptr,"des_encrypt_u16_risc2_ptr",11);
496 num+=3;
497#endif
498
499#ifdef PART1
500 str[0]=" 4 c i";
501 print_it("des_encrypt_u4_cisc_idx ",0);
502 max=tm[0];
503 max_idx=0;
504 str[1]="16 c i";
505 print_it("des_encrypt_u16_cisc_idx ",1);
506 if (max < tm[1]) { max=tm[1]; max_idx=1; }
507 str[2]=" 4 r1 i";
508 print_it("des_encrypt_u4_risc1_idx ",2);
509 if (max < tm[2]) { max=tm[2]; max_idx=2; }
510#endif
511#ifdef PART2
512 str[3]="16 r1 i";
513 print_it("des_encrypt_u16_risc1_idx",3);
514 if (max < tm[3]) { max=tm[3]; max_idx=3; }
515 str[4]=" 4 r2 i";
516 print_it("des_encrypt_u4_risc2_idx ",4);
517 if (max < tm[4]) { max=tm[4]; max_idx=4; }
518 str[5]="16 r2 i";
519 print_it("des_encrypt_u16_risc2_idx",5);
520 if (max < tm[5]) { max=tm[5]; max_idx=5; }
521#endif
522#ifdef PART3
523 str[6]=" 4 c p";
524 print_it("des_encrypt_u4_cisc_ptr ",6);
525 if (max < tm[6]) { max=tm[6]; max_idx=6; }
526 str[7]="16 c p";
527 print_it("des_encrypt_u16_cisc_ptr ",7);
528 if (max < tm[7]) { max=tm[7]; max_idx=7; }
529 str[8]=" 4 r1 p";
530 print_it("des_encrypt_u4_risc1_ptr ",8);
531 if (max < tm[8]) { max=tm[8]; max_idx=8; }
532#endif
533#ifdef PART4
534 str[9]="16 r1 p";
535 print_it("des_encrypt_u16_risc1_ptr",9);
536 if (max < tm[9]) { max=tm[9]; max_idx=9; }
537 str[10]=" 4 r2 p";
538 print_it("des_encrypt_u4_risc2_ptr ",10);
539 if (max < tm[10]) { max=tm[10]; max_idx=10; }
540 str[11]="16 r2 p";
541 print_it("des_encrypt_u16_risc2_ptr",11);
542 if (max < tm[11]) { max=tm[11]; max_idx=11; }
543#endif
544 printf("options des ecb/s\n");
545 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
546 d=tm[max_idx];
547 tm[max_idx]= -2.0;
548 max= -1.0;
549 for (;;)
550 {
551 for (i=0; i<12; i++)
552 {
553 if (max < tm[i]) { max=tm[i]; j=i; }
554 }
555 if (max < 0.0) break;
556 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
557 tm[j]= -2.0;
558 max= -1.0;
559 }
560
561 switch (max_idx)
562 {
563 case 0:
564 printf("-DDES_DEFAULT_OPTIONS\n");
565 break;
566 case 1:
567 printf("-DDES_UNROLL\n");
568 break;
569 case 2:
570 printf("-DDES_RISC1\n");
571 break;
572 case 3:
573 printf("-DDES_UNROLL -DDES_RISC1\n");
574 break;
575 case 4:
576 printf("-DDES_RISC2\n");
577 break;
578 case 5:
579 printf("-DDES_UNROLL -DDES_RISC2\n");
580 break;
581 case 6:
582 printf("-DDES_PTR\n");
583 break;
584 case 7:
585 printf("-DDES_UNROLL -DDES_PTR\n");
586 break;
587 case 8:
588 printf("-DDES_RISC1 -DDES_PTR\n");
589 break;
590 case 9:
591 printf("-DDES_UNROLL -DDES_RISC1 -DDES_PTR\n");
592 break;
593 case 10:
594 printf("-DDES_RISC2 -DDES_PTR\n");
595 break;
596 case 11:
597 printf("-DDES_UNROLL -DDES_RISC2 -DDES_PTR\n");
598 break;
599 }
600 exit(0);
601#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
602 return(0);
603#endif
604 }
diff --git a/src/lib/libcrypto/des/des_ver.h b/src/lib/libcrypto/des/des_ver.h
new file mode 100644
index 0000000000..379bbadda2
--- /dev/null
+++ b/src/lib/libcrypto/des/des_ver.h
@@ -0,0 +1,71 @@
1/* crypto/des/des_ver.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/e_os2.h>
60
61#ifdef OPENSSL_BUILD_SHLIBCRYPTO
62# undef OPENSSL_EXTERN
63# define OPENSSL_EXTERN OPENSSL_EXPORT
64#endif
65
66/* The following macros make sure the names are different from libdes names */
67#define DES_version OSSL_DES_version
68#define libdes_version OSSL_libdes_version
69
70OPENSSL_EXTERN const char *OSSL_DES_version; /* SSLeay version string */
71OPENSSL_EXTERN const char *OSSL_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..5549bab90a
--- /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 <openssl/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_encrypt1(&data[0],key,1);
49 GetTSC(s1);
50 des_encrypt1(&data[0],key,1);
51 des_encrypt1(&data[0],key,1);
52 des_encrypt1(&data[0],key,1);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt1(&data[0],key,1);
56 des_encrypt1(&data[0],key,1);
57 des_encrypt1(&data[0],key,1);
58 des_encrypt1(&data[0],key,1);
59 GetTSC(e2);
60 des_encrypt1(&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..e3e9d77f14
--- /dev/null
+++ b/src/lib/libcrypto/des/destest.c
@@ -0,0 +1,948 @@
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#include <stdio.h>
60#include <stdlib.h>
61
62#include <openssl/e_os2.h>
63#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_WINDOWS)
64#ifndef OPENSSL_SYS_MSDOS
65#define OPENSSL_SYS_MSDOS
66#endif
67#endif
68
69#ifndef OPENSSL_SYS_MSDOS
70#if !defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_VMS_DECC)
71#include OPENSSL_UNISTD
72#endif
73#else
74#include <io.h>
75#endif
76#include <string.h>
77
78#ifdef OPENSSL_NO_DES
79int main(int argc, char *argv[])
80{
81 printf("No DES support\n");
82 return(0);
83}
84#else
85#include <openssl/des.h>
86
87#define crypt(c,s) (des_crypt((c),(s)))
88
89/* tisk tisk - the test keys don't all have odd parity :-( */
90/* test data */
91#define NUM_TESTS 34
92static unsigned char key_data[NUM_TESTS][8]={
93 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
94 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
95 {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
96 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
97 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
98 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
99 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
100 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
101 {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
102 {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
103 {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
104 {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
105 {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
106 {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
107 {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
108 {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
109 {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
110 {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
111 {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
112 {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
113 {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
114 {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
115 {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
116 {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
117 {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
118 {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
119 {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
120 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
121 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
122 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
123 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
124 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
125 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
126 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
127
128static unsigned char plain_data[NUM_TESTS][8]={
129 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
130 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
131 {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
132 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
133 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
134 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
135 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
136 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
137 {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
138 {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
139 {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
140 {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
141 {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
142 {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
143 {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
144 {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
145 {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
146 {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
147 {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
148 {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
149 {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
150 {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
151 {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
152 {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
153 {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
154 {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
155 {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
156 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
157 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
158 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
159 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
160 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
161 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
162 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
163
164static unsigned char cipher_data[NUM_TESTS][8]={
165 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
166 {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58},
167 {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B},
168 {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33},
169 {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D},
170 {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD},
171 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
172 {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4},
173 {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B},
174 {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71},
175 {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A},
176 {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A},
177 {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95},
178 {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B},
179 {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09},
180 {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A},
181 {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F},
182 {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88},
183 {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77},
184 {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A},
185 {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56},
186 {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56},
187 {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56},
188 {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC},
189 {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A},
190 {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41},
191 {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93},
192 {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00},
193 {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06},
194 {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7},
195 {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51},
196 {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE},
197 {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D},
198 {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}};
199
200static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
201 {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E},
202 {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16},
203 {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27},
204 {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6},
205 {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25},
206 {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A},
207 {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74},
208 {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6},
209 {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67},
210 {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10},
211 {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85},
212 {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA},
213 {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3},
214 {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3},
215 {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A},
216 {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69},
217 {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1},
218 {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7},
219 {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F},
220 {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87},
221 {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A},
222 {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE},
223 {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3},
224 {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD},
225 {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84},
226 {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85},
227 {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC},
228 {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89},
229 {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E},
230 {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89},
231 {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7},
232 {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8},
233 {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
234
235static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
236static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86};
237static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
238static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
239/* Changed the following text constant to binary so it will work on ebcdic
240 * machines :-) */
241/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
242static unsigned char cbc_data[40]={
243 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20,
244 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74,
245 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20,
246 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00,
247 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
248 };
249
250static unsigned char cbc_ok[32]={
251 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
252 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb,
253 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
254 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
255
256#ifdef SCREW_THE_PARITY
257#error "SCREW_THE_PARITY is not ment to be defined."
258#error "Original vectors are preserved for reference only."
259static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
260static unsigned char xcbc_ok[32]={
261 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48,
262 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD,
263 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76,
264 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2,
265 };
266#else
267static unsigned char xcbc_ok[32]={
268 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29,
269 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1,
270 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53,
271 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4,
272 };
273#endif
274
275static unsigned char cbc3_ok[32]={
276 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0,
277 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC,
278 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4,
279 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75};
280
281static unsigned char pcbc_ok[32]={
282 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
283 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15,
284 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f,
285 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88};
286
287static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
288static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
289static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
290static unsigned char plain[24]=
291 {
292 0x4e,0x6f,0x77,0x20,0x69,0x73,
293 0x20,0x74,0x68,0x65,0x20,0x74,
294 0x69,0x6d,0x65,0x20,0x66,0x6f,
295 0x72,0x20,0x61,0x6c,0x6c,0x20
296 };
297static unsigned char cfb_cipher8[24]= {
298 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8,
299 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 };
300static unsigned char cfb_cipher16[24]={
301 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70,
302 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B };
303static unsigned char cfb_cipher32[24]={
304 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD,
305 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 };
306static unsigned char cfb_cipher48[24]={
307 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85,
308 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F };
309static unsigned char cfb_cipher64[24]={
310 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B,
311 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 };
312
313static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
314static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
315static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8];
316static unsigned char ofb_cipher[24]=
317 {
318 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
319 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
320 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
321 };
322
323#if 0
324static DES_LONG cbc_cksum_ret=0xB462FEF7L;
325#else
326static DES_LONG cbc_cksum_ret=0xF7FE62B4L;
327#endif
328static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
329
330static char *pt(unsigned char *p);
331static int cfb_test(int bits, unsigned char *cfb_cipher);
332static int cfb64_test(unsigned char *cfb_cipher);
333static int ede_cfb64_test(unsigned char *cfb_cipher);
334int main(int argc, char *argv[])
335 {
336 int i,j,err=0;
337 des_cblock in,out,outin,iv3,iv2;
338 des_key_schedule ks,ks2,ks3;
339 unsigned char cbc_in[40];
340 unsigned char cbc_out[40];
341 DES_LONG cs;
342 unsigned char cret[8];
343#ifdef _CRAY
344 struct {
345 int a:32;
346 int b:32;
347 } lqret[2];
348#else
349 DES_LONG lqret[4];
350#endif
351 int num;
352 char *str;
353
354#ifndef OPENSSL_NO_DESCBCM
355 printf("Doing cbcm\n");
356 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
357 {
358 printf("Key error %d\n",j);
359 err=1;
360 }
361 if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
362 {
363 printf("Key error %d\n",j);
364 err=1;
365 }
366 if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
367 {
368 printf("Key error %d\n",j);
369 err=1;
370 }
371 memset(cbc_out,0,40);
372 memset(cbc_in,0,40);
373 i=strlen((char *)cbc_data)+1;
374 /* i=((i+7)/8)*8; */
375 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
376 memset(iv2,'\0',sizeof iv2);
377
378 DES_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,&ks,&ks2,&ks3,&iv3,&iv2,
379 DES_ENCRYPT);
380 DES_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,&ks,&ks2,&ks3,
381 &iv3,&iv2,DES_ENCRYPT);
382 /* if (memcmp(cbc_out,cbc3_ok,
383 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
384 {
385 printf("des_ede3_cbc_encrypt encrypt error\n");
386 err=1;
387 }
388 */
389 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
390 memset(iv2,'\0',sizeof iv2);
391 DES_ede3_cbcm_encrypt(cbc_out,cbc_in,i,&ks,&ks2,&ks3,&iv3,&iv2,DES_DECRYPT);
392 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
393 {
394 int n;
395
396 printf("des_ede3_cbcm_encrypt decrypt error\n");
397 for(n=0 ; n < i ; ++n)
398 printf(" %02x",cbc_data[n]);
399 printf("\n");
400 for(n=0 ; n < i ; ++n)
401 printf(" %02x",cbc_in[n]);
402 printf("\n");
403 err=1;
404 }
405#endif
406
407 printf("Doing ecb\n");
408 for (i=0; i<NUM_TESTS; i++)
409 {
410 DES_set_key_unchecked(&key_data[i],&ks);
411 memcpy(in,plain_data[i],8);
412 memset(out,0,8);
413 memset(outin,0,8);
414 des_ecb_encrypt(&in,&out,ks,DES_ENCRYPT);
415 des_ecb_encrypt(&out,&outin,ks,DES_DECRYPT);
416
417 if (memcmp(out,cipher_data[i],8) != 0)
418 {
419 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
420 i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]),
421 pt(out));
422 err=1;
423 }
424 if (memcmp(in,outin,8) != 0)
425 {
426 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
427 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
428 err=1;
429 }
430 }
431
432#ifndef LIBDES_LIT
433 printf("Doing ede ecb\n");
434 for (i=0; i<(NUM_TESTS-2); i++)
435 {
436 DES_set_key_unchecked(&key_data[i],&ks);
437 DES_set_key_unchecked(&key_data[i+1],&ks2);
438 DES_set_key_unchecked(&key_data[i+2],&ks3);
439 memcpy(in,plain_data[i],8);
440 memset(out,0,8);
441 memset(outin,0,8);
442 des_ecb2_encrypt(in,out,ks,ks2,DES_ENCRYPT);
443 des_ecb2_encrypt(out,outin,ks,ks2,DES_DECRYPT);
444
445 if (memcmp(out,cipher_ecb2[i],8) != 0)
446 {
447 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
448 i+1,pt(key_data[i]),pt(in),pt(cipher_ecb2[i]),
449 pt(out));
450 err=1;
451 }
452 if (memcmp(in,outin,8) != 0)
453 {
454 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
455 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
456 err=1;
457 }
458 }
459#endif
460
461 printf("Doing cbc\n");
462 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
463 {
464 printf("Key error %d\n",j);
465 err=1;
466 }
467 memset(cbc_out,0,40);
468 memset(cbc_in,0,40);
469 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
470 des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
471 &iv3,DES_ENCRYPT);
472 if (memcmp(cbc_out,cbc_ok,32) != 0)
473 {
474 printf("cbc_encrypt encrypt error\n");
475 err=1;
476 }
477
478 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
479 des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
480 &iv3,DES_DECRYPT);
481 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0)
482 {
483 printf("cbc_encrypt decrypt error\n");
484 err=1;
485 }
486
487#ifndef LIBDES_LIT
488 printf("Doing desx cbc\n");
489 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
490 {
491 printf("Key error %d\n",j);
492 err=1;
493 }
494 memset(cbc_out,0,40);
495 memset(cbc_in,0,40);
496 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
497 des_xcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
498 &iv3,&cbc2_key,&cbc3_key, DES_ENCRYPT);
499 if (memcmp(cbc_out,xcbc_ok,32) != 0)
500 {
501 printf("des_xcbc_encrypt encrypt error\n");
502 err=1;
503 }
504 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
505 des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
506 &iv3,&cbc2_key,&cbc3_key, DES_DECRYPT);
507 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
508 {
509 printf("des_xcbc_encrypt decrypt error\n");
510 err=1;
511 }
512#endif
513
514 printf("Doing ede cbc\n");
515 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
516 {
517 printf("Key error %d\n",j);
518 err=1;
519 }
520 if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
521 {
522 printf("Key error %d\n",j);
523 err=1;
524 }
525 if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
526 {
527 printf("Key error %d\n",j);
528 err=1;
529 }
530 memset(cbc_out,0,40);
531 memset(cbc_in,0,40);
532 i=strlen((char *)cbc_data)+1;
533 /* i=((i+7)/8)*8; */
534 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
535
536 des_ede3_cbc_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,&iv3,
537 DES_ENCRYPT);
538 des_ede3_cbc_encrypt(&(cbc_data[16]),&(cbc_out[16]),i-16,ks,ks2,ks3,
539 &iv3,DES_ENCRYPT);
540 if (memcmp(cbc_out,cbc3_ok,
541 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
542 {
543 int n;
544
545 printf("des_ede3_cbc_encrypt encrypt error\n");
546 for(n=0 ; n < i ; ++n)
547 printf(" %02x",cbc_out[n]);
548 printf("\n");
549 for(n=0 ; n < i ; ++n)
550 printf(" %02x",cbc3_ok[n]);
551 printf("\n");
552 err=1;
553 }
554
555 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
556 des_ede3_cbc_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,DES_DECRYPT);
557 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
558 {
559 int n;
560
561 printf("des_ede3_cbc_encrypt decrypt error\n");
562 for(n=0 ; n < i ; ++n)
563 printf(" %02x",cbc_data[n]);
564 printf("\n");
565 for(n=0 ; n < i ; ++n)
566 printf(" %02x",cbc_in[n]);
567 printf("\n");
568 err=1;
569 }
570
571#ifndef LIBDES_LIT
572 printf("Doing pcbc\n");
573 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
574 {
575 printf("Key error %d\n",j);
576 err=1;
577 }
578 memset(cbc_out,0,40);
579 memset(cbc_in,0,40);
580 des_pcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
581 &cbc_iv,DES_ENCRYPT);
582 if (memcmp(cbc_out,pcbc_ok,32) != 0)
583 {
584 printf("pcbc_encrypt encrypt error\n");
585 err=1;
586 }
587 des_pcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,&cbc_iv,
588 DES_DECRYPT);
589 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
590 {
591 printf("pcbc_encrypt decrypt error\n");
592 err=1;
593 }
594
595 printf("Doing ");
596 printf("cfb8 ");
597 err+=cfb_test(8,cfb_cipher8);
598 printf("cfb16 ");
599 err+=cfb_test(16,cfb_cipher16);
600 printf("cfb32 ");
601 err+=cfb_test(32,cfb_cipher32);
602 printf("cfb48 ");
603 err+=cfb_test(48,cfb_cipher48);
604 printf("cfb64 ");
605 err+=cfb_test(64,cfb_cipher64);
606
607 printf("cfb64() ");
608 err+=cfb64_test(cfb_cipher64);
609
610 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
611 for (i=0; i<sizeof(plain); i++)
612 des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]),
613 8,1,ks,&cfb_tmp,DES_ENCRYPT);
614 if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
615 {
616 printf("cfb_encrypt small encrypt error\n");
617 err=1;
618 }
619
620 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
621 for (i=0; i<sizeof(plain); i++)
622 des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
623 8,1,ks,&cfb_tmp,DES_DECRYPT);
624 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
625 {
626 printf("cfb_encrypt small decrypt error\n");
627 err=1;
628 }
629
630 printf("ede_cfb64() ");
631 err+=ede_cfb64_test(cfb_cipher64);
632
633 printf("done\n");
634
635 printf("Doing ofb\n");
636 DES_set_key_checked(&ofb_key,&ks);
637 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
638 des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp);
639 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
640 {
641 printf("ofb_encrypt encrypt error\n");
642printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
643ofb_buf1[8+0], ofb_buf1[8+1], ofb_buf1[8+2], ofb_buf1[8+3],
644ofb_buf1[8+4], ofb_buf1[8+5], ofb_buf1[8+6], ofb_buf1[8+7]);
645printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
646ofb_buf1[8+0], ofb_cipher[8+1], ofb_cipher[8+2], ofb_cipher[8+3],
647ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]);
648 err=1;
649 }
650 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
651 des_ofb_encrypt(ofb_buf1,ofb_buf2,64,sizeof(ofb_buf1)/8,ks,&ofb_tmp);
652 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
653 {
654 printf("ofb_encrypt decrypt error\n");
655printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
656ofb_buf2[8+0], ofb_buf2[8+1], ofb_buf2[8+2], ofb_buf2[8+3],
657ofb_buf2[8+4], ofb_buf2[8+5], ofb_buf2[8+6], ofb_buf2[8+7]);
658printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
659plain[8+0], plain[8+1], plain[8+2], plain[8+3],
660plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
661 err=1;
662 }
663
664 printf("Doing ofb64\n");
665 DES_set_key_checked(&ofb_key,&ks);
666 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
667 memset(ofb_buf1,0,sizeof(ofb_buf1));
668 memset(ofb_buf2,0,sizeof(ofb_buf1));
669 num=0;
670 for (i=0; i<sizeof(plain); i++)
671 {
672 des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,&ofb_tmp,
673 &num);
674 }
675 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
676 {
677 printf("ofb64_encrypt encrypt error\n");
678 err=1;
679 }
680 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
681 num=0;
682 des_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,&ofb_tmp,
683 &num);
684 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
685 {
686 printf("ofb64_encrypt decrypt error\n");
687 err=1;
688 }
689
690 printf("Doing ede_ofb64\n");
691 DES_set_key_checked(&ofb_key,&ks);
692 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
693 memset(ofb_buf1,0,sizeof(ofb_buf1));
694 memset(ofb_buf2,0,sizeof(ofb_buf1));
695 num=0;
696 for (i=0; i<sizeof(plain); i++)
697 {
698 des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,
699 ks,&ofb_tmp,&num);
700 }
701 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
702 {
703 printf("ede_ofb64_encrypt encrypt error\n");
704 err=1;
705 }
706 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
707 num=0;
708 des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,ks,ks,
709 &ofb_tmp,&num);
710 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
711 {
712 printf("ede_ofb64_encrypt decrypt error\n");
713 err=1;
714 }
715
716 printf("Doing cbc_cksum\n");
717 DES_set_key_checked(&cbc_key,&ks);
718 cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv);
719 if (cs != cbc_cksum_ret)
720 {
721 printf("bad return value (%08lX), should be %08lX\n",
722 (unsigned long)cs,(unsigned long)cbc_cksum_ret);
723 err=1;
724 }
725 if (memcmp(cret,cbc_cksum_data,8) != 0)
726 {
727 printf("bad cbc_cksum block returned\n");
728 err=1;
729 }
730
731 printf("Doing quad_cksum\n");
732 cs=des_quad_cksum(cbc_data,(des_cblock *)lqret,
733 (long)strlen((char *)cbc_data),2,(des_cblock *)cbc_iv);
734 if (cs != 0x70d7a63aL)
735 {
736 printf("quad_cksum error, ret %08lx should be 70d7a63a\n",
737 (unsigned long)cs);
738 err=1;
739 }
740#ifdef _CRAY
741 if (lqret[0].a != 0x327eba8dL)
742 {
743 printf("quad_cksum error, out[0] %08lx is not %08lx\n",
744 (unsigned long)lqret[0].a,0x327eba8dUL);
745 err=1;
746 }
747 if (lqret[0].b != 0x201a49ccL)
748 {
749 printf("quad_cksum error, out[1] %08lx is not %08lx\n",
750 (unsigned long)lqret[0].b,0x201a49ccUL);
751 err=1;
752 }
753 if (lqret[1].a != 0x70d7a63aL)
754 {
755 printf("quad_cksum error, out[2] %08lx is not %08lx\n",
756 (unsigned long)lqret[1].a,0x70d7a63aUL);
757 err=1;
758 }
759 if (lqret[1].b != 0x501c2c26L)
760 {
761 printf("quad_cksum error, out[3] %08lx is not %08lx\n",
762 (unsigned long)lqret[1].b,0x501c2c26UL);
763 err=1;
764 }
765#else
766 if (lqret[0] != 0x327eba8dL)
767 {
768 printf("quad_cksum error, out[0] %08lx is not %08lx\n",
769 (unsigned long)lqret[0],0x327eba8dUL);
770 err=1;
771 }
772 if (lqret[1] != 0x201a49ccL)
773 {
774 printf("quad_cksum error, out[1] %08lx is not %08lx\n",
775 (unsigned long)lqret[1],0x201a49ccUL);
776 err=1;
777 }
778 if (lqret[2] != 0x70d7a63aL)
779 {
780 printf("quad_cksum error, out[2] %08lx is not %08lx\n",
781 (unsigned long)lqret[2],0x70d7a63aUL);
782 err=1;
783 }
784 if (lqret[3] != 0x501c2c26L)
785 {
786 printf("quad_cksum error, out[3] %08lx is not %08lx\n",
787 (unsigned long)lqret[3],0x501c2c26UL);
788 err=1;
789 }
790#endif
791#endif
792
793 printf("input word alignment test");
794 for (i=0; i<4; i++)
795 {
796 printf(" %d",i);
797 des_ncbc_encrypt(&(cbc_out[i]),cbc_in,
798 strlen((char *)cbc_data)+1,ks,
799 &cbc_iv,DES_ENCRYPT);
800 }
801 printf("\noutput word alignment test");
802 for (i=0; i<4; i++)
803 {
804 printf(" %d",i);
805 des_ncbc_encrypt(cbc_out,&(cbc_in[i]),
806 strlen((char *)cbc_data)+1,ks,
807 &cbc_iv,DES_ENCRYPT);
808 }
809 printf("\n");
810 printf("fast crypt test ");
811 str=crypt("testing","ef");
812 if (strcmp("efGnQx2725bI2",str) != 0)
813 {
814 printf("fast crypt error, %s should be efGnQx2725bI2\n",str);
815 err=1;
816 }
817 str=crypt("bca76;23","yA");
818 if (strcmp("yA1Rp/1hZXIJk",str) != 0)
819 {
820 printf("fast crypt error, %s should be yA1Rp/1hZXIJk\n",str);
821 err=1;
822 }
823 printf("\n");
824 return(err);
825 }
826
827static char *pt(unsigned char *p)
828 {
829 static char bufs[10][20];
830 static int bnum=0;
831 char *ret;
832 int i;
833 static char *f="0123456789ABCDEF";
834
835 ret= &(bufs[bnum++][0]);
836 bnum%=10;
837 for (i=0; i<8; i++)
838 {
839 ret[i*2]=f[(p[i]>>4)&0xf];
840 ret[i*2+1]=f[p[i]&0xf];
841 }
842 ret[16]='\0';
843 return(ret);
844 }
845
846#ifndef LIBDES_LIT
847
848static int cfb_test(int bits, unsigned char *cfb_cipher)
849 {
850 des_key_schedule ks;
851 int i,err=0;
852
853 DES_set_key_checked(&cfb_key,&ks);
854 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
855 des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp,
856 DES_ENCRYPT);
857 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
858 {
859 err=1;
860 printf("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 des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp,
866 DES_DECRYPT);
867 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
868 {
869 err=1;
870 printf("cfb_encrypt decrypt error\n");
871 for (i=0; i<24; i+=8)
872 printf("%s\n",pt(&(cfb_buf1[i])));
873 }
874 return(err);
875 }
876
877static int cfb64_test(unsigned char *cfb_cipher)
878 {
879 des_key_schedule ks;
880 int err=0,i,n;
881
882 DES_set_key_checked(&cfb_key,&ks);
883 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
884 n=0;
885 des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT);
886 des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks,
887 &cfb_tmp,&n,DES_ENCRYPT);
888 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
889 {
890 err=1;
891 printf("cfb_encrypt encrypt error\n");
892 for (i=0; i<24; i+=8)
893 printf("%s\n",pt(&(cfb_buf1[i])));
894 }
895 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
896 n=0;
897 des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT);
898 des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
899 sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT);
900 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
901 {
902 err=1;
903 printf("cfb_encrypt decrypt error\n");
904 for (i=0; i<24; i+=8)
905 printf("%s\n",pt(&(cfb_buf2[i])));
906 }
907 return(err);
908 }
909
910static int ede_cfb64_test(unsigned char *cfb_cipher)
911 {
912 des_key_schedule ks;
913 int err=0,i,n;
914
915 DES_set_key_checked(&cfb_key,&ks);
916 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
917 n=0;
918 des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n,
919 DES_ENCRYPT);
920 des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
921 sizeof(plain)-12,ks,ks,ks,
922 &cfb_tmp,&n,DES_ENCRYPT);
923 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
924 {
925 err=1;
926 printf("ede_cfb_encrypt encrypt error\n");
927 for (i=0; i<24; i+=8)
928 printf("%s\n",pt(&(cfb_buf1[i])));
929 }
930 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
931 n=0;
932 des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,
933 &cfb_tmp,&n,DES_DECRYPT);
934 des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
935 sizeof(plain)-17,ks,ks,ks,
936 &cfb_tmp,&n,DES_DECRYPT);
937 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
938 {
939 err=1;
940 printf("ede_cfb_encrypt decrypt error\n");
941 for (i=0; i<24; i+=8)
942 printf("%s\n",pt(&(cfb_buf2[i])));
943 }
944 return(err);
945 }
946
947#endif
948#endif
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..3a63c4016c
--- /dev/null
+++ b/src/lib/libcrypto/des/read2pwd.c
@@ -0,0 +1,139 @@
1/* crypto/des/read2pwd.c */
2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
56 * All rights reserved.
57 *
58 * This package is an SSL implementation written
59 * by Eric Young (eay@cryptsoft.com).
60 * The implementation was written so as to conform with Netscapes SSL.
61 *
62 * This library is free for commercial and non-commercial use as long as
63 * the following conditions are aheared to. The following conditions
64 * apply to all code found in this distribution, be it the RC4, RSA,
65 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
66 * included with this distribution is covered by the same copyright terms
67 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
68 *
69 * Copyright remains Eric Young's, and as such any Copyright notices in
70 * the code are not to be removed.
71 * If this package is used in a product, Eric Young should be given attribution
72 * as the author of the parts of the library used.
73 * This can be in the form of a textual message at program startup or
74 * in documentation (online or textual) provided with the package.
75 *
76 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions
78 * are met:
79 * 1. Redistributions of source code must retain the copyright
80 * notice, this list of conditions and the following disclaimer.
81 * 2. Redistributions in binary form must reproduce the above copyright
82 * notice, this list of conditions and the following disclaimer in the
83 * documentation and/or other materials provided with the distribution.
84 * 3. All advertising materials mentioning features or use of this software
85 * must display the following acknowledgement:
86 * "This product includes cryptographic software written by
87 * Eric Young (eay@cryptsoft.com)"
88 * The word 'cryptographic' can be left out if the rouines from the library
89 * being used are not cryptographic related :-).
90 * 4. If you include any Windows specific code (or a derivative thereof) from
91 * the apps directory (application code) you must include an acknowledgement:
92 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
93 *
94 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
95 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
98 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
99 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
100 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
101 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
102 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
103 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
104 * SUCH DAMAGE.
105 *
106 * The licence and distribution terms for any publically available version or
107 * derivative of this code cannot be changed. i.e. this code cannot simply be
108 * copied and put under another distribution licence
109 * [including the GNU Public Licence.]
110 */
111
112#include <string.h>
113#include <openssl/des.h>
114#include <openssl/ui.h>
115
116int DES_read_password(DES_cblock *key, const char *prompt, int verify)
117 {
118 int ok;
119 char buf[BUFSIZ],buff[BUFSIZ];
120
121 if ((ok=UI_UTIL_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
122 DES_string_to_key(buf,key);
123 OPENSSL_cleanse(buf,BUFSIZ);
124 OPENSSL_cleanse(buff,BUFSIZ);
125 return(ok);
126 }
127
128int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
129 int verify)
130 {
131 int ok;
132 char buf[BUFSIZ],buff[BUFSIZ];
133
134 if ((ok=UI_UTIL_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
135 DES_string_to_2keys(buf,key1,key2);
136 OPENSSL_cleanse(buf,BUFSIZ);
137 OPENSSL_cleanse(buff,BUFSIZ);
138 return(ok);
139 }
diff --git a/src/lib/libcrypto/des/read_pwd.c b/src/lib/libcrypto/des/read_pwd.c
new file mode 100644
index 0000000000..ce5fa00a37
--- /dev/null
+++ b/src/lib/libcrypto/des/read_pwd.c
@@ -0,0 +1,521 @@
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#include <openssl/e_os2.h>
60#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WIN32)
61#ifdef OPENSSL_UNISTD
62# include OPENSSL_UNISTD
63#else
64# include <unistd.h>
65#endif
66/* If unistd.h defines _POSIX_VERSION, we conclude that we
67 * are on a POSIX system and have sigaction and termios. */
68#if defined(_POSIX_VERSION)
69
70# define SIGACTION
71# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
72# define TERMIOS
73# endif
74
75#endif
76#endif
77
78/* #define SIGACTION */ /* Define this if you have sigaction() */
79
80#ifdef WIN16TTY
81#undef OPENSSL_SYS_WIN16
82#undef _WINDOWS
83#include <graph.h>
84#endif
85
86/* 06-Apr-92 Luke Brennan Support for VMS */
87#include "des_locl.h"
88#include "cryptlib.h"
89#include <signal.h>
90#include <stdio.h>
91#include <string.h>
92#include <setjmp.h>
93#include <errno.h>
94
95#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */
96#include <starlet.h>
97#ifdef __DECC
98#pragma message disable DOLLARID
99#endif
100#endif
101
102#ifdef WIN_CONSOLE_BUG
103#include <windows.h>
104#ifndef OPENSSL_SYS_WINCE
105#include <wincon.h>
106#endif
107#endif
108
109
110/* There are 5 types of terminal interface supported,
111 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
112 */
113
114#if defined(__sgi) && !defined(TERMIOS)
115#define TERMIOS
116#undef TERMIO
117#undef SGTTY
118#endif
119
120#if defined(linux) && !defined(TERMIO)
121#undef TERMIOS
122#define TERMIO
123#undef SGTTY
124#endif
125
126#ifdef _LIBC
127#undef TERMIOS
128#define TERMIO
129#undef SGTTY
130#endif
131
132#if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(MAC_OS_pre_X) && !defined(MAC_OS_GUSI_SOURCE)
133#undef TERMIOS
134#undef TERMIO
135#define SGTTY
136#endif
137
138#if defined(OPENSSL_SYS_VXWORKS)
139#undef TERMIOS
140#undef TERMIO
141#undef SGTTY
142#endif
143
144#ifdef TERMIOS
145#include <termios.h>
146#define TTY_STRUCT struct termios
147#define TTY_FLAGS c_lflag
148#define TTY_get(tty,data) tcgetattr(tty,data)
149#define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
150#endif
151
152#ifdef TERMIO
153#include <termio.h>
154#define TTY_STRUCT struct termio
155#define TTY_FLAGS c_lflag
156#define TTY_get(tty,data) ioctl(tty,TCGETA,data)
157#define TTY_set(tty,data) ioctl(tty,TCSETA,data)
158#endif
159
160#ifdef SGTTY
161#include <sgtty.h>
162#define TTY_STRUCT struct sgttyb
163#define TTY_FLAGS sg_flags
164#define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
165#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
166#endif
167
168#if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(MAC_OS_pre_X)
169#include <sys/ioctl.h>
170#endif
171
172#if defined(OPENSSL_SYS_MSDOS) && !defined(__CYGWIN32__) && !defined(OPENSSL_SYS_WINCE)
173#include <conio.h>
174#define fgets(a,b,c) noecho_fgets(a,b,c)
175#endif
176
177#ifdef OPENSSL_SYS_VMS
178#include <ssdef.h>
179#include <iodef.h>
180#include <ttdef.h>
181#include <descrip.h>
182struct IOSB {
183 short iosb$w_value;
184 short iosb$w_count;
185 long iosb$l_info;
186 };
187#endif
188
189#if defined(MAC_OS_pre_X) || defined(MAC_OS_GUSI_SOURCE)
190/*
191 * This one needs work. As a matter of fact the code is unoperational
192 * and this is only a trick to get it compiled.
193 * <appro@fy.chalmers.se>
194 */
195#define TTY_STRUCT int
196#endif
197
198#ifndef NX509_SIG
199#define NX509_SIG 32
200#endif
201
202static void read_till_nl(FILE *);
203static void recsig(int);
204static void pushsig(void);
205static void popsig(void);
206#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
207static int noecho_fgets(char *buf, int size, FILE *tty);
208#endif
209#ifdef SIGACTION
210 static struct sigaction savsig[NX509_SIG];
211#else
212 static void (*savsig[NX509_SIG])(int );
213#endif
214static jmp_buf save;
215
216int des_read_pw_string(char *buf, int length, const char *prompt,
217 int verify)
218 {
219 char buff[BUFSIZ];
220 int ret;
221
222 ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
223 OPENSSL_cleanse(buff,BUFSIZ);
224 return(ret);
225 }
226
227#ifdef OPENSSL_SYS_WINCE
228
229int des_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
230 {
231 memset(buf,0,size);
232 memset(buff,0,size);
233 return(0);
234 }
235
236#elif defined(OPENSSL_SYS_WIN16)
237
238int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify)
239 {
240 memset(buf,0,size);
241 memset(buff,0,size);
242 return(0);
243 }
244
245#else /* !OPENSSL_SYS_WINCE && !OPENSSL_SYS_WIN16 */
246
247static void read_till_nl(FILE *in)
248 {
249#define SIZE 4
250 char buf[SIZE+1];
251
252 do {
253 fgets(buf,SIZE,in);
254 } while (strchr(buf,'\n') == NULL);
255 }
256
257
258/* return 0 if ok, 1 (or -1) otherwise */
259int des_read_pw(char *buf, char *buff, int size, const char *prompt,
260 int verify)
261 {
262#ifdef OPENSSL_SYS_VMS
263 struct IOSB iosb;
264 $DESCRIPTOR(terminal,"TT");
265 long tty_orig[3], tty_new[3];
266 long status;
267 unsigned short channel = 0;
268#else
269#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
270 TTY_STRUCT tty_orig,tty_new;
271#endif
272#endif
273 int number;
274 int ok;
275 /* statics are simply to avoid warnings about longjmp clobbering
276 things */
277 static int ps;
278 int is_a_tty;
279 static FILE *tty;
280 char *p;
281
282 if (setjmp(save))
283 {
284 ok=0;
285 goto error;
286 }
287
288 number=5;
289 ok=0;
290 ps=0;
291 is_a_tty=1;
292 tty=NULL;
293
294#ifdef OPENSSL_SYS_MSDOS
295 if ((tty=fopen("con","r")) == NULL)
296 tty=stdin;
297#elif defined(MAC_OS_pre_X) || defined(OPENSSL_SYS_VXWORKS)
298 tty=stdin;
299#else
300#ifndef OPENSSL_SYS_MPE
301 if ((tty=fopen("/dev/tty","r")) == NULL)
302#endif
303 tty=stdin;
304#endif
305
306#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
307 if (TTY_get(fileno(tty),&tty_orig) == -1)
308 {
309#ifdef ENOTTY
310 if (errno == ENOTTY)
311 is_a_tty=0;
312 else
313#endif
314#ifdef EINVAL
315 /* Ariel Glenn ariel@columbia.edu reports that solaris
316 * can return EINVAL instead. This should be ok */
317 if (errno == EINVAL)
318 is_a_tty=0;
319 else
320#endif
321 return(-1);
322 }
323 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
324#endif
325#ifdef OPENSSL_SYS_VMS
326 status = sys$assign(&terminal,&channel,0,0);
327 if (status != SS$_NORMAL)
328 return(-1);
329 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
330 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
331 return(-1);
332#endif
333
334 pushsig();
335 ps=1;
336
337#ifdef TTY_FLAGS
338 tty_new.TTY_FLAGS &= ~ECHO;
339#endif
340
341#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
342 if (is_a_tty && (TTY_set(fileno(tty),&tty_new) == -1))
343#ifdef OPENSSL_SYS_MPE
344 ; /* MPE lies -- echo really has been disabled */
345#else
346 return(-1);
347#endif
348#endif
349#ifdef OPENSSL_SYS_VMS
350 tty_new[0] = tty_orig[0];
351 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
352 tty_new[2] = tty_orig[2];
353 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
354 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
355 return(-1);
356#endif
357 ps=2;
358
359 while ((!ok) && (number--))
360 {
361 fputs(prompt,stderr);
362 fflush(stderr);
363
364 buf[0]='\0';
365 fgets(buf,size,tty);
366 if (feof(tty)) goto error;
367 if (ferror(tty)) goto error;
368 if ((p=(char *)strchr(buf,'\n')) != NULL)
369 *p='\0';
370 else read_till_nl(tty);
371 if (verify)
372 {
373 fprintf(stderr,"\nVerifying password - %s",prompt);
374 fflush(stderr);
375 buff[0]='\0';
376 fgets(buff,size,tty);
377 if (feof(tty)) goto error;
378 if ((p=(char *)strchr(buff,'\n')) != NULL)
379 *p='\0';
380 else read_till_nl(tty);
381
382 if (strcmp(buf,buff) != 0)
383 {
384 fprintf(stderr,"\nVerify failure");
385 fflush(stderr);
386 break;
387 /* continue; */
388 }
389 }
390 ok=1;
391 }
392
393error:
394 fprintf(stderr,"\n");
395#if 0
396 perror("fgets(tty)");
397#endif
398 /* What can we do if there is an error? */
399#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
400 if (ps >= 2) TTY_set(fileno(tty),&tty_orig);
401#endif
402#ifdef OPENSSL_SYS_VMS
403 if (ps >= 2)
404 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0
405 ,tty_orig,12,0,0,0,0);
406#endif
407
408 if (ps >= 1) popsig();
409 if (stdin != tty) fclose(tty);
410#ifdef OPENSSL_SYS_VMS
411 status = sys$dassgn(channel);
412#endif
413 return(!ok);
414 }
415
416static void pushsig(void)
417 {
418 int i;
419#ifdef SIGACTION
420 struct sigaction sa;
421
422 memset(&sa,0,sizeof sa);
423 sa.sa_handler=recsig;
424#endif
425
426 for (i=1; i<NX509_SIG; i++)
427 {
428#ifdef SIGUSR1
429 if (i == SIGUSR1)
430 continue;
431#endif
432#ifdef SIGUSR2
433 if (i == SIGUSR2)
434 continue;
435#endif
436#ifdef SIGACTION
437 sigaction(i,&sa,&savsig[i]);
438#else
439 savsig[i]=signal(i,recsig);
440#endif
441 }
442
443#ifdef SIGWINCH
444 signal(SIGWINCH,SIG_DFL);
445#endif
446 }
447
448static void popsig(void)
449 {
450 int i;
451
452 for (i=1; i<NX509_SIG; i++)
453 {
454#ifdef SIGUSR1
455 if (i == SIGUSR1)
456 continue;
457#endif
458#ifdef SIGUSR2
459 if (i == SIGUSR2)
460 continue;
461#endif
462#ifdef SIGACTION
463 sigaction(i,&savsig[i],NULL);
464#else
465 signal(i,savsig[i]);
466#endif
467 }
468 }
469
470static void recsig(int i)
471 {
472 longjmp(save,1);
473#ifdef LINT
474 i=i;
475#endif
476 }
477
478#ifdef OPENSSL_SYS_MSDOS
479static int noecho_fgets(char *buf, int size, FILE *tty)
480 {
481 int i;
482 char *p;
483
484 p=buf;
485 for (;;)
486 {
487 if (size == 0)
488 {
489 *p='\0';
490 break;
491 }
492 size--;
493#ifdef WIN16TTY
494 i=_inchar();
495#else
496 i=getch();
497#endif
498 if (i == '\r') i='\n';
499 *(p++)=i;
500 if (i == '\n')
501 {
502 *p='\0';
503 break;
504 }
505 }
506#ifdef WIN_CONSOLE_BUG
507/* Win95 has several evil console bugs: one of these is that the
508 * last character read using getch() is passed to the next read: this is
509 * usually a CR so this can be trouble. No STDIO fix seems to work but
510 * flushing the console appears to do the trick.
511 */
512 {
513 HANDLE inh;
514 inh = GetStdHandle(STD_INPUT_HANDLE);
515 FlushConsoleInputBuffer(inh);
516 }
517#endif
518 return(strlen(buf));
519 }
520#endif
521#endif /* !OPENSSL_SYS_WINCE && !WIN16 */
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..d937d08da5
--- /dev/null
+++ b/src/lib/libcrypto/des/rpc_enc.c
@@ -0,0 +1,98 @@
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
63int _des_crypt(char *buf,int len,struct desparams *desp);
64int _des_crypt(char *buf, int len, struct desparams *desp)
65 {
66 DES_key_schedule ks;
67 int enc;
68
69 DES_set_key_unchecked(&desp->des_key,&ks);
70 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
71
72 if (desp->des_mode == CBC)
73 DES_ecb_encrypt((const_DES_cblock *)desp->UDES.UDES_buf,
74 (DES_cblock *)desp->UDES.UDES_buf,&ks,
75 enc);
76 else
77 {
78 DES_ncbc_encrypt(desp->UDES.UDES_buf,desp->UDES.UDES_buf,
79 len,&ks,&desp->des_ivec,enc);
80#ifdef undef
81 /* len will always be %8 if called from common_crypt
82 * in secure_rpc.
83 * Libdes's cbc encrypt does not copy back the iv,
84 * so we have to do it here. */
85 /* It does now :-) eay 20/09/95 */
86
87 a=(char *)&(desp->UDES.UDES_buf[len-8]);
88 b=(char *)&(desp->des_ivec[0]);
89
90 *(a++)= *(b++); *(a++)= *(b++);
91 *(a++)= *(b++); *(a++)= *(b++);
92 *(a++)= *(b++); *(a++)= *(b++);
93 *(a++)= *(b++); *(a++)= *(b++);
94#endif
95 }
96 return(1);
97 }
98
diff --git a/src/lib/libcrypto/des/rpw.c b/src/lib/libcrypto/des/rpw.c
new file mode 100644
index 0000000000..8a9473c4f9
--- /dev/null
+++ b/src/lib/libcrypto/des/rpw.c
@@ -0,0 +1,99 @@
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 <openssl/des.h>
61
62int main(int argc, char *argv[])
63 {
64 DES_cblock k,k1;
65 int i;
66
67 printf("read passwd\n");
68 if ((i=des_read_password(&k,"Enter password:",0)) == 0)
69 {
70 printf("password = ");
71 for (i=0; i<8; i++)
72 printf("%02x ",k[i]);
73 }
74 else
75 printf("error %d\n",i);
76 printf("\n");
77 printf("read 2passwds and verify\n");
78 if ((i=des_read_2passwords(&k,&k1,
79 "Enter verified password:",1)) == 0)
80 {
81 printf("password1 = ");
82 for (i=0; i<8; i++)
83 printf("%02x ",k[i]);
84 printf("\n");
85 printf("password2 = ");
86 for (i=0; i<8; i++)
87 printf("%02x ",k1[i]);
88 printf("\n");
89 exit(1);
90 }
91 else
92 {
93 printf("error %d\n",i);
94 exit(0);
95 }
96#ifdef LINT
97 return(0);
98#endif
99 }
diff --git a/src/lib/libcrypto/des/speed.c b/src/lib/libcrypto/des/speed.c
new file mode 100644
index 0000000000..48fc1d49fc
--- /dev/null
+++ b/src/lib/libcrypto/des/speed.c
@@ -0,0 +1,310 @@
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#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
63#define TIMES
64#endif
65
66#include <stdio.h>
67
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD_IO
70OPENSSL_DECLARE_EXIT
71
72#include <signal.h>
73#ifndef _IRIX
74#include <time.h>
75#endif
76#ifdef TIMES
77#include <sys/types.h>
78#include <sys/times.h>
79#endif
80
81/* Depending on the VMS version, the tms structure is perhaps defined.
82 The __TMS macro will show if it was. If it wasn't defined, we should
83 undefine TIMES, since that tells the rest of the program how things
84 should be handled. -- Richard Levitte */
85#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
86#undef TIMES
87#endif
88
89#ifndef TIMES
90#include <sys/timeb.h>
91#endif
92
93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
95#include <limits.h>
96#include <sys/param.h>
97#endif
98
99#include <openssl/des.h>
100
101/* The following if from times(3) man page. It may need to be changed */
102#ifndef HZ
103# ifndef CLK_TCK
104# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
105# define HZ 100.0
106# else /* _BSD_CLK_TCK_ */
107# define HZ ((double)_BSD_CLK_TCK_)
108# endif
109# else /* CLK_TCK */
110# define HZ ((double)CLK_TCK)
111# endif
112#endif
113
114#define BUFSIZE ((long)1024)
115long run=0;
116
117double Time_F(int s);
118#ifdef SIGALRM
119#if defined(__STDC__) || defined(sgi) || defined(_AIX)
120#define SIGRETTYPE void
121#else
122#define SIGRETTYPE int
123#endif
124
125SIGRETTYPE sig_done(int sig);
126SIGRETTYPE sig_done(int sig)
127 {
128 signal(SIGALRM,sig_done);
129 run=0;
130#ifdef LINT
131 sig=sig;
132#endif
133 }
134#endif
135
136#define START 0
137#define STOP 1
138
139double Time_F(int s)
140 {
141 double ret;
142#ifdef TIMES
143 static struct tms tstart,tend;
144
145 if (s == START)
146 {
147 times(&tstart);
148 return(0);
149 }
150 else
151 {
152 times(&tend);
153 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
154 return((ret == 0.0)?1e-6:ret);
155 }
156#else /* !times() */
157 static struct timeb tstart,tend;
158 long i;
159
160 if (s == START)
161 {
162 ftime(&tstart);
163 return(0);
164 }
165 else
166 {
167 ftime(&tend);
168 i=(long)tend.millitm-(long)tstart.millitm;
169 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
170 return((ret == 0.0)?1e-6:ret);
171 }
172#endif
173 }
174
175int main(int argc, char **argv)
176 {
177 long count;
178 static unsigned char buf[BUFSIZE];
179 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
180 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
181 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
182 DES_key_schedule sch,sch2,sch3;
183 double a,b,c,d,e;
184#ifndef SIGALRM
185 long ca,cb,cc,cd,ce;
186#endif
187
188#ifndef TIMES
189 printf("To get the most accurate results, try to run this\n");
190 printf("program when this computer is idle.\n");
191#endif
192
193 DES_set_key_unchecked(&key2,&sch2);
194 DES_set_key_unchecked(&key3,&sch3);
195
196#ifndef SIGALRM
197 printf("First we calculate the approximate speed ...\n");
198 DES_set_key_unchecked(&key,&sch);
199 count=10;
200 do {
201 long i;
202 DES_LONG data[2];
203
204 count*=2;
205 Time_F(START);
206 for (i=count; i; i--)
207 DES_encrypt1(data,&sch,DES_ENCRYPT);
208 d=Time_F(STOP);
209 } while (d < 3.0);
210 ca=count;
211 cb=count*3;
212 cc=count*3*8/BUFSIZE+1;
213 cd=count*8/BUFSIZE+1;
214 ce=count/20+1;
215 printf("Doing set_key %ld times\n",ca);
216#define COND(d) (count != (d))
217#define COUNT(d) (d)
218#else
219#define COND(c) (run)
220#define COUNT(d) (count)
221 signal(SIGALRM,sig_done);
222 printf("Doing set_key for 10 seconds\n");
223 alarm(10);
224#endif
225
226 Time_F(START);
227 for (count=0,run=1; COND(ca); count++)
228 DES_set_key_unchecked(&key,&sch);
229 d=Time_F(STOP);
230 printf("%ld set_key's in %.2f seconds\n",count,d);
231 a=((double)COUNT(ca))/d;
232
233#ifdef SIGALRM
234 printf("Doing DES_encrypt's for 10 seconds\n");
235 alarm(10);
236#else
237 printf("Doing DES_encrypt %ld times\n",cb);
238#endif
239 Time_F(START);
240 for (count=0,run=1; COND(cb); count++)
241 {
242 DES_LONG data[2];
243
244 DES_encrypt1(data,&sch,DES_ENCRYPT);
245 }
246 d=Time_F(STOP);
247 printf("%ld DES_encrypt's in %.2f second\n",count,d);
248 b=((double)COUNT(cb)*8)/d;
249
250#ifdef SIGALRM
251 printf("Doing DES_cbc_encrypt on %ld byte blocks for 10 seconds\n",
252 BUFSIZE);
253 alarm(10);
254#else
255 printf("Doing DES_cbc_encrypt %ld times on %ld byte blocks\n",cc,
256 BUFSIZE);
257#endif
258 Time_F(START);
259 for (count=0,run=1; COND(cc); count++)
260 DES_ncbc_encrypt(buf,buf,BUFSIZE,&sch,
261 &key,DES_ENCRYPT);
262 d=Time_F(STOP);
263 printf("%ld DES_cbc_encrypt's of %ld byte blocks in %.2f second\n",
264 count,BUFSIZE,d);
265 c=((double)COUNT(cc)*BUFSIZE)/d;
266
267#ifdef SIGALRM
268 printf("Doing DES_ede_cbc_encrypt on %ld byte blocks for 10 seconds\n",
269 BUFSIZE);
270 alarm(10);
271#else
272 printf("Doing DES_ede_cbc_encrypt %ld times on %ld byte blocks\n",cd,
273 BUFSIZE);
274#endif
275 Time_F(START);
276 for (count=0,run=1; COND(cd); count++)
277 DES_ede3_cbc_encrypt(buf,buf,BUFSIZE,
278 &sch,
279 &sch2,
280 &sch3,
281 &key,
282 DES_ENCRYPT);
283 d=Time_F(STOP);
284 printf("%ld DES_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n",
285 count,BUFSIZE,d);
286 d=((double)COUNT(cd)*BUFSIZE)/d;
287
288#ifdef SIGALRM
289 printf("Doing crypt for 10 seconds\n");
290 alarm(10);
291#else
292 printf("Doing crypt %ld times\n",ce);
293#endif
294 Time_F(START);
295 for (count=0,run=1; COND(ce); count++)
296 crypt("testing1","ef");
297 e=Time_F(STOP);
298 printf("%ld crypts in %.2f second\n",count,e);
299 e=((double)COUNT(ce))/e;
300
301 printf("set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
302 printf("DES raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
303 printf("DES cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
304 printf("DES ede cbc bytes per sec = %12.2f (%9.3fuS)\n",d,8.0e6/d);
305 printf("crypt per sec = %12.2f (%9.3fuS)\n",e,1.0e6/e);
306 exit(0);
307#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
308 return(0);
309#endif
310 }
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..0864285ef6
--- /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 believe 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);