2 * linux/arch/arm64/crypto/aes-ce.S - AES cipher for ARMv8 with
5 * Copyright (C) 2013 - 2017 Linaro Ltd <ard.biesheuvel@linaro.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/linkage.h>
13 #include <asm/assembler.h>
15 #define AES_ENTRY(func) ENTRY(ce_ ## func)
16 #define AES_ENDPROC(func) ENDPROC(ce_ ## func)
20 /* preload all round keys */
21 .macro load_round_keys, rounds, rk
23 blo 2222f /* 128 bits */
24 beq 1111f /* 192 bits */
25 ld1 {v17.4s-v18.4s}, [\rk], #32
26 1111: ld1 {v19.4s-v20.4s}, [\rk], #32
27 2222: ld1 {v21.4s-v24.4s}, [\rk], #64
28 ld1 {v25.4s-v28.4s}, [\rk], #64
29 ld1 {v29.4s-v31.4s}, [\rk]
32 /* prepare for encryption with key in rk[] */
33 .macro enc_prepare, rounds, rk, temp
35 load_round_keys \rounds, \temp
38 /* prepare for encryption (again) but with new key in rk[] */
39 .macro enc_switch_key, rounds, rk, temp
41 load_round_keys \rounds, \temp
44 /* prepare for decryption with key in rk[] */
45 .macro dec_prepare, rounds, rk, temp
47 load_round_keys \rounds, \temp
50 .macro do_enc_Nx, de, mc, k, i0, i1, i2, i3
51 aes\de \i0\().16b, \k\().16b
52 aes\mc \i0\().16b, \i0\().16b
54 aes\de \i1\().16b, \k\().16b
55 aes\mc \i1\().16b, \i1\().16b
57 aes\de \i2\().16b, \k\().16b
58 aes\mc \i2\().16b, \i2\().16b
59 aes\de \i3\().16b, \k\().16b
60 aes\mc \i3\().16b, \i3\().16b
65 /* up to 4 interleaved encryption rounds with the same round key */
66 .macro round_Nx, enc, k, i0, i1, i2, i3
68 do_enc_Nx e, mc, \k, \i0, \i1, \i2, \i3
70 do_enc_Nx d, imc, \k, \i0, \i1, \i2, \i3
74 /* up to 4 interleaved final rounds */
75 .macro fin_round_Nx, de, k, k2, i0, i1, i2, i3
76 aes\de \i0\().16b, \k\().16b
78 aes\de \i1\().16b, \k\().16b
80 aes\de \i2\().16b, \k\().16b
81 aes\de \i3\().16b, \k\().16b
84 eor \i0\().16b, \i0\().16b, \k2\().16b
86 eor \i1\().16b, \i1\().16b, \k2\().16b
88 eor \i2\().16b, \i2\().16b, \k2\().16b
89 eor \i3\().16b, \i3\().16b, \k2\().16b
94 /* up to 4 interleaved blocks */
95 .macro do_block_Nx, enc, rounds, i0, i1, i2, i3
97 blo 2222f /* 128 bits */
98 beq 1111f /* 192 bits */
99 round_Nx \enc, v17, \i0, \i1, \i2, \i3
100 round_Nx \enc, v18, \i0, \i1, \i2, \i3
101 1111: round_Nx \enc, v19, \i0, \i1, \i2, \i3
102 round_Nx \enc, v20, \i0, \i1, \i2, \i3
103 2222: .irp key, v21, v22, v23, v24, v25, v26, v27, v28, v29
104 round_Nx \enc, \key, \i0, \i1, \i2, \i3
106 fin_round_Nx \enc, v30, v31, \i0, \i1, \i2, \i3
109 .macro encrypt_block, in, rounds, t0, t1, t2
110 do_block_Nx e, \rounds, \in
113 .macro encrypt_block2x, i0, i1, rounds, t0, t1, t2
114 do_block_Nx e, \rounds, \i0, \i1
117 .macro encrypt_block4x, i0, i1, i2, i3, rounds, t0, t1, t2
118 do_block_Nx e, \rounds, \i0, \i1, \i2, \i3
121 .macro decrypt_block, in, rounds, t0, t1, t2
122 do_block_Nx d, \rounds, \in
125 .macro decrypt_block2x, i0, i1, rounds, t0, t1, t2
126 do_block_Nx d, \rounds, \i0, \i1
129 .macro decrypt_block4x, i0, i1, i2, i3, rounds, t0, t1, t2
130 do_block_Nx d, \rounds, \i0, \i1, \i2, \i3
133 #include "aes-modes.S"