1 // SPDX-License-Identifier: GPL-2.0+
4 * Command for encapsulating/decapsulating blob of memory.
10 #include <asm/byteorder.h>
11 #include <linux/compiler.h>
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
20 * Returns zero on success,and negative on error.
22 __weak int blob_decap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
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
34 * Returns zero on success,and negative on error.
36 __weak int blob_encap(u8 *key_mod, u8 *src, u8 *dst, u32 len)
42 * do_blob() - Handle the "blob" command-line command
43 * @cmdtp: Command data struct pointer
45 * @argc: Command-line argument count
46 * @argv: Array of command-line arguments
48 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
51 static int do_blob(struct cmd_tbl *cmdtp, int flag, int argc,
54 ulong key_addr, src_addr, dst_addr, len;
55 uint8_t *km_ptr, *src_ptr, *dst_ptr;
61 if (!strncmp(argv[1], "enc", 3))
63 else if (!strncmp(argv[1], "dec", 3))
68 src_addr = simple_strtoul(argv[2], NULL, 16);
69 dst_addr = simple_strtoul(argv[3], NULL, 16);
70 len = simple_strtoul(argv[4], NULL, 16);
71 key_addr = simple_strtoul(argv[5], NULL, 16);
73 km_ptr = (uint8_t *)(uintptr_t)key_addr;
74 src_ptr = (uint8_t *)(uintptr_t)src_addr;
75 dst_ptr = (uint8_t *)(uintptr_t)dst_addr;
78 ret = blob_encap(km_ptr, src_ptr, dst_ptr, len);
80 ret = blob_decap(km_ptr, src_ptr, dst_ptr, len);
85 /***************************************************/
86 static char blob_help_text[] =
87 "enc src dst len km - Encapsulate and create blob of data\n"
88 " $len bytes long at address $src and\n"
89 " store the result at address $dst.\n"
90 " $km is the address where the key\n"
91 " modifier is stored.\n"
92 " The modifier is required for generation\n"
93 " /use as key for cryptographic operation.\n"
94 " Key modifier should be 16 byte long.\n"
95 "blob dec src dst len km - Decapsulate the blob of data at address\n"
96 " $src and store result of $len byte at\n"
98 " $km is the address where the key\n"
99 " modifier is stored.\n"
100 " The modifier is required for generation\n"
101 " /use as key for cryptographic operation.\n"
102 " Key modifier should be 16 byte long.\n";
106 "Blob encapsulation/decryption",