<?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>nRF5340 w/ &amp;#39;Crypto: RNG&amp;#39;, true or pseudo random numbers?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/115204/nrf5340-w-crypto-rng-true-or-pseudo-random-numbers</link><description>I am working w/ the nRF5340DK, and the project mentioned here (NCS v2.5.0, nrf/samples/crypto/rng). I was able to build/flash the project. 
 I wanted to verify whether the random numbers generated are pseudo random or true random. It appears to be true</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 13 Nov 2024 09:12:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/115204/nrf5340-w-crypto-rng-true-or-pseudo-random-numbers" /><item><title>RE: nRF5340 w/ 'Crypto: RNG', true or pseudo random numbers?</title><link>https://devzone.nordicsemi.com/thread/510243?ContentTypeID=1</link><pubDate>Wed, 13 Nov 2024 09:12:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2c3229e-0430-475b-a6bd-4c5a577029e8</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Yes, TF-M uses the same crypto backend as the app&amp;nbsp;does when not using Trustzone&amp;nbsp;(&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/security/tfm.html#enabling_secure_services"&gt;Enabling secure services&lt;/a&gt;).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 w/ 'Crypto: RNG', true or pseudo random numbers?</title><link>https://devzone.nordicsemi.com/thread/510192?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2024 20:11:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02730a2b-1642-4393-8902-c82b05fcef84</guid><dc:creator>esmart-engineering</dc:creator><description>&lt;p&gt;Okay this makes sense. I went ahead and tested adding the breakpoint, and confirmed it does get called.&lt;/p&gt;
