remove gcc34
[dragonfly.git] / crypto / heimdal-0.6.3 / lib / des / asm / des586.pl
blobc2bee84b70c9c569b6d339676774273c822c7f3d
1 #!/usr/local/bin/perl
3 $prog="des586.pl";
5 # base code is in microsft
6 # op dest, source
7 # format.
10 # WILL NOT WORK ANYMORE WITH desboth.pl
11 require "desboth.pl";
13 if ( ($ARGV[0] eq "elf"))
14 { require "x86unix.pl"; }
15 elsif ( ($ARGV[0] eq "a.out"))
16 { $aout=1; require "x86unix.pl"; }
17 elsif ( ($ARGV[0] eq "sol"))
18 { $sol=1; require "x86unix.pl"; }
19 elsif ( ($ARGV[0] eq "cpp"))
20 { $cpp=1; require "x86unix.pl"; }
21 elsif ( ($ARGV[0] eq "win32"))
22 { require "x86ms.pl"; }
23 else
25 print STDERR <<"EOF";
26 Pick one target type from
27 elf - linux, FreeBSD etc
28 a.out - old linux
29 sol - x86 solaris
30 cpp - format so x86unix.cpp can be used
31 win32 - Windows 95/Windows NT
32 EOF
33 exit(1);
36 &comment("Don't even think of reading this code");
37 &comment("It was automatically generated by $prog");
38 &comment("Which is a perl program used to generate the x86 assember for");
39 &comment("any of elf, a.out, Win32, or Solaris");
40 &comment("It can be found in SSLeay 0.6.5+ or in libdes 3.26+");
41 &comment("eric <eay\@mincom.oz.au>");
42 &comment("");
44 &file("dx86xxxx");
46 $L="edi";
47 $R="esi";
49 &des_encrypt("des_encrypt",1);
50 &des_encrypt("des_encrypt2",0);
52 &des_encrypt3("des_encrypt3",1);
53 &des_encrypt3("des_decrypt3",0);
55 &file_end();
57 sub des_encrypt
59 local($name,$do_ip)=@_;
61 &function_begin($name,3);
63 &comment("");
64 &comment("Load the 2 words");
65 &mov("eax",&wparam(0));
66 &mov($R,&DWP(0,"eax","",0));
67 &mov($L,&DWP(4,"eax","",0));
69 if ($do_ip)
71 &comment("");
72 &comment("IP");
73 &IP($R,$L,"eax");
76 &comment("");
77 &comment("fixup rotate");
78 &rotl($R,3);
79 &rotl($L,3);
81 &comment("");
82 &comment("load counter, key_schedule and enc flag");
84 # encrypting part
86 $ks="ebp";
87 &xor( "ebx", "ebx" );
88 &mov("eax",&wparam(2)); # get encrypt flag
89 &xor( "ecx", "ecx" );
90 &cmp("eax","0");
91 &mov( $ks, &wparam(1) );
92 &je(&label("start_decrypt"));
94 for ($i=0; $i<16; $i+=2)
96 &comment("");
97 &comment("Round $i");
98 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
100 &comment("");
101 &comment("Round ".sprintf("%d",$i+1));
102 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
104 &jmp(&label("end"));
106 &set_label("start_decrypt");
108 for ($i=15; $i>0; $i-=2)
110 &comment("");
111 &comment("Round $i");
112 &D_ENCRYPT(15-$i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
113 &comment("");
114 &comment("Round ".sprintf("%d",$i-1));
115 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
118 &set_label("end");
120 &comment("");
121 &comment("Fixup");
122 &rotr($L,3); # r
123 &rotr($R,3); # l
125 if ($do_ip)
127 &comment("");
128 &comment("FP");
129 &FP($R,$L,"eax");
132 &mov("eax",&wparam(0));
133 &mov(&DWP(0,"eax","",0),$L);
134 &mov(&DWP(4,"eax","",0),$R);
136 &function_end($name);
139 sub D_ENCRYPT
141 local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_;
143 &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0));
144 &mov( $u, &DWP(&n2a($S*4),$ks,"",0));
145 &xor( $t, $R);
146 &xor( $u, $R);
147 &rotr( $t, 4 );
148 &and( $u, "0xfcfcfcfc" );
149 &and( $t, "0xfcfcfcfc" );
150 &movb( &LB($tmp1), &LB($u) );
151 &movb( &LB($tmp2), &HB($u) );
152 &xor( $L, &DWP(" $desSP",$tmp1,"",0));
153 &shr( $u, 16);
154 &xor( $L, &DWP("0x200+$desSP",$tmp2,"",0));
155 &movb( &LB($tmp1), &LB($u) );
156 &movb( &LB($tmp2), &HB($u) );
157 &xor( $L, &DWP("0x400+$desSP",$tmp1,"",0));
158 &mov( $u, &DWP("0x600+$desSP",$tmp2,"",0));
160 &movb( &LB($tmp1), &LB($t) );
161 &movb( &LB($tmp2), &HB($t) );
162 &xor( $L, &DWP("0x100+$desSP",$tmp1,"",0));
163 &shr( $t, 16);
164 &xor( $u, &DWP("0x300+$desSP",$tmp2,"",0));
165 &movb( &LB($tmp1), &LB($t) );
166 &movb( &LB($tmp2), &HB($t) );
167 &xor( $L, &DWP("0x500+$desSP",$tmp1,"",0));
168 &xor( $u, &DWP("0x700+$desSP",$tmp2,"",0));
169 &xor( $L, $u);
172 sub PERM_OP
174 local($a,$b,$tt,$shift,$mask)=@_;
176 &mov( $tt, $a );
177 &shr( $tt, $shift );
178 &xor( $tt, $b );
179 &and( $tt, $mask );
180 &xor( $b, $tt );
181 &shl( $tt, $shift );
182 &xor( $a, $tt );
185 sub IP
187 local($l,$r,$tt)=@_;
189 &PERM_OP($r,$l,$tt, 4,"0x0f0f0f0f");
190 &PERM_OP($l,$r,$tt,16,"0x0000ffff");
191 &PERM_OP($r,$l,$tt, 2,"0x33333333");
192 &PERM_OP($l,$r,$tt, 8,"0x00ff00ff");
193 &PERM_OP($r,$l,$tt, 1,"0x55555555");
196 sub FP
198 local($l,$r,$tt)=@_;
200 &PERM_OP($l,$r,$tt, 1,"0x55555555");
201 &PERM_OP($r,$l,$tt, 8,"0x00ff00ff");
202 &PERM_OP($l,$r,$tt, 2,"0x33333333");
203 &PERM_OP($r,$l,$tt,16,"0x0000ffff");
204 &PERM_OP($l,$r,$tt, 4,"0x0f0f0f0f");
207 sub n2a
209 sprintf("%d",$_[0]);