33. Secure AES coprocessor (SAES)

33.1 Introduction

The secure AES coprocessor (SAES) encrypts or decrypts data, using an algorithm and implementation fully compliant with the advanced encryption standard (AES) defined in Federal information processing standards (FIPS) publication 197. It incorporates a protection against side-channel attacks (SCA), including differential power analysis (DPA), required for SESIP and PSA security assurance level 3 target.

The peripheral supports CTR, GCM, GMAC, CCM, ECB, and CBC chaining modes for key sizes of 128 or 256 bits, as well as special modes such as hardware secret key encryption/decryption (Wrapped-key mode) and key sharing with faster CRYP peripheral (Shared-key mode).

SAES has the possibility to load by hardware STM32 hardware secret keys (boot hardware key BHK and derived hardware unique key DHUK), usable but not readable by application.

SAES is an AMBA AHB slave peripheral accessible through 32-bit single accesses only. Other access types generate an AHB error, and other than 32-bit writes may corrupt the register content.

The peripheral supports DMA single transfers for incoming and outgoing data (two DMA channels required). It is hardware-linked with the true random number generator (TRNG) and with the CRYP peripheral.

33.2 SAES main features

33.3 SAES implementation

The devices have one SAES peripheral connected to an MDMA.

33.4 SAES functional description

33.4.1 SAES block diagram

Figure 275 shows the block diagram of SAES.

Figure 275. SAES block diagram

SAES block diagram showing internal components and interfaces.

The diagram illustrates the internal architecture of the Secure AES coprocessor (SAES). It features a central AES Core (AEA) which is connected to several control and data interfaces. The AHB interface provides a 32-bit AHB bus for control and status access. The DMA interface handles data input and output. The IRQ interface manages interrupts. The Control Logic coordinates the operation of the core and interfaces. The PRNG (Pseudo-Random Number Generator) is connected to the AHB interface and provides a shared key to the AES block. The AES block is connected to the TAMP (Tamper Protection) block, which contains registers TAMP_BKP0R through TAMP_BKP7R. The TAMP block is connected to the BHK (Boot Hardware Key) register. The BHK is connected to the RHUK (Root Hardware Unique Key) register. The RHUK is connected to the KGen (Key Generator) block. The KGen block is connected to the DHUK (Derived Hardware Unique Key) register. The DHUK is connected to the swap block. The swap block is connected to the AES Core (AEA). The AES Core (AEA) is connected to the AES_DOUTR and AES_DINR registers. The AES_DOUTR register is connected to the AES_DOUTR register. The AES_DINR register is connected to the AES_DINR register. The AES_DOUTR register is connected to the AES_DOUTR register. The AES_DINR register is connected to the AES_DINR register. The AES_DOUTR register is connected to the AES_DOUTR register. The AES_DINR register is connected to the AES_DINR register.

SAES block diagram showing internal components and interfaces.

Note: AES represents the CRYP peripheral.

33.4.2 SAES internal signals

Table 275 describes the user relevant internal signals interfacing the SAES peripheral.

Table 275. SAES internal input/output signals

Signal nameSignal typeDescription
saes_hclkInputAHB bus clock
saes_itOutputSAES interrupt request
saes_in_dmaInput/OutputInput DMA single request/acknowledge
saes_out_dmaInput/OutputOutput DMA single request/acknowledge
saes_itamp_outOutputTamper event signal to TAMP (XOR-ed), triggered when an unexpected hardware fault occurs. When this signal is triggered, SAES automatically clears key registers. A reset is required for SAES to be usable again.
saes_ker_ckInputSAES kernel clock.
RHUKInput256-bit root hardware unique key (non-volatile, unique per device and secret to software), used to internally compute the derived hardware unique key (DHUK)
BHK(1)Input256-bit boot hardware key (BHK) stored in tamper-resistant secure backup registers and written by a secure code during boot. Once written, this key cannot be read nor written by any application until the next product reset.
  1. 1. Connected to a set of backup registers in TAMP peripheral that are written, then read/write locked, by the application software (see Section 33.4.16 for details).

33.4.3 SAES cryptographic core

Overview

The SAES cryptographic core consists of the following components:

The SAES core works on 128-bit data blocks (four words) with 128-bit or 256-bit key length. Depending on the chaining mode, the SAES requires zero or one 128-bit initialization vector IV.

The SAES features the following modes of operation:

Note: Mode 2 is only used when performing ECB and CBC decryption.

The operating mode is selected by programming the MODE[1:0] bitfield of the SAES_CR register. It may be done only when the SAES peripheral is disabled.

Special key operation is selected using the KMOD[1:0] bitfield of the SAES_CR register. See Section 33.4.14 and Section 33.4.13 for details.

Typical data processing

Typical usage of the SAES is described in Section 33.4.4: SAES procedure to perform a cipher operation.

Note: The outputs of the intermediate AEA stages are never revealed outside the cryptographic boundary, with the exclusion of the IVI bitfield.

Chaining modes

The following chaining modes are supported by SAES, selected through the CHMOD[2:0] bitfield of the SAES_CR register:

Note: The chaining mode may be changed only when SAES is disabled (bit EN of the SAES_CR register cleared).

Principle of each SAES chaining mode is provided in the following subsections.

Detailed information is in dedicated sections, starting from Section 33.4.8: SAES basic chaining modes (ECB, CBC).

Electronic codebook (ECB) mode

Figure 276. ECB encryption and decryption principle

Diagram showing ECB encryption and decryption principles. Encryption: Plaintext blocks 1, 2, 3 are individually encrypted using a key to produce Ciphertext blocks 1, 2, 3. Decryption: Ciphertext blocks 1, 2, 3 are individually decrypted using a key to produce Plaintext blocks 1, 2, 3. Legend: input (white box), output (grey box), key scheduling (circular arrow).

The diagram illustrates the ECB mode operation. It is divided into two main sections: 'Encryption' and 'Decryption'.

Encryption: Three separate paths are shown. In each path, a 'Plaintext block' (white box, input) is fed into an 'Encrypt' block (white box). A 'key' (arrow) is also input to the 'Encrypt' block. The output of the 'Encrypt' block is a 'Ciphertext block' (grey box, output).

Decryption: Three separate paths are shown. In each path, a 'Ciphertext block' (grey box, input) is fed into a 'Decrypt' block (white box). A 'key' (arrow) is also input to the 'Decrypt' block. The output of the 'Decrypt' block is a 'Plaintext block' (white box, output). The first 'Decrypt' block includes a 'key scheduling' symbol (a circular arrow).

Legend:

MSv42140V1

Diagram showing ECB encryption and decryption principles. Encryption: Plaintext blocks 1, 2, 3 are individually encrypted using a key to produce Ciphertext blocks 1, 2, 3. Decryption: Ciphertext blocks 1, 2, 3 are individually decrypted using a key to produce Plaintext blocks 1, 2, 3. Legend: input (white box), output (grey box), key scheduling (circular arrow).

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.

Note: For decryption, a special key scheduling is required before processing the first block.

Cipher block chaining (CBC) mode

Figure 277. CBC encryption and decryption principle

Diagram showing CBC encryption and decryption principles. The Encryption section shows three blocks: Plaintext block 1, 2, and 3. Plaintext block 1 is XORed with an initialization vector, then encrypted with a key to produce Ciphertext block 1. Ciphertext block 1 is XORed with Plaintext block 2, then encrypted to produce Ciphertext block 2. Ciphertext block 2 is XORed with Plaintext block 3, then encrypted to produce Ciphertext block 3. The Decryption section shows three blocks: Plaintext block 1, 2, and 3. Ciphertext block 1 is decrypted with a key and XORed with the initialization vector to produce Plaintext block 1. Ciphertext block 2 is decrypted with a key and XORed with Ciphertext block 1 to produce Plaintext block 2. Ciphertext block 3 is decrypted with a key and XORed with Ciphertext block 2 to produce Plaintext block 3. A legend indicates input boxes, output boxes, and a circular arrow indicating key scheduling.

MSv42141V1

Diagram showing CBC encryption and decryption principles. The Encryption section shows three blocks: Plaintext block 1, 2, and 3. Plaintext block 1 is XORed with an initialization vector, then encrypted with a key to produce Ciphertext block 1. Ciphertext block 1 is XORed with Plaintext block 2, then encrypted to produce Ciphertext block 2. Ciphertext block 2 is XORed with Plaintext block 3, then encrypted to produce Ciphertext block 3. The Decryption section shows three blocks: Plaintext block 1, 2, and 3. Ciphertext block 1 is decrypted with a key and XORed with the initialization vector to produce Plaintext block 1. Ciphertext block 2 is decrypted with a key and XORed with Ciphertext block 1 to produce Plaintext block 2. Ciphertext block 3 is decrypted with a key and XORed with Ciphertext block 2 to produce Plaintext block 3. A legend indicates input boxes, output boxes, and a circular arrow indicating key scheduling.

In CBC 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.

Note: For decryption, a special key scheduling is required before processing the first block.

Counter (CTR) mode

Figure 278. CTR encryption and decryption principle

Diagram showing CTR encryption and decryption principles. Encryption: Counter (value) -> Encrypt (key) -> XOR with Plaintext block 1 -> Ciphertext block 1. Decryption: Counter (value) -> Decrypt (key) -> XOR with Ciphertext block 1 -> Plaintext block 1. Legend: input (light grey), output (dark grey), XOR (circle with plus).

The diagram illustrates the Counter (CTR) mode for encryption and decryption. It is divided into two sections: Encryption and Decryption.

Encryption: A sequence of three blocks is shown. Each block starts with a 'Counter' box. The first counter has 'value', the second 'value + 1', and the third 'value + 2'. Each counter output goes to an 'Encrypt' block, which also takes a 'key' input. The output of the 'Encrypt' block goes to an XOR gate (⊕). The other input to the XOR gate is a 'Plaintext block' (1, 2, or 3). The output of the XOR gate is a 'Ciphertext block' (1, 2, or 3).

Decryption: A similar sequence of three blocks is shown. Each block starts with a 'Counter' box with 'value', 'value + 1', and 'value + 2'. Each counter output goes to a 'Decrypt' block, which also takes a 'key' input. The output of the 'Decrypt' block goes to an XOR gate (⊕). The other input to the XOR gate is a 'Ciphertext block' (1, 2, or 3). The output of the XOR gate is a 'Plaintext block' (1, 2, or 3).

Legend:
- Light grey box: input
- Dark grey box: output
- ⊕: XOR

MSv42142V1

Diagram showing CTR encryption and decryption principles. Encryption: Counter (value) -> Encrypt (key) -> XOR with Plaintext block 1 -> Ciphertext block 1. Decryption: Counter (value) -> Decrypt (key) -> XOR with Ciphertext block 1 -> Plaintext block 1. Legend: input (light grey), output (dark grey), XOR (circle with plus).

The CTR mode uses the SAES core to generate a key stream. The keys are then XOR-ed with the plaintext to obtain the ciphertext as specified in NIST Special Publication 800-38A, Recommendation for Block Cipher Modes of Operation.

Note: Unlike with ECB and CBC modes, no key scheduling is required for the CTR decryption, since in this chaining scheme the SAES core is always used in encryption mode for producing the key stream, or counter blocks.

Galois/counter mode (GCM)

Figure 279. GCM encryption and authentication principle

Figure 279: GCM encryption and authentication principle diagram. Shows parallel encryption and authentication data flow with initialization vector, counter increments (+1), keys, AES encryption blocks, Plaintext blocks 1 to 3, XOR operations, Ciphertext blocks 1 to 3, GF2mul blocks, Final block, and output TAG. An Init (Encrypt) block produces H. A legend defines input (white box), output (grey box), and XOR (circled plus). Label MSv42143V1 is at the bottom right.
Figure 279: GCM encryption and authentication principle diagram. Shows parallel encryption and authentication data flow with initialization vector, counter increments (+1), keys, AES encryption blocks, Plaintext blocks 1 to 3, XOR operations, Ciphertext blocks 1 to 3, GF2mul blocks, Final block, and output TAG. An Init (Encrypt) block produces H. A legend defines input (white box), output (grey box), and XOR (circled plus). Label MSv42143V1 is at the bottom right.

In Galois/counter mode (GCM), the plaintext message is encrypted while a message authentication code (MAC) is computed in parallel, thus generating the corresponding ciphertext and its MAC (also known as authentication tag). It is defined in NIST Special Publication 800-38D, Recommendation for Block Cipher Modes of Operation - Galois/Counter Mode (GCM) and GMAC.

GCM mode is based on SAES in counter mode for confidentiality. It uses a multiplier over a fixed finite field for computing the message authentication code. It requires an initial value and a particular 128-bit block at the end of the message.

Galois message authentication code (GMAC) principle

Figure 280. GMAC authentication principle

Figure 280: GMAC authentication principle diagram. Shows authentication data flow with Initialization vector, key, Init (Encrypt) block producing H, Plaintext blocks 1 to 3 XORed sequentially through GF2mul blocks, followed by Final block to output TAG. Legend defines input, output, and XOR. Label MSv42144V1 is at the bottom right.
Figure 280: GMAC authentication principle diagram. Shows authentication data flow with Initialization vector, key, Init (Encrypt) block producing H, Plaintext blocks 1 to 3 XORed sequentially through GF2mul blocks, followed by Final block to output TAG. Legend defines input, output, and XOR. Label MSv42144V1 is at the bottom right.

Galois message authentication code (GMAC) allows authenticating a message and generating the corresponding message authentication code (MAC). It is defined in NIST Special Publication 800-38D, Recommendation for Block Cipher Modes of Operation - Galois/Counter Mode (GCM) and GMAC.

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).

Counter with CBC-MAC (CCM) principle

Figure 281. CCM encryption and authentication principle

A block diagram illustrating the CCM encryption and authentication principle. It shows a counter sequence (B0, Count 1, Count 2, Count 3) where Count 1 is derived from B0 and subsequent counts are incremented by 1. Each count is encrypted with a key to produce an initialization vector and subsequent ciphertext blocks. These are then XORed with plaintext blocks to produce ciphertext blocks, which are further encrypted to produce the final TAG. A legend indicates that light gray boxes are inputs, dark gray boxes are outputs, and the circle with a plus sign represents XOR.

The diagram illustrates the CCM encryption and authentication principle. It shows a counter sequence starting from B0, which leads to Count 1. Count 1 is incremented by 1 to produce Count 2, which is then incremented by 1 to produce Count 3. Each count is encrypted with a key to produce an initialization vector and subsequent ciphertext blocks. These are then XORed with plaintext blocks to produce ciphertext blocks, which are further encrypted to produce the final TAG. A legend indicates that light gray boxes are inputs, dark gray boxes are outputs, and the circle with a plus sign represents XOR.

A block diagram illustrating the CCM encryption and authentication principle. It shows a counter sequence (B0, Count 1, Count 2, Count 3) where Count 1 is derived from B0 and subsequent counts are incremented by 1. Each count is encrypted with a key to produce an initialization vector and subsequent ciphertext blocks. These are then XORed with plaintext blocks to produce ciphertext blocks, which are further encrypted to produce the final TAG. A legend indicates that light gray boxes are inputs, dark gray boxes are outputs, and the circle with a plus sign represents XOR.

