40. Cryptographic processor (CRYP)

40.1 Introduction

The cryptographic processor (CRYP) can be used both to encrypt and decrypt data using the DES, Triple-DES or AES algorithms. It is a fully compliant implementation of the following standards:

Multiple key sizes and chaining modes are supported:

The CRYP processor is a 32-bit AHB peripheral. It supports DMA transfers for incoming and outgoing data (two DMA channels are required). The peripheral also includes input and output FIFOs (each 8 words deep) for better performance.

40.2 CRYP main features

40.3 CRYP implementation

This device has one CRYP instance.

40.4 CRYP functional description

40.4.1 CRYP block diagram

The figure below shows the block diagram of the cryptographic processor.

Figure 341. CRYP block diagram

CRYP block diagram showing internal components like AHB interface, registers (CRYP_DIN, CRYP_DOUT, CRYP_SR, CRYP_CR, CRYP_Kx, CRYP_IVx, CRYP_GCMx, CSGCMCMx, CRYP_IMSCR, CRYP_RIS, CRYP_MIS, CRYP_DMACR), DMA/IRQ interfaces, Control Logic, and processing cores (AES Core (AEA) and DES/TDES Core (DEA)).

The block diagram illustrates the internal architecture of the CRYP processor. On the left, a vertical bar represents the 32-bit AHB2 bus, which connects to an AHB interface. Below the bus are two external pins: cryp_hclk (clock) and cryp_it (interrupt). The AHB interface is connected to a central block of registers and two external interfaces: DMA and IRQ. The registers are organized into three groups: 'Banked Registers (main)' containing CRYP_DIN, CRYP_DOUT, CRYP_SR, CRYP_CR, CRYP_Kx, and CRYP_IVx; 'Banked Registers (suspend/restore)' containing CRYP_GCMx and CSGCMCMx; and 'Banked Registers (IRQ & DMA)' containing CRYP_IMSCR, CRYP_RIS, CRYP_MIS, and CRYP_DMACR. Data flow is indicated by arrows: 'data in' to CRYP_DIN, 'data out' from CRYP_DOUT, and 'status', 'control', 'key', and 'iv' for the other registers. CRYP_DIN and CRYP_DOUT are connected to 8x32-bit IN FIFO and OUT FIFO blocks, which in turn connect to the AES Core (AEA) and DES/TDES Core (DEA) via 'switch' and 'Dh/dm' components. CRYP_Kx and CRYP_IVx provide 'Key' and 'IV' inputs to the cores. CRYP_GCMx and CSGCMCMx are connected to a 'Save/Restore' block. The DMA interface is connected to 'cryp_in_dma' and 'cryp_out_dma' pins and to the Control Logic. The IRQ interface is connected to the 'cryp_it' pin and to the Control Logic. The Control Logic block is connected to the registers and the cores. The diagram is labeled with 'MSv41956V3' in the bottom right corner.

CRYP block diagram showing internal components like AHB interface, registers (CRYP_DIN, CRYP_DOUT, CRYP_SR, CRYP_CR, CRYP_Kx, CRYP_IVx, CRYP_GCMx, CSGCMCMx, CRYP_IMSCR, CRYP_RIS, CRYP_MIS, CRYP_DMACR), DMA/IRQ interfaces, Control Logic, and processing cores (AES Core (AEA) and DES/TDES Core (DEA)).

40.4.2 CRYP internal signals

Table 322 provides a list of useful-to-know internal signals available at cryptographic processor level and not at STM32 product level (on pads).

Table 322. CRYP internal input/output signals

Signal nameSignal typeDescription
cryp_hclkDigital inputAHB bus clock
cryp_itDigital outputCryptographic processor global interrupt request
cryp_in_dmaDigital input/outputIN FIFO DMA burst request/ acknowledge
cryp_out_dmaDigital input/outputOUT FIFO DMA burst request/ acknowledge (with single request for DES/TDES)

40.4.3 CRYP DES/TDES cryptographic core

Overview

The DES/Triple-DES cryptographic core consists of three components:

The DES/Triple-DES cryptographic core provides two operating modes:

The operating mode is selected by programming the ALGODIR bit in the CRYP_CR register.

Typical data processing

Typical usage of the cryptographic processor in DES modes can be found in Section 40.4.10: CRYP DES/TDES basic chaining modes (ECB, CBC) .

Note: The outputs of the intermediate DEA stages are never revealed outside the cryptographic boundary, with the exclusion of the IV registers in CBC mode.

DES/TDES keying and chaining modes

The DES/TDES allows three different keying options:

The first option specifies that all the keys are independent, that is, K1, K2 and K3 are independent. FIPS PUB 46-3 – 1999 (and ANSI X9.52 – 1998) refers to this option as the Keying Option 1 and, to the TDES as 3-key TDES.

The second option specifies that K1 and K2 are independent and K3 is equal to K1, that is, K1 and K2 are independent, K3 = K1. FIPS PUB 46-3 – 1999 (and ANSI X9.52

– 1998) refers to this second option as the Keying Option 2 and, to the TDES as 2-key TDES.

The third option specifies that K1, K2 and K3 are equal, that is:

\[ K1 = K2 = K3 \]

FIPS PUB 46-3 – 1999 (and ANSI X9.52 – 1998) refers to the third option as the Keying Option 3. This “1-key” TDES is equivalent to single DES.

The following chaining algorithms are supported by the DES hardware and can be selected through the ALGOMODE bits in the CRYP_CR register:

These modes are described in details in Section 40.4.10: CRYP DES/TDES basic chaining modes (ECB, CBC) .

40.4.4 CRYP AES cryptographic core

Overview

The AES cryptographic core consists of the following components:

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

The cryptographic peripheral features two operating modes:

The operating mode is selected by programming the ALGODIR bit in the CRYP_CR register.

Typical data processing

A description of cryptographic processor typical usage in AES mode can be found in Section 40.4.11: CRYP AES basic chaining modes (ECB, CBC) .

Note: The outputs of the intermediate AEA stages is never revealed outside the cryptographic boundary, with the exclusion of the IV registers.

AES chaining modes

The following chaining algorithms are supported by the cryptographic processor and can be selected through the ALGOMODE bits in the CRYP_CR register:

A quick introduction on these chaining modes can be found in the following subsections.

For detailed instructions, refer to Section 40.4.11: CRYP AES basic chaining modes (ECB, CBC) and onward.

AES Electronic CodeBook (ECB)

Figure 342. AES-ECB mode overview

Diagram illustrating the AES-ECB mode overview for encryption and decryption.

The diagram illustrates the AES-ECB mode overview, showing both encryption and decryption processes for three blocks.

Encryption: Three separate paths are shown. Each path starts with a Plaintext block (1, 2, or 3) entering an Encrypt block. A key is also input to each Encrypt block. The output of each Encrypt block is a Ciphertext block (1, 2, or 3).

Decryption: Three separate paths are shown. Each path starts with a Ciphertext block (1, 2, or 3) entering a Decrypt block. A key is also input to each Decrypt block. The output of each Decrypt block is a Plaintext block (1, 2, or 3).

Legend:

MSv42140V1

Diagram illustrating the AES-ECB mode overview for encryption and decryption.

ECB is the simplest operating mode. 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.

AES Cipher block chaining (CBC)

Figure 343. AES-CBC mode overview

Diagram of AES-CBC mode showing encryption and decryption processes for three blocks. It includes labels for plaintext, ciphertext, initialization vector, and key. A legend defines input, output, and key scheduling symbols.

The diagram illustrates the AES-CBC mode of operation for three blocks. It is divided into two sections: Encryption and Decryption .

Encryption: Three plaintext blocks (Plaintext block 1, 2, and 3) are shown. Each block is XORed with an initialization vector (for the first block) or the previous ciphertext block (for subsequent blocks). The result is then passed through an Encrypt block along with a key to produce the corresponding ciphertext block (Ciphertext block 1, 2, and 3). The ciphertext blocks are chained, with each block's output being the input for the next block's XOR operation.

Decryption: Three ciphertext blocks (Ciphertext block 1, 2, and 3) are shown. Each block is passed through a Decrypt block along with a key . The output is then XORed with the previous ciphertext block (or the initialization vector for the first block) to produce the plaintext block (Plaintext block 1, 2, and 3). The decryption process is the reverse of the encryption process.

Legend:

MSv42141V1

Diagram of AES-CBC mode showing encryption and decryption processes for three blocks. It includes labels for plaintext, ciphertext, initialization vector, and key. A legend defines input, output, and key scheduling symbols.

CBC operating mode chains the output of each block 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.

AES Counter mode (CTR)

Figure 344. AES-CTR mode overview

Diagram illustrating the AES Counter mode (CTR) for encryption and decryption. The diagram shows three blocks of data. In the 'Encryption' section, a Counter block (value, value+1, value+2) is input to an 'Encrypt' block along with a 'key'. The output of the 'Encrypt' block is XORed with 'Plaintext block 1, 2, or 3' to produce 'Ciphertext block 1, 2, or 3'. In the 'Decryption' section, the same Counter blocks are input to a 'Decrypt' block along with the 'key'. The output of the 'Decrypt' block is XORed with 'Ciphertext block 1, 2, or 3' to produce 'Plaintext block 1, 2, or 3'. A legend indicates that white boxes are 'input', grey boxes are 'output', and the circle with a cross symbol is 'XOR'. The diagram is labeled MSv42142V1.

Encryption

Counter → (+1) → Counter → (+1) → Counter

value      value + 1      value + 2

key → Encrypt      key → Encrypt      key → Encrypt

Plaintext block 1 → ⊕ → Plaintext block 2 → ⊕ → Plaintext block 3 → ⊕

Ciphertext block 1      Ciphertext block 2      Ciphertext block 3

Decryption

Counter → (+1) → Counter → (+1) → Counter

value      value + 1      value + 2

key → Decrypt      key → Decrypt      key → Decrypt

Plaintext block 1 ← ⊕ ← Plaintext block 2 ← ⊕ ← Plaintext block 3 ← ⊕

Ciphertext block 1      Ciphertext block 2      Ciphertext block 3

Legend

input

output

⊕ XOR

MSv42142V1

Diagram illustrating the AES Counter mode (CTR) for encryption and decryption. The diagram shows three blocks of data. In the 'Encryption' section, a Counter block (value, value+1, value+2) is input to an 'Encrypt' block along with a 'key'. The output of the 'Encrypt' block is XORed with 'Plaintext block 1, 2, or 3' to produce 'Ciphertext block 1, 2, or 3'. In the 'Decryption' section, the same Counter blocks are input to a 'Decrypt' block along with the 'key'. The output of the 'Decrypt' block is XORed with 'Ciphertext block 1, 2, or 3' to produce 'Plaintext block 1, 2, or 3'. A legend indicates that white boxes are 'input', grey boxes are 'output', and the circle with a cross symbol is 'XOR'. The diagram is labeled MSv42142V1.

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

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

AES Galois/Counter mode (GCM)

Figure 345. AES-GCM mode overview

Figure 345. AES-GCM mode overview diagram showing the encryption and authentication process.

The diagram illustrates the AES-GCM mode of operation. It shows the flow from an initialization vector (IV) and a key through an 'Init (Encrypt)' block to produce a hash 'H'. Simultaneously, the IV is passed through a series of 'Counter' blocks, each incremented by 1. These counter values are passed through 'Encrypt' blocks with the key to produce keystream blocks. Each plaintext block is XORed with its corresponding keystream block to produce a ciphertext block. The ciphertext blocks are then passed through 'GF2mul' blocks, which also take the hash 'H' as input. The outputs of the 'GF2mul' blocks are XORed together and passed through a 'Final' block to produce the authentication 'TAG'. A legend indicates that white boxes are inputs, grey boxes are outputs, and the circle with a cross symbol represents XOR. The diagram is labeled MSv42143V1.

Figure 345. AES-GCM mode overview diagram showing the encryption and authentication process.

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

AES Galois Message Authentication Code (GMAC)

Figure 346. AES-GMAC mode overview

Figure 346. AES-GMAC mode overview diagram showing the authentication process.

The diagram illustrates the AES-GMAC mode of operation. It shows the flow from an initialization vector (IV) and a key through an 'Init (Encrypt)' block to produce a hash 'H'. The hash 'H' is then passed through a series of 'GF2mul' blocks. Each plaintext block is XORed with the output of the previous 'GF2mul' block and then passed through a 'GF2mul' block. The final output of the last 'GF2mul' block is passed through a 'Final' block to produce the authentication 'TAG'. A legend indicates that white boxes are inputs, grey boxes are outputs, and the circle with a cross symbol represents XOR. The diagram is labeled MSv42144V1.

Figure 346. AES-GMAC mode overview diagram showing the authentication process.

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 Galois/Counter mode (GCM), except that it is applied on a message composed only by clear-text authenticated data (i.e. only header, no payload).

AES Counter with CBC-MAC (CCM)

Figure 347. AES-CCM mode overview

Figure 347. AES-CCM mode overview diagram showing the encryption and authentication process. The diagram illustrates the flow from B0 through counters (Count 1, Count 2, Count 3) and encryption blocks to produce ciphertext blocks and a final TAG. A legend defines input, output, and XOR symbols.

The diagram illustrates the AES-CCM mode overview. It shows the following components and flow:

Figure 347. AES-CCM mode overview diagram showing the encryption and authentication process. The diagram illustrates the flow from B0 through counters (Count 1, Count 2, Count 3) and encryption blocks to produce ciphertext blocks and a final TAG. A legend defines input, output, and XOR symbols.

In Counter with Cipher Block Chaining-Message Authentication Code (CCM), 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 AES in counter mode for confidentiality and it uses CBC for computing the message authentication code. It requires an initial value.

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

40.4.5 CRYP procedure to perform a cipher operation

Introduction

To understand how the cryptographic peripheral operates, a typical cipher operation is described below. For the detailed peripheral usage according to the cipher mode, refer to the specific section, for example Section 40.4.11: CRYP AES basic chaining modes (ECB, CBC) .

CRYP initialization

To initialize the cryptographic processor, first disable it by clearing the CRYPTEN bit in the CRYP_CR register. Then execute the following steps:

  1. 1. Configure the algorithm and the chaining mode through the ALGOMODE and ALGODIR bits in the CRYP_CR register. Configure also the key size with the KEYSIZE bits.
  2. 2. When the previous step is complete, and when applicable, write the symmetric key into the CRYP_KxL/R registers. The way to write key registers is defined in Section 40.4.17: CRYP key registers
  3. 3. Configure the data type (1, 8, 16 or 32 bits) through the DATATYPE bits of the CRYP_CR register.
  4. 4. When it is required (for example for CBC or CTR chaining modes), write the initialization vectors into the CRYP_IVxL/R register.
  5. 5. Flush the IN and OUT FIFOs by writing the FFLUSH bit to 1 in the CRYP_CR register.

Preliminary warning for all cases

If the ECB or CBC mode is selected and data are not a multiple of 64 bits (for DES) or 128 bits (for AES), the second and the last block management is more complex than the sequences below. Refer to Section 40.4.8: CRYP stealing and data padding for more details.

