RM0367 Rev 7 439/1043
RM0367 AES hardware accelerator (AES)
466
Figure 88. STM32 cryptolib AES flowchart example
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, Mode 1 must be selected (MODE[1:0] = 00).
– For decryption, Mode 3 must be selected (MODE[1:0] = 10), unless ECB or CBC
chaining modes are used. In this latter case, an initial key derivation of the
encryption key must be performed, as described in Section 19.4.5: AES
decryption key preparation.
• Select the chaining mode, by programming the CHMOD[1:0] bitfield of the AES_CR
register
• Write a symmetric key into the AES_KEYRx registers .
• 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
vectors into the AES_IVRx register.
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.
MSv42146V1
Error status
Begin
AES_x encrypt init
AES_x encrypt
append
Error status
AES_x encrypt finish/
final
Error status
End
success
success
success
Encryption
Error status
Begin
AES_x decrypt init
AES_x decrypt
append
Error status
AES_x decrypt finish/
final
Error status
End
success
success
success
Decryption
Data to append
Data to append