In Counter with cipher block chaining-message authentication code (CCM) mode, the plaintext message is encrypted while a message authentication code (MAC) is computed in parallel, thus generating the corresponding ciphertext and the corresponding MAC (also known as tag). It is described by NIST in Special Publication 800-38C, Recommendation for Block Cipher Modes of Operation - The CCM Mode for Authentication and Confidentiality.

CCM mode is based on SAES in counter mode for confidentiality and it uses CBC for computing the message authentication code. It requires an initial value.

Like GCM, the CCM chaining mode can be applied on a message composed only by plaintext authenticated data (that is, only header, no payload). Note that this way of using CCM is not called CMAC (it is not similar to GCM/GMAC), and its use is not recommended by NIST.

33.4.4 SAES procedure to perform a cipher operation

Introduction

A typical cipher operation is explained below. Detailed information is provided in sections starting from Section 33.4.8: SAES basic chaining modes (ECB, CBC).

Initialization of SAES

To initialize SAES, first disable it by clearing the EN bit of the SAES_CR register. Then perform the following steps in any order (except KEYSIZE):

Note: SAES sets KEYVALID in SAES_SR when key information defined by KEYSIZE is loaded in SAES_KEYRx.

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 when KMOD[1:0] = 00. For other KMOD[1:0] values refer to Section 33.4.14 and Section 33.4.13.

For ECB or CBC mode, refer to Section 33.4.6: SAES ciphertext stealing and data padding. The last block management in these cases is more complex than in the sequence described in this section.

Data append through polling

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

  1. 1. Enable the SAES peripheral by setting the EN bit of the SAES_CR register.
  2. 2. Repeat the following sub-sequence until the payload is entirely processed:
    1. a) Write four input data words into the SAES_DINR register.
    2. b) Wait until the status flag CCF is set in the SAES_SR, then read the four data words from the SAES_DOUTR register.
    3. c) Clear the CCF flag, by setting the CCF bit of the SAES_ICR register.
    4. d) If the data block just processed is the second-last block of the message and the significant data in the last block to process is inferior to 128 bits, pad the remainder of the last block with zeros and, in case of GCM payload encryption or CCM payload decryption, specify the number of non-valid bytes, using the NPBLB bitfield of the SAES_CR register, for SAES to compute a correct tag; refer to Section 33.4.6: SAES ciphertext stealing and data padding.
  3. 3. As it is the last block, follow the instructions in Section 33.4.6: SAES ciphertext stealing and data padding, discard the data that is not part of the data, then disable the SAES peripheral by clearing the EN bit of the SAES_CR register.

Note: Up to three wait cycles are automatically inserted between two consecutive writes to the SAES_DINR register, to allow sending the key to the AES co-processor.

NPBLB bits are not used in header phase of GCM, GMAC and CCM chaining modes.

Data append using interrupt

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

  1. 1. Enable interrupts from SAES by setting the CCFIE bit of the SAES_IER register.
  2. 2. Enable the SAES peripheral by setting the EN bit of the SAES_CR register.
  3. 3. Write first four input data words into the SAES_DINR register.
  4. 4. Handle the data in the SAES interrupt service routine, upon interrupt:
    1. a) Read four output data words from the SAES_DOUTR register.
    2. b) Clear the CCF flag and thus the pending interrupt, by setting the CCF bit of the SAES_ICR register.
    3. c) If the data block just processed is the second-last block of an message and the significant data in the last block to process is inferior to 128 bits, pad the remainder of the last block with zeros and, in case of GCM payload encryption or CCM payload decryption, specify the number of non-valid bytes, using the NPBLB bitfield of the SAES_CR register, for SAES to compute a correct tag; refer to Section 33.4.6: SAES ciphertext stealing and data padding. Then proceed with point 4e).
    4. d) If the data block just processed is the last block of the message, discard the data that is not part of the data follow if needed Section 33.4.6: SAES ciphertext stealing and data padding, then disable the SAES peripheral by clearing the EN bit of the SAES_CR register and quit the interrupt service routine.
    5. e) Write next four input data words into the SAES_DINR register and quit the interrupt service routine.

Note: SAES is tolerant of delays between consecutive read or write operations, which allows, for example, an interrupt from another peripheral to be served between two SAES computations.

NPBLB bits are not used in header phase of GCM, GMAC and CCM chaining modes.

Data append using DMA

With this method, all the transfers and processing are managed by DMA and SAES. To use the method, proceed as follows:

  1. 1. If the last block to process is inferior to 128 bits, refer to Section 33.4.6: SAES ciphertext stealing and data padding to prepare the last four-word data block.
  2. 2. Configure the DMA controller so as to transfer the data to process from the memory to the SAES peripheral input and the processed data from the SAES peripheral output to the memory, as described in Section 33.4.18: SAES DMA interface. Configure the DMA controller so as to generate an interrupt on transfer completion. In case of GCM payload encryption or CCM payload decryption, DMA transfer must not include the last four-word block if padded with zeros. The sequence described in Data append through polling must be used instead for this last block, because NPBLB bits must be setup before processing the block, for SAES to compute a correct tag.
  3. 3. Enable the SAES peripheral by setting the EN bit of the SAES_CR register
  4. 4. Enable DMA requests by setting the DMAINEN and DMAOUTEN bits of the SAES_CR register.
  5. 5. Upon DMA interrupt indicating the transfer completion, get the SAES-processed data from the memory.

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

NPBLB bits are not used in header phase of GCM, GMAC, and CCM chaining modes.

33.4.5 SAES decryption round key preparation

Internal key schedule is used to generate AES round keys. In AES encryption, the round 0 key is the one stored in the key registers. AES decryption must start using the last round key. As the encryption key is stored in memory, a special key scheduling must be performed to obtain the decryption key. This key scheduling is only required for AES decryption in ECB and CBC modes.

Recommended method is to select the Mode 2 by setting to 01 the MODE[1:0] bitfield of the SAES_CR (key process only), then proceed with the decryption by setting MODE[1:0] to 10 (Mode 3, decryption only). Mode 2 usage is described below:

  1. 1. Verify that BUSY = 0 in SAES_SR (no RNG random number fetch in progress).
  2. 2. Disable the SAES peripheral by clearing the EN bit of the SAES_CR register.
  3. 3. Select Mode 2 by setting to 01 the MODE[1:0] bitfield of the SAES_CR. The CHMOD[2:0] bitfield is not significant in this case because this key derivation mode is independent of the chaining algorithm selected. Select normal key mode by setting KMOD[1:0] to 00. For decryption with other KMOD[1:0] values, refer to Section 33.4.14 and Section 33.4.13.
  4. 4. Set key length to 128 or 256 bits, via KEYSIZE bit of SAES_CR register. If the key must not be shared with a different security context (different secure attribute), the KEYPROT bit of the SAES_CR register must also be set.
  5. 5. Write the SAES_KEYRx registers (128 or 256 bits) with encryption key, or, alternatively, select a key source different from the key registers, through KEYSEL[2:0]. Refer to Section 33.4.16: SAES key registers for details. Writes to the SAES_IVRx registers have no effect.
  6. 6. Enable the SAES peripheral, by setting the EN bit of the SAES_CR register.
  1. 7. Wait until the CCF flag is set in the SAES_SR register.
  2. 8. Clear the CCF flag. Derived key is available in AES core, ready to use for decryption.

Note: The SAES is disabled by hardware when the derivation key is available.

To restart a derivation key computation, repeat steps 5, 6, 7, and 8.

Note: The operation of the key preparation lasts 145 or 230 clock cycles, depending on the key size (128- or 256-bit).

33.4.6 SAES ciphertext stealing and data padding

When using SAES in ECB or CBC modes to manage messages the size of which is not a multiple of the block size (128 bits), ciphertext stealing techniques are used, 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 the SAES peripheral does not support 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, when SAES is used in other modes than ECB or CBC, an incomplete input data block (that is, block with input data shorter than 128 bits) 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. As SAES does not implement automatic data padding operation to the last block, the application must follow the recommendation given in Section 33.4.4: SAES procedure to perform a cipher operation to manage messages the size of which is not a multiple of 128 bits.

Note: Padding data are swapped in a similar way as normal data, according to the DATATYPE[1:0] field of the SAES_CR register (see Section 33.4.15: SAES data registers and data swapping for details).

33.4.7 SAES task suspend and resume

A message can be suspended if another message with a higher priority must be processed. When this highest priority message is sent, the suspended message can resume in both encryption or decryption mode.

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

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

Figure 282. Example of suspend mode management

Flowchart showing suspend and resume operations between Message 1 and Message 2. Message 1 consists of 128-bit blocks 1, 2, and 3. A 'New higher-priority message 2 to be processed' interrupt occurs during block 3, leading to an 'AES suspend sequence'. Message 2 then starts with 128-bit blocks 1 and 2. After Message 2 is processed, an 'AES resume sequence' is performed before Message 1 continues with blocks 4, 5, and 6.
Flowchart showing suspend and resume operations between Message 1 and Message 2. Message 1 consists of 128-bit blocks 1, 2, and 3. A 'New higher-priority message 2 to be processed' interrupt occurs during block 3, leading to an 'AES suspend sequence'. Message 2 then starts with 128-bit blocks 1 and 2. After Message 2 is processed, an 'AES resume sequence' is performed before Message 1 continues with blocks 4, 5, and 6.

MSv42148V1

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

33.4.8 SAES basic chaining modes (ECB, CBC)

Overview

This section gives a brief explanation of the four basic operation modes provided by the SAES core: ECB encryption, ECB decryption, CBC encryption and CBC decryption. For detailed information, refer to the FIPS publication 197 from November 26, 2001.

Figure 283 illustrates the electronic codebook (ECB) encryption.

Figure 283. ECB encryption

Diagram of ECB encryption for Block 1 and Block 2. Each block follows the sequence: AES_DINR (plaintext Px) -> Swap management (using DATATYPE[1:0]) -> AES core Encrypt (using AES_KEYRx (KEY)) -> Swap management (using DATATYPE[1:0]) -> AES_DOUTR (ciphertext Cx). A legend indicates that white boxes are inputs and grey boxes are outputs.
Diagram of ECB encryption for Block 1 and Block 2. Each block follows the sequence: AES_DINR (plaintext Px) -> Swap management (using DATATYPE[1:0]) -> AES core Encrypt (using AES_KEYRx (KEY)) -> Swap management (using DATATYPE[1:0]) -> AES_DOUTR (ciphertext Cx). A legend indicates that white boxes are inputs and grey boxes are outputs.

MSv19105V2

In ECB encrypt mode, the 128-bit plaintext input data block Px in the SAES_DINR register first goes through bit/byte/half-word swapping. The swap result Ix is processed with the AES core set in encrypt mode, using a 128- or 256-bit key. The encryption result Ox goes through bit/byte/half-word swapping, then is stored in the SAES_DOUTR register as 128-bit

ciphertext output data block Cx. The ECB encryption continues in this way until the last complete plaintext block is encrypted.

Figure 284 illustrates the electronic codebook (ECB) decryption.

Figure 284. ECB decryption

Figure 284. ECB decryption diagram showing Block 1 and Block 2 decryption processes. Each block takes a ciphertext input (AES_DINR), undergoes swap management (DATATYPE[1:0]), then decryption (AES_KEYRx), and finally swap management to produce plaintext output (AES_DOUTR).

The diagram illustrates the ECB decryption process for two blocks.
Block 1: AES_DINR (ciphertext C1) is the input. It passes through a 'Swap management' block (controlled by DATATYPE[1:0]) to produce I1. I1 is then processed by a 'Decrypt' block using AES_KEYRx (KEY) to produce O1. O1 passes through another 'Swap management' block to produce the final output AES_DOUTR (plaintext P1).
Block 2: AES_DINR (ciphertext C2) is the input. It passes through a 'Swap management' block to produce I2. I2 is then processed by a 'Decrypt' block using AES_KEYRx (KEY) to produce O2. O2 passes through another 'Swap management' block to produce the final output AES_DOUTR (plaintext P2).
Legend: Light gray boxes represent input, and dark gray boxes represent output.
MSv19106V2

Figure 284. ECB decryption diagram showing Block 1 and Block 2 decryption processes. Each block takes a ciphertext input (AES_DINR), undergoes swap management (DATATYPE[1:0]), then decryption (AES_KEYRx), and finally swap management to produce plaintext output (AES_DOUTR).

To perform an AES decryption in the ECB mode, the secret key has to be prepared by collecting the last-round encryption key (which requires to first execute the complete key schedule for encryption), and using it as the first-round key for the decryption of the ciphertext. This preparation is supported by the AES core.

In ECB decrypt mode, the 128-bit ciphertext input data block C1 in the SAES_DINR register first goes through bit/byte/half-word swapping. The keying sequence is reversed compared to that of the ECB encryption. The swap result I1 is processed with the AES core set in decrypt mode, using the formerly prepared decryption key. The decryption result goes through bit/byte/half-word swapping, then is stored in the SAES_DOUTR register as 128-bit plaintext output data block P1. The ECB decryption continues in this way until the last complete ciphertext block is decrypted.

Figure 285 illustrates the cipher block chaining (CBC) encryption.

Figure 285. CBC encryption

Figure 285. CBC encryption diagram showing Block 1 and Block 2 encryption processes. Block 1 takes plaintext P1, XORs it with IVI, then encrypts it to produce ciphertext C1. Block 2 takes plaintext P2, XORs it with C1, then encrypts it to produce ciphertext C2.

The diagram illustrates the CBC encryption process for two blocks.
Block 1: AES_DINR (plaintext P1) is the input. It passes through a 'Swap management' block to produce P1'. P1' is then XORed with the initialization vector IVI to produce I1. I1 is processed by a 'Block cipher encryption' block using AES_KEYRx (KEY) to produce O1. O1 passes through a 'Swap management' block to produce the final output AES_DOUTR (ciphertext C1).
Block 2: AES_DINR (plaintext P2) is the input. It passes through a 'Swap management' block to produce P2'. P2' is then XORed with the ciphertext C1 from Block 1 to produce I2. I2 is processed by a 'Block cipher encryption' block using AES_KEYRx (KEY) to produce O2. O2 passes through a 'Swap management' block to produce the final output AES_DOUTR (ciphertext C2).
Legend: Light gray boxes represent input, and dark gray boxes represent output. The XOR operation is denoted by a circle with a plus sign.
MSv19107V2

Figure 285. CBC encryption diagram showing Block 1 and Block 2 encryption processes. Block 1 takes plaintext P1, XORs it with IVI, then encrypts it to produce ciphertext C1. Block 2 takes plaintext P2, XORs it with C1, then encrypts it to produce ciphertext C2.

