<?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>Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79073/unaligned-memory-access-fault-using-mbedtls-on-nrf5340-cpuapp</link><description>I took the RSA example in /nrf/samples/crypto/rsa and added a function foo() to it. I am using nrf5340DK with nrfConnect v1.6.1 and build for cpuapp. 
 my function foo() uses mbedtls functions heavily and makes a call to mbedtls_entropy_init ( entropy</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 16 Sep 2021 13:34:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79073/unaligned-memory-access-fault-using-mbedtls-on-nrf5340-cpuapp" /><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/329865?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 13:34:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:be4dd0e0-88fa-40cf-af73-42458b714747</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;This is from the ARM version of the runtime library (used for the ARM Musca boards). As mentioned, the one used for Nordic devices is supplied as binary only. And that has a lot of our changes. I am afraid we cannot support bypassing all that. You are of course free to experiment on your own, though.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/329676?ContentTypeID=1</link><pubDate>Wed, 15 Sep 2021 19:49:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ceebbc90-8ce3-4f1f-a646-41b819d5760a</guid><dc:creator>persimmon</dc:creator><description>&lt;p&gt;Thanks for clarification. I notice there is an alt implementation of mbedtls in the following link&lt;br /&gt;&lt;br /&gt;All I need is to be able to modify a function&amp;nbsp;in the following file and/or add my own function&amp;nbsp;there and being able to call it from my program( never mind the compatibility etc). I know how to modify it. But I don&amp;#39;t know how to have it compiled and linked.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Function in this file make calls to CC_* functions. They are low level enough for me.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;modules/tee/tfm/trusted-firmware-m/lib/ext/cryptocell-312-runtime/codesafe/src/mbedtls_api/rsa_alt.c&lt;/span&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;P.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/329626?ContentTypeID=1</link><pubDate>Wed, 15 Sep 2021 12:54:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81cc7d6c-fcdd-43be-8899-f5a1ea04c425</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;The&amp;nbsp;cc312_mbedcrypto is provided as a prebuilt library only. The source code is not publicly available, and as such you have not source code to modify.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/329534?ContentTypeID=1</link><pubDate>Wed, 15 Sep 2021 07:10:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0df0aeb0-5da4-4574-9751-8c601ce1a08e</guid><dc:creator>persimmon</dc:creator><description>&lt;p&gt;&amp;gt;&lt;span&gt;Yes, it is part of the cc312_mbedcrypto library.&lt;br /&gt;&lt;br /&gt;Thanks for your response.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Is it possible to&amp;nbsp;modify the provided&amp;nbsp;&lt;span&gt;cc312_mbedcrypto library and have complied as part of the build? (I&amp;nbsp;intentionally added a syntax error there&amp;nbsp;and observed that it is not build during a normal compile of a zehyer program&amp;nbsp;)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/329380?ContentTypeID=1</link><pubDate>Tue, 14 Sep 2021 10:30:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4742db1-7aed-4feb-94fd-56a1b418e6fe</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="persimmon"]Do I add the&amp;nbsp;cryptocell-312-runtime source to my code and try to compile[/quote]
&lt;p&gt;You cannot simply build the CC312 runtime library and make it work with the nRF. There is a platform abstraction layer etc that needs to be implemented. The implementation used in the nrfxlib is not available in source so I cannot share that unfortunately. I do not recommend going down the path of using the CC312 library directly, and we cannot provide support for it. But as you see it is available and you can use it as you want.&lt;/p&gt;
[quote user="persimmon"]or the&amp;nbsp;&lt;span&gt;cryptocell-312-runtime library is already linked (this is probably the case, because I use mbedTLS)?&lt;/span&gt;[/quote]
&lt;p&gt;Yes, it is part of the cc312_mbedcrypto library.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/329286?ContentTypeID=1</link><pubDate>Mon, 13 Sep 2021 21:41:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c536455f-1a13-42a2-9161-aecc382b1c03</guid><dc:creator>persimmon</dc:creator><description>&lt;p&gt;I appreciate sending the links they are very helpful. &lt;br /&gt;&lt;br /&gt;The process of linking to a library in Zephyr is not very clear to me.&amp;nbsp;Do I add the&amp;nbsp;cryptocell-312-runtime source to my code and try to compile or the&amp;nbsp;&lt;span&gt;cryptocell-312-runtime library is already linked (this is probably the case, because I use mbedTLS)?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;But when I makes calls to&amp;nbsp;cryptocell Iibrary, I get errors.&lt;br /&gt;&lt;br /&gt;If you cannot respond to this I understand. Thanks for the help so far.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/329169?ContentTypeID=1</link><pubDate>Mon, 13 Sep 2021 09:29:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:283b753a-a9d9-4afe-a381-586f390c98fc</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I see, but mbedTLS togethwer with the platform library is what we provide for CryptoCell. You can see all we provide&amp;nbsp; under &lt;a href="https://github.com/nrfconnect/sdk-nrfxlib/tree/master/crypto"&gt;sdk-nrflib/crypto&lt;/a&gt;. (ARM also provide the &lt;a href="https://github.com/ARM-software/cryptocell-312-runtime"&gt;CC312 runtime library&lt;/a&gt; directly, but while this is used by us we do not support using the ARM library directly. You are of course free to play with it, though).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/329087?ContentTypeID=1</link><pubDate>Fri, 10 Sep 2021 17:57:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:edb56408-e683-4908-811a-31275e1d55a2</guid><dc:creator>persimmon</dc:creator><description>&lt;p&gt;Thanks for the recommendations. The&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;&amp;nbsp;/nrf/tests/crypto&lt;/span&gt; uses mbedTLS. I&amp;#39;d like to bypass mbedTLS and call Cryptocell directly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/328210?ContentTypeID=1</link><pubDate>Mon, 06 Sep 2021 13:11:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66c069eb-31a1-46f0-912d-5dcc6de2e542</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="persimmon"]I noticed that mbedTLS in secure-world calls to CryptoCell library and I was wondering how we can do&amp;nbsp; that.[/quote]
&lt;p&gt;There are quite a few libraries crypto libraries in nRF Connect SDK. These are managed by the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/nrf_security/README.html#nrf-security"&gt;Nordic Security Module&lt;/a&gt;, so I suggest you start looking at that. That is relevant both if you want to use it, of if you want to see how various modules (like the CryptoCell runtime library, Mbed TLS, etc) are integrated. The &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/tests/crypto/README.html"&gt;Cryptography tests&lt;/a&gt;&amp;nbsp;are a good example to look at to see this in practice. It configurations for various scenarios, like using mbed TLS with CryptoCell as a crypto accelerator, and using CryptoCell only for entropy, etc.&lt;/p&gt;
[quote user="persimmon"]Is&amp;nbsp;the random number generate in the code I send&amp;nbsp; is&amp;nbsp;&lt;strong&gt;correctly&lt;/strong&gt;&amp;nbsp;constructed and uses the &lt;strong&gt;hardware-random-number generator&lt;/strong&gt;, or we need to add that HW-RNG explicitly as entropy source?[/quote]
&lt;p&gt;You use the CrytoCell RNG in this project.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/327874?ContentTypeID=1</link><pubDate>Fri, 03 Sep 2021 04:09:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d8bfe7d-b200-420c-b9cf-dc31a38e8d1c</guid><dc:creator>persimmon</dc:creator><description>&lt;p&gt;I appreciate the fix. I try and let you know.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&lt;span&gt;May I ask why that is?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;We are&amp;nbsp;performing very customized crypto operations (we are cryptographers) and PSA is too high-level for us. Even mbedTLS is too high-level. We would like to use CryptoCell directly, but we don&amp;#39;t exactly know NRF software architecture. I noticed that mbedTLS in secure-world calls to CryptoCell library and I was wondering how we can do&amp;nbsp; that. I even&amp;nbsp;modified&amp;nbsp;some of your&amp;nbsp;&lt;span&gt;mbedTLS functions in secure-world, but apparently&amp;nbsp;they are not build during the SW build.&lt;br /&gt;&lt;br /&gt;Any help would be really appreciated. We are capable of modifying mbedTLS library and/or add our own functions. But we don&amp;#39;t know how to build it and with our software.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;Yes and no. Purely as a SW library....&lt;br /&gt;&lt;br /&gt;Agreed.&amp;nbsp; noticed that your build pulls in the TF-M automatically, when you use PSA and build for NS. And makes call to the secure part under the hood. It is a&amp;nbsp;very interesting SW work. I have worked with similar chips, but their build&amp;nbsp;is way more complicated.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;We run our code in secure-world. We need quick access to CryptoCell.&lt;br /&gt;&lt;br /&gt;Another question, if I may.&amp;nbsp;Is&amp;nbsp;the random number generate in the code I send&amp;nbsp; is&amp;nbsp;&lt;strong&gt;correctly&lt;/strong&gt;&amp;nbsp;constructed and uses the &lt;strong&gt;hardware-random-number generator&lt;/strong&gt;, or we need to add that HW-RNG explicitly as entropy source?&lt;br /&gt;&lt;br /&gt;Reagards,&lt;br /&gt;P.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/327722?ContentTypeID=1</link><pubDate>Thu, 02 Sep 2021 08:03:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e800fb47-9d1a-4679-85d1-fce5c2fee303</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="persimmon"]The code I provided is an example to show the problem, not the actual project.[/quote]
&lt;p&gt;I see. The actual issue you are seeing her is what is described in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/58824/cc310-platform-mutex-init-error"&gt;this thread&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The fix is to add this line before your call to&amp;nbsp;&lt;code&gt;mbedtls_entropy_init()&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    memset(&amp;amp;ec-&amp;gt;entropy, 0, sizeof(ec-&amp;gt;entropy));&lt;/pre&gt;&lt;/p&gt;
[quote user="persimmon"]We cannot&amp;nbsp;not use PSA in our project, we can only use mbedTLS.[/quote]
&lt;p&gt;May I ask why that is?&lt;/p&gt;
[quote user="persimmon"]I think we agree that mbedTLS should work in both secure and in&amp;nbsp;non-secure worlds correctly.[/quote]
&lt;p&gt;Yes and no. Purely as a SW library, yes. But the only entropy source available to the application core is within CryptoCell, and that is only accessible from secure domain. So you cannot use this code in non-secure. The only solution to that that is provided by the nRF Connect SDK is using PSA TF-M. That way, TF-M will provide crypto operations as secure services to the non-secure code, using PSA APIs.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/327668?ContentTypeID=1</link><pubDate>Wed, 01 Sep 2021 16:21:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a793155c-f5b9-425c-b55c-c658433cef9a</guid><dc:creator>persimmon</dc:creator><description>&lt;p&gt;Hello There,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Thank you for your response.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&lt;span&gt;Why are you using mbedTLS here and how do you intend it to work?&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The code I provided is an example to show the problem, not the actual project. We cannot&amp;nbsp;not use PSA in our project, we can only use mbedTLS. Therefore, please take this problem as making calls to the mbedTLS library.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&amp;gt;&amp;gt;&lt;span&gt;So in short I think you need to revise your approach, as it cannot work the way you intend.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The problem is not me changing my approach. The problem is that you cannot make certain mbedTLS calls in the secure world of your platform.&lt;/p&gt;
&lt;p&gt;I think we agree that mbedTLS should work in both secure and in&amp;nbsp;non-secure worlds correctly.&amp;nbsp;As I mentioned it currently creates unaligned error, when accessing mutex. If you define corresponding variable as static, error is not generated. This essentially shows that the compiler creates aligned data&amp;nbsp;in data-segment, but not the stack of my code.&lt;br /&gt;&lt;br /&gt;The&amp;nbsp;RSA part that uses PSA, makes call to the same mutex, but&amp;nbsp;you don&amp;#39;t see that problem.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;PS: Apart from above, it seems to me there is a problem with SECP256K1. I investigate and get back to you.&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;P.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/327650?ContentTypeID=1</link><pubDate>Wed, 01 Sep 2021 13:55:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b02629d-3a39-4d31-baa0-a19afacbb140</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am a bit confused. Why are you using mbedTLS here and how do you intend it to work? Taking the last question first, this will not work with non-secure (ns) without using the PSA APIs and TF-M. That is because the CryptoCell peripheral used for HW acceleration only works in secure mode.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can use this example (without your modifications) in non-secure as well, using TF-M. That way, the TF-M implementation provide the PSA API to the non-secure code.&lt;/p&gt;
&lt;p&gt;Note that PSA just like mbedTLS is maintained by ARM, and you can think of PSA as a standardized crypto API that sits on top on several implementations.&lt;/p&gt;
&lt;p&gt;So in short I think you need to revise your approach, as it cannot work the way you intend. Probably what you want to do is skip all teh mbed TLS API calls and replace them with PSA calls, which can then also be used in non-secure.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/327488?ContentTypeID=1</link><pubDate>Tue, 31 Aug 2021 18:33:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b79a023-8497-4281-83df-76c6c8642933</guid><dc:creator>persimmon</dc:creator><description>&lt;p&gt;Attached, please find the code that generates fault.&amp;nbsp;&lt;br /&gt;Please also note that&amp;nbsp;secp256K1 does NOT run in cpuappNS, and that is a problem as well.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/fault_2D00_generation.zip"&gt;devzone.nordicsemi.com/.../fault_2D00_generation.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/327326?ContentTypeID=1</link><pubDate>Tue, 31 Aug 2021 06:41:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42b5f45d-cd44-4d0e-bbb7-0665acefff3c</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It is better to keep all communication to DevZone. If you want to keep your code private but still have this public case for others to refer to, then you can open a private case to share your code. We can then update this public case with any findings that are not specific to your code in the end.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/327310?ContentTypeID=1</link><pubDate>Tue, 31 Aug 2021 05:14:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb52fe26-368b-47f0-af57-42a4678a152d</guid><dc:creator>persimmon</dc:creator><description>&lt;p&gt;Hi There,&lt;br /&gt;&lt;br /&gt;Can I email them to you?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp</title><link>https://devzone.nordicsemi.com/thread/327275?ContentTypeID=1</link><pubDate>Mon, 30 Aug 2021 15:30:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a5a0aeb-c7b0-4fba-92a6-87df7160a1c0</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Can you attach your modified RSA sample so that I can attempt to reproduce on my side?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>