Commit Graph
100 Commits
Author SHA1 Message Date
harshal.patil 7c83e4ced8 ci(examples/esp_local_ctrl): fix app size increase build failure 2026-08-26 10:16:52 +05:30
harshal.patil dd99e05dd1 test(mbedtls): add partial-block PSRAM coverage for AES
Extend the CTR test data length to 6433 bytes so the trailing partial
block is exercised with external RAM buffers (which stalls the ESP32-S2
Crypto DMA on an unfixed driver).
2026-08-25 08:54:20 +05:30
harshal.patil c4075d6124 fix(mbedtls/aes): fix ESP32-S2 Crypto DMA stall on PSRAM output with partial blocks
The ESP32-S2 Crypto DMA in-channel stalls silently when a receive
descriptor list transitions from external to internal RAM. The AES
driver hits this when a PSRAM-output operation has a trailing partial
block, as the internal stream descriptor is linked after the external
RAM data descriptors.

- esp_aes_process_dma(): process the block-aligned part and the partial
  block as two separate DMA operations, keeping each descriptor list
  uniform
- crypto_dma_ll_reset(): also reset the in-channel (per the TRM receive
  reset sequence), otherwise stale state from a preceding external-RAM
  operation corrupts the next operation's output

The GCM DMA path is unaffected; it never operates on PSRAM buffers.
2026-08-25 08:54:19 +05:30
harshal.patil 6459793edd change(security): disable Key Manager support on ESP32-C5/P4/S31
The Key Manager hardware peripheral in its current form needs further
design changes before it can be offered as a production feature.
Until a revised peripheral design is available, withdraw ESP-IDF
support for it on all Key Manager capable targets.
2026-08-21 11:47:41 +05:30
harshal.patil 67affdd43b fix(hal): Fix MMU PSRAM anti-fi MMU target check
In case of ESP32-C5 and ESP32-C61, mmu_ids for PSRAM and Flash
MMU are the same due to their shared memory space. Thus, instead of
mmu_id we should use mmu_target_t.
2026-08-03 14:29:42 +05:30
harshal.patil 159d222973 refactor(esp_system): deduplicate ROM fast wake RTC digest reservation
The digest length and the condition that reserves it at the end of RTC RAM were
duplicated in seven places. Hold the reservation in a hidden Kconfig value that
is zero when the feature does not apply, so every consumer subtracts it
unconditionally, and derive ESP_SECURE_BOOT_DIGEST_LEN from it.
2026-07-31 10:57:02 +08:00
harshal.patil b64ab272b9 test(mbedtls): move AES test vectors to a dedicated header 2026-07-01 16:44:21 +05:30
harshal.patil 53b9e831f3 fix(mbedtls/aes): Fix AES-DMA over encrypted PSRAM on ESP32-S31
esp_crypto_shared_gdma_done() polled the AXI RX raw interrupt status
(in_done) but never cleared it, so after the first transfer the set bit
made every subsequent call return immediately without waiting.
2026-07-01 16:35:41 +05:30
harshal.patil a847bb8439 fix(panic): handle absent IROM/DROM alignment gap in spiram-xip memprot tests
The spiram-xip IROM/DROM alignment tests assumed the XIP region always
leaves an alignment gap before the next MMU page: they executed into the
gap and expected an instruction access fault followed by a register dump.
When the section ends exactly on an MMU page boundary there is no gap - the
device prints "<IROM/DROM> alignment gap not added into heap" and returns,
the framework restarts cleanly (esp_restart_noos, no panic), and the test
timed out waiting for a register dump.
2026-07-01 11:00:16 +05:30
harshal.patil 1fde0259fe change(esp_psram): Consider all PSRAM regions in PMP protection 2026-06-23 14:56:39 +05:30
harshal.patil 024de60208 fix(esp_common/esp_fault): make ESP_FAULT_ASSERT survive optimization
ESP_FAULT_ASSERT(C) was silently deleted by the optimizer when C is a cached
flag/status already proven by a preceding `if (!C) return/goto`: the compiler
folds C to a constant and drops all three checks, removing the fault-injection
protection with no warning.
2026-06-22 11:20:04 +05:30
harshal.patil 1a36a6409b fix(secure_boot): range-check ECDSA r,s in bootloader before ROM verify 2026-06-12 16:54:33 +05:30
harshal.patil 9514a0fd2f fix(esp_common): Add esp_fault_internal.h for use by G0 components
In release/v5.x, esp_fault.h resides in the esp_hw_support (G1)
component, so the G0 components (hal, esp_rom) must not depend on it.
Copy its contents to esp_common as esp_fault_internal.h, keep
esp_fault.h as a compatibility wrapper around it, and switch the hal
and esp_rom ECDSA/ECC code to the internal header.
2026-06-12 16:54:33 +05:30
harshal.patil faa70e9cd0 fix(esp_tee): Reset crypto peripherals before the panic-induced reset 2026-06-12 16:54:33 +05:30
harshal.patil 8a934fa932 test(mbedtls): Add out-of-bounds test for the ECDSA hardware driver 2026-06-12 16:54:33 +05:30
harshal.patil 792922eb69 fix(esp_rom): Patch ets_ecdsa_verify() to include signature bounds check 2026-06-12 16:54:33 +05:30
harshal.patilandAshish Sharma 483c51b3c8 fix(mbedtls): validate ECDSA signature range and harden ECC memory power-down
Co-Authored-By: Ashish Sharma <ashish.sharma@espressif.com>
2026-06-12 16:54:33 +05:30
harshal.patil 673c861ac2 fix(soc): Remove non-existent crypto registers (ESP32-C61) 2026-06-09 18:18:13 +05:30
harshal.patil fcb5e51c6d fix(esp_security): Add more validation checks 2026-05-15 00:13:34 +05:30
harshal.patil fe0bac38a9 fix(key_mgr): Correct XTS-AES key length register configuration
The key_mgr_ll_set_xts_aes_key_len() function was incorrectly using
REG_SET_FIELD() with the key_len enum value directly. Since
KEYMNG_FLASH_KEY_LEN is a 1-bit register field (0=128-bit, 1=256-bit),
writing ESP_KEY_MGR_XTS_AES_LEN_128 (value 3) resulted in the LSB (1)
being stored, incorrectly configuring 256-bit mode.

