1 C nettle
, low-level cryptographics library
3 C Copyright
(C
) 2001, 2002, 2005, 2008 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_64
/aes.m4
>)
24 C AES state
, use two of them
35 define
(<TABLE
>, <%rsi
>)
36 define
(<PARAM_LENGTH
>,<%edx>) C
Length is only
32 bits
37 define
(<PARAM_DST
>, <%rcx
>)
42 define
(<COUNT
>, <%r15d
>)
43 define
(<BLOCK_COUNT
>, <%r13d
>)
45 C Must correspond to an old
-style register
, for movzb from
%ah--%dh to
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
,
57 PROLOGUE
(_nettle_aes_encrypt
)
59 test PARAM_LENGTH
, PARAM_LENGTH
62 C save all registers that need to be saved
71 movl PARAM_LENGTH
, BLOCK_COUNT
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
83 add $16,KEY C point to next key
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
)
95 xorl
(KEY
),SA C
add current session key to plaintext
100 add $16,KEY C point to next key
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
)
113 AES_SUBST_BYTE
(TA
,TB
,TC
,SD
, TABLE
, TMP
)
118 C
Add last subkey
, and store encrypted data
119 AES_STORE
(TA
,TB
,TC
,SD
, KEY
, DST
)
135 EPILOGUE
(_nettle_aes_encrypt
)