<?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>bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/123729/bt_gatt-unable-to-import-the-key-for-aes-cmac--141</link><description>I am using a dynamic BAS service. I have noticed that after a few bt_gatt_service_unregister() and bt_gatt_service_register() calls, the following error occurs: bt_gatt: Unable to import the key for AES CMAC -141 . 
 It appears that the problem is caused</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 16 Feb 2026 16:05:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/123729/bt_gatt-unable-to-import-the-key-for-aes-cmac--141" /><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/561275?ContentTypeID=1</link><pubDate>Mon, 16 Feb 2026 16:05:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7be2c38f-4bf5-4e19-af05-505f54a20c39</guid><dc:creator>Amanda Hsieh</dc:creator><description>[quote user="kubavit123"]I have confirmed this fix&amp;nbsp;was introduced in NCS v3.1.1.[/quote]
&lt;p&gt;&lt;span style="margin:0;padding:0;"&gt;Your issue is fixed by PR&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/pull/3218" rel="noopener noreferrer" target="_blank"&gt;3218&lt;/a&gt;,&amp;nbsp;which has been committed to&lt;/span&gt;&amp;nbsp;NCS v3.1.1.&amp;nbsp;&lt;/p&gt;
[quote user="kubavit123"]&lt;strong&gt;NCSDK-31487: Improper reuse of dynamic GATT service handles&amp;nbsp;&lt;/strong&gt;(known issues of NCS) ?&lt;br /&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/releases_and_maturity/known_issues.html"&gt;docs.nordicsemi.com/.../known_issues.html&lt;/a&gt;[/quote]
&lt;p&gt;This fixed as the&amp;nbsp;Workaround.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/561255?ContentTypeID=1</link><pubDate>Mon, 16 Feb 2026 14:25:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b435ddf1-e46a-4d8a-a1db-697abca0e98c</guid><dc:creator>jwitowski</dc:creator><description>&lt;p&gt;Do you have any estimation already in which release it&amp;#39;s going to be fixed ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/561253?ContentTypeID=1</link><pubDate>Mon, 16 Feb 2026 14:19:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a66a6ad5-a934-40e6-b737-8566b19853b3</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;&lt;span&gt;Your issue is more related to the crypto backend.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/561203?ContentTypeID=1</link><pubDate>Mon, 16 Feb 2026 09:17:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbf4eff5-ad24-4deb-aeb7-e30f20972ccc</guid><dc:creator>jwitowski</dc:creator><description>&lt;p&gt;I have confirmed this fix&amp;nbsp;was introduced in NCS v3.1.1.&lt;br /&gt;&lt;br /&gt;I have one additional question. Isn&amp;#39;t it also related to:&lt;br /&gt;&lt;strong&gt;NCSDK-31487: Improper reuse of dynamic GATT service handles&amp;nbsp;&lt;/strong&gt;(known issues of NCS) ?&lt;br /&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/releases_and_maturity/known_issues.html"&gt;docs.nordicsemi.com/.../known_issues.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/547757?ContentTypeID=1</link><pubDate>Thu, 04 Sep 2025 12:53:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1153777a-728a-4a43-a127-bab053d28640</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Thanks for the update. &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/547732?ContentTypeID=1</link><pubDate>Thu, 04 Sep 2025 09:28:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67aeba28-65cd-4e91-b7ee-70d16c25e43c</guid><dc:creator>jwitowski</dc:creator><description>&lt;p&gt;Thank you for the support. I have tested it and the bug doesn&amp;#39;t exist anymore :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/547672?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2025 14:05:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5613397a-27fd-434f-90ed-c5a58999e94a</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;yes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/547666?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2025 13:47:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9467a519-d1f7-41bf-a234-85148a74b19c</guid><dc:creator>jwitowski</dc:creator><description>&lt;p&gt;Will test it tomorrow and let you know about the results. BTW, will it be a part of NCS v3.1.1 release ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/546655?ContentTypeID=1</link><pubDate>Mon, 25 Aug 2025 17:14:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32a3fd3f-738c-4765-a6cb-33ddff9a6572</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Here is the PR&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/pull/3218"&gt;https://github.com/nrfconnect/sdk-zephyr/pull/3218&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/546603?ContentTypeID=1</link><pubDate>Mon, 25 Aug 2025 10:54:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4afe348-f98d-4300-b37a-43a14d701718</guid><dc:creator>jwitowski</dc:creator><description>&lt;p&gt;Thank you, any updates ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/546054?ContentTypeID=1</link><pubDate>Tue, 19 Aug 2025 13:08:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3626541-0e7d-4007-a729-4e714fbd53ab</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Thanks for the testing. I have reported to the internal team to investigate. I will update if we have any way to fix it.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/545945?ContentTypeID=1</link><pubDate>Mon, 18 Aug 2025 14:24:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9cb418b6-4043-4aa1-aa2e-24c7d16c321f</guid><dc:creator>jwitowski</dc:creator><description>&lt;p&gt;I have&amp;nbsp;changed it&amp;#39;s value from 512 to 4096&amp;nbsp;and the difference is it reproduces now after more&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;bt_gatt_service_register()&lt;/code&gt;&lt;span&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;code&gt;&lt;span&gt;bt_gatt_service_unregister() &lt;/span&gt;&lt;/code&gt;calls. So for me it still looks like some memory leakage.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/545938?ContentTypeID=1</link><pubDate>Mon, 18 Aug 2025 13:27:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06c7f992-d989-4c38-858a-ee66a97ab8c6</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Seems like lack of mbedtls heap. Please&amp;nbsp;increase the CONFIG_MBEDTLS_HEAP_SIZE value.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;See&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-mbedtls/blob/v3.6.3-ncs1/include/psa/crypto_values.h#L143"&gt;https://github.com/nrfconnect/sdk-mbedtls/blob/v3.6.3-ncs1/include/psa/crypto_values.h#L143&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Amanda H.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/545824?ContentTypeID=1</link><pubDate>Fri, 15 Aug 2025 19:52:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1555d64d-1d1a-481e-af91-93cb16e98089</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am working on your case, and will update next week.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: bt_gatt: Unable to import the key for AES CMAC -141</title><link>https://devzone.nordicsemi.com/thread/545753?ContentTypeID=1</link><pubDate>Fri, 15 Aug 2025 09:19:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6680c67-786a-4899-b8f2-ece2028524a5</guid><dc:creator>jwitowski</dc:creator><description>&lt;p&gt;&lt;code&gt;psa_crypto.c&lt;/code&gt; modifications:&lt;br /&gt;&lt;code&gt;&lt;pre class="ui-code" data-mode="diff"&gt;diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index 301eed0..d9421c1 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -37,6 +37,8 @@
 #include &amp;quot;mbedtls/constant_time.h&amp;quot;
 #include &amp;quot;mbedtls/cipher.h&amp;quot;  // mbedtls_operation_t

