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 if ($cpp) { &picmeup("edx","DES_SPtrans"); }
36 else { &lea("edx",&DWP("DES_SPtrans")); }
37 &push("edx"); # becomes &swtmp(1)
39 &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT
41 &push(&DWC(25)); # add a variable
44 for ($i=0; $i<16; $i+=2)
48 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
51 &comment("Round ".sprintf("%d",$i+1));
52 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
54 &mov("ebx", &swtmp(0));
59 &mov(&swtmp(0), "ebx");
60 &jnz(&label("start"));
64 &mov("edx",&wparam(0));
66 &FP_new($R,$L,"eax",3);
67 &mov(&DWP(0,"edx","",0),"eax");
68 &mov(&DWP(4,"edx","",0),$L);
70 &add("esp",8); # remove variables
77 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
79 &mov( $u, &wparam(2)); # 2
82 &mov( $tmp2, &wparam(3)); # 2
94 &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2
96 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2
101 &and( $u, "0xfcfcfcfc" ); # 2
102 &xor( $tmp1, $tmp1); # 1
103 &and( $t, "0xcfcfcfcf" ); # 2
105 &movb( &LB($tmp1), &LB($u) );
106 &movb( &LB($tmp2), &HB($u) );
108 &mov( $trans, &swtmp(1));
109 &xor( $L, &DWP(" ",$trans,$tmp1,0));
110 &movb( &LB($tmp1), &LB($t) );
111 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
112 &movb( &LB($tmp2), &HB($t) );
114 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
115 &movb( &LB($tmp1), &HB($u) );
117 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
118 &movb( &LB($tmp2), &HB($t) );
121 &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0));
123 &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0));
125 &mov( $tmp1, &DWP("0x400",$trans,$u,0));
127 &mov( $tmp1, &DWP("0x500",$trans,$t,0));
129 &mov( $trans, &wparam(1));
137 # now has a side affect of rotating $a by $shift
140 local($a,$b,$tt,$shift,$mask,$last)=@_;
142 &rotl( $a, $shift ) if ($shift != 0);
161 local($l,$r,$tt,$lr)=@_;
163 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
164 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
165 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
166 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
167 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
172 { &rotr($tt, 3-$lr); }
173 else { &rotl($tt, $lr-3); }
178 { &rotr($r, 2-$lr); }
179 else { &rotl($r, $lr-2); }
185 local($l,$r,$tt,$lr)=@_;
190 { &rotl($r, 2-$lr); }
191 else { &rotr($r, $lr-2); }
196 { &rotl($l, 3-$lr); }
197 else { &rotr($l, $lr-3); }
200 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
201 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
202 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
203 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
204 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);