3 # The inner loop instruction sequence and the IP/FP modifications are from
4 # Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
7 push(@INC,"perlasm","../../perlasm");
12 # base code is in microsft
17 &asm_init($ARGV[0],"des-586.pl");
22 &external_label("DES_SPtrans");
23 &DES_encrypt("DES_encrypt1",1);
24 &DES_encrypt("DES_encrypt2",0);
25 &DES_encrypt3("DES_encrypt3",1);
26 &DES_encrypt3("DES_decrypt3",0);
27 &cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
28 &cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
34 local($name,$do_ip)=@_;
36 &function_begin_B($name,"EXTRN _DES_SPtrans:DWORD");
42 &comment("Load the 2 words");
53 &mov("eax",&DWP(0,$R,"",0));
54 &mov("ebx",&wparam(2)); # get encrypt flag
55 &mov($L,&DWP(4,$R,"",0));
58 &IP_new("eax",$L,$R,3);
62 &mov("eax",&wparam(0));
68 &mov($R,&DWP(0,"eax","",0));
69 &mov("ebx",&wparam(2)); # get encrypt flag
71 &mov($L,&DWP(4,"eax","",0));
75 &mov( $ks, &wparam(1) );
77 &je(&label("start_decrypt"));
79 for ($i=0; $i<16; $i+=2)
83 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx");
86 &comment("Round ".sprintf("%d",$i+1));
87 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx");
91 &set_label("start_decrypt");
93 for ($i=15; $i>0; $i-=2)
97 &D_ENCRYPT(15-$i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx");
99 &comment("Round ".sprintf("%d",$i-1));
100 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx");
109 &mov("edx",&wparam(0));
110 &FP_new($L,$R,"eax",3);
112 &mov(&DWP(0,"edx","",0),"eax");
113 &mov(&DWP(4,"edx","",0),$R);
120 &mov("eax",&wparam(0));
122 &mov(&DWP(0,"eax","",0),$L);
123 &mov(&DWP(4,"eax","",0),$R);
132 &function_end_B($name);
137 local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_;
139 &mov( $u, &DWP(&n2a($S*4),$ks,"",0));
141 &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0));
144 &and( $u, "0xfcfcfcfc" );
145 &and( $t, "0xcfcfcfcf" );
146 &movb( &LB($tmp1), &LB($u) );
147 &movb( &LB($tmp2), &HB($u) );
149 &mov( $ks, &DWP(" $desSP",$tmp1,"",0));
150 &movb( &LB($tmp1), &LB($t) );
152 &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0));
153 &xor( $L, $ks); ######
154 &movb( &LB($tmp2), &HB($t) );
156 &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0));
157 &xor( $L, $ks); ######
158 &movb( &LB($tmp1), &HB($u) );
160 &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0));
162 &mov( $ks, &wparam(1) );
163 &movb( &LB($tmp2), &HB($t) );
166 &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0));
168 &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0));
170 &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0));
172 &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0));
181 # now has a side affect of rotating $a by $shift
184 local($a,$b,$tt,$shift,$mask,$last)=@_;
186 &rotl( $a, $shift ) if ($shift != 0);
190 # This can never succeed, and besides it is difficult to see what the
191 # idea was - Ben 13 Feb 99
207 local($l,$r,$tt,$lr)=@_;
209 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
210 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
211 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
212 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
213 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
218 { &rotr($tt, 3-$lr); }
219 else { &rotl($tt, $lr-3); }
224 { &rotr($r, 2-$lr); }
225 else { &rotl($r, $lr-2); }
231 local($l,$r,$tt,$lr)=@_;
236 { &rotl($r, 2-$lr); }
237 else { &rotr($r, $lr-2); }
242 { &rotl($l, 3-$lr); }
243 else { &rotr($l, $lr-3); }
246 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
247 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
248 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
249 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
250 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);