Random number generator incorrectly seeded


Status: Open

First reported:

Fixed in: TBD


The random number generator for the 53x device family is seeded with values based on the RAM state during the start-up. The initialization is unconditionally done in the system_init. After a reset it will potentially initialize the random generator with a predictable seed. Consequently, the random number generation sequence is made predictable after each reset.


The workaround is to conditionally initialize the random number generator depending on whether it is already seeded or not. This is done by capturing a “magic word” which is stored in retained memory during the random number generator initialization. The code change below has to be applied in sdk/platform/arch/main/arch_system.c:

@@ -81,6 +81,9 @@
 #if defined (__DA14531__)
+#  if (USE_TRNG) //TODO
+extern uint32_t trng_state_val;
 #define DEFAULT_XTAL32M_TRIM_VALUE_QFN      (0x80)
@@ -1305,9 +1308,14 @@ void system_init(void)

 #if !defined (__NON_BLE_EXAMPLE__)
-    // Initialize random process
-    co_random_init(1);
+#if ((__DA14531__) && (USE_TRNG))
+    if (trng_state_val != 0x12348765) //TODO
+    {
+        co_random_init(1);
+    }
+#else /* for DA14585-86*/
+   co_random_init(1);
      * BLE initialization