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 507 subscribers
  • Views 11407 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
  • brianonn
    0 brianonn over 9 years ago

    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 have is where to get that AES key from and how to securely store it?

     

    I have a several thoughts on the matter.

     

    1. If this is a commercial product, and the set of communicating devices is known beforehand and small and limited in the members of the set, then I would come up with a way to allow the end user to enter a shared key into each device at the time of deployment.  This would be similar to the way you enter your shared key password into a WiFi router at home. The device is secure and the members of the set that need the key is small and limited in size;
    2. If the situation is similar to #1 above, but the device is NOT secured access (i.e. there is public access), or it's impractical due to the number of devices involved, and you want the key pre-set on the device, then you will need to use some secure storage as suggested by many already. The end user can enter the key into secure storage either at the time of deployment or at the time of manufacture if you don't want end-users dealing with keys (of if there is too many to deal with);
    3. If you can't or don't want to employ secured storage, then you can also use a random session key for the duration of the connection. Once you get the link up and synchronized, you do a Diffie-Hellman (DH) key exchange with your peer, agree on a shared session key and use that for further communication.  You can timeout the shared key if you want, so that a new session key is generated after some time has passed.  This limits the usefulness of any session key discovered via cryptanalysis on your link, and your link becomes more secure because of the changing session keys. Doing a DH key exchange can be expensive in memory and time, so it's a tradeoff between how much security you want and how often you are willing to re-generate session key.

     

    The amount of security you need for your keys, and the level of risk you're willing to accept depends entirely upon your application.  If there's money directly involved, or any other kind of monetary gain to be had, people will be willing to spend time to crack it, and that's when you don't want any keys on insecure storage.  If there is a life safety factor, you also don't want anyone to gain access to the keys.

     

    Keep in mind that Diffie-Hellman is getting weaker and weaker as computers get more powerful, too.  On an embedded system it's tempting to choose DH parameters that are not going to be costly in time, which means a weaker exchange, and one that can likely be cracked on modern PC.  It is for this reason that modern DH key-exchanges use an elliptic curve as the field for the generator.

     

    Finally, here's a public domain Elliptic Curve Diffie-Hellman (ECDH) library, Curve25519, that is written for x86 architecture but can easily be ported to an embedded processor:  https://cr.yp.to/ecdh.html , In fact, this PDF paper https://eprint.iacr.org/2015/343.pdf  does just that, describing the author's efforts at porting the ECDH Curve25519 to 8-bit AVR, 16-bit MSP430 and 32-bit ARM Cortex M0.  It apparently runs in just 1 second time at 16MHz on an AVR. At that point, both sides of the link have a 128-bit shared key they can use for the session encryption. You can do it twice for a 256-bit AES key, or pass the 128-bit key through a key derivation function to stretch it to 256-bits for AES.

     

    Cheers!

    Brian

    • Cancel
    • Vote Up +5 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • clem57
    0 clem57 over 9 years ago in reply to brianonn

    Very well stated brianonn

    Clem

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • clem57
    0 clem57 over 9 years ago in reply to brianonn

    Very well stated brianonn

    Clem

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • brianonn
    0 brianonn over 9 years ago in reply to clem57

    Thanks Clem!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify 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