Skip to contentSkip to conversation

aspeed: ast2700: Add Caliptra ECDSA driver

PATCH Superseded Chia-Wei Wang 2 participants 7 messages Sep 27, 2024 – Oct 14, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover aspeed: ast2700: Add Caliptra ECDSA driver

Aspeed AST2700 SoCs integrates the Caliptra secure IP, where an ECDSA384 signature verification HW interface is exported for SoC crypto needs.

This patch series firstly extends the FIT image signing/verify common code to support the ECDSA384 algorithm. For better convenience, the device tree for ECDSA public key storage is also revised by referring to RSA implementations.

After the FIT common code revision, the driver is implemented for AST2700 to leverage the Caliptra ECDSA384 signature verification.

These are verified by signed FIT images with the algorithm "sha384,ecdsa384".

v2 change:
- revise the commit message of padding check removal for better explanation
- remove redundant check in static function
- revise errno and error message as suggested by Simon
- collect Reviewed-by tags

Chia-Wei Wang (4):
lib: ecdsa: Add ECDSA384 support
lib: ecdsa: Create device tree node automatically
image-fit-sig: Remove padding check drivers/crypto: aspeed: Add Caliptra ECDSA384 support

 boot/image-fit-sig.c                |   2 +-
 drivers/crypto/aspeed/Kconfig       |  10 ++
 drivers/crypto/aspeed/Makefile      |   1 +
 drivers/crypto/aspeed/cptra_ecdsa.c | 184 ++++++++++++++++++++++++++++
 include/u-boot/ecdsa.h              |   1 +
 lib/ecdsa/ecdsa-libcrypto.c         |  25 ++--
 lib/ecdsa/ecdsa-verify.c            |  14 ++-
 tools/image-sig-host.c              |   7 ++
 8 files changed, 233 insertions(+), 11 deletions(-)
 create mode 100644 drivers/crypto/aspeed/cptra_ecdsa.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/4 lib: ecdsa: Add ECDSA384 support

Add ECDSA384 algorithm support for image signing and verification.

---
 include/u-boot/ecdsa.h   |  1 +
 lib/ecdsa/ecdsa-verify.c | 14 +++++++++++---
 tools/image-sig-host.c   |  7 +++++++
 3 files changed, 19 insertions(+), 3 deletions(-)
