CBC-mode decryption of N blocks of ciphertext into N blocks of plaintext without CPU interaction is achieved through the use of 3 DMA channels (referred to as DMA_A, DMA_B, and DMA_C). To implement CBC decryption follow these steps:
- Configure the AESACTL0 register to pre-generate the decryption key (last round key):
- Clear CMEN to disable block cipher mode
- Set OPx to 0x2 (decryption key generation)
- Write key into AESAKEY register as described in Section 23.2.2
- Wait for the BUSY status in the AESSTAT register to clear, indicating key generation has completed
- Configure the AESACTL0 register for block cipher decryption mode using CBC:
- Set CMEN to enable block cipher mode (0x1)
- Set CMx to 0x1 (CBC mode)
- Set OPx to 0x3 (decryption mode)
- Set the AESKEYWR bit in AESSTAT (to use pre-generate key from step 1)
- Configure DMA_A channel for loading the
initialization vector and ciphertext:
- Set up the ciphertext buffer in memory and pre-pend
the initialization vector (IV) to the ciphertext
- Set DMA channel trigger
selection to AES0 trigger
- Set DMA channel source
address to location where initialization vector is stored in front of
the following ciphertext (for example, SRAM)
- Set DMA channel
destination address to AESAXIN
- Set DMA channel transfer
size to N∗4 words
- Set DMA channel mode to
single transfer mode
- In the AES event
registers, unmask DMA0 in the IMASK register of DMA_TRIG
- Configure DMA_B channel for saving plaintext:
- Set DMA channel trigger selection to AES1 trigger
- Set DMA channel source address to AESADOUT
- Set DMA channel destination address to location where plaintext is to be stored (for example, SRAM)
- Set DMA channel transfer size to N∗4 words
- Set DMA channel mode to single transfer mode
- In the AES event registers, unmask DMA1 in the
IMASK register of DMA_TRIG
- Configure DMA_C channel for loading ciphertext:
- Set DMA channel trigger selection to AES2 trigger
- Set DMA channel source address to location where
ciphertext is stored after the IV (for example, SRAM)
- Set DMA channel destination address to AESADIN
- Set DMA channel transfer size to N∗4 words
- Set DMA channel mode to single transfer mode
- In the AES event registers, unmask DMA2 in the
IMASK register of DMA_TRIG
- Configure and enable the DMA interrupt for the DMA_A and DMA_B channels in the DMA controller
- Start decryption by writing the block count N to BLKCNTx in the AESACTL1 register
- Wait for the DMA_B channel interrupt which indicates completion of the operation. The plaintext output will be stored in the location configured in step 5c.