Skip to content

Commit 46cbaa7

Browse files
fix(mbedtls/ecc): Enable hardware ECC mult operations only for SOC_ECC_CONSTANT_TIME_MUL
Co-authored-by: aditya.patwardhan <[email protected]>
1 parent 49ced36 commit 46cbaa7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

components/mbedtls/port/ecc/esp_ecc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -12,6 +12,7 @@
1212
#include "ecc_impl.h"
1313
#include "hal/ecc_hal.h"
1414
#include "hal/ecc_ll.h"
15+
#include "soc/soc_caps.h"
1516

1617
static void esp_ecc_acquire_hardware(void)
1718
{
@@ -44,6 +45,14 @@ int esp_ecc_point_multiply(const ecc_point_t *point, const uint8_t *scalar, ecc_
4445

4546
ecc_hal_write_mul_param(scalar, point->x, point->y, len);
4647
ecc_hal_set_mode(work_mode);
48+
#ifdef SOC_ECC_CONSTANT_TIME_POINT_MUL
49+
/* Enable constant-time point multiplication operations for the ECC hardware accelerator
50+
This protects the ECC multiplication operation from timing attacks.
51+
This increases the time taken (by almost 50%) for some point multiplication
52+
operations performed by the ECC hardware accelerator.
53+
*/
54+
ecc_hal_enable_constant_time_point_mul(true);
55+
#endif /* SOC_ECC_CONSTANT_TIME_POINT_MUL */
4756
ecc_hal_start_calc();
4857

4958
memset(result, 0, sizeof(ecc_point_t));

0 commit comments

Comments
 (0)