<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>MCUboot ECIES encryption</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/62488/mcuboot-ecies-encryption</link><description>Hello, I am trying to follow and understand the MCUboot encrypted image design found here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/encrypted_images.html#ecies-encryption 
 Specifically these sections (marked blue below) 
 The</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 22 Jun 2020 12:39:33 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/62488/mcuboot-ecies-encryption" /><item><title>RE: MCUboot ECIES encryption</title><link>https://devzone.nordicsemi.com/thread/256181?ContentTypeID=1</link><pubDate>Mon, 22 Jun 2020 12:39:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5994f54c-19b3-4a53-863a-a232da75df7e</guid><dc:creator>Richard R</dc:creator><description>&lt;p&gt;Thanks Simon. I think I got it now. I will just do some experiments on my end to check.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUboot ECIES encryption</title><link>https://devzone.nordicsemi.com/thread/256096?ContentTypeID=1</link><pubDate>Mon, 22 Jun 2020 07:04:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc30ef88-07b5-41e4-b799-bfc674ff453c</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I got some answers:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;em&gt;&amp;quot;MCUboot is only officially supported by us in NCS scope. There, this is only possible with mbed TLS (nrf_security) which is available&amp;quot;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&amp;quot;But in nRF5 SDK, it&amp;#39;s possible to use the APIs he&amp;#39;s talking about to do ECDH with curve25519 (which means we support x25519).&amp;quot;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;Best regards,&lt;/div&gt;
