Esp32 nvs encryption issue
Posted: Sat Jan 27, 2024 1:16 pm
I have an issue with nvs encryption.
The target is unicore esp32 (ESP32-U4WDH revision 3).
My project has the following partition structure:
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x140000,
app1, app, ota_1, ,0x140000,
spiffs, data, spiffs, ,0x160000,
nvs_key, data, nvs_keys, , 0x1000, encrypted
The actual fimware is generated in PlatformiO IDE and the transferred to ESP-IDF and flashed to esp32. The bootloader has encryption enabled (as well, nvs-encryption enabled) in development mode. UART download/encrypt/decrypt not disabled. The encryption key generated and burned to eFuses. The flash erased completely before flashing the content. The bootloader, partition table and firmware flashed in encrypted form.
The flash encryption works fine, the app is encrypted.
I have included following lines in my code:
----------
esp_err_t ret;
Serial.begin(115200);
nvs_flash_erase(); // erasing nvs at every startup
ret = nvs_flash_init();
Serial.println("NVS Init");
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
Serial.println("NVS erased and initialized");
}
if (ret != ESP_OK) {
Serial.printf("NVS init failed error code: %d\n", ret);
} else {
Serial.println("NVS initialized.\n");
}
ESP_ERROR_CHECK(ret);
-----------
The nvs partition is still saving the wifi credentials as plain text. What am I doing wrong / some additional steps missing?
The target is unicore esp32 (ESP32-U4WDH revision 3).
My project has the following partition structure:
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x140000,
app1, app, ota_1, ,0x140000,
spiffs, data, spiffs, ,0x160000,
nvs_key, data, nvs_keys, , 0x1000, encrypted
The actual fimware is generated in PlatformiO IDE and the transferred to ESP-IDF and flashed to esp32. The bootloader has encryption enabled (as well, nvs-encryption enabled) in development mode. UART download/encrypt/decrypt not disabled. The encryption key generated and burned to eFuses. The flash erased completely before flashing the content. The bootloader, partition table and firmware flashed in encrypted form.
The flash encryption works fine, the app is encrypted.
I have included following lines in my code:
----------
esp_err_t ret;
Serial.begin(115200);
nvs_flash_erase(); // erasing nvs at every startup
ret = nvs_flash_init();
Serial.println("NVS Init");
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
Serial.println("NVS erased and initialized");
}
if (ret != ESP_OK) {
Serial.printf("NVS init failed error code: %d\n", ret);
} else {
Serial.println("NVS initialized.\n");
}
ESP_ERROR_CHECK(ret);
-----------
The nvs partition is still saving the wifi credentials as plain text. What am I doing wrong / some additional steps missing?