Fixed by using a switch statement to properly map:
- ESP_KEY_MGR_XTS_AES_LEN_128 → REG_CLR_BIT (0)
- ESP_KEY_MGR_XTS_AES_LEN_256 → REG_SET_BIT (1)

Thus, matching the correct ESP32-C5 implementation.
2026-05-15 00:13:34 +05:30
harshal.patil 8b2e942e4e change(esp_key_mgr): Store key_len field in the key_info
- Update the Key Manager key types to be generic
- Define a new enum to determine the length of the keys
- Refactor the Key Manager driver support generic key types and key lengths
- Also store key deployment mode in the key recovery info
2026-05-15 00:13:34 +05:30
harshal.patil 6e4dac831d fix(hal): Force HUK power up when configuring HUK for ESP32-C5 2026-05-15 00:13:34 +05:30
harshal.patil 6e74698920 feat(flash_encryption): Remove mspi reset when switching the XTS-AES key source 2026-05-15 00:13:33 +05:30
harshal.patil acd9cf6271 fix(esp_security/esp_key_mgr): Fix missed error codes and some cleanup 2026-05-15 00:13:30 +05:30
harshal.patil 55657f5f22 fix(cpu_region_protect): Fix incorrect definition of ALIGN_UP macro 2026-05-08 12:43:26 +05:30
harshal.patil fe83bf0011 fix(esp_hw_support): reset stale PMP gap entries on P4 v3 before app memprot setup 2026-05-08 12:43:26 +05:30
harshal.patil 8121f66ec3 feat(cpu_region_protect): Extend PMP memprot for ESP32-P4 V3 2026-05-08 12:43:26 +05:30
harshal.patil e0211edf0e fix(esp_security): Enable ECC clock while using the Key Manager's ECDH key deployment mode 2026-05-05 13:37:00 +05:30
harshal.patil 52a8c04bd6 test(esp_security): Update the Key Manager test to support ESP32-P4 2026-04-28 21:27:40 +05:30
harshal.patil beaa37a2e6 fix(esp_security): guard key manager APIs against unsupported chip revs
On ESP32-P4 rev < 3.0, Key Manager is software-disabled, but the public
esp_key_mgr.h APIs had no runtime check.
Calls using HMAC/DS/PSRAM key types fell through to
HAL_ASSERT("Unsupported ...") paths in key_mgr_ll.h. Gate
each public API with key_mgr_ll_is_supported() and return
ESP_ERR_NOT_SUPPORTED cleanly instead.
2026-04-28 15:02:40 +05:30
harshal.patil 8f9b860131 fix(esp_security): Fixes incorrect key manager configuration for ESP32-P4 rev < 3 2026-04-28 14:55:51 +05:30
harshal.patil 9c86e8bdc1 fix(esp_security): Enable Key Manager clocks even for efuse key operations
The Key Manager holds a key usage register, thus, the Key Manager peripheral
clock must be enabled even for efuses-based key operations to route the
crypto operations to correctly to the efuses (default is Key Manager)
2026-04-06 18:36:17 +05:30
harshal.patil 8dafc3b75f feat(esp32p4): Support newer Key Manager key sources for ESP32-P4 V3 2026-04-06 18:11:43 +05:30
harshal.patil 0742f3fce3 fix(mbedtls/aes): Cache invalidate the output buffer before the AES-DMA operation
Instead of performing the cache-to-memory (C2M) operation on the output buffer,
even a cache invalidate (M2C) is sufficient to ensure that no write-back occurs
during the DMA write operation
2026-01-16 11:07:00 +05:30
harshal.patil 525ef3a2ea fix(mbedlts/aes): Ensure cache coherency when DMA writes to cacheable PSRAM buffers 2026-01-16 11:06:46 +05:30
harshal.patil cb9acbdd21 fix(secure_boot): Application's Secure Boot verify API support ECDSA-P384 2025-12-24 10:42:15 +05:30
harshal.patil 11c8f6aa94 fix(mbedtls/aes): Reallocate buffers only if in external RAM 2025-12-12 13:00:40 +05:30
harshal.patil 76436b3418 fix(mbedtls/port): Use internal buffers to perform chunkwise operations
when the external input and output buffers are unaligned.
This also fixes as a recursion loop that occurs when the size of the input
buffer is not aligned to dcache_line_size but is aligned to AES_BLOCK_BYTES
2025-12-01 18:15:25 +05:30
harshal.patil 6ea63548d4 fix(esp_security): Set WR_DIS_SECURE_BOOT_SHA384_EN by default when
Flash Encryption Release mode is enabled and Secure Boot P384 scheme not is enabled.
2025-11-11 17:53:04 +05:30
harshal.patil 7b57a1cd16 fix(esp_security): Fix undefined efuse build failure in case of ESP32-P4
- The `wr_dis` efuse bit corresponding to `SECURE_BOOT_SHA384_EN` is absent in P4
2025-11-11 17:53:04 +05:30
harshal.patil 317a6f074d fix(mbedtls/port): Align AES and SHA DMA buffers to 16 when SPIRAM encryption is enabled
- Targets that support GDMA and MSPI encryption module need data and addresses aligned to 16
2025-11-11 17:45:11 +05:30
harshal.patil 6ab5a2f883 fix(esp_security): Configure the Key Manager to use XTS-AES efuse key by-default 2025-10-13 10:40:50 +05:30
harshal.patil 175a6510f5 fix(bootloader_support): Allow pre-programmed XTS-AES psuedo round level efuses
- The API esp_flash_encryption_set_release_mode() by defualt programs
the XTS-AES pseudo round level efuse to level low but did not considered
any existing value that would have been programmed in the efuse bit.
2025-10-13 10:40:16 +05:30
harshal.patil 70a8b4d842 fix(bootloader_support): Reorder write disabling ECDSA_CURVE_MODE 2025-10-13 10:40:16 +05:30
harshal.patil d902072d80 fix(bootloader_support): Reorder write protection bits of some shared security efuses 2025-10-13 10:40:16 +05:30
harshal.patil ae7d7542e0 fix(esp_key_mgr): Fix incorrect key manager state management 2025-09-12 17:26:27 +05:30
harshal.patil 4213e41bbd fix(soc): Disable XTS-AES-256 using efuse key for ESP32-C5 2025-08-19 21:59:34 +05:30
harshal.patil f6f15bf91a change(mbedtls/ecdsa): The ECDSA module of ESP32-H2 ECO5 does not use MPI module 2025-08-13 18:53:19 +05:30
harshal.patil 12393745c2 fix(esp_system): Remove redundant crypto clock source selection 2025-07-25 14:43:56 +05:30
harshal.patil 6a03c8ffee ci(security): Security test app updated yml
- Also fixes the errors generated by the check-test-scripts command
2025-07-25 14:43:56 +05:30
harshal.patil 3d6423a251 docs(secure-boot-v2): Update the signature verification timings
- THe timings are calculated for the ROM verifying the bootloader's signature
2025-07-25 14:43:56 +05:30
harshal.patil c473b3deee docs(secure_boot_v2): Add documentation for Secure Boot V2 using ECDSA-P384 2025-07-25 14:43:56 +05:30
harshal.patil 9822c6f199 test(secure_boot): Add tests for ECDSA-based secure boot scheme 2025-07-25 14:43:46 +05:30
harshal.patil 96f11e01bf test(examples/efuse): Add test for secure boot v2 using ecdsa-p384 2025-07-25 14:25:33 +05:30
harshal.patil 476f8f6f51 feat(bootloader_support): Support Secure Boot using ECDSA-P384 curve 2025-07-25 14:25:31 +05:30
harshal.patil 55f693d4dd change(bootloader_support/secure_boot): Allow NULL as verified_digest for app build
The esp_secure_boot_verify_sbv2_signature_block() and esp_secure_boot_verify_rsa_signature_block()
APIs need and use the verified_digest argument only for BOOTLOADER_BUILD, but the argument is
not used in the application code, and the value present in verified_digest is considered invalid.
Thus, allow passing NULL as the verified_digest parameter to help some save space.
2025-07-25 14:23:02 +05:30
harshal.patil 1b3eb8f93e fix(bootloader_support/secure_boot): Fix incorrect usage of ESP_SECURE_BOOT_KEY_DIGEST_LEN 2025-07-25 14:23:02 +05:30
harshal.patil 61b0b072f9 fix(mbedtls/gcm): Allow enabling GCM fallback only if software GCM is available 2025-07-25 08:48:00 +05:30
harshal.patil 1c0b86e00c docs(bootloader): Change the default value of maximum supported bootloader size 2025-07-24 17:18:19 +05:30
harshal.patil 0644f453be fix(bootlaoder): Fix documentation as ESP32 does not support secure download mode 2025-06-30 10:26:36 +05:30
harshal.patil 5210e576d5 feat(mbedtls/sha): New API for setting SHA mode 2025-06-18 16:46:39 +05:30
harshal.patil e7a76ff71e feat(soc): Update ESP32-C5 ECO2 to support SHA512 2025-06-18 16:46:39 +05:30
harshal.patilandMahavir Jain 07ae83249a fix(mbedtls/esp_crt_bundle): Suppress non-negative serial number warning
Co-authored-by: Mahavir Jain <mahavir.jain@espressif.com>
2025-06-04 17:37:47 +05:30
harshal.patil 59496b4927 fix(system_internal): Avoid the sec clock reset caused due to resetting all crypto peripherals 2025-05-26 11:40:51 +05:30
harshal.patil 1ba8abd8b7 fix(mbedtls): Enable signature verification s/w fallback when ECDSA curve is disabled 2025-05-20 12:18:07 +05:30
Harshal Patil 51fef26287 Merge branch 'fix/configure_xip_psram_alignment_gaps_heap_by_default' into 'master'
Add XIP PSRAM alignment gaps in heap only if PSRAM protection is enabled

