<?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: Calculating SHA-256 using MMCAU v2 triggers HardFault in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1329745#M61347</link>
    <description>&lt;P&gt;Can a representative of NXP please confirm if the module requires the data to be preprocessed before the calculation can occur?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sachin Patel&lt;/P&gt;</description>
    <pubDate>Wed, 25 Aug 2021 19:30:02 GMT</pubDate>
    <dc:creator>sachin_patel</dc:creator>
    <dc:date>2021-08-25T19:30:02Z</dc:date>
    <item>
      <title>Calculating SHA-256 using MMCAU v2 triggers HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1327728#M61317</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm currently using the Kinetis K32 L2A, which includes a CAU v2 module. I'm trying to use it to calculate a SHA-256 of my main image from my bootloader.&lt;BR /&gt;&lt;BR /&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#include "bootloader_sha256.h"

#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stddef.h&amp;gt;

#include "fsl_mmcau.h"

int sha256_calculate(const uint32_t addr, const size_t size, uint32_t sha256sum[static 8])
{
    /* Confirm the SHA-256 hardware exists. */
    if (MMCAU_SHA256_InitializeOutput(sha256sum) != kStatus_Success) {
        return -1;
    }

    /* Block Size is 512. */
    if (MMCAU_SHA256_HashN((const uint8_t *) addr, (size / 64) + ((size % 64) != 0), sha256sum) != kStatus_Success) {
        return -1;
    }
    return 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On calling MMCAU_SHA256_HashN, the HardFault_Hander IRQ is invoked.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;For context, addr = 0x8100, which is 4-byte mod 0 aligned as required by the module, and the variable sha256sum is instantiated in the bootloader, so there should be no overlap.&lt;BR /&gt;&lt;BR /&gt;Any hints would be helpful.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sachin Patel&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 18:57:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1327728#M61317</guid>
      <dc:creator>sachin_patel</dc:creator>
      <dc:date>2021-08-27T18:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating SHA-256 using MMCAU v2 triggers HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1327955#M61320</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;[static 8]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looks odd to me.&lt;/P&gt;&lt;P&gt;Where exactly does the 'static 8' get allocated and does it happen on each call to the function running out of memory?&lt;BR /&gt;&lt;BR /&gt;Does&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;static uint32_t sha256sum[ 8U ];&lt;/P&gt;&lt;P&gt;then&lt;BR /&gt;&lt;BR /&gt;int sha256_calculate(const uint32_t addr, const size_t size, uint32_t *sha256sum )&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 18:20:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1327955#M61320</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2021-08-23T18:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating SHA-256 using MMCAU v2 triggers HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1328899#M61333</link>
      <description>&lt;P&gt;The static 8 syntax is a valid way to ensure that the array being passed to the function has a minimum of 8 members and is syntactically analogous to passing the pointer uint32_t *sha256sum. Using the pointer doesn’t change the output binary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the problem is not the sha256sum array anyway as the initialise output does not fail - the hash values do get initialised and it confirms the hardware is valid - it’s on computation that the program breaks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sachin Patel&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 21:13:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1328899#M61333</guid>
      <dc:creator>sachin_patel</dc:creator>
      <dc:date>2021-08-24T21:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating SHA-256 using MMCAU v2 triggers HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1329743#M61346</link>
      <description>&lt;P&gt;After some investigations into the MMCAU example project, it appears that in order for the CAU module to be able to compute an SHA-256 message digest it requires the data to have already been preprocessed by applying the required padding as defined by the SHA-256 specification. However, even after applying this change to my own program, the program still hard faults on calling Hash_N. I’ll investigate further with the example project.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 19:28:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1329743#M61346</guid>
      <dc:creator>sachin_patel</dc:creator>
      <dc:date>2021-08-25T19:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating SHA-256 using MMCAU v2 triggers HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1329745#M61347</link>
      <description>&lt;P&gt;Can a representative of NXP please confirm if the module requires the data to be preprocessed before the calculation can occur?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sachin Patel&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 19:30:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1329745#M61347</guid>
      <dc:creator>sachin_patel</dc:creator>
      <dc:date>2021-08-25T19:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating SHA-256 using MMCAU v2 triggers HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1331166#M61363</link>
      <description>&lt;P&gt;Hi Sachil,&lt;/P&gt;
&lt;P&gt;You are correct, hashing requires padding as you can see in &lt;A href="https://www.nxp.com/docs/en/application-note/AN4307.pdf" target="_blank"&gt;AN4307&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Have a great day,&lt;/P&gt;
&lt;P&gt;Felipe&lt;/P&gt;
&lt;P&gt;-------------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;Note:&lt;/P&gt;
&lt;P&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;
&lt;P&gt;- We are following threads for 7 weeks after the last post, later replies are ignored. Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;------------------------------------------------------------------------------&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 18:19:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1331166#M61363</guid>
      <dc:creator>FelipeGarcia</dc:creator>
      <dc:date>2021-08-27T18:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating SHA-256 using MMCAU v2 triggers HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1331275#M61368</link>
      <description>&lt;P&gt;I've been debugging using the MMCAU API Example Project for the FRDM-K32L2A4S Board in the MCUXpresso Environment on Windows (I typically build standalone using the Embedded GCC Toolchain in Ubuntu Linux for our custom hardware). Running the example as-is seems to be fine using the test string, which is only 1 block large. So instead, I generated a binary file in Ubuntu, and appended the padding as required by FIPS 180-2, and as I'd seem previously the program triggers the HardFault_Handler. The difference is with the MCUXpresso IDE I can determine using breakpoints and the dissassembler where the program is crashing:&lt;/P&gt;&lt;P&gt;Disassembler Snippet:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;00000474: mov r9, r5&lt;BR /&gt;00000476: mov r10, r6&lt;BR /&gt;00000478: mov r11, r7&lt;BR /&gt;0000047a: ldr r5, [pc, #600] ; (0x6d4 &amp;lt;mmcau_sha256_hash+20&amp;gt;)&lt;BR /&gt;next_blk:&lt;BR /&gt;0000047c: ldmia r0!, {r7}&lt;BR /&gt;0000047e: rev r7, r7&lt;BR /&gt;00000480: str r7, [sp, #0]&lt;BR /&gt;00000482: mov r6, r9&lt;BR /&gt;00000484: str r7, [r6, #0]&lt;BR /&gt;00000486: str r3, [r5, #0]&lt;BR /&gt;00000488: ldmia r4!, {r7}&lt;BR /&gt;0000048a: mov r6, r10&lt;BR /&gt;0000048c: str r7, [r6, #0]&lt;BR /&gt;0000048e: str r2, [r5, #0]&lt;BR /&gt;00000490: str r1, [r5, #0] &amp;lt;-- Registers measured at this point, next instruction causes program crash&lt;BR /&gt;00000492: ldmia r0!, {r7}&lt;BR /&gt;00000494: rev r7, r7&lt;BR /&gt;00000496: str r7, [sp, #4]&lt;BR /&gt;00000498: mov r6, r9&lt;BR /&gt;0000049a: str r7, [r6, #0]&lt;BR /&gt;&lt;BR /&gt;Registers:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;r0 0x5410 Argument/Scratch Register 1&lt;BR /&gt;r1 0xd4000000 Argument/Scratch Register 2&lt;BR /&gt;r2 0xa6994327 Argument/Scratch Register 3&lt;BR /&gt;r3 0x96594b26 Argument/Scratch Register 4&lt;BR /&gt;r4 0x1fff80d4 Variable Register 1&lt;BR /&gt;r5 0xf0005000 Variable Register 2&lt;BR /&gt;r6 0xf00058c4 Variable Register 3&lt;BR /&gt;r7 0x428a2f98 Variable Register 4&lt;BR /&gt;r8 0x1 Variable Register 5&lt;BR /&gt;r9 0xf0005844 Variable Register 6&lt;BR /&gt;r10 0xf00058c4 Variable Register 7&lt;BR /&gt;r11 0xf0005884 Variable Register 8&lt;BR /&gt;r12 0x20017ef8 Intra-Procedure-Call Scratch Register&lt;BR /&gt;sp 0x20017dac Stack Pointer (r13)&lt;BR /&gt;lr 0x6b3 &amp;lt;mmcau_sha256_update+34&amp;gt; Link Register (r14)&lt;BR /&gt;pc 0x490 &amp;lt;next_blk+20&amp;gt; Program Counter (r15)&lt;BR /&gt;xpsr 0x21000000 Program Status Register&lt;BR /&gt;msp 0x20017dac Main Stack Pointer&lt;BR /&gt;psp 0xffeffffc Process Stack Pointer&lt;BR /&gt;control 0x0 Control Register&lt;BR /&gt;primask 0x0 Interrupt/Exception Mask Register&lt;BR /&gt;cycles 0&lt;BR /&gt;Status Registers Status Registers for cortex-m0plus&lt;BR /&gt;apsr nzCvq Application Program Status Register&lt;BR /&gt;ipsr no fault Interrupt Program Status Register&lt;BR /&gt;epsr T Execution Program Status Register&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From my understanding, the crash happens on the second loop into "next_blk", i.e. when the data block size is greater than 1.&lt;/P&gt;&lt;P&gt;Any further support would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sachin Patel&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 13:08:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1331275#M61368</guid>
      <dc:creator>sachin_patel</dc:creator>
      <dc:date>2021-08-28T13:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating SHA-256 using MMCAU v2 triggers HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1331276#M61369</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/167536"&gt;@FelipeGarcia&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;Is there any proof that the MMCAU SHA-256 algorithm works for packets of block size greater than 1? My current theory is that the CAU fails on the second block calculation. The application note software only provides a test with a block size of 1.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sachin Patel&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 13:10:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1331276#M61369</guid>
      <dc:creator>sachin_patel</dc:creator>
      <dc:date>2021-08-28T13:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating SHA-256 using MMCAU v2 triggers HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1332721#M61389</link>
      <description>&lt;P&gt;Hi Sachin,&lt;/P&gt;
&lt;P&gt;MMCAU_SHA256_Update should work with multiple block to process as long as they are 512 bits size. How many block are you trying to process? Did you add padding correctly to the message so every block is same 64 bytes size?&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Felipe&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 22:58:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1332721#M61389</guid>
      <dc:creator>FelipeGarcia</dc:creator>
      <dc:date>2021-08-31T22:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating SHA-256 using MMCAU v2 triggers HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1334300#M61406</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/167536"&gt;@FelipeGarcia&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Yes, every block is exactly 64 bytes matching the padding as specified by FIPS 180-2.&lt;BR /&gt;&lt;BR /&gt;For my code, I want to process about 200 blocks, and possibly more in the future, but the hard fault happens on block 2.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sachin Patel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 18:47:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1334300#M61406</guid>
      <dc:creator>sachin_patel</dc:creator>
      <dc:date>2021-09-02T18:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating SHA-256 using MMCAU v2 triggers HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1334655#M61412</link>
      <description>&lt;P&gt;So I've found a work-around. There is a bug in the library which doesn't permit accessing more than 1 block, even though the function supposedly supports it. What does work though is to just call the MMCAU_SHA256_HashN() function once for each block.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Here is my final working function:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;int sha256_calculate(const uint32_t addr, const size_t size, uint32_t *sha256sum)
{
    /* Calculate the length of the SHA-256 input message. */
    size_t sha256_len = size + 9;
    int K = 64 - 9 - (size % 64);
    if (K &amp;lt; 0) {
        K += 64;
    }
    sha256_len += K;
    MMCAU_SHA256_InitializeOutput(sha256sum);
    /* Block Size is 512 bits. */
    for (size_t i = 0; i &amp;lt; sha256_len; i += 64) {
        MMCAU_SHA256_HashN((const uint8_t *) (addr + i), 1, sha256sum);
    }
    return 0;

}&lt;/LI-CODE&gt;&lt;P&gt;I've confirmed the output result matches the result given by OpenSSL, so I'll accept the additional overhead of re-calling the function a couple of hundred times. Hopefully the compiler optimises most of the overhead out.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 07:34:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Calculating-SHA-256-using-MMCAU-v2-triggers-HardFault/m-p/1334655#M61412</guid>
      <dc:creator>sachin_patel</dc:creator>
      <dc:date>2021-09-03T07:34:26Z</dc:date>
    </item>
  </channel>
</rss>

