The fastest way to accelerate this
cipher mode is to upload the next plaintext during the current encryption.
An Initialization Vector (IV) is used
to randomize the encryption so that distinct ciphertexts are produced even if the
same plaintext is encrypted multiple times. Assuming initialization from reset state
and denoting plaintext as an array, m[1:x]:
Initialization:
- Write KEY0-KEY3
- AUTOCFG
- AESSRC = TXTXBUF
- TRGAES = RDTXT3 |
WRBUF3S (the first encryption starts by writing BUF3, the successive
ones by reading TXT3)
- Write IV to TXT0-TXT3
Cipher mode with µDMA:
Assumes CHA has written new plaintext
to BUF before reading ciphertext.
- µDMA channel A moves m[1:x] into
BUF when a new encryption starts
- ADRCHA = BUF0
- TRGCHA = AESSTART
- DONEACT =
GATE_TRGAES_ON_CHA_DEL (to avoid spurious last AES operation).In case of
single block encryption, configure DONEACT = GATE_TRGAES_ON_CHA
- µDMA channel B moves
ciphertext[1:x] to memory when AES completes
- ADRCHB = TXT0
- TRGCHB = AESDONE
- START: CPU writes 0x1 to
TRG.DMACHA to start CBC encryption. µDMA moves N x 16B.
- END : CPU waits for µDMA to
signal 'done' and STA.STATE = IDLE, then reads result/TAG/MIC from
TXT0-TXT3.
Cipher mode with CPU:
- Writes m[1] to BUF (triggers
AES)
- for i = 1; i<x, increment i:
- Prepares m[i+1]
- Wait until STA.STATE =
BUSY || use interrupt (This can be skipped since AES is immediately
triggered)
- Writes m[i+1] to BUF
- Waits for STA.STATE =
IDLE || use interrupt
- Reads ciphertext[i] from
TXT
- Last m(x):
- Set AUTOCFG.TRGAES =
DISABLE
- Waits for STA.STATE =
IDLE || use interrupt
- Reads ciphertext[x] from
TXT
Note: The loop can run over i=1:x, but then an additional AES
encryption is triggered on the last read of TXT3. This can be aborted immediately
after completing the x-th iteration of the for-loop.