From 7eb9ecb4f69123d0c2ed69595e13c486bf89c69d Mon Sep 17 00:00:00 2001 From: morris Date: Fri, 2 Apr 2021 17:03:10 +0800 Subject: [PATCH] esp_ds: move timeout mechanism to driver layer --- components/esp32c3/esp_ds.c | 13 ++++++++----- components/hal/ds_hal.c | 12 ------------ components/hal/include/hal/ds_hal.h | 5 ----- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/components/esp32c3/esp_ds.c b/components/esp32c3/esp_ds.c index e77c40531d..03b2f2fffb 100644 --- a/components/esp32c3/esp_ds.c +++ b/components/esp32c3/esp_ds.c @@ -21,9 +21,10 @@ #include "driver/periph_ctrl.h" #include "esp_crypto_lock.h" #include "hal/ds_hal.h" +#include "hal/ds_ll.h" #include "hal/hmac_hal.h" #include "esp32c3/rom/digital_signature.h" - +#include "esp_timer.h" #include "esp_ds.h" struct esp_ds_context { @@ -128,10 +129,12 @@ esp_err_t esp_ds_start_sign(const void *message, ds_hal_start(); // check encryption key from HMAC - ds_key_check_t key_check_result = ds_hal_check_decryption_key(); - if (key_check_result != DS_KEY_INPUT_OK) { - ds_disable_release(); - return ESP32C3_ERR_HW_CRYPTO_DS_INVALID_KEY; + int64_t start_time = esp_timer_get_time(); + while (ds_ll_busy() != 0) { + if ((esp_timer_get_time() - start_time) > DS_KEY_CHECK_MAX_WAIT_US) { + ds_disable_release(); + return ESP32C3_ERR_HW_CRYPTO_DS_INVALID_KEY; + } } esp_ds_context_t *context = malloc(sizeof(esp_ds_context_t)); diff --git a/components/hal/ds_hal.c b/components/hal/ds_hal.c index efd7404ae0..6a8fec9afd 100644 --- a/components/hal/ds_hal.c +++ b/components/hal/ds_hal.c @@ -26,18 +26,6 @@ void ds_hal_finish(void) ds_ll_finish(); } -ds_key_check_t ds_hal_check_decryption_key(void) -{ - uint64_t start_time = systimer_hal_get_time(SYSTIMER_COUNTER_0); - while (ds_ll_busy() != 0) { - if ((systimer_hal_get_time(SYSTIMER_COUNTER_0) - start_time) > DS_KEY_CHECK_MAX_WAIT_US) { - return ds_ll_key_error_source(); - } - } - - return DS_KEY_INPUT_OK; -} - void ds_hal_configure_iv(const uint32_t *iv) { ds_ll_configure_iv(iv); diff --git a/components/hal/include/hal/ds_hal.h b/components/hal/include/hal/ds_hal.h index fe7d7892fb..253fab9f96 100644 --- a/components/hal/include/hal/ds_hal.h +++ b/components/hal/include/hal/ds_hal.h @@ -60,11 +60,6 @@ void ds_hal_start(void); */ void ds_hal_finish(void); -/** - * @brief Check whether the key input (HMAC on ESP32-C3) is correct. - */ -ds_key_check_t ds_hal_check_decryption_key(void); - /** * @brief Write the initialization vector. */