Skip to content

Commit

Permalink
Merge branch 'feat/support_esp32c2_eco4_rom_mbedtls_v3.6.0_lts' into …
Browse files Browse the repository at this point in the history
…'master'

feat(mbedtls): support esp32c2 rev2.0 ROM mbedTLS v3.6.0-LTS

Closes IDF-10680

See merge request espressif/esp-idf!33227
  • Loading branch information
jack0c committed Sep 9, 2024
2 parents a900008 + 5bb9306 commit 9a47de5
Show file tree
Hide file tree
Showing 8 changed files with 821 additions and 25 deletions.
4 changes: 4 additions & 0 deletions components/esp_rom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ else() # Regular app build

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()
endif()

if(CONFIG_IDF_TARGET_ARCH_XTENSA)
Expand Down
221 changes: 221 additions & 0 deletions components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.eco4.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

/***************************************
Group eco4_rom_mbedtls
***************************************/

/* Functions */
mbedtls_mpi_init = 0x400026dc;
mbedtls_mpi_free = 0x400026e0;
mbedtls_mpi_grow = 0x400026e4;
mbedtls_mpi_shrink = 0x400026e8;
mbedtls_mpi_copy = 0x400026ec;
mbedtls_mpi_safe_cond_assign = 0x400026f0;
mbedtls_mpi_safe_cond_swap = 0x400026f4;
mbedtls_mpi_lset = 0x400026f8;
mbedtls_mpi_get_bit = 0x400026fc;
mbedtls_mpi_set_bit = 0x40002700;
mbedtls_mpi_lsb = 0x40002704;
mbedtls_mpi_bitlen = 0x40002708;
mbedtls_mpi_size = 0x4000270c;
mbedtls_mpi_read_binary = 0x40002710;
mbedtls_mpi_write_binary = 0x40002714;
mbedtls_mpi_shift_l = 0x40002718;
mbedtls_mpi_shift_r = 0x4000271c;
mbedtls_mpi_cmp_abs = 0x40002720;
mbedtls_mpi_cmp_mpi = 0x40002724;
mbedtls_mpi_lt_mpi_ct = 0x40002728;
mbedtls_mpi_cmp_int = 0x4000272c;
mbedtls_mpi_add_abs = 0x40002730;
mbedtls_mpi_sub_abs = 0x40002734;
mbedtls_mpi_add_mpi = 0x40002738;
mbedtls_mpi_sub_mpi = 0x4000273c;
mbedtls_mpi_add_int = 0x40002740;
mbedtls_mpi_sub_int = 0x40002744;
mbedtls_mpi_mul_mpi = 0x40002748;
mbedtls_mpi_mul_int = 0x4000274c;
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_fill_random = 0x40002764;
mbedtls_mpi_gcd = 0x40002768;
mbedtls_mpi_inv_mod = 0x4000276c;
mbedtls_mpi_is_prime_ext = 0x40002770;

/***************************************
Group eco4_rom_mbedtls
***************************************/

