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 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
10 push(@INC,"${dir}","${dir}../../perlasm");
13 &asm_init($ARGV[0],"crypt586.pl");
18 &external_label("DES_SPtrans");
19 &fcrypt_body("fcrypt_body");
24 local($name,$do_ip)=@_;
26 &function_begin($name);
29 &comment("Load the 2 words");
36 &picmeup("edx","DES_SPtrans");
37 #if ($cpp) { &picmeup("edx","DES_SPtrans"); }
38 #else { &lea("edx",&DWP("DES_SPtrans")); }
39 &push("edx"); # becomes &swtmp(1)
41 &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT
43 &push(&DWC(25)); # add a variable
46 for ($i=0; $i<16; $i+=2)
50 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
53 &comment("Round ".sprintf("%d",$i+1));
54 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
56 &mov("ebx", &swtmp(0));
61 &mov(&swtmp(0), "ebx");
62 &jnz(&label("start"));
66 &mov("edx",&wparam(0));
68 &FP_new($R,$L,"eax",3);
69 &mov(&DWP(0,"edx","",0),"eax");
70 &mov(&DWP(4,"edx","",0),$L);
72 &add("esp",8); # remove variables
79 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
81 &mov( $u, &wparam(2)); # 2
84 &mov( $tmp2, &wparam(3)); # 2
96 &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2
98 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2
103 &and( $u, "0xfcfcfcfc" ); # 2
104 &xor( $tmp1, $tmp1); # 1
105 &and( $t, "0xcfcfcfcf" ); # 2
107 &movb( &LB($tmp1), &LB($u) );
108 &movb( &LB($tmp2), &HB($u) );
110 &mov( $trans, &swtmp(1));
111 &xor( $L, &DWP(" ",$trans,$tmp1,0));
112 &movb( &LB($tmp1), &LB($t) );
113 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
114 &movb( &LB($tmp2), &HB($t) );
116 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
117 &movb( &LB($tmp1), &HB($u) );
119 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
120 &movb( &LB($tmp2), &HB($t) );
123 &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0));
125 &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0));
127 &mov( $tmp1, &DWP("0x400",$trans,$u,0));
129 &mov( $tmp1, &DWP("0x500",$trans,$t,0));
131 &mov( $trans, &wparam(1));
139 # now has a side affect of rotating $a by $shift
142 local($a,$b,$tt,$shift,$mask,$last)=@_;
144 &rotl( $a, $shift ) if ($shift != 0);
163 local($l,$r,$tt,$lr)=@_;
165 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
166 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
167 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
168 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
169 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
174 { &rotr($tt, 3-$lr); }
175 else { &rotl($tt, $lr-3); }
180 { &rotr($r, 2-$lr); }
181 else { &rotl($r, $lr-2); }
187 local($l,$r,$tt,$lr)=@_;
192 { &rotl($r, 2-$lr); }
193 else { &rotr($r, $lr-2); }
198 { &rotl($l, 3-$lr); }
199 else { &rotr($l, $lr-3); }
202 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
203 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
204 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
205 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
206 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);