3 * Command for encapsulating/decapsulating blob of memory.
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <environment.h>
12 #include <asm/byteorder.h>
13 #include <linux/compiler.h>
16 * blob_decap() - Decapsulate the data as a blob
17 * @key_mod: - Pointer to key modifier/key
18 * @src: - Address of data to be decapsulated
19 * @dst: - Address of data to be decapsulated
20 * @len: - Size of data to be decapsulated
22 * Returns zero on success,and negative on error.
24 __weak int blob_decap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
30 * blob_encap() - Encapsulate the data as a blob
31 * @key_mod: - Pointer to key modifier/key
32 * @src: - Address of data to be encapsulated
33 * @dst: - Address of data to be encapsulated
34 * @len: - Size of data to be encapsulated
36 * Returns zero on success,and negative on error.
38 __weak int blob_encap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
44 * do_blob() - Handle the "blob" command-line command
45 * @cmdtp: Command data struct pointer
47 * @argc: Command-line argument count
48 * @argv: Array of command-line arguments
50 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
53 static int do_blob(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
55 ulong key_addr, src_addr, dst_addr, len;
56 uint8_t *km_ptr, *src_ptr, *dst_ptr;
62 if (!strncmp(argv[1], "enc", 3))
64 else if (!strncmp(argv[1], "dec", 3))
69 src_addr = simple_strtoul(argv[2], NULL, 16);
70 dst_addr = simple_strtoul(argv[3], NULL, 16);
71 len = simple_strtoul(argv[4], NULL, 16);
72 key_addr = simple_strtoul(argv[5], NULL, 16);
74 km_ptr = (uint8_t *)(uintptr_t)key_addr;
75 src_ptr = (uint8_t *)(uintptr_t)src_addr;
76 dst_ptr = (uint8_t *)(uintptr_t)dst_addr;
79 ret = blob_encap(km_ptr, src_ptr, dst_ptr, len);
81 ret = blob_decap(km_ptr, src_ptr, dst_ptr, len);
86 /***************************************************/
87 static char blob_help_text[] =
88 "enc src dst len km - Encapsulate and create blob of data\n"
89 " $len bytes long at address $src and\n"
90 " store the result at address $dst.\n"
91 " $km is the address where the key\n"
92 " modifier is stored.\n"
93 " The modifier is required for generation\n"
94 " /use as key for cryptographic operation.\n"
95 " Key modifier should be 16 byte long.\n"
96 "blob dec src dst len km - Decapsulate the blob of data at address\n"
97 " $src and store result of $len byte at\n"
99 " $km is the address where the key\n"
100 " modifier is stored.\n"
101 " The modifier is required for generation\n"
102 " /use as key for cryptographic operation.\n"
103 " Key modifier should be 16 byte long.\n";
107 "Blob encapsulation/decryption",