1 | default rel
|
---|
2 | %define XMMWORD
|
---|
3 | %define YMMWORD
|
---|
4 | %define ZMMWORD
|
---|
5 | EXTERN OPENSSL_cpuid_setup
|
---|
6 |
|
---|
7 | section .CRT$XCU rdata align=8
|
---|
8 | DQ OPENSSL_cpuid_setup
|
---|
9 |
|
---|
10 |
|
---|
11 | common OPENSSL_ia32cap_P 16
|
---|
12 |
|
---|
13 | section .text code align=64
|
---|
14 |
|
---|
15 |
|
---|
16 | global OPENSSL_atomic_add
|
---|
17 |
|
---|
18 | ALIGN 16
|
---|
19 | OPENSSL_atomic_add:
|
---|
20 | mov eax,DWORD[rcx]
|
---|
21 | $L$spin: lea r8,[rax*1+rdx]
|
---|
22 | DB 0xf0
|
---|
23 | cmpxchg DWORD[rcx],r8d
|
---|
24 | jne NEAR $L$spin
|
---|
25 | mov eax,r8d
|
---|
26 | DB 0x48,0x98
|
---|
27 | DB 0F3h,0C3h ;repret
|
---|
28 |
|
---|
29 |
|
---|
30 | global OPENSSL_rdtsc
|
---|
31 |
|
---|
32 | ALIGN 16
|
---|
33 | OPENSSL_rdtsc:
|
---|
34 | rdtsc
|
---|
35 | shl rdx,32
|
---|
36 | or rax,rdx
|
---|
37 | DB 0F3h,0C3h ;repret
|
---|
38 |
|
---|
39 |
|
---|
40 | global OPENSSL_ia32_cpuid
|
---|
41 |
|
---|
42 | ALIGN 16
|
---|
43 | OPENSSL_ia32_cpuid:
|
---|
44 | mov QWORD[8+rsp],rdi ;WIN64 prologue
|
---|
45 | mov QWORD[16+rsp],rsi
|
---|
46 | mov rax,rsp
|
---|
47 | $L$SEH_begin_OPENSSL_ia32_cpuid:
|
---|
48 | mov rdi,rcx
|
---|
49 |
|
---|
50 |
|
---|
51 | mov r8,rbx
|
---|
52 |
|
---|
53 | xor eax,eax
|
---|
54 | mov DWORD[8+rdi],eax
|
---|
55 | cpuid
|
---|
56 | mov r11d,eax
|
---|
57 |
|
---|
58 | xor eax,eax
|
---|
59 | cmp ebx,0x756e6547
|
---|
60 | setne al
|
---|
61 | mov r9d,eax
|
---|
62 | cmp edx,0x49656e69
|
---|
63 | setne al
|
---|
64 | or r9d,eax
|
---|
65 | cmp ecx,0x6c65746e
|
---|
66 | setne al
|
---|
67 | or r9d,eax
|
---|
68 | jz NEAR $L$intel
|
---|
69 |
|
---|
70 | cmp ebx,0x68747541
|
---|
71 | setne al
|
---|
72 | mov r10d,eax
|
---|
73 | cmp edx,0x69746E65
|
---|
74 | setne al
|
---|
75 | or r10d,eax
|
---|
76 | cmp ecx,0x444D4163
|
---|
77 | setne al
|
---|
78 | or r10d,eax
|
---|
79 | jnz NEAR $L$intel
|
---|
80 |
|
---|
81 |
|
---|
82 | mov eax,0x80000000
|
---|
83 | cpuid
|
---|
84 | cmp eax,0x80000001
|
---|
85 | jb NEAR $L$intel
|
---|
86 | mov r10d,eax
|
---|
87 | mov eax,0x80000001
|
---|
88 | cpuid
|
---|
89 | or r9d,ecx
|
---|
90 | and r9d,0x00000801
|
---|
91 |
|
---|
92 | cmp r10d,0x80000008
|
---|
93 | jb NEAR $L$intel
|
---|
94 |
|
---|
95 | mov eax,0x80000008
|
---|
96 | cpuid
|
---|
97 | movzx r10,cl
|
---|
98 | inc r10
|
---|
99 |
|
---|
100 | mov eax,1
|
---|
101 | cpuid
|
---|
102 | bt edx,28
|
---|
103 | jnc NEAR $L$generic
|
---|
104 | shr ebx,16
|
---|
105 | cmp bl,r10b
|
---|
106 | ja NEAR $L$generic
|
---|
107 | and edx,0xefffffff
|
---|
108 | jmp NEAR $L$generic
|
---|
109 |
|
---|
110 | $L$intel:
|
---|
111 | cmp r11d,4
|
---|
112 | mov r10d,-1
|
---|
113 | jb NEAR $L$nocacheinfo
|
---|
114 |
|
---|
115 | mov eax,4
|
---|
116 | mov ecx,0
|
---|
117 | cpuid
|
---|
118 | mov r10d,eax
|
---|
119 | shr r10d,14
|
---|
120 | and r10d,0xfff
|
---|
121 |
|
---|
122 | $L$nocacheinfo:
|
---|
123 | mov eax,1
|
---|
124 | cpuid
|
---|
125 | and edx,0xbfefffff
|
---|
126 | cmp r9d,0
|
---|
127 | jne NEAR $L$notintel
|
---|
128 | or edx,0x40000000
|
---|
129 | and ah,15
|
---|
130 | cmp ah,15
|
---|
131 | jne NEAR $L$notintel
|
---|
132 | or edx,0x00100000
|
---|
133 | $L$notintel:
|
---|
134 | bt edx,28
|
---|
135 | jnc NEAR $L$generic
|
---|
136 | and edx,0xefffffff
|
---|
137 | cmp r10d,0
|
---|
138 | je NEAR $L$generic
|
---|
139 |
|
---|
140 | or edx,0x10000000
|
---|
141 | shr ebx,16
|
---|
142 | cmp bl,1
|
---|
143 | ja NEAR $L$generic
|
---|
144 | and edx,0xefffffff
|
---|
145 | $L$generic:
|
---|
146 | and r9d,0x00000800
|
---|
147 | and ecx,0xfffff7ff
|
---|
148 | or r9d,ecx
|
---|
149 |
|
---|
150 | mov r10d,edx
|
---|
151 |
|
---|
152 | cmp r11d,7
|
---|
153 | jb NEAR $L$no_extended_info
|
---|
154 | mov eax,7
|
---|
155 | xor ecx,ecx
|
---|
156 | cpuid
|
---|
157 | mov DWORD[8+rdi],ebx
|
---|
158 | $L$no_extended_info:
|
---|
159 |
|
---|
160 | bt r9d,27
|
---|
161 | jnc NEAR $L$clear_avx
|
---|
162 | xor ecx,ecx
|
---|
163 | DB 0x0f,0x01,0xd0
|
---|
164 | and eax,6
|
---|
165 | cmp eax,6
|
---|
166 | je NEAR $L$done
|
---|
167 | $L$clear_avx:
|
---|
168 | mov eax,0xefffe7ff
|
---|
169 | and r9d,eax
|
---|
170 | and DWORD[8+rdi],0xffffffdf
|
---|
171 | $L$done:
|
---|
172 | shl r9,32
|
---|
173 | mov eax,r10d
|
---|
174 | mov rbx,r8
|
---|
175 | or rax,r9
|
---|
176 | mov rdi,QWORD[8+rsp] ;WIN64 epilogue
|
---|
177 | mov rsi,QWORD[16+rsp]
|
---|
178 | DB 0F3h,0C3h ;repret
|
---|
179 | $L$SEH_end_OPENSSL_ia32_cpuid:
|
---|
180 |
|
---|
181 | global OPENSSL_cleanse
|
---|
182 |
|
---|
183 | ALIGN 16
|
---|
184 | OPENSSL_cleanse:
|
---|
185 | xor rax,rax
|
---|
186 | cmp rdx,15
|
---|
187 | jae NEAR $L$ot
|
---|
188 | cmp rdx,0
|
---|
189 | je NEAR $L$ret
|
---|
190 | $L$ittle:
|
---|
191 | mov BYTE[rcx],al
|
---|
192 | sub rdx,1
|
---|
193 | lea rcx,[1+rcx]
|
---|
194 | jnz NEAR $L$ittle
|
---|
195 | $L$ret:
|
---|
196 | DB 0F3h,0C3h ;repret
|
---|
197 | ALIGN 16
|
---|
198 | $L$ot:
|
---|
199 | test rcx,7
|
---|
200 | jz NEAR $L$aligned
|
---|
201 | mov BYTE[rcx],al
|
---|
202 | lea rdx,[((-1))+rdx]
|
---|
203 | lea rcx,[1+rcx]
|
---|
204 | jmp NEAR $L$ot
|
---|
205 | $L$aligned:
|
---|
206 | mov QWORD[rcx],rax
|
---|
207 | lea rdx,[((-8))+rdx]
|
---|
208 | test rdx,-8
|
---|
209 | lea rcx,[8+rcx]
|
---|
210 | jnz NEAR $L$aligned
|
---|
211 | cmp rdx,0
|
---|
212 | jne NEAR $L$ittle
|
---|
213 | DB 0F3h,0C3h ;repret
|
---|
214 |
|
---|
215 |
|
---|
216 | global CRYPTO_memcmp
|
---|
217 |
|
---|
218 | ALIGN 16
|
---|
219 | CRYPTO_memcmp:
|
---|
220 | xor rax,rax
|
---|
221 | xor r10,r10
|
---|
222 | cmp r8,0
|
---|
223 | je NEAR $L$no_data
|
---|
224 | $L$oop_cmp:
|
---|
225 | mov r10b,BYTE[rcx]
|
---|
226 | lea rcx,[1+rcx]
|
---|
227 | xor r10b,BYTE[rdx]
|
---|
228 | lea rdx,[1+rdx]
|
---|
229 | or al,r10b
|
---|
230 | dec r8
|
---|
231 | jnz NEAR $L$oop_cmp
|
---|
232 | neg rax
|
---|
233 | shr rax,63
|
---|
234 | $L$no_data:
|
---|
235 | DB 0F3h,0C3h ;repret
|
---|
236 |
|
---|
237 | global OPENSSL_wipe_cpu
|
---|
238 |
|
---|
239 | ALIGN 16
|
---|
240 | OPENSSL_wipe_cpu:
|
---|
241 | pxor xmm0,xmm0
|
---|
242 | pxor xmm1,xmm1
|
---|
243 | pxor xmm2,xmm2
|
---|
244 | pxor xmm3,xmm3
|
---|
245 | pxor xmm4,xmm4
|
---|
246 | pxor xmm5,xmm5
|
---|
247 | xor rcx,rcx
|
---|
248 | xor rdx,rdx
|
---|
249 | xor r8,r8
|
---|
250 | xor r9,r9
|
---|
251 | xor r10,r10
|
---|
252 | xor r11,r11
|
---|
253 | lea rax,[8+rsp]
|
---|
254 | DB 0F3h,0C3h ;repret
|
---|
255 |
|
---|
256 | global OPENSSL_instrument_bus
|
---|
257 |
|
---|
258 | ALIGN 16
|
---|
259 | OPENSSL_instrument_bus:
|
---|
260 | mov r10,rcx
|
---|
261 | mov rcx,rdx
|
---|
262 | mov r11,rdx
|
---|
263 |
|
---|
264 | rdtsc
|
---|
265 | mov r8d,eax
|
---|
266 | mov r9d,0
|
---|
267 | clflush [r10]
|
---|
268 | DB 0xf0
|
---|
269 | add DWORD[r10],r9d
|
---|
270 | jmp NEAR $L$oop
|
---|
271 | ALIGN 16
|
---|
272 | $L$oop: rdtsc
|
---|
273 | mov edx,eax
|
---|
274 | sub eax,r8d
|
---|
275 | mov r8d,edx
|
---|
276 | mov r9d,eax
|
---|
277 | clflush [r10]
|
---|
278 | DB 0xf0
|
---|
279 | add DWORD[r10],eax
|
---|
280 | lea r10,[4+r10]
|
---|
281 | sub rcx,1
|
---|
282 | jnz NEAR $L$oop
|
---|
283 |
|
---|
284 | mov rax,r11
|
---|
285 | DB 0F3h,0C3h ;repret
|
---|
286 |
|
---|
287 |
|
---|
288 | global OPENSSL_instrument_bus2
|
---|
289 |
|
---|
290 | ALIGN 16
|
---|
291 | OPENSSL_instrument_bus2:
|
---|
292 | mov r10,rcx
|
---|
293 | mov rcx,rdx
|
---|
294 | mov r11,r8
|
---|
295 | mov QWORD[8+rsp],rcx
|
---|
296 |
|
---|
297 | rdtsc
|
---|
298 | mov r8d,eax
|
---|
299 | mov r9d,0
|
---|
300 |
|
---|
301 | clflush [r10]
|
---|
302 | DB 0xf0
|
---|
303 | add DWORD[r10],r9d
|
---|
304 |
|
---|
305 | rdtsc
|
---|
306 | mov edx,eax
|
---|
307 | sub eax,r8d
|
---|
308 | mov r8d,edx
|
---|
309 | mov r9d,eax
|
---|
310 | $L$oop2:
|
---|
311 | clflush [r10]
|
---|
312 | DB 0xf0
|
---|
313 | add DWORD[r10],eax
|
---|
314 |
|
---|
315 | sub r11,1
|
---|
316 | jz NEAR $L$done2
|
---|
317 |
|
---|
318 | rdtsc
|
---|
319 | mov edx,eax
|
---|
320 | sub eax,r8d
|
---|
321 | mov r8d,edx
|
---|
322 | cmp eax,r9d
|
---|
323 | mov r9d,eax
|
---|
324 | mov edx,0
|
---|
325 | setne dl
|
---|
326 | sub rcx,rdx
|
---|
327 | lea r10,[rdx*4+r10]
|
---|
328 | jnz NEAR $L$oop2
|
---|
329 |
|
---|
330 | $L$done2:
|
---|
331 | mov rax,QWORD[8+rsp]
|
---|
332 | sub rax,rcx
|
---|
333 | DB 0F3h,0C3h ;repret
|
---|
334 |
|
---|
335 | global OPENSSL_ia32_rdrand
|
---|
336 |
|
---|
337 | ALIGN 16
|
---|
338 | OPENSSL_ia32_rdrand:
|
---|
339 | mov ecx,8
|
---|
340 | $L$oop_rdrand:
|
---|
341 | DB 72,15,199,240
|
---|
342 | jc NEAR $L$break_rdrand
|
---|
343 | loop $L$oop_rdrand
|
---|
344 | $L$break_rdrand:
|
---|
345 | cmp rax,0
|
---|
346 | cmove rax,rcx
|
---|
347 | DB 0F3h,0C3h ;repret
|
---|
348 |
|
---|
349 |
|
---|
350 | global OPENSSL_ia32_rdrand_bytes
|
---|
351 |
|
---|
352 | ALIGN 16
|
---|
353 | OPENSSL_ia32_rdrand_bytes:
|
---|
354 | xor rax,rax
|
---|
355 | cmp rdx,0
|
---|
356 | je NEAR $L$done_rdrand_bytes
|
---|
357 |
|
---|
358 | mov r11,8
|
---|
359 | $L$oop_rdrand_bytes:
|
---|
360 | DB 73,15,199,242
|
---|
361 | jc NEAR $L$break_rdrand_bytes
|
---|
362 | dec r11
|
---|
363 | jnz NEAR $L$oop_rdrand_bytes
|
---|
364 | jmp NEAR $L$done_rdrand_bytes
|
---|
365 |
|
---|
366 | ALIGN 16
|
---|
367 | $L$break_rdrand_bytes:
|
---|
368 | cmp rdx,8
|
---|
369 | jb NEAR $L$tail_rdrand_bytes
|
---|
370 | mov QWORD[rcx],r10
|
---|
371 | lea rcx,[8+rcx]
|
---|
372 | add rax,8
|
---|
373 | sub rdx,8
|
---|
374 | jz NEAR $L$done_rdrand_bytes
|
---|
375 | mov r11,8
|
---|
376 | jmp NEAR $L$oop_rdrand_bytes
|
---|
377 |
|
---|
378 | ALIGN 16
|
---|
379 | $L$tail_rdrand_bytes:
|
---|
380 | mov BYTE[rcx],r10b
|
---|
381 | lea rcx,[1+rcx]
|
---|
382 | inc rax
|
---|
383 | shr r8,8
|
---|
384 | dec rdx
|
---|
385 | jnz NEAR $L$tail_rdrand_bytes
|
---|
386 |
|
---|
387 | $L$done_rdrand_bytes:
|
---|
388 | DB 0F3h,0C3h ;repret
|
---|
389 |
|
---|
390 | global OPENSSL_ia32_rdseed
|
---|
391 |
|
---|
392 | ALIGN 16
|
---|
393 | OPENSSL_ia32_rdseed:
|
---|
394 | mov ecx,8
|
---|
395 | $L$oop_rdseed:
|
---|
396 | DB 72,15,199,248
|
---|
397 | jc NEAR $L$break_rdseed
|
---|
398 | loop $L$oop_rdseed
|
---|
399 | $L$break_rdseed:
|
---|
400 | cmp rax,0
|
---|
401 | cmove rax,rcx
|
---|
402 | DB 0F3h,0C3h ;repret
|
---|
403 |
|
---|
404 |
|
---|
405 | global OPENSSL_ia32_rdseed_bytes
|
---|
406 |
|
---|
407 | ALIGN 16
|
---|
408 | OPENSSL_ia32_rdseed_bytes:
|
---|
409 | xor rax,rax
|
---|
410 | cmp rdx,0
|
---|
411 | je NEAR $L$done_rdseed_bytes
|
---|
412 |
|
---|
413 | mov r11,8
|
---|
414 | $L$oop_rdseed_bytes:
|
---|
415 | DB 73,15,199,250
|
---|
416 | jc NEAR $L$break_rdseed_bytes
|
---|
417 | dec r11
|
---|
418 | jnz NEAR $L$oop_rdseed_bytes
|
---|
419 | jmp NEAR $L$done_rdseed_bytes
|
---|
420 |
|
---|
421 | ALIGN 16
|
---|
422 | $L$break_rdseed_bytes:
|
---|
423 | cmp rdx,8
|
---|
424 | jb NEAR $L$tail_rdseed_bytes
|
---|
425 | mov QWORD[rcx],r10
|
---|
426 | lea rcx,[8+rcx]
|
---|
427 | add rax,8
|
---|
428 | sub rdx,8
|
---|
429 | jz NEAR $L$done_rdseed_bytes
|
---|
430 | mov r11,8
|
---|
431 | jmp NEAR $L$oop_rdseed_bytes
|
---|
432 |
|
---|
433 | ALIGN 16
|
---|
434 | $L$tail_rdseed_bytes:
|
---|
435 | mov BYTE[rcx],r10b
|
---|
436 | lea rcx,[1+rcx]
|
---|
437 | inc rax
|
---|
438 | shr r8,8
|
---|
439 | dec rdx
|
---|
440 | jnz NEAR $L$tail_rdseed_bytes
|
---|
441 |
|
---|
442 | $L$done_rdseed_bytes:
|
---|
443 | DB 0F3h,0C3h ;repret
|
---|
444 |
|
---|