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