
AES hardware accelerator (AES)
RM0453
656/1454
RM0453 Rev 2
Initialization of AES
To initialize AES, first disable it by clearing the EN bit of the AES_CR register. Then perform
the following steps in any order:
•
Configure the AES mode, by programming the MODE[1:0] bitfield of the AES_CR
register.
–
For encryption, select Mode 1 (MODE[1:0] = 00).
–
For decryption, select Mode 3 (MODE[1:0] = 10), unless ECB or CBC chaining
modes are used. In this latter case, perform an initial key derivation of the
encryption key, as described in
Section 23.4.5: AES decryption round key
•
Select the chaining mode, by programming the CHMOD[2:0] bitfield of the AES_CR
register.
•
Configure the data type (1-, 8-, 16- or 32-bit), with the DATATYPE[1:0] bitfield in the
AES_CR register.
•
When it is required (for example in CBC or CTR chaining modes), write the initialization
vector into the AES_IVRx registers.
•
Configure the key size (128-bit or 256-bit), with the KEYSIZE bitfield of the AES_CR
register.
•
Write a symmetric key into the AES_KEYRx registers (4 or 8 registers depending on
the key size).
Data append
This section describes different ways of appending data for processing, where the size of
data to process is not a multiple of 128 bits.
For ECB or CBC mode, refer to
Section 23.4.6: AES ciphertext stealing and data padding
.
The last block management in these cases is more complex than in the sequence described
in this section.
Data append through polling
This method uses flag polling to control the data append through the following sequence:
1.
Enable the AES peripheral by setting the EN bit of the AES_CR register.
2. Repeat the following sub-sequence until the payload is entirely processed:
a) Write four input data words into the AES_DINR register.
b) Wait until the status flag CCF is set in the AES_SR, then read the four data words
from the AES_DOUTR register.
c) Clear the CCF flag, by setting the CCFC bit of the AES_CR register.
d) If the data block just processed is the second-last block of the message and the
significant data in the last block to process is inferior to 128 bits, pad the
remainder of the last block with zeros and, in case of GCM payload encryption or
CCM payload decryption, specify the number of non-valid bytes, using the NPBLB
bitfield of the AES_CR register, for AES to compute a correct tag;.
3. As it is the last block, discard the data that is not part of the data, then disable the AES
peripheral by clearing the EN bit of the AES_CR register.
Note:
Up to three wait cycles are automatically inserted between two consecutive writes to the
AES_DINR register, to allow sending the key to the AES processor.
NPBLB bits are not used in header phase of GCM, GMAC and CCM chaining modes.