CTR-mode encryption of N blocks of plaintext into N blocks of ciphertext is achieved by following the steps below:
- Configure the AESACTL0 register for single block encryption mode:
- Clear CMEN to disable block cipher mode (if previously enabled)
- Set OPx to encryption mode (0x0)
- Load key as described in Section 23.2.2
- Load first (nonce || counter) value into AESADIN as described in Section 23.2.3
- Wait for the encryption process to complete (wait for the BUSY flag to clear)
- The encrypted (nonce || counter) value is now in the STATE. The first ciphertext block can be obtained by XORing the first plaintext block with the keystream in the STATE.
- Load the first plaintext block into AESAXIN (XORing the plaintext with the keystream, but not starting any encryption operation)
- Read the first block of ciphertext from AESADOUT as described in Section 23.2.4
- Repeat steps 3-6 for additional data blocks, incrementing the counter value each time.