See merge request espressif/esp-idf!38888
2025-05-12 15:07:07 +08:00
harshal.patil 3123fff18a fix(esp_psram): Add XIP PSRAM alignment gaps in heap only if PSRAM protection is enabled 2025-05-05 10:50:19 +05:30
Harshal Patil d898c2398b Merge branch 'feat/some_xip_psram_related_optimisations_and_fixes' into 'master'
feat(esp_psram): Fix late PSRAM init and add some wasted XIP PSRAM memory in heap

Closes IDF-11463 and IDF-10555

See merge request espressif/esp-idf!37116
2025-04-30 00:02:19 +08:00
harshal.patil 43a0026701 fix(hal/sha): Fix unaligned memory access in case of non-byte aligned regions 2025-04-29 14:08:42 +05:30
harshal.patil 003b54ebfe feat(esp_psram): XIP from PSRAM can be used only when SPIRAM_BOOT_INIT=y for ESP32P4
In case of ESP32-P4, if SPIRAM memory initialisations are not performed during
boot-up, XIP PSRAM can be setup because of different virtual range of PSRAM and Flash
2025-04-29 11:48:28 +05:30
harshal.patil c67901fc07 ci(esp_psram): Add a test to validate non-bootup PSRAM initialisation
- Also adds a test for the newly added PSRAM helper APIs:
esp_psram_get_heap_pool_size() and esp_psram_get_effective_mapped_size()
2025-04-29 11:48:28 +05:30
harshal.patil f58c78b644 fix(esp_psram): Fix loading PSRAM XIP segments after PMP split has been configured 2025-04-29 11:48:27 +05:30
harshal.patil ab229a34b3 feat(cpu_region_protect): Enable basic memory protection for SPIRAM 2025-04-29 11:48:27 +05:30
harshal.patil 49f253361e feat(esp_psram): Add the gap created due to alignment of XIP segments in heap 2025-04-29 11:48:27 +05:30
harshal.patil 0f628496c8 feat(esp_psram): Add some helper APIs to get usable PSRAM memory size 2025-04-29 11:48:27 +05:30
harshal.patil 46225a4026 feat(esp_psram): Add a new API to just detect and enable the PSRAM
- esp_psram_chip_init() just detects and does basic initialisations of PSRAM
- esp_psram_init() initialises and maps/loads the PSRAM pages
2025-04-29 11:48:27 +05:30
harshal.patil b0d9ccf6e3 fix(mbedtls): Fix config dependencies when ROM mbedtls is used 2025-04-21 13:38:29 +05:30
harshal.patil a42be5b1dd fix(wpa_supplicant): Disable fastpbkdf2 when s/w and h/w SHA1 is disabled 2025-04-21 13:38:29 +05:30
harshal.patil e738ec5ccd fix(esp-tls): Fix build failure when CONFIG_MBEDTLS_SHA1_C is disabled 2025-04-21 13:38:29 +05:30
harshal.patil 75fd14efbc fix(docs): Fix unterminated quotes in secure-boot-v2.rst 2025-04-21 11:18:22 +05:30
harshal.patil 9221c4eecd fix(examples): Example CA certs must contain the Key Usage parameter
- Example CA certificates that are used for self-signed client certificates
need to include the Key Usage parameter.
- Python3.13 changed the default context of the SSL context that is
generated using ssl.create_default_context() by enabling the VERIFY_X509_STRICT
flag by default
2025-04-03 09:20:35 +05:30
harshal.patil 4edd6c1f6d fix(bootloader_support): Fix sha handle memory leak when returning error 2025-03-27 09:18:30 +05:30
Harshal Patil a45d713b03 Merge branch 'refactor/unify_bootloader_sha' into 'master'
Unify the bootloader_sha layer

