Skip to contentSkip to conversation

rsa: Split the rsa-verify to separate the modular exponentiation

PATCH New Ruchika Gupta 2 participants 29 messages Jan 23, 2015 – Jan 28, 2015

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

PATCH v6 1/10 rsa: Split the rsa-verify to separate the modular exponentiation

Public exponentiation which is required in rsa verify functionality is tightly integrated with verification code in rsa_verify.c. The patch splits the file into twp separating the modular exponentiation.

1. rsa-verify.c
- The file parses device tree keys node to fill a keyprop structure. The keyprop structure can then be converted to implementation specific format.
(struct rsa_pub_key for sw implementation)
- The parsed device tree node is then passed to a generic rsa_mod_exp function.

2. rsa-mod-exp.c
Move the software specific functions related to modular exponentiation from rsa-verify.c to this file.

---
Changes in v6:
No changes

Changes in v5:
Reverted change in rsa_mod_exp_sw function to add pointer to output length Addressed other comments by Simon

Changes in v4:
Modified rsa_mod_exp_sw function to add pointer to output length

Changes in v3:
Kconfig moved to separate patch. This patch just splits the file now

Changes in v2:
Addressed few of Simon Glass's comments:
- Kconfig option added for RSA
- Comments added for new keyprop struct

 include/u-boot/rsa-mod-exp.h |  43 ++++++
 lib/rsa/Makefile             |   2 +-
 lib/rsa/rsa-mod-exp.c        | 303 +++++++++++++++++++++++++++++++++++++++
 lib/rsa/rsa-verify.c         | 329 ++++++++-----------------------------------
 tools/Makefile               |   3 +-
 5 files changed, 404 insertions(+), 276 deletions(-)
 create mode 100644 include/u-boot/rsa-mod-exp.h
 create mode 100644 lib/rsa/rsa-mod-exp.c
include/u-boot/rsa-mod-exp.h new file +43 -0
new file mode 100644
index 0000000..59cd9ea
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2014, Ruchika Gupta.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+*/
+
+#ifndef _RSA_MOD_EXP_H
+#define _RSA_MOD_EXP_H
+
+#include <errno.h>
+#include <image.h>
+
+/**
+ * struct key_prop - holder for a public key properties
+ *
+ * The struct has pointers to modulus (Typically called N),
+ * The inverse, R^2, exponent. These can be typecasted and
+ * used as byte arrays or converted to the required format
+ * as per requirement of RSA implementation.
+ */
+struct key_prop {
+	const void *rr;		/* R^2 can be treated as byte array */
+	const void *modulus;	/* modulus as byte array */
+	const void *public_exponent; /* public exponent as byte array */
+	uint32_t n0inv;		/* -1 / modulus[0] mod 2^32 */
+	int num_bits;		/* Key length in bits */
+	uint32_t exp_len;	/* Exponent length in number of uint8_t */
+};
+
+/**
+ * rsa_mod_exp_sw() - Perform RSA Modular Exponentiation in sw
+ *
+ * Operation: out[] = sig ^ exponent % modulus
+ *
+ * @sig:	RSA PKCS1.5 signature
+ * @sig_len:	Length of signature in number of bytes
+ * @node:	Node with RSA key elements like modulus, exponent, R^2, n0inv
+ * @out:	Result in form of byte array
+ */
+int rsa_mod_exp_sw(const uint8_t *sig, uint32_t sig_len,
+		struct key_prop *node, uint8_t *out);
+
+#endif
lib/rsa/Makefile +1 -1
index a5a96cb6..cc25b3c 100644
@@ -7,4 +7,4 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
-obj-$(CONFIG_FIT_SIGNATURE) += rsa-verify.o rsa-checksum.o
+obj-$(CONFIG_FIT_SIGNATURE) += rsa-verify.o rsa-checksum.o rsa-mod-exp.o
lib/rsa/rsa-mod-exp.c new file +303 -0

303 lines not on this page · raw message

lib/rsa/rsa-verify.c +55 -274

380 lines not on this page · raw message

tools/Makefile +2 -1
index e549f8e..46b90b2 100644
@@ -60,7 +60,8 @@ FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := common/image-sig.o
 LIBFDT_OBJS := $(addprefix lib/libfdt/, \
 			fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_wip.o)
 RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \
-					rsa-sign.o rsa-verify.o rsa-checksum.o)
+					rsa-sign.o rsa-verify.o rsa-checksum.o \
+					rsa-mod-exp.o)
 
 # common objs for dumpimage and mkimage
 dumpimage-mkimage-objs := aisimage.o \
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v6 2/10 FIT: Modify option FIT_SIGNATURE in Kconfig

For FIT signature based approach to work, RSA library needs to be selected. The FIT_SIGNATURE option in Kconfig is modified to automatically select RSA. Selecting RSA compiles the RSA library required for image verification.

---
Changes in v6:
No Changes

Changes in v5:
Word wrapping in commit
Added space after .

Changes in v4:
Expanded CONFIG_RSA with documentation link

Changes in v3:
New patch created for adding Kconfig option for FIT signature

 Kconfig     | 3 ++-
 lib/Kconfig | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
Kconfig +2 -1
index 4157da3..fed488f 100644
@@ -116,8 +116,9 @@ config FIT_VERBOSE
 	depends on FIT
 
 config FIT_SIGNATURE
-	bool "Enabel signature verification of FIT uImages"
+	bool "Enable signature verification of FIT uImages"
 	depends on FIT
+	select RSA
 	help
 	  This option enables signature verification of FIT uImages,
 	  using a hash signed and verified using RSA.
lib/Kconfig +7 -0
index 8460439..79b91b7 100644
@@ -27,4 +27,11 @@ config SYS_HZ
 	  get_timer() must operate in milliseconds and this option must be
 	  set to 1000.
 
+config RSA
+	bool "Use RSA Library"
+	help
+	  RSA support. This enables the RSA algorithm used for FIT image
+	  verification in U-Boot.
+	  See doc/uImage.FIT/signature.txt for more details.
+
 endmenu
Signature · 1 line
1.8.1.4
#3 lore raw

PATCH v6 3/10 DM: crypto/rsa_mod_exp: Add rsa Modular Exponentiation DM driver

In reply to Ruchika Gupta

Add a new rsa uclass for performing modular exponentiation and implement the software driver basing on this uclass.

---
Changes in v6:
No Changes

Changes in v5:
Changed UCLASS name to UCLASS_MOD_EXP

Changes in v4:
Removed Kconfig option for DM_RSA
Corrected driver name for sw rsa driver Updated the rsa_mod_exp operation to have output length

Changes in v3:
New patch with driver model for RSA UCLASS

 drivers/crypto/Makefile                     |  1 +
 drivers/crypto/rsa_mod_exp/Kconfig          |  5 ++++
 drivers/crypto/rsa_mod_exp/Makefile         |  7 ++++++
 drivers/crypto/rsa_mod_exp/mod_exp_sw.c     | 39 +++++++++++++++++++++++++++++
 drivers/crypto/rsa_mod_exp/mod_exp_uclass.c | 31 +++++++++++++++++++++++
 include/dm/uclass-id.h                      |  1 +
 include/u-boot/rsa-mod-exp.h                | 34 ++++++++++++++++++++++++-
 7 files changed, 117 insertions(+), 1 deletion(-)
 create mode 100644 drivers/crypto/rsa_mod_exp/Kconfig
 create mode 100644 drivers/crypto/rsa_mod_exp/Makefile
 create mode 100644 drivers/crypto/rsa_mod_exp/mod_exp_sw.c
 create mode 100644 drivers/crypto/rsa_mod_exp/mod_exp_uclass.c
drivers/crypto/Makefile +1 -0
index 7b79237..fb8c10b 100644
@@ -6,4 +6,5 @@
 #
 
 obj-$(CONFIG_EXYNOS_ACE_SHA)	+= ace_sha.o
+obj-y += rsa_mod_exp/
 obj-y += fsl/
drivers/crypto/rsa_mod_exp/Kconfig new file +5 -0
new file mode 100644
index 0000000..6dcb39a
@@ -0,0 +1,5 @@
+config DM_MOD_EXP
+	bool "Enable Driver Model for RSA Modular Exponentiation"
+	depends on DM
+	help
+	  If you want to use driver model for RSA Modular Exponentiation, say Y.
drivers/crypto/rsa_mod_exp/Makefile new file +7 -0
new file mode 100644
index 0000000..915b751
@@ -0,0 +1,7 @@
+#
+# (C) Copyright 2014 Freescale Semiconductor, Inc.
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_RSA) += mod_exp_uclass.o mod_exp_sw.o
drivers/crypto/rsa_mod_exp/mod_exp_sw.c new file +39 -0
new file mode 100644
index 0000000..dc6c064
@@ -0,0 +1,39 @@
+/*
+ * (C) Copyright 2014 Freescale Semiconductor, Inc.
+ * Author: Ruchika Gupta <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <config.h>
+#include <common.h>
+#include <dm.h>
+#include <u-boot/rsa-mod-exp.h>
+
+int mod_exp_sw(struct udevice *dev, const uint8_t *sig, uint32_t sig_len,
+		struct key_prop *prop, uint8_t *out)
+{
+	int ret = 0;
+
+	ret = rsa_mod_exp_sw(sig, sig_len, prop, out);
+	if (ret) {
+		debug("%s: RSA failed to verify: %d\n", __func__, ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct mod_exp_ops mod_exp_ops_sw = {
+	.mod_exp	= mod_exp_sw,
+};
+
+U_BOOT_DRIVER(mod_exp_sw) = {
+	.name	= "mod_exp_sw",
+	.id	= UCLASS_MOD_EXP,
+	.ops	= &mod_exp_ops_sw,
+};
+
+U_BOOT_DEVICE(mod_exp_sw) = {
+	.name = "mod_exp_sw",
+};
drivers/crypto/rsa_mod_exp/mod_exp_uclass.c new file +31 -0
new file mode 100644
index 0000000..266f094
@@ -0,0 +1,31 @@
+/*
+ * (C) Copyright 2014 Freescale Semiconductor, Inc
+ * Author: Ruchika Gupta <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <u-boot/rsa-mod-exp.h>
+#include <errno.h>
+#include <fdtdec.h>
+#include <malloc.h>
+#include <asm/io.h>
+#include <linux/list.h>
+
+int rsa_mod_exp(struct udevice *dev, const uint8_t *sig, uint32_t sig_len,
+		struct key_prop *node, uint8_t *out)
+{
+	const struct mod_exp_ops *ops = device_get_ops(dev);
+
+	if (!ops->mod_exp)
+		return -ENOSYS;
+
+	return ops->mod_exp(dev, sig, sig_len, node, out);
+}
+
+UCLASS_DRIVER(mod_exp) = {
+	.id		= UCLASS_MOD_EXP,
+	.name		= "rsa_mod_exp",
+};
include/dm/uclass-id.h +1 -0
index f17c3c2..91bb90d 100644
@@ -33,6 +33,7 @@ enum uclass_id {
 	UCLASS_I2C,		/* I2C bus */
 	UCLASS_I2C_GENERIC,	/* Generic I2C device */
 	UCLASS_I2C_EEPROM,	/* I2C EEPROM device */
+	UCLASS_MOD_EXP,		/* RSA Mod Exp device */
 
 	UCLASS_COUNT,
 	UCLASS_INVALID = -1,
include/u-boot/rsa-mod-exp.h +33 -1
index 59cd9ea..fce445a 100644
@@ -35,9 +35,41 @@ struct key_prop {
  * @sig:	RSA PKCS1.5 signature
  * @sig_len:	Length of signature in number of bytes
  * @node:	Node with RSA key elements like modulus, exponent, R^2, n0inv
- * @out:	Result in form of byte array
+ * @out:	Result in form of byte array of len equal to sig_len
  */
 int rsa_mod_exp_sw(const uint8_t *sig, uint32_t sig_len,
 		struct key_prop *node, uint8_t *out);
 
+int rsa_mod_exp(struct udevice *dev, const uint8_t *sig, uint32_t sig_len,
+		struct key_prop *node, uint8_t *out);
+
+/**
+ * struct struct mod_exp_ops - Driver model for RSA Modular Exponentiation
+ *				operations
+ *
+ * The uclass interface is implemented by all crypto devices which use
+ * driver model.
+ */
+struct mod_exp_ops {
+	/**
+	 * Perform Modular Exponentiation
+	 *
+	 * Operation: out[] = sig ^ exponent % modulus
+	 *
+	 * @dev:	RSA Device
+	 * @sig:	RSA PKCS1.5 signature
+	 * @sig_len:	Length of signature in number of bytes
+	 * @node:	Node with RSA key elements like modulus, exponent,
+	 *		R^2, n0inv
+	 * @out:	Result in form of byte array of len equal to sig_len
+	 *
+	 * This function computes exponentiation over the signature.
+	 * Returns: 0 if exponentiation is successful, or a negative value
+	 * if it wasn't.
+	 */
+	int (*mod_exp)(struct udevice *dev, const uint8_t *sig,
+			   uint32_t sig_len, struct key_prop *node,
+			   uint8_t *outp);
+};
+
 #endif
Signature · 1 line
1.8.1.4
#7 lore raw

PATCH v6 4/10 configs: Move CONFIG_FIT_SIGNATURE to defconfig

In reply to Ruchika Gupta

For the platforms which use,CONFIG_FIT_SIGNATURE, the required configs are moved to the platform's defconfig file. Selecting CONFIG_FIT_SIGNATURE using defconfig automatically resolves the dependencies for signature verification. The RSA library gets automatically selected and user does not have to define CONFIG_RSA manually.

---
Changes in v6:
No Changes

Changes in v5:
No changes

Changes in v4:
No changes

Changes in v3:
New patch

 configs/ids8313_defconfig          | 2 ++
 configs/sandbox_defconfig          | 3 +++
 configs/zynq_microzed_defconfig    | 3 +++
 configs/zynq_zc70x_defconfig       | 3 +++
 configs/zynq_zc770_xm010_defconfig | 3 +++
 configs/zynq_zc770_xm012_defconfig | 3 +++
 configs/zynq_zc770_xm013_defconfig | 3 +++
 configs/zynq_zed_defconfig         | 3 +++
 configs/zynq_zybo_defconfig        | 3 +++
 include/configs/am335x_evm.h       | 4 ++--
 include/configs/ids8313.h          | 3 ---
 include/configs/sandbox.h          | 3 ---
 include/configs/zynq-common.h      | 6 ------
 13 files changed, 28 insertions(+), 14 deletions(-)
configs/ids8313_defconfig +2 -0
index 1c665aa..8479cd4 100644
@@ -1,4 +1,6 @@
 CONFIG_SYS_EXTRA_OPTIONS="SYS_TEXT_BASE=0xFFF00000"
 CONFIG_PPC=y
 CONFIG_MPC83xx=y
+CONFIG_FIT=y
+CONFIG_FIT_SIGNATURE=y
 CONFIG_TARGET_IDS8313=y
configs/sandbox_defconfig +3 -0
index 47d8400..0111f25 100644
@@ -1,3 +1,6 @@
 CONFIG_OF_CONTROL=y
 CONFIG_OF_HOSTFILE=y
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_FIT_SIGNATURE=y
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
configs/zynq_microzed_defconfig +3 -0
index 9588849..b9a6fe5 100644
@@ -3,4 +3,7 @@ CONFIG_SPL=y
 +S:CONFIG_ZYNQ=y
 +S:CONFIG_TARGET_ZYNQ_MICROZED=y
 CONFIG_OF_CONTROL=y
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_FIT_SIGNATURE=y
 CONFIG_DEFAULT_DEVICE_TREE="zynq-microzed"
configs/zynq_zc70x_defconfig +3 -0
index cf50730..dc8aa84 100644
@@ -4,3 +4,6 @@ CONFIG_SPL=y
 +S:CONFIG_TARGET_ZYNQ_ZC70X=y
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="zynq-zc702"
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_FIT_SIGNATURE=y
configs/zynq_zc770_xm010_defconfig +3 -0
index 8bb405d..2f5fa8c 100644
@@ -5,3 +5,6 @@ CONFIG_SYS_EXTRA_OPTIONS="ZC770_XM010"
 +S:CONFIG_TARGET_ZYNQ_ZC770=y
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="zynq-zc770-xm010"
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_FIT_SIGNATURE=y
configs/zynq_zc770_xm012_defconfig +3 -0
index 0ba5da5..a92d495 100644
@@ -5,3 +5,6 @@ CONFIG_SYS_EXTRA_OPTIONS="ZC770_XM012"
 +S:CONFIG_TARGET_ZYNQ_ZC770=y
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="zynq-zc770-xm012"
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_FIT_SIGNATURE=y
configs/zynq_zc770_xm013_defconfig +3 -0
index 13f8112..3a02f75 100644
@@ -5,3 +5,6 @@ CONFIG_SYS_EXTRA_OPTIONS="ZC770_XM013"
 +S:CONFIG_TARGET_ZYNQ_ZC770=y
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="zynq-zc770-xm013"
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_FIT_SIGNATURE=y
configs/zynq_zed_defconfig +3 -0
index eb057fa..1d816f6 100644
@@ -4,3 +4,6 @@ CONFIG_SPL=y
 +S:CONFIG_TARGET_ZYNQ_ZED=y
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="zynq-zed"
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_FIT_SIGNATURE=y
configs/zynq_zybo_defconfig +3 -0
index 12311cd..9183629 100644
@@ -4,3 +4,6 @@ CONFIG_SPL=y
 +S:CONFIG_TARGET_ZYNQ_ZYBO=y
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="zynq-zybo"
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_FIT_SIGNATURE=y
include/configs/am335x_evm.h +2 -2
index 0004750..f9bc23b 100644
@@ -23,8 +23,8 @@
 # define CONFIG_TIMESTAMP
 # define CONFIG_LZO
 # ifdef CONFIG_ENABLE_VBOOT
-#  define CONFIG_FIT_SIGNATURE
-#  define CONFIG_RSA
+# define CONFIG_FIT_SIGNATURE
+# define CONFIG_RSA
 # endif
 #endif
 
include/configs/ids8313.h +0 -3
index f084834..2384864 100644
@@ -575,12 +575,9 @@
 
 #define CONFIG_VERSION_VARIABLE
 
-#define CONFIG_FIT
-#define CONFIG_FIT_SIGNATURE
 #define CONFIG_IMAGE_FORMAT_LEGACY
 #define CONFIG_CMD_FDT
 #define CONFIG_CMD_HASH
-#define CONFIG_RSA
 #define CONFIG_SHA1
 #define CONFIG_SHA256
 
include/configs/sandbox.h +0 -3
index 657f751..6fd29b9 100644
@@ -41,9 +41,6 @@
 
 #define CONFIG_OF_LIBFDT
 #define CONFIG_LMB
-#define CONFIG_FIT
-#define CONFIG_FIT_SIGNATURE
-#define CONFIG_RSA
 #define CONFIG_CMD_FDT
 #define CONFIG_ANDROID_BOOT_IMAGE
 
include/configs/zynq-common.h +0 -6
index 87b4fff..3894517 100644
@@ -219,17 +219,11 @@
 #define CONFIG_OF_LIBFDT
 
 /* FIT support */
-#define CONFIG_FIT
-#define CONFIG_FIT_VERBOSE	1 /* enable fit_format_{error,warning}() */
 #define CONFIG_IMAGE_FORMAT_LEGACY /* enable also legacy image format */
 
 /* FDT support */
 #define CONFIG_DISPLAY_BOARDINFO_LATE
 
-/* RSA support */
-#define CONFIG_FIT_SIGNATURE
-#define CONFIG_RSA
-
 /* Extend size of kernel image for uncompression */
 #define CONFIG_SYS_BOOTM_LEN	(60 * 1024 * 1024)
 
Signature · 1 line
1.8.1.4
#9 lore raw

PATCH v6 5/10 lib/rsa: Modify rsa to use DM driver

In reply to Ruchika Gupta

Modify rsa_verify to use the rsa driver of DM library .The tools will continue to use the same RSA sw library.

CONFIG_RSA is now dependent on CONFIG_DM. All configurations which enable FIT based signatures have been modified to enable CONFIG_DM by default.

---
Changes in v6:
No Changes

Changes in v5:
Added signature option in am335x_boneblack_vboot_defconfig Made changes in rsa-verify.c as suggested by Simon

Changes in v4:
Make CONFIG_RSA always depenedent on Driver Model.
Add CONFIG_DM in defconfigs of the platforms which enable CONFIG_FIT_SIGNATURE

Changes in v3:
New patch

 README                                   |  7 ++++++-
 configs/am335x_boneblack_vboot_defconfig |  4 ++++
 configs/ids8313_defconfig                |  1 +
 configs/sandbox_defconfig                |  1 +
 configs/zynq_microzed_defconfig          |  1 +
 configs/zynq_zc70x_defconfig             |  1 +
 configs/zynq_zc770_xm010_defconfig       |  1 +
 configs/zynq_zc770_xm012_defconfig       |  1 +
 configs/zynq_zc770_xm013_defconfig       |  1 +
 configs/zynq_zed_defconfig               |  1 +
 configs/zynq_zybo_defconfig              |  1 +
 include/configs/am335x_evm.h             |  6 ++----
 include/configs/sandbox.h                |  1 -
 lib/rsa/rsa-verify.c                     | 14 ++++++++++++++
 14 files changed, 35 insertions(+), 6 deletions(-)
README +6 -1
index fefa71c..cac7978 100644
@@ -3176,8 +3176,13 @@ CBFS (Coreboot Filesystem) support
 		This enables the RSA algorithm used for FIT image verification
 		in U-Boot. See doc/uImage.FIT/signature.txt for more information.
 
+		The Modular Exponentiation algorithm in RSA is implemented using
+		driver model. So CONFIG_DM needs to be enabled by default for this
+		library to function.
+
 		The signing part is build into mkimage regardless of this
-		option.
+		option. The software based modular exponentiation is built into
+		mkimage irrespective of this option.
 
 - bootcount support:
 		CONFIG_BOOTCOUNT_LIMIT
configs/am335x_boneblack_vboot_defconfig +4 -0
index 5837a0a..51bf370 100644
@@ -4,3 +4,7 @@ CONFIG_SYS_EXTRA_OPTIONS="EMMC_BOOT,ENABLE_VBOOT"
 +S:CONFIG_TARGET_AM335X_EVM=y
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="am335x-boneblack"
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_FIT_SIGNATURE=y
+CONFIG_DM=y
configs/ids8313_defconfig +1 -0
index 8479cd4..0950ec8 100644
@@ -4,3 +4,4 @@ CONFIG_MPC83xx=y
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_TARGET_IDS8313=y
+CONFIG_DM=y
configs/sandbox_defconfig +1 -0
index 0111f25..660063e 100644
@@ -3,4 +3,5 @@ CONFIG_OF_HOSTFILE=y
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_FIT_SIGNATURE=y
+CONFIG_DM=y
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
configs/zynq_microzed_defconfig +1 -0
index b9a6fe5..8b985fe 100644
@@ -6,4 +6,5 @@ CONFIG_OF_CONTROL=y
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_FIT_SIGNATURE=y
+CONFIG_DM=y
 CONFIG_DEFAULT_DEVICE_TREE="zynq-microzed"
configs/zynq_zc70x_defconfig +1 -0
index dc8aa84..cceb321 100644
@@ -7,3 +7,4 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-zc702"
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_FIT_SIGNATURE=y
+CONFIG_DM=y
configs/zynq_zc770_xm010_defconfig +1 -0
index 2f5fa8c..2935c0d 100644
@@ -8,3 +8,4 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-zc770-xm010"
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_FIT_SIGNATURE=y
+CONFIG_DM=y
configs/zynq_zc770_xm012_defconfig +1 -0
index a92d495..0401739 100644
@@ -8,3 +8,4 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-zc770-xm012"
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_FIT_SIGNATURE=y
+CONFIG_DM=y
configs/zynq_zc770_xm013_defconfig +1 -0
index 3a02f75..a95970a 100644
@@ -8,3 +8,4 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-zc770-xm013"
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_FIT_SIGNATURE=y
+CONFIG_DM=y
configs/zynq_zed_defconfig +1 -0
index 1d816f6..0fbc41a 100644
@@ -7,3 +7,4 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-zed"
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_FIT_SIGNATURE=y
+CONFIG_DM=y
configs/zynq_zybo_defconfig +1 -0
index 9183629..4e66760 100644
@@ -7,3 +7,4 @@ CONFIG_DEFAULT_DEVICE_TREE="zynq-zybo"
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_FIT_SIGNATURE=y
+CONFIG_DM=y
include/configs/am335x_evm.h +2 -4
index f9bc23b..76ce7de 100644
@@ -19,13 +19,11 @@
 #include <configs/ti_am335x_common.h>
 
 #ifndef CONFIG_SPL_BUILD
+#ifndef CONFIG_FIT
 # define CONFIG_FIT
+#endif
 # define CONFIG_TIMESTAMP
 # define CONFIG_LZO
-# ifdef CONFIG_ENABLE_VBOOT
-# define CONFIG_FIT_SIGNATURE
-# define CONFIG_RSA
-# endif
 #endif
 
 #define CONFIG_SYS_BOOTM_LEN		(16 << 20)
include/configs/sandbox.h +0 -1
index 6fd29b9..e9d3f32 100644
@@ -23,7 +23,6 @@
 
 #define CONFIG_BOOTSTAGE
 #define CONFIG_BOOTSTAGE_REPORT
-#define CONFIG_DM
 #define CONFIG_CMD_DEMO
 #define CONFIG_CMD_DM
 #define CONFIG_DM_DEMO
lib/rsa/rsa-verify.c +14 -0
index f8bc086..da45daf 100644
@@ -12,6 +12,7 @@
 #include <asm/errno.h>
 #include <asm/types.h>
 #include <asm/unaligned.h>
+#include <dm.h>
 #else
 #include "fdt_host.h"
 #include "mkimage.h"
@@ -43,6 +44,9 @@ static int rsa_verify_key(struct key_prop *prop, const uint8_t *sig,
 	const uint8_t *padding;
 	int pad_len;
 	int ret;
+#if !defined(USE_HOSTCC)
+	struct udevice *mod_exp_dev;
+#endif
 
 	if (!prop || !sig || !hash || !algo)
 		return -EIO;
@@ -63,7 +67,17 @@ static int rsa_verify_key(struct key_prop *prop, const uint8_t *sig,
 
 	uint8_t buf[sig_len];
 
+#if !defined(USE_HOSTCC)
+	ret = uclass_get_device(UCLASS_MOD_EXP, 0, &mod_exp_dev);
+	if (ret) {
+		printf("RSA: Can't find Modular Exp implementation\n");
+		return -EINVAL;
+	}
+
+	ret = rsa_mod_exp(mod_exp_dev, sig, sig_len, prop, buf);
+#else
 	ret = rsa_mod_exp_sw(sig, sig_len, prop, buf);
+#endif
 	if (ret) {
 		debug("Error in Modular exponentation\n");
 		return ret;
Signature · 1 line
1.8.1.4
#12 lore raw

PATCH v6 6/10 DM: crypto/fsl - Add Freescale rsa DM driver

In reply to Ruchika Gupta

Driver added for RSA Modular Exponentiation using Freescale Hardware Accelerator CAAM. The driver uses UCLASS_MOD_EXP

---
Changes in v6:
No Changes

Changes in v5:
Reverted mod_exp not to use output length

Changes in v4:
Modified for the changes in op function of rsa class mod_exp

Changes in v3:
Moved to integrate with RSA UCLASS

 drivers/crypto/Kconfig        |  1 +
 drivers/crypto/fsl/Kconfig    |  6 +++++
 drivers/crypto/fsl/Makefile   |  1 +
 drivers/crypto/fsl/fsl_rsa.c  | 60 +++++++++++++++++++++++++++++++++++++++++++
 drivers/crypto/fsl/jobdesc.c  | 28 ++++++++++++++++++++
 drivers/crypto/fsl/jobdesc.h  |  5 ++++
 drivers/crypto/fsl/rsa_caam.h | 28 ++++++++++++++++++++
 7 files changed, 129 insertions(+)
 create mode 100644 drivers/crypto/fsl/Kconfig
 create mode 100644 drivers/crypto/fsl/fsl_rsa.c
 create mode 100644 drivers/crypto/fsl/rsa_caam.h
drivers/crypto/Kconfig +1 -0
index e69de29..bd26a2b 100644
@@ -0,0 +1 @@
+source drivers/crypto/fsl/Kconfig
drivers/crypto/fsl/Kconfig new file +6 -0
new file mode 100644
index 0000000..86b2f2f
@@ -0,0 +1,6 @@
+config FSL_CAAM
+	bool "Freescale Crypto Driver Support"
+	help
+	  Enables the Freescale's Cryptographic Accelerator and Assurance
+	  Module (CAAM), also known as the SEC version 4 (SEC4). The driver uses
+	  Job Ring as interface to communicate with CAAM.
drivers/crypto/fsl/Makefile +1 -0
index cb13d2e..db3c010 100644
@@ -8,3 +8,4 @@
 
 obj-$(CONFIG_FSL_CAAM) += jr.o fsl_hash.o jobdesc.o error.o
 obj-$(CONFIG_CMD_BLOB) += fsl_blob.o
+obj-$(CONFIG_RSA_FREESCALE_EXP) += fsl_rsa.o
drivers/crypto/fsl/fsl_rsa.c new file +60 -0

60 lines not on this page · raw message

drivers/crypto/fsl/jobdesc.c +28 -0
index 1386bae..cc0dced 100644
@@ -11,6 +11,7 @@
 #include <common.h>
 #include "desc_constr.h"
 #include "jobdesc.h"
+#include "rsa_caam.h"
 
 #define KEY_BLOB_SIZE			32
 #define MAC_SIZE			16
@@ -123,3 +124,30 @@ void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc)
 	append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
 			 OP_ALG_RNG4_SK);
 }
+
+/* Change key size to bytes form bits in calling function*/
+void inline_cnstr_jobdesc_pkha_rsaexp(uint32_t *desc,
+				      struct pk_in_params *pkin, uint8_t *out,
+				      uint32_t out_siz)
+{
+	dma_addr_t dma_addr_e, dma_addr_a, dma_addr_n, dma_addr_out;
+
+	dma_addr_e = virt_to_phys((void *)pkin->e);
+	dma_addr_a = virt_to_phys((void *)pkin->a);
+	dma_addr_n = virt_to_phys((void *)pkin->n);
+	dma_addr_out = virt_to_phys((void *)out);
+
+	init_job_desc(desc, 0);
+	append_key(desc, dma_addr_e, pkin->e_siz, KEY_DEST_PKHA_E | CLASS_1);
+
+	append_fifo_load(desc, dma_addr_a,
+			 pkin->a_siz, LDST_CLASS_1_CCB | FIFOLD_TYPE_PK_A);
+
+	append_fifo_load(desc, dma_addr_n,
+			 pkin->n_siz, LDST_CLASS_1_CCB | FIFOLD_TYPE_PK_N);
+
+	append_operation(desc, OP_TYPE_PK | OP_ALG_PK | OP_ALG_PKMODE_MOD_EXPO);
+
+	append_fifo_store(desc, dma_addr_out, out_siz,
+			  LDST_CLASS_1_CCB | FIFOST_TYPE_PKHA_B);
+}
drivers/crypto/fsl/jobdesc.h +5 -0
index 3cf7226..84b3edd 100644
@@ -10,6 +10,7 @@
 
 #include <common.h>
 #include <asm/io.h>
+#include "rsa_caam.h"
 
 #define KEY_IDNFR_SZ_BYTES		16
 
@@ -26,4 +27,8 @@ void inline_cnstr_jobdesc_blob_decap(uint32_t *desc, uint8_t *key_idnfr,
 				     uint32_t out_sz);
 
 void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc);
