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.

cc2540 using aes

Hi

I would like to use the aes functions to encrypt a message between a BLE-device und the dongle with a private key, but the don't work...

I'm working with the simpleBLEPeripheral

1) when I try to use the aes functions like AesStartShortBlock( uint8 *out, uint8 *in ) I get an error:

Error[e46]: Undefined external "AesStartShortBlock::?relay" referred in simpleBLEPeripheral ( C:\Texas Instruments\BLE-CC2540-1.1a\Projects\ble\SimpleBLEPeripheral\CC2540DB\ CC2540DK-MINI Keyfob Slave\Obj\simpleBLEPeripheral.r51 )

2) I found the function SM_Encrypt(aesKey,aesIn,aesOut);
This function works more or less... If I call this function, I get no error. But I really don't know what this function does. Somehow the encrypted code is wrong.

Input:

static uint8 aesIn [30]={'h','e','l','l','o','h','e','l','l','o','h','e','l','l','o','h'};
static uint8 aesKey[17]={'1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g'};

Output:

0x9B,0x2B,0xB7,0x2C,0x98,0x5A,0x5A,0xCB,0x78,0xFA,0x5B,0x0C,0xD2,0x78,0x2A,0xEA

According to two different online tools (http://www.riscure.com/tech-corner/online-crypto-tools/aes.html) the Output should be

0xE7,0x66,0xEA,0x14,0x23,0x53,0x06,0x64,0x48,0x67,0xED,0x8D,0xB7,0xA9,0xA4,0x60

  • I'm not very used to AES but this is perhaps due to you do not have specified a padding scheme? A 17-length key (x8) does not seem very... standard.

  • This happend during debugging...

    But it makes no difference between 16 or 17. My key has 16Bytes = 16*8Bit=128Bit.

    And the function gives in both cases 0x00 back. I think this is ok.

  • Ok, it works.

    the functions I have to take are:

    static uint8 aesIn [30]={'h','e','l','l','o','h','e','l','l','o','h','e','l','l','o','h'};
    static uint8 aesOut [30];
    static uint8 aesOut2 [30];
    static uint8 aesKey[16]={'1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g'};

    LL_Encrypt(aesKey,aesIn,aesOut );

    and

    LL_EXT_Decrypt(aesKey,aesOut,aesOut2);

    Using this function, everythin is correct with the standard. The aesOut2 is after the encryption and decryption the same as aesIn.

  • Happy to know :)

  • Hi all,

    I also tried using hal_aes.h and got same error. So i shifted to using LL_encrypt.

    It works perfectly fine on the module.

    But i want to encrypt on CC-2540 and decrypt the data on my android phone.

    There i get the error "javax.crypto.BadPaddingException: pad block corrupted"

    I have also tried encrypting and decrypting the data within android it also works fine.

    The only problem is when i go from one platform to another.

    Can anybody please help?

    Thanks in advance