Debian Codegraph @

cipher/chacha20-aarch64.S

raw
1 /* chacha20-aarch64.S - ARMv8/AArch64 accelerated chacha20 blocks function
2 *
3 * Copyright (C) 2017-2019 Jussi Kivilinna <[email protected]>
4 *
5 * This file is part of Libgcrypt.
6 *
7 * Libgcrypt is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * Libgcrypt is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21 /*
22 * Based on D. J. Bernstein reference implementation at
23 * http://cr.yp.to/chacha.html:
24 *
25 * chacha-regs.c version 20080118
26 * D. J. Bernstein
27 * Public domain.
28 */
29
30 #include "asm-common-aarch64.h"
31
32 #if defined(__AARCH64EL__) && \
33 defined(HAVE_COMPATIBLE_GCC_AARCH64_PLATFORM_AS) && \
34 defined(HAVE_GCC_INLINE_ASM_AARCH64_NEON) && \
35 defined(USE_CHACHA20)
36
37 .cpu generic+simd
38
39 #include "asm-poly1305-aarch64.h"
40
41 /* register macros */
42 #define INPUT x0
43 #define DST x1
44 #define SRC x2
45 #define NBLKS x3
46 #define ROUND x4
47 #define INPUT_CTR x5
48 #define INPUT_POS x6
49 #define CTR x7
50
51 /* vector registers */
52 #define X0 v16
53 #define X1 v17
54 #define X2 v18
55 #define X3 v19
56 #define X4 v20
57 #define X5 v21
58 #define X6 v22
59 #define X7 v23
60 #define X8 v24
61 #define X9 v25
62 #define X10 v26
63 #define X11 v27
64 #define X12 v28
65 #define X13 v29
66 #define X14 v30
67 #define X15 v31
68
69 #define VCTR v0
70 #define VTMP0 v1
71 #define VTMP1 v2
72 #define VTMP2 v3
73 #define VTMP3 v4
74 #define X12_TMP v5
75 #define X13_TMP v6
76 #define ROT8 v7
77
78 /**********************************************************************
79 helper macros
80 **********************************************************************/
81
82 #define _(...) __VA_ARGS__
83
84 #define vpunpckldq(s1, s2, dst) \
85 zip1 dst.4s, s2.4s, s1.4s;
86
87 #define vpunpckhdq(s1, s2, dst) \
88 zip2 dst.4s, s2.4s, s1.4s;
89
90 #define vpunpcklqdq(s1, s2, dst) \
91 zip1 dst.2d, s2.2d, s1.2d;
92
93 #define vpunpckhqdq(s1, s2, dst) \
94 zip2 dst.2d, s2.2d, s1.2d;
95
96 /* 4x4 32-bit integer matrix transpose */
97 #define transpose_4x4(x0, x1, x2, x3, t1, t2, t3) \
98 vpunpckhdq(x1, x0, t2); \
99 vpunpckldq(x1, x0, x0); \
100 \
101 vpunpckldq(x3, x2, t1); \
102 vpunpckhdq(x3, x2, x2); \
103 \
104 vpunpckhqdq(t1, x0, x1); \
105 vpunpcklqdq(t1, x0, x0); \
106 \
107 vpunpckhqdq(x2, t2, x3); \
108 vpunpcklqdq(x2, t2, x2);
109
110 #define clear(x) \
111 movi x.16b, #0;
112
113 /**********************************************************************
114 4-way chacha20
115 **********************************************************************/
116
117 #define XOR(d,s1,s2) \
118 eor d.16b, s2.16b, s1.16b;
119
120 #define PLUS(ds,s) \
121 add ds.4s, ds.4s, s.4s;
122
123 #define ROTATE4(dst1,dst2,dst3,dst4,c,src1,src2,src3,src4,iop1,iop2,iop3) \
124 shl dst1.4s, src1.4s, #(c); \
125 shl dst2.4s, src2.4s, #(c); \
126 iop1; \
127 shl dst3.4s, src3.4s, #(c); \
128 shl dst4.4s, src4.4s, #(c); \
129 iop2; \
130 sri dst1.4s, src1.4s, #(32 - (c)); \
131 sri dst2.4s, src2.4s, #(32 - (c)); \
132 iop3; \
133 sri dst3.4s, src3.4s, #(32 - (c)); \
134 sri dst4.4s, src4.4s, #(32 - (c));
135
136 #define ROTATE4_8(dst1,dst2,dst3,dst4,src1,src2,src3,src4,iop1,iop2,iop3) \
137 tbl dst1.16b, {src1.16b}, ROT8.16b; \
138 iop1; \
139 tbl dst2.16b, {src2.16b}, ROT8.16b; \
140 iop2; \
141 tbl dst3.16b, {src3.16b}, ROT8.16b; \
142 iop3; \
143 tbl dst4.16b, {src4.16b}, ROT8.16b;
144
145 #define ROTATE4_16(dst1,dst2,dst3,dst4,src1,src2,src3,src4,iop1) \
146 rev32 dst1.8h, src1.8h; \
147 rev32 dst2.8h, src2.8h; \
148 iop1; \
149 rev32 dst3.8h, src3.8h; \
150 rev32 dst4.8h, src4.8h;
151
152 #define QUARTERROUND4(a1,b1,c1,d1,a2,b2,c2,d2,a3,b3,c3,d3,a4,b4,c4,d4,ign,tmp1,tmp2,tmp3,tmp4,\
153 iop1,iop2,iop3,iop4,iop5,iop6,iop7,iop8,iop9,iop10,iop11,iop12,iop13,iop14,\
154 iop15,iop16,iop17,iop18,iop19,iop20,iop21,iop22,iop23,iop24,iop25,iop26,\
155 iop27,iop28,iop29) \
156 PLUS(a1,b1); PLUS(a2,b2); iop1; \
157 PLUS(a3,b3); PLUS(a4,b4); iop2; \
158 XOR(tmp1,d1,a1); XOR(tmp2,d2,a2); iop3; \
159 XOR(tmp3,d3,a3); XOR(tmp4,d4,a4); iop4; \
160 ROTATE4_16(d1, d2, d3, d4, tmp1, tmp2, tmp3, tmp4, _(iop5)); \
161 iop6; \
162 PLUS(c1,d1); PLUS(c2,d2); iop7; \
163 PLUS(c3,d3); PLUS(c4,d4); iop8; \
164 XOR(tmp1,b1,c1); XOR(tmp2,b2,c2); iop9; \
165 XOR(tmp3,b3,c3); XOR(tmp4,b4,c4); iop10; \
166 ROTATE4(b1, b2, b3, b4, 12, tmp1, tmp2, tmp3, tmp4, \
167 _(iop11), _(iop12), _(iop13)); iop14; \
168 PLUS(a1,b1); PLUS(a2,b2); iop15; \
169 PLUS(a3,b3); PLUS(a4,b4); iop16; \
170 XOR(tmp1,d1,a1); XOR(tmp2,d2,a2); iop17; \
171 XOR(tmp3,d3,a3); XOR(tmp4,d4,a4); iop18; \
172 ROTATE4_8(d1, d2, d3, d4, tmp1, tmp2, tmp3, tmp4, \
173 _(iop19), _(iop20), _(iop21)); iop22; \
174 PLUS(c1,d1); PLUS(c2,d2); iop23; \
175 PLUS(c3,d3); PLUS(c4,d4); iop24; \
176 XOR(tmp1,b1,c1); XOR(tmp2,b2,c2); iop25; \
177 XOR(tmp3,b3,c3); XOR(tmp4,b4,c4); iop26; \
178 ROTATE4(b1, b2, b3, b4, 7, tmp1, tmp2, tmp3, tmp4, \
179 _(iop27), _(iop28), _(iop29));
180
181 SECTION_RODATA
182
183 .align 4
184 ELF(.type _gcry_chacha20_aarch64_blocks4_data_inc_counter,%object;)
185 _gcry_chacha20_aarch64_blocks4_data_inc_counter:
186 .long 0,1,2,3
187
188 .align 4
189 ELF(.type _gcry_chacha20_aarch64_blocks4_data_rot8,%object;)
190 _gcry_chacha20_aarch64_blocks4_data_rot8:
191 .byte 3,0,1,2
192 .byte 7,4,5,6
193 .byte 11,8,9,10
194 .byte 15,12,13,14
195
196 .text
197
198 .align 4
199 .globl _gcry_chacha20_aarch64_blocks4
200 ELF(.type _gcry_chacha20_aarch64_blocks4,%function;)
201
202 _gcry_chacha20_aarch64_blocks4:
203 /* input:
204 * x0: input
205 * x1: dst
206 * x2: src
207 * x3: nblks (multiple of 4)
208 */
209 CFI_STARTPROC()
210
211 GET_DATA_POINTER(CTR, _gcry_chacha20_aarch64_blocks4_data_rot8);
212 add INPUT_CTR, INPUT, #(12*4);
213 ld1 {ROT8.16b}, [CTR];
214 GET_DATA_POINTER(CTR, _gcry_chacha20_aarch64_blocks4_data_inc_counter);
215 mov INPUT_POS, INPUT;
216 ld1 {VCTR.16b}, [CTR];
217
218 .Loop4:
219 /* Construct counter vectors X12 and X13 */
220
221 ld1 {X15.16b}, [INPUT_CTR];
222 mov ROUND, #20;
223 ld1 {VTMP1.16b-VTMP3.16b}, [INPUT_POS];
224
225 dup X12.4s, X15.s[0];
226 dup X13.4s, X15.s[1];
227 ldr CTR, [INPUT_CTR];
228 add X12.4s, X12.4s, VCTR.4s;
229 dup X0.4s, VTMP1.s[0];
230 dup X1.4s, VTMP1.s[1];
231 dup X2.4s, VTMP1.s[2];
232 dup X3.4s, VTMP1.s[3];
233 dup X14.4s, X15.s[2];
234 cmhi VTMP0.4s, VCTR.4s, X12.4s;
235 dup X15.4s, X15.s[3];
236 add CTR, CTR, #4; /* Update counter */
237 dup X4.4s, VTMP2.s[0];
238 dup X5.4s, VTMP2.s[1];
239 dup X6.4s, VTMP2.s[2];
240 dup X7.4s, VTMP2.s[3];
241 sub X13.4s, X13.4s, VTMP0.4s;
242 dup X8.4s, VTMP3.s[0];
243 dup X9.4s, VTMP3.s[1];
244 dup X10.4s, VTMP3.s[2];
245 dup X11.4s, VTMP3.s[3];
246 mov X12_TMP.16b, X12.16b;
247 mov X13_TMP.16b, X13.16b;
248 str CTR, [INPUT_CTR];
249
250 .Lround2:
251 subs ROUND, ROUND, #2
252 QUARTERROUND4(X0, X4, X8, X12, X1, X5, X9, X13,
253 X2, X6, X10, X14, X3, X7, X11, X15,
254 tmp:=,VTMP0,VTMP1,VTMP2,VTMP3,
255 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,)
256 QUARTERROUND4(X0, X5, X10, X15, X1, X6, X11, X12,
257 X2, X7, X8, X13, X3, X4, X9, X14,
258 tmp:=,VTMP0,VTMP1,VTMP2,VTMP3,
259 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,)
260 b.ne .Lround2;
261
262 ld1 {VTMP0.16b, VTMP1.16b}, [INPUT_POS], #32;
263
264 PLUS(X12, X12_TMP); /* INPUT + 12 * 4 + counter */
265 PLUS(X13, X13_TMP); /* INPUT + 13 * 4 + counter */
266
267 dup VTMP2.4s, VTMP0.s[0]; /* INPUT + 0 * 4 */
268 dup VTMP3.4s, VTMP0.s[1]; /* INPUT + 1 * 4 */
269 dup X12_TMP.4s, VTMP0.s[2]; /* INPUT + 2 * 4 */
270 dup X13_TMP.4s, VTMP0.s[3]; /* INPUT + 3 * 4 */
271 PLUS(X0, VTMP2);
272 PLUS(X1, VTMP3);
273 PLUS(X2, X12_TMP);
274 PLUS(X3, X13_TMP);
275
276 dup VTMP2.4s, VTMP1.s[0]; /* INPUT + 4 * 4 */
277 dup VTMP3.4s, VTMP1.s[1]; /* INPUT + 5 * 4 */
278 dup X12_TMP.4s, VTMP1.s[2]; /* INPUT + 6 * 4 */
279 dup X13_TMP.4s, VTMP1.s[3]; /* INPUT + 7 * 4 */
280 ld1 {VTMP0.16b, VTMP1.16b}, [INPUT_POS];
281 mov INPUT_POS, INPUT;
282 PLUS(X4, VTMP2);
283 PLUS(X5, VTMP3);
284 PLUS(X6, X12_TMP);
285 PLUS(X7, X13_TMP);
286
287 dup VTMP2.4s, VTMP0.s[0]; /* INPUT + 8 * 4 */
288 dup VTMP3.4s, VTMP0.s[1]; /* INPUT + 9 * 4 */
289 dup X12_TMP.4s, VTMP0.s[2]; /* INPUT + 10 * 4 */
290 dup X13_TMP.4s, VTMP0.s[3]; /* INPUT + 11 * 4 */
291 dup VTMP0.4s, VTMP1.s[2]; /* INPUT + 14 * 4 */
292 dup VTMP1.4s, VTMP1.s[3]; /* INPUT + 15 * 4 */
293 PLUS(X8, VTMP2);
294 PLUS(X9, VTMP3);
295 PLUS(X10, X12_TMP);
296 PLUS(X11, X13_TMP);
297 PLUS(X14, VTMP0);
298 PLUS(X15, VTMP1);
299
300 transpose_4x4(X0, X1, X2, X3, VTMP0, VTMP1, VTMP2);
301 transpose_4x4(X4, X5, X6, X7, VTMP0, VTMP1, VTMP2);
302 transpose_4x4(X8, X9, X10, X11, VTMP0, VTMP1, VTMP2);
303 transpose_4x4(X12, X13, X14, X15, VTMP0, VTMP1, VTMP2);
304
305 subs NBLKS, NBLKS, #4;
306
307 ld1 {VTMP0.16b-VTMP3.16b}, [SRC], #64;
308 ld1 {X12_TMP.16b-X13_TMP.16b}, [SRC], #32;
309 eor VTMP0.16b, X0.16b, VTMP0.16b;
310 eor VTMP1.16b, X4.16b, VTMP1.16b;
311 eor VTMP2.16b, X8.16b, VTMP2.16b;
312 eor VTMP3.16b, X12.16b, VTMP3.16b;
313 eor X12_TMP.16b, X1.16b, X12_TMP.16b;
314 eor X13_TMP.16b, X5.16b, X13_TMP.16b;
315 st1 {VTMP0.16b-VTMP3.16b}, [DST], #64;
316 ld1 {VTMP0.16b-VTMP3.16b}, [SRC], #64;
317 st1 {X12_TMP.16b-X13_TMP.16b}, [DST], #32;
318 ld1 {X12_TMP.16b-X13_TMP.16b}, [SRC], #32;
319 eor VTMP0.16b, X9.16b, VTMP0.16b;
320 eor VTMP1.16b, X13.16b, VTMP1.16b;
321 eor VTMP2.16b, X2.16b, VTMP2.16b;
322 eor VTMP3.16b, X6.16b, VTMP3.16b;
323 eor X12_TMP.16b, X10.16b, X12_TMP.16b;
324 eor X13_TMP.16b, X14.16b, X13_TMP.16b;
325 st1 {VTMP0.16b-VTMP3.16b}, [DST], #64;
326 ld1 {VTMP0.16b-VTMP3.16b}, [SRC], #64;
327 st1 {X12_TMP.16b-X13_TMP.16b}, [DST], #32;
328 eor VTMP0.16b, X3.16b, VTMP0.16b;
329 eor VTMP1.16b, X7.16b, VTMP1.16b;
330 eor VTMP2.16b, X11.16b, VTMP2.16b;
331 eor VTMP3.16b, X15.16b, VTMP3.16b;
332 st1 {VTMP0.16b-VTMP3.16b}, [DST], #64;
333
334 b.ne .Loop4;
335
336 /* clear the used vector registers and stack */
337 clear(VTMP0);
338 clear(VTMP1);
339 clear(VTMP2);
340 clear(VTMP3);
341 clear(X12_TMP);
342 clear(X13_TMP);
343 clear(X0);
344 clear(X1);
345 clear(X2);
346 clear(X3);
347 clear(X4);
348 clear(X5);
349 clear(X6);
350 clear(X7);
351 clear(X8);
352 clear(X9);
353 clear(X10);
354 clear(X11);
355 clear(X12);
356 clear(X13);
357 clear(X14);
358 clear(X15);
359
360 eor x0, x0, x0
361 ret_spec_stop
362 CFI_ENDPROC()
363 ELF(.size _gcry_chacha20_aarch64_blocks4, .-_gcry_chacha20_aarch64_blocks4;)
364
365 /**********************************************************************
366 4-way stitched chacha20-poly1305
367 **********************************************************************/
368
369 .align 4
370 .globl _gcry_chacha20_poly1305_aarch64_blocks4
371 ELF(.type _gcry_chacha20_poly1305_aarch64_blocks4,%function;)
372
373 _gcry_chacha20_poly1305_aarch64_blocks4:
374 /* input:
375 * x0: input
376 * x1: dst
377 * x2: src
378 * x3: nblks (multiple of 4)
379 * x4: poly1305-state
380 * x5: poly1305-src
381 */
382 CFI_STARTPROC()
383 POLY1305_PUSH_REGS()
384
385 mov POLY_RSTATE, x4;
386 mov POLY_RSRC, x5;
387
388 GET_DATA_POINTER(CTR, _gcry_chacha20_aarch64_blocks4_data_rot8);
389 add INPUT_CTR, INPUT, #(12*4);
390 ld1 {ROT8.16b}, [CTR];
391 GET_DATA_POINTER(CTR, _gcry_chacha20_aarch64_blocks4_data_inc_counter);
392 mov INPUT_POS, INPUT;
393 ld1 {VCTR.16b}, [CTR];
394
395 POLY1305_LOAD_STATE()
396
397 .Loop_poly4:
398 /* Construct counter vectors X12 and X13 */
399
400 ld1 {X15.16b}, [INPUT_CTR];
401 ld1 {VTMP1.16b-VTMP3.16b}, [INPUT_POS];
402
403 dup X12.4s, X15.s[0];
404 dup X13.4s, X15.s[1];
405 ldr CTR, [INPUT_CTR];
406 add X12.4s, X12.4s, VCTR.4s;
407 dup X0.4s, VTMP1.s[0];
408 dup X1.4s, VTMP1.s[1];
409 dup X2.4s, VTMP1.s[2];
410 dup X3.4s, VTMP1.s[3];
411 dup X14.4s, X15.s[2];
412 cmhi VTMP0.4s, VCTR.4s, X12.4s;
413 dup X15.4s, X15.s[3];
414 add CTR, CTR, #4; /* Update counter */
415 dup X4.4s, VTMP2.s[0];
416 dup X5.4s, VTMP2.s[1];
417 dup X6.4s, VTMP2.s[2];
418 dup X7.4s, VTMP2.s[3];
419 sub X13.4s, X13.4s, VTMP0.4s;
420 dup X8.4s, VTMP3.s[0];
421 dup X9.4s, VTMP3.s[1];
422 dup X10.4s, VTMP3.s[2];
423 dup X11.4s, VTMP3.s[3];
424 mov X12_TMP.16b, X12.16b;
425 mov X13_TMP.16b, X13.16b;
426 str CTR, [INPUT_CTR];
427
428 mov ROUND, #20
429 .Lround4_with_poly1305_outer:
430 mov POLY_CHACHA_ROUND, #6;
431 .Lround4_with_poly1305_inner1:
432 POLY1305_BLOCK_PART1(0 * 16)
433 QUARTERROUND4(X0, X4, X8, X12, X1, X5, X9, X13,
434 X2, X6, X10, X14, X3, X7, X11, X15,
435 tmp:=,VTMP0,VTMP1,VTMP2,VTMP3,
436 POLY1305_BLOCK_PART2(0 * 16),
437 POLY1305_BLOCK_PART3(),
438 POLY1305_BLOCK_PART4(),
439 POLY1305_BLOCK_PART5(),
440 POLY1305_BLOCK_PART6(),
441 POLY1305_BLOCK_PART7(),
442 POLY1305_BLOCK_PART8(),
443 POLY1305_BLOCK_PART9(),
444 POLY1305_BLOCK_PART10(),
445 POLY1305_BLOCK_PART11(),
446 POLY1305_BLOCK_PART12(),
447 POLY1305_BLOCK_PART13(),
448 POLY1305_BLOCK_PART14(),
449 POLY1305_BLOCK_PART15(),
450 POLY1305_BLOCK_PART16(),
451 POLY1305_BLOCK_PART17(),
452 POLY1305_BLOCK_PART18(),
453 POLY1305_BLOCK_PART19(),
454 POLY1305_BLOCK_PART20(),
455 POLY1305_BLOCK_PART21(),
456 POLY1305_BLOCK_PART22(),
457 POLY1305_BLOCK_PART23(),
458 POLY1305_BLOCK_PART24(),
459 POLY1305_BLOCK_PART25(),
460 POLY1305_BLOCK_PART26(),
461 POLY1305_BLOCK_PART27(),
462 POLY1305_BLOCK_PART28(),
463 POLY1305_BLOCK_PART29(),
464 POLY1305_BLOCK_PART1(1 * 16))
465 POLY1305_BLOCK_PART2(1 * 16)
466 QUARTERROUND4(X0, X5, X10, X15, X1, X6, X11, X12,
467 X2, X7, X8, X13, X3, X4, X9, X14,
468 tmp:=,VTMP0,VTMP1,VTMP2,VTMP3,
469 _(add POLY_RSRC, POLY_RSRC, #(2*16)),
470 POLY1305_BLOCK_PART3(),
471 POLY1305_BLOCK_PART4(),
472 POLY1305_BLOCK_PART5(),
473 POLY1305_BLOCK_PART6(),
474 POLY1305_BLOCK_PART7(),
475 POLY1305_BLOCK_PART8(),
476 POLY1305_BLOCK_PART9(),
477 POLY1305_BLOCK_PART10(),
478 POLY1305_BLOCK_PART11(),
479 POLY1305_BLOCK_PART12(),
480 POLY1305_BLOCK_PART13(),
481 POLY1305_BLOCK_PART14(),
482 POLY1305_BLOCK_PART15(),
483 POLY1305_BLOCK_PART16(),
484 POLY1305_BLOCK_PART17(),
485 POLY1305_BLOCK_PART18(),
486 POLY1305_BLOCK_PART19(),
487 POLY1305_BLOCK_PART20(),
488 POLY1305_BLOCK_PART21(),
489 POLY1305_BLOCK_PART22(),
490 POLY1305_BLOCK_PART23(),
491 POLY1305_BLOCK_PART24(),
492 POLY1305_BLOCK_PART25(),
493 POLY1305_BLOCK_PART26(),
494 POLY1305_BLOCK_PART27(),
495 POLY1305_BLOCK_PART28(),
496 POLY1305_BLOCK_PART29(),
497 _(subs POLY_CHACHA_ROUND, POLY_CHACHA_ROUND, #2));
498 b.ne .Lround4_with_poly1305_inner1;
499
500 mov POLY_CHACHA_ROUND, #4;
501 .Lround4_with_poly1305_inner2:
502 POLY1305_BLOCK_PART1(0 * 16)
503 QUARTERROUND4(X0, X4, X8, X12, X1, X5, X9, X13,
504 X2, X6, X10, X14, X3, X7, X11, X15,
505 tmp:=,VTMP0,VTMP1,VTMP2,VTMP3,,
506 POLY1305_BLOCK_PART2(0 * 16),,
507 _(add POLY_RSRC, POLY_RSRC, #(1*16)),,
508 POLY1305_BLOCK_PART3(),,
509 POLY1305_BLOCK_PART4(),,
510 POLY1305_BLOCK_PART5(),,
511 POLY1305_BLOCK_PART6(),,
512 POLY1305_BLOCK_PART7(),,
513 POLY1305_BLOCK_PART8(),,
514 POLY1305_BLOCK_PART9(),,
515 POLY1305_BLOCK_PART10(),,
516 POLY1305_BLOCK_PART11(),,
517 POLY1305_BLOCK_PART12(),,
518 POLY1305_BLOCK_PART13(),,
519 POLY1305_BLOCK_PART14(),)
520 POLY1305_BLOCK_PART15()
521 QUARTERROUND4(X0, X5, X10, X15, X1, X6, X11, X12,
522 X2, X7, X8, X13, X3, X4, X9, X14,
523 tmp:=,VTMP0,VTMP1,VTMP2,VTMP3,
524 POLY1305_BLOCK_PART16(),,
525 POLY1305_BLOCK_PART17(),,
526 POLY1305_BLOCK_PART18(),,
527 POLY1305_BLOCK_PART19(),,
528 POLY1305_BLOCK_PART20(),,
529 POLY1305_BLOCK_PART21(),,
530 POLY1305_BLOCK_PART22(),,
531 POLY1305_BLOCK_PART23(),,
532 POLY1305_BLOCK_PART24(),,
533 POLY1305_BLOCK_PART25(),,
534 POLY1305_BLOCK_PART26(),,
535 POLY1305_BLOCK_PART27(),,
536 POLY1305_BLOCK_PART28(),,
537 POLY1305_BLOCK_PART29(),
538 _(subs POLY_CHACHA_ROUND, POLY_CHACHA_ROUND, #2),)
539 b.ne .Lround4_with_poly1305_inner2;
540
541 subs ROUND, ROUND, #10
542 b.ne .Lround4_with_poly1305_outer;
543
544 ld1 {VTMP0.16b, VTMP1.16b}, [INPUT_POS], #32;
545
546 PLUS(X12, X12_TMP); /* INPUT + 12 * 4 + counter */
547 PLUS(X13, X13_TMP); /* INPUT + 13 * 4 + counter */
548
549 dup VTMP2.4s, VTMP0.s[0]; /* INPUT + 0 * 4 */
550 dup VTMP3.4s, VTMP0.s[1]; /* INPUT + 1 * 4 */
551 dup X12_TMP.4s, VTMP0.s[2]; /* INPUT + 2 * 4 */
552 dup X13_TMP.4s, VTMP0.s[3]; /* INPUT + 3 * 4 */
553 PLUS(X0, VTMP2);
554 PLUS(X1, VTMP3);
555 PLUS(X2, X12_TMP);
556 PLUS(X3, X13_TMP);
557
558 dup VTMP2.4s, VTMP1.s[0]; /* INPUT + 4 * 4 */
559 dup VTMP3.4s, VTMP1.s[1]; /* INPUT + 5 * 4 */
560 dup X12_TMP.4s, VTMP1.s[2]; /* INPUT + 6 * 4 */
561 dup X13_TMP.4s, VTMP1.s[3]; /* INPUT + 7 * 4 */
562 ld1 {VTMP0.16b, VTMP1.16b}, [INPUT_POS];
563 mov INPUT_POS, INPUT;
564 PLUS(X4, VTMP2);
565 PLUS(X5, VTMP3);
566 PLUS(X6, X12_TMP);
567 PLUS(X7, X13_TMP);
568
569 dup VTMP2.4s, VTMP0.s[0]; /* INPUT + 8 * 4 */
570 dup VTMP3.4s, VTMP0.s[1]; /* INPUT + 9 * 4 */
571 dup X12_TMP.4s, VTMP0.s[2]; /* INPUT + 10 * 4 */
572 dup X13_TMP.4s, VTMP0.s[3]; /* INPUT + 11 * 4 */
573 dup VTMP0.4s, VTMP1.s[2]; /* INPUT + 14 * 4 */
574 dup VTMP1.4s, VTMP1.s[3]; /* INPUT + 15 * 4 */
575 PLUS(X8, VTMP2);
576 PLUS(X9, VTMP3);
577 PLUS(X10, X12_TMP);
578 PLUS(X11, X13_TMP);
579 PLUS(X14, VTMP0);
580 PLUS(X15, VTMP1);
581
582 transpose_4x4(X0, X1, X2, X3, VTMP0, VTMP1, VTMP2);
583 transpose_4x4(X4, X5, X6, X7, VTMP0, VTMP1, VTMP2);
584 transpose_4x4(X8, X9, X10, X11, VTMP0, VTMP1, VTMP2);
585 transpose_4x4(X12, X13, X14, X15, VTMP0, VTMP1, VTMP2);
586
587 subs NBLKS, NBLKS, #4;
588
589 ld1 {VTMP0.16b-VTMP3.16b}, [SRC], #64;
590 ld1 {X12_TMP.16b-X13_TMP.16b}, [SRC], #32;
591 eor VTMP0.16b, X0.16b, VTMP0.16b;
592 eor VTMP1.16b, X4.16b, VTMP1.16b;
593 eor VTMP2.16b, X8.16b, VTMP2.16b;
594 eor VTMP3.16b, X12.16b, VTMP3.16b;
595 eor X12_TMP.16b, X1.16b, X12_TMP.16b;
596 eor X13_TMP.16b, X5.16b, X13_TMP.16b;
597 st1 {VTMP0.16b-VTMP3.16b}, [DST], #64;
598 ld1 {VTMP0.16b-VTMP3.16b}, [SRC], #64;
599 st1 {X12_TMP.16b-X13_TMP.16b}, [DST], #32;
600 ld1 {X12_TMP.16b-X13_TMP.16b}, [SRC], #32;
601 eor VTMP0.16b, X9.16b, VTMP0.16b;
602 eor VTMP1.16b, X13.16b, VTMP1.16b;
603 eor VTMP2.16b, X2.16b, VTMP2.16b;
604 eor VTMP3.16b, X6.16b, VTMP3.16b;
605 eor X12_TMP.16b, X10.16b, X12_TMP.16b;
606 eor X13_TMP.16b, X14.16b, X13_TMP.16b;
607 st1 {VTMP0.16b-VTMP3.16b}, [DST], #64;
608 ld1 {VTMP0.16b-VTMP3.16b}, [SRC], #64;
609 st1 {X12_TMP.16b-X13_TMP.16b}, [DST], #32;
610 eor VTMP0.16b, X3.16b, VTMP0.16b;
611 eor VTMP1.16b, X7.16b, VTMP1.16b;
612 eor VTMP2.16b, X11.16b, VTMP2.16b;
613 eor VTMP3.16b, X15.16b, VTMP3.16b;
614 st1 {VTMP0.16b-VTMP3.16b}, [DST], #64;
615
616 b.ne .Loop_poly4;
617
618 POLY1305_STORE_STATE()
619
620 /* clear the used vector registers and stack */
621 clear(VTMP0);
622 clear(VTMP1);
623 clear(VTMP2);
624 clear(VTMP3);
625 clear(X12_TMP);
626 clear(X13_TMP);
627 clear(X0);
628 clear(X1);
629 clear(X2);
630 clear(X3);
631 clear(X4);
632 clear(X5);
633 clear(X6);
634 clear(X7);
635 clear(X8);
636 clear(X9);
637 clear(X10);
638 clear(X11);
639 clear(X12);
640 clear(X13);
641 clear(X14);
642 clear(X15);
643
644 eor x0, x0, x0
645 POLY1305_POP_REGS()
646 ret_spec_stop
647 CFI_ENDPROC()
648 ELF(.size _gcry_chacha20_poly1305_aarch64_blocks4, .-_gcry_chacha20_poly1305_aarch64_blocks4;)
649
650 #endif