25. AES hardware accelerator (AES)

In this section, any references to SAES only apply to STM32WBA52/54/55xx products. The STM32WBA50xx products do not have the SAES peripheral.

25.1 Introduction

The AES hardware accelerator (AES) encrypts or decrypts data in compliance with the advanced encryption standard (AES) defined by NIST.

AES supports ECB, CBC, CTR, GCM, GMAC, and CCM chaining modes for key sizes of 128 or 256 bits.

AES has the possibility to load by hardware the key stored in SAES peripheral, under SAES control.

The peripheral supports DMA single transfers for incoming and outgoing data (two DMA channels are required).

25.2 AES main features

25.3 AES implementation

The devices have one AES peripheral, implemented as per the following table. It can use the key generated by the SAES peripheral. For comparison, the SAES peripheral is also included in the table.

Table 181. AES versus SAES features

Modes or features (1)AESSAES
ECB, CBC chainingXX
CTR, CCM, GCM chainingXX
AES 128-bit ECB encryption in cycles51480
DHUK and BHK key selection-X
Resistance to side-channel attacks-X
Shared key between SAES and AESX
Key sizes in bits128, 256128, 256

1. X = supported.

25.4 AES functional description

25.4.1 AES block diagram

Figure 113 shows the block diagram of AES.

Figure 113. AES block diagram

Figure 113. AES block diagram. The diagram shows the internal architecture of the AES hardware accelerator. It includes an AHB interface connected to a 32-bit AHB bus and aes_hclk. The interface connects to a set of registers: AES_KEYRx, AES_IVRx, AES_SR, AES_CR, AES_DINR, AES_DOUTR, and AES_SUSPRx. These registers are part of a 'Banked registers' block. The registers connect to an 'AES Core (AEA)' which includes a 'swap' block. The registers also connect to 'Control Logic'. The 'Control Logic' is connected to a 'DMA interface' (with aes_in_dma and aes_out_dma signals) and an 'IRQ interface' (with aes_it signal). The 'Control Logic' also outputs aes_itamp_out. An external 'SAES' block provides a 'Shared key' to the AES_KEYRx register. The diagram is labeled MSv47991V1.
Figure 113. AES block diagram. The diagram shows the internal architecture of the AES hardware accelerator. It includes an AHB interface connected to a 32-bit AHB bus and aes_hclk. The interface connects to a set of registers: AES_KEYRx, AES_IVRx, AES_SR, AES_CR, AES_DINR, AES_DOUTR, and AES_SUSPRx. These registers are part of a 'Banked registers' block. The registers connect to an 'AES Core (AEA)' which includes a 'swap' block. The registers also connect to 'Control Logic'. The 'Control Logic' is connected to a 'DMA interface' (with aes_in_dma and aes_out_dma signals) and an 'IRQ interface' (with aes_it signal). The 'Control Logic' also outputs aes_itamp_out. An external 'SAES' block provides a 'Shared key' to the AES_KEYRx register. The diagram is labeled MSv47991V1.

25.4.2 AES internal signals

Table 182 describes the user relevant internal signals interfacing the AES peripheral.

Table 182. AES internal input/output signals

Signal nameSignal typeDescription
aes_hclkInputAHB bus clock
aes_itOutputAES interrupt request
aes_in_dmaInput/OutputAES incoming data DMA single request/acknowledge
aes_out_dmaInput/OutputAES processed data DMA single request/acknowledge
aes_itamp_outOutputTamper event signal to TAMP (XOR-ed), triggered when an unexpected hardware fault occurs. When this signal is triggered, AES automatically clears key registers. A reset is required for AES to be usable again.

25.4.3 AES reset and clocks

The AES peripheral is clocked by the AHB bus clock. It has a dedicated reset bit controlled through the RCC.

25.4.4 AES symmetric cipher implementation

The AES hardware accelerator (AES) is a 32-bit AHB peripheral that encrypts or decrypts 16-byte blocks of data using the advanced encryption standard (AES). It also implements a set of approved AES symmetric key security functions summarized in Table 183. Those functions can be certified NIST PUB 140-3.

Table 183. AES approved symmetric key functions

OperationsAlgorithmSpecificationKey bit lengthsChaining modes
Encryption, decryptionAESFIPS PUB 197
NIST SP800-38A
128, 256ECB, CBC, CTR
Authenticated encryption or decryptionNIST SP800-38C
NIST SP800-38D
GCM, CCM
Cipher-based message authentication codeNIST SP800-38DGMAC

AES can be used directly by the CPU, or indirectly, using two DMA channels (one for the plaintext, one for the ciphertext). It is possible to suspend then resume any AES processing, following the sequence described in Section 25.4.8 .

25.4.5 AES encryption or decryption typical usage

The following figure shows a typical operation for encryption or decryption.

Figure 114. Encryption/ decryption typical usage

Flowchart of AES encryption/decryption typical usage. The process starts with 'Start' -> 'Initialization'. A decision diamond 'ECB or CBC decryption?' follows. If 'Yes', it goes to 'Round key preparation' then to 'Data append'. If 'No', it goes directly to 'Data append'. From 'Data append', a decision diamond 'Last block?' follows. If 'No', it loops back to 'Data append'. If 'Yes', it goes to 'All bytes valid?'. If 'Yes', it goes to 'Finalize' -> 'End'. If 'No', it goes to 'Data padding' or 'Data stealing'. Both lead to a decision diamond 'ECB or CBC chaining?'. If 'Yes', it goes to 'Data stealing'. If 'No', it goes to 'Data padding'. Both 'Data padding' and 'Data stealing' lead to 'Finalize' -> 'End'. MSV66120V1 is noted in the bottom right.
Flowchart of AES encryption/decryption typical usage. The process starts with 'Start' -> 'Initialization'. A decision diamond 'ECB or CBC decryption?' follows. If 'Yes', it goes to 'Round key preparation' then to 'Data append'. If 'No', it goes directly to 'Data append'. From 'Data append', a decision diamond 'Last block?' follows. If 'No', it loops back to 'Data append'. If 'Yes', it goes to 'All bytes valid?'. If 'Yes', it goes to 'Finalize' -> 'End'. If 'No', it goes to 'Data padding' or 'Data stealing'. Both lead to a decision diamond 'ECB or CBC chaining?'. If 'Yes', it goes to 'Data stealing'. If 'No', it goes to 'Data padding'. Both 'Data padding' and 'Data stealing' lead to 'Finalize' -> 'End'. MSV66120V1 is noted in the bottom right.

Initialization

The AES peripheral is initialized according to the chaining mode. Refer to Section 25.4.9: AES basic chaining modes (ECB, CBC) and Section 25.4.10: AES counter (CTR) mode for details.

Data append

This section describes different ways of appending data for processing. For ECB or CBC chaining modes, refer to Section 25.4.7: AES ciphertext stealing and data padding if the size of data to process is not a multiple of 16 bytes. The last block management in these cases is more complex than what is described in this section.

Appending data using the CPU in polling mode

This method uses flag polling to control the data append through the following sequence:

  1. 1. Enable the AES peripheral when KEYVALID is set, by setting the EN bit of the AES_CR register (if not already done).
  2. 2. Repeat the following sub-sequence until the payload is entirely processed:
    1. a) Write four input data words into the AES_DINR register.
    2. b) Wait until the status flag CCF is set in the AES_ISR register, then read the four data words from the AES_DOUTR register.
    3. c) Clear the CCF flag, by setting the CCF bit of the AES_ICR register.
    4. d) If the next processing block is the last block, pad (when applicable) the data with zeros to obtain a complete block, and specify the number of non-valid bytes (using NPBLB[3:0]) in case of GCM payload encryption or CCM payload decryption (otherwise the tag computation is wrong).
  3. 3. As the data block just processed is the last block of the message, optionally discard the data that is not part of the message/payload, then disable the AES peripheral by clearing EN.

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[3:0] bitfield is not used in header phase of GCM, GMAC and CCM chaining modes.

Appending data using the CPU in interrupt mode

The method uses interrupt from the AES peripheral to control the data append, through the following sequence:

  1. 1. Enable interrupts from AES, by setting the CCFIE bit of the AES_IER register.
  2. 2. Enable the AES peripheral when KEYVALID is set, by setting EN (if not already done).
  3. 3. Write first four input data words into the AES_DINR register.
  4. 4. Handle the data in the AES interrupt service routine. Upon each interrupt:
    1. a) Read four output data words from the AES_DOUTR register.
    2. b) Clear the CCF flag and thus the pending interrupt, by setting the CCF bit of the AES_ICR register.
    3. c) If the next processing block is the last block of the message, pad (when applicable) the data with zeros to obtain a complete block, and specify the number of non-valid bytes (through NPBLB[3:0]) in case of GCM payload encryption or CCM payload decryption (otherwise the tag computation is wrong). Then proceed with point 4e).
    4. d) If the data block just processed is the last block of the message, optionally discard the data that are not part of the message/payload, then disable the AES peripheral by clearing EN and quit the interrupt service routine.
    5. e) Write next four input data words into the AES_DINR register and quit the interrupt service routine.

Note: AES is tolerant of delays between consecutive read or write operations, which allows, for example, an interrupt from another peripheral to be served between two AES computations.
The NPBLB[3:0] bitfield is not used in the header phase of GCM, GMAC, and CCM chaining modes.

Appending data using DMA

With this method, all the transfers and processing are managed by DMA and AES. Proceed as follows:

  1. 1. If the last block of the message to process is shorter than 16 bytes, prepare the last four-word data block by padding the remainder of the block with zeros.
  2. 2. Configure the DMA controller so as to transfer the data to process from the memory to the AES peripheral input and the processed data from the AES peripheral output to the memory, as described in Section 25.6: AES DMA requests . Configure the DMA controller so as to generate an interrupt on transfer completion. For GCM payload encryption or CCM payload decryption, the DMA transfer must not include the last four-word block if padded with zeros. The sequence described in Appending data using the CPU in polling mode must be used instead for this last block, because the NPBLB[3:0] bitfield must be set up before processing the block, for AES to compute a correct tag.
  3. 3. Enable the AES peripheral when KEYVALID is set, by setting EN (if not already done).
  4. 4. Enable DMA requests, by setting DMAINEN and DMAOUTEN.
  5. 5. Upon DMA interrupt indicating the transfer completion, get the AES-processed data from the memory.

When appending data using DMA, the suspend/resume operation as described in Section 25.4.8 is not supported.

Note: The CCF flag has no use with this method because the reading of the AES_DOUTR register is managed by DMA automatically, without any software action, at the end of the computation phase.

The NPBLB[3:0] bitfield is not used in the header phase of GCM, GMAC, and CCM chaining modes.

25.4.6 AES authenticated encryption, decryption, and cipher-based message authentication

The following figure shows a typical operation for authenticated encryption or decryption, and for cipher-based message authentication.

Figure 115. Typical operation with authentication