Closes IDF-12704

See merge request espressif/esp-idf!37927
2025-03-26 19:15:25 +08:00
harshal.patil a02dec09ca refactor(bootloader_support): Unify bootloader_sha layer 2025-03-21 16:37:20 +05:30
harshal.patil e442f11320 feat(mbedtls): Make mbedtls SHA1 support configurable 2025-03-19 14:28:40 +05:30
harshal.patil a6ea9bcd41 fix(secure_boot): Fix SB verification failure when sig block and key digest mismatch
- Secure boot V2 verification failed when multiple keys are used to sign the bootloader
  and the application is signed with a key other than the first key that is used to
  sign the bootloader.
- The issue was introduced as a regression from the commit `ff16ce43`.
- Added a QEMU test for recreating the issue.
- Made SECURE_BOOT_FLASH_BOOTLOADER_DEFAULT independent of SECURE_BOOT_BUILD_SIGNED_BINARIES.
2025-03-04 11:26:51 +05:30
harshal.patil 700f62e206 feat(wpa_supplicant): Support all targets generically in fastpsk 2025-03-03 14:04:45 +05:30
harshal.patil a1e6387c16 fix(esp_psram): Fix incorrect calculation of used XIP PSRAM pages
The functions mmu_config_psram_text_segment() and mmu_config_psram_rodata_segment()
used to return the value of next start page in *out_page instead of the number
of pages used as mentioned in the documentation
2025-02-21 11:07:39 +05:30
harshal.patil d403005afc change(mbedtls/sha): Change the legacy formatting in the SHA port layers 2025-02-11 11:04:57 +05:30
harshal.patil 2717e5b62e fix(mbedtls/sha): Fix some local variable's types to avoid any substraction overflow error
- Though such a case would not occur given the way it is used the driver layer
2025-02-11 10:58:16 +05:30
Harshal Patil 7c9c2537ed Merge branch 'feat/support_both_aes_and_sha_block_and_dma_modes_during_runtime' into 'master'
feat(mbedtls): Support both SHA block and DMA modes during runtime

