Skip to content

Commit a7af364

Browse files
Harshal5Li HongXi
andcommitted
fix(esp_security): Power up MPI memory registers when enabling MPI
Co-authored-by: Li HongXi <[email protected]>
1 parent 33d8c05 commit a7af364

File tree

5 files changed

+10
-16
lines changed

5 files changed

+10
-16
lines changed

components/esp_security/src/esp_crypto_periph_clk.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ void esp_crypto_mpi_enable_periph_clk(bool enable)
8080
MPI_RCC_ATOMIC() {
8181
mpi_ll_enable_bus_clock(enable);
8282
if (enable) {
83+
mpi_ll_power_up();
8384
mpi_ll_reset_register();
85+
} else {
86+
mpi_ll_power_down();
8487
}
8588
}
8689
}

components/esp_security/src/esp_ds.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,14 @@ static void ds_acquire_enable(void)
253253
// We also enable SHA and HMAC here. SHA is used by HMAC, HMAC is used by DS.
254254
esp_crypto_hmac_enable_periph_clk(true);
255255
esp_crypto_sha_enable_periph_clk(true);
256+
esp_crypto_mpi_enable_periph_clk(true);
256257
esp_crypto_ds_enable_periph_clk(true);
257258
}
258259

259260
static void ds_disable_release(void)
260261
{
261262
esp_crypto_ds_enable_periph_clk(false);
263+
esp_crypto_mpi_enable_periph_clk(false);
262264
esp_crypto_sha_enable_periph_clk(false);
263265
esp_crypto_hmac_enable_periph_clk(false);
264266

components/hal/mpi_hal.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ size_t mpi_hal_calc_hardware_words(size_t words)
1515

1616
void mpi_hal_enable_hardware_hw_op(void)
1717
{
18-
mpi_ll_power_up();
1918
while (mpi_ll_check_memory_init_complete()) {
2019
}
2120
// Note: from enabling RSA clock to here takes about 1.3us
@@ -27,7 +26,7 @@ void mpi_hal_enable_hardware_hw_op(void)
2726

2827
void mpi_hal_disable_hardware_hw_op(void)
2928
{
30-
mpi_ll_power_down();
29+
3130
}
3231

3332
void mpi_hal_interrupt_enable(bool enable)

components/hal/test_apps/crypto/main/mpi/test_mpi.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -19,29 +19,21 @@
1919
#include "hal/mpi_hal.h"
2020
#include "hal/mpi_ll.h"
2121
#include "mpi_params.h"
22+
#include "esp_crypto_periph_clk.h"
2223

2324
#define _DEBUG_ 0
2425

2526
static void esp_mpi_enable_hardware_hw_op( void )
2627
{
27-
/* Enable RSA hardware */
28-
MPI_RCC_ATOMIC() {
29-
mpi_ll_enable_bus_clock(true);
30-
mpi_ll_reset_register();
31-
}
32-
28+
esp_crypto_mpi_enable_periph_clk(true);
3329
mpi_hal_enable_hardware_hw_op();
3430
}
3531

3632

3733
static void esp_mpi_disable_hardware_hw_op( void )
3834
{
3935
mpi_hal_disable_hardware_hw_op();
40-
41-
/* Disable RSA hardware */
42-
MPI_RCC_ATOMIC() {
43-
mpi_ll_enable_bus_clock(false);
44-
}
36+
esp_crypto_mpi_enable_periph_clk(false);
4537
}
4638

4739

components/mbedtls/port/bignum/bignum_alt.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ void esp_mpi_enable_hardware_hw_op( void )
2424

2525
void esp_mpi_disable_hardware_hw_op( void )
2626
{
27-
mpi_hal_disable_hardware_hw_op();
28-
2927
/* Disable RSA hardware */
3028
esp_crypto_mpi_enable_periph_clk(false);
3129

0 commit comments

Comments
 (0)