Random number generator incorrectly seeded

ID: LPCBARESDK-670

Status: Fixed

First reported: 6.0.14.1114

Fixed in: 6.0.20.1338

Description

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.

Workaround

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;
+#endif
 #define DEFAULT_XTAL32M_TRIM_VALUE_QFN      (0x80)
 #define DEFAULT_XTAL32M_TRIM_VALUE_WLCSP    (0x6E)
 #else
@@ -1305,9 +1308,14 @@ void system_init(void)
     periph_init();

 #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);
+#endif
     /*
      ************************************************************************************
      * BLE initialization