cancel
Showing results for 
Search instead for 
Did you mean: 

AES-128 encryption for firmware image

KR.269
Associate

Hi,

I am using STM32L4 controller for my project and using KEIL IDE.

I want to do AES-128 encryption for my firmware .hex file because we are planning to keep this firmware image in the cloud server for OTA but it is not safe keeping original firmware image in the server. Can it possible to do encryption at the compilation stage in the keil IDE? 

Please suggest the procedure to get the encrypted .hex file

Thanks.

4 REPLIES 4

You'll have to create a separate PC tool which processes the unencrypted hex/bin file and creates an encrypted one, which you will place on your server, which will be downloaded and decrypted by your firmware.

Take a look at this example - https://github.com/dev26th/bootloader

The "creator" directory is the sources of the PC tool that I'm talking about.

Keil allows for a user post-link application to be run, this could package the firmware update in a secure manner. Usually binary, and often compressed, prior to encryption.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
KR.269
Associate

Hi After Forever,

Thanks, The link that you send is really helped me to proceed my work. I have one more doubt please clarify this also:

After the AES encryption, The 128bit secret Key I am planning to store into the external FLAHS which is connected to my MCU via SPI. This key also I dont want to save the original secret key instead of that I want to save derived secret key to the External FLASH. So that attacker gets the key from external FLASH he cant use that key for decrypt.

Thanks.

Don't store the secret in the external flash, store it in internal flash and make sure to use read-out protection options so people can't extract the secret key so easily.

If you need good security, you could implement combined asymmetric (RSA or ECC) + symmetric (AES for example) encryption with different random AES key every new update. I.e. firmware will get encrypted key + encrypted binary, then decrypt the encrypted key using its private RSA key, then be able to proceed to decrypt the binary.

Cryptography is hard, you should hire professionals if you want robust protection. Even giants like Nintendo make mistakes so researches are able to get/decrypt the OTA updates.