<?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>RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/95814/rsa-example-fails-on-psa_sign_hash-returning--133</link><description>I have one problem report and some related questions: 
 Problem report: 
 When executing the RSA sampe provided with SDK 2.1.0 on the nRD5340DK board the psa_sign_hash function fails with -133 (PSA_ERROR_NOT_PERMITTED). 
 The explanation PSA_ERROR_NOT_PERMITTED</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 21 May 2025 14:43:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/95814/rsa-example-fails-on-psa_sign_hash-returning--133" /><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/536485?ContentTypeID=1</link><pubDate>Wed, 21 May 2025 14:43:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96de8d0f-f9b9-4f14-9ca2-b3b6c9fcc8b4</guid><dc:creator>Riccardo Gaiati</dc:creator><description>&lt;p&gt;Thanks so much for the prompt reply Sigurd. Much appreciated !&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/536437?ContentTypeID=1</link><pubDate>Wed, 21 May 2025 12:45:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ee74fd6-08bf-4c8d-be90-e037801e83b7</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi Riccardo,&lt;/p&gt;
&lt;p&gt;From &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/libraries/security/nrf_security/doc/driver_config.html#nrf-security-driver-config"&gt;Features: Asymmetric encryption support&lt;/a&gt;, see&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/4341.pastedimage1747831350153v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Also see &lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/119742/nrf5340-cc312-rsa-2048-psa_asymmetric_encrypt-psa_alg_rsa_oaep-psa_alg_sha_256-error-issue"&gt;nRF5340 CC312 RSA 2048 psa_asymmetric_encrypt PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256) Error Issue&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/536413?ContentTypeID=1</link><pubDate>Wed, 21 May 2025 11:35:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2835ae4c-e82f-4b07-8db8-101bc6f4402d</guid><dc:creator>Riccardo Gaiati</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;does the PSA Crypto api support&amp;nbsp;&lt;span&gt;2048 bit RSA OEAP operation, from SDK 2.7.0 upwards ?&lt;br /&gt;Thanks in advance !&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Riccardo&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/408037?ContentTypeID=1</link><pubDate>Fri, 03 Feb 2023 14:36:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec241913-94e5-4e9c-a280-9bc6f30baee2</guid><dc:creator>TBing</dc:creator><description>&lt;p&gt;Hi John&lt;/p&gt;
&lt;p&gt;Thanks for the information!&lt;/p&gt;
&lt;p&gt;I think you are correct that a lot might have changed in the SDK around PSA (and mbed_tsl integration).&lt;/p&gt;
&lt;p&gt;Fortunately I was able to use the mbed_tsl API directly, but spend quite some time realizing that.&lt;/p&gt;
&lt;p&gt;In SDK 2.1.1 the unmodified &amp;quot;RSA&amp;quot; sample that uses PSA does not work (even on the nRF5340DK board). So I will stick with the mbed_tsl API for now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/408031?ContentTypeID=1</link><pubDate>Fri, 03 Feb 2023 14:25:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:109e5469-b8da-4a14-9547-98937e7e0808</guid><dc:creator>johntaylor2</dc:creator><description>&lt;p&gt;Tony,&lt;/p&gt;
&lt;p&gt;I ran into &lt;span&gt;PSA_ERROR_NOT_SUPPORT (-134)&amp;nbsp;&amp;nbsp;&lt;/span&gt;error when trying to use RSA decryption with a 2048 bit key.&amp;nbsp; I traced down the error to the mbedtls_psa_rsa_export_key() function being conditionally compiled to a hard coded failure.&amp;nbsp; I added the following statements to my prj.conf file and now I am working.&amp;nbsp; Caveat: I am using an older version of the SDK (v1.7) - so YMMV.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;CONFIG_MBEDTLS_RSA_C=y&lt;br /&gt;CONFIG_MBEDTLS_PK_WRITE_C=y&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/406315?ContentTypeID=1</link><pubDate>Tue, 24 Jan 2023 15:18:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb8b5e20-844e-4c94-bee8-784c40f75eb0</guid><dc:creator>TBing</dc:creator><description>&lt;p&gt;Hi Sigurd&lt;/p&gt;
&lt;p&gt;Thanks for your effort!&lt;/p&gt;
&lt;p&gt;Using the mbed_tsl API does works for RSA 3072 bit encryption.&lt;/p&gt;
&lt;p&gt;I think that you should make tickets on the found problems:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;- RSA signing sample included in SDK does not work.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;- PSA cannot be used for RSA encryption (I could not make it work even for 1024 bit keys)&lt;/p&gt;
&lt;p&gt;I have added my mbed_tsl code for other with similar problems:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="text"&gt;// Output size must be == keysize == keysizeBits / 8
bool mbedTslTest(const uint8_t *input, size_t input_len, uint8_t *output) {
  mbedtls_rsa_context rsa;

  /* Initialize RSA Context */
  mbedtls_rsa_init(&amp;amp;rsa);

  int ret = mbedtls_rsa_set_padding(&amp;amp;rsa, MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_SHA1);
  if (ret) {
    LOG_INF(&amp;quot;failed! to confuigure padding: -%04x&amp;quot;, -ret);
    return (ret);
  }

  ret = mbedtls_rsa_import_raw(&amp;amp;rsa,
                               &amp;amp;RSA_N_3072[0], sizeof(RSA_N_3072),
                               NULL, 0,
                               NULL, 0,
                               NULL, 0,
                               &amp;amp;RSA_E_3072[0], sizeof(RSA_E_3072));
  
  if (ret) {
    LOG_INF(&amp;quot;failed! mbedtls_rsa_import_raw: -%04x&amp;quot;, -ret);
    return (ret);
  }

  ret = mbedtls_rsa_complete(&amp;amp;rsa);
  if (ret) {
    LOG_INF(&amp;quot;failed! mbedtls_rsa_complete: -%04x&amp;quot;, -ret);
    return (ret);
  }

  ret = mbedtls_rsa_rsaes_oaep_encrypt(&amp;amp;rsa, mbedtls_random, NULL, NULL, 0, input_len, input, output);
  if (ret) {
    LOG_INF(&amp;quot;failed! mbedtls_rsa_rsaes_oaep_encrypt: -%04x&amp;quot;, -ret);
    return false;
  }

  LOG_INF(&amp;quot;Success&amp;quot;);

  return true;
}&lt;/pre&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;PSA can be use as RNG:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int mbedtls_random( void *p_rng, unsigned char *output,
                             size_t outputLen ){
  psa_status_t status = psa_generate_random(output, outputLen);
  if (status != PSA_SUCCESS) {
    LOG_ERR(&amp;quot;psa_generate_random failed! (Error: %d)&amp;quot;, outputLen);
    return -1;
  }

  return 0;
}&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards Tonny&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/406104?ContentTypeID=1</link><pubDate>Mon, 23 Jan 2023 17:22:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e5e1104-1ee4-4b9b-af40-583a029b3ad1</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Checking with our developers, it seems that our PSA Crypto API does not yet support 2048 bit keys.&lt;/p&gt;
&lt;p&gt;Instead, I suggest that you use the mbedtls API directly.&lt;br /&gt;I think the API you look for is&lt;a href="https://github.com/nrfconnect/sdk-mbedtls/blob/main/include/mbedtls/rsa.h"&gt; https://github.com/nrfconnect/sdk-mbedtls/blob/main/library/psa_crypto_rsa.h.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/405866?ContentTypeID=1</link><pubDate>Fri, 20 Jan 2023 14:47:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:411b6dd0-afae-4331-b82e-9fee68d0bf1b</guid><dc:creator>TBing</dc:creator><description>&lt;p&gt;Hi Sigurd&lt;/p&gt;
&lt;p&gt;If you remove the&lt;span&gt;&amp;nbsp;&lt;em&gt;psa_export_public_key&lt;/em&gt;, and related then you are not doing public key encryption using a public (only) key.&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The method&amp;nbsp;&lt;em&gt;psa_asymmetric_encrypt&amp;nbsp;&lt;/em&gt;is intended to use a public key without the private part.&lt;/p&gt;
&lt;p&gt;This is the purpose of&amp;nbsp;&lt;em&gt;asymmetric&amp;nbsp;&lt;/em&gt;cryptography&lt;i&gt;,&amp;nbsp;&lt;/i&gt;so this approach will not work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/405859?ContentTypeID=1</link><pubDate>Fri, 20 Jan 2023 14:38:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a7ce186-2f49-4427-9f50-e20b088b5abc</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;To start, I will test our rsa sample.&lt;/p&gt;
&lt;p&gt;I only changed the size from 1024 to 2048, and i t seems that it is psa_export_public_key fails with -147.&lt;br /&gt;If I remove psa_export_public_key and the anything which use the public key, the sample runs without error.&lt;/p&gt;
&lt;p&gt;I have looked a bit at why the encryption is NOT_PERMITTED, but have not found out why this is.&lt;/p&gt;
&lt;p&gt;I will look some more into this and return with more information on Monday.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/405774?ContentTypeID=1</link><pubDate>Fri, 20 Jan 2023 07:47:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:10775272-b2d7-44ff-aba8-8d7864e2e547</guid><dc:creator>TBing</dc:creator><description>&lt;p&gt;Hi Sigurd&lt;/p&gt;
&lt;p&gt;We want to use the CryptoCell, so our requirement has been lowered to the supported 2048 bit keys.&lt;/p&gt;
&lt;p&gt;I have used the code sample from the nRFSDK 2.1.0 called &lt;em&gt;RSA&lt;/em&gt; that performs RSA signature and signature verification.&lt;/p&gt;
&lt;p&gt;As described this sample fails at my end, when using the nRF5340DK board with error -133.&lt;/p&gt;
&lt;p&gt;I have attached the sample including my enhancements to perform RSA encryption.&lt;/p&gt;
&lt;p&gt;Per default, encryption is tested. Signature can be tested by uncommenting the line:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; TEST_RSA_ENCRYPTION (&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;The test shows:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;1) RSA signature/verification fails with -133.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;2) RSA key generation using keys above 1024 bits hangs the program.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;3) RSA encryption using key size 1024 fails with -133.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;We need to perform a 2048 bit RSA OEAP operation, which should be supported according to the documentation / nRF5340 datasheet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I appreciate your effort, hope you are able to help solving this issue.&lt;/p&gt;
&lt;p&gt;Regards Tonny&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/rsa_5F00_encrypt_5F00_or_5F00_sign_5F00_test.zip"&gt;devzone.nordicsemi.com/.../rsa_5F00_encrypt_5F00_or_5F00_sign_5F00_test.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/405682?ContentTypeID=1</link><pubDate>Thu, 19 Jan 2023 13:13:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb9901e6-a279-493d-a961-25e76c873c28</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Can you share the lines of code (or sample) you use to do RSA OAEP?&lt;br /&gt;(Use Insert-&amp;gt;Code to insert code)&lt;/p&gt;
[quote user=""]1) I have a requirement to implement RSA OAEP(SHA1) public key encryption using 3072 bit keys. The CryptoCell on the nRF5340 has a upper limit of 2048 bit keys. The question is, how can I implement the required encryption operation? Is using &lt;em&gt;mbed_tsl&lt;/em&gt; directly an option or is the&amp;nbsp;2048 bit key limit also imposed on this API?[/quote]
&lt;p&gt;For a quick look, I were not able to figure out what the Mbed TLS key limit would be.&lt;br /&gt;From our &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/nrf_security/doc/driver_config.html#nrf-security-driver-config"&gt;Driver configurations and supported features&lt;/a&gt;: &lt;br /&gt;&amp;quot;If a specific cryptographic feature is not supported by a PSA driver but the algorithm is configured to be used, then Built-in Mbed TLS will be enabled to ensure the feature is available.&amp;quot;&lt;/p&gt;
&lt;p&gt;So you can use Mbed TLS for this from the PSA API.&lt;br /&gt;Using the Mbed TLS API directly is also an option, but I recommend trying the PSA API first.&lt;br /&gt;Can you try to use Mbed TLS to do the same operation, and see if it works that way?&lt;/p&gt;
[quote user=""]&lt;span&gt;2) When attempting to do&amp;nbsp;RSA OAEP(SHA1)&amp;nbsp;using a supposedly&amp;nbsp;supported&amp;nbsp;2048 bit key, this fails with return code -147 (PSA_ERROR_HARDWARE_FAILURE). There are no sample code performing RSA public key encryption using the CryptoCell, is this operation not supported?&lt;/span&gt;[/quote]
&lt;p&gt;Which function returns this error?&lt;/p&gt;
&lt;p&gt;Do you get the same error for 1024?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RSA example fails on psa_sign_hash returning -133</title><link>https://devzone.nordicsemi.com/thread/405420?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2023 09:50:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e6a60fe-3406-4971-bbbc-4e018b562814</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I will look into this and return with more information tomorrow.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>