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.

Crypto AES Counter Mode (CTR)

Other Parts Discussed in Thread: CC1350

Hi, 

I want to use the crypto hardware in CC1350 to do a AES CTR encryption and decryption. I have seen the example in:

https://e2e.ti.com/support/wireless_connectivity/proprietary_sub_1_ghz_simpliciti/f/156/p/525152/1910063#1910063

But I can't find a function in driverlib/crypto.h that helps me with the CTR encryption.

I have seen the AES_CTR function in rom_crypto.h but as I mentioned, I want to use the crypto hardware.

I am using cc13xxware version: 2.04.02.17240

Btw. I am not using the RTOS

Best regards, 

Kai André Venjum

  • Dear Kai,

    CTR mode is still missing in CC13xxWare and it is unclear whether it will be added and when. You can try to implement it on your own if you want. This should be possible by studying crypto.c in DriverLib. Sorry for the inconvenience.

  • The easiest solution is maybe to use the rom_crypto functionality? Do you have an example on how this should be used? I have searched, but cant fine any god example.

    This is what I have tried for now:

    /* Set up the variables */
    uint8_t aesKey[16] = {
      0x5a, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6c,
      0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x30, 0x39
    };
    
    uint8_t inputData[]= {
      0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
      0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
    };
    
    uint8_t nonce_en[] = {
      0x00, 0x01, 0x00, 0x00
    };
    
    uint8_t nonce_de[] = {
      0x00, 0x01, 0x00, 0x00
    };
    
    uint8_t iv_en[] = {
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x01
    };
    
    uint8_t iv_de[] = {
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x01
    };
    
    uint8_t encryptedData[sizeof(inputData)] = { 0 };
    uint8_t outputData[sizeof(inputData)]    = { 0 };
    
    StandaloneRomCryptoInit();
    
    memcpy(encryptedData, inputData, sizeof(inputData));
    
    AES_CTR_EncryptData(encryptedData, sizeof(inputData), aesKey, nonce_en, iv_en);
    
    memcpy(outputData, encryptedData, sizeof(inputData));
    
    AES_CTR_DecryptData(outputData, sizeof(inputData), aesKey, nonce_de, iv_de);
    
    for (uint8_t i = 0; i < sizeof(inputData); i++)
    {
      if (inputData[i] != outputData[i])
      {
        while(true)
        {
        }
      }
    }

    But when running this code it goes to fault handler when executing the AES_CTR_EncryptData()

    Any idea?

    Best regard Kai André Venjum

  • Hi Kai,

    I guess that you included cc13xxware/utils/rom_crypto/standalone_rom_crypto.c/h into your project and compiled it with IAR? This file uses some compiler-specific features, like placing a scratch area at a fixed address in RAM. The following line looks problematic:

    uint32_t commonROMScratchArea[ 53 ] @0x20004F2C;

    Can you make sure that nothing else is using this address? Maybe edit your linker script accordingly. If you don't use IAR, you need to put this variable into its own section and modify the linker script as well. Sorry, I don't have time to post a full compiler-independent solution.

  • Hi, 

    Yes I have included both files in the project and have changed the linker file to free up the last 53-bytes of the RAM (rom for the commonROMScratchArea).

  • Hi,

    I can reproduce the fault ISR error in CCS. As far as I could find out, these functions are used in one of the stacks. They are not supposed to be used from within customer applications directly, but I don't see any reason, why this shouldn't be possible. Maybe you can do a file search in the stack sources to find out, how they are used? I would be interested in the answer as well.