2 # Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (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
12 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
13 push(@INC,"${dir}","${dir}../../perlasm");
16 $output=pop and open STDOUT,">$output";
23 &external_label("DES_SPtrans");
24 &fcrypt_body("fcrypt_body");
27 close STDOUT or die "error closing STDOUT: $!";
31 local($name,$do_ip)=@_;
33 &function_begin($name);
36 &comment("Load the 2 words");
43 &picmeup("edx","DES_SPtrans");
44 #if ($cpp) { &picmeup("edx","DES_SPtrans"); }
45 #else { &lea("edx",&DWP("DES_SPtrans")); }
46 &push("edx"); # becomes &swtmp(1)
48 &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT
50 &push(&DWC(25)); # add a variable
53 for ($i=0; $i<16; $i+=2)
57 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
60 &comment("Round ".sprintf("%d",$i+1));
61 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
63 &mov("ebx", &swtmp(0));
68 &mov(&swtmp(0), "ebx");
69 &jnz(&label("start"));
73 &mov("edx",&wparam(0));
75 &FP_new($R,$L,"eax",3);
76 &mov(&DWP(0,"edx","",0),"eax");
77 &mov(&DWP(4,"edx","",0),$L);
79 &add("esp",8); # remove variables
86 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
88 &mov( $u, &wparam(2)); # 2
91 &mov( $tmp2, &wparam(3)); # 2
100 &shl( $tmp2, 16); # 1
101 &xor( $u, $tmp1); # 2
102 &xor( $t, $tmp2); # 2
103 &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2
105 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2
110 &and( $u, "0xfcfcfcfc" ); # 2
111 &xor( $tmp1, $tmp1); # 1
112 &and( $t, "0xcfcfcfcf" ); # 2
114 &movb( &LB($tmp1), &LB($u) );
115 &movb( &LB($tmp2), &HB($u) );
117 &mov( $trans, &swtmp(1));
118 &xor( $L, &DWP(" ",$trans,$tmp1,0));
119 &movb( &LB($tmp1), &LB($t) );
120 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
121 &movb( &LB($tmp2), &HB($t) );
123 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
124 &movb( &LB($tmp1), &HB($u) );
126 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
127 &movb( &LB($tmp2), &HB($t) );
130 &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0));
132 &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0));
134 &mov( $tmp1, &DWP("0x400",$trans,$u,0));
136 &mov( $tmp1, &DWP("0x500",$trans,$t,0));
138 &mov( $trans, &wparam(1));
146 # now has a side affect of rotating $a by $shift
149 local($a,$b,$tt,$shift,$mask,$last)=@_;
151 &rotl( $a, $shift ) if ($shift != 0);
170 local($l,$r,$tt,$lr)=@_;
172 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
173 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
174 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
175 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
176 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
181 { &rotr($tt, 3-$lr); }
182 else { &rotl($tt, $lr-3); }
187 { &rotr($r, 2-$lr); }
188 else { &rotl($r, $lr-2); }
194 local($l,$r,$tt,$lr)=@_;
199 { &rotl($r, 2-$lr); }
200 else { &rotr($r, $lr-2); }
205 { &rotl($l, 3-$lr); }
206 else { &rotr($l, $lr-3); }
209 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
210 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
211 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
212 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
213 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);