&lt;p&gt;Just to confirm, it looks like this TrustedZone call also similarly uses PRNG&amp;nbsp; seeded by TRNG, just like what the non-TrustedZone does? I saw a description of the TrustedZone call in nrfxlib/crypto/nrf_cc312_platform/include that claims &amp;quot;&lt;em&gt;This function will calculate PRNG using HW accelerated AES CTR_DRBG with a 16-byte key and reseed with TRNG using ARM CryptoCell cc3xx HW according&amp;nbsp;to a reseed interval.&lt;/em&gt;&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 w/ 'Crypto: RNG', true or pseudo random numbers?</title><link>https://devzone.nordicsemi.com/thread/510064?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2024 10:18:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21c221f6-861b-4753-963f-7f9ca35bdcdb</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;The difference when building for the *_ns target is that the crypto services are implemented in the TF-M firmware image, separating them from the app running in the Non-Secure Processing Environment. So the code will branch to the TF-M code running in the secure processing environment after&amp;nbsp;&lt;span&gt;tfm_ns_interface_dispatch().&lt;/span&gt; I should have mentioned this in my initial answer, but following the code flow from the psa_generate_random() call to nrf_cc3xx_platform_ctr_drbg_get() is more challenging when using TF-M for several reasons. For instance, psa_generate_random() does not wrap around the crypto driver, instead it calls the psa_call() function to request RNG data from TF-M via the Non-Secure Callable Interface. The stacks are also seperated.&amp;nbsp;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;If you have debug symbols loaded for the TF-M image (this happens automatically when using our VS Code extension for debugging), you can place a breakpoint at the nrf_cc3xx_platform_ctr_drbg_get() call in nrf/subsys/nrf_security/src/psa_crypto_driver_wrappers.c to confirm that it is called.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 w/ 'Crypto: RNG', true or pseudo random numbers?</title><link>https://devzone.nordicsemi.com/thread/509998?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2024 00:14:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ba68c2c-52e8-4550-873c-c63d5170fa6d</guid><dc:creator>esmart-engineering</dc:creator><description>&lt;p&gt;(OP replying) I can confirm seeing that it uses&amp;nbsp;the CC312 when building for nRF5340...But I&amp;#39;m more interested in building &lt;strong&gt;nRF5340 Non Secure (using TrustedZone and such)&lt;/strong&gt;. However, it seems to use something else for the RNG and I cannot seem to pinpoint which function, entropy source, etc. is being called. Could I get some help identifying what&amp;#39;s different when using Non Secure, and whether the numbers generated in Non Secure are pseudo or true random?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-size:75%;"&gt;I tried inspecting the .config output file (for non-secure) and noticed the following settings that seem possibly relevant:&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;
&lt;div&gt;&lt;span style="font-size:75%;"&gt;CONFIG_ENTROPY_PSA_CRYPTO_RNG=y&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size:75%;"&gt;&lt;span&gt;CONFIG_OBERON_BACKEND=y&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size:75%;"&gt;&lt;span&gt;CONFIG_MBEDTLS_HMAC_DRBG_C&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size:75%;"&gt;When I single-step w/ a debugger,&amp;nbsp;the call stack only goes as far as:&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;
&lt;div&gt;&lt;span style="font-size:75%;"&gt;tfm_ns_interface_dispatch()&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-size:75%;"&gt;this is located in the NCS v2.5.0,&amp;nbsp;&lt;span style="text-decoration:underline;"&gt;zephyr/modules/trusted-firmware-m/interface/interface.c&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size:75%;"&gt;&amp;nbsp;psa_call()&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-size:75%;"&gt;this is located in ./build/tfm/install/interface/src/tfm_psa_ns_api.c&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size:75%;"&gt;psa_generate_random()&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size:75%;"&gt;produce_rng_data()&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size:75%;"&gt;main()&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 w/ 'Crypto: RNG', true or pseudo random numbers?</title><link>https://devzone.nordicsemi.com/thread/505097?ContentTypeID=1</link><pubDate>Mon, 07 Oct 2024 06:31:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8fa43a20-b489-48a2-95b9-f6e1ac712377</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;The&amp;nbsp;output from this function is unpredictable as long as the seed generated by the TRNG is kept secret. Since generating random numbers directly with TRNGs is relatively time consuming, it is more efficient to use CTR DRBG as the random number source. The library automatically handles periodic reseeding from the TRNG. I&amp;#39;m not an expert on this subject, so I would recommend having a look at the NIST SP 800-90A paper if you want to read more about the CTR DRBG mechanism.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 w/ 'Crypto: RNG', true or pseudo random numbers?</title><link>https://devzone.nordicsemi.com/thread/505054?ContentTypeID=1</link><pubDate>Fri, 04 Oct 2024 23:32:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7761a14-5f9c-4582-892e-05e65f0dc543</guid><dc:creator>esmart-engineering</dc:creator><description>&lt;p&gt;Thank you for the info. Just to confirm, even though this function uses the PRNG (which, by itself, means pseudo random numbers are generated), the result should be a true random number because it&amp;#39;s &amp;#39;&lt;span style="text-decoration:underline;"&gt;seeded by TRNG&lt;/span&gt;&amp;#39;. Have I interpreted this correctly?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 w/ 'Crypto: RNG', true or pseudo random numbers?</title><link>https://devzone.nordicsemi.com/thread/504859?ContentTypeID=1</link><pubDate>Thu, 03 Oct 2024 14:11:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c2d62df-2cbb-4755-89cf-ee9ad14b3c27</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Yes, the RNG crypto sample uses the CC312 as the entropy source. In this sample, the psa_generate_random() function wraps around nrf_cc3xx_platform_ctr_drbg_get()&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/** @brief Function to get PRNG data using ctr_drbg
 *
 * @note  If the context is NULL the function uses an internal context.
 *
 * @details This function calculates random numbers using PRNG seeded by TRNG as
 *          defined in &amp;lt;em&amp;gt;NIST SP 800-90A: Recommendation for Random Number
 *          Generation Using Deterministic Random Bit Generators&amp;lt;/em&amp;gt;. The
 *          random numbers are generated using Arm CryptoCell cc3xx hardware
 *          acceleration.
 *
 * @note Before calling this api the context to must be initialized by calling
 *       @ref nrf_cc3xx_platform_ctr_drbg_init.
 *
 * @note This API is only usable if @ref nrf_cc3xx_platform_init was run
 *       prior to calling it.
 *
 * @param[in,out]   context     Pointer to structure holding the ctr_drbg context.
 * @param[in]       buffer      Pointer to buffer to hold PRNG data.
 * @param[in]       length      Length of PRNG to get.
 * @param[out]      olen        Length reported out.
 *
 * @return 0 on success, otherwise a non-zero failure  according to the API
 *         mbedtls_ctr_drbg_random.
 */
int nrf_cc3xx_platform_ctr_drbg_get(
    nrf_cc3xx_platform_ctr_drbg_context_t * const context,
    uint8_t *buffer,
    size_t length,
    size_t* olen);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you are unsure whether it is enabled in your application, you can check if the generated configuration file (if building without TF-M: build/zephyr/.config) contains CONFIG_ENTROPY_CC3XX=y. Another approach is to single-step through the code with a debugger.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>