xref: /aosp_15_r20/external/boringssl/src/gen/bcm/aesni-x86_64-win.asm (revision 8fb009dc861624b67b6cdb62ea21f0f22d0c584b)
1; This file is generated from a similarly-named Perl script in the BoringSSL
2; source tree. Do not edit by hand.
3
4%ifidn __OUTPUT_FORMAT__, win64
5default	rel
6%define XMMWORD
7%define YMMWORD
8%define ZMMWORD
9%define _CET_ENDBR
10
11%ifdef BORINGSSL_PREFIX
12%include "boringssl_prefix_symbols_nasm.inc"
13%endif
14section	.text code align=64
15
16global	aes_hw_encrypt
17
18ALIGN	16
19aes_hw_encrypt:
20
21_CET_ENDBR
22%ifdef BORINGSSL_DISPATCH_TEST
23EXTERN	BORINGSSL_function_hit
24	mov	BYTE[((BORINGSSL_function_hit+1))],1
25%endif
26	movups	xmm2,XMMWORD[rcx]
27	mov	eax,DWORD[240+r8]
28	movups	xmm0,XMMWORD[r8]
29	movups	xmm1,XMMWORD[16+r8]
30	lea	r8,[32+r8]
31	xorps	xmm2,xmm0
32$L$oop_enc1_1:
33	DB	102,15,56,220,209
34	dec	eax
35	movups	xmm1,XMMWORD[r8]
36	lea	r8,[16+r8]
37	jnz	NEAR $L$oop_enc1_1
38	DB	102,15,56,221,209
39	pxor	xmm0,xmm0
40	pxor	xmm1,xmm1
41	movups	XMMWORD[rdx],xmm2
42	pxor	xmm2,xmm2
43	ret
44
45
46
47global	aes_hw_decrypt
48
49ALIGN	16
50aes_hw_decrypt:
51
52_CET_ENDBR
53	movups	xmm2,XMMWORD[rcx]
54	mov	eax,DWORD[240+r8]
55	movups	xmm0,XMMWORD[r8]
56	movups	xmm1,XMMWORD[16+r8]
57	lea	r8,[32+r8]
58	xorps	xmm2,xmm0
59$L$oop_dec1_2:
60	DB	102,15,56,222,209
61	dec	eax
62	movups	xmm1,XMMWORD[r8]
63	lea	r8,[16+r8]
64	jnz	NEAR $L$oop_dec1_2
65	DB	102,15,56,223,209
66	pxor	xmm0,xmm0
67	pxor	xmm1,xmm1
68	movups	XMMWORD[rdx],xmm2
69	pxor	xmm2,xmm2
70	ret
71
72
73
74ALIGN	16
75_aesni_encrypt2:
76
77	movups	xmm0,XMMWORD[rcx]
78	shl	eax,4
79	movups	xmm1,XMMWORD[16+rcx]
80	xorps	xmm2,xmm0
81	xorps	xmm3,xmm0
82	movups	xmm0,XMMWORD[32+rcx]
83	lea	rcx,[32+rax*1+rcx]
84	neg	rax
85	add	rax,16
86
87$L$enc_loop2:
88	DB	102,15,56,220,209
89	DB	102,15,56,220,217
90	movups	xmm1,XMMWORD[rax*1+rcx]
91	add	rax,32
92	DB	102,15,56,220,208
93	DB	102,15,56,220,216
94	movups	xmm0,XMMWORD[((-16))+rax*1+rcx]
95	jnz	NEAR $L$enc_loop2
96
97	DB	102,15,56,220,209
98	DB	102,15,56,220,217
99	DB	102,15,56,221,208
100	DB	102,15,56,221,216
101	ret
102
103
104
105ALIGN	16
106_aesni_decrypt2:
107
108	movups	xmm0,XMMWORD[rcx]
109	shl	eax,4
110	movups	xmm1,XMMWORD[16+rcx]
111	xorps	xmm2,xmm0
112	xorps	xmm3,xmm0
113	movups	xmm0,XMMWORD[32+rcx]
114	lea	rcx,[32+rax*1+rcx]
115	neg	rax
116	add	rax,16
117
118$L$dec_loop2:
119	DB	102,15,56,222,209
120	DB	102,15,56,222,217
121	movups	xmm1,XMMWORD[rax*1+rcx]
122	add	rax,32
123	DB	102,15,56,222,208
124	DB	102,15,56,222,216
125	movups	xmm0,XMMWORD[((-16))+rax*1+rcx]
126	jnz	NEAR $L$dec_loop2
127
128	DB	102,15,56,222,209
129	DB	102,15,56,222,217
130	DB	102,15,56,223,208
131	DB	102,15,56,223,216
132	ret
133
134
135
136ALIGN	16
137_aesni_encrypt3:
138
139	movups	xmm0,XMMWORD[rcx]
140	shl	eax,4
141	movups	xmm1,XMMWORD[16+rcx]
142	xorps	xmm2,xmm0
143	xorps	xmm3,xmm0
144	xorps	xmm4,xmm0
145	movups	xmm0,XMMWORD[32+rcx]
146	lea	rcx,[32+rax*1+rcx]
147	neg	rax
148	add	rax,16
149
150$L$enc_loop3:
151	DB	102,15,56,220,209
152	DB	102,15,56,220,217
153	DB	102,15,56,220,225
154	movups	xmm1,XMMWORD[rax*1+rcx]
155	add	rax,32
156	DB	102,15,56,220,208
157	DB	102,15,56,220,216
158	DB	102,15,56,220,224
159	movups	xmm0,XMMWORD[((-16))+rax*1+rcx]
160	jnz	NEAR $L$enc_loop3
161
162	DB	102,15,56,220,209
163	DB	102,15,56,220,217
164	DB	102,15,56,220,225
165	DB	102,15,56,221,208
166	DB	102,15,56,221,216
167	DB	102,15,56,221,224
168	ret
169
170
171
172ALIGN	16
173_aesni_decrypt3:
174
175	movups	xmm0,XMMWORD[rcx]
176	shl	eax,4
177	movups	xmm1,XMMWORD[16+rcx]
178	xorps	xmm2,xmm0
179	xorps	xmm3,xmm0
180	xorps	xmm4,xmm0
181	movups	xmm0,XMMWORD[32+rcx]
182	lea	rcx,[32+rax*1+rcx]
183	neg	rax
184	add	rax,16
185
186$L$dec_loop3:
187	DB	102,15,56,222,209
188	DB	102,15,56,222,217
189	DB	102,15,56,222,225
190	movups	xmm1,XMMWORD[rax*1+rcx]
191	add	rax,32
192	DB	102,15,56,222,208
193	DB	102,15,56,222,216
194	DB	102,15,56,222,224
195	movups	xmm0,XMMWORD[((-16))+rax*1+rcx]
196	jnz	NEAR $L$dec_loop3
197
198	DB	102,15,56,222,209
199	DB	102,15,56,222,217
200	DB	102,15,56,222,225
201	DB	102,15,56,223,208
202	DB	102,15,56,223,216
203	DB	102,15,56,223,224
204	ret
205
206
207
208ALIGN	16
209_aesni_encrypt4:
210
211	movups	xmm0,XMMWORD[rcx]
212	shl	eax,4
213	movups	xmm1,XMMWORD[16+rcx]
214	xorps	xmm2,xmm0
215	xorps	xmm3,xmm0
216	xorps	xmm4,xmm0
217	xorps	xmm5,xmm0
218	movups	xmm0,XMMWORD[32+rcx]
219	lea	rcx,[32+rax*1+rcx]
220	neg	rax
221	DB	0x0f,0x1f,0x00
222	add	rax,16
223
224$L$enc_loop4:
225	DB	102,15,56,220,209
226	DB	102,15,56,220,217
227	DB	102,15,56,220,225
228	DB	102,15,56,220,233
229	movups	xmm1,XMMWORD[rax*1+rcx]
230	add	rax,32
231	DB	102,15,56,220,208
232	DB	102,15,56,220,216
233	DB	102,15,56,220,224
234	DB	102,15,56,220,232
235	movups	xmm0,XMMWORD[((-16))+rax*1+rcx]
236	jnz	NEAR $L$enc_loop4
237
238	DB	102,15,56,220,209
239	DB	102,15,56,220,217
240	DB	102,15,56,220,225
241	DB	102,15,56,220,233
242	DB	102,15,56,221,208
243	DB	102,15,56,221,216
244	DB	102,15,56,221,224
245	DB	102,15,56,221,232
246	ret
247
248
249
250ALIGN	16
251_aesni_decrypt4:
252
253	movups	xmm0,XMMWORD[rcx]
254	shl	eax,4
255	movups	xmm1,XMMWORD[16+rcx]
256	xorps	xmm2,xmm0
257	xorps	xmm3,xmm0
258	xorps	xmm4,xmm0
259	xorps	xmm5,xmm0
260	movups	xmm0,XMMWORD[32+rcx]
261	lea	rcx,[32+rax*1+rcx]
262	neg	rax
263	DB	0x0f,0x1f,0x00
264	add	rax,16
265
266$L$dec_loop4:
267	DB	102,15,56,222,209
268	DB	102,15,56,222,217
269	DB	102,15,56,222,225
270	DB	102,15,56,222,233
271	movups	xmm1,XMMWORD[rax*1+rcx]
272	add	rax,32
273	DB	102,15,56,222,208
274	DB	102,15,56,222,216
275	DB	102,15,56,222,224
276	DB	102,15,56,222,232
277	movups	xmm0,XMMWORD[((-16))+rax*1+rcx]
278	jnz	NEAR $L$dec_loop4
279
280	DB	102,15,56,222,209
281	DB	102,15,56,222,217
282	DB	102,15,56,222,225
283	DB	102,15,56,222,233
284	DB	102,15,56,223,208
285	DB	102,15,56,223,216
286	DB	102,15,56,223,224
287	DB	102,15,56,223,232
288	ret
289
290
291
292ALIGN	16
293_aesni_encrypt6:
294
295	movups	xmm0,XMMWORD[rcx]
296	shl	eax,4
297	movups	xmm1,XMMWORD[16+rcx]
298	xorps	xmm2,xmm0
299	pxor	xmm3,xmm0
300	pxor	xmm4,xmm0
301	DB	102,15,56,220,209
302	lea	rcx,[32+rax*1+rcx]
303	neg	rax
304	DB	102,15,56,220,217
305	pxor	xmm5,xmm0
306	pxor	xmm6,xmm0
307	DB	102,15,56,220,225
308	pxor	xmm7,xmm0
309	movups	xmm0,XMMWORD[rax*1+rcx]
310	add	rax,16
311	jmp	NEAR $L$enc_loop6_enter
312ALIGN	16
313$L$enc_loop6:
314	DB	102,15,56,220,209
315	DB	102,15,56,220,217
316	DB	102,15,56,220,225
317$L$enc_loop6_enter:
318	DB	102,15,56,220,233
319	DB	102,15,56,220,241
320	DB	102,15,56,220,249
321	movups	xmm1,XMMWORD[rax*1+rcx]
322	add	rax,32
323	DB	102,15,56,220,208
324	DB	102,15,56,220,216
325	DB	102,15,56,220,224
326	DB	102,15,56,220,232
327	DB	102,15,56,220,240
328	DB	102,15,56,220,248
329	movups	xmm0,XMMWORD[((-16))+rax*1+rcx]
330	jnz	NEAR $L$enc_loop6
331
332	DB	102,15,56,220,209
333	DB	102,15,56,220,217
334	DB	102,15,56,220,225
335	DB	102,15,56,220,233
336	DB	102,15,56,220,241
337	DB	102,15,56,220,249
338	DB	102,15,56,221,208
339	DB	102,15,56,221,216
340	DB	102,15,56,221,224
341	DB	102,15,56,221,232
342	DB	102,15,56,221,240
343	DB	102,15,56,221,248
344	ret
345
346
347
348ALIGN	16
349_aesni_decrypt6:
350
351	movups	xmm0,XMMWORD[rcx]
352	shl	eax,4
353	movups	xmm1,XMMWORD[16+rcx]
354	xorps	xmm2,xmm0
355	pxor	xmm3,xmm0
356	pxor	xmm4,xmm0
357	DB	102,15,56,222,209
358	lea	rcx,[32+rax*1+rcx]
359	neg	rax
360	DB	102,15,56,222,217
361	pxor	xmm5,xmm0
362	pxor	xmm6,xmm0
363	DB	102,15,56,222,225
364	pxor	xmm7,xmm0
365	movups	xmm0,XMMWORD[rax*1+rcx]
366	add	rax,16
367	jmp	NEAR $L$dec_loop6_enter
368ALIGN	16
369$L$dec_loop6:
370	DB	102,15,56,222,209
371	DB	102,15,56,222,217
372	DB	102,15,56,222,225
373$L$dec_loop6_enter:
374	DB	102,15,56,222,233
375	DB	102,15,56,222,241
376	DB	102,15,56,222,249
377	movups	xmm1,XMMWORD[rax*1+rcx]
378	add	rax,32
379	DB	102,15,56,222,208
380	DB	102,15,56,222,216
381	DB	102,15,56,222,224
382	DB	102,15,56,222,232
383	DB	102,15,56,222,240
384	DB	102,15,56,222,248
385	movups	xmm0,XMMWORD[((-16))+rax*1+rcx]
386	jnz	NEAR $L$dec_loop6
387
388	DB	102,15,56,222,209
389	DB	102,15,56,222,217
390	DB	102,15,56,222,225
391	DB	102,15,56,222,233
392	DB	102,15,56,222,241
393	DB	102,15,56,222,249
394	DB	102,15,56,223,208
395	DB	102,15,56,223,216
396	DB	102,15,56,223,224
397	DB	102,15,56,223,232
398	DB	102,15,56,223,240
399	DB	102,15,56,223,248
400	ret
401
402
403
404ALIGN	16
405_aesni_encrypt8:
406
407	movups	xmm0,XMMWORD[rcx]
408	shl	eax,4
409	movups	xmm1,XMMWORD[16+rcx]
410	xorps	xmm2,xmm0
411	xorps	xmm3,xmm0
412	pxor	xmm4,xmm0
413	pxor	xmm5,xmm0
414	pxor	xmm6,xmm0
415	lea	rcx,[32+rax*1+rcx]
416	neg	rax
417	DB	102,15,56,220,209
418	pxor	xmm7,xmm0
419	pxor	xmm8,xmm0
420	DB	102,15,56,220,217
421	pxor	xmm9,xmm0
422	movups	xmm0,XMMWORD[rax*1+rcx]
423	add	rax,16
424	jmp	NEAR $L$enc_loop8_inner
425ALIGN	16
426$L$enc_loop8:
427	DB	102,15,56,220,209
428	DB	102,15,56,220,217
429$L$enc_loop8_inner:
430	DB	102,15,56,220,225
431	DB	102,15,56,220,233
432	DB	102,15,56,220,241
433	DB	102,15,56,220,249
434	DB	102,68,15,56,220,193
435	DB	102,68,15,56,220,201
436$L$enc_loop8_enter:
437	movups	xmm1,XMMWORD[rax*1+rcx]
438	add	rax,32
439	DB	102,15,56,220,208
440	DB	102,15,56,220,216
441	DB	102,15,56,220,224
442	DB	102,15,56,220,232
443	DB	102,15,56,220,240
444	DB	102,15,56,220,248
445	DB	102,68,15,56,220,192
446	DB	102,68,15,56,220,200
447	movups	xmm0,XMMWORD[((-16))+rax*1+rcx]
448	jnz	NEAR $L$enc_loop8
449
450	DB	102,15,56,220,209
451	DB	102,15,56,220,217
452	DB	102,15,56,220,225
453	DB	102,15,56,220,233
454	DB	102,15,56,220,241
455	DB	102,15,56,220,249
456	DB	102,68,15,56,220,193
457	DB	102,68,15,56,220,201
458	DB	102,15,56,221,208
459	DB	102,15,56,221,216
460	DB	102,15,56,221,224
461	DB	102,15,56,221,232
462	DB	102,15,56,221,240
463	DB	102,15,56,221,248
464	DB	102,68,15,56,221,192
465	DB	102,68,15,56,221,200
466	ret
467
468
469
470ALIGN	16
471_aesni_decrypt8:
472
473	movups	xmm0,XMMWORD[rcx]
474	shl	eax,4
475	movups	xmm1,XMMWORD[16+rcx]
476	xorps	xmm2,xmm0
477	xorps	xmm3,xmm0
478	pxor	xmm4,xmm0
479	pxor	xmm5,xmm0
480	pxor	xmm6,xmm0
481	lea	rcx,[32+rax*1+rcx]
482	neg	rax
483	DB	102,15,56,222,209
484	pxor	xmm7,xmm0
485	pxor	xmm8,xmm0
486	DB	102,15,56,222,217
487	pxor	xmm9,xmm0
488	movups	xmm0,XMMWORD[rax*1+rcx]
489	add	rax,16
490	jmp	NEAR $L$dec_loop8_inner
491ALIGN	16
492$L$dec_loop8:
493	DB	102,15,56,222,209
494	DB	102,15,56,222,217
495$L$dec_loop8_inner:
496	DB	102,15,56,222,225
497	DB	102,15,56,222,233
498	DB	102,15,56,222,241
499	DB	102,15,56,222,249
500	DB	102,68,15,56,222,193
501	DB	102,68,15,56,222,201
502$L$dec_loop8_enter:
503	movups	xmm1,XMMWORD[rax*1+rcx]
504	add	rax,32
505	DB	102,15,56,222,208
506	DB	102,15,56,222,216
507	DB	102,15,56,222,224
508	DB	102,15,56,222,232
509	DB	102,15,56,222,240
510	DB	102,15,56,222,248
511	DB	102,68,15,56,222,192
512	DB	102,68,15,56,222,200
513	movups	xmm0,XMMWORD[((-16))+rax*1+rcx]
514	jnz	NEAR $L$dec_loop8
515
516	DB	102,15,56,222,209
517	DB	102,15,56,222,217
518	DB	102,15,56,222,225
519	DB	102,15,56,222,233
520	DB	102,15,56,222,241
521	DB	102,15,56,222,249
522	DB	102,68,15,56,222,193
523	DB	102,68,15,56,222,201
524	DB	102,15,56,223,208
525	DB	102,15,56,223,216
526	DB	102,15,56,223,224
527	DB	102,15,56,223,232
528	DB	102,15,56,223,240
529	DB	102,15,56,223,248
530	DB	102,68,15,56,223,192
531	DB	102,68,15,56,223,200
532	ret
533
534
535global	aes_hw_ecb_encrypt
536
537ALIGN	16
538aes_hw_ecb_encrypt:
539	mov	QWORD[8+rsp],rdi	;WIN64 prologue
540	mov	QWORD[16+rsp],rsi
541	mov	rax,rsp
542$L$SEH_begin_aes_hw_ecb_encrypt:
543	mov	rdi,rcx
544	mov	rsi,rdx
545	mov	rdx,r8
546	mov	rcx,r9
547	mov	r8,QWORD[40+rsp]
548
549
550
551_CET_ENDBR
552	lea	rsp,[((-88))+rsp]
553	movaps	XMMWORD[rsp],xmm6
554	movaps	XMMWORD[16+rsp],xmm7
555	movaps	XMMWORD[32+rsp],xmm8
556	movaps	XMMWORD[48+rsp],xmm9
557$L$ecb_enc_body:
558	and	rdx,-16
559	jz	NEAR $L$ecb_ret
560
561	mov	eax,DWORD[240+rcx]
562	movups	xmm0,XMMWORD[rcx]
563	mov	r11,rcx
564	mov	r10d,eax
565	test	r8d,r8d
566	jz	NEAR $L$ecb_decrypt
567
568	cmp	rdx,0x80
569	jb	NEAR $L$ecb_enc_tail
570
571	movdqu	xmm2,XMMWORD[rdi]
572	movdqu	xmm3,XMMWORD[16+rdi]
573	movdqu	xmm4,XMMWORD[32+rdi]
574	movdqu	xmm5,XMMWORD[48+rdi]
575	movdqu	xmm6,XMMWORD[64+rdi]
576	movdqu	xmm7,XMMWORD[80+rdi]
577	movdqu	xmm8,XMMWORD[96+rdi]
578	movdqu	xmm9,XMMWORD[112+rdi]
579	lea	rdi,[128+rdi]
580	sub	rdx,0x80
581	jmp	NEAR $L$ecb_enc_loop8_enter
582ALIGN	16
583$L$ecb_enc_loop8:
584	movups	XMMWORD[rsi],xmm2
585	mov	rcx,r11
586	movdqu	xmm2,XMMWORD[rdi]
587	mov	eax,r10d
588	movups	XMMWORD[16+rsi],xmm3
589	movdqu	xmm3,XMMWORD[16+rdi]
590	movups	XMMWORD[32+rsi],xmm4
591	movdqu	xmm4,XMMWORD[32+rdi]
592	movups	XMMWORD[48+rsi],xmm5
593	movdqu	xmm5,XMMWORD[48+rdi]
594	movups	XMMWORD[64+rsi],xmm6
595	movdqu	xmm6,XMMWORD[64+rdi]
596	movups	XMMWORD[80+rsi],xmm7
597	movdqu	xmm7,XMMWORD[80+rdi]
598	movups	XMMWORD[96+rsi],xmm8
599	movdqu	xmm8,XMMWORD[96+rdi]
600	movups	XMMWORD[112+rsi],xmm9
601	lea	rsi,[128+rsi]
602	movdqu	xmm9,XMMWORD[112+rdi]
603	lea	rdi,[128+rdi]
604$L$ecb_enc_loop8_enter:
605
606	call	_aesni_encrypt8
607
608	sub	rdx,0x80
609	jnc	NEAR $L$ecb_enc_loop8
610
611	movups	XMMWORD[rsi],xmm2
612	mov	rcx,r11
613	movups	XMMWORD[16+rsi],xmm3
614	mov	eax,r10d
615	movups	XMMWORD[32+rsi],xmm4
616	movups	XMMWORD[48+rsi],xmm5
617	movups	XMMWORD[64+rsi],xmm6
618	movups	XMMWORD[80+rsi],xmm7
619	movups	XMMWORD[96+rsi],xmm8
620	movups	XMMWORD[112+rsi],xmm9
621	lea	rsi,[128+rsi]
622	add	rdx,0x80
623	jz	NEAR $L$ecb_ret
624
625$L$ecb_enc_tail:
626	movups	xmm2,XMMWORD[rdi]
627	cmp	rdx,0x20
628	jb	NEAR $L$ecb_enc_one
629	movups	xmm3,XMMWORD[16+rdi]
630	je	NEAR $L$ecb_enc_two
631	movups	xmm4,XMMWORD[32+rdi]
632	cmp	rdx,0x40
633	jb	NEAR $L$ecb_enc_three
634	movups	xmm5,XMMWORD[48+rdi]
635	je	NEAR $L$ecb_enc_four
636	movups	xmm6,XMMWORD[64+rdi]
637	cmp	rdx,0x60
638	jb	NEAR $L$ecb_enc_five
639	movups	xmm7,XMMWORD[80+rdi]
640	je	NEAR $L$ecb_enc_six
641	movdqu	xmm8,XMMWORD[96+rdi]
642	xorps	xmm9,xmm9
643	call	_aesni_encrypt8
644	movups	XMMWORD[rsi],xmm2
645	movups	XMMWORD[16+rsi],xmm3
646	movups	XMMWORD[32+rsi],xmm4
647	movups	XMMWORD[48+rsi],xmm5
648	movups	XMMWORD[64+rsi],xmm6
649	movups	XMMWORD[80+rsi],xmm7
650	movups	XMMWORD[96+rsi],xmm8
651	jmp	NEAR $L$ecb_ret
652ALIGN	16
653$L$ecb_enc_one:
654	movups	xmm0,XMMWORD[rcx]
655	movups	xmm1,XMMWORD[16+rcx]
656	lea	rcx,[32+rcx]
657	xorps	xmm2,xmm0
658$L$oop_enc1_3:
659	DB	102,15,56,220,209
660	dec	eax
661	movups	xmm1,XMMWORD[rcx]
662	lea	rcx,[16+rcx]
663	jnz	NEAR $L$oop_enc1_3
664	DB	102,15,56,221,209
665	movups	XMMWORD[rsi],xmm2
666	jmp	NEAR $L$ecb_ret
667ALIGN	16
668$L$ecb_enc_two:
669	call	_aesni_encrypt2
670	movups	XMMWORD[rsi],xmm2
671	movups	XMMWORD[16+rsi],xmm3
672	jmp	NEAR $L$ecb_ret
673ALIGN	16
674$L$ecb_enc_three:
675	call	_aesni_encrypt3
676	movups	XMMWORD[rsi],xmm2
677	movups	XMMWORD[16+rsi],xmm3
678	movups	XMMWORD[32+rsi],xmm4
679	jmp	NEAR $L$ecb_ret
680ALIGN	16
681$L$ecb_enc_four:
682	call	_aesni_encrypt4
683	movups	XMMWORD[rsi],xmm2
684	movups	XMMWORD[16+rsi],xmm3
685	movups	XMMWORD[32+rsi],xmm4
686	movups	XMMWORD[48+rsi],xmm5
687	jmp	NEAR $L$ecb_ret
688ALIGN	16
689$L$ecb_enc_five:
690	xorps	xmm7,xmm7
691	call	_aesni_encrypt6
692	movups	XMMWORD[rsi],xmm2
693	movups	XMMWORD[16+rsi],xmm3
694	movups	XMMWORD[32+rsi],xmm4
695	movups	XMMWORD[48+rsi],xmm5
696	movups	XMMWORD[64+rsi],xmm6
697	jmp	NEAR $L$ecb_ret
698ALIGN	16
699$L$ecb_enc_six:
700	call	_aesni_encrypt6
701	movups	XMMWORD[rsi],xmm2
702	movups	XMMWORD[16+rsi],xmm3
703	movups	XMMWORD[32+rsi],xmm4
704	movups	XMMWORD[48+rsi],xmm5
705	movups	XMMWORD[64+rsi],xmm6
706	movups	XMMWORD[80+rsi],xmm7
707	jmp	NEAR $L$ecb_ret
708
709ALIGN	16
710$L$ecb_decrypt:
711	cmp	rdx,0x80
712	jb	NEAR $L$ecb_dec_tail
713
714	movdqu	xmm2,XMMWORD[rdi]
715	movdqu	xmm3,XMMWORD[16+rdi]
716	movdqu	xmm4,XMMWORD[32+rdi]
717	movdqu	xmm5,XMMWORD[48+rdi]
718	movdqu	xmm6,XMMWORD[64+rdi]
719	movdqu	xmm7,XMMWORD[80+rdi]
720	movdqu	xmm8,XMMWORD[96+rdi]
721	movdqu	xmm9,XMMWORD[112+rdi]
722	lea	rdi,[128+rdi]
723	sub	rdx,0x80
724	jmp	NEAR $L$ecb_dec_loop8_enter
725ALIGN	16
726$L$ecb_dec_loop8:
727	movups	XMMWORD[rsi],xmm2
728	mov	rcx,r11
729	movdqu	xmm2,XMMWORD[rdi]
730	mov	eax,r10d
731	movups	XMMWORD[16+rsi],xmm3
732	movdqu	xmm3,XMMWORD[16+rdi]
733	movups	XMMWORD[32+rsi],xmm4
734	movdqu	xmm4,XMMWORD[32+rdi]
735	movups	XMMWORD[48+rsi],xmm5
736	movdqu	xmm5,XMMWORD[48+rdi]
737	movups	XMMWORD[64+rsi],xmm6
738	movdqu	xmm6,XMMWORD[64+rdi]
739	movups	XMMWORD[80+rsi],xmm7
740	movdqu	xmm7,XMMWORD[80+rdi]
741	movups	XMMWORD[96+rsi],xmm8
742	movdqu	xmm8,XMMWORD[96+rdi]
743	movups	XMMWORD[112+rsi],xmm9
744	lea	rsi,[128+rsi]
745	movdqu	xmm9,XMMWORD[112+rdi]
746	lea	rdi,[128+rdi]
747$L$ecb_dec_loop8_enter:
748
749	call	_aesni_decrypt8
750
751	movups	xmm0,XMMWORD[r11]
752	sub	rdx,0x80
753	jnc	NEAR $L$ecb_dec_loop8
754
755	movups	XMMWORD[rsi],xmm2
756	pxor	xmm2,xmm2
757	mov	rcx,r11
758	movups	XMMWORD[16+rsi],xmm3
759	pxor	xmm3,xmm3
760	mov	eax,r10d
761	movups	XMMWORD[32+rsi],xmm4
762	pxor	xmm4,xmm4
763	movups	XMMWORD[48+rsi],xmm5
764	pxor	xmm5,xmm5
765	movups	XMMWORD[64+rsi],xmm6
766	pxor	xmm6,xmm6
767	movups	XMMWORD[80+rsi],xmm7
768	pxor	xmm7,xmm7
769	movups	XMMWORD[96+rsi],xmm8
770	pxor	xmm8,xmm8
771	movups	XMMWORD[112+rsi],xmm9
772	pxor	xmm9,xmm9
773	lea	rsi,[128+rsi]
774	add	rdx,0x80
775	jz	NEAR $L$ecb_ret
776
777$L$ecb_dec_tail:
778	movups	xmm2,XMMWORD[rdi]
779	cmp	rdx,0x20
780	jb	NEAR $L$ecb_dec_one
781	movups	xmm3,XMMWORD[16+rdi]
782	je	NEAR $L$ecb_dec_two
783	movups	xmm4,XMMWORD[32+rdi]
784	cmp	rdx,0x40
785	jb	NEAR $L$ecb_dec_three
786	movups	xmm5,XMMWORD[48+rdi]
787	je	NEAR $L$ecb_dec_four
788	movups	xmm6,XMMWORD[64+rdi]
789	cmp	rdx,0x60
790	jb	NEAR $L$ecb_dec_five
791	movups	xmm7,XMMWORD[80+rdi]
792	je	NEAR $L$ecb_dec_six
793	movups	xmm8,XMMWORD[96+rdi]
794	movups	xmm0,XMMWORD[rcx]
795	xorps	xmm9,xmm9
796	call	_aesni_decrypt8
797	movups	XMMWORD[rsi],xmm2
798	pxor	xmm2,xmm2
799	movups	XMMWORD[16+rsi],xmm3
800	pxor	xmm3,xmm3
801	movups	XMMWORD[32+rsi],xmm4
802	pxor	xmm4,xmm4
803	movups	XMMWORD[48+rsi],xmm5
804	pxor	xmm5,xmm5
805	movups	XMMWORD[64+rsi],xmm6
806	pxor	xmm6,xmm6
807	movups	XMMWORD[80+rsi],xmm7
808	pxor	xmm7,xmm7
809	movups	XMMWORD[96+rsi],xmm8
810	pxor	xmm8,xmm8
811	pxor	xmm9,xmm9
812	jmp	NEAR $L$ecb_ret
813ALIGN	16
814$L$ecb_dec_one:
815	movups	xmm0,XMMWORD[rcx]
816	movups	xmm1,XMMWORD[16+rcx]
817	lea	rcx,[32+rcx]
818	xorps	xmm2,xmm0
819$L$oop_dec1_4:
820	DB	102,15,56,222,209
821	dec	eax
822	movups	xmm1,XMMWORD[rcx]
823	lea	rcx,[16+rcx]
824	jnz	NEAR $L$oop_dec1_4
825	DB	102,15,56,223,209
826	movups	XMMWORD[rsi],xmm2
827	pxor	xmm2,xmm2
828	jmp	NEAR $L$ecb_ret
829ALIGN	16
830$L$ecb_dec_two:
831	call	_aesni_decrypt2
832	movups	XMMWORD[rsi],xmm2
833	pxor	xmm2,xmm2
834	movups	XMMWORD[16+rsi],xmm3
835	pxor	xmm3,xmm3
836	jmp	NEAR $L$ecb_ret
837ALIGN	16
838$L$ecb_dec_three:
839	call	_aesni_decrypt3
840	movups	XMMWORD[rsi],xmm2
841	pxor	xmm2,xmm2
842	movups	XMMWORD[16+rsi],xmm3
843	pxor	xmm3,xmm3
844	movups	XMMWORD[32+rsi],xmm4
845	pxor	xmm4,xmm4
846	jmp	NEAR $L$ecb_ret
847ALIGN	16
848$L$ecb_dec_four:
849	call	_aesni_decrypt4
850	movups	XMMWORD[rsi],xmm2
851	pxor	xmm2,xmm2
852	movups	XMMWORD[16+rsi],xmm3
853	pxor	xmm3,xmm3
854	movups	XMMWORD[32+rsi],xmm4
855	pxor	xmm4,xmm4
856	movups	XMMWORD[48+rsi],xmm5
857	pxor	xmm5,xmm5
858	jmp	NEAR $L$ecb_ret
859ALIGN	16
860$L$ecb_dec_five:
861	xorps	xmm7,xmm7
862	call	_aesni_decrypt6
863	movups	XMMWORD[rsi],xmm2
864	pxor	xmm2,xmm2
865	movups	XMMWORD[16+rsi],xmm3
866	pxor	xmm3,xmm3
867	movups	XMMWORD[32+rsi],xmm4
868	pxor	xmm4,xmm4
869	movups	XMMWORD[48+rsi],xmm5
870	pxor	xmm5,xmm5
871	movups	XMMWORD[64+rsi],xmm6
872	pxor	xmm6,xmm6
873	pxor	xmm7,xmm7
874	jmp	NEAR $L$ecb_ret
875ALIGN	16
876$L$ecb_dec_six:
877	call	_aesni_decrypt6
878	movups	XMMWORD[rsi],xmm2
879	pxor	xmm2,xmm2
880	movups	XMMWORD[16+rsi],xmm3
881	pxor	xmm3,xmm3
882	movups	XMMWORD[32+rsi],xmm4
883	pxor	xmm4,xmm4
884	movups	XMMWORD[48+rsi],xmm5
885	pxor	xmm5,xmm5
886	movups	XMMWORD[64+rsi],xmm6
887	pxor	xmm6,xmm6
888	movups	XMMWORD[80+rsi],xmm7
889	pxor	xmm7,xmm7
890
891$L$ecb_ret:
892	xorps	xmm0,xmm0
893	pxor	xmm1,xmm1
894	movaps	xmm6,XMMWORD[rsp]
895	movaps	XMMWORD[rsp],xmm0
896	movaps	xmm7,XMMWORD[16+rsp]
897	movaps	XMMWORD[16+rsp],xmm0
898	movaps	xmm8,XMMWORD[32+rsp]
899	movaps	XMMWORD[32+rsp],xmm0
900	movaps	xmm9,XMMWORD[48+rsp]
901	movaps	XMMWORD[48+rsp],xmm0
902	lea	rsp,[88+rsp]
903$L$ecb_enc_ret:
904	mov	rdi,QWORD[8+rsp]	;WIN64 epilogue
905	mov	rsi,QWORD[16+rsp]
906	ret
907
908$L$SEH_end_aes_hw_ecb_encrypt:
909global	aes_hw_ctr32_encrypt_blocks
910
911ALIGN	16
912aes_hw_ctr32_encrypt_blocks:
913	mov	QWORD[8+rsp],rdi	;WIN64 prologue
914	mov	QWORD[16+rsp],rsi
915	mov	rax,rsp
916$L$SEH_begin_aes_hw_ctr32_encrypt_blocks:
917	mov	rdi,rcx
918	mov	rsi,rdx
919	mov	rdx,r8
920	mov	rcx,r9
921	mov	r8,QWORD[40+rsp]
922
923
924
925_CET_ENDBR
926%ifdef BORINGSSL_DISPATCH_TEST
927	mov	BYTE[BORINGSSL_function_hit],1
928%endif
929	cmp	rdx,1
930	jne	NEAR $L$ctr32_bulk
931
932
933
934	movups	xmm2,XMMWORD[r8]
935	movups	xmm3,XMMWORD[rdi]
936	mov	edx,DWORD[240+rcx]
937	movups	xmm0,XMMWORD[rcx]
938	movups	xmm1,XMMWORD[16+rcx]
939	lea	rcx,[32+rcx]
940	xorps	xmm2,xmm0
941$L$oop_enc1_5:
942	DB	102,15,56,220,209
943	dec	edx
944	movups	xmm1,XMMWORD[rcx]
945	lea	rcx,[16+rcx]
946	jnz	NEAR $L$oop_enc1_5
947	DB	102,15,56,221,209
948	pxor	xmm0,xmm0
949	pxor	xmm1,xmm1
950	xorps	xmm2,xmm3
951	pxor	xmm3,xmm3
952	movups	XMMWORD[rsi],xmm2
953	xorps	xmm2,xmm2
954	jmp	NEAR $L$ctr32_epilogue
955
956ALIGN	16
957$L$ctr32_bulk:
958	lea	r11,[rsp]
959
960	push	rbp
961
962	sub	rsp,288
963	and	rsp,-16
964	movaps	XMMWORD[(-168)+r11],xmm6
965	movaps	XMMWORD[(-152)+r11],xmm7
966	movaps	XMMWORD[(-136)+r11],xmm8
967	movaps	XMMWORD[(-120)+r11],xmm9
968	movaps	XMMWORD[(-104)+r11],xmm10
969	movaps	XMMWORD[(-88)+r11],xmm11
970	movaps	XMMWORD[(-72)+r11],xmm12
971	movaps	XMMWORD[(-56)+r11],xmm13
972	movaps	XMMWORD[(-40)+r11],xmm14
973	movaps	XMMWORD[(-24)+r11],xmm15
974$L$ctr32_body:
975
976
977
978
979	movdqu	xmm2,XMMWORD[r8]
980	movdqu	xmm0,XMMWORD[rcx]
981	mov	r8d,DWORD[12+r8]
982	pxor	xmm2,xmm0
983	mov	ebp,DWORD[12+rcx]
984	movdqa	XMMWORD[rsp],xmm2
985	bswap	r8d
986	movdqa	xmm3,xmm2
987	movdqa	xmm4,xmm2
988	movdqa	xmm5,xmm2
989	movdqa	XMMWORD[64+rsp],xmm2
990	movdqa	XMMWORD[80+rsp],xmm2
991	movdqa	XMMWORD[96+rsp],xmm2
992	mov	r10,rdx
993	movdqa	XMMWORD[112+rsp],xmm2
994
995	lea	rax,[1+r8]
996	lea	rdx,[2+r8]
997	bswap	eax
998	bswap	edx
999	xor	eax,ebp
1000	xor	edx,ebp
1001DB	102,15,58,34,216,3
1002	lea	rax,[3+r8]
1003	movdqa	XMMWORD[16+rsp],xmm3
1004DB	102,15,58,34,226,3
1005	bswap	eax
1006	mov	rdx,r10
1007	lea	r10,[4+r8]
1008	movdqa	XMMWORD[32+rsp],xmm4
1009	xor	eax,ebp
1010	bswap	r10d
1011DB	102,15,58,34,232,3
1012	xor	r10d,ebp
1013	movdqa	XMMWORD[48+rsp],xmm5
1014	lea	r9,[5+r8]
1015	mov	DWORD[((64+12))+rsp],r10d
1016	bswap	r9d
1017	lea	r10,[6+r8]
1018	mov	eax,DWORD[240+rcx]
1019	xor	r9d,ebp
1020	bswap	r10d
1021	mov	DWORD[((80+12))+rsp],r9d
1022	xor	r10d,ebp
1023	lea	r9,[7+r8]
1024	mov	DWORD[((96+12))+rsp],r10d
1025	bswap	r9d
1026	xor	r9d,ebp
1027	mov	DWORD[((112+12))+rsp],r9d
1028
1029	movups	xmm1,XMMWORD[16+rcx]
1030
1031	movdqa	xmm6,XMMWORD[64+rsp]
1032	movdqa	xmm7,XMMWORD[80+rsp]
1033
1034	cmp	rdx,8
1035	jb	NEAR $L$ctr32_tail
1036
1037	lea	rcx,[128+rcx]
1038	sub	rdx,8
1039	jmp	NEAR $L$ctr32_loop8
1040
1041ALIGN	32
1042$L$ctr32_loop8:
1043	add	r8d,8
1044	movdqa	xmm8,XMMWORD[96+rsp]
1045	DB	102,15,56,220,209
1046	mov	r9d,r8d
1047	movdqa	xmm9,XMMWORD[112+rsp]
1048	DB	102,15,56,220,217
1049	bswap	r9d
1050	movups	xmm0,XMMWORD[((32-128))+rcx]
1051	DB	102,15,56,220,225
1052	xor	r9d,ebp
1053	nop
1054	DB	102,15,56,220,233
1055	mov	DWORD[((0+12))+rsp],r9d
1056	lea	r9,[1+r8]
1057	DB	102,15,56,220,241
1058	DB	102,15,56,220,249
1059	DB	102,68,15,56,220,193
1060	DB	102,68,15,56,220,201
1061	movups	xmm1,XMMWORD[((48-128))+rcx]
1062	bswap	r9d
1063	DB	102,15,56,220,208
1064	DB	102,15,56,220,216
1065	xor	r9d,ebp
1066	DB	0x66,0x90
1067	DB	102,15,56,220,224
1068	DB	102,15,56,220,232
1069	mov	DWORD[((16+12))+rsp],r9d
1070	lea	r9,[2+r8]
1071	DB	102,15,56,220,240
1072	DB	102,15,56,220,248
1073	DB	102,68,15,56,220,192
1074	DB	102,68,15,56,220,200
1075	movups	xmm0,XMMWORD[((64-128))+rcx]
1076	bswap	r9d
1077	DB	102,15,56,220,209
1078	DB	102,15,56,220,217
1079	xor	r9d,ebp
1080	DB	0x66,0x90
1081	DB	102,15,56,220,225
1082	DB	102,15,56,220,233
1083	mov	DWORD[((32+12))+rsp],r9d
1084	lea	r9,[3+r8]
1085	DB	102,15,56,220,241
1086	DB	102,15,56,220,249
1087	DB	102,68,15,56,220,193
1088	DB	102,68,15,56,220,201
1089	movups	xmm1,XMMWORD[((80-128))+rcx]
1090	bswap	r9d
1091	DB	102,15,56,220,208
1092	DB	102,15,56,220,216
1093	xor	r9d,ebp
1094	DB	0x66,0x90
1095	DB	102,15,56,220,224
1096	DB	102,15,56,220,232
1097	mov	DWORD[((48+12))+rsp],r9d
1098	lea	r9,[4+r8]
1099	DB	102,15,56,220,240
1100	DB	102,15,56,220,248
1101	DB	102,68,15,56,220,192
1102	DB	102,68,15,56,220,200
1103	movups	xmm0,XMMWORD[((96-128))+rcx]
1104	bswap	r9d
1105	DB	102,15,56,220,209
1106	DB	102,15,56,220,217
1107	xor	r9d,ebp
1108	DB	0x66,0x90
1109	DB	102,15,56,220,225
1110	DB	102,15,56,220,233
1111	mov	DWORD[((64+12))+rsp],r9d
1112	lea	r9,[5+r8]
1113	DB	102,15,56,220,241
1114	DB	102,15,56,220,249
1115	DB	102,68,15,56,220,193
1116	DB	102,68,15,56,220,201
1117	movups	xmm1,XMMWORD[((112-128))+rcx]
1118	bswap	r9d
1119	DB	102,15,56,220,208
1120	DB	102,15,56,220,216
1121	xor	r9d,ebp
1122	DB	0x66,0x90
1123	DB	102,15,56,220,224
1124	DB	102,15,56,220,232
1125	mov	DWORD[((80+12))+rsp],r9d
1126	lea	r9,[6+r8]
1127	DB	102,15,56,220,240
1128	DB	102,15,56,220,248
1129	DB	102,68,15,56,220,192
1130	DB	102,68,15,56,220,200
1131	movups	xmm0,XMMWORD[((128-128))+rcx]
1132	bswap	r9d
1133	DB	102,15,56,220,209
1134	DB	102,15,56,220,217
1135	xor	r9d,ebp
1136	DB	0x66,0x90
1137	DB	102,15,56,220,225
1138	DB	102,15,56,220,233
1139	mov	DWORD[((96+12))+rsp],r9d
1140	lea	r9,[7+r8]
1141	DB	102,15,56,220,241
1142	DB	102,15,56,220,249
1143	DB	102,68,15,56,220,193
1144	DB	102,68,15,56,220,201
1145	movups	xmm1,XMMWORD[((144-128))+rcx]
1146	bswap	r9d
1147	DB	102,15,56,220,208
1148	DB	102,15,56,220,216
1149	DB	102,15,56,220,224
1150	xor	r9d,ebp
1151	movdqu	xmm10,XMMWORD[rdi]
1152	DB	102,15,56,220,232
1153	mov	DWORD[((112+12))+rsp],r9d
1154	cmp	eax,11
1155	DB	102,15,56,220,240
1156	DB	102,15,56,220,248
1157	DB	102,68,15,56,220,192
1158	DB	102,68,15,56,220,200
1159	movups	xmm0,XMMWORD[((160-128))+rcx]
1160
1161	jb	NEAR $L$ctr32_enc_done
1162
1163	DB	102,15,56,220,209
1164	DB	102,15,56,220,217
1165	DB	102,15,56,220,225
1166	DB	102,15,56,220,233
1167	DB	102,15,56,220,241
1168	DB	102,15,56,220,249
1169	DB	102,68,15,56,220,193
1170	DB	102,68,15,56,220,201
1171	movups	xmm1,XMMWORD[((176-128))+rcx]
1172
1173	DB	102,15,56,220,208
1174	DB	102,15,56,220,216
1175	DB	102,15,56,220,224
1176	DB	102,15,56,220,232
1177	DB	102,15,56,220,240
1178	DB	102,15,56,220,248
1179	DB	102,68,15,56,220,192
1180	DB	102,68,15,56,220,200
1181	movups	xmm0,XMMWORD[((192-128))+rcx]
1182	je	NEAR $L$ctr32_enc_done
1183
1184	DB	102,15,56,220,209
1185	DB	102,15,56,220,217
1186	DB	102,15,56,220,225
1187	DB	102,15,56,220,233
1188	DB	102,15,56,220,241
1189	DB	102,15,56,220,249
1190	DB	102,68,15,56,220,193
1191	DB	102,68,15,56,220,201
1192	movups	xmm1,XMMWORD[((208-128))+rcx]
1193
1194	DB	102,15,56,220,208
1195	DB	102,15,56,220,216
1196	DB	102,15,56,220,224
1197	DB	102,15,56,220,232
1198	DB	102,15,56,220,240
1199	DB	102,15,56,220,248
1200	DB	102,68,15,56,220,192
1201	DB	102,68,15,56,220,200
1202	movups	xmm0,XMMWORD[((224-128))+rcx]
1203	jmp	NEAR $L$ctr32_enc_done
1204
1205ALIGN	16
1206$L$ctr32_enc_done:
1207	movdqu	xmm11,XMMWORD[16+rdi]
1208	pxor	xmm10,xmm0
1209	movdqu	xmm12,XMMWORD[32+rdi]
1210	pxor	xmm11,xmm0
1211	movdqu	xmm13,XMMWORD[48+rdi]
1212	pxor	xmm12,xmm0
1213	movdqu	xmm14,XMMWORD[64+rdi]
1214	pxor	xmm13,xmm0
1215	movdqu	xmm15,XMMWORD[80+rdi]
1216	pxor	xmm14,xmm0
1217	prefetcht0	[448+rdi]
1218	prefetcht0	[512+rdi]
1219	pxor	xmm15,xmm0
1220	DB	102,15,56,220,209
1221	DB	102,15,56,220,217
1222	DB	102,15,56,220,225
1223	DB	102,15,56,220,233
1224	DB	102,15,56,220,241
1225	DB	102,15,56,220,249
1226	DB	102,68,15,56,220,193
1227	DB	102,68,15,56,220,201
1228	movdqu	xmm1,XMMWORD[96+rdi]
1229	lea	rdi,[128+rdi]
1230
1231	DB	102,65,15,56,221,210
1232	pxor	xmm1,xmm0
1233	movdqu	xmm10,XMMWORD[((112-128))+rdi]
1234	DB	102,65,15,56,221,219
1235	pxor	xmm10,xmm0
1236	movdqa	xmm11,XMMWORD[rsp]
1237	DB	102,65,15,56,221,228
1238	DB	102,65,15,56,221,237
1239	movdqa	xmm12,XMMWORD[16+rsp]
1240	movdqa	xmm13,XMMWORD[32+rsp]
1241	DB	102,65,15,56,221,246
1242	DB	102,65,15,56,221,255
1243	movdqa	xmm14,XMMWORD[48+rsp]
1244	movdqa	xmm15,XMMWORD[64+rsp]
1245	DB	102,68,15,56,221,193
1246	movdqa	xmm0,XMMWORD[80+rsp]
1247	movups	xmm1,XMMWORD[((16-128))+rcx]
1248	DB	102,69,15,56,221,202
1249
1250	movups	XMMWORD[rsi],xmm2
1251	movdqa	xmm2,xmm11
1252	movups	XMMWORD[16+rsi],xmm3
1253	movdqa	xmm3,xmm12
1254	movups	XMMWORD[32+rsi],xmm4
1255	movdqa	xmm4,xmm13
1256	movups	XMMWORD[48+rsi],xmm5
1257	movdqa	xmm5,xmm14
1258	movups	XMMWORD[64+rsi],xmm6
1259	movdqa	xmm6,xmm15
1260	movups	XMMWORD[80+rsi],xmm7
1261	movdqa	xmm7,xmm0
1262	movups	XMMWORD[96+rsi],xmm8
1263	movups	XMMWORD[112+rsi],xmm9
1264	lea	rsi,[128+rsi]
1265
1266	sub	rdx,8
1267	jnc	NEAR $L$ctr32_loop8
1268
1269	add	rdx,8
1270	jz	NEAR $L$ctr32_done
1271	lea	rcx,[((-128))+rcx]
1272
1273$L$ctr32_tail:
1274
1275
1276	lea	rcx,[16+rcx]
1277	cmp	rdx,4
1278	jb	NEAR $L$ctr32_loop3
1279	je	NEAR $L$ctr32_loop4
1280
1281
1282	shl	eax,4
1283	movdqa	xmm8,XMMWORD[96+rsp]
1284	pxor	xmm9,xmm9
1285
1286	movups	xmm0,XMMWORD[16+rcx]
1287	DB	102,15,56,220,209
1288	DB	102,15,56,220,217
1289	lea	rcx,[((32-16))+rax*1+rcx]
1290	neg	rax
1291	DB	102,15,56,220,225
1292	add	rax,16
1293	movups	xmm10,XMMWORD[rdi]
1294	DB	102,15,56,220,233
1295	DB	102,15,56,220,241
1296	movups	xmm11,XMMWORD[16+rdi]
1297	movups	xmm12,XMMWORD[32+rdi]
1298	DB	102,15,56,220,249
1299	DB	102,68,15,56,220,193
1300
1301	call	$L$enc_loop8_enter
1302
1303	movdqu	xmm13,XMMWORD[48+rdi]
1304	pxor	xmm2,xmm10
1305	movdqu	xmm10,XMMWORD[64+rdi]
1306	pxor	xmm3,xmm11
1307	movdqu	XMMWORD[rsi],xmm2
1308	pxor	xmm4,xmm12
1309	movdqu	XMMWORD[16+rsi],xmm3
1310	pxor	xmm5,xmm13
1311	movdqu	XMMWORD[32+rsi],xmm4
1312	pxor	xmm6,xmm10
1313	movdqu	XMMWORD[48+rsi],xmm5
1314	movdqu	XMMWORD[64+rsi],xmm6
1315	cmp	rdx,6
1316	jb	NEAR $L$ctr32_done
1317
1318	movups	xmm11,XMMWORD[80+rdi]
1319	xorps	xmm7,xmm11
1320	movups	XMMWORD[80+rsi],xmm7
1321	je	NEAR $L$ctr32_done
1322
1323	movups	xmm12,XMMWORD[96+rdi]
1324	xorps	xmm8,xmm12
1325	movups	XMMWORD[96+rsi],xmm8
1326	jmp	NEAR $L$ctr32_done
1327
1328ALIGN	32
1329$L$ctr32_loop4:
1330	DB	102,15,56,220,209
1331	lea	rcx,[16+rcx]
1332	dec	eax
1333	DB	102,15,56,220,217
1334	DB	102,15,56,220,225
1335	DB	102,15,56,220,233
1336	movups	xmm1,XMMWORD[rcx]
1337	jnz	NEAR $L$ctr32_loop4
1338	DB	102,15,56,221,209
1339	DB	102,15,56,221,217
1340	movups	xmm10,XMMWORD[rdi]
1341	movups	xmm11,XMMWORD[16+rdi]
1342	DB	102,15,56,221,225
1343	DB	102,15,56,221,233
1344	movups	xmm12,XMMWORD[32+rdi]
1345	movups	xmm13,XMMWORD[48+rdi]
1346
1347	xorps	xmm2,xmm10
1348	movups	XMMWORD[rsi],xmm2
1349	xorps	xmm3,xmm11
1350	movups	XMMWORD[16+rsi],xmm3
1351	pxor	xmm4,xmm12
1352	movdqu	XMMWORD[32+rsi],xmm4
1353	pxor	xmm5,xmm13
1354	movdqu	XMMWORD[48+rsi],xmm5
1355	jmp	NEAR $L$ctr32_done
1356
1357ALIGN	32
1358$L$ctr32_loop3:
1359	DB	102,15,56,220,209
1360	lea	rcx,[16+rcx]
1361	dec	eax
1362	DB	102,15,56,220,217
1363	DB	102,15,56,220,225
1364	movups	xmm1,XMMWORD[rcx]
1365	jnz	NEAR $L$ctr32_loop3
1366	DB	102,15,56,221,209
1367	DB	102,15,56,221,217
1368	DB	102,15,56,221,225
1369
1370	movups	xmm10,XMMWORD[rdi]
1371	xorps	xmm2,xmm10
1372	movups	XMMWORD[rsi],xmm2
1373	cmp	rdx,2
1374	jb	NEAR $L$ctr32_done
1375
1376	movups	xmm11,XMMWORD[16+rdi]
1377	xorps	xmm3,xmm11
1378	movups	XMMWORD[16+rsi],xmm3
1379	je	NEAR $L$ctr32_done
1380
1381	movups	xmm12,XMMWORD[32+rdi]
1382	xorps	xmm4,xmm12
1383	movups	XMMWORD[32+rsi],xmm4
1384
1385$L$ctr32_done:
1386	xorps	xmm0,xmm0
1387	xor	ebp,ebp
1388	pxor	xmm1,xmm1
1389	pxor	xmm2,xmm2
1390	pxor	xmm3,xmm3
1391	pxor	xmm4,xmm4
1392	pxor	xmm5,xmm5
1393	movaps	xmm6,XMMWORD[((-168))+r11]
1394	movaps	XMMWORD[(-168)+r11],xmm0
1395	movaps	xmm7,XMMWORD[((-152))+r11]
1396	movaps	XMMWORD[(-152)+r11],xmm0
1397	movaps	xmm8,XMMWORD[((-136))+r11]
1398	movaps	XMMWORD[(-136)+r11],xmm0
1399	movaps	xmm9,XMMWORD[((-120))+r11]
1400	movaps	XMMWORD[(-120)+r11],xmm0
1401	movaps	xmm10,XMMWORD[((-104))+r11]
1402	movaps	XMMWORD[(-104)+r11],xmm0
1403	movaps	xmm11,XMMWORD[((-88))+r11]
1404	movaps	XMMWORD[(-88)+r11],xmm0
1405	movaps	xmm12,XMMWORD[((-72))+r11]
1406	movaps	XMMWORD[(-72)+r11],xmm0
1407	movaps	xmm13,XMMWORD[((-56))+r11]
1408	movaps	XMMWORD[(-56)+r11],xmm0
1409	movaps	xmm14,XMMWORD[((-40))+r11]
1410	movaps	XMMWORD[(-40)+r11],xmm0
1411	movaps	xmm15,XMMWORD[((-24))+r11]
1412	movaps	XMMWORD[(-24)+r11],xmm0
1413	movaps	XMMWORD[rsp],xmm0
1414	movaps	XMMWORD[16+rsp],xmm0
1415	movaps	XMMWORD[32+rsp],xmm0
1416	movaps	XMMWORD[48+rsp],xmm0
1417	movaps	XMMWORD[64+rsp],xmm0
1418	movaps	XMMWORD[80+rsp],xmm0
1419	movaps	XMMWORD[96+rsp],xmm0
1420	movaps	XMMWORD[112+rsp],xmm0
1421	mov	rbp,QWORD[((-8))+r11]
1422
1423	lea	rsp,[r11]
1424
1425$L$ctr32_epilogue:
1426	mov	rdi,QWORD[8+rsp]	;WIN64 epilogue
1427	mov	rsi,QWORD[16+rsp]
1428	ret
1429
1430$L$SEH_end_aes_hw_ctr32_encrypt_blocks:
1431global	aes_hw_cbc_encrypt
1432
1433ALIGN	16
1434aes_hw_cbc_encrypt:
1435	mov	QWORD[8+rsp],rdi	;WIN64 prologue
1436	mov	QWORD[16+rsp],rsi
1437	mov	rax,rsp
1438$L$SEH_begin_aes_hw_cbc_encrypt:
1439	mov	rdi,rcx
1440	mov	rsi,rdx
1441	mov	rdx,r8
1442	mov	rcx,r9
1443	mov	r8,QWORD[40+rsp]
1444	mov	r9,QWORD[48+rsp]
1445
1446
1447
1448_CET_ENDBR
1449	test	rdx,rdx
1450	jz	NEAR $L$cbc_ret
1451
1452	mov	r10d,DWORD[240+rcx]
1453	mov	r11,rcx
1454	test	r9d,r9d
1455	jz	NEAR $L$cbc_decrypt
1456
1457	movups	xmm2,XMMWORD[r8]
1458	mov	eax,r10d
1459	cmp	rdx,16
1460	jb	NEAR $L$cbc_enc_tail
1461	sub	rdx,16
1462	jmp	NEAR $L$cbc_enc_loop
1463ALIGN	16
1464$L$cbc_enc_loop:
1465	movups	xmm3,XMMWORD[rdi]
1466	lea	rdi,[16+rdi]
1467
1468	movups	xmm0,XMMWORD[rcx]
1469	movups	xmm1,XMMWORD[16+rcx]
1470	xorps	xmm3,xmm0
1471	lea	rcx,[32+rcx]
1472	xorps	xmm2,xmm3
1473$L$oop_enc1_6:
1474	DB	102,15,56,220,209
1475	dec	eax
1476	movups	xmm1,XMMWORD[rcx]
1477	lea	rcx,[16+rcx]
1478	jnz	NEAR $L$oop_enc1_6
1479	DB	102,15,56,221,209
1480	mov	eax,r10d
1481	mov	rcx,r11
1482	movups	XMMWORD[rsi],xmm2
1483	lea	rsi,[16+rsi]
1484	sub	rdx,16
1485	jnc	NEAR $L$cbc_enc_loop
1486	add	rdx,16
1487	jnz	NEAR $L$cbc_enc_tail
1488	pxor	xmm0,xmm0
1489	pxor	xmm1,xmm1
1490	movups	XMMWORD[r8],xmm2
1491	pxor	xmm2,xmm2
1492	pxor	xmm3,xmm3
1493	jmp	NEAR $L$cbc_ret
1494
1495$L$cbc_enc_tail:
1496	mov	rcx,rdx
1497	xchg	rsi,rdi
1498	DD	0x9066A4F3
1499	mov	ecx,16
1500	sub	rcx,rdx
1501	xor	eax,eax
1502	DD	0x9066AAF3
1503	lea	rdi,[((-16))+rdi]
1504	mov	eax,r10d
1505	mov	rsi,rdi
1506	mov	rcx,r11
1507	xor	rdx,rdx
1508	jmp	NEAR $L$cbc_enc_loop
1509
1510ALIGN	16
1511$L$cbc_decrypt:
1512	cmp	rdx,16
1513	jne	NEAR $L$cbc_decrypt_bulk
1514
1515
1516
1517	movdqu	xmm2,XMMWORD[rdi]
1518	movdqu	xmm3,XMMWORD[r8]
1519	movdqa	xmm4,xmm2
1520	movups	xmm0,XMMWORD[rcx]
1521	movups	xmm1,XMMWORD[16+rcx]
1522	lea	rcx,[32+rcx]
1523	xorps	xmm2,xmm0
1524$L$oop_dec1_7:
1525	DB	102,15,56,222,209
1526	dec	r10d
1527	movups	xmm1,XMMWORD[rcx]
1528	lea	rcx,[16+rcx]
1529	jnz	NEAR $L$oop_dec1_7
1530	DB	102,15,56,223,209
1531	pxor	xmm0,xmm0
1532	pxor	xmm1,xmm1
1533	movdqu	XMMWORD[r8],xmm4
1534	xorps	xmm2,xmm3
1535	pxor	xmm3,xmm3
1536	movups	XMMWORD[rsi],xmm2
1537	pxor	xmm2,xmm2
1538	jmp	NEAR $L$cbc_ret
1539ALIGN	16
1540$L$cbc_decrypt_bulk:
1541	lea	r11,[rsp]
1542
1543	push	rbp
1544
1545	sub	rsp,176
1546	and	rsp,-16
1547	movaps	XMMWORD[16+rsp],xmm6
1548	movaps	XMMWORD[32+rsp],xmm7
1549	movaps	XMMWORD[48+rsp],xmm8
1550	movaps	XMMWORD[64+rsp],xmm9
1551	movaps	XMMWORD[80+rsp],xmm10
1552	movaps	XMMWORD[96+rsp],xmm11
1553	movaps	XMMWORD[112+rsp],xmm12
1554	movaps	XMMWORD[128+rsp],xmm13
1555	movaps	XMMWORD[144+rsp],xmm14
1556	movaps	XMMWORD[160+rsp],xmm15
1557$L$cbc_decrypt_body:
1558	mov	rbp,rcx
1559	movups	xmm10,XMMWORD[r8]
1560	mov	eax,r10d
1561	cmp	rdx,0x50
1562	jbe	NEAR $L$cbc_dec_tail
1563
1564	movups	xmm0,XMMWORD[rcx]
1565	movdqu	xmm2,XMMWORD[rdi]
1566	movdqu	xmm3,XMMWORD[16+rdi]
1567	movdqa	xmm11,xmm2
1568	movdqu	xmm4,XMMWORD[32+rdi]
1569	movdqa	xmm12,xmm3
1570	movdqu	xmm5,XMMWORD[48+rdi]
1571	movdqa	xmm13,xmm4
1572	movdqu	xmm6,XMMWORD[64+rdi]
1573	movdqa	xmm14,xmm5
1574	movdqu	xmm7,XMMWORD[80+rdi]
1575	movdqa	xmm15,xmm6
1576	cmp	rdx,0x70
1577	jbe	NEAR $L$cbc_dec_six_or_seven
1578
1579	sub	rdx,0x70
1580	lea	rcx,[112+rcx]
1581	jmp	NEAR $L$cbc_dec_loop8_enter
1582ALIGN	16
1583$L$cbc_dec_loop8:
1584	movups	XMMWORD[rsi],xmm9
1585	lea	rsi,[16+rsi]
1586$L$cbc_dec_loop8_enter:
1587	movdqu	xmm8,XMMWORD[96+rdi]
1588	pxor	xmm2,xmm0
1589	movdqu	xmm9,XMMWORD[112+rdi]
1590	pxor	xmm3,xmm0
1591	movups	xmm1,XMMWORD[((16-112))+rcx]
1592	pxor	xmm4,xmm0
1593	mov	rbp,-1
1594	cmp	rdx,0x70
1595	pxor	xmm5,xmm0
1596	pxor	xmm6,xmm0
1597	pxor	xmm7,xmm0
1598	pxor	xmm8,xmm0
1599
1600	DB	102,15,56,222,209
1601	pxor	xmm9,xmm0
1602	movups	xmm0,XMMWORD[((32-112))+rcx]
1603	DB	102,15,56,222,217
1604	DB	102,15,56,222,225
1605	DB	102,15,56,222,233
1606	DB	102,15,56,222,241
1607	DB	102,15,56,222,249
1608	DB	102,68,15,56,222,193
1609	adc	rbp,0
1610	and	rbp,128
1611	DB	102,68,15,56,222,201
1612	add	rbp,rdi
1613	movups	xmm1,XMMWORD[((48-112))+rcx]
1614	DB	102,15,56,222,208
1615	DB	102,15,56,222,216
1616	DB	102,15,56,222,224
1617	DB	102,15,56,222,232
1618	DB	102,15,56,222,240
1619	DB	102,15,56,222,248
1620	DB	102,68,15,56,222,192
1621	DB	102,68,15,56,222,200
1622	movups	xmm0,XMMWORD[((64-112))+rcx]
1623	nop
1624	DB	102,15,56,222,209
1625	DB	102,15,56,222,217
1626	DB	102,15,56,222,225
1627	DB	102,15,56,222,233
1628	DB	102,15,56,222,241
1629	DB	102,15,56,222,249
1630	DB	102,68,15,56,222,193
1631	DB	102,68,15,56,222,201
1632	movups	xmm1,XMMWORD[((80-112))+rcx]
1633	nop
1634	DB	102,15,56,222,208
1635	DB	102,15,56,222,216
1636	DB	102,15,56,222,224
1637	DB	102,15,56,222,232
1638	DB	102,15,56,222,240
1639	DB	102,15,56,222,248
1640	DB	102,68,15,56,222,192
1641	DB	102,68,15,56,222,200
1642	movups	xmm0,XMMWORD[((96-112))+rcx]
1643	nop
1644	DB	102,15,56,222,209
1645	DB	102,15,56,222,217
1646	DB	102,15,56,222,225
1647	DB	102,15,56,222,233
1648	DB	102,15,56,222,241
1649	DB	102,15,56,222,249
1650	DB	102,68,15,56,222,193
1651	DB	102,68,15,56,222,201
1652	movups	xmm1,XMMWORD[((112-112))+rcx]
1653	nop
1654	DB	102,15,56,222,208
1655	DB	102,15,56,222,216
1656	DB	102,15,56,222,224
1657	DB	102,15,56,222,232
1658	DB	102,15,56,222,240
1659	DB	102,15,56,222,248
1660	DB	102,68,15,56,222,192
1661	DB	102,68,15,56,222,200
1662	movups	xmm0,XMMWORD[((128-112))+rcx]
1663	nop
1664	DB	102,15,56,222,209
1665	DB	102,15,56,222,217
1666	DB	102,15,56,222,225
1667	DB	102,15,56,222,233
1668	DB	102,15,56,222,241
1669	DB	102,15,56,222,249
1670	DB	102,68,15,56,222,193
1671	DB	102,68,15,56,222,201
1672	movups	xmm1,XMMWORD[((144-112))+rcx]
1673	cmp	eax,11
1674	DB	102,15,56,222,208
1675	DB	102,15,56,222,216
1676	DB	102,15,56,222,224
1677	DB	102,15,56,222,232
1678	DB	102,15,56,222,240
1679	DB	102,15,56,222,248
1680	DB	102,68,15,56,222,192
1681	DB	102,68,15,56,222,200
1682	movups	xmm0,XMMWORD[((160-112))+rcx]
1683	jb	NEAR $L$cbc_dec_done
1684	DB	102,15,56,222,209
1685	DB	102,15,56,222,217
1686	DB	102,15,56,222,225
1687	DB	102,15,56,222,233
1688	DB	102,15,56,222,241
1689	DB	102,15,56,222,249
1690	DB	102,68,15,56,222,193
1691	DB	102,68,15,56,222,201
1692	movups	xmm1,XMMWORD[((176-112))+rcx]
1693	nop
1694	DB	102,15,56,222,208
1695	DB	102,15,56,222,216
1696	DB	102,15,56,222,224
1697	DB	102,15,56,222,232
1698	DB	102,15,56,222,240
1699	DB	102,15,56,222,248
1700	DB	102,68,15,56,222,192
1701	DB	102,68,15,56,222,200
1702	movups	xmm0,XMMWORD[((192-112))+rcx]
1703	je	NEAR $L$cbc_dec_done
1704	DB	102,15,56,222,209
1705	DB	102,15,56,222,217
1706	DB	102,15,56,222,225
1707	DB	102,15,56,222,233
1708	DB	102,15,56,222,241
1709	DB	102,15,56,222,249
1710	DB	102,68,15,56,222,193
1711	DB	102,68,15,56,222,201
1712	movups	xmm1,XMMWORD[((208-112))+rcx]
1713	nop
1714	DB	102,15,56,222,208
1715	DB	102,15,56,222,216
1716	DB	102,15,56,222,224
1717	DB	102,15,56,222,232
1718	DB	102,15,56,222,240
1719	DB	102,15,56,222,248
1720	DB	102,68,15,56,222,192
1721	DB	102,68,15,56,222,200
1722	movups	xmm0,XMMWORD[((224-112))+rcx]
1723	jmp	NEAR $L$cbc_dec_done
1724ALIGN	16
1725$L$cbc_dec_done:
1726	DB	102,15,56,222,209
1727	DB	102,15,56,222,217
1728	pxor	xmm10,xmm0
1729	pxor	xmm11,xmm0
1730	DB	102,15,56,222,225
1731	DB	102,15,56,222,233
1732	pxor	xmm12,xmm0
1733	pxor	xmm13,xmm0
1734	DB	102,15,56,222,241
1735	DB	102,15,56,222,249
1736	pxor	xmm14,xmm0
1737	pxor	xmm15,xmm0
1738	DB	102,68,15,56,222,193
1739	DB	102,68,15,56,222,201
1740	movdqu	xmm1,XMMWORD[80+rdi]
1741
1742	DB	102,65,15,56,223,210
1743	movdqu	xmm10,XMMWORD[96+rdi]
1744	pxor	xmm1,xmm0
1745	DB	102,65,15,56,223,219
1746	pxor	xmm10,xmm0
1747	movdqu	xmm0,XMMWORD[112+rdi]
1748	DB	102,65,15,56,223,228
1749	lea	rdi,[128+rdi]
1750	movdqu	xmm11,XMMWORD[rbp]
1751	DB	102,65,15,56,223,237
1752	DB	102,65,15,56,223,246
1753	movdqu	xmm12,XMMWORD[16+rbp]
1754	movdqu	xmm13,XMMWORD[32+rbp]
1755	DB	102,65,15,56,223,255
1756	DB	102,68,15,56,223,193
1757	movdqu	xmm14,XMMWORD[48+rbp]
1758	movdqu	xmm15,XMMWORD[64+rbp]
1759	DB	102,69,15,56,223,202
1760	movdqa	xmm10,xmm0
1761	movdqu	xmm1,XMMWORD[80+rbp]
1762	movups	xmm0,XMMWORD[((-112))+rcx]
1763
1764	movups	XMMWORD[rsi],xmm2
1765	movdqa	xmm2,xmm11
1766	movups	XMMWORD[16+rsi],xmm3
1767	movdqa	xmm3,xmm12
1768	movups	XMMWORD[32+rsi],xmm4
1769	movdqa	xmm4,xmm13
1770	movups	XMMWORD[48+rsi],xmm5
1771	movdqa	xmm5,xmm14
1772	movups	XMMWORD[64+rsi],xmm6
1773	movdqa	xmm6,xmm15
1774	movups	XMMWORD[80+rsi],xmm7
1775	movdqa	xmm7,xmm1
1776	movups	XMMWORD[96+rsi],xmm8
1777	lea	rsi,[112+rsi]
1778
1779	sub	rdx,0x80
1780	ja	NEAR $L$cbc_dec_loop8
1781
1782	movaps	xmm2,xmm9
1783	lea	rcx,[((-112))+rcx]
1784	add	rdx,0x70
1785	jle	NEAR $L$cbc_dec_clear_tail_collected
1786	movups	XMMWORD[rsi],xmm9
1787	lea	rsi,[16+rsi]
1788	cmp	rdx,0x50
1789	jbe	NEAR $L$cbc_dec_tail
1790
1791	movaps	xmm2,xmm11
1792$L$cbc_dec_six_or_seven:
1793	cmp	rdx,0x60
1794	ja	NEAR $L$cbc_dec_seven
1795
1796	movaps	xmm8,xmm7
1797	call	_aesni_decrypt6
1798	pxor	xmm2,xmm10
1799	movaps	xmm10,xmm8
1800	pxor	xmm3,xmm11
1801	movdqu	XMMWORD[rsi],xmm2
1802	pxor	xmm4,xmm12
1803	movdqu	XMMWORD[16+rsi],xmm3
1804	pxor	xmm3,xmm3
1805	pxor	xmm5,xmm13
1806	movdqu	XMMWORD[32+rsi],xmm4
1807	pxor	xmm4,xmm4
1808	pxor	xmm6,xmm14
1809	movdqu	XMMWORD[48+rsi],xmm5
1810	pxor	xmm5,xmm5
1811	pxor	xmm7,xmm15
1812	movdqu	XMMWORD[64+rsi],xmm6
1813	pxor	xmm6,xmm6
1814	lea	rsi,[80+rsi]
1815	movdqa	xmm2,xmm7
1816	pxor	xmm7,xmm7
1817	jmp	NEAR $L$cbc_dec_tail_collected
1818
1819ALIGN	16
1820$L$cbc_dec_seven:
1821	movups	xmm8,XMMWORD[96+rdi]
1822	xorps	xmm9,xmm9
1823	call	_aesni_decrypt8
1824	movups	xmm9,XMMWORD[80+rdi]
1825	pxor	xmm2,xmm10
1826	movups	xmm10,XMMWORD[96+rdi]
1827	pxor	xmm3,xmm11
1828	movdqu	XMMWORD[rsi],xmm2
1829	pxor	xmm4,xmm12
1830	movdqu	XMMWORD[16+rsi],xmm3
1831	pxor	xmm3,xmm3
1832	pxor	xmm5,xmm13
1833	movdqu	XMMWORD[32+rsi],xmm4
1834	pxor	xmm4,xmm4
1835	pxor	xmm6,xmm14
1836	movdqu	XMMWORD[48+rsi],xmm5
1837	pxor	xmm5,xmm5
1838	pxor	xmm7,xmm15
1839	movdqu	XMMWORD[64+rsi],xmm6
1840	pxor	xmm6,xmm6
1841	pxor	xmm8,xmm9
1842	movdqu	XMMWORD[80+rsi],xmm7
1843	pxor	xmm7,xmm7
1844	lea	rsi,[96+rsi]
1845	movdqa	xmm2,xmm8
1846	pxor	xmm8,xmm8
1847	pxor	xmm9,xmm9
1848	jmp	NEAR $L$cbc_dec_tail_collected
1849
1850$L$cbc_dec_tail:
1851	movups	xmm2,XMMWORD[rdi]
1852	sub	rdx,0x10
1853	jbe	NEAR $L$cbc_dec_one
1854
1855	movups	xmm3,XMMWORD[16+rdi]
1856	movaps	xmm11,xmm2
1857	sub	rdx,0x10
1858	jbe	NEAR $L$cbc_dec_two
1859
1860	movups	xmm4,XMMWORD[32+rdi]
1861	movaps	xmm12,xmm3
1862	sub	rdx,0x10
1863	jbe	NEAR $L$cbc_dec_three
1864
1865	movups	xmm5,XMMWORD[48+rdi]
1866	movaps	xmm13,xmm4
1867	sub	rdx,0x10
1868	jbe	NEAR $L$cbc_dec_four
1869
1870	movups	xmm6,XMMWORD[64+rdi]
1871	movaps	xmm14,xmm5
1872	movaps	xmm15,xmm6
1873	xorps	xmm7,xmm7
1874	call	_aesni_decrypt6
1875	pxor	xmm2,xmm10
1876	movaps	xmm10,xmm15
1877	pxor	xmm3,xmm11
1878	movdqu	XMMWORD[rsi],xmm2
1879	pxor	xmm4,xmm12
1880	movdqu	XMMWORD[16+rsi],xmm3
1881	pxor	xmm3,xmm3
1882	pxor	xmm5,xmm13
1883	movdqu	XMMWORD[32+rsi],xmm4
1884	pxor	xmm4,xmm4
1885	pxor	xmm6,xmm14
1886	movdqu	XMMWORD[48+rsi],xmm5
1887	pxor	xmm5,xmm5
1888	lea	rsi,[64+rsi]
1889	movdqa	xmm2,xmm6
1890	pxor	xmm6,xmm6
1891	pxor	xmm7,xmm7
1892	sub	rdx,0x10
1893	jmp	NEAR $L$cbc_dec_tail_collected
1894
1895ALIGN	16
1896$L$cbc_dec_one:
1897	movaps	xmm11,xmm2
1898	movups	xmm0,XMMWORD[rcx]
1899	movups	xmm1,XMMWORD[16+rcx]
1900	lea	rcx,[32+rcx]
1901	xorps	xmm2,xmm0
1902$L$oop_dec1_8:
1903	DB	102,15,56,222,209
1904	dec	eax
1905	movups	xmm1,XMMWORD[rcx]
1906	lea	rcx,[16+rcx]
1907	jnz	NEAR $L$oop_dec1_8
1908	DB	102,15,56,223,209
1909	xorps	xmm2,xmm10
1910	movaps	xmm10,xmm11
1911	jmp	NEAR $L$cbc_dec_tail_collected
1912ALIGN	16
1913$L$cbc_dec_two:
1914	movaps	xmm12,xmm3
1915	call	_aesni_decrypt2
1916	pxor	xmm2,xmm10
1917	movaps	xmm10,xmm12
1918	pxor	xmm3,xmm11
1919	movdqu	XMMWORD[rsi],xmm2
1920	movdqa	xmm2,xmm3
1921	pxor	xmm3,xmm3
1922	lea	rsi,[16+rsi]
1923	jmp	NEAR $L$cbc_dec_tail_collected
1924ALIGN	16
1925$L$cbc_dec_three:
1926	movaps	xmm13,xmm4
1927	call	_aesni_decrypt3
1928	pxor	xmm2,xmm10
1929	movaps	xmm10,xmm13
1930	pxor	xmm3,xmm11
1931	movdqu	XMMWORD[rsi],xmm2
1932	pxor	xmm4,xmm12
1933	movdqu	XMMWORD[16+rsi],xmm3
1934	pxor	xmm3,xmm3
1935	movdqa	xmm2,xmm4
1936	pxor	xmm4,xmm4
1937	lea	rsi,[32+rsi]
1938	jmp	NEAR $L$cbc_dec_tail_collected
1939ALIGN	16
1940$L$cbc_dec_four:
1941	movaps	xmm14,xmm5
1942	call	_aesni_decrypt4
1943	pxor	xmm2,xmm10
1944	movaps	xmm10,xmm14
1945	pxor	xmm3,xmm11
1946	movdqu	XMMWORD[rsi],xmm2
1947	pxor	xmm4,xmm12
1948	movdqu	XMMWORD[16+rsi],xmm3
1949	pxor	xmm3,xmm3
1950	pxor	xmm5,xmm13
1951	movdqu	XMMWORD[32+rsi],xmm4
1952	pxor	xmm4,xmm4
1953	movdqa	xmm2,xmm5
1954	pxor	xmm5,xmm5
1955	lea	rsi,[48+rsi]
1956	jmp	NEAR $L$cbc_dec_tail_collected
1957
1958ALIGN	16
1959$L$cbc_dec_clear_tail_collected:
1960	pxor	xmm3,xmm3
1961	pxor	xmm4,xmm4
1962	pxor	xmm5,xmm5
1963$L$cbc_dec_tail_collected:
1964	movups	XMMWORD[r8],xmm10
1965	and	rdx,15
1966	jnz	NEAR $L$cbc_dec_tail_partial
1967	movups	XMMWORD[rsi],xmm2
1968	pxor	xmm2,xmm2
1969	jmp	NEAR $L$cbc_dec_ret
1970ALIGN	16
1971$L$cbc_dec_tail_partial:
1972	movaps	XMMWORD[rsp],xmm2
1973	pxor	xmm2,xmm2
1974	mov	rcx,16
1975	mov	rdi,rsi
1976	sub	rcx,rdx
1977	lea	rsi,[rsp]
1978	DD	0x9066A4F3
1979	movdqa	XMMWORD[rsp],xmm2
1980
1981$L$cbc_dec_ret:
1982	xorps	xmm0,xmm0
1983	pxor	xmm1,xmm1
1984	movaps	xmm6,XMMWORD[16+rsp]
1985	movaps	XMMWORD[16+rsp],xmm0
1986	movaps	xmm7,XMMWORD[32+rsp]
1987	movaps	XMMWORD[32+rsp],xmm0
1988	movaps	xmm8,XMMWORD[48+rsp]
1989	movaps	XMMWORD[48+rsp],xmm0
1990	movaps	xmm9,XMMWORD[64+rsp]
1991	movaps	XMMWORD[64+rsp],xmm0
1992	movaps	xmm10,XMMWORD[80+rsp]
1993	movaps	XMMWORD[80+rsp],xmm0
1994	movaps	xmm11,XMMWORD[96+rsp]
1995	movaps	XMMWORD[96+rsp],xmm0
1996	movaps	xmm12,XMMWORD[112+rsp]
1997	movaps	XMMWORD[112+rsp],xmm0
1998	movaps	xmm13,XMMWORD[128+rsp]
1999	movaps	XMMWORD[128+rsp],xmm0
2000	movaps	xmm14,XMMWORD[144+rsp]
2001	movaps	XMMWORD[144+rsp],xmm0
2002	movaps	xmm15,XMMWORD[160+rsp]
2003	movaps	XMMWORD[160+rsp],xmm0
2004	mov	rbp,QWORD[((-8))+r11]
2005
2006	lea	rsp,[r11]
2007
2008$L$cbc_ret:
2009	mov	rdi,QWORD[8+rsp]	;WIN64 epilogue
2010	mov	rsi,QWORD[16+rsp]
2011	ret
2012
2013$L$SEH_end_aes_hw_cbc_encrypt:
2014global	aes_hw_encrypt_key_to_decrypt_key
2015
2016ALIGN	16
2017aes_hw_encrypt_key_to_decrypt_key:
2018
2019_CET_ENDBR
2020
2021	mov	edx,DWORD[240+rcx]
2022	shl	edx,4
2023
2024	lea	r8,[16+rdx*1+rcx]
2025
2026	movups	xmm0,XMMWORD[rcx]
2027	movups	xmm1,XMMWORD[r8]
2028	movups	XMMWORD[r8],xmm0
2029	movups	XMMWORD[rcx],xmm1
2030	lea	rcx,[16+rcx]
2031	lea	r8,[((-16))+r8]
2032
2033$L$dec_key_inverse:
2034	movups	xmm0,XMMWORD[rcx]
2035	movups	xmm1,XMMWORD[r8]
2036	DB	102,15,56,219,192
2037	DB	102,15,56,219,201
2038	lea	rcx,[16+rcx]
2039	lea	r8,[((-16))+r8]
2040	movups	XMMWORD[16+r8],xmm0
2041	movups	XMMWORD[(-16)+rcx],xmm1
2042	cmp	r8,rcx
2043	ja	NEAR $L$dec_key_inverse
2044
2045	movups	xmm0,XMMWORD[rcx]
2046	DB	102,15,56,219,192
2047	pxor	xmm1,xmm1
2048	movups	XMMWORD[r8],xmm0
2049	pxor	xmm0,xmm0
2050	ret
2051
2052
2053global	aes_hw_set_encrypt_key_base
2054
2055ALIGN	16
2056aes_hw_set_encrypt_key_base:
2057
2058$L$SEH_begin_aes_hw_set_encrypt_key_base_1:
2059_CET_ENDBR
2060%ifdef BORINGSSL_DISPATCH_TEST
2061	mov	BYTE[((BORINGSSL_function_hit+3))],1
2062%endif
2063	sub	rsp,8
2064
2065$L$SEH_prologue_aes_hw_set_encrypt_key_base_2:
2066$L$SEH_endprologue_aes_hw_set_encrypt_key_base_3:
2067	movups	xmm0,XMMWORD[rcx]
2068	xorps	xmm4,xmm4
2069	lea	rax,[16+r8]
2070	cmp	edx,256
2071	je	NEAR $L$14rounds
2072	cmp	edx,192
2073	je	NEAR $L$12rounds
2074	cmp	edx,128
2075	jne	NEAR $L$bad_keybits
2076
2077$L$10rounds:
2078	mov	edx,9
2079
2080	movups	XMMWORD[r8],xmm0
2081	DB	102,15,58,223,200,1
2082	call	$L$key_expansion_128_cold
2083	DB	102,15,58,223,200,2
2084	call	$L$key_expansion_128
2085	DB	102,15,58,223,200,4
2086	call	$L$key_expansion_128
2087	DB	102,15,58,223,200,8
2088	call	$L$key_expansion_128
2089	DB	102,15,58,223,200,16
2090	call	$L$key_expansion_128
2091	DB	102,15,58,223,200,32
2092	call	$L$key_expansion_128
2093	DB	102,15,58,223,200,64
2094	call	$L$key_expansion_128
2095	DB	102,15,58,223,200,128
2096	call	$L$key_expansion_128
2097	DB	102,15,58,223,200,27
2098	call	$L$key_expansion_128
2099	DB	102,15,58,223,200,54
2100	call	$L$key_expansion_128
2101	movups	XMMWORD[rax],xmm0
2102	mov	DWORD[80+rax],edx
2103	xor	eax,eax
2104	jmp	NEAR $L$enc_key_ret
2105
2106ALIGN	16
2107$L$12rounds:
2108	movq	xmm2,QWORD[16+rcx]
2109	mov	edx,11
2110
2111	movups	XMMWORD[r8],xmm0
2112	DB	102,15,58,223,202,1
2113	call	$L$key_expansion_192a_cold
2114	DB	102,15,58,223,202,2
2115	call	$L$key_expansion_192b
2116	DB	102,15,58,223,202,4
2117	call	$L$key_expansion_192a
2118	DB	102,15,58,223,202,8
2119	call	$L$key_expansion_192b
2120	DB	102,15,58,223,202,16
2121	call	$L$key_expansion_192a
2122	DB	102,15,58,223,202,32
2123	call	$L$key_expansion_192b
2124	DB	102,15,58,223,202,64
2125	call	$L$key_expansion_192a
2126	DB	102,15,58,223,202,128
2127	call	$L$key_expansion_192b
2128	movups	XMMWORD[rax],xmm0
2129	mov	DWORD[48+rax],edx
2130	xor	rax,rax
2131	jmp	NEAR $L$enc_key_ret
2132
2133ALIGN	16
2134$L$14rounds:
2135	movups	xmm2,XMMWORD[16+rcx]
2136	mov	edx,13
2137	lea	rax,[16+rax]
2138
2139	movups	XMMWORD[r8],xmm0
2140	movups	XMMWORD[16+r8],xmm2
2141	DB	102,15,58,223,202,1
2142	call	$L$key_expansion_256a_cold
2143	DB	102,15,58,223,200,1
2144	call	$L$key_expansion_256b
2145	DB	102,15,58,223,202,2
2146	call	$L$key_expansion_256a
2147	DB	102,15,58,223,200,2
2148	call	$L$key_expansion_256b
2149	DB	102,15,58,223,202,4
2150	call	$L$key_expansion_256a
2151	DB	102,15,58,223,200,4
2152	call	$L$key_expansion_256b
2153	DB	102,15,58,223,202,8
2154	call	$L$key_expansion_256a
2155	DB	102,15,58,223,200,8
2156	call	$L$key_expansion_256b
2157	DB	102,15,58,223,202,16
2158	call	$L$key_expansion_256a
2159	DB	102,15,58,223,200,16
2160	call	$L$key_expansion_256b
2161	DB	102,15,58,223,202,32
2162	call	$L$key_expansion_256a
2163	DB	102,15,58,223,200,32
2164	call	$L$key_expansion_256b
2165	DB	102,15,58,223,202,64
2166	call	$L$key_expansion_256a
2167	movups	XMMWORD[rax],xmm0
2168	mov	DWORD[16+rax],edx
2169	xor	rax,rax
2170	jmp	NEAR $L$enc_key_ret
2171
2172ALIGN	16
2173$L$bad_keybits:
2174	mov	rax,-2
2175$L$enc_key_ret:
2176	pxor	xmm0,xmm0
2177	pxor	xmm1,xmm1
2178	pxor	xmm2,xmm2
2179	pxor	xmm3,xmm3
2180	pxor	xmm4,xmm4
2181	pxor	xmm5,xmm5
2182	add	rsp,8
2183
2184	ret
2185
2186$L$SEH_end_aes_hw_set_encrypt_key_base_4:
2187
2188ALIGN	16
2189$L$key_expansion_128:
2190
2191	movups	XMMWORD[rax],xmm0
2192	lea	rax,[16+rax]
2193$L$key_expansion_128_cold:
2194	shufps	xmm4,xmm0,16
2195	xorps	xmm0,xmm4
2196	shufps	xmm4,xmm0,140
2197	xorps	xmm0,xmm4
2198	shufps	xmm1,xmm1,255
2199	xorps	xmm0,xmm1
2200	ret
2201
2202
2203ALIGN	16
2204$L$key_expansion_192a:
2205
2206	movups	XMMWORD[rax],xmm0
2207	lea	rax,[16+rax]
2208$L$key_expansion_192a_cold:
2209	movaps	xmm5,xmm2
2210$L$key_expansion_192b_warm:
2211	shufps	xmm4,xmm0,16
2212	movdqa	xmm3,xmm2
2213	xorps	xmm0,xmm4
2214	shufps	xmm4,xmm0,140
2215	pslldq	xmm3,4
2216	xorps	xmm0,xmm4
2217	pshufd	xmm1,xmm1,85
2218	pxor	xmm2,xmm3
2219	pxor	xmm0,xmm1
2220	pshufd	xmm3,xmm0,255
2221	pxor	xmm2,xmm3
2222	ret
2223
2224
2225ALIGN	16
2226$L$key_expansion_192b:
2227
2228	movaps	xmm3,xmm0
2229	shufps	xmm5,xmm0,68
2230	movups	XMMWORD[rax],xmm5
2231	shufps	xmm3,xmm2,78
2232	movups	XMMWORD[16+rax],xmm3
2233	lea	rax,[32+rax]
2234	jmp	NEAR $L$key_expansion_192b_warm
2235
2236
2237ALIGN	16
2238$L$key_expansion_256a:
2239
2240	movups	XMMWORD[rax],xmm2
2241	lea	rax,[16+rax]
2242$L$key_expansion_256a_cold:
2243	shufps	xmm4,xmm0,16
2244	xorps	xmm0,xmm4
2245	shufps	xmm4,xmm0,140
2246	xorps	xmm0,xmm4
2247	shufps	xmm1,xmm1,255
2248	xorps	xmm0,xmm1
2249	ret
2250
2251
2252ALIGN	16
2253$L$key_expansion_256b:
2254
2255	movups	XMMWORD[rax],xmm0
2256	lea	rax,[16+rax]
2257
2258	shufps	xmm4,xmm2,16
2259	xorps	xmm2,xmm4
2260	shufps	xmm4,xmm2,140
2261	xorps	xmm2,xmm4
2262	shufps	xmm1,xmm1,170
2263	xorps	xmm2,xmm1
2264	ret
2265
2266
2267
2268global	aes_hw_set_encrypt_key_alt
2269
2270ALIGN	16
2271aes_hw_set_encrypt_key_alt:
2272
2273$L$SEH_begin_aes_hw_set_encrypt_key_alt_1:
2274_CET_ENDBR
2275%ifdef BORINGSSL_DISPATCH_TEST
2276	mov	BYTE[((BORINGSSL_function_hit+3))],1
2277%endif
2278	sub	rsp,8
2279
2280$L$SEH_prologue_aes_hw_set_encrypt_key_alt_2:
2281$L$SEH_endprologue_aes_hw_set_encrypt_key_alt_3:
2282	movups	xmm0,XMMWORD[rcx]
2283	xorps	xmm4,xmm4
2284	lea	rax,[16+r8]
2285	cmp	edx,256
2286	je	NEAR $L$14rounds_alt
2287	cmp	edx,192
2288	je	NEAR $L$12rounds_alt
2289	cmp	edx,128
2290	jne	NEAR $L$bad_keybits_alt
2291
2292	mov	edx,9
2293	movdqa	xmm5,XMMWORD[$L$key_rotate]
2294	mov	r10d,8
2295	movdqa	xmm4,XMMWORD[$L$key_rcon1]
2296	movdqa	xmm2,xmm0
2297	movdqu	XMMWORD[r8],xmm0
2298	jmp	NEAR $L$oop_key128
2299
2300ALIGN	16
2301$L$oop_key128:
2302DB	102,15,56,0,197
2303	DB	102,15,56,221,196
2304	pslld	xmm4,1
2305	lea	rax,[16+rax]
2306
2307	movdqa	xmm3,xmm2
2308	pslldq	xmm2,4
2309	pxor	xmm3,xmm2
2310	pslldq	xmm2,4
2311	pxor	xmm3,xmm2
2312	pslldq	xmm2,4
2313	pxor	xmm2,xmm3
2314
2315	pxor	xmm0,xmm2
2316	movdqu	XMMWORD[(-16)+rax],xmm0
2317	movdqa	xmm2,xmm0
2318
2319	dec	r10d
2320	jnz	NEAR $L$oop_key128
2321
2322	movdqa	xmm4,XMMWORD[$L$key_rcon1b]
2323
2324DB	102,15,56,0,197
2325	DB	102,15,56,221,196
2326	pslld	xmm4,1
2327
2328	movdqa	xmm3,xmm2
2329	pslldq	xmm2,4
2330	pxor	xmm3,xmm2
2331	pslldq	xmm2,4
2332	pxor	xmm3,xmm2
2333	pslldq	xmm2,4
2334	pxor	xmm2,xmm3
2335
2336	pxor	xmm0,xmm2
2337	movdqu	XMMWORD[rax],xmm0
2338
2339	movdqa	xmm2,xmm0
2340DB	102,15,56,0,197
2341	DB	102,15,56,221,196
2342
2343	movdqa	xmm3,xmm2
2344	pslldq	xmm2,4
2345	pxor	xmm3,xmm2
2346	pslldq	xmm2,4
2347	pxor	xmm3,xmm2
2348	pslldq	xmm2,4
2349	pxor	xmm2,xmm3
2350
2351	pxor	xmm0,xmm2
2352	movdqu	XMMWORD[16+rax],xmm0
2353
2354	mov	DWORD[96+rax],edx
2355	xor	eax,eax
2356	jmp	NEAR $L$enc_key_ret_alt
2357
2358ALIGN	16
2359$L$12rounds_alt:
2360	movq	xmm2,QWORD[16+rcx]
2361	mov	edx,11
2362	movdqa	xmm5,XMMWORD[$L$key_rotate192]
2363	movdqa	xmm4,XMMWORD[$L$key_rcon1]
2364	mov	r10d,8
2365	movdqu	XMMWORD[r8],xmm0
2366	jmp	NEAR $L$oop_key192
2367
2368ALIGN	16
2369$L$oop_key192:
2370	movq	QWORD[rax],xmm2
2371	movdqa	xmm1,xmm2
2372DB	102,15,56,0,213
2373	DB	102,15,56,221,212
2374	pslld	xmm4,1
2375	lea	rax,[24+rax]
2376
2377	movdqa	xmm3,xmm0
2378	pslldq	xmm0,4
2379	pxor	xmm3,xmm0
2380	pslldq	xmm0,4
2381	pxor	xmm3,xmm0
2382	pslldq	xmm0,4
2383	pxor	xmm0,xmm3
2384
2385	pshufd	xmm3,xmm0,0xff
2386	pxor	xmm3,xmm1
2387	pslldq	xmm1,4
2388	pxor	xmm3,xmm1
2389
2390	pxor	xmm0,xmm2
2391	pxor	xmm2,xmm3
2392	movdqu	XMMWORD[(-16)+rax],xmm0
2393
2394	dec	r10d
2395	jnz	NEAR $L$oop_key192
2396
2397	mov	DWORD[32+rax],edx
2398	xor	eax,eax
2399	jmp	NEAR $L$enc_key_ret_alt
2400
2401ALIGN	16
2402$L$14rounds_alt:
2403	movups	xmm2,XMMWORD[16+rcx]
2404	mov	edx,13
2405	lea	rax,[16+rax]
2406	movdqa	xmm5,XMMWORD[$L$key_rotate]
2407	movdqa	xmm4,XMMWORD[$L$key_rcon1]
2408	mov	r10d,7
2409	movdqu	XMMWORD[r8],xmm0
2410	movdqa	xmm1,xmm2
2411	movdqu	XMMWORD[16+r8],xmm2
2412	jmp	NEAR $L$oop_key256
2413
2414ALIGN	16
2415$L$oop_key256:
2416DB	102,15,56,0,213
2417	DB	102,15,56,221,212
2418
2419	movdqa	xmm3,xmm0
2420	pslldq	xmm0,4
2421	pxor	xmm3,xmm0
2422	pslldq	xmm0,4
2423	pxor	xmm3,xmm0
2424	pslldq	xmm0,4
2425	pxor	xmm0,xmm3
2426	pslld	xmm4,1
2427
2428	pxor	xmm0,xmm2
2429	movdqu	XMMWORD[rax],xmm0
2430
2431	dec	r10d
2432	jz	NEAR $L$done_key256
2433
2434	pshufd	xmm2,xmm0,0xff
2435	pxor	xmm3,xmm3
2436	DB	102,15,56,221,211
2437
2438	movdqa	xmm3,xmm1
2439	pslldq	xmm1,4
2440	pxor	xmm3,xmm1
2441	pslldq	xmm1,4
2442	pxor	xmm3,xmm1
2443	pslldq	xmm1,4
2444	pxor	xmm1,xmm3
2445
2446	pxor	xmm2,xmm1
2447	movdqu	XMMWORD[16+rax],xmm2
2448	lea	rax,[32+rax]
2449	movdqa	xmm1,xmm2
2450
2451	jmp	NEAR $L$oop_key256
2452
2453$L$done_key256:
2454	mov	DWORD[16+rax],edx
2455	xor	eax,eax
2456	jmp	NEAR $L$enc_key_ret_alt
2457
2458ALIGN	16
2459$L$bad_keybits_alt:
2460	mov	rax,-2
2461$L$enc_key_ret_alt:
2462	pxor	xmm0,xmm0
2463	pxor	xmm1,xmm1
2464	pxor	xmm2,xmm2
2465	pxor	xmm3,xmm3
2466	pxor	xmm4,xmm4
2467	pxor	xmm5,xmm5
2468	add	rsp,8
2469
2470	ret
2471
2472$L$SEH_end_aes_hw_set_encrypt_key_alt_4:
2473
2474section	.rdata rdata align=8
2475ALIGN	64
2476$L$bswap_mask:
2477	DB	15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
2478$L$increment32:
2479	DD	6,6,6,0
2480$L$increment64:
2481	DD	1,0,0,0
2482$L$xts_magic:
2483	DD	0x87,0,1,0
2484$L$increment1:
2485	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
2486$L$key_rotate:
2487	DD	0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d
2488$L$key_rotate192:
2489	DD	0x04070605,0x04070605,0x04070605,0x04070605
2490$L$key_rcon1:
2491	DD	1,1,1,1
2492$L$key_rcon1b:
2493	DD	0x1b,0x1b,0x1b,0x1b
2494
2495	DB	65,69,83,32,102,111,114,32,73,110,116,101,108,32,65,69
2496	DB	83,45,78,73,44,32,67,82,89,80,84,79,71,65,77,83
2497	DB	32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115
2498	DB	115,108,46,111,114,103,62,0
2499ALIGN	64
2500section	.text
2501
2502EXTERN	__imp_RtlVirtualUnwind
2503
2504ALIGN	16
2505ecb_ccm64_se_handler:
2506	push	rsi
2507	push	rdi
2508	push	rbx
2509	push	rbp
2510	push	r12
2511	push	r13
2512	push	r14
2513	push	r15
2514	pushfq
2515	sub	rsp,64
2516
2517	mov	rax,QWORD[120+r8]
2518	mov	rbx,QWORD[248+r8]
2519
2520	mov	rsi,QWORD[8+r9]
2521	mov	r11,QWORD[56+r9]
2522
2523	mov	r10d,DWORD[r11]
2524	lea	r10,[r10*1+rsi]
2525	cmp	rbx,r10
2526	jb	NEAR $L$common_seh_tail
2527
2528	mov	rax,QWORD[152+r8]
2529
2530	mov	r10d,DWORD[4+r11]
2531	lea	r10,[r10*1+rsi]
2532	cmp	rbx,r10
2533	jae	NEAR $L$common_seh_tail
2534
2535	lea	rsi,[rax]
2536	lea	rdi,[512+r8]
2537	mov	ecx,8
2538	DD	0xa548f3fc
2539	lea	rax,[88+rax]
2540
2541	jmp	NEAR $L$common_seh_tail
2542
2543
2544
2545ALIGN	16
2546ctr_xts_se_handler:
2547	push	rsi
2548	push	rdi
2549	push	rbx
2550	push	rbp
2551	push	r12
2552	push	r13
2553	push	r14
2554	push	r15
2555	pushfq
2556	sub	rsp,64
2557
2558	mov	rax,QWORD[120+r8]
2559	mov	rbx,QWORD[248+r8]
2560
2561	mov	rsi,QWORD[8+r9]
2562	mov	r11,QWORD[56+r9]
2563
2564	mov	r10d,DWORD[r11]
2565	lea	r10,[r10*1+rsi]
2566	cmp	rbx,r10
2567	jb	NEAR $L$common_seh_tail
2568
2569	mov	rax,QWORD[152+r8]
2570
2571	mov	r10d,DWORD[4+r11]
2572	lea	r10,[r10*1+rsi]
2573	cmp	rbx,r10
2574	jae	NEAR $L$common_seh_tail
2575
2576	mov	rax,QWORD[208+r8]
2577
2578	lea	rsi,[((-168))+rax]
2579	lea	rdi,[512+r8]
2580	mov	ecx,20
2581	DD	0xa548f3fc
2582
2583	mov	rbp,QWORD[((-8))+rax]
2584	mov	QWORD[160+r8],rbp
2585	jmp	NEAR $L$common_seh_tail
2586
2587
2588
2589ALIGN	16
2590cbc_se_handler:
2591	push	rsi
2592	push	rdi
2593	push	rbx
2594	push	rbp
2595	push	r12
2596	push	r13
2597	push	r14
2598	push	r15
2599	pushfq
2600	sub	rsp,64
2601
2602	mov	rax,QWORD[152+r8]
2603	mov	rbx,QWORD[248+r8]
2604
2605	lea	r10,[$L$cbc_decrypt_bulk]
2606	cmp	rbx,r10
2607	jb	NEAR $L$common_seh_tail
2608
2609	mov	rax,QWORD[120+r8]
2610
2611	lea	r10,[$L$cbc_decrypt_body]
2612	cmp	rbx,r10
2613	jb	NEAR $L$common_seh_tail
2614
2615	mov	rax,QWORD[152+r8]
2616
2617	lea	r10,[$L$cbc_ret]
2618	cmp	rbx,r10
2619	jae	NEAR $L$common_seh_tail
2620
2621	lea	rsi,[16+rax]
2622	lea	rdi,[512+r8]
2623	mov	ecx,20
2624	DD	0xa548f3fc
2625
2626	mov	rax,QWORD[208+r8]
2627
2628	mov	rbp,QWORD[((-8))+rax]
2629	mov	QWORD[160+r8],rbp
2630
2631$L$common_seh_tail:
2632	mov	rdi,QWORD[8+rax]
2633	mov	rsi,QWORD[16+rax]
2634	mov	QWORD[152+r8],rax
2635	mov	QWORD[168+r8],rsi
2636	mov	QWORD[176+r8],rdi
2637
2638	mov	rdi,QWORD[40+r9]
2639	mov	rsi,r8
2640	mov	ecx,154
2641	DD	0xa548f3fc
2642
2643	mov	rsi,r9
2644	xor	rcx,rcx
2645	mov	rdx,QWORD[8+rsi]
2646	mov	r8,QWORD[rsi]
2647	mov	r9,QWORD[16+rsi]
2648	mov	r10,QWORD[40+rsi]
2649	lea	r11,[56+rsi]
2650	lea	r12,[24+rsi]
2651	mov	QWORD[32+rsp],r10
2652	mov	QWORD[40+rsp],r11
2653	mov	QWORD[48+rsp],r12
2654	mov	QWORD[56+rsp],rcx
2655	call	QWORD[__imp_RtlVirtualUnwind]
2656
2657	mov	eax,1
2658	add	rsp,64
2659	popfq
2660	pop	r15
2661	pop	r14
2662	pop	r13
2663	pop	r12
2664	pop	rbp
2665	pop	rbx
2666	pop	rdi
2667	pop	rsi
2668	ret
2669
2670
2671section	.pdata rdata align=4
2672ALIGN	4
2673	DD	$L$SEH_begin_aes_hw_ecb_encrypt wrt ..imagebase
2674	DD	$L$SEH_end_aes_hw_ecb_encrypt wrt ..imagebase
2675	DD	$L$SEH_info_ecb wrt ..imagebase
2676
2677	DD	$L$SEH_begin_aes_hw_ctr32_encrypt_blocks wrt ..imagebase
2678	DD	$L$SEH_end_aes_hw_ctr32_encrypt_blocks wrt ..imagebase
2679	DD	$L$SEH_info_ctr32 wrt ..imagebase
2680	DD	$L$SEH_begin_aes_hw_cbc_encrypt wrt ..imagebase
2681	DD	$L$SEH_end_aes_hw_cbc_encrypt wrt ..imagebase
2682	DD	$L$SEH_info_cbc wrt ..imagebase
2683section	.xdata rdata align=8
2684ALIGN	8
2685$L$SEH_info_ecb:
2686	DB	9,0,0,0
2687	DD	ecb_ccm64_se_handler wrt ..imagebase
2688	DD	$L$ecb_enc_body wrt ..imagebase,$L$ecb_enc_ret wrt ..imagebase
2689$L$SEH_info_ctr32:
2690	DB	9,0,0,0
2691	DD	ctr_xts_se_handler wrt ..imagebase
2692	DD	$L$ctr32_body wrt ..imagebase,$L$ctr32_epilogue wrt ..imagebase
2693$L$SEH_info_cbc:
2694	DB	9,0,0,0
2695	DD	cbc_se_handler wrt ..imagebase
2696section	.pdata
2697ALIGN	4
2698	DD	$L$SEH_begin_aes_hw_set_encrypt_key_base_1 wrt ..imagebase
2699	DD	$L$SEH_end_aes_hw_set_encrypt_key_base_4 wrt ..imagebase
2700	DD	$L$SEH_info_aes_hw_set_encrypt_key_base_0 wrt ..imagebase
2701
2702	DD	$L$SEH_begin_aes_hw_set_encrypt_key_alt_1 wrt ..imagebase
2703	DD	$L$SEH_end_aes_hw_set_encrypt_key_alt_4 wrt ..imagebase
2704	DD	$L$SEH_info_aes_hw_set_encrypt_key_alt_0 wrt ..imagebase
2705
2706
2707section	.xdata
2708ALIGN	4
2709$L$SEH_info_aes_hw_set_encrypt_key_base_0:
2710	DB	1
2711	DB	$L$SEH_endprologue_aes_hw_set_encrypt_key_base_3-$L$SEH_begin_aes_hw_set_encrypt_key_base_1
2712	DB	1
2713	DB	0
2714	DB	$L$SEH_prologue_aes_hw_set_encrypt_key_base_2-$L$SEH_begin_aes_hw_set_encrypt_key_base_1
2715	DB	2
2716
2717	DW	0
2718$L$SEH_info_aes_hw_set_encrypt_key_alt_0:
2719	DB	1
2720	DB	$L$SEH_endprologue_aes_hw_set_encrypt_key_alt_3-$L$SEH_begin_aes_hw_set_encrypt_key_alt_1
2721	DB	1
2722	DB	0
2723	DB	$L$SEH_prologue_aes_hw_set_encrypt_key_alt_2-$L$SEH_begin_aes_hw_set_encrypt_key_alt_1
2724	DB	2
2725
2726	DW	0
2727%else
2728; Work around https://bugzilla.nasm.us/show_bug.cgi?id=3392738
2729ret
2730%endif
2731