summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/des')
-rw-r--r--src/lib/libcrypto/des/Makefile.ssl23
-rw-r--r--src/lib/libcrypto/des/asm/crypt586.pl46
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl50
-rw-r--r--src/lib/libcrypto/des/cbc_cksm.c9
-rw-r--r--src/lib/libcrypto/des/des.c32
-rw-r--r--src/lib/libcrypto/des/des_locl.h13
-rw-r--r--src/lib/libcrypto/des/des_old.h2
-rw-r--r--src/lib/libcrypto/des/des_ver.h8
-rw-r--r--src/lib/libcrypto/des/destest.c6
-rw-r--r--src/lib/libcrypto/des/read2pwd.c8
-rw-r--r--src/lib/libcrypto/des/read_pwd.c44
-rw-r--r--src/lib/libcrypto/des/str2key.c4
12 files changed, 137 insertions, 108 deletions
diff --git a/src/lib/libcrypto/des/Makefile.ssl b/src/lib/libcrypto/des/Makefile.ssl
index 826ffcc58c..45eba0b3c9 100644
--- a/src/lib/libcrypto/des/Makefile.ssl
+++ b/src/lib/libcrypto/des/Makefile.ssl
@@ -66,22 +66,11 @@ des: des.o cbc3_enc.o lib
66 $(CC) $(CFLAGS) -o des des.o cbc3_enc.o $(LIB) 66 $(CC) $(CFLAGS) -o des des.o cbc3_enc.o $(LIB)
67 67
68# elf 68# elf
69asm/dx86-elf.o: asm/dx86unix.cpp 69asm/dx86-elf.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
70 $(CPP) -DELF -x c asm/dx86unix.cpp | as -o asm/dx86-elf.o 70 (cd asm; $(PERL) des-586.pl elf $(CFLAGS) > dx86-elf.s)
71 71
72asm/yx86-elf.o: asm/yx86unix.cpp 72asm/yx86-elf.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
73 $(CPP) -DELF -x c asm/yx86unix.cpp | as -o asm/yx86-elf.o 73 (cd asm; $(PERL) crypt586.pl elf $(CFLAGS) > yx86-elf.s)
74
75# solaris
76asm/dx86-sol.o: asm/dx86unix.cpp
77 $(CC) -E -DSOL asm/dx86unix.cpp | sed 's/^#.*//' > asm/dx86-sol.s
78 as -o asm/dx86-sol.o asm/dx86-sol.s
79 rm -f asm/dx86-sol.s
80
81asm/yx86-sol.o: asm/yx86unix.cpp
82 $(CC) -E -DSOL asm/yx86unix.cpp | sed 's/^#.*//' > asm/yx86-sol.s
83 as -o asm/yx86-sol.o asm/yx86-sol.s
84 rm -f asm/yx86-sol.s
85 74
86# a.out 75# a.out
87asm/dx86-out.o: asm/dx86unix.cpp 76asm/dx86-out.o: asm/dx86unix.cpp
@@ -130,14 +119,14 @@ lint:
130 lint -DLINT $(INCLUDES) $(SRC)>fluff 119 lint -DLINT $(INCLUDES) $(SRC)>fluff
131 120
132depend: 121depend:
133 $(MAKEDEPEND) $(CFLAG) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) 122 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
134 123
135dclean: 124dclean:
136 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 125 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
137 mv -f Makefile.new $(MAKEFILE) 126 mv -f Makefile.new $(MAKEFILE)
138 127
139clean: 128clean:
140 rm -f asm/dx86unix.cpp asm/yx86unix.cpp *.o asm/*.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff 129 rm -f asm/dx86unix.cpp asm/yx86unix.cpp asm/*-elf.* *.o asm/*.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff
141 130
142# DO NOT DELETE THIS LINE -- make depend depends on it. 131# DO NOT DELETE THIS LINE -- make depend depends on it.
143 132
diff --git a/src/lib/libcrypto/des/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl
index 3d41d82f69..1d04ed6def 100644
--- a/src/lib/libcrypto/des/asm/crypt586.pl
+++ b/src/lib/libcrypto/des/asm/crypt586.pl
@@ -26,11 +26,18 @@ sub fcrypt_body
26 26
27 &comment(""); 27 &comment("");
28 &comment("Load the 2 words"); 28 &comment("Load the 2 words");
29 $ks="ebp"; 29 $trans="ebp";
30 30
31 &xor( $L, $L); 31 &xor( $L, $L);
32 &xor( $R, $R); 32 &xor( $R, $R);
33 &mov($ks,&wparam(1)); 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
34 41
35 &push(&DWC(25)); # add a variable 42 &push(&DWC(25)); # add a variable
36 43
@@ -39,11 +46,11 @@ sub fcrypt_body
39 { 46 {
40 &comment(""); 47 &comment("");
41 &comment("Round $i"); 48 &comment("Round $i");
42 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); 49 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
43 50
44 &comment(""); 51 &comment("");
45 &comment("Round ".sprintf("%d",$i+1)); 52 &comment("Round ".sprintf("%d",$i+1));
46 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); 53 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
47 } 54 }
48 &mov("ebx", &swtmp(0)); 55 &mov("ebx", &swtmp(0));
49 &mov("eax", $L); 56 &mov("eax", $L);
@@ -61,14 +68,14 @@ sub fcrypt_body
61 &mov(&DWP(0,"edx","",0),"eax"); 68 &mov(&DWP(0,"edx","",0),"eax");
62 &mov(&DWP(4,"edx","",0),$L); 69 &mov(&DWP(4,"edx","",0),$L);
63 70
64 &pop("ecx"); # remove variable 71 &add("esp",8); # remove variables
65 72
66 &function_end($name); 73 &function_end($name);
67 } 74 }
68 75
69sub D_ENCRYPT 76sub D_ENCRYPT
70 { 77 {
71 local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_; 78 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
72 79
73 &mov( $u, &wparam(2)); # 2 80 &mov( $u, &wparam(2)); # 2
74 &mov( $t, $R); 81 &mov( $t, $R);
@@ -85,9 +92,9 @@ sub D_ENCRYPT
85 &shl( $tmp2, 16); # 1 92 &shl( $tmp2, 16); # 1
86 &xor( $u, $tmp1); # 2 93 &xor( $u, $tmp1); # 2
87 &xor( $t, $tmp2); # 2 94 &xor( $t, $tmp2); # 2
88 &mov( $tmp1, &DWP(&n2a($S*4),$ks,"",0)); # 2 95 &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2
89 &xor( $u, $tmp1); 96 &xor( $u, $tmp1);
90 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$ks,"",0)); # 2 97 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2
91 &xor( $u, $R); 98 &xor( $u, $R);
92 &xor( $t, $R); 99 &xor( $t, $R);
93 &xor( $t, $tmp2); 100 &xor( $t, $tmp2);
@@ -99,31 +106,28 @@ sub D_ENCRYPT
99 &movb( &LB($tmp1), &LB($u) ); 106 &movb( &LB($tmp1), &LB($u) );
100 &movb( &LB($tmp2), &HB($u) ); 107 &movb( &LB($tmp2), &HB($u) );
101 &rotr( $t, 4 ); 108 &rotr( $t, 4 );
102 &mov( $ks, &DWP(" $desSP",$tmp1,"",0)); 109 &mov( $trans, &swtmp(1));
110 &xor( $L, &DWP(" ",$trans,$tmp1,0));
103 &movb( &LB($tmp1), &LB($t) ); 111 &movb( &LB($tmp1), &LB($t) );
104 &xor( $L, $ks); 112 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
105 &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0));
106 &xor( $L, $ks);
107 &movb( &LB($tmp2), &HB($t) ); 113 &movb( &LB($tmp2), &HB($t) );
108 &shr( $u, 16); 114 &shr( $u, 16);
109 &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0)); 115 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
110 &xor( $L, $ks);
111 &movb( &LB($tmp1), &HB($u) ); 116 &movb( &LB($tmp1), &HB($u) );
112 &shr( $t, 16); 117 &shr( $t, 16);
113 &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0)); 118 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
114 &xor( $L, $ks);
115 &mov( $ks, &wparam(1));
116 &movb( &LB($tmp2), &HB($t) ); 119 &movb( &LB($tmp2), &HB($t) );
117 &and( $u, "0xff" ); 120 &and( $u, "0xff" );
118 &and( $t, "0xff" ); 121 &and( $t, "0xff" );
119 &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0)); 122 &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0));
120 &xor( $L, $tmp1); 123 &xor( $L, $tmp1);
121 &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0)); 124 &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0));
122 &xor( $L, $tmp1); 125 &xor( $L, $tmp1);
123 &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0)); 126 &mov( $tmp1, &DWP("0x400",$trans,$u,0));
124 &xor( $L, $tmp1); 127 &xor( $L, $tmp1);
125 &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0)); 128 &mov( $tmp1, &DWP("0x500",$trans,$t,0));
126 &xor( $L, $tmp1); 129 &xor( $L, $tmp1);
130 &mov( $trans, &wparam(1));
127 } 131 }
128 132
129sub n2a 133sub n2a
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl
index 0d08e8a3a9..b75d3c6b3a 100644
--- a/src/lib/libcrypto/des/asm/des-586.pl
+++ b/src/lib/libcrypto/des/asm/des-586.pl
@@ -40,7 +40,7 @@ sub DES_encrypt
40 40
41 &comment(""); 41 &comment("");
42 &comment("Load the 2 words"); 42 &comment("Load the 2 words");
43 $ks="ebp"; 43 $trans="ebp";
44 44
45 if ($do_ip) 45 if ($do_ip)
46 { 46 {
@@ -72,7 +72,12 @@ sub DES_encrypt
72 &rotl($L,3); 72 &rotl($L,3);
73 } 73 }
74 74
75 &mov( $ks, &wparam(1) ); 75 # PIC-ification:-)
76 &picmeup($trans,"DES_SPtrans");
77 #if ($cpp) { &picmeup($trans,"DES_SPtrans"); }
78 #else { &lea($trans,&DWP("DES_SPtrans")); }
79
80 &mov( "ecx", &wparam(1) );
76 &cmp("ebx","0"); 81 &cmp("ebx","0");
77 &je(&label("start_decrypt")); 82 &je(&label("start_decrypt"));
78 83
@@ -80,11 +85,11 @@ sub DES_encrypt
80 { 85 {
81 &comment(""); 86 &comment("");
82 &comment("Round $i"); 87 &comment("Round $i");
83 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); 88 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
84 89
85 &comment(""); 90 &comment("");
86 &comment("Round ".sprintf("%d",$i+1)); 91 &comment("Round ".sprintf("%d",$i+1));
87 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); 92 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
88 } 93 }
89 &jmp(&label("end")); 94 &jmp(&label("end"));
90 95
@@ -94,10 +99,10 @@ sub DES_encrypt
94 { 99 {
95 &comment(""); 100 &comment("");
96 &comment("Round $i"); 101 &comment("Round $i");
97 &D_ENCRYPT(15-$i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); 102 &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
98 &comment(""); 103 &comment("");
99 &comment("Round ".sprintf("%d",$i-1)); 104 &comment("Round ".sprintf("%d",$i-1));
100 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); 105 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx");
101 } 106 }
102 107
103 &set_label("end"); 108 &set_label("end");
@@ -134,43 +139,36 @@ sub DES_encrypt
134 139
135sub D_ENCRYPT 140sub D_ENCRYPT
136 { 141 {
137 local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_; 142 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
138 143
139 &mov( $u, &DWP(&n2a($S*4),$ks,"",0)); 144 &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0));
140 &xor( $tmp1, $tmp1); 145 &xor( $tmp1, $tmp1);
141 &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0)); 146 &mov( $t, &DWP(&n2a(($S+1)*4),$tmp2,"",0));
142 &xor( $u, $R); 147 &xor( $u, $R);
148 &xor( $tmp2, $tmp2);
143 &xor( $t, $R); 149 &xor( $t, $R);
144 &and( $u, "0xfcfcfcfc" ); 150 &and( $u, "0xfcfcfcfc" );
145 &and( $t, "0xcfcfcfcf" ); 151 &and( $t, "0xcfcfcfcf" );
146 &movb( &LB($tmp1), &LB($u) ); 152 &movb( &LB($tmp1), &LB($u) );
147 &movb( &LB($tmp2), &HB($u) ); 153 &movb( &LB($tmp2), &HB($u) );
148 &rotr( $t, 4 ); 154 &rotr( $t, 4 );
149 &mov( $ks, &DWP(" $desSP",$tmp1,"",0)); 155 &xor( $L, &DWP(" ",$trans,$tmp1,0));
150 &movb( &LB($tmp1), &LB($t) ); 156 &movb( &LB($tmp1), &LB($t) );
151 &xor( $L, $ks); 157 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
152 &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0));
153 &xor( $L, $ks); ######
154 &movb( &LB($tmp2), &HB($t) ); 158 &movb( &LB($tmp2), &HB($t) );
155 &shr( $u, 16); 159 &shr( $u, 16);
156 &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0)); 160 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
157 &xor( $L, $ks); ######
158 &movb( &LB($tmp1), &HB($u) ); 161 &movb( &LB($tmp1), &HB($u) );
159 &shr( $t, 16); 162 &shr( $t, 16);
160 &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0)); 163 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
161 &xor( $L, $ks);
162 &mov( $ks, &wparam(1) );
163 &movb( &LB($tmp2), &HB($t) ); 164 &movb( &LB($tmp2), &HB($t) );
164 &and( $u, "0xff" ); 165 &and( $u, "0xff" );
165 &and( $t, "0xff" ); 166 &and( $t, "0xff" );
166 &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0)); 167 &xor( $L, &DWP("0x600",$trans,$tmp1,0));
167 &xor( $L, $tmp1); 168 &xor( $L, &DWP("0x700",$trans,$tmp2,0));
168 &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0)); 169 &mov( $tmp2, &wparam(1) );
169 &xor( $L, $tmp1); 170 &xor( $L, &DWP("0x400",$trans,$u,0));
170 &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0)); 171 &xor( $L, &DWP("0x500",$trans,$t,0));
171 &xor( $L, $tmp1);
172 &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0));
173 &xor( $L, $tmp1);
174 } 172 }
175 173
176sub n2a 174sub n2a
diff --git a/src/lib/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c
index 6c5305b99d..09a7ba56aa 100644
--- a/src/lib/libcrypto/des/cbc_cksm.c
+++ b/src/lib/libcrypto/des/cbc_cksm.c
@@ -93,5 +93,14 @@ DES_LONG DES_cbc_cksum(const unsigned char *in, DES_cblock *output,
93 l2c(tout1,out); 93 l2c(tout1,out);
94 } 94 }
95 tout0=tin0=tin1=tin[0]=tin[1]=0; 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);
96 return(tout1); 105 return(tout1);
97 } 106 }
diff --git a/src/lib/libcrypto/des/des.c b/src/lib/libcrypto/des/des.c
index d8c846b23d..343135ff9e 100644
--- a/src/lib/libcrypto/des/des.c
+++ b/src/lib/libcrypto/des/des.c
@@ -427,7 +427,7 @@ void doencryption(void)
427 k2[i-8]=k; 427 k2[i-8]=k;
428 } 428 }
429 DES_set_key_unchecked(&k2,&ks2); 429 DES_set_key_unchecked(&k2,&ks2);
430 memset(k2,0,sizeof(k2)); 430 OPENSSL_cleanse(k2,sizeof(k2));
431 } 431 }
432 else if (longk || flag3) 432 else if (longk || flag3)
433 { 433 {
@@ -435,7 +435,7 @@ void doencryption(void)
435 { 435 {
436 DES_string_to_2keys(key,&kk,&k2); 436 DES_string_to_2keys(key,&kk,&k2);
437 DES_set_key_unchecked(&k2,&ks2); 437 DES_set_key_unchecked(&k2,&ks2);
438 memset(k2,0,sizeof(k2)); 438 OPENSSL_cleanse(k2,sizeof(k2));
439 } 439 }
440 else 440 else
441 DES_string_to_key(key,&kk); 441 DES_string_to_key(key,&kk);
@@ -457,8 +457,8 @@ void doencryption(void)
457 } 457 }
458 458
459 DES_set_key_unchecked(&kk,&ks); 459 DES_set_key_unchecked(&kk,&ks);
460 memset(key,0,sizeof(key)); 460 OPENSSL_cleanse(key,sizeof(key));
461 memset(kk,0,sizeof(kk)); 461 OPENSSL_cleanse(kk,sizeof(kk));
462 /* woops - A bug that does not showup under unix :-( */ 462 /* woops - A bug that does not showup under unix :-( */
463 memset(iv,0,sizeof(iv)); 463 memset(iv,0,sizeof(iv));
464 memset(iv2,0,sizeof(iv2)); 464 memset(iv2,0,sizeof(iv2));
@@ -666,18 +666,18 @@ void doencryption(void)
666 if (l) fclose(CKSUM_OUT); 666 if (l) fclose(CKSUM_OUT);
667 } 667 }
668problems: 668problems:
669 memset(buf,0,sizeof(buf)); 669 OPENSSL_cleanse(buf,sizeof(buf));
670 memset(obuf,0,sizeof(obuf)); 670 OPENSSL_cleanse(obuf,sizeof(obuf));
671 memset(&ks,0,sizeof(ks)); 671 OPENSSL_cleanse(&ks,sizeof(ks));
672 memset(&ks2,0,sizeof(ks2)); 672 OPENSSL_cleanse(&ks2,sizeof(ks2));
673 memset(iv,0,sizeof(iv)); 673 OPENSSL_cleanse(iv,sizeof(iv));
674 memset(iv2,0,sizeof(iv2)); 674 OPENSSL_cleanse(iv2,sizeof(iv2));
675 memset(kk,0,sizeof(kk)); 675 OPENSSL_cleanse(kk,sizeof(kk));
676 memset(k2,0,sizeof(k2)); 676 OPENSSL_cleanse(k2,sizeof(k2));
677 memset(uubuf,0,sizeof(uubuf)); 677 OPENSSL_cleanse(uubuf,sizeof(uubuf));
678 memset(b,0,sizeof(b)); 678 OPENSSL_cleanse(b,sizeof(b));
679 memset(bb,0,sizeof(bb)); 679 OPENSSL_cleanse(bb,sizeof(bb));
680 memset(cksum,0,sizeof(cksum)); 680 OPENSSL_cleanse(cksum,sizeof(cksum));
681 if (Exit) EXIT(Exit); 681 if (Exit) EXIT(Exit);
682 } 682 }
683 683
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
index 70e833be3f..e44e8e98b2 100644
--- a/src/lib/libcrypto/des/des_locl.h
+++ b/src/lib/libcrypto/des/des_locl.h
@@ -162,7 +162,18 @@
162 162
163#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER) 163#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
164#define ROTATE(a,n) (_lrotr(a,n)) 164#define ROTATE(a,n) (_lrotr(a,n))
165#else 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
166#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n)))) 177#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n))))
167#endif 178#endif
168 179
diff --git a/src/lib/libcrypto/des/des_old.h b/src/lib/libcrypto/des/des_old.h
index fe32f21f61..1d8bf65101 100644
--- a/src/lib/libcrypto/des/des_old.h
+++ b/src/lib/libcrypto/des/des_old.h
@@ -173,10 +173,12 @@ typedef struct _ossl_old_des_ks_struct
173 DES_fcrypt((b),(s),(r)) 173 DES_fcrypt((b),(s),(r))
174#define des_crypt(b,s)\ 174#define des_crypt(b,s)\
175 DES_crypt((b),(s)) 175 DES_crypt((b),(s))
176#if 0
176#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT) && !defined(__OpenBSD__) 177#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT) && !defined(__OpenBSD__)
177#define crypt(b,s)\ 178#define crypt(b,s)\
178 DES_crypt((b),(s)) 179 DES_crypt((b),(s))
179#endif 180#endif
181#endif
180#define des_ofb_encrypt(i,o,n,l,k,iv)\ 182#define des_ofb_encrypt(i,o,n,l,k,iv)\
181 DES_ofb_encrypt((i),(o),(n),(l),&(k),(iv)) 183 DES_ofb_encrypt((i),(o),(n),(l),&(k),(iv))
182#define des_pcbc_encrypt(i,o,l,k,iv,e)\ 184#define des_pcbc_encrypt(i,o,l,k,iv,e)\
diff --git a/src/lib/libcrypto/des/des_ver.h b/src/lib/libcrypto/des/des_ver.h
index ec9cc736e3..379bbadda2 100644
--- a/src/lib/libcrypto/des/des_ver.h
+++ b/src/lib/libcrypto/des/des_ver.h
@@ -63,5 +63,9 @@
63# define OPENSSL_EXTERN OPENSSL_EXPORT 63# define OPENSSL_EXTERN OPENSSL_EXPORT
64#endif 64#endif
65 65
66OPENSSL_EXTERN const char *DES_version; /* SSLeay version string */ 66/* The following macros make sure the names are different from libdes names */
67OPENSSL_EXTERN const char *libdes_version; /* old libdes version string */ 67#define DES_version OSSL_DES_version
68#define libdes_version OSSL_libdes_version
69
70OPENSSL_EXTERN const char *OSSL_DES_version; /* SSLeay version string */
71OPENSSL_EXTERN const char *OSSL_libdes_version; /* old libdes version string */
diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c
index 58e8c35dcb..687c00c792 100644
--- a/src/lib/libcrypto/des/destest.c
+++ b/src/lib/libcrypto/des/destest.c
@@ -84,9 +84,7 @@ int main(int argc, char *argv[])
84#else 84#else
85#include <openssl/des.h> 85#include <openssl/des.h>
86 86
87#if defined(PERL5) || defined(__FreeBSD__) || defined(NeXT)
88#define crypt(c,s) (des_crypt((c),(s))) 87#define crypt(c,s) (des_crypt((c),(s)))
89#endif
90 88
91/* tisk tisk - the test keys don't all have odd parity :-( */ 89/* tisk tisk - the test keys don't all have odd parity :-( */
92/* test data */ 90/* test data */
@@ -322,7 +320,11 @@ static unsigned char ofb_cipher[24]=
322 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3 320 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
323 }; 321 };
324 322
323#if 0
325static DES_LONG cbc_cksum_ret=0xB462FEF7L; 324static DES_LONG cbc_cksum_ret=0xB462FEF7L;
325#else
326static DES_LONG cbc_cksum_ret=0xF7FE62B4L;
327#endif
326static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; 328static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
327 329
328static char *pt(unsigned char *p); 330static char *pt(unsigned char *p);
diff --git a/src/lib/libcrypto/des/read2pwd.c b/src/lib/libcrypto/des/read2pwd.c
index b4720c3a98..3a63c4016c 100644
--- a/src/lib/libcrypto/des/read2pwd.c
+++ b/src/lib/libcrypto/des/read2pwd.c
@@ -120,8 +120,8 @@ int DES_read_password(DES_cblock *key, const char *prompt, int verify)
120 120
121 if ((ok=UI_UTIL_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0) 121 if ((ok=UI_UTIL_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
122 DES_string_to_key(buf,key); 122 DES_string_to_key(buf,key);
123 memset(buf,0,BUFSIZ); 123 OPENSSL_cleanse(buf,BUFSIZ);
124 memset(buff,0,BUFSIZ); 124 OPENSSL_cleanse(buff,BUFSIZ);
125 return(ok); 125 return(ok);
126 } 126 }
127 127
@@ -133,7 +133,7 @@ int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
133 133
134 if ((ok=UI_UTIL_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0) 134 if ((ok=UI_UTIL_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
135 DES_string_to_2keys(buf,key1,key2); 135 DES_string_to_2keys(buf,key1,key2);
136 memset(buf,0,BUFSIZ); 136 OPENSSL_cleanse(buf,BUFSIZ);
137 memset(buff,0,BUFSIZ); 137 OPENSSL_cleanse(buff,BUFSIZ);
138 return(ok); 138 return(ok);
139 } 139 }
diff --git a/src/lib/libcrypto/des/read_pwd.c b/src/lib/libcrypto/des/read_pwd.c
index 9061935f21..ce5fa00a37 100644
--- a/src/lib/libcrypto/des/read_pwd.c
+++ b/src/lib/libcrypto/des/read_pwd.c
@@ -101,8 +101,10 @@
101 101
102#ifdef WIN_CONSOLE_BUG 102#ifdef WIN_CONSOLE_BUG
103#include <windows.h> 103#include <windows.h>
104#ifndef OPENSSL_SYS_WINCE
104#include <wincon.h> 105#include <wincon.h>
105#endif 106#endif
107#endif
106 108
107 109
108/* There are 5 types of terminal interface supported, 110/* There are 5 types of terminal interface supported,
@@ -133,7 +135,7 @@
133#define SGTTY 135#define SGTTY
134#endif 136#endif
135 137
136#if defined(OPENSSL_SYS_VSWORKS) 138#if defined(OPENSSL_SYS_VXWORKS)
137#undef TERMIOS 139#undef TERMIOS
138#undef TERMIO 140#undef TERMIO
139#undef SGTTY 141#undef SGTTY
@@ -167,7 +169,7 @@
167#include <sys/ioctl.h> 169#include <sys/ioctl.h>
168#endif 170#endif
169 171
170#if defined(OPENSSL_SYS_MSDOS) && !defined(__CYGWIN32__) 172#if defined(OPENSSL_SYS_MSDOS) && !defined(__CYGWIN32__) && !defined(OPENSSL_SYS_WINCE)
171#include <conio.h> 173#include <conio.h>
172#define fgets(a,b,c) noecho_fgets(a,b,c) 174#define fgets(a,b,c) noecho_fgets(a,b,c)
173#endif 175#endif
@@ -218,11 +220,29 @@ int des_read_pw_string(char *buf, int length, const char *prompt,
218 int ret; 220 int ret;
219 221
220 ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify); 222 ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
221 memset(buff,0,BUFSIZ); 223 OPENSSL_cleanse(buff,BUFSIZ);
222 return(ret); 224 return(ret);
223 } 225 }
224 226
225#ifndef OPENSSL_SYS_WIN16 227#ifdef OPENSSL_SYS_WINCE
228
229int des_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
230 {
231 memset(buf,0,size);
232 memset(buff,0,size);
233 return(0);
234 }
235
236#elif defined(OPENSSL_SYS_WIN16)
237
238int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify)
239 {
240 memset(buf,0,size);
241 memset(buff,0,size);
242 return(0);
243 }
244
245#else /* !OPENSSL_SYS_WINCE && !OPENSSL_SYS_WIN16 */
226 246
227static void read_till_nl(FILE *in) 247static void read_till_nl(FILE *in)
228 { 248 {
@@ -274,7 +294,7 @@ int des_read_pw(char *buf, char *buff, int size, const char *prompt,
274#ifdef OPENSSL_SYS_MSDOS 294#ifdef OPENSSL_SYS_MSDOS
275 if ((tty=fopen("con","r")) == NULL) 295 if ((tty=fopen("con","r")) == NULL)
276 tty=stdin; 296 tty=stdin;
277#elif defined(MAC_OS_pre_X) || defined(OPENSSL_SYS_VSWORKS) 297#elif defined(MAC_OS_pre_X) || defined(OPENSSL_SYS_VXWORKS)
278 tty=stdin; 298 tty=stdin;
279#else 299#else
280#ifndef OPENSSL_SYS_MPE 300#ifndef OPENSSL_SYS_MPE
@@ -393,17 +413,6 @@ error:
393 return(!ok); 413 return(!ok);
394 } 414 }
395 415
396#else /* OPENSSL_SYS_WIN16 */
397
398int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify)
399 {
400 memset(buf,0,size);
401 memset(buff,0,size);
402 return(0);
403 }
404
405#endif
406
407static void pushsig(void) 416static void pushsig(void)
408 { 417 {
409 int i; 418 int i;
@@ -466,7 +475,7 @@ static void recsig(int i)
466#endif 475#endif
467 } 476 }
468 477
469#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) 478#ifdef OPENSSL_SYS_MSDOS
470static int noecho_fgets(char *buf, int size, FILE *tty) 479static int noecho_fgets(char *buf, int size, FILE *tty)
471 { 480 {
472 int i; 481 int i;
@@ -509,3 +518,4 @@ static int noecho_fgets(char *buf, int size, FILE *tty)
509 return(strlen(buf)); 518 return(strlen(buf));
510 } 519 }
511#endif 520#endif
521#endif /* !OPENSSL_SYS_WINCE && !WIN16 */
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c
index 36c3f81d99..0373db469c 100644
--- a/src/lib/libcrypto/des/str2key.c
+++ b/src/lib/libcrypto/des/str2key.c
@@ -94,7 +94,7 @@ void DES_string_to_key(const char *str, DES_cblock *key)
94 DES_set_key_unchecked(key,&ks); 94 DES_set_key_unchecked(key,&ks);
95#endif 95#endif
96 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key); 96 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key);
97 memset(&ks,0,sizeof(ks)); 97 OPENSSL_cleanse(&ks,sizeof(ks));
98 DES_set_odd_parity(key); 98 DES_set_odd_parity(key);
99 } 99 }
100 100
@@ -167,7 +167,7 @@ void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
167 DES_set_key_unchecked(key2,&ks); 167 DES_set_key_unchecked(key2,&ks);
168#endif 168#endif
169 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2); 169 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2);
170 memset(&ks,0,sizeof(ks)); 170 OPENSSL_cleanse(&ks,sizeof(ks));
171 DES_set_odd_parity(key1); 171 DES_set_odd_parity(key1);
172 DES_set_odd_parity(key2); 172 DES_set_odd_parity(key2);
173 } 173 }