Tool/software: TI-RTOS
Hi!
I'm using CC2640R2F with simplelink_cc2640r2_sdk_1_50_00_58 in a Bluetooth LE project.
Now I want to use AES-CCM (Counter mode with CBC-MAC).
In the documentation (simplelink_cc2640r2_sdk_1_50_00_58/docs/tidrivers/doxygen/html/_crypto_c_c26_x_x_8h.html) I found this sample code:
AES CCM operation
Perform a crypto and authentication operation with AES-CCM in CRYPTOCC26XX_MODE_BLOCKING.
#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).
uint8_t verificationMAC[macLength]; // Location that the recalculated and encrypted MAC is stored during decryption.
} 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_CRYPTO0, false, NULL);
if (handle == NULL) {
System_abort("CryptoCC26XX did not open");
}
// 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.");
}
// 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.");
}
// 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.verificationMAC;
// Do AES-CCM decryption and authentication
status = CryptoCC26XX_transact(handle, (CryptoCC26XX_Transaction *) &trans);
if(status != CRYPTOCC26XX_STATUS_SUCCESS){
System_abort("Decryption and authentication failed.");
}
// Release the key location
status = CryptoCC26XX_releaseKey(handle, &keyIndex);
if (status != CRYPTOCC26XX_STATUS_SUCCESS) {
System_abort("Key release was not successful.");
}
Encryption and decryption works fine.
Now, I want to decrypt the cipher text on a different platform, let's say a PC.
Therefore, I tried some AES online tools/calculators but the results don't match.
Can somebody please explain the relations between TI's AES configuration (ccmSetup in crypto.c) and other AES implementations?
I think key, clearAndCipherText and header are straightforward, but what about IV (initialization vector) and nonce?
Looking at the test vectors in RFC3610 (Counter with CBC-MAC) I am also confused by names like CBC IV in, CBC IV out CTR.
BTW, where is the counter defined in TI's AES-CCM implementation?
Can someone please point me to a software tool or online calculator that is compatible to TI's implementation?
Thank you and best regards,
Andreas