Flowchart illustrating the typical operation with authentication, showing header and payload phases.
graph TD
    Start([Start]) --> Init[Initialization]
    Init --> HeaderInit[Header phase init]
    HeaderInit --> HeaderAppend[Header data append]
    HeaderAppend --> LastBlockHeader{Last block?}
    LastBlockHeader -- No --> HeaderAppend
    LastBlockHeader -- Yes --> AllBytesValidHeader{All bytes valid?}
    AllBytesValidHeader -- No --> DataPaddingHeader[Data padding]
    AllBytesValidHeader -- Yes --> CipherBasedAuth{cipher-based* authentication?}
    DataPaddingHeader --> CipherBasedAuth
    CipherBasedAuth -- Yes --> Finalization[Finalization]
    CipherBasedAuth -- No --> PayloadInit[Payload phase init]
    PayloadInit --> PayloadAppend[Payload data append]
    PayloadAppend --> LastBlockPayload{Last block?}
    LastBlockPayload -- No --> PayloadAppend
    LastBlockPayload -- Yes --> AllBytesValidPayload{All bytes valid?}
    AllBytesValidPayload -- No --> DataPaddingPayload[Data padding]
    AllBytesValidPayload -- Yes --> Finalization
    DataPaddingPayload --> Finalization
    Finalization --> End([End])
  

The flowchart shows two main paths: a header phase and a payload phase. Both phases start with an initialization step, followed by an append step. A loop exists for appending multiple blocks until the last block is reached. Once the last block is reached, a validity check is performed. If not valid, data padding is applied. Both valid and padded data then lead to a decision point for 'cipher-based* authentication?'. If 'Yes', the process moves to 'Finalization'. If 'No', it moves to the 'Payload phase init'. The payload phase follows a similar structure to the header phase. All paths eventually lead to 'Finalization' and then 'End'. A note indicates that the 'cipher-based' authentication step is '* such as GMAC'. The diagram is labeled MSV66121V1.

Flowchart illustrating the typical operation with authentication, showing header and payload phases.

Section 25.4.11: AES Galois/counter mode (GCM) and Section 25.4.13: AES counter with CBC-MAC (CCM) describe detailed sequences supported by AES.

Cipher-based message authentication flow omits the payload phase, as shown in the figure. Detailed sequence supported by AES is described in Section 25.4.12: AES Galois message authentication code (GMAC) .

25.4.7 AES ciphertext stealing and data padding

When using AES in ECB or CBC modes to manage messages the size of which is not a multiple of the block size (16 bytes), the application must use ciphertext stealing techniques such as those described in NIST Special Publication 800-38A, Recommendation for Block Cipher Modes of Operation: Three Variants of Ciphertext Stealing for CBC Mode . Since AES does not implement such techniques, the application must complete the last block of input data using data from the second last block .

Note: Ciphertext stealing techniques are not documented in this reference manual.

Similarly, in modes other than ECB or CBC, an incomplete input data block (that is, a block with input data shorter than 16 bytes) must be padded with zeros prior to encryption. That is, extra bits must be appended to the trailing end of the data string. After decryption, the extra bits must be discarded. Since AES does not implement automatic data padding operation to the last block , the application must follow the recommendation given in this document to manage messages the size of which is not a multiple of 16 bytes.

25.4.8 AES suspend and resume operations

A message can be suspended to process another message with a higher priority. When the higher-priority message is sent, the suspended message can resume. This applies to both encryption and decryption mode.

Suspend and resume operations do not break the chaining operation. The message processing can resume as soon as AES is enabled again, to receive a next data block.

The suspend and resume operations are only supported when AES is used in CPU mode, not in DMA mode.

Figure 116 gives an example of suspend and resume operations: Message 1 is suspended in order to send a shorter and higher-priority Message 2.

Figure 116. Example of suspend mode management

Diagram illustrating AES suspend and resume operations. Message 1 consists of 128-bit blocks 1 through 6. Message 2 consists of 128-bit blocks 1 and 2. The diagram shows Message 1 being processed, then suspended by an 'AES suspend sequence' when a higher-priority Message 2 is introduced. After Message 2 is processed, an 'AES resume sequence' resumes Message 1.

The diagram illustrates the flow of data blocks for two messages. Message 1 is shown as a vertical sequence of blocks: 128-bit block 1, 128-bit block 2, 128-bit block 3, 128-bit block 4, 128-bit block 5, 128-bit block 6, and an ellipsis. Message 2 is shown as a vertical sequence of blocks: 128-bit block 1 and 128-bit block 2. A callout bubble on the left indicates 'New higher-priority message 2 to be processed'. An arrow points from the end of Message 1's initial sequence (after block 3) to a box labeled 'AES suspend sequence'. From this box, an arrow points to the start of Message 2's sequence. After Message 2's sequence, an arrow points to a box labeled 'AES resume sequence'. From this box, an arrow points back to the continuation of Message 1's sequence (starting at block 4). The diagram is labeled 'MSV42148V1' in the bottom right corner.

Diagram illustrating AES suspend and resume operations. Message 1 consists of 128-bit blocks 1 through 6. Message 2 consists of 128-bit blocks 1 and 2. The diagram shows Message 1 being processed, then suspended by an 'AES suspend sequence' when a higher-priority Message 2 is introduced. After Message 2 is processed, an 'AES resume sequence' resumes Message 1.

A detailed description of suspend and resume operations is in the sections dedicated to each chaining mode.

25.4.9 AES basic chaining modes (ECB, CBC)

ECB is the simplest mode of operation. There are no chaining operations, and no special initialization stage. The message is divided into blocks and each block is encrypted or decrypted separately. When decrypting in ECB, a special key scheduling is required before processing the first block.

Figure 117 and Figure 118 describe the electronic codebook (ECB) chaining implementation in encryption and in decryption, respectively. To select ECB chaining mode, write CHMOD[2:0] with 0x0.

Figure 117. ECB encryption

Diagram of ECB encryption showing two blocks, Block 1 and Block 2. Each block consists of a Swap management block, an Encrypt block, and another Swap management block. Inputs are DIN (plaintext P1, P2), KEY, and DATATYPE[1:0]. Outputs are DOUT (ciphertext C1, C2). A legend indicates input and output blocks.

Figure 117. ECB encryption

The diagram illustrates the ECB encryption process for two blocks, Block 1 and Block 2. Each block follows a similar structure:

Legend

Diagram of ECB encryption showing two blocks, Block 1 and Block 2. Each block consists of a Swap management block, an Encrypt block, and another Swap management block. Inputs are DIN (plaintext P1, P2), KEY, and DATATYPE[1:0]. Outputs are DOUT (ciphertext C1, C2). A legend indicates input and output blocks.

Figure 118. ECB decryption

Diagram of ECB decryption showing two blocks, Block 1 and Block 2. Each block consists of a Swap management block, a Decrypt block, and another Swap management block. Inputs are DIN (ciphertext C1, C2), KEY, and DATATYPE[1:0]. Outputs are DOUT (plaintext P1, P2). A legend indicates input and output blocks.

Figure 118. ECB decryption

The diagram illustrates the ECB decryption process for two blocks, Block 1 and Block 2. Each block follows a similar structure:

Legend

Diagram of ECB decryption showing two blocks, Block 1 and Block 2. Each block consists of a Swap management block, a Decrypt block, and another Swap management block. Inputs are DIN (ciphertext C1, C2), KEY, and DATATYPE[1:0]. Outputs are DOUT (plaintext P1, P2). A legend indicates input and output blocks.

In CBC encryption mode the output of each block chains with the input of the following block. To make each message unique, an initialization vector is used during the first block processing. When decrypting in CBC, a special key scheduling is required before processing the first block.

Figure 119 and Figure 120 describe the cipher block chaining (CBC) implementation in encryption and in decryption, respectively. To select this chaining mode, write CHMOD[2:0] with 0x1.

Figure 119. CBC encryption

Diagram of CBC encryption showing two blocks, Block 1 and Block 2. Each block consists of a Swap management block, a Block cipher encryption block, and another Swap management block. Inputs are DIN (plaintext P1, P2), KEY, and DATATYPE[1:0]. Outputs are DOUT (ciphertext C1, C2). A legend indicates input, output, and XOR blocks.

Figure 119. CBC encryption

The diagram illustrates the CBC encryption process for two blocks, Block 1 and Block 2. Each block follows a similar structure:

Legend

Diagram of CBC encryption showing two blocks, Block 1 and Block 2. Each block consists of a Swap management block, a Block cipher encryption block, and another Swap management block. Inputs are DIN (plaintext P1, P2), KEY, and DATATYPE[1:0]. Outputs are DOUT (ciphertext C1, C2). A legend indicates input, output, and XOR blocks.

Figure 120. CBC decryption

Diagram of CBC decryption process showing Block 1 and Block 2. Block 1 takes DIN (ciphertext C1) through Swap management to get I1, which is decrypted using KEY to produce O1. O1 is XORed with IVI to produce P1', which is then Swap managed to produce DOUT (plaintext P1). Block 2 takes DIN (ciphertext C2) through Swap management to get I2, which is decrypted using KEY to produce O2. O2 is XORed with O1 (the previous ciphertext block) to produce P2', which is then Swap managed to produce DOUT (plaintext P2). A legend indicates that white boxes are input, grey boxes are output, and a circle with an X is XOR.
Diagram of CBC decryption process showing Block 1 and Block 2. Block 1 takes DIN (ciphertext C1) through Swap management to get I1, which is decrypted using KEY to produce O1. O1 is XORed with IVI to produce P1', which is then Swap managed to produce DOUT (plaintext P1). Block 2 takes DIN (ciphertext C2) through Swap management to get I2, which is decrypted using KEY to produce O2. O2 is XORed with O1 (the previous ciphertext block) to produce P2', which is then Swap managed to produce DOUT (plaintext P2). A legend indicates that white boxes are input, grey boxes are output, and a circle with an X is XOR.

For more details, refer to NIST Special Publication 800-38A, Recommendation for Block Cipher Modes of Operation .

ECB and CBC encryption process

This process is described in Section 25.4.5 , with the following sequence of events:

  1. 1. Disable the AES peripheral, by clearing EN.
  2. 2. Initialize the AES_CR register as follows:
    • – Select ECB or CBC chaining mode (write CHMOD[2:0] with 0x0 or 0x1) in encryption mode (write MODE[1:0] with 0x0).
    • – Configure the data type, through DATATYPE[1:0].
    • – Configure the key size, through KEYSIZE.
    • – Select the key mode, using KMOD[1:0]. If the key comes from the SAES peripheral, write KMOD[1:0] with 0x2, otherwise keep it at 0x0.
  3. 3. Write the initialization vector into the AES_IVRx registers if CBC mode is selected in the previous step.
  4. 4. Write the key into the AES_KEYRx registers if KMOD[1:0] is at 0x0. If KMOD[1:0] is at 0x2, the key is transferred from the SAES peripheral (see Section 25.4.14 ).
  5. 5. Wait until KEYVALID is set (the key loading completed).
  6. 6. Enable the AES peripheral, by setting EN.
  7. 7. Append cleartext data:
    1. a) If it is the second-last or the last block and the plaintext size of the message is not a multiple of 16 bytes, follow the guidance in Section 25.4.7 .
    2. b) Append the cleartext block into AES as described in Section 25.4.5 , then read the AES_DOUTR register four times to save the ciphertext block.
    3. c) Repeat the step b) until the third-last plaintext block is encrypted. For the last two blocks, follow the steps a) and b) .
  8. 8. Finalize the sequence: disable the AES peripheral, by clearing EN.

