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.

CC2642R: How to use AES-CTR on partial data for decryption

Part Number: CC2642R

Hi,

I am using SDK v5.10 where AES CTR driver is available. I need to decrypt a large set of data around ~300KB using AES CTR. However, I cannot do that in a single go as the data to decrypt can be made available in chunks only. Considering that, can the existing driver support decrypting the data in chinks (i.e.256 bytes at a time)?

  • Hi,

    Would you happen to know how the encryption is done? Using the whole 300KB or by chunks?

    I would expect the second option to be used. That way, the decryption should use the same chunk size.

    Best regards,

  • The encryption is done in a single chunk only in the PC and the fimrware is required to decrypt it in chunk due to memory limitation.

  • Hi Clement, any clarification you can add?

  • I have verified using the program in the Python that even after the encryption took place for a large data in a single go, the decryption can give us expected result if performed in chunk i.e. 256 bytes. So, I assume the TO driver will do the same as well?

  • Hi,

    Having the driver yielding the proper results is definitely a good start.

    I am waiting for the confirmation from our R&D.

    Best regards,

  • Hi,

    For AES CTR mode we do not provide yet a direct API to extend/add data.

    Multiple calls to AESCTR_oneStepEncrypt() or AESCTR_oneStepDecrypt() should be done carefully. The value of initialCounter should be changed each time as appropriate. For this to work, the length of data passed in each call (inputLength parameter) must be a whole multiple of 16 bytes until the last call which may then be any number of bytes. 16 bytes is the AES Block size. AES CTR mode increments the counter by one for each block processed. So if you are going to pass 256 bytes on each call then you need to increment the initialCounter value by 256/16 = 16 with each call. The initialCounter value must be a 128 bit value. I believe it should be treated as BE data and incremented as such. You can look at AESCTRDRBGXX_addBigendCounter() in the AESCTRDRBGXX.c file for an example that can be used to do the increment.

    See https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_(CTR) for more background on CTR mode.

    I hope this will help,

    Best regards,