我正在尝试使用TI提供的加密库来使用cc2650 sensortag上的硬件AES模块。不幸的是,只要AesInit
被执行或我的脚本中有任何其他空白,我的代码就会陷入无限循环。但是,代码编译的信息很好。我怀疑这是由于一些内存或中断问题。我的问题如下:
我的代码如下:
/* 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);
如果我发表评论AesInit
,代码仍会卡在HW_KeyInit
中,依此类推。我真的很感激任何建议,暗示或帮助。