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/COPYRIGHT50
-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/FILES0 (renamed from src/lib/libcrypto/des/FILES)0
-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/Makefile292
-rw-r--r--src/lib/libcrypto/des/README54
-rw-r--r--src/lib/libcrypto/des/VERSION412
-rw-r--r--src/lib/libcrypto/des/asm/crypt586.pl208
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl255
-rw-r--r--src/lib/libcrypto/des/asm/des686.pl230
-rw-r--r--src/lib/libcrypto/des/asm/des_enc.m41980
-rw-r--r--src/lib/libcrypto/des/asm/desboth.pl79
-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/cbc_cksm.c106
-rw-r--r--src/lib/libcrypto/des/cbc_enc.c61
-rw-r--r--src/lib/libcrypto/des/cfb64ede.c254
-rw-r--r--src/lib/libcrypto/des/cfb64enc.c121
-rw-r--r--src/lib/libcrypto/des/cfb_enc.c195
-rw-r--r--src/lib/libcrypto/des/des-lib.com1003
-rw-r--r--src/lib/libcrypto/des/des.c932
-rw-r--r--src/lib/libcrypto/des/des.h247
-rw-r--r--src/lib/libcrypto/des/des.pod217
-rw-r--r--src/lib/libcrypto/des/des3s.cpp67
-rw-r--r--src/lib/libcrypto/des/des_enc.c411
-rw-r--r--src/lib/libcrypto/des/des_locl.h428
-rw-r--r--src/lib/libcrypto/des/des_old.c273
-rw-r--r--src/lib/libcrypto/des/des_old.h446
-rw-r--r--src/lib/libcrypto/des/des_old2.c82
-rw-r--r--src/lib/libcrypto/des/des_opts.c608
-rw-r--r--src/lib/libcrypto/des/des_ver.h71
-rw-r--r--src/lib/libcrypto/des/dess.cpp67
-rw-r--r--src/lib/libcrypto/des/destest.c952
-rw-r--r--src/lib/libcrypto/des/ecb3_enc.c83
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c123
-rw-r--r--src/lib/libcrypto/des/ede_cbcm_enc.c199
-rw-r--r--src/lib/libcrypto/des/enc_read.c228
-rw-r--r--src/lib/libcrypto/des/enc_writ.c171
-rw-r--r--src/lib/libcrypto/des/fcrypt.c170
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c148
-rw-r--r--src/lib/libcrypto/des/makefile.bc50
-rw-r--r--src/lib/libcrypto/des/ncbc_enc.c148
-rw-r--r--src/lib/libcrypto/des/ofb64ede.c125
-rw-r--r--src/lib/libcrypto/des/ofb64enc.c110
-rw-r--r--src/lib/libcrypto/des/ofb_enc.c135
-rw-r--r--src/lib/libcrypto/des/options.txt39
-rw-r--r--src/lib/libcrypto/des/pcbc_enc.c123
-rw-r--r--src/lib/libcrypto/des/qud_cksm.c139
-rw-r--r--src/lib/libcrypto/des/rand_key.c68
-rw-r--r--src/lib/libcrypto/des/read2pwd.c140
-rw-r--r--src/lib/libcrypto/des/read_pwd.c521
-rw-r--r--src/lib/libcrypto/des/rpc_des.h131
-rw-r--r--src/lib/libcrypto/des/rpc_enc.c98
-rw-r--r--src/lib/libcrypto/des/rpw.c99
-rw-r--r--src/lib/libcrypto/des/set_key.c407
-rw-r--r--src/lib/libcrypto/des/speed.c314
-rw-r--r--src/lib/libcrypto/des/spr.h204
-rw-r--r--src/lib/libcrypto/des/str2key.c174
-rw-r--r--src/lib/libcrypto/des/t/test27
-rw-r--r--src/lib/libcrypto/des/times/486-50.sol16
-rw-r--r--src/lib/libcrypto/des/times/586-100.lnx20
-rw-r--r--src/lib/libcrypto/des/times/686-200.fre18
-rw-r--r--src/lib/libcrypto/des/times/aix.cc26
-rw-r--r--src/lib/libcrypto/des/times/alpha.cc18
-rw-r--r--src/lib/libcrypto/des/times/hpux.cc17
-rw-r--r--src/lib/libcrypto/des/times/sparc.gcc17
-rw-r--r--src/lib/libcrypto/des/times/usparc.cc31
-rw-r--r--src/lib/libcrypto/des/typemap34
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c197
72 files changed, 15331 insertions, 0 deletions
diff --git a/src/lib/libcrypto/des/COPYRIGHT b/src/lib/libcrypto/des/COPYRIGHT
new file mode 100644
index 0000000000..5469e1e469
--- /dev/null
+++ b/src/lib/libcrypto/des/COPYRIGHT
@@ -0,0 +1,50 @@
1Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
2All rights reserved.
3
4This package is an DES implementation written by Eric Young (eay@cryptsoft.com).
5The implementation was written so as to conform with MIT's libdes.
6
7This library is free for commercial and non-commercial use as long as
8the following conditions are aheared to. The following conditions
9apply to all code found in this distribution.
10
11Copyright remains Eric Young's, and as such any Copyright notices in
12the code are not to be removed.
13If this package is used in a product, Eric Young should be given attribution
14as the author of that the SSL library. This can be in the form of a textual
15message at program startup or in documentation (online or textual) provided
16with the package.
17
18Redistribution and use in source and binary forms, with or without
19modification, are permitted provided that the following conditions
20are met:
211. Redistributions of source code must retain the copyright
22 notice, this list of conditions and the following disclaimer.
232. Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
263. All advertising materials mentioning features or use of this software
27 must display the following acknowledgement:
28 This product includes software developed by Eric Young (eay@cryptsoft.com)
29
30THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
31ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40SUCH DAMAGE.
41
42The license and distribution terms for any publically available version or
43derivative of this code cannot be changed. i.e. this code cannot simply be
44copied and put under another distrubution license
45[including the GNU Public License.]
46
47The reason behind this being stated in this direct manner is past
48experience in code simply being copied and the attribution removed
49from it and then being distributed as part of other packages. This
50implementation was a non-trivial and unpaid effort.
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/FILES b/src/lib/libcrypto/des/FILES0
index 4c7ea2de7a..4c7ea2de7a 100644
--- a/src/lib/libcrypto/des/FILES
+++ b/src/lib/libcrypto/des/FILES0
diff --git a/src/lib/libcrypto/des/INSTALL b/src/lib/libcrypto/des/INSTALL
new file mode 100644
index 0000000000..8aebdfe110
--- /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 relevant option in the Makefile.
29
30There are some special Makefile targets that make life easier.
31make cc - standard cc build
32make gcc - standard gcc build
33make x86-elf - x86 assembler (elf), linux-elf.
34make x86-out - x86 assembler (a.out), FreeBSD
35make x86-solaris- x86 assembler
36make x86-bsdi - x86 assembler (a.out with primative assembler).
37
38If at all possible use the assembler (for Windows NT/95, use
39asm/win32.obj to link with). The x86 assembler is very very fast.
40
41A make install will by default install
42libdes.a in /usr/local/lib/libdes.a
43des in /usr/local/bin/des
44des_crypt.man in /usr/local/man/man3/des_crypt.3
45des.man in /usr/local/man/man1/des.1
46des.h in /usr/include/des.h
47
48des(1) should be compatible with sunOS's but I have been unable to
49test it.
50
51These routines should compile on MSDOS, most 32bit and 64bit version
52of Unix (BSD and SYSV) and VMS, without modification.
53The only problems should be #include files that are in the wrong places.
54
55These routines can be compiled under MSDOS.
56I have successfully encrypted files using des(1) under MSDOS and then
57decrypted the files on a SparcStation.
58I have been able to compile and test the routines with
59Microsoft C v 5.1 and Turbo C v 2.0.
60The code in this library is in no way optimised for the 16bit
61operation of MSDOS.
62
63When building for glibc, ignore all of the above and just unpack into
64glibc-1.??/des and then gmake as per normal.
65
66As a final note on performace. Certain CPUs like sparcs and Alpha often give
67a %10 speed difference depending on the link order. It is rather anoying
68when one program reports 'x' DES encrypts a second and another reports
69'x*0.9' the speed.
diff --git a/src/lib/libcrypto/des/Imakefile b/src/lib/libcrypto/des/Imakefile
new file mode 100644
index 0000000000..1b9b5629e1
--- /dev/null
+++ b/src/lib/libcrypto/des/Imakefile
@@ -0,0 +1,35 @@
1# This Imakefile has not been tested for a while but it should still
2# work when placed in the correct directory in the kerberos v 4 distribution
3
4SRCS= cbc_cksm.c cbc_enc.c ecb_enc.c pcbc_enc.c \
5 qud_cksm.c rand_key.c read_pwd.c set_key.c str2key.c \
6 enc_read.c enc_writ.c fcrypt.c cfb_enc.c \
7 ecb3_enc.c ofb_enc.c ofb64enc.c
8
9OBJS= cbc_cksm.o cbc_enc.o ecb_enc.o pcbc_enc.o \
10 qud_cksm.o rand_key.o read_pwd.o set_key.o str2key.o \
11 enc_read.o enc_writ.o fcrypt.o cfb_enc.o \
12 ecb3_enc.o ofb_enc.o ofb64enc.o
13
14GENERAL=COPYRIGHT FILES INSTALL Imakefile README VERSION makefile times \
15 vms.com KERBEROS
16DES= des.c des.man
17TESTING=destest.c speed.c rpw.c
18LIBDES= des_crypt.man des.h des_locl.h podd.h sk.h spr.h
19
20PERL= des.pl testdes.pl doIP doPC1 doPC2 PC1 PC2 shifts.pl
21
22CODE= $(GENERAL) $(DES) $(TESTING) $(SRCS) $(LIBDES) $(PERL)
23
24SRCDIR=$(SRCTOP)/lib/des
25
26DBG= -O
27INCLUDE= -I$(SRCDIR)
28CC= cc
29
30library_obj_rule()
31
32install_library_target(des,$(OBJS),$(SRCS),)
33
34test(destest,libdes.a,)
35test(rpw,libdes.a,)
diff --git a/src/lib/libcrypto/des/KERBEROS b/src/lib/libcrypto/des/KERBEROS
new file mode 100644
index 0000000000..f401b10014
--- /dev/null
+++ b/src/lib/libcrypto/des/KERBEROS
@@ -0,0 +1,41 @@
1 [ This is an old file, I don't know if it is true anymore
2 but I will leave the file here - eay 21/11/95 ]
3
4To use this library with Bones (kerberos without DES):
51) Get my modified Bones - eBones. It can be found on
6 gondwana.ecr.mu.oz.au (128.250.1.63) /pub/athena/eBones-p9.tar.Z
7 and
8 nic.funet.fi (128.214.6.100) /pub/unix/security/Kerberos/eBones-p9.tar.Z
9
102) Unpack this library in src/lib/des, makeing sure it is version
11 3.00 or greater (libdes.tar.93-10-07.Z). This versions differences
12 from the version in comp.sources.misc volume 29 patchlevel2.
13 The primarily difference is that it should compile under kerberos :-).
14 It can be found at.
15 ftp.psy.uq.oz.au (130.102.32.1) /pub/DES/libdes.tar.93-10-07.Z
16
17Now do a normal kerberos build and things should work.
18
19One problem I found when I was build on my local sun.
20---
21For sunOS 4.1.1 apply the following patch to src/util/ss/make_commands.c
22
23*** make_commands.c.orig Fri Jul 3 04:18:35 1987
24--- make_commands.c Wed May 20 08:47:42 1992
25***************
26*** 98,104 ****
27 if (!rename(o_file, z_file)) {
28 if (!vfork()) {
29 chdir("/tmp");
30! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r", "-n",
31 z_file+5, 0);
32 perror("/bin/ld");
33 _exit(1);
34--- 98,104 ----
35 if (!rename(o_file, z_file)) {
36 if (!vfork()) {
37 chdir("/tmp");
38! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r",
39 z_file+5, 0);
40 perror("/bin/ld");
41 _exit(1);
diff --git a/src/lib/libcrypto/des/Makefile b/src/lib/libcrypto/des/Makefile
new file mode 100644
index 0000000000..523dfe38f2
--- /dev/null
+++ b/src/lib/libcrypto/des/Makefile
@@ -0,0 +1,292 @@
1#
2# OpenSSL/crypto/des/Makefile
3#
4
5DIR= des
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=-I$(TOP) -I../../include
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13RANLIB= ranlib
14DES_ENC= des_enc.o fcrypt_b.o
15# or use
16#DES_ENC= dx86-elf.o yx86-elf.o
17
18CFLAGS= $(INCLUDES) $(CFLAG)
19ASFLAGS= $(INCLUDES) $(ASFLAG)
20AFLAGS= $(ASFLAGS)
21
22GENERAL=Makefile
23TEST=destest.c
24APPS=
25
26LIB=$(TOP)/libcrypto.a
27LIBSRC= cbc_cksm.c cbc_enc.c cfb64enc.c cfb_enc.c \
28 ecb3_enc.c ecb_enc.c enc_read.c enc_writ.c \
29 fcrypt.c ofb64enc.c ofb_enc.c pcbc_enc.c \
30 qud_cksm.c rand_key.c rpc_enc.c set_key.c \
31 des_enc.c fcrypt_b.c \
32 xcbc_enc.c \
33 str2key.c cfb64ede.c ofb64ede.c ede_cbcm_enc.c des_old.c des_old2.c \
34 read2pwd.c
35
36LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \
37 ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \
38 enc_read.o enc_writ.o ofb64enc.o \
39 ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \
40 ${DES_ENC} \
41 fcrypt.o xcbc_enc.o rpc_enc.o cbc_cksm.o \
42 ede_cbcm_enc.o des_old.o des_old2.o read2pwd.o
43
44SRC= $(LIBSRC)
45
46EXHEADER= des.h des_old.h
47HEADER= des_locl.h rpc_des.h spr.h des_ver.h $(EXHEADER)
48
49ALL= $(GENERAL) $(SRC) $(HEADER)
50
51top:
52 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
53
54all: lib
55
56lib: $(LIBOBJ)
57 $(AR) $(LIB) $(LIBOBJ)
58 $(RANLIB) $(LIB) || echo Never mind.
59 @touch lib
60
61des: des.o cbc3_enc.o lib
62 $(CC) $(CFLAGS) -o des des.o cbc3_enc.o $(LIB)
63
64des_enc-sparc.S: asm/des_enc.m4
65 m4 -B 8192 asm/des_enc.m4 > des_enc-sparc.S
66
67# ELF
68dx86-elf.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
69 (cd asm; $(PERL) des-586.pl elf $(CFLAGS) > ../$@)
70yx86-elf.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
71 (cd asm; $(PERL) crypt586.pl elf $(CFLAGS) > ../$@)
72# COFF
73dx86-cof.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
74 (cd asm; $(PERL) des-586.pl coff $(CFLAGS) > ../$@)
75yx86-cof.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
76 (cd asm; $(PERL) crypt586.pl coff $(CFLAGS) > ../$@)
77# a.out
78dx86-out.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
79 (cd asm; $(PERL) des-586.pl a.out $(CFLAGS) > ../$@)
80yx86-out.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
81 (cd asm; $(PERL) crypt586.pl a.out $(CFLAGS) > ../$@)
82
83files:
84 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
85
86links:
87 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
88 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
89 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
90
91# We need to use force because 'install' matches 'INSTALL' on case
92# insensitive systems
93FRC.install:
94install: FRC.install
95 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
96 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
97 do \
98 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
99 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
100 done;
101
102tags:
103 ctags $(SRC)
104
105tests:
106
107lint:
108 lint -DLINT $(INCLUDES) $(SRC)>fluff
109
110depend:
111 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
112 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
113
114dclean:
115 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
116 mv -f Makefile.new $(MAKEFILE)
117
118clean:
119 rm -f *.s *.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff
120
121# DO NOT DELETE THIS LINE -- make depend depends on it.
122
123cbc_cksm.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
124cbc_cksm.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
125cbc_cksm.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
126cbc_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
127cbc_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
128cbc_cksm.o: cbc_cksm.c des_locl.h
129cbc_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
130cbc_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
131cbc_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
132cbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
133cbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
134cbc_enc.o: cbc_enc.c des_locl.h ncbc_enc.c
135cfb64ede.o: ../../e_os.h ../../include/openssl/des.h
136cfb64ede.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
137cfb64ede.o: ../../include/openssl/opensslconf.h
138cfb64ede.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
139cfb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
140cfb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
141cfb64ede.o: cfb64ede.c des_locl.h
142cfb64enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
143cfb64enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
144cfb64enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
145cfb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
146cfb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
147cfb64enc.o: cfb64enc.c des_locl.h
148cfb_enc.o: ../../e_os.h ../../include/openssl/des.h
149cfb_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
150cfb_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/ossl_typ.h
151cfb_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
152cfb_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
153cfb_enc.o: ../../include/openssl/ui_compat.h cfb_enc.c des_locl.h
154des_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
155des_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
156des_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
157des_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
158des_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
159des_enc.o: des_enc.c des_locl.h ncbc_enc.c
160des_old.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
161des_old.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
162des_old.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
163des_old.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
164des_old.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
165des_old.o: ../../include/openssl/ui_compat.h des_old.c
166des_old2.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
167des_old2.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
168des_old2.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
169des_old2.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
170des_old2.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
171des_old2.o: ../../include/openssl/ui_compat.h des_old2.c
172ecb3_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
173ecb3_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
174ecb3_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
175ecb3_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
176ecb3_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
177ecb3_enc.o: des_locl.h ecb3_enc.c
178ecb_enc.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
179ecb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
180ecb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
181ecb_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
182ecb_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
183ecb_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
184ecb_enc.o: ../../include/openssl/ui_compat.h des_locl.h des_ver.h ecb_enc.c
185ecb_enc.o: spr.h
186ede_cbcm_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
187ede_cbcm_enc.o: ../../include/openssl/e_os2.h
188ede_cbcm_enc.o: ../../include/openssl/opensslconf.h
189ede_cbcm_enc.o: ../../include/openssl/ossl_typ.h
190ede_cbcm_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
191ede_cbcm_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
192ede_cbcm_enc.o: ../../include/openssl/ui_compat.h des_locl.h ede_cbcm_enc.c
193enc_read.o: ../../e_os.h ../../include/openssl/bio.h
194enc_read.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
195enc_read.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
196enc_read.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
197enc_read.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
198enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
199enc_read.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
200enc_read.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
201enc_read.o: ../../include/openssl/ui_compat.h ../cryptlib.h des_locl.h
202enc_read.o: enc_read.c
203enc_writ.o: ../../e_os.h ../../include/openssl/bio.h
204enc_writ.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
205enc_writ.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
206enc_writ.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
207enc_writ.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
208enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
209enc_writ.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
210enc_writ.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
211enc_writ.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
212enc_writ.o: ../cryptlib.h des_locl.h enc_writ.c
213fcrypt.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
214fcrypt.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
215fcrypt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
216fcrypt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
217fcrypt.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
218fcrypt.o: des_locl.h fcrypt.c
219fcrypt_b.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
220fcrypt_b.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
221fcrypt_b.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
222fcrypt_b.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
223fcrypt_b.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
224fcrypt_b.o: des_locl.h fcrypt_b.c
225ofb64ede.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
226ofb64ede.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
227ofb64ede.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
228ofb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
229ofb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
230ofb64ede.o: des_locl.h ofb64ede.c
231ofb64enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
232ofb64enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
233ofb64enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
234ofb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
235ofb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
236ofb64enc.o: des_locl.h ofb64enc.c
237ofb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
238ofb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
239ofb_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
240ofb_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
241ofb_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
242ofb_enc.o: des_locl.h ofb_enc.c
243pcbc_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
244pcbc_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
245pcbc_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
246pcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
247pcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
248pcbc_enc.o: des_locl.h pcbc_enc.c
249qud_cksm.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
250qud_cksm.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
251qud_cksm.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
252qud_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
253qud_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
254qud_cksm.o: des_locl.h qud_cksm.c
255rand_key.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
256rand_key.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
257rand_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
258rand_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
259rand_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
260rand_key.o: ../../include/openssl/ui_compat.h rand_key.c
261read2pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
262read2pwd.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
263read2pwd.o: ../../include/openssl/opensslconf.h
264read2pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
265read2pwd.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
266read2pwd.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
267read2pwd.o: ../../include/openssl/ui_compat.h read2pwd.c
268rpc_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
269rpc_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
270rpc_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
271rpc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
272rpc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
273rpc_enc.o: des_locl.h des_ver.h rpc_des.h rpc_enc.c
274set_key.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
275set_key.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
276set_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
277set_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
278set_key.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
279set_key.o: des_locl.h set_key.c
280str2key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
281str2key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
282str2key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
283str2key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
284str2key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
285str2key.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
286str2key.o: des_locl.h str2key.c
287xcbc_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
288xcbc_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
289xcbc_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
290xcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
291xcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
292xcbc_enc.o: des_locl.h xcbc_enc.c
diff --git a/src/lib/libcrypto/des/README b/src/lib/libcrypto/des/README
new file mode 100644
index 0000000000..621a5ab467
--- /dev/null
+++ b/src/lib/libcrypto/des/README
@@ -0,0 +1,54 @@
1
2 libdes, Version 4.01 10-Jan-97
3
4 Copyright (c) 1997, Eric Young
5 All rights reserved.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms specified in COPYRIGHT.
9
10--
11The primary ftp site for this library is
12ftp://ftp.psy.uq.oz.au/pub/Crypto/DES/libdes-x.xx.tar.gz
13libdes is now also shipped with SSLeay. Primary ftp site of
14ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL/SSLeay-x.x.x.tar.gz
15
16The best way to build this library is to build it as part of SSLeay.
17
18This kit builds a DES encryption library and a DES encryption program.
19It supports ecb, cbc, ofb, cfb, triple ecb, triple cbc, triple ofb,
20triple cfb, desx, and MIT's pcbc encryption modes and also has a fast
21implementation of crypt(3).
22It contains support routines to read keys from a terminal,
23generate a random key, generate a key from an arbitrary length string,
24read/write encrypted data from/to a file descriptor.
25
26The implementation was written so as to conform with the manual entry
27for the des_crypt(3) library routines from MIT's project Athena.
28
29destest should be run after compilation to test the des routines.
30rpw should be run after compilation to test the read password routines.
31The des program is a replacement for the sun des command. I believe it
32conforms to the sun version.
33
34The Imakefile is setup for use in the kerberos distribution.
35
36These routines are best compiled with gcc or any other good
37optimising compiler.
38Just turn you optimiser up to the highest settings and run destest
39after the build to make sure everything works.
40
41I believe these routines are close to the fastest and most portable DES
42routines that use small lookup tables (4.5k) that are publicly available.
43The fcrypt routine is faster than ufc's fcrypt (when compiling with
44gcc2 -O2) on the sparc 2 (1410 vs 1270) but is not so good on other machines
45(on a sun3/260 168 vs 336). It is a function of CPU on chip cache size.
46[ 10-Jan-97 and a function of an incorrect speed testing program in
47 ufc which gave much better test figures that reality ].
48
49It is worth noting that on sparc and Alpha CPUs, performance of the DES
50library can vary by upto %10 due to the positioning of files after application
51linkage.
52
53Eric Young (eay@cryptsoft.com)
54
diff --git a/src/lib/libcrypto/des/VERSION b/src/lib/libcrypto/des/VERSION
new file mode 100644
index 0000000000..c7d01542bc
--- /dev/null
+++ b/src/lib/libcrypto/des/VERSION
@@ -0,0 +1,412 @@
1 Fixed the weak key values which were wrong :-(
2 Defining SIGACTION causes sigaction() to be used instead of signal().
3 SIGUSR1/SIGUSR2 are no longer mapped in the read tty stuff because it
4 can cause problems. This should hopefully not affect normal
5 applications.
6
7Version 4.04
8 Fixed a few tests in destest. Also added x86 assember for
9 des_ncbc_encrypt() which is the standard cbc mode function.
10 This makes a very very large performace difference.
11 Ariel Glenn ariel@columbia.edu reports that the terminal
12 'turn echo off' can return (errno == EINVAL) under solaris
13 when redirection is used. So I now catch that as well as ENOTTY.
14
15
16Version 4.03
17 Left a static out of enc_write.c, which caused to buffer to be
18 continiously malloc()ed. Does anyone use these functions? I keep
19 on feeling like removing them since I only had these in there
20 for a version of kerberised login. Anyway, this was pointed out
21 by Theo de Raadt <deraadt@cvs.openbsd.org>
22 The 'n' bit ofb code was wrong, it was not shifting the shift
23 register. It worked correctly for n == 64. Thanks to
24 Gigi Ankeny <Gigi.Ankeny@Eng.Sun.COM> for pointing this one out.
25
26Version 4.02
27 I was doing 'if (memcmp(weak_keys[i],key,sizeof(key)) == 0)'
28 when checking for weak keys which is wrong :-(, pointed out by
29 Markus F.X.J. Oberhumer <markus.oberhumer@jk.uni-linz.ac.at>.
30
31Version 4.01
32 Even faster inner loop in the DES assembler for x86 and a modification
33 for IP/FP which is faster on x86. Both of these changes are
34 from Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>. His
35 changes make the assembler run %40 faster on a pentium. This is just
36 a case of getting the instruction sequence 'just right'.
37 All credit to 'Svend' :-)
38 Quite a few special x86 'make' targets.
39 A libdes-l (lite) distribution.
40
41Version 4.00
42 After a bit of a pause, I'll up the major version number since this
43 is mostly a performace release. I've added x86 assembler and
44 added more options for performance. A %28 speedup for gcc
45 on a pentium and the assembler is a %50 speedup.
46 MIPS CPU's, sparc and Alpha are the main CPU's with speedups.
47 Run des_opts to work out which options should be used.
48 DES_RISC1/DES_RISC2 use alternative inner loops which use
49 more registers but should give speedups on any CPU that does
50 dual issue (pentium). DES_UNROLL unrolls the inner loop,
51 which costs in code size.
52
53Version 3.26
54 I've finally removed one of the shifts in D_ENCRYPT. This
55 meant I've changed the des_SPtrans table (spr.h), the set_key()
56 function and some things in des_enc.c. This has definitly
57 made things faster :-). I've known about this one for some
58 time but I've been too lazy to follow it up :-).
59 Noticed that in the D_ENCRYPT() macro, we can just do L^=(..)^(..)^..
60 instead of L^=((..)|(..)|(..).. This should save a register at
61 least.
62 Assember for x86. The file to replace is des_enc.c, which is replaced
63 by one of the assembler files found in asm. Look at des/asm/readme
64 for more info.
65
66 /* Modification to fcrypt so it can be compiled to support
67 HPUX 10.x's long password format, define -DLONGCRYPT to use this.
68 Thanks to Jens Kupferschmidt <bt1cu@hpboot.rz.uni-leipzig.de>. */
69
70 SIGWINCH case put in des_read_passwd() so the function does not
71 'exit' if this function is recieved.
72
73Version 3.25 17/07/96
74 Modified read_pwd.c so that stdin can be read if not a tty.
75 Thanks to Jeff Barber <jeffb@issl.atl.hp.com> for the patches.
76 des_init_random_number_generator() shortened due to VMS linker
77 limits.
78 Added RSA's DESX cbc mode. It is a form of cbc encryption, with 2
79 8 byte quantites xored before and after encryption.
80 des_xcbc_encryption() - the name is funny to preserve the des_
81 prefix on all functions.
82
83Version 3.24 20/04/96
84 The DES_PTR macro option checked and used by SSLeay configuration
85
86Version 3.23 11/04/96
87 Added DES_LONG. If defined to 'unsigned int' on the DEC Alpha,
88 it gives a %20 speedup :-)
89 Fixed the problem with des.pl under perl5. The patches were
90 sent by Ed Kubaitis (ejk@uiuc.edu).
91 if fcrypt.c, changed values to handle illegal salt values the way
92 normal crypt() implementations do. Some programs apparently use
93 them :-(. The patch was sent by Bjorn Gronvall <bg@sics.se>
94
95Version 3.22 29/11/95
96 Bug in des(1), an error with the uuencoding stuff when the
97 'data' is small, thanks to Geoff Keating <keagchon@mehta.anu.edu.au>
98 for the patch.
99
100Version 3.21 22/11/95
101 After some emailing back and forth with
102 Colin Plumb <colin@nyx10.cs.du.edu>, I've tweaked a few things
103 and in a future version I will probably put in some of the
104 optimisation he suggested for use with the DES_USE_PTR option.
105 Extra routines from Mark Murray <mark@grondar.za> for use in
106 freeBSD. They mostly involve random number generation for use
107 with kerberos. They involve evil machine specific system calls
108 etc so I would normally suggest pushing this stuff into the
109 application and/or using RAND_seed()/RAND_bytes() if you are
110 using this DES library as part of SSLeay.
111 Redone the read_pw() function so that it is cleaner and
112 supports termios, thanks to Sameer Parekh <sameer@c2.org>
113 for the initial patches for this.
114 Renamed 3ecb_encrypt() to ecb3_encrypt(). This has been
115 done just to make things more consistent.
116 I have also now added triple DES versions of cfb and ofb.
117
118Version 3.20
119 Damn, Damn, Damn, as pointed out by Mike_Spreitzer.PARC@xerox.com,
120 my des_random_seed() function was only copying 4 bytes of the
121 passed seed into the init structure. It is now fixed to copy 8.
122 My own suggestion is to used something like MD5 :-)
123
124Version 3.19
125 While looking at my code one day, I though, why do I keep on
126 calling des_encrypt(in,out,ks,enc) when every function that
127 calls it has in and out the same. So I dropped the 'out'
128 parameter, people should not be using this function.
129
130Version 3.18 30/08/95
131 Fixed a few bit with the distribution and the filenames.
132 3.17 had been munged via a move to DOS and back again.
133 NO CODE CHANGES
134
135Version 3.17 14/07/95
136 Fixed ede3 cbc which I had broken in 3.16. I have also
137 removed some unneeded variables in 7-8 of the routines.
138
139Version 3.16 26/06/95
140 Added des_encrypt2() which does not use IP/FP, used by triple
141 des routines. Tweaked things a bit elsewhere. %13 speedup on
142 sparc and %6 on a R4400 for ede3 cbc mode.
143
144Version 3.15 06/06/95
145 Added des_ncbc_encrypt(), it is des_cbc mode except that it is
146 'normal' and copies the new iv value back over the top of the
147 passed parameter.
148 CHANGED des_ede3_cbc_encrypt() so that it too now overwrites
149 the iv. THIS WILL BREAK EXISTING CODE, but since this function
150 only new, I feel I can change it, not so with des_cbc_encrypt :-(.
151 I need to update the documentation.
152
153Version 3.14 31/05/95
154 New release upon the world, as part of my SSL implementation.
155 New copyright and usage stuff. Basically free for all to use
156 as long as you say it came from me :-)
157
158Version 3.13 31/05/95
159 A fix in speed.c, if HZ is not defined, I set it to 100.0
160 which is reasonable for most unixes except SunOS 4.x.
161 I now have a #ifdef sun but timing for SunOS 4.x looked very
162 good :-(. At my last job where I used SunOS 4.x, it was
163 defined to be 60.0 (look at the old INSTALL documentation), at
164 the last release had it changed to 100.0 since I now work with
165 Solaris2 and SVR4 boxes.
166 Thanks to Rory Chisholm <rchishol@math.ethz.ch> for pointing this
167 one out.
168
169Version 3.12 08/05/95
170 As pointed out by The Crypt Keeper <tck@bend.UCSD.EDU>,
171 my D_ENCRYPT macro in crypt() had an un-necessary variable.
172 It has been removed.
173
174Version 3.11 03/05/95
175 Added des_ede3_cbc_encrypt() which is cbc mode des with 3 keys
176 and one iv. It is a standard and I needed it for my SSL code.
177 It makes more sense to use this for triple DES than
178 3cbc_encrypt(). I have also added (or should I say tested :-)
179 cfb64_encrypt() which is cfb64 but it will encrypt a partial
180 number of bytes - 3 bytes in 3 bytes out. Again this is for
181 my SSL library, as a form of encryption to use with SSL
182 telnet.
183
184Version 3.10 22/03/95
185 Fixed a bug in 3cbc_encrypt() :-(. When making repeated calls
186 to cbc3_encrypt, the 2 iv values that were being returned to
187 be used in the next call were reversed :-(.
188 Many thanks to Bill Wade <wade@Stoner.COM> for pointing out
189 this error.
190
191Version 3.09 01/02/95
192 Fixed des_random_key to far more random, it was rather feeble
193 with regards to picking the initial seed. The problem was
194 pointed out by Olaf Kirch <okir@monad.swb.de>.
195
196Version 3.08 14/12/94
197 Added Makefile.PL so libdes can be built into perl5.
198 Changed des_locl.h so RAND is always defined.
199
200Version 3.07 05/12/94
201 Added GNUmake and stuff so the library can be build with
202 glibc.
203
204Version 3.06 30/08/94
205 Added rpc_enc.c which contains _des_crypt. This is for use in
206 secure_rpc v 4.0
207 Finally fixed the cfb_enc problems.
208 Fixed a few parameter parsing bugs in des (-3 and -b), thanks
209 to Rob McMillan <R.McMillan@its.gu.edu.au>
210
211Version 3.05 21/04/94
212 for unsigned long l; gcc does not produce ((l>>34) == 0)
213 This causes bugs in cfb_enc.
214 Thanks to Hadmut Danisch <danisch@ira.uka.de>
215
216Version 3.04 20/04/94
217 Added a version number to des.c and libdes.a
218
219Version 3.03 12/01/94
220 Fixed a bug in non zero iv in 3cbc_enc.
221
222Version 3.02 29/10/93
223 I now work in a place where there are 6+ architectures and 14+
224 OS versions :-).
225 Fixed TERMIO definition so the most sys V boxes will work :-)
226
227Release upon comp.sources.misc
228Version 3.01 08/10/93
229 Added des_3cbc_encrypt()
230
231Version 3.00 07/10/93
232 Fixed up documentation.
233 quad_cksum definitely compatible with MIT's now.
234
235Version 2.30 24/08/93
236 Triple DES now defaults to triple cbc but can do triple ecb
237 with the -b flag.
238 Fixed some MSDOS uuen/uudecoding problems, thanks to
239 Added prototypes.
240
241Version 2.22 29/06/93
242 Fixed a bug in des_is_weak_key() which stopped it working :-(
243 thanks to engineering@MorningStar.Com.
244
245Version 2.21 03/06/93
246 des(1) with no arguments gives quite a bit of help.
247 Added -c (generate ckecksum) flag to des(1).
248 Added -3 (triple DES) flag to des(1).
249 Added cfb and ofb routines to the library.
250
251Version 2.20 11/03/93
252 Added -u (uuencode) flag to des(1).
253 I have been playing with byte order in quad_cksum to make it
254 compatible with MIT's version. All I can say is avid this
255 function if possible since MIT's output is endian dependent.
256
257Version 2.12 14/10/92
258 Added MSDOS specific macro in ecb_encrypt which gives a %70
259 speed up when the code is compiled with turbo C.
260
261Version 2.11 12/10/92
262 Speedup in set_key (recoding of PC-1)
263 I now do it in 47 simple operations, down from 60.
264 Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
265 for motivating me to look for a faster system :-)
266 The speedup is probably less that 1% but it is still 13
267 instructions less :-).
268
269Version 2.10 06/10/92
270 The code now works on the 64bit ETA10 and CRAY without modifications or
271 #defines. I believe the code should work on any machine that
272 defines long, int or short to be 8 bytes long.
273 Thanks to Shabbir J. Safdar (shabby@mentor.cc.purdue.edu)
274 for helping me fix the code to run on 64bit machines (he had
275 access to an ETA10).
276 Thanks also to John Fletcher <john_fletcher@lccmail.ocf.llnl.gov>
277 for testing the routines on a CRAY.
278 read_password.c has been renamed to read_passwd.c
279 string_to_key.c has been renamed to string2key.c
280
281Version 2.00 14/09/92
282 Made mods so that the library should work on 64bit CPU's.
283 Removed all my uchar and ulong defs. To many different
284 versions of unix define them in their header files in too many
285 different combinations :-)
286 IRIX - Sillicon Graphics mods (mostly in read_password.c).
287 Thanks to Andrew Daviel (advax@erich.triumf.ca)
288
289Version 1.99 26/08/92
290 Fixed a bug or 2 in enc_read.c
291 Fixed a bug in enc_write.c
292 Fixed a pseudo bug in fcrypt.c (very obscure).
293
294Version 1.98 31/07/92
295 Support for the ETA10. This is a strange machine that defines
296 longs and ints as 8 bytes and shorts as 4 bytes.
297 Since I do evil things with long * that assume that they are 4
298 bytes. Look in the Makefile for the option to compile for
299 this machine. quad_cksum appears to have problems but I
300 will don't have the time to fix it right now, and this is not
301 a function that uses DES and so will not effect the main uses
302 of the library.
303
304Version 1.97 20/05/92 eay
305 Fixed the Imakefile and made some changes to des.h to fix some
306 problems when building this package with Kerberos v 4.
307
308Version 1.96 18/05/92 eay
309 Fixed a small bug in string_to_key() where problems could
310 occur if des_check_key was set to true and the string
311 generated a weak key.
312
313Patch2 posted to comp.sources.misc
314Version 1.95 13/05/92 eay
315 Added an alternative version of the D_ENCRYPT macro in
316 ecb_encrypt and fcrypt. Depending on the compiler, one version or the
317 other will be faster. This was inspired by
318 Dana How <how@isl.stanford.edu>, and her pointers about doing the
319 *(ulong *)((uchar *)ptr+(value&0xfc))
320 vs
321 ptr[value&0x3f]
322 to stop the C compiler doing a <<2 to convert the long array index.
323
324Version 1.94 05/05/92 eay
325 Fixed an incompatibility between my string_to_key and the MIT
326 version. When the key is longer than 8 chars, I was wrapping
327 with a different method. To use the old version, define
328 OLD_STR_TO_KEY in the makefile. Thanks to
329 viktor@newsu.shearson.com (Viktor Dukhovni).
330
331Version 1.93 28/04/92 eay
332 Fixed the VMS mods so that echo is now turned off in
333 read_password. Thanks again to brennan@coco.cchs.su.oz.AU.
334 MSDOS support added. The routines can be compiled with
335 Turbo C (v2.0) and MSC (v5.1). Make sure MSDOS is defined.
336
337Patch1 posted to comp.sources.misc
338Version 1.92 13/04/92 eay
339 Changed D_ENCRYPT so that the rotation of R occurs outside of
340 the loop. This required rotating all the longs in sp.h (now
341 called spr.h). Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
342 speed.c has been changed so it will work without SIGALRM. If
343 times(3) is not present it will try to use ftime() instead.
344
345Version 1.91 08/04/92 eay
346 Added -E/-D options to des(1) so it can use string_to_key.
347 Added SVR4 mods suggested by witr@rwwa.COM
348 Added VMS mods suggested by brennan@coco.cchs.su.oz.AU. If
349 anyone knows how to turn of tty echo in VMS please tell me or
350 implement it yourself :-).
351 Changed FILE *IN/*OUT to *DES_IN/*DES_OUT since it appears VMS
352 does not like IN/OUT being used.
353
354Libdes posted to comp.sources.misc
355Version 1.9 24/03/92 eay
356 Now contains a fast small crypt replacement.
357 Added des(1) command.
358 Added des_rw_mode so people can use cbc encryption with
359 enc_read and enc_write.
360
361Version 1.8 15/10/91 eay
362 Bug in cbc_cksum.
363 Many thanks to Keith Reynolds (keithr@sco.COM) for pointing this
364 one out.
365
366Version 1.7 24/09/91 eay
367 Fixed set_key :-)
368 set_key is 4 times faster and takes less space.
369 There are a few minor changes that could be made.
370
371Version 1.6 19/09/1991 eay
372 Finally go IP and FP finished.
373 Now I need to fix set_key.
374 This version is quite a bit faster that 1.51
375
376Version 1.52 15/06/1991 eay
377 20% speedup in ecb_encrypt by changing the E bit selection
378 to use 2 32bit words. This also required modification of the
379 sp table. There is still a way to speedup the IP and IP-1
380 (hints from outer@sq.com) still working on this one :-(.
381
382Version 1.51 07/06/1991 eay
383 Faster des_encrypt by loop unrolling
384 Fixed bug in quad_cksum.c (thanks to hughes@logos.ucs.indiana.edu)
385
386Version 1.50 28/05/1991 eay
387 Optimised the code a bit more for the sparc. I have improved the
388 speed of the inner des_encrypt by speeding up the initial and
389 final permutations.
390
391Version 1.40 23/10/1990 eay
392 Fixed des_random_key, it did not produce a random key :-(
393
394Version 1.30 2/10/1990 eay
395 Have made des_quad_cksum the same as MIT's, the full package
396 should be compatible with MIT's
397 Have tested on a DECstation 3100
398 Still need to fix des_set_key (make it faster).
399 Does des_cbc_encrypts at 70.5k/sec on a 3100.
400
401Version 1.20 18/09/1990 eay
402 Fixed byte order dependencies.
403 Fixed (I hope) all the word alignment problems.
404 Speedup in des_ecb_encrypt.
405
406Version 1.10 11/09/1990 eay
407 Added des_enc_read and des_enc_write.
408 Still need to fix des_quad_cksum.
409 Still need to document des_enc_read and des_enc_write.
410
411Version 1.00 27/08/1990 eay
412
diff --git a/src/lib/libcrypto/des/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl
new file mode 100644
index 0000000000..1d04ed6def
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/crypt586.pl
@@ -0,0 +1,208 @@
1#!/usr/local/bin/perl
2#
3# The inner loop instruction sequence and the IP/FP modifications are from
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
5# I've added the stuff needed for crypt() but I've not worried about making
6# things perfect.
7#
8
9push(@INC,"perlasm","../../perlasm");
10require "x86asm.pl";
11
12&asm_init($ARGV[0],"crypt586.pl");
13
14$L="edi";
15$R="esi";
16
17&external_label("DES_SPtrans");
18&fcrypt_body("fcrypt_body");
19&asm_finish();
20
21sub fcrypt_body
22 {
23 local($name,$do_ip)=@_;
24
25 &function_begin($name,"EXTRN _DES_SPtrans:DWORD");
26
27 &comment("");
28 &comment("Load the 2 words");
29 $trans="ebp";
30
31 &xor( $L, $L);
32 &xor( $R, $R);
33
34 # PIC-ification:-)
35 &picmeup("edx","DES_SPtrans");
36 #if ($cpp) { &picmeup("edx","DES_SPtrans"); }
37 #else { &lea("edx",&DWP("DES_SPtrans")); }
38 &push("edx"); # becomes &swtmp(1)
39 #
40 &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT
41
42 &push(&DWC(25)); # add a variable
43
44 &set_label("start");
45 for ($i=0; $i<16; $i+=2)
46 {
47 &comment("");
48 &comment("Round $i");
49 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
50
51 &comment("");
52 &comment("Round ".sprintf("%d",$i+1));
53 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
54 }
55 &mov("ebx", &swtmp(0));
56 &mov("eax", $L);
57 &dec("ebx");
58 &mov($L, $R);
59 &mov($R, "eax");
60 &mov(&swtmp(0), "ebx");
61 &jnz(&label("start"));
62
63 &comment("");
64 &comment("FP");
65 &mov("edx",&wparam(0));
66
67 &FP_new($R,$L,"eax",3);
68 &mov(&DWP(0,"edx","",0),"eax");
69 &mov(&DWP(4,"edx","",0),$L);
70
71 &add("esp",8); # remove variables
72
73 &function_end($name);
74 }
75
76sub D_ENCRYPT
77 {
78 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
79
80 &mov( $u, &wparam(2)); # 2
81 &mov( $t, $R);
82 &shr( $t, 16); # 1
83 &mov( $tmp2, &wparam(3)); # 2
84 &xor( $t, $R); # 1
85
86 &and( $u, $t); # 2
87 &and( $t, $tmp2); # 2
88
89 &mov( $tmp1, $u);
90 &shl( $tmp1, 16); # 1
91 &mov( $tmp2, $t);
92 &shl( $tmp2, 16); # 1
93 &xor( $u, $tmp1); # 2
94 &xor( $t, $tmp2); # 2
95 &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2
96 &xor( $u, $tmp1);
97 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2
98 &xor( $u, $R);
99 &xor( $t, $R);
100 &xor( $t, $tmp2);
101
102 &and( $u, "0xfcfcfcfc" ); # 2
103 &xor( $tmp1, $tmp1); # 1
104 &and( $t, "0xcfcfcfcf" ); # 2
105 &xor( $tmp2, $tmp2);
106 &movb( &LB($tmp1), &LB($u) );
107 &movb( &LB($tmp2), &HB($u) );
108 &rotr( $t, 4 );
109 &mov( $trans, &swtmp(1));
110 &xor( $L, &DWP(" ",$trans,$tmp1,0));
111 &movb( &LB($tmp1), &LB($t) );
112 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
113 &movb( &LB($tmp2), &HB($t) );
114 &shr( $u, 16);
115 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
116 &movb( &LB($tmp1), &HB($u) );
117 &shr( $t, 16);
118 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
119 &movb( &LB($tmp2), &HB($t) );
120 &and( $u, "0xff" );
121 &and( $t, "0xff" );
122 &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0));
123 &xor( $L, $tmp1);
124 &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0));
125 &xor( $L, $tmp1);
126 &mov( $tmp1, &DWP("0x400",$trans,$u,0));
127 &xor( $L, $tmp1);
128 &mov( $tmp1, &DWP("0x500",$trans,$t,0));
129 &xor( $L, $tmp1);
130 &mov( $trans, &wparam(1));
131 }
132
133sub n2a
134 {
135 sprintf("%d",$_[0]);
136 }
137
138# now has a side affect of rotating $a by $shift
139sub R_PERM_OP
140 {
141 local($a,$b,$tt,$shift,$mask,$last)=@_;
142
143 &rotl( $a, $shift ) if ($shift != 0);
144 &mov( $tt, $a );
145 &xor( $a, $b );
146 &and( $a, $mask );
147 if ($notlast eq $b)
148 {
149 &xor( $b, $a );
150 &xor( $tt, $a );
151 }
152 else
153 {
154 &xor( $tt, $a );
155 &xor( $b, $a );
156 }
157 &comment("");
158 }
159
160sub IP_new
161 {
162 local($l,$r,$tt,$lr)=@_;
163
164 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
165 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
166 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
167 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
168 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
169
170 if ($lr != 3)
171 {
172 if (($lr-3) < 0)
173 { &rotr($tt, 3-$lr); }
174 else { &rotl($tt, $lr-3); }
175 }
176 if ($lr != 2)
177 {
178 if (($lr-2) < 0)
179 { &rotr($r, 2-$lr); }
180 else { &rotl($r, $lr-2); }
181 }
182 }
183
184sub FP_new
185 {
186 local($l,$r,$tt,$lr)=@_;
187
188 if ($lr != 2)
189 {
190 if (($lr-2) < 0)
191 { &rotl($r, 2-$lr); }
192 else { &rotr($r, $lr-2); }
193 }
194 if ($lr != 3)
195 {
196 if (($lr-3) < 0)
197 { &rotl($l, 3-$lr); }
198 else { &rotr($l, $lr-3); }
199 }
200
201 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
202 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
203 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
204 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
205 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
206 &rotr($tt , 4);
207 }
208
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl
new file mode 100644
index 0000000000..60d577cc8d
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/des-586.pl
@@ -0,0 +1,255 @@
1#!/usr/local/bin/perl
2#
3# The inner loop instruction sequence and the IP/FP modifications are from
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
5#
6
7push(@INC,"perlasm","../../perlasm");
8require "x86asm.pl";
9require "cbc.pl";
10require "desboth.pl";
11
12# base code is in microsft
13# op dest, source
14# format.
15#
16
17&asm_init($ARGV[0],"des-586.pl");
18
19$L="edi";
20$R="esi";
21
22&external_label("DES_SPtrans");
23&DES_encrypt("DES_encrypt1",1);
24&DES_encrypt("DES_encrypt2",0);
25
26if (!$main'openbsd)
27 {
28 &DES_encrypt3("DES_encrypt3",1);
29 &DES_encrypt3("DES_decrypt3",0);
30 &cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
31 &cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
32 }
33
34&asm_finish();
35
36sub DES_encrypt
37 {
38 local($name,$do_ip)=@_;
39
40 &function_begin_B($name,"EXTRN _DES_SPtrans:DWORD");
41
42 &push("esi");
43 &push("edi");
44
45 &comment("");
46 &comment("Load the 2 words");
47 $trans="ebp";
48
49 if ($do_ip)
50 {
51 &mov($R,&wparam(0));
52 &xor( "ecx", "ecx" );
53
54 &push("ebx");
55 &push("ebp");
56
57 &mov("eax",&DWP(0,$R,"",0));
58 &mov("ebx",&wparam(2)); # get encrypt flag
59 &mov($L,&DWP(4,$R,"",0));
60 &comment("");
61 &comment("IP");
62 &IP_new("eax",$L,$R,3);
63 }
64 else
65 {
66 &mov("eax",&wparam(0));
67 &xor( "ecx", "ecx" );
68
69 &push("ebx");
70 &push("ebp");
71
72 &mov($R,&DWP(0,"eax","",0));
73 &mov("ebx",&wparam(2)); # get encrypt flag
74 &rotl($R,3);
75 &mov($L,&DWP(4,"eax","",0));
76 &rotl($L,3);
77 }
78
79 # PIC-ification:-)
80 &picmeup($trans,"DES_SPtrans");
81 #if ($cpp) { &picmeup($trans,"DES_SPtrans"); }
82 #else { &lea($trans,&DWP("DES_SPtrans")); }
83
84 &mov( "ecx", &wparam(1) );
85 &cmp("ebx","0");
86 &je(&label("start_decrypt"));
87
88 for ($i=0; $i<16; $i+=2)
89 {
90 &comment("");
91 &comment("Round $i");
92 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
93
94 &comment("");
95 &comment("Round ".sprintf("%d",$i+1));
96 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
97 }
98 &jmp(&label("end"));
99
100 &set_label("start_decrypt");
101
102 for ($i=15; $i>0; $i-=2)
103 {
104 &comment("");
105 &comment("Round $i");
106 &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
107 &comment("");
108 &comment("Round ".sprintf("%d",$i-1));
109 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx");
110 }
111
112 &set_label("end");
113
114 if ($do_ip)
115 {
116 &comment("");
117 &comment("FP");
118 &mov("edx",&wparam(0));
119 &FP_new($L,$R,"eax",3);
120
121 &mov(&DWP(0,"edx","",0),"eax");
122 &mov(&DWP(4,"edx","",0),$R);
123 }
124 else
125 {
126 &comment("");
127 &comment("Fixup");
128 &rotr($L,3); # r
129 &mov("eax",&wparam(0));
130 &rotr($R,3); # l
131 &mov(&DWP(0,"eax","",0),$L);
132 &mov(&DWP(4,"eax","",0),$R);
133 }
134
135 &pop("ebp");
136 &pop("ebx");
137 &pop("edi");
138 &pop("esi");
139 &ret();
140
141 &function_end_B($name);
142 }
143
144sub D_ENCRYPT
145 {
146 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
147
148 &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0));
149 &xor( $tmp1, $tmp1);
150 &mov( $t, &DWP(&n2a(($S+1)*4),$tmp2,"",0));
151 &xor( $u, $R);
152 &xor( $tmp2, $tmp2);
153 &xor( $t, $R);
154 &and( $u, "0xfcfcfcfc" );
155 &and( $t, "0xcfcfcfcf" );
156 &movb( &LB($tmp1), &LB($u) );
157 &movb( &LB($tmp2), &HB($u) );
158 &rotr( $t, 4 );
159 &xor( $L, &DWP(" ",$trans,$tmp1,0));
160 &movb( &LB($tmp1), &LB($t) );
161 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
162 &movb( &LB($tmp2), &HB($t) );
163 &shr( $u, 16);
164 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
165 &movb( &LB($tmp1), &HB($u) );
166 &shr( $t, 16);
167 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
168 &movb( &LB($tmp2), &HB($t) );
169 &and( $u, "0xff" );
170 &and( $t, "0xff" );
171 &xor( $L, &DWP("0x600",$trans,$tmp1,0));
172 &xor( $L, &DWP("0x700",$trans,$tmp2,0));
173 &mov( $tmp2, &wparam(1) );
174 &xor( $L, &DWP("0x400",$trans,$u,0));
175 &xor( $L, &DWP("0x500",$trans,$t,0));
176 }
177
178sub n2a
179 {
180 sprintf("%d",$_[0]);
181 }
182
183# now has a side affect of rotating $a by $shift
184sub R_PERM_OP
185 {
186 local($a,$b,$tt,$shift,$mask,$last)=@_;
187
188 &rotl( $a, $shift ) if ($shift != 0);
189 &mov( $tt, $a );
190 &xor( $a, $b );
191 &and( $a, $mask );
192 # This can never succeed, and besides it is difficult to see what the
193 # idea was - Ben 13 Feb 99
194 if (!$last eq $b)
195 {
196 &xor( $b, $a );
197 &xor( $tt, $a );
198 }
199 else
200 {
201 &xor( $tt, $a );
202 &xor( $b, $a );
203 }
204 &comment("");
205 }
206
207sub IP_new
208 {
209 local($l,$r,$tt,$lr)=@_;
210
211 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
212 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
213 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
214 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
215 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
216
217 if ($lr != 3)
218 {
219 if (($lr-3) < 0)
220 { &rotr($tt, 3-$lr); }
221 else { &rotl($tt, $lr-3); }
222 }
223 if ($lr != 2)
224 {
225 if (($lr-2) < 0)
226 { &rotr($r, 2-$lr); }
227 else { &rotl($r, $lr-2); }
228 }
229 }
230
231sub FP_new
232 {
233 local($l,$r,$tt,$lr)=@_;
234
235 if ($lr != 2)
236 {
237 if (($lr-2) < 0)
238 { &rotl($r, 2-$lr); }
239 else { &rotr($r, $lr-2); }
240 }
241 if ($lr != 3)
242 {
243 if (($lr-3) < 0)
244 { &rotl($l, 3-$lr); }
245 else { &rotr($l, $lr-3); }
246 }
247
248 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
249 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
250 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
251 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
252 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
253 &rotr($tt , 4);
254 }
255
diff --git a/src/lib/libcrypto/des/asm/des686.pl b/src/lib/libcrypto/des/asm/des686.pl
new file mode 100644
index 0000000000..d3ad5d5edd
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/des686.pl
@@ -0,0 +1,230 @@
1#!/usr/local/bin/perl
2
3$prog="des686.pl";
4
5# base code is in microsft
6# op dest, source
7# format.
8#
9
10# WILL NOT WORK ANYMORE WITH desboth.pl
11require "desboth.pl";
12
13if ( ($ARGV[0] eq "elf"))
14 { require "x86unix.pl"; }
15elsif ( ($ARGV[0] eq "a.out"))
16 { $aout=1; require "x86unix.pl"; }
17elsif ( ($ARGV[0] eq "sol"))
18 { $sol=1; require "x86unix.pl"; }
19elsif ( ($ARGV[0] eq "cpp"))
20 { $cpp=1; require "x86unix.pl"; }
21elsif ( ($ARGV[0] eq "win32"))
22 { require "x86ms.pl"; }
23else
24 {
25 print STDERR <<"EOF";
26Pick one target type from
27 elf - linux, FreeBSD etc
28 a.out - old linux
29 sol - x86 solaris
30 cpp - format so x86unix.cpp can be used
31 win32 - Windows 95/Windows NT
32EOF
33 exit(1);
34 }
35
36&comment("Don't even think of reading this code");
37&comment("It was automatically generated by $prog");
38&comment("Which is a perl program used to generate the x86 assember for");
39&comment("any of elf, a.out, Win32, or Solaris");
40&comment("It can be found in SSLeay 0.6.5+ or in libdes 3.26+");
41&comment("eric <eay\@cryptsoft.com>");
42&comment("");
43
44&file("dx86xxxx");
45
46$L="edi";
47$R="esi";
48
49&DES_encrypt("DES_encrypt1",1);
50&DES_encrypt("DES_encrypt2",0);
51
52&DES_encrypt3("DES_encrypt3",1);
53&DES_encrypt3("DES_decrypt3",0);
54
55&file_end();
56
57sub DES_encrypt
58 {
59 local($name,$do_ip)=@_;
60
61 &function_begin($name,"EXTRN _DES_SPtrans:DWORD");
62
63 &comment("");
64 &comment("Load the 2 words");
65 &mov("eax",&wparam(0));
66 &mov($L,&DWP(0,"eax","",0));
67 &mov($R,&DWP(4,"eax","",0));
68
69 $ksp=&wparam(1);
70
71 if ($do_ip)
72 {
73 &comment("");
74 &comment("IP");
75 &IP_new($L,$R,"eax");
76 }
77
78 &comment("");
79 &comment("fixup rotate");
80 &rotl($R,3);
81 &rotl($L,3);
82 &exch($L,$R);
83
84 &comment("");
85 &comment("load counter, key_schedule and enc flag");
86 &mov("eax",&wparam(2)); # get encrypt flag
87 &mov("ebp",&wparam(1)); # get ks
88 &cmp("eax","0");
89 &je(&label("start_decrypt"));
90
91 # encrypting part
92
93 for ($i=0; $i<16; $i+=2)
94 {
95 &comment("");
96 &comment("Round $i");
97 &D_ENCRYPT($L,$R,$i*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
98
99 &comment("");
100 &comment("Round ".sprintf("%d",$i+1));
101 &D_ENCRYPT($R,$L,($i+1)*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
102 }
103 &jmp(&label("end"));
104
105 &set_label("start_decrypt");
106
107 for ($i=15; $i>0; $i-=2)
108 {
109 &comment("");
110 &comment("Round $i");
111 &D_ENCRYPT($L,$R,$i*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
112 &comment("");
113 &comment("Round ".sprintf("%d",$i-1));
114 &D_ENCRYPT($R,$L,($i-1)*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
115 }
116
117 &set_label("end");
118
119 &comment("");
120 &comment("Fixup");
121 &rotr($L,3); # r
122 &rotr($R,3); # l
123
124 if ($do_ip)
125 {
126 &comment("");
127 &comment("FP");
128 &FP_new($R,$L,"eax");
129 }
130
131 &mov("eax",&wparam(0));
132 &mov(&DWP(0,"eax","",0),$L);
133 &mov(&DWP(4,"eax","",0),$R);
134
135 &function_end($name);
136 }
137
138
139# The logic is to load R into 2 registers and operate on both at the same time.
140# We also load the 2 R's into 2 more registers so we can do the 'move word down a byte'
141# while also masking the other copy and doing a lookup. We then also accumulate the
142# L value in 2 registers then combine them at the end.
143sub D_ENCRYPT
144 {
145 local($L,$R,$S,$ks,$desSP,$u,$t,$tmp1,$tmp2,$tmp3)=@_;
146
147 &mov( $u, &DWP(&n2a($S*4),$ks,"",0));
148 &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0));
149 &xor( $u, $R );
150 &xor( $t, $R );
151 &rotr( $t, 4 );
152
153 # the numbers at the end of the line are origional instruction order
154 &mov( $tmp2, $u ); # 1 2
155 &mov( $tmp1, $t ); # 1 1
156 &and( $tmp2, "0xfc" ); # 1 4
157 &and( $tmp1, "0xfc" ); # 1 3
158 &shr( $t, 8 ); # 1 5
159 &xor( $L, &DWP("0x100+$desSP",$tmp1,"",0)); # 1 7
160 &shr( $u, 8 ); # 1 6
161 &mov( $tmp1, &DWP(" $desSP",$tmp2,"",0)); # 1 8
162
163 &mov( $tmp2, $u ); # 2 2
164 &xor( $L, $tmp1 ); # 1 9
165 &and( $tmp2, "0xfc" ); # 2 4
166 &mov( $tmp1, $t ); # 2 1
167 &and( $tmp1, "0xfc" ); # 2 3
168 &shr( $t, 8 ); # 2 5
169 &xor( $L, &DWP("0x300+$desSP",$tmp1,"",0)); # 2 7
170 &shr( $u, 8 ); # 2 6
171 &mov( $tmp1, &DWP("0x200+$desSP",$tmp2,"",0)); # 2 8
172 &mov( $tmp2, $u ); # 3 2
173
174 &xor( $L, $tmp1 ); # 2 9
175 &and( $tmp2, "0xfc" ); # 3 4
176
177 &mov( $tmp1, $t ); # 3 1
178 &shr( $u, 8 ); # 3 6
179 &and( $tmp1, "0xfc" ); # 3 3
180 &shr( $t, 8 ); # 3 5
181 &xor( $L, &DWP("0x500+$desSP",$tmp1,"",0)); # 3 7
182 &mov( $tmp1, &DWP("0x400+$desSP",$tmp2,"",0)); # 3 8
183
184 &and( $t, "0xfc" ); # 4 1
185 &xor( $L, $tmp1 ); # 3 9
186
187 &and( $u, "0xfc" ); # 4 2
188 &xor( $L, &DWP("0x700+$desSP",$t,"",0)); # 4 3
189 &xor( $L, &DWP("0x600+$desSP",$u,"",0)); # 4 4
190 }
191
192sub PERM_OP
193 {
194 local($a,$b,$tt,$shift,$mask)=@_;
195
196 &mov( $tt, $a );
197 &shr( $tt, $shift );
198 &xor( $tt, $b );
199 &and( $tt, $mask );
200 &xor( $b, $tt );
201 &shl( $tt, $shift );
202 &xor( $a, $tt );
203 }
204
205sub IP_new
206 {
207 local($l,$r,$tt)=@_;
208
209 &PERM_OP($r,$l,$tt, 4,"0x0f0f0f0f");
210 &PERM_OP($l,$r,$tt,16,"0x0000ffff");
211 &PERM_OP($r,$l,$tt, 2,"0x33333333");
212 &PERM_OP($l,$r,$tt, 8,"0x00ff00ff");
213 &PERM_OP($r,$l,$tt, 1,"0x55555555");
214 }
215
216sub FP_new
217 {
218 local($l,$r,$tt)=@_;
219
220 &PERM_OP($l,$r,$tt, 1,"0x55555555");
221 &PERM_OP($r,$l,$tt, 8,"0x00ff00ff");
222 &PERM_OP($l,$r,$tt, 2,"0x33333333");
223 &PERM_OP($r,$l,$tt,16,"0x0000ffff");
224 &PERM_OP($l,$r,$tt, 4,"0x0f0f0f0f");
225 }
226
227sub n2a
228 {
229 sprintf("%d",$_[0]);
230 }
diff --git a/src/lib/libcrypto/des/asm/des_enc.m4 b/src/lib/libcrypto/des/asm/des_enc.m4
new file mode 100644
index 0000000000..f5b1928f99
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/des_enc.m4
@@ -0,0 +1,1980 @@
1! des_enc.m4
2! des_enc.S (generated from des_enc.m4)
3!
4! UltraSPARC assembler version of the LibDES/SSLeay/OpenSSL des_enc.c file.
5!
6! Version 1.0. 32-bit version.
7!
8! June 8, 2000.
9!
10! Version 2.0. 32/64-bit, PIC-ification, blended CPU adaptation
11! by Andy Polyakov.
12!
13! January 1, 2003.
14!
15! Assembler version: Copyright Svend Olaf Mikkelsen.
16!
17! Original C code: Copyright Eric A. Young.
18!
19! This code can be freely used by LibDES/SSLeay/OpenSSL users.
20!
21! The LibDES/SSLeay/OpenSSL copyright notices must be respected.
22!
23! This version can be redistributed.
24!
25! To expand the m4 macros: m4 -B 8192 des_enc.m4 > des_enc.S
26!
27! Global registers 1 to 5 are used. This is the same as done by the
28! cc compiler. The UltraSPARC load/store little endian feature is used.
29!
30! Instruction grouping often refers to one CPU cycle.
31!
32! Assemble through gcc: gcc -c -mcpu=ultrasparc -o des_enc.o des_enc.S
33!
34! Assemble through cc: cc -c -xarch=v8plusa -o des_enc.o des_enc.S
35!
36! Performance improvement according to './apps/openssl speed des'
37!
38! 32-bit build:
39! 23% faster than cc-5.2 -xarch=v8plus -xO5
40! 115% faster than gcc-3.2.1 -m32 -mcpu=ultrasparc -O5
41! 64-bit build:
42! 50% faster than cc-5.2 -xarch=v9 -xO5
43! 100% faster than gcc-3.2.1 -m64 -mcpu=ultrasparc -O5
44!
45
46.ident "des_enc.m4 2.1"
47
48#if defined(__SUNPRO_C) && defined(__sparcv9)
49# define ABI64 /* They've said -xarch=v9 at command line */
50#elif defined(__GNUC__) && defined(__arch64__)
51# define ABI64 /* They've said -m64 at command line */
52#endif
53
54#ifdef ABI64
55 .register %g2,#scratch
56 .register %g3,#scratch
57# define FRAME -192
58# define BIAS 2047
59# define LDPTR ldx
60# define STPTR stx
61# define ARG0 128
62# define ARGSZ 8
63# ifndef OPENSSL_SYSNAME_ULTRASPARC
64# define OPENSSL_SYSNAME_ULTRASPARC
65# endif
66#else
67# define FRAME -96
68# define BIAS 0
69# define LDPTR ld
70# define STPTR st
71# define ARG0 68
72# define ARGSZ 4
73#endif
74
75#define LOOPS 7
76
77#define global0 %g0
78#define global1 %g1
79#define global2 %g2
80#define global3 %g3
81#define global4 %g4
82#define global5 %g5
83
84#define local0 %l0
85#define local1 %l1
86#define local2 %l2
87#define local3 %l3
88#define local4 %l4
89#define local5 %l5
90#define local7 %l6
91#define local6 %l7
92
93#define in0 %i0
94#define in1 %i1
95#define in2 %i2
96#define in3 %i3
97#define in4 %i4
98#define in5 %i5
99#define in6 %i6
100#define in7 %i7
101
102#define out0 %o0
103#define out1 %o1
104#define out2 %o2
105#define out3 %o3
106#define out4 %o4
107#define out5 %o5
108#define out6 %o6
109#define out7 %o7
110
111#define stub stb
112
113changequote({,})
114
115
116! Macro definitions:
117
118
119! {ip_macro}
120!
121! The logic used in initial and final permutations is the same as in
122! the C code. The permutations are done with a clever shift, xor, and
123! technique.
124!
125! The macro also loads address sbox 1 to 5 to global 1 to 5, address
126! sbox 6 to local6, and addres sbox 8 to out3.
127!
128! Rotates the halfs 3 left to bring the sbox bits in convenient positions.
129!
130! Loads key first round from address in parameter 5 to out0, out1.
131!
132! After the the original LibDES initial permutation, the resulting left
133! is in the variable initially used for right and vice versa. The macro
134! implements the possibility to keep the halfs in the original registers.
135!
136! parameter 1 left
137! parameter 2 right
138! parameter 3 result left (modify in first round)
139! parameter 4 result right (use in first round)
140! parameter 5 key address
141! parameter 6 1/2 for include encryption/decryption
142! parameter 7 1 for move in1 to in3
143! parameter 8 1 for move in3 to in4, 2 for move in4 to in3
144! parameter 9 1 for load ks3 and ks2 to in4 and in3
145
146define(ip_macro, {
147
148! {ip_macro}
149! $1 $2 $4 $3 $5 $6 $7 $8 $9
150
151 ld [out2+256], local1
152 srl $2, 4, local4
153
154 xor local4, $1, local4
155 ifelse($7,1,{mov in1, in3},{nop})
156
157 ld [out2+260], local2
158 and local4, local1, local4
159 ifelse($8,1,{mov in3, in4},{})
160 ifelse($8,2,{mov in4, in3},{})
161
162 ld [out2+280], out4 ! loop counter
163 sll local4, 4, local1
164 xor $1, local4, $1
165
166 ld [out2+264], local3
167 srl $1, 16, local4
168 xor $2, local1, $2
169
170 ifelse($9,1,{LDPTR KS3, in4},{})
171 xor local4, $2, local4
172 nop !sethi %hi(DES_SPtrans), global1 ! sbox addr
173
174 ifelse($9,1,{LDPTR KS2, in3},{})
175 and local4, local2, local4
176 nop !or global1, %lo(DES_SPtrans), global1 ! sbox addr
177
178 sll local4, 16, local1
179 xor $2, local4, $2
180
181 srl $2, 2, local4
182 xor $1, local1, $1
183
184 sethi %hi(16711680), local5
185 xor local4, $1, local4
186
187 and local4, local3, local4
188 or local5, 255, local5
189
190 sll local4, 2, local2
191 xor $1, local4, $1
192
193 srl $1, 8, local4
194 xor $2, local2, $2
195
196 xor local4, $2, local4
197 add global1, 768, global4
198
199 and local4, local5, local4
200 add global1, 1024, global5
201
202 ld [out2+272], local7
203 sll local4, 8, local1
204 xor $2, local4, $2
205
206 srl $2, 1, local4
207 xor $1, local1, $1
208
209 ld [$5], out0 ! key 7531
210 xor local4, $1, local4
211 add global1, 256, global2
212
213 ld [$5+4], out1 ! key 8642
214 and local4, local7, local4
215 add global1, 512, global3
216
217 sll local4, 1, local1
218 xor $1, local4, $1
219
220 sll $1, 3, local3
221 xor $2, local1, $2
222
223 sll $2, 3, local2
224 add global1, 1280, local6 ! address sbox 8
225
226 srl $1, 29, local4
227 add global1, 1792, out3 ! address sbox 8
228
229 srl $2, 29, local1
230 or local4, local3, $4
231
232 or local2, local1, $3
233
234 ifelse($6, 1, {
235
236 ld [out2+284], local5 ! 0x0000FC00 used in the rounds
237 or local2, local1, $3
238 xor $4, out0, local1
239
240 call .des_enc.1
241 and local1, 252, local1
242
243 },{})
244
245 ifelse($6, 2, {
246
247 ld [out2+284], local5 ! 0x0000FC00 used in the rounds
248 or local2, local1, $3
249 xor $4, out0, local1
250
251 call .des_dec.1
252 and local1, 252, local1
253
254 },{})
255})
256
257
258! {rounds_macro}
259!
260! The logic used in the DES rounds is the same as in the C code,
261! except that calculations for sbox 1 and sbox 5 begin before
262! the previous round is finished.
263!
264! In each round one half (work) is modified based on key and the
265! other half (use).
266!
267! In this version we do two rounds in a loop repeated 7 times
268! and two rounds seperately.
269!
270! One half has the bits for the sboxes in the following positions:
271!
272! 777777xx555555xx333333xx111111xx
273!
274! 88xx666666xx444444xx222222xx8888
275!
276! The bits for each sbox are xor-ed with the key bits for that box.
277! The above xx bits are cleared, and the result used for lookup in
278! the sbox table. Each sbox entry contains the 4 output bits permuted
279! into 32 bits according to the P permutation.
280!
281! In the description of DES, left and right are switched after
282! each round, except after last round. In this code the original
283! left and right are kept in the same register in all rounds, meaning
284! that after the 16 rounds the result for right is in the register
285! originally used for left.
286!
287! parameter 1 first work (left in first round)
288! parameter 2 first use (right in first round)
289! parameter 3 enc/dec 1/-1
290! parameter 4 loop label
291! parameter 5 key address register
292! parameter 6 optional address for key next encryption/decryption
293! parameter 7 not empty for include retl
294!
295! also compares in2 to 8
296
297define(rounds_macro, {
298
299! {rounds_macro}
300! $1 $2 $3 $4 $5 $6 $7 $8 $9
301
302 xor $2, out0, local1
303
304 ld [out2+284], local5 ! 0x0000FC00
305 ba $4
306 and local1, 252, local1
307
308 .align 32
309
310$4:
311 ! local6 is address sbox 6
312 ! out3 is address sbox 8
313 ! out4 is loop counter
314
315 ld [global1+local1], local1
316 xor $2, out1, out1 ! 8642
317 xor $2, out0, out0 ! 7531
318 fmovs %f0, %f0 ! fxor used for alignment
319
320 srl out1, 4, local0 ! rotate 4 right
321 and out0, local5, local3 ! 3
322 fmovs %f0, %f0
323
324 ld [$5+$3*8], local7 ! key 7531 next round
325 srl local3, 8, local3 ! 3
326 and local0, 252, local2 ! 2
327 fmovs %f0, %f0
328
329 ld [global3+local3],local3 ! 3
330 sll out1, 28, out1 ! rotate
331 xor $1, local1, $1 ! 1 finished, local1 now sbox 7
332
333 ld [global2+local2], local2 ! 2
334 srl out0, 24, local1 ! 7
335 or out1, local0, out1 ! rotate
336
337 ldub [out2+local1], local1 ! 7 (and 0xFC)
338 srl out1, 24, local0 ! 8
339 and out1, local5, local4 ! 4
340
341 ldub [out2+local0], local0 ! 8 (and 0xFC)
342 srl local4, 8, local4 ! 4
343 xor $1, local2, $1 ! 2 finished local2 now sbox 6
344
345 ld [global4+local4],local4 ! 4
346 srl out1, 16, local2 ! 6
347 xor $1, local3, $1 ! 3 finished local3 now sbox 5
348
349 ld [out3+local0],local0 ! 8
350 and local2, 252, local2 ! 6
351 add global1, 1536, local5 ! address sbox 7
352
353 ld [local6+local2], local2 ! 6
354 srl out0, 16, local3 ! 5
355 xor $1, local4, $1 ! 4 finished
356
357 ld [local5+local1],local1 ! 7
358 and local3, 252, local3 ! 5
359 xor $1, local0, $1 ! 8 finished
360
361 ld [global5+local3],local3 ! 5
362 xor $1, local2, $1 ! 6 finished
363 subcc out4, 1, out4
364
365 ld [$5+$3*8+4], out0 ! key 8642 next round
366 xor $1, local7, local2 ! sbox 5 next round
367 xor $1, local1, $1 ! 7 finished
368
369 srl local2, 16, local2 ! sbox 5 next round
370 xor $1, local3, $1 ! 5 finished
371
372 ld [$5+$3*16+4], out1 ! key 8642 next round again
373 and local2, 252, local2 ! sbox5 next round
374! next round
375 xor $1, local7, local7 ! 7531
376
377 ld [global5+local2], local2 ! 5
378 srl local7, 24, local3 ! 7
379 xor $1, out0, out0 ! 8642
380
381 ldub [out2+local3], local3 ! 7 (and 0xFC)
382 srl out0, 4, local0 ! rotate 4 right
383 and local7, 252, local1 ! 1
384
385 sll out0, 28, out0 ! rotate
386 xor $2, local2, $2 ! 5 finished local2 used
387
388 srl local0, 8, local4 ! 4
389 and local0, 252, local2 ! 2
390 ld [local5+local3], local3 ! 7
391
392 srl local0, 16, local5 ! 6
393 or out0, local0, out0 ! rotate
394 ld [global2+local2], local2 ! 2
395
396 srl out0, 24, local0
397 ld [$5+$3*16], out0 ! key 7531 next round
398 and local4, 252, local4 ! 4
399
400 and local5, 252, local5 ! 6
401 ld [global4+local4], local4 ! 4
402 xor $2, local3, $2 ! 7 finished local3 used
403
404 and local0, 252, local0 ! 8
405 ld [local6+local5], local5 ! 6
406 xor $2, local2, $2 ! 2 finished local2 now sbox 3
407
408 srl local7, 8, local2 ! 3 start
409 ld [out3+local0], local0 ! 8
410 xor $2, local4, $2 ! 4 finished
411
412 and local2, 252, local2 ! 3
413 ld [global1+local1], local1 ! 1
414 xor $2, local5, $2 ! 6 finished local5 used
415
416 ld [global3+local2], local2 ! 3
417 xor $2, local0, $2 ! 8 finished
418 add $5, $3*16, $5 ! enc add 8, dec add -8 to key pointer
419
420 ld [out2+284], local5 ! 0x0000FC00
421 xor $2, out0, local4 ! sbox 1 next round
422 xor $2, local1, $2 ! 1 finished
423
424 xor $2, local2, $2 ! 3 finished
425#ifdef OPENSSL_SYSNAME_ULTRASPARC
426 bne,pt %icc, $4
427#else
428 bne $4
429#endif
430 and local4, 252, local1 ! sbox 1 next round
431
432! two rounds more:
433
434 ld [global1+local1], local1
435 xor $2, out1, out1
436 xor $2, out0, out0
437
438 srl out1, 4, local0 ! rotate
439 and out0, local5, local3
440
441 ld [$5+$3*8], local7 ! key 7531
442 srl local3, 8, local3
443 and local0, 252, local2
444
445 ld [global3+local3],local3
446 sll out1, 28, out1 ! rotate
447 xor $1, local1, $1 ! 1 finished, local1 now sbox 7
448
449 ld [global2+local2], local2
450 srl out0, 24, local1
451 or out1, local0, out1 ! rotate
452
453 ldub [out2+local1], local1
454 srl out1, 24, local0
455 and out1, local5, local4
456
457 ldub [out2+local0], local0
458 srl local4, 8, local4
459 xor $1, local2, $1 ! 2 finished local2 now sbox 6
460
461 ld [global4+local4],local4
462 srl out1, 16, local2
463 xor $1, local3, $1 ! 3 finished local3 now sbox 5
464
465 ld [out3+local0],local0
466 and local2, 252, local2
467 add global1, 1536, local5 ! address sbox 7
468
469 ld [local6+local2], local2
470 srl out0, 16, local3
471 xor $1, local4, $1 ! 4 finished
472
473 ld [local5+local1],local1
474 and local3, 252, local3
475 xor $1, local0, $1
476
477 ld [global5+local3],local3
478 xor $1, local2, $1 ! 6 finished
479 cmp in2, 8
480
481 ifelse($6,{}, {}, {ld [out2+280], out4}) ! loop counter
482 xor $1, local7, local2 ! sbox 5 next round
483 xor $1, local1, $1 ! 7 finished
484
485 ld [$5+$3*8+4], out0
486 srl local2, 16, local2 ! sbox 5 next round
487 xor $1, local3, $1 ! 5 finished
488
489 and local2, 252, local2
490! next round (two rounds more)
491 xor $1, local7, local7 ! 7531
492
493 ld [global5+local2], local2
494 srl local7, 24, local3
495 xor $1, out0, out0 ! 8642
496
497 ldub [out2+local3], local3
498 srl out0, 4, local0 ! rotate
499 and local7, 252, local1
500
501 sll out0, 28, out0 ! rotate
502 xor $2, local2, $2 ! 5 finished local2 used
503
504 srl local0, 8, local4
505 and local0, 252, local2
506 ld [local5+local3], local3
507
508 srl local0, 16, local5
509 or out0, local0, out0 ! rotate
510 ld [global2+local2], local2
511
512 srl out0, 24, local0
513 ifelse($6,{}, {}, {ld [$6], out0}) ! key next encryption/decryption
514 and local4, 252, local4
515
516 and local5, 252, local5
517 ld [global4+local4], local4
518 xor $2, local3, $2 ! 7 finished local3 used
519
520 and local0, 252, local0
521 ld [local6+local5], local5
522 xor $2, local2, $2 ! 2 finished local2 now sbox 3
523
524 srl local7, 8, local2 ! 3 start
525 ld [out3+local0], local0
526 xor $2, local4, $2
527
528 and local2, 252, local2
529 ld [global1+local1], local1
530 xor $2, local5, $2 ! 6 finished local5 used
531
532 ld [global3+local2], local2
533 srl $1, 3, local3
534 xor $2, local0, $2
535
536 ifelse($6,{}, {}, {ld [$6+4], out1}) ! key next encryption/decryption
537 sll $1, 29, local4
538 xor $2, local1, $2
539
540 ifelse($7,{}, {}, {retl})
541 xor $2, local2, $2
542})
543
544
545! {fp_macro}
546!
547! parameter 1 right (original left)
548! parameter 2 left (original right)
549! parameter 3 1 for optional store to [in0]
550! parameter 4 1 for load input/output address to local5/7
551!
552! The final permutation logic switches the halfes, meaning that
553! left and right ends up the the registers originally used.
554
555define(fp_macro, {
556
557! {fp_macro}
558! $1 $2 $3 $4 $5 $6 $7 $8 $9
559
560 ! initially undo the rotate 3 left done after initial permutation
561 ! original left is received shifted 3 right and 29 left in local3/4
562
563 sll $2, 29, local1
564 or local3, local4, $1
565
566 srl $2, 3, $2
567 sethi %hi(0x55555555), local2
568
569 or $2, local1, $2
570 or local2, %lo(0x55555555), local2
571
572 srl $2, 1, local3
573 sethi %hi(0x00ff00ff), local1
574 xor local3, $1, local3
575 or local1, %lo(0x00ff00ff), local1
576 and local3, local2, local3
577 sethi %hi(0x33333333), local4
578 sll local3, 1, local2
579
580 xor $1, local3, $1
581
582 srl $1, 8, local3
583 xor $2, local2, $2
584 xor local3, $2, local3
585 or local4, %lo(0x33333333), local4
586 and local3, local1, local3
587 sethi %hi(0x0000ffff), local1
588 sll local3, 8, local2
589
590 xor $2, local3, $2
591
592 srl $2, 2, local3
593 xor $1, local2, $1
594 xor local3, $1, local3
595 or local1, %lo(0x0000ffff), local1
596 and local3, local4, local3
597 sethi %hi(0x0f0f0f0f), local4
598 sll local3, 2, local2
599
600 ifelse($4,1, {LDPTR INPUT, local5})
601 xor $1, local3, $1
602
603 ifelse($4,1, {LDPTR OUTPUT, local7})
604 srl $1, 16, local3
605 xor $2, local2, $2
606 xor local3, $2, local3
607 or local4, %lo(0x0f0f0f0f), local4
608 and local3, local1, local3
609 sll local3, 16, local2
610
611 xor $2, local3, local1
612
613 srl local1, 4, local3
614 xor $1, local2, $1
615 xor local3, $1, local3
616 and local3, local4, local3
617 sll local3, 4, local2
618
619 xor $1, local3, $1
620
621 ! optional store:
622
623 ifelse($3,1, {st $1, [in0]})
624
625 xor local1, local2, $2
626
627 ifelse($3,1, {st $2, [in0+4]})
628
629})
630
631
632! {fp_ip_macro}
633!
634! Does initial permutation for next block mixed with
635! final permutation for current block.
636!
637! parameter 1 original left
638! parameter 2 original right
639! parameter 3 left ip
640! parameter 4 right ip
641! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4
642! 2: mov in4 to in3
643!
644! also adds -8 to length in2 and loads loop counter to out4
645
646define(fp_ip_macro, {
647
648! {fp_ip_macro}
649! $1 $2 $3 $4 $5 $6 $7 $8 $9
650
651 define({temp1},{out4})
652 define({temp2},{local3})
653
654 define({ip1},{local1})
655 define({ip2},{local2})
656 define({ip4},{local4})
657 define({ip5},{local5})
658
659 ! $1 in local3, local4
660
661 ld [out2+256], ip1
662 sll out5, 29, temp1
663 or local3, local4, $1
664
665 srl out5, 3, $2
666 ifelse($5,2,{mov in4, in3})
667
668 ld [out2+272], ip5
669 srl $4, 4, local0
670 or $2, temp1, $2
671
672 srl $2, 1, temp1
673 xor temp1, $1, temp1
674
675 and temp1, ip5, temp1
676 xor local0, $3, local0
677
678 sll temp1, 1, temp2
679 xor $1, temp1, $1
680
681 and local0, ip1, local0
682 add in2, -8, in2
683
684 sll local0, 4, local7
685 xor $3, local0, $3
686
687 ld [out2+268], ip4
688 srl $1, 8, temp1
689 xor $2, temp2, $2
690 ld [out2+260], ip2
691 srl $3, 16, local0
692 xor $4, local7, $4
693 xor temp1, $2, temp1
694 xor local0, $4, local0
695 and temp1, ip4, temp1
696 and local0, ip2, local0
697 sll temp1, 8, temp2
698 xor $2, temp1, $2
699 sll local0, 16, local7
700 xor $4, local0, $4
701
702 srl $2, 2, temp1
703 xor $1, temp2, $1
704
705 ld [out2+264], temp2 ! ip3
706 srl $4, 2, local0
707 xor $3, local7, $3
708 xor temp1, $1, temp1
709 xor local0, $3, local0
710 and temp1, temp2, temp1
711 and local0, temp2, local0
712 sll temp1, 2, temp2
713 xor $1, temp1, $1
714 sll local0, 2, local7
715 xor $3, local0, $3
716
717 srl $1, 16, temp1
718 xor $2, temp2, $2
719 srl $3, 8, local0
720 xor $4, local7, $4
721 xor temp1, $2, temp1
722 xor local0, $4, local0
723 and temp1, ip2, temp1
724 and local0, ip4, local0
725 sll temp1, 16, temp2
726 xor $2, temp1, local4
727 sll local0, 8, local7
728 xor $4, local0, $4
729
730 srl $4, 1, local0
731 xor $3, local7, $3
732
733 srl local4, 4, temp1
734 xor local0, $3, local0
735
736 xor $1, temp2, $1
737 and local0, ip5, local0
738
739 sll local0, 1, local7
740 xor temp1, $1, temp1
741
742 xor $3, local0, $3
743 xor $4, local7, $4
744
745 sll $3, 3, local5
746 and temp1, ip1, temp1
747
748 sll temp1, 4, temp2
749 xor $1, temp1, $1
750
751 ifelse($5,1,{LDPTR KS2, in4})
752 sll $4, 3, local2
753 xor local4, temp2, $2
754
755 ! reload since used as temporar:
756
757 ld [out2+280], out4 ! loop counter
758
759 srl $3, 29, local0
760 ifelse($5,1,{add in4, 120, in4})
761
762 ifelse($5,1,{LDPTR KS1, in3})
763 srl $4, 29, local7
764
765 or local0, local5, $4
766 or local2, local7, $3
767
768})
769
770
771
772! {load_little_endian}
773!
774! parameter 1 address
775! parameter 2 destination left
776! parameter 3 destination right
777! parameter 4 temporar
778! parameter 5 label
779
780define(load_little_endian, {
781
782! {load_little_endian}
783! $1 $2 $3 $4 $5 $6 $7 $8 $9
784
785 ! first in memory to rightmost in register
786
787#ifdef OPENSSL_SYSNAME_ULTRASPARC
788 andcc $1, 3, global0
789 bne,pn %icc, $5
790 nop
791
792 lda [$1] 0x88, $2
793 add $1, 4, $4
794
795 ba,pt %icc, $5a
796 lda [$4] 0x88, $3
797#endif
798
799$5:
800 ldub [$1+3], $2
801
802 ldub [$1+2], $4
803 sll $2, 8, $2
804 or $2, $4, $2
805
806 ldub [$1+1], $4
807 sll $2, 8, $2
808 or $2, $4, $2
809
810 ldub [$1+0], $4
811 sll $2, 8, $2
812 or $2, $4, $2
813
814
815 ldub [$1+3+4], $3
816
817 ldub [$1+2+4], $4
818 sll $3, 8, $3
819 or $3, $4, $3
820
821 ldub [$1+1+4], $4
822 sll $3, 8, $3
823 or $3, $4, $3
824
825 ldub [$1+0+4], $4
826 sll $3, 8, $3
827 or $3, $4, $3
828$5a:
829
830})
831
832
833! {load_little_endian_inc}
834!
835! parameter 1 address
836! parameter 2 destination left
837! parameter 3 destination right
838! parameter 4 temporar
839! parameter 4 label
840!
841! adds 8 to address
842
843define(load_little_endian_inc, {
844
845! {load_little_endian_inc}
846! $1 $2 $3 $4 $5 $6 $7 $8 $9
847
848 ! first in memory to rightmost in register
849
850#ifdef OPENSSL_SYSNAME_ULTRASPARC
851 andcc $1, 3, global0
852 bne,pn %icc, $5
853 nop
854
855 lda [$1] 0x88, $2
856 add $1, 4, $1
857
858 lda [$1] 0x88, $3
859 ba,pt %icc, $5a
860 add $1, 4, $1
861#endif
862
863$5:
864 ldub [$1+3], $2
865
866 ldub [$1+2], $4
867 sll $2, 8, $2
868 or $2, $4, $2
869
870 ldub [$1+1], $4
871 sll $2, 8, $2
872 or $2, $4, $2
873
874 ldub [$1+0], $4
875 sll $2, 8, $2
876 or $2, $4, $2
877
878 ldub [$1+3+4], $3
879 add $1, 8, $1
880
881 ldub [$1+2+4-8], $4
882 sll $3, 8, $3
883 or $3, $4, $3
884
885 ldub [$1+1+4-8], $4
886 sll $3, 8, $3
887 or $3, $4, $3
888
889 ldub [$1+0+4-8], $4
890 sll $3, 8, $3
891 or $3, $4, $3
892$5a:
893
894})
895
896
897! {load_n_bytes}
898!
899! Loads 1 to 7 bytes little endian
900! Remaining bytes are zeroed.
901!
902! parameter 1 address
903! parameter 2 length
904! parameter 3 destination register left
905! parameter 4 destination register right
906! parameter 5 temp
907! parameter 6 temp2
908! parameter 7 label
909! parameter 8 return label
910
911define(load_n_bytes, {
912
913! {load_n_bytes}
914! $1 $2 $5 $6 $7 $8 $7 $8 $9
915
916$7.0: call .+8
917 sll $2, 2, $6
918
919 add %o7,$7.jmp.table-$7.0,$5
920
921 add $5, $6, $5
922 mov 0, $4
923
924 ld [$5], $5
925
926 jmp %o7+$5
927 mov 0, $3
928
929$7.7:
930 ldub [$1+6], $5
931 sll $5, 16, $5
932 or $3, $5, $3
933$7.6:
934 ldub [$1+5], $5
935 sll $5, 8, $5
936 or $3, $5, $3
937$7.5:
938 ldub [$1+4], $5
939 or $3, $5, $3
940$7.4:
941 ldub [$1+3], $5
942 sll $5, 24, $5
943 or $4, $5, $4
944$7.3:
945 ldub [$1+2], $5
946 sll $5, 16, $5
947 or $4, $5, $4
948$7.2:
949 ldub [$1+1], $5
950 sll $5, 8, $5
951 or $4, $5, $4
952$7.1:
953 ldub [$1+0], $5
954 ba $8
955 or $4, $5, $4
956
957 .align 4
958
959$7.jmp.table:
960 .word 0
961 .word $7.1-$7.0
962 .word $7.2-$7.0
963 .word $7.3-$7.0
964 .word $7.4-$7.0
965 .word $7.5-$7.0
966 .word $7.6-$7.0
967 .word $7.7-$7.0
968})
969
970
971! {store_little_endian}
972!
973! parameter 1 address
974! parameter 2 source left
975! parameter 3 source right
976! parameter 4 temporar
977
978define(store_little_endian, {
979
980! {store_little_endian}
981! $1 $2 $3 $4 $5 $6 $7 $8 $9
982
983 ! rightmost in register to first in memory
984
985#ifdef OPENSSL_SYSNAME_ULTRASPARC
986 andcc $1, 3, global0
987 bne,pn %icc, $5
988 nop
989
990 sta $2, [$1] 0x88
991 add $1, 4, $4
992
993 ba,pt %icc, $5a
994 sta $3, [$4] 0x88
995#endif
996
997$5:
998 and $2, 255, $4
999 stub $4, [$1+0]
1000
1001 srl $2, 8, $4
1002 and $4, 255, $4
1003 stub $4, [$1+1]
1004
1005 srl $2, 16, $4
1006 and $4, 255, $4
1007 stub $4, [$1+2]
1008
1009 srl $2, 24, $4
1010 stub $4, [$1+3]
1011
1012
1013 and $3, 255, $4
1014 stub $4, [$1+0+4]
1015
1016 srl $3, 8, $4
1017 and $4, 255, $4
1018 stub $4, [$1+1+4]
1019
1020 srl $3, 16, $4
1021 and $4, 255, $4
1022 stub $4, [$1+2+4]
1023
1024 srl $3, 24, $4
1025 stub $4, [$1+3+4]
1026
1027$5a:
1028
1029})
1030
1031
1032! {store_n_bytes}
1033!
1034! Stores 1 to 7 bytes little endian
1035!
1036! parameter 1 address
1037! parameter 2 length
1038! parameter 3 source register left
1039! parameter 4 source register right
1040! parameter 5 temp
1041! parameter 6 temp2
1042! parameter 7 label
1043! parameter 8 return label
1044
1045define(store_n_bytes, {
1046
1047! {store_n_bytes}
1048! $1 $2 $5 $6 $7 $8 $7 $8 $9
1049
1050$7.0: call .+8
1051 sll $2, 2, $6
1052
1053 add %o7,$7.jmp.table-$7.0,$5
1054
1055 add $5, $6, $5
1056
1057 ld [$5], $5
1058
1059 jmp %o7+$5
1060 nop
1061
1062$7.7:
1063 srl $3, 16, $5
1064 and $5, 0xff, $5
1065 stub $5, [$1+6]
1066$7.6:
1067 srl $3, 8, $5
1068 and $5, 0xff, $5
1069 stub $5, [$1+5]
1070$7.5:
1071 and $3, 0xff, $5
1072 stub $5, [$1+4]
1073$7.4:
1074 srl $4, 24, $5
1075 stub $5, [$1+3]
1076$7.3:
1077 srl $4, 16, $5
1078 and $5, 0xff, $5
1079 stub $5, [$1+2]
1080$7.2:
1081 srl $4, 8, $5
1082 and $5, 0xff, $5
1083 stub $5, [$1+1]
1084$7.1:
1085 and $4, 0xff, $5
1086
1087
1088 ba $8
1089 stub $5, [$1]
1090
1091 .align 4
1092
1093$7.jmp.table:
1094
1095 .word 0
1096 .word $7.1-$7.0
1097 .word $7.2-$7.0
1098 .word $7.3-$7.0
1099 .word $7.4-$7.0
1100 .word $7.5-$7.0
1101 .word $7.6-$7.0
1102 .word $7.7-$7.0
1103})
1104
1105
1106define(testvalue,{1})
1107
1108define(register_init, {
1109
1110! For test purposes:
1111
1112 sethi %hi(testvalue), local0
1113 or local0, %lo(testvalue), local0
1114
1115 ifelse($1,{},{}, {mov local0, $1})
1116 ifelse($2,{},{}, {mov local0, $2})
1117 ifelse($3,{},{}, {mov local0, $3})
1118 ifelse($4,{},{}, {mov local0, $4})
1119 ifelse($5,{},{}, {mov local0, $5})
1120 ifelse($6,{},{}, {mov local0, $6})
1121 ifelse($7,{},{}, {mov local0, $7})
1122 ifelse($8,{},{}, {mov local0, $8})
1123
1124 mov local0, local1
1125 mov local0, local2
1126 mov local0, local3
1127 mov local0, local4
1128 mov local0, local5
1129 mov local0, local7
1130 mov local0, local6
1131 mov local0, out0
1132 mov local0, out1
1133 mov local0, out2
1134 mov local0, out3
1135 mov local0, out4
1136 mov local0, out5
1137 mov local0, global1
1138 mov local0, global2
1139 mov local0, global3
1140 mov local0, global4
1141 mov local0, global5
1142
1143})
1144
1145.section ".text"
1146
1147 .align 32
1148
1149.des_enc:
1150
1151 ! key address in3
1152 ! loads key next encryption/decryption first round from [in4]
1153
1154 rounds_macro(in5, out5, 1, .des_enc.1, in3, in4, retl)
1155
1156
1157 .align 32
1158
1159.des_dec:
1160
1161 ! implemented with out5 as first parameter to avoid
1162 ! register exchange in ede modes
1163
1164 ! key address in4
1165 ! loads key next encryption/decryption first round from [in3]
1166
1167 rounds_macro(out5, in5, -1, .des_dec.1, in4, in3, retl)
1168
1169
1170
1171! void DES_encrypt1(data, ks, enc)
1172! *******************************
1173
1174 .align 32
1175 .global DES_encrypt1
1176 .type DES_encrypt1,#function
1177
1178DES_encrypt1:
1179
1180 save %sp, FRAME, %sp
1181
1182 call .PIC.me.up
1183 mov .PIC.me.up-(.-4),out0
1184
1185 ld [in0], in5 ! left
1186 cmp in2, 0 ! enc
1187
1188#ifdef OPENSSL_SYSNAME_ULTRASPARC
1189 be,pn %icc, .encrypt.dec ! enc/dec
1190#else
1191 be .encrypt.dec
1192#endif
1193 ld [in0+4], out5 ! right
1194
1195 ! parameter 6 1/2 for include encryption/decryption
1196 ! parameter 7 1 for move in1 to in3
1197 ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3
1198
1199 ip_macro(in5, out5, in5, out5, in3, 0, 1, 1)
1200
1201 rounds_macro(in5, out5, 1, .des_encrypt1.1, in3, in4) ! in4 not used
1202
1203 fp_macro(in5, out5, 1) ! 1 for store to [in0]
1204
1205 ret
1206 restore
1207
1208.encrypt.dec:
1209
1210 add in1, 120, in3 ! use last subkey for first round
1211
1212 ! parameter 6 1/2 for include encryption/decryption
1213 ! parameter 7 1 for move in1 to in3
1214 ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3
1215
1216 ip_macro(in5, out5, out5, in5, in4, 2, 0, 1) ! include dec, ks in4
1217
1218 fp_macro(out5, in5, 1) ! 1 for store to [in0]
1219
1220 ret
1221 restore
1222
1223.DES_encrypt1.end:
1224 .size DES_encrypt1,.DES_encrypt1.end-DES_encrypt1
1225
1226
1227! void DES_encrypt2(data, ks, enc)
1228!*********************************
1229
1230 ! encrypts/decrypts without initial/final permutation
1231
1232 .align 32
1233 .global DES_encrypt2
1234 .type DES_encrypt2,#function
1235
1236DES_encrypt2:
1237
1238 save %sp, FRAME, %sp
1239
1240 call .PIC.me.up
1241 mov .PIC.me.up-(.-4),out0
1242
1243 ! Set sbox address 1 to 6 and rotate halfs 3 left
1244 ! Errors caught by destest? Yes. Still? *NO*
1245
1246 !sethi %hi(DES_SPtrans), global1 ! address sbox 1
1247
1248 !or global1, %lo(DES_SPtrans), global1 ! sbox 1
1249
1250 add global1, 256, global2 ! sbox 2
1251 add global1, 512, global3 ! sbox 3
1252
1253 ld [in0], out5 ! right
1254 add global1, 768, global4 ! sbox 4
1255 add global1, 1024, global5 ! sbox 5
1256
1257 ld [in0+4], in5 ! left
1258 add global1, 1280, local6 ! sbox 6
1259 add global1, 1792, out3 ! sbox 8
1260
1261 ! rotate
1262
1263 sll in5, 3, local5
1264 mov in1, in3 ! key address to in3
1265
1266 sll out5, 3, local7
1267 srl in5, 29, in5
1268
1269 srl out5, 29, out5
1270 add in5, local5, in5
1271
1272 add out5, local7, out5
1273 cmp in2, 0
1274
1275 ! we use our own stackframe
1276
1277#ifdef OPENSSL_SYSNAME_ULTRASPARC
1278 be,pn %icc, .encrypt2.dec ! decryption
1279#else
1280 be .encrypt2.dec
1281#endif
1282 STPTR in0, [%sp+BIAS+ARG0+0*ARGSZ]
1283
1284 ld [in3], out0 ! key 7531 first round
1285 mov LOOPS, out4 ! loop counter
1286
1287 ld [in3+4], out1 ! key 8642 first round
1288 sethi %hi(0x0000FC00), local5
1289
1290 call .des_enc
1291 mov in3, in4
1292
1293 ! rotate
1294 sll in5, 29, in0
1295 srl in5, 3, in5
1296 sll out5, 29, in1
1297 add in5, in0, in5
1298 srl out5, 3, out5
1299 LDPTR [%sp+BIAS+ARG0+0*ARGSZ], in0
1300 add out5, in1, out5
1301 st in5, [in0]
1302 st out5, [in0+4]
1303
1304 ret
1305 restore
1306
1307
1308.encrypt2.dec:
1309
1310 add in3, 120, in4
1311
1312 ld [in4], out0 ! key 7531 first round
1313 mov LOOPS, out4 ! loop counter
1314
1315 ld [in4+4], out1 ! key 8642 first round
1316 sethi %hi(0x0000FC00), local5
1317
1318 mov in5, local1 ! left expected in out5
1319 mov out5, in5
1320
1321 call .des_dec
1322 mov local1, out5
1323
1324.encrypt2.finish:
1325
1326 ! rotate
1327 sll in5, 29, in0
1328 srl in5, 3, in5
1329 sll out5, 29, in1
1330 add in5, in0, in5
1331 srl out5, 3, out5
1332 LDPTR [%sp+BIAS+ARG0+0*ARGSZ], in0
1333 add out5, in1, out5
1334 st out5, [in0]
1335 st in5, [in0+4]
1336
1337 ret
1338 restore
1339
1340.DES_encrypt2.end:
1341 .size DES_encrypt2, .DES_encrypt2.end-DES_encrypt2
1342
1343
1344! void DES_encrypt3(data, ks1, ks2, ks3)
1345! **************************************
1346
1347 .align 32
1348 .global DES_encrypt3
1349 .type DES_encrypt3,#function
1350
1351DES_encrypt3:
1352
1353 save %sp, FRAME, %sp
1354
1355 call .PIC.me.up
1356 mov .PIC.me.up-(.-4),out0
1357
1358 ld [in0], in5 ! left
1359 add in2, 120, in4 ! ks2
1360
1361 ld [in0+4], out5 ! right
1362 mov in3, in2 ! save ks3
1363
1364 ! parameter 6 1/2 for include encryption/decryption
1365 ! parameter 7 1 for mov in1 to in3
1366 ! parameter 8 1 for mov in3 to in4
1367 ! parameter 9 1 for load ks3 and ks2 to in4 and in3
1368
1369 ip_macro(in5, out5, in5, out5, in3, 1, 1, 0, 0)
1370
1371 call .des_dec
1372 mov in2, in3 ! preload ks3
1373
1374 call .des_enc
1375 nop
1376
1377 fp_macro(in5, out5, 1)
1378
1379 ret
1380 restore
1381
1382.DES_encrypt3.end:
1383 .size DES_encrypt3,.DES_encrypt3.end-DES_encrypt3
1384
1385
1386! void DES_decrypt3(data, ks1, ks2, ks3)
1387! **************************************
1388
1389 .align 32
1390 .global DES_decrypt3
1391 .type DES_decrypt3,#function
1392
1393DES_decrypt3:
1394
1395 save %sp, FRAME, %sp
1396
1397 call .PIC.me.up
1398 mov .PIC.me.up-(.-4),out0
1399
1400 ld [in0], in5 ! left
1401 add in3, 120, in4 ! ks3
1402
1403 ld [in0+4], out5 ! right
1404 mov in2, in3 ! ks2
1405
1406 ! parameter 6 1/2 for include encryption/decryption
1407 ! parameter 7 1 for mov in1 to in3
1408 ! parameter 8 1 for mov in3 to in4
1409 ! parameter 9 1 for load ks3 and ks2 to in4 and in3
1410
1411 ip_macro(in5, out5, out5, in5, in4, 2, 0, 0, 0)
1412
1413 call .des_enc
1414 add in1, 120, in4 ! preload ks1
1415
1416 call .des_dec
1417 nop
1418
1419 fp_macro(out5, in5, 1)
1420
1421 ret
1422 restore
1423
1424.DES_decrypt3.end:
1425 .size DES_decrypt3,.DES_decrypt3.end-DES_decrypt3
1426
1427 .align 256
1428 .type .des_and,#object
1429 .size .des_and,284
1430
1431.des_and:
1432
1433! This table is used for AND 0xFC when it is known that register
1434! bits 8-31 are zero. Makes it possible to do three arithmetic
1435! operations in one cycle.
1436
1437 .byte 0, 0, 0, 0, 4, 4, 4, 4
1438 .byte 8, 8, 8, 8, 12, 12, 12, 12
1439 .byte 16, 16, 16, 16, 20, 20, 20, 20
1440 .byte 24, 24, 24, 24, 28, 28, 28, 28
1441 .byte 32, 32, 32, 32, 36, 36, 36, 36
1442 .byte 40, 40, 40, 40, 44, 44, 44, 44
1443 .byte 48, 48, 48, 48, 52, 52, 52, 52
1444 .byte 56, 56, 56, 56, 60, 60, 60, 60
1445 .byte 64, 64, 64, 64, 68, 68, 68, 68
1446 .byte 72, 72, 72, 72, 76, 76, 76, 76
1447 .byte 80, 80, 80, 80, 84, 84, 84, 84
1448 .byte 88, 88, 88, 88, 92, 92, 92, 92
1449 .byte 96, 96, 96, 96, 100, 100, 100, 100
1450 .byte 104, 104, 104, 104, 108, 108, 108, 108
1451 .byte 112, 112, 112, 112, 116, 116, 116, 116
1452 .byte 120, 120, 120, 120, 124, 124, 124, 124
1453 .byte 128, 128, 128, 128, 132, 132, 132, 132
1454 .byte 136, 136, 136, 136, 140, 140, 140, 140
1455 .byte 144, 144, 144, 144, 148, 148, 148, 148
1456 .byte 152, 152, 152, 152, 156, 156, 156, 156
1457 .byte 160, 160, 160, 160, 164, 164, 164, 164
1458 .byte 168, 168, 168, 168, 172, 172, 172, 172
1459 .byte 176, 176, 176, 176, 180, 180, 180, 180
1460 .byte 184, 184, 184, 184, 188, 188, 188, 188
1461 .byte 192, 192, 192, 192, 196, 196, 196, 196
1462 .byte 200, 200, 200, 200, 204, 204, 204, 204
1463 .byte 208, 208, 208, 208, 212, 212, 212, 212
1464 .byte 216, 216, 216, 216, 220, 220, 220, 220
1465 .byte 224, 224, 224, 224, 228, 228, 228, 228
1466 .byte 232, 232, 232, 232, 236, 236, 236, 236
1467 .byte 240, 240, 240, 240, 244, 244, 244, 244
1468 .byte 248, 248, 248, 248, 252, 252, 252, 252
1469
1470 ! 5 numbers for initil/final permutation
1471
1472 .word 0x0f0f0f0f ! offset 256
1473 .word 0x0000ffff ! 260
1474 .word 0x33333333 ! 264
1475 .word 0x00ff00ff ! 268
1476 .word 0x55555555 ! 272
1477
1478 .word 0 ! 276
1479 .word LOOPS ! 280
1480 .word 0x0000FC00 ! 284
1481.PIC.DES_SPtrans:
1482 .word %r_disp32(DES_SPtrans)
1483
1484! input: out0 offset between .PIC.me.up and caller
1485! output: out0 pointer to .PIC.me.up
1486! out2 pointer to .des_and
1487! global1 pointer to DES_SPtrans
1488 .align 32
1489.PIC.me.up:
1490 add out0,%o7,out0 ! pointer to .PIC.me.up
1491#if 1
1492 ld [out0+(.PIC.DES_SPtrans-.PIC.me.up)],global1
1493 add global1,(.PIC.DES_SPtrans-.PIC.me.up),global1
1494 add global1,out0,global1
1495#else
1496# ifdef OPENSSL_PIC
1497 ! In case anybody wonders why this code is same for both ABI.
1498 ! To start with it is not. Do note LDPTR below. But of course
1499 ! you must be wondering why the rest of it does not contain
1500 ! things like %hh, %hm and %lm. Well, those are needed only
1501 ! if OpenSSL library *itself* will become larger than 4GB,
1502 ! which is not going to happen any time soon.
1503 sethi %hi(DES_SPtrans),global1
1504 or global1,%lo(DES_SPtrans),global1
1505 sethi %hi(_GLOBAL_OFFSET_TABLE_-(.PIC.me.up-.)),out2
1506 add global1,out0,global1
1507 add out2,%lo(_GLOBAL_OFFSET_TABLE_-(.PIC.me.up-.)),out2
1508 LDPTR [out2+global1],global1
1509# elif 0
1510 setn DES_SPtrans,out2,global1 ! synthetic instruction !
1511# elif defined(ABI64)
1512 sethi %hh(DES_SPtrans),out2
1513 or out2,%hm(DES_SPtrans),out2
1514 sethi %lm(DES_SPtrans),global1
1515 or global1,%lo(DES_SPtrans),global1
1516 sllx out2,32,out2
1517 or out2,global1,global1
1518# else
1519 sethi %hi(DES_SPtrans),global1
1520 or global1,%lo(DES_SPtrans),global1
1521# endif
1522#endif
1523 retl
1524 add out0,.des_and-.PIC.me.up,out2
1525
1526! void DES_ncbc_encrypt(input, output, length, schedule, ivec, enc)
1527! *****************************************************************
1528
1529
1530 .align 32
1531 .global DES_ncbc_encrypt
1532 .type DES_ncbc_encrypt,#function
1533
1534DES_ncbc_encrypt:
1535
1536 save %sp, FRAME, %sp
1537
1538 define({INPUT}, { [%sp+BIAS+ARG0+0*ARGSZ] })
1539 define({OUTPUT}, { [%sp+BIAS+ARG0+1*ARGSZ] })
1540 define({IVEC}, { [%sp+BIAS+ARG0+4*ARGSZ] })
1541
1542 call .PIC.me.up
1543 mov .PIC.me.up-(.-4),out0
1544
1545 cmp in5, 0 ! enc
1546
1547#ifdef OPENSSL_SYSNAME_ULTRASPARC
1548 be,pn %icc, .ncbc.dec
1549#else
1550 be .ncbc.dec
1551#endif
1552 STPTR in4, IVEC
1553
1554 ! addr left right temp label
1555 load_little_endian(in4, in5, out5, local3, .LLE1) ! iv
1556
1557 addcc in2, -8, in2 ! bytes missing when first block done
1558
1559#ifdef OPENSSL_SYSNAME_ULTRASPARC
1560 bl,pn %icc, .ncbc.enc.seven.or.less
1561#else
1562 bl .ncbc.enc.seven.or.less
1563#endif
1564 mov in3, in4 ! schedule
1565
1566.ncbc.enc.next.block:
1567
1568 load_little_endian(in0, out4, global4, local3, .LLE2) ! block
1569
1570.ncbc.enc.next.block_1:
1571
1572 xor in5, out4, in5 ! iv xor
1573 xor out5, global4, out5 ! iv xor
1574
1575 ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3
1576 ip_macro(in5, out5, in5, out5, in3, 0, 0, 2)
1577
1578.ncbc.enc.next.block_2:
1579
1580!// call .des_enc ! compares in2 to 8
1581! rounds inlined for alignment purposes
1582
1583 add global1, 768, global4 ! address sbox 4 since register used below
1584
1585 rounds_macro(in5, out5, 1, .ncbc.enc.1, in3, in4) ! include encryption ks in3
1586
1587#ifdef OPENSSL_SYSNAME_ULTRASPARC
1588 bl,pn %icc, .ncbc.enc.next.block_fp
1589#else
1590 bl .ncbc.enc.next.block_fp
1591#endif
1592 add in0, 8, in0 ! input address
1593
1594 ! If 8 or more bytes are to be encrypted after this block,
1595 ! we combine final permutation for this block with initial
1596 ! permutation for next block. Load next block:
1597
1598 load_little_endian(in0, global3, global4, local5, .LLE12)
1599
1600 ! parameter 1 original left
1601 ! parameter 2 original right
1602 ! parameter 3 left ip
1603 ! parameter 4 right ip
1604 ! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4
1605 ! 2: mov in4 to in3
1606 !
1607 ! also adds -8 to length in2 and loads loop counter to out4
1608
1609 fp_ip_macro(out0, out1, global3, global4, 2)
1610
1611 store_little_endian(in1, out0, out1, local3, .SLE10) ! block
1612
1613 ld [in3], out0 ! key 7531 first round next block
1614 mov in5, local1
1615 xor global3, out5, in5 ! iv xor next block
1616
1617 ld [in3+4], out1 ! key 8642
1618 add global1, 512, global3 ! address sbox 3 since register used
1619 xor global4, local1, out5 ! iv xor next block
1620
1621 ba .ncbc.enc.next.block_2
1622 add in1, 8, in1 ! output adress
1623
1624.ncbc.enc.next.block_fp:
1625
1626 fp_macro(in5, out5)
1627
1628 store_little_endian(in1, in5, out5, local3, .SLE1) ! block
1629
1630 addcc in2, -8, in2 ! bytes missing when next block done
1631
1632#ifdef OPENSSL_SYSNAME_ULTRASPARC
1633 bpos,pt %icc, .ncbc.enc.next.block ! also jumps if 0
1634#else
1635 bpos .ncbc.enc.next.block
1636#endif
1637 add in1, 8, in1
1638
1639.ncbc.enc.seven.or.less:
1640
1641 cmp in2, -8
1642
1643#ifdef OPENSSL_SYSNAME_ULTRASPARC
1644 ble,pt %icc, .ncbc.enc.finish
1645#else
1646 ble .ncbc.enc.finish
1647#endif
1648 nop
1649
1650 add in2, 8, local1 ! bytes to load
1651
1652 ! addr, length, dest left, dest right, temp, temp2, label, ret label
1653 load_n_bytes(in0, local1, global4, out4, local2, local3, .LNB1, .ncbc.enc.next.block_1)
1654
1655 ! Loads 1 to 7 bytes little endian to global4, out4
1656
1657
1658.ncbc.enc.finish:
1659
1660 LDPTR IVEC, local4
1661 store_little_endian(local4, in5, out5, local5, .SLE2) ! ivec
1662
1663 ret
1664 restore
1665
1666
1667.ncbc.dec:
1668
1669 STPTR in0, INPUT
1670 cmp in2, 0 ! length
1671 add in3, 120, in3
1672
1673 LDPTR IVEC, local7 ! ivec
1674#ifdef OPENSSL_SYSNAME_ULTRASPARC
1675 ble,pn %icc, .ncbc.dec.finish
1676#else
1677 ble .ncbc.dec.finish
1678#endif
1679 mov in3, in4 ! schedule
1680
1681 STPTR in1, OUTPUT
1682 mov in0, local5 ! input
1683
1684 load_little_endian(local7, in0, in1, local3, .LLE3) ! ivec
1685
1686.ncbc.dec.next.block:
1687
1688 load_little_endian(local5, in5, out5, local3, .LLE4) ! block
1689
1690 ! parameter 6 1/2 for include encryption/decryption
1691 ! parameter 7 1 for mov in1 to in3
1692 ! parameter 8 1 for mov in3 to in4
1693
1694 ip_macro(in5, out5, out5, in5, in4, 2, 0, 1) ! include decryprion ks in4
1695
1696 fp_macro(out5, in5, 0, 1) ! 1 for input and output address to local5/7
1697
1698 ! in2 is bytes left to be stored
1699 ! in2 is compared to 8 in the rounds
1700
1701 xor out5, in0, out4 ! iv xor
1702#ifdef OPENSSL_SYSNAME_ULTRASPARC
1703 bl,pn %icc, .ncbc.dec.seven.or.less
1704#else
1705 bl .ncbc.dec.seven.or.less
1706#endif
1707 xor in5, in1, global4 ! iv xor
1708
1709 ! Load ivec next block now, since input and output address might be the same.
1710
1711 load_little_endian_inc(local5, in0, in1, local3, .LLE5) ! iv
1712
1713 store_little_endian(local7, out4, global4, local3, .SLE3)
1714
1715 STPTR local5, INPUT
1716 add local7, 8, local7
1717 addcc in2, -8, in2
1718
1719#ifdef OPENSSL_SYSNAME_ULTRASPARC
1720 bg,pt %icc, .ncbc.dec.next.block
1721#else
1722 bg .ncbc.dec.next.block
1723#endif
1724 STPTR local7, OUTPUT
1725
1726
1727.ncbc.dec.store.iv:
1728
1729 LDPTR IVEC, local4 ! ivec
1730 store_little_endian(local4, in0, in1, local5, .SLE4)
1731
1732.ncbc.dec.finish:
1733
1734 ret
1735 restore
1736
1737.ncbc.dec.seven.or.less:
1738
1739 load_little_endian_inc(local5, in0, in1, local3, .LLE13) ! ivec
1740
1741 store_n_bytes(local7, in2, global4, out4, local3, local4, .SNB1, .ncbc.dec.store.iv)
1742
1743
1744.DES_ncbc_encrypt.end:
1745 .size DES_ncbc_encrypt, .DES_ncbc_encrypt.end-DES_ncbc_encrypt
1746
1747
1748! void DES_ede3_cbc_encrypt(input, output, lenght, ks1, ks2, ks3, ivec, enc)
1749! **************************************************************************
1750
1751
1752 .align 32
1753 .global DES_ede3_cbc_encrypt
1754 .type DES_ede3_cbc_encrypt,#function
1755
1756DES_ede3_cbc_encrypt:
1757
1758 save %sp, FRAME, %sp
1759
1760 define({KS1}, { [%sp+BIAS+ARG0+3*ARGSZ] })
1761 define({KS2}, { [%sp+BIAS+ARG0+4*ARGSZ] })
1762 define({KS3}, { [%sp+BIAS+ARG0+5*ARGSZ] })
1763
1764 call .PIC.me.up
1765 mov .PIC.me.up-(.-4),out0
1766
1767 LDPTR [%fp+BIAS+ARG0+7*ARGSZ], local3 ! enc
1768 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec
1769 cmp local3, 0 ! enc
1770
1771#ifdef OPENSSL_SYSNAME_ULTRASPARC
1772 be,pn %icc, .ede3.dec
1773#else
1774 be .ede3.dec
1775#endif
1776 STPTR in4, KS2
1777
1778 STPTR in5, KS3
1779
1780 load_little_endian(local4, in5, out5, local3, .LLE6) ! ivec
1781
1782 addcc in2, -8, in2 ! bytes missing after next block
1783
1784#ifdef OPENSSL_SYSNAME_ULTRASPARC
1785 bl,pn %icc, .ede3.enc.seven.or.less
1786#else
1787 bl .ede3.enc.seven.or.less
1788#endif
1789 STPTR in3, KS1
1790
1791.ede3.enc.next.block:
1792
1793 load_little_endian(in0, out4, global4, local3, .LLE7)
1794
1795.ede3.enc.next.block_1:
1796
1797 LDPTR KS2, in4
1798 xor in5, out4, in5 ! iv xor
1799 xor out5, global4, out5 ! iv xor
1800
1801 LDPTR KS1, in3
1802 add in4, 120, in4 ! for decryption we use last subkey first
1803 nop
1804
1805 ip_macro(in5, out5, in5, out5, in3)
1806
1807.ede3.enc.next.block_2:
1808
1809 call .des_enc ! ks1 in3
1810 nop
1811
1812 call .des_dec ! ks2 in4
1813 LDPTR KS3, in3
1814
1815 call .des_enc ! ks3 in3 compares in2 to 8
1816 nop
1817
1818#ifdef OPENSSL_SYSNAME_ULTRASPARC
1819 bl,pn %icc, .ede3.enc.next.block_fp
1820#else
1821 bl .ede3.enc.next.block_fp
1822#endif
1823 add in0, 8, in0
1824
1825 ! If 8 or more bytes are to be encrypted after this block,
1826 ! we combine final permutation for this block with initial
1827 ! permutation for next block. Load next block:
1828
1829 load_little_endian(in0, global3, global4, local5, .LLE11)
1830
1831 ! parameter 1 original left
1832 ! parameter 2 original right
1833 ! parameter 3 left ip
1834 ! parameter 4 right ip
1835 ! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4
1836 ! 2: mov in4 to in3
1837 !
1838 ! also adds -8 to length in2 and loads loop counter to out4
1839
1840 fp_ip_macro(out0, out1, global3, global4, 1)
1841
1842 store_little_endian(in1, out0, out1, local3, .SLE9) ! block
1843
1844 mov in5, local1
1845 xor global3, out5, in5 ! iv xor next block
1846
1847 ld [in3], out0 ! key 7531
1848 add global1, 512, global3 ! address sbox 3
1849 xor global4, local1, out5 ! iv xor next block
1850
1851 ld [in3+4], out1 ! key 8642
1852 add global1, 768, global4 ! address sbox 4
1853 ba .ede3.enc.next.block_2
1854 add in1, 8, in1
1855
1856.ede3.enc.next.block_fp:
1857
1858 fp_macro(in5, out5)
1859
1860 store_little_endian(in1, in5, out5, local3, .SLE5) ! block
1861
1862 addcc in2, -8, in2 ! bytes missing when next block done
1863
1864#ifdef OPENSSL_SYSNAME_ULTRASPARC
1865 bpos,pt %icc, .ede3.enc.next.block
1866#else
1867 bpos .ede3.enc.next.block
1868#endif
1869 add in1, 8, in1
1870
1871.ede3.enc.seven.or.less:
1872
1873 cmp in2, -8
1874
1875#ifdef OPENSSL_SYSNAME_ULTRASPARC
1876 ble,pt %icc, .ede3.enc.finish
1877#else
1878 ble .ede3.enc.finish
1879#endif
1880 nop
1881
1882 add in2, 8, local1 ! bytes to load
1883
1884 ! addr, length, dest left, dest right, temp, temp2, label, ret label
1885 load_n_bytes(in0, local1, global4, out4, local2, local3, .LNB2, .ede3.enc.next.block_1)
1886
1887.ede3.enc.finish:
1888
1889 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec
1890 store_little_endian(local4, in5, out5, local5, .SLE6) ! ivec
1891
1892 ret
1893 restore
1894
1895.ede3.dec:
1896
1897 STPTR in0, INPUT
1898 add in5, 120, in5
1899
1900 STPTR in1, OUTPUT
1901 mov in0, local5
1902 add in3, 120, in3
1903
1904 STPTR in3, KS1
1905 cmp in2, 0
1906
1907#ifdef OPENSSL_SYSNAME_ULTRASPARC
1908 ble %icc, .ede3.dec.finish
1909#else
1910 ble .ede3.dec.finish
1911#endif
1912 STPTR in5, KS3
1913
1914 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local7 ! iv
1915 load_little_endian(local7, in0, in1, local3, .LLE8)
1916
1917.ede3.dec.next.block:
1918
1919 load_little_endian(local5, in5, out5, local3, .LLE9)
1920
1921 ! parameter 6 1/2 for include encryption/decryption
1922 ! parameter 7 1 for mov in1 to in3
1923 ! parameter 8 1 for mov in3 to in4
1924 ! parameter 9 1 for load ks3 and ks2 to in4 and in3
1925
1926 ip_macro(in5, out5, out5, in5, in4, 2, 0, 0, 1) ! inc .des_dec ks3 in4
1927
1928 call .des_enc ! ks2 in3
1929 LDPTR KS1, in4
1930
1931 call .des_dec ! ks1 in4
1932 nop
1933
1934 fp_macro(out5, in5, 0, 1) ! 1 for input and output address local5/7
1935
1936 ! in2 is bytes left to be stored
1937 ! in2 is compared to 8 in the rounds
1938
1939 xor out5, in0, out4
1940#ifdef OPENSSL_SYSNAME_ULTRASPARC
1941 bl,pn %icc, .ede3.dec.seven.or.less
1942#else
1943 bl .ede3.dec.seven.or.less
1944#endif
1945 xor in5, in1, global4
1946
1947 load_little_endian_inc(local5, in0, in1, local3, .LLE10) ! iv next block
1948
1949 store_little_endian(local7, out4, global4, local3, .SLE7) ! block
1950
1951 STPTR local5, INPUT
1952 addcc in2, -8, in2
1953 add local7, 8, local7
1954
1955#ifdef OPENSSL_SYSNAME_ULTRASPARC
1956 bg,pt %icc, .ede3.dec.next.block
1957#else
1958 bg .ede3.dec.next.block
1959#endif
1960 STPTR local7, OUTPUT
1961
1962.ede3.dec.store.iv:
1963
1964 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec
1965 store_little_endian(local4, in0, in1, local5, .SLE8) ! ivec
1966
1967.ede3.dec.finish:
1968
1969 ret
1970 restore
1971
1972.ede3.dec.seven.or.less:
1973
1974 load_little_endian_inc(local5, in0, in1, local3, .LLE14) ! iv
1975
1976 store_n_bytes(local7, in2, global4, out4, local3, local4, .SNB2, .ede3.dec.store.iv)
1977
1978
1979.DES_ede3_cbc_encrypt.end:
1980 .size DES_ede3_cbc_encrypt,.DES_ede3_cbc_encrypt.end-DES_ede3_cbc_encrypt
diff --git a/src/lib/libcrypto/des/asm/desboth.pl b/src/lib/libcrypto/des/asm/desboth.pl
new file mode 100644
index 0000000000..eec00886e4
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/desboth.pl
@@ -0,0 +1,79 @@
1#!/usr/local/bin/perl
2
3$L="edi";
4$R="esi";
5
6sub DES_encrypt3
7 {
8 local($name,$enc)=@_;
9
10 &function_begin_B($name,"");
11 &push("ebx");
12 &mov("ebx",&wparam(0));
13
14 &push("ebp");
15 &push("esi");
16
17 &push("edi");
18
19 &comment("");
20 &comment("Load the data words");
21 &mov($L,&DWP(0,"ebx","",0));
22 &mov($R,&DWP(4,"ebx","",0));
23 &stack_push(3);
24
25 &comment("");
26 &comment("IP");
27 &IP_new($L,$R,"edx",0);
28
29 # put them back
30
31 if ($enc)
32 {
33 &mov(&DWP(4,"ebx","",0),$R);
34 &mov("eax",&wparam(1));
35 &mov(&DWP(0,"ebx","",0),"edx");
36 &mov("edi",&wparam(2));
37 &mov("esi",&wparam(3));
38 }
39 else
40 {
41 &mov(&DWP(4,"ebx","",0),$R);
42 &mov("esi",&wparam(1));
43 &mov(&DWP(0,"ebx","",0),"edx");
44 &mov("edi",&wparam(2));
45 &mov("eax",&wparam(3));
46 }
47 &mov(&swtmp(2), (DWC(($enc)?"1":"0")));
48 &mov(&swtmp(1), "eax");
49 &mov(&swtmp(0), "ebx");
50 &call("DES_encrypt2");
51 &mov(&swtmp(2), (DWC(($enc)?"0":"1")));
52 &mov(&swtmp(1), "edi");
53 &mov(&swtmp(0), "ebx");
54 &call("DES_encrypt2");
55 &mov(&swtmp(2), (DWC(($enc)?"1":"0")));
56 &mov(&swtmp(1), "esi");
57 &mov(&swtmp(0), "ebx");
58 &call("DES_encrypt2");
59
60 &stack_pop(3);
61 &mov($L,&DWP(0,"ebx","",0));
62 &mov($R,&DWP(4,"ebx","",0));
63
64 &comment("");
65 &comment("FP");
66 &FP_new($L,$R,"eax",0);
67
68 &mov(&DWP(0,"ebx","",0),"eax");
69 &mov(&DWP(4,"ebx","",0),$R);
70
71 &pop("edi");
72 &pop("esi");
73 &pop("ebp");
74 &pop("ebx");
75 &ret();
76 &function_end_B($name);
77 }
78
79
diff --git a/src/lib/libcrypto/des/asm/readme b/src/lib/libcrypto/des/asm/readme
new file mode 100644
index 0000000000..1beafe253b
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/readme
@@ -0,0 +1,131 @@
1First up, let me say I don't like writing in assembler. It is not portable,
2dependant on the particular CPU architecture release and is generally a pig
3to debug and get right. Having said that, the x86 architecture is probably
4the most important for speed due to number of boxes and since
5it appears to be the worst architecture to to get
6good C compilers for. So due to this, I have lowered myself to do
7assembler for the inner DES routines in libdes :-).
8
9The file to implement in assembler is des_enc.c. Replace the following
104 functions
11des_encrypt1(DES_LONG data[2],des_key_schedule ks, int encrypt);
12des_encrypt2(DES_LONG data[2],des_key_schedule ks, int encrypt);
13des_encrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
14des_decrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
15
16They encrypt/decrypt the 64 bits held in 'data' using
17the 'ks' key schedules. The only difference between the 4 functions is that
18des_encrypt2() does not perform IP() or FP() on the data (this is an
19optimization for when doing triple DES and des_encrypt3() and des_decrypt3()
20perform triple des. The triple DES routines are in here because it does
21make a big difference to have them located near the des_encrypt2 function
22at link time..
23
24Now as we all know, there are lots of different operating systems running on
25x86 boxes, and unfortunately they normally try to make sure their assembler
26formating is not the same as the other peoples.
27The 4 main formats I know of are
28Microsoft Windows 95/Windows NT
29Elf Includes Linux and FreeBSD(?).
30a.out The older Linux.
31Solaris Same as Elf but different comments :-(.
32
33Now I was not overly keen to write 4 different copies of the same code,
34so I wrote a few perl routines to output the correct assembler, given
35a target assembler type. This code is ugly and is just a hack.
36The libraries are x86unix.pl and x86ms.pl.
37des586.pl, des686.pl and des-som[23].pl are the programs to actually
38generate the assembler.
39
40So to generate elf assembler
41perl des-som3.pl elf >dx86-elf.s
42For Windows 95/NT
43perl des-som2.pl win32 >win32.asm
44
45[ update 4 Jan 1996 ]
46I have added another way to do things.
47perl des-som3.pl cpp >dx86-cpp.s
48generates a file that will be included by dx86unix.cpp when it is compiled.
49To build for elf, a.out, solaris, bsdi etc,
50cc -E -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o
51cc -E -DSOL asm/dx86unix.cpp | as -o asm/dx86-sol.o
52cc -E -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o
53cc -E -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o
54This was done to cut down the number of files in the distribution.
55
56Now the ugly part. I acquired my copy of Intels
57"Optimization's For Intel's 32-Bit Processors" and found a few interesting
58things. First, the aim of the exersize is to 'extract' one byte at a time
59from a word and do an array lookup. This involves getting the byte from
60the 4 locations in the word and moving it to a new word and doing the lookup.
61The most obvious way to do this is
62xor eax, eax # clear word
63movb al, cl # get low byte
64xor edi DWORD PTR 0x100+des_SP[eax] # xor in word
65movb al, ch # get next byte
66xor edi DWORD PTR 0x300+des_SP[eax] # xor in word
67shr ecx 16
68which seems ok. For the pentium, this system appears to be the best.
69One has to do instruction interleaving to keep both functional units
70operating, but it is basically very efficient.
71
72Now the crunch. When a full register is used after a partial write, eg.
73mov al, cl
74xor edi, DWORD PTR 0x100+des_SP[eax]
75386 - 1 cycle stall
76486 - 1 cycle stall
77586 - 0 cycle stall
78686 - at least 7 cycle stall (page 22 of the above mentioned document).
79
80So the technique that produces the best results on a pentium, according to
81the documentation, will produce hideous results on a pentium pro.
82
83To get around this, des686.pl will generate code that is not as fast on
84a pentium, should be very good on a pentium pro.
85mov eax, ecx # copy word
86shr ecx, 8 # line up next byte
87and eax, 0fch # mask byte
88xor edi DWORD PTR 0x100+des_SP[eax] # xor in array lookup
89mov eax, ecx # get word
90shr ecx 8 # line up next byte
91and eax, 0fch # mask byte
92xor edi DWORD PTR 0x300+des_SP[eax] # xor in array lookup
93
94Due to the execution units in the pentium, this actually works quite well.
95For a pentium pro it should be very good. This is the type of output
96Visual C++ generates.
97
98There is a third option. instead of using
99mov al, ch
100which is bad on the pentium pro, one may be able to use
101movzx eax, ch
102which may not incur the partial write penalty. On the pentium,
103this instruction takes 4 cycles so is not worth using but on the
104pentium pro it appears it may be worth while. I need access to one to
105experiment :-).
106
107eric (20 Oct 1996)
108
10922 Nov 1996 - I have asked people to run the 2 different version on pentium
110pros and it appears that the intel documentation is wrong. The
111mov al,bh is still faster on a pentium pro, so just use the des586.pl
112install des686.pl
113
1143 Dec 1996 - I added des_encrypt3/des_decrypt3 because I have moved these
115functions into des_enc.c because it does make a massive performance
116difference on some boxes to have the functions code located close to
117the des_encrypt2() function.
118
1199 Jan 1997 - des-som2.pl is now the correct perl script to use for
120pentiums. It contains an inner loop from
121Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> which does raw ecb DES calls at
122273,000 per second. He had a previous version at 250,000 and the best
123I was able to get was 203,000. The content has not changed, this is all
124due to instruction sequencing (and actual instructions choice) which is able
125to keep both functional units of the pentium going.
126We may have lost the ugly register usage restrictions when x86 went 32 bit
127but for the pentium it has been replaced by evil instruction ordering tricks.
128
12913 Jan 1997 - des-som3.pl, more optimizations from Svend Olaf.
130raw DES at 281,000 per second on a pentium 100.
131
diff --git a/src/lib/libcrypto/des/cbc3_enc.c b/src/lib/libcrypto/des/cbc3_enc.c
new file mode 100644
index 0000000000..b5db4e14f7
--- /dev/null
+++ b/src/lib/libcrypto/des/cbc3_enc.c
@@ -0,0 +1,99 @@
1/* crypto/des/cbc3_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* HAS BUGS! DON'T USE - this is only present for use in des.c */
62void DES_3cbc_encrypt(DES_cblock *input, DES_cblock *output, long length,
63 DES_key_schedule ks1, DES_key_schedule ks2, DES_cblock *iv1,
64 DES_cblock *iv2, int enc)
65 {
66 int off=((int)length-1)/8;
67 long l8=((length+7)/8)*8;
68 DES_cblock niv1,niv2;
69
70 if (enc == DES_ENCRYPT)
71 {
72 DES_cbc_encrypt((unsigned char*)input,
73 (unsigned char*)output,length,&ks1,iv1,enc);
74 if (length >= sizeof(DES_cblock))
75 memcpy(niv1,output[off],sizeof(DES_cblock));
76 DES_cbc_encrypt((unsigned char*)output,
77 (unsigned char*)output,l8,&ks2,iv1,!enc);
78 DES_cbc_encrypt((unsigned char*)output,
79 (unsigned char*)output,l8,&ks1,iv2,enc);
80 if (length >= sizeof(DES_cblock))
81 memcpy(niv2,output[off],sizeof(DES_cblock));
82 }
83 else
84 {
85 if (length >= sizeof(DES_cblock))
86 memcpy(niv2,input[off],sizeof(DES_cblock));
87 DES_cbc_encrypt((unsigned char*)input,
88 (unsigned char*)output,l8,&ks1,iv2,enc);
89 DES_cbc_encrypt((unsigned char*)output,
90 (unsigned char*)output,l8,&ks2,iv1,!enc);
91 if (length >= sizeof(DES_cblock))
92 memcpy(niv1,output[off],sizeof(DES_cblock));
93 DES_cbc_encrypt((unsigned char*)output,
94 (unsigned char*)output,length,&ks1,iv1,enc);
95 }
96 memcpy(*iv1,niv1,sizeof(DES_cblock));
97 memcpy(*iv2,niv2,sizeof(DES_cblock));
98 }
99
diff --git a/src/lib/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c
new file mode 100644
index 0000000000..09a7ba56aa
--- /dev/null
+++ b/src/lib/libcrypto/des/cbc_cksm.c
@@ -0,0 +1,106 @@
1/* crypto/des/cbc_cksm.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
61DES_LONG DES_cbc_cksum(const unsigned char *in, DES_cblock *output,
62 long length, DES_key_schedule *schedule,
63 const_DES_cblock *ivec)
64 {
65 register DES_LONG tout0,tout1,tin0,tin1;
66 register long l=length;
67 DES_LONG tin[2];
68 unsigned char *out = &(*output)[0];
69 const unsigned char *iv = &(*ivec)[0];
70
71 c2l(iv,tout0);
72 c2l(iv,tout1);
73 for (; l>0; l-=8)
74 {
75 if (l >= 8)
76 {
77 c2l(in,tin0);
78 c2l(in,tin1);
79 }
80 else
81 c2ln(in,tin0,tin1,l);
82
83 tin0^=tout0; tin[0]=tin0;
84 tin1^=tout1; tin[1]=tin1;
85 DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT);
86 /* fix 15/10/91 eay - thanks to keithr@sco.COM */
87 tout0=tin[0];
88 tout1=tin[1];
89 }
90 if (out != NULL)
91 {
92 l2c(tout0,out);
93 l2c(tout1,out);
94 }
95 tout0=tin0=tin1=tin[0]=tin[1]=0;
96 /*
97 Transform the data in tout1 so that it will
98 match the return value that the MIT Kerberos
99 mit_des_cbc_cksum API returns.
100 */
101 tout1 = ((tout1 >> 24L) & 0x000000FF)
102 | ((tout1 >> 8L) & 0x0000FF00)
103 | ((tout1 << 8L) & 0x00FF0000)
104 | ((tout1 << 24L) & 0xFF000000);
105 return(tout1);
106 }
diff --git a/src/lib/libcrypto/des/cbc_enc.c b/src/lib/libcrypto/des/cbc_enc.c
new file mode 100644
index 0000000000..677903ae4e
--- /dev/null
+++ b/src/lib/libcrypto/des/cbc_enc.c
@@ -0,0 +1,61 @@
1/* crypto/des/cbc_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#define CBC_ENC_C__DONT_UPDATE_IV
60
61#include "ncbc_enc.c" /* des_cbc_encrypt */
diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c
new file mode 100644
index 0000000000..de34ecceb9
--- /dev/null
+++ b/src/lib/libcrypto/des/cfb64ede.c
@@ -0,0 +1,254 @@
1/* crypto/des/cfb64ede.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#include "e_os.h"
61
62/* The input and output encrypted as though 64bit cfb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66
67void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
68 long length, DES_key_schedule *ks1,
69 DES_key_schedule *ks2, DES_key_schedule *ks3,
70 DES_cblock *ivec, int *num, int enc)
71 {
72 register DES_LONG v0,v1;
73 register long l=length;
74 register int n= *num;
75 DES_LONG ti[2];
76 unsigned char *iv,c,cc;
77
78 iv=&(*ivec)[0];
79 if (enc)
80 {
81 while (l--)
82 {
83 if (n == 0)
84 {
85 c2l(iv,v0);
86 c2l(iv,v1);
87
88 ti[0]=v0;
89 ti[1]=v1;
90 DES_encrypt3(ti,ks1,ks2,ks3);
91 v0=ti[0];
92 v1=ti[1];
93
94 iv = &(*ivec)[0];
95 l2c(v0,iv);
96 l2c(v1,iv);
97 iv = &(*ivec)[0];
98 }
99 c= *(in++)^iv[n];
100 *(out++)=c;
101 iv[n]=c;
102 n=(n+1)&0x07;
103 }
104 }
105 else
106 {
107 while (l--)
108 {
109 if (n == 0)
110 {
111 c2l(iv,v0);
112 c2l(iv,v1);
113
114 ti[0]=v0;
115 ti[1]=v1;
116 DES_encrypt3(ti,ks1,ks2,ks3);
117 v0=ti[0];
118 v1=ti[1];
119
120 iv = &(*ivec)[0];
121 l2c(v0,iv);
122 l2c(v1,iv);
123 iv = &(*ivec)[0];
124 }
125 cc= *(in++);
126 c=iv[n];
127 iv[n]=cc;
128 *(out++)=c^cc;
129 n=(n+1)&0x07;
130 }
131 }
132 v0=v1=ti[0]=ti[1]=c=cc=0;
133 *num=n;
134 }
135
136#ifdef undef /* MACRO */
137void DES_ede2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
138 DES_key_schedule ks1, DES_key_schedule ks2, DES_cblock (*ivec),
139 int *num, int enc)
140 {
141 DES_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc);
142 }
143#endif
144
145/* This is compatible with the single key CFB-r for DES, even thought that's
146 * not what EVP needs.
147 */
148
149void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
150 int numbits,long length,DES_key_schedule *ks1,
151 DES_key_schedule *ks2,DES_key_schedule *ks3,
152 DES_cblock *ivec,int enc)
153 {
154 register DES_LONG d0,d1,v0,v1;
155 register unsigned long l=length,n=((unsigned int)numbits+7)/8;
156 register int num=numbits,i;
157 DES_LONG ti[2];
158 unsigned char *iv;
159 unsigned char ovec[16];
160
161 if (num > 64) return;
162 iv = &(*ivec)[0];
163 c2l(iv,v0);
164 c2l(iv,v1);
165 if (enc)
166 {
167 while (l >= n)
168 {
169 l-=n;
170 ti[0]=v0;
171 ti[1]=v1;
172 DES_encrypt3(ti,ks1,ks2,ks3);
173 c2ln(in,d0,d1,n);
174 in+=n;
175 d0^=ti[0];
176 d1^=ti[1];
177 l2cn(d0,d1,out,n);
178 out+=n;
179 /* 30-08-94 - eay - changed because l>>32 and
180 * l<<32 are bad under gcc :-( */
181 if (num == 32)
182 { v0=v1; v1=d0; }
183 else if (num == 64)
184 { v0=d0; v1=d1; }
185 else
186 {
187 iv=&ovec[0];
188 l2c(v0,iv);
189 l2c(v1,iv);
190 l2c(d0,iv);
191 l2c(d1,iv);
192 /* shift ovec left most of the bits... */
193 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
194 /* now the remaining bits */
195 if(num%8 != 0)
196 for(i=0 ; i < 8 ; ++i)
197 {
198 ovec[i]<<=num%8;
199 ovec[i]|=ovec[i+1]>>(8-num%8);
200 }
201 iv=&ovec[0];
202 c2l(iv,v0);
203 c2l(iv,v1);
204 }
205 }
206 }
207 else
208 {
209 while (l >= n)
210 {
211 l-=n;
212 ti[0]=v0;
213 ti[1]=v1;
214 DES_encrypt3(ti,ks1,ks2,ks3);
215 c2ln(in,d0,d1,n);
216 in+=n;
217 /* 30-08-94 - eay - changed because l>>32 and
218 * l<<32 are bad under gcc :-( */
219 if (num == 32)
220 { v0=v1; v1=d0; }
221 else if (num == 64)
222 { v0=d0; v1=d1; }
223 else
224 {
225 iv=&ovec[0];
226 l2c(v0,iv);
227 l2c(v1,iv);
228 l2c(d0,iv);
229 l2c(d1,iv);
230 /* shift ovec left most of the bits... */
231 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
232 /* now the remaining bits */
233 if(num%8 != 0)
234 for(i=0 ; i < 8 ; ++i)
235 {
236 ovec[i]<<=num%8;
237 ovec[i]|=ovec[i+1]>>(8-num%8);
238 }
239 iv=&ovec[0];
240 c2l(iv,v0);
241 c2l(iv,v1);
242 }
243 d0^=ti[0];
244 d1^=ti[1];
245 l2cn(d0,d1,out,n);
246 out+=n;
247 }
248 }
249 iv = &(*ivec)[0];
250 l2c(v0,iv);
251 l2c(v1,iv);
252 v0=v1=d0=d1=ti[0]=ti[1]=0;
253 }
254
diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c
new file mode 100644
index 0000000000..5ec8683e40
--- /dev/null
+++ b/src/lib/libcrypto/des/cfb64enc.c
@@ -0,0 +1,121 @@
1/* crypto/des/cfb64enc.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/* The input and output encrypted as though 64bit cfb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65
66void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
67 long length, DES_key_schedule *schedule,
68 DES_cblock *ivec, int *num, int enc)
69 {
70 register DES_LONG v0,v1;
71 register long l=length;
72 register int n= *num;
73 DES_LONG ti[2];
74 unsigned char *iv,c,cc;
75
76 iv = &(*ivec)[0];
77 if (enc)
78 {
79 while (l--)
80 {
81 if (n == 0)
82 {
83 c2l(iv,v0); ti[0]=v0;
84 c2l(iv,v1); ti[1]=v1;
85 DES_encrypt1(ti,schedule,DES_ENCRYPT);
86 iv = &(*ivec)[0];
87 v0=ti[0]; l2c(v0,iv);
88 v0=ti[1]; l2c(v0,iv);
89 iv = &(*ivec)[0];
90 }
91 c= *(in++)^iv[n];
92 *(out++)=c;
93 iv[n]=c;
94 n=(n+1)&0x07;
95 }
96 }
97 else
98 {
99 while (l--)
100 {
101 if (n == 0)
102 {
103 c2l(iv,v0); ti[0]=v0;
104 c2l(iv,v1); ti[1]=v1;
105 DES_encrypt1(ti,schedule,DES_ENCRYPT);
106 iv = &(*ivec)[0];
107 v0=ti[0]; l2c(v0,iv);
108 v0=ti[1]; l2c(v0,iv);
109 iv = &(*ivec)[0];
110 }
111 cc= *(in++);
112 c=iv[n];
113 iv[n]=cc;
114 *(out++)=c^cc;
115 n=(n+1)&0x07;
116 }
117 }
118 v0=v1=ti[0]=ti[1]=c=cc=0;
119 *num=n;
120 }
121
diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c
new file mode 100644
index 0000000000..720f29a28e
--- /dev/null
+++ b/src/lib/libcrypto/des/cfb_enc.c
@@ -0,0 +1,195 @@
1/* crypto/des/cfb_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 "e_os.h"
60#include "des_locl.h"
61#include <assert.h>
62
63/* The input and output are loaded in multiples of 8 bits.
64 * What this means is that if you hame numbits=12 and length=2
65 * the first 12 bits will be retrieved from the first byte and half
66 * the second. The second 12 bits will come from the 3rd and half the 4th
67 * byte.
68 */
69/* Until Aug 1 2003 this function did not correctly implement CFB-r, so it
70 * will not be compatible with any encryption prior to that date. Ben. */
71void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
72 long length, DES_key_schedule *schedule, DES_cblock *ivec,
73 int enc)
74 {
75 register DES_LONG d0,d1,v0,v1;
76 register unsigned long l=length;
77 register int num=numbits/8,n=(numbits+7)/8,i,rem=numbits%8;
78 DES_LONG ti[2];
79 unsigned char *iv;
80#ifndef L_ENDIAN
81 unsigned char ovec[16];
82#else
83 unsigned int sh[4];
84 unsigned char *ovec=(unsigned char *)sh;
85
86 /* I kind of count that compiler optimizes away this assertioni,*/
87 assert (sizeof(sh[0])==4); /* as this holds true for all, */
88 /* but 16-bit platforms... */
89
90#endif
91
92 if (numbits<=0 || numbits > 64) return;
93 iv = &(*ivec)[0];
94 c2l(iv,v0);
95 c2l(iv,v1);
96 if (enc)
97 {
98 while (l >= (unsigned long)n)
99 {
100 l-=n;
101 ti[0]=v0;
102 ti[1]=v1;
103 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
104 c2ln(in,d0,d1,n);
105 in+=n;
106 d0^=ti[0];
107 d1^=ti[1];
108 l2cn(d0,d1,out,n);
109 out+=n;
110 /* 30-08-94 - eay - changed because l>>32 and
111 * l<<32 are bad under gcc :-( */
112 if (numbits == 32)
113 { v0=v1; v1=d0; }
114 else if (numbits == 64)
115 { v0=d0; v1=d1; }
116 else
117 {
118#ifndef L_ENDIAN
119 iv=&ovec[0];
120 l2c(v0,iv);
121 l2c(v1,iv);
122 l2c(d0,iv);
123 l2c(d1,iv);
124#else
125 sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1;
126#endif
127 if (rem==0)
128 memmove(ovec,ovec+num,8);
129 else
130 for(i=0 ; i < 8 ; ++i)
131 ovec[i]=ovec[i+num]<<rem |
132 ovec[i+num+1]>>(8-rem);
133#ifdef L_ENDIAN
134 v0=sh[0], v1=sh[1];
135#else
136 iv=&ovec[0];
137 c2l(iv,v0);
138 c2l(iv,v1);
139#endif
140 }
141 }
142 }
143 else
144 {
145 while (l >= (unsigned long)n)
146 {
147 l-=n;
148 ti[0]=v0;
149 ti[1]=v1;
150 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
151 c2ln(in,d0,d1,n);
152 in+=n;
153 /* 30-08-94 - eay - changed because l>>32 and
154 * l<<32 are bad under gcc :-( */
155 if (numbits == 32)
156 { v0=v1; v1=d0; }
157 else if (numbits == 64)
158 { v0=d0; v1=d1; }
159 else
160 {
161#ifndef L_ENDIAN
162 iv=&ovec[0];
163 l2c(v0,iv);
164 l2c(v1,iv);
165 l2c(d0,iv);
166 l2c(d1,iv);
167#else
168 sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1;
169#endif
170 if (rem==0)
171 memmove(ovec,ovec+num,8);
172 else
173 for(i=0 ; i < 8 ; ++i)
174 ovec[i]=ovec[i+num]<<rem |
175 ovec[i+num+1]>>(8-rem);
176#ifdef L_ENDIAN
177 v0=sh[0], v1=sh[1];
178#else
179 iv=&ovec[0];
180 c2l(iv,v0);
181 c2l(iv,v1);
182#endif
183 }
184 d0^=ti[0];
185 d1^=ti[1];
186 l2cn(d0,d1,out,n);
187 out+=n;
188 }
189 }
190 iv = &(*ivec)[0];
191 l2c(v0,iv);
192 l2c(v1,iv);
193 v0=v1=d0=d1=ti[0]=ti[1]=0;
194 }
195
diff --git a/src/lib/libcrypto/des/des-lib.com b/src/lib/libcrypto/des/des-lib.com
new file mode 100644
index 0000000000..fc2c35a1ce
--- /dev/null
+++ b/src/lib/libcrypto/des/des-lib.com
@@ -0,0 +1,1003 @@
1$!
2$! DES-LIB.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$! Changes by Richard Levitte <richard@levitte.org>
9$!
10$! This command files compiles and creates the
11$! "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" library. The "xxx" denotes the machine
12$! architecture of AXP or VAX.
13$!
14$! It was re-written to try to determine which "C" compiler to try to use
15$! or the user can specify a compiler in P3.
16$!
17$! Specify one of the following to build just that part, specify "ALL" to
18$! just build everything.
19$!
20$! ALL To Just Build "Everything".
21$! LIBRARY To Just Build The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library.
22$! DESTEST To Just Build The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program.
23$! SPEED To Just Build The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program.
24$! RPW To Just Build The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program.
25$! DES To Just Build The [.xxx.EXE.CRYPTO.DES]DES.EXE Program.
26$! DES_OPTS To Just Build The [.xxx.EXE.CRYPTO.DES]DES_OPTS.EXE Program.
27$!
28$! Specify either DEBUG or NODEBUG as P2 to compile with or without
29$! debugging information.
30$!
31$! Specify which compiler at P3 to try to compile under.
32$!
33$! VAXC For VAX C.
34$! DECC For DEC C.
35$! GNUC For GNU C.
36$!
37$! If you don't speficy a compiler, it will try to determine which
38$! "C" compiler to try to use.
39$!
40$! P4, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
41$!
42$!
43$! Make sure we know what architecture we run on.
44$!
45$!
46$! Check Which Architecture We Are Using.
47$!
48$ IF (F$GETSYI("CPU").GE.128)
49$ THEN
50$!
51$! The Architecture Is AXP.
52$!
53$ ARCH := AXP
54$!
55$! Else...
56$!
57$ ELSE
58$!
59$! The Architecture Is VAX.
60$!
61$ ARCH := VAX
62$!
63$! End The Architecture Check.
64$!
65$ ENDIF
66$!
67$! Check To Make Sure We Have Valid Command Line Parameters.
68$!
69$ GOSUB CHECK_OPTIONS
70$!
71$! Tell The User What Kind of Machine We Run On.
72$!
73$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
74$!
75$! Define The OBJ Directory Name.
76$!
77$ OBJ_DIR := SYS$DISK:[--.'ARCH'.OBJ.CRYPTO.DES]
78$!
79$! Check To See If The Architecture Specific OBJ Directory Exists.
80$!
81$ IF (F$PARSE(OBJ_DIR).EQS."")
82$ THEN
83$!
84$! It Dosen't Exist, So Create It.
85$!
86$ CREATE/DIR 'OBJ_DIR'
87$!
88$! End The Architecture Specific OBJ Directory Check.
89$!
90$ ENDIF
91$!
92$! Define The EXE Directory Name.
93$!
94$ EXE_DIR :== SYS$DISK:[--.'ARCH'.EXE.CRYPTO.DES]
95$!
96$! Check To See If The Architecture Specific Directory Exists.
97$!
98$ IF (F$PARSE(EXE_DIR).EQS."")
99$ THEN
100$!
101$! It Dosen't Exist, So Create It.
102$!
103$ CREATE/DIR 'EXE_DIR'
104$!
105$! End The Architecture Specific Directory Check.
106$!
107$ ENDIF
108$!
109$! Define The Library Name.
110$!
111$ LIB_NAME := 'EXE_DIR'LIBDES.OLB
112$!
113$! Check To See What We Are To Do.
114$!
115$ IF (BUILDALL.EQS."TRUE")
116$ THEN
117$!
118$! Since Nothing Special Was Specified, Do Everything.
119$!
120$ GOSUB LIBRARY
121$ GOSUB DESTEST
122$ GOSUB SPEED
123$ GOSUB RPW
124$ GOSUB DES
125$ GOSUB DES_OPTS
126$!
127$! Else...
128$!
129$ ELSE
130$!
131$! Build Just What The User Wants Us To Build.
132$!
133$ GOSUB 'BUILDALL'
134$!
135$! End The BUILDALL Check.
136$!
137$ ENDIF
138$!
139$! Time To EXIT.
140$!
141$ EXIT
142$ LIBRARY:
143$!
144$! Tell The User That We Are Compiling.
145$!
146$ WRITE SYS$OUTPUT "Compiling The ",LIB_NAME," Files."
147$!
148$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" Library...
149$!
150$ IF (F$SEARCH(LIB_NAME).EQS."")
151$ THEN
152$!
153$! Guess Not, Create The Library.
154$!
155$ LIBRARY/CREATE/OBJECT 'LIB_NAME'
156$!
157$! End The Library Exist Check.
158$!
159$ ENDIF
160$!
161$! Define The DES Library Files.
162$!
163$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ -
164 "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ -
165 "enc_read,enc_writ,ofb64enc,"+ -
166 "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ -
167 "des_enc,fcrypt_b,read2pwd,"+ -
168 "fcrypt,xcbc_enc,read_pwd,rpc_enc,cbc_cksm,supp"
169$!
170$! Define A File Counter And Set It To "0".
171$!
172$ FILE_COUNTER = 0
173$!
174$! Top Of The File Loop.
175$!
176$ NEXT_FILE:
177$!
178$! O.K, Extract The File Name From The File List.
179$!
180$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",LIB_DES)
181$!
182$! Check To See If We Are At The End Of The File List.
183$!
184$ IF (FILE_NAME.EQS.",") THEN GOTO FILE_DONE
185$!
186$! Increment The Counter.
187$!
188$ FILE_COUNTER = FILE_COUNTER + 1
189$!
190$! Create The Source File Name.
191$!
192$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME + ".C"
193$!
194$! Tell The User We Are Compiling The Source File.
195$!
196$ WRITE SYS$OUTPUT " ",FILE_NAME,".C"
197$!
198$! Create The Object File Name.
199$!
200$ OBJECT_FILE = OBJ_DIR + FILE_NAME + "." + ARCH + "OBJ"
201$ ON WARNING THEN GOTO NEXT_FILE
202$!
203$! Check To See If The File We Want To Compile Actually Exists.
204$!
205$ IF (F$SEARCH(SOURCE_FILE).EQS."")
206$ THEN
207$!
208$! Tell The User That The File Dosen't Exist.
209$!
210$ WRITE SYS$OUTPUT ""
211$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
212$ WRITE SYS$OUTPUT ""
213$!
214$! Exit The Build.
215$!
216$ EXIT
217$!
218$! End The File Exists Check.
219$!
220$ ENDIF
221$!
222$! Compile The File.
223$!
224$ ON ERROR THEN GOTO NEXT_FILE
225$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
226$!
227$! Add It To The Library.
228$!
229$ LIBRARY/REPLACE/OBJECT 'LIB_NAME' 'OBJECT_FILE'
230$!
231$! Time To Clean Up The Object File.
232$!
233$ DELETE 'OBJECT_FILE';*
234$!
235$! Go Back And Do It Again.
236$!
237$ GOTO NEXT_FILE
238$!
239$! All Done With This Library Part.
240$!
241$ FILE_DONE:
242$!
243$! Tell The User That We Are All Done.
244$!
245$ WRITE SYS$OUTPUT "Library ",LIB_NAME," Built."
246$!
247$! All Done, Time To Return.
248$!
249$ RETURN
250$!
251$! Compile The DESTEST Program.
252$!
253$ DESTEST:
254$!
255$! Check To See If We Have The Proper Libraries.
256$!
257$ GOSUB LIB_CHECK
258$!
259$! Check To See If We Have A Linker Option File.
260$!
261$ GOSUB CHECK_OPT_FILE
262$!
263$! Check To See If The File We Want To Compile Actually Exists.
264$!
265$ IF (F$SEARCH("SYS$DISK:[]DESTEST.C").EQS."")
266$ THEN
267$!
268$! Tell The User That The File Dosen't Exist.
269$!
270$ WRITE SYS$OUTPUT ""
271$ WRITE SYS$OUTPUT "The File DESTEST.C Dosen't Exist."
272$ WRITE SYS$OUTPUT ""
273$!
274$! Exit The Build.
275$!
276$ EXIT
277$!
278$! End The DESTEST.C File Check.
279$!
280$ ENDIF
281$!
282$! Tell The User What We Are Building.
283$!
284$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DESTEST.EXE"
285$!
286$! Compile The DESTEST Program.
287$!
288$ CC/OBJECT='OBJ_DIR'DESTEST.OBJ SYS$DISK:[]DESTEST.C
289$!
290$! Link The DESTEST Program.
291$!
292$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DESTEST.EXE -
293 'OBJ_DIR'DESTEST.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
294$!
295$! All Done, Time To Return.
296$!
297$ RETURN
298$!
299$! Compile The SPEED Program.
300$!
301$ SPEED:
302$!
303$! Check To See If We Have The Proper Libraries.
304$!
305$ GOSUB LIB_CHECK
306$!
307$! Check To See If We Have A Linker Option File.
308$!
309$ GOSUB CHECK_OPT_FILE
310$!
311$! Check To See If The File We Want To Compile Actually Exists.
312$!
313$ IF (F$SEARCH("SYS$DISK:[]SPEED.C").EQS."")
314$ THEN
315$!
316$! Tell The User That The File Dosen't Exist.
317$!
318$ WRITE SYS$OUTPUT ""
319$ WRITE SYS$OUTPUT "The File SPEED.C Dosen't Exist."
320$ WRITE SYS$OUTPUT ""
321$!
322$! Exit The Build.
323$!
324$ EXIT
325$!
326$! End The SPEED.C File Check.
327$!
328$ ENDIF
329$!
330$! Tell The User What We Are Building.
331$!
332$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"SPEED.EXE"
333$!
334$! Compile The SPEED Program.
335$!
336$ CC/OBJECT='OBJ_DIR'SPEED.OBJ SYS$DISK:[]SPEED.C
337$!
338$! Link The SPEED Program.
339$!
340$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'SPEED.EXE -
341 'OBJ_DIR'SPEED.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
342$!
343$! All Done, Time To Return.
344$!
345$ RETURN
346$!
347$! Compile The RPW Program.
348$!
349$ RPW:
350$!
351$! Check To See If We Have The Proper Libraries.
352$!
353$ GOSUB LIB_CHECK
354$!
355$! Check To See If We Have A Linker Option File.
356$!
357$ GOSUB CHECK_OPT_FILE
358$!
359$! Check To See If The File We Want To Compile Actually Exists.
360$!
361$ IF (F$SEARCH("SYS$DISK:[]RPW.C").EQS."")
362$ THEN
363$!
364$! Tell The User That The File Dosen't Exist.
365$!
366$ WRITE SYS$OUTPUT ""
367$ WRITE SYS$OUTPUT "The File RPW.C Dosen't Exist."
368$ WRITE SYS$OUTPUT ""
369$!
370$! Exit The Build.
371$!
372$ EXIT
373$!
374$! End The RPW.C File Check.
375$!
376$ ENDIF
377$!
378$! Tell The User What We Are Building.
379$!
380$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"RPW.EXE"
381$!
382$! Compile The RPW Program.
383$!
384$ CC/OBJECT='OBJ_DIR'RPW.OBJ SYS$DISK:[]RPW.C
385$!
386$! Link The RPW Program.
387$!
388$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'RPW.EXE -
389 'OBJ_DIR'RPW.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
390$!
391$! All Done, Time To Return.
392$!
393$ RETURN
394$!
395$! Compile The DES Program.
396$!
397$ DES:
398$!
399$! Check To See If We Have The Proper Libraries.
400$!
401$ GOSUB LIB_CHECK
402$!
403$! Check To See If We Have A Linker Option File.
404$!
405$ GOSUB CHECK_OPT_FILE
406$!
407$! Check To See If The File We Want To Compile Actually Exists.
408$!
409$ IF (F$SEARCH("SYS$DISK:[]DES.C").EQS."")
410$ THEN
411$!
412$! Tell The User That The File Dosen't Exist.
413$!
414$ WRITE SYS$OUTPUT ""
415$ WRITE SYS$OUTPUT "The File DES.C Dosen't Exist."
416$ WRITE SYS$OUTPUT ""
417$!
418$! Exit The Build.
419$!
420$ EXIT
421$!
422$! End The DES.C File Check.
423$!
424$ ENDIF
425$!
426$! Tell The User What We Are Building.
427$!
428$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES.EXE"
429$!
430$! Compile The DES Program.
431$!
432$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]DES.C
433$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]CBC3_ENC.C
434$!
435$! Link The DES Program.
436$!
437$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES.EXE -
438 'OBJ_DIR'DES.OBJ,'OBJ_DIR'CBC3_ENC.OBJ,-
439 'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
440$!
441$! All Done, Time To Return.
442$!
443$ RETURN
444$!
445$! Compile The DES_OPTS Program.
446$!
447$ DES_OPTS:
448$!
449$! Check To See If We Have The Proper Libraries.
450$!
451$ GOSUB LIB_CHECK
452$!
453$! Check To See If We Have A Linker Option File.
454$!
455$ GOSUB CHECK_OPT_FILE
456$!
457$! Check To See If The File We Want To Compile Actually Exists.
458$!
459$ IF (F$SEARCH("SYS$DISK:[]DES_OPTS.C").EQS."")
460$ THEN
461$!
462$! Tell The User That The File Dosen't Exist.
463$!
464$ WRITE SYS$OUTPUT ""
465$ WRITE SYS$OUTPUT "The File DES_OPTS.C Dosen't Exist."
466$ WRITE SYS$OUTPUT ""
467$!
468$! Exit The Build.
469$!
470$ EXIT
471$!
472$! End The DES_OPTS.C File Check.
473$!
474$ ENDIF
475$!
476$! Tell The User What We Are Building.
477$!
478$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES_OPTS.EXE"
479$!
480$! Compile The DES_OPTS Program.
481$!
482$ CC/OBJECT='OBJ_DIR'DES_OPTS.OBJ SYS$DISK:[]DES_OPTS.C
483$!
484$! Link The DES_OPTS Program.
485$!
486$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES_OPTS.EXE -
487 'OBJ_DIR'DES_OPTS.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
488$!
489$! All Done, Time To Return.
490$!
491$ RETURN
492$ EXIT
493$!
494$! Check For The Link Option FIle.
495$!
496$ CHECK_OPT_FILE:
497$!
498$! Check To See If We Need To Make A VAX C Option File.
499$!
500$ IF (COMPILER.EQS."VAXC")
501$ THEN
502$!
503$! Check To See If We Already Have A VAX C Linker Option File.
504$!
505$ IF (F$SEARCH(OPT_FILE).EQS."")
506$ THEN
507$!
508$! We Need A VAX C Linker Option File.
509$!
510$ CREATE 'OPT_FILE'
511$DECK
512!
513! Default System Options File To Link Agianst
514! The Sharable VAX C Runtime Library.
515!
516SYS$SHARE:VAXCRTL.EXE/SHARE
517$EOD
518$!
519$! End The Option File Check.
520$!
521$ ENDIF
522$!
523$! End The VAXC Check.
524$!
525$ ENDIF
526$!
527$! Check To See If We Need A GNU C Option File.
528$!
529$ IF (COMPILER.EQS."GNUC")
530$ THEN
531$!
532$! Check To See If We Already Have A GNU C Linker Option File.
533$!
534$ IF (F$SEARCH(OPT_FILE).EQS."")
535$ THEN
536$!
537$! We Need A GNU C Linker Option File.
538$!
539$ CREATE 'OPT_FILE'
540$DECK
541!
542! Default System Options File To Link Agianst
543! The Sharable C Runtime Library.
544!
545GNU_CC:[000000]GCCLIB/LIBRARY
546SYS$SHARE:VAXCRTL/SHARE
547$EOD
548$!
549$! End The Option File Check.
550$!
551$ ENDIF
552$!
553$! End The GNU C Check.
554$!
555$ ENDIF
556$!
557$! Check To See If We Need A DEC C Option File.
558$!
559$ IF (COMPILER.EQS."DECC")
560$ THEN
561$!
562$! Check To See If We Already Have A DEC C Linker Option File.
563$!
564$ IF (F$SEARCH(OPT_FILE).EQS."")
565$ THEN
566$!
567$! Figure Out If We Need An AXP Or A VAX Linker Option File.
568$!
569$ IF (F$GETSYI("CPU").LT.128)
570$ THEN
571$!
572$! We Need A DEC C Linker Option File For VAX.
573$!
574$ CREATE 'OPT_FILE'
575$DECK
576!
577! Default System Options File To Link Agianst
578! The Sharable DEC C Runtime Library.
579!
580SYS$SHARE:DECC$SHR.EXE/SHARE
581$EOD
582$!
583$! Else...
584$!
585$ ELSE
586$!
587$! Create The AXP Linker Option File.
588$!
589$ CREATE 'OPT_FILE'
590$DECK
591!
592! Default System Options File For AXP To Link Agianst
593! The Sharable C Runtime Library.
594!
595SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
596SYS$SHARE:CMA$OPEN_RTL/SHARE
597$EOD
598$!
599$! End The VAX/AXP DEC C Option File Check.
600$!
601$ ENDIF
602$!
603$! End The Option File Search.
604$!
605$ ENDIF
606$!
607$! End The DEC C Check.
608$!
609$ ENDIF
610$!
611$! Tell The User What Linker Option File We Are Using.
612$!
613$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
614$!
615$! Time To RETURN.
616$!
617$ RETURN
618$!
619$! Library Check.
620$!
621$ LIB_CHECK:
622$!
623$! Look For The Library LIBDES.OLB.
624$!
625$ IF (F$SEARCH(LIB_NAME).EQS."")
626$ THEN
627$!
628$! Tell The User We Can't Find The [.xxx.CRYPTO.DES]LIBDES.OLB Library.
629$!
630$ WRITE SYS$OUTPUT ""
631$ WRITE SYS$OUTPUT "Can't Find The Library ",LIB_NAME,"."
632$ WRITE SYS$OUTPUT "We Can't Link Without It."
633$ WRITE SYS$OUTPUT ""
634$!
635$! Since We Can't Link Without It, Exit.
636$!
637$ EXIT
638$ ENDIF
639$!
640$! Time To Return.
641$!
642$ RETURN
643$!
644$! Check The User's Options.
645$!
646$ CHECK_OPTIONS:
647$!
648$! Check To See If We Are To "Just Build Everything".
649$!
650$ IF (P1.EQS."ALL")
651$ THEN
652$!
653$! P1 Is "ALL", So Build Everything.
654$!
655$ BUILDALL = "TRUE"
656$!
657$! Else...
658$!
659$ ELSE
660$!
661$! Else, Check To See If P1 Has A Valid Arguement.
662$!
663$ IF (P1.EQS."LIBRARY").OR.(P1.EQS."DESTEST").OR.(P1.EQS."SPEED") -
664 .OR.(P1.EQS."RPW").OR.(P1.EQS."DES").OR.(P1.EQS."DES_OPTS")
665$ THEN
666$!
667$! A Valid Arguement.
668$!
669$ BUILDALL = P1
670$!
671$! Else...
672$!
673$ ELSE
674$!
675$! Tell The User We Don't Know What They Want.
676$!
677$ WRITE SYS$OUTPUT ""
678$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
679$ WRITE SYS$OUTPUT ""
680$ WRITE SYS$OUTPUT " ALL : Just Build Everything.
681$ WRITE SYS$OUTPUT " LIBRARY : To Compile Just The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library."
682$ WRITE SYS$OUTPUT " DESTEST : To Compile Just The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program."
683$ WRITE SYS$OUTPUT " SPEED : To Compile Just The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program."
684$ WRITE SYS$OUTPUT " RPW : To Compile Just The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program."
685$ WRITE SYS$OUTPUT " DES : To Compile Just The [.xxx.EXE.CRYPTO.DES]DES.EXE Program."
686$ WRITE SYS$OUTPUT " DES_OPTS : To Compile Just The [.xxx.EXE.CRYTPO.DES]DES_OPTS.EXE Program."
687$ WRITE SYS$OUTPUT ""
688$ WRITE SYS$OUTPUT " Where 'xxx' Stands For: "
689$ WRITE SYS$OUTPUT ""
690$ WRITE SYS$OUTPUT " AXP : Alpha Architecture."
691$ WRITE SYS$OUTPUT " VAX : VAX Architecture."
692$ WRITE SYS$OUTPUT ""
693$!
694$! Time To EXIT.
695$!
696$ EXIT
697$!
698$! End The Valid Arguement Check.
699$!
700$ ENDIF
701$!
702$! End The P1 Check.
703$!
704$ ENDIF
705$!
706$! Check To See If We Are To Compile Without Debugger Information.
707$!
708$ IF (P2.EQS."NODEBUG")
709$ THEN
710$!
711$! P2 Is Blank, So Compile Without Debugger Information.
712$!
713$ DEBUGGER = "NODEBUG"
714$ TRACEBACK = "NOTRACEBACK"
715$ GCC_OPTIMIZE = "OPTIMIZE"
716$ CC_OPTIMIZE = "OPTIMIZE"
717$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
718$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
719$!
720$! Else...
721$!
722$ ELSE
723$!
724$! Check To See If We Are To Compile With Debugger Information.
725$!
726$ IF (P2.EQS."DEBUG")
727$ THEN
728$!
729$! Compile With Debugger Information.
730$!
731$ DEBUGGER = "DEBUG"
732$ TRACEBACK = "TRACEBACK"
733$ GCC_OPTIMIZE = "NOOPTIMIZE"
734$ CC_OPTIMIZE = "NOOPTIMIZE"
735$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
736$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
737$!
738$! Else...
739$!
740$ ELSE
741$!
742$! Tell The User Entered An Invalid Option..
743$!
744$ WRITE SYS$OUTPUT ""
745$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
746$ WRITE SYS$OUTPUT ""
747$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
748$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
749$ WRITE SYS$OUTPUT ""
750$!
751$! Time To EXIT.
752$!
753$ EXIT
754$!
755$! End The Valid Arguement Check.
756$!
757$ ENDIF
758$!
759$! End The P2 Check.
760$!
761$ ENDIF
762$!
763$! Special Threads For OpenVMS v7.1 Or Later.
764$!
765$! Written By: Richard Levitte
766$! richard@levitte.org
767$!
768$!
769$! Check To See If We Have A Option For P4.
770$!
771$ IF (P4.EQS."")
772$ THEN
773$!
774$! Get The Version Of VMS We Are Using.
775$!
776$ ISSEVEN := ""
777$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
778$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
779$!
780$! Check To See If The VMS Version Is v7.1 Or Later.
781$!
782$ IF (TMP.GE.71)
783$ THEN
784$!
785$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
786$!
787$ ISSEVEN := ,PTHREAD_USE_D4
788$!
789$! End The VMS Version Check.
790$!
791$ ENDIF
792$!
793$! End The P4 Check.
794$!
795$ ENDIF
796$!
797$! Check To See If P3 Is Blank.
798$!
799$ IF (P3.EQS."")
800$ THEN
801$!
802$! O.K., The User Didn't Specify A Compiler, Let's Try To
803$! Find Out Which One To Use.
804$!
805$! Check To See If We Have GNU C.
806$!
807$ IF (F$TRNLNM("GNU_CC").NES."")
808$ THEN
809$!
810$! Looks Like GNUC, Set To Use GNUC.
811$!
812$ P3 = "GNUC"
813$!
814$! Else...
815$!
816$ ELSE
817$!
818$! Check To See If We Have VAXC Or DECC.
819$!
820$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
821$ THEN
822$!
823$! Looks Like DECC, Set To Use DECC.
824$!
825$ P3 = "DECC"
826$!
827$! Else...
828$!
829$ ELSE
830$!
831$! Looks Like VAXC, Set To Use VAXC.
832$!
833$ P3 = "VAXC"
834$!
835$! End The VAXC Compiler Check.
836$!
837$ ENDIF
838$!
839$! End The DECC & VAXC Compiler Check.
840$!
841$ ENDIF
842$!
843$! End The Compiler Check.
844$!
845$ ENDIF
846$!
847$! Set Up Initial CC Definitions, Possibly With User Ones
848$!
849$ CCDEFS = ""
850$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = USER_CCDEFS
851$ CCEXTRAFLAGS = ""
852$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
853$ CCDISABLEWARNINGS = ""
854$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
855 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS
856$!
857$! Check To See If The User Entered A Valid Paramter.
858$!
859$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
860$ THEN
861$!
862$! Check To See If The User Wanted DECC.
863$!
864$ IF (P3.EQS."DECC")
865$ THEN
866$!
867$! Looks Like DECC, Set To Use DECC.
868$!
869$ COMPILER = "DECC"
870$!
871$! Tell The User We Are Using DECC.
872$!
873$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
874$!
875$! Use DECC...
876$!
877$ CC = "CC"
878$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
879 THEN CC = "CC/DECC"
880$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
881 "/NOLIST/PREFIX=ALL" + CCEXTRAFLAGS
882$!
883$! Define The Linker Options File Name.
884$!
885$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
886$!
887$! End DECC Check.
888$!
889$ ENDIF
890$!
891$! Check To See If We Are To Use VAXC.
892$!
893$ IF (P3.EQS."VAXC")
894$ THEN
895$!
896$! Looks Like VAXC, Set To Use VAXC.
897$!
898$ COMPILER = "VAXC"
899$!
900$! Tell The User We Are Using VAX C.
901$!
902$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
903$!
904$! Compile Using VAXC.
905$!
906$ CC = "CC"
907$ IF ARCH.EQS."AXP"
908$ THEN
909$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
910$ EXIT
911$ ENDIF
912$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
913$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
914$ CCDEFS = """VAXC""," + CCDEFS
915$!
916$! Define <sys> As SYS$COMMON:[SYSLIB]
917$!
918$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
919$!
920$! Define The Linker Options File Name.
921$!
922$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
923$!
924$! End VAXC Check
925$!
926$ ENDIF
927$!
928$! Check To See If We Are To Use GNU C.
929$!
930$ IF (P3.EQS."GNUC")
931$ THEN
932$!
933$! Looks Like GNUC, Set To Use GNUC.
934$!
935$ COMPILER = "GNUC"
936$!
937$! Tell The User We Are Using GNUC.
938$!
939$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
940$!
941$! Use GNU C...
942$!
943$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
944$!
945$! Define The Linker Options File Name.
946$!
947$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
948$!
949$! End The GNU C Check.
950$!
951$ ENDIF
952$!
953$! Set up default defines
954$!
955$ CCDEFS = """FLAT_INC=1""," + CCDEFS
956$!
957$! Finish up the definition of CC.
958$!
959$ IF COMPILER .EQS. "DECC"
960$ THEN
961$ IF CCDISABLEWARNINGS .EQS. ""
962$ THEN
963$ CC4DISABLEWARNINGS = "DOLLARID"
964$ ELSE
965$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
966$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
967$ ENDIF
968$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
969$ ELSE
970$ CCDISABLEWARNINGS = ""
971$ CC4DISABLEWARNINGS = ""
972$ ENDIF
973$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
974$!
975$! Show user the result
976$!
977$ WRITE SYS$OUTPUT "Main Compiling Command: ",CC
978$!
979$! Else The User Entered An Invalid Arguement.
980$!
981$ ELSE
982$!
983$! Tell The User We Don't Know What They Want.
984$!
985$ WRITE SYS$OUTPUT ""
986$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
987$ WRITE SYS$OUTPUT ""
988$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
989$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
990$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
991$ WRITE SYS$OUTPUT ""
992$!
993$! Time To EXIT.
994$!
995$ EXIT
996$!
997$! End The P3 Check.
998$!
999$ ENDIF
1000$!
1001$! Time To RETURN...
1002$!
1003$ RETURN
diff --git a/src/lib/libcrypto/des/des.c b/src/lib/libcrypto/des/des.c
new file mode 100644
index 0000000000..343135ff9e
--- /dev/null
+++ b/src/lib/libcrypto/des/des.c
@@ -0,0 +1,932 @@
1/* crypto/des/des.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <openssl/opensslconf.h>
63#ifndef OPENSSL_SYS_MSDOS
64#ifndef OPENSSL_SYS_VMS
65#include OPENSSL_UNISTD
66#else /* OPENSSL_SYS_VMS */
67#ifdef __DECC
68#include <unistd.h>
69#else /* not __DECC */
70#include <math.h>
71#endif /* __DECC */
72#endif /* OPENSSL_SYS_VMS */
73#else /* OPENSSL_SYS_MSDOS */
74#include <io.h>
75#endif
76
77#include <time.h>
78#include "des_ver.h"
79
80#ifdef OPENSSL_SYS_VMS
81#include <types.h>
82#include <stat.h>
83#else
84#ifndef _IRIX
85#include <sys/types.h>
86#endif
87#include <sys/stat.h>
88#endif
89#include <openssl/des.h>
90#include <openssl/rand.h>
91#include <openssl/ui_compat.h>
92
93void usage(void);
94void doencryption(void);
95int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp);
96void uufwriteEnd(FILE *fp);
97int uufread(unsigned char *out,int size,unsigned int num,FILE *fp);
98int uuencode(unsigned char *in,int num,unsigned char *out);
99int uudecode(unsigned char *in,int num,unsigned char *out);
100void DES_3cbc_encrypt(DES_cblock *input,DES_cblock *output,long length,
101 DES_key_schedule sk1,DES_key_schedule sk2,
102 DES_cblock *ivec1,DES_cblock *ivec2,int enc);
103#ifdef OPENSSL_SYS_VMS
104#define EXIT(a) exit(a&0x10000000L)
105#else
106#define EXIT(a) exit(a)
107#endif
108
109#define BUFSIZE (8*1024)
110#define VERIFY 1
111#define KEYSIZ 8
112#define KEYSIZB 1024 /* should hit tty line limit first :-) */
113char key[KEYSIZB+1];
114int do_encrypt,longk=0;
115FILE *DES_IN,*DES_OUT,*CKSUM_OUT;
116char uuname[200];
117unsigned char uubuf[50];
118int uubufnum=0;
119#define INUUBUFN (45*100)
120#define OUTUUBUF (65*100)
121unsigned char b[OUTUUBUF];
122unsigned char bb[300];
123DES_cblock cksum={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
124char cksumname[200]="";
125
126int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error;
127
128int main(int argc, char **argv)
129 {
130 int i;
131 struct stat ins,outs;
132 char *p;
133 char *in=NULL,*out=NULL;
134
135 vflag=cflag=eflag=dflag=kflag=hflag=bflag=fflag=sflag=uflag=flag3=0;
136 error=0;
137 memset(key,0,sizeof(key));
138
139 for (i=1; i<argc; i++)
140 {
141 p=argv[i];
142 if ((p[0] == '-') && (p[1] != '\0'))
143 {
144 p++;
145 while (*p)
146 {
147 switch (*(p++))
148 {
149 case '3':
150 flag3=1;
151 longk=1;
152 break;
153 case 'c':
154 cflag=1;
155 strncpy(cksumname,p,200);
156 cksumname[sizeof(cksumname)-1]='\0';
157 p+=strlen(cksumname);
158 break;
159 case 'C':
160 cflag=1;
161 longk=1;
162 strncpy(cksumname,p,200);
163 cksumname[sizeof(cksumname)-1]='\0';
164 p+=strlen(cksumname);
165 break;
166 case 'e':
167 eflag=1;
168 break;
169 case 'v':
170 vflag=1;
171 break;
172 case 'E':
173 eflag=1;
174 longk=1;
175 break;
176 case 'd':
177 dflag=1;
178 break;
179 case 'D':
180 dflag=1;
181 longk=1;
182 break;
183 case 'b':
184 bflag=1;
185 break;
186 case 'f':
187 fflag=1;
188 break;
189 case 's':
190 sflag=1;
191 break;
192 case 'u':
193 uflag=1;
194 strncpy(uuname,p,200);
195 uuname[sizeof(uuname)-1]='\0';
196 p+=strlen(uuname);
197 break;
198 case 'h':
199 hflag=1;
200 break;
201 case 'k':
202 kflag=1;
203 if ((i+1) == argc)
204 {
205 fputs("must have a key with the -k option\n",stderr);
206 error=1;
207 }
208 else
209 {
210 int j;
211
212 i++;
213 strncpy(key,argv[i],KEYSIZB);
214 for (j=strlen(argv[i])-1; j>=0; j--)
215 argv[i][j]='\0';
216 }
217 break;
218 default:
219 fprintf(stderr,"'%c' unknown flag\n",p[-1]);
220 error=1;
221 break;
222 }
223 }
224 }
225 else
226 {
227 if (in == NULL)
228 in=argv[i];
229 else if (out == NULL)
230 out=argv[i];
231 else
232 error=1;
233 }
234 }
235 if (error) usage();
236 /* We either
237 * do checksum or
238 * do encrypt or
239 * do decrypt or
240 * do decrypt then ckecksum or
241 * do checksum then encrypt
242 */
243 if (((eflag+dflag) == 1) || cflag)
244 {
245 if (eflag) do_encrypt=DES_ENCRYPT;
246 if (dflag) do_encrypt=DES_DECRYPT;
247 }
248 else
249 {
250 if (vflag)
251 {
252#ifndef _Windows
253 fprintf(stderr,"des(1) built with %s\n",libdes_version);
254#endif
255 EXIT(1);
256 }
257 else usage();
258 }
259
260#ifndef _Windows
261 if (vflag) fprintf(stderr,"des(1) built with %s\n",libdes_version);
262#endif
263 if ( (in != NULL) &&
264 (out != NULL) &&
265#ifndef OPENSSL_SYS_MSDOS
266 (stat(in,&ins) != -1) &&
267 (stat(out,&outs) != -1) &&
268 (ins.st_dev == outs.st_dev) &&
269 (ins.st_ino == outs.st_ino))
270#else /* OPENSSL_SYS_MSDOS */
271 (strcmp(in,out) == 0))
272#endif
273 {
274 fputs("input and output file are the same\n",stderr);
275 EXIT(3);
276 }
277
278 if (!kflag)
279 if (des_read_pw_string(key,KEYSIZB+1,"Enter key:",eflag?VERIFY:0))
280 {
281 fputs("password error\n",stderr);
282 EXIT(2);
283 }
284
285 if (in == NULL)
286 DES_IN=stdin;
287 else if ((DES_IN=fopen(in,"r")) == NULL)
288 {
289 perror("opening input file");
290 EXIT(4);
291 }
292
293 CKSUM_OUT=stdout;
294 if (out == NULL)
295 {
296 DES_OUT=stdout;
297 CKSUM_OUT=stderr;
298 }
299 else if ((DES_OUT=fopen(out,"w")) == NULL)
300 {
301 perror("opening output file");
302 EXIT(5);
303 }
304
305#ifdef OPENSSL_SYS_MSDOS
306 /* This should set the file to binary mode. */
307 {
308#include <fcntl.h>
309 if (!(uflag && dflag))
310 setmode(fileno(DES_IN),O_BINARY);
311 if (!(uflag && eflag))
312 setmode(fileno(DES_OUT),O_BINARY);
313 }
314#endif
315
316 doencryption();
317 fclose(DES_IN);
318 fclose(DES_OUT);
319 EXIT(0);
320 }
321
322void usage(void)
323 {
324 char **u;
325 static const char *Usage[]={
326"des <options> [input-file [output-file]]",
327"options:",
328"-v : des(1) version number",
329"-e : encrypt using SunOS compatible user key to DES key conversion.",
330"-E : encrypt ",
331"-d : decrypt using SunOS compatible user key to DES key conversion.",
332"-D : decrypt ",
333"-c[ckname] : generate a cbc_cksum using SunOS compatible user key to",
334" DES key conversion and output to ckname (stdout default,",
335" stderr if data being output on stdout). The checksum is",
336" generated before encryption and after decryption if used",
337" in conjunction with -[eEdD].",
338"-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].",
339"-k key : use key 'key'",
340"-h : the key that is entered will be a hexadecimal number",
341" that is used directly as the des key",
342"-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]",
343" (uuname is the filename to put in the uuencode header).",
344"-b : encrypt using DES in ecb encryption mode, the default is cbc mode.",
345"-3 : encrypt using triple DES encryption. This uses 2 keys",
346" generated from the input key. If the input key is less",
347" than 8 characters long, this is equivalent to normal",
348" encryption. Default is triple cbc, -b makes it triple ecb.",
349NULL
350};
351 for (u=(char **)Usage; *u; u++)
352 {
353 fputs(*u,stderr);
354 fputc('\n',stderr);
355 }
356
357 EXIT(1);
358 }
359
360void doencryption(void)
361 {
362#ifdef _LIBC
363 extern unsigned long time();
364#endif
365
366 register int i;
367 DES_key_schedule ks,ks2;
368 DES_cblock iv,iv2;
369 char *p;
370 int num=0,j,k,l,rem,ll,len,last,ex=0;
371 DES_cblock kk,k2;
372 FILE *O;
373 int Exit=0;
374#ifndef OPENSSL_SYS_MSDOS
375 static unsigned char buf[BUFSIZE+8],obuf[BUFSIZE+8];
376#else
377 static unsigned char *buf=NULL,*obuf=NULL;
378
379 if (buf == NULL)
380 {
381 if ( (( buf=OPENSSL_malloc(BUFSIZE+8)) == NULL) ||
382 ((obuf=OPENSSL_malloc(BUFSIZE+8)) == NULL))
383 {
384 fputs("Not enough memory\n",stderr);
385 Exit=10;
386 goto problems;
387 }
388 }
389#endif
390
391 if (hflag)
392 {
393 j=(flag3?16:8);
394 p=key;
395 for (i=0; i<j; i++)
396 {
397 k=0;
398 if ((*p <= '9') && (*p >= '0'))
399 k=(*p-'0')<<4;
400 else if ((*p <= 'f') && (*p >= 'a'))
401 k=(*p-'a'+10)<<4;
402 else if ((*p <= 'F') && (*p >= 'A'))
403 k=(*p-'A'+10)<<4;
404 else
405 {
406 fputs("Bad hex key\n",stderr);
407 Exit=9;
408 goto problems;
409 }
410 p++;
411 if ((*p <= '9') && (*p >= '0'))
412 k|=(*p-'0');
413 else if ((*p <= 'f') && (*p >= 'a'))
414 k|=(*p-'a'+10);
415 else if ((*p <= 'F') && (*p >= 'A'))
416 k|=(*p-'A'+10);
417 else
418 {
419 fputs("Bad hex key\n",stderr);
420 Exit=9;
421 goto problems;
422 }
423 p++;
424 if (i < 8)
425 kk[i]=k;
426 else
427 k2[i-8]=k;
428 }
429 DES_set_key_unchecked(&k2,&ks2);
430 OPENSSL_cleanse(k2,sizeof(k2));
431 }
432 else if (longk || flag3)
433 {
434 if (flag3)
435 {
436 DES_string_to_2keys(key,&kk,&k2);
437 DES_set_key_unchecked(&k2,&ks2);
438 OPENSSL_cleanse(k2,sizeof(k2));
439 }
440 else
441 DES_string_to_key(key,&kk);
442 }
443 else
444 for (i=0; i<KEYSIZ; i++)
445 {
446 l=0;
447 k=key[i];
448 for (j=0; j<8; j++)
449 {
450 if (k&1) l++;
451 k>>=1;
452 }
453 if (l & 1)
454 kk[i]=key[i]&0x7f;
455 else
456 kk[i]=key[i]|0x80;
457 }
458
459 DES_set_key_unchecked(&kk,&ks);
460 OPENSSL_cleanse(key,sizeof(key));
461 OPENSSL_cleanse(kk,sizeof(kk));
462 /* woops - A bug that does not showup under unix :-( */
463 memset(iv,0,sizeof(iv));
464 memset(iv2,0,sizeof(iv2));
465
466 l=1;
467 rem=0;
468 /* first read */
469 if (eflag || (!dflag && cflag))
470 {
471 for (;;)
472 {
473 num=l=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
474 l+=rem;
475 num+=rem;
476 if (l < 0)
477 {
478 perror("read error");
479 Exit=6;
480 goto problems;
481 }
482
483 rem=l%8;
484 len=l-rem;
485 if (feof(DES_IN))
486 {
487 for (i=7-rem; i>0; i--)
488 RAND_pseudo_bytes(buf + l++, 1);
489 buf[l++]=rem;
490 ex=1;
491 len+=rem;
492 }
493 else
494 l-=rem;
495
496 if (cflag)
497 {
498 DES_cbc_cksum(buf,&cksum,
499 (long)len,&ks,&cksum);
500 if (!eflag)
501 {
502 if (feof(DES_IN)) break;
503 else continue;
504 }
505 }
506
507 if (bflag && !flag3)
508 for (i=0; i<l; i+=8)
509 DES_ecb_encrypt(
510 (DES_cblock *)&(buf[i]),
511 (DES_cblock *)&(obuf[i]),
512 &ks,do_encrypt);
513 else if (flag3 && bflag)
514 for (i=0; i<l; i+=8)
515 DES_ecb2_encrypt(
516 (DES_cblock *)&(buf[i]),
517 (DES_cblock *)&(obuf[i]),
518 &ks,&ks2,do_encrypt);
519 else if (flag3 && !bflag)
520 {
521 char tmpbuf[8];
522
523 if (rem) memcpy(tmpbuf,&(buf[l]),
524 (unsigned int)rem);
525 DES_3cbc_encrypt(
526 (DES_cblock *)buf,(DES_cblock *)obuf,
527 (long)l,ks,ks2,&iv,
528 &iv2,do_encrypt);
529 if (rem) memcpy(&(buf[l]),tmpbuf,
530 (unsigned int)rem);
531 }
532 else
533 {
534 DES_cbc_encrypt(
535 buf,obuf,
536 (long)l,&ks,&iv,do_encrypt);
537 if (l >= 8) memcpy(iv,&(obuf[l-8]),8);
538 }
539 if (rem) memcpy(buf,&(buf[l]),(unsigned int)rem);
540
541 i=0;
542 while (i < l)
543 {
544 if (uflag)
545 j=uufwrite(obuf,1,(unsigned int)l-i,
546 DES_OUT);
547 else
548 j=fwrite(obuf,1,(unsigned int)l-i,
549 DES_OUT);
550 if (j == -1)
551 {
552 perror("Write error");
553 Exit=7;
554 goto problems;
555 }
556 i+=j;
557 }
558 if (feof(DES_IN))
559 {
560 if (uflag) uufwriteEnd(DES_OUT);
561 break;
562 }
563 }
564 }
565 else /* decrypt */
566 {
567 ex=1;
568 for (;;)
569 {
570 if (ex) {
571 if (uflag)
572 l=uufread(buf,1,BUFSIZE,DES_IN);
573 else
574 l=fread(buf,1,BUFSIZE,DES_IN);
575 ex=0;
576 rem=l%8;
577 l-=rem;
578 }
579 if (l < 0)
580 {
581 perror("read error");
582 Exit=6;
583 goto problems;
584 }
585
586 if (bflag && !flag3)
587 for (i=0; i<l; i+=8)
588 DES_ecb_encrypt(
589 (DES_cblock *)&(buf[i]),
590 (DES_cblock *)&(obuf[i]),
591 &ks,do_encrypt);
592 else if (flag3 && bflag)
593 for (i=0; i<l; i+=8)
594 DES_ecb2_encrypt(
595 (DES_cblock *)&(buf[i]),
596 (DES_cblock *)&(obuf[i]),
597 &ks,&ks2,do_encrypt);
598 else if (flag3 && !bflag)
599 {
600 DES_3cbc_encrypt(
601 (DES_cblock *)buf,(DES_cblock *)obuf,
602 (long)l,ks,ks2,&iv,
603 &iv2,do_encrypt);
604 }
605 else
606 {
607 DES_cbc_encrypt(
608 buf,obuf,
609 (long)l,&ks,&iv,do_encrypt);
610 if (l >= 8) memcpy(iv,&(buf[l-8]),8);
611 }
612
613 if (uflag)
614 ll=uufread(&(buf[rem]),1,BUFSIZE,DES_IN);
615 else
616 ll=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
617 ll+=rem;
618 rem=ll%8;
619 ll-=rem;
620 if (feof(DES_IN) && (ll == 0))
621 {
622 last=obuf[l-1];
623
624 if ((last > 7) || (last < 0))
625 {
626 fputs("The file was not decrypted correctly.\n",
627 stderr);
628 Exit=8;
629 last=0;
630 }
631 l=l-8+last;
632 }
633 i=0;
634 if (cflag) DES_cbc_cksum(obuf,
635 (DES_cblock *)cksum,(long)l/8*8,&ks,
636 (DES_cblock *)cksum);
637 while (i != l)
638 {
639 j=fwrite(obuf,1,(unsigned int)l-i,DES_OUT);
640 if (j == -1)
641 {
642 perror("Write error");
643 Exit=7;
644 goto problems;
645 }
646 i+=j;
647 }
648 l=ll;
649 if ((l == 0) && feof(DES_IN)) break;
650 }
651 }
652 if (cflag)
653 {
654 l=0;
655 if (cksumname[0] != '\0')
656 {
657 if ((O=fopen(cksumname,"w")) != NULL)
658 {
659 CKSUM_OUT=O;
660 l=1;
661 }
662 }
663 for (i=0; i<8; i++)
664 fprintf(CKSUM_OUT,"%02X",cksum[i]);
665 fprintf(CKSUM_OUT,"\n");
666 if (l) fclose(CKSUM_OUT);
667 }
668problems:
669 OPENSSL_cleanse(buf,sizeof(buf));
670 OPENSSL_cleanse(obuf,sizeof(obuf));
671 OPENSSL_cleanse(&ks,sizeof(ks));
672 OPENSSL_cleanse(&ks2,sizeof(ks2));
673 OPENSSL_cleanse(iv,sizeof(iv));
674 OPENSSL_cleanse(iv2,sizeof(iv2));
675 OPENSSL_cleanse(kk,sizeof(kk));
676 OPENSSL_cleanse(k2,sizeof(k2));
677 OPENSSL_cleanse(uubuf,sizeof(uubuf));
678 OPENSSL_cleanse(b,sizeof(b));
679 OPENSSL_cleanse(bb,sizeof(bb));
680 OPENSSL_cleanse(cksum,sizeof(cksum));
681 if (Exit) EXIT(Exit);
682 }
683
684/* We ignore this parameter but it should be > ~50 I believe */
685int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp)
686 {
687 int i,j,left,rem,ret=num;
688 static int start=1;
689
690 if (start)
691 {
692 fprintf(fp,"begin 600 %s\n",
693 (uuname[0] == '\0')?"text.d":uuname);
694 start=0;
695 }
696
697 if (uubufnum)
698 {
699 if (uubufnum+num < 45)
700 {
701 memcpy(&(uubuf[uubufnum]),data,(unsigned int)num);
702 uubufnum+=num;
703 return(num);
704 }
705 else
706 {
707 i=45-uubufnum;
708 memcpy(&(uubuf[uubufnum]),data,(unsigned int)i);
709 j=uuencode((unsigned char *)uubuf,45,b);
710 fwrite(b,1,(unsigned int)j,fp);
711 uubufnum=0;
712 data+=i;
713 num-=i;
714 }
715 }
716
717 for (i=0; i<(((int)num)-INUUBUFN); i+=INUUBUFN)
718 {
719 j=uuencode(&(data[i]),INUUBUFN,b);
720 fwrite(b,1,(unsigned int)j,fp);
721 }
722 rem=(num-i)%45;
723 left=(num-i-rem);
724 if (left)
725 {
726 j=uuencode(&(data[i]),left,b);
727 fwrite(b,1,(unsigned int)j,fp);
728 i+=left;
729 }
730 if (i != num)
731 {
732 memcpy(uubuf,&(data[i]),(unsigned int)rem);
733 uubufnum=rem;
734 }
735 return(ret);
736 }
737
738void uufwriteEnd(FILE *fp)
739 {
740 int j;
741 static const char *end=" \nend\n";
742
743 if (uubufnum != 0)
744 {
745 uubuf[uubufnum]='\0';
746 uubuf[uubufnum+1]='\0';
747 uubuf[uubufnum+2]='\0';
748 j=uuencode(uubuf,uubufnum,b);
749 fwrite(b,1,(unsigned int)j,fp);
750 }
751 fwrite(end,1,strlen(end),fp);
752 }
753
754/* int size: should always be > ~ 60; I actually ignore this parameter :-) */
755int uufread(unsigned char *out, int size, unsigned int num, FILE *fp)
756 {
757 int i,j,tot;
758 static int done=0;
759 static int valid=0;
760 static int start=1;
761
762 if (start)
763 {
764 for (;;)
765 {
766 b[0]='\0';
767 fgets((char *)b,300,fp);
768 if (b[0] == '\0')
769 {
770 fprintf(stderr,"no 'begin' found in uuencoded input\n");
771 return(-1);
772 }
773 if (strncmp((char *)b,"begin ",6) == 0) break;
774 }
775 start=0;
776 }
777 if (done) return(0);
778 tot=0;
779 if (valid)
780 {
781 memcpy(out,bb,(unsigned int)valid);
782 tot=valid;
783 valid=0;
784 }
785 for (;;)
786 {
787 b[0]='\0';
788 fgets((char *)b,300,fp);
789 if (b[0] == '\0') break;
790 i=strlen((char *)b);
791 if ((b[0] == 'e') && (b[1] == 'n') && (b[2] == 'd'))
792 {
793 done=1;
794 while (!feof(fp))
795 {
796 fgets((char *)b,300,fp);
797 }
798 break;
799 }
800 i=uudecode(b,i,bb);
801 if (i < 0) break;
802 if ((i+tot+8) > num)
803 {
804 /* num to copy to make it a multiple of 8 */
805 j=(num/8*8)-tot-8;
806 memcpy(&(out[tot]),bb,(unsigned int)j);
807 tot+=j;
808 memcpy(bb,&(bb[j]),(unsigned int)i-j);
809 valid=i-j;
810 break;
811 }
812 memcpy(&(out[tot]),bb,(unsigned int)i);
813 tot+=i;
814 }
815 return(tot);
816 }
817
818#define ccc2l(c,l) (l =((DES_LONG)(*((c)++)))<<16, \
819 l|=((DES_LONG)(*((c)++)))<< 8, \
820 l|=((DES_LONG)(*((c)++))))
821
822#define l2ccc(l,c) (*((c)++)=(unsigned char)(((l)>>16)&0xff), \
823 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
824 *((c)++)=(unsigned char)(((l) )&0xff))
825
826
827int uuencode(unsigned char *in, int num, unsigned char *out)
828 {
829 int j,i,n,tot=0;
830 DES_LONG l;
831 register unsigned char *p;
832 p=out;
833
834 for (j=0; j<num; j+=45)
835 {
836 if (j+45 > num)
837 i=(num-j);
838 else i=45;
839 *(p++)=i+' ';
840 for (n=0; n<i; n+=3)
841 {
842 ccc2l(in,l);
843 *(p++)=((l>>18)&0x3f)+' ';
844 *(p++)=((l>>12)&0x3f)+' ';
845 *(p++)=((l>> 6)&0x3f)+' ';
846 *(p++)=((l )&0x3f)+' ';
847 tot+=4;
848 }
849 *(p++)='\n';
850 tot+=2;
851 }
852 *p='\0';
853 l=0;
854 return(tot);
855 }
856
857int uudecode(unsigned char *in, int num, unsigned char *out)
858 {
859 int j,i,k;
860 unsigned int n=0,space=0;
861 DES_LONG l;
862 DES_LONG w,x,y,z;
863 unsigned int blank=(unsigned int)'\n'-' ';
864
865 for (j=0; j<num; )
866 {
867 n= *(in++)-' ';
868 if (n == blank)
869 {
870 n=0;
871 in--;
872 }
873 if (n > 60)
874 {
875 fprintf(stderr,"uuencoded line length too long\n");
876 return(-1);
877 }
878 j++;
879
880 for (i=0; i<n; j+=4,i+=3)
881 {
882 /* the following is for cases where spaces are
883 * removed from lines.
884 */
885 if (space)
886 {
887 w=x=y=z=0;
888 }
889 else
890 {
891 w= *(in++)-' ';
892 x= *(in++)-' ';
893 y= *(in++)-' ';
894 z= *(in++)-' ';
895 }
896 if ((w > 63) || (x > 63) || (y > 63) || (z > 63))
897 {
898 k=0;
899 if (w == blank) k=1;
900 if (x == blank) k=2;
901 if (y == blank) k=3;
902 if (z == blank) k=4;
903 space=1;
904 switch (k) {
905 case 1: w=0; in--;
906 case 2: x=0; in--;
907 case 3: y=0; in--;
908 case 4: z=0; in--;
909 break;
910 case 0:
911 space=0;
912 fprintf(stderr,"bad uuencoded data values\n");
913 w=x=y=z=0;
914 return(-1);
915 break;
916 }
917 }
918 l=(w<<18)|(x<<12)|(y<< 6)|(z );
919 l2ccc(l,out);
920 }
921 if (*(in++) != '\n')
922 {
923 fprintf(stderr,"missing nl in uuencoded line\n");
924 w=x=y=z=0;
925 return(-1);
926 }
927 j++;
928 }
929 *out='\0';
930 w=x=y=z=0;
931 return(n);
932 }
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
new file mode 100644
index 0000000000..7318593699
--- /dev/null
+++ b/src/lib/libcrypto/des/des.h
@@ -0,0 +1,247 @@
1/* crypto/des/des.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DES_H
60#define HEADER_DES_H
61
62#include <openssl/e_os2.h> /* OPENSSL_EXTERN, OPENSSL_NO_DES,
63 DES_LONG (via openssl/opensslconf.h */
64
65#ifdef OPENSSL_NO_DES
66#error DES is disabled.
67#endif
68
69#ifdef OPENSSL_BUILD_SHLIBCRYPTO
70# undef OPENSSL_EXTERN
71# define OPENSSL_EXTERN OPENSSL_EXPORT
72#endif
73
74#define des_SPtrans DES_SPtrans
75
76#ifdef __cplusplus
77extern "C" {
78#endif
79
80typedef unsigned char DES_cblock[8];
81typedef /* const */ unsigned char const_DES_cblock[8];
82/* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock *
83 * and const_DES_cblock * are incompatible pointer types. */
84
85typedef struct DES_ks
86 {
87 union
88 {
89 DES_cblock cblock;
90 /* make sure things are correct size on machines with
91 * 8 byte longs */
92 DES_LONG deslong[2];
93 } ks[16];
94 } DES_key_schedule;
95
96#ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT
97# ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT
98# define OPENSSL_ENABLE_OLD_DES_SUPPORT
99# endif
100#endif
101
102#ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT
103# include <openssl/des_old.h>
104#endif
105
106#define DES_KEY_SZ (sizeof(DES_cblock))
107#define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
108
109#define DES_ENCRYPT 1
110#define DES_DECRYPT 0
111
112#define DES_CBC_MODE 0
113#define DES_PCBC_MODE 1
114
115#define DES_ecb2_encrypt(i,o,k1,k2,e) \
116 DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
117
118#define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
119 DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
120
121#define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
122 DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
123
124#define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
125 DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
126
127OPENSSL_DECLARE_GLOBAL(int,DES_check_key); /* defaults to false */
128#define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)
129OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */
130#define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode)
131
132const char *DES_options(void);
133void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
134 DES_key_schedule *ks1,DES_key_schedule *ks2,
135 DES_key_schedule *ks3, int enc);
136DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output,
137 long length,DES_key_schedule *schedule,
138 const_DES_cblock *ivec);
139/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
140void DES_cbc_encrypt(const unsigned char *input,unsigned char *output,
141 long length,DES_key_schedule *schedule,DES_cblock *ivec,
142 int enc);
143void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output,
144 long length,DES_key_schedule *schedule,DES_cblock *ivec,
145 int enc);
146void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output,
147 long length,DES_key_schedule *schedule,DES_cblock *ivec,
148 const_DES_cblock *inw,const_DES_cblock *outw,int enc);
149void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
150 long length,DES_key_schedule *schedule,DES_cblock *ivec,
151 int enc);
152void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output,
153 DES_key_schedule *ks,int enc);
154
155/* This is the DES encryption function that gets called by just about
156 every other DES routine in the library. You should not use this
157 function except to implement 'modes' of DES. I say this because the
158 functions that call this routine do the conversion from 'char *' to
159 long, and this needs to be done to make sure 'non-aligned' memory
160 access do not occur. The characters are loaded 'little endian'.
161 Data is a pointer to 2 unsigned long's and ks is the
162 DES_key_schedule to use. enc, is non zero specifies encryption,
163 zero if decryption. */
164void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);
165
166/* This functions is the same as DES_encrypt1() except that the DES
167 initial permutation (IP) and final permutation (FP) have been left
168 out. As for DES_encrypt1(), you should not use this function.
169 It is used by the routines in the library that implement triple DES.
170 IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same
171 as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */
172void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc);
173
174void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
175 DES_key_schedule *ks2, DES_key_schedule *ks3);
176void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
177 DES_key_schedule *ks2, DES_key_schedule *ks3);
178void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
179 long length,
180 DES_key_schedule *ks1,DES_key_schedule *ks2,
181 DES_key_schedule *ks3,DES_cblock *ivec,int enc);
182void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
183 long length,
184 DES_key_schedule *ks1,DES_key_schedule *ks2,
185 DES_key_schedule *ks3,
186 DES_cblock *ivec1,DES_cblock *ivec2,
187 int enc);
188void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
189 long length,DES_key_schedule *ks1,
190 DES_key_schedule *ks2,DES_key_schedule *ks3,
191 DES_cblock *ivec,int *num,int enc);
192void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
193 int numbits,long length,DES_key_schedule *ks1,
194 DES_key_schedule *ks2,DES_key_schedule *ks3,
195 DES_cblock *ivec,int enc);
196void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
197 long length,DES_key_schedule *ks1,
198 DES_key_schedule *ks2,DES_key_schedule *ks3,
199 DES_cblock *ivec,int *num);
200#if 0
201void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white,
202 DES_cblock *out_white);
203#endif
204
205int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched,
206 DES_cblock *iv);
207int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched,
208 DES_cblock *iv);
209char *DES_fcrypt(const char *buf,const char *salt, char *ret);
210char *DES_crypt(const char *buf,const char *salt);
211void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
212 long length,DES_key_schedule *schedule,DES_cblock *ivec);
213void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output,
214 long length,DES_key_schedule *schedule,DES_cblock *ivec,
215 int enc);
216DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[],
217 long length,int out_count,DES_cblock *seed);
218int DES_random_key(DES_cblock *ret);
219void DES_set_odd_parity(DES_cblock *key);
220int DES_check_key_parity(const_DES_cblock *key);
221int DES_is_weak_key(const_DES_cblock *key);
222/* DES_set_key (= set_key = DES_key_sched = key_sched) calls
223 * DES_set_key_checked if global variable DES_check_key is set,
224 * DES_set_key_unchecked otherwise. */
225int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule);
226int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule);
227int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule);
228void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule);
229void DES_string_to_key(const char *str,DES_cblock *key);
230void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2);
231void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
232 DES_key_schedule *schedule,DES_cblock *ivec,int *num,
233 int enc);
234void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
235 DES_key_schedule *schedule,DES_cblock *ivec,int *num);
236
237int DES_read_password(DES_cblock *key, const char *prompt, int verify);
238int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
239 int verify);
240
241#define DES_fixup_key_parity DES_set_odd_parity
242
243#ifdef __cplusplus
244}
245#endif
246
247#endif
diff --git a/src/lib/libcrypto/des/des.pod b/src/lib/libcrypto/des/des.pod
new file mode 100644
index 0000000000..bf479e83d2
--- /dev/null
+++ b/src/lib/libcrypto/des/des.pod
@@ -0,0 +1,217 @@
1=pod
2
3=head1 NAME
4
5des - encrypt or decrypt data using Data Encryption Standard
6
7=head1 SYNOPSIS
8
9B<des>
10(
11B<-e>
12|
13B<-E>
14) | (
15B<-d>
16|
17B<-D>
18) | (
19B<->[B<cC>][B<ckname>]
20) |
21[
22B<-b3hfs>
23] [
24B<-k>
25I<key>
26]
27] [
28B<-u>[I<uuname>]
29[
30I<input-file>
31[
32I<output-file>
33] ]
34
35=head1 NOTE
36
37This page describes the B<des> stand-alone program, not the B<openssl des>
38command.
39
40=head1 DESCRIPTION
41
42B<des>
43encrypts and decrypts data using the
44Data Encryption Standard algorithm.
45One of
46B<-e>, B<-E>
47(for encrypt) or
48B<-d>, B<-D>
49(for decrypt) must be specified.
50It is also possible to use
51B<-c>
52or
53B<-C>
54in conjunction or instead of the a encrypt/decrypt option to generate
55a 16 character hexadecimal checksum, generated via the
56I<des_cbc_cksum>.
57
58Two standard encryption modes are supported by the
59B<des>
60program, Cipher Block Chaining (the default) and Electronic Code Book
61(specified with
62B<-b>).
63
64The key used for the DES
65algorithm is obtained by prompting the user unless the
66B<-k>
67I<key>
68option is given.
69If the key is an argument to the
70B<des>
71command, it is potentially visible to users executing
72ps(1)
73or a derivative. To minimise this possibility,
74B<des>
75takes care to destroy the key argument immediately upon entry.
76If your shell keeps a history file be careful to make sure it is not
77world readable.
78
79Since this program attempts to maintain compatibility with sunOS's
80des(1) command, there are 2 different methods used to convert the user
81supplied key to a des key.
82Whenever and one or more of
83B<-E>, B<-D>, B<-C>
84or
85B<-3>
86options are used, the key conversion procedure will not be compatible
87with the sunOS des(1) version but will use all the user supplied
88character to generate the des key.
89B<des>
90command reads from standard input unless
91I<input-file>
92is specified and writes to standard output unless
93I<output-file>
94is given.
95
96=head1 OPTIONS
97
98=over 4
99
100=item B<-b>
101
102Select ECB
103(eight bytes at a time) encryption mode.
104
105=item B<-3>
106
107Encrypt using triple encryption.
108By default triple cbc encryption is used but if the
109B<-b>
110option is used then triple ECB encryption is performed.
111If the key is less than 8 characters long, the flag has no effect.
112
113=item B<-e>
114
115Encrypt data using an 8 byte key in a manner compatible with sunOS
116des(1).
117
118=item B<-E>
119
120Encrypt data using a key of nearly unlimited length (1024 bytes).
121This will product a more secure encryption.
122
123=item B<-d>
124
125Decrypt data that was encrypted with the B<-e> option.
126
127=item B<-D>
128
129Decrypt data that was encrypted with the B<-E> option.
130
131=item B<-c>
132
133Generate a 16 character hexadecimal cbc checksum and output this to
134stderr.
135If a filename was specified after the
136B<-c>
137option, the checksum is output to that file.
138The checksum is generated using a key generated in a sunOS compatible
139manner.
140
141=item B<-C>
142
143A cbc checksum is generated in the same manner as described for the
144B<-c>
145option but the DES key is generated in the same manner as used for the
146B<-E>
147and
148B<-D>
149options
150
151=item B<-f>
152
153Does nothing - allowed for compatibility with sunOS des(1) command.
154
155=item B<-s>
156
157Does nothing - allowed for compatibility with sunOS des(1) command.
158
159=item B<-k> I<key>
160
161Use the encryption
162I<key>
163specified.
164
165=item B<-h>
166
167The
168I<key>
169is assumed to be a 16 character hexadecimal number.
170If the
171B<-3>
172option is used the key is assumed to be a 32 character hexadecimal
173number.
174
175=item B<-u>
176
177This flag is used to read and write uuencoded files. If decrypting,
178the input file is assumed to contain uuencoded, DES encrypted data.
179If encrypting, the characters following the B<-u> are used as the name of
180the uuencoded file to embed in the begin line of the uuencoded
181output. If there is no name specified after the B<-u>, the name text.des
182will be embedded in the header.
183
184=head1 SEE ALSO
185
186ps(1),
187L<des_crypt(3)|des_crypt(3)>
188
189=head1 BUGS
190
191The problem with using the
192B<-e>
193option is the short key length.
194It would be better to use a real 56-bit key rather than an
195ASCII-based 56-bit pattern. Knowing that the key was derived from ASCII
196radically reduces the time necessary for a brute-force cryptographic attack.
197My attempt to remove this problem is to add an alternative text-key to
198DES-key function. This alternative function (accessed via
199B<-E>, B<-D>, B<-S>
200and
201B<-3>)
202uses DES to help generate the key.
203
204Be carefully when using the B<-u> option. Doing B<des -ud> I<filename> will
205not decrypt filename (the B<-u> option will gobble the B<-d> option).
206
207The VMS operating system operates in a world where files are always a
208multiple of 512 bytes. This causes problems when encrypted data is
209send from Unix to VMS since a 88 byte file will suddenly be padded
210with 424 null bytes. To get around this problem, use the B<-u> option
211to uuencode the data before it is send to the VMS system.
212
213=head1 AUTHOR
214
215Eric Young (eay@cryptsoft.com)
216
217=cut
diff --git a/src/lib/libcrypto/des/des3s.cpp b/src/lib/libcrypto/des/des3s.cpp
new file mode 100644
index 0000000000..02d527c057
--- /dev/null
+++ b/src/lib/libcrypto/des/des3s.cpp
@@ -0,0 +1,67 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/des.h>
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key1,key2,key3;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt3(&data[0],key1,key2,key3);
49 GetTSC(s1);
50 des_encrypt3(&data[0],key1,key2,key3);
51 des_encrypt3(&data[0],key1,key2,key3);
52 des_encrypt3(&data[0],key1,key2,key3);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt3(&data[0],key1,key2,key3);
56 des_encrypt3(&data[0],key1,key2,key3);
57 des_encrypt3(&data[0],key1,key2,key3);
58 des_encrypt3(&data[0],key1,key2,key3);
59 GetTSC(e2);
60 des_encrypt3(&data[0],key1,key2,key3);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
new file mode 100644
index 0000000000..0fe4e0b2ad
--- /dev/null
+++ b/src/lib/libcrypto/des/des_enc.c
@@ -0,0 +1,411 @@
1/* crypto/des/des_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#ifndef OPENBSD_DES_ASM
62
63void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
64 {
65 register DES_LONG l,r,t,u;
66#ifdef DES_PTR
67 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
68#endif
69#ifndef DES_UNROLL
70 register int i;
71#endif
72 register DES_LONG *s;
73
74 r=data[0];
75 l=data[1];
76
77 IP(r,l);
78 /* Things have been modified so that the initial rotate is
79 * done outside the loop. This required the
80 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
81 * One perl script later and things have a 5% speed up on a sparc2.
82 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
83 * for pointing this out. */
84 /* clear the top bits on machines with 8byte longs */
85 /* shift left by 2 */
86 r=ROTATE(r,29)&0xffffffffL;
87 l=ROTATE(l,29)&0xffffffffL;
88
89 s=ks->ks->deslong;
90 /* I don't know if it is worth the effort of loop unrolling the
91 * inner loop */
92 if (enc)
93 {
94#ifdef DES_UNROLL
95 D_ENCRYPT(l,r, 0); /* 1 */
96 D_ENCRYPT(r,l, 2); /* 2 */
97 D_ENCRYPT(l,r, 4); /* 3 */
98 D_ENCRYPT(r,l, 6); /* 4 */
99 D_ENCRYPT(l,r, 8); /* 5 */
100 D_ENCRYPT(r,l,10); /* 6 */
101 D_ENCRYPT(l,r,12); /* 7 */
102 D_ENCRYPT(r,l,14); /* 8 */
103 D_ENCRYPT(l,r,16); /* 9 */
104 D_ENCRYPT(r,l,18); /* 10 */
105 D_ENCRYPT(l,r,20); /* 11 */
106 D_ENCRYPT(r,l,22); /* 12 */
107 D_ENCRYPT(l,r,24); /* 13 */
108 D_ENCRYPT(r,l,26); /* 14 */
109 D_ENCRYPT(l,r,28); /* 15 */
110 D_ENCRYPT(r,l,30); /* 16 */
111#else
112 for (i=0; i<32; i+=8)
113 {
114 D_ENCRYPT(l,r,i+0); /* 1 */
115 D_ENCRYPT(r,l,i+2); /* 2 */
116 D_ENCRYPT(l,r,i+4); /* 3 */
117 D_ENCRYPT(r,l,i+6); /* 4 */
118 }
119#endif
120 }
121 else
122 {
123#ifdef DES_UNROLL
124 D_ENCRYPT(l,r,30); /* 16 */
125 D_ENCRYPT(r,l,28); /* 15 */
126 D_ENCRYPT(l,r,26); /* 14 */
127 D_ENCRYPT(r,l,24); /* 13 */
128 D_ENCRYPT(l,r,22); /* 12 */
129 D_ENCRYPT(r,l,20); /* 11 */
130 D_ENCRYPT(l,r,18); /* 10 */
131 D_ENCRYPT(r,l,16); /* 9 */
132 D_ENCRYPT(l,r,14); /* 8 */
133 D_ENCRYPT(r,l,12); /* 7 */
134 D_ENCRYPT(l,r,10); /* 6 */
135 D_ENCRYPT(r,l, 8); /* 5 */
136 D_ENCRYPT(l,r, 6); /* 4 */
137 D_ENCRYPT(r,l, 4); /* 3 */
138 D_ENCRYPT(l,r, 2); /* 2 */
139 D_ENCRYPT(r,l, 0); /* 1 */
140#else
141 for (i=30; i>0; i-=8)
142 {
143 D_ENCRYPT(l,r,i-0); /* 16 */
144 D_ENCRYPT(r,l,i-2); /* 15 */
145 D_ENCRYPT(l,r,i-4); /* 14 */
146 D_ENCRYPT(r,l,i-6); /* 13 */
147 }
148#endif
149 }
150
151 /* rotate and clear the top bits on machines with 8byte longs */
152 l=ROTATE(l,3)&0xffffffffL;
153 r=ROTATE(r,3)&0xffffffffL;
154
155 FP(r,l);
156 data[0]=l;
157 data[1]=r;
158 l=r=t=u=0;
159 }
160
161void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
162 {
163 register DES_LONG l,r,t,u;
164#ifdef DES_PTR
165 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
166#endif
167#ifndef DES_UNROLL
168 register int i;
169#endif
170 register DES_LONG *s;
171
172 r=data[0];
173 l=data[1];
174
175 /* Things have been modified so that the initial rotate is
176 * done outside the loop. This required the
177 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
178 * One perl script later and things have a 5% speed up on a sparc2.
179 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
180 * for pointing this out. */
181 /* clear the top bits on machines with 8byte longs */
182 r=ROTATE(r,29)&0xffffffffL;
183 l=ROTATE(l,29)&0xffffffffL;
184
185 s=ks->ks->deslong;
186 /* I don't know if it is worth the effort of loop unrolling the
187 * inner loop */
188 if (enc)
189 {
190#ifdef DES_UNROLL
191 D_ENCRYPT(l,r, 0); /* 1 */
192 D_ENCRYPT(r,l, 2); /* 2 */
193 D_ENCRYPT(l,r, 4); /* 3 */
194 D_ENCRYPT(r,l, 6); /* 4 */
195 D_ENCRYPT(l,r, 8); /* 5 */
196 D_ENCRYPT(r,l,10); /* 6 */
197 D_ENCRYPT(l,r,12); /* 7 */
198 D_ENCRYPT(r,l,14); /* 8 */
199 D_ENCRYPT(l,r,16); /* 9 */
200 D_ENCRYPT(r,l,18); /* 10 */
201 D_ENCRYPT(l,r,20); /* 11 */
202 D_ENCRYPT(r,l,22); /* 12 */
203 D_ENCRYPT(l,r,24); /* 13 */
204 D_ENCRYPT(r,l,26); /* 14 */
205 D_ENCRYPT(l,r,28); /* 15 */
206 D_ENCRYPT(r,l,30); /* 16 */
207#else
208 for (i=0; i<32; i+=8)
209 {
210 D_ENCRYPT(l,r,i+0); /* 1 */
211 D_ENCRYPT(r,l,i+2); /* 2 */
212 D_ENCRYPT(l,r,i+4); /* 3 */
213 D_ENCRYPT(r,l,i+6); /* 4 */
214 }
215#endif
216 }
217 else
218 {
219#ifdef DES_UNROLL
220 D_ENCRYPT(l,r,30); /* 16 */
221 D_ENCRYPT(r,l,28); /* 15 */
222 D_ENCRYPT(l,r,26); /* 14 */
223 D_ENCRYPT(r,l,24); /* 13 */
224 D_ENCRYPT(l,r,22); /* 12 */
225 D_ENCRYPT(r,l,20); /* 11 */
226 D_ENCRYPT(l,r,18); /* 10 */
227 D_ENCRYPT(r,l,16); /* 9 */
228 D_ENCRYPT(l,r,14); /* 8 */
229 D_ENCRYPT(r,l,12); /* 7 */
230 D_ENCRYPT(l,r,10); /* 6 */
231 D_ENCRYPT(r,l, 8); /* 5 */
232 D_ENCRYPT(l,r, 6); /* 4 */
233 D_ENCRYPT(r,l, 4); /* 3 */
234 D_ENCRYPT(l,r, 2); /* 2 */
235 D_ENCRYPT(r,l, 0); /* 1 */
236#else
237 for (i=30; i>0; i-=8)
238 {
239 D_ENCRYPT(l,r,i-0); /* 16 */
240 D_ENCRYPT(r,l,i-2); /* 15 */
241 D_ENCRYPT(l,r,i-4); /* 14 */
242 D_ENCRYPT(r,l,i-6); /* 13 */
243 }
244#endif
245 }
246 /* rotate and clear the top bits on machines with 8byte longs */
247 data[0]=ROTATE(l,3)&0xffffffffL;
248 data[1]=ROTATE(r,3)&0xffffffffL;
249 l=r=t=u=0;
250 }
251
252#endif /* OPENBSD_DES_ASM */
253
254void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
255 DES_key_schedule *ks2, DES_key_schedule *ks3)
256 {
257 register DES_LONG l,r;
258
259 l=data[0];
260 r=data[1];
261 IP(l,r);
262 data[0]=l;
263 data[1]=r;
264 DES_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);
265 DES_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);
266 DES_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);
267 l=data[0];
268 r=data[1];
269 FP(r,l);
270 data[0]=l;
271 data[1]=r;
272 }
273
274void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
275 DES_key_schedule *ks2, DES_key_schedule *ks3)
276 {
277 register DES_LONG l,r;
278
279 l=data[0];
280 r=data[1];
281 IP(l,r);
282 data[0]=l;
283 data[1]=r;
284 DES_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT);
285 DES_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT);
286 DES_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT);
287 l=data[0];
288 r=data[1];
289 FP(r,l);
290 data[0]=l;
291 data[1]=r;
292 }
293
294#ifndef DES_DEFAULT_OPTIONS
295
296#undef CBC_ENC_C__DONT_UPDATE_IV
297#include "ncbc_enc.c" /* DES_ncbc_encrypt */
298
299void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
300 long length, DES_key_schedule *ks1,
301 DES_key_schedule *ks2, DES_key_schedule *ks3,
302 DES_cblock *ivec, int enc)
303 {
304 register DES_LONG tin0,tin1;
305 register DES_LONG tout0,tout1,xor0,xor1;
306 register const unsigned char *in;
307 unsigned char *out;
308 register long l=length;
309 DES_LONG tin[2];
310 unsigned char *iv;
311
312 in=input;
313 out=output;
314 iv = &(*ivec)[0];
315
316 if (enc)
317 {
318 c2l(iv,tout0);
319 c2l(iv,tout1);
320 for (l-=8; l>=0; l-=8)
321 {
322 c2l(in,tin0);
323 c2l(in,tin1);
324 tin0^=tout0;
325 tin1^=tout1;
326
327 tin[0]=tin0;
328 tin[1]=tin1;
329 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
330 tout0=tin[0];
331 tout1=tin[1];
332
333 l2c(tout0,out);
334 l2c(tout1,out);
335 }
336 if (l != -8)
337 {
338 c2ln(in,tin0,tin1,l+8);
339 tin0^=tout0;
340 tin1^=tout1;
341
342 tin[0]=tin0;
343 tin[1]=tin1;
344 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
345 tout0=tin[0];
346 tout1=tin[1];
347
348 l2c(tout0,out);
349 l2c(tout1,out);
350 }
351 iv = &(*ivec)[0];
352 l2c(tout0,iv);
353 l2c(tout1,iv);
354 }
355 else
356 {
357 register DES_LONG t0,t1;
358
359 c2l(iv,xor0);
360 c2l(iv,xor1);
361 for (l-=8; l>=0; l-=8)
362 {
363 c2l(in,tin0);
364 c2l(in,tin1);
365
366 t0=tin0;
367 t1=tin1;
368
369 tin[0]=tin0;
370 tin[1]=tin1;
371 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
372 tout0=tin[0];
373 tout1=tin[1];
374
375 tout0^=xor0;
376 tout1^=xor1;
377 l2c(tout0,out);
378 l2c(tout1,out);
379 xor0=t0;
380 xor1=t1;
381 }
382 if (l != -8)
383 {
384 c2l(in,tin0);
385 c2l(in,tin1);
386
387 t0=tin0;
388 t1=tin1;
389
390 tin[0]=tin0;
391 tin[1]=tin1;
392 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
393 tout0=tin[0];
394 tout1=tin[1];
395
396 tout0^=xor0;
397 tout1^=xor1;
398 l2cn(tout0,tout1,out,l+8);
399 xor0=t0;
400 xor1=t1;
401 }
402
403 iv = &(*ivec)[0];
404 l2c(xor0,iv);
405 l2c(xor1,iv);
406 }
407 tin0=tin1=tout0=tout1=xor0=xor1=0;
408 tin[0]=tin[1]=0;
409 }
410
411#endif /* DES_DEFAULT_OPTIONS */
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
new file mode 100644
index 0000000000..4b9ecff233
--- /dev/null
+++ b/src/lib/libcrypto/des/des_locl.h
@@ -0,0 +1,428 @@
1/* crypto/des/des_locl.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DES_LOCL_H
60#define HEADER_DES_LOCL_H
61
62#include <openssl/e_os2.h>
63
64#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
65#ifndef OPENSSL_SYS_MSDOS
66#define OPENSSL_SYS_MSDOS
67#endif
68#endif
69
70#include <stdio.h>
71#include <stdlib.h>
72
73#ifndef OPENSSL_SYS_MSDOS
74#if !defined(OPENSSL_SYS_VMS) || defined(__DECC)
75#ifdef OPENSSL_UNISTD
76# include OPENSSL_UNISTD
77#else
78# include <unistd.h>
79#endif
80#include <math.h>
81#endif
82#endif
83#include <openssl/des.h>
84
85#ifdef OPENSSL_SYS_MSDOS /* Visual C++ 2.1 (Windows NT/95) */
86#include <stdlib.h>
87#include <errno.h>
88#include <time.h>
89#include <io.h>
90#endif
91
92#if defined(__STDC__) || defined(OPENSSL_SYS_VMS) || defined(M_XENIX) || defined(OPENSSL_SYS_MSDOS)
93#include <string.h>
94#endif
95
96#ifdef OPENSSL_BUILD_SHLIBCRYPTO
97# undef OPENSSL_EXTERN
98# define OPENSSL_EXTERN OPENSSL_EXPORT
99#endif
100
101#define ITERATIONS 16
102#define HALF_ITERATIONS 8
103
104/* used in des_read and des_write */
105#define MAXWRITE (1024*16)
106#define BSIZE (MAXWRITE+4)
107
108#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
109 l|=((DES_LONG)(*((c)++)))<< 8L, \
110 l|=((DES_LONG)(*((c)++)))<<16L, \
111 l|=((DES_LONG)(*((c)++)))<<24L)
112
113/* NOTE - c is not incremented as per c2l */
114#define c2ln(c,l1,l2,n) { \
115 c+=n; \
116 l1=l2=0; \
117 switch (n) { \
118 case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
119 case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
120 case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
121 case 5: l2|=((DES_LONG)(*(--(c)))); \
122 case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
123 case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
124 case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
125 case 1: l1|=((DES_LONG)(*(--(c)))); \
126 } \
127 }
128
129#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
130 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
131 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
132 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
133
134/* replacements for htonl and ntohl since I have no idea what to do
135 * when faced with machines with 8 byte longs. */
136#define HDRSIZE 4
137
138#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \
139 l|=((DES_LONG)(*((c)++)))<<16L, \
140 l|=((DES_LONG)(*((c)++)))<< 8L, \
141 l|=((DES_LONG)(*((c)++))))
142
143#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
144 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
145 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
146 *((c)++)=(unsigned char)(((l) )&0xff))
147
148/* NOTE - c is not incremented as per l2c */
149#define l2cn(l1,l2,c,n) { \
150 c+=n; \
151 switch (n) { \
152 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
153 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
154 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
155 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
156 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
157 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
158 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
159 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
160 } \
161 }
162
163#if (defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)) || defined(__ICC)
164#define ROTATE(a,n) (_lrotr(a,n))
165#elif defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC)
166# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
167# define ROTATE(a,n) ({ register unsigned int ret; \
168 asm ("rorl %1,%0" \
169 : "=r"(ret) \
170 : "I"(n),"0"(a) \
171 : "cc"); \
172 ret; \
173 })
174# endif
175#endif
176#ifndef ROTATE
177#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n))))
178#endif
179
180/* Don't worry about the LOAD_DATA() stuff, that is used by
181 * fcrypt() to add it's little bit to the front */
182
183#ifdef DES_FCRYPT
184
185#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \
186 { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); }
187
188#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
189 t=R^(R>>16L); \
190 u=t&E0; t&=E1; \
191 tmp=(u<<16); u^=R^s[S ]; u^=tmp; \
192 tmp=(t<<16); t^=R^s[S+1]; t^=tmp
193#else
194#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
195#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
196 u=R^s[S ]; \
197 t=R^s[S+1]
198#endif
199
200/* The changes to this macro may help or hinder, depending on the
201 * compiler and the architecture. gcc2 always seems to do well :-).
202 * Inspired by Dana How <how@isl.stanford.edu>
203 * DO NOT use the alternative version on machines with 8 byte longs.
204 * It does not seem to work on the Alpha, even when DES_LONG is 4
205 * bytes, probably an issue of accessing non-word aligned objects :-( */
206#ifdef DES_PTR
207
208/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
209 * is no reason to not xor all the sub items together. This potentially
210 * saves a register since things can be xored directly into L */
211
212#if defined(DES_RISC1) || defined(DES_RISC2)
213#ifdef DES_RISC1
214#define D_ENCRYPT(LL,R,S) { \
215 unsigned int u1,u2,u3; \
216 LOAD_DATA(R,S,u,t,E0,E1,u1); \
217 u2=(int)u>>8L; \
218 u1=(int)u&0xfc; \
219 u2&=0xfc; \
220 t=ROTATE(t,4); \
221 u>>=16L; \
222 LL^= *(const DES_LONG *)(des_SP +u1); \
223 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
224 u3=(int)(u>>8L); \
225 u1=(int)u&0xfc; \
226 u3&=0xfc; \
227 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
228 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
229 u2=(int)t>>8L; \
230 u1=(int)t&0xfc; \
231 u2&=0xfc; \
232 t>>=16L; \
233 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
234 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
235 u3=(int)t>>8L; \
236 u1=(int)t&0xfc; \
237 u3&=0xfc; \
238 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
239 LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
240#endif
241#ifdef DES_RISC2
242#define D_ENCRYPT(LL,R,S) { \
243 unsigned int u1,u2,s1,s2; \
244 LOAD_DATA(R,S,u,t,E0,E1,u1); \
245 u2=(int)u>>8L; \
246 u1=(int)u&0xfc; \
247 u2&=0xfc; \
248 t=ROTATE(t,4); \
249 LL^= *(const DES_LONG *)(des_SP +u1); \
250 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
251 s1=(int)(u>>16L); \
252 s2=(int)(u>>24L); \
253 s1&=0xfc; \
254 s2&=0xfc; \
255 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
256 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
257 u2=(int)t>>8L; \
258 u1=(int)t&0xfc; \
259 u2&=0xfc; \
260 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
261 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
262 s1=(int)(t>>16L); \
263 s2=(int)(t>>24L); \
264 s1&=0xfc; \
265 s2&=0xfc; \
266 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
267 LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
268#endif
269#else
270#define D_ENCRYPT(LL,R,S) { \
271 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
272 t=ROTATE(t,4); \
273 LL^= \
274 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \
275 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
276 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
277 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
278 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
279 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
280 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
281 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
282#endif
283
284#else /* original version */
285
286#if defined(DES_RISC1) || defined(DES_RISC2)
287#ifdef DES_RISC1
288#define D_ENCRYPT(LL,R,S) {\
289 unsigned int u1,u2,u3; \
290 LOAD_DATA(R,S,u,t,E0,E1,u1); \
291 u>>=2L; \
292 t=ROTATE(t,6); \
293 u2=(int)u>>8L; \
294 u1=(int)u&0x3f; \
295 u2&=0x3f; \
296 u>>=16L; \
297 LL^=DES_SPtrans[0][u1]; \
298 LL^=DES_SPtrans[2][u2]; \
299 u3=(int)u>>8L; \
300 u1=(int)u&0x3f; \
301 u3&=0x3f; \
302 LL^=DES_SPtrans[4][u1]; \
303 LL^=DES_SPtrans[6][u3]; \
304 u2=(int)t>>8L; \
305 u1=(int)t&0x3f; \
306 u2&=0x3f; \
307 t>>=16L; \
308 LL^=DES_SPtrans[1][u1]; \
309 LL^=DES_SPtrans[3][u2]; \
310 u3=(int)t>>8L; \
311 u1=(int)t&0x3f; \
312 u3&=0x3f; \
313 LL^=DES_SPtrans[5][u1]; \
314 LL^=DES_SPtrans[7][u3]; }
315#endif
316#ifdef DES_RISC2
317#define D_ENCRYPT(LL,R,S) {\
318 unsigned int u1,u2,s1,s2; \
319 LOAD_DATA(R,S,u,t,E0,E1,u1); \
320 u>>=2L; \
321 t=ROTATE(t,6); \
322 u2=(int)u>>8L; \
323 u1=(int)u&0x3f; \
324 u2&=0x3f; \
325 LL^=DES_SPtrans[0][u1]; \
326 LL^=DES_SPtrans[2][u2]; \
327 s1=(int)u>>16L; \
328 s2=(int)u>>24L; \
329 s1&=0x3f; \
330 s2&=0x3f; \
331 LL^=DES_SPtrans[4][s1]; \
332 LL^=DES_SPtrans[6][s2]; \
333 u2=(int)t>>8L; \
334 u1=(int)t&0x3f; \
335 u2&=0x3f; \
336 LL^=DES_SPtrans[1][u1]; \
337 LL^=DES_SPtrans[3][u2]; \
338 s1=(int)t>>16; \
339 s2=(int)t>>24L; \
340 s1&=0x3f; \
341 s2&=0x3f; \
342 LL^=DES_SPtrans[5][s1]; \
343 LL^=DES_SPtrans[7][s2]; }
344#endif
345
346#else
347
348#define D_ENCRYPT(LL,R,S) {\
349 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
350 t=ROTATE(t,4); \
351 LL^=\
352 DES_SPtrans[0][(u>> 2L)&0x3f]^ \
353 DES_SPtrans[2][(u>>10L)&0x3f]^ \
354 DES_SPtrans[4][(u>>18L)&0x3f]^ \
355 DES_SPtrans[6][(u>>26L)&0x3f]^ \
356 DES_SPtrans[1][(t>> 2L)&0x3f]^ \
357 DES_SPtrans[3][(t>>10L)&0x3f]^ \
358 DES_SPtrans[5][(t>>18L)&0x3f]^ \
359 DES_SPtrans[7][(t>>26L)&0x3f]; }
360#endif
361#endif
362
363 /* IP and FP
364 * The problem is more of a geometric problem that random bit fiddling.
365 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
366 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
367 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
368 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
369
370 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
371 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
372 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
373 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
374
375 The output has been subject to swaps of the form
376 0 1 -> 3 1 but the odd and even bits have been put into
377 2 3 2 0
378 different words. The main trick is to remember that
379 t=((l>>size)^r)&(mask);
380 r^=t;
381 l^=(t<<size);
382 can be used to swap and move bits between words.
383
384 So l = 0 1 2 3 r = 16 17 18 19
385 4 5 6 7 20 21 22 23
386 8 9 10 11 24 25 26 27
387 12 13 14 15 28 29 30 31
388 becomes (for size == 2 and mask == 0x3333)
389 t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
390 6^20 7^21 -- -- 4 5 20 21 6 7 22 23
391 10^24 11^25 -- -- 8 9 24 25 10 11 24 25
392 14^28 15^29 -- -- 12 13 28 29 14 15 28 29
393
394 Thanks for hints from Richard Outerbridge - he told me IP&FP
395 could be done in 15 xor, 10 shifts and 5 ands.
396 When I finally started to think of the problem in 2D
397 I first got ~42 operations without xors. When I remembered
398 how to use xors :-) I got it to its final state.
399 */
400#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
401 (b)^=(t),\
402 (a)^=((t)<<(n)))
403
404#define IP(l,r) \
405 { \
406 register DES_LONG tt; \
407 PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
408 PERM_OP(l,r,tt,16,0x0000ffffL); \
409 PERM_OP(r,l,tt, 2,0x33333333L); \
410 PERM_OP(l,r,tt, 8,0x00ff00ffL); \
411 PERM_OP(r,l,tt, 1,0x55555555L); \
412 }
413
414#define FP(l,r) \
415 { \
416 register DES_LONG tt; \
417 PERM_OP(l,r,tt, 1,0x55555555L); \
418 PERM_OP(r,l,tt, 8,0x00ff00ffL); \
419 PERM_OP(l,r,tt, 2,0x33333333L); \
420 PERM_OP(r,l,tt,16,0x0000ffffL); \
421 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
422 }
423
424extern const DES_LONG DES_SPtrans[8][64];
425
426void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
427 DES_LONG Eswap0, DES_LONG Eswap1);
428#endif
diff --git a/src/lib/libcrypto/des/des_old.c b/src/lib/libcrypto/des/des_old.c
new file mode 100644
index 0000000000..7c33ed7a93
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old.c
@@ -0,0 +1,273 @@
1/* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with libdes. OpenSSL now provides
7 * functions where "des_" has been replaced with "DES_" in the names,
8 * to make it possible to make incompatible changes that are needed
9 * for C type security and other stuff.
10 *
11 * Please consider starting to use the DES_ functions rather than the
12 * des_ ones. The des_ functions will dissapear completely before
13 * OpenSSL 1.0!
14 *
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16 */
17
18/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
19 * project 2001.
20 */
21/* ====================================================================
22 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 *
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 *
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 *
36 * 3. All advertising materials mentioning features or use of this
37 * software must display the following acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40 *
41 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42 * endorse or promote products derived from this software without
43 * prior written permission. For written permission, please contact
44 * openssl-core@openssl.org.
45 *
46 * 5. Products derived from this software may not be called "OpenSSL"
47 * nor may "OpenSSL" appear in their names without prior written
48 * permission of the OpenSSL Project.
49 *
50 * 6. Redistributions of any form whatsoever must retain the following
51 * acknowledgment:
52 * "This product includes software developed by the OpenSSL Project
53 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66 * OF THE POSSIBILITY OF SUCH DAMAGE.
67 * ====================================================================
68 *
69 * This product includes cryptographic software written by Eric Young
70 * (eay@cryptsoft.com). This product includes software written by Tim
71 * Hudson (tjh@cryptsoft.com).
72 *
73 */
74
75#define OPENSSL_DES_LIBDES_COMPATIBILITY
76#include <openssl/des.h>
77#include <openssl/rand.h>
78
79const char *_ossl_old_des_options(void)
80 {
81 return DES_options();
82 }
83void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
84 des_key_schedule ks1,des_key_schedule ks2,
85 des_key_schedule ks3, int enc)
86 {
87 DES_ecb3_encrypt((const_DES_cblock *)input, output,
88 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
89 (DES_key_schedule *)ks3, enc);
90 }
91DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
92 long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec)
93 {
94 return DES_cbc_cksum((unsigned char *)input, output, length,
95 (DES_key_schedule *)schedule, ivec);
96 }
97void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
98 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
99 {
100 DES_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
101 length, (DES_key_schedule *)schedule, ivec, enc);
102 }
103void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
104 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
105 {
106 DES_ncbc_encrypt((unsigned char *)input, (unsigned char *)output,
107 length, (DES_key_schedule *)schedule, ivec, enc);
108 }
109void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
110 des_key_schedule schedule,_ossl_old_des_cblock *ivec,
111 _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc)
112 {
113 DES_xcbc_encrypt((unsigned char *)input, (unsigned char *)output,
114 length, (DES_key_schedule *)schedule, ivec, inw, outw, enc);
115 }
116void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
117 long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
118 {
119 DES_cfb_encrypt(in, out, numbits, length,
120 (DES_key_schedule *)schedule, ivec, enc);
121 }
122void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
123 des_key_schedule ks,int enc)
124 {
125 DES_ecb_encrypt(input, output, (DES_key_schedule *)ks, enc);
126 }
127void _ossl_old_des_encrypt(DES_LONG *data,des_key_schedule ks, int enc)
128 {
129 DES_encrypt1(data, (DES_key_schedule *)ks, enc);
130 }
131void _ossl_old_des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc)
132 {
133 DES_encrypt2(data, (DES_key_schedule *)ks, enc);
134 }
135void _ossl_old_des_encrypt3(DES_LONG *data, des_key_schedule ks1,
136 des_key_schedule ks2, des_key_schedule ks3)
137 {
138 DES_encrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
139 (DES_key_schedule *)ks3);
140 }
141void _ossl_old_des_decrypt3(DES_LONG *data, des_key_schedule ks1,
142 des_key_schedule ks2, des_key_schedule ks3)
143 {
144 DES_decrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
145 (DES_key_schedule *)ks3);
146 }
147void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output,
148 long length, des_key_schedule ks1, des_key_schedule ks2,
149 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc)
150 {
151 DES_ede3_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
152 length, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
153 (DES_key_schedule *)ks3, ivec, enc);
154 }
155void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
156 long length, des_key_schedule ks1, des_key_schedule ks2,
157 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc)
158 {
159 DES_ede3_cfb64_encrypt(in, out, length,
160 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
161 (DES_key_schedule *)ks3, ivec, num, enc);
162 }
163void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
164 long length, des_key_schedule ks1, des_key_schedule ks2,
165 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num)
166 {
167 DES_ede3_ofb64_encrypt(in, out, length,
168 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
169 (DES_key_schedule *)ks3, ivec, num);
170 }
171
172#if 0 /* broken code, preserved just in case anyone specifically looks for this */
173void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
174 _ossl_old_des_cblock (*out_white))
175 {
176 DES_xwhite_in2out(des_key, in_white, out_white);
177 }
178#endif
179
180int _ossl_old_des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
181 _ossl_old_des_cblock *iv)
182 {
183 return DES_enc_read(fd, buf, len, (DES_key_schedule *)sched, iv);
184 }
185int _ossl_old_des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
186 _ossl_old_des_cblock *iv)
187 {
188 return DES_enc_write(fd, buf, len, (DES_key_schedule *)sched, iv);
189 }
190char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret)
191 {
192 return DES_fcrypt(buf, salt, ret);
193 }
194char *_ossl_old_des_crypt(const char *buf,const char *salt)
195 {
196 return DES_crypt(buf, salt);
197 }
198char *_ossl_old_crypt(const char *buf,const char *salt)
199 {
200 return DES_crypt(buf, salt);
201 }
202void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
203 int numbits,long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec)
204 {
205 DES_ofb_encrypt(in, out, numbits, length, (DES_key_schedule *)schedule,
206 ivec);
207 }
208void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
209 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
210 {
211 DES_pcbc_encrypt((unsigned char *)input, (unsigned char *)output,
212 length, (DES_key_schedule *)schedule, ivec, enc);
213 }
214DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
215 long length,int out_count,_ossl_old_des_cblock *seed)
216 {
217 return DES_quad_cksum((unsigned char *)input, output, length,
218 out_count, seed);
219 }
220void _ossl_old_des_random_seed(_ossl_old_des_cblock key)
221 {
222 RAND_seed(key, sizeof(_ossl_old_des_cblock));
223 }
224void _ossl_old_des_random_key(_ossl_old_des_cblock ret)
225 {
226 DES_random_key((DES_cblock *)ret);
227 }
228int _ossl_old_des_read_password(_ossl_old_des_cblock *key, const char *prompt,
229 int verify)
230 {
231 return DES_read_password(key, prompt, verify);
232 }
233int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1, _ossl_old_des_cblock *key2,
234 const char *prompt, int verify)
235 {
236 return DES_read_2passwords(key1, key2, prompt, verify);
237 }
238void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key)
239 {
240 DES_set_odd_parity(key);
241 }
242int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key)
243 {
244 return DES_is_weak_key(key);
245 }
246int _ossl_old_des_set_key(_ossl_old_des_cblock *key,des_key_schedule schedule)
247 {
248 return DES_set_key(key, (DES_key_schedule *)schedule);
249 }
250int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,des_key_schedule schedule)
251 {
252 return DES_key_sched(key, (DES_key_schedule *)schedule);
253 }
254void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key)
255 {
256 DES_string_to_key(str, key);
257 }
258void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2)
259 {
260 DES_string_to_2keys(str, key1, key2);
261 }
262void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
263 des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc)
264 {
265 DES_cfb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
266 ivec, num, enc);
267 }
268void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
269 des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num)
270 {
271 DES_ofb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
272 ivec, num);
273 }
diff --git a/src/lib/libcrypto/des/des_old.h b/src/lib/libcrypto/des/des_old.h
new file mode 100644
index 0000000000..8665ba4e7e
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old.h
@@ -0,0 +1,446 @@
1/* crypto/des/des_old.h -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with openssl 0.9.6 and older as
7 * well as libdes. OpenSSL now provides functions where "des_" has
8 * been replaced with "DES_" in the names, to make it possible to
9 * make incompatible changes that are needed for C type security and
10 * other stuff.
11 *
12 * This include files has two compatibility modes:
13 *
14 * - If OPENSSL_DES_LIBDES_COMPATIBILITY is defined, you get an API
15 * that is compatible with libdes and SSLeay.
16 * - If OPENSSL_DES_LIBDES_COMPATIBILITY isn't defined, you get an
17 * API that is compatible with OpenSSL 0.9.5x to 0.9.6x.
18 *
19 * Note that these modes break earlier snapshots of OpenSSL, where
20 * libdes compatibility was the only available mode or (later on) the
21 * prefered compatibility mode. However, after much consideration
22 * (and more or less violent discussions with external parties), it
23 * was concluded that OpenSSL should be compatible with earlier versions
24 * of itself before anything else. Also, in all honesty, libdes is
25 * an old beast that shouldn't really be used any more.
26 *
27 * Please consider starting to use the DES_ functions rather than the
28 * des_ ones. The des_ functions will disappear completely before
29 * OpenSSL 1.0!
30 *
31 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
32 */
33
34/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
35 * project 2001.
36 */
37/* ====================================================================
38 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 *
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in
49 * the documentation and/or other materials provided with the
50 * distribution.
51 *
52 * 3. All advertising materials mentioning features or use of this
53 * software must display the following acknowledgment:
54 * "This product includes software developed by the OpenSSL Project
55 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
56 *
57 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
58 * endorse or promote products derived from this software without
59 * prior written permission. For written permission, please contact
60 * openssl-core@openssl.org.
61 *
62 * 5. Products derived from this software may not be called "OpenSSL"
63 * nor may "OpenSSL" appear in their names without prior written
64 * permission of the OpenSSL Project.
65 *
66 * 6. Redistributions of any form whatsoever must retain the following
67 * acknowledgment:
68 * "This product includes software developed by the OpenSSL Project
69 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
70 *
71 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
72 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
74 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
75 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
76 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
77 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
78 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
79 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
80 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
81 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
82 * OF THE POSSIBILITY OF SUCH DAMAGE.
83 * ====================================================================
84 *
85 * This product includes cryptographic software written by Eric Young
86 * (eay@cryptsoft.com). This product includes software written by Tim
87 * Hudson (tjh@cryptsoft.com).
88 *
89 */
90
91#ifndef HEADER_DES_OLD_H
92#define HEADER_DES_OLD_H
93
94#include <openssl/e_os2.h> /* OPENSSL_EXTERN, OPENSSL_NO_DES, DES_LONG */
95
96#ifdef OPENSSL_NO_DES
97#error DES is disabled.
98#endif
99
100#ifndef HEADER_DES_H
101#error You must include des.h, not des_old.h directly.
102#endif
103
104#ifdef _KERBEROS_DES_H
105#error <openssl/des_old.h> replaces <kerberos/des.h>.
106#endif
107
108#include <openssl/symhacks.h>
109
110#ifdef OPENSSL_BUILD_SHLIBCRYPTO
111# undef OPENSSL_EXTERN
112# define OPENSSL_EXTERN OPENSSL_EXPORT
113#endif
114
115#ifdef __cplusplus
116extern "C" {
117#endif
118
119#ifdef _
120#undef _
121#endif
122
123typedef unsigned char _ossl_old_des_cblock[8];
124typedef struct _ossl_old_des_ks_struct
125 {
126 union {
127 _ossl_old_des_cblock _;
128 /* make sure things are correct size on machines with
129 * 8 byte longs */
130 DES_LONG pad[2];
131 } ks;
132 } _ossl_old_des_key_schedule[16];
133
134#ifndef OPENSSL_DES_LIBDES_COMPATIBILITY
135#define des_cblock DES_cblock
136#define const_des_cblock const_DES_cblock
137#define des_key_schedule DES_key_schedule
138#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
139 DES_ecb3_encrypt((i),(o),&(k1),&(k2),&(k3),(e))
140#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
141 DES_ede3_cbc_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(e))
142#define des_ede3_cbcm_encrypt(i,o,l,k1,k2,k3,iv1,iv2,e)\
143 DES_ede3_cbcm_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv1),(iv2),(e))
144#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
145 DES_ede3_cfb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n),(e))
146#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
147 DES_ede3_ofb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n))
148#define des_options()\
149 DES_options()
150#define des_cbc_cksum(i,o,l,k,iv)\
151 DES_cbc_cksum((i),(o),(l),&(k),(iv))
152#define des_cbc_encrypt(i,o,l,k,iv,e)\
153 DES_cbc_encrypt((i),(o),(l),&(k),(iv),(e))
154#define des_ncbc_encrypt(i,o,l,k,iv,e)\
155 DES_ncbc_encrypt((i),(o),(l),&(k),(iv),(e))
156#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
157 DES_xcbc_encrypt((i),(o),(l),&(k),(iv),(inw),(outw),(e))
158#define des_cfb_encrypt(i,o,n,l,k,iv,e)\
159 DES_cfb_encrypt((i),(o),(n),(l),&(k),(iv),(e))
160#define des_ecb_encrypt(i,o,k,e)\
161 DES_ecb_encrypt((i),(o),&(k),(e))
162#define des_encrypt1(d,k,e)\
163 DES_encrypt1((d),&(k),(e))
164#define des_encrypt2(d,k,e)\
165 DES_encrypt2((d),&(k),(e))
166#define des_encrypt3(d,k1,k2,k3)\
167 DES_encrypt3((d),&(k1),&(k2),&(k3))
168#define des_decrypt3(d,k1,k2,k3)\
169 DES_decrypt3((d),&(k1),&(k2),&(k3))
170#define des_xwhite_in2out(k,i,o)\
171 DES_xwhite_in2out((k),(i),(o))
172#define des_enc_read(f,b,l,k,iv)\
173 DES_enc_read((f),(b),(l),&(k),(iv))
174#define des_enc_write(f,b,l,k,iv)\
175 DES_enc_write((f),(b),(l),&(k),(iv))
176#define des_fcrypt(b,s,r)\
177 DES_fcrypt((b),(s),(r))
178#if 0
179#define des_crypt(b,s)\
180 DES_crypt((b),(s))
181#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT) && !defined(__OpenBSD__)
182#define crypt(b,s)\
183 DES_crypt((b),(s))
184#endif
185#endif
186#define des_ofb_encrypt(i,o,n,l,k,iv)\
187 DES_ofb_encrypt((i),(o),(n),(l),&(k),(iv))
188#define des_pcbc_encrypt(i,o,l,k,iv,e)\
189 DES_pcbc_encrypt((i),(o),(l),&(k),(iv),(e))
190#define des_quad_cksum(i,o,l,c,s)\
191 DES_quad_cksum((i),(o),(l),(c),(s))
192#define des_random_seed(k)\
193 _ossl_096_des_random_seed((k))
194#define des_random_key(r)\
195 DES_random_key((r))
196#define des_read_password(k,p,v) \
197 DES_read_password((k),(p),(v))
198#define des_read_2passwords(k1,k2,p,v) \
199 DES_read_2passwords((k1),(k2),(p),(v))
200#define des_set_odd_parity(k)\
201 DES_set_odd_parity((k))
202#define des_check_key_parity(k)\
203 DES_check_key_parity((k))
204#define des_is_weak_key(k)\
205 DES_is_weak_key((k))
206#define des_set_key(k,ks)\
207 DES_set_key((k),&(ks))
208#define des_key_sched(k,ks)\
209 DES_key_sched((k),&(ks))
210#define des_set_key_checked(k,ks)\
211 DES_set_key_checked((k),&(ks))
212#define des_set_key_unchecked(k,ks)\
213 DES_set_key_unchecked((k),&(ks))
214#define des_string_to_key(s,k)\
215 DES_string_to_key((s),(k))
216#define des_string_to_2keys(s,k1,k2)\
217 DES_string_to_2keys((s),(k1),(k2))
218#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
219 DES_cfb64_encrypt((i),(o),(l),&(ks),(iv),(n),(e))
220#define des_ofb64_encrypt(i,o,l,ks,iv,n)\
221 DES_ofb64_encrypt((i),(o),(l),&(ks),(iv),(n))
222
223
224#define des_ecb2_encrypt(i,o,k1,k2,e) \
225 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
226
227#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
228 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
229
230#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
231 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
232
233#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
234 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
235
236#define des_check_key DES_check_key
237#define des_rw_mode DES_rw_mode
238#else /* libdes compatibility */
239/* Map all symbol names to _ossl_old_des_* form, so we avoid all
240 clashes with libdes */
241#define des_cblock _ossl_old_des_cblock
242#define des_key_schedule _ossl_old_des_key_schedule
243#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
244 _ossl_old_des_ecb3_encrypt((i),(o),(k1),(k2),(k3),(e))
245#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
246 _ossl_old_des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))
247#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
248 _ossl_old_des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n),(e))
249#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
250 _ossl_old_des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n))
251#define des_options()\
252 _ossl_old_des_options()
253#define des_cbc_cksum(i,o,l,k,iv)\
254 _ossl_old_des_cbc_cksum((i),(o),(l),(k),(iv))
255#define des_cbc_encrypt(i,o,l,k,iv,e)\
256 _ossl_old_des_cbc_encrypt((i),(o),(l),(k),(iv),(e))
257#define des_ncbc_encrypt(i,o,l,k,iv,e)\
258 _ossl_old_des_ncbc_encrypt((i),(o),(l),(k),(iv),(e))
259#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
260 _ossl_old_des_xcbc_encrypt((i),(o),(l),(k),(iv),(inw),(outw),(e))
261#define des_cfb_encrypt(i,o,n,l,k,iv,e)\
262 _ossl_old_des_cfb_encrypt((i),(o),(n),(l),(k),(iv),(e))
263#define des_ecb_encrypt(i,o,k,e)\
264 _ossl_old_des_ecb_encrypt((i),(o),(k),(e))
265#define des_encrypt(d,k,e)\
266 _ossl_old_des_encrypt((d),(k),(e))
267#define des_encrypt2(d,k,e)\
268 _ossl_old_des_encrypt2((d),(k),(e))
269#define des_encrypt3(d,k1,k2,k3)\
270 _ossl_old_des_encrypt3((d),(k1),(k2),(k3))
271#define des_decrypt3(d,k1,k2,k3)\
272 _ossl_old_des_decrypt3((d),(k1),(k2),(k3))
273#define des_xwhite_in2out(k,i,o)\
274 _ossl_old_des_xwhite_in2out((k),(i),(o))
275#define des_enc_read(f,b,l,k,iv)\
276 _ossl_old_des_enc_read((f),(b),(l),(k),(iv))
277#define des_enc_write(f,b,l,k,iv)\
278 _ossl_old_des_enc_write((f),(b),(l),(k),(iv))
279#define des_fcrypt(b,s,r)\
280 _ossl_old_des_fcrypt((b),(s),(r))
281#define des_crypt(b,s)\
282 _ossl_old_des_crypt((b),(s))
283#if 0
284#define crypt(b,s)\
285 _ossl_old_crypt((b),(s))
286#endif
287#define des_ofb_encrypt(i,o,n,l,k,iv)\
288 _ossl_old_des_ofb_encrypt((i),(o),(n),(l),(k),(iv))
289#define des_pcbc_encrypt(i,o,l,k,iv,e)\
290 _ossl_old_des_pcbc_encrypt((i),(o),(l),(k),(iv),(e))
291#define des_quad_cksum(i,o,l,c,s)\
292 _ossl_old_des_quad_cksum((i),(o),(l),(c),(s))
293#define des_random_seed(k)\
294 _ossl_old_des_random_seed((k))
295#define des_random_key(r)\
296 _ossl_old_des_random_key((r))
297#define des_read_password(k,p,v) \
298 _ossl_old_des_read_password((k),(p),(v))
299#define des_read_2passwords(k1,k2,p,v) \
300 _ossl_old_des_read_2passwords((k1),(k2),(p),(v))
301#define des_set_odd_parity(k)\
302 _ossl_old_des_set_odd_parity((k))
303#define des_is_weak_key(k)\
304 _ossl_old_des_is_weak_key((k))
305#define des_set_key(k,ks)\
306 _ossl_old_des_set_key((k),(ks))
307#define des_key_sched(k,ks)\
308 _ossl_old_des_key_sched((k),(ks))
309#define des_string_to_key(s,k)\
310 _ossl_old_des_string_to_key((s),(k))
311#define des_string_to_2keys(s,k1,k2)\
312 _ossl_old_des_string_to_2keys((s),(k1),(k2))
313#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
314 _ossl_old_des_cfb64_encrypt((i),(o),(l),(ks),(iv),(n),(e))
315#define des_ofb64_encrypt(i,o,l,ks,iv,n)\
316 _ossl_old_des_ofb64_encrypt((i),(o),(l),(ks),(iv),(n))
317
318
319#define des_ecb2_encrypt(i,o,k1,k2,e) \
320 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
321
322#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
323 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
324
325#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
326 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
327
328#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
329 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
330
331#define des_check_key DES_check_key
332#define des_rw_mode DES_rw_mode
333#endif
334
335const char *_ossl_old_des_options(void);
336void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
337 _ossl_old_des_key_schedule ks1,_ossl_old_des_key_schedule ks2,
338 _ossl_old_des_key_schedule ks3, int enc);
339DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
340 long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
341void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
342 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
343void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
344 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
345void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
346 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,
347 _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc);
348void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
349 long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
350void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
351 _ossl_old_des_key_schedule ks,int enc);
352void _ossl_old_des_encrypt(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
353void _ossl_old_des_encrypt2(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
354void _ossl_old_des_encrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
355 _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
356void _ossl_old_des_decrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
357 _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
358void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output,
359 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
360 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc);
361void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
362 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
363 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc);
364void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
365 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
366 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num);
367#if 0
368void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
369 _ossl_old_des_cblock (*out_white));
370#endif
371
372int _ossl_old_des_enc_read(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
373 _ossl_old_des_cblock *iv);
374int _ossl_old_des_enc_write(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
375 _ossl_old_des_cblock *iv);
376char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret);
377char *_ossl_old_des_crypt(const char *buf,const char *salt);
378#if !defined(PERL5) && !defined(NeXT)
379char *_ossl_old_crypt(const char *buf,const char *salt);
380#endif
381void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
382 int numbits,long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
383void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
384 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
385DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
386 long length,int out_count,_ossl_old_des_cblock *seed);
387void _ossl_old_des_random_seed(_ossl_old_des_cblock key);
388void _ossl_old_des_random_key(_ossl_old_des_cblock ret);
389int _ossl_old_des_read_password(_ossl_old_des_cblock *key,const char *prompt,int verify);
390int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2,
391 const char *prompt,int verify);
392void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key);
393int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key);
394int _ossl_old_des_set_key(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
395int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
396void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key);
397void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2);
398void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
399 _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc);
400void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
401 _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num);
402
403void _ossl_096_des_random_seed(des_cblock *key);
404
405/* The following definitions provide compatibility with the MIT Kerberos
406 * library. The _ossl_old_des_key_schedule structure is not binary compatible. */
407
408#define _KERBEROS_DES_H
409
410#define KRBDES_ENCRYPT DES_ENCRYPT
411#define KRBDES_DECRYPT DES_DECRYPT
412
413#ifdef KERBEROS
414# define ENCRYPT DES_ENCRYPT
415# define DECRYPT DES_DECRYPT
416#endif
417
418#ifndef NCOMPAT
419# define C_Block des_cblock
420# define Key_schedule des_key_schedule
421# define KEY_SZ DES_KEY_SZ
422# define string_to_key des_string_to_key
423# define read_pw_string des_read_pw_string
424# define random_key des_random_key
425# define pcbc_encrypt des_pcbc_encrypt
426# define set_key des_set_key
427# define key_sched des_key_sched
428# define ecb_encrypt des_ecb_encrypt
429# define cbc_encrypt des_cbc_encrypt
430# define ncbc_encrypt des_ncbc_encrypt
431# define xcbc_encrypt des_xcbc_encrypt
432# define cbc_cksum des_cbc_cksum
433# define quad_cksum des_quad_cksum
434# define check_parity des_check_key_parity
435#endif
436
437#define des_fixup_key_parity DES_fixup_key_parity
438
439#ifdef __cplusplus
440}
441#endif
442
443/* for DES_read_pw_string et al */
444#include <openssl/ui_compat.h>
445
446#endif
diff --git a/src/lib/libcrypto/des/des_old2.c b/src/lib/libcrypto/des/des_old2.c
new file mode 100644
index 0000000000..c8fa3ee135
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old2.c
@@ -0,0 +1,82 @@
1/* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with OpenSSL 0.9.6c. OpenSSL now
7 * provides functions where "des_" has been replaced with "DES_" in
8 * the names, to make it possible to make incompatible changes that
9 * are needed for C type security and other stuff.
10 *
11 * Please consider starting to use the DES_ functions rather than the
12 * des_ ones. The des_ functions will dissapear completely before
13 * OpenSSL 1.0!
14 *
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16 */
17
18/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
19 * project 2001.
20 */
21/* ====================================================================
22 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 *
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 *
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 *
36 * 3. All advertising materials mentioning features or use of this
37 * software must display the following acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40 *
41 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42 * endorse or promote products derived from this software without
43 * prior written permission. For written permission, please contact
44 * openssl-core@openssl.org.
45 *
46 * 5. Products derived from this software may not be called "OpenSSL"
47 * nor may "OpenSSL" appear in their names without prior written
48 * permission of the OpenSSL Project.
49 *
50 * 6. Redistributions of any form whatsoever must retain the following
51 * acknowledgment:
52 * "This product includes software developed by the OpenSSL Project
53 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66 * OF THE POSSIBILITY OF SUCH DAMAGE.
67 * ====================================================================
68 *
69 * This product includes cryptographic software written by Eric Young
70 * (eay@cryptsoft.com). This product includes software written by Tim
71 * Hudson (tjh@cryptsoft.com).
72 *
73 */
74
75#undef OPENSSL_DES_LIBDES_COMPATIBILITY
76#include <openssl/des.h>
77#include <openssl/rand.h>
78
79void _ossl_096_des_random_seed(DES_cblock *key)
80 {
81 RAND_seed(key, sizeof(DES_cblock));
82 }
diff --git a/src/lib/libcrypto/des/des_opts.c b/src/lib/libcrypto/des/des_opts.c
new file mode 100644
index 0000000000..2df82962c5
--- /dev/null
+++ b/src/lib/libcrypto/des/des_opts.c
@@ -0,0 +1,608 @@
1/* crypto/des/des_opts.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
60 * This is for machines with 64k code segment size restrictions. */
61
62#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef OPENSSL_SYS_MSDOS
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD
70#else
71#include <io.h>
72extern void exit();
73#endif
74
75#ifndef OPENSSL_SYS_NETWARE
76#include <signal.h>
77#endif
78
79#ifndef _IRIX
80#include <time.h>
81#endif
82#ifdef TIMES
83#include <sys/types.h>
84#include <sys/times.h>
85#endif
86
87/* Depending on the VMS version, the tms structure is perhaps defined.
88 The __TMS macro will show if it was. If it wasn't defined, we should
89 undefine TIMES, since that tells the rest of the program how things
90 should be handled. -- Richard Levitte */
91#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
92#undef TIMES
93#endif
94
95#ifndef TIMES
96#include <sys/timeb.h>
97#endif
98
99
100#if defined(sun) || defined(__ultrix)
101#define _POSIX_SOURCE
102#include <limits.h>
103#include <sys/param.h>
104#endif
105
106#include <openssl/des.h>
107#include "spr.h"
108
109#define DES_DEFAULT_OPTIONS
110
111#if !defined(PART1) && !defined(PART2) && !defined(PART3) && !defined(PART4)
112#define PART1
113#define PART2
114#define PART3
115#define PART4
116#endif
117
118#ifdef PART1
119
120#undef DES_UNROLL
121#undef DES_RISC1
122#undef DES_RISC2
123#undef DES_PTR
124#undef D_ENCRYPT
125#define DES_encrypt1 des_encrypt_u4_cisc_idx
126#define DES_encrypt2 des_encrypt2_u4_cisc_idx
127#define DES_encrypt3 des_encrypt3_u4_cisc_idx
128#define DES_decrypt3 des_decrypt3_u4_cisc_idx
129#undef HEADER_DES_LOCL_H
130#include "des_enc.c"
131
132#define DES_UNROLL
133#undef DES_RISC1
134#undef DES_RISC2
135#undef DES_PTR
136#undef D_ENCRYPT
137#undef DES_encrypt1
138#undef DES_encrypt2
139#undef DES_encrypt3
140#undef DES_decrypt3
141#define DES_encrypt1 des_encrypt_u16_cisc_idx
142#define DES_encrypt2 des_encrypt2_u16_cisc_idx
143#define DES_encrypt3 des_encrypt3_u16_cisc_idx
144#define DES_decrypt3 des_decrypt3_u16_cisc_idx
145#undef HEADER_DES_LOCL_H
146#include "des_enc.c"
147
148#undef DES_UNROLL
149#define DES_RISC1
150#undef DES_RISC2
151#undef DES_PTR
152#undef D_ENCRYPT
153#undef DES_encrypt1
154#undef DES_encrypt2
155#undef DES_encrypt3
156#undef DES_decrypt3
157#define DES_encrypt1 des_encrypt_u4_risc1_idx
158#define DES_encrypt2 des_encrypt2_u4_risc1_idx
159#define DES_encrypt3 des_encrypt3_u4_risc1_idx
160#define DES_decrypt3 des_decrypt3_u4_risc1_idx
161#undef HEADER_DES_LOCL_H
162#include "des_enc.c"
163
164#endif
165
166#ifdef PART2
167
168#undef DES_UNROLL
169#undef DES_RISC1
170#define DES_RISC2
171#undef DES_PTR
172#undef D_ENCRYPT
173#undef DES_encrypt1
174#undef DES_encrypt2
175#undef DES_encrypt3
176#undef DES_decrypt3
177#define DES_encrypt1 des_encrypt_u4_risc2_idx
178#define DES_encrypt2 des_encrypt2_u4_risc2_idx
179#define DES_encrypt3 des_encrypt3_u4_risc2_idx
180#define DES_decrypt3 des_decrypt3_u4_risc2_idx
181#undef HEADER_DES_LOCL_H
182#include "des_enc.c"
183
184#define DES_UNROLL
185#define DES_RISC1
186#undef DES_RISC2
187#undef DES_PTR
188#undef D_ENCRYPT
189#undef DES_encrypt1
190#undef DES_encrypt2
191#undef DES_encrypt3
192#undef DES_decrypt3
193#define DES_encrypt1 des_encrypt_u16_risc1_idx
194#define DES_encrypt2 des_encrypt2_u16_risc1_idx
195#define DES_encrypt3 des_encrypt3_u16_risc1_idx
196#define DES_decrypt3 des_decrypt3_u16_risc1_idx
197#undef HEADER_DES_LOCL_H
198#include "des_enc.c"
199
200#define DES_UNROLL
201#undef DES_RISC1
202#define DES_RISC2
203#undef DES_PTR
204#undef D_ENCRYPT
205#undef DES_encrypt1
206#undef DES_encrypt2
207#undef DES_encrypt3
208#undef DES_decrypt3
209#define DES_encrypt1 des_encrypt_u16_risc2_idx
210#define DES_encrypt2 des_encrypt2_u16_risc2_idx
211#define DES_encrypt3 des_encrypt3_u16_risc2_idx
212#define DES_decrypt3 des_decrypt3_u16_risc2_idx
213#undef HEADER_DES_LOCL_H
214#include "des_enc.c"
215
216#endif
217
218#ifdef PART3
219
220#undef DES_UNROLL
221#undef DES_RISC1
222#undef DES_RISC2
223#define DES_PTR
224#undef D_ENCRYPT
225#undef DES_encrypt1
226#undef DES_encrypt2
227#undef DES_encrypt3
228#undef DES_decrypt3
229#define DES_encrypt1 des_encrypt_u4_cisc_ptr
230#define DES_encrypt2 des_encrypt2_u4_cisc_ptr
231#define DES_encrypt3 des_encrypt3_u4_cisc_ptr
232#define DES_decrypt3 des_decrypt3_u4_cisc_ptr
233#undef HEADER_DES_LOCL_H
234#include "des_enc.c"
235
236#define DES_UNROLL
237#undef DES_RISC1
238#undef DES_RISC2
239#define DES_PTR
240#undef D_ENCRYPT
241#undef DES_encrypt1
242#undef DES_encrypt2
243#undef DES_encrypt3
244#undef DES_decrypt3
245#define DES_encrypt1 des_encrypt_u16_cisc_ptr
246#define DES_encrypt2 des_encrypt2_u16_cisc_ptr
247#define DES_encrypt3 des_encrypt3_u16_cisc_ptr
248#define DES_decrypt3 des_decrypt3_u16_cisc_ptr
249#undef HEADER_DES_LOCL_H
250#include "des_enc.c"
251
252#undef DES_UNROLL
253#define DES_RISC1
254#undef DES_RISC2
255#define DES_PTR
256#undef D_ENCRYPT
257#undef DES_encrypt1
258#undef DES_encrypt2
259#undef DES_encrypt3
260#undef DES_decrypt3
261#define DES_encrypt1 des_encrypt_u4_risc1_ptr
262#define DES_encrypt2 des_encrypt2_u4_risc1_ptr
263#define DES_encrypt3 des_encrypt3_u4_risc1_ptr
264#define DES_decrypt3 des_decrypt3_u4_risc1_ptr
265#undef HEADER_DES_LOCL_H
266#include "des_enc.c"
267
268#endif
269
270#ifdef PART4
271
272#undef DES_UNROLL
273#undef DES_RISC1
274#define DES_RISC2
275#define DES_PTR
276#undef D_ENCRYPT
277#undef DES_encrypt1
278#undef DES_encrypt2
279#undef DES_encrypt3
280#undef DES_decrypt3
281#define DES_encrypt1 des_encrypt_u4_risc2_ptr
282#define DES_encrypt2 des_encrypt2_u4_risc2_ptr
283#define DES_encrypt3 des_encrypt3_u4_risc2_ptr
284#define DES_decrypt3 des_decrypt3_u4_risc2_ptr
285#undef HEADER_DES_LOCL_H
286#include "des_enc.c"
287
288#define DES_UNROLL
289#define DES_RISC1
290#undef DES_RISC2
291#define DES_PTR
292#undef D_ENCRYPT
293#undef DES_encrypt1
294#undef DES_encrypt2
295#undef DES_encrypt3
296#undef DES_decrypt3
297#define DES_encrypt1 des_encrypt_u16_risc1_ptr
298#define DES_encrypt2 des_encrypt2_u16_risc1_ptr
299#define DES_encrypt3 des_encrypt3_u16_risc1_ptr
300#define DES_decrypt3 des_decrypt3_u16_risc1_ptr
301#undef HEADER_DES_LOCL_H
302#include "des_enc.c"
303
304#define DES_UNROLL
305#undef DES_RISC1
306#define DES_RISC2
307#define DES_PTR
308#undef D_ENCRYPT
309#undef DES_encrypt1
310#undef DES_encrypt2
311#undef DES_encrypt3
312#undef DES_decrypt3
313#define DES_encrypt1 des_encrypt_u16_risc2_ptr
314#define DES_encrypt2 des_encrypt2_u16_risc2_ptr
315#define DES_encrypt3 des_encrypt3_u16_risc2_ptr
316#define DES_decrypt3 des_decrypt3_u16_risc2_ptr
317#undef HEADER_DES_LOCL_H
318#include "des_enc.c"
319
320#endif
321
322/* The following if from times(3) man page. It may need to be changed */
323#ifndef HZ
324# ifndef CLK_TCK
325# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
326# define HZ 100.0
327# else /* _BSD_CLK_TCK_ */
328# define HZ ((double)_BSD_CLK_TCK_)
329# endif
330# else /* CLK_TCK */
331# define HZ ((double)CLK_TCK)
332# endif
333#endif
334
335#define BUFSIZE ((long)1024)
336long run=0;
337
338double Time_F(int s);
339#ifdef SIGALRM
340#if defined(__STDC__) || defined(sgi)
341#define SIGRETTYPE void
342#else
343#define SIGRETTYPE int
344#endif
345
346SIGRETTYPE sig_done(int sig);
347SIGRETTYPE sig_done(int sig)
348 {
349 signal(SIGALRM,sig_done);
350 run=0;
351#ifdef LINT
352 sig=sig;
353#endif
354 }
355#endif
356
357#define START 0
358#define STOP 1
359
360double Time_F(int s)
361 {
362 double ret;
363#ifdef TIMES
364 static struct tms tstart,tend;
365
366 if (s == START)
367 {
368 times(&tstart);
369 return(0);
370 }
371 else
372 {
373 times(&tend);
374 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
375 return((ret == 0.0)?1e-6:ret);
376 }
377#else /* !times() */
378 static struct timeb tstart,tend;
379 long i;
380
381 if (s == START)
382 {
383 ftime(&tstart);
384 return(0);
385 }
386 else
387 {
388 ftime(&tend);
389 i=(long)tend.millitm-(long)tstart.millitm;
390 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
391 return((ret == 0.0)?1e-6:ret);
392 }
393#endif
394 }
395
396#ifdef SIGALRM
397#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
398#else
399#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
400#endif
401
402#define time_it(func,name,index) \
403 print_name(name); \
404 Time_F(START); \
405 for (count=0,run=1; COND(cb); count++) \
406 { \
407 unsigned long d[2]; \
408 func(d,&sch,DES_ENCRYPT); \
409 } \
410 tm[index]=Time_F(STOP); \
411 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
412 tm[index]=((double)COUNT(cb))/tm[index];
413
414#define print_it(name,index) \
415 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
416 tm[index]*8,1.0e6/tm[index]);
417
418int main(int argc, char **argv)
419 {
420 long count;
421 static unsigned char buf[BUFSIZE];
422 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
423 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
424 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
425 DES_key_schedule sch,sch2,sch3;
426 double d,tm[16],max=0;
427 int rank[16];
428 char *str[16];
429 int max_idx=0,i,num=0,j;
430#ifndef SIGALARM
431 long ca,cb,cc,cd,ce;
432#endif
433
434 for (i=0; i<12; i++)
435 {
436 tm[i]=0.0;
437 rank[i]=0;
438 }
439
440#ifndef TIMES
441 fprintf(stderr,"To get the most accurate results, try to run this\n");
442 fprintf(stderr,"program when this computer is idle.\n");
443#endif
444
445 DES_set_key_unchecked(&key,&sch);
446 DES_set_key_unchecked(&key2,&sch2);
447 DES_set_key_unchecked(&key3,&sch3);
448
449#ifndef SIGALRM
450 fprintf(stderr,"First we calculate the approximate speed ...\n");
451 DES_set_key_unchecked(&key,sch);
452 count=10;
453 do {
454 long i;
455 unsigned long data[2];
456
457 count*=2;
458 Time_F(START);
459 for (i=count; i; i--)
460 DES_encrypt1(data,&(sch[0]),DES_ENCRYPT);
461 d=Time_F(STOP);
462 } while (d < 3.0);
463 ca=count;
464 cb=count*3;
465 cc=count*3*8/BUFSIZE+1;
466 cd=count*8/BUFSIZE+1;
467
468 ce=count/20+1;
469#define COND(d) (count != (d))
470#define COUNT(d) (d)
471#else
472#define COND(c) (run)
473#define COUNT(d) (count)
474 signal(SIGALRM,sig_done);
475 alarm(10);
476#endif
477
478#ifdef PART1
479 time_it(des_encrypt_u4_cisc_idx, "des_encrypt_u4_cisc_idx ", 0);
480 time_it(des_encrypt_u16_cisc_idx, "des_encrypt_u16_cisc_idx ", 1);
481 time_it(des_encrypt_u4_risc1_idx, "des_encrypt_u4_risc1_idx ", 2);
482 num+=3;
483#endif
484#ifdef PART2
485 time_it(des_encrypt_u16_risc1_idx,"des_encrypt_u16_risc1_idx", 3);
486 time_it(des_encrypt_u4_risc2_idx, "des_encrypt_u4_risc2_idx ", 4);
487 time_it(des_encrypt_u16_risc2_idx,"des_encrypt_u16_risc2_idx", 5);
488 num+=3;
489#endif
490#ifdef PART3
491 time_it(des_encrypt_u4_cisc_ptr, "des_encrypt_u4_cisc_ptr ", 6);
492 time_it(des_encrypt_u16_cisc_ptr, "des_encrypt_u16_cisc_ptr ", 7);
493 time_it(des_encrypt_u4_risc1_ptr, "des_encrypt_u4_risc1_ptr ", 8);
494 num+=3;
495#endif
496#ifdef PART4
497 time_it(des_encrypt_u16_risc1_ptr,"des_encrypt_u16_risc1_ptr", 9);
498 time_it(des_encrypt_u4_risc2_ptr, "des_encrypt_u4_risc2_ptr ",10);
499 time_it(des_encrypt_u16_risc2_ptr,"des_encrypt_u16_risc2_ptr",11);
500 num+=3;
501#endif
502
503#ifdef PART1
504 str[0]=" 4 c i";
505 print_it("des_encrypt_u4_cisc_idx ",0);
506 max=tm[0];
507 max_idx=0;
508 str[1]="16 c i";
509 print_it("des_encrypt_u16_cisc_idx ",1);
510 if (max < tm[1]) { max=tm[1]; max_idx=1; }
511 str[2]=" 4 r1 i";
512 print_it("des_encrypt_u4_risc1_idx ",2);
513 if (max < tm[2]) { max=tm[2]; max_idx=2; }
514#endif
515#ifdef PART2
516 str[3]="16 r1 i";
517 print_it("des_encrypt_u16_risc1_idx",3);
518 if (max < tm[3]) { max=tm[3]; max_idx=3; }
519 str[4]=" 4 r2 i";
520 print_it("des_encrypt_u4_risc2_idx ",4);
521 if (max < tm[4]) { max=tm[4]; max_idx=4; }
522 str[5]="16 r2 i";
523 print_it("des_encrypt_u16_risc2_idx",5);
524 if (max < tm[5]) { max=tm[5]; max_idx=5; }
525#endif
526#ifdef PART3
527 str[6]=" 4 c p";
528 print_it("des_encrypt_u4_cisc_ptr ",6);
529 if (max < tm[6]) { max=tm[6]; max_idx=6; }
530 str[7]="16 c p";
531 print_it("des_encrypt_u16_cisc_ptr ",7);
532 if (max < tm[7]) { max=tm[7]; max_idx=7; }
533 str[8]=" 4 r1 p";
534 print_it("des_encrypt_u4_risc1_ptr ",8);
535 if (max < tm[8]) { max=tm[8]; max_idx=8; }
536#endif
537#ifdef PART4
538 str[9]="16 r1 p";
539 print_it("des_encrypt_u16_risc1_ptr",9);
540 if (max < tm[9]) { max=tm[9]; max_idx=9; }
541 str[10]=" 4 r2 p";
542 print_it("des_encrypt_u4_risc2_ptr ",10);
543 if (max < tm[10]) { max=tm[10]; max_idx=10; }
544 str[11]="16 r2 p";
545 print_it("des_encrypt_u16_risc2_ptr",11);
546 if (max < tm[11]) { max=tm[11]; max_idx=11; }
547#endif
548 printf("options des ecb/s\n");
549 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
550 d=tm[max_idx];
551 tm[max_idx]= -2.0;
552 max= -1.0;
553 for (;;)
554 {
555 for (i=0; i<12; i++)
556 {
557 if (max < tm[i]) { max=tm[i]; j=i; }
558 }
559 if (max < 0.0) break;
560 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
561 tm[j]= -2.0;
562 max= -1.0;
563 }
564
565 switch (max_idx)
566 {
567 case 0:
568 printf("-DDES_DEFAULT_OPTIONS\n");
569 break;
570 case 1:
571 printf("-DDES_UNROLL\n");
572 break;
573 case 2:
574 printf("-DDES_RISC1\n");
575 break;
576 case 3:
577 printf("-DDES_UNROLL -DDES_RISC1\n");
578 break;
579 case 4:
580 printf("-DDES_RISC2\n");
581 break;
582 case 5:
583 printf("-DDES_UNROLL -DDES_RISC2\n");
584 break;
585 case 6:
586 printf("-DDES_PTR\n");
587 break;
588 case 7:
589 printf("-DDES_UNROLL -DDES_PTR\n");
590 break;
591 case 8:
592 printf("-DDES_RISC1 -DDES_PTR\n");
593 break;
594 case 9:
595 printf("-DDES_UNROLL -DDES_RISC1 -DDES_PTR\n");
596 break;
597 case 10:
598 printf("-DDES_RISC2 -DDES_PTR\n");
599 break;
600 case 11:
601 printf("-DDES_UNROLL -DDES_RISC2 -DDES_PTR\n");
602 break;
603 }
604 exit(0);
605#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
606 return(0);
607#endif
608 }
diff --git a/src/lib/libcrypto/des/des_ver.h b/src/lib/libcrypto/des/des_ver.h
new file mode 100644
index 0000000000..d1ada258a6
--- /dev/null
+++ b/src/lib/libcrypto/des/des_ver.h
@@ -0,0 +1,71 @@
1/* crypto/des/des_ver.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/e_os2.h>
60
61#ifdef OPENSSL_BUILD_SHLIBCRYPTO
62# undef OPENSSL_EXTERN
63# define OPENSSL_EXTERN OPENSSL_EXPORT
64#endif
65
66/* The following macros make sure the names are different from libdes names */
67#define DES_version OSSL_DES_version
68#define libdes_version OSSL_libdes_version
69
70OPENSSL_EXTERN const char OSSL_DES_version[]; /* SSLeay version string */
71OPENSSL_EXTERN const char OSSL_libdes_version[]; /* old libdes version string */
diff --git a/src/lib/libcrypto/des/dess.cpp b/src/lib/libcrypto/des/dess.cpp
new file mode 100644
index 0000000000..5549bab90a
--- /dev/null
+++ b/src/lib/libcrypto/des/dess.cpp
@@ -0,0 +1,67 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/des.h>
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt1(&data[0],key,1);
49 GetTSC(s1);
50 des_encrypt1(&data[0],key,1);
51 des_encrypt1(&data[0],key,1);
52 des_encrypt1(&data[0],key,1);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt1(&data[0],key,1);
56 des_encrypt1(&data[0],key,1);
57 des_encrypt1(&data[0],key,1);
58 des_encrypt1(&data[0],key,1);
59 GetTSC(e2);
60 des_encrypt1(&data[0],key,1);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c
new file mode 100644
index 0000000000..64b92a34fe
--- /dev/null
+++ b/src/lib/libcrypto/des/destest.c
@@ -0,0 +1,952 @@
1/* crypto/des/destest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61
62#include <openssl/e_os2.h>
63#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_WINDOWS)
64#ifndef OPENSSL_SYS_MSDOS
65#define OPENSSL_SYS_MSDOS
66#endif
67#endif
68
69#ifndef OPENSSL_SYS_MSDOS
70#if !defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_VMS_DECC)
71#include OPENSSL_UNISTD
72#endif
73#else
74#include <io.h>
75#endif
76#include <string.h>
77
78#ifdef OPENSSL_NO_DES
79int main(int argc, char *argv[])
80{
81 printf("No DES support\n");
82 return(0);
83}
84#else
85#include <openssl/des.h>
86
87#define crypt(c,s) (DES_crypt((c),(s)))
88
89/* tisk tisk - the test keys don't all have odd parity :-( */
90/* test data */
91#define NUM_TESTS 34
92static unsigned char key_data[NUM_TESTS][8]={
93 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
94 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
95 {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
96 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
97 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
98 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
99 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
100 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
101 {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
102 {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
103 {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
104 {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
105 {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
106 {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
107 {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
108 {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
109 {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
110 {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
111 {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
112 {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
113 {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
114 {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
115 {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
116 {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
117 {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
118 {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
119 {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
120 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
121 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
122 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
123 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
124 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
125 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
126 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
127
128static unsigned char plain_data[NUM_TESTS][8]={
129 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
130 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
131 {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
132 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
133 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
134 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
135 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
136 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
137 {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
138 {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
139 {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
140 {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
141 {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
142 {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
143 {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
144 {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
145 {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
146 {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
147 {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
148 {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
149 {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
150 {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
151 {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
152 {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
153 {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
154 {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
155 {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
156 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
157 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
158 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
159 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
160 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
161 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
162 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
163
164static unsigned char cipher_data[NUM_TESTS][8]={
165 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
166 {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58},
167 {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B},
168 {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33},
169 {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D},
170 {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD},
171 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
172 {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4},
173 {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B},
174 {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71},
175 {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A},
176 {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A},
177 {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95},
178 {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B},
179 {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09},
180 {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A},
181 {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F},
182 {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88},
183 {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77},
184 {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A},
185 {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56},
186 {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56},
187 {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56},
188 {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC},
189 {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A},
190 {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41},
191 {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93},
192 {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00},
193 {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06},
194 {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7},
195 {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51},
196 {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE},
197 {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D},
198 {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}};
199
200static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
201 {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E},
202 {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16},
203 {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27},
204 {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6},
205 {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25},
206 {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A},
207 {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74},
208 {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6},
209 {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67},
210 {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10},
211 {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85},
212 {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA},
213 {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3},
214 {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3},
215 {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A},
216 {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69},
217 {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1},
218 {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7},
219 {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F},
220 {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87},
221 {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A},
222 {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE},
223 {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3},
224 {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD},
225 {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84},
226 {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85},
227 {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC},
228 {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89},
229 {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E},
230 {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89},
231 {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7},
232 {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8},
233 {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
234
235static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
236static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86};
237static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
238static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
239/* Changed the following text constant to binary so it will work on ebcdic
240 * machines :-) */
241/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
242static unsigned char cbc_data[40]={
243 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20,
244 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74,
245 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20,
246 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00,
247 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
248 };
249
250static unsigned char cbc_ok[32]={
251 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
252 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb,
253 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
254 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
255
256#ifdef SCREW_THE_PARITY
257#error "SCREW_THE_PARITY is not ment to be defined."
258#error "Original vectors are preserved for reference only."
259static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
260static unsigned char xcbc_ok[32]={
261 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48,
262 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD,
263 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76,
264 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2,
265 };
266#else
267static unsigned char xcbc_ok[32]={
268 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29,
269 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1,
270 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53,
271 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4,
272 };
273#endif
274
275static unsigned char cbc3_ok[32]={
276 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0,
277 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC,
278 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4,
279 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75};
280
281static unsigned char pcbc_ok[32]={
282 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
283 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15,
284 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f,
285 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88};
286
287static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
288static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
289static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
290static unsigned char plain[24]=
291 {
292 0x4e,0x6f,0x77,0x20,0x69,0x73,
293 0x20,0x74,0x68,0x65,0x20,0x74,
294 0x69,0x6d,0x65,0x20,0x66,0x6f,
295 0x72,0x20,0x61,0x6c,0x6c,0x20
296 };
297static unsigned char cfb_cipher8[24]= {
298 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8,
299 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 };
300static unsigned char cfb_cipher16[24]={
301 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70,
302 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B };
303static unsigned char cfb_cipher32[24]={
304 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD,
305 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 };
306static unsigned char cfb_cipher48[24]={
307 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85,
308 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F };
309static unsigned char cfb_cipher64[24]={
310 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B,
311 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 };
312
313static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
314static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
315static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8];
316static unsigned char ofb_cipher[24]=
317 {
318 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
319 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
320 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
321 };
322
323#if 0
324static DES_LONG cbc_cksum_ret=0xB462FEF7L;
325#else
326static DES_LONG cbc_cksum_ret=0xF7FE62B4L;
327#endif
328static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
329
330static char *pt(unsigned char *p);
331static int cfb_test(int bits, unsigned char *cfb_cipher);
332static int cfb64_test(unsigned char *cfb_cipher);
333static int ede_cfb64_test(unsigned char *cfb_cipher);
334int main(int argc, char *argv[])
335 {
336 int j,err=0;
337 unsigned int i;
338 des_cblock in,out,outin,iv3,iv2;
339 des_key_schedule ks,ks2,ks3;
340 unsigned char cbc_in[40];
341 unsigned char cbc_out[40];
342 DES_LONG cs;
343 unsigned char cret[8];
344#ifdef _CRAY
345 struct {
346 int a:32;
347 int b:32;
348 } lqret[2];
349#else
350 DES_LONG lqret[4];
351#endif
352 int num;
353 char *str;
354
355#ifndef OPENSSL_NO_DESCBCM
356 printf("Doing cbcm\n");
357 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
358 {
359 printf("Key error %d\n",j);
360 err=1;
361 }
362 if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
363 {
364 printf("Key error %d\n",j);
365 err=1;
366 }
367 if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
368 {
369 printf("Key error %d\n",j);
370 err=1;
371 }
372 memset(cbc_out,0,40);
373 memset(cbc_in,0,40);
374 i=strlen((char *)cbc_data)+1;
375 /* i=((i+7)/8)*8; */
376 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
377 memset(iv2,'\0',sizeof iv2);
378
379 DES_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,&ks,&ks2,&ks3,&iv3,&iv2,
380 DES_ENCRYPT);
381 DES_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,&ks,&ks2,&ks3,
382 &iv3,&iv2,DES_ENCRYPT);
383 /* if (memcmp(cbc_out,cbc3_ok,
384 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
385 {
386 printf("des_ede3_cbc_encrypt encrypt error\n");
387 err=1;
388 }
389 */
390 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
391 memset(iv2,'\0',sizeof iv2);
392 DES_ede3_cbcm_encrypt(cbc_out,cbc_in,i,&ks,&ks2,&ks3,&iv3,&iv2,DES_DECRYPT);
393 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
394 {
395 unsigned int n;
396
397 printf("des_ede3_cbcm_encrypt decrypt error\n");
398 for(n=0 ; n < i ; ++n)
399 printf(" %02x",cbc_data[n]);
400 printf("\n");
401 for(n=0 ; n < i ; ++n)
402 printf(" %02x",cbc_in[n]);
403 printf("\n");
404 err=1;
405 }
406#endif
407
408 printf("Doing ecb\n");
409 for (i=0; i<NUM_TESTS; i++)
410 {
411 DES_set_key_unchecked(&key_data[i],&ks);
412 memcpy(in,plain_data[i],8);
413 memset(out,0,8);
414 memset(outin,0,8);
415 des_ecb_encrypt(&in,&out,ks,DES_ENCRYPT);
416 des_ecb_encrypt(&out,&outin,ks,DES_DECRYPT);
417
418 if (memcmp(out,cipher_data[i],8) != 0)
419 {
420 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
421 i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]),
422 pt(out));
423 err=1;
424 }
425 if (memcmp(in,outin,8) != 0)
426 {
427 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
428 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
429 err=1;
430 }
431 }
432
433#ifndef LIBDES_LIT
434 printf("Doing ede ecb\n");
435 for (i=0; i<(NUM_TESTS-2); i++)
436 {
437 DES_set_key_unchecked(&key_data[i],&ks);
438 DES_set_key_unchecked(&key_data[i+1],&ks2);
439 DES_set_key_unchecked(&key_data[i+2],&ks3);
440 memcpy(in,plain_data[i],8);
441 memset(out,0,8);
442 memset(outin,0,8);
443 des_ecb2_encrypt(&in,&out,ks,ks2,DES_ENCRYPT);
444 des_ecb2_encrypt(&out,&outin,ks,ks2,DES_DECRYPT);
445
446 if (memcmp(out,cipher_ecb2[i],8) != 0)
447 {
448 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
449 i+1,pt(key_data[i]),pt(in),pt(cipher_ecb2[i]),
450 pt(out));
451 err=1;
452 }
453 if (memcmp(in,outin,8) != 0)
454 {
455 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
456 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
457 err=1;
458 }
459 }
460#endif
461
462 printf("Doing cbc\n");
463 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
464 {
465 printf("Key error %d\n",j);
466 err=1;
467 }
468 memset(cbc_out,0,40);
469 memset(cbc_in,0,40);
470 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
471 des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
472 &iv3,DES_ENCRYPT);
473 if (memcmp(cbc_out,cbc_ok,32) != 0)
474 {
475 printf("cbc_encrypt encrypt error\n");
476 err=1;
477 }
478
479 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
480 des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
481 &iv3,DES_DECRYPT);
482 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0)
483 {
484 printf("cbc_encrypt decrypt error\n");
485 err=1;
486 }
487
488#ifndef LIBDES_LIT
489 printf("Doing desx cbc\n");
490 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
491 {
492 printf("Key error %d\n",j);
493 err=1;
494 }
495 memset(cbc_out,0,40);
496 memset(cbc_in,0,40);
497 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
498 des_xcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
499 &iv3,&cbc2_key,&cbc3_key, DES_ENCRYPT);
500 if (memcmp(cbc_out,xcbc_ok,32) != 0)
501 {
502 printf("des_xcbc_encrypt encrypt error\n");
503 err=1;
504 }
505 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
506 des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
507 &iv3,&cbc2_key,&cbc3_key, DES_DECRYPT);
508 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
509 {
510 printf("des_xcbc_encrypt decrypt error\n");
511 err=1;
512 }
513#endif
514
515 printf("Doing ede cbc\n");
516 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
517 {
518 printf("Key error %d\n",j);
519 err=1;
520 }
521 if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
522 {
523 printf("Key error %d\n",j);
524 err=1;
525 }
526 if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
527 {
528 printf("Key error %d\n",j);
529 err=1;
530 }
531 memset(cbc_out,0,40);
532 memset(cbc_in,0,40);
533 i=strlen((char *)cbc_data)+1;
534 /* i=((i+7)/8)*8; */
535 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
536
537 des_ede3_cbc_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,&iv3,
538 DES_ENCRYPT);
539 des_ede3_cbc_encrypt(&(cbc_data[16]),&(cbc_out[16]),i-16,ks,ks2,ks3,
540 &iv3,DES_ENCRYPT);
541 if (memcmp(cbc_out,cbc3_ok,
542 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
543 {
544 unsigned int n;
545
546 printf("des_ede3_cbc_encrypt encrypt error\n");
547 for(n=0 ; n < i ; ++n)
548 printf(" %02x",cbc_out[n]);
549 printf("\n");
550 for(n=0 ; n < i ; ++n)
551 printf(" %02x",cbc3_ok[n]);
552 printf("\n");
553 err=1;
554 }
555
556 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
557 des_ede3_cbc_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,DES_DECRYPT);
558 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
559 {
560 unsigned int n;
561
562 printf("des_ede3_cbc_encrypt decrypt error\n");
563 for(n=0 ; n < i ; ++n)
564 printf(" %02x",cbc_data[n]);
565 printf("\n");
566 for(n=0 ; n < i ; ++n)
567 printf(" %02x",cbc_in[n]);
568 printf("\n");
569 err=1;
570 }
571
572#ifndef LIBDES_LIT
573 printf("Doing pcbc\n");
574 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
575 {
576 printf("Key error %d\n",j);
577 err=1;
578 }
579 memset(cbc_out,0,40);
580 memset(cbc_in,0,40);
581 des_pcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
582 &cbc_iv,DES_ENCRYPT);
583 if (memcmp(cbc_out,pcbc_ok,32) != 0)
584 {
585 printf("pcbc_encrypt encrypt error\n");
586 err=1;
587 }
588 des_pcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,&cbc_iv,
589 DES_DECRYPT);
590 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
591 {
592 printf("pcbc_encrypt decrypt error\n");
593 err=1;
594 }
595
596 printf("Doing ");
597 printf("cfb8 ");
598 err+=cfb_test(8,cfb_cipher8);
599 printf("cfb16 ");
600 err+=cfb_test(16,cfb_cipher16);
601 printf("cfb32 ");
602 err+=cfb_test(32,cfb_cipher32);
603 printf("cfb48 ");
604 err+=cfb_test(48,cfb_cipher48);
605 printf("cfb64 ");
606 err+=cfb_test(64,cfb_cipher64);
607
608 printf("cfb64() ");
609 err+=cfb64_test(cfb_cipher64);
610
611 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
612 for (i=0; i<sizeof(plain); i++)
613 des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]),
614 8,1,ks,&cfb_tmp,DES_ENCRYPT);
615 if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
616 {
617 printf("cfb_encrypt small encrypt error\n");
618 err=1;
619 }
620
621 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
622 for (i=0; i<sizeof(plain); i++)
623 des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
624 8,1,ks,&cfb_tmp,DES_DECRYPT);
625 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
626 {
627 printf("cfb_encrypt small decrypt error\n");
628 err=1;
629 }
630
631 printf("ede_cfb64() ");
632 err+=ede_cfb64_test(cfb_cipher64);
633
634 printf("done\n");
635
636 printf("Doing ofb\n");
637 DES_set_key_checked(&ofb_key,&ks);
638 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
639 des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp);
640 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
641 {
642 printf("ofb_encrypt encrypt error\n");
643printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
644ofb_buf1[8+0], ofb_buf1[8+1], ofb_buf1[8+2], ofb_buf1[8+3],
645ofb_buf1[8+4], ofb_buf1[8+5], ofb_buf1[8+6], ofb_buf1[8+7]);
646printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
647ofb_buf1[8+0], ofb_cipher[8+1], ofb_cipher[8+2], ofb_cipher[8+3],
648ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]);
649 err=1;
650 }
651 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
652 des_ofb_encrypt(ofb_buf1,ofb_buf2,64,sizeof(ofb_buf1)/8,ks,&ofb_tmp);
653 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
654 {
655 printf("ofb_encrypt decrypt error\n");
656printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
657ofb_buf2[8+0], ofb_buf2[8+1], ofb_buf2[8+2], ofb_buf2[8+3],
658ofb_buf2[8+4], ofb_buf2[8+5], ofb_buf2[8+6], ofb_buf2[8+7]);
659printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
660plain[8+0], plain[8+1], plain[8+2], plain[8+3],
661plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
662 err=1;
663 }
664
665 printf("Doing ofb64\n");
666 DES_set_key_checked(&ofb_key,&ks);
667 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
668 memset(ofb_buf1,0,sizeof(ofb_buf1));
669 memset(ofb_buf2,0,sizeof(ofb_buf1));
670 num=0;
671 for (i=0; i<sizeof(plain); i++)
672 {
673 des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,&ofb_tmp,
674 &num);
675 }
676 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
677 {
678 printf("ofb64_encrypt encrypt error\n");
679 err=1;
680 }
681 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
682 num=0;
683 des_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,&ofb_tmp,
684 &num);
685 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
686 {
687 printf("ofb64_encrypt decrypt error\n");
688 err=1;
689 }
690
691 printf("Doing ede_ofb64\n");
692 DES_set_key_checked(&ofb_key,&ks);
693 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
694 memset(ofb_buf1,0,sizeof(ofb_buf1));
695 memset(ofb_buf2,0,sizeof(ofb_buf1));
696 num=0;
697 for (i=0; i<sizeof(plain); i++)
698 {
699 des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,
700 ks,&ofb_tmp,&num);
701 }
702 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
703 {
704 printf("ede_ofb64_encrypt encrypt error\n");
705 err=1;
706 }
707 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
708 num=0;
709 des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,ks,ks,
710 &ofb_tmp,&num);
711 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
712 {
713 printf("ede_ofb64_encrypt decrypt error\n");
714 err=1;
715 }
716
717 printf("Doing cbc_cksum\n");
718 DES_set_key_checked(&cbc_key,&ks);
719 cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv);
720 if (cs != cbc_cksum_ret)
721 {
722 printf("bad return value (%08lX), should be %08lX\n",
723 (unsigned long)cs,(unsigned long)cbc_cksum_ret);
724 err=1;
725 }
726 if (memcmp(cret,cbc_cksum_data,8) != 0)
727 {
728 printf("bad cbc_cksum block returned\n");
729 err=1;
730 }
731
732 printf("Doing quad_cksum\n");
733 cs=des_quad_cksum(cbc_data,(des_cblock *)lqret,
734 (long)strlen((char *)cbc_data),2,(des_cblock *)cbc_iv);
735 if (cs != 0x70d7a63aL)
736 {
737 printf("quad_cksum error, ret %08lx should be 70d7a63a\n",
738 (unsigned long)cs);
739 err=1;
740 }
741#ifdef _CRAY
742 if (lqret[0].a != 0x327eba8dL)
743 {
744 printf("quad_cksum error, out[0] %08lx is not %08lx\n",
745 (unsigned long)lqret[0].a,0x327eba8dUL);
746 err=1;
747 }
748 if (lqret[0].b != 0x201a49ccL)
749 {
750 printf("quad_cksum error, out[1] %08lx is not %08lx\n",
751 (unsigned long)lqret[0].b,0x201a49ccUL);
752 err=1;
753 }
754 if (lqret[1].a != 0x70d7a63aL)
755 {
756 printf("quad_cksum error, out[2] %08lx is not %08lx\n",
757 (unsigned long)lqret[1].a,0x70d7a63aUL);
758 err=1;
759 }
760 if (lqret[1].b != 0x501c2c26L)
761 {
762 printf("quad_cksum error, out[3] %08lx is not %08lx\n",
763 (unsigned long)lqret[1].b,0x501c2c26UL);
764 err=1;
765 }
766#else
767 if (lqret[0] != 0x327eba8dL)
768 {
769 printf("quad_cksum error, out[0] %08lx is not %08lx\n",
770 (unsigned long)lqret[0],0x327eba8dUL);
771 err=1;
772 }
773 if (lqret[1] != 0x201a49ccL)
774 {
775 printf("quad_cksum error, out[1] %08lx is not %08lx\n",
776 (unsigned long)lqret[1],0x201a49ccUL);
777 err=1;
778 }
779 if (lqret[2] != 0x70d7a63aL)
780 {
781 printf("quad_cksum error, out[2] %08lx is not %08lx\n",
782 (unsigned long)lqret[2],0x70d7a63aUL);
783 err=1;
784 }
785 if (lqret[3] != 0x501c2c26L)
786 {
787 printf("quad_cksum error, out[3] %08lx is not %08lx\n",
788 (unsigned long)lqret[3],0x501c2c26UL);
789 err=1;
790 }
791#endif
792#endif
793
794 printf("input word alignment test");
795 for (i=0; i<4; i++)
796 {
797 printf(" %d",i);
798 des_ncbc_encrypt(&(cbc_out[i]),cbc_in,
799 strlen((char *)cbc_data)+1,ks,
800 &cbc_iv,DES_ENCRYPT);
801 }
802 printf("\noutput word alignment test");
803 for (i=0; i<4; i++)
804 {
805 printf(" %d",i);
806 des_ncbc_encrypt(cbc_out,&(cbc_in[i]),
807 strlen((char *)cbc_data)+1,ks,
808 &cbc_iv,DES_ENCRYPT);
809 }
810 printf("\n");
811 printf("fast crypt test ");
812 str=crypt("testing","ef");
813 if (strcmp("efGnQx2725bI2",str) != 0)
814 {
815 printf("fast crypt error, %s should be efGnQx2725bI2\n",str);
816 err=1;
817 }
818 str=crypt("bca76;23","yA");
819 if (strcmp("yA1Rp/1hZXIJk",str) != 0)
820 {
821 printf("fast crypt error, %s should be yA1Rp/1hZXIJk\n",str);
822 err=1;
823 }
824#ifdef OPENSSL_SYS_NETWARE
825 if (err) printf("ERROR: %d\n", err);
826#endif
827 printf("\n");
828 return(err);
829 }
830
831static char *pt(unsigned char *p)
832 {
833 static char bufs[10][20];
834 static int bnum=0;
835 char *ret;
836 int i;
837 static char *f="0123456789ABCDEF";
838
839 ret= &(bufs[bnum++][0]);
840 bnum%=10;
841 for (i=0; i<8; i++)
842 {
843 ret[i*2]=f[(p[i]>>4)&0xf];
844 ret[i*2+1]=f[p[i]&0xf];
845 }
846 ret[16]='\0';
847 return(ret);
848 }
849
850#ifndef LIBDES_LIT
851
852static int cfb_test(int bits, unsigned char *cfb_cipher)
853 {
854 des_key_schedule ks;
855 int i,err=0;
856
857 DES_set_key_checked(&cfb_key,&ks);
858 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
859 des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp,
860 DES_ENCRYPT);
861 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
862 {
863 err=1;
864 printf("cfb_encrypt encrypt error\n");
865 for (i=0; i<24; i+=8)
866 printf("%s\n",pt(&(cfb_buf1[i])));
867 }
868 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
869 des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp,
870 DES_DECRYPT);
871 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
872 {
873 err=1;
874 printf("cfb_encrypt decrypt error\n");
875 for (i=0; i<24; i+=8)
876 printf("%s\n",pt(&(cfb_buf1[i])));
877 }
878 return(err);
879 }
880
881static int cfb64_test(unsigned char *cfb_cipher)
882 {
883 des_key_schedule ks;
884 int err=0,i,n;
885
886 DES_set_key_checked(&cfb_key,&ks);
887 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
888 n=0;
889 des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT);
890 des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks,
891 &cfb_tmp,&n,DES_ENCRYPT);
892 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
893 {
894 err=1;
895 printf("cfb_encrypt encrypt error\n");
896 for (i=0; i<24; i+=8)
897 printf("%s\n",pt(&(cfb_buf1[i])));
898 }
899 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
900 n=0;
901 des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT);
902 des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
903 sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT);
904 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
905 {
906 err=1;
907 printf("cfb_encrypt decrypt error\n");
908 for (i=0; i<24; i+=8)
909 printf("%s\n",pt(&(cfb_buf2[i])));
910 }
911 return(err);
912 }
913
914static int ede_cfb64_test(unsigned char *cfb_cipher)
915 {
916 des_key_schedule ks;
917 int err=0,i,n;
918
919 DES_set_key_checked(&cfb_key,&ks);
920 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
921 n=0;
922 des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n,
923 DES_ENCRYPT);
924 des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
925 sizeof(plain)-12,ks,ks,ks,
926 &cfb_tmp,&n,DES_ENCRYPT);
927 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
928 {
929 err=1;
930 printf("ede_cfb_encrypt encrypt error\n");
931 for (i=0; i<24; i+=8)
932 printf("%s\n",pt(&(cfb_buf1[i])));
933 }
934 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
935 n=0;
936 des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,
937 &cfb_tmp,&n,DES_DECRYPT);
938 des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
939 sizeof(plain)-17,ks,ks,ks,
940 &cfb_tmp,&n,DES_DECRYPT);
941 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
942 {
943 err=1;
944 printf("ede_cfb_encrypt decrypt error\n");
945 for (i=0; i<24; i+=8)
946 printf("%s\n",pt(&(cfb_buf2[i])));
947 }
948 return(err);
949 }
950
951#endif
952#endif
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c
new file mode 100644
index 0000000000..c3437bc606
--- /dev/null
+++ b/src/lib/libcrypto/des/ecb3_enc.c
@@ -0,0 +1,83 @@
1/* crypto/des/ecb3_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
61void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
62 DES_key_schedule *ks1, DES_key_schedule *ks2,
63 DES_key_schedule *ks3,
64 int enc)
65 {
66 register DES_LONG l0,l1;
67 DES_LONG ll[2];
68 const unsigned char *in = &(*input)[0];
69 unsigned char *out = &(*output)[0];
70
71 c2l(in,l0);
72 c2l(in,l1);
73 ll[0]=l0;
74 ll[1]=l1;
75 if (enc)
76 DES_encrypt3(ll,ks1,ks2,ks3);
77 else
78 DES_decrypt3(ll,ks1,ks2,ks3);
79 l0=ll[0];
80 l1=ll[1];
81 l2c(l0,out);
82 l2c(l1,out);
83 }
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c
new file mode 100644
index 0000000000..00d5b91e8c
--- /dev/null
+++ b/src/lib/libcrypto/des/ecb_enc.c
@@ -0,0 +1,123 @@
1/* crypto/des/ecb_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#include "des_ver.h"
61#include "spr.h"
62#include <openssl/opensslv.h>
63#include <openssl/bio.h>
64
65OPENSSL_GLOBAL const char libdes_version[]="libdes" OPENSSL_VERSION_PTEXT;
66OPENSSL_GLOBAL const char DES_version[]="DES" OPENSSL_VERSION_PTEXT;
67
68const char *DES_options(void)
69 {
70 static int init=1;
71 static char buf[32];
72
73 if (init)
74 {
75 const char *ptr,*unroll,*risc,*size;
76
77#ifdef DES_PTR
78 ptr="ptr";
79#else
80 ptr="idx";
81#endif
82#if defined(DES_RISC1) || defined(DES_RISC2)
83#ifdef DES_RISC1
84 risc="risc1";
85#endif
86#ifdef DES_RISC2
87 risc="risc2";
88#endif
89#else
90 risc="cisc";
91#endif
92#ifdef DES_UNROLL
93 unroll="16";
94#else
95 unroll="4";
96#endif
97 if (sizeof(DES_LONG) != sizeof(long))
98 size="int";
99 else
100 size="long";
101 BIO_snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,
102 size);
103 init=0;
104 }
105 return(buf);
106 }
107
108
109void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
110 DES_key_schedule *ks, int enc)
111 {
112 register DES_LONG l;
113 DES_LONG ll[2];
114 const unsigned char *in = &(*input)[0];
115 unsigned char *out = &(*output)[0];
116
117 c2l(in,l); ll[0]=l;
118 c2l(in,l); ll[1]=l;
119 DES_encrypt1(ll,ks,enc);
120 l=ll[0]; l2c(l,out);
121 l=ll[1]; l2c(l,out);
122 l=ll[0]=ll[1]=0;
123 }
diff --git a/src/lib/libcrypto/des/ede_cbcm_enc.c b/src/lib/libcrypto/des/ede_cbcm_enc.c
new file mode 100644
index 0000000000..adfcb75cf3
--- /dev/null
+++ b/src/lib/libcrypto/des/ede_cbcm_enc.c
@@ -0,0 +1,199 @@
1/* ede_cbcm_enc.c */
2/* Written by Ben Laurie <ben@algroup.co.uk> for the OpenSSL
3 * project 13 Feb 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/*
60
61This is an implementation of Triple DES Cipher Block Chaining with Output
62Feedback Masking, by Coppersmith, Johnson and Matyas, (IBM and Certicom).
63
64Note that there is a known attack on this by Biham and Knudsen but it takes
65a lot of work:
66
67http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/1998/CS/CS0928.ps.gz
68
69*/
70
71#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_DESCBCM is defined */
72
73#ifndef OPENSSL_NO_DESCBCM
74#include "des_locl.h"
75
76void DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
77 long length, DES_key_schedule *ks1, DES_key_schedule *ks2,
78 DES_key_schedule *ks3, DES_cblock *ivec1, DES_cblock *ivec2,
79 int enc)
80 {
81 register DES_LONG tin0,tin1;
82 register DES_LONG tout0,tout1,xor0,xor1,m0,m1;
83 register long l=length;
84 DES_LONG tin[2];
85 unsigned char *iv1,*iv2;
86
87 iv1 = &(*ivec1)[0];
88 iv2 = &(*ivec2)[0];
89
90 if (enc)
91 {
92 c2l(iv1,m0);
93 c2l(iv1,m1);
94 c2l(iv2,tout0);
95 c2l(iv2,tout1);
96 for (l-=8; l>=-7; l-=8)
97 {
98 tin[0]=m0;
99 tin[1]=m1;
100 DES_encrypt1(tin,ks3,1);
101 m0=tin[0];
102 m1=tin[1];
103
104 if(l < 0)
105 {
106 c2ln(in,tin0,tin1,l+8);
107 }
108 else
109 {
110 c2l(in,tin0);
111 c2l(in,tin1);
112 }
113 tin0^=tout0;
114 tin1^=tout1;
115
116 tin[0]=tin0;
117 tin[1]=tin1;
118 DES_encrypt1(tin,ks1,1);
119 tin[0]^=m0;
120 tin[1]^=m1;
121 DES_encrypt1(tin,ks2,0);
122 tin[0]^=m0;
123 tin[1]^=m1;
124 DES_encrypt1(tin,ks1,1);
125 tout0=tin[0];
126 tout1=tin[1];
127
128 l2c(tout0,out);
129 l2c(tout1,out);
130 }
131 iv1=&(*ivec1)[0];
132 l2c(m0,iv1);
133 l2c(m1,iv1);
134
135 iv2=&(*ivec2)[0];
136 l2c(tout0,iv2);
137 l2c(tout1,iv2);
138 }
139 else
140 {
141 register DES_LONG t0,t1;
142
143 c2l(iv1,m0);
144 c2l(iv1,m1);
145 c2l(iv2,xor0);
146 c2l(iv2,xor1);
147 for (l-=8; l>=-7; l-=8)
148 {
149 tin[0]=m0;
150 tin[1]=m1;
151 DES_encrypt1(tin,ks3,1);
152 m0=tin[0];
153 m1=tin[1];
154
155 c2l(in,tin0);
156 c2l(in,tin1);
157
158 t0=tin0;
159 t1=tin1;
160
161 tin[0]=tin0;
162 tin[1]=tin1;
163 DES_encrypt1(tin,ks1,0);
164 tin[0]^=m0;
165 tin[1]^=m1;
166 DES_encrypt1(tin,ks2,1);
167 tin[0]^=m0;
168 tin[1]^=m1;
169 DES_encrypt1(tin,ks1,0);
170 tout0=tin[0];
171 tout1=tin[1];
172
173 tout0^=xor0;
174 tout1^=xor1;
175 if(l < 0)
176 {
177 l2cn(tout0,tout1,out,l+8);
178 }
179 else
180 {
181 l2c(tout0,out);
182 l2c(tout1,out);
183 }
184 xor0=t0;
185 xor1=t1;
186 }
187
188 iv1=&(*ivec1)[0];
189 l2c(m0,iv1);
190 l2c(m1,iv1);
191
192 iv2=&(*ivec2)[0];
193 l2c(xor0,iv2);
194 l2c(xor1,iv2);
195 }
196 tin0=tin1=tout0=tout1=xor0=xor1=0;
197 tin[0]=tin[1]=0;
198 }
199#endif
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c
new file mode 100644
index 0000000000..c70fb686b8
--- /dev/null
+++ b/src/lib/libcrypto/des/enc_read.c
@@ -0,0 +1,228 @@
1/* crypto/des/enc_read.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 <errno.h>
61#include "cryptlib.h"
62#include "des_locl.h"
63
64/* This has some uglies in it but it works - even over sockets. */
65/*extern int errno;*/
66OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode)=DES_PCBC_MODE;
67
68
69/*
70 * WARNINGS:
71 *
72 * - The data format used by DES_enc_write() and DES_enc_read()
73 * has a cryptographic weakness: When asked to write more
74 * than MAXWRITE bytes, DES_enc_write will split the data
75 * into several chunks that are all encrypted
76 * using the same IV. So don't use these functions unless you
77 * are sure you know what you do (in which case you might
78 * not want to use them anyway).
79 *
80 * - This code cannot handle non-blocking sockets.
81 *
82 * - This function uses an internal state and thus cannot be
83 * used on multiple files.
84 */
85
86
87int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
88 DES_cblock *iv)
89 {
90 /* data to be unencrypted */
91 int net_num=0;
92 static unsigned char *net=NULL;
93 /* extra unencrypted data
94 * for when a block of 100 comes in but is des_read one byte at
95 * a time. */
96 static unsigned char *unnet=NULL;
97 static int unnet_start=0;
98 static int unnet_left=0;
99 static unsigned char *tmpbuf=NULL;
100 int i;
101 long num=0,rnum;
102 unsigned char *p;
103
104 if (tmpbuf == NULL)
105 {
106 tmpbuf=OPENSSL_malloc(BSIZE);
107 if (tmpbuf == NULL) return(-1);
108 }
109 if (net == NULL)
110 {
111 net=OPENSSL_malloc(BSIZE);
112 if (net == NULL) return(-1);
113 }
114 if (unnet == NULL)
115 {
116 unnet=OPENSSL_malloc(BSIZE);
117 if (unnet == NULL) return(-1);
118 }
119 /* left over data from last decrypt */
120 if (unnet_left != 0)
121 {
122 if (unnet_left < len)
123 {
124 /* we still still need more data but will return
125 * with the number of bytes we have - should always
126 * check the return value */
127 memcpy(buf,&(unnet[unnet_start]),
128 unnet_left);
129 /* eay 26/08/92 I had the next 2 lines
130 * reversed :-( */
131 i=unnet_left;
132 unnet_start=unnet_left=0;
133 }
134 else
135 {
136 memcpy(buf,&(unnet[unnet_start]),len);
137 unnet_start+=len;
138 unnet_left-=len;
139 i=len;
140 }
141 return(i);
142 }
143
144 /* We need to get more data. */
145 if (len > MAXWRITE) len=MAXWRITE;
146
147 /* first - get the length */
148 while (net_num < HDRSIZE)
149 {
150 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
151#ifdef EINTR
152 if ((i == -1) && (errno == EINTR)) continue;
153#endif
154 if (i <= 0) return(0);
155 net_num+=i;
156 }
157
158 /* we now have at net_num bytes in net */
159 p=net;
160 /* num=0; */
161 n2l(p,num);
162 /* num should be rounded up to the next group of eight
163 * we make sure that we have read a multiple of 8 bytes from the net.
164 */
165 if ((num > MAXWRITE) || (num < 0)) /* error */
166 return(-1);
167 rnum=(num < 8)?8:((num+7)/8*8);
168
169 net_num=0;
170 while (net_num < rnum)
171 {
172 i=read(fd,(void *)&(net[net_num]),rnum-net_num);
173#ifdef EINTR
174 if ((i == -1) && (errno == EINTR)) continue;
175#endif
176 if (i <= 0) return(0);
177 net_num+=i;
178 }
179
180 /* Check if there will be data left over. */
181 if (len < num)
182 {
183 if (DES_rw_mode & DES_PCBC_MODE)
184 DES_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
185 else
186 DES_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
187 memcpy(buf,unnet,len);
188 unnet_start=len;
189 unnet_left=num-len;
190
191 /* The following line is done because we return num
192 * as the number of bytes read. */
193 num=len;
194 }
195 else
196 {
197 /* >output is a multiple of 8 byes, if len < rnum
198 * >we must be careful. The user must be aware that this
199 * >routine will write more bytes than he asked for.
200 * >The length of the buffer must be correct.
201 * FIXED - Should be ok now 18-9-90 - eay */
202 if (len < rnum)
203 {
204
205 if (DES_rw_mode & DES_PCBC_MODE)
206 DES_pcbc_encrypt(net,tmpbuf,num,sched,iv,
207 DES_DECRYPT);
208 else
209 DES_cbc_encrypt(net,tmpbuf,num,sched,iv,
210 DES_DECRYPT);
211
212 /* eay 26/08/92 fix a bug that returned more
213 * bytes than you asked for (returned len bytes :-( */
214 memcpy(buf,tmpbuf,num);
215 }
216 else
217 {
218 if (DES_rw_mode & DES_PCBC_MODE)
219 DES_pcbc_encrypt(net,buf,num,sched,iv,
220 DES_DECRYPT);
221 else
222 DES_cbc_encrypt(net,buf,num,sched,iv,
223 DES_DECRYPT);
224 }
225 }
226 return num;
227 }
228
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
new file mode 100644
index 0000000000..af5b8c2349
--- /dev/null
+++ b/src/lib/libcrypto/des/enc_writ.c
@@ -0,0 +1,171 @@
1/* crypto/des/enc_writ.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 <errno.h>
60#include <time.h>
61#include <stdio.h>
62#include "cryptlib.h"
63#include "des_locl.h"
64#include <openssl/rand.h>
65
66/*
67 * WARNINGS:
68 *
69 * - The data format used by DES_enc_write() and DES_enc_read()
70 * has a cryptographic weakness: When asked to write more
71 * than MAXWRITE bytes, DES_enc_write will split the data
72 * into several chunks that are all encrypted
73 * using the same IV. So don't use these functions unless you
74 * are sure you know what you do (in which case you might
75 * not want to use them anyway).
76 *
77 * - This code cannot handle non-blocking sockets.
78 */
79
80int DES_enc_write(int fd, const void *_buf, int len,
81 DES_key_schedule *sched, DES_cblock *iv)
82 {
83#ifdef _LIBC
84 extern unsigned long time();
85 extern int write();
86#endif
87 const unsigned char *buf=_buf;
88 long rnum;
89 int i,j,k,outnum;
90 static unsigned char *outbuf=NULL;
91 unsigned char shortbuf[8];
92 unsigned char *p;
93 const unsigned char *cp;
94 static int start=1;
95
96 if (outbuf == NULL)
97 {
98 outbuf=OPENSSL_malloc(BSIZE+HDRSIZE);
99 if (outbuf == NULL) return(-1);
100 }
101 /* If we are sending less than 8 bytes, the same char will look
102 * the same if we don't pad it out with random bytes */
103 if (start)
104 {
105 start=0;
106 }
107
108 /* lets recurse if we want to send the data in small chunks */
109 if (len > MAXWRITE)
110 {
111 j=0;
112 for (i=0; i<len; i+=k)
113 {
114 k=DES_enc_write(fd,&(buf[i]),
115 ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv);
116 if (k < 0)
117 return(k);
118 else
119 j+=k;
120 }
121 return(j);
122 }
123
124 /* write length first */
125 p=outbuf;
126 l2n(len,p);
127
128 /* pad short strings */
129 if (len < 8)
130 {
131 cp=shortbuf;
132 memcpy(shortbuf,buf,len);
133 RAND_pseudo_bytes(shortbuf+len, 8-len);
134 rnum=8;
135 }
136 else
137 {
138 cp=buf;
139 rnum=((len+7)/8*8); /* round up to nearest eight */
140 }
141
142 if (DES_rw_mode & DES_PCBC_MODE)
143 DES_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
144 DES_ENCRYPT);
145 else
146 DES_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
147 DES_ENCRYPT);
148
149 /* output */
150 outnum=rnum+HDRSIZE;
151
152 for (j=0; j<outnum; j+=i)
153 {
154 /* eay 26/08/92 I was not doing writing from where we
155 * got up to. */
156 i=write(fd,(void *)&(outbuf[j]),outnum-j);
157 if (i == -1)
158 {
159#ifdef EINTR
160 if (errno == EINTR)
161 i=0;
162 else
163#endif
164 /* This is really a bad error - very bad
165 * It will stuff-up both ends. */
166 return(-1);
167 }
168 }
169
170 return(len);
171 }
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
new file mode 100644
index 0000000000..ccbdff250f
--- /dev/null
+++ b/src/lib/libcrypto/des/fcrypt.c
@@ -0,0 +1,170 @@
1/* NOCW */
2#include <stdio.h>
3#ifdef _OSD_POSIX
4#ifndef CHARSET_EBCDIC
5#define CHARSET_EBCDIC 1
6#endif
7#endif
8#ifdef CHARSET_EBCDIC
9#include <openssl/ebcdic.h>
10#endif
11
12/* This version of crypt has been developed from my MIT compatible
13 * DES library.
14 * Eric Young (eay@cryptsoft.com)
15 */
16
17/* Modification by Jens Kupferschmidt (Cu)
18 * I have included directive PARA for shared memory computers.
19 * I have included a directive LONGCRYPT to using this routine to cipher
20 * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN
21 * definition is the maximum of length of password and can changed. I have
22 * defined 24.
23 */
24
25#include "des_locl.h"
26
27/* Added more values to handle illegal salt values the way normal
28 * crypt() implementations do. The patch was sent by
29 * Bjorn Gronvall <bg@sics.se>
30 */
31static unsigned const char con_salt[128]={
320xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,
330xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1,
340xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,
350xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,
360xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,
370xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01,
380x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
390x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A,
400x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,
410x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,
420x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,
430x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24,
440x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,
450x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,
460x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,
470x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44,
48};
49
50static unsigned const char cov_2char[64]={
510x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
520x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
530x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
540x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
550x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
560x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
570x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
580x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
59};
60
61char *DES_crypt(const char *buf, const char *salt)
62 {
63 static char buff[14];
64
65#ifndef CHARSET_EBCDIC
66 return(DES_fcrypt(buf,salt,buff));
67#else
68 char e_salt[2+1];
69 char e_buf[32+1]; /* replace 32 by 8 ? */
70 char *ret;
71
72 /* Copy at most 2 chars of salt */
73 if ((e_salt[0] = salt[0]) != '\0')
74 e_salt[1] = salt[1];
75
76 /* Copy at most 32 chars of password */
77 strncpy (e_buf, buf, sizeof(e_buf));
78
79 /* Make sure we have a delimiter */
80 e_salt[sizeof(e_salt)-1] = e_buf[sizeof(e_buf)-1] = '\0';
81
82 /* Convert the e_salt to ASCII, as that's what DES_fcrypt works on */
83 ebcdic2ascii(e_salt, e_salt, sizeof e_salt);
84
85 /* Convert the cleartext password to ASCII */
86 ebcdic2ascii(e_buf, e_buf, sizeof e_buf);
87
88 /* Encrypt it (from/to ASCII) */
89 ret = DES_fcrypt(e_buf,e_salt,buff);
90
91 /* Convert the result back to EBCDIC */
92 ascii2ebcdic(ret, ret, strlen(ret));
93
94 return ret;
95#endif
96 }
97
98
99char *DES_fcrypt(const char *buf, const char *salt, char *ret)
100 {
101 unsigned int i,j,x,y;
102 DES_LONG Eswap0,Eswap1;
103 DES_LONG out[2],ll;
104 DES_cblock key;
105 DES_key_schedule ks;
106 unsigned char bb[9];
107 unsigned char *b=bb;
108 unsigned char c,u;
109
110 /* eay 25/08/92
111 * If you call crypt("pwd","*") as often happens when you
112 * have * as the pwd field in /etc/passwd, the function
113 * returns *\0XXXXXXXXX
114 * The \0 makes the string look like * so the pwd "*" would
115 * crypt to "*". This was found when replacing the crypt in
116 * our shared libraries. People found that the disabled
117 * accounts effectively had no passwd :-(. */
118#ifndef CHARSET_EBCDIC
119 x=ret[0]=((salt[0] == '\0')?'A':salt[0]);
120 Eswap0=con_salt[x]<<2;
121 x=ret[1]=((salt[1] == '\0')?'A':salt[1]);
122 Eswap1=con_salt[x]<<6;
123#else
124 x=ret[0]=((salt[0] == '\0')?os_toascii['A']:salt[0]);
125 Eswap0=con_salt[x]<<2;
126 x=ret[1]=((salt[1] == '\0')?os_toascii['A']:salt[1]);
127 Eswap1=con_salt[x]<<6;
128#endif
129
130/* EAY
131r=strlen(buf);
132r=(r+7)/8;
133*/
134 for (i=0; i<8; i++)
135 {
136 c= *(buf++);
137 if (!c) break;
138 key[i]=(c<<1);
139 }
140 for (; i<8; i++)
141 key[i]=0;
142
143 DES_set_key_unchecked(&key,&ks);
144 fcrypt_body(&(out[0]),&ks,Eswap0,Eswap1);
145
146 ll=out[0]; l2c(ll,b);
147 ll=out[1]; l2c(ll,b);
148 y=0;
149 u=0x80;
150 bb[8]=0;
151 for (i=2; i<13; i++)
152 {
153 c=0;
154 for (j=0; j<6; j++)
155 {
156 c<<=1;
157 if (bb[y] & u) c|=1;
158 u>>=1;
159 if (!u)
160 {
161 y++;
162 u=0x80;
163 }
164 }
165 ret[i]=cov_2char[c];
166 }
167 ret[13]='\0';
168 return(ret);
169 }
170
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
new file mode 100644
index 0000000000..c56b461e91
--- /dev/null
+++ b/src/lib/libcrypto/des/fcrypt_b.c
@@ -0,0 +1,148 @@
1/* crypto/des/fcrypt_b.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
61/* This version of crypt has been developed from my MIT compatible
62 * DES library.
63 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au
64 * Eric Young (eay@cryptsoft.com)
65 */
66
67#define DES_FCRYPT
68#include "des_locl.h"
69#undef DES_FCRYPT
70
71#ifndef OPENBSD_DES_ASM
72
73#undef PERM_OP
74#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
75 (b)^=(t),\
76 (a)^=((t)<<(n)))
77
78#undef HPERM_OP
79#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
80 (a)=(a)^(t)^(t>>(16-(n))))\
81
82void fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0,
83 DES_LONG Eswap1)
84 {
85 register DES_LONG l,r,t,u;
86#ifdef DES_PTR
87 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
88#endif
89 register DES_LONG *s;
90 register int j;
91 register DES_LONG E0,E1;
92
93 l=0;
94 r=0;
95
96 s=(DES_LONG *)ks;
97 E0=Eswap0;
98 E1=Eswap1;
99
100 for (j=0; j<25; j++)
101 {
102#ifndef DES_UNROLL
103 register int i;
104
105 for (i=0; i<32; i+=8)
106 {
107 D_ENCRYPT(l,r,i+0); /* 1 */
108 D_ENCRYPT(r,l,i+2); /* 2 */
109 D_ENCRYPT(l,r,i+4); /* 1 */
110 D_ENCRYPT(r,l,i+6); /* 2 */
111 }
112#else
113 D_ENCRYPT(l,r, 0); /* 1 */
114 D_ENCRYPT(r,l, 2); /* 2 */
115 D_ENCRYPT(l,r, 4); /* 3 */
116 D_ENCRYPT(r,l, 6); /* 4 */
117 D_ENCRYPT(l,r, 8); /* 5 */
118 D_ENCRYPT(r,l,10); /* 6 */
119 D_ENCRYPT(l,r,12); /* 7 */
120 D_ENCRYPT(r,l,14); /* 8 */
121 D_ENCRYPT(l,r,16); /* 9 */
122 D_ENCRYPT(r,l,18); /* 10 */
123 D_ENCRYPT(l,r,20); /* 11 */
124 D_ENCRYPT(r,l,22); /* 12 */
125 D_ENCRYPT(l,r,24); /* 13 */
126 D_ENCRYPT(r,l,26); /* 14 */
127 D_ENCRYPT(l,r,28); /* 15 */
128 D_ENCRYPT(r,l,30); /* 16 */
129#endif
130
131 t=l;
132 l=r;
133 r=t;
134 }
135 l=ROTATE(l,3)&0xffffffffL;
136 r=ROTATE(r,3)&0xffffffffL;
137
138 PERM_OP(l,r,t, 1,0x55555555L);
139 PERM_OP(r,l,t, 8,0x00ff00ffL);
140 PERM_OP(l,r,t, 2,0x33333333L);
141 PERM_OP(r,l,t,16,0x0000ffffL);
142 PERM_OP(l,r,t, 4,0x0f0f0f0fL);
143
144 out[0]=r;
145 out[1]=l;
146 }
147
148#endif /* OPENBSD_DES_ASM */
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/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c
new file mode 100644
index 0000000000..fda23d522f
--- /dev/null
+++ b/src/lib/libcrypto/des/ncbc_enc.c
@@ -0,0 +1,148 @@
1/* crypto/des/ncbc_enc.c */
2/*
3 * #included by:
4 * cbc_enc.c (DES_cbc_encrypt)
5 * des_enc.c (DES_ncbc_encrypt)
6 */
7/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
8 * All rights reserved.
9 *
10 * This package is an SSL implementation written
11 * by Eric Young (eay@cryptsoft.com).
12 * The implementation was written so as to conform with Netscapes SSL.
13 *
14 * This library is free for commercial and non-commercial use as long as
15 * the following conditions are aheared to. The following conditions
16 * apply to all code found in this distribution, be it the RC4, RSA,
17 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
18 * included with this distribution is covered by the same copyright terms
19 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
20 *
21 * Copyright remains Eric Young's, and as such any Copyright notices in
22 * the code are not to be removed.
23 * If this package is used in a product, Eric Young should be given attribution
24 * as the author of the parts of the library used.
25 * This can be in the form of a textual message at program startup or
26 * in documentation (online or textual) provided with the package.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * "This product includes cryptographic software written by
39 * Eric Young (eay@cryptsoft.com)"
40 * The word 'cryptographic' can be left out if the rouines from the library
41 * being used are not cryptographic related :-).
42 * 4. If you include any Windows specific code (or a derivative thereof) from
43 * the apps directory (application code) you must include an acknowledgement:
44 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
45 *
46 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * The licence and distribution terms for any publically available version or
59 * derivative of this code cannot be changed. i.e. this code cannot simply be
60 * copied and put under another distribution licence
61 * [including the GNU Public Licence.]
62 */
63
64#include "des_locl.h"
65
66#ifdef CBC_ENC_C__DONT_UPDATE_IV
67void DES_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
68 DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
69#else
70void DES_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
71 DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
72#endif
73 {
74 register DES_LONG tin0,tin1;
75 register DES_LONG tout0,tout1,xor0,xor1;
76 register long l=length;
77 DES_LONG tin[2];
78 unsigned char *iv;
79
80 iv = &(*ivec)[0];
81
82 if (enc)
83 {
84 c2l(iv,tout0);
85 c2l(iv,tout1);
86 for (l-=8; l>=0; l-=8)
87 {
88 c2l(in,tin0);
89 c2l(in,tin1);
90 tin0^=tout0; tin[0]=tin0;
91 tin1^=tout1; tin[1]=tin1;
92 DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT);
93 tout0=tin[0]; l2c(tout0,out);
94 tout1=tin[1]; l2c(tout1,out);
95 }
96 if (l != -8)
97 {
98 c2ln(in,tin0,tin1,l+8);
99 tin0^=tout0; tin[0]=tin0;
100 tin1^=tout1; tin[1]=tin1;
101 DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT);
102 tout0=tin[0]; l2c(tout0,out);
103 tout1=tin[1]; l2c(tout1,out);
104 }
105#ifndef CBC_ENC_C__DONT_UPDATE_IV
106 iv = &(*ivec)[0];
107 l2c(tout0,iv);
108 l2c(tout1,iv);
109#endif
110 }
111 else
112 {
113 c2l(iv,xor0);
114 c2l(iv,xor1);
115 for (l-=8; l>=0; l-=8)
116 {
117 c2l(in,tin0); tin[0]=tin0;
118 c2l(in,tin1); tin[1]=tin1;
119 DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT);
120 tout0=tin[0]^xor0;
121 tout1=tin[1]^xor1;
122 l2c(tout0,out);
123 l2c(tout1,out);
124 xor0=tin0;
125 xor1=tin1;
126 }
127 if (l != -8)
128 {
129 c2l(in,tin0); tin[0]=tin0;
130 c2l(in,tin1); tin[1]=tin1;
131 DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT);
132 tout0=tin[0]^xor0;
133 tout1=tin[1]^xor1;
134 l2cn(tout0,tout1,out,l+8);
135#ifndef CBC_ENC_C__DONT_UPDATE_IV
136 xor0=tin0;
137 xor1=tin1;
138#endif
139 }
140#ifndef CBC_ENC_C__DONT_UPDATE_IV
141 iv = &(*ivec)[0];
142 l2c(xor0,iv);
143 l2c(xor1,iv);
144#endif
145 }
146 tin0=tin1=tout0=tout1=xor0=xor1=0;
147 tin[0]=tin[1]=0;
148 }
diff --git a/src/lib/libcrypto/des/ofb64ede.c b/src/lib/libcrypto/des/ofb64ede.c
new file mode 100644
index 0000000000..26bbf9a6a7
--- /dev/null
+++ b/src/lib/libcrypto/des/ofb64ede.c
@@ -0,0 +1,125 @@
1/* crypto/des/ofb64ede.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/* The input and output encrypted as though 64bit ofb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65void DES_ede3_ofb64_encrypt(register const unsigned char *in,
66 register unsigned char *out, long length,
67 DES_key_schedule *k1, DES_key_schedule *k2,
68 DES_key_schedule *k3, DES_cblock *ivec,
69 int *num)
70 {
71 register DES_LONG v0,v1;
72 register int n= *num;
73 register long l=length;
74 DES_cblock d;
75 register char *dp;
76 DES_LONG ti[2];
77 unsigned char *iv;
78 int save=0;
79
80 iv = &(*ivec)[0];
81 c2l(iv,v0);
82 c2l(iv,v1);
83 ti[0]=v0;
84 ti[1]=v1;
85 dp=(char *)d;
86 l2c(v0,dp);
87 l2c(v1,dp);
88 while (l--)
89 {
90 if (n == 0)
91 {
92 /* ti[0]=v0; */
93 /* ti[1]=v1; */
94 DES_encrypt3(ti,k1,k2,k3);
95 v0=ti[0];
96 v1=ti[1];
97
98 dp=(char *)d;
99 l2c(v0,dp);
100 l2c(v1,dp);
101 save++;
102 }
103 *(out++)= *(in++)^d[n];
104 n=(n+1)&0x07;
105 }
106 if (save)
107 {
108/* v0=ti[0];
109 v1=ti[1];*/
110 iv = &(*ivec)[0];
111 l2c(v0,iv);
112 l2c(v1,iv);
113 }
114 v0=v1=ti[0]=ti[1]=0;
115 *num=n;
116 }
117
118#ifdef undef /* MACRO */
119void DES_ede2_ofb64_encrypt(register unsigned char *in,
120 register unsigned char *out, long length, DES_key_schedule k1,
121 DES_key_schedule k2, DES_cblock (*ivec), int *num)
122 {
123 DES_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num);
124 }
125#endif
diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c
new file mode 100644
index 0000000000..8ca3d49dea
--- /dev/null
+++ b/src/lib/libcrypto/des/ofb64enc.c
@@ -0,0 +1,110 @@
1/* crypto/des/ofb64enc.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/* The input and output encrypted as though 64bit ofb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65void DES_ofb64_encrypt(register const unsigned char *in,
66 register unsigned char *out, long length,
67 DES_key_schedule *schedule, DES_cblock *ivec, int *num)
68 {
69 register DES_LONG v0,v1,t;
70 register int n= *num;
71 register long l=length;
72 DES_cblock d;
73 register unsigned char *dp;
74 DES_LONG ti[2];
75 unsigned char *iv;
76 int save=0;
77
78 iv = &(*ivec)[0];
79 c2l(iv,v0);
80 c2l(iv,v1);
81 ti[0]=v0;
82 ti[1]=v1;
83 dp=d;
84 l2c(v0,dp);
85 l2c(v1,dp);
86 while (l--)
87 {
88 if (n == 0)
89 {
90 DES_encrypt1(ti,schedule,DES_ENCRYPT);
91 dp=d;
92 t=ti[0]; l2c(t,dp);
93 t=ti[1]; l2c(t,dp);
94 save++;
95 }
96 *(out++)= *(in++)^d[n];
97 n=(n+1)&0x07;
98 }
99 if (save)
100 {
101 v0=ti[0];
102 v1=ti[1];
103 iv = &(*ivec)[0];
104 l2c(v0,iv);
105 l2c(v1,iv);
106 }
107 t=v0=v1=ti[0]=ti[1]=0;
108 *num=n;
109 }
110
diff --git a/src/lib/libcrypto/des/ofb_enc.c b/src/lib/libcrypto/des/ofb_enc.c
new file mode 100644
index 0000000000..e887a3c6f4
--- /dev/null
+++ b/src/lib/libcrypto/des/ofb_enc.c
@@ -0,0 +1,135 @@
1/* crypto/des/ofb_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/* The input and output are loaded in multiples of 8 bits.
62 * What this means is that if you hame numbits=12 and length=2
63 * the first 12 bits will be retrieved from the first byte and half
64 * the second. The second 12 bits will come from the 3rd and half the 4th
65 * byte.
66 */
67void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
68 long length, DES_key_schedule *schedule,
69 DES_cblock *ivec)
70 {
71 register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8;
72 register DES_LONG mask0,mask1;
73 register long l=length;
74 register int num=numbits;
75 DES_LONG ti[2];
76 unsigned char *iv;
77
78 if (num > 64) return;
79 if (num > 32)
80 {
81 mask0=0xffffffffL;
82 if (num >= 64)
83 mask1=mask0;
84 else
85 mask1=(1L<<(num-32))-1;
86 }
87 else
88 {
89 if (num == 32)
90 mask0=0xffffffffL;
91 else
92 mask0=(1L<<num)-1;
93 mask1=0x00000000L;
94 }
95
96 iv = &(*ivec)[0];
97 c2l(iv,v0);
98 c2l(iv,v1);
99 ti[0]=v0;
100 ti[1]=v1;
101 while (l-- > 0)
102 {
103 ti[0]=v0;
104 ti[1]=v1;
105 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
106 vv0=ti[0];
107 vv1=ti[1];
108 c2ln(in,d0,d1,n);
109 in+=n;
110 d0=(d0^vv0)&mask0;
111 d1=(d1^vv1)&mask1;
112 l2cn(d0,d1,out,n);
113 out+=n;
114
115 if (num == 32)
116 { v0=v1; v1=vv0; }
117 else if (num == 64)
118 { v0=vv0; v1=vv1; }
119 else if (num > 32) /* && num != 64 */
120 {
121 v0=((v1>>(num-32))|(vv0<<(64-num)))&0xffffffffL;
122 v1=((vv0>>(num-32))|(vv1<<(64-num)))&0xffffffffL;
123 }
124 else /* num < 32 */
125 {
126 v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL;
127 v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL;
128 }
129 }
130 iv = &(*ivec)[0];
131 l2c(v0,iv);
132 l2c(v1,iv);
133 v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0;
134 }
135
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/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c
new file mode 100644
index 0000000000..17a40f9520
--- /dev/null
+++ b/src/lib/libcrypto/des/pcbc_enc.c
@@ -0,0 +1,123 @@
1/* crypto/des/pcbc_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
61void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
62 long length, DES_key_schedule *schedule,
63 DES_cblock *ivec, int enc)
64 {
65 register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1;
66 DES_LONG tin[2];
67 const unsigned char *in;
68 unsigned char *out,*iv;
69
70 in=input;
71 out=output;
72 iv = &(*ivec)[0];
73
74 if (enc)
75 {
76 c2l(iv,xor0);
77 c2l(iv,xor1);
78 for (; length>0; length-=8)
79 {
80 if (length >= 8)
81 {
82 c2l(in,sin0);
83 c2l(in,sin1);
84 }
85 else
86 c2ln(in,sin0,sin1,length);
87 tin[0]=sin0^xor0;
88 tin[1]=sin1^xor1;
89 DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT);
90 tout0=tin[0];
91 tout1=tin[1];
92 xor0=sin0^tout0;
93 xor1=sin1^tout1;
94 l2c(tout0,out);
95 l2c(tout1,out);
96 }
97 }
98 else
99 {
100 c2l(iv,xor0); c2l(iv,xor1);
101 for (; length>0; length-=8)
102 {
103 c2l(in,sin0);
104 c2l(in,sin1);
105 tin[0]=sin0;
106 tin[1]=sin1;
107 DES_encrypt1((DES_LONG *)tin,schedule,DES_DECRYPT);
108 tout0=tin[0]^xor0;
109 tout1=tin[1]^xor1;
110 if (length >= 8)
111 {
112 l2c(tout0,out);
113 l2c(tout1,out);
114 }
115 else
116 l2cn(tout0,tout1,out,length);
117 xor0=tout0^sin0;
118 xor1=tout1^sin1;
119 }
120 }
121 tin[0]=tin[1]=0;
122 sin0=sin1=xor0=xor1=tout0=tout1=0;
123 }
diff --git a/src/lib/libcrypto/des/qud_cksm.c b/src/lib/libcrypto/des/qud_cksm.c
new file mode 100644
index 0000000000..dac201227e
--- /dev/null
+++ b/src/lib/libcrypto/des/qud_cksm.c
@@ -0,0 +1,139 @@
1/* crypto/des/qud_cksm.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/* From "Message Authentication" R.R. Jueneman, S.M. Matyas, C.H. Meyer
60 * IEEE Communications Magazine Sept 1985 Vol. 23 No. 9 p 29-40
61 * This module in only based on the code in this paper and is
62 * almost definitely not the same as the MIT implementation.
63 */
64#include "des_locl.h"
65
66/* bug fix for dos - 7/6/91 - Larry hughes@logos.ucs.indiana.edu */
67#define Q_B0(a) (((DES_LONG)(a)))
68#define Q_B1(a) (((DES_LONG)(a))<<8)
69#define Q_B2(a) (((DES_LONG)(a))<<16)
70#define Q_B3(a) (((DES_LONG)(a))<<24)
71
72/* used to scramble things a bit */
73/* Got the value MIT uses via brute force :-) 2/10/90 eay */
74#define NOISE ((DES_LONG)83653421L)
75
76DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
77 long length, int out_count, DES_cblock *seed)
78 {
79 DES_LONG z0,z1,t0,t1;
80 int i;
81 long l;
82 const unsigned char *cp;
83#ifdef _CRAY
84 struct lp_st { int a:32; int b:32; } *lp;
85#else
86 DES_LONG *lp;
87#endif
88
89 if (out_count < 1) out_count=1;
90#ifdef _CRAY
91 lp = (struct lp_st *) &(output[0])[0];
92#else
93 lp = (DES_LONG *) &(output[0])[0];
94#endif
95
96 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]);
97 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]);
98
99 for (i=0; ((i<4)&&(i<out_count)); i++)
100 {
101 cp=input;
102 l=length;
103 while (l > 0)
104 {
105 if (l > 1)
106 {
107 t0= (DES_LONG)(*(cp++));
108 t0|=(DES_LONG)Q_B1(*(cp++));
109 l--;
110 }
111 else
112 t0= (DES_LONG)(*(cp++));
113 l--;
114 /* add */
115 t0+=z0;
116 t0&=0xffffffffL;
117 t1=z1;
118 /* square, well sort of square */
119 z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL))
120 &0xffffffffL)%0x7fffffffL;
121 z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL;
122 }
123 if (lp != NULL)
124 {
125 /* The MIT library assumes that the checksum is
126 * composed of 2*out_count 32 bit ints */
127#ifdef _CRAY
128 (*lp).a = z0;
129 (*lp).b = z1;
130 lp++;
131#else
132 *lp++ = z0;
133 *lp++ = z1;
134#endif
135 }
136 }
137 return(z0);
138 }
139
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c
new file mode 100644
index 0000000000..2398165568
--- /dev/null
+++ b/src/lib/libcrypto/des/rand_key.c
@@ -0,0 +1,68 @@
1/* crypto/des/rand_key.c */
2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/des.h>
57#include <openssl/rand.h>
58
59int DES_random_key(DES_cblock *ret)
60 {
61 do
62 {
63 if (RAND_bytes((unsigned char *)ret, sizeof(DES_cblock)) != 1)
64 return (0);
65 } while (DES_is_weak_key(ret));
66 DES_set_odd_parity(ret);
67 return (1);
68 }
diff --git a/src/lib/libcrypto/des/read2pwd.c b/src/lib/libcrypto/des/read2pwd.c
new file mode 100644
index 0000000000..ee6969f76e
--- /dev/null
+++ b/src/lib/libcrypto/des/read2pwd.c
@@ -0,0 +1,140 @@
1/* crypto/des/read2pwd.c */
2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
56 * All rights reserved.
57 *
58 * This package is an SSL implementation written
59 * by Eric Young (eay@cryptsoft.com).
60 * The implementation was written so as to conform with Netscapes SSL.
61 *
62 * This library is free for commercial and non-commercial use as long as
63 * the following conditions are aheared to. The following conditions
64 * apply to all code found in this distribution, be it the RC4, RSA,
65 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
66 * included with this distribution is covered by the same copyright terms
67 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
68 *
69 * Copyright remains Eric Young's, and as such any Copyright notices in
70 * the code are not to be removed.
71 * If this package is used in a product, Eric Young should be given attribution
72 * as the author of the parts of the library used.
73 * This can be in the form of a textual message at program startup or
74 * in documentation (online or textual) provided with the package.
75 *
76 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions
78 * are met:
79 * 1. Redistributions of source code must retain the copyright
80 * notice, this list of conditions and the following disclaimer.
81 * 2. Redistributions in binary form must reproduce the above copyright
82 * notice, this list of conditions and the following disclaimer in the
83 * documentation and/or other materials provided with the distribution.
84 * 3. All advertising materials mentioning features or use of this software
85 * must display the following acknowledgement:
86 * "This product includes cryptographic software written by
87 * Eric Young (eay@cryptsoft.com)"
88 * The word 'cryptographic' can be left out if the rouines from the library
89 * being used are not cryptographic related :-).
90 * 4. If you include any Windows specific code (or a derivative thereof) from
91 * the apps directory (application code) you must include an acknowledgement:
92 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
93 *
94 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
95 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
98 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
99 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
100 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
101 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
102 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
103 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
104 * SUCH DAMAGE.
105 *
106 * The licence and distribution terms for any publically available version or
107 * derivative of this code cannot be changed. i.e. this code cannot simply be
108 * copied and put under another distribution licence
109 * [including the GNU Public Licence.]
110 */
111
112#include <string.h>
113#include <openssl/des.h>
114#include <openssl/ui.h>
115#include <openssl/crypto.h>
116
117int DES_read_password(DES_cblock *key, const char *prompt, int verify)
118 {
119 int ok;
120 char buf[BUFSIZ],buff[BUFSIZ];
121
122 if ((ok=UI_UTIL_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
123 DES_string_to_key(buf,key);
124 OPENSSL_cleanse(buf,BUFSIZ);
125 OPENSSL_cleanse(buff,BUFSIZ);
126 return(ok);
127 }
128
129int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
130 int verify)
131 {
132 int ok;
133 char buf[BUFSIZ],buff[BUFSIZ];
134
135 if ((ok=UI_UTIL_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
136 DES_string_to_2keys(buf,key1,key2);
137 OPENSSL_cleanse(buf,BUFSIZ);
138 OPENSSL_cleanse(buff,BUFSIZ);
139 return(ok);
140 }
diff --git a/src/lib/libcrypto/des/read_pwd.c b/src/lib/libcrypto/des/read_pwd.c
new file mode 100644
index 0000000000..ce5fa00a37
--- /dev/null
+++ b/src/lib/libcrypto/des/read_pwd.c
@@ -0,0 +1,521 @@
1/* crypto/des/read_pwd.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/e_os2.h>
60#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WIN32)
61#ifdef OPENSSL_UNISTD
62# include OPENSSL_UNISTD
63#else
64# include <unistd.h>
65#endif
66/* If unistd.h defines _POSIX_VERSION, we conclude that we
67 * are on a POSIX system and have sigaction and termios. */
68#if defined(_POSIX_VERSION)
69
70# define SIGACTION
71# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
72# define TERMIOS
73# endif
74
75#endif
76#endif
77
78/* #define SIGACTION */ /* Define this if you have sigaction() */
79
80#ifdef WIN16TTY
81#undef OPENSSL_SYS_WIN16
82#undef _WINDOWS
83#include <graph.h>
84#endif
85
86/* 06-Apr-92 Luke Brennan Support for VMS */
87#include "des_locl.h"
88#include "cryptlib.h"
89#include <signal.h>
90#include <stdio.h>
91#include <string.h>
92#include <setjmp.h>
93#include <errno.h>
94
95#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */
96#include <starlet.h>
97#ifdef __DECC
98#pragma message disable DOLLARID
99#endif
100#endif
101
102#ifdef WIN_CONSOLE_BUG
103#include <windows.h>
104#ifndef OPENSSL_SYS_WINCE
105#include <wincon.h>
106#endif
107#endif
108
109
110/* There are 5 types of terminal interface supported,
111 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
112 */
113
114#if defined(__sgi) && !defined(TERMIOS)
115#define TERMIOS
116#undef TERMIO
117#undef SGTTY
118#endif
119
120#if defined(linux) && !defined(TERMIO)
121#undef TERMIOS
122#define TERMIO
123#undef SGTTY
124#endif
125
126#ifdef _LIBC
127#undef TERMIOS
128#define TERMIO
129#undef SGTTY
130#endif
131
132#if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(MAC_OS_pre_X) && !defined(MAC_OS_GUSI_SOURCE)
133#undef TERMIOS
134#undef TERMIO
135#define SGTTY
136#endif
137
138#if defined(OPENSSL_SYS_VXWORKS)
139#undef TERMIOS
140#undef TERMIO
141#undef SGTTY
142#endif
143
144#ifdef TERMIOS
145#include <termios.h>
146#define TTY_STRUCT struct termios
147#define TTY_FLAGS c_lflag
148#define TTY_get(tty,data) tcgetattr(tty,data)
149#define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
150#endif
151
152#ifdef TERMIO
153#include <termio.h>
154#define TTY_STRUCT struct termio
155#define TTY_FLAGS c_lflag
156#define TTY_get(tty,data) ioctl(tty,TCGETA,data)
157#define TTY_set(tty,data) ioctl(tty,TCSETA,data)
158#endif
159
160#ifdef SGTTY
161#include <sgtty.h>
162#define TTY_STRUCT struct sgttyb
163#define TTY_FLAGS sg_flags
164#define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
165#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
166#endif
167
168#if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(MAC_OS_pre_X)
169#include <sys/ioctl.h>
170#endif
171
172#if defined(OPENSSL_SYS_MSDOS) && !defined(__CYGWIN32__) && !defined(OPENSSL_SYS_WINCE)
173#include <conio.h>
174#define fgets(a,b,c) noecho_fgets(a,b,c)
175#endif
176
177#ifdef OPENSSL_SYS_VMS
178#include <ssdef.h>
179#include <iodef.h>
180#include <ttdef.h>
181#include <descrip.h>
182struct IOSB {
183 short iosb$w_value;
184 short iosb$w_count;
185 long iosb$l_info;
186 };
187#endif
188
189#if defined(MAC_OS_pre_X) || defined(MAC_OS_GUSI_SOURCE)
190/*
191 * This one needs work. As a matter of fact the code is unoperational
192 * and this is only a trick to get it compiled.
193 * <appro@fy.chalmers.se>
194 */
195#define TTY_STRUCT int
196#endif
197
198#ifndef NX509_SIG
199#define NX509_SIG 32
200#endif
201
202static void read_till_nl(FILE *);
203static void recsig(int);
204static void pushsig(void);
205static void popsig(void);
206#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
207static int noecho_fgets(char *buf, int size, FILE *tty);
208#endif
209#ifdef SIGACTION
210 static struct sigaction savsig[NX509_SIG];
211#else
212 static void (*savsig[NX509_SIG])(int );
213#endif
214static jmp_buf save;
215
216int des_read_pw_string(char *buf, int length, const char *prompt,
217 int verify)
218 {
219 char buff[BUFSIZ];
220 int ret;
221
222 ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
223 OPENSSL_cleanse(buff,BUFSIZ);
224 return(ret);
225 }
226
227#ifdef OPENSSL_SYS_WINCE
228
229int des_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
230 {
231 memset(buf,0,size);
232 memset(buff,0,size);
233 return(0);
234 }
235
236#elif defined(OPENSSL_SYS_WIN16)
237
238int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify)
239 {
240 memset(buf,0,size);
241 memset(buff,0,size);
242 return(0);
243 }
244
245#else /* !OPENSSL_SYS_WINCE && !OPENSSL_SYS_WIN16 */
246
247static void read_till_nl(FILE *in)
248 {
249#define SIZE 4
250 char buf[SIZE+1];
251
252 do {
253 fgets(buf,SIZE,in);
254 } while (strchr(buf,'\n') == NULL);
255 }
256
257
258/* return 0 if ok, 1 (or -1) otherwise */
259int des_read_pw(char *buf, char *buff, int size, const char *prompt,
260 int verify)
261 {
262#ifdef OPENSSL_SYS_VMS
263 struct IOSB iosb;
264 $DESCRIPTOR(terminal,"TT");
265 long tty_orig[3], tty_new[3];
266 long status;
267 unsigned short channel = 0;
268#else
269#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
270 TTY_STRUCT tty_orig,tty_new;
271#endif
272#endif
273 int number;
274 int ok;
275 /* statics are simply to avoid warnings about longjmp clobbering
276 things */
277 static int ps;
278 int is_a_tty;
279 static FILE *tty;
280 char *p;
281
282 if (setjmp(save))
283 {
284 ok=0;
285 goto error;
286 }
287
288 number=5;
289 ok=0;
290 ps=0;
291 is_a_tty=1;
292 tty=NULL;
293
294#ifdef OPENSSL_SYS_MSDOS
295 if ((tty=fopen("con","r")) == NULL)
296 tty=stdin;
297#elif defined(MAC_OS_pre_X) || defined(OPENSSL_SYS_VXWORKS)
298 tty=stdin;
299#else
300#ifndef OPENSSL_SYS_MPE
301 if ((tty=fopen("/dev/tty","r")) == NULL)
302#endif
303 tty=stdin;
304#endif
305
306#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
307 if (TTY_get(fileno(tty),&tty_orig) == -1)
308 {
309#ifdef ENOTTY
310 if (errno == ENOTTY)
311 is_a_tty=0;
312 else
313#endif
314#ifdef EINVAL
315 /* Ariel Glenn ariel@columbia.edu reports that solaris
316 * can return EINVAL instead. This should be ok */
317 if (errno == EINVAL)
318 is_a_tty=0;
319 else
320#endif
321 return(-1);
322 }
323 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
324#endif
325#ifdef OPENSSL_SYS_VMS
326 status = sys$assign(&terminal,&channel,0,0);
327 if (status != SS$_NORMAL)
328 return(-1);
329 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
330 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
331 return(-1);
332#endif
333
334 pushsig();
335 ps=1;
336
337#ifdef TTY_FLAGS
338 tty_new.TTY_FLAGS &= ~ECHO;
339#endif
340
341#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
342 if (is_a_tty && (TTY_set(fileno(tty),&tty_new) == -1))
343#ifdef OPENSSL_SYS_MPE
344 ; /* MPE lies -- echo really has been disabled */
345#else
346 return(-1);
347#endif
348#endif
349#ifdef OPENSSL_SYS_VMS
350 tty_new[0] = tty_orig[0];
351 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
352 tty_new[2] = tty_orig[2];
353 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
354 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
355 return(-1);
356#endif
357 ps=2;
358
359 while ((!ok) && (number--))
360 {
361 fputs(prompt,stderr);
362 fflush(stderr);
363
364 buf[0]='\0';
365 fgets(buf,size,tty);
366 if (feof(tty)) goto error;
367 if (ferror(tty)) goto error;
368 if ((p=(char *)strchr(buf,'\n')) != NULL)
369 *p='\0';
370 else read_till_nl(tty);
371 if (verify)
372 {
373 fprintf(stderr,"\nVerifying password - %s",prompt);
374 fflush(stderr);
375 buff[0]='\0';
376 fgets(buff,size,tty);
377 if (feof(tty)) goto error;
378 if ((p=(char *)strchr(buff,'\n')) != NULL)
379 *p='\0';
380 else read_till_nl(tty);
381
382 if (strcmp(buf,buff) != 0)
383 {
384 fprintf(stderr,"\nVerify failure");
385 fflush(stderr);
386 break;
387 /* continue; */
388 }
389 }
390 ok=1;
391 }
392
393error:
394 fprintf(stderr,"\n");
395#if 0
396 perror("fgets(tty)");
397#endif
398 /* What can we do if there is an error? */
399#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
400 if (ps >= 2) TTY_set(fileno(tty),&tty_orig);
401#endif
402#ifdef OPENSSL_SYS_VMS
403 if (ps >= 2)
404 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0
405 ,tty_orig,12,0,0,0,0);
406#endif
407
408 if (ps >= 1) popsig();
409 if (stdin != tty) fclose(tty);
410#ifdef OPENSSL_SYS_VMS
411 status = sys$dassgn(channel);
412#endif
413 return(!ok);
414 }
415
416static void pushsig(void)
417 {
418 int i;
419#ifdef SIGACTION
420 struct sigaction sa;
421
422 memset(&sa,0,sizeof sa);
423 sa.sa_handler=recsig;
424#endif
425
426 for (i=1; i<NX509_SIG; i++)
427 {
428#ifdef SIGUSR1
429 if (i == SIGUSR1)
430 continue;
431#endif
432#ifdef SIGUSR2
433 if (i == SIGUSR2)
434 continue;
435#endif
436#ifdef SIGACTION
437 sigaction(i,&sa,&savsig[i]);
438#else
439 savsig[i]=signal(i,recsig);
440#endif
441 }
442
443#ifdef SIGWINCH
444 signal(SIGWINCH,SIG_DFL);
445#endif
446 }
447
448static void popsig(void)
449 {
450 int i;
451
452 for (i=1; i<NX509_SIG; i++)
453 {
454#ifdef SIGUSR1
455 if (i == SIGUSR1)
456 continue;
457#endif
458#ifdef SIGUSR2
459 if (i == SIGUSR2)
460 continue;
461#endif
462#ifdef SIGACTION
463 sigaction(i,&savsig[i],NULL);
464#else
465 signal(i,savsig[i]);
466#endif
467 }
468 }
469
470static void recsig(int i)
471 {
472 longjmp(save,1);
473#ifdef LINT
474 i=i;
475#endif
476 }
477
478#ifdef OPENSSL_SYS_MSDOS
479static int noecho_fgets(char *buf, int size, FILE *tty)
480 {
481 int i;
482 char *p;
483
484 p=buf;
485 for (;;)
486 {
487 if (size == 0)
488 {
489 *p='\0';
490 break;
491 }
492 size--;
493#ifdef WIN16TTY
494 i=_inchar();
495#else
496 i=getch();
497#endif
498 if (i == '\r') i='\n';
499 *(p++)=i;
500 if (i == '\n')
501 {
502 *p='\0';
503 break;
504 }
505 }
506#ifdef WIN_CONSOLE_BUG
507/* Win95 has several evil console bugs: one of these is that the
508 * last character read using getch() is passed to the next read: this is
509 * usually a CR so this can be trouble. No STDIO fix seems to work but
510 * flushing the console appears to do the trick.
511 */
512 {
513 HANDLE inh;
514 inh = GetStdHandle(STD_INPUT_HANDLE);
515 FlushConsoleInputBuffer(inh);
516 }
517#endif
518 return(strlen(buf));
519 }
520#endif
521#endif /* !OPENSSL_SYS_WINCE && !WIN16 */
diff --git a/src/lib/libcrypto/des/rpc_des.h b/src/lib/libcrypto/des/rpc_des.h
new file mode 100644
index 0000000000..4cbb4d2dcd
--- /dev/null
+++ b/src/lib/libcrypto/des/rpc_des.h
@@ -0,0 +1,131 @@
1/* crypto/des/rpc_des.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* @(#)des.h 2.2 88/08/10 4.0 RPCSRC; from 2.7 88/02/08 SMI */
60/*
61 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
62 * unrestricted use provided that this legend is included on all tape
63 * media and as a part of the software program in whole or part. Users
64 * may copy or modify Sun RPC without charge, but are not authorized
65 * to license or distribute it to anyone else except as part of a product or
66 * program developed by the user.
67 *
68 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
69 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
70 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
71 *
72 * Sun RPC is provided with no support and without any obligation on the
73 * part of Sun Microsystems, Inc. to assist in its use, correction,
74 * modification or enhancement.
75 *
76 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
77 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
78 * OR ANY PART THEREOF.
79 *
80 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
81 * or profits or other special, indirect and consequential damages, even if
82 * Sun has been advised of the possibility of such damages.
83 *
84 * Sun Microsystems, Inc.
85 * 2550 Garcia Avenue
86 * Mountain View, California 94043
87 */
88/*
89 * Generic DES driver interface
90 * Keep this file hardware independent!
91 * Copyright (c) 1986 by Sun Microsystems, Inc.
92 */
93
94#define DES_MAXLEN 65536 /* maximum # of bytes to encrypt */
95#define DES_QUICKLEN 16 /* maximum # of bytes to encrypt quickly */
96
97#ifdef HEADER_DES_H
98#undef ENCRYPT
99#undef DECRYPT
100#endif
101
102enum desdir { ENCRYPT, DECRYPT };
103enum desmode { CBC, ECB };
104
105/*
106 * parameters to ioctl call
107 */
108struct desparams {
109 unsigned char des_key[8]; /* key (with low bit parity) */
110 enum desdir des_dir; /* direction */
111 enum desmode des_mode; /* mode */
112 unsigned char des_ivec[8]; /* input vector */
113 unsigned des_len; /* number of bytes to crypt */
114 union {
115 unsigned char UDES_data[DES_QUICKLEN];
116 unsigned char *UDES_buf;
117 } UDES;
118# define des_data UDES.UDES_data /* direct data here if quick */
119# define des_buf UDES.UDES_buf /* otherwise, pointer to data */
120};
121
122/*
123 * Encrypt an arbitrary sized buffer
124 */
125#define DESIOCBLOCK _IOWR(d, 6, struct desparams)
126
127/*
128 * Encrypt of small amount of data, quickly
129 */
130#define DESIOCQUICK _IOWR(d, 7, struct desparams)
131
diff --git a/src/lib/libcrypto/des/rpc_enc.c b/src/lib/libcrypto/des/rpc_enc.c
new file mode 100644
index 0000000000..d937d08da5
--- /dev/null
+++ b/src/lib/libcrypto/des/rpc_enc.c
@@ -0,0 +1,98 @@
1/* crypto/des/rpc_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "rpc_des.h"
60#include "des_locl.h"
61#include "des_ver.h"
62
63int _des_crypt(char *buf,int len,struct desparams *desp);
64int _des_crypt(char *buf, int len, struct desparams *desp)
65 {
66 DES_key_schedule ks;
67 int enc;
68
69 DES_set_key_unchecked(&desp->des_key,&ks);
70 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
71
72 if (desp->des_mode == CBC)
73 DES_ecb_encrypt((const_DES_cblock *)desp->UDES.UDES_buf,
74 (DES_cblock *)desp->UDES.UDES_buf,&ks,
75 enc);
76 else
77 {
78 DES_ncbc_encrypt(desp->UDES.UDES_buf,desp->UDES.UDES_buf,
79 len,&ks,&desp->des_ivec,enc);
80#ifdef undef
81 /* len will always be %8 if called from common_crypt
82 * in secure_rpc.
83 * Libdes's cbc encrypt does not copy back the iv,
84 * so we have to do it here. */
85 /* It does now :-) eay 20/09/95 */
86
87 a=(char *)&(desp->UDES.UDES_buf[len-8]);
88 b=(char *)&(desp->des_ivec[0]);
89
90 *(a++)= *(b++); *(a++)= *(b++);
91 *(a++)= *(b++); *(a++)= *(b++);
92 *(a++)= *(b++); *(a++)= *(b++);
93 *(a++)= *(b++); *(a++)= *(b++);
94#endif
95 }
96 return(1);
97 }
98
diff --git a/src/lib/libcrypto/des/rpw.c b/src/lib/libcrypto/des/rpw.c
new file mode 100644
index 0000000000..8a9473c4f9
--- /dev/null
+++ b/src/lib/libcrypto/des/rpw.c
@@ -0,0 +1,99 @@
1/* crypto/des/rpw.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/des.h>
61
62int main(int argc, char *argv[])
63 {
64 DES_cblock k,k1;
65 int i;
66
67 printf("read passwd\n");
68 if ((i=des_read_password(&k,"Enter password:",0)) == 0)
69 {
70 printf("password = ");
71 for (i=0; i<8; i++)
72 printf("%02x ",k[i]);
73 }
74 else
75 printf("error %d\n",i);
76 printf("\n");
77 printf("read 2passwds and verify\n");
78 if ((i=des_read_2passwords(&k,&k1,
79 "Enter verified password:",1)) == 0)
80 {
81 printf("password1 = ");
82 for (i=0; i<8; i++)
83 printf("%02x ",k[i]);
84 printf("\n");
85 printf("password2 = ");
86 for (i=0; i<8; i++)
87 printf("%02x ",k1[i]);
88 printf("\n");
89 exit(1);
90 }
91 else
92 {
93 printf("error %d\n",i);
94 exit(0);
95 }
96#ifdef LINT
97 return(0);
98#endif
99 }
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
new file mode 100644
index 0000000000..a43ef3c881
--- /dev/null
+++ b/src/lib/libcrypto/des/set_key.c
@@ -0,0 +1,407 @@
1/* crypto/des/set_key.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/* set_key.c v 1.4 eay 24/9/91
60 * 1.4 Speed up by 400% :-)
61 * 1.3 added register declarations.
62 * 1.2 unrolled make_key_sched a bit more
63 * 1.1 added norm_expand_bits
64 * 1.0 First working version
65 */
66#include "des_locl.h"
67
68OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key); /* defaults to false */
69
70static const unsigned char odd_parity[256]={
71 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
72 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
73 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
74 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
75 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
76 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
77 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
78112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
79128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
80145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
81161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
82176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
83193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
84208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
85224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
86241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254};
87
88void DES_set_odd_parity(DES_cblock *key)
89 {
90 unsigned int i;
91
92 for (i=0; i<DES_KEY_SZ; i++)
93 (*key)[i]=odd_parity[(*key)[i]];
94 }
95
96int DES_check_key_parity(const_DES_cblock *key)
97 {
98 unsigned int i;
99
100 for (i=0; i<DES_KEY_SZ; i++)
101 {
102 if ((*key)[i] != odd_parity[(*key)[i]])
103 return(0);
104 }
105 return(1);
106 }
107
108/* Weak and semi week keys as take from
109 * %A D.W. Davies
110 * %A W.L. Price
111 * %T Security for Computer Networks
112 * %I John Wiley & Sons
113 * %D 1984
114 * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
115 * (and actual cblock values).
116 */
117#define NUM_WEAK_KEY 16
118static const DES_cblock weak_keys[NUM_WEAK_KEY]={
119 /* weak keys */
120 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
121 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
122 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
123 {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
124 /* semi-weak keys */
125 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
126 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
127 {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
128 {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
129 {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
130 {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
131 {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
132 {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
133 {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
134 {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
135 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
136 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
137
138int DES_is_weak_key(const_DES_cblock *key)
139 {
140 int i;
141
142 for (i=0; i<NUM_WEAK_KEY; i++)
143 /* Added == 0 to comparison, I obviously don't run
144 * this section very often :-(, thanks to
145 * engineering@MorningStar.Com for the fix
146 * eay 93/06/29
147 * Another problem, I was comparing only the first 4
148 * bytes, 97/03/18 */
149 if (memcmp(weak_keys[i],key,sizeof(DES_cblock)) == 0) return(1);
150 return(0);
151 }
152
153/* NOW DEFINED IN des_local.h
154 * See ecb_encrypt.c for a pseudo description of these macros.
155 * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
156 * (b)^=(t),\
157 * (a)=((a)^((t)<<(n))))
158 */
159
160#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
161 (a)=(a)^(t)^(t>>(16-(n))))
162
163static const DES_LONG des_skb[8][64]={
164 {
165 /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
166 0x00000000L,0x00000010L,0x20000000L,0x20000010L,
167 0x00010000L,0x00010010L,0x20010000L,0x20010010L,
168 0x00000800L,0x00000810L,0x20000800L,0x20000810L,
169 0x00010800L,0x00010810L,0x20010800L,0x20010810L,
170 0x00000020L,0x00000030L,0x20000020L,0x20000030L,
171 0x00010020L,0x00010030L,0x20010020L,0x20010030L,
172 0x00000820L,0x00000830L,0x20000820L,0x20000830L,
173 0x00010820L,0x00010830L,0x20010820L,0x20010830L,
174 0x00080000L,0x00080010L,0x20080000L,0x20080010L,
175 0x00090000L,0x00090010L,0x20090000L,0x20090010L,
176 0x00080800L,0x00080810L,0x20080800L,0x20080810L,
177 0x00090800L,0x00090810L,0x20090800L,0x20090810L,
178 0x00080020L,0x00080030L,0x20080020L,0x20080030L,
179 0x00090020L,0x00090030L,0x20090020L,0x20090030L,
180 0x00080820L,0x00080830L,0x20080820L,0x20080830L,
181 0x00090820L,0x00090830L,0x20090820L,0x20090830L,
182 },{
183 /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
184 0x00000000L,0x02000000L,0x00002000L,0x02002000L,
185 0x00200000L,0x02200000L,0x00202000L,0x02202000L,
186 0x00000004L,0x02000004L,0x00002004L,0x02002004L,
187 0x00200004L,0x02200004L,0x00202004L,0x02202004L,
188 0x00000400L,0x02000400L,0x00002400L,0x02002400L,
189 0x00200400L,0x02200400L,0x00202400L,0x02202400L,
190 0x00000404L,0x02000404L,0x00002404L,0x02002404L,
191 0x00200404L,0x02200404L,0x00202404L,0x02202404L,
192 0x10000000L,0x12000000L,0x10002000L,0x12002000L,
193 0x10200000L,0x12200000L,0x10202000L,0x12202000L,
194 0x10000004L,0x12000004L,0x10002004L,0x12002004L,
195 0x10200004L,0x12200004L,0x10202004L,0x12202004L,
196 0x10000400L,0x12000400L,0x10002400L,0x12002400L,
197 0x10200400L,0x12200400L,0x10202400L,0x12202400L,
198 0x10000404L,0x12000404L,0x10002404L,0x12002404L,
199 0x10200404L,0x12200404L,0x10202404L,0x12202404L,
200 },{
201 /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
202 0x00000000L,0x00000001L,0x00040000L,0x00040001L,
203 0x01000000L,0x01000001L,0x01040000L,0x01040001L,
204 0x00000002L,0x00000003L,0x00040002L,0x00040003L,
205 0x01000002L,0x01000003L,0x01040002L,0x01040003L,
206 0x00000200L,0x00000201L,0x00040200L,0x00040201L,
207 0x01000200L,0x01000201L,0x01040200L,0x01040201L,
208 0x00000202L,0x00000203L,0x00040202L,0x00040203L,
209 0x01000202L,0x01000203L,0x01040202L,0x01040203L,
210 0x08000000L,0x08000001L,0x08040000L,0x08040001L,
211 0x09000000L,0x09000001L,0x09040000L,0x09040001L,
212 0x08000002L,0x08000003L,0x08040002L,0x08040003L,
213 0x09000002L,0x09000003L,0x09040002L,0x09040003L,
214 0x08000200L,0x08000201L,0x08040200L,0x08040201L,
215 0x09000200L,0x09000201L,0x09040200L,0x09040201L,
216 0x08000202L,0x08000203L,0x08040202L,0x08040203L,
217 0x09000202L,0x09000203L,0x09040202L,0x09040203L,
218 },{
219 /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
220 0x00000000L,0x00100000L,0x00000100L,0x00100100L,
221 0x00000008L,0x00100008L,0x00000108L,0x00100108L,
222 0x00001000L,0x00101000L,0x00001100L,0x00101100L,
223 0x00001008L,0x00101008L,0x00001108L,0x00101108L,
224 0x04000000L,0x04100000L,0x04000100L,0x04100100L,
225 0x04000008L,0x04100008L,0x04000108L,0x04100108L,
226 0x04001000L,0x04101000L,0x04001100L,0x04101100L,
227 0x04001008L,0x04101008L,0x04001108L,0x04101108L,
228 0x00020000L,0x00120000L,0x00020100L,0x00120100L,
229 0x00020008L,0x00120008L,0x00020108L,0x00120108L,
230 0x00021000L,0x00121000L,0x00021100L,0x00121100L,
231 0x00021008L,0x00121008L,0x00021108L,0x00121108L,
232 0x04020000L,0x04120000L,0x04020100L,0x04120100L,
233 0x04020008L,0x04120008L,0x04020108L,0x04120108L,
234 0x04021000L,0x04121000L,0x04021100L,0x04121100L,
235 0x04021008L,0x04121008L,0x04021108L,0x04121108L,
236 },{
237 /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
238 0x00000000L,0x10000000L,0x00010000L,0x10010000L,
239 0x00000004L,0x10000004L,0x00010004L,0x10010004L,
240 0x20000000L,0x30000000L,0x20010000L,0x30010000L,
241 0x20000004L,0x30000004L,0x20010004L,0x30010004L,
242 0x00100000L,0x10100000L,0x00110000L,0x10110000L,
243 0x00100004L,0x10100004L,0x00110004L,0x10110004L,
244 0x20100000L,0x30100000L,0x20110000L,0x30110000L,
245 0x20100004L,0x30100004L,0x20110004L,0x30110004L,
246 0x00001000L,0x10001000L,0x00011000L,0x10011000L,
247 0x00001004L,0x10001004L,0x00011004L,0x10011004L,
248 0x20001000L,0x30001000L,0x20011000L,0x30011000L,
249 0x20001004L,0x30001004L,0x20011004L,0x30011004L,
250 0x00101000L,0x10101000L,0x00111000L,0x10111000L,
251 0x00101004L,0x10101004L,0x00111004L,0x10111004L,
252 0x20101000L,0x30101000L,0x20111000L,0x30111000L,
253 0x20101004L,0x30101004L,0x20111004L,0x30111004L,
254 },{
255 /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
256 0x00000000L,0x08000000L,0x00000008L,0x08000008L,
257 0x00000400L,0x08000400L,0x00000408L,0x08000408L,
258 0x00020000L,0x08020000L,0x00020008L,0x08020008L,
259 0x00020400L,0x08020400L,0x00020408L,0x08020408L,
260 0x00000001L,0x08000001L,0x00000009L,0x08000009L,
261 0x00000401L,0x08000401L,0x00000409L,0x08000409L,
262 0x00020001L,0x08020001L,0x00020009L,0x08020009L,
263 0x00020401L,0x08020401L,0x00020409L,0x08020409L,
264 0x02000000L,0x0A000000L,0x02000008L,0x0A000008L,
265 0x02000400L,0x0A000400L,0x02000408L,0x0A000408L,
266 0x02020000L,0x0A020000L,0x02020008L,0x0A020008L,
267 0x02020400L,0x0A020400L,0x02020408L,0x0A020408L,
268 0x02000001L,0x0A000001L,0x02000009L,0x0A000009L,
269 0x02000401L,0x0A000401L,0x02000409L,0x0A000409L,
270 0x02020001L,0x0A020001L,0x02020009L,0x0A020009L,
271 0x02020401L,0x0A020401L,0x02020409L,0x0A020409L,
272 },{
273 /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
274 0x00000000L,0x00000100L,0x00080000L,0x00080100L,
275 0x01000000L,0x01000100L,0x01080000L,0x01080100L,
276 0x00000010L,0x00000110L,0x00080010L,0x00080110L,
277 0x01000010L,0x01000110L,0x01080010L,0x01080110L,
278 0x00200000L,0x00200100L,0x00280000L,0x00280100L,
279 0x01200000L,0x01200100L,0x01280000L,0x01280100L,
280 0x00200010L,0x00200110L,0x00280010L,0x00280110L,
281 0x01200010L,0x01200110L,0x01280010L,0x01280110L,
282 0x00000200L,0x00000300L,0x00080200L,0x00080300L,
283 0x01000200L,0x01000300L,0x01080200L,0x01080300L,
284 0x00000210L,0x00000310L,0x00080210L,0x00080310L,
285 0x01000210L,0x01000310L,0x01080210L,0x01080310L,
286 0x00200200L,0x00200300L,0x00280200L,0x00280300L,
287 0x01200200L,0x01200300L,0x01280200L,0x01280300L,
288 0x00200210L,0x00200310L,0x00280210L,0x00280310L,
289 0x01200210L,0x01200310L,0x01280210L,0x01280310L,
290 },{
291 /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
292 0x00000000L,0x04000000L,0x00040000L,0x04040000L,
293 0x00000002L,0x04000002L,0x00040002L,0x04040002L,
294 0x00002000L,0x04002000L,0x00042000L,0x04042000L,
295 0x00002002L,0x04002002L,0x00042002L,0x04042002L,
296 0x00000020L,0x04000020L,0x00040020L,0x04040020L,
297 0x00000022L,0x04000022L,0x00040022L,0x04040022L,
298 0x00002020L,0x04002020L,0x00042020L,0x04042020L,
299 0x00002022L,0x04002022L,0x00042022L,0x04042022L,
300 0x00000800L,0x04000800L,0x00040800L,0x04040800L,
301 0x00000802L,0x04000802L,0x00040802L,0x04040802L,
302 0x00002800L,0x04002800L,0x00042800L,0x04042800L,
303 0x00002802L,0x04002802L,0x00042802L,0x04042802L,
304 0x00000820L,0x04000820L,0x00040820L,0x04040820L,
305 0x00000822L,0x04000822L,0x00040822L,0x04040822L,
306 0x00002820L,0x04002820L,0x00042820L,0x04042820L,
307 0x00002822L,0x04002822L,0x00042822L,0x04042822L,
308 }};
309
310int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule)
311 {
312 if (DES_check_key)
313 {
314 return DES_set_key_checked(key, schedule);
315 }
316 else
317 {
318 DES_set_key_unchecked(key, schedule);
319 return 0;
320 }
321 }
322
323/* return 0 if key parity is odd (correct),
324 * return -1 if key parity error,
325 * return -2 if illegal weak key.
326 */
327int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule)
328 {
329 if (!DES_check_key_parity(key))
330 return(-1);
331 if (DES_is_weak_key(key))
332 return(-2);
333 DES_set_key_unchecked(key, schedule);
334 return 0;
335 }
336
337void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
338 {
339 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
340 register DES_LONG c,d,t,s,t2;
341 register const unsigned char *in;
342 register DES_LONG *k;
343 register int i;
344
345#ifdef OPENBSD_DEV_CRYPTO
346 memcpy(schedule->key,key,sizeof schedule->key);
347 schedule->session=NULL;
348#endif
349 k = &schedule->ks->deslong[0];
350 in = &(*key)[0];
351
352 c2l(in,c);
353 c2l(in,d);
354
355 /* do PC1 in 47 simple operations :-)
356 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
357 * for the inspiration. :-) */
358 PERM_OP (d,c,t,4,0x0f0f0f0fL);
359 HPERM_OP(c,t,-2,0xcccc0000L);
360 HPERM_OP(d,t,-2,0xcccc0000L);
361 PERM_OP (d,c,t,1,0x55555555L);
362 PERM_OP (c,d,t,8,0x00ff00ffL);
363 PERM_OP (d,c,t,1,0x55555555L);
364 d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) |
365 ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
366 c&=0x0fffffffL;
367
368 for (i=0; i<ITERATIONS; i++)
369 {
370 if (shifts2[i])
371 { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
372 else
373 { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); }
374 c&=0x0fffffffL;
375 d&=0x0fffffffL;
376 /* could be a few less shifts but I am to lazy at this
377 * point in time to investigate */
378 s= des_skb[0][ (c )&0x3f ]|
379 des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
380 des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
381 des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
382 ((c>>22L)&0x38)];
383 t= des_skb[4][ (d )&0x3f ]|
384 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
385 des_skb[6][ (d>>15L)&0x3f ]|
386 des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
387
388 /* table contained 0213 4657 */
389 t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
390 *(k++)=ROTATE(t2,30)&0xffffffffL;
391
392 t2=((s>>16L)|(t&0xffff0000L));
393 *(k++)=ROTATE(t2,26)&0xffffffffL;
394 }
395 }
396
397int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule)
398 {
399 return(DES_set_key(key,schedule));
400 }
401/*
402#undef des_fixup_key_parity
403void des_fixup_key_parity(des_cblock *key)
404 {
405 des_set_odd_parity(key);
406 }
407*/
diff --git a/src/lib/libcrypto/des/speed.c b/src/lib/libcrypto/des/speed.c
new file mode 100644
index 0000000000..1616f4b7c9
--- /dev/null
+++ b/src/lib/libcrypto/des/speed.c
@@ -0,0 +1,314 @@
1/* crypto/des/speed.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
63#define TIMES
64#endif
65
66#include <stdio.h>
67
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD_IO
70OPENSSL_DECLARE_EXIT
71
72#ifndef OPENSSL_SYS_NETWARE
73#include <signal.h>
74#define crypt(c,s) (des_crypt((c),(s)))
75#endif
76
77#ifndef _IRIX
78#include <time.h>
79#endif
80#ifdef TIMES
81#include <sys/types.h>
82#include <sys/times.h>
83#endif
84
85/* Depending on the VMS version, the tms structure is perhaps defined.
86 The __TMS macro will show if it was. If it wasn't defined, we should
87 undefine TIMES, since that tells the rest of the program how things
88 should be handled. -- Richard Levitte */
89#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
90#undef TIMES
91#endif
92
93#ifndef TIMES
94#include <sys/timeb.h>
95#endif
96
97#if defined(sun) || defined(__ultrix)
98#define _POSIX_SOURCE
99#include <limits.h>
100#include <sys/param.h>
101#endif
102
103#include <openssl/des.h>
104
105/* The following if from times(3) man page. It may need to be changed */
106#ifndef HZ
107# ifndef CLK_TCK
108# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
109# define HZ 100.0
110# else /* _BSD_CLK_TCK_ */
111# define HZ ((double)_BSD_CLK_TCK_)
112# endif
113# else /* CLK_TCK */
114# define HZ ((double)CLK_TCK)
115# endif
116#endif
117
118#define BUFSIZE ((long)1024)
119long run=0;
120
121double Time_F(int s);
122#ifdef SIGALRM
123#if defined(__STDC__) || defined(sgi) || defined(_AIX)
124#define SIGRETTYPE void
125#else
126#define SIGRETTYPE int
127#endif
128
129SIGRETTYPE sig_done(int sig);
130SIGRETTYPE sig_done(int sig)
131 {
132 signal(SIGALRM,sig_done);
133 run=0;
134#ifdef LINT
135 sig=sig;
136#endif
137 }
138#endif
139
140#define START 0
141#define STOP 1
142
143double Time_F(int s)
144 {
145 double ret;
146#ifdef TIMES
147 static struct tms tstart,tend;
148
149 if (s == START)
150 {
151 times(&tstart);
152 return(0);
153 }
154 else
155 {
156 times(&tend);
157 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
158 return((ret == 0.0)?1e-6:ret);
159 }
160#else /* !times() */
161 static struct timeb tstart,tend;
162 long i;
163
164 if (s == START)
165 {
166 ftime(&tstart);
167 return(0);
168 }
169 else
170 {
171 ftime(&tend);
172 i=(long)tend.millitm-(long)tstart.millitm;
173 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
174 return((ret == 0.0)?1e-6:ret);
175 }
176#endif
177 }
178
179int main(int argc, char **argv)
180 {
181 long count;
182 static unsigned char buf[BUFSIZE];
183 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
184 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
185 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
186 DES_key_schedule sch,sch2,sch3;
187 double a,b,c,d,e;
188#ifndef SIGALRM
189 long ca,cb,cc,cd,ce;
190#endif
191
192#ifndef TIMES
193 printf("To get the most accurate results, try to run this\n");
194 printf("program when this computer is idle.\n");
195#endif
196
197 DES_set_key_unchecked(&key2,&sch2);
198 DES_set_key_unchecked(&key3,&sch3);
199
200#ifndef SIGALRM
201 printf("First we calculate the approximate speed ...\n");
202 DES_set_key_unchecked(&key,&sch);
203 count=10;
204 do {
205 long i;
206 DES_LONG data[2];
207
208 count*=2;
209 Time_F(START);
210 for (i=count; i; i--)
211 DES_encrypt1(data,&sch,DES_ENCRYPT);
212 d=Time_F(STOP);
213 } while (d < 3.0);
214 ca=count;
215 cb=count*3;
216 cc=count*3*8/BUFSIZE+1;
217 cd=count*8/BUFSIZE+1;
218 ce=count/20+1;
219 printf("Doing set_key %ld times\n",ca);
220#define COND(d) (count != (d))
221#define COUNT(d) (d)
222#else
223#define COND(c) (run)
224#define COUNT(d) (count)
225 signal(SIGALRM,sig_done);
226 printf("Doing set_key for 10 seconds\n");
227 alarm(10);
228#endif
229
230 Time_F(START);
231 for (count=0,run=1; COND(ca); count++)
232 DES_set_key_unchecked(&key,&sch);
233 d=Time_F(STOP);
234 printf("%ld set_key's in %.2f seconds\n",count,d);
235 a=((double)COUNT(ca))/d;
236
237#ifdef SIGALRM
238 printf("Doing DES_encrypt's for 10 seconds\n");
239 alarm(10);
240#else
241 printf("Doing DES_encrypt %ld times\n",cb);
242#endif
243 Time_F(START);
244 for (count=0,run=1; COND(cb); count++)
245 {
246 DES_LONG data[2];
247
248 DES_encrypt1(data,&sch,DES_ENCRYPT);
249 }
250 d=Time_F(STOP);
251 printf("%ld DES_encrypt's in %.2f second\n",count,d);
252 b=((double)COUNT(cb)*8)/d;
253
254#ifdef SIGALRM
255 printf("Doing DES_cbc_encrypt on %ld byte blocks for 10 seconds\n",
256 BUFSIZE);
257 alarm(10);
258#else
259 printf("Doing DES_cbc_encrypt %ld times on %ld byte blocks\n",cc,
260 BUFSIZE);
261#endif
262 Time_F(START);
263 for (count=0,run=1; COND(cc); count++)
264 DES_ncbc_encrypt(buf,buf,BUFSIZE,&sch,
265 &key,DES_ENCRYPT);
266 d=Time_F(STOP);
267 printf("%ld DES_cbc_encrypt's of %ld byte blocks in %.2f second\n",
268 count,BUFSIZE,d);
269 c=((double)COUNT(cc)*BUFSIZE)/d;
270
271#ifdef SIGALRM
272 printf("Doing DES_ede_cbc_encrypt on %ld byte blocks for 10 seconds\n",
273 BUFSIZE);
274 alarm(10);
275#else
276 printf("Doing DES_ede_cbc_encrypt %ld times on %ld byte blocks\n",cd,
277 BUFSIZE);
278#endif
279 Time_F(START);
280 for (count=0,run=1; COND(cd); count++)
281 DES_ede3_cbc_encrypt(buf,buf,BUFSIZE,
282 &sch,
283 &sch2,
284 &sch3,
285 &key,
286 DES_ENCRYPT);
287 d=Time_F(STOP);
288 printf("%ld DES_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n",
289 count,BUFSIZE,d);
290 d=((double)COUNT(cd)*BUFSIZE)/d;
291
292#ifdef SIGALRM
293 printf("Doing crypt for 10 seconds\n");
294 alarm(10);
295#else
296 printf("Doing crypt %ld times\n",ce);
297#endif
298 Time_F(START);
299 for (count=0,run=1; COND(ce); count++)
300 crypt("testing1","ef");
301 e=Time_F(STOP);
302 printf("%ld crypts in %.2f second\n",count,e);
303 e=((double)COUNT(ce))/e;
304
305 printf("set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
306 printf("DES raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
307 printf("DES cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
308 printf("DES ede cbc bytes per sec = %12.2f (%9.3fuS)\n",d,8.0e6/d);
309 printf("crypt per sec = %12.2f (%9.3fuS)\n",e,1.0e6/e);
310 exit(0);
311#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
312 return(0);
313#endif
314 }
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h
new file mode 100644
index 0000000000..b91936a5a5
--- /dev/null
+++ b/src/lib/libcrypto/des/spr.h
@@ -0,0 +1,204 @@
1/* crypto/des/spr.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
59OPENSSL_GLOBAL const DES_LONG DES_SPtrans[8][64]={
60{
61/* nibble 0 */
620x02080800L, 0x00080000L, 0x02000002L, 0x02080802L,
630x02000000L, 0x00080802L, 0x00080002L, 0x02000002L,
640x00080802L, 0x02080800L, 0x02080000L, 0x00000802L,
650x02000802L, 0x02000000L, 0x00000000L, 0x00080002L,
660x00080000L, 0x00000002L, 0x02000800L, 0x00080800L,
670x02080802L, 0x02080000L, 0x00000802L, 0x02000800L,
680x00000002L, 0x00000800L, 0x00080800L, 0x02080002L,
690x00000800L, 0x02000802L, 0x02080002L, 0x00000000L,
700x00000000L, 0x02080802L, 0x02000800L, 0x00080002L,
710x02080800L, 0x00080000L, 0x00000802L, 0x02000800L,
720x02080002L, 0x00000800L, 0x00080800L, 0x02000002L,
730x00080802L, 0x00000002L, 0x02000002L, 0x02080000L,
740x02080802L, 0x00080800L, 0x02080000L, 0x02000802L,
750x02000000L, 0x00000802L, 0x00080002L, 0x00000000L,
760x00080000L, 0x02000000L, 0x02000802L, 0x02080800L,
770x00000002L, 0x02080002L, 0x00000800L, 0x00080802L,
78},{
79/* nibble 1 */
800x40108010L, 0x00000000L, 0x00108000L, 0x40100000L,
810x40000010L, 0x00008010L, 0x40008000L, 0x00108000L,
820x00008000L, 0x40100010L, 0x00000010L, 0x40008000L,
830x00100010L, 0x40108000L, 0x40100000L, 0x00000010L,
840x00100000L, 0x40008010L, 0x40100010L, 0x00008000L,
850x00108010L, 0x40000000L, 0x00000000L, 0x00100010L,
860x40008010L, 0x00108010L, 0x40108000L, 0x40000010L,
870x40000000L, 0x00100000L, 0x00008010L, 0x40108010L,
880x00100010L, 0x40108000L, 0x40008000L, 0x00108010L,
890x40108010L, 0x00100010L, 0x40000010L, 0x00000000L,
900x40000000L, 0x00008010L, 0x00100000L, 0x40100010L,
910x00008000L, 0x40000000L, 0x00108010L, 0x40008010L,
920x40108000L, 0x00008000L, 0x00000000L, 0x40000010L,
930x00000010L, 0x40108010L, 0x00108000L, 0x40100000L,
940x40100010L, 0x00100000L, 0x00008010L, 0x40008000L,
950x40008010L, 0x00000010L, 0x40100000L, 0x00108000L,
96},{
97/* nibble 2 */
980x04000001L, 0x04040100L, 0x00000100L, 0x04000101L,
990x00040001L, 0x04000000L, 0x04000101L, 0x00040100L,
1000x04000100L, 0x00040000L, 0x04040000L, 0x00000001L,
1010x04040101L, 0x00000101L, 0x00000001L, 0x04040001L,
1020x00000000L, 0x00040001L, 0x04040100L, 0x00000100L,
1030x00000101L, 0x04040101L, 0x00040000L, 0x04000001L,
1040x04040001L, 0x04000100L, 0x00040101L, 0x04040000L,
1050x00040100L, 0x00000000L, 0x04000000L, 0x00040101L,
1060x04040100L, 0x00000100L, 0x00000001L, 0x00040000L,
1070x00000101L, 0x00040001L, 0x04040000L, 0x04000101L,
1080x00000000L, 0x04040100L, 0x00040100L, 0x04040001L,
1090x00040001L, 0x04000000L, 0x04040101L, 0x00000001L,
1100x00040101L, 0x04000001L, 0x04000000L, 0x04040101L,
1110x00040000L, 0x04000100L, 0x04000101L, 0x00040100L,
1120x04000100L, 0x00000000L, 0x04040001L, 0x00000101L,
1130x04000001L, 0x00040101L, 0x00000100L, 0x04040000L,
114},{
115/* nibble 3 */
1160x00401008L, 0x10001000L, 0x00000008L, 0x10401008L,
1170x00000000L, 0x10400000L, 0x10001008L, 0x00400008L,
1180x10401000L, 0x10000008L, 0x10000000L, 0x00001008L,
1190x10000008L, 0x00401008L, 0x00400000L, 0x10000000L,
1200x10400008L, 0x00401000L, 0x00001000L, 0x00000008L,
1210x00401000L, 0x10001008L, 0x10400000L, 0x00001000L,
1220x00001008L, 0x00000000L, 0x00400008L, 0x10401000L,
1230x10001000L, 0x10400008L, 0x10401008L, 0x00400000L,
1240x10400008L, 0x00001008L, 0x00400000L, 0x10000008L,
1250x00401000L, 0x10001000L, 0x00000008L, 0x10400000L,
1260x10001008L, 0x00000000L, 0x00001000L, 0x00400008L,
1270x00000000L, 0x10400008L, 0x10401000L, 0x00001000L,
1280x10000000L, 0x10401008L, 0x00401008L, 0x00400000L,
1290x10401008L, 0x00000008L, 0x10001000L, 0x00401008L,
1300x00400008L, 0x00401000L, 0x10400000L, 0x10001008L,
1310x00001008L, 0x10000000L, 0x10000008L, 0x10401000L,
132},{
133/* nibble 4 */
1340x08000000L, 0x00010000L, 0x00000400L, 0x08010420L,
1350x08010020L, 0x08000400L, 0x00010420L, 0x08010000L,
1360x00010000L, 0x00000020L, 0x08000020L, 0x00010400L,
1370x08000420L, 0x08010020L, 0x08010400L, 0x00000000L,
1380x00010400L, 0x08000000L, 0x00010020L, 0x00000420L,
1390x08000400L, 0x00010420L, 0x00000000L, 0x08000020L,
1400x00000020L, 0x08000420L, 0x08010420L, 0x00010020L,
1410x08010000L, 0x00000400L, 0x00000420L, 0x08010400L,
1420x08010400L, 0x08000420L, 0x00010020L, 0x08010000L,
1430x00010000L, 0x00000020L, 0x08000020L, 0x08000400L,
1440x08000000L, 0x00010400L, 0x08010420L, 0x00000000L,
1450x00010420L, 0x08000000L, 0x00000400L, 0x00010020L,
1460x08000420L, 0x00000400L, 0x00000000L, 0x08010420L,
1470x08010020L, 0x08010400L, 0x00000420L, 0x00010000L,
1480x00010400L, 0x08010020L, 0x08000400L, 0x00000420L,
1490x00000020L, 0x00010420L, 0x08010000L, 0x08000020L,
150},{
151/* nibble 5 */
1520x80000040L, 0x00200040L, 0x00000000L, 0x80202000L,
1530x00200040L, 0x00002000L, 0x80002040L, 0x00200000L,
1540x00002040L, 0x80202040L, 0x00202000L, 0x80000000L,
1550x80002000L, 0x80000040L, 0x80200000L, 0x00202040L,
1560x00200000L, 0x80002040L, 0x80200040L, 0x00000000L,
1570x00002000L, 0x00000040L, 0x80202000L, 0x80200040L,
1580x80202040L, 0x80200000L, 0x80000000L, 0x00002040L,
1590x00000040L, 0x00202000L, 0x00202040L, 0x80002000L,
1600x00002040L, 0x80000000L, 0x80002000L, 0x00202040L,
1610x80202000L, 0x00200040L, 0x00000000L, 0x80002000L,
1620x80000000L, 0x00002000L, 0x80200040L, 0x00200000L,
1630x00200040L, 0x80202040L, 0x00202000L, 0x00000040L,
1640x80202040L, 0x00202000L, 0x00200000L, 0x80002040L,
1650x80000040L, 0x80200000L, 0x00202040L, 0x00000000L,
1660x00002000L, 0x80000040L, 0x80002040L, 0x80202000L,
1670x80200000L, 0x00002040L, 0x00000040L, 0x80200040L,
168},{
169/* nibble 6 */
1700x00004000L, 0x00000200L, 0x01000200L, 0x01000004L,
1710x01004204L, 0x00004004L, 0x00004200L, 0x00000000L,
1720x01000000L, 0x01000204L, 0x00000204L, 0x01004000L,
1730x00000004L, 0x01004200L, 0x01004000L, 0x00000204L,
1740x01000204L, 0x00004000L, 0x00004004L, 0x01004204L,
1750x00000000L, 0x01000200L, 0x01000004L, 0x00004200L,
1760x01004004L, 0x00004204L, 0x01004200L, 0x00000004L,
1770x00004204L, 0x01004004L, 0x00000200L, 0x01000000L,
1780x00004204L, 0x01004000L, 0x01004004L, 0x00000204L,
1790x00004000L, 0x00000200L, 0x01000000L, 0x01004004L,
1800x01000204L, 0x00004204L, 0x00004200L, 0x00000000L,
1810x00000200L, 0x01000004L, 0x00000004L, 0x01000200L,
1820x00000000L, 0x01000204L, 0x01000200L, 0x00004200L,
1830x00000204L, 0x00004000L, 0x01004204L, 0x01000000L,
1840x01004200L, 0x00000004L, 0x00004004L, 0x01004204L,
1850x01000004L, 0x01004200L, 0x01004000L, 0x00004004L,
186},{
187/* nibble 7 */
1880x20800080L, 0x20820000L, 0x00020080L, 0x00000000L,
1890x20020000L, 0x00800080L, 0x20800000L, 0x20820080L,
1900x00000080L, 0x20000000L, 0x00820000L, 0x00020080L,
1910x00820080L, 0x20020080L, 0x20000080L, 0x20800000L,
1920x00020000L, 0x00820080L, 0x00800080L, 0x20020000L,
1930x20820080L, 0x20000080L, 0x00000000L, 0x00820000L,
1940x20000000L, 0x00800000L, 0x20020080L, 0x20800080L,
1950x00800000L, 0x00020000L, 0x20820000L, 0x00000080L,
1960x00800000L, 0x00020000L, 0x20000080L, 0x20820080L,
1970x00020080L, 0x20000000L, 0x00000000L, 0x00820000L,
1980x20800080L, 0x20020080L, 0x20020000L, 0x00800080L,
1990x20820000L, 0x00000080L, 0x00800080L, 0x20020000L,
2000x20820080L, 0x00800000L, 0x20800000L, 0x20000080L,
2010x00820000L, 0x00020080L, 0x20020080L, 0x20800000L,
2020x00000080L, 0x20820000L, 0x00820080L, 0x00000000L,
2030x20000000L, 0x20800080L, 0x00020000L, 0x00820080L,
204}};
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c
new file mode 100644
index 0000000000..9c2054bda6
--- /dev/null
+++ b/src/lib/libcrypto/des/str2key.c
@@ -0,0 +1,174 @@
1/* crypto/des/str2key.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#include <openssl/crypto.h>
61
62void DES_string_to_key(const char *str, DES_cblock *key)
63 {
64 DES_key_schedule ks;
65 int i,length;
66 register unsigned char j;
67
68 memset(key,0,8);
69 length=strlen(str);
70#ifdef OLD_STR_TO_KEY
71 for (i=0; i<length; i++)
72 (*key)[i%8]^=(str[i]<<1);
73#else /* MIT COMPATIBLE */
74 for (i=0; i<length; i++)
75 {
76 j=str[i];
77 if ((i%16) < 8)
78 (*key)[i%8]^=(j<<1);
79 else
80 {
81 /* Reverse the bit order 05/05/92 eay */
82 j=((j<<4)&0xf0)|((j>>4)&0x0f);
83 j=((j<<2)&0xcc)|((j>>2)&0x33);
84 j=((j<<1)&0xaa)|((j>>1)&0x55);
85 (*key)[7-(i%8)]^=j;
86 }
87 }
88#endif
89 DES_set_odd_parity(key);
90#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
91 if(DES_is_weak_key(key))
92 (*key)[7] ^= 0xF0;
93 DES_set_key(key,&ks);
94#else
95 DES_set_key_unchecked(key,&ks);
96#endif
97 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key);
98 OPENSSL_cleanse(&ks,sizeof(ks));
99 DES_set_odd_parity(key);
100 }
101
102void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
103 {
104 DES_key_schedule ks;
105 int i,length;
106 register unsigned char j;
107
108 memset(key1,0,8);
109 memset(key2,0,8);
110 length=strlen(str);
111#ifdef OLD_STR_TO_KEY
112 if (length <= 8)
113 {
114 for (i=0; i<length; i++)
115 {
116 (*key2)[i]=(*key1)[i]=(str[i]<<1);
117 }
118 }
119 else
120 {
121 for (i=0; i<length; i++)
122 {
123 if ((i/8)&1)
124 (*key2)[i%8]^=(str[i]<<1);
125 else
126 (*key1)[i%8]^=(str[i]<<1);
127 }
128 }
129#else /* MIT COMPATIBLE */
130 for (i=0; i<length; i++)
131 {
132 j=str[i];
133 if ((i%32) < 16)
134 {
135 if ((i%16) < 8)
136 (*key1)[i%8]^=(j<<1);
137 else
138 (*key2)[i%8]^=(j<<1);
139 }
140 else
141 {
142 j=((j<<4)&0xf0)|((j>>4)&0x0f);
143 j=((j<<2)&0xcc)|((j>>2)&0x33);
144 j=((j<<1)&0xaa)|((j>>1)&0x55);
145 if ((i%16) < 8)
146 (*key1)[7-(i%8)]^=j;
147 else
148 (*key2)[7-(i%8)]^=j;
149 }
150 }
151 if (length <= 8) memcpy(key2,key1,8);
152#endif
153 DES_set_odd_parity(key1);
154 DES_set_odd_parity(key2);
155#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
156 if(DES_is_weak_key(key1))
157 (*key1)[7] ^= 0xF0;
158 DES_set_key(key1,&ks);
159#else
160 DES_set_key_unchecked(key1,&ks);
161#endif
162 DES_cbc_cksum((const unsigned char*)str,key1,length,&ks,key1);
163#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
164 if(DES_is_weak_key(key2))
165 (*key2)[7] ^= 0xF0;
166 DES_set_key(key2,&ks);
167#else
168 DES_set_key_unchecked(key2,&ks);
169#endif
170 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2);
171 OPENSSL_cleanse(&ks,sizeof(ks));
172 DES_set_odd_parity(key1);
173 DES_set_odd_parity(key2);
174 }
diff --git a/src/lib/libcrypto/des/t/test b/src/lib/libcrypto/des/t/test
new file mode 100644
index 0000000000..97acd0552e
--- /dev/null
+++ b/src/lib/libcrypto/des/t/test
@@ -0,0 +1,27 @@
1#!./perl
2
3BEGIN { push(@INC, qw(../../../lib ../../lib ../lib lib)); }
4
5use DES;
6
7$key='00000000';
8$ks=DES::set_key($key);
9@a=split(//,$ks);
10foreach (@a) { printf "%02x-",ord($_); }
11print "\n";
12
13
14$key=DES::random_key();
15print "($_)\n";
16@a=split(//,$key);
17foreach (@a) { printf "%02x-",ord($_); }
18print "\n";
19$str="this is and again into the breach";
20($k1,$k2)=DES::string_to_2keys($str);
21@a=split(//,$k1);
22foreach (@a) { printf "%02x-",ord($_); }
23print "\n";
24@a=split(//,$k2);
25foreach (@a) { printf "%02x-",ord($_); }
26print "\n";
27
diff --git a/src/lib/libcrypto/des/times/486-50.sol b/src/lib/libcrypto/des/times/486-50.sol
new file mode 100644
index 0000000000..0de62d6db3
--- /dev/null
+++ b/src/lib/libcrypto/des/times/486-50.sol
@@ -0,0 +1,16 @@
1Solaris 2.4, 486 50mhz, gcc 2.6.3
2options des ecb/s
316 r2 i 43552.51 100.0%
416 r1 i 43487.45 99.9%
516 c p 43003.23 98.7%
616 r2 p 42339.00 97.2%
716 c i 41900.91 96.2%
816 r1 p 41360.64 95.0%
9 4 c i 38728.48 88.9%
10 4 c p 38225.63 87.8%
11 4 r1 i 38085.79 87.4%
12 4 r2 i 37825.64 86.9%
13 4 r2 p 34611.00 79.5%
14 4 r1 p 31802.00 73.0%
15-DDES_UNROLL -DDES_RISC2
16
diff --git a/src/lib/libcrypto/des/times/586-100.lnx b/src/lib/libcrypto/des/times/586-100.lnx
new file mode 100644
index 0000000000..4323914a11
--- /dev/null
+++ b/src/lib/libcrypto/des/times/586-100.lnx
@@ -0,0 +1,20 @@
1Pentium 100
2Linux 2 kernel
3gcc 2.7.0 -O3 -fomit-frame-pointer
4No X server running, just a console, it makes the top speed jump from 151,000
5to 158,000 :-).
6options des ecb/s
7assember 281000.00 177.1%
816 r1 p 158667.40 100.0%
916 r1 i 148471.70 93.6%
1016 r2 p 143961.80 90.7%
1116 r2 i 141689.20 89.3%
12 4 r1 i 140100.00 88.3%
13 4 r2 i 134049.40 84.5%
1416 c i 124145.20 78.2%
1516 c p 121584.20 76.6%
16 4 c i 118116.00 74.4%
17 4 r2 p 117977.90 74.4%
18 4 c p 114971.40 72.5%
19 4 r1 p 114578.40 72.2%
20-DDES_UNROLL -DDES_RISC1 -DDES_PTR
diff --git a/src/lib/libcrypto/des/times/686-200.fre b/src/lib/libcrypto/des/times/686-200.fre
new file mode 100644
index 0000000000..7d83f6adee
--- /dev/null
+++ b/src/lib/libcrypto/des/times/686-200.fre
@@ -0,0 +1,18 @@
1Pentium 100
2Free BSD 2.1.5 kernel
3gcc 2.7.2.2 -O3 -fomit-frame-pointer
4options des ecb/s
5assember 578000.00 133.1%
616 r2 i 434454.80 100.0%
716 r1 i 433621.43 99.8%
816 r2 p 431375.69 99.3%
9 4 r1 i 423722.30 97.5%
10 4 r2 i 422399.40 97.2%
1116 r1 p 421739.40 97.1%
1216 c i 399027.94 91.8%
1316 c p 372251.70 85.7%
14 4 c i 365118.35 84.0%
15 4 c p 352880.51 81.2%
16 4 r2 p 255104.90 58.7%
17 4 r1 p 251289.18 57.8%
18-DDES_UNROLL -DDES_RISC2
diff --git a/src/lib/libcrypto/des/times/aix.cc b/src/lib/libcrypto/des/times/aix.cc
new file mode 100644
index 0000000000..d96b74e2ce
--- /dev/null
+++ b/src/lib/libcrypto/des/times/aix.cc
@@ -0,0 +1,26 @@
1From: Paco Garcia <pgarcia@cam.es>
2
3This machine is a Bull Estrella Minitower Model MT604-100
4Processor : PPC604
5P.Speed : 100Mhz
6Data/Instr Cache : 16 K
7L2 Cache : 256 K
8PCI BUS Speed : 33 Mhz
9TransfRate PCI : 132 MB/s
10Memory : 96 MB
11
12options des ecb/s
13 4 c p 275118.61 100.0%
14 4 c i 273545.07 99.4%
15 4 r2 p 270441.02 98.3%
16 4 r1 p 253052.15 92.0%
17 4 r2 i 240842.97 87.5%
18 4 r1 i 240556.66 87.4%
1916 c i 224603.99 81.6%
2016 c p 224483.98 81.6%
2116 r2 p 215691.19 78.4%
2216 r1 p 208332.83 75.7%
2316 r1 i 199206.50 72.4%
2416 r2 i 198963.70 72.3%
25-DDES_PTR
26
diff --git a/src/lib/libcrypto/des/times/alpha.cc b/src/lib/libcrypto/des/times/alpha.cc
new file mode 100644
index 0000000000..95c17efae7
--- /dev/null
+++ b/src/lib/libcrypto/des/times/alpha.cc
@@ -0,0 +1,18 @@
1cc -O2
2DES_LONG is 'unsigned int'
3
4options des ecb/s
5 4 r2 p 181146.14 100.0%
616 r2 p 172102.94 95.0%
7 4 r2 i 165424.11 91.3%
816 c p 160468.64 88.6%
9 4 c p 156653.59 86.5%
10 4 c i 155245.18 85.7%
11 4 r1 p 154729.68 85.4%
1216 r2 i 154137.69 85.1%
1316 r1 p 152357.96 84.1%
1416 c i 148743.91 82.1%
15 4 r1 i 146695.59 81.0%
1616 r1 i 144961.00 80.0%
17-DDES_RISC2 -DDES_PTR
18
diff --git a/src/lib/libcrypto/des/times/hpux.cc b/src/lib/libcrypto/des/times/hpux.cc
new file mode 100644
index 0000000000..3de856ddac
--- /dev/null
+++ b/src/lib/libcrypto/des/times/hpux.cc
@@ -0,0 +1,17 @@
1HPUX 10 - 9000/887 - cc -D_HPUX_SOURCE -Aa +ESlit +O2 -Wl,-a,archive
2
3options des ecb/s
416 c i 149448.90 100.0%
5 4 c i 145861.79 97.6%
616 r2 i 141710.96 94.8%
716 r1 i 139455.33 93.3%
8 4 r2 i 138800.00 92.9%
9 4 r1 i 136692.65 91.5%
1016 r2 p 110228.17 73.8%
1116 r1 p 109397.07 73.2%
1216 c p 109209.89 73.1%
13 4 c p 108014.71 72.3%
14 4 r2 p 107873.88 72.2%
15 4 r1 p 107685.83 72.1%
16-DDES_UNROLL
17
diff --git a/src/lib/libcrypto/des/times/sparc.gcc b/src/lib/libcrypto/des/times/sparc.gcc
new file mode 100644
index 0000000000..8eaa042104
--- /dev/null
+++ b/src/lib/libcrypto/des/times/sparc.gcc
@@ -0,0 +1,17 @@
1solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2
2
3options des ecb/s
416 c i 124382.70 100.0%
5 4 c i 118884.68 95.6%
616 c p 112261.20 90.3%
716 r2 i 111777.10 89.9%
816 r2 p 108896.30 87.5%
916 r1 p 108791.59 87.5%
10 4 c p 107290.10 86.3%
11 4 r1 p 104583.80 84.1%
1216 r1 i 104206.20 83.8%
13 4 r2 p 103709.80 83.4%
14 4 r2 i 98306.43 79.0%
15 4 r1 i 91525.80 73.6%
16-DDES_UNROLL
17
diff --git a/src/lib/libcrypto/des/times/usparc.cc b/src/lib/libcrypto/des/times/usparc.cc
new file mode 100644
index 0000000000..0864285ef6
--- /dev/null
+++ b/src/lib/libcrypto/des/times/usparc.cc
@@ -0,0 +1,31 @@
1solaris 2.5.1 usparc 167mhz?? - SC4.0 cc -fast -Xa -xO5
2
3For the ultra sparc, SunC 4.0 cc -fast -Xa -xO5, running 'des_opts'
4gives a speed of 475,000 des/s while 'speed' gives 417,000 des/s.
5I believe the difference is tied up in optimisation that the compiler
6is able to perform when the code is 'inlined'. For 'speed', the DES
7routines are being linked from a library. I'll record the higher
8speed since if performance is everything, you can always inline
9'des_enc.c'.
10
11[ 16-Jan-06 - I've been playing with the
12 '-xtarget=ultra -xarch=v8plus -Xa -xO5 -Xa'
13 and while it makes the des_opts numbers much slower, it makes the
14 actual 'speed' numbers look better which is a realistic version of
15 using the libraries. ]
16
17options des ecb/s
1816 r1 p 475516.90 100.0%
1916 r2 p 439388.10 92.4%
2016 c i 427001.40 89.8%
2116 c p 419516.50 88.2%
22 4 r2 p 409491.70 86.1%
23 4 r1 p 404266.90 85.0%
24 4 c p 398121.00 83.7%
25 4 c i 370588.40 77.9%
26 4 r1 i 362742.20 76.3%
2716 r2 i 331275.50 69.7%
2816 r1 i 324730.60 68.3%
29 4 r2 i 63535.10 13.4% <-- very very weird, must be cache problems.
30-DDES_UNROLL -DDES_RISC1 -DDES_PTR
31
diff --git a/src/lib/libcrypto/des/typemap b/src/lib/libcrypto/des/typemap
new file mode 100644
index 0000000000..a524f53634
--- /dev/null
+++ b/src/lib/libcrypto/des/typemap
@@ -0,0 +1,34 @@
1#
2# DES SECTION
3#
4deschar * T_DESCHARP
5des_cblock * T_CBLOCK
6des_cblock T_CBLOCK
7des_key_schedule T_SCHEDULE
8des_key_schedule * T_SCHEDULE
9
10INPUT
11T_CBLOCK
12 $var=(des_cblock *)SvPV($arg,len);
13 if (len < DES_KEY_SZ)
14 {
15 croak(\"$var needs to be at least %u bytes long\",DES_KEY_SZ);
16 }
17
18T_SCHEDULE
19 $var=(des_key_schedule *)SvPV($arg,len);
20 if (len < DES_SCHEDULE_SZ)
21 {
22 croak(\"$var needs to be at least %u bytes long\",
23 DES_SCHEDULE_SZ);
24 }
25
26OUTPUT
27T_CBLOCK
28 sv_setpvn($arg,(char *)$var,DES_KEY_SZ);
29
30T_SCHEDULE
31 sv_setpvn($arg,(char *)$var,DES_SCHEDULE_SZ);
32
33T_DESCHARP
34 sv_setpvn($arg,(char *)$var,len);
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c
new file mode 100644
index 0000000000..dc0c761b71
--- /dev/null
+++ b/src/lib/libcrypto/des/xcbc_enc.c
@@ -0,0 +1,197 @@
1/* crypto/des/xcbc_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/* RSA's DESX */
62
63#if 0 /* broken code, preserved just in case anyone specifically looks for this */
64static unsigned char desx_white_in2out[256]={
650xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0,
660x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A,
670x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36,
680x3E,0xEE,0xFB,0x95,0x1A,0xFE,0xCE,0xA8,0x34,0xA9,0x13,0xF0,0xA6,0x3F,0xD8,0x0C,
690x78,0x24,0xAF,0x23,0x52,0xC1,0x67,0x17,0xF5,0x66,0x90,0xE7,0xE8,0x07,0xB8,0x60,
700x48,0xE6,0x1E,0x53,0xF3,0x92,0xA4,0x72,0x8C,0x08,0x15,0x6E,0x86,0x00,0x84,0xFA,
710xF4,0x7F,0x8A,0x42,0x19,0xF6,0xDB,0xCD,0x14,0x8D,0x50,0x12,0xBA,0x3C,0x06,0x4E,
720xEC,0xB3,0x35,0x11,0xA1,0x88,0x8E,0x2B,0x94,0x99,0xB7,0x71,0x74,0xD3,0xE4,0xBF,
730x3A,0xDE,0x96,0x0E,0xBC,0x0A,0xED,0x77,0xFC,0x37,0x6B,0x03,0x79,0x89,0x62,0xC6,
740xD7,0xC0,0xD2,0x7C,0x6A,0x8B,0x22,0xA3,0x5B,0x05,0x5D,0x02,0x75,0xD5,0x61,0xE3,
750x18,0x8F,0x55,0x51,0xAD,0x1F,0x0B,0x5E,0x85,0xE5,0xC2,0x57,0x63,0xCA,0x3D,0x6C,
760xB4,0xC5,0xCC,0x70,0xB2,0x91,0x59,0x0D,0x47,0x20,0xC8,0x4F,0x58,0xE0,0x01,0xE2,
770x16,0x38,0xC4,0x6F,0x3B,0x0F,0x65,0x46,0xBE,0x7E,0x2D,0x7B,0x82,0xF9,0x40,0xB5,
780x1D,0x73,0xF8,0xEB,0x26,0xC7,0x87,0x97,0x25,0x54,0xB1,0x28,0xAA,0x98,0x9D,0xA5,
790x64,0x6D,0x7A,0xD4,0x10,0x81,0x44,0xEF,0x49,0xD6,0xAE,0x2E,0xDD,0x76,0x5C,0x2F,
800xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB,
81 };
82
83void DES_xwhite_in2out(const_DES_cblock *des_key, const_DES_cblock *in_white,
84 DES_cblock *out_white)
85 {
86 int out0,out1;
87 int i;
88 const unsigned char *key = &(*des_key)[0];
89 const unsigned char *in = &(*in_white)[0];
90 unsigned char *out = &(*out_white)[0];
91
92 out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0;
93 out0=out1=0;
94 for (i=0; i<8; i++)
95 {
96 out[i]=key[i]^desx_white_in2out[out0^out1];
97 out0=out1;
98 out1=(int)out[i&0x07];
99 }
100
101 out0=out[0];
102 out1=out[i]; /* BUG: out-of-bounds read */
103 for (i=0; i<8; i++)
104 {
105 out[i]=in[i]^desx_white_in2out[out0^out1];
106 out0=out1;
107 out1=(int)out[i&0x07];
108 }
109 }
110#endif
111
112void DES_xcbc_encrypt(const unsigned char *in, unsigned char *out,
113 long length, DES_key_schedule *schedule,
114 DES_cblock *ivec, const_DES_cblock *inw,
115 const_DES_cblock *outw, int enc)
116 {
117 register DES_LONG tin0,tin1;
118 register DES_LONG tout0,tout1,xor0,xor1;
119 register DES_LONG inW0,inW1,outW0,outW1;
120 register const unsigned char *in2;
121 register long l=length;
122 DES_LONG tin[2];
123 unsigned char *iv;
124
125 in2 = &(*inw)[0];
126 c2l(in2,inW0);
127 c2l(in2,inW1);
128 in2 = &(*outw)[0];
129 c2l(in2,outW0);
130 c2l(in2,outW1);
131
132 iv = &(*ivec)[0];
133
134 if (enc)
135 {
136 c2l(iv,tout0);
137 c2l(iv,tout1);
138 for (l-=8; l>=0; l-=8)
139 {
140 c2l(in,tin0);
141 c2l(in,tin1);
142 tin0^=tout0^inW0; tin[0]=tin0;
143 tin1^=tout1^inW1; tin[1]=tin1;
144 DES_encrypt1(tin,schedule,DES_ENCRYPT);
145 tout0=tin[0]^outW0; l2c(tout0,out);
146 tout1=tin[1]^outW1; l2c(tout1,out);
147 }
148 if (l != -8)
149 {
150 c2ln(in,tin0,tin1,l+8);
151 tin0^=tout0^inW0; tin[0]=tin0;
152 tin1^=tout1^inW1; tin[1]=tin1;
153 DES_encrypt1(tin,schedule,DES_ENCRYPT);
154 tout0=tin[0]^outW0; l2c(tout0,out);
155 tout1=tin[1]^outW1; l2c(tout1,out);
156 }
157 iv = &(*ivec)[0];
158 l2c(tout0,iv);
159 l2c(tout1,iv);
160 }
161 else
162 {
163 c2l(iv,xor0);
164 c2l(iv,xor1);
165 for (l-=8; l>0; l-=8)
166 {
167 c2l(in,tin0); tin[0]=tin0^outW0;
168 c2l(in,tin1); tin[1]=tin1^outW1;
169 DES_encrypt1(tin,schedule,DES_DECRYPT);
170 tout0=tin[0]^xor0^inW0;
171 tout1=tin[1]^xor1^inW1;
172 l2c(tout0,out);
173 l2c(tout1,out);
174 xor0=tin0;
175 xor1=tin1;
176 }
177 if (l != -8)
178 {
179 c2l(in,tin0); tin[0]=tin0^outW0;
180 c2l(in,tin1); tin[1]=tin1^outW1;
181 DES_encrypt1(tin,schedule,DES_DECRYPT);
182 tout0=tin[0]^xor0^inW0;
183 tout1=tin[1]^xor1^inW1;
184 l2cn(tout0,tout1,out,l+8);
185 xor0=tin0;
186 xor1=tin1;
187 }
188
189 iv = &(*ivec)[0];
190 l2c(xor0,iv);
191 l2c(xor1,iv);
192 }
193 tin0=tin1=tout0=tout1=xor0=xor1=0;
194 inW0=inW1=outW0=outW1=0;
195 tin[0]=tin[1]=0;
196 }
197