Closes IDF-11848

See merge request espressif/esp-idf!36589
2025-02-06 11:19:51 +08:00
harshal.patil 7d8211bf87 feat(mbedtls): Support both SHA block and DMA modes during runtime
Dynamically switch the SHA operation modes based on the buffer operating length
2025-02-04 16:49:30 +05:30
harshal.patil 62df1017ad change(nvs_sec_provider): Change NVS encryption's default efuse HMAC key ID to -1 2025-01-29 18:51:29 +05:30
harshal.patil f205476ffe fix(nvs_flash): Add encrypted-flash as the dependency in nvs_create_partition_image() 2025-01-29 18:51:29 +05:30
harshal.patil c7f86301e6 change(bootloader): Increase the iram_seg size of bootloader to fit NVS encryption 2025-01-29 18:51:29 +05:30
harshal.patil 5b17375aca test(nvs_flash): Extend the nvs_flash test app to support encrypted NVS reads 2025-01-29 18:51:29 +05:30
harshal.patil 3b7d71eca2 feat(examples): Extend the bootloader_nvs example to support encrypted NVS reads 2025-01-29 18:51:29 +05:30
harshal.patil cadd6b8bcc feat(nvs_flash): Support reading encrypted NVS partitions in the bootloader 2025-01-29 18:51:29 +05:30
harshal.patil 37de702e97 feat(nvs_flash): Enable the usage of mbedtls from ROM for bootloader NVS decryption
Bootloader NVS decryption uses hardware ROM APIs to decrypt the NVS contents,
but for targets that do not support AES hardware we could benefit by using the
software mbedtls library that is present in the ROM directly.
2025-01-29 18:51:29 +05:30
harshal.patil 7c3832ff2a feat(nvs_flash): Add a minimal XTS-AES layer for the bootloader 2025-01-29 18:51:29 +05:30