Appending data using the CPU in Polling mode

  1. 1. Enable the cryptographic processor by setting to 1 the CRYPTEN bit in the CRYP_CR register.
  2. 2. Write data in the IN FIFO (one block or until the FIFO is full).
  3. 3. Repeat the following sequence until the second last block of data has been processed:
    1. a) Wait until the not-empty-flag OFNE is set to 1, then read the OUT FIFO (one block or until the FIFO is empty).
    2. b) Wait until the not-full-flag IFNF is set to 1, then write the IN FIFO (one block or until the FIFO is full) except if it is the last block.
  4. 4. The BUSY bit is set automatically by the cryptographic processor. At the end of the processing, the BUSY bit returns to 0 and both FIFOs are empty (IN FIFO empty flag IFEM = 1 and OUT FIFO not empty flag OFNE = 0).
  5. 5. If the next processing block is the last block, the CPU must pad (when applicable) the data with zeroes to obtain a complete block and specify the number of non-valid bytes using NPBLB bits in CRYP_CR register in case of AES GCM payload encryption or AES CCM payload decryption (otherwise the tag computation will be wrong). This operation must be performed after checking that the BUSY bit in the CRYP_CR register is set to 0.

Note: NPBLB bits are not used in the header phase of AES GCM, GMAC and CCM modes.

  1. 6. When the operation is complete, the cryptographic processor can be disabled by clearing the CRYPTEN bit in CRYP_CR register.

Appending data using the CPU in Interrupt mode

  1. 1. Enable the interrupts by setting the INIM and OUTIM bits in the CRYP_IMSCR register.
  2. 2. Enable the cryptographic processor by setting to 1 the CRYPTEN bit in the CRYP_CR register.
  3. 3. In the interrupt service routine that manages the input data:
    1. a) If the last block is being loaded, the CPU must pad (when applicable) the data with zeroes to have a complete block and specify the number of non-valid bytes using NPBLB bits in CRYP_CR register in case of AES GCM payload encryption or AES CCM payload decryption (otherwise the tag computation will be wrong). This operation must be performed after checking that the BUSY bit in the CRYP_CR register is set to 0. Then load the block into the IN FIFO.

Note: NPBLB bits are not used in the header phase of AES GCM, GMAC and CCM.

    1. b) If it is not the last block, load the data into the IN FIFO. You can load only one block (2 words for DES, 4 words for AES), or load data until the FIFO is full.
    2. c) In all cases, after the last word of data has been written, disable the interrupt by clearing the INIM interrupt mask.
    1. 4. In the interrupt service routine that manages the input data:
      1. a) Read the output data from the OUT FIFO. You can read only one block (2 words for DES, 4 words for AES), or read data until the FIFO is empty.
      2. b) When the last word has been read, INIM and BUSY bits are set to 0 and both FIFOs are empty (IFEM = 1 and OFNE = 0). You can disable the interrupt by clearing the OUTIM bit, and disable the peripheral by clearing the CRYPTEN bit.
      3. c) If you read the last block of cleartext data (i.e. decryption), optionally discard the data that is not part of message/payload.

Appending data using the DMA

  1. 1. Prepare the last block of data by optionally padding it with zeroes to have a complete block.
  2. 2. Configure the DMA controller to transfer the input data from the memory and transfer the output data from the peripheral to the memory, as described in Section 40.4.19: CRYP DMA interface . The DMA should be configured to set an interrupt on transfer completion to indicate that the processing is complete. In case of AES GCM payload encryption or AES CCM payload decryption, DMA transfers must not include the last block. The sequence using the CPU described above must be used instead for this last block, because NPBLB bits needs to be setup before processing the block (otherwise the tag computation will be wrong).

Note: NPBLB bits are not used in the header phase of AES GCM, GMAC and CCM.

  1. 3. Enable the cryptographic processor by setting to 1 the CRYPTEN bit in CRYP_CR register, then enable the DMA IN and OUT requests by setting to 1 the DIEN and DOEN bits in the CRYP_DMACR register.
  2. 4. All the transfers and processing are managed by the DMA and the cryptographic processor. The DMA interrupt indicates that the processing is complete. Both FIFOs are normally empty and BUSY flag is set 0.

Caution: It is important that DMA controller empties the cryptographic processor output FIFO before filling up the cryptographic processor input FIFO. To achieve this, the DMA controller should be configured so that the transfer from the cryptographic peripheral to the memory has a higher priority than the transfer from the memory to the cryptographic peripheral.

40.4.6 CRYP busy state

The cryptographic processor is busy and processing data (BUSY set to 1 in CRYP_SR register) when all the conditions below are met:

Write operations to the CRYP_Kx(L/R)R key registers, to the CRYP_IVx(L/R)R initialization registers, or to bits [9:2] of the CRYP_CR register, are ignored when cryptographic processor is busy (i.e. the registers are not modified). It is thus not possible to modify the configuration of the cryptographic processor while it is processing a data block.

It is possible to clear the CRYPTEN bit while BUSY bit is set to 1. In this case the ongoing DES/TDES or AES processing first completes (i.e. the word results are written to the output FIFO) before the BUSY bit is cleared by hardware.

Note: If the application needs to suspend a message to process another one with a higher priority, refer to Section 40.4.9: CRYP suspend/resume operations

When a block is being processed in DES or TDES mode, if the output FIFO becomes full and the input FIFO contains at least one new block, then the new block is popped off the input FIFO and the BUSY bit remains high until there is enough space to store this new block into the output FIFO.

40.4.7 Preparing the CRYP AES key for decryption

When performing an AES ECB or CBC decryption , the AES key has to be prepared. Indeed, in AES encryption the round 0 key is the one stored in the key registers, and AES decryption must start using the last round key. Hence, as the encryption key is stored in memory, a special key scheduling must be performed to obtain the decryption key. This preparation is not required in any other AES modes than ECB or CBC decryption.

When the cryptographic processor is disabled (CRYPEN = 0), the CRYP key preparation process is performed as follows:

  1. 1. Program ALGOMODE bits to 0x7 in CRYP_CR. In addition, configure the key length with the KEYSIZE bits.
  2. 2. Write the symmetric key to the CRYP_KxL/R registers, as described in Section 40.4.17: CRYP key registers .
  3. 3. Enable the cryptographic processor by setting the CRYPEN bit in the CRYP_CR register. It immediately starts an AES round for key preparation (BUSY = 1).
  4. 4. Wait until the BUSY bit is cleared in the CRYP_SR register. Then update ALGOMODE bits in the CRYP_CR register to select the correct chaining mode, that is 0x4 for ECB or 0x5 for CBC.
  5. 5. The AES key is available in the CRYP key registers, ready to use for decryption.

Note: As the CRYPEN bitfield is reset by hardware at the end of the key preparation, the application software must set it again for the next operation.

The latency of the key preparation operation is 14, 16 or 18 clock cycles depending on the key size (128, 192 or 256 bits).

40.4.8 CRYP stealing and data padding

When using DES or AES algorithm in ECB or CBC modes to manage messages that are not multiple of the block size (64 bits for DES, 128 bits for AES), use ciphertext stealing techniques such as those described in NIST Special Publication 800-38A, Recommendation for Block Cipher Modes of Operation: Three Variants of Ciphertext Stealing for CBC Mode . Since the cryptographic processor does not implement such techniques, the last two blocks must be handled in a special way by the application.

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

Similarly, when the AES algorithm is used in other modes than ECB or CBC, incomplete input data blocks (i.e. block shorter than 128 bits) have to be padded with zeroes by the application prior to encryption (i.e. extra bits should be appended to the trailing end of the data string). After decryption, the extra bits have to be discarded. The cryptographic processor does not implement automatic data padding operation to the last block , so the application should follow the recommendation given in Section 40.4.5: CRYP procedure to perform a cipher operation to manage messages that are not multiple of 128 bits.

Note: Padding data are swapped in a similar way as normal data, according to the DATATYPE field in CRYP_CR register (see Section 40.4.16: CRYP data registers and data swapping for details).

40.4.9 CRYP suspend/resume operations

A message can be suspended if another message with a higher priority has to be processed. When this highest priority message has been sent, the suspended message can be resumed in both encryption or decryption mode.

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

Figure 348 gives an example of suspend/resume operation: message 1 is suspended in order to send a higher priority message (message 2), which is shorter than message 1 (AES algorithm).

Figure 348. Example of suspend mode management

Diagram illustrating suspend mode management for CRYP operations. Message 1 is suspended after block 3 to allow Message 2 to be processed, then resumed.
graph TD
    subgraph Message_1 [Message 1]
    M1B1[128-bit block 1] --> M1B2[128-bit block 2]
    M1B2 --> M1B3[128-bit block 3]
    M1B3 --> Suspend[CRYP suspend sequence]
    Resume[CRYP resume sequence] --> M1B4[128-bit block 4]
    M1B4 --> M1B5[128-bit block 5]
    M1B5 --> M1B6[128-bit block 6]
    M1B6 --> Ellipsis[...]
    end

    subgraph Message_2 [Message 2]
    M2B1[128-bit block 1] --> M2B2[128-bit block 2]
    end

    NewMsg((New higher priority message 2 to be processed)) -.-> Suspend
    Suspend --> M2B1
    M2B2 --> Resume

The diagram illustrates the flow of data blocks for two messages, Message 1 and Message 2, during a suspend/resume operation. Message 1 consists of 128-bit blocks 1 through 6, followed by an ellipsis. Message 2 consists of 128-bit blocks 1 and 2. The process starts with Message 1 blocks 1, 2, and 3 being processed. A lightning bolt icon points to a yellow oval containing the text "New higher priority message 2 to be processed". This oval points to a box labeled "CRYP suspend sequence". From this box, an arrow points to the start of Message 2's blocks. After Message 2's blocks 1 and 2 are processed, an arrow points to a box labeled "CRYP resume sequence". From this box, an arrow points back to the continuation of Message 1's blocks, specifically to block 4. The diagram is labeled with "MSv43715V1" in the bottom right corner.

Diagram illustrating suspend mode management for CRYP operations. Message 1 is suspended after block 3 to allow Message 2 to be processed, then resumed.

A detailed description of suspend/resume operations can be found in each AES mode section.

40.4.10 CRYP DES/TDES basic chaining modes (ECB, CBC)

Overview

FIPS PUB 46-3 – 1999 (and ANSI X9.52-1998) provides a thorough explanation of the processing involved in the four operation modes supplied by the DES computing core: TDES-ECB encryption, TDES-ECB decryption, TDES-CBC encryption and TDES-CBC decryption. This section only gives a brief explanation of each mode.

DES/TDES-ECB encryption

Figure 349 illustrates the encryption in DES and TDES Electronic CodeBook (DES/TDES-ECB) mode. This mode is selected by programming ALGOMODE 0x0 and ALGODIR to 0 in CRYP_CR.

Figure 349. DES/TDES-ECB mode encryption

Figure 349. DES/TDES-ECB mode encryption diagram. The diagram shows the flow of data from an input block (P) through a series of DES/TDES operations (encrypt, decrypt, encrypt) using keys K1, K2, and K3, resulting in an output block (O) which is then swapped to produce the ciphertext (C).
graph TD
    P[IN FIFO plaintext P] -- "P, 64 bits" --> S1[swapping]
    S1 --> DEA1[DEA, encrypt]
    K1[K1 64] --> DEA1
    DEA1 --> DEA2[DEA, decrypt]
    K2[K2 64] --> DEA2
    DEA2 --> DEA3[DEA, encrypt]
    K3[K3 64] --> DEA3
    DEA3 -- "O, 64 bits" --> S2[swapping]
    S2 -- "C, 64 bits" --> C[OUT FIFO ciphertext C]
  

The diagram illustrates the data flow for DES/TDES-ECB encryption. It starts with an 'IN FIFO plaintext P' block. An arrow labeled 'P, 64 bits' points down to a 'swapping' block. A 'DATATYPE' input is shown to the left of this block. From the 'swapping' block, an arrow points down to a 'DEA, encrypt' block. A key 'K1' (64 bits) is input to this block. The output of 'DEA, encrypt' points down to a 'DEA, decrypt' block. A key 'K2' (64 bits) is input to this block. The output of 'DEA, decrypt' points down to a 'DEA, encrypt' block. A key 'K3' (64 bits) is input to this block. The output of this block is labeled 'O, 64 bits' and points down to another 'swapping' block. A 'DATATYPE' input is shown to the left of this block. From this 'swapping' block, an arrow labeled 'C, 64 bits' points down to an 'OUT FIFO ciphertext C' block.

Figure 349. DES/TDES-ECB mode encryption diagram. The diagram shows the flow of data from an input block (P) through a series of DES/TDES operations (encrypt, decrypt, encrypt) using keys K1, K2, and K3, resulting in an output block (O) which is then swapped to produce the ciphertext (C).
  1. 1. K: key; C: cipher text; I: input block; O: output block; P: plain text.

A 64-bit plaintext data block (P) is used after bit/byte/half-word as the input block (I). The input block is processed through the DEA in the encrypt state using K1. The output of this process is fed back directly to the input of the DEA where the DES is performed in the decrypt state using K2. The output of this process is fed back directly to the input of the DEA where the DES is performed in the encrypt state using K3. The resultant 64-bit output block (O) is used, after bit/byte/half-word swapping, as ciphertext (C) and it is pushed into the OUT FIFO.

Note: For more information on data swapping, refer to Section 40.4.16: CRYP data registers and data swapping . Detailed DES/TDES encryption sequence can be found in Section 40.4.5: CRYP procedure to perform a cipher operation .

DES/TDES-ECB mode decryption

Figure 350 illustrates the decryption in DES and TDES Electronic CodeBook (DES/TDES-ECB) mode. This mode is selected by programming ALGOMODE to 0x0 and ALGODIR to 1 in CRYP_CR.

Figure 350. DES/TDES-ECB mode decryption

