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.

LAUNCHXL-CC26X2R1: AES 128 Decryption data is not correct?

Part Number: LAUNCHXL-CC26X2R1

Hi,

I am working on CC26x2R1 BLE SoC. My use case is to decrypt the data with 128 bit. Key and IV length is 16 bytes and Input data is 24 bytes.

I am following these steps:

static uint8_t AES_Decrypt_Key(uint8_t const *inData, uint8_t *IV, uint8_t const *key,
uint8_t keylength, uint8_t *outData, uint8_t datalength)
{
if ((inData == NULL) || (IV == NULL) || (key == NULL) || (outData == NULL))
{
return INVALIDPARAMETER;
}

uint8_t ret_status = SUCCESS;
AESCBC_Handle aescbcHandle;
AESCBC_Params aescbcParams;
AESCBC_Operation operationOneStepDecrypt;
CryptoKey cryptoKey;

AESCBC_init();
AESCBC_Params_init(&aescbcParams);

// Open AESCCM_open
aescbcHandle = AESCBC_open(0, &aescbcParams);
if (!aescbcHandle)
{
return INVALIDPARAMETER;
}

// Initialize the key structure
CryptoKeyPlaintext_initKey(&cryptoKey, (uint8_t *) key, keylength);

/* Perform a single step decrypt operation of the cipher text */
AESCBC_Operation_init(&operationOneStepDecrypt);
operationOneStepDecrypt.key = &cryptoKey;
operationOneStepDecrypt.input = inData;
operationOneStepDecrypt.output = outData;
operationOneStepDecrypt.iv = IV;
operationOneStepDecrypt.inputLength = datalength;
operationOneStepDecrypt.ivInternallyGenerated = false;

uint8_t result = AESCBC_oneStepDecrypt(aescbcHandle, &operationOneStepDecrypt);
// uint8_t result = AESCBC_oneStepEncrypt(aescbcHandle, &operationOneStepDecrypt);

if (result != AESCBC_STATUS_SUCCESS)
{
ret_status = FAILURE;
}

AESCBC_close(aescbcHandle);
return ret_status;
}

I am passing these parameters but I am not getting correct data. Please suggest me If i am doing wrong?

For Example:

uint8_t EncryptedInputData[24] = {0x11,0x22,0x33,0x44,0x55,0x66,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11};

uint8_t DecryptedOutputData[16] = { 0 };

uint8_t key_128[16] = {0x11,0x22,0x33,0x44,0x55,0x66,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x11,0x11,0x11};

uint8_t IV_128[16] = {0x11,0x22,0x33,0x44,0x55,0x66,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x11,0x11,0x11};

AES_Decrypt_Key(EncryptedInputData, IV_128, key_128, sizeof(key_128), DecryptedOutputData, sizeof(DecryptedOutputData));

I have tried with online tools but Output data is not matched with this DecryptedOutputData.

 

Thanks in advance.

  • Hi Vijay,

    Have you considered padding, this is often the case in the "result don't match my online tool" cases involving AES blockciphers. Our hardware typically pad with zeroes while many online tools often use other padding schemes. The easiest way to check for this is to make sure your encryption data is in N*block size. So 16 * N number of bytes.