<?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>AES CBC 256 encryption on nrf52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/120246/aes-cbc-256-encryption-on-nrf52840</link><description>Hi, 
 
 I need to use AES CBC 256 encryption/decryption on nrf52840 but since its cyrpto cell only supports AES 128, I tried using mbedtls to do AES 256 encryption. It works fine but if then I add 
 
 CONFIG_NRF_SECURITY=y in the prj.conf, the decrypted</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 01 Apr 2025 11:14:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/120246/aes-cbc-256-encryption-on-nrf52840" /><item><title>RE: AES CBC 256 encryption on nrf52840</title><link>https://devzone.nordicsemi.com/thread/529963?ContentTypeID=1</link><pubDate>Tue, 01 Apr 2025 11:14:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27ababb8-f1d4-444c-83f1-747bddebbb51</guid><dc:creator>imtiz_ahmed</dc:creator><description>&lt;p&gt;Thanks a lot, this does it!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES CBC 256 encryption on nrf52840</title><link>https://devzone.nordicsemi.com/thread/529943?ContentTypeID=1</link><pubDate>Tue, 01 Apr 2025 10:23:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a81a190-3b64-4f72-a721-f19a67ea8015</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="imtiz_ahmed"]1) Does CONFIG_PSA_CRYPTO_DRIVER_OBERON=y mean that all crypto related work then be run in software and hardware cell will no longer be used for the app?[/quote]
&lt;p&gt;CC310 will still be used and preferred where it can be used.&lt;/p&gt;
[quote user="imtiz_ahmed"]I get following error when using 2.4.2&lt;br /&gt;[/quote]
&lt;p&gt;I see. You can do something similar in NCS v2.4. Also there, make sure that both Oberon and CC310 are enabled:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_PSA_CRYPTO_DRIVER_OBERON=y
CONFIG_PSA_CRYPTO_DRIVER_CC3XX=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And additionally, disable the CC310 driver for CBC explicitly:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_PSA_CRYPTO_DRIVER_ALG_CBC_NO_PADDING_CC3XX=n&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES CBC 256 encryption on nrf52840</title><link>https://devzone.nordicsemi.com/thread/529507?ContentTypeID=1</link><pubDate>Fri, 28 Mar 2025 12:30:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:acbae0b4-edac-483f-8094-38863deab5b0</guid><dc:creator>imtiz_ahmed</dc:creator><description>&lt;p&gt;I get following error when using 2.4.2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;error: PSA_WANT_KEY_TYPE_AES (defined at modules/mbedtls/Kconfig.psa:55,&lt;br /&gt;/opt/nordic/ncs/v2.4.2/nrf/modules/trusted-firmware-m/Kconfig.mbedtls_minimal.defconfig:89,&lt;br /&gt;/opt/nordic/ncs/v2.4.2/nrf/modules/trusted-firmware-m/Kconfig.psa.defconfig:11,&lt;br /&gt;modules/mbedtls/Kconfig.psa:55, modules/mbedtls/Kconfig.psa:55) is assigned in a configuration file,&lt;br /&gt;but is not directly user-configurable (has no prompt). It gets its value indirectly from other&lt;br /&gt;symbols. See &lt;a href="http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_PSA_WANT_KEY_TYPE_AES"&gt;docs.zephyrproject.org/.../kconfig.html&lt;/a&gt; and/or&lt;br /&gt;look up PSA_WANT_KEY_TYPE_AES in the menuconfig/guiconfig interface. The Application Development&lt;br /&gt;Primer, Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual&lt;br /&gt;might be helpful too.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I can make it work if I set the following value in ./aes_cbc/boards/nrf52840dk_nrf52840.conf, but I guess that disables the hardware crypto (not something I want).&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_PSA_CRYPTO_DRIVER_CC3XX=n&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES CBC 256 encryption on nrf52840</title><link>https://devzone.nordicsemi.com/thread/529483?ContentTypeID=1</link><pubDate>Fri, 28 Mar 2025 11:08:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfe13366-60b7-483f-9fb9-ede926589f04</guid><dc:creator>imtiz_ahmed</dc:creator><description>&lt;p&gt;Thanks, I could make it run in the sample. I have couple of questions though.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1) Does CONFIG_PSA_CRYPTO_DRIVER_OBERON=y mean that all crypto related work then be run in software and hardware cell will no longer be used for the app?&lt;br /&gt;&lt;br /&gt;2) I could make it work in aes_cbc sample based on 2.9.0 but the project I have to port this to is based on 2.4.2. If I upgrade that project, it will open up new work scope, so I tried aes_cbc sample based on 2.4.2 and followed exact steps, but over there I still got -134 at psa_cipher_encrypt_setup. Any guesses what could be wrong?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES CBC 256 encryption on nrf52840</title><link>https://devzone.nordicsemi.com/thread/529471?ContentTypeID=1</link><pubDate>Fri, 28 Mar 2025 09:52:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e150b29-7250-436b-8cd9-3daa591290af</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I would recommend that you use the PSA crypto APIs, as the &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/libraries/security/nrf_security/doc/backend_config.html"&gt;legacy APIs are deprecated and will be removed&lt;/a&gt;. You can use the Oberon backend fro AES256. To test it you can use the &lt;a href="https://docs.nordicsemi.com/bundle/ncs-2.9.1/page/nrf/samples/crypto/aes_cbc/README.html"&gt;AES CBC sample&lt;/a&gt;, modify&amp;nbsp;nrf/samples/crypto/aes_cbc/boards/nrf52840dk_nrf52840.conf so that&amp;nbsp;CONFIG_PSA_CRYPTO_DRIVER_OBERON is enabled isntead of being disabled, and add&amp;nbsp;CONFIG_PSA_WANT_AES_KEY_SIZE_256=y to prj.conf. Lastly, modify the call to&amp;nbsp;psa_set_key_bits() in&amp;nbsp;the sample to set 256 bit key size instead of 128.&lt;/p&gt;
&lt;p&gt;This is a full diff of my modifications from SDK 2.9.1 that works for me on the nRF52840 DK:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="diff"&gt;diff --git a/samples/crypto/aes_cbc/boards/nrf52840dk_nrf52840.conf b/samples/crypto/aes_cbc/boards/nrf52840dk_nrf52840.conf
index 1506df21e8..60a0917f5f 100644
--- a/samples/crypto/aes_cbc/boards/nrf52840dk_nrf52840.conf
+++ b/samples/crypto/aes_cbc/boards/nrf52840dk_nrf52840.conf
@@ -4,7 +4,7 @@
 # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 #
 # Using hardware crypto accelerator
