ESP32 Flash Encryption: Which operations consume FLASH_CRYPT_CNT bits, and does the host need the key?

PETERESP
Posts: 16
Joined: Mon May 25, 2026 7:45 am

ESP32 Flash Encryption: Which operations consume FLASH_CRYPT_CNT bits, and does the host need the key?

Postby PETERESP » Sun Aug 02, 2026 9:30 am

I have some questions about flash encryption in development mode, specifically about which operations consume a FLASH_CRYPT_CNT bit and which do not, and whether the host PC needs to hold the encryption key.

From the documentation I understand that FLASH_CRYPT_CNT is a 7-bit eFuse field, and each time plaintext firmware is flashed and encrypted in-place on boot, the next bit is set, giving a maximum of 4 plaintext flash cycles in development mode.

What I am unclear about is the following scenarios:

Code: Select all

Method                                        | PC needs key? | Consumes FLASH_CRYPT_CNT?
----------------------------------------------|---------------|-------------------------
UART flash plaintext, in-place encrypt on boot| No            | Yes
OTA via esp_partition_write()                 | No            | No
PC pre-encrypts, flashes ciphertext via UART  | Yes           | ?
idf.py encrypted-app-flash (dev mode)         | No            | ?
idf.py encrypted-flash (dev mode)             | No            | ?
Release mode: UART flash pre-encrypted data   | Yes           | ?
My specific questions are:

1. For idf.py encrypted-app-flash and idf.py encrypted-flash, does the UART download mode use the hardware encryption engine to write ciphertext directly, bypassing the in-place encryption on boot, and therefore not consuming a FLASH_CRYPT_CNT bit?

2. If flashing pre-encrypted ciphertext via UART, does the bootloader still flip FLASH_CRYPT_CNT on the next boot, or does it detect via FLASH_CRYPT_CNT odd/even state that no in-place encryption is needed?

3. Since FLASH_CRYPT_CNT odd/even is the only mechanism the bootloader uses to decide whether to encrypt, and the bootloader cannot inspect flash content directly to determine if it is encrypted, how exactly does the bootloader decide whether to consume a bit after flashing via encrypted-app-flash?

Thank you.

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32 Flash Encryption: Which operations consume FLASH_CRYPT_CNT bits, and does the host need the key?

Postby MicroController » Mon Aug 03, 2026 7:21 am

FLASH_CRYPT_CNT is used by the bootloader to determine if there's plaintext in flash it needs to encrypt. When you flash a host-encrypted binary, FLASH_CRYPT_CNT can stay untouched.

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest