From 116d03ab6d40ba87140800cf0cf15fad03e98fd7 Mon Sep 17 00:00:00 2001 From: Sahil Malhotra Date: Mon, 4 Nov 2024 12:44:56 +0100 Subject: [PATCH] drivers: caam: cache align Key blob modifier An array was used as Key blob modifier, changed it cache aligned dynamic memory. Signed-off-by: Sahil Malhotra Acked-by: Jens Wiklander --- core/drivers/crypto/caam/caam_key.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/core/drivers/crypto/caam/caam_key.c b/core/drivers/crypto/caam/caam_key.c index 5205b8b196d..835ad32e1b1 100644 --- a/core/drivers/crypto/caam/caam_key.c +++ b/core/drivers/crypto/caam/caam_key.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: BSD-2-Clause /* - * Copyright 2023 NXP + * Copyright 2023-2024 NXP */ #include #include @@ -57,8 +57,9 @@ * makes it non-volatile and can be re-created when the chip powers up again. */ #define KEY_BLOB_MODIFIER_SIZE 16 -static const uint8_t key_blob_modifier[KEY_BLOB_MODIFIER_SIZE] = - "NXP_OPTEE_BLOB"; +#define KEY_BLOB_MODIFIER "NXP_KEY_MODIFIER" +static_assert(sizeof(KEY_BLOB_MODIFIER) >= KEY_BLOB_MODIFIER_SIZE); +static uint8_t *key_blob_modifier; /* * Serialized CAAM key structure format. @@ -379,6 +380,8 @@ enum caam_status caam_key_operation_blob(const struct caamkey *in_key, KEY_DUMPDESC(desc); + cache_operation(TEE_CACHECLEAN, key_blob_modifier, + KEY_BLOB_MODIFIER_SIZE); caam_key_cache_op(TEE_CACHECLEAN, in_key); caam_key_cache_op(TEE_CACHECLEAN, out_key); @@ -743,6 +746,12 @@ enum caam_status caam_key_init(void) assert(alloc_size <= CFG_CORE_BIGNUM_MAX_BITS); + key_blob_modifier = caam_calloc_align(KEY_BLOB_MODIFIER_SIZE); + if (!key_blob_modifier) + return CAAM_FAILURE; + + memcpy(key_blob_modifier, KEY_BLOB_MODIFIER, KEY_BLOB_MODIFIER_SIZE); + KEY_TRACE("Max serialized key size %zu", alloc_size); KEY_TRACE("Default CAAM key generation type %s",