In CBC encrypt mode, the first plaintext input block, after bit/byte/half-word swapping (P1'), is XOR-ed with a 128-bit IVI bitfield (initialization vector and counter), producing the I1 input data for encrypt with the AES core, using a 128- or 256-bit key. The resulting 128-bit output block O1, after swapping operation, is used as ciphertext C1. The O1 data is then XOR-ed

with the second-block plaintext data P2' to produce the I2 input data for the AES core to produce the second block of ciphertext data. The chaining of data blocks continues in this way until the last plaintext block in the message is encrypted.

If the message size is not a multiple of 128 bits, the final partial data block is encrypted in the way explained in Section 33.4.6: SAES ciphertext stealing and data padding.

Figure 286 illustrates the cipher block chaining (CBC) decryption.

Figure 286. CBC decryption

Figure 286: CBC decryption diagram showing the flow for Block 1 and Block 2. Block 1: AES_DINR (ciphertext C1) and DATATYPE[1:0] enter a Swap management block, producing I1. I1 and AES_KEYRx (KEY) enter a Decrypt block, producing O1. O1 is XORed with AES_IVRx (IV) to produce P1'. P1' and DATATYPE[1:0] enter a Swap management block, producing AES_DOUTR (plaintext P1). Block 2: AES_DINR (ciphertext C2) and DATATYPE[1:0] enter a Swap management block, producing I2. I2 and AES_KEYRx (KEY) enter a Decrypt block, producing O2. O2 is XORed with P1' to produce P2'. P2' and DATATYPE[1:0] enter a Swap management block, producing AES_DOUTR (plaintext P2). Legend: input (white box), output (shaded box), XOR (⊕ symbol).
Figure 286: CBC decryption diagram showing the flow for Block 1 and Block 2. Block 1: AES_DINR (ciphertext C1) and DATATYPE[1:0] enter a Swap management block, producing I1. I1 and AES_KEYRx (KEY) enter a Decrypt block, producing O1. O1 is XORed with AES_IVRx (IV) to produce P1'. P1' and DATATYPE[1:0] enter a Swap management block, producing AES_DOUTR (plaintext P1). Block 2: AES_DINR (ciphertext C2) and DATATYPE[1:0] enter a Swap management block, producing I2. I2 and AES_KEYRx (KEY) enter a Decrypt block, producing O2. O2 is XORed with P1' to produce P2'. P2' and DATATYPE[1:0] enter a Swap management block, producing AES_DOUTR (plaintext P2). Legend: input (white box), output (shaded box), XOR (⊕ symbol).

In CBC decrypt mode, like in ECB decrypt mode, the secret key must be prepared to perform an AES decryption.

After the key preparation process, the decryption goes as follows: the first 128-bit ciphertext block (after the swap operation) is used directly as the AES core input block I1 for decrypt operation, using the 128-bit or 256-bit key. Its output O1 is XOR-ed with the 128-bit IVI field (that must be identical to that used during encryption) to produce the first plaintext block P1.

The second ciphertext block is processed in the same way as the first block, except that the I1 data from the first block is used in place of the initialization vector.

The decryption continues in this way until the last complete ciphertext block is decrypted.

If the message size is not a multiple of 128 bits, the final partial data block is decrypted in the way explained in Section 33.4.6: SAES ciphertext stealing and data padding.

For more information on data swapping, refer to Section 33.4.15: SAES data registers and data swapping.

ECB/CBC encryption sequence

The sequence of events to perform an ECB/CBC encryption (more detail in Section 33.4.4):

  1. 1. Verify that BUSY = 0 in SAES_SR (no RNG random number fetch in progress).
  2. 2. Disable the SAES peripheral by clearing the EN bit of the SAES_CR register.
  3. 3. Select the Mode 1 by setting to 00 the MODE[1:0] bitfield of the SAES_CR register and select ECB or CBC chaining mode by setting the CHMOD[2:0] bitfield of the SAES_CR register to 000 or 001, respectively. Data type can also be defined, using DATATYPE[1:0] bitfield. Select normal key mode by setting KMOD[1:0] to 00. For encryption with other KMOD[1:0] values, refer to Section 33.4.14 and Section 33.4.13.
  1. 4. Select 128- or 256-bit key length through the KEYSIZE bit of the SAES_CR register. If the key must not be shared with a different security context (different secure attribute), the KEYPROT bit of the SAES_CR register must also be set.
  2. 5. Write the SAES_KEYRx registers (128 or 256 bits) with encryption key. Alternatively, select a key source different from the key registers, through KEYSEL[2:0]. Refer to Section 33.4.16: SAES key registers for details. Fill the SAES_IVRx registers with the initialization vector data if CBC mode has been selected.
  3. 6. Enable the SAES peripheral by setting the EN bit of the SAES_CR register.
  4. 7. Write the SAES_DINR register four times to input the plaintext (MSB first), as shown in Figure 287.
  5. 8. Wait until the CCF flag is set in the SAES_SR register.
  6. 9. Read the SAES_DOUTR register four times to get the ciphertext (MSB first) as shown in Figure 287. Then clear the CCF flag by setting the CCF bit of the SAES_ICR register.
  7. 10. Repeat steps 7-8-9 to process all the blocks with the same encryption key.

Figure 287. ECB/CBC encryption (Mode 1)

Diagram of ECB/CBC encryption (Mode 1) showing three phases: Input phase, Computation phase, and Output phase.

The diagram illustrates the ECB/CBC encryption process in Mode 1, divided into three distinct phases:

Below the diagram, the following definitions are provided:

MS18936V3

Diagram of ECB/CBC encryption (Mode 1) showing three phases: Input phase, Computation phase, and Output phase.

ECB/CBC decryption sequence

The sequence of events to perform an AES ECB/CBC decryption is as follows (More detail in Section 33.4.4). Select normal key mode by setting KMOD[1:0] to 00. For decryption with other KMOD[1:0] values, refer to Section 33.4.14 and Section 33.4.13.

  1. 1. Follow the steps described in Section 33.4.5: SAES decryption round key preparation, in order to prepare the decryption key in AES core.
  2. 2. Select the Mode 3 by setting to 10 the MODE[1:0] bitfield of the SAES_CR register and select ECB or CBC chaining mode by setting the CHMOD[2:0] bitfield of the SAES_CR register to 000 or 001, respectively. Data type can also be defined, using DATATYPE[1:0] bitfield. KEYSIZE and KMOD[1:0] bitfields must be kept as-is.
  3. 3. Write the SAES_IVRx registers with the initialization vector (required in CBC mode only).
  4. 4. Enable SAES by setting the EN bit of the SAES_CR register.
  5. 5. Write the SAES_DINR register four times to input the cipher text (MSB first), as shown in Figure 288.
  6. 6. Wait until the CCF flag is set in the SAES_SR register.
  1. 7. Read the SAES_DOUTR register four times to get the plain text (MSB first), as shown in Figure 288. Then clear the CCF flag by setting the CCF bit of the SAES_ICR register.
  2. 8. Repeat steps 5-6-7 to process all the blocks encrypted with the same key.

Figure 288. ECB/CBC decryption (Mode 3)

Diagram of ECB/CBC decryption (Mode 3) showing three phases: Input phase, Computation phase, and Output phase.

The diagram illustrates the ECB/CBC decryption process in Mode 3, divided into three phases:

PT = plaintext = 4 words (PT3, ... , PT0)
CT = ciphertext = 4 words (CT3, ... , CT0)

MS18938V3

Diagram of ECB/CBC decryption (Mode 3) showing three phases: Input phase, Computation phase, and Output phase.

Suspend/resume operations in ECB/CBC modes

The following sequences are valid for normal key mode (KMOD[1:0] = 00).

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

  1. 1. If DMA is used, stop the SAES DMA transfers to the IN FIFO by clearing the DMAINEN bit of the SAES_CR register.
  2. 2. If DMA is not used, read four times the SAES_DOUTR register to save the last processed block. If DMA is used, wait until the CCF flag is set in the SAES_SR register then stop the DMA transfers from the OUT FIFO by clearing the DMAOUTEN bit of the SAES_CR register.
  3. 3. If DMA is not used, poll the CCF flag of the SAES_SR register until it becomes 1 (computation completed).
  4. 4. Clear the CCF flag by setting the CCF bit of the SAES_ICR register.
  5. 5. Save initialization vector registers (only required in CBC mode as SAES_IVRx registers are altered during the data processing).
  6. 6. Disable the SAES peripheral by clearing the bit EN of the SAES_CR register.
  7. 7. Save the SAES_CR register and clear the key registers if they are not needed, to process the higher priority message.
  8. 8. If DMA is used, save the DMA controller status (pointers for IN and OUT data transfers, number of remaining bytes, and so on).

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

  1. 1. If DMA is used, configure the DMA controller so as to complete the rest of the FIFO IN and FIFO OUT transfers.
  2. 2. Disable the SAES peripheral by clearing the EN bit of the SAES_CR register.
  3. 3. Restore SAES_CR register (with correct KEYSIZE) then restore SAES_KEYRx registers. Alternatively, select a key source different from key registers, using KEYSEL[2:0]. Refer to Section 33.4.16: SAES key registers for details.
  4. 4. Prepare the decryption key as described in Section 33.4.5: SAES decryption round key preparation (only required for ECB or CBC decryption).
  5. 5. Restore SAES_IVRx registers using the saved configuration (only required in CBC mode).
  6. 6. Enable the SAES peripheral by setting the EN bit of the SAES_CR register.
  7. 7. If DMA is used, enable SAES DMA transfers by setting the DMAINEN and DMAOUTEN bits of the SAES_CR register.

33.4.9 SAES counter (CTR) mode

Overview

The counter mode (CTR) uses SAES as a key-stream generator. The generated keys are then XOR-ed with the plaintext to obtain the ciphertext.

CTR chaining is defined in NIST Special Publication 800-38A, Recommendation for Block Cipher Modes of Operation. A typical message construction in CTR mode is given in Figure 289.

Figure 289. Message construction in CTR mode

Diagram illustrating message construction in CTR mode. The diagram shows a sequence of 16-byte blocks. The first block is the Initial Counter Block (ICB), which is further divided into an Initialization vector (IV) and a Counter, each with 4-byte boundaries. The subsequent blocks are Ciphertext (C) blocks, also with 16-byte boundaries. A 'decrypt' arrow points from the Ciphertext (C) block to the Plaintext (P) block. The final block is a Zero padding block containing the value 0. The diagram is labeled MSv42156V1 in the bottom right corner.
Diagram illustrating message construction in CTR mode. The diagram shows a sequence of 16-byte blocks. The first block is the Initial Counter Block (ICB), which is further divided into an Initialization vector (IV) and a Counter, each with 4-byte boundaries. The subsequent blocks are Ciphertext (C) blocks, also with 16-byte boundaries. A 'decrypt' arrow points from the Ciphertext (C) block to the Plaintext (P) block. The final block is a Zero padding block containing the value 0. The diagram is labeled MSv42156V1 in the bottom right corner.

The structure of this message is:

CTR encryption and decryption

Figure 290 and Figure 291 describe the CTR encryption and decryption process, respectively, as implemented in the SAES peripheral. The CTR mode is selected by writing 010 to the CHMOD[2:0] bitfield of SAES_CR register.

Figure 290. CTR encryption

Block diagram of CTR encryption for Block 1 and Block 2

MSv19102V3

Block diagram of CTR encryption for Block 1 and Block 2

Figure 291. CTR decryption

Block diagram of CTR decryption for Block 1 and Block 2

MSv18942V2

Block diagram of CTR decryption for Block 1 and Block 2

In CTR mode, the cryptographic core output (also called keystream) Ox is XOR-ed with relevant input block (Px' for encryption, Cx' for decryption), to produce the correct output block (Cx' for encryption, Px' for decryption). Initialization vectors in SAES must be initialized as shown in Table 276.

Table 276. CTR mode initialization vector definition

SAES_IVR3[31:0]SAES_IVR2[31:0]SAES_IVR1[31:0]SAES_IVR0[31:0]
IVI[127:96]IVI[95:64]IVI[63:32]IVI[31:0}
32-bit counter = 0x0001

Unlike in CBC mode that uses the SAES_IVRx registers only once when processing the first data block, in CTR mode SAES_IVRx registers are used for processing each data block, and the SAES peripheral increments the counter bits of the initialization vector (leaving the nonce bits unchanged).

CTR decryption does not differ from CTR encryption, since the core always encrypts the current counter block to produce the key stream that is then XOR-ed with the plaintext (CTR encryption) or ciphertext (CTR decryption) input. In CTR mode, the MODE[1:0] bitfield setting 01 (key derivation) is forbidden and all the other settings default to encryption mode.

The sequence of events to perform an encryption or a decryption in CTR chaining mode:

  1. 1. Verify that BUSY = 0 in SAES_SR (no RNG random number fetch in progress).
  2. 2. Disable the SAES peripheral by clearing the EN bit of the SAES_CR register.
  3. 3. Select CTR chaining mode by setting to 010 the CHMOD[2:0] bitfield of the SAES_CR register. Set MODE[1:0] bitfield to any value other than 01.
  4. 4. Initialize the SAES_KEYRx registers, and load the SAES_IVRx registers as described in Table 276.
  5. 5. Set the EN bit of the SAES_CR register, to start encrypting the current counter (EN is automatically reset when the calculation finishes).
  6. 6. If it is the last block, pad the data with zeros to have a complete block, if needed.
  7. 7. Append data in SAES, and read the result. The three possible scenarios are described in Section 33.4.4: SAES procedure to perform a cipher operation.
  8. 8. Repeat the previous step till the second-last block is processed. For the last block, apply the two previous steps and discard the bits that are not part of the payload (if the size of the significant data in the last input block is less than 16 bytes).

Suspend/resume operations in CTR mode

Like for the CBC mode, it is possible to interrupt a message to send a higher priority message, and resume the message that was interrupted. Detailed CBC suspend/resume sequence is described in Section 33.4.8: SAES basic chaining modes (ECB, CBC).

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

33.4.10 SAES Galois/counter mode (GCM)

Overview

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). To ensure confidentiality, GCM algorithm is based on AES counter mode. It uses a multiplier over a fixed finite field to generate the tag.

GCM chaining is defined in NIST Special Publication 800-38D, Recommendation for Block Cipher Modes of Operation - Galois/Counter Mode (GCM) and GMAC. A typical message construction in GCM mode is given in Figure 292.

Figure 292. Message construction in GCM

Diagram of GCM message construction showing the flow from Initialization vector (IV) and Counter to the Authentication tag (T).

The diagram illustrates the message construction in GCM. It shows the flow from the Initialization vector (IV) and Counter through the ICB (Initial Counter Block) to the Additional authenticated data (AAD) and Plaintext (P). The AAD and P are authenticated and encrypted to produce the Authenticated & encrypted ciphertext (C) and the Authentication tag (T). The Last block contains the AAD header length and payload length information. The diagram also shows the 16-byte boundaries for the ICB and the 4-byte boundaries for the IV and Counter. The authentication process is indicated by arrows labeled 'authenticate' and 'auth.' The encryption process is indicated by an arrow labeled 'encrypt'. The final output is the Authentication tag (T).

MSv42157V1

Diagram of GCM message construction showing the flow from Initialization vector (IV) and Counter to the 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.

Table 277. GCM last block definition

EndiannessBit[0] ----- Bit[31]Bit[32]----- Bit[63]Bit[64] ----- Bit[95]Bit[96] ----- Bit[127]
Input data0x0AAD length[31:0]0x0Payload length[31:0]

GCM processing

Figure 293 describes the GCM implementation in the SAES peripheral. The GCM is selected by writing 011 to the CHMOD[2:0] bitfield of the SAES_CR register.

Figure 293. GCM authenticated encryption

Figure 293. GCM authenticated encryption block diagram with 4 phases: (1) Init, (2) Header, (3) Payload, (4) Final.
Figure 293. GCM authenticated encryption block diagram with 4 phases: (1) Init, (2) Header, (3) Payload, (4) Final.

The mechanism for the confidentiality of the plaintext in GCM mode is similar to that in the Counter mode, with a particular increment function (denoted 32-bit increment) that generates the sequence of input counter blocks.

SAES_IVRx registers keeping the counter block of data are used for processing each data block. The SAES peripheral automatically increments the Counter[31:0] bitfield. The first counter block (CB1) is derived from the initial counter block ICB by the application software (see Table 278).

Table 278. Initialization of SAES_IVRx registers in GCM mode

SAES_IVR3[31:0]SAES_IVR2[31:0]SAES_IVR1[31:0]SAES_IVR0[31:0]
ICB[127:96]ICB[95:64]ICB[63:32]ICB[31:0]
32-bit counter = 0x0002

Note: In this mode, the setting 01 of the MODE[1:0] bitfield (key derivation) is forbidden.

The authentication mechanism in GCM mode is based on a hash function called GF2mul that performs multiplication by a fixed parameter, called hash subkey (H), within a binary Galois field.

A GCM message is processed through the following phases, further described in next subsections:

GCM init phase

During this first step, the GCM hash subkey (H) is calculated and saved internally, to be used for processing all the blocks. The recommended sequence is:

  1. 1. Verify that BUSY = 0 in SAES_SR (no RNG random number fetch in progress).
  2. 2. Disable the SAES peripheral by clearing the EN bit of the SAES_CR register.
  3. 3. Select GCM chaining mode, by setting to 011 the CHMOD[2:0] bitfield of the SAES_CR register, and optionally, set the DATATYPE[1:0] bitfield.
  4. 4. Indicate the Init phase, by setting to 00 the GCMPH[1:0] bitfield of the SAES_CR register.
  5. 5. Set the MODE[1:0] bitfield of the SAES_CR register to 00 or 10. Although the bitfield is only used in payload phase, it is recommended to set it in the Init phase and keep it unchanged in all subsequent phases.
  6. 6. Initialize the SAES_KEYRx registers with a key, and initialize SAES_IVRx registers with the information as defined in Table 278.
  7. 7. Start the calculation of the hash key, by setting to 1 the EN bit of the SAES_CR register (EN is automatically reset when the calculation finishes).
  8. 8. Wait until the end of computation, indicated by the CCF flag of the SAES_SR transiting to 1. Alternatively, use the corresponding interrupt.
  9. 9. Clear the CCF flag of the SAES_SR register, by setting the CCF bit of the SAES_ICR register.

GCM header phase

This phase coming after the GCM Init phase must be completed before the payload phase. The sequence to execute, identical for encryption and decryption, is:

  1. 1. Indicate the header phase, by setting to 01 the GCMPH[1:0] bitfield of the SAES_CR register. Do not modify the MODE[1:0] bitfield as set in the Init phase.
  2. 2. Enable the SAES peripheral by setting the EN bit of the SAES_CR register.
  3. 3. If it is the last block and the AAD size in the block is inferior to 128 bits, pad the remainder of the block with zeros. Then append the data block into SAES in one of ways described in Section 33.4.4: SAES procedure to perform a cipher operation. No data is read during this phase.
  4. 4. Repeat the step 3 until the last additional authenticated data block is processed.

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

GCM payload phase

This phase, identical for encryption and decryption, is executed after the GCM header phase. During this phase, the encrypted/decrypted payload is stored in the SAES_DOUTR register. The sequence to execute is:

  1. 1. Indicate the payload phase, by setting to 10 the GCMPH[1:0] bitfield of the SAES_CR register. Do not modify the MODE[1:0] bitfield as set in the Init phase.
  2. 2. If the header phase was skipped, enable the SAES peripheral by setting the EN bit of the SAES_CR register.
  3. 3. If it is the last block and the plaintext (encryption) or ciphertext (decryption) size in the block is inferior to 128 bits, pad the remainder of the block with zeros.
  4. 4. Append the data block into SAES in one of ways described in Section 33.4.4: SAES procedure to perform a cipher operation, and read the result.
  5. 5. Repeat the previous step till the second-last plaintext block is encrypted or till the last block of ciphertext is decrypted. For the last block of plaintext (encryption only), execute the two previous steps. For the last block, discard the bits that are not part of the payload when the last block size is less than 16 bytes.

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

GCM final phase

In this last phase, the SAES peripheral generates the GCM authentication tag and stores it in the SAES_DOUTR register. The sequence to execute is:

  1. 1. Encryption only: wait until the BUSY flag in the SAES_SR register is cleared.
  2. 2. Indicate the final phase, by setting to 11 the GCMPH[1:0] bitfield of the SAES_CR register.
  3. 3. Compose the data of the block, by concatenating the AAD bit length and the payload bit length, as shown in Table 277. Write the block into the SAES_DINR register.
  4. 4. Wait until the end of computation, indicated by the CCF flag of the SAES_SR transiting to 1.
  5. 5. Get the GCM authentication tag, by reading the SAES_DOUTR register four times.
  6. 6. Clear the CCF flag of the SAES_SR register, by setting the CCF bit of the SAES_ICR register.
  7. 7. Disable the SAES peripheral, by clearing the bit EN of the SAES_CR register. If it is an authenticated decryption, compare the generated tag with the expected tag passed with the message.

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

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

Suspend/resume operations in GCM mode

Suspend/resume operations are not supported in GCM mode.

33.4.11 SAES Galois message authentication code (GMAC)

Overview

The Galois message authentication code (GMAC) allows the authentication of a plaintext, generating the corresponding tag information (also known as message authentication code). It is based on GCM algorithm, as defined in NIST Special Publication 800-38D, Recommendation for Block Cipher Modes of Operation - Galois/Counter Mode (GCM) and GMAC.

A typical message construction for GMAC is given in Figure 294.

Figure 294. Message construction in GMAC mode

Diagram showing message construction in GMAC mode. It illustrates the flow from Initialization vector (IV) and Counter through ICB and Authenticated data to the Last block, which includes length fields [Len(A)]64 and [0]64. An authentication process (auth.) leads to the Authentication tag (T).

The diagram illustrates the message construction for GMAC mode. It shows a sequence of blocks: an Initialization vector (IV) and a Counter, which are processed by an ICB (Initial Counter Block). This is followed by a block of Authenticated data of length Len(A). The final block is the Last block, which contains the length of the authenticated data, [Len(A)]₆₄, and a zero padding block, [0]₆₄. The entire sequence is authenticated (auth.) to produce the Authentication tag (T). A legend indicates that the gray shaded area represents Zero padding.

MSv42158V2

Diagram showing message construction in GMAC mode. It illustrates the flow from Initialization vector (IV) and Counter through ICB and Authenticated data to the Last block, which includes length fields [Len(A)]64 and [0]64. An authentication process (auth.) leads to the Authentication tag (T).

AES GMAC processing

Figure 295 describes the GMAC mode implementation in the SAES peripheral. This mode is selected by writing 011 to the CHMOD[2:0] bitfield of the SAES_CR register.

Figure 295. GMAC authentication mode

Figure 295: GMAC authentication mode diagram showing stages: (1) Init with AES_KEYRx (KEY) encrypting [0]128 to generate H; (2) Header processing AES_DINR (message blocks) through Swap management and GF2mul; (4) Final computing AES_DOUTR (authentication tag T) using AES_IVRx (IV + 32-bit counter = 0x0), AES_KEYRx, len(A)64 || [0]64, GF2mul, and XOR operations.
Figure 295: GMAC authentication mode diagram showing stages: (1) Init with AES_KEYRx (KEY) encrypting [0]128 to generate H; (2) Header processing AES_DINR (message blocks) through Swap management and GF2mul; (4) Final computing AES_DOUTR (authentication tag T) using AES_IVRx (IV + 32-bit counter = 0x0), AES_KEYRx, len(A)64 || [0]64, GF2mul, and XOR operations.

The GMAC algorithm corresponds to the GCM algorithm applied on a message only containing 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

Suspend/resume operations are not supported in GMAC mode.

33.4.12 SAES counter with CBC-MAC (CCM)

Overview

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 SAES in counter mode. It uses cipher block chaining technique to generate the message authentication code. This is commonly called CBC-MAC.

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

CCM chaining is specified in NIST Special Publication 800-38C, Recommendation for Block Cipher Modes of Operation - The CCM Mode for Authentication and Confidentiality. A typical message construction for CCM is given in Figure 296.

Figure 296. Message construction in CCM mode

Diagram of message construction in CCM mode. The diagram shows a sequence of blocks: B0, Associated data (A), 0, Plaintext (P), 0, and Enc (T). B0 is further divided into flags, Nonce (N), and Q. The length of B0 is 16 bytes. The length of A is Len(A). The length of P is Len(P). The length of Enc (T) is Len(T). The total length of the message is Len(C). The diagram also shows the authentication and encryption process. The Associated data (A) is authenticated to produce MAC (T). The Plaintext (P) is encrypted to produce Authenticated & encrypted ciphertext (C). The MAC (T) is then encrypted to produce Enc (T). A 'Decrypt and compare' block is shown at the bottom, which takes the Enc (T) and the Authenticated & encrypted ciphertext (C) as input.

The diagram illustrates the message construction in CCM mode. It shows a sequence of blocks: B0, Associated data (A), 0, Plaintext (P), 0, and Enc (T). B0 is further divided into flags, Nonce (N), and Q. The length of B0 is 16 bytes. The length of A is Len(A). The length of P is Len(P). The length of Enc (T) is Len(T). The total length of the message is Len(C). The diagram also shows the authentication and encryption process. The Associated data (A) is authenticated to produce MAC (T). The Plaintext (P) is encrypted to produce Authenticated & encrypted ciphertext (C). The MAC (T) is then encrypted to produce Enc (T). A 'Decrypt and compare' block is shown at the bottom, which takes the Enc (T) and the Authenticated & encrypted ciphertext (C) as input.

Diagram of message construction in CCM mode. The diagram shows a sequence of blocks: B0, Associated data (A), 0, Plaintext (P), 0, and Enc (T). B0 is further divided into flags, Nonce (N), and Q. The length of B0 is 16 bytes. The length of A is Len(A). The length of P is Len(P). The length of Enc (T) is Len(T). The total length of the message is Len(C). The diagram also shows the authentication and encryption process. The Associated data (A) is authenticated to produce MAC (T). The Plaintext (P) is encrypted to produce Authenticated & encrypted ciphertext (C). The MAC (T) is then encrypted to produce Enc (T). A 'Decrypt and compare' block is shown at the bottom, which takes the Enc (T) and the Authenticated & encrypted ciphertext (C) as input.

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):

Generation of formatted input data blocks Bx (especially B0 and B1) must be managed by the application.

CCM processing

Figure 297 describes the CCM implementation within the SAES peripheral (encryption example). This mode is selected by writing 100 into the CHMOD[2:0] bitfield of the SAES_CR register.

Figure 297. CCM mode authenticated encryption

A detailed block diagram of CCM mode authenticated encryption. It is divided into four main sections: (1) Init, (2) Header, (3) Payload, and (4) Final. Section (1) Init shows the generation of the first block B0 from CTR0 and KEY. Section (2) Header shows the processing of associated data blocks B1 and Bu. Section (3) Payload shows the encryption of plaintext blocks P1 through Pm. Section (4) Final shows the generation of the MAC (T) and EncTAG from CTR0 and the last ciphertext block Cm. The diagram includes components like AES_IVRx, AES_KEYRx, Encrypt blocks, Counter increment, Swap management, and XOR operations. A legend indicates that light gray boxes are inputs, dark gray boxes are outputs, and the circle with a plus sign represents an XOR operation. The diagram is labeled MSv42152V2.
A detailed block diagram of CCM mode authenticated encryption. It is divided into four main sections: (1) Init, (2) Header, (3) Payload, and (4) Final. Section (1) Init shows the generation of the first block B0 from CTR0 and KEY. Section (2) Header shows the processing of associated data blocks B1 and Bu. Section (3) Payload shows the encryption of plaintext blocks P1 through Pm. Section (4) Final shows the generation of the MAC (T) and EncTAG from CTR0 and the last ciphertext block Cm. The diagram includes components like AES_IVRx, AES_KEYRx, Encrypt blocks, Counter increment, Swap management, and XOR operations. A legend indicates that light gray boxes are inputs, dark gray boxes are outputs, and the circle with a plus sign represents an XOR operation. The diagram is labeled MSv42152V2.

The data input to the generation-encryption process are a valid nonce, a valid payload string, and a valid associated data string, all properly formatted. The CBC chaining mechanism is applied to the formatted plaintext data to generate a MAC, with a known length. Counter mode encryption that requires a sufficiently long sequence of counter blocks as input, is applied to the payload string and separately to the MAC. The resulting ciphertext C is the output of the generation-encryption process on plaintext P.

SAES_IVRx registers are used for processing each data block, SAES automatically incrementing the CTR counter with a bit length defined by the first block B0. Table 279 shows how the application must load the B0 data.

Note: The SAES peripheral in CCM mode supports counters up to 64 bits, as specified by NIST.

Table 279. Initialization of SAES_IVRx registers in CCM mode

SAES_IVR3[31:0]SAES_IVR2[31:0]SAES_IVR1[31:0]SAES_IVR0[31:0]
B0[127:96]B0[95:64]B0[63:32]B0[31:0]

Note: In this mode, the setting 01 of the MODE[1:0] bitfield (key derivation) is forbidden.

A CCM message is processed through the following phases, further described in next subsections:

CCM Init phase

In this phase, the first block B0 of the CCM message is written into the SAES_IVRx register. The SAES_DOUTR register does not contain any output data. The recommended sequence is:

  1. 1. Verify that BUSY = 0 in SAES_SR (no RNG random number fetch in progress).
  2. 2. Disable the SAES peripheral by clearing the EN bit of the SAES_CR register.
  3. 3. Select CCM chaining mode, by setting to 100 the CHMOD[2:0] bitfield of the SAES_CR register, and optionally, set the DATATYPE[1:0] bitfield.
  4. 4. Indicate the Init phase, by setting to 00 the GCMPH[1:0] bitfield of the SAES_CR register.
  5. 5. Set the MODE[1:0] bitfield of the SAES_CR register to 00 or 10. Although the bitfield is only used in payload phase, it is recommended to set it in the Init phase and keep it unchanged in all subsequent phases.
  6. 6. Initialize the SAES_KEYRx registers with a key, and initialize SAES_IVRx registers with B0 data as described in Table 279.
  7. 7. Start the calculation of the counter, by setting to 1 the EN bit of the SAES_CR register (EN is automatically reset when the calculation finishes).
  8. 8. Wait until the end of computation, indicated by the CCF flag of the SAES_SR transiting to 1. Alternatively, use the corresponding interrupt.
  9. 9. Clear the CCF flag in the SAES_SR register, by setting to 1 the CCF bit of the SAES_ICR register.

