<?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>NRF9160 CC310 Crypto Lib Run RSA</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50286/nrf9160-cc310-crypto-lib-run-rsa</link><description>Hi everyone, 
 I few days I tried run on my NRF9160 DK CC310 hardware RSA crypto functions. 
 When I started it at first I ran security_service demo where board run random number generation. 
 After it I added similar code only for RSA tests. I take RSA</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 23 Sep 2019 14:01:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50286/nrf9160-cc310-crypto-lib-run-rsa" /><item><title>RE: NRF9160 CC310 Crypto Lib Run RSA</title><link>https://devzone.nordicsemi.com/thread/211316?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 14:01:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65005160-7083-4ed4-9b75-df9508e45495</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Unfortunately, the pull request with this fix has not yet made it in, but you can see it &lt;a href="https://github.com/NordicPlayground/nrfxlib/pull/82"&gt;here&lt;/a&gt; (and use it).&amp;nbsp; I have not been able to test myself today, but we expect it should fix the issue. The relevant changes are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;MBEDTLS_ENTROPY_MAX_GATHER is set to 144&lt;/li&gt;
&lt;li&gt;MBEDTLS_ENTROPY_FORCE_SH256 must be set (is on by default)&lt;/li&gt;
&lt;li&gt;MBEDTLs_CTR_DRBG_USE_128_BIT_KEY must be set (also on by default)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is due to limitations in the CC310 HW.&lt;/p&gt;
&lt;p&gt;Br,&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 CC310 Crypto Lib Run RSA</title><link>https://devzone.nordicsemi.com/thread/211210?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 11:22:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55b70467-d7f1-4cb0-928f-23a0ea51984a</guid><dc:creator>DenisAks</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/eith"&gt;Einar&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;Do you have any news? Maybe you can say how we can solve this problem?&lt;/p&gt;
&lt;p&gt;We need this on current week.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 CC310 Crypto Lib Run RSA</title><link>https://devzone.nordicsemi.com/thread/204936?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2019 08:13:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4258fab-7456-4863-9a35-47376b36ce93</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I see the same on my side as well when I test your code (mbedtls_ctr_drbg_seed() returns -32, which is MBEDTLS_ERR_AES_INVALID_KEY_LENGTH).&amp;nbsp; I&amp;nbsp;have not been able to track down the root cause, so I have to look into it and get back to you (hopefully soon).&lt;/p&gt;
&lt;p&gt;Note that RSA will not work yet, as mentionned in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/50465/nrf9160-partitions-issue-with-hardware-cc310-crypto-library/201822#201822"&gt;another thread&lt;/a&gt; since there is a known RSA issue in &lt;a href="https://github.com/NordicPlayground/nrfxlib/tree/master/crypto/nrf_cc310_mbedcrypto"&gt;nrf_cc310_mbedcrypto&lt;/a&gt;&amp;nbsp;that will be fixed in the next release. (This specific bug does not affect the RNG though, so I would have expected that to work).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 CC310 Crypto Lib Run RSA</title><link>https://devzone.nordicsemi.com/thread/204290?ContentTypeID=1</link><pubDate>Thu, 15 Aug 2019 11:49:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ddf7b8ad-46f5-4266-b9b8-6534c7b7c9e6</guid><dc:creator>DenisAks</dc:creator><description>&lt;p&gt;Hi.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tried also this&amp;nbsp; example:&amp;nbsp;&amp;nbsp;&lt;a href="https://github.com/ARMmbed/mbedtls/blob/development/programs/pkey/rsa_decrypt.c"&gt;https://github.com/ARMmbed/mbedtls/blob/development/programs/pkey/rsa_decrypt.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is official example from mbedTLS developers.&amp;nbsp;Also you will need set &amp;quot;Reserved SPM Flash size&amp;quot; to 0x20000 then my code will be copiled without partitions errors.&lt;/p&gt;
&lt;p&gt;For print debug&amp;nbsp;info from secure_service.c mbedtls_printf which use Segger RTT.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;platform.c 

