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");
14 open STDOUT,">$output";
16 &asm_init($ARGV[0],"crypt586.pl");
21 &external_label("DES_SPtrans");
22 &fcrypt_body("fcrypt_body");
29 local($name,$do_ip)=@_;
31 &function_begin($name);
34 &comment("Load the 2 words");
41 &picmeup("edx","DES_SPtrans");
42 #if ($cpp) { &picmeup("edx","DES_SPtrans"); }
43 #else { &lea("edx",&DWP("DES_SPtrans")); }
44 &push("edx"); # becomes &swtmp(1)
46 &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT
48 &push(&DWC(25)); # add a variable
51 for ($i=0; $i<16; $i+=2)
55 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
58 &comment("Round ".sprintf("%d",$i+1));
59 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
61 &mov("ebx", &swtmp(0));
66 &mov(&swtmp(0), "ebx");
67 &jnz(&label("start"));
71 &mov("edx",&wparam(0));
73 &FP_new($R,$L,"eax",3);
74 &mov(&DWP(0,"edx","",0),"eax");
75 &mov(&DWP(4,"edx","",0),$L);
77 &add("esp",8); # remove variables
84 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
86 &mov( $u, &wparam(2)); # 2
89 &mov( $tmp2, &wparam(3)); # 2
100 &xor( $t, $tmp2); # 2
101 &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2
103 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2
108 &and( $u, "0xfcfcfcfc" ); # 2
109 &xor( $tmp1, $tmp1); # 1
110 &and( $t, "0xcfcfcfcf" ); # 2
112 &movb( &LB($tmp1), &LB($u) );
113 &movb( &LB($tmp2), &HB($u) );
115 &mov( $trans, &swtmp(1));
116 &xor( $L, &DWP(" ",$trans,$tmp1,0));
117 &movb( &LB($tmp1), &LB($t) );
118 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
119 &movb( &LB($tmp2), &HB($t) );
121 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
122 &movb( &LB($tmp1), &HB($u) );
124 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
125 &movb( &LB($tmp2), &HB($t) );
128 &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0));
130 &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0));
132 &mov( $tmp1, &DWP("0x400",$trans,$u,0));
134 &mov( $tmp1, &DWP("0x500",$trans,$t,0));
136 &mov( $trans, &wparam(1));
144 # now has a side affect of rotating $a by $shift
147 local($a,$b,$tt,$shift,$mask,$last)=@_;
149 &rotl( $a, $shift ) if ($shift != 0);
168 local($l,$r,$tt,$lr)=@_;
170 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
171 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
172 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
173 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
174 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
179 { &rotr($tt, 3-$lr); }
180 else { &rotl($tt, $lr-3); }
185 { &rotr($r, 2-$lr); }
186 else { &rotl($r, $lr-2); }
192 local($l,$r,$tt,$lr)=@_;
197 { &rotl($r, 2-$lr); }
198 else { &rotr($r, $lr-2); }
203 { &rotl($l, 3-$lr); }
204 else { &rotr($l, $lr-3); }
207 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
208 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
209 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
210 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
211 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);