🛠 Secure boot RSA-3072 et chiffrement de la flash

ESP32-S2 · avance · Schéma : IMG-esp32-s2-avance-2-esp32-s2-secure-boot-chiffrement.svg — ESP32-S2 reliée en USB à un ordinateur, cadenas et bouclier au-dessus de la puce, icône de clé RSA-3072 et puce de flash chiffrée en AES-XTS.

Objectives

Secure an ESP32-S2 production: enable secure boot v2 (RSA-3072 signature, the S2 only accepts this key size) which rejects any unsigned firmware, and flash encryption (AES-XTS) which makes reading the chip useless without the key. Irreversible operations via eFuses: test on a dedicated development board.

Hardware

Complete code

// Verification a l'execution de l'etat de securite (Arduino-ESP32)
#include <esp_secure_boot.h>
#include <esp_flash_encryption.h>

void setup {
  Serial.begin(115200);
  delay(1000);
  Serial.printf("Secure boot actif      : %s\n",
                esp_secure_boot_enabled ? "OUI" : "NON");
  Serial.printf("Chiffrement flash actif : %s\n",
                esp_flash_encryption_enabled ? "OUI" : "NON");
}

void loop { delay(5000); }

eFuse burning commands (read twice before executing):

# 1. Genere la cle de signature RSA-3072 (secure boot v2)
espsecure.py generate_signing_key --version 2 ma_cle.pem
# 2. Convertit le binaire signe
espsecure.py sign_data --version 2 --keyfile ma_cle.pem --output firmware_signed.bin firmware.bin
# 3. Grave la cle dans les eFuses puis active le secure boot
espefuse.py --port COM3 burn_key secure_boot_v2_0 ma_cle.bin
espefuse.py --port COM3 burn_efuse SECURE_BOOT_ENABLE
# 4. Chiffrement de la flash (AES-XTS)
espefuse.py --port COM3 burn_key flash_encryption cle_flash.bin
espefuse.py --port COM3 burn_efuse FLASH_CRYPT_CONFIG 0xF
espefuse.py --port COM3 burn_efuse FLASH_ENCRYPT

Expected verification

After burning, the status sketch displays "Secure boot active: YES" and "Flash encryption active: YES". An unsigned firmware refuses to start (the serial monitor remains silent or displays a boot failure). An attempt to read the flash with esptool outputs only unreadable encrypted data.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials