aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ks_flash.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/ks_flash.c b/ks_flash.c
index b9397f8..c0179ca 100644
--- a/ks_flash.c
+++ b/ks_flash.c
@@ -1075,7 +1075,13 @@ static hal_error_t ks_store(hal_ks_t *ks,
k->der_len = SIZEOF_FLASH_KEY_BLOCK_DER;
k->attributes_len = 0;
- if ((err = hal_mkm_get_kek(kek, &kek_len, sizeof(kek))) == HAL_OK)
+ if (db.ksi.used < db.ksi.size)
+ err = block_erase_maybe(db.ksi.index[db.ksi.used]);
+
+ if (err == HAL_OK)
+ err = hal_mkm_get_kek(kek, &kek_len, sizeof(kek));
+
+ if (err == HAL_OK)
err = hal_aes_keywrap(NULL, kek, kek_len, der, der_len, k->der, &k->der_len);
memset(kek, 0, sizeof(kek));