summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des
diff options
context:
space:
mode:
authordjm <>2010-10-01 22:54:21 +0000
committerdjm <>2010-10-01 22:54:21 +0000
commit829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2 (patch)
treee03b9f1bd051e844b971936729e9df549a209130 /src/lib/libcrypto/des
parente6b755d2a53d3cac7a344dfdd6bf7c951cac754c (diff)
downloadopenbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.tar.gz
openbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.tar.bz2
openbsd-829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2.zip
import OpenSSL-1.0.0a
Diffstat (limited to 'src/lib/libcrypto/des')
-rw-r--r--src/lib/libcrypto/des/asm/crypt586.pl5
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl274
-rw-r--r--src/lib/libcrypto/des/asm/des_enc.m46
-rw-r--r--src/lib/libcrypto/des/des_enc.c21
-rw-r--r--src/lib/libcrypto/des/des_locl.h6
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c48
-rw-r--r--src/lib/libcrypto/des/enc_read.c12
-rw-r--r--src/lib/libcrypto/des/enc_writ.c4
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c4
-rw-r--r--src/lib/libcrypto/des/set_key.c13
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c2
11 files changed, 320 insertions, 75 deletions
diff --git a/src/lib/libcrypto/des/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl
index 1d04ed6def..e36f7d44bd 100644
--- a/src/lib/libcrypto/des/asm/crypt586.pl
+++ b/src/lib/libcrypto/des/asm/crypt586.pl
@@ -6,7 +6,8 @@
6# things perfect. 6# things perfect.
7# 7#
8 8
9push(@INC,"perlasm","../../perlasm"); 9$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
10push(@INC,"${dir}","${dir}../../perlasm");
10require "x86asm.pl"; 11require "x86asm.pl";
11 12
12&asm_init($ARGV[0],"crypt586.pl"); 13&asm_init($ARGV[0],"crypt586.pl");
@@ -22,7 +23,7 @@ sub fcrypt_body
22 { 23 {
23 local($name,$do_ip)=@_; 24 local($name,$do_ip)=@_;
24 25
25 &function_begin($name,"EXTRN _DES_SPtrans:DWORD"); 26 &function_begin($name);
26 27
27 &comment(""); 28 &comment("");
28 &comment("Load the 2 words"); 29 &comment("Load the 2 words");
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl
index b75d3c6b3a..5b5f39cebd 100644
--- a/src/lib/libcrypto/des/asm/des-586.pl
+++ b/src/lib/libcrypto/des/asm/des-586.pl
@@ -4,7 +4,8 @@
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> 4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
5# 5#
6 6
7push(@INC,"perlasm","../../perlasm"); 7$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
8push(@INC,"${dir}","${dir}../../perlasm");
8require "x86asm.pl"; 9require "x86asm.pl";
9require "cbc.pl"; 10require "cbc.pl";
10require "desboth.pl"; 11require "desboth.pl";
@@ -18,29 +19,110 @@ require "desboth.pl";
18 19
19$L="edi"; 20$L="edi";
20$R="esi"; 21$R="esi";
22$trans="ebp";
23$small_footprint=1 if (grep(/\-DOPENSSL_SMALL_FOOTPRINT/,@ARGV));
24# one can discuss setting this variable to 1 unconditionally, as
25# the folded loop is only 3% slower than unrolled, but >7 times smaller
21 26
22&external_label("DES_SPtrans"); 27&public_label("DES_SPtrans");
28
29&DES_encrypt_internal();
30&DES_decrypt_internal();
23&DES_encrypt("DES_encrypt1",1); 31&DES_encrypt("DES_encrypt1",1);
24&DES_encrypt("DES_encrypt2",0); 32&DES_encrypt("DES_encrypt2",0);
25&DES_encrypt3("DES_encrypt3",1); 33&DES_encrypt3("DES_encrypt3",1);
26&DES_encrypt3("DES_decrypt3",0); 34&DES_encrypt3("DES_decrypt3",0);
27&cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1); 35&cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
28&cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5); 36&cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
37&DES_SPtrans();
29 38
30&asm_finish(); 39&asm_finish();
31 40
41sub DES_encrypt_internal()
42 {
43 &function_begin_B("_x86_DES_encrypt");
44
45 if ($small_footprint)
46 {
47 &lea("edx",&DWP(128,"ecx"));
48 &push("edx");
49 &push("ecx");
50 &set_label("eloop");
51 &D_ENCRYPT(0,$L,$R,0,$trans,"eax","ebx","ecx","edx",&swtmp(0));
52 &comment("");
53 &D_ENCRYPT(1,$R,$L,2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
54 &comment("");
55 &add("ecx",16);
56 &cmp("ecx",&swtmp(1));
57 &mov(&swtmp(0),"ecx");
58 &jb(&label("eloop"));
59 &add("esp",8);
60 }
61 else
62 {
63 &push("ecx");
64 for ($i=0; $i<16; $i+=2)
65 {
66 &comment("Round $i");
67 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
68 &comment("Round ".sprintf("%d",$i+1));
69 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
70 }
71 &add("esp",4);
72 }
73 &ret();
74
75 &function_end_B("_x86_DES_encrypt");
76 }
77
78sub DES_decrypt_internal()
79 {
80 &function_begin_B("_x86_DES_decrypt");
81
82 if ($small_footprint)
83 {
84 &push("ecx");
85 &lea("ecx",&DWP(128,"ecx"));
86 &push("ecx");
87 &set_label("dloop");
88 &D_ENCRYPT(0,$L,$R,-2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
89 &comment("");
90 &D_ENCRYPT(1,$R,$L,-4,$trans,"eax","ebx","ecx","edx",&swtmp(0));
91 &comment("");
92 &sub("ecx",16);
93 &cmp("ecx",&swtmp(1));
94 &mov(&swtmp(0),"ecx");
95 &ja(&label("dloop"));
96 &add("esp",8);
97 }
98 else
99 {
100 &push("ecx");
101 for ($i=15; $i>0; $i-=2)
102 {
103 &comment("Round $i");
104 &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
105 &comment("Round ".sprintf("%d",$i-1));
106 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx",&swtmp(0));
107 }
108 &add("esp",4);
109 }
110 &ret();
111
112 &function_end_B("_x86_DES_decrypt");
113 }
114
32sub DES_encrypt 115sub DES_encrypt
33 { 116 {
34 local($name,$do_ip)=@_; 117 local($name,$do_ip)=@_;
35 118
36 &function_begin_B($name,"EXTRN _DES_SPtrans:DWORD"); 119 &function_begin_B($name);
37 120
38 &push("esi"); 121 &push("esi");
39 &push("edi"); 122 &push("edi");
40 123
41 &comment(""); 124 &comment("");
42 &comment("Load the 2 words"); 125 &comment("Load the 2 words");
43 $trans="ebp";
44 126
45 if ($do_ip) 127 if ($do_ip)
46 { 128 {
@@ -73,39 +155,20 @@ sub DES_encrypt
73 } 155 }
74 156
75 # PIC-ification:-) 157 # PIC-ification:-)
76 &picmeup($trans,"DES_SPtrans"); 158 &call (&label("pic_point"));
77 #if ($cpp) { &picmeup($trans,"DES_SPtrans"); } 159 &set_label("pic_point");
78 #else { &lea($trans,&DWP("DES_SPtrans")); } 160 &blindpop($trans);
161 &lea ($trans,&DWP(&label("DES_SPtrans")."-".&label("pic_point"),$trans));
79 162
80 &mov( "ecx", &wparam(1) ); 163 &mov( "ecx", &wparam(1) );
81 &cmp("ebx","0");
82 &je(&label("start_decrypt"));
83
84 for ($i=0; $i<16; $i+=2)
85 {
86 &comment("");
87 &comment("Round $i");
88 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
89
90 &comment("");
91 &comment("Round ".sprintf("%d",$i+1));
92 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
93 }
94 &jmp(&label("end"));
95 164
96 &set_label("start_decrypt"); 165 &cmp("ebx","0");
97 166 &je(&label("decrypt"));
98 for ($i=15; $i>0; $i-=2) 167 &call("_x86_DES_encrypt");
99 { 168 &jmp(&label("done"));
100 &comment(""); 169 &set_label("decrypt");
101 &comment("Round $i"); 170 &call("_x86_DES_decrypt");
102 &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx"); 171 &set_label("done");
103 &comment("");
104 &comment("Round ".sprintf("%d",$i-1));
105 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx");
106 }
107
108 &set_label("end");
109 172
110 if ($do_ip) 173 if ($do_ip)
111 { 174 {
@@ -139,7 +202,7 @@ sub DES_encrypt
139 202
140sub D_ENCRYPT 203sub D_ENCRYPT
141 { 204 {
142 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_; 205 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t,$wp1)=@_;
143 206
144 &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0)); 207 &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0));
145 &xor( $tmp1, $tmp1); 208 &xor( $tmp1, $tmp1);
@@ -166,7 +229,7 @@ sub D_ENCRYPT
166 &and( $t, "0xff" ); 229 &and( $t, "0xff" );
167 &xor( $L, &DWP("0x600",$trans,$tmp1,0)); 230 &xor( $L, &DWP("0x600",$trans,$tmp1,0));
168 &xor( $L, &DWP("0x700",$trans,$tmp2,0)); 231 &xor( $L, &DWP("0x700",$trans,$tmp2,0));
169 &mov( $tmp2, &wparam(1) ); 232 &mov( $tmp2, $wp1 );
170 &xor( $L, &DWP("0x400",$trans,$u,0)); 233 &xor( $L, &DWP("0x400",$trans,$u,0));
171 &xor( $L, &DWP("0x500",$trans,$t,0)); 234 &xor( $L, &DWP("0x500",$trans,$t,0));
172 } 235 }
@@ -249,3 +312,142 @@ sub FP_new
249 &rotr($tt , 4); 312 &rotr($tt , 4);
250 } 313 }
251 314
315sub DES_SPtrans
316 {
317 &set_label("DES_SPtrans",64);
318 &data_word(0x02080800, 0x00080000, 0x02000002, 0x02080802);
319 &data_word(0x02000000, 0x00080802, 0x00080002, 0x02000002);
320 &data_word(0x00080802, 0x02080800, 0x02080000, 0x00000802);
321 &data_word(0x02000802, 0x02000000, 0x00000000, 0x00080002);
322 &data_word(0x00080000, 0x00000002, 0x02000800, 0x00080800);
323 &data_word(0x02080802, 0x02080000, 0x00000802, 0x02000800);
324 &data_word(0x00000002, 0x00000800, 0x00080800, 0x02080002);
325 &data_word(0x00000800, 0x02000802, 0x02080002, 0x00000000);
326 &data_word(0x00000000, 0x02080802, 0x02000800, 0x00080002);
327 &data_word(0x02080800, 0x00080000, 0x00000802, 0x02000800);
328 &data_word(0x02080002, 0x00000800, 0x00080800, 0x02000002);
329 &data_word(0x00080802, 0x00000002, 0x02000002, 0x02080000);
330 &data_word(0x02080802, 0x00080800, 0x02080000, 0x02000802);
331 &data_word(0x02000000, 0x00000802, 0x00080002, 0x00000000);
332 &data_word(0x00080000, 0x02000000, 0x02000802, 0x02080800);
333 &data_word(0x00000002, 0x02080002, 0x00000800, 0x00080802);
334 # nibble 1
335 &data_word(0x40108010, 0x00000000, 0x00108000, 0x40100000);
336 &data_word(0x40000010, 0x00008010, 0x40008000, 0x00108000);
337 &data_word(0x00008000, 0x40100010, 0x00000010, 0x40008000);
338 &data_word(0x00100010, 0x40108000, 0x40100000, 0x00000010);
339 &data_word(0x00100000, 0x40008010, 0x40100010, 0x00008000);
340 &data_word(0x00108010, 0x40000000, 0x00000000, 0x00100010);
341 &data_word(0x40008010, 0x00108010, 0x40108000, 0x40000010);
342 &data_word(0x40000000, 0x00100000, 0x00008010, 0x40108010);
343 &data_word(0x00100010, 0x40108000, 0x40008000, 0x00108010);
344 &data_word(0x40108010, 0x00100010, 0x40000010, 0x00000000);
345 &data_word(0x40000000, 0x00008010, 0x00100000, 0x40100010);
346 &data_word(0x00008000, 0x40000000, 0x00108010, 0x40008010);
347 &data_word(0x40108000, 0x00008000, 0x00000000, 0x40000010);
348 &data_word(0x00000010, 0x40108010, 0x00108000, 0x40100000);
349 &data_word(0x40100010, 0x00100000, 0x00008010, 0x40008000);
350 &data_word(0x40008010, 0x00000010, 0x40100000, 0x00108000);
351 # nibble 2
352 &data_word(0x04000001, 0x04040100, 0x00000100, 0x04000101);
353 &data_word(0x00040001, 0x04000000, 0x04000101, 0x00040100);
354 &data_word(0x04000100, 0x00040000, 0x04040000, 0x00000001);
355 &data_word(0x04040101, 0x00000101, 0x00000001, 0x04040001);
356 &data_word(0x00000000, 0x00040001, 0x04040100, 0x00000100);
357 &data_word(0x00000101, 0x04040101, 0x00040000, 0x04000001);
358 &data_word(0x04040001, 0x04000100, 0x00040101, 0x04040000);
359 &data_word(0x00040100, 0x00000000, 0x04000000, 0x00040101);
360 &data_word(0x04040100, 0x00000100, 0x00000001, 0x00040000);
361 &data_word(0x00000101, 0x00040001, 0x04040000, 0x04000101);
362 &data_word(0x00000000, 0x04040100, 0x00040100, 0x04040001);
363 &data_word(0x00040001, 0x04000000, 0x04040101, 0x00000001);
364 &data_word(0x00040101, 0x04000001, 0x04000000, 0x04040101);
365 &data_word(0x00040000, 0x04000100, 0x04000101, 0x00040100);
366 &data_word(0x04000100, 0x00000000, 0x04040001, 0x00000101);
367 &data_word(0x04000001, 0x00040101, 0x00000100, 0x04040000);
368 # nibble 3
369 &data_word(0x00401008, 0x10001000, 0x00000008, 0x10401008);
370 &data_word(0x00000000, 0x10400000, 0x10001008, 0x00400008);
371 &data_word(0x10401000, 0x10000008, 0x10000000, 0x00001008);
372 &data_word(0x10000008, 0x00401008, 0x00400000, 0x10000000);
373 &data_word(0x10400008, 0x00401000, 0x00001000, 0x00000008);
374 &data_word(0x00401000, 0x10001008, 0x10400000, 0x00001000);
375 &data_word(0x00001008, 0x00000000, 0x00400008, 0x10401000);
376 &data_word(0x10001000, 0x10400008, 0x10401008, 0x00400000);
377 &data_word(0x10400008, 0x00001008, 0x00400000, 0x10000008);
378 &data_word(0x00401000, 0x10001000, 0x00000008, 0x10400000);
379 &data_word(0x10001008, 0x00000000, 0x00001000, 0x00400008);
380 &data_word(0x00000000, 0x10400008, 0x10401000, 0x00001000);
381 &data_word(0x10000000, 0x10401008, 0x00401008, 0x00400000);
382 &data_word(0x10401008, 0x00000008, 0x10001000, 0x00401008);
383 &data_word(0x00400008, 0x00401000, 0x10400000, 0x10001008);
384 &data_word(0x00001008, 0x10000000, 0x10000008, 0x10401000);
385 # nibble 4
386 &data_word(0x08000000, 0x00010000, 0x00000400, 0x08010420);
387 &data_word(0x08010020, 0x08000400, 0x00010420, 0x08010000);
388 &data_word(0x00010000, 0x00000020, 0x08000020, 0x00010400);
389 &data_word(0x08000420, 0x08010020, 0x08010400, 0x00000000);
390 &data_word(0x00010400, 0x08000000, 0x00010020, 0x00000420);
391 &data_word(0x08000400, 0x00010420, 0x00000000, 0x08000020);
392 &data_word(0x00000020, 0x08000420, 0x08010420, 0x00010020);
393 &data_word(0x08010000, 0x00000400, 0x00000420, 0x08010400);
394 &data_word(0x08010400, 0x08000420, 0x00010020, 0x08010000);
395 &data_word(0x00010000, 0x00000020, 0x08000020, 0x08000400);
396 &data_word(0x08000000, 0x00010400, 0x08010420, 0x00000000);
397 &data_word(0x00010420, 0x08000000, 0x00000400, 0x00010020);
398 &data_word(0x08000420, 0x00000400, 0x00000000, 0x08010420);
399 &data_word(0x08010020, 0x08010400, 0x00000420, 0x00010000);
400 &data_word(0x00010400, 0x08010020, 0x08000400, 0x00000420);
401 &data_word(0x00000020, 0x00010420, 0x08010000, 0x08000020);
402 # nibble 5
403 &data_word(0x80000040, 0x00200040, 0x00000000, 0x80202000);
404 &data_word(0x00200040, 0x00002000, 0x80002040, 0x00200000);
405 &data_word(0x00002040, 0x80202040, 0x00202000, 0x80000000);
406 &data_word(0x80002000, 0x80000040, 0x80200000, 0x00202040);
407 &data_word(0x00200000, 0x80002040, 0x80200040, 0x00000000);
408 &data_word(0x00002000, 0x00000040, 0x80202000, 0x80200040);
409 &data_word(0x80202040, 0x80200000, 0x80000000, 0x00002040);
410 &data_word(0x00000040, 0x00202000, 0x00202040, 0x80002000);
411 &data_word(0x00002040, 0x80000000, 0x80002000, 0x00202040);
412 &data_word(0x80202000, 0x00200040, 0x00000000, 0x80002000);
413 &data_word(0x80000000, 0x00002000, 0x80200040, 0x00200000);
414 &data_word(0x00200040, 0x80202040, 0x00202000, 0x00000040);
415 &data_word(0x80202040, 0x00202000, 0x00200000, 0x80002040);
416 &data_word(0x80000040, 0x80200000, 0x00202040, 0x00000000);
417 &data_word(0x00002000, 0x80000040, 0x80002040, 0x80202000);
418 &data_word(0x80200000, 0x00002040, 0x00000040, 0x80200040);
419 # nibble 6
420 &data_word(0x00004000, 0x00000200, 0x01000200, 0x01000004);
421 &data_word(0x01004204, 0x00004004, 0x00004200, 0x00000000);
422 &data_word(0x01000000, 0x01000204, 0x00000204, 0x01004000);
423 &data_word(0x00000004, 0x01004200, 0x01004000, 0x00000204);
424 &data_word(0x01000204, 0x00004000, 0x00004004, 0x01004204);
425 &data_word(0x00000000, 0x01000200, 0x01000004, 0x00004200);
426 &data_word(0x01004004, 0x00004204, 0x01004200, 0x00000004);
427 &data_word(0x00004204, 0x01004004, 0x00000200, 0x01000000);
428 &data_word(0x00004204, 0x01004000, 0x01004004, 0x00000204);
429 &data_word(0x00004000, 0x00000200, 0x01000000, 0x01004004);
430 &data_word(0x01000204, 0x00004204, 0x00004200, 0x00000000);
431 &data_word(0x00000200, 0x01000004, 0x00000004, 0x01000200);
432 &data_word(0x00000000, 0x01000204, 0x01000200, 0x00004200);
433 &data_word(0x00000204, 0x00004000, 0x01004204, 0x01000000);
434 &data_word(0x01004200, 0x00000004, 0x00004004, 0x01004204);
435 &data_word(0x01000004, 0x01004200, 0x01004000, 0x00004004);
436 # nibble 7
437 &data_word(0x20800080, 0x20820000, 0x00020080, 0x00000000);
438 &data_word(0x20020000, 0x00800080, 0x20800000, 0x20820080);
439 &data_word(0x00000080, 0x20000000, 0x00820000, 0x00020080);
440 &data_word(0x00820080, 0x20020080, 0x20000080, 0x20800000);
441 &data_word(0x00020000, 0x00820080, 0x00800080, 0x20020000);
442 &data_word(0x20820080, 0x20000080, 0x00000000, 0x00820000);
443 &data_word(0x20000000, 0x00800000, 0x20020080, 0x20800080);
444 &data_word(0x00800000, 0x00020000, 0x20820000, 0x00000080);
445 &data_word(0x00800000, 0x00020000, 0x20000080, 0x20820080);
446 &data_word(0x00020080, 0x20000000, 0x00000000, 0x00820000);
447 &data_word(0x20800080, 0x20020080, 0x20020000, 0x00800080);
448 &data_word(0x20820000, 0x00000080, 0x00800080, 0x20020000);
449 &data_word(0x20820080, 0x00800000, 0x20800000, 0x20000080);
450 &data_word(0x00820000, 0x00020080, 0x20020080, 0x20800000);
451 &data_word(0x00000080, 0x20820000, 0x00820080, 0x00000000);
452 &data_word(0x20000000, 0x20800080, 0x00020000, 0x00820080);
453 }
diff --git a/src/lib/libcrypto/des/asm/des_enc.m4 b/src/lib/libcrypto/des/asm/des_enc.m4
index f59333a030..3280595478 100644
--- a/src/lib/libcrypto/des/asm/des_enc.m4
+++ b/src/lib/libcrypto/des/asm/des_enc.m4
@@ -1954,9 +1954,11 @@ DES_ede3_cbc_encrypt:
1954 .word LOOPS ! 280 1954 .word LOOPS ! 280
1955 .word 0x0000FC00 ! 284 1955 .word 0x0000FC00 ! 284
1956 1956
1957 .type .PIC.DES_SPtrans,#object 1957 .global DES_SPtrans
1958 .size .PIC.DES_SPtrans,2048 1958 .type DES_SPtrans,#object
1959 .size DES_SPtrans,2048
1959.align 64 1960.align 64
1961DES_SPtrans:
1960.PIC.DES_SPtrans: 1962.PIC.DES_SPtrans:
1961 ! nibble 0 1963 ! nibble 0
1962 .word 0x02080800, 0x00080000, 0x02000002, 0x02080802 1964 .word 0x02080800, 0x00080000, 0x02000002, 0x02080802
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
index cf71965aca..828feba208 100644
--- a/src/lib/libcrypto/des/des_enc.c
+++ b/src/lib/libcrypto/des/des_enc.c
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60#include "spr.h"
60 61
61void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc) 62void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
62 { 63 {
@@ -107,12 +108,10 @@ void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
107 D_ENCRYPT(l,r,28); /* 15 */ 108 D_ENCRYPT(l,r,28); /* 15 */
108 D_ENCRYPT(r,l,30); /* 16 */ 109 D_ENCRYPT(r,l,30); /* 16 */
109#else 110#else
110 for (i=0; i<32; i+=8) 111 for (i=0; i<32; i+=4)
111 { 112 {
112 D_ENCRYPT(l,r,i+0); /* 1 */ 113 D_ENCRYPT(l,r,i+0); /* 1 */
113 D_ENCRYPT(r,l,i+2); /* 2 */ 114 D_ENCRYPT(r,l,i+2); /* 2 */
114 D_ENCRYPT(l,r,i+4); /* 3 */
115 D_ENCRYPT(r,l,i+6); /* 4 */
116 } 115 }
117#endif 116#endif
118 } 117 }
@@ -136,12 +135,10 @@ void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
136 D_ENCRYPT(l,r, 2); /* 2 */ 135 D_ENCRYPT(l,r, 2); /* 2 */
137 D_ENCRYPT(r,l, 0); /* 1 */ 136 D_ENCRYPT(r,l, 0); /* 1 */
138#else 137#else
139 for (i=30; i>0; i-=8) 138 for (i=30; i>0; i-=4)
140 { 139 {
141 D_ENCRYPT(l,r,i-0); /* 16 */ 140 D_ENCRYPT(l,r,i-0); /* 16 */
142 D_ENCRYPT(r,l,i-2); /* 15 */ 141 D_ENCRYPT(r,l,i-2); /* 15 */
143 D_ENCRYPT(l,r,i-4); /* 14 */
144 D_ENCRYPT(r,l,i-6); /* 13 */
145 } 142 }
146#endif 143#endif
147 } 144 }
@@ -203,12 +200,10 @@ void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
203 D_ENCRYPT(l,r,28); /* 15 */ 200 D_ENCRYPT(l,r,28); /* 15 */
204 D_ENCRYPT(r,l,30); /* 16 */ 201 D_ENCRYPT(r,l,30); /* 16 */
205#else 202#else
206 for (i=0; i<32; i+=8) 203 for (i=0; i<32; i+=4)
207 { 204 {
208 D_ENCRYPT(l,r,i+0); /* 1 */ 205 D_ENCRYPT(l,r,i+0); /* 1 */
209 D_ENCRYPT(r,l,i+2); /* 2 */ 206 D_ENCRYPT(r,l,i+2); /* 2 */
210 D_ENCRYPT(l,r,i+4); /* 3 */
211 D_ENCRYPT(r,l,i+6); /* 4 */
212 } 207 }
213#endif 208#endif
214 } 209 }
@@ -232,12 +227,10 @@ void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
232 D_ENCRYPT(l,r, 2); /* 2 */ 227 D_ENCRYPT(l,r, 2); /* 2 */
233 D_ENCRYPT(r,l, 0); /* 1 */ 228 D_ENCRYPT(r,l, 0); /* 1 */
234#else 229#else
235 for (i=30; i>0; i-=8) 230 for (i=30; i>0; i-=4)
236 { 231 {
237 D_ENCRYPT(l,r,i-0); /* 16 */ 232 D_ENCRYPT(l,r,i-0); /* 16 */
238 D_ENCRYPT(r,l,i-2); /* 15 */ 233 D_ENCRYPT(r,l,i-2); /* 15 */
239 D_ENCRYPT(l,r,i-4); /* 14 */
240 D_ENCRYPT(r,l,i-6); /* 13 */
241 } 234 }
242#endif 235#endif
243 } 236 }
@@ -289,8 +282,6 @@ void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
289 282
290#ifndef DES_DEFAULT_OPTIONS 283#ifndef DES_DEFAULT_OPTIONS
291 284
292#if !defined(OPENSSL_FIPS_DES_ASM)
293
294#undef CBC_ENC_C__DONT_UPDATE_IV 285#undef CBC_ENC_C__DONT_UPDATE_IV
295#include "ncbc_enc.c" /* DES_ncbc_encrypt */ 286#include "ncbc_enc.c" /* DES_ncbc_encrypt */
296 287
@@ -406,6 +397,4 @@ void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
406 tin[0]=tin[1]=0; 397 tin[0]=tin[1]=0;
407 } 398 }
408 399
409#endif
410
411#endif /* DES_DEFAULT_OPTIONS */ 400#endif /* DES_DEFAULT_OPTIONS */
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
index 4b9ecff233..a3b512e9b0 100644
--- a/src/lib/libcrypto/des/des_locl.h
+++ b/src/lib/libcrypto/des/des_locl.h
@@ -61,7 +61,7 @@
61 61
62#include <openssl/e_os2.h> 62#include <openssl/e_os2.h>
63 63
64#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) 64#if defined(OPENSSL_SYS_WIN32)
65#ifndef OPENSSL_SYS_MSDOS 65#ifndef OPENSSL_SYS_MSDOS
66#define OPENSSL_SYS_MSDOS 66#define OPENSSL_SYS_MSDOS
67#endif 67#endif
@@ -425,4 +425,8 @@ extern const DES_LONG DES_SPtrans[8][64];
425 425
426void fcrypt_body(DES_LONG *out,DES_key_schedule *ks, 426void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
427 DES_LONG Eswap0, DES_LONG Eswap1); 427 DES_LONG Eswap0, DES_LONG Eswap1);
428
429#ifdef OPENSSL_SMALL_FOOTPRINT
430#undef DES_UNROLL
431#endif
428#endif 432#endif
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c
index 75ae6cf8bb..0684e769b3 100644
--- a/src/lib/libcrypto/des/ecb_enc.c
+++ b/src/lib/libcrypto/des/ecb_enc.c
@@ -57,7 +57,53 @@
57 */ 57 */
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60#include "spr.h" 60#include "des_ver.h"
61#include <openssl/opensslv.h>
62#include <openssl/bio.h>
63
64OPENSSL_GLOBAL const char libdes_version[]="libdes" OPENSSL_VERSION_PTEXT;
65OPENSSL_GLOBAL const char DES_version[]="DES" OPENSSL_VERSION_PTEXT;
66
67const char *DES_options(void)
68 {
69 static int init=1;
70 static char buf[32];
71
72 if (init)
73 {
74 const char *ptr,*unroll,*risc,*size;
75
76#ifdef DES_PTR
77 ptr="ptr";
78#else
79 ptr="idx";
80#endif
81#if defined(DES_RISC1) || defined(DES_RISC2)
82#ifdef DES_RISC1
83 risc="risc1";
84#endif
85#ifdef DES_RISC2
86 risc="risc2";
87#endif
88#else
89 risc="cisc";
90#endif
91#ifdef DES_UNROLL
92 unroll="16";
93#else
94 unroll="2";
95#endif
96 if (sizeof(DES_LONG) != sizeof(long))
97 size="int";
98 else
99 size="long";
100 BIO_snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,
101 size);
102 init=0;
103 }
104 return(buf);
105 }
106
61 107
62void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output, 108void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
63 DES_key_schedule *ks, int enc) 109 DES_key_schedule *ks, int enc)
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c
index e7da2ec66b..edb6620d08 100644
--- a/src/lib/libcrypto/des/enc_read.c
+++ b/src/lib/libcrypto/des/enc_read.c
@@ -63,7 +63,7 @@
63 63
64/* This has some uglies in it but it works - even over sockets. */ 64/* This has some uglies in it but it works - even over sockets. */
65/*extern int errno;*/ 65/*extern int errno;*/
66OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode)=DES_PCBC_MODE; 66OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode,DES_PCBC_MODE)
67 67
68 68
69/* 69/*
@@ -87,6 +87,9 @@ OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode)=DES_PCBC_MODE;
87int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched, 87int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
88 DES_cblock *iv) 88 DES_cblock *iv)
89 { 89 {
90#if defined(OPENSSL_NO_POSIX_IO)
91 return(0);
92#else
90 /* data to be unencrypted */ 93 /* data to be unencrypted */
91 int net_num=0; 94 int net_num=0;
92 static unsigned char *net=NULL; 95 static unsigned char *net=NULL;
@@ -147,7 +150,7 @@ int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
147 /* first - get the length */ 150 /* first - get the length */
148 while (net_num < HDRSIZE) 151 while (net_num < HDRSIZE)
149 { 152 {
150#ifndef _WIN32 153#ifndef OPENSSL_SYS_WIN32
151 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num); 154 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
152#else 155#else
153 i=_read(fd,(void *)&(net[net_num]),HDRSIZE-net_num); 156 i=_read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
@@ -173,7 +176,11 @@ int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
173 net_num=0; 176 net_num=0;
174 while (net_num < rnum) 177 while (net_num < rnum)
175 { 178 {
179#ifndef OPENSSL_SYS_WIN32
176 i=read(fd,(void *)&(net[net_num]),rnum-net_num); 180 i=read(fd,(void *)&(net[net_num]),rnum-net_num);
181#else
182 i=_read(fd,(void *)&(net[net_num]),rnum-net_num);
183#endif
177#ifdef EINTR 184#ifdef EINTR
178 if ((i == -1) && (errno == EINTR)) continue; 185 if ((i == -1) && (errno == EINTR)) continue;
179#endif 186#endif
@@ -228,5 +235,6 @@ int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
228 } 235 }
229 } 236 }
230 return num; 237 return num;
238#endif /* OPENSSL_NO_POSIX_IO */
231 } 239 }
232 240
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
index c2f032c9a6..2353ac1e89 100644
--- a/src/lib/libcrypto/des/enc_writ.c
+++ b/src/lib/libcrypto/des/enc_writ.c
@@ -80,6 +80,9 @@
80int DES_enc_write(int fd, const void *_buf, int len, 80int DES_enc_write(int fd, const void *_buf, int len,
81 DES_key_schedule *sched, DES_cblock *iv) 81 DES_key_schedule *sched, DES_cblock *iv)
82 { 82 {
83#if defined(OPENSSL_NO_POSIX_IO)
84 return (-1);
85#else
83#ifdef _LIBC 86#ifdef _LIBC
84 extern unsigned long time(); 87 extern unsigned long time();
85 extern int write(); 88 extern int write();
@@ -172,4 +175,5 @@ int DES_enc_write(int fd, const void *_buf, int len,
172 } 175 }
173 176
174 return(len); 177 return(len);
178#endif /* OPENSSL_NO_POSIX_IO */
175 } 179 }
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
index 1390138787..8822816938 100644
--- a/src/lib/libcrypto/des/fcrypt_b.c
+++ b/src/lib/libcrypto/des/fcrypt_b.c
@@ -100,12 +100,10 @@ void fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0,
100#ifndef DES_UNROLL 100#ifndef DES_UNROLL
101 register int i; 101 register int i;
102 102
103 for (i=0; i<32; i+=8) 103 for (i=0; i<32; i+=4)
104 { 104 {
105 D_ENCRYPT(l,r,i+0); /* 1 */ 105 D_ENCRYPT(l,r,i+0); /* 1 */
106 D_ENCRYPT(r,l,i+2); /* 2 */ 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 } 107 }
110#else 108#else
111 D_ENCRYPT(l,r, 0); /* 1 */ 109 D_ENCRYPT(l,r, 0); /* 1 */
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
index c0806d593c..3004cc3ab3 100644
--- a/src/lib/libcrypto/des/set_key.c
+++ b/src/lib/libcrypto/des/set_key.c
@@ -64,12 +64,8 @@
64 * 1.0 First working version 64 * 1.0 First working version
65 */ 65 */
66#include "des_locl.h" 66#include "des_locl.h"
67#ifdef OPENSSL_FIPS
68#include <openssl/fips.h>
69#endif
70
71 67
72OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key); /* defaults to false */ 68OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key,0) /* defaults to false */
73 69
74static const unsigned char odd_parity[256]={ 70static const unsigned char odd_parity[256]={
75 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14, 71 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
@@ -340,7 +336,7 @@ int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule)
340 336
341void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule) 337void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
342 { 338 {
343 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; 339 static const int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
344 register DES_LONG c,d,t,s,t2; 340 register DES_LONG c,d,t,s,t2;
345 register const unsigned char *in; 341 register const unsigned char *in;
346 register DES_LONG *k; 342 register DES_LONG *k;
@@ -353,10 +349,6 @@ void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
353 k = &schedule->ks->deslong[0]; 349 k = &schedule->ks->deslong[0];
354 in = &(*key)[0]; 350 in = &(*key)[0];
355 351
356#ifdef OPENSSL_FIPS
357 FIPS_selftest_check();
358#endif
359
360 c2l(in,c); 352 c2l(in,c);
361 c2l(in,d); 353 c2l(in,d);
362 354
@@ -413,4 +405,3 @@ void des_fixup_key_parity(des_cblock *key)
413 des_set_odd_parity(key); 405 des_set_odd_parity(key);
414 } 406 }
415*/ 407*/
416
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c
index dc0c761b71..058cab6bce 100644
--- a/src/lib/libcrypto/des/xcbc_enc.c
+++ b/src/lib/libcrypto/des/xcbc_enc.c
@@ -61,7 +61,7 @@
61/* RSA's DESX */ 61/* RSA's DESX */
62 62
63#if 0 /* broken code, preserved just in case anyone specifically looks for this */ 63#if 0 /* broken code, preserved just in case anyone specifically looks for this */
64static unsigned char desx_white_in2out[256]={ 64static const unsigned char desx_white_in2out[256]={
650xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0, 650xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0,
660x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A, 660x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A,
670x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36, 670x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36,