
Preliminary
...the world's most energy friendly microcontrollers
2011-05-19 - d0034_Rev0.91
440
www.energymicro.com
Figure 27.1. AES Key and Data Definitions
PlainText
CipherText
PlainKey
CipherKey
Encrypt ion
Decrypt ion
Encrypt ion
Decrypt ion
27.3.1 Encryption/Decryption
The AES module can be set to encrypt or decrypt by clearing/setting the DECRYPT bit in AES_CTRL.
The AES256 bit in AES_CTRL configures the size of the key used for encryption/decryption. The
AES_CTRL register should not be altered while AES is running, as this may lead to unpredictable
behaviour.
An AES encryption/decryption can be started in the following ways:
Writing a 1 to the START bit in AES_CMD
Writing 4 times 32 bits to AES_DATA when the DATASTART control bit is set
Writing 4 times 32 bits to AES_XORDATA when the XORSTART control bit is set
An AES encryption/decryption can be stopped by writing a 1 to the STOP bit in AES_CMD. The
RUNNING bit in AES_STATUS indicates that an AES encryption/decryption is ongoing.
27.3.2 Data and Key Access
The AES module contains a 128-bit DATA (State) register and two 128-bit KEY registers defined as
DATA3-DATA0, KEY3-KEY0 (KEYL) and KEY7-KEY4 (KEYH). In AES128 mode, the 128-bit key is read
from KEYL, while both KEYH and KEYL are used in AES256 mode. The AES module has configurable
data written to the AES registers is mapped to the key and state defined in the Advanced Encryption
Standard (FIPS-197). The figure presents the key byte order for 256-bit keys. In 128-bit mode with
BYTEORDER cleared, a16 represents the first byte of the 128-bit key. When BYTEORDER is set, a0
represents the first byte in the key. AES encryption/decryption takes two extra cycles when BYTEORDER
is set. BYTEORDER has to be set prior to loading the data and key registers.
Figure 27.2. AES Data and Key Orientation as Defined in the Advanced Encryption Standard
D
A
T
A
0
D
A
T
A
1
D
A
T
A
2
D
A
T
A
3
K
E
Y
3
K
E
Y
2
K
E
Y
1
K
E
Y
0
DATA
KEYL
[ 31:24]
[ 23:16]
[ 15:8]
[ 7:0]
a0
a4
a1
a5
a2
a6
a8
a12
a9
a13
a10
a14
a11
a15
a3
a7
B
y
te
o
rd
e
r
in
w
o
rd
S0,0
S0,1
S1,0
S1,1
S2,0
S2,1
S0,2
S0,3
S1,2
S1,3
S2,2
S2,3
S3,2
S3,3
S3,0
S3,1
K
E
Y
7
K
E
Y
6
K
E
Y
5
K
E
Y
4
KEYH
a16
a20
a17
a21
a18
a22
a24
a28
a25
a29
a26
a30
a27
a31
a19
a23
BYTEORDER = 0
BYTEORDER = 1
D
A
T
A
3
D
A
T
A
2
D
A
T
A
1
D
A
T
A
0
K
E
Y
4
K
E
Y
5
K
E
Y
6
K
E
Y
7
DATA
KEYH
[ 7:0]
[ 15:8]
[ 23:16]
[ 31:24]
a0
a4
a1
a5
a2
a6
a8
a12
a9
a13
a10
a14
a11
a15
a3
a7
B
y
te
o
rd
e
r
in
w
o
rd
S0,0
S0,1
S1,0
S1,1
S2,0
S2,1
S0,2
S0,3
S1,2
S1,3
S2,2
S2,3
S3,2
S3,3
S3,0
S3,1
K
E
Y
0
K
E
Y
1
K
E
Y
2
K
E
Y
3
KEYL
a16
a20
a17
a21
a18
a22
a24
a28
a25
a29
a26
a30
a27
a31
a19
a23
The registers DATA3-DATA0, are not memory mapped directly, but can be written/read by accessing
AES_DATA or AES_XORDATA. The same applies for the key registers, KEY3-KEY0 which are
accessed through AES_KEYLn (n=A, B, C or D), while KEY7-KEY4 are accessed through KEYHn
(n=A, B, C or D). Writing DATA3-DATA0 is then done through 4 consecutive writes to AES_DATA (or
AES_XORDATA), starting with the word which is to be written to DATA0. For each write, the words will