1 C arm/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/.
33 include_src(<arm/aes.m4>)
35 C Benchmarked at at 725, 815, 990 cycles/block on cortex A9,
36 C for 128, 192 and 256 bit key sizes.
38 C Possible improvements: More efficient load and store with
39 C aligned accesses. Better scheduling.
41 define(<PARAM_ROUNDS>, <r0>)
42 define(<PARAM_KEYS>, <r1>)
44 define(<PARAM_LENGTH>, <r3>)
52 define(<COUNT>, <r10>)
55 define(<MASK>, <r0>) C Overlaps inputs, except TABLE
59 define(<X3>, <r14>) C lr
61 define(<FRAME_ROUNDS>, <[sp]>)
62 define(<FRAME_KEYS>, <[sp, #+4]>)
63 define(<FRAME_LENGTH>, <[sp, #+8]>)
65 define(<FRAME_DST>, <[sp, #+44]>)
66 define(<FRAME_SRC>, <[sp, #+48]>)
69 C AES_ENCRYPT_ROUND(x0,x1,x2,x3,w0,w1,w2,w3,key)
70 C MASK should hold the constant 0x3fc.
71 define(<AES_ENCRYPT_ROUND>, <
73 and T0, MASK, $1, lsl #2
75 and T0, MASK, $2, lsl #2
77 and T0, MASK, $3, lsl #2
79 and T0, MASK, $4, lsl #2
82 and T0, MASK, $2, ror #6
83 add TABLE, TABLE, #1024
86 and T0, MASK, $3, ror #6
89 and T0, MASK, $4, ror #6
92 and T0, MASK, $1, ror #6
96 and T0, MASK, $3, ror #14
97 add TABLE, TABLE, #1024
100 and T0, MASK, $4, ror #14
103 and T0, MASK, $1, ror #14
106 and T0, MASK, $2, ror #14
110 and T0, MASK, $4, ror #22
111 add TABLE, TABLE, #1024
114 and T0, MASK, $1, ror #22
117 and T0, MASK, $2, ror #22
120 and T0, MASK, $3, ror #22
123 ldm $9!, {$1,$2,$3,$4}
125 sub TABLE, TABLE, #3072
132 .file "aes-encrypt-internal.asm"
134 C _aes_encrypt(unsigned rounds, const uint32_t *keys,
135 C const struct aes_table *T,
136 C size_t length, uint8_t *dst,
140 PROLOGUE(_nettle_aes_encrypt)
144 push {r0,r1,r3, r4,r5,r6,r7,r8,r10,r11,lr}
148 ldr X0, FRAME_SRC C Use X0 as SRC pointer
158 add TABLE, TABLE, #AES_TABLE0
164 AES_ENCRYPT_ROUND(X0, X1, X2, X3, W0, W1, W2, W3, KEY)
169 AES_ENCRYPT_ROUND(W0, W1, W2, W3, X0, X1, X2, X3, KEY)
173 lsr COUNT, MASK, #2 C Put the needed mask in the unused COUNT register
174 sub TABLE, TABLE, #AES_TABLE0
176 AES_FINAL_ROUND_V5(X0, X1, X2, X3, KEY, W0, COUNT)
177 AES_FINAL_ROUND_V5(X1, X2, X3, X0, KEY, W1, COUNT)
178 AES_FINAL_ROUND_V5(X2, X3, X0, X1, KEY, W2, COUNT)
179 AES_FINAL_ROUND_V5(X3, X0, X1, X2, KEY, W3, COUNT)
195 add sp, sp, #12 C Drop saved r0, r1, r3
196 pop {r4,r5,r6,r7,r8,r10,r11,pc}
200 EPILOGUE(_nettle_aes_encrypt)