ECB/CBC decryption process

This process is described in Section 25.4.5 , with the following sequence of events:

  1. 1. Disable the AES peripheral, by clearing EN.
  2. 2. Initialize the AES_CR register as follows:
    • – Select the key derivation mode (write MODE[1:0] with 0x1). The CHMOD[2:0] bitfield is not significant during this operation.
    • – Configure the data type, through DATATYPE[1:0].
    • – Configure the key size, through KEYSIZE.
    • – Select the key mode, using KMOD[1:0]. If the key comes from the SAES peripheral, write KMOD[1:0] with 0x2, otherwise keep it at 0x0.
  3. 3. Write the key into the AES_KEYRx registers if KMOD[1:0] is at 0x0. If KMOD[1:0] is at 0x2, the key is transferred from the SAES peripheral (see Section 25.4.14 ).
  4. 4. Wait until KEYVALID is set (the key loading completed).
  5. 5. Enable the AES peripheral, by setting EN. The peripheral immediately starts an AES round for key preparation.
  6. 6. Wait until the CCF flag in the AES_ISR register is set.
  7. 7. Clear the CCF flag, by setting the CCF bit of the AES_ICR register. The decryption key is available in the AES core and AES is disabled automatically.
  8. 8. Select ECB or CBC chaining mode (write CHMOD[2:0] with 0x0 or 0x1) in decryption mode (write MODE[1:0] with 0x2). Do not change other parameters.
  9. 9. Write the initialization vector into the AES_IVRx registers if CBC mode is selected in the previous step.
  10. 10. Enable the AES peripheral, by setting EN.
  11. 11. Append encrypted data:
    1. a) If it is the second-last or the last block and the ciphertext size of the message is not a multiple of 16 bytes, follow the guidance in Section 25.4.7 .
    2. b) Append the ciphertext block into AES as described in Section 25.4.5 , then read the AES_DOUTR register four times to save the cleartext block (MSB first).
    3. c) Repeat the step b ) until the third-last ciphertext block is decrypted. For the last two blocks, follow the steps a ) and b ).
  12. 12. Finalize the sequence: disable the AES peripheral, by clearing EN.

Suspend/resume operations in ECB/CBC modes

The suspend and resume operations are only supported when AES is used in CPU mode, not in DMA mode.

To suspend the processing of a message , proceed as follows:

  1. 1. Wait until the CCF flag in the AES_ISR register is set (computation completed).
  2. 2. Read four times the AES_DOUTR register to save the last processed block.
  3. 3. Clear the CCF flag, by setting the CCF bit of the AES_ICR register.
  4. 4. Save initialization vector registers (only required in CBC mode as the AES_IVRx registers are altered during the data processing).

To resume the processing of a message, proceed as follows:

Note: It is not required to save the key registers as the application knows the original key.

25.4.10 AES counter (CTR) mode

The CTR mode uses the AES core to generate a key stream. The keys are then XOR-ed with the plaintext to obtain the ciphertext. Unlike with ECB and CBC modes, no key scheduling is required for the CTR decryption since the AES core is always used in encryption mode.

A typical message construction in CTR mode is given in Figure 121 .

Figure 121. Message construction in CTR mode

Diagram of message construction in CTR mode showing the ICB (Initialization vector and Counter) and the resulting Ciphertext (C) with zero padding.

The diagram illustrates the message structure in CTR mode. At the top, a horizontal bar represents the message, divided into three main parts: an Initial Counter Block (ICB), a Ciphertext (C) section, and a Zero padding section at the end. The ICB is shown in more detail below, as a 16-byte block (indicated by a '16-byte boundaries' label above it) composed of two fields: an Initialization vector (IV) and a Counter (indicated by '4-byte boundaries' labels above them). An arrow labeled 'decrypt' points from the Ciphertext (C) section down to a Plaintext (P) section. The Zero padding section is marked with a '0' and the label 'Zero padding'. A reference code 'MSv42156V1' is visible in the bottom right corner of the diagram area.

Diagram of message construction in CTR mode showing the ICB (Initialization vector and Counter) and the resulting Ciphertext (C) with zero padding.

The structure of this message is:

For more details, refer to NIST Special Publication 800-38A, Recommendation for Block Cipher Modes of Operation .

CTR encryption and decryption

Figure 122 describes the counter (CTR) chaining implementation in the AES peripheral (encryption). To select this chaining mode, write CHMOD[2:0] with 0x2.

Figure 122. CTR encryption

Diagram of CTR encryption process showing Block 1 and Block 2. Each block consists of an IV/Nonce + 32-bit counter, an Encrypt block, a Swap management block, and an XOR block. The counter is incremented by 1 for each block. The plaintext (DIN) is XORed with the output of the Encrypt block to produce the ciphertext (DOUT).

The diagram illustrates the CTR encryption process across two blocks, Block 1 and Block 2.
In Block 1:
- The IV/Nonce + 32-bit counter (labeled I1) is input to the Encrypt block along with the KEY.
- The Encrypt block outputs O1.
- O1 is input to a Swap management block.
- The Swap management block outputs P1'.
- P1' is XORed with the DIN (plaintext P1) to produce C1'.
- C1' is input to another Swap management block, which outputs DOUT (ciphertext C1).
- The counter is incremented by 1 to become the IV/Nonce + 32-bit counter (+1) for Block 2.
In Block 2:
- The IV/Nonce + 32-bit counter (+1) (labeled I2) is input to the Encrypt block along with the KEY.
- The Encrypt block outputs O2.
- O2 is input to a Swap management block.
- The Swap management block outputs P2'.
- P2' is XORed with the DIN (plaintext P2) to produce C2'.
- C2' is input to another Swap management block, which outputs DOUT (ciphertext C2).
Legend:
- Input: light gray rectangle
- Output: dark gray rectangle
- XOR: circle with a cross symbol
- DATATYPE[1:0]: control signal for Swap management blocks
- MSV69567V1: document code

Diagram of CTR encryption process showing Block 1 and Block 2. Each block consists of an IV/Nonce + 32-bit counter, an Encrypt block, a Swap management block, and an XOR block. The counter is incremented by 1 for each block. The plaintext (DIN) is XORed with the output of the Encrypt block to produce the ciphertext (DOUT).

Initialization vectors in AES must be initialized as shown in Table 184.

Table 184. Counter mode initialization vector definition

AES_IVR3[31:0]AES_IVR2[31:0]AES_IVR1[31:0]AES_IVR0[31:0]
IVI[127:96]IVI[95:64]IVI[63:32]IVI[31:0]
32-bit counter = 0x0001

CTR encryption and decryption process

This process is described in Section 25.4.5, with the following sequence of events:

  1. Disable the AES peripheral, by clearing EN.
  2. Initialize the AES_CR register:
    • Select CTR chaining mode (write CHMOD[2:0] with 0x2) in encryption or decryption mode (write MODE[1:0] with 0x0 or 0x2).
    • Configure the data type, through DATATYPE[1:0].
    • Configure the key size, through KEYSIZE.
    • Select the key mode, using KMOD[1:0]. If the key comes from the SAES peripheral, write KMOD[1:0] with 0x2, otherwise keep it at 0x0.
  3. Write the initialization vector into the AES_IVRx registers according to Table 184.
  4. Write the key into the AES_KEYRx registers if KMOD[1:0] is at 0x0. If KMOD[1:0] is at 0x2, the key is transferred from the SAES peripheral (see Section 25.4.14).
  5. Wait until KEYVALID is set (the key loading completed).
  6. Enable the AES peripheral, by setting EN.
  1. 7. Append data:
    1. a) If it is the last block and the plaintext (encryption) or ciphertext (decryption) size in the block is less than 16 bytes, pad the remainder of the block with zeros.
    2. b) Append the data block into AES as described in Section 25.4.5 , then read the AES_DOUTR register four times to save the resulting block (MSB first).
    3. c) Repeat the step b) until the second-last block is processed. For the last block of plaintext (encryption only), follow the steps a) and b). For the last block, discard the bits that are not part of the message when the last block is smaller than 16 bytes.
  2. 8. Finalize the sequence: disable the AES peripheral, by clearing EN.

Suspend/resume operations in CTR mode

Like for the CBC mode, it is possible to interrupt a message to send a higher-priority message, then resume the interrupted message. Detailed CBC suspend and resume sequence is described in Section 25.4.9: AES basic chaining modes (ECB, CBC) .

The suspend and resume operations are only supported when AES is used in CPU mode, not in DMA mode.

Note: Like for CBC mode, the IV registers must be reloaded during the resume operation.

25.4.11 AES Galois/counter mode (GCM)

The AES Galois/counter mode (GCM) allows encrypting and authenticating a plaintext message into the corresponding ciphertext and tag (also known as message authentication code).

GCM mode is based on AES in counter mode for confidentiality. It uses a multiplier over a fixed finite field for computing the message authentication code. The following figure shows a typical message construction in GCM mode.

Figure 123. Message construction in GCM

Diagram illustrating message construction in GCM mode. It shows the flow from Initialization vector (IV) and Counter through ICB to Additional authenticated data (AAD) and Plaintext (P), resulting in Authenticated & encrypted ciphertext (C) and an Authentication tag (T).

The diagram illustrates the message construction in GCM mode. It shows the following components and flow:

The diagram also shows the flow of data: ICB leads to AAD and Plaintext (P). AAD is processed by 'authenticate' to produce the Authentication tag (T). Plaintext (P) is processed by 'encrypt' to produce the Authenticated & encrypted ciphertext (C). The final block of the ciphertext is also processed by 'authenticate' to produce the Authentication tag (T).

Diagram illustrating message construction in GCM mode. It shows the flow from Initialization vector (IV) and Counter through ICB to Additional authenticated data (AAD) and Plaintext (P), resulting in Authenticated & encrypted ciphertext (C) and an Authentication tag (T).

The message has the following structure:

The GCM standard specifies that ciphertext C has the same bit length as the plaintext P.

When a part of the message (AAD or P) has a length that is a non-multiple of 16-bytes a special padding scheme is required.

For more details, refer to NIST Special Publication 800-38D, Recommendation for Block Cipher Modes of Operation - Galois/Counter Mode (GCM) and GMAC .

Figure 124 describes the GCM chaining implementation in the AES peripheral (encryption). To select this chaining mode, write CHMOD[2:0] with 0x3.

Figure 124. GCM authenticated encryption

Diagram of GCM authenticated encryption process showing Init, Header, Payload, and Final stages with counter blocks and GF2mul operations.

