I'm having some difficulties implementing the AES encryption primitives for an msp430fr5969 micro controller following the indications described here:
www.ti.com.cn/.../slau367f.pdf
more particularly the AES CBC cipher mode:
www.ti.com.cn/.../slau367f.pdf
My current implementation looks like:
int i = 8, j = 0; uint16_t *tmp; // key is given in 16-bit words uint16_t key[] = { 0x1234, 0x5678, 0x9ABC, 0xDEF0, 0xDEF1, 0xDEF2, 0xDEF3, 0xDEF4}; uint16_t iv[] = { 0x7545, 0xA546, 0x5461, 0x7526, 0xDCD1, 0x21A2, 0xD453, 0x216F}; // AESOPx prepares the accelerator for encryption // Reset AES controller state o 0x0. AESACTL0 is // the control register AESACTL0 |= AESSWRST; // Prepare for encryption AESACTL0 |= AESCMEN; AESACTL0 &= ~AESOP0; AESACTL0 &= ~AESOP1; // Load the key while(i--) AESAKEY = (uint16_t)key[j++]; // Wait for the AES accelerator to finish while(AESASTAT & AESBUSY); // Load initialization vector(needed for CBC) i = 8; j = 0; while(i--) AESAXIN = (uint16_t)iv[j++]; // Wait for the AES accelerator to finish while(AESASTAT & AESBUSY); // Setup DMA as described in the manual // Channel selection. AES trigger 0 on channel 0 ------------------ DMACTL0 = DMA0TSEL_11; // The AES accelerator makes use of level sensitive triggers DMA0CTL |= DMALEVEL; // Set transfer mode. For the AES accelerator it is always single transfer mode (DMADTx = 000) DMA0CTL |= DMADT_0; // Enable DMA //DMA0CTL |= DMAEN; // Source address DMA0SAL = (uint16_t)&AESADOUT; // Destination address. The cipher text is a byte array(char*) tmp = (uint16_t*)cipher_text; DMA0DAL = (uint16_t)tmp; // Size in words DMA0SZ = (uint16_t)number_of_blocks * 8; // Set increment value(2 bytes/ 1 word) // Increment source address DMA0CTL |= DMASRCINCR_3; // Increment destination address DMA0CTL |= DMADSTINCR_3; // Channel selection. AES trigger 1 on channel 1 ------------------ DMACTL0 = DMA1TSEL_12; // The AES accelerator makes use of level sensitive triggers DMA1CTL |= DMALEVEL; // Set transfer mode. For the AES accelerator it is always single transfer mode (DMADTx = 000) DMA1CTL |= DMADT_0; // Enable DMA DMA1CTL |= DMAEN; // Source address // Destination address. The plain text is a byte array(char*) tmp = (uint16_t*)plain_text; DMA1DAL = (uint16_t)tmp; // Destination address DMA1DAL = (uint16_t)&AESAXDIN; // Size in words DMA1SZ = (uint16_t)n_blocks * 8; // Set increment value(2 bytes/ 1 word) // Increment source address DMA1CTL |= DMASRCINCR_3; // Increment destination address DMA1CTL |= DMADSTINCR_3; // According to the manual setting the number of blocks should trigger the // the encryption but it doesn't AESACTL1 &= ~AESBLKCNT0; AESACTL1 |= AESBLKCNT1; // Wait for the AES accelerator to finish while(AESASTAT & AESBUSY); // Wait for dma transfers to finish while (!(DMA0CTL & DMAIFG)); while (!(DMA1CTL & DMAIFG));
Why isn't encryption triggered upon setting the number of blocks?