2 # Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
9 # The inner loop instruction sequence and the IP/FP modifications are from
10 # Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
12 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
13 push(@INC,"${dir}","${dir}../../perlasm");
17 open STDOUT,">$output";
19 &asm_init($ARGV[0],"crypt586.pl");
24 &external_label("DES_SPtrans");
25 &fcrypt_body("fcrypt_body");
32 local($name,$do_ip)=@_;
34 &function_begin($name);
37 &comment("Load the 2 words");
44 &picmeup("edx","DES_SPtrans");
45 #if ($cpp) { &picmeup("edx","DES_SPtrans"); }
46 #else { &lea("edx",&DWP("DES_SPtrans")); }
47 &push("edx"); # becomes &swtmp(1)
49 &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT
51 &push(&DWC(25)); # add a variable
54 for ($i=0; $i<16; $i+=2)
58 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
61 &comment("Round ".sprintf("%d",$i+1));
62 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
64 &mov("ebx", &swtmp(0));
69 &mov(&swtmp(0), "ebx");
70 &jnz(&label("start"));
74 &mov("edx",&wparam(0));
76 &FP_new($R,$L,"eax",3);
77 &mov(&DWP(0,"edx","",0),"eax");
78 &mov(&DWP(4,"edx","",0),$L);
80 &add("esp",8); # remove variables
87 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
89 &mov( $u, &wparam(2)); # 2
92 &mov( $tmp2, &wparam(3)); # 2
101 &shl( $tmp2, 16); # 1
102 &xor( $u, $tmp1); # 2
103 &xor( $t, $tmp2); # 2
104 &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2
106 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2
111 &and( $u, "0xfcfcfcfc" ); # 2
112 &xor( $tmp1, $tmp1); # 1
113 &and( $t, "0xcfcfcfcf" ); # 2
115 &movb( &LB($tmp1), &LB($u) );
116 &movb( &LB($tmp2), &HB($u) );
118 &mov( $trans, &swtmp(1));
119 &xor( $L, &DWP(" ",$trans,$tmp1,0));
120 &movb( &LB($tmp1), &LB($t) );
121 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
122 &movb( &LB($tmp2), &HB($t) );
124 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
125 &movb( &LB($tmp1), &HB($u) );
127 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
128 &movb( &LB($tmp2), &HB($t) );
131 &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0));
133 &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0));
135 &mov( $tmp1, &DWP("0x400",$trans,$u,0));
137 &mov( $tmp1, &DWP("0x500",$trans,$t,0));
139 &mov( $trans, &wparam(1));
147 # now has a side affect of rotating $a by $shift
150 local($a,$b,$tt,$shift,$mask,$last)=@_;
152 &rotl( $a, $shift ) if ($shift != 0);
171 local($l,$r,$tt,$lr)=@_;
173 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
174 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
175 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
176 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
177 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
182 { &rotr($tt, 3-$lr); }
183 else { &rotl($tt, $lr-3); }
188 { &rotr($r, 2-$lr); }
189 else { &rotl($r, $lr-2); }
195 local($l,$r,$tt,$lr)=@_;
200 { &rotl($r, 2-$lr); }
201 else { &rotr($r, $lr-2); }
206 { &rotl($l, 3-$lr); }
207 else { &rotr($l, $lr-3); }
210 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
211 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
212 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
213 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
214 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);