+
+void inline_cnstr_jobdesc_pkha_rsaexp(uint32_t *desc,
+				      struct pk_in_params *pkin, uint8_t *out,
+				      uint32_t out_siz);
 #endif
drivers/crypto/fsl/rsa_caam.h new file +28 -0
new file mode 100644
index 0000000..4ff87ef
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __RSA_CAAM_H
+#define __RSA_CAAM_H
+
+#include <common.h>
+
+/**
+ * struct pk_in_params - holder for input to PKHA block in CAAM
+ * These parameters are required to perform Modular Exponentiation
+ * using PKHA Block in CAAM
+ */
+struct pk_in_params {
+	const uint8_t *e;	/* public exponent as byte array */
+	uint32_t e_siz;		/* size of e[] in number of bytes */
+	const uint8_t *n;	/* modulus as byte array */
+	uint32_t n_siz;		/* size of n[] in number of bytes */
+	const uint8_t *a;		/* Signature as byte array */
+	uint32_t a_siz;		/* size of a[] in number of bytes */
+	uint8_t *b;		/* Result exp. modulus in number of bytes */
+	uint32_t b_siz;		/* size of b[] in number of bytes */
+};
+
+#endif
Signature · 1 line
1.8.1.4
#15 lore raw

PATCH v6 7/10 lib/rsa: Add Kconfig for devices supporting RSA Modular Exponentiation

