summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/des')
-rw-r--r--src/lib/libcrypto/des/COPYRIGHT50
-rw-r--r--src/lib/libcrypto/des/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.c244
-rw-r--r--src/lib/libcrypto/des/cfb64enc.c121
-rw-r--r--src/lib/libcrypto/des/cfb_enc.c189
-rw-r--r--src/lib/libcrypto/des/des.h219
-rw-r--r--src/lib/libcrypto/des/des_enc.c404
-rw-r--r--src/lib/libcrypto/des/des_locl.h392
-rw-r--r--src/lib/libcrypto/des/ecb3_enc.c83
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c118
-rw-r--r--src/lib/libcrypto/des/ede_cbcm_enc.c199
-rw-r--r--src/lib/libcrypto/des/enc_read.c229
-rw-r--r--src/lib/libcrypto/des/enc_writ.c173
-rw-r--r--src/lib/libcrypto/des/fcrypt.c125
-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.c114
-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.c125
-rw-r--r--src/lib/libcrypto/des/rand_key.c68
-rw-r--r--src/lib/libcrypto/des/set_key.c400
-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.c148
31 files changed, 0 insertions, 7448 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 20553ef09f..0000000000
--- a/src/lib/libcrypto/des/cbc_cksm.c
+++ /dev/null
@@ -1,106 +0,0 @@
1/* $OpenBSD: cbc_cksm.c,v 1.7 2014/10/28 07:35:58 jsg Exp $ */
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 DES_LONG tout0,tout1,tin0,tin1;
66 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 5db52809c0..0000000000
--- a/src/lib/libcrypto/des/cbc_enc.c
+++ /dev/null
@@ -1,61 +0,0 @@
1/* $OpenBSD: cbc_enc.c,v 1.3 2014/06/12 15:49:28 deraadt Exp $ */
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 6d4d287775..0000000000
--- a/src/lib/libcrypto/des/cfb64ede.c
+++ /dev/null
@@ -1,244 +0,0 @@
1/* $OpenBSD: cfb64ede.c,v 1.9 2015/02/07 13:19:15 doug Exp $ */
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_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
67 long length, DES_key_schedule *ks1,
68 DES_key_schedule *ks2, DES_key_schedule *ks3,
69 DES_cblock *ivec, int *num, int enc)
70 {
71 DES_LONG v0,v1;
72 long l=length;
73 int n= *num;
74 DES_LONG ti[2];
75 unsigned char *iv,c,cc;
76
77 iv=&(*ivec)[0];
78 if (enc)
79 {
80 while (l--)
81 {
82 if (n == 0)
83 {
84 c2l(iv,v0);
85 c2l(iv,v1);
86
87 ti[0]=v0;
88 ti[1]=v1;
89 DES_encrypt3(ti,ks1,ks2,ks3);
90 v0=ti[0];
91 v1=ti[1];
92
93 iv = &(*ivec)[0];
94 l2c(v0,iv);
95 l2c(v1,iv);
96 iv = &(*ivec)[0];
97 }
98 c= *(in++)^iv[n];
99 *(out++)=c;
100 iv[n]=c;
101 n=(n+1)&0x07;
102 }
103 }
104 else
105 {
106 while (l--)
107 {
108 if (n == 0)
109 {
110 c2l(iv,v0);
111 c2l(iv,v1);
112
113 ti[0]=v0;
114 ti[1]=v1;
115 DES_encrypt3(ti,ks1,ks2,ks3);
116 v0=ti[0];
117 v1=ti[1];
118
119 iv = &(*ivec)[0];
120 l2c(v0,iv);
121 l2c(v1,iv);
122 iv = &(*ivec)[0];
123 }
124 cc= *(in++);
125 c=iv[n];
126 iv[n]=cc;
127 *(out++)=c^cc;
128 n=(n+1)&0x07;
129 }
130 }
131 v0=v1=ti[0]=ti[1]=c=cc=0;
132 *num=n;
133 }
134
135/* This is compatible with the single key CFB-r for DES, even thought that's
136 * not what EVP needs.
137 */
138
139void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
140 int numbits,long length,DES_key_schedule *ks1,
141 DES_key_schedule *ks2,DES_key_schedule *ks3,
142 DES_cblock *ivec,int enc)
143 {
144 DES_LONG d0,d1,v0,v1;
145 unsigned long l=length,n=((unsigned int)numbits+7)/8;
146 int num=numbits,i;
147 DES_LONG ti[2];
148 unsigned char *iv;
149 unsigned char ovec[16];
150
151 if (num > 64) return;
152 iv = &(*ivec)[0];
153 c2l(iv,v0);
154 c2l(iv,v1);
155 if (enc)
156 {
157 while (l >= n)
158 {
159 l-=n;
160 ti[0]=v0;
161 ti[1]=v1;
162 DES_encrypt3(ti,ks1,ks2,ks3);
163 c2ln(in,d0,d1,n);
164 in+=n;
165 d0^=ti[0];
166 d1^=ti[1];
167 l2cn(d0,d1,out,n);
168 out+=n;
169 /* 30-08-94 - eay - changed because l>>32 and
170 * l<<32 are bad under gcc :-( */
171 if (num == 32)
172 { v0=v1; v1=d0; }
173 else if (num == 64)
174 { v0=d0; v1=d1; }
175 else
176 {
177 iv=&ovec[0];
178 l2c(v0,iv);
179 l2c(v1,iv);
180 l2c(d0,iv);
181 l2c(d1,iv);
182 /* shift ovec left most of the bits... */
183 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
184 /* now the remaining bits */
185 if(num%8 != 0)
186 for(i=0 ; i < 8 ; ++i)
187 {
188 ovec[i]<<=num%8;
189 ovec[i]|=ovec[i+1]>>(8-num%8);
190 }
191 iv=&ovec[0];
192 c2l(iv,v0);
193 c2l(iv,v1);
194 }
195 }
196 }
197 else
198 {
199 while (l >= n)
200 {
201 l-=n;
202 ti[0]=v0;
203 ti[1]=v1;
204 DES_encrypt3(ti,ks1,ks2,ks3);
205 c2ln(in,d0,d1,n);
206 in+=n;
207 /* 30-08-94 - eay - changed because l>>32 and
208 * l<<32 are bad under gcc :-( */
209 if (num == 32)
210 { v0=v1; v1=d0; }
211 else if (num == 64)
212 { v0=d0; v1=d1; }
213 else
214 {
215 iv=&ovec[0];
216 l2c(v0,iv);
217 l2c(v1,iv);
218 l2c(d0,iv);
219 l2c(d1,iv);
220 /* shift ovec left most of the bits... */
221 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
222 /* now the remaining bits */
223 if(num%8 != 0)
224 for(i=0 ; i < 8 ; ++i)
225 {
226 ovec[i]<<=num%8;
227 ovec[i]|=ovec[i+1]>>(8-num%8);
228 }
229 iv=&ovec[0];
230 c2l(iv,v0);
231 c2l(iv,v1);
232 }
233 d0^=ti[0];
234 d1^=ti[1];
235 l2cn(d0,d1,out,n);
236 out+=n;
237 }
238 }
239 iv = &(*ivec)[0];
240 l2c(v0,iv);
241 l2c(v1,iv);
242 v0=v1=d0=d1=ti[0]=ti[1]=0;
243 }
244
diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c
deleted file mode 100644
index 6c8f99e841..0000000000
--- a/src/lib/libcrypto/des/cfb64enc.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/* $OpenBSD: cfb64enc.c,v 1.6 2014/10/28 07:35:58 jsg Exp $ */
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 DES_LONG v0,v1;
71 long l=length;
72 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 59a3e71862..0000000000
--- a/src/lib/libcrypto/des/cfb_enc.c
+++ /dev/null
@@ -1,189 +0,0 @@
1/* $OpenBSD: cfb_enc.c,v 1.13 2015/02/10 09:46:30 miod Exp $ */
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 <machine/endian.h>
61
62/* The input and output are loaded in multiples of 8 bits.
63 * What this means is that if you hame numbits=12 and length=2
64 * the first 12 bits will be retrieved from the first byte and half
65 * the second. The second 12 bits will come from the 3rd and half the 4th
66 * byte.
67 */
68/* Until Aug 1 2003 this function did not correctly implement CFB-r, so it
69 * will not be compatible with any encryption prior to that date. Ben. */
70void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
71 long length, DES_key_schedule *schedule, DES_cblock *ivec,
72 int enc)
73 {
74 DES_LONG d0,d1,v0,v1;
75 unsigned long l=length;
76 int num=numbits/8,n=(numbits+7)/8,i,rem=numbits%8;
77 DES_LONG ti[2];
78 unsigned char *iv;
79#if BYTE_ORDER != LITTLE_ENDIAN
80 unsigned char ovec[16];
81#else
82 unsigned int sh[4];
83 unsigned char *ovec=(unsigned char *)sh;
84#endif
85
86 if (numbits<=0 || numbits > 64) return;
87 iv = &(*ivec)[0];
88 c2l(iv,v0);
89 c2l(iv,v1);
90 if (enc)
91 {
92 while (l >= (unsigned long)n)
93 {
94 l-=n;
95 ti[0]=v0;
96 ti[1]=v1;
97 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
98 c2ln(in,d0,d1,n);
99 in+=n;
100 d0^=ti[0];
101 d1^=ti[1];
102 l2cn(d0,d1,out,n);
103 out+=n;
104 /* 30-08-94 - eay - changed because l>>32 and
105 * l<<32 are bad under gcc :-( */
106 if (numbits == 32)
107 { v0=v1; v1=d0; }
108 else if (numbits == 64)
109 { v0=d0; v1=d1; }
110 else
111 {
112#if BYTE_ORDER != LITTLE_ENDIAN
113 iv=&ovec[0];
114 l2c(v0,iv);
115 l2c(v1,iv);
116 l2c(d0,iv);
117 l2c(d1,iv);
118#else
119 sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1;
120#endif
121 if (rem==0)
122 memmove(ovec,ovec+num,8);
123 else
124 for(i=0 ; i < 8 ; ++i)
125 ovec[i]=ovec[i+num]<<rem |
126 ovec[i+num+1]>>(8-rem);
127#if BYTE_ORDER == LITTLE_ENDIAN
128 v0=sh[0], v1=sh[1];
129#else
130 iv=&ovec[0];
131 c2l(iv,v0);
132 c2l(iv,v1);
133#endif
134 }
135 }
136 }
137 else
138 {
139 while (l >= (unsigned long)n)
140 {
141 l-=n;
142 ti[0]=v0;
143 ti[1]=v1;
144 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
145 c2ln(in,d0,d1,n);
146 in+=n;
147 /* 30-08-94 - eay - changed because l>>32 and
148 * l<<32 are bad under gcc :-( */
149 if (numbits == 32)
150 { v0=v1; v1=d0; }
151 else if (numbits == 64)
152 { v0=d0; v1=d1; }
153 else
154 {
155#if BYTE_ORDER != LITTLE_ENDIAN
156 iv=&ovec[0];
157 l2c(v0,iv);
158 l2c(v1,iv);
159 l2c(d0,iv);
160 l2c(d1,iv);
161#else
162 sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1;
163#endif
164 if (rem==0)
165 memmove(ovec,ovec+num,8);
166 else
167 for(i=0 ; i < 8 ; ++i)
168 ovec[i]=ovec[i+num]<<rem |
169 ovec[i+num+1]>>(8-rem);
170#if BYTE_ORDER == LITTLE_ENDIAN
171 v0=sh[0], v1=sh[1];
172#else
173 iv=&ovec[0];
174 c2l(iv,v0);
175 c2l(iv,v1);
176#endif
177 }
178 d0^=ti[0];
179 d1^=ti[1];
180 l2cn(d0,d1,out,n);
181 out+=n;
182 }
183 }
184 iv = &(*ivec)[0];
185 l2c(v0,iv);
186 l2c(v1,iv);
187 v0=v1=d0=d1=ti[0]=ti[1]=0;
188 }
189
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
deleted file mode 100644
index e1331d3fa2..0000000000
--- a/src/lib/libcrypto/des/des.h
+++ /dev/null
@@ -1,219 +0,0 @@
1/* $OpenBSD: des.h,v 1.19 2015/02/07 13:19:15 doug Exp $ */
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_NEW_DES_H
60#define HEADER_NEW_DES_H
61
62#include <openssl/opensslconf.h>
63
64#ifdef OPENSSL_NO_DES
65#error DES is disabled.
66#endif
67
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73typedef unsigned char DES_cblock[8];
74typedef /* const */ unsigned char const_DES_cblock[8];
75/* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock *
76 * and const_DES_cblock * are incompatible pointer types. */
77
78typedef struct DES_ks
79 {
80 union
81 {
82 DES_cblock cblock;
83 /* make sure things are correct size on machines with
84 * 8 byte longs */
85 DES_LONG deslong[2];
86 } ks[16];
87 } DES_key_schedule;
88
89#define DES_KEY_SZ (sizeof(DES_cblock))
90#define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
91
92#define DES_ENCRYPT 1
93#define DES_DECRYPT 0
94
95#define DES_CBC_MODE 0
96#define DES_PCBC_MODE 1
97
98#define DES_ecb2_encrypt(i,o,k1,k2,e) \
99 DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
100
101#define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
102 DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
103
104#define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
105 DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
106
107#define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
108 DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
109
110extern int DES_check_key; /* defaults to false */
111extern int DES_rw_mode; /* defaults to DES_PCBC_MODE */
112
113const char *DES_options(void);
114void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
115 DES_key_schedule *ks1,DES_key_schedule *ks2,
116 DES_key_schedule *ks3, int enc);
117DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output,
118 long length,DES_key_schedule *schedule,
119 const_DES_cblock *ivec);
120/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
121void DES_cbc_encrypt(const unsigned char *input,unsigned char *output,
122 long length,DES_key_schedule *schedule,DES_cblock *ivec,
123 int enc);
124void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output,
125 long length,DES_key_schedule *schedule,DES_cblock *ivec,
126 int enc);
127void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output,
128 long length,DES_key_schedule *schedule,DES_cblock *ivec,
129 const_DES_cblock *inw,const_DES_cblock *outw,int enc);
130void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
131 long length,DES_key_schedule *schedule,DES_cblock *ivec,
132 int enc);
133void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output,
134 DES_key_schedule *ks,int enc);
135
136/* This is the DES encryption function that gets called by just about
137 every other DES routine in the library. You should not use this
138 function except to implement 'modes' of DES. I say this because the
139 functions that call this routine do the conversion from 'char *' to
140 long, and this needs to be done to make sure 'non-aligned' memory
141 access do not occur. The characters are loaded 'little endian'.
142 Data is a pointer to 2 unsigned long's and ks is the
143 DES_key_schedule to use. enc, is non zero specifies encryption,
144 zero if decryption. */
145void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);
146
147/* This functions is the same as DES_encrypt1() except that the DES
148 initial permutation (IP) and final permutation (FP) have been left
149 out. As for DES_encrypt1(), you should not use this function.
150 It is used by the routines in the library that implement triple DES.
151 IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same
152 as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */
153void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc);
154
155void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
156 DES_key_schedule *ks2, DES_key_schedule *ks3);
157void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
158 DES_key_schedule *ks2, DES_key_schedule *ks3);
159void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
160 long length,
161 DES_key_schedule *ks1,DES_key_schedule *ks2,
162 DES_key_schedule *ks3,DES_cblock *ivec,int enc);
163void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
164 long length,
165 DES_key_schedule *ks1,DES_key_schedule *ks2,
166 DES_key_schedule *ks3,
167 DES_cblock *ivec1,DES_cblock *ivec2,
168 int enc);
169void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
170 long length,DES_key_schedule *ks1,
171 DES_key_schedule *ks2,DES_key_schedule *ks3,
172 DES_cblock *ivec,int *num,int enc);
173void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
174 int numbits,long length,DES_key_schedule *ks1,
175 DES_key_schedule *ks2,DES_key_schedule *ks3,
176 DES_cblock *ivec,int enc);
177void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
178 long length,DES_key_schedule *ks1,
179 DES_key_schedule *ks2,DES_key_schedule *ks3,
180 DES_cblock *ivec,int *num);
181int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched,
182 DES_cblock *iv);
183int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched,
184 DES_cblock *iv);
185char *DES_fcrypt(const char *buf,const char *salt, char *ret);
186char *DES_crypt(const char *buf,const char *salt);
187void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
188 long length,DES_key_schedule *schedule,DES_cblock *ivec);
189void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output,
190 long length,DES_key_schedule *schedule,DES_cblock *ivec,
191 int enc);
192DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[],
193 long length,int out_count,DES_cblock *seed);
194int DES_random_key(DES_cblock *ret);
195void DES_set_odd_parity(DES_cblock *key);
196int DES_check_key_parity(const_DES_cblock *key);
197int DES_is_weak_key(const_DES_cblock *key);
198/* DES_set_key (= set_key = DES_key_sched = key_sched) calls
199 * DES_set_key_checked if global variable DES_check_key is set,
200 * DES_set_key_unchecked otherwise. */
201int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule);
202int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule);
203int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule);
204void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule);
205void DES_string_to_key(const char *str,DES_cblock *key);
206void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2);
207void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
208 DES_key_schedule *schedule,DES_cblock *ivec,int *num,
209 int enc);
210void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
211 DES_key_schedule *schedule,DES_cblock *ivec,int *num);
212
213#define DES_fixup_key_parity DES_set_odd_parity
214
215#ifdef __cplusplus
216}
217#endif
218
219#endif
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
deleted file mode 100644
index 1de35e1e34..0000000000
--- a/src/lib/libcrypto/des/des_enc.c
+++ /dev/null
@@ -1,404 +0,0 @@
1/* $OpenBSD: des_enc.c,v 1.12 2014/10/28 07:35:58 jsg Exp $ */
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 DES_LONG l,r,t,u;
67#ifdef DES_PTR
68 const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
69#endif
70#ifndef DES_UNROLL
71 int i;
72#endif
73 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 DES_LONG l,r,t,u;
161#ifdef DES_PTR
162 const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
163#endif
164#ifndef DES_UNROLL
165 int i;
166#endif
167 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 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 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 DES_LONG tin0,tin1;
298 DES_LONG tout0,tout1,xor0,xor1;
299 const unsigned char *in;
300 unsigned char *out;
301 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 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 38ac68a6e6..0000000000
--- a/src/lib/libcrypto/des/des_locl.h
+++ /dev/null
@@ -1,392 +0,0 @@
1/* $OpenBSD: des_locl.h,v 1.18 2014/10/28 07:35:58 jsg Exp $ */
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 <math.h>
63#include <stdint.h>
64#include <stdio.h>
65#include <stdlib.h>
66#include <string.h>
67#include <unistd.h>
68
69#include <openssl/opensslconf.h>
70
71#include <openssl/des.h>
72
73#define ITERATIONS 16
74#define HALF_ITERATIONS 8
75
76/* used in des_read and des_write */
77#define MAXWRITE (1024*16)
78#define BSIZE (MAXWRITE+4)
79
80#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
81 l|=((DES_LONG)(*((c)++)))<< 8L, \
82 l|=((DES_LONG)(*((c)++)))<<16L, \
83 l|=((DES_LONG)(*((c)++)))<<24L)
84
85/* NOTE - c is not incremented as per c2l */
86#define c2ln(c,l1,l2,n) { \
87 c+=n; \
88 l1=l2=0; \
89 switch (n) { \
90 case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
91 case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
92 case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
93 case 5: l2|=((DES_LONG)(*(--(c)))); \
94 case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
95 case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
96 case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
97 case 1: l1|=((DES_LONG)(*(--(c)))); \
98 } \
99 }
100
101#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
102 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
103 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
104 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
105
106/* replacements for htonl and ntohl since I have no idea what to do
107 * when faced with machines with 8 byte longs. */
108#define HDRSIZE 4
109
110#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \
111 l|=((DES_LONG)(*((c)++)))<<16L, \
112 l|=((DES_LONG)(*((c)++)))<< 8L, \
113 l|=((DES_LONG)(*((c)++))))
114
115#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
116 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
117 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
118 *((c)++)=(unsigned char)(((l) )&0xff))
119
120/* NOTE - c is not incremented as per l2c */
121#define l2cn(l1,l2,c,n) { \
122 c+=n; \
123 switch (n) { \
124 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
125 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
126 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
127 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
128 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
129 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
130 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
131 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
132 } \
133 }
134
135static inline uint32_t ROTATE(uint32_t a, uint32_t n)
136{
137 return (a>>n)+(a<<(32-n));
138}
139
140/* Don't worry about the LOAD_DATA() stuff, that is used by
141 * fcrypt() to add it's little bit to the front */
142
143#ifdef DES_FCRYPT
144
145#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \
146 { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); }
147
148#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
149 t=R^(R>>16L); \
150 u=t&E0; t&=E1; \
151 tmp=(u<<16); u^=R^s[S ]; u^=tmp; \
152 tmp=(t<<16); t^=R^s[S+1]; t^=tmp
153#else
154#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
155#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
156 u=R^s[S ]; \
157 t=R^s[S+1]
158#endif
159
160/* The changes to this macro may help or hinder, depending on the
161 * compiler and the architecture. gcc2 always seems to do well :-).
162 * Inspired by Dana How <how@isl.stanford.edu>
163 * DO NOT use the alternative version on machines with 8 byte longs.
164 * It does not seem to work on the Alpha, even when DES_LONG is 4
165 * bytes, probably an issue of accessing non-word aligned objects :-( */
166#ifdef DES_PTR
167
168/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
169 * is no reason to not xor all the sub items together. This potentially
170 * saves a register since things can be xored directly into L */
171
172#if defined(DES_RISC1) || defined(DES_RISC2)
173#ifdef DES_RISC1
174#define D_ENCRYPT(LL,R,S) { \
175 unsigned int u1,u2,u3; \
176 LOAD_DATA(R,S,u,t,E0,E1,u1); \
177 u2=(int)u>>8L; \
178 u1=(int)u&0xfc; \
179 u2&=0xfc; \
180 t=ROTATE(t,4); \
181 u>>=16L; \
182 LL^= *(const DES_LONG *)(des_SP +u1); \
183 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
184 u3=(int)(u>>8L); \
185 u1=(int)u&0xfc; \
186 u3&=0xfc; \
187 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
188 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
189 u2=(int)t>>8L; \
190 u1=(int)t&0xfc; \
191 u2&=0xfc; \
192 t>>=16L; \
193 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
194 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
195 u3=(int)t>>8L; \
196 u1=(int)t&0xfc; \
197 u3&=0xfc; \
198 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
199 LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
200#endif
201#ifdef DES_RISC2
202#define D_ENCRYPT(LL,R,S) { \
203 unsigned int u1,u2,s1,s2; \
204 LOAD_DATA(R,S,u,t,E0,E1,u1); \
205 u2=(int)u>>8L; \
206 u1=(int)u&0xfc; \
207 u2&=0xfc; \
208 t=ROTATE(t,4); \
209 LL^= *(const DES_LONG *)(des_SP +u1); \
210 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
211 s1=(int)(u>>16L); \
212 s2=(int)(u>>24L); \
213 s1&=0xfc; \
214 s2&=0xfc; \
215 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
216 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
217 u2=(int)t>>8L; \
218 u1=(int)t&0xfc; \
219 u2&=0xfc; \
220 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
221 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
222 s1=(int)(t>>16L); \
223 s2=(int)(t>>24L); \
224 s1&=0xfc; \
225 s2&=0xfc; \
226 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
227 LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
228#endif
229#else
230#define D_ENCRYPT(LL,R,S) { \
231 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
232 t=ROTATE(t,4); \
233 LL^= \
234 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \
235 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
236 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
237 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
238 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
239 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
240 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
241 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
242#endif
243
244#else /* original version */
245
246#if defined(DES_RISC1) || defined(DES_RISC2)
247#ifdef DES_RISC1
248#define D_ENCRYPT(LL,R,S) {\
249 unsigned int u1,u2,u3; \
250 LOAD_DATA(R,S,u,t,E0,E1,u1); \
251 u>>=2L; \
252 t=ROTATE(t,6); \
253 u2=(int)u>>8L; \
254 u1=(int)u&0x3f; \
255 u2&=0x3f; \
256 u>>=16L; \
257 LL^=DES_SPtrans[0][u1]; \
258 LL^=DES_SPtrans[2][u2]; \
259 u3=(int)u>>8L; \
260 u1=(int)u&0x3f; \
261 u3&=0x3f; \
262 LL^=DES_SPtrans[4][u1]; \
263 LL^=DES_SPtrans[6][u3]; \
264 u2=(int)t>>8L; \
265 u1=(int)t&0x3f; \
266 u2&=0x3f; \
267 t>>=16L; \
268 LL^=DES_SPtrans[1][u1]; \
269 LL^=DES_SPtrans[3][u2]; \
270 u3=(int)t>>8L; \
271 u1=(int)t&0x3f; \
272 u3&=0x3f; \
273 LL^=DES_SPtrans[5][u1]; \
274 LL^=DES_SPtrans[7][u3]; }
275#endif
276#ifdef DES_RISC2
277#define D_ENCRYPT(LL,R,S) {\
278 unsigned int u1,u2,s1,s2; \
279 LOAD_DATA(R,S,u,t,E0,E1,u1); \
280 u>>=2L; \
281 t=ROTATE(t,6); \
282 u2=(int)u>>8L; \
283 u1=(int)u&0x3f; \
284 u2&=0x3f; \
285 LL^=DES_SPtrans[0][u1]; \
286 LL^=DES_SPtrans[2][u2]; \
287 s1=(int)u>>16L; \
288 s2=(int)u>>24L; \
289 s1&=0x3f; \
290 s2&=0x3f; \
291 LL^=DES_SPtrans[4][s1]; \
292 LL^=DES_SPtrans[6][s2]; \
293 u2=(int)t>>8L; \
294 u1=(int)t&0x3f; \
295 u2&=0x3f; \
296 LL^=DES_SPtrans[1][u1]; \
297 LL^=DES_SPtrans[3][u2]; \
298 s1=(int)t>>16; \
299 s2=(int)t>>24L; \
300 s1&=0x3f; \
301 s2&=0x3f; \
302 LL^=DES_SPtrans[5][s1]; \
303 LL^=DES_SPtrans[7][s2]; }
304#endif
305
306#else
307
308#define D_ENCRYPT(LL,R,S) {\
309 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
310 t=ROTATE(t,4); \
311 LL^=\
312 DES_SPtrans[0][(u>> 2L)&0x3f]^ \
313 DES_SPtrans[2][(u>>10L)&0x3f]^ \
314 DES_SPtrans[4][(u>>18L)&0x3f]^ \
315 DES_SPtrans[6][(u>>26L)&0x3f]^ \
316 DES_SPtrans[1][(t>> 2L)&0x3f]^ \
317 DES_SPtrans[3][(t>>10L)&0x3f]^ \
318 DES_SPtrans[5][(t>>18L)&0x3f]^ \
319 DES_SPtrans[7][(t>>26L)&0x3f]; }
320#endif
321#endif
322
323 /* IP and FP
324 * The problem is more of a geometric problem that random bit fiddling.
325 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
326 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
327 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
328 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
329
330 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
331 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
332 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
333 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
334
335 The output has been subject to swaps of the form
336 0 1 -> 3 1 but the odd and even bits have been put into
337 2 3 2 0
338 different words. The main trick is to remember that
339 t=((l>>size)^r)&(mask);
340 r^=t;
341 l^=(t<<size);
342 can be used to swap and move bits between words.
343
344 So l = 0 1 2 3 r = 16 17 18 19
345 4 5 6 7 20 21 22 23
346 8 9 10 11 24 25 26 27
347 12 13 14 15 28 29 30 31
348 becomes (for size == 2 and mask == 0x3333)
349 t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
350 6^20 7^21 -- -- 4 5 20 21 6 7 22 23
351 10^24 11^25 -- -- 8 9 24 25 10 11 24 25
352 14^28 15^29 -- -- 12 13 28 29 14 15 28 29
353
354 Thanks for hints from Richard Outerbridge - he told me IP&FP
355 could be done in 15 xor, 10 shifts and 5 ands.
356 When I finally started to think of the problem in 2D
357 I first got ~42 operations without xors. When I remembered
358 how to use xors :-) I got it to its final state.
359 */
360#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
361 (b)^=(t),\
362 (a)^=((t)<<(n)))
363
364#define IP(l,r) \
365 { \
366 DES_LONG tt; \
367 PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
368 PERM_OP(l,r,tt,16,0x0000ffffL); \
369 PERM_OP(r,l,tt, 2,0x33333333L); \
370 PERM_OP(l,r,tt, 8,0x00ff00ffL); \
371 PERM_OP(r,l,tt, 1,0x55555555L); \
372 }
373
374#define FP(l,r) \
375 { \
376 DES_LONG tt; \
377 PERM_OP(l,r,tt, 1,0x55555555L); \
378 PERM_OP(r,l,tt, 8,0x00ff00ffL); \
379 PERM_OP(l,r,tt, 2,0x33333333L); \
380 PERM_OP(r,l,tt,16,0x0000ffffL); \
381 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
382 }
383
384extern const DES_LONG DES_SPtrans[8][64];
385
386void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
387 DES_LONG Eswap0, DES_LONG Eswap1);
388
389#ifdef OPENSSL_SMALL_FOOTPRINT
390#undef DES_UNROLL
391#endif
392#endif
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c
deleted file mode 100644
index 97de804cfb..0000000000
--- a/src/lib/libcrypto/des/ecb3_enc.c
+++ /dev/null
@@ -1,83 +0,0 @@
1/* $OpenBSD: ecb3_enc.c,v 1.7 2014/10/28 07:35:58 jsg Exp $ */
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 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 dac37de882..0000000000
--- a/src/lib/libcrypto/des/ecb_enc.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/* $OpenBSD: ecb_enc.c,v 1.16 2014/10/28 07:35:58 jsg Exp $ */
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/opensslv.h>
61#include <openssl/bio.h>
62
63const char *DES_options(void)
64 {
65 static int init=1;
66 static char buf[32];
67
68 if (init)
69 {
70 const char *ptr,*unroll,*risc,*size;
71
72#ifdef DES_PTR
73 ptr="ptr";
74#else
75 ptr="idx";
76#endif
77#if defined(DES_RISC1) || defined(DES_RISC2)
78#ifdef DES_RISC1
79 risc="risc1";
80#endif
81#ifdef DES_RISC2
82 risc="risc2";
83#endif
84#else
85 risc="cisc";
86#endif
87#ifdef DES_UNROLL
88 unroll="16";
89#else
90 unroll="2";
91#endif
92 if (sizeof(DES_LONG) != sizeof(long))
93 size="int";
94 else
95 size="long";
96 snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,
97 size);
98 init=0;
99 }
100 return(buf);
101 }
102
103
104void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
105 DES_key_schedule *ks, int enc)
106 {
107 DES_LONG l;
108 DES_LONG ll[2];
109 const unsigned char *in = &(*input)[0];
110 unsigned char *out = &(*output)[0];
111
112 c2l(in,l); ll[0]=l;
113 c2l(in,l); ll[1]=l;
114 DES_encrypt1(ll,ks,enc);
115 l=ll[0]; l2c(l,out);
116 l=ll[1]; l2c(l,out);
117 l=ll[0]=ll[1]=0;
118 }
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 9a9f51e311..0000000000
--- a/src/lib/libcrypto/des/ede_cbcm_enc.c
+++ /dev/null
@@ -1,199 +0,0 @@
1/* $OpenBSD: ede_cbcm_enc.c,v 1.6 2014/10/28 07:35:58 jsg Exp $ */
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 DES_LONG tin0,tin1;
82 DES_LONG tout0,tout1,xor0,xor1,m0,m1;
83 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 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 f5659150d3..0000000000
--- a/src/lib/libcrypto/des/enc_read.c
+++ /dev/null
@@ -1,229 +0,0 @@
1/* $OpenBSD: enc_read.c,v 1.15 2015/02/12 03:54:07 jsing Exp $ */
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 <stdio.h>
61
62#include <openssl/opensslconf.h>
63
64#include "des_locl.h"
65
66/* This has some uglies in it but it works - even over sockets. */
67/*extern int errno;*/
68int DES_rw_mode = DES_PCBC_MODE;
69
70/*
71 * WARNINGS:
72 *
73 * - The data format used by DES_enc_write() and DES_enc_read()
74 * has a cryptographic weakness: When asked to write more
75 * than MAXWRITE bytes, DES_enc_write will split the data
76 * into several chunks that are all encrypted
77 * using the same IV. So don't use these functions unless you
78 * are sure you know what you do (in which case you might
79 * not want to use them anyway).
80 *
81 * - This code cannot handle non-blocking sockets.
82 *
83 * - This function uses an internal state and thus cannot be
84 * used on multiple files.
85 */
86
87
88int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
89 DES_cblock *iv)
90 {
91 /* data to be unencrypted */
92 int net_num=0;
93 static unsigned char *net=NULL;
94 /* extra unencrypted data
95 * for when a block of 100 comes in but is des_read one byte at
96 * a time. */
97 static unsigned char *unnet=NULL;
98 static int unnet_start=0;
99 static int unnet_left=0;
100 static unsigned char *tmpbuf=NULL;
101 int i;
102 long num=0,rnum;
103 unsigned char *p;
104
105 if (tmpbuf == NULL)
106 {
107 tmpbuf=malloc(BSIZE);
108 if (tmpbuf == NULL) return(-1);
109 }
110 if (net == NULL)
111 {
112 net=malloc(BSIZE);
113 if (net == NULL) return(-1);
114 }
115 if (unnet == NULL)
116 {
117 unnet=malloc(BSIZE);
118 if (unnet == NULL) return(-1);
119 }
120 /* left over data from last decrypt */
121 if (unnet_left != 0)
122 {
123 if (unnet_left < len)
124 {
125 /* we still still need more data but will return
126 * with the number of bytes we have - should always
127 * check the return value */
128 memcpy(buf,&(unnet[unnet_start]),
129 unnet_left);
130 /* eay 26/08/92 I had the next 2 lines
131 * reversed :-( */
132 i=unnet_left;
133 unnet_start=unnet_left=0;
134 }
135 else
136 {
137 memcpy(buf,&(unnet[unnet_start]),len);
138 unnet_start+=len;
139 unnet_left-=len;
140 i=len;
141 }
142 return(i);
143 }
144
145 /* We need to get more data. */
146 if (len > MAXWRITE) len=MAXWRITE;
147
148 /* first - get the length */
149 while (net_num < HDRSIZE)
150 {
151 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
152#ifdef EINTR
153 if ((i == -1) && (errno == EINTR)) continue;
154#endif
155 if (i <= 0) return(0);
156 net_num+=i;
157 }
158
159 /* we now have at net_num bytes in net */
160 p=net;
161 /* num=0; */
162 n2l(p,num);
163 /* num should be rounded up to the next group of eight
164 * we make sure that we have read a multiple of 8 bytes from the net.
165 */
166 if ((num > MAXWRITE) || (num < 0)) /* error */
167 return(-1);
168 rnum=(num < 8)?8:((num+7)/8*8);
169
170 net_num=0;
171 while (net_num < rnum)
172 {
173 i=read(fd,(void *)&(net[net_num]),rnum-net_num);
174#ifdef EINTR
175 if ((i == -1) && (errno == EINTR)) continue;
176#endif
177 if (i <= 0) return(0);
178 net_num+=i;
179 }
180
181 /* Check if there will be data left over. */
182 if (len < num)
183 {
184 if (DES_rw_mode & DES_PCBC_MODE)
185 DES_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
186 else
187 DES_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
188 memcpy(buf,unnet,len);
189 unnet_start=len;
190 unnet_left=num-len;
191
192 /* The following line is done because we return num
193 * as the number of bytes read. */
194 num=len;
195 }
196 else
197 {
198 /* >output is a multiple of 8 byes, if len < rnum
199 * >we must be careful. The user must be aware that this
200 * >routine will write more bytes than he asked for.
201 * >The length of the buffer must be correct.
202 * FIXED - Should be ok now 18-9-90 - eay */
203 if (len < rnum)
204 {
205
206 if (DES_rw_mode & DES_PCBC_MODE)
207 DES_pcbc_encrypt(net,tmpbuf,num,sched,iv,
208 DES_DECRYPT);
209 else
210 DES_cbc_encrypt(net,tmpbuf,num,sched,iv,
211 DES_DECRYPT);
212
213 /* eay 26/08/92 fix a bug that returned more
214 * bytes than you asked for (returned len bytes :-( */
215 memcpy(buf,tmpbuf,num);
216 }
217 else
218 {
219 if (DES_rw_mode & DES_PCBC_MODE)
220 DES_pcbc_encrypt(net,buf,num,sched,iv,
221 DES_DECRYPT);
222 else
223 DES_cbc_encrypt(net,buf,num,sched,iv,
224 DES_DECRYPT);
225 }
226 }
227 return num;
228 }
229
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
deleted file mode 100644
index 59f3878de9..0000000000
--- a/src/lib/libcrypto/des/enc_writ.c
+++ /dev/null
@@ -1,173 +0,0 @@
1/* $OpenBSD: enc_writ.c,v 1.14 2015/02/12 03:54:07 jsing Exp $ */
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 <stdio.h>
61#include <stdlib.h>
62#include <time.h>
63
64#include <openssl/opensslconf.h>
65
66#include "des_locl.h"
67
68/*
69 * WARNINGS:
70 *
71 * - The data format used by DES_enc_write() and DES_enc_read()
72 * has a cryptographic weakness: When asked to write more
73 * than MAXWRITE bytes, DES_enc_write will split the data
74 * into several chunks that are all encrypted
75 * using the same IV. So don't use these functions unless you
76 * are sure you know what you do (in which case you might
77 * not want to use them anyway).
78 *
79 * - This code cannot handle non-blocking sockets.
80 */
81
82int DES_enc_write(int fd, const void *_buf, int len,
83 DES_key_schedule *sched, DES_cblock *iv)
84 {
85#ifdef _LIBC
86 extern unsigned long time();
87 extern int write();
88#endif
89 const unsigned char *buf=_buf;
90 long rnum;
91 int i,j,k,outnum;
92 static unsigned char *outbuf=NULL;
93 unsigned char shortbuf[8];
94 unsigned char *p;
95 const unsigned char *cp;
96 static int start=1;
97
98 if (outbuf == NULL)
99 {
100 outbuf=malloc(BSIZE+HDRSIZE);
101 if (outbuf == NULL) return(-1);
102 }
103 /* If we are sending less than 8 bytes, the same char will look
104 * the same if we don't pad it out with random bytes */
105 if (start)
106 {
107 start=0;
108 }
109
110 /* lets recurse if we want to send the data in small chunks */
111 if (len > MAXWRITE)
112 {
113 j=0;
114 for (i=0; i<len; i+=k)
115 {
116 k=DES_enc_write(fd,&(buf[i]),
117 ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv);
118 if (k < 0)
119 return(k);
120 else
121 j+=k;
122 }
123 return(j);
124 }
125
126 /* write length first */
127 p=outbuf;
128 l2n(len,p);
129
130 /* pad short strings */
131 if (len < 8)
132 {
133 cp=shortbuf;
134 memcpy(shortbuf,buf,len);
135 arc4random_buf(shortbuf+len, 8-len);
136 rnum=8;
137 }
138 else
139 {
140 cp=buf;
141 rnum=((len+7)/8*8); /* round up to nearest eight */
142 }
143
144 if (DES_rw_mode & DES_PCBC_MODE)
145 DES_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
146 DES_ENCRYPT);
147 else
148 DES_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
149 DES_ENCRYPT);
150
151 /* output */
152 outnum=rnum+HDRSIZE;
153
154 for (j=0; j<outnum; j+=i)
155 {
156 /* eay 26/08/92 I was not doing writing from where we
157 * got up to. */
158 i=write(fd,(void *)&(outbuf[j]),outnum-j);
159 if (i == -1)
160 {
161#ifdef EINTR
162 if (errno == EINTR)
163 i=0;
164 else
165#endif
166 /* This is really a bad error - very bad
167 * It will stuff-up both ends. */
168 return(-1);
169 }
170 }
171
172 return(len);
173 }
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
deleted file mode 100644
index e2675fa451..0000000000
--- a/src/lib/libcrypto/des/fcrypt.c
+++ /dev/null
@@ -1,125 +0,0 @@
1/* $OpenBSD: fcrypt.c,v 1.11 2014/06/12 15:49:28 deraadt Exp $ */
2
3#include <stdio.h>
4
5/* This version of crypt has been developed from my MIT compatible
6 * DES library.
7 * Eric Young (eay@cryptsoft.com)
8 */
9
10/* Modification by Jens Kupferschmidt (Cu)
11 * I have included directive PARA for shared memory computers.
12 * I have included a directive LONGCRYPT to using this routine to cipher
13 * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN
14 * definition is the maximum of length of password and can changed. I have
15 * defined 24.
16 */
17
18#include "des_locl.h"
19
20/* Added more values to handle illegal salt values the way normal
21 * crypt() implementations do. The patch was sent by
22 * Bjorn Gronvall <bg@sics.se>
23 */
24static unsigned const char con_salt[128]={
250xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,
260xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1,
270xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,
280xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,
290xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,
300xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01,
310x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
320x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A,
330x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,
340x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,
350x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,
360x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24,
370x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,
380x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,
390x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,
400x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44,
41};
42
43static unsigned const char cov_2char[64]={
440x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
450x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
460x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
470x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
480x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
490x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
500x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
510x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
52};
53
54char *DES_crypt(const char *buf, const char *salt)
55 {
56 static char buff[14];
57
58 return(DES_fcrypt(buf,salt,buff));
59 }
60
61
62char *DES_fcrypt(const char *buf, const char *salt, char *ret)
63 {
64 unsigned int i,j,x,y;
65 DES_LONG Eswap0,Eswap1;
66 DES_LONG out[2],ll;
67 DES_cblock key;
68 DES_key_schedule ks;
69 unsigned char bb[9];
70 unsigned char *b=bb;
71 unsigned char c,u;
72
73 /* eay 25/08/92
74 * If you call crypt("pwd","*") as often happens when you
75 * have * as the pwd field in /etc/passwd, the function
76 * returns *\0xxxxxxxxx
77 * The \0 makes the string look like * so the pwd "*" would
78 * crypt to "*". This was found when replacing the crypt in
79 * our shared libraries. People found that the disabled
80 * accounts effectively had no passwd :-(. */
81 x=ret[0]=((salt[0] == '\0')?'A':salt[0]);
82 Eswap0=con_salt[x]<<2;
83 x=ret[1]=((salt[1] == '\0')?'A':salt[1]);
84 Eswap1=con_salt[x]<<6;
85/* EAY
86r=strlen(buf);
87r=(r+7)/8;
88*/
89 for (i=0; i<8; i++)
90 {
91 c= *(buf++);
92 if (!c) break;
93 key[i]=(c<<1);
94 }
95 for (; i<8; i++)
96 key[i]=0;
97
98 DES_set_key_unchecked(&key,&ks);
99 fcrypt_body(&(out[0]),&ks,Eswap0,Eswap1);
100
101 ll=out[0]; l2c(ll,b);
102 ll=out[1]; l2c(ll,b);
103 y=0;
104 u=0x80;
105 bb[8]=0;
106 for (i=2; i<13; i++)
107 {
108 c=0;
109 for (j=0; j<6; j++)
110 {
111 c<<=1;
112 if (bb[y] & u) c|=1;
113 u>>=1;
114 if (!u)
115 {
116 y++;
117 u=0x80;
118 }
119 }
120 ret[i]=cov_2char[c];
121 }
122 ret[13]='\0';
123 return(ret);
124 }
125
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
deleted file mode 100644
index ad11a47d88..0000000000
--- a/src/lib/libcrypto/des/fcrypt_b.c
+++ /dev/null
@@ -1,146 +0,0 @@
1/* $OpenBSD: fcrypt_b.c,v 1.9 2014/10/28 07:35:58 jsg Exp $ */
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 DES_LONG l,r,t,u;
86#ifdef DES_PTR
87 const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
88#endif
89 DES_LONG *s;
90 int j;
91 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 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 212796237d..0000000000
--- a/src/lib/libcrypto/des/ncbc_enc.c
+++ /dev/null
@@ -1,148 +0,0 @@
1/* $OpenBSD: ncbc_enc.c,v 1.7 2014/10/28 07:35:58 jsg Exp $ */
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 DES_LONG tin0,tin1;
75 DES_LONG tout0,tout1,xor0,xor1;
76 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 474d38caaf..0000000000
--- a/src/lib/libcrypto/des/ofb64ede.c
+++ /dev/null
@@ -1,114 +0,0 @@
1/* $OpenBSD: ofb64ede.c,v 1.6 2015/02/07 13:19:15 doug Exp $ */
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(const unsigned char *in,
66 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 DES_LONG v0,v1;
72 int n= *num;
73 long l=length;
74 DES_cblock d;
75 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 iv = &(*ivec)[0];
109 l2c(v0,iv);
110 l2c(v1,iv);
111 }
112 v0=v1=ti[0]=ti[1]=0;
113 *num=n;
114 }
diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c
deleted file mode 100644
index de1a26b99f..0000000000
--- a/src/lib/libcrypto/des/ofb64enc.c
+++ /dev/null
@@ -1,110 +0,0 @@
1/* $OpenBSD: ofb64enc.c,v 1.6 2014/10/28 07:35:58 jsg Exp $ */
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(const unsigned char *in,
66 unsigned char *out, long length,
67 DES_key_schedule *schedule, DES_cblock *ivec, int *num)
68 {
69 DES_LONG v0,v1,t;
70 int n= *num;
71 long l=length;
72 DES_cblock d;
73 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 8cc5bbcb1e..0000000000
--- a/src/lib/libcrypto/des/ofb_enc.c
+++ /dev/null
@@ -1,135 +0,0 @@
1/* $OpenBSD: ofb_enc.c,v 1.6 2014/10/28 07:35:58 jsg Exp $ */
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 DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8;
72 DES_LONG mask0,mask1;
73 long l=length;
74 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 fda18ba83d..0000000000
--- a/src/lib/libcrypto/des/pcbc_enc.c
+++ /dev/null
@@ -1,123 +0,0 @@
1/* $OpenBSD: pcbc_enc.c,v 1.6 2014/10/28 07:35:58 jsg Exp $ */
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 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 e2409d8ba4..0000000000
--- a/src/lib/libcrypto/des/qud_cksm.c
+++ /dev/null
@@ -1,125 +0,0 @@
1/* $OpenBSD: qud_cksm.c,v 1.7 2014/06/12 15:49:28 deraadt Exp $ */
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 DES_LONG *lp;
84
85 if (out_count < 1) out_count=1;
86 lp = (DES_LONG *) &(output[0])[0];
87
88 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]);
89 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]);
90
91 for (i=0; ((i<4)&&(i<out_count)); i++)
92 {
93 cp=input;
94 l=length;
95 while (l > 0)
96 {
97 if (l > 1)
98 {
99 t0= (DES_LONG)(*(cp++));
100 t0|=(DES_LONG)Q_B1(*(cp++));
101 l--;
102 }
103 else
104 t0= (DES_LONG)(*(cp++));
105 l--;
106 /* add */
107 t0+=z0;
108 t0&=0xffffffffL;
109 t1=z1;
110 /* square, well sort of square */
111 z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL))
112 &0xffffffffL)%0x7fffffffL;
113 z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL;
114 }
115 if (lp != NULL)
116 {
117 /* The MIT library assumes that the checksum is
118 * composed of 2*out_count 32 bit ints */
119 *lp++ = z0;
120 *lp++ = z1;
121 }
122 }
123 return(z0);
124 }
125
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c
deleted file mode 100644
index 7abb811df4..0000000000
--- a/src/lib/libcrypto/des/rand_key.c
+++ /dev/null
@@ -1,68 +0,0 @@
1/* $OpenBSD: rand_key.c,v 1.8 2014/10/22 13:02:04 jsing Exp $ */
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 <stdlib.h>
57
58#include <openssl/des.h>
59
60int
61DES_random_key(DES_cblock *ret)
62{
63 do {
64 arc4random_buf(ret, sizeof(DES_cblock));
65 DES_set_odd_parity(ret);
66 } while (DES_is_weak_key(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 59d6893a80..0000000000
--- a/src/lib/libcrypto/des/set_key.c
+++ /dev/null
@@ -1,400 +0,0 @@
1/* $OpenBSD: set_key.c,v 1.19 2014/10/28 07:35:58 jsg Exp $ */
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 <openssl/crypto.h>
67#include "des_locl.h"
68
69int DES_check_key = 0; /* defaults to false */
70
71static const unsigned char odd_parity[256]={
72 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
73 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
74 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
75 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
76 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
77 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
78 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
79112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
80128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
81145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
82161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
83176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
84193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
85208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
86224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
87241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254};
88
89void DES_set_odd_parity(DES_cblock *key)
90 {
91 unsigned int i;
92
93 for (i=0; i<DES_KEY_SZ; i++)
94 (*key)[i]=odd_parity[(*key)[i]];
95 }
96
97int DES_check_key_parity(const_DES_cblock *key)
98 {
99 unsigned int i;
100
101 for (i=0; i<DES_KEY_SZ; i++)
102 {
103 if ((*key)[i] != odd_parity[(*key)[i]])
104 return(0);
105 }
106 return(1);
107 }
108
109/* Weak and semi week keys as take from
110 * %A D.W. Davies
111 * %A W.L. Price
112 * %T Security for Computer Networks
113 * %I John Wiley & Sons
114 * %D 1984
115 * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
116 * (and actual cblock values).
117 */
118#define NUM_WEAK_KEY 16
119static const DES_cblock weak_keys[NUM_WEAK_KEY]={
120 /* weak keys */
121 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
122 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
123 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
124 {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
125 /* semi-weak keys */
126 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
127 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
128 {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
129 {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
130 {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
131 {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
132 {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
133 {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
134 {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
135 {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
136 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
137 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
138
139int
140DES_is_weak_key(const_DES_cblock *key)
141{
142 unsigned int i;
143
144 for (i = 0; i < NUM_WEAK_KEY; i++)
145 if (memcmp(weak_keys[i], key, sizeof(DES_cblock)) == 0)
146 return 1;
147 return 0;
148}
149
150/* NOW DEFINED IN des_local.h
151 * See ecb_encrypt.c for a pseudo description of these macros.
152 * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
153 * (b)^=(t),\
154 * (a)=((a)^((t)<<(n))))
155 */
156
157#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
158 (a)=(a)^(t)^(t>>(16-(n))))
159
160static const DES_LONG des_skb[8][64]={
161 {
162 /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
163 0x00000000L,0x00000010L,0x20000000L,0x20000010L,
164 0x00010000L,0x00010010L,0x20010000L,0x20010010L,
165 0x00000800L,0x00000810L,0x20000800L,0x20000810L,
166 0x00010800L,0x00010810L,0x20010800L,0x20010810L,
167 0x00000020L,0x00000030L,0x20000020L,0x20000030L,
168 0x00010020L,0x00010030L,0x20010020L,0x20010030L,
169 0x00000820L,0x00000830L,0x20000820L,0x20000830L,
170 0x00010820L,0x00010830L,0x20010820L,0x20010830L,
171 0x00080000L,0x00080010L,0x20080000L,0x20080010L,
172 0x00090000L,0x00090010L,0x20090000L,0x20090010L,
173 0x00080800L,0x00080810L,0x20080800L,0x20080810L,
174 0x00090800L,0x00090810L,0x20090800L,0x20090810L,
175 0x00080020L,0x00080030L,0x20080020L,0x20080030L,
176 0x00090020L,0x00090030L,0x20090020L,0x20090030L,
177 0x00080820L,0x00080830L,0x20080820L,0x20080830L,
178 0x00090820L,0x00090830L,0x20090820L,0x20090830L,
179 },{
180 /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
181 0x00000000L,0x02000000L,0x00002000L,0x02002000L,
182 0x00200000L,0x02200000L,0x00202000L,0x02202000L,
183 0x00000004L,0x02000004L,0x00002004L,0x02002004L,
184 0x00200004L,0x02200004L,0x00202004L,0x02202004L,
185 0x00000400L,0x02000400L,0x00002400L,0x02002400L,
186 0x00200400L,0x02200400L,0x00202400L,0x02202400L,
187 0x00000404L,0x02000404L,0x00002404L,0x02002404L,
188 0x00200404L,0x02200404L,0x00202404L,0x02202404L,
189 0x10000000L,0x12000000L,0x10002000L,0x12002000L,
190 0x10200000L,0x12200000L,0x10202000L,0x12202000L,
191 0x10000004L,0x12000004L,0x10002004L,0x12002004L,
192 0x10200004L,0x12200004L,0x10202004L,0x12202004L,
193 0x10000400L,0x12000400L,0x10002400L,0x12002400L,
194 0x10200400L,0x12200400L,0x10202400L,0x12202400L,
195 0x10000404L,0x12000404L,0x10002404L,0x12002404L,
196 0x10200404L,0x12200404L,0x10202404L,0x12202404L,
197 },{
198 /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
199 0x00000000L,0x00000001L,0x00040000L,0x00040001L,
200 0x01000000L,0x01000001L,0x01040000L,0x01040001L,
201 0x00000002L,0x00000003L,0x00040002L,0x00040003L,
202 0x01000002L,0x01000003L,0x01040002L,0x01040003L,
203 0x00000200L,0x00000201L,0x00040200L,0x00040201L,
204 0x01000200L,0x01000201L,0x01040200L,0x01040201L,
205 0x00000202L,0x00000203L,0x00040202L,0x00040203L,
206 0x01000202L,0x01000203L,0x01040202L,0x01040203L,
207 0x08000000L,0x08000001L,0x08040000L,0x08040001L,
208 0x09000000L,0x09000001L,0x09040000L,0x09040001L,
209 0x08000002L,0x08000003L,0x08040002L,0x08040003L,
210 0x09000002L,0x09000003L,0x09040002L,0x09040003L,
211 0x08000200L,0x08000201L,0x08040200L,0x08040201L,
212 0x09000200L,0x09000201L,0x09040200L,0x09040201L,
213 0x08000202L,0x08000203L,0x08040202L,0x08040203L,
214 0x09000202L,0x09000203L,0x09040202L,0x09040203L,
215 },{
216 /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
217 0x00000000L,0x00100000L,0x00000100L,0x00100100L,
218 0x00000008L,0x00100008L,0x00000108L,0x00100108L,
219 0x00001000L,0x00101000L,0x00001100L,0x00101100L,
220 0x00001008L,0x00101008L,0x00001108L,0x00101108L,
221 0x04000000L,0x04100000L,0x04000100L,0x04100100L,
222 0x04000008L,0x04100008L,0x04000108L,0x04100108L,
223 0x04001000L,0x04101000L,0x04001100L,0x04101100L,
224 0x04001008L,0x04101008L,0x04001108L,0x04101108L,
225 0x00020000L,0x00120000L,0x00020100L,0x00120100L,
226 0x00020008L,0x00120008L,0x00020108L,0x00120108L,
227 0x00021000L,0x00121000L,0x00021100L,0x00121100L,
228 0x00021008L,0x00121008L,0x00021108L,0x00121108L,
229 0x04020000L,0x04120000L,0x04020100L,0x04120100L,
230 0x04020008L,0x04120008L,0x04020108L,0x04120108L,
231 0x04021000L,0x04121000L,0x04021100L,0x04121100L,
232 0x04021008L,0x04121008L,0x04021108L,0x04121108L,
233 },{
234 /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
235 0x00000000L,0x10000000L,0x00010000L,0x10010000L,
236 0x00000004L,0x10000004L,0x00010004L,0x10010004L,
237 0x20000000L,0x30000000L,0x20010000L,0x30010000L,
238 0x20000004L,0x30000004L,0x20010004L,0x30010004L,
239 0x00100000L,0x10100000L,0x00110000L,0x10110000L,
240 0x00100004L,0x10100004L,0x00110004L,0x10110004L,
241 0x20100000L,0x30100000L,0x20110000L,0x30110000L,
242 0x20100004L,0x30100004L,0x20110004L,0x30110004L,
243 0x00001000L,0x10001000L,0x00011000L,0x10011000L,
244 0x00001004L,0x10001004L,0x00011004L,0x10011004L,
245 0x20001000L,0x30001000L,0x20011000L,0x30011000L,
246 0x20001004L,0x30001004L,0x20011004L,0x30011004L,
247 0x00101000L,0x10101000L,0x00111000L,0x10111000L,
248 0x00101004L,0x10101004L,0x00111004L,0x10111004L,
249 0x20101000L,0x30101000L,0x20111000L,0x30111000L,
250 0x20101004L,0x30101004L,0x20111004L,0x30111004L,
251 },{
252 /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
253 0x00000000L,0x08000000L,0x00000008L,0x08000008L,
254 0x00000400L,0x08000400L,0x00000408L,0x08000408L,
255 0x00020000L,0x08020000L,0x00020008L,0x08020008L,
256 0x00020400L,0x08020400L,0x00020408L,0x08020408L,
257 0x00000001L,0x08000001L,0x00000009L,0x08000009L,
258 0x00000401L,0x08000401L,0x00000409L,0x08000409L,
259 0x00020001L,0x08020001L,0x00020009L,0x08020009L,
260 0x00020401L,0x08020401L,0x00020409L,0x08020409L,
261 0x02000000L,0x0A000000L,0x02000008L,0x0A000008L,
262 0x02000400L,0x0A000400L,0x02000408L,0x0A000408L,
263 0x02020000L,0x0A020000L,0x02020008L,0x0A020008L,
264 0x02020400L,0x0A020400L,0x02020408L,0x0A020408L,
265 0x02000001L,0x0A000001L,0x02000009L,0x0A000009L,
266 0x02000401L,0x0A000401L,0x02000409L,0x0A000409L,
267 0x02020001L,0x0A020001L,0x02020009L,0x0A020009L,
268 0x02020401L,0x0A020401L,0x02020409L,0x0A020409L,
269 },{
270 /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
271 0x00000000L,0x00000100L,0x00080000L,0x00080100L,
272 0x01000000L,0x01000100L,0x01080000L,0x01080100L,
273 0x00000010L,0x00000110L,0x00080010L,0x00080110L,
274 0x01000010L,0x01000110L,0x01080010L,0x01080110L,
275 0x00200000L,0x00200100L,0x00280000L,0x00280100L,
276 0x01200000L,0x01200100L,0x01280000L,0x01280100L,
277 0x00200010L,0x00200110L,0x00280010L,0x00280110L,
278 0x01200010L,0x01200110L,0x01280010L,0x01280110L,
279 0x00000200L,0x00000300L,0x00080200L,0x00080300L,
280 0x01000200L,0x01000300L,0x01080200L,0x01080300L,
281 0x00000210L,0x00000310L,0x00080210L,0x00080310L,
282 0x01000210L,0x01000310L,0x01080210L,0x01080310L,
283 0x00200200L,0x00200300L,0x00280200L,0x00280300L,
284 0x01200200L,0x01200300L,0x01280200L,0x01280300L,
285 0x00200210L,0x00200310L,0x00280210L,0x00280310L,
286 0x01200210L,0x01200310L,0x01280210L,0x01280310L,
287 },{
288 /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
289 0x00000000L,0x04000000L,0x00040000L,0x04040000L,
290 0x00000002L,0x04000002L,0x00040002L,0x04040002L,
291 0x00002000L,0x04002000L,0x00042000L,0x04042000L,
292 0x00002002L,0x04002002L,0x00042002L,0x04042002L,
293 0x00000020L,0x04000020L,0x00040020L,0x04040020L,
294 0x00000022L,0x04000022L,0x00040022L,0x04040022L,
295 0x00002020L,0x04002020L,0x00042020L,0x04042020L,
296 0x00002022L,0x04002022L,0x00042022L,0x04042022L,
297 0x00000800L,0x04000800L,0x00040800L,0x04040800L,
298 0x00000802L,0x04000802L,0x00040802L,0x04040802L,
299 0x00002800L,0x04002800L,0x00042800L,0x04042800L,
300 0x00002802L,0x04002802L,0x00042802L,0x04042802L,
301 0x00000820L,0x04000820L,0x00040820L,0x04040820L,
302 0x00000822L,0x04000822L,0x00040822L,0x04040822L,
303 0x00002820L,0x04002820L,0x00042820L,0x04042820L,
304 0x00002822L,0x04002822L,0x00042822L,0x04042822L,
305 }};
306
307int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule)
308 {
309 if (DES_check_key)
310 {
311 return DES_set_key_checked(key, schedule);
312 }
313 else
314 {
315 DES_set_key_unchecked(key, schedule);
316 return 0;
317 }
318 }
319
320/* return 0 if key parity is odd (correct),
321 * return -1 if key parity error,
322 * return -2 if illegal weak key.
323 */
324int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule)
325 {
326 if (!DES_check_key_parity(key))
327 return(-1);
328 if (DES_is_weak_key(key))
329 return(-2);
330 DES_set_key_unchecked(key, schedule);
331 return 0;
332 }
333
334void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
335 {
336 static const int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
337 DES_LONG c,d,t,s,t2;
338 const unsigned char *in;
339 DES_LONG *k;
340 int i;
341
342 k = &schedule->ks->deslong[0];
343 in = &(*key)[0];
344
345 c2l(in,c);
346 c2l(in,d);
347
348 /* do PC1 in 47 simple operations :-)
349 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
350 * for the inspiration. :-) */
351 PERM_OP (d,c,t,4,0x0f0f0f0fL);
352 HPERM_OP(c,t,-2,0xcccc0000L);
353 HPERM_OP(d,t,-2,0xcccc0000L);
354 PERM_OP (d,c,t,1,0x55555555L);
355 PERM_OP (c,d,t,8,0x00ff00ffL);
356 PERM_OP (d,c,t,1,0x55555555L);
357 d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) |
358 ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
359 c&=0x0fffffffL;
360
361 for (i=0; i<ITERATIONS; i++)
362 {
363 if (shifts2[i])
364 { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
365 else
366 { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); }
367 c&=0x0fffffffL;
368 d&=0x0fffffffL;
369 /* could be a few less shifts but I am to lazy at this
370 * point in time to investigate */
371 s= des_skb[0][ (c )&0x3f ]|
372 des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
373 des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
374 des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
375 ((c>>22L)&0x38)];
376 t= des_skb[4][ (d )&0x3f ]|
377 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
378 des_skb[6][ (d>>15L)&0x3f ]|
379 des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
380
381 /* table contained 0213 4657 */
382 t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
383 *(k++)=ROTATE(t2,30)&0xffffffffL;
384
385 t2=((s>>16L)|(t&0xffff0000L));
386 *(k++)=ROTATE(t2,26)&0xffffffffL;
387 }
388 }
389
390int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule)
391 {
392 return(DES_set_key(key,schedule));
393 }
394/*
395#undef des_fixup_key_parity
396void des_fixup_key_parity(des_cblock *key)
397 {
398 des_set_odd_parity(key);
399 }
400*/
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h
deleted file mode 100644
index eec6beb9f7..0000000000
--- a/src/lib/libcrypto/des/spr.h
+++ /dev/null
@@ -1,204 +0,0 @@
1/* $OpenBSD: spr.h,v 1.5 2014/06/12 15:49:28 deraadt Exp $ */
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
59const 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 8999eb292a..0000000000
--- a/src/lib/libcrypto/des/str2key.c
+++ /dev/null
@@ -1,174 +0,0 @@
1/* $OpenBSD: str2key.c,v 1.9 2014/10/28 07:35:58 jsg Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/crypto.h>
60#include "des_locl.h"
61
62void DES_string_to_key(const char *str, DES_cblock *key)
63 {
64 DES_key_schedule ks;
65 int i,length;
66 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 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 4f7a070103..0000000000
--- a/src/lib/libcrypto/des/xcbc_enc.c
+++ /dev/null
@@ -1,148 +0,0 @@
1/* $OpenBSD: xcbc_enc.c,v 1.9 2015/02/07 13:19:15 doug Exp $ */
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
63void DES_xcbc_encrypt(const unsigned char *in, unsigned char *out,
64 long length, DES_key_schedule *schedule,
65 DES_cblock *ivec, const_DES_cblock *inw,
66 const_DES_cblock *outw, int enc)
67 {
68 DES_LONG tin0,tin1;
69 DES_LONG tout0,tout1,xor0,xor1;
70 DES_LONG inW0,inW1,outW0,outW1;
71 const unsigned char *in2;
72 long l=length;
73 DES_LONG tin[2];
74 unsigned char *iv;
75
76 in2 = &(*inw)[0];
77 c2l(in2,inW0);
78 c2l(in2,inW1);
79 in2 = &(*outw)[0];
80 c2l(in2,outW0);
81 c2l(in2,outW1);
82
83 iv = &(*ivec)[0];
84
85 if (enc)
86 {
87 c2l(iv,tout0);
88 c2l(iv,tout1);
89 for (l-=8; l>=0; l-=8)
90 {
91 c2l(in,tin0);
92 c2l(in,tin1);
93 tin0^=tout0^inW0; tin[0]=tin0;
94 tin1^=tout1^inW1; tin[1]=tin1;
95 DES_encrypt1(tin,schedule,DES_ENCRYPT);
96 tout0=tin[0]^outW0; l2c(tout0,out);
97 tout1=tin[1]^outW1; l2c(tout1,out);
98 }
99 if (l != -8)
100 {
101 c2ln(in,tin0,tin1,l+8);
102 tin0^=tout0^inW0; tin[0]=tin0;
103 tin1^=tout1^inW1; tin[1]=tin1;
104 DES_encrypt1(tin,schedule,DES_ENCRYPT);
105 tout0=tin[0]^outW0; l2c(tout0,out);
106 tout1=tin[1]^outW1; l2c(tout1,out);
107 }
108 iv = &(*ivec)[0];
109 l2c(tout0,iv);
110 l2c(tout1,iv);
111 }
112 else
113 {
114 c2l(iv,xor0);
115 c2l(iv,xor1);
116 for (l-=8; l>0; l-=8)
117 {
118 c2l(in,tin0); tin[0]=tin0^outW0;
119 c2l(in,tin1); tin[1]=tin1^outW1;
120 DES_encrypt1(tin,schedule,DES_DECRYPT);
121 tout0=tin[0]^xor0^inW0;
122 tout1=tin[1]^xor1^inW1;
123 l2c(tout0,out);
124 l2c(tout1,out);
125 xor0=tin0;
126 xor1=tin1;
127 }
128 if (l != -8)
129 {
130 c2l(in,tin0); tin[0]=tin0^outW0;
131 c2l(in,tin1); tin[1]=tin1^outW1;
132 DES_encrypt1(tin,schedule,DES_DECRYPT);
133 tout0=tin[0]^xor0^inW0;
134 tout1=tin[1]^xor1^inW1;
135 l2cn(tout0,tout1,out,l+8);
136 xor0=tin0;
137 xor1=tin1;
138 }
139
140 iv = &(*ivec)[0];
141 l2c(xor0,iv);
142 l2c(xor1,iv);
143 }
144 tin0=tin1=tout0=tout1=xor0=xor1=0;
145 inW0=inW1=outW0=outW1=0;
146 tin[0]=tin[1]=0;
147 }
148