xref: /minix3/crypto/external/bsd/openssl/lib/libcrypto/arch/arm/aesv8-armx.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc#include "arm_arch.h"
2*0a6a1f1dSLionel Sambuc#include "arm_asm.h"
3*0a6a1f1dSLionel Sambuc
4*0a6a1f1dSLionel Sambuc#if __ARM_MAX_ARCH__>=7
5*0a6a1f1dSLionel Sambuc.text
6*0a6a1f1dSLionel Sambuc.arch	armv7-a
7*0a6a1f1dSLionel Sambuc.fpu	neon
8*0a6a1f1dSLionel Sambuc.code	32
9*0a6a1f1dSLionel Sambuc.align	5
10*0a6a1f1dSLionel Sambucrcon:
11*0a6a1f1dSLionel Sambuc.long	0x01,0x01,0x01,0x01
12*0a6a1f1dSLionel Sambuc.long	0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d	@ rotate-n-splat
13*0a6a1f1dSLionel Sambuc.long	0x1b,0x1b,0x1b,0x1b
14*0a6a1f1dSLionel Sambuc
15*0a6a1f1dSLionel Sambuc.globl	aes_v8_set_encrypt_key
16*0a6a1f1dSLionel Sambuc.type	aes_v8_set_encrypt_key,%function
17*0a6a1f1dSLionel Sambuc.align	5
18*0a6a1f1dSLionel Sambucaes_v8_set_encrypt_key:
19*0a6a1f1dSLionel Sambuc.Lenc_key:
20*0a6a1f1dSLionel Sambuc	mov	r3,#-1
21*0a6a1f1dSLionel Sambuc	cmp	r0,#0
22*0a6a1f1dSLionel Sambuc	beq	.Lenc_key_abort
23*0a6a1f1dSLionel Sambuc	cmp	r2,#0
24*0a6a1f1dSLionel Sambuc	beq	.Lenc_key_abort
25*0a6a1f1dSLionel Sambuc	mov	r3,#-2
26*0a6a1f1dSLionel Sambuc	cmp	r1,#128
27*0a6a1f1dSLionel Sambuc	blt	.Lenc_key_abort
28*0a6a1f1dSLionel Sambuc	cmp	r1,#256
29*0a6a1f1dSLionel Sambuc	bgt	.Lenc_key_abort
30*0a6a1f1dSLionel Sambuc	tst	r1,#0x3f
31*0a6a1f1dSLionel Sambuc	bne	.Lenc_key_abort
32*0a6a1f1dSLionel Sambuc
33*0a6a1f1dSLionel Sambuc	adr	r3,rcon
34*0a6a1f1dSLionel Sambuc	cmp	r1,#192
35*0a6a1f1dSLionel Sambuc
36*0a6a1f1dSLionel Sambuc	veor	q0,q0,q0
37*0a6a1f1dSLionel Sambuc	vld1.8	{q3},[r0]!
38*0a6a1f1dSLionel Sambuc	mov	r1,#8		@ reuse r1
39*0a6a1f1dSLionel Sambuc	vld1.32	{q1,q2},[r3]!
40*0a6a1f1dSLionel Sambuc
41*0a6a1f1dSLionel Sambuc	blt	.Loop128
42*0a6a1f1dSLionel Sambuc	beq	.L192
43*0a6a1f1dSLionel Sambuc	b	.L256
44*0a6a1f1dSLionel Sambuc
45*0a6a1f1dSLionel Sambuc.align	4
46*0a6a1f1dSLionel Sambuc.Loop128:
47*0a6a1f1dSLionel Sambuc	vtbl.8	d20,{q3},d4
48*0a6a1f1dSLionel Sambuc	vtbl.8	d21,{q3},d5
49*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q3,#12
50*0a6a1f1dSLionel Sambuc	vst1.32	{q3},[r2]!
51*0a6a1f1dSLionel Sambuc	.inst	0xf3f04300		@ aese q10,q0
52*0a6a1f1dSLionel Sambuc	subs	r1,r1,#1
53*0a6a1f1dSLionel Sambuc
54*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
55*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
56*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
57*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
58*0a6a1f1dSLionel Sambuc	 veor	q10,q10,q1
59*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
60*0a6a1f1dSLionel Sambuc	vshl.u8	q1,q1,#1
61*0a6a1f1dSLionel Sambuc	veor	q3,q3,q10
62*0a6a1f1dSLionel Sambuc	bne	.Loop128
63*0a6a1f1dSLionel Sambuc
64*0a6a1f1dSLionel Sambuc	vld1.32	{q1},[r3]
65*0a6a1f1dSLionel Sambuc
66*0a6a1f1dSLionel Sambuc	vtbl.8	d20,{q3},d4
67*0a6a1f1dSLionel Sambuc	vtbl.8	d21,{q3},d5
68*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q3,#12
69*0a6a1f1dSLionel Sambuc	vst1.32	{q3},[r2]!
70*0a6a1f1dSLionel Sambuc	.inst	0xf3f04300	@ aese q10,q0
71*0a6a1f1dSLionel Sambuc
72*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
73*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
74*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
75*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
76*0a6a1f1dSLionel Sambuc	 veor	q10,q10,q1
77*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
78*0a6a1f1dSLionel Sambuc	vshl.u8	q1,q1,#1
79*0a6a1f1dSLionel Sambuc	veor	q3,q3,q10
80*0a6a1f1dSLionel Sambuc
81*0a6a1f1dSLionel Sambuc	vtbl.8	d20,{q3},d4
82*0a6a1f1dSLionel Sambuc	vtbl.8	d21,{q3},d5
83*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q3,#12
84*0a6a1f1dSLionel Sambuc	vst1.32	{q3},[r2]!
85*0a6a1f1dSLionel Sambuc	.inst	0xf3f04300	@ aese q10,q0
86*0a6a1f1dSLionel Sambuc
87*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
88*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
89*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
90*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
91*0a6a1f1dSLionel Sambuc	 veor	q10,q10,q1
92*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
93*0a6a1f1dSLionel Sambuc	veor	q3,q3,q10
94*0a6a1f1dSLionel Sambuc	vst1.32	{q3},[r2]
95*0a6a1f1dSLionel Sambuc	add	r2,r2,#0x50
96*0a6a1f1dSLionel Sambuc
97*0a6a1f1dSLionel Sambuc	mov	r12,#10
98*0a6a1f1dSLionel Sambuc	b	.Ldone
99*0a6a1f1dSLionel Sambuc
100*0a6a1f1dSLionel Sambuc.align	4
101*0a6a1f1dSLionel Sambuc.L192:
102*0a6a1f1dSLionel Sambuc	vld1.8	{d16},[r0]!
103*0a6a1f1dSLionel Sambuc	vmov.i8	q10,#8			@ borrow q10
104*0a6a1f1dSLionel Sambuc	vst1.32	{q3},[r2]!
105*0a6a1f1dSLionel Sambuc	vsub.i8	q2,q2,q10	@ adjust the mask
106*0a6a1f1dSLionel Sambuc
107*0a6a1f1dSLionel Sambuc.Loop192:
108*0a6a1f1dSLionel Sambuc	vtbl.8	d20,{q8},d4
109*0a6a1f1dSLionel Sambuc	vtbl.8	d21,{q8},d5
110*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q3,#12
111*0a6a1f1dSLionel Sambuc	vst1.32	{d16},[r2]!
112*0a6a1f1dSLionel Sambuc	.inst	0xf3f04300	@ aese q10,q0
113*0a6a1f1dSLionel Sambuc	subs	r1,r1,#1
114*0a6a1f1dSLionel Sambuc
115*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
116*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
117*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
118*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
119*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
120*0a6a1f1dSLionel Sambuc
121*0a6a1f1dSLionel Sambuc	vdup.32	q9,d7[1]
122*0a6a1f1dSLionel Sambuc	veor	q9,q9,q8
123*0a6a1f1dSLionel Sambuc	 veor	q10,q10,q1
124*0a6a1f1dSLionel Sambuc	vext.8	q8,q0,q8,#12
125*0a6a1f1dSLionel Sambuc	vshl.u8	q1,q1,#1
126*0a6a1f1dSLionel Sambuc	veor	q8,q8,q9
127*0a6a1f1dSLionel Sambuc	veor	q3,q3,q10
128*0a6a1f1dSLionel Sambuc	veor	q8,q8,q10
129*0a6a1f1dSLionel Sambuc	vst1.32	{q3},[r2]!
130*0a6a1f1dSLionel Sambuc	bne	.Loop192
131*0a6a1f1dSLionel Sambuc
132*0a6a1f1dSLionel Sambuc	mov	r12,#12
133*0a6a1f1dSLionel Sambuc	add	r2,r2,#0x20
134*0a6a1f1dSLionel Sambuc	b	.Ldone
135*0a6a1f1dSLionel Sambuc
136*0a6a1f1dSLionel Sambuc.align	4
137*0a6a1f1dSLionel Sambuc.L256:
138*0a6a1f1dSLionel Sambuc	vld1.8	{q8},[r0]
139*0a6a1f1dSLionel Sambuc	mov	r1,#7
140*0a6a1f1dSLionel Sambuc	mov	r12,#14
141*0a6a1f1dSLionel Sambuc	vst1.32	{q3},[r2]!
142*0a6a1f1dSLionel Sambuc
143*0a6a1f1dSLionel Sambuc.Loop256:
144*0a6a1f1dSLionel Sambuc	vtbl.8	d20,{q8},d4
145*0a6a1f1dSLionel Sambuc	vtbl.8	d21,{q8},d5
146*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q3,#12
147*0a6a1f1dSLionel Sambuc	vst1.32	{q8},[r2]!
148*0a6a1f1dSLionel Sambuc	.inst	0xf3f04300	@ aese q10,q0
149*0a6a1f1dSLionel Sambuc	subs	r1,r1,#1
150*0a6a1f1dSLionel Sambuc
151*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
152*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
153*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
154*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
155*0a6a1f1dSLionel Sambuc	 veor	q10,q10,q1
156*0a6a1f1dSLionel Sambuc	veor	q3,q3,q9
157*0a6a1f1dSLionel Sambuc	vshl.u8	q1,q1,#1
158*0a6a1f1dSLionel Sambuc	veor	q3,q3,q10
159*0a6a1f1dSLionel Sambuc	vst1.32	{q3},[r2]!
160*0a6a1f1dSLionel Sambuc	beq	.Ldone
161*0a6a1f1dSLionel Sambuc
162*0a6a1f1dSLionel Sambuc	vdup.32	q10,d7[1]
163*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q8,#12
164*0a6a1f1dSLionel Sambuc	.inst	0xf3f04300	@ aese q10,q0
165*0a6a1f1dSLionel Sambuc
166*0a6a1f1dSLionel Sambuc	veor	q8,q8,q9
167*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
168*0a6a1f1dSLionel Sambuc	veor	q8,q8,q9
169*0a6a1f1dSLionel Sambuc	vext.8	q9,q0,q9,#12
170*0a6a1f1dSLionel Sambuc	veor	q8,q8,q9
171*0a6a1f1dSLionel Sambuc
172*0a6a1f1dSLionel Sambuc	veor	q8,q8,q10
173*0a6a1f1dSLionel Sambuc	b	.Loop256
174*0a6a1f1dSLionel Sambuc
175*0a6a1f1dSLionel Sambuc.Ldone:
176*0a6a1f1dSLionel Sambuc	str	r12,[r2]
177*0a6a1f1dSLionel Sambuc	mov	r3,#0
178*0a6a1f1dSLionel Sambuc
179*0a6a1f1dSLionel Sambuc.Lenc_key_abort:
180*0a6a1f1dSLionel Sambuc	mov	r0,r3			@ return value
181*0a6a1f1dSLionel Sambuc
182*0a6a1f1dSLionel Sambuc	RET
183*0a6a1f1dSLionel Sambuc.size	aes_v8_set_encrypt_key,.-aes_v8_set_encrypt_key
184*0a6a1f1dSLionel Sambuc
185*0a6a1f1dSLionel Sambuc.globl	aes_v8_set_decrypt_key
186*0a6a1f1dSLionel Sambuc.type	aes_v8_set_decrypt_key,%function
187*0a6a1f1dSLionel Sambuc.align	5
188*0a6a1f1dSLionel Sambucaes_v8_set_decrypt_key:
189*0a6a1f1dSLionel Sambuc	stmdb	sp!,{r4,lr}
190*0a6a1f1dSLionel Sambuc	bl	.Lenc_key
191*0a6a1f1dSLionel Sambuc
192*0a6a1f1dSLionel Sambuc	cmp	r0,#0
193*0a6a1f1dSLionel Sambuc	bne	.Ldec_key_abort
194*0a6a1f1dSLionel Sambuc
195*0a6a1f1dSLionel Sambuc	sub	r2,r2,#240		@ restore original r2
196*0a6a1f1dSLionel Sambuc	mov	r4,#-16
197*0a6a1f1dSLionel Sambuc	add	r0,r2,r12,lsl#4	@ end of key schedule
198*0a6a1f1dSLionel Sambuc
199*0a6a1f1dSLionel Sambuc	vld1.32	{q0},[r2]
200*0a6a1f1dSLionel Sambuc	vld1.32	{q1},[r0]
201*0a6a1f1dSLionel Sambuc	vst1.32	{q0},[r0],r4
202*0a6a1f1dSLionel Sambuc	vst1.32	{q1},[r2]!
203*0a6a1f1dSLionel Sambuc
204*0a6a1f1dSLionel Sambuc.Loop_imc:
205*0a6a1f1dSLionel Sambuc	vld1.32	{q0},[r2]
206*0a6a1f1dSLionel Sambuc	vld1.32	{q1},[r0]
207*0a6a1f1dSLionel Sambuc	.inst	0xf3b003c0	@ aesimc q0,q0
208*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
209*0a6a1f1dSLionel Sambuc	vst1.32	{q0},[r0],r4
210*0a6a1f1dSLionel Sambuc	vst1.32	{q1},[r2]!
211*0a6a1f1dSLionel Sambuc	cmp	r0,r2
212*0a6a1f1dSLionel Sambuc	bhi	.Loop_imc
213*0a6a1f1dSLionel Sambuc
214*0a6a1f1dSLionel Sambuc	vld1.32	{q0},[r2]
215*0a6a1f1dSLionel Sambuc	.inst	0xf3b003c0	@ aesimc q0,q0
216*0a6a1f1dSLionel Sambuc	vst1.32	{q0},[r0]
217*0a6a1f1dSLionel Sambuc
218*0a6a1f1dSLionel Sambuc	eor	r0,r0,r0		@ return value
219*0a6a1f1dSLionel Sambuc.Ldec_key_abort:
220*0a6a1f1dSLionel Sambuc	ldmia	sp!,{r4,pc}
221*0a6a1f1dSLionel Sambuc.size	aes_v8_set_decrypt_key,.-aes_v8_set_decrypt_key
222*0a6a1f1dSLionel Sambuc.globl	aes_v8_encrypt
223*0a6a1f1dSLionel Sambuc.type	aes_v8_encrypt,%function
224*0a6a1f1dSLionel Sambuc.align	5
225*0a6a1f1dSLionel Sambucaes_v8_encrypt:
226*0a6a1f1dSLionel Sambuc	ldr	r3,[r2,#240]
227*0a6a1f1dSLionel Sambuc	vld1.32	{q0},[r2]!
228*0a6a1f1dSLionel Sambuc	vld1.8	{q2},[r0]
229*0a6a1f1dSLionel Sambuc	sub	r3,r3,#2
230*0a6a1f1dSLionel Sambuc	vld1.32	{q1},[r2]!
231*0a6a1f1dSLionel Sambuc
232*0a6a1f1dSLionel Sambuc.Loop_enc:
233*0a6a1f1dSLionel Sambuc	.inst	0xf3b04300	@ aese q2,q0
234*0a6a1f1dSLionel Sambuc	vld1.32	{q0},[r2]!
235*0a6a1f1dSLionel Sambuc	.inst	0xf3b04384	@ aesmc q2,q2
236*0a6a1f1dSLionel Sambuc	subs	r3,r3,#2
237*0a6a1f1dSLionel Sambuc	.inst	0xf3b04302	@ aese q2,q1
238*0a6a1f1dSLionel Sambuc	vld1.32	{q1},[r2]!
239*0a6a1f1dSLionel Sambuc	.inst	0xf3b04384	@ aesmc q2,q2
240*0a6a1f1dSLionel Sambuc	bgt	.Loop_enc
241*0a6a1f1dSLionel Sambuc
242*0a6a1f1dSLionel Sambuc	.inst	0xf3b04300	@ aese q2,q0
243*0a6a1f1dSLionel Sambuc	vld1.32	{q0},[r2]
244*0a6a1f1dSLionel Sambuc	.inst	0xf3b04384	@ aesmc q2,q2
245*0a6a1f1dSLionel Sambuc	.inst	0xf3b04302	@ aese q2,q1
246*0a6a1f1dSLionel Sambuc	veor	q2,q2,q0
247*0a6a1f1dSLionel Sambuc
248*0a6a1f1dSLionel Sambuc	vst1.8	{q2},[r1]
249*0a6a1f1dSLionel Sambuc	RET
250*0a6a1f1dSLionel Sambuc.size	aes_v8_encrypt,.-aes_v8_encrypt
251*0a6a1f1dSLionel Sambuc.globl	aes_v8_decrypt
252*0a6a1f1dSLionel Sambuc.type	aes_v8_decrypt,%function
253*0a6a1f1dSLionel Sambuc.align	5
254*0a6a1f1dSLionel Sambucaes_v8_decrypt:
255*0a6a1f1dSLionel Sambuc	ldr	r3,[r2,#240]
256*0a6a1f1dSLionel Sambuc	vld1.32	{q0},[r2]!
257*0a6a1f1dSLionel Sambuc	vld1.8	{q2},[r0]
258*0a6a1f1dSLionel Sambuc	sub	r3,r3,#2
259*0a6a1f1dSLionel Sambuc	vld1.32	{q1},[r2]!
260*0a6a1f1dSLionel Sambuc
261*0a6a1f1dSLionel Sambuc.Loop_dec:
262*0a6a1f1dSLionel Sambuc	.inst	0xf3b04340	@ aesd q2,q0
263*0a6a1f1dSLionel Sambuc	vld1.32	{q0},[r2]!
264*0a6a1f1dSLionel Sambuc	.inst	0xf3b043c4	@ aesimc q2,q2
265*0a6a1f1dSLionel Sambuc	subs	r3,r3,#2
266*0a6a1f1dSLionel Sambuc	.inst	0xf3b04342	@ aesd q2,q1
267*0a6a1f1dSLionel Sambuc	vld1.32	{q1},[r2]!
268*0a6a1f1dSLionel Sambuc	.inst	0xf3b043c4	@ aesimc q2,q2
269*0a6a1f1dSLionel Sambuc	bgt	.Loop_dec
270*0a6a1f1dSLionel Sambuc
271*0a6a1f1dSLionel Sambuc	.inst	0xf3b04340	@ aesd q2,q0
272*0a6a1f1dSLionel Sambuc	vld1.32	{q0},[r2]
273*0a6a1f1dSLionel Sambuc	.inst	0xf3b043c4	@ aesimc q2,q2
274*0a6a1f1dSLionel Sambuc	.inst	0xf3b04342	@ aesd q2,q1
275*0a6a1f1dSLionel Sambuc	veor	q2,q2,q0
276*0a6a1f1dSLionel Sambuc
277*0a6a1f1dSLionel Sambuc	vst1.8	{q2},[r1]
278*0a6a1f1dSLionel Sambuc	RET
279*0a6a1f1dSLionel Sambuc.size	aes_v8_decrypt,.-aes_v8_decrypt
280*0a6a1f1dSLionel Sambuc.globl	aes_v8_cbc_encrypt
281*0a6a1f1dSLionel Sambuc.type	aes_v8_cbc_encrypt,%function
282*0a6a1f1dSLionel Sambuc.align	5
283*0a6a1f1dSLionel Sambucaes_v8_cbc_encrypt:
284*0a6a1f1dSLionel Sambuc	mov	ip,sp
285*0a6a1f1dSLionel Sambuc	stmdb	sp!,{r4-r8,lr}
286*0a6a1f1dSLionel Sambuc	vstmdb	sp!,{d8-d15}            @ ABI specification says so
287*0a6a1f1dSLionel Sambuc	ldmia	ip,{r4-r5}		@ load remaining args
288*0a6a1f1dSLionel Sambuc	subs	r2,r2,#16
289*0a6a1f1dSLionel Sambuc	mov	r8,#16
290*0a6a1f1dSLionel Sambuc	blo	.Lcbc_abort
291*0a6a1f1dSLionel Sambuc	moveq	r8,#0
292*0a6a1f1dSLionel Sambuc
293*0a6a1f1dSLionel Sambuc	cmp	r5,#0			@ en- or decrypting?
294*0a6a1f1dSLionel Sambuc	ldr	r5,[r3,#240]
295*0a6a1f1dSLionel Sambuc	and	r2,r2,#-16
296*0a6a1f1dSLionel Sambuc	vld1.8	{q6},[r4]
297*0a6a1f1dSLionel Sambuc	vld1.8	{q0},[r0],r8
298*0a6a1f1dSLionel Sambuc
299*0a6a1f1dSLionel Sambuc	vld1.32	{q8-q9},[r3]		@ load key schedule...
300*0a6a1f1dSLionel Sambuc	sub	r5,r5,#6
301*0a6a1f1dSLionel Sambuc	add	r7,r3,r5,lsl#4	@ pointer to last 7 round keys
302*0a6a1f1dSLionel Sambuc	sub	r5,r5,#2
303*0a6a1f1dSLionel Sambuc	vld1.32	{q10-q11},[r7]!
304*0a6a1f1dSLionel Sambuc	vld1.32	{q12-q13},[r7]!
305*0a6a1f1dSLionel Sambuc	vld1.32	{q14-q15},[r7]!
306*0a6a1f1dSLionel Sambuc	vld1.32	{q7},[r7]
307*0a6a1f1dSLionel Sambuc
308*0a6a1f1dSLionel Sambuc	add	r7,r3,#32
309*0a6a1f1dSLionel Sambuc	mov	r6,r5
310*0a6a1f1dSLionel Sambuc	beq	.Lcbc_dec
311*0a6a1f1dSLionel Sambuc
312*0a6a1f1dSLionel Sambuc	cmp	r5,#2
313*0a6a1f1dSLionel Sambuc	veor	q0,q0,q6
314*0a6a1f1dSLionel Sambuc	veor	q5,q8,q7
315*0a6a1f1dSLionel Sambuc	beq	.Lcbc_enc128
316*0a6a1f1dSLionel Sambuc
317*0a6a1f1dSLionel Sambuc.Loop_cbc_enc:
318*0a6a1f1dSLionel Sambuc	.inst	0xf3b00320	@ aese q0,q8
319*0a6a1f1dSLionel Sambuc	vld1.32	{q8},[r7]!
320*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
321*0a6a1f1dSLionel Sambuc	subs	r6,r6,#2
322*0a6a1f1dSLionel Sambuc	.inst	0xf3b00322	@ aese q0,q9
323*0a6a1f1dSLionel Sambuc	vld1.32	{q9},[r7]!
324*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
325*0a6a1f1dSLionel Sambuc	bgt	.Loop_cbc_enc
326*0a6a1f1dSLionel Sambuc
327*0a6a1f1dSLionel Sambuc	.inst	0xf3b00320	@ aese q0,q8
328*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
329*0a6a1f1dSLionel Sambuc	 subs	r2,r2,#16
330*0a6a1f1dSLionel Sambuc	.inst	0xf3b00322	@ aese q0,q9
331*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
332*0a6a1f1dSLionel Sambuc	 moveq	r8,#0
333*0a6a1f1dSLionel Sambuc	.inst	0xf3b00324	@ aese q0,q10
334*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
335*0a6a1f1dSLionel Sambuc	 add	r7,r3,#16
336*0a6a1f1dSLionel Sambuc	.inst	0xf3b00326	@ aese q0,q11
337*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
338*0a6a1f1dSLionel Sambuc	 vld1.8	{q8},[r0],r8
339*0a6a1f1dSLionel Sambuc	.inst	0xf3b00328	@ aese q0,q12
340*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
341*0a6a1f1dSLionel Sambuc	 veor	q8,q8,q5
342*0a6a1f1dSLionel Sambuc	.inst	0xf3b0032a	@ aese q0,q13
343*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
344*0a6a1f1dSLionel Sambuc	 vld1.32 {q9},[r7]!	@ re-pre-load rndkey[1]
345*0a6a1f1dSLionel Sambuc	.inst	0xf3b0032c	@ aese q0,q14
346*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
347*0a6a1f1dSLionel Sambuc	.inst	0xf3b0032e	@ aese q0,q15
348*0a6a1f1dSLionel Sambuc
349*0a6a1f1dSLionel Sambuc	 mov	r6,r5
350*0a6a1f1dSLionel Sambuc	veor	q6,q0,q7
351*0a6a1f1dSLionel Sambuc	vst1.8	{q6},[r1]!
352*0a6a1f1dSLionel Sambuc	bhs	.Loop_cbc_enc
353*0a6a1f1dSLionel Sambuc
354*0a6a1f1dSLionel Sambuc	b	.Lcbc_done
355*0a6a1f1dSLionel Sambuc
356*0a6a1f1dSLionel Sambuc.align	5
357*0a6a1f1dSLionel Sambuc.Lcbc_enc128:
358*0a6a1f1dSLionel Sambuc	vld1.32	{q2-q3},[r7]
359*0a6a1f1dSLionel Sambuc	.inst	0xf3b00320	@ aese q0,q8
360*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
361*0a6a1f1dSLionel Sambuc	b	.Lenter_cbc_enc128
362*0a6a1f1dSLionel Sambuc.Loop_cbc_enc128:
363*0a6a1f1dSLionel Sambuc	.inst	0xf3b00320	@ aese q0,q8
364*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
365*0a6a1f1dSLionel Sambuc	 vst1.8	{q6},[r1]!
366*0a6a1f1dSLionel Sambuc.Lenter_cbc_enc128:
367*0a6a1f1dSLionel Sambuc	.inst	0xf3b00322	@ aese q0,q9
368*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
369*0a6a1f1dSLionel Sambuc	 subs	r2,r2,#16
370*0a6a1f1dSLionel Sambuc	.inst	0xf3b00304	@ aese q0,q2
371*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
372*0a6a1f1dSLionel Sambuc	 moveq	r8,#0
373*0a6a1f1dSLionel Sambuc	.inst	0xf3b00306	@ aese q0,q3
374*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
375*0a6a1f1dSLionel Sambuc	.inst	0xf3b00324	@ aese q0,q10
376*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
377*0a6a1f1dSLionel Sambuc	.inst	0xf3b00326	@ aese q0,q11
378*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
379*0a6a1f1dSLionel Sambuc	 vld1.8	{q8},[r0],r8
380*0a6a1f1dSLionel Sambuc	.inst	0xf3b00328	@ aese q0,q12
381*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
382*0a6a1f1dSLionel Sambuc	.inst	0xf3b0032a	@ aese q0,q13
383*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
384*0a6a1f1dSLionel Sambuc	.inst	0xf3b0032c	@ aese q0,q14
385*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
386*0a6a1f1dSLionel Sambuc	 veor	q8,q8,q5
387*0a6a1f1dSLionel Sambuc	.inst	0xf3b0032e	@ aese q0,q15
388*0a6a1f1dSLionel Sambuc	veor	q6,q0,q7
389*0a6a1f1dSLionel Sambuc	bhs	.Loop_cbc_enc128
390*0a6a1f1dSLionel Sambuc
391*0a6a1f1dSLionel Sambuc	vst1.8	{q6},[r1]!
392*0a6a1f1dSLionel Sambuc	b	.Lcbc_done
393*0a6a1f1dSLionel Sambuc.align	5
394*0a6a1f1dSLionel Sambuc.Lcbc_dec:
395*0a6a1f1dSLionel Sambuc	vld1.8	{q10},[r0]!
396*0a6a1f1dSLionel Sambuc	subs	r2,r2,#32		@ bias
397*0a6a1f1dSLionel Sambuc	add	r6,r5,#2
398*0a6a1f1dSLionel Sambuc	vorr	q3,q0,q0
399*0a6a1f1dSLionel Sambuc	vorr	q1,q0,q0
400*0a6a1f1dSLionel Sambuc	vorr	q11,q10,q10
401*0a6a1f1dSLionel Sambuc	blo	.Lcbc_dec_tail
402*0a6a1f1dSLionel Sambuc
403*0a6a1f1dSLionel Sambuc	vorr	q1,q10,q10
404*0a6a1f1dSLionel Sambuc	vld1.8	{q10},[r0]!
405*0a6a1f1dSLionel Sambuc	vorr	q2,q0,q0
406*0a6a1f1dSLionel Sambuc	vorr	q3,q1,q1
407*0a6a1f1dSLionel Sambuc	vorr	q11,q10,q10
408*0a6a1f1dSLionel Sambuc
409*0a6a1f1dSLionel Sambuc.Loop3x_cbc_dec:
410*0a6a1f1dSLionel Sambuc	.inst	0xf3b00360	@ aesd q0,q8
411*0a6a1f1dSLionel Sambuc	.inst	0xf3b02360	@ aesd q1,q8
412*0a6a1f1dSLionel Sambuc	.inst	0xf3f04360	@ aesd q10,q8
413*0a6a1f1dSLionel Sambuc	vld1.32	{q8},[r7]!
414*0a6a1f1dSLionel Sambuc	.inst	0xf3b003c0	@ aesimc q0,q0
415*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
416*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
417*0a6a1f1dSLionel Sambuc	subs	r6,r6,#2
418*0a6a1f1dSLionel Sambuc	.inst	0xf3b00362	@ aesd q0,q9
419*0a6a1f1dSLionel Sambuc	.inst	0xf3b02362	@ aesd q1,q9
420*0a6a1f1dSLionel Sambuc	.inst	0xf3f04362	@ aesd q10,q9
421*0a6a1f1dSLionel Sambuc	vld1.32	{q9},[r7]!
422*0a6a1f1dSLionel Sambuc	.inst	0xf3b003c0	@ aesimc q0,q0
423*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
424*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
425*0a6a1f1dSLionel Sambuc	bgt	.Loop3x_cbc_dec
426*0a6a1f1dSLionel Sambuc
427*0a6a1f1dSLionel Sambuc	.inst	0xf3b00360	@ aesd q0,q8
428*0a6a1f1dSLionel Sambuc	.inst	0xf3b02360	@ aesd q1,q8
429*0a6a1f1dSLionel Sambuc	.inst	0xf3f04360	@ aesd q10,q8
430*0a6a1f1dSLionel Sambuc	 veor	q4,q6,q7
431*0a6a1f1dSLionel Sambuc	.inst	0xf3b003c0	@ aesimc q0,q0
432*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
433*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
434*0a6a1f1dSLionel Sambuc	 veor	q5,q2,q7
435*0a6a1f1dSLionel Sambuc	.inst	0xf3b00362	@ aesd q0,q9
436*0a6a1f1dSLionel Sambuc	.inst	0xf3b02362	@ aesd q1,q9
437*0a6a1f1dSLionel Sambuc	.inst	0xf3f04362	@ aesd q10,q9
438*0a6a1f1dSLionel Sambuc	 veor	q9,q3,q7
439*0a6a1f1dSLionel Sambuc	 subs	r2,r2,#0x30
440*0a6a1f1dSLionel Sambuc	.inst	0xf3b003c0	@ aesimc q0,q0
441*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
442*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
443*0a6a1f1dSLionel Sambuc	 vorr	q6,q11,q11
444*0a6a1f1dSLionel Sambuc	 movlo	r6,r2			@ r6, r6, is zero at this point
445*0a6a1f1dSLionel Sambuc	.inst	0xf3b00368	@ aesd q0,q12
446*0a6a1f1dSLionel Sambuc	.inst	0xf3b02368	@ aesd q1,q12
447*0a6a1f1dSLionel Sambuc	.inst	0xf3f04368	@ aesd q10,q12
448*0a6a1f1dSLionel Sambuc	 add	r0,r0,r6		@ r0 is adjusted in such way that
449*0a6a1f1dSLionel Sambuc					@ at exit from the loop q1-q10
450*0a6a1f1dSLionel Sambuc					@ are loaded with last "words"
451*0a6a1f1dSLionel Sambuc	.inst	0xf3b003c0	@ aesimc q0,q0
452*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
453*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
454*0a6a1f1dSLionel Sambuc	 mov	r7,r3
455*0a6a1f1dSLionel Sambuc	.inst	0xf3b0036a	@ aesd q0,q13
456*0a6a1f1dSLionel Sambuc	.inst	0xf3b0236a	@ aesd q1,q13
457*0a6a1f1dSLionel Sambuc	.inst	0xf3f0436a	@ aesd q10,q13
458*0a6a1f1dSLionel Sambuc	 vld1.8	{q2},[r0]!
459*0a6a1f1dSLionel Sambuc	.inst	0xf3b003c0	@ aesimc q0,q0
460*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
461*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
462*0a6a1f1dSLionel Sambuc	 vld1.8	{q3},[r0]!
463*0a6a1f1dSLionel Sambuc	.inst	0xf3b0036c	@ aesd q0,q14
464*0a6a1f1dSLionel Sambuc	.inst	0xf3b0236c	@ aesd q1,q14
465*0a6a1f1dSLionel Sambuc	.inst	0xf3f0436c	@ aesd q10,q14
466*0a6a1f1dSLionel Sambuc	 vld1.8 {q11},[r0]!
467*0a6a1f1dSLionel Sambuc	.inst	0xf3b003c0	@ aesimc q0,q0
468*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
469*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
470*0a6a1f1dSLionel Sambuc	 vld1.32 {q8},[r7]!	@ re-pre-load rndkey[0]
471*0a6a1f1dSLionel Sambuc	.inst	0xf3b0036e	@ aesd q0,q15
472*0a6a1f1dSLionel Sambuc	.inst	0xf3b0236e	@ aesd q1,q15
473*0a6a1f1dSLionel Sambuc	.inst	0xf3f0436e	@ aesd q10,q15
474*0a6a1f1dSLionel Sambuc
475*0a6a1f1dSLionel Sambuc	 add	r6,r5,#2
476*0a6a1f1dSLionel Sambuc	veor	q4,q4,q0
477*0a6a1f1dSLionel Sambuc	veor	q5,q5,q1
478*0a6a1f1dSLionel Sambuc	veor	q10,q10,q9
479*0a6a1f1dSLionel Sambuc	 vld1.32 {q9},[r7]!	@ re-pre-load rndkey[1]
480*0a6a1f1dSLionel Sambuc	 vorr	q0,q2,q2
481*0a6a1f1dSLionel Sambuc	vst1.8	{q4},[r1]!
482*0a6a1f1dSLionel Sambuc	 vorr	q1,q3,q3
483*0a6a1f1dSLionel Sambuc	vst1.8	{q5},[r1]!
484*0a6a1f1dSLionel Sambuc	vst1.8	{q10},[r1]!
485*0a6a1f1dSLionel Sambuc	 vorr	q10,q11,q11
486*0a6a1f1dSLionel Sambuc	bhs	.Loop3x_cbc_dec
487*0a6a1f1dSLionel Sambuc
488*0a6a1f1dSLionel Sambuc	cmn	r2,#0x30
489*0a6a1f1dSLionel Sambuc	beq	.Lcbc_done
490*0a6a1f1dSLionel Sambuc	nop
491*0a6a1f1dSLionel Sambuc
492*0a6a1f1dSLionel Sambuc.Lcbc_dec_tail:
493*0a6a1f1dSLionel Sambuc	.inst	0xf3b02360	@ aesd q1,q8
494*0a6a1f1dSLionel Sambuc	.inst	0xf3f04360	@ aesd q10,q8
495*0a6a1f1dSLionel Sambuc	vld1.32	{q8},[r7]!
496*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
497*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
498*0a6a1f1dSLionel Sambuc	subs	r6,r6,#2
499*0a6a1f1dSLionel Sambuc	.inst	0xf3b02362	@ aesd q1,q9
500*0a6a1f1dSLionel Sambuc	.inst	0xf3f04362	@ aesd q10,q9
501*0a6a1f1dSLionel Sambuc	vld1.32	{q9},[r7]!
502*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
503*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
504*0a6a1f1dSLionel Sambuc	bgt	.Lcbc_dec_tail
505*0a6a1f1dSLionel Sambuc
506*0a6a1f1dSLionel Sambuc	.inst	0xf3b02360	@ aesd q1,q8
507*0a6a1f1dSLionel Sambuc	.inst	0xf3f04360	@ aesd q10,q8
508*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
509*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
510*0a6a1f1dSLionel Sambuc	.inst	0xf3b02362	@ aesd q1,q9
511*0a6a1f1dSLionel Sambuc	.inst	0xf3f04362	@ aesd q10,q9
512*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
513*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
514*0a6a1f1dSLionel Sambuc	.inst	0xf3b02368	@ aesd q1,q12
515*0a6a1f1dSLionel Sambuc	.inst	0xf3f04368	@ aesd q10,q12
516*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
517*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
518*0a6a1f1dSLionel Sambuc	 cmn	r2,#0x20
519*0a6a1f1dSLionel Sambuc	.inst	0xf3b0236a	@ aesd q1,q13
520*0a6a1f1dSLionel Sambuc	.inst	0xf3f0436a	@ aesd q10,q13
521*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
522*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
523*0a6a1f1dSLionel Sambuc	 veor	q5,q6,q7
524*0a6a1f1dSLionel Sambuc	.inst	0xf3b0236c	@ aesd q1,q14
525*0a6a1f1dSLionel Sambuc	.inst	0xf3f0436c	@ aesd q10,q14
526*0a6a1f1dSLionel Sambuc	.inst	0xf3b023c2	@ aesimc q1,q1
527*0a6a1f1dSLionel Sambuc	.inst	0xf3f043e4	@ aesimc q10,q10
528*0a6a1f1dSLionel Sambuc	 veor	q9,q3,q7
529*0a6a1f1dSLionel Sambuc	.inst	0xf3b0236e	@ aesd q1,q15
530*0a6a1f1dSLionel Sambuc	.inst	0xf3f0436e	@ aesd q10,q15
531*0a6a1f1dSLionel Sambuc	beq	.Lcbc_dec_one
532*0a6a1f1dSLionel Sambuc	veor	q5,q5,q1
533*0a6a1f1dSLionel Sambuc	veor	q9,q9,q10
534*0a6a1f1dSLionel Sambuc	 vorr	q6,q11,q11
535*0a6a1f1dSLionel Sambuc	vst1.8	{q5},[r1]!
536*0a6a1f1dSLionel Sambuc	vst1.8	{q9},[r1]!
537*0a6a1f1dSLionel Sambuc	b	.Lcbc_done
538*0a6a1f1dSLionel Sambuc
539*0a6a1f1dSLionel Sambuc.Lcbc_dec_one:
540*0a6a1f1dSLionel Sambuc	veor	q5,q5,q10
541*0a6a1f1dSLionel Sambuc	 vorr	q6,q11,q11
542*0a6a1f1dSLionel Sambuc	vst1.8	{q5},[r1]!
543*0a6a1f1dSLionel Sambuc
544*0a6a1f1dSLionel Sambuc.Lcbc_done:
545*0a6a1f1dSLionel Sambuc	vst1.8	{q6},[r4]
546*0a6a1f1dSLionel Sambuc.Lcbc_abort:
547*0a6a1f1dSLionel Sambuc	vldmia	sp!,{d8-d15}
548*0a6a1f1dSLionel Sambuc	ldmia	sp!,{r4-r8,pc}
549*0a6a1f1dSLionel Sambuc.size	aes_v8_cbc_encrypt,.-aes_v8_cbc_encrypt
550*0a6a1f1dSLionel Sambuc.globl	aes_v8_ctr32_encrypt_blocks
551*0a6a1f1dSLionel Sambuc.type	aes_v8_ctr32_encrypt_blocks,%function
552*0a6a1f1dSLionel Sambuc.align	5
553*0a6a1f1dSLionel Sambucaes_v8_ctr32_encrypt_blocks:
554*0a6a1f1dSLionel Sambuc	mov		ip,sp
555*0a6a1f1dSLionel Sambuc	stmdb		sp!,{r4-r10,lr}
556*0a6a1f1dSLionel Sambuc	vstmdb		sp!,{d8-d15}            @ ABI specification says so
557*0a6a1f1dSLionel Sambuc	ldr		r4, [ip]		@ load remaining arg
558*0a6a1f1dSLionel Sambuc	ldr		r5,[r3,#240]
559*0a6a1f1dSLionel Sambuc
560*0a6a1f1dSLionel Sambuc	ldr		r8, [r4, #12]
561*0a6a1f1dSLionel Sambuc	vld1.32		{q0},[r4]
562*0a6a1f1dSLionel Sambuc
563*0a6a1f1dSLionel Sambuc	vld1.32		{q8-q9},[r3]		@ load key schedule...
564*0a6a1f1dSLionel Sambuc	sub		r5,r5,#4
565*0a6a1f1dSLionel Sambuc	mov		r12,#16
566*0a6a1f1dSLionel Sambuc	cmp		r2,#2
567*0a6a1f1dSLionel Sambuc	add		r7,r3,r5,lsl#4	@ pointer to last 5 round keys
568*0a6a1f1dSLionel Sambuc	sub		r5,r5,#2
569*0a6a1f1dSLionel Sambuc	vld1.32		{q12-q13},[r7]!
570*0a6a1f1dSLionel Sambuc	vld1.32		{q14-q15},[r7]!
571*0a6a1f1dSLionel Sambuc	vld1.32		{q7},[r7]
572*0a6a1f1dSLionel Sambuc	add		r7,r3,#32
573*0a6a1f1dSLionel Sambuc	mov		r6,r5
574*0a6a1f1dSLionel Sambuc	movlo	r12,#0
575*0a6a1f1dSLionel Sambuc#ifndef __ARMEB__
576*0a6a1f1dSLionel Sambuc	rev		r8, r8
577*0a6a1f1dSLionel Sambuc#endif
578*0a6a1f1dSLionel Sambuc	vorr		q1,q0,q0
579*0a6a1f1dSLionel Sambuc	add		r10, r8, #1
580*0a6a1f1dSLionel Sambuc	vorr		q10,q0,q0
581*0a6a1f1dSLionel Sambuc	add		r8, r8, #2
582*0a6a1f1dSLionel Sambuc	vorr		q6,q0,q0
583*0a6a1f1dSLionel Sambuc	rev		r10, r10
584*0a6a1f1dSLionel Sambuc	vmov.32	d3[1],r10
585*0a6a1f1dSLionel Sambuc	bls		.Lctr32_tail
586*0a6a1f1dSLionel Sambuc	rev		r12, r8
587*0a6a1f1dSLionel Sambuc	sub		r2,r2,#3		@ bias
588*0a6a1f1dSLionel Sambuc	vmov.32	d21[1],r12
589*0a6a1f1dSLionel Sambuc	b		.Loop3x_ctr32
590*0a6a1f1dSLionel Sambuc
591*0a6a1f1dSLionel Sambuc.align	4
592*0a6a1f1dSLionel Sambuc.Loop3x_ctr32:
593*0a6a1f1dSLionel Sambuc	.inst	0xf3b00320	@ aese q0,q8
594*0a6a1f1dSLionel Sambuc	.inst	0xf3b02320	@ aese q1,q8
595*0a6a1f1dSLionel Sambuc	.inst	0xf3f04320	@ aese q10,q8
596*0a6a1f1dSLionel Sambuc	vld1.32		{q8},[r7]!
597*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
598*0a6a1f1dSLionel Sambuc	.inst	0xf3b02382	@ aesmc q1,q1
599*0a6a1f1dSLionel Sambuc	.inst	0xf3f043a4	@ aesmc q10,q10
600*0a6a1f1dSLionel Sambuc	subs		r6,r6,#2
601*0a6a1f1dSLionel Sambuc	.inst	0xf3b00322	@ aese q0,q9
602*0a6a1f1dSLionel Sambuc	.inst	0xf3b02322	@ aese q1,q9
603*0a6a1f1dSLionel Sambuc	.inst	0xf3f04322	@ aese q10,q9
604*0a6a1f1dSLionel Sambuc	vld1.32		{q9},[r7]!
605*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
606*0a6a1f1dSLionel Sambuc	.inst	0xf3b02382	@ aesmc q1,q1
607*0a6a1f1dSLionel Sambuc	.inst	0xf3f043a4	@ aesmc q10,q10
608*0a6a1f1dSLionel Sambuc	bgt		.Loop3x_ctr32
609*0a6a1f1dSLionel Sambuc
610*0a6a1f1dSLionel Sambuc	.inst	0xf3b00320	@ aese q0,q8
611*0a6a1f1dSLionel Sambuc	.inst	0xf3b02320	@ aese q1,q8
612*0a6a1f1dSLionel Sambuc	.inst	0xf3f04320	@ aese q10,q8
613*0a6a1f1dSLionel Sambuc	 mov		r7,r3
614*0a6a1f1dSLionel Sambuc	.inst	0xf3b08380	@ aesmc q4,q0
615*0a6a1f1dSLionel Sambuc	 vld1.8		{q2},[r0]!
616*0a6a1f1dSLionel Sambuc	.inst	0xf3b0a382	@ aesmc q5,q1
617*0a6a1f1dSLionel Sambuc	.inst	0xf3f043a4	@ aesmc q10,q10
618*0a6a1f1dSLionel Sambuc	 vorr		q0,q6,q6
619*0a6a1f1dSLionel Sambuc	.inst	0xf3b08322	@ aese q4,q9
620*0a6a1f1dSLionel Sambuc	 vld1.8		{q3},[r0]!
621*0a6a1f1dSLionel Sambuc	.inst	0xf3b0a322	@ aese q5,q9
622*0a6a1f1dSLionel Sambuc	.inst	0xf3f04322	@ aese q10,q9
623*0a6a1f1dSLionel Sambuc	 vorr		q1,q6,q6
624*0a6a1f1dSLionel Sambuc	.inst	0xf3b08388	@ aesmc q4,q4
625*0a6a1f1dSLionel Sambuc	 vld1.8		{q11},[r0]!
626*0a6a1f1dSLionel Sambuc	.inst	0xf3b0a38a	@ aesmc q5,q5
627*0a6a1f1dSLionel Sambuc	.inst	0xf3f023a4	@ aesmc q9,q10
628*0a6a1f1dSLionel Sambuc	 vorr		q10,q6,q6
629*0a6a1f1dSLionel Sambuc	 add		r9,r8,#1
630*0a6a1f1dSLionel Sambuc	.inst	0xf3b08328	@ aese q4,q12
631*0a6a1f1dSLionel Sambuc	.inst	0xf3b0a328	@ aese q5,q12
632*0a6a1f1dSLionel Sambuc	.inst	0xf3f02328	@ aese q9,q12
633*0a6a1f1dSLionel Sambuc	 veor		q2,q2,q7
634*0a6a1f1dSLionel Sambuc	 add		r10,r8,#2
635*0a6a1f1dSLionel Sambuc	.inst	0xf3b08388	@ aesmc q4,q4
636*0a6a1f1dSLionel Sambuc	.inst	0xf3b0a38a	@ aesmc q5,q5
637*0a6a1f1dSLionel Sambuc	.inst	0xf3f023a2	@ aesmc q9,q9
638*0a6a1f1dSLionel Sambuc	 veor		q3,q3,q7
639*0a6a1f1dSLionel Sambuc	 add		r8,r8,#3
640*0a6a1f1dSLionel Sambuc	.inst	0xf3b0832a	@ aese q4,q13
641*0a6a1f1dSLionel Sambuc	.inst	0xf3b0a32a	@ aese q5,q13
642*0a6a1f1dSLionel Sambuc	.inst	0xf3f0232a	@ aese q9,q13
643*0a6a1f1dSLionel Sambuc	 veor		q11,q11,q7
644*0a6a1f1dSLionel Sambuc	 rev		r9,r9
645*0a6a1f1dSLionel Sambuc	.inst	0xf3b08388	@ aesmc q4,q4
646*0a6a1f1dSLionel Sambuc	 vld1.32	 {q8},[r7]!	@ re-pre-load rndkey[0]
647*0a6a1f1dSLionel Sambuc	.inst	0xf3b0a38a	@ aesmc q5,q5
648*0a6a1f1dSLionel Sambuc	.inst	0xf3f023a2	@ aesmc q9,q9
649*0a6a1f1dSLionel Sambuc	 vmov.32	d1[1], r9
650*0a6a1f1dSLionel Sambuc	 rev		r10,r10
651*0a6a1f1dSLionel Sambuc	.inst	0xf3b0832c	@ aese q4,q14
652*0a6a1f1dSLionel Sambuc	.inst	0xf3b0a32c	@ aese q5,q14
653*0a6a1f1dSLionel Sambuc	.inst	0xf3f0232c	@ aese q9,q14
654*0a6a1f1dSLionel Sambuc	 vmov.32	d3[1], r10
655*0a6a1f1dSLionel Sambuc	 rev		r12,r8
656*0a6a1f1dSLionel Sambuc	.inst	0xf3b08388	@ aesmc q4,q4
657*0a6a1f1dSLionel Sambuc	.inst	0xf3b0a38a	@ aesmc q5,q5
658*0a6a1f1dSLionel Sambuc	.inst	0xf3f023a2	@ aesmc q9,q9
659*0a6a1f1dSLionel Sambuc	 vmov.32	d21[1], r12
660*0a6a1f1dSLionel Sambuc	 subs		r2,r2,#3
661*0a6a1f1dSLionel Sambuc	.inst	0xf3b0832e	@ aese q4,q15
662*0a6a1f1dSLionel Sambuc	.inst	0xf3b0a32e	@ aese q5,q15
663*0a6a1f1dSLionel Sambuc	.inst	0xf3f0232e	@ aese q9,q15
664*0a6a1f1dSLionel Sambuc
665*0a6a1f1dSLionel Sambuc	 mov		r6,r5
666*0a6a1f1dSLionel Sambuc	veor		q2,q2,q4
667*0a6a1f1dSLionel Sambuc	veor		q3,q3,q5
668*0a6a1f1dSLionel Sambuc	veor		q11,q11,q9
669*0a6a1f1dSLionel Sambuc	 vld1.32	 {q9},[r7]!	@ re-pre-load rndkey[1]
670*0a6a1f1dSLionel Sambuc	vst1.8		{q2},[r1]!
671*0a6a1f1dSLionel Sambuc	vst1.8		{q3},[r1]!
672*0a6a1f1dSLionel Sambuc	vst1.8		{q11},[r1]!
673*0a6a1f1dSLionel Sambuc	bhs		.Loop3x_ctr32
674*0a6a1f1dSLionel Sambuc
675*0a6a1f1dSLionel Sambuc	adds		r2,r2,#3
676*0a6a1f1dSLionel Sambuc	beq		.Lctr32_done
677*0a6a1f1dSLionel Sambuc	cmp		r2,#1
678*0a6a1f1dSLionel Sambuc	mov		r12,#16
679*0a6a1f1dSLionel Sambuc	moveq	r12,#0
680*0a6a1f1dSLionel Sambuc
681*0a6a1f1dSLionel Sambuc.Lctr32_tail:
682*0a6a1f1dSLionel Sambuc	.inst	0xf3b00320	@ aese q0,q8
683*0a6a1f1dSLionel Sambuc	.inst	0xf3b02320	@ aese q1,q8
684*0a6a1f1dSLionel Sambuc	vld1.32		{q8},[r7]!
685*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
686*0a6a1f1dSLionel Sambuc	.inst	0xf3b02382	@ aesmc q1,q1
687*0a6a1f1dSLionel Sambuc	subs		r6,r6,#2
688*0a6a1f1dSLionel Sambuc	.inst	0xf3b00322	@ aese q0,q9
689*0a6a1f1dSLionel Sambuc	.inst	0xf3b02322	@ aese q1,q9
690*0a6a1f1dSLionel Sambuc	vld1.32		{q9},[r7]!
691*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
692*0a6a1f1dSLionel Sambuc	.inst	0xf3b02382	@ aesmc q1,q1
693*0a6a1f1dSLionel Sambuc	bgt		.Lctr32_tail
694*0a6a1f1dSLionel Sambuc
695*0a6a1f1dSLionel Sambuc	.inst	0xf3b00320	@ aese q0,q8
696*0a6a1f1dSLionel Sambuc	.inst	0xf3b02320	@ aese q1,q8
697*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
698*0a6a1f1dSLionel Sambuc	.inst	0xf3b02382	@ aesmc q1,q1
699*0a6a1f1dSLionel Sambuc	.inst	0xf3b00322	@ aese q0,q9
700*0a6a1f1dSLionel Sambuc	.inst	0xf3b02322	@ aese q1,q9
701*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
702*0a6a1f1dSLionel Sambuc	.inst	0xf3b02382	@ aesmc q1,q1
703*0a6a1f1dSLionel Sambuc	 vld1.8		{q2},[r0],r12
704*0a6a1f1dSLionel Sambuc	.inst	0xf3b00328	@ aese q0,q12
705*0a6a1f1dSLionel Sambuc	.inst	0xf3b02328	@ aese q1,q12
706*0a6a1f1dSLionel Sambuc	 vld1.8		{q3},[r0]
707*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
708*0a6a1f1dSLionel Sambuc	.inst	0xf3b02382	@ aesmc q1,q1
709*0a6a1f1dSLionel Sambuc	.inst	0xf3b0032a	@ aese q0,q13
710*0a6a1f1dSLionel Sambuc	.inst	0xf3b0232a	@ aese q1,q13
711*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
712*0a6a1f1dSLionel Sambuc	.inst	0xf3b02382	@ aesmc q1,q1
713*0a6a1f1dSLionel Sambuc	.inst	0xf3b0032c	@ aese q0,q14
714*0a6a1f1dSLionel Sambuc	.inst	0xf3b0232c	@ aese q1,q14
715*0a6a1f1dSLionel Sambuc	 veor		q2,q2,q7
716*0a6a1f1dSLionel Sambuc	.inst	0xf3b00380	@ aesmc q0,q0
717*0a6a1f1dSLionel Sambuc	.inst	0xf3b02382	@ aesmc q1,q1
718*0a6a1f1dSLionel Sambuc	 veor		q3,q3,q7
719*0a6a1f1dSLionel Sambuc	.inst	0xf3b0032e	@ aese q0,q15
720*0a6a1f1dSLionel Sambuc	.inst	0xf3b0232e	@ aese q1,q15
721*0a6a1f1dSLionel Sambuc
722*0a6a1f1dSLionel Sambuc	cmp		r2,#1
723*0a6a1f1dSLionel Sambuc	veor		q2,q2,q0
724*0a6a1f1dSLionel Sambuc	veor		q3,q3,q1
725*0a6a1f1dSLionel Sambuc	vst1.8		{q2},[r1]!
726*0a6a1f1dSLionel Sambuc	beq		.Lctr32_done
727*0a6a1f1dSLionel Sambuc	vst1.8		{q3},[r1]
728*0a6a1f1dSLionel Sambuc
729*0a6a1f1dSLionel Sambuc.Lctr32_done:
730*0a6a1f1dSLionel Sambuc	vldmia		sp!,{d8-d15}
731*0a6a1f1dSLionel Sambuc	ldmia		sp!,{r4-r10,pc}
732*0a6a1f1dSLionel Sambuc.size	aes_v8_ctr32_encrypt_blocks,.-aes_v8_ctr32_encrypt_blocks
733*0a6a1f1dSLionel Sambuc#endif
734