Part Number:CC1310
Tool/software: TI-RTOS
Hey geeks
I'm using AES 128 Encryption api from the Crypto library with CC1310. The type of the encryption is ECB. I'm just sending the strings from the UART and getting output on terminal
In my case encryption and decryption working great infarct I'm getting decrypted string at output but the problem is decryption is limited to 15 bytes only. If the payload size is more than 15 bytes then the encypted bytes is limited to 15 only
Here is my code with TI rtos
/*
* ======== uartecho.c ========
*/
#include <stdint.h>
#include <stddef.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/crypto/CryptoCC26XX.h>
#include <USB.h>
/* Example/Board Header files */
#include "Board.h"
/*
* ======== mainThread ========
*/
/*
*
* AES 128 CBC encryption test
*/
#define PAYLOAD_LEN 100
typedef struct
{
uint8_t key[16]; // Stores the Aes Key
CryptoCC26XX_KeyLocation keyLocation; // Location in Key RAM
uint8_t clearText[PAYLOAD_LEN]; // Input message - cleartext
uint8_t msgOut[PAYLOAD_LEN]; // Output message
} AESECBExample;
// AES ECB example data
AESECBExample ecbExample =
{
{ 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }, //Key 128 bit
CRYPTOCC26XX_KEY_0, //Location
{'t','h','i','s','i','s','a','p','l','a','i','n','t','e','x','t'}, //text message
{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } //Output message
};
// Declaration (typically done in a task)
CryptoCC26XX_Handle handle;
int32_t keyIndex;
int32_t status;
CryptoCC26XX_AESECB_Transaction trans;
void *mainThread(void *arg0)
{
char input;
const char echoPrompt[] = "AES128 Encryption Example";
const char Prompt[]= "Enterd data";
const char EncData[]= "Encrypted data";
const char Enter[]="\r\n";
char RxBuff[50];
uint8_t count=0;
/* Call driver init functions */
GPIO_init();
USB_ON();
/* Configure the LED pin */
GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
/* Turn on user LED */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
USB_println(echoPrompt);
/* Loop forever echoing */
while (1) {
input=USB_read();
if(input!=NULL){
RxBuff[count]=input;
if(RxBuff[count]=='\r'){
RxBuff[count]=NULL;
count=0;
USB_printString("Enter Data: "); USB_println(RxBuff);
//--------------------------------Encryption-----------------------------------
CryptoCC26XX_init();
// Attempt to open CryptoCC26XX.
handle = CryptoCC26XX_open(Board_CRYPTO0, false, NULL);
if (!handle) {
USB_printString("Crypto module could not be opened.");
}
keyIndex = CryptoCC26XX_allocateKey(handle, ecbExample.keyLocation,
(const uint32_t *) ecbExample.key);
if (keyIndex == CRYPTOCC26XX_STATUS_ERROR) {
USB_printString("Key Location was not allocated.");
}
// Initialize transaction
CryptoCC26XX_Transac_init((CryptoCC26XX_Transaction *) &trans, CRYPTOCC26XX_OP_AES_ECB_ENCRYPT);
// Setup transaction
trans.keyIndex = keyIndex;
trans.msgIn = (uint32_t *) RxBuff;
trans.msgOut = (uint32_t *) ecbExample.msgOut;
// Encrypt the plaintext with AES ECB
status = CryptoCC26XX_transact(handle, (CryptoCC26XX_Transaction *) &trans);
if(status != CRYPTOCC26XX_STATUS_SUCCESS){
USB_printString("Encryption failed.");
}
USB_printString("Encrypted Message: "); USB_println((uint32_t *)trans.msgOut);
// Initialize transaction
CryptoCC26XX_Transac_init((CryptoCC26XX_Transaction *) &trans, CRYPTOCC26XX_OP_AES_ECB_DECRYPT);
// Setup transaction
trans.keyIndex = keyIndex;
trans.msgIn = (uint32_t *) ecbExample.msgOut;
trans.msgOut = (uint32_t *) ecbExample.clearText;
// Zero original clear text before decrypting the cypher text into the ecbExample.clearText array
memset(ecbExample.clearText, 0x0, PAYLOAD_LEN);
// Decrypt the plaintext with AES ECB
status = CryptoCC26XX_transact(handle, (CryptoCC26XX_Transaction *) &trans);
if(status != CRYPTOCC26XX_STATUS_SUCCESS){
USB_printString("Decryption failed.");
}
CryptoCC26XX_releaseKey(handle, &keyIndex);
USB_printString("Decrypted Message: "); USB_println((uint32_t *)ecbExample.clearText);
//----------------------------End encryption----------------------------
}else{
count++;
}
}
}
}
![]()
Here is the screen shot of the terminal tool
is there anything else that I'm missing here ?
Thanks