Transparent FS Encryption "Rewrite" Data Clarification

pctj101
Posts: 11
Joined: Wed Aug 23, 2017 3:20 pm

Transparent FS Encryption "Rewrite" Data Clarification

Postby pctj101 » Fri Sep 13, 2019 12:13 pm

I understand that flash allows bits to go from 1->0, then we can reset a 4k page back all at once from 0->1

Yet esp-idf allows just 32bit writes to an encrypted partition.
https://docs.espressif.com/projects/esp ... ypt-config
> AES-256 operates on 16 byte blocks of data. The flash encryption
engine encrypts and decrypts data in 32 byte blocks, two AES blocks in series.

Understanding encryption, it's fairly random how those 32 bits end up in value.

Can I
A) Expect that writing to the same 32 bits will result in corrupted data? (because no transparent page 0->1)
B) Expect that if any bits need to go from 0->1 that the whole 4k page will be transparently backed up, erased, then re-written correctly as long as the power doesn't go out
C) Expect that if any bits need to go from 0->1 that the whole 4k page will be transparently backed up, erased, then re-written correctly in some magical atomic fashion immune to power outage? (haha)

And if A) rewriting the same bits can result in corruption, how does the FS leave all bits at 1* until encryption is necessary? Just don't touch the other bits other than the 32 bits in question? (would be technically fine as long as I know)

Thanks a bunch for anyone who just happens to know the answer.

WiFive
Posts: 2624
Joined: Tue Dec 01, 2015 7:35 am

Re: Transparent FS Encryption "Rewrite" Data Clarification

Postby WiFive » Fri Sep 13, 2019 1:10 pm

A. Yes
B. With flash and partition apis you need to do this yourself. With NVS and fatfs it is handled by the implementation.
C. See below
https://docs.espressif.com/projects/esp ... flash.html
The library does try to recover from conditions when flash memory is in an inconsistent state. In particular, one should be able to power off the device at any point and time and then power it back on. This should not result in loss of data, except for the new key-value pair if it was being written at the moment of powering off.
https://docs.espressif.com/projects/esp ... lling.html
Safety mode. The data is first saved to flash memory, and after the sector is erased, the data is saved back. If a device is powered off, the data can be recovered as soon as the device boots up.

pctj101
Posts: 11
Joined: Wed Aug 23, 2017 3:20 pm

Re: Transparent FS Encryption "Rewrite" Data Clarification

Postby pctj101 » Fri Sep 13, 2019 1:39 pm

Thanks Wifive!

Do you happen to know, does the spiflash for fatfs refer to the onboard SPI flash (I assume a particular partition) within the WROOM32 module? Or does it refer ONLY to offboard spiflash (just like offboard sdcard)?

WiFive
Posts: 2624
Joined: Tue Dec 01, 2015 7:35 am

Re: Transparent FS Encryption "Rewrite" Data Clarification

Postby WiFive » Fri Sep 13, 2019 11:12 pm

Yes, internal/onboard. The encryption only works with internal flash. In esp-idf 4.x you can use filesystems on external flash but there is no encryption.

pctj101
Posts: 11
Joined: Wed Aug 23, 2017 3:20 pm

Re: Transparent FS Encryption "Rewrite" Data Clarification

Postby pctj101 » Sat Sep 14, 2019 11:49 am

Thanks WiFive!

Who is online

Users browsing this forum: Google [Bot], xSampaio and 20 guests