1 C x86_64/aes-encrypt-internal.asm
5 Copyright (C) 2001, 2002, 2005, Rafael R. Sevilla, Niels Möller
6 Copyright (C) 2008, 2013 Niels Möller
8 This file is part of GNU Nettle.
10 GNU Nettle is free software: you can redistribute it and/or
11 modify it under the terms of either:
13 * the GNU Lesser General Public License as published by the Free
14 Software Foundation; either version 3 of the License, or (at your
15 option) any later version.
19 * the GNU General Public License as published by the Free
20 Software Foundation; either version 2 of the License, or (at your
21 option) any later version.
23 or both in parallel, as here.
25 GNU Nettle is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 General Public License for more details.
30 You should have received copies of the GNU General Public License and
31 the GNU Lesser General Public License along with this program. If
32 not, see http://www.gnu.org/licenses/.
35 include_src(<x86_64/aes.m4>)
39 C AES state, use two of them
50 define(<ROUNDS>, <%rdi>)
51 define(<KEYS>, <%rsi>)
52 define(<PARAM_TABLE>, <%rdx>)
53 define(<PARAM_LENGTH>,<%rcx>)
57 define(<TABLE>, <%r13>)
58 define(<LENGTH>,<%r14>)
61 C Must correspond to an old-style register, for movzb from %ah--%dh to
65 .file "aes-encrypt-internal.asm"
67 C _aes_encrypt(unsigned rounds, const uint32_t *keys,
68 C const struct aes_table *T,
69 C size_t length, uint8_t *dst,
73 PROLOGUE(_nettle_aes_encrypt)
75 test PARAM_LENGTH, PARAM_LENGTH
78 C save all registers that need to be saved
87 push ROUNDS C Rounds at (%rsp)
89 mov PARAM_TABLE, TABLE
90 mov PARAM_LENGTH, LENGTH
95 AES_LOAD(SA, SB, SC, SD, SRC, KEY)
96 add $16, SRC C Increment src pointer
98 movl (%rsp), XREG(ROUNDS)
100 add $16, KEY C point to next key
103 AES_ROUND(TABLE, SA,SB,SC,SD, TA, TMP)
104 AES_ROUND(TABLE, SB,SC,SD,SA, TB, TMP)
105 AES_ROUND(TABLE, SC,SD,SA,SB, TC, TMP)
106 AES_ROUND(TABLE, SD,SA,SB,SC, SD, TMP)
112 xorl (KEY),SA C add current session key to plaintext
117 add $16, KEY C point to next key
122 AES_FINAL_ROUND(SA,SB,SC,SD, TABLE, TA, TMP)
123 AES_FINAL_ROUND(SB,SC,SD,SA, TABLE, TB, TMP)
124 AES_FINAL_ROUND(SC,SD,SA,SB, TABLE, TC, TMP)
125 AES_FINAL_ROUND(SD,SA,SB,SC, TABLE, SD, TMP)
130 AES_SUBST_BYTE(TA,TB,TC,SD, TABLE, TMP)
135 C Add last subkey, and store encrypted data
136 AES_STORE(TA,TB,TC,SD, KEY, DST)
143 lea 8(%rsp), %rsp C Drop ROUNDS
153 EPILOGUE(_nettle_aes_encrypt)