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