element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Internet of Things
  • Technologies
  • More
Internet of Things
Forum Where do you store/hide your AES keys used for embedded encypt and decrypt?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Internet of Things to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 36 replies
  • Answers 8 answers
  • Subscribers 505 subscribers
  • Views 11333 views
  • Users 0 members are here
  • aes
  • aes_encryption
  • keystore
  • iot
  • aes_decryption
Related

Where do you store/hide your AES keys used for embedded encypt and decrypt?

Jan Cumps
Jan Cumps over 9 years ago

In a scenario where you have two embedded systems talking to each other,

and you want to encrypt/decrypt the data with AES,

where/how do you store the AES key in your firmware sources?

 

If I put my aes-128-ecb in my source code of my firmware like this:

 

    /* Set up the variables */ 
    uint8_t aesKey[16] = { 
            0x5a, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6c, 
            0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x30, 0x39 
    };

 

 

it's  out there for everyone that has access to the version control system, and can leak to the outside world.

 

What's your approach?

  • Sign in to reply
  • Cancel

Top Replies

  • brianonn
    brianonn over 9 years ago +5 suggested
    Definitely don't check any encryption keys into source control. Let's look at the problem: While programming your APIs you see that you needed an AES key for encrypting your shared link. The problem you…
  • clem57
    clem57 over 9 years ago +2
    I would take the AES 256 bit key and encrypt with a private-public key pair RSA 1024 bit. Public is safe out in the open, but the private is stored on a USB medium on a system with a locked keyring. This…
  • Fred27
    Fred27 over 9 years ago +2 suggested
    Would a "good enough" solution be to have this in a separate file that's ignored by source control? It would in theory be accessible by anyone who could get hold of the firmware, but that would be hard…