Diagram of DES/TDES-ECB mode decryption process. The flow starts with 'IN FIFO ciphertext C' (64 bits) entering a 'swapping' block controlled by 'DATATYPE'. The output is 'I, 64 bits' (input block). This block is processed by a 'DEA, decrypt' block using key 'K3' (64 bits). The output is fed back into a 'DEA, encrypt' block using key 'K2' (64 bits). The output of this block is fed into a 'DEA, decrypt' block using key 'K1' (64 bits). The output is 'O, 64 bits' (output block), which then enters another 'swapping' block controlled by 'DATATYPE'. The final output is 'P, 64 bits' (plaintext) in the 'OUT FIFO'.
graph TD
    C["IN FIFO
ciphertext C
C, 64 bits"] --> S1[swapping] S1 --> I["I, 64 bits"] I --> D1["DEA, decrypt
K3 64"] D1 --> E1["DEA, encrypt
K2 64"] E1 --> D2["DEA, decrypt
K1 64"] D2 --> O["O, 64 bits"] O --> S2[swapping] S2 --> P["P, 64 bits"] P --> OUT["OUT FIFO
plaintext P"]

MS19021V1

Diagram of DES/TDES-ECB mode decryption process. The flow starts with 'IN FIFO ciphertext C' (64 bits) entering a 'swapping' block controlled by 'DATATYPE'. The output is 'I, 64 bits' (input block). This block is processed by a 'DEA, decrypt' block using key 'K3' (64 bits). The output is fed back into a 'DEA, encrypt' block using key 'K2' (64 bits). The output of this block is fed into a 'DEA, decrypt' block using key 'K1' (64 bits). The output is 'O, 64 bits' (output block), which then enters another 'swapping' block controlled by 'DATATYPE'. The final output is 'P, 64 bits' (plaintext) in the 'OUT FIFO'.
  1. 1. K: key; C: cipher text; I: input block; O: output block; P: plain text.

A 64-bit ciphertext block (C) is used, after bit/byte/half-word swapping, as the input block (I). The keying sequence is reversed compared to that used in the encryption process. The input block is processed through the DEA in the decrypt state using K3. The output of this process is fed back directly to the input of the DEA where the DES is performed in the encrypt state using K2. The new result is directly fed to the input of the DEA where the DES is performed in the decrypt state using K1. The resultant 64-bit output block (O), after bit/byte/half-word swapping, produces the plaintext (P).

Note: For more information on data swapping refer to Section 40.4.16: CRYP data registers and data swapping . Detailed DES/TDES encryption sequence can be found in Section 40.4.5: CRYP procedure to perform a cipher operation .

DES/TDES-CBC encryption

Figure 351 illustrates the encryption in DES and TDES Cipher Block Chaining (DES/TDES-CBC) mode. This mode is selected by programming ALGOMODE to 0x1 and ALGODIR to 0 in CRYP_CR.

Figure 351. DES/TDES-CBC mode encryption

Diagram of DES/TDES-CBC mode encryption process. The diagram shows the flow of data from an IN FIFO (plaintext P) through a swapping block (producing Ps, 64 bits) to an XOR gate. The XOR gate also takes an initialization vector (IV) from an IV0(L/R) register. The output of the XOR gate (I, 64 bits) is processed by a DEA (encrypt) block using key K1. The output of the DEA (O, 64 bits) is then passed through another swapping block (producing C, 64 bits) to an OUT FIFO (ciphertext C). A feedback loop shows that the output O is written back into the IV register at the same time it is pushed into the OUT FIFO. The diagram also shows keys K1, K2, and K3 being used by the DEA blocks. A note indicates that AHB2 data write (before CRYP is enabled) is used to write data into the IN FIFO.
Diagram of DES/TDES-CBC mode encryption process. The diagram shows the flow of data from an IN FIFO (plaintext P) through a swapping block (producing Ps, 64 bits) to an XOR gate. The XOR gate also takes an initialization vector (IV) from an IV0(L/R) register. The output of the XOR gate (I, 64 bits) is processed by a DEA (encrypt) block using key K1. The output of the DEA (O, 64 bits) is then passed through another swapping block (producing C, 64 bits) to an OUT FIFO (ciphertext C). A feedback loop shows that the output O is written back into the IV register at the same time it is pushed into the OUT FIFO. The diagram also shows keys K1, K2, and K3 being used by the DEA blocks. A note indicates that AHB2 data write (before CRYP is enabled) is used to write data into the IN FIFO.

K: key; C: cipher text; I: input block; O: output block; Ps: plain text before swapping (when decoding) or after swapping (when encoding); P: plain text; IV: initialization vectors.

This mode begins by dividing a plaintext message into 64-bit data blocks. In TCBC encryption, the first input block ( \( I_1 \) ), obtained after bit/byte/half-word swapping, is formed by exclusive-ORing the first plaintext data block ( \( P_1 \) ) with a 64-bit initialization vector IV ( \( I_1 = IV \oplus P_1 \) ). The input block is processed through the DEA in the encrypt state using K1. The output of this process is fed back directly to the input of the DEA, which performs the DES in the decrypt state using K2. The output of this process is fed directly to the input of the DEA, which performs the DES in the encrypt state using K3. The resultant 64-bit output block ( \( O_1 \) ) is used directly as the ciphertext ( \( C_1 \) ), that is, \( C_1 = O_1 \) .

This first ciphertext block is then exclusive-ORed with the second plaintext data block to produce the second input block, ( \( I_2 = (C_1 \oplus P_2) \) ). Note that \( I_2 \) and \( P_2 \) now refer to the second block. The second input block is processed through the TDEA to produce the second ciphertext block.

This encryption process continues to “chain” successive cipher and plaintext blocks together until the last plaintext block in the message is encrypted.

If the message does not consist of an integral number of data blocks, then the final partial data block should be encrypted in a manner specified for the application.

Note: For more information on data swapping refer to Section 40.4.16: CRYP data registers and data swapping .

Detailed DES/TDES encryption sequence can be found in Section 40.4.5: CRYP procedure to perform a cipher operation .

DES/TDES-CBC decryption

Figure 351 illustrates the decryption in DES and TDES Cipher Block Chaining (DES/TDES-ECB) mode. This mode is selected by writing ALGOMODE to 0x1 and ALGODIR to 1 in CRYP_CR.

Figure 352. DES/TDES-CBC mode decryption

Diagram of DES/TDES-CBC mode decryption process. The flow starts with ciphertext C (64 bits) from an IN FIFO, passing through a swapping block to become input block I (64 bits). I is then processed through three DEA stages: decrypt with key K3, encrypt with key K2, and decrypt with key K1. The output O (64 bits) is XORed with the initialization vector IV0(L/R) to produce Ps (64 bits). Ps then passes through another swapping block to become plaintext P (64 bits), which is pushed into an OUT FIFO. A note indicates that I is written back into IV at the same time as P is pushed into the OUT FIFO. An AHB2 data write (before CRYP is enabled) is shown to the IV0(L/R) register. The diagram is labeled MS19022V1.
Diagram of DES/TDES-CBC mode decryption process. The flow starts with ciphertext C (64 bits) from an IN FIFO, passing through a swapping block to become input block I (64 bits). I is then processed through three DEA stages: decrypt with key K3, encrypt with key K2, and decrypt with key K1. The output O (64 bits) is XORed with the initialization vector IV0(L/R) to produce Ps (64 bits). Ps then passes through another swapping block to become plaintext P (64 bits), which is pushed into an OUT FIFO. A note indicates that I is written back into IV at the same time as P is pushed into the OUT FIFO. An AHB2 data write (before CRYP is enabled) is shown to the IV0(L/R) register. The diagram is labeled MS19022V1.
  1. 1. K: key; C: cipher text; I: input block; O: output block; Ps: plain text before swapping (when decoding) or after swapping (when encoding); P: plain text; IV: initialization vectors.

In this mode the first ciphertext block ( \( C_1 \) ) is used directly as the input block ( \( I_1 \) ). The keying sequence is reversed compared to that used for the encrypt process. The input block is processed through the DEA in the decrypt state using \( K_3 \) . The output of this process is fed directly to the input of the DEA where the DES is processed in the encrypt state using \( K_2 \) . This resulting value is directly fed to the input of the DEA where the DES is processed in the decrypt state using \( K_1 \) . The resulting output block is exclusive-ORed with the IV (which must be the same as that used during encryption) to produce the first plaintext block ( \( P_1 = O_1 \oplus IV \) ).

The second ciphertext block is then used as the next input block and is processed through the TDEA. The resulting output block is exclusive-ORed with the first ciphertext block to produce the second plaintext data block ( \( P_2 = O_2 \oplus C_1 \) ). Note that \( P_2 \) and \( O_2 \) refer to the second block of data.

The DES/TDES-CBC decryption process continues in this manner until the last complete ciphertext block has been decrypted.

Ciphertext representing a partial data block must be decrypted in a manner specified for the application.

Note: For more information on data swapping refer to Section 40.4.16: CRYP data registers and data swapping .

Detailed DES/TDES encryption sequence can be found in Section 40.4.5: CRYP procedure to perform a cipher operation .

DES/TDES suspend/resume operations in ECB/CBC modes

Before interrupting the current message, the user application must respect the following steps:

  1. 1. If DMA is used, stop the DMA transfers to the IN FIFO by clearing to 0 the DIEN bit in the CRYP_DMACR register.
  2. 2. Wait until both the IN and the OUT FIFOs are empty (IFEM = 1 and OFNE = 0 in the CRYP_SR) and the BUSY bit is cleared. Alternatively, as the input FIFO can contain up to four unprocessed DES blocks, the application could decide for real-time reason to interrupt the cryptographic processing without waiting for the IN FIFO to be empty. In this case, the alternative is:
    1. a) Wait until OUT FIFO is empty (OFNE = 0).
    2. b) Read back the data loaded in the IN FIFO that have not been processed and save them in the memory until the IN FIFO is empty.
  3. 3. If DMA is used stop the DMA transfers from the OUT FIFO by clearing to 0 the DOEN bit in the CRYP_DMACR register.
  4. 4. Disable the cryptographic processor by setting the CRYPTEN bit to 0 in CRYP_CR, then save the current configuration (bits [9:2] in the CRYP_CR register). If CBC mode is selected, save the initialization vector registers, since CRYP_IVx registers have changed from initial values during the data processing.

Note: Key registers do not need to be saved as the original key value is known by the application.

  1. 5. If DMA is used, save the DMA controller status (such as the pointers to IN and OUT data transfers, number of remaining bytes).

To resume message processing, the user application must respect the following sequence:

  1. 1. If DMA is used, reconfigure the DMA controller to complete the rest of the FIFO IN and FIFO OUT transfers.
  2. 2. Make sure the cryptographic processor is disabled by reading the CRYPTEN bit in CRYP_CR (it must be 0).
  3. 3. Configure again the cryptographic processor with the initial setting in CRYP_CR, as well as the key registers using the saved configuration.
  4. 4. If the CBC mode is selected, restore CRYP_IVx registers using the saved configuration.
  5. 5. Optionally, write the data that were saved during context saving into the IN FIFO.
  6. 6. Enable the cryptographic processor by setting the CRYPTEN bit to 1.
  7. 7. If DMA is used, enable again DMA requests for the cryptographic processor, by setting to 1 the DIEN and DOEN bits in the CRYP_DMACR register.

40.4.11 CRYP AES basic chaining modes (ECB, CBC)

Overview

FIPS PUB 197 (November 26, 2001) provides a thorough explanation of the processing involved in the four basic operation modes supplied by the AES computing core: AES-ECB encryption, AES-ECB decryption, AES-CBC encryption and AES-CBC decryption. This section only gives a brief explanation of each mode.

AES ECB encryption

Figure 353 illustrates the AES Electronic codebook (AES-ECB) mode encryption. This mode is selected by writing ALGOMODE to 0x4 and ALGODIR to 0 in CRYP_CR.

Figure 353. AES-ECB mode encryption

Figure 353. AES-ECB mode encryption flow diagram

The diagram illustrates the data flow for AES-ECB encryption. It starts with the 'IN FIFO plaintext P' block at the top. An arrow labeled 'P, 128 bits' points down to a 'swapping' block. A 'DATATYPE' input is shown to the left of this block. Below the 'swapping' block, an arrow labeled 'I, 128 bits' points down to the 'AEA, encrypt' block. To the left of the 'AEA, encrypt' block is a 'K0...3(1)' block, with an arrow labeled '128/192 or 256' pointing to the 'AEA, encrypt' block. Below the 'AEA, encrypt' block, an arrow points down to another 'swapping' block, which also has a 'DATATYPE' input from the left. Below this second 'swapping' block, an arrow labeled 'C, 128 bits' points down to the 'OUT FIFO ciphertext C' block at the bottom. The identifier 'ai16071b' is located in the bottom right corner of the diagram area.

Figure 353. AES-ECB mode encryption flow diagram
  1. 1. K: key; C: cipher text; I: input block; O: output block; P: plain text.
  2. 2. If Key size = 128: Key = [K3 K2].
    If Key size = 192: Key = [K3 K2 K1].
    If Key size = 256: Key = [K3 K2 K1 K0].

In this mode a 128- bit plaintext data block (P) is used after bit/byte/half-word swapping as the input block (I). The input block is processed through the AEA in the encrypt state using the 128, 192 or 256-bit key. The resultant 128-bit output block (O) is used after bit/byte/half-word swapping as ciphertext (C). It is then pushed into the OUT FIFO.

For more information on data swapping refer to Section 40.4.16: CRYP data registers and data swapping .

AES ECB decryption

Figure 354 illustrates the AES Electronic codebook (AES-ECB) mode decryption. This mode is selected by programming ALGOMODE to 0x4 and ALGODIR to 1 in CRYP_CR.

Figure 354. AES-ECB mode decryption

Figure 354. AES-ECB mode decryption flow diagram

The diagram illustrates the data flow for AES-ECB decryption. It starts with an 'IN FIFO' containing 'ciphertext C'. An arrow labeled 'C, 128 bits' points down to a 'swapping' block. A 'DATATYPE' input is shown to the left of this block. The output of the 'swapping' block is 'I, 128 bits', which points down to an 'AEA, decrypt' block. To the left of the 'AEA, decrypt' block is a key input 'K0...3(1)' with a slash and '128/192 or 256'. The output of the 'AEA, decrypt' block is 'O, 128 bits', which points down to another 'swapping' block. A 'DATATYPE' input is shown to the left of this block. The output of the second 'swapping' block is 'P, 128 bits', which points down to an 'OUT FIFO' containing 'plaintext P'. The identifier 'MS19023V1' is in the bottom right corner of the diagram area.

Figure 354. AES-ECB mode decryption flow diagram
  1. 1. K: key; C: cipher text; I: input block; O: output block; P: plain text.
  2. 2. If Key size = 128 => Key = [K3 K2]
    If Key size = 192 => Key = [K3 K2 K1]
    If Key size = 256 => Key = [K3 K2 K1 K0].

To perform an AES decryption in ECB mode, the secret key has to be prepared (it is necessary to execute the complete key schedule for encryption) by collecting the last round key, and using it as the first round key for the decryption of the ciphertext. This preparation phase is computed by the AES core. Refer to Section 40.4.7: Preparing the CRYP AES key for decryption for more details on how to prepare the key.

When the key preparation is complete, the decryption proceed as follows: a 128-bit ciphertext block (C) is used after bit/byte/half-word swapping as the input block (I). The keying sequence is reversed compared to that of the encryption process. The resultant 128-bit output block (O), after bit/byte or half-word swapping, produces the plaintext (P). The AES-CBC decryption process continues in this manner until the last complete ciphertext block has been decrypted.

For more information on data swapping refer to Section 40.4.16: CRYP data registers and data swapping .

AES CBC encryption

Figure 355 illustrates the AES Cipher block chaining (AES-CBC) mode encryption. This mode is selected by writing ALGOMODE to 0x5 and ALGODIR to 0 in CRYP_CR.

Figure 355. AES-CBC mode encryption

Figure 355. AES-CBC mode encryption diagram. The diagram shows the flow of data through the CRYP processor. Plaintext P (128 bits) is read from the IN FIFO and passes through a 'swapping' block (controlled by DATATYPE). The output is Ps (128 bits). Ps is XORed with the Initialization Vector IV (which is [IV1 IV0]^(2)). The result is I (128 bits). I is then processed by the AEA (encrypt) block using a key K (0...3^(3), which can be 128, 192, or 256 bits). The output is O (128 bits). O is written back into the IV register and also passes through another 'swapping' block (controlled by DATATYPE) to produce the ciphertext C (128 bits), which is then written to the OUT FIFO. A dashed box indicates that O is written back into IV at the same time it is pushed into the OUT FIFO.
Figure 355. AES-CBC mode encryption diagram. The diagram shows the flow of data through the CRYP processor. Plaintext P (128 bits) is read from the IN FIFO and passes through a 'swapping' block (controlled by DATATYPE). The output is Ps (128 bits). Ps is XORed with the Initialization Vector IV (which is [IV1 IV0]^(2)). The result is I (128 bits). I is then processed by the AEA (encrypt) block using a key K (0...3^(3), which can be 128, 192, or 256 bits). The output is O (128 bits). O is written back into the IV register and also passes through another 'swapping' block (controlled by DATATYPE) to produce the ciphertext C (128 bits), which is then written to the OUT FIFO. A dashed box indicates that O is written back into IV at the same time it is pushed into the OUT FIFO.
  1. 1. K: key; C: cipher text; I: input block; O: output block; Ps: plain text before swapping (when decoding) or after swapping (when encoding); P: plain text; IV: Initialization vectors.
  2. 2. \( IV_x = [IV_x^R \ IV_x^L] \) , R = right, L = left.
  3. 3. If Key size = 128 => Key = [K3 K2].
    If Key size = 192 => Key = [K3 K2 K1]
    If Key size = 256 => Key = [K3 K2 K1 K0].