CCM header phase

This phase coming after the GCM Init phase must be completed before the payload phase. During this phase, the SAES_DOUTR register does not contain any output data.

The sequence to execute, identical for encryption and decryption, is:

  1. 1. Indicate the header phase, by setting to 01 the GCMPH[1:0] bitfield of the SAES_CR register. Do not modify the MODE[1:0] bitfield as set in the Init phase.
  2. 2. Enable the SAES peripheral by setting the EN bit of the SAES_CR register.
  3. 3. If it is the last block and the AAD size in the block is inferior to 128 bits, pad the remainder of the block with zeros. Then append the data block into SAES in one of ways described in Section 33.4.4: SAES procedure to perform a cipher operation. No data is read during this phase.
  4. 4. Repeat the step 3 until the last additional authenticated data block is processed.

Note: The header phase can be skipped if there is no associated data, that is, Len(A) = 0.
The first block of the associated data (B1) must be formatted by software, with the associated data length.

CCM payload phase (encryption or decryption)

This phase, identical for encryption and decryption, is executed after the CCM header phase. During this phase, the encrypted/decrypted payload is stored in the SAES_DOUTR register. The sequence to execute is:

  1. 1. Indicate the payload phase, by setting to 10 the GCMPH[1:0] bitfield of the SAES_CR register. Do not modify the MODE[1:0] bitfield as set in the Init phase.
  2. 2. If the header phase was skipped, enable the SAES peripheral by setting the EN bit of the SAES_CR register.
  3. 3. If it is the last data block to encrypt and the plaintext size in the block is inferior to 128 bits, pad the remainder of the block with zeros.
  4. 4. Append the data block into SAES in one of ways described in Section 33.4.4: SAES procedure to perform a cipher operation, and read the result.
  5. 5. Repeat the previous step till the second-last plaintext block is encrypted or till the last block of ciphertext is decrypted. For the last block of plaintext (encryption only), apply the two previous steps. For the last block, discard the data that is not part of the payload when the last block size is less than 16 bytes.

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

CCM final phase

In this last phase, the SAES peripheral generates the GCM authentication tag and stores it in the SAES_DOUTR register. The sequence to execute is:

  1. 1. Indicate the final phase, by setting to 11 the GCMPH[1:0] bitfield of the SAES_CR register.
  2. 2. Wait until the end-of-computation flag CCF of the SAES_SR register is set.
  3. 3. Read four times the SAES_DOUTR register: the output corresponds to the CCM authentication tag.
  4. 4. Clear the CCF flag of the SAES_SR register by setting the CCF bit of the SAES_ICR register.
  5. 5. Disable the SAES peripheral, by clearing the EN bit of the SAES_CR register.
  6. 6. For authenticated decryption, compare the generated encrypted tag with the encrypted tag padded in the ciphertext.

Note: In this final phase, swapping is applied to tag data read from SAES_DOUTR register.

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

Application must mask the authentication tag output with tag length to obtain a valid tag.

Suspend/resume operations in CCM mode

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

  1. 1. If DMA is used, stop the SAES DMA transfers to the IN FIFO by clearing the DMAINEN bit of the SAES_CR register. If DMA is not used, make sure that the current computation is completed, which is indicated by the CCF flag of the SAES_SR register set to 1.
  2. 2. In the payload phase, if DMA is not used, read four times the SAES_DOUTR register to save the last-processed block. If DMA is used, wait until the CCF flag is set in the SAES_SR register then stop the DMA transfers from the OUT FIFO by clearing the DMAOUTEN bit of the SAES_CR register.
  3. 3. Clear the CCF flag of the SAES_SR register, by setting to 1 the CCF bit of the SAES_ICR register.
  4. 4. Save the SAES_SUSPxR registers (where x is from 0 to 7) in the memory.
  5. 5. Save the SAES_IVRx registers as, during the data processing, they changed from their initial values.
  6. 6. Disable the SAES peripheral, by clearing the EN bit of the SAES_CR register.
  7. 7. Save the current SAES configuration in the memory, excluding the initialization vector registers SAES_IVRx. Key registers do not need to be saved as the original key value is known by the application.
  8. 8. If DMA is used, save the DMA controller status (pointers for IN data transfers, number of remaining bytes, and so on). In the payload phase, pointers for OUT data transfers must also be saved.

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

  1. 1. If DMA is used, configure the DMA controller in order to complete the rest of the FIFO IN transfers. In the payload phase, the rest of the FIFO OUT transfers must also be configured in the DMA controller.
  2. 2. Disable the SAES peripheral by clearing the EN bit of the SAES_CR register.
  3. 3. Write the suspend register values, previously saved in the memory, back into their corresponding SAES_SUSPxR registers (where x is from 0 to 7).
  4. 4. Write the initialization vector register values, previously saved in the memory, back into their corresponding SAES_IVRx registers.
  5. 5. Restore the initial setting values in the SAES_CR and SAES_KEYRx registers.
  6. 6. Enable the SAES peripheral by setting the EN bit of the SAES_CR register.
  7. 7. If DMA is used, enable SAES DMA requests by setting to 1 the DMAINEN bit (and DMAOUTEN bit if in payload phase) of the SAES_CR register.

33.4.13 SAES operation with wrapped keys

SAES peripheral can wrap (encrypt) and unwrap (decrypt) application keys using hardware-secret key DHUK, XOR-ed or not with application key BHK. With this feature, AES keys can be made usable by application software without being exposed in clear-text (unencrypted).

Wrapped key sequences are too small to be suspended/resumed. SAES cannot unwrap a key using an unwrapped key.

Operation with wrapped keys in ECB and CBC modes

Figure 298 summarizes the operation with wrapped keys in ECB and CBC modes. To protect the wrapped key, select DHUK by setting KEYSEL[2:0] to 001 or 100. Alternatively, select BHK by setting KEYSEL to 010 if the corresponding registers are read/write-locked in the TAMP peripheral.

Figure 298. Operation with wrapped keys in ECB and CBC modes

Diagram showing SAES operation with wrapped keys in ECB and CBC modes. It is divided into three steps: Step 1: provision, Step 2: load, and Step 3: use. Step 1 shows encryption of a clear-text key (DIN) using SAES enc to produce a wrapped (encrypted) key (DOUT). Step 2 shows decryption of a wrapped key (DIN) using SAES dec to produce an unwrapped (decrypted) key (DOUT). Step 3 shows the use of the unwrapped key (DIN) with SAES enc/dec to produce DOUT. The diagram includes keying information: KEYSEL = 001 or 100, MODE = 00 (encryption) for Step 1; KEYSEL = 001 or 100, MODE = 10 (decryption) for Step 2; and KEYSEL = 00, MODE = any value for Step 3. A pink note indicates that DHUK and BHK are hardware secrets not readable by application.

Wrapped-key mode (KMOD = 01)

Step 1: provision
DIN: clear-text key
SAES enc
DOUT: wrapped (encrypted) key
KEYSEL = 001 or 100
MODE = 00 (encryption)

Step 2: load
DIN: wrapped key
SAES dec
DOUT: unwrapped (decrypted) key
KEYSEL = 001 or 100
MODE = 10 (decryption)

Normal-key mode (KMOD = 00)

Step 3: use
DIN: unwrapped key
SAES enc/dec
DOUT
KEYSEL = 00 (to keep the wrapped key)
MODE = any value

Pink: hardware secret (not readable by application)

Diagram showing SAES operation with wrapped keys in ECB and CBC modes. It is divided into three steps: Step 1: provision, Step 2: load, and Step 3: use. Step 1 shows encryption of a clear-text key (DIN) using SAES enc to produce a wrapped (encrypted) key (DOUT). Step 2 shows decryption of a wrapped key (DIN) using SAES dec to produce an unwrapped (decrypted) key (DOUT). Step 3 shows the use of the unwrapped key (DIN) with SAES enc/dec to produce DOUT. The diagram includes keying information: KEYSEL = 001 or 100, MODE = 00 (encryption) for Step 1; KEYSEL = 001 or 100, MODE = 10 (decryption) for Step 2; and KEYSEL = 00, MODE = any value for Step 3. A pink note indicates that DHUK and BHK are hardware secrets not readable by application.

Note: DHUK value depends on privilege, KMOD[1:0], KEYSEL, CHMOD[2:0], and on whether SAES peripheral is secure or nonsecure.

Encryption in Wrapped-key mode

Recommended sequence to wrap (that is, encrypt) a key is described below:

  1. 1. Verify that BUSY = 0 in SAES_SR (no RNG random number fetch in progress).
  2. 2. Disable the SAES peripheral by clearing the EN bit of the SAES_CR register.
  3. 3. In SAES_CR register, select the Mode 1 (encryption) by setting to 00 the MODE[1:0] bitfield, and select ECB or CBC chaining mode by setting CHMOD[2:0] bitfield to 000 or 001, respectively. Data type can be defined as 32-bit, with DATATYPE[1:0] bitfield set to 00. Key size must be properly configured using KEYSIZE bit, and KMOD[1:0] bitfield must be set as 01 (wrapped key). The KEYSIZE information is used both for the encryption key and for the key to be encrypted.
  4. 4. Write the SAES_IVRx registers with the initialization vector if CBC mode has been selected in previous step.
  5. 5. Select the DHUK by setting the KEYSEL[2:0] bitfield of the SAES_CR register to 001 or 100. Upon successful key loading BUSY bit is cleared and KEYVALID bit is set in SAES_SR register. Refer to Section 33.4.16: SAES key registers for detail on KEYSEL = 100 usage.
  6. 6. Enable SAES by setting the EN bit of the SAES_CR register.
  7. 7. Write the SAES_DINR register four times to input the key to encrypt (MSB first, see Table 280 on page 1820).
  8. 8. Wait until the CCF flag is set in the SAES_SR register.
  9. 9. Get the encrypted key (MSB first) by reading the SAES_DOUTR register four times. Then clear the CCF flag by setting the CCF bit in SAES_ICR register.
  10. 10. Repeat steps 6 to 8 if KEYSIZE is 256 bits.

Note: Encryption in Wrapped-key mode is only supported when ECB or CBC is selected through CHMOD[2:0].

Decryption in Wrapped-key mode

Recommended sequence to unwrap (i.e. decrypt) a wrapped key is described below:

  1. 1. Verify that BUSY = 0 in SAES_SR (no RNG random number fetch in progress).
  2. 2. Disable the SAES peripheral by clearing the EN bit of the SAES_CR register.
  3. 3. SAES_CR register, select the Mode 2 by setting to 01 the MODE[1:0] bitfield, and select ECB or CBC chaining mode by setting CHMOD[2:0] to 000 or 001, respectively. Key size must be properly configured using KEYSIZE bit, and KMOD[1:0] bitfield must be set as 01 (wrapped key). Data type selection with DATATYPE[1:0] bitfield must be the same as the one used during encryption (that is, 0x0). The KEYSIZE information is used both for the decryption key and for the key to be decrypted.

    If the decrypted key is not to share with a different security context (different security attribute), the KEYPROT bit of the SAES_CR register must also be set.
  4. 4. Select the DHUK by setting the KEYSEL[2:0] bitfield of the SAES_CR register to 001 or 100. Upon successful key loading, the SAES_SR register BUSY bit is cleared and KEYVALID bit set. Refer to Section 33.4.16: SAES key registers for detail on KEYSEL = 100 usage.
  5. 5. Enable SAES by setting the EN bit of the SAES_CR register.
  1. 6. Wait until the CCF flag is set in the SAES_SR register.
  2. 7. Clear the CCF flag. Decryption key is available in AES core, and SAES is disabled automatically.
  3. 8. In SAES_CR register select the Mode 3 by setting to 10 the MODE[1:0] bitfield.
  4. 9. Write the SAES_IVRx registers with the initialization vector if CBC mode has been selected in previous step.
  5. 10. Enable SAES by setting the EN bit of the SAES_CR register.
  6. 11. Write the SAES_DINR register four times to input the encrypted random key (MSB first, see Table 280 on page 1820).
  7. 12. Wait until the CCF flag is set in the SAES_SR register.
  8. 13. Clear the CCF flag, then repeat steps 10 and 11 if KEYSIZE is 256 bits.

When the decrypted key is loaded in key registers, KEYSEL[2:0] of the SAES_CR register is automatically cleared. Hence, after this sequence, the decrypted wrapped key is available in SAES_KEYRx registers, immediately usable by the application software for any AES operation (normal key mode, that is, with KMOD[1:0] = 00).

Decrypted wrapped key can be shared with an application running in a different security context (different security attribute) if KEYPROT bit was cleared during step 2.

Note: When KMOD[1:0] = 01 (wrapped key) and MODE[1:0] = 10 (decryption) a read access to SAES_DOUTR register triggers a read error (RDERR).

When KEYSEL[2:0] = 001 (DHUK) or 100 (DHUK XOR BHK), the application software must use the same privilege, security, KMOD[1:0], CHMOD[2:0] and KEYSIZE context for encryption and decryption. Otherwise, the result is incorrect.

Operation with wrapped keys in CTR mode

Figure 299 summarizes the operation with wrapped keys in CTR mode. To protect the derived key, select DHUK by setting KEYSEL[2:0] to 001 or 100. Alternatively, select BHK by setting KEYSEL to 010 if the corresponding registers are read/write-locked in the TAMP peripheral.

Figure 299. Operation with wrapped keys in CTR mode

Diagram illustrating the operation with wrapped keys in CTR mode, divided into two steps: Step 1: provision and Step 2: use.

The diagram is divided into two main sections by a vertical dashed line:

Diagram illustrating the operation with wrapped keys in CTR mode, divided into two steps: Step 1: provision and Step 2: use.

Note: DHUK value depends on privilege, KMOD[1:0], KEYSEL, CHMOD[2:0], and on whether SAES peripheral is secure or nonsecure.

