File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
targets/TARGET_NUVOTON/TARGET_M460/crypto Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 28
28
#include " crypto-misc.h"
29
29
#include " platform/SingletonPtr.h"
30
30
#include " platform/PlatformMutex.h"
31
+ #include " hal/trng_api.h"
31
32
32
33
/* Consideration for choosing proper synchronization mechanism
33
34
*
@@ -93,8 +94,33 @@ void crypto_init(void)
93
94
CLK_EnableModuleClock (CRPT_MODULE);
94
95
SYS_ResetModule (CRPT_RST);
95
96
SYS_LockReg (); // Lock protected register
96
-
97
+
97
98
NVIC_EnableIRQ (CRPT_IRQn);
99
+
100
+ /* Seed PRNG with TRNG to enable SCAP
101
+ *
102
+ * According to TRM, it is suggested PRNG be seeded by TRNG on
103
+ * every Crypto H/W reset.
104
+ *
105
+ * To serialize access to TRNG, we invoke Mbed OS TRNG HAL API whose
106
+ * implementations are thread-safe, instead of BSP RNG driver.
107
+ */
108
+ trng_t trng_ctx;
109
+ trng_init (&trng_ctx);
110
+
111
+ /* Wait for PRNG free */
112
+ while (CRPT->PRNG_CTL & CRPT_PRNG_CTL_BUSY_Msk);
113
+
114
+ /* Reload seed from TRNG for the first time */
115
+ CRPT->PRNG_CTL = (PRNG_KEY_SIZE_256 << CRPT_PRNG_CTL_KEYSZ_Pos) | CRPT_PRNG_CTL_START_Msk | CRPT_PRNG_CTL_SEEDRLD_Msk | PRNG_CTL_SEEDSRC_TRNG;
116
+
117
+ /* Wait for PRNG done */
118
+ while (CRPT->PRNG_CTL & CRPT_PRNG_CTL_BUSY_Msk);
119
+
120
+ /* No reload seed for following times */
121
+ CRPT->PRNG_CTL = 0 ;
122
+
123
+ trng_free (&trng_ctx);
98
124
}
99
125
core_util_critical_section_exit ();
100
126
}
You can’t perform that action at this time.
0 commit comments