The diagram illustrates the GCM authenticated encryption process, divided into four main stages:

A legend indicates: input (white box), output (grey box), and XOR (circle with cross).

Diagram of GCM authenticated encryption process showing Init, Header, Payload, and Final stages with counter blocks and GF2mul operations.

The first counter block (CB1) is derived from the initial counter block ICB by the application software, as defined in Table 185.

Table 185. Initialization of IV registers in GCM mode

AES_IVR3[31:0]AES_IVR2[31:0]AES_IVR1[31:0]AES_IVR0[31:0]
ICB[127:96]ICB[95:64]ICB[63:32]ICB[31:0]
32-bit counter = 0x0002

The last block of a GCM message contains the AAD header length and the payload length information, as shown in Table 186.

Table 186. GCM last block definition

Word order to AES_DINRFirst wordSecond wordThird wordFourth word
Input dataAAD length[63:32]AAD length[31:0]Payload length[63:32]Payload length[31:0]

GCM encryption and decryption process

This process is described in Section 25.4.6 , with the following sequence of events:

GCM initialize

  1. 1. Disable the AES peripheral, by clearing EN.
  2. 2. Initialize the AES_CR register:
    • – Select GCM chaining mode (write CHMOD[2:0] with 0x3) in encryption or decryption mode (write MODE[1:0] with 0x0 or 0x2). Do not write MODE[1:0] with 0x1.
    • – Configure the data type, through DATATYPE[1:0]
    • – Configure the key size, through KEYSIZE.
    • – Select the key mode, using KMOD[1:0]. If the key comes from the SAES peripheral, write KMOD[1:0] with 0x2, otherwise keep it at 0x0.
    • – Select the GCM initialization phase, by writing GCMPH[1:0] with 0x0.
  3. 3. Write the initialization vector in AES_IVRx registers according to Table 185 .
  4. 4. Write the key into the AES_KEYRx registers if KMOD[1:0] is at 0x0. If KMOD[1:0] is at 0x2, the key is transferred from the SAES peripheral (see Section 25.4.14 ).
  5. 5. Wait until KEYVALID is set (the key loading completed).
  6. 6. Set EN to start the calculation of the hash key. EN is automatically cleared when the calculation is completed.
  7. 7. Wait until the CCF flag is set in the AES_ISR register, indicating that the GCM hash subkey (H) computation is completed.
  8. 8. Clear the CCF flag by setting the CCF bit of the AES_ICR register.

GCM header phase

  1. 9. Initialize header phase:
    1. a) Select the GCM header phase, by writing 0x1 to GCMPH[1:0]. Do not change the other configurations written during GCM initialization.
    2. b) Enable the AES peripheral, by setting EN.
  2. 10. Append header data:
    1. a) If it is the last block and the AAD in the block is smaller than 16 bytes, pad the remainder of the block with zeros.
    2. b) Append the data block into AES as described in Section 25.4.5 .
    3. c) Repeat the step b) until the second-last AAD data block is processed. For the last block, follow the steps a) and b) .

Note: This phase can be skipped if there is no AAD, that is, Len(A) = 0.

No data are read during header phase.

GCM payload phase

  1. 11. Initialize payload phase:
    1. a) Select the GCM payload phase, by writing GCMPH[1:0] with 0x2. Do not change the other configurations written during GCM initialization.
    2. b) If the header phase is skipped, enable the AES peripheral by setting EN.
  1. 12. Append payload data:
    1. a) If it is the last block and the message in the block is smaller than 16 bytes, pad the remainder of the block with zeros.
    2. b) Append the data block into AES as described in Section 25.4.5 , then read the AES_DOUTR register four times to save the resulting block
    3. c) Repeat the step b) until the second-last plaintext block is encrypted or until the last block of ciphertext is decrypted. For the last block of plaintext (encryption only), follow the steps a) and b) . For the last block, discard the bits that are not part of the payload when the last block is smaller than 16 bytes.

Note: This phase can be skipped if there is no payload, that is, Len(C)=0 (see GMAC mode).

GCM finalization

  1. 13. Select the GCM final phase, by writing GCMPH[1:0] with 0x3. Do not change the other configurations written during GCM initialization.
  2. 14. Write the final GCM block into the AES_DINR register. It is the concatenated AAD bit and payload bit lengths, as shown in Table 186 .
  3. 15. Wait until the CCF flag in the AES_ISR register is set.
  4. 16. Get the GCM authentication tag, by reading the AES_DOUTR register four times.
  5. 17. Clear the CCF flag, by setting the CCF bit of the AES_ICR register.
  6. 18. Disable the AES peripheral, by clearing EN. If it is an authenticated decryption, compare the generated tag with the expected tag passed with the message.

Note: In the final phase, data are written to AES_DINR normally (no swapping), while swapping is applied to tag data read from AES_DOUTR.

When transiting from the header or the payload phase to the final phase, the AES peripheral must not be disabled, otherwise the result is wrong.

Suspend/resume operations in GCM mode

The suspend and resume operations are only supported when AES is used in CPU mode, not in DMA mode.

To suspend the processing of a message , proceed as follows:

  1. 1. Wait until the CCF flag in the AES_ISR register is set (computation completed).
  2. 2. In the payload phase, read four times the AES_DOUTR register to save the last-processed block.
  3. 3. Clear the CCF flag of the AES_ISR register, by setting the CCF bit of the AES_ICR register. When GCM encryption payload phase is selected, verify that BUSY is cleared in AES_SR, to ensure that GF2mul hash function is completed.
  4. 4. Save the AES_SUSPRx registers in the memory.
  5. 5. In the payload phase, save the AES_IVRx registers as, during the data processing, they changed from their initial values. In the header phase, this step is not required.
  6. 6. Disable the AES peripheral, by clearing EN.
  7. 7. Save the current AES_CR configuration in the memory. Key registers do not need to be saved as the original key value is known by the application.

To resume the processing of a message, proceed as follows:

  1. 1. Disable the AES peripheral, by clearing EN.
  2. 2. Write the suspend register values, previously saved in the memory, back into their corresponding AES_SUSPRx registers.
  3. 3. In the payload phase, write the initialization vector register values, previously saved in the memory, back into their corresponding AES_IVRx registers. In the header phase, write initial setting values back into the AES_IVRx registers.
  4. 4. Restore the initial setting values in the AES_CR and AES_KEYRx registers if KMOD[1:0] is at 0x0. If KMOD[1:0] is at 0x2, the key is transferred from the SAES peripheral (see Section 25.4.14 ).
  5. 5. Enable the AES peripheral, by setting EN.

25.4.12 AES Galois message authentication code (GMAC)

The Galois message authentication code (GMAC) allows the authentication of a plaintext, generating the corresponding tag information (also known as message authentication code).

GMAC is similar to GCM, except that it is applied on a message composed only by plaintext authenticated data (that is, only header, no payload). The following figure shows typical message construction for GMAC.

Figure 125. Message construction in GMAC mode

Diagram of GMAC message construction. It shows an ICB block (split into IV and Counter) and an Authenticated data block (split into 16-byte segments). The end of the authenticated data is followed by a zero-padded 'Last block' and a final block containing [Len(A)]64 and [0]64. An arrow labeled 'auth.' points from the authenticated data to a box labeled 'Authentication tag (T)'.

The diagram illustrates the message construction for GMAC. It shows the following components:

Diagram of GMAC message construction. It shows an ICB block (split into IV and Counter) and an Authenticated data block (split into 16-byte segments). The end of the authenticated data is followed by a zero-padded 'Last block' and a final block containing [Len(A)]64 and [0]64. An arrow labeled 'auth.' points from the authenticated data to a box labeled 'Authentication tag (T)'.

For more details, refer to NIST Special Publication 800-38D, Recommendation for Block Cipher Modes of Operation - Galois/Counter Mode (GCM) and GMAC .

Figure 126 describes the GMAC chaining implementation in the AES peripheral. To select this chaining mode, write CHMOD[2:0] with 0x3.

Figure 126. GMAC authentication mode

Diagram of GMAC authentication mode showing stages (1) Init, (2) Header, and (4) Final. Stage (3) is omitted. The diagram shows data flow through Encrypt, Swap management, GF2mul, and XOR blocks to produce an authentication tag T.

The diagram illustrates the GMAC authentication mode in three active stages:

Legend:

MSv69569V1

Diagram of GMAC authentication mode showing stages (1) Init, (2) Header, and (4) Final. Stage (3) is omitted. The diagram shows data flow through Encrypt, Swap management, GF2mul, and XOR blocks to produce an authentication tag T.

The GMAC algorithm corresponds to the GCM algorithm applied on a message that only contains a header. As a consequence, all steps and settings are the same as with the GCM, except that the payload phase is omitted.

Suspend/resume operations in GMAC

In GMAC mode, the sequence described for the GCM applies except that only the header phase can be interrupted.

25.4.13 AES counter with CBC-MAC (CCM)

The AES counter with cipher block chaining-message authentication code (CCM) algorithm allows encryption and authentication of plaintext, generating the corresponding ciphertext and tag (also known as message authentication code). To ensure confidentiality, the CCM algorithm is based on AES counter mode processing. It uses cipher block chaining technique to generate the message authentication code. This is commonly called CBC-MAC.

Note: NIST does not approve CBC-MAC as an authentication mode outside the context of the CCM specification.

The following figure shows typical message construction for CCM.

Figure 127. Message construction in CCM mode

Diagram illustrating the message construction in CCM mode. The diagram shows the structure of the message blocks: B0 (flags, Nonce (N), Q), Associated data (A), Plaintext (P), and Encrypted MAC (T). B0 is a 16-byte block where the first octet contains flags and the remaining 15 bytes are the Nonce (N) and Q. The length of the Nonce (N) is Len(N). The length of the Associated data (A) is Len(A). The length of the Plaintext (P) is Len(P). The length of the Encrypted MAC (T) is Len(T). The total length of the ciphertext (C) is Len(C). The diagram also shows the authentication and encryption process: the B0 block is used to generate the MAC (T) via an 'authenticate' function. The Plaintext (P) is encrypted to produce the ciphertext (C) via an 'encrypt' function. The MAC (T) is then decrypted and compared with the ciphertext (C) via a 'Decrypt and compare' function. Zero padding is indicated for the end of the message.
Diagram illustrating the message construction in CCM mode. The diagram shows the structure of the message blocks: B0 (flags, Nonce (N), Q), Associated data (A), Plaintext (P), and Encrypted MAC (T). B0 is a 16-byte block where the first octet contains flags and the remaining 15 bytes are the Nonce (N) and Q. The length of the Nonce (N) is Len(N). The length of the Associated data (A) is Len(A). The length of the Plaintext (P) is Len(P). The length of the Encrypted MAC (T) is Len(T). The total length of the ciphertext (C) is Len(C). The diagram also shows the authentication and encryption process: the B0 block is used to generate the MAC (T) via an 'authenticate' function. The Plaintext (P) is encrypted to produce the ciphertext (C) via an 'encrypt' function. The MAC (T) is then decrypted and compared with the ciphertext (C) via a 'Decrypt and compare' function. Zero padding is indicated for the end of the message.