/* Functions */
rom_mbedtls_threading_set_alt = 0x40002c0c;
mbedtls_aes_crypt_cfb8 = 0x40002c10;
mbedtls_mpi_swap = 0x40002c14;
mbedtls_mpi_read_string = 0x40002c18;
mbedtls_mpi_write_string = 0x40002c1c;
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_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_asn1_get_enum = 0x40002ce4;
mbedtls_asn1_sequence_free = 0x40002ce8;
mbedtls_asn1_traverse_sequence_of = 0x40002cec;
mbedtls_asn1_find_named_data = 0x40002cf0;
mbedtls_asn1_free_named_data_list = 0x40002cf4;
mbedtls_asn1_free_named_data_list_shallow = 0x40002cf8;
mbedtls_asn1_write_raw_buffer = 0x40002cfc;
mbedtls_asn1_write_null = 0x40002d00;
mbedtls_asn1_write_oid = 0x40002d04;
mbedtls_asn1_write_algorithm_identifier = 0x40002d08;
mbedtls_asn1_write_bool = 0x40002d0c;
mbedtls_asn1_write_int = 0x40002d10;
mbedtls_asn1_write_enum = 0x40002d14;
mbedtls_asn1_write_tagged_string = 0x40002d18;
mbedtls_asn1_write_printable_string = 0x40002d1c;
mbedtls_asn1_write_utf8_string = 0x40002d20;
mbedtls_asn1_write_ia5_string = 0x40002d24;
mbedtls_asn1_write_bitstring = 0x40002d28;
mbedtls_asn1_write_named_bitstring = 0x40002d2c;
mbedtls_asn1_write_octet_string = 0x40002d30;
mbedtls_asn1_store_named_data = 0x40002d34;
mbedtls_ccm_starts = 0x40002d38;
mbedtls_ccm_set_lengths = 0x40002d3c;
mbedtls_ccm_update_ad = 0x40002d40;
mbedtls_ccm_update = 0x40002d44;
mbedtls_ccm_finish = 0x40002d48;
mbedtls_cipher_list = 0x40002d4c;
mbedtls_cipher_info_from_string = 0x40002d50;
mbedtls_cipher_info_from_type = 0x40002d54;
mbedtls_cipher_info_from_values = 0x40002d58;
mbedtls_cipher_free = 0x40002d5c;
mbedtls_cipher_setup = 0x40002d60;
mbedtls_cipher_setkey = 0x40002d64;
mbedtls_cipher_set_iv = 0x40002d68;
mbedtls_cipher_update_ad = 0x40002d6c;
mbedtls_cipher_update = 0x40002d70;
mbedtls_cipher_write_tag = 0x40002d74;
mbedtls_cipher_check_tag = 0x40002d78;
mbedtls_cipher_auth_encrypt_ext = 0x40002d7c;
mbedtls_cipher_auth_decrypt_ext = 0x40002d80;
mbedtls_cipher_cmac_reset = 0x40002d84;
mbedtls_cipher_cmac = 0x40002d88;
mbedtls_aes_cmac_prf_128 = 0x40002d8c;
mbedtls_ctr_drbg_set_prediction_resistance = 0x40002d90;
mbedtls_ctr_drbg_set_entropy_len = 0x40002d94;
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_ecdh_can_do = 0x40002e2c;
mbedtls_ecdh_gen_public = 0x40002e30;
mbedtls_ecdh_compute_shared = 0x40002e34;
mbedtls_ecdh_init = 0x40002e38;
mbedtls_ecdh_setup = 0x40002e3c;
mbedtls_ecdh_free = 0x40002e40;
mbedtls_ecdh_make_params = 0x40002e44;
mbedtls_ecdh_read_params = 0x40002e48;
mbedtls_ecdh_get_params = 0x40002e4c;
mbedtls_ecdh_make_public = 0x40002e50;
mbedtls_ecdh_read_public = 0x40002e54;
mbedtls_ecdh_calc_secret = 0x40002e58;
mbedtls_ecdh_enable_restart = 0x40002e5c;
mbedtls_ecdsa_can_do = 0x40002e60;
mbedtls_ecdsa_sign = 0x40002e64;
mbedtls_ecdsa_sign_det_ext = 0x40002e68;
mbedtls_ecdsa_sign_restartable = 0x40002e6c;
mbedtls_ecdsa_sign_det_restartable = 0x40002e70;
mbedtls_ecdsa_verify = 0x40002e74;
mbedtls_ecdsa_verify_restartable = 0x40002e78;
mbedtls_ecdsa_write_signature = 0x40002e7c;
mbedtls_ecdsa_write_signature_restartable = 0x40002e80;
mbedtls_ecdsa_read_signature = 0x40002e84;
mbedtls_ecdsa_read_signature_restartable = 0x40002e88;
mbedtls_ecdsa_genkey = 0x40002e8c;
mbedtls_ecdsa_from_keypair = 0x40002e90;
mbedtls_ecdsa_init = 0x40002e94;
mbedtls_ecdsa_free = 0x40002e98;
mbedtls_ecdsa_restart_init = 0x40002e9c;
mbedtls_ecdsa_restart_free = 0x40002ea0;
4 changes: 2 additions & 2 deletions components/esp_rom/esp32c2/ld/esp32c2.rom.mbedtls.ld
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mbedtls_sha512_clone = 0x40002a50;
mbedtls_sha512_starts = 0x40002a54;
mbedtls_sha512_update = 0x40002a58;
mbedtls_sha512_finish = 0x40002a5c;
mbedtls_internal_sha512_process = 0x40002a60;
/*mbedtls_internal_sha512_process = 0x40002a60;*/
mbedtls_sha512 = 0x40002a64;
mbedtls_aes_xts_init = 0x40002b68;
mbedtls_aes_xts_free = 0x40002b6c;
Expand All @@ -95,7 +95,7 @@ mbedtls_md5_clone = 0x40002be0;
mbedtls_md5_starts = 0x40002be4;
mbedtls_md5_update = 0x40002be8;
mbedtls_md5_finish = 0x40002bec;
mbedtls_internal_md5_process = 0x40002bf0;
/*mbedtls_internal_md5_process = 0x40002bf0;*/
mbedtls_md5 = 0x40002bf4;
mbedtls_sha1 = 0x40002c08;
/* Data (.data, .bss, .rodata) */
Expand Down
9 changes: 9 additions & 0 deletions components/mbedtls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ endif()
set(mbedtls_srcs "")
set(mbedtls_include_dirs "port/include" "mbedtls/include" "mbedtls/library")

if(CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL)
list(APPEND mbedtls_include_dirs "port/mbedtls_rom")
endif()

if(CONFIG_MBEDTLS_CERTIFICATE_BUNDLE)
list(APPEND mbedtls_srcs "esp_crt_bundle/esp_crt_bundle.c")
list(APPEND mbedtls_include_dirs "esp_crt_bundle/include")
Expand Down Expand Up @@ -94,6 +98,11 @@ set(Python3_EXECUTABLE ${python})
# Needed to for include_next includes to work from within mbedtls
include_directories("${COMPONENT_DIR}/port/include")

# Needed to for mbedtls_rom includes to work from within mbedtls
if(CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL)
include_directories("${COMPONENT_DIR}/port/mbedtls_rom")
endif()

# Import mbedtls library targets
add_subdirectory(mbedtls)

Expand Down
11 changes: 7 additions & 4 deletions components/mbedtls/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ menu "mbedTLS"

config MBEDTLS_CMAC_C
bool "Enable CMAC mode for block ciphers"
default y if MBEDTLS_USE_CRYPTO_ROM_IMPL
default n
depends on MBEDTLS_AES_C || MBEDTLS_DES_C
help
Expand Down Expand Up @@ -1144,17 +1143,21 @@ menu "mbedTLS"
select MBEDTLS_SHA512_C
select MBEDTLS_AES_C
select MBEDTLS_CCM_C
select MBEDTLS_CMAC_C
select MBEDTLS_ROM_MD5
select MBEDTLS_HARDWARE_SHA
select MBEDTLS_ECP_RESTARTABLE
select MBEDTLS_THREADING_C
help
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 is v2.16.12.
We have done the security analysis of the mbedtls revision in ROM (v2.16.12)
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 (v2.16.12) then we shall patch the relevant symbols. This would increase
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.

Expand Down
Loading

0 comments on commit 9a47de5

Please sign in to comment.