+#include &amp;lt;zephyr/logging/log.h&amp;gt;
+LOG_MODULE_REGISTER(psa_crypto_srvc);

 #if defined(PSA_CRYPTO_DRIVER_TFM_BUILTIN_KEY_LOADER)
 #include &amp;quot;tfm_builtin_key_loader.h&amp;quot;
@@ -283,9 +285,37 @@ MBEDTLS_STATIC_TESTABLE psa_status_t psa_mac_key_can_do(
     return PSA_ERROR_INVALID_ARGUMENT;
 }

+// ...existing code...
+static atomic_t g_psa_key_bytes_current;
+static atomic_t g_psa_key_bytes_peak;
+
+static void psa_debug_acc_add(size_t sz)
+{
+    atomic_add(&amp;amp;g_psa_key_bytes_current, sz);
+    size_t cur = atomic_get(&amp;amp;g_psa_key_bytes_current);
+    size_t peak = atomic_get(&amp;amp;g_psa_key_bytes_peak);
+    if (cur &amp;gt; peak) {
+        atomic_set(&amp;amp;g_psa_key_bytes_peak, cur);
+    }
+}
+
+static void psa_debug_acc_sub(size_t sz)
+{
+    atomic_sub(&amp;amp;g_psa_key_bytes_current, sz);
+}
+
+void psa_crypto_debug_dump(void)
+{
+    size_t cur = atomic_get(&amp;amp;g_psa_key_bytes_current);
+    size_t peak = atomic_get(&amp;amp;g_psa_key_bytes_peak);
+    LOG_ERR(&amp;quot;=== PSA KEYS: tracked_cur=%zu peak=%zu&amp;quot;, cur, peak);
+}
+// ...existing code...
+
 psa_status_t psa_allocate_buffer_to_slot(psa_key_slot_t *slot,
                                          size_t buffer_length)
 {
+    psa_crypto_debug_dump();
 #if defined(MBEDTLS_PSA_STATIC_KEY_SLOTS)
     if (buffer_length &amp;gt; ((size_t) MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE)) {
         return PSA_ERROR_NOT_SUPPORTED;
@@ -297,8 +327,10 @@ psa_status_t psa_allocate_buffer_to_slot(psa_key_slot_t *slot,

     slot-&amp;gt;key.data = mbedtls_calloc(1, buffer_length);
     if (slot-&amp;gt;key.data == NULL) {
+        LOG_ERR(&amp;quot;=== mbedtls_calloc failed ===&amp;quot;);
         return PSA_ERROR_INSUFFICIENT_MEMORY;
     }
+    psa_debug_acc_add(buffer_length);
 #endif

     slot-&amp;gt;key.bytes = buffer_length;
@@ -729,12 +761,14 @@ static psa_status_t psa_get_and_lock_transparent_key_slot_with_policy(

 psa_status_t psa_remove_key_data_from_memory(psa_key_slot_t *slot)
 {
+    LOG_ERR(&amp;quot;=== REMOVE KEY DATA ===&amp;quot;);
 #if defined(MBEDTLS_PSA_STATIC_KEY_SLOTS)
     if (slot-&amp;gt;key.bytes &amp;gt; 0) {
         mbedtls_platform_zeroize(slot-&amp;gt;key.data, MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE);
     }
 #else
     if (slot-&amp;gt;key.data != NULL) {
+        psa_debug_acc_sub(slot-&amp;gt;key.bytes);
         mbedtls_zeroize_and_free(slot-&amp;gt;key.data, slot-&amp;gt;key.bytes);
     }

@@ -1541,6 +1575,7 @@ psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
                             size_t data_length,
                             mbedtls_svc_key_id_t *key)
 {
+    LOG_ERR(&amp;quot;==== IMPORT KEY ====&amp;quot;);
     psa_status_t status;
     psa_key_slot_t *slot = NULL;
     psa_se_drv_table_entry_t *driver = NULL;
@@ -1598,6 +1633,7 @@ psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
         }
         status = psa_allocate_buffer_to_slot(slot, storage_size);
         if (status != PSA_SUCCESS) {
+            LOG_ERR(&amp;quot;=== PSA allocate buffer failed ===&amp;quot;);
             goto exit;
         }
     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>