<?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-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/118102/aes-gcm-iv-sizes-failing-with-nrf54-and-cracen-backend</link><description>Hello, 
 We have an application that uses AES-GCM for AEAD with a 128-bit key and an 64 bit initialization vector (IV). Using the psa_aead_encrypt API seems to work well for us on the nRF52840 where I believe we are using the Oberon backend currently</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 08 May 2025 08:18:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/118102/aes-gcm-iv-sizes-failing-with-nrf54-and-cracen-backend" /><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/534405?ContentTypeID=1</link><pubDate>Thu, 08 May 2025 08:18:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:80a94aad-0970-4b53-b8aa-56233e54e2b1</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Thank you for sharing this. I have forwarded it internally and we will consider if and how we can incorporate this approach in the SDK future.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/534357?ContentTypeID=1</link><pubDate>Wed, 07 May 2025 21:22:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3a12f0e-12ba-4085-ab64-9aad851dba75</guid><dc:creator>Emil Lenngren</dc:creator><description>&lt;p&gt;After some experimentation, I found out that it is indeed possible to perform AES-GCM encryption/decryption with CRACEN with any-sized IV. You just need to add extra&amp;nbsp;DMA descriptors to perform that additional GHASH step in the beginning of the operation to calculate the correct J0 (initial counter), and then additionally make sure that J0 is used at the end when encrypting the tag in the final step.&lt;/p&gt;
