This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2538: AES ECB error

Part Number: CC2538


Hi, I am trying to encrypt data using ECB as below

Init:

                                                                            
  /* Enable AES peripheral */                                                   
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_AES);                               
                                                                                
    /* Register interrupt handler */                                            
    IntRegister(INT_AES, AESIntHandler);                                        
                                                                                
    /* Enable global interrupts */                                              
    IntAltMapEnable();                                                          
    IntMasterEnable();                                                          

Doing Encrypt:

  stsLK = AESLoadKey(key, keyloc);
  stsEn = AESECBStart(input, output, keyloc, true, false);
  
  do
  {
    ASM_NOP;
  }while(!(AESECBCheckResult()));
  
  stsGet=AESECBGetResult();

stsGet is returning me 0x03, it means "AES_DMA_BUS_ERROR", can any one tell why its happening

Thank you

  • Hi,
    In the AESECBStart(), you have interrupt disabled. Perhaps that might fix it.
  • Hi FI,
    I enabled Interrupt, but same issue.

    I tried to get result in Interrupt handler as like
    switch (g_ui8CurrentAESOp)
    {
    case AES_ECB:
    uint8 sts=AESECBGetResult();
    HWREG(AES_CTRL_INT_CLR) = 0x00000003;
    break;
    .......................................
  • Hi,

    Please find attached the code files for interrupt and polling method for AES-ECB 128bit encryption. The example  vectors are taken from here 

    The attached code is working on CC2538+smartRF06 board.

    Regards,

    /******************************************************************************
    *  Filename:       aes_example.c
    *  Revised:        $Date: 2013-05-02 14:32:18 +0200 (Thu, 02 May 2013) $
    *  Revision:       $Revision: 9961 $
    *
    *  Description:    AES ECB access example for CC2538 on SmartRF06EB. 
    *                  This example shows how AES ECB should be used. 
    *                  The example also verifies the CCM functionality.
    *
    *  Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
    *
    *
    *  Redistribution and use in source and binary forms, with or without
    *  modification, are permitted provided that the following conditions
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the
    *    documentation and/or other materials provided with the distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    ******************************************************************************/
    
    #include "aes.h"
    #include <string.h>
    #include "sys_ctrl.h"
    #include "hw_memmap.h"
    #include "hw_ioc.h"
    #include "gpio.h"
    #include "ioc.h"
    #include "uart.h"
    #include "uartstdio.h"
    
    
    //*****************************************************************************
    //
    // This function sets up UART0 to be used for a console to display information
    // as the example is running.
    //
    //*****************************************************************************
    #define EXAMPLE_PIN_UART_RXD            GPIO_PIN_0 
    #define EXAMPLE_PIN_UART_TXD            GPIO_PIN_1 
    #define EXAMPLE_GPIO_UART_BASE          GPIO_A_BASE
    
    void
    InitConsole(void)
    {
        //
        // Map UART signals to the correct GPIO pins and configure them as
        // hardware controlled.
        //
        IOCPinConfigPeriphOutput(EXAMPLE_GPIO_UART_BASE, EXAMPLE_PIN_UART_TXD, 
                                 IOC_MUX_OUT_SEL_UART0_TXD);
        GPIOPinTypeUARTOutput(EXAMPLE_GPIO_UART_BASE, EXAMPLE_PIN_UART_TXD);
        
        IOCPinConfigPeriphInput(EXAMPLE_GPIO_UART_BASE, EXAMPLE_PIN_UART_RXD, 
                                IOC_UARTRXD_UART0);
        GPIOPinTypeUARTInput(EXAMPLE_GPIO_UART_BASE, EXAMPLE_PIN_UART_RXD);
         
        //
        // Initialize the UART (UART0) for console I/O.
        //
        UARTStdioInit(0);
    }
    
    //
    // NOTES:
    // This example has been run on a SmartRF06 evaluation board.
    //
    //*****************************************************************************
    //
    //! \addtogroup aes_examples_list
    //! <h1>AES ECB (aes_example)</h1>
    //!
    //! This example shows how to configure the AES ECB with interrupt handler 
    //! and polling.
    //!
    //! This example uses the following peripherals and I/O signals.  You must
    //! review these and change as needed for your own board:
    //! - NONE
    //!
    //! This example uses the following interrupt handlers.  To use this example
    //! in your own application you can add these interrupt handlers to your
    //! vector table.
    //! - AESIntHandler
    //!
    //! \note The example registers the handler in dynamic fashion. This consumes
    //!       RAM space as the vector table is allocated and copied to RAM.
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // Variables to syncronize with interrupt handler
    //
    //*****************************************************************************
    uint8_t ui8AESECBIntHandler = 0;
    
    
    unsigned char ui8AESKey[] = {0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,\
                                  0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c };
    unsigned char ui8AESBufIn[] = {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
    
    unsigned char ui8AESBufOut[]={0};
    
    //*****************************************************************************
    //
    // Interrupt handler for AES
    //
    // param   None
    //
    // return  None
    //
    //*****************************************************************************
    void AESIntHandler(void)
    {
        switch (g_ui8CurrentAESOp)
        {
        case AES_ECB:
            ui8AESECBIntHandler = 1;
            //
            // clear interrupts
            //
            HWREG(AES_CTRL_INT_CLR) = 0x00000003;
            break;
            
        case AES_NONE:
            break;
            
        case AES_CCM:
            break;
            
        case AES_SHA256:
            break;
            
        case AES_KEYL0AD:
            break;
        }
    }
    
    
    
    //*****************************************************************************
    //
    // Main function of example.
    //
    //*****************************************************************************
    void  main(void)
    {
        uint8_t ui8Status;
        
        //
        // Set the clocking to run directly from the external crystal/oscillator.
        // (no ext 32k osc, no internal osc)
        //
        SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);
        
        //
        // Set IO clock to the same as system clock
        //
        SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);
         InitConsole();
         UARTprintf("\nAES-ECB Interrupt Example\n");
        //
        // Enable AES peripheral
        //
        SysCtrlPeripheralReset(SYS_CTRL_PERIPH_AES);
        SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_AES);
        
        //
        // Register interrupt handler
        //
      //  IntRegister(INT_AES, AESIntHandler);
        IntEnable(INT_AES);
        
        //
        // Enable global interrupts
        //
        IntAltMapEnable();
        IntMasterEnable();
        
             //
            // example using polling
            //
            AESLoadKey((uint8_t*)ui8AESKey, 2);
            AESECBStart(ui8AESBufIn, ui8AESBufOut, 2, true, true);
            
            //
            // wait for completion of the operation
            //
            do
            {
                ASM_NOP;
            }while(ui8AESECBIntHandler == 0);
             ui8AESECBIntHandler = 0;
            
            ui8Status = AESECBGetResult();
            
            if(ui8Status == AES_SUCCESS){
              for(int i = 0;i<16;i++){
                UARTprintf("0x%x, ", ui8AESBufOut[i]);
              }
            }
     
        
        // ECB was successful 
        while(1)
        {
        }
    }
    
    
    /******************************************************************************
    *  Filename:       aes_example.c
    *  Revised:        $Date: 2013-05-02 14:32:18 +0200 (Thu, 02 May 2013) $
    *  Revision:       $Revision: 9961 $
    *
    *  Description:    AES ECB access example for CC2538 on SmartRF06EB. 
    *                  This example shows how AES ECB should be used. 
    *                  The example also verifies the CCM functionality.
    *
    *  Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
    *
    *
    *  Redistribution and use in source and binary forms, with or without
    *  modification, are permitted provided that the following conditions
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the
    *    documentation and/or other materials provided with the distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    ******************************************************************************/
    
    #include "aes.h"
    #include <string.h>
    #include "sys_ctrl.h"
    #include "hw_memmap.h"
    #include "hw_ioc.h"
    #include "gpio.h"
    #include "ioc.h"
    #include "uart.h"
    #include "uartstdio.h"
    
    
    //*****************************************************************************
    //
    // This function sets up UART0 to be used for a console to display information
    // as the example is running.
    //
    //*****************************************************************************
    #define EXAMPLE_PIN_UART_RXD            GPIO_PIN_0 
    #define EXAMPLE_PIN_UART_TXD            GPIO_PIN_1 
    #define EXAMPLE_GPIO_UART_BASE          GPIO_A_BASE
    
    void
    InitConsole(void)
    {
        //
        // Map UART signals to the correct GPIO pins and configure them as
        // hardware controlled.
        //
        IOCPinConfigPeriphOutput(EXAMPLE_GPIO_UART_BASE, EXAMPLE_PIN_UART_TXD, 
                                 IOC_MUX_OUT_SEL_UART0_TXD);
        GPIOPinTypeUARTOutput(EXAMPLE_GPIO_UART_BASE, EXAMPLE_PIN_UART_TXD);
        
        IOCPinConfigPeriphInput(EXAMPLE_GPIO_UART_BASE, EXAMPLE_PIN_UART_RXD, 
                                IOC_UARTRXD_UART0);
        GPIOPinTypeUARTInput(EXAMPLE_GPIO_UART_BASE, EXAMPLE_PIN_UART_RXD);
         
        //
        // Initialize the UART (UART0) for console I/O.
        //
        UARTStdioInit(0);
    }
    
    //
    // NOTES:
    // This example has been run on a SmartRF06 evaluation board.
    //
    //*****************************************************************************
    //
    //! \addtogroup aes_examples_list
    //! <h1>AES ECB (aes_example)</h1>
    //!
    //! This example shows how to configure the AES ECB with interrupt handler 
    //! and polling.
    //!
    //! This example uses the following peripherals and I/O signals.  You must
    //! review these and change as needed for your own board:
    //! - NONE
    //!
    //! This example uses the following interrupt handlers.  To use this example
    //! in your own application you can add these interrupt handlers to your
    //! vector table.
    //! - AESIntHandler
    //!
    //! \note The example registers the handler in dynamic fashion. This consumes
    //!       RAM space as the vector table is allocated and copied to RAM.
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // Variables to syncronize with interrupt handler
    //
    //*****************************************************************************
    uint8_t ui8AESECBIntHandler = 0;
    
    
    unsigned char ui8AESKey[] = {0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,\
                                  0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c };
    unsigned char ui8AESBufIn[] = {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
    
    unsigned char ui8AESBufOut[]={0};
    
    
    //*****************************************************************************
    //
    // Main function of example.
    //
    //*****************************************************************************
    void  main(void)
    {
        uint8_t ui8Status;
        
        //
        // Set the clocking to run directly from the external crystal/oscillator.
        // (no ext 32k osc, no internal osc)
        //
        SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);
        
        //
        // Set IO clock to the same as system clock
        //
        SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);
         InitConsole();
         UARTprintf("\nAES ECB Polling Example\n");
        //
        // Enable AES peripheral
        //
        SysCtrlPeripheralReset(SYS_CTRL_PERIPH_AES);
        SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_AES);
        IntMasterEnable();
        
             //
            // example using polling
            //
            AESLoadKey((uint8_t*)ui8AESKey, 4);
            AESECBStart(ui8AESBufIn, ui8AESBufOut, 4, true, false);
            
            //
            // wait for completion of the operation
            //
            do
            {
                ASM_NOP;
            }while(!(AESECBCheckResult()));
            
            ui8Status = AESECBGetResult();
            if(ui8Status == AES_SUCCESS){
              for(int i = 0;i<16;i++){
                UARTprintf("0x%x, ", ui8AESBufOut[i]);
              }
            }
    
        
        // ECB was successful 
        while(1)
        {
        }
    }
    
    

  • Thank you FI, I am also doing the same. Why you are not registering AES_INT in "aes_example_int". So where your interrupt will direct to.
  • Hi,
    In my project i am using IntEnable(INT_AES), for this make sure you have AESIntHandler() registered in the startup.c file.
    You can also use IntRegister(INT_AES, AESIntHandler) instead.