summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/md5/asm
diff options
context:
space:
mode:
authorryker <>1998-10-05 20:13:14 +0000
committerryker <>1998-10-05 20:13:14 +0000
commitaeeae06a79815dc190061534d47236cec09f9e32 (patch)
tree851692b9c2f9c04f077666855641900f19fdb217 /src/lib/libcrypto/md5/asm
parenta4f79641824cbf9f60ca9d1168d1fcc46717a82a (diff)
downloadopenbsd-aeeae06a79815dc190061534d47236cec09f9e32.tar.gz
openbsd-aeeae06a79815dc190061534d47236cec09f9e32.tar.bz2
openbsd-aeeae06a79815dc190061534d47236cec09f9e32.zip
Import of SSLeay-0.9.0b with RSA and IDEA stubbed + OpenBSD build
functionality for shared libs. Note that routines such as sslv2_init and friends that use RSA will not work due to lack of RSA in this library. Needs documentation and help from ports for easy upgrade to full functionality where legally possible.
Diffstat (limited to 'src/lib/libcrypto/md5/asm')
-rw-r--r--src/lib/libcrypto/md5/asm/md5-586.pl304
1 files changed, 304 insertions, 0 deletions
diff --git a/src/lib/libcrypto/md5/asm/md5-586.pl b/src/lib/libcrypto/md5/asm/md5-586.pl
new file mode 100644
index 0000000000..2c7fb7dd98
--- /dev/null
+++ b/src/lib/libcrypto/md5/asm/md5-586.pl
@@ -0,0 +1,304 @@
1#!/usr/bin/perl
2
3# Normal is the
4# md5_block_x86(MD5_CTX *c, ULONG *X);
5# version, non-normal is the
6# md5_block_x86(MD5_CTX *c, ULONG *X,int blocks);
7
8$normal=0;
9
10push(@INC,"perlasm","../../perlasm");
11require "x86asm.pl";
12
13&asm_init($ARGV[0],$0);
14
15$A="eax";
16$B="ebx";
17$C="ecx";
18$D="edx";
19$tmp1="edi";
20$tmp2="ebp";
21$X="esi";
22
23# What we need to load into $tmp for the next round
24%Ltmp1=("R0",&Np($C), "R1",&Np($C), "R2",&Np($C), "R3",&Np($D));
25@xo=(
26 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # R0
27 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, # R1
28 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, # R2
29 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, # R3
30 );
31
32&md5_block("md5_block_x86");
33&asm_finish();
34
35sub Np
36 {
37 local($p)=@_;
38 local(%n)=($A,$D,$B,$A,$C,$B,$D,$C);
39 return($n{$p});
40 }
41
42sub R0
43 {
44 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
45
46 &mov($tmp1,$C) if $pos < 0;
47 &mov($tmp2,&DWP($xo[$ki]*4,$K,"",0)) if $pos < 0; # very first one
48
49 # body proper
50
51 &comment("R0 $ki");
52 &xor($tmp1,$d); # F function - part 2
53
54 &and($tmp1,$b); # F function - part 3
55 &lea($a,&DWP($t,$a,$tmp2,1));
56
57 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
58 &xor($tmp1,$d); # F function - part 4
59
60 &add($a,$tmp1);
61 &mov($tmp1,&Np($c)) if $pos < 1; # next tmp1 for R0
62 &mov($tmp1,&Np($c)) if $pos == 1; # next tmp1 for R1
63
64 &rotl($a,$s);
65 &add($a,$b);
66
67 }
68
69sub R1
70 {
71 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
72
73 &comment("R1 $ki");
74
75 &lea($a,&DWP($t,$a,$tmp2,1));
76
77 &xor($tmp1,$b); # G function - part 2
78 &and($tmp1,$d); # G function - part 3
79
80 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
81 &xor($tmp1,$c); # G function - part 4
82
83 &add($a,$tmp1);
84 &mov($tmp1,&Np($c)) if $pos < 1; # G function - part 1
85 &mov($tmp1,&Np($c)) if $pos == 1; # G function - part 1
86
87 &rotl($a,$s);
88
89 &add($a,$b);
90 }
91
92sub R2
93 {
94 local($n,$pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
95 # This one is different, only 3 logical operations
96
97if (($n & 1) == 0)
98 {
99 &comment("R2 $ki");
100 # make sure to do 'D' first, not 'B', else we clash with
101 # the last add from the previous round.
102
103 &xor($tmp1,$d); # H function - part 2
104
105 &xor($tmp1,$b); # H function - part 3
106 &lea($a,&DWP($t,$a,$tmp2,1));
107
108 &add($a,$tmp1);
109 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0));
110
111 &rotl($a,$s);
112
113 &mov($tmp1,&Np($c));
114 }
115else
116 {
117 &comment("R2 $ki");
118 # make sure to do 'D' first, not 'B', else we clash with
119 # the last add from the previous round.
120
121 &lea($a,&DWP($t,$a,$tmp2,1));
122
123 &add($b,$c); # MOVED FORWARD
124 &xor($tmp1,$d); # H function - part 2
125
126 &xor($tmp1,$b); # H function - part 3
127 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
128
129 &add($a,$tmp1);
130 &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1
131 &mov($tmp1,-1) if $pos == 1; # I function - part 1
132
133 &rotl($a,$s);
134
135 &add($a,$b);
136 }
137 }
138
139sub R3
140 {
141 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
142
143 &comment("R3 $ki");
144
145 # &not($tmp1)
146 &xor($tmp1,$d) if $pos < 0; # I function - part 2
147
148 &or($tmp1,$b); # I function - part 3
149 &lea($a,&DWP($t,$a,$tmp2,1));
150
151 &xor($tmp1,$c); # I function - part 4
152 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value
153 &mov($tmp2,&wparam(0)) if $pos == 2;
154
155 &add($a,$tmp1);
156 &mov($tmp1,-1) if $pos < 1; # H function - part 1
157 &add($K,64) if $pos >=1 && !$normal;
158
159 &rotl($a,$s);
160
161 &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time
162 &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0;
163 &add($a,$b);
164 }
165
166
167sub md5_block
168 {
169 local($name)=@_;
170
171 &function_begin_B($name,"",3);
172
173 # parameter 1 is the MD5_CTX structure.
174 # A 0
175 # B 4
176 # C 8
177 # D 12
178
179 &push("esi");
180 &push("edi");
181 &mov($tmp1, &wparam(0)); # edi
182 &mov($X, &wparam(1)); # esi
183 &mov($C, &wparam(2));
184 &push("ebp");
185 &push("ebx");
186 &add($C, $X); # offset we end at
187 &sub($C, 64);
188 &mov($A, &DWP( 0,$tmp1,"",0));
189 &push($C); # Put on the TOS
190 &mov($B, &DWP( 4,$tmp1,"",0));
191 &mov($C, &DWP( 8,$tmp1,"",0));
192 &mov($D, &DWP(12,$tmp1,"",0));
193
194 &set_label("start") unless $normal;
195 &comment("");
196 &comment("R0 section");
197
198 &R0(-2,$A,$B,$C,$D,$X, 0, 7,0xd76aa478);
199 &R0( 0,$D,$A,$B,$C,$X, 1,12,0xe8c7b756);
200 &R0( 0,$C,$D,$A,$B,$X, 2,17,0x242070db);
201 &R0( 0,$B,$C,$D,$A,$X, 3,22,0xc1bdceee);
202 &R0( 0,$A,$B,$C,$D,$X, 4, 7,0xf57c0faf);
203 &R0( 0,$D,$A,$B,$C,$X, 5,12,0x4787c62a);
204 &R0( 0,$C,$D,$A,$B,$X, 6,17,0xa8304613);
205 &R0( 0,$B,$C,$D,$A,$X, 7,22,0xfd469501);
206 &R0( 0,$A,$B,$C,$D,$X, 8, 7,0x698098d8);
207 &R0( 0,$D,$A,$B,$C,$X, 9,12,0x8b44f7af);
208 &R0( 0,$C,$D,$A,$B,$X,10,17,0xffff5bb1);
209 &R0( 0,$B,$C,$D,$A,$X,11,22,0x895cd7be);
210 &R0( 0,$A,$B,$C,$D,$X,12, 7,0x6b901122);
211 &R0( 0,$D,$A,$B,$C,$X,13,12,0xfd987193);
212 &R0( 0,$C,$D,$A,$B,$X,14,17,0xa679438e);
213 &R0( 1,$B,$C,$D,$A,$X,15,22,0x49b40821);
214
215 &comment("");
216 &comment("R1 section");
217 &R1(-1,$A,$B,$C,$D,$X,16, 5,0xf61e2562);
218 &R1( 0,$D,$A,$B,$C,$X,17, 9,0xc040b340);
219 &R1( 0,$C,$D,$A,$B,$X,18,14,0x265e5a51);
220 &R1( 0,$B,$C,$D,$A,$X,19,20,0xe9b6c7aa);
221 &R1( 0,$A,$B,$C,$D,$X,20, 5,0xd62f105d);
222 &R1( 0,$D,$A,$B,$C,$X,21, 9,0x02441453);
223 &R1( 0,$C,$D,$A,$B,$X,22,14,0xd8a1e681);
224 &R1( 0,$B,$C,$D,$A,$X,23,20,0xe7d3fbc8);
225 &R1( 0,$A,$B,$C,$D,$X,24, 5,0x21e1cde6);
226 &R1( 0,$D,$A,$B,$C,$X,25, 9,0xc33707d6);
227 &R1( 0,$C,$D,$A,$B,$X,26,14,0xf4d50d87);
228 &R1( 0,$B,$C,$D,$A,$X,27,20,0x455a14ed);
229 &R1( 0,$A,$B,$C,$D,$X,28, 5,0xa9e3e905);
230 &R1( 0,$D,$A,$B,$C,$X,29, 9,0xfcefa3f8);
231 &R1( 0,$C,$D,$A,$B,$X,30,14,0x676f02d9);
232 &R1( 1,$B,$C,$D,$A,$X,31,20,0x8d2a4c8a);
233
234 &comment("");
235 &comment("R2 section");
236 &R2( 0,-1,$A,$B,$C,$D,$X,32, 4,0xfffa3942);
237 &R2( 1, 0,$D,$A,$B,$C,$X,33,11,0x8771f681);
238 &R2( 2, 0,$C,$D,$A,$B,$X,34,16,0x6d9d6122);
239 &R2( 3, 0,$B,$C,$D,$A,$X,35,23,0xfde5380c);
240 &R2( 4, 0,$A,$B,$C,$D,$X,36, 4,0xa4beea44);
241 &R2( 5, 0,$D,$A,$B,$C,$X,37,11,0x4bdecfa9);
242 &R2( 6, 0,$C,$D,$A,$B,$X,38,16,0xf6bb4b60);
243 &R2( 7, 0,$B,$C,$D,$A,$X,39,23,0xbebfbc70);
244 &R2( 8, 0,$A,$B,$C,$D,$X,40, 4,0x289b7ec6);
245 &R2( 9, 0,$D,$A,$B,$C,$X,41,11,0xeaa127fa);
246 &R2(10, 0,$C,$D,$A,$B,$X,42,16,0xd4ef3085);
247 &R2(11, 0,$B,$C,$D,$A,$X,43,23,0x04881d05);
248 &R2(12, 0,$A,$B,$C,$D,$X,44, 4,0xd9d4d039);
249 &R2(13, 0,$D,$A,$B,$C,$X,45,11,0xe6db99e5);
250 &R2(14, 0,$C,$D,$A,$B,$X,46,16,0x1fa27cf8);
251 &R2(15, 1,$B,$C,$D,$A,$X,47,23,0xc4ac5665);
252
253 &comment("");
254 &comment("R3 section");
255 &R3(-1,$A,$B,$C,$D,$X,48, 6,0xf4292244);
256 &R3( 0,$D,$A,$B,$C,$X,49,10,0x432aff97);
257 &R3( 0,$C,$D,$A,$B,$X,50,15,0xab9423a7);
258 &R3( 0,$B,$C,$D,$A,$X,51,21,0xfc93a039);
259 &R3( 0,$A,$B,$C,$D,$X,52, 6,0x655b59c3);
260 &R3( 0,$D,$A,$B,$C,$X,53,10,0x8f0ccc92);
261 &R3( 0,$C,$D,$A,$B,$X,54,15,0xffeff47d);
262 &R3( 0,$B,$C,$D,$A,$X,55,21,0x85845dd1);
263 &R3( 0,$A,$B,$C,$D,$X,56, 6,0x6fa87e4f);
264 &R3( 0,$D,$A,$B,$C,$X,57,10,0xfe2ce6e0);
265 &R3( 0,$C,$D,$A,$B,$X,58,15,0xa3014314);
266 &R3( 0,$B,$C,$D,$A,$X,59,21,0x4e0811a1);
267 &R3( 0,$A,$B,$C,$D,$X,60, 6,0xf7537e82);
268 &R3( 0,$D,$A,$B,$C,$X,61,10,0xbd3af235);
269 &R3( 0,$C,$D,$A,$B,$X,62,15,0x2ad7d2bb);
270 &R3( 2,$B,$C,$D,$A,$X,63,21,0xeb86d391);
271
272 # &mov($tmp2,&wparam(0)); # done in the last R3
273 # &mov($tmp1, &DWP( 0,$tmp2,"",0)); # done is the last R3
274
275 &add($A,$tmp1);
276 &mov($tmp1, &DWP( 4,$tmp2,"",0));
277
278 &add($B,$tmp1);
279 &mov($tmp1, &DWP( 8,$tmp2,"",0));
280
281 &add($C,$tmp1);
282 &mov($tmp1, &DWP(12,$tmp2,"",0));
283
284 &add($D,$tmp1);
285 &mov(&DWP( 0,$tmp2,"",0),$A);
286
287 &mov(&DWP( 4,$tmp2,"",0),$B);
288 &mov($tmp1,&swtmp(0)) unless $normal;
289
290 &mov(&DWP( 8,$tmp2,"",0),$C);
291 &mov(&DWP(12,$tmp2,"",0),$D);
292
293 &cmp($tmp1,$X) unless $normal; # check count
294 &jge(&label("start")) unless $normal;
295
296 &pop("eax"); # pop the temp variable off the stack
297 &pop("ebx");
298 &pop("ebp");
299 &pop("edi");
300 &pop("esi");
301 &ret();
302 &function_end_B($name);
303 }
304