Skip to content

Commit cf431dc

Browse files
tomi-fontrlubos
authored andcommitted
secure_storage: huk: add some checks and logging
To be more user-friendly. Signed-off-by: Tomi Fontanilles <[email protected]>
1 parent 3155b35 commit cf431dc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

subsys/secure_storage/src/its_transform_aead_get_key_huk.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
33
*/
44
#include <zephyr/secure_storage/its/transform/aead_get.h>
5+
#include <zephyr/logging/log.h>
56
#include <hw_unique_key.h>
67
#include <psa/crypto_values.h>
78

9+
LOG_MODULE_DECLARE(secure_storage, CONFIG_SECURE_STORAGE_LOG_LEVEL);
10+
811
psa_status_t secure_storage_its_transform_aead_get_key(
912
secure_storage_its_uid_t uid,
1013
uint8_t key[static CONFIG_SECURE_STORAGE_ITS_TRANSFORM_AEAD_KEY_SIZE])
1114
{
1215
int result;
1316
enum hw_unique_key_slot key_slot;
1417

18+
if (!hw_unique_key_are_any_written()) {
19+
return PSA_ERROR_BAD_STATE;
20+
}
21+
1522
#ifdef HUK_HAS_KMU
1623
key_slot = HUK_KEYSLOT_MKEK;
1724
#else
@@ -21,7 +28,8 @@ psa_status_t secure_storage_its_transform_aead_get_key(
2128
result = hw_unique_key_derive_key(key_slot, NULL, 0, (uint8_t *)&uid, sizeof(uid), key,
2229
CONFIG_SECURE_STORAGE_ITS_TRANSFORM_AEAD_KEY_SIZE);
2330
if (result != HW_UNIQUE_KEY_SUCCESS) {
24-
return PSA_ERROR_BAD_STATE;
31+
LOG_DBG("Failed to derive key. (%#x)", result);
32+
return PSA_ERROR_GENERIC_ERROR;
2533
}
2634

2735
return PSA_SUCCESS;

0 commit comments

Comments
 (0)