Skip to contentSkip to conversation

arm: zynqmp: Add zynqmp specific command for security features

PATCH New Michal Simek 2 participants 6 messages Oct 20, 2020 – Oct 27, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover arm: zynqmp: Add zynqmp specific command for security features

Hi,

the series is adding support for security features on zynqmp devices.

Thanks,
Michal

Changes in v2:
- Fix cmd_tbl parameters
- Add - in help
- fix cmd_tbl
- Add - in help
- fix cmd_tbl
- Add - to help
- Include to "arm: zynqmp: Add zynqmp specific command for security features" series
- Rebase with new - in help

Michal Simek (1):
arm64: zynqmp: Add support for saving sha3 key to different address

Siva Durga Prasad Paladugu (1):
arm64: zynqmp: Add support for encryption and decryption on data blob

T Karthik Reddy (2):
arm64: zynqmp: Add support for RSA command
arm64: zynqmp: Add support for SHA3 command

 arch/arm/mach-zynqmp/include/mach/sys_proto.h |  10 +
 board/xilinx/zynqmp/cmds.c                    | 228 +++++++++++++++++-
 2 files changed, 237 insertions(+), 1 deletion(-)
Signature · 1 line
2.28.0
#1 lore raw

PATCH v2 1/4 arm64: zynqmp: Add support for encryption and decryption on data blob

From: Siva Durga Prasad Paladugu <[email protected]>

This patch adds support for encryption and decryption on a given data blob using different key sources such as userkey(KUP), device key and PUF key. Inorder to support this a new zynqmp command(zynqmp aes) has been introduced.

Command:
zynqmp aes srcaddr ivaddr len aesop keysrc dstaddr [keyaddr]\n"
Encrypts or decrypts blob of data at src address and puts it\n" back to dstaddr using key and iv at keyaddr and ivaddr\n" respectively. keysrc values specifies from which source key\n" has to be used, it can be User/Device/PUF key. A value of 0\n" for KUP(user key),1 for DeviceKey and 2 for PUF key. The\n" aesop value would specify the operationwhich can be 0 for\n" decrypt and 1 for encrypt(1) operation\n";

---

Changes in v2:
- Fix cmd_tbl parameters
- Add - in help

 arch/arm/mach-zynqmp/include/mach/sys_proto.h |  1 +
 board/xilinx/zynqmp/cmds.c                    | 82 ++++++++++++++++++-
 2 files changed, 82 insertions(+), 1 deletion(-)
arch/arm/mach-zynqmp/include/mach/sys_proto.h +1 -0
index f2b3ceab1358..df944bde09eb 100644
@@ -9,6 +9,7 @@
 
 #define ZYNQMP_CSU_SILICON_VER_MASK	0xF
 #define KEY_PTR_LEN	32
+#define IV_SIZE		12
 
 #define ZYNQMP_FPGA_BIT_AUTH_DDR	1
 #define ZYNQMP_FPGA_BIT_AUTH_OCM	2
board/xilinx/zynqmp/cmds.c +81 -1

117 lines not on this page · raw message

Signature · 1 line
2.28.0
#2 lore raw

PATCH v2 2/4 arm64: zynqmp: Add support for RSA command

In reply to Michal Simek

From: T Karthik Reddy <[email protected]>

This patch adds support for RSA command, performs RSA encrypt & RSA decrypt on data blob of key size.

---

Changes in v2:
- fix cmd_tbl
- Add - in help

 arch/arm/mach-zynqmp/include/mach/sys_proto.h |  4 ++
 board/xilinx/zynqmp/cmds.c                    | 72 +++++++++++++++++++
 2 files changed, 76 insertions(+)
arch/arm/mach-zynqmp/include/mach/sys_proto.h +4 -0
index df944bde09eb..d52eccc7e6e8 100644
@@ -10,6 +10,10 @@
 #define ZYNQMP_CSU_SILICON_VER_MASK	0xF
 #define KEY_PTR_LEN	32
 #define IV_SIZE		12
