aboutsummaryrefslogtreecommitdiff
path: root/ks_flash.c
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2017-02-14 20:01:04 -0500
committerRob Austein <sra@hactrn.net>2017-02-14 20:01:04 -0500
commit44652e52ae7b238adcac5a347ca74f2a9838ab6f (patch)
tree29016cc0fc056fcff2ebbde81aeb9c406525552a /ks_flash.c
parentc05eb9f25182bf0db349d943855bebeccca0c691 (diff)
Erase new head of free list in ks_store().
Diffstat (limited to 'ks_flash.c')
-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));