@ -28,13 +28,13 @@ DECLARE_GLOBAL_DATA_PTR;
*/
*/
static int do_aes ( cmd_tbl_t * cmdtp , int flag , int argc , char * const argv [ ] )
static int do_aes ( cmd_tbl_t * cmdtp , int flag , int argc , char * const argv [ ] )
{
{
uint32_t key_addr , src_addr , dst_addr , len ;
uint32_t key_addr , iv_addr , src_addr , dst_addr , len ;
uint8_t * key_ptr , * src_ptr , * dst_ptr ;
uint8_t * key_ptr , * iv_ptr , * src_ptr , * dst_ptr ;
uint8_t key_exp [ AES_EXPAND_KEY_LENGTH ] ;
uint8_t key_exp [ AES_EXPAND_KEY_LENGTH ] ;
uint32_t aes_blocks ;
uint32_t aes_blocks ;
int enc ;
int enc ;
if ( argc ! = 6 )
if ( argc ! = 7 )
return CMD_RET_USAGE ;
return CMD_RET_USAGE ;
if ( ! strncmp ( argv [ 1 ] , " enc " , 3 ) )
if ( ! strncmp ( argv [ 1 ] , " enc " , 3 ) )
@ -45,11 +45,13 @@ static int do_aes(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
return CMD_RET_USAGE ;
return CMD_RET_USAGE ;
key_addr = simple_strtoul ( argv [ 2 ] , NULL , 16 ) ;
key_addr = simple_strtoul ( argv [ 2 ] , NULL , 16 ) ;
src_addr = simple_strtoul ( argv [ 3 ] , NULL , 16 ) ;
iv_addr = simple_strtoul ( argv [ 3 ] , NULL , 16 ) ;
dst_addr = simple_strtoul ( argv [ 4 ] , NULL , 16 ) ;
src_addr = simple_strtoul ( argv [ 4 ] , NULL , 16 ) ;
len = simple_strtoul ( argv [ 5 ] , NULL , 16 ) ;
dst_addr = simple_strtoul ( argv [ 5 ] , NULL , 16 ) ;
len = simple_strtoul ( argv [ 6 ] , NULL , 16 ) ;
key_ptr = ( uint8_t * ) key_addr ;
key_ptr = ( uint8_t * ) key_addr ;
iv_ptr = ( uint8_t * ) iv_addr ;
src_ptr = ( uint8_t * ) src_addr ;
src_ptr = ( uint8_t * ) src_addr ;
dst_ptr = ( uint8_t * ) dst_addr ;
dst_ptr = ( uint8_t * ) dst_addr ;
@ -60,9 +62,11 @@ static int do_aes(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
aes_blocks = DIV_ROUND_UP ( len , AES_KEY_LENGTH ) ;
aes_blocks = DIV_ROUND_UP ( len , AES_KEY_LENGTH ) ;
if ( enc )
if ( enc )
aes_cbc_encrypt_blocks ( key_exp , src_ptr , dst_ptr , aes_blocks ) ;
aes_cbc_encrypt_blocks ( key_exp , iv_ptr , src_ptr , dst_ptr ,
aes_blocks ) ;
else
else
aes_cbc_decrypt_blocks ( key_exp , src_ptr , dst_ptr , aes_blocks ) ;
aes_cbc_decrypt_blocks ( key_exp , iv_ptr , src_ptr , dst_ptr ,
aes_blocks ) ;
return 0 ;
return 0 ;
}
}
@ -70,20 +74,22 @@ static int do_aes(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
/***************************************************/
/***************************************************/
# ifdef CONFIG_SYS_LONGHELP
# ifdef CONFIG_SYS_LONGHELP
static char aes_help_text [ ] =
static char aes_help_text [ ] =
" enc key src dst len - Encrypt block of data $len bytes long \n "
" enc key iv src dst len - Encrypt block of data $len bytes long \n "
" at address $src using a key at address \n "
" at address $src using a key at address \n "
" $key and store the result at address \n "
" $key with initialization vector at address \n "
" $dst. The $len size must be multiple of \n "
" $iv. Store the result at address $dst. \n "
" 16 bytes and $key must be 16 bytes long. \n "
" The $len size must be multiple of 16 bytes. \n "
" aes dec key src dst len - Decrypt block of data $len bytes long \n "
" The $key and $iv must be 16 bytes long. \n "
" at address $src using a key at address \n "
" aes dec key iv src dst len - Decrypt block of data $len bytes long \n "
" $key and store the result at address \n "
" at address $src using a key at address \n "
" $dst. The $len size must be multiple of \n "
" $key with initialization vector at address \n "
" 16 bytes and $key must be 16 bytes long. " ;
" $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. " ;
# endif
# endif
U_BOOT_CMD (
U_BOOT_CMD (
aes , 6 , 1 , do_aes ,
aes , 7 , 1 , do_aes ,
" AES 128 CBC encryption " ,
" AES 128 CBC encryption " ,
aes_help_text
aes_help_text
) ;
) ;