• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.text
2
3.type	_aesni_ctr32_ghash_6x,@function
4.align	32
5_aesni_ctr32_ghash_6x:
6.cfi_startproc
7	vmovdqu	32(%r11),%xmm2
8	subq	$6,%rdx
9	vpxor	%xmm4,%xmm4,%xmm4
10	vmovdqu	0-128(%rcx),%xmm15
11	vpaddb	%xmm2,%xmm1,%xmm10
12	vpaddb	%xmm2,%xmm10,%xmm11
13	vpaddb	%xmm2,%xmm11,%xmm12
14	vpaddb	%xmm2,%xmm12,%xmm13
15	vpaddb	%xmm2,%xmm13,%xmm14
16	vpxor	%xmm15,%xmm1,%xmm9
17	vmovdqu	%xmm4,16+8(%rsp)
18	jmp	.Loop6x
19
20.align	32
21.Loop6x:
22	addl	$100663296,%ebx
23	jc	.Lhandle_ctr32
24	vmovdqu	0-32(%r9),%xmm3
25	vpaddb	%xmm2,%xmm14,%xmm1
26	vpxor	%xmm15,%xmm10,%xmm10
27	vpxor	%xmm15,%xmm11,%xmm11
28
29.Lresume_ctr32:
30	vmovdqu	%xmm1,(%r8)
31	vpclmulqdq	$0x10,%xmm3,%xmm7,%xmm5
32	vpxor	%xmm15,%xmm12,%xmm12
33	vmovups	16-128(%rcx),%xmm2
34	vpclmulqdq	$0x01,%xmm3,%xmm7,%xmm6
35	xorq	%r12,%r12
36	cmpq	%r14,%r15
37
38	vaesenc	%xmm2,%xmm9,%xmm9
39	vmovdqu	48+8(%rsp),%xmm0
40	vpxor	%xmm15,%xmm13,%xmm13
41	vpclmulqdq	$0x00,%xmm3,%xmm7,%xmm1
42	vaesenc	%xmm2,%xmm10,%xmm10
43	vpxor	%xmm15,%xmm14,%xmm14
44	setnc	%r12b
45	vpclmulqdq	$0x11,%xmm3,%xmm7,%xmm7
46	vaesenc	%xmm2,%xmm11,%xmm11
47	vmovdqu	16-32(%r9),%xmm3
48	negq	%r12
49	vaesenc	%xmm2,%xmm12,%xmm12
50	vpxor	%xmm5,%xmm6,%xmm6
51	vpclmulqdq	$0x00,%xmm3,%xmm0,%xmm5
52	vpxor	%xmm4,%xmm8,%xmm8
53	vaesenc	%xmm2,%xmm13,%xmm13
54	vpxor	%xmm5,%xmm1,%xmm4
55	andq	$0x60,%r12
56	vmovups	32-128(%rcx),%xmm15
57	vpclmulqdq	$0x10,%xmm3,%xmm0,%xmm1
58	vaesenc	%xmm2,%xmm14,%xmm14
59
60	vpclmulqdq	$0x01,%xmm3,%xmm0,%xmm2
61	leaq	(%r14,%r12,1),%r14
62	vaesenc	%xmm15,%xmm9,%xmm9
63	vpxor	16+8(%rsp),%xmm8,%xmm8
64	vpclmulqdq	$0x11,%xmm3,%xmm0,%xmm3
65	vmovdqu	64+8(%rsp),%xmm0
66	vaesenc	%xmm15,%xmm10,%xmm10
67	movbeq	88(%r14),%r13
68	vaesenc	%xmm15,%xmm11,%xmm11
69	movbeq	80(%r14),%r12
70	vaesenc	%xmm15,%xmm12,%xmm12
71	movq	%r13,32+8(%rsp)
72	vaesenc	%xmm15,%xmm13,%xmm13
73	movq	%r12,40+8(%rsp)
74	vmovdqu	48-32(%r9),%xmm5
75	vaesenc	%xmm15,%xmm14,%xmm14
76
77	vmovups	48-128(%rcx),%xmm15
78	vpxor	%xmm1,%xmm6,%xmm6
79	vpclmulqdq	$0x00,%xmm5,%xmm0,%xmm1
80	vaesenc	%xmm15,%xmm9,%xmm9
81	vpxor	%xmm2,%xmm6,%xmm6
82	vpclmulqdq	$0x10,%xmm5,%xmm0,%xmm2
83	vaesenc	%xmm15,%xmm10,%xmm10
84	vpxor	%xmm3,%xmm7,%xmm7
85	vpclmulqdq	$0x01,%xmm5,%xmm0,%xmm3
86	vaesenc	%xmm15,%xmm11,%xmm11
87	vpclmulqdq	$0x11,%xmm5,%xmm0,%xmm5
88	vmovdqu	80+8(%rsp),%xmm0
89	vaesenc	%xmm15,%xmm12,%xmm12
90	vaesenc	%xmm15,%xmm13,%xmm13
91	vpxor	%xmm1,%xmm4,%xmm4
92	vmovdqu	64-32(%r9),%xmm1
93	vaesenc	%xmm15,%xmm14,%xmm14
94
95	vmovups	64-128(%rcx),%xmm15
96	vpxor	%xmm2,%xmm6,%xmm6
97	vpclmulqdq	$0x00,%xmm1,%xmm0,%xmm2
98	vaesenc	%xmm15,%xmm9,%xmm9
99	vpxor	%xmm3,%xmm6,%xmm6
100	vpclmulqdq	$0x10,%xmm1,%xmm0,%xmm3
101	vaesenc	%xmm15,%xmm10,%xmm10
102	movbeq	72(%r14),%r13
103	vpxor	%xmm5,%xmm7,%xmm7
104	vpclmulqdq	$0x01,%xmm1,%xmm0,%xmm5
105	vaesenc	%xmm15,%xmm11,%xmm11
106	movbeq	64(%r14),%r12
107	vpclmulqdq	$0x11,%xmm1,%xmm0,%xmm1
108	vmovdqu	96+8(%rsp),%xmm0
109	vaesenc	%xmm15,%xmm12,%xmm12
110	movq	%r13,48+8(%rsp)
111	vaesenc	%xmm15,%xmm13,%xmm13
112	movq	%r12,56+8(%rsp)
113	vpxor	%xmm2,%xmm4,%xmm4
114	vmovdqu	96-32(%r9),%xmm2
115	vaesenc	%xmm15,%xmm14,%xmm14
116
117	vmovups	80-128(%rcx),%xmm15
118	vpxor	%xmm3,%xmm6,%xmm6
119	vpclmulqdq	$0x00,%xmm2,%xmm0,%xmm3
120	vaesenc	%xmm15,%xmm9,%xmm9
121	vpxor	%xmm5,%xmm6,%xmm6
122	vpclmulqdq	$0x10,%xmm2,%xmm0,%xmm5
123	vaesenc	%xmm15,%xmm10,%xmm10
124	movbeq	56(%r14),%r13
125	vpxor	%xmm1,%xmm7,%xmm7
126	vpclmulqdq	$0x01,%xmm2,%xmm0,%xmm1
127	vpxor	112+8(%rsp),%xmm8,%xmm8
128	vaesenc	%xmm15,%xmm11,%xmm11
129	movbeq	48(%r14),%r12
130	vpclmulqdq	$0x11,%xmm2,%xmm0,%xmm2
131	vaesenc	%xmm15,%xmm12,%xmm12
132	movq	%r13,64+8(%rsp)
133	vaesenc	%xmm15,%xmm13,%xmm13
134	movq	%r12,72+8(%rsp)
135	vpxor	%xmm3,%xmm4,%xmm4
136	vmovdqu	112-32(%r9),%xmm3
137	vaesenc	%xmm15,%xmm14,%xmm14
138
139	vmovups	96-128(%rcx),%xmm15
140	vpxor	%xmm5,%xmm6,%xmm6
141	vpclmulqdq	$0x10,%xmm3,%xmm8,%xmm5
142	vaesenc	%xmm15,%xmm9,%xmm9
143	vpxor	%xmm1,%xmm6,%xmm6
144	vpclmulqdq	$0x01,%xmm3,%xmm8,%xmm1
145	vaesenc	%xmm15,%xmm10,%xmm10
146	movbeq	40(%r14),%r13
147	vpxor	%xmm2,%xmm7,%xmm7
148	vpclmulqdq	$0x00,%xmm3,%xmm8,%xmm2
149	vaesenc	%xmm15,%xmm11,%xmm11
150	movbeq	32(%r14),%r12
151	vpclmulqdq	$0x11,%xmm3,%xmm8,%xmm8
152	vaesenc	%xmm15,%xmm12,%xmm12
153	movq	%r13,80+8(%rsp)
154	vaesenc	%xmm15,%xmm13,%xmm13
155	movq	%r12,88+8(%rsp)
156	vpxor	%xmm5,%xmm6,%xmm6
157	vaesenc	%xmm15,%xmm14,%xmm14
158	vpxor	%xmm1,%xmm6,%xmm6
159
160	vmovups	112-128(%rcx),%xmm15
161	vpslldq	$8,%xmm6,%xmm5
162	vpxor	%xmm2,%xmm4,%xmm4
163	vmovdqu	16(%r11),%xmm3
164
165	vaesenc	%xmm15,%xmm9,%xmm9
166	vpxor	%xmm8,%xmm7,%xmm7
167	vaesenc	%xmm15,%xmm10,%xmm10
168	vpxor	%xmm5,%xmm4,%xmm4
169	movbeq	24(%r14),%r13
170	vaesenc	%xmm15,%xmm11,%xmm11
171	movbeq	16(%r14),%r12
172	vpalignr	$8,%xmm4,%xmm4,%xmm0
173	vpclmulqdq	$0x10,%xmm3,%xmm4,%xmm4
174	movq	%r13,96+8(%rsp)
175	vaesenc	%xmm15,%xmm12,%xmm12
176	movq	%r12,104+8(%rsp)
177	vaesenc	%xmm15,%xmm13,%xmm13
178	vmovups	128-128(%rcx),%xmm1
179	vaesenc	%xmm15,%xmm14,%xmm14
180
181	vaesenc	%xmm1,%xmm9,%xmm9
182	vmovups	144-128(%rcx),%xmm15
183	vaesenc	%xmm1,%xmm10,%xmm10
184	vpsrldq	$8,%xmm6,%xmm6
185	vaesenc	%xmm1,%xmm11,%xmm11
186	vpxor	%xmm6,%xmm7,%xmm7
187	vaesenc	%xmm1,%xmm12,%xmm12
188	vpxor	%xmm0,%xmm4,%xmm4
189	movbeq	8(%r14),%r13
190	vaesenc	%xmm1,%xmm13,%xmm13
191	movbeq	0(%r14),%r12
192	vaesenc	%xmm1,%xmm14,%xmm14
193	vmovups	160-128(%rcx),%xmm1
194	cmpl	$11,%ebp
195	jb	.Lenc_tail
196
197	vaesenc	%xmm15,%xmm9,%xmm9
198	vaesenc	%xmm15,%xmm10,%xmm10
199	vaesenc	%xmm15,%xmm11,%xmm11
200	vaesenc	%xmm15,%xmm12,%xmm12
201	vaesenc	%xmm15,%xmm13,%xmm13
202	vaesenc	%xmm15,%xmm14,%xmm14
203
204	vaesenc	%xmm1,%xmm9,%xmm9
205	vaesenc	%xmm1,%xmm10,%xmm10
206	vaesenc	%xmm1,%xmm11,%xmm11
207	vaesenc	%xmm1,%xmm12,%xmm12
208	vaesenc	%xmm1,%xmm13,%xmm13
209	vmovups	176-128(%rcx),%xmm15
210	vaesenc	%xmm1,%xmm14,%xmm14
211	vmovups	192-128(%rcx),%xmm1
212	je	.Lenc_tail
213
214	vaesenc	%xmm15,%xmm9,%xmm9
215	vaesenc	%xmm15,%xmm10,%xmm10
216	vaesenc	%xmm15,%xmm11,%xmm11
217	vaesenc	%xmm15,%xmm12,%xmm12
218	vaesenc	%xmm15,%xmm13,%xmm13
219	vaesenc	%xmm15,%xmm14,%xmm14
220
221	vaesenc	%xmm1,%xmm9,%xmm9
222	vaesenc	%xmm1,%xmm10,%xmm10
223	vaesenc	%xmm1,%xmm11,%xmm11
224	vaesenc	%xmm1,%xmm12,%xmm12
225	vaesenc	%xmm1,%xmm13,%xmm13
226	vmovups	208-128(%rcx),%xmm15
227	vaesenc	%xmm1,%xmm14,%xmm14
228	vmovups	224-128(%rcx),%xmm1
229	jmp	.Lenc_tail
230
231.align	32
232.Lhandle_ctr32:
233	vmovdqu	(%r11),%xmm0
234	vpshufb	%xmm0,%xmm1,%xmm6
235	vmovdqu	48(%r11),%xmm5
236	vpaddd	64(%r11),%xmm6,%xmm10
237	vpaddd	%xmm5,%xmm6,%xmm11
238	vmovdqu	0-32(%r9),%xmm3
239	vpaddd	%xmm5,%xmm10,%xmm12
240	vpshufb	%xmm0,%xmm10,%xmm10
241	vpaddd	%xmm5,%xmm11,%xmm13
242	vpshufb	%xmm0,%xmm11,%xmm11
243	vpxor	%xmm15,%xmm10,%xmm10
244	vpaddd	%xmm5,%xmm12,%xmm14
245	vpshufb	%xmm0,%xmm12,%xmm12
246	vpxor	%xmm15,%xmm11,%xmm11
247	vpaddd	%xmm5,%xmm13,%xmm1
248	vpshufb	%xmm0,%xmm13,%xmm13
249	vpshufb	%xmm0,%xmm14,%xmm14
250	vpshufb	%xmm0,%xmm1,%xmm1
251	jmp	.Lresume_ctr32
252
253.align	32
254.Lenc_tail:
255	vaesenc	%xmm15,%xmm9,%xmm9
256	vmovdqu	%xmm7,16+8(%rsp)
257	vpalignr	$8,%xmm4,%xmm4,%xmm8
258	vaesenc	%xmm15,%xmm10,%xmm10
259	vpclmulqdq	$0x10,%xmm3,%xmm4,%xmm4
260	vpxor	0(%rdi),%xmm1,%xmm2
261	vaesenc	%xmm15,%xmm11,%xmm11
262	vpxor	16(%rdi),%xmm1,%xmm0
263	vaesenc	%xmm15,%xmm12,%xmm12
264	vpxor	32(%rdi),%xmm1,%xmm5
265	vaesenc	%xmm15,%xmm13,%xmm13
266	vpxor	48(%rdi),%xmm1,%xmm6
267	vaesenc	%xmm15,%xmm14,%xmm14
268	vpxor	64(%rdi),%xmm1,%xmm7
269	vpxor	80(%rdi),%xmm1,%xmm3
270	vmovdqu	(%r8),%xmm1
271
272	vaesenclast	%xmm2,%xmm9,%xmm9
273	vmovdqu	32(%r11),%xmm2
274	vaesenclast	%xmm0,%xmm10,%xmm10
275	vpaddb	%xmm2,%xmm1,%xmm0
276	movq	%r13,112+8(%rsp)
277	leaq	96(%rdi),%rdi
278	vaesenclast	%xmm5,%xmm11,%xmm11
279	vpaddb	%xmm2,%xmm0,%xmm5
280	movq	%r12,120+8(%rsp)
281	leaq	96(%rsi),%rsi
282	vmovdqu	0-128(%rcx),%xmm15
283	vaesenclast	%xmm6,%xmm12,%xmm12
284	vpaddb	%xmm2,%xmm5,%xmm6
285	vaesenclast	%xmm7,%xmm13,%xmm13
286	vpaddb	%xmm2,%xmm6,%xmm7
287	vaesenclast	%xmm3,%xmm14,%xmm14
288	vpaddb	%xmm2,%xmm7,%xmm3
289
290	addq	$0x60,%r10
291	subq	$0x6,%rdx
292	jc	.L6x_done
293
294	vmovups	%xmm9,-96(%rsi)
295	vpxor	%xmm15,%xmm1,%xmm9
296	vmovups	%xmm10,-80(%rsi)
297	vmovdqa	%xmm0,%xmm10
298	vmovups	%xmm11,-64(%rsi)
299	vmovdqa	%xmm5,%xmm11
300	vmovups	%xmm12,-48(%rsi)
301	vmovdqa	%xmm6,%xmm12
302	vmovups	%xmm13,-32(%rsi)
303	vmovdqa	%xmm7,%xmm13
304	vmovups	%xmm14,-16(%rsi)
305	vmovdqa	%xmm3,%xmm14
306	vmovdqu	32+8(%rsp),%xmm7
307	jmp	.Loop6x
308
309.L6x_done:
310	vpxor	16+8(%rsp),%xmm8,%xmm8
311	vpxor	%xmm4,%xmm8,%xmm8
312
313	.byte	0xf3,0xc3
314.cfi_endproc
315.size	_aesni_ctr32_ghash_6x,.-_aesni_ctr32_ghash_6x
316.globl	aesni_gcm_decrypt
317.type	aesni_gcm_decrypt,@function
318.align	32
319aesni_gcm_decrypt:
320.cfi_startproc
321	xorq	%r10,%r10
322	cmpq	$0x60,%rdx
323	jb	.Lgcm_dec_abort
324
325	leaq	(%rsp),%rax
326.cfi_def_cfa_register	%rax
327	pushq	%rbx
328.cfi_offset	%rbx,-16
329	pushq	%rbp
330.cfi_offset	%rbp,-24
331	pushq	%r12
332.cfi_offset	%r12,-32
333	pushq	%r13
334.cfi_offset	%r13,-40
335	pushq	%r14
336.cfi_offset	%r14,-48
337	pushq	%r15
338.cfi_offset	%r15,-56
339	vzeroupper
340
341	vmovdqu	(%r8),%xmm1
342	addq	$-128,%rsp
343	movl	12(%r8),%ebx
344	leaq	.Lbswap_mask(%rip),%r11
345	leaq	-128(%rcx),%r14
346	movq	$0xf80,%r15
347	vmovdqu	(%r9),%xmm8
348	andq	$-128,%rsp
349	vmovdqu	(%r11),%xmm0
350	leaq	128(%rcx),%rcx
351	leaq	32+32(%r9),%r9
352	movl	240-128(%rcx),%ebp
353	vpshufb	%xmm0,%xmm8,%xmm8
354
355	andq	%r15,%r14
356	andq	%rsp,%r15
357	subq	%r14,%r15
358	jc	.Ldec_no_key_aliasing
359	cmpq	$768,%r15
360	jnc	.Ldec_no_key_aliasing
361	subq	%r15,%rsp
362.Ldec_no_key_aliasing:
363
364	vmovdqu	80(%rdi),%xmm7
365	leaq	(%rdi),%r14
366	vmovdqu	64(%rdi),%xmm4
367	leaq	-192(%rdi,%rdx,1),%r15
368	vmovdqu	48(%rdi),%xmm5
369	shrq	$4,%rdx
370	xorq	%r10,%r10
371	vmovdqu	32(%rdi),%xmm6
372	vpshufb	%xmm0,%xmm7,%xmm7
373	vmovdqu	16(%rdi),%xmm2
374	vpshufb	%xmm0,%xmm4,%xmm4
375	vmovdqu	(%rdi),%xmm3
376	vpshufb	%xmm0,%xmm5,%xmm5
377	vmovdqu	%xmm4,48(%rsp)
378	vpshufb	%xmm0,%xmm6,%xmm6
379	vmovdqu	%xmm5,64(%rsp)
380	vpshufb	%xmm0,%xmm2,%xmm2
381	vmovdqu	%xmm6,80(%rsp)
382	vpshufb	%xmm0,%xmm3,%xmm3
383	vmovdqu	%xmm2,96(%rsp)
384	vmovdqu	%xmm3,112(%rsp)
385
386	call	_aesni_ctr32_ghash_6x
387
388	vmovups	%xmm9,-96(%rsi)
389	vmovups	%xmm10,-80(%rsi)
390	vmovups	%xmm11,-64(%rsi)
391	vmovups	%xmm12,-48(%rsi)
392	vmovups	%xmm13,-32(%rsi)
393	vmovups	%xmm14,-16(%rsi)
394
395	vpshufb	(%r11),%xmm8,%xmm8
396	vmovdqu	%xmm8,-64(%r9)
397
398	vzeroupper
399	movq	-48(%rax),%r15
400.cfi_restore	%r15
401	movq	-40(%rax),%r14
402.cfi_restore	%r14
403	movq	-32(%rax),%r13
404.cfi_restore	%r13
405	movq	-24(%rax),%r12
406.cfi_restore	%r12
407	movq	-16(%rax),%rbp
408.cfi_restore	%rbp
409	movq	-8(%rax),%rbx
410.cfi_restore	%rbx
411	leaq	(%rax),%rsp
412.cfi_def_cfa_register	%rsp
413.Lgcm_dec_abort:
414	movq	%r10,%rax
415	.byte	0xf3,0xc3
416.cfi_endproc
417.size	aesni_gcm_decrypt,.-aesni_gcm_decrypt
418.type	_aesni_ctr32_6x,@function
419.align	32
420_aesni_ctr32_6x:
421.cfi_startproc
422	vmovdqu	0-128(%rcx),%xmm4
423	vmovdqu	32(%r11),%xmm2
424	leaq	-1(%rbp),%r13
425	vmovups	16-128(%rcx),%xmm15
426	leaq	32-128(%rcx),%r12
427	vpxor	%xmm4,%xmm1,%xmm9
428	addl	$100663296,%ebx
429	jc	.Lhandle_ctr32_2
430	vpaddb	%xmm2,%xmm1,%xmm10
431	vpaddb	%xmm2,%xmm10,%xmm11
432	vpxor	%xmm4,%xmm10,%xmm10
433	vpaddb	%xmm2,%xmm11,%xmm12
434	vpxor	%xmm4,%xmm11,%xmm11
435	vpaddb	%xmm2,%xmm12,%xmm13
436	vpxor	%xmm4,%xmm12,%xmm12
437	vpaddb	%xmm2,%xmm13,%xmm14
438	vpxor	%xmm4,%xmm13,%xmm13
439	vpaddb	%xmm2,%xmm14,%xmm1
440	vpxor	%xmm4,%xmm14,%xmm14
441	jmp	.Loop_ctr32
442
443.align	16
444.Loop_ctr32:
445	vaesenc	%xmm15,%xmm9,%xmm9
446	vaesenc	%xmm15,%xmm10,%xmm10
447	vaesenc	%xmm15,%xmm11,%xmm11
448	vaesenc	%xmm15,%xmm12,%xmm12
449	vaesenc	%xmm15,%xmm13,%xmm13
450	vaesenc	%xmm15,%xmm14,%xmm14
451	vmovups	(%r12),%xmm15
452	leaq	16(%r12),%r12
453	decl	%r13d
454	jnz	.Loop_ctr32
455
456	vmovdqu	(%r12),%xmm3
457	vaesenc	%xmm15,%xmm9,%xmm9
458	vpxor	0(%rdi),%xmm3,%xmm4
459	vaesenc	%xmm15,%xmm10,%xmm10
460	vpxor	16(%rdi),%xmm3,%xmm5
461	vaesenc	%xmm15,%xmm11,%xmm11
462	vpxor	32(%rdi),%xmm3,%xmm6
463	vaesenc	%xmm15,%xmm12,%xmm12
464	vpxor	48(%rdi),%xmm3,%xmm8
465	vaesenc	%xmm15,%xmm13,%xmm13
466	vpxor	64(%rdi),%xmm3,%xmm2
467	vaesenc	%xmm15,%xmm14,%xmm14
468	vpxor	80(%rdi),%xmm3,%xmm3
469	leaq	96(%rdi),%rdi
470
471	vaesenclast	%xmm4,%xmm9,%xmm9
472	vaesenclast	%xmm5,%xmm10,%xmm10
473	vaesenclast	%xmm6,%xmm11,%xmm11
474	vaesenclast	%xmm8,%xmm12,%xmm12
475	vaesenclast	%xmm2,%xmm13,%xmm13
476	vaesenclast	%xmm3,%xmm14,%xmm14
477	vmovups	%xmm9,0(%rsi)
478	vmovups	%xmm10,16(%rsi)
479	vmovups	%xmm11,32(%rsi)
480	vmovups	%xmm12,48(%rsi)
481	vmovups	%xmm13,64(%rsi)
482	vmovups	%xmm14,80(%rsi)
483	leaq	96(%rsi),%rsi
484
485	.byte	0xf3,0xc3
486.align	32
487.Lhandle_ctr32_2:
488	vpshufb	%xmm0,%xmm1,%xmm6
489	vmovdqu	48(%r11),%xmm5
490	vpaddd	64(%r11),%xmm6,%xmm10
491	vpaddd	%xmm5,%xmm6,%xmm11
492	vpaddd	%xmm5,%xmm10,%xmm12
493	vpshufb	%xmm0,%xmm10,%xmm10
494	vpaddd	%xmm5,%xmm11,%xmm13
495	vpshufb	%xmm0,%xmm11,%xmm11
496	vpxor	%xmm4,%xmm10,%xmm10
497	vpaddd	%xmm5,%xmm12,%xmm14
498	vpshufb	%xmm0,%xmm12,%xmm12
499	vpxor	%xmm4,%xmm11,%xmm11
500	vpaddd	%xmm5,%xmm13,%xmm1
501	vpshufb	%xmm0,%xmm13,%xmm13
502	vpxor	%xmm4,%xmm12,%xmm12
503	vpshufb	%xmm0,%xmm14,%xmm14
504	vpxor	%xmm4,%xmm13,%xmm13
505	vpshufb	%xmm0,%xmm1,%xmm1
506	vpxor	%xmm4,%xmm14,%xmm14
507	jmp	.Loop_ctr32
508.cfi_endproc
509.size	_aesni_ctr32_6x,.-_aesni_ctr32_6x
510
511.globl	aesni_gcm_encrypt
512.type	aesni_gcm_encrypt,@function
513.align	32
514aesni_gcm_encrypt:
515.cfi_startproc
516	xorq	%r10,%r10
517	cmpq	$288,%rdx
518	jb	.Lgcm_enc_abort
519
520	leaq	(%rsp),%rax
521.cfi_def_cfa_register	%rax
522	pushq	%rbx
523.cfi_offset	%rbx,-16
524	pushq	%rbp
525.cfi_offset	%rbp,-24
526	pushq	%r12
527.cfi_offset	%r12,-32
528	pushq	%r13
529.cfi_offset	%r13,-40
530	pushq	%r14
531.cfi_offset	%r14,-48
532	pushq	%r15
533.cfi_offset	%r15,-56
534	vzeroupper
535
536	vmovdqu	(%r8),%xmm1
537	addq	$-128,%rsp
538	movl	12(%r8),%ebx
539	leaq	.Lbswap_mask(%rip),%r11
540	leaq	-128(%rcx),%r14
541	movq	$0xf80,%r15
542	leaq	128(%rcx),%rcx
543	vmovdqu	(%r11),%xmm0
544	andq	$-128,%rsp
545	movl	240-128(%rcx),%ebp
546
547	andq	%r15,%r14
548	andq	%rsp,%r15
549	subq	%r14,%r15
550	jc	.Lenc_no_key_aliasing
551	cmpq	$768,%r15
552	jnc	.Lenc_no_key_aliasing
553	subq	%r15,%rsp
554.Lenc_no_key_aliasing:
555
556	leaq	(%rsi),%r14
557	leaq	-192(%rsi,%rdx,1),%r15
558	shrq	$4,%rdx
559
560	call	_aesni_ctr32_6x
561	vpshufb	%xmm0,%xmm9,%xmm8
562	vpshufb	%xmm0,%xmm10,%xmm2
563	vmovdqu	%xmm8,112(%rsp)
564	vpshufb	%xmm0,%xmm11,%xmm4
565	vmovdqu	%xmm2,96(%rsp)
566	vpshufb	%xmm0,%xmm12,%xmm5
567	vmovdqu	%xmm4,80(%rsp)
568	vpshufb	%xmm0,%xmm13,%xmm6
569	vmovdqu	%xmm5,64(%rsp)
570	vpshufb	%xmm0,%xmm14,%xmm7
571	vmovdqu	%xmm6,48(%rsp)
572
573	call	_aesni_ctr32_6x
574
575	vmovdqu	(%r9),%xmm8
576	leaq	32+32(%r9),%r9
577	subq	$12,%rdx
578	movq	$192,%r10
579	vpshufb	%xmm0,%xmm8,%xmm8
580
581	call	_aesni_ctr32_ghash_6x
582	vmovdqu	32(%rsp),%xmm7
583	vmovdqu	(%r11),%xmm0
584	vmovdqu	0-32(%r9),%xmm3
585	vpunpckhqdq	%xmm7,%xmm7,%xmm1
586	vmovdqu	32-32(%r9),%xmm15
587	vmovups	%xmm9,-96(%rsi)
588	vpshufb	%xmm0,%xmm9,%xmm9
589	vpxor	%xmm7,%xmm1,%xmm1
590	vmovups	%xmm10,-80(%rsi)
591	vpshufb	%xmm0,%xmm10,%xmm10
592	vmovups	%xmm11,-64(%rsi)
593	vpshufb	%xmm0,%xmm11,%xmm11
594	vmovups	%xmm12,-48(%rsi)
595	vpshufb	%xmm0,%xmm12,%xmm12
596	vmovups	%xmm13,-32(%rsi)
597	vpshufb	%xmm0,%xmm13,%xmm13
598	vmovups	%xmm14,-16(%rsi)
599	vpshufb	%xmm0,%xmm14,%xmm14
600	vmovdqu	%xmm9,16(%rsp)
601	vmovdqu	48(%rsp),%xmm6
602	vmovdqu	16-32(%r9),%xmm0
603	vpunpckhqdq	%xmm6,%xmm6,%xmm2
604	vpclmulqdq	$0x00,%xmm3,%xmm7,%xmm5
605	vpxor	%xmm6,%xmm2,%xmm2
606	vpclmulqdq	$0x11,%xmm3,%xmm7,%xmm7
607	vpclmulqdq	$0x00,%xmm15,%xmm1,%xmm1
608
609	vmovdqu	64(%rsp),%xmm9
610	vpclmulqdq	$0x00,%xmm0,%xmm6,%xmm4
611	vmovdqu	48-32(%r9),%xmm3
612	vpxor	%xmm5,%xmm4,%xmm4
613	vpunpckhqdq	%xmm9,%xmm9,%xmm5
614	vpclmulqdq	$0x11,%xmm0,%xmm6,%xmm6
615	vpxor	%xmm9,%xmm5,%xmm5
616	vpxor	%xmm7,%xmm6,%xmm6
617	vpclmulqdq	$0x10,%xmm15,%xmm2,%xmm2
618	vmovdqu	80-32(%r9),%xmm15
619	vpxor	%xmm1,%xmm2,%xmm2
620
621	vmovdqu	80(%rsp),%xmm1
622	vpclmulqdq	$0x00,%xmm3,%xmm9,%xmm7
623	vmovdqu	64-32(%r9),%xmm0
624	vpxor	%xmm4,%xmm7,%xmm7
625	vpunpckhqdq	%xmm1,%xmm1,%xmm4
626	vpclmulqdq	$0x11,%xmm3,%xmm9,%xmm9
627	vpxor	%xmm1,%xmm4,%xmm4
628	vpxor	%xmm6,%xmm9,%xmm9
629	vpclmulqdq	$0x00,%xmm15,%xmm5,%xmm5
630	vpxor	%xmm2,%xmm5,%xmm5
631
632	vmovdqu	96(%rsp),%xmm2
633	vpclmulqdq	$0x00,%xmm0,%xmm1,%xmm6
634	vmovdqu	96-32(%r9),%xmm3
635	vpxor	%xmm7,%xmm6,%xmm6
636	vpunpckhqdq	%xmm2,%xmm2,%xmm7
637	vpclmulqdq	$0x11,%xmm0,%xmm1,%xmm1
638	vpxor	%xmm2,%xmm7,%xmm7
639	vpxor	%xmm9,%xmm1,%xmm1
640	vpclmulqdq	$0x10,%xmm15,%xmm4,%xmm4
641	vmovdqu	128-32(%r9),%xmm15
642	vpxor	%xmm5,%xmm4,%xmm4
643
644	vpxor	112(%rsp),%xmm8,%xmm8
645	vpclmulqdq	$0x00,%xmm3,%xmm2,%xmm5
646	vmovdqu	112-32(%r9),%xmm0
647	vpunpckhqdq	%xmm8,%xmm8,%xmm9
648	vpxor	%xmm6,%xmm5,%xmm5
649	vpclmulqdq	$0x11,%xmm3,%xmm2,%xmm2
650	vpxor	%xmm8,%xmm9,%xmm9
651	vpxor	%xmm1,%xmm2,%xmm2
652	vpclmulqdq	$0x00,%xmm15,%xmm7,%xmm7
653	vpxor	%xmm4,%xmm7,%xmm4
654
655	vpclmulqdq	$0x00,%xmm0,%xmm8,%xmm6
656	vmovdqu	0-32(%r9),%xmm3
657	vpunpckhqdq	%xmm14,%xmm14,%xmm1
658	vpclmulqdq	$0x11,%xmm0,%xmm8,%xmm8
659	vpxor	%xmm14,%xmm1,%xmm1
660	vpxor	%xmm5,%xmm6,%xmm5
661	vpclmulqdq	$0x10,%xmm15,%xmm9,%xmm9
662	vmovdqu	32-32(%r9),%xmm15
663	vpxor	%xmm2,%xmm8,%xmm7
664	vpxor	%xmm4,%xmm9,%xmm6
665
666	vmovdqu	16-32(%r9),%xmm0
667	vpxor	%xmm5,%xmm7,%xmm9
668	vpclmulqdq	$0x00,%xmm3,%xmm14,%xmm4
669	vpxor	%xmm9,%xmm6,%xmm6
670	vpunpckhqdq	%xmm13,%xmm13,%xmm2
671	vpclmulqdq	$0x11,%xmm3,%xmm14,%xmm14
672	vpxor	%xmm13,%xmm2,%xmm2
673	vpslldq	$8,%xmm6,%xmm9
674	vpclmulqdq	$0x00,%xmm15,%xmm1,%xmm1
675	vpxor	%xmm9,%xmm5,%xmm8
676	vpsrldq	$8,%xmm6,%xmm6
677	vpxor	%xmm6,%xmm7,%xmm7
678
679	vpclmulqdq	$0x00,%xmm0,%xmm13,%xmm5
680	vmovdqu	48-32(%r9),%xmm3
681	vpxor	%xmm4,%xmm5,%xmm5
682	vpunpckhqdq	%xmm12,%xmm12,%xmm9
683	vpclmulqdq	$0x11,%xmm0,%xmm13,%xmm13
684	vpxor	%xmm12,%xmm9,%xmm9
685	vpxor	%xmm14,%xmm13,%xmm13
686	vpalignr	$8,%xmm8,%xmm8,%xmm14
687	vpclmulqdq	$0x10,%xmm15,%xmm2,%xmm2
688	vmovdqu	80-32(%r9),%xmm15
689	vpxor	%xmm1,%xmm2,%xmm2
690
691	vpclmulqdq	$0x00,%xmm3,%xmm12,%xmm4
692	vmovdqu	64-32(%r9),%xmm0
693	vpxor	%xmm5,%xmm4,%xmm4
694	vpunpckhqdq	%xmm11,%xmm11,%xmm1
695	vpclmulqdq	$0x11,%xmm3,%xmm12,%xmm12
696	vpxor	%xmm11,%xmm1,%xmm1
697	vpxor	%xmm13,%xmm12,%xmm12
698	vxorps	16(%rsp),%xmm7,%xmm7
699	vpclmulqdq	$0x00,%xmm15,%xmm9,%xmm9
700	vpxor	%xmm2,%xmm9,%xmm9
701
702	vpclmulqdq	$0x10,16(%r11),%xmm8,%xmm8
703	vxorps	%xmm14,%xmm8,%xmm8
704
705	vpclmulqdq	$0x00,%xmm0,%xmm11,%xmm5
706	vmovdqu	96-32(%r9),%xmm3
707	vpxor	%xmm4,%xmm5,%xmm5
708	vpunpckhqdq	%xmm10,%xmm10,%xmm2
709	vpclmulqdq	$0x11,%xmm0,%xmm11,%xmm11
710	vpxor	%xmm10,%xmm2,%xmm2
711	vpalignr	$8,%xmm8,%xmm8,%xmm14
712	vpxor	%xmm12,%xmm11,%xmm11
713	vpclmulqdq	$0x10,%xmm15,%xmm1,%xmm1
714	vmovdqu	128-32(%r9),%xmm15
715	vpxor	%xmm9,%xmm1,%xmm1
716
717	vxorps	%xmm7,%xmm14,%xmm14
718	vpclmulqdq	$0x10,16(%r11),%xmm8,%xmm8
719	vxorps	%xmm14,%xmm8,%xmm8
720
721	vpclmulqdq	$0x00,%xmm3,%xmm10,%xmm4
722	vmovdqu	112-32(%r9),%xmm0
723	vpxor	%xmm5,%xmm4,%xmm4
724	vpunpckhqdq	%xmm8,%xmm8,%xmm9
725	vpclmulqdq	$0x11,%xmm3,%xmm10,%xmm10
726	vpxor	%xmm8,%xmm9,%xmm9
727	vpxor	%xmm11,%xmm10,%xmm10
728	vpclmulqdq	$0x00,%xmm15,%xmm2,%xmm2
729	vpxor	%xmm1,%xmm2,%xmm2
730
731	vpclmulqdq	$0x00,%xmm0,%xmm8,%xmm5
732	vpclmulqdq	$0x11,%xmm0,%xmm8,%xmm7
733	vpxor	%xmm4,%xmm5,%xmm5
734	vpclmulqdq	$0x10,%xmm15,%xmm9,%xmm6
735	vpxor	%xmm10,%xmm7,%xmm7
736	vpxor	%xmm2,%xmm6,%xmm6
737
738	vpxor	%xmm5,%xmm7,%xmm4
739	vpxor	%xmm4,%xmm6,%xmm6
740	vpslldq	$8,%xmm6,%xmm1
741	vmovdqu	16(%r11),%xmm3
742	vpsrldq	$8,%xmm6,%xmm6
743	vpxor	%xmm1,%xmm5,%xmm8
744	vpxor	%xmm6,%xmm7,%xmm7
745
746	vpalignr	$8,%xmm8,%xmm8,%xmm2
747	vpclmulqdq	$0x10,%xmm3,%xmm8,%xmm8
748	vpxor	%xmm2,%xmm8,%xmm8
749
750	vpalignr	$8,%xmm8,%xmm8,%xmm2
751	vpclmulqdq	$0x10,%xmm3,%xmm8,%xmm8
752	vpxor	%xmm7,%xmm2,%xmm2
753	vpxor	%xmm2,%xmm8,%xmm8
754	vpshufb	(%r11),%xmm8,%xmm8
755	vmovdqu	%xmm8,-64(%r9)
756
757	vzeroupper
758	movq	-48(%rax),%r15
759.cfi_restore	%r15
760	movq	-40(%rax),%r14
761.cfi_restore	%r14
762	movq	-32(%rax),%r13
763.cfi_restore	%r13
764	movq	-24(%rax),%r12
765.cfi_restore	%r12
766	movq	-16(%rax),%rbp
767.cfi_restore	%rbp
768	movq	-8(%rax),%rbx
769.cfi_restore	%rbx
770	leaq	(%rax),%rsp
771.cfi_def_cfa_register	%rsp
772.Lgcm_enc_abort:
773	movq	%r10,%rax
774	.byte	0xf3,0xc3
775.cfi_endproc
776.size	aesni_gcm_encrypt,.-aesni_gcm_encrypt
777.align	64
778.Lbswap_mask:
779.byte	15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
780.Lpoly:
781.byte	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xc2
782.Lone_msb:
783.byte	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
784.Ltwo_lsb:
785.byte	2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
786.Lone_lsb:
787.byte	1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
788.byte	65,69,83,45,78,73,32,71,67,77,32,109,111,100,117,108,101,32,102,111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
789.align	64
790