include/u-boot/ecdsa.h +1 -0
index 53490c6b287..0d4df9887e6 100644
@@ -65,5 +65,6 @@ int ecdsa_verify(struct image_sign_info *info,
 /** @} */
 
 #define ECDSA256_BYTES	(256 / 8)
+#define ECDSA384_BYTES	(384 / 8)
 
 #endif
lib/ecdsa/ecdsa-verify.c +11 -3
index 4d1835b598a..629b662cf6c 100644
@@ -22,8 +22,10 @@ static int ecdsa_key_size(const char *curve_name)
 {
 	if (!strcmp(curve_name, "prime256v1"))
 		return 256;
-	else
-		return 0;
+	else if (!strcmp(curve_name, "secp384r1"))
+		return 384;
+
+	return 0;
 }
 
 static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
@@ -121,12 +123,18 @@ int ecdsa_verify(struct image_sign_info *info,
 	return ecdsa_verify_hash(dev, info, hash, sig, sig_len);
 }
 
-U_BOOT_CRYPTO_ALGO(ecdsa) = {
+U_BOOT_CRYPTO_ALGO(ecdsa256) = {
 	.name = "ecdsa256",
 	.key_len = ECDSA256_BYTES,
 	.verify = ecdsa_verify,
 };
 
+U_BOOT_CRYPTO_ALGO(ecdsa384) = {
+	.name = "ecdsa384",
+	.key_len = ECDSA384_BYTES,
+	.verify = ecdsa_verify,
+};
+
 /*
  * uclass definition for ECDSA API
  *
tools/image-sig-host.c +7 -0
index d0133aec4c8..22253502065 100644
@@ -76,6 +76,13 @@ struct crypto_algo crypto_algos[] = {
 		.add_verify_data = ecdsa_add_verify_data,
 		.verify = ecdsa_verify,
 	},
+	{
+		.name = "ecdsa384",
+		.key_len = ECDSA384_BYTES,
+		.sign = ecdsa_sign,
+		.add_verify_data = ecdsa_add_verify_data,
+		.verify = ecdsa_verify,
+	},
 };
 
 struct padding_algo padding_algos[] = {
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 2/4 lib: ecdsa: Create device tree node automatically

In reply to Chia-Wei Wang

Both the signature and the public key are stored as DTS nodes in the FIT image and SPL/U-Boot DTBs.

Like the RSA signing & verification do, this patch either creates the nodes or overwirte the content automatically.

---
 lib/ecdsa/ecdsa-libcrypto.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
lib/ecdsa/ecdsa-libcrypto.c +18 -7
index 5fa9be10b4b..774cc946c7b 100644
@@ -281,15 +281,26 @@ static int do_add(struct signer *ctx, void *fdt, const char *key_node_name)
 	BIGNUM *x, *y;
 
 	signature_node = fdt_subnode_offset(fdt, 0, FIT_SIG_NODENAME);
-	if (signature_node < 0) {
-		fprintf(stderr, "Could not find 'signature node: %s\n",
-			fdt_strerror(signature_node));
-		return signature_node;
+	if (signature_node == -FDT_ERR_NOTFOUND) {
+		signature_node = fdt_add_subnode(fdt, 0, FIT_SIG_NODENAME);
+		if (signature_node < 0) {
+			fprintf(stderr, "Could not add 'signature' node: %s\n",
+				fdt_strerror(signature_node));
+			return signature_node;
+		}
 	}
 
-	key_node = fdt_add_subnode(fdt, signature_node, key_node_name);
-	if (key_node < 0) {
-		fprintf(stderr, "Could not create '%s' node: %s\n",
+	/* Either create or overwrite the named key node */
+	key_node = fdt_subnode_offset(fdt, signature_node, key_node_name);
+	if (key_node == -FDT_ERR_NOTFOUND) {
+		key_node = fdt_add_subnode(fdt, signature_node, key_node_name);
+		if (key_node < 0) {
+			fprintf(stderr, "Could not create '%s' node: %s\n",
+				key_node_name, fdt_strerror(key_node));
+			return key_node;
+		}
+	} else if (key_node < 0) {
+		fprintf(stderr, "cannot select '%s' node: %s\n",
 			key_node_name, fdt_strerror(key_node));
 		return key_node;
 	}
Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 3/4 image-fit-sig: Remove padding check

In reply to Chia-Wei Wang

The padding algorithm is not mandatory for all signing algorithm. For example, ECDSA does not require a padding method.

For RSA requiring PKCS padding, the belonging info->crypto(), assigned with rsa_verify_key(), also has the check on the validity of info->padding().

Thus, remove the info->padding check from the upper, general layer.

---
 boot/image-fit-sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
boot/image-fit-sig.c +1 -1
index fe328df4a85..d06e6cc8ed6 100644
@@ -95,7 +95,7 @@ static int fit_image_setup_verify(struct image_sign_info *info,
 	info->required_keynode = required_keynode;
 	printf("%s:%s", algo_name, info->keyname);
 
-	if (!info->checksum || !info->crypto || !info->padding) {
+	if (!info->checksum || !info->crypto) {
 		*err_msgp = "Unknown signature algorithm";
 		return -1;
 	}
Signature · 1 line
2.25.1
#4 lore raw

PATCH v2 4/4 drivers/crypto: aspeed: Add Caliptra ECDSA384 support

In reply to Chia-Wei Wang

Aspeed AST27xx SoCs integrate the CPTRA 1.0 secure IP, which export an ECDSA384_SIGNATURE_VERIFY mailbox command service for SoC to use.

This patch is verified by the FIT signature verification using the "sha384,ecdsa384" algorithm.

---
 drivers/crypto/aspeed/Kconfig       |  10 ++
 drivers/crypto/aspeed/Makefile      |   1 +
 drivers/crypto/aspeed/cptra_ecdsa.c | 184 ++++++++++++++++++++++++++++
 3 files changed, 195 insertions(+)
 create mode 100644 drivers/crypto/aspeed/cptra_ecdsa.c
drivers/crypto/aspeed/Kconfig +10 -0
index 9bf317177aa..19fbe983888 100644
@@ -18,3 +18,13 @@ config ASPEED_ACRY
 
 	 Enabling this allows the use of RSA/ECC operations in hardware without requiring the
 	 software implementations. It also improves performance and saves code size.
+
+config ASPEED_CPTRA_ECDSA
+	bool "Caliptra ECDSA384 signature verifier for Aspeed SoCs"
+	depends on ECDSA_VERIFY || SPL_ECDSA_VERIFY
+	help
+	  Select this option to enable a driver for using the ECDSA384_SIGNATURE_VERIFY
+	  feature of Caliptra, which is integrated in AST27xx BMC SoCs.
+
+	  Enabling this allows the use of ECDSA384 signature verification in hardware.
+	  Note that only ECDSA384 is supported by Caliptra.
drivers/crypto/aspeed/Makefile +1 -0
index 58b55fc46e4..3ca5e829412 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_ASPEED_HACE) += aspeed_hace.o
 obj-$(CONFIG_ASPEED_ACRY) += aspeed_acry.o
+obj-$(CONFIG_ASPEED_CPTRA_ECDSA) += cptra_ecdsa.o
drivers/crypto/aspeed/cptra_ecdsa.c new file +184 -0

184 lines not on this page · raw message

Signature · 1 line
2.25.1
#5 lore raw
In reply to Chia-Wei Wang
Quoted 11 lines · Chia-Wei Wang

Aspeed AST2700 SoCs integrates the Caliptra secure IP, where an ECDSA384 signature verification HW interface is exported for SoC crypto needs.

This patch series firstly extends the FIT image signing/verify common code to support the ECDSA384 algorithm. For better convenience, the device tree for ECDSA public key storage is also revised by referring to RSA implementations.

After the FIT common code revision, the driver is implemented for AST2700 to leverage the Caliptra ECDSA384 signature verification.

Quoted 7 lines

These are verified by signed FIT images with the algorithm "sha384,ecdsa384".

v2 change:
- revise the commit message of padding check removal for better explanation
- remove redundant check in static function
- revise errno and error message as suggested by Simon
- collect Reviewed-by tags

Please rebase on top of current master, thanks.

Signature · 1 line
Tom
#6 lore raw
Quoted 21 lines

From: Tom Rini <[email protected]>
Sent: Saturday, October 12, 2024 1:34 AM
To: ChiaWei Wang <[email protected]>

Quoted 2 lines · Chia-Wei Wang

Aspeed AST2700 SoCs integrates the Caliptra secure IP, where an ECDSA384 signature verification HW interface is exported for SoC crypto

needs.

Quoted 10 lines

This patch series firstly extends the FIT image signing/verify common code to support the ECDSA384 algorithm. For better convenience, the device tree for ECDSA public key storage is also revised by referring to RSA implementations.

After the FIT common code revision, the driver is implemented for AST2700 to leverage the Caliptra ECDSA384 signature verification.

These are verified by signed FIT images with the algorithm

"sha384,ecdsa384".

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

v2 change:
- revise the commit message of padding check removal for better

explanation

Quoted 3 lines

- remove redundant check in static function
- revise errno and error message as suggested by Simon
- collect Reviewed-by tags

Please rebase on top of current master, thanks.

I will rebase the patch and send v3. Thanks!

Regards,
Chiawei