TI cc26xx aes hardware implementation code keeps getting stuck

3

I am trying to use the crypto lib provided by TI to use the hardware AES module on the cc2650 sensortag. Unfortunately my code keeps getting stuck in endless loops, whenever AesInit is excuted or any of the other voids I have in my script. However the code compiles fine for the info. I suspect that it is due to some memory or interrupts issue. My questions are the following:

  1. Am I missing any header files or dependencies in my file?
  2. Is there any simple aes hardware implementations for cc26xx to follow?
  3. Any idea how to fix my code?

My code is the following:

/* Contiki Headers */
#include "contiki.h"
#include "sys/ctimer.h"
#include "dev/leds.h"
#include "random.h"
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/netstack.h"
#include "clock.h"

/* CC2650 Specific Headers */
#include "lpm.h"
#include "ti-lib.h"
#include "dev/watchdog.h"
#include "lib/cc26xxware/driverlib/gpio.h"
#include "button-sensor.h"
#include "batmon-sensor.h"
#include "board-peripherals.h"

/* Crypto APIs Header */
#include <driverlib/crypto.h>

#define PRINTF(...) printf(__VA_ARGS__)

/* Define functions */
void uint8_print(char *hint,uint8_t *data, int size){
  PRINTF(hint);
  for(uint8_t i = 0; i < size; i++) {
        PRINTF("%02X ", data[i]);
  }
  PRINTF("\r\n");
}

void AesInit( void ) {
  HWREG(CRYPTO_BASE + CRYPTO_O_IRQTYPE) |= 0x00000001;
  HWREG(CRYPTO_BASE + CRYPTO_O_IRQEN) |= 0x00000003;
}

void HW_KeyInit( uint8_t *AesKey ) {
  CRYPTOAesLoadKey( (uint32_t *)AesKey, 0);
}

void AesEncryptHW( uint8_t *AesKey, uint8_t *Cstate ) {
  CRYPTOAesEcb( (uint32_t *)Cstate, (uint32_t *)Cstate, 0, true, false);
  /* wait for completion of the operation */
  do { __asm("nop"); } while(CRYPTOAesEcbStatus());
  CRYPTOAesEcbFinish();
}

void AesDecryptHW( uint8_t *AesKey, uint8_t *Cstate ) {
  CRYPTOAesEcb( (uint32_t *)Cstate, (uint32_t *)Cstate, 0, false, false);
  /* wait for completion of the operation */
  do { __asm("nop"); } while(!(CRYPTOAesEcbStatus()));
  CRYPTOAesEcbFinish();
}

void AesEncryptHW_keylocation(uint8_t *msg_in, uint8_t *msg_out, uint8_t key_location ) {
  CRYPTOAesEcb( (uint32_t *)msg_in, (uint32_t *)msg_out, key_location, true, false);
  /* wait for completion of the operation */
  do { __asm("nop"); } while(!(CRYPTOAesEcbStatus()));
  CRYPTOAesEcbFinish();
}

void AesDecryptHW_keylocation( uint8_t *msg_in, uint8_t *msg_out, uint8_t key_location ){
  CRYPTOAesEcb( (uint32_t *)msg_in, (uint32_t *)msg_out, key_location, false, false);
  /* wait for completion of the operation */
  do { __asm("nop");  } while(CRYPTOAesEcbStatus());
  CRYPTOAesEcbFinish();
}

/*---------------------------------------------------------------------------*/
PROCESS(test_process, "Test process");
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_process, ev, data)
{
    PROCESS_BEGIN();
    printf("\r\nDEBUG: Process started\r\n ");

    uint8_t ui8MsgOut[16];
    uint8_t ui8MsgIn[16]   = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
    uint8_t ciphertext[16] = {0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a};
    uint8_t ui8AesKey[16]  = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};

    AesInit();
    PRINTF("AesInit done\n");
    HW_KeyInit( ui8AesKey );
    PRINTF("HW_KeyInit done\n");

    uint8_print("Start Key:    ",ui8AesKey, 16);
    uint8_print("Start MsgIn:  ",ui8MsgIn, 16);
    uint8_print("Start MsgOut: ",ui8MsgOut, 16);

    AesEncryptHW( ui8AesKey, ui8MsgIn );
    uint8_print("Start Key:    ",ui8AesKey, 16);
    uint8_print("Start MsgIn:  ",ui8MsgIn, 16 );

    AesDecryptHW( ui8AesKey, ui8MsgIn );
    uint8_print("Start Key:    ",ui8AesKey, 16);
    uint8_print("Start MsgOut: ",ui8MsgIn, 16 );

    AesEncryptHW_keylocation(ui8MsgIn, ui8MsgOut, 0 );
    AesDecryptHW_keylocation(ui8MsgIn, ui8MsgOut, 0 );

    uint8_print("Start Key:    ",ui8AesKey, 16);
    uint8_print("Start MsgIn:  ",ui8MsgIn, 16);
    uint8_print("Start MsgOut: ",ui8MsgIn, 16);

    printf("\r\nDEBUG: Process ended\r\n ");
    PROCESS_END();
}
AUTOSTART_PROCESSES(&test_process);

If I comment AesInit the code still gets stuck in HW_KeyInit and so on. I would really appreciate any advice, hint or help.

c
aes
contiki
texas-instruments
asked on Stack Overflow Nov 2, 2017 by SuperKogito

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0