<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [Freedom K82f] Help to configure QSPI for encrypted I/O in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633192#M38141</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Javier,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addtional note:&lt;/P&gt;&lt;P&gt;KEK placed in &amp;nbsp;&lt;STRONG&gt;[0x30 - 0x33] &lt;/STRONG&gt;is not as&amp;nbsp;high security&amp;nbsp;as&lt;STRONG&gt; [0x20 - 0x23],&amp;nbsp;&lt;/STRONG&gt;propose to&amp;nbsp;enable flash security feature.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;[0x30 - 0x33]&lt;/STRONG&gt; erase operation is ame with&lt;STRONG&gt; [0x20 - 0x23], &lt;/STRONG&gt;if erasing the key, it should cause to erase your application.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Juying&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 04 Jan 2017 07:42:45 GMT</pubDate>
    <dc:creator>juying_zhong</dc:creator>
    <dc:date>2017-01-04T07:42:45Z</dc:date>
    <item>
      <title>[Freedom K82f] Help to configure QSPI for encrypted I/O</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633190#M38139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need some help to configure the QSPI for encrypted I/O. This in in general terms what I want to do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. My application resides in the internal flash.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;nbsp;This means that I do not want to have my application on the QSPI. Many examples assume you want to boot your &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; application from the encrypted QSPI. I do not want this.&lt;/P&gt;&lt;P&gt;2. My application creates the keyblob, and uses aes-128 to wrap it. Then it writes the aes-keyblob in the internal flash.&lt;/P&gt;&lt;P&gt;3. My application writes the KEK to &lt;EM&gt;the place where it should go.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;4. My application reboots the device, so after the system is up, the new (and valid) keyblob will be used to configure the OTFAD.&lt;/P&gt;&lt;P&gt;5. Because the OTFAD is configured, encrypted data form the QSPI can be read (because it is decrypted on the fly).&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- Data that will be written to the QSPI needs to be encrypted by my application before the writing operation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So far, I have reached point 2,&amp;nbsp;and I have some questions about point 3:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.nxp.com/assets/documents/data/en/user-guides/KBLQSPIUG.pdf?&amp;amp;fromsite=ja"&gt;This document&lt;/A&gt;&amp;nbsp;states that "KEK needs to be preprogrammed in flash's IFR region. In MK82F256, the Flash IFR index for KEK is from index 0x20 to 0x23 ... using elftosb tools"&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;- How can I verify the current value of [0x20 - 0x23] ?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;- Is there an alternative to the elftosb tools? &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;- Can my application write the KEK at runtime?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;- If the KEK is programmed using elftosb tools (or any existing alternative), is there ANY way to erase/reset it?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Javier&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Dec 2016 16:27:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633190#M38139</guid>
      <dc:creator>javiersoriano</dc:creator>
      <dc:date>2016-12-21T16:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: [Freedom K82f] Help to configure QSPI for encrypted I/O</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633191#M38140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Javier,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Upon my understanding for your application, i guessed that you don't want to use ROM bootloader, then questions answer&amp;nbsp;as below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Firstly, i want you to pay attention&amp;nbsp;on the below description in K82's RM.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;34.3.3 Program Flash Erasable IFR Map&lt;BR /&gt;The program flash erasable IFR is nonvolatile information memory that&lt;STRONG&gt; can be erased but&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;has limited program capabilities and limited read access.&lt;/STRONG&gt; The contents of the program&lt;BR /&gt;flash erasable IFR fields are summarized in the table found here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;34.3.3.1 Erasable Program Once Field&lt;BR /&gt;The Program Once Field in the program flash erasable IFR with indexes 0x20 - 0x23&lt;BR /&gt;provides 16 bytes of user data storage that can be&lt;STRONG&gt; programmed using the Program Once&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;command but cannot be read using the Read Once command.&lt;/STRONG&gt; The Program Once Field in&lt;BR /&gt;the program flash erasable IFR with indexes 0x30 - 0x33 provides 16 bytes of user data&lt;BR /&gt;storage that can be &lt;STRONG&gt;programmed using the Program Once command and read using the&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Read Once command.&lt;/STRONG&gt; The program flash erasable IFR is erased using the Erase All&lt;BR /&gt;Blocks command, Erase All Blocks Unsecure command, and using the external erase all&lt;BR /&gt;feature (mass erase).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;- How can I verify the current value of [0x20 - 0x23] ?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;[Q/A] You can't verify them, because they&amp;nbsp;can only be&amp;nbsp;read by ROM bootlaoder.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;- Is there an alternative to the elftosb tools? &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;[Q/A] No, there isn't.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;- Can my application write the KEK at runtime?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;[Q/A] No, you can't. &amp;nbsp;[0x20 - 0x23] can only be&amp;nbsp;programed once after using erase all block (Flash unsesure) or mass erase (Flash secured and Mass erase enabled).&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;- If the KEK is programmed using elftosb tools (or any existing alternative), is there ANY way to erase/reset it?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;[Q/A] yes, there is. you could use "erase all block command (Flash unsesure) " or "mass erase command (Flash secured and Mass erase enabled)" .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Summary:&lt;/P&gt;&lt;P&gt;KEK placed in &lt;STRONG&gt;[0x20 - 0x23]&lt;/STRONG&gt;&amp;nbsp;can't be read by application firmware except for ROM bootloader (because of considering KEK's security).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Upon your application requirement and K82's features, i proposed that your KEK is same with SB Key placed in&amp;nbsp;&lt;STRONG&gt;[0x30 - 0x33]&lt;/STRONG&gt; . Your application must read it, then use it to decrypt keyblob, finally&amp;nbsp;config OTFAD.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;5. Because the OTFAD is configured, encrypted data form the QSPI can be read (because it is decrypted on the fly).&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- Data that will be written to the QSPI needs to be encrypted by my application before the writing operation.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;OTFAD is one-way, in other word, it can only read data from QSPI and can't write to QSPI.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Juying&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jan 2017 07:24:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633191#M38140</guid>
      <dc:creator>juying_zhong</dc:creator>
      <dc:date>2017-01-04T07:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: [Freedom K82f] Help to configure QSPI for encrypted I/O</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633192#M38141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Javier,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addtional note:&lt;/P&gt;&lt;P&gt;KEK placed in &amp;nbsp;&lt;STRONG&gt;[0x30 - 0x33] &lt;/STRONG&gt;is not as&amp;nbsp;high security&amp;nbsp;as&lt;STRONG&gt; [0x20 - 0x23],&amp;nbsp;&lt;/STRONG&gt;propose to&amp;nbsp;enable flash security feature.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;[0x30 - 0x33]&lt;/STRONG&gt; erase operation is ame with&lt;STRONG&gt; [0x20 - 0x23], &lt;/STRONG&gt;if erasing the key, it should cause to erase your application.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Juying&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jan 2017 07:42:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633192#M38141</guid>
      <dc:creator>juying_zhong</dc:creator>
      <dc:date>2017-01-04T07:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: [Freedom K82f] Help to configure QSPI for encrypted I/O</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633193#M38142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Juying,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the very specific answers. They are definitely helpful!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have one follow up question, though, about this:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Juying Zhong wrote:&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Note:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;5. Because the OTFAD is configured, encrypted data form the QSPI can be read (because it is decrypted on the fly).&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- Data that will be written to the QSPI needs to be encrypted by my application before the writing operation.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;OTFAD is one-way, in other word, it can only read data from QSPI and can't write to QSPI.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;The OTFAD is able to decrypt only when reading. That much is clear. What I would like to do is to write content back to the QSPI, even if I have to encrypt it on my application.&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;Let's assume, for example,&amp;nbsp;that&amp;nbsp;I configure the OTFAD context 1 between 0x6800_0000 and&amp;nbsp;&lt;SPAN&gt;0x6800_1FFF with a key:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;1. Is the region 0x6800_000 - 0x6800_1FFF writable?&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;2. Is it possible to read the output of the OTFAD via an IP command? Or must it be done with AHB commands? I may have misunderstood completely, because I think an IP command read should do the trick.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;Thanks in advance for all the help.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;Javier&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2017 16:15:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633193#M38142</guid>
      <dc:creator>javiersoriano</dc:creator>
      <dc:date>2017-01-06T16:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: [Freedom K82f] Help to configure QSPI for encrypted I/O</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633194#M38143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Javier,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Is the region 0x6800_000 - 0x6800_1FFF writable?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes，it is. Data (code is regarded as data)&amp;nbsp;are wrote through peripheral bus for qspi controller.&lt;/P&gt;&lt;P style="padding: 0px; min-height: 8pt;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Is it possible to read the output of the OTFAD via an IP command?&lt;/P&gt;&lt;P&gt;No, it isn't. IP commands are used to control qspi's IF module by reading preconfigured LUT.&lt;/P&gt;&lt;P&gt;OTFAD returns decrypted data to qspi controller.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or must it be done with AHB commands?&lt;/P&gt;&lt;P&gt;Yes.&amp;nbsp;In fact, &amp;nbsp;you needn't distinguish between IP commands and AHB commands,&amp;nbsp;just need&amp;nbsp;configure&amp;nbsp;LUT and access memory&amp;nbsp;mapped to "0x6800_000 - 0x6800_1FFF".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Juying&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jan 2017 02:47:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633194#M38143</guid>
      <dc:creator>juying_zhong</dc:creator>
      <dc:date>2017-01-11T02:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: [Freedom K82f] Help to configure QSPI for encrypted I/O</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633195#M38144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I am very close to getting the encrypted read/write to work. My problem right now (I believe), has to do with the counters used for encryption of the data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The first 16-byte chunk is decrypted without problems:&lt;/P&gt;&lt;P&gt;1) I encrypt plain text -&amp;gt; cipher&lt;/P&gt;&lt;P&gt;2) I write the cipher to the QSPI&lt;/P&gt;&lt;P&gt;3) I enable the OTFAD&lt;/P&gt;&lt;P&gt;4) Read back cipher from QSPI, which is decrypted on the fly&lt;/P&gt;&lt;P&gt;5) Decrypted cipher is exactly the same as original plain text from step 1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;BUT&lt;/EM&gt;, from the second 16-byte chunk, and all chunks afterwards, the decrypted plain text not matching the input plain text:&lt;/P&gt;&lt;P&gt;0) Increase the address by 16.&lt;/P&gt;&lt;P&gt;Repeat steps 1-5 above..&lt;/P&gt;&lt;P&gt;The difference is that at step 5 I do not get the original plain text anymore. :smileysad:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What I know so far:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;- The data has to be encrypted per 16-byte chunks.&lt;/P&gt;&lt;P&gt;- The "extended counter" is formed with the counter, XOR'ed counter, and address.&lt;/P&gt;&lt;P&gt;- The address needs to be incremented by 16 per 16-byte chunk. (&lt;STRONG&gt;is this correct?&lt;/STRONG&gt;)&lt;/P&gt;&lt;P&gt;- The&amp;nbsp;&lt;EM&gt;encrypt_16byte_block&amp;nbsp;&lt;/EM&gt;part has been verified using the example values in the K82 sub-family reference manual, Rev2 09/2015. This is why I believe my error is somewhere in the "increase counter" logic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HELP! I'm almost there :smileysilly:!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Javier&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS: I attach my code for reference. I have copied it from different parts of my code into a single file for the sake of clarity.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jan 2017 15:44:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633195#M38144</guid>
      <dc:creator>javiersoriano</dc:creator>
      <dc:date>2017-01-24T15:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: [Freedom K82f] Help to configure QSPI for encrypted I/O</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633196#M38145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found some problems in your code, they are below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;static void encrypt_256byte(uint32_t* qspi_addr, uint32_t* data, uint8_t* key, uint8_t* counter)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t address_as_uint32_t = (uint32_t)qspi_addr;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; address_as_uint32_t &amp;amp;= 0xfffffff0; // Bitwise AND to force address to 0-mod-16&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t cipher[4] = {0};&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t plain[4] = {0};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int iterations = FLASH_PAGE_SIZE / 16;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t* offset = data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;uint16_t expand_temp;&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&amp;nbsp; uint8_t expanded_counter[16] = {0};&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; expand_counter(counter, address_as_uint32_t, expanded_counter);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; expand_temp = ((uint16_t)expanded_counter[14])&amp;nbsp;&amp;lt;&amp;lt; 8 | (uint16_t)expanded_counter[15]; //&amp;nbsp;maybe be modified according to your image size&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i = 0; i &amp;lt; iterations ; i++)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memcpy( plain, offset, 16 );&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; encrypt_16byte_block(plain, expanded_counter, key, cipher);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memcpy(offset, cipher, 16);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memset(plain, 0, 16);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memset(cipher, 0, 16);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;expand_temp += 16;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; expanded_counter[15] = (uint8_t)(expand_temp);&amp;nbsp; //&amp;nbsp;maybe be modified according to your image size&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; expanded_counter[14] = (uint8_t)(expand_temp &amp;gt;&amp;gt; 8); //&amp;nbsp;maybe be modified according to your image size&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;offset += sizeof(uint32_t) * 4;&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jan 2017 04:24:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633196#M38145</guid>
      <dc:creator>juying_zhong</dc:creator>
      <dc:date>2017-01-25T04:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: [Freedom K82f] Help to configure QSPI for encrypted I/O</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633197#M38146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the quick answer. These changes did the trick (mostly). :smileyhappy:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I adjusted:&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #51626f; background-color: #ffffff; border: 0px; font-weight: bold;"&gt;offset += sizeof(uint32_t); &lt;/STRONG&gt;&amp;nbsp;// Because offset is a pointer to a uint32_t.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I thought my problem was only on the counter. However I later found that calling&amp;nbsp;&lt;EM&gt;mbedtls_aes_crypt_ctr&lt;/EM&gt; (see attached code above) modified the&amp;nbsp;&lt;EM&gt;key.&amp;nbsp;&lt;/EM&gt;Restoring the key to its initial value fixed the rest of the problems. Now I am able to read (with OTFAD) and write (with software encryption).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for all the help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jan 2017 16:49:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Freedom-K82f-Help-to-configure-QSPI-for-encrypted-I-O/m-p/633197#M38146</guid>
      <dc:creator>javiersoriano</dc:creator>
      <dc:date>2017-01-25T16:49:51Z</dc:date>
    </item>
  </channel>
</rss>

