|
90 | 90 | #endif |
91 | 91 |
|
92 | 92 | #ifndef ESP_RSA_EXPT_YBITS |
93 | | - #define ESP_RSA_EXPT_YBITS 8 |
| 93 | + #define ESP_RSA_EXPT_YBITS 8 |
94 | 94 | #endif |
95 | 95 |
|
96 | 96 | #define ESP_TIMEOUT(cnt) (cnt >= ESP_RSA_TIMEOUT_CNT) |
@@ -140,12 +140,14 @@ static portMUX_TYPE wc_rsa_reg_lock = portMUX_INITIALIZER_UNLOCKED; |
140 | 140 |
|
141 | 141 | /* usage metrics can be turned on independently of debugging */ |
142 | 142 | #ifdef WOLFSSL_HW_METRICS |
143 | | - static unsigned long esp_mp_max_used = 0; |
| 143 | + static unsigned long esp_mp_max_used = 0; |
144 | 144 |
|
145 | 145 | static unsigned long esp_mp_mulmod_small_x_ct = 0; |
146 | 146 | static unsigned long esp_mp_mulmod_small_y_ct = 0; |
147 | 147 |
|
148 | | -#ifndef NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL |
| 148 | + static unsigned long esp_mp_max_timeout = 0; |
| 149 | + |
| 150 | + #ifndef NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL |
149 | 151 | static unsigned long esp_mp_mul_usage_ct = 0; |
150 | 152 | static unsigned long esp_mp_mul_error_ct = 0; |
151 | 153 | #endif /* !NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_MP_MUL */ |
@@ -236,6 +238,13 @@ static int esp_mp_hw_wait_clean(void) |
236 | 238 | /* no HW timeout if we don't know the platform. assumes no HW */ |
237 | 239 | #endif |
238 | 240 |
|
| 241 | + #if defined(WOLFSSL_HW_METRICS) |
| 242 | + { |
| 243 | + esp_mp_max_timeout = (timeout > esp_mp_max_timeout) ? timeout : |
| 244 | + esp_mp_max_timeout; |
| 245 | + } |
| 246 | + #endif |
| 247 | + |
239 | 248 | if (ESP_TIMEOUT(timeout)) { |
240 | 249 | ESP_LOGE(TAG, "esp_mp_hw_wait_clean waiting HW ready timed out."); |
241 | 250 | ret = WC_HW_WAIT_E; /* hardware is busy, MP_HW_BUSY; */ |
@@ -1016,7 +1025,7 @@ int esp_mp_montgomery_init(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* M, |
1016 | 1025 | } |
1017 | 1026 | if ((X == NULL) || (Y == NULL) || (M == NULL) ) { |
1018 | 1027 | /* if a bad operand passed, we cannot use HW */ |
1019 | | - ESP_LOGE(TAG, "ERROR: Bad montgomery operand, falling back to SW"); |
| 1028 | + ESP_LOGE(TAG, "ERROR: Bad Montgomery operand, falling back to SW"); |
1020 | 1029 | return MP_HW_FALLBACK; |
1021 | 1030 | } |
1022 | 1031 | XMEMSET(mph, 0, sizeof(struct esp_mp_helper)); |
@@ -1298,7 +1307,7 @@ int esp_mp_mul(MATH_INT_T* X, MATH_INT_T* Y, MATH_INT_T* Z) |
1298 | 1307 |
|
1299 | 1308 | resultWords_sz = bits2words(Xs + Ys); |
1300 | 1309 | /* sanity check */ |
1301 | | - if((hwWords_sz << 5) > ESP_HW_MULTI_RSAMAX_BITS) { |
| 1310 | + if ( (hwWords_sz << 5) > ESP_HW_MULTI_RSAMAX_BITS) { |
1302 | 1311 | ESP_LOGW(TAG, "exceeds max bit length(2048) (a)"); |
1303 | 1312 | ret = MP_HW_FALLBACK; /* Error: value is not able to be used. */ |
1304 | 1313 | } |
@@ -3060,6 +3069,8 @@ int esp_hw_show_mp_metrics(void) |
3060 | 3069 | #endif /* EXPTMOD not disabled !NO_WOLFSSL_ESP32_CRYPT_RSA_PRI_EXPTMOD */ |
3061 | 3070 |
|
3062 | 3071 | ESP_LOGI(TAG, "Max N->used: esp_mp_max_used = %lu", esp_mp_max_used); |
| 3072 | + ESP_LOGI(TAG, "Max timeout: esp_mp_max_timeout = %lu", esp_mp_max_timeout); |
| 3073 | + |
3063 | 3074 | #else |
3064 | 3075 | /* no HW math, no HW math metrics */ |
3065 | 3076 | ret = ESP_OK; |
|
0 commit comments