In this mode the first input block ( \( I_1 \) ) obtained after bit/byte/half-word swapping is formed by exclusive-ORing the first plaintext data block ( \( P_1 \) ) with a 128-bit initialization vector IV ( \( I_1 = IV \oplus P_1 \) ). The input block is processed through the AEA in the encrypt state using the 128-, 192- or 256-bit key ( \( K_{0..3} \) ). The resultant 128-bit output block ( \( O_1 \) ) is used directly as ciphertext ( \( C_1 \) ), that is, \( C_1 = O_1 \) . This first ciphertext block is then exclusive-ORed with the second plaintext data block to produce the second input block, \( (I_2) = (C_1 \oplus P_2) \) . Note that \( I_2 \) and \( P_2 \) now refer to the second block. The second input block is processed through the AEA to produce the second ciphertext block. This encryption process continues to “chain” successive cipher and plaintext blocks together until the last plaintext block in the message is encrypted.

If the message does not consist of an integral number of data blocks, then the final partial data block should be encrypted in a manner specified for the application, as explained in Section 40.4.8: CRYP stealing and data padding .

For more information on data swapping, refer to Section 40.4.16: CRYP data registers and data swapping .

AES CBC decryption

Figure 356 illustrates the AES Cipher block chaining (AES-CBC) mode decryption. This mode is selected by writing ALGOMODE to 0x5 and ALGODIR to 1 in CRYP_CR.

Figure 356. AES-CBC mode decryption

Block diagram of AES-CBC mode decryption. The process starts with 'IN FIFO ciphertext C' (128 bits) entering a 'swapping' block. The output 'I, 128 bits' goes into 'AEA, decrypt'. The 'AEA, decrypt' block also takes a key 'K0...3(3)' (128, 192, or 256 bits) as input. The output 'O, 128 bits' from the AEA is XORed with the 'IV=[IV1 IV0](2)' (128 bits) from an 'IV' block. The result 'Ps, 128 bits' goes into another 'swapping' block, which outputs 'P, 128 bits' to the 'OUT FIFO plaintext P'. A dashed box indicates that 'I is written back into IV at the same time I as P is pushed into the OUT FIFO'. An 'AHB2 data write (before CRYP is enabled)' is shown to the 'IV' block. The 'DATATYPE' control is shown for both 'swapping' blocks. The diagram is labeled 'MS19024V1'.
Block diagram of AES-CBC mode decryption. The process starts with 'IN FIFO ciphertext C' (128 bits) entering a 'swapping' block. The output 'I, 128 bits' goes into 'AEA, decrypt'. The 'AEA, decrypt' block also takes a key 'K0...3(3)' (128, 192, or 256 bits) as input. The output 'O, 128 bits' from the AEA is XORed with the 'IV=[IV1 IV0](2)' (128 bits) from an 'IV' block. The result 'Ps, 128 bits' goes into another 'swapping' block, which outputs 'P, 128 bits' to the 'OUT FIFO plaintext P'. A dashed box indicates that 'I is written back into IV at the same time I as P is pushed into the OUT FIFO'. An 'AHB2 data write (before CRYP is enabled)' is shown to the 'IV' block. The 'DATATYPE' control is shown for both 'swapping' blocks. The diagram is labeled 'MS19024V1'.
  1. 1. K: key; C: cipher text; I: input block; O: output block; Ps: plain text before swapping (when decoding) or after swapping (when encoding); P: plain text; IV: Initialization vectors.
  2. 2. \( IV_x = [IV_{xR} \ IV_{xL}] \) , R = right, L = left.
  3. 3. If Key size = 128 => Key = [K3 K2].
    If Key size = 192 => Key = [K3 K2 K1].
    If Key size = 256 => Key = [K3 K2 K1 K0].

In CBC mode, like in ECB mode, the secret key must be prepared to perform an AES decryption. Refer to Section 40.4.7: Preparing the CRYP AES key for decryption for more details on how to prepare the key.

When the key preparation process is complete, the decryption proceeds as follows: the first 128-bit ciphertext block ( \( C_1 \) ) is used directly as the input block ( \( I_1 \) ). The input block is processed through the AEA in the decrypt state using the 128-, 192- or 256-bit key. The resulting output block is exclusive-ORed with the 128-bit initialization vector IV (which must be the same as that used during encryption) to produce the first plaintext block ( \( P_1 = O_1 \oplus IV \) ).

The second ciphertext block is then used as the next input block and is processed through the AEA. The resulting output block is exclusive-ORed with the first ciphertext block to produce the second plaintext data block ( \( P_2 = O_2 \oplus C_1 \) ). Note that \( P_2 \) and \( O_2 \) refer to the second block of data. The AES-CBC decryption process continues in this manner until the last complete ciphertext block has been decrypted.

Ciphertext representing a partial data block must be decrypted in a manner specified for the application, as explained in Section 40.4.8: CRYP stealing and data padding .

For more information on data swapping, refer to Section 40.4.16: CRYP data registers and data swapping .

AES suspend/resume operations in ECB/CBC modes

Before interrupting the current message, the user application must respect the following sequence:

  1. 1. If DMA is used, stop the DMA transfers to the IN FIFO by clearing to 0 the DIEN bit in the CRYP_DMACR register.
  2. 2. Wait until both the IN and the OUT FIFOs are empty (IFEM = 1 and OFNE = 0 in the CRYP_SR) and the BUSY bit is cleared.
  3. 3. If DMA is used, stop the DMA transfers from the OUT FIFO by clearing to 0 the DOEN bit in the CRYP_DMACR register.
  4. 4. Disable the CRYP by setting the CRYPTEN bit to 0 in CRYP_CR, then save the current configuration (bits [9:2] in the CRYP_CR register). If ECB mode is not selected, save the initialization vector registers, because CRYP_IVx registers have changed from initial values during the data processing.

Note: Key registers do not need to be saved as the original key value is known by the application.

  1. 5. If DMA is used, save the DMA controller status (such as pointers to IN and OUT data transfers, number of remaining bytes).

To resume message processing, the user application must respect the following sequence:

  1. 1. If DMA is used, reconfigure the DMA controller to complete the rest of the FIFO IN and FIFO OUT transfers.
  2. 2. Make sure the cryptographic processor is disabled by reading the CRYPTEN bit in CRYP_CR (it must be set to 0).
  3. 3. Configure the cryptographic processor again with the initial setting in CRYP_CR, as well as the key registers using the saved configuration.
  4. 4. For AES-ECB or AES-CBC decryption, the key must be prepared again, as described in Section 40.4.7: Preparing the CRYP AES key for decryption .
  5. 5. If ECB mode is not selected, restore CRYP_IVx registers using the saved configuration.
  6. 6. Enable the cryptographic processor by setting the CRYPTEN bit to 1.
  7. 7. If DMA is used, enable again the DMA requests from the cryptographic processor, by setting DIEN and DOEN bits to 1 in the CRYP_DMACR register.

40.4.12 CRYP AES counter mode (AES-CTR)

Overview

The AES counter mode (CTR) uses the AES block as a key stream generator. The generated keys are then XORed 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 357 .

Figure 357. Message construction for the Counter mode

Diagram illustrating the message construction for the Counter mode (CTR). The diagram shows the structure of the ciphertext (C) and the corresponding plaintext (P). The ciphertext is composed of an Initial Counter Block (ICB) followed by Encrypted Ciphertext (C) and Padding. The ICB is further detailed as being composed of a Nonce, Initialization vector (IV), and Counter (0x1). The diagram indicates 16-Byte boundaries for the ciphertext blocks and 4-Byte boundaries for the ICB fields. A 'decrypt' arrow points from the ciphertext to the plaintext.

The diagram illustrates the message construction for the Counter mode (CTR). It shows the structure of the ciphertext (C) and the corresponding plaintext (P). The ciphertext is composed of an Initial Counter Block (ICB) followed by Encrypted Ciphertext (C) and Padding. The ICB is further detailed as being composed of a Nonce, Initialization vector (IV), and Counter (0x1). The diagram indicates 16-Byte boundaries for the ciphertext blocks and 4-Byte boundaries for the ICB fields. A 'decrypt' arrow points from the ciphertext to the plaintext.

Diagram illustrating the message construction for the Counter mode (CTR). The diagram shows the structure of the ciphertext (C) and the corresponding plaintext (P). The ciphertext is composed of an Initial Counter Block (ICB) followed by Encrypted Ciphertext (C) and Padding. The ICB is further detailed as being composed of a Nonce, Initialization vector (IV), and Counter (0x1). The diagram indicates 16-Byte boundaries for the ciphertext blocks and 4-Byte boundaries for the ICB fields. A 'decrypt' arrow points from the ciphertext to the plaintext.

The structure of this message is as below:

AES CTR processing

Figure 358 (respectively Figure 359) describes the AES-CTR encryption (respectively decryption) process implemented within this peripheral. This mode is selected by programming ALGOMODE bitfield to 0x6 in CRYP_CR.

Figure 358. AES-CTR mode encryption

Block diagram of AES-CTR mode encryption process. The diagram shows the flow of data from an IN FIFO (plaintext P) through a swapping block, an AEA (encrypt) block, an XOR block, and an OUT FIFO (ciphertext C). The AEA block also receives an initialization vector (IV) and a key (K0...3). The IV is incremented by 1 and written back into the IV0...1(L/R) block. The swapping block is controlled by DATATYPE. The process is described in the text as: P (128 bits) from IN FIFO goes to swapping block. The output of the swapping block (Ps, 128 bits) goes to the AEA (encrypt) block. The AEA block also receives I (128 bits) from IV0...1(L/R) and K0...3 (128, 192, or 256 bits). The output of the AEA block (O, 128 bits) is XORed with Ps to produce Cs (128 bits). Cs then goes to the swapping block. The output of the swapping block is C (128 bits), which is written to the OUT FIFO. A dashed box indicates that (I + 1) is written back into IV at the same time that C is pushed in OUT FIFO. An AHB2 data write (before CRYP is enabled) is shown entering the IV0...1(L/R) block.
graph TD
    IN_FIFO[IN FIFO
plaintext P] -- "P, 128 bits" --> SWAP1[swapping] SWAP1 -- "Ps, 128 bits" --> AEA[AEA, encrypt] AEA -- "O, 128 bits" --> XOR((+)) XOR -- "Cs, 128 bits" --> SWAP2[swapping] SWAP2 -- "C, 128 bits" --> OUT_FIFO[OUT FIFO
ciphertext C] IV[IV0...1(L/R)] -- "I, 128 bits" --> AEA INC[+1] --> IV KEY[K0...3] -- "128, 192 or 256 bits" --> AEA AHB2[AHB2 data write
(before CRYP is enabled)] --> IV DTYPE1[DATATYPE] --> SWAP1 DTYPE2[DATATYPE] --> SWAP2 subgraph DashedBox [ ] INC IV end style DashedBox fill:none,stroke-dasharray: 5 5
Block diagram of AES-CTR mode encryption process. The diagram shows the flow of data from an IN FIFO (plaintext P) through a swapping block, an AEA (encrypt) block, an XOR block, and an OUT FIFO (ciphertext C). The AEA block also receives an initialization vector (IV) and a key (K0...3). The IV is incremented by 1 and written back into the IV0...1(L/R) block. The swapping block is controlled by DATATYPE. The process is described in the text as: P (128 bits) from IN FIFO goes to swapping block. The output of the swapping block (Ps, 128 bits) goes to the AEA (encrypt) block. The AEA block also receives I (128 bits) from IV0...1(L/R) and K0...3 (128, 192, or 256 bits). The output of the AEA block (O, 128 bits) is XORed with Ps to produce Cs (128 bits). Cs then goes to the swapping block. The output of the swapping block is C (128 bits), which is written to the OUT FIFO. A dashed box indicates that (I + 1) is written back into IV at the same time that C is pushed in OUT FIFO. An AHB2 data write (before CRYP is enabled) is shown entering the IV0...1(L/R) block.
  1. 1. K: key; C: cipher text; I: input Block; o: output block; Ps: plain text before swapping (when decoding) or after swapping (when encoding); Cs: cipher text after swapping (when decoding) or before swapping (when encoding); P: plain text; IV: Initialization vectors.

Figure 359. AES-CTR mode decryption

Block diagram of AES-CTR mode decryption. The diagram shows the flow of data from an IN FIFO (ciphertext P) through a swapping block (producing C, 128 bits) to an XOR gate. The XOR gate also receives an output O (128 bits) from an AEA (encrypt) block. The output of the XOR gate is Ps (128 bits), which then passes through another swapping block (producing P, 128 bits) to an OUT FIFO (plaintext C). The AEA (encrypt) block takes a key K0...3 (128, 192, or 256 bits) and an input block I (128 bits) as input. The input block I is derived from IV0...1(L/R) and is incremented by +1. The IV0...1(L/R) block is initialized by an AHB2 data write (before CRYP is enabled). A dashed box indicates that (I + 1) is written back into IV at the same time that P is pushed in OUT FIFO. The diagram is labeled MS19025V1.
Block diagram of AES-CTR mode decryption. The diagram shows the flow of data from an IN FIFO (ciphertext P) through a swapping block (producing C, 128 bits) to an XOR gate. The XOR gate also receives an output O (128 bits) from an AEA (encrypt) block. The output of the XOR gate is Ps (128 bits), which then passes through another swapping block (producing P, 128 bits) to an OUT FIFO (plaintext C). The AEA (encrypt) block takes a key K0...3 (128, 192, or 256 bits) and an input block I (128 bits) as input. The input block I is derived from IV0...1(L/R) and is incremented by +1. The IV0...1(L/R) block is initialized by an AHB2 data write (before CRYP is enabled). A dashed box indicates that (I + 1) is written back into IV at the same time that P is pushed in OUT FIFO. The diagram is labeled MS19025V1.
  1. 1. K: key; C: cipher text; I: input Block; o: output block; Ps: plain text before swapping (when decoding) or after swapping (when encoding); Cs: cipher text after swapping (when decoding) or before swapping (when encoding); P: plain text; IV: Initialization vectors.

In CTR mode, the output block is XORed with the subsequent input block before it is input to the algorithm. Initialization vectors in the peripheral must be initialized as shown on Table 323 .

Table 323. Counter mode initialization vector

CRYP_IV1R[31:0]CRYP_IV1L[31:0]CRYP_IV0R[31:0]CRYP_IV0L[31:0]
IV[127:96]IV[95:64]IV[63:32]IV[31:0]
32-bit counter = 0x1

