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/INSTALL69
-rw-r--r--src/lib/libcrypto/des/Imakefile35
-rw-r--r--src/lib/libcrypto/des/KERBEROS41
-rw-r--r--src/lib/libcrypto/des/README54
-rw-r--r--src/lib/libcrypto/des/VERSION411
-rw-r--r--src/lib/libcrypto/des/asm/des686.pl230
-rw-r--r--src/lib/libcrypto/des/asm/readme131
-rw-r--r--src/lib/libcrypto/des/cbc3_enc.c99
-rw-r--r--src/lib/libcrypto/des/des.c964
-rw-r--r--src/lib/libcrypto/des/des3s.cpp67
-rw-r--r--src/lib/libcrypto/des/des_opts.c620
-rw-r--r--src/lib/libcrypto/des/des_ver.h60
-rw-r--r--src/lib/libcrypto/des/dess.cpp67
-rw-r--r--src/lib/libcrypto/des/destest.c882
-rw-r--r--src/lib/libcrypto/des/makefile.bc50
-rw-r--r--src/lib/libcrypto/des/options.txt39
-rw-r--r--src/lib/libcrypto/des/read2pwd.c90
-rw-r--r--src/lib/libcrypto/des/read_pwd.c459
-rw-r--r--src/lib/libcrypto/des/rpc_des.h131
-rw-r--r--src/lib/libcrypto/des/rpc_enc.c107
-rw-r--r--src/lib/libcrypto/des/rpw.c101
-rw-r--r--src/lib/libcrypto/des/speed.c329
-rw-r--r--src/lib/libcrypto/des/t/test27
-rw-r--r--src/lib/libcrypto/des/times/486-50.sol16
-rw-r--r--src/lib/libcrypto/des/times/586-100.lnx20
-rw-r--r--src/lib/libcrypto/des/times/686-200.fre18
-rw-r--r--src/lib/libcrypto/des/times/aix.cc26
-rw-r--r--src/lib/libcrypto/des/times/alpha.cc18
-rw-r--r--src/lib/libcrypto/des/times/hpux.cc17
-rw-r--r--src/lib/libcrypto/des/times/sparc.gcc17
-rw-r--r--src/lib/libcrypto/des/times/usparc.cc31
-rw-r--r--src/lib/libcrypto/des/typemap34
34 files changed, 5547 insertions, 0 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/INSTALL b/src/lib/libcrypto/des/INSTALL
new file mode 100644
index 0000000000..32457d775c
--- /dev/null
+++ b/src/lib/libcrypto/des/INSTALL
@@ -0,0 +1,69 @@
1Check the CC and CFLAGS lines in the makefile
2
3If your C library does not support the times(3) function, change the
4#define TIMES to
5#undef TIMES in speed.c
6If it does, check the HZ value for the times(3) function.
7If your system does not define CLK_TCK it will be assumed to
8be 100.0.
9
10If possible use gcc v 2.7.?
11Turn on the maximum optimising (normally '-O3 -fomit-frame-pointer' for gcc)
12In recent times, some system compilers give better performace.
13
14type 'make'
15
16run './destest' to check things are ok.
17run './rpw' to check the tty code for reading passwords works.
18run './speed' to see how fast those optimisations make the library run :-)
19run './des_opts' to determin the best compile time options.
20
21The output from des_opts should be put in the makefile options and des_enc.c
22should be rebuilt. For 64 bit computers, do not use the DES_PTR option.
23For the DEC Alpha, edit des.h and change DES_LONG to 'unsigned int'
24and then you can use the 'DES_PTR' option.
25
26The file options.txt has the options listed for best speed on quite a
27few systems. Look and the options (UNROLL, PTR, RISC2 etc) and then
28turn on the relevent option in the Makefile
29
30There are some special Makefile targets that make life easier.
31make cc - standard cc build
32make gcc - standard gcc build
33make x86-elf - x86 assembler (elf), linux-elf.
34make x86-out - x86 assembler (a.out), FreeBSD
35make x86-solaris- x86 assembler
36make x86-bsdi - x86 assembler (a.out with primative assembler).
37
38If at all possible use the assembler (for Windows NT/95, use
39asm/win32.obj to link with). The x86 assembler is very very fast.
40
41A make install will by default install
42libdes.a in /usr/local/lib/libdes.a
43des in /usr/local/bin/des
44des_crypt.man in /usr/local/man/man3/des_crypt.3
45des.man in /usr/local/man/man1/des.1
46des.h in /usr/include/des.h
47
48des(1) should be compatible with sunOS's but I have been unable to
49test it.
50
51These routines should compile on MSDOS, most 32bit and 64bit version
52of Unix (BSD and SYSV) and VMS, without modification.
53The only problems should be #include files that are in the wrong places.
54
55These routines can be compiled under MSDOS.
56I have successfully encrypted files using des(1) under MSDOS and then
57decrypted the files on a SparcStation.
58I have been able to compile and test the routines with
59Microsoft C v 5.1 and Turbo C v 2.0.
60The code in this library is in no way optimised for the 16bit
61operation of MSDOS.
62
63When building for glibc, ignore all of the above and just unpack into
64glibc-1.??/des and then gmake as per normal.
65
66As a final note on performace. Certain CPUs like sparcs and Alpha often give
67a %10 speed difference depending on the link order. It is rather anoying
68when one program reports 'x' DES encrypts a second and another reports
69'x*0.9' the speed.
diff --git a/src/lib/libcrypto/des/Imakefile b/src/lib/libcrypto/des/Imakefile
new file mode 100644
index 0000000000..1b9b5629e1
--- /dev/null
+++ b/src/lib/libcrypto/des/Imakefile
@@ -0,0 +1,35 @@
1# This Imakefile has not been tested for a while but it should still
2# work when placed in the correct directory in the kerberos v 4 distribution
3
4SRCS= cbc_cksm.c cbc_enc.c ecb_enc.c pcbc_enc.c \
5 qud_cksm.c rand_key.c read_pwd.c set_key.c str2key.c \
6 enc_read.c enc_writ.c fcrypt.c cfb_enc.c \
7 ecb3_enc.c ofb_enc.c ofb64enc.c
8
9OBJS= cbc_cksm.o cbc_enc.o ecb_enc.o pcbc_enc.o \
10 qud_cksm.o rand_key.o read_pwd.o set_key.o str2key.o \
11 enc_read.o enc_writ.o fcrypt.o cfb_enc.o \
12 ecb3_enc.o ofb_enc.o ofb64enc.o
13
14GENERAL=COPYRIGHT FILES INSTALL Imakefile README VERSION makefile times \
15 vms.com KERBEROS
16DES= des.c des.man
17TESTING=destest.c speed.c rpw.c
18LIBDES= des_crypt.man des.h des_locl.h podd.h sk.h spr.h
19
20PERL= des.pl testdes.pl doIP doPC1 doPC2 PC1 PC2 shifts.pl
21
22CODE= $(GENERAL) $(DES) $(TESTING) $(SRCS) $(LIBDES) $(PERL)
23
24SRCDIR=$(SRCTOP)/lib/des
25
26DBG= -O
27INCLUDE= -I$(SRCDIR)
28CC= cc
29
30library_obj_rule()
31
32install_library_target(des,$(OBJS),$(SRCS),)
33
34test(destest,libdes.a,)
35test(rpw,libdes.a,)
diff --git a/src/lib/libcrypto/des/KERBEROS b/src/lib/libcrypto/des/KERBEROS
new file mode 100644
index 0000000000..f401b10014
--- /dev/null
+++ b/src/lib/libcrypto/des/KERBEROS
@@ -0,0 +1,41 @@
1 [ This is an old file, I don't know if it is true anymore
2 but I will leave the file here - eay 21/11/95 ]
3
4To use this library with Bones (kerberos without DES):
51) Get my modified Bones - eBones. It can be found on
6 gondwana.ecr.mu.oz.au (128.250.1.63) /pub/athena/eBones-p9.tar.Z
7 and
8 nic.funet.fi (128.214.6.100) /pub/unix/security/Kerberos/eBones-p9.tar.Z
9
102) Unpack this library in src/lib/des, makeing sure it is version
11 3.00 or greater (libdes.tar.93-10-07.Z). This versions differences
12 from the version in comp.sources.misc volume 29 patchlevel2.
13 The primarily difference is that it should compile under kerberos :-).
14 It can be found at.
15 ftp.psy.uq.oz.au (130.102.32.1) /pub/DES/libdes.tar.93-10-07.Z
16
17Now do a normal kerberos build and things should work.
18
19One problem I found when I was build on my local sun.
20---
21For sunOS 4.1.1 apply the following patch to src/util/ss/make_commands.c
22
23*** make_commands.c.orig Fri Jul 3 04:18:35 1987
24--- make_commands.c Wed May 20 08:47:42 1992
25***************
26*** 98,104 ****
27 if (!rename(o_file, z_file)) {
28 if (!vfork()) {
29 chdir("/tmp");
30! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r", "-n",
31 z_file+5, 0);
32 perror("/bin/ld");
33 _exit(1);
34--- 98,104 ----
35 if (!rename(o_file, z_file)) {
36 if (!vfork()) {
37 chdir("/tmp");
38! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r",
39 z_file+5, 0);
40 perror("/bin/ld");
41 _exit(1);
diff --git a/src/lib/libcrypto/des/README b/src/lib/libcrypto/des/README
new file mode 100644
index 0000000000..621a5ab467
--- /dev/null
+++ b/src/lib/libcrypto/des/README
@@ -0,0 +1,54 @@
1
2 libdes, Version 4.01 10-Jan-97
3
4 Copyright (c) 1997, Eric Young
5 All rights reserved.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms specified in COPYRIGHT.
9
10--
11The primary ftp site for this library is
12ftp://ftp.psy.uq.oz.au/pub/Crypto/DES/libdes-x.xx.tar.gz
13libdes is now also shipped with SSLeay. Primary ftp site of
14ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL/SSLeay-x.x.x.tar.gz
15
16The best way to build this library is to build it as part of SSLeay.
17
18This kit builds a DES encryption library and a DES encryption program.
19It supports ecb, cbc, ofb, cfb, triple ecb, triple cbc, triple ofb,
20triple cfb, desx, and MIT's pcbc encryption modes and also has a fast
21implementation of crypt(3).
22It contains support routines to read keys from a terminal,
23generate a random key, generate a key from an arbitrary length string,
24read/write encrypted data from/to a file descriptor.
25
26The implementation was written so as to conform with the manual entry
27for the des_crypt(3) library routines from MIT's project Athena.
28
29destest should be run after compilation to test the des routines.
30rpw should be run after compilation to test the read password routines.
31The des program is a replacement for the sun des command. I believe it
32conforms to the sun version.
33
34The Imakefile is setup for use in the kerberos distribution.
35
36These routines are best compiled with gcc or any other good
37optimising compiler.
38Just turn you optimiser up to the highest settings and run destest
39after the build to make sure everything works.
40
41I believe these routines are close to the fastest and most portable DES
42routines that use small lookup tables (4.5k) that are publicly available.
43The fcrypt routine is faster than ufc's fcrypt (when compiling with
44gcc2 -O2) on the sparc 2 (1410 vs 1270) but is not so good on other machines
45(on a sun3/260 168 vs 336). It is a function of CPU on chip cache size.
46[ 10-Jan-97 and a function of an incorrect speed testing program in
47 ufc which gave much better test figures that reality ].
48
49It is worth noting that on sparc and Alpha CPUs, performance of the DES
50library can vary by upto %10 due to the positioning of files after application
51linkage.
52
53Eric Young (eay@cryptsoft.com)
54
diff --git a/src/lib/libcrypto/des/VERSION b/src/lib/libcrypto/des/VERSION
new file mode 100644
index 0000000000..f62d8bdac0
--- /dev/null
+++ b/src/lib/libcrypto/des/VERSION
@@ -0,0 +1,411 @@
1 Defining SIGACTION causes sigaction() to be used instead of signal().
2 SIGUSR1/SIGUSR2 are no longer mapped in the read tty stuff because it
3 can cause problems. This should hopefully not affect normal
4 applications.
5
6Version 4.04
7 Fixed a few tests in destest. Also added x86 assember for
8 des_ncbc_encrypt() which is the standard cbc mode function.
9 This makes a very very large performace difference.
10 Ariel Glenn ariel@columbia.edu reports that the terminal
11 'turn echo off' can return (errno == EINVAL) under solaris
12 when redirection is used. So I now catch that as well as ENOTTY.
13
14
15Version 4.03
16 Left a static out of enc_write.c, which caused to buffer to be
17 continiously malloc()ed. Does anyone use these functions? I keep
18 on feeling like removing them since I only had these in there
19 for a version of kerberised login. Anyway, this was pointed out
20 by Theo de Raadt <deraadt@cvs.openbsd.org>
21 The 'n' bit ofb code was wrong, it was not shifting the shift
22 register. It worked correctly for n == 64. Thanks to
23 Gigi Ankeny <Gigi.Ankeny@Eng.Sun.COM> for pointing this one out.
24
25Version 4.02
26 I was doing 'if (memcmp(weak_keys[i],key,sizeof(key)) == 0)'
27 when checking for weak keys which is wrong :-(, pointed out by
28 Markus F.X.J. Oberhumer <markus.oberhumer@jk.uni-linz.ac.at>.
29
30Version 4.01
31 Even faster inner loop in the DES assembler for x86 and a modification
32 for IP/FP which is faster on x86. Both of these changes are
33 from Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>. His
34 changes make the assembler run %40 faster on a pentium. This is just
35 a case of getting the instruction sequence 'just right'.
36 All credit to 'Svend' :-)
37 Quite a few special x86 'make' targets.
38 A libdes-l (lite) distribution.
39
40Version 4.00
41 After a bit of a pause, I'll up the major version number since this
42 is mostly a performace release. I've added x86 assembler and
43 added more options for performance. A %28 speedup for gcc
44 on a pentium and the assembler is a %50 speedup.
45 MIPS CPU's, sparc and Alpha are the main CPU's with speedups.
46 Run des_opts to work out which options should be used.
47 DES_RISC1/DES_RISC2 use alternative inner loops which use
48 more registers but should give speedups on any CPU that does
49 dual issue (pentium). DES_UNROLL unrolls the inner loop,
50 which costs in code size.
51
52Version 3.26
53 I've finally removed one of the shifts in D_ENCRYPT. This
54 meant I've changed the des_SPtrans table (spr.h), the set_key()
55 function and some things in des_enc.c. This has definitly
56 made things faster :-). I've known about this one for some
57 time but I've been too lazy to follow it up :-).
58 Noticed that in the D_ENCRYPT() macro, we can just do L^=(..)^(..)^..
59 instead of L^=((..)|(..)|(..).. This should save a register at
60 least.
61 Assember for x86. The file to replace is des_enc.c, which is replaced
62 by one of the assembler files found in asm. Look at des/asm/readme
63 for more info.
64
65 /* Modification to fcrypt so it can be compiled to support
66 HPUX 10.x's long password format, define -DLONGCRYPT to use this.
67 Thanks to Jens Kupferschmidt <bt1cu@hpboot.rz.uni-leipzig.de>. */
68
69 SIGWINCH case put in des_read_passwd() so the function does not
70 'exit' if this function is recieved.
71
72Version 3.25 17/07/96
73 Modified read_pwd.c so that stdin can be read if not a tty.
74 Thanks to Jeff Barber <jeffb@issl.atl.hp.com> for the patches.
75 des_init_random_number_generator() shortened due to VMS linker
76 limits.
77 Added RSA's DESX cbc mode. It is a form of cbc encryption, with 2
78 8 byte quantites xored before and after encryption.
79 des_xcbc_encryption() - the name is funny to preserve the des_
80 prefix on all functions.
81
82Version 3.24 20/04/96
83 The DES_PTR macro option checked and used by SSLeay configuration
84
85Version 3.23 11/04/96
86 Added DES_LONG. If defined to 'unsigned int' on the DEC Alpha,
87 it gives a %20 speedup :-)
88 Fixed the problem with des.pl under perl5. The patches were
89 sent by Ed Kubaitis (ejk@uiuc.edu).
90 if fcrypt.c, changed values to handle illegal salt values the way
91 normal crypt() implementations do. Some programs apparently use
92 them :-(. The patch was sent by Bjorn Gronvall <bg@sics.se>
93
94Version 3.22 29/11/95
95 Bug in des(1), an error with the uuencoding stuff when the
96 'data' is small, thanks to Geoff Keating <keagchon@mehta.anu.edu.au>
97 for the patch.
98
99Version 3.21 22/11/95
100 After some emailing back and forth with
101 Colin Plumb <colin@nyx10.cs.du.edu>, I've tweaked a few things
102 and in a future version I will probably put in some of the
103 optimisation he suggested for use with the DES_USE_PTR option.
104 Extra routines from Mark Murray <mark@grondar.za> for use in
105 freeBSD. They mostly involve random number generation for use
106 with kerberos. They involve evil machine specific system calls
107 etc so I would normally suggest pushing this stuff into the
108 application and/or using RAND_seed()/RAND_bytes() if you are
109 using this DES library as part of SSLeay.
110 Redone the read_pw() function so that it is cleaner and
111 supports termios, thanks to Sameer Parekh <sameer@c2.org>
112 for the initial patches for this.
113 Renamed 3ecb_encrypt() to ecb3_encrypt(). This has been
114 done just to make things more consistent.
115 I have also now added triple DES versions of cfb and ofb.
116
117Version 3.20
118 Damn, Damn, Damn, as pointed out by Mike_Spreitzer.PARC@xerox.com,
119 my des_random_seed() function was only copying 4 bytes of the
120 passed seed into the init structure. It is now fixed to copy 8.
121 My own suggestion is to used something like MD5 :-)
122
123Version 3.19
124 While looking at my code one day, I though, why do I keep on
125 calling des_encrypt(in,out,ks,enc) when every function that
126 calls it has in and out the same. So I dropped the 'out'
127 parameter, people should not be using this function.
128
129Version 3.18 30/08/95
130 Fixed a few bit with the distribution and the filenames.
131 3.17 had been munged via a move to DOS and back again.
132 NO CODE CHANGES
133
134Version 3.17 14/07/95
135 Fixed ede3 cbc which I had broken in 3.16. I have also
136 removed some unneeded variables in 7-8 of the routines.
137
138Version 3.16 26/06/95
139 Added des_encrypt2() which does not use IP/FP, used by triple
140 des routines. Tweaked things a bit elsewhere. %13 speedup on
141 sparc and %6 on a R4400 for ede3 cbc mode.
142
143Version 3.15 06/06/95
144 Added des_ncbc_encrypt(), it is des_cbc mode except that it is
145 'normal' and copies the new iv value back over the top of the
146 passed parameter.
147 CHANGED des_ede3_cbc_encrypt() so that it too now overwrites
148 the iv. THIS WILL BREAK EXISTING CODE, but since this function
149 only new, I feel I can change it, not so with des_cbc_encrypt :-(.
150 I need to update the documentation.
151
152Version 3.14 31/05/95
153 New release upon the world, as part of my SSL implementation.
154 New copyright and usage stuff. Basically free for all to use
155 as long as you say it came from me :-)
156
157Version 3.13 31/05/95
158 A fix in speed.c, if HZ is not defined, I set it to 100.0
159 which is reasonable for most unixes except SunOS 4.x.
160 I now have a #ifdef sun but timing for SunOS 4.x looked very
161 good :-(. At my last job where I used SunOS 4.x, it was
162 defined to be 60.0 (look at the old INSTALL documentation), at
163 the last release had it changed to 100.0 since I now work with
164 Solaris2 and SVR4 boxes.
165 Thanks to Rory Chisholm <rchishol@math.ethz.ch> for pointing this
166 one out.
167
168Version 3.12 08/05/95
169 As pointed out by The Crypt Keeper <tck@bend.UCSD.EDU>,
170 my D_ENCRYPT macro in crypt() had an un-necessary variable.
171 It has been removed.
172
173Version 3.11 03/05/95
174 Added des_ede3_cbc_encrypt() which is cbc mode des with 3 keys
175 and one iv. It is a standard and I needed it for my SSL code.
176 It makes more sense to use this for triple DES than
177 3cbc_encrypt(). I have also added (or should I say tested :-)
178 cfb64_encrypt() which is cfb64 but it will encrypt a partial
179 number of bytes - 3 bytes in 3 bytes out. Again this is for
180 my SSL library, as a form of encryption to use with SSL
181 telnet.
182
183Version 3.10 22/03/95
184 Fixed a bug in 3cbc_encrypt() :-(. When making repeated calls
185 to cbc3_encrypt, the 2 iv values that were being returned to
186 be used in the next call were reversed :-(.
187 Many thanks to Bill Wade <wade@Stoner.COM> for pointing out
188 this error.
189
190Version 3.09 01/02/95
191 Fixed des_random_key to far more random, it was rather feeble
192 with regards to picking the initial seed. The problem was
193 pointed out by Olaf Kirch <okir@monad.swb.de>.
194
195Version 3.08 14/12/94
196 Added Makefile.PL so libdes can be built into perl5.
197 Changed des_locl.h so RAND is always defined.
198
199Version 3.07 05/12/94
200 Added GNUmake and stuff so the library can be build with
201 glibc.
202
203Version 3.06 30/08/94
204 Added rpc_enc.c which contains _des_crypt. This is for use in
205 secure_rpc v 4.0
206 Finally fixed the cfb_enc problems.
207 Fixed a few parameter parsing bugs in des (-3 and -b), thanks
208 to Rob McMillan <R.McMillan@its.gu.edu.au>
209
210Version 3.05 21/04/94
211 for unsigned long l; gcc does not produce ((l>>34) == 0)
212 This causes bugs in cfb_enc.
213 Thanks to Hadmut Danisch <danisch@ira.uka.de>
214
215Version 3.04 20/04/94
216 Added a version number to des.c and libdes.a
217
218Version 3.03 12/01/94
219 Fixed a bug in non zero iv in 3cbc_enc.
220
221Version 3.02 29/10/93
222 I now work in a place where there are 6+ architectures and 14+
223 OS versions :-).
224 Fixed TERMIO definition so the most sys V boxes will work :-)
225
226Release upon comp.sources.misc
227Version 3.01 08/10/93
228 Added des_3cbc_encrypt()
229
230Version 3.00 07/10/93
231 Fixed up documentation.
232 quad_cksum definitely compatible with MIT's now.
233
234Version 2.30 24/08/93
235 Triple DES now defaults to triple cbc but can do triple ecb
236 with the -b flag.
237 Fixed some MSDOS uuen/uudecoding problems, thanks to
238 Added prototypes.
239
240Version 2.22 29/06/93
241 Fixed a bug in des_is_weak_key() which stopped it working :-(
242 thanks to engineering@MorningStar.Com.
243
244Version 2.21 03/06/93
245 des(1) with no arguments gives quite a bit of help.
246 Added -c (generate ckecksum) flag to des(1).
247 Added -3 (triple DES) flag to des(1).
248 Added cfb and ofb routines to the library.
249
250Version 2.20 11/03/93
251 Added -u (uuencode) flag to des(1).
252 I have been playing with byte order in quad_cksum to make it
253 compatible with MIT's version. All I can say is avid this
254 function if possible since MIT's output is endian dependent.
255
256Version 2.12 14/10/92
257 Added MSDOS specific macro in ecb_encrypt which gives a %70
258 speed up when the code is compiled with turbo C.
259
260Version 2.11 12/10/92
261 Speedup in set_key (recoding of PC-1)
262 I now do it in 47 simple operations, down from 60.
263 Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
264 for motivating me to look for a faster system :-)
265 The speedup is probably less that 1% but it is still 13
266 instructions less :-).
267
268Version 2.10 06/10/92
269 The code now works on the 64bit ETA10 and CRAY without modifications or
270 #defines. I believe the code should work on any machine that
271 defines long, int or short to be 8 bytes long.
272 Thanks to Shabbir J. Safdar (shabby@mentor.cc.purdue.edu)
273 for helping me fix the code to run on 64bit machines (he had
274 access to an ETA10).
275 Thanks also to John Fletcher <john_fletcher@lccmail.ocf.llnl.gov>
276 for testing the routines on a CRAY.
277 read_password.c has been renamed to read_passwd.c
278 string_to_key.c has been renamed to string2key.c
279
280Version 2.00 14/09/92
281 Made mods so that the library should work on 64bit CPU's.
282 Removed all my uchar and ulong defs. To many different
283 versions of unix define them in their header files in too many
284 different combinations :-)
285 IRIX - Sillicon Graphics mods (mostly in read_password.c).
286 Thanks to Andrew Daviel (advax@erich.triumf.ca)
287
288Version 1.99 26/08/92
289 Fixed a bug or 2 in enc_read.c
290 Fixed a bug in enc_write.c
291 Fixed a pseudo bug in fcrypt.c (very obscure).
292
293Version 1.98 31/07/92
294 Support for the ETA10. This is a strange machine that defines
295 longs and ints as 8 bytes and shorts as 4 bytes.
296 Since I do evil things with long * that assume that they are 4
297 bytes. Look in the Makefile for the option to compile for
298 this machine. quad_cksum appears to have problems but I
299 will don't have the time to fix it right now, and this is not
300 a function that uses DES and so will not effect the main uses
301 of the library.
302
303Version 1.97 20/05/92 eay
304 Fixed the Imakefile and made some changes to des.h to fix some
305 problems when building this package with Kerberos v 4.
306
307Version 1.96 18/05/92 eay
308 Fixed a small bug in string_to_key() where problems could
309 occur if des_check_key was set to true and the string
310 generated a weak key.
311
312Patch2 posted to comp.sources.misc
313Version 1.95 13/05/92 eay
314 Added an alternative version of the D_ENCRYPT macro in
315 ecb_encrypt and fcrypt. Depending on the compiler, one version or the
316 other will be faster. This was inspired by
317 Dana How <how@isl.stanford.edu>, and her pointers about doing the
318 *(ulong *)((uchar *)ptr+(value&0xfc))
319 vs
320 ptr[value&0x3f]
321 to stop the C compiler doing a <<2 to convert the long array index.
322
323Version 1.94 05/05/92 eay
324 Fixed an incompatibility between my string_to_key and the MIT
325 version. When the key is longer than 8 chars, I was wrapping
326 with a different method. To use the old version, define
327 OLD_STR_TO_KEY in the makefile. Thanks to
328 viktor@newsu.shearson.com (Viktor Dukhovni).
329
330Version 1.93 28/04/92 eay
331 Fixed the VMS mods so that echo is now turned off in
332 read_password. Thanks again to brennan@coco.cchs.su.oz.AU.
333 MSDOS support added. The routines can be compiled with
334 Turbo C (v2.0) and MSC (v5.1). Make sure MSDOS is defined.
335
336Patch1 posted to comp.sources.misc
337Version 1.92 13/04/92 eay
338 Changed D_ENCRYPT so that the rotation of R occurs outside of
339 the loop. This required rotating all the longs in sp.h (now
340 called spr.h). Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
341 speed.c has been changed so it will work without SIGALRM. If
342 times(3) is not present it will try to use ftime() instead.
343
344Version 1.91 08/04/92 eay
345 Added -E/-D options to des(1) so it can use string_to_key.
346 Added SVR4 mods suggested by witr@rwwa.COM
347 Added VMS mods suggested by brennan@coco.cchs.su.oz.AU. If
348 anyone knows how to turn of tty echo in VMS please tell me or
349 implement it yourself :-).
350 Changed FILE *IN/*OUT to *DES_IN/*DES_OUT since it appears VMS
351 does not like IN/OUT being used.
352
353Libdes posted to comp.sources.misc
354Version 1.9 24/03/92 eay
355 Now contains a fast small crypt replacement.
356 Added des(1) command.
357 Added des_rw_mode so people can use cbc encryption with
358 enc_read and enc_write.
359
360Version 1.8 15/10/91 eay
361 Bug in cbc_cksum.
362 Many thanks to Keith Reynolds (keithr@sco.COM) for pointing this
363 one out.
364
365Version 1.7 24/09/91 eay
366 Fixed set_key :-)
367 set_key is 4 times faster and takes less space.
368 There are a few minor changes that could be made.
369
370Version 1.6 19/09/1991 eay
371 Finally go IP and FP finished.
372 Now I need to fix set_key.
373 This version is quite a bit faster that 1.51
374
375Version 1.52 15/06/1991 eay
376 20% speedup in ecb_encrypt by changing the E bit selection
377 to use 2 32bit words. This also required modification of the
378 sp table. There is still a way to speedup the IP and IP-1
379 (hints from outer@sq.com) still working on this one :-(.
380
381Version 1.51 07/06/1991 eay
382 Faster des_encrypt by loop unrolling
383 Fixed bug in quad_cksum.c (thanks to hughes@logos.ucs.indiana.edu)
384
385Version 1.50 28/05/1991 eay
386 Optimised the code a bit more for the sparc. I have improved the
387 speed of the inner des_encrypt by speeding up the initial and
388 final permutations.
389
390Version 1.40 23/10/1990 eay
391 Fixed des_random_key, it did not produce a random key :-(
392
393Version 1.30 2/10/1990 eay
394 Have made des_quad_cksum the same as MIT's, the full package
395 should be compatible with MIT's
396 Have tested on a DECstation 3100
397 Still need to fix des_set_key (make it faster).
398 Does des_cbc_encrypts at 70.5k/sec on a 3100.
399
400Version 1.20 18/09/1990 eay
401 Fixed byte order dependencies.
402 Fixed (I hope) all the word alignment problems.
403 Speedup in des_ecb_encrypt.
404
405Version 1.10 11/09/1990 eay
406 Added des_enc_read and des_enc_write.
407 Still need to fix des_quad_cksum.
408 Still need to document des_enc_read and des_enc_write.
409
410Version 1.00 27/08/1990 eay
411
diff --git a/src/lib/libcrypto/des/asm/des686.pl b/src/lib/libcrypto/des/asm/des686.pl
new file mode 100644
index 0000000000..cf1a82fb5c
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/des686.pl
@@ -0,0 +1,230 @@
1#!/usr/bin/perl
2
3$prog="des686.pl";
4
5# base code is in microsft
6# op dest, source
7# format.
8#
9
10# WILL NOT WORK ANYMORE WITH desboth.pl
11require "desboth.pl";
12
13if ( ($ARGV[0] eq "elf"))
14 { require "x86unix.pl"; }
15elsif ( ($ARGV[0] eq "a.out"))
16 { $aout=1; require "x86unix.pl"; }
17elsif ( ($ARGV[0] eq "sol"))
18 { $sol=1; require "x86unix.pl"; }
19elsif ( ($ARGV[0] eq "cpp"))
20 { $cpp=1; require "x86unix.pl"; }
21elsif ( ($ARGV[0] eq "win32"))
22 { require "x86ms.pl"; }
23else
24 {
25 print STDERR <<"EOF";
26Pick one target type from
27 elf - linux, FreeBSD etc
28 a.out - old linux
29 sol - x86 solaris
30 cpp - format so x86unix.cpp can be used
31 win32 - Windows 95/Windows NT
32EOF
33 exit(1);
34 }
35
36&comment("Don't even think of reading this code");
37&comment("It was automatically generated by $prog");
38&comment("Which is a perl program used to generate the x86 assember for");
39&comment("any of elf, a.out, Win32, or Solaris");
40&comment("It can be found in SSLeay 0.6.5+ or in libdes 3.26+");
41&comment("eric <eay\@cryptsoft.com>");
42&comment("");
43
44&file("dx86xxxx");
45
46$L="edi";
47$R="esi";
48
49&des_encrypt("des_encrypt",1);
50&des_encrypt("des_encrypt2",0);
51
52&des_encrypt3("des_encrypt3",1);
53&des_encrypt3("des_decrypt3",0);
54
55&file_end();
56
57sub des_encrypt
58 {
59 local($name,$do_ip)=@_;
60
61 &function_begin($name,"EXTRN _des_SPtrans:DWORD");
62
63 &comment("");
64 &comment("Load the 2 words");
65 &mov("eax",&wparam(0));
66 &mov($L,&DWP(0,"eax","",0));
67 &mov($R,&DWP(4,"eax","",0));
68
69 $ksp=&wparam(1);
70
71 if ($do_ip)
72 {
73 &comment("");
74 &comment("IP");
75 &IP_new($L,$R,"eax");
76 }
77
78 &comment("");
79 &comment("fixup rotate");
80 &rotl($R,3);
81 &rotl($L,3);
82 &exch($L,$R);
83
84 &comment("");
85 &comment("load counter, key_schedule and enc flag");
86 &mov("eax",&wparam(2)); # get encrypt flag
87 &mov("ebp",&wparam(1)); # get ks
88 &cmp("eax","0");
89 &je(&label("start_decrypt"));
90
91 # encrypting part
92
93 for ($i=0; $i<16; $i+=2)
94 {
95 &comment("");
96 &comment("Round $i");
97 &D_ENCRYPT($L,$R,$i*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
98
99 &comment("");
100 &comment("Round ".sprintf("%d",$i+1));
101 &D_ENCRYPT($R,$L,($i+1)*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
102 }
103 &jmp(&label("end"));
104
105 &set_label("start_decrypt");
106
107 for ($i=15; $i>0; $i-=2)
108 {
109 &comment("");
110 &comment("Round $i");
111 &D_ENCRYPT($L,$R,$i*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
112 &comment("");
113 &comment("Round ".sprintf("%d",$i-1));
114 &D_ENCRYPT($R,$L,($i-1)*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
115 }
116
117 &set_label("end");
118
119 &comment("");
120 &comment("Fixup");
121 &rotr($L,3); # r
122 &rotr($R,3); # l
123
124 if ($do_ip)
125 {
126 &comment("");
127 &comment("FP");
128 &FP_new($R,$L,"eax");
129 }
130
131 &mov("eax",&wparam(0));
132 &mov(&DWP(0,"eax","",0),$L);
133 &mov(&DWP(4,"eax","",0),$R);
134
135 &function_end($name);
136 }
137
138
139# The logic is to load R into 2 registers and operate on both at the same time.
140# We also load the 2 R's into 2 more registers so we can do the 'move word down a byte'
141# while also masking the other copy and doing a lookup. We then also accumulate the
142# L value in 2 registers then combine them at the end.
143sub D_ENCRYPT
144 {
145 local($L,$R,$S,$ks,$desSP,$u,$t,$tmp1,$tmp2,$tmp3)=@_;
146
147 &mov( $u, &DWP(&n2a($S*4),$ks,"",0));
148 &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0));
149 &xor( $u, $R );
150 &xor( $t, $R );
151 &rotr( $t, 4 );
152
153 # the numbers at the end of the line are origional instruction order
154 &mov( $tmp2, $u ); # 1 2
155 &mov( $tmp1, $t ); # 1 1
156 &and( $tmp2, "0xfc" ); # 1 4
157 &and( $tmp1, "0xfc" ); # 1 3
158 &shr( $t, 8 ); # 1 5
159 &xor( $L, &DWP("0x100+$desSP",$tmp1,"",0)); # 1 7
160 &shr( $u, 8 ); # 1 6
161 &mov( $tmp1, &DWP(" $desSP",$tmp2,"",0)); # 1 8
162
163 &mov( $tmp2, $u ); # 2 2
164 &xor( $L, $tmp1 ); # 1 9
165 &and( $tmp2, "0xfc" ); # 2 4
166 &mov( $tmp1, $t ); # 2 1
167 &and( $tmp1, "0xfc" ); # 2 3
168 &shr( $t, 8 ); # 2 5
169 &xor( $L, &DWP("0x300+$desSP",$tmp1,"",0)); # 2 7
170 &shr( $u, 8 ); # 2 6
171 &mov( $tmp1, &DWP("0x200+$desSP",$tmp2,"",0)); # 2 8
172 &mov( $tmp2, $u ); # 3 2
173
174 &xor( $L, $tmp1 ); # 2 9
175 &and( $tmp2, "0xfc" ); # 3 4
176
177 &mov( $tmp1, $t ); # 3 1
178 &shr( $u, 8 ); # 3 6
179 &and( $tmp1, "0xfc" ); # 3 3
180 &shr( $t, 8 ); # 3 5
181 &xor( $L, &DWP("0x500+$desSP",$tmp1,"",0)); # 3 7
182 &mov( $tmp1, &DWP("0x400+$desSP",$tmp2,"",0)); # 3 8
183
184 &and( $t, "0xfc" ); # 4 1
185 &xor( $L, $tmp1 ); # 3 9
186
187 &and( $u, "0xfc" ); # 4 2
188 &xor( $L, &DWP("0x700+$desSP",$t,"",0)); # 4 3
189 &xor( $L, &DWP("0x600+$desSP",$u,"",0)); # 4 4
190 }
191
192sub PERM_OP
193 {
194 local($a,$b,$tt,$shift,$mask)=@_;
195
196 &mov( $tt, $a );
197 &shr( $tt, $shift );
198 &xor( $tt, $b );
199 &and( $tt, $mask );
200 &xor( $b, $tt );
201 &shl( $tt, $shift );
202 &xor( $a, $tt );
203 }
204
205sub IP_new
206 {
207 local($l,$r,$tt)=@_;
208
209 &PERM_OP($r,$l,$tt, 4,"0x0f0f0f0f");
210 &PERM_OP($l,$r,$tt,16,"0x0000ffff");
211 &PERM_OP($r,$l,$tt, 2,"0x33333333");
212 &PERM_OP($l,$r,$tt, 8,"0x00ff00ff");
213 &PERM_OP($r,$l,$tt, 1,"0x55555555");
214 }
215
216sub FP_new
217 {
218 local($l,$r,$tt)=@_;
219
220 &PERM_OP($l,$r,$tt, 1,"0x55555555");
221 &PERM_OP($r,$l,$tt, 8,"0x00ff00ff");
222 &PERM_OP($l,$r,$tt, 2,"0x33333333");
223 &PERM_OP($r,$l,$tt,16,"0x0000ffff");
224 &PERM_OP($l,$r,$tt, 4,"0x0f0f0f0f");
225 }
226
227sub n2a
228 {
229 sprintf("%d",$_[0]);
230 }
diff --git a/src/lib/libcrypto/des/asm/readme b/src/lib/libcrypto/des/asm/readme
new file mode 100644
index 0000000000..f8529d9307
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/readme
@@ -0,0 +1,131 @@
1First up, let me say I don't like writing in assembler. It is not portable,
2dependant on the particular CPU architecture release and is generally a pig
3to debug and get right. Having said that, the x86 architecture is probably
4the most important for speed due to number of boxes and since
5it appears to be the worst architecture to to get
6good C compilers for. So due to this, I have lowered myself to do
7assembler for the inner DES routines in libdes :-).
8
9The file to implement in assembler is des_enc.c. Replace the following
104 functions
11des_encrypt(DES_LONG data[2],des_key_schedule ks, int encrypt);
12des_encrypt2(DES_LONG data[2],des_key_schedule ks, int encrypt);
13des_encrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
14des_decrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
15
16They encrypt/decrypt the 64 bits held in 'data' using
17the 'ks' key schedules. The only difference between the 4 functions is that
18des_encrypt2() does not perform IP() or FP() on the data (this is an
19optimization for when doing triple DES and des_encrypt3() and des_decrypt3()
20perform triple des. The triple DES routines are in here because it does
21make a big difference to have them located near the des_encrypt2 function
22at link time..
23
24Now as we all know, there are lots of different operating systems running on
25x86 boxes, and unfortunately they normally try to make sure their assembler
26formating is not the same as the other peoples.
27The 4 main formats I know of are
28Microsoft Windows 95/Windows NT
29Elf Includes Linux and FreeBSD(?).
30a.out The older Linux.
31Solaris Same as Elf but different comments :-(.
32
33Now I was not overly keen to write 4 different copies of the same code,
34so I wrote a few perl routines to output the correct assembler, given
35a target assembler type. This code is ugly and is just a hack.
36The libraries are x86unix.pl and x86ms.pl.
37des586.pl, des686.pl and des-som[23].pl are the programs to actually
38generate the assembler.
39
40So to generate elf assembler
41perl des-som3.pl elf >dx86-elf.s
42For Windows 95/NT
43perl des-som2.pl win32 >win32.asm
44
45[ update 4 Jan 1996 ]
46I have added another way to do things.
47perl des-som3.pl cpp >dx86-cpp.s
48generates a file that will be included by dx86unix.cpp when it is compiled.
49To build for elf, a.out, solaris, bsdi etc,
50cc -E -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o
51cc -E -DSOL asm/dx86unix.cpp | as -o asm/dx86-sol.o
52cc -E -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o
53cc -E -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o
54This was done to cut down the number of files in the distribution.
55
56Now the ugly part. I acquired my copy of Intels
57"Optimization's For Intel's 32-Bit Processors" and found a few interesting
58things. First, the aim of the exersize is to 'extract' one byte at a time
59from a word and do an array lookup. This involves getting the byte from
60the 4 locations in the word and moving it to a new word and doing the lookup.
61The most obvious way to do this is
62xor eax, eax # clear word
63movb al, cl # get low byte
64xor edi DWORD PTR 0x100+des_SP[eax] # xor in word
65movb al, ch # get next byte
66xor edi DWORD PTR 0x300+des_SP[eax] # xor in word
67shr ecx 16
68which seems ok. For the pentium, this system appears to be the best.
69One has to do instruction interleaving to keep both functional units
70operating, but it is basically very efficient.
71
72Now the crunch. When a full register is used after a partial write, eg.
73mov al, cl
74xor edi, DWORD PTR 0x100+des_SP[eax]
75386 - 1 cycle stall
76486 - 1 cycle stall
77586 - 0 cycle stall
78686 - at least 7 cycle stall (page 22 of the above mentioned document).
79
80So the technique that produces the best results on a pentium, according to
81the documentation, will produce hideous results on a pentium pro.
82
83To get around this, des686.pl will generate code that is not as fast on
84a pentium, should be very good on a pentium pro.
85mov eax, ecx # copy word
86shr ecx, 8 # line up next byte
87and eax, 0fch # mask byte
88xor edi DWORD PTR 0x100+des_SP[eax] # xor in array lookup
89mov eax, ecx # get word
90shr ecx 8 # line up next byte
91and eax, 0fch # mask byte
92xor edi DWORD PTR 0x300+des_SP[eax] # xor in array lookup
93
94Due to the execution units in the pentium, this actually works quite well.
95For a pentium pro it should be very good. This is the type of output
96Visual C++ generates.
97
98There is a third option. instead of using
99mov al, ch
100which is bad on the pentium pro, one may be able to use
101movzx eax, ch
102which may not incur the partial write penalty. On the pentium,
103this instruction takes 4 cycles so is not worth using but on the
104pentium pro it appears it may be worth while. I need access to one to
105experiment :-).
106
107eric (20 Oct 1996)
108
10922 Nov 1996 - I have asked people to run the 2 different version on pentium
110pros and it appears that the intel documentation is wrong. The
111mov al,bh is still faster on a pentium pro, so just use the des586.pl
112install des686.pl
113
1143 Dec 1996 - I added des_encrypt3/des_decrypt3 because I have moved these
115functions into des_enc.c because it does make a massive performance
116difference on some boxes to have the functions code located close to
117the des_encrypt2() function.
118
1199 Jan 1997 - des-som2.pl is now the correct perl script to use for
120pentiums. It contains an inner loop from
121Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> which does raw ecb DES calls at
122273,000 per second. He had a previous version at 250,000 and the best
123I was able to get was 203,000. The content has not changed, this is all
124due to instruction sequencing (and actual instructions choice) which is able
125to keep both functional units of the pentium going.
126We may have lost the ugly register usage restrictions when x86 went 32 bit
127but for the pentium it has been replaced by evil instruction ordering tricks.
128
12913 Jan 1997 - des-som3.pl, more optimizations from Svend Olaf.
130raw DES at 281,000 per second on a pentium 100.
131
diff --git a/src/lib/libcrypto/des/cbc3_enc.c b/src/lib/libcrypto/des/cbc3_enc.c
new file mode 100644
index 0000000000..92a78b05d6
--- /dev/null
+++ b/src/lib/libcrypto/des/cbc3_enc.c
@@ -0,0 +1,99 @@
1/* crypto/des/cbc3_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* HAS BUGS? DON'T USE - this is only present for use in des.c */
62void des_3cbc_encrypt(input, output, length, ks1, ks2, iv1, iv2, enc)
63des_cblock (*input);
64des_cblock (*output);
65long length;
66des_key_schedule ks1;
67des_key_schedule ks2;
68des_cblock (*iv1);
69des_cblock (*iv2);
70int enc;
71 {
72 int off=((int)length-1)/8;
73 long l8=((length+7)/8)*8;
74 des_cblock niv1,niv2;
75
76 if (enc == DES_ENCRYPT)
77 {
78 des_cbc_encrypt(input,output,length,ks1,iv1,enc);
79 if (length >= sizeof(des_cblock))
80 memcpy(niv1,output[off],sizeof(des_cblock));
81 des_cbc_encrypt(output,output,l8,ks2,iv1,!enc);
82 des_cbc_encrypt(output,output,l8,ks1,iv2, enc);
83 if (length >= sizeof(des_cblock))
84 memcpy(niv2,output[off],sizeof(des_cblock));
85 }
86 else
87 {
88 if (length >= sizeof(des_cblock))
89 memcpy(niv2,input[off],sizeof(des_cblock));
90 des_cbc_encrypt(input,output,l8,ks1,iv2,enc);
91 des_cbc_encrypt(output,output,l8,ks2,iv1,!enc);
92 if (length >= sizeof(des_cblock))
93 memcpy(niv1,output[off],sizeof(des_cblock));
94 des_cbc_encrypt(output,output,length,ks1,iv1, enc);
95 }
96 memcpy(*iv1,niv1,sizeof(des_cblock));
97 memcpy(*iv2,niv2,sizeof(des_cblock));
98 }
99
diff --git a/src/lib/libcrypto/des/des.c b/src/lib/libcrypto/des/des.c
new file mode 100644
index 0000000000..c1e5005474
--- /dev/null
+++ b/src/lib/libcrypto/des/des.c
@@ -0,0 +1,964 @@
1/* crypto/des/des.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#ifndef MSDOS
62#include <unistd.h>
63#else
64#include <io.h>
65#define RAND
66#endif
67
68#include <time.h>
69#include "des_ver.h"
70
71#ifdef VMS
72#include <types.h>
73#include <stat.h>
74#else
75#ifndef _IRIX
76#include <sys/types.h>
77#endif
78#include <sys/stat.h>
79#endif
80#if defined(NOCONST)
81#define const
82#endif
83#include "des.h"
84
85#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
86#include <string.h>
87#endif
88
89#ifdef RAND
90#define random rand
91#define srandom(s) srand(s)
92#endif
93
94#ifndef NOPROTO
95void usage(void);
96void doencryption(void);
97int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp);
98void uufwriteEnd(FILE *fp);
99int uufread(unsigned char *out,int size,unsigned int num,FILE *fp);
100int uuencode(unsigned char *in,int num,unsigned char *out);
101int uudecode(unsigned char *in,int num,unsigned char *out);
102void des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length,
103 des_key_schedule sk1,des_key_schedule sk2,
104 des_cblock *ivec1,des_cblock *ivec2,int enc);
105#else
106void usage();
107void doencryption();
108int uufwrite();
109void uufwriteEnd();
110int uufread();
111int uuencode();
112int uudecode();
113void des_3cbc_encrypt();
114#endif
115
116#ifdef VMS
117#define EXIT(a) exit(a&0x10000000L)
118#else
119#define EXIT(a) exit(a)
120#endif
121
122#define BUFSIZE (8*1024)
123#define VERIFY 1
124#define KEYSIZ 8
125#define KEYSIZB 1024 /* should hit tty line limit first :-) */
126char key[KEYSIZB+1];
127int do_encrypt,longk=0;
128FILE *DES_IN,*DES_OUT,*CKSUM_OUT;
129char uuname[200];
130unsigned char uubuf[50];
131int uubufnum=0;
132#define INUUBUFN (45*100)
133#define OUTUUBUF (65*100)
134unsigned char b[OUTUUBUF];
135unsigned char bb[300];
136des_cblock cksum={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
137char cksumname[200]="";
138
139int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error;
140
141int main(argc, argv)
142int argc;
143char **argv;
144 {
145 int i;
146 struct stat ins,outs;
147 char *p;
148 char *in=NULL,*out=NULL;
149
150 vflag=cflag=eflag=dflag=kflag=hflag=bflag=fflag=sflag=uflag=flag3=0;
151 error=0;
152 memset(key,0,sizeof(key));
153
154 for (i=1; i<argc; i++)
155 {
156 p=argv[i];
157 if ((p[0] == '-') && (p[1] != '\0'))
158 {
159 p++;
160 while (*p)
161 {
162 switch (*(p++))
163 {
164 case '3':
165 flag3=1;
166 longk=1;
167 break;
168 case 'c':
169 cflag=1;
170 strncpy(cksumname,p,200);
171 p+=strlen(cksumname);
172 break;
173 case 'C':
174 cflag=1;
175 longk=1;
176 strncpy(cksumname,p,200);
177 p+=strlen(cksumname);
178 break;
179 case 'e':
180 eflag=1;
181 break;
182 case 'v':
183 vflag=1;
184 break;
185 case 'E':
186 eflag=1;
187 longk=1;
188 break;
189 case 'd':
190 dflag=1;
191 break;
192 case 'D':
193 dflag=1;
194 longk=1;
195 break;
196 case 'b':
197 bflag=1;
198 break;
199 case 'f':
200 fflag=1;
201 break;
202 case 's':
203 sflag=1;
204 break;
205 case 'u':
206 uflag=1;
207 strncpy(uuname,p,200);
208 p+=strlen(uuname);
209 break;
210 case 'h':
211 hflag=1;
212 break;
213 case 'k':
214 kflag=1;
215 if ((i+1) == argc)
216 {
217 fputs("must have a key with the -k option\n",stderr);
218 error=1;
219 }
220 else
221 {
222 int j;
223
224 i++;
225 strncpy(key,argv[i],KEYSIZB);
226 for (j=strlen(argv[i])-1; j>=0; j--)
227 argv[i][j]='\0';
228 }
229 break;
230 default:
231 fprintf(stderr,"'%c' unknown flag\n",p[-1]);
232 error=1;
233 break;
234 }
235 }
236 }
237 else
238 {
239 if (in == NULL)
240 in=argv[i];
241 else if (out == NULL)
242 out=argv[i];
243 else
244 error=1;
245 }
246 }
247 if (error) usage();
248 /* We either
249 * do checksum or
250 * do encrypt or
251 * do decrypt or
252 * do decrypt then ckecksum or
253 * do checksum then encrypt
254 */
255 if (((eflag+dflag) == 1) || cflag)
256 {
257 if (eflag) do_encrypt=DES_ENCRYPT;
258 if (dflag) do_encrypt=DES_DECRYPT;
259 }
260 else
261 {
262 if (vflag)
263 {
264#ifndef _Windows
265 fprintf(stderr,"des(1) built with %s\n",libdes_version);
266#endif
267 EXIT(1);
268 }
269 else usage();
270 }
271
272#ifndef _Windows
273 if (vflag) fprintf(stderr,"des(1) built with %s\n",libdes_version);
274#endif
275 if ( (in != NULL) &&
276 (out != NULL) &&
277#ifndef MSDOS
278 (stat(in,&ins) != -1) &&
279 (stat(out,&outs) != -1) &&
280 (ins.st_dev == outs.st_dev) &&
281 (ins.st_ino == outs.st_ino))
282#else /* MSDOS */
283 (strcmp(in,out) == 0))
284#endif
285 {
286 fputs("input and output file are the same\n",stderr);
287 EXIT(3);
288 }
289
290 if (!kflag)
291 if (des_read_pw_string(key,KEYSIZB+1,"Enter key:",eflag?VERIFY:0))
292 {
293 fputs("password error\n",stderr);
294 EXIT(2);
295 }
296
297 if (in == NULL)
298 DES_IN=stdin;
299 else if ((DES_IN=fopen(in,"r")) == NULL)
300 {
301 perror("opening input file");
302 EXIT(4);
303 }
304
305 CKSUM_OUT=stdout;
306 if (out == NULL)
307 {
308 DES_OUT=stdout;
309 CKSUM_OUT=stderr;
310 }
311 else if ((DES_OUT=fopen(out,"w")) == NULL)
312 {
313 perror("opening output file");
314 EXIT(5);
315 }
316
317#ifdef MSDOS
318 /* This should set the file to binary mode. */
319 {
320#include <fcntl.h>
321 if (!(uflag && dflag))
322 setmode(fileno(DES_IN),O_BINARY);
323 if (!(uflag && eflag))
324 setmode(fileno(DES_OUT),O_BINARY);
325 }
326#endif
327
328 doencryption();
329 fclose(DES_IN);
330 fclose(DES_OUT);
331 EXIT(0);
332 }
333
334void usage()
335 {
336 char **u;
337 static const char *Usage[]={
338"des <options> [input-file [output-file]]",
339"options:",
340"-v : des(1) version number",
341"-e : encrypt using sunOS compatible user key to DES key conversion.",
342"-E : encrypt ",
343"-d : decrypt using sunOS compatible user key to DES key conversion.",
344"-D : decrypt ",
345"-c[ckname] : generate a cbc_cksum using sunOS compatible user key to",
346" DES key conversion and output to ckname (stdout default,",
347" stderr if data being output on stdout). The checksum is",
348" generated before encryption and after decryption if used",
349" in conjunction with -[eEdD].",
350"-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].",
351"-k key : use key 'key'",
352"-h : the key that is entered will be a hexidecimal number",
353" that is used directly as the des key",
354"-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]",
355" (uuname is the filename to put in the uuencode header).",
356"-b : encrypt using DES in ecb encryption mode, the defaut is cbc mode.",
357"-3 : encrypt using tripple DES encryption. This uses 2 keys",
358" generated from the input key. If the input key is less",
359" than 8 characters long, this is equivelent to normal",
360" encryption. Default is tripple cbc, -b makes it tripple ecb.",
361NULL
362};
363 for (u=(char **)Usage; *u; u++)
364 {
365 fputs(*u,stderr);
366 fputc('\n',stderr);
367 }
368
369 EXIT(1);
370 }
371
372void doencryption()
373 {
374#ifdef _LIBC
375 extern int srandom();
376 extern int random();
377 extern unsigned long time();
378#endif
379
380 register int i;
381 des_key_schedule ks,ks2;
382 unsigned char iv[8],iv2[8];
383 char *p;
384 int num=0,j,k,l,rem,ll,len,last,ex=0;
385 des_cblock kk,k2;
386 FILE *O;
387 int Exit=0;
388#ifndef MSDOS
389 static unsigned char buf[BUFSIZE+8],obuf[BUFSIZE+8];
390#else
391 static unsigned char *buf=NULL,*obuf=NULL;
392
393 if (buf == NULL)
394 {
395 if ( (( buf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL) ||
396 ((obuf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL))
397 {
398 fputs("Not enough memory\n",stderr);
399 Exit=10;
400 goto problems;
401 }
402 }
403#endif
404
405 if (hflag)
406 {
407 j=(flag3?16:8);
408 p=key;
409 for (i=0; i<j; i++)
410 {
411 k=0;
412 if ((*p <= '9') && (*p >= '0'))
413 k=(*p-'0')<<4;
414 else if ((*p <= 'f') && (*p >= 'a'))
415 k=(*p-'a'+10)<<4;
416 else if ((*p <= 'F') && (*p >= 'A'))
417 k=(*p-'A'+10)<<4;
418 else
419 {
420 fputs("Bad hex key\n",stderr);
421 Exit=9;
422 goto problems;
423 }
424 p++;
425 if ((*p <= '9') && (*p >= '0'))
426 k|=(*p-'0');
427 else if ((*p <= 'f') && (*p >= 'a'))
428 k|=(*p-'a'+10);
429 else if ((*p <= 'F') && (*p >= 'A'))
430 k|=(*p-'A'+10);
431 else
432 {
433 fputs("Bad hex key\n",stderr);
434 Exit=9;
435 goto problems;
436 }
437 p++;
438 if (i < 8)
439 kk[i]=k;
440 else
441 k2[i-8]=k;
442 }
443 des_set_key((C_Block *)k2,ks2);
444 memset(k2,0,sizeof(k2));
445 }
446 else if (longk || flag3)
447 {
448 if (flag3)
449 {
450 des_string_to_2keys(key,(C_Block *)kk,(C_Block *)k2);
451 des_set_key((C_Block *)k2,ks2);
452 memset(k2,0,sizeof(k2));
453 }
454 else
455 des_string_to_key(key,(C_Block *)kk);
456 }
457 else
458 for (i=0; i<KEYSIZ; i++)
459 {
460 l=0;
461 k=key[i];
462 for (j=0; j<8; j++)
463 {
464 if (k&1) l++;
465 k>>=1;
466 }
467 if (l & 1)
468 kk[i]=key[i]&0x7f;
469 else
470 kk[i]=key[i]|0x80;
471 }
472
473 des_set_key((C_Block *)kk,ks);
474 memset(key,0,sizeof(key));
475 memset(kk,0,sizeof(kk));
476 /* woops - A bug that does not showup under unix :-( */
477 memset(iv,0,sizeof(iv));
478 memset(iv2,0,sizeof(iv2));
479
480 l=1;
481 rem=0;
482 /* first read */
483 if (eflag || (!dflag && cflag))
484 {
485 for (;;)
486 {
487 num=l=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
488 l+=rem;
489 num+=rem;
490 if (l < 0)
491 {
492 perror("read error");
493 Exit=6;
494 goto problems;
495 }
496
497 rem=l%8;
498 len=l-rem;
499 if (feof(DES_IN))
500 {
501 srandom((unsigned int)time(NULL));
502 for (i=7-rem; i>0; i--)
503 buf[l++]=random()&0xff;
504 buf[l++]=rem;
505 ex=1;
506 len+=rem;
507 }
508 else
509 l-=rem;
510
511 if (cflag)
512 {
513 des_cbc_cksum((C_Block *)buf,(C_Block *)cksum,
514 (long)len,ks,(C_Block *)cksum);
515 if (!eflag)
516 {
517 if (feof(DES_IN)) break;
518 else continue;
519 }
520 }
521
522 if (bflag && !flag3)
523 for (i=0; i<l; i+=8)
524 des_ecb_encrypt(
525 (des_cblock *)&(buf[i]),
526 (des_cblock *)&(obuf[i]),
527 ks,do_encrypt);
528 else if (flag3 && bflag)
529 for (i=0; i<l; i+=8)
530 des_ecb2_encrypt(
531 (des_cblock *)&(buf[i]),
532 (des_cblock *)&(obuf[i]),
533 ks,ks2,do_encrypt);
534 else if (flag3 && !bflag)
535 {
536 char tmpbuf[8];
537
538 if (rem) memcpy(tmpbuf,&(buf[l]),
539 (unsigned int)rem);
540 des_3cbc_encrypt(
541 (des_cblock *)buf,(des_cblock *)obuf,
542 (long)l,ks,ks2,(des_cblock *)iv,
543 (des_cblock *)iv2,do_encrypt);
544 if (rem) memcpy(&(buf[l]),tmpbuf,
545 (unsigned int)rem);
546 }
547 else
548 {
549 des_cbc_encrypt(
550 (des_cblock *)buf,(des_cblock *)obuf,
551 (long)l,ks,(des_cblock *)iv,do_encrypt);
552 if (l >= 8) memcpy(iv,&(obuf[l-8]),8);
553 }
554 if (rem) memcpy(buf,&(buf[l]),(unsigned int)rem);
555
556 i=0;
557 while (i < l)
558 {
559 if (uflag)
560 j=uufwrite(obuf,1,(unsigned int)l-i,
561 DES_OUT);
562 else
563 j=fwrite(obuf,1,(unsigned int)l-i,
564 DES_OUT);
565 if (j == -1)
566 {
567 perror("Write error");
568 Exit=7;
569 goto problems;
570 }
571 i+=j;
572 }
573 if (feof(DES_IN))
574 {
575 if (uflag) uufwriteEnd(DES_OUT);
576 break;
577 }
578 }
579 }
580 else /* decrypt */
581 {
582 ex=1;
583 for (;;)
584 {
585 if (ex) {
586 if (uflag)
587 l=uufread(buf,1,BUFSIZE,DES_IN);
588 else
589 l=fread(buf,1,BUFSIZE,DES_IN);
590 ex=0;
591 rem=l%8;
592 l-=rem;
593 }
594 if (l < 0)
595 {
596 perror("read error");
597 Exit=6;
598 goto problems;
599 }
600
601 if (bflag && !flag3)
602 for (i=0; i<l; i+=8)
603 des_ecb_encrypt(
604 (des_cblock *)&(buf[i]),
605 (des_cblock *)&(obuf[i]),
606 ks,do_encrypt);
607 else if (flag3 && bflag)
608 for (i=0; i<l; i+=8)
609 des_ecb2_encrypt(
610 (des_cblock *)&(buf[i]),
611 (des_cblock *)&(obuf[i]),
612 ks,ks2,do_encrypt);
613 else if (flag3 && !bflag)
614 {
615 des_3cbc_encrypt(
616 (des_cblock *)buf,(des_cblock *)obuf,
617 (long)l,ks,ks2,(des_cblock *)iv,
618 (des_cblock *)iv2,do_encrypt);
619 }
620 else
621 {
622 des_cbc_encrypt(
623 (des_cblock *)buf,(des_cblock *)obuf,
624 (long)l,ks,(des_cblock *)iv,do_encrypt);
625 if (l >= 8) memcpy(iv,&(buf[l-8]),8);
626 }
627
628 if (uflag)
629 ll=uufread(&(buf[rem]),1,BUFSIZE,DES_IN);
630 else
631 ll=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
632 ll+=rem;
633 rem=ll%8;
634 ll-=rem;
635 if (feof(DES_IN) && (ll == 0))
636 {
637 last=obuf[l-1];
638
639 if ((last > 7) || (last < 0))
640 {
641 fputs("The file was not decrypted correctly.\n",
642 stderr);
643 Exit=8;
644 last=0;
645 }
646 l=l-8+last;
647 }
648 i=0;
649 if (cflag) des_cbc_cksum((C_Block *)obuf,
650 (C_Block *)cksum,(long)l/8*8,ks,
651 (C_Block *)cksum);
652 while (i != l)
653 {
654 j=fwrite(obuf,1,(unsigned int)l-i,DES_OUT);
655 if (j == -1)
656 {
657 perror("Write error");
658 Exit=7;
659 goto problems;
660 }
661 i+=j;
662 }
663 l=ll;
664 if ((l == 0) && feof(DES_IN)) break;
665 }
666 }
667 if (cflag)
668 {
669 l=0;
670 if (cksumname[0] != '\0')
671 {
672 if ((O=fopen(cksumname,"w")) != NULL)
673 {
674 CKSUM_OUT=O;
675 l=1;
676 }
677 }
678 for (i=0; i<8; i++)
679 fprintf(CKSUM_OUT,"%02X",cksum[i]);
680 fprintf(CKSUM_OUT,"\n");
681 if (l) fclose(CKSUM_OUT);
682 }
683problems:
684 memset(buf,0,sizeof(buf));
685 memset(obuf,0,sizeof(obuf));
686 memset(ks,0,sizeof(ks));
687 memset(ks2,0,sizeof(ks2));
688 memset(iv,0,sizeof(iv));
689 memset(iv2,0,sizeof(iv2));
690 memset(kk,0,sizeof(kk));
691 memset(k2,0,sizeof(k2));
692 memset(uubuf,0,sizeof(uubuf));
693 memset(b,0,sizeof(b));
694 memset(bb,0,sizeof(bb));
695 memset(cksum,0,sizeof(cksum));
696 if (Exit) EXIT(Exit);
697 }
698
699int uufwrite(data, size, num, fp)
700unsigned char *data;
701int size;
702unsigned int num;
703FILE *fp;
704
705 /* We ignore this parameter but it should be > ~50 I believe */
706
707
708 {
709 int i,j,left,rem,ret=num;
710 static int start=1;
711
712 if (start)
713 {
714 fprintf(fp,"begin 600 %s\n",
715 (uuname[0] == '\0')?"text.d":uuname);
716 start=0;
717 }
718
719 if (uubufnum)
720 {
721 if (uubufnum+num < 45)
722 {
723 memcpy(&(uubuf[uubufnum]),data,(unsigned int)num);
724 uubufnum+=num;
725 return(num);
726 }
727 else
728 {
729 i=45-uubufnum;
730 memcpy(&(uubuf[uubufnum]),data,(unsigned int)i);
731 j=uuencode((unsigned char *)uubuf,45,b);
732 fwrite(b,1,(unsigned int)j,fp);
733 uubufnum=0;
734 data+=i;
735 num-=i;
736 }
737 }
738
739 for (i=0; i<(((int)num)-INUUBUFN); i+=INUUBUFN)
740 {
741 j=uuencode(&(data[i]),INUUBUFN,b);
742 fwrite(b,1,(unsigned int)j,fp);
743 }
744 rem=(num-i)%45;
745 left=(num-i-rem);
746 if (left)
747 {
748 j=uuencode(&(data[i]),left,b);
749 fwrite(b,1,(unsigned int)j,fp);
750 i+=left;
751 }
752 if (i != num)
753 {
754 memcpy(uubuf,&(data[i]),(unsigned int)rem);
755 uubufnum=rem;
756 }
757 return(ret);
758 }
759
760void uufwriteEnd(fp)
761FILE *fp;
762 {
763 int j;
764 static const char *end=" \nend\n";
765
766 if (uubufnum != 0)
767 {
768 uubuf[uubufnum]='\0';
769 uubuf[uubufnum+1]='\0';
770 uubuf[uubufnum+2]='\0';
771 j=uuencode(uubuf,uubufnum,b);
772 fwrite(b,1,(unsigned int)j,fp);
773 }
774 fwrite(end,1,strlen(end),fp);
775 }
776
777int uufread(out, size, num, fp)
778unsigned char *out;
779int size; /* should always be > ~ 60; I actually ignore this parameter :-) */
780unsigned int num;
781FILE *fp;
782 {
783 int i,j,tot;
784 static int done=0;
785 static int valid=0;
786 static int start=1;
787
788 if (start)
789 {
790 for (;;)
791 {
792 b[0]='\0';
793 fgets((char *)b,300,fp);
794 if (b[0] == '\0')
795 {
796 fprintf(stderr,"no 'begin' found in uuencoded input\n");
797 return(-1);
798 }
799 if (strncmp((char *)b,"begin ",6) == 0) break;
800 }
801 start=0;
802 }
803 if (done) return(0);
804 tot=0;
805 if (valid)
806 {
807 memcpy(out,bb,(unsigned int)valid);
808 tot=valid;
809 valid=0;
810 }
811 for (;;)
812 {
813 b[0]='\0';
814 fgets((char *)b,300,fp);
815 if (b[0] == '\0') break;
816 i=strlen((char *)b);
817 if ((b[0] == 'e') && (b[1] == 'n') && (b[2] == 'd'))
818 {
819 done=1;
820 while (!feof(fp))
821 {
822 fgets((char *)b,300,fp);
823 }
824 break;
825 }
826 i=uudecode(b,i,bb);
827 if (i < 0) break;
828 if ((i+tot+8) > num)
829 {
830 /* num to copy to make it a multiple of 8 */
831 j=(num/8*8)-tot-8;
832 memcpy(&(out[tot]),bb,(unsigned int)j);
833 tot+=j;
834 memcpy(bb,&(bb[j]),(unsigned int)i-j);
835 valid=i-j;
836 break;
837 }
838 memcpy(&(out[tot]),bb,(unsigned int)i);
839 tot+=i;
840 }
841 return(tot);
842 }
843
844#define ccc2l(c,l) (l =((DES_LONG)(*((c)++)))<<16, \
845 l|=((DES_LONG)(*((c)++)))<< 8, \
846 l|=((DES_LONG)(*((c)++))))
847
848#define l2ccc(l,c) (*((c)++)=(unsigned char)(((l)>>16)&0xff), \
849 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
850 *((c)++)=(unsigned char)(((l) )&0xff))
851
852
853int uuencode(in, num, out)
854unsigned char *in;
855int num;
856unsigned char *out;
857 {
858 int j,i,n,tot=0;
859 DES_LONG l;
860 register unsigned char *p;
861 p=out;
862
863 for (j=0; j<num; j+=45)
864 {
865 if (j+45 > num)
866 i=(num-j);
867 else i=45;
868 *(p++)=i+' ';
869 for (n=0; n<i; n+=3)
870 {
871 ccc2l(in,l);
872 *(p++)=((l>>18)&0x3f)+' ';
873 *(p++)=((l>>12)&0x3f)+' ';
874 *(p++)=((l>> 6)&0x3f)+' ';
875 *(p++)=((l )&0x3f)+' ';
876 tot+=4;
877 }
878 *(p++)='\n';
879 tot+=2;
880 }
881 *p='\0';
882 l=0;
883 return(tot);
884 }
885
886int uudecode(in, num, out)
887unsigned char *in;
888int num;
889unsigned char *out;
890 {
891 int j,i,k;
892 unsigned int n=0,space=0;
893 DES_LONG l;
894 DES_LONG w,x,y,z;
895 unsigned int blank=(unsigned int)'\n'-' ';
896
897 for (j=0; j<num; )
898 {
899 n= *(in++)-' ';
900 if (n == blank)
901 {
902 n=0;
903 in--;
904 }
905 if (n > 60)
906 {
907 fprintf(stderr,"uuencoded line length too long\n");
908 return(-1);
909 }
910 j++;
911
912 for (i=0; i<n; j+=4,i+=3)
913 {
914 /* the following is for cases where spaces are
915 * removed from lines.
916 */
917 if (space)
918 {
919 w=x=y=z=0;
920 }
921 else
922 {
923 w= *(in++)-' ';
924 x= *(in++)-' ';
925 y= *(in++)-' ';
926 z= *(in++)-' ';
927 }
928 if ((w > 63) || (x > 63) || (y > 63) || (z > 63))
929 {
930 k=0;
931 if (w == blank) k=1;
932 if (x == blank) k=2;
933 if (y == blank) k=3;
934 if (z == blank) k=4;
935 space=1;
936 switch (k) {
937 case 1: w=0; in--;
938 case 2: x=0; in--;
939 case 3: y=0; in--;
940 case 4: z=0; in--;
941 break;
942 case 0:
943 space=0;
944 fprintf(stderr,"bad uuencoded data values\n");
945 w=x=y=z=0;
946 return(-1);
947 break;
948 }
949 }
950 l=(w<<18)|(x<<12)|(y<< 6)|(z );
951 l2ccc(l,out);
952 }
953 if (*(in++) != '\n')
954 {
955 fprintf(stderr,"missing nl in uuencoded line\n");
956 w=x=y=z=0;
957 return(-1);
958 }
959 j++;
960 }
961 *out='\0';
962 w=x=y=z=0;
963 return(n);
964 }
diff --git a/src/lib/libcrypto/des/des3s.cpp b/src/lib/libcrypto/des/des3s.cpp
new file mode 100644
index 0000000000..9aff6494d9
--- /dev/null
+++ b/src/lib/libcrypto/des/des3s.cpp
@@ -0,0 +1,67 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include "des.h"
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key1,key2,key3;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt3(&data[0],key1,key2,key3);
49 GetTSC(s1);
50 des_encrypt3(&data[0],key1,key2,key3);
51 des_encrypt3(&data[0],key1,key2,key3);
52 des_encrypt3(&data[0],key1,key2,key3);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt3(&data[0],key1,key2,key3);
56 des_encrypt3(&data[0],key1,key2,key3);
57 des_encrypt3(&data[0],key1,key2,key3);
58 des_encrypt3(&data[0],key1,key2,key3);
59 GetTSC(e2);
60 des_encrypt3(&data[0],key1,key2,key3);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libcrypto/des/des_opts.c b/src/lib/libcrypto/des/des_opts.c
new file mode 100644
index 0000000000..fdf0fbf461
--- /dev/null
+++ b/src/lib/libcrypto/des/des_opts.c
@@ -0,0 +1,620 @@
1/* crypto/des/des_opts.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
60 * This is for machines with 64k code segment size restrictions. */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern void exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "des.h"
101#include "spr.h"
102
103#define DES_DEFAULT_OPTIONS
104
105#if !defined(PART1) && !defined(PART2) && !defined(PART3) && !defined(PART4)
106#define PART1
107#define PART2
108#define PART3
109#define PART4
110#endif
111
112#ifdef PART1
113
114#undef DES_UNROLL
115#undef DES_RISC1
116#undef DES_RISC2
117#undef DES_PTR
118#undef D_ENCRYPT
119#define des_encrypt des_encrypt_u4_cisc_idx
120#define des_encrypt2 des_encrypt2_u4_cisc_idx
121#define des_encrypt3 des_encrypt3_u4_cisc_idx
122#define des_decrypt3 des_decrypt3_u4_cisc_idx
123#undef HEADER_DES_LOCL_H
124#include "des_enc.c"
125
126#define DES_UNROLL
127#undef DES_RISC1
128#undef DES_RISC2
129#undef DES_PTR
130#undef D_ENCRYPT
131#undef des_encrypt
132#undef des_encrypt2
133#undef des_encrypt3
134#undef des_decrypt3
135#define des_encrypt des_encrypt_u16_cisc_idx
136#define des_encrypt2 des_encrypt2_u16_cisc_idx
137#define des_encrypt3 des_encrypt3_u16_cisc_idx
138#define des_decrypt3 des_decrypt3_u16_cisc_idx
139#undef HEADER_DES_LOCL_H
140#include "des_enc.c"
141
142#undef DES_UNROLL
143#define DES_RISC1
144#undef DES_RISC2
145#undef DES_PTR
146#undef D_ENCRYPT
147#undef des_encrypt
148#undef des_encrypt2
149#undef des_encrypt3
150#undef des_decrypt3
151#define des_encrypt des_encrypt_u4_risc1_idx
152#define des_encrypt2 des_encrypt2_u4_risc1_idx
153#define des_encrypt3 des_encrypt3_u4_risc1_idx
154#define des_decrypt3 des_decrypt3_u4_risc1_idx
155#undef HEADER_DES_LOCL_H
156#include "des_enc.c"
157
158#endif
159
160#ifdef PART2
161
162#undef DES_UNROLL
163#undef DES_RISC1
164#define DES_RISC2
165#undef DES_PTR
166#undef D_ENCRYPT
167#undef des_encrypt
168#undef des_encrypt2
169#undef des_encrypt3
170#undef des_decrypt3
171#define des_encrypt des_encrypt_u4_risc2_idx
172#define des_encrypt2 des_encrypt2_u4_risc2_idx
173#define des_encrypt3 des_encrypt3_u4_risc2_idx
174#define des_decrypt3 des_decrypt3_u4_risc2_idx
175#undef HEADER_DES_LOCL_H
176#include "des_enc.c"
177
178#define DES_UNROLL
179#define DES_RISC1
180#undef DES_RISC2
181#undef DES_PTR
182#undef D_ENCRYPT
183#undef des_encrypt
184#undef des_encrypt2
185#undef des_encrypt3
186#undef des_decrypt3
187#define des_encrypt des_encrypt_u16_risc1_idx
188#define des_encrypt2 des_encrypt2_u16_risc1_idx
189#define des_encrypt3 des_encrypt3_u16_risc1_idx
190#define des_decrypt3 des_decrypt3_u16_risc1_idx
191#undef HEADER_DES_LOCL_H
192#include "des_enc.c"
193
194#define DES_UNROLL
195#undef DES_RISC1
196#define DES_RISC2
197#undef DES_PTR
198#undef D_ENCRYPT
199#undef des_encrypt
200#undef des_encrypt2
201#undef des_encrypt3
202#undef des_decrypt3
203#define des_encrypt des_encrypt_u16_risc2_idx
204#define des_encrypt2 des_encrypt2_u16_risc2_idx
205#define des_encrypt3 des_encrypt3_u16_risc2_idx
206#define des_decrypt3 des_decrypt3_u16_risc2_idx
207#undef HEADER_DES_LOCL_H
208#include "des_enc.c"
209
210#endif
211
212#ifdef PART3
213
214#undef DES_UNROLL
215#undef DES_RISC1
216#undef DES_RISC2
217#define DES_PTR
218#undef D_ENCRYPT
219#undef des_encrypt
220#undef des_encrypt2
221#undef des_encrypt3
222#undef des_decrypt3
223#define des_encrypt des_encrypt_u4_cisc_ptr
224#define des_encrypt2 des_encrypt2_u4_cisc_ptr
225#define des_encrypt3 des_encrypt3_u4_cisc_ptr
226#define des_decrypt3 des_decrypt3_u4_cisc_ptr
227#undef HEADER_DES_LOCL_H
228#include "des_enc.c"
229
230#define DES_UNROLL
231#undef DES_RISC1
232#undef DES_RISC2
233#define DES_PTR
234#undef D_ENCRYPT
235#undef des_encrypt
236#undef des_encrypt2
237#undef des_encrypt3
238#undef des_decrypt3
239#define des_encrypt des_encrypt_u16_cisc_ptr
240#define des_encrypt2 des_encrypt2_u16_cisc_ptr
241#define des_encrypt3 des_encrypt3_u16_cisc_ptr
242#define des_decrypt3 des_decrypt3_u16_cisc_ptr
243#undef HEADER_DES_LOCL_H
244#include "des_enc.c"
245
246#undef DES_UNROLL
247#define DES_RISC1
248#undef DES_RISC2
249#define DES_PTR
250#undef D_ENCRYPT
251#undef des_encrypt
252#undef des_encrypt2
253#undef des_encrypt3
254#undef des_decrypt3
255#define des_encrypt des_encrypt_u4_risc1_ptr
256#define des_encrypt2 des_encrypt2_u4_risc1_ptr
257#define des_encrypt3 des_encrypt3_u4_risc1_ptr
258#define des_decrypt3 des_decrypt3_u4_risc1_ptr
259#undef HEADER_DES_LOCL_H
260#include "des_enc.c"
261
262#endif
263
264#ifdef PART4
265
266#undef DES_UNROLL
267#undef DES_RISC1
268#define DES_RISC2
269#define DES_PTR
270#undef D_ENCRYPT
271#undef des_encrypt
272#undef des_encrypt2
273#undef des_encrypt3
274#undef des_decrypt3
275#define des_encrypt des_encrypt_u4_risc2_ptr
276#define des_encrypt2 des_encrypt2_u4_risc2_ptr
277#define des_encrypt3 des_encrypt3_u4_risc2_ptr
278#define des_decrypt3 des_decrypt3_u4_risc2_ptr
279#undef HEADER_DES_LOCL_H
280#include "des_enc.c"
281
282#define DES_UNROLL
283#define DES_RISC1
284#undef DES_RISC2
285#define DES_PTR
286#undef D_ENCRYPT
287#undef des_encrypt
288#undef des_encrypt2
289#undef des_encrypt3
290#undef des_decrypt3
291#define des_encrypt des_encrypt_u16_risc1_ptr
292#define des_encrypt2 des_encrypt2_u16_risc1_ptr
293#define des_encrypt3 des_encrypt3_u16_risc1_ptr
294#define des_decrypt3 des_decrypt3_u16_risc1_ptr
295#undef HEADER_DES_LOCL_H
296#include "des_enc.c"
297
298#define DES_UNROLL
299#undef DES_RISC1
300#define DES_RISC2
301#define DES_PTR
302#undef D_ENCRYPT
303#undef des_encrypt
304#undef des_encrypt2
305#undef des_encrypt3
306#undef des_decrypt3
307#define des_encrypt des_encrypt_u16_risc2_ptr
308#define des_encrypt2 des_encrypt2_u16_risc2_ptr
309#define des_encrypt3 des_encrypt3_u16_risc2_ptr
310#define des_decrypt3 des_decrypt3_u16_risc2_ptr
311#undef HEADER_DES_LOCL_H
312#include "des_enc.c"
313
314#endif
315
316/* The following if from times(3) man page. It may need to be changed */
317#ifndef HZ
318# ifndef CLK_TCK
319# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
320# ifndef VMS
321# define HZ 100.0
322# else /* VMS */
323# define HZ 100.0
324# endif
325# else /* _BSD_CLK_TCK_ */
326# define HZ ((double)_BSD_CLK_TCK_)
327# endif
328# else /* CLK_TCK */
329# define HZ ((double)CLK_TCK)
330# endif
331#endif
332
333#define BUFSIZE ((long)1024)
334long run=0;
335
336#ifndef NOPROTO
337double Time_F(int s);
338#else
339double Time_F();
340#endif
341
342#ifdef SIGALRM
343#if defined(__STDC__) || defined(sgi)
344#define SIGRETTYPE void
345#else
346#define SIGRETTYPE int
347#endif
348
349#ifndef NOPROTO
350SIGRETTYPE sig_done(int sig);
351#else
352SIGRETTYPE sig_done();
353#endif
354
355SIGRETTYPE sig_done(sig)
356int sig;
357 {
358 signal(SIGALRM,sig_done);
359 run=0;
360#ifdef LINT
361 sig=sig;
362#endif
363 }
364#endif
365
366#define START 0
367#define STOP 1
368
369double Time_F(s)
370int s;
371 {
372 double ret;
373#ifdef TIMES
374 static struct tms tstart,tend;
375
376 if (s == START)
377 {
378 times(&tstart);
379 return(0);
380 }
381 else
382 {
383 times(&tend);
384 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
385 return((ret == 0.0)?1e-6:ret);
386 }
387#else /* !times() */
388 static struct timeb tstart,tend;
389 long i;
390
391 if (s == START)
392 {
393 ftime(&tstart);
394 return(0);
395 }
396 else
397 {
398 ftime(&tend);
399 i=(long)tend.millitm-(long)tstart.millitm;
400 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
401 return((ret == 0.0)?1e-6:ret);
402 }
403#endif
404 }
405
406#ifdef SIGALRM
407#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
408#else
409#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
410#endif
411
412#define time_it(func,name,index) \
413 print_name(name); \
414 Time_F(START); \
415 for (count=0,run=1; COND(cb); count++) \
416 { \
417 unsigned long d[2]; \
418 func(d,&(sch[0]),DES_ENCRYPT); \
419 } \
420 tm[index]=Time_F(STOP); \
421 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
422 tm[index]=((double)COUNT(cb))/tm[index];
423
424#define print_it(name,index) \
425 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
426 tm[index]*8,1.0e6/tm[index]);
427
428int main(argc,argv)
429int argc;
430char **argv;
431 {
432 long count;
433 static unsigned char buf[BUFSIZE];
434 static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
435 static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
436 static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
437 des_key_schedule sch,sch2,sch3;
438 double d,tm[16],max=0;
439 int rank[16];
440 char *str[16];
441 int max_idx=0,i,num=0,j;
442#ifndef SIGALARM
443 long ca,cb,cc,cd,ce;
444#endif
445
446 for (i=0; i<12; i++)
447 {
448 tm[i]=0.0;
449 rank[i]=0;
450 }
451
452#ifndef TIMES
453 fprintf(stderr,"To get the most acurate results, try to run this\n");
454 fprintf(stderr,"program when this computer is idle.\n");
455#endif
456
457 des_set_key((C_Block *)key,sch);
458 des_set_key((C_Block *)key2,sch2);
459 des_set_key((C_Block *)key3,sch3);
460
461#ifndef SIGALRM
462 fprintf(stderr,"First we calculate the approximate speed ...\n");
463 des_set_key((C_Block *)key,sch);
464 count=10;
465 do {
466 long i;
467 unsigned long data[2];
468
469 count*=2;
470 Time_F(START);
471 for (i=count; i; i--)
472 des_encrypt(data,&(sch[0]),DES_ENCRYPT);
473 d=Time_F(STOP);
474 } while (d < 3.0);
475 ca=count;
476 cb=count*3;
477 cc=count*3*8/BUFSIZE+1;
478 cd=count*8/BUFSIZE+1;
479
480 ce=count/20+1;
481#define COND(d) (count != (d))
482#define COUNT(d) (d)
483#else
484#define COND(c) (run)
485#define COUNT(d) (count)
486 signal(SIGALRM,sig_done);
487 alarm(10);
488#endif
489
490#ifdef PART1
491 time_it(des_encrypt_u4_cisc_idx, "des_encrypt_u4_cisc_idx ", 0);
492 time_it(des_encrypt_u16_cisc_idx, "des_encrypt_u16_cisc_idx ", 1);
493 time_it(des_encrypt_u4_risc1_idx, "des_encrypt_u4_risc1_idx ", 2);
494 num+=3;
495#endif
496#ifdef PART2
497 time_it(des_encrypt_u16_risc1_idx,"des_encrypt_u16_risc1_idx", 3);
498 time_it(des_encrypt_u4_risc2_idx, "des_encrypt_u4_risc2_idx ", 4);
499 time_it(des_encrypt_u16_risc2_idx,"des_encrypt_u16_risc2_idx", 5);
500 num+=3;
501#endif
502#ifdef PART3
503 time_it(des_encrypt_u4_cisc_ptr, "des_encrypt_u4_cisc_ptr ", 6);
504 time_it(des_encrypt_u16_cisc_ptr, "des_encrypt_u16_cisc_ptr ", 7);
505 time_it(des_encrypt_u4_risc1_ptr, "des_encrypt_u4_risc1_ptr ", 8);
506 num+=3;
507#endif
508#ifdef PART4
509 time_it(des_encrypt_u16_risc1_ptr,"des_encrypt_u16_risc1_ptr", 9);
510 time_it(des_encrypt_u4_risc2_ptr, "des_encrypt_u4_risc2_ptr ",10);
511 time_it(des_encrypt_u16_risc2_ptr,"des_encrypt_u16_risc2_ptr",11);
512 num+=3;
513#endif
514
515#ifdef PART1
516 str[0]=" 4 c i";
517 print_it("des_encrypt_u4_cisc_idx ",0);
518 max=tm[0];
519 max_idx=0;
520 str[1]="16 c i";
521 print_it("des_encrypt_u16_cisc_idx ",1);
522 if (max < tm[1]) { max=tm[1]; max_idx=1; }
523 str[2]=" 4 r1 i";
524 print_it("des_encrypt_u4_risc1_idx ",2);
525 if (max < tm[2]) { max=tm[2]; max_idx=2; }
526#endif
527#ifdef PART2
528 str[3]="16 r1 i";
529 print_it("des_encrypt_u16_risc1_idx",3);
530 if (max < tm[3]) { max=tm[3]; max_idx=3; }
531 str[4]=" 4 r2 i";
532 print_it("des_encrypt_u4_risc2_idx ",4);
533 if (max < tm[4]) { max=tm[4]; max_idx=4; }
534 str[5]="16 r2 i";
535 print_it("des_encrypt_u16_risc2_idx",5);
536 if (max < tm[5]) { max=tm[5]; max_idx=5; }
537#endif
538#ifdef PART3
539 str[6]=" 4 c p";
540 print_it("des_encrypt_u4_cisc_ptr ",6);
541 if (max < tm[6]) { max=tm[6]; max_idx=6; }
542 str[7]="16 c p";
543 print_it("des_encrypt_u16_cisc_ptr ",7);
544 if (max < tm[7]) { max=tm[7]; max_idx=7; }
545 str[8]=" 4 r1 p";
546 print_it("des_encrypt_u4_risc1_ptr ",8);
547 if (max < tm[8]) { max=tm[8]; max_idx=8; }
548#endif
549#ifdef PART4
550 str[9]="16 r1 p";
551 print_it("des_encrypt_u16_risc1_ptr",9);
552 if (max < tm[9]) { max=tm[9]; max_idx=9; }
553 str[10]=" 4 r2 p";
554 print_it("des_encrypt_u4_risc2_ptr ",10);
555 if (max < tm[10]) { max=tm[10]; max_idx=10; }
556 str[11]="16 r2 p";
557 print_it("des_encrypt_u16_risc2_ptr",11);
558 if (max < tm[11]) { max=tm[11]; max_idx=11; }
559#endif
560 printf("options des ecb/s\n");
561 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
562 d=tm[max_idx];
563 tm[max_idx]= -2.0;
564 max= -1.0;
565 for (;;)
566 {
567 for (i=0; i<12; i++)
568 {
569 if (max < tm[i]) { max=tm[i]; j=i; }
570 }
571 if (max < 0.0) break;
572 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
573 tm[j]= -2.0;
574 max= -1.0;
575 }
576
577 switch (max_idx)
578 {
579 case 0:
580 printf("-DDES_DEFAULT_OPTIONS\n");
581 break;
582 case 1:
583 printf("-DDES_UNROLL\n");
584 break;
585 case 2:
586 printf("-DDES_RISC1\n");
587 break;
588 case 3:
589 printf("-DDES_UNROLL -DDES_RISC1\n");
590 break;
591 case 4:
592 printf("-DDES_RISC2\n");
593 break;
594 case 5:
595 printf("-DDES_UNROLL -DDES_RISC2\n");
596 break;
597 case 6:
598 printf("-DDES_PTR\n");
599 break;
600 case 7:
601 printf("-DDES_UNROLL -DDES_PTR\n");
602 break;
603 case 8:
604 printf("-DDES_RISC1 -DDES_PTR\n");
605 break;
606 case 9:
607 printf("-DDES_UNROLL -DDES_RISC1 -DDES_PTR\n");
608 break;
609 case 10:
610 printf("-DDES_RISC2 -DDES_PTR\n");
611 break;
612 case 11:
613 printf("-DDES_UNROLL -DDES_RISC2 -DDES_PTR\n");
614 break;
615 }
616 exit(0);
617#if defined(LINT) || defined(MSDOS)
618 return(0);
619#endif
620 }
diff --git a/src/lib/libcrypto/des/des_ver.h b/src/lib/libcrypto/des/des_ver.h
new file mode 100644
index 0000000000..7041a9271d
--- /dev/null
+++ b/src/lib/libcrypto/des/des_ver.h
@@ -0,0 +1,60 @@
1/* crypto/des/des_ver.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59extern char *DES_version; /* SSLeay version string */
60extern char *libdes_version; /* old libdes version string */
diff --git a/src/lib/libcrypto/des/dess.cpp b/src/lib/libcrypto/des/dess.cpp
new file mode 100644
index 0000000000..7fb5987314
--- /dev/null
+++ b/src/lib/libcrypto/des/dess.cpp
@@ -0,0 +1,67 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include "des.h"
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt(&data[0],key,1);
49 GetTSC(s1);
50 des_encrypt(&data[0],key,1);
51 des_encrypt(&data[0],key,1);
52 des_encrypt(&data[0],key,1);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt(&data[0],key,1);
56 des_encrypt(&data[0],key,1);
57 des_encrypt(&data[0],key,1);
58 des_encrypt(&data[0],key,1);
59 GetTSC(e2);
60 des_encrypt(&data[0],key,1);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c
new file mode 100644
index 0000000000..620c13ba6f
--- /dev/null
+++ b/src/lib/libcrypto/des/destest.c
@@ -0,0 +1,882 @@
1/* crypto/des/destest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#if defined(WIN32) || defined(WIN16) || defined(WINDOWS)
60#ifndef MSDOS
61#define MSDOS
62#endif
63#endif
64
65#include <stdio.h>
66#include <stdlib.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71#endif
72#include <string.h>
73#include "des.h"
74
75/* tisk tisk - the test keys don't all have odd parity :-( */
76/* test data */
77#define NUM_TESTS 34
78static unsigned char key_data[NUM_TESTS][8]={
79 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
80 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
81 {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
82 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
83 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
84 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
85 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
86 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
87 {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
88 {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
89 {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
90 {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
91 {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
92 {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
93 {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
94 {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
95 {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
96 {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
97 {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
98 {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
99 {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
100 {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
101 {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
102 {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
103 {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
104 {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
105 {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
106 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
107 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
108 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
109 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
110 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
111 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
112 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
113
114static unsigned char plain_data[NUM_TESTS][8]={
115 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
116 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
117 {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
118 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
119 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
120 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
121 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
122 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
123 {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
124 {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
125 {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
126 {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
127 {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
128 {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
129 {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
130 {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
131 {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
132 {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
133 {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
134 {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
135 {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
136 {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
137 {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
138 {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
139 {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
140 {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
141 {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
142 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
143 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
144 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
145 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
146 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
147 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
148 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
149
150static unsigned char cipher_data[NUM_TESTS][8]={
151 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
152 {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58},
153 {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B},
154 {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33},
155 {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D},
156 {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD},
157 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
158 {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4},
159 {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B},
160 {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71},
161 {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A},
162 {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A},
163 {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95},
164 {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B},
165 {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09},
166 {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A},
167 {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F},
168 {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88},
169 {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77},
170 {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A},
171 {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56},
172 {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56},
173 {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56},
174 {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC},
175 {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A},
176 {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41},
177 {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93},
178 {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00},
179 {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06},
180 {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7},
181 {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51},
182 {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE},
183 {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D},
184 {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}};
185
186static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
187 {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E},
188 {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16},
189 {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27},
190 {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6},
191 {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25},
192 {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A},
193 {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74},
194 {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6},
195 {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67},
196 {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10},
197 {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85},
198 {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA},
199 {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3},
200 {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3},
201 {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A},
202 {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69},
203 {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1},
204 {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7},
205 {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F},
206 {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87},
207 {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A},
208 {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE},
209 {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3},
210 {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD},
211 {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84},
212 {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85},
213 {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC},
214 {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89},
215 {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E},
216 {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89},
217 {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7},
218 {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8},
219 {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
220
221static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
222static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
223static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
224static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
225/* Changed the following text constant to binary so it will work on ebcdic
226 * machines :-) */
227/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
228static char cbc_data[40]={
229 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20,
230 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74,
231 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20,
232 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00,
233 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
234 };
235
236static unsigned char cbc_ok[32]={
237 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
238 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb,
239 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
240 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
241
242static unsigned char xcbc_ok[32]={
243 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48,
244 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD,
245 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76,
246 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2,
247 };
248
249static unsigned char cbc3_ok[32]={
250 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0,
251 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC,
252 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4,
253 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75};
254
255static unsigned char pcbc_ok[32]={
256 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
257 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15,
258 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f,
259 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88};
260
261static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
262static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
263static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
264static unsigned char plain[24]=
265 {
266 0x4e,0x6f,0x77,0x20,0x69,0x73,
267 0x20,0x74,0x68,0x65,0x20,0x74,
268 0x69,0x6d,0x65,0x20,0x66,0x6f,
269 0x72,0x20,0x61,0x6c,0x6c,0x20
270 };
271static unsigned char cfb_cipher8[24]= {
272 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8,
273 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 };
274static unsigned char cfb_cipher16[24]={
275 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70,
276 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B };
277static unsigned char cfb_cipher32[24]={
278 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD,
279 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 };
280static unsigned char cfb_cipher48[24]={
281 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85,
282 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F };
283static unsigned char cfb_cipher64[24]={
284 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B,
285 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 };
286
287static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
288static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
289static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8];
290static unsigned char ofb_cipher[24]=
291 {
292 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
293 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
294 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
295 };
296
297DES_LONG cbc_cksum_ret=0xB462FEF7L;
298unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
299
300#ifndef NOPROTO
301static char *pt(unsigned char *p);
302static int cfb_test(int bits, unsigned char *cfb_cipher);
303static int cfb64_test(unsigned char *cfb_cipher);
304static int ede_cfb64_test(unsigned char *cfb_cipher);
305#else
306static char *pt();
307static int cfb_test();
308static int cfb64_test();
309static int ede_cfb64_test();
310#endif
311
312int main(argc,argv)
313int argc;
314char *argv[];
315 {
316 int i,j,err=0;
317 des_cblock in,out,outin,iv3;
318 des_key_schedule ks,ks2,ks3;
319 unsigned char cbc_in[40];
320 unsigned char cbc_out[40];
321 DES_LONG cs;
322 unsigned char qret[4][4],cret[8];
323 DES_LONG lqret[4];
324 int num;
325 char *str;
326
327 printf("Doing ecb\n");
328 for (i=0; i<NUM_TESTS; i++)
329 {
330 if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0)
331 {
332 printf("Key error %2d:%d\n",i+1,j);
333 err=1;
334 }
335 memcpy(in,plain_data[i],8);
336 memset(out,0,8);
337 memset(outin,0,8);
338 des_ecb_encrypt((C_Block *)in,(C_Block *)out,ks,DES_ENCRYPT);
339 des_ecb_encrypt((C_Block *)out,(C_Block *)outin,ks,DES_DECRYPT);
340
341 if (memcmp(out,cipher_data[i],8) != 0)
342 {
343 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
344 i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]),
345 pt(out));
346 err=1;
347 }
348 if (memcmp(in,outin,8) != 0)
349 {
350 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
351 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
352 err=1;
353 }
354 }
355
356#ifndef LIBDES_LIT
357 printf("Doing ede ecb\n");
358 for (i=0; i<(NUM_TESTS-1); i++)
359 {
360 if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0)
361 {
362 err=1;
363 printf("Key error %2d:%d\n",i+1,j);
364 }
365 if ((j=des_key_sched((C_Block *)(key_data[i+1]),ks2)) != 0)
366 {
367 printf("Key error %2d:%d\n",i+2,j);
368 err=1;
369 }
370 if ((j=des_key_sched((C_Block *)(key_data[i+2]),ks3)) != 0)
371 {
372 printf("Key error %2d:%d\n",i+3,j);
373 err=1;
374 }
375 memcpy(in,plain_data[i],8);
376 memset(out,0,8);
377 memset(outin,0,8);
378 des_ecb2_encrypt((C_Block *)in,(C_Block *)out,ks,ks2,
379 DES_ENCRYPT);
380 des_ecb2_encrypt((C_Block *)out,(C_Block *)outin,ks,ks2,
381 DES_DECRYPT);
382
383 if (memcmp(out,cipher_ecb2[i],8) != 0)
384 {
385 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
386 i+1,pt(key_data[i]),pt(in),pt(cipher_ecb2[i]),
387 pt(out));
388 err=1;
389 }
390 if (memcmp(in,outin,8) != 0)
391 {
392 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
393 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
394 err=1;
395 }
396 }
397#endif
398
399 printf("Doing cbc\n");
400 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
401 {
402 printf("Key error %d\n",j);
403 err=1;
404 }
405 memset(cbc_out,0,40);
406 memset(cbc_in,0,40);
407 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
408 des_ncbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
409 (long)strlen((char *)cbc_data)+1,ks,
410 (C_Block *)iv3,DES_ENCRYPT);
411 if (memcmp(cbc_out,cbc_ok,32) != 0)
412 printf("cbc_encrypt encrypt error\n");
413
414 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
415 des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
416 (long)strlen((char *)cbc_data)+1,ks,
417 (C_Block *)iv3,DES_DECRYPT);
418 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0)
419 {
420 printf("cbc_encrypt decrypt error\n");
421 err=1;
422 }
423
424#ifndef LIBDES_LIT
425 printf("Doing desx cbc\n");
426 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
427 {
428 printf("Key error %d\n",j);
429 err=1;
430 }
431 memset(cbc_out,0,40);
432 memset(cbc_in,0,40);
433 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
434 des_xcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
435 (long)strlen((char *)cbc_data)+1,ks,
436 (C_Block *)iv3,
437 (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_ENCRYPT);
438 if (memcmp(cbc_out,xcbc_ok,32) != 0)
439 {
440 printf("des_xcbc_encrypt encrypt error\n");
441 }
442 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
443 des_xcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
444 (long)strlen((char *)cbc_data)+1,ks,
445 (C_Block *)iv3,
446 (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_DECRYPT);
447 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
448 {
449 printf("des_xcbc_encrypt decrypt error\n");
450 err=1;
451 }
452#endif
453
454 printf("Doing ede cbc\n");
455 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
456 {
457 printf("Key error %d\n",j);
458 err=1;
459 }
460 if ((j=des_key_sched((C_Block *)cbc2_key,ks2)) != 0)
461 {
462 printf("Key error %d\n",j);
463 err=1;
464 }
465 if ((j=des_key_sched((C_Block *)cbc3_key,ks3)) != 0)
466 {
467 printf("Key error %d\n",j);
468 err=1;
469 }
470 memset(cbc_out,0,40);
471 memset(cbc_in,0,40);
472 i=strlen((char *)cbc_data)+1;
473 /* i=((i+7)/8)*8; */
474 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
475
476 des_ede3_cbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
477 16L,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT);
478 des_ede3_cbc_encrypt((C_Block *)&(cbc_data[16]),
479 (C_Block *)&(cbc_out[16]),
480 (long)i-16,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT);
481 if (memcmp(cbc_out,cbc3_ok,
482 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
483 {
484 printf("des_ede3_cbc_encrypt encrypt error\n");
485 err=1;
486 }
487
488 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
489 des_ede3_cbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
490 (long)i,ks,ks2,ks3,(C_Block *)iv3,DES_DECRYPT);
491 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
492 {
493 printf("des_ede3_cbc_encrypt decrypt error\n");
494 err=1;
495 }
496
497#ifndef LIBDES_LIT
498 printf("Doing pcbc\n");
499 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
500 {
501 printf("Key error %d\n",j);
502 err=1;
503 }
504 memset(cbc_out,0,40);
505 memset(cbc_in,0,40);
506 des_pcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
507 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_ENCRYPT);
508 if (memcmp(cbc_out,pcbc_ok,32) != 0)
509 {
510 printf("pcbc_encrypt encrypt error\n");
511 err=1;
512 }
513 des_pcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
514 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_DECRYPT);
515 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
516 {
517 printf("pcbc_encrypt decrypt error\n");
518 err=1;
519 }
520
521 printf("Doing ");
522 printf("cfb8 ");
523 err+=cfb_test(8,cfb_cipher8);
524 printf("cfb16 ");
525 err+=cfb_test(16,cfb_cipher16);
526 printf("cfb32 ");
527 err+=cfb_test(32,cfb_cipher32);
528 printf("cfb48 ");
529 err+=cfb_test(48,cfb_cipher48);
530 printf("cfb64 ");
531 err+=cfb_test(64,cfb_cipher64);
532
533 printf("cfb64() ");
534 err+=cfb64_test(cfb_cipher64);
535
536 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
537 for (i=0; i<sizeof(plain); i++)
538 des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]),
539 8,(long)1,ks,(C_Block *)cfb_tmp,DES_ENCRYPT);
540 if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
541 {
542 printf("cfb_encrypt small encrypt error\n");
543 err=1;
544 }
545
546 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
547 for (i=0; i<sizeof(plain); i++)
548 des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
549 8,(long)1,ks,(C_Block *)cfb_tmp,DES_DECRYPT);
550 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
551 {
552 printf("cfb_encrypt small decrypt error\n");
553 err=1;
554 }
555
556 printf("ede_cfb64() ");
557 err+=ede_cfb64_test(cfb_cipher64);
558
559 printf("done\n");
560
561 printf("Doing ofb\n");
562 des_key_sched((C_Block *)ofb_key,ks);
563 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
564 des_ofb_encrypt(plain,ofb_buf1,64,(long)sizeof(plain)/8,ks,
565 (C_Block *)ofb_tmp);
566 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
567 {
568 printf("ofb_encrypt encrypt error\n");
569printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
570ofb_buf1[8+0], ofb_buf1[8+1], ofb_buf1[8+2], ofb_buf1[8+3],
571ofb_buf1[8+4], ofb_buf1[8+5], ofb_buf1[8+6], ofb_buf1[8+7]);
572printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
573ofb_buf1[8+0], ofb_cipher[8+1], ofb_cipher[8+2], ofb_cipher[8+3],
574ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]);
575 err=1;
576 }
577 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
578 des_ofb_encrypt(ofb_buf1,ofb_buf2,64,(long)sizeof(ofb_buf1)/8,ks,
579 (C_Block *)ofb_tmp);
580 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
581 {
582 printf("ofb_encrypt decrypt error\n");
583printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
584ofb_buf2[8+0], ofb_buf2[8+1], ofb_buf2[8+2], ofb_buf2[8+3],
585ofb_buf2[8+4], ofb_buf2[8+5], ofb_buf2[8+6], ofb_buf2[8+7]);
586printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
587plain[8+0], plain[8+1], plain[8+2], plain[8+3],
588plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
589 err=1;
590 }
591
592 printf("Doing ofb64\n");
593 des_key_sched((C_Block *)ofb_key,ks);
594 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
595 memset(ofb_buf1,0,sizeof(ofb_buf1));
596 memset(ofb_buf2,0,sizeof(ofb_buf1));
597 num=0;
598 for (i=0; i<sizeof(plain); i++)
599 {
600 des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,
601 (C_Block *)ofb_tmp,&num);
602 }
603 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
604 {
605 printf("ofb64_encrypt encrypt error\n");
606 err=1;
607 }
608 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
609 num=0;
610 des_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks,
611 (C_Block *)ofb_tmp,&num);
612 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
613 {
614 printf("ofb64_encrypt decrypt error\n");
615 err=1;
616 }
617
618 printf("Doing ede_ofb64\n");
619 des_key_sched((C_Block *)ofb_key,ks);
620 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
621 memset(ofb_buf1,0,sizeof(ofb_buf1));
622 memset(ofb_buf2,0,sizeof(ofb_buf1));
623 num=0;
624 for (i=0; i<sizeof(plain); i++)
625 {
626 des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,ks,
627 (C_Block *)ofb_tmp,&num);
628 }
629 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
630 {
631 printf("ede_ofb64_encrypt encrypt error\n");
632 err=1;
633 }
634 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
635 num=0;
636 des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks,
637 ks,ks,(C_Block *)ofb_tmp,&num);
638 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
639 {
640 printf("ede_ofb64_encrypt decrypt error\n");
641 err=1;
642 }
643
644 printf("Doing cbc_cksum\n");
645 des_key_sched((C_Block *)cbc_key,ks);
646 cs=des_cbc_cksum((C_Block *)cbc_data,(C_Block *)cret,
647 (long)strlen(cbc_data),ks,(C_Block *)cbc_iv);
648 if (cs != cbc_cksum_ret)
649 {
650 printf("bad return value (%08lX), should be %08lX\n",
651 (unsigned long)cs,(unsigned long)cbc_cksum_ret);
652 err=1;
653 }
654 if (memcmp(cret,cbc_cksum_data,8) != 0)
655 {
656 printf("bad cbc_cksum block returned\n");
657 err=1;
658 }
659
660 printf("Doing quad_cksum\n");
661 cs=quad_cksum((C_Block *)cbc_data,(C_Block *)qret,
662 (long)strlen(cbc_data),2,(C_Block *)cbc_iv);
663 j=sizeof(lqret[0])-4;
664 for (i=0; i<4; i++)
665 {
666 lqret[i]=0;
667 memcpy(&(lqret[i]),&(qret[i][0]),4);
668 if (j > 0) lqret[i]=lqret[i]>>(j*8); /* For Cray */
669 }
670 { /* Big-endian fix */
671 static DES_LONG l=1;
672 static unsigned char *c=(unsigned char *)&l;
673 DES_LONG ll;
674
675 if (!c[0])
676 {
677 ll=lqret[0]^lqret[3];
678 lqret[0]^=ll;
679 lqret[3]^=ll;
680 ll=lqret[1]^lqret[2];
681 lqret[1]^=ll;
682 lqret[2]^=ll;
683 }
684 }
685 if (cs != 0x70d7a63aL)
686 {
687 printf("quad_cksum error, ret %08lx should be 70d7a63a\n",
688 (unsigned long)cs);
689 err=1;
690 }
691 if (lqret[0] != 0x327eba8dL)
692 {
693 printf("quad_cksum error, out[0] %08lx is not %08lx\n",
694 (unsigned long)lqret[0],0x327eba8dL);
695 err=1;
696 }
697 if (lqret[1] != 0x201a49ccL)
698 {
699 printf("quad_cksum error, out[1] %08lx is not %08lx\n",
700 (unsigned long)lqret[1],0x201a49ccL);
701 err=1;
702 }
703 if (lqret[2] != 0x70d7a63aL)
704 {
705 printf("quad_cksum error, out[2] %08lx is not %08lx\n",
706 (unsigned long)lqret[2],0x70d7a63aL);
707 err=1;
708 }
709 if (lqret[3] != 0x501c2c26L)
710 {
711 printf("quad_cksum error, out[3] %08lx is not %08lx\n",
712 (unsigned long)lqret[3],0x501c2c26L);
713 err=1;
714 }
715#endif
716
717 printf("input word alignment test");
718 for (i=0; i<4; i++)
719 {
720 printf(" %d",i);
721 des_ncbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in,
722 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,
723 DES_ENCRYPT);
724 }
725 printf("\noutput word alignment test");
726 for (i=0; i<4; i++)
727 {
728 printf(" %d",i);
729 des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]),
730 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,
731 DES_ENCRYPT);
732 }
733 printf("\n");
734 printf("fast crypt test ");
735 str=crypt("testing","ef");
736 if (strcmp("efGnQx2725bI2",str) != 0)
737 {
738 printf("fast crypt error, %s should be efGnQx2725bI2\n",str);
739 err=1;
740 }
741 str=crypt("bca76;23","yA");
742 if (strcmp("yA1Rp/1hZXIJk",str) != 0)
743 {
744 printf("fast crypt error, %s should be yA1Rp/1hZXIJk\n",str);
745 err=1;
746 }
747 printf("\n");
748 exit(err);
749 return(0);
750 }
751
752static char *pt(p)
753unsigned char *p;
754 {
755 static char bufs[10][20];
756 static int bnum=0;
757 char *ret;
758 int i;
759 static char *f="0123456789ABCDEF";
760
761 ret= &(bufs[bnum++][0]);
762 bnum%=10;
763 for (i=0; i<8; i++)
764 {
765 ret[i*2]=f[(p[i]>>4)&0xf];
766 ret[i*2+1]=f[p[i]&0xf];
767 }
768 ret[16]='\0';
769 return(ret);
770 }
771
772#ifndef LIBDES_LIT
773
774static int cfb_test(bits, cfb_cipher)
775int bits;
776unsigned char *cfb_cipher;
777 {
778 des_key_schedule ks;
779 int i,err=0;
780
781 des_key_sched((C_Block *)cfb_key,ks);
782 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
783 des_cfb_encrypt(plain,cfb_buf1,bits,(long)sizeof(plain),ks,
784 (C_Block *)cfb_tmp,DES_ENCRYPT);
785 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
786 {
787 err=1;
788 printf("cfb_encrypt encrypt error\n");
789 for (i=0; i<24; i+=8)
790 printf("%s\n",pt(&(cfb_buf1[i])));
791 }
792 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
793 des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,(long)sizeof(plain),ks,
794 (C_Block *)cfb_tmp,DES_DECRYPT);
795 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
796 {
797 err=1;
798 printf("cfb_encrypt decrypt error\n");
799 for (i=0; i<24; i+=8)
800 printf("%s\n",pt(&(cfb_buf1[i])));
801 }
802 return(err);
803 }
804
805static int cfb64_test(cfb_cipher)
806unsigned char *cfb_cipher;
807 {
808 des_key_schedule ks;
809 int err=0,i,n;
810
811 des_key_sched((C_Block *)cfb_key,ks);
812 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
813 n=0;
814 des_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,
815 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
816 des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
817 (long)sizeof(plain)-12,ks,
818 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
819 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
820 {
821 err=1;
822 printf("cfb_encrypt encrypt error\n");
823 for (i=0; i<24; i+=8)
824 printf("%s\n",pt(&(cfb_buf1[i])));
825 }
826 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
827 n=0;
828 des_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,
829 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
830 des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
831 (long)sizeof(plain)-17,ks,
832 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
833 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
834 {
835 err=1;
836 printf("cfb_encrypt decrypt error\n");
837 for (i=0; i<24; i+=8)
838 printf("%s\n",pt(&(cfb_buf2[i])));
839 }
840 return(err);
841 }
842
843static int ede_cfb64_test(cfb_cipher)
844unsigned char *cfb_cipher;
845 {
846 des_key_schedule ks;
847 int err=0,i,n;
848
849 des_key_sched((C_Block *)cfb_key,ks);
850 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
851 n=0;
852 des_ede3_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,ks,ks,
853 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
854 des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
855 (long)sizeof(plain)-12,ks,ks,ks,
856 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
857 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
858 {
859 err=1;
860 printf("ede_cfb_encrypt encrypt error\n");
861 for (i=0; i<24; i+=8)
862 printf("%s\n",pt(&(cfb_buf1[i])));
863 }
864 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
865 n=0;
866 des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,
867 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
868 des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
869 (long)sizeof(plain)-17,ks,ks,ks,
870 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
871 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
872 {
873 err=1;
874 printf("ede_cfb_encrypt decrypt error\n");
875 for (i=0; i<24; i+=8)
876 printf("%s\n",pt(&(cfb_buf2[i])));
877 }
878 return(err);
879 }
880
881#endif
882
diff --git a/src/lib/libcrypto/des/makefile.bc b/src/lib/libcrypto/des/makefile.bc
new file mode 100644
index 0000000000..1fe6d4915a
--- /dev/null
+++ b/src/lib/libcrypto/des/makefile.bc
@@ -0,0 +1,50 @@
1#
2# Origional BC Makefile from Teun <Teun.Nijssen@kub.nl>
3#
4#
5CC = bcc
6TLIB = tlib /0 /C
7# note: the -3 flag produces code for 386, 486, Pentium etc; omit it for 286s
8OPTIMIZE= -3 -O2
9#WINDOWS= -W
10CFLAGS = -c -ml -d $(OPTIMIZE) $(WINDOWS) -DMSDOS
11LFLAGS = -ml $(WINDOWS)
12
13.c.obj:
14 $(CC) $(CFLAGS) $*.c
15
16.obj.exe:
17 $(CC) $(LFLAGS) -e$*.exe $*.obj libdes.lib
18
19all: $(LIB) destest.exe rpw.exe des.exe speed.exe
20
21# "make clean": use a directory containing only libdes .exe and .obj files...
22clean:
23 del *.exe
24 del *.obj
25 del libdes.lib
26 del libdes.rsp
27
28OBJS= cbc_cksm.obj cbc_enc.obj ecb_enc.obj pcbc_enc.obj \
29 qud_cksm.obj rand_key.obj set_key.obj str2key.obj \
30 enc_read.obj enc_writ.obj fcrypt.obj cfb_enc.obj \
31 ecb3_enc.obj ofb_enc.obj cbc3_enc.obj read_pwd.obj\
32 cfb64enc.obj ofb64enc.obj ede_enc.obj cfb64ede.obj\
33 ofb64ede.obj supp.obj
34
35LIB= libdes.lib
36
37$(LIB): $(OBJS)
38 del $(LIB)
39 makersp "+%s &\n" &&|
40 $(OBJS)
41| >libdes.rsp
42 $(TLIB) libdes.lib @libdes.rsp,nul
43 del libdes.rsp
44
45destest.exe: destest.obj libdes.lib
46rpw.exe: rpw.obj libdes.lib
47speed.exe: speed.obj libdes.lib
48des.exe: des.obj libdes.lib
49
50
diff --git a/src/lib/libcrypto/des/options.txt b/src/lib/libcrypto/des/options.txt
new file mode 100644
index 0000000000..6e2b50f765
--- /dev/null
+++ b/src/lib/libcrypto/des/options.txt
@@ -0,0 +1,39 @@
1Note that the UNROLL option makes the 'inner' des loop unroll all 16 rounds
2instead of the default 4.
3RISC1 and RISC2 are 2 alternatives for the inner loop and
4PTR means to use pointers arithmatic instead of arrays.
5
6FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - assembler 577,000 4620k/s
7IRIX 6.2 - R10000 195mhz - cc (-O3 -n32) - UNROLL RISC2 PTR 496,000 3968k/s
8solaris 2.5.1 usparc 167mhz?? - SC4.0 - UNROLL RISC1 PTR [1] 459,400 3672k/s
9FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - UNROLL RISC1 433,000 3468k/s
10solaris 2.5.1 usparc 167mhz?? - gcc 2.7.2 - UNROLL 380,000 3041k/s
11linux - pentium 100mhz - gcc 2.7.0 - assembler 281,000 2250k/s
12NT 4.0 - pentium 100mhz - VC 4.2 - assembler 281,000 2250k/s
13AIX 4.1? - PPC604 100mhz - cc - UNROLL 275,000 2200k/s
14IRIX 5.3 - R4400 200mhz - gcc 2.6.3 - UNROLL RISC2 PTR 235,300 1882k/s
15IRIX 5.3 - R4400 200mhz - cc - UNROLL RISC2 PTR 233,700 1869k/s
16NT 4.0 - pentium 100mhz - VC 4.2 - UNROLL RISC1 PTR 191,000 1528k/s
17DEC Alpha 165mhz?? - cc - RISC2 PTR [2] 181,000 1448k/s
18linux - pentium 100mhz - gcc 2.7.0 - UNROLL RISC1 PTR 158,500 1268k/s
19HPUX 10 - 9000/887 - cc - UNROLL [3] 148,000 1190k/s
20solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2 - UNROLL 123,600 989k/s
21IRIX 5.3 - R4000 100mhz - cc - UNROLL RISC2 PTR 101,000 808k/s
22DGUX - 88100 50mhz(?) - gcc 2.6.3 - UNROLL 81,000 648k/s
23solaris 2.4 486 50mhz - gcc 2.6.3 - assembler 65,000 522k/s
24HPUX 10 - 9000/887 - k&r cc (default compiler) - UNROLL PTR 76,000 608k/s
25solaris 2.4 486 50mhz - gcc 2.6.3 - UNROLL RISC2 43,500 344k/s
26AIX - old slow one :-) - cc - 39,000 312k/s
27
28Notes.
29[1] For the ultra sparc, SunC 4.0
30 cc -xtarget=ultra -xarch=v8plus -Xa -xO5, running 'des_opts'
31 gives a speed of 344,000 des/s while 'speed' gives 459,000 des/s.
32 I'll record the higher since it is coming from the library but it
33 is all rather weird.
34[2] Similar to the ultra sparc ([1]), 181,000 for 'des_opts' vs 175,000.
35[3] I was unable to get access to this machine when it was not heavily loaded.
36 As such, my timing program was never able to get more that %30 of the CPU.
37 This would cause the program to give much lower speed numbers because
38 it would be 'fighting' to stay in the cache with the other CPU burning
39 processes.
diff --git a/src/lib/libcrypto/des/read2pwd.c b/src/lib/libcrypto/des/read2pwd.c
new file mode 100644
index 0000000000..a0d53793e4
--- /dev/null
+++ b/src/lib/libcrypto/des/read2pwd.c
@@ -0,0 +1,90 @@
1/* crypto/des/read2pwd.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61int des_read_password(key, prompt, verify)
62des_cblock (*key);
63char *prompt;
64int verify;
65 {
66 int ok;
67 char buf[BUFSIZ],buff[BUFSIZ];
68
69 if ((ok=des_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
70 des_string_to_key(buf,key);
71 memset(buf,0,BUFSIZ);
72 memset(buff,0,BUFSIZ);
73 return(ok);
74 }
75
76int des_read_2passwords(key1, key2, prompt, verify)
77des_cblock (*key1);
78des_cblock (*key2);
79char *prompt;
80int verify;
81 {
82 int ok;
83 char buf[BUFSIZ],buff[BUFSIZ];
84
85 if ((ok=des_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
86 des_string_to_2keys(buf,key1,key2);
87 memset(buf,0,BUFSIZ);
88 memset(buff,0,BUFSIZ);
89 return(ok);
90 }
diff --git a/src/lib/libcrypto/des/read_pwd.c b/src/lib/libcrypto/des/read_pwd.c
new file mode 100644
index 0000000000..99920f2f86
--- /dev/null
+++ b/src/lib/libcrypto/des/read_pwd.c
@@ -0,0 +1,459 @@
1/* crypto/des/read_pwd.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* #define SIGACTION */ /* Define this if you have sigaction() */
60#ifdef WIN16TTY
61#undef WIN16
62#undef _WINDOWS
63#include <graph.h>
64#endif
65
66/* 06-Apr-92 Luke Brennan Support for VMS */
67#include "des_locl.h"
68#include <signal.h>
69#include <string.h>
70#include <setjmp.h>
71#include <errno.h>
72
73/* There are 5 types of terminal interface supported,
74 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
75 */
76
77#if defined(__sgi) && !defined(TERMIOS)
78#define TERMIOS
79#undef TERMIO
80#undef SGTTY
81#endif
82
83#if defined(linux) && !defined(TERMIO)
84#undef TERMIOS
85#define TERMIO
86#undef SGTTY
87#endif
88
89#ifdef _LIBC
90#undef TERMIOS
91#define TERMIO
92#undef SGTTY
93#endif
94
95#if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS)
96#undef TERMIOS
97#undef TERMIO
98#define SGTTY
99#endif
100
101#ifdef TERMIOS
102#include <termios.h>
103#define TTY_STRUCT struct termios
104#define TTY_FLAGS c_lflag
105#define TTY_get(tty,data) tcgetattr(tty,data)
106#define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
107#endif
108
109#ifdef TERMIO
110#include <termio.h>
111#define TTY_STRUCT struct termio
112#define TTY_FLAGS c_lflag
113#define TTY_get(tty,data) ioctl(tty,TCGETA,data)
114#define TTY_set(tty,data) ioctl(tty,TCSETA,data)
115#endif
116
117#ifdef SGTTY
118#include <sgtty.h>
119#define TTY_STRUCT struct sgttyb
120#define TTY_FLAGS sg_flags
121#define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
122#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
123#endif
124
125#if !defined(_LIBC) && !defined(MSDOS) && !defined(VMS)
126#include <sys/ioctl.h>
127#endif
128
129#ifdef MSDOS
130#include <conio.h>
131#define fgets(a,b,c) noecho_fgets(a,b,c)
132#endif
133
134#ifdef VMS
135#include <ssdef.h>
136#include <iodef.h>
137#include <ttdef.h>
138#include <descrip.h>
139struct IOSB {
140 short iosb$w_value;
141 short iosb$w_count;
142 long iosb$l_info;
143 };
144#endif
145
146#ifndef NX509_SIG
147#define NX509_SIG 32
148#endif
149
150#ifndef NOPROTO
151static void read_till_nl(FILE *);
152static void recsig(int);
153static void pushsig(void);
154static void popsig(void);
155#if defined(MSDOS) && !defined(WIN16)
156static int noecho_fgets(char *buf, int size, FILE *tty);
157#endif
158#else
159static void read_till_nl();
160static void recsig();
161static void pushsig();
162static void popsig();
163#if defined(MSDOS) && !defined(WIN16)
164static int noecho_fgets();
165#endif
166#endif
167
168#ifdef SIGACTION
169 static struct sigaction savsig[NX509_SIG];
170#else
171# ifndef NOPROTO
172 static void (*savsig[NX509_SIG])(int );
173# else
174 static void (*savsig[NX509_SIG])();
175# endif
176#endif
177static jmp_buf save;
178
179int des_read_pw_string(buf, length, prompt, verify)
180char *buf;
181int length;
182char *prompt;
183int verify;
184 {
185 char buff[BUFSIZ];
186 int ret;
187
188 ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
189 memset(buff,0,BUFSIZ);
190 return(ret);
191 }
192
193#ifndef WIN16
194
195static void read_till_nl(in)
196FILE *in;
197 {
198#define SIZE 4
199 char buf[SIZE+1];
200
201 do {
202 fgets(buf,SIZE,in);
203 } while (strchr(buf,'\n') == NULL);
204 }
205
206
207/* return 0 if ok, 1 (or -1) otherwise */
208int des_read_pw(buf, buff, size, prompt, verify)
209char *buf;
210char *buff;
211int size;
212char *prompt;
213int verify;
214 {
215#ifdef VMS
216 struct IOSB iosb;
217 $DESCRIPTOR(terminal,"TT");
218 long tty_orig[3], tty_new[3];
219 long status;
220 unsigned short channel = 0;
221#else
222#ifndef MSDOS
223 TTY_STRUCT tty_orig,tty_new;
224#endif
225#endif
226 int number=5;
227 int ok=0;
228 int ps=0;
229 int is_a_tty=1;
230
231 FILE *tty=NULL;
232 char *p;
233
234#ifndef MSDOS
235 if ((tty=fopen("/dev/tty","r")) == NULL)
236 tty=stdin;
237#else /* MSDOS */
238 if ((tty=fopen("con","r")) == NULL)
239 tty=stdin;
240#endif /* MSDOS */
241
242#if defined(TTY_get) && !defined(VMS)
243 if (TTY_get(fileno(tty),&tty_orig) == -1)
244 {
245#ifdef ENOTTY
246 if (errno == ENOTTY)
247 is_a_tty=0;
248 else
249#endif
250#ifdef EINVAL
251 /* Ariel Glenn ariel@columbia.edu reports that solaris
252 * can return EINVAL instead. This should be ok */
253 if (errno == EINVAL)
254 is_a_tty=0;
255 else
256#endif
257 return(-1);
258 }
259 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
260#endif
261#ifdef VMS
262 status = SYS$ASSIGN(&terminal,&channel,0,0);
263 if (status != SS$_NORMAL)
264 return(-1);
265 status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
266 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
267 return(-1);
268#endif
269
270 if (setjmp(save))
271 {
272 ok=0;
273 goto error;
274 }
275 pushsig();
276 ps=1;
277
278#ifdef TTY_FLAGS
279 tty_new.TTY_FLAGS &= ~ECHO;
280#endif
281
282#if defined(TTY_set) && !defined(VMS)
283 if (is_a_tty && (TTY_set(fileno(tty),&tty_new) == -1))
284 return(-1);
285#endif
286#ifdef VMS
287 tty_new[0] = tty_orig[0];
288 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
289 tty_new[2] = tty_orig[2];
290 status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
291 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
292 return(-1);
293#endif
294 ps=2;
295
296 while ((!ok) && (number--))
297 {
298 fputs(prompt,stderr);
299 fflush(stderr);
300
301 buf[0]='\0';
302 fgets(buf,size,tty);
303 if (feof(tty)) goto error;
304 if (ferror(tty)) goto error;
305 if ((p=(char *)strchr(buf,'\n')) != NULL)
306 *p='\0';
307 else read_till_nl(tty);
308 if (verify)
309 {
310 fprintf(stderr,"\nVerifying password - %s",prompt);
311 fflush(stderr);
312 buff[0]='\0';
313 fgets(buff,size,tty);
314 if (feof(tty)) goto error;
315 if ((p=(char *)strchr(buff,'\n')) != NULL)
316 *p='\0';
317 else read_till_nl(tty);
318
319 if (strcmp(buf,buff) != 0)
320 {
321 fprintf(stderr,"\nVerify failure");
322 fflush(stderr);
323 break;
324 /* continue; */
325 }
326 }
327 ok=1;
328 }
329
330error:
331 fprintf(stderr,"\n");
332#ifdef DEBUG
333 perror("fgets(tty)");
334#endif
335 /* What can we do if there is an error? */
336#if defined(TTY_set) && !defined(VMS)
337 if (ps >= 2) TTY_set(fileno(tty),&tty_orig);
338#endif
339#ifdef VMS
340 if (ps >= 2)
341 status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0
342 ,tty_orig,12,0,0,0,0);
343#endif
344
345 if (ps >= 1) popsig();
346 if (stdin != tty) fclose(tty);
347#ifdef VMS
348 status = SYS$DASSGN(channel);
349#endif
350 return(!ok);
351 }
352
353#else /* WIN16 */
354
355int des_read_pw(buf, buff, size, prompt, verify)
356char *buf;
357char *buff;
358int size;
359char *prompt;
360int verify;
361 {
362 memset(buf,0,size);
363 memset(buff,0,size);
364 return(0);
365 }
366
367#endif
368
369static void pushsig()
370 {
371 int i;
372
373 for (i=1; i<NX509_SIG; i++)
374 {
375#ifdef SIGUSR1
376 if (i == SIGUSR1)
377 continue;
378#endif
379#ifdef SIGUSR2
380 if (i == SIGUSR2)
381 continue;
382#endif
383#ifdef SIGACTION
384 sigaction(i,NULL,&savsig[i]);
385#else
386 savsig[i]=signal(i,recsig);
387#endif
388 }
389
390#ifdef SIGWINCH
391 signal(SIGWINCH,SIG_DFL);
392#endif
393 }
394
395static void popsig()
396 {
397 int i;
398
399 for (i=1; i<NX509_SIG; i++)
400 {
401#ifdef SIGUSR1
402 if (i == SIGUSR1)
403 continue;
404#endif
405#ifdef SIGUSR2
406 if (i == SIGUSR2)
407 continue;
408#endif
409#ifdef SIGACTION
410 sigaction(i,&savsig[i],NULL);
411#else
412 signal(i,savsig[i]);
413#endif
414 }
415 }
416
417static void recsig(i)
418int i;
419 {
420 longjmp(save,1);
421#ifdef LINT
422 i=i;
423#endif
424 }
425
426#if defined(MSDOS) && !defined(WIN16)
427static int noecho_fgets(buf,size,tty)
428char *buf;
429int size;
430FILE *tty;
431 {
432 int i;
433 char *p;
434
435 p=buf;
436 for (;;)
437 {
438 if (size == 0)
439 {
440 *p='\0';
441 break;
442 }
443 size--;
444#ifdef WIN16TTY
445 i=_inchar();
446#else
447 i=getch();
448#endif
449 if (i == '\r') i='\n';
450 *(p++)=i;
451 if (i == '\n')
452 {
453 *p='\0';
454 break;
455 }
456 }
457 return(strlen(buf));
458 }
459#endif
diff --git a/src/lib/libcrypto/des/rpc_des.h b/src/lib/libcrypto/des/rpc_des.h
new file mode 100644
index 0000000000..4cbb4d2dcd
--- /dev/null
+++ b/src/lib/libcrypto/des/rpc_des.h
@@ -0,0 +1,131 @@
1/* crypto/des/rpc_des.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* @(#)des.h 2.2 88/08/10 4.0 RPCSRC; from 2.7 88/02/08 SMI */
60/*
61 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
62 * unrestricted use provided that this legend is included on all tape
63 * media and as a part of the software program in whole or part. Users
64 * may copy or modify Sun RPC without charge, but are not authorized
65 * to license or distribute it to anyone else except as part of a product or
66 * program developed by the user.
67 *
68 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
69 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
70 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
71 *
72 * Sun RPC is provided with no support and without any obligation on the
73 * part of Sun Microsystems, Inc. to assist in its use, correction,
74 * modification or enhancement.
75 *
76 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
77 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
78 * OR ANY PART THEREOF.
79 *
80 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
81 * or profits or other special, indirect and consequential damages, even if
82 * Sun has been advised of the possibility of such damages.
83 *
84 * Sun Microsystems, Inc.
85 * 2550 Garcia Avenue
86 * Mountain View, California 94043
87 */
88/*
89 * Generic DES driver interface
90 * Keep this file hardware independent!
91 * Copyright (c) 1986 by Sun Microsystems, Inc.
92 */
93
94#define DES_MAXLEN 65536 /* maximum # of bytes to encrypt */
95#define DES_QUICKLEN 16 /* maximum # of bytes to encrypt quickly */
96
97#ifdef HEADER_DES_H
98#undef ENCRYPT
99#undef DECRYPT
100#endif
101
102enum desdir { ENCRYPT, DECRYPT };
103enum desmode { CBC, ECB };
104
105/*
106 * parameters to ioctl call
107 */
108struct desparams {
109 unsigned char des_key[8]; /* key (with low bit parity) */
110 enum desdir des_dir; /* direction */
111 enum desmode des_mode; /* mode */
112 unsigned char des_ivec[8]; /* input vector */
113 unsigned des_len; /* number of bytes to crypt */
114 union {
115 unsigned char UDES_data[DES_QUICKLEN];
116 unsigned char *UDES_buf;
117 } UDES;
118# define des_data UDES.UDES_data /* direct data here if quick */
119# define des_buf UDES.UDES_buf /* otherwise, pointer to data */
120};
121
122/*
123 * Encrypt an arbitrary sized buffer
124 */
125#define DESIOCBLOCK _IOWR(d, 6, struct desparams)
126
127/*
128 * Encrypt of small amount of data, quickly
129 */
130#define DESIOCQUICK _IOWR(d, 7, struct desparams)
131
diff --git a/src/lib/libcrypto/des/rpc_enc.c b/src/lib/libcrypto/des/rpc_enc.c
new file mode 100644
index 0000000000..7c1da1f538
--- /dev/null
+++ b/src/lib/libcrypto/des/rpc_enc.c
@@ -0,0 +1,107 @@
1/* crypto/des/rpc_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "rpc_des.h"
60#include "des_locl.h"
61#include "des_ver.h"
62
63#ifndef NOPROTO
64int _des_crypt(char *buf,int len,struct desparams *desp);
65#else
66int _des_crypt();
67#endif
68
69int _des_crypt(buf, len, desp)
70char *buf;
71int len;
72struct desparams *desp;
73 {
74 des_key_schedule ks;
75 int enc;
76
77 des_set_key((des_cblock *)desp->des_key,ks);
78 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
79
80 if (desp->des_mode == CBC)
81 des_ecb_encrypt((des_cblock *)desp->UDES.UDES_buf,
82 (des_cblock *)desp->UDES.UDES_buf,ks,enc);
83 else
84 {
85 des_ncbc_encrypt((des_cblock *)desp->UDES.UDES_buf,
86 (des_cblock *)desp->UDES.UDES_buf,
87 (long)len,ks,
88 (des_cblock *)desp->des_ivec,enc);
89#ifdef undef
90 /* len will always be %8 if called from common_crypt
91 * in secure_rpc.
92 * Libdes's cbc encrypt does not copy back the iv,
93 * so we have to do it here. */
94 /* It does now :-) eay 20/09/95 */
95
96 a=(char *)&(desp->UDES.UDES_buf[len-8]);
97 b=(char *)&(desp->des_ivec[0]);
98
99 *(a++)= *(b++); *(a++)= *(b++);
100 *(a++)= *(b++); *(a++)= *(b++);
101 *(a++)= *(b++); *(a++)= *(b++);
102 *(a++)= *(b++); *(a++)= *(b++);
103#endif
104 }
105 return(1);
106 }
107
diff --git a/src/lib/libcrypto/des/rpw.c b/src/lib/libcrypto/des/rpw.c
new file mode 100644
index 0000000000..6447ed9cf0
--- /dev/null
+++ b/src/lib/libcrypto/des/rpw.c
@@ -0,0 +1,101 @@
1/* crypto/des/rpw.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "des.h"
61
62int main(argc,argv)
63int argc;
64char *argv[];
65 {
66 des_cblock k,k1;
67 int i;
68
69 printf("read passwd\n");
70 if ((i=des_read_password((C_Block *)k,"Enter password:",0)) == 0)
71 {
72 printf("password = ");
73 for (i=0; i<8; i++)
74 printf("%02x ",k[i]);
75 }
76 else
77 printf("error %d\n",i);
78 printf("\n");
79 printf("read 2passwds and verify\n");
80 if ((i=des_read_2passwords((C_Block *)k,(C_Block *)k1,
81 "Enter verified password:",1)) == 0)
82 {
83 printf("password1 = ");
84 for (i=0; i<8; i++)
85 printf("%02x ",k[i]);
86 printf("\n");
87 printf("password2 = ");
88 for (i=0; i<8; i++)
89 printf("%02x ",k1[i]);
90 printf("\n");
91 exit(1);
92 }
93 else
94 {
95 printf("error %d\n",i);
96 exit(0);
97 }
98#ifdef LINT
99 return(0);
100#endif
101 }
diff --git a/src/lib/libcrypto/des/speed.c b/src/lib/libcrypto/des/speed.c
new file mode 100644
index 0000000000..5bbe8b01d6
--- /dev/null
+++ b/src/lib/libcrypto/des/speed.c
@@ -0,0 +1,329 @@
1/* crypto/des/speed.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern int exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "des.h"
101
102/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ
104# ifndef CLK_TCK
105# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
106# ifndef VMS
107# define HZ 100.0
108# else /* VMS */
109# define HZ 100.0
110# endif
111# else /* _BSD_CLK_TCK_ */
112# define HZ ((double)_BSD_CLK_TCK_)
113# endif
114# else /* CLK_TCK */
115# define HZ ((double)CLK_TCK)
116# endif
117#endif
118
119#define BUFSIZE ((long)1024)
120long run=0;
121
122#ifndef NOPROTO
123double Time_F(int s);
124#else
125double Time_F();
126#endif
127
128#ifdef SIGALRM
129#if defined(__STDC__) || defined(sgi) || defined(_AIX)
130#define SIGRETTYPE void
131#else
132#define SIGRETTYPE int
133#endif
134
135#ifndef NOPROTO
136SIGRETTYPE sig_done(int sig);
137#else
138SIGRETTYPE sig_done();
139#endif
140
141SIGRETTYPE sig_done(sig)
142int sig;
143 {
144 signal(SIGALRM,sig_done);
145 run=0;
146#ifdef LINT
147 sig=sig;
148#endif
149 }
150#endif
151
152#define START 0
153#define STOP 1
154
155double Time_F(s)
156int s;
157 {
158 double ret;
159#ifdef TIMES
160 static struct tms tstart,tend;
161
162 if (s == START)
163 {
164 times(&tstart);
165 return(0);
166 }
167 else
168 {
169 times(&tend);
170 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
171 return((ret == 0.0)?1e-6:ret);
172 }
173#else /* !times() */
174 static struct timeb tstart,tend;
175 long i;
176
177 if (s == START)
178 {
179 ftime(&tstart);
180 return(0);
181 }
182 else
183 {
184 ftime(&tend);
185 i=(long)tend.millitm-(long)tstart.millitm;
186 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
187 return((ret == 0.0)?1e-6:ret);
188 }
189#endif
190 }
191
192int main(argc,argv)
193int argc;
194char **argv;
195 {
196 long count;
197 static unsigned char buf[BUFSIZE];
198 static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
199 static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
200 static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
201 des_key_schedule sch,sch2,sch3;
202 double a,b,c,d,e;
203#ifndef SIGALRM
204 long ca,cb,cc,cd,ce;
205#endif
206
207#ifndef TIMES
208 printf("To get the most acurate results, try to run this\n");
209 printf("program when this computer is idle.\n");
210#endif
211
212 des_set_key((C_Block *)key2,sch2);
213 des_set_key((C_Block *)key3,sch3);
214
215#ifndef SIGALRM
216 printf("First we calculate the approximate speed ...\n");
217 des_set_key((C_Block *)key,sch);
218 count=10;
219 do {
220 long i;
221 DES_LONG data[2];
222
223 count*=2;
224 Time_F(START);
225 for (i=count; i; i--)
226 des_encrypt(data,&(sch[0]),DES_ENCRYPT);
227 d=Time_F(STOP);
228 } while (d < 3.0);
229 ca=count;
230 cb=count*3;
231 cc=count*3*8/BUFSIZE+1;
232 cd=count*8/BUFSIZE+1;
233 ce=count/20+1;
234 printf("Doing set_key %ld times\n",ca);
235#define COND(d) (count != (d))
236#define COUNT(d) (d)
237#else
238#define COND(c) (run)
239#define COUNT(d) (count)
240 signal(SIGALRM,sig_done);
241 printf("Doing set_key for 10 seconds\n");
242 alarm(10);
243#endif
244
245 Time_F(START);
246 for (count=0,run=1; COND(ca); count++)
247 des_set_key((C_Block *)key,sch);
248 d=Time_F(STOP);
249 printf("%ld set_key's in %.2f seconds\n",count,d);
250 a=((double)COUNT(ca))/d;
251
252#ifdef SIGALRM
253 printf("Doing des_encrypt's for 10 seconds\n");
254 alarm(10);
255#else
256 printf("Doing des_encrypt %ld times\n",cb);
257#endif
258 Time_F(START);
259 for (count=0,run=1; COND(cb); count++)
260 {
261 DES_LONG data[2];
262
263 des_encrypt(data,&(sch[0]),DES_ENCRYPT);
264 }
265 d=Time_F(STOP);
266 printf("%ld des_encrypt's in %.2f second\n",count,d);
267 b=((double)COUNT(cb)*8)/d;
268
269#ifdef SIGALRM
270 printf("Doing des_cbc_encrypt on %ld byte blocks for 10 seconds\n",
271 BUFSIZE);
272 alarm(10);
273#else
274 printf("Doing des_cbc_encrypt %ld times on %ld byte blocks\n",cc,
275 BUFSIZE);
276#endif
277 Time_F(START);
278 for (count=0,run=1; COND(cc); count++)
279 des_ncbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,&(sch[0]),
280 (C_Block *)&(key[0]),DES_ENCRYPT);
281 d=Time_F(STOP);
282 printf("%ld des_cbc_encrypt's of %ld byte blocks in %.2f second\n",
283 count,BUFSIZE,d);
284 c=((double)COUNT(cc)*BUFSIZE)/d;
285
286#ifdef SIGALRM
287 printf("Doing des_ede_cbc_encrypt on %ld byte blocks for 10 seconds\n",
288 BUFSIZE);
289 alarm(10);
290#else
291 printf("Doing des_ede_cbc_encrypt %ld times on %ld byte blocks\n",cd,
292 BUFSIZE);
293#endif
294 Time_F(START);
295 for (count=0,run=1; COND(cd); count++)
296 des_ede3_cbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,
297 &(sch[0]),
298 &(sch2[0]),
299 &(sch3[0]),
300 (C_Block *)&(key[0]),
301 DES_ENCRYPT);
302 d=Time_F(STOP);
303 printf("%ld des_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n",
304 count,BUFSIZE,d);
305 d=((double)COUNT(cd)*BUFSIZE)/d;
306
307#ifdef SIGALRM
308 printf("Doing crypt for 10 seconds\n");
309 alarm(10);
310#else
311 printf("Doing crypt %ld times\n",ce);
312#endif
313 Time_F(START);
314 for (count=0,run=1; COND(ce); count++)
315 crypt("testing1","ef");
316 e=Time_F(STOP);
317 printf("%ld crypts in %.2f second\n",count,e);
318 e=((double)COUNT(ce))/e;
319
320 printf("set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
321 printf("DES raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
322 printf("DES cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
323 printf("DES ede cbc bytes per sec = %12.2f (%9.3fuS)\n",d,8.0e6/d);
324 printf("crypt per sec = %12.2f (%9.3fuS)\n",e,1.0e6/e);
325 exit(0);
326#if defined(LINT) || defined(MSDOS)
327 return(0);
328#endif
329 }
diff --git a/src/lib/libcrypto/des/t/test b/src/lib/libcrypto/des/t/test
new file mode 100644
index 0000000000..97acd0552e
--- /dev/null
+++ b/src/lib/libcrypto/des/t/test
@@ -0,0 +1,27 @@
1#!./perl
2
3BEGIN { push(@INC, qw(../../../lib ../../lib ../lib lib)); }
4
5use DES;
6
7$key='00000000';
8$ks=DES::set_key($key);
9@a=split(//,$ks);
10foreach (@a) { printf "%02x-",ord($_); }
11print "\n";
12
13
14$key=DES::random_key();
15print "($_)\n";
16@a=split(//,$key);
17foreach (@a) { printf "%02x-",ord($_); }
18print "\n";
19$str="this is and again into the breach";
20($k1,$k2)=DES::string_to_2keys($str);
21@a=split(//,$k1);
22foreach (@a) { printf "%02x-",ord($_); }
23print "\n";
24@a=split(//,$k2);
25foreach (@a) { printf "%02x-",ord($_); }
26print "\n";
27
diff --git a/src/lib/libcrypto/des/times/486-50.sol b/src/lib/libcrypto/des/times/486-50.sol
new file mode 100644
index 0000000000..0de62d6db3
--- /dev/null
+++ b/src/lib/libcrypto/des/times/486-50.sol
@@ -0,0 +1,16 @@
1Solaris 2.4, 486 50mhz, gcc 2.6.3
2options des ecb/s
316 r2 i 43552.51 100.0%
416 r1 i 43487.45 99.9%
516 c p 43003.23 98.7%
616 r2 p 42339.00 97.2%
716 c i 41900.91 96.2%
816 r1 p 41360.64 95.0%
9 4 c i 38728.48 88.9%
10 4 c p 38225.63 87.8%
11 4 r1 i 38085.79 87.4%
12 4 r2 i 37825.64 86.9%
13 4 r2 p 34611.00 79.5%
14 4 r1 p 31802.00 73.0%
15-DDES_UNROLL -DDES_RISC2
16
diff --git a/src/lib/libcrypto/des/times/586-100.lnx b/src/lib/libcrypto/des/times/586-100.lnx
new file mode 100644
index 0000000000..4323914a11
--- /dev/null
+++ b/src/lib/libcrypto/des/times/586-100.lnx
@@ -0,0 +1,20 @@
1Pentium 100
2Linux 2 kernel
3gcc 2.7.0 -O3 -fomit-frame-pointer
4No X server running, just a console, it makes the top speed jump from 151,000
5to 158,000 :-).
6options des ecb/s
7assember 281000.00 177.1%
816 r1 p 158667.40 100.0%
916 r1 i 148471.70 93.6%
1016 r2 p 143961.80 90.7%
1116 r2 i 141689.20 89.3%
12 4 r1 i 140100.00 88.3%
13 4 r2 i 134049.40 84.5%
1416 c i 124145.20 78.2%
1516 c p 121584.20 76.6%
16 4 c i 118116.00 74.4%
17 4 r2 p 117977.90 74.4%
18 4 c p 114971.40 72.5%
19 4 r1 p 114578.40 72.2%
20-DDES_UNROLL -DDES_RISC1 -DDES_PTR
diff --git a/src/lib/libcrypto/des/times/686-200.fre b/src/lib/libcrypto/des/times/686-200.fre
new file mode 100644
index 0000000000..7d83f6adee
--- /dev/null
+++ b/src/lib/libcrypto/des/times/686-200.fre
@@ -0,0 +1,18 @@
1Pentium 100
2Free BSD 2.1.5 kernel
3gcc 2.7.2.2 -O3 -fomit-frame-pointer
4options des ecb/s
5assember 578000.00 133.1%
616 r2 i 434454.80 100.0%
716 r1 i 433621.43 99.8%
816 r2 p 431375.69 99.3%
9 4 r1 i 423722.30 97.5%
10 4 r2 i 422399.40 97.2%
1116 r1 p 421739.40 97.1%
1216 c i 399027.94 91.8%
1316 c p 372251.70 85.7%
14 4 c i 365118.35 84.0%
15 4 c p 352880.51 81.2%
16 4 r2 p 255104.90 58.7%
17 4 r1 p 251289.18 57.8%
18-DDES_UNROLL -DDES_RISC2
diff --git a/src/lib/libcrypto/des/times/aix.cc b/src/lib/libcrypto/des/times/aix.cc
new file mode 100644
index 0000000000..d96b74e2ce
--- /dev/null
+++ b/src/lib/libcrypto/des/times/aix.cc
@@ -0,0 +1,26 @@
1From: Paco Garcia <pgarcia@cam.es>
2
3This machine is a Bull Estrella Minitower Model MT604-100
4Processor : PPC604
5P.Speed : 100Mhz
6Data/Instr Cache : 16 K
7L2 Cache : 256 K
8PCI BUS Speed : 33 Mhz
9TransfRate PCI : 132 MB/s
10Memory : 96 MB
11
12options des ecb/s
13 4 c p 275118.61 100.0%
14 4 c i 273545.07 99.4%
15 4 r2 p 270441.02 98.3%
16 4 r1 p 253052.15 92.0%
17 4 r2 i 240842.97 87.5%
18 4 r1 i 240556.66 87.4%
1916 c i 224603.99 81.6%
2016 c p 224483.98 81.6%
2116 r2 p 215691.19 78.4%
2216 r1 p 208332.83 75.7%
2316 r1 i 199206.50 72.4%
2416 r2 i 198963.70 72.3%
25-DDES_PTR
26
diff --git a/src/lib/libcrypto/des/times/alpha.cc b/src/lib/libcrypto/des/times/alpha.cc
new file mode 100644
index 0000000000..95c17efae7
--- /dev/null
+++ b/src/lib/libcrypto/des/times/alpha.cc
@@ -0,0 +1,18 @@
1cc -O2
2DES_LONG is 'unsigned int'
3
4options des ecb/s
5 4 r2 p 181146.14 100.0%
616 r2 p 172102.94 95.0%
7 4 r2 i 165424.11 91.3%
816 c p 160468.64 88.6%
9 4 c p 156653.59 86.5%
10 4 c i 155245.18 85.7%
11 4 r1 p 154729.68 85.4%
1216 r2 i 154137.69 85.1%
1316 r1 p 152357.96 84.1%
1416 c i 148743.91 82.1%
15 4 r1 i 146695.59 81.0%
1616 r1 i 144961.00 80.0%
17-DDES_RISC2 -DDES_PTR
18
diff --git a/src/lib/libcrypto/des/times/hpux.cc b/src/lib/libcrypto/des/times/hpux.cc
new file mode 100644
index 0000000000..3de856ddac
--- /dev/null
+++ b/src/lib/libcrypto/des/times/hpux.cc
@@ -0,0 +1,17 @@
1HPUX 10 - 9000/887 - cc -D_HPUX_SOURCE -Aa +ESlit +O2 -Wl,-a,archive
2
3options des ecb/s
416 c i 149448.90 100.0%
5 4 c i 145861.79 97.6%
616 r2 i 141710.96 94.8%
716 r1 i 139455.33 93.3%
8 4 r2 i 138800.00 92.9%
9 4 r1 i 136692.65 91.5%
1016 r2 p 110228.17 73.8%
1116 r1 p 109397.07 73.2%
1216 c p 109209.89 73.1%
13 4 c p 108014.71 72.3%
14 4 r2 p 107873.88 72.2%
15 4 r1 p 107685.83 72.1%
16-DDES_UNROLL
17
diff --git a/src/lib/libcrypto/des/times/sparc.gcc b/src/lib/libcrypto/des/times/sparc.gcc
new file mode 100644
index 0000000000..8eaa042104
--- /dev/null
+++ b/src/lib/libcrypto/des/times/sparc.gcc
@@ -0,0 +1,17 @@
1solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2
2
3options des ecb/s
416 c i 124382.70 100.0%
5 4 c i 118884.68 95.6%
616 c p 112261.20 90.3%
716 r2 i 111777.10 89.9%
816 r2 p 108896.30 87.5%
916 r1 p 108791.59 87.5%
10 4 c p 107290.10 86.3%
11 4 r1 p 104583.80 84.1%
1216 r1 i 104206.20 83.8%
13 4 r2 p 103709.80 83.4%
14 4 r2 i 98306.43 79.0%
15 4 r1 i 91525.80 73.6%
16-DDES_UNROLL
17
diff --git a/src/lib/libcrypto/des/times/usparc.cc b/src/lib/libcrypto/des/times/usparc.cc
new file mode 100644
index 0000000000..f6ec8e8831
--- /dev/null
+++ b/src/lib/libcrypto/des/times/usparc.cc
@@ -0,0 +1,31 @@
1solaris 2.5.1 usparc 167mhz?? - SC4.0 cc -fast -Xa -xO5
2
3For the ultra sparc, SunC 4.0 cc -fast -Xa -xO5, running 'des_opts'
4gives a speed of 475,000 des/s while 'speed' gives 417,000 des/s.
5I belive the difference is tied up in optimisation that the compiler
6is able to perform when the code is 'inlined'. For 'speed', the DES
7routines are being linked from a library. I'll record the higher
8speed since if performance is everything, you can always inline
9'des_enc.c'.
10
11[ 16-Jan-06 - I've been playing with the
12 '-xtarget=ultra -xarch=v8plus -Xa -xO5 -Xa'
13 and while it makes the des_opts numbers much slower, it makes the
14 actual 'speed' numbers look better which is a realistic version of
15 using the libraries. ]
16
17options des ecb/s
1816 r1 p 475516.90 100.0%
1916 r2 p 439388.10 92.4%
2016 c i 427001.40 89.8%
2116 c p 419516.50 88.2%
22 4 r2 p 409491.70 86.1%
23 4 r1 p 404266.90 85.0%
24 4 c p 398121.00 83.7%
25 4 c i 370588.40 77.9%
26 4 r1 i 362742.20 76.3%
2716 r2 i 331275.50 69.7%
2816 r1 i 324730.60 68.3%
29 4 r2 i 63535.10 13.4% <-- very very weird, must be cache problems.
30-DDES_UNROLL -DDES_RISC1 -DDES_PTR
31
diff --git a/src/lib/libcrypto/des/typemap b/src/lib/libcrypto/des/typemap
new file mode 100644
index 0000000000..a524f53634
--- /dev/null
+++ b/src/lib/libcrypto/des/typemap
@@ -0,0 +1,34 @@
1#
2# DES SECTION
3#
4deschar * T_DESCHARP
5des_cblock * T_CBLOCK
6des_cblock T_CBLOCK
7des_key_schedule T_SCHEDULE
8des_key_schedule * T_SCHEDULE
9
10INPUT
11T_CBLOCK
12 $var=(des_cblock *)SvPV($arg,len);
13 if (len < DES_KEY_SZ)
14 {
15 croak(\"$var needs to be at least %u bytes long\",DES_KEY_SZ);
16 }
17
18T_SCHEDULE
19 $var=(des_key_schedule *)SvPV($arg,len);
20 if (len < DES_SCHEDULE_SZ)
21 {
22 croak(\"$var needs to be at least %u bytes long\",
23 DES_SCHEDULE_SZ);
24 }
25
26OUTPUT
27T_CBLOCK
28 sv_setpvn($arg,(char *)$var,DES_KEY_SZ);
29
30T_SCHEDULE
31 sv_setpvn($arg,(char *)$var,DES_SCHEDULE_SZ);
32
33T_DESCHARP
34 sv_setpvn($arg,(char *)$var,len);