3 # The inner loop instruction sequence and the IP/FP modifications are from
\r
4 # Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
\r
5 # I've added the stuff needed for crypt() but I've not worried about making
\r
11 # base code is in microsft
\r
16 require "desboth.pl";
\r
18 if ( ($ARGV[0] eq "elf"))
\r
19 { require "x86unix.pl"; }
\r
20 elsif ( ($ARGV[0] eq "a.out"))
\r
21 { $aout=1; require "x86unix.pl"; }
\r
22 elsif ( ($ARGV[0] eq "sol"))
\r
23 { $sol=1; require "x86unix.pl"; }
\r
24 elsif ( ($ARGV[0] eq "cpp"))
\r
25 { $cpp=1; require "x86unix.pl"; }
\r
26 elsif ( ($ARGV[0] eq "win32"))
\r
27 { require "x86ms.pl"; }
\r
30 print STDERR <<"EOF";
\r
31 Pick one target type from
\r
32 elf - linux, FreeBSD etc
\r
35 cpp - format so x86unix.cpp can be used
\r
36 win32 - Windows 95/Windows NT
\r
41 &comment("Don't even think of reading this code");
\r
42 &comment("It was automatically generated by $prog");
\r
43 &comment("Which is a perl program used to generate the x86 assember for");
\r
44 &comment("any of elf, a.out, Win32, or Solaris");
\r
45 &comment("It can be found in SSLeay 0.6.5+ or in libdes 3.26+");
\r
46 &comment("eric <eay\@cryptsoft.com>");
\r
47 &comment("The inner loop instruction sequence and the IP/FP modifications");
\r
48 &comment("are from Svend Olaf Mikkelsen <svolaf\@inet.uni-c.dk>");
\r
57 &fcrypt_body("fcrypt_body");
\r
63 local($name,$do_ip)=@_;
\r
65 &function_begin($name,3,"EXTRN _des_SPtrans:DWORD");
\r
68 &comment("Load the 2 words");
\r
73 &mov($ks,&wparam(1));
\r
77 &set_label("start");
\r
78 for ($i=0; $i<16; $i+=2)
\r
81 &comment("Round $i");
\r
82 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
\r
85 &comment("Round ".sprintf("%d",$i+1));
\r
86 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
\r
92 &jnz(&label("start"));
\r
96 &mov("edx",&wparam(0));
\r
98 &FP_new($R,$L,"eax",3);
\r
99 &mov(&DWP(0,"edx","",0),"eax");
\r
100 &mov(&DWP(4,"edx","",0),$L);
\r
102 &function_end($name);
\r
107 local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_;
\r
109 &mov( $u, &wparam(2)); # 2
\r
112 &mov( $tmp2, &wparam(3)); # 2
\r
116 &and( $t, $tmp2); # 2
\r
119 &shl( $tmp1, 16); # 1
\r
121 &shl( $tmp2, 16); # 1
\r
122 &xor( $u, $tmp1); # 2
\r
123 &xor( $t, $tmp2); # 2
\r
124 &mov( $tmp1, &DWP(&n2a($S*4),$ks,"",0)); # 2
\r
126 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$ks,"",0)); # 2
\r
131 &and( $u, "0xfcfcfcfc" ); # 2
\r
132 &xor( $tmp1, $tmp1); # 1
\r
133 &and( $t, "0xcfcfcfcf" ); # 2
\r
134 &xor( $tmp2, $tmp2);
\r
135 &movb( &LB($tmp1), &LB($u) );
\r
136 &movb( &LB($tmp2), &HB($u) );
\r
138 &mov( $ks, &DWP(" $desSP",$tmp1,"",0));
\r
139 &movb( &LB($tmp1), &LB($t) );
\r
141 &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0));
\r
143 &movb( &LB($tmp2), &HB($t) );
\r
145 &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0));
\r
147 &movb( &LB($tmp1), &HB($u) );
\r
149 &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0));
\r
151 &mov( $ks, &DWP(24,"esp","",0));
\r
152 &movb( &LB($tmp2), &HB($t) );
\r
153 &and( $u, "0xff" );
\r
154 &and( $t, "0xff" );
\r
155 &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0));
\r
157 &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0));
\r
159 &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0));
\r
161 &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0));
\r
167 sprintf("%d",$_[0]);
\r
170 # now has a side affect of rotating $a by $shift
\r
173 local($a,$b,$tt,$shift,$mask,$last)=@_;
\r
175 &rotl( $a, $shift ) if ($shift != 0);
\r
179 if ($notlast eq $b)
\r
194 local($l,$r,$tt,$lr)=@_;
\r
196 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
\r
197 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
\r
198 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
\r
199 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
\r
200 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
\r
205 { &rotr($tt, 3-$lr); }
\r
206 else { &rotl($tt, $lr-3); }
\r
211 { &rotr($r, 2-$lr); }
\r
212 else { &rotl($r, $lr-2); }
\r
218 local($l,$r,$tt,$lr)=@_;
\r
223 { &rotl($r, 2-$lr); }
\r
224 else { &rotr($r, $lr-2); }
\r
229 { &rotl($l, 3-$lr); }
\r
230 else { &rotr($l, $lr-3); }
\r
233 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
\r
234 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
\r
235 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
\r
236 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
\r
237 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
\r