In reply to Ruchika Gupta

Kconfig option added for devices which support RSA Verification.
1. RSA_SOFTWARE_EXP
Enables driver for supporting RSA Modular Exponentiation in Software
2. RSA_FREESCALE_EXP
Enables driver for supporting RSA Modular Exponentiation using Freescale specific driver

The above drivers use RSA uclass

---
Changes in v6:
No Changes

Changes in v5:
No changes

Changes in v4:
Introduced 2 options when CONFIG_RSA is selected:
RSA_SOFTWARE_EXP
RSA_FREESCALE_EXP

Removed RSA_HW. Changes the name pf RSA_SW to RSA_SOFTWARE_EXP

Changes in v3:
New patch

 lib/Kconfig     |  7 +------
 lib/rsa/Kconfig | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 6 deletions(-)
 create mode 100644 lib/rsa/Kconfig
lib/Kconfig +1 -6
index 79b91b7..a1f30a2 100644
@@ -27,11 +27,6 @@ config SYS_HZ
 	  get_timer() must operate in milliseconds and this option must be
 	  set to 1000.
 
-config RSA
-	bool "Use RSA Library"
-	help
-	  RSA support. This enables the RSA algorithm used for FIT image
-	  verification in U-Boot.
-	  See doc/uImage.FIT/signature.txt for more details.
+source lib/rsa/Kconfig
 
 endmenu
lib/rsa/Kconfig new file +28 -0
new file mode 100644
index 0000000..4fa79d7
@@ -0,0 +1,28 @@
+config RSA
+	bool "Use RSA Library"
+	select RSA_FREESCALE_EXP if FSL_CAAM
+	select RSA_SOFTWARE_EXP if !RSA_FREESCALE_EXP
+	help
+	  RSA support. This enables the RSA algorithm used for FIT image
+	  verification in U-Boot.
+	  See doc/uImage.FIT/signature.txt for more details.
+	  See doc/uImage.FIT/signature.txt for more details.
+
+if RSA
+config RSA_SOFTWARE_EXP
+	bool "Enable driver for RSA Modular Exponentiation in software"
+	depends on DM && RSA
+	help
+	  Enables driver for modular exponentiation in software. This is a RSA
+	  algorithm used in FIT image verification. It required RSA Key as
+	  input.
+	  See doc/uImage.FIT/signature.txt for more details.
+
+config RSA_FREESCALE_EXP
+	bool "Enable RSA Modular Exponentiation with FSL crypto accelerator"
+	depends on DM && RSA && FSL_CAAM
+	help
+	Enables driver for RSA modular exponentiation using Freescale cryptographic
+	accelerator - CAAM.
+
+endif
Signature · 1 line
1.8.1.4
#18 lore raw

PATCH v6 8/10 hash: Add function to find hash_algo struct with progressive hash

In reply to Ruchika Gupta

The hash_algo structure has some implementations in which progressive hash API's are not defined. These are basically the hardware based implementations of SHA. An API is added to find the algo which has progressive hash API's defined. This can then be integrated with RSA checksum library which uses Progressive Hash API's.

---
Changes in v6:
No Changes

Changes in v5:
None

Changes in v4:
Few cosmetic changes. Currently I have not replaced CONFIG_SHA1 with CONFIG_CMD_SHA1SUM. Waiting for reply from Simon and Denx for the same.

Changes in v3 :
Corrected ifdef for SHA1

Changes in v2 :
Added commit message

 common/hash.c  | 33 ++++++++++++++++++++++++---------
 include/hash.h | 14 ++++++++++++++
 2 files changed, 38 insertions(+), 9 deletions(-)
common/hash.c +24 -9
index aceabc5..c4d8c3a 100644
@@ -20,7 +20,7 @@
 #include <asm/io.h>
 #include <asm/errno.h>
 