The recommended sequence to use SAES Wrapped-key mode with stream cipher (CTR) is:

  1. 1. Verify that BUSY = 0 in SAES_SR (no RNG random number fetch in progress).
  2. 2. Disable the SAES peripheral by clearing the EN bit of the SAES_CR register.
  3. 3. Set KMOD[1:0] bitfield of the SAES_CR register to 01 (wrapped key) and select CTR chaining mode through CHMOD[2:0]. Keep DATATYPE[1:0] at 00, and set MODE to 10 (the value 00 is not supported). Configure the key size appropriately with the KEYSIZE bit. It is used both for the cipher key and for the key to load.
  4. 4. Select DHUK by setting KEYSEL[2:0] to 001 or 100 in the SAES_CR register. Upon the successful key load, the BUSY bit is cleared and the KEYVALID bit is set in the SAES_SR register. Refer to Figure 33.4.16 for detail on KEYSEL = 100 usage.
  5. 5. Load the SAES_IVRx registers, keeping the two least significant bits of SAES_IVR0 at 00
  6. 6. Enable SAES by setting the EN bit of the SAES_CR register.
  7. 7. Wait until the CCF flag is set in the SAES_SR register.
  8. 8. Clear the CCF flag. Derived hardware secret key is available in SAES_KEYRx registers.
  9. 9. Disable the SAES peripheral, by clearing the bit EN of the SAES_CR register.

The hardware secret key derived from the public data in SAES_IVRx registers is automatically loaded in the SAES_KEYRx registers, which also clears the KEYSEL[2:0] bitfield of the SAES_CR register. The hardware secret key is then immediately usable by the application software for any AES operation (normal key mode, that is, with KMOD[1:0] = 00).

Note: The setting KMOD[1:0] = 01 (wrapped key), CHMOD[2:0] = 010 (CTR chaining), and MODE = 00 (encryption) disables the peripheral by automatically clearing the EN bit of the SAES_CR register.

33.4.14 SAES operation with shared keys

SAES peripheral can share application keys wrapped with hardware-secret key DHUK, XOR-ed or not with application key BHK. With this feature, the application software can make the AES keys available to the CRYIP peripheral, without exposing them in clear-text (unencrypted).

Shared key sequences are too small to be suspended/resumed. SAES cannot unwrap a shared key using an unwrapped key.

Note: When a key stored in SAES is shared with CRYIP, the protection given by KEYPROT bit is lost. The protection is detailed in Section 33.4.16: SAES key registers.

Figure 300 summarizes how to use Shared-key mode. To protect the shared key, DHUK must be selected, by setting KEYSEL[2:0] to 001 or 100. Alternatively, select BHK by setting KEYSEL to 010 if the corresponding registers are read/write-locked in the TAMP peripheral.

Figure 300. Usage of Shared-key mode

Diagram showing the usage of Shared-key mode (KMOD = 10) and Normal-key mode (KMOD = 00) in three steps: provision, load, and use. Step 1 (provision) shows SAES encryption of a clear-text shared key. Step 2 (load) shows SAES decryption of a wrapped shared key. Step 3 (use) shows the shared key being used by an AES peripheral. Pink text indicates hardware secrets not readable by application.

The diagram illustrates the usage of Shared-key mode (KMOD = 10) and Normal-key mode (KMOD = 00) in three steps: Step 1: provision, Step 2: load, and Step 3: use.

Pink: hardware secret (not readable by application)

Diagram showing the usage of Shared-key mode (KMOD = 10) and Normal-key mode (KMOD = 00) in three steps: provision, load, and use. Step 1 (provision) shows SAES encryption of a clear-text shared key. Step 2 (load) shows SAES decryption of a wrapped shared key. Step 3 (use) shows the shared key being used by an AES peripheral. Pink text indicates hardware secrets not readable by application.

Note: DHUK value depends on privilege, KMOD[1:0], KSHAREID, KEYSEL, CHMOD[2:0], and on whether SAES peripheral is secure or nonsecure.

In the step 3, AES represents the CRYPP peripheral.

Encryption in Shared-key mode

Before SAES can share a key with the CRYPP peripheral, the key must be encrypted once. The encryption sequence of a shared key is the same as for a wrapped key, with KMOD[1:0] set to 10 (shared key) and KSHAREID[1:0] kept at 00 in the step 3 in Figure 300. See Encryption in Wrapped-key mode for details.

Note: Encryption in Shared-key mode is only supported when ECB or CBC is selected through CHMOD[2:0].

Decryption in Shared-key mode

Each time SAES needs to share a key with the CRYPP peripheral, shared encrypted key must be decrypted in SAES, then loaded by the CRYPP. The overall sequence is described next.

Sequence in the SAES peripheral

The decryption sequence of a shared key is the same as for a wrapped key, with KMOD[1:0] set to 10 (shared key) and KSHAREID[1:0] kept at 00 in the step 3 in Figure 300. See Decryption in Wrapped-key mode for details.

Note: Instead of being shared, a decrypted shared key can be used directly in SAES as the KEYSEL[2:0] bitfield is automatically cleared. In this case, KMOD[1:0] must be set to 00 (normal key mode).

Sequence in the CRYPP peripheral

Once the shared key is decrypted in SAES key registers, it can be shared with the CRYPP peripheral, while SAES peripheral remains in key sharing state, that is, with KMOD[1:0] = 10 and KEYVALID = 1 in the SAES_SR register. The sequence in the CRYPP key share target peripheral is as follows:

  1. 1. Initialize the AES processor to process some data
  2. 2. When the key must be loaded, set the same KEYSIZE as for the SAES peripheral and write the KMOD[1:0] bitfield of the CRYP_CR register to 10 (shared key). If the previous sequence in the SAES peripheral completed successfully, with KMOD[1:0] kept at 10 and KSHAREID[1:0] kept at 00, the SAES_KEYRx registers are automatically copied into the CRYP_KEYRx registers, with BUSY set in CRYP_SR.
  3. 3. Once the transfer is completed, the BUSY flag is cleared and KEYVALID set in the CRYP_SR register. If KEYVALID is not set when BUSY bit is cleared, or if a key error flag (KEIF) is set an unexpected event occurred during the transfer, such as a DPA error, a tamper event or the KEYVALID SAES flag was cleared before the end of the transfer. When such errors occur, the whole key sharing process starting from the SAES peripheral must be restarted, through the IPRST bits of both control registers.
  4. 4. As KEYVALID is set, the key share target peripheral is initialized with a valid, shared key. The application can proceed with the data processing of data, setting KMOD[1:0] to 00.

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

Note: in SAES peripheral, when KMOD[1:0] = 10 (shared key) and MODE[1:0] = 10 (decryption), a read access to the SAES_DOUTR register triggers a read error (RDERR).

When KEYSEL[2:0] = 001 (DHUK) or 100 (DHUK XOR BHK), the application software must use the same privilege, security, KMOD[1:0] / KSHAREID[1:0], CHMOD[2:0], and KEYSIZE context for encryption and decryption. Otherwise, the result is incorrect.

When KMOD[1:0] = 10 and BUSY = 1 in the CRYP peripheral and KEYSIZE value of CRYP and SAES differs, the key sharing fails and the KEIF flag is raised in both peripherals.

33.4.15 SAES data registers and data swapping

Data input and output

A 128-bit data block is entered into the SAES peripheral with four successive 32-bit word writes into the SAES_DINR register (bitfield DIN[31:0]), the most significant word (bits [127:96]) first, the least significant word (bits [31:0]) last.

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

The 32-bit data word for SAES_DINR register or from SAES_DOUTR register is organized in big endian order, that is:

For using DMA for input data block write into SAES, the four words of the input block must be stored in the memory consecutively and in big-endian order, that is, the most significant word on the lowest address. See Section 33.4.18: SAES DMA interface.

Data swapping

The SAES peripheral can be configured to perform a bit-, a byte-, a half-word-, or no swapping on the input data word in the SAES_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 SAES_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 the DATATYPE[1:0] bitfield of the SAES_CR register. The selection applies both to the input and the output of the AES core.

For different data swap types, Figure 301 shows the construction of AES processing core input buffer data P127 to P0, from the input data entered through the SAES_DINR register, or the construction of the output data available through the SAES_DOUTR register, from the AES processing core output buffer data P127 to P0.

Figure 301. 128-bit block construction with respect to data swap

Figure 301: 128-bit block construction with respect to data swap. The diagram shows four scenarios based on the DATATYPE[1:0] register value: 00 (no swapping), 01 (16-bit (half-word) swapping), 10 (8-bit (byte) swapping), and 11 (bit swapping). Each scenario illustrates the mapping of 128 bits from memory (Words 0-3) to the AES core buffer. A legend at the bottom explains the symbols used, including MSB, LSB, zero padding, and data swap arrows.

increasing memory address

byte 3 byte 2 byte 1 byte 0
D63 D56 D55 D48 D47 D40 D39 D32

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:

MSv42153V2

Figure 301: 128-bit block construction with respect to data swap. The diagram shows four scenarios based on the DATATYPE[1:0] register value: 00 (no swapping), 01 (16-bit (half-word) swapping), 10 (8-bit (byte) swapping), and 11 (bit swapping). Each scenario illustrates the mapping of 128 bits from memory (Words 0-3) to the AES core buffer. A legend at the bottom explains the symbols used, including MSB, LSB, zero padding, and data swap arrows.

Note: The data in SAES key registers (SAES_KEYRx) and initialization registers (SAES_IVRx) are not sensitive to the swap mode selection.

Data padding

Figure 301 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:

33.4.16 SAES key registers

The SAES_KEYRx write-only registers store the encryption or decryption key bitfield KEY[127:0] or KEY[255:0]. The data to write to each register is organized in the memory in little-endian order, that is, with most significant byte on the highest address (reads are not allowed for security reason).

The key is spread over eight registers as shown in Table 280.

Table 280. Key endianness in SAES_KEYRx registers (128- or 256-bit key length)

SAES_KEYR
7
[31:0]
SAES_KEYR
6
[31:0]
SAES_KEYR
5
[31:0]
SAES_KEYR
4
[31:0]
SAES_KEYR
3
[31:0]
SAES_KEYR
2
[31:0]
SAES_KEYR
1
[31:0]
SAES_KEYR
0
[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]
TAMP_BKP7R
[31:0]
TAMP_BKP6R
[31:0]
TAMP_BKP5R
[31:0]
TAMP_BKP4R
[31:0]
TAMP_BKP3R
[31:0]
TAMP_BKP2R
[31:0]
TAMP_BKP1R
[31:0]
TAMP_BKP0R
[31:0]

The key for encryption or decryption may be written into these registers when the SAES peripheral is disabled, by clearing the EN bit and the KEYSEL[2:0] bitfield of the SAES_CR register.

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

The entire key must be written before starting an AES computation. In normal key mode (KMOD[1:0] = 00), with KEYSEL[2:0] = 000, the SAES_KEYRx (x = 0 to 3 for KEYSIZE = 0, x = 0 to 7 for KEYSIZE = 1) registers must always be written in either ascending or descending order.

With KEYSEL[2:0] set to 001, a derived hardware unique key (DHUK), computed inside the SAES engine from a non-volatile OTP-based root hardware unique key, is loaded directly into key registers, based on KEYSIZE information.

With KEYSEL[2:0] set to 010, the boot hardware key (BHK), stored in tamper-resistant secure backup registers, is entirely transferred into key registers upon a secure application performing a single read of all TAMP_BKPxR registers (x = 0 to 3 for KEYSIZE = 0, x = 0 to 7 for KEYSIZE = 1) in either ascending or descending order. Refer to Table 280.

With KEYSEL[2:0] set to 100, the XOR combination of DHUK and BHK is entirely transferred into key registers upon a secure application performing a single read of all TAMP_BKPxR registers (x = 0 to 3 for KEYSIZE = 0, x = 0 to 7 for KEYSIZE = 1) in either ascending or descending order. Refer to Table 280.

Repeated writing of KEYSEL[2:0] with the same non-zero value only triggers the loading of DHUK or BHK if KEYVALID = 0. The recommended method to clear KEYVALID is to set the IPRST bit in the SAES_CR register. Such method is required for example when switching from ECB decryption to ECB encryption, selecting the same BHK (KEYSEL[2:0] = 010).

The KEYPROT bit of SAES_CR register must be set if the key to load in key registers must not be shared with an application executing in a different security context (that is, different security attribute). Setting KEYPROT and KEYVALID makes KEIF flag an error upon SAES access attempts by an application executing in a different security context than the one that loaded the key, as shown in Figure 302.

Note: KEYSEL[2:0] values different from zero (normal key) automatically protect the key registers.

DHUK, BHK and their XOR combination are not readable by any software (even secure). Secure SAES uses secure DHUK. Nonsecure SAES uses nonsecure DHUK.

Figure 302. Key protection mechanisms

Diagram illustrating key protection mechanisms between Security context A (secure) and Security context B (nonsecure).

The diagram illustrates key protection mechanisms between two security contexts: Security context A (for example secure) and Security context B (for example nonsecure). Each context contains an SAES block with a key icon.

MSv63151V1

Diagram illustrating key protection mechanisms between Security context A (secure) and Security context B (nonsecure).

Note: Initiating the key-loading sequence sets the BUSY flag and clears the KEYVALID flag. Once the amount of bits defined by KEYSIZE is transferred to the SAES_KEYRx registers, BUSY is cleared, KEYVALID set and the EN bit becomes writable. If an error occurs, BUSY and KEYVALID are cleared and KEIF set (see Section 33.4.19: SAES error management for details). This holds for all KEYSEL values. For additional information on key modes, refer to Section 33.4.14 and Section 33.4.13.

33.4.17 SAES initialization vector registers

The four SAES_IVRx registers keep the initialization vector input bitfield IVI[127:0]. The data to write to or to read from each register is organized in the memory in little-endian order, that is, with most significant byte on the highest address. The registers are also ordered from lowest address (SAES_IVR0) to highest address (SAES_IVR3).

The signification of data in the bitfield depends on the chaining mode selected. When used, the bitfield is updated upon each computation cycle of the AES core.

Write operations to the SAES_IVRx registers when the SAES peripheral is enabled have no effect to the register contents. For modifying the contents of the SAES_IVRx registers, the EN bit of the SAES_CR register must first be cleared.

Reading the SAES_IVRx registers returns the latest counter value (useful for managing suspend mode).

The SAES_IVRx registers are not affected by the data swapping feature controlled by the DATATYPE[1:0] bitfield of the SAES_CR register.

33.4.18 SAES DMA interface

The SAES peripheral provides an interface to connect to the DMA (direct memory access) controller. The DMA operation is controlled through the SAES_CR register.

Data input using DMA

Setting the DMAINEN bit of the SAES_CR register enables DMA writing into SAES. The SAES peripheral then initiates a DMA request during the input phase each time it requires to write a 128-bit block (quadruple word) to the SAES_DINR register, as shown in Figure 303.

Note: According to the algorithm and the mode selected, special padding / ciphertext stealing might be required. For example, in case of AES GCM encryption or AES CCM decryption, a DMA transfer must not include the last block. For details, refer to Section 33.4.4: SAES procedure to perform a cipher operation.

Figure 303. DMA transfer of a 128-bit data block during input phase

Diagram showing the DMA transfer of a 128-bit data block during the input phase. It illustrates the flow from memory accessed through DMA (Words 0-3) to the SAES_DINR register and then to the AES core input buffer. It includes DMA requests (DMA req N to N+3), single write operations, and the order of writing to the AES_DINR register (1-4).

