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
9 push(@INC,"perlasm","../../perlasm");
12 &asm_init($ARGV[0],"crypt586.pl");
17 &external_label("des_SPtrans");
18 &fcrypt_body("fcrypt_body");
23 local($name,$do_ip)=@_;
25 &function_begin($name,"EXTRN _des_SPtrans:DWORD");
28 &comment("Load the 2 words");
35 &push(25); # add a variable
38 for ($i=0; $i<16; $i+=2)
42 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
45 &comment("Round ".sprintf("%d",$i+1));
46 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
48 &mov("ebx", &swtmp(0));
53 &mov(&swtmp(0), "ebx");
54 &jnz(&label("start"));
58 &mov("edx",&wparam(0));
60 &FP_new($R,$L,"eax",3);
61 &mov(&DWP(0,"edx","",0),"eax");
62 &mov(&DWP(4,"edx","",0),$L);
64 &pop("ecx"); # remove variable
71 local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_;
73 &mov( $u, &wparam(2)); # 2
76 &mov( $tmp2, &wparam(3)); # 2
88 &mov( $tmp1, &DWP(&n2a($S*4),$ks,"",0)); # 2
90 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$ks,"",0)); # 2
95 &and( $u, "0xfcfcfcfc" ); # 2
96 &xor( $tmp1, $tmp1); # 1
97 &and( $t, "0xcfcfcfcf" ); # 2
99 &movb( &LB($tmp1), &LB($u) );
100 &movb( &LB($tmp2), &HB($u) );
102 &mov( $ks, &DWP(" $desSP",$tmp1,"",0));
103 &movb( &LB($tmp1), &LB($t) );
105 &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0));
107 &movb( &LB($tmp2), &HB($t) );
109 &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0));
111 &movb( &LB($tmp1), &HB($u) );
113 &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0));
115 &mov( $ks, &wparam(1));
116 &movb( &LB($tmp2), &HB($t) );
119 &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0));
121 &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0));
123 &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0));
125 &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0));
134 # now has a side affect of rotating $a by $shift
137 local($a,$b,$tt,$shift,$mask,$last)=@_;
139 &rotl( $a, $shift ) if ($shift != 0);
158 local($l,$r,$tt,$lr)=@_;
160 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
161 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
162 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
163 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
164 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
169 { &rotr($tt, 3-$lr); }
170 else { &rotl($tt, $lr-3); }
175 { &rotr($r, 2-$lr); }
176 else { &rotl($r, $lr-2); }
182 local($l,$r,$tt,$lr)=@_;
187 { &rotl($r, 2-$lr); }
188 else { &rotr($r, $lr-2); }
193 { &rotl($l, 3-$lr); }
194 else { &rotr($l, $lr-3); }
197 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
198 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
199 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
200 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
201 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);