1 C x86_64/aes-decrypt-internal.asm
4 Copyright (C) 2001, 2002, 2005, Rafael R. Sevilla, Niels Möller
5 Copyright (C) 2008, 2013 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
18 * the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at your
20 option) any later version.
22 or both in parallel, as here.
24 GNU Nettle is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
29 You should have received copies of the GNU General Public License and
30 the GNU Lesser General Public License along with this program. If
31 not, see http://www.gnu.org/licenses/.
34 include_src(<x86_64/aes.m4>)
38 C AES state, use two of them
49 define(<ROUNDS>, <%rdi>)
50 define(<KEYS>, <%rsi>)
51 define(<PARAM_TABLE>, <%rdx>)
52 define(<PARAM_LENGTH>,<%rcx>)
56 define(<TABLE>, <%r13>)
57 define(<LENGTH>,<%r14>)
60 C Must correspond to an old-style register, for movzb from %ah--%dh to
64 .file "aes-decrypt-internal.asm"
66 C _aes_decrypt(unsigned rounds, const uint32_t *keys,
67 C const struct aes_table *T,
68 C size_t length, uint8_t *dst,
72 PROLOGUE(_nettle_aes_decrypt)
74 test PARAM_LENGTH, PARAM_LENGTH
77 C save all registers that need to be saved
86 push ROUNDS C Rounds at (%rsp)
88 mov PARAM_TABLE, TABLE
89 mov PARAM_LENGTH, LENGTH
94 AES_LOAD(SA, SB, SC, SD, SRC, KEY)
95 add $16, SRC C Increment src pointer
97 movl (%rsp), XREG(ROUNDS)
99 add $16, KEY C point to next key
102 AES_ROUND(TABLE, SA,SD,SC,SB, TA, TMP)
103 AES_ROUND(TABLE, SB,SA,SD,SC, TB, TMP)
104 AES_ROUND(TABLE, SC,SB,SA,SD, TC, TMP)
105 AES_ROUND(TABLE, SD,SC,SB,SA, SD, TMP)
111 xorl (KEY),SA C add current session key to plaintext
116 add $16, KEY C point to next key
121 AES_FINAL_ROUND(SA,SD,SC,SB, TABLE, TA, TMP)
122 AES_FINAL_ROUND(SB,SA,SD,SC, TABLE, TB, TMP)
123 AES_FINAL_ROUND(SC,SB,SA,SD, TABLE, TC, TMP)
124 AES_FINAL_ROUND(SD,SC,SB,SA, TABLE, SD, TMP)
126 C Inverse S-box substitution
129 AES_SUBST_BYTE(TA,TB,TC,SD, TABLE, TMP)
134 C Add last subkey, and store decrypted data
135 AES_STORE(TA,TB,TC,SD, KEY, DST)
142 lea 8(%rsp), %rsp C Drop ROUNDS
152 EPILOGUE(_nettle_aes_decrypt)