-CONFIG_PSA_CRYPTO_DRIVER_OBERON=n
+CONFIG_PSA_CRYPTO_DRIVER_OBERON=y
 CONFIG_PSA_CRYPTO_DRIVER_CC3XX=y
 
 # Mbedtls configuration
diff --git a/samples/crypto/aes_cbc/prj.conf b/samples/crypto/aes_cbc/prj.conf
index 8b4ddbcf9f..934b132e36 100644
--- a/samples/crypto/aes_cbc/prj.conf
+++ b/samples/crypto/aes_cbc/prj.conf
@@ -16,7 +16,10 @@ CONFIG_LOG=y
 # Enable nordic security backend and PSA APIs
 CONFIG_NRF_SECURITY=y
 CONFIG_MBEDTLS_PSA_CRYPTO_C=y
+CONFIG_PSA_CRYPTO_DRIVER_OBERON=y
 
 CONFIG_PSA_WANT_GENERATE_RANDOM=y
 CONFIG_PSA_WANT_KEY_TYPE_AES=y
 CONFIG_PSA_WANT_ALG_CBC_NO_PADDING=y
+
+CONFIG_PSA_WANT_AES_KEY_SIZE_256=y
\ No newline at end of file
diff --git a/samples/crypto/aes_cbc/src/main.c b/samples/crypto/aes_cbc/src/main.c
index 37ab449d8a..2b851c628d 100644
--- a/samples/crypto/aes_cbc/src/main.c
+++ b/samples/crypto/aes_cbc/src/main.c
@@ -87,7 +87,7 @@ int generate_key(void)
 	psa_set_key_lifetime(&amp;amp;key_attributes, PSA_KEY_LIFETIME_VOLATILE);
 	psa_set_key_algorithm(&amp;amp;key_attributes, PSA_ALG_CBC_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_bits(&amp;amp;key_attributes, 256);
 
 	/* Generate a random key. The key is not exposed to the application,
 	 * we can use it to encrypt/decrypt using the key handle
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>