<?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>nRF54L15 + SRAM + Crypto questions</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119370/nrf54l15-sram-crypto-questions</link><description>Hello, 
 Platform: nRF54L15, SDK 2.9, VS Code 
 Our application is Matter + BLE (like NUS) based door lock application. A BLE custom service (adapted from NUS) is used to exchange info in parallel with Matter. We are not encrypting the BLE transmissions</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 14 Jan 2025 17:17:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119370/nrf54l15-sram-crypto-questions" /><item><title>RE: nRF54L15 + SRAM + Crypto questions</title><link>https://devzone.nordicsemi.com/thread/524893?ContentTypeID=1</link><pubDate>Tue, 14 Jan 2025 17:17:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:846204fc-7198-4334-9d47-bec2fe3d399c</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
[quote user="SubuMuthu"]1. Do you have an example for storing a key in KMU, then retrieving it after reboot and using it?[/quote]
&lt;p&gt;Unfortunately, no, but you can refer to the following files&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/app_dev/device_guides/nrf54l/cryptography.html#storing_keys_in_kmu"&gt;Storing keys in KMU&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/app_dev/device_guides/nrf54l/cryptography.html#using_kmu_keys"&gt;Using KMU keys&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a title="test_kmu_write.c" href="https://github.com/nrfconnect/sdk-nrf/blob/main/tests/psa_crypto/tests/test_kmu_write.c"&gt;test_kmu_write.c&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a title="test_kmu_use.c" href="https://github.com/nrfconnect/sdk-nrf/blob/main/tests/psa_crypto/tests/test_kmu_use.c"&gt;test_kmu_use.c&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
[quote user="SubuMuthu"]can&amp;nbsp; you please help me to correct the below code? It is not working. The key is not set and error is generated.[/quote]
&lt;p&gt;I use the following code and&amp;nbsp;CONFIG_PSA_WANT_ALG_ECB_NO_PADDING=y with&amp;nbsp;nrf\samples\crypto\aes_gcm&amp;nbsp;to generate the key without issue. Please be aware that&amp;nbsp;&lt;span&gt;aes_gcm sample doesn&amp;#39;t support encrypt/decrypt with&amp;nbsp;PSA_ALG_ECB_NO_PADDING.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int generate_key(void)
{
	psa_status_t status;

	LOG_INF(&amp;quot;Generating random AES key...&amp;quot;);

	/* Configure the key attributes */
	psa_key_attributes_t key_attributes = PSA_KEY_ATTRIBUTES_INIT;

	psa_set_key_usage_flags(&amp;amp;key_attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
	//psa_set_key_lifetime(&amp;amp;key_attributes, PSA_KEY_LIFETIME_VOLATILE);
	psa_set_key_algorithm(&amp;amp;key_attributes, PSA_ALG_ECB_NO_PADDING);
	psa_set_key_type(&amp;amp;key_attributes, PSA_KEY_TYPE_AES);
	psa_set_key_bits(&amp;amp;key_attributes, 128);

	psa_set_key_lifetime(&amp;amp;key_attributes,
				 PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
					 PSA_KEY_PERSISTENCE_DEFAULT, PSA_KEY_LOCATION_CRACEN_KMU));
	psa_set_key_id(&amp;amp;key_attributes,
		PSA_KEY_HANDLE_FROM_CRACEN_KMU_SLOT(CRACEN_KMU_KEY_USAGE_SCHEME_RAW, KMU_SLOT_NUM));	

	/* Generate a random key. The key is not exposed to the application,
	 * we can use it to encrypt/decrypt using the key handle
	 */
	status = psa_generate_key(&amp;amp;key_attributes, &amp;amp;key_id);
	if (status != PSA_SUCCESS) {
		LOG_INF(&amp;quot;psa_generate_key failed! (Error: %d)&amp;quot;, status);
		return APP_ERROR;
	}

	/* After the key handle is acquired the attributes are not needed */
	psa_reset_key_attributes(&amp;amp;key_attributes);

	LOG_INF(&amp;quot;AES key generated successfully!&amp;quot;);

	return 0;
}&lt;/pre&gt;&lt;/p&gt;
[quote user="SubuMuthu"]3. How do I use this key after power cycle or reboot?&amp;nbsp;[/quote]
&lt;p&gt;&lt;span&gt;See&amp;nbsp;&lt;/span&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/app_dev/device_guides/nrf54l/cryptography.html#using_kmu_keys"&gt;Using KMU keys&lt;/a&gt;&amp;nbsp;doc.&lt;/p&gt;
[quote user="SubuMuthu"]4. I picked slot #50 (randomly) for testing purpose but would like to know which KMU slot is occupied or available.&amp;nbsp; Is there an API?[/quote]
&lt;p&gt;Currently, there is no such API as your requirement to check slot availability, but you can refer to the&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/app_dev/device_guides/nrf54l/cryptography.html#kmu_slots"&gt;KMU slots&lt;/a&gt;&amp;nbsp;section.&lt;/p&gt;
&lt;p&gt;-Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF54L15 + SRAM + Crypto questions</title><link>https://devzone.nordicsemi.com/thread/524892?ContentTypeID=1</link><pubDate>Sun, 12 Jan 2025 17:00:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5912d18-2afe-47b5-990d-8fc5adcb0a59</guid><dc:creator>SubuMuthu</dc:creator><description>&lt;p&gt;Hi, can you please review and let me know? we are in development and have a release deadline.. Thanks for your understanding and support.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF54L15 + SRAM + Crypto questions</title><link>https://devzone.nordicsemi.com/thread/524891?ContentTypeID=1</link><pubDate>Thu, 09 Jan 2025 23:56:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8242ade7-4d53-46cd-a0ea-1cc52a3548fb</guid><dc:creator>SubuMuthu</dc:creator><description>&lt;p&gt;Hi Amanda, Thank for the explanation.&lt;/p&gt;
&lt;p&gt;Regarding Q4:&lt;/p&gt;
&lt;p&gt;1. Do you have an example for storing a key in KMU, then retrieving it after reboot and using it?&lt;/p&gt;
&lt;p&gt;2. If not,&amp;nbsp; can&amp;nbsp; you please help me to correct the below code? It is not working. The key is not set and error is generated.&lt;/p&gt;
&lt;p&gt;Primarily I have a AES key and I want to store in KMU.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    psa_status_t ret;

