summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2005-03-12 00:02:08 +0000
committercvs2svn <admin@example.com>2005-03-12 00:02:08 +0000
commit259e36b1c57849c281afb8526bab11e7ba2592e2 (patch)
treed0e478b7669f593934b32e564b5611b40796a4b1 /src/lib/libcrypto/des
parent9a03506f8308b6023a12f108a2072feb958607a6 (diff)
downloadopenbsd-OPENBSD_3_7_BASE.tar.gz
openbsd-OPENBSD_3_7_BASE.tar.bz2
openbsd-OPENBSD_3_7_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_3_7_BASE'.OPENBSD_3_7_BASE
Diffstat (limited to 'src/lib/libcrypto/des')
-rw-r--r--src/lib/libcrypto/des/COPYRIGHT50
-rw-r--r--src/lib/libcrypto/des/asm/crypt586.pl208
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl255
-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.c142
-rw-r--r--src/lib/libcrypto/des/cfb64enc.c121
-rw-r--r--src/lib/libcrypto/des/cfb_enc.c174
-rw-r--r--src/lib/libcrypto/des/des.h242
-rw-r--r--src/lib/libcrypto/des/des_enc.c409
-rw-r--r--src/lib/libcrypto/des/des_locl.h428
-rw-r--r--src/lib/libcrypto/des/ecb3_enc.c83
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c123
-rw-r--r--src/lib/libcrypto/des/ede_cbcm_enc.c197
-rw-r--r--src/lib/libcrypto/des/enc_read.c228
-rw-r--r--src/lib/libcrypto/des/enc_writ.c171
-rw-r--r--src/lib/libcrypto/des/fcrypt.c173
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c145
-rw-r--r--src/lib/libcrypto/des/ncbc_enc.c148
-rw-r--r--src/lib/libcrypto/des/ofb64ede.c125
-rw-r--r--src/lib/libcrypto/des/ofb64enc.c110
-rw-r--r--src/lib/libcrypto/des/ofb_enc.c135
-rw-r--r--src/lib/libcrypto/des/pcbc_enc.c123
-rw-r--r--src/lib/libcrypto/des/qud_cksm.c139
-rw-r--r--src/lib/libcrypto/des/rand_key.c68
-rw-r--r--src/lib/libcrypto/des/set_key.c407
-rw-r--r--src/lib/libcrypto/des/spr.h204
-rw-r--r--src/lib/libcrypto/des/str2key.c173
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c195
30 files changed, 0 insertions, 5222 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 1d04ed6def..0000000000
--- a/src/lib/libcrypto/des/asm/crypt586.pl
+++ /dev/null
@@ -1,208 +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
9push(@INC,"perlasm","../../perlasm");
10require "x86asm.pl";
11
12&asm_init($ARGV[0],"crypt586.pl");
13
14$L="edi";
15$R="esi";
16
17&external_label("DES_SPtrans");
18&fcrypt_body("fcrypt_body");
19&asm_finish();
20
21sub fcrypt_body
22 {
23 local($name,$do_ip)=@_;
24
25 &function_begin($name,"EXTRN _DES_SPtrans:DWORD");
26
27 &comment("");
28 &comment("Load the 2 words");
29 $trans="ebp";
30
31 &xor( $L, $L);
32 &xor( $R, $R);
33
34 # PIC-ification:-)
35 &picmeup("edx","DES_SPtrans");
36 #if ($cpp) { &picmeup("edx","DES_SPtrans"); }
37 #else { &lea("edx",&DWP("DES_SPtrans")); }
38 &push("edx"); # becomes &swtmp(1)
39 #
40 &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT
41
42 &push(&DWC(25)); # add a variable
43
44 &set_label("start");
45 for ($i=0; $i<16; $i+=2)
46 {
47 &comment("");
48 &comment("Round $i");
49 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
50
51 &comment("");
52 &comment("Round ".sprintf("%d",$i+1));
53 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
54 }
55 &mov("ebx", &swtmp(0));
56 &mov("eax", $L);
57 &dec("ebx");
58 &mov($L, $R);
59 &mov($R, "eax");
60 &mov(&swtmp(0), "ebx");
61 &jnz(&label("start"));
62
63 &comment("");
64 &comment("FP");
65 &mov("edx",&wparam(0));
66
67 &FP_new($R,$L,"eax",3);
68 &mov(&DWP(0,"edx","",0),"eax");
69 &mov(&DWP(4,"edx","",0),$L);
70
71 &add("esp",8); # remove variables
72
73 &function_end($name);
74 }
75
76sub D_ENCRYPT
77 {
78 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
79
80 &mov( $u, &wparam(2)); # 2
81 &mov( $t, $R);
82 &shr( $t, 16); # 1
83 &mov( $tmp2, &wparam(3)); # 2
84 &xor( $t, $R); # 1
85
86 &and( $u, $t); # 2
87 &and( $t, $tmp2); # 2
88
89 &mov( $tmp1, $u);
90 &shl( $tmp1, 16); # 1
91 &mov( $tmp2, $t);
92 &shl( $tmp2, 16); # 1
93 &xor( $u, $tmp1); # 2
94 &xor( $t, $tmp2); # 2
95 &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2
96 &xor( $u, $tmp1);
97 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2
98 &xor( $u, $R);
99 &xor( $t, $R);
100 &xor( $t, $tmp2);
101
102 &and( $u, "0xfcfcfcfc" ); # 2
103 &xor( $tmp1, $tmp1); # 1
104 &and( $t, "0xcfcfcfcf" ); # 2
105 &xor( $tmp2, $tmp2);
106 &movb( &LB($tmp1), &LB($u) );
107 &movb( &LB($tmp2), &HB($u) );
108 &rotr( $t, 4 );
109 &mov( $trans, &swtmp(1));
110 &xor( $L, &DWP(" ",$trans,$tmp1,0));
111 &movb( &LB($tmp1), &LB($t) );
112 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
113 &movb( &LB($tmp2), &HB($t) );
114 &shr( $u, 16);
115 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
116 &movb( &LB($tmp1), &HB($u) );
117 &shr( $t, 16);
118 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
119 &movb( &LB($tmp2), &HB($t) );
120 &and( $u, "0xff" );
121 &and( $t, "0xff" );
122 &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0));
123 &xor( $L, $tmp1);
124 &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0));
125 &xor( $L, $tmp1);
126 &mov( $tmp1, &DWP("0x400",$trans,$u,0));
127 &xor( $L, $tmp1);
128 &mov( $tmp1, &DWP("0x500",$trans,$t,0));
129 &xor( $L, $tmp1);
130 &mov( $trans, &wparam(1));
131 }
132
133sub n2a
134 {
135 sprintf("%d",$_[0]);
136 }
137
138# now has a side affect of rotating $a by $shift
139sub R_PERM_OP
140 {
141 local($a,$b,$tt,$shift,$mask,$last)=@_;
142
143 &rotl( $a, $shift ) if ($shift != 0);
144 &mov( $tt, $a );
145 &xor( $a, $b );
146 &and( $a, $mask );
147 if ($notlast eq $b)
148 {
149 &xor( $b, $a );
150 &xor( $tt, $a );
151 }
152 else
153 {
154 &xor( $tt, $a );
155 &xor( $b, $a );
156 }
157 &comment("");
158 }
159
160sub IP_new
161 {
162 local($l,$r,$tt,$lr)=@_;
163
164 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
165 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
166 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
167 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
168 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
169
170 if ($lr != 3)
171 {
172 if (($lr-3) < 0)
173 { &rotr($tt, 3-$lr); }
174 else { &rotl($tt, $lr-3); }
175 }
176 if ($lr != 2)
177 {
178 if (($lr-2) < 0)
179 { &rotr($r, 2-$lr); }
180 else { &rotl($r, $lr-2); }
181 }
182 }
183
184sub FP_new
185 {
186 local($l,$r,$tt,$lr)=@_;
187
188 if ($lr != 2)
189 {
190 if (($lr-2) < 0)
191 { &rotl($r, 2-$lr); }
192 else { &rotr($r, $lr-2); }
193 }
194 if ($lr != 3)
195 {
196 if (($lr-3) < 0)
197 { &rotl($l, 3-$lr); }
198 else { &rotr($l, $lr-3); }
199 }
200
201 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
202 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
203 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
204 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
205 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
206 &rotr($tt , 4);
207 }
208
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl
deleted file mode 100644
index 60d577cc8d..0000000000
--- a/src/lib/libcrypto/des/asm/des-586.pl
+++ /dev/null
@@ -1,255 +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
7push(@INC,"perlasm","../../perlasm");
8require "x86asm.pl";
9require "cbc.pl";
10require "desboth.pl";
11
12# base code is in microsft
13# op dest, source
14# format.
15#
16
17&asm_init($ARGV[0],"des-586.pl");
18
19$L="edi";
20$R="esi";
21
22&external_label("DES_SPtrans");
23&DES_encrypt("DES_encrypt1",1);
24&DES_encrypt("DES_encrypt2",0);
25
26if (!$main'openbsd)
27 {
28 &DES_encrypt3("DES_encrypt3",1);
29 &DES_encrypt3("DES_decrypt3",0);
30 &cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
31 &cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
32 }
33
34&asm_finish();
35
36sub DES_encrypt
37 {
38 local($name,$do_ip)=@_;
39
40 &function_begin_B($name,"EXTRN _DES_SPtrans:DWORD");
41
42 &push("esi");
43 &push("edi");
44
45 &comment("");
46 &comment("Load the 2 words");
47 $trans="ebp";
48
49 if ($do_ip)
50 {
51 &mov($R,&wparam(0));
52 &xor( "ecx", "ecx" );
53
54 &push("ebx");
55 &push("ebp");
56
57 &mov("eax",&DWP(0,$R,"",0));
58 &mov("ebx",&wparam(2)); # get encrypt flag
59 &mov($L,&DWP(4,$R,"",0));
60 &comment("");
61 &comment("IP");
62 &IP_new("eax",$L,$R,3);
63 }
64 else
65 {
66 &mov("eax",&wparam(0));
67 &xor( "ecx", "ecx" );
68
69 &push("ebx");
70 &push("ebp");
71
72 &mov($R,&DWP(0,"eax","",0));
73 &mov("ebx",&wparam(2)); # get encrypt flag
74 &rotl($R,3);
75 &mov($L,&DWP(4,"eax","",0));
76 &rotl($L,3);
77 }
78
79 # PIC-ification:-)
80 &picmeup($trans,"DES_SPtrans");
81 #if ($cpp) { &picmeup($trans,"DES_SPtrans"); }
82 #else { &lea($trans,&DWP("DES_SPtrans")); }
83
84 &mov( "ecx", &wparam(1) );
85 &cmp("ebx","0");
86 &je(&label("start_decrypt"));
87
88 for ($i=0; $i<16; $i+=2)
89 {
90 &comment("");
91 &comment("Round $i");
92 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
93
94 &comment("");
95 &comment("Round ".sprintf("%d",$i+1));
96 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
97 }
98 &jmp(&label("end"));
99
100 &set_label("start_decrypt");
101
102 for ($i=15; $i>0; $i-=2)
103 {
104 &comment("");
105 &comment("Round $i");
106 &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
107 &comment("");
108 &comment("Round ".sprintf("%d",$i-1));
109 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx");
110 }
111
112 &set_label("end");
113
114 if ($do_ip)
115 {
116 &comment("");
117 &comment("FP");
118 &mov("edx",&wparam(0));
119 &FP_new($L,$R,"eax",3);
120
121 &mov(&DWP(0,"edx","",0),"eax");
122 &mov(&DWP(4,"edx","",0),$R);
123 }
124 else
125 {
126 &comment("");
127 &comment("Fixup");
128 &rotr($L,3); # r
129 &mov("eax",&wparam(0));
130 &rotr($R,3); # l
131 &mov(&DWP(0,"eax","",0),$L);
132 &mov(&DWP(4,"eax","",0),$R);
133 }
134
135 &pop("ebp");
136 &pop("ebx");
137 &pop("edi");
138 &pop("esi");
139 &ret();
140
141 &function_end_B($name);
142 }
143
144sub D_ENCRYPT
145 {
146 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
147
148 &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0));
149 &xor( $tmp1, $tmp1);
150 &mov( $t, &DWP(&n2a(($S+1)*4),$tmp2,"",0));
151 &xor( $u, $R);
152 &xor( $tmp2, $tmp2);
153 &xor( $t, $R);
154 &and( $u, "0xfcfcfcfc" );
155 &and( $t, "0xcfcfcfcf" );
156 &movb( &LB($tmp1), &LB($u) );
157 &movb( &LB($tmp2), &HB($u) );
158 &rotr( $t, 4 );
159 &xor( $L, &DWP(" ",$trans,$tmp1,0));
160 &movb( &LB($tmp1), &LB($t) );
161 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
162 &movb( &LB($tmp2), &HB($t) );
163 &shr( $u, 16);
164 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
165 &movb( &LB($tmp1), &HB($u) );
166 &shr( $t, 16);
167 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
168 &movb( &LB($tmp2), &HB($t) );
169 &and( $u, "0xff" );
170 &and( $t, "0xff" );
171 &xor( $L, &DWP("0x600",$trans,$tmp1,0));
172 &xor( $L, &DWP("0x700",$trans,$tmp2,0));
173 &mov( $tmp2, &wparam(1) );
174 &xor( $L, &DWP("0x400",$trans,$u,0));
175 &xor( $L, &DWP("0x500",$trans,$t,0));
176 }
177
178sub n2a
179 {
180 sprintf("%d",$_[0]);
181 }
182
183# now has a side affect of rotating $a by $shift
184sub R_PERM_OP
185 {
186 local($a,$b,$tt,$shift,$mask,$last)=@_;
187
188 &rotl( $a, $shift ) if ($shift != 0);
189 &mov( $tt, $a );
190 &xor( $a, $b );
191 &and( $a, $mask );
192 # This can never succeed, and besides it is difficult to see what the
193 # idea was - Ben 13 Feb 99
194 if (!$last eq $b)
195 {
196 &xor( $b, $a );
197 &xor( $tt, $a );
198 }
199 else
200 {
201 &xor( $tt, $a );
202 &xor( $b, $a );
203 }
204 &comment("");
205 }
206
207sub IP_new
208 {
209 local($l,$r,$tt,$lr)=@_;
210
211 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
212 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
213 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
214 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
215 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
216
217 if ($lr != 3)
218 {
219 if (($lr-3) < 0)
220 { &rotr($tt, 3-$lr); }
221 else { &rotl($tt, $lr-3); }
222 }
223 if ($lr != 2)
224 {
225 if (($lr-2) < 0)
226 { &rotr($r, 2-$lr); }
227 else { &rotl($r, $lr-2); }
228 }
229 }
230
231sub FP_new
232 {
233 local($l,$r,$tt,$lr)=@_;
234
235 if ($lr != 2)
236 {
237 if (($lr-2) < 0)
238 { &rotl($r, 2-$lr); }
239 else { &rotr($r, $lr-2); }
240 }
241 if ($lr != 3)
242 {
243 if (($lr-3) < 0)
244 { &rotl($l, 3-$lr); }
245 else { &rotr($l, $lr-3); }
246 }
247
248 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
249 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
250 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
251 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
252 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
253 &rotr($tt , 4);
254 }
255
diff --git a/src/lib/libcrypto/des/asm/desboth.pl b/src/lib/libcrypto/des/asm/desboth.pl
deleted file mode 100644
index eec00886e4..0000000000
--- a/src/lib/libcrypto/des/asm/desboth.pl
+++ /dev/null
@@ -1,79 +0,0 @@
1#!/usr/local/bin/perl
2
3$L="edi";
4$R="esi";
5
6sub DES_encrypt3
7 {
8 local($name,$enc)=@_;
9
10 &function_begin_B($name,"");
11 &push("ebx");
12 &mov("ebx",&wparam(0));
13
14 &push("ebp");
15 &push("esi");
16
17 &push("edi");
18
19 &comment("");
20 &comment("Load the data words");
21 &mov($L,&DWP(0,"ebx","",0));
22 &mov($R,&DWP(4,"ebx","",0));
23 &stack_push(3);
24
25 &comment("");
26 &comment("IP");
27 &IP_new($L,$R,"edx",0);
28
29 # put them back
30
31 if ($enc)
32 {
33 &mov(&DWP(4,"ebx","",0),$R);
34 &mov("eax",&wparam(1));
35 &mov(&DWP(0,"ebx","",0),"edx");
36 &mov("edi",&wparam(2));
37 &mov("esi",&wparam(3));
38 }
39 else
40 {
41 &mov(&DWP(4,"ebx","",0),$R);
42 &mov("esi",&wparam(1));
43 &mov(&DWP(0,"ebx","",0),"edx");
44 &mov("edi",&wparam(2));
45 &mov("eax",&wparam(3));
46 }
47 &mov(&swtmp(2), (DWC(($enc)?"1":"0")));
48 &mov(&swtmp(1), "eax");
49 &mov(&swtmp(0), "ebx");
50 &call("DES_encrypt2");
51 &mov(&swtmp(2), (DWC(($enc)?"0":"1")));
52 &mov(&swtmp(1), "edi");
53 &mov(&swtmp(0), "ebx");
54 &call("DES_encrypt2");
55 &mov(&swtmp(2), (DWC(($enc)?"1":"0")));
56 &mov(&swtmp(1), "esi");
57 &mov(&swtmp(0), "ebx");
58 &call("DES_encrypt2");
59
60 &stack_pop(3);
61 &mov($L,&DWP(0,"ebx","",0));
62 &mov($R,&DWP(4,"ebx","",0));
63
64 &comment("");
65 &comment("FP");
66 &FP_new($L,$R,"eax",0);
67
68 &mov(&DWP(0,"ebx","",0),"eax");
69 &mov(&DWP(4,"ebx","",0),$R);
70
71 &pop("edi");
72 &pop("esi");
73 &pop("ebp");
74 &pop("ebx");
75 &ret();
76 &function_end_B($name);
77 }
78
79
diff --git a/src/lib/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c
deleted file mode 100644
index 09a7ba56aa..0000000000
--- a/src/lib/libcrypto/des/cbc_cksm.c
+++ /dev/null
@@ -1,106 +0,0 @@
1/* crypto/des/cbc_cksm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61DES_LONG DES_cbc_cksum(const unsigned char *in, DES_cblock *output,
62 long length, DES_key_schedule *schedule,
63 const_DES_cblock *ivec)
64 {
65 register DES_LONG tout0,tout1,tin0,tin1;
66 register long l=length;
67 DES_LONG tin[2];
68 unsigned char *out = &(*output)[0];
69 const unsigned char *iv = &(*ivec)[0];
70
71 c2l(iv,tout0);
72 c2l(iv,tout1);
73 for (; l>0; l-=8)
74 {
75 if (l >= 8)
76 {
77 c2l(in,tin0);
78 c2l(in,tin1);
79 }
80 else
81 c2ln(in,tin0,tin1,l);
82
83 tin0^=tout0; tin[0]=tin0;
84 tin1^=tout1; tin[1]=tin1;
85 DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT);
86 /* fix 15/10/91 eay - thanks to keithr@sco.COM */
87 tout0=tin[0];
88 tout1=tin[1];
89 }
90 if (out != NULL)
91 {
92 l2c(tout0,out);
93 l2c(tout1,out);
94 }
95 tout0=tin0=tin1=tin[0]=tin[1]=0;
96 /*
97 Transform the data in tout1 so that it will
98 match the return value that the MIT Kerberos
99 mit_des_cbc_cksum API returns.
100 */
101 tout1 = ((tout1 >> 24L) & 0x000000FF)
102 | ((tout1 >> 8L) & 0x0000FF00)
103 | ((tout1 << 8L) & 0x00FF0000)
104 | ((tout1 << 24L) & 0xFF000000);
105 return(tout1);
106 }
diff --git a/src/lib/libcrypto/des/cbc_enc.c b/src/lib/libcrypto/des/cbc_enc.c
deleted file mode 100644
index 677903ae4e..0000000000
--- a/src/lib/libcrypto/des/cbc_enc.c
+++ /dev/null
@@ -1,61 +0,0 @@
1/* crypto/des/cbc_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#define CBC_ENC_C__DONT_UPDATE_IV
60
61#include "ncbc_enc.c" /* des_cbc_encrypt */
diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c
deleted file mode 100644
index 60c1aa08db..0000000000
--- a/src/lib/libcrypto/des/cfb64ede.c
+++ /dev/null
@@ -1,142 +0,0 @@
1/* crypto/des/cfb64ede.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
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 register DES_LONG v0,v1;
72 register long l=length;
73 register 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#ifdef undef /* MACRO */
136void DES_ede2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
137 DES_key_schedule ks1, DES_key_schedule ks2, DES_cblock (*ivec),
138 int *num, int enc)
139 {
140 DES_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc);
141 }
142#endif
diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c
deleted file mode 100644
index 5ec8683e40..0000000000
--- a/src/lib/libcrypto/des/cfb64enc.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/* crypto/des/cfb64enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* The input and output encrypted as though 64bit cfb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65
66void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
67 long length, DES_key_schedule *schedule,
68 DES_cblock *ivec, int *num, int enc)
69 {
70 register DES_LONG v0,v1;
71 register long l=length;
72 register int n= *num;
73 DES_LONG ti[2];
74 unsigned char *iv,c,cc;
75
76 iv = &(*ivec)[0];
77 if (enc)
78 {
79 while (l--)
80 {
81 if (n == 0)
82 {
83 c2l(iv,v0); ti[0]=v0;
84 c2l(iv,v1); ti[1]=v1;
85 DES_encrypt1(ti,schedule,DES_ENCRYPT);
86 iv = &(*ivec)[0];
87 v0=ti[0]; l2c(v0,iv);
88 v0=ti[1]; l2c(v0,iv);
89 iv = &(*ivec)[0];
90 }
91 c= *(in++)^iv[n];
92 *(out++)=c;
93 iv[n]=c;
94 n=(n+1)&0x07;
95 }
96 }
97 else
98 {
99 while (l--)
100 {
101 if (n == 0)
102 {
103 c2l(iv,v0); ti[0]=v0;
104 c2l(iv,v1); ti[1]=v1;
105 DES_encrypt1(ti,schedule,DES_ENCRYPT);
106 iv = &(*ivec)[0];
107 v0=ti[0]; l2c(v0,iv);
108 v0=ti[1]; l2c(v0,iv);
109 iv = &(*ivec)[0];
110 }
111 cc= *(in++);
112 c=iv[n];
113 iv[n]=cc;
114 *(out++)=c^cc;
115 n=(n+1)&0x07;
116 }
117 }
118 v0=v1=ti[0]=ti[1]=c=cc=0;
119 *num=n;
120 }
121
diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c
deleted file mode 100644
index 03cabb223c..0000000000
--- a/src/lib/libcrypto/des/cfb_enc.c
+++ /dev/null
@@ -1,174 +0,0 @@
1/* crypto/des/cfb_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "e_os.h"
60#include "des_locl.h"
61
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 register DES_LONG d0,d1,v0,v1;
75 register unsigned long l=length,n=(numbits+7)/8;
76 register int num=numbits,i;
77 DES_LONG ti[2];
78 unsigned char *iv;
79 unsigned char ovec[16];
80
81 if (num > 64) return;
82 iv = &(*ivec)[0];
83 c2l(iv,v0);
84 c2l(iv,v1);
85 if (enc)
86 {
87 while (l >= n)
88 {
89 l-=n;
90 ti[0]=v0;
91 ti[1]=v1;
92 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
93 c2ln(in,d0,d1,n);
94 in+=n;
95 d0^=ti[0];
96 d1^=ti[1];
97 l2cn(d0,d1,out,n);
98 out+=n;
99 /* 30-08-94 - eay - changed because l>>32 and
100 * l<<32 are bad under gcc :-( */
101 if (num == 32)
102 { v0=v1; v1=d0; }
103 else if (num == 64)
104 { v0=d0; v1=d1; }
105 else
106 {
107 iv=&ovec[0];
108 l2c(v0,iv);
109 l2c(v1,iv);
110 l2c(d0,iv);
111 l2c(d1,iv);
112 /* shift ovec left most of the bits... */
113 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
114 /* now the remaining bits */
115 if(num%8 != 0)
116 for(i=0 ; i < 8 ; ++i)
117 {
118 ovec[i]<<=num%8;
119 ovec[i]|=ovec[i+1]>>(8-num%8);
120 }
121 iv=&ovec[0];
122 c2l(iv,v0);
123 c2l(iv,v1);
124 }
125 }
126 }
127 else
128 {
129 while (l >= n)
130 {
131 l-=n;
132 ti[0]=v0;
133 ti[1]=v1;
134 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
135 c2ln(in,d0,d1,n);
136 in+=n;
137 /* 30-08-94 - eay - changed because l>>32 and
138 * l<<32 are bad under gcc :-( */
139 if (num == 32)
140 { v0=v1; v1=d0; }
141 else if (num == 64)
142 { v0=d0; v1=d1; }
143 else
144 {
145 iv=&ovec[0];
146 l2c(v0,iv);
147 l2c(v1,iv);
148 l2c(d0,iv);
149 l2c(d1,iv);
150 /* shift ovec left most of the bits... */
151 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
152 /* now the remaining bits */
153 if(num%8 != 0)
154 for(i=0 ; i < 8 ; ++i)
155 {
156 ovec[i]<<=num%8;
157 ovec[i]|=ovec[i+1]>>(8-num%8);
158 }
159 iv=&ovec[0];
160 c2l(iv,v0);
161 c2l(iv,v1);
162 }
163 d0^=ti[0];
164 d1^=ti[1];
165 l2cn(d0,d1,out,n);
166 out+=n;
167 }
168 }
169 iv = &(*ivec)[0];
170 l2c(v0,iv);
171 l2c(v1,iv);
172 v0=v1=d0=d1=ti[0]=ti[1]=0;
173 }
174
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
deleted file mode 100644
index dfe5ff64e4..0000000000
--- a/src/lib/libcrypto/des/des.h
+++ /dev/null
@@ -1,242 +0,0 @@
1/* crypto/des/des.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DES_H
60#define HEADER_DES_H
61
62#ifdef OPENSSL_NO_DES
63#error DES is disabled.
64#endif
65
66#include <openssl/opensslconf.h> /* DES_LONG */
67#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
68
69#ifdef OPENSSL_BUILD_SHLIBCRYPTO
70# undef OPENSSL_EXTERN
71# define OPENSSL_EXTERN OPENSSL_EXPORT
72#endif
73
74#define des_SPtrans DES_SPtrans
75
76#ifdef __cplusplus
77extern "C" {
78#endif
79
80typedef unsigned char DES_cblock[8];
81typedef /* const */ unsigned char const_DES_cblock[8];
82/* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock *
83 * and const_DES_cblock * are incompatible pointer types. */
84
85typedef struct DES_ks
86 {
87 union
88 {
89 DES_cblock cblock;
90 /* make sure things are correct size on machines with
91 * 8 byte longs */
92 DES_LONG deslong[2];
93 } ks[16];
94 } DES_key_schedule;
95
96#ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT
97# ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT
98# define OPENSSL_ENABLE_OLD_DES_SUPPORT
99# endif
100#endif
101
102#ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT
103# include <openssl/des_old.h>
104#endif
105
106#define DES_KEY_SZ (sizeof(DES_cblock))
107#define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
108
109#define DES_ENCRYPT 1
110#define DES_DECRYPT 0
111
112#define DES_CBC_MODE 0
113#define DES_PCBC_MODE 1
114
115#define DES_ecb2_encrypt(i,o,k1,k2,e) \
116 DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
117
118#define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
119 DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
120
121#define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
122 DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
123
124#define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
125 DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
126
127OPENSSL_DECLARE_GLOBAL(int,DES_check_key); /* defaults to false */
128#define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)
129OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */
130#define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode)
131
132const char *DES_options(void);
133void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
134 DES_key_schedule *ks1,DES_key_schedule *ks2,
135 DES_key_schedule *ks3, int enc);
136DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output,
137 long length,DES_key_schedule *schedule,
138 const_DES_cblock *ivec);
139/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
140void DES_cbc_encrypt(const unsigned char *input,unsigned char *output,
141 long length,DES_key_schedule *schedule,DES_cblock *ivec,
142 int enc);
143void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output,
144 long length,DES_key_schedule *schedule,DES_cblock *ivec,
145 int enc);
146void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output,
147 long length,DES_key_schedule *schedule,DES_cblock *ivec,
148 const_DES_cblock *inw,const_DES_cblock *outw,int enc);
149void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
150 long length,DES_key_schedule *schedule,DES_cblock *ivec,
151 int enc);
152void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output,
153 DES_key_schedule *ks,int enc);
154
155/* This is the DES encryption function that gets called by just about
156 every other DES routine in the library. You should not use this
157 function except to implement 'modes' of DES. I say this because the
158 functions that call this routine do the conversion from 'char *' to
159 long, and this needs to be done to make sure 'non-aligned' memory
160 access do not occur. The characters are loaded 'little endian'.
161 Data is a pointer to 2 unsigned long's and ks is the
162 DES_key_schedule to use. enc, is non zero specifies encryption,
163 zero if decryption. */
164void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);
165
166/* This functions is the same as DES_encrypt1() except that the DES
167 initial permutation (IP) and final permutation (FP) have been left
168 out. As for DES_encrypt1(), you should not use this function.
169 It is used by the routines in the library that implement triple DES.
170 IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same
171 as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */
172void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc);
173
174void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
175 DES_key_schedule *ks2, DES_key_schedule *ks3);
176void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
177 DES_key_schedule *ks2, DES_key_schedule *ks3);
178void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
179 long length,
180 DES_key_schedule *ks1,DES_key_schedule *ks2,
181 DES_key_schedule *ks3,DES_cblock *ivec,int enc);
182void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
183 long length,
184 DES_key_schedule *ks1,DES_key_schedule *ks2,
185 DES_key_schedule *ks3,
186 DES_cblock *ivec1,DES_cblock *ivec2,
187 int enc);
188void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
189 long length,DES_key_schedule *ks1,
190 DES_key_schedule *ks2,DES_key_schedule *ks3,
191 DES_cblock *ivec,int *num,int enc);
192void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
193 long length,DES_key_schedule *ks1,
194 DES_key_schedule *ks2,DES_key_schedule *ks3,
195 DES_cblock *ivec,int *num);
196
197void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white,
198 DES_cblock *out_white);
199
200int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched,
201 DES_cblock *iv);
202int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched,
203 DES_cblock *iv);
204char *DES_fcrypt(const char *buf,const char *salt, char *ret);
205char *DES_crypt(const char *buf,const char *salt);
206void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
207 long length,DES_key_schedule *schedule,DES_cblock *ivec);
208void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output,
209 long length,DES_key_schedule *schedule,DES_cblock *ivec,
210 int enc);
211DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[],
212 long length,int out_count,DES_cblock *seed);
213int DES_random_key(DES_cblock *ret);
214void DES_set_odd_parity(DES_cblock *key);
215int DES_check_key_parity(const_DES_cblock *key);
216int DES_is_weak_key(const_DES_cblock *key);
217/* DES_set_key (= set_key = DES_key_sched = key_sched) calls
218 * DES_set_key_checked if global variable DES_check_key is set,
219 * DES_set_key_unchecked otherwise. */
220int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule);
221int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule);
222int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule);
223void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule);
224void DES_string_to_key(const char *str,DES_cblock *key);
225void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2);
226void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
227 DES_key_schedule *schedule,DES_cblock *ivec,int *num,
228 int enc);
229void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
230 DES_key_schedule *schedule,DES_cblock *ivec,int *num);
231
232int DES_read_password(DES_cblock *key, const char *prompt, int verify);
233int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
234 int verify);
235
236#define DES_fixup_key_parity DES_set_odd_parity
237
238#ifdef __cplusplus
239}
240#endif
241
242#endif
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
deleted file mode 100644
index 4f09804c44..0000000000
--- a/src/lib/libcrypto/des/des_enc.c
+++ /dev/null
@@ -1,409 +0,0 @@
1/* crypto/des/des_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61#ifndef OPENBSD_DES_ASM
62void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
63 {
64 register DES_LONG l,r,t,u;
65#ifdef DES_PTR
66 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
67#endif
68#ifndef DES_UNROLL
69 register int i;
70#endif
71 register DES_LONG *s;
72
73 r=data[0];
74 l=data[1];
75
76 IP(r,l);
77 /* Things have been modified so that the initial rotate is
78 * done outside the loop. This required the
79 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
80 * One perl script later and things have a 5% speed up on a sparc2.
81 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
82 * for pointing this out. */
83 /* clear the top bits on machines with 8byte longs */
84 /* shift left by 2 */
85 r=ROTATE(r,29)&0xffffffffL;
86 l=ROTATE(l,29)&0xffffffffL;
87
88 s=ks->ks->deslong;
89 /* I don't know if it is worth the effort of loop unrolling the
90 * inner loop */
91 if (enc)
92 {
93#ifdef DES_UNROLL
94 D_ENCRYPT(l,r, 0); /* 1 */
95 D_ENCRYPT(r,l, 2); /* 2 */
96 D_ENCRYPT(l,r, 4); /* 3 */
97 D_ENCRYPT(r,l, 6); /* 4 */
98 D_ENCRYPT(l,r, 8); /* 5 */
99 D_ENCRYPT(r,l,10); /* 6 */
100 D_ENCRYPT(l,r,12); /* 7 */
101 D_ENCRYPT(r,l,14); /* 8 */
102 D_ENCRYPT(l,r,16); /* 9 */
103 D_ENCRYPT(r,l,18); /* 10 */
104 D_ENCRYPT(l,r,20); /* 11 */
105 D_ENCRYPT(r,l,22); /* 12 */
106 D_ENCRYPT(l,r,24); /* 13 */
107 D_ENCRYPT(r,l,26); /* 14 */
108 D_ENCRYPT(l,r,28); /* 15 */
109 D_ENCRYPT(r,l,30); /* 16 */
110#else
111 for (i=0; i<32; i+=8)
112 {
113 D_ENCRYPT(l,r,i+0); /* 1 */
114 D_ENCRYPT(r,l,i+2); /* 2 */
115 D_ENCRYPT(l,r,i+4); /* 3 */
116 D_ENCRYPT(r,l,i+6); /* 4 */
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-=8)
141 {
142 D_ENCRYPT(l,r,i-0); /* 16 */
143 D_ENCRYPT(r,l,i-2); /* 15 */
144 D_ENCRYPT(l,r,i-4); /* 14 */
145 D_ENCRYPT(r,l,i-6); /* 13 */
146 }
147#endif
148 }
149
150 /* rotate and clear the top bits on machines with 8byte longs */
151 l=ROTATE(l,3)&0xffffffffL;
152 r=ROTATE(r,3)&0xffffffffL;
153
154 FP(r,l);
155 data[0]=l;
156 data[1]=r;
157 l=r=t=u=0;
158 }
159
160void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
161 {
162 register DES_LONG l,r,t,u;
163#ifdef DES_PTR
164 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
165#endif
166#ifndef DES_UNROLL
167 register int i;
168#endif
169 register DES_LONG *s;
170
171 r=data[0];
172 l=data[1];
173
174 /* Things have been modified so that the initial rotate is
175 * done outside the loop. This required the
176 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
177 * One perl script later and things have a 5% speed up on a sparc2.
178 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
179 * for pointing this out. */
180 /* clear the top bits on machines with 8byte longs */
181 r=ROTATE(r,29)&0xffffffffL;
182 l=ROTATE(l,29)&0xffffffffL;
183
184 s=ks->ks->deslong;
185 /* I don't know if it is worth the effort of loop unrolling the
186 * inner loop */
187 if (enc)
188 {
189#ifdef DES_UNROLL
190 D_ENCRYPT(l,r, 0); /* 1 */
191 D_ENCRYPT(r,l, 2); /* 2 */
192 D_ENCRYPT(l,r, 4); /* 3 */
193 D_ENCRYPT(r,l, 6); /* 4 */
194 D_ENCRYPT(l,r, 8); /* 5 */
195 D_ENCRYPT(r,l,10); /* 6 */
196 D_ENCRYPT(l,r,12); /* 7 */
197 D_ENCRYPT(r,l,14); /* 8 */
198 D_ENCRYPT(l,r,16); /* 9 */
199 D_ENCRYPT(r,l,18); /* 10 */
200 D_ENCRYPT(l,r,20); /* 11 */
201 D_ENCRYPT(r,l,22); /* 12 */
202 D_ENCRYPT(l,r,24); /* 13 */
203 D_ENCRYPT(r,l,26); /* 14 */
204 D_ENCRYPT(l,r,28); /* 15 */
205 D_ENCRYPT(r,l,30); /* 16 */
206#else
207 for (i=0; i<32; i+=8)
208 {
209 D_ENCRYPT(l,r,i+0); /* 1 */
210 D_ENCRYPT(r,l,i+2); /* 2 */
211 D_ENCRYPT(l,r,i+4); /* 3 */
212 D_ENCRYPT(r,l,i+6); /* 4 */
213 }
214#endif
215 }
216 else
217 {
218#ifdef DES_UNROLL
219 D_ENCRYPT(l,r,30); /* 16 */
220 D_ENCRYPT(r,l,28); /* 15 */
221 D_ENCRYPT(l,r,26); /* 14 */
222 D_ENCRYPT(r,l,24); /* 13 */
223 D_ENCRYPT(l,r,22); /* 12 */
224 D_ENCRYPT(r,l,20); /* 11 */
225 D_ENCRYPT(l,r,18); /* 10 */
226 D_ENCRYPT(r,l,16); /* 9 */
227 D_ENCRYPT(l,r,14); /* 8 */
228 D_ENCRYPT(r,l,12); /* 7 */
229 D_ENCRYPT(l,r,10); /* 6 */
230 D_ENCRYPT(r,l, 8); /* 5 */
231 D_ENCRYPT(l,r, 6); /* 4 */
232 D_ENCRYPT(r,l, 4); /* 3 */
233 D_ENCRYPT(l,r, 2); /* 2 */
234 D_ENCRYPT(r,l, 0); /* 1 */
235#else
236 for (i=30; i>0; i-=8)
237 {
238 D_ENCRYPT(l,r,i-0); /* 16 */
239 D_ENCRYPT(r,l,i-2); /* 15 */
240 D_ENCRYPT(l,r,i-4); /* 14 */
241 D_ENCRYPT(r,l,i-6); /* 13 */
242 }
243#endif
244 }
245 /* rotate and clear the top bits on machines with 8byte longs */
246 data[0]=ROTATE(l,3)&0xffffffffL;
247 data[1]=ROTATE(r,3)&0xffffffffL;
248 l=r=t=u=0;
249 }
250#endif
251
252void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
253 DES_key_schedule *ks2, DES_key_schedule *ks3)
254 {
255 register DES_LONG l,r;
256
257 l=data[0];
258 r=data[1];
259 IP(l,r);
260 data[0]=l;
261 data[1]=r;
262 DES_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);
263 DES_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);
264 DES_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);
265 l=data[0];
266 r=data[1];
267 FP(r,l);
268 data[0]=l;
269 data[1]=r;
270 }
271
272void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
273 DES_key_schedule *ks2, DES_key_schedule *ks3)
274 {
275 register DES_LONG l,r;
276
277 l=data[0];
278 r=data[1];
279 IP(l,r);
280 data[0]=l;
281 data[1]=r;
282 DES_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT);
283 DES_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT);
284 DES_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT);
285 l=data[0];
286 r=data[1];
287 FP(r,l);
288 data[0]=l;
289 data[1]=r;
290 }
291
292#ifndef DES_DEFAULT_OPTIONS
293
294#undef CBC_ENC_C__DONT_UPDATE_IV
295#include "ncbc_enc.c" /* DES_ncbc_encrypt */
296
297void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
298 long length, DES_key_schedule *ks1,
299 DES_key_schedule *ks2, DES_key_schedule *ks3,
300 DES_cblock *ivec, int enc)
301 {
302 register DES_LONG tin0,tin1;
303 register DES_LONG tout0,tout1,xor0,xor1;
304 register const unsigned char *in;
305 unsigned char *out;
306 register long l=length;
307 DES_LONG tin[2];
308 unsigned char *iv;
309
310 in=input;
311 out=output;
312 iv = &(*ivec)[0];
313
314 if (enc)
315 {
316 c2l(iv,tout0);
317 c2l(iv,tout1);
318 for (l-=8; l>=0; l-=8)
319 {
320 c2l(in,tin0);
321 c2l(in,tin1);
322 tin0^=tout0;
323 tin1^=tout1;
324
325 tin[0]=tin0;
326 tin[1]=tin1;
327 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
328 tout0=tin[0];
329 tout1=tin[1];
330
331 l2c(tout0,out);
332 l2c(tout1,out);
333 }
334 if (l != -8)
335 {
336 c2ln(in,tin0,tin1,l+8);
337 tin0^=tout0;
338 tin1^=tout1;
339
340 tin[0]=tin0;
341 tin[1]=tin1;
342 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
343 tout0=tin[0];
344 tout1=tin[1];
345
346 l2c(tout0,out);
347 l2c(tout1,out);
348 }
349 iv = &(*ivec)[0];
350 l2c(tout0,iv);
351 l2c(tout1,iv);
352 }
353 else
354 {
355 register DES_LONG t0,t1;
356
357 c2l(iv,xor0);
358 c2l(iv,xor1);
359 for (l-=8; l>=0; l-=8)
360 {
361 c2l(in,tin0);
362 c2l(in,tin1);
363
364 t0=tin0;
365 t1=tin1;
366
367 tin[0]=tin0;
368 tin[1]=tin1;
369 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
370 tout0=tin[0];
371 tout1=tin[1];
372
373 tout0^=xor0;
374 tout1^=xor1;
375 l2c(tout0,out);
376 l2c(tout1,out);
377 xor0=t0;
378 xor1=t1;
379 }
380 if (l != -8)
381 {
382 c2l(in,tin0);
383 c2l(in,tin1);
384
385 t0=tin0;
386 t1=tin1;
387
388 tin[0]=tin0;
389 tin[1]=tin1;
390 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
391 tout0=tin[0];
392 tout1=tin[1];
393
394 tout0^=xor0;
395 tout1^=xor1;
396 l2cn(tout0,tout1,out,l+8);
397 xor0=t0;
398 xor1=t1;
399 }
400
401 iv = &(*ivec)[0];
402 l2c(xor0,iv);
403 l2c(xor1,iv);
404 }
405 tin0=tin1=tout0=tout1=xor0=xor1=0;
406 tin[0]=tin[1]=0;
407 }
408
409#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 e44e8e98b2..0000000000
--- a/src/lib/libcrypto/des/des_locl.h
+++ /dev/null
@@ -1,428 +0,0 @@
1/* crypto/des/des_locl.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DES_LOCL_H
60#define HEADER_DES_LOCL_H
61
62#include <openssl/e_os2.h>
63
64#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
65#ifndef OPENSSL_SYS_MSDOS
66#define OPENSSL_SYS_MSDOS
67#endif
68#endif
69
70#include <stdio.h>
71#include <stdlib.h>
72
73#ifndef OPENSSL_SYS_MSDOS
74#if !defined(OPENSSL_SYS_VMS) || defined(__DECC)
75#ifdef OPENSSL_UNISTD
76# include OPENSSL_UNISTD
77#else
78# include <unistd.h>
79#endif
80#include <math.h>
81#endif
82#endif
83#include <openssl/des.h>
84
85#ifdef OPENSSL_SYS_MSDOS /* Visual C++ 2.1 (Windows NT/95) */
86#include <stdlib.h>
87#include <errno.h>
88#include <time.h>
89#include <io.h>
90#endif
91
92#if defined(__STDC__) || defined(OPENSSL_SYS_VMS) || defined(M_XENIX) || defined(OPENSSL_SYS_MSDOS)
93#include <string.h>
94#endif
95
96#ifdef OPENSSL_BUILD_SHLIBCRYPTO
97# undef OPENSSL_EXTERN
98# define OPENSSL_EXTERN OPENSSL_EXPORT
99#endif
100
101#define ITERATIONS 16
102#define HALF_ITERATIONS 8
103
104/* used in des_read and des_write */
105#define MAXWRITE (1024*16)
106#define BSIZE (MAXWRITE+4)
107
108#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
109 l|=((DES_LONG)(*((c)++)))<< 8L, \
110 l|=((DES_LONG)(*((c)++)))<<16L, \
111 l|=((DES_LONG)(*((c)++)))<<24L)
112
113/* NOTE - c is not incremented as per c2l */
114#define c2ln(c,l1,l2,n) { \
115 c+=n; \
116 l1=l2=0; \
117 switch (n) { \
118 case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
119 case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
120 case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
121 case 5: l2|=((DES_LONG)(*(--(c)))); \
122 case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
123 case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
124 case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
125 case 1: l1|=((DES_LONG)(*(--(c)))); \
126 } \
127 }
128
129#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
130 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
131 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
132 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
133
134/* replacements for htonl and ntohl since I have no idea what to do
135 * when faced with machines with 8 byte longs. */
136#define HDRSIZE 4
137
138#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \
139 l|=((DES_LONG)(*((c)++)))<<16L, \
140 l|=((DES_LONG)(*((c)++)))<< 8L, \
141 l|=((DES_LONG)(*((c)++))))
142
143#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
144 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
145 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
146 *((c)++)=(unsigned char)(((l) )&0xff))
147
148/* NOTE - c is not incremented as per l2c */
149#define l2cn(l1,l2,c,n) { \
150 c+=n; \
151 switch (n) { \
152 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
153 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
154 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
155 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
156 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
157 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
158 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
159 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
160 } \
161 }
162
163#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
164#define ROTATE(a,n) (_lrotr(a,n))
165#elif defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC)
166# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
167# define ROTATE(a,n) ({ register unsigned int ret; \
168 asm ("rorl %1,%0" \
169 : "=r"(ret) \
170 : "I"(n),"0"(a) \
171 : "cc"); \
172 ret; \
173 })
174# endif
175#endif
176#ifndef ROTATE
177#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n))))
178#endif
179
180/* Don't worry about the LOAD_DATA() stuff, that is used by
181 * fcrypt() to add it's little bit to the front */
182
183#ifdef DES_FCRYPT
184
185#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \
186 { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); }
187
188#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
189 t=R^(R>>16L); \
190 u=t&E0; t&=E1; \
191 tmp=(u<<16); u^=R^s[S ]; u^=tmp; \
192 tmp=(t<<16); t^=R^s[S+1]; t^=tmp
193#else
194#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
195#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
196 u=R^s[S ]; \
197 t=R^s[S+1]
198#endif
199
200/* The changes to this macro may help or hinder, depending on the
201 * compiler and the architecture. gcc2 always seems to do well :-).
202 * Inspired by Dana How <how@isl.stanford.edu>
203 * DO NOT use the alternative version on machines with 8 byte longs.
204 * It does not seem to work on the Alpha, even when DES_LONG is 4
205 * bytes, probably an issue of accessing non-word aligned objects :-( */
206#ifdef DES_PTR
207
208/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
209 * is no reason to not xor all the sub items together. This potentially
210 * saves a register since things can be xored directly into L */
211
212#if defined(DES_RISC1) || defined(DES_RISC2)
213#ifdef DES_RISC1
214#define D_ENCRYPT(LL,R,S) { \
215 unsigned int u1,u2,u3; \
216 LOAD_DATA(R,S,u,t,E0,E1,u1); \
217 u2=(int)u>>8L; \
218 u1=(int)u&0xfc; \
219 u2&=0xfc; \
220 t=ROTATE(t,4); \
221 u>>=16L; \
222 LL^= *(const DES_LONG *)(des_SP +u1); \
223 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
224 u3=(int)(u>>8L); \
225 u1=(int)u&0xfc; \
226 u3&=0xfc; \
227 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
228 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
229 u2=(int)t>>8L; \
230 u1=(int)t&0xfc; \
231 u2&=0xfc; \
232 t>>=16L; \
233 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
234 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
235 u3=(int)t>>8L; \
236 u1=(int)t&0xfc; \
237 u3&=0xfc; \
238 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
239 LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
240#endif
241#ifdef DES_RISC2
242#define D_ENCRYPT(LL,R,S) { \
243 unsigned int u1,u2,s1,s2; \
244 LOAD_DATA(R,S,u,t,E0,E1,u1); \
245 u2=(int)u>>8L; \
246 u1=(int)u&0xfc; \
247 u2&=0xfc; \
248 t=ROTATE(t,4); \
249 LL^= *(const DES_LONG *)(des_SP +u1); \
250 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
251 s1=(int)(u>>16L); \
252 s2=(int)(u>>24L); \
253 s1&=0xfc; \
254 s2&=0xfc; \
255 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
256 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
257 u2=(int)t>>8L; \
258 u1=(int)t&0xfc; \
259 u2&=0xfc; \
260 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
261 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
262 s1=(int)(t>>16L); \
263 s2=(int)(t>>24L); \
264 s1&=0xfc; \
265 s2&=0xfc; \
266 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
267 LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
268#endif
269#else
270#define D_ENCRYPT(LL,R,S) { \
271 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
272 t=ROTATE(t,4); \
273 LL^= \
274 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \
275 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
276 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
277 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
278 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
279 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
280 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
281 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
282#endif
283
284#else /* original version */
285
286#if defined(DES_RISC1) || defined(DES_RISC2)
287#ifdef DES_RISC1
288#define D_ENCRYPT(LL,R,S) {\
289 unsigned int u1,u2,u3; \
290 LOAD_DATA(R,S,u,t,E0,E1,u1); \
291 u>>=2L; \
292 t=ROTATE(t,6); \
293 u2=(int)u>>8L; \
294 u1=(int)u&0x3f; \
295 u2&=0x3f; \
296 u>>=16L; \
297 LL^=DES_SPtrans[0][u1]; \
298 LL^=DES_SPtrans[2][u2]; \
299 u3=(int)u>>8L; \
300 u1=(int)u&0x3f; \
301 u3&=0x3f; \
302 LL^=DES_SPtrans[4][u1]; \
303 LL^=DES_SPtrans[6][u3]; \
304 u2=(int)t>>8L; \
305 u1=(int)t&0x3f; \
306 u2&=0x3f; \
307 t>>=16L; \
308 LL^=DES_SPtrans[1][u1]; \
309 LL^=DES_SPtrans[3][u2]; \
310 u3=(int)t>>8L; \
311 u1=(int)t&0x3f; \
312 u3&=0x3f; \
313 LL^=DES_SPtrans[5][u1]; \
314 LL^=DES_SPtrans[7][u3]; }
315#endif
316#ifdef DES_RISC2
317#define D_ENCRYPT(LL,R,S) {\
318 unsigned int u1,u2,s1,s2; \
319 LOAD_DATA(R,S,u,t,E0,E1,u1); \
320 u>>=2L; \
321 t=ROTATE(t,6); \
322 u2=(int)u>>8L; \
323 u1=(int)u&0x3f; \
324 u2&=0x3f; \
325 LL^=DES_SPtrans[0][u1]; \
326 LL^=DES_SPtrans[2][u2]; \
327 s1=(int)u>>16L; \
328 s2=(int)u>>24L; \
329 s1&=0x3f; \
330 s2&=0x3f; \
331 LL^=DES_SPtrans[4][s1]; \
332 LL^=DES_SPtrans[6][s2]; \
333 u2=(int)t>>8L; \
334 u1=(int)t&0x3f; \
335 u2&=0x3f; \
336 LL^=DES_SPtrans[1][u1]; \
337 LL^=DES_SPtrans[3][u2]; \
338 s1=(int)t>>16; \
339 s2=(int)t>>24L; \
340 s1&=0x3f; \
341 s2&=0x3f; \
342 LL^=DES_SPtrans[5][s1]; \
343 LL^=DES_SPtrans[7][s2]; }
344#endif
345
346#else
347
348#define D_ENCRYPT(LL,R,S) {\
349 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
350 t=ROTATE(t,4); \
351 LL^=\
352 DES_SPtrans[0][(u>> 2L)&0x3f]^ \
353 DES_SPtrans[2][(u>>10L)&0x3f]^ \
354 DES_SPtrans[4][(u>>18L)&0x3f]^ \
355 DES_SPtrans[6][(u>>26L)&0x3f]^ \
356 DES_SPtrans[1][(t>> 2L)&0x3f]^ \
357 DES_SPtrans[3][(t>>10L)&0x3f]^ \
358 DES_SPtrans[5][(t>>18L)&0x3f]^ \
359 DES_SPtrans[7][(t>>26L)&0x3f]; }
360#endif
361#endif
362
363 /* IP and FP
364 * The problem is more of a geometric problem that random bit fiddling.
365 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
366 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
367 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
368 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
369
370 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
371 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
372 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
373 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
374
375 The output has been subject to swaps of the form
376 0 1 -> 3 1 but the odd and even bits have been put into
377 2 3 2 0
378 different words. The main trick is to remember that
379 t=((l>>size)^r)&(mask);
380 r^=t;
381 l^=(t<<size);
382 can be used to swap and move bits between words.
383
384 So l = 0 1 2 3 r = 16 17 18 19
385 4 5 6 7 20 21 22 23
386 8 9 10 11 24 25 26 27
387 12 13 14 15 28 29 30 31
388 becomes (for size == 2 and mask == 0x3333)
389 t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
390 6^20 7^21 -- -- 4 5 20 21 6 7 22 23
391 10^24 11^25 -- -- 8 9 24 25 10 11 24 25
392 14^28 15^29 -- -- 12 13 28 29 14 15 28 29
393
394 Thanks for hints from Richard Outerbridge - he told me IP&FP
395 could be done in 15 xor, 10 shifts and 5 ands.
396 When I finally started to think of the problem in 2D
397 I first got ~42 operations without xors. When I remembered
398 how to use xors :-) I got it to its final state.
399 */
400#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
401 (b)^=(t),\
402 (a)^=((t)<<(n)))
403
404#define IP(l,r) \
405 { \
406 register DES_LONG tt; \
407 PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
408 PERM_OP(l,r,tt,16,0x0000ffffL); \
409 PERM_OP(r,l,tt, 2,0x33333333L); \
410 PERM_OP(l,r,tt, 8,0x00ff00ffL); \
411 PERM_OP(r,l,tt, 1,0x55555555L); \
412 }
413
414#define FP(l,r) \
415 { \
416 register DES_LONG tt; \
417 PERM_OP(l,r,tt, 1,0x55555555L); \
418 PERM_OP(r,l,tt, 8,0x00ff00ffL); \
419 PERM_OP(l,r,tt, 2,0x33333333L); \
420 PERM_OP(r,l,tt,16,0x0000ffffL); \
421 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
422 }
423
424OPENSSL_EXTERN const DES_LONG DES_SPtrans[8][64];
425
426void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
427 DES_LONG Eswap0, DES_LONG Eswap1);
428#endif
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c
deleted file mode 100644
index c3437bc606..0000000000
--- a/src/lib/libcrypto/des/ecb3_enc.c
+++ /dev/null
@@ -1,83 +0,0 @@
1/* crypto/des/ecb3_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
62 DES_key_schedule *ks1, DES_key_schedule *ks2,
63 DES_key_schedule *ks3,
64 int enc)
65 {
66 register DES_LONG l0,l1;
67 DES_LONG ll[2];
68 const unsigned char *in = &(*input)[0];
69 unsigned char *out = &(*output)[0];
70
71 c2l(in,l0);
72 c2l(in,l1);
73 ll[0]=l0;
74 ll[1]=l1;
75 if (enc)
76 DES_encrypt3(ll,ks1,ks2,ks3);
77 else
78 DES_decrypt3(ll,ks1,ks2,ks3);
79 l0=ll[0];
80 l1=ll[1];
81 l2c(l0,out);
82 l2c(l1,out);
83 }
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c
deleted file mode 100644
index 784aa5ba23..0000000000
--- a/src/lib/libcrypto/des/ecb_enc.c
+++ /dev/null
@@ -1,123 +0,0 @@
1/* crypto/des/ecb_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60#include "des_ver.h"
61#include "spr.h"
62#include <openssl/opensslv.h>
63#include <openssl/bio.h>
64
65OPENSSL_GLOBAL const char *libdes_version="libdes" OPENSSL_VERSION_PTEXT;
66OPENSSL_GLOBAL const char *DES_version="DES" OPENSSL_VERSION_PTEXT;
67
68const char *DES_options(void)
69 {
70 static int init=1;
71 static char buf[32];
72
73 if (init)
74 {
75 const char *ptr,*unroll,*risc,*size;
76
77#ifdef DES_PTR
78 ptr="ptr";
79#else
80 ptr="idx";
81#endif
82#if defined(DES_RISC1) || defined(DES_RISC2)
83#ifdef DES_RISC1
84 risc="risc1";
85#endif
86#ifdef DES_RISC2
87 risc="risc2";
88#endif
89#else
90 risc="cisc";
91#endif
92#ifdef DES_UNROLL
93 unroll="16";
94#else
95 unroll="4";
96#endif
97 if (sizeof(DES_LONG) != sizeof(long))
98 size="int";
99 else
100 size="long";
101 BIO_snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,
102 size);
103 init=0;
104 }
105 return(buf);
106 }
107
108
109void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
110 DES_key_schedule *ks, int enc)
111 {
112 register DES_LONG l;
113 DES_LONG ll[2];
114 const unsigned char *in = &(*input)[0];
115 unsigned char *out = &(*output)[0];
116
117 c2l(in,l); ll[0]=l;
118 c2l(in,l); ll[1]=l;
119 DES_encrypt1(ll,ks,enc);
120 l=ll[0]; l2c(l,out);
121 l=ll[1]; l2c(l,out);
122 l=ll[0]=ll[1]=0;
123 }
diff --git a/src/lib/libcrypto/des/ede_cbcm_enc.c b/src/lib/libcrypto/des/ede_cbcm_enc.c
deleted file mode 100644
index fa45aa272b..0000000000
--- a/src/lib/libcrypto/des/ede_cbcm_enc.c
+++ /dev/null
@@ -1,197 +0,0 @@
1/* ede_cbcm_enc.c */
2/* Written by Ben Laurie <ben@algroup.co.uk> for the OpenSSL
3 * project 13 Feb 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/*
60
61This is an implementation of Triple DES Cipher Block Chaining with Output
62Feedback Masking, by Coppersmith, Johnson and Matyas, (IBM and Certicom).
63
64Note that there is a known attack on this by Biham and Knudsen but it takes
65a lot of work:
66
67http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/1998/CS/CS0928.ps.gz
68
69*/
70
71#ifndef OPENSSL_NO_DESCBCM
72#include "des_locl.h"
73
74void DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
75 long length, DES_key_schedule *ks1, DES_key_schedule *ks2,
76 DES_key_schedule *ks3, DES_cblock *ivec1, DES_cblock *ivec2,
77 int enc)
78 {
79 register DES_LONG tin0,tin1;
80 register DES_LONG tout0,tout1,xor0,xor1,m0,m1;
81 register long l=length;
82 DES_LONG tin[2];
83 unsigned char *iv1,*iv2;
84
85 iv1 = &(*ivec1)[0];
86 iv2 = &(*ivec2)[0];
87
88 if (enc)
89 {
90 c2l(iv1,m0);
91 c2l(iv1,m1);
92 c2l(iv2,tout0);
93 c2l(iv2,tout1);
94 for (l-=8; l>=-7; l-=8)
95 {
96 tin[0]=m0;
97 tin[1]=m1;
98 DES_encrypt1(tin,ks3,1);
99 m0=tin[0];
100 m1=tin[1];
101
102 if(l < 0)
103 {
104 c2ln(in,tin0,tin1,l+8);
105 }
106 else
107 {
108 c2l(in,tin0);
109 c2l(in,tin1);
110 }
111 tin0^=tout0;
112 tin1^=tout1;
113
114 tin[0]=tin0;
115 tin[1]=tin1;
116 DES_encrypt1(tin,ks1,1);
117 tin[0]^=m0;
118 tin[1]^=m1;
119 DES_encrypt1(tin,ks2,0);
120 tin[0]^=m0;
121 tin[1]^=m1;
122 DES_encrypt1(tin,ks1,1);
123 tout0=tin[0];
124 tout1=tin[1];
125
126 l2c(tout0,out);
127 l2c(tout1,out);
128 }
129 iv1=&(*ivec1)[0];
130 l2c(m0,iv1);
131 l2c(m1,iv1);
132
133 iv2=&(*ivec2)[0];
134 l2c(tout0,iv2);
135 l2c(tout1,iv2);
136 }
137 else
138 {
139 register DES_LONG t0,t1;
140
141 c2l(iv1,m0);
142 c2l(iv1,m1);
143 c2l(iv2,xor0);
144 c2l(iv2,xor1);
145 for (l-=8; l>=-7; l-=8)
146 {
147 tin[0]=m0;
148 tin[1]=m1;
149 DES_encrypt1(tin,ks3,1);
150 m0=tin[0];
151 m1=tin[1];
152
153 c2l(in,tin0);
154 c2l(in,tin1);
155
156 t0=tin0;
157 t1=tin1;
158
159 tin[0]=tin0;
160 tin[1]=tin1;
161 DES_encrypt1(tin,ks1,0);
162 tin[0]^=m0;
163 tin[1]^=m1;
164 DES_encrypt1(tin,ks2,1);
165 tin[0]^=m0;
166 tin[1]^=m1;
167 DES_encrypt1(tin,ks1,0);
168 tout0=tin[0];
169 tout1=tin[1];
170
171 tout0^=xor0;
172 tout1^=xor1;
173 if(l < 0)
174 {
175 l2cn(tout0,tout1,out,l+8);
176 }
177 else
178 {
179 l2c(tout0,out);
180 l2c(tout1,out);
181 }
182 xor0=t0;
183 xor1=t1;
184 }
185
186 iv1=&(*ivec1)[0];
187 l2c(m0,iv1);
188 l2c(m1,iv1);
189
190 iv2=&(*ivec2)[0];
191 l2c(xor0,iv2);
192 l2c(xor1,iv2);
193 }
194 tin0=tin1=tout0=tout1=xor0=xor1=0;
195 tin[0]=tin[1]=0;
196 }
197#endif
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c
deleted file mode 100644
index c70fb686b8..0000000000
--- a/src/lib/libcrypto/des/enc_read.c
+++ /dev/null
@@ -1,228 +0,0 @@
1/* crypto/des/enc_read.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include "des_locl.h"
63
64/* This has some uglies in it but it works - even over sockets. */
65/*extern int errno;*/
66OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode)=DES_PCBC_MODE;
67
68
69/*
70 * WARNINGS:
71 *
72 * - The data format used by DES_enc_write() and DES_enc_read()
73 * has a cryptographic weakness: When asked to write more
74 * than MAXWRITE bytes, DES_enc_write will split the data
75 * into several chunks that are all encrypted
76 * using the same IV. So don't use these functions unless you
77 * are sure you know what you do (in which case you might
78 * not want to use them anyway).
79 *
80 * - This code cannot handle non-blocking sockets.
81 *
82 * - This function uses an internal state and thus cannot be
83 * used on multiple files.
84 */
85
86
87int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
88 DES_cblock *iv)
89 {
90 /* data to be unencrypted */
91 int net_num=0;
92 static unsigned char *net=NULL;
93 /* extra unencrypted data
94 * for when a block of 100 comes in but is des_read one byte at
95 * a time. */
96 static unsigned char *unnet=NULL;
97 static int unnet_start=0;
98 static int unnet_left=0;
99 static unsigned char *tmpbuf=NULL;
100 int i;
101 long num=0,rnum;
102 unsigned char *p;
103
104 if (tmpbuf == NULL)
105 {
106 tmpbuf=OPENSSL_malloc(BSIZE);
107 if (tmpbuf == NULL) return(-1);
108 }
109 if (net == NULL)
110 {
111 net=OPENSSL_malloc(BSIZE);
112 if (net == NULL) return(-1);
113 }
114 if (unnet == NULL)
115 {
116 unnet=OPENSSL_malloc(BSIZE);
117 if (unnet == NULL) return(-1);
118 }
119 /* left over data from last decrypt */
120 if (unnet_left != 0)
121 {
122 if (unnet_left < len)
123 {
124 /* we still still need more data but will return
125 * with the number of bytes we have - should always
126 * check the return value */
127 memcpy(buf,&(unnet[unnet_start]),
128 unnet_left);
129 /* eay 26/08/92 I had the next 2 lines
130 * reversed :-( */
131 i=unnet_left;
132 unnet_start=unnet_left=0;
133 }
134 else
135 {
136 memcpy(buf,&(unnet[unnet_start]),len);
137 unnet_start+=len;
138 unnet_left-=len;
139 i=len;
140 }
141 return(i);
142 }
143
144 /* We need to get more data. */
145 if (len > MAXWRITE) len=MAXWRITE;
146
147 /* first - get the length */
148 while (net_num < HDRSIZE)
149 {
150 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
151#ifdef EINTR
152 if ((i == -1) && (errno == EINTR)) continue;
153#endif
154 if (i <= 0) return(0);
155 net_num+=i;
156 }
157
158 /* we now have at net_num bytes in net */
159 p=net;
160 /* num=0; */
161 n2l(p,num);
162 /* num should be rounded up to the next group of eight
163 * we make sure that we have read a multiple of 8 bytes from the net.
164 */
165 if ((num > MAXWRITE) || (num < 0)) /* error */
166 return(-1);
167 rnum=(num < 8)?8:((num+7)/8*8);
168
169 net_num=0;
170 while (net_num < rnum)
171 {
172 i=read(fd,(void *)&(net[net_num]),rnum-net_num);
173#ifdef EINTR
174 if ((i == -1) && (errno == EINTR)) continue;
175#endif
176 if (i <= 0) return(0);
177 net_num+=i;
178 }
179
180 /* Check if there will be data left over. */
181 if (len < num)
182 {
183 if (DES_rw_mode & DES_PCBC_MODE)
184 DES_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
185 else
186 DES_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
187 memcpy(buf,unnet,len);
188 unnet_start=len;
189 unnet_left=num-len;
190
191 /* The following line is done because we return num
192 * as the number of bytes read. */
193 num=len;
194 }
195 else
196 {
197 /* >output is a multiple of 8 byes, if len < rnum
198 * >we must be careful. The user must be aware that this
199 * >routine will write more bytes than he asked for.
200 * >The length of the buffer must be correct.
201 * FIXED - Should be ok now 18-9-90 - eay */
202 if (len < rnum)
203 {
204
205 if (DES_rw_mode & DES_PCBC_MODE)
206 DES_pcbc_encrypt(net,tmpbuf,num,sched,iv,
207 DES_DECRYPT);
208 else
209 DES_cbc_encrypt(net,tmpbuf,num,sched,iv,
210 DES_DECRYPT);
211
212 /* eay 26/08/92 fix a bug that returned more
213 * bytes than you asked for (returned len bytes :-( */
214 memcpy(buf,tmpbuf,num);
215 }
216 else
217 {
218 if (DES_rw_mode & DES_PCBC_MODE)
219 DES_pcbc_encrypt(net,buf,num,sched,iv,
220 DES_DECRYPT);
221 else
222 DES_cbc_encrypt(net,buf,num,sched,iv,
223 DES_DECRYPT);
224 }
225 }
226 return num;
227 }
228
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
deleted file mode 100644
index af5b8c2349..0000000000
--- a/src/lib/libcrypto/des/enc_writ.c
+++ /dev/null
@@ -1,171 +0,0 @@
1/* crypto/des/enc_writ.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <errno.h>
60#include <time.h>
61#include <stdio.h>
62#include "cryptlib.h"
63#include "des_locl.h"
64#include <openssl/rand.h>
65
66/*
67 * WARNINGS:
68 *
69 * - The data format used by DES_enc_write() and DES_enc_read()
70 * has a cryptographic weakness: When asked to write more
71 * than MAXWRITE bytes, DES_enc_write will split the data
72 * into several chunks that are all encrypted
73 * using the same IV. So don't use these functions unless you
74 * are sure you know what you do (in which case you might
75 * not want to use them anyway).
76 *
77 * - This code cannot handle non-blocking sockets.
78 */
79
80int DES_enc_write(int fd, const void *_buf, int len,
81 DES_key_schedule *sched, DES_cblock *iv)
82 {
83#ifdef _LIBC
84 extern unsigned long time();
85 extern int write();
86#endif
87 const unsigned char *buf=_buf;
88 long rnum;
89 int i,j,k,outnum;
90 static unsigned char *outbuf=NULL;
91 unsigned char shortbuf[8];
92 unsigned char *p;
93 const unsigned char *cp;
94 static int start=1;
95
96 if (outbuf == NULL)
97 {
98 outbuf=OPENSSL_malloc(BSIZE+HDRSIZE);
99 if (outbuf == NULL) return(-1);
100 }
101 /* If we are sending less than 8 bytes, the same char will look
102 * the same if we don't pad it out with random bytes */
103 if (start)
104 {
105 start=0;
106 }
107
108 /* lets recurse if we want to send the data in small chunks */
109 if (len > MAXWRITE)
110 {
111 j=0;
112 for (i=0; i<len; i+=k)
113 {
114 k=DES_enc_write(fd,&(buf[i]),
115 ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv);
116 if (k < 0)
117 return(k);
118 else
119 j+=k;
120 }
121 return(j);
122 }
123
124 /* write length first */
125 p=outbuf;
126 l2n(len,p);
127
128 /* pad short strings */
129 if (len < 8)
130 {
131 cp=shortbuf;
132 memcpy(shortbuf,buf,len);
133 RAND_pseudo_bytes(shortbuf+len, 8-len);
134 rnum=8;
135 }
136 else
137 {
138 cp=buf;
139 rnum=((len+7)/8*8); /* round up to nearest eight */
140 }
141
142 if (DES_rw_mode & DES_PCBC_MODE)
143 DES_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
144 DES_ENCRYPT);
145 else
146 DES_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
147 DES_ENCRYPT);
148
149 /* output */
150 outnum=rnum+HDRSIZE;
151
152 for (j=0; j<outnum; j+=i)
153 {
154 /* eay 26/08/92 I was not doing writing from where we
155 * got up to. */
156 i=write(fd,(void *)&(outbuf[j]),outnum-j);
157 if (i == -1)
158 {
159#ifdef EINTR
160 if (errno == EINTR)
161 i=0;
162 else
163#endif
164 /* This is really a bad error - very bad
165 * It will stuff-up both ends. */
166 return(-1);
167 }
168 }
169
170 return(len);
171 }
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
deleted file mode 100644
index 2758c32656..0000000000
--- a/src/lib/libcrypto/des/fcrypt.c
+++ /dev/null
@@ -1,173 +0,0 @@
1/* NOCW */
2#include <stdio.h>
3#ifdef _OSD_POSIX
4#ifndef CHARSET_EBCDIC
5#define CHARSET_EBCDIC 1
6#endif
7#endif
8#ifdef CHARSET_EBCDIC
9#include <openssl/ebcdic.h>
10#endif
11
12/* This version of crypt has been developed from my MIT compatible
13 * DES library.
14 * Eric Young (eay@cryptsoft.com)
15 */
16
17/* Modification by Jens Kupferschmidt (Cu)
18 * I have included directive PARA for shared memory computers.
19 * I have included a directive LONGCRYPT to using this routine to cipher
20 * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN
21 * definition is the maximum of length of password and can changed. I have
22 * defined 24.
23 */
24
25#include "des_locl.h"
26
27/* Added more values to handle illegal salt values the way normal
28 * crypt() implementations do. The patch was sent by
29 * Bjorn Gronvall <bg@sics.se>
30 */
31static unsigned const char con_salt[128]={
320xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,
330xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1,
340xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,
350xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,
360xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,
370xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01,
380x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
390x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A,
400x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,
410x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,
420x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,
430x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24,
440x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,
450x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,
460x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,
470x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44,
48};
49
50static unsigned const char cov_2char[64]={
510x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
520x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
530x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
540x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
550x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
560x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
570x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
580x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
59};
60
61void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
62 DES_LONG Eswap0, DES_LONG Eswap1);
63
64char *DES_crypt(const char *buf, const char *salt)
65 {
66 static char buff[14];
67
68#ifndef CHARSET_EBCDIC
69 return(DES_fcrypt(buf,salt,buff));
70#else
71 char e_salt[2+1];
72 char e_buf[32+1]; /* replace 32 by 8 ? */
73 char *ret;
74
75 /* Copy at most 2 chars of salt */
76 if ((e_salt[0] = salt[0]) != '\0')
77 e_salt[1] = salt[1];
78
79 /* Copy at most 32 chars of password */
80 strncpy (e_buf, buf, sizeof(e_buf));
81
82 /* Make sure we have a delimiter */
83 e_salt[sizeof(e_salt)-1] = e_buf[sizeof(e_buf)-1] = '\0';
84
85 /* Convert the e_salt to ASCII, as that's what DES_fcrypt works on */
86 ebcdic2ascii(e_salt, e_salt, sizeof e_salt);
87
88 /* Convert the cleartext password to ASCII */
89 ebcdic2ascii(e_buf, e_buf, sizeof e_buf);
90
91 /* Encrypt it (from/to ASCII) */
92 ret = DES_fcrypt(e_buf,e_salt,buff);
93
94 /* Convert the result back to EBCDIC */
95 ascii2ebcdic(ret, ret, strlen(ret));
96
97 return ret;
98#endif
99 }
100
101
102char *DES_fcrypt(const char *buf, const char *salt, char *ret)
103 {
104 unsigned int i,j,x,y;
105 DES_LONG Eswap0,Eswap1;
106 DES_LONG out[2],ll;
107 DES_cblock key;
108 DES_key_schedule ks;
109 unsigned char bb[9];
110 unsigned char *b=bb;
111 unsigned char c,u;
112
113 /* eay 25/08/92
114 * If you call crypt("pwd","*") as often happens when you
115 * have * as the pwd field in /etc/passwd, the function
116 * returns *\0XXXXXXXXX
117 * The \0 makes the string look like * so the pwd "*" would
118 * crypt to "*". This was found when replacing the crypt in
119 * our shared libraries. People found that the disabled
120 * accounts effectively had no passwd :-(. */
121#ifndef CHARSET_EBCDIC
122 x=ret[0]=((salt[0] == '\0')?'A':salt[0]);
123 Eswap0=con_salt[x]<<2;
124 x=ret[1]=((salt[1] == '\0')?'A':salt[1]);
125 Eswap1=con_salt[x]<<6;
126#else
127 x=ret[0]=((salt[0] == '\0')?os_toascii['A']:salt[0]);
128 Eswap0=con_salt[x]<<2;
129 x=ret[1]=((salt[1] == '\0')?os_toascii['A']:salt[1]);
130 Eswap1=con_salt[x]<<6;
131#endif
132
133/* EAY
134r=strlen(buf);
135r=(r+7)/8;
136*/
137 for (i=0; i<8; i++)
138 {
139 c= *(buf++);
140 if (!c) break;
141 key[i]=(c<<1);
142 }
143 for (; i<8; i++)
144 key[i]=0;
145
146 DES_set_key_unchecked(&key,&ks);
147 fcrypt_body(&(out[0]),&ks,Eswap0,Eswap1);
148
149 ll=out[0]; l2c(ll,b);
150 ll=out[1]; l2c(ll,b);
151 y=0;
152 u=0x80;
153 bb[8]=0;
154 for (i=2; i<13; i++)
155 {
156 c=0;
157 for (j=0; j<6; j++)
158 {
159 c<<=1;
160 if (bb[y] & u) c|=1;
161 u>>=1;
162 if (!u)
163 {
164 y++;
165 u=0x80;
166 }
167 }
168 ret[i]=cov_2char[c];
169 }
170 ret[13]='\0';
171 return(ret);
172 }
173
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
deleted file mode 100644
index 1390138787..0000000000
--- a/src/lib/libcrypto/des/fcrypt_b.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/* crypto/des/fcrypt_b.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60
61/* This version of crypt has been developed from my MIT compatible
62 * DES library.
63 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au
64 * Eric Young (eay@cryptsoft.com)
65 */
66
67#define DES_FCRYPT
68#include "des_locl.h"
69#undef DES_FCRYPT
70
71#undef PERM_OP
72#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
73 (b)^=(t),\
74 (a)^=((t)<<(n)))
75
76#undef HPERM_OP
77#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
78 (a)=(a)^(t)^(t>>(16-(n))))\
79
80void fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0,
81 DES_LONG Eswap1)
82 {
83 register DES_LONG l,r,t,u;
84#ifdef DES_PTR
85 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
86#endif
87 register DES_LONG *s;
88 register int j;
89 register DES_LONG E0,E1;
90
91 l=0;
92 r=0;
93
94 s=(DES_LONG *)ks;
95 E0=Eswap0;
96 E1=Eswap1;
97
98 for (j=0; j<25; j++)
99 {
100#ifndef DES_UNROLL
101 register int i;
102
103 for (i=0; i<32; i+=8)
104 {
105 D_ENCRYPT(l,r,i+0); /* 1 */
106 D_ENCRYPT(r,l,i+2); /* 2 */
107 D_ENCRYPT(l,r,i+4); /* 1 */
108 D_ENCRYPT(r,l,i+6); /* 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
diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c
deleted file mode 100644
index fda23d522f..0000000000
--- a/src/lib/libcrypto/des/ncbc_enc.c
+++ /dev/null
@@ -1,148 +0,0 @@
1/* crypto/des/ncbc_enc.c */
2/*
3 * #included by:
4 * cbc_enc.c (DES_cbc_encrypt)
5 * des_enc.c (DES_ncbc_encrypt)
6 */
7/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
8 * All rights reserved.
9 *
10 * This package is an SSL implementation written
11 * by Eric Young (eay@cryptsoft.com).
12 * The implementation was written so as to conform with Netscapes SSL.
13 *
14 * This library is free for commercial and non-commercial use as long as
15 * the following conditions are aheared to. The following conditions
16 * apply to all code found in this distribution, be it the RC4, RSA,
17 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
18 * included with this distribution is covered by the same copyright terms
19 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
20 *
21 * Copyright remains Eric Young's, and as such any Copyright notices in
22 * the code are not to be removed.
23 * If this package is used in a product, Eric Young should be given attribution
24 * as the author of the parts of the library used.
25 * This can be in the form of a textual message at program startup or
26 * in documentation (online or textual) provided with the package.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * "This product includes cryptographic software written by
39 * Eric Young (eay@cryptsoft.com)"
40 * The word 'cryptographic' can be left out if the rouines from the library
41 * being used are not cryptographic related :-).
42 * 4. If you include any Windows specific code (or a derivative thereof) from
43 * the apps directory (application code) you must include an acknowledgement:
44 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
45 *
46 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * The licence and distribution terms for any publically available version or
59 * derivative of this code cannot be changed. i.e. this code cannot simply be
60 * copied and put under another distribution licence
61 * [including the GNU Public Licence.]
62 */
63
64#include "des_locl.h"
65
66#ifdef CBC_ENC_C__DONT_UPDATE_IV
67void DES_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
68 DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
69#else
70void DES_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
71 DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
72#endif
73 {
74 register DES_LONG tin0,tin1;
75 register DES_LONG tout0,tout1,xor0,xor1;
76 register long l=length;
77 DES_LONG tin[2];
78 unsigned char *iv;
79
80 iv = &(*ivec)[0];
81
82 if (enc)
83 {
84 c2l(iv,tout0);
85 c2l(iv,tout1);
86 for (l-=8; l>=0; l-=8)
87 {
88 c2l(in,tin0);
89 c2l(in,tin1);
90 tin0^=tout0; tin[0]=tin0;
91 tin1^=tout1; tin[1]=tin1;
92 DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT);
93 tout0=tin[0]; l2c(tout0,out);
94 tout1=tin[1]; l2c(tout1,out);
95 }
96 if (l != -8)
97 {
98 c2ln(in,tin0,tin1,l+8);
99 tin0^=tout0; tin[0]=tin0;
100 tin1^=tout1; tin[1]=tin1;
101 DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT);
102 tout0=tin[0]; l2c(tout0,out);
103 tout1=tin[1]; l2c(tout1,out);
104 }
105#ifndef CBC_ENC_C__DONT_UPDATE_IV
106 iv = &(*ivec)[0];
107 l2c(tout0,iv);
108 l2c(tout1,iv);
109#endif
110 }
111 else
112 {
113 c2l(iv,xor0);
114 c2l(iv,xor1);
115 for (l-=8; l>=0; l-=8)
116 {
117 c2l(in,tin0); tin[0]=tin0;
118 c2l(in,tin1); tin[1]=tin1;
119 DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT);
120 tout0=tin[0]^xor0;
121 tout1=tin[1]^xor1;
122 l2c(tout0,out);
123 l2c(tout1,out);
124 xor0=tin0;
125 xor1=tin1;
126 }
127 if (l != -8)
128 {
129 c2l(in,tin0); tin[0]=tin0;
130 c2l(in,tin1); tin[1]=tin1;
131 DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT);
132 tout0=tin[0]^xor0;
133 tout1=tin[1]^xor1;
134 l2cn(tout0,tout1,out,l+8);
135#ifndef CBC_ENC_C__DONT_UPDATE_IV
136 xor0=tin0;
137 xor1=tin1;
138#endif
139 }
140#ifndef CBC_ENC_C__DONT_UPDATE_IV
141 iv = &(*ivec)[0];
142 l2c(xor0,iv);
143 l2c(xor1,iv);
144#endif
145 }
146 tin0=tin1=tout0=tout1=xor0=xor1=0;
147 tin[0]=tin[1]=0;
148 }
diff --git a/src/lib/libcrypto/des/ofb64ede.c b/src/lib/libcrypto/des/ofb64ede.c
deleted file mode 100644
index 26bbf9a6a7..0000000000
--- a/src/lib/libcrypto/des/ofb64ede.c
+++ /dev/null
@@ -1,125 +0,0 @@
1/* crypto/des/ofb64ede.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* The input and output encrypted as though 64bit ofb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65void DES_ede3_ofb64_encrypt(register const unsigned char *in,
66 register unsigned char *out, long length,
67 DES_key_schedule *k1, DES_key_schedule *k2,
68 DES_key_schedule *k3, DES_cblock *ivec,
69 int *num)
70 {
71 register DES_LONG v0,v1;
72 register int n= *num;
73 register long l=length;
74 DES_cblock d;
75 register char *dp;
76 DES_LONG ti[2];
77 unsigned char *iv;
78 int save=0;
79
80 iv = &(*ivec)[0];
81 c2l(iv,v0);
82 c2l(iv,v1);
83 ti[0]=v0;
84 ti[1]=v1;
85 dp=(char *)d;
86 l2c(v0,dp);
87 l2c(v1,dp);
88 while (l--)
89 {
90 if (n == 0)
91 {
92 /* ti[0]=v0; */
93 /* ti[1]=v1; */
94 DES_encrypt3(ti,k1,k2,k3);
95 v0=ti[0];
96 v1=ti[1];
97
98 dp=(char *)d;
99 l2c(v0,dp);
100 l2c(v1,dp);
101 save++;
102 }
103 *(out++)= *(in++)^d[n];
104 n=(n+1)&0x07;
105 }
106 if (save)
107 {
108/* v0=ti[0];
109 v1=ti[1];*/
110 iv = &(*ivec)[0];
111 l2c(v0,iv);
112 l2c(v1,iv);
113 }
114 v0=v1=ti[0]=ti[1]=0;
115 *num=n;
116 }
117
118#ifdef undef /* MACRO */
119void DES_ede2_ofb64_encrypt(register unsigned char *in,
120 register unsigned char *out, long length, DES_key_schedule k1,
121 DES_key_schedule k2, DES_cblock (*ivec), int *num)
122 {
123 DES_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num);
124 }
125#endif
diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c
deleted file mode 100644
index 8ca3d49dea..0000000000
--- a/src/lib/libcrypto/des/ofb64enc.c
+++ /dev/null
@@ -1,110 +0,0 @@
1/* crypto/des/ofb64enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* The input and output encrypted as though 64bit ofb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65void DES_ofb64_encrypt(register const unsigned char *in,
66 register unsigned char *out, long length,
67 DES_key_schedule *schedule, DES_cblock *ivec, int *num)
68 {
69 register DES_LONG v0,v1,t;
70 register int n= *num;
71 register long l=length;
72 DES_cblock d;
73 register unsigned char *dp;
74 DES_LONG ti[2];
75 unsigned char *iv;
76 int save=0;
77
78 iv = &(*ivec)[0];
79 c2l(iv,v0);
80 c2l(iv,v1);
81 ti[0]=v0;
82 ti[1]=v1;
83 dp=d;
84 l2c(v0,dp);
85 l2c(v1,dp);
86 while (l--)
87 {
88 if (n == 0)
89 {
90 DES_encrypt1(ti,schedule,DES_ENCRYPT);
91 dp=d;
92 t=ti[0]; l2c(t,dp);
93 t=ti[1]; l2c(t,dp);
94 save++;
95 }
96 *(out++)= *(in++)^d[n];
97 n=(n+1)&0x07;
98 }
99 if (save)
100 {
101 v0=ti[0];
102 v1=ti[1];
103 iv = &(*ivec)[0];
104 l2c(v0,iv);
105 l2c(v1,iv);
106 }
107 t=v0=v1=ti[0]=ti[1]=0;
108 *num=n;
109 }
110
diff --git a/src/lib/libcrypto/des/ofb_enc.c b/src/lib/libcrypto/des/ofb_enc.c
deleted file mode 100644
index e887a3c6f4..0000000000
--- a/src/lib/libcrypto/des/ofb_enc.c
+++ /dev/null
@@ -1,135 +0,0 @@
1/* crypto/des/ofb_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* The input and output are loaded in multiples of 8 bits.
62 * What this means is that if you hame numbits=12 and length=2
63 * the first 12 bits will be retrieved from the first byte and half
64 * the second. The second 12 bits will come from the 3rd and half the 4th
65 * byte.
66 */
67void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
68 long length, DES_key_schedule *schedule,
69 DES_cblock *ivec)
70 {
71 register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8;
72 register DES_LONG mask0,mask1;
73 register long l=length;
74 register int num=numbits;
75 DES_LONG ti[2];
76 unsigned char *iv;
77
78 if (num > 64) return;
79 if (num > 32)
80 {
81 mask0=0xffffffffL;
82 if (num >= 64)
83 mask1=mask0;
84 else
85 mask1=(1L<<(num-32))-1;
86 }
87 else
88 {
89 if (num == 32)
90 mask0=0xffffffffL;
91 else
92 mask0=(1L<<num)-1;
93 mask1=0x00000000L;
94 }
95
96 iv = &(*ivec)[0];
97 c2l(iv,v0);
98 c2l(iv,v1);
99 ti[0]=v0;
100 ti[1]=v1;
101 while (l-- > 0)
102 {
103 ti[0]=v0;
104 ti[1]=v1;
105 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
106 vv0=ti[0];
107 vv1=ti[1];
108 c2ln(in,d0,d1,n);
109 in+=n;
110 d0=(d0^vv0)&mask0;
111 d1=(d1^vv1)&mask1;
112 l2cn(d0,d1,out,n);
113 out+=n;
114
115 if (num == 32)
116 { v0=v1; v1=vv0; }
117 else if (num == 64)
118 { v0=vv0; v1=vv1; }
119 else if (num > 32) /* && num != 64 */
120 {
121 v0=((v1>>(num-32))|(vv0<<(64-num)))&0xffffffffL;
122 v1=((vv0>>(num-32))|(vv1<<(64-num)))&0xffffffffL;
123 }
124 else /* num < 32 */
125 {
126 v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL;
127 v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL;
128 }
129 }
130 iv = &(*ivec)[0];
131 l2c(v0,iv);
132 l2c(v1,iv);
133 v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0;
134 }
135
diff --git a/src/lib/libcrypto/des/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c
deleted file mode 100644
index 17a40f9520..0000000000
--- a/src/lib/libcrypto/des/pcbc_enc.c
+++ /dev/null
@@ -1,123 +0,0 @@
1/* crypto/des/pcbc_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
62 long length, DES_key_schedule *schedule,
63 DES_cblock *ivec, int enc)
64 {
65 register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1;
66 DES_LONG tin[2];
67 const unsigned char *in;
68 unsigned char *out,*iv;
69
70 in=input;
71 out=output;
72 iv = &(*ivec)[0];
73
74 if (enc)
75 {
76 c2l(iv,xor0);
77 c2l(iv,xor1);
78 for (; length>0; length-=8)
79 {
80 if (length >= 8)
81 {
82 c2l(in,sin0);
83 c2l(in,sin1);
84 }
85 else
86 c2ln(in,sin0,sin1,length);
87 tin[0]=sin0^xor0;
88 tin[1]=sin1^xor1;
89 DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT);
90 tout0=tin[0];
91 tout1=tin[1];
92 xor0=sin0^tout0;
93 xor1=sin1^tout1;
94 l2c(tout0,out);
95 l2c(tout1,out);
96 }
97 }
98 else
99 {
100 c2l(iv,xor0); c2l(iv,xor1);
101 for (; length>0; length-=8)
102 {
103 c2l(in,sin0);
104 c2l(in,sin1);
105 tin[0]=sin0;
106 tin[1]=sin1;
107 DES_encrypt1((DES_LONG *)tin,schedule,DES_DECRYPT);
108 tout0=tin[0]^xor0;
109 tout1=tin[1]^xor1;
110 if (length >= 8)
111 {
112 l2c(tout0,out);
113 l2c(tout1,out);
114 }
115 else
116 l2cn(tout0,tout1,out,length);
117 xor0=tout0^sin0;
118 xor1=tout1^sin1;
119 }
120 }
121 tin[0]=tin[1]=0;
122 sin0=sin1=xor0=xor1=tout0=tout1=0;
123 }
diff --git a/src/lib/libcrypto/des/qud_cksm.c b/src/lib/libcrypto/des/qud_cksm.c
deleted file mode 100644
index dac201227e..0000000000
--- a/src/lib/libcrypto/des/qud_cksm.c
+++ /dev/null
@@ -1,139 +0,0 @@
1/* crypto/des/qud_cksm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* From "Message Authentication" R.R. Jueneman, S.M. Matyas, C.H. Meyer
60 * IEEE Communications Magazine Sept 1985 Vol. 23 No. 9 p 29-40
61 * This module in only based on the code in this paper and is
62 * almost definitely not the same as the MIT implementation.
63 */
64#include "des_locl.h"
65
66/* bug fix for dos - 7/6/91 - Larry hughes@logos.ucs.indiana.edu */
67#define Q_B0(a) (((DES_LONG)(a)))
68#define Q_B1(a) (((DES_LONG)(a))<<8)
69#define Q_B2(a) (((DES_LONG)(a))<<16)
70#define Q_B3(a) (((DES_LONG)(a))<<24)
71
72/* used to scramble things a bit */
73/* Got the value MIT uses via brute force :-) 2/10/90 eay */
74#define NOISE ((DES_LONG)83653421L)
75
76DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
77 long length, int out_count, DES_cblock *seed)
78 {
79 DES_LONG z0,z1,t0,t1;
80 int i;
81 long l;
82 const unsigned char *cp;
83#ifdef _CRAY
84 struct lp_st { int a:32; int b:32; } *lp;
85#else
86 DES_LONG *lp;
87#endif
88
89 if (out_count < 1) out_count=1;
90#ifdef _CRAY
91 lp = (struct lp_st *) &(output[0])[0];
92#else
93 lp = (DES_LONG *) &(output[0])[0];
94#endif
95
96 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]);
97 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]);
98
99 for (i=0; ((i<4)&&(i<out_count)); i++)
100 {
101 cp=input;
102 l=length;
103 while (l > 0)
104 {
105 if (l > 1)
106 {
107 t0= (DES_LONG)(*(cp++));
108 t0|=(DES_LONG)Q_B1(*(cp++));
109 l--;
110 }
111 else
112 t0= (DES_LONG)(*(cp++));
113 l--;
114 /* add */
115 t0+=z0;
116 t0&=0xffffffffL;
117 t1=z1;
118 /* square, well sort of square */
119 z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL))
120 &0xffffffffL)%0x7fffffffL;
121 z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL;
122 }
123 if (lp != NULL)
124 {
125 /* The MIT library assumes that the checksum is
126 * composed of 2*out_count 32 bit ints */
127#ifdef _CRAY
128 (*lp).a = z0;
129 (*lp).b = z1;
130 lp++;
131#else
132 *lp++ = z0;
133 *lp++ = z1;
134#endif
135 }
136 }
137 return(z0);
138 }
139
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c
deleted file mode 100644
index 2398165568..0000000000
--- a/src/lib/libcrypto/des/rand_key.c
+++ /dev/null
@@ -1,68 +0,0 @@
1/* crypto/des/rand_key.c */
2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/des.h>
57#include <openssl/rand.h>
58
59int DES_random_key(DES_cblock *ret)
60 {
61 do
62 {
63 if (RAND_bytes((unsigned char *)ret, sizeof(DES_cblock)) != 1)
64 return (0);
65 } while (DES_is_weak_key(ret));
66 DES_set_odd_parity(ret);
67 return (1);
68 }
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
deleted file mode 100644
index 143008ed9c..0000000000
--- a/src/lib/libcrypto/des/set_key.c
+++ /dev/null
@@ -1,407 +0,0 @@
1/* crypto/des/set_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* set_key.c v 1.4 eay 24/9/91
60 * 1.4 Speed up by 400% :-)
61 * 1.3 added register declarations.
62 * 1.2 unrolled make_key_sched a bit more
63 * 1.1 added norm_expand_bits
64 * 1.0 First working version
65 */
66#include "des_locl.h"
67
68OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key); /* defaults to false */
69
70static const unsigned char odd_parity[256]={
71 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
72 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
73 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
74 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
75 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
76 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
77 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
78112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
79128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
80145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
81161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
82176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
83193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
84208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
85224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
86241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254};
87
88void DES_set_odd_parity(DES_cblock *key)
89 {
90 int i;
91
92 for (i=0; i<DES_KEY_SZ; i++)
93 (*key)[i]=odd_parity[(*key)[i]];
94 }
95
96int DES_check_key_parity(const_DES_cblock *key)
97 {
98 int i;
99
100 for (i=0; i<DES_KEY_SZ; i++)
101 {
102 if ((*key)[i] != odd_parity[(*key)[i]])
103 return(0);
104 }
105 return(1);
106 }
107
108/* Weak and semi week keys as take from
109 * %A D.W. Davies
110 * %A W.L. Price
111 * %T Security for Computer Networks
112 * %I John Wiley & Sons
113 * %D 1984
114 * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
115 * (and actual cblock values).
116 */
117#define NUM_WEAK_KEY 16
118static DES_cblock weak_keys[NUM_WEAK_KEY]={
119 /* weak keys */
120 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
121 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
122 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
123 {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
124 /* semi-weak keys */
125 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
126 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
127 {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
128 {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
129 {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
130 {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
131 {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
132 {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
133 {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
134 {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
135 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
136 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
137
138int DES_is_weak_key(const_DES_cblock *key)
139 {
140 int i;
141
142 for (i=0; i<NUM_WEAK_KEY; i++)
143 /* Added == 0 to comparison, I obviously don't run
144 * this section very often :-(, thanks to
145 * engineering@MorningStar.Com for the fix
146 * eay 93/06/29
147 * Another problem, I was comparing only the first 4
148 * bytes, 97/03/18 */
149 if (memcmp(weak_keys[i],key,sizeof(DES_cblock)) == 0) return(1);
150 return(0);
151 }
152
153/* NOW DEFINED IN des_local.h
154 * See ecb_encrypt.c for a pseudo description of these macros.
155 * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
156 * (b)^=(t),\
157 * (a)=((a)^((t)<<(n))))
158 */
159
160#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
161 (a)=(a)^(t)^(t>>(16-(n))))
162
163static const DES_LONG des_skb[8][64]={
164 {
165 /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
166 0x00000000L,0x00000010L,0x20000000L,0x20000010L,
167 0x00010000L,0x00010010L,0x20010000L,0x20010010L,
168 0x00000800L,0x00000810L,0x20000800L,0x20000810L,
169 0x00010800L,0x00010810L,0x20010800L,0x20010810L,
170 0x00000020L,0x00000030L,0x20000020L,0x20000030L,
171 0x00010020L,0x00010030L,0x20010020L,0x20010030L,
172 0x00000820L,0x00000830L,0x20000820L,0x20000830L,
173 0x00010820L,0x00010830L,0x20010820L,0x20010830L,
174 0x00080000L,0x00080010L,0x20080000L,0x20080010L,
175 0x00090000L,0x00090010L,0x20090000L,0x20090010L,
176 0x00080800L,0x00080810L,0x20080800L,0x20080810L,
177 0x00090800L,0x00090810L,0x20090800L,0x20090810L,
178 0x00080020L,0x00080030L,0x20080020L,0x20080030L,
179 0x00090020L,0x00090030L,0x20090020L,0x20090030L,
180 0x00080820L,0x00080830L,0x20080820L,0x20080830L,
181 0x00090820L,0x00090830L,0x20090820L,0x20090830L,
182 },{
183 /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
184 0x00000000L,0x02000000L,0x00002000L,0x02002000L,
185 0x00200000L,0x02200000L,0x00202000L,0x02202000L,
186 0x00000004L,0x02000004L,0x00002004L,0x02002004L,
187 0x00200004L,0x02200004L,0x00202004L,0x02202004L,
188 0x00000400L,0x02000400L,0x00002400L,0x02002400L,
189 0x00200400L,0x02200400L,0x00202400L,0x02202400L,
190 0x00000404L,0x02000404L,0x00002404L,0x02002404L,
191 0x00200404L,0x02200404L,0x00202404L,0x02202404L,
192 0x10000000L,0x12000000L,0x10002000L,0x12002000L,
193 0x10200000L,0x12200000L,0x10202000L,0x12202000L,
194 0x10000004L,0x12000004L,0x10002004L,0x12002004L,
195 0x10200004L,0x12200004L,0x10202004L,0x12202004L,
196 0x10000400L,0x12000400L,0x10002400L,0x12002400L,
197 0x10200400L,0x12200400L,0x10202400L,0x12202400L,
198 0x10000404L,0x12000404L,0x10002404L,0x12002404L,
199 0x10200404L,0x12200404L,0x10202404L,0x12202404L,
200 },{
201 /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
202 0x00000000L,0x00000001L,0x00040000L,0x00040001L,
203 0x01000000L,0x01000001L,0x01040000L,0x01040001L,
204 0x00000002L,0x00000003L,0x00040002L,0x00040003L,
205 0x01000002L,0x01000003L,0x01040002L,0x01040003L,
206 0x00000200L,0x00000201L,0x00040200L,0x00040201L,
207 0x01000200L,0x01000201L,0x01040200L,0x01040201L,
208 0x00000202L,0x00000203L,0x00040202L,0x00040203L,
209 0x01000202L,0x01000203L,0x01040202L,0x01040203L,
210 0x08000000L,0x08000001L,0x08040000L,0x08040001L,
211 0x09000000L,0x09000001L,0x09040000L,0x09040001L,
212 0x08000002L,0x08000003L,0x08040002L,0x08040003L,
213 0x09000002L,0x09000003L,0x09040002L,0x09040003L,
214 0x08000200L,0x08000201L,0x08040200L,0x08040201L,
215 0x09000200L,0x09000201L,0x09040200L,0x09040201L,
216 0x08000202L,0x08000203L,0x08040202L,0x08040203L,
217 0x09000202L,0x09000203L,0x09040202L,0x09040203L,
218 },{
219 /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
220 0x00000000L,0x00100000L,0x00000100L,0x00100100L,
221 0x00000008L,0x00100008L,0x00000108L,0x00100108L,
222 0x00001000L,0x00101000L,0x00001100L,0x00101100L,
223 0x00001008L,0x00101008L,0x00001108L,0x00101108L,
224 0x04000000L,0x04100000L,0x04000100L,0x04100100L,
225 0x04000008L,0x04100008L,0x04000108L,0x04100108L,
226 0x04001000L,0x04101000L,0x04001100L,0x04101100L,
227 0x04001008L,0x04101008L,0x04001108L,0x04101108L,
228 0x00020000L,0x00120000L,0x00020100L,0x00120100L,
229 0x00020008L,0x00120008L,0x00020108L,0x00120108L,
230 0x00021000L,0x00121000L,0x00021100L,0x00121100L,
231 0x00021008L,0x00121008L,0x00021108L,0x00121108L,
232 0x04020000L,0x04120000L,0x04020100L,0x04120100L,
233 0x04020008L,0x04120008L,0x04020108L,0x04120108L,
234 0x04021000L,0x04121000L,0x04021100L,0x04121100L,
235 0x04021008L,0x04121008L,0x04021108L,0x04121108L,
236 },{
237 /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
238 0x00000000L,0x10000000L,0x00010000L,0x10010000L,
239 0x00000004L,0x10000004L,0x00010004L,0x10010004L,
240 0x20000000L,0x30000000L,0x20010000L,0x30010000L,
241 0x20000004L,0x30000004L,0x20010004L,0x30010004L,
242 0x00100000L,0x10100000L,0x00110000L,0x10110000L,
243 0x00100004L,0x10100004L,0x00110004L,0x10110004L,
244 0x20100000L,0x30100000L,0x20110000L,0x30110000L,
245 0x20100004L,0x30100004L,0x20110004L,0x30110004L,
246 0x00001000L,0x10001000L,0x00011000L,0x10011000L,
247 0x00001004L,0x10001004L,0x00011004L,0x10011004L,
248 0x20001000L,0x30001000L,0x20011000L,0x30011000L,
249 0x20001004L,0x30001004L,0x20011004L,0x30011004L,
250 0x00101000L,0x10101000L,0x00111000L,0x10111000L,
251 0x00101004L,0x10101004L,0x00111004L,0x10111004L,
252 0x20101000L,0x30101000L,0x20111000L,0x30111000L,
253 0x20101004L,0x30101004L,0x20111004L,0x30111004L,
254 },{
255 /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
256 0x00000000L,0x08000000L,0x00000008L,0x08000008L,
257 0x00000400L,0x08000400L,0x00000408L,0x08000408L,
258 0x00020000L,0x08020000L,0x00020008L,0x08020008L,
259 0x00020400L,0x08020400L,0x00020408L,0x08020408L,
260 0x00000001L,0x08000001L,0x00000009L,0x08000009L,
261 0x00000401L,0x08000401L,0x00000409L,0x08000409L,
262 0x00020001L,0x08020001L,0x00020009L,0x08020009L,
263 0x00020401L,0x08020401L,0x00020409L,0x08020409L,
264 0x02000000L,0x0A000000L,0x02000008L,0x0A000008L,
265 0x02000400L,0x0A000400L,0x02000408L,0x0A000408L,
266 0x02020000L,0x0A020000L,0x02020008L,0x0A020008L,
267 0x02020400L,0x0A020400L,0x02020408L,0x0A020408L,
268 0x02000001L,0x0A000001L,0x02000009L,0x0A000009L,
269 0x02000401L,0x0A000401L,0x02000409L,0x0A000409L,
270 0x02020001L,0x0A020001L,0x02020009L,0x0A020009L,
271 0x02020401L,0x0A020401L,0x02020409L,0x0A020409L,
272 },{
273 /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
274 0x00000000L,0x00000100L,0x00080000L,0x00080100L,
275 0x01000000L,0x01000100L,0x01080000L,0x01080100L,
276 0x00000010L,0x00000110L,0x00080010L,0x00080110L,
277 0x01000010L,0x01000110L,0x01080010L,0x01080110L,
278 0x00200000L,0x00200100L,0x00280000L,0x00280100L,
279 0x01200000L,0x01200100L,0x01280000L,0x01280100L,
280 0x00200010L,0x00200110L,0x00280010L,0x00280110L,
281 0x01200010L,0x01200110L,0x01280010L,0x01280110L,
282 0x00000200L,0x00000300L,0x00080200L,0x00080300L,
283 0x01000200L,0x01000300L,0x01080200L,0x01080300L,
284 0x00000210L,0x00000310L,0x00080210L,0x00080310L,
285 0x01000210L,0x01000310L,0x01080210L,0x01080310L,
286 0x00200200L,0x00200300L,0x00280200L,0x00280300L,
287 0x01200200L,0x01200300L,0x01280200L,0x01280300L,
288 0x00200210L,0x00200310L,0x00280210L,0x00280310L,
289 0x01200210L,0x01200310L,0x01280210L,0x01280310L,
290 },{
291 /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
292 0x00000000L,0x04000000L,0x00040000L,0x04040000L,
293 0x00000002L,0x04000002L,0x00040002L,0x04040002L,
294 0x00002000L,0x04002000L,0x00042000L,0x04042000L,
295 0x00002002L,0x04002002L,0x00042002L,0x04042002L,
296 0x00000020L,0x04000020L,0x00040020L,0x04040020L,
297 0x00000022L,0x04000022L,0x00040022L,0x04040022L,
298 0x00002020L,0x04002020L,0x00042020L,0x04042020L,
299 0x00002022L,0x04002022L,0x00042022L,0x04042022L,
300 0x00000800L,0x04000800L,0x00040800L,0x04040800L,
301 0x00000802L,0x04000802L,0x00040802L,0x04040802L,
302 0x00002800L,0x04002800L,0x00042800L,0x04042800L,
303 0x00002802L,0x04002802L,0x00042802L,0x04042802L,
304 0x00000820L,0x04000820L,0x00040820L,0x04040820L,
305 0x00000822L,0x04000822L,0x00040822L,0x04040822L,
306 0x00002820L,0x04002820L,0x00042820L,0x04042820L,
307 0x00002822L,0x04002822L,0x00042822L,0x04042822L,
308 }};
309
310int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule)
311 {
312 if (DES_check_key)
313 {
314 return DES_set_key_checked(key, schedule);
315 }
316 else
317 {
318 DES_set_key_unchecked(key, schedule);
319 return 0;
320 }
321 }
322
323/* return 0 if key parity is odd (correct),
324 * return -1 if key parity error,
325 * return -2 if illegal weak key.
326 */
327int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule)
328 {
329 if (!DES_check_key_parity(key))
330 return(-1);
331 if (DES_is_weak_key(key))
332 return(-2);
333 DES_set_key_unchecked(key, schedule);
334 return 0;
335 }
336
337void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
338 {
339 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
340 register DES_LONG c,d,t,s,t2;
341 register const unsigned char *in;
342 register DES_LONG *k;
343 register int i;
344
345#ifdef OPENBSD_DEV_CRYPTO
346 memcpy(schedule->key,key,sizeof schedule->key);
347 schedule->session=NULL;
348#endif
349 k = &schedule->ks->deslong[0];
350 in = &(*key)[0];
351
352 c2l(in,c);
353 c2l(in,d);
354
355 /* do PC1 in 47 simple operations :-)
356 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
357 * for the inspiration. :-) */
358 PERM_OP (d,c,t,4,0x0f0f0f0fL);
359 HPERM_OP(c,t,-2,0xcccc0000L);
360 HPERM_OP(d,t,-2,0xcccc0000L);
361 PERM_OP (d,c,t,1,0x55555555L);
362 PERM_OP (c,d,t,8,0x00ff00ffL);
363 PERM_OP (d,c,t,1,0x55555555L);
364 d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) |
365 ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
366 c&=0x0fffffffL;
367
368 for (i=0; i<ITERATIONS; i++)
369 {
370 if (shifts2[i])
371 { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
372 else
373 { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); }
374 c&=0x0fffffffL;
375 d&=0x0fffffffL;
376 /* could be a few less shifts but I am to lazy at this
377 * point in time to investigate */
378 s= des_skb[0][ (c )&0x3f ]|
379 des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
380 des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
381 des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
382 ((c>>22L)&0x38)];
383 t= des_skb[4][ (d )&0x3f ]|
384 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
385 des_skb[6][ (d>>15L)&0x3f ]|
386 des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
387
388 /* table contained 0213 4657 */
389 t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
390 *(k++)=ROTATE(t2,30)&0xffffffffL;
391
392 t2=((s>>16L)|(t&0xffff0000L));
393 *(k++)=ROTATE(t2,26)&0xffffffffL;
394 }
395 }
396
397int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule)
398 {
399 return(DES_set_key(key,schedule));
400 }
401/*
402#undef des_fixup_key_parity
403void des_fixup_key_parity(des_cblock *key)
404 {
405 des_set_odd_parity(key);
406 }
407*/
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h
deleted file mode 100644
index b91936a5a5..0000000000
--- a/src/lib/libcrypto/des/spr.h
+++ /dev/null
@@ -1,204 +0,0 @@
1/* crypto/des/spr.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59OPENSSL_GLOBAL const DES_LONG DES_SPtrans[8][64]={
60{
61/* nibble 0 */
620x02080800L, 0x00080000L, 0x02000002L, 0x02080802L,
630x02000000L, 0x00080802L, 0x00080002L, 0x02000002L,
640x00080802L, 0x02080800L, 0x02080000L, 0x00000802L,
650x02000802L, 0x02000000L, 0x00000000L, 0x00080002L,
660x00080000L, 0x00000002L, 0x02000800L, 0x00080800L,
670x02080802L, 0x02080000L, 0x00000802L, 0x02000800L,
680x00000002L, 0x00000800L, 0x00080800L, 0x02080002L,
690x00000800L, 0x02000802L, 0x02080002L, 0x00000000L,
700x00000000L, 0x02080802L, 0x02000800L, 0x00080002L,
710x02080800L, 0x00080000L, 0x00000802L, 0x02000800L,
720x02080002L, 0x00000800L, 0x00080800L, 0x02000002L,
730x00080802L, 0x00000002L, 0x02000002L, 0x02080000L,
740x02080802L, 0x00080800L, 0x02080000L, 0x02000802L,
750x02000000L, 0x00000802L, 0x00080002L, 0x00000000L,
760x00080000L, 0x02000000L, 0x02000802L, 0x02080800L,
770x00000002L, 0x02080002L, 0x00000800L, 0x00080802L,
78},{
79/* nibble 1 */
800x40108010L, 0x00000000L, 0x00108000L, 0x40100000L,
810x40000010L, 0x00008010L, 0x40008000L, 0x00108000L,
820x00008000L, 0x40100010L, 0x00000010L, 0x40008000L,
830x00100010L, 0x40108000L, 0x40100000L, 0x00000010L,
840x00100000L, 0x40008010L, 0x40100010L, 0x00008000L,
850x00108010L, 0x40000000L, 0x00000000L, 0x00100010L,
860x40008010L, 0x00108010L, 0x40108000L, 0x40000010L,
870x40000000L, 0x00100000L, 0x00008010L, 0x40108010L,
880x00100010L, 0x40108000L, 0x40008000L, 0x00108010L,
890x40108010L, 0x00100010L, 0x40000010L, 0x00000000L,
900x40000000L, 0x00008010L, 0x00100000L, 0x40100010L,
910x00008000L, 0x40000000L, 0x00108010L, 0x40008010L,
920x40108000L, 0x00008000L, 0x00000000L, 0x40000010L,
930x00000010L, 0x40108010L, 0x00108000L, 0x40100000L,
940x40100010L, 0x00100000L, 0x00008010L, 0x40008000L,
950x40008010L, 0x00000010L, 0x40100000L, 0x00108000L,
96},{
97/* nibble 2 */
980x04000001L, 0x04040100L, 0x00000100L, 0x04000101L,
990x00040001L, 0x04000000L, 0x04000101L, 0x00040100L,
1000x04000100L, 0x00040000L, 0x04040000L, 0x00000001L,
1010x04040101L, 0x00000101L, 0x00000001L, 0x04040001L,
1020x00000000L, 0x00040001L, 0x04040100L, 0x00000100L,
1030x00000101L, 0x04040101L, 0x00040000L, 0x04000001L,
1040x04040001L, 0x04000100L, 0x00040101L, 0x04040000L,
1050x00040100L, 0x00000000L, 0x04000000L, 0x00040101L,
1060x04040100L, 0x00000100L, 0x00000001L, 0x00040000L,
1070x00000101L, 0x00040001L, 0x04040000L, 0x04000101L,
1080x00000000L, 0x04040100L, 0x00040100L, 0x04040001L,
1090x00040001L, 0x04000000L, 0x04040101L, 0x00000001L,
1100x00040101L, 0x04000001L, 0x04000000L, 0x04040101L,
1110x00040000L, 0x04000100L, 0x04000101L, 0x00040100L,
1120x04000100L, 0x00000000L, 0x04040001L, 0x00000101L,
1130x04000001L, 0x00040101L, 0x00000100L, 0x04040000L,
114},{
115/* nibble 3 */
1160x00401008L, 0x10001000L, 0x00000008L, 0x10401008L,
1170x00000000L, 0x10400000L, 0x10001008L, 0x00400008L,
1180x10401000L, 0x10000008L, 0x10000000L, 0x00001008L,
1190x10000008L, 0x00401008L, 0x00400000L, 0x10000000L,
1200x10400008L, 0x00401000L, 0x00001000L, 0x00000008L,
1210x00401000L, 0x10001008L, 0x10400000L, 0x00001000L,
1220x00001008L, 0x00000000L, 0x00400008L, 0x10401000L,
1230x10001000L, 0x10400008L, 0x10401008L, 0x00400000L,
1240x10400008L, 0x00001008L, 0x00400000L, 0x10000008L,
1250x00401000L, 0x10001000L, 0x00000008L, 0x10400000L,
1260x10001008L, 0x00000000L, 0x00001000L, 0x00400008L,
1270x00000000L, 0x10400008L, 0x10401000L, 0x00001000L,
1280x10000000L, 0x10401008L, 0x00401008L, 0x00400000L,
1290x10401008L, 0x00000008L, 0x10001000L, 0x00401008L,
1300x00400008L, 0x00401000L, 0x10400000L, 0x10001008L,
1310x00001008L, 0x10000000L, 0x10000008L, 0x10401000L,
132},{
133/* nibble 4 */
1340x08000000L, 0x00010000L, 0x00000400L, 0x08010420L,
1350x08010020L, 0x08000400L, 0x00010420L, 0x08010000L,
1360x00010000L, 0x00000020L, 0x08000020L, 0x00010400L,
1370x08000420L, 0x08010020L, 0x08010400L, 0x00000000L,
1380x00010400L, 0x08000000L, 0x00010020L, 0x00000420L,
1390x08000400L, 0x00010420L, 0x00000000L, 0x08000020L,
1400x00000020L, 0x08000420L, 0x08010420L, 0x00010020L,
1410x08010000L, 0x00000400L, 0x00000420L, 0x08010400L,
1420x08010400L, 0x08000420L, 0x00010020L, 0x08010000L,
1430x00010000L, 0x00000020L, 0x08000020L, 0x08000400L,
1440x08000000L, 0x00010400L, 0x08010420L, 0x00000000L,
1450x00010420L, 0x08000000L, 0x00000400L, 0x00010020L,
1460x08000420L, 0x00000400L, 0x00000000L, 0x08010420L,
1470x08010020L, 0x08010400L, 0x00000420L, 0x00010000L,
1480x00010400L, 0x08010020L, 0x08000400L, 0x00000420L,
1490x00000020L, 0x00010420L, 0x08010000L, 0x08000020L,
150},{
151/* nibble 5 */
1520x80000040L, 0x00200040L, 0x00000000L, 0x80202000L,
1530x00200040L, 0x00002000L, 0x80002040L, 0x00200000L,
1540x00002040L, 0x80202040L, 0x00202000L, 0x80000000L,
1550x80002000L, 0x80000040L, 0x80200000L, 0x00202040L,
1560x00200000L, 0x80002040L, 0x80200040L, 0x00000000L,
1570x00002000L, 0x00000040L, 0x80202000L, 0x80200040L,
1580x80202040L, 0x80200000L, 0x80000000L, 0x00002040L,
1590x00000040L, 0x00202000L, 0x00202040L, 0x80002000L,
1600x00002040L, 0x80000000L, 0x80002000L, 0x00202040L,
1610x80202000L, 0x00200040L, 0x00000000L, 0x80002000L,
1620x80000000L, 0x00002000L, 0x80200040L, 0x00200000L,
1630x00200040L, 0x80202040L, 0x00202000L, 0x00000040L,
1640x80202040L, 0x00202000L, 0x00200000L, 0x80002040L,
1650x80000040L, 0x80200000L, 0x00202040L, 0x00000000L,
1660x00002000L, 0x80000040L, 0x80002040L, 0x80202000L,
1670x80200000L, 0x00002040L, 0x00000040L, 0x80200040L,
168},{
169/* nibble 6 */
1700x00004000L, 0x00000200L, 0x01000200L, 0x01000004L,
1710x01004204L, 0x00004004L, 0x00004200L, 0x00000000L,
1720x01000000L, 0x01000204L, 0x00000204L, 0x01004000L,
1730x00000004L, 0x01004200L, 0x01004000L, 0x00000204L,
1740x01000204L, 0x00004000L, 0x00004004L, 0x01004204L,
1750x00000000L, 0x01000200L, 0x01000004L, 0x00004200L,
1760x01004004L, 0x00004204L, 0x01004200L, 0x00000004L,
1770x00004204L, 0x01004004L, 0x00000200L, 0x01000000L,
1780x00004204L, 0x01004000L, 0x01004004L, 0x00000204L,
1790x00004000L, 0x00000200L, 0x01000000L, 0x01004004L,
1800x01000204L, 0x00004204L, 0x00004200L, 0x00000000L,
1810x00000200L, 0x01000004L, 0x00000004L, 0x01000200L,
1820x00000000L, 0x01000204L, 0x01000200L, 0x00004200L,
1830x00000204L, 0x00004000L, 0x01004204L, 0x01000000L,
1840x01004200L, 0x00000004L, 0x00004004L, 0x01004204L,
1850x01000004L, 0x01004200L, 0x01004000L, 0x00004004L,
186},{
187/* nibble 7 */
1880x20800080L, 0x20820000L, 0x00020080L, 0x00000000L,
1890x20020000L, 0x00800080L, 0x20800000L, 0x20820080L,
1900x00000080L, 0x20000000L, 0x00820000L, 0x00020080L,
1910x00820080L, 0x20020080L, 0x20000080L, 0x20800000L,
1920x00020000L, 0x00820080L, 0x00800080L, 0x20020000L,
1930x20820080L, 0x20000080L, 0x00000000L, 0x00820000L,
1940x20000000L, 0x00800000L, 0x20020080L, 0x20800080L,
1950x00800000L, 0x00020000L, 0x20820000L, 0x00000080L,
1960x00800000L, 0x00020000L, 0x20000080L, 0x20820080L,
1970x00020080L, 0x20000000L, 0x00000000L, 0x00820000L,
1980x20800080L, 0x20020080L, 0x20020000L, 0x00800080L,
1990x20820000L, 0x00000080L, 0x00800080L, 0x20020000L,
2000x20820080L, 0x00800000L, 0x20800000L, 0x20000080L,
2010x00820000L, 0x00020080L, 0x20020080L, 0x20800000L,
2020x00000080L, 0x20820000L, 0x00820080L, 0x00000000L,
2030x20000000L, 0x20800080L, 0x00020000L, 0x00820080L,
204}};
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c
deleted file mode 100644
index 0373db469c..0000000000
--- a/src/lib/libcrypto/des/str2key.c
+++ /dev/null
@@ -1,173 +0,0 @@
1/* crypto/des/str2key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61void DES_string_to_key(const char *str, DES_cblock *key)
62 {
63 DES_key_schedule ks;
64 int i,length;
65 register unsigned char j;
66
67 memset(key,0,8);
68 length=strlen(str);
69#ifdef OLD_STR_TO_KEY
70 for (i=0; i<length; i++)
71 (*key)[i%8]^=(str[i]<<1);
72#else /* MIT COMPATIBLE */
73 for (i=0; i<length; i++)
74 {
75 j=str[i];
76 if ((i%16) < 8)
77 (*key)[i%8]^=(j<<1);
78 else
79 {
80 /* Reverse the bit order 05/05/92 eay */
81 j=((j<<4)&0xf0)|((j>>4)&0x0f);
82 j=((j<<2)&0xcc)|((j>>2)&0x33);
83 j=((j<<1)&0xaa)|((j>>1)&0x55);
84 (*key)[7-(i%8)]^=j;
85 }
86 }
87#endif
88 DES_set_odd_parity(key);
89#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
90 if(DES_is_weak_key(key))
91 (*key)[7] ^= 0xF0;
92 DES_set_key(key,&ks);
93#else
94 DES_set_key_unchecked(key,&ks);
95#endif
96 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key);
97 OPENSSL_cleanse(&ks,sizeof(ks));
98 DES_set_odd_parity(key);
99 }
100
101void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
102 {
103 DES_key_schedule ks;
104 int i,length;
105 register unsigned char j;
106
107 memset(key1,0,8);
108 memset(key2,0,8);
109 length=strlen(str);
110#ifdef OLD_STR_TO_KEY
111 if (length <= 8)
112 {
113 for (i=0; i<length; i++)
114 {
115 (*key2)[i]=(*key1)[i]=(str[i]<<1);
116 }
117 }
118 else
119 {
120 for (i=0; i<length; i++)
121 {
122 if ((i/8)&1)
123 (*key2)[i%8]^=(str[i]<<1);
124 else
125 (*key1)[i%8]^=(str[i]<<1);
126 }
127 }
128#else /* MIT COMPATIBLE */
129 for (i=0; i<length; i++)
130 {
131 j=str[i];
132 if ((i%32) < 16)
133 {
134 if ((i%16) < 8)
135 (*key1)[i%8]^=(j<<1);
136 else
137 (*key2)[i%8]^=(j<<1);
138 }
139 else
140 {
141 j=((j<<4)&0xf0)|((j>>4)&0x0f);
142 j=((j<<2)&0xcc)|((j>>2)&0x33);
143 j=((j<<1)&0xaa)|((j>>1)&0x55);
144 if ((i%16) < 8)
145 (*key1)[7-(i%8)]^=j;
146 else
147 (*key2)[7-(i%8)]^=j;
148 }
149 }
150 if (length <= 8) memcpy(key2,key1,8);
151#endif
152 DES_set_odd_parity(key1);
153 DES_set_odd_parity(key2);
154#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
155 if(DES_is_weak_key(key1))
156 (*key1)[7] ^= 0xF0;
157 DES_set_key(key1,&ks);
158#else
159 DES_set_key_unchecked(key1,&ks);
160#endif
161 DES_cbc_cksum((const unsigned char*)str,key1,length,&ks,key1);
162#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
163 if(DES_is_weak_key(key2))
164 (*key2)[7] ^= 0xF0;
165 DES_set_key(key2,&ks);
166#else
167 DES_set_key_unchecked(key2,&ks);
168#endif
169 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2);
170 OPENSSL_cleanse(&ks,sizeof(ks));
171 DES_set_odd_parity(key1);
172 DES_set_odd_parity(key2);
173 }
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c
deleted file mode 100644
index 47246eb466..0000000000
--- a/src/lib/libcrypto/des/xcbc_enc.c
+++ /dev/null
@@ -1,195 +0,0 @@
1/* crypto/des/xcbc_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* RSA's DESX */
62
63static unsigned char desx_white_in2out[256]={
640xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0,
650x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A,
660x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36,
670x3E,0xEE,0xFB,0x95,0x1A,0xFE,0xCE,0xA8,0x34,0xA9,0x13,0xF0,0xA6,0x3F,0xD8,0x0C,
680x78,0x24,0xAF,0x23,0x52,0xC1,0x67,0x17,0xF5,0x66,0x90,0xE7,0xE8,0x07,0xB8,0x60,
690x48,0xE6,0x1E,0x53,0xF3,0x92,0xA4,0x72,0x8C,0x08,0x15,0x6E,0x86,0x00,0x84,0xFA,
700xF4,0x7F,0x8A,0x42,0x19,0xF6,0xDB,0xCD,0x14,0x8D,0x50,0x12,0xBA,0x3C,0x06,0x4E,
710xEC,0xB3,0x35,0x11,0xA1,0x88,0x8E,0x2B,0x94,0x99,0xB7,0x71,0x74,0xD3,0xE4,0xBF,
720x3A,0xDE,0x96,0x0E,0xBC,0x0A,0xED,0x77,0xFC,0x37,0x6B,0x03,0x79,0x89,0x62,0xC6,
730xD7,0xC0,0xD2,0x7C,0x6A,0x8B,0x22,0xA3,0x5B,0x05,0x5D,0x02,0x75,0xD5,0x61,0xE3,
740x18,0x8F,0x55,0x51,0xAD,0x1F,0x0B,0x5E,0x85,0xE5,0xC2,0x57,0x63,0xCA,0x3D,0x6C,
750xB4,0xC5,0xCC,0x70,0xB2,0x91,0x59,0x0D,0x47,0x20,0xC8,0x4F,0x58,0xE0,0x01,0xE2,
760x16,0x38,0xC4,0x6F,0x3B,0x0F,0x65,0x46,0xBE,0x7E,0x2D,0x7B,0x82,0xF9,0x40,0xB5,
770x1D,0x73,0xF8,0xEB,0x26,0xC7,0x87,0x97,0x25,0x54,0xB1,0x28,0xAA,0x98,0x9D,0xA5,
780x64,0x6D,0x7A,0xD4,0x10,0x81,0x44,0xEF,0x49,0xD6,0xAE,0x2E,0xDD,0x76,0x5C,0x2F,
790xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB,
80 };
81
82void DES_xwhite_in2out(const_DES_cblock *des_key, const_DES_cblock *in_white,
83 DES_cblock *out_white)
84 {
85 int out0,out1;
86 int i;
87 const unsigned char *key = &(*des_key)[0];
88 const unsigned char *in = &(*in_white)[0];
89 unsigned char *out = &(*out_white)[0];
90
91 out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0;
92 out0=out1=0;
93 for (i=0; i<8; i++)
94 {
95 out[i]=key[i]^desx_white_in2out[out0^out1];
96 out0=out1;
97 out1=(int)out[i&0x07];
98 }
99
100 out0=out[0];
101 out1=out[i];
102 for (i=0; i<8; i++)
103 {
104 out[i]=in[i]^desx_white_in2out[out0^out1];
105 out0=out1;
106 out1=(int)out[i&0x07];
107 }
108 }
109
110void DES_xcbc_encrypt(const unsigned char *in, unsigned char *out,
111 long length, DES_key_schedule *schedule,
112 DES_cblock *ivec, const_DES_cblock *inw,
113 const_DES_cblock *outw, int enc)
114 {
115 register DES_LONG tin0,tin1;
116 register DES_LONG tout0,tout1,xor0,xor1;
117 register DES_LONG inW0,inW1,outW0,outW1;
118 register const unsigned char *in2;
119 register long l=length;
120 DES_LONG tin[2];
121 unsigned char *iv;
122
123 in2 = &(*inw)[0];
124 c2l(in2,inW0);
125 c2l(in2,inW1);
126 in2 = &(*outw)[0];
127 c2l(in2,outW0);
128 c2l(in2,outW1);
129
130 iv = &(*ivec)[0];
131
132 if (enc)
133 {
134 c2l(iv,tout0);
135 c2l(iv,tout1);
136 for (l-=8; l>=0; l-=8)
137 {
138 c2l(in,tin0);
139 c2l(in,tin1);
140 tin0^=tout0^inW0; tin[0]=tin0;
141 tin1^=tout1^inW1; tin[1]=tin1;
142 DES_encrypt1(tin,schedule,DES_ENCRYPT);
143 tout0=tin[0]^outW0; l2c(tout0,out);
144 tout1=tin[1]^outW1; l2c(tout1,out);
145 }
146 if (l != -8)
147 {
148 c2ln(in,tin0,tin1,l+8);
149 tin0^=tout0^inW0; tin[0]=tin0;
150 tin1^=tout1^inW1; tin[1]=tin1;
151 DES_encrypt1(tin,schedule,DES_ENCRYPT);
152 tout0=tin[0]^outW0; l2c(tout0,out);
153 tout1=tin[1]^outW1; l2c(tout1,out);
154 }
155 iv = &(*ivec)[0];
156 l2c(tout0,iv);
157 l2c(tout1,iv);
158 }
159 else
160 {
161 c2l(iv,xor0);
162 c2l(iv,xor1);
163 for (l-=8; l>0; l-=8)
164 {
165 c2l(in,tin0); tin[0]=tin0^outW0;
166 c2l(in,tin1); tin[1]=tin1^outW1;
167 DES_encrypt1(tin,schedule,DES_DECRYPT);
168 tout0=tin[0]^xor0^inW0;
169 tout1=tin[1]^xor1^inW1;
170 l2c(tout0,out);
171 l2c(tout1,out);
172 xor0=tin0;
173 xor1=tin1;
174 }
175 if (l != -8)
176 {
177 c2l(in,tin0); tin[0]=tin0^outW0;
178 c2l(in,tin1); tin[1]=tin1^outW1;
179 DES_encrypt1(tin,schedule,DES_DECRYPT);
180 tout0=tin[0]^xor0^inW0;
181 tout1=tin[1]^xor1^inW1;
182 l2cn(tout0,tout1,out,l+8);
183 xor0=tin0;
184 xor1=tin1;
185 }
186
187 iv = &(*ivec)[0];
188 l2c(xor0,iv);
189 l2c(xor1,iv);
190 }
191 tin0=tin1=tout0=tout1=xor0=xor1=0;
192 inW0=inW1=outW0=outW1=0;
193 tin[0]=tin[1]=0;
194 }
195