The diagram illustrates the DMA transfer of a 128-bit data block during the input phase. It is divided into three main sections: 'Memory accessed through DMA', 'SAES peripheral', and 'AES peripheral'.

Labels 'MSB' and 'LSB' are used to indicate the most significant and least significant bits of the data blocks. The diagram is labeled 'MSv42160V1'.

Diagram showing the DMA transfer of a 128-bit data block during the input phase. It illustrates the flow from memory accessed through DMA (Words 0-3) to the SAES_DINR register and then to the AES core input buffer. It includes DMA requests (DMA req N to N+3), single write operations, and the order of writing to the AES_DINR register (1-4).

Data output using DMA

Setting the DMAOUTEN bit of the SAES_CR register enables DMA reading from SAES. The SAES peripheral then initiates a DMA request during the Output phase each time it

requires to read a 128-bit block (quadruple word) to the SAES_DINR register, as shown in Figure 304.

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

Figure 304. DMA transfer of a 128-bit data block during output phase

Diagram illustrating the DMA transfer of a 128-bit data block during the output phase. The diagram shows the flow of data from the AES core output buffer through the AES_DOUTR register to memory accessed through DMA. The process is divided into four steps (1-4) corresponding to the four words of the 128-bit block. Step 1: DMA req N triggers a single read from the AES_DOUTR register (Word3, D127:D96) to memory. Step 2: DMA req N+1 triggers a single read from the AES_DOUTR register (Word2, D95:D64) to memory. Step 3: DMA req N+2 triggers a single read from the AES_DOUTR register (Word1, D63:D32) to memory. Step 4: DMA req N+3 triggers a single read from the AES_DOUTR register (Word0, D31:D0) to memory. The AES core output buffer contains the data words (O127:O0) and the AES_DOUTR register contains the data words (D127:D0). The diagram also shows the order of read from the AES_DOUTR register (1-4) and the order of read from memory (1-4).

The diagram illustrates the DMA transfer of a 128-bit data block during the output phase. It shows the flow of data from the AES core output buffer through the AES_DOUTR register to memory accessed through DMA. The process is divided into four steps (1-4) corresponding to the four words of the 128-bit block. Step 1: DMA req N triggers a single read from the AES_DOUTR register (Word3, D127:D96) to memory. Step 2: DMA req N+1 triggers a single read from the AES_DOUTR register (Word2, D95:D64) to memory. Step 3: DMA req N+2 triggers a single read from the AES_DOUTR register (Word1, D63:D32) to memory. Step 4: DMA req N+3 triggers a single read from the AES_DOUTR register (Word0, D31:D0) to memory. The AES core output buffer contains the data words (O127:O0) and the AES_DOUTR register contains the data words (D127:D0). The diagram also shows the order of read from the AES_DOUTR register (1-4) and the order of read from memory (1-4).

Diagram illustrating the DMA transfer of a 128-bit data block during the output phase. The diagram shows the flow of data from the AES core output buffer through the AES_DOUTR register to memory accessed through DMA. The process is divided into four steps (1-4) corresponding to the four words of the 128-bit block. Step 1: DMA req N triggers a single read from the AES_DOUTR register (Word3, D127:D96) to memory. Step 2: DMA req N+1 triggers a single read from the AES_DOUTR register (Word2, D95:D64) to memory. Step 3: DMA req N+2 triggers a single read from the AES_DOUTR register (Word1, D63:D32) to memory. Step 4: DMA req N+3 triggers a single read from the AES_DOUTR register (Word0, D31:D0) to memory. The AES core output buffer contains the data words (O127:O0) and the AES_DOUTR register contains the data words (D127:D0). The diagram also shows the order of read from the AES_DOUTR register (1-4) and the order of read from memory (1-4).

DMA operation in different operating modes

DMA operations are usable when Mode 1 (encryption) or Mode 3 (decryption) are selected via the MODE[1:0] bitfield of the register SAES_CR. As in Mode 2 (key derivation) the SAES_KEYRx registers must be written by software, enabling the DMA transfer through the DMAINEN and DMAOUTEN bits of the SAES_CR register have no effect in that mode.

DMA single requests are generated by SAES until it is disabled. So, after the data output phase at the end of processing of a 128-bit data block, SAES switches automatically to a new data input phase for the next data block, if any.

When the data transferring between SAES and memory is managed by DMA, the CCF flag has no use because the reading of the SAES_DOUTR register is managed by DMA automatically at the end of the computation phase. The CCF flag must only be cleared when transitioning back to data transferring managed by software. See Section 33.4.4: SAES procedure to perform a cipher operation, subsection Data append, for details.

33.4.19 SAES error management

Unless indicated otherwise, SAES configuration can be changed at any moment by clearing the EN bit of the SAES_CR register.

Read error flag (RDERR)

Unexpected read attempt of the SAES_DOUTR register sets the RDERR flag of the SAES_SR register and the RWEIF flag of the SAES_ISR register, and returns zero.

RDERR is triggered during the computation phase or during the input phase.

Note: Unless indicated otherwise, SAES is not disabled upon a RDERR error detection and continues processing.

An interrupt is generated if the RWEIE bit of the SAES_IER register is set. For more details, refer to Section 33.5: SAES interrupts.

The RDERR and RWEIF flag is cleared by setting the RWEIE bit of the SAES_ICR register.

Write error flag (WDERR)

Unexpected write attempt of the SAES_DINR register sets the WRERR flag of the SAES_SR register and the RWEIF flag of the SAES_ISR register, and has no effect on the SAES_DINR register. The WRERR is triggered during the computation phase or during the output phase.

Note: Unless indicated otherwise, SAES is not disabled after a WRERR error detection and continues processing.

An interrupt is generated if the RWEIE bit of the SAES_IER register is set. For more details, refer to Section 33.5: SAES interrupts.

The WRERR and RWEIF flag is cleared by setting the RWEIF bit of the SAES_ICR register.

Key error interrupt flag (KEIF)

Failure to load a key into key registers, or attempt to load a key while the key is protected, sets the KEIF flag of the SAES_ISR register and clears the KEYVALID bit of the SAES_SR register.

The KEIF flag is cleared with corresponding bit of the SAES_ICR register. An interrupt is generated if the KEIE bit of the SAES_IER register is set. For more details, refer to Section 33.5: SAES interrupts.

The possible sources of key errors are:

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

Upon a key selection error, clearing the KEIF flag automatically restarts the key selection process. Persisting problems (for example, RHUK load failing) may require a power-on reset.

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

RNG error interrupt flag (RNGEIF)

SAES fetches random numbers from the RNG peripheral automatically after an IP reset triggered in the RCC. SAES cannot be used when RNGEIF is set.

An error detected while fetching a random number from RNG peripheral (due to, for example, bad entropy) sets the RNGEIF flag of the SAES_ISR register. The flag is cleared by setting the corresponding bit of the SAES_ICR register. An interrupt is generated if the RNGEIE bit of the SAES_IER register is set. For more details, refer to Section 33.5: SAES interrupts.

Upon an RNG error:

Note: To avoid RNGEIF errors, it is recommended to activate the RNG AHB clock each time SAES AHB clock is activated.

About DPA errors

An unexpected error triggers an SAES internal tamper event in the TAMP peripheral, and stops any SAES co-processor processing.

To resume normal operation, application must reset the SAES peripheral through RCC or global reset.

33.5 SAES interrupts

Individual maskable interrupt sources generated by the SAES peripheral signal the following events:

These sources are combined into a common interrupt signal from the SAES peripheral that connects to the Arm® Cortex® interrupt controller. Each can individually be enabled/disabled, by setting/clearing the corresponding enable bit of the SAES_IER register, and cleared by setting the corresponding bit of the SAES_ICR register.

The status of each can be read from the SAES_SR and SAES_ISR registers.

Table 281 gives a summary of the interrupt sources, their event flags and enable bits.

Table 281. SAES interrupt requests

Interrupt acronymSAES interrupt eventEvent flagEnable bitInterrupt clear method
SAEScomputation completed flagCCFCCFIEset CCF(1)
read error flagRDERR(2)RWEIEset RWEIF(1)
write error flagWRERR(2)
key error flagKEIFKEIEset KEIF(1)
RNG error flagRNGEIFRNGEIEset RNGEIF(1)
  1. 1. Bit of the SAES_ICR register.
  2. 2. Flag of the SAES_SR register, mirrored by the flag RWEIF of the SAES_ISR register.

33.6 SAES processing latency

The tables below summarize the latency to process a 128-bit block for each mode of operation.

Table 282. Processing latency for ECB, CBC and CTR

Key sizeMode of operationAlgorithmClock cycles(1)
128-bitMode 1: EncryptionECB, CBC, CTR480
Mode 2: Key derivation-145
Mode 3: DecryptionECB, CBC, CTR480
256-bitMode 1: EncryptionECB, CBC, CTR680
Mode 2: Key derivation-230
Mode 3: DecryptionECB, CBC, CTR680
  1. 1. SAES kernel clock

Table 283. Processing latency for GCM and CCM (in SAES kernel clock cycles)

Key sizeMode of operationAlgorithmInit PhaseHeader phase(1)Payload phase(1)Tag phase(1)
128-bitMode 1: Encryption/
Mode 3: Decryption
GCM49072(2)480(3)490
CCM490490800490
256-bitMode 1: Encryption/
Mode 3: Decryption
GCM65072(2)690(3)650
CCM6506801350650
  1. 1. Data insertion can include wait states forced by SAES on the AHB bus (maximum 3 cycles, typical 1 cycle).
  2. 2. SAES AHB clock cycles instead of kernel clock cycle (Galois multiplier only).
  3. 3. As a worst case in encryption mode, add extra 72 AHB clock cycles for the last block computation.

33.7 SAES registers

33.7.1 SAES control register (SAES_CR)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
IPRSTKEYSEL[2:0]KSHAREID[1:0]KMOD[1:0]NPBLB[3:0]KEYPROTKEYSIZERes.CHMOD[2]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
Res.GCMIPH[1:0]DMAOUTENDMAINENRes.Res.Res.Res.CHMOD[1:0]MODE[1:0]DATATYPE[1:0]EN
rwrwrwrwrwrwrwrwrwrwrw

Bit 31 IPRST: SAES peripheral software reset

Setting the bit resets the SAES peripheral, putting all registers to their default values, except the IPRST bit itself and the SAES_DPACFG register. Hence, any key-relative data is lost. For this reason, it is recommended to set the bit before handing over the SAES to a less secure application. The bit must be low while writing any configuration registers.

Bits 30:28 KEYSEL[2:0]: Key selection

The bitfield defines the source of the key information to use in the AES cryptographic core.

000: Software key, loaded in key registers SAES_KEYx

001: Derived hardware unique key (DHUK)

010: Boot hardware key (BHK)

100: XOR of DHUK and BHK

111: Test mode key (256-bit hardware constant 0xA5A5...A5A5)

Others: Reserved (if used, unfreeze SAES with IPRST)

When KEYSEL is different from zero, selected key value is available in key registers when BUSY bit is cleared and KEYVALID is set in the SAES_SR register. Otherwise, the key error flag KEIF is set. Repeated writing of KEYSEL[2:0] with the same non-zero value only triggers the loading of DHUK or BHK if KEYVALID = 0.

When the application software changes the key selection by writing the KEYSEL[2:0] bitfield, the key registers are immediately erased and the KEYVALID flag cleared.

At the end of the decryption process, if KMOD[1:0] is other than zero, KEYSEL[2:0] is cleared.

With the bitfield value other than zero and KEYVALID set, the application cannot transfer the ownership of SAES with a loaded key to an application running in another security context (such as secure, nonsecure). More specifically, when security of an access to any register does not match the information recorded by SAES, the KEIF flag is set.

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

Bits 27:26 KSHAREID[1:0]: Key share identification

This bitfield defines, at the end of a decryption process with KMOD[1:0] = 10 (shared key), which target can read the SAES key registers using a dedicated hardware bus.

00: CRYP peripheral

Others: Reserved

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

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

The bitfield defines how the SAES key can be used by the application:

00: Normal key

01: Wrapped key

10: Shared key

Others: Reserved

With normal key selection, the key registers are freely usable, no specific usage or protection applies to SAES_DIN and SAES_DOUT registers.

With wrapped key selection, the key loaded in key registers can only be used to encrypt or decrypt AES keys. Hence, when a decryption is selected in Wrapped-key mode read-as-zero SAES_DOUT register is automatically loaded into SAES key registers after a successful decryption process.

With shared key selection, after a successful decryption process, SAES key registers are shared with the peripheral described in KSHAREID(1:0] bitfield. This sharing is valid only while KMOD[1:0] = 10 and KEYVALID = 1. When a decryption is selected, read-as-zero SAES_DOUT register is automatically loaded into SAES key registers after a successful decryption process.

With KMOD[1:0] other than zero, any attempt to configure the SAES peripheral for use by an application belonging to a different security domain (secure or nonsecure) results in automatic key erasure and setting of the KEIF flag.

Attempts to write the bitfield are ignored when the BUSY flag of SAES_SR register is set, as well as when the EN bit of the SAES_CR register 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

The bitfield sets the number of padding bytes in last block of payload:

0000: All bytes are valid (no padding)

0001: Padding for one least-significant byte of last block

...

1111: Padding for 15 least-significant bytes of last block

Bit 19 KEYPROT: Key protection

When set, hardware-based key protection is enabled.

0: When KEYVALID is set and KEYSEL = 0 application can transfer the ownership of the SAES, with its loaded key, to an application running in another security context (such as nonsecure, secure).

1: When KEYVALID is set, key error flag (KEIF) is set when an access to any registers is detected, this access having a security context (for example, secure, nonsecure) that does not match the one of the application that loaded the key.

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

Bits 4:3 MODE[1:0]: SAES operating mode

This bitfield selects the SAES operating mode:

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

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

This bitfield defines the format of data written in the SAES_DINR register or read from the SAES_DOUTR register, through selecting the mode of data swapping:

For more details, refer to Section 33.4.15: SAES data registers and data swapping.

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

Bit 0 EN: SAES enable

This bit enables/disables the SAES peripheral:

At any moment, clearing then setting the bit re-initializes the SAES peripheral.

This bit is automatically cleared by hardware upon the completion of the key preparation (Mode 2) and upon the completion of GCM/GMAC/CCM initial phase.

The bit cannot be set as long as KEYVALID = 0 nor along with the following settings:

KMOD[1:0] = 01 + CHMOD[2:0] = 011 and KMOD[1:0] = 01 + CHMOD[2:0] = 010 + MODE[1:0] = 00.

Note: With KMOD[1:0] other than 00, use the IPRST bit rather than the bit EN.

33.7.2 SAES status register (SAES_SR)

Address offset: 0x04

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.BUSYWRERRRDERRCCF
rrrrr

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

ST logo
ST logo

Bit 7 KEYVALID: Key Valid flag

This bit is set by hardware when the amount of key information defined by KEYSIZE in SAES_CR has been loaded in SAES_KEYx key registers.

0: No valid key information is available in key registers. EN bit in SAES_CR cannot be set.

