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