projects
/
oweals
/
u-boot.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge tag 'arc-fixes-for-2020.07-rc3' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git]
/
cmd
/
aes.c
diff --git
a/cmd/aes.c
b/cmd/aes.c
index 8c61cee8e89b25db485c1e8729d14d5aea5ecd48..8c5b42fd2c4a261e92d461087b677e73eb490713 100644
(file)
--- a/
cmd/aes.c
+++ b/
cmd/aes.c
@@
-2,7
+2,7
@@
/*
* Copyright (C) 2014 Marek Vasut <marex@denx.de>
*
/*
* Copyright (C) 2014 Marek Vasut <marex@denx.de>
*
- * Command for en/de-crypting block of memory with AES-
128
-CBC cipher.
+ * Command for en/de-crypting block of memory with AES-
[128/192/256]
-CBC cipher.
*/
#include <common.h>
*/
#include <common.h>
@@
-13,6
+13,18
@@
#include <linux/compiler.h>
#include <mapmem.h>
#include <linux/compiler.h>
#include <mapmem.h>
+u32 aes_get_key_len(char *command)
+{
+ u32 key_len = AES128_KEY_LENGTH;
+
+ if (!strcmp(command, "aes.192"))
+ key_len = AES192_KEY_LENGTH;
+ else if (!strcmp(command, "aes.256"))
+ key_len = AES256_KEY_LENGTH;
+
+ return key_len;
+}
+
/**
* do_aes() - Handle the "aes" command-line command
* @cmdtp: Command data struct pointer
/**
* do_aes() - Handle the "aes" command-line command
* @cmdtp: Command data struct pointer
@@
-27,13
+39,15
@@
static int do_aes(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
uint32_t key_addr, iv_addr, src_addr, dst_addr, len;
uint8_t *key_ptr, *iv_ptr, *src_ptr, *dst_ptr;
{
uint32_t key_addr, iv_addr, src_addr, dst_addr, len;
uint8_t *key_ptr, *iv_ptr, *src_ptr, *dst_ptr;
- u
int8_t key_exp[AES
_EXPAND_KEY_LENGTH];
- u
int32_t aes_blocks
;
+ u
8 key_exp[AES256
_EXPAND_KEY_LENGTH];
+ u
32 aes_blocks, key_len
;
int enc;
if (argc != 7)
return CMD_RET_USAGE;
int enc;
if (argc != 7)
return CMD_RET_USAGE;
+ key_len = aes_get_key_len(argv[0]);
+
if (!strncmp(argv[1], "enc", 3))
enc = 1;
else if (!strncmp(argv[1], "dec", 3))
if (!strncmp(argv[1], "enc", 3))
enc = 1;
else if (!strncmp(argv[1], "dec", 3))
@@
-47,23
+61,23
@@
static int do_aes(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
dst_addr = simple_strtoul(argv[5], NULL, 16);
len = simple_strtoul(argv[6], NULL, 16);
dst_addr = simple_strtoul(argv[5], NULL, 16);
len = simple_strtoul(argv[6], NULL, 16);
- key_ptr = (uint8_t *)map_sysmem(key_addr,
128 / 8
);
+ key_ptr = (uint8_t *)map_sysmem(key_addr,
key_len
);
iv_ptr = (uint8_t *)map_sysmem(iv_addr, 128 / 8);
src_ptr = (uint8_t *)map_sysmem(src_addr, len);
dst_ptr = (uint8_t *)map_sysmem(dst_addr, len);
/* First we expand the key. */
iv_ptr = (uint8_t *)map_sysmem(iv_addr, 128 / 8);
src_ptr = (uint8_t *)map_sysmem(src_addr, len);
dst_ptr = (uint8_t *)map_sysmem(dst_addr, len);
/* First we expand the key. */
- aes_expand_key(key_ptr, key_exp);
+ aes_expand_key(key_ptr, key_
len, key_
exp);
/* Calculate the number of AES blocks to encrypt. */
/* Calculate the number of AES blocks to encrypt. */
- aes_blocks = DIV_ROUND_UP(len, AES_
KEY
_LENGTH);
+ aes_blocks = DIV_ROUND_UP(len, AES_
BLOCK
_LENGTH);
if (enc)
if (enc)
- aes_cbc_encrypt_blocks(key_
exp, iv_ptr, src_ptr, dst
_ptr,
- aes_blocks);
+ aes_cbc_encrypt_blocks(key_
len, key_exp, iv_ptr, src
_ptr,
+
dst_ptr,
aes_blocks);
else
else
- aes_cbc_decrypt_blocks(key_
exp, iv_ptr, src_ptr, dst
_ptr,
- aes_blocks);
+ aes_cbc_decrypt_blocks(key_
len, key_exp, iv_ptr, src
_ptr,
+
dst_ptr,
aes_blocks);
unmap_sysmem(key_ptr);
unmap_sysmem(iv_ptr);
unmap_sysmem(key_ptr);
unmap_sysmem(iv_ptr);
@@
-76,13
+90,13
@@
static int do_aes(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
/***************************************************/
#ifdef CONFIG_SYS_LONGHELP
static char aes_help_text[] =
/***************************************************/
#ifdef CONFIG_SYS_LONGHELP
static char aes_help_text[] =
- "enc key iv src dst len - Encrypt block of data $len bytes long\n"
+ "
[.128,.192,.256]
enc key iv src dst len - Encrypt block of data $len bytes long\n"
" at address $src using a key at address\n"
" $key with initialization vector at address\n"
" $iv. Store the result at address $dst.\n"
" The $len size must be multiple of 16 bytes.\n"
" The $key and $iv must be 16 bytes long.\n"
" at address $src using a key at address\n"
" $key with initialization vector at address\n"
" $iv. Store the result at address $dst.\n"
" The $len size must be multiple of 16 bytes.\n"
" The $key and $iv must be 16 bytes long.\n"
- "aes dec key iv src dst len - Decrypt block of data $len bytes long\n"
+ "aes
[.128,.192,.256]
dec key iv src dst len - Decrypt block of data $len bytes long\n"
" at address $src using a key at address\n"
" $key with initialization vector at address\n"
" $iv. Store the result at address $dst.\n"
" at address $src using a key at address\n"
" $key with initialization vector at address\n"
" $iv. Store the result at address $dst.\n"
@@
-92,6
+106,6
@@
static char aes_help_text[] =
U_BOOT_CMD(
aes, 7, 1, do_aes,
U_BOOT_CMD(
aes, 7, 1, do_aes,
- "AES 128 CBC encryption",
+ "AES 128
/192/256
CBC encryption",
aes_help_text
);
aes_help_text
);