1 C arm/v6/aes-encrypt-internal.asm
4 Copyright (C) 2013 Niels Möller
6 This file is part of GNU Nettle.
8 GNU Nettle is free software: you can redistribute it and/or
9 modify it under the terms of either:
11 * the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
17 * the GNU General Public License as published by the Free
18 Software Foundation; either version 2 of the License, or (at your
19 option) any later version.
21 or both in parallel, as here.
23 GNU Nettle is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 General Public License for more details.
28 You should have received copies of the GNU General Public License and
29 the GNU Lesser General Public License along with this program. If
30 not, see http://www.gnu.org/licenses/.
35 include_src(<arm/aes.m4>)
37 C Benchmarked at at 706, 870, 963 cycles/block on cortex A9,
38 C for 128, 192 and 256 bit key sizes.
40 C Possible improvements: More efficient load and store with
41 C aligned accesses. Better scheduling.
43 define(<PARAM_ROUNDS>, <r0>)
44 define(<PARAM_KEYS>, <r1>)
46 define(<LENGTH>, <r3>)
54 define(<COUNT>, <r10>)
57 define(<X0>, <r0>) C Overlaps PARAM_ROUNDS and PARAM_KEYS
60 define(<X3>, <r14>) C lr
62 define(<FRAME_ROUNDS>>, <[sp]>)
63 define(<FRAME_KEYS>, <[sp, #+4]>)
65 define(<FRAME_DST>, <[sp, #+40]>)
66 define(<FRAME_SRC>, <[sp, #+44]>)
68 define(<SRC>, <r12>) C Overlap registers used in inner loop.
69 define(<DST>, <COUNT>)
72 C It's tempting to use eor with rotation, but that's slower.
73 C AES_ENCRYPT_ROUND(x0,x1,x2,x3,w0,w1,w2,w3,key)
74 define(<AES_ENCRYPT_ROUND>, <
76 ldr $5, [TABLE, T0, lsl #2]
78 ldr $6, [TABLE, T0, lsl #2]
80 ldr $7, [TABLE, T0, lsl #2]
82 ldr $8, [TABLE, T0, lsl #2]
85 add TABLE, TABLE, #1024
86 ldr T0, [TABLE, T0, lsl #2]
89 ldr T0, [TABLE, T0, lsl #2]
92 ldr T0, [TABLE, T0, lsl #2]
95 ldr T0, [TABLE, T0, lsl #2]
99 add TABLE, TABLE, #1024
100 ldr T0, [TABLE, T0, lsl #2]
103 ldr T0, [TABLE, T0, lsl #2]
106 ldr T0, [TABLE, T0, lsl #2]
109 ldr T0, [TABLE, T0, lsl #2]
113 add TABLE, TABLE, #1024
114 ldr T0, [TABLE, T0, lsl #2]
117 ldr T0, [TABLE, T0, lsl #2]
120 ldr T0, [TABLE, T0, lsl #2]
123 ldr T0, [TABLE, T0, lsl #2]
125 ldm $9!, {$1,$2,$3,$4}
127 sub TABLE, TABLE, #3072
134 .file "aes-encrypt-internal.asm"
136 C _aes_encrypt(unsigned rounds, const uint32_t *keys,
137 C const struct aes_table *T,
138 C size_t length, uint8_t *dst,
142 PROLOGUE(_nettle_aes_encrypt)
148 push {r0,r1, r4,r5,r6,r7,r8,r10,r11,lr}
154 add TABLE, TABLE, #AES_TABLE0
167 AES_ENCRYPT_ROUND(X0, X1, X2, X3, W0, W1, W2, W3, KEY)
172 AES_ENCRYPT_ROUND(W0, W1, W2, W3, X0, X1, X2, X3, KEY)
176 sub TABLE, TABLE, #AES_TABLE0
181 AES_FINAL_ROUND_V6(X0, X1, X2, X3, KEY, W0)
182 AES_FINAL_ROUND_V6(X1, X2, X3, X0, KEY, W1)
183 AES_FINAL_ROUND_V6(X2, X3, X0, X1, KEY, W2)
184 AES_FINAL_ROUND_V6(X3, X0, X1, X2, KEY, W3)
194 subs LENGTH, LENGTH, #16
197 add sp, sp, #8 C Drop saved r0, r1
198 pop {r4,r5,r6,r7,r8,r10,r11,pc}
202 EPILOGUE(_nettle_aes_encrypt)