+#define RSA_KEY_SIZE	512
+#define MODULUS_LEN	512
+#define PRIV_EXPO_LEN	512
+#define PUB_EXPO_LEN	4
 
 #define ZYNQMP_FPGA_BIT_AUTH_DDR	1
 #define ZYNQMP_FPGA_BIT_AUTH_OCM	2
board/xilinx/zynqmp/cmds.c +72 -0

90 lines not on this page · raw message

Signature · 1 line
2.28.0
#3 lore raw

PATCH v2 3/4 arm64: zynqmp: Add support for SHA3 command

In reply to Michal Simek

From: T Karthik Reddy <[email protected]>

This patch adds support for SHA3 command. It takes data blob as input and generates 48 bytes sha3 hash value.

---

Changes in v2:
- fix cmd_tbl
- Add - to help

 arch/arm/mach-zynqmp/include/mach/sys_proto.h |  5 ++
 board/xilinx/zynqmp/cmds.c                    | 63 +++++++++++++++++++
 2 files changed, 68 insertions(+)
arch/arm/mach-zynqmp/include/mach/sys_proto.h +5 -0
index d52eccc7e6e8..1c12eac715e5 100644
@@ -15,6 +15,11 @@
 #define PRIV_EXPO_LEN	512
 #define PUB_EXPO_LEN	4
 
+#define ZYNQMP_SHA3_INIT	1
+#define ZYNQMP_SHA3_UPDATE	2
+#define ZYNQMP_SHA3_FINAL	4
+#define ZYNQMP_SHA3_SIZE	48
+
 #define ZYNQMP_FPGA_BIT_AUTH_DDR	1
 #define ZYNQMP_FPGA_BIT_AUTH_OCM	2
 #define ZYNQMP_FPGA_BIT_ENC_USR_KEY	3
board/xilinx/zynqmp/cmds.c +63 -0

81 lines not on this page · raw message

Signature · 1 line
2.28.0
#4 lore raw

PATCH v2 4/4 arm64: zynqmp: Add support for saving sha3 key to different address

In reply to Michal Simek

By default 48B sha3 hash value is written to srcaddr which is not the best solution in case of that you want to use data for other operations. That's why add key_addr optional parameters which enables to write 48B sha3 hash value to specified address.

---

Changes in v2:
- Include to "arm: zynqmp: Add zynqmp specific command for security features" series
- Rebase with new - in help

 board/xilinx/zynqmp/cmds.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
