blob: 80478b8802daa24d56c7f81793fa1d082207c8b1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ruchika Gupta4345a572014-10-07 15:46:20 +05302/*
3 *
4 * Command for encapsulating/decapsulating blob of memory.
Ruchika Gupta4345a572014-10-07 15:46:20 +05305 */
6
7#include <common.h>
8#include <command.h>
Ruchika Gupta4345a572014-10-07 15:46:20 +05309#include <malloc.h>
10#include <asm/byteorder.h>
11#include <linux/compiler.h>
12
Ruchika Gupta4345a572014-10-07 15:46:20 +053013/**
14 * blob_decap() - Decapsulate the data as a blob
15 * @key_mod: - Pointer to key modifier/key
16 * @src: - Address of data to be decapsulated
17 * @dst: - Address of data to be decapsulated
18 * @len: - Size of data to be decapsulated
19 *
20 * Returns zero on success,and negative on error.
21 */
22__weak int blob_decap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
23{
24 return 0;
25}
26
27/**
28 * blob_encap() - Encapsulate the data as a blob
29 * @key_mod: - Pointer to key modifier/key
30 * @src: - Address of data to be encapsulated
31 * @dst: - Address of data to be encapsulated
32 * @len: - Size of data to be encapsulated
33 *
34 * Returns zero on success,and negative on error.
35 */
36__weak int blob_encap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
37{
38 return 0;
39}
40
41/**
42 * do_blob() - Handle the "blob" command-line command
43 * @cmdtp: Command data struct pointer
44 * @flag: Command flag
45 * @argc: Command-line argument count
46 * @argv: Array of command-line arguments
47 *
48 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
49 * on error.
50 */
51static int do_blob(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
52{
Sumit Gargff9eb052016-07-14 13:27:50 -040053 ulong key_addr, src_addr, dst_addr, len;
Ruchika Gupta4345a572014-10-07 15:46:20 +053054 uint8_t *km_ptr, *src_ptr, *dst_ptr;
55 int enc, ret = 0;
56
57 if (argc != 6)
58 return CMD_RET_USAGE;
59
60 if (!strncmp(argv[1], "enc", 3))
61 enc = 1;
62 else if (!strncmp(argv[1], "dec", 3))
63 enc = 0;
64 else
65 return CMD_RET_USAGE;
66
67 src_addr = simple_strtoul(argv[2], NULL, 16);
68 dst_addr = simple_strtoul(argv[3], NULL, 16);
69 len = simple_strtoul(argv[4], NULL, 16);
70 key_addr = simple_strtoul(argv[5], NULL, 16);
71
Aneesh Bansalb3e98202015-12-08 13:54:29 +053072 km_ptr = (uint8_t *)(uintptr_t)key_addr;
73 src_ptr = (uint8_t *)(uintptr_t)src_addr;
74 dst_ptr = (uint8_t *)(uintptr_t)dst_addr;
Ruchika Gupta4345a572014-10-07 15:46:20 +053075
76 if (enc)
77 ret = blob_encap(km_ptr, src_ptr, dst_ptr, len);
78 else
79 ret = blob_decap(km_ptr, src_ptr, dst_ptr, len);
80
81 return ret;
82}
83
84/***************************************************/
85static char blob_help_text[] =
86 "enc src dst len km - Encapsulate and create blob of data\n"
87 " $len bytes long at address $src and\n"
88 " store the result at address $dst.\n"
gaurav ranab64308e2015-02-25 09:37:09 +053089 " $km is the address where the key\n"
90 " modifier is stored.\n"
91 " The modifier is required for generation\n"
92 " /use as key for cryptographic operation.\n"
93 " Key modifier should be 16 byte long.\n"
Ruchika Gupta4345a572014-10-07 15:46:20 +053094 "blob dec src dst len km - Decapsulate the blob of data at address\n"
95 " $src and store result of $len byte at\n"
96 " addr $dst.\n"
gaurav ranab64308e2015-02-25 09:37:09 +053097 " $km is the address where the key\n"
98 " modifier is stored.\n"
99 " The modifier is required for generation\n"
100 " /use as key for cryptographic operation.\n"
101 " Key modifier should be 16 byte long.\n";
Ruchika Gupta4345a572014-10-07 15:46:20 +0530102
103U_BOOT_CMD(
104 blob, 6, 1, do_blob,
105 "Blob encapsulation/decryption",
106 blob_help_text
107);