Skip to contentSkip to conversation

Enable ECDSA FIT verification for stm32mp

PATCH New Alexandru Gagniuc 3 participants 17 messages Jan 11, 2021 – Feb 9, 2021

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

cover Enable ECDSA FIT verification for stm32mp

This series is Part II of the ECDSA saga. It applies on top of [1]:
* [PATCH v4 0/6] Add support for ECDSA image signing (with test)

I've designed the UCLASS_ECDSA such that it aligns with the ROM API of the stm32mp. Instead of splitting the verification into
(1) curve operations and (2) modular exponentiation, I've concatenated everything in a 'verify' step. It would be impossible to split the steps and use the stm32mp ROM for verification.

Should more granular control be required, this API could be extended at a later time. Until we have more hardware supporting ECDSA, this is purely speculative.

The ROM API of the stm32mp is passed in 'r0' when the FSBL is called. While we can save 'r0' in SPL, this series does not implement a mechanism to pass this to u-boot. Thus the ROM API, and ECDSA verification are only available for SPL. Although extending this to u-boot by adding the ROM address to the FDT blob, implementing and verifying this is beyond the scope of this series.

[1] https://lists.denx.de/pipermail/u-boot/2021-January/436935.html

Alexandru Gagniuc (5):
dm: crypto: Define UCLASS API for ECDSA signature verification
lib: ecdsa: Add skeleton to implement ecdsa verification in u-boot
lib: ecdsa: Implement signature verification for crypto_algo API
arm: stm32mp1: Implement ECDSA signature verification
Kconfig: FIT_SIGNATURE should not select RSA_VERIFY

 arch/arm/mach-stm32mp/Kconfig        |   9 ++
 arch/arm/mach-stm32mp/Makefile       |   1 +
 arch/arm/mach-stm32mp/ecdsa_romapi.c | 106 ++++++++++++++++++++++
 common/Kconfig.boot                  |   8 +-
 include/crypto/ecdsa-uclass.h        |  39 ++++++++
 include/dm/uclass-id.h               |   1 +
 include/image.h                      |  10 +--
 include/u-boot/rsa.h                 |   2 +-
 lib/Kconfig                          |   1 +
 lib/Makefile                         |   1 +
 lib/ecdsa/Kconfig                    |  23 +++++
 lib/ecdsa/Makefile                   |   1 +
 lib/ecdsa/ecdsa-verify.c             | 128 +++++++++++++++++++++++++++
 13 files changed, 320 insertions(+), 10 deletions(-)
 create mode 100644 arch/arm/mach-stm32mp/ecdsa_romapi.c
 create mode 100644 include/crypto/ecdsa-uclass.h
 create mode 100644 lib/ecdsa/Kconfig
 create mode 100644 lib/ecdsa/Makefile
 create mode 100644 lib/ecdsa/ecdsa-verify.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/5 dm: crypto: Define UCLASS API for ECDSA signature verification

Define a UCLASS API for verifying ECDSA signatures. Unlike UCLASS_MOD_EXP, which focuses strictly on modular exponentiation, the ECDSA class focuses on verification. This is done so that it better aligns with mach-specific implementations, such as stm32mp.

---
 include/crypto/ecdsa-uclass.h | 39 +++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h        |  1 +
 2 files changed, 40 insertions(+)
 create mode 100644 include/crypto/ecdsa-uclass.h
include/crypto/ecdsa-uclass.h new file +39 -0
new file mode 100644
index 0000000000..189843820a
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2020, Alexandru Gagniuc <[email protected]>
+ */
+
+#include <dm/device.h>
+
+/**
+ * struct ecdsa_public_key - ECDSA public key properties
+ *
+ * The struct has pointers to the (x, y) curve coordinates to an ECDSA public
+ * key, as well as the name of the ECDSA curve. The size of the key is inferred
+ * from the 'curve_name'
+ */
+struct ecdsa_public_key {
+	const char *curve_name;	/* Name of curve, e.g. "prime256v1" */
+	const void *x;		/* x coordinate of public key */
+	const void *y;		/* y coordinate of public key */
+	unsigned int size_bits;	/* key size in bits, derived from curve name */
+};
+
+struct ecdsa_ops {
+	/**
+	 * Verify signature of hash against given public key
+	 *
+	 * @dev:	ECDSA Device
+	 * @pubkey:	ECDSA public key
+	 * @hash:	Hash of binary image
+	 * @hash_len:	Length of hash in bytes
+	 * @signature:	Signature in a raw (R, S) point pair
+	 * @sig_len:	Length of signature in bytes
+	 *
+	 * This function verifies that the 'signature' of the given 'hash' was
+	 * signed by the private key corresponding to 'pubkey'.
+	 */
+	int (*verify)(struct udevice *dev, const struct ecdsa_public_key *pubkey,
+		      const void *hash, size_t hash_len,
+		      const void *signature, size_t sig_len);
+};
include/dm/uclass-id.h +1 -0
index e952a9967c..de4f5db086 100644
@@ -45,6 +45,7 @@ enum uclass_id {
 	UCLASS_DISPLAY,		/* Display (e.g. DisplayPort, HDMI) */
 	UCLASS_DSI_HOST,	/* Display Serial Interface host */
 	UCLASS_DMA,		/* Direct Memory Access */
+	UCLASS_ECDSA,		/* Elliptic curve cryptographic device */
 	UCLASS_EFI,		/* EFI managed devices */
 	UCLASS_ETH,		/* Ethernet device */
 	UCLASS_ETH_PHY,		/* Ethernet PHY device */
Signature · 1 line
2.26.2
#2 lore raw

PATCH 1/5 dm: crypto: Define UCLASS API for ECDSA signature verification

Hi Alexandru,

Quoted 6 lines · Alexandru Gagniuc

Define a UCLASS API for verifying ECDSA signatures. Unlike UCLASS_MOD_EXP, which focuses strictly on modular exponentiation, the ECDSA class focuses on verification. This is done so that it better aligns with mach-specific implementations, such as stm32mp.

Quoted 6 lines
---
 include/crypto/ecdsa-uclass.h | 39 +++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h        |  1 +
 2 files changed, 40 insertions(+)
 create mode 100644 include/crypto/ecdsa-uclass.h

This needs a test, as do all uclasses in U-Boot. If it isn't easy to implement the algorithm then I suppose you could fake it by using an easy algorithm like md5, but it does need a test.

Regards,
Simon

author
#3 lore raw

PATCH 1/5 dm: crypto: Define UCLASS API for ECDSA signature verification

Quoted 16 lines · Simon Glass

Hi Alexandru,

Quoted 6 lines · Alexandru Gagniuc

Define a UCLASS API for verifying ECDSA signatures. Unlike UCLASS_MOD_EXP, which focuses strictly on modular exponentiation, the ECDSA class focuses on verification. This is done so that it better aligns with mach-specific implementations, such as stm32mp.

Quoted 6 lines
---
  include/crypto/ecdsa-uclass.h | 39 +++++++++++++++++++++++++++++++++++
  include/dm/uclass-id.h        |  1 +
  2 files changed, 40 insertions(+)

create mode 100644 include/crypto/ecdsa-uclass.h

Quoted 3 lines

This needs a test, as do all uclasses in U-Boot. If it isn't easy to implement the algorithm then I suppose you could fake it by using an easy algorithm like md5, but it does need a test.

I agree. I couldn't find a test for UCLASS_MOD_EXP (for guidance), so I'm not sure where to even start.

Alex

Quoted 3 lines

Regards,
Simon

#4 lore raw

PATCH 1/5 dm: crypto: Define UCLASS API for ECDSA signature verification

Hi Alex,

Quoted 18 lines · Alex G.
Quoted 16 lines · Simon Glass

Hi Alexandru,

Quoted 12 lines · Alexandru Gagniuc

Define a UCLASS API for verifying ECDSA signatures. Unlike UCLASS_MOD_EXP, which focuses strictly on modular exponentiation, the ECDSA class focuses on verification. This is done so that it better aligns with mach-specific implementations, such as stm32mp.

---
  include/crypto/ecdsa-uclass.h | 39 +++++++++++++++++++++++++++++++++++
  include/dm/uclass-id.h        |  1 +
  2 files changed, 40 insertions(+)

create mode 100644 include/crypto/ecdsa-uclass.h

Quoted 6 lines
Quoted 3 lines

This needs a test, as do all uclasses in U-Boot. If it isn't easy to implement the algorithm then I suppose you could fake it by using an easy algorithm like md5, but it does need a test.

I agree. I couldn't find a test for UCLASS_MOD_EXP (for guidance), so I'm not sure where to even start.

How about dm_test_rng_read()? That is pretty simple and does a few basic things.

Re UCLASS_MOD_EXP this is tested by the vboot tests. It should really have a simple unit test too, though. This is an example of how to add a software implementation of a hardware algorithm. See mod_exp_sw.c

Regards,
Simon

#5 lore raw

PATCH 2/5 lib: ecdsa: Add skeleton to implement ecdsa verification in u-boot

In reply to Alexandru Gagniuc

Prepare the source tree for accepting implementations of the ECDSA algorithm. This patch deals with the boring aspects of Makefiles and Kconfig files.

---
 include/image.h          | 10 +++++-----
 include/u-boot/rsa.h     |  2 +-
 lib/Kconfig              |  1 +
 lib/Makefile             |  1 +
 lib/ecdsa/Kconfig        | 23 +++++++++++++++++++++++
 lib/ecdsa/Makefile       |  1 +
 lib/ecdsa/ecdsa-verify.c | 13 +++++++++++++
 7 files changed, 45 insertions(+), 6 deletions(-)
 create mode 100644 lib/ecdsa/Kconfig
 create mode 100644 lib/ecdsa/Makefile
 create mode 100644 lib/ecdsa/ecdsa-verify.c
include/image.h +5 -5
index 6628173dca..1d70ba0ece 100644
@@ -1198,20 +1198,20 @@ int calculate_hash(const void *data, int data_len, const char *algo,
 #if defined(USE_HOSTCC)
 # if defined(CONFIG_FIT_SIGNATURE)
 #  define IMAGE_ENABLE_SIGN	1
-#  define IMAGE_ENABLE_VERIFY	1
+#  define IMAGE_ENABLE_VERIFY_RSA	1
 #  define IMAGE_ENABLE_VERIFY_ECDSA	1
 #  define FIT_IMAGE_ENABLE_VERIFY	1
 #  include <openssl/evp.h>
 # else
 #  define IMAGE_ENABLE_SIGN	0
-#  define IMAGE_ENABLE_VERIFY	0
+#  define IMAGE_ENABLE_VERIFY_RSA	0
 # define IMAGE_ENABLE_VERIFY_ECDSA	0
 #  define FIT_IMAGE_ENABLE_VERIFY	0
 # endif
 #else
 # define IMAGE_ENABLE_SIGN	0
-# define IMAGE_ENABLE_VERIFY		CONFIG_IS_ENABLED(RSA_VERIFY)
-# define IMAGE_ENABLE_VERIFY_ECDSA	0
+# define IMAGE_ENABLE_VERIFY_RSA	CONFIG_IS_ENABLED(RSA_VERIFY)
+# define IMAGE_ENABLE_VERIFY_ECDSA	CONFIG_IS_ENABLED(ECDSA_VERIFY)
 # define FIT_IMAGE_ENABLE_VERIFY	CONFIG_IS_ENABLED(FIT_SIGNATURE)
 #endif
 
@@ -1260,7 +1260,7 @@ struct image_region {
 	int size;
 };
 
-#if IMAGE_ENABLE_VERIFY
+#if FIT_IMAGE_ENABLE_VERIFY
 # include <u-boot/hash-checksum.h>
 #endif
 struct checksum_algo {
include/u-boot/rsa.h +1 -1
index bed1c097c2..eb258fca4c 100644
@@ -81,7 +81,7 @@ static inline int rsa_add_verify_data(struct image_sign_info *info,
 }
 #endif
 
-#if IMAGE_ENABLE_VERIFY
+#if IMAGE_ENABLE_VERIFY_RSA
 /**
  * rsa_verify_hash() - Verify a signature against a hash
  *
lib/Kconfig +1 -0
index 7673d2e4e0..e2cb846fc0 100644
@@ -292,6 +292,7 @@ config AES
 	  supported by the algorithm but only a 128-bit key is supported at
 	  present.
 
+source lib/ecdsa/Kconfig
 source lib/rsa/Kconfig
 source lib/crypto/Kconfig
 
lib/Makefile +1 -0
index cf64188ba5..ab86be2678 100644
@@ -59,6 +59,7 @@ endif
 
 obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi/
 obj-$(CONFIG_$(SPL_)MD5) += md5.o
+obj-$(CONFIG_ECDSA) += ecdsa/
 obj-$(CONFIG_$(SPL_)RSA) += rsa/
 obj-$(CONFIG_FIT_SIGNATURE) += hash-checksum.o
 obj-$(CONFIG_SHA1) += sha1.o
lib/ecdsa/Kconfig new file +23 -0
new file mode 100644
index 0000000000..1244d6b6ea
@@ -0,0 +1,23 @@
+config ECDSA
+	bool "Enable ECDSA support"
+	depends on DM
+	help
+	  This enables the ECDSA algorithm for FIT image verification in U-Boot.
+	  See doc/uImage.FIT/signature.txt for more details.
+	  The ECDSA algorithm is implemented using the driver model. So
+	  CONFIG_DM is required by this library.
+	  ECDSA is enabled for mkimage regardless of this  option.
+
+if ECDSA
+
+config ECDSA_VERIFY
+	bool "Enable ECDSA verification support in U-Boot."
+	help
+	  Allow ECDSA signatures to be recognized and verified in U-Boot.
+
+config SPL_ECDSA_VERIFY
+	bool "Enable ECDSA verification support in SPL"
+	help
+	  Allow ECDSA signatures to be recognized and verified in SPL.
+
+endif
lib/ecdsa/Makefile new file +1 -0
new file mode 100644
index 0000000000..771d6d3135
@@ -0,0 +1 @@
+obj-$(CONFIG_$(SPL_)ECDSA_VERIFY) += ecdsa-verify.o
lib/ecdsa/ecdsa-verify.c new file +13 -0
new file mode 100644
index 0000000000..d2e6a40f4a
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2020, Alexandru Gagniuc <[email protected]>
+ */
+
+#include <u-boot/ecdsa.h>
+
+int ecdsa_verify(struct image_sign_info *info,
+		 const struct image_region region[], int region_count,
+		 uint8_t *sig, uint sig_len)
+{
+	return -EOPNOTSUPP;
+}
Signature · 1 line
2.26.2
#6 lore raw

PATCH 2/5 lib: ecdsa: Add skeleton to implement ecdsa verification in u-boot

Hi,

Quoted 34 lines · Alexandru Gagniuc

Prepare the source tree for accepting implementations of the ECDSA algorithm. This patch deals with the boring aspects of Makefiles and Kconfig files.

---
  include/image.h          | 10 +++++-----
  include/u-boot/rsa.h     |  2 +-
  lib/Kconfig              |  1 +
  lib/Makefile             |  1 +
  lib/ecdsa/Kconfig        | 23 +++++++++++++++++++++++
  lib/ecdsa/Makefile       |  1 +
  lib/ecdsa/ecdsa-verify.c | 13 +++++++++++++
  7 files changed, 45 insertions(+), 6 deletions(-)

create mode 100644 lib/ecdsa/Kconfig
create mode 100644 lib/ecdsa/Makefile
create mode 100644 lib/ecdsa/ecdsa-verify.c

include/image.h +1 -2
index 6628173dca..1d70ba0ece 100644
@@ -1198,20 +1198,20 @@ int calculate_hash(const void *data, int data_len, const char *algo,
  #if defined(USE_HOSTCC)
  # if defined(CONFIG_FIT_SIGNATURE)
  #  define IMAGE_ENABLE_SIGN	1
-#  define IMAGE_ENABLE_VERIFY	1
+#  define IMAGE_ENABLE_VERIFY_RSA	1
  #  define IMAGE_ENABLE_VERIFY_ECDSA	1
  #  define FIT_IMAGE_ENABLE_VERIFY	1
  #  include <openssl/evp.h>
  # else
  #  define IMAGE_ENABLE_SIGN	0
-#  define IMAGE_ENABLE_VERIFY	0

include/image.h int calculate_hash(const void *data, int data_len, const char *algo, · line 1214

Quoted 10 lines
include/image.h +3 -2
+#  define IMAGE_ENABLE_VERIFY_RSA	0
  # define IMAGE_ENABLE_VERIFY_ECDSA	0
  #  define FIT_IMAGE_ENABLE_VERIFY	0
  # endif
  #else
  # define IMAGE_ENABLE_SIGN	0
-# define IMAGE_ENABLE_VERIFY		CONFIG_IS_ENABLED(RSA_VERIFY)
-# define IMAGE_ENABLE_VERIFY_ECDSA	0
+# define IMAGE_ENABLE_VERIFY_RSA	CONFIG_IS_ENABLED(RSA_VERIFY)
+# define IMAGE_ENABLE_VERIFY_ECDSA	CONFIG_IS_ENABLED(ECDSA_VERIFY)

here you are using CONFIG_IS_ENABLED.

This macro imply to test CONFIG_ECDSA_VERIFY or CONFIG_SPL_ECDSA_VERIFY (for SPL build)

=> but CONFIG_SPL_ECDSA_VERIFY is missing, I think you need to add it, as RSA

Quoted 42 lines
include/image.h +1 -1
  # define FIT_IMAGE_ENABLE_VERIFY	CONFIG_IS_ENABLED(FIT_SIGNATURE)
  #endif
 
@@ -1260,7 +1260,7 @@ struct image_region {
  	int size;
  };
 
-#if IMAGE_ENABLE_VERIFY
+#if FIT_IMAGE_ENABLE_VERIFY
  # include <u-boot/hash-checksum.h>
  #endif
  struct checksum_algo {
include/u-boot/rsa.h +1 -1
index bed1c097c2..eb258fca4c 100644
@@ -81,7 +81,7 @@ static inline int rsa_add_verify_data(struct image_sign_info *info,
  }
  #endif
 
-#if IMAGE_ENABLE_VERIFY
+#if IMAGE_ENABLE_VERIFY_RSA
  /**
   * rsa_verify_hash() - Verify a signature against a hash
   *
lib/Kconfig +1 -0
index 7673d2e4e0..e2cb846fc0 100644
@@ -292,6 +292,7 @@ config AES
  	  supported by the algorithm but only a 128-bit key is supported at
  	  present.
 
+source lib/ecdsa/Kconfig
  source lib/rsa/Kconfig
  source lib/crypto/Kconfig
 
lib/Makefile +0 -0
index cf64188ba5..ab86be2678 100644

lib/Makefile endif · line 62

Quoted 4 lines
lib/Makefile +1 -0
@@ -59,6 +59,7 @@ endif
 
  obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi/
  obj-$(CONFIG_$(SPL_)MD5) += md5.o
+obj-$(CONFIG_ECDSA) += ecdsa/

obj-$(CONFIG_$(SPL_)ECDSA) += ecdsa/

Quoted 11 lines
lib/Makefile +0 -0
  obj-$(CONFIG_$(SPL_)RSA) += rsa/
  obj-$(CONFIG_FIT_SIGNATURE) += hash-checksum.o
  obj-$(CONFIG_SHA1) += sha1.o
lib/ecdsa/Kconfig new file +2 -0
new file mode 100644
index 0000000000..1244d6b6ea
@@ -0,0 +1,23 @@
+config ECDSA
+	bool "Enable ECDSA support"

lib/ecdsa/Kconfig line 12

Quoted 10 lines
lib/ecdsa/Kconfig new file +10 -0
+	depends on DM
+	help
+	  This enables the ECDSA algorithm for FIT image verification in U-Boot.
+	  See doc/uImage.FIT/signature.txt for more details.
+	  The ECDSA algorithm is implemented using the driver model. So
+	  CONFIG_DM is required by this library.
+	  ECDSA is enabled for mkimage regardless of this  option.
+
+if ECDSA
+

Add CONFIG_SPL_ECDSA to select independently support in SPL et/or in U-Boot

as it is done for RSA

+ config SPL_ECDSA
+ bool "Use ECDSA library within in SPL"

lib/ecdsa/Kconfig line 14

Quoted 2 lines
lib/ecdsa/Kconfig new file +2 -0
+config ECDSA_VERIFY
+	bool "Enable ECDSA verification support in U-Boot."

+ select SPL_ECDSA

Quoted 25 lines
lib/ecdsa/Kconfig new file +9 -0
+	help
+	  Allow ECDSA signatures to be recognized and verified in U-Boot.
+
+config SPL_ECDSA_VERIFY
+	bool "Enable ECDSA verification support in SPL"
+	help
+	  Allow ECDSA signatures to be recognized and verified in SPL.
+
+endif
lib/ecdsa/Makefile new file +1 -0
new file mode 100644
index 0000000000..771d6d3135
@@ -0,0 +1 @@
+obj-$(CONFIG_$(SPL_)ECDSA_VERIFY) += ecdsa-verify.o
lib/ecdsa/ecdsa-verify.c new file +3 -0
new file mode 100644
index 0000000000..d2e6a40f4a
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2020, Alexandru Gagniuc<[email protected]>

lib/ecdsa/ecdsa-verify.c line 13

Quoted 10 lines
lib/ecdsa/ecdsa-verify.c new file +10 -0
+ */
+
+#include <u-boot/ecdsa.h>
+
+int ecdsa_verify(struct image_sign_info *info,
+		 const struct image_region region[], int region_count,
+		 uint8_t *sig, uint sig_len)
+{
+	return -EOPNOTSUPP;
+}

Regards,

Patrick

author
#7 lore raw

PATCH 2/5 lib: ecdsa: Add skeleton to implement ecdsa verification in u-boot

Hi Patrick,

Quoted 51 lines · Patrick DELAUNAY

Hi,

Quoted 41 lines · Alexandru Gagniuc

Prepare the source tree for accepting implementations of the ECDSA algorithm. This patch deals with the boring aspects of Makefiles and Kconfig files.

---

? include/image.h????????? | 10 +++++-----
? include/u-boot/rsa.h???? |? 2 +-
? lib/Kconfig????????????? |? 1 +
? lib/Makefile???????????? |? 1 +
? lib/ecdsa/Kconfig??????? | 23 +++++++++++++++++++++++
? lib/ecdsa/Makefile?????? |? 1 +
? lib/ecdsa/ecdsa-verify.c | 13 +++++++++++++

? 7 files changed, 45 insertions(+), 6 deletions(-) ? create mode 100644 lib/ecdsa/Kconfig
? create mode 100644 lib/ecdsa/Makefile
? create mode 100644 lib/ecdsa/ecdsa-verify.c

include/image.h +0 -0
index 6628173dca..1d70ba0ece 100644
@@ -1198,20 +1198,20 @@ int calculate_hash(const void *data, int 
 data_len, const char *algo,
 ? #if defined(USE_HOSTCC)
 ? # if defined(CONFIG_FIT_SIGNATURE)

? #? define IMAGE_ENABLE_SIGN??? 1

include/image.h +1 -1
-#? define IMAGE_ENABLE_VERIFY??? 1
+#? define IMAGE_ENABLE_VERIFY_RSA??? 1

? #? define IMAGE_ENABLE_VERIFY_ECDSA??? 1
? #? define FIT_IMAGE_ENABLE_VERIFY??? 1
? #? include <openssl/evp.h>
? # else
? #? define IMAGE_ENABLE_SIGN??? 0

include/image.h +1 -1
-#? define IMAGE_ENABLE_VERIFY??? 0
+#? define IMAGE_ENABLE_VERIFY_RSA??? 0

? # define IMAGE_ENABLE_VERIFY_ECDSA??? 0
? #? define FIT_IMAGE_ENABLE_VERIFY??? 0
? # endif
? #else
? # define IMAGE_ENABLE_SIGN??? 0

include/image.h

Quoted 4 lines
include/image.h +2 -2
-# define IMAGE_ENABLE_VERIFY??????? CONFIG_IS_ENABLED(RSA_VERIFY)
-# define IMAGE_ENABLE_VERIFY_ECDSA??? 0
+# define IMAGE_ENABLE_VERIFY_RSA??? CONFIG_IS_ENABLED(RSA_VERIFY)
+# define IMAGE_ENABLE_VERIFY_ECDSA??? CONFIG_IS_ENABLED(ECDSA_VERIFY)

here you are using CONFIG_IS_ENABLED.

Quoted 5 lines

This macro imply to test CONFIG_ECDSA_VERIFY or CONFIG_SPL_ECDSA_VERIFY (for SPL build)

=> but CONFIG_SPL_ECDSA_VERIFY is missing, I think you need to add it, as RSA

This patch adds both "config ECDSA_VERIFY" and "config SPL_ECDSA_VERIFY" see @lib/ecdsa/Kconfig. I believe this achieves what you need.

[snip]

Quoted 10 lines
Quoted 8 lines
lib/Makefile +0 -0
index cf64188ba5..ab86be2678 100644
@@ -59,6 +59,7 @@ endif

? obj-$(CONFIG_$(SPL_)ACPIGEN) += acpi/
? obj-$(CONFIG_$(SPL_)MD5) += md5.o
+obj-$(CONFIG_ECDSA) += ecdsa/

obj-$(CONFIG_$(SPL_)ECDSA) += ecdsa/

The intent here is to use CONFIG_ECDSA to denote ECDSA support. CONFIG_ECDSA_VERIFY and CONFIG_SPL_ECDSA_VERIFY are used to enable the code in u-boot and SPL respectively. Only verification is supported on the target, so these are the only switches that enable or disable code.

Quoted 27 lines
Quoted 20 lines

? obj-$(CONFIG_$(SPL_)RSA) += rsa/
? obj-$(CONFIG_FIT_SIGNATURE) += hash-checksum.o
? obj-$(CONFIG_SHA1) += sha1.o

lib/ecdsa/Kconfig new file +5 -0
new file mode 100644
index 0000000000..1244d6b6ea
@@ -0,0 +1,23 @@
+config ECDSA
+??? bool "Enable ECDSA support"
+??? depends on DM
+??? help
+????? This enables the ECDSA algorithm for FIT image verification in 

U-Boot.
+????? See doc/uImage.FIT/signature.txt for more details. +????? The ECDSA algorithm is implemented using the driver model. So +????? CONFIG_DM is required by this library.
+????? ECDSA is enabled for mkimage regardless of this? option.

lib/ecdsa/Kconfig line 12

Quoted 3 lines
lib/ecdsa/Kconfig new file +3 -0
+
+if ECDSA
+

Add CONFIG_SPL_ECDSA to select independently support in SPL et/or in U-Boot as it is done for RSA

Quoted 3 lines

+ config SPL_ECDSA
+??? bool "Use ECDSA library within in SPL"

I though about an SPL_ECDSA kconfig. As mentioned above, we have independent switches to enable the code for u-boot/SPL. We can enable ECDSA support in u-boot, SPL, neither or both. What would this switch add?

Quoted 8 lines
Quoted 3 lines

+config ECDSA_VERIFY
+??? bool "Enable ECDSA verification support in U-Boot."

+ select SPL_ECDSA

Quoted 7 lines

lib/ecdsa/Kconfig

Quoted 7 lines

+??? help
+????? Allow ECDSA signatures to be recognized and verified in U-Boot.

lib/ecdsa/Kconfig new file +5 -0
+
+config SPL_ECDSA_VERIFY
+??? bool "Enable ECDSA verification support in SPL"
+??? help
+????? Allow ECDSA signatures to be recognized and verified in SPL.

This is the switch for SPL (@mentioned earlier).

Alex

#8 lore raw

PATCH 3/5 lib: ecdsa: Implement signature verification for crypto_algo API

In reply to Alexandru Gagniuc

Implement the crypto_algo .verify() function for ecdsa256. Because it backends on UCLASS_ECDSA, this change is focused on parsing the keys from devicetree and passing this information to the specific UCLASS driver.

---
 lib/ecdsa/ecdsa-verify.c | 117 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 116 insertions(+), 1 deletion(-)
lib/ecdsa/ecdsa-verify.c +116 -1
index d2e6a40f4a..d84f6eb093 100644
@@ -1,13 +1,128 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
+ * ECDSA signature verification for u-boot
+ *
+ * This implements the firmware-side wrapper for ECDSA verification. It bridges
+ * the struct crypto_algo API to the ECDSA uclass implementations.
+ *
  * Copyright (c) 2020, Alexandru Gagniuc <[email protected]>
  */
 
+#include <dm/uclass.h>
 #include <u-boot/ecdsa.h>
+#include <crypto/ecdsa-uclass.h>
+
+/*
+ * Derive size of an ECDSA key from the curve name
+ *
+ * While it's possible to extract the key size by using string manipulation,
+ * use a list of known curves for the time being.
+ */
+static int ecdsa_key_size(const char *curve_name)
+{
+	if (!strcmp(curve_name, "prime256v1"))
+		return 256;
+	else
+		return 0;
+}
+
+static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
+{
+	int x_len, y_len;
+
+	key->curve_name = fdt_getprop(fdt, node, "ecdsa,curve", NULL);
+	key->size_bits = ecdsa_key_size(key->curve_name);
+	if (key->size_bits == 0) {
+		debug("Unknown ECDSA curve '%s'", key->curve_name);
+		return -EINVAL;
+	}
+
+	key->x = fdt_getprop(fdt, node, "ecdsa,x-point", &x_len);
+	key->y = fdt_getprop(fdt, node, "ecdsa,y-point", &y_len);
+
+	if (!key->x || !key->y)
+		return -EINVAL;
+
+	if (x_len != (key->size_bits / 8) || y_len != (key->size_bits / 8)) {
+		printf("%s: node=%d, curve@%p x@%p+%i y@%p+%i\n", __func__,
+		       node, key->curve_name, key->x, x_len, key->y, y_len);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int ecdsa_verify_hash(struct udevice *dev,
+			     const struct image_sign_info *info,
+			     const void *hash, const void *sig, uint sig_len)
+{
+	const struct ecdsa_ops *ops = device_get_ops(dev);
+	const struct checksum_algo *algo = info->checksum;
+	struct ecdsa_public_key key;
+	int sig_node, key_node, ret;
+
+	if (!ops || !ops->verify)
+		return -ENODEV;
+
+	if (info->required_keynode > 0) {
+		ret = fdt_get_key(&key, info->fdt_blob, info->required_keynode);
+		if (ret < 0)
+			return ret;
+
+		return ops->verify(dev, &key, hash, algo->checksum_len,
+				   sig, sig_len);
+	}
+
+	sig_node = fdt_subnode_offset(info->fdt_blob, 0, FIT_SIG_NODENAME);
+	if (sig_node < 0)
+		return -ENOENT;
+
+	/* Try all possible keys under the "/signature" node */
+	fdt_for_each_subnode(key_node, info->fdt_blob, sig_node) {
+		ret = fdt_get_key(&key, info->fdt_blob, key_node);
+		if (ret < 0)
+			continue;
+
+		ret = ops->verify(dev, &key, hash, algo->checksum_len,
+				  sig, sig_len);
+
+		/* On success, don't worry about remaining keys */
+		if (ret == 0)
+			return 0;
+	}
+
+	return -EPERM;
+}
 
 int ecdsa_verify(struct image_sign_info *info,
 		 const struct image_region region[], int region_count,
 		 uint8_t *sig, uint sig_len)
 {
-	return -EOPNOTSUPP;
+	const struct checksum_algo *algo = info->checksum;
+	uint8_t hash[algo->checksum_len];
+	struct udevice *dev;
+	int ret;
+
+	ret = uclass_first_device(UCLASS_ECDSA, &dev);
+	if (ret) {
+		debug("ECDSA: Could not find ECDSA implementation: %d\n", ret);
+		return ret;
+	}
+
+	ret = algo->calculate(algo->name, region, region_count, hash);
+	if (ret < 0)
+		return -EINVAL;
+
+	return ecdsa_verify_hash(dev, info, hash, sig, sig_len);
 }
+
+/*
+ * uclass definition for ECDSA API
+ *
+ * We don't implement any wrappers around ecdsa_ops->verify() because it's
+ * trivial to call ops->verify().
+ */
+UCLASS_DRIVER(ecdsa) = {
+	.id		= UCLASS_ECDSA,
+	.name		= "ecdsa_verifier",
+};
Signature · 1 line
2.26.2
#9 lore raw

PATCH 3/5 lib: ecdsa: Implement signature verification for crypto_algo API

Quoted 10 lines · Alexandru Gagniuc

Implement the crypto_algo .verify() function for ecdsa256. Because it backends on UCLASS_ECDSA, this change is focused on parsing the keys from devicetree and passing this information to the specific UCLASS driver.

---
 lib/ecdsa/ecdsa-verify.c | 117 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 116 insertions(+), 1 deletion(-)
#10 lore raw

PATCH 3/5 lib: ecdsa: Implement signature verification for crypto_algo API

In reply to Alexandru Gagniuc

Hi,

Quoted 15 lines · Alexandru Gagniuc

Implement the crypto_algo .verify() function for ecdsa256. Because it backends on UCLASS_ECDSA, this change is focused on parsing the keys from devicetree and passing this information to the specific UCLASS driver.

---
  lib/ecdsa/ecdsa-verify.c | 117 ++++++++++++++++++++++++++++++++++++++-
  1 file changed, 116 insertions(+), 1 deletion(-)
lib/ecdsa/ecdsa-verify.c +0 -0
index d2e6a40f4a..d84f6eb093 100644

lib/ecdsa/ecdsa-verify.c line 10

Quoted 10 lines
lib/ecdsa/ecdsa-verify.c +5 -0
@@ -1,13 +1,128 @@
  // SPDX-License-Identifier: GPL-2.0+
  /*
+ * ECDSA signature verification for u-boot
+ *
+ * This implements the firmware-side wrapper for ECDSA verification. It bridges
+ * the struct crypto_algo API to the ECDSA uclass implementations.
+ *
   * Copyright (c) 2020, Alexandru Gagniuc<[email protected]>
   */
 

http://www.denx.de/wiki/U-Boot/CodingStyle #Include files

#include <crypto/ecdsa-uclass.h>

it is normally the first in alphabetic order of directory

Quoted 8 lines
lib/ecdsa/ecdsa-verify.c +7 -0
+#include <dm/uclass.h>
  #include <u-boot/ecdsa.h>
+#include <crypto/ecdsa-uclass.h>
+
+/*
+ * Derive size of an ECDSA key from the curve name
+ *
+ * While it's possible to extract the key size by using string manipulation,

lib/ecdsa/ecdsa-verify.c line 28

Quoted 10 lines
lib/ecdsa/ecdsa-verify.c +10 -0
+ * use a list of known curves for the time being.
+ */
+static int ecdsa_key_size(const char *curve_name)
+{
+	if (!strcmp(curve_name, "prime256v1"))
+		return 256;
+	else
+		return 0;
+}
+

To prepare the future can you parse a array of supported curves with associated ID

used as parameter of ECDSA parameter = enum ECDSA_CURVES

for example: char * name, int size, enum ECDSA_CURVES

const [] = {
{"prime256v1", 256, ECDSA_PRIME256V1 },

}

Quoted 35 lines
lib/ecdsa/ecdsa-verify.c +35 -0
+static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
+{
+	int x_len, y_len;
+
+	key->curve_name = fdt_getprop(fdt, node, "ecdsa,curve", NULL);
+	key->size_bits = ecdsa_key_size(key->curve_name);
+	if (key->size_bits == 0) {
+		debug("Unknown ECDSA curve '%s'", key->curve_name);
+		return -EINVAL;
+	}
+
+	key->x = fdt_getprop(fdt, node, "ecdsa,x-point", &x_len);
+	key->y = fdt_getprop(fdt, node, "ecdsa,y-point", &y_len);
+
+	if (!key->x || !key->y)
+		return -EINVAL;
+
+	if (x_len != (key->size_bits / 8) || y_len != (key->size_bits / 8)) {
+		printf("%s: node=%d, curve@%p x@%p+%i y@%p+%i\n", __func__,
+		       node, key->curve_name, key->x, x_len, key->y, y_len);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int ecdsa_verify_hash(struct udevice *dev,
+			     const struct image_sign_info *info,
+			     const void *hash, const void *sig, uint sig_len)
+{
+	const struct ecdsa_ops *ops = device_get_ops(dev);
+	const struct checksum_algo *algo = info->checksum;
+	struct ecdsa_public_key key;
+	int sig_node, key_node, ret;
+

lib/ecdsa/ecdsa-verify.c line 73

Quoted 10 lines
lib/ecdsa/ecdsa-verify.c +10 -0
+	if (!ops || !ops->verify)
+		return -ENODEV;
+
+	if (info->required_keynode > 0) {
+		ret = fdt_get_key(&key, info->fdt_blob, info->required_keynode);
+		if (ret < 0)
+			return ret;
+
+		return ops->verify(dev, &key, hash, algo->checksum_len,
+				   sig, sig_len);

Need to indicate the used curve here as parameter of the verify opts ?

Quoted 7 lines
lib/ecdsa/ecdsa-verify.c +7 -0
+	}
+
+	sig_node = fdt_subnode_offset(info->fdt_blob, 0, FIT_SIG_NODENAME);
+	if (sig_node < 0)
+		return -ENOENT;
+
+	/* Try all possible keys under the "/signature" node */

lib/ecdsa/ecdsa-verify.c line 90

Quoted 10 lines
lib/ecdsa/ecdsa-verify.c +10 -0
+	fdt_for_each_subnode(key_node, info->fdt_blob, sig_node) {
+		ret = fdt_get_key(&key, info->fdt_blob, key_node);
+		if (ret < 0)
+			continue;
+
+		ret = ops->verify(dev, &key, hash, algo->checksum_len,
+				  sig, sig_len);
+
+		/* On success, don't worry about remaining keys */
+		if (ret == 0)

issue raised by chekpatch I think

if (!ret)

Quoted 29 lines
lib/ecdsa/ecdsa-verify.c +22 -1
+			return 0;
+	}
+
+	return -EPERM;
+}
 
  int ecdsa_verify(struct image_sign_info *info,
  		 const struct image_region region[], int region_count,
  		 uint8_t *sig, uint sig_len)
  {
-	return -EOPNOTSUPP;
+	const struct checksum_algo *algo = info->checksum;
+	uint8_t hash[algo->checksum_len];
+	struct udevice *dev;
+	int ret;
+
+	ret = uclass_first_device(UCLASS_ECDSA, &dev);
+	if (ret) {
+		debug("ECDSA: Could not find ECDSA implementation: %d\n", ret);
+		return ret;
+	}
+
+	ret = algo->calculate(algo->name, region, region_count, hash);
+	if (ret < 0)
+		return -EINVAL;
+
+	return ecdsa_verify_hash(dev, info, hash, sig, sig_len);
  }
+

lib/ecdsa/ecdsa-verify.c line 128

Quoted 10 lines
lib/ecdsa/ecdsa-verify.c +10 -0
+/*
+ * uclass definition for ECDSA API
+ *
+ * We don't implement any wrappers around ecdsa_ops->verify() because it's
+ * trivial to call ops->verify().
+ */
+UCLASS_DRIVER(ecdsa) = {
+	.id		= UCLASS_ECDSA,
+	.name		= "ecdsa_verifier",
+};

Regards

Patrick

author
#11 lore raw

PATCH 3/5 lib: ecdsa: Implement signature verification for crypto_algo API

Quoted 1 line · Patrick DELAUNAY

Hi,

[snip]

Quoted 18 lines
Quoted 7 lines
lib/ecdsa/ecdsa-verify.c +0 -0
index d2e6a40f4a..d84f6eb093 100644
@@ -1,13 +1,128 @@

? // SPDX-License-Identifier: GPL-2.0+
? /*

Quoted 8 lines

+ * ECDSA signature verification for u-boot
+ *
+ * This implements the firmware-side wrapper for ECDSA verification. It bridges
+ * the struct crypto_algo API to the ECDSA uclass implementations.
+ *
?? * Copyright (c) 2020, Alexandru Gagniuc<[email protected]> ?? */

http://www.denx.de/wiki/U-Boot/CodingStyle #Include files

Quoted 3 lines

#include <crypto/ecdsa-uclass.h>

it is normally the first in alphabetic order of directory

Thank your for catching that. I will have it fixed in the next iteration of this series.

Quoted 24 lines
Quoted 11 lines

+#include <dm/uclass.h>
? #include <u-boot/ecdsa.h>

lib/ecdsa/ecdsa-verify.c +6 -0
+#include <crypto/ecdsa-uclass.h>
+
+/*
+ * Derive size of an ECDSA key from the curve name
+ *
+ * While it's possible to extract the key size by using string 

manipulation,
+ * use a list of known curves for the time being.
+ */

lib/ecdsa/ecdsa-verify.c line 28

Quoted 8 lines
lib/ecdsa/ecdsa-verify.c +8 -0
+static int ecdsa_key_size(const char *curve_name)
+{
+??? if (!strcmp(curve_name, "prime256v1"))
+??????? return 256;
+??? else
+??????? return 0;
+}
+

To prepare the future can you parse a array of supported curves with associated ID

Quoted 8 lines

used as parameter of ECDSA parameter = enum ECDSA_CURVES

for example: char * name, int size, enum ECDSA_CURVES

const [] = {
{"prime256v1", 256, ECDSA_PRIME256V1 },

}

That is possible. If I were to have a longer list of curve names, I change things to extract the key length from the name itself. So instead of running strncmp() of N keyname strings, I would extract the digits from 'curve_name'.

I chose not to do that here because I want this patch to be didactic. That is, I'm trying to achieve the goal clearly, with the lowest number of lines of code.

[snip]

Quoted 14 lines
Quoted 14 lines
lib/ecdsa/ecdsa-verify.c +14 -0
+static int ecdsa_verify_hash(struct udevice *dev,
+???????????????? const struct image_sign_info *info,
+???????????????? const void *hash, const void *sig, uint sig_len)
+{
+??? const struct ecdsa_ops *ops = device_get_ops(dev);
+??? const struct checksum_algo *algo = info->checksum;
+??? struct ecdsa_public_key key;
+??? int sig_node, key_node, ret;
+
+??? if (!ops || !ops->verify)
+??????? return -ENODEV;
+
+??? if (info->required_keynode > 0) {
+??????? ret = fdt_get_key(&key, info->fdt_blob, info->required_keynode);
Quoted 8 lines
Quoted 5 lines

+??????? if (ret < 0)
+??????????? return ret;
+
+??????? return ops->verify(dev, &key, hash, algo->checksum_len, +?????????????????? sig, sig_len);

Need to indicate the used curve here as parameter of the verify opts ?

The curve name is part of the key (struct ecdsa_public_key).

[snip]

Quoted 10 lines
Quoted 5 lines

+??????? ret = ops->verify(dev, &key, hash, algo->checksum_len, +????????????????? sig, sig_len);
+
+??????? /* On success, don't worry about remaining keys */ +??????? if (ret == 0)

issue raised by chekpatch I think

if (!ret)

Oh! I'll get this fixed. Thanks!

Alex

#12 lore raw

PATCH 4/5 arm: stm32mp1: Implement ECDSA signature verification

In reply to Alexandru Gagniuc

The STM32MP ROM provides several service. One of them is the ability to verify ecdsa256 signatures. Hook the ROM API into the ECDSA uclass.

---
 arch/arm/mach-stm32mp/Kconfig        |   9 +++
 arch/arm/mach-stm32mp/Makefile       |   1 +
 arch/arm/mach-stm32mp/ecdsa_romapi.c | 106 +++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 arch/arm/mach-stm32mp/ecdsa_romapi.c
arch/arm/mach-stm32mp/Kconfig +9 -0
index f538d7cb83..f1e00929fd 100644
@@ -121,6 +121,15 @@ config STM32_ETZPC
 	help
 	  Say y to enable STM32 Extended TrustZone Protection
 
+config STM32_ECDSA_VERIFY
+	bool "STM32 ECDSA verification via the ROM API"
+	depends on SPL_ECDSA_VERIFY
+	default y
+	help
+	  Say y to enable the uclass driver for ECDSA verification using the
+	  ROM API provided on STM32MP.
+	  The ROM API is only available during SPL for now.
+
 config CMD_STM32PROG
 	bool "command stm32prog for STM32CudeProgrammer"
 	select DFU
arch/arm/mach-stm32mp/Makefile +1 -0
index c8aa24d489..c03fedb486 100644
@@ -10,6 +10,7 @@ obj-y += bsec.o
 
 ifdef CONFIG_SPL_BUILD
 obj-y += spl.o
+obj-$(CONFIG_STM32_ECDSA_VERIFY) += ecdsa_romapi.o
 else
 obj-$(CONFIG_CMD_STM32PROG) += cmd_stm32prog/
 obj-$(CONFIG_CMD_STM32KEY) += cmd_stm32key.o
arch/arm/mach-stm32mp/ecdsa_romapi.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.26.2
#13 lore raw

PATCH 5/5 Kconfig: FIT_SIGNATURE should not select RSA_VERIFY

In reply to Alexandru Gagniuc

FIT signatures can now be implemented with ECDSA. The assumption that all FIT images are signed with RSA is no longer valid. Thus, instead of 'select'ing RSA, only 'imply' it. This doesn't change the defaults, but allows one to explicitly disable RSA support.

---
 common/Kconfig.boot | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
common/Kconfig.boot +4 -4
index 3f6d9c1a25..280476698d 100644
@@ -67,8 +67,8 @@ config FIT_SIGNATURE
 	bool "Enable signature verification of FIT uImages"
 	depends on DM
 	select HASH
-	select RSA
-	select RSA_VERIFY
+	imply RSA
+	imply RSA_VERIFY
 	select IMAGE_SIGN_INFO
 	help
 	  This option enables signature verification of FIT uImages,
@@ -159,8 +159,8 @@ config SPL_FIT_SIGNATURE
 	select SPL_FIT
 	select SPL_CRYPTO_SUPPORT
 	select SPL_HASH_SUPPORT
-	select SPL_RSA
-	select SPL_RSA_VERIFY
+	imply SPL_RSA
+	imply SPL_RSA_VERIFY
 	select SPL_IMAGE_SIGN_INFO
 
 config SPL_LOAD_FIT
Signature · 1 line
2.26.2
#14 lore raw

PATCH 5/5 Kconfig: FIT_SIGNATURE should not select RSA_VERIFY

Quoted 10 lines · Alexandru Gagniuc

FIT signatures can now be implemented with ECDSA. The assumption that all FIT images are signed with RSA is no longer valid. Thus, instead of 'select'ing RSA, only 'imply' it. This doesn't change the defaults, but allows one to explicitly disable RSA support.

---
 common/Kconfig.boot | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
#15 lore raw

cover Enable ECDSA FIT verification for stm32mp

In reply to Alexandru Gagniuc

Hi Alexandru,

Quoted 1 line · Alexandru Gagniuc

This series is Part II of the ECDSA saga. It applies on top of [1]: * > [PATCH v4 0/6] Add support for ECDSA image signing (with test) > >

I've designed the UCLASS_ECDSA such that it aligns with the ROM API > of the stm32mp. Instead of splitting the verification into (1) curve > operations and (2) modular exponentiation, I've concatenated > everything in a 'verify' step. It would be impossible to split the > steps and use the stm32mp ROM for verification. > > Should more granular control be required, this API could be extended > at a later time. Until we have more hardware supporting ECDSA, this > is purely speculative. >

Quoted 1 line

The ROM API of the stm32mp is passed in 'r0' when the FSBL is >

called. While we can save 'r0' in SPL, this series does not implement > a mechanism to pass this to u-boot. Thus the ROM API, and ECDSA > verification are only available for SPL. Although extending this to > u-boot by adding the ROM address to the FDT blob, implementing and > verifying this is beyond the scope of this series.

For information, today the STMicroelectronics expected that the boot sequence for secure boot

(with closed STM32MP1 devices) is the trusted boot chain.

TF-A (BL2) => OP-TEE or????? => U-Boot =>? OS

??????????????????????? TF-A (BL32)

BL2 is authenticated by ROM code, with EDCSA support.

I next OpenSTLinux release (and soon after in upstream) STMicroelectronics will add FIP support

for STM32MP15x; TF-A FIP allows to boot Kernel after TF-A BL2 if you want to skip U-Boot

TF-A (BL2) => FIP (OP-TEE + Kernel)

And the FIP allow authentication with certificate for 'secured boot' with a complete chain of trust.

https://trustedfirmware-a.readthedocs.io/en/latest/index.html

So the ECDSA support in SPL for STM32MP15x will be not actively supported by STMicroelectronics for product design.

Quoted 4 lines
Quoted 3 lines

[1] https://lists.denx.de/pipermail/u-boot/2021-January/436935.html >

Alexandru Gagniuc (5): dm: crypto: Define UCLASS API for ECDSA >

signature verification lib: ecdsa: Add skeleton to implement ecdsa > verification in u-boot lib: ecdsa: Implement signature verification > for crypto_algo API arm: stm32mp1: Implement ECDSA signature > verification Kconfig: FIT_SIGNATURE should not select RSA_VERIFY > > arch/arm/mach-stm32mp/Kconfig | 9 ++ > arch/arm/mach-stm32mp/Makefile | 1 + > arch/arm/mach-stm32mp/ecdsa_romapi.c | 106 ++++++++++++++++++++++

Quoted 1 line

common/Kconfig.boot | 8 +- > include/crypto/ecdsa-uclass.h | 39

++++++++ > include/dm/uclass-id.h | 1 + include/image.h > | 10 +-- include/u-boot/rsa.h | 2 +- lib/Kconfig > | 1 + lib/Makefile | 1 + > lib/ecdsa/Kconfig | 23 +++++ lib/ecdsa/Makefile > | 1 + lib/ecdsa/ecdsa-verify.c | 128 > +++++++++++++++++++++++++++ 13 files changed, 320 insertions(+), 10 > deletions(-) create mode 100644 arch/arm/mach-stm32mp/ecdsa_romapi.c > create mode 100644 include/crypto/ecdsa-uclass.h create mode 100644 > lib/ecdsa/Kconfig create mode 100644 lib/ecdsa/Makefile create mode > 100644 lib/ecdsa/ecdsa-verify.c >

Regards

Patrick

author
#16 lore raw

cover Enable ECDSA FIT verification for stm32mp

Hi Patrick,

On 2/9/21 9:08 AM, Patrick DELAUNAY wrote:
[snip]

Quoted 24 lines

For information, today the STMicroelectronics expected that the boot sequence for secure boot

(with closed STM32MP1 devices) is the trusted boot chain.

TF-A (BL2) => OP-TEE or????? => U-Boot =>? OS

??????????????????????? TF-A (BL32)

BL2 is authenticated by ROM code, with EDCSA support.

I next OpenSTLinux release (and soon after in upstream) STMicroelectronics will add FIP support

for STM32MP15x; TF-A FIP allows to boot Kernel after TF-A BL2 if you want to skip U-Boot

TF-A (BL2) => FIP (OP-TEE + Kernel)

Quoted 8 lines

And the FIP allow authentication with certificate for 'secured boot' with a complete chain of trust.

https://trustedfirmware-a.readthedocs.io/en/latest/index.html

So the ECDSA support in SPL for STM32MP15x will be not actively supported by STMicroelectronics for product design.

The boot flow I'm working on will use an authenticated BL2 as well:

ROM -> SPL(BL2) -> FIT(OP-TEE -> Linux)

I'm using this to boot to a 3D application very fast (a couple of seconds max). It's really cool. I even wrote a utility for signing SPL images for the ROM code to check [1].

I had looked at FIP images briefly a few months back. I didn't see any advantage over the FIT format. I also wanted to have as little code as possible, so avoiding TF-A made sense. There were also some major issues with syncing the clock tree between linux and TF-A. TF-A was a beautiful disaster. Maybe that changed, but given I have a working proof of concept, I doubt I'll be re-engineering the boot flow.

I realize there won't be any STM support for SPL. openstlinux seems to have moved away from SPL. I've gotten a lot of enthusiastic support from u-boot members, as a number of people seem to really like this chip (meself included).

Alex

[1] https://github.com/mrnuke/stm32mp-keygen