#define AES_KEY_KMU_SLOT_ID 50

    psa_key_id_t mDACPrivKeyId;
    psa_key_attributes_t key_attributes = PSA_KEY_ATTRIBUTES_INIT;

//    psa_reset_key_attributes(&amp;amp;key_attributes);
    psa_set_key_type(&amp;amp;key_attributes, PSA_KEY_TYPE_AES);
    psa_set_key_bits(&amp;amp;key_attributes, 128);
    psa_set_key_algorithm(&amp;amp;key_attributes, PSA_ALG_ECB_NO_PADDING);
    psa_set_key_usage_flags(&amp;amp;key_attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);

    mDACPrivKeyId = PSA_KEY_HANDLE_FROM_CRACEN_KMU_SLOT(CRACEN_KMU_KEY_USAGE_SCHEME_RAW, AES_KEY_KMU_SLOT_ID);
    psa_set_key_id(&amp;amp;key_attributes, mDACPrivKeyId);

    psa_set_key_lifetime(
        &amp;amp;key_attributes,
        PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_DEFAULT, PSA_KEY_LOCATION_CRACEN_KMU));

    // ret = psa_import_key(&amp;amp;key_attributes, mobile_public_key, 65, &amp;amp;mDACPrivKeyId);
    // when tried importing, the Error = -135 or -133
    //    ret = psa_copy_key(mobile_encryption_key_id, &amp;amp;key_attributes, &amp;amp;mDACPrivKeyId);
    // when tried copying, the error wass -133
    
    ret = psa_generate_key(&amp;amp;key_attributes, &amp;amp;mDACPrivKeyId); // does not generate key, no error&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;3. How do I use this key after power cycle or reboot?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;4. I picked slot #50 (randomly) for testing purpose but would like to know which KMU slot is occupied or available.&amp;nbsp; Is there an API?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Subu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF54L15 + SRAM + Crypto questions</title><link>https://devzone.nordicsemi.com/thread/524890?ContentTypeID=1</link><pubDate>Wed, 08 Jan 2025 20:15:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92c560c8-9e75-4ebf-b7f1-1c99f3b99605</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