static int platform_printf_uninit( const char *format, ... )
{


  char buffer[128];  
  va_list args;  
  va_start (args, format);  
  int n = vsnprintf(buffer, sizeof(buffer), format, args);  
  SEGGER_RTT_Write(0, buffer, n);  
  va_end(args);  
  return n;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int RSA_Test(unsigned char * in_buf, unsigned char * out_buf)
{
    int ret = 1;
    int exit_code = -1;
    mbedtls_rsa_context rsa;
    mbedtls_entropy_context entropy;
    mbedtls_ctr_drbg_context ctr_drbg;
    mbedtls_mpi N, P, Q, D, E, DP, DQ, QP;
    const char *pers = &amp;quot;rsa_genkey&amp;quot;;

    mbedtls_ctr_drbg_init( &amp;amp;ctr_drbg );
    mbedtls_rsa_init( &amp;amp;rsa, MBEDTLS_RSA_PKCS_V15, 0 );
    mbedtls_mpi_init( &amp;amp;N ); mbedtls_mpi_init( &amp;amp;P ); mbedtls_mpi_init( &amp;amp;Q );
    mbedtls_mpi_init( &amp;amp;D ); mbedtls_mpi_init( &amp;amp;E ); mbedtls_mpi_init( &amp;amp;DP );
    mbedtls_mpi_init( &amp;amp;DQ ); mbedtls_mpi_init( &amp;amp;QP );
 
    mbedtls_printf( &amp;quot;\n  . Seeding the random number generator...&amp;quot; );

    mbedtls_entropy_init( &amp;amp;entropy );
    if( ( ret = mbedtls_ctr_drbg_seed( &amp;amp;ctr_drbg, mbedtls_entropy_func, &amp;amp;entropy,
                               (const unsigned char *) pers,
                               strlen( pers ) ) ) != 0 )
    {
        mbedtls_printf( &amp;quot; failed\n  ! mbedtls_ctr_drbg_seed returned %d\n&amp;quot;, ret );
        goto exit;
    }

    mbedtls_printf( &amp;quot; ok\n  . Generating the RSA key [ %d-bit ]...&amp;quot;, KEY_SIZE );
//    fflush( stdout );

    if( ( ret = mbedtls_rsa_gen_key( &amp;amp;rsa, mbedtls_ctr_drbg_random, &amp;amp;ctr_drbg, KEY_SIZE,
                                     EXPONENT ) ) != 0 )
    {
        mbedtls_printf( &amp;quot; failed\n  ! mbedtls_rsa_gen_key returned %d\n\n&amp;quot;, ret );
        goto exit;
    }

    mbedtls_printf( &amp;quot; ok\n  . Exporting the public  key in rsa_pub.txt....&amp;quot; );
//    fflush( stdout );

    if( ( ret = mbedtls_rsa_export    ( &amp;amp;rsa, &amp;amp;N, &amp;amp;P, &amp;amp;Q, &amp;amp;D, &amp;amp;E ) ) != 0 ||
        ( ret = mbedtls_rsa_export_crt( &amp;amp;rsa, &amp;amp;DP, &amp;amp;DQ, &amp;amp;QP ) )      != 0 )
    {
        mbedtls_printf( &amp;quot; failed\n  ! could not export RSA parameters\n\n&amp;quot; );
        goto exit;
    }

    if( ( ret = mbedtls_rsa_export    ( &amp;amp;rsa, &amp;amp;N, &amp;amp;P, &amp;amp;Q, &amp;amp;D, &amp;amp;E ) ) != 0 ||
        ( ret = mbedtls_rsa_export_crt( &amp;amp;rsa, &amp;amp;DP, &amp;amp;DQ, &amp;amp;QP ) )      != 0 )
    {
        mbedtls_printf( &amp;quot; failed\n  ! could not export RSA parameters\n\n&amp;quot; );
        goto exit;
    }


exit:

    mbedtls_mpi_free( &amp;amp;N ); mbedtls_mpi_free( &amp;amp;P ); mbedtls_mpi_free( &amp;amp;Q );
    mbedtls_mpi_free( &amp;amp;D ); mbedtls_mpi_free( &amp;amp;E ); mbedtls_mpi_free( &amp;amp;DP );
    mbedtls_mpi_free( &amp;amp;DQ ); mbedtls_mpi_free( &amp;amp;QP );
    mbedtls_rsa_free( &amp;amp;rsa );
    mbedtls_ctr_drbg_free( &amp;amp;ctr_drbg );
    mbedtls_entropy_free( &amp;amp;entropy );
    
    return ret;

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I got follow error:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/_21043D0438043C043E043A04_.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;All files which you will need I attached. There is files with paths.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks in advance.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ncs.zip"&gt;devzone.nordicsemi.com/.../ncs.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF9160 CC310 Crypto Lib Run RSA</title><link>https://devzone.nordicsemi.com/thread/201117?ContentTypeID=1</link><pubDate>Tue, 30 Jul 2019 06:53:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8cca819-72f5-4499-9d30-a133f213d687</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Can you upload your completed project (e.g. everything within &amp;lt;NCS&amp;gt;\nrf\samples\nrf9160\secure_services or similar) so that I can get a better understanding of what you have done and test the exact same on my side?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>