The structure of the message is:

When a part of the message (A or P) has a length that is a non-multiple of 16-bytes, a special padding scheme is required.

Note: CCM chaining mode can also be used with associated data only (that is, no payload).

As an example, the C.1 section in NIST Special Publication 800-38C gives the following values (hexadecimal numbers):

For more details, refer to NIST Special Publication 800-38C, Recommendation for Block Cipher Modes of Operation - The CCM Mode for Authentication and Confidentiality .

Figure 128 describes the CCM chaining implementation in the AES peripheral (encryption). To select this chaining mode, write CHMOD[2:0] with 0x4.

Figure 128. CCM mode authenticated encryption

A detailed block diagram of CCM mode authenticated encryption. The diagram is divided into four main sections: (1) Init, (2) Header, (3) Payload, and (4) Final. Section (1) shows the initialization of the counter (CTR0) and the first block (B0). Section (2) shows the processing of associated data (Header) blocks B1 through Bu. Section (3) shows the processing of payload blocks P1 through Pm, with Block 1 and Block m specifically detailed. Section (4) shows the finalization step to produce the MAC (T) and EncTAG. The diagram uses various blocks like 'Encrypt', 'Swap management', and 'XOR' to show the data flow. A legend at the bottom left defines input, output, and XOR symbols. The diagram is labeled MSv69570V1.
A detailed block diagram of CCM mode authenticated encryption. The diagram is divided into four main sections: (1) Init, (2) Header, (3) Payload, and (4) Final. Section (1) shows the initialization of the counter (CTR0) and the first block (B0). Section (2) shows the processing of associated data (Header) blocks B1 through Bu. Section (3) shows the processing of payload blocks P1 through Pm, with Block 1 and Block m specifically detailed. Section (4) shows the finalization step to produce the MAC (T) and EncTAG. The diagram uses various blocks like 'Encrypt', 'Swap management', and 'XOR' to show the data flow. A legend at the bottom left defines input, output, and XOR symbols. The diagram is labeled MSv69570V1.

The first block of a CCM message (B0) must be prepared by the application as defined in Table 187.

Table 187. Initialization of IV registers in CCM mode
AES_IVR3[31:0]AES_IVR2[31:0]AES_IVR1[31:0]AES_IVR0[31:0]
B0[127:96] (1)B0[95:64]B0[63:32]B0[31:0] (2)
  1. 1. The five most significant bits are cleared (flag bits).
  2. 2. Q length bits are cleared, except for the bit 0 that is set.

AES supports counters up to 64 bits, as specified by NIST.

CCM encryption and decryption process

This process is described in Section 25.4.6 , with the following sequence of events:

CCM initialize

  1. 1. Disable the AES peripheral, by clearing EN.
  2. 2. Initialize the AES_CR register:
    • – Select CCM chaining mode (write CHMOD[2:0] with 0x4) in encryption or decryption mode (write MODE[1:0] with 0x0 or 0x2). Do not write MODE[1:0] with 0x1.
    • – Configure the data type, through DATATYPE[1:0]
    • – Configure the key size, through KEYSIZE.
    • – Select the key mode, using KMOD[1:0]. If the key comes from the SAES peripheral, write KMOD[1:0] with 0x2, otherwise keep it at 0x0.
    • – Select the CCM initialization phase, by writing GCMPH[1:0] with 0x0.
  3. 3. Write the B0 data in AES_IVRx registers according to Table 187 .
  4. 4. Write the key into the AES_KEYRx registers if KMOD[1:0] is at 0x0. If KMOD[1:0] is at 0x2, the key is transferred from the SAES peripheral (see Section 25.4.14 ).
  5. 5. Wait until KEYVALID is set (the key loading completed).
  6. 6. Set EN to start the first mask calculation. The EN bit is automatically cleared when the calculation is completed.
  7. 7. Wait until the CCF flag in the AES_ISR register is set.
  8. 8. Clear the CCF flag, by setting the CCF bit of the AES_ICR register.

CCM header phase

  1. 9. Initialize header phase:
    1. a) Prepare the first block of the (B1) data associated with the message, in accordance with CCM chaining rules.
    2. b) Select the CCM header phase, by writing GCMPH[1:0] with 0x1. Do not change the other configurations written during the CCM initialization.
    3. c) Enable the AES peripheral, by setting EN.
  2. 10. Append header data:
    1. a) If it is the last block and the associated data in the block is smaller than 16 bytes, pad the remainder of the block with zeros.
    2. b) Append the data block into AES as described in Section 25.4.5 .
    3. c) Repeat the step b) until the second-last associated data block is processed. For the last block, follow the steps a) and b) .

Note: This phase can be skipped if there is no associated data, that is, \( Len(A) = 0 \) . No data are read during the header phase.

CCM payload phase

  1. 11. Initialize payload phase:
    1. a) Select the CCM payload phase, by writing GCMPH[1:0] with 0x2. Do not change the other configurations written during the CCM initialization.
    2. b) If the header phase is skipped, enable the AES peripheral, by setting EN.
  2. 12. Append payload data:
    1. a) In encryption only, if it is the last block and the plaintext in the block is smaller than 16 bytes, pad the remainder of the block with zeros.
    2. b) Append the data block into AES as described in Section 25.4.5 , then read the AES_DOUTR register four times to save the resulting block.
    3. c) Repeat the step b) until the second-last plaintext block is encrypted or until the last block of ciphertext is decrypted. For the last block of plaintext (encryption only), follow the steps a) and b). For the last block, discard the bits that are not part of the payload when the last block is smaller than 16 bytes.

Note: This phase can be skipped if there is no payload, that is, \( Len(P) = 0 \) or \( Len(C) = Len(T) \) . Remove \( LSB_{Len(T)}(C) \) encrypted tag information when decrypting ciphertext C.

CCM finalization

  1. 13. Select the CCM final phase, by writing GCMPH[1:0] with 0x3. Do not change the other configurations written during the CCM initialization.
  2. 14. Wait until CCF flag in the AES_ISR register is set.
  3. 15. Get the CCM authentication tag, by reading the AES_DOUTR register four times.
  4. 16. Clear the CCF flag, by setting the CCF bit of the AES_ICR register.
  5. 17. Disable the AES peripheral, by clearing EN. If it is an authenticated decryption, compare the generated tag with the expected tag passed with the message. Mask the authentication tag output with tag length to obtain a valid tag.

Note: In the final phase, swapping is applied to tag data read from AES_DOUTR register. When transiting from the header or the payload phase to the final phase, the AES peripheral must not be disabled, otherwise the result is wrong.

Suspend and resume operations in CCM mode

The suspend and resume operations are only supported when AES is used in CPU mode, not in DMA mode.

To suspend the processing of a message in header or payload phase , proceed as follows:

  1. 1. Wait until the CCF flag of the AES_ISR register is set (computation completed).
  2. 2. In the payload phase, read four times the AES_DOUTR register to save the last-processed block.
  3. 3. Clear the CCF flag in the AES_ISR register, by setting the CCF bit of the AES_ICR register.
  4. 4. Save the AES_SUSPRx registers in the memory.
  5. 5. Save the IV registers as they are altered during the data processing.
  6. 6. Disable the AES peripheral, by clearing EN.
  1. 7. Save the current AES_CR configuration in the memory. Key registers do not need to be saved as the original key value is known by the application.

To resume the processing of a message , proceed as follows:

  1. 1. Disable the AES peripheral, by clearing EN.
  2. 2. Write the suspend register values, previously saved in the memory, back into their corresponding AES_SUSPRx registers.
  3. 3. Restore AES_IVRx registers using the saved configuration.
  4. 4. Restore the initial setting values in the AES_CR and AES_KEYRx registers if KMOD[1:0] is at 0x0. If KMOD[1:0] is at 0x2, the key must be transferred again from the SAES peripheral (see Section 25.4.14 ).
  5. 5. Enable the AES peripheral, by setting EN.

25.4.14 AES key sharing with secure AES co-processor

The AES peripheral can use the SAES peripheral as security co-processor. The secure application prepares the key in the robust SAES peripheral and when it is ready, the AES application can load this prepared key through a dedicated hardware key bus.

The recommended sequence is described hereafter and in the section SAES operations with shared keys in the SAES section of this document.

  1. 1. In SAES peripheral, the application encrypts (wraps) the key to share in Shared-key mode (KMOD[1:0] at 0x2).
  2. 2. Each time the shared key is required in AES peripheral, the application decrypts it in the SAES peripheral in Shared-key mode (KMOD[1:0] at 0x2).
  3. 3. Once the shared key is decrypted (unwrapped) and loaded in SAES_KEYRx registers it can be shared with AES. To load the shared key in AES, the application sets KEYSIZE as appropriate and writes KMOD[1:0] with 0x2. When KEYVALID is cleared, the key is automatically transferred by hardware into the AES_KEYRx registers and the BUSY flag in the AES_SR register set.
  4. 4. Once the key transfer is completed, the BUSY flag is cleared and the KEYVALID flag set in the AES_SR register. If KEYVALID is not set when BUSY bit is cleared, or if the KEIF flag is set in the AES_ISR register, either the KEYSIZE value is incorrect or an unexpected event occurred during the transfer (such as DPA error, tamper event or KEYVALID cleared before the end of the transfer). When such errors occur, reset both peripherals through their IPRST bits and restart the whole key sharing process.

When the key sharing sequence is completed, the AES is initialized with a valid, shared key. The application can then process data in normal key mode, by writing KMOD[1:0] with 0x0.

Note: This sequence in AES peripheral can be run multiple times (for example, to manage a suspend/resume situation), as long as SAES peripheral is unused and duly remains in key sharing state.

25.4.15 AES data registers and data swapping

Data input and output

A 16-byte data block enters the AES peripheral with four successive 32-bit word writes into the AES_DINR register (bitfield DIN[31:0]), the most significant word (bits [127:96]) first, the least significant word (bits [31:0]) last.

A 16-byte data block is retrieved from the AES peripheral with four successive 32-bit word reads of the AES_DOUTR register (bitfield DOUT[31:0]), the most significant word (bits [127:96]) first, the least significant word (bits [31:0]) last.

The four 32-bit words of a 16-byte data block must be stored in the memory consecutively and in big-endian order, that is, with the most significant word on the lowest address. See Table 188 “no swapping” option for details.

Data swapping

The AES peripheral can be configured to perform a bit-, a byte-, a half-word-, or no swapping on the input data word in the AES_DINR register, before loading it to the AES processing core, and on the data output from the AES processing core, before sending it to the AES_DOUTR register. The choice depends on the type of data. For example, a byte swapping is used for an ASCII text stream.

The data swap type is selected through DATATYPE[1:0]. The selection applies to both AES input and output.

Note: The data in AES key registers (AES_KEYRx) and initialization vector registers (AES_IVRx) are not sensitive to the swap mode selection.