[quote user=""]Setting bonding will eliminate this but Matter standard does not allow bonding.[/quote]
&lt;p&gt;Using CONFIG_BT_PRIVACY makes it non-compliant with the Matter specification, as it will make the device support Random Private Address. The&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;span dir="ltr"&gt;Matter spec requires using static random address for the Matter BLE service advertising purpose and Random Private Address cannot be used. The address has to be rotated on every reboot.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span dir="ltr"&gt;However, this requirement is only for Matter BLE service purposes, so one workaround is to introduce a second Bluetooth identity for the non-Matter services. One of our developers has implemented this in the following commit:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-connectedhomeip/commit/5ae63841a525579afce2c6bb7abcf33692b07a4a"&gt;https://github.com/nrfconnect/sdk-connectedhomeip/commit/5ae63841a525579afce2c6bb7abcf33692b07a4a&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span dir="ltr"&gt;These changes make the BLEManager work in the following way:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If bonding is not enabled, a single Bluetooth ID will be used, and it will initialize a static random address before enabling the Bluetooth stack. If this is not initialized before the stack is enabled, it will configure Bluetooth ID itself and assign the default configuration to it, which we need to avoid,&lt;/li&gt;
&lt;li&gt;If bonding is enabled, two Bluetooth IDs will be used. One is used for bonding and the other for Matter. We first have to initialize the Bluetooth stack to recover the persisted bonding configuration (encryption keys, etc.), and then we initialize a static address for the second Bluetooth ID.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can see the changes that are required in the application here:&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/commit/f84125d62d76fe3dba9b5ae019eb1e66956f6160"&gt;https://github.com/nrfconnect/sdk-nrf/commit/f84125d62d76fe3dba9b5ae019eb1e66956f6160&lt;/a&gt;. To summarize, this Matter implementation allows to enable bonding, and it is necessary to set&amp;nbsp;&lt;span&gt;&lt;span dir="ltr"&gt;&lt;code&gt;CONFIG_&lt;/code&gt;BT_ID_MAX=2&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;and enable&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;span dir="ltr"&gt;CONFIG_&lt;code&gt;BT_EXT_ADV&lt;/code&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;on both the application and network cores.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user=""]Question #1: is there a solution that will allow us to use encryption that comes with BLE stack than we writing the custom encryption (we would prefer BT_SECURITY_L4) but without the iPhone and Android pairing request notifications?I do not believe one exists but we want to ask Nordic to rule this option out.[/quote]
&lt;p&gt;Unfortunately, there is no standard BLE security solution that provides encryption without triggering pairing notifications on iOS/Android.&amp;nbsp;Nordic does not offer a built-in solution to avoid the pairing prompts while using BT_SECURITY_L4.&lt;/p&gt;
[quote user=""]Q2: When we look look at the ram_report, the SRAM&amp;nbsp; needed for our Crypto application is very small - it is the space needed for variables. It looks like MBEDtls library did not take additional space. Does it look alright? From our reading,&amp;nbsp; the MBEDtls should be a memory hog and should consume large memory while we are not seeing an increase in SRAM usage.. This is the reason for asking this question.[/quote]
&lt;p&gt;The small SRAM usage you&amp;#39;re seeing for crypto operations is expected when using PSA Crypto APIs. PSA Crypto leverages hardware acceleration provided by the CryptoCell on Nordic devices, which offloads much of the cryptographic processing from the main CPU. This results in lower SRAM usage compared to a pure software implementation like mbedTLS. Your observation is correct and not a cause for concern.&lt;/p&gt;
&lt;div&gt;Please be aware that&lt;span&gt;&lt;span&gt;&amp;nbsp;Mbed TLS legacy crypto toolbox APIs are marked as deprecated in the nRF Connect SDK version 2.8.0, and will be removed in a future version.&amp;nbsp;See the&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/libraries/security/nrf_security/doc/configuration.html#legacy_crypto_support"&gt;Legacy crypto support&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;[quote user=""]Q3. We tried &amp;nbsp;TF-M (/ns builds),&amp;nbsp; however, we are running out of SRAM. Without TF-M, the SRM usage comes to 220KB. When we try to build with /ns, the build complains that&amp;nbsp;region `RAM&amp;#39; overflowed by 4076 bytes.&amp;nbsp;[/quote]&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;p&gt;I think you&amp;nbsp;&lt;span&gt;adapted from&amp;nbsp;&lt;a title="pm_static_nrf54l15dk_nrf54l15_cpuapp_ns.yml" href="https://github.com/nrfconnect/sdk-nrf/blob/main/samples/matter/lock/pm_static_nrf54l15dk_nrf54l15_cpuapp_ns.yml"&gt;pm_static_nrf54l15dk_nrf54l15_cpuapp_ns.yml&lt;/a&gt;, then the SRAM layout would show like this&lt;/span&gt;&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/pastedimage1736360220430v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;There seems to be insufficient space for your application.&amp;nbsp;&lt;span&gt;You can also look at the suggestions under&amp;nbsp;&lt;/span&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.2/nrf/test_and_optimize/optimizing/memory.html"&gt;Memory footprint optimization&lt;/a&gt;&amp;nbsp;or&amp;nbsp;&lt;span&gt;Check if you can reduce the secure partition size (tfm_sram) without compromising the security features you need.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
[quote user=""]Q4.&amp;nbsp; &amp;nbsp;We would like to store the resulting AES-128 bit asymmetric key in the KMU. It is little bit confusing from&amp;nbsp; the readings if it will be possible to store the key in the KMU without TF-M as the documentation is sparse.&amp;nbsp; Assuming that we won&amp;#39;t be able to do TF-M, please provide an example, or provide the necessary guidelines for storing the keys and also the certificate in the KMU.[/quote]
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;See&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/app_dev/device_guides/nrf54l/cryptography.html"&gt;nRF54L Series cryptography&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Regards,&lt;br /&gt;Amanda H.&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>