• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 *     http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
16#include "hitls_build.h"
17#ifdef HITLS_CRYPTO_AES
18
19.file    "crypt_aes_macro_x86_64.s"
20
21/* AES_ENC_1_BLK */
22.macro    AES_ENC_1_BLK    key round rdk blk
23.align 16
24.Laesenc_loop:
25    leaq 16(\key), \key
26    movdqu (\key), \rdk
27    aesenc  \rdk, \blk
28    decl \round
29    jnz .Laesenc_loop
30    leaq 16(\key), \key
31    movdqu (\key), \rdk
32    aesenclast \rdk, \blk
33.endm
34
35/* AES_ENC_2_BLKS */
36.macro    AES_ENC_2_BLKS    key round rdk blk0 blk1
37.align 16
38.Laesenc_2_blks_loop:
39    leaq 16(\key), \key
40    movdqu (\key), \rdk
41    aesenc  \rdk, \blk0
42    aesenc  \rdk, \blk1
43    decl \round
44    jnz .Laesenc_2_blks_loop
45    leaq 16(\key), \key
46    movdqu (\key), \rdk
47    aesenclast \rdk, \blk0
48    aesenclast \rdk, \blk1
49.endm
50
51/* AES_ENC_3_BLKS */
52.macro    AES_ENC_3_BLKS    key round rdk blk0 blk1 blk2
53.align 16
54.Laesenc_3_blks_loop:
55    leaq 16(\key), \key
56    movdqu (\key), \rdk
57    aesenc  \rdk, \blk0
58    aesenc  \rdk, \blk1
59    aesenc  \rdk, \blk2
60    decl \round
61    jnz .Laesenc_3_blks_loop
62    leaq 16(\key), \key
63    movdqu (\key), \rdk
64    aesenclast \rdk, \blk0
65    aesenclast \rdk, \blk1
66    aesenclast \rdk, \blk2
67.endm
68
69/* AES_ENC_4_BLKS */
70.macro    AES_ENC_4_BLKS    key round rdk blk0 blk1 blk2 blk3
71.align 16
72.Laesenc_4_blks_loop:
73    leaq 16(\key), \key
74    movdqu (\key), \rdk
75    aesenc  \rdk, \blk0
76    aesenc  \rdk, \blk1
77    aesenc  \rdk, \blk2
78    aesenc  \rdk, \blk3
79    decl \round
80    jnz .Laesenc_4_blks_loop
81    leaq 16(\key), \key
82    movdqu (\key), \rdk
83    aesenclast \rdk, \blk0
84    aesenclast \rdk, \blk1
85    aesenclast \rdk, \blk2
86    aesenclast \rdk, \blk3
87.endm
88
89/* AES_ENC_5_BLKS */
90.macro    AES_ENC_5_BLKS    key round rdk blk0 blk1 blk2 blk3 blk4
91.align 16
92.Laesenc_5_blks_loop:
93    leaq 16(\key), \key
94    movdqu (\key), \rdk
95    aesenc  \rdk, \blk0
96    aesenc  \rdk, \blk1
97    aesenc  \rdk, \blk2
98    aesenc  \rdk, \blk3
99    aesenc  \rdk, \blk4
100    decl \round
101    jnz .Laesenc_5_blks_loop
102    leaq 16(\key), \key
103    movdqu (\key), \rdk
104    aesenclast \rdk, \blk0
105    aesenclast \rdk, \blk1
106    aesenclast \rdk, \blk2
107    aesenclast \rdk, \blk3
108    aesenclast \rdk, \blk4
109.endm
110
111/* AES_ENC_6_BLKS */
112.macro    AES_ENC_6_BLKS    key round rdk blk0 blk1 blk2 blk3 blk4 blk5
113.align 16
114.Laesenc_6_blks_loop:
115    leaq 16(\key), \key
116    movdqu (\key), \rdk
117    aesenc  \rdk, \blk0
118    aesenc  \rdk, \blk1
119    aesenc  \rdk, \blk2
120    aesenc  \rdk, \blk3
121    aesenc  \rdk, \blk4
122    aesenc  \rdk, \blk5
123    decl \round
124    jnz .Laesenc_6_blks_loop
125    leaq 16(\key), \key
126    movdqu (\key), \rdk
127    aesenclast \rdk, \blk0
128    aesenclast \rdk, \blk1
129    aesenclast \rdk, \blk2
130    aesenclast \rdk, \blk3
131    aesenclast \rdk, \blk4
132    aesenclast \rdk, \blk5
133.endm
134
135/* AES_ENC_7_BLKS */
136.macro    AES_ENC_7_BLKS    key round rdk blk0 blk1 blk2 blk3 blk4 blk5 blk6
137.align 16
138.Laesenc_7_blks_loop:
139    leaq 16(\key), \key
140    movdqu (\key), \rdk
141    aesenc  \rdk, \blk0
142    aesenc  \rdk, \blk1
143    aesenc  \rdk, \blk2
144    aesenc  \rdk, \blk3
145    aesenc  \rdk, \blk4
146    aesenc  \rdk, \blk5
147    aesenc  \rdk, \blk6
148    decl \round
149    jnz .Laesenc_7_blks_loop
150    leaq 16(\key), \key
151    movdqu (\key), \rdk
152    aesenclast \rdk, \blk0
153    aesenclast \rdk, \blk1
154    aesenclast \rdk, \blk2
155    aesenclast \rdk, \blk3
156    aesenclast \rdk, \blk4
157    aesenclast \rdk, \blk5
158    aesenclast \rdk, \blk6
159.endm
160
161/* AES_ENC_8_BLKS */
162.macro    AES_ENC_8_BLKS    key round rdk blk0 blk1 blk2 blk3 blk4 blk5 blk6 blk7
163.align 16
164.Laesenc_8_blks_loop:
165    leaq 16(\key), \key
166    movdqu (\key), \rdk
167    aesenc  \rdk, \blk0
168    aesenc  \rdk, \blk1
169    aesenc  \rdk, \blk2
170    aesenc  \rdk, \blk3
171    aesenc  \rdk, \blk4
172    aesenc  \rdk, \blk5
173    aesenc  \rdk, \blk6
174    aesenc  \rdk, \blk7
175    decl \round
176    jnz .Laesenc_8_blks_loop
177    leaq 16(\key), \key
178    movdqu (\key), \rdk
179    aesenclast \rdk, \blk0
180    aesenclast \rdk, \blk1
181    aesenclast \rdk, \blk2
182    aesenclast \rdk, \blk3
183    aesenclast \rdk, \blk4
184    aesenclast \rdk, \blk5
185    aesenclast \rdk, \blk6
186    aesenclast \rdk, \blk7
187.endm
188
189/* AES_ENC_14_BLKS */
190.macro AES_ENC_14_BLKS    ARG2 key round rdk blk0 blk1 blk2 blk3 blk4 blk5 blk6 blk7 blk8 blk9 blk10 blk11 blk12 blk13
191.align 16
192.Laesenc_14_blks_loop:
193    leaq 16(\key), \key
194    movdqu (\key), \rdk
195    aesenc  \rdk, \blk0
196    aesenc  \rdk, \blk1
197    aesenc  \rdk, \blk2
198    aesenc  \rdk, \blk3
199    aesenc  \rdk, \blk4
200    aesenc  \rdk, \blk5
201    aesenc  \rdk, \blk6
202    aesenc  \rdk, \blk7
203    aesenc  \rdk, \blk8
204    aesenc  \rdk, \blk9
205    aesenc  \rdk, \blk10
206    aesenc  \rdk, \blk11
207    aesenc  \rdk, \blk12
208    aesenc  \rdk, \blk13
209    decl \round
210    jnz .Laesenc_14_blks_loop
211    leaq 16(\key), \key
212    movdqu (\key), \rdk
213    aesenclast \rdk, \blk0
214    aesenclast \rdk, \blk1
215    aesenclast \rdk, \blk2
216    aesenclast \rdk, \blk3
217    aesenclast \rdk, \blk4
218    aesenclast \rdk, \blk5
219    aesenclast \rdk, \blk6
220    aesenclast \rdk, \blk7
221    aesenclast \rdk, \blk8
222    aesenclast \rdk, \blk9
223    aesenclast \rdk, \blk10
224    aesenclast \rdk, \blk11
225    aesenclast \rdk, \blk12
226    aesenclast \rdk, \blk13
227.endm
228
229/* AES_DEC_1_BLK */
230.macro    AES_DEC_1_BLK    key round rdk blk
231.align 16
232.Laesdec_loop:
233    leaq 16(\key), \key
234    movdqu (\key), \rdk
235    aesdec  \rdk, \blk
236    decl \round
237    jnz .Laesdec_loop
238    leaq 16(\key), \key
239    movdqu (\key), \rdk
240    aesdeclast \rdk, \blk
241.endm
242
243/* AES_DEC_2_BLKS */
244.macro    AES_DEC_2_BLKS    key round rdk blk0 blk1
245.align 32
246.Laesdec_2_blks_loop:
247    leaq 16(\key), \key
248    movdqu (\key), \rdk
249    aesdec  \rdk, \blk0
250    aesdec  \rdk, \blk1
251    decl \round
252    jnz .Laesdec_2_blks_loop
253    leaq 16(\key), \key
254    movdqu (\key), \rdk
255    aesdeclast \rdk, \blk0
256    aesdeclast \rdk, \blk1
257.endm
258
259/* AES_DEC_3_BLKS */
260.macro    AES_DEC_3_BLKS    key round rdk blk0 blk1 blk2
261.align 16
262.Laesdec_3_blks_loop:
263    leaq 16(\key), \key
264    movdqu (\key), \rdk
265    aesdec  \rdk, \blk0
266    aesdec  \rdk, \blk1
267    aesdec  \rdk, \blk2
268    decl \round
269    jnz .Laesdec_3_blks_loop
270    leaq 16(\key), \key
271    movdqu (\key), \rdk
272    aesdeclast \rdk, \blk0
273    aesdeclast \rdk, \blk1
274    aesdeclast \rdk, \blk2
275.endm
276
277/* AES_DEC_4_BLKS */
278.macro    AES_DEC_4_BLKS    key round rdk blk0 blk1 blk2 blk3
279.align 16
280.Laesdec_4_blks_loop:
281    leaq 16(\key), \key
282    movdqu (\key), \rdk
283    aesdec  \rdk, \blk0
284    aesdec  \rdk, \blk1
285    aesdec  \rdk, \blk2
286    aesdec  \rdk, \blk3
287    decl \round
288    jnz .Laesdec_4_blks_loop
289    leaq 16(\key), \key
290    movdqu (\key), \rdk
291    aesdeclast \rdk, \blk0
292    aesdeclast \rdk, \blk1
293    aesdeclast \rdk, \blk2
294    aesdeclast \rdk, \blk3
295.endm
296
297/* AES_DEC_5_BLKS */
298.macro    AES_DEC_5_BLKS    key round rdk blk0 blk1 blk2 blk3 blk4
299.align 16
300.Laesdec_5_blks_loop:
301    leaq 16(\key), \key
302    movdqu (\key), \rdk
303    aesdec  \rdk, \blk0
304    aesdec  \rdk, \blk1
305    aesdec  \rdk, \blk2
306    aesdec  \rdk, \blk3
307    aesdec  \rdk, \blk4
308    decl \round
309    jnz .Laesdec_5_blks_loop
310    leaq 16(\key), \key
311    movdqu (\key), \rdk
312    aesdeclast \rdk, \blk0
313    aesdeclast \rdk, \blk1
314    aesdeclast \rdk, \blk2
315    aesdeclast \rdk, \blk3
316    aesdeclast \rdk, \blk4
317.endm
318
319/* AES_DEC_6_BLKS */
320.macro    AES_DEC_6_BLKS    key round rdk blk0 blk1 blk2 blk3 blk4 blk5
321.align 16
322.Laesdec_6_blks_loop:
323    leaq 16(\key), \key
324    movdqu (\key), \rdk
325    aesdec  \rdk, \blk0
326    aesdec  \rdk, \blk1
327    aesdec  \rdk, \blk2
328    aesdec  \rdk, \blk3
329    aesdec  \rdk, \blk4
330    aesdec  \rdk, \blk5
331    decl \round
332    jnz .Laesdec_6_blks_loop
333    leaq 16(\key), \key
334    movdqu (\key), \rdk
335    aesdeclast \rdk, \blk0
336    aesdeclast \rdk, \blk1
337    aesdeclast \rdk, \blk2
338    aesdeclast \rdk, \blk3
339    aesdeclast \rdk, \blk4
340    aesdeclast \rdk, \blk5
341.endm
342
343/* AES_DEC_7_BLKS */
344.macro    AES_DEC_7_BLKS    key round rdk blk0 blk1 blk2 blk3 blk4 blk5 blk6
345.align 16
346.Laesdec_7_blks_loop:
347    leaq 16(\key), \key
348    movdqu (\key), \rdk
349    aesdec  \rdk, \blk0
350    aesdec  \rdk, \blk1
351    aesdec  \rdk, \blk2
352    aesdec  \rdk, \blk3
353    aesdec  \rdk, \blk4
354    aesdec  \rdk, \blk5
355    aesdec  \rdk, \blk6
356    decl \round
357    jnz .Laesdec_7_blks_loop
358    leaq 16(\key), \key
359    movdqu (\key), \rdk
360    aesdeclast \rdk, \blk0
361    aesdeclast \rdk, \blk1
362    aesdeclast \rdk, \blk2
363    aesdeclast \rdk, \blk3
364    aesdeclast \rdk, \blk4
365    aesdeclast \rdk, \blk5
366    aesdeclast \rdk, \blk6
367.endm
368
369/* AES_DEC_8_BLKS */
370.macro    AES_DEC_8_BLKS    key round rdk blk0 blk1 blk2 blk3 blk4 blk5 blk6 blk7
371
372.align 16
373.Laesdec_8_blks_loop:
374    leaq 16(\key), \key
375    movdqu (\key), \rdk
376    aesdec  \rdk, \blk0
377    aesdec  \rdk, \blk1
378    aesdec  \rdk, \blk2
379    aesdec  \rdk, \blk3
380    aesdec  \rdk, \blk4
381    aesdec  \rdk, \blk5
382    aesdec  \rdk, \blk6
383    aesdec  \rdk, \blk7
384    decl \round
385    jnz .Laesdec_8_blks_loop
386    leaq 16(\key), \key
387    movdqu (\key), \rdk
388    aesdeclast \rdk, \blk0
389    aesdeclast \rdk, \blk1
390    aesdeclast \rdk, \blk2
391    aesdeclast \rdk, \blk3
392    aesdeclast \rdk, \blk4
393    aesdeclast \rdk, \blk5
394    aesdeclast \rdk, \blk6
395    aesdeclast \rdk, \blk7
396.endm
397
398/* AES_DEC_14_BLKS */
399.macro    AES_DEC_14_BLKS    key round rdk blk0 blk1 blk2 blk3 blk4 blk5 blk6 blk7 blk8 blk9 blk10 blk11 blk12 blk13
400.align 16
401.Laesdec_14_blks_loop:
402    leaq 16(\key), \key
403    movdqu (\key), \rdk
404    aesdec  \rdk, \blk0
405    aesdec  \rdk, \blk1
406    aesdec  \rdk, \blk2
407    aesdec  \rdk, \blk3
408    aesdec  \rdk, \blk4
409    aesdec  \rdk, \blk5
410    aesdec  \rdk, \blk6
411    aesdec  \rdk, \blk7
412    aesdec  \rdk, \blk8
413    aesdec  \rdk, \blk9
414    aesdec  \rdk, \blk10
415    aesdec  \rdk, \blk11
416    aesdec  \rdk, \blk12
417    aesdec  \rdk, \blk13
418    decl \round
419    jnz .Laesdec_14_blks_loop
420    leaq 16(\key), \key
421    movdqu (\key), \rdk
422    aesdeclast \rdk, \blk0
423    aesdeclast \rdk, \blk1
424    aesdeclast \rdk, \blk2
425    aesdeclast \rdk, \blk3
426    aesdeclast \rdk, \blk4
427    aesdeclast \rdk, \blk5
428    aesdeclast \rdk, \blk6
429    aesdeclast \rdk, \blk7
430    aesdeclast \rdk, \blk8
431    aesdeclast \rdk, \blk9
432    aesdeclast \rdk, \blk10
433    aesdeclast \rdk, \blk11
434    aesdeclast \rdk, \blk12
435    aesdeclast \rdk, \blk13
436.endm
437
438#endif
439