1: Valid key information, defined by KEYSIZE in SAES_CR, is loaded in key registers.

In normal mode when KEYSEL equals to zero, the application must write the key registers in the correct sequence, otherwise the KEIF flag of the SAES_ISR register is set and KEYVALID stays at zero.

When KEYSEL is different from zero the BUSY flag is automatically set by SAES. When key is loaded successfully, the BUSY flag is cleared and KEYVALID set. Upon an error, the KEIF flag of the SAES_ISR register is set, the BUSY flag cleared and KEYVALID kept at zero.

When the KEIF flag is set, the application must clear it through the SAES_ICR register, otherwise KEYVALID cannot be set. See the KEIF bit description for more details.

For more information on key loading, refer to Section 33.4.16: SAES key registers.

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

Bit 3 BUSY: Busy

This flag indicates whether SAES is idle or busy during GCM payload encryption phase:

0: Idle

1: Busy

The flag is also set upon SAES initialization, upon fetching random number from the RNG, or upon transferring a shared key to a target peripheral.

When GCM encryption is selected, the flag must be at zero before selecting the GCM final phase.

Bit 2 WRERR: Write error

This flag indicates the detection of an unexpected write operation to the SAES_DINR register (during computation or data output phase):

0: Not detected

1: Detected

The flag is set by hardware. It is cleared by software upon setting the RWEIF bit of the SAES_ICR register.

Upon the flag setting, an interrupt is generated if enabled through the RWEIE bit of the SAES_ICR register.

The flag setting has no impact on the SAES operation. Unexpected write is ignored.

Bit 1 RDERR: Read error flag

This flag indicates the detection of an unexpected read operation from the SAES_DOUTR register (during computation or data input phase):

0: Not detected

1: Detected

The flag is set by hardware. It is cleared by software upon setting the RWEIF bit of the SAES_ICR register.

Upon the flag setting, an interrupt is generated if enabled through the RWEIE bit of the SAES_ICR register.

The flag setting has no impact on the SAES operation. Unexpected read returns zero.

Bit 0 CCF: Computation completed flag

This bit mirrors the CCF bit of the SAES_ISR register.

33.7.3 SAES data input register (SAES_DINR)

Address offset: 0x08

Reset value: 0x0000 0000

Only 32-bit write access type is supported.

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

Bits 31:0 DIN[31:0]: Input data word

A four-fold sequential write to this bitfield during the input phase results in writing a complete 128-bit block of input data to the SAES 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 128-bit input buffer.

The data signification of the input data block depends on the SAES operating mode:

The data swap operation is described in Section 33.4.15: SAES data registers and data swapping on page 1818.

33.7.4 SAES data output register (SAES_DOUTR)

Address offset: 0x0C

Reset value: 0x0000 0000

Only 32-bit read access type is supported. Read when KMOD[1:0] = 01 or 10 while MODE[1:0] = 10 and EN = 1 triggers a read error.

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

Bits 31:0 DOUT[31:0]: Output data word

This read-only bitfield fetches a 32-bit output buffer. A four-fold sequential read of this bitfield, upon the computation completion (CCF set), virtually reads a complete 128-bit block of output data from the SAES 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].

The data signification of the output data block depends on the SAES operating mode:

The data swap operation is described in Section 33.4.15: SAES data registers and data swapping on page 1818.

33.7.5 SAES key register 0 (SAES_KEYR0)

Address offset: 0x10

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]

This write-only bitfield contains the bits [31:0] of the AES encryption or decryption key, depending on the operating mode:

The SAES_KEYRx registers may be written only when KEYSIZE value is correct and when the SAES peripheral is disabled (EN bit of the SAES_CR register cleared). A special writing sequence is also required, as described in KEYVALID bit of the SAES_SR register. Note that, if KEYSEL is different from 0 and KEYVALID = 0, the key is directly loaded to SAES_KEYRx registers (hence writes to key register is ignored and KEIF is set).

Refer to Section 33.4.16: SAES key registers on page 1820 for more details.

33.7.6 SAES key register 1 (SAES_KEYR1)

Address offset: 0x14

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 SAES_KEYR0 register for description of the KEY[255:0] bitfield.

33.7.7 SAES key register 2 (SAES_KEYR2)

Address offset: 0x18

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 SAES_KEYR0 register for description of the KEY[255:0] bitfield.

33.7.8 SAES key register 3 (SAES_KEYR3)

Address offset: 0x1C

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 SAES_KEYR0 register for description of the KEY[255:0] bitfield.

33.7.9 SAES initialization vector register 0 (SAES_IVR0)

Address offset: 0x20

Reset value: 0x0000 0000

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

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

Refer to Section 33.4.17: SAES initialization vector registers on page 1822 for description of the IVI[127:0] bitfield.

The initialization vector is only used in chaining modes other than ECB.

The SAES_IVRx registers may be written only when the SAES peripheral is disabled

33.7.10 SAES initialization vector register 1 (SAES_IVR1)

Address offset: 0x24

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 SAES_IVR0 register for description of the IVI[128:0] bitfield.

33.7.11 SAES initialization vector register 2 (SAES_IVR2)

Address offset: 0x28

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 SAES_IVR0 register for description of the IVI[128:0] bitfield.

33.7.12 SAES initialization vector register 3 (SAES_IVR3)

Address offset: 0x2C

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 SAES_IVR0 register for description of the IVI[128:0] bitfield.

33.7.13 SAES key register 4 (SAES_KEYR4)

Address offset: 0x30

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 SAES_KEYR0 register for description of the KEY[255:0] bitfield.

33.7.14 SAES key register 5 (SAES_KEYR5)

Address offset: 0x34

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 SAES_KEYR0 register for description of the KEY[255:0] bitfield.

33.7.15 SAES key register 6 (SAES_KEYR6)

Address offset: 0x38

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 SAES_KEYR0 register for description of the KEY[255:0] bitfield.

33.7.16 SAES key register 7 (SAES_KEYR7)

Address offset: 0x3C

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 SAES_KEYR0 register for description of the KEY[255:0] bitfield.

Note: The key registers from 4 to 7 are used only when the key length of 256 bits is selected. They have no effect when the key length of 128 bits is selected (only key registers 0 to 3 are used in that case).

33.7.17 SAES suspend registers (SAES_SUSPxR)

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

Reset value: 0x0000 0000

These registers contain the complete internal register states of the AES processor when the AES processing of the current task is suspended to process a higher-priority task.

Upon suspend, the software reads and saves the SAES_SUSPxR register contents (where x is from 0 to 7) into memory, before using the AES processor for the higher-priority task.

Upon completion, the software restores the saved contents back into the corresponding suspend registers, before resuming the original task.

Note: These registers are used only when CCM chaining mode is selected.

These registers can be read only when SAES is enabled. Reading these registers while SAES is disabled returns 0x0000 0000.

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

Bits 31:0 SUSP[31:0]: SAES suspend

Upon suspend operation, this bitfield of the corresponding SAES_SUSPxR register takes the value of one of internal SAES registers.

33.7.18 SAES interrupt enable register (SAES_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.RNGEIEKEIERWEIECCFIE
rwrwrwrw

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

Bit 3 RNGEIE: RNG error interrupt enable

This bit enables or disables (masks) the SAES interrupt generation when RNGEIF (RNG error flag) is set.

0: Disabled (masked)

1: Enabled (not masked)

Bit 2 KEIE: Key error interrupt enable

This bit enables or disables (masks) the SAES 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 SAES 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 SAES interrupt generation when CCF (computation complete flag) is set.

0: Disabled (masked)

1: Enabled (not masked)

33.7.19 SAES interrupt status register (SAES_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.RNGEIFKEIFRWEIFCCF
rrrr

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

Bit 3 RNGEIF: RNG error interrupt flag

This read-only bit is set by hardware when an error is detected on RNG bus interface (e.g. bad entropy).

0: RNG bus is functional

1: Error detected on RNG bus interface (random seed fetching error)

RNGEIE bit is cleared when application sets the corresponding bit of SAES_ICR register. An interrupt is generated if the RNGEIE bit has been previously set in the SAES_IER register. Clearing this bit triggers the reload of a new random number from RNG peripheral.

Bit 2 KEIF: Key error interrupt flag

This read-only bit is set by hardware when key information failed to load into key registers or key register usage is forbidden.

0: No key error detected

1: Key information failed to load into key registers, or key register use is forbidden

Setting the corresponding bit of the SAES_ICR register clears the KEIF and generates interrupt if the KEIE bit of the SAES_IER register is set.

KEIF is triggered upon any of the following errors:

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 RDERR or a WRERR error flag is set in the SAES_SR register.

0: No read or write error detected

1: Read or write error detected (see SAES_SR register for details)

RWEIF bit is cleared when application sets the corresponding bit of SAES_ICR register. An interrupt is generated if the RWEIE bit has been previously set in the SAES_IER register.

This flags has no meaning when key derivation mode is selected.

Bit 0 CCF: Computation complete flag

This flag indicates whether the computation is completed:

0: Not completed

1: Completed

The flag is set by hardware upon the completion of the computation. It is cleared by software, upon setting the CCF bit of the SAES_ICR register.

Upon the flag setting, an interrupt is generated if enabled through the CCFIE bit of the SAES_IER register.

The flag is significant only when the DMAOUTEN bit is 0. It may stay high when DMA_EN is 1.

33.7.20 SAES interrupt clear register (SAES_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.RNGEIFKEIFRWEIFCCF
wwww

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

Bit 3 RNGEIF: RNG error interrupt flag clear

Application must set this bit to clear the RNGEIF status bit in SAES_ISR register.

Bit 2 KEIF: Key error interrupt flag clear

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

Bit 1 RWEIF: Read or write error interrupt flag clear

Setting this bit clears the RWEIF status bit of the SAES_ISR register, and both RDERR and WRERR flags in the SAES_SR register.

Bit 0 CCF: Computation complete flag clear

Setting this bit clears the CCF status bit of the SAES_SR and SAES_ISR registers.

33.7.21 SAES hardware configuration register (SAES_HWCFGR)

Address offset: 0x3F0

Reset value: 0x0000 0112

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.CFG3[3:0]CFG2[3:0]CFG1[3:0]
rrrrrrrrrrrr

Bits 31:12 Reserved, must be kept at zero.

Bits 11:8 CFG3[3:0]: HW Generic 3

This bitfield returns 0x1.

Bits 7:4 CFG2[3:0]: HW Generic 2

This bitfield returns 0x1.

Bits 3:0 CFG1[3:0]: HW Generic 1

This bitfield returns 0x2.

33.7.22 SAES version register (SAES_VERR)

Address offset: 0x3F4

Reset value: 0x0000 0030

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.MAJREV[3:0]MINREV[3:0]
rrrrrrrr

Bits 31:8 Reserved, must be kept at zero

Bits 7:4 MAJREV[3:0]: Major revision

This bitfield returns the SAES peripheral major version (0x3).

Bits 3:0 MINREV[3:0]: Minor revision

This bitfield returns the SAES peripheral minor version (0x0).

33.7.23 SAES identification register (SAES_IPIDR)

Address offset: 0x3F8

Reset value: 0x0017 0023

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

Bits 31:0 ID[31:0]: Identification code of the peripheral

This bitfield returns the identification code of the SAES peripheral.

33.7.24 SAES size ID register (SAES_SIDR)

Address offset: 0x3FC

Reset value: 0xA3C5 DD01

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

Bits 31:0 SID[31:0]: Size identification code

This bitfield returns the size identification code of the SAES peripheral as defined below:

Bits[31:8] = 0xA3C5DD (fixed code)

Bits[7:0] = 0x01 (1 Kbyte address decoding)

33.7.25 SAES register map

Table 284. SAES register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x000SAES_CRIPRSTKEYSEL[2:0]KSHAREID[1:0]KMOD[1:0]NPBLB[3:0]KEYPROTKEYSIZERes.CHMOD[2]Res.GCMPH[1:0]DMAOUTENDMAINENRes.Res.Res.Res.Res.Res.Res.CHMOD[1:0]MODE[1:0]DATATYPE[1:0]EN
Reset value00000000000000000000000000
0x004SAES_SRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.KEYVALIDRes.Res.Res.BUSYWRERRRDERRCCF
Reset value000000

Table 284. SAES register map and reset values (continued)

OffsetRegister313029282726252423222120191817161514131211109876543210
0x008SAES_DINRDIN[31:0]
Reset value00000000000000000000000000000000
0x00CSAES_DOUTRDOUT[31:0]
Reset value00000000000000000000000000000000
0x010SAES_KEYR0KEY[31:0]
Reset value00000000000000000000000000000000
0x014SAES_KEYR1KEY[63:32]
Reset value00000000000000000000000000000000
0x018SAES_KEYR2KEY[95:64]
Reset value00000000000000000000000000000000
0x01CSAES_KEYR3KEY[127:96]
Reset value00000000000000000000000000000000
0x020SAES_IVR0IVI[31:0]
Reset value00000000000000000000000000000000
0x024SAES_IVR1IVI[63:32]
Reset value00000000000000000000000000000000
0x028SAES_IVR2IVI[95:64]
Reset value00000000000000000000000000000000
0x02CSAES_IVR3IVI[127:96]
Reset value00000000000000000000000000000000
0x030SAES_KEYR4KEY[159:128]
Reset value00000000000000000000000000000000
0x034SAES_KEYR5KEY[191:160]
Reset value00000000000000000000000000000000
0x038SAES_KEYR6KEY[223:192]
Reset value00000000000000000000000000000000
0x03CSAES_KEYR7KEY[255:224]
Reset value00000000000000000000000000000000
0x040SAES_SUSP0RSUSP[31:0]
Reset value00000000000000000000000000000000
0x044SAES_SUSP1RSUSP[31:0]
Reset value00000000000000000000000000000000
0x048SAES_SUSP2RSUSP[31:0]
Reset value00000000000000000000000000000000
0x04CSAES_SUSP3RSUSP[31:0]
Reset value00000000000000000000000000000000
0x050SAES_SUSP4RSUSP[31:0]
Reset value00000000000000000000000000000000

Table 284. SAES register map and reset values (continued)

OffsetRegister313029282726252423222120191817161514131211109876543210
0x054SAES_SUSP5RSUSP[31:0]
Reset value00000000000000000000000000000000
0x058SAES_SUSP6RSUSP[31:0]
Reset value00000000000000000000000000000000
0x05CSAES_SUSP7RSUSP[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.
0x300SAES_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.RNGEIEKEIERWEIECCFIE
Reset value00000
0x304SAES_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.RNGEIFKEIFRWEIFCCF
Reset value00000
0x308SAES_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.RNGEIFKEIFRWEIFCCF
Reset value00000
0x3F0SAES_HWCFG
R
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.
Reset value0001000100
0x3F4SAES_VERRRes.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.
Reset value001100
0x3F8SAES_IPIDRID[31:0]
Reset value00000000000101110000000000100011
0x3FCSAES_SIDRSID[31:0]
Reset value10100011110001011101110100000001
Refer to Section 2.5 on page 153 for the register boundary addresses.