-#ifdef CONFIG_CMD_SHA1SUM
+#ifdef CONFIG_SHA1
 static int hash_init_sha1(struct hash_algo *algo, void **ctxp)
 {
 	sha1_context *ctx = malloc(sizeof(sha1_context));
@@ -125,12 +125,7 @@ static struct hash_algo hash_algo[] = {
 		CHUNKSZ_SHA256,
 	},
 #endif
-	/*
-	 * This is CONFIG_CMD_SHA1SUM instead of CONFIG_SHA1 since otherwise
-	 * it bloats the code for boards which use SHA1 but not the 'hash'
-	 * or 'sha1sum' commands.
-	 */
-#ifdef CONFIG_CMD_SHA1SUM
+#ifdef CONFIG_SHA1
 	{
 		"sha1",
 		SHA1_SUM_LEN,
@@ -140,7 +135,6 @@ static struct hash_algo hash_algo[] = {
 		hash_update_sha1,
 		hash_finish_sha1,
 	},
-#define MULTI_HASH
 #endif
 #ifdef CONFIG_SHA256
 	{
@@ -152,7 +146,6 @@ static struct hash_algo hash_algo[] = {
 		hash_update_sha256,
 		hash_finish_sha256,
 	},
-#define MULTI_HASH
 #endif
 	{
 		"crc32",
@@ -165,6 +158,10 @@ static struct hash_algo hash_algo[] = {
 	},
 };
 
+#if defined(CONFIG_SHA256) || defined(CONFIG_CMD_SHA1SUM)
+#define MULTI_HASH
+#endif
+
 #if defined(CONFIG_HASH_VERIFY) || defined(CONFIG_CMD_HASH)
 #define MULTI_HASH
 #endif
@@ -311,6 +308,24 @@ int hash_lookup_algo(const char *algo_name, struct hash_algo **algop)
 	return -EPROTONOSUPPORT;
 }
 
+int hash_progressive_lookup_algo(const char *algo_name,
+				 struct hash_algo **algop)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
+		if (!strcmp(algo_name, hash_algo[i].name)) {
+			if (hash_algo[i].hash_init) {
+				*algop = &hash_algo[i];
+				return 0;
+			}
+		}
+	}
+
+	debug("Unknown hash algorithm '%s'\n", algo_name);
+	return -EPROTONOSUPPORT;
+}
+
 void hash_show(struct hash_algo *algo, ulong addr, ulong len, uint8_t *output)
 {
 	int i;
include/hash.h +14 -0
index d8ec4f0..c0a7ebc 100644
@@ -128,6 +128,20 @@ int hash_block(const char *algo_name, const void *data, unsigned int len,
 int hash_lookup_algo(const char *algo_name, struct hash_algo **algop);
 
 /**
+ * hash_progressive_lookup_algo() - Look up hash_algo for prog. hash support
+ *
+ * The function returns the pointer to the struct or -EPROTONOSUPPORT if the
+ * algorithm is not available with progressive hash support.
+ *
+ * @algo_name: Hash algorithm to look up
+ * @algop: Pointer to the hash_algo struct if found
+ *
+ * @return 0 if ok, -EPROTONOSUPPORT for an unknown algorithm.
+ */
+int hash_progressive_lookup_algo(const char *algo_name,
+				 struct hash_algo **algop);
+
+/**
  * hash_show() - Print out a hash algorithm and value
  *
  * You will get a message like this (without a newline@the end):
Signature · 1 line
1.8.1.4
#21 lore raw

PATCH v6 9/10 Use hash.c in mkimage

In reply to Ruchika Gupta

---
Changes in v6:
Fixed compilation error in this file for tools when FIT_SIGNATURE not enabled

Changes in v5:
New patch based on WIP patch by Simon.

 common/hash.c  | 81 +++++++++++++++++++++++++++++++++-------------------------
 include/hash.h | 34 ++++++++++++------------
 tools/Makefile |  1 +
 3 files changed, 65 insertions(+), 51 deletions(-)
common/hash.c +46 -35
index c4d8c3a..d154d02 100644
@@ -10,15 +10,24 @@
  * SPDX-License-Identifier:	GPL-2.0+
  */
 
+#ifndef USE_HOSTCC
 #include <common.h>
 #include <command.h>
 #include <malloc.h>
 #include <hw_sha.h>
+#include <asm/io.h>
+#include <asm/errno.h>
+#else
+#include "mkimage.h"
+#include <time.h>
+#include <image.h>
+#endif /* !USE_HOSTCC*/
+
 #include <hash.h>
+#include <u-boot/crc.h>
 #include <u-boot/sha1.h>
 #include <u-boot/sha256.h>
-#include <asm/io.h>
-#include <asm/errno.h>
+#include <u-boot/md5.h>
 
 #ifdef CONFIG_SHA1
 static int hash_init_sha1(struct hash_algo *algo, void **ctxp)
@@ -173,6 +182,40 @@ static struct hash_algo hash_algo[] = {
 #define multi_hash()	0
 #endif
 
+int hash_lookup_algo(const char *algo_name, struct hash_algo **algop)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
+		if (!strcmp(algo_name, hash_algo[i].name)) {
+			*algop = &hash_algo[i];
+			return 0;
+		}
+	}
+
+	debug("Unknown hash algorithm '%s'\n", algo_name);
+	return -EPROTONOSUPPORT;
+}
+
+int hash_progressive_lookup_algo(const char *algo_name,
+				 struct hash_algo **algop)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
+		if (!strcmp(algo_name, hash_algo[i].name)) {
+			if (hash_algo[i].hash_init) {
+				*algop = &hash_algo[i];
+				return 0;
+			}
+		}
+	}
+
+	debug("Unknown hash algorithm '%s'\n", algo_name);
+	return -EPROTONOSUPPORT;
+}
+
+#ifndef USE_HOSTCC
 /**
  * store_result: Store the resulting sum to an address or variable
  *
@@ -293,39 +336,6 @@ static int parse_verify_sum(struct hash_algo *algo, char *verify_str,
 	return 0;
 }
 
-int hash_lookup_algo(const char *algo_name, struct hash_algo **algop)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
-		if (!strcmp(algo_name, hash_algo[i].name)) {
-			*algop = &hash_algo[i];
-			return 0;
-		}
-	}
-
-	debug("Unknown hash algorithm '%s'\n", algo_name);
-	return -EPROTONOSUPPORT;
-}
-
-int hash_progressive_lookup_algo(const char *algo_name,
-				 struct hash_algo **algop)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
-		if (!strcmp(algo_name, hash_algo[i].name)) {
-			if (hash_algo[i].hash_init) {
-				*algop = &hash_algo[i];
-				return 0;
-			}
-		}
-	}
-
-	debug("Unknown hash algorithm '%s'\n", algo_name);
-	return -EPROTONOSUPPORT;
-}
-
 void hash_show(struct hash_algo *algo, ulong addr, ulong len, uint8_t *output)
 {
 	int i;
@@ -439,3 +449,4 @@ int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag,
 
 	return 0;
 }
+#endif
include/hash.h +18 -16
index c0a7ebc..f4eb100 100644
@@ -17,7 +17,6 @@ enum {
 	HASH_FLAG_ENV		= 1 << 1,	/* Allow env vars */
 };
 
-#ifndef USE_HOSTCC
 #if defined(CONFIG_SHA1SUM_VERIFY) || defined(CONFIG_CRC32_VERIFY)
 #define CONFIG_HASH_VERIFY
 #endif
@@ -77,6 +76,7 @@ struct hash_algo {
 			   int size);
 };
 
+#ifndef USE_HOSTCC
 /**
  * hash_command: Process a hash command for a particular algorithm
  *
@@ -115,6 +115,23 @@ int hash_block(const char *algo_name, const void *data, unsigned int len,
 	       uint8_t *output, int *output_size);
 
 /**
+ * hash_show() - Print out a hash algorithm and value
+ *
+ * You will get a message like this (without a newline@the end):
+ *
+ * "sha1 for 9eb3337c ... 9eb3338f ==> 7942ef1df479fd3130f716eb9613d107dab7e257"
+ *
+ * @algo:		Algorithm used for hash
+ * @addr:		Address of data that was hashed
+ * @len:		Length of data that was hashed
+ * @output:		Hash value to display
+ */
+void hash_show(struct hash_algo *algo, ulong addr, ulong len,
+	       uint8_t *output);
+
+#endif /* !USE_HOSTCC */
+
+/**
  * hash_lookup_algo() - Look up the hash_algo struct for an algorithm
  *
  * The function returns the pointer to the struct or -EPROTONOSUPPORT if the
@@ -141,19 +158,4 @@ int hash_lookup_algo(const char *algo_name, struct hash_algo **algop);
 int hash_progressive_lookup_algo(const char *algo_name,
 				 struct hash_algo **algop);
 
-/**
- * hash_show() - Print out a hash algorithm and value
- *
- * You will get a message like this (without a newline at the end):
- *
- * "sha1 for 9eb3337c ... 9eb3338f ==> 7942ef1df479fd3130f716eb9613d107dab7e257"
- *
- * @algo:		Algorithm used for hash
- * @addr:		Address of data that was hashed
- * @len:		Length of data that was hashed
- * @output:		Hash value to display
- */
-void hash_show(struct hash_algo *algo, ulong addr, ulong len,
-	       uint8_t *output);
-#endif /* !USE_HOSTCC */
 #endif
tools/Makefile +1 -0
index 46b90b2..ea76a3e 100644
@@ -91,6 +91,7 @@ dumpimage-mkimage-objs := aisimage.o \
 			socfpgaimage.o \
 			lib/sha1.o \
 			lib/sha256.o \
+			common/hash.o \
 			ublimage.o \
 			$(LIBFDT_OBJS) \
 			$(RSA_OBJS-y)
Signature · 1 line
1.8.1.4
#24 lore raw

PATCH v6 10/10 rsa: Use checksum algorithms from struct hash_algo

In reply to Ruchika Gupta

Currently the hash functions used in RSA are called directly from the sha1 and sha256 libraries. Change the RSA checksum library to use the progressive hash API's registered with struct hash_algo. This will allow the checksum library to use the hardware accelerated progressive hash API's once available.

---
Changes in v6:
Removed changes in ls1021aqds.h accidently included in this patch

Changes in v5:
Both tools and uboot use the same code in rsa-checksum.c

Changes in v4:
No changes in this patch. Still under discussion

Changes in v3:
Modified rsa-verify to check for return from checksum function

Changes in v2:
Added generic function hash_calculate. Pass an additional argument as name of algorithm.

 common/image-sig.c            |  6 +++---
 include/image.h               |  5 +++--
 include/u-boot/rsa-checksum.h | 17 +++++++++++----
 lib/rsa/rsa-checksum.c        | 50 ++++++++++++++++++++++++++-----------------
 lib/rsa/rsa-verify.c          |  7 +++++-
 5 files changed, 55 insertions(+), 30 deletions(-)
