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));