From 363824c03692d0d34a3871d0d7e70adcf2a19475 Mon Sep 17 00:00:00 2001 From: Poovendhan Selvaraj Date: Thu, 3 Aug 2023 19:28:07 +0530 Subject: [PATCH] aes : Add fix to read correct value from ram address for derive_aes_256_key cmd Change-Id: I0e3080b641b3b050655fdbb626273ec14cbc6aa2 Signed-off-by: Poovendhan Selvaraj --- common/cmd_aes.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/common/cmd_aes.c b/common/cmd_aes.c index bd9152e6ff..7af8cbb93d 100644 --- a/common/cmd_aes.c +++ b/common/cmd_aes.c @@ -118,15 +118,13 @@ static int do_derive_aes_256_key(cmd_tbl_t *cmdtp, int flag, struct crypto_aes_derive_key_cmd_t *req_ptr = NULL; int ret = CMD_RET_USAGE; uintptr_t *key_handle = NULL; - char *context_buf = NULL; + uint8_t *context_buf = NULL; int context_len = 0; int i = 0, j = 0; - unsigned char temp; if (argc != 5) return ret; - - context_buf = argv[3]; + context_buf = (uint8_t *)simple_strtoul(argv[3], NULL, 16);; context_len = simple_strtoul(argv[4], NULL, 16); if (context_len > 64) { printf("Error: context length should be less than 64\n"); @@ -142,19 +140,14 @@ static int do_derive_aes_256_key(cmd_tbl_t *cmdtp, int flag, req_ptr->policy.key_type = DEFAULT_KEY_TYPE; req_ptr->policy.destination = DEFAULT_POLICY_DESTINATION; req_ptr->source = simple_strtoul(argv[1], NULL, 16); - req_ptr->hw_key_bindings.bindings = simple_strtoul(argv[2], NULL, 16);; + req_ptr->hw_key_bindings.bindings = simple_strtoul(argv[2], NULL, 16); key_handle = (uintptr_t *)memalign(ARCH_DMA_MINALIGN, sizeof(uint64_t)); req_ptr->key = (uintptr_t) key_handle; req_ptr->mixing_key = 0; req_ptr->hw_key_bindings.context_len = context_len; - - while(context_buf[i] != '\0' && i < context_len*2) { - temp = toBinary(context_buf[i]) << 4; - temp += toBinary(context_buf[i+1]); - req_ptr->hw_key_bindings.context[j] = temp; - j++; - i += 2; + while (i < context_len) { + req_ptr->hw_key_bindings.context[j++] = context_buf[i++]; } ret = qca_scm_crypto(TZ_CRYPTO_SERVICE_AES_DERIVE_KEY_ID, (void *)req_ptr, sizeof(struct crypto_aes_derive_key_cmd_t));