5 # base code is in microsft
\r
10 # WILL NOT WORK ANYMORE WITH desboth.pl
\r
11 require "desboth.pl";
\r
13 if ( ($ARGV[0] eq "elf"))
\r
14 { require "x86unix.pl"; }
\r
15 elsif ( ($ARGV[0] eq "a.out"))
\r
16 { $aout=1; require "x86unix.pl"; }
\r
17 elsif ( ($ARGV[0] eq "sol"))
\r
18 { $sol=1; require "x86unix.pl"; }
\r
19 elsif ( ($ARGV[0] eq "cpp"))
\r
20 { $cpp=1; require "x86unix.pl"; }
\r
21 elsif ( ($ARGV[0] eq "win32"))
\r
22 { require "x86ms.pl"; }
\r
25 print STDERR <<"EOF";
\r
26 Pick one target type from
\r
27 elf - linux, FreeBSD etc
\r
30 cpp - format so x86unix.cpp can be used
\r
31 win32 - Windows 95/Windows NT
\r
36 &comment("Don't even think of reading this code");
\r
37 &comment("It was automatically generated by $prog");
\r
38 &comment("Which is a perl program used to generate the x86 assember for");
\r
39 &comment("any of elf, a.out, Win32, or Solaris");
\r
40 &comment("It can be found in SSLeay 0.6.5+ or in libdes 3.26+");
\r
41 &comment("eric <eay\@cryptsoft.com>");
\r
49 &des_encrypt("des_encrypt",1);
\r
50 &des_encrypt("des_encrypt2",0);
\r
52 &des_encrypt3("des_encrypt3",1);
\r
53 &des_encrypt3("des_decrypt3",0);
\r
59 local($name,$do_ip)=@_;
\r
61 &function_begin($name,3,"EXTRN _des_SPtrans:DWORD");
\r
64 &comment("Load the 2 words");
\r
65 &mov("eax",&wparam(0));
\r
66 &mov($L,&DWP(0,"eax","",0));
\r
67 &mov($R,&DWP(4,"eax","",0));
\r
79 &comment("fixup rotate");
\r
85 &comment("load counter, key_schedule and enc flag");
\r
86 &mov("eax",&wparam(2)); # get encrypt flag
\r
87 &mov("ebp",&wparam(1)); # get ks
\r
89 &je(&label("start_decrypt"));
\r
93 for ($i=0; $i<16; $i+=2)
\r
96 &comment("Round $i");
\r
97 &D_ENCRYPT($L,$R,$i*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
\r
100 &comment("Round ".sprintf("%d",$i+1));
\r
101 &D_ENCRYPT($R,$L,($i+1)*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
\r
103 &jmp(&label("end"));
\r
105 &set_label("start_decrypt");
\r
107 for ($i=15; $i>0; $i-=2)
\r
110 &comment("Round $i");
\r
111 &D_ENCRYPT($L,$R,$i*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
\r
113 &comment("Round ".sprintf("%d",$i-1));
\r
114 &D_ENCRYPT($R,$L,($i-1)*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
\r
131 &mov("eax",&wparam(0));
\r
132 &mov(&DWP(0,"eax","",0),$L);
\r
133 &mov(&DWP(4,"eax","",0),$R);
\r
135 &function_end($name);
\r
139 # The logic is to load R into 2 registers and operate on both at the same time.
\r
140 # We also load the 2 R's into 2 more registers so we can do the 'move word down a byte'
\r
141 # while also masking the other copy and doing a lookup. We then also accumulate the
\r
142 # L value in 2 registers then combine them at the end.
\r
145 local($L,$R,$S,$ks,$desSP,$u,$t,$tmp1,$tmp2,$tmp3)=@_;
\r
147 &mov( $u, &DWP(&n2a($S*4),$ks,"",0));
\r
148 &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0));
\r
153 # the numbers at the end of the line are origional instruction order
\r
154 &mov( $tmp2, $u ); # 1 2
\r
155 &mov( $tmp1, $t ); # 1 1
\r
156 &and( $tmp2, "0xfc" ); # 1 4
\r
157 &and( $tmp1, "0xfc" ); # 1 3
\r
158 &shr( $t, 8 ); # 1 5
\r
159 &xor( $L, &DWP("0x100+$desSP",$tmp1,"",0)); # 1 7
\r
160 &shr( $u, 8 ); # 1 6
\r
161 &mov( $tmp1, &DWP(" $desSP",$tmp2,"",0)); # 1 8
\r
163 &mov( $tmp2, $u ); # 2 2
\r
164 &xor( $L, $tmp1 ); # 1 9
\r
165 &and( $tmp2, "0xfc" ); # 2 4
\r
166 &mov( $tmp1, $t ); # 2 1
\r
167 &and( $tmp1, "0xfc" ); # 2 3
\r
168 &shr( $t, 8 ); # 2 5
\r
169 &xor( $L, &DWP("0x300+$desSP",$tmp1,"",0)); # 2 7
\r
170 &shr( $u, 8 ); # 2 6
\r
171 &mov( $tmp1, &DWP("0x200+$desSP",$tmp2,"",0)); # 2 8
\r
172 &mov( $tmp2, $u ); # 3 2
\r
174 &xor( $L, $tmp1 ); # 2 9
\r
175 &and( $tmp2, "0xfc" ); # 3 4
\r
177 &mov( $tmp1, $t ); # 3 1
\r
178 &shr( $u, 8 ); # 3 6
\r
179 &and( $tmp1, "0xfc" ); # 3 3
\r
180 &shr( $t, 8 ); # 3 5
\r
181 &xor( $L, &DWP("0x500+$desSP",$tmp1,"",0)); # 3 7
\r
182 &mov( $tmp1, &DWP("0x400+$desSP",$tmp2,"",0)); # 3 8
\r
184 &and( $t, "0xfc" ); # 4 1
\r
185 &xor( $L, $tmp1 ); # 3 9
\r
187 &and( $u, "0xfc" ); # 4 2
\r
188 &xor( $L, &DWP("0x700+$desSP",$t,"",0)); # 4 3
\r
189 &xor( $L, &DWP("0x600+$desSP",$u,"",0)); # 4 4
\r
194 local($a,$b,$tt,$shift,$mask)=@_;
\r
197 &shr( $tt, $shift );
\r
199 &and( $tt, $mask );
\r
201 &shl( $tt, $shift );
\r
207 local($l,$r,$tt)=@_;
\r
209 &PERM_OP($r,$l,$tt, 4,"0x0f0f0f0f");
\r
210 &PERM_OP($l,$r,$tt,16,"0x0000ffff");
\r
211 &PERM_OP($r,$l,$tt, 2,"0x33333333");
\r
212 &PERM_OP($l,$r,$tt, 8,"0x00ff00ff");
\r
213 &PERM_OP($r,$l,$tt, 1,"0x55555555");
\r
218 local($l,$r,$tt)=@_;
\r
220 &PERM_OP($l,$r,$tt, 1,"0x55555555");
\r
221 &PERM_OP($r,$l,$tt, 8,"0x00ff00ff");
\r
222 &PERM_OP($l,$r,$tt, 2,"0x33333333");
\r
223 &PERM_OP($r,$l,$tt,16,"0x0000ffff");
\r
224 &PERM_OP($l,$r,$tt, 4,"0x0f0f0f0f");
\r
229 sprintf("%d",$_[0]);
\r