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.

CC2651R3: Assistance Required for AESCCM Encryption/Decryption on CC2651R3

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:

  1. Proper configuration steps or example code for initializing and using AESCCM in this environment.
  2. Common reasons for the AESCCM_oneStepEncrypt() function not producing the correct encrypted data.
  3. Debugging steps or troubleshooting tips to resolve this issue.

Thank you for your support.

Best regards,
Aarohi Shirbavikar

  • Hello Aarohi,

    Thanks for sharing your code.

    Are you starting off with the SDK example?
    https://dev.ti.com/tirex/explore/node?node=A__AJOAPDnkx00C8yQ4dAYzbw__com.ti.SIMPLELINK_CC13XX_CC26XX_SDK__BSEc4rl__LATEST

    Can you confirm that the code from that SDK example is running ok on your CC2651? (Note that UART loopback is used, so you need to connect a jumper between the UART RX and TX pins).
    Also, are you using a custom board or a TI EVM?

    Thanks,
    Toby

  • Dear TI Support Team,

    Thank you so much for your response.

    Yes, I am working on porting example code from the CC2651P3 to the CC2651R3 for our custom board. While implementing this, I opted to drive the code without UART, instead using custom-written code for data sharing.

    As part of this implementation, I am using the AESCCM driver for encrypting and decrypting data. The encryption and decryption processes are functioning correctly with symmetric key exchange in the initial implementation.

    Now, I am integrating this encryption functionality into the BLE code for the CC2651R3. However, I am encountering an issue where the code gets stuck in the AESCCM_oneStepEncrypt() function during encryption.

    Could you please provide guidance on resolving this issue? Any specific considerations or debugging suggestions for using the AESCCM driver with BLE on the CC2651R3 would be greatly appreciated.

    Thank you for your assistance!

    Best regards,

    Aarohi Shirbavikar

  • Hi,

    Now, I am integrating this encryption functionality into the BLE code for the CC2651R3.

    Does it work if you are not operating in a BLE context?

    Thanks,
    Toby