summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2014-02-27 21:04:58 +0000
committercvs2svn <admin@example.com>2014-02-27 21:04:58 +0000
commit726818f36b5221c023cd04c4b90bdbc08e94cd96 (patch)
treecf8221f3aa5bf5a578ddf1ecf5677ad08c04d342 /src/lib/libcrypto/des
parent3b6d92e82b1421b811bcdec7f7fdfb31eeef18de (diff)
downloadopenbsd-OPENBSD_5_5_BASE.tar.gz
openbsd-OPENBSD_5_5_BASE.tar.bz2
openbsd-OPENBSD_5_5_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_5_5_BASE'.OPENBSD_5_5_BASE
Diffstat (limited to 'src/lib/libcrypto/des')
-rw-r--r--src/lib/libcrypto/des/COPYRIGHT50
-rw-r--r--src/lib/libcrypto/des/asm/crypt586.pl209
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl453
-rw-r--r--src/lib/libcrypto/des/asm/des_enc.m42099
-rw-r--r--src/lib/libcrypto/des/asm/desboth.pl79
-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.h250
-rw-r--r--src/lib/libcrypto/des/des_enc.c404
-rw-r--r--src/lib/libcrypto/des/des_locl.h432
-rw-r--r--src/lib/libcrypto/des/ecb3_enc.c83
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c122
-rw-r--r--src/lib/libcrypto/des/ede_cbcm_enc.c199
-rw-r--r--src/lib/libcrypto/des/enc_read.c240
-rw-r--r--src/lib/libcrypto/des/enc_writ.c179
-rw-r--r--src/lib/libcrypto/des/fcrypt.c170
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c146
-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/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/set_key.c416
-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/xcbc_enc.c197
31 files changed, 0 insertions, 7691 deletions
diff --git a/src/lib/libcrypto/des/COPYRIGHT b/src/lib/libcrypto/des/COPYRIGHT
deleted file mode 100644
index 5469e1e469..0000000000
--- a/src/lib/libcrypto/des/COPYRIGHT
+++ /dev/null
@@ -1,50 +0,0 @@
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/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl
deleted file mode 100644
index e36f7d44bd..0000000000
--- a/src/lib/libcrypto/des/asm/crypt586.pl
+++ /dev/null
@@ -1,209 +0,0 @@
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
9$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
10push(@INC,"${dir}","${dir}../../perlasm");
11require "x86asm.pl";
12
13&asm_init($ARGV[0],"crypt586.pl");
14
15$L="edi";
16$R="esi";
17
18&external_label("DES_SPtrans");
19&fcrypt_body("fcrypt_body");
20&asm_finish();
21
22sub fcrypt_body
23 {
24 local($name,$do_ip)=@_;
25
26 &function_begin($name);
27
28 &comment("");
29 &comment("Load the 2 words");
30 $trans="ebp";
31
32 &xor( $L, $L);
33 &xor( $R, $R);
34
35 # PIC-ification:-)
36 &picmeup("edx","DES_SPtrans");
37 #if ($cpp) { &picmeup("edx","DES_SPtrans"); }
38 #else { &lea("edx",&DWP("DES_SPtrans")); }
39 &push("edx"); # becomes &swtmp(1)
40 #
41 &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT
42
43 &push(&DWC(25)); # add a variable
44
45 &set_label("start");
46 for ($i=0; $i<16; $i+=2)
47 {
48 &comment("");
49 &comment("Round $i");
50 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
51
52 &comment("");
53 &comment("Round ".sprintf("%d",$i+1));
54 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
55 }
56 &mov("ebx", &swtmp(0));
57 &mov("eax", $L);
58 &dec("ebx");
59 &mov($L, $R);
60 &mov($R, "eax");
61 &mov(&swtmp(0), "ebx");
62 &jnz(&label("start"));
63
64 &comment("");
65 &comment("FP");
66 &mov("edx",&wparam(0));
67
68 &FP_new($R,$L,"eax",3);
69 &mov(&DWP(0,"edx","",0),"eax");
70 &mov(&DWP(4,"edx","",0),$L);
71
72 &add("esp",8); # remove variables
73
74 &function_end($name);
75 }
76
77sub D_ENCRYPT
78 {
79 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
80
81 &mov( $u, &wparam(2)); # 2
82 &mov( $t, $R);
83 &shr( $t, 16); # 1
84 &mov( $tmp2, &wparam(3)); # 2
85 &xor( $t, $R); # 1
86
87 &and( $u, $t); # 2
88 &and( $t, $tmp2); # 2
89
90 &mov( $tmp1, $u);
91 &shl( $tmp1, 16); # 1
92 &mov( $tmp2, $t);
93 &shl( $tmp2, 16); # 1
94 &xor( $u, $tmp1); # 2
95 &xor( $t, $tmp2); # 2
96 &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2
97 &xor( $u, $tmp1);
98 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2
99 &xor( $u, $R);
100 &xor( $t, $R);
101 &xor( $t, $tmp2);
102
103 &and( $u, "0xfcfcfcfc" ); # 2
104 &xor( $tmp1, $tmp1); # 1
105 &and( $t, "0xcfcfcfcf" ); # 2
106 &xor( $tmp2, $tmp2);
107 &movb( &LB($tmp1), &LB($u) );
108 &movb( &LB($tmp2), &HB($u) );
109 &rotr( $t, 4 );
110 &mov( $trans, &swtmp(1));
111 &xor( $L, &DWP(" ",$trans,$tmp1,0));
112 &movb( &LB($tmp1), &LB($t) );
113 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
114 &movb( &LB($tmp2), &HB($t) );
115 &shr( $u, 16);
116 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
117 &movb( &LB($tmp1), &HB($u) );
118 &shr( $t, 16);
119 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
120 &movb( &LB($tmp2), &HB($t) );
121 &and( $u, "0xff" );
122 &and( $t, "0xff" );
123 &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0));
124 &xor( $L, $tmp1);
125 &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0));
126 &xor( $L, $tmp1);
127 &mov( $tmp1, &DWP("0x400",$trans,$u,0));
128 &xor( $L, $tmp1);
129 &mov( $tmp1, &DWP("0x500",$trans,$t,0));
130 &xor( $L, $tmp1);
131 &mov( $trans, &wparam(1));
132 }
133
134sub n2a
135 {
136 sprintf("%d",$_[0]);
137 }
138
139# now has a side affect of rotating $a by $shift
140sub R_PERM_OP
141 {
142 local($a,$b,$tt,$shift,$mask,$last)=@_;
143
144 &rotl( $a, $shift ) if ($shift != 0);
145 &mov( $tt, $a );
146 &xor( $a, $b );
147 &and( $a, $mask );
148 if ($notlast eq $b)
149 {
150 &xor( $b, $a );
151 &xor( $tt, $a );
152 }
153 else
154 {
155 &xor( $tt, $a );
156 &xor( $b, $a );
157 }
158 &comment("");
159 }
160
161sub IP_new
162 {
163 local($l,$r,$tt,$lr)=@_;
164
165 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
166 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
167 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
168 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
169 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
170
171 if ($lr != 3)
172 {
173 if (($lr-3) < 0)
174 { &rotr($tt, 3-$lr); }
175 else { &rotl($tt, $lr-3); }
176 }
177 if ($lr != 2)
178 {
179 if (($lr-2) < 0)
180 { &rotr($r, 2-$lr); }
181 else { &rotl($r, $lr-2); }
182 }
183 }
184
185sub FP_new
186 {
187 local($l,$r,$tt,$lr)=@_;
188
189 if ($lr != 2)
190 {
191 if (($lr-2) < 0)
192 { &rotl($r, 2-$lr); }
193 else { &rotr($r, $lr-2); }
194 }
195 if ($lr != 3)
196 {
197 if (($lr-3) < 0)
198 { &rotl($l, 3-$lr); }
199 else { &rotr($l, $lr-3); }
200 }
201
202 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
203 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
204 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
205 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
206 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
207 &rotr($tt , 4);
208 }
209
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl
deleted file mode 100644
index 5b5f39cebd..0000000000
--- a/src/lib/libcrypto/des/asm/des-586.pl
+++ /dev/null
@@ -1,453 +0,0 @@
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
7$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
8push(@INC,"${dir}","${dir}../../perlasm");
9require "x86asm.pl";
10require "cbc.pl";
11require "desboth.pl";
12
13# base code is in microsft
14# op dest, source
15# format.
16#
17
18&asm_init($ARGV[0],"des-586.pl");
19
20$L="edi";
21$R="esi";
22$trans="ebp";
23$small_footprint=1 if (grep(/\-DOPENSSL_SMALL_FOOTPRINT/,@ARGV));
24# one can discuss setting this variable to 1 unconditionally, as
25# the folded loop is only 3% slower than unrolled, but >7 times smaller
26
27&public_label("DES_SPtrans");
28
29&DES_encrypt_internal();
30&DES_decrypt_internal();
31&DES_encrypt("DES_encrypt1",1);
32&DES_encrypt("DES_encrypt2",0);
33&DES_encrypt3("DES_encrypt3",1);
34&DES_encrypt3("DES_decrypt3",0);
35&cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
36&cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
37&DES_SPtrans();
38
39&asm_finish();
40
41sub DES_encrypt_internal()
42 {
43 &function_begin_B("_x86_DES_encrypt");
44
45 if ($small_footprint)
46 {
47 &lea("edx",&DWP(128,"ecx"));
48 &push("edx");
49 &push("ecx");
50 &set_label("eloop");
51 &D_ENCRYPT(0,$L,$R,0,$trans,"eax","ebx","ecx","edx",&swtmp(0));
52 &comment("");
53 &D_ENCRYPT(1,$R,$L,2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
54 &comment("");
55 &add("ecx",16);
56 &cmp("ecx",&swtmp(1));
57 &mov(&swtmp(0),"ecx");
58 &jb(&label("eloop"));
59 &add("esp",8);
60 }
61 else
62 {
63 &push("ecx");
64 for ($i=0; $i<16; $i+=2)
65 {
66 &comment("Round $i");
67 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
68 &comment("Round ".sprintf("%d",$i+1));
69 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
70 }
71 &add("esp",4);
72 }
73 &ret();
74
75 &function_end_B("_x86_DES_encrypt");
76 }
77
78sub DES_decrypt_internal()
79 {
80 &function_begin_B("_x86_DES_decrypt");
81
82 if ($small_footprint)
83 {
84 &push("ecx");
85 &lea("ecx",&DWP(128,"ecx"));
86 &push("ecx");
87 &set_label("dloop");
88 &D_ENCRYPT(0,$L,$R,-2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
89 &comment("");
90 &D_ENCRYPT(1,$R,$L,-4,$trans,"eax","ebx","ecx","edx",&swtmp(0));
91 &comment("");
92 &sub("ecx",16);
93 &cmp("ecx",&swtmp(1));
94 &mov(&swtmp(0),"ecx");
95 &ja(&label("dloop"));
96 &add("esp",8);
97 }
98 else
99 {
100 &push("ecx");
101 for ($i=15; $i>0; $i-=2)
102 {
103 &comment("Round $i");
104 &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
105 &comment("Round ".sprintf("%d",$i-1));
106 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
107 }
108 &add("esp",4);
109 }
110 &ret();
111
112 &function_end_B("_x86_DES_decrypt");
113 }
114
115sub DES_encrypt
116 {
117 local($name,$do_ip)=@_;
118
119 &function_begin_B($name);
120
121 &push("esi");
122 &push("edi");
123
124 &comment("");
125 &comment("Load the 2 words");
126
127 if ($do_ip)
128 {
129 &mov($R,&wparam(0));
130 &xor( "ecx", "ecx" );
131
132 &push("ebx");
133 &push("ebp");
134
135 &mov("eax",&DWP(0,$R,"",0));
136 &mov("ebx",&wparam(2)); # get encrypt flag
137 &mov($L,&DWP(4,$R,"",0));
138 &comment("");
139 &comment("IP");
140 &IP_new("eax",$L,$R,3);
141 }
142 else
143 {
144 &mov("eax",&wparam(0));
145 &xor( "ecx", "ecx" );
146
147 &push("ebx");
148 &push("ebp");
149
150 &mov($R,&DWP(0,"eax","",0));
151 &mov("ebx",&wparam(2)); # get encrypt flag
152 &rotl($R,3);
153 &mov($L,&DWP(4,"eax","",0));
154 &rotl($L,3);
155 }
156
157 # PIC-ification:-)
158 &call (&label("pic_point"));
159 &set_label("pic_point");
160 &blindpop($trans);
161 &lea ($trans,&DWP(&label("DES_SPtrans")."-".&label("pic_point"),$trans));
162
163 &mov( "ecx", &wparam(1) );
164
165 &cmp("ebx","0");
166 &je(&label("decrypt"));
167 &call("_x86_DES_encrypt");
168 &jmp(&label("done"));
169 &set_label("decrypt");
170 &call("_x86_DES_decrypt");
171 &set_label("done");
172
173 if ($do_ip)
174 {
175 &comment("");
176 &comment("FP");
177 &mov("edx",&wparam(0));
178 &FP_new($L,$R,"eax",3);
179
180 &mov(&DWP(0,"edx","",0),"eax");
181 &mov(&DWP(4,"edx","",0),$R);
182 }
183 else
184 {
185 &comment("");
186 &comment("Fixup");
187 &rotr($L,3); # r
188 &mov("eax",&wparam(0));
189 &rotr($R,3); # l
190 &mov(&DWP(0,"eax","",0),$L);
191 &mov(&DWP(4,"eax","",0),$R);
192 }
193
194 &pop("ebp");
195 &pop("ebx");
196 &pop("edi");
197 &pop("esi");
198 &ret();
199
200 &function_end_B($name);
201 }
202
203sub D_ENCRYPT
204 {
205 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t,$wp1)=@_;
206
207 &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0));
208 &xor( $tmp1, $tmp1);
209 &mov( $t, &DWP(&n2a(($S+1)*4),$tmp2,"",0));
210 &xor( $u, $R);
211 &xor( $tmp2, $tmp2);
212 &xor( $t, $R);
213 &and( $u, "0xfcfcfcfc" );
214 &and( $t, "0xcfcfcfcf" );
215 &movb( &LB($tmp1), &LB($u) );
216 &movb( &LB($tmp2), &HB($u) );
217 &rotr( $t, 4 );
218 &xor( $L, &DWP(" ",$trans,$tmp1,0));
219 &movb( &LB($tmp1), &LB($t) );
220 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
221 &movb( &LB($tmp2), &HB($t) );
222 &shr( $u, 16);
223 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
224 &movb( &LB($tmp1), &HB($u) );
225 &shr( $t, 16);
226 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
227 &movb( &LB($tmp2), &HB($t) );
228 &and( $u, "0xff" );
229 &and( $t, "0xff" );
230 &xor( $L, &DWP("0x600",$trans,$tmp1,0));
231 &xor( $L, &DWP("0x700",$trans,$tmp2,0));
232 &mov( $tmp2, $wp1 );
233 &xor( $L, &DWP("0x400",$trans,$u,0));
234 &xor( $L, &DWP("0x500",$trans,$t,0));
235 }
236
237sub n2a
238 {
239 sprintf("%d",$_[0]);
240 }
241
242# now has a side affect of rotating $a by $shift
243sub R_PERM_OP
244 {
245 local($a,$b,$tt,$shift,$mask,$last)=@_;
246
247 &rotl( $a, $shift ) if ($shift != 0);
248 &mov( $tt, $a );
249 &xor( $a, $b );
250 &and( $a, $mask );
251 # This can never succeed, and besides it is difficult to see what the
252 # idea was - Ben 13 Feb 99
253 if (!$last eq $b)
254 {
255 &xor( $b, $a );
256 &xor( $tt, $a );
257 }
258 else
259 {
260 &xor( $tt, $a );
261 &xor( $b, $a );
262 }
263 &comment("");
264 }
265
266sub IP_new
267 {
268 local($l,$r,$tt,$lr)=@_;
269
270 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
271 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
272 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
273 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
274 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
275
276 if ($lr != 3)
277 {
278 if (($lr-3) < 0)
279 { &rotr($tt, 3-$lr); }
280 else { &rotl($tt, $lr-3); }
281 }
282 if ($lr != 2)
283 {
284 if (($lr-2) < 0)
285 { &rotr($r, 2-$lr); }
286 else { &rotl($r, $lr-2); }
287 }
288 }
289
290sub FP_new
291 {
292 local($l,$r,$tt,$lr)=@_;
293
294 if ($lr != 2)
295 {
296 if (($lr-2) < 0)
297 { &rotl($r, 2-$lr); }
298 else { &rotr($r, $lr-2); }
299 }
300 if ($lr != 3)
301 {
302 if (($lr-3) < 0)
303 { &rotl($l, 3-$lr); }
304 else { &rotr($l, $lr-3); }
305 }
306
307 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
308 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
309 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
310 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
311 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
312 &rotr($tt , 4);
313 }
314
315sub DES_SPtrans
316 {
317 &set_label("DES_SPtrans",64);
318 &data_word(0x02080800, 0x00080000, 0x02000002, 0x02080802);
319 &data_word(0x02000000, 0x00080802, 0x00080002, 0x02000002);
320 &data_word(0x00080802, 0x02080800, 0x02080000, 0x00000802);
321 &data_word(0x02000802, 0x02000000, 0x00000000, 0x00080002);
322 &data_word(0x00080000, 0x00000002, 0x02000800, 0x00080800);
323 &data_word(0x02080802, 0x02080000, 0x00000802, 0x02000800);
324 &data_word(0x00000002, 0x00000800, 0x00080800, 0x02080002);
325 &data_word(0x00000800, 0x02000802, 0x02080002, 0x00000000);
326 &data_word(0x00000000, 0x02080802, 0x02000800, 0x00080002);
327 &data_word(0x02080800, 0x00080000, 0x00000802, 0x02000800);
328 &data_word(0x02080002, 0x00000800, 0x00080800, 0x02000002);
329 &data_word(0x00080802, 0x00000002, 0x02000002, 0x02080000);
330 &data_word(0x02080802, 0x00080800, 0x02080000, 0x02000802);
331 &data_word(0x02000000, 0x00000802, 0x00080002, 0x00000000);
332 &data_word(0x00080000, 0x02000000, 0x02000802, 0x02080800);
333 &data_word(0x00000002, 0x02080002, 0x00000800, 0x00080802);
334 # nibble 1
335 &data_word(0x40108010, 0x00000000, 0x00108000, 0x40100000);
336 &data_word(0x40000010, 0x00008010, 0x40008000, 0x00108000);
337 &data_word(0x00008000, 0x40100010, 0x00000010, 0x40008000);
338 &data_word(0x00100010, 0x40108000, 0x40100000, 0x00000010);
339 &data_word(0x00100000, 0x40008010, 0x40100010, 0x00008000);
340 &data_word(0x00108010, 0x40000000, 0x00000000, 0x00100010);
341 &data_word(0x40008010, 0x00108010, 0x40108000, 0x40000010);
342 &data_word(0x40000000, 0x00100000, 0x00008010, 0x40108010);
343 &data_word(0x00100010, 0x40108000, 0x40008000, 0x00108010);
344 &data_word(0x40108010, 0x00100010, 0x40000010, 0x00000000);
345 &data_word(0x40000000, 0x00008010, 0x00100000, 0x40100010);
346 &data_word(0x00008000, 0x40000000, 0x00108010, 0x40008010);
347 &data_word(0x40108000, 0x00008000, 0x00000000, 0x40000010);
348 &data_word(0x00000010, 0x40108010, 0x00108000, 0x40100000);
349 &data_word(0x40100010, 0x00100000, 0x00008010, 0x40008000);
350 &data_word(0x40008010, 0x00000010, 0x40100000, 0x00108000);
351 # nibble 2
352 &data_word(0x04000001, 0x04040100, 0x00000100, 0x04000101);
353 &data_word(0x00040001, 0x04000000, 0x04000101, 0x00040100);
354 &data_word(0x04000100, 0x00040000, 0x04040000, 0x00000001);
355 &data_word(0x04040101, 0x00000101, 0x00000001, 0x04040001);
356 &data_word(0x00000000, 0x00040001, 0x04040100, 0x00000100);
357 &data_word(0x00000101, 0x04040101, 0x00040000, 0x04000001);
358 &data_word(0x04040001, 0x04000100, 0x00040101, 0x04040000);
359 &data_word(0x00040100, 0x00000000, 0x04000000, 0x00040101);
360 &data_word(0x04040100, 0x00000100, 0x00000001, 0x00040000);
361 &data_word(0x00000101, 0x00040001, 0x04040000, 0x04000101);
362 &data_word(0x00000000, 0x04040100, 0x00040100, 0x04040001);
363 &data_word(0x00040001, 0x04000000, 0x04040101, 0x00000001);
364 &data_word(0x00040101, 0x04000001, 0x04000000, 0x04040101);
365 &data_word(0x00040000, 0x04000100, 0x04000101, 0x00040100);
366 &data_word(0x04000100, 0x00000000, 0x04040001, 0x00000101);
367 &data_word(0x04000001, 0x00040101, 0x00000100, 0x04040000);
368 # nibble 3
369 &data_word(0x00401008, 0x10001000, 0x00000008, 0x10401008);
370 &data_word(0x00000000, 0x10400000, 0x10001008, 0x00400008);
371 &data_word(0x10401000, 0x10000008, 0x10000000, 0x00001008);
372 &data_word(0x10000008, 0x00401008, 0x00400000, 0x10000000);
373 &data_word(0x10400008, 0x00401000, 0x00001000, 0x00000008);
374 &data_word(0x00401000, 0x10001008, 0x10400000, 0x00001000);
375 &data_word(0x00001008, 0x00000000, 0x00400008, 0x10401000);
376 &data_word(0x10001000, 0x10400008, 0x10401008, 0x00400000);
377 &data_word(0x10400008, 0x00001008, 0x00400000, 0x10000008);
378 &data_word(0x00401000, 0x10001000, 0x00000008, 0x10400000);
379 &data_word(0x10001008, 0x00000000, 0x00001000, 0x00400008);
380 &data_word(0x00000000, 0x10400008, 0x10401000, 0x00001000);
381 &data_word(0x10000000, 0x10401008, 0x00401008, 0x00400000);
382 &data_word(0x10401008, 0x00000008, 0x10001000, 0x00401008);
383 &data_word(0x00400008, 0x00401000, 0x10400000, 0x10001008);
384 &data_word(0x00001008, 0x10000000, 0x10000008, 0x10401000);
385 # nibble 4
386 &data_word(0x08000000, 0x00010000, 0x00000400, 0x08010420);
387 &data_word(0x08010020, 0x08000400, 0x00010420, 0x08010000);
388 &data_word(0x00010000, 0x00000020, 0x08000020, 0x00010400);
389 &data_word(0x08000420, 0x08010020, 0x08010400, 0x00000000);
390 &data_word(0x00010400, 0x08000000, 0x00010020, 0x00000420);
391 &data_word(0x08000400, 0x00010420, 0x00000000, 0x08000020);
392 &data_word(0x00000020, 0x08000420, 0x08010420, 0x00010020);
393 &data_word(0x08010000, 0x00000400, 0x00000420, 0x08010400);
394 &data_word(0x08010400, 0x08000420, 0x00010020, 0x08010000);
395 &data_word(0x00010000, 0x00000020, 0x08000020, 0x08000400);
396 &data_word(0x08000000, 0x00010400, 0x08010420, 0x00000000);
397 &data_word(0x00010420, 0x08000000, 0x00000400, 0x00010020);
398 &data_word(0x08000420, 0x00000400, 0x00000000, 0x08010420);
399 &data_word(0x08010020, 0x08010400, 0x00000420, 0x00010000);
400 &data_word(0x00010400, 0x08010020, 0x08000400, 0x00000420);
401 &data_word(0x00000020, 0x00010420, 0x08010000, 0x08000020);
402 # nibble 5
403 &data_word(0x80000040, 0x00200040, 0x00000000, 0x80202000);
404 &data_word(0x00200040, 0x00002000, 0x80002040, 0x00200000);
405 &data_word(0x00002040, 0x80202040, 0x00202000, 0x80000000);
406 &data_word(0x80002000, 0x80000040, 0x80200000, 0x00202040);
407 &data_word(0x00200000, 0x80002040, 0x80200040, 0x00000000);
408 &data_word(0x00002000, 0x00000040, 0x80202000, 0x80200040);
409 &data_word(0x80202040, 0x80200000, 0x80000000, 0x00002040);
410 &data_word(0x00000040, 0x00202000, 0x00202040, 0x80002000);
411 &data_word(0x00002040, 0x80000000, 0x80002000, 0x00202040);
412 &data_word(0x80202000, 0x00200040, 0x00000000, 0x80002000);
413 &data_word(0x80000000, 0x00002000, 0x80200040, 0x00200000);
414 &data_word(0x00200040, 0x80202040, 0x00202000, 0x00000040);
415 &data_word(0x80202040, 0x00202000, 0x00200000, 0x80002040);
416 &data_word(0x80000040, 0x80200000, 0x00202040, 0x00000000);
417 &data_word(0x00002000, 0x80000040, 0x80002040, 0x80202000);
418 &data_word(0x80200000, 0x00002040, 0x00000040, 0x80200040);
419 # nibble 6
420 &data_word(0x00004000, 0x00000200, 0x01000200, 0x01000004);
421 &data_word(0x01004204, 0x00004004, 0x00004200, 0x00000000);
422 &data_word(0x01000000, 0x01000204, 0x00000204, 0x01004000);
423 &data_word(0x00000004, 0x01004200, 0x01004000, 0x00000204);
424 &data_word(0x01000204, 0x00004000, 0x00004004, 0x01004204);
425 &data_word(0x00000000, 0x01000200, 0x01000004, 0x00004200);
426 &data_word(0x01004004, 0x00004204, 0x01004200, 0x00000004);
427 &data_word(0x00004204, 0x01004004, 0x00000200, 0x01000000);
428 &data_word(0x00004204, 0x01004000, 0x01004004, 0x00000204);
429 &data_word(0x00004000, 0x00000200, 0x01000000, 0x01004004);
430 &data_word(0x01000204, 0x00004204, 0x00004200, 0x00000000);
431 &data_word(0x00000200, 0x01000004, 0x00000004, 0x01000200);
432 &data_word(0x00000000, 0x01000204, 0x01000200, 0x00004200);
433 &data_word(0x00000204, 0x00004000, 0x01004204, 0x01000000);
434 &data_word(0x01004200, 0x00000004, 0x00004004, 0x01004204);
435 &data_word(0x01000004, 0x01004200, 0x01004000, 0x00004004);
436 # nibble 7
437 &data_word(0x20800080, 0x20820000, 0x00020080, 0x00000000);
438 &data_word(0x20020000, 0x00800080, 0x20800000, 0x20820080);
439 &data_word(0x00000080, 0x20000000, 0x00820000, 0x00020080);
440 &data_word(0x00820080, 0x20020080, 0x20000080, 0x20800000);
441 &data_word(0x00020000, 0x00820080, 0x00800080, 0x20020000);
442 &data_word(0x20820080, 0x20000080, 0x00000000, 0x00820000);
443 &data_word(0x20000000, 0x00800000, 0x20020080, 0x20800080);
444 &data_word(0x00800000, 0x00020000, 0x20820000, 0x00000080);
445 &data_word(0x00800000, 0x00020000, 0x20000080, 0x20820080);
446 &data_word(0x00020080, 0x20000000, 0x00000000, 0x00820000);
447 &data_word(0x20800080, 0x20020080, 0x20020000, 0x00800080);
448 &data_word(0x20820000, 0x00000080, 0x00800080, 0x20020000);
449 &data_word(0x20820080, 0x00800000, 0x20800000, 0x20000080);
450 &data_word(0x00820000, 0x00020080, 0x20020080, 0x20800000);
451 &data_word(0x00000080, 0x20820000, 0x00820080, 0x00000000);
452 &data_word(0x20000000, 0x20800080, 0x00020000, 0x00820080);
453 }
diff --git a/src/lib/libcrypto/des/asm/des_enc.m4 b/src/lib/libcrypto/des/asm/des_enc.m4
deleted file mode 100644
index 3280595478..0000000000
--- a/src/lib/libcrypto/des/asm/des_enc.m4
+++ /dev/null
@@ -1,2099 +0,0 @@
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.file "des_enc-sparc.S"
48
49#if defined(__SUNPRO_C) && defined(__sparcv9)
50# define ABI64 /* They've said -xarch=v9 at command line */
51#elif defined(__GNUC__) && defined(__arch64__)
52# define ABI64 /* They've said -m64 at command line */
53#endif
54
55#ifdef ABI64
56 .register %g2,#scratch
57 .register %g3,#scratch
58# define FRAME -192
59# define BIAS 2047
60# define LDPTR ldx
61# define STPTR stx
62# define ARG0 128
63# define ARGSZ 8
64# ifndef OPENSSL_SYSNAME_ULTRASPARC
65# define OPENSSL_SYSNAME_ULTRASPARC
66# endif
67#else
68# define FRAME -96
69# define BIAS 0
70# define LDPTR ld
71# define STPTR st
72# define ARG0 68
73# define ARGSZ 4
74#endif
75
76#define LOOPS 7
77
78#define global0 %g0
79#define global1 %g1
80#define global2 %g2
81#define global3 %g3
82#define global4 %g4
83#define global5 %g5
84
85#define local0 %l0
86#define local1 %l1
87#define local2 %l2
88#define local3 %l3
89#define local4 %l4
90#define local5 %l5
91#define local7 %l6
92#define local6 %l7
93
94#define in0 %i0
95#define in1 %i1
96#define in2 %i2
97#define in3 %i3
98#define in4 %i4
99#define in5 %i5
100#define in6 %i6
101#define in7 %i7
102
103#define out0 %o0
104#define out1 %o1
105#define out2 %o2
106#define out3 %o3
107#define out4 %o4
108#define out5 %o5
109#define out6 %o6
110#define out7 %o7
111
112#define stub stb
113
114changequote({,})
115
116
117! Macro definitions:
118
119
120! {ip_macro}
121!
122! The logic used in initial and final permutations is the same as in
123! the C code. The permutations are done with a clever shift, xor, and
124! technique.
125!
126! The macro also loads address sbox 1 to 5 to global 1 to 5, address
127! sbox 6 to local6, and addres sbox 8 to out3.
128!
129! Rotates the halfs 3 left to bring the sbox bits in convenient positions.
130!
131! Loads key first round from address in parameter 5 to out0, out1.
132!
133! After the the original LibDES initial permutation, the resulting left
134! is in the variable initially used for right and vice versa. The macro
135! implements the possibility to keep the halfs in the original registers.
136!
137! parameter 1 left
138! parameter 2 right
139! parameter 3 result left (modify in first round)
140! parameter 4 result right (use in first round)
141! parameter 5 key address
142! parameter 6 1/2 for include encryption/decryption
143! parameter 7 1 for move in1 to in3
144! parameter 8 1 for move in3 to in4, 2 for move in4 to in3
145! parameter 9 1 for load ks3 and ks2 to in4 and in3
146
147define(ip_macro, {
148
149! {ip_macro}
150! $1 $2 $4 $3 $5 $6 $7 $8 $9
151
152 ld [out2+256], local1
153 srl $2, 4, local4
154
155 xor local4, $1, local4
156 ifelse($7,1,{mov in1, in3},{nop})
157
158 ld [out2+260], local2
159 and local4, local1, local4
160 ifelse($8,1,{mov in3, in4},{})
161 ifelse($8,2,{mov in4, in3},{})
162
163 ld [out2+280], out4 ! loop counter
164 sll local4, 4, local1
165 xor $1, local4, $1
166
167 ld [out2+264], local3
168 srl $1, 16, local4
169 xor $2, local1, $2
170
171 ifelse($9,1,{LDPTR KS3, in4},{})
172 xor local4, $2, local4
173 nop !sethi %hi(DES_SPtrans), global1 ! sbox addr
174
175 ifelse($9,1,{LDPTR KS2, in3},{})
176 and local4, local2, local4
177 nop !or global1, %lo(DES_SPtrans), global1 ! sbox addr
178
179 sll local4, 16, local1
180 xor $2, local4, $2
181
182 srl $2, 2, local4
183 xor $1, local1, $1
184
185 sethi %hi(16711680), local5
186 xor local4, $1, local4
187
188 and local4, local3, local4
189 or local5, 255, local5
190
191 sll local4, 2, local2
192 xor $1, local4, $1
193
194 srl $1, 8, local4
195 xor $2, local2, $2
196
197 xor local4, $2, local4
198 add global1, 768, global4
199
200 and local4, local5, local4
201 add global1, 1024, global5
202
203 ld [out2+272], local7
204 sll local4, 8, local1
205 xor $2, local4, $2
206
207 srl $2, 1, local4
208 xor $1, local1, $1
209
210 ld [$5], out0 ! key 7531
211 xor local4, $1, local4
212 add global1, 256, global2
213
214 ld [$5+4], out1 ! key 8642
215 and local4, local7, local4
216 add global1, 512, global3
217
218 sll local4, 1, local1
219 xor $1, local4, $1
220
221 sll $1, 3, local3
222 xor $2, local1, $2
223
224 sll $2, 3, local2
225 add global1, 1280, local6 ! address sbox 8
226
227 srl $1, 29, local4
228 add global1, 1792, out3 ! address sbox 8
229
230 srl $2, 29, local1
231 or local4, local3, $4
232
233 or local2, local1, $3
234
235 ifelse($6, 1, {
236
237 ld [out2+284], local5 ! 0x0000FC00 used in the rounds
238 or local2, local1, $3
239 xor $4, out0, local1
240
241 call .des_enc.1
242 and local1, 252, local1
243
244 },{})
245
246 ifelse($6, 2, {
247
248 ld [out2+284], local5 ! 0x0000FC00 used in the rounds
249 or local2, local1, $3
250 xor $4, out0, local1
251
252 call .des_dec.1
253 and local1, 252, local1
254
255 },{})
256})
257
258
259! {rounds_macro}
260!
261! The logic used in the DES rounds is the same as in the C code,
262! except that calculations for sbox 1 and sbox 5 begin before
263! the previous round is finished.
264!
265! In each round one half (work) is modified based on key and the
266! other half (use).
267!
268! In this version we do two rounds in a loop repeated 7 times
269! and two rounds seperately.
270!
271! One half has the bits for the sboxes in the following positions:
272!
273! 777777xx555555xx333333xx111111xx
274!
275! 88xx666666xx444444xx222222xx8888
276!
277! The bits for each sbox are xor-ed with the key bits for that box.
278! The above xx bits are cleared, and the result used for lookup in
279! the sbox table. Each sbox entry contains the 4 output bits permuted
280! into 32 bits according to the P permutation.
281!
282! In the description of DES, left and right are switched after
283! each round, except after last round. In this code the original
284! left and right are kept in the same register in all rounds, meaning
285! that after the 16 rounds the result for right is in the register
286! originally used for left.
287!
288! parameter 1 first work (left in first round)
289! parameter 2 first use (right in first round)
290! parameter 3 enc/dec 1/-1
291! parameter 4 loop label
292! parameter 5 key address register
293! parameter 6 optional address for key next encryption/decryption
294! parameter 7 not empty for include retl
295!
296! also compares in2 to 8
297
298define(rounds_macro, {
299
300! {rounds_macro}
301! $1 $2 $3 $4 $5 $6 $7 $8 $9
302
303 xor $2, out0, local1
304
305 ld [out2+284], local5 ! 0x0000FC00
306 ba $4
307 and local1, 252, local1
308
309 .align 32
310
311$4:
312 ! local6 is address sbox 6
313 ! out3 is address sbox 8
314 ! out4 is loop counter
315
316 ld [global1+local1], local1
317 xor $2, out1, out1 ! 8642
318 xor $2, out0, out0 ! 7531
319 ! fmovs %f0, %f0 ! fxor used for alignment
320
321 srl out1, 4, local0 ! rotate 4 right
322 and out0, local5, local3 ! 3
323 ! fmovs %f0, %f0
324
325 ld [$5+$3*8], local7 ! key 7531 next round
326 srl local3, 8, local3 ! 3
327 and local0, 252, local2 ! 2
328 ! fmovs %f0, %f0
329
330 ld [global3+local3],local3 ! 3
331 sll out1, 28, out1 ! rotate
332 xor $1, local1, $1 ! 1 finished, local1 now sbox 7
333
334 ld [global2+local2], local2 ! 2
335 srl out0, 24, local1 ! 7
336 or out1, local0, out1 ! rotate
337
338 ldub [out2+local1], local1 ! 7 (and 0xFC)
339 srl out1, 24, local0 ! 8
340 and out1, local5, local4 ! 4
341
342 ldub [out2+local0], local0 ! 8 (and 0xFC)
343 srl local4, 8, local4 ! 4
344 xor $1, local2, $1 ! 2 finished local2 now sbox 6
345
346 ld [global4+local4],local4 ! 4
347 srl out1, 16, local2 ! 6
348 xor $1, local3, $1 ! 3 finished local3 now sbox 5
349
350 ld [out3+local0],local0 ! 8
351 and local2, 252, local2 ! 6
352 add global1, 1536, local5 ! address sbox 7
353
354 ld [local6+local2], local2 ! 6
355 srl out0, 16, local3 ! 5
356 xor $1, local4, $1 ! 4 finished
357
358 ld [local5+local1],local1 ! 7
359 and local3, 252, local3 ! 5
360 xor $1, local0, $1 ! 8 finished
361
362 ld [global5+local3],local3 ! 5
363 xor $1, local2, $1 ! 6 finished
364 subcc out4, 1, out4
365
366 ld [$5+$3*8+4], out0 ! key 8642 next round
367 xor $1, local7, local2 ! sbox 5 next round
368 xor $1, local1, $1 ! 7 finished
369
370 srl local2, 16, local2 ! sbox 5 next round
371 xor $1, local3, $1 ! 5 finished
372
373 ld [$5+$3*16+4], out1 ! key 8642 next round again
374 and local2, 252, local2 ! sbox5 next round
375! next round
376 xor $1, local7, local7 ! 7531
377
378 ld [global5+local2], local2 ! 5
379 srl local7, 24, local3 ! 7
380 xor $1, out0, out0 ! 8642
381
382 ldub [out2+local3], local3 ! 7 (and 0xFC)
383 srl out0, 4, local0 ! rotate 4 right
384 and local7, 252, local1 ! 1
385
386 sll out0, 28, out0 ! rotate
387 xor $2, local2, $2 ! 5 finished local2 used
388
389 srl local0, 8, local4 ! 4
390 and local0, 252, local2 ! 2
391 ld [local5+local3], local3 ! 7
392
393 srl local0, 16, local5 ! 6
394 or out0, local0, out0 ! rotate
395 ld [global2+local2], local2 ! 2
396
397 srl out0, 24, local0
398 ld [$5+$3*16], out0 ! key 7531 next round
399 and local4, 252, local4 ! 4
400
401 and local5, 252, local5 ! 6
402 ld [global4+local4], local4 ! 4
403 xor $2, local3, $2 ! 7 finished local3 used
404
405 and local0, 252, local0 ! 8
406 ld [local6+local5], local5 ! 6
407 xor $2, local2, $2 ! 2 finished local2 now sbox 3
408
409 srl local7, 8, local2 ! 3 start
410 ld [out3+local0], local0 ! 8
411 xor $2, local4, $2 ! 4 finished
412
413 and local2, 252, local2 ! 3
414 ld [global1+local1], local1 ! 1
415 xor $2, local5, $2 ! 6 finished local5 used
416
417 ld [global3+local2], local2 ! 3
418 xor $2, local0, $2 ! 8 finished
419 add $5, $3*16, $5 ! enc add 8, dec add -8 to key pointer
420
421 ld [out2+284], local5 ! 0x0000FC00
422 xor $2, out0, local4 ! sbox 1 next round
423 xor $2, local1, $2 ! 1 finished
424
425 xor $2, local2, $2 ! 3 finished
426#ifdef OPENSSL_SYSNAME_ULTRASPARC
427 bne,pt %icc, $4
428#else
429 bne $4
430#endif
431 and local4, 252, local1 ! sbox 1 next round
432
433! two rounds more:
434
435 ld [global1+local1], local1
436 xor $2, out1, out1
437 xor $2, out0, out0
438
439 srl out1, 4, local0 ! rotate
440 and out0, local5, local3
441
442 ld [$5+$3*8], local7 ! key 7531
443 srl local3, 8, local3
444 and local0, 252, local2
445
446 ld [global3+local3],local3
447 sll out1, 28, out1 ! rotate
448 xor $1, local1, $1 ! 1 finished, local1 now sbox 7
449
450 ld [global2+local2], local2
451 srl out0, 24, local1
452 or out1, local0, out1 ! rotate
453
454 ldub [out2+local1], local1
455 srl out1, 24, local0
456 and out1, local5, local4
457
458 ldub [out2+local0], local0
459 srl local4, 8, local4
460 xor $1, local2, $1 ! 2 finished local2 now sbox 6
461
462 ld [global4+local4],local4
463 srl out1, 16, local2
464 xor $1, local3, $1 ! 3 finished local3 now sbox 5
465
466 ld [out3+local0],local0
467 and local2, 252, local2
468 add global1, 1536, local5 ! address sbox 7
469
470 ld [local6+local2], local2
471 srl out0, 16, local3
472 xor $1, local4, $1 ! 4 finished
473
474 ld [local5+local1],local1
475 and local3, 252, local3
476 xor $1, local0, $1
477
478 ld [global5+local3],local3
479 xor $1, local2, $1 ! 6 finished
480 cmp in2, 8
481
482 ifelse($6,{}, {}, {ld [out2+280], out4}) ! loop counter
483 xor $1, local7, local2 ! sbox 5 next round
484 xor $1, local1, $1 ! 7 finished
485
486 ld [$5+$3*8+4], out0
487 srl local2, 16, local2 ! sbox 5 next round
488 xor $1, local3, $1 ! 5 finished
489
490 and local2, 252, local2
491! next round (two rounds more)
492 xor $1, local7, local7 ! 7531
493
494 ld [global5+local2], local2
495 srl local7, 24, local3
496 xor $1, out0, out0 ! 8642
497
498 ldub [out2+local3], local3
499 srl out0, 4, local0 ! rotate
500 and local7, 252, local1
501
502 sll out0, 28, out0 ! rotate
503 xor $2, local2, $2 ! 5 finished local2 used
504
505 srl local0, 8, local4
506 and local0, 252, local2
507 ld [local5+local3], local3
508
509 srl local0, 16, local5
510 or out0, local0, out0 ! rotate
511 ld [global2+local2], local2
512
513 srl out0, 24, local0
514 ifelse($6,{}, {}, {ld [$6], out0}) ! key next encryption/decryption
515 and local4, 252, local4
516
517 and local5, 252, local5
518 ld [global4+local4], local4
519 xor $2, local3, $2 ! 7 finished local3 used
520
521 and local0, 252, local0
522 ld [local6+local5], local5
523 xor $2, local2, $2 ! 2 finished local2 now sbox 3
524
525 srl local7, 8, local2 ! 3 start
526 ld [out3+local0], local0
527 xor $2, local4, $2
528
529 and local2, 252, local2
530 ld [global1+local1], local1
531 xor $2, local5, $2 ! 6 finished local5 used
532
533 ld [global3+local2], local2
534 srl $1, 3, local3
535 xor $2, local0, $2
536
537 ifelse($6,{}, {}, {ld [$6+4], out1}) ! key next encryption/decryption
538 sll $1, 29, local4
539 xor $2, local1, $2
540
541 ifelse($7,{}, {}, {retl})
542 xor $2, local2, $2
543})
544
545
546! {fp_macro}
547!
548! parameter 1 right (original left)
549! parameter 2 left (original right)
550! parameter 3 1 for optional store to [in0]
551! parameter 4 1 for load input/output address to local5/7
552!
553! The final permutation logic switches the halfes, meaning that
554! left and right ends up the the registers originally used.
555
556define(fp_macro, {
557
558! {fp_macro}
559! $1 $2 $3 $4 $5 $6 $7 $8 $9
560
561 ! initially undo the rotate 3 left done after initial permutation
562 ! original left is received shifted 3 right and 29 left in local3/4
563
564 sll $2, 29, local1
565 or local3, local4, $1
566
567 srl $2, 3, $2
568 sethi %hi(0x55555555), local2
569
570 or $2, local1, $2
571 or local2, %lo(0x55555555), local2
572
573 srl $2, 1, local3
574 sethi %hi(0x00ff00ff), local1
575 xor local3, $1, local3
576 or local1, %lo(0x00ff00ff), local1
577 and local3, local2, local3
578 sethi %hi(0x33333333), local4
579 sll local3, 1, local2
580
581 xor $1, local3, $1
582
583 srl $1, 8, local3
584 xor $2, local2, $2
585 xor local3, $2, local3
586 or local4, %lo(0x33333333), local4
587 and local3, local1, local3
588 sethi %hi(0x0000ffff), local1
589 sll local3, 8, local2
590
591 xor $2, local3, $2
592
593 srl $2, 2, local3
594 xor $1, local2, $1
595 xor local3, $1, local3
596 or local1, %lo(0x0000ffff), local1
597 and local3, local4, local3
598 sethi %hi(0x0f0f0f0f), local4
599 sll local3, 2, local2
600
601 ifelse($4,1, {LDPTR INPUT, local5})
602 xor $1, local3, $1
603
604 ifelse($4,1, {LDPTR OUTPUT, local7})
605 srl $1, 16, local3
606 xor $2, local2, $2
607 xor local3, $2, local3
608 or local4, %lo(0x0f0f0f0f), local4
609 and local3, local1, local3
610 sll local3, 16, local2
611
612 xor $2, local3, local1
613
614 srl local1, 4, local3
615 xor $1, local2, $1
616 xor local3, $1, local3
617 and local3, local4, local3
618 sll local3, 4, local2
619
620 xor $1, local3, $1
621
622 ! optional store:
623
624 ifelse($3,1, {st $1, [in0]})
625
626 xor local1, local2, $2
627
628 ifelse($3,1, {st $2, [in0+4]})
629
630})
631
632
633! {fp_ip_macro}
634!
635! Does initial permutation for next block mixed with
636! final permutation for current block.
637!
638! parameter 1 original left
639! parameter 2 original right
640! parameter 3 left ip
641! parameter 4 right ip
642! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4
643! 2: mov in4 to in3
644!
645! also adds -8 to length in2 and loads loop counter to out4
646
647define(fp_ip_macro, {
648
649! {fp_ip_macro}
650! $1 $2 $3 $4 $5 $6 $7 $8 $9
651
652 define({temp1},{out4})
653 define({temp2},{local3})
654
655 define({ip1},{local1})
656 define({ip2},{local2})
657 define({ip4},{local4})
658 define({ip5},{local5})
659
660 ! $1 in local3, local4
661
662 ld [out2+256], ip1
663 sll out5, 29, temp1
664 or local3, local4, $1
665
666 srl out5, 3, $2
667 ifelse($5,2,{mov in4, in3})
668
669 ld [out2+272], ip5
670 srl $4, 4, local0
671 or $2, temp1, $2
672
673 srl $2, 1, temp1
674 xor temp1, $1, temp1
675
676 and temp1, ip5, temp1
677 xor local0, $3, local0
678
679 sll temp1, 1, temp2
680 xor $1, temp1, $1
681
682 and local0, ip1, local0
683 add in2, -8, in2
684
685 sll local0, 4, local7
686 xor $3, local0, $3
687
688 ld [out2+268], ip4
689 srl $1, 8, temp1
690 xor $2, temp2, $2
691 ld [out2+260], ip2
692 srl $3, 16, local0
693 xor $4, local7, $4
694 xor temp1, $2, temp1
695 xor local0, $4, local0
696 and temp1, ip4, temp1
697 and local0, ip2, local0
698 sll temp1, 8, temp2
699 xor $2, temp1, $2
700 sll local0, 16, local7
701 xor $4, local0, $4
702
703 srl $2, 2, temp1
704 xor $1, temp2, $1
705
706 ld [out2+264], temp2 ! ip3
707 srl $4, 2, local0
708 xor $3, local7, $3
709 xor temp1, $1, temp1
710 xor local0, $3, local0
711 and temp1, temp2, temp1
712 and local0, temp2, local0
713 sll temp1, 2, temp2
714 xor $1, temp1, $1
715 sll local0, 2, local7
716 xor $3, local0, $3
717
718 srl $1, 16, temp1
719 xor $2, temp2, $2
720 srl $3, 8, local0
721 xor $4, local7, $4
722 xor temp1, $2, temp1
723 xor local0, $4, local0
724 and temp1, ip2, temp1
725 and local0, ip4, local0
726 sll temp1, 16, temp2
727 xor $2, temp1, local4
728 sll local0, 8, local7
729 xor $4, local0, $4
730
731 srl $4, 1, local0
732 xor $3, local7, $3
733
734 srl local4, 4, temp1
735 xor local0, $3, local0
736
737 xor $1, temp2, $1
738 and local0, ip5, local0
739
740 sll local0, 1, local7
741 xor temp1, $1, temp1
742
743 xor $3, local0, $3
744 xor $4, local7, $4
745
746 sll $3, 3, local5
747 and temp1, ip1, temp1
748
749 sll temp1, 4, temp2
750 xor $1, temp1, $1
751
752 ifelse($5,1,{LDPTR KS2, in4})
753 sll $4, 3, local2
754 xor local4, temp2, $2
755
756 ! reload since used as temporar:
757
758 ld [out2+280], out4 ! loop counter
759
760 srl $3, 29, local0
761 ifelse($5,1,{add in4, 120, in4})
762
763 ifelse($5,1,{LDPTR KS1, in3})
764 srl $4, 29, local7
765
766 or local0, local5, $4
767 or local2, local7, $3
768
769})
770
771
772
773! {load_little_endian}
774!
775! parameter 1 address
776! parameter 2 destination left
777! parameter 3 destination right
778! parameter 4 temporar
779! parameter 5 label
780
781define(load_little_endian, {
782
783! {load_little_endian}
784! $1 $2 $3 $4 $5 $6 $7 $8 $9
785
786 ! first in memory to rightmost in register
787
788#ifdef OPENSSL_SYSNAME_ULTRASPARC
789 andcc $1, 3, global0
790 bne,pn %icc, $5
791 nop
792
793 lda [$1] 0x88, $2
794 add $1, 4, $4
795
796 ba,pt %icc, $5a
797 lda [$4] 0x88, $3
798#endif
799
800$5:
801 ldub [$1+3], $2
802
803 ldub [$1+2], $4
804 sll $2, 8, $2
805 or $2, $4, $2
806
807 ldub [$1+1], $4
808 sll $2, 8, $2
809 or $2, $4, $2
810
811 ldub [$1+0], $4
812 sll $2, 8, $2
813 or $2, $4, $2
814
815
816 ldub [$1+3+4], $3
817
818 ldub [$1+2+4], $4
819 sll $3, 8, $3
820 or $3, $4, $3
821
822 ldub [$1+1+4], $4
823 sll $3, 8, $3
824 or $3, $4, $3
825
826 ldub [$1+0+4], $4
827 sll $3, 8, $3
828 or $3, $4, $3
829$5a:
830
831})
832
833
834! {load_little_endian_inc}
835!
836! parameter 1 address
837! parameter 2 destination left
838! parameter 3 destination right
839! parameter 4 temporar
840! parameter 4 label
841!
842! adds 8 to address
843
844define(load_little_endian_inc, {
845
846! {load_little_endian_inc}
847! $1 $2 $3 $4 $5 $6 $7 $8 $9
848
849 ! first in memory to rightmost in register
850
851#ifdef OPENSSL_SYSNAME_ULTRASPARC
852 andcc $1, 3, global0
853 bne,pn %icc, $5
854 nop
855
856 lda [$1] 0x88, $2
857 add $1, 4, $1
858
859 lda [$1] 0x88, $3
860 ba,pt %icc, $5a
861 add $1, 4, $1
862#endif
863
864$5:
865 ldub [$1+3], $2
866
867 ldub [$1+2], $4
868 sll $2, 8, $2
869 or $2, $4, $2
870
871 ldub [$1+1], $4
872 sll $2, 8, $2
873 or $2, $4, $2
874
875 ldub [$1+0], $4
876 sll $2, 8, $2
877 or $2, $4, $2
878
879 ldub [$1+3+4], $3
880 add $1, 8, $1
881
882 ldub [$1+2+4-8], $4
883 sll $3, 8, $3
884 or $3, $4, $3
885
886 ldub [$1+1+4-8], $4
887 sll $3, 8, $3
888 or $3, $4, $3
889
890 ldub [$1+0+4-8], $4
891 sll $3, 8, $3
892 or $3, $4, $3
893$5a:
894
895})
896
897
898! {load_n_bytes}
899!
900! Loads 1 to 7 bytes little endian
901! Remaining bytes are zeroed.
902!
903! parameter 1 address
904! parameter 2 length
905! parameter 3 destination register left
906! parameter 4 destination register right
907! parameter 5 temp
908! parameter 6 temp2
909! parameter 7 label
910! parameter 8 return label
911
912define(load_n_bytes, {
913
914! {load_n_bytes}
915! $1 $2 $5 $6 $7 $8 $7 $8 $9
916
917$7.0: call .+8
918 sll $2, 2, $6
919
920 add %o7,$7.jmp.table-$7.0,$5
921
922 add $5, $6, $5
923 mov 0, $4
924
925 ld [$5], $5
926
927 jmp %o7+$5
928 mov 0, $3
929
930$7.7:
931 ldub [$1+6], $5
932 sll $5, 16, $5
933 or $3, $5, $3
934$7.6:
935 ldub [$1+5], $5
936 sll $5, 8, $5
937 or $3, $5, $3
938$7.5:
939 ldub [$1+4], $5
940 or $3, $5, $3
941$7.4:
942 ldub [$1+3], $5
943 sll $5, 24, $5
944 or $4, $5, $4
945$7.3:
946 ldub [$1+2], $5
947 sll $5, 16, $5
948 or $4, $5, $4
949$7.2:
950 ldub [$1+1], $5
951 sll $5, 8, $5
952 or $4, $5, $4
953$7.1:
954 ldub [$1+0], $5
955 ba $8
956 or $4, $5, $4
957
958 .align 4
959
960$7.jmp.table:
961 .word 0
962 .word $7.1-$7.0
963 .word $7.2-$7.0
964 .word $7.3-$7.0
965 .word $7.4-$7.0
966 .word $7.5-$7.0
967 .word $7.6-$7.0
968 .word $7.7-$7.0
969})
970
971
972! {store_little_endian}
973!
974! parameter 1 address
975! parameter 2 source left
976! parameter 3 source right
977! parameter 4 temporar
978
979define(store_little_endian, {
980
981! {store_little_endian}
982! $1 $2 $3 $4 $5 $6 $7 $8 $9
983
984 ! rightmost in register to first in memory
985
986#ifdef OPENSSL_SYSNAME_ULTRASPARC
987 andcc $1, 3, global0
988 bne,pn %icc, $5
989 nop
990
991 sta $2, [$1] 0x88
992 add $1, 4, $4
993
994 ba,pt %icc, $5a
995 sta $3, [$4] 0x88
996#endif
997
998$5:
999 and $2, 255, $4
1000 stub $4, [$1+0]
1001
1002 srl $2, 8, $4
1003 and $4, 255, $4
1004 stub $4, [$1+1]
1005
1006 srl $2, 16, $4
1007 and $4, 255, $4
1008 stub $4, [$1+2]
1009
1010 srl $2, 24, $4
1011 stub $4, [$1+3]
1012
1013
1014 and $3, 255, $4
1015 stub $4, [$1+0+4]
1016
1017 srl $3, 8, $4
1018 and $4, 255, $4
1019 stub $4, [$1+1+4]
1020
1021 srl $3, 16, $4
1022 and $4, 255, $4
1023 stub $4, [$1+2+4]
1024
1025 srl $3, 24, $4
1026 stub $4, [$1+3+4]
1027
1028$5a:
1029
1030})
1031
1032
1033! {store_n_bytes}
1034!
1035! Stores 1 to 7 bytes little endian
1036!
1037! parameter 1 address
1038! parameter 2 length
1039! parameter 3 source register left
1040! parameter 4 source register right
1041! parameter 5 temp
1042! parameter 6 temp2
1043! parameter 7 label
1044! parameter 8 return label
1045
1046define(store_n_bytes, {
1047
1048! {store_n_bytes}
1049! $1 $2 $5 $6 $7 $8 $7 $8 $9
1050
1051$7.0: call .+8
1052 sll $2, 2, $6
1053
1054 add %o7,$7.jmp.table-$7.0,$5
1055
1056 add $5, $6, $5
1057
1058 ld [$5], $5
1059
1060 jmp %o7+$5
1061 nop
1062
1063$7.7:
1064 srl $3, 16, $5
1065 and $5, 0xff, $5
1066 stub $5, [$1+6]
1067$7.6:
1068 srl $3, 8, $5
1069 and $5, 0xff, $5
1070 stub $5, [$1+5]
1071$7.5:
1072 and $3, 0xff, $5
1073 stub $5, [$1+4]
1074$7.4:
1075 srl $4, 24, $5
1076 stub $5, [$1+3]
1077$7.3:
1078 srl $4, 16, $5
1079 and $5, 0xff, $5
1080 stub $5, [$1+2]
1081$7.2:
1082 srl $4, 8, $5
1083 and $5, 0xff, $5
1084 stub $5, [$1+1]
1085$7.1:
1086 and $4, 0xff, $5
1087
1088
1089 ba $8
1090 stub $5, [$1]
1091
1092 .align 4
1093
1094$7.jmp.table:
1095
1096 .word 0
1097 .word $7.1-$7.0
1098 .word $7.2-$7.0
1099 .word $7.3-$7.0
1100 .word $7.4-$7.0
1101 .word $7.5-$7.0
1102 .word $7.6-$7.0
1103 .word $7.7-$7.0
1104})
1105
1106
1107define(testvalue,{1})
1108
1109define(register_init, {
1110
1111! For test purposes:
1112
1113 sethi %hi(testvalue), local0
1114 or local0, %lo(testvalue), local0
1115
1116 ifelse($1,{},{}, {mov local0, $1})
1117 ifelse($2,{},{}, {mov local0, $2})
1118 ifelse($3,{},{}, {mov local0, $3})
1119 ifelse($4,{},{}, {mov local0, $4})
1120 ifelse($5,{},{}, {mov local0, $5})
1121 ifelse($6,{},{}, {mov local0, $6})
1122 ifelse($7,{},{}, {mov local0, $7})
1123 ifelse($8,{},{}, {mov local0, $8})
1124
1125 mov local0, local1
1126 mov local0, local2
1127 mov local0, local3
1128 mov local0, local4
1129 mov local0, local5
1130 mov local0, local7
1131 mov local0, local6
1132 mov local0, out0
1133 mov local0, out1
1134 mov local0, out2
1135 mov local0, out3
1136 mov local0, out4
1137 mov local0, out5
1138 mov local0, global1
1139 mov local0, global2
1140 mov local0, global3
1141 mov local0, global4
1142 mov local0, global5
1143
1144})
1145
1146.section ".text"
1147
1148 .align 32
1149
1150.des_enc:
1151
1152 ! key address in3
1153 ! loads key next encryption/decryption first round from [in4]
1154
1155 rounds_macro(in5, out5, 1, .des_enc.1, in3, in4, retl)
1156
1157
1158 .align 32
1159
1160.des_dec:
1161
1162 ! implemented with out5 as first parameter to avoid
1163 ! register exchange in ede modes
1164
1165 ! key address in4
1166 ! loads key next encryption/decryption first round from [in3]
1167
1168 rounds_macro(out5, in5, -1, .des_dec.1, in4, in3, retl)
1169
1170
1171
1172! void DES_encrypt1(data, ks, enc)
1173! *******************************
1174
1175 .align 32
1176 .global DES_encrypt1
1177 .type DES_encrypt1,#function
1178
1179DES_encrypt1:
1180
1181 save %sp, FRAME, %sp
1182
1183 sethi %hi(.PIC.DES_SPtrans-1f),global1
1184 or global1,%lo(.PIC.DES_SPtrans-1f),global1
11851: call .+8
1186 add %o7,global1,global1
1187 sub global1,.PIC.DES_SPtrans-.des_and,out2
1188
1189 ld [in0], in5 ! left
1190 cmp in2, 0 ! enc
1191
1192#ifdef OPENSSL_SYSNAME_ULTRASPARC
1193 be,pn %icc, .encrypt.dec ! enc/dec
1194#else
1195 be .encrypt.dec
1196#endif
1197 ld [in0+4], out5 ! right
1198
1199 ! parameter 6 1/2 for include encryption/decryption
1200 ! parameter 7 1 for move in1 to in3
1201 ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3
1202
1203 ip_macro(in5, out5, in5, out5, in3, 0, 1, 1)
1204
1205 rounds_macro(in5, out5, 1, .des_encrypt1.1, in3, in4) ! in4 not used
1206
1207 fp_macro(in5, out5, 1) ! 1 for store to [in0]
1208
1209 ret
1210 restore
1211
1212.encrypt.dec:
1213
1214 add in1, 120, in3 ! use last subkey for first round
1215
1216 ! parameter 6 1/2 for include encryption/decryption
1217 ! parameter 7 1 for move in1 to in3
1218 ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3
1219
1220 ip_macro(in5, out5, out5, in5, in4, 2, 0, 1) ! include dec, ks in4
1221
1222 fp_macro(out5, in5, 1) ! 1 for store to [in0]
1223
1224 ret
1225 restore
1226
1227.DES_encrypt1.end:
1228 .size DES_encrypt1,.DES_encrypt1.end-DES_encrypt1
1229
1230
1231! void DES_encrypt2(data, ks, enc)
1232!*********************************
1233
1234 ! encrypts/decrypts without initial/final permutation
1235
1236 .align 32
1237 .global DES_encrypt2
1238 .type DES_encrypt2,#function
1239
1240DES_encrypt2:
1241
1242 save %sp, FRAME, %sp
1243
1244 sethi %hi(.PIC.DES_SPtrans-1f),global1
1245 or global1,%lo(.PIC.DES_SPtrans-1f),global1
12461: call .+8
1247 add %o7,global1,global1
1248 sub global1,.PIC.DES_SPtrans-.des_and,out2
1249
1250 ! Set sbox address 1 to 6 and rotate halfs 3 left
1251 ! Errors caught by destest? Yes. Still? *NO*
1252
1253 !sethi %hi(DES_SPtrans), global1 ! address sbox 1
1254
1255 !or global1, %lo(DES_SPtrans), global1 ! sbox 1
1256
1257 add global1, 256, global2 ! sbox 2
1258 add global1, 512, global3 ! sbox 3
1259
1260 ld [in0], out5 ! right
1261 add global1, 768, global4 ! sbox 4
1262 add global1, 1024, global5 ! sbox 5
1263
1264 ld [in0+4], in5 ! left
1265 add global1, 1280, local6 ! sbox 6
1266 add global1, 1792, out3 ! sbox 8
1267
1268 ! rotate
1269
1270 sll in5, 3, local5
1271 mov in1, in3 ! key address to in3
1272
1273 sll out5, 3, local7
1274 srl in5, 29, in5
1275
1276 srl out5, 29, out5
1277 add in5, local5, in5
1278
1279 add out5, local7, out5
1280 cmp in2, 0
1281
1282 ! we use our own stackframe
1283
1284#ifdef OPENSSL_SYSNAME_ULTRASPARC
1285 be,pn %icc, .encrypt2.dec ! decryption
1286#else
1287 be .encrypt2.dec
1288#endif
1289 STPTR in0, [%sp+BIAS+ARG0+0*ARGSZ]
1290
1291 ld [in3], out0 ! key 7531 first round
1292 mov LOOPS, out4 ! loop counter
1293
1294 ld [in3+4], out1 ! key 8642 first round
1295 sethi %hi(0x0000FC00), local5
1296
1297 call .des_enc
1298 mov in3, in4
1299
1300 ! rotate
1301 sll in5, 29, in0
1302 srl in5, 3, in5
1303 sll out5, 29, in1
1304 add in5, in0, in5
1305 srl out5, 3, out5
1306 LDPTR [%sp+BIAS+ARG0+0*ARGSZ], in0
1307 add out5, in1, out5
1308 st in5, [in0]
1309 st out5, [in0+4]
1310
1311 ret
1312 restore
1313
1314
1315.encrypt2.dec:
1316
1317 add in3, 120, in4
1318
1319 ld [in4], out0 ! key 7531 first round
1320 mov LOOPS, out4 ! loop counter
1321
1322 ld [in4+4], out1 ! key 8642 first round
1323 sethi %hi(0x0000FC00), local5
1324
1325 mov in5, local1 ! left expected in out5
1326 mov out5, in5
1327
1328 call .des_dec
1329 mov local1, out5
1330
1331.encrypt2.finish:
1332
1333 ! rotate
1334 sll in5, 29, in0
1335 srl in5, 3, in5
1336 sll out5, 29, in1
1337 add in5, in0, in5
1338 srl out5, 3, out5
1339 LDPTR [%sp+BIAS+ARG0+0*ARGSZ], in0
1340 add out5, in1, out5
1341 st out5, [in0]
1342 st in5, [in0+4]
1343
1344 ret
1345 restore
1346
1347.DES_encrypt2.end:
1348 .size DES_encrypt2, .DES_encrypt2.end-DES_encrypt2
1349
1350
1351! void DES_encrypt3(data, ks1, ks2, ks3)
1352! **************************************
1353
1354 .align 32
1355 .global DES_encrypt3
1356 .type DES_encrypt3,#function
1357
1358DES_encrypt3:
1359
1360 save %sp, FRAME, %sp
1361
1362 sethi %hi(.PIC.DES_SPtrans-1f),global1
1363 or global1,%lo(.PIC.DES_SPtrans-1f),global1
13641: call .+8
1365 add %o7,global1,global1
1366 sub global1,.PIC.DES_SPtrans-.des_and,out2
1367
1368 ld [in0], in5 ! left
1369 add in2, 120, in4 ! ks2
1370
1371 ld [in0+4], out5 ! right
1372 mov in3, in2 ! save ks3
1373
1374 ! parameter 6 1/2 for include encryption/decryption
1375 ! parameter 7 1 for mov in1 to in3
1376 ! parameter 8 1 for mov in3 to in4
1377 ! parameter 9 1 for load ks3 and ks2 to in4 and in3
1378
1379 ip_macro(in5, out5, in5, out5, in3, 1, 1, 0, 0)
1380
1381 call .des_dec
1382 mov in2, in3 ! preload ks3
1383
1384 call .des_enc
1385 nop
1386
1387 fp_macro(in5, out5, 1)
1388
1389 ret
1390 restore
1391
1392.DES_encrypt3.end:
1393 .size DES_encrypt3,.DES_encrypt3.end-DES_encrypt3
1394
1395
1396! void DES_decrypt3(data, ks1, ks2, ks3)
1397! **************************************
1398
1399 .align 32
1400 .global DES_decrypt3
1401 .type DES_decrypt3,#function
1402
1403DES_decrypt3:
1404
1405 save %sp, FRAME, %sp
1406
1407 sethi %hi(.PIC.DES_SPtrans-1f),global1
1408 or global1,%lo(.PIC.DES_SPtrans-1f),global1
14091: call .+8
1410 add %o7,global1,global1
1411 sub global1,.PIC.DES_SPtrans-.des_and,out2
1412
1413 ld [in0], in5 ! left
1414 add in3, 120, in4 ! ks3
1415
1416 ld [in0+4], out5 ! right
1417 mov in2, in3 ! ks2
1418
1419 ! parameter 6 1/2 for include encryption/decryption
1420 ! parameter 7 1 for mov in1 to in3
1421 ! parameter 8 1 for mov in3 to in4
1422 ! parameter 9 1 for load ks3 and ks2 to in4 and in3
1423
1424 ip_macro(in5, out5, out5, in5, in4, 2, 0, 0, 0)
1425
1426 call .des_enc
1427 add in1, 120, in4 ! preload ks1
1428
1429 call .des_dec
1430 nop
1431
1432 fp_macro(out5, in5, 1)
1433
1434 ret
1435 restore
1436
1437.DES_decrypt3.end:
1438 .size DES_decrypt3,.DES_decrypt3.end-DES_decrypt3
1439
1440! void DES_ncbc_encrypt(input, output, length, schedule, ivec, enc)
1441! *****************************************************************
1442
1443
1444 .align 32
1445 .global DES_ncbc_encrypt
1446 .type DES_ncbc_encrypt,#function
1447
1448DES_ncbc_encrypt:
1449
1450 save %sp, FRAME, %sp
1451
1452 define({INPUT}, { [%sp+BIAS+ARG0+0*ARGSZ] })
1453 define({OUTPUT}, { [%sp+BIAS+ARG0+1*ARGSZ] })
1454 define({IVEC}, { [%sp+BIAS+ARG0+4*ARGSZ] })
1455
1456 sethi %hi(.PIC.DES_SPtrans-1f),global1
1457 or global1,%lo(.PIC.DES_SPtrans-1f),global1
14581: call .+8
1459 add %o7,global1,global1
1460 sub global1,.PIC.DES_SPtrans-.des_and,out2
1461
1462 cmp in5, 0 ! enc
1463
1464#ifdef OPENSSL_SYSNAME_ULTRASPARC
1465 be,pn %icc, .ncbc.dec
1466#else
1467 be .ncbc.dec
1468#endif
1469 STPTR in4, IVEC
1470
1471 ! addr left right temp label
1472 load_little_endian(in4, in5, out5, local3, .LLE1) ! iv
1473
1474 addcc in2, -8, in2 ! bytes missing when first block done
1475
1476#ifdef OPENSSL_SYSNAME_ULTRASPARC
1477 bl,pn %icc, .ncbc.enc.seven.or.less
1478#else
1479 bl .ncbc.enc.seven.or.less
1480#endif
1481 mov in3, in4 ! schedule
1482
1483.ncbc.enc.next.block:
1484
1485 load_little_endian(in0, out4, global4, local3, .LLE2) ! block
1486
1487.ncbc.enc.next.block_1:
1488
1489 xor in5, out4, in5 ! iv xor
1490 xor out5, global4, out5 ! iv xor
1491
1492 ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3
1493 ip_macro(in5, out5, in5, out5, in3, 0, 0, 2)
1494
1495.ncbc.enc.next.block_2:
1496
1497!// call .des_enc ! compares in2 to 8
1498! rounds inlined for alignment purposes
1499
1500 add global1, 768, global4 ! address sbox 4 since register used below
1501
1502 rounds_macro(in5, out5, 1, .ncbc.enc.1, in3, in4) ! include encryption ks in3
1503
1504#ifdef OPENSSL_SYSNAME_ULTRASPARC
1505 bl,pn %icc, .ncbc.enc.next.block_fp
1506#else
1507 bl .ncbc.enc.next.block_fp
1508#endif
1509 add in0, 8, in0 ! input address
1510
1511 ! If 8 or more bytes are to be encrypted after this block,
1512 ! we combine final permutation for this block with initial
1513 ! permutation for next block. Load next block:
1514
1515 load_little_endian(in0, global3, global4, local5, .LLE12)
1516
1517 ! parameter 1 original left
1518 ! parameter 2 original right
1519 ! parameter 3 left ip
1520 ! parameter 4 right ip
1521 ! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4
1522 ! 2: mov in4 to in3
1523 !
1524 ! also adds -8 to length in2 and loads loop counter to out4
1525
1526 fp_ip_macro(out0, out1, global3, global4, 2)
1527
1528 store_little_endian(in1, out0, out1, local3, .SLE10) ! block
1529
1530 ld [in3], out0 ! key 7531 first round next block
1531 mov in5, local1
1532 xor global3, out5, in5 ! iv xor next block
1533
1534 ld [in3+4], out1 ! key 8642
1535 add global1, 512, global3 ! address sbox 3 since register used
1536 xor global4, local1, out5 ! iv xor next block
1537
1538 ba .ncbc.enc.next.block_2
1539 add in1, 8, in1 ! output adress
1540
1541.ncbc.enc.next.block_fp:
1542
1543 fp_macro(in5, out5)
1544
1545 store_little_endian(in1, in5, out5, local3, .SLE1) ! block
1546
1547 addcc in2, -8, in2 ! bytes missing when next block done
1548
1549#ifdef OPENSSL_SYSNAME_ULTRASPARC
1550 bpos,pt %icc, .ncbc.enc.next.block ! also jumps if 0
1551#else
1552 bpos .ncbc.enc.next.block
1553#endif
1554 add in1, 8, in1
1555
1556.ncbc.enc.seven.or.less:
1557
1558 cmp in2, -8
1559
1560#ifdef OPENSSL_SYSNAME_ULTRASPARC
1561 ble,pt %icc, .ncbc.enc.finish
1562#else
1563 ble .ncbc.enc.finish
1564#endif
1565 nop
1566
1567 add in2, 8, local1 ! bytes to load
1568
1569 ! addr, length, dest left, dest right, temp, temp2, label, ret label
1570 load_n_bytes(in0, local1, global4, out4, local2, local3, .LNB1, .ncbc.enc.next.block_1)
1571
1572 ! Loads 1 to 7 bytes little endian to global4, out4
1573
1574
1575.ncbc.enc.finish:
1576
1577 LDPTR IVEC, local4
1578 store_little_endian(local4, in5, out5, local5, .SLE2) ! ivec
1579
1580 ret
1581 restore
1582
1583
1584.ncbc.dec:
1585
1586 STPTR in0, INPUT
1587 cmp in2, 0 ! length
1588 add in3, 120, in3
1589
1590 LDPTR IVEC, local7 ! ivec
1591#ifdef OPENSSL_SYSNAME_ULTRASPARC
1592 ble,pn %icc, .ncbc.dec.finish
1593#else
1594 ble .ncbc.dec.finish
1595#endif
1596 mov in3, in4 ! schedule
1597
1598 STPTR in1, OUTPUT
1599 mov in0, local5 ! input
1600
1601 load_little_endian(local7, in0, in1, local3, .LLE3) ! ivec
1602
1603.ncbc.dec.next.block:
1604
1605 load_little_endian(local5, in5, out5, local3, .LLE4) ! block
1606
1607 ! parameter 6 1/2 for include encryption/decryption
1608 ! parameter 7 1 for mov in1 to in3
1609 ! parameter 8 1 for mov in3 to in4
1610
1611 ip_macro(in5, out5, out5, in5, in4, 2, 0, 1) ! include decryprion ks in4
1612
1613 fp_macro(out5, in5, 0, 1) ! 1 for input and output address to local5/7
1614
1615 ! in2 is bytes left to be stored
1616 ! in2 is compared to 8 in the rounds
1617
1618 xor out5, in0, out4 ! iv xor
1619#ifdef OPENSSL_SYSNAME_ULTRASPARC
1620 bl,pn %icc, .ncbc.dec.seven.or.less
1621#else
1622 bl .ncbc.dec.seven.or.less
1623#endif
1624 xor in5, in1, global4 ! iv xor
1625
1626 ! Load ivec next block now, since input and output address might be the same.
1627
1628 load_little_endian_inc(local5, in0, in1, local3, .LLE5) ! iv
1629
1630 store_little_endian(local7, out4, global4, local3, .SLE3)
1631
1632 STPTR local5, INPUT
1633 add local7, 8, local7
1634 addcc in2, -8, in2
1635
1636#ifdef OPENSSL_SYSNAME_ULTRASPARC
1637 bg,pt %icc, .ncbc.dec.next.block
1638#else
1639 bg .ncbc.dec.next.block
1640#endif
1641 STPTR local7, OUTPUT
1642
1643
1644.ncbc.dec.store.iv:
1645
1646 LDPTR IVEC, local4 ! ivec
1647 store_little_endian(local4, in0, in1, local5, .SLE4)
1648
1649.ncbc.dec.finish:
1650
1651 ret
1652 restore
1653
1654.ncbc.dec.seven.or.less:
1655
1656 load_little_endian_inc(local5, in0, in1, local3, .LLE13) ! ivec
1657
1658 store_n_bytes(local7, in2, global4, out4, local3, local4, .SNB1, .ncbc.dec.store.iv)
1659
1660
1661.DES_ncbc_encrypt.end:
1662 .size DES_ncbc_encrypt, .DES_ncbc_encrypt.end-DES_ncbc_encrypt
1663
1664
1665! void DES_ede3_cbc_encrypt(input, output, lenght, ks1, ks2, ks3, ivec, enc)
1666! **************************************************************************
1667
1668
1669 .align 32
1670 .global DES_ede3_cbc_encrypt
1671 .type DES_ede3_cbc_encrypt,#function
1672
1673DES_ede3_cbc_encrypt:
1674
1675 save %sp, FRAME, %sp
1676
1677 define({KS1}, { [%sp+BIAS+ARG0+3*ARGSZ] })
1678 define({KS2}, { [%sp+BIAS+ARG0+4*ARGSZ] })
1679 define({KS3}, { [%sp+BIAS+ARG0+5*ARGSZ] })
1680
1681 sethi %hi(.PIC.DES_SPtrans-1f),global1
1682 or global1,%lo(.PIC.DES_SPtrans-1f),global1
16831: call .+8
1684 add %o7,global1,global1
1685 sub global1,.PIC.DES_SPtrans-.des_and,out2
1686
1687 LDPTR [%fp+BIAS+ARG0+7*ARGSZ], local3 ! enc
1688 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec
1689 cmp local3, 0 ! enc
1690
1691#ifdef OPENSSL_SYSNAME_ULTRASPARC
1692 be,pn %icc, .ede3.dec
1693#else
1694 be .ede3.dec
1695#endif
1696 STPTR in4, KS2
1697
1698 STPTR in5, KS3
1699
1700 load_little_endian(local4, in5, out5, local3, .LLE6) ! ivec
1701
1702 addcc in2, -8, in2 ! bytes missing after next block
1703
1704#ifdef OPENSSL_SYSNAME_ULTRASPARC
1705 bl,pn %icc, .ede3.enc.seven.or.less
1706#else
1707 bl .ede3.enc.seven.or.less
1708#endif
1709 STPTR in3, KS1
1710
1711.ede3.enc.next.block:
1712
1713 load_little_endian(in0, out4, global4, local3, .LLE7)
1714
1715.ede3.enc.next.block_1:
1716
1717 LDPTR KS2, in4
1718 xor in5, out4, in5 ! iv xor
1719 xor out5, global4, out5 ! iv xor
1720
1721 LDPTR KS1, in3
1722 add in4, 120, in4 ! for decryption we use last subkey first
1723 nop
1724
1725 ip_macro(in5, out5, in5, out5, in3)
1726
1727.ede3.enc.next.block_2:
1728
1729 call .des_enc ! ks1 in3
1730 nop
1731
1732 call .des_dec ! ks2 in4
1733 LDPTR KS3, in3
1734
1735 call .des_enc ! ks3 in3 compares in2 to 8
1736 nop
1737
1738#ifdef OPENSSL_SYSNAME_ULTRASPARC
1739 bl,pn %icc, .ede3.enc.next.block_fp
1740#else
1741 bl .ede3.enc.next.block_fp
1742#endif
1743 add in0, 8, in0
1744
1745 ! If 8 or more bytes are to be encrypted after this block,
1746 ! we combine final permutation for this block with initial
1747 ! permutation for next block. Load next block:
1748
1749 load_little_endian(in0, global3, global4, local5, .LLE11)
1750
1751 ! parameter 1 original left
1752 ! parameter 2 original right
1753 ! parameter 3 left ip
1754 ! parameter 4 right ip
1755 ! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4
1756 ! 2: mov in4 to in3
1757 !
1758 ! also adds -8 to length in2 and loads loop counter to out4
1759
1760 fp_ip_macro(out0, out1, global3, global4, 1)
1761
1762 store_little_endian(in1, out0, out1, local3, .SLE9) ! block
1763
1764 mov in5, local1
1765 xor global3, out5, in5 ! iv xor next block
1766
1767 ld [in3], out0 ! key 7531
1768 add global1, 512, global3 ! address sbox 3
1769 xor global4, local1, out5 ! iv xor next block
1770
1771 ld [in3+4], out1 ! key 8642
1772 add global1, 768, global4 ! address sbox 4
1773 ba .ede3.enc.next.block_2
1774 add in1, 8, in1
1775
1776.ede3.enc.next.block_fp:
1777
1778 fp_macro(in5, out5)
1779
1780 store_little_endian(in1, in5, out5, local3, .SLE5) ! block
1781
1782 addcc in2, -8, in2 ! bytes missing when next block done
1783
1784#ifdef OPENSSL_SYSNAME_ULTRASPARC
1785 bpos,pt %icc, .ede3.enc.next.block
1786#else
1787 bpos .ede3.enc.next.block
1788#endif
1789 add in1, 8, in1
1790
1791.ede3.enc.seven.or.less:
1792
1793 cmp in2, -8
1794
1795#ifdef OPENSSL_SYSNAME_ULTRASPARC
1796 ble,pt %icc, .ede3.enc.finish
1797#else
1798 ble .ede3.enc.finish
1799#endif
1800 nop
1801
1802 add in2, 8, local1 ! bytes to load
1803
1804 ! addr, length, dest left, dest right, temp, temp2, label, ret label
1805 load_n_bytes(in0, local1, global4, out4, local2, local3, .LNB2, .ede3.enc.next.block_1)
1806
1807.ede3.enc.finish:
1808
1809 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec
1810 store_little_endian(local4, in5, out5, local5, .SLE6) ! ivec
1811
1812 ret
1813 restore
1814
1815.ede3.dec:
1816
1817 STPTR in0, INPUT
1818 add in5, 120, in5
1819
1820 STPTR in1, OUTPUT
1821 mov in0, local5
1822 add in3, 120, in3
1823
1824 STPTR in3, KS1
1825 cmp in2, 0
1826
1827#ifdef OPENSSL_SYSNAME_ULTRASPARC
1828 ble %icc, .ede3.dec.finish
1829#else
1830 ble .ede3.dec.finish
1831#endif
1832 STPTR in5, KS3
1833
1834 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local7 ! iv
1835 load_little_endian(local7, in0, in1, local3, .LLE8)
1836
1837.ede3.dec.next.block:
1838
1839 load_little_endian(local5, in5, out5, local3, .LLE9)
1840
1841 ! parameter 6 1/2 for include encryption/decryption
1842 ! parameter 7 1 for mov in1 to in3
1843 ! parameter 8 1 for mov in3 to in4
1844 ! parameter 9 1 for load ks3 and ks2 to in4 and in3
1845
1846 ip_macro(in5, out5, out5, in5, in4, 2, 0, 0, 1) ! inc .des_dec ks3 in4
1847
1848 call .des_enc ! ks2 in3
1849 LDPTR KS1, in4
1850
1851 call .des_dec ! ks1 in4
1852 nop
1853
1854 fp_macro(out5, in5, 0, 1) ! 1 for input and output address local5/7
1855
1856 ! in2 is bytes left to be stored
1857 ! in2 is compared to 8 in the rounds
1858
1859 xor out5, in0, out4
1860#ifdef OPENSSL_SYSNAME_ULTRASPARC
1861 bl,pn %icc, .ede3.dec.seven.or.less
1862#else
1863 bl .ede3.dec.seven.or.less
1864#endif
1865 xor in5, in1, global4
1866
1867 load_little_endian_inc(local5, in0, in1, local3, .LLE10) ! iv next block
1868
1869 store_little_endian(local7, out4, global4, local3, .SLE7) ! block
1870
1871 STPTR local5, INPUT
1872 addcc in2, -8, in2
1873 add local7, 8, local7
1874
1875#ifdef OPENSSL_SYSNAME_ULTRASPARC
1876 bg,pt %icc, .ede3.dec.next.block
1877#else
1878 bg .ede3.dec.next.block
1879#endif
1880 STPTR local7, OUTPUT
1881
1882.ede3.dec.store.iv:
1883
1884 LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec
1885 store_little_endian(local4, in0, in1, local5, .SLE8) ! ivec
1886
1887.ede3.dec.finish:
1888
1889 ret
1890 restore
1891
1892.ede3.dec.seven.or.less:
1893
1894 load_little_endian_inc(local5, in0, in1, local3, .LLE14) ! iv
1895
1896 store_n_bytes(local7, in2, global4, out4, local3, local4, .SNB2, .ede3.dec.store.iv)
1897
1898
1899.DES_ede3_cbc_encrypt.end:
1900 .size DES_ede3_cbc_encrypt,.DES_ede3_cbc_encrypt.end-DES_ede3_cbc_encrypt
1901
1902 .align 256
1903 .type .des_and,#object
1904 .size .des_and,284
1905
1906.des_and:
1907
1908! This table is used for AND 0xFC when it is known that register
1909! bits 8-31 are zero. Makes it possible to do three arithmetic
1910! operations in one cycle.
1911
1912 .byte 0, 0, 0, 0, 4, 4, 4, 4
1913 .byte 8, 8, 8, 8, 12, 12, 12, 12
1914 .byte 16, 16, 16, 16, 20, 20, 20, 20
1915 .byte 24, 24, 24, 24, 28, 28, 28, 28
1916 .byte 32, 32, 32, 32, 36, 36, 36, 36
1917 .byte 40, 40, 40, 40, 44, 44, 44, 44
1918 .byte 48, 48, 48, 48, 52, 52, 52, 52
1919 .byte 56, 56, 56, 56, 60, 60, 60, 60
1920 .byte 64, 64, 64, 64, 68, 68, 68, 68
1921 .byte 72, 72, 72, 72, 76, 76, 76, 76
1922 .byte 80, 80, 80, 80, 84, 84, 84, 84
1923 .byte 88, 88, 88, 88, 92, 92, 92, 92
1924 .byte 96, 96, 96, 96, 100, 100, 100, 100
1925 .byte 104, 104, 104, 104, 108, 108, 108, 108
1926 .byte 112, 112, 112, 112, 116, 116, 116, 116
1927 .byte 120, 120, 120, 120, 124, 124, 124, 124
1928 .byte 128, 128, 128, 128, 132, 132, 132, 132
1929 .byte 136, 136, 136, 136, 140, 140, 140, 140
1930 .byte 144, 144, 144, 144, 148, 148, 148, 148
1931 .byte 152, 152, 152, 152, 156, 156, 156, 156
1932 .byte 160, 160, 160, 160, 164, 164, 164, 164
1933 .byte 168, 168, 168, 168, 172, 172, 172, 172
1934 .byte 176, 176, 176, 176, 180, 180, 180, 180
1935 .byte 184, 184, 184, 184, 188, 188, 188, 188
1936 .byte 192, 192, 192, 192, 196, 196, 196, 196
1937 .byte 200, 200, 200, 200, 204, 204, 204, 204
1938 .byte 208, 208, 208, 208, 212, 212, 212, 212
1939 .byte 216, 216, 216, 216, 220, 220, 220, 220
1940 .byte 224, 224, 224, 224, 228, 228, 228, 228
1941 .byte 232, 232, 232, 232, 236, 236, 236, 236
1942 .byte 240, 240, 240, 240, 244, 244, 244, 244
1943 .byte 248, 248, 248, 248, 252, 252, 252, 252
1944
1945 ! 5 numbers for initil/final permutation
1946
1947 .word 0x0f0f0f0f ! offset 256
1948 .word 0x0000ffff ! 260
1949 .word 0x33333333 ! 264
1950 .word 0x00ff00ff ! 268
1951 .word 0x55555555 ! 272
1952
1953 .word 0 ! 276
1954 .word LOOPS ! 280
1955 .word 0x0000FC00 ! 284
1956
1957 .global DES_SPtrans
1958 .type DES_SPtrans,#object
1959 .size DES_SPtrans,2048
1960.align 64
1961DES_SPtrans:
1962.PIC.DES_SPtrans:
1963 ! nibble 0
1964 .word 0x02080800, 0x00080000, 0x02000002, 0x02080802
1965 .word 0x02000000, 0x00080802, 0x00080002, 0x02000002
1966 .word 0x00080802, 0x02080800, 0x02080000, 0x00000802
1967 .word 0x02000802, 0x02000000, 0x00000000, 0x00080002
1968 .word 0x00080000, 0x00000002, 0x02000800, 0x00080800
1969 .word 0x02080802, 0x02080000, 0x00000802, 0x02000800
1970 .word 0x00000002, 0x00000800, 0x00080800, 0x02080002
1971 .word 0x00000800, 0x02000802, 0x02080002, 0x00000000
1972 .word 0x00000000, 0x02080802, 0x02000800, 0x00080002
1973 .word 0x02080800, 0x00080000, 0x00000802, 0x02000800
1974 .word 0x02080002, 0x00000800, 0x00080800, 0x02000002
1975 .word 0x00080802, 0x00000002, 0x02000002, 0x02080000
1976 .word 0x02080802, 0x00080800, 0x02080000, 0x02000802
1977 .word 0x02000000, 0x00000802, 0x00080002, 0x00000000
1978 .word 0x00080000, 0x02000000, 0x02000802, 0x02080800
1979 .word 0x00000002, 0x02080002, 0x00000800, 0x00080802
1980 ! nibble 1
1981 .word 0x40108010, 0x00000000, 0x00108000, 0x40100000
1982 .word 0x40000010, 0x00008010, 0x40008000, 0x00108000
1983 .word 0x00008000, 0x40100010, 0x00000010, 0x40008000
1984 .word 0x00100010, 0x40108000, 0x40100000, 0x00000010
1985 .word 0x00100000, 0x40008010, 0x40100010, 0x00008000
1986 .word 0x00108010, 0x40000000, 0x00000000, 0x00100010
1987 .word 0x40008010, 0x00108010, 0x40108000, 0x40000010
1988 .word 0x40000000, 0x00100000, 0x00008010, 0x40108010
1989 .word 0x00100010, 0x40108000, 0x40008000, 0x00108010
1990 .word 0x40108010, 0x00100010, 0x40000010, 0x00000000
1991 .word 0x40000000, 0x00008010, 0x00100000, 0x40100010
1992 .word 0x00008000, 0x40000000, 0x00108010, 0x40008010
1993 .word 0x40108000, 0x00008000, 0x00000000, 0x40000010
1994 .word 0x00000010, 0x40108010, 0x00108000, 0x40100000
1995 .word 0x40100010, 0x00100000, 0x00008010, 0x40008000
1996 .word 0x40008010, 0x00000010, 0x40100000, 0x00108000
1997 ! nibble 2
1998 .word 0x04000001, 0x04040100, 0x00000100, 0x04000101
1999 .word 0x00040001, 0x04000000, 0x04000101, 0x00040100
2000 .word 0x04000100, 0x00040000, 0x04040000, 0x00000001
2001 .word 0x04040101, 0x00000101, 0x00000001, 0x04040001
2002 .word 0x00000000, 0x00040001, 0x04040100, 0x00000100
2003 .word 0x00000101, 0x04040101, 0x00040000, 0x04000001
2004 .word 0x04040001, 0x04000100, 0x00040101, 0x04040000
2005 .word 0x00040100, 0x00000000, 0x04000000, 0x00040101
2006 .word 0x04040100, 0x00000100, 0x00000001, 0x00040000
2007 .word 0x00000101, 0x00040001, 0x04040000, 0x04000101
2008 .word 0x00000000, 0x04040100, 0x00040100, 0x04040001
2009 .word 0x00040001, 0x04000000, 0x04040101, 0x00000001
2010 .word 0x00040101, 0x04000001, 0x04000000, 0x04040101
2011 .word 0x00040000, 0x04000100, 0x04000101, 0x00040100
2012 .word 0x04000100, 0x00000000, 0x04040001, 0x00000101
2013 .word 0x04000001, 0x00040101, 0x00000100, 0x04040000
2014 ! nibble 3
2015 .word 0x00401008, 0x10001000, 0x00000008, 0x10401008
2016 .word 0x00000000, 0x10400000, 0x10001008, 0x00400008
2017 .word 0x10401000, 0x10000008, 0x10000000, 0x00001008
2018 .word 0x10000008, 0x00401008, 0x00400000, 0x10000000
2019 .word 0x10400008, 0x00401000, 0x00001000, 0x00000008
2020 .word 0x00401000, 0x10001008, 0x10400000, 0x00001000
2021 .word 0x00001008, 0x00000000, 0x00400008, 0x10401000
2022 .word 0x10001000, 0x10400008, 0x10401008, 0x00400000
2023 .word 0x10400008, 0x00001008, 0x00400000, 0x10000008
2024 .word 0x00401000, 0x10001000, 0x00000008, 0x10400000
2025 .word 0x10001008, 0x00000000, 0x00001000, 0x00400008
2026 .word 0x00000000, 0x10400008, 0x10401000, 0x00001000
2027 .word 0x10000000, 0x10401008, 0x00401008, 0x00400000
2028 .word 0x10401008, 0x00000008, 0x10001000, 0x00401008
2029 .word 0x00400008, 0x00401000, 0x10400000, 0x10001008
2030 .word 0x00001008, 0x10000000, 0x10000008, 0x10401000
2031 ! nibble 4
2032 .word 0x08000000, 0x00010000, 0x00000400, 0x08010420
2033 .word 0x08010020, 0x08000400, 0x00010420, 0x08010000
2034 .word 0x00010000, 0x00000020, 0x08000020, 0x00010400
2035 .word 0x08000420, 0x08010020, 0x08010400, 0x00000000
2036 .word 0x00010400, 0x08000000, 0x00010020, 0x00000420
2037 .word 0x08000400, 0x00010420, 0x00000000, 0x08000020
2038 .word 0x00000020, 0x08000420, 0x08010420, 0x00010020
2039 .word 0x08010000, 0x00000400, 0x00000420, 0x08010400
2040 .word 0x08010400, 0x08000420, 0x00010020, 0x08010000
2041 .word 0x00010000, 0x00000020, 0x08000020, 0x08000400
2042 .word 0x08000000, 0x00010400, 0x08010420, 0x00000000
2043 .word 0x00010420, 0x08000000, 0x00000400, 0x00010020
2044 .word 0x08000420, 0x00000400, 0x00000000, 0x08010420
2045 .word 0x08010020, 0x08010400, 0x00000420, 0x00010000
2046 .word 0x00010400, 0x08010020, 0x08000400, 0x00000420
2047 .word 0x00000020, 0x00010420, 0x08010000, 0x08000020
2048 ! nibble 5
2049 .word 0x80000040, 0x00200040, 0x00000000, 0x80202000
2050 .word 0x00200040, 0x00002000, 0x80002040, 0x00200000
2051 .word 0x00002040, 0x80202040, 0x00202000, 0x80000000
2052 .word 0x80002000, 0x80000040, 0x80200000, 0x00202040
2053 .word 0x00200000, 0x80002040, 0x80200040, 0x00000000
2054 .word 0x00002000, 0x00000040, 0x80202000, 0x80200040
2055 .word 0x80202040, 0x80200000, 0x80000000, 0x00002040
2056 .word 0x00000040, 0x00202000, 0x00202040, 0x80002000
2057 .word 0x00002040, 0x80000000, 0x80002000, 0x00202040
2058 .word 0x80202000, 0x00200040, 0x00000000, 0x80002000
2059 .word 0x80000000, 0x00002000, 0x80200040, 0x00200000
2060 .word 0x00200040, 0x80202040, 0x00202000, 0x00000040
2061 .word 0x80202040, 0x00202000, 0x00200000, 0x80002040
2062 .word 0x80000040, 0x80200000, 0x00202040, 0x00000000
2063 .word 0x00002000, 0x80000040, 0x80002040, 0x80202000
2064 .word 0x80200000, 0x00002040, 0x00000040, 0x80200040
2065 ! nibble 6
2066 .word 0x00004000, 0x00000200, 0x01000200, 0x01000004
2067 .word 0x01004204, 0x00004004, 0x00004200, 0x00000000
2068 .word 0x01000000, 0x01000204, 0x00000204, 0x01004000
2069 .word 0x00000004, 0x01004200, 0x01004000, 0x00000204
2070 .word 0x01000204, 0x00004000, 0x00004004, 0x01004204
2071 .word 0x00000000, 0x01000200, 0x01000004, 0x00004200
2072 .word 0x01004004, 0x00004204, 0x01004200, 0x00000004
2073 .word 0x00004204, 0x01004004, 0x00000200, 0x01000000
2074 .word 0x00004204, 0x01004000, 0x01004004, 0x00000204
2075 .word 0x00004000, 0x00000200, 0x01000000, 0x01004004
2076 .word 0x01000204, 0x00004204, 0x00004200, 0x00000000
2077 .word 0x00000200, 0x01000004, 0x00000004, 0x01000200
2078 .word 0x00000000, 0x01000204, 0x01000200, 0x00004200
2079 .word 0x00000204, 0x00004000, 0x01004204, 0x01000000
2080 .word 0x01004200, 0x00000004, 0x00004004, 0x01004204
2081 .word 0x01000004, 0x01004200, 0x01004000, 0x00004004
2082 ! nibble 7
2083 .word 0x20800080, 0x20820000, 0x00020080, 0x00000000
2084 .word 0x20020000, 0x00800080, 0x20800000, 0x20820080
2085 .word 0x00000080, 0x20000000, 0x00820000, 0x00020080
2086 .word 0x00820080, 0x20020080, 0x20000080, 0x20800000
2087 .word 0x00020000, 0x00820080, 0x00800080, 0x20020000
2088 .word 0x20820080, 0x20000080, 0x00000000, 0x00820000
2089 .word 0x20000000, 0x00800000, 0x20020080, 0x20800080
2090 .word 0x00800000, 0x00020000, 0x20820000, 0x00000080
2091 .word 0x00800000, 0x00020000, 0x20000080, 0x20820080
2092 .word 0x00020080, 0x20000000, 0x00000000, 0x00820000
2093 .word 0x20800080, 0x20020080, 0x20020000, 0x00800080
2094 .word 0x20820000, 0x00000080, 0x00800080, 0x20020000
2095 .word 0x20820080, 0x00800000, 0x20800000, 0x20000080
2096 .word 0x00820000, 0x00020080, 0x20020080, 0x20800000
2097 .word 0x00000080, 0x20820000, 0x00820080, 0x00000000
2098 .word 0x20000000, 0x20800080, 0x00020000, 0x00820080
2099
diff --git a/src/lib/libcrypto/des/asm/desboth.pl b/src/lib/libcrypto/des/asm/desboth.pl
deleted file mode 100644
index eec00886e4..0000000000
--- a/src/lib/libcrypto/des/asm/desboth.pl
+++ /dev/null
@@ -1,79 +0,0 @@
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/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c
deleted file mode 100644
index 09a7ba56aa..0000000000
--- a/src/lib/libcrypto/des/cbc_cksm.c
+++ /dev/null
@@ -1,106 +0,0 @@
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
deleted file mode 100644
index 677903ae4e..0000000000
--- a/src/lib/libcrypto/des/cbc_enc.c
+++ /dev/null
@@ -1,61 +0,0 @@
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
deleted file mode 100644
index de34ecceb9..0000000000
--- a/src/lib/libcrypto/des/cfb64ede.c
+++ /dev/null
@@ -1,254 +0,0 @@
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
deleted file mode 100644
index 5ec8683e40..0000000000
--- a/src/lib/libcrypto/des/cfb64enc.c
+++ /dev/null
@@ -1,121 +0,0 @@
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
deleted file mode 100644
index 720f29a28e..0000000000
--- a/src/lib/libcrypto/des/cfb_enc.c
+++ /dev/null
@@ -1,195 +0,0 @@
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.h b/src/lib/libcrypto/des/des.h
deleted file mode 100644
index 23c8cfc901..0000000000
--- a/src/lib/libcrypto/des/des.h
+++ /dev/null
@@ -1,250 +0,0 @@
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);
229#ifdef OPENSSL_FIPS
230void private_DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule);
231#endif
232void DES_string_to_key(const char *str,DES_cblock *key);
233void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2);
234void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
235 DES_key_schedule *schedule,DES_cblock *ivec,int *num,
236 int enc);
237void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
238 DES_key_schedule *schedule,DES_cblock *ivec,int *num);
239
240int DES_read_password(DES_cblock *key, const char *prompt, int verify);
241int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
242 int verify);
243
244#define DES_fixup_key_parity DES_set_odd_parity
245
246#ifdef __cplusplus
247}
248#endif
249
250#endif
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
deleted file mode 100644
index 5c47553a5a..0000000000
--- a/src/lib/libcrypto/des/des_enc.c
+++ /dev/null
@@ -1,404 +0,0 @@
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#include "spr.h"
61
62#ifndef OPENBSD_DES_ASM
63
64void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
65 {
66 register DES_LONG l,r,t,u;
67#ifdef DES_PTR
68 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
69#endif
70#ifndef DES_UNROLL
71 register int i;
72#endif
73 register DES_LONG *s;
74
75 r=data[0];
76 l=data[1];
77
78 IP(r,l);
79 /* Things have been modified so that the initial rotate is
80 * done outside the loop. This required the
81 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
82 * One perl script later and things have a 5% speed up on a sparc2.
83 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
84 * for pointing this out. */
85 /* clear the top bits on machines with 8byte longs */
86 /* shift left by 2 */
87 r=ROTATE(r,29)&0xffffffffL;
88 l=ROTATE(l,29)&0xffffffffL;
89
90 s=ks->ks->deslong;
91 /* I don't know if it is worth the effort of loop unrolling the
92 * inner loop */
93 if (enc)
94 {
95#ifdef DES_UNROLL
96 D_ENCRYPT(l,r, 0); /* 1 */
97 D_ENCRYPT(r,l, 2); /* 2 */
98 D_ENCRYPT(l,r, 4); /* 3 */
99 D_ENCRYPT(r,l, 6); /* 4 */
100 D_ENCRYPT(l,r, 8); /* 5 */
101 D_ENCRYPT(r,l,10); /* 6 */
102 D_ENCRYPT(l,r,12); /* 7 */
103 D_ENCRYPT(r,l,14); /* 8 */
104 D_ENCRYPT(l,r,16); /* 9 */
105 D_ENCRYPT(r,l,18); /* 10 */
106 D_ENCRYPT(l,r,20); /* 11 */
107 D_ENCRYPT(r,l,22); /* 12 */
108 D_ENCRYPT(l,r,24); /* 13 */
109 D_ENCRYPT(r,l,26); /* 14 */
110 D_ENCRYPT(l,r,28); /* 15 */
111 D_ENCRYPT(r,l,30); /* 16 */
112#else
113 for (i=0; i<32; i+=4)
114 {
115 D_ENCRYPT(l,r,i+0); /* 1 */
116 D_ENCRYPT(r,l,i+2); /* 2 */
117 }
118#endif
119 }
120 else
121 {
122#ifdef DES_UNROLL
123 D_ENCRYPT(l,r,30); /* 16 */
124 D_ENCRYPT(r,l,28); /* 15 */
125 D_ENCRYPT(l,r,26); /* 14 */
126 D_ENCRYPT(r,l,24); /* 13 */
127 D_ENCRYPT(l,r,22); /* 12 */
128 D_ENCRYPT(r,l,20); /* 11 */
129 D_ENCRYPT(l,r,18); /* 10 */
130 D_ENCRYPT(r,l,16); /* 9 */
131 D_ENCRYPT(l,r,14); /* 8 */
132 D_ENCRYPT(r,l,12); /* 7 */
133 D_ENCRYPT(l,r,10); /* 6 */
134 D_ENCRYPT(r,l, 8); /* 5 */
135 D_ENCRYPT(l,r, 6); /* 4 */
136 D_ENCRYPT(r,l, 4); /* 3 */
137 D_ENCRYPT(l,r, 2); /* 2 */
138 D_ENCRYPT(r,l, 0); /* 1 */
139#else
140 for (i=30; i>0; i-=4)
141 {
142 D_ENCRYPT(l,r,i-0); /* 16 */
143 D_ENCRYPT(r,l,i-2); /* 15 */
144 }
145#endif
146 }
147
148 /* rotate and clear the top bits on machines with 8byte longs */
149 l=ROTATE(l,3)&0xffffffffL;
150 r=ROTATE(r,3)&0xffffffffL;
151
152 FP(r,l);
153 data[0]=l;
154 data[1]=r;
155 l=r=t=u=0;
156 }
157
158void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
159 {
160 register DES_LONG l,r,t,u;
161#ifdef DES_PTR
162 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
163#endif
164#ifndef DES_UNROLL
165 register int i;
166#endif
167 register DES_LONG *s;
168
169 r=data[0];
170 l=data[1];
171
172 /* Things have been modified so that the initial rotate is
173 * done outside the loop. This required the
174 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
175 * One perl script later and things have a 5% speed up on a sparc2.
176 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
177 * for pointing this out. */
178 /* clear the top bits on machines with 8byte longs */
179 r=ROTATE(r,29)&0xffffffffL;
180 l=ROTATE(l,29)&0xffffffffL;
181
182 s=ks->ks->deslong;
183 /* I don't know if it is worth the effort of loop unrolling the
184 * inner loop */
185 if (enc)
186 {
187#ifdef DES_UNROLL
188 D_ENCRYPT(l,r, 0); /* 1 */
189 D_ENCRYPT(r,l, 2); /* 2 */
190 D_ENCRYPT(l,r, 4); /* 3 */
191 D_ENCRYPT(r,l, 6); /* 4 */
192 D_ENCRYPT(l,r, 8); /* 5 */
193 D_ENCRYPT(r,l,10); /* 6 */
194 D_ENCRYPT(l,r,12); /* 7 */
195 D_ENCRYPT(r,l,14); /* 8 */
196 D_ENCRYPT(l,r,16); /* 9 */
197 D_ENCRYPT(r,l,18); /* 10 */
198 D_ENCRYPT(l,r,20); /* 11 */
199 D_ENCRYPT(r,l,22); /* 12 */
200 D_ENCRYPT(l,r,24); /* 13 */
201 D_ENCRYPT(r,l,26); /* 14 */
202 D_ENCRYPT(l,r,28); /* 15 */
203 D_ENCRYPT(r,l,30); /* 16 */
204#else
205 for (i=0; i<32; i+=4)
206 {
207 D_ENCRYPT(l,r,i+0); /* 1 */
208 D_ENCRYPT(r,l,i+2); /* 2 */
209 }
210#endif
211 }
212 else
213 {
214#ifdef DES_UNROLL
215 D_ENCRYPT(l,r,30); /* 16 */
216 D_ENCRYPT(r,l,28); /* 15 */
217 D_ENCRYPT(l,r,26); /* 14 */
218 D_ENCRYPT(r,l,24); /* 13 */
219 D_ENCRYPT(l,r,22); /* 12 */
220 D_ENCRYPT(r,l,20); /* 11 */
221 D_ENCRYPT(l,r,18); /* 10 */
222 D_ENCRYPT(r,l,16); /* 9 */
223 D_ENCRYPT(l,r,14); /* 8 */
224 D_ENCRYPT(r,l,12); /* 7 */
225 D_ENCRYPT(l,r,10); /* 6 */
226 D_ENCRYPT(r,l, 8); /* 5 */
227 D_ENCRYPT(l,r, 6); /* 4 */
228 D_ENCRYPT(r,l, 4); /* 3 */
229 D_ENCRYPT(l,r, 2); /* 2 */
230 D_ENCRYPT(r,l, 0); /* 1 */
231#else
232 for (i=30; i>0; i-=4)
233 {
234 D_ENCRYPT(l,r,i-0); /* 16 */
235 D_ENCRYPT(r,l,i-2); /* 15 */
236 }
237#endif
238 }
239 /* rotate and clear the top bits on machines with 8byte longs */
240 data[0]=ROTATE(l,3)&0xffffffffL;
241 data[1]=ROTATE(r,3)&0xffffffffL;
242 l=r=t=u=0;
243 }
244
245#endif /* OPENBSD_DES_ASM */
246
247void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
248 DES_key_schedule *ks2, DES_key_schedule *ks3)
249 {
250 register DES_LONG l,r;
251
252 l=data[0];
253 r=data[1];
254 IP(l,r);
255 data[0]=l;
256 data[1]=r;
257 DES_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);
258 DES_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);
259 DES_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);
260 l=data[0];
261 r=data[1];
262 FP(r,l);
263 data[0]=l;
264 data[1]=r;
265 }
266
267void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
268 DES_key_schedule *ks2, DES_key_schedule *ks3)
269 {
270 register DES_LONG l,r;
271
272 l=data[0];
273 r=data[1];
274 IP(l,r);
275 data[0]=l;
276 data[1]=r;
277 DES_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT);
278 DES_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT);
279 DES_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT);
280 l=data[0];
281 r=data[1];
282 FP(r,l);
283 data[0]=l;
284 data[1]=r;
285 }
286
287#ifndef DES_DEFAULT_OPTIONS
288
289#undef CBC_ENC_C__DONT_UPDATE_IV
290#include "ncbc_enc.c" /* DES_ncbc_encrypt */
291
292void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
293 long length, DES_key_schedule *ks1,
294 DES_key_schedule *ks2, DES_key_schedule *ks3,
295 DES_cblock *ivec, int enc)
296 {
297 register DES_LONG tin0,tin1;
298 register DES_LONG tout0,tout1,xor0,xor1;
299 register const unsigned char *in;
300 unsigned char *out;
301 register long l=length;
302 DES_LONG tin[2];
303 unsigned char *iv;
304
305 in=input;
306 out=output;
307 iv = &(*ivec)[0];
308
309 if (enc)
310 {
311 c2l(iv,tout0);
312 c2l(iv,tout1);
313 for (l-=8; l>=0; l-=8)
314 {
315 c2l(in,tin0);
316 c2l(in,tin1);
317 tin0^=tout0;
318 tin1^=tout1;
319
320 tin[0]=tin0;
321 tin[1]=tin1;
322 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
323 tout0=tin[0];
324 tout1=tin[1];
325
326 l2c(tout0,out);
327 l2c(tout1,out);
328 }
329 if (l != -8)
330 {
331 c2ln(in,tin0,tin1,l+8);
332 tin0^=tout0;
333 tin1^=tout1;
334
335 tin[0]=tin0;
336 tin[1]=tin1;
337 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
338 tout0=tin[0];
339 tout1=tin[1];
340
341 l2c(tout0,out);
342 l2c(tout1,out);
343 }
344 iv = &(*ivec)[0];
345 l2c(tout0,iv);
346 l2c(tout1,iv);
347 }
348 else
349 {
350 register DES_LONG t0,t1;
351
352 c2l(iv,xor0);
353 c2l(iv,xor1);
354 for (l-=8; l>=0; l-=8)
355 {
356 c2l(in,tin0);
357 c2l(in,tin1);
358
359 t0=tin0;
360 t1=tin1;
361
362 tin[0]=tin0;
363 tin[1]=tin1;
364 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
365 tout0=tin[0];
366 tout1=tin[1];
367
368 tout0^=xor0;
369 tout1^=xor1;
370 l2c(tout0,out);
371 l2c(tout1,out);
372 xor0=t0;
373 xor1=t1;
374 }
375 if (l != -8)
376 {
377 c2l(in,tin0);
378 c2l(in,tin1);
379
380 t0=tin0;
381 t1=tin1;
382
383 tin[0]=tin0;
384 tin[1]=tin1;
385 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
386 tout0=tin[0];
387 tout1=tin[1];
388
389 tout0^=xor0;
390 tout1^=xor1;
391 l2cn(tout0,tout1,out,l+8);
392 xor0=t0;
393 xor1=t1;
394 }
395
396 iv = &(*ivec)[0];
397 l2c(xor0,iv);
398 l2c(xor1,iv);
399 }
400 tin0=tin1=tout0=tout1=xor0=xor1=0;
401 tin[0]=tin[1]=0;
402 }
403
404#endif /* DES_DEFAULT_OPTIONS */
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
deleted file mode 100644
index a3b512e9b0..0000000000
--- a/src/lib/libcrypto/des/des_locl.h
+++ /dev/null
@@ -1,432 +0,0 @@
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)
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
429#ifdef OPENSSL_SMALL_FOOTPRINT
430#undef DES_UNROLL
431#endif
432#endif
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c
deleted file mode 100644
index c3437bc606..0000000000
--- a/src/lib/libcrypto/des/ecb3_enc.c
+++ /dev/null
@@ -1,83 +0,0 @@
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
deleted file mode 100644
index 0684e769b3..0000000000
--- a/src/lib/libcrypto/des/ecb_enc.c
+++ /dev/null
@@ -1,122 +0,0 @@
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 <openssl/opensslv.h>
62#include <openssl/bio.h>
63
64OPENSSL_GLOBAL const char libdes_version[]="libdes" OPENSSL_VERSION_PTEXT;
65OPENSSL_GLOBAL const char DES_version[]="DES" OPENSSL_VERSION_PTEXT;
66
67const char *DES_options(void)
68 {
69 static int init=1;
70 static char buf[32];
71
72 if (init)
73 {
74 const char *ptr,*unroll,*risc,*size;
75
76#ifdef DES_PTR
77 ptr="ptr";
78#else
79 ptr="idx";
80#endif
81#if defined(DES_RISC1) || defined(DES_RISC2)
82#ifdef DES_RISC1
83 risc="risc1";
84#endif
85#ifdef DES_RISC2
86 risc="risc2";
87#endif
88#else
89 risc="cisc";
90#endif
91#ifdef DES_UNROLL
92 unroll="16";
93#else
94 unroll="2";
95#endif
96 if (sizeof(DES_LONG) != sizeof(long))
97 size="int";
98 else
99 size="long";
100 BIO_snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,
101 size);
102 init=0;
103 }
104 return(buf);
105 }
106
107
108void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
109 DES_key_schedule *ks, int enc)
110 {
111 register DES_LONG l;
112 DES_LONG ll[2];
113 const unsigned char *in = &(*input)[0];
114 unsigned char *out = &(*output)[0];
115
116 c2l(in,l); ll[0]=l;
117 c2l(in,l); ll[1]=l;
118 DES_encrypt1(ll,ks,enc);
119 l=ll[0]; l2c(l,out);
120 l=ll[1]; l2c(l,out);
121 l=ll[0]=ll[1]=0;
122 }
diff --git a/src/lib/libcrypto/des/ede_cbcm_enc.c b/src/lib/libcrypto/des/ede_cbcm_enc.c
deleted file mode 100644
index adfcb75cf3..0000000000
--- a/src/lib/libcrypto/des/ede_cbcm_enc.c
+++ /dev/null
@@ -1,199 +0,0 @@
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
deleted file mode 100644
index edb6620d08..0000000000
--- a/src/lib/libcrypto/des/enc_read.c
+++ /dev/null
@@ -1,240 +0,0 @@
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#if defined(OPENSSL_NO_POSIX_IO)
91 return(0);
92#else
93 /* data to be unencrypted */
94 int net_num=0;
95 static unsigned char *net=NULL;
96 /* extra unencrypted data
97 * for when a block of 100 comes in but is des_read one byte at
98 * a time. */
99 static unsigned char *unnet=NULL;
100 static int unnet_start=0;
101 static int unnet_left=0;
102 static unsigned char *tmpbuf=NULL;
103 int i;
104 long num=0,rnum;
105 unsigned char *p;
106
107 if (tmpbuf == NULL)
108 {
109 tmpbuf=OPENSSL_malloc(BSIZE);
110 if (tmpbuf == NULL) return(-1);
111 }
112 if (net == NULL)
113 {
114 net=OPENSSL_malloc(BSIZE);
115 if (net == NULL) return(-1);
116 }
117 if (unnet == NULL)
118 {
119 unnet=OPENSSL_malloc(BSIZE);
120 if (unnet == NULL) return(-1);
121 }
122 /* left over data from last decrypt */
123 if (unnet_left != 0)
124 {
125 if (unnet_left < len)
126 {
127 /* we still still need more data but will return
128 * with the number of bytes we have - should always
129 * check the return value */
130 memcpy(buf,&(unnet[unnet_start]),
131 unnet_left);
132 /* eay 26/08/92 I had the next 2 lines
133 * reversed :-( */
134 i=unnet_left;
135 unnet_start=unnet_left=0;
136 }
137 else
138 {
139 memcpy(buf,&(unnet[unnet_start]),len);
140 unnet_start+=len;
141 unnet_left-=len;
142 i=len;
143 }
144 return(i);
145 }
146
147 /* We need to get more data. */
148 if (len > MAXWRITE) len=MAXWRITE;
149
150 /* first - get the length */
151 while (net_num < HDRSIZE)
152 {
153#ifndef OPENSSL_SYS_WIN32
154 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
155#else
156 i=_read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
157#endif
158#ifdef EINTR
159 if ((i == -1) && (errno == EINTR)) continue;
160#endif
161 if (i <= 0) return(0);
162 net_num+=i;
163 }
164
165 /* we now have at net_num bytes in net */
166 p=net;
167 /* num=0; */
168 n2l(p,num);
169 /* num should be rounded up to the next group of eight
170 * we make sure that we have read a multiple of 8 bytes from the net.
171 */
172 if ((num > MAXWRITE) || (num < 0)) /* error */
173 return(-1);
174 rnum=(num < 8)?8:((num+7)/8*8);
175
176 net_num=0;
177 while (net_num < rnum)
178 {
179#ifndef OPENSSL_SYS_WIN32
180 i=read(fd,(void *)&(net[net_num]),rnum-net_num);
181#else
182 i=_read(fd,(void *)&(net[net_num]),rnum-net_num);
183#endif
184#ifdef EINTR
185 if ((i == -1) && (errno == EINTR)) continue;
186#endif
187 if (i <= 0) return(0);
188 net_num+=i;
189 }
190
191 /* Check if there will be data left over. */
192 if (len < num)
193 {
194 if (DES_rw_mode & DES_PCBC_MODE)
195 DES_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
196 else
197 DES_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
198 memcpy(buf,unnet,len);
199 unnet_start=len;
200 unnet_left=num-len;
201
202 /* The following line is done because we return num
203 * as the number of bytes read. */
204 num=len;
205 }
206 else
207 {
208 /* >output is a multiple of 8 byes, if len < rnum
209 * >we must be careful. The user must be aware that this
210 * >routine will write more bytes than he asked for.
211 * >The length of the buffer must be correct.
212 * FIXED - Should be ok now 18-9-90 - eay */
213 if (len < rnum)
214 {
215
216 if (DES_rw_mode & DES_PCBC_MODE)
217 DES_pcbc_encrypt(net,tmpbuf,num,sched,iv,
218 DES_DECRYPT);
219 else
220 DES_cbc_encrypt(net,tmpbuf,num,sched,iv,
221 DES_DECRYPT);
222
223 /* eay 26/08/92 fix a bug that returned more
224 * bytes than you asked for (returned len bytes :-( */
225 memcpy(buf,tmpbuf,num);
226 }
227 else
228 {
229 if (DES_rw_mode & DES_PCBC_MODE)
230 DES_pcbc_encrypt(net,buf,num,sched,iv,
231 DES_DECRYPT);
232 else
233 DES_cbc_encrypt(net,buf,num,sched,iv,
234 DES_DECRYPT);
235 }
236 }
237 return num;
238#endif /* OPENSSL_NO_POSIX_IO */
239 }
240
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
deleted file mode 100644
index 2353ac1e89..0000000000
--- a/src/lib/libcrypto/des/enc_writ.c
+++ /dev/null
@@ -1,179 +0,0 @@
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#if defined(OPENSSL_NO_POSIX_IO)
84 return (-1);
85#else
86#ifdef _LIBC
87 extern unsigned long time();
88 extern int write();
89#endif
90 const unsigned char *buf=_buf;
91 long rnum;
92 int i,j,k,outnum;
93 static unsigned char *outbuf=NULL;
94 unsigned char shortbuf[8];
95 unsigned char *p;
96 const unsigned char *cp;
97 static int start=1;
98
99 if (outbuf == NULL)
100 {
101 outbuf=OPENSSL_malloc(BSIZE+HDRSIZE);
102 if (outbuf == NULL) return(-1);
103 }
104 /* If we are sending less than 8 bytes, the same char will look
105 * the same if we don't pad it out with random bytes */
106 if (start)
107 {
108 start=0;
109 }
110
111 /* lets recurse if we want to send the data in small chunks */
112 if (len > MAXWRITE)
113 {
114 j=0;
115 for (i=0; i<len; i+=k)
116 {
117 k=DES_enc_write(fd,&(buf[i]),
118 ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv);
119 if (k < 0)
120 return(k);
121 else
122 j+=k;
123 }
124 return(j);
125 }
126
127 /* write length first */
128 p=outbuf;
129 l2n(len,p);
130
131 /* pad short strings */
132 if (len < 8)
133 {
134 cp=shortbuf;
135 memcpy(shortbuf,buf,len);
136 RAND_pseudo_bytes(shortbuf+len, 8-len);
137 rnum=8;
138 }
139 else
140 {
141 cp=buf;
142 rnum=((len+7)/8*8); /* round up to nearest eight */
143 }
144
145 if (DES_rw_mode & DES_PCBC_MODE)
146 DES_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
147 DES_ENCRYPT);
148 else
149 DES_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
150 DES_ENCRYPT);
151
152 /* output */
153 outnum=rnum+HDRSIZE;
154
155 for (j=0; j<outnum; j+=i)
156 {
157 /* eay 26/08/92 I was not doing writing from where we
158 * got up to. */
159#ifndef _WIN32
160 i=write(fd,(void *)&(outbuf[j]),outnum-j);
161#else
162 i=_write(fd,(void *)&(outbuf[j]),outnum-j);
163#endif
164 if (i == -1)
165 {
166#ifdef EINTR
167 if (errno == EINTR)
168 i=0;
169 else
170#endif
171 /* This is really a bad error - very bad
172 * It will stuff-up both ends. */
173 return(-1);
174 }
175 }
176
177 return(len);
178#endif /* OPENSSL_NO_POSIX_IO */
179 }
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
deleted file mode 100644
index ccbdff250f..0000000000
--- a/src/lib/libcrypto/des/fcrypt.c
+++ /dev/null
@@ -1,170 +0,0 @@
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
deleted file mode 100644
index 87fc71eb26..0000000000
--- a/src/lib/libcrypto/des/fcrypt_b.c
+++ /dev/null
@@ -1,146 +0,0 @@
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+=4)
106 {
107 D_ENCRYPT(l,r,i+0); /* 1 */
108 D_ENCRYPT(r,l,i+2); /* 2 */
109 }
110#else
111 D_ENCRYPT(l,r, 0); /* 1 */
112 D_ENCRYPT(r,l, 2); /* 2 */
113 D_ENCRYPT(l,r, 4); /* 3 */
114 D_ENCRYPT(r,l, 6); /* 4 */
115 D_ENCRYPT(l,r, 8); /* 5 */
116 D_ENCRYPT(r,l,10); /* 6 */
117 D_ENCRYPT(l,r,12); /* 7 */
118 D_ENCRYPT(r,l,14); /* 8 */
119 D_ENCRYPT(l,r,16); /* 9 */
120 D_ENCRYPT(r,l,18); /* 10 */
121 D_ENCRYPT(l,r,20); /* 11 */
122 D_ENCRYPT(r,l,22); /* 12 */
123 D_ENCRYPT(l,r,24); /* 13 */
124 D_ENCRYPT(r,l,26); /* 14 */
125 D_ENCRYPT(l,r,28); /* 15 */
126 D_ENCRYPT(r,l,30); /* 16 */
127#endif
128
129 t=l;
130 l=r;
131 r=t;
132 }
133 l=ROTATE(l,3)&0xffffffffL;
134 r=ROTATE(r,3)&0xffffffffL;
135
136 PERM_OP(l,r,t, 1,0x55555555L);
137 PERM_OP(r,l,t, 8,0x00ff00ffL);
138 PERM_OP(l,r,t, 2,0x33333333L);
139 PERM_OP(r,l,t,16,0x0000ffffL);
140 PERM_OP(l,r,t, 4,0x0f0f0f0fL);
141
142 out[0]=r;
143 out[1]=l;
144 }
145
146#endif /* OPENBSD_DES_ASM */
diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c
deleted file mode 100644
index fda23d522f..0000000000
--- a/src/lib/libcrypto/des/ncbc_enc.c
+++ /dev/null
@@ -1,148 +0,0 @@
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
deleted file mode 100644
index 26bbf9a6a7..0000000000
--- a/src/lib/libcrypto/des/ofb64ede.c
+++ /dev/null
@@ -1,125 +0,0 @@
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
deleted file mode 100644
index 8ca3d49dea..0000000000
--- a/src/lib/libcrypto/des/ofb64enc.c
+++ /dev/null
@@ -1,110 +0,0 @@
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
deleted file mode 100644
index e887a3c6f4..0000000000
--- a/src/lib/libcrypto/des/ofb_enc.c
+++ /dev/null
@@ -1,135 +0,0 @@
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/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c
deleted file mode 100644
index 17a40f9520..0000000000
--- a/src/lib/libcrypto/des/pcbc_enc.c
+++ /dev/null
@@ -1,123 +0,0 @@
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
deleted file mode 100644
index dac201227e..0000000000
--- a/src/lib/libcrypto/des/qud_cksm.c
+++ /dev/null
@@ -1,139 +0,0 @@
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
deleted file mode 100644
index 2398165568..0000000000
--- a/src/lib/libcrypto/des/rand_key.c
+++ /dev/null
@@ -1,68 +0,0 @@
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/set_key.c b/src/lib/libcrypto/des/set_key.c
deleted file mode 100644
index d3e69ca8b5..0000000000
--- a/src/lib/libcrypto/des/set_key.c
+++ /dev/null
@@ -1,416 +0,0 @@
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
68#include <openssl/crypto.h>
69
70OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key,0) /* defaults to false */
71
72static const unsigned char odd_parity[256]={
73 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
74 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
75 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
76 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
77 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
78 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
79 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
80112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
81128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
82145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
83161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
84176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
85193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
86208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
87224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
88241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254};
89
90void DES_set_odd_parity(DES_cblock *key)
91 {
92 unsigned int i;
93
94 for (i=0; i<DES_KEY_SZ; i++)
95 (*key)[i]=odd_parity[(*key)[i]];
96 }
97
98int DES_check_key_parity(const_DES_cblock *key)
99 {
100 unsigned int i;
101
102 for (i=0; i<DES_KEY_SZ; i++)
103 {
104 if ((*key)[i] != odd_parity[(*key)[i]])
105 return(0);
106 }
107 return(1);
108 }
109
110/* Weak and semi week keys as take from
111 * %A D.W. Davies
112 * %A W.L. Price
113 * %T Security for Computer Networks
114 * %I John Wiley & Sons
115 * %D 1984
116 * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
117 * (and actual cblock values).
118 */
119#define NUM_WEAK_KEY 16
120static const DES_cblock weak_keys[NUM_WEAK_KEY]={
121 /* weak keys */
122 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
123 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
124 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
125 {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
126 /* semi-weak keys */
127 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
128 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
129 {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
130 {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
131 {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
132 {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
133 {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
134 {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
135 {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
136 {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
137 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
138 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
139
140int DES_is_weak_key(const_DES_cblock *key)
141 {
142 int i;
143
144 for (i=0; i<NUM_WEAK_KEY; i++)
145 /* Added == 0 to comparison, I obviously don't run
146 * this section very often :-(, thanks to
147 * engineering@MorningStar.Com for the fix
148 * eay 93/06/29
149 * Another problem, I was comparing only the first 4
150 * bytes, 97/03/18 */
151 if (memcmp(weak_keys[i],key,sizeof(DES_cblock)) == 0) return(1);
152 return(0);
153 }
154
155/* NOW DEFINED IN des_local.h
156 * See ecb_encrypt.c for a pseudo description of these macros.
157 * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
158 * (b)^=(t),\
159 * (a)=((a)^((t)<<(n))))
160 */
161
162#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
163 (a)=(a)^(t)^(t>>(16-(n))))
164
165static const DES_LONG des_skb[8][64]={
166 {
167 /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
168 0x00000000L,0x00000010L,0x20000000L,0x20000010L,
169 0x00010000L,0x00010010L,0x20010000L,0x20010010L,
170 0x00000800L,0x00000810L,0x20000800L,0x20000810L,
171 0x00010800L,0x00010810L,0x20010800L,0x20010810L,
172 0x00000020L,0x00000030L,0x20000020L,0x20000030L,
173 0x00010020L,0x00010030L,0x20010020L,0x20010030L,
174 0x00000820L,0x00000830L,0x20000820L,0x20000830L,
175 0x00010820L,0x00010830L,0x20010820L,0x20010830L,
176 0x00080000L,0x00080010L,0x20080000L,0x20080010L,
177 0x00090000L,0x00090010L,0x20090000L,0x20090010L,
178 0x00080800L,0x00080810L,0x20080800L,0x20080810L,
179 0x00090800L,0x00090810L,0x20090800L,0x20090810L,
180 0x00080020L,0x00080030L,0x20080020L,0x20080030L,
181 0x00090020L,0x00090030L,0x20090020L,0x20090030L,
182 0x00080820L,0x00080830L,0x20080820L,0x20080830L,
183 0x00090820L,0x00090830L,0x20090820L,0x20090830L,
184 },{
185 /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
186 0x00000000L,0x02000000L,0x00002000L,0x02002000L,
187 0x00200000L,0x02200000L,0x00202000L,0x02202000L,
188 0x00000004L,0x02000004L,0x00002004L,0x02002004L,
189 0x00200004L,0x02200004L,0x00202004L,0x02202004L,
190 0x00000400L,0x02000400L,0x00002400L,0x02002400L,
191 0x00200400L,0x02200400L,0x00202400L,0x02202400L,
192 0x00000404L,0x02000404L,0x00002404L,0x02002404L,
193 0x00200404L,0x02200404L,0x00202404L,0x02202404L,
194 0x10000000L,0x12000000L,0x10002000L,0x12002000L,
195 0x10200000L,0x12200000L,0x10202000L,0x12202000L,
196 0x10000004L,0x12000004L,0x10002004L,0x12002004L,
197 0x10200004L,0x12200004L,0x10202004L,0x12202004L,
198 0x10000400L,0x12000400L,0x10002400L,0x12002400L,
199 0x10200400L,0x12200400L,0x10202400L,0x12202400L,
200 0x10000404L,0x12000404L,0x10002404L,0x12002404L,
201 0x10200404L,0x12200404L,0x10202404L,0x12202404L,
202 },{
203 /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
204 0x00000000L,0x00000001L,0x00040000L,0x00040001L,
205 0x01000000L,0x01000001L,0x01040000L,0x01040001L,
206 0x00000002L,0x00000003L,0x00040002L,0x00040003L,
207 0x01000002L,0x01000003L,0x01040002L,0x01040003L,
208 0x00000200L,0x00000201L,0x00040200L,0x00040201L,
209 0x01000200L,0x01000201L,0x01040200L,0x01040201L,
210 0x00000202L,0x00000203L,0x00040202L,0x00040203L,
211 0x01000202L,0x01000203L,0x01040202L,0x01040203L,
212 0x08000000L,0x08000001L,0x08040000L,0x08040001L,
213 0x09000000L,0x09000001L,0x09040000L,0x09040001L,
214 0x08000002L,0x08000003L,0x08040002L,0x08040003L,
215 0x09000002L,0x09000003L,0x09040002L,0x09040003L,
216 0x08000200L,0x08000201L,0x08040200L,0x08040201L,
217 0x09000200L,0x09000201L,0x09040200L,0x09040201L,
218 0x08000202L,0x08000203L,0x08040202L,0x08040203L,
219 0x09000202L,0x09000203L,0x09040202L,0x09040203L,
220 },{
221 /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
222 0x00000000L,0x00100000L,0x00000100L,0x00100100L,
223 0x00000008L,0x00100008L,0x00000108L,0x00100108L,
224 0x00001000L,0x00101000L,0x00001100L,0x00101100L,
225 0x00001008L,0x00101008L,0x00001108L,0x00101108L,
226 0x04000000L,0x04100000L,0x04000100L,0x04100100L,
227 0x04000008L,0x04100008L,0x04000108L,0x04100108L,
228 0x04001000L,0x04101000L,0x04001100L,0x04101100L,
229 0x04001008L,0x04101008L,0x04001108L,0x04101108L,
230 0x00020000L,0x00120000L,0x00020100L,0x00120100L,
231 0x00020008L,0x00120008L,0x00020108L,0x00120108L,
232 0x00021000L,0x00121000L,0x00021100L,0x00121100L,
233 0x00021008L,0x00121008L,0x00021108L,0x00121108L,
234 0x04020000L,0x04120000L,0x04020100L,0x04120100L,
235 0x04020008L,0x04120008L,0x04020108L,0x04120108L,
236 0x04021000L,0x04121000L,0x04021100L,0x04121100L,
237 0x04021008L,0x04121008L,0x04021108L,0x04121108L,
238 },{
239 /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
240 0x00000000L,0x10000000L,0x00010000L,0x10010000L,
241 0x00000004L,0x10000004L,0x00010004L,0x10010004L,
242 0x20000000L,0x30000000L,0x20010000L,0x30010000L,
243 0x20000004L,0x30000004L,0x20010004L,0x30010004L,
244 0x00100000L,0x10100000L,0x00110000L,0x10110000L,
245 0x00100004L,0x10100004L,0x00110004L,0x10110004L,
246 0x20100000L,0x30100000L,0x20110000L,0x30110000L,
247 0x20100004L,0x30100004L,0x20110004L,0x30110004L,
248 0x00001000L,0x10001000L,0x00011000L,0x10011000L,
249 0x00001004L,0x10001004L,0x00011004L,0x10011004L,
250 0x20001000L,0x30001000L,0x20011000L,0x30011000L,
251 0x20001004L,0x30001004L,0x20011004L,0x30011004L,
252 0x00101000L,0x10101000L,0x00111000L,0x10111000L,
253 0x00101004L,0x10101004L,0x00111004L,0x10111004L,
254 0x20101000L,0x30101000L,0x20111000L,0x30111000L,
255 0x20101004L,0x30101004L,0x20111004L,0x30111004L,
256 },{
257 /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
258 0x00000000L,0x08000000L,0x00000008L,0x08000008L,
259 0x00000400L,0x08000400L,0x00000408L,0x08000408L,
260 0x00020000L,0x08020000L,0x00020008L,0x08020008L,
261 0x00020400L,0x08020400L,0x00020408L,0x08020408L,
262 0x00000001L,0x08000001L,0x00000009L,0x08000009L,
263 0x00000401L,0x08000401L,0x00000409L,0x08000409L,
264 0x00020001L,0x08020001L,0x00020009L,0x08020009L,
265 0x00020401L,0x08020401L,0x00020409L,0x08020409L,
266 0x02000000L,0x0A000000L,0x02000008L,0x0A000008L,
267 0x02000400L,0x0A000400L,0x02000408L,0x0A000408L,
268 0x02020000L,0x0A020000L,0x02020008L,0x0A020008L,
269 0x02020400L,0x0A020400L,0x02020408L,0x0A020408L,
270 0x02000001L,0x0A000001L,0x02000009L,0x0A000009L,
271 0x02000401L,0x0A000401L,0x02000409L,0x0A000409L,
272 0x02020001L,0x0A020001L,0x02020009L,0x0A020009L,
273 0x02020401L,0x0A020401L,0x02020409L,0x0A020409L,
274 },{
275 /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
276 0x00000000L,0x00000100L,0x00080000L,0x00080100L,
277 0x01000000L,0x01000100L,0x01080000L,0x01080100L,
278 0x00000010L,0x00000110L,0x00080010L,0x00080110L,
279 0x01000010L,0x01000110L,0x01080010L,0x01080110L,
280 0x00200000L,0x00200100L,0x00280000L,0x00280100L,
281 0x01200000L,0x01200100L,0x01280000L,0x01280100L,
282 0x00200010L,0x00200110L,0x00280010L,0x00280110L,
283 0x01200010L,0x01200110L,0x01280010L,0x01280110L,
284 0x00000200L,0x00000300L,0x00080200L,0x00080300L,
285 0x01000200L,0x01000300L,0x01080200L,0x01080300L,
286 0x00000210L,0x00000310L,0x00080210L,0x00080310L,
287 0x01000210L,0x01000310L,0x01080210L,0x01080310L,
288 0x00200200L,0x00200300L,0x00280200L,0x00280300L,
289 0x01200200L,0x01200300L,0x01280200L,0x01280300L,
290 0x00200210L,0x00200310L,0x00280210L,0x00280310L,
291 0x01200210L,0x01200310L,0x01280210L,0x01280310L,
292 },{
293 /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
294 0x00000000L,0x04000000L,0x00040000L,0x04040000L,
295 0x00000002L,0x04000002L,0x00040002L,0x04040002L,
296 0x00002000L,0x04002000L,0x00042000L,0x04042000L,
297 0x00002002L,0x04002002L,0x00042002L,0x04042002L,
298 0x00000020L,0x04000020L,0x00040020L,0x04040020L,
299 0x00000022L,0x04000022L,0x00040022L,0x04040022L,
300 0x00002020L,0x04002020L,0x00042020L,0x04042020L,
301 0x00002022L,0x04002022L,0x00042022L,0x04042022L,
302 0x00000800L,0x04000800L,0x00040800L,0x04040800L,
303 0x00000802L,0x04000802L,0x00040802L,0x04040802L,
304 0x00002800L,0x04002800L,0x00042800L,0x04042800L,
305 0x00002802L,0x04002802L,0x00042802L,0x04042802L,
306 0x00000820L,0x04000820L,0x00040820L,0x04040820L,
307 0x00000822L,0x04000822L,0x00040822L,0x04040822L,
308 0x00002820L,0x04002820L,0x00042820L,0x04042820L,
309 0x00002822L,0x04002822L,0x00042822L,0x04042822L,
310 }};
311
312int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule)
313 {
314 if (DES_check_key)
315 {
316 return DES_set_key_checked(key, schedule);
317 }
318 else
319 {
320 DES_set_key_unchecked(key, schedule);
321 return 0;
322 }
323 }
324
325/* return 0 if key parity is odd (correct),
326 * return -1 if key parity error,
327 * return -2 if illegal weak key.
328 */
329int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule)
330 {
331 if (!DES_check_key_parity(key))
332 return(-1);
333 if (DES_is_weak_key(key))
334 return(-2);
335 DES_set_key_unchecked(key, schedule);
336 return 0;
337 }
338
339void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
340#ifdef OPENSSL_FIPS
341 {
342 fips_cipher_abort(DES);
343 private_DES_set_key_unchecked(key, schedule);
344 }
345void private_DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
346#endif
347 {
348 static const int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
349 register DES_LONG c,d,t,s,t2;
350 register const unsigned char *in;
351 register DES_LONG *k;
352 register int i;
353
354#ifdef OPENBSD_DEV_CRYPTO
355 memcpy(schedule->key,key,sizeof schedule->key);
356 schedule->session=NULL;
357#endif
358 k = &schedule->ks->deslong[0];
359 in = &(*key)[0];
360
361 c2l(in,c);
362 c2l(in,d);
363
364 /* do PC1 in 47 simple operations :-)
365 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
366 * for the inspiration. :-) */
367 PERM_OP (d,c,t,4,0x0f0f0f0fL);
368 HPERM_OP(c,t,-2,0xcccc0000L);
369 HPERM_OP(d,t,-2,0xcccc0000L);
370 PERM_OP (d,c,t,1,0x55555555L);
371 PERM_OP (c,d,t,8,0x00ff00ffL);
372 PERM_OP (d,c,t,1,0x55555555L);
373 d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) |
374 ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
375 c&=0x0fffffffL;
376
377 for (i=0; i<ITERATIONS; i++)
378 {
379 if (shifts2[i])
380 { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
381 else
382 { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); }
383 c&=0x0fffffffL;
384 d&=0x0fffffffL;
385 /* could be a few less shifts but I am to lazy at this
386 * point in time to investigate */
387 s= des_skb[0][ (c )&0x3f ]|
388 des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
389 des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
390 des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
391 ((c>>22L)&0x38)];
392 t= des_skb[4][ (d )&0x3f ]|
393 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
394 des_skb[6][ (d>>15L)&0x3f ]|
395 des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
396
397 /* table contained 0213 4657 */
398 t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
399 *(k++)=ROTATE(t2,30)&0xffffffffL;
400
401 t2=((s>>16L)|(t&0xffff0000L));
402 *(k++)=ROTATE(t2,26)&0xffffffffL;
403 }
404 }
405
406int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule)
407 {
408 return(DES_set_key(key,schedule));
409 }
410/*
411#undef des_fixup_key_parity
412void des_fixup_key_parity(des_cblock *key)
413 {
414 des_set_odd_parity(key);
415 }
416*/
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h
deleted file mode 100644
index b91936a5a5..0000000000
--- a/src/lib/libcrypto/des/spr.h
+++ /dev/null
@@ -1,204 +0,0 @@
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
deleted file mode 100644
index 9c2054bda6..0000000000
--- a/src/lib/libcrypto/des/str2key.c
+++ /dev/null
@@ -1,174 +0,0 @@
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/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c
deleted file mode 100644
index 058cab6bce..0000000000
--- a/src/lib/libcrypto/des/xcbc_enc.c
+++ /dev/null
@@ -1,197 +0,0 @@
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 const 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