CFB mode encryption of N blocks of plaintext into N blocks of ciphertext without CPU interaction is achieved through the use of 2 DMA channels. To implement CFB encryption follow these steps:
- Configure Output DMA channel for saving ciphertext:
- Set DMA channel trigger selection to AES Trig1
- Set DMA channel source address to DATA_OUT
- Set DMA channel destination address to location where ciphertext is to be stored (for example, SRAM)
- Set DMA channel transfer size to N∗4
- Set DMA channel mode to single transfer mode
- In the AES event registers, unmask Trig1 in the IMASK register of DMA_TRIG_DATAOUT
- Configure Input DMA channel for loading plaintext:
- Set DMA channel trigger selection to AES Trig0
- Set DMA channel source address to location where plaintext is stored (for example, SRAM)
- Set DMA channel destination address to DATA_IN
- Set DMA channel transfer size to N∗4
- Set DMA channel mode to single transfer mode
- In the AES event registers, unmask Trig0 in the IMASK register of DMA_TRIG0
- Configure and enable the DMA interrupt for the Output DMA channel in the DMA controller
- Configure DMA_HS for DMA based handshake: set DMA_HS[DMA_DATA_ACK] = 1
- Load key as described in Section 11.2.1
- Load Initialization vector (IV) by writing to IV0, IV1, IV2 and IV3 registers
- Configure the CTRL register for block cipher encryption mode for CFB
- Select key size via CTRL[KEY_SIZ]
- Select Direction for Encryption by CTRL[DIR] = 1
- Select CFB mode by setting CTRL[CFB]=1
- Select feedback width by setting CTRL[CTR_WIDTH]
- 00b - CFB-128
- 01b - CFB-1
- 10b - CFB-8
- Start encryption by writing number of bytes N×4 to AES C_LENGTH_0 and C_LENGTH_1 registers
- Wait for the DMA channel interrupt that indicates completion of the entire operation. The ciphertext output is stored in the location configured in step 1c.