feat(esp_tee): Use CTR-DRBG for assisting random number generation in TEE

- For ESP-TEE, fault-assert in `esp_random()` if the RNG is held in a
  freeze state
This commit is contained in:
Laukik Hase
2026-09-04 10:20:20 +05:30
parent 79751671ce
commit bc6b8f7fa5
5 changed files with 110 additions and 7 deletions
+5
View File
@@ -18,6 +18,8 @@
#if !ESP_TEE_BUILD
#include "esp_private/startup_internal.h"
#else
#include "esp_fault.h"
#endif
#include "hal/rtc_timer_hal.h"
@@ -84,6 +86,9 @@ uint32_t IRAM_ATTR esp_random(void)
uint32_t result = 0;
for (size_t i = 0; i < sizeof(result); i++) {
do {
#if ESP_TEE_BUILD
ESP_FAULT_ASSERT(rng_ll_is_enabled());
#endif
ccount = esp_cpu_get_cycle_count();
result ^= rng_ll_read_data();
} while (ccount - last_ccount < cpu_to_apb_freq_ratio * APB_CYCLE_WAIT_NUM);