The AES data swapping feature is summarized in Table 188 and Figure 129 .

Table 188. AES data swapping example

DATATYPE[1:0]Swapping performedData block
System memory data (big-endian)
0x0No swappingBlock[127..64]: 0x04EEF672 2E04CE96
Block[63..0]: 0x4E6F7720 69732074
Address @, word[127..96]: 0x04EEF672
Address @ + 0x4, word[95..64]: 0x2E04CE96
Address @ + 0x8, word[63..32]: 0x4E6F7720
Address @ + 0xC, word[31..0]: 0x69732074
0x1Half-word (16-bit) swappingBlock[63..0]: 0x 4E6F 7720 6973 2074
Address @, word[63..32]: 0x7720 4E6F
Address @ + 0x4, word[31..0]: 0x2074 6973
0x2Byte (8-bit) swappingBlock[63..0]: 0x 4E 6F 77 20 69 73 20 74
Address @, word[63..32]: 0x2077 6F4E
Address @ + 0x4, word[31..0]: 0x74 20 73 69

Table 188. AES data swapping example (continued)

DATATYPE[1:0]Swapping performedData block
System memory data (big-endian)
0x3Bit swappingBlock[63..32]: 0x4E6F7720
0100 1110 0110 1111 0111 0111 0010 0000
Block[31..0]: 0x69732074
0110 1001 0111 0011 0010 0000 0111 0100
Address @, word[63..32]: 0x04EE F672
0000 0100 1110 1110 1111 0110 0111 0010
Address @ + 0x4, word[31..0]: 0x2E04 CE96
0010 1110 0000 0100 1100 1110 1001 0110

Figure 129. 128-bit block construction according to the data type

Diagram showing no swapping: 128-bit block is divided into Word 3 (D127-D96), Word 2 (D95-D64), Word 1 (D63-D32), and Word 0 (D31-D0). Data is written/read in order 1 to 4 (Word 3 to Word 0) without any internal rearrangement of bits. Diagram showing 16-bit swapping: Each 32-bit word is split into two 16-bit halves. For Word 3, bits D127..D112 and D111..D96 are swapped. This pattern repeats for Word 2, Word 1, and Word 0. The output register reflects these swapped halves. Diagram showing 8-bit byte swapping: Each 32-bit word is split into four bytes. For Word 3, the bytes (D127..120, D119..112, D111..104, D103..96) are reversed in order within the word. This byte-reversal occurs for all four words. Diagram showing bit swapping: Within each 32-bit word, the bit order is completely reversed. For Word 3, D127 swaps with D96, D126 with D97, and so on. This bit-level reversal is applied to all four words.

DATATYPE[1:0] = 00: no swapping

DATATYPE[1:0] = 01: 16-bit (half-word) swapping

DATATYPE[1:0] = 10: 8-bit (byte) swapping

DATATYPE[1:0] = 11: bit swapping

Legend:

MSV66122V1

Diagram showing no swapping: 128-bit block is divided into Word 3 (D127-D96), Word 2 (D95-D64), Word 1 (D63-D32), and Word 0 (D31-D0). Data is written/read in order 1 to 4 (Word 3 to Word 0) without any internal rearrangement of bits. Diagram showing 16-bit swapping: Each 32-bit word is split into two 16-bit halves. For Word 3, bits D127..D112 and D111..D96 are swapped. This pattern repeats for Word 2, Word 1, and Word 0. The output register reflects these swapped halves. Diagram showing 8-bit byte swapping: Each 32-bit word is split into four bytes. For Word 3, the bytes (D127..120, D119..112, D111..104, D103..96) are reversed in order within the word. This byte-reversal occurs for all four words. Diagram showing bit swapping: Within each 32-bit word, the bit order is completely reversed. For Word 3, D127 swaps with D96, D126 with D97, and so on. This bit-level reversal is applied to all four words.

Data padding

Figure 129 also gives an example of memory data block padding with zeros such that the zeroed bits after the data swap form a contiguous zone at the MSB end of the AES core input buffer. The example shows the padding of an input data block containing:

25.4.16 AES key registers

The eight AES_KEYRx write-only registers store the encryption or decryption key information, as shown on Table 189. Reads are not allowed for security reason.

Note: In memory and in AES key registers, keys are stored in little-endian format, with most significant byte on the highest address.

Table 189. Key endianness in AES_KEYRx registers (128/256-bit keys)

AES_KEYR7
[31:0]
AES_KEYR6
[31:0]
AES_KEYR5
[31:0]
AES_KEYR4
[31:0]
AES_KEYR3
[31:0]
AES_KEYR2
[31:0]
AES_KEYR1
[31:0]
AES_KEYR0
[31:0]
----KEY[127:96]KEY[95:64]KEY[63:32]KEY[31:0]
KEY[255:224]KEY[223:192]KEY[191:160]KEY[159:128]KEY[127:96]KEY[95:64]KEY[63:32]KEY[31:0]

The key registers are not affected by the data swapping feature controlled by the DATATYPE[1:0] bitfield.

Write operations to the AES_KEYRx registers are ignored when AES peripheral is enabled (EN bit set). The application must check this before modifying key registers.

The entire key must be written before starting an AES computation.

In normal key mode (KMOD[1:0] at 0x0), the key registers must always be written in either ascending or descending order. The write sequence becomes:

Note: KEYSIZE must be written before the key.

As soon as the first key register is written, the KEYVALID flag is cleared. Once the key registers writing sequence is completed, KEYVALID is set and EN becomes writable. If an error occurs, KEYVALID is cleared and KEIF set (see Section 25.4.18).

25.4.17 AES initialization vector registers

The four AES_IVRx registers store the initialization vector (IV) information, as shown in Table 190. They can only be written if the AES peripheral is disabled (EN cleared).

Note: In memory and in AES IV registers, initialization vectors are stored in little-endian format, with most significant byte on the highest address.

Table 190. IVI bitfield spread over AES_IVRx registers

AES_IVR3[31:0]AES_IVR2[31:0]AES_IVR1[31:0]AES_IVR0[31:0]
IVI[127:96]IVI[95:64]IVI[63:32]IVI[31:0]

Initialization vector information depends on the chaining mode selected. When used, AES_IVRx registers are updated upon each AES computation cycle (useful for managing suspend mode).

The initialization vector registers are not affected by the data swapping feature controlled through DATATYPE[1:0].

25.4.18 AES error management

The AES peripheral manages the errors described in this section.

Read error flag (RDERRF)

Unexpected read attempt of the AES_DOUTR register returns zero, setting the RDERRF flag and the RWEIF flag. RDERRF is triggered during the computation phase or during the input phase.

Note: AES is not disabled when RDERRF rises and it continues processing.

An interrupt is generated if the RWEIE bit is set. For more details, refer to Section 25.5: AES interrupts .

The RDERRF and RWEIF flags are cleared by setting the RWEIF bit of the AES_ICR register.

Write error flag (WRERRF)

Unexpected write attempt of the AES_DINR register is ignored, setting the WRERRF and the RWEIF flags. WRERRF is triggered during the computation phase or during the output phase.

Note: AES is not disabled when WRERRF rises and it continues processing.

An interrupt is generated if the RWEIE bit is set. For more details, refer to Section 25.5: AES interrupts .

The WRERRF and RWEIF flags are cleared by setting the RWEIF bit of the AES_ICR register.

Key error interrupt flag (KEIF)

There are multiple sources of errors that set the KEIF flag of the AES_ISR register and clear the KEYVALID bit of the AES_SR register:

The KEIF flag is cleared with corresponding bit of the AES_ICR register. An interrupt is generated if the KEIE bit of the AES_IER register is set. For more details, refer to Section 25.5: AES interrupts .

Upon a key sharing error, reset both AES and SAES peripherals through the IPRST bit of their corresponding control register, then restart the key sharing sequence.

Note: For any key error, clear KEIF flag prior to disabling and re-configuring AES.

25.5 AES interrupts

There are multiple individual maskable interrupt sources generated by the AES peripheral to signal the following events:

See Section 25.4.18: AES error management for details on AES errors.

These sources are combined into a common interrupt signal from the AES peripheral that connects to the Cortex® CPU interrupt controller. Application can enable or disable AES interrupt sources individually by setting/clearing the corresponding enable bit of the AES_IER register.

The status of the individual maskable interrupt sources can be read from the AES_ISR register. They are cleared by setting the corresponding bit of the AES_ICR register.

Table 191 gives a summary of the available features.

Table 191. AES interrupt requests

Interrupt acronymInterrupt eventEvent flagEnable bitInterrupt clear method
AEScomputation completed flagCCFCCFIEset CCF (1)
read error flagRDERRF (2)RWEIEset RWEIF (1)
write error flagWRERRF (2)
key error flagKEIFKEIEset KEIF (1)

1. Bit of the AES_ICR register.

2. Flag of the AES_SR register, mirrored by the flag RWEIF of the AES_ISR register.

25.6 AES DMA requests

The AES peripheral provides an interface to connect to the DMA (direct memory access) controller. The DMA operation is controlled through the DMAINEN and DMAOUTEN bits of the AES_CR register. When key derivation is selected (MODE[1:0] is at 0x1), setting those bits has no effect.

AES only supports single DMA requests.

Suspend and resume operations are not supported in DMA mode.

Detailed usage of DMA with AES can be found in Appending data using DMA subsection of Section 25.4.5: AES encryption or decryption typical usage .

Data input using DMA

Setting DMAINEN enables DMA writing into AES. AES then initiates, during the input phase, a set of single DMA requests for each 16-byte data block to write to the AES_DINR register (quadruple 32-bit word, MSB first).

Note: According to the algorithm and the mode selected, special padding / ciphertext stealing might be required (see Section 25.4.7 ).

Data output using DMA

Setting DMAOUTEN enables DMA reading from AES. AES then initiates, during the output phase, a set of single DMA requests for each 16-byte data block to read from the AES_DOUTR register (quadruple 32-bit word, MSB first).

After the output phase, at the end of processing of a 16-byte data block, AES switches automatically to a new input phase for the next data block, if any.

In DMA mode, the CCF flag has no use because the reading of the AES_DOUTR register is managed by DMA automatically at the end of the computation phase. The CCF flag must only be cleared when transiting back to managing the data transfers by software.

Note: According to the message size, extra bytes might need to be discarded by application in the last block.

Stopping DMA transfers

All DMA request signals are de-asserted when AES is disabled (EN cleared) or the DMA enable bit (DMAINEN for input data, DMAOUTEN for output data) is cleared.

25.7 AES processing latency

The following tables provide the 16-byte data block processing latency per operating mode.

Table 192. Processing latency for ECB, CBC and CTR

Key sizeMode of operationChaining algorithmClock cycles
128-bitEncryption or decryption (1)ECB, CBC, CTR51
Key preparation-59
256-bitEncryption or decryption (1)ECB, CBC, CTR75
Key preparation-82

1. Excluding key preparation time (ECB and CBC only).

Table 193. Processing latency for GCM and CCM (in clock cycles)
Key sizeMode of operationChaining algorithmInitialization phaseHeader phase (1)Payload phase (1)Final phase (1)
128-bitEncryption/
Decryption
GCM64355159
CCM635511458
256-bitEncryption/
Decryption
GCM88357575
CCM877916282

1. Data insertion can include wait states forced by AES on the AHB bus (maximum 3 cycles, typical 1 cycle).

25.8 AES registers

The registers are accessible through 32-bit word single accesses only. Other access types generate an AHB error, and other than 32-bit writes may corrupt the register content.

25.8.1 AES control register (AES_CR)

Address offset: 0x000

Reset value: 0x0000 0000

31302928272625242322212019181716
IPRSTRes.Res.Res.Res.Res.KMOD[1:0]NPBLB[3:0]Res.KEYSIZERes.CHMOD[2]
rwrwrwrwrwrwrwrwrw

1514131211109876543210
Res.GCM[1:0]DMAOUTENDMAINENRes.Res.Res.Res.CHMOD[1:0]MODE[1:0]DATATYPE[1:0]EN
rwrwrwrwrwrwrwrwrwrwrw

Bit 31 IPRST : AES peripheral software reset

Setting the bit resets the AES peripheral, putting all registers to their default values, except the IPRST bit itself. Hence, any key-relative data are lost. For this reason, it is recommended to set the bit before handing over the AES to a less secure application.

The bit must be kept low while writing any configuration registers.

Bits 30:26 Reserved, must be kept at reset value.

Bits 25:24 KMOD[1:0] : Key mode selection

The bitfield defines how the AES key can be used by the application. KEYSIZE must be correctly initialized when setting KMOD[1:0] different from zero.

0x0: Normal key mode. Key registers are freely usable.

0x2: Shared key mode. If shared key mode is properly initialized in SAES peripheral, the AES peripheral automatically loads its key registers with the data stored in the SAES key registers. The key value is available in AES key registers when BUSY bit is cleared and KEYVALID is set in the AES_SR register. Key error flag KEIF is set otherwise in the AES_ISR register.

Others: Reserved

Attempts to write the bitfield are ignored when BUSY is set, as well as when EN is set before the write access and it is not cleared by that write access.

Bits 23:20 NPBLB[3:0] : Number of padding bytes in last block

This padding information must be filled by software before processing the last block of GCM payload encryption or CCM payload decryption, otherwise authentication tag computation is incorrect.

0x0: All bytes are valid (no padding)

0x1: Padding for the last LSB byte

...

0xF: Padding for the 15 LSB bytes of last block.

Bit 19 Reserved, must be kept at reset value.

Bit 18 KEYSIZE : Key size selection

This bitfield defines the key length in bits of the key used by AES.

0: 128-bit

1: 256-bit

Attempts to write the bit are ignored when BUSY is set, as well as when the EN is set before the write access and it is not cleared by that write access.

Bit 17 Reserved, must be kept at reset value.

Bit 15 Reserved, must be kept at reset value.

Bits 14:13 GCMPH[1:0] : GCM or CCM phase selection

This bitfield selects the phase, applicable only with GCM, GMAC or CCM chaining modes.

0x0: Initialization phase

0x1: Header phase

0x2: Payload phase

0x3: Final phase

Bit 12 DMAOUTEN : DMA output enable

This bit enables automatic generation of DMA requests during the data phase, for outgoing data transfers from AES via DMA.

0: Disable

1: Enable

Setting this bit is ignored when MODE[1:0] is at 0x1 (key derivation).

Bit 11 DMAINEN : DMA input enable

This bit enables automatic generation of DMA requests during the data phase, for incoming data transfers to AES via DMA.

0: Disable

1: Enable

Setting this bit is ignored when MODE[1:0] is at 0x1 (key derivation).

Bits 10:7 Reserved, must be kept at reset value.

Bits 16, 6:5 CHMOD[2:0] : Chaining mode

This bitfield selects the AES chaining mode:

0x0: Electronic codebook (ECB)

0x1: Cipher-block chaining (CBC)

0x2: Counter mode (CTR)

0x3: Galois counter mode (GCM) and Galois message authentication code (GMAC)

0x4: Counter with CBC-MAC (CCM)

others: Reserved

Attempts to write the bitfield are ignored when BUSY is set, as well as when EN is set before the write access and it is not cleared by that write access.

Bits 4:3 MODE[1:0] : Operating mode

This bitfield selects the AES operating mode:

0x0: Encryption

0x1: Key derivation (or key preparation), for ECB/CBC decryption only

0x2: Decryption

0x3: Reserved

Attempts to write the bitfield are ignored when BUSY is set, as well as when EN is set before the write access and it is not cleared by that write access.

Bits 2:1 DATATYPE[1:0] : Data type

This bitfield defines the format of data written in the AES_DINR register or read from the AES_DOUTR register, through selecting the mode of data swapping. This swapping is defined in Section 25.4.15: AES data registers and data swapping .

0x0: No swapping (32-bit data).

0x1: Half-word swapping (16-bit data)

0x2: Byte swapping (8-bit data)

0x3: Bit-level swapping

Attempts to write the bitfield are ignored when BUSY is set, as well as when EN is set before the write access and it is not cleared by that write access.

Bit 0 EN : Enable

This bit enables/disables the AES peripheral.

0: Disable

1: Enable

At any moment, clearing then setting the bit re-initializes the AES peripheral. When KMOD[1:0] is different from 0x0, using IPRST bit is recommended instead.

This bit is automatically cleared by hardware upon the completion of the key preparation (MODE[1:0] at 0x1) and upon the completion of GCM/GMAC/CCM initialization phase.

25.8.2 AES status register (AES_SR)

Address offset: 0x004

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.KEYVALIDRes.Res.Res.BUSYWRERRFRDERRFRes.
rrrr

Bits 31:8 Reserved, must be kept at reset value.

Bit 7 KEYVALID : Key valid flag

This bit is set by hardware when the key of size defined by KEYSIZE is loaded in AES_KEYRx key registers.

0: Key not valid

1: Key valid

The EN bit can only be set when KEYVALID is set.

In normal mode when KMOD[1:0] is at zero, the key must be written in the key registers in the correct sequence, otherwise the KEIF flag is set and KEYVALID remains cleared.

When KMOD[1:0] is different from zero, the BUSY flag is automatically set by AES. When the key is loaded successfully, BUSY is cleared and KEYVALID set. Upon an error, KEIF is usually set, BUSY cleared and KEYVALID remains cleared.

If set, KEIF must be cleared through the AES_ICR register, otherwise KEYVALID cannot be set. See the KEIF flag description for more details.

For further information on key loading, refer to Section 25.4.16: AES key registers .

Bits 6:4 Reserved, must be kept at reset value.

Bit 3 BUSY : Busy

This flag indicates whether AES is idle or busy.

0: Idle

1: Busy

AES is flagged as idle when disabled (when EN is low) or when the last processing is completed.

AES is flagged as busy when processing a block data, preparing a key (ECB or CBC decryption only), or transferring a shared key from the SAES peripheral.

When GCM encryption payload phase is selected, this flag must be at zero before suspending current process to manage a higher-priority message.

Bit 2 WRERRF : Write error flag

This bit is set when an unexpected write to the AES_DINR register occurred. When set WRERRF bit has no impact on the AES operations.

0: No error

1: Unexpected write to AES_DINR register occurred during computation or data output phase.

The flag setting generates an interrupt if the RWEIE bit of the AES_IER register is set.

The flag is cleared by setting the RWEIF bit of the AES_ICR register.

Bit 1 RDERRF : Read error flag

This bit is set when an unexpected read to the AES_DOUTR register occurred. When set RDERRF bit has no impact on the AES operations.

0: No error

1: Unexpected read to AES_DOUTR register occurred during computation or data input phase.

The flag setting generates an interrupt if the RWEIE bit of the AES_IER register is set.

The flag is cleared by setting the RWEIF bit of the AES_ICR register.

Bit 0 Reserved, must be kept at reset value.

25.8.3 AES data input register (AES_DINR)

Address offset: 0x008

Reset value: 0x0000 0000

31302928272625242322212019181716
DIN[31:16]
wwwwwwwwwwwwwwww
1514131211109876543210
DIN[15:0]
wwwwwwwwwwwwwwww

Bits 31:0 DIN[31:0] : Data input

A four-fold sequential write to this bitfield during the Input phase results in writing a complete 16-bytes block of input data to the AES peripheral. From the first to the fourth write, the corresponding data weights are [127:96], [95:64], [63:32], and [31:0]. Upon each write, the data from the 32-bit input buffer are handled by the data swap block according to the DATATYPE[1:0] bitfield, then written into the AES core 16-bytes input buffer.

Reads return zero.

25.8.4 AES data output register (AES_DOUTR)

Address offset: 0x00C

Reset value: 0x0000 0000

