Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / x86_64 / aes-encrypt-internal.asm
blob4ae0ec858b07851106a50f023a61e31d3987c852
1 C nettle, low-level cryptographics library
2 C
3 C Copyright (C) 2001, 2002, 2005, 2008 Rafael R. Sevilla, Niels Möller
4 C
5 C The nettle library is free software; you can redistribute it and/or modify
6 C it under the terms of the GNU Lesser General Public License as published by
7 C the Free Software Foundation; either version 2.1 of the License, or (at your
8 C option) any later version.
9 C
10 C The nettle library is distributed in the hope that it will be useful, but
11 C WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 C or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13 C License for more details.
15 C You should have received a copy of the GNU Lesser General Public License
16 C along with the nettle library; see the file COPYING.LIB. If not, write to
17 C the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 C MA 02111-1301, USA.
20 include_src(<x86_64/aes.m4>)
22 C Register usage:
24 C AES state, use two of them
25 define(<SA>,<%eax>)
26 define(<SB>,<%ebx>)
27 define(<SC>,<%ecx>)
28 define(<SD>,<%edx>)
30 define(<TA>,<%r10d>)
31 define(<TB>,<%r11d>)
32 define(<TC>,<%r12d>)
34 define(<CTX>, <%rdi>)
35 define(<TABLE>, <%rsi>)
36 define(<PARAM_LENGTH>,<%edx>) C Length is only 32 bits
37 define(<PARAM_DST>, <%rcx>)
38 define(<SRC>, <%r8>)
40 define(<DST>, <%r9>)
41 define(<KEY>,<%r14>)
42 define(<COUNT>, <%r15d>)
43 define(<BLOCK_COUNT>, <%r13d>)
45 C Must correspond to an old-style register, for movzb from %ah--%dh to
46 C work.
47 define(<TMP>,<%rbp>)
49 .file "aes-encrypt-internal.asm"
51 C _aes_encrypt(struct aes_context *ctx,
52 C const struct aes_table *T,
53 C unsigned length, uint8_t *dst,
54 C uint8_t *src)
55 .text
56 ALIGN(16)
57 PROLOGUE(_nettle_aes_encrypt)
58 W64_ENTRY(5, 0)
59 test PARAM_LENGTH, PARAM_LENGTH
60 jz .Lend
62 C save all registers that need to be saved
63 push %rbx
64 push %rbp
65 push %r12
66 push %r13
67 push %r14
68 push %r15
70 mov PARAM_DST, DST
71 movl PARAM_LENGTH, BLOCK_COUNT
72 shrl $4, BLOCK_COUNT
73 .Lblock_loop:
74 mov CTX,KEY
76 AES_LOAD(SA, SB, SC, SD, SRC, KEY)
77 add $16, SRC C Increment src pointer
79 C get number of rounds to do from ctx struct
80 movl AES_NROUNDS (CTX), COUNT
81 subl $1, COUNT
83 add $16,KEY C point to next key
84 ALIGN(16)
85 .Lround_loop:
86 AES_ROUND(TABLE, SA,SB,SC,SD, TA, TMP)
87 AES_ROUND(TABLE, SB,SC,SD,SA, TB, TMP)
88 AES_ROUND(TABLE, SC,SD,SA,SB, TC, TMP)
89 AES_ROUND(TABLE, SD,SA,SB,SC, SD, TMP)
91 movl TA, SA
92 movl TB, SB
93 movl TC, SC
95 xorl (KEY),SA C add current session key to plaintext
96 xorl 4(KEY),SB
97 xorl 8(KEY),SC
98 xorl 12(KEY),SD
100 add $16,KEY C point to next key
101 decl COUNT
102 jnz .Lround_loop
104 C last round
105 AES_FINAL_ROUND(SA,SB,SC,SD, TABLE, TA, TMP)
106 AES_FINAL_ROUND(SB,SC,SD,SA, TABLE, TB, TMP)
107 AES_FINAL_ROUND(SC,SD,SA,SB, TABLE, TC, TMP)
108 AES_FINAL_ROUND(SD,SA,SB,SC, TABLE, SD, TMP)
110 C S-box substitution
111 mov $3, COUNT
112 .Lsubst:
113 AES_SUBST_BYTE(TA,TB,TC,SD, TABLE, TMP)
115 decl COUNT
116 jnz .Lsubst
118 C Add last subkey, and store encrypted data
119 AES_STORE(TA,TB,TC,SD, KEY, DST)
121 add $16, DST
122 decl BLOCK_COUNT
124 jnz .Lblock_loop
126 pop %r15
127 pop %r14
128 pop %r13
129 pop %r12
130 pop %rbp
131 pop %rbx
132 .Lend:
133 W64_EXIT(5, 0)
135 EPILOGUE(_nettle_aes_encrypt)