1
2
3
4
5
6
7
8
9
10
11.extern crypto_ft_tab
12.extern crypto_it_tab
13.extern crypto_fl_tab
14.extern crypto_il_tab
15
16.text
17
18#include <linux/linkage.h>
19#include <asm/asm-offsets.h>
20
21#define R1 %rax
22#define R1E %eax
23#define R1X %ax
24#define R1H %ah
25#define R1L %al
26#define R2 %rbx
27#define R2E %ebx
28#define R2X %bx
29#define R2H %bh
30#define R2L %bl
31#define R3 %rcx
32#define R3E %ecx
33#define R3X %cx
34#define R3H %ch
35#define R3L %cl
36#define R4 %rdx
37#define R4E %edx
38#define R4X %dx
39#define R4H %dh
40#define R4L %dl
41#define R5 %rsi
42#define R5E %esi
43#define R6 %rdi
44#define R6E %edi
45#define R7 %rbp
46#define R7E %ebp
47#define R8 %r8
48#define R9 %r9
49#define R10 %r10
50#define R11 %r11
51
52#define prologue(FUNC,KEY,B128,B192,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11) \
53 ENTRY(FUNC); \
54 movq r1,r2; \
55 movq r3,r4; \
56 leaq KEY+48(r8),r9; \
57 movq r10,r11; \
58 movl (r7),r5
59 movl 4(r7),r1
60 movl 8(r7),r6
61 movl 12(r7),r7
62 movl 480(r8),r10
63 xorl -48(r9),r5
64 xorl -44(r9),r1
65 xorl -40(r9),r6
66 xorl -36(r9),r7
67 cmpl $24,r10
68 jb B128; \
69 leaq 32(r9),r9; \
70 je B192; \
71 leaq 32(r9),r9;
72
73#define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
74 movq r1,r2; \
75 movq r3,r4; \
76 movl r5
77 movl r6
78 movl r7
79 movl r8
80 ret; \
81 ENDPROC(FUNC);
82
83#define round(TAB,OFFSET,r1,r2,r3,r4,r5,r6,r7,r8,ra,rb,rc,rd) \
84 movzbl r2
85 movzbl r2
86 movl TAB+1024(,r5,4),r5
87 movw r4
88 movl TAB(,r6,4),r6
89 roll $16,r2
90 shrl $16,r4
91 movzbl r4
92 movzbl r4
93 xorl OFFSET(r8),ra
94 xorl OFFSET+4(r8),rb
95 xorl TAB+3072(,r7,4),r5
96 xorl TAB+2048(,r4,4),r6
97 movzbl r1
98 movzbl r1
99 movl TAB+1024(,r4,4),r4
100 movw r3
101 roll $16,r1
102 shrl $16,r3
103 xorl TAB(,r7,4),r5
104 movzbl r3
105 movzbl r3
106 xorl TAB+3072(,r7,4),r4
107 xorl TAB+2048(,r3,4),r5
108 movzbl r1
109 movzbl r1
110 shrl $16,r1
111 xorl TAB+3072(,r7,4),r6
112 movl TAB+2048(,r3,4),r3
113 movzbl r1
114 movzbl r1
115 xorl TAB+1024(,r7,4),r6
116 xorl TAB(,r1,4),r3
117 movzbl r2
118 movzbl r2
119 shrl $16,r2
120 xorl TAB+3072(,r1,4),r3
121 xorl TAB+2048(,r7,4),r4
122 movzbl r2
123 movzbl r2
124 xorl OFFSET+8(r8),rc
125 xorl OFFSET+12(r8),rd
126 xorl TAB+1024(,r1,4),r3
127 xorl TAB(,r2,4),r4
128
129#define move_regs(r1,r2,r3,r4) \
130 movl r3
131 movl r4
132
133#define entry(FUNC,KEY,B128,B192) \
134 prologue(FUNC,KEY,B128,B192,R2,R8,R7,R9,R1,R3,R4,R6,R10,R5,R11)
135
136#define return(FUNC) epilogue(FUNC,R8,R2,R9,R7,R5,R6,R3,R4,R11)
137
138#define encrypt_round(TAB,OFFSET) \
139 round(TAB,OFFSET,R1,R2,R3,R4,R5,R6,R7,R10,R5,R6,R3,R4) \
140 move_regs(R1,R2,R5,R6)
141
142#define encrypt_final(TAB,OFFSET) \
143 round(TAB,OFFSET,R1,R2,R3,R4,R5,R6,R7,R10,R5,R6,R3,R4)
144
145#define decrypt_round(TAB,OFFSET) \
146 round(TAB,OFFSET,R2,R1,R4,R3,R6,R5,R7,R10,R5,R6,R3,R4) \
147 move_regs(R1,R2,R5,R6)
148
149#define decrypt_final(TAB,OFFSET) \
150 round(TAB,OFFSET,R2,R1,R4,R3,R6,R5,R7,R10,R5,R6,R3,R4)
151
152
153
154 entry(aes_enc_blk,0,.Le128,.Le192)
155 encrypt_round(crypto_ft_tab,-96)
156 encrypt_round(crypto_ft_tab,-80)
157.Le192: encrypt_round(crypto_ft_tab,-64)
158 encrypt_round(crypto_ft_tab,-48)
159.Le128: encrypt_round(crypto_ft_tab,-32)
160 encrypt_round(crypto_ft_tab,-16)
161 encrypt_round(crypto_ft_tab, 0)
162 encrypt_round(crypto_ft_tab, 16)
163 encrypt_round(crypto_ft_tab, 32)
164 encrypt_round(crypto_ft_tab, 48)
165 encrypt_round(crypto_ft_tab, 64)
166 encrypt_round(crypto_ft_tab, 80)
167 encrypt_round(crypto_ft_tab, 96)
168 encrypt_final(crypto_fl_tab,112)
169 return(aes_enc_blk)
170
171
172
173 entry(aes_dec_blk,240,.Ld128,.Ld192)
174 decrypt_round(crypto_it_tab,-96)
175 decrypt_round(crypto_it_tab,-80)
176.Ld192: decrypt_round(crypto_it_tab,-64)
177 decrypt_round(crypto_it_tab,-48)
178.Ld128: decrypt_round(crypto_it_tab,-32)
179 decrypt_round(crypto_it_tab,-16)
180 decrypt_round(crypto_it_tab, 0)
181 decrypt_round(crypto_it_tab, 16)
182 decrypt_round(crypto_it_tab, 32)
183 decrypt_round(crypto_it_tab, 48)
184 decrypt_round(crypto_it_tab, 64)
185 decrypt_round(crypto_it_tab, 80)
186 decrypt_round(crypto_it_tab, 96)
187 decrypt_final(crypto_il_tab,112)
188 return(aes_dec_blk)
189