I am trying to encrypt a simple message on the CC2652R which I then send over UART to a python script. Here the result is always a failed decryption. I know both the message, MAC, and Nonce arrive correctly. And both the script and the program running on the CC2652R already contain a pre-shared key.
To debug the issue I tried encrypting the same message in the python script as well, using the same PSK and Nonce. However the resulting ciphertext is different in the python script. Am I executing the AES CCM module on the CC2652R incorrectly?
This is the code on the CC2652R:
// the digest is the SHA256 result of a pre-shared salt. // the result is the same on both the CC2652R and the python script result = CryptoKeyPlaintext_initKey(&_cryptoKey, digest, sizeof(digest)); if (result != CryptoKey_STATUS_SUCCESS) return 1; AESCCM_Params ccmParams; AESCCM_Params_init(&ccmParams); ccmParams.returnBehavior = AESCCM_RETURN_BEHAVIOR_BLOCKING; _ccmHandle = AESCCM_open(CONFIG_AESCCM_0, &ccmParams); if (_ccmHandle == NULL) return 0; AESCCM_Operation operation; AESCCM_Operation_init(&operation); char msg[] = {'H', 'E', 'L', 'L', 'O' }; char output[5]; operation.key = &_cryptoKey; operation.input = msg; operation.output = output; operation.inputLength = 5; operation.nonce = nonce; // the nonce is hardcoded as {0xE3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} for now operation.nonceLength = NONCE_SIZE; operation.mac = mac; operation.macLength = 16; int_fast16_t result = AESCCM_oneStepEncrypt(_ccmHandle, &operation);