2 * Scalar AES core transform
4 * Copyright (C) 2017 Linaro Ltd.
5 * Author: Ard Biesheuvel <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>
27 .macro __select, out, in, idx
28 .if __LINUX_ARM_ARCH__ < 7
29 and \out, \in, #0xff << (8 * \idx)
31 ubfx \out, \in, #(8 * \idx), #8
35 .macro __load, out, in, idx
36 .if __LINUX_ARM_ARCH__ < 7 && \idx > 0
37 ldr \out, [ttab, \in, lsr #(8 * \idx) - 2]
39 ldr \out, [ttab, \in, lsl #2]
43 .macro __hround, out0, out1, in0, in1, in2, in3, t3, t4, enc
44 __select \out0, \in0, 0
46 __load \out0, \out0, 0
50 __select \out1, \in1, 0
53 __select \out1, \in3, 0
56 __load \out1, \out1, 0
61 eor \out0, \out0, t0, ror #24
75 eor \out1, \out1, t1, ror #24
76 eor \out0, \out0, t2, ror #16
78 eor \out1, \out1, \t3, ror #16
79 eor \out0, \out0, t0, ror #8
80 eor \out1, \out1, \t4, ror #8
85 .macro fround, out0, out1, out2, out3, in0, in1, in2, in3
86 __hround \out0, \out1, \in0, \in1, \in2, \in3, \out2, \out3, 1
87 __hround \out2, \out3, \in2, \in3, \in0, \in1, \in1, \in2, 1
90 .macro iround, out0, out1, out2, out3, in0, in1, in2, in3
91 __hround \out0, \out1, \in0, \in3, \in2, \in1, \out2, \out3, 0
92 __hround \out2, \out3, \in2, \in1, \in0, \in3, \in1, \in0, 0
96 .if __LINUX_ARM_ARCH__ < 6
99 and t2, \in, #0xff0000
100 orr \out, t0, \in, lsr #24
101 orr \out, \out, t1, lsl #8
102 orr \out, \out, t2, lsr #8
108 .macro __adrl, out, sym, c
109 .if __LINUX_ARM_ARCH__ < 7
112 movw\c \out, #:lower16:\sym
113 movt\c \out, #:upper16:\sym
117 .macro do_crypt, round, ttab, ltab
127 #ifdef CONFIG_CPU_BIG_ENDIAN
144 0: \round r8, r9, r10, r11, r4, r5, r6, r7
145 \round r4, r5, r6, r7, r8, r9, r10, r11
147 1: subs rounds, rounds, #4
148 \round r8, r9, r10, r11, r4, r5, r6, r7
149 __adrl ttab, \ltab, ls
150 \round r4, r5, r6, r7, r8, r9, r10, r11
153 #ifdef CONFIG_CPU_BIG_ENDIAN
173 ENTRY(__aes_arm_encrypt)
174 do_crypt fround, crypto_ft_tab, crypto_fl_tab
175 ENDPROC(__aes_arm_encrypt)
177 ENTRY(__aes_arm_decrypt)
178 do_crypt iround, crypto_it_tab, crypto_il_tab
179 ENDPROC(__aes_arm_decrypt)