blob: 4ab36b84c1b36d3efe00c47e1458c024636fcad1 [file] [log] [blame]
Robert Sloanc9abfe42018-11-26 12:19:07 -08001// This file is generated from a similarly-named Perl script in the BoringSSL
2// source tree. Do not edit by hand.
3
Pete Bentley0c61efe2019-08-13 09:32:23 +01004#if !defined(__has_feature)
5#define __has_feature(x) 0
6#endif
Robert Sloan726e9d12018-09-11 11:45:04 -07007#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
8#define OPENSSL_NO_ASM
9#endif
Robert Sloan726e9d12018-09-11 11:45:04 -070010
11#if !defined(OPENSSL_NO_ASM)
Kenny Rootb8494592015-09-25 02:29:14 +000012#if defined(__aarch64__)
Robert Sloan726e9d12018-09-11 11:45:04 -070013#if defined(BORINGSSL_PREFIX)
14#include <boringssl_prefix_symbols_asm.h>
15#endif
Kenny Rootb8494592015-09-25 02:29:14 +000016#include <openssl/arm_arch.h>
Adam Langleyd9e397b2015-01-22 14:27:53 -080017
18#if __ARM_MAX_ARCH__>=7
19.text
20.arch armv8-a+crypto
Robert Sloanc9abfe42018-11-26 12:19:07 -080021.section .rodata
Adam Langleyd9e397b2015-01-22 14:27:53 -080022.align 5
Adam Langleye9ada862015-05-11 17:20:37 -070023.Lrcon:
Adam Langleyd9e397b2015-01-22 14:27:53 -080024.long 0x01,0x01,0x01,0x01
25.long 0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d // rotate-n-splat
26.long 0x1b,0x1b,0x1b,0x1b
27
Robert Sloanc9abfe42018-11-26 12:19:07 -080028.text
29
Steven Valdezbb1ceac2016-10-07 10:34:51 -040030.globl aes_hw_set_encrypt_key
31.hidden aes_hw_set_encrypt_key
32.type aes_hw_set_encrypt_key,%function
Adam Langleyd9e397b2015-01-22 14:27:53 -080033.align 5
Steven Valdezbb1ceac2016-10-07 10:34:51 -040034aes_hw_set_encrypt_key:
Adam Langleyd9e397b2015-01-22 14:27:53 -080035.Lenc_key:
36 stp x29,x30,[sp,#-16]!
37 add x29,sp,#0
38 mov x3,#-1
39 cmp x0,#0
40 b.eq .Lenc_key_abort
41 cmp x2,#0
42 b.eq .Lenc_key_abort
43 mov x3,#-2
44 cmp w1,#128
45 b.lt .Lenc_key_abort
46 cmp w1,#256
47 b.gt .Lenc_key_abort
48 tst w1,#0x3f
49 b.ne .Lenc_key_abort
50
Robert Sloanc9abfe42018-11-26 12:19:07 -080051 adrp x3,.Lrcon
52 add x3,x3,:lo12:.Lrcon
Adam Langleyd9e397b2015-01-22 14:27:53 -080053 cmp w1,#192
54
55 eor v0.16b,v0.16b,v0.16b
56 ld1 {v3.16b},[x0],#16
57 mov w1,#8 // reuse w1
58 ld1 {v1.4s,v2.4s},[x3],#32
59
60 b.lt .Loop128
61 b.eq .L192
62 b .L256
63
64.align 4
65.Loop128:
66 tbl v6.16b,{v3.16b},v2.16b
67 ext v5.16b,v0.16b,v3.16b,#12
68 st1 {v3.4s},[x2],#16
69 aese v6.16b,v0.16b
70 subs w1,w1,#1
71
72 eor v3.16b,v3.16b,v5.16b
73 ext v5.16b,v0.16b,v5.16b,#12
74 eor v3.16b,v3.16b,v5.16b
75 ext v5.16b,v0.16b,v5.16b,#12
Adam Langleye9ada862015-05-11 17:20:37 -070076 eor v6.16b,v6.16b,v1.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -080077 eor v3.16b,v3.16b,v5.16b
78 shl v1.16b,v1.16b,#1
79 eor v3.16b,v3.16b,v6.16b
80 b.ne .Loop128
81
82 ld1 {v1.4s},[x3]
83
84 tbl v6.16b,{v3.16b},v2.16b
85 ext v5.16b,v0.16b,v3.16b,#12
86 st1 {v3.4s},[x2],#16
87 aese v6.16b,v0.16b
88
89 eor v3.16b,v3.16b,v5.16b
90 ext v5.16b,v0.16b,v5.16b,#12
91 eor v3.16b,v3.16b,v5.16b
92 ext v5.16b,v0.16b,v5.16b,#12
Adam Langleye9ada862015-05-11 17:20:37 -070093 eor v6.16b,v6.16b,v1.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -080094 eor v3.16b,v3.16b,v5.16b
95 shl v1.16b,v1.16b,#1
96 eor v3.16b,v3.16b,v6.16b
97
98 tbl v6.16b,{v3.16b},v2.16b
99 ext v5.16b,v0.16b,v3.16b,#12
100 st1 {v3.4s},[x2],#16
101 aese v6.16b,v0.16b
102
103 eor v3.16b,v3.16b,v5.16b
104 ext v5.16b,v0.16b,v5.16b,#12
105 eor v3.16b,v3.16b,v5.16b
106 ext v5.16b,v0.16b,v5.16b,#12
Adam Langleye9ada862015-05-11 17:20:37 -0700107 eor v6.16b,v6.16b,v1.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800108 eor v3.16b,v3.16b,v5.16b
109 eor v3.16b,v3.16b,v6.16b
110 st1 {v3.4s},[x2]
111 add x2,x2,#0x50
112
113 mov w12,#10
114 b .Ldone
115
116.align 4
117.L192:
118 ld1 {v4.8b},[x0],#8
119 movi v6.16b,#8 // borrow v6.16b
120 st1 {v3.4s},[x2],#16
121 sub v2.16b,v2.16b,v6.16b // adjust the mask
122
123.Loop192:
124 tbl v6.16b,{v4.16b},v2.16b
125 ext v5.16b,v0.16b,v3.16b,#12
126 st1 {v4.8b},[x2],#8
127 aese v6.16b,v0.16b
128 subs w1,w1,#1
129
130 eor v3.16b,v3.16b,v5.16b
131 ext v5.16b,v0.16b,v5.16b,#12
132 eor v3.16b,v3.16b,v5.16b
133 ext v5.16b,v0.16b,v5.16b,#12
134 eor v3.16b,v3.16b,v5.16b
135
136 dup v5.4s,v3.s[3]
137 eor v5.16b,v5.16b,v4.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700138 eor v6.16b,v6.16b,v1.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800139 ext v4.16b,v0.16b,v4.16b,#12
140 shl v1.16b,v1.16b,#1
141 eor v4.16b,v4.16b,v5.16b
142 eor v3.16b,v3.16b,v6.16b
143 eor v4.16b,v4.16b,v6.16b
144 st1 {v3.4s},[x2],#16
145 b.ne .Loop192
146
147 mov w12,#12
148 add x2,x2,#0x20
149 b .Ldone
150
151.align 4
152.L256:
153 ld1 {v4.16b},[x0]
154 mov w1,#7
155 mov w12,#14
156 st1 {v3.4s},[x2],#16
157
158.Loop256:
159 tbl v6.16b,{v4.16b},v2.16b
160 ext v5.16b,v0.16b,v3.16b,#12
161 st1 {v4.4s},[x2],#16
162 aese v6.16b,v0.16b
163 subs w1,w1,#1
164
165 eor v3.16b,v3.16b,v5.16b
166 ext v5.16b,v0.16b,v5.16b,#12
167 eor v3.16b,v3.16b,v5.16b
168 ext v5.16b,v0.16b,v5.16b,#12
Adam Langleye9ada862015-05-11 17:20:37 -0700169 eor v6.16b,v6.16b,v1.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800170 eor v3.16b,v3.16b,v5.16b
171 shl v1.16b,v1.16b,#1
172 eor v3.16b,v3.16b,v6.16b
173 st1 {v3.4s},[x2],#16
174 b.eq .Ldone
175
176 dup v6.4s,v3.s[3] // just splat
177 ext v5.16b,v0.16b,v4.16b,#12
178 aese v6.16b,v0.16b
179
180 eor v4.16b,v4.16b,v5.16b
181 ext v5.16b,v0.16b,v5.16b,#12
182 eor v4.16b,v4.16b,v5.16b
183 ext v5.16b,v0.16b,v5.16b,#12
184 eor v4.16b,v4.16b,v5.16b
185
186 eor v4.16b,v4.16b,v6.16b
187 b .Loop256
188
189.Ldone:
190 str w12,[x2]
191 mov x3,#0
192
193.Lenc_key_abort:
194 mov x0,x3 // return value
195 ldr x29,[sp],#16
196 ret
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400197.size aes_hw_set_encrypt_key,.-aes_hw_set_encrypt_key
Adam Langleyd9e397b2015-01-22 14:27:53 -0800198
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400199.globl aes_hw_set_decrypt_key
200.hidden aes_hw_set_decrypt_key
201.type aes_hw_set_decrypt_key,%function
Adam Langleyd9e397b2015-01-22 14:27:53 -0800202.align 5
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400203aes_hw_set_decrypt_key:
Adam Langleyd9e397b2015-01-22 14:27:53 -0800204 stp x29,x30,[sp,#-16]!
205 add x29,sp,#0
206 bl .Lenc_key
207
208 cmp x0,#0
209 b.ne .Ldec_key_abort
210
211 sub x2,x2,#240 // restore original x2
212 mov x4,#-16
213 add x0,x2,x12,lsl#4 // end of key schedule
214
215 ld1 {v0.4s},[x2]
216 ld1 {v1.4s},[x0]
217 st1 {v0.4s},[x0],x4
218 st1 {v1.4s},[x2],#16
219
220.Loop_imc:
221 ld1 {v0.4s},[x2]
222 ld1 {v1.4s},[x0]
223 aesimc v0.16b,v0.16b
224 aesimc v1.16b,v1.16b
225 st1 {v0.4s},[x0],x4
226 st1 {v1.4s},[x2],#16
227 cmp x0,x2
228 b.hi .Loop_imc
229
230 ld1 {v0.4s},[x2]
231 aesimc v0.16b,v0.16b
232 st1 {v0.4s},[x0]
233
234 eor x0,x0,x0 // return value
235.Ldec_key_abort:
236 ldp x29,x30,[sp],#16
237 ret
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400238.size aes_hw_set_decrypt_key,.-aes_hw_set_decrypt_key
239.globl aes_hw_encrypt
240.hidden aes_hw_encrypt
241.type aes_hw_encrypt,%function
Adam Langleyd9e397b2015-01-22 14:27:53 -0800242.align 5
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400243aes_hw_encrypt:
Adam Langleyd9e397b2015-01-22 14:27:53 -0800244 ldr w3,[x2,#240]
245 ld1 {v0.4s},[x2],#16
246 ld1 {v2.16b},[x0]
247 sub w3,w3,#2
248 ld1 {v1.4s},[x2],#16
249
250.Loop_enc:
251 aese v2.16b,v0.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800252 aesmc v2.16b,v2.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700253 ld1 {v0.4s},[x2],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800254 subs w3,w3,#2
255 aese v2.16b,v1.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800256 aesmc v2.16b,v2.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700257 ld1 {v1.4s},[x2],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800258 b.gt .Loop_enc
259
260 aese v2.16b,v0.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800261 aesmc v2.16b,v2.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700262 ld1 {v0.4s},[x2]
Adam Langleyd9e397b2015-01-22 14:27:53 -0800263 aese v2.16b,v1.16b
264 eor v2.16b,v2.16b,v0.16b
265
266 st1 {v2.16b},[x1]
267 ret
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400268.size aes_hw_encrypt,.-aes_hw_encrypt
269.globl aes_hw_decrypt
270.hidden aes_hw_decrypt
271.type aes_hw_decrypt,%function
Adam Langleyd9e397b2015-01-22 14:27:53 -0800272.align 5
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400273aes_hw_decrypt:
Adam Langleyd9e397b2015-01-22 14:27:53 -0800274 ldr w3,[x2,#240]
275 ld1 {v0.4s},[x2],#16
276 ld1 {v2.16b},[x0]
277 sub w3,w3,#2
278 ld1 {v1.4s},[x2],#16
279
280.Loop_dec:
281 aesd v2.16b,v0.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800282 aesimc v2.16b,v2.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700283 ld1 {v0.4s},[x2],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800284 subs w3,w3,#2
285 aesd v2.16b,v1.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800286 aesimc v2.16b,v2.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700287 ld1 {v1.4s},[x2],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800288 b.gt .Loop_dec
289
290 aesd v2.16b,v0.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800291 aesimc v2.16b,v2.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700292 ld1 {v0.4s},[x2]
Adam Langleyd9e397b2015-01-22 14:27:53 -0800293 aesd v2.16b,v1.16b
294 eor v2.16b,v2.16b,v0.16b
295
296 st1 {v2.16b},[x1]
297 ret
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400298.size aes_hw_decrypt,.-aes_hw_decrypt
299.globl aes_hw_cbc_encrypt
300.hidden aes_hw_cbc_encrypt
301.type aes_hw_cbc_encrypt,%function
Adam Langleyd9e397b2015-01-22 14:27:53 -0800302.align 5
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400303aes_hw_cbc_encrypt:
Adam Langleyd9e397b2015-01-22 14:27:53 -0800304 stp x29,x30,[sp,#-16]!
305 add x29,sp,#0
306 subs x2,x2,#16
307 mov x8,#16
308 b.lo .Lcbc_abort
309 csel x8,xzr,x8,eq
310
311 cmp w5,#0 // en- or decrypting?
312 ldr w5,[x3,#240]
313 and x2,x2,#-16
314 ld1 {v6.16b},[x4]
315 ld1 {v0.16b},[x0],x8
316
Adam Langleye9ada862015-05-11 17:20:37 -0700317 ld1 {v16.4s,v17.4s},[x3] // load key schedule...
Adam Langleyd9e397b2015-01-22 14:27:53 -0800318 sub w5,w5,#6
319 add x7,x3,x5,lsl#4 // pointer to last 7 round keys
320 sub w5,w5,#2
Adam Langleye9ada862015-05-11 17:20:37 -0700321 ld1 {v18.4s,v19.4s},[x7],#32
322 ld1 {v20.4s,v21.4s},[x7],#32
323 ld1 {v22.4s,v23.4s},[x7],#32
Adam Langleyd9e397b2015-01-22 14:27:53 -0800324 ld1 {v7.4s},[x7]
325
326 add x7,x3,#32
327 mov w6,w5
328 b.eq .Lcbc_dec
329
330 cmp w5,#2
331 eor v0.16b,v0.16b,v6.16b
332 eor v5.16b,v16.16b,v7.16b
333 b.eq .Lcbc_enc128
334
Adam Langleye9ada862015-05-11 17:20:37 -0700335 ld1 {v2.4s,v3.4s},[x7]
336 add x7,x3,#16
337 add x6,x3,#16*4
338 add x12,x3,#16*5
339 aese v0.16b,v16.16b
340 aesmc v0.16b,v0.16b
341 add x14,x3,#16*6
342 add x3,x3,#16*7
343 b .Lenter_cbc_enc
344
345.align 4
Adam Langleyd9e397b2015-01-22 14:27:53 -0800346.Loop_cbc_enc:
347 aese v0.16b,v16.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800348 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700349 st1 {v6.16b},[x1],#16
350.Lenter_cbc_enc:
Adam Langleyd9e397b2015-01-22 14:27:53 -0800351 aese v0.16b,v17.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800352 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700353 aese v0.16b,v2.16b
354 aesmc v0.16b,v0.16b
355 ld1 {v16.4s},[x6]
356 cmp w5,#4
357 aese v0.16b,v3.16b
358 aesmc v0.16b,v0.16b
359 ld1 {v17.4s},[x12]
360 b.eq .Lcbc_enc192
Adam Langleyd9e397b2015-01-22 14:27:53 -0800361
362 aese v0.16b,v16.16b
363 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700364 ld1 {v16.4s},[x14]
Adam Langleyd9e397b2015-01-22 14:27:53 -0800365 aese v0.16b,v17.16b
366 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700367 ld1 {v17.4s},[x3]
368 nop
369
370.Lcbc_enc192:
371 aese v0.16b,v16.16b
372 aesmc v0.16b,v0.16b
373 subs x2,x2,#16
374 aese v0.16b,v17.16b
375 aesmc v0.16b,v0.16b
376 csel x8,xzr,x8,eq
Adam Langleyd9e397b2015-01-22 14:27:53 -0800377 aese v0.16b,v18.16b
378 aesmc v0.16b,v0.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800379 aese v0.16b,v19.16b
380 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700381 ld1 {v16.16b},[x0],x8
Adam Langleyd9e397b2015-01-22 14:27:53 -0800382 aese v0.16b,v20.16b
383 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700384 eor v16.16b,v16.16b,v5.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800385 aese v0.16b,v21.16b
386 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700387 ld1 {v17.4s},[x7] // re-pre-load rndkey[1]
Adam Langleyd9e397b2015-01-22 14:27:53 -0800388 aese v0.16b,v22.16b
389 aesmc v0.16b,v0.16b
390 aese v0.16b,v23.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800391 eor v6.16b,v0.16b,v7.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800392 b.hs .Loop_cbc_enc
393
Adam Langleye9ada862015-05-11 17:20:37 -0700394 st1 {v6.16b},[x1],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800395 b .Lcbc_done
396
397.align 5
398.Lcbc_enc128:
Adam Langleye9ada862015-05-11 17:20:37 -0700399 ld1 {v2.4s,v3.4s},[x7]
Adam Langleyd9e397b2015-01-22 14:27:53 -0800400 aese v0.16b,v16.16b
401 aesmc v0.16b,v0.16b
402 b .Lenter_cbc_enc128
403.Loop_cbc_enc128:
404 aese v0.16b,v16.16b
405 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700406 st1 {v6.16b},[x1],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800407.Lenter_cbc_enc128:
408 aese v0.16b,v17.16b
409 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700410 subs x2,x2,#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800411 aese v0.16b,v2.16b
412 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700413 csel x8,xzr,x8,eq
Adam Langleyd9e397b2015-01-22 14:27:53 -0800414 aese v0.16b,v3.16b
415 aesmc v0.16b,v0.16b
416 aese v0.16b,v18.16b
417 aesmc v0.16b,v0.16b
418 aese v0.16b,v19.16b
419 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700420 ld1 {v16.16b},[x0],x8
Adam Langleyd9e397b2015-01-22 14:27:53 -0800421 aese v0.16b,v20.16b
422 aesmc v0.16b,v0.16b
423 aese v0.16b,v21.16b
424 aesmc v0.16b,v0.16b
425 aese v0.16b,v22.16b
426 aesmc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700427 eor v16.16b,v16.16b,v5.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800428 aese v0.16b,v23.16b
429 eor v6.16b,v0.16b,v7.16b
430 b.hs .Loop_cbc_enc128
431
432 st1 {v6.16b},[x1],#16
433 b .Lcbc_done
434.align 5
435.Lcbc_dec:
436 ld1 {v18.16b},[x0],#16
437 subs x2,x2,#32 // bias
438 add w6,w5,#2
439 orr v3.16b,v0.16b,v0.16b
440 orr v1.16b,v0.16b,v0.16b
441 orr v19.16b,v18.16b,v18.16b
442 b.lo .Lcbc_dec_tail
443
444 orr v1.16b,v18.16b,v18.16b
445 ld1 {v18.16b},[x0],#16
446 orr v2.16b,v0.16b,v0.16b
447 orr v3.16b,v1.16b,v1.16b
448 orr v19.16b,v18.16b,v18.16b
449
450.Loop3x_cbc_dec:
451 aesd v0.16b,v16.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800452 aesimc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700453 aesd v1.16b,v16.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800454 aesimc v1.16b,v1.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700455 aesd v18.16b,v16.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800456 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700457 ld1 {v16.4s},[x7],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800458 subs w6,w6,#2
459 aesd v0.16b,v17.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800460 aesimc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700461 aesd v1.16b,v17.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800462 aesimc v1.16b,v1.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700463 aesd v18.16b,v17.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800464 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700465 ld1 {v17.4s},[x7],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800466 b.gt .Loop3x_cbc_dec
467
468 aesd v0.16b,v16.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700469 aesimc v0.16b,v0.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800470 aesd v1.16b,v16.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700471 aesimc v1.16b,v1.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800472 aesd v18.16b,v16.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800473 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700474 eor v4.16b,v6.16b,v7.16b
475 subs x2,x2,#0x30
476 eor v5.16b,v2.16b,v7.16b
477 csel x6,x2,x6,lo // x6, w6, is zero at this point
Adam Langleyd9e397b2015-01-22 14:27:53 -0800478 aesd v0.16b,v17.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800479 aesimc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700480 aesd v1.16b,v17.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800481 aesimc v1.16b,v1.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700482 aesd v18.16b,v17.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800483 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700484 eor v17.16b,v3.16b,v7.16b
485 add x0,x0,x6 // x0 is adjusted in such way that
Adam Langleyd9e397b2015-01-22 14:27:53 -0800486 // at exit from the loop v1.16b-v18.16b
487 // are loaded with last "words"
Adam Langleye9ada862015-05-11 17:20:37 -0700488 orr v6.16b,v19.16b,v19.16b
489 mov x7,x3
490 aesd v0.16b,v20.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800491 aesimc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700492 aesd v1.16b,v20.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800493 aesimc v1.16b,v1.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700494 aesd v18.16b,v20.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800495 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700496 ld1 {v2.16b},[x0],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800497 aesd v0.16b,v21.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700498 aesimc v0.16b,v0.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800499 aesd v1.16b,v21.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700500 aesimc v1.16b,v1.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800501 aesd v18.16b,v21.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800502 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700503 ld1 {v3.16b},[x0],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800504 aesd v0.16b,v22.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800505 aesimc v0.16b,v0.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700506 aesd v1.16b,v22.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800507 aesimc v1.16b,v1.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700508 aesd v18.16b,v22.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800509 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700510 ld1 {v19.16b},[x0],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800511 aesd v0.16b,v23.16b
512 aesd v1.16b,v23.16b
513 aesd v18.16b,v23.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700514 ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0]
515 add w6,w5,#2
Adam Langleyd9e397b2015-01-22 14:27:53 -0800516 eor v4.16b,v4.16b,v0.16b
517 eor v5.16b,v5.16b,v1.16b
518 eor v18.16b,v18.16b,v17.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700519 ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1]
Adam Langleyd9e397b2015-01-22 14:27:53 -0800520 st1 {v4.16b},[x1],#16
Adam Langleye9ada862015-05-11 17:20:37 -0700521 orr v0.16b,v2.16b,v2.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800522 st1 {v5.16b},[x1],#16
Adam Langleye9ada862015-05-11 17:20:37 -0700523 orr v1.16b,v3.16b,v3.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800524 st1 {v18.16b},[x1],#16
Adam Langleye9ada862015-05-11 17:20:37 -0700525 orr v18.16b,v19.16b,v19.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800526 b.hs .Loop3x_cbc_dec
527
528 cmn x2,#0x30
529 b.eq .Lcbc_done
530 nop
531
532.Lcbc_dec_tail:
533 aesd v1.16b,v16.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800534 aesimc v1.16b,v1.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700535 aesd v18.16b,v16.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800536 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700537 ld1 {v16.4s},[x7],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800538 subs w6,w6,#2
539 aesd v1.16b,v17.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800540 aesimc v1.16b,v1.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700541 aesd v18.16b,v17.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800542 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700543 ld1 {v17.4s},[x7],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800544 b.gt .Lcbc_dec_tail
545
546 aesd v1.16b,v16.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800547 aesimc v1.16b,v1.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700548 aesd v18.16b,v16.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800549 aesimc v18.16b,v18.16b
550 aesd v1.16b,v17.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800551 aesimc v1.16b,v1.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700552 aesd v18.16b,v17.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800553 aesimc v18.16b,v18.16b
554 aesd v1.16b,v20.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700555 aesimc v1.16b,v1.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800556 aesd v18.16b,v20.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800557 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700558 cmn x2,#0x20
Adam Langleyd9e397b2015-01-22 14:27:53 -0800559 aesd v1.16b,v21.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700560 aesimc v1.16b,v1.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800561 aesd v18.16b,v21.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800562 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700563 eor v5.16b,v6.16b,v7.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800564 aesd v1.16b,v22.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800565 aesimc v1.16b,v1.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700566 aesd v18.16b,v22.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800567 aesimc v18.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700568 eor v17.16b,v3.16b,v7.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800569 aesd v1.16b,v23.16b
570 aesd v18.16b,v23.16b
571 b.eq .Lcbc_dec_one
572 eor v5.16b,v5.16b,v1.16b
573 eor v17.16b,v17.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700574 orr v6.16b,v19.16b,v19.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800575 st1 {v5.16b},[x1],#16
576 st1 {v17.16b},[x1],#16
577 b .Lcbc_done
578
579.Lcbc_dec_one:
580 eor v5.16b,v5.16b,v18.16b
Adam Langleye9ada862015-05-11 17:20:37 -0700581 orr v6.16b,v19.16b,v19.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800582 st1 {v5.16b},[x1],#16
583
584.Lcbc_done:
585 st1 {v6.16b},[x4]
586.Lcbc_abort:
587 ldr x29,[sp],#16
588 ret
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400589.size aes_hw_cbc_encrypt,.-aes_hw_cbc_encrypt
590.globl aes_hw_ctr32_encrypt_blocks
591.hidden aes_hw_ctr32_encrypt_blocks
592.type aes_hw_ctr32_encrypt_blocks,%function
Adam Langleyd9e397b2015-01-22 14:27:53 -0800593.align 5
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400594aes_hw_ctr32_encrypt_blocks:
Adam Langleye9ada862015-05-11 17:20:37 -0700595 stp x29,x30,[sp,#-16]!
596 add x29,sp,#0
597 ldr w5,[x3,#240]
Adam Langleyd9e397b2015-01-22 14:27:53 -0800598
Adam Langleye9ada862015-05-11 17:20:37 -0700599 ldr w8, [x4, #12]
600 ld1 {v0.4s},[x4]
Adam Langleyd9e397b2015-01-22 14:27:53 -0800601
Adam Langleye9ada862015-05-11 17:20:37 -0700602 ld1 {v16.4s,v17.4s},[x3] // load key schedule...
603 sub w5,w5,#4
604 mov x12,#16
605 cmp x2,#2
606 add x7,x3,x5,lsl#4 // pointer to last 5 round keys
607 sub w5,w5,#2
608 ld1 {v20.4s,v21.4s},[x7],#32
609 ld1 {v22.4s,v23.4s},[x7],#32
610 ld1 {v7.4s},[x7]
611 add x7,x3,#32
612 mov w6,w5
Adam Langleyd9e397b2015-01-22 14:27:53 -0800613 csel x12,xzr,x12,lo
614#ifndef __ARMEB__
Adam Langleye9ada862015-05-11 17:20:37 -0700615 rev w8, w8
Adam Langleyd9e397b2015-01-22 14:27:53 -0800616#endif
Adam Langleye9ada862015-05-11 17:20:37 -0700617 orr v1.16b,v0.16b,v0.16b
618 add w10, w8, #1
619 orr v18.16b,v0.16b,v0.16b
620 add w8, w8, #2
621 orr v6.16b,v0.16b,v0.16b
622 rev w10, w10
623 mov v1.s[3],w10
624 b.ls .Lctr32_tail
625 rev w12, w8
626 sub x2,x2,#3 // bias
627 mov v18.s[3],w12
628 b .Loop3x_ctr32
Adam Langleyd9e397b2015-01-22 14:27:53 -0800629
630.align 4
631.Loop3x_ctr32:
Adam Langleye9ada862015-05-11 17:20:37 -0700632 aese v0.16b,v16.16b
633 aesmc v0.16b,v0.16b
634 aese v1.16b,v16.16b
635 aesmc v1.16b,v1.16b
636 aese v18.16b,v16.16b
637 aesmc v18.16b,v18.16b
638 ld1 {v16.4s},[x7],#16
639 subs w6,w6,#2
640 aese v0.16b,v17.16b
641 aesmc v0.16b,v0.16b
642 aese v1.16b,v17.16b
643 aesmc v1.16b,v1.16b
644 aese v18.16b,v17.16b
645 aesmc v18.16b,v18.16b
646 ld1 {v17.4s},[x7],#16
647 b.gt .Loop3x_ctr32
Adam Langleyd9e397b2015-01-22 14:27:53 -0800648
Adam Langleye9ada862015-05-11 17:20:37 -0700649 aese v0.16b,v16.16b
650 aesmc v4.16b,v0.16b
651 aese v1.16b,v16.16b
652 aesmc v5.16b,v1.16b
653 ld1 {v2.16b},[x0],#16
654 orr v0.16b,v6.16b,v6.16b
655 aese v18.16b,v16.16b
656 aesmc v18.16b,v18.16b
657 ld1 {v3.16b},[x0],#16
658 orr v1.16b,v6.16b,v6.16b
659 aese v4.16b,v17.16b
660 aesmc v4.16b,v4.16b
661 aese v5.16b,v17.16b
662 aesmc v5.16b,v5.16b
663 ld1 {v19.16b},[x0],#16
664 mov x7,x3
665 aese v18.16b,v17.16b
666 aesmc v17.16b,v18.16b
667 orr v18.16b,v6.16b,v6.16b
668 add w9,w8,#1
669 aese v4.16b,v20.16b
670 aesmc v4.16b,v4.16b
671 aese v5.16b,v20.16b
672 aesmc v5.16b,v5.16b
673 eor v2.16b,v2.16b,v7.16b
674 add w10,w8,#2
675 aese v17.16b,v20.16b
676 aesmc v17.16b,v17.16b
677 eor v3.16b,v3.16b,v7.16b
678 add w8,w8,#3
679 aese v4.16b,v21.16b
680 aesmc v4.16b,v4.16b
681 aese v5.16b,v21.16b
682 aesmc v5.16b,v5.16b
683 eor v19.16b,v19.16b,v7.16b
684 rev w9,w9
685 aese v17.16b,v21.16b
686 aesmc v17.16b,v17.16b
687 mov v0.s[3], w9
688 rev w10,w10
689 aese v4.16b,v22.16b
690 aesmc v4.16b,v4.16b
691 aese v5.16b,v22.16b
692 aesmc v5.16b,v5.16b
693 mov v1.s[3], w10
694 rev w12,w8
695 aese v17.16b,v22.16b
696 aesmc v17.16b,v17.16b
697 mov v18.s[3], w12
698 subs x2,x2,#3
699 aese v4.16b,v23.16b
700 aese v5.16b,v23.16b
701 aese v17.16b,v23.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800702
Adam Langleye9ada862015-05-11 17:20:37 -0700703 eor v2.16b,v2.16b,v4.16b
704 ld1 {v16.4s},[x7],#16 // re-pre-load rndkey[0]
705 st1 {v2.16b},[x1],#16
706 eor v3.16b,v3.16b,v5.16b
707 mov w6,w5
708 st1 {v3.16b},[x1],#16
709 eor v19.16b,v19.16b,v17.16b
710 ld1 {v17.4s},[x7],#16 // re-pre-load rndkey[1]
711 st1 {v19.16b},[x1],#16
712 b.hs .Loop3x_ctr32
Adam Langleyd9e397b2015-01-22 14:27:53 -0800713
Adam Langleye9ada862015-05-11 17:20:37 -0700714 adds x2,x2,#3
715 b.eq .Lctr32_done
716 cmp x2,#1
717 mov x12,#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800718 csel x12,xzr,x12,eq
719
720.Lctr32_tail:
Adam Langleye9ada862015-05-11 17:20:37 -0700721 aese v0.16b,v16.16b
722 aesmc v0.16b,v0.16b
723 aese v1.16b,v16.16b
724 aesmc v1.16b,v1.16b
725 ld1 {v16.4s},[x7],#16
726 subs w6,w6,#2
727 aese v0.16b,v17.16b
728 aesmc v0.16b,v0.16b
729 aese v1.16b,v17.16b
730 aesmc v1.16b,v1.16b
731 ld1 {v17.4s},[x7],#16
732 b.gt .Lctr32_tail
Adam Langleyd9e397b2015-01-22 14:27:53 -0800733
Adam Langleye9ada862015-05-11 17:20:37 -0700734 aese v0.16b,v16.16b
735 aesmc v0.16b,v0.16b
736 aese v1.16b,v16.16b
737 aesmc v1.16b,v1.16b
738 aese v0.16b,v17.16b
739 aesmc v0.16b,v0.16b
740 aese v1.16b,v17.16b
741 aesmc v1.16b,v1.16b
742 ld1 {v2.16b},[x0],x12
743 aese v0.16b,v20.16b
744 aesmc v0.16b,v0.16b
745 aese v1.16b,v20.16b
746 aesmc v1.16b,v1.16b
747 ld1 {v3.16b},[x0]
748 aese v0.16b,v21.16b
749 aesmc v0.16b,v0.16b
750 aese v1.16b,v21.16b
751 aesmc v1.16b,v1.16b
752 eor v2.16b,v2.16b,v7.16b
753 aese v0.16b,v22.16b
754 aesmc v0.16b,v0.16b
755 aese v1.16b,v22.16b
756 aesmc v1.16b,v1.16b
757 eor v3.16b,v3.16b,v7.16b
758 aese v0.16b,v23.16b
759 aese v1.16b,v23.16b
Adam Langleyd9e397b2015-01-22 14:27:53 -0800760
Adam Langleye9ada862015-05-11 17:20:37 -0700761 cmp x2,#1
762 eor v2.16b,v2.16b,v0.16b
763 eor v3.16b,v3.16b,v1.16b
764 st1 {v2.16b},[x1],#16
765 b.eq .Lctr32_done
766 st1 {v3.16b},[x1]
Adam Langleyd9e397b2015-01-22 14:27:53 -0800767
768.Lctr32_done:
Adam Langleye9ada862015-05-11 17:20:37 -0700769 ldr x29,[sp],#16
Adam Langleyd9e397b2015-01-22 14:27:53 -0800770 ret
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400771.size aes_hw_ctr32_encrypt_blocks,.-aes_hw_ctr32_encrypt_blocks
Adam Langleyd9e397b2015-01-22 14:27:53 -0800772#endif
Tobias Thierer01e077a2019-10-09 20:48:13 +0100773.section .note.GNU-stack,"",%progbits
David Benjamin4969cc92016-04-22 15:02:23 -0400774#endif
Robert Sloan726e9d12018-09-11 11:45:04 -0700775#endif // !OPENSSL_NO_ASM