&lt;div&gt;Simon&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUboot ECIES encryption</title><link>https://devzone.nordicsemi.com/thread/255795?ContentTypeID=1</link><pubDate>Thu, 18 Jun 2020 13:28:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a739f9e-225c-4a13-a32c-e1d7ecfa42d1</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I&amp;#39;ve forwarded your questions internally and currently waiting for an answer. However, I&amp;#39;ll be gone tomorrow and will not be available until Monday.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUboot ECIES encryption</title><link>https://devzone.nordicsemi.com/thread/255784?ContentTypeID=1</link><pubDate>Thu, 18 Jun 2020 13:10:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5dea1eba-7adc-4626-9a40-8fa0a3e24097</guid><dc:creator>Richard R</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;based on you last message, I was under the impression that you are following up internally on your side on the crypto backend?&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Just so we are on the same page, I am trying to use the design from MCUBoot, but the codebase I am working on is based on nRF-SDK and its libraries.&lt;/p&gt;
&lt;p&gt;On my front I have figured out that the SDK allows configuration of specific curves on the crypto engine and uses curve specific data structures (e.g.&amp;nbsp;nrf_crypto_ecdh_curve25519_shared_secret_t&lt;b&gt;)&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;I know that is driven by code and memory space saving.&lt;/p&gt;
&lt;p&gt;I am hoping that this does &lt;strong&gt;not&lt;/strong&gt; mean that it cannot compute ECDH shared secrets generated by other curve parameters. I am curious because the actual API to compute ECDH (nrf_crypto_ecdh_compute) seems to be curve agnostic (as in it does not need to be told the curve parameters itself).&lt;/p&gt;
&lt;p&gt;hopefully the internal team can shed some light into this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUboot ECIES encryption</title><link>https://devzone.nordicsemi.com/thread/255762?ContentTypeID=1</link><pubDate>Thu, 18 Jun 2020 12:17:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05033fd7-0d52-4928-b794-5cf63a87774e</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Have you gotten any progress on this? Have you figured out the question about the crypto backend?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUboot ECIES encryption</title><link>https://devzone.nordicsemi.com/thread/255114?ContentTypeID=1</link><pubDate>Tue, 16 Jun 2020 00:44:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb58ffba-282c-4162-bc13-1f0b8b720994</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I tried to investigate this a little, and I think I got a little smarter. I will share what I&amp;#39;ve figured out so far:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First you need to create a public key (pub_key_dev1) and private key (priv_key_dev1), the private key should be put inside ncs\bootloader\mcuboot\boot\zephyr\keys.c
&lt;ul&gt;
&lt;li&gt;This is the public/private keyset belonging to the device and will not change&lt;/li&gt;
&lt;li&gt;This private/public keyset will be used to create the shared secret through the Elliptic curve Diffie Hellman method (ECDH). The ECDH method needs another public/private keyset (belonging to the deice/computer generating the DFU image), and this keyset will be regenerated (new unique key-pair) on every new image update.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Then,&amp;nbsp;after you&amp;#39;ve created the&amp;nbsp;public/private keyset (&lt;span&gt;pub_key_dev1 and&amp;nbsp;priv_key_dev1&lt;/span&gt;), put the private key in your software, create your product, and maybe a year later you want to do a DFU update, then you do the following:
&lt;ul&gt;
&lt;li&gt;On your computer create the ephemeral (temporary) keyset (public key = pub_key_eph, private key = priv_key_eph)&lt;/li&gt;
&lt;li&gt;Then create a shared secret using the ephemeral private key (priv_key_eph) and the public key (pub_key_dev1) that correspond to the private key&lt;br /&gt; stored in ncs\bootloader\mcuboot\boot\zephyr\keys.c.
&lt;ul&gt;
&lt;li&gt;The same shared secret can be calculated later in the device as well using pub_key_eph (resides in the TLV area) and priv_key_dev1 (in keys.c)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The key derivation method HKDF can now be used to generate 48 bytes of key material (the salt is the string &amp;quot;MCUBoot_ECIES_v1&amp;quot;)
&lt;ul&gt;
&lt;li&gt;The same 48 bytes of key material can also be calculated in the device (MCUboot), since it has the shared secret and uses the same salt &amp;quot;MCUBoot_ECIES_v1&amp;quot;&lt;/li&gt;
&lt;li&gt;Let&amp;#39;s call this key_hkdf&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Then, on the computer you create a new random AES encryption key of 16 bytes (priv_key_AES)&lt;/li&gt;
&lt;li&gt;Next,&amp;nbsp;you encrypt the payload of the image (the executable firmware/code) using that key (priv_key_AES). The header and the TLV area is not encrypted as stated &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/encrypted_images.html#design"&gt;here&lt;/a&gt;:&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;&amp;quot;When encrypting an image, only the payload (FW) is encrypted. The header, TLVs are still sent as plain data.&amp;quot;&lt;/li&gt;
&lt;li&gt;As you can see &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/design.html#protected-tlvs"&gt;here&lt;/a&gt;, the header is stored&lt;br /&gt; first followed by the payload, and the TLV area is placed at the end, after the payload&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Then you encrypt this key (priv_key_AES) using the keys derived from the shared secret (key_hkdf):
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&amp;quot;The key is encrypted with AES-128-CTR and a nonce of 0 using the first 16 bytes of key material generated previously by the HKDF.&amp;quot;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&amp;quot;The encrypted key now goes through a HMAC-SHA256 using the remaining 32 bytes of key material from the HKDF.&amp;quot;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;The aes key (priv_key_AES) is now encrypted. Let&amp;#39;s call it priv_key_AES_cipher&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The ephemeral public key (pub_key_eph) and the ciphered AES key (priv_key_AES_cipher) should be placed in the TLV area of the image that should be sent to the device through DFU.&lt;/li&gt;
&lt;li&gt;When the device receives the image, it can now calculate the shared secret (using priv_key_dev1 and pub_key_eph) and get the key key_hkdf, which can be used to decrypt the priv_key_AES_cipher (in the TLV) to get the AES key (priv_key_AES) to decrypt the image.
&lt;ul&gt;
&lt;li&gt;All this is implemented in MCUboot.&lt;/li&gt;
&lt;li&gt;Look at the function &lt;em&gt;ncs\bootloader\mcuboot\boot\bootutil\src\loader.c--&amp;gt;boot_image_check()&lt;/em&gt;&lt;em&gt;--&amp;gt;boot_enc_load()--&amp;gt;boot_enc_decrypt()&lt;/em&gt; which is used to get priv_key_AES&lt;/li&gt;
&lt;li&gt;Look at the function &lt;em&gt;ncs\bootloader\mcuboot\boot\bootutil\src\image_validate.c--&amp;gt;bootutil_img_validate()--&amp;gt;bootutil_img_hash()--&amp;gt;boot_encrypt()&lt;/em&gt;, which is used to decrypt the image payload.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Be aware that I am still learning this, and this answer may contain errors/misunderstandings. I&amp;#39;ve not looked into the practicalities of this and how to actually do this, but if you have problems with this, don&amp;#39;t hesitate to ask and I will look into it.&lt;/p&gt;
&lt;p&gt;Regarding your question about crypto backend, I will ask internally about this and get back to you.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUboot ECIES encryption</title><link>https://devzone.nordicsemi.com/thread/255033?ContentTypeID=1</link><pubDate>Mon, 15 Jun 2020 13:10:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2335d22-cd1a-4ea6-8ecc-2a8fe9a11dc3</guid><dc:creator>Richard R</dc:creator><description>&lt;p&gt;Thanks for the follow up Simon. I have been reading the material in nrf_crypto sections of the product spec as well and I think it has began to illuminate my understanding. I think the HKDF is performed on both the image-generator and the bootloader receiving the encrypted image and they need to compute to the same 48-byte key material. Will be doing experiments today to confirm.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Also, If you can help me, also pass along this question internally. In the nrf_crypto section, what does it mean when a specific crypto backend &amp;quot;supports&amp;quot; a specific elliptical curve (e.g.&amp;nbsp;&lt;span&gt;secp256r1) - if I pick for example nrf_oberon as a backend, can it not do operations with `secp256k1`?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: MCUboot ECIES encryption</title><link>https://devzone.nordicsemi.com/thread/254904?ContentTypeID=1</link><pubDate>Mon, 15 Jun 2020 08:11:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe93d2f5-308a-4d83-b475-66915fac800c</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Hello, I&amp;#39;m currently looking into your issue. I&amp;#39;m not too familiar with this topic but will investigate/ask internally and try to provide you with an answer today/tomorrow.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>