Parents
  • Fred27
    0 Fred27 over 9 years ago

    Would a "good enough" solution be to have this in a separate file that's ignored by source control? It would in theory be accessible by anyone who could get hold of the firmware, but that would be hard work and would require someone to have physical access to the devices. Whether this simple solution is good enough depends on what you're protecting and whether it's a commercial product or a home one-off project.

     

    Clem's asymmetric key encryption is obviously better but more work.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 9 years ago in reply to Fred27

    Fred27, it's one of the things I've been thinking about. I'm curious how commercial product providers do it.

    I'm reading the tech ref manual of my controller (cc1310) like a madman, haven't found advice on this topic though.

    They have a non-readable keystore, but I don't yet know how to get my key in there without exposing it to 'people in the know'

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Jan Cumps
    0 Jan Cumps over 9 years ago in reply to Fred27

    Fred27, it's one of the things I've been thinking about. I'm curious how commercial product providers do it.

    I'm reading the tech ref manual of my controller (cc1310) like a madman, haven't found advice on this topic though.

    They have a non-readable keystore, but I don't yet know how to get my key in there without exposing it to 'people in the know'

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Fred27
    0 Fred27 over 9 years ago in reply to Jan Cumps

    I think you've stumbled over one of the issues with IoT products. People don't think about this sort of thing and security is not what it should be.

     

    An example - I've recently retired my v1.0 Tado smart thermostat in favour of a v2.0. It's based on Stellaris / MSP430 microcontrollers and CC1101 radios. I thought the gateway unit (LM3S9997 and CC1101) might make a nice Sub-1Ghz 6LowPAN border router so I stated tinkering. It was easy enough to find debug headers and backup the firmware ready to write my own.

     

    Anyway, whilst I believe they've done a much better job than most and have probably secured it fairly well, I'm sure that with enough determination the keys could be retrieved. I'm not going to bother trying because it would involve trawling though assembler but I'm sure it could be done. Even using Clem's asymmetric key encryption technique it will be possible to get the keys. They may not be stored in the clear, but have to be decrypted before they're used.

     

    I think there's no "standard" way of doing it as that starts to imply it's approved and the vendor has said it's secure. What's secure enough for you is really for you to decide. Personally, I'd probably keep it simple - don't check in the key. For a commercial product blow the JTAG fuse and ensure any OTA updates are signed. (I'm not a professional embedded developer so those are just the opinions of a hobbyist.)

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 9 years ago in reply to Fred27

    As long as physical security is maintained, no keys are sent over the air unencrypted. Sorry that is not possible. You assume physical access all bets are off. In some hardware vendors they provide tamper proof storage. Most embedded are not.

    Clem

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Fred27
    0 Fred27 over 9 years ago in reply to clem57

    Clem - Agreed. I was talking about the case where you've got hold of the device and have dumped the firmware. Then the keys are available given enough motivation and effort.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to Fred27

    Fred27

     

    One significant security advantage of using the asymmetric approach mentioned by clem57 :

    • If the private key is compromised, the previous payloads should not be exposed (assuming there was a man in the middle recording packets) as each payload was encrypted with the current session secret key based on (hopefully!) secure random bits; the session key should be generated randomly after each mutual authentication and can be optionally reestablished during the same session.
    • If one is simply storing a secret key and it is compromised, then the historical payloads back to the last key exchange can be recovered by a man in the middle.

     

    Regarding private key security, they should only reside in one place, should never be backed up, and destroyed securely if the owning application is ever removed.  At a major financial corporation where Clem and I used to work, they generate the random private key using 3 unique security officers:

    • Officer 1 privately generates random key part 1 using a security application which manages 3 key parts.  Officer 1 seals part 1 in an envelope and has it stored in the designated "safe deposit" like box in a physically secure location.
    • Ditto for officers 2 and 3.
    • The security application exclusive-ORs the 3 parts together which becomes the stored private key.

     

    I would feel more secure knowing that IoT applications handling my finances were following the above procedure or an equivalent or a more secure one.

     

    Jan Cumps This might be overkill for your application of the cc1310.  David, Clem, and I went off on a tangent, perhaps.  If it were me, I'd be using OpenSSL or one of the "tiny" equivalents.  Would that kill performance of your application?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • crjeder
    0 crjeder over 9 years ago in reply to Former Member

    What you say applies to a scheme wher you use Diffie Hellman to derive session keys. If you are simply encrypting the AES key with the private RSA key you are not doing any better than stroing the AES key in the clear.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 9 years ago in reply to Former Member

    Yes, I thought my question would be simple to solve image

    I wasn't yet at the point where I was going to use the key, just thinking about safely including it in the build and flash process.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 9 years ago in reply to Jan Cumps

    Unfortunately without a tamper proof storage, physical access compromises any scheme. I have not seen a tamper proof access except on a mainframe like this.It can be used on special x86 environments according to IBM.

    Clem

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to crjeder

    Yes, DIffie Hellman is equivalent to using RSA although some folks might argue about which is more effective.

     

    By using DF or SSL/TLS, I don't ever have to store the working key which is used to actually protect the payloads which are transmitted.  The payload-encryptng key is a random secret.  That is one of the advantages of using a public-private key pair over using only a data encrypting key.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to Jan Cumps

    Jan Cumps

     

    I realize that you do not have the luxury of someone else administering the devices for you like with IBM zOS ICSF.  So, how secure do you want this IoT to be?  What follows is an idea for "Version 2" of your cc1310 software in a security sense.

     

    My point of view is that I'd rather do some manual work and more programming work (call me a glutton for punishment) in order to protect payloads flying through the air from a man-in-the-middle attack.  I'd also like a secure end to end mutual authentication process based on a CA both ends trust.  Stretch goal: ensure message integrity.

     

    Instead of hard-coding an AES-128 key, you could load Flash with the following during device installation: 

    • Private key (based on DH or RSA ... pick your poison .... OpenSSL seems to be available under TI-RTOS)
    • Trusted CA certificate (I'll only charge you the price of a good ale during a future October in Flanders)

     

    There are a number of public CAs that you could use for signing the end-point certificates.  Someone who understands OpenSSL and the SSL key exchange process could act as your CA using Linux or Microsoft shell scripts for testing this model. 

     

    When an installed device goes into service in a transactional sense and before setting up the first session, a one-time allocate must be done for enough heap in order to allow enough space for the data encryption key information (key data, IV) for each of the maximum number of sessions.  If it is always only one session at a time, then this is overkill.

     

    Net:

    • Extra administrator work for device installation.
    • Extra programming work for device initialization.
    • Extra programming work for partner session set up.
    • No change to programming work for payload protection, except using CBC instead of ECB.
    • Optional: Implement MAC processing of messages at both ends.  A MAC key would get stored in the same place with the data encryption key.

     

    Private key exposure risks:

    • If a device is compromised, that device has to be re-installed with a new public-private key pair (just start over for this one device).
    • Partner devices are not impacted as long as there is no change to CA.
    • Historical payloads are not at risk.
    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 9 years ago in reply to Former Member

    Thanks!

     

    I've been dealing with trusted CA certificates - including chasing the signature of our CFO and submitting the board structure of my company to one of those certification authorities (I work for a rather big multinational and by the time I had all doco submitted we didn't need the certificate anymore).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube