1 C nettle
, low-level cryptographics library
3 C Copyright
(C
) 2001, 2002, 2005 Rafael R. Sevilla
, Niels Möller
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.
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
,
20 include_src
(<x86
/aes.m4
>)
30 C Primary use of these registers. They
're also used temporarily for other things.
35 define(<FRAME_CTX>, <40(%esp)>)
36 define(<FRAME_TABLE>, <44(%esp)>)
37 define(<FRAME_LENGTH>, <48(%esp)>)
38 define(<FRAME_DST>, <52(%esp)>)
39 define(<FRAME_SRC>, <56(%esp)>)
41 define(<FRAME_KEY>, <16(%esp)>)
42 define(<FRAME_COUNT>, <12(%esp)>)
43 define(<TA>, <8(%esp)>)
44 define(<TB>, <4(%esp)>)
45 define(<TC>, <(%esp)>)
47 C The aes state is kept in %eax, %ebx, %ecx and %edx
49 C %esi is used as temporary, to point to the input, and to the
52 C %ebp is used as the round counter, and as a temporary in the final round.
54 C %edi is a temporary, often used as an accumulator.
56 .file "aes-encrypt-internal.asm"
58 C _aes_encrypt(struct aes_context *ctx,
59 C const struct aes_table *T,
60 C unsigned length, uint8_t *dst,
64 PROLOGUE(_nettle_aes_encrypt)
65 C save all registers that need to be saved
71 subl $20, %esp C loop counter and save area for the key pointer
73 movl FRAME_LENGTH, %ebp
80 movl FRAME_CTX,KEY C address of context struct ctx
82 movl FRAME_SRC,TMP C address of plaintext
83 AES_LOAD(SA, SB, SC, SD, TMP, KEY)
84 addl $16, FRAME_SRC C Increment src pointer
87 C get number of rounds to do from ctx struct
88 movl AES_NROUNDS (KEY),TMP
91 C Loop counter on stack
94 addl $16,KEY C point to next key
98 AES_ROUND(T, SA,SB,SC,SD, TMP, KEY)
101 AES_ROUND(T, SB,SC,SD,SA, TMP, KEY)
104 AES_ROUND(T, SC,SD,SA,SB, TMP, KEY)
107 AES_ROUND(T, SD,SA,SB,SC, SD, KEY)
115 xorl (KEY),SA C add current session key to plaintext
119 addl $16,FRAME_KEY C point to next key
125 AES_FINAL_ROUND(SA,SB,SC,SD, T, TMP, KEY)
128 AES_FINAL_ROUND(SB,SC,SD,SA, T, TMP, KEY)
131 AES_FINAL_ROUND(SC,SD,SA,SB, T, TMP, KEY)
134 AES_FINAL_ROUND(SD,SA,SB,SC, T, SD, KEY)
143 AES_SUBST_BYTE(SA,SB,SC,SD, T, KEY)
148 C Add last subkey, and store encrypted data
151 AES_STORE(SA,SB,SC,SD, KEY, TMP)
153 addl $16, FRAME_DST C Increment destination pointer
165 EPILOGUE(_nettle_aes_encrypt)