|
| 1 | +## Encrypted external partitions |
| 2 | + |
| 3 | +wolfBoot offers the possibility to encrypt the content of the entire UPDATE partition, |
| 4 | +by using a pre-shared symmetric key which can be temporarily stored in a safer non-volatile memory area. |
| 5 | + |
| 6 | +SWAP partition is also temporarily encrypted using the same key, so a dump of the external flash won't reveal |
| 7 | +any content of the firmware update packages. |
| 8 | + |
| 9 | +### Rationale |
| 10 | + |
| 11 | +Encryption of external partition works at the level of the external flash interface. |
| 12 | + |
| 13 | +All write calls to external partitions from the bootloader perform an additional encryption step |
| 14 | +to hide the actual content of the external non-volatile memory. |
| 15 | + |
| 16 | +Viceversa, all read operations will decrypt the data stored when the feature is enabled. |
| 17 | + |
| 18 | +An extra option is provided to the `sign.py` sign tool to encrypt the firmware update after signing it, so |
| 19 | +that it can be stored as is in the external memory by the application, and will be decrypted by the bootloader |
| 20 | +in order to verify the update and begin the installation. |
| 21 | + |
| 22 | + |
| 23 | +### Temporary key storage |
| 24 | + |
| 25 | +By default, wolfBoot will store the pre-shared symmetric key used for encryption in a temporary area |
| 26 | +on the internal flash. This allows read-out protections to be used to hide the temporary key. |
| 27 | + |
| 28 | +Alternatively, more secure mechanisms are available to store the temporary key in a different key storage |
| 29 | +(e.g. using a hardware security module or a TPM device). |
| 30 | + |
| 31 | +The temporary key can be set at run time by the application, and will be used exactly once by the bootloader |
| 32 | +to verify and install the next update. The key can be for example received from a back-end during the update |
| 33 | +process using secure communication, and set by the application, using `libwolfboot` API, to be used by |
| 34 | +wolfBoot upon next boot. |
| 35 | + |
| 36 | +Aside from setting the temporary key, the update mechanism remains the same for distrubuting, uploading and |
| 37 | +installing firmware updates through wolfBoot. |
| 38 | + |
| 39 | +### Libwolfboot API |
| 40 | + |
| 41 | +The API to communicate with the bootloader from the application is expanded when this feature is enabled, |
| 42 | +to allow setting a temporary key to process the next update. |
| 43 | + |
| 44 | +The functions |
| 45 | + |
| 46 | +``` |
| 47 | +int wolfBoot_set_encrypt_key(const uint8_t *key, int len); |
| 48 | +int wolfBoot_erase_encrypt_key(void); |
| 49 | +``` |
| 50 | + |
| 51 | +can be used to set a temporary encryption key for the external partition, or erase a key previously set, respectively. |
| 52 | + |
| 53 | +Moreover, using `libwolfboot` to access the external flash with wolfboot hal from the application will not |
| 54 | +use encryption. This way the received update, already encrypted at origin, can be stored in the external |
| 55 | +memory unchanged, and retreived in its encrypted format, e.g. to verify that the transfer has been successful before |
| 56 | +reboot. |
| 57 | + |
| 58 | +### Symmetric encryption algorithm |
| 59 | + |
| 60 | +The algorithm currently used to encrypt and decrypt data in external partitions |
| 61 | +is Chacha20-256. The expected key to provide to `wolfBoot_set_encrypt_key()` must be exactly 32 Bytes long. |
| 62 | + |
| 63 | + |
0 commit comments