Unlike in CBC mode, which uses the CRYP_IVx registers only once when processing the first data block, in CTR mode IV registers are used for processing each data block, and the peripheral increments the least significant 32 bits (leaving the other most significant 96 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 will be XORed with the plaintext or cipher as input. Thus when ALGOMODE is set to 0x6, ALGODIR is don't care.

Note: In this mode the key must NOT be prepared for decryption.

The following sequence must be used to perform an encryption or a decryption in CTR chaining mode:

  1. 1. Make sure the cryptographic processor is disabled by clearing the CRYPTEN bit in the CRYP_CR register.
  2. 2. Configure CRYP_CR as follows:
    1. a) Program ALGOMODE bits to 0x6 to select CTR mode. ALGODIR can be set to any value.
    2. b) Configure the data type (1, 8, 16 or 32 bits) through the DATATYPE bits.
    3. c) Define the key length using KEYSIZE bits.
  3. 3. Initialize the key registers (128, 192 or 256 bits) in CRYP_KEYRx as well as the initialization vector (IV) as described in Table 323 .
  4. 4. Flush the IN and OUT FIFOs by writing the FFLUSH bit to 1 in the CRYP_CR register.
  5. 5. If it is the last block, optionally pad the data with zeros to have a complete block.
  6. 6. Append data in the cryptographic processor and read the result. The three possible scenarios are described in Section 40.4.5: CRYP procedure to perform a cipher operation .
  7. 7. Repeat the previous step until the second last block is processed. For the last block, execute the two previous steps. For this last block, the driver must discard the data that is not part of the data when the last block size 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 which was interrupted. Detailed CBC sequence can be found in Section 40.4.11: CRYP AES basic chaining modes (ECB, CBC) .

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

40.4.13 CRYP AES Galois/counter mode (GCM)

Overview

The AES Galois/counter mode (GCM) allows encrypting and authenticating the plaintext, and generating the correspondent 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 360 .

Figure 360. Message construction for the Galois/counter mode

Diagram illustrating the message construction for the Galois/counter mode (GCM).

The diagram shows the structure of a GCM message. It starts with a 16-byte Initial Counter Block (ICB), which is composed of a 96-bit Initialization vector (IV) and a 32-bit Counter. This is followed by Additional authenticated data (AAD) of length \( Len(A) \) . The AAD is followed by a 0-filled block. The next part is the Plaintext (P) of length \( Len(P) = Len(C) \) . This is followed by a 0-filled block. The last part is the Last block, which contains the length of A (on 64 bits) and the length of ciphertext C (on 64 bits). The AAD, Plaintext, and Last block are processed by an 'encrypt' function to produce the Authenticated & encrypted ciphertext (C). The ICB, AAD, and Last block are also processed by an 'authenticate' function to produce the Authentication tag (T). The 'auth.' function is shown below the ciphertext. A legend indicates that grey boxes represent zero padding / zeroed bits. The diagram is labeled MSv42157V1.

Diagram illustrating the message construction for the Galois/counter mode (GCM).

The structure of this message is defined as below:

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

Table 324. GCM last block definition

EndiannessBit[0]Bit[32]Bit[64]Bit[96]
Input data0x0Header length[31:0]0x0Payload length[31:0]

AES GCM processing

This mode is selected by writing ALGOMODE bitfield to 0x6 in CRYP_CR.

The mechanism for the confidentiality of the plaintext in GCM mode is a variation of the Counter mode, with a particular 32-bit incrementing function that generates the necessary sequence of counter blocks.

CRYP_IV registers are used for processing each data block. The cryptographic processor automatically increments the 32 least significant bits of the counter block. The first counter block (CB1) written by the application is equal to the Initial Counter Block incremented by one (see Table 325 ).

Table 325. GCM mode IV registers initialization

RegisterCRYP_IV0LR[31:0]CRYP_IV0RR[31:0]CRYP_IV1LR[31:0]CRYP_IV1RR[31:0]
Input dataICB[127:96]ICB[95:64]ICB[63:32]ICB[31:0]
32-bit counter = 0x2

Note: In this mode the key must NOT be prepared for decryption.

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

To process a GCM message, the driver must go through four phases, which are described in the following subsections.

1. GCM initialization phase

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

  1. Make sure the cryptographic processor is disabled by clearing the CRYPTEN bit in the CRYP_CR register.
  2. Select the GCM chaining mode by programming ALGOMODE bits to 0x8 in CRYP_CR. In the same register define the key length using KEYSIZE bits and the data type using DATATYPE bits.
  3. Configure GCM_CCMPH bits to 0b00 in CRYP_CR to indicate that the initialization phase is ongoing.
  4. Initialize the key registers (128, 192 or 256 bits) in CRYP_KEYRx as well as the initialization vector (IV) as defined in Table 325 .
  5. Set CRYPTEN bit to 1 to start the calculation of the hash key.
  6. Wait for the CRYPTEN bit to be cleared to 0 by the cryptographic processor, before moving on to the next phase.

2. GCM header phase

The below sequence shall be performed after the GCM initialization phase. It must be complete before jumping to the payload phase. The sequence is identical for encryption and decryption.

  1. Set the GCM_CCMPH bits to 0b01 in CRYP_CR to indicate that the header phase is ongoing.
  2. Set the CRYPTEN bit to 1 to start accepting data.
  3. If it is the last block of additional authenticated data, optionally pad the data with zeros to have a complete block.
  4. Append additional authenticated data in the cryptographic processor. The three possible scenarios are described in Section 40.4.5: CRYP procedure to perform a cipher operation .
  5. Repeat the previous step until the second last additional authenticated data block is processed. For the last block, execute the two previous steps. Once all the additional authenticated data have been supplied, wait until the BUSY flag is cleared before moving on to the next phase.

Note: This phase can be skipped if there is no additional authenticated data, i.e. Len(A) = 0.
In header and payload phases, CRYPTEN bit is not automatically cleared by the cryptographic processor.

3. GCM payload phase (encryption or decryption)

When the payload size is not null, this sequence must be executed after the GCM header phase. During this phase, the encrypted/decrypted payload is stored in the CRYP_DOUT register.

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

4. GCM final phase

In this last step, the cryptographic processor generates the GCM authentication tag and stores it in CRYP_DOUT register.

Note: In this final phase, data have to be inserted normally (no swapping).

Suspend/resume operations in GCM mode

Before interrupting the current message in header or payload phase, the user application must respect the following sequence:

  1. 1. If DMA is used, stop DMA transfers to the IN FIFO by clearing to 0 the DIEN bit in the CRYP_DMACR register.
  2. 2. Wait until both the IN and the OUT FIFOs are empty (IFEM = 1 and OFNE = 0 in the CRYP_SR register) and the BUSY bit is cleared.
  3. 3. If DMA is used, stop DMA transfers from the OUT FIFO by clearing to 0 the DOEN bit in the CRYP_DMACR register.
  4. 4. Disable the cryptographic processor by setting the CRYPTEN bit to 0 in CRYP_CR, then save the current configuration (bits [9:2], bits [17:16] and bits 19 of the CRYP_CR register). In addition, save the initialization vector registers, since CRYP_IVx registers have changed from their initial values during data processing.

Note: Key registers do not need to be saved as original their key value is known by the application.

  1. 5. Save context swap registers: CRYP_CSGCMCCM0..7R and CRYP_CSGCM0..7R
  2. 6. If DMA is used, save the DMA controller status (pointers to IN and OUT data transfers, number of remaining bytes, etc.).

To resume message processing, the user must respect the following sequence:

  1. 1. If DMA is used, reconfigure the DMA controller to complete the rest of the FIFO IN and FIFO OUT transfers.
  2. 2. Make sure the cryptographic processor is disabled by reading the CRYPTEN bit in CRYP_CR (it must be 0).
  3. 3. Configure again the cryptographic processor with the initial setting in CRYP_CR, as well as the key registers using the saved configuration.
  4. 4. Restore context swap registers: CRYP_CSGCMCCM0..7R and CRYP_CSGCM0..7R
  5. 5. Restore CRYP_IVx registers using the saved configuration.
  6. 6. Enable the cryptographic processor by setting the CRYPTEN bit to 1.
  7. 7. If DMA is used, enable again cryptographic processor DMA requests by setting to 1 the DIEN and DOEN bits in the CRYP_DMACR register.

Note: In Header phase, DMA OUT FIFO transfer is not used.

40.4.14 CRYP AES Galois message authentication code (GMAC)

Overview

The Galois message authentication code (GMAC) allows authenticating a plaintext and 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 in GMAC mode is given in Figure 361 .

Figure 361. Message construction for the Galois Message Authentication Code mode

Diagram illustrating the message construction for the Galois Message Authentication Code (GMAC) mode. The diagram shows a sequence of blocks: ICB (Initialization Counter Block), Authenticated data, and Last block. The ICB is split into an Initialization vector (IV) and a Counter. The Authenticated data is split into blocks of 16-byte boundaries. The Last block is split into a 0 (zero padding) and a Last block. The length of the authenticated data is indicated by Len(A). The diagram also shows the generation of an Authentication tag (T) from the Authenticated data and the Last block. A legend indicates that grey blocks represent zero padding.

The diagram illustrates the message construction for GMAC. It shows a sequence of blocks: ICB (Initialization Counter Block), Authenticated data, and Last block. The ICB is split into an Initialization vector (IV) and a Counter. The Authenticated data is split into blocks of 16-byte boundaries. The Last block is split into a 0 (zero padding) and a Last block. The length of the authenticated data is indicated by Len(A). The diagram also shows the generation of an Authentication tag (T) from the Authenticated data and the Last block. A legend indicates that grey blocks represent zero padding.

Diagram illustrating the message construction for the Galois Message Authentication Code (GMAC) mode. The diagram shows a sequence of blocks: ICB (Initialization Counter Block), Authenticated data, and Last block. The ICB is split into an Initialization vector (IV) and a Counter. The Authenticated data is split into blocks of 16-byte boundaries. The Last block is split into a 0 (zero padding) and a Last block. The length of the authenticated data is indicated by Len(A). The diagram also shows the generation of an Authentication tag (T) from the Authenticated data and the Last block. A legend indicates that grey blocks represent zero padding.

AES GMAC processing

This mode is selected by writing ALGOMODE bitfield to 0x6 in CRYP_CR.

GMAC algorithm corresponds to the GCM algorithm applied on a message composed only of an header. As a consequence, all steps and settings are the same as in GCM mode, except that the payload phase (3) is not used.

Suspend/resume operations in GMAC

GMAC is exactly the same as GCM algorithm except that only header phase (2) can be interrupted.

40.4.15 CRYP AES Counter with CBC-MAC (CCM)

Overview

The AES Counter with Cipher Block Chaining-Message Authentication Code (CCM) algorithm allows encrypting and authenticating the plaintext, and generating the correspondent ciphertext and tag (also known as message authentication code). To ensure confidentiality, CCM algorithm is based on AES 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 of 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 in CCM mode is given in Figure 362 .

Figure 362. Message construction for the Counter with CBC-MAC mode

Diagram illustrating the message construction for the Counter with CBC-MAC mode. It shows the layout of message blocks B0, Associated data (A), and Plaintext (P) with their respective lengths and zero padding. It also depicts the authentication and encryption flow resulting in the MAC (T) and Authenticated & encrypted ciphertext (C).

The diagram illustrates the message construction for the Counter with CBC-MAC mode. It shows the following components and processes:

Diagram illustrating the message construction for the Counter with CBC-MAC mode. It shows the layout of message blocks B0, Associated data (A), and Plaintext (P) with their respective lengths and zero padding. It also depicts the authentication and encryption flow resulting in the MAC (T) and Authenticated & encrypted ciphertext (C).

The structure of this message is as below:

This part of the message is only authenticated, not encrypted. This section has a known length, ALen , that can be a non-multiple of 16 bytes (see Figure 362 ). The standard also states that, on the MSB bits of the first message block (B1), the associated data length expressed in bytes ( a ) must be encoded as defined below:

Note: CCM chaining mode can also be used with associated data only (i.e. no payload).

As an example, the C.1 section in NIST Special Publication 800-38C gives the following:

N: 10111213 141516 (Nlen = 56 bits or 0x7 bytes)
A: 00010203 04050607 (ALen = 64 bits or 0x8 bytes)
P: 20212223 (PLen = 32 bits i.e. Q = 0x4 bytes)
T: 6084341b (TLen = 32 bits or t = 4)
B0: 4f101112 13141516 00000000 00000004
B1: 00080001 02030405 06070000 00000000
B2: 20212223 00000000 00000000 00000000
CTR0: 0710111213 141516 00000000 00000000
CTR1: 0710111213 141516 00000000 00000001

The usage of control blocks CTRx is explained in the following section. The generation of CTR0 from the first block (B0) must be managed by software.

AES CCM processing

This mode is selected by writing ALGOMODE bitfield to 0x9 in CRYP_CR.

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 data to generate a MAC, whose length is known. Counter mode encryption, which requires a sufficiently long sequence of counter blocks as input, is applied to the payload string and separately to the MAC. The resulting data, called the ciphertext C, is the output of the generation-encryption process on plaintext P.

CRYP_IV registers are used for processing each data block. The cryptographic processor automatically increments the CTR counter with a bit length defined by the first block (B0). The first counter written by application, CTR1, is equal to B0 with the first 5 bits zeroed and the most significant bits containing P byte length also zeroed, then incremented by one (see Table 326 ).

Table 326. CCM mode IV registers initialization

RegisterCRYP_IV0LR[31:0]CRYP_IV0RR[31:0]CRYP_IV1LR[31:0]CRYP_IV1RR[31:0]
Input dataB0[127:96], where the 5 most significant bits are set to 0 (flag bits)B0[95:64]B0[63:32]B0[31:0], where Q length bits are set to 0, except for bit 0 that is set to 1

Note: In this mode, the key must NOT be prepared for decryption.

To process a CCM message, the driver must go through four phases, which are described below.

1. CCM initialization phase

In this first step, the first block (B0) of the CCM message is programmed into the CRYP_DIN register. During this phase, the CRYP_DOUT register does not contain any output data. It is recommended to follow the sequence below:

  1. a) Make sure that the cryptographic processor is disabled by clearing the CRYPTEN bit in the CRYP_CR register.
  2. b) Select the CCM chaining mode by programming the ALGOMODE bits to 0x9 in the CRYP_CR register. In the same register define the key length using KEYSIZE bits and the data type using DATATYPE bits.
  3. c) Configure the GCM_CCMPH bits to 0b00 in CRYP_CR to indicate that we are in the initialization phase.
  4. d) Initialize the key registers (128, 192 or 256 bits) in CRYP_KEYRx as well as the initialization vector (IV) with CTR1 information, as defined in Table 326 .
  5. e) Set the CRYPTEN bit to 1 in CRYP_CR to start accepting data.
  6. f) Write the B0 packet into CRYP_DIN register, then wait for the CRYPTEN bit to be cleared to 0 by the cryptographic processor before moving on to the next phase.

Note: In this initialization phase, data have to be inserted normally (no swapping).

2. CCM header phase

The below sequence shall be performed after the CCM initialization phase. It must be complete before jumping to the payload phase. The sequence is identical for encryption and decryption. During this phase, the CRYP_DOUT register does not contain any output data.

  1. g) Set the GCM_CCMPH bit to 0b01 in CRYP_CR to indicate that the header phase is ongoing.
  2. h) Set the CRYPTEN bit to 1 to start accepting data.
  3. i) If it is the last block of associated data, optionally pad the data with zeros to have a complete block.
  4. j) Append the associated data in the cryptographic processor. The three possible scenarios are described in Section 40.4.5: CRYP procedure to perform a cipher operation .
  5. k) Repeat the previous step until the second last associated data block is processed. For the last block, execute the two previous steps. Once all the additional authenticated data have been supplied, wait until the BUSY flag is cleared.

Note: This phase can be skipped if there is no associated data (Alen = 0).

The first block of the associated data B1 must be formatted with the associated data length. This task must be managed by the driver.

3. CCM payload phase (encryption or decryption)

When the payload size is not null, this sequence must be performed after the CCM header phase. During this phase, the encrypted/decrypted payload is stored in the CRYP_DOUT register.

Note: This phase can be skipped if there is no payload data, i.e. Plen = 0 or Clen = Tlen

Note: Do not forget to remove \( LSB_{Tlen}(C) \) encrypted tag information when decrypting ciphertext C.

4. CCM final phase

In this last step, the cryptographic processor generates the CCM authentication tag and stores it in the CRYP_DOUT register.

Note: In this final phase, data have to be inserted normally (no swapping).

Suspend/resume operations in CCM mode

Before interrupting the current message in payload phase, the user application must respect the following sequence:

  1. 1. If DMA is used, stop the DMA transfers to the IN FIFO by clearing to 0 the DIEN bit in the CRYP_DMACR register.
  2. 2. Wait until both the IN and the OUT FIFOs are empty (IFEM = 1 and OFNE = 0 in the CRYP_SR register) and the BUSY bit is cleared.
  3. 3. If DMA is used, stop the DMA transfers from the OUT FIFO by clearing to 0 the DOEN bit in the CRYP_DMACR register.
  4. 4. Disable the cryptographic processor by setting the CRYPTEN bit to 0 in CRYP_CR, then save the current configuration (bits [9:2], bits [17:16] and bits 19 in the CRYP_CR register). In addition, save the initialization vector registers, since CRYP_IVx registers have changed from their initial values during the data processing.

Note: Key registers do not need to be saved as their original key value is known by the application.

  1. 5. Save context swap registers: CRYP_CSGCMCCM0..7R
  2. 6. If DMA is used, save the DMA controller status (pointers for IN and OUT data transfers, number of remaining bytes, etc.).

To resume message processing, the user application must respect the following sequence:

  1. 1. If DMA is used, reconfigure the DMA controller to complete the rest of the FIFO IN and FIFO OUT transfers.
  2. 2. Make sure the cryptographic processor is disabled by reading the CRYPTEN bit in CRYP_CR (must be 0).
  3. 3. Configure the cryptographic processor again with the initial setting in CRYP_CR and key registers using the saved configuration.
  4. 4. Restore context swap registers: CRYP_CSGCMCCM0..7R
  5. 5. Restore CRYP_IVx registers using the saved configuration.
  6. 6. Enable the cryptographic processor by setting the CRYPTEN bit to 1.
  7. 7. If DMA is used, enable again cryptographic processor DMA requests by setting to 1 the DIEN and DOEN bits in the CRYP_DMACR register.

Note: In Header phase DMA OUT FIFO transfer is not used.

40.4.16 CRYP data registers and data swapping

The CRYP_DIN register is the 32-bit wide data input register of the peripheral. It is used to enter into the input FIFO up to four 64-bit blocks (TDES) or two 128-bit blocks (AES) of plaintext (when encrypting) or ciphertext (when decrypting), one 32-bit word at a time.

The four adjacent (respectively two) words of the AES (respectively DES/TDES) data block are organized in big-endian order, with the most significant byte of a word on the lowest address.

The cryptographic accelerator can be configured to perform a bit, byte, half-word, or no swapping on the input data word in the CRYP_DINR register, before loading it to the CRYP processing core, and on the data output from the CRYP processing core, before sending it

to the CRYP_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 AES_CR register. The selection applies both to the input and the output of the CRYP processing core.

Note: The CRYP Key registers (CRYP_Kx(L/R)) and initialization registers (CRYP_IVx(L/R)) are not sensitive to the swap mode selected.

More information on data input and data swapping can be found in the next subsections.

DES/TDES data input and output

A 64-bit data block is entered into the cryptographic processor with two successive 32-bit word write operations to the CRYP_DINR register (DIN[31:0] bitfield), the most significant word (bits [64:33]) first, the least significant word (bits [32:1]) last.

A 64-bit data block is retrieved from the cryptographic processor with two successive 32-bit word read operations from the CRYP_DOUTR register (DOUT[31:0] bitfield), the most significant word (bits [64:33]) first, the least significant word (bits [32:1]) last.

DES/TDES data swapping feature

The cryptographic processor data swapping feature for DES/TDES is summarized in Table 327 and Figure 363 .

Table 327. DES/TDES data swapping example

DATATYPE
in CRYP_CR
Swapping
performed
Data block representation (64-bit)
System memory data (big-endian)
00No swappingBlock[64..1]: 0xABCD7720 6973FE01
Address @, word[63..32]: 0xABCD 7720
Address @+4, word[31..0]: 0x6973 FE01
01Half-word (16-bit)
swapping
Block[64..1]: 0xABCD 7720 6973 FE01
Address @, word[63..32]: 0x7720 ABCD
Address @+4, word[31..0]: 0xFE01 6973
10Byte (8-bit)
swapping
Block[64..1]: 0x AB CD 77 20 69 73 FE 01
Address @, word[63..32]: 0x2077 CDAB
Address @+4, word[31..0]: 0x01FE 7369
11Bit swapping in
32-bit word
Block[64..33]: 0xABCD7720
1010 1011 1100 1101 0111 0111 0010 0000
Block[32..1]: 0x6973FE01
0110 1001 0111 0011 1111 1110 0000 0001
Address @, word[63..32]: 0x04EEB3D5
0000 0100 1110 1110 1011 0011 1101 0101
Address @+4, word[31..0]: 0x807FCE96
1000 0000 0111 1111 1100 1110 1001 0110

Figure 363. 64-bit block construction according to the data type (IN FIFO)

Figure 363: 64-bit block construction according to the data type (IN FIFO). The diagram shows four cases for DATATYPE[1:0]: 00 (no swapping), 01 (16-bit (half-word) swapping), 10 (8-bit (byte) swapping), and 11 (bit swapping). Each case shows the mapping of input/output data bits (Dx) to system memory data (Mx) in a 64-bit block. The order of write to CRYP_DINR / read from CRYP_DOUTR is indicated by circled numbers 1 and 2. A legend defines Dx as input/output data bit 'x' and the double-headed arrow as Data swap.

DATATYPE[1:0] = 00: no swapping

Word1 (D63..D32) and Word0 (D31..D0) are written directly to memory blocks M64..M33 and M32..M1 respectively.

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

Word1 (D63..D32) is split into two 16-bit half-words (D63..D48 and D47..D32) which are swapped and written to memory blocks M48..M33 and M64..M49. Word0 (D31..D0) is similarly split and swapped into M16..M1 and M32..M17.

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

Word1 (D63..D32) is split into eight 8-bit bytes (D63..D56, D55..D48, D47..D40, D39..D32) which are swapped and written to memory blocks M40..M33, M48..M41, M56..M49, M64..M57, M8..M1, M16..M9, M24..M17, and M32..M25. Word0 (D31..D0) is similarly split and swapped into M30..M23, M38..M31, M46..M39, M54..M47, M2..M1, M10..M3, M18..M11, and M26..M19.

DATATYPE[1:0] = 11: bit swapping

Word1 (D63..D32) is split into individual bits (D63, D62, D61, D60, D59, D58, D57, D56, D55, D54, D53, D52, D51, D50, D49, D48, D47, D46, D45, D44, D43, D42, D41, D40, D39, D38, D37, D36, D35, D34, D33, D32) which are swapped and written to memory blocks M33, M34, M35, M36, M37, M38, M39, M40, M41, M42, M43, M44, M45, M46, M47, M48, M49, M50, M51, M52, M53, M54, M55, M56, M57, M58, M59, M60, M61, M62, M63, M64, M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14, M15, M16, M17, M18, M19, M20, M21, M22, M23, M24, M25, M26, M27, M28, M29, M30, M31, M32. Word0 (D31..D0) is similarly split and swapped into M30, M31, M32, M33, M34, M35, M36, M37, M38, M39, M40, M41, M42, M43, M44, M45, M46, M47, M48, M49, M50, M51, M52, M53, M54, M55, M56, M57, M58, M59, M60, M61, M62, M63, M64.

Legend: Dx input/output data bit 'x'
↔ Data swap
①..④ Order of write to CRYP_DINR / read from CRYP_DOUTR

MSV43720V2

Figure 363: 64-bit block construction according to the data type (IN FIFO). The diagram shows four cases for DATATYPE[1:0]: 00 (no swapping), 01 (16-bit (half-word) swapping), 10 (8-bit (byte) swapping), and 11 (bit swapping). Each case shows the mapping of input/output data bits (Dx) to system memory data (Mx) in a 64-bit block. The order of write to CRYP_DINR / read from CRYP_DOUTR is indicated by circled numbers 1 and 2. A legend defines Dx as input/output data bit 'x' and the double-headed arrow as Data swap.

AES data input and output

A 128-bit data block is entered into the cryptographic processor with four successive 32-bit word writes into the CRYP_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 cryptographic processor with four successive 32-bit word reads from the CRYP_DOUTR register (bitfield DOUT[31:0]), the most significant word (bits [127:96]) first, the least significant word (bits [31:0]) last.

AES data swapping feature

The cryptographic processor data swapping feature for AES is summarized in Table 328 and Figure 364 .

Note: Data swapping does not apply to GCM and CCM final phases. Data can be inserted normally by the application.

Table 328. AES data swapping example

DATATYPE in CRYP_CRSwapping performedFirst half data block (64-bit)
System memory data (big-endian)
00No swappingBlock[63..0]: 0x4E6F7720 69732074
Address @, word[63..32]: 0x4E6F7720
Address @+4, word[31..0]: 0x69732074
01Half-word (16-bit) swappingBlock[63..0]: 0x4E6F 7720 6973 2074
Address @, word[63..32]: 0x7720 4E6F
Address @+4, word[31..0]: 0x2074 6973

Table 328. AES data swapping example (continued)

DATATYPE
in CRYP_CR
Swapping
performed
First half data block (64-bit)
System memory data (big-endian)
10Byte (8-bit)
swapping
Block[63..0]: 0x4E 6F 77 20 69 73 20 74
Address @, word[63..32]: 0x2077 6F4E
Address @+4, word[31..0]: 0x7420 7369
11Bit swappingBlock[63..32]: 0x4E6F7720
0100 1110 0110 1111 0111 0111 0010 0000
Block[31..0]: 0x69732074
0110 1001 0111 0011 0010 0000 0111 0100
Address @, word[63..32]: 0x04EE F672
0000 0100 1110 1110 1111 0110 0111 0010
Address @+4, word[31..0]: 0x2E04 CE96
0010 1110 0000 0100 1100 1110 1001 0110

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

Diagram showing 128-bit block construction for DATATYPE[1:0] = 00 (no swapping). It displays four words (Word 0 to Word 3) and their corresponding bit sequences (D0 to D127) with no bit-level swapping. Arrows 1-4 indicate the order of write/read operations. Diagram showing 128-bit block construction for DATATYPE[1:0] = 01 (16-bit half-word swapping). It shows Word 0 and Word 1 with their 16-bit half-words swapped. Arrows 1-4 indicate the order of write/read operations. Diagram showing 128-bit block construction for DATATYPE[1:0] = 10 (8-bit byte swapping). It shows Word 0 and Word 1 with their 8-bit bytes swapped. Arrows 1-4 indicate the order of write/read operations. Diagram showing 128-bit block construction for DATATYPE[1:0] = 11 (bit swapping). It shows Word 0 and Word 1 with individual bits swapped. Arrows 1-4 indicate the order of write/read operations.

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:

MSv43721V2

Diagram showing 128-bit block construction for DATATYPE[1:0] = 00 (no swapping). It displays four words (Word 0 to Word 3) and their corresponding bit sequences (D0 to D127) with no bit-level swapping. Arrows 1-4 indicate the order of write/read operations. Diagram showing 128-bit block construction for DATATYPE[1:0] = 01 (16-bit half-word swapping). It shows Word 0 and Word 1 with their 16-bit half-words swapped. Arrows 1-4 indicate the order of write/read operations. Diagram showing 128-bit block construction for DATATYPE[1:0] = 10 (8-bit byte swapping). It shows Word 0 and Word 1 with their 8-bit bytes swapped. Arrows 1-4 indicate the order of write/read operations. Diagram showing 128-bit block construction for DATATYPE[1:0] = 11 (bit swapping). It shows Word 0 and Word 1 with individual bits swapped. Arrows 1-4 indicate the order of write/read operations.

40.4.17 CRYP key registers

The CRYP_Kx registers are write-only registers used to store the encryption or decryption keys. They are organized as four 64-bit registers, as shown in Table 329 and Table 330 .

Note: In memory and in CRYP key registers, AES and DES/TDES keys are stored in big-endian format, with most significant byte on the lowest address.

Table 329. Key endianness in CRYP_KxR/LR registers (AES 128/192/256-bit keys)

K0LR[31:0]K0RR[31:0]K1LR[31:0]K1RR[31:0]K2LR[31:0]K2RR[31:0]K3LR[31:0]K3RR[31:0]
----k[127:96]k[95:64]k[63:32]k[31:0]
K0LR[31:0]K0RR[31:0]K1LR[31:0]K1RR[31:0]K2LR[31:0]K2RR[31:0]K3LR[31:0]K3RR[31:0]
--k[191:160]k[159:128]k[127:96]k[95:64]k[63:32]k[31:0]
Table 329. Key endianness in CRYP_KxR/LR registers (AES 128/192/256-bit keys) (continued)
K0LR[31:0]K0RR[31:0]K1LR[31:0]K1RR[31:0]K2LR[31:0]K2RR[31:0]K3LR[31:0]K3RR[31:0]
k[255:224]k[223:192]k[191:160]k[159:128]k[127:96]k[95:64]k[63:32]k[31:0]
Table 330. Key endianness in CRYP_KxR/LR registers (DES K1 and TDES K1/2/3)
K0LR[31:0]K0RR[31:0]K1LR[31:0]K1RR[31:0]K2LR[31:0]K2RR[31:0]K3LR[31:0]K3RR[31:0]
--K1[64:33]K1[32:1]----
--K1[64:33]K1[32:1]K2[64:33]K2[32:1]K3[64:33]K3[32:1]

As shown on Table 330 , when TDES is selected (ALGOMODE[2:0] = 000 or 001) a 3-key vector (K1, K2, and K3) is used. When DES is selected (ALGOMODE[2:0] = 010 or 011) only 1-key vector (K1) is used.

Note: DES/TDES keys include 8-bit parity information that are not used by the cryptographic processor. In other words, bits 8, 16, 24, 32, 40, 48, 56 and 64 of each 64-bit key value Kx[1:64] are not used.

Write operations to the CRYP_Kx(L/R) registers when the BUSY bit is set to 1 in the CRYP_SR register are ignored (which means that the register content is not modified). The application must thus check that the BUSY bit is cleared to 0 before modifying key registers.

Key registers are not affected by the data swapping controlled by DATATYPE value in CRYP_CR register.

Refer to Section 40.7: CRYP registers for a detailed description of CRYP_Kx(L/R) registers.

40.4.18 CRYP initialization vector registers

The CRYP_IVxL/IVxR registers are used to store the initialization vector or the nonce, depending on the chaining mode selected. When used, these registers are updated by the core after each computation round of the TDES or AES core.

They are organized as four 64-bit registers, as shown in Table 331 and Table 332 . In DES/TDES mode only CRYP_IV0x are used.

Note: In memory and in CRYP IV registers, AES and DES/TDES initialization vectors are stored in big-endian format, with most significant byte on the lowest address.

Table 331. Initialization vector endianness in CRYP_IVxR registers (AES)
CRYP_IV0L[31:0]CRYP_IV0R[31:0]CRYP_IV1L[31:0]CRYP_IV1R[31:0]
IV[127:96]IV[95:64]IV[63:32]IV[31:0]
Table 332. Initialization vector endianness in CRYP_IVxR registers (DES/TDES)
CRYP_IV0L[31:0]CRYP_IV0R[31:0]CRYP_IV1L[31:0]CRYP_IV1R[31:0]
IV[64:32]IV[31:0]--

Any write operation to the CRYP_IV0...1(L/R) registers when the BUSY bit is set to 1 in the CRYP_SR register is disregarded (which means that register content not modified). The

software must thus check that the BUSY bit is cleared to 0 in the CRYP_SR register before modifying initialization vectors.

Reading the CRYP_IV0...1(L/R) register returns the latest counter value (useful for managing suspend mode) except for CCM/GCM.

The initialization vector registers are not affected by the data swapping feature controlled by DATATYPE value in CRYP_CR register.

Refer to Section 40.7: CRYP registers for a detailed description of CRYP_IVxL/IVxR registers.

40.4.19 CRYP DMA interface

The cryptographic processor provides an interface to connect to the DMA (Direct Memory Access) controller. The DMA operation is controlled through the CRYP DMA control register (CRYP_DMACR).

Data input using DMA

DMA can be enabled for writing data into the cryptographic peripheral by setting the DIEN bit in the CRYP_DMACR register. When this bit is set, the cryptographic processor initiates a DMA request during the INPUT phase each time it requires a word to be written to the CRYP_DIN register.

Table 333 shows the recommended configuration to transfer data from memory to cryptographic processor through the DMA controller.

Table 333. Cryptographic processor configuration for memory-to-peripheral DMA transfers

DMA channel control register fieldProgramming recommendation
Transfer sizeMessage length, multiple of four 32-bit words. This 128-bit granularity corresponds to two blocks for DES/TDES, one block for AES.
According to the algorithm and the mode selected, special padding/ciphertext stealing might be required. As an example, in case of AES GCM encryption or AES CCM decryption, DMA transfers must not include the last block. Refer to Section 40.4.5: CRYP procedure to perform a cipher operation for details.
Source burst size (memory)CRYP_FIFO_size /2 /transfer_width = 4
Destination burst size (peripheral)CRYP_FIFO_size /2 /transfer_width = 4
(FIFO_size = 8x32-bit, transfer_width = 32-bit)
DMA FIFO sizeCRYP_FIFO_size /2 = 16 bytes
Source transfer width (memory)32-bit words
Destination transfer width (peripheral)32-bit words
Table 333. Cryptographic processor configuration for memory-to-peripheral DMA transfers (continued)
DMA channel control register fieldProgramming recommendation
Source address increment (memory)Yes, after each 32-bit transfer.
Destination address increment (peripheral)Fixed address of CRYP_DIN shall be used (no increment).
Data output using DMA

To enable the DMA for reading data from CRYP processor, set the DOEN bit in the CRYP_DMACR register. When this bit is set, the cryptographic processor initiates a DMA request during the OUTPUT phase each time it requires a word to be read from the CRYP_DOUT register.

Table 334 shows the recommended configuration to transfer data from cryptographic processor to memory through the DMA controller.

Table 334. Cryptographic processor configuration for peripheral-to-memory DMA transfers
DMA channel control register fieldProgramming recommendation
Transfer sizeMessage length, multiple of four 32-bit words. This 128-bit granularity corresponds to two blocks for DES/TDES, one block for AES. Depending on the chaining mode selected, extra bits have to be discarded.
Source burst size (peripheral)When DES is used:
Single transfer (burst size = 1)
When AES is used:
CRYP_FIFO_size /2 /transfer_width = 4
(FIFO_size = 8x32-bit, transfer_width = 32-bit)
Destination burst size (memory)CRYP_FIFO_size /2 /transfer_width = 4
DMA FIFO sizeCRYP_FIFO_size /2 = 16 bytes
Source transfer width (peripheral)32-bit words
memory transfer width (memory)32-bit words
Source address increment (peripheral)Fixed address of CRYP_DOUT shall be used (no increment).
Destination address increment (memory)Yes, after each 32-bit transfer.

DMA mode

When AES is used, the cryptographic processor manages two DMA transfer requests through cryp_in_dma and cryp_out_dma internal input/output signals, which are asserted:

When DES/TDES is used, the cryptographic processor manages two DMA transfer requests through cryp_in_dma and cryp_out_dma internal input/output signals, which are asserted:

for OUT FIFO: every time a word has been written into the FIFO by the cryptographic processor (single transfer). Note that a burst transfer is also triggered when two blocks have been written into the FIFO.

All request signals are deasserted if the cryptographic peripheral is disabled or the DMA enable bit is cleared (DIEN bit for the IN FIFO and DOEN bit for the OUT FIFO in the CRYP_DMACR register).

Caution: It is important that DMA controller empties the cryptographic peripheral output FIFO before filling up the CRYP input FIFO. To achieve it, the DMA controller should be configured so that the transfer from the peripheral to the memory has a higher priority than the transfer from the memory to the peripheral.

For more detailed information on DMA operations, refer to Section 40.4.5: CRYP procedure to perform a cipher operation .

40.4.20 CRYP error management

No error flags are generated by the cryptographic processor.

40.5 CRYP interrupts

Overview

There are two individual maskable interrupt sources generated by the cryptographic processor to signal the following events:

These two sources are combined into a single interrupt signal which is the only interrupt signal from the CRYP processor that drives the Cortex® CPU interrupt controller. You can enable or disable CRYP interrupt sources individually by changing the mask bits in the CRYP_IMSCR register. Setting the appropriate mask bit to 1 enables the interrupt.

The status of the individual maskable interrupt sources can be read either from the CRYP_RISR register, for raw interrupt status, or from the CRYP_MISR register for masked

interrupt status. The status of the individual source of event flags can be read from the CRYP_SR register.

Table 335 gives a summary of the available features.

Table 335. CRYP interrupt requests

Interrupt acronymInterrupt eventEvent flagEnable bitInterrupt clear method
in CRYP_xISR (1)in CRYP_SR
CRYPOutput FIFO fullOUTRIS (not masked)
OUTMIS (masked)
OFFUOUTIM (2) and
CRYPEN
Read one data from output FIFO
Output FIFO not emptyOFNERead all data from output FIFO
Input FIFO not fullINRIS (not masked)
INMIS (masked)
IFNFINIM (2) and
CRYPEN
Write data until input FIFO is full
Input FIFO emptyIFEMWrite at least one word in input FIFO

1. The flags belong to CRYP_RISR registers (unmasked or raw) or CRYP_MISR registers (masked).

2. The flags belong to CRYP_IMSCR register.

Output FIFO service interrupt - OUTMIS

The output FIFO service interrupt is asserted when there is one or more (32-bit word) data items in the output FIFO. This interrupt is cleared by reading data from the output FIFO until there is no valid (32-bit) word left (that is when the interrupt follows the state of the output FIFO not empty flag OFNE).

The output FIFO service interrupt OUTMIS is NOT enabled with the CRYP processor enable bit. Consequently, disabling the CRYP processor does not force the OUTMIS signal low if the output FIFO is not empty.

Input FIFO service interrupt - INMIS

The input FIFO service interrupt is asserted when there are less than four words in the input FIFO. It is cleared by performing write operations to the input FIFO until it holds four or more words.

The input FIFO service interrupt INMIS is enabled with the CRYP enable bit. Consequently, when CRYP is disabled, the INMIS signal is low even if the input FIFO is empty.

40.6 CRYP processing time

The time required to process a block for each mode of operation is summarized below. The block size is 128 bits for AES and 64 bits for DES/TDES.

Table 336. Processing latency for ECB, CBC and CTR

Key sizeOperating modesChaining algorithmClock cycles
64 bitsDES encryption or decryptionECD, CBC16
3x64 bitsTDES encryption or decryption48
128 bitsAES encryption or decryption (1)ECD, CBC, CTR14
AES key preparation-12
192 bitsAES encryption or decryption (1)ECD, CBC, CTR16
AES key preparation-14
256 bitsAES encryption or decryption (1)ECD, CBC, CTR18
AES key preparation-16

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

Table 337. Processing time (in clock cycle) for GCM and CCM per 128-bit block

Key sizeOperating modesChaining algorithmInitialization phaseHeader phasePayload phaseTag phase
128 bitsAES encryption or decryptionGCM24101414
CCM12142514
192 bitsGCM28101616
CCM14162916
256 bitsGCM32101818
CCM16183318

40.7 CRYP registers

The cryptographic core is associated with several control and status registers, eight key registers and four initialization vectors registers.

40.7.1 CRYP control register (CRYP_CR)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.NPBLB[3:0]ALGOMODE3Res.GCM_CCMPH [1:0]
rwrwrwrwrwrwrw

1514131211109876543210
CRYPENFFLUSHRes.Res.Res.Res.KEYSIZE[1:0]DATATYPE[1:0]ALGOMODE[2:0]ALGODIRRes.Res.
rwrwrwrwrwrwrwrwrwrw

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

Bits 23:20 NPBLB[3:0] : Number of Padding Bytes in Last Block of payload.

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

0000: All bytes are valid (no padding)

0001: Padding for the last LSB byte

...

1111: Padding for the 15 LSB bytes of last block.

Writing NPBLB bits while BUSY = 1 has no effect.

Bit 18 Reserved, must be kept at reset value.

Bits 17:16 GCM_CCMPH[1:0] : GCM or CCM Phase selection

This bitfield has no effect if GCM, GMAC or CCM algorithm is not selected in ALGOMODE field.

00: Initialization phase

01: Header phase

10: Payload phase

11: Final phase

Writing to GCM_CCMPH bits while BUSY = 1 has no effect.

Bit 15 CRYPTEN : CRYP processor Enable

0: Cryptographic processor peripheral is disabled

1: Cryptographic processor peripheral is enabled

This bit is automatically cleared by hardware when the key preparation process ends (ALGOMODE = 0111) or after GCM/GMAC or CCM Initialization phase.

Bit 14 FFLUSH : CRYP FIFO Flush

0: No FIFO flush

1: FIFO flush enabled

When CRYPTEN = 0, writing this bit to 1 flushes the IN and OUT FIFOs (that is read and write pointers of the FIFOs are reset). Writing this bit to 0 has no effect.

When CRYPTEN = 1, writing this bit to 0 or 1 has no effect.

Reading this bit always returns 0.

FFLUSH bit has to be set only when BUSY = 0. If not, the FIFO is flushed, but the block being processed may be pushed into the output FIFO just after the flush operation, resulting in a non-empty FIFO condition.

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

Bits 9:8 KEYSIZE[1:0] : Key size selection (AES mode only)

This bitfield defines the bit-length of the key used for the AES cryptographic core.

This bitfield is 'don't care' in the DES or TDES modes.

00: 128-bit key length

01: 192-bit key length

10: 256-bit key length

11: Reserved, do not use this value

Writing KEYSIZE bits while BUSY = 1 has no effect.

Bits 7:6 DATATYPE[1:0] : Data Type selection

This bitfield defines the format of data written in CRYP_DIN or read from CRYP_DOUT registers. For more details refer to Section 40.4.16: CRYP data registers and data swapping .

00: 32-bit data. No swapping for each word. First word pushed into the IN FIFO (or popped off the OUT FIFO) forms bits 1...32 of the data block, the second word forms bits 33...64 etc.

01: 16-bit data, or half-word. Each word pushed into the IN FIFO (or popped off the OUT FIFO) is considered as 2 half-words, which are swapped with each other.

10: 8-bit data, or bytes. Each word pushed into the IN FIFO (or popped off the OUT FIFO) is considered as 4 bytes, which are swapped with each other.

11: bit data, or bit-string. Each word pushed into the IN FIFO (or popped off the OUT FIFO) is considered as 32 bits (1st bit of the string at position 0), which are swapped with each other.

Writing DATATYPE bits while BUSY = 1 has no effect.

Bits 19, 5:3 ALGOMODE[3:0] : Algorithm mode

Below definition includes the bit 19:

0000: TDES-ECB (triple-DES Electronic Codebook).

0001: TDES-CBC (triple-DES Cipher Block Chaining).

0010: DES-ECB (simple DES Electronic Codebook).

0011: DES-CBC (simple DES Cipher Block Chaining).

0100: AES-ECB (AES Electronic Codebook).

0101: AES-CBC (AES Cipher Block Chaining).

0110: AES-CTR (AES Counter mode).

0111: AES key preparation for ECB or CBC decryption.

1000: AES-GCM (Galois Counter mode) and AES-GMAC (Galois Message Authentication Code mode).

1001: AES-CCM (Counter with CBC-MAC).

Writing ALGOMODE bits while BUSY = 1 has no effect.

Others: Reserved, must no be used

Bit 2 ALGODIR : Algorithm Direction

0: Encrypt

1: Decrypt

Writing ALGODIR bit while BUSY = 1 has no effect.

Bits 1:0 Reserved, must be kept at reset value.

40.7.2 CRYP status register (CRYP_SR)

Address offset: 0x04

Reset value: 0x0000 0003

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

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

Bit 4 BUSY : Busy bit

0: The CRYP core is not processing any data. The reason is:

1: The CRYP core is currently processing a block of data or a key preparation is ongoing (AES ECB or CBC decryption only).

40.7.3 CRYP data input register (CRYP_DIN)

Address offset: 0x08

Reset value: 0x0000 0000

The CRYP_DIN register is the data input register. It is 32-bit wide. It is used to enter into the input FIFO up to four 64-bit blocks (TDES) or two 128-bit blocks (AES) of plaintext (when encrypting) or ciphertext (when decrypting), one 32-bit word at a time.

To fit different data sizes, the data can be swapped after processing by configuring the DATATYPE bits in the CRYP_CR register. Refer to Section 40.4.16: CRYP data registers and data swapping for more details.

When CRYP_DIN register is written to the data are pushed into the input FIFO.

When CRYP_DIN register is read:

Note: After the CRYP_DIN register has been read once or several times, the FIFO must be flushed by setting the FFLUSH bit prior to processing new data.

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

Bits 31:0 DATAIN[31:0] : Data Input

On read FIFO is popped (last written value is returned), and its value is returned if CRYPEN = 0. If CRYPEN = 1 DATAIN register returns an undefined value.

On write current register content is pushed inside the FIFO.

40.7.4 CRYP data output register (CRYP_DOUT)

Address offset: 0x0C

Reset value: 0x0000 0000

The CRYP_DOUT register is the data output register. It is read-only and 32-bit wide. It is used to retrieve from the output FIFO up to four 64-bit blocks (TDES) or two 128-bit blocks (AES) of plaintext (when encrypting) or ciphertext (when decrypting), one 32-bit word at a time.

To fit different data sizes, the data can be swapped after processing by configuring the DATATYPE bits in the CRYP_CR register. Refer to Section 40.4.16: CRYP data registers and data swapping for more details.

When CRYP_DOUT register is read, the last data entered into the output FIFO (pointed to by the read pointer) is returned.

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

Bits 31:0 DATAOUT[31:0] : Data Output

On read returns output FIFO content (pointed to by read pointer), else returns an undefined value.

On write, no effect.

40.7.5 CRYP DMA control register (CRYP_DMACR)

Address offset: 0x10

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DOENDIEN
rwrw

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

Bit 1 DOEN : DMA Output Enable

When this bit is set, DMA requests are automatically generated by the peripheral during the output data phase.

0: DMA for outgoing data transfer is disabled

1: DMA for outgoing data transfer is enabled

Bit 0 DIEN : DMA Input Enable

When this bit is set, DMA requests are automatically generated by the peripheral during the input data phase.

0: DMA for incoming data transfer is disabled

1: DMA for incoming data transfer is enabled

40.7.6 CRYP interrupt mask set/clear register (CRYP_IMSCR)

Address offset: 0x14

Reset value: 0x0000 0000

The CRYP_IMSCR register is the interrupt mask set or clear register. It is a read/write register. When a read operation is performed, this register gives the current value of the mask applied to the relevant interrupt. Writing 1 to the particular bit sets the mask, thus enabling the interrupt to be read. Writing 0 to this bit clears the corresponding mask. All the bits are cleared to 0 when the peripheral is reset.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OUTIMINIM
rwrw

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

Bit 1 OUTIM : Output FIFO service interrupt mask

0: Output FIFO service interrupt is masked

1: Output FIFO service interrupt is not masked

Bit 0 INIM : Input FIFO service interrupt mask

0: Input FIFO service interrupt is masked

1: Input FIFO service interrupt is not masked

40.7.7 CRYP raw interrupt status register (CRYP_RISR)

Address offset: 0x18

Reset value: 0x0000 0001

The CRYP_RISR register is the raw interrupt status register. It is a read-only register. When a read operation is performed, this register gives the current raw status of the corresponding

interrupt, i.e. the interrupt information without taking CRYP_IMSCR mask into account. Write operations have no effect.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OUTRIS
r
INRIS
r

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

Bit 1 OUTRIS : Output FIFO service raw interrupt status

This bit gives the output FIFO interrupt information without taking CRYP_IMSCR corresponding mask into account.

0: Raw interrupt not pending

1: Raw interrupt pending

Bit 0 INRIS : Input FIFO service raw interrupt status

This bit gives the input FIFO interrupt information without taking CRYP_IMSCR corresponding mask into account.

0: Raw interrupt not pending

1: Raw interrupt pending

40.7.8 CRYP masked interrupt status register (CRYP_MISR)

Address offset: 0x1C

Reset value: 0x0000 0000

The CRYP_MISR register is the masked interrupt status register. It is a read-only register. When a read operation is performed, this register gives the current masked status of the corresponding interrupt, i.e. the interrupt information taking CRYP_IMSCR mask into account. Write operations have no effect.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OUTMIS
r
INMIS
r

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

Bit 1 OUTMIS : Output FIFO service masked interrupt status

This bit gives the output FIFO interrupt information without taking into account the corresponding CRYP_IMSCR mask.

0: Interrupt not pending

1: Interrupt pending

Bit 0 INMIS : Input FIFO service masked interrupt status

This bit gives the input FIFO interrupt information without taking into account the corresponding CRYP_IMSCR mask.

0: Interrupt not pending

1: Interrupt pending when CRYPTEN = 1

40.7.9 CRYP key register 0L (CRYP_K0LR)

Address offset: 0x20

Reset value: 0x0000 0000

CRYP key registers contain the cryptographic keys.

For more information refer to Section 40.4.17: CRYP key registers .

Note: Write accesses to these registers are disregarded when the cryptographic processor is busy (bit BUSY = 1 in the CRYP_SR register) .

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

Bits 31:0 K[255:224] : Key bit x (x = 255 to 224)

This write-only bitfield contains the bits [255:224] of the AES encryption or decryption key, depending on the operating mode. This register is not used in DES/TDES mode.

40.7.10 CRYP key register 0R (CRYP_K0RR)

Address offset: 0x24

Reset value: 0x0000 0000

Refer to Section 40.7.9: CRYP key register 0L (CRYP_K0LR) for details.

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

Bits 31:0 K[223:192] : Key bit x (x = 223 to 192)

This write-only bitfield contains the bits [223:192] of the AES encryption or decryption key, depending on the operating mode. This register is not used in DES/TDES mode.

40.7.11 CRYP key register 1L (CRYP_K1LR)

Address offset: 0x28

Reset value: 0x0000 0000

Refer to Section 40.7.9: CRYP key register 0L (CRYP_K0LR) for details.

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

Bits 31:0 K[191:160] : Key bit x (x = 191 to 160)

This write-only bitfield contains the bits [191:160] of the AES encryption or decryption key, depending on the operating mode. In DES/TDES mode this bitfield contains the bits [64:33] of the key K1, with parity bits unused.

40.7.12 CRYP key register 1R (CRYP_K1RR)

Address offset: 0x2C

Reset value: 0x0000 0000

Refer to Section 40.7.9: CRYP key register 0L (CRYP_K0LR) for details.

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

Bits 31:0 K[159:128] : Key bit x (x = 159 to 128)

This write-only bitfield contains the bits [159:128] of the AES encryption or decryption key, depending on the operating mode. In DES/TDES mode this bitfield contains the bits [32:1] of the key K1, with parity bits unused.

40.7.13 CRYP key register 2L (CRYP_K2LR)

Address offset: 0x30

Reset value: 0x0000 0000

Refer to Section 40.7.9: CRYP key register 0L (CRYP_K0LR) for details.

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

Bits 31:0 K[127:96] : Key bit x (x = 127 to 96)

This write-only bitfield contains the bits [127:96] of the AES encryption or decryption key, depending on the operating mode. In DES/TDES mode this bitfield contains the bits [64:33] of the key K2, with parity bits unused.

40.7.14 CRYP key register 2R (CRYP_K2RR)

Address offset: 0x34

Reset value: 0x0000 0000

Refer to Section 40.7.9: CRYP key register 0L (CRYP_K0LR) for details.

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

Bits 31:0 K[95:64] : Key bit x (x = 95 to 64)

This write-only bitfield contains the bits [95:64] of the AES encryption or decryption key, depending on the operating mode. In DES/TDES mode this bitfield contains the bits [32:1] of the key K2, with parity bits unused.

40.7.15 CRYP key register 3L (CRYP_K3LR)

Address offset: 0x38

Reset value: 0x0000 0000

Refer to Section 40.7.9: CRYP key register 0L (CRYP_K0LR) for details.

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

Bits 31:0 K[63:32] : Key bit x (x = 63 to 32)

This write-only bitfield contains the bits [63:32] of the AES encryption or decryption key, depending on the operating mode. In DES/TDES mode this bitfield contains the bits [64:33] of the key K3, with parity bits unused.

40.7.16 CRYP key register 3R (CRYP_K3RR)

Address offset: 0x3C

Reset value: 0x0000 0000

Refer to Section 40.7.9: CRYP key register 0L (CRYP_K0LR) for details.

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

Bits 31:0 K[31:0] : Key bit x (x = 31 to 0)

This write-only bitfield contains the bits [31:0] of the AES encryption or decryption key, depending on the operating mode. In DES/TDES mode this bitfield contains the bits [32:1] of the key K3, with parity bits unused.

40.7.17 CRYP initialization vector register 0L (CRYP_IV0LR)

Address offset: 0x40

Reset value: 0x0000 0000

The CRYP_IV registers store the initialization vector or the nonce, depending on the chaining mode selected. The size of the IV data is 64 bits for DES/TDES and 128 bits for AES. For more information refer to Section 40.4.18: CRYP initialization vector registers .

Note: Write accesses to these registers are disregarded when the cryptographic processor is busy (BUSY = 1 in the CRYP_SR register).

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

Bits 31:0 IV[127:96] : Initialization vector bit x (x = 127 to 96)

This bitfield stores the initialization vector bits [127:96] for AES chaining modes other than ECB. In DES/TDES mode it corresponds to IV bits [63:32].

IV registers are updated by the core after each computation round of the DES/TDES or AES core.

40.7.18 CRYP initialization vector register 0R (CRYP_IV0RR)

Address offset: 0x44

Reset value: 0x0000 0000

Refer to Section 40.7.17: CRYP initialization vector register 0L (CRYP_IV0LR) for details.

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

Bits 31:0 IV[95:64] : Initialization vector bit x (x = 95 to 64)

This bitfield stores the initialization vector bits [95:64] for AES chaining modes other than ECB. In DES/TDES mode it corresponds to IV bits [31:0].

IV registers are updated by the core after each computation round of the DES/TDES or AES core.

40.7.19 CRYP initialization vector register 1L (CRYP_IV1LR)

Address offset: 0x48

Reset value: 0x0000 0000

Refer to Section 40.7.17: CRYP initialization vector register 0L (CRYP_IV0LR) for details.

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

Bits 31:0 IV[63:32] : Initialization vector bit x (x = 63 to 32)

This bitfield stores the initialization vector bits [63:32] for AES chaining modes other than ECB. This register is not used in DES mode.

IV registers are updated by the core after each computation round of the AES core.

40.7.20 CRYP initialization vector register 1R (CRYP_IV1RR)

Address offset: 0x4C

Reset value: 0x0000 0000

Refer to Section 40.7.17: CRYP initialization vector register 0L (CRYP_IV0LR) for details.

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

Bits 31:0 IV[31:16] : Initialization vector bit x (x = 31 to 16)

This bitfield stores the initialization vector bits [31:0] for AES chaining modes other than ECB. This register is not used in DES mode.

IV registers are updated by the core after each computation round of the AES core.

40.7.21 CRYP context swap GCM-CCM registers (CRYP_CSGCMCCMxR)

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

Reset value: 0x0000 0000

These registers contain the complete internal register states of the CRYP processor when the GCM/GMAC or CCM algorithm is selected. They are useful when a context swap has to be performed because a high-priority task needs the cryptographic processor while it is already in use by another task.

When such an event occurs, the CRYP_CSGCMCCM0..7R and CRYP_CSGCM0..7R (in GCM/GMAC mode) or CRYP_CSGCMCCM0..7R (in CCM mode) registers have to be read and the values retrieved have to be saved in the system memory space. The cryptographic processor can then be used by the preemptive task. Then when the cryptographic computation is complete, the saved context can be read from memory and written back into the corresponding context swap registers.

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

Bits 31:0 CSGCMCCMx[31:0] : CRYP processor internal register states for GCM, GMAC and CCM modes.

Note: This register is not used in DES/TDES or other AES modes than the ones indicated

40.7.22 CRYP context swap GCM registers (CRYP_CSGCMxR)

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

Reset value: 0x0000 0000

Refer to Section 40.7.21: CRYP context swap GCM-CCM registers (CRYP_CSGCMCCMxR) for details.

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

Bits 31:0 CSGCMx[31:0] : CRYP processor internal register states for GCM and GMAC modes.

Note: This register is not used in DES/TDES or other AES modes than the ones indicated

40.7.23 CRYP register map

Table 338. CRYP register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00CRYP_CRRes.Res.Res.Res.Res.Res.Res.Res.Res.NPBLBRes.Res.ALGOMODE[3]Res.GCM_CCMPHRes.CRYPENFFLUSHRes.Res.Res.Res.KEYSIZEDATATYPEALGOMODE[2:0]Res.ALGODIRRes.Res.
Reset value00000000000000000
0x04CRYP_SRRes.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.BUSYOFFUOFNEIFNFIFEM
Reset value00011
0x08CRYP_DINDATAIN
Reset value00000000000000000000000000000000
0x0CCRYP_DOUTDATAOUT
Reset value00000000000000000000000000000000
0x10CRYP_DMACRRes.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.DOENDIEN
Reset value00
0x14CRYP_IMSCRRes.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.OUTIMINIM
Reset value00
0x18CRYP_RISRRes.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.OUTRISINRIS
Reset value01
0x1CCRYP_MISRRes.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.OUTMISINMIS
Reset value00
0x20CRYP_K0LRK[255:224]
Reset value00000000000000000000000000000000
0x24CRYP_K0RRK[223:192]
Reset value00000000000000000000000000000000
...
0x38CRYP_K3LRK[63:32]
Reset value00000000000000000000000000000000
0x3CCRYP_K3RRK[31:0]
Reset value00000000000000000000000000000000
0x40CRYP_IV0LRIV0IV1IV2IV3IV4IV5IV6IV7IV8IV9IV10IV11IV12IV13IV14IV15IV16IV17IV18IV19IV20IV21IV22IV23IV24IV25IV26IV27IV28IV29IV30IV31
Reset value00000000000000000000000000000000

Table 338. CRYP register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x44CRYP_IV0RRIV32IV33IV34IV35IV36IV37IV38IV39IV40IV41IV42IV43IV44IV45IV46IV47IV48IV49IV50IV51IV52IV53IV54IV55IV56IV57IV58IV59IV60IV61IV62IV63
Reset value00000000000000000000000000000000
0x48CRYP_IV1LRIV62IV63IV64IV65IV66IV67IV68IV69IV70IV71IV72IV73IV74IV75IV76IV77IV78IV79IV80IV81IV82IV83IV84IV85IV86IV87IV88IV89IV90IV91IV92IV93
Reset value00000000000000000000000000000000
0x4CCRYP_IV1RRIV96IV97IV98IV99IV100IV101IV102IV103IV104IV105IV106IV107IV108IV109IV110IV111IV112IV113IV114IV115IV116IV117IV118IV119IV120IV121IV122IV123IV124IV125IV126IV127
Reset value00000000000000000000000000000000
0x50CRYP_CSGCMCCM0RCSGCMCCM0
Reset value00000000000000000000000000000000
0x54CRYP_CSGCMCCM1RCSGCMCCM1
Reset value00000000000000000000000000000000
0x58CRYP_CSGCMCCM2RCSGCMCCM2
Reset value00000000000000000000000000000000
0x5CCRYP_CSGCMCCM3RCSGCMCCM3
Reset value00000000000000000000000000000000
0x60CRYP_CSGCMCCM4RCSGCMCCM4
Reset value00000000000000000000000000000000
0x64CRYP_CSGCMCCM5RCSGCMCCM5
Reset value00000000000000000000000000000000
0x68CRYP_CSGCMCCM6RCSGCMCCM6
Reset value00000000000000000000000000000000
0x6CCRYP_CSGCMCCM7RCSGCMCCM7
Reset value00000000000000000000000000000000
0x70CRYP_CSGCM0RCSGCM0
Reset value00000000000000000000000000000000
0x74CRYP_CSGCM1RCSGCM1
Reset value00000000000000000000000000000000
0x78CRYP_CSGCM2RCSGCM2
Reset value00000000000000000000000000000000
0x7CCRYP_CSGCM3RCSGCM3
Reset value00000000000000000000000000000000
0x80CRYP_CSGCM4RCSGCM4
Reset value00000000000000000000000000000000

Table 338. CRYP register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x84CRYP_CSGCM5RCSGCM5
Reset value000000000000000000000000000000000
0x88CRYP_CSGCM6RCSGCM6
Reset value000000000000000000000000000000000
0x8CCRYP_CSGCM7RCSGCM7
Reset value000000000000000000000000000000000

Refer to Section 2.3 on page 131 for the register boundary addresses.