1;;
2;; Copyright (c) 2012-2020, Intel Corporation
3;;
4;; Redistribution and use in source and binary forms, with or without
5;; modification, are permitted provided that the following conditions are met:
6;;
7;;     * Redistributions of source code must retain the above copyright notice,
8;;       this list of conditions and the following disclaimer.
9;;     * Redistributions in binary form must reproduce the above copyright
10;;       notice, this list of conditions and the following disclaimer in the
11;;       documentation and/or other materials provided with the distribution.
12;;     * Neither the name of Intel Corporation nor the names of its contributors
13;;       may be used to endorse or promote products derived from this software
14;;       without specific prior written permission.
15;;
16;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26;;
27
28; Routine to do AES key expansion
29%include "include/os.asm"
30%define NO_AESNI_RENAME
31%include "include/aesni_emu.inc"
32%include "include/clear_regs.asm"
33
34%macro key_expansion_128_sse 0
35	;; Assumes the xmm3 includes all zeros at this point.
36        pshufd	xmm2, xmm2, 11111111b
37        shufps	xmm3, xmm1, 00010000b
38        pxor	xmm1, xmm3
39        shufps	xmm3, xmm1, 10001100b
40        pxor	xmm1, xmm3
41	pxor	xmm1, xmm2
42%endmacro
43
44%macro key_expansion_128_avx 0
45	;; Assumes the xmm3 includes all zeros at this point.
46        vpshufd	xmm2, xmm2, 11111111b
47        vshufps	xmm3, xmm3, xmm1, 00010000b
48        vpxor	xmm1, xmm1, xmm3
49        vshufps	xmm3, xmm3, xmm1, 10001100b
50        vpxor	xmm1, xmm1, xmm3
51	vpxor	xmm1, xmm1, xmm2
52%endmacro
53
54%ifdef LINUX
55%define KEY		rdi
56%define EXP_ENC_KEYS	rsi
57%define EXP_DEC_KEYS	rdx
58%else
59%define KEY		rcx
60%define EXP_ENC_KEYS	rdx
61%define EXP_DEC_KEYS	r8
62%endif
63
64section .text
65
66; void aes_keyexp_128(UINT128 *key,
67;                     UINT128 *enc_exp_keys,
68;                     UINT128 *dec_exp_keys);
69;
70; arg 1: rcx: pointer to key
71; arg 2: rdx: pointer to expanded key array for encrypt
72; arg 3: r8:  pointer to expanded key array for decrypt
73;
74MKGLOBAL(aes_keyexp_128_sse,function,)
75aes_keyexp_128_sse:
76
77%ifdef SAFE_PARAM
78        cmp     KEY, 0
79        jz      aes_keyexp_128_sse_return
80        cmp     EXP_ENC_KEYS, 0
81        jz      aes_keyexp_128_sse_return
82        cmp     EXP_DEC_KEYS, 0
83        jz      aes_keyexp_128_sse_return
84%endif
85
86        movdqu	xmm1, [KEY]	; loading the AES key
87	movdqa	[EXP_ENC_KEYS + 16*0], xmm1
88        movdqa	[EXP_DEC_KEYS + 16*10], xmm1  ; Storing key in memory
89	pxor	xmm3, xmm3
90
91        aeskeygenassist	xmm2, xmm1, 0x1     ; Generating round key 1
92        key_expansion_128_sse
93	movdqa	[EXP_ENC_KEYS + 16*1], xmm1
94        aesimc	xmm4, xmm1
95        movdqa	[EXP_DEC_KEYS + 16*9], xmm4
96
97        aeskeygenassist xmm2, xmm1, 0x2     ; Generating round key 2
98        key_expansion_128_sse
99	movdqa	[EXP_ENC_KEYS + 16*2], xmm1
100        aesimc	xmm5, xmm1
101        movdqa	[EXP_DEC_KEYS + 16*8], xmm5
102
103        aeskeygenassist xmm2, xmm1, 0x4     ; Generating round key 3
104        key_expansion_128_sse
105	movdqa	[EXP_ENC_KEYS + 16*3], xmm1
106        aesimc	xmm4, xmm1
107        movdqa	[EXP_DEC_KEYS + 16*7], xmm4
108
109        aeskeygenassist xmm2, xmm1, 0x8     ; Generating round key 4
110        key_expansion_128_sse
111	movdqa	[EXP_ENC_KEYS + 16*4], xmm1
112        aesimc	xmm5, xmm1
113        movdqa	[EXP_DEC_KEYS + 16*6], xmm5
114
115        aeskeygenassist xmm2, xmm1, 0x10    ; Generating round key 5
116        key_expansion_128_sse
117	movdqa	[EXP_ENC_KEYS + 16*5], xmm1
118        aesimc	xmm4, xmm1
119        movdqa	[EXP_DEC_KEYS + 16*5], xmm4
120
121        aeskeygenassist xmm2, xmm1, 0x20    ; Generating round key 6
122        key_expansion_128_sse
123	movdqa	[EXP_ENC_KEYS + 16*6], xmm1
124        aesimc	xmm5, xmm1
125        movdqa	[EXP_DEC_KEYS + 16*4], xmm5
126
127        aeskeygenassist xmm2, xmm1, 0x40    ; Generating round key 7
128        key_expansion_128_sse
129	movdqa	[EXP_ENC_KEYS + 16*7], xmm1
130        aesimc	xmm4, xmm1
131        movdqa	[EXP_DEC_KEYS + 16*3], xmm4
132
133        aeskeygenassist xmm2, xmm1, 0x80    ; Generating round key 8
134        key_expansion_128_sse
135	movdqa	[EXP_ENC_KEYS + 16*8], xmm1
136        aesimc	xmm5, xmm1
137        movdqa	[EXP_DEC_KEYS + 16*2], xmm5
138
139        aeskeygenassist xmm2, xmm1, 0x1b    ; Generating round key 9
140        key_expansion_128_sse
141	movdqa	[EXP_ENC_KEYS + 16*9], xmm1
142        aesimc	xmm4, xmm1
143        movdqa	[EXP_DEC_KEYS + 16*1], xmm4
144
145        aeskeygenassist xmm2, xmm1, 0x36    ; Generating round key 10
146        key_expansion_128_sse
147	movdqa	[EXP_ENC_KEYS + 16*10], xmm1
148        movdqa	[EXP_DEC_KEYS + 16*0], xmm1
149
150aes_keyexp_128_sse_return:
151
152%ifdef SAFE_DATA
153        clear_scratch_gps_asm
154        clear_scratch_xmms_sse_asm
155%endif
156	ret
157
158MKGLOBAL(aes_keyexp_128_sse_no_aesni,function,)
159aes_keyexp_128_sse_no_aesni:
160
161%ifdef SAFE_PARAM
162        cmp     KEY, 0
163        jz      aes_keyexp_128_sse_no_aesni_return
164        cmp     EXP_ENC_KEYS, 0
165        jz      aes_keyexp_128_sse_no_aesni_return
166        cmp     EXP_DEC_KEYS, 0
167        jz      aes_keyexp_128_sse_no_aesni_return
168%endif
169
170        movdqu	xmm1, [KEY]	; loading the AES key
171	movdqa	[EXP_ENC_KEYS + 16*0], xmm1
172        movdqa	[EXP_DEC_KEYS + 16*10], xmm1  ; Storing key in memory
173	pxor	xmm3, xmm3
174
175        EMULATE_AESKEYGENASSIST	xmm2, xmm1, 0x1     ; Generating round key 1
176        key_expansion_128_sse
177	movdqa	[EXP_ENC_KEYS + 16*1], xmm1
178        EMULATE_AESIMC	xmm4, xmm1
179        movdqa	[EXP_DEC_KEYS + 16*9], xmm4
180
181        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x2     ; Generating round key 2
182        key_expansion_128_sse
183	movdqa	[EXP_ENC_KEYS + 16*2], xmm1
184        EMULATE_AESIMC	xmm5, xmm1
185        movdqa	[EXP_DEC_KEYS + 16*8], xmm5
186
187        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x4     ; Generating round key 3
188        key_expansion_128_sse
189	movdqa	[EXP_ENC_KEYS + 16*3], xmm1
190        EMULATE_AESIMC	xmm4, xmm1
191        movdqa	[EXP_DEC_KEYS + 16*7], xmm4
192
193        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x8     ; Generating round key 4
194        key_expansion_128_sse
195	movdqa	[EXP_ENC_KEYS + 16*4], xmm1
196        EMULATE_AESIMC	xmm5, xmm1
197        movdqa	[EXP_DEC_KEYS + 16*6], xmm5
198
199        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x10    ; Generating round key 5
200        key_expansion_128_sse
201	movdqa	[EXP_ENC_KEYS + 16*5], xmm1
202        EMULATE_AESIMC	xmm4, xmm1
203        movdqa	[EXP_DEC_KEYS + 16*5], xmm4
204
205        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x20    ; Generating round key 6
206        key_expansion_128_sse
207	movdqa	[EXP_ENC_KEYS + 16*6], xmm1
208        EMULATE_AESIMC	xmm5, xmm1
209        movdqa	[EXP_DEC_KEYS + 16*4], xmm5
210
211        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x40    ; Generating round key 7
212        key_expansion_128_sse
213	movdqa	[EXP_ENC_KEYS + 16*7], xmm1
214        EMULATE_AESIMC	xmm4, xmm1
215        movdqa	[EXP_DEC_KEYS + 16*3], xmm4
216
217        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x80    ; Generating round key 8
218        key_expansion_128_sse
219	movdqa	[EXP_ENC_KEYS + 16*8], xmm1
220        EMULATE_AESIMC	xmm5, xmm1
221        movdqa	[EXP_DEC_KEYS + 16*2], xmm5
222
223        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x1b    ; Generating round key 9
224        key_expansion_128_sse
225	movdqa	[EXP_ENC_KEYS + 16*9], xmm1
226        EMULATE_AESIMC	xmm4, xmm1
227        movdqa	[EXP_DEC_KEYS + 16*1], xmm4
228
229        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x36    ; Generating round key 10
230        key_expansion_128_sse
231	movdqa	[EXP_ENC_KEYS + 16*10], xmm1
232        movdqa	[EXP_DEC_KEYS + 16*0], xmm1
233
234aes_keyexp_128_sse_no_aesni_return:
235
236%ifdef SAFE_DATA
237        clear_scratch_gps_asm
238        clear_scratch_xmms_sse_asm
239%endif
240        ret
241
242;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
243;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
244;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
245;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
246
247MKGLOBAL(aes_keyexp_128_avx,function,)
248MKGLOBAL(aes_keyexp_128_avx2,function,)
249MKGLOBAL(aes_keyexp_128_avx512,function,)
250aes_keyexp_128_avx:
251aes_keyexp_128_avx2:
252aes_keyexp_128_avx512:
253
254%ifdef SAFE_PARAM
255        cmp     KEY, 0
256        jz      aes_keyexp_128_avx_return
257        cmp     EXP_ENC_KEYS, 0
258        jz      aes_keyexp_128_avx_return
259        cmp     EXP_DEC_KEYS, 0
260        jz      aes_keyexp_128_avx_return
261%endif
262
263        vmovdqu	xmm1, [KEY]	; loading the AES key
264	vmovdqa	[EXP_ENC_KEYS + 16*0], xmm1
265        vmovdqa	[EXP_DEC_KEYS + 16*10], xmm1  ; Storing key in memory
266	vpxor	xmm3, xmm3, xmm3
267
268        vaeskeygenassist	xmm2, xmm1, 0x1     ; Generating round key 1
269        key_expansion_128_avx
270	vmovdqa	[EXP_ENC_KEYS + 16*1], xmm1
271        vaesimc	xmm4, xmm1
272        vmovdqa	[EXP_DEC_KEYS + 16*9], xmm4
273
274        vaeskeygenassist xmm2, xmm1, 0x2     ; Generating round key 2
275        key_expansion_128_avx
276	vmovdqa	[EXP_ENC_KEYS + 16*2], xmm1
277        vaesimc	xmm5, xmm1
278        vmovdqa	[EXP_DEC_KEYS + 16*8], xmm5
279
280        vaeskeygenassist xmm2, xmm1, 0x4     ; Generating round key 3
281        key_expansion_128_avx
282	vmovdqa	[EXP_ENC_KEYS + 16*3], xmm1
283        vaesimc	xmm4, xmm1
284        vmovdqa	[EXP_DEC_KEYS + 16*7], xmm4
285
286        vaeskeygenassist xmm2, xmm1, 0x8     ; Generating round key 4
287        key_expansion_128_avx
288	vmovdqa	[EXP_ENC_KEYS + 16*4], xmm1
289        vaesimc	xmm5, xmm1
290        vmovdqa	[EXP_DEC_KEYS + 16*6], xmm5
291
292        vaeskeygenassist xmm2, xmm1, 0x10    ; Generating round key 5
293        key_expansion_128_avx
294	vmovdqa	[EXP_ENC_KEYS + 16*5], xmm1
295        vaesimc	xmm4, xmm1
296        vmovdqa	[EXP_DEC_KEYS + 16*5], xmm4
297
298        vaeskeygenassist xmm2, xmm1, 0x20    ; Generating round key 6
299        key_expansion_128_avx
300	vmovdqa	[EXP_ENC_KEYS + 16*6], xmm1
301        vaesimc	xmm5, xmm1
302        vmovdqa	[EXP_DEC_KEYS + 16*4], xmm5
303
304        vaeskeygenassist xmm2, xmm1, 0x40    ; Generating round key 7
305        key_expansion_128_avx
306	vmovdqa	[EXP_ENC_KEYS + 16*7], xmm1
307        vaesimc	xmm4, xmm1
308        vmovdqa	[EXP_DEC_KEYS + 16*3], xmm4
309
310        vaeskeygenassist xmm2, xmm1, 0x80    ; Generating round key 8
311        key_expansion_128_avx
312	vmovdqa	[EXP_ENC_KEYS + 16*8], xmm1
313        vaesimc	xmm5, xmm1
314        vmovdqa	[EXP_DEC_KEYS + 16*2], xmm5
315
316        vaeskeygenassist xmm2, xmm1, 0x1b    ; Generating round key 9
317        key_expansion_128_avx
318	vmovdqa	[EXP_ENC_KEYS + 16*9], xmm1
319        vaesimc	xmm4, xmm1
320        vmovdqa	[EXP_DEC_KEYS + 16*1], xmm4
321
322        vaeskeygenassist xmm2, xmm1, 0x36    ; Generating round key 10
323        key_expansion_128_avx
324	vmovdqa	[EXP_ENC_KEYS + 16*10], xmm1
325        vmovdqa	[EXP_DEC_KEYS + 16*0], xmm1
326
327aes_keyexp_128_avx_return:
328
329%ifdef SAFE_DATA
330        clear_scratch_gps_asm
331        clear_scratch_xmms_avx_asm
332%endif
333        ret
334
335;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
336;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
337;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
338;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
339
340; void aes_keyexp_128_enc_sse(UINT128 *key,
341;                             UINT128 *enc_exp_keys);
342;
343; arg 1: rcx: pointer to key
344; arg 2: rdx: pointer to expanded key array for encrypt
345;
346MKGLOBAL(aes_keyexp_128_enc_sse,function,)
347aes_keyexp_128_enc_sse:
348
349%ifdef SAFE_PARAM
350        cmp     KEY, 0
351        jz      aes_keyexp_128_enc_sse_return
352        cmp     EXP_ENC_KEYS, 0
353        jz      aes_keyexp_128_enc_sse_return
354%endif
355
356        movdqu	xmm1, [KEY]	; loading the AES key
357	movdqa	[EXP_ENC_KEYS + 16*0], xmm1
358	pxor	xmm3, xmm3
359
360        aeskeygenassist	xmm2, xmm1, 0x1     ; Generating round key 1
361        key_expansion_128_sse
362	movdqa	[EXP_ENC_KEYS + 16*1], xmm1
363
364        aeskeygenassist xmm2, xmm1, 0x2     ; Generating round key 2
365        key_expansion_128_sse
366	movdqa	[EXP_ENC_KEYS + 16*2], xmm1
367
368        aeskeygenassist xmm2, xmm1, 0x4     ; Generating round key 3
369        key_expansion_128_sse
370	movdqa	[EXP_ENC_KEYS + 16*3], xmm1
371
372        aeskeygenassist xmm2, xmm1, 0x8     ; Generating round key 4
373        key_expansion_128_sse
374	movdqa	[EXP_ENC_KEYS + 16*4], xmm1
375
376        aeskeygenassist xmm2, xmm1, 0x10    ; Generating round key 5
377        key_expansion_128_sse
378	movdqa	[EXP_ENC_KEYS + 16*5], xmm1
379
380        aeskeygenassist xmm2, xmm1, 0x20    ; Generating round key 6
381        key_expansion_128_sse
382	movdqa	[EXP_ENC_KEYS + 16*6], xmm1
383
384        aeskeygenassist xmm2, xmm1, 0x40    ; Generating round key 7
385        key_expansion_128_sse
386	movdqa	[EXP_ENC_KEYS + 16*7], xmm1
387
388        aeskeygenassist xmm2, xmm1, 0x80    ; Generating round key 8
389        key_expansion_128_sse
390	movdqa	[EXP_ENC_KEYS + 16*8], xmm1
391
392        aeskeygenassist xmm2, xmm1, 0x1b    ; Generating round key 9
393        key_expansion_128_sse
394	movdqa	[EXP_ENC_KEYS + 16*9], xmm1
395
396        aeskeygenassist xmm2, xmm1, 0x36    ; Generating round key 10
397        key_expansion_128_sse
398	movdqa	[EXP_ENC_KEYS + 16*10], xmm1
399
400aes_keyexp_128_enc_sse_return:
401	ret
402
403MKGLOBAL(aes_keyexp_128_enc_sse_no_aesni,function,)
404aes_keyexp_128_enc_sse_no_aesni:
405
406%ifdef SAFE_PARAM
407        cmp     KEY, 0
408        jz      aes_keyexp_128_enc_sse_no_aesni_return
409        cmp     EXP_ENC_KEYS, 0
410        jz      aes_keyexp_128_enc_sse_no_aesni_return
411%endif
412
413        movdqu	xmm1, [KEY]	; loading the AES key
414	movdqa	[EXP_ENC_KEYS + 16*0], xmm1
415	pxor	xmm3, xmm3
416
417        EMULATE_AESKEYGENASSIST	xmm2, xmm1, 0x1     ; Generating round key 1
418        key_expansion_128_sse
419	movdqa	[EXP_ENC_KEYS + 16*1], xmm1
420
421        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x2     ; Generating round key 2
422        key_expansion_128_sse
423	movdqa	[EXP_ENC_KEYS + 16*2], xmm1
424
425        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x4     ; Generating round key 3
426        key_expansion_128_sse
427	movdqa	[EXP_ENC_KEYS + 16*3], xmm1
428
429        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x8     ; Generating round key 4
430        key_expansion_128_sse
431	movdqa	[EXP_ENC_KEYS + 16*4], xmm1
432
433        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x10    ; Generating round key 5
434        key_expansion_128_sse
435	movdqa	[EXP_ENC_KEYS + 16*5], xmm1
436
437        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x20    ; Generating round key 6
438        key_expansion_128_sse
439	movdqa	[EXP_ENC_KEYS + 16*6], xmm1
440
441        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x40    ; Generating round key 7
442        key_expansion_128_sse
443	movdqa	[EXP_ENC_KEYS + 16*7], xmm1
444
445        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x80    ; Generating round key 8
446        key_expansion_128_sse
447	movdqa	[EXP_ENC_KEYS + 16*8], xmm1
448
449        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x1b    ; Generating round key 9
450        key_expansion_128_sse
451	movdqa	[EXP_ENC_KEYS + 16*9], xmm1
452
453        EMULATE_AESKEYGENASSIST xmm2, xmm1, 0x36    ; Generating round key 10
454        key_expansion_128_sse
455	movdqa	[EXP_ENC_KEYS + 16*10], xmm1
456
457aes_keyexp_128_enc_sse_no_aesni_return:
458	ret
459
460MKGLOBAL(aes_keyexp_128_enc_avx,function,)
461MKGLOBAL(aes_keyexp_128_enc_avx2,function,)
462MKGLOBAL(aes_keyexp_128_enc_avx512,function,)
463aes_keyexp_128_enc_avx:
464aes_keyexp_128_enc_avx2:
465aes_keyexp_128_enc_avx512:
466
467%ifdef SAFE_PARAM
468        cmp     KEY, 0
469        jz      aes_keyexp_128_enc_avx_return
470        cmp     EXP_ENC_KEYS, 0
471        jz      aes_keyexp_128_enc_avx_return
472%endif
473
474        vmovdqu	xmm1, [KEY]	; loading the AES key
475	vmovdqa	[EXP_ENC_KEYS + 16*0], xmm1
476	vpxor	xmm3, xmm3, xmm3
477
478        vaeskeygenassist	xmm2, xmm1, 0x1     ; Generating round key 1
479        key_expansion_128_avx
480	vmovdqa	[EXP_ENC_KEYS + 16*1], xmm1
481
482        vaeskeygenassist xmm2, xmm1, 0x2     ; Generating round key 2
483        key_expansion_128_avx
484	vmovdqa	[EXP_ENC_KEYS + 16*2], xmm1
485
486        vaeskeygenassist xmm2, xmm1, 0x4     ; Generating round key 3
487        key_expansion_128_avx
488	vmovdqa	[EXP_ENC_KEYS + 16*3], xmm1
489
490        vaeskeygenassist xmm2, xmm1, 0x8     ; Generating round key 4
491        key_expansion_128_avx
492	vmovdqa	[EXP_ENC_KEYS + 16*4], xmm1
493
494        vaeskeygenassist xmm2, xmm1, 0x10    ; Generating round key 5
495        key_expansion_128_avx
496	vmovdqa	[EXP_ENC_KEYS + 16*5], xmm1
497
498        vaeskeygenassist xmm2, xmm1, 0x20    ; Generating round key 6
499        key_expansion_128_avx
500	vmovdqa	[EXP_ENC_KEYS + 16*6], xmm1
501
502        vaeskeygenassist xmm2, xmm1, 0x40    ; Generating round key 7
503        key_expansion_128_avx
504	vmovdqa	[EXP_ENC_KEYS + 16*7], xmm1
505
506        vaeskeygenassist xmm2, xmm1, 0x80    ; Generating round key 8
507        key_expansion_128_avx
508	vmovdqa	[EXP_ENC_KEYS + 16*8], xmm1
509
510        vaeskeygenassist xmm2, xmm1, 0x1b    ; Generating round key 9
511        key_expansion_128_avx
512	vmovdqa	[EXP_ENC_KEYS + 16*9], xmm1
513
514        vaeskeygenassist xmm2, xmm1, 0x36    ; Generating round key 10
515        key_expansion_128_avx
516	vmovdqa	[EXP_ENC_KEYS + 16*10], xmm1
517
518aes_keyexp_128_enc_avx_return:
519	ret
520
521%ifdef LINUX
522section .note.GNU-stack noalloc noexec nowrite progbits
523%endif
524