xref: /linux/arch/arm64/crypto/aes-ce-core.S (revision e9f0878c4b2004ac19581274c1ae4c61ae3ca70e)
1/*
2 * Copyright (C) 2013 - 2017 Linaro Ltd <ard.biesheuvel@linaro.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/linkage.h>
10#include <asm/assembler.h>
11
12	.arch		armv8-a+crypto
13
14ENTRY(__aes_ce_encrypt)
15	sub		w3, w3, #2
16	ld1		{v0.16b}, [x2]
17	ld1		{v1.4s}, [x0], #16
18	cmp		w3, #10
19	bmi		0f
20	bne		3f
21	mov		v3.16b, v1.16b
22	b		2f
230:	mov		v2.16b, v1.16b
24	ld1		{v3.4s}, [x0], #16
251:	aese		v0.16b, v2.16b
26	aesmc		v0.16b, v0.16b
272:	ld1		{v1.4s}, [x0], #16
28	aese		v0.16b, v3.16b
29	aesmc		v0.16b, v0.16b
303:	ld1		{v2.4s}, [x0], #16
31	subs		w3, w3, #3
32	aese		v0.16b, v1.16b
33	aesmc		v0.16b, v0.16b
34	ld1		{v3.4s}, [x0], #16
35	bpl		1b
36	aese		v0.16b, v2.16b
37	eor		v0.16b, v0.16b, v3.16b
38	st1		{v0.16b}, [x1]
39	ret
40ENDPROC(__aes_ce_encrypt)
41
42ENTRY(__aes_ce_decrypt)
43	sub		w3, w3, #2
44	ld1		{v0.16b}, [x2]
45	ld1		{v1.4s}, [x0], #16
46	cmp		w3, #10
47	bmi		0f
48	bne		3f
49	mov		v3.16b, v1.16b
50	b		2f
510:	mov		v2.16b, v1.16b
52	ld1		{v3.4s}, [x0], #16
531:	aesd		v0.16b, v2.16b
54	aesimc		v0.16b, v0.16b
552:	ld1		{v1.4s}, [x0], #16
56	aesd		v0.16b, v3.16b
57	aesimc		v0.16b, v0.16b
583:	ld1		{v2.4s}, [x0], #16
59	subs		w3, w3, #3
60	aesd		v0.16b, v1.16b
61	aesimc		v0.16b, v0.16b
62	ld1		{v3.4s}, [x0], #16
63	bpl		1b
64	aesd		v0.16b, v2.16b
65	eor		v0.16b, v0.16b, v3.16b
66	st1		{v0.16b}, [x1]
67	ret
68ENDPROC(__aes_ce_decrypt)
69
70/*
71 * __aes_ce_sub() - use the aese instruction to perform the AES sbox
72 *                  substitution on each byte in 'input'
73 */
74ENTRY(__aes_ce_sub)
75	dup		v1.4s, w0
76	movi		v0.16b, #0
77	aese		v0.16b, v1.16b
78	umov		w0, v0.s[0]
79	ret
80ENDPROC(__aes_ce_sub)
81
82ENTRY(__aes_ce_invert)
83	ld1		{v0.4s}, [x1]
84	aesimc		v1.16b, v0.16b
85	st1		{v1.4s}, [x0]
86	ret
87ENDPROC(__aes_ce_invert)
88