bootutil: allow encryption key TLVs in swap status
Add a new option that when enabled, allows a swap status to store
an encrypted key TLV instead of plain keys. When a new swap operation is
started the encryption keys are saved to the swap status area to allow
for resuming (because it is challenging to find those TLV in the middle
of a swap operation).
Previously those keys were saved in plain text, so it would be easy to
dump them if the images were stored in external flash. With this new
option one can choose to save the TLV instead, which uses more flash
but does not leak secrets. The amount of flash required varies depending
on the size of the TLV, which is 48 for AES-128-KW, 512 for RSA and 240
for ECIES-P256.
Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/bootutil/src/swap_misc.c b/boot/bootutil/src/swap_misc.c
index 9db3299..31995b6 100644
--- a/boot/bootutil/src/swap_misc.c
+++ b/boot/bootutil/src/swap_misc.c
@@ -114,10 +114,10 @@
assert(rc == 0);
#ifdef MCUBOOT_ENC_IMAGES
- rc = boot_write_enc_key(fap, 0, bs->enckey[0]);
+ rc = boot_write_enc_key(fap, 0, bs);
assert(rc == 0);
- rc = boot_write_enc_key(fap, 1, bs->enckey[1]);
+ rc = boot_write_enc_key(fap, 1, bs);
assert(rc == 0);
#endif