diff options
Diffstat (limited to 'src/lib/libcrypto/md5/asm')
-rw-r--r-- | src/lib/libcrypto/md5/asm/md5-586.pl | 306 | ||||
-rwxr-xr-x | src/lib/libcrypto/md5/asm/md5-x86_64.pl | 245 |
2 files changed, 0 insertions, 551 deletions
diff --git a/src/lib/libcrypto/md5/asm/md5-586.pl b/src/lib/libcrypto/md5/asm/md5-586.pl deleted file mode 100644 index 76ac235f7d..0000000000 --- a/src/lib/libcrypto/md5/asm/md5-586.pl +++ /dev/null | |||
@@ -1,306 +0,0 @@ | |||
1 | #!/usr/local/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 | |||
10 | push(@INC,"perlasm","../../perlasm"); | ||
11 | require "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_asm_data_order"); | ||
33 | &asm_finish(); | ||
34 | |||
35 | sub Np | ||
36 | { | ||
37 | local($p)=@_; | ||
38 | local(%n)=($A,$D,$B,$A,$C,$B,$D,$C); | ||
39 | return($n{$p}); | ||
40 | } | ||
41 | |||
42 | sub 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 | &xor($tmp1,$d); # F function - part 4 | ||
58 | |||
59 | &add($a,$tmp1); | ||
60 | &mov($tmp1,&Np($c)) if $pos < 1; # next tmp1 for R0 | ||
61 | &mov($tmp1,&Np($c)) if $pos == 1; # next tmp1 for R1 | ||
62 | |||
63 | &rotl($a,$s); | ||
64 | |||
65 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); | ||
66 | |||
67 | &add($a,$b); | ||
68 | } | ||
69 | |||
70 | sub R1 | ||
71 | { | ||
72 | local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; | ||
73 | |||
74 | &comment("R1 $ki"); | ||
75 | |||
76 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
77 | |||
78 | &xor($tmp1,$b); # G function - part 2 | ||
79 | &and($tmp1,$d); # G function - part 3 | ||
80 | |||
81 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); | ||
82 | &xor($tmp1,$c); # G function - part 4 | ||
83 | |||
84 | &add($a,$tmp1); | ||
85 | &mov($tmp1,&Np($c)) if $pos < 1; # G function - part 1 | ||
86 | &mov($tmp1,&Np($c)) if $pos == 1; # G function - part 1 | ||
87 | |||
88 | &rotl($a,$s); | ||
89 | |||
90 | &add($a,$b); | ||
91 | } | ||
92 | |||
93 | sub R2 | ||
94 | { | ||
95 | local($n,$pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; | ||
96 | # This one is different, only 3 logical operations | ||
97 | |||
98 | if (($n & 1) == 0) | ||
99 | { | ||
100 | &comment("R2 $ki"); | ||
101 | # make sure to do 'D' first, not 'B', else we clash with | ||
102 | # the last add from the previous round. | ||
103 | |||
104 | &xor($tmp1,$d); # H function - part 2 | ||
105 | |||
106 | &xor($tmp1,$b); # H function - part 3 | ||
107 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
108 | |||
109 | &add($a,$tmp1); | ||
110 | |||
111 | &rotl($a,$s); | ||
112 | |||
113 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)); | ||
114 | &mov($tmp1,&Np($c)); | ||
115 | } | ||
116 | else | ||
117 | { | ||
118 | &comment("R2 $ki"); | ||
119 | # make sure to do 'D' first, not 'B', else we clash with | ||
120 | # the last add from the previous round. | ||
121 | |||
122 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
123 | |||
124 | &add($b,$c); # MOVED FORWARD | ||
125 | &xor($tmp1,$d); # H function - part 2 | ||
126 | |||
127 | &xor($tmp1,$b); # H function - part 3 | ||
128 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); | ||
129 | |||
130 | &add($a,$tmp1); | ||
131 | &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1 | ||
132 | &mov($tmp1,-1) if $pos == 1; # I function - part 1 | ||
133 | |||
134 | &rotl($a,$s); | ||
135 | |||
136 | &add($a,$b); | ||
137 | } | ||
138 | } | ||
139 | |||
140 | sub R3 | ||
141 | { | ||
142 | local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; | ||
143 | |||
144 | &comment("R3 $ki"); | ||
145 | |||
146 | # ¬($tmp1) | ||
147 | &xor($tmp1,$d) if $pos < 0; # I function - part 2 | ||
148 | |||
149 | &or($tmp1,$b); # I function - part 3 | ||
150 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
151 | |||
152 | &xor($tmp1,$c); # I function - part 4 | ||
153 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value | ||
154 | &mov($tmp2,&wparam(0)) if $pos == 2; | ||
155 | |||
156 | &add($a,$tmp1); | ||
157 | &mov($tmp1,-1) if $pos < 1; # H function - part 1 | ||
158 | &add($K,64) if $pos >=1 && !$normal; | ||
159 | |||
160 | &rotl($a,$s); | ||
161 | |||
162 | &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time | ||
163 | &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0; | ||
164 | &add($a,$b); | ||
165 | } | ||
166 | |||
167 | |||
168 | sub md5_block | ||
169 | { | ||
170 | local($name)=@_; | ||
171 | |||
172 | &function_begin_B($name,"",3); | ||
173 | |||
174 | # parameter 1 is the MD5_CTX structure. | ||
175 | # A 0 | ||
176 | # B 4 | ||
177 | # C 8 | ||
178 | # D 12 | ||
179 | |||
180 | &push("esi"); | ||
181 | &push("edi"); | ||
182 | &mov($tmp1, &wparam(0)); # edi | ||
183 | &mov($X, &wparam(1)); # esi | ||
184 | &mov($C, &wparam(2)); | ||
185 | &push("ebp"); | ||
186 | &shl($C, 6); | ||
187 | &push("ebx"); | ||
188 | &add($C, $X); # offset we end at | ||
189 | &sub($C, 64); | ||
190 | &mov($A, &DWP( 0,$tmp1,"",0)); | ||
191 | &push($C); # Put on the TOS | ||
192 | &mov($B, &DWP( 4,$tmp1,"",0)); | ||
193 | &mov($C, &DWP( 8,$tmp1,"",0)); | ||
194 | &mov($D, &DWP(12,$tmp1,"",0)); | ||
195 | |||
196 | &set_label("start") unless $normal; | ||
197 | &comment(""); | ||
198 | &comment("R0 section"); | ||
199 | |||
200 | &R0(-2,$A,$B,$C,$D,$X, 0, 7,0xd76aa478); | ||
201 | &R0( 0,$D,$A,$B,$C,$X, 1,12,0xe8c7b756); | ||
202 | &R0( 0,$C,$D,$A,$B,$X, 2,17,0x242070db); | ||
203 | &R0( 0,$B,$C,$D,$A,$X, 3,22,0xc1bdceee); | ||
204 | &R0( 0,$A,$B,$C,$D,$X, 4, 7,0xf57c0faf); | ||
205 | &R0( 0,$D,$A,$B,$C,$X, 5,12,0x4787c62a); | ||
206 | &R0( 0,$C,$D,$A,$B,$X, 6,17,0xa8304613); | ||
207 | &R0( 0,$B,$C,$D,$A,$X, 7,22,0xfd469501); | ||
208 | &R0( 0,$A,$B,$C,$D,$X, 8, 7,0x698098d8); | ||
209 | &R0( 0,$D,$A,$B,$C,$X, 9,12,0x8b44f7af); | ||
210 | &R0( 0,$C,$D,$A,$B,$X,10,17,0xffff5bb1); | ||
211 | &R0( 0,$B,$C,$D,$A,$X,11,22,0x895cd7be); | ||
212 | &R0( 0,$A,$B,$C,$D,$X,12, 7,0x6b901122); | ||
213 | &R0( 0,$D,$A,$B,$C,$X,13,12,0xfd987193); | ||
214 | &R0( 0,$C,$D,$A,$B,$X,14,17,0xa679438e); | ||
215 | &R0( 1,$B,$C,$D,$A,$X,15,22,0x49b40821); | ||
216 | |||
217 | &comment(""); | ||
218 | &comment("R1 section"); | ||
219 | &R1(-1,$A,$B,$C,$D,$X,16, 5,0xf61e2562); | ||
220 | &R1( 0,$D,$A,$B,$C,$X,17, 9,0xc040b340); | ||
221 | &R1( 0,$C,$D,$A,$B,$X,18,14,0x265e5a51); | ||
222 | &R1( 0,$B,$C,$D,$A,$X,19,20,0xe9b6c7aa); | ||
223 | &R1( 0,$A,$B,$C,$D,$X,20, 5,0xd62f105d); | ||
224 | &R1( 0,$D,$A,$B,$C,$X,21, 9,0x02441453); | ||
225 | &R1( 0,$C,$D,$A,$B,$X,22,14,0xd8a1e681); | ||
226 | &R1( 0,$B,$C,$D,$A,$X,23,20,0xe7d3fbc8); | ||
227 | &R1( 0,$A,$B,$C,$D,$X,24, 5,0x21e1cde6); | ||
228 | &R1( 0,$D,$A,$B,$C,$X,25, 9,0xc33707d6); | ||
229 | &R1( 0,$C,$D,$A,$B,$X,26,14,0xf4d50d87); | ||
230 | &R1( 0,$B,$C,$D,$A,$X,27,20,0x455a14ed); | ||
231 | &R1( 0,$A,$B,$C,$D,$X,28, 5,0xa9e3e905); | ||
232 | &R1( 0,$D,$A,$B,$C,$X,29, 9,0xfcefa3f8); | ||
233 | &R1( 0,$C,$D,$A,$B,$X,30,14,0x676f02d9); | ||
234 | &R1( 1,$B,$C,$D,$A,$X,31,20,0x8d2a4c8a); | ||
235 | |||
236 | &comment(""); | ||
237 | &comment("R2 section"); | ||
238 | &R2( 0,-1,$A,$B,$C,$D,$X,32, 4,0xfffa3942); | ||
239 | &R2( 1, 0,$D,$A,$B,$C,$X,33,11,0x8771f681); | ||
240 | &R2( 2, 0,$C,$D,$A,$B,$X,34,16,0x6d9d6122); | ||
241 | &R2( 3, 0,$B,$C,$D,$A,$X,35,23,0xfde5380c); | ||
242 | &R2( 4, 0,$A,$B,$C,$D,$X,36, 4,0xa4beea44); | ||
243 | &R2( 5, 0,$D,$A,$B,$C,$X,37,11,0x4bdecfa9); | ||
244 | &R2( 6, 0,$C,$D,$A,$B,$X,38,16,0xf6bb4b60); | ||
245 | &R2( 7, 0,$B,$C,$D,$A,$X,39,23,0xbebfbc70); | ||
246 | &R2( 8, 0,$A,$B,$C,$D,$X,40, 4,0x289b7ec6); | ||
247 | &R2( 9, 0,$D,$A,$B,$C,$X,41,11,0xeaa127fa); | ||
248 | &R2(10, 0,$C,$D,$A,$B,$X,42,16,0xd4ef3085); | ||
249 | &R2(11, 0,$B,$C,$D,$A,$X,43,23,0x04881d05); | ||
250 | &R2(12, 0,$A,$B,$C,$D,$X,44, 4,0xd9d4d039); | ||
251 | &R2(13, 0,$D,$A,$B,$C,$X,45,11,0xe6db99e5); | ||
252 | &R2(14, 0,$C,$D,$A,$B,$X,46,16,0x1fa27cf8); | ||
253 | &R2(15, 1,$B,$C,$D,$A,$X,47,23,0xc4ac5665); | ||
254 | |||
255 | &comment(""); | ||
256 | &comment("R3 section"); | ||
257 | &R3(-1,$A,$B,$C,$D,$X,48, 6,0xf4292244); | ||
258 | &R3( 0,$D,$A,$B,$C,$X,49,10,0x432aff97); | ||
259 | &R3( 0,$C,$D,$A,$B,$X,50,15,0xab9423a7); | ||
260 | &R3( 0,$B,$C,$D,$A,$X,51,21,0xfc93a039); | ||
261 | &R3( 0,$A,$B,$C,$D,$X,52, 6,0x655b59c3); | ||
262 | &R3( 0,$D,$A,$B,$C,$X,53,10,0x8f0ccc92); | ||
263 | &R3( 0,$C,$D,$A,$B,$X,54,15,0xffeff47d); | ||
264 | &R3( 0,$B,$C,$D,$A,$X,55,21,0x85845dd1); | ||
265 | &R3( 0,$A,$B,$C,$D,$X,56, 6,0x6fa87e4f); | ||
266 | &R3( 0,$D,$A,$B,$C,$X,57,10,0xfe2ce6e0); | ||
267 | &R3( 0,$C,$D,$A,$B,$X,58,15,0xa3014314); | ||
268 | &R3( 0,$B,$C,$D,$A,$X,59,21,0x4e0811a1); | ||
269 | &R3( 0,$A,$B,$C,$D,$X,60, 6,0xf7537e82); | ||
270 | &R3( 0,$D,$A,$B,$C,$X,61,10,0xbd3af235); | ||
271 | &R3( 0,$C,$D,$A,$B,$X,62,15,0x2ad7d2bb); | ||
272 | &R3( 2,$B,$C,$D,$A,$X,63,21,0xeb86d391); | ||
273 | |||
274 | # &mov($tmp2,&wparam(0)); # done in the last R3 | ||
275 | # &mov($tmp1, &DWP( 0,$tmp2,"",0)); # done is the last R3 | ||
276 | |||
277 | &add($A,$tmp1); | ||
278 | &mov($tmp1, &DWP( 4,$tmp2,"",0)); | ||
279 | |||
280 | &add($B,$tmp1); | ||
281 | &mov($tmp1, &DWP( 8,$tmp2,"",0)); | ||
282 | |||
283 | &add($C,$tmp1); | ||
284 | &mov($tmp1, &DWP(12,$tmp2,"",0)); | ||
285 | |||
286 | &add($D,$tmp1); | ||
287 | &mov(&DWP( 0,$tmp2,"",0),$A); | ||
288 | |||
289 | &mov(&DWP( 4,$tmp2,"",0),$B); | ||
290 | &mov($tmp1,&swtmp(0)) unless $normal; | ||
291 | |||
292 | &mov(&DWP( 8,$tmp2,"",0),$C); | ||
293 | &mov(&DWP(12,$tmp2,"",0),$D); | ||
294 | |||
295 | &cmp($tmp1,$X) unless $normal; # check count | ||
296 | &jae(&label("start")) unless $normal; | ||
297 | |||
298 | &pop("eax"); # pop the temp variable off the stack | ||
299 | &pop("ebx"); | ||
300 | &pop("ebp"); | ||
301 | &pop("edi"); | ||
302 | &pop("esi"); | ||
303 | &ret(); | ||
304 | &function_end_B($name); | ||
305 | } | ||
306 | |||
diff --git a/src/lib/libcrypto/md5/asm/md5-x86_64.pl b/src/lib/libcrypto/md5/asm/md5-x86_64.pl deleted file mode 100755 index 9a6fa67224..0000000000 --- a/src/lib/libcrypto/md5/asm/md5-x86_64.pl +++ /dev/null | |||
@@ -1,245 +0,0 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | # | ||
3 | # MD5 optimized for AMD64. | ||
4 | # | ||
5 | # Author: Marc Bevand <bevand_m (at) epita.fr> | ||
6 | # Licence: I hereby disclaim the copyright on this code and place it | ||
7 | # in the public domain. | ||
8 | # | ||
9 | |||
10 | use strict; | ||
11 | |||
12 | my $code; | ||
13 | |||
14 | # round1_step() does: | ||
15 | # dst = x + ((dst + F(x,y,z) + X[k] + T_i) <<< s) | ||
16 | # %r10d = X[k_next] | ||
17 | # %r11d = z' (copy of z for the next step) | ||
18 | # Each round1_step() takes about 5.71 clocks (9 instructions, 1.58 IPC) | ||
19 | sub round1_step | ||
20 | { | ||
21 | my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_; | ||
22 | $code .= " mov 0*4(%rsi), %r10d /* (NEXT STEP) X[0] */\n" if ($pos == -1); | ||
23 | $code .= " mov %edx, %r11d /* (NEXT STEP) z' = %edx */\n" if ($pos == -1); | ||
24 | $code .= <<EOF; | ||
25 | xor $y, %r11d /* y ^ ... */ | ||
26 | lea $T_i($dst,%r10d),$dst /* Const + dst + ... */ | ||
27 | and $x, %r11d /* x & ... */ | ||
28 | xor $z, %r11d /* z ^ ... */ | ||
29 | mov $k_next*4(%rsi),%r10d /* (NEXT STEP) X[$k_next] */ | ||
30 | add %r11d, $dst /* dst += ... */ | ||
31 | rol \$$s, $dst /* dst <<< s */ | ||
32 | mov $y, %r11d /* (NEXT STEP) z' = $y */ | ||
33 | add $x, $dst /* dst += x */ | ||
34 | EOF | ||
35 | } | ||
36 | |||
37 | # round2_step() does: | ||
38 | # dst = x + ((dst + G(x,y,z) + X[k] + T_i) <<< s) | ||
39 | # %r10d = X[k_next] | ||
40 | # %r11d = y' (copy of y for the next step) | ||
41 | # Each round2_step() takes about 6.22 clocks (9 instructions, 1.45 IPC) | ||
42 | sub round2_step | ||
43 | { | ||
44 | my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_; | ||
45 | $code .= " mov 1*4(%rsi), %r10d /* (NEXT STEP) X[1] */\n" if ($pos == -1); | ||
46 | $code .= " mov %ecx, %r11d /* (NEXT STEP) y' = %ecx */\n" if ($pos == -1); | ||
47 | $code .= <<EOF; | ||
48 | xor $x, %r11d /* x ^ ... */ | ||
49 | lea $T_i($dst,%r10d),$dst /* Const + dst + ... */ | ||
50 | and $z, %r11d /* z & ... */ | ||
51 | xor $y, %r11d /* y ^ ... */ | ||
52 | mov $k_next*4(%rsi),%r10d /* (NEXT STEP) X[$k_next] */ | ||
53 | add %r11d, $dst /* dst += ... */ | ||
54 | rol \$$s, $dst /* dst <<< s */ | ||
55 | mov $x, %r11d /* (NEXT STEP) y' = $x */ | ||
56 | add $x, $dst /* dst += x */ | ||
57 | EOF | ||
58 | } | ||
59 | |||
60 | # round3_step() does: | ||
61 | # dst = x + ((dst + H(x,y,z) + X[k] + T_i) <<< s) | ||
62 | # %r10d = X[k_next] | ||
63 | # %r11d = y' (copy of y for the next step) | ||
64 | # Each round3_step() takes about 4.26 clocks (8 instructions, 1.88 IPC) | ||
65 | sub round3_step | ||
66 | { | ||
67 | my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_; | ||
68 | $code .= " mov 5*4(%rsi), %r10d /* (NEXT STEP) X[5] */\n" if ($pos == -1); | ||
69 | $code .= " mov %ecx, %r11d /* (NEXT STEP) y' = %ecx */\n" if ($pos == -1); | ||
70 | $code .= <<EOF; | ||
71 | lea $T_i($dst,%r10d),$dst /* Const + dst + ... */ | ||
72 | mov $k_next*4(%rsi),%r10d /* (NEXT STEP) X[$k_next] */ | ||
73 | xor $z, %r11d /* z ^ ... */ | ||
74 | xor $x, %r11d /* x ^ ... */ | ||
75 | add %r11d, $dst /* dst += ... */ | ||
76 | rol \$$s, $dst /* dst <<< s */ | ||
77 | mov $x, %r11d /* (NEXT STEP) y' = $x */ | ||
78 | add $x, $dst /* dst += x */ | ||
79 | EOF | ||
80 | } | ||
81 | |||
82 | # round4_step() does: | ||
83 | # dst = x + ((dst + I(x,y,z) + X[k] + T_i) <<< s) | ||
84 | # %r10d = X[k_next] | ||
85 | # %r11d = not z' (copy of not z for the next step) | ||
86 | # Each round4_step() takes about 5.27 clocks (9 instructions, 1.71 IPC) | ||
87 | sub round4_step | ||
88 | { | ||
89 | my ($pos, $dst, $x, $y, $z, $k_next, $T_i, $s) = @_; | ||
90 | $code .= " mov 0*4(%rsi), %r10d /* (NEXT STEP) X[0] */\n" if ($pos == -1); | ||
91 | $code .= " mov \$0xffffffff, %r11d\n" if ($pos == -1); | ||
92 | $code .= " xor %edx, %r11d /* (NEXT STEP) not z' = not %edx*/\n" | ||
93 | if ($pos == -1); | ||
94 | $code .= <<EOF; | ||
95 | lea $T_i($dst,%r10d),$dst /* Const + dst + ... */ | ||
96 | or $x, %r11d /* x | ... */ | ||
97 | xor $y, %r11d /* y ^ ... */ | ||
98 | add %r11d, $dst /* dst += ... */ | ||
99 | mov $k_next*4(%rsi),%r10d /* (NEXT STEP) X[$k_next] */ | ||
100 | mov \$0xffffffff, %r11d | ||
101 | rol \$$s, $dst /* dst <<< s */ | ||
102 | xor $y, %r11d /* (NEXT STEP) not z' = not $y */ | ||
103 | add $x, $dst /* dst += x */ | ||
104 | EOF | ||
105 | } | ||
106 | |||
107 | my $output = shift; | ||
108 | open STDOUT,"| $^X ../perlasm/x86_64-xlate.pl $output"; | ||
109 | |||
110 | $code .= <<EOF; | ||
111 | .text | ||
112 | .align 16 | ||
113 | |||
114 | .globl md5_block_asm_data_order | ||
115 | .type md5_block_asm_data_order,\@function,3 | ||
116 | md5_block_asm_data_order: | ||
117 | push %rbp | ||
118 | push %rbx | ||
119 | push %r14 | ||
120 | push %r15 | ||
121 | |||
122 | # rdi = arg #1 (ctx, MD5_CTX pointer) | ||
123 | # rsi = arg #2 (ptr, data pointer) | ||
124 | # rdx = arg #3 (nbr, number of 16-word blocks to process) | ||
125 | mov %rdi, %rbp # rbp = ctx | ||
126 | shl \$6, %rdx # rdx = nbr in bytes | ||
127 | lea (%rsi,%rdx), %rdi # rdi = end | ||
128 | mov 0*4(%rbp), %eax # eax = ctx->A | ||
129 | mov 1*4(%rbp), %ebx # ebx = ctx->B | ||
130 | mov 2*4(%rbp), %ecx # ecx = ctx->C | ||
131 | mov 3*4(%rbp), %edx # edx = ctx->D | ||
132 | # end is 'rdi' | ||
133 | # ptr is 'rsi' | ||
134 | # A is 'eax' | ||
135 | # B is 'ebx' | ||
136 | # C is 'ecx' | ||
137 | # D is 'edx' | ||
138 | |||
139 | cmp %rdi, %rsi # cmp end with ptr | ||
140 | je .Lend # jmp if ptr == end | ||
141 | |||
142 | # BEGIN of loop over 16-word blocks | ||
143 | .Lloop: # save old values of A, B, C, D | ||
144 | mov %eax, %r8d | ||
145 | mov %ebx, %r9d | ||
146 | mov %ecx, %r14d | ||
147 | mov %edx, %r15d | ||
148 | EOF | ||
149 | round1_step(-1,'%eax','%ebx','%ecx','%edx', '1','0xd76aa478', '7'); | ||
150 | round1_step( 0,'%edx','%eax','%ebx','%ecx', '2','0xe8c7b756','12'); | ||
151 | round1_step( 0,'%ecx','%edx','%eax','%ebx', '3','0x242070db','17'); | ||
152 | round1_step( 0,'%ebx','%ecx','%edx','%eax', '4','0xc1bdceee','22'); | ||
153 | round1_step( 0,'%eax','%ebx','%ecx','%edx', '5','0xf57c0faf', '7'); | ||
154 | round1_step( 0,'%edx','%eax','%ebx','%ecx', '6','0x4787c62a','12'); | ||
155 | round1_step( 0,'%ecx','%edx','%eax','%ebx', '7','0xa8304613','17'); | ||
156 | round1_step( 0,'%ebx','%ecx','%edx','%eax', '8','0xfd469501','22'); | ||
157 | round1_step( 0,'%eax','%ebx','%ecx','%edx', '9','0x698098d8', '7'); | ||
158 | round1_step( 0,'%edx','%eax','%ebx','%ecx','10','0x8b44f7af','12'); | ||
159 | round1_step( 0,'%ecx','%edx','%eax','%ebx','11','0xffff5bb1','17'); | ||
160 | round1_step( 0,'%ebx','%ecx','%edx','%eax','12','0x895cd7be','22'); | ||
161 | round1_step( 0,'%eax','%ebx','%ecx','%edx','13','0x6b901122', '7'); | ||
162 | round1_step( 0,'%edx','%eax','%ebx','%ecx','14','0xfd987193','12'); | ||
163 | round1_step( 0,'%ecx','%edx','%eax','%ebx','15','0xa679438e','17'); | ||
164 | round1_step( 1,'%ebx','%ecx','%edx','%eax', '0','0x49b40821','22'); | ||
165 | |||
166 | round2_step(-1,'%eax','%ebx','%ecx','%edx', '6','0xf61e2562', '5'); | ||
167 | round2_step( 0,'%edx','%eax','%ebx','%ecx','11','0xc040b340', '9'); | ||
168 | round2_step( 0,'%ecx','%edx','%eax','%ebx', '0','0x265e5a51','14'); | ||
169 | round2_step( 0,'%ebx','%ecx','%edx','%eax', '5','0xe9b6c7aa','20'); | ||
170 | round2_step( 0,'%eax','%ebx','%ecx','%edx','10','0xd62f105d', '5'); | ||
171 | round2_step( 0,'%edx','%eax','%ebx','%ecx','15', '0x2441453', '9'); | ||
172 | round2_step( 0,'%ecx','%edx','%eax','%ebx', '4','0xd8a1e681','14'); | ||
173 | round2_step( 0,'%ebx','%ecx','%edx','%eax', '9','0xe7d3fbc8','20'); | ||
174 | round2_step( 0,'%eax','%ebx','%ecx','%edx','14','0x21e1cde6', '5'); | ||
175 | round2_step( 0,'%edx','%eax','%ebx','%ecx', '3','0xc33707d6', '9'); | ||
176 | round2_step( 0,'%ecx','%edx','%eax','%ebx', '8','0xf4d50d87','14'); | ||
177 | round2_step( 0,'%ebx','%ecx','%edx','%eax','13','0x455a14ed','20'); | ||
178 | round2_step( 0,'%eax','%ebx','%ecx','%edx', '2','0xa9e3e905', '5'); | ||
179 | round2_step( 0,'%edx','%eax','%ebx','%ecx', '7','0xfcefa3f8', '9'); | ||
180 | round2_step( 0,'%ecx','%edx','%eax','%ebx','12','0x676f02d9','14'); | ||
181 | round2_step( 1,'%ebx','%ecx','%edx','%eax', '0','0x8d2a4c8a','20'); | ||
182 | |||
183 | round3_step(-1,'%eax','%ebx','%ecx','%edx', '8','0xfffa3942', '4'); | ||
184 | round3_step( 0,'%edx','%eax','%ebx','%ecx','11','0x8771f681','11'); | ||
185 | round3_step( 0,'%ecx','%edx','%eax','%ebx','14','0x6d9d6122','16'); | ||
186 | round3_step( 0,'%ebx','%ecx','%edx','%eax', '1','0xfde5380c','23'); | ||
187 | round3_step( 0,'%eax','%ebx','%ecx','%edx', '4','0xa4beea44', '4'); | ||
188 | round3_step( 0,'%edx','%eax','%ebx','%ecx', '7','0x4bdecfa9','11'); | ||
189 | round3_step( 0,'%ecx','%edx','%eax','%ebx','10','0xf6bb4b60','16'); | ||
190 | round3_step( 0,'%ebx','%ecx','%edx','%eax','13','0xbebfbc70','23'); | ||
191 | round3_step( 0,'%eax','%ebx','%ecx','%edx', '0','0x289b7ec6', '4'); | ||
192 | round3_step( 0,'%edx','%eax','%ebx','%ecx', '3','0xeaa127fa','11'); | ||
193 | round3_step( 0,'%ecx','%edx','%eax','%ebx', '6','0xd4ef3085','16'); | ||
194 | round3_step( 0,'%ebx','%ecx','%edx','%eax', '9', '0x4881d05','23'); | ||
195 | round3_step( 0,'%eax','%ebx','%ecx','%edx','12','0xd9d4d039', '4'); | ||
196 | round3_step( 0,'%edx','%eax','%ebx','%ecx','15','0xe6db99e5','11'); | ||
197 | round3_step( 0,'%ecx','%edx','%eax','%ebx', '2','0x1fa27cf8','16'); | ||
198 | round3_step( 1,'%ebx','%ecx','%edx','%eax', '0','0xc4ac5665','23'); | ||
199 | |||
200 | round4_step(-1,'%eax','%ebx','%ecx','%edx', '7','0xf4292244', '6'); | ||
201 | round4_step( 0,'%edx','%eax','%ebx','%ecx','14','0x432aff97','10'); | ||
202 | round4_step( 0,'%ecx','%edx','%eax','%ebx', '5','0xab9423a7','15'); | ||
203 | round4_step( 0,'%ebx','%ecx','%edx','%eax','12','0xfc93a039','21'); | ||
204 | round4_step( 0,'%eax','%ebx','%ecx','%edx', '3','0x655b59c3', '6'); | ||
205 | round4_step( 0,'%edx','%eax','%ebx','%ecx','10','0x8f0ccc92','10'); | ||
206 | round4_step( 0,'%ecx','%edx','%eax','%ebx', '1','0xffeff47d','15'); | ||
207 | round4_step( 0,'%ebx','%ecx','%edx','%eax', '8','0x85845dd1','21'); | ||
208 | round4_step( 0,'%eax','%ebx','%ecx','%edx','15','0x6fa87e4f', '6'); | ||
209 | round4_step( 0,'%edx','%eax','%ebx','%ecx', '6','0xfe2ce6e0','10'); | ||
210 | round4_step( 0,'%ecx','%edx','%eax','%ebx','13','0xa3014314','15'); | ||
211 | round4_step( 0,'%ebx','%ecx','%edx','%eax', '4','0x4e0811a1','21'); | ||
212 | round4_step( 0,'%eax','%ebx','%ecx','%edx','11','0xf7537e82', '6'); | ||
213 | round4_step( 0,'%edx','%eax','%ebx','%ecx', '2','0xbd3af235','10'); | ||
214 | round4_step( 0,'%ecx','%edx','%eax','%ebx', '9','0x2ad7d2bb','15'); | ||
215 | round4_step( 1,'%ebx','%ecx','%edx','%eax', '0','0xeb86d391','21'); | ||
216 | $code .= <<EOF; | ||
217 | # add old values of A, B, C, D | ||
218 | add %r8d, %eax | ||
219 | add %r9d, %ebx | ||
220 | add %r14d, %ecx | ||
221 | add %r15d, %edx | ||
222 | |||
223 | # loop control | ||
224 | add \$64, %rsi # ptr += 64 | ||
225 | cmp %rdi, %rsi # cmp end with ptr | ||
226 | jb .Lloop # jmp if ptr < end | ||
227 | # END of loop over 16-word blocks | ||
228 | |||
229 | .Lend: | ||
230 | mov %eax, 0*4(%rbp) # ctx->A = A | ||
231 | mov %ebx, 1*4(%rbp) # ctx->B = B | ||
232 | mov %ecx, 2*4(%rbp) # ctx->C = C | ||
233 | mov %edx, 3*4(%rbp) # ctx->D = D | ||
234 | |||
235 | pop %r15 | ||
236 | pop %r14 | ||
237 | pop %rbx | ||
238 | pop %rbp | ||
239 | ret | ||
240 | .size md5_block_asm_data_order,.-md5_block_asm_data_order | ||
241 | EOF | ||
242 | |||
243 | print $code; | ||
244 | |||
245 | close STDOUT; | ||