aboutsummaryrefslogtreecommitdiff
path: root/ks_token.c
diff options
context:
space:
mode:
Diffstat (limited to 'ks_token.c')
-rw-r--r--ks_token.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/ks_token.c b/ks_token.c
index 3f2194a..1676bc0 100644
--- a/ks_token.c
+++ b/ks_token.c
@@ -52,7 +52,7 @@
#include "last_gasp_pin_internal.h"
-#define HAL_OK CMIS_HAL_OK
+#define HAL_OK CMSIS_HAL_OK
#include "stm-keystore.h"
#undef HAL_OK
@@ -106,10 +106,9 @@ static hal_error_t ks_token_read(hal_ks_t *ks, const unsigned blockno, hal_ks_bl
if (ks != hal_ks_token || block == NULL || blockno >= NUM_FLASH_BLOCKS || sizeof(*block) != HAL_KS_BLOCK_SIZE)
return HAL_ERROR_IMPOSSIBLE;
- /* Sigh, magic numeric return codes */
if (keystore_read_data(ks_token_offset(blockno),
block->bytes,
- KEYSTORE_PAGE_SIZE) != 1)
+ KEYSTORE_PAGE_SIZE) != CMSIS_HAL_OK)
return HAL_ERROR_KEYSTORE_ACCESS;
switch (hal_ks_block_get_type(block)) {
@@ -131,10 +130,9 @@ static hal_error_t ks_token_read(hal_ks_t *ks, const unsigned blockno, hal_ks_bl
return HAL_ERROR_KEYSTORE_BAD_BLOCK_TYPE;
}
- /* Sigh, magic numeric return codes */
if (keystore_read_data(ks_token_offset(blockno) + KEYSTORE_PAGE_SIZE,
block->bytes + KEYSTORE_PAGE_SIZE,
- sizeof(*block) - KEYSTORE_PAGE_SIZE) != 1)
+ sizeof(*block) - KEYSTORE_PAGE_SIZE) != CMSIS_HAL_OK)
return HAL_ERROR_KEYSTORE_ACCESS;
if (hal_ks_block_calculate_crc(block) != block->header.crc)
@@ -158,14 +156,12 @@ static hal_error_t ks_token_deprecate(hal_ks_t *ks, const unsigned blockno)
hal_ks_block_header_t *header = (void *) page;
uint32_t offset = ks_token_offset(blockno);
- /* Sigh, magic numeric return codes */
- if (keystore_read_data(offset, page, sizeof(page)) != 1)
+ if (keystore_read_data(offset, page, sizeof(page)) != CMSIS_HAL_OK)
return HAL_ERROR_KEYSTORE_ACCESS;
header->block_status = HAL_KS_BLOCK_STATUS_TOMBSTONE;
- /* Sigh, magic numeric return codes */
- if (keystore_write_data(offset, page, sizeof(page)) != 1)
+ if (keystore_write_data(offset, page, sizeof(page)) != CMSIS_HAL_OK)
return HAL_ERROR_KEYSTORE_ACCESS;
return HAL_OK;
@@ -182,8 +178,7 @@ static hal_error_t ks_token_zero(hal_ks_t *ks, const unsigned blockno)
uint8_t page[KEYSTORE_PAGE_SIZE] = {0};
- /* Sigh, magic numeric return codes */
- if (keystore_write_data(ks_token_offset(blockno), page, sizeof(page)) != 1)
+ if (keystore_write_data(ks_token_offset(blockno), page, sizeof(page)) != CMSIS_HAL_OK)
return HAL_ERROR_KEYSTORE_ACCESS;
return HAL_OK;
@@ -202,8 +197,7 @@ static hal_error_t ks_token_erase(hal_ks_t *ks, const unsigned blockno)
const unsigned end = (blockno + 1) * SUBSECTORS_PER_BLOCK;
do {
- /* Sigh, magic numeric return codes */
- if (keystore_erase_subsector(subsector) != 1)
+ if (keystore_erase_subsector(subsector) != CMSIS_HAL_OK)
return HAL_ERROR_KEYSTORE_ACCESS;
} while (++subsector < end);
@@ -229,7 +223,7 @@ static hal_error_t ks_token_erase_maybe(hal_ks_t *ks, const unsigned blockno)
for (uint32_t a = ks_token_offset(blockno); a < ks_token_offset(blockno + 1); a += KEYSTORE_PAGE_SIZE) {
uint8_t page[KEYSTORE_PAGE_SIZE];
- if (keystore_read_data(a, page, sizeof(page)) != 1)
+ if (keystore_read_data(a, page, sizeof(page)) != CMSIS_HAL_OK)
return HAL_ERROR_KEYSTORE_ACCESS;
for (int i = 0; i < KEYSTORE_PAGE_SIZE; i++)
mask &= page[i];
@@ -261,8 +255,7 @@ static hal_error_t ks_token_write(hal_ks_t *ks, const unsigned blockno, hal_ks_b
break;
}
- /* Sigh, magic numeric return codes */
- if (keystore_write_data(ks_token_offset(blockno), block->bytes, sizeof(*block)) != 1)
+ if (keystore_write_data(ks_token_offset(blockno), block->bytes, sizeof(*block)) != CMSIS_HAL_OK)
return HAL_ERROR_KEYSTORE_ACCESS;
return HAL_OK;
@@ -417,7 +410,7 @@ hal_ks_t * const hal_ks_token = &_db.ks;
void hal_ks_init_read_only_pins_only(void)
{
- unsigned b, best_seen = ~0;
+ unsigned b, best_seen = NUM_FLASH_BLOCKS;
hal_ks_block_t block[1];
hal_ks_lock();
@@ -431,11 +424,11 @@ void hal_ks_init_read_only_pins_only(void)
break;
}
- if (b != best_seen && best_seen != ~0 &&
+ if (b != best_seen && best_seen != NUM_FLASH_BLOCKS &&
hal_ks_block_read(hal_ks_token, best_seen, block) != HAL_OK)
- best_seen = ~0;
+ best_seen = NUM_FLASH_BLOCKS;
- if (best_seen == ~0) {
+ if (best_seen == NUM_FLASH_BLOCKS) {
memset(block, 0xFF, sizeof(*block));
block->pin.wheel_pin = hal_last_gasp_pin;
}
@@ -653,7 +646,7 @@ hal_error_t hal_mkm_flash_erase(const size_t len)
hal_ks_pin_block_t new_data = block->pin;
- new_data.kek_set = FLASH_KEK_SET;
+ new_data.kek_set = FLASH_KEK_NOT_SET;
memset(new_data.kek, 0, len);
err = update_pin_block(b, block, &new_data);