From 6ae3fa39f424d9d2ff0be9e3dda9f2c5ac4e8e4f Mon Sep 17 00:00:00 2001 From: Jiang Guang Ming Date: Wed, 6 May 2026 17:26:30 +0800 Subject: [PATCH 1/6] feat(mbedtls): enable ESP32-C2(Rev2.0) ROM crypto for PSA --- .../esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld | 148 ++-- components/mbedtls/CMakeLists.txt | 8 +- components/mbedtls/Kconfig | 18 +- .../port/mbedtls_rom/mbedtls_rom_osi.c | 630 +++++++----------- .../port/mbedtls_rom/mbedtls_rom_osi.h | 513 +------------- .../mbedtls_rom/mbedtls_rom_osi_bootloader.c | 29 +- 6 files changed, 357 insertions(+), 989 deletions(-) diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld index fe893c335a0..f015e92527d 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -42,7 +42,7 @@ mbedtls_mpi_div_mpi = 0x40002750; mbedtls_mpi_div_int = 0x40002754; mbedtls_mpi_mod_mpi = 0x40002758; mbedtls_mpi_mod_int = 0x4000275c; -mbedtls_mpi_exp_mod = 0x40002760; +/*mbedtls_mpi_exp_mod = 0x40002760;*/ mbedtls_mpi_fill_random = 0x40002764; mbedtls_mpi_gcd = 0x40002768; mbedtls_mpi_inv_mod = 0x4000276c; @@ -72,51 +72,51 @@ mbedtls_mpi_read_binary_le = 0x40002c20; mbedtls_mpi_write_binary_le = 0x40002c24; mbedtls_mpi_random = 0x40002c28; mbedtls_mpi_gen_prime = 0x40002c2c; -mbedtls_ecp_check_budget = 0x40002c30; -mbedtls_ecp_set_max_ops = 0x40002c34; -mbedtls_ecp_restart_is_enabled = 0x40002c38; +/*mbedtls_ecp_check_budget = 0x40002c30;*/ +/*mbedtls_ecp_set_max_ops = 0x40002c34;*/ +/*mbedtls_ecp_restart_is_enabled = 0x40002c38;*/ mbedtls_ecp_get_type = 0x40002c3c; mbedtls_ecp_curve_list = 0x40002c40; mbedtls_ecp_grp_id_list = 0x40002c44; mbedtls_ecp_curve_info_from_grp_id = 0x40002c48; mbedtls_ecp_curve_info_from_tls_id = 0x40002c4c; mbedtls_ecp_curve_info_from_name = 0x40002c50; -mbedtls_ecp_point_init = 0x40002c54; -mbedtls_ecp_group_init = 0x40002c58; -mbedtls_ecp_keypair_init = 0x40002c5c; -mbedtls_ecp_point_free = 0x40002c60; -mbedtls_ecp_group_free = 0x40002c64; -mbedtls_ecp_keypair_free = 0x40002c68; -mbedtls_ecp_restart_init = 0x40002c6c; -mbedtls_ecp_restart_free = 0x40002c70; -mbedtls_ecp_copy = 0x40002c74; -mbedtls_ecp_group_copy = 0x40002c78; -mbedtls_ecp_set_zero = 0x40002c7c; -mbedtls_ecp_is_zero = 0x40002c80; -mbedtls_ecp_point_cmp = 0x40002c84; -mbedtls_ecp_point_read_string = 0x40002c88; -mbedtls_ecp_point_write_binary = 0x40002c8c; -mbedtls_ecp_point_read_binary = 0x40002c90; -mbedtls_ecp_tls_read_point = 0x40002c94; -mbedtls_ecp_tls_write_point = 0x40002c98; -mbedtls_ecp_group_load = 0x40002c9c; -mbedtls_ecp_tls_read_group = 0x40002ca0; -mbedtls_ecp_tls_read_group_id = 0x40002ca4; -mbedtls_ecp_tls_write_group = 0x40002ca8; -mbedtls_ecp_mul = 0x40002cac; -mbedtls_ecp_mul_restartable = 0x40002cb0; -mbedtls_ecp_muladd = 0x40002cb4; -mbedtls_ecp_muladd_restartable = 0x40002cb8; -mbedtls_ecp_check_pubkey = 0x40002cbc; -mbedtls_ecp_check_privkey = 0x40002cc0; -mbedtls_ecp_gen_privkey = 0x40002cc4; -mbedtls_ecp_gen_keypair_base = 0x40002cc8; -mbedtls_ecp_gen_keypair = 0x40002ccc; -mbedtls_ecp_gen_key = 0x40002cd0; -mbedtls_ecp_read_key = 0x40002cd4; -mbedtls_ecp_write_key_ext = 0x40002cd8; -mbedtls_ecp_check_pub_priv = 0x40002cdc; -mbedtls_ecp_export = 0x40002ce0; +/*mbedtls_ecp_point_init = 0x40002c54;*/ +/*mbedtls_ecp_group_init = 0x40002c58;*/ +/*mbedtls_ecp_keypair_init = 0x40002c5c;*/ +/*mbedtls_ecp_point_free = 0x40002c60;*/ +/*mbedtls_ecp_group_free = 0x40002c64;*/ +/*mbedtls_ecp_keypair_free = 0x40002c68;*/ +/*mbedtls_ecp_restart_init = 0x40002c6c;*/ +/*mbedtls_ecp_restart_free = 0x40002c70;*/ +/*mbedtls_ecp_copy = 0x40002c74;*/ +/*mbedtls_ecp_group_copy = 0x40002c78;*/ +/*mbedtls_ecp_set_zero = 0x40002c7c;*/ +/*mbedtls_ecp_is_zero = 0x40002c80;*/ +/*mbedtls_ecp_point_cmp = 0x40002c84;*/ +/*mbedtls_ecp_point_read_string = 0x40002c88;*/ +/*mbedtls_ecp_point_write_binary = 0x40002c8c;*/ +/*mbedtls_ecp_point_read_binary = 0x40002c90;*/ +/*mbedtls_ecp_tls_read_point = 0x40002c94;*/ +/*mbedtls_ecp_tls_write_point = 0x40002c98;*/ +/*mbedtls_ecp_group_load = 0x40002c9c;*/ +/*mbedtls_ecp_tls_read_group = 0x40002ca0;*/ +/*mbedtls_ecp_tls_read_group_id = 0x40002ca4;*/ +/*mbedtls_ecp_tls_write_group = 0x40002ca8;*/ +/*mbedtls_ecp_mul = 0x40002cac;*/ +/*mbedtls_ecp_mul_restartable = 0x40002cb0;*/ +/*mbedtls_ecp_muladd = 0x40002cb4;*/ +/*mbedtls_ecp_muladd_restartable = 0x40002cb8;*/ +/*mbedtls_ecp_check_pubkey = 0x40002cbc;*/ +/*mbedtls_ecp_check_privkey = 0x40002cc0;*/ +/*mbedtls_ecp_gen_privkey = 0x40002cc4;*/ +/*mbedtls_ecp_gen_keypair_base = 0x40002cc8;*/ +/*mbedtls_ecp_gen_keypair = 0x40002ccc;*/ +/*mbedtls_ecp_gen_key = 0x40002cd0;*/ +/*mbedtls_ecp_read_key = 0x40002cd4;*/ +/*mbedtls_ecp_write_key_ext = 0x40002cd8;*/ +/*mbedtls_ecp_check_pub_priv = 0x40002cdc;*/ +/*mbedtls_ecp_export = 0x40002ce0;*/ mbedtls_asn1_get_enum = 0x40002ce4; mbedtls_asn1_sequence_free = 0x40002ce8; mbedtls_asn1_traverse_sequence_of = 0x40002cec; @@ -166,39 +166,39 @@ mbedtls_ctr_drbg_set_nonce_len = 0x40002d98; mbedtls_ctr_drbg_set_reseed_interval = 0x40002d9c; mbedtls_ctr_drbg_update = 0x40002da0; mbedtls_base64_encode = 0x40002da4; -mbedtls_rsa_init = 0x40002da8; -mbedtls_rsa_set_padding = 0x40002dac; -mbedtls_rsa_get_padding_mode = 0x40002db0; -mbedtls_rsa_get_md_alg = 0x40002db4; -mbedtls_rsa_import = 0x40002db8; -mbedtls_rsa_import_raw = 0x40002dbc; -mbedtls_rsa_complete = 0x40002dc0; -mbedtls_rsa_export = 0x40002dc4; -mbedtls_rsa_export_raw = 0x40002dc8; -mbedtls_rsa_export_crt = 0x40002dcc; -mbedtls_rsa_get_len = 0x40002dd0; -mbedtls_rsa_gen_key = 0x40002dd4; -mbedtls_rsa_check_pubkey = 0x40002dd8; -mbedtls_rsa_check_privkey = 0x40002ddc; -mbedtls_rsa_check_pub_priv = 0x40002de0; -mbedtls_rsa_public = 0x40002de4; -mbedtls_rsa_private = 0x40002de8; -mbedtls_rsa_pkcs1_encrypt = 0x40002dec; -mbedtls_rsa_rsaes_pkcs1_v15_encrypt = 0x40002df0; -mbedtls_rsa_rsaes_oaep_encrypt = 0x40002df4; -mbedtls_rsa_pkcs1_decrypt = 0x40002df8; -mbedtls_rsa_rsaes_pkcs1_v15_decrypt = 0x40002dfc; -mbedtls_rsa_rsaes_oaep_decrypt = 0x40002e00; -mbedtls_rsa_pkcs1_sign = 0x40002e04; -mbedtls_rsa_rsassa_pkcs1_v15_sign = 0x40002e08; -mbedtls_rsa_rsassa_pss_sign_ext = 0x40002e0c; -mbedtls_rsa_rsassa_pss_sign = 0x40002e10; -mbedtls_rsa_pkcs1_verify = 0x40002e14; -mbedtls_rsa_rsassa_pkcs1_v15_verify = 0x40002e18; -mbedtls_rsa_rsassa_pss_verify = 0x40002e1c; -mbedtls_rsa_rsassa_pss_verify_ext = 0x40002e20; -mbedtls_rsa_copy = 0x40002e24; -mbedtls_rsa_free = 0x40002e28; +/*mbedtls_rsa_init = 0x40002da8;*/ +/*mbedtls_rsa_set_padding = 0x40002dac;*/ +/*mbedtls_rsa_get_padding_mode = 0x40002db0;*/ +/*mbedtls_rsa_get_md_alg = 0x40002db4;*/ +/*mbedtls_rsa_import = 0x40002db8;*/ +/*mbedtls_rsa_import_raw = 0x40002dbc;*/ +/*mbedtls_rsa_complete = 0x40002dc0;*/ +/*mbedtls_rsa_export = 0x40002dc4;*/ +/*mbedtls_rsa_export_raw = 0x40002dc8;*/ +/*mbedtls_rsa_export_crt = 0x40002dcc;*/ +/*mbedtls_rsa_get_len = 0x40002dd0;*/ +/*mbedtls_rsa_gen_key = 0x40002dd4;*/ +/*mbedtls_rsa_check_pubkey = 0x40002dd8;*/ +/*mbedtls_rsa_check_privkey = 0x40002ddc;*/ +/*mbedtls_rsa_check_pub_priv = 0x40002de0;*/ +/*mbedtls_rsa_public = 0x40002de4;*/ +/*mbedtls_rsa_private = 0x40002de8;*/ +/*mbedtls_rsa_pkcs1_encrypt = 0x40002dec;*/ +/*mbedtls_rsa_rsaes_pkcs1_v15_encrypt = 0x40002df0;*/ +/*mbedtls_rsa_rsaes_oaep_encrypt = 0x40002df4;*/ +/*mbedtls_rsa_pkcs1_decrypt = 0x40002df8;*/ +/*mbedtls_rsa_rsaes_pkcs1_v15_decrypt = 0x40002dfc;*/ +/*mbedtls_rsa_rsaes_oaep_decrypt = 0x40002e00;*/ +/*mbedtls_rsa_pkcs1_sign = 0x40002e04;*/ +/*mbedtls_rsa_rsassa_pkcs1_v15_sign = 0x40002e08;*/ +/*mbedtls_rsa_rsassa_pss_sign_ext = 0x40002e0c;*/ +/*mbedtls_rsa_rsassa_pss_sign = 0x40002e10;*/ +/*mbedtls_rsa_pkcs1_verify = 0x40002e14;*/ +/*mbedtls_rsa_rsassa_pkcs1_v15_verify = 0x40002e18;*/ +/*mbedtls_rsa_rsassa_pss_verify = 0x40002e1c;*/ +/*mbedtls_rsa_rsassa_pss_verify_ext = 0x40002e20;*/ +/*mbedtls_rsa_copy = 0x40002e24;*/ +/*mbedtls_rsa_free = 0x40002e28;*/ mbedtls_ecdh_can_do = 0x40002e2c; mbedtls_ecdh_gen_public = 0x40002e30; mbedtls_ecdh_compute_shared = 0x40002e34; diff --git a/components/mbedtls/CMakeLists.txt b/components/mbedtls/CMakeLists.txt index 6d5c314338e..e3f64f019f7 100644 --- a/components/mbedtls/CMakeLists.txt +++ b/components/mbedtls/CMakeLists.txt @@ -458,10 +458,10 @@ if(CONFIG_MBEDTLS_HARDWARE_ECDSA_SIGN OR CONFIG_MBEDTLS_HARDWARE_ECDSA_VERIFY OR endif() endif() -# if(CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL) -# target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/mbedtls_rom/mbedtls_rom_osi.c") -# target_link_libraries(${COMPONENT_LIB} PRIVATE "-u mbedtls_rom_osi_functions_init") -# endif() +if(CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL) + target_sources(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/mbedtls_rom/mbedtls_rom_osi.c") + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u mbedtls_rom_osi_functions_init") +endif() if(CONFIG_COMPILER_STATIC_ANALYZER AND CMAKE_C_COMPILER_ID STREQUAL "GNU") target_compile_options(${COMPONENT_LIB} PRIVATE "-fno-analyzer") diff --git a/components/mbedtls/Kconfig b/components/mbedtls/Kconfig index 76084d006df..255d4581c90 100644 --- a/components/mbedtls/Kconfig +++ b/components/mbedtls/Kconfig @@ -1613,8 +1613,7 @@ menu "mbedTLS" config MBEDTLS_USE_CRYPTO_ROM_IMPL bool "Use ROM implementation of the crypto algorithm" - # TODO: IDF-15012 - depends on ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB && !MBEDTLS_VER_4_X_SUPPORT + depends on ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB default "n" select MBEDTLS_SHA512_C select MBEDTLS_AES_C @@ -1628,12 +1627,11 @@ menu "mbedTLS" Enable this flag to use mbedtls crypto algorithm from ROM instead of ESP-IDF. This configuration option saves flash footprint in the application binary. - Note that the version of mbedtls crypto algorithm library in ROM(ECO1~ECO3) is v2.16.12, - and the version of mbedtls crypto algorithm library in ROM(ECO4) is v3.6.0. - We have done the security analysis of the mbedtls revision in ROM (ECO1~ECO4) - and ensured that affected symbols have been patched (removed). If in the future - mbedtls revisions there are security issues that also affects the version in - ROM (ECO1~ECO4) then we shall patch the relevant symbols. This would increase - the flash footprint and hence care must be taken to keep some reserved space - for the application binary in flash layout. + It is available for ESP32-C2 rev2.0 and later, where the ECO4 ROM contains + the mbedtls crypto algorithm library v3.6.0. + We have done the security analysis of the mbedtls revision in ROM and ensured + that affected symbols have been patched (removed). If future mbedtls revisions + include security issues that also affect the version in ROM, then we shall patch + the relevant symbols. This would increase the flash footprint and hence care must + be taken to keep some reserved space for the application binary in flash layout. endmenu # mbedTLS diff --git a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.c b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.c index d29d03e966d..c345cf5bef0 100644 --- a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.c +++ b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,13 +10,42 @@ #include MBEDTLS_CONFIG_FILE #endif -#include "soc/chip_revision.h" -#include "hal/efuse_hal.h" #include "mbedtls/platform.h" #include "mbedtls_rom_osi.h" +#ifndef MBEDTLS_ERR_THREADING_BAD_INPUT_DATA +#define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA MBEDTLS_ERR_THREADING_USAGE_ERROR +#endif + +_Static_assert(sizeof(mbedtls_rom_eco4_funcs_t) == 221 * sizeof(void (*)(void)), + "mbedtls_rom_eco4_funcs_t layout must match ROM"); + +#define ROM_TABLE_FN(table_type, field, fn) ((__typeof__(((table_type *)0)->field))(fn)) + void mbedtls_rom_osi_functions_init(void); +extern void mbedtls_internal_sha1_process(void) __attribute__((weak)); +extern void mbedtls_internal_sha256_process(void) __attribute__((weak)); +extern void mbedtls_internal_sha512_process(void) __attribute__((weak)); +extern void mbedtls_internal_aes_encrypt(void) __attribute__((weak)); +extern void mbedtls_internal_aes_decrypt(void) __attribute__((weak)); +extern int mbedtls_sha1_update(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen) __attribute__((weak)); +extern int mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen) __attribute__((weak)); +extern void mbedtls_oid_get_cipher_alg(void) __attribute__((weak)); +extern void mbedtls_oid_get_ec_grp(void) __attribute__((weak)); +extern void mbedtls_oid_get_md_alg(void) __attribute__((weak)); +extern void mbedtls_oid_get_md_hmac(void) __attribute__((weak)); +extern void mbedtls_oid_get_oid_by_md(void) __attribute__((weak)); +extern void mbedtls_oid_get_pk_alg(void) __attribute__((weak)); +extern void mbedtls_oid_get_pkcs12_pbe_alg(void) __attribute__((weak)); +extern void mbedtls_oid_get_sig_alg(void) __attribute__((weak)); +extern void mbedtls_oid_get_x509_ext_type(void) __attribute__((weak)); + +extern void rom_mbedtls_threading_set_alt(void (*mutex_init)(mbedtls_threading_mutex_t *), + void (*mutex_free)(mbedtls_threading_mutex_t *), + int (*mutex_lock)(mbedtls_threading_mutex_t *), + int (*mutex_unlock)(mbedtls_threading_mutex_t *)); + static void mbedtls_rom_mutex_init( mbedtls_threading_mutex_t *mutex ) { if (mutex == NULL) { @@ -76,370 +105,228 @@ static int mbedtls_rom_mutex_unlock( mbedtls_threading_mutex_t *mutex ) #endif } -/* This structure can be automatically generated by the script with rom.mbedtls.ld. */ -static const mbedtls_rom_funcs_t mbedtls_rom_funcs_table = { - /* Fill the ROM functions into mbedtls rom function table. */ - /* aes module */ - ._rom_mbedtls_aes_init = mbedtls_aes_init, - ._rom_mbedtls_aes_free = mbedtls_aes_free, - ._rom_mbedtls_aes_setkey_enc = mbedtls_aes_setkey_enc, - ._rom_mbedtls_aes_setkey_dec = mbedtls_aes_setkey_dec, - ._rom_mbedtls_aes_crypt_ecb = mbedtls_aes_crypt_ecb, - ._rom_mbedtls_aes_crypt_cbc = mbedtls_aes_crypt_cbc, - ._rom_mbedtls_internal_aes_encrypt = mbedtls_internal_aes_encrypt, - ._rom_mbedtls_internal_aes_decrypt = mbedtls_internal_aes_decrypt, - /* asn1 module */ - ._rom_mbedtls_asn1_get_len = mbedtls_asn1_get_len, - ._rom_mbedtls_asn1_get_tag = mbedtls_asn1_get_tag, - ._rom_mbedtls_asn1_get_bool = mbedtls_asn1_get_bool, - ._rom_mbedtls_asn1_get_int = mbedtls_asn1_get_int, - ._rom_mbedtls_asn1_get_bitstring = mbedtls_asn1_get_bitstring, - ._rom_mbedtls_asn1_get_bitstring_null = mbedtls_asn1_get_bitstring_null, - ._rom_mbedtls_asn1_get_sequence_of = mbedtls_asn1_get_sequence_of, - ._rom_mbedtls_asn1_get_mpi = mbedtls_asn1_get_mpi, - ._rom_mbedtls_asn1_get_alg = mbedtls_asn1_get_alg, - ._rom_mbedtls_asn1_get_alg_null = mbedtls_asn1_get_alg_null, - ._rom_mbedtls_asn1_write_len = mbedtls_asn1_write_len, - ._rom_mbedtls_asn1_write_tag = mbedtls_asn1_write_tag, - ._rom_mbedtls_asn1_write_mpi = mbedtls_asn1_write_mpi, - /* base64 module */ - ._rom_mbedtls_base64_decode = mbedtls_base64_decode, - /* bignum module */ - ._rom_mbedtls_mpi_init = mbedtls_mpi_init, - ._rom_mbedtls_mpi_free = mbedtls_mpi_free, - ._rom_mbedtls_mpi_grow = mbedtls_mpi_grow, - ._rom_mbedtls_mpi_shrink = mbedtls_mpi_shrink, - ._rom_mbedtls_mpi_copy = mbedtls_mpi_copy, - ._rom_mbedtls_mpi_safe_cond_assign = mbedtls_mpi_safe_cond_assign, - ._rom_mbedtls_mpi_safe_cond_swap = mbedtls_mpi_safe_cond_swap, - ._rom_mbedtls_mpi_lset = mbedtls_mpi_lset, - ._rom_mbedtls_mpi_get_bit = mbedtls_mpi_get_bit, - ._rom_mbedtls_mpi_set_bit = mbedtls_mpi_set_bit, - ._rom_mbedtls_mpi_lsb = mbedtls_mpi_lsb, - ._rom_mbedtls_mpi_bitlen = mbedtls_mpi_bitlen, - ._rom_mbedtls_mpi_size = mbedtls_mpi_size, - ._rom_mbedtls_mpi_read_binary = mbedtls_mpi_read_binary, - ._rom_mbedtls_mpi_write_binary = mbedtls_mpi_write_binary, - ._rom_mbedtls_mpi_shift_l = mbedtls_mpi_shift_l, - ._rom_mbedtls_mpi_shift_r = mbedtls_mpi_shift_r, - ._rom_mbedtls_mpi_cmp_abs = mbedtls_mpi_cmp_abs, - ._rom_mbedtls_mpi_cmp_mpi = mbedtls_mpi_cmp_mpi, - ._rom_mbedtls_mpi_lt_mpi_ct = mbedtls_mpi_lt_mpi_ct, - ._rom_mbedtls_mpi_cmp_int = mbedtls_mpi_cmp_int, - ._rom_mbedtls_mpi_add_abs = mbedtls_mpi_add_abs, - ._rom_mbedtls_mpi_sub_abs = mbedtls_mpi_sub_abs, - ._rom_mbedtls_mpi_add_mpi = mbedtls_mpi_add_mpi, - ._rom_mbedtls_mpi_sub_mpi = mbedtls_mpi_sub_mpi, - ._rom_mbedtls_mpi_add_int = mbedtls_mpi_add_int, - ._rom_mbedtls_mpi_sub_int = mbedtls_mpi_sub_int, - ._rom_mbedtls_mpi_mul_mpi = mbedtls_mpi_mul_mpi, - ._rom_mbedtls_mpi_mul_int = mbedtls_mpi_mul_int, - ._rom_mbedtls_mpi_div_mpi = mbedtls_mpi_div_mpi, - ._rom_mbedtls_mpi_div_int = mbedtls_mpi_div_int, - ._rom_mbedtls_mpi_mod_mpi = mbedtls_mpi_mod_mpi, - ._rom_mbedtls_mpi_mod_int = mbedtls_mpi_mod_int, - ._rom_mbedtls_mpi_exp_mod = mbedtls_mpi_exp_mod, - ._rom_mbedtls_mpi_fill_random = mbedtls_mpi_fill_random, - ._rom_mbedtls_mpi_gcd = mbedtls_mpi_gcd, - ._rom_mbedtls_mpi_inv_mod = mbedtls_mpi_inv_mod, - ._rom_mbedtls_mpi_is_prime_ext = mbedtls_mpi_is_prime_ext, - /* ccm module */ - ._rom_mbedtls_ccm_star_encrypt_and_tag = mbedtls_ccm_star_encrypt_and_tag, - ._rom_mbedtls_ccm_star_auth_decrypt = mbedtls_ccm_star_auth_decrypt, - /* cipher module */ - ._rom_mbedtls_cipher_init = mbedtls_cipher_init, - ._rom_mbedtls_cipher_set_padding_mode = mbedtls_cipher_set_padding_mode, - ._rom_mbedtls_cipher_reset = mbedtls_cipher_reset, - ._rom_mbedtls_cipher_finish = mbedtls_cipher_finish, - ._rom_mbedtls_cipher_crypt = mbedtls_cipher_crypt, - ._rom_mbedtls_cipher_cmac_starts = mbedtls_cipher_cmac_starts, - ._rom_mbedtls_cipher_cmac_update = mbedtls_cipher_cmac_update, - ._rom_mbedtls_cipher_cmac_finish = mbedtls_cipher_cmac_finish, - /* ctr drbg module */ - ._rom_mbedtls_ctr_drbg_init = mbedtls_ctr_drbg_init, - ._rom_mbedtls_ctr_drbg_seed = mbedtls_ctr_drbg_seed, - ._rom_mbedtls_ctr_drbg_free = mbedtls_ctr_drbg_free, - ._rom_mbedtls_ctr_drbg_reseed = mbedtls_ctr_drbg_reseed, - ._rom_mbedtls_ctr_drbg_random_with_add = mbedtls_ctr_drbg_random_with_add, - ._rom_mbedtls_ctr_drbg_random = mbedtls_ctr_drbg_random, - /* sha1 module */ - ._rom_mbedtls_sha1_init = mbedtls_sha1_init, - ._rom_mbedtls_sha1_free = mbedtls_sha1_free, - ._rom_mbedtls_sha1_clone = mbedtls_sha1_clone, - ._rom_mbedtls_sha1_starts = mbedtls_sha1_starts, - ._rom_mbedtls_sha1_finish = mbedtls_sha1_finish, - /* sha256 module */ - ._rom_mbedtls_sha256_init = mbedtls_sha256_init, - ._rom_mbedtls_sha256_free = mbedtls_sha256_free, - ._rom_mbedtls_sha256_clone = mbedtls_sha256_clone, - ._rom_mbedtls_sha256_starts = mbedtls_sha256_starts, - ._rom_mbedtls_sha256_finish = mbedtls_sha256_finish, - ._rom_mbedtls_sha256 = mbedtls_sha256, - /* sha512 module */ - ._rom_mbedtls_sha512_init = mbedtls_sha512_init, - ._rom_mbedtls_sha512_free = mbedtls_sha512_free, - ._rom_mbedtls_sha512_clone = mbedtls_sha512_clone, - ._rom_mbedtls_sha512_starts = mbedtls_sha512_starts, - ._rom_mbedtls_sha512_update = mbedtls_sha512_update, - ._rom_mbedtls_sha512_finish = mbedtls_sha512_finish, - ._rom_mbedtls_internal_sha512_process = mbedtls_internal_sha512_process, - ._rom_mbedtls_sha512 = mbedtls_sha512, - - /* Fill the platform functions into mbedtls rom function table. */ - ._mbedtls_mutex_init = mbedtls_rom_mutex_init, - ._mbedtls_mutex_free = mbedtls_rom_mutex_free, - ._mbedtls_mutex_lock = mbedtls_rom_mutex_lock, - ._mbedtls_mutex_unlock = mbedtls_rom_mutex_unlock, - ._mbedtls_calloc = MBEDTLS_PLATFORM_STD_CALLOC, - ._mbedtls_free = MBEDTLS_PLATFORM_STD_FREE, - - /* Fill the SHA functions into mbedtls rom function table, since these functions are not exported in the ROM interface. */ - ._mbedtls_sha1_update = mbedtls_sha1_update, - ._mbedtls_internal_sha1_process = mbedtls_internal_sha1_process, - ._mbedtls_sha256_update = mbedtls_sha256_update, - ._mbedtls_internal_sha256_process = mbedtls_internal_sha256_process, -}; - /* This structure can be automatically generated by the script with rom.mbedtls.ld. */ static const mbedtls_rom_eco4_funcs_t mbedtls_rom_eco4_funcs_table = { /* Fill the ROM functions into mbedtls rom function table. */ - /* aes module */ - ._rom_mbedtls_aes_init = mbedtls_aes_init, - ._rom_mbedtls_aes_free = mbedtls_aes_free, - ._rom_mbedtls_aes_setkey_enc = mbedtls_aes_setkey_enc, - ._rom_mbedtls_aes_setkey_dec = mbedtls_aes_setkey_dec, - ._rom_mbedtls_aes_crypt_ecb = mbedtls_aes_crypt_ecb, - ._rom_mbedtls_aes_crypt_cbc = mbedtls_aes_crypt_cbc, - ._rom_mbedtls_internal_aes_encrypt = mbedtls_internal_aes_encrypt, - ._rom_mbedtls_internal_aes_decrypt = mbedtls_internal_aes_decrypt, - /* asn1 module */ - ._rom_mbedtls_asn1_get_len = mbedtls_asn1_get_len, - ._rom_mbedtls_asn1_get_tag = mbedtls_asn1_get_tag, - ._rom_mbedtls_asn1_get_bool = mbedtls_asn1_get_bool, - ._rom_mbedtls_asn1_get_int = mbedtls_asn1_get_int, - ._rom_mbedtls_asn1_get_bitstring = mbedtls_asn1_get_bitstring, - ._rom_mbedtls_asn1_get_bitstring_null = mbedtls_asn1_get_bitstring_null, - ._rom_mbedtls_asn1_get_sequence_of = mbedtls_asn1_get_sequence_of, - ._rom_mbedtls_asn1_get_mpi = mbedtls_asn1_get_mpi, - ._rom_mbedtls_asn1_get_alg = mbedtls_asn1_get_alg, - ._rom_mbedtls_asn1_get_alg_null = mbedtls_asn1_get_alg_null, - ._rom_mbedtls_asn1_write_len = mbedtls_asn1_write_len, - ._rom_mbedtls_asn1_write_tag = mbedtls_asn1_write_tag, - ._rom_mbedtls_asn1_write_mpi = mbedtls_asn1_write_mpi, - /* base64 module */ - ._rom_mbedtls_base64_decode = mbedtls_base64_decode, - /* bignum module */ - ._rom_mbedtls_mpi_init = mbedtls_mpi_init, - ._rom_mbedtls_mpi_free = mbedtls_mpi_free, - ._rom_mbedtls_mpi_grow = mbedtls_mpi_grow, - ._rom_mbedtls_mpi_shrink = mbedtls_mpi_shrink, - ._rom_mbedtls_mpi_copy = mbedtls_mpi_copy, - ._rom_mbedtls_mpi_safe_cond_assign = mbedtls_mpi_safe_cond_assign, - ._rom_mbedtls_mpi_safe_cond_swap = mbedtls_mpi_safe_cond_swap, - ._rom_mbedtls_mpi_lset = mbedtls_mpi_lset, - ._rom_mbedtls_mpi_get_bit = mbedtls_mpi_get_bit, - ._rom_mbedtls_mpi_set_bit = mbedtls_mpi_set_bit, - ._rom_mbedtls_mpi_lsb = mbedtls_mpi_lsb, - ._rom_mbedtls_mpi_bitlen = mbedtls_mpi_bitlen, - ._rom_mbedtls_mpi_size = mbedtls_mpi_size, - ._rom_mbedtls_mpi_read_binary = mbedtls_mpi_read_binary, - ._rom_mbedtls_mpi_write_binary = mbedtls_mpi_write_binary, - ._rom_mbedtls_mpi_shift_l = mbedtls_mpi_shift_l, - ._rom_mbedtls_mpi_shift_r = mbedtls_mpi_shift_r, - ._rom_mbedtls_mpi_cmp_abs = mbedtls_mpi_cmp_abs, - ._rom_mbedtls_mpi_cmp_mpi = mbedtls_mpi_cmp_mpi, - ._rom_mbedtls_mpi_lt_mpi_ct = mbedtls_mpi_lt_mpi_ct, - ._rom_mbedtls_mpi_cmp_int = mbedtls_mpi_cmp_int, - ._rom_mbedtls_mpi_add_abs = mbedtls_mpi_add_abs, - ._rom_mbedtls_mpi_sub_abs = mbedtls_mpi_sub_abs, - ._rom_mbedtls_mpi_add_mpi = mbedtls_mpi_add_mpi, - ._rom_mbedtls_mpi_sub_mpi = mbedtls_mpi_sub_mpi, - ._rom_mbedtls_mpi_add_int = mbedtls_mpi_add_int, - ._rom_mbedtls_mpi_sub_int = mbedtls_mpi_sub_int, - ._rom_mbedtls_mpi_mul_mpi = mbedtls_mpi_mul_mpi, - ._rom_mbedtls_mpi_mul_int = mbedtls_mpi_mul_int, - ._rom_mbedtls_mpi_div_mpi = mbedtls_mpi_div_mpi, - ._rom_mbedtls_mpi_div_int = mbedtls_mpi_div_int, - ._rom_mbedtls_mpi_mod_mpi = mbedtls_mpi_mod_mpi, - ._rom_mbedtls_mpi_mod_int = mbedtls_mpi_mod_int, - ._rom_mbedtls_mpi_exp_mod = mbedtls_mpi_exp_mod, - ._rom_mbedtls_mpi_fill_random = mbedtls_mpi_fill_random, - ._rom_mbedtls_mpi_gcd = mbedtls_mpi_gcd, - ._rom_mbedtls_mpi_inv_mod = mbedtls_mpi_inv_mod, - ._rom_mbedtls_mpi_is_prime_ext = mbedtls_mpi_is_prime_ext, - /* ccm module */ - ._rom_mbedtls_ccm_star_encrypt_and_tag = mbedtls_ccm_star_encrypt_and_tag, - ._rom_mbedtls_ccm_star_auth_decrypt = mbedtls_ccm_star_auth_decrypt, - /* cipher module */ - ._rom_mbedtls_cipher_init = mbedtls_cipher_init, - ._rom_mbedtls_cipher_set_padding_mode = mbedtls_cipher_set_padding_mode, - ._rom_mbedtls_cipher_reset = mbedtls_cipher_reset, - ._rom_mbedtls_cipher_finish = mbedtls_cipher_finish, - ._rom_mbedtls_cipher_crypt = mbedtls_cipher_crypt, - ._rom_mbedtls_cipher_cmac_starts = mbedtls_cipher_cmac_starts, - ._rom_mbedtls_cipher_cmac_update = mbedtls_cipher_cmac_update, - ._rom_mbedtls_cipher_cmac_finish = mbedtls_cipher_cmac_finish, - /* ctr drbg module */ - ._rom_mbedtls_ctr_drbg_init = mbedtls_ctr_drbg_init, - ._rom_mbedtls_ctr_drbg_seed = mbedtls_ctr_drbg_seed, - ._rom_mbedtls_ctr_drbg_free = mbedtls_ctr_drbg_free, - ._rom_mbedtls_ctr_drbg_reseed = mbedtls_ctr_drbg_reseed, - ._rom_mbedtls_ctr_drbg_random_with_add = mbedtls_ctr_drbg_random_with_add, - ._rom_mbedtls_ctr_drbg_random = mbedtls_ctr_drbg_random, - /* sha1 module */ - ._rom_mbedtls_sha1_init = mbedtls_sha1_init, - ._rom_mbedtls_sha1_free = mbedtls_sha1_free, - ._rom_mbedtls_sha1_clone = mbedtls_sha1_clone, - ._rom_mbedtls_sha1_starts = mbedtls_sha1_starts, - ._rom_mbedtls_sha1_finish = mbedtls_sha1_finish, - /* sha256 module */ - ._rom_mbedtls_sha256_init = mbedtls_sha256_init, - ._rom_mbedtls_sha256_free = mbedtls_sha256_free, - ._rom_mbedtls_sha256_clone = mbedtls_sha256_clone, - ._rom_mbedtls_sha256_starts = mbedtls_sha256_starts, - ._rom_mbedtls_sha256_finish = mbedtls_sha256_finish, - ._rom_mbedtls_sha256 = mbedtls_sha256, - /* sha512 module */ - ._rom_mbedtls_sha512_init = mbedtls_sha512_init, - ._rom_mbedtls_sha512_free = mbedtls_sha512_free, - ._rom_mbedtls_sha512_clone = mbedtls_sha512_clone, - ._rom_mbedtls_sha512_starts = mbedtls_sha512_starts, - ._rom_mbedtls_sha512_update = mbedtls_sha512_update, - ._rom_mbedtls_sha512_finish = mbedtls_sha512_finish, - //._rom_mbedtls_internal_sha512_process = mbedtls_internal_sha512_process, - ._rom_mbedtls_sha512 = mbedtls_sha512, - - ._rom_mbedtls_aes_xts_init = mbedtls_aes_xts_init, - ._rom_mbedtls_aes_xts_free = mbedtls_aes_xts_free, - ._rom_mbedtls_aes_xts_setkey_enc = mbedtls_aes_xts_setkey_enc, - ._rom_mbedtls_aes_xts_setkey_dec = mbedtls_aes_xts_setkey_dec, - ._rom_mbedtls_aes_crypt_xts = mbedtls_aes_crypt_xts, - ._rom_mbedtls_aes_crypt_cfb128 = mbedtls_aes_crypt_cfb128, - ._rom_mbedtls_aes_crypt_ofb = mbedtls_aes_crypt_ofb, - ._rom_mbedtls_aes_crypt_ctr = mbedtls_aes_crypt_ctr, - ._rom_mbedtls_ccm_init = mbedtls_ccm_init, - ._rom_mbedtls_ccm_setkey = mbedtls_ccm_setkey, - ._rom_mbedtls_ccm_free = mbedtls_ccm_free, - ._rom_mbedtls_ccm_encrypt_and_tag = mbedtls_ccm_encrypt_and_tag, - ._rom_mbedtls_ccm_auth_decrypt = mbedtls_ccm_auth_decrypt, - ._rom_mbedtls_md5_init = mbedtls_md5_init, - ._rom_mbedtls_md5_free = mbedtls_md5_free, - ._rom_mbedtls_md5_clone = mbedtls_md5_clone, - ._rom_mbedtls_md5_starts = mbedtls_md5_starts, - ._rom_mbedtls_md5_update = mbedtls_md5_update, - ._rom_mbedtls_md5_finish = mbedtls_md5_finish, - ._rom_mbedtls_md5 = mbedtls_md5, - ._rom_mbedtls_sha1 = mbedtls_sha1, - - // eco4 rom mbedtls functions - ._rom_mbedtls_aes_crypt_cfb8 = mbedtls_aes_crypt_cfb8, - ._rom_mbedtls_mpi_swap = mbedtls_mpi_swap, - ._rom_mbedtls_mpi_read_string = mbedtls_mpi_read_string, - ._rom_mbedtls_mpi_write_string = mbedtls_mpi_write_string, - ._rom_mbedtls_mpi_read_binary_le = mbedtls_mpi_read_binary_le, - ._rom_mbedtls_mpi_write_binary_le = mbedtls_mpi_write_binary_le, - ._rom_mbedtls_mpi_random = mbedtls_mpi_random, - ._rom_mbedtls_mpi_gen_prime = mbedtls_mpi_gen_prime, - ._rom_mbedtls_ecp_check_budget = mbedtls_ecp_check_budget, - ._rom_mbedtls_ecp_set_max_ops = mbedtls_ecp_set_max_ops, - ._rom_mbedtls_ecp_restart_is_enabled = mbedtls_ecp_restart_is_enabled, - ._rom_mbedtls_ecp_get_type = mbedtls_ecp_get_type, - ._rom_mbedtls_ecp_curve_list = mbedtls_ecp_curve_list, - ._rom_mbedtls_ecp_grp_id_list = mbedtls_ecp_grp_id_list, - ._rom_mbedtls_ecp_curve_info_from_grp_id = mbedtls_ecp_curve_info_from_grp_id, - ._rom_mbedtls_ecp_curve_info_from_tls_id = mbedtls_ecp_curve_info_from_tls_id, - ._rom_mbedtls_ecp_curve_info_from_name = mbedtls_ecp_curve_info_from_name, - ._rom_mbedtls_ecp_point_init = mbedtls_ecp_point_init, - ._rom_mbedtls_ecp_group_init = mbedtls_ecp_group_init, - ._rom_mbedtls_ecp_keypair_init = mbedtls_ecp_keypair_init, - ._rom_mbedtls_ecp_point_free = mbedtls_ecp_point_free, - ._rom_mbedtls_ecp_group_free = mbedtls_ecp_group_free, - ._rom_mbedtls_ecp_keypair_free = mbedtls_ecp_keypair_free, - ._rom_mbedtls_ecp_restart_init = mbedtls_ecp_restart_init, - ._rom_mbedtls_ecp_restart_free = mbedtls_ecp_restart_free, - ._rom_mbedtls_ecp_copy = mbedtls_ecp_copy, - ._rom_mbedtls_ecp_group_copy = mbedtls_ecp_group_copy, - ._rom_mbedtls_ecp_set_zero = mbedtls_ecp_set_zero, - ._rom_mbedtls_ecp_is_zero = mbedtls_ecp_is_zero, - ._rom_mbedtls_ecp_point_cmp = mbedtls_ecp_point_cmp, - ._rom_mbedtls_ecp_point_read_string = mbedtls_ecp_point_read_string, - ._rom_mbedtls_ecp_point_write_binary = mbedtls_ecp_point_write_binary, - ._rom_mbedtls_ecp_point_read_binary = mbedtls_ecp_point_read_binary, - ._rom_mbedtls_ecp_tls_read_point = mbedtls_ecp_tls_read_point, - ._rom_mbedtls_ecp_tls_write_point = mbedtls_ecp_tls_write_point, - ._rom_mbedtls_ecp_group_load = mbedtls_ecp_group_load, - ._rom_mbedtls_ecp_tls_read_group = mbedtls_ecp_tls_read_group, - ._rom_mbedtls_ecp_tls_read_group_id = mbedtls_ecp_tls_read_group_id, - ._rom_mbedtls_ecp_tls_write_group = mbedtls_ecp_tls_write_group, - ._rom_mbedtls_ecp_mul = mbedtls_ecp_mul, - ._rom_mbedtls_ecp_mul_restartable = mbedtls_ecp_mul_restartable, - ._rom_mbedtls_ecp_muladd = mbedtls_ecp_muladd, - ._rom_mbedtls_ecp_muladd_restartable = mbedtls_ecp_muladd_restartable, - ._rom_mbedtls_ecp_check_pubkey = mbedtls_ecp_check_pubkey, - ._rom_mbedtls_ecp_check_privkey = mbedtls_ecp_check_privkey, - ._rom_mbedtls_ecp_gen_privkey = mbedtls_ecp_gen_privkey, - ._rom_mbedtls_ecp_gen_keypair_base = mbedtls_ecp_gen_keypair_base, - ._rom_mbedtls_ecp_gen_keypair = mbedtls_ecp_gen_keypair, - ._rom_mbedtls_ecp_gen_key = mbedtls_ecp_gen_key, - ._rom_mbedtls_ecp_read_key = mbedtls_ecp_read_key, - ._rom_mbedtls_ecp_write_key_ext = mbedtls_ecp_write_key_ext, - ._rom_mbedtls_ecp_check_pub_priv = mbedtls_ecp_check_pub_priv, - ._rom_mbedtls_ecp_export = mbedtls_ecp_export, - ._rom_mbedtls_asn1_get_enum = mbedtls_asn1_get_enum, - ._rom_mbedtls_asn1_sequence_free = mbedtls_asn1_sequence_free, - ._rom_mbedtls_asn1_traverse_sequence_of = mbedtls_asn1_traverse_sequence_of, - ._rom_mbedtls_asn1_find_named_data = mbedtls_asn1_find_named_data, - ._rom_mbedtls_asn1_free_named_data_list = mbedtls_asn1_free_named_data_list, - ._rom_mbedtls_asn1_free_named_data_list_shallow = mbedtls_asn1_free_named_data_list_shallow, - ._rom_mbedtls_asn1_write_raw_buffer = mbedtls_asn1_write_raw_buffer, - ._rom_mbedtls_asn1_write_null = mbedtls_asn1_write_null, - ._rom_mbedtls_asn1_write_oid = mbedtls_asn1_write_oid, - ._rom_mbedtls_asn1_write_algorithm_identifier = mbedtls_asn1_write_algorithm_identifier, - ._rom_mbedtls_asn1_write_bool = mbedtls_asn1_write_bool, - ._rom_mbedtls_asn1_write_int = mbedtls_asn1_write_int, - ._rom_mbedtls_asn1_write_enum = mbedtls_asn1_write_enum, - ._rom_mbedtls_asn1_write_tagged_string = mbedtls_asn1_write_tagged_string, - ._rom_mbedtls_asn1_write_printable_string = mbedtls_asn1_write_printable_string, - ._rom_mbedtls_asn1_write_utf8_string = mbedtls_asn1_write_utf8_string, - ._rom_mbedtls_asn1_write_ia5_string = mbedtls_asn1_write_ia5_string, - ._rom_mbedtls_asn1_write_bitstring = mbedtls_asn1_write_bitstring, - ._rom_mbedtls_asn1_write_named_bitstring = mbedtls_asn1_write_named_bitstring, - ._rom_mbedtls_asn1_write_octet_string = mbedtls_asn1_write_octet_string, - ._rom_mbedtls_asn1_store_named_data = mbedtls_asn1_store_named_data, - ._rom_mbedtls_ccm_starts = mbedtls_ccm_starts, - ._rom_mbedtls_ccm_set_lengths = mbedtls_ccm_set_lengths, - ._rom_mbedtls_ccm_update_ad = mbedtls_ccm_update_ad, - ._rom_mbedtls_ccm_update = mbedtls_ccm_update, - ._rom_mbedtls_ccm_finish = mbedtls_ccm_finish, - ._rom_mbedtls_cipher_list = mbedtls_cipher_list, - ._rom_mbedtls_cipher_info_from_string = mbedtls_cipher_info_from_string, - ._rom_mbedtls_cipher_info_from_type = mbedtls_cipher_info_from_type, - ._rom_mbedtls_cipher_info_from_values = mbedtls_cipher_info_from_values, - ._rom_mbedtls_cipher_free = mbedtls_cipher_free, - ._rom_mbedtls_cipher_setup = mbedtls_cipher_setup, - ._rom_mbedtls_cipher_setkey = mbedtls_cipher_setkey, - ._rom_mbedtls_cipher_set_iv = mbedtls_cipher_set_iv, - ._rom_mbedtls_cipher_update_ad = mbedtls_cipher_update_ad, - ._rom_mbedtls_cipher_update = mbedtls_cipher_update, - ._rom_mbedtls_cipher_write_tag = mbedtls_cipher_write_tag, - ._rom_mbedtls_cipher_check_tag = mbedtls_cipher_check_tag, - ._rom_mbedtls_cipher_auth_encrypt_ext = mbedtls_cipher_auth_encrypt_ext, - ._rom_mbedtls_cipher_auth_decrypt_ext = mbedtls_cipher_auth_decrypt_ext, - ._rom_mbedtls_cipher_cmac_reset = mbedtls_cipher_cmac_reset, - ._rom_mbedtls_cipher_cmac = mbedtls_cipher_cmac, - ._rom_mbedtls_aes_cmac_prf_128 = mbedtls_aes_cmac_prf_128, - ._rom_mbedtls_ctr_drbg_set_prediction_resistance = mbedtls_ctr_drbg_set_prediction_resistance, - ._rom_mbedtls_ctr_drbg_set_entropy_len = mbedtls_ctr_drbg_set_entropy_len, - ._rom_mbedtls_ctr_drbg_set_nonce_len = mbedtls_ctr_drbg_set_nonce_len, - ._rom_mbedtls_ctr_drbg_set_reseed_interval = mbedtls_ctr_drbg_set_reseed_interval, - ._rom_mbedtls_ctr_drbg_update = mbedtls_ctr_drbg_update, - ._rom_mbedtls_base64_encode = mbedtls_base64_encode, - - /* Fill the SHA hardware functions into mbedtls rom function table */ - ._rom_mbedtls_sha1_update = mbedtls_sha1_update, - ._rom_mbedtls_sha256_update = mbedtls_sha256_update, - - //memory calloc free + ._rom_mbedtls_aes_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_init, mbedtls_aes_init), + ._rom_mbedtls_aes_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_free, mbedtls_aes_free), + ._rom_mbedtls_aes_setkey_enc = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_setkey_enc, mbedtls_aes_setkey_enc), + ._rom_mbedtls_aes_setkey_dec = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_setkey_dec, mbedtls_aes_setkey_dec), + ._rom_mbedtls_aes_crypt_ecb = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_ecb, mbedtls_aes_crypt_ecb), + ._rom_mbedtls_aes_crypt_cbc = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_cbc, mbedtls_aes_crypt_cbc), + ._rom_mbedtls_internal_aes_encrypt = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_internal_aes_encrypt, mbedtls_internal_aes_encrypt), + ._rom_mbedtls_internal_aes_decrypt = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_internal_aes_decrypt, mbedtls_internal_aes_decrypt), + ._rom_mbedtls_asn1_get_len = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_get_len, mbedtls_asn1_get_len), + ._rom_mbedtls_asn1_get_tag = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_get_tag, mbedtls_asn1_get_tag), + ._rom_mbedtls_asn1_get_bool = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_get_bool, mbedtls_asn1_get_bool), + ._rom_mbedtls_asn1_get_int = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_get_int, mbedtls_asn1_get_int), + ._rom_mbedtls_asn1_get_bitstring = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_get_bitstring, mbedtls_asn1_get_bitstring), + ._rom_mbedtls_asn1_get_bitstring_null = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_get_bitstring_null, mbedtls_asn1_get_bitstring_null), + ._rom_mbedtls_asn1_get_sequence_of = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_get_sequence_of, mbedtls_asn1_get_sequence_of), + ._rom_mbedtls_asn1_get_mpi = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_get_mpi, mbedtls_asn1_get_mpi), + ._rom_mbedtls_asn1_get_alg = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_get_alg, mbedtls_asn1_get_alg), + ._rom_mbedtls_asn1_get_alg_null = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_get_alg_null, mbedtls_asn1_get_alg_null), + ._rom_mbedtls_asn1_write_len = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_len, mbedtls_asn1_write_len), + ._rom_mbedtls_asn1_write_tag = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_tag, mbedtls_asn1_write_tag), + ._rom_mbedtls_asn1_write_mpi = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_mpi, mbedtls_asn1_write_mpi), + ._rom_mbedtls_base64_decode = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_base64_decode, mbedtls_base64_decode), + ._rom_mbedtls_mpi_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_init, mbedtls_mpi_init), + ._rom_mbedtls_mpi_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_free, mbedtls_mpi_free), + ._rom_mbedtls_mpi_grow = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_grow, mbedtls_mpi_grow), + ._rom_mbedtls_mpi_shrink = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_shrink, mbedtls_mpi_shrink), + ._rom_mbedtls_mpi_copy = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_copy, mbedtls_mpi_copy), + ._rom_mbedtls_mpi_safe_cond_assign = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_safe_cond_assign, mbedtls_mpi_safe_cond_assign), + ._rom_mbedtls_mpi_safe_cond_swap = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_safe_cond_swap, mbedtls_mpi_safe_cond_swap), + ._rom_mbedtls_mpi_lset = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_lset, mbedtls_mpi_lset), + ._rom_mbedtls_mpi_get_bit = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_get_bit, mbedtls_mpi_get_bit), + ._rom_mbedtls_mpi_set_bit = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_set_bit, mbedtls_mpi_set_bit), + ._rom_mbedtls_mpi_lsb = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_lsb, mbedtls_mpi_lsb), + ._rom_mbedtls_mpi_bitlen = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_bitlen, mbedtls_mpi_bitlen), + ._rom_mbedtls_mpi_size = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_size, mbedtls_mpi_size), + ._rom_mbedtls_mpi_read_binary = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_read_binary, mbedtls_mpi_read_binary), + ._rom_mbedtls_mpi_write_binary = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_write_binary, mbedtls_mpi_write_binary), + ._rom_mbedtls_mpi_shift_l = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_shift_l, mbedtls_mpi_shift_l), + ._rom_mbedtls_mpi_shift_r = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_shift_r, mbedtls_mpi_shift_r), + ._rom_mbedtls_mpi_cmp_abs = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_cmp_abs, mbedtls_mpi_cmp_abs), + ._rom_mbedtls_mpi_cmp_mpi = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_cmp_mpi, mbedtls_mpi_cmp_mpi), + ._rom_mbedtls_mpi_lt_mpi_ct = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_lt_mpi_ct, mbedtls_mpi_lt_mpi_ct), + ._rom_mbedtls_mpi_cmp_int = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_cmp_int, mbedtls_mpi_cmp_int), + ._rom_mbedtls_mpi_add_abs = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_add_abs, mbedtls_mpi_add_abs), + ._rom_mbedtls_mpi_sub_abs = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_sub_abs, mbedtls_mpi_sub_abs), + ._rom_mbedtls_mpi_add_mpi = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_add_mpi, mbedtls_mpi_add_mpi), + ._rom_mbedtls_mpi_sub_mpi = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_sub_mpi, mbedtls_mpi_sub_mpi), + ._rom_mbedtls_mpi_add_int = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_add_int, mbedtls_mpi_add_int), + ._rom_mbedtls_mpi_sub_int = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_sub_int, mbedtls_mpi_sub_int), + ._rom_mbedtls_mpi_mul_mpi = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_mul_mpi, mbedtls_mpi_mul_mpi), + ._rom_mbedtls_mpi_mul_int = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_mul_int, mbedtls_mpi_mul_int), + ._rom_mbedtls_mpi_div_mpi = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_div_mpi, mbedtls_mpi_div_mpi), + ._rom_mbedtls_mpi_div_int = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_div_int, mbedtls_mpi_div_int), + ._rom_mbedtls_mpi_mod_mpi = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_mod_mpi, mbedtls_mpi_mod_mpi), + ._rom_mbedtls_mpi_mod_int = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_mod_int, mbedtls_mpi_mod_int), + ._rom_mbedtls_mpi_exp_mod = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_exp_mod, mbedtls_mpi_exp_mod), + ._rom_mbedtls_mpi_fill_random = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_fill_random, mbedtls_mpi_fill_random), + ._rom_mbedtls_mpi_gcd = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_gcd, mbedtls_mpi_gcd), + ._rom_mbedtls_mpi_inv_mod = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_inv_mod, mbedtls_mpi_inv_mod), + ._rom_mbedtls_mpi_is_prime_ext = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_is_prime_ext, mbedtls_mpi_is_prime_ext), + ._rom_mbedtls_ccm_star_encrypt_and_tag = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_star_encrypt_and_tag, mbedtls_ccm_star_encrypt_and_tag), + ._rom_mbedtls_ccm_star_auth_decrypt = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_star_auth_decrypt, mbedtls_ccm_star_auth_decrypt), + ._rom_mbedtls_cipher_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_init, mbedtls_cipher_init), + ._rom_mbedtls_cipher_set_padding_mode = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_set_padding_mode, mbedtls_cipher_set_padding_mode), + ._rom_mbedtls_cipher_reset = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_reset, mbedtls_cipher_reset), + ._rom_mbedtls_cipher_finish = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_finish, mbedtls_cipher_finish), + ._rom_mbedtls_cipher_crypt = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_crypt, mbedtls_cipher_crypt), + ._rom_mbedtls_cipher_cmac_starts = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_cmac_starts, mbedtls_cipher_cmac_starts), + ._rom_mbedtls_cipher_cmac_update = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_cmac_update, mbedtls_cipher_cmac_update), + ._rom_mbedtls_cipher_cmac_finish = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_cmac_finish, mbedtls_cipher_cmac_finish), + ._rom_mbedtls_ctr_drbg_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ctr_drbg_init, mbedtls_ctr_drbg_init), + ._rom_mbedtls_ctr_drbg_seed = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ctr_drbg_seed, mbedtls_ctr_drbg_seed), + ._rom_mbedtls_ctr_drbg_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ctr_drbg_free, mbedtls_ctr_drbg_free), + ._rom_mbedtls_ctr_drbg_reseed = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ctr_drbg_reseed, mbedtls_ctr_drbg_reseed), + ._rom_mbedtls_ctr_drbg_random_with_add = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ctr_drbg_random_with_add, mbedtls_ctr_drbg_random_with_add), + ._rom_mbedtls_ctr_drbg_random = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ctr_drbg_random, mbedtls_ctr_drbg_random), + ._rom_mbedtls_sha1_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha1_init, mbedtls_sha1_init), + ._rom_mbedtls_sha1_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha1_free, mbedtls_sha1_free), + ._rom_mbedtls_sha1_clone = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha1_clone, mbedtls_sha1_clone), + ._rom_mbedtls_sha1_starts = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha1_starts, mbedtls_sha1_starts), + ._rom_mbedtls_sha1_finish = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha1_finish, mbedtls_sha1_finish), + ._rom_mbedtls_sha256_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha256_init, mbedtls_sha256_init), + ._rom_mbedtls_sha256_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha256_free, mbedtls_sha256_free), + ._rom_mbedtls_sha256_clone = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha256_clone, mbedtls_sha256_clone), + ._rom_mbedtls_sha256_starts = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha256_starts, mbedtls_sha256_starts), + ._rom_mbedtls_sha256_finish = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha256_finish, mbedtls_sha256_finish), + ._rom_mbedtls_sha256 = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha256, mbedtls_sha256), + ._rom_mbedtls_sha512_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha512_init, mbedtls_sha512_init), + ._rom_mbedtls_sha512_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha512_free, mbedtls_sha512_free), + ._rom_mbedtls_sha512_clone = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha512_clone, mbedtls_sha512_clone), + ._rom_mbedtls_sha512_starts = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha512_starts, mbedtls_sha512_starts), + ._rom_mbedtls_sha512_update = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha512_update, mbedtls_sha512_update), + ._rom_mbedtls_sha512_finish = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha512_finish, mbedtls_sha512_finish), + ._rom_mbedtls_sha512 = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha512, mbedtls_sha512), + ._rom_mbedtls_aes_xts_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_xts_init, mbedtls_aes_xts_init), + ._rom_mbedtls_aes_xts_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_xts_free, mbedtls_aes_xts_free), + ._rom_mbedtls_aes_xts_setkey_enc = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_xts_setkey_enc, mbedtls_aes_xts_setkey_enc), + ._rom_mbedtls_aes_xts_setkey_dec = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_xts_setkey_dec, mbedtls_aes_xts_setkey_dec), + ._rom_mbedtls_aes_crypt_xts = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_xts, mbedtls_aes_crypt_xts), + ._rom_mbedtls_aes_crypt_cfb128 = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_cfb128, mbedtls_aes_crypt_cfb128), + ._rom_mbedtls_aes_crypt_ofb = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_ofb, mbedtls_aes_crypt_ofb), + ._rom_mbedtls_aes_crypt_ctr = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_ctr, mbedtls_aes_crypt_ctr), + ._rom_mbedtls_ccm_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_init, mbedtls_ccm_init), + ._rom_mbedtls_ccm_setkey = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_setkey, mbedtls_ccm_setkey), + ._rom_mbedtls_ccm_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_free, mbedtls_ccm_free), + ._rom_mbedtls_ccm_encrypt_and_tag = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_encrypt_and_tag, mbedtls_ccm_encrypt_and_tag), + ._rom_mbedtls_ccm_auth_decrypt = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_auth_decrypt, mbedtls_ccm_auth_decrypt), + ._rom_mbedtls_md5_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_md5_init, mbedtls_md5_init), + ._rom_mbedtls_md5_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_md5_free, mbedtls_md5_free), + ._rom_mbedtls_md5_clone = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_md5_clone, mbedtls_md5_clone), + ._rom_mbedtls_md5_starts = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_md5_starts, mbedtls_md5_starts), + ._rom_mbedtls_md5_update = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_md5_update, mbedtls_md5_update), + ._rom_mbedtls_md5_finish = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_md5_finish, mbedtls_md5_finish), + ._rom_mbedtls_md5 = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_md5, mbedtls_md5), + ._rom_mbedtls_sha1 = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha1, mbedtls_sha1), + ._rom_mbedtls_aes_crypt_cfb8 = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_cfb8, mbedtls_aes_crypt_cfb8), + ._rom_mbedtls_mpi_swap = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_swap, mbedtls_mpi_swap), + ._rom_mbedtls_mpi_read_string = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_read_string, mbedtls_mpi_read_string), + ._rom_mbedtls_mpi_write_string = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_write_string, mbedtls_mpi_write_string), + ._rom_mbedtls_mpi_read_binary_le = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_read_binary_le, mbedtls_mpi_read_binary_le), + ._rom_mbedtls_mpi_write_binary_le = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_write_binary_le, mbedtls_mpi_write_binary_le), + ._rom_mbedtls_mpi_random = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_random, mbedtls_mpi_random), + ._rom_mbedtls_mpi_gen_prime = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_mpi_gen_prime, mbedtls_mpi_gen_prime), + ._rom_mbedtls_ecp_check_budget = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_check_budget, mbedtls_ecp_check_budget), + ._rom_mbedtls_ecp_set_max_ops = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_set_max_ops, mbedtls_ecp_set_max_ops), + ._rom_mbedtls_ecp_restart_is_enabled = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_restart_is_enabled, mbedtls_ecp_restart_is_enabled), + ._rom_mbedtls_ecp_get_type = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_get_type, mbedtls_ecp_get_type), + ._rom_mbedtls_ecp_curve_list = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_curve_list, mbedtls_ecp_curve_list), + ._rom_mbedtls_ecp_grp_id_list = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_grp_id_list, mbedtls_ecp_grp_id_list), + ._rom_mbedtls_ecp_curve_info_from_grp_id = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_curve_info_from_grp_id, mbedtls_ecp_curve_info_from_grp_id), + ._rom_mbedtls_ecp_curve_info_from_tls_id = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_curve_info_from_tls_id, mbedtls_ecp_curve_info_from_tls_id), + ._rom_mbedtls_ecp_curve_info_from_name = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_curve_info_from_name, mbedtls_ecp_curve_info_from_name), + ._rom_mbedtls_ecp_point_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_point_init, mbedtls_ecp_point_init), + ._rom_mbedtls_ecp_group_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_group_init, mbedtls_ecp_group_init), + ._rom_mbedtls_ecp_keypair_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_keypair_init, mbedtls_ecp_keypair_init), + ._rom_mbedtls_ecp_point_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_point_free, mbedtls_ecp_point_free), + ._rom_mbedtls_ecp_group_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_group_free, mbedtls_ecp_group_free), + ._rom_mbedtls_ecp_keypair_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_keypair_free, mbedtls_ecp_keypair_free), + ._rom_mbedtls_ecp_restart_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_restart_init, mbedtls_ecp_restart_init), + ._rom_mbedtls_ecp_restart_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_restart_free, mbedtls_ecp_restart_free), + ._rom_mbedtls_ecp_copy = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_copy, mbedtls_ecp_copy), + ._rom_mbedtls_ecp_group_copy = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_group_copy, mbedtls_ecp_group_copy), + ._rom_mbedtls_ecp_set_zero = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_set_zero, mbedtls_ecp_set_zero), + ._rom_mbedtls_ecp_is_zero = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_is_zero, mbedtls_ecp_is_zero), + ._rom_mbedtls_ecp_point_cmp = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_point_cmp, mbedtls_ecp_point_cmp), + ._rom_mbedtls_ecp_point_read_string = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_point_read_string, mbedtls_ecp_point_read_string), + ._rom_mbedtls_ecp_point_write_binary = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_point_write_binary, mbedtls_ecp_point_write_binary), + ._rom_mbedtls_ecp_point_read_binary = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_point_read_binary, mbedtls_ecp_point_read_binary), + ._rom_mbedtls_ecp_tls_read_point = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_tls_read_point, mbedtls_ecp_tls_read_point), + ._rom_mbedtls_ecp_tls_write_point = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_tls_write_point, mbedtls_ecp_tls_write_point), + ._rom_mbedtls_ecp_group_load = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_group_load, mbedtls_ecp_group_load), + ._rom_mbedtls_ecp_tls_read_group = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_tls_read_group, mbedtls_ecp_tls_read_group), + ._rom_mbedtls_ecp_tls_read_group_id = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_tls_read_group_id, mbedtls_ecp_tls_read_group_id), + ._rom_mbedtls_ecp_tls_write_group = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_tls_write_group, mbedtls_ecp_tls_write_group), + ._rom_mbedtls_ecp_mul = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_mul, mbedtls_ecp_mul), + ._rom_mbedtls_ecp_mul_restartable = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_mul_restartable, mbedtls_ecp_mul_restartable), + ._rom_mbedtls_ecp_muladd = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_muladd, mbedtls_ecp_muladd), + ._rom_mbedtls_ecp_muladd_restartable = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_muladd_restartable, mbedtls_ecp_muladd_restartable), + ._rom_mbedtls_ecp_check_pubkey = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_check_pubkey, mbedtls_ecp_check_pubkey), + ._rom_mbedtls_ecp_check_privkey = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_check_privkey, mbedtls_ecp_check_privkey), + ._rom_mbedtls_ecp_gen_privkey = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_gen_privkey, mbedtls_ecp_gen_privkey), + ._rom_mbedtls_ecp_gen_keypair_base = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_gen_keypair_base, mbedtls_ecp_gen_keypair_base), + ._rom_mbedtls_ecp_gen_keypair = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_gen_keypair, mbedtls_ecp_gen_keypair), + ._rom_mbedtls_ecp_gen_key = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_gen_key, mbedtls_ecp_gen_key), + ._rom_mbedtls_ecp_read_key = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_read_key, mbedtls_ecp_read_key), + ._rom_mbedtls_ecp_write_key_ext = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_write_key_ext, mbedtls_ecp_write_key_ext), + ._rom_mbedtls_ecp_check_pub_priv = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_check_pub_priv, mbedtls_ecp_check_pub_priv), + ._rom_mbedtls_ecp_export = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ecp_export, mbedtls_ecp_export), + ._rom_mbedtls_asn1_get_enum = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_get_enum, mbedtls_asn1_get_enum), + ._rom_mbedtls_asn1_sequence_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_sequence_free, mbedtls_asn1_sequence_free), + ._rom_mbedtls_asn1_traverse_sequence_of = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_traverse_sequence_of, mbedtls_asn1_traverse_sequence_of), + ._rom_mbedtls_asn1_find_named_data = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_find_named_data, mbedtls_asn1_find_named_data), + ._rom_mbedtls_asn1_free_named_data_list = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_free_named_data_list, mbedtls_asn1_free_named_data_list), + ._rom_mbedtls_asn1_free_named_data_list_shallow = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_free_named_data_list_shallow, mbedtls_asn1_free_named_data_list_shallow), + ._rom_mbedtls_asn1_write_raw_buffer = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_raw_buffer, mbedtls_asn1_write_raw_buffer), + ._rom_mbedtls_asn1_write_null = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_null, mbedtls_asn1_write_null), + ._rom_mbedtls_asn1_write_oid = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_oid, mbedtls_asn1_write_oid), + ._rom_mbedtls_asn1_write_algorithm_identifier = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_algorithm_identifier, mbedtls_asn1_write_algorithm_identifier), + ._rom_mbedtls_asn1_write_bool = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_bool, mbedtls_asn1_write_bool), + ._rom_mbedtls_asn1_write_int = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_int, mbedtls_asn1_write_int), + ._rom_mbedtls_asn1_write_enum = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_enum, mbedtls_asn1_write_enum), + ._rom_mbedtls_asn1_write_tagged_string = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_tagged_string, mbedtls_asn1_write_tagged_string), + ._rom_mbedtls_asn1_write_printable_string = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_printable_string, mbedtls_asn1_write_printable_string), + ._rom_mbedtls_asn1_write_utf8_string = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_utf8_string, mbedtls_asn1_write_utf8_string), + ._rom_mbedtls_asn1_write_ia5_string = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_ia5_string, mbedtls_asn1_write_ia5_string), + ._rom_mbedtls_asn1_write_bitstring = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_bitstring, mbedtls_asn1_write_bitstring), + ._rom_mbedtls_asn1_write_named_bitstring = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_named_bitstring, mbedtls_asn1_write_named_bitstring), + ._rom_mbedtls_asn1_write_octet_string = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_write_octet_string, mbedtls_asn1_write_octet_string), + ._rom_mbedtls_asn1_store_named_data = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_asn1_store_named_data, mbedtls_asn1_store_named_data), + ._rom_mbedtls_ccm_starts = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_starts, mbedtls_ccm_starts), + ._rom_mbedtls_ccm_set_lengths = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_set_lengths, mbedtls_ccm_set_lengths), + ._rom_mbedtls_ccm_update_ad = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_update_ad, mbedtls_ccm_update_ad), + ._rom_mbedtls_ccm_update = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_update, mbedtls_ccm_update), + ._rom_mbedtls_ccm_finish = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ccm_finish, mbedtls_ccm_finish), + ._rom_mbedtls_cipher_list = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_list, mbedtls_cipher_list), + ._rom_mbedtls_cipher_info_from_string = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_info_from_string, mbedtls_cipher_info_from_string), + ._rom_mbedtls_cipher_info_from_type = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_info_from_type, mbedtls_cipher_info_from_type), + ._rom_mbedtls_cipher_info_from_values = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_info_from_values, mbedtls_cipher_info_from_values), + ._rom_mbedtls_cipher_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_free, mbedtls_cipher_free), + ._rom_mbedtls_cipher_setup = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_setup, mbedtls_cipher_setup), + ._rom_mbedtls_cipher_setkey = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_setkey, mbedtls_cipher_setkey), + ._rom_mbedtls_cipher_set_iv = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_set_iv, mbedtls_cipher_set_iv), + ._rom_mbedtls_cipher_update_ad = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_update_ad, mbedtls_cipher_update_ad), + ._rom_mbedtls_cipher_update = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_update, mbedtls_cipher_update), + ._rom_mbedtls_cipher_write_tag = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_write_tag, mbedtls_cipher_write_tag), + ._rom_mbedtls_cipher_check_tag = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_check_tag, mbedtls_cipher_check_tag), + ._rom_mbedtls_cipher_auth_encrypt_ext = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_auth_encrypt_ext, mbedtls_cipher_auth_encrypt_ext), + ._rom_mbedtls_cipher_auth_decrypt_ext = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_auth_decrypt_ext, mbedtls_cipher_auth_decrypt_ext), + ._rom_mbedtls_cipher_cmac_reset = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_cmac_reset, mbedtls_cipher_cmac_reset), + ._rom_mbedtls_cipher_cmac = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_cipher_cmac, mbedtls_cipher_cmac), + ._rom_mbedtls_aes_cmac_prf_128 = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_cmac_prf_128, mbedtls_aes_cmac_prf_128), + ._rom_mbedtls_ctr_drbg_set_prediction_resistance = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ctr_drbg_set_prediction_resistance, mbedtls_ctr_drbg_set_prediction_resistance), + ._rom_mbedtls_ctr_drbg_set_entropy_len = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ctr_drbg_set_entropy_len, mbedtls_ctr_drbg_set_entropy_len), + ._rom_mbedtls_ctr_drbg_set_nonce_len = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ctr_drbg_set_nonce_len, mbedtls_ctr_drbg_set_nonce_len), + ._rom_mbedtls_ctr_drbg_set_reseed_interval = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ctr_drbg_set_reseed_interval, mbedtls_ctr_drbg_set_reseed_interval), + ._rom_mbedtls_ctr_drbg_update = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_ctr_drbg_update, mbedtls_ctr_drbg_update), + ._rom_mbedtls_base64_encode = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_base64_encode, mbedtls_base64_encode), + ._rom_mbedtls_sha1_update = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha1_update, mbedtls_sha1_update), + ._rom_mbedtls_sha256_update = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_sha256_update, mbedtls_sha256_update), ._rom_mbedtls_mem_calloc = MBEDTLS_PLATFORM_STD_CALLOC, ._rom_mbedtls_mem_free = MBEDTLS_PLATFORM_STD_FREE, }; @@ -453,16 +340,9 @@ __attribute__((constructor)) void mbedtls_rom_osi_functions_init(void) mbedtls_threading_set_alt(mbedtls_rom_mutex_init, mbedtls_rom_mutex_free, mbedtls_rom_mutex_lock, mbedtls_rom_mutex_unlock); #endif - unsigned chip_version = efuse_hal_chip_revision(); - if ( ESP_CHIP_REV_ABOVE(chip_version, 200) ) { - /* Initialize the rom function mbedtls_threading_set_alt on chip rev2.0 with rom eco4 */ - _rom_mbedtls_threading_set_alt_t rom_mbedtls_threading_set_alt = (_rom_mbedtls_threading_set_alt_t)0x40002c0c; - rom_mbedtls_threading_set_alt(mbedtls_rom_mutex_init, mbedtls_rom_mutex_free, mbedtls_rom_mutex_lock, mbedtls_rom_mutex_unlock); + /* Initialize the rom function mbedtls_threading_set_alt on chip rev2.0 with rom eco4 */ + rom_mbedtls_threading_set_alt(mbedtls_rom_mutex_init, mbedtls_rom_mutex_free, mbedtls_rom_mutex_lock, mbedtls_rom_mutex_unlock); - /* Initialize the pointer of rom eco4 mbedtls functions table. */ - mbedtls_rom_osi_funcs_ptr = (mbedtls_rom_eco4_funcs_t *)&mbedtls_rom_eco4_funcs_table; - } else { - /* Initialize the pointer of rom mbedtls functions table. */ - mbedtls_rom_osi_funcs_ptr = (mbedtls_rom_funcs_t *)&mbedtls_rom_funcs_table; - } + /* Initialize the pointer of rom eco4 mbedtls functions table. */ + mbedtls_rom_osi_funcs_ptr = (mbedtls_rom_eco4_funcs_t *)&mbedtls_rom_eco4_funcs_table; } diff --git a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.h b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.h index 6408e1c5437..47f755d556c 100644 --- a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.h +++ b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,38 +7,24 @@ #pragma once #include -#include "mbedtls/aes.h" +#include +#include "mbedtls/private/aes.h" #include "mbedtls/asn1.h" #include "mbedtls/asn1write.h" #include "mbedtls/base64.h" #include "mbedtls/bignum.h" -#include "mbedtls/ccm.h" -#include "mbedtls/cipher.h" -#include "mbedtls/cmac.h" -#include "mbedtls/ctr_drbg.h" -#include "mbedtls/dhm.h" -#include "mbedtls/ecdh.h" -#include "mbedtls/ecdsa.h" -#include "mbedtls/ecjpake.h" -#include "mbedtls/ecp.h" -#include "mbedtls/entropy.h" -#include "mbedtls/hmac_drbg.h" +#include "mbedtls/private/ccm.h" +#include "mbedtls/private/cipher.h" +#include "mbedtls/private/cmac.h" +#include "mbedtls/private/ctr_drbg.h" +#include "mbedtls/private/ecp.h" #include "mbedtls/md.h" -#include "mbedtls/md5.h" -#include "mbedtls/oid.h" -#include "mbedtls/pem.h" -#include "mbedtls/pkcs12.h" -#include "mbedtls/pkcs5.h" -#include "mbedtls/pk.h" +#include "mbedtls/private/md5.h" #include "mbedtls/platform.h" -#include "mbedtls/rsa.h" -#include "mbedtls/sha1.h" -#include "mbedtls/sha256.h" -#include "mbedtls/sha512.h" -#include "mbedtls/ssl_ciphersuites.h" -#include "mbedtls/ssl.h" -#include "mbedtls/x509_crt.h" -#include "mbedtls/x509.h" +#include "mbedtls/private/sha1.h" +#include "mbedtls/private/sha256.h" +#include "mbedtls/private/sha512.h" +#include "mbedtls/threading.h" #include "soc/soc_caps.h" #ifdef __cplusplus @@ -58,362 +44,6 @@ typedef void (*_rom_mbedtls_threading_set_alt_t)(void (*mutex_init)(mbedtls_thre typedef void mbedtls_threading_mutex_t; #endif /* BOOTLOADER_BUILD */ -typedef struct mbedtls_rom_funcs { - void (*_rom_mbedtls_aes_init)( mbedtls_aes_context *ctx ); - int (*_rom_ssl_write_client_hello)( mbedtls_ssl_context *ssl ); - int (*_rom_ssl_parse_server_hello)( mbedtls_ssl_context *ssl ); - int (*_rom_ssl_parse_server_key_exchange)( mbedtls_ssl_context *ssl ); - int (*_rom_ssl_parse_certificate_request)( mbedtls_ssl_context *ssl ); - int (*_rom_ssl_parse_server_hello_done)( mbedtls_ssl_context *ssl ); - int (*_rom_ssl_write_client_key_exchange)( mbedtls_ssl_context *ssl ); - int (*_rom_ssl_write_certificate_verify)( mbedtls_ssl_context *ssl ); - int (*_rom_ssl_parse_new_session_ticket)( mbedtls_ssl_context *ssl ); - void (*_rom_mbedtls_aes_free)( mbedtls_aes_context *ctx ); - int (*_rom_mbedtls_aes_setkey_enc)( mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits ); - int (*_rom_mbedtls_aes_setkey_dec)( mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits ); - int (*_rom_mbedtls_aes_crypt_ecb)( mbedtls_aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16] ); - int (*_rom_mbedtls_aes_crypt_cbc)( mbedtls_aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output ); - int (*_rom_mbedtls_internal_aes_encrypt)( mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16] ); - int (*_rom_mbedtls_internal_aes_decrypt)( mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16] ); - int (*_rom_mbedtls_asn1_get_len)( unsigned char **p, const unsigned char *end, size_t *len ); - int (*_rom_mbedtls_asn1_get_tag)( unsigned char **p, const unsigned char *end, size_t *len, int tag ); - int (*_rom_mbedtls_asn1_get_bool)( unsigned char **p, const unsigned char *end, int *val ); - int (*_rom_mbedtls_asn1_get_int)( unsigned char **p, const unsigned char *end, int *val ); - int (*_rom_mbedtls_asn1_get_bitstring)( unsigned char **p, const unsigned char *end, mbedtls_asn1_bitstring *bs); - int (*_rom_mbedtls_asn1_get_bitstring_null)( unsigned char **p, const unsigned char *end, size_t *len ); - int (*_rom_mbedtls_asn1_get_sequence_of)( unsigned char **p, const unsigned char *end, mbedtls_asn1_sequence *cur, int tag); - int (*_rom_mbedtls_asn1_get_mpi)( unsigned char **p, const unsigned char *end, mbedtls_mpi *X ); - int (*_rom_mbedtls_asn1_get_alg)( unsigned char **p, const unsigned char *end, mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params ); - int (*_rom_mbedtls_asn1_get_alg_null)( unsigned char **p, const unsigned char *end, mbedtls_asn1_buf *alg ); - int (*_rom_mbedtls_asn1_write_len)( unsigned char **p, const unsigned char *start, size_t len ); - int (*_rom_mbedtls_asn1_write_tag)( unsigned char **p, const unsigned char *start, unsigned char tag ); - int (*_rom_mbedtls_asn1_write_mpi)( unsigned char **p, const unsigned char *start, const mbedtls_mpi *X ); - int (*_rom_mbedtls_base64_decode)( unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen ); - void (*_rom_mbedtls_mpi_init)( mbedtls_mpi *X ); - void (*_rom_mbedtls_mpi_free)( mbedtls_mpi *X ); - int (*_rom_mbedtls_mpi_grow)( mbedtls_mpi *X, size_t nblimbs ); - int (*_rom_mbedtls_mpi_shrink)( mbedtls_mpi *X, size_t nblimbs ); - int (*_rom_mbedtls_mpi_copy)( mbedtls_mpi *X, const mbedtls_mpi *Y ); - int (*_rom_mbedtls_mpi_safe_cond_assign)( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign ); - int (*_rom_mbedtls_mpi_safe_cond_swap)( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign ); - int (*_rom_mbedtls_mpi_lset)( mbedtls_mpi *X, mbedtls_mpi_sint z ); - int (*_rom_mbedtls_mpi_get_bit)( const mbedtls_mpi *X, size_t pos ); - int (*_rom_mbedtls_mpi_set_bit)( mbedtls_mpi *X, size_t pos, unsigned char val ); - size_t (*_rom_mbedtls_mpi_lsb)( const mbedtls_mpi *X ); - size_t (*_rom_mbedtls_mpi_bitlen)( const mbedtls_mpi *X ); - size_t (*_rom_mbedtls_mpi_size)( const mbedtls_mpi *X ); - int (*_rom_mbedtls_mpi_read_binary)( mbedtls_mpi *X, const unsigned char *buf, size_t buflen ); - int (*_rom_mbedtls_mpi_write_binary)( const mbedtls_mpi *X, unsigned char *buf, size_t buflen ); - int (*_rom_mbedtls_mpi_shift_l)( mbedtls_mpi *X, size_t count ); - int (*_rom_mbedtls_mpi_shift_r)( mbedtls_mpi *X, size_t count ); - int (*_rom_mbedtls_mpi_cmp_abs)( const mbedtls_mpi *X, const mbedtls_mpi *Y ); - int (*_rom_mbedtls_mpi_cmp_mpi)( const mbedtls_mpi *X, const mbedtls_mpi *Y ); - int (*_rom_mbedtls_mpi_lt_mpi_ct)( const mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned *ret ); - int (*_rom_mbedtls_mpi_cmp_int)( const mbedtls_mpi *X, mbedtls_mpi_sint z ); - int (*_rom_mbedtls_mpi_add_abs)( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); - int (*_rom_mbedtls_mpi_sub_abs)( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); - int (*_rom_mbedtls_mpi_add_mpi)( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); - int (*_rom_mbedtls_mpi_sub_mpi)( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); - int (*_rom_mbedtls_mpi_add_int)( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b ); - int (*_rom_mbedtls_mpi_sub_int)( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b ); - int (*_rom_mbedtls_mpi_mul_mpi)( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); - int (*_rom_mbedtls_mpi_mul_int)( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b ); - int (*_rom_mbedtls_mpi_div_mpi)( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B ); - int (*_rom_mbedtls_mpi_div_int)( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, mbedtls_mpi_sint b ); - int (*_rom_mbedtls_mpi_mod_mpi)( mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B ); - int (*_rom_mbedtls_mpi_mod_int)( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b ); - int (*_rom_mbedtls_mpi_exp_mod)( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_mpi *N, mbedtls_mpi *_RR ); - int (*_rom_mbedtls_mpi_fill_random)( mbedtls_mpi *X, size_t size, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - int (*_rom_mbedtls_mpi_gcd)( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B ); - int (*_rom_mbedtls_mpi_inv_mod)( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N ); - int (*_rom_mbedtls_mpi_is_prime_ext)( const mbedtls_mpi *X, int rounds, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - int (*_rom_mbedtls_ccm_star_encrypt_and_tag)( mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, unsigned char *tag, size_t tag_len ); - int (*_rom_mbedtls_ccm_star_auth_decrypt)( mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, const unsigned char *tag, size_t tag_len ); - void (*_rom_mbedtls_cipher_init)( mbedtls_cipher_context_t *ctx ); - int (*_rom_mbedtls_cipher_set_padding_mode)( mbedtls_cipher_context_t *ctx, mbedtls_cipher_padding_t mode ); - int (*_rom_mbedtls_cipher_reset)( mbedtls_cipher_context_t *ctx ); - int (*_rom_mbedtls_cipher_finish)( mbedtls_cipher_context_t *ctx, unsigned char *output, size_t *olen ); - int (*_rom_mbedtls_cipher_crypt)( mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen ); - int (*_rom_mbedtls_cipher_cmac_starts)( mbedtls_cipher_context_t *ctx, const unsigned char *key, size_t keybits ); - int (*_rom_mbedtls_cipher_cmac_update)( mbedtls_cipher_context_t *ctx, const unsigned char *input, size_t ilen ); - int (*_rom_mbedtls_cipher_cmac_finish)( mbedtls_cipher_context_t *ctx, unsigned char *output ); - void (*_rom_mbedtls_ctr_drbg_init)( mbedtls_ctr_drbg_context *ctx ); - int (*_rom_mbedtls_ctr_drbg_seed)( mbedtls_ctr_drbg_context *ctx, int (*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len ); - void (*_rom_mbedtls_ctr_drbg_free)( mbedtls_ctr_drbg_context *ctx ); - int (*_rom_mbedtls_ctr_drbg_reseed)( mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t len ); - int (*_rom_mbedtls_ctr_drbg_random_with_add)( void *p_rng, unsigned char *output, size_t output_len, const unsigned char *additional, size_t add_len ); - int (*_rom_mbedtls_ctr_drbg_random)( void *p_rng, unsigned char *output, size_t output_len ); - void (*_rom_mbedtls_dhm_init)( mbedtls_dhm_context *ctx ); - int (*_rom_mbedtls_dhm_read_params)( mbedtls_dhm_context *ctx, unsigned char **p, const unsigned char *end ); - int (*_rom_mbedtls_dhm_make_public)( mbedtls_dhm_context *ctx, int x_size, unsigned char *output, size_t olen, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - int (*_rom_mbedtls_dhm_calc_secret)( mbedtls_dhm_context *ctx, unsigned char *output, size_t output_size, size_t *olen, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - void (*_rom_mbedtls_dhm_free)( mbedtls_dhm_context *ctx ); - void (*_rom_mbedtls_ecdh_init)( mbedtls_ecdh_context *ctx ); - int (*_rom_mbedtls_ecdh_setup)( mbedtls_ecdh_context *ctx, mbedtls_ecp_group_id grp_id ); - void (*_rom_mbedtls_ecdh_free)( mbedtls_ecdh_context *ctx ); - int (*_rom_mbedtls_ecdh_read_params)( mbedtls_ecdh_context *ctx, const unsigned char **buf, const unsigned char *end ); - int (*_rom_mbedtls_ecdh_get_params)( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key, mbedtls_ecdh_side side ); - int (*_rom_mbedtls_ecdh_make_public)( mbedtls_ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - int (*_rom_mbedtls_ecdh_calc_secret)( mbedtls_ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - void (*_rom_mbedtls_ecdh_enable_restart)( mbedtls_ecdh_context *ctx ); - int (*_rom_mbedtls_ecdsa_write_signature)( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hlen, unsigned char *sig, size_t *slen, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - int (*_rom_mbedtls_ecdsa_write_signature_restartable)( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hlen, unsigned char *sig, size_t *slen, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, mbedtls_ecdsa_restart_ctx *rs_ctx ); - int (*_rom_mbedtls_ecdsa_read_signature)( mbedtls_ecdsa_context *ctx, const unsigned char *hash, size_t hlen, const unsigned char *sig, size_t slen ); - int (*_rom_mbedtls_ecdsa_read_signature_restartable)( mbedtls_ecdsa_context *ctx, const unsigned char *hash, size_t hlen, const unsigned char *sig, size_t slen, mbedtls_ecdsa_restart_ctx *rs_ctx ); - int (*_rom_mbedtls_ecdsa_from_keypair)( mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key ); - void (*_rom_mbedtls_ecdsa_init)( mbedtls_ecdsa_context *ctx ); - void (*_rom_mbedtls_ecdsa_free)( mbedtls_ecdsa_context *ctx ); - void (*_rom_mbedtls_ecdsa_restart_init)( mbedtls_ecdsa_restart_ctx *ctx ); - void (*_rom_mbedtls_ecdsa_restart_free)( mbedtls_ecdsa_restart_ctx *ctx ); - void (*_rom_mbedtls_ecjpake_init)( mbedtls_ecjpake_context *ctx ); - int (*_rom_mbedtls_ecjpake_check)( const mbedtls_ecjpake_context *ctx ); - int (*_rom_mbedtls_ecjpake_write_round_one)( mbedtls_ecjpake_context *ctx, unsigned char *buf, size_t len, size_t *olen, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - int (*_rom_mbedtls_ecjpake_read_round_one)( mbedtls_ecjpake_context *ctx, const unsigned char *buf, size_t len ); - int (*_rom_mbedtls_ecjpake_write_round_two)( mbedtls_ecjpake_context *ctx, unsigned char *buf, size_t len, size_t *olen, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - int (*_rom_mbedtls_ecjpake_read_round_two)( mbedtls_ecjpake_context *ctx, const unsigned char *buf, size_t len ); - int (*_rom_mbedtls_ecjpake_derive_secret)( mbedtls_ecjpake_context *ctx, unsigned char *buf, size_t len, size_t *olen, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - void (*_rom_mbedtls_ecjpake_free)( mbedtls_ecjpake_context *ctx ); - int (*_rom_mbedtls_ecp_check_budget)( const mbedtls_ecp_group *grp, mbedtls_ecp_restart_ctx *rs_ctx, unsigned ops ); - int (*_rom_mbedtls_ecp_restart_is_enabled)( void ); - const mbedtls_ecp_curve_info *(*_rom_mbedtls_ecp_curve_list)( void ); - const mbedtls_ecp_group_id *(*_rom_mbedtls_ecp_grp_id_list)( void ); - const mbedtls_ecp_curve_info *(*_rom_mbedtls_ecp_curve_info_from_grp_id)( mbedtls_ecp_group_id grp_id ); - const mbedtls_ecp_curve_info *(*_rom_mbedtls_ecp_curve_info_from_tls_id)( uint16_t tls_id ); - void (*_rom_mbedtls_ecp_point_init)( mbedtls_ecp_point *pt ); - void (*_rom_mbedtls_ecp_group_init)( mbedtls_ecp_group *grp ); - void (*_rom_mbedtls_ecp_keypair_init)( mbedtls_ecp_keypair *key ); - void (*_rom_mbedtls_ecp_point_free)( mbedtls_ecp_point *pt ); - void (*_rom_mbedtls_ecp_group_free)( mbedtls_ecp_group *grp ); - void (*_rom_mbedtls_ecp_keypair_free)( mbedtls_ecp_keypair *key ); - void (*_rom_mbedtls_ecp_restart_init)( mbedtls_ecp_restart_ctx *ctx ); - void (*_rom_mbedtls_ecp_restart_free)( mbedtls_ecp_restart_ctx *ctx ); - int (*_rom_mbedtls_ecp_copy)( mbedtls_ecp_point *P, const mbedtls_ecp_point *Q ); - int (*_rom_mbedtls_ecp_group_copy)( mbedtls_ecp_group *dst, const mbedtls_ecp_group *src ); - int (*_rom_mbedtls_ecp_set_zero)( mbedtls_ecp_point *pt ); - int (*_rom_mbedtls_ecp_is_zero)( mbedtls_ecp_point *pt ); - int (*_rom_mbedtls_ecp_point_cmp)( const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q ); - int (*_rom_mbedtls_ecp_point_write_binary)( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *P, int format, size_t *olen, unsigned char *buf, size_t buflen ); - int (*_rom_mbedtls_ecp_point_read_binary)( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P, const unsigned char *buf, size_t ilen ); - int (*_rom_mbedtls_ecp_tls_read_point)( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt, const unsigned char **buf, size_t len ); - int (*_rom_mbedtls_ecp_tls_write_point)( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt, int format, size_t *olen, unsigned char *buf, size_t blen ); - int (*_rom_mbedtls_ecp_group_load)( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id ); - int (*_rom_mbedtls_ecp_tls_read_group)( mbedtls_ecp_group *grp, const unsigned char **buf, size_t len ); - int (*_rom_mbedtls_ecp_tls_read_group_id)( mbedtls_ecp_group_id *grp, const unsigned char **buf, size_t len ); - int (*_rom_mbedtls_ecp_tls_write_group)( const mbedtls_ecp_group *grp, size_t *olen, unsigned char *buf, size_t blen ); - int (*_rom_mbedtls_ecp_mul)( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - int (*_rom_mbedtls_ecp_mul_restartable)( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, mbedtls_ecp_restart_ctx *rs_ctx ); - int (*_rom_mbedtls_ecp_muladd)( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, const mbedtls_mpi *n, const mbedtls_ecp_point *Q ); - int (*_rom_mbedtls_ecp_muladd_restartable)( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, const mbedtls_mpi *n, const mbedtls_ecp_point *Q, mbedtls_ecp_restart_ctx *rs_ctx ); - int (*_rom_mbedtls_ecp_check_pubkey)( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt ); - int (*_rom_mbedtls_ecp_check_privkey)( const mbedtls_ecp_group *grp, const mbedtls_mpi *d ); - int (*_rom_mbedtls_ecp_gen_privkey)( const mbedtls_ecp_group *grp, mbedtls_mpi *d, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - int (*_rom_mbedtls_ecp_gen_keypair_base)( mbedtls_ecp_group *grp, const mbedtls_ecp_point *G, mbedtls_mpi *d, mbedtls_ecp_point *Q, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - int (*_rom_mbedtls_ecp_check_pub_priv)( const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv ); - int (*_rom_mbedtls_reserved0)(void); - int (*_rom_mbedtls_reserved1)(void); - int (*_rom_mbedtls_gcm_crypt_and_tag)( mbedtls_gcm_context *ctx, int mode, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, size_t tag_len, unsigned char *tag ); - int (*_rom_mbedtls_gcm_starts)( mbedtls_gcm_context *ctx, int mode, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len ); - int (*_rom_mbedtls_gcm_update)( mbedtls_gcm_context *ctx, size_t length, const unsigned char *input, unsigned char *output ); - int (*_rom_mbedtls_gcm_finish)( mbedtls_gcm_context *ctx, unsigned char *tag, size_t tag_len ); - void (*_rom_mbedtls_hmac_drbg_init)( mbedtls_hmac_drbg_context *ctx ); - int (*_rom_mbedtls_hmac_drbg_seed_buf)( mbedtls_hmac_drbg_context *ctx, const mbedtls_md_info_t * md_info, const unsigned char *data, size_t data_len ); - int (*_rom_mbedtls_hmac_drbg_update_ret)( mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t add_len ); - int (*_rom_mbedtls_hmac_drbg_reseed)( mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t len ); - int (*_rom_mbedtls_hmac_drbg_random_with_add)( void *p_rng, unsigned char *output, size_t output_len, const unsigned char *additional, size_t add_len ); - int (*_rom_mbedtls_hmac_drbg_random)( void *p_rng, unsigned char *output, size_t out_len ); - void (*_rom_mbedtls_hmac_drbg_free)( mbedtls_hmac_drbg_context *ctx ); - const int *(*_rom_mbedtls_md_list)( void ); - void (*_rom_mbedtls_md_init)( mbedtls_md_context_t *ctx ); - void (*_rom_mbedtls_md_free)( mbedtls_md_context_t *ctx ); - int (*_rom_mbedtls_md_setup)( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac ); - int (*_rom_mbedtls_md_clone)( mbedtls_md_context_t *dst, const mbedtls_md_context_t *src ); - unsigned char (*_rom_mbedtls_md_get_size)( const mbedtls_md_info_t *md_info ); - mbedtls_md_type_t (*_rom_mbedtls_md_get_type)( const mbedtls_md_info_t *md_info ); - int (*_rom_mbedtls_md_starts)( mbedtls_md_context_t *ctx ); - int (*_rom_mbedtls_md_update)( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ); - int (*_rom_mbedtls_md_finish)( mbedtls_md_context_t *ctx, unsigned char *output ); - int (*_rom_mbedtls_md)( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output ); - int (*_rom_mbedtls_md_hmac_starts)( mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen ); - int (*_rom_mbedtls_md_hmac_update)( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ); - int (*_rom_mbedtls_md_hmac_finish)( mbedtls_md_context_t *ctx, unsigned char *output); - int (*_rom_mbedtls_md_hmac_reset)( mbedtls_md_context_t *ctx ); - int (*_rom_mbedtls_oid_get_x509_ext_type)( const mbedtls_asn1_buf *oid, int *ext_type ); - int (*_rom_mbedtls_oid_get_pk_alg)( const mbedtls_asn1_buf *oid, mbedtls_pk_type_t *pk_alg ); - int (*_rom_mbedtls_oid_get_ec_grp)( const mbedtls_asn1_buf *oid, mbedtls_ecp_group_id *grp_id ); - int (*_rom_mbedtls_oid_get_sig_alg)( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg ); - int (*_rom_mbedtls_oid_get_md_alg)( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg ); - int (*_rom_mbedtls_oid_get_md_hmac)( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_hmac ); - int (*_rom_mbedtls_oid_get_oid_by_md)( mbedtls_md_type_t md_alg, const char **oid, size_t *olen ); - int (*_rom_mbedtls_oid_get_cipher_alg)( const mbedtls_asn1_buf *oid, mbedtls_cipher_type_t *cipher_alg ); - int (*_rom_mbedtls_oid_get_pkcs12_pbe_alg)( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg, mbedtls_cipher_type_t *cipher_alg ); - void (*_rom_mbedtls_pem_init)( void *ctx ); - void (*_rom_mbedtls_pem_free)( void *ctx ); - int (*_rom_mbedtls_pkcs12_pbe_sha1_rc4_128)( mbedtls_asn1_buf *pbe_params, int mode, const unsigned char *pwd, size_t pwdlen, const unsigned char *input, size_t len, unsigned char *output ); - int (*_rom_mbedtls_pkcs12_pbe)( mbedtls_asn1_buf *pbe_params, int mode, mbedtls_cipher_type_t cipher_type, mbedtls_md_type_t md_type, const unsigned char *pwd, size_t pwdlen, const unsigned char *input, size_t len, unsigned char *output ); - int (*_rom_mbedtls_pkcs12_derivation)( unsigned char *data, size_t datalen, const unsigned char *pwd, size_t pwdlen, const unsigned char *salt, size_t saltlen, mbedtls_md_type_t mbedtls_md, int id, int iterations ); - int (*_rom_mbedtls_pkcs5_pbes2)( const mbedtls_asn1_buf *pbe_params, int mode, const unsigned char *pwd, size_t pwdlen, const unsigned char *data, size_t datalen, unsigned char *output ); - int (*_rom_mbedtls_pkcs5_pbkdf2_hmac)( mbedtls_md_context_t *ctx, const unsigned char *password, size_t plen, const unsigned char *salt, size_t slen, unsigned int iteration_count, uint32_t key_length, unsigned char *output ); - const mbedtls_pk_info_t *(*_rom_mbedtls_pk_info_from_type)( mbedtls_pk_type_t pk_type ); - void (*_rom_mbedtls_pk_init)( mbedtls_pk_context *ctx ); - void (*_rom_mbedtls_pk_free)( mbedtls_pk_context *ctx ); - void (*_rom_mbedtls_pk_restart_init)( mbedtls_pk_restart_ctx *ctx ); - void (*_rom_mbedtls_pk_restart_free)( mbedtls_pk_restart_ctx *ctx ); - int (*_rom_mbedtls_pk_setup)( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info ); - int (*_rom_mbedtls_pk_can_do)( const mbedtls_pk_context *ctx, mbedtls_pk_type_t type ); - int (*_rom_mbedtls_pk_verify)( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len ); - int (*_rom_mbedtls_pk_verify_restartable)( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len, mbedtls_pk_restart_ctx *rs_ctx ); - int (*_rom_mbedtls_pk_verify_ext)( mbedtls_pk_type_t type, const void *options, mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len ); - int (*_rom_mbedtls_pk_sign_restartable)( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, unsigned char *sig, size_t *sig_len, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, mbedtls_pk_restart_ctx *rs_ctx ); - int (*_rom_mbedtls_pk_encrypt)( mbedtls_pk_context *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - mbedtls_pk_type_t (*_rom_mbedtls_pk_get_type)( const mbedtls_pk_context *ctx ); - int (*_rom_mbedtls_pk_parse_subpubkey)( unsigned char **p, const unsigned char *end, mbedtls_pk_context *pk ); - void (*_rom_mbedtls_rsa_init)( mbedtls_rsa_context *ctx ); - int (*_rom_mbedtls_rsa_import)( mbedtls_rsa_context *ctx, const mbedtls_mpi *N, const mbedtls_mpi *P, const mbedtls_mpi *Q, const mbedtls_mpi *D, const mbedtls_mpi *E ); - int (*_rom_mbedtls_rsa_import_raw)( mbedtls_rsa_context *ctx, unsigned char const *N, size_t N_len, unsigned char const *P, size_t P_len, unsigned char const *Q, size_t Q_len, unsigned char const *D, size_t D_len, unsigned char const *E, size_t E_len ); - int (*_rom_mbedtls_rsa_complete)( mbedtls_rsa_context *ctx ); - int (*_rom_mbedtls_rsa_set_padding)( mbedtls_rsa_context *ctx, int padding, mbedtls_md_type_t hash_id ); - size_t (*_rom_mbedtls_rsa_get_len)( const mbedtls_rsa_context *ctx ); - int (*_rom_mbedtls_rsa_check_pubkey)( const mbedtls_rsa_context *ctx ); - int (*_rom_mbedtls_rsa_check_privkey)( const mbedtls_rsa_context *ctx ); - int (*_rom_mbedtls_rsa_check_pub_priv)( const mbedtls_rsa_context *pub, const mbedtls_rsa_context *prv ); - int (*_rom_mbedtls_rsa_public)( mbedtls_rsa_context *ctx, const unsigned char *input, unsigned char *output ); - int (*_rom_mbedtls_rsa_private)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, const unsigned char *input, unsigned char *output ); - int (*_rom_mbedtls_rsa_pkcs1_encrypt)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, size_t ilen, const unsigned char *input, unsigned char *output ); - int (*_rom_mbedtls_rsa_rsaes_pkcs1_v15_encrypt)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, size_t ilen, const unsigned char *input, unsigned char *output ); - int (*_rom_mbedtls_rsa_rsaes_oaep_encrypt)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, const unsigned char *label, size_t label_len, size_t ilen, const unsigned char *input, unsigned char *output ); - int (*_rom_mbedtls_rsa_pkcs1_decrypt)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len ); - int (*_rom_mbedtls_rsa_rsaes_pkcs1_v15_decrypt)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len ); - int (*_rom_mbedtls_rsa_rsaes_oaep_decrypt)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, const unsigned char *label, size_t label_len, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len ); - int (*_rom_mbedtls_rsa_pkcs1_sign)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig ); - int (*_rom_mbedtls_rsa_rsassa_pkcs1_v15_sign)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig ); - int (*_rom_mbedtls_rsa_rsassa_pss_sign)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig ); - int (*_rom_mbedtls_rsa_pkcs1_verify)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, const unsigned char *sig ); - int (*_rom_mbedtls_rsa_rsassa_pkcs1_v15_verify)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, const unsigned char *sig ); - int (*_rom_mbedtls_rsa_rsassa_pss_verify)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, const unsigned char *sig ); - int (*_rom_mbedtls_rsa_rsassa_pss_verify_ext)( mbedtls_rsa_context *ctx, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, mbedtls_md_type_t mgf1_hash_id, int expected_salt_len, const unsigned char *sig ); - void (*_rom_mbedtls_rsa_free)( mbedtls_rsa_context *ctx ); - int (*_rom_mbedtls_rsa_deduce_primes)( mbedtls_mpi const *N, mbedtls_mpi const *E, mbedtls_mpi const *D, mbedtls_mpi *P, mbedtls_mpi *Q ); - int (*_rom_mbedtls_rsa_deduce_private_exponent)( mbedtls_mpi const *P, mbedtls_mpi const *Q, mbedtls_mpi const *E, mbedtls_mpi *D ); - int (*_rom_mbedtls_rsa_deduce_crt)( const mbedtls_mpi *P, const mbedtls_mpi *Q, const mbedtls_mpi *D, mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP ); - int (*_rom_mbedtls_rsa_validate_params)( const mbedtls_mpi *N, const mbedtls_mpi *P, const mbedtls_mpi *Q, const mbedtls_mpi *D, const mbedtls_mpi *E, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); - int (*_rom_mbedtls_rsa_validate_crt)( const mbedtls_mpi *P, const mbedtls_mpi *Q, const mbedtls_mpi *D, const mbedtls_mpi *DP, const mbedtls_mpi *DQ, const mbedtls_mpi *QP ); - void (*_rom_mbedtls_sha1_init)( mbedtls_sha1_context *ctx ); - void (*_rom_mbedtls_sha1_free)( mbedtls_sha1_context *ctx ); - void (*_rom_mbedtls_sha1_clone)( mbedtls_sha1_context *dst, const mbedtls_sha1_context *src ); - int (*_rom_mbedtls_sha1_starts)( mbedtls_sha1_context *ctx ); - int (*_rom_mbedtls_sha1_finish)( mbedtls_sha1_context *ctx, unsigned char output[20] ); - void (*_rom_mbedtls_sha256_init)( mbedtls_sha256_context *ctx ); - void (*_rom_mbedtls_sha256_free)( mbedtls_sha256_context *ctx ); - void (*_rom_mbedtls_sha256_clone)( mbedtls_sha256_context *dst, const mbedtls_sha256_context *src ); - int (*_rom_mbedtls_sha256_starts)( mbedtls_sha256_context *ctx, int is224 ); - int (*_rom_mbedtls_sha256_finish)( mbedtls_sha256_context *ctx, unsigned char output[32] ); - int (*_rom_mbedtls_sha256)( const unsigned char *input, size_t ilen, unsigned char output[32], int is224 ); - void (*_rom_mbedtls_sha512_init)( mbedtls_sha512_context *ctx ); - void (*_rom_mbedtls_sha512_free)( mbedtls_sha512_context *ctx ); - void (*_rom_mbedtls_sha512_clone)( mbedtls_sha512_context *dst, const mbedtls_sha512_context *src ); - int (*_rom_mbedtls_sha512_starts)( mbedtls_sha512_context *ctx, int is384 ); - int (*_rom_mbedtls_sha512_update)( mbedtls_sha512_context *ctx, const unsigned char *input, size_t ilen ); - int (*_rom_mbedtls_sha512_finish)( mbedtls_sha512_context *ctx, unsigned char output[64] ); - int (*_rom_mbedtls_internal_sha512_process)( mbedtls_sha512_context *ctx, const unsigned char data[128] ); - int (*_rom_mbedtls_sha512)( const unsigned char *input, size_t ilen, unsigned char output[64], int is384 ); - void (*_rom_mbedtls_ssl_conf_endpoint)( mbedtls_ssl_config *conf, int endpoint ); - void (*_rom_mbedtls_ssl_conf_transport)( mbedtls_ssl_config *conf, int transport ); - void (*_rom_mbedtls_ssl_set_bio)( mbedtls_ssl_context *ssl, void *p_bio, mbedtls_ssl_send_t *f_send, mbedtls_ssl_recv_t *f_recv, mbedtls_ssl_recv_timeout_t *f_recv_timeout ); - int (*_rom_mbedtls_ssl_conf_dh_param_bin)( mbedtls_ssl_config *conf, const unsigned char *dhm_P, size_t P_len, const unsigned char *dhm_G, size_t G_len ); - size_t (*_rom_mbedtls_ssl_get_max_frag_len)( const mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_get_max_out_record_payload)( const mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_handshake)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_handshake_step)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_renegotiate)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_send_alert_message)( mbedtls_ssl_context *ssl, unsigned char level, unsigned char message ); - int (*_rom_mbedtls_ssl_config_defaults)( mbedtls_ssl_config *conf, int endpoint, int transport, int preset ); - void (*_rom_mbedtls_ssl_session_init)( mbedtls_ssl_session *session ); - void (*_rom_mbedtls_ssl_session_free)( mbedtls_ssl_session *session ); - void (*_rom_mbedtls_ssl_transform_free)( mbedtls_ssl_transform *transform ); - void (*_rom_mbedtls_ssl_handshake_free)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_handshake_client_step)( mbedtls_ssl_context *ssl ); - void (*_rom_mbedtls_ssl_handshake_wrapup)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_derive_keys)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_handle_message_type)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_prepare_handshake_record)( mbedtls_ssl_context *ssl ); - void (*_rom_mbedtls_ssl_update_handshake_status)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_read_record)( mbedtls_ssl_context *ssl, unsigned update_hs_digest ); - int (*_rom_mbedtls_ssl_fetch_input)( mbedtls_ssl_context *ssl, size_t nb_want ); - int (*_rom_mbedtls_ssl_write_handshake_msg)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_write_record)( mbedtls_ssl_context *ssl, uint8_t force_flush ); - int (*_rom_mbedtls_ssl_flush_output)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_parse_certificate)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_write_certificate)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_parse_change_cipher_spec)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_write_change_cipher_spec)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_parse_finished)( mbedtls_ssl_context *ssl ); - int (*_rom_mbedtls_ssl_write_finished)( mbedtls_ssl_context *ssl ); - void (*_rom_mbedtls_ssl_optimize_checksum)( mbedtls_ssl_context *ssl, const mbedtls_ssl_ciphersuite_t *ciphersuite_info ); - int (*_rom_mbedtls_ssl_psk_derive_premaster)( mbedtls_ssl_context *ssl, mbedtls_key_exchange_type_t key_ex ); - unsigned char (*_rom_mbedtls_ssl_sig_from_pk)( mbedtls_pk_context *pk ); - mbedtls_pk_type_t (*_rom_mbedtls_ssl_pk_alg_from_sig)( unsigned char sig ); - mbedtls_md_type_t (*_rom_mbedtls_ssl_md_alg_from_hash)( unsigned char hash ); - unsigned char (*_rom_mbedtls_ssl_hash_from_md_alg)( int md ); - int (*_rom_mbedtls_ssl_check_curve)( const mbedtls_ssl_context *ssl, mbedtls_ecp_group_id grp_id ); - int (*_rom_mbedtls_ssl_check_sig_hash)( const mbedtls_ssl_context *ssl, mbedtls_md_type_t md ); - void (*_rom_mbedtls_ssl_write_version)( int major, int minor, int transport, unsigned char ver[2] ); - void (*_rom_mbedtls_ssl_read_version)( int *major, int *minor, int transport, const unsigned char ver[2] ); - int (*_rom_mbedtls_ssl_get_key_exchange_md_ssl_tls)( mbedtls_ssl_context *ssl, unsigned char *output, unsigned char *data, size_t data_len ); - int (*_rom_mbedtls_ssl_get_key_exchange_md_tls1_2)( mbedtls_ssl_context *ssl, unsigned char *hash, size_t *hashlen, unsigned char *data, size_t data_len, mbedtls_md_type_t md_alg ); - int (*_rom_mbedtls_ssl_cf_hmac)( mbedtls_md_context_t *ctx, const unsigned char *add_data, size_t add_data_len, const unsigned char *data, size_t data_len_secret, size_t min_data_len, size_t max_data_len, unsigned char *output ); - void (*_rom_mbedtls_ssl_cf_memcpy_offset)( unsigned char *dst, const unsigned char *src_base, size_t offset_secret, size_t offset_min, size_t offset_max, size_t len ); - int (*_rom_mbedtls_x509_crt_parse_der)( mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen ); - int (*_rom_mbedtls_x509_crt_verify_restartable)( mbedtls_x509_crt *crt, mbedtls_x509_crt *trust_ca, mbedtls_x509_crl *ca_crl, const mbedtls_x509_crt_profile *profile, const char *cn, uint32_t *flags, int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), void *p_vrfy, mbedtls_x509_crt_restart_ctx *rs_ctx ); - int (*_rom_mbedtls_x509_crt_check_key_usage)( const mbedtls_x509_crt *crt, unsigned int usage ); - int (*_rom_mbedtls_x509_crt_check_extended_key_usage)( const mbedtls_x509_crt *crt, const char *usage_oid, size_t usage_len ); - int (*_rom_mbedtls_x509_crt_is_revoked)( const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl ); - void (*_rom_mbedtls_x509_crt_init)( mbedtls_x509_crt *crt ); - void (*_rom_mbedtls_x509_crt_free)( mbedtls_x509_crt *crt ); - void (*_rom_mbedtls_x509_crt_restart_init)( mbedtls_x509_crt_restart_ctx *ctx ); - void (*_rom_mbedtls_x509_crt_restart_free)( mbedtls_x509_crt_restart_ctx *ctx ); - int (*_rom_mbedtls_x509_get_name)( unsigned char **p, const unsigned char *end, mbedtls_x509_name *cur ); - int (*_rom_mbedtls_x509_get_alg_null)( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *alg ); - int (*_rom_mbedtls_x509_get_alg)( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *alg, mbedtls_x509_buf *params ); - int (*_rom_mbedtls_x509_get_rsassa_pss_params)( const mbedtls_x509_buf *params, mbedtls_md_type_t *md_alg, mbedtls_md_type_t *mgf_md, int *salt_len ); - int (*_rom_mbedtls_x509_get_sig)( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig ); - int (*_rom_mbedtls_x509_get_sig_alg)( const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params, mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg, void **sig_opts ); - int (*_rom_mbedtls_x509_get_time)( unsigned char **p, const unsigned char *end, mbedtls_x509_time *t ); - int (*_rom_mbedtls_x509_get_serial)( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *serial ); - int (*_rom_mbedtls_x509_get_ext)( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *ext, int tag ); - void (*_mbedtls_mutex_init)( mbedtls_threading_mutex_t *mutex ); - void (*_mbedtls_mutex_free)( mbedtls_threading_mutex_t *mutex ); - int (*_mbedtls_mutex_lock)( mbedtls_threading_mutex_t *mutex ); - int (*_mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex ); - bool (*_mbedtls_allow_unsupported_critical_ext)( void ); - const mbedtls_cipher_info_t *(*_mbedtls_cipher_info_from_type)( const mbedtls_cipher_type_t cipher_type ); - const mbedtls_cipher_info_t *(*_mbedtls_cipher_info_from_values)( const mbedtls_cipher_id_t cipher_id, int key_bitlen, const mbedtls_cipher_mode_t mode ); - void (*_mbedtls_cipher_free)( mbedtls_cipher_context_t *ctx ); - int (*_mbedtls_cipher_setup)( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info ); - int (*_mbedtls_cipher_setkey)( mbedtls_cipher_context_t *ctx, const unsigned char *key, int key_bitlen, const mbedtls_operation_t operation ); - int (*_mbedtls_cipher_set_iv)( mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len ); - int (*_mbedtls_cipher_update)( mbedtls_cipher_context_t *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen ); - int (*_mbedtls_cipher_auth_encrypt)( mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, const unsigned char *ad, size_t ad_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, unsigned char *tag, size_t tag_len ); - int (*_mbedtls_cipher_auth_decrypt)( mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, const unsigned char *ad, size_t ad_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, const unsigned char *tag, size_t tag_len ); - int (*_mbedtls_hardware_poll)( void *data, unsigned char *output, size_t len, size_t *olen ); - const mbedtls_md_info_t *(*_mbedtls_md_info_from_type)( mbedtls_md_type_t md_type ); - int (*_mbedtls_pem_read_buffer)( void *ctx, const char *header, const char *footer, const unsigned char *data, const unsigned char *pwd, size_t pwdlen, size_t *use_len ); - void *(*_mbedtls_calloc)( size_t n, size_t size ); - void (*_mbedtls_free)( void *ptr ); - int (*_mbedtls_sha1_update)( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen ); - int (*_mbedtls_internal_sha1_process)( mbedtls_sha1_context *ctx, const unsigned char data[64] ); - int (*_mbedtls_sha256_update)( mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen ); - int (*_mbedtls_internal_sha256_process)( mbedtls_sha256_context *ctx, const unsigned char data[64] ); - const int *(*_mbedtls_ssl_list_ciphersuites)( void ); - const mbedtls_ssl_ciphersuite_t *(*_mbedtls_ssl_ciphersuite_from_id)( int ciphersuite_id ); - mbedtls_pk_type_t (*_mbedtls_ssl_get_ciphersuite_sig_pk_alg)( const mbedtls_ssl_ciphersuite_t *info ); - int (*_mbedtls_ssl_ciphersuite_uses_ec)( const mbedtls_ssl_ciphersuite_t *info ); - int (*_mbedtls_ssl_ciphersuite_uses_psk)( const mbedtls_ssl_ciphersuite_t *info ); - int (*_mbedtls_ssl_handshake_server_step)( mbedtls_ssl_context *ssl ); - int (*_mbedtls_ssl_check_cert_usage)( const mbedtls_x509_crt *cert, const mbedtls_ssl_ciphersuite_t *ciphersuite, int cert_endpoint, uint32_t *flags ); - int (*_mbedtls_x509_time_is_past)( const mbedtls_x509_time *to ); - int (*_mbedtls_x509_time_is_future)( const mbedtls_x509_time *from ); -} mbedtls_rom_funcs_t; - typedef struct mbedtls_rom_eco4_funcs { // aes module void (*_rom_mbedtls_aes_init)(mbedtls_aes_context *ctx); @@ -541,7 +171,6 @@ typedef struct mbedtls_rom_eco4_funcs { int (*_rom_mbedtls_ctr_drbg_random)(void *p_rng, unsigned char *output, size_t output_len); // base64 module int (*_rom_mbedtls_base64_decode)(unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen); - //*******************************************************************************************************************************************************************// // aes module int (*_rom_mbedtls_aes_crypt_cfb8)(mbedtls_aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output); // md5 module @@ -674,122 +303,6 @@ typedef struct mbedtls_rom_eco4_funcs { #error "MBEDTLS_PLATFORM_ZEROIZE_ALT" #endif -#ifndef BOOTLOADER_BUILD -/* sha1.c */ -STRUCT_OFFSET_CHECK(mbedtls_sha1_context, total, 0); -STRUCT_OFFSET_CHECK(mbedtls_sha1_context, state, 8); -STRUCT_OFFSET_CHECK(mbedtls_sha1_context, buffer, 28); -STRUCT_OFFSET_CHECK(mbedtls_sha1_context, first_block, 92); -STRUCT_OFFSET_CHECK(mbedtls_sha1_context, mode, 96); -STRUCT_OFFSET_CHECK(mbedtls_sha1_context, sha_state, 100); -STRUCT_SIZE_CHECK(mbedtls_sha1_context, 104); -#if !(defined(MBEDTLS_SHA1_C) || (defined(MBEDTLS_SHA1_ALT) && SOC_SHA_SUPPORT_SHA1)) -#error "MBEDTLS_SHA1_C" -#endif - -/* sha256.c */ -STRUCT_OFFSET_CHECK(mbedtls_sha256_context, total, 0); -STRUCT_OFFSET_CHECK(mbedtls_sha256_context, state, 8); -STRUCT_OFFSET_CHECK(mbedtls_sha256_context, buffer, 40); -STRUCT_OFFSET_CHECK(mbedtls_sha256_context, first_block, 104); -STRUCT_OFFSET_CHECK(mbedtls_sha256_context, mode, 108); -STRUCT_OFFSET_CHECK(mbedtls_sha256_context, sha_state, 112); -STRUCT_SIZE_CHECK(mbedtls_sha256_context, 116); -#if !(defined(MBEDTLS_SHA256_C) || (defined(MBEDTLS_SHA256_ALT) && SOC_SHA_SUPPORT_SHA256)) -#error "MBEDTLS_SHA256_C" -#endif - -/* sha512.c */ -STRUCT_OFFSET_CHECK(mbedtls_sha512_context, MBEDTLS_PRIVATE(total), 0); -STRUCT_OFFSET_CHECK(mbedtls_sha512_context, MBEDTLS_PRIVATE(state), 16); -STRUCT_OFFSET_CHECK(mbedtls_sha512_context, MBEDTLS_PRIVATE(buffer), 80); -STRUCT_OFFSET_CHECK(mbedtls_sha512_context, MBEDTLS_PRIVATE(is384), 208); -STRUCT_SIZE_CHECK(mbedtls_sha512_context, 216); -#if !(defined(MBEDTLS_SHA512_C) || (defined(MBEDTLS_SHA512_ALT) && SOC_SHA_SUPPORT_SHA512)) -#error "MBEDTLS_SHA512_C" -#endif - -/* aes.c */ -STRUCT_OFFSET_CHECK(mbedtls_aes_context, MBEDTLS_PRIVATE(nr), 0); -STRUCT_OFFSET_CHECK(mbedtls_aes_context, MBEDTLS_PRIVATE(rk_offset), 4); -STRUCT_OFFSET_CHECK(mbedtls_aes_context, MBEDTLS_PRIVATE(buf), 8); -STRUCT_SIZE_CHECK(mbedtls_aes_context, 280); -STRUCT_OFFSET_CHECK(mbedtls_aes_xts_context, MBEDTLS_PRIVATE(crypt), 0); -STRUCT_OFFSET_CHECK(mbedtls_aes_xts_context, MBEDTLS_PRIVATE(tweak), 280); -STRUCT_SIZE_CHECK(mbedtls_aes_xts_context, 560); -#if (defined(MBEDTLS_HAVE_X86)) || \ - (defined(MBEDTLS_HAVE_X86_64)) -#error "MBEDTLS_HAVE_X86" -#endif -#if (!defined(MBEDTLS_AES_C)) || \ - (defined(MBEDTLS_AES_ALT)) || \ - (defined(MBEDTLS_AES_ENCRYPT_ALT)) || \ - (defined(MBEDTLS_AES_DECRYPT_ALT)) || \ - (defined(MBEDTLS_AES_SETKEY_ENC_ALT)) || \ - (defined(MBEDTLS_AES_SETKEY_DEC_ALT)) -#error "MBEDTLS_AES_C" -#endif -#if (!defined(MBEDTLS_AES_ROM_TABLES)) || \ - (defined(MBEDTLS_AES_FEWER_TABLES)) -#error "MBEDTLS_AES_ROM_TABLES" -#endif -#if (!defined(MBEDTLS_CIPHER_MODE_XTS)) || \ - (!defined(MBEDTLS_CIPHER_MODE_CBC)) || \ - (!defined(MBEDTLS_CIPHER_MODE_CFB)) || \ - (!defined(MBEDTLS_CIPHER_MODE_OFB)) || \ - (!defined(MBEDTLS_CIPHER_MODE_CTR)) -#error "MBEDTLS_CIPHER_MODE" -#endif - -/* asn1parse.c asn1write.c */ -STRUCT_OFFSET_CHECK(mbedtls_asn1_buf, tag, 0); -STRUCT_OFFSET_CHECK(mbedtls_asn1_buf, len, 4); -STRUCT_OFFSET_CHECK(mbedtls_asn1_buf, p, 8); -STRUCT_SIZE_CHECK(mbedtls_asn1_buf, 12); -STRUCT_OFFSET_CHECK(mbedtls_asn1_bitstring, len, 0); -STRUCT_OFFSET_CHECK(mbedtls_asn1_bitstring, unused_bits, 4); -STRUCT_OFFSET_CHECK(mbedtls_asn1_bitstring, p, 8); -STRUCT_SIZE_CHECK(mbedtls_asn1_bitstring, 12); -STRUCT_OFFSET_CHECK(mbedtls_asn1_sequence, buf, 0); -STRUCT_OFFSET_CHECK(mbedtls_asn1_sequence, next, 12); -STRUCT_SIZE_CHECK(mbedtls_asn1_sequence, 16); -STRUCT_OFFSET_CHECK(mbedtls_asn1_named_data, oid, 0); -STRUCT_OFFSET_CHECK(mbedtls_asn1_named_data, val, 12); -STRUCT_OFFSET_CHECK(mbedtls_asn1_named_data, next, 24); -STRUCT_OFFSET_CHECK(mbedtls_asn1_named_data, MBEDTLS_PRIVATE(next_merged), 28); -STRUCT_SIZE_CHECK(mbedtls_asn1_named_data, 32); -#if (!defined(MBEDTLS_ASN1_PARSE_C)) -#error "MBEDTLS_ASN1_PARSE_C" -#endif -#if (!defined(MBEDTLS_ASN1_WRITE_C)) -#error "MBEDTLS_ASN1_PARSE_C" -#endif - -/* base64.c */ -#if (!defined(MBEDTLS_BASE64_C)) -#error "MBEDTLS_BASE64_C" -#endif - -/* md5.c */ -#if (defined(MBEDTLS_MD2_C)) || \ - (defined(MBEDTLS_MD4_C)) || \ - (!defined(MBEDTLS_MD5_C)) /* || \ - (defined(MBEDTLS_MD5_ALT)) */ -#error "MBEDTLS_MD_C" -#endif -#ifdef CONFIG_MBEDTLS_ROM_MD5 -STRUCT_OFFSET_CHECK(mbedtls_md5_context, total, 0); -STRUCT_OFFSET_CHECK(mbedtls_md5_context, state, 8); -STRUCT_OFFSET_CHECK(mbedtls_md5_context, buffer, 24); -STRUCT_SIZE_CHECK(mbedtls_md5_context, 88); -#else -STRUCT_OFFSET_CHECK(mbedtls_md5_context, MBEDTLS_PRIVATE(total), 0); -STRUCT_OFFSET_CHECK(mbedtls_md5_context, MBEDTLS_PRIVATE(state), 8); -STRUCT_OFFSET_CHECK(mbedtls_md5_context, MBEDTLS_PRIVATE(buffer), 24); -STRUCT_SIZE_CHECK(mbedtls_md5_context, 88); -#endif -#endif /* BOOTLOADER_BUILD */ - #if BOOTLOADER_BUILD void mbedtls_rom_osi_functions_init_bootloader(void); #endif /* BOOTLOADER_BUILD */ diff --git a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi_bootloader.c b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi_bootloader.c index 2c730a9ff77..0ea46f9591f 100644 --- a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi_bootloader.c +++ b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi_bootloader.c @@ -1,27 +1,11 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/chip_revision.h" -#include "hal/efuse_hal.h" #include "mbedtls_rom_osi.h" -/* This structure can be automatically generated by the script with rom.mbedtls.ld. */ -static const mbedtls_rom_funcs_t mbedtls_rom_funcs_table = { - /* Fill the ROM functions into mbedtls rom function table. */ - /* aes module */ - ._rom_mbedtls_aes_init = mbedtls_aes_init, - ._rom_mbedtls_aes_free = mbedtls_aes_free, - ._rom_mbedtls_aes_setkey_enc = mbedtls_aes_setkey_enc, - ._rom_mbedtls_aes_setkey_dec = mbedtls_aes_setkey_dec, - ._rom_mbedtls_aes_crypt_ecb = mbedtls_aes_crypt_ecb, - ._rom_mbedtls_aes_crypt_cbc = mbedtls_aes_crypt_cbc, - ._rom_mbedtls_internal_aes_encrypt = mbedtls_internal_aes_encrypt, - ._rom_mbedtls_internal_aes_decrypt = mbedtls_internal_aes_decrypt, -}; - /* This structure can be automatically generated by the script with rom.mbedtls.ld. */ static const mbedtls_rom_eco4_funcs_t mbedtls_rom_eco4_funcs_table = { /* Fill the ROM functions into mbedtls rom function table. */ @@ -46,13 +30,6 @@ void mbedtls_rom_osi_functions_init_bootloader(void) { // /* Export the rom mbedtls functions table pointer */ extern void *mbedtls_rom_osi_funcs_ptr; - - unsigned chip_version = efuse_hal_chip_revision(); - if ( ESP_CHIP_REV_ABOVE(chip_version, 200) ) { - /* Initialize the pointer of rom eco4 mbedtls functions table. */ - mbedtls_rom_osi_funcs_ptr = (mbedtls_rom_eco4_funcs_t *)&mbedtls_rom_eco4_funcs_table; - } else { - /* Initialize the pointer of rom mbedtls functions table. */ - mbedtls_rom_osi_funcs_ptr = (mbedtls_rom_funcs_t *)&mbedtls_rom_funcs_table; - } + /* Initialize the pointer of rom eco4 mbedtls functions table. */ + mbedtls_rom_osi_funcs_ptr = (mbedtls_rom_eco4_funcs_t *)&mbedtls_rom_eco4_funcs_table; } From 6eb7f181a2cec979946f3d7767386168d6af6e59 Mon Sep 17 00:00:00 2001 From: Jiang Guang Ming Date: Wed, 6 May 2026 19:52:43 +0800 Subject: [PATCH 2/6] feat(mbedtls): enable ROM mbedTLS pytest with esp32c2 rev2.0 --- components/mbedtls/CMakeLists.txt | 1 + components/mbedtls/Kconfig | 5 ++-- .../test_apps/mbedtls_ut/pytest_mbedtls_ut.py | 25 ++++++++++--------- .../mbedtls_ut/sdkconfig.ci.rom_impl | 5 ++-- .../sdkconfig.defaults.esp32c2 | 1 + .../https_request/pytest_https_request.py | 1 + .../sdkconfig.ci.esp32c2_rom_mbedtls | 4 +-- examples/storage/nvs/.build-test-rules.yml | 3 --- examples/storage/nvs/nvs_bootloader/README.md | 4 +-- .../nvs_bootloader/sdkconfig.defaults.esp32c2 | 1 + 10 files changed, 26 insertions(+), 24 deletions(-) diff --git a/components/mbedtls/CMakeLists.txt b/components/mbedtls/CMakeLists.txt index e3f64f019f7..55fb96281d5 100644 --- a/components/mbedtls/CMakeLists.txt +++ b/components/mbedtls/CMakeLists.txt @@ -8,6 +8,7 @@ if(esp_tee_build) elseif(BOOTLOADER_BUILD) # TODO: IDF-11673 if(CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL_BOOTLOADER) set(include_dirs "${COMPONENT_DIR}/mbedtls/include" + "${COMPONENT_DIR}/mbedtls/tf-psa-crypto/drivers/builtin/include" "port/mbedtls_rom") set(srcs "port/mbedtls_rom/mbedtls_rom_osi_bootloader.c") endif() diff --git a/components/mbedtls/Kconfig b/components/mbedtls/Kconfig index 255d4581c90..58d465ae134 100644 --- a/components/mbedtls/Kconfig +++ b/components/mbedtls/Kconfig @@ -1601,8 +1601,7 @@ menu "mbedTLS" config MBEDTLS_USE_CRYPTO_ROM_IMPL_BOOTLOADER bool "Use ROM implementation of the crypto algorithm in the bootloader" - # TODO: IDF-15012 - depends on ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB && !MBEDTLS_VER_4_X_SUPPORT + depends on ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB && ESP32C2_REV_MIN_200 default "n" select MBEDTLS_AES_C help @@ -1613,7 +1612,7 @@ menu "mbedTLS" config MBEDTLS_USE_CRYPTO_ROM_IMPL bool "Use ROM implementation of the crypto algorithm" - depends on ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB + depends on ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB && ESP32C2_REV_MIN_200 default "n" select MBEDTLS_SHA512_C select MBEDTLS_AES_C diff --git a/components/mbedtls/test_apps/mbedtls_ut/pytest_mbedtls_ut.py b/components/mbedtls/test_apps/mbedtls_ut/pytest_mbedtls_ut.py index 78392bb6014..97faf924d3c 100644 --- a/components/mbedtls/test_apps/mbedtls_ut/pytest_mbedtls_ut.py +++ b/components/mbedtls/test_apps/mbedtls_ut/pytest_mbedtls_ut.py @@ -117,18 +117,19 @@ def test_mbedtls_hmac_opaque(dut: Dut) -> None: dut.run_all_single_board_cases(group='efuse_hmac_key') -# TODO: IDF-15012 -# @pytest.mark.generic -# @pytest.mark.parametrize( -# 'config', -# [ -# 'rom_impl', -# ], -# indirect=True, -# ) -# @idf_parametrize('target', ['esp32c2'], indirect=['target']) -# def test_mbedtls_rom_impl_esp32c2(dut: Dut) -> None: -# dut.run_all_single_board_cases() +@pytest.mark.esp32c2_rev2 +@pytest.mark.xtal_26mhz +@pytest.mark.generic +@pytest.mark.parametrize( + 'config, baud', + [ + ('rom_impl', '74880'), + ], + indirect=True, +) +@idf_parametrize('target', ['esp32c2'], indirect=['target']) +def test_mbedtls_rom_impl_esp32c2(dut: Dut) -> None: + dut.run_all_single_board_cases() @pytest.mark.generic diff --git a/components/mbedtls/test_apps/mbedtls_ut/sdkconfig.ci.rom_impl b/components/mbedtls/test_apps/mbedtls_ut/sdkconfig.ci.rom_impl index 53574d1c42d..44cf92ee55d 100644 --- a/components/mbedtls/test_apps/mbedtls_ut/sdkconfig.ci.rom_impl +++ b/components/mbedtls/test_apps/mbedtls_ut/sdkconfig.ci.rom_impl @@ -1,3 +1,4 @@ CONFIG_IDF_TARGET="esp32c2" -# TODO: IDF-15012 -# CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL=y +CONFIG_XTAL_FREQ_26=y +CONFIG_ESP32C2_REV_MIN_200=y +CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL=y diff --git a/components/nvs_flash/test_apps_bootloader/sdkconfig.defaults.esp32c2 b/components/nvs_flash/test_apps_bootloader/sdkconfig.defaults.esp32c2 index 5e3a3c88f46..6b1f01f17c8 100644 --- a/components/nvs_flash/test_apps_bootloader/sdkconfig.defaults.esp32c2 +++ b/components/nvs_flash/test_apps_bootloader/sdkconfig.defaults.esp32c2 @@ -1,2 +1,3 @@ CONFIG_IDF_TARGET="esp32c2" +CONFIG_ESP32C2_REV_MIN_200=y CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL_BOOTLOADER=y diff --git a/examples/protocols/https_request/pytest_https_request.py b/examples/protocols/https_request/pytest_https_request.py index c4dfc541323..122e8a89532 100644 --- a/examples/protocols/https_request/pytest_https_request.py +++ b/examples/protocols/https_request/pytest_https_request.py @@ -389,6 +389,7 @@ def test_examples_protocol_https_request(dut: Dut) -> None: @pytest.mark.wifi_ap +@pytest.mark.esp32c2_rev2 @pytest.mark.xtal_26mhz @pytest.mark.parametrize( 'config, baud', diff --git a/examples/protocols/https_request/sdkconfig.ci.esp32c2_rom_mbedtls b/examples/protocols/https_request/sdkconfig.ci.esp32c2_rom_mbedtls index 04000befa49..73f8dcc658d 100644 --- a/examples/protocols/https_request/sdkconfig.ci.esp32c2_rom_mbedtls +++ b/examples/protocols/https_request/sdkconfig.ci.esp32c2_rom_mbedtls @@ -1,6 +1,6 @@ CONFIG_IDF_TARGET="esp32c2" CONFIG_XTAL_FREQ_26=y +CONFIG_ESP32C2_REV_MIN_200=y CONFIG_EXAMPLE_CONNECT_WIFI=y CONFIG_EXAMPLE_WIFI_SSID_PWD_FROM_STDIN=y -# TODO: IDF-15012 -CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL=n +CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL=y diff --git a/examples/storage/nvs/.build-test-rules.yml b/examples/storage/nvs/.build-test-rules.yml index 24f56e4dae4..4ff9b1bb989 100644 --- a/examples/storage/nvs/.build-test-rules.yml +++ b/examples/storage/nvs/.build-test-rules.yml @@ -9,9 +9,6 @@ examples/storage/nvs/nvs_bootloader: - if: CONFIG_NAME == "nvs_enc_flash_enc" and (SOC_AES_SUPPORTED != 1 and ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB != 1) - if: CONFIG_NAME == "nvs_enc_hmac" and (SOC_HMAC_SUPPORTED != 1 or (SOC_HMAC_SUPPORTED == 1 and (SOC_AES_SUPPORTED != 1 and ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB != 1))) reason: As of now in such cases, we do not have any way to perform AES operations in the bootloader build - # TODO: IDF-15012 - - if: IDF_TARGET in ["esp32c2"] - reason: PSA is not yet available for ESP32-C2 examples/storage/nvs/nvs_console: depends_components: diff --git a/examples/storage/nvs/nvs_bootloader/README.md b/examples/storage/nvs/nvs_bootloader/README.md index 50d209cd546..8d1f7dda6b1 100644 --- a/examples/storage/nvs/nvs_bootloader/README.md +++ b/examples/storage/nvs/nvs_bootloader/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- | # NVS Bootloader diff --git a/examples/storage/nvs/nvs_bootloader/sdkconfig.defaults.esp32c2 b/examples/storage/nvs/nvs_bootloader/sdkconfig.defaults.esp32c2 index 5e3a3c88f46..6b1f01f17c8 100644 --- a/examples/storage/nvs/nvs_bootloader/sdkconfig.defaults.esp32c2 +++ b/examples/storage/nvs/nvs_bootloader/sdkconfig.defaults.esp32c2 @@ -1,2 +1,3 @@ CONFIG_IDF_TARGET="esp32c2" +CONFIG_ESP32C2_REV_MIN_200=y CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL_BOOTLOADER=y From 3fdf8eba84baba0a1d740dedc17854472f12e56d Mon Sep 17 00:00:00 2001 From: Jiang Guang Ming Date: Wed, 6 May 2026 20:02:44 +0800 Subject: [PATCH 3/6] docs(mbedtls): update docs with CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL --- docs/en/api-guides/performance/size.rst | 1 + docs/zh_CN/api-guides/performance/size.rst | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/en/api-guides/performance/size.rst b/docs/en/api-guides/performance/size.rst index 3ed85bed7b0..88156f6cbda 100644 --- a/docs/en/api-guides/performance/size.rst +++ b/docs/en/api-guides/performance/size.rst @@ -242,6 +242,7 @@ The help text for each option has some more information for reference. .. only:: CONFIG_ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB Enabling the config option :ref:`CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL` will use the crypto algorithms from mbedTLS library inside the chip ROM. + This option is available only when the selected target and minimum chip revision support the ROM mbedTLS crypto library. Disabling the config option :ref:`CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL` will use the crypto algorithms from the ESP-IDF mbedtls component library. This will increase the binary size (flash footprint). diff --git a/docs/zh_CN/api-guides/performance/size.rst b/docs/zh_CN/api-guides/performance/size.rst index bb1f9bb38da..83d13208e55 100644 --- a/docs/zh_CN/api-guides/performance/size.rst +++ b/docs/zh_CN/api-guides/performance/size.rst @@ -241,8 +241,9 @@ MbedTLS 功能 .. only:: CONFIG_ESP_ROM_HAS_MBEDTLS_CRYPTO_LIB 启用配置选项 :ref:`CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL` 时 mbedtls 使用由 ROM 提供的加密算法。 + 该选项仅在所选目标芯片和最低芯片版本支持 ROM mbedTLS 加密算法库时可用。 - 禁用配置选项 :ref:`CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL` 时mbedtls 完全使用由 ESP-IDF 中提供的加密算法。这会导致二进制文件大小增加。 + 禁用配置选项 :ref:`CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL` 时,mbedtls 完全使用由 ESP-IDF 中提供的加密算法。这会导致二进制文件大小增加。 .. note:: From 61cd10bf7671d71c24db63b216184ac3b07bd507 Mon Sep 17 00:00:00 2001 From: Jiang Guang Ming Date: Thu, 7 May 2026 11:56:11 +0800 Subject: [PATCH 4/6] feat(esp_rom): merge rom.mbedtls.ld to rom.mbedtls.eco4.ld --- components/esp_rom/CMakeLists.txt | 10 +- .../esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld | 91 ++++++++++++++- .../esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.ld | 105 ------------------ 3 files changed, 92 insertions(+), 114 deletions(-) delete mode 100644 components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.ld diff --git a/components/esp_rom/CMakeLists.txt b/components/esp_rom/CMakeLists.txt index 2bde986745d..008be9eeff0 100644 --- a/components/esp_rom/CMakeLists.txt +++ b/components/esp_rom/CMakeLists.txt @@ -192,11 +192,8 @@ if(BOOTLOADER_BUILD) endif() if(CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL_BOOTLOADER) - rom_linker_script("mbedtls") # For ESP32C2(ECO4), mbedTLS in ROM has been updated to v3.6.0-LTS - if(CONFIG_ESP32C2_REV_MIN_FULL GREATER_EQUAL 200) - rom_linker_script("mbedtls.eco4") - endif() + rom_linker_script("mbedtls.eco4") endif() else() # Regular app build @@ -408,11 +405,8 @@ else() # Regular app build endif() if(CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL) - rom_linker_script("mbedtls") # For ESP32C2(ECO4), mbedTLS in ROM has been updated to v3.6.0-LTS - if(CONFIG_ESP32C2_REV_MIN_FULL GREATER_EQUAL 200) - rom_linker_script("mbedtls.eco4") - endif() + rom_linker_script("mbedtls.eco4") endif() if(CONFIG_ESP_ROM_DELAY_US_PATCH AND CONFIG_SECURE_ENABLE_TEE AND diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld index f015e92527d..53b9bacc5cb 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld @@ -4,6 +4,96 @@ * SPDX-License-Identifier: Apache-2.0 */ +/*************************************** + Group rom_mbedtls + ***************************************/ + +/* Functions */ +mbedtls_aes_init = 0x40002664; +mbedtls_aes_free = 0x40002688; +mbedtls_aes_setkey_enc = 0x4000268c; +mbedtls_aes_setkey_dec = 0x40002690; +mbedtls_aes_crypt_ecb = 0x40002694; +mbedtls_aes_crypt_cbc = 0x40002698; +mbedtls_internal_aes_encrypt = 0x4000269c; +mbedtls_internal_aes_decrypt = 0x400026a0; +mbedtls_asn1_get_len = 0x400026a4; +mbedtls_asn1_get_tag = 0x400026a8; +mbedtls_asn1_get_bool = 0x400026ac; +mbedtls_asn1_get_int = 0x400026b0; +mbedtls_asn1_get_bitstring = 0x400026b4; +mbedtls_asn1_get_bitstring_null = 0x400026b8; +mbedtls_asn1_get_sequence_of = 0x400026bc; +mbedtls_asn1_get_mpi = 0x400026c0; +mbedtls_asn1_get_alg = 0x400026c4; +mbedtls_asn1_get_alg_null = 0x400026c8; +mbedtls_asn1_write_len = 0x400026cc; +mbedtls_asn1_write_tag = 0x400026d0; +mbedtls_asn1_write_mpi = 0x400026d4; +mbedtls_base64_decode = 0x400026d8; +mbedtls_ccm_star_encrypt_and_tag = 0x40002774; +mbedtls_ccm_star_auth_decrypt = 0x40002778; +mbedtls_ctr_drbg_init = 0x4000279c; +mbedtls_ctr_drbg_seed = 0x400027a0; +mbedtls_ctr_drbg_free = 0x400027a4; +mbedtls_ctr_drbg_reseed = 0x400027a8; +mbedtls_ctr_drbg_random_with_add = 0x400027ac; +mbedtls_ctr_drbg_random = 0x400027b0; +mbedtls_sha1_init = 0x40002a1c; +mbedtls_sha1_free = 0x40002a20; +mbedtls_sha1_clone = 0x40002a24; +mbedtls_sha1_starts = 0x40002a28; +mbedtls_sha1_finish = 0x40002a2c; +mbedtls_sha256_init = 0x40002a30; +mbedtls_sha256_free = 0x40002a34; +mbedtls_sha256_clone = 0x40002a38; +mbedtls_sha256_starts = 0x40002a3c; +mbedtls_sha256_finish = 0x40002a40; +mbedtls_sha256 = 0x40002a44; +mbedtls_sha512_init = 0x40002a48; +mbedtls_sha512_free = 0x40002a4c; +mbedtls_sha512_clone = 0x40002a50; +mbedtls_sha512_starts = 0x40002a54; +mbedtls_sha512_update = 0x40002a58; +mbedtls_sha512_finish = 0x40002a5c; +/*mbedtls_internal_sha512_process = 0x40002a60;*/ +mbedtls_sha512 = 0x40002a64; +mbedtls_aes_xts_init = 0x40002b68; +mbedtls_aes_xts_free = 0x40002b6c; +mbedtls_aes_xts_setkey_enc = 0x40002b70; +mbedtls_aes_xts_setkey_dec = 0x40002b74; +mbedtls_aes_crypt_xts = 0x40002b78; +mbedtls_aes_crypt_cfb128 = 0x40002b7c; +mbedtls_aes_crypt_ofb = 0x40002b80; +mbedtls_aes_crypt_ctr = 0x40002b84; +mbedtls_ccm_init = 0x40002b98; +mbedtls_ccm_setkey = 0x40002b9c; +mbedtls_ccm_free = 0x40002ba0; +mbedtls_ccm_encrypt_and_tag = 0x40002ba4; +mbedtls_ccm_auth_decrypt = 0x40002ba8; +mbedtls_md5_init = 0x40002bd8; +mbedtls_md5_free = 0x40002bdc; +mbedtls_md5_clone = 0x40002be0; +mbedtls_md5_starts = 0x40002be4; +mbedtls_md5_update = 0x40002be8; +mbedtls_md5_finish = 0x40002bec; +/*mbedtls_internal_md5_process = 0x40002bf0;*/ +mbedtls_md5 = 0x40002bf4; +mbedtls_sha1 = 0x40002c08; +/* Data (.data, .bss, .rodata) */ +mbedtls_rom_osi_funcs_ptr = 0x3fcdfaa0; +AES_FSb_ptr = 0x3fcdfa9c; +AES_RT0_ptr = 0x3fcdfa98; +AES_RT1_ptr = 0x3fcdfa94; +AES_RT2_ptr = 0x3fcdfa90; +AES_RT3_ptr = 0x3fcdfa8c; +AES_FT0_ptr = 0x3fcdfa88; +AES_FT1_ptr = 0x3fcdfa84; +AES_FT2_ptr = 0x3fcdfa80; +AES_FT3_ptr = 0x3fcdfa7c; +bignum_small_prime_ptr = 0x3fcdfa78; +sha512_K_ptr = 0x3fcdfa74; + /*************************************** Group eco4_rom_mbedtls ***************************************/ @@ -48,7 +138,6 @@ mbedtls_mpi_gcd = 0x40002768; mbedtls_mpi_inv_mod = 0x4000276c; mbedtls_mpi_is_prime_ext = 0x40002770; -/* Moved from mbedtls.ld to mbedtls.eco4 ld */ mbedtls_cipher_init = 0x4000277c; mbedtls_cipher_set_padding_mode = 0x40002780; mbedtls_cipher_reset = 0x40002784; diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.ld deleted file mode 100644 index 20182027d66..00000000000 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.ld +++ /dev/null @@ -1,105 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* ROM function interface esp32c2.rom.mbedtls.ld for esp32c2 - * - * - * Generated from ./interface-esp32c2.yml md5sum c679b6ed5e9f0a9c3e7b93e5e0f2a1a3 - * - * Compatible with ROM where ECO version equal or greater to 1. - * - * THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT. - */ - -/*************************************** - Group rom_mbedtls - ***************************************/ - -/* Functions */ -mbedtls_aes_init = 0x40002664; -mbedtls_aes_free = 0x40002688; -mbedtls_aes_setkey_enc = 0x4000268c; -mbedtls_aes_setkey_dec = 0x40002690; -mbedtls_aes_crypt_ecb = 0x40002694; -mbedtls_aes_crypt_cbc = 0x40002698; -mbedtls_internal_aes_encrypt = 0x4000269c; -mbedtls_internal_aes_decrypt = 0x400026a0; -mbedtls_asn1_get_len = 0x400026a4; -mbedtls_asn1_get_tag = 0x400026a8; -mbedtls_asn1_get_bool = 0x400026ac; -mbedtls_asn1_get_int = 0x400026b0; -mbedtls_asn1_get_bitstring = 0x400026b4; -mbedtls_asn1_get_bitstring_null = 0x400026b8; -mbedtls_asn1_get_sequence_of = 0x400026bc; -mbedtls_asn1_get_mpi = 0x400026c0; -mbedtls_asn1_get_alg = 0x400026c4; -mbedtls_asn1_get_alg_null = 0x400026c8; -mbedtls_asn1_write_len = 0x400026cc; -mbedtls_asn1_write_tag = 0x400026d0; -mbedtls_asn1_write_mpi = 0x400026d4; -mbedtls_base64_decode = 0x400026d8; -mbedtls_ccm_star_encrypt_and_tag = 0x40002774; -mbedtls_ccm_star_auth_decrypt = 0x40002778; -mbedtls_ctr_drbg_init = 0x4000279c; -mbedtls_ctr_drbg_seed = 0x400027a0; -mbedtls_ctr_drbg_free = 0x400027a4; -mbedtls_ctr_drbg_reseed = 0x400027a8; -mbedtls_ctr_drbg_random_with_add = 0x400027ac; -mbedtls_ctr_drbg_random = 0x400027b0; -mbedtls_sha1_init = 0x40002a1c; -mbedtls_sha1_free = 0x40002a20; -mbedtls_sha1_clone = 0x40002a24; -mbedtls_sha1_starts = 0x40002a28; -mbedtls_sha1_finish = 0x40002a2c; -mbedtls_sha256_init = 0x40002a30; -mbedtls_sha256_free = 0x40002a34; -mbedtls_sha256_clone = 0x40002a38; -mbedtls_sha256_starts = 0x40002a3c; -mbedtls_sha256_finish = 0x40002a40; -mbedtls_sha256 = 0x40002a44; -mbedtls_sha512_init = 0x40002a48; -mbedtls_sha512_free = 0x40002a4c; -mbedtls_sha512_clone = 0x40002a50; -mbedtls_sha512_starts = 0x40002a54; -mbedtls_sha512_update = 0x40002a58; -mbedtls_sha512_finish = 0x40002a5c; -/*mbedtls_internal_sha512_process = 0x40002a60;*/ -mbedtls_sha512 = 0x40002a64; -mbedtls_aes_xts_init = 0x40002b68; -mbedtls_aes_xts_free = 0x40002b6c; -mbedtls_aes_xts_setkey_enc = 0x40002b70; -mbedtls_aes_xts_setkey_dec = 0x40002b74; -mbedtls_aes_crypt_xts = 0x40002b78; -mbedtls_aes_crypt_cfb128 = 0x40002b7c; -mbedtls_aes_crypt_ofb = 0x40002b80; -mbedtls_aes_crypt_ctr = 0x40002b84; -mbedtls_ccm_init = 0x40002b98; -mbedtls_ccm_setkey = 0x40002b9c; -mbedtls_ccm_free = 0x40002ba0; -mbedtls_ccm_encrypt_and_tag = 0x40002ba4; -mbedtls_ccm_auth_decrypt = 0x40002ba8; -mbedtls_md5_init = 0x40002bd8; -mbedtls_md5_free = 0x40002bdc; -mbedtls_md5_clone = 0x40002be0; -mbedtls_md5_starts = 0x40002be4; -mbedtls_md5_update = 0x40002be8; -mbedtls_md5_finish = 0x40002bec; -/*mbedtls_internal_md5_process = 0x40002bf0;*/ -mbedtls_md5 = 0x40002bf4; -mbedtls_sha1 = 0x40002c08; -/* Data (.data, .bss, .rodata) */ -mbedtls_rom_osi_funcs_ptr = 0x3fcdfaa0; -AES_FSb_ptr = 0x3fcdfa9c; -AES_RT0_ptr = 0x3fcdfa98; -AES_RT1_ptr = 0x3fcdfa94; -AES_RT2_ptr = 0x3fcdfa90; -AES_RT3_ptr = 0x3fcdfa8c; -AES_FT0_ptr = 0x3fcdfa88; -AES_FT1_ptr = 0x3fcdfa84; -AES_FT2_ptr = 0x3fcdfa80; -AES_FT3_ptr = 0x3fcdfa7c; -bignum_small_prime_ptr = 0x3fcdfa78; -sha512_K_ptr = 0x3fcdfa74; From dd28e303d5fd0fe7114d41ddb117e357b3199bc1 Mon Sep 17 00:00:00 2001 From: Jiang Guang Ming Date: Thu, 7 May 2026 14:18:54 +0800 Subject: [PATCH 5/6] fix(mbedtls): support ROM mbedTLS crypto in bootloader --- components/mbedtls/CMakeLists.txt | 11 ++- .../port/mbedtls_rom/mbedtls_rom_osi.h | 8 --- .../mbedtls_rom/mbedtls_rom_osi_bootloader.c | 69 +++++++++++++++---- components/nvs_flash/src/nvs_bootloader.c | 2 +- 4 files changed, 66 insertions(+), 24 deletions(-) diff --git a/components/mbedtls/CMakeLists.txt b/components/mbedtls/CMakeLists.txt index 55fb96281d5..7ae5daadef6 100644 --- a/components/mbedtls/CMakeLists.txt +++ b/components/mbedtls/CMakeLists.txt @@ -7,15 +7,24 @@ if(esp_tee_build) return() elseif(BOOTLOADER_BUILD) # TODO: IDF-11673 if(CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL_BOOTLOADER) - set(include_dirs "${COMPONENT_DIR}/mbedtls/include" + set(include_dirs "${COMPONENT_DIR}/port/include" + "${COMPONENT_DIR}/mbedtls/include" + "${COMPONENT_DIR}/mbedtls/tf-psa-crypto/include" "${COMPONENT_DIR}/mbedtls/tf-psa-crypto/drivers/builtin/include" + "${COMPONENT_DIR}/port/psa_driver/include" "port/mbedtls_rom") set(srcs "port/mbedtls_rom/mbedtls_rom_osi_bootloader.c") + set(public_compile_definitions + -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" + MBEDTLS_CIPHER_MODE_XTS) endif() idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" PRIV_REQUIRES esp_hal_dma) + if(public_compile_definitions) + target_compile_definitions(${COMPONENT_LIB} PUBLIC ${public_compile_definitions}) + endif() return() endif() diff --git a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.h b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.h index 47f755d556c..9d53887cecb 100644 --- a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.h +++ b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.h @@ -31,7 +31,6 @@ extern "C" { #endif -#ifndef BOOTLOADER_BUILD #if (!defined(CONFIG_MBEDTLS_THREADING_C)) #error CONFIG_MBEDTLS_THREADING_C #endif @@ -40,9 +39,6 @@ typedef void (*_rom_mbedtls_threading_set_alt_t)(void (*mutex_init)(mbedtls_thre void (*mutex_free)(mbedtls_threading_mutex_t *), int (*mutex_lock)(mbedtls_threading_mutex_t *), int (*mutex_unlock)(mbedtls_threading_mutex_t *)); -#else /* BOOTLOADER_BUILD */ -typedef void mbedtls_threading_mutex_t; -#endif /* BOOTLOADER_BUILD */ typedef struct mbedtls_rom_eco4_funcs { // aes module @@ -303,10 +299,6 @@ typedef struct mbedtls_rom_eco4_funcs { #error "MBEDTLS_PLATFORM_ZEROIZE_ALT" #endif -#if BOOTLOADER_BUILD -void mbedtls_rom_osi_functions_init_bootloader(void); -#endif /* BOOTLOADER_BUILD */ - #ifdef __cplusplus } #endif diff --git a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi_bootloader.c b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi_bootloader.c index 0ea46f9591f..3dccaa768b0 100644 --- a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi_bootloader.c +++ b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi_bootloader.c @@ -4,26 +4,67 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "mbedtls_rom_osi.h" +#include + +#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS +#include "mbedtls/private/aes.h" + +int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16]); +int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16]); + +#define ROM_TABLE_FN(table_type, field, fn) ((__typeof__(((table_type *)0)->field))(fn)) + +#define MBEDTLS_ROM_ECO4_FUNC_COUNT 221 +#define MBEDTLS_ROM_ECO4_BOOTLOADER_FUNC_COUNT 16 + +typedef struct mbedtls_rom_eco4_funcs { + void (*_rom_mbedtls_aes_init)(mbedtls_aes_context *ctx); + void (*_rom_mbedtls_aes_free)(mbedtls_aes_context *ctx); + void (*_rom_mbedtls_aes_xts_init)(mbedtls_aes_xts_context *ctx); + void (*_rom_mbedtls_aes_xts_free)(mbedtls_aes_xts_context *ctx); + int (*_rom_mbedtls_aes_setkey_enc)(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits); + int (*_rom_mbedtls_aes_setkey_dec)(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits); + int (*_rom_mbedtls_aes_xts_setkey_enc)(mbedtls_aes_xts_context *ctx, const unsigned char *key, unsigned int keybits); + int (*_rom_mbedtls_aes_xts_setkey_dec)(mbedtls_aes_xts_context *ctx, const unsigned char *key, unsigned int keybits); + int (*_rom_mbedtls_aes_crypt_ecb)(mbedtls_aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16]); + int (*_rom_mbedtls_aes_crypt_cbc)(mbedtls_aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output); + int (*_rom_mbedtls_aes_crypt_xts)(mbedtls_aes_xts_context *ctx, int mode, size_t length, const unsigned char data_unit[16], const unsigned char *input, unsigned char *output); + int (*_rom_mbedtls_aes_crypt_cfb128)(mbedtls_aes_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output); + int (*_rom_mbedtls_aes_crypt_ofb)(mbedtls_aes_context *ctx, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output); + int (*_rom_mbedtls_aes_crypt_ctr)(mbedtls_aes_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[16], unsigned char stream_block[16], const unsigned char *input, unsigned char *output); + int (*_rom_mbedtls_internal_aes_encrypt)(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16]); + int (*_rom_mbedtls_internal_aes_decrypt)(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16]); + void (*_rom_mbedtls_unused[MBEDTLS_ROM_ECO4_FUNC_COUNT - MBEDTLS_ROM_ECO4_BOOTLOADER_FUNC_COUNT])(void); +} mbedtls_rom_eco4_funcs_t; + +_Static_assert(sizeof(mbedtls_rom_eco4_funcs_t) == MBEDTLS_ROM_ECO4_FUNC_COUNT * sizeof(void (*)(void)), + "Bootloader ROM function table must cover the full ROM ECO4 table"); /* This structure can be automatically generated by the script with rom.mbedtls.ld. */ +/* Keep the bootloader table the full ROM ECO4 size. The bootloader only fills AES + * entries, but ROM code may index later slots internally; all non-AES entries must + * exist and remain zero-initialized. + */ static const mbedtls_rom_eco4_funcs_t mbedtls_rom_eco4_funcs_table = { /* Fill the ROM functions into mbedtls rom function table. */ /* aes module */ - ._rom_mbedtls_aes_init = mbedtls_aes_init, - ._rom_mbedtls_aes_free = mbedtls_aes_free, - ._rom_mbedtls_aes_setkey_enc = mbedtls_aes_setkey_enc, - ._rom_mbedtls_aes_setkey_dec = mbedtls_aes_setkey_dec, - ._rom_mbedtls_aes_crypt_ecb = mbedtls_aes_crypt_ecb, - ._rom_mbedtls_aes_crypt_cbc = mbedtls_aes_crypt_cbc, - ._rom_mbedtls_internal_aes_encrypt = mbedtls_internal_aes_encrypt, - ._rom_mbedtls_internal_aes_decrypt = mbedtls_internal_aes_decrypt, + ._rom_mbedtls_aes_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_init, mbedtls_aes_init), + ._rom_mbedtls_aes_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_free, mbedtls_aes_free), + ._rom_mbedtls_aes_setkey_enc = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_setkey_enc, mbedtls_aes_setkey_enc), + ._rom_mbedtls_aes_setkey_dec = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_setkey_dec, mbedtls_aes_setkey_dec), + ._rom_mbedtls_aes_crypt_ecb = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_ecb, mbedtls_aes_crypt_ecb), + ._rom_mbedtls_aes_crypt_cbc = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_cbc, mbedtls_aes_crypt_cbc), + ._rom_mbedtls_internal_aes_encrypt = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_internal_aes_encrypt, mbedtls_internal_aes_encrypt), + ._rom_mbedtls_internal_aes_decrypt = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_internal_aes_decrypt, mbedtls_internal_aes_decrypt), - ._rom_mbedtls_aes_xts_init = mbedtls_aes_xts_init, - ._rom_mbedtls_aes_xts_free = mbedtls_aes_xts_free, - ._rom_mbedtls_aes_xts_setkey_enc = mbedtls_aes_xts_setkey_enc, - ._rom_mbedtls_aes_xts_setkey_dec = mbedtls_aes_xts_setkey_dec, - ._rom_mbedtls_aes_crypt_xts = mbedtls_aes_crypt_xts, + ._rom_mbedtls_aes_xts_init = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_xts_init, mbedtls_aes_xts_init), + ._rom_mbedtls_aes_xts_free = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_xts_free, mbedtls_aes_xts_free), + ._rom_mbedtls_aes_xts_setkey_enc = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_xts_setkey_enc, mbedtls_aes_xts_setkey_enc), + ._rom_mbedtls_aes_xts_setkey_dec = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_xts_setkey_dec, mbedtls_aes_xts_setkey_dec), + ._rom_mbedtls_aes_crypt_xts = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_xts, mbedtls_aes_crypt_xts), + ._rom_mbedtls_aes_crypt_cfb128 = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_cfb128, mbedtls_aes_crypt_cfb128), + ._rom_mbedtls_aes_crypt_ofb = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_ofb, mbedtls_aes_crypt_ofb), + ._rom_mbedtls_aes_crypt_ctr = ROM_TABLE_FN(mbedtls_rom_eco4_funcs_t, _rom_mbedtls_aes_crypt_ctr, mbedtls_aes_crypt_ctr), }; void mbedtls_rom_osi_functions_init_bootloader(void) diff --git a/components/nvs_flash/src/nvs_bootloader.c b/components/nvs_flash/src/nvs_bootloader.c index 9347cfd3ba2..a8c50d76536 100644 --- a/components/nvs_flash/src/nvs_bootloader.c +++ b/components/nvs_flash/src/nvs_bootloader.c @@ -16,7 +16,7 @@ #include #if CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL_BOOTLOADER && BOOTLOADER_BUILD -#include "mbedtls_rom_osi.h" +void mbedtls_rom_osi_functions_init_bootloader(void); #endif static const char* TAG = "nvs_bootloader"; From 9320f709bdcbfd7ec34684d122bf293241c776f4 Mon Sep 17 00:00:00 2001 From: Jiang Guang Ming Date: Fri, 8 May 2026 11:59:38 +0800 Subject: [PATCH 6/6] feat(mbedtls): enable PSA threading alt with ROM mbedTLS --- .../esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld | 16 +- .../port/mbedtls_rom/mbedtls_rom_osi.c | 267 ++++++++++++++++-- .../mbedtls/port/mbedtls_rom/threading_alt.h | 19 +- 3 files changed, 259 insertions(+), 43 deletions(-) diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld index 53b9bacc5cb..842d468c858 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld @@ -138,14 +138,14 @@ mbedtls_mpi_gcd = 0x40002768; mbedtls_mpi_inv_mod = 0x4000276c; mbedtls_mpi_is_prime_ext = 0x40002770; -mbedtls_cipher_init = 0x4000277c; -mbedtls_cipher_set_padding_mode = 0x40002780; -mbedtls_cipher_reset = 0x40002784; -mbedtls_cipher_finish = 0x40002788; -mbedtls_cipher_crypt = 0x4000278c; -mbedtls_cipher_cmac_starts = 0x40002790; -mbedtls_cipher_cmac_update = 0x40002794; -mbedtls_cipher_cmac_finish = 0x40002798; +/*mbedtls_cipher_init = 0x4000277c;*/ +/*mbedtls_cipher_set_padding_mode = 0x40002780;*/ +/*mbedtls_cipher_reset = 0x40002784;*/ +/*mbedtls_cipher_finish = 0x40002788;*/ +/*mbedtls_cipher_crypt = 0x4000278c;*/ +/*mbedtls_cipher_cmac_starts = 0x40002790;*/ +/*mbedtls_cipher_cmac_update = 0x40002794;*/ +/*mbedtls_cipher_cmac_finish = 0x40002798;*/ /*************************************** Group eco4_rom_mbedtls diff --git a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.c b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.c index c345cf5bef0..ac72ab87498 100644 --- a/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.c +++ b/components/mbedtls/port/mbedtls_rom/mbedtls_rom_osi.c @@ -17,7 +17,8 @@ #define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA MBEDTLS_ERR_THREADING_USAGE_ERROR #endif -_Static_assert(sizeof(mbedtls_rom_eco4_funcs_t) == 221 * sizeof(void (*)(void)), +#define MBEDTLS_ROM_ECO4_FUNC_COUNT 221 +_Static_assert(sizeof(mbedtls_rom_eco4_funcs_t) == MBEDTLS_ROM_ECO4_FUNC_COUNT * sizeof(void (*)(void)), "mbedtls_rom_eco4_funcs_t layout must match ROM"); #define ROM_TABLE_FN(table_type, field, fn) ((__typeof__(((table_type *)0)->field))(fn)) @@ -46,65 +47,267 @@ extern void rom_mbedtls_threading_set_alt(void (*mutex_init)(mbedtls_threading_m int (*mutex_lock)(mbedtls_threading_mutex_t *), int (*mutex_unlock)(mbedtls_threading_mutex_t *)); -static void mbedtls_rom_mutex_init( mbedtls_threading_mutex_t *mutex ) -{ - if (mutex == NULL) { - return; - } - #if defined(MBEDTLS_THREADING_ALT) - mutex->mutex = xSemaphoreCreateMutex(); - assert(mutex->mutex != NULL); +static int mbedtls_rom_platform_mutex_init(mbedtls_platform_mutex_t *mutex); +static void mbedtls_rom_platform_mutex_free(mbedtls_platform_mutex_t *mutex); +static int mbedtls_rom_platform_mutex_lock(mbedtls_platform_mutex_t *mutex); +static int mbedtls_rom_platform_mutex_unlock(mbedtls_platform_mutex_t *mutex); +#endif + +static void mbedtls_rom_mutex_init(mbedtls_threading_mutex_t *mutex) +{ +#if defined(MBEDTLS_THREADING_ALT) + int ret = mbedtls_rom_platform_mutex_init(&mutex->MBEDTLS_PRIVATE(mutex)); + mutex->MBEDTLS_PRIVATE(initialized) = (ret == 0); #else mbedtls_mutex_init(mutex); #endif } -static void mbedtls_rom_mutex_free( mbedtls_threading_mutex_t *mutex ) +static void mbedtls_rom_mutex_free(mbedtls_threading_mutex_t *mutex) { - if (mutex == NULL) { +#if defined(MBEDTLS_THREADING_ALT) + if (!mutex->MBEDTLS_PRIVATE(initialized)) { return; } - -#if defined(MBEDTLS_THREADING_ALT) - vSemaphoreDelete(mutex->mutex); + mbedtls_rom_platform_mutex_free(&mutex->MBEDTLS_PRIVATE(mutex)); + mutex->MBEDTLS_PRIVATE(initialized) = 0; #else mbedtls_mutex_free(mutex); #endif } -static int mbedtls_rom_mutex_lock( mbedtls_threading_mutex_t *mutex ) +static int mbedtls_rom_mutex_lock(mbedtls_threading_mutex_t *mutex) { - if (mutex == NULL) { - return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; - } - #if defined(MBEDTLS_THREADING_ALT) - if (xSemaphoreTake(mutex->mutex, portMAX_DELAY) != pdTRUE) { - return MBEDTLS_ERR_THREADING_MUTEX_ERROR; + if (!mutex->MBEDTLS_PRIVATE(initialized)) { + return MBEDTLS_ERR_THREADING_USAGE_ERROR; } - return 0; + return mbedtls_rom_platform_mutex_lock(&mutex->MBEDTLS_PRIVATE(mutex)); #else return mbedtls_mutex_lock(mutex); #endif } -static int mbedtls_rom_mutex_unlock( mbedtls_threading_mutex_t *mutex ) +static int mbedtls_rom_mutex_unlock(mbedtls_threading_mutex_t *mutex) +{ +#if defined(MBEDTLS_THREADING_ALT) + if (!mutex->MBEDTLS_PRIVATE(initialized)) { + return MBEDTLS_ERR_THREADING_USAGE_ERROR; + } + return mbedtls_rom_platform_mutex_unlock(&mutex->MBEDTLS_PRIVATE(mutex)); +#else + return mbedtls_mutex_unlock(mutex); +#endif +} + +#if defined(MBEDTLS_THREADING_ALT) +static int mbedtls_rom_platform_mutex_init(mbedtls_platform_mutex_t *mutex) { if (mutex == NULL) { return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; } -#if defined(MBEDTLS_THREADING_ALT) + mutex->mutex = xSemaphoreCreateMutex(); + mutex->is_valid = (mutex->mutex != NULL); + assert(mutex->is_valid); + return mutex->is_valid ? 0 : MBEDTLS_ERR_THREADING_MUTEX_ERROR; +} + +static void mbedtls_rom_platform_mutex_free(mbedtls_platform_mutex_t *mutex) +{ + if (mutex == NULL || !mutex->is_valid) { + return; + } + + vSemaphoreDelete(mutex->mutex); + mutex->mutex = NULL; + mutex->is_valid = 0; +} + +static int mbedtls_rom_platform_mutex_lock(mbedtls_platform_mutex_t *mutex) +{ + if (mutex == NULL || !mutex->is_valid) { + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; + } + + if (xSemaphoreTake(mutex->mutex, portMAX_DELAY) != pdTRUE) { + return MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + return 0; +} + +static int mbedtls_rom_platform_mutex_unlock(mbedtls_platform_mutex_t *mutex) +{ + if (mutex == NULL || !mutex->is_valid) { + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; + } + if (xSemaphoreGive(mutex->mutex) != pdTRUE) { return MBEDTLS_ERR_THREADING_MUTEX_ERROR; } return 0; -#else - return mbedtls_mutex_unlock(mutex); -#endif } +typedef struct mbedtls_rom_cond_waiter { + SemaphoreHandle_t semaphore; + struct mbedtls_rom_cond_waiter *next; +} mbedtls_rom_cond_waiter_t; + +static void mbedtls_rom_cond_remove_waiter(mbedtls_platform_condition_variable_t *cond, + mbedtls_rom_cond_waiter_t *waiter) +{ + mbedtls_rom_cond_waiter_t **current = &cond->waiters; + + while (*current != NULL) { + if (*current == waiter) { + *current = waiter->next; + waiter->next = NULL; + return; + } + current = &(*current)->next; + } +} + +static int mbedtls_rom_cond_init(mbedtls_platform_condition_variable_t *cond) +{ + if (cond == NULL) { + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; + } + + cond->mutex = xSemaphoreCreateMutex(); + cond->waiters = NULL; + cond->is_valid = (cond->mutex != NULL); + return cond->is_valid ? 0 : MBEDTLS_ERR_THREADING_MUTEX_ERROR; +} + +static void mbedtls_rom_cond_free(mbedtls_platform_condition_variable_t *cond) +{ + if (cond == NULL || !cond->is_valid) { + return; + } + + vSemaphoreDelete(cond->mutex); + cond->mutex = NULL; + cond->waiters = NULL; + cond->is_valid = 0; +} + +static int mbedtls_rom_cond_signal(mbedtls_platform_condition_variable_t *cond) +{ + mbedtls_rom_cond_waiter_t *waiter; + + if (cond == NULL || !cond->is_valid) { + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; + } + + if (xSemaphoreTake(cond->mutex, portMAX_DELAY) != pdTRUE) { + return MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + + waiter = cond->waiters; + if (waiter != NULL) { + cond->waiters = waiter->next; + waiter->next = NULL; + if (xSemaphoreGive(waiter->semaphore) != pdTRUE) { + (void) xSemaphoreGive(cond->mutex); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + } + + if (xSemaphoreGive(cond->mutex) != pdTRUE) { + return MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + + return 0; +} + +static int mbedtls_rom_cond_broadcast(mbedtls_platform_condition_variable_t *cond) +{ + mbedtls_rom_cond_waiter_t *waiter; + + if (cond == NULL || !cond->is_valid) { + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; + } + + if (xSemaphoreTake(cond->mutex, portMAX_DELAY) != pdTRUE) { + return MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + + waiter = cond->waiters; + cond->waiters = NULL; + + while (waiter != NULL) { + mbedtls_rom_cond_waiter_t *next = waiter->next; + waiter->next = NULL; + if (xSemaphoreGive(waiter->semaphore) != pdTRUE) { + (void) xSemaphoreGive(cond->mutex); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + waiter = next; + } + + return (xSemaphoreGive(cond->mutex) == pdTRUE) ? 0 : MBEDTLS_ERR_THREADING_MUTEX_ERROR; +} + +static int mbedtls_rom_cond_wait(mbedtls_platform_condition_variable_t *cond, + mbedtls_platform_mutex_t *mutex) +{ + int ret; + mbedtls_rom_cond_waiter_t waiter = { 0 }; + + if (cond == NULL || mutex == NULL || !cond->is_valid) { + return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; + } + + waiter.semaphore = xSemaphoreCreateBinary(); + if (waiter.semaphore == NULL) { + return MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + + if (xSemaphoreTake(cond->mutex, portMAX_DELAY) != pdTRUE) { + vSemaphoreDelete(waiter.semaphore); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + + waiter.next = cond->waiters; + cond->waiters = &waiter; + + if (xSemaphoreGive(cond->mutex) != pdTRUE) { + cond->waiters = waiter.next; + waiter.next = NULL; + vSemaphoreDelete(waiter.semaphore); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + + ret = mbedtls_rom_platform_mutex_unlock(mutex); + if (ret != 0) { + if (xSemaphoreTake(cond->mutex, portMAX_DELAY) == pdTRUE) { + mbedtls_rom_cond_remove_waiter(cond, &waiter); + (void) xSemaphoreGive(cond->mutex); + } + vSemaphoreDelete(waiter.semaphore); + return ret; + } + + if (xSemaphoreTake(waiter.semaphore, portMAX_DELAY) != pdTRUE) { + if (xSemaphoreTake(cond->mutex, portMAX_DELAY) == pdTRUE) { + mbedtls_rom_cond_remove_waiter(cond, &waiter); + (void) xSemaphoreGive(cond->mutex); + } + vSemaphoreDelete(waiter.semaphore); + (void) mbedtls_rom_platform_mutex_lock(mutex); + return MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + + vSemaphoreDelete(waiter.semaphore); + ret = mbedtls_rom_platform_mutex_lock(mutex); + /* The wakeup has already been consumed, so a re-lock failure is unrecoverable. */ + assert(ret == 0); + return ret; +} +#endif + /* This structure can be automatically generated by the script with rom.mbedtls.ld. */ static const mbedtls_rom_eco4_funcs_t mbedtls_rom_eco4_funcs_table = { /* Fill the ROM functions into mbedtls rom function table. */ @@ -337,7 +540,15 @@ __attribute__((constructor)) void mbedtls_rom_osi_functions_init(void) extern void *mbedtls_rom_osi_funcs_ptr; #if defined(MBEDTLS_THREADING_ALT) - mbedtls_threading_set_alt(mbedtls_rom_mutex_init, mbedtls_rom_mutex_free, mbedtls_rom_mutex_lock, mbedtls_rom_mutex_unlock); + mbedtls_threading_set_alt(mbedtls_rom_platform_mutex_init, + mbedtls_rom_platform_mutex_free, + mbedtls_rom_platform_mutex_lock, + mbedtls_rom_platform_mutex_unlock, + mbedtls_rom_cond_init, + mbedtls_rom_cond_free, + mbedtls_rom_cond_signal, + mbedtls_rom_cond_broadcast, + mbedtls_rom_cond_wait); #endif /* Initialize the rom function mbedtls_threading_set_alt on chip rev2.0 with rom eco4 */ diff --git a/components/mbedtls/port/mbedtls_rom/threading_alt.h b/components/mbedtls/port/mbedtls_rom/threading_alt.h index 6dc3349da1e..36367b98a10 100644 --- a/components/mbedtls/port/mbedtls_rom/threading_alt.h +++ b/components/mbedtls/port/mbedtls_rom/threading_alt.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,15 +8,20 @@ #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" -typedef struct mbedtls_threading_mutex_t { +struct mbedtls_rom_cond_waiter; + +typedef struct mbedtls_platform_mutex_t { SemaphoreHandle_t mutex; /* is_valid is 0 after a failed init or a free, and nonzero after a * successful init. This field is not considered part of the public * API of Mbed TLS and may change without notice. */ char is_valid; -} mbedtls_threading_mutex_t; +} mbedtls_platform_mutex_t; -extern void mbedtls_threading_set_alt(void (*mutex_init)(mbedtls_threading_mutex_t *), - void (*mutex_free)(mbedtls_threading_mutex_t *), - int (*mutex_lock)(mbedtls_threading_mutex_t *), - int (*mutex_unlock)(mbedtls_threading_mutex_t *)); +typedef struct mbedtls_platform_condition_variable_t { + /* Protects the waiter list below. */ + SemaphoreHandle_t mutex; + /* Intrusive list of threads currently blocked on this condition variable. */ + struct mbedtls_rom_cond_waiter *waiters; + char is_valid; +} mbedtls_platform_condition_variable_t;