Hi,
I tried many times to make CC1310 AES CCM work by referencing the AES ECB sample in doxygen in SDK, but not work out. Could you provide sample code for CC1310 AES CCM? Thank you very much!
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.
What exact problem do you observe? That it doesn't compile or that the result is wrong? Here is a correct version for CCM:
#include <ti/drivers/crypto/CryptoCC26XX.h> #include <xdc/runtime/System.h> // AES-ECB example struct typedef struct { uint8_t ui8AESKey[16]; // Stores the Aes Key CryptoCC26XX_KeyLocation ui8AESKeyLocation; // Location in Key RAM uint8_t ui8AESClearText[16]; // Input message - clear text uint8_t ui8AESMsgOut[16]; // Output message uint8_t ui8IntEnable; // Set to true/false to enable/ // disable interrupts } tAESECBExample; // AES ECB example data tAESECBExample sAESexample = { { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }, CRYPTOCC26XX_KEY_0, { 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A }, { 0x3A, 0xD7, 0x7B, 0xB4, 0x0D, 0x7A, 0x36, 0x60, 0xA8, 0x9E, 0xCA, 0xF3, 0x24, 0x66, 0xEF, 0x97 }, true, }; // Declaration (typically done in a task) CryptoCC26XX_Handle handle; CryptoCC26XX_Params params; uint8_t keyIndex; CryptoCC26XX_AESECB_Transaction trans; // Initialize Crypto driver CryptoCC26XX_init(); // Configure CryptoCC26XX parameters. CryptoCC26XX_Params_init(¶ms); // Initialize transaction CryptoCC26XX_Transac_init((CryptoCC26XX_Transaction *) &trans, CRYPTOCC26XX_OP_AES_CCM); // Attempt to open CryptoCC26XX. handle = CryptoCC26XX_open(Board_CRYPTO, false, ¶ms); if (!handle) { System_printf("CryptoCC26XX did not open"); } else { keyIndex = CryptoCC26XX_allocateKey(handle, sAESexample.ui8AESKeyLocation, (const uint32_t *) sAESexample.ui8AESKey); if (keyIndex != CRYPTOCC26XX_STATUS_ERROR) { // Setup transaction trans.keyIndex = keyIndex; trans.msgIn = (uint32_t *) sAESexample.ui8AESClearText; trans.msgOut = (uint32_t *) sAESexample.ui8AESMsgOut; // Do AES-ECB operation int res = CryptoCC26XX_transact(handle, (CryptoCC26XX_Transaction *) &trans); CryptoCC26XX_releaseKey(handle, &keyIndex); } else { System_printf("Key Location was not allocated."); } }
Hi Richard,
I, too, had some troubles running the above example. I single-stepped the above instructions and got stuck in the "CryptoCC26XX_transact()" API. I was able to pull in the TI CryptoCC26XX.c source code and found that execution halts in the following code snippet:
/* Pend on blocking mode semaphore and wait for Hwi to finish. */ if (!Semaphore_pend(Semaphore_handle(&(object->waitSem)), object->timeout)) { . .
Any clues or hints would be appreciated.
Thank you!
Sorry guys,
I have lost track of this. Could you solve your problem? I have just posted demo code for the AES hardware module in another thread that does not use the TI-RTOS crypto driver, but only DriverLib.
Hello,
I am having this very same issue when running AES_CCM on CC2640 w/ SDK2.21 - Single stepping through it does show me stuck in the Semaphore_pend like discussed above - Did anyone figure out what was missing ?
Thanks,
Padmaja
Below is my code very similar to what was posted on this thread before.
#include <ti/drivers/crypto/CryptoCC26XX.h>
#include <xdc/runtime/System.h>
#define macLength (4)
#define clearTextLength (16)
#define cipherTextLength (macLength + clearTextLength)
#define nonceLength (12)
#define aadLength (14)
// AES-CCM setup example struct
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).
} tAESCCMExample;
// AES CCM example data
tAESCCMExample sAESexample =
{
.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' }
};
// Declaration (typically done in a task)
CryptoCC26XX_Handle handle;
CryptoCC26XX_Params params;
uint8_t keyIndex;
CryptoCC26XX_AESCCM_Transaction trans;
uint8_t status;
void AES_CCM()
{
// Initialize Crypto driver
CryptoCC26XX_init();
// Configure CryptoCC26XX parameters.
CryptoCC26XX_Params_init(¶ms);
handle = CryptoCC26XX_open(Board_CRYPTO, false, ¶ms);
if (!handle)
{
System_printf("CryptoCC26XX did not open");
}
else
{
keyIndex = CryptoCC26XX_allocateKey(handle, sAESexample.keyLocation,
(const uint32_t *) sAESexample.key);
if (keyIndex != CRYPTOCC26XX_STATUS_ERROR)
{
// Encrypt and sign message
CryptoCC26XX_Transac_init((CryptoCC26XX_Transaction *) &trans, CRYPTOCC26XX_OP_AES_CCM)
trans.keyIndex = keyIndex;
trans.authLength = macLength;
trans.nonce = (char *) sAESexample.nonce;
trans.header = (char *) sAESexample.header;
trans.fieldLength = 3;
trans.msgInLength = clearTextLength;
trans.headerLength = aadLength;
trans.msgIn = (char *) &(sAESexample.clearAndCipherText[0]); // Message is encrypted in place
trans.msgOut = (char *) &(sAESexample.clearAndCipherText[clearTextLength]); // MAC will be written to this position
// Do AES-CCM operation
status = CryptoCC26XX_transact(handle, (CryptoCC26XX_Transaction *) &trans);
if (status != CRYPTOCC26XX_STATUS_SUCCESS)
{
System_printf("Encryption and signing failed.");
while(1);
}
// Decrypt and authenticate message
CryptoCC26XX_Transac_init((CryptoCC26XX_Transaction *) &trans, CRYPTOCC26XX_OP_AES_CCMINV);
trans.keyIndex = keyIndex;
trans.authLength = macLength;
trans.nonce = (char *) sAESexample.nonce;
trans.header = (char *) sAESexample.header;
trans.fieldLength = 3;
trans.msgInLength = clearTextLength;
trans.headerLength = aadLength;
trans.msgIn = (char *) &(sAESexample.clearAndCipherText[0]); // Message is decrypted in place
trans.msgOut = (char *) &(sAESexample.clearAndCipherText[clearTextLength]); // MAC will be written to this position
// Do AES-CCM operation
status = CryptoCC26XX_transact(handle, (CryptoCC26XX_Transaction *) &trans);
if (status != CRYPTOCC26XX_STATUS_SUCCESS)
{
System_printf("Decryption and authentication failed.");
while(1);
}
// Release the key location
status = CryptoCC26XX_releaseKey(handle, &keyIndex);
if (status != CRYPTOCC26XX_STATUS_SUCCESS)
{
System_printf("Key release was not successful.");
while(1);
}
}
else
{
System_printf("Key Location was not allocated.");
}
}
}