<?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: rsa_varification using mbedtls libs in i.MX RT Crossover MCUs</title>
    <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/rsa-varification-using-mbedtls-libs/m-p/1395435#M17892</link>
    <description>&lt;P&gt;Thanks for the reply,&lt;/P&gt;&lt;P&gt;the problem was I did not call &lt;STRONG&gt;CRYPTO_InitHardware()&amp;nbsp;&lt;/STRONG&gt; initially,&amp;nbsp;&lt;/P&gt;&lt;P&gt;now I'm able to generate sha256 hashes of inputs properly.&lt;/P&gt;&lt;P&gt;BUT&amp;nbsp;&lt;/P&gt;&lt;P&gt;my calles to &lt;STRONG&gt;mbedtls_rsa_pkcs1_verify( &amp;amp;g_rsa,NULL,NULL,MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1,20, hash, buf )&lt;/STRONG&gt; is failed. the error code returned is&lt;STRONG&gt; -0x4290&lt;/STRONG&gt; but i couldn't find this error code from &lt;STRONG&gt;rsa.h&lt;/STRONG&gt; file, but the closest one is&amp;nbsp;&lt;/P&gt;&lt;P&gt;#define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280 /**&amp;lt; The public key operation failed. */&lt;/P&gt;&lt;P&gt;am i missing any other initialization here ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jan 2022 07:44:23 GMT</pubDate>
    <dc:creator>slimSHA</dc:creator>
    <dc:date>2022-01-06T07:44:23Z</dc:date>
    <item>
      <title>rsa_varification using mbedtls libs</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/rsa-varification-using-mbedtls-libs/m-p/1394246#M17851</link>
      <description>&lt;P&gt;I was trying to verify a signature of a binary file using mbedtls library (v2.26.0)&lt;/P&gt;&lt;P&gt;I took the reference code from&amp;nbsp;&lt;A href="https://github.com/ARMmbed/mbedtls/blob/v2.26.0/programs/pkey/rsa_verify.c" target="_blank" rel="noopener"&gt;https://github.com/ARMmbed/mbedtls/blob/v2.26.0/programs/pkey/rsa_verify.c&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the reference code, they are using the&amp;nbsp;&lt;STRONG&gt;&lt;SPAN class=""&gt;mbedtls_md_file&lt;/SPAN&gt;()&amp;nbsp;&lt;/STRONG&gt;function to calculate the hash of the file.&lt;BR /&gt;But I'm using the FATFS library to access the files. so I had to modify the reference code as follows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/**
 * Function to get hash of a file of path.
 * the hash will be stored in output buffer.
 * return 0 on success and error code on failure.
 */
int rsa_get_hash_of_file(const mbedtls_md_info_t *md_info, char *path,unsigned char *output)
{
	int ret = -1;
    FIL f;
    mbedtls_md_context_t ctx;
    FRESULT error;
    int br=0;
    unsigned char buf[1024];
    if( md_info == NULL )
    {
    	PRINTF("bad input data\r\n");
    	blogd("bad input data\r\n");
    	return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
    }
    error=f_open(&amp;amp;f, path, FA_READ);
    if( error != FR_OK )
    {
    	PRINTF("Unable to open update file for security check\r\n");
    	blogd("Unable to open update file for security check\r\n");
    	return( MBEDTLS_ERR_MD_FILE_IO_ERROR );
    }
    mbedtls_md_init( &amp;amp;ctx );

    if( ( ret = mbedtls_md_init_ctx(&amp;amp;ctx, md_info4) ) != 0 )
        goto cleanup;
    if( ( ret = mbedtls_md_starts( &amp;amp;ctx ) ) != 0 )
        goto cleanup;

    while( (f_read(&amp;amp;f, buf, sizeof(buf), &amp;amp;br) == FR_OK ) &amp;amp;&amp;amp; br &amp;gt; 0)
        {
   	if( ( ret = mbedtls_md_update( &amp;amp;ctx, buf, br ) ) != 0 )
            goto cleanup;
        }
    if( f_error( &amp;amp;f ) != 0 )
        ret = MBEDTLS_ERR_MD_FILE_IO_ERROR;
    else
        ret = mbedtls_md_finish( &amp;amp;ctx, output );
cleanup:
	memset(buf, 0, sizeof(buf));
	f_close( &amp;amp;f );
	mbedtls_md_free( &amp;amp;ctx );
	return( ret );
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the problem is im getting no values in the output buffer and no error code is returning from mbedtls functions.&lt;BR /&gt;is there any macro or to be enabled to get this work ?&amp;nbsp;&lt;BR /&gt;any help are appreciated .&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 12:34:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/rsa-varification-using-mbedtls-libs/m-p/1394246#M17851</guid>
      <dc:creator>slimSHA</dc:creator>
      <dc:date>2022-01-04T12:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: rsa_varification using mbedtls libs</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/rsa-varification-using-mbedtls-libs/m-p/1395156#M17880</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;As this is a library from ARM I would recommend to open an issue in GitHub directly. If you would like to get more information on how to implement file system, I recommend you to check our FatFS examples in our MCUXpresso SDK.&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>Thu, 06 Jan 2022 00:06:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/rsa-varification-using-mbedtls-libs/m-p/1395156#M17880</guid>
      <dc:creator>FelipeGarcia</dc:creator>
      <dc:date>2022-01-06T00:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: rsa_varification using mbedtls libs</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/rsa-varification-using-mbedtls-libs/m-p/1395435#M17892</link>
      <description>&lt;P&gt;Thanks for the reply,&lt;/P&gt;&lt;P&gt;the problem was I did not call &lt;STRONG&gt;CRYPTO_InitHardware()&amp;nbsp;&lt;/STRONG&gt; initially,&amp;nbsp;&lt;/P&gt;&lt;P&gt;now I'm able to generate sha256 hashes of inputs properly.&lt;/P&gt;&lt;P&gt;BUT&amp;nbsp;&lt;/P&gt;&lt;P&gt;my calles to &lt;STRONG&gt;mbedtls_rsa_pkcs1_verify( &amp;amp;g_rsa,NULL,NULL,MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1,20, hash, buf )&lt;/STRONG&gt; is failed. the error code returned is&lt;STRONG&gt; -0x4290&lt;/STRONG&gt; but i couldn't find this error code from &lt;STRONG&gt;rsa.h&lt;/STRONG&gt; file, but the closest one is&amp;nbsp;&lt;/P&gt;&lt;P&gt;#define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280 /**&amp;lt; The public key operation failed. */&lt;/P&gt;&lt;P&gt;am i missing any other initialization here ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 07:44:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/rsa-varification-using-mbedtls-libs/m-p/1395435#M17892</guid>
      <dc:creator>slimSHA</dc:creator>
      <dc:date>2022-01-06T07:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: rsa_varification using mbedtls libs</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/rsa-varification-using-mbedtls-libs/m-p/1396372#M17916</link>
      <description>&lt;P&gt;I increased the heap to 0x8000&amp;nbsp; and the problem resolved&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jan 2022 09:20:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/rsa-varification-using-mbedtls-libs/m-p/1396372#M17916</guid>
      <dc:creator>slimSHA</dc:creator>
      <dc:date>2022-01-08T09:20:31Z</dc:date>
    </item>
  </channel>
</rss>