common/image-sig.c +3 -3
index 8601eda..2c9f0cd 100644
@@ -38,7 +38,7 @@ struct checksum_algo checksum_algos[] = {
 #if IMAGE_ENABLE_SIGN
 		EVP_sha1,
 #endif
-		sha1_calculate,
+		hash_calculate,
 		padding_sha1_rsa2048,
 	},
 	{
@@ -48,7 +48,7 @@ struct checksum_algo checksum_algos[] = {
 #if IMAGE_ENABLE_SIGN
 		EVP_sha256,
 #endif
-		sha256_calculate,
+		hash_calculate,
 		padding_sha256_rsa2048,
 	},
 	{
@@ -58,7 +58,7 @@ struct checksum_algo checksum_algos[] = {
 #if IMAGE_ENABLE_SIGN
 		EVP_sha256,
 #endif
-		sha256_calculate,
+		hash_calculate,
 		padding_sha256_rsa4096,
 	}
 
include/image.h +3 -2
index ee3afe3..dcbc72f 100644
@@ -927,8 +927,9 @@ struct checksum_algo {
 #if IMAGE_ENABLE_SIGN
 	const EVP_MD *(*calculate_sign)(void);
 #endif
-	void (*calculate)(const struct image_region region[],
-			  int region_count, uint8_t *checksum);
+	int (*calculate)(const char *name,
+			 const struct image_region region[],
+			 int region_count, uint8_t *checksum);
 	const uint8_t *rsa_padding;
 };
 
include/u-boot/rsa-checksum.h +13 -4
index c996fb3..3c69d85 100644
@@ -16,9 +16,18 @@ extern const uint8_t padding_sha256_rsa4096[];
 extern const uint8_t padding_sha256_rsa2048[];
 extern const uint8_t padding_sha1_rsa2048[];
 
-void sha256_calculate(const struct image_region region[], int region_count,
-		      uint8_t *checksum);
-void sha1_calculate(const struct image_region region[], int region_count,
-		    uint8_t *checksum);
+/**
+ * hash_calculate() - Calculate hash over the data
+ *
+ * @name:  Name of algorithm to be used for hash calculation
+ * @region: Array having info of regions over which hash needs to be calculated
+ * @region_count: Number of regions in the region array
+ * @checksum: Buffer contanining the output hash
+ *
+ * @return 0 if OK, < 0 if error
+ */
+int hash_calculate(const char *name,
+		   const struct image_region region[], int region_count,
+		   uint8_t *checksum);
 
 #endif
lib/rsa/rsa-checksum.c +30 -20

70 lines not on this page · raw message

lib/rsa/rsa-verify.c +6 -1
index da45daf..60126d2 100644
@@ -184,7 +184,12 @@ int rsa_verify(struct image_sign_info *info,
 	}
 
 	/* Calculate checksum with checksum-algorithm */
-	info->algo->checksum->calculate(region, region_count, hash);
+	ret = info->algo->checksum->calculate(info->algo->checksum->name,
+					region, region_count, hash);
+	if (ret < 0) {
+		debug("%s: Error in checksum calculation\n", __func__);
+		return -EINVAL;
+	}
 
 	/* See if we must use a particular key */
 	if (info->required_keynode != -1) {
Signature · 1 line
1.8.1.4
#27 lore raw

PATCH v6 1/10 rsa: Split the rsa-verify to separate the modular exponentiation

In reply to Ruchika Gupta
Quoted 37 lines · Ruchika Gupta

Public exponentiation which is required in rsa verify functionality is tightly integrated with verification code in rsa_verify.c. The patch splits the file into twp separating the modular exponentiation.

1. rsa-verify.c
- The file parses device tree keys node to fill a keyprop structure. The keyprop structure can then be converted to implementation specific format.
(struct rsa_pub_key for sw implementation)
- The parsed device tree node is then passed to a generic rsa_mod_exp function.

2. rsa-mod-exp.c
Move the software specific functions related to modular exponentiation from rsa-verify.c to this file.

---
Changes in v6:
No changes

Changes in v5:
Reverted change in rsa_mod_exp_sw function to add pointer to output length Addressed other comments by Simon

Changes in v4:
Modified rsa_mod_exp_sw function to add pointer to output length

Changes in v3:
Kconfig moved to separate patch. This patch just splits the file now

Changes in v2:
Addressed few of Simon Glass's comments:
- Kconfig option added for RSA
- Comments added for new keyprop struct

Quoted 8 lines
 include/u-boot/rsa-mod-exp.h |  43 ++++++
 lib/rsa/Makefile             |   2 +-
 lib/rsa/rsa-mod-exp.c        | 303 +++++++++++++++++++++++++++++++++++++++
 lib/rsa/rsa-verify.c         | 329 ++++++++-----------------------------------
 tools/Makefile               |   3 +-
 5 files changed, 404 insertions(+), 276 deletions(-)
 create mode 100644 include/u-boot/rsa-mod-exp.h
 create mode 100644 lib/rsa/rsa-mod-exp.c
#4 lore raw

PATCH v6 3/10 DM: crypto/rsa_mod_exp: Add rsa Modular Exponentiation DM driver

In reply to Ruchika Gupta

Hi Ruchika,

Quoted 20 lines · Ruchika Gupta

Add a new rsa uclass for performing modular exponentiation and implement the software driver basing on this uclass.

---
Changes in v6:
No Changes

Changes in v5:
Changed UCLASS name to UCLASS_MOD_EXP

Changes in v4:
Removed Kconfig option for DM_RSA
Corrected driver name for sw rsa driver Updated the rsa_mod_exp operation to have output length

Changes in v3:
New patch with driver model for RSA UCLASS

Quoted 12 lines
 drivers/crypto/Makefile                     |  1 +
 drivers/crypto/rsa_mod_exp/Kconfig          |  5 ++++
 drivers/crypto/rsa_mod_exp/Makefile         |  7 ++++++
 drivers/crypto/rsa_mod_exp/mod_exp_sw.c     | 39 +++++++++++++++++++++++++++++
 drivers/crypto/rsa_mod_exp/mod_exp_uclass.c | 31 +++++++++++++++++++++++
 include/dm/uclass-id.h                      |  1 +
 include/u-boot/rsa-mod-exp.h                | 34 ++++++++++++++++++++++++-
 7 files changed, 117 insertions(+), 1 deletion(-)
 create mode 100644 drivers/crypto/rsa_mod_exp/Kconfig
 create mode 100644 drivers/crypto/rsa_mod_exp/Makefile
 create mode 100644 drivers/crypto/rsa_mod_exp/mod_exp_sw.c
 create mode 100644 drivers/crypto/rsa_mod_exp/mod_exp_uclass.c

Just in case there is a v7:

Quoted 8 lines

+++ b/drivers/crypto/rsa_mod_exp/mod_exp_uclass.c

drivers/crypto/rsa_mod_exp/mod_exp_uclass.c new file +6 -0
@@ -0,0 +1,31 @@
+/*
+ * (C) Copyright 2014 Freescale Semiconductor, Inc
+ * Author: Ruchika Gupta <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */

drivers/crypto/rsa_mod_exp/mod_exp_uclass.c line 16

Quoted 10 lines
drivers/crypto/rsa_mod_exp/mod_exp_uclass.c new file +10 -0
+
+#include <common.h>
+#include <dm.h>
+#include <u-boot/rsa-mod-exp.h>
+#include <errno.h>
+#include <fdtdec.h>
+#include <malloc.h>
+#include <asm/io.h>
+#include <linux/list.h>
+

You can trim headers here.

Regards,
Simon

#10 lore raw

PATCH v6 5/10 lib/rsa: Modify rsa to use DM driver

In reply to Ruchika Gupta
Quoted 24 lines · Ruchika Gupta

Modify rsa_verify to use the rsa driver of DM library .The tools will continue to use the same RSA sw library.

CONFIG_RSA is now dependent on CONFIG_DM. All configurations which enable FIT based signatures have been modified to enable CONFIG_DM by default.

---
Changes in v6:
No Changes

Changes in v5:
Added signature option in am335x_boneblack_vboot_defconfig Made changes in rsa-verify.c as suggested by Simon

Changes in v4:
Make CONFIG_RSA always depenedent on Driver Model.
Add CONFIG_DM in defconfigs of the platforms which enable CONFIG_FIT_SIGNATURE

Changes in v3:
New patch

Quoted 16 lines
 README                                   |  7 ++++++-
 configs/am335x_boneblack_vboot_defconfig |  4 ++++
 configs/ids8313_defconfig                |  1 +
 configs/sandbox_defconfig                |  1 +
 configs/zynq_microzed_defconfig          |  1 +
 configs/zynq_zc70x_defconfig             |  1 +
 configs/zynq_zc770_xm010_defconfig       |  1 +
 configs/zynq_zc770_xm012_defconfig       |  1 +
 configs/zynq_zc770_xm013_defconfig       |  1 +
 configs/zynq_zed_defconfig               |  1 +
 configs/zynq_zybo_defconfig              |  1 +
 include/configs/am335x_evm.h             |  6 ++----
 include/configs/sandbox.h                |  1 -
 lib/rsa/rsa-verify.c                     | 14 ++++++++++++++
 14 files changed, 35 insertions(+), 6 deletions(-)
#13 lore raw

PATCH v6 6/10 DM: crypto/fsl - Add Freescale rsa DM driver

In reply to Ruchika Gupta
Quoted 18 lines · Ruchika Gupta

Driver added for RSA Modular Exponentiation using Freescale Hardware Accelerator CAAM. The driver uses UCLASS_MOD_EXP

---
Changes in v6:
No Changes

Changes in v5:
Reverted mod_exp not to use output length

Changes in v4:
Modified for the changes in op function of rsa class mod_exp

Changes in v3:
Moved to integrate with RSA UCLASS

Quoted 11 lines
 drivers/crypto/Kconfig        |  1 +
 drivers/crypto/fsl/Kconfig    |  6 +++++
 drivers/crypto/fsl/Makefile   |  1 +
 drivers/crypto/fsl/fsl_rsa.c  | 60 +++++++++++++++++++++++++++++++++++++++++++
 drivers/crypto/fsl/jobdesc.c  | 28 ++++++++++++++++++++
 drivers/crypto/fsl/jobdesc.h  |  5 ++++
 drivers/crypto/fsl/rsa_caam.h | 28 ++++++++++++++++++++
 7 files changed, 129 insertions(+)
 create mode 100644 drivers/crypto/fsl/Kconfig
 create mode 100644 drivers/crypto/fsl/fsl_rsa.c
 create mode 100644 drivers/crypto/fsl/rsa_caam.h

I don't see what you want inline functions in jobdesc.h, but I suppose that is your business.

#16 lore raw

PATCH v6 7/10 lib/rsa: Add Kconfig for devices supporting RSA Modular Exponentiation

In reply to Ruchika Gupta
Quoted 23 lines · Ruchika Gupta

Kconfig option added for devices which support RSA Verification.
1. RSA_SOFTWARE_EXP
Enables driver for supporting RSA Modular Exponentiation in Software
2. RSA_FREESCALE_EXP
Enables driver for supporting RSA Modular Exponentiation using Freescale specific driver

The above drivers use RSA uclass

---
Changes in v6:
No Changes

Changes in v5:
No changes

Changes in v4:
Introduced 2 options when CONFIG_RSA is selected:
RSA_SOFTWARE_EXP
RSA_FREESCALE_EXP

Quoted 8 lines

Removed RSA_HW. Changes the name pf RSA_SW to RSA_SOFTWARE_EXP

Changes in v3:
New patch

 lib/Kconfig     |  7 +------
 lib/rsa/Kconfig | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 6 deletions(-)
 create mode 100644 lib/rsa/Kconfig

(note the duplicated line in your Kconfig if you issue a new version, but I can clean that up when applying it)

+++ b/lib/rsa/Kconfig

Quoted 10 lines
lib/rsa/Kconfig new file +9 -0
@@ -0,0 +1,28 @@
+config RSA
+       bool "Use RSA Library"
+       select RSA_FREESCALE_EXP if FSL_CAAM
+       select RSA_SOFTWARE_EXP if !RSA_FREESCALE_EXP
+       help
+         RSA support. This enables the RSA algorithm used for FIT image
+         verification in U-Boot.
+         See doc/uImage.FIT/signature.txt for more details.
+         See doc/uImage.FIT/signature.txt for more details.
#19 lore raw

PATCH v6 8/10 hash: Add function to find hash_algo struct with progressive hash

In reply to Ruchika Gupta
Quoted 22 lines · Ruchika Gupta

The hash_algo structure has some implementations in which progressive hash API's are not defined. These are basically the hardware based implementations of SHA. An API is added to find the algo which has progressive hash API's defined. This can then be integrated with RSA checksum library which uses Progressive Hash API's.

---
Changes in v6:
No Changes

Changes in v5:
None

Changes in v4:
Few cosmetic changes. Currently I have not replaced CONFIG_SHA1 with CONFIG_CMD_SHA1SUM. Waiting for reply from Simon and Denx for the same.

Changes in v3 :
Corrected ifdef for SHA1

Quoted 6 lines

Changes in v2 :
Added commit message

 common/hash.c  | 33 ++++++++++++++++++++++++---------
 include/hash.h | 14 ++++++++++++++
 2 files changed, 38 insertions(+), 9 deletions(-)
#22 lore raw

PATCH v6 9/10 Use hash.c in mkimage

In reply to Ruchika Gupta
Quoted 6 lines · Ruchika Gupta

---
Changes in v6:
Fixed compilation error in this file for tools when FIT_SIGNATURE not enabled

Quoted 7 lines

Changes in v5:
New patch based on WIP patch by Simon.

 common/hash.c  | 81 +++++++++++++++++++++++++++++++++-------------------------
 include/hash.h | 34 ++++++++++++------------
 tools/Makefile |  1 +
 3 files changed, 65 insertions(+), 51 deletions(-)
#25 lore raw

PATCH v6 10/10 rsa: Use checksum algorithms from struct hash_algo

In reply to Ruchika Gupta
Quoted 24 lines · Ruchika Gupta

Currently the hash functions used in RSA are called directly from the sha1 and sha256 libraries. Change the RSA checksum library to use the progressive hash API's registered with struct hash_algo. This will allow the checksum library to use the hardware accelerated progressive hash API's once available.

---
Changes in v6:
Removed changes in ls1021aqds.h accidently included in this patch

Changes in v5:
Both tools and uboot use the same code in rsa-checksum.c

Changes in v4:
No changes in this patch. Still under discussion

Changes in v3:
Modified rsa-verify to check for return from checksum function

Changes in v2:
Added generic function hash_calculate. Pass an additional argument as name of algorithm.

Quoted 6 lines
 common/image-sig.c            |  6 +++---
 include/image.h               |  5 +++--
 include/u-boot/rsa-checksum.h | 17 +++++++++++----
 lib/rsa/rsa-checksum.c        | 50 ++++++++++++++++++++++++++-----------------
 lib/rsa/rsa-verify.c          |  7 +++++-
 5 files changed, 55 insertions(+), 30 deletions(-)
#5 lore raw

PATCH v6 3/10 DM: crypto/rsa_mod_exp: Add rsa Modular Exponentiation DM driver

In reply to Simon Glass

Hi Ruchika,

Quoted 52 lines · Simon Glass

Hi Ruchika,

Quoted 20 lines · Ruchika Gupta

Add a new rsa uclass for performing modular exponentiation and implement the software driver basing on this uclass.

---
Changes in v6:
No Changes

Changes in v5:
Changed UCLASS name to UCLASS_MOD_EXP

Changes in v4:
Removed Kconfig option for DM_RSA
Corrected driver name for sw rsa driver Updated the rsa_mod_exp operation to have output length

Changes in v3:
New patch with driver model for RSA UCLASS

Quoted 12 lines
 drivers/crypto/Makefile                     |  1 +
 drivers/crypto/rsa_mod_exp/Kconfig          |  5 ++++
 drivers/crypto/rsa_mod_exp/Makefile         |  7 ++++++
 drivers/crypto/rsa_mod_exp/mod_exp_sw.c     | 39 +++++++++++++++++++++++++++++
 drivers/crypto/rsa_mod_exp/mod_exp_uclass.c | 31 +++++++++++++++++++++++
 include/dm/uclass-id.h                      |  1 +
 include/u-boot/rsa-mod-exp.h                | 34 ++++++++++++++++++++++++-
 7 files changed, 117 insertions(+), 1 deletion(-)
 create mode 100644 drivers/crypto/rsa_mod_exp/Kconfig
 create mode 100644 drivers/crypto/rsa_mod_exp/Makefile
 create mode 100644 drivers/crypto/rsa_mod_exp/mod_exp_sw.c
 create mode 100644 drivers/crypto/rsa_mod_exp/mod_exp_uclass.c

Just in case there is a v7:

Quoted 12 lines

+++ b/drivers/crypto/rsa_mod_exp/mod_exp_uclass.c

drivers/crypto/rsa_mod_exp/mod_exp_uclass.c new file +10 -0
@@ -0,0 +1,31 @@
+/*
+ * (C) Copyright 2014 Freescale Semiconductor, Inc
+ * Author: Ruchika Gupta <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <u-boot/rsa-mod-exp.h>
Quoted 8 lines

drivers/crypto/rsa_mod_exp/mod_exp_uclass.c line 16

Quoted 6 lines
drivers/crypto/rsa_mod_exp/mod_exp_uclass.c new file +6 -0
+#include <errno.h>
+#include <fdtdec.h>
+#include <malloc.h>
+#include <asm/io.h>
+#include <linux/list.h>
+

You can trim headers here.

There are a few nits I mentioned in your patches.

To avoid further delay and testing I would like to pick these patches up as is, but if you like you could send a follow-on patch.

Regards,
Simon

#28 lore raw

PATCH v6 1/10 rsa: Split the rsa-verify to separate the modular exponentiation

In reply to Simon Glass
Quoted 47 lines · Simon Glass
Quoted 37 lines · Ruchika Gupta

Public exponentiation which is required in rsa verify functionality is tightly integrated with verification code in rsa_verify.c. The patch splits the file into twp separating the modular exponentiation.

1. rsa-verify.c
- The file parses device tree keys node to fill a keyprop structure. The keyprop structure can then be converted to implementation specific format.
(struct rsa_pub_key for sw implementation)
- The parsed device tree node is then passed to a generic rsa_mod_exp function.

2. rsa-mod-exp.c
Move the software specific functions related to modular exponentiation from rsa-verify.c to this file.

---
Changes in v6:
No changes

Changes in v5:
Reverted change in rsa_mod_exp_sw function to add pointer to output length Addressed other comments by Simon

Changes in v4:
Modified rsa_mod_exp_sw function to add pointer to output length

Changes in v3:
Kconfig moved to separate patch. This patch just splits the file now

Changes in v2:
Addressed few of Simon Glass's comments:
- Kconfig option added for RSA
- Comments added for new keyprop struct

Quoted 8 lines
 include/u-boot/rsa-mod-exp.h |  43 ++++++
 lib/rsa/Makefile             |   2 +-
 lib/rsa/rsa-mod-exp.c        | 303 +++++++++++++++++++++++++++++++++++++++
 lib/rsa/rsa-verify.c         | 329 ++++++++-----------------------------------
 tools/Makefile               |   3 +-
 5 files changed, 404 insertions(+), 276 deletions(-)
 create mode 100644 include/u-boot/rsa-mod-exp.h
 create mode 100644 lib/rsa/rsa-mod-exp.c
Quoted 1 line

Applied to u-boot-dm, thanks!

#2 lore raw

PATCH v6 2/10 FIT: Modify option FIT_SIGNATURE in Kconfig

In reply to Ruchika Gupta
Quoted 7 lines · Ruchika Gupta

For FIT signature based approach to work, RSA library needs to be selected. The FIT_SIGNATURE option in Kconfig is modified to automatically select RSA. Selecting RSA compiles the RSA library required for image verification.

Applied to u-boot-dm, thanks!

#6 lore raw

PATCH v6 3/10 DM: crypto/rsa_mod_exp: Add rsa Modular Exponentiation DM driver

In reply to Simon Glass
Quoted 64 lines · Simon Glass

Hi Ruchika,

Quoted 52 lines · Simon Glass

Hi Ruchika,

Quoted 20 lines · Ruchika Gupta

Add a new rsa uclass for performing modular exponentiation and implement the software driver basing on this uclass.

---
Changes in v6:
No Changes

Changes in v5:
Changed UCLASS name to UCLASS_MOD_EXP

Changes in v4:
Removed Kconfig option for DM_RSA
Corrected driver name for sw rsa driver Updated the rsa_mod_exp operation to have output length

Changes in v3:
New patch with driver model for RSA UCLASS

Quoted 12 lines
 drivers/crypto/Makefile                     |  1 +
 drivers/crypto/rsa_mod_exp/Kconfig          |  5 ++++
 drivers/crypto/rsa_mod_exp/Makefile         |  7 ++++++
 drivers/crypto/rsa_mod_exp/mod_exp_sw.c     | 39 +++++++++++++++++++++++++++++
 drivers/crypto/rsa_mod_exp/mod_exp_uclass.c | 31 +++++++++++++++++++++++
 include/dm/uclass-id.h                      |  1 +
 include/u-boot/rsa-mod-exp.h                | 34 ++++++++++++++++++++++++-
 7 files changed, 117 insertions(+), 1 deletion(-)
 create mode 100644 drivers/crypto/rsa_mod_exp/Kconfig
 create mode 100644 drivers/crypto/rsa_mod_exp/Makefile
 create mode 100644 drivers/crypto/rsa_mod_exp/mod_exp_sw.c
 create mode 100644 drivers/crypto/rsa_mod_exp/mod_exp_uclass.c

Just in case there is a v7:

Quoted 12 lines

+++ b/drivers/crypto/rsa_mod_exp/mod_exp_uclass.c

drivers/crypto/rsa_mod_exp/mod_exp_uclass.c new file +10 -0
@@ -0,0 +1,31 @@
+/*
+ * (C) Copyright 2014 Freescale Semiconductor, Inc
+ * Author: Ruchika Gupta <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <u-boot/rsa-mod-exp.h>
Quoted 8 lines

drivers/crypto/rsa_mod_exp/mod_exp_uclass.c line 16

Quoted 6 lines
drivers/crypto/rsa_mod_exp/mod_exp_uclass.c new file +6 -0
+#include <errno.h>
+#include <fdtdec.h>
+#include <malloc.h>
+#include <asm/io.h>
+#include <linux/list.h>
+

You can trim headers here.

Quoted 4 lines

There are a few nits I mentioned in your patches.

To avoid further delay and testing I would like to pick these patches up as is, but if you like you could send a follow-on patch.

Applied to u-boot-dm, thanks!

#8 lore raw

PATCH v6 4/10 configs: Move CONFIG_FIT_SIGNATURE to defconfig

In reply to Ruchika Gupta
Quoted 6 lines · Ruchika Gupta

For the platforms which use,CONFIG_FIT_SIGNATURE, the required configs are moved to the platform's defconfig file. Selecting CONFIG_FIT_SIGNATURE using defconfig automatically resolves the dependencies for signature verification. The RSA library gets automatically selected and user does not have to define CONFIG_RSA manually.

Quoted 6 lines

---
Changes in v6:
No Changes

Applied to u-boot-dm, thanks!

#11 lore raw

PATCH v6 5/10 lib/rsa: Modify rsa to use DM driver

In reply to Simon Glass
Quoted 42 lines · Simon Glass
Quoted 24 lines · Ruchika Gupta

Modify rsa_verify to use the rsa driver of DM library .The tools will continue to use the same RSA sw library.

CONFIG_RSA is now dependent on CONFIG_DM. All configurations which enable FIT based signatures have been modified to enable CONFIG_DM by default.

---
Changes in v6:
No Changes

Changes in v5:
Added signature option in am335x_boneblack_vboot_defconfig Made changes in rsa-verify.c as suggested by Simon

Changes in v4:
Make CONFIG_RSA always depenedent on Driver Model.
Add CONFIG_DM in defconfigs of the platforms which enable CONFIG_FIT_SIGNATURE

Changes in v3:
New patch

Quoted 16 lines
 README                                   |  7 ++++++-
 configs/am335x_boneblack_vboot_defconfig |  4 ++++
 configs/ids8313_defconfig                |  1 +
 configs/sandbox_defconfig                |  1 +
 configs/zynq_microzed_defconfig          |  1 +
 configs/zynq_zc70x_defconfig             |  1 +
 configs/zynq_zc770_xm010_defconfig       |  1 +
 configs/zynq_zc770_xm012_defconfig       |  1 +
 configs/zynq_zc770_xm013_defconfig       |  1 +
 configs/zynq_zed_defconfig               |  1 +
 configs/zynq_zybo_defconfig              |  1 +
 include/configs/am335x_evm.h             |  6 ++----
 include/configs/sandbox.h                |  1 -
 lib/rsa/rsa-verify.c                     | 14 ++++++++++++++
 14 files changed, 35 insertions(+), 6 deletions(-)
Quoted 1 line

Applied to u-boot-dm, thanks!

#14 lore raw

PATCH v6 6/10 DM: crypto/fsl - Add Freescale rsa DM driver

In reply to Simon Glass
Quoted 31 lines · Simon Glass
Quoted 18 lines · Ruchika Gupta

Driver added for RSA Modular Exponentiation using Freescale Hardware Accelerator CAAM. The driver uses UCLASS_MOD_EXP

---
Changes in v6:
No Changes

Changes in v5:
Reverted mod_exp not to use output length

Changes in v4:
Modified for the changes in op function of rsa class mod_exp

Changes in v3:
Moved to integrate with RSA UCLASS

Quoted 11 lines
 drivers/crypto/Kconfig        |  1 +
 drivers/crypto/fsl/Kconfig    |  6 +++++
 drivers/crypto/fsl/Makefile   |  1 +
 drivers/crypto/fsl/fsl_rsa.c  | 60 +++++++++++++++++++++++++++++++++++++++++++
 drivers/crypto/fsl/jobdesc.c  | 28 ++++++++++++++++++++
 drivers/crypto/fsl/jobdesc.h  |  5 ++++
 drivers/crypto/fsl/rsa_caam.h | 28 ++++++++++++++++++++
 7 files changed, 129 insertions(+)
 create mode 100644 drivers/crypto/fsl/Kconfig
 create mode 100644 drivers/crypto/fsl/fsl_rsa.c
 create mode 100644 drivers/crypto/fsl/rsa_caam.h
Quoted 4 lines

I don't see what you want inline functions in jobdesc.h, but I suppose that is your business.

Applied to u-boot-dm, thanks!

#17 lore raw

PATCH v6 7/10 lib/rsa: Add Kconfig for devices supporting RSA Modular Exponentiation

In reply to Simon Glass
Quoted 40 lines · Simon Glass
Quoted 23 lines · Ruchika Gupta

Kconfig option added for devices which support RSA Verification.
1. RSA_SOFTWARE_EXP
Enables driver for supporting RSA Modular Exponentiation in Software
2. RSA_FREESCALE_EXP
Enables driver for supporting RSA Modular Exponentiation using Freescale specific driver

The above drivers use RSA uclass

---
Changes in v6:
No Changes

Changes in v5:
No changes

Changes in v4:
Introduced 2 options when CONFIG_RSA is selected:
RSA_SOFTWARE_EXP
RSA_FREESCALE_EXP

Quoted 8 lines

Removed RSA_HW. Changes the name pf RSA_SW to RSA_SOFTWARE_EXP

Changes in v3:
New patch

 lib/Kconfig     |  7 +------
 lib/rsa/Kconfig | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 6 deletions(-)
 create mode 100644 lib/rsa/Kconfig

(note the duplicated line in your Kconfig if you issue a new version, but I can clean that up when applying it)

+++ b/lib/rsa/Kconfig

Quoted 10 lines

lib/rsa/Kconfig line 9

Quoted 10 lines
lib/rsa/Kconfig new file +9 -0
@@ -0,0 +1,28 @@
+config RSA
+       bool "Use RSA Library"
+       select RSA_FREESCALE_EXP if FSL_CAAM
+       select RSA_SOFTWARE_EXP if !RSA_FREESCALE_EXP
+       help
+         RSA support. This enables the RSA algorithm used for FIT image
+         verification in U-Boot.
+         See doc/uImage.FIT/signature.txt for more details.
+         See doc/uImage.FIT/signature.txt for more details.

I tidied this up.

Applied to u-boot-dm, thanks!

#20 lore raw

PATCH v6 8/10 hash: Add function to find hash_algo struct with progressive hash

In reply to Simon Glass
Quoted 23 lines · Simon Glass
Quoted 22 lines · Ruchika Gupta

The hash_algo structure has some implementations in which progressive hash API's are not defined. These are basically the hardware based implementations of SHA. An API is added to find the algo which has progressive hash API's defined. This can then be integrated with RSA checksum library which uses Progressive Hash API's.

---
Changes in v6:
No Changes

Changes in v5:
None

Changes in v4:
Few cosmetic changes. Currently I have not replaced CONFIG_SHA1 with CONFIG_CMD_SHA1SUM. Waiting for reply from Simon and Denx for the same.

Changes in v3 :
Corrected ifdef for SHA1

Quoted 8 lines
Quoted 6 lines

Changes in v2 :
Added commit message

 common/hash.c  | 33 ++++++++++++++++++++++++---------
 include/hash.h | 14 ++++++++++++++
 2 files changed, 38 insertions(+), 9 deletions(-)

Applied to u-boot-dm, thanks!

#23 lore raw

PATCH v6 9/10 Use hash.c in mkimage

In reply to Simon Glass
Quoted 10 lines · Simon Glass
Quoted 9 lines · Ruchika Gupta

---
Changes in v6:
Fixed compilation error in this file for tools when FIT_SIGNATURE not enabled

Changes in v5:
New patch based on WIP patch by Simon.

Quoted 6 lines
Quoted 4 lines
 common/hash.c  | 81 +++++++++++++++++++++++++++++++++-------------------------
 include/hash.h | 34 ++++++++++++------------
 tools/Makefile |  1 +
 3 files changed, 65 insertions(+), 51 deletions(-)

Applied to u-boot-dm, thanks!

#26 lore raw

PATCH v6 10/10 rsa: Use checksum algorithms from struct hash_algo

In reply to Simon Glass
Quoted 25 lines · Simon Glass
Quoted 24 lines · Ruchika Gupta

Currently the hash functions used in RSA are called directly from the sha1 and sha256 libraries. Change the RSA checksum library to use the progressive hash API's registered with struct hash_algo. This will allow the checksum library to use the hardware accelerated progressive hash API's once available.

---
Changes in v6:
Removed changes in ls1021aqds.h accidently included in this patch

Changes in v5:
Both tools and uboot use the same code in rsa-checksum.c

Changes in v4:
No changes in this patch. Still under discussion

Changes in v3:
Modified rsa-verify to check for return from checksum function

Changes in v2:
Added generic function hash_calculate. Pass an additional argument as name of algorithm.

Quoted 8 lines
Quoted 6 lines
 common/image-sig.c            |  6 +++---
 include/image.h               |  5 +++--
 include/u-boot/rsa-checksum.h | 17 +++++++++++----
 lib/rsa/rsa-checksum.c        | 50 ++++++++++++++++++++++++++-----------------
 lib/rsa/rsa-verify.c          |  7 +++++-
 5 files changed, 55 insertions(+), 30 deletions(-)

I had to make a tweak to include/configs/ti_am335x_common.h to avoid a build breakage. With that:

Applied to u-boot-dm, thanks!