&lt;p&gt;I am attaching code that performs arbitrary AES-GCM encryption/decryption using the CRACEN peripheral directly (the existing CRACEN PSA library was to messy too modify for my test). If you want to use it together with nRF Connect SDK, you should probably wrap CRACEN usage between `cracen_acquire` + `nrf_security_mutex_lock(cracen_mutex_symmetric)`&amp;nbsp;and `cracen_release` + `nrf_security_mutex_unlock(cracen_mutex_symmetric)` and remove my ENABLE register writes.&lt;/p&gt;
&lt;p&gt;It would be nice to have code that uses this approach in the nRF Connect SDK, probably behind a Kconfig flag because implementations are recommended by the GCM standard to by default restrict IV size to 12 bytes, to promote interoperability.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/aes_2D00_gcm_2D00_cracen.c"&gt;devzone.nordicsemi.com/.../aes_2D00_gcm_2D00_cracen.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/520332?ContentTypeID=1</link><pubDate>Tue, 28 Jan 2025 10:04:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a2620a3-ae68-4992-b431-b621f81fe8dc</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Ben,&lt;/p&gt;
&lt;p&gt;I see, thank you for sharing the background. It will not be possible to support IV different than 96 bit in CRACEN, and we plan to update the documentation to make that clear. So the alternatives are to either use Oberon as you do now or modify/update your protocol. (Note that Oberon on the nRF54L is not fully supported, so there will be some limitations such as not being able to use HW protected keys).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/520045?ContentTypeID=1</link><pubDate>Fri, 24 Jan 2025 20:09:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d67a9866-2dac-4430-bd2d-eabcc810056a</guid><dc:creator>bvyates</dc:creator><description>&lt;p&gt;Hey Einar,&lt;/p&gt;
&lt;p&gt;This is just an internally defined protocol that we implemented several years ago. It could be changed to use a 96 bit IV, or to use 0 padding to get to 96 bits instead of feeding the smaller IV into AES-GCM directly. That change would just require updating code on a good number of fielded devices, so the cost of just using Oberon is probably less for us than making the change on all the other systems to accommodate this limitation of CRACEN at least for the time being.&lt;/p&gt;
&lt;p&gt;We had originally chosen 64 bits just to save&amp;nbsp;a few bytes in a size-constrained communication environment. The additional time of AES-GCM running a hash to increase the IV size is inconsequential to us. We send few enough messages before key rotation such that reuse of a random IV even at the smaller size is sufficiently unlikely. We could have done the 0 padding prior to feeding in the IV as mentioned above, but it did not occur to anyone at the time that security stacks would not have support for other IV sizes.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/519930?ContentTypeID=1</link><pubDate>Fri, 24 Jan 2025 08:18:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ec4f2fe-ef8b-4561-bdcb-89eff1419bac</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Ben,&lt;/p&gt;
&lt;p&gt;There is a hardware limitation that prevents non-standard IV lengths in nRF54L15. But we are looking into this and wonder if you can share a bit about your use-case and why your application need a 64 bit IV?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/519848?ContentTypeID=1</link><pubDate>Thu, 23 Jan 2025 16:30:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a23b7979-fac9-4440-a881-ac2f515dd357</guid><dc:creator>Emil Lenngren</dc:creator><description>[quote userid="98335" url="~/f/nordic-q-a/118102/aes-gcm-iv-sizes-failing-with-nrf54-and-cracen-backend/518898"]When we use the 64 bit IV that is required by the protocol we&amp;#39;re adhering to[/quote]
&lt;p&gt;What protocol are you using that requires 64-bit IVs? Everything less than 96-bit IV is in my opinion bad design since that requires an extra GHASH operation, which takes time. Padding the IV to 96 bits instead would result in the same security level at a lower performance cost.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/519844?ContentTypeID=1</link><pubDate>Thu, 23 Jan 2025 16:23:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c6184ad-7950-4486-9ca7-61342b47f7b9</guid><dc:creator>bvyates</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Since CRACEN will not work for our application&amp;#39;s use of AES-GCM at this time, I have used the following workaround. Enabling both the CRACEN and Oberon backends, and disabling the CRACEN AEAD component specifically got everything working.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_PSA_CRYPTO_DRIVER_CRACEN=y
CONFIG_PSA_CRYPTO_DRIVER_OBERON=y
CONFIG_PSA_USE_CRACEN_AEAD_DRIVER=n
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I originally tried to disable CRACEN and enable only Oberon, but I was running into an error with EC key generation failing elsewhere in our application. I was not expecting this since the Oberon backend is working fine with the same application on an nRF52 based board. The symptom was similar to these other DevZone posts [&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/98100/psa_generate_key-returns-error--134"&gt;1&lt;/a&gt;], [&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/113696/psa_generate_key-failed-with-error--134"&gt;2&lt;/a&gt;], but none of the config option changes recommended there resolved my issue. Enabling both backends got all of our crypto operations working.&lt;/p&gt;
&lt;p&gt;So our application is all working at this point with the workaround of using both backends. As development continues, we would certainly like to consolidate down to using one backend, ideally CRACEN to make use of the hardware-acceleration.&lt;/p&gt;
&lt;p&gt;Please let me know if is possible that a future update NCS version could include a change that would support non-default IVs on CRACEN. If it is not possible due to the hardware implementation, or just unlikely to be pursued, we will look at&amp;nbsp;only using Oberon.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Ben&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/519243?ContentTypeID=1</link><pubDate>Tue, 21 Jan 2025 10:18:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f311fe0-c3ba-42e9-aee7-852255fb08e2</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I was not aware of that.&amp;nbsp;We are looking into if/how we can support other IV lengths, but for now that meanst&amp;nbsp;that you cannot use HW crypto acceleration with an IV different from 96 bits on nRF54L.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/519137?ContentTypeID=1</link><pubDate>Mon, 20 Jan 2025 15:52:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07e19aec-7ad5-40d6-a21b-75a128b5c30a</guid><dc:creator>Emil Lenngren</dc:creator><description>&lt;p&gt;No, non-96-bit IV are handled differently:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://wikimedia.org/api/rest_v1/media/math/render/svg/623cf4e63a38c4555d651bf235473ca894c8604a"&gt;https://wikimedia.org/api/rest_v1/media/math/render/svg/623cf4e63a38c4555d651bf235473ca894c8604a&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;See&amp;nbsp;&lt;a id="" href="https://en.wikipedia.org/wiki/Galois/Counter_Mode"&gt;https://en.wikipedia.org/wiki/Galois/Counter_Mode&lt;/a&gt;&amp;nbsp;under Mathematical basis, the assignment of Counter0.&lt;/p&gt;
&lt;p&gt;For this to work, the implementation must support it. The user cannot simply pad the IV to&amp;nbsp;96&amp;nbsp;bits.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/519130?ContentTypeID=1</link><pubDate>Mon, 20 Jan 2025 15:20:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c21fe7b-bd59-418f-b47f-73219a5dd3ba</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Ben,&lt;/p&gt;
&lt;p&gt;My understanding is that implementations that support less than 96 bit / 12 byte IV does zero padding under the hood. Did you padd the wrong &amp;quot;end&amp;quot; of the array? I have forwarded the request for supporting IV length othar than 96 bit, but it is currently not supported and I cannot say when it will be.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/518898?ContentTypeID=1</link><pubDate>Fri, 17 Jan 2025 17:17:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c78ea594-2a8f-41c2-ade4-19d44ef3ced7</guid><dc:creator>bvyates</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;Thank you for the information. For my reference, is this the result of a hardware limitation on the MCUs that use the CRACEN backend or a software limitation that might be updated in a future release?&lt;br /&gt;&lt;br /&gt; My understanding is that&amp;nbsp;the extension (or reduction) of the IV to be 12 bytes is built in to the AES-GCM algorithm and is done using the GHASH&amp;nbsp;primitive that is used elsewhere within it.&amp;nbsp;When we use the 64 bit IV that is required by the protocol we&amp;#39;re adhering to, all other systems we&amp;#39;ve encountered (including other Nordic offerings) use the AES-GCM standard mechanism of expanding the IV. Padding with 0s unfortunately then does seem to not produce the same result as any other system, and the encrypted material is invalid.&lt;/p&gt;
&lt;p&gt;I believe&amp;nbsp;that if we were able to GHASH our shorter IV separately in the application to produce a 12 byte value, and fed that value into the the aead function, then it would not be hashed again with the AES-GCM operation, and the IV used would be the same as on another system where the smaller IV was fed in and then hashed internal to AES-GCM. I do not see&amp;nbsp;an obvious way to perform our own GHASH with any APIs within the SDK though, is there any existing access to this primitive?&lt;/p&gt;
&lt;p&gt;If not it seems like we would have either bring in a different implementation of GHASH or not be able to use the CRACEN backend.&lt;/p&gt;
&lt;p&gt;Please let me know if I&amp;#39;m missing something here or if there is a straightforward way for use to perform the GHASH operation ourselves.&lt;/p&gt;
&lt;p&gt;Thank you,&lt;/p&gt;
&lt;p&gt;Ben&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES-GCM IV Sizes failing with nRF54 and CRACEN Backend</title><link>https://devzone.nordicsemi.com/thread/518846?ContentTypeID=1</link><pubDate>Fri, 17 Jan 2025 13:04:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ecbbee4-3280-4997-a69f-b23e5e8de415</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Ben,&lt;/p&gt;
&lt;p&gt;CRACEN only support a 96 bit (12 byte) IV. However, you can zero pad the IV to effecively use shorter, so to use a 64 bit one, you can pass a 12 byte array where 4 are set to 0 and pass that to &lt;code&gt;psa_aead_encrypt()&lt;/code&gt;.&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></channel></rss>