Part Number: CC2651R3
Other Parts Discussed in Thread: CC2651P3
Tool/software:
Dear TI Support Team,
I am working on a project using the CC2651R3 microcontroller and encountering an issue with the AESCCM encryption functionality. Below are the details of my development environment and the problem I am facing:
- Microcontroller: CC2651R3
- SDK Version: simplelink_cc13xx_cc26xx_sdk_7_41_00_17
- Development Environment: Code Composer Studio (CCS) Version 12.7
- Base Code: Project Zero
I am utilizing the AES driver for encryption and decryption. The AES_init() function is successfully executed, but I am unable to get proper encrypted values when using the AESCCM_oneStepEncrypt(handle, &operation); function.
Below is the flow of my encryption code:
static CryptoKey symmetricKey;
void TX_mainTaskFunc(void) {
AESCCM_Handle handle;
AESCCM_Operation operation;
int_fast16_t status;
/* Initialize all the CryptoKeys */
CryptoKeyPlaintext_initBlankKey(&txPublicKey, txPublicKeyMaterial, PUBLIC_KEY_LENGTH);
CryptoKeyPlaintext_initBlankKey(&txPrivateKey, txPrivateKeyMaterial, PRIVATE_KEY_LENGTH);
CryptoKeyPlaintext_initBlankKey(&sharedSecretKey, sharedSecretKeyMaterial, PUBLIC_KEY_LENGTH);
CryptoKeyPlaintext_initBlankKey(&symmetricKey, symmetricKeyMaterial, AES_KEY_LENGTH);
CryptoKeyPlaintext_initKey(&rxPublicKey, rxPublicKeyMaterial, PUBLIC_KEY_LENGTH);
/* Encrypt the phrase 'this is plaintext' and transmit it */
txPacket[PACKET_IDENT_BYTE] = ENCRYPTED_PACKET;
txPacket[PACKET_LENGTH_BYTE] = ENCRYPTED_PACKET_LENGTH;
// Increment a unique nonce each time a message is sent
COM_incrementNonce(nonce, NONCE_LENGTH);
memcpy(&txPacket[HEADER_LENGTH], nonce, NONCE_LENGTH);
/* Debug: Print the nonce */
printf("TX Nonce: ");
for (size_t i = 0; i < NONCE_LENGTH; i++) {
printf("%02X ", nonce[i]);
}
printf("\n");
/* Initialize encryption */
handle = AESCCM_open(CONFIG_AESCCM0, NULL);
printf("AESCCM handle value: %p\n", handle);
if (handle == NULL) {
printf("AESCCM initialization failed\n");
while (1) {}
}
AESCCM_Operation_init(&operation);
operation.key = &symmetricKey;
operation.aad = txPacket;
operation.aadLength = HEADER_LENGTH;
operation.nonce = &txPacket[HEADER_LENGTH];
operation.nonceLength = NONCE_LENGTH;
operation.input = (uint8_t *)msgBuffer;
operation.inputLength = MESSAGE_LENGTH;
operation.output = &txPacket[HEADER_LENGTH + NONCE_LENGTH];
operation.mac = &txPacket[HEADER_LENGTH + NONCE_LENGTH + MESSAGE_LENGTH];
operation.macLength = MAC_LENGTH;
/* Execute the encryption transaction */
encryptionResult = AESCCM_oneStepEncrypt(handle, &operation);
if (encryptionResult != AESCCM_STATUS_SUCCESS) {
printf("Encryption failed, error code: %d\n", encryptionResult);
while (1) {}
}
AESCCM_close(handle);
/* Debug: Print the encrypted packet */
printf("TX Encrypted packet: ");
for (size_t i = 0; i < ENCRYPTED_PACKET_LENGTH; i++) {
printf("%02X ", txPacket[i]);
}
printf("\n");
/* Send encrypted packet to RX task */
COM_sendPacket(txPacket, ENCRYPTED_PACKET_LENGTH);
}
If I comment out the symmetric key operation, the value of encryptionResult becomes -1, and encryption fails.
Could you please assist me with the following:
- Proper configuration steps or example code for initializing and using AESCCM in this environment.
- Common reasons for the
AESCCM_oneStepEncrypt()function not producing the correct encrypted data. - Debugging steps or troubleshooting tips to resolve this issue.
Thank you for your support.
Best regards,
Aarohi Shirbavikar