31302928272625242322212019181716
DOUT[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
DOUT[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 DOUT[31:0] : Data output

This read-only bitfield fetches a 32-bit output buffer. A four-fold sequential read of this bitfield, upon the computation completion (CCF flag set), virtually reads a complete 16-byte block of output data from the AES peripheral. Before reaching the output buffer, the data produced by the AES core are handled by the data swap block according to the DATATYPE[1:0] bitfield.

Data weights from the first to the fourth read operation are: [127:96], [95:64], [63:32], and [31:0].

25.8.5 AES key register 0 (AES_KEYR0)

Address offset: 0x010

Reset value: 0x0000 0000

31302928272625242322212019181716
KEY[31:16]
wwwwwwwwwwwwwwww
1514131211109876543210
KEY[15:0]
wwwwwwwwwwwwwwww

Bits 31:0 KEY[31:0] : Cryptographic key, bits [31:0]

These are bits [31:0] of the write-only bitfield KEY[255:0] AES encryption or decryption key, depending on the MODE[1:0] bitfield of the AES_CR register.

Writes to AES_KEYRx registers are ignored when AES is enabled (EN bit set). When the key comes from the SAES peripheral (KMOD[1:0] at 0x2), writes to key registers are also ignored and they result in setting the KEIF bit of the AES_ISR register.

With KMOD[1:0] at 0x0, a special writing sequence is required. In this sequence, any valid write to AES_KEYRx register clears the KEYVALID flag except for the sequence-completing write that sets it. Also refer to the description of the KEYVALID flag in the AES_SR register.

25.8.6 AES key register 1 (AES_KEYR1)

Address offset: 0x014

Reset value: 0x0000 0000

31302928272625242322212019181716
KEY[63:48]
wwwwwwwwwwwwwwww
1514131211109876543210
KEY[47:32]
wwwwwwwwwwwwwwww

Bits 31:0 KEY[63:32] : Cryptographic key, bits [63:32]

Refer to the AES_KEYR0 register for description of the KEY[255:0] bitfield and for information relative to writing AES_KEYRx registers.

25.8.7 AES key register 2 (AES_KEYR2)

Address offset: 0x018

Reset value: 0x0000 0000

31302928272625242322212019181716
KEY[95:80]
wwwwwwwwwwwwwwww
1514131211109876543210
KEY[79:64]
wwwwwwwwwwwwwwww

Bits 31:0 KEY[95:64] : Cryptographic key, bits [95:64]

Refer to the AES_KEYR0 register for description of the KEY[255:0] bitfield and for information relative to writing AES_KEYRx registers.

25.8.8 AES key register 3 (AES_KEYR3)

Address offset: 0x01C

Reset value: 0x0000 0000

31302928272625242322212019181716
KEY[127:112]
wwwwwwwwwwwwwwww
1514131211109876543210
KEY[111:96]
wwwwwwwwwwwwwwww

Bits 31:0 KEY[127:96] : Cryptographic key, bits [127:96]

Refer to the AES_KEYR0 register for description of the KEY[255:0] bitfield and for information relative to writing AES_KEYRx registers.

25.8.9 AES initialization vector register 0 (AES_IVR0)

Address offset: 0x020

Reset value: 0x0000 0000

31302928272625242322212019181716
IVI[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
IVI[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 IVI[31:0] : Initialization vector input, bits [31:0]

AES_IVRx registers store the 128-bit initialization vector or the nonce, depending on the chaining mode selected. This value is updated by hardware after each computation round (when applicable). Write to this register is ignored when EN bit is set in AES_CR register

25.8.10 AES initialization vector register 1 (AES_IVR1)

Address offset: 0x024

Reset value: 0x0000 0000

31302928272625242322212019181716
IVI[63:48]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
IVI[47:32]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 IVI[63:32] : Initialization vector input, bits [63:32]

Refer to the AES_IVR0 register for description of the IVI[128:0] bitfield.

25.8.11 AES initialization vector register 2 (AES_IVR2)

Address offset: 0x028

Reset value: 0x0000 0000

31302928272625242322212019181716
IVI[95:80]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
IVI[79:64]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 IVI[95:64] : Initialization vector input, bits [95:64]

Refer to the AES_IVR0 register for description of the IVI[128:0] bitfield.

25.8.12 AES initialization vector register 3 (AES_IVR3)

Address offset: 0x02C

Reset value: 0x0000 0000

31302928272625242322212019181716
IVI[127:112]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
IVI[111:96]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 IVI[127:96] : Initialization vector input, bits [127:96]

Refer to the AES_IVR0 register for description of the IVI[128:0] bitfield.

25.8.13 AES key register 4 (AES_KEYR4)

Address offset: 0x030

Reset value: 0x0000 0000

31302928272625242322212019181716
KEY[159:144]
wwwwwwwwwwwwwwww
1514131211109876543210
KEY[143:128]
wwwwwwwwwwwwwwww

Bits 31:0 KEY[159:128] : Cryptographic key, bits [159:128]

Refer to the AES_KEYR0 register for description of the KEY[255:0] bitfield and for information relative to writing AES_KEYRx registers.

25.8.14 AES key register 5 (AES_KEYR5)

Address offset: 0x034

Reset value: 0x0000 0000

31302928272625242322212019181716
KEY[191:176]
wwwwwwwwwwwwwwww
1514131211109876543210
KEY[175:160]
wwwwwwwwwwwwwwww

Bits 31:0 KEY[191:160] : Cryptographic key, bits [191:160]

Refer to the AES_KEYR0 register for description of the KEY[255:0] bitfield and for information relative to writing AES_KEYRx registers.

25.8.15 AES key register 6 (AES_KEYR6)

Address offset: 0x038

Reset value: 0x0000 0000

31302928272625242322212019181716
KEY[223:208]
wwwwwwwwwwwwwwww
1514131211109876543210
KEY[207:192]
wwwwwwwwwwwwwwww

Bits 31:0 KEY[223:192] : Cryptographic key, bits [223:192]

Refer to the AES_KEYR0 register for description of the KEY[255:0] bitfield and for information relative to writing AES_KEYRx registers.

25.8.16 AES key register 7 (AES_KEYR7)

Address offset: 0x03C

Reset value: 0x0000 0000

31302928272625242322212019181716
KEY[255:240]
wwwwwwwwwwwwwwww
1514131211109876543210
KEY[239:224]
wwwwwwwwwwwwwwww

Bits 31:0 KEY[255:224] : Cryptographic key, bits [255:224]

Refer to the AES_KEYR0 register for description of the KEY[255:0] bitfield and for information relative to writing AES_KEYRx registers.

25.8.17 AES suspend registers (AES_SUSPRx)

Address offset: 0x040 + 0x4 * x, (x = 0 to 7)

Reset value: 0x0000 0000

31302928272625242322212019181716
SUSP[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
SUSP[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 SUSP[31:0] : Suspend data

AES_SUSPRx registers contain the complete internal register states of the AES when the GCM, GMAC or CCM processing of the current task is suspended to process a higher-priority task. Refer to Section 25.4.8: AES suspend and resume operations for more details.

Clearing EN bit of the AES_CR register clears this register to zero.

AES_SUSPRx registers are not used in other chaining modes than GCM, GMAC or CCM.

25.8.18 AES interrupt enable register (AES_IER)

Address offset: 0x300

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.KEIE
rw
RWEIE
rw
CCFIE
rw

Bits 31:3 Reserved, must be kept at reset value.

Bit 2 KEIE : Key error interrupt enable

This bit enables or disables (masks) the AES interrupt generation when KEIF (key error flag) is set.

0: Disabled (masked)

1: Enabled (not masked)

Bit 1 RWEIE : Read or write error interrupt enable

This bit enables or disables (masks) the AES interrupt generation when RWEIF (read and/or write error flag) is set.

0: Disabled (masked)

1: Enabled (not masked)

Bit 0 CCFIE : Computation complete flag interrupt enable

This bit enables or disables (masks) the AES interrupt generation when CCF (computation complete flag) is set.

0: Disabled (masked)

1: Enabled (not masked)

25.8.19 AES interrupt status register (AES_ISR)

Address offset: 0x304

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.KEIFRWEIFCCF
rrr

Bits 31:3 Reserved, must be kept at reset value.

Bit 2 KEIF : Key error interrupt flag

This read-only bit is set by hardware when the key information fails to load into key registers.

0: No key error detected

1: Key information failed to load into key registers

The flag setting generates an interrupt if the KEIE bit of the AES_IER register is set. It also clears the key registers and the KEYVALID flag in the AES_SR register.

The flag is cleared by setting the corresponding bit of the AES_ICR register.

KEIF is raised upon any of the following events:

KEIF must be cleared by the application software, otherwise KEYVALID cannot be set.

Bit 1 RWEIF : Read or write error interrupt flag

This read-only bit is set by hardware when a RDERRF or a WRERRF error flag is set in the AES_SR register.

0: No read or write error detected

1: Read or write error detected

The flag setting generates an interrupt if the RWEIE bit of the AES_IER register is set.

The flag is cleared by setting the corresponding bit of the AES_ICR register.

The flag has no meaning when key derivation mode is selected.

See the AES_SR register for details.

Bit 0 CCF : Computation complete flag

This flag indicates whether the computation is completed. It is significant only when the DMAOUTEN bit is cleared, and it may stay high when DMAOUTEN is set.

0: Not completed

1: Completed

The flag setting generates an interrupt if the CCFIE bit of the AES_IER register is set.

The flag is cleared by setting the corresponding bit of the AES_ICR register.

25.8.20 AES interrupt clear register (AES_ICR)

Address offset: 0x308

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.KEIFRWEIFCCF
www

Bits 31:3 Reserved, must be kept at reset value.

Bit 2 KEIF : Key error interrupt flag clear

Setting this bit clears the KEIF status bit of the AES_ISR register.

Bit 1 RWEIF : Read or write error interrupt flag clear

Setting this bit clears the RWEIF status bit of the AES_ISR register, and clears both RDERRF and WRERRF flags in the AES_SR register.

Bit 0 CCF : Computation complete flag clear

Setting this bit clears the CCF status bit of the AES_ISR register.

25.8.21 AES register map

Table 194. AES register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x000AES_CRIPRSTRes.KMOD[1]KMOD[0]NPBLB[3:0]Res.KEYSIZERes.CHMOD[2]Res.GCMPH[1:0]DMAOUTENDMAINENRes.CHMOD[1:0]MODE[1:0]DATATYPE[1:0]EN
Reset value00000000000000000000
0x004AES_SRRes.KEYVALIDRes.BUSYWRERRFRDERRFRes.
Reset value0000
0x008AES_DINRDIN[31:0]
Reset value00000000000000000000000000000000
0x00CAES_DOUTRDOUT[31:0]
Reset value00000000000000000000000000000000
0x010AES_KEYR0KEY[31:0]
Reset value00000000000000000000000000000000
0x014AES_KEYR1KEY[63:32]
Reset value00000000000000000000000000000000
Table 194. AES register map and reset values (continued)
OffsetRegister name313029282726252423222120191817161514131211109876543210
0x018AES_KEYR2KEY[95:64]
Reset value00000000000000000000000000000000
0x01CAES_KEYR3KEY[127:96]
Reset value00000000000000000000000000000000
0x020AES_IVR0IVI[31:0]
Reset value00000000000000000000000000000000
0x024AES_IVR1IVI[63:32]
Reset value00000000000000000000000000000000
0x028AES_IVR2IVI[95:64]
Reset value00000000000000000000000000000000
0x02CAES_IVR3IVI[127:96]
Reset value00000000000000000000000000000000
0x030AES_KEYR4KEY[159:128]
Reset value00000000000000000000000000000000
0x034AES_KEYR5KEY[191:160]
Reset value00000000000000000000000000000000
0x038AES_KEYR6KEY[223:192]
Reset value00000000000000000000000000000000
0x03CAES_KEYR7KEY[255:224]
Reset value00000000000000000000000000000000
0x040AES_SUSPR0SUSP[31:0]
Reset value00000000000000000000000000000000
0x044AES_SUSPR1SUSP[31:0]
Reset value00000000000000000000000000000000
0x048AES_SUSPR2SUSP[31:0]
Reset value00000000000000000000000000000000
0x04CAES_SUSPR3SUSP[31:0]
Reset value00000000000000000000000000000000
0x050AES_SUSPR4SUSP[31:0]
Reset value00000000000000000000000000000000
0x054AES_SUSPR5SUSP[31:0]
Reset value00000000000000000000000000000000
0x058AES_SUSPR6SUSP[31:0]
Reset value00000000000000000000000000000000
0x05CAES_SUSPR7SUSP[31:0]
Reset value00000000000000000000000000000000
0x060-0x2FFReservedRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.

Table 194. AES register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x300AES_IERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.KEIERWEIE
Reset value000
0x304AES_ISRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.KEIFRWEIF
Reset value000
0x308AES_ICRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.KEIFRWEIF
Reset value000
0x309-
0x3FF
ReservedRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.

Refer to Section 2.3: Memory organization for the register boundary addresses.