summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des/asm/des-586.pl
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/des/asm/des-586.pl')
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl255
1 files changed, 0 insertions, 255 deletions
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl
deleted file mode 100644
index 60d577cc8d..0000000000
--- a/src/lib/libcrypto/des/asm/des-586.pl
+++ /dev/null
@@ -1,255 +0,0 @@
1#!/usr/local/bin/perl
2#
3# The inner loop instruction sequence and the IP/FP modifications are from
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
5#
6
7push(@INC,"perlasm","../../perlasm");
8require "x86asm.pl";
9require "cbc.pl";
10require "desboth.pl";
11
12# base code is in microsft
13# op dest, source
14# format.
15#
16
17&asm_init($ARGV[0],"des-586.pl");
18
19$L="edi";
20$R="esi";
21
22&external_label("DES_SPtrans");
23&DES_encrypt("DES_encrypt1",1);
24&DES_encrypt("DES_encrypt2",0);
25
26if (!$main'openbsd)
27 {
28 &DES_encrypt3("DES_encrypt3",1);
29 &DES_encrypt3("DES_decrypt3",0);
30 &cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
31 &cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
32 }
33
34&asm_finish();
35
36sub DES_encrypt
37 {
38 local($name,$do_ip)=@_;
39
40 &function_begin_B($name,"EXTRN _DES_SPtrans:DWORD");
41
42 &push("esi");
43 &push("edi");
44
45 &comment("");
46 &comment("Load the 2 words");
47 $trans="ebp";
48
49 if ($do_ip)
50 {
51 &mov($R,&wparam(0));
52 &xor( "ecx", "ecx" );
53
54 &push("ebx");
55 &push("ebp");
56
57 &mov("eax",&DWP(0,$R,"",0));
58 &mov("ebx",&wparam(2)); # get encrypt flag
59 &mov($L,&DWP(4,$R,"",0));
60 &comment("");
61 &comment("IP");
62 &IP_new("eax",$L,$R,3);
63 }
64 else
65 {
66 &mov("eax",&wparam(0));
67 &xor( "ecx", "ecx" );
68
69 &push("ebx");
70 &push("ebp");
71
72 &mov($R,&DWP(0,"eax","",0));
73 &mov("ebx",&wparam(2)); # get encrypt flag
74 &rotl($R,3);
75 &mov($L,&DWP(4,"eax","",0));
76 &rotl($L,3);
77 }
78
79 # PIC-ification:-)
80 &picmeup($trans,"DES_SPtrans");
81 #if ($cpp) { &picmeup($trans,"DES_SPtrans"); }
82 #else { &lea($trans,&DWP("DES_SPtrans")); }
83
84 &mov( "ecx", &wparam(1) );
85 &cmp("ebx","0");
86 &je(&label("start_decrypt"));
87
88 for ($i=0; $i<16; $i+=2)
89 {
90 &comment("");
91 &comment("Round $i");
92 &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
93
94 &comment("");
95 &comment("Round ".sprintf("%d",$i+1));
96 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx");
97 }
98 &jmp(&label("end"));
99
100 &set_label("start_decrypt");
101
102 for ($i=15; $i>0; $i-=2)
103 {
104 &comment("");
105 &comment("Round $i");
106 &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx");
107 &comment("");
108 &comment("Round ".sprintf("%d",$i-1));
109 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx");
110 }
111
112 &set_label("end");
113
114 if ($do_ip)
115 {
116 &comment("");
117 &comment("FP");
118 &mov("edx",&wparam(0));
119 &FP_new($L,$R,"eax",3);
120
121 &mov(&DWP(0,"edx","",0),"eax");
122 &mov(&DWP(4,"edx","",0),$R);
123 }
124 else
125 {
126 &comment("");
127 &comment("Fixup");
128 &rotr($L,3); # r
129 &mov("eax",&wparam(0));
130 &rotr($R,3); # l
131 &mov(&DWP(0,"eax","",0),$L);
132 &mov(&DWP(4,"eax","",0),$R);
133 }
134
135 &pop("ebp");
136 &pop("ebx");
137 &pop("edi");
138 &pop("esi");
139 &ret();
140
141 &function_end_B($name);
142 }
143
144sub D_ENCRYPT
145 {
146 local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_;
147
148 &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0));
149 &xor( $tmp1, $tmp1);
150 &mov( $t, &DWP(&n2a(($S+1)*4),$tmp2,"",0));
151 &xor( $u, $R);
152 &xor( $tmp2, $tmp2);
153 &xor( $t, $R);
154 &and( $u, "0xfcfcfcfc" );
155 &and( $t, "0xcfcfcfcf" );
156 &movb( &LB($tmp1), &LB($u) );
157 &movb( &LB($tmp2), &HB($u) );
158 &rotr( $t, 4 );
159 &xor( $L, &DWP(" ",$trans,$tmp1,0));
160 &movb( &LB($tmp1), &LB($t) );
161 &xor( $L, &DWP("0x200",$trans,$tmp2,0));
162 &movb( &LB($tmp2), &HB($t) );
163 &shr( $u, 16);
164 &xor( $L, &DWP("0x100",$trans,$tmp1,0));
165 &movb( &LB($tmp1), &HB($u) );
166 &shr( $t, 16);
167 &xor( $L, &DWP("0x300",$trans,$tmp2,0));
168 &movb( &LB($tmp2), &HB($t) );
169 &and( $u, "0xff" );
170 &and( $t, "0xff" );
171 &xor( $L, &DWP("0x600",$trans,$tmp1,0));
172 &xor( $L, &DWP("0x700",$trans,$tmp2,0));
173 &mov( $tmp2, &wparam(1) );
174 &xor( $L, &DWP("0x400",$trans,$u,0));
175 &xor( $L, &DWP("0x500",$trans,$t,0));
176 }
177
178sub n2a
179 {
180 sprintf("%d",$_[0]);
181 }
182
183# now has a side affect of rotating $a by $shift
184sub R_PERM_OP
185 {
186 local($a,$b,$tt,$shift,$mask,$last)=@_;
187
188 &rotl( $a, $shift ) if ($shift != 0);
189 &mov( $tt, $a );
190 &xor( $a, $b );
191 &and( $a, $mask );
192 # This can never succeed, and besides it is difficult to see what the
193 # idea was - Ben 13 Feb 99
194 if (!$last eq $b)
195 {
196 &xor( $b, $a );
197 &xor( $tt, $a );
198 }
199 else
200 {
201 &xor( $tt, $a );
202 &xor( $b, $a );
203 }
204 &comment("");
205 }
206
207sub IP_new
208 {
209 local($l,$r,$tt,$lr)=@_;
210
211 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
212 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
213 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
214 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
215 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
216
217 if ($lr != 3)
218 {
219 if (($lr-3) < 0)
220 { &rotr($tt, 3-$lr); }
221 else { &rotl($tt, $lr-3); }
222 }
223 if ($lr != 2)
224 {
225 if (($lr-2) < 0)
226 { &rotr($r, 2-$lr); }
227 else { &rotl($r, $lr-2); }
228 }
229 }
230
231sub FP_new
232 {
233 local($l,$r,$tt,$lr)=@_;
234
235 if ($lr != 2)
236 {
237 if (($lr-2) < 0)
238 { &rotl($r, 2-$lr); }
239 else { &rotr($r, $lr-2); }
240 }
241 if ($lr != 3)
242 {
243 if (($lr-3) < 0)
244 { &rotl($l, 3-$lr); }
245 else { &rotr($l, $lr-3); }
246 }
247
248 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
249 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
250 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
251 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
252 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
253 &rotr($tt , 4);
254 }
255