This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

51822 AES encryption and decryption demo code

Hi,

I want to use the AES of 51822 and I have read the nRF51_Reference_manual,I cann't find any demo about AES in SDK.Do you have the demo code about 51822 AES encryption and decryption ?

BR Alice

Parents
  • Alice, a lot of the Nordic APIs have a sd_ prefix to arbitrate sharing of HW resources between user code and SoftDevice.

    With that said: if you're not using the SoftDevice (or it's disabled) call nrf_ecb_crypt() if you're using the SoftDevice and its active, call sd_ecb_block_encrypt()

    As Ole Morten states above, you'll likely want to implement CBC mode yourself on top of the HW accelerated ECB functionality. Remember it is considered dangerous to use ECB alone to protect data (read the Wikipedia article)!

    To do this you would pick a nonce value (random, and doesn't need to be protected) and counter which gets incremented for each data block and concatenate them for use as the data to encrypt, call encrypt with a key of your choice and then XOR your data block with the output of the encrypt call. You would publicly give the output of the XOR and the nonce to the other party and communicate the key to them via protected means or by it being a pre-shared secret.

Reply
  • Alice, a lot of the Nordic APIs have a sd_ prefix to arbitrate sharing of HW resources between user code and SoftDevice.

    With that said: if you're not using the SoftDevice (or it's disabled) call nrf_ecb_crypt() if you're using the SoftDevice and its active, call sd_ecb_block_encrypt()

    As Ole Morten states above, you'll likely want to implement CBC mode yourself on top of the HW accelerated ECB functionality. Remember it is considered dangerous to use ECB alone to protect data (read the Wikipedia article)!

    To do this you would pick a nonce value (random, and doesn't need to be protected) and counter which gets incremented for each data block and concatenate them for use as the data to encrypt, call encrypt with a key of your choice and then XOR your data block with the output of the encrypt call. You would publicly give the output of the XOR and the nonce to the other party and communicate the key to them via protected means or by it being a pre-shared secret.

Children
Related