Other Parts Discussed in Thread: CC2640, CC2650
Tool/software: TI-RTOS
If searched the forum for hints, but I didn't get any helpful tips.
I'm using the CC2650STK - Sensortag.
What I try to accomplish is, that the sensor values (humidity and IR- temp) are encrypted via AES-CCM. Later a RaspberryPi 3 connects to it and collects the data and then decrypts it.
If read the Developers Guide (CC2640 and CC2650 SimpleLink™ Bluetooth® low energy Software Stack 2.2.1) it states that there is a crypto driver. Which releates to: C:\TI\tirtos_cc13xx_cc26xx_2_20_01_08\products\tidrivers_cc13xx_cc26xx_2_20_01_10\docs\doxygen\html\index.html. This leads me to the CryptoCC26XX.h File Reference - Part.
I'v used the sample code (inside the sensortag_hum.c - file starting at line 328 --> right after the SensorHdc1000_read(&data.v.rawTemp, &data.v.rawHum)-function):
#define macLength (4)
#define clearTextLength (16)
#define cipherTextLength (macLength + clearTextLength)
#define nonceLength (12)
#define aadLength (14)
// Holds the AES-CCM setup for this example
typedef struct
{
uint8_t key[16]; // A 128 Bit AES key
CryptoCC26XX_KeyLocation keyLocation; // One of 8 key locations in the hardware
uint8_t clearAndCipherText[cipherTextLength]; // Holds the cleartext before, and the ciphertext
// after the encryption operation.
// Ciphertext = encrypted text + message authentication code (MAC).
uint8_t nonce[nonceLength]; // A value that is used only once (cryptographic term 'nonce')
uint8_t header[aadLength]; // A header that is not encrypted but is authenticated in the operation (AAD).
} AesCcmExample;
AesCcmExample ccmSetup =
{
.key = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C },
.keyLocation = CRYPTOCC26XX_KEY_0,
.clearAndCipherText = { 't','h','i','s','i','s','a','p','l','a','i','n','t','e','x','t','0','0','0','0' },
.nonce = { 't','h','i','s','i','s','a','n','o','n','c','e' },
.header = { 't','h','i','s','i','s','a','h','e','a','d','e','r','1' }
};
CryptoCC26XX_Handle handle;
int32_t keyIndex;
CryptoCC26XX_AESCCM_Transaction trans;
int32_t status;
// Initialize Crypto driver structures
CryptoCC26XX_init();
// Open the crypto hardware with non-exclusive access and default parameters.
handle = CryptoCC26XX_open(Board_CRYPTO, false, NULL);
if (handle == NULL) {
//System_abort("CryptoCC26XX did not open");
cryptoOpen = 0;
}else{
cryptoOpen = 1;
}
// Allocate a key storage location in the hardware
keyIndex = CryptoCC26XX_allocateKey(handle, ccmSetup.keyLocation, (const uint32_t *) ccmSetup.key);
if (keyIndex == CRYPTOCC26XX_STATUS_ERROR) {
//System_abort("Key Location was not allocated.");
keyLocation = 0;
} else {
keyLocation = 1;
}
// Encrypt and authenticate the message
CryptoCC26XX_Transac_init((CryptoCC26XX_Transaction *) &trans, CRYPTOCC26XX_OP_AES_CCM);
trans.keyIndex = keyIndex;
trans.authLength = macLength;
trans.nonce = (char *) ccmSetup.nonce;
trans.header = (char *) ccmSetup.header;
trans.fieldLength = 3;
trans.msgInLength = clearTextLength;
trans.headerLength = aadLength;
trans.msgIn = (char *) &(ccmSetup.clearAndCipherText[0]); // Message is encrypted in place
trans.msgOut = (char *) &(ccmSetup.clearAndCipherText[clearTextLength]); // MAC will be written to this position
status = CryptoCC26XX_transact(handle, (CryptoCC26XX_Transaction *) &trans);
if (status != CRYPTOCC26XX_STATUS_SUCCESS) {
//System_abort("Encryption and signing failed.");
encryption_AND_signing = 0;
} else {
encryption_AND_signing = 1;
}
// Decrypt and authenticate message
CryptoCC26XX_Transac_init((CryptoCC26XX_Transaction *) &trans, CRYPTOCC26XX_OP_AES_CCMINV);
trans.keyIndex = keyIndex;
trans.authLength = macLength;
trans.nonce = (char *) ccmSetup.nonce;
trans.header = (char *) ccmSetup.header;
trans.fieldLength = 3;
trans.msgInLength = cipherTextLength;
trans.headerLength = aadLength;
trans.msgIn = (char *) &(ccmSetup.clearAndCipherText[0]); // Message is decrypted in place
trans.msgOut = (char *) &(ccmSetup.clearAndCipherText[clearTextLength]); // Points to the MAC, is used as input here
// Do AES-CCM decryption and authentication
status = CryptoCC26XX_transact(handle, (CryptoCC26XX_Transaction *) &trans);
if(status != CRYPTOCC26XX_STATUS_SUCCESS){
//System_abort("Decryption and authentication failed.");
decrytion_AND_ath = 0;
}
else {
decrytion_AND_ath = 1;
}
// Release the key location
status = CryptoCC26XX_releaseKey(handle, &keyIndex);
if (status != CRYPTOCC26XX_STATUS_SUCCESS) {
//System_abort("Key release was not successful.");
keyRealease = 0;
} else {
keyRealease = 1;
}
While I debugged it, my dummy variables ( cryptoOpen, keyLocation, encryption_AND_signing, decrytion_AND_ath, keyRelease) always got the value 1, which means everything should have worked.. unfortunately I can't access the trans variable (more precise the trans.msgOut, which should be the cipher + the MAC).
I'v also tried the crypto.c/crypto.h (first seen in this thread: e2e.ti.com/.../2298769 ):
uint32_t Plaintext[16] = { 't','h','i','s','i','s','a','p','l','a','i','n','t','e','x','t'};
uint32_t Ciphertext[16]= 0;
uint32_t MsgLength = 16;
uint32_t Nonce[16] = {'t','h','i','s','i','s','a','n','o','n','c','e','1','2','3','4'};
uint32_t status;
CRYPTOAesCbc(Plaintext, Ciphertext, MsgLength, Nonce, CRYPTO_KEY_AREA_0, true, false);
status = CRYPTOAesCbcStatus();
if(status != AES_SUCCESS)
{
//Error
encryption_AND_signing = 0;
}else {
//Success
encryption_AND_signing = 1;
}
Which leads to a stop of the application (it seems it gets stuck at the CRYPTOAesCbc()-function <-- I'v tried this time another mode (CBC)).
Is there a way to encrypt (using AES-CCM) a value, for example the uint16_t rawTemp, rawHum of the huminidity typdef union and then sending it like as the normal value? - As far as I know the:
uint8* const pValue;
can get up to 512 octets, which should be enough for a encryption-length of (2*16bit = 4 byte + 16byte authentication length).
I appreciate any help and thank you in advance.


