[Cryptech-Commits] [sw/libhal] 03/04: alloc mkmif core around both reads (status + KEK)
git at cryptech.is
git at cryptech.is
Wed Mar 11 00:11:19 UTC 2020
This is an automated email from the git hooks/post-receive script.
paul at psgd.org pushed a commit to branch master
in repository sw/libhal.
commit fd8ca81821b6a146e6e628860436f86020eac998
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Tue Mar 10 19:32:23 2020 -0400
alloc mkmif core around both reads (status + KEK)
---
mkm.c | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/mkm.c b/mkm.c
index 46abe69..4119744 100644
--- a/mkm.c
+++ b/mkm.c
@@ -4,6 +4,8 @@
* Master Key Memory functions.
*
* Copyright (c) 2016-2019, NORDUnet A/S All rights reserved.
+ * Copyright: 2020, The Commons Conservancy Cryptech Project
+ * SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -110,14 +112,18 @@ hal_error_t hal_mkm_volatile_read(uint8_t *buf, const size_t len)
{
hal_error_t err;
uint32_t status;
+ hal_core_t *core = NULL;
if (len && len != KEK_LENGTH)
return HAL_ERROR_MASTERKEY_BAD_LENGTH;
if ((err = hal_mkm_volatile_init()) != HAL_OK ||
- (err = hal_mkmif_read_word(NULL, MKM_VOLATILE_STATUS_ADDRESS, &status)) != HAL_OK)
+ (err = hal_core_alloc(MKMIF_NAME, &core, NULL)) != HAL_OK)
return err;
+ if ((err = hal_mkmif_read_word(core, MKM_VOLATILE_STATUS_ADDRESS, &status)) != HAL_OK)
+ goto out;
+
if (buf != NULL && len) {
/*
* Don't return the random bytes in the RAM memory in case it isn't initialized.
@@ -125,10 +131,15 @@ hal_error_t hal_mkm_volatile_read(uint8_t *buf, const size_t len)
*/
if (status != MKM_STATUS_SET)
memset(buf, 0x0, len);
- else if ((err = hal_mkmif_read(NULL, MKM_VOLATILE_STATUS_ADDRESS + 4, buf, len)) != HAL_OK)
- return err;
+ else
+ err = hal_mkmif_read(core, MKM_VOLATILE_STATUS_ADDRESS + 4, buf, len);
}
+out:
+ hal_core_free(core);
+ if (err != HAL_OK)
+ return err;
+
if (status == MKM_STATUS_SET)
return HAL_OK;
@@ -141,6 +152,7 @@ hal_error_t hal_mkm_volatile_read(uint8_t *buf, const size_t len)
hal_error_t hal_mkm_volatile_write(const uint8_t * const buf, const size_t len)
{
hal_error_t err;
+ hal_core_t *core = NULL;
if (len != KEK_LENGTH)
return HAL_ERROR_MASTERKEY_BAD_LENGTH;
@@ -149,27 +161,34 @@ hal_error_t hal_mkm_volatile_write(const uint8_t * const buf, const size_t len)
return HAL_ERROR_MASTERKEY_FAIL;
if ((err = hal_mkm_volatile_init()) != HAL_OK ||
- (err = hal_mkmif_write(NULL, MKM_VOLATILE_STATUS_ADDRESS + 4, buf, len)) != HAL_OK ||
- (err = hal_mkmif_write_word(NULL, MKM_VOLATILE_STATUS_ADDRESS, MKM_STATUS_SET)) != HAL_OK)
+ (err = hal_core_alloc(MKMIF_NAME, &core, NULL)) != HAL_OK)
return err;
- return HAL_OK;
+ if ((err = hal_mkmif_write(core, MKM_VOLATILE_STATUS_ADDRESS + 4, buf, len)) == HAL_OK)
+ err = hal_mkmif_write_word(core, MKM_VOLATILE_STATUS_ADDRESS, MKM_STATUS_SET);
+
+ hal_core_free(core);
+ return err;
}
hal_error_t hal_mkm_volatile_erase(const size_t len)
{
uint8_t buf[KEK_LENGTH] = {0};
hal_error_t err;
+ hal_core_t *core = NULL;
if (len != KEK_LENGTH)
return HAL_ERROR_MASTERKEY_BAD_LENGTH;
if ((err = hal_mkm_volatile_init()) != HAL_OK ||
- (err = hal_mkmif_write(NULL, MKM_VOLATILE_STATUS_ADDRESS + 4, buf, sizeof(buf))) != HAL_OK ||
- (err = hal_mkmif_write_word(NULL, MKM_VOLATILE_STATUS_ADDRESS, MKM_STATUS_NOT_SET)) != HAL_OK)
+ (err = hal_core_alloc(MKMIF_NAME, &core, NULL)) != HAL_OK)
return err;
- return HAL_OK;
+ if ((err = hal_mkmif_write(NULL, MKM_VOLATILE_STATUS_ADDRESS + 4, buf, sizeof(buf))) == HAL_OK)
+ err = hal_mkmif_write_word(NULL, MKM_VOLATILE_STATUS_ADDRESS, MKM_STATUS_NOT_SET);
+
+ hal_core_free(core);
+ return err;
}
/*
More information about the Commits
mailing list