board/xilinx/zynqmp/cmds.c +18 -7
index b1dc98d076d0..cf63ad97fab7 100644
@@ -285,11 +285,11 @@ static int do_zynqmp_rsa(struct cmd_tbl *cmdtp, int flag, int argc,
 static int do_zynqmp_sha3(struct cmd_tbl *cmdtp, int flag,
 			  int argc, char * const argv[])
 {
-	u64 srcaddr;
+	u64 srcaddr, hashaddr;
 	u32 srclen, ret_payload[PAYLOAD_ARG_CNT];
 	int ret;
 
-	if (argc != cmdtp->maxargs)
+	if (argc > cmdtp->maxargs || argc < (cmdtp->maxargs - 1))
 		return CMD_RET_USAGE;
 
 	if (zynqmp_firmware_version() <= PMUFW_V1_0) {
@@ -302,6 +302,15 @@ static int do_zynqmp_sha3(struct cmd_tbl *cmdtp, int flag,
 	srcaddr = simple_strtoul(argv[2], NULL, 16);
 	srclen = simple_strtoul(argv[3], NULL, 16);
 
+	if (argc == 5) {
+		hashaddr = simple_strtoul(argv[4], NULL, 16);
+		flush_dcache_range(hashaddr,
+				   hashaddr + roundup(ZYNQMP_SHA3_SIZE,
+						      ARCH_DMA_MINALIGN));
+	} else {
+		hashaddr = srcaddr;
+	}
+
 	/* Check srcaddr or srclen != 0 */
 	if (!srcaddr || !srclen) {
 		puts("ERR: srcaddr & srclen should not be 0\n");
@@ -328,9 +337,10 @@ static int do_zynqmp_sha3(struct cmd_tbl *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
-	ret = xilinx_pm_request(PM_SECURE_SHA, upper_32_bits((ulong)srcaddr),
-				lower_32_bits((ulong)srcaddr), ZYNQMP_SHA3_SIZE,
-				ZYNQMP_SHA3_FINAL, ret_payload);
+	ret = xilinx_pm_request(PM_SECURE_SHA, upper_32_bits((ulong)hashaddr),
+				lower_32_bits((ulong)hashaddr),
+				ZYNQMP_SHA3_SIZE, ZYNQMP_SHA3_FINAL,
+				ret_payload);
 	if (ret || ret_payload[1]) {
 		printf("Failed: SHA FINAL status:0x%x, errcode:0x%x\n",
 		       ret, ret_payload[1]);
@@ -347,7 +357,7 @@ static struct cmd_tbl cmd_zynqmp_sub[] = {
 	U_BOOT_CMD_MKENT(mmio_write, 5, 0, do_zynqmp_mmio_write, "", ""),
 	U_BOOT_CMD_MKENT(aes, 9, 0, do_zynqmp_aes, "", ""),
 	U_BOOT_CMD_MKENT(rsa, 7, 0, do_zynqmp_rsa, "", ""),
-	U_BOOT_CMD_MKENT(sha3, 4, 0, do_zynqmp_sha3, "", ""),
+	U_BOOT_CMD_MKENT(sha3, 5, 0, do_zynqmp_sha3, "", ""),
 #ifdef CONFIG_DEFINE_TCM_OCM_MMAP
 	U_BOOT_CMD_MKENT(tcminit, 3, 0, do_zynqmp_tcm_init, "", ""),
 #endif
@@ -415,9 +425,10 @@ static char zynqmp_help_text[] =
 	"	exp :	private key exponent for RSA decryption(4096 bits)\n"
 	"		public key exponent for RSA encryption(32 bits)\n"
 	"	rsaop :	0 for RSA Decryption, 1 for RSA Encryption\n"
-	"zynqmp sha3 srcaddr srclen -\n"
+	"zynqmp sha3 srcaddr srclen [key_addr] -\n"
 	"	Generates sha3 hash value for data blob@srcaddr and puts\n"
 	"	48 bytes hash value into srcaddr\n"
+	"	Optional key_addr can be specified for saving sha3 hash value\n"
 	"	Note: srcaddr/srclen should not be 0\n"
 	;
 #endif
Signature · 1 line
2.28.0
Applied
#5 lore raw

v2 cover arm: zynqmp: Add zynqmp specific command for security features

In reply to Michal Simek

?t 20. 10. 2020 v 8:33 odes?latel Michal Simek <[email protected]> napsal:

Quoted 29 lines

Hi,

the series is adding support for security features on zynqmp devices.

Thanks,
Michal

Changes in v2:
- Fix cmd_tbl parameters
- Add - in help
- fix cmd_tbl
- Add - in help
- fix cmd_tbl
- Add - to help
- Include to "arm: zynqmp: Add zynqmp specific command for security features" series
- Rebase with new - in help

Michal Simek (1):
arm64: zynqmp: Add support for saving sha3 key to different address

Siva Durga Prasad Paladugu (1):
arm64: zynqmp: Add support for encryption and decryption on data blob

T Karthik Reddy (2):
arm64: zynqmp: Add support for RSA command
arm64: zynqmp: Add support for SHA3 command

Quoted 7 lines
 arch/arm/mach-zynqmp/include/mach/sys_proto.h |  10 +
 board/xilinx/zynqmp/cmds.c                    | 228 +++++++++++++++++-
 2 files changed, 237 insertions(+), 1 deletion(-)

--
2.28.0

Applied.
M

Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs