This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nrf_ecb_crypt

I am trying to decrypt some data. My data is encrypted using AES-ECB No padding method. I know the 32Byte key used for decryption. Following is the code snippet. I am not getting desired decrypted data. Any comments on this?

//key
    uint8_t key[32]= {0x5A,0x34,0xF5,0xF2,0xBB,0x0C,0x6F,0xEF,0x8E,0x94,0x80,0xDE,0xE1,0x31,0x6C,0x51};
//input buffer     
    uint8_t ibuf[16]={0x3D,0xB7,0x7B,0x40,0x6B,0x1D,0x5B,0x38,0xA3,0xCF,0x34,0xFB,0x27,0xD8,0x3B,8E};
//output buffer to store decrypted data
    uint8_t obuf[16];

//init    
nrf_ecb_init();
nrf_ecb_set_key(key);

//call to decrypt data
if (true == nrf_ecb_crypt(obuf, ibuf))
{
   printf("\n done");
}
else
{
   printf("\n failed");
}

Using following online tool, I am able to get correct output: http://aes.online-domain-tools.com/

obuf must have following output:

0x5A,0x34,0xF5,0xF2,0xBB,0x0C,0x6F,0xEF
  • Hi Milan, have you read all responses to your previous question on the same topic?

    Nordic nRF51 ICs and Soft Device API do not support AES decryption, only encryption. So the result of nrf_ecb_crypt function call are always AES-128 ECB encrypted data. So your test vector is:

    • AES-128-ECB-ENCRYPT(clear text = 0x3DB77B406B1D5B38A3CF34FB27D83B8E, key = 0x5A34F5F2BB0C6FEF8E9480DEE1316C51) = 0x7ED754853E36C3E3FFCFF4484F56F10D

    rather then

    • AES-128-ECB-DECRYPT(clear text = 0x3DB77B406B1D5B38A3CF34FB27D83B8E, key = 0x5A34F5F2BB0C6FEF8E9480DEE1316C51) = 0x35613334663566326262306336666566 (aka "5a34f5f2bb0c6fef" in ASCII;).

    What is definitely confusing is description of AES ECB encryption module in Nordic's documentation but even they say "encryption/decryption" there is no input flag which would determine which operation will be performed and it (obviously) cannot be visible just from the inputs (key or cypher text data).

    Cheers Jan

  • I read all posts of earlier topic but I am not getting clear view. Is it possible to decrypt AES ECB data using Nordic API's? or Do I need to port some other library on Nordic?

    Please give your valuable comments.

    Thanks!!

  • clear!! AES block is only for encryption!! Thanks!!

  • Well if you port some open source C implementation of AES decrypt function then you willl cry because performance will be hardly usable. Better choice is probably designing protocols where you need only AES encryption.

Related