Browse Source

fix: crypto.trng的第一个值总是相同. https://gitee.com/openLuat/LuatOS/issues/I5TOCL

Wendal Chen 3 years ago
parent
commit
dcf6070985
1 changed files with 6 additions and 4 deletions
  1. 6 4
      app/port/luat_crypto_air101.c

+ 6 - 4
app/port/luat_crypto_air101.c

@@ -9,14 +9,16 @@
 #define LUAT_LOG_TAG "crypto"
 #define LUAT_LOG_TAG "crypto"
 #include "luat_log.h"
 #include "luat_log.h"
 
 
+#include "FreeRTOS.h"
+#include "task.h"
+
 static char trng_init = 0;
 static char trng_init = 0;
 
 
 int luat_crypto_trng(char* buff, size_t len) {
 int luat_crypto_trng(char* buff, size_t len) {
-    if (trng_init == 0) {
-        trng_init = 1;
-        tls_crypto_random_init(0, CRYPTO_RNG_SWITCH_32);
-    }
+    tls_crypto_random_init(0, CRYPTO_RNG_SWITCH_32);
+    vTaskDelay(1);
     tls_crypto_random_bytes_range(buff, len, 256);
     tls_crypto_random_bytes_range(buff, len, 256);
+    tls_crypto_random_stop();
     return 0;
     return 0;
 }
 }