From b554ee475cd536dbe1acb2682c8792552aa3b81a Mon Sep 17 00:00:00 2001 From: Jiang Guang Ming Date: Wed, 2 Aug 2023 17:56:02 +0800 Subject: [PATCH 1/2] feat(mbedtls): support ecp fixed-point multiplication configurable --- components/mbedtls/Kconfig | 10 ++++++++++ .../mbedtls/port/include/mbedtls/esp_config.h | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/components/mbedtls/Kconfig b/components/mbedtls/Kconfig index d0b2c3479a..58b73e09b5 100644 --- a/components/mbedtls/Kconfig +++ b/components/mbedtls/Kconfig @@ -959,6 +959,16 @@ menu "mbedTLS" Disabling this option saves some code size. + config MBEDTLS_ECP_FIXED_POINT_OPTIM + bool "Enable fixed-point multiplication optimisations" + depends on MBEDTLS_ECP_C + default y + help + This configuration option enables optimizations to speedup (about 3 ~ 4 times) the ECP + fixed point multiplication using pre-computed tables in the flash memory. + Disabling this configuration option saves flash footprint (about 29KB if all Elliptic Curve selected) + in the application binary. + # end of Elliptic Curve options config MBEDTLS_POLY1305_C diff --git a/components/mbedtls/port/include/mbedtls/esp_config.h b/components/mbedtls/port/include/mbedtls/esp_config.h index 4a7439944c..06841348b2 100644 --- a/components/mbedtls/port/include/mbedtls/esp_config.h +++ b/components/mbedtls/port/include/mbedtls/esp_config.h @@ -487,6 +487,19 @@ #undef MBEDTLS_ECP_NIST_OPTIM #endif +/** + * \def MBEDTLS_ECP_FIXED_POINT_OPTIM + * + * Enable speed up fixed-point multiplication. + * + * Comment this macro to disable FIXED POINT curves optimisation. + */ +#ifdef CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM +#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 +#else +#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 +#endif + /** * \def MBEDTLS_ECDSA_DETERMINISTIC * From 498d0125102821b1a8e06f15419b5be165b88e6d Mon Sep 17 00:00:00 2001 From: Jiang Guang Ming Date: Wed, 2 Aug 2023 21:14:13 +0800 Subject: [PATCH 2/2] docs: add new mbedtls configuration option in optimize size --- docs/en/api-guides/performance/size.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/en/api-guides/performance/size.rst b/docs/en/api-guides/performance/size.rst index 1c274bb8e1..829c73fcad 100644 --- a/docs/en/api-guides/performance/size.rst +++ b/docs/en/api-guides/performance/size.rst @@ -391,6 +391,8 @@ These include: - :ref:`CONFIG_MBEDTLS_CCM_C` - :ref:`CONFIG_MBEDTLS_GCM_C` - :ref:`CONFIG_MBEDTLS_ECP_C` (Alternatively: Leave this option enabled but disable some of the elliptic curves listed in the sub-menu.) +- :ref:`CONFIG_MBEDTLS_ECP_NIST_OPTIM` +- :ref:`CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM` - Change :ref:`CONFIG_MBEDTLS_TLS_MODE` if both server & client functionalities are not needed - Consider disabling some ciphersuites listed in the "TLS Key Exchange Methods" sub-menu (i.e. :ref:`CONFIG_MBEDTLS_KEY_EXCHANGE_RSA`)