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($R,&DWP(0,"eax","",0));
\r
67 &mov($L,&DWP(4,"eax","",0));
\r
77 &comment("fixup rotate");
\r
82 &comment("load counter, key_schedule and enc flag");
\r
87 &xor( "ebx", "ebx" );
\r
88 &mov("eax",&wparam(2)); # get encrypt flag
\r
89 &xor( "ecx", "ecx" );
\r
91 &mov( $ks, &wparam(1) );
\r
92 &je(&label("start_decrypt"));
\r
94 for ($i=0; $i<16; $i+=2)
\r
97 &comment("Round $i");
\r
98 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
\r
101 &comment("Round ".sprintf("%d",$i+1));
\r
102 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
\r
104 &jmp(&label("end"));
\r
106 &set_label("start_decrypt");
\r
108 for ($i=15; $i>0; $i-=2)
\r
111 &comment("Round $i");
\r
112 &D_ENCRYPT(15-$i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
\r
114 &comment("Round ".sprintf("%d",$i-1));
\r
115 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
\r
132 &mov("eax",&wparam(0));
\r
133 &mov(&DWP(0,"eax","",0),$L);
\r
134 &mov(&DWP(4,"eax","",0),$R);
\r
136 &function_end($name);
\r
141 local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_;
\r
143 &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0));
\r
144 &mov( $u, &DWP(&n2a($S*4),$ks,"",0));
\r
148 &and( $u, "0xfcfcfcfc" );
\r
149 &and( $t, "0xfcfcfcfc" );
\r
150 &movb( &LB($tmp1), &LB($u) );
\r
151 &movb( &LB($tmp2), &HB($u) );
\r
152 &xor( $L, &DWP(" $desSP",$tmp1,"",0));
\r
154 &xor( $L, &DWP("0x200+$desSP",$tmp2,"",0));
\r
155 &movb( &LB($tmp1), &LB($u) );
\r
156 &movb( &LB($tmp2), &HB($u) );
\r
157 &xor( $L, &DWP("0x400+$desSP",$tmp1,"",0));
\r
158 &mov( $u, &DWP("0x600+$desSP",$tmp2,"",0));
\r
160 &movb( &LB($tmp1), &LB($t) );
\r
161 &movb( &LB($tmp2), &HB($t) );
\r
162 &xor( $L, &DWP("0x100+$desSP",$tmp1,"",0));
\r
164 &xor( $u, &DWP("0x300+$desSP",$tmp2,"",0));
\r
165 &movb( &LB($tmp1), &LB($t) );
\r
166 &movb( &LB($tmp2), &HB($t) );
\r
167 &xor( $L, &DWP("0x500+$desSP",$tmp1,"",0));
\r
168 &xor( $u, &DWP("0x700+$desSP",$tmp2,"",0));
\r
174 local($a,$b,$tt,$shift,$mask)=@_;
\r
177 &shr( $tt, $shift );
\r
179 &and( $tt, $mask );
\r
181 &shl( $tt, $shift );
\r
187 local($l,$r,$tt)=@_;
\r
189 &PERM_OP($r,$l,$tt, 4,"0x0f0f0f0f");
\r
190 &PERM_OP($l,$r,$tt,16,"0x0000ffff");
\r
191 &PERM_OP($r,$l,$tt, 2,"0x33333333");
\r
192 &PERM_OP($l,$r,$tt, 8,"0x00ff00ff");
\r
193 &PERM_OP($r,$l,$tt, 1,"0x55555555");
\r
198 local($l,$r,$tt)=@_;
\r
200 &PERM_OP($l,$r,$tt, 1,"0x55555555");
\r
201 &PERM_OP($r,$l,$tt, 8,"0x00ff00ff");
\r
202 &PERM_OP($l,$r,$tt, 2,"0x33333333");
\r
203 &PERM_OP($r,$l,$tt,16,"0x0000ffff");
\r
204 &PERM_OP($l,$r,$tt, 4,"0x0f0f0f0f");
\r
209 sprintf("%d",$_[0]);
\r