1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/arch/arm64/crypto/aes-ce.S - AES cipher for ARMv8 with
6 * Copyright (C) 2013 - 2017 Linaro Ltd <ard.biesheuvel@linaro.org>
9 #include <linux/linkage.h>
10 #include <asm/assembler.h>
12 #define AES_FUNC_START(func) SYM_FUNC_START(ce_ ## func)
13 #define AES_FUNC_END(func) SYM_FUNC_END(ce_ ## func)
21 .macro xts_reload_mask, tmp
24 .macro xts_cts_skip_tw, reg, lbl
27 /* preload all round keys */
28 .macro load_round_keys, rounds, rk
30 blo 2222f /* 128 bits */
31 beq 1111f /* 192 bits */
32 ld1 {v17.4s-v18.4s}, [\rk], #32
33 1111: ld1 {v19.4s-v20.4s}, [\rk], #32
34 2222: ld1 {v21.4s-v24.4s}, [\rk], #64
35 ld1 {v25.4s-v28.4s}, [\rk], #64
36 ld1 {v29.4s-v31.4s}, [\rk]
39 /* prepare for encryption with key in rk[] */
40 .macro enc_prepare, rounds, rk, temp
42 load_round_keys \rounds, \temp
45 /* prepare for encryption (again) but with new key in rk[] */
46 .macro enc_switch_key, rounds, rk, temp
48 load_round_keys \rounds, \temp
51 /* prepare for decryption with key in rk[] */
52 .macro dec_prepare, rounds, rk, temp
54 load_round_keys \rounds, \temp
57 .macro do_enc_Nx, de, mc, k, i0, i1, i2, i3, i4
58 aes\de \i0\().16b, \k\().16b
59 aes\mc \i0\().16b, \i0\().16b
61 aes\de \i1\().16b, \k\().16b
62 aes\mc \i1\().16b, \i1\().16b
64 aes\de \i2\().16b, \k\().16b
65 aes\mc \i2\().16b, \i2\().16b
66 aes\de \i3\().16b, \k\().16b
67 aes\mc \i3\().16b, \i3\().16b
69 aes\de \i4\().16b, \k\().16b
70 aes\mc \i4\().16b, \i4\().16b
76 /* up to 5 interleaved encryption rounds with the same round key */
77 .macro round_Nx, enc, k, i0, i1, i2, i3, i4
79 do_enc_Nx e, mc, \k, \i0, \i1, \i2, \i3, \i4
81 do_enc_Nx d, imc, \k, \i0, \i1, \i2, \i3, \i4
85 /* up to 5 interleaved final rounds */
86 .macro fin_round_Nx, de, k, k2, i0, i1, i2, i3, i4
87 aes\de \i0\().16b, \k\().16b
89 aes\de \i1\().16b, \k\().16b
91 aes\de \i2\().16b, \k\().16b
92 aes\de \i3\().16b, \k\().16b
94 aes\de \i4\().16b, \k\().16b
98 eor \i0\().16b, \i0\().16b, \k2\().16b
100 eor \i1\().16b, \i1\().16b, \k2\().16b
102 eor \i2\().16b, \i2\().16b, \k2\().16b
103 eor \i3\().16b, \i3\().16b, \k2\().16b
105 eor \i4\().16b, \i4\().16b, \k2\().16b
111 /* up to 5 interleaved blocks */
112 .macro do_block_Nx, enc, rounds, i0, i1, i2, i3, i4
114 blo 2222f /* 128 bits */
115 beq 1111f /* 192 bits */
116 round_Nx \enc, v17, \i0, \i1, \i2, \i3, \i4
117 round_Nx \enc, v18, \i0, \i1, \i2, \i3, \i4
118 1111: round_Nx \enc, v19, \i0, \i1, \i2, \i3, \i4
119 round_Nx \enc, v20, \i0, \i1, \i2, \i3, \i4
120 2222: .irp key, v21, v22, v23, v24, v25, v26, v27, v28, v29
121 round_Nx \enc, \key, \i0, \i1, \i2, \i3, \i4
123 fin_round_Nx \enc, v30, v31, \i0, \i1, \i2, \i3, \i4
126 .macro encrypt_block, in, rounds, t0, t1, t2
127 do_block_Nx e, \rounds, \in
130 .macro encrypt_block4x, i0, i1, i2, i3, rounds, t0, t1, t2
131 do_block_Nx e, \rounds, \i0, \i1, \i2, \i3
134 .macro encrypt_block5x, i0, i1, i2, i3, i4, rounds, t0, t1, t2
135 do_block_Nx e, \rounds, \i0, \i1, \i2, \i3, \i4
138 .macro decrypt_block, in, rounds, t0, t1, t2
139 do_block_Nx d, \rounds, \in
142 .macro decrypt_block4x, i0, i1, i2, i3, rounds, t0, t1, t2
143 do_block_Nx d, \rounds, \i0, \i1, \i2, \i3
146 .macro decrypt_block5x, i0, i1, i2, i3, i4, rounds, t0, t1, t2
147 do_block_Nx d, \rounds, \i0, \i1, \i2, \i3, \i4
152 #include "aes-modes.S"