Merge pull request #4900 from miyazakh/esp_waituntil

Fix wait-until-done in rsa hw primitive acceleration of ESP-IDF port
This commit is contained in:
Chris Conlon
2022-03-04 17:32:06 -07:00
committed by GitHub
5 changed files with 19 additions and 16 deletions

View File

@ -54,7 +54,7 @@ static void set_time()
/* please update the time if seeing unknown failure when loading cert. */ /* please update the time if seeing unknown failure when loading cert. */
/* this could cause TLS communication failure due to time expiration */ /* this could cause TLS communication failure due to time expiration */
/* incleasing 31536000 seconds is close to spend 356 days. */ /* incleasing 31536000 seconds is close to spend 356 days. */
utctime.tv_sec = 1619650800; /* dummy time: Wed April 28 23:00:00 2021 */ utctime.tv_sec = 1645797600; /* dummy time: Fri 25 Feb 2022 02:00:00 2022 */
utctime.tv_usec = 0; utctime.tv_usec = 0;
tz.tz_minuteswest = 0; tz.tz_minuteswest = 0;
tz.tz_dsttime = 0; tz.tz_dsttime = 0;

View File

@ -51,7 +51,7 @@ static void set_time()
/* please update the time if seeing unknown failure when loading cert. */ /* please update the time if seeing unknown failure when loading cert. */
/* this could cause TLS communication failure due to time expiration */ /* this could cause TLS communication failure due to time expiration */
/* incleasing 31536000 seconds is close to spend 356 days. */ /* incleasing 31536000 seconds is close to spend 356 days. */
utctime.tv_sec = 1619650800; /* dummy time: Wed April 28 23:00:00 2021 */ utctime.tv_sec = 1645797600; /* dummy time: Fri 25 Feb 2022 02:00:00 2022 */
utctime.tv_usec = 0; utctime.tv_usec = 0;
tz.tz_minuteswest = 0; tz.tz_minuteswest = 0;
tz.tz_dsttime = 0; tz.tz_dsttime = 0;

View File

@ -99,3 +99,6 @@
/* #define NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH*/ /* #define NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH*/
/* #define NO_WOLFSSL_ESP32WROOM32_CRYPT_AES */ /* #define NO_WOLFSSL_ESP32WROOM32_CRYPT_AES */
/* #define NO_WOLFSSL_ESP32WROOM32_CRYPT_RSA_PRI */ /* #define NO_WOLFSSL_ESP32WROOM32_CRYPT_RSA_PRI */
/* adjust wait-timeout count if you see timeout in rsa hw acceleration */
#define ESP_RSA_TIMEOUT_CNT 0x249F00

View File

@ -51,6 +51,8 @@ static const char* const TAG = "wolfssl_mp";
#define MP_NG -1 #define MP_NG -1
#define ESP_TIMEOUT(cnt) (cnt >= ESP_RSA_TIMEOUT_CNT)
/* mutex */ /* mutex */
static wolfSSL_Mutex mp_mutex; static wolfSSL_Mutex mp_mutex;
static int espmp_CryptHwMutexInit = 0; static int espmp_CryptHwMutexInit = 0;
@ -59,11 +61,12 @@ static int espmp_CryptHwMutexInit = 0;
*/ */
static int esp_mp_hw_wait_clean() static int esp_mp_hw_wait_clean()
{ {
int timeout = 0; word32 timeout = 0;
while(++timeout < ESP_RSA_TIMEOUT && DPORT_REG_READ(RSA_CLEAN_REG) != 1){} while(!ESP_TIMEOUT(++timeout) &&
DPORT_REG_READ(RSA_CLEAN_REG) != 1) { }
if(timeout >= ESP_RSA_TIMEOUT) { if(ESP_TIMEOUT(timeout)) {
ESP_LOGE(TAG, "waiting hw ready is time-outed."); ESP_LOGE(TAG, "waiting hw ready is timed out.");
return MP_NG; return MP_NG;
} }
return MP_OKAY; return MP_OKAY;
@ -146,19 +149,16 @@ static void process_start(word32 reg)
/* wait until done */ /* wait until done */
static int wait_uitil_done(word32 reg) static int wait_uitil_done(word32 reg)
{ {
int timeout = 0; word32 timeout = 0;
/* wait until done && not timeout */ /* wait until done && not timeout */
while(1) { while(!ESP_TIMEOUT(++timeout) &&
if(++timeout < ESP_RSA_TIMEOUT && DPORT_REG_READ(reg) == 1){ DPORT_REG_READ(reg) != 1) { }
break;
}
}
/* clear interrupt */ /* clear interrupt */
DPORT_REG_WRITE(RSA_INTERRUPT_REG, 1); DPORT_REG_WRITE(RSA_INTERRUPT_REG, 1);
if(timeout >= ESP_RSA_TIMEOUT) { if(ESP_TIMEOUT(timeout)) {
ESP_LOGE(TAG, "rsa operation is time-outed."); ESP_LOGE(TAG, "rsa operation is timed out.");
return MP_NG; return MP_NG;
} }

View File

@ -142,8 +142,8 @@ int esp_sha_process(struct wc_Sha* sha, const byte* data);
#if !defined(NO_RSA) || defined(HAVE_ECC) #if !defined(NO_RSA) || defined(HAVE_ECC)
#ifndef ESP_RSA_TIMEOUT #if !defined(ESP_RSA_TIMEOUT_CNT)
#define ESP_RSA_TIMEOUT 0xFFFFF #define ESP_RSA_TIMEOUT_CNT 0x249F00
#endif #endif
struct fp_int; struct fp_int;