Skip to contentSkip to conversation

add software ecdsa support

PATCH Superseded Philippe Reynes 4 participants 38 messages Mar 31 – Apr 2

Subsystems (3)

v3 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v3 cover add software ecdsa support

This serie adds the support of ecdsa with software using mbedtls. So boards without ecdsa hardware may also use signature with ecdsa.

To add the support of ecdsa with mbedtls, I have:
- enabled ecdsa in mbedtls
- add a function sw_ecdsa_verify that uses mbedtls
- add a driver sw_ecdsa that call sw_ecdsa_verify

I have tested this code with sandbox, and I have followed those steps:

0) build u-boot using sandbox_defconfig and adding those options:
CONFIG_ECDSA_SW=y
CONFIG_ECDSA_MBEDTLS=y
CONFIG_ECDSA=y
CONFIG_ECDSA_VERIFY=y

1) add a signature node to an its file

	signature-256 {
		algo = "sha256,ecdsa256";
		key-name-hint = "private-key-256";
	};

2) generate an ecdsa key
openssl ecparam -name prime256v1 -genkey -noout -out private-key-256.pem

3) create the itb file
./tools/mkimage -f <file.its> -k . -K arch/sandbox/dts/test.dtb <file.itb>

4) launch sandbox u-boot

./u-boot -d arch/sandbox/dts/test.dtb

5) on sandbox u-boot prompt, load the itb and launch bootm on it

=> host load hostfs - 1000000 uboot-ecdsa.itb
4628674 bytes read in 1 ms (4.3 GiB/s)
=> bootm 1000000
...
...
Verifying Hash Integrity ... sha256,ecdsa256:private-key-256+ OK

I have tested with success ecdsa256 and ecdsa384, but there is an issue with secp521r1.

Changes in v2:
- move ECDSA_MBEDTLS to MBEDTLS_LIB_X509
- rename lib/mbedtls/sw_ecdsa.c to lib/mbedtls/ecdsa.c
- enhance dependancies for ECDSA_MBEDTLS
- fix support of ecdsa521/secp521r1
- add vboot test using ecdsa

Changes in v3:
- do not use _MBEDTLS in mbedtls_def_config.h
- check returns and remove mem leak in lib/mbedtls/ecdsa.c
- remove useless field *k in struct ecdsa_test_vector_s
- check returns in test/lib/ecdsa.c
- fix third parameter when calling sha*_csum_wd()
- add support of ecdsa in pre-load header

Philippe Reynes (15):
mbedtls: enable support of ecc
ecdsa: initial support of ecdsa using mbedtls
test: lib: ecdsa: add initial test
drivers: crypto: add software ecdsa support
ecdsa: fix support of secp521r1
test: dm: ecdsa.c: clean this test as software ecdsa is now
implemented
test: py: vboot: prepare integration test for ecdsa
test: vboot: add test for ecdsa
tools: mkimage: pre-load: add support of ecdsa
tools: binman: pre-load: add support of ecdsa
tools: binman: pre-load: add test for ecdsa
boot: pre-load: add support of ecdsa
tools: preload_check_sign: add support of ecdsa
test: py: vboot: prepare test for glocal signature with ecdsa
test: py: vboot: add test for global signature with ecdsa

 boot/image-pre-load.c                         |  48 +-
 configs/amd_versal2_virt_defconfig            |   1 +
 configs/qemu_arm64_lwip_defconfig             |   1 +
 configs/starfive_visionfive2_defconfig        |   1 +
 configs/xilinx_versal_net_virt_defconfig      |   1 +
 configs/xilinx_versal_virt_defconfig          |   1 +
 configs/xilinx_zynqmp_kria_defconfig          |   1 +
 configs/xilinx_zynqmp_virt_defconfig          |   1 +
 drivers/crypto/Kconfig                        |   2 +
 drivers/crypto/Makefile                       |   1 +
 drivers/crypto/ecdsa/Kconfig                  |   8 +
 drivers/crypto/ecdsa/Makefile                 |   6 +
 drivers/crypto/ecdsa/ecdsa-sw.c               |  33 ++
 include/crypto/internal/ecdsa.h               |  14 +
 lib/ecdsa/ecdsa-libcrypto.c                   |  50 +-
 lib/ecdsa/ecdsa-verify.c                      |  24 +-
 lib/fdt-libcrypto.c                           |   2 +-
 lib/mbedtls/Kconfig                           |  16 +
 lib/mbedtls/Makefile                          |  19 +-
 lib/mbedtls/ecdsa.c                           | 141 ++++++
 lib/mbedtls/mbedtls_def_config.h              |  18 +
 test/dm/ecdsa.c                               |  18 +-
 test/lib/Makefile                             |   1 +
 test/lib/ecdsa.c                              | 447 ++++++++++++++++++
 test/py/tests/test_fit_ecdsa.py               |   2 +-
 test/py/tests/test_vboot.py                   | 143 +++---
 .../tests/vboot/sandbox-binman-ecdsa256.dts   |  24 +
 .../tests/vboot/sandbox-binman-ecdsa384.dts   |  24 +
 .../tests/vboot/sandbox-binman-ecdsa521.dts   |  24 +
 ...pss.dts => sandbox-binman-rsa2048-pss.dts} |   0
 ...-binman.dts => sandbox-binman-rsa2048.dts} |   0
 .../vboot/sandbox-u-boot-global-ecdsa256.dts  |  27 ++
 .../vboot/sandbox-u-boot-global-ecdsa384.dts  |  27 ++
 .../vboot/sandbox-u-boot-global-ecdsa521.dts  |  27 ++
 ... => sandbox-u-boot-global-rsa2048-pss.dts} |   0
 ....dts => sandbox-u-boot-global-rsa2048.dts} |   0
 ....its => sign-configs-sha1-rsa2048-pss.its} |   0
 ...sha1.its => sign-configs-sha1-rsa2048.its} |   0
 .../vboot/sign-configs-sha256-ecdsa256.its    |  45 ++
 .../vboot/sign-configs-sha256-ecdsa384.its    |  45 ++
 .../vboot/sign-configs-sha256-ecdsa521.its    |  45 ++
 ... sign-configs-sha256-rsa2048-pss-prod.its} |   0
 ...ts => sign-configs-sha256-rsa2048-pss.its} |   0
 ...56.its => sign-configs-sha256-rsa2048.its} |   0
 ...84.its => sign-configs-sha384-rsa3072.its} |   0
 ...s.its => sign-images-sha1-rsa2048-pss.its} |   0
 ...-sha1.its => sign-images-sha1-rsa2048.its} |   0
 .../vboot/sign-images-sha256-ecdsa256.its     |  42 ++
 .../vboot/sign-images-sha256-ecdsa384.its     |  42 ++
 .../vboot/sign-images-sha256-ecdsa521.its     |  42 ++
 ...its => sign-images-sha256-rsa2048-pss.its} |   0
 ...256.its => sign-images-sha256-rsa2048.its} |   0
 ...384.its => sign-images-sha384-rsa3072.its} |   0
 tools/binman/etype/pre_load.py                |  78 ++-
 tools/binman/ftest.py                         |  31 ++
 tools/binman/test/351_pre_load_ecdsa.dts      |  22 +
 .../test/352_pre_load_ecdsa_invalid_sha.dts   |  22 +
 .../test/353_pre_load_ecdsa_invalid_algo.dts  |  22 +
 tools/binman/test/ecdsa521.pem                |   7 +
 tools/image-host.c                            |  78 ++-
 tools/image-sig-host.c                        |   2 +-
 tools/preload_check_sign.c                    |  24 +
 62 files changed, 1577 insertions(+), 123 deletions(-)
 create mode 100644 drivers/crypto/ecdsa/Kconfig
 create mode 100644 drivers/crypto/ecdsa/Makefile
 create mode 100644 drivers/crypto/ecdsa/ecdsa-sw.c
 create mode 100644 include/crypto/internal/ecdsa.h
 create mode 100644 lib/mbedtls/ecdsa.c
 create mode 100644 test/lib/ecdsa.c
 create mode 100644 test/py/tests/vboot/sandbox-binman-ecdsa256.dts
 create mode 100644 test/py/tests/vboot/sandbox-binman-ecdsa384.dts
 create mode 100644 test/py/tests/vboot/sandbox-binman-ecdsa521.dts
 rename test/py/tests/vboot/{sandbox-binman-pss.dts => sandbox-binman-rsa2048-pss.dts} (100%)
 rename test/py/tests/vboot/{sandbox-binman.dts => sandbox-binman-rsa2048.dts} (100%)
 create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-ecdsa256.dts
 create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-ecdsa384.dts
 create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-ecdsa521.dts
 rename test/py/tests/vboot/{sandbox-u-boot-global-pss.dts => sandbox-u-boot-global-rsa2048-pss.dts} (100%)
 rename test/py/tests/vboot/{sandbox-u-boot-global.dts => sandbox-u-boot-global-rsa2048.dts} (100%)
 rename test/py/tests/vboot/{sign-configs-sha1-pss.its => sign-configs-sha1-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha1.its => sign-configs-sha1-rsa2048.its} (100%)
 create mode 100644 test/py/tests/vboot/sign-configs-sha256-ecdsa256.its
 create mode 100644 test/py/tests/vboot/sign-configs-sha256-ecdsa384.its
 create mode 100644 test/py/tests/vboot/sign-configs-sha256-ecdsa521.its
 rename test/py/tests/vboot/{sign-configs-sha256-pss-prod.its => sign-configs-sha256-rsa2048-pss-prod.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha256-pss.its => sign-configs-sha256-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha256.its => sign-configs-sha256-rsa2048.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha384.its => sign-configs-sha384-rsa3072.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha1-pss.its => sign-images-sha1-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha1.its => sign-images-sha1-rsa2048.its} (100%)
 create mode 100644 test/py/tests/vboot/sign-images-sha256-ecdsa256.its
 create mode 100644 test/py/tests/vboot/sign-images-sha256-ecdsa384.its
 create mode 100644 test/py/tests/vboot/sign-images-sha256-ecdsa521.its
 rename test/py/tests/vboot/{sign-images-sha256-pss.its => sign-images-sha256-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha256.its => sign-images-sha256-rsa2048.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha384.its => sign-images-sha384-rsa3072.its} (100%)
 create mode 100644 tools/binman/test/351_pre_load_ecdsa.dts
 create mode 100644 tools/binman/test/352_pre_load_ecdsa_invalid_sha.dts
 create mode 100644 tools/binman/test/353_pre_load_ecdsa_invalid_algo.dts
 create mode 100644 tools/binman/test/ecdsa521.pem
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/15 mbedtls: enable support of ecc

Enables the support of ecc in mbedtls.

---
v2:
- move ecdsa to MBEDTLS_LIB_X509
- enhance depencendies
v3:
- do not use _MBEDTLS in mbedtls_def_config.h

 configs/amd_versal2_virt_defconfig       |  1 +
 configs/qemu_arm64_lwip_defconfig        |  1 +
 configs/starfive_visionfive2_defconfig   |  1 +
 configs/xilinx_versal_net_virt_defconfig |  1 +
 configs/xilinx_versal_virt_defconfig     |  1 +
 configs/xilinx_zynqmp_kria_defconfig     |  1 +
 configs/xilinx_zynqmp_virt_defconfig     |  1 +
 lib/mbedtls/Kconfig                      | 16 ++++++++++++++++
 lib/mbedtls/Makefile                     | 16 +++++++++-------
 lib/mbedtls/mbedtls_def_config.h         | 18 ++++++++++++++++++
 10 files changed, 50 insertions(+), 7 deletions(-)
configs/amd_versal2_virt_defconfig +1 -0
index 0344089030c..702bf28405d 100644
@@ -164,6 +164,7 @@ CONFIG_VIRTIO_MMIO=y
 CONFIG_VIRTIO_NET=y
 CONFIG_VIRTIO_BLK=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
 CONFIG_TPM=y
 # CONFIG_OPTEE_LIB is not set
 CONFIG_TOOLS_MKFWUMDATA=y
configs/qemu_arm64_lwip_defconfig +1 -0
index a974970c3d3..ab6302b67eb 100644
@@ -11,3 +11,4 @@ CONFIG_CMD_WGET=y
 CONFIG_EFI_HTTP_BOOT=y
 CONFIG_WGET_HTTPS=y
 CONFIG_WGET_CACERT=y
+CONFIG_ECDSA=y
configs/starfive_visionfive2_defconfig +1 -0
index a754134a313..508bd465704 100644
@@ -156,3 +156,4 @@ CONFIG_USB_GADGET=y
 CONFIG_WDT=y
 CONFIG_WDT_STARFIVE=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
configs/xilinx_versal_net_virt_defconfig +1 -0
index 323b5606566..8b760beab03 100644
@@ -154,4 +154,5 @@ CONFIG_VIRTIO_MMIO=y
 CONFIG_VIRTIO_NET=y
 CONFIG_VIRTIO_BLK=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
 CONFIG_TPM=y
configs/xilinx_versal_virt_defconfig +1 -0
index 652121e27a0..6dd8620cf51 100644
@@ -168,5 +168,6 @@ CONFIG_VIRTIO_MMIO=y
 CONFIG_VIRTIO_NET=y
 CONFIG_VIRTIO_BLK=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
 CONFIG_TPM=y
 CONFIG_TOOLS_MKFWUMDATA=y
configs/xilinx_zynqmp_kria_defconfig +1 -0
index 8ad05e37189..d23452e96d0 100644
@@ -219,6 +219,7 @@ CONFIG_VIRTIO_BLK=y
 CONFIG_BINMAN_DTB="./arch/arm/dts/zynqmp-binman-som.dtb"
 CONFIG_PANIC_HANG=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
 CONFIG_TPM=y
 CONFIG_SPL_GZIP=y
 CONFIG_TOOLS_MKFWUMDATA=y
configs/xilinx_zynqmp_virt_defconfig +1 -0
index bb79ddf989e..01370a215d4 100644
@@ -237,6 +237,7 @@ CONFIG_VIRTIO_BLK=y
 CONFIG_BINMAN_DTB="./arch/arm/dts/zynqmp-binman.dtb"
 CONFIG_PANIC_HANG=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
 CONFIG_TPM=y
 CONFIG_SPL_GZIP=y
 CONFIG_TOOLS_MKFWUMDATA=y
lib/mbedtls/Kconfig +16 -0
index 789721ee6cd..8bf8809198f 100644
@@ -242,11 +242,16 @@ config MBEDTLS_LIB_X509
 	select X509_CERTIFICATE_PARSER_MBEDTLS if X509_CERTIFICATE_PARSER
 	select PKCS7_MESSAGE_PARSER_MBEDTLS if PKCS7_MESSAGE_PARSER
 	select MSCODE_PARSER_MBEDTLS if MSCODE_PARSER
+	select ECDSA_MBEDTLS if ECDSA
 	help
 	  Enable MbedTLS certificate libraries.
 
 if MBEDTLS_LIB_X509
 
+config BIGNUM_MBEDTLS
+	bool
+	default n
+
 config ASN1_DECODER_MBEDTLS
 	bool "ASN1 decoder with MbedTLS certificate library"
 	depends on MBEDTLS_LIB_X509 && ASN1_DECODER
@@ -264,6 +269,7 @@ config RSA_PUBLIC_KEY_PARSER_MBEDTLS
 	bool "RSA public key parser with MbedTLS certificate library"
 	depends on ASYMMETRIC_PUBLIC_KEY_MBEDTLS
 	select ASN1_DECODER_MBEDTLS
+	select BIGNUM_MBEDTLS
 	help
 	  This option chooses MbedTLS certificate library for RSA public key
 	  parser.
@@ -292,6 +298,15 @@ config MSCODE_PARSER_MBEDTLS
 	  This option chooses MbedTLS certificate library for MS authenticode
 	  parser.
 
+config ECDSA_MBEDTLS
+	bool "Enable ECDSA support with MbedTLS certificate library"
+	depends on MBEDTLS_LIB_X509
+	select ASN1_DECODER
+	select BIGNUM_MBEDTLS
+	help
+	  This option enables support of ECDSA with the MbedTLS certificate
+	  library.
+
 endif # MBEDTLS_LIB_X509
 
 config MBEDTLS_LIB_TLS
@@ -301,6 +316,7 @@ config MBEDTLS_LIB_TLS
 	depends on ASYMMETRIC_PUBLIC_KEY_MBEDTLS
 	depends on ASN1_DECODER_MBEDTLS
 	depends on MBEDTLS_LIB
+	depends on ECDSA_MBEDTLS
 	help
 	  Enable MbedTLS TLS library. Required for HTTPs support
 	  in wget
lib/mbedtls/Makefile +9 -7
index c5b445bd85c..5433e17cc64 100644
@@ -39,13 +39,14 @@ mbedtls_lib_crypto-$(CONFIG_$(PHASE_)HKDF_MBEDTLS) += \
 # MbedTLS X509 library
 obj-$(CONFIG_$(XPL_)MBEDTLS_LIB_X509) += mbedtls_lib_x509.o
 mbedtls_lib_x509-y := $(MBEDTLS_LIB_DIR)/x509.o
+mbedtls_lib_x509-$(CONFIG_$(PHASE_)BIGNUM_MBEDTLS) += \
+	$(MBEDTLS_LIB_DIR)/bignum.o \
+	$(MBEDTLS_LIB_DIR)/bignum_core.o
 mbedtls_lib_x509-$(CONFIG_$(PHASE_)ASN1_DECODER_MBEDTLS) += \
 	$(MBEDTLS_LIB_DIR)/asn1parse.o \
 	$(MBEDTLS_LIB_DIR)/asn1write.o \
 	$(MBEDTLS_LIB_DIR)/oid.o
 mbedtls_lib_x509-$(CONFIG_$(PHASE_)RSA_PUBLIC_KEY_PARSER_MBEDTLS) += \
-	$(MBEDTLS_LIB_DIR)/bignum.o \
-	$(MBEDTLS_LIB_DIR)/bignum_core.o \
 	$(MBEDTLS_LIB_DIR)/rsa.o \
 	$(MBEDTLS_LIB_DIR)/rsa_alt_helpers.o
 mbedtls_lib_x509-$(CONFIG_$(PHASE_)ASYMMETRIC_PUBLIC_KEY_MBEDTLS) += \
@@ -57,6 +58,12 @@ mbedtls_lib_x509-$(CONFIG_$(PHASE_)X509_CERTIFICATE_PARSER_MBEDTLS) += \
 	$(MBEDTLS_LIB_DIR)/x509_crt.o
 mbedtls_lib_x509-$(CONFIG_$(PHASE_)PKCS7_MESSAGE_PARSER_MBEDTLS) += \
 	$(MBEDTLS_LIB_DIR)/pkcs7.o
+mbedtls_lib_x509-$(CONFIG_$(PHASE_)ECDSA_MBEDTLS) += \
+	$(MBEDTLS_LIB_DIR)/ecdsa.o \
+	$(MBEDTLS_LIB_DIR)/ecp.o \
+	$(MBEDTLS_LIB_DIR)/ecp_curves.o \
+	$(MBEDTLS_LIB_DIR)/ecp_curves_new.o \
+	$(MBEDTLS_LIB_DIR)/pk_ecc.o
 
 #mbedTLS TLS support
 obj-$(CONFIG_$(XPL_)MBEDTLS_LIB_TLS) += mbedtls_lib_tls.o
@@ -64,7 +71,6 @@ mbedtls_lib_tls-y := \
 	$(MBEDTLS_LIB_DIR)/mps_reader.o \
 	$(MBEDTLS_LIB_DIR)/mps_trace.o \
 	$(MBEDTLS_LIB_DIR)/net_sockets.o \
-	$(MBEDTLS_LIB_DIR)/pk_ecc.o \
 	$(MBEDTLS_LIB_DIR)/ssl_cache.o \
 	$(MBEDTLS_LIB_DIR)/ssl_ciphersuites.o \
 	$(MBEDTLS_LIB_DIR)/ssl_client.o \
@@ -82,8 +88,4 @@ mbedtls_lib_tls-y := \
 	$(MBEDTLS_LIB_DIR)/cipher.o \
 	$(MBEDTLS_LIB_DIR)/cipher_wrap.o \
 	$(MBEDTLS_LIB_DIR)/ecdh.o \
-	$(MBEDTLS_LIB_DIR)/ecdsa.o \
-	$(MBEDTLS_LIB_DIR)/ecp.o \
-	$(MBEDTLS_LIB_DIR)/ecp_curves.o \
-	$(MBEDTLS_LIB_DIR)/ecp_curves_new.o \
 	$(MBEDTLS_LIB_DIR)/gcm.o \
lib/mbedtls/mbedtls_def_config.h +18 -0
index dda3f4dd6e4..0c8449afe6a 100644
@@ -89,6 +89,24 @@
 #define MBEDTLS_ASN1_WRITE_C
 #endif
 
+#if CONFIG_IS_ENABLED(ECDSA)
+#define MBEDTLS_ECDSA_C
+#define MBEDTLS_ECP_C
+#define MBEDTLS_BIGNUM_C
+#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
+#define MBEDTLS_ECP_DP_BP256R1_ENABLED
+#define MBEDTLS_ECP_DP_BP384R1_ENABLED
+#define MBEDTLS_ECP_DP_BP512R1_ENABLED
+#endif
+
 #endif /* #if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) */
 
 #if CONFIG_IS_ENABLED(MBEDTLS_LIB_TLS)
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v3 01/15] mbedtls: enable support of ecc

Hi Philippe,

Quoted 128 lines · Philippe Reynes

Enables the support of ecc in mbedtls.

---
v2:
- move ecdsa to MBEDTLS_LIB_X509
- enhance depencendies
v3:
- do not use _MBEDTLS in mbedtls_def_config.h

 configs/amd_versal2_virt_defconfig       |  1 +
 configs/qemu_arm64_lwip_defconfig        |  1 +
 configs/starfive_visionfive2_defconfig   |  1 +
 configs/xilinx_versal_net_virt_defconfig |  1 +
 configs/xilinx_versal_virt_defconfig     |  1 +
 configs/xilinx_zynqmp_kria_defconfig     |  1 +
 configs/xilinx_zynqmp_virt_defconfig     |  1 +
 lib/mbedtls/Kconfig                      | 16 ++++++++++++++++
 lib/mbedtls/Makefile                     | 16 +++++++++-------
 lib/mbedtls/mbedtls_def_config.h         | 18 ++++++++++++++++++
 10 files changed, 50 insertions(+), 7 deletions(-)
configs/amd_versal2_virt_defconfig +1 -0
index 0344089030c..702bf28405d 100644
@@ -164,6 +164,7 @@ CONFIG_VIRTIO_MMIO=y
 CONFIG_VIRTIO_NET=y
 CONFIG_VIRTIO_BLK=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
 CONFIG_TPM=y
 # CONFIG_OPTEE_LIB is not set
 CONFIG_TOOLS_MKFWUMDATA=y
configs/qemu_arm64_lwip_defconfig +1 -0
index a974970c3d3..ab6302b67eb 100644
@@ -11,3 +11,4 @@ CONFIG_CMD_WGET=y
 CONFIG_EFI_HTTP_BOOT=y
 CONFIG_WGET_HTTPS=y
 CONFIG_WGET_CACERT=y
+CONFIG_ECDSA=y
configs/starfive_visionfive2_defconfig +1 -0
index a754134a313..508bd465704 100644
@@ -156,3 +156,4 @@ CONFIG_USB_GADGET=y
 CONFIG_WDT=y
 CONFIG_WDT_STARFIVE=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
configs/xilinx_versal_net_virt_defconfig +1 -0
index 323b5606566..8b760beab03 100644
@@ -154,4 +154,5 @@ CONFIG_VIRTIO_MMIO=y
 CONFIG_VIRTIO_NET=y
 CONFIG_VIRTIO_BLK=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
 CONFIG_TPM=y
configs/xilinx_versal_virt_defconfig +1 -0
index 652121e27a0..6dd8620cf51 100644
@@ -168,5 +168,6 @@ CONFIG_VIRTIO_MMIO=y
 CONFIG_VIRTIO_NET=y
 CONFIG_VIRTIO_BLK=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
 CONFIG_TPM=y
 CONFIG_TOOLS_MKFWUMDATA=y
configs/xilinx_zynqmp_kria_defconfig +1 -0
index 8ad05e37189..d23452e96d0 100644
@@ -219,6 +219,7 @@ CONFIG_VIRTIO_BLK=y
 CONFIG_BINMAN_DTB="./arch/arm/dts/zynqmp-binman-som.dtb"
 CONFIG_PANIC_HANG=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
 CONFIG_TPM=y
 CONFIG_SPL_GZIP=y
 CONFIG_TOOLS_MKFWUMDATA=y
configs/xilinx_zynqmp_virt_defconfig +1 -0
index bb79ddf989e..01370a215d4 100644
@@ -237,6 +237,7 @@ CONFIG_VIRTIO_BLK=y
 CONFIG_BINMAN_DTB="./arch/arm/dts/zynqmp-binman.dtb"
 CONFIG_PANIC_HANG=y
 CONFIG_MBEDTLS_LIB=y
+CONFIG_ECDSA=y
 CONFIG_TPM=y
 CONFIG_SPL_GZIP=y
 CONFIG_TOOLS_MKFWUMDATA=y
lib/mbedtls/Kconfig +6 -0
index 789721ee6cd..8bf8809198f 100644
@@ -242,11 +242,16 @@ config MBEDTLS_LIB_X509
        select X509_CERTIFICATE_PARSER_MBEDTLS if X509_CERTIFICATE_PARSER
        select PKCS7_MESSAGE_PARSER_MBEDTLS if PKCS7_MESSAGE_PARSER
        select MSCODE_PARSER_MBEDTLS if MSCODE_PARSER
+       select ECDSA_MBEDTLS if ECDSA
        help
          Enable MbedTLS certificate libraries.
 
 if MBEDTLS_LIB_X509
 
+config BIGNUM_MBEDTLS
+       bool
+       default n
+
 config ASN1_DECODER_MBEDTLS
        bool "ASN1 decoder with MbedTLS certificate library"
        depends on MBEDTLS_LIB_X509 && ASN1_DECODER
@@ -264,6 +269,7 @@ config RSA_PUBLIC_KEY_PARSER_MBEDTLS
        bool "RSA public key parser with MbedTLS certificate library"
        depends on ASYMMETRIC_PUBLIC_KEY_MBEDTLS
        select ASN1_DECODER_MBEDTLS
+       select BIGNUM_MBEDTLS
        help
          This option chooses MbedTLS certificate library for RSA public key
          parser.

lib/mbedtls/Kconfig config MSCODE_PARSER_MBEDTLS · line 304

Quoted 7 lines
lib/mbedtls/Kconfig +4 -0
@@ -292,6 +298,15 @@ config MSCODE_PARSER_MBEDTLS
          This option chooses MbedTLS certificate library for MS authenticode
          parser.
 
+config ECDSA_MBEDTLS
+       bool "Enable ECDSA support with MbedTLS certificate library"
+       depends on MBEDTLS_LIB_X509
+       select ASN1_DECODER

As I replied in your V2 thread, it is better to depend/select only _MBEDTLS switches here, and let ECDSA select the common one, for example:

config ECDSA
select ASN1_DECODER

config MBEDTLS_LIB_X509
select ASN1_DECODER_MBEDTLS if ASN1_DECODER

Regards,
Raymond

Quoted 99 lines
lib/mbedtls/Kconfig +6 -0
+       select BIGNUM_MBEDTLS
+       help
+         This option enables support of ECDSA with the MbedTLS certificate
+         library.
+
 endif # MBEDTLS_LIB_X509
 
 config MBEDTLS_LIB_TLS
@@ -301,6 +316,7 @@ config MBEDTLS_LIB_TLS
        depends on ASYMMETRIC_PUBLIC_KEY_MBEDTLS
        depends on ASN1_DECODER_MBEDTLS
        depends on MBEDTLS_LIB
+       depends on ECDSA_MBEDTLS
        help
          Enable MbedTLS TLS library. Required for HTTPs support
          in wget
lib/mbedtls/Makefile +9 -7
index c5b445bd85c..5433e17cc64 100644
@@ -39,13 +39,14 @@ mbedtls_lib_crypto-$(CONFIG_$(PHASE_)HKDF_MBEDTLS) += \
 # MbedTLS X509 library
 obj-$(CONFIG_$(XPL_)MBEDTLS_LIB_X509) += mbedtls_lib_x509.o
 mbedtls_lib_x509-y := $(MBEDTLS_LIB_DIR)/x509.o
+mbedtls_lib_x509-$(CONFIG_$(PHASE_)BIGNUM_MBEDTLS) += \
+       $(MBEDTLS_LIB_DIR)/bignum.o \
+       $(MBEDTLS_LIB_DIR)/bignum_core.o
 mbedtls_lib_x509-$(CONFIG_$(PHASE_)ASN1_DECODER_MBEDTLS) += \
        $(MBEDTLS_LIB_DIR)/asn1parse.o \
        $(MBEDTLS_LIB_DIR)/asn1write.o \
        $(MBEDTLS_LIB_DIR)/oid.o
 mbedtls_lib_x509-$(CONFIG_$(PHASE_)RSA_PUBLIC_KEY_PARSER_MBEDTLS) += \
-       $(MBEDTLS_LIB_DIR)/bignum.o \
-       $(MBEDTLS_LIB_DIR)/bignum_core.o \
        $(MBEDTLS_LIB_DIR)/rsa.o \
        $(MBEDTLS_LIB_DIR)/rsa_alt_helpers.o
 mbedtls_lib_x509-$(CONFIG_$(PHASE_)ASYMMETRIC_PUBLIC_KEY_MBEDTLS) += \
@@ -57,6 +58,12 @@ mbedtls_lib_x509-$(CONFIG_$(PHASE_)X509_CERTIFICATE_PARSER_MBEDTLS) += \
        $(MBEDTLS_LIB_DIR)/x509_crt.o
 mbedtls_lib_x509-$(CONFIG_$(PHASE_)PKCS7_MESSAGE_PARSER_MBEDTLS) += \
        $(MBEDTLS_LIB_DIR)/pkcs7.o
+mbedtls_lib_x509-$(CONFIG_$(PHASE_)ECDSA_MBEDTLS) += \
+       $(MBEDTLS_LIB_DIR)/ecdsa.o \
+       $(MBEDTLS_LIB_DIR)/ecp.o \
+       $(MBEDTLS_LIB_DIR)/ecp_curves.o \
+       $(MBEDTLS_LIB_DIR)/ecp_curves_new.o \
+       $(MBEDTLS_LIB_DIR)/pk_ecc.o
 
 #mbedTLS TLS support
 obj-$(CONFIG_$(XPL_)MBEDTLS_LIB_TLS) += mbedtls_lib_tls.o
@@ -64,7 +71,6 @@ mbedtls_lib_tls-y := \
        $(MBEDTLS_LIB_DIR)/mps_reader.o \
        $(MBEDTLS_LIB_DIR)/mps_trace.o \
        $(MBEDTLS_LIB_DIR)/net_sockets.o \
-       $(MBEDTLS_LIB_DIR)/pk_ecc.o \
        $(MBEDTLS_LIB_DIR)/ssl_cache.o \
        $(MBEDTLS_LIB_DIR)/ssl_ciphersuites.o \
        $(MBEDTLS_LIB_DIR)/ssl_client.o \
@@ -82,8 +88,4 @@ mbedtls_lib_tls-y := \
        $(MBEDTLS_LIB_DIR)/cipher.o \
        $(MBEDTLS_LIB_DIR)/cipher_wrap.o \
        $(MBEDTLS_LIB_DIR)/ecdh.o \
-       $(MBEDTLS_LIB_DIR)/ecdsa.o \
-       $(MBEDTLS_LIB_DIR)/ecp.o \
-       $(MBEDTLS_LIB_DIR)/ecp_curves.o \
-       $(MBEDTLS_LIB_DIR)/ecp_curves_new.o \
        $(MBEDTLS_LIB_DIR)/gcm.o \
lib/mbedtls/mbedtls_def_config.h +18 -1
index dda3f4dd6e4..0c8449afe6a 100644
@@ -89,6 +89,24 @@
 #define MBEDTLS_ASN1_WRITE_C
 #endif
 
+#if CONFIG_IS_ENABLED(ECDSA)
+#define MBEDTLS_ECDSA_C
+#define MBEDTLS_ECP_C
+#define MBEDTLS_BIGNUM_C
+#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
+#define MBEDTLS_ECP_DP_BP256R1_ENABLED
+#define MBEDTLS_ECP_DP_BP384R1_ENABLED
+#define MBEDTLS_ECP_DP_BP512R1_ENABLED
+#endif
+
 #endif /* #if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509) */
 
 #if CONFIG_IS_ENABLED(MBEDTLS_LIB_TLS)
--

2.43.0

#3 lore raw

Re: [v3,01/15] mbedtls: enable support of ecc

In reply to Philippe Reynes

Hi Philippe,

Quoted 4 lines · Philippe Reynes
lib/mbedtls/mbedtls_def_config.h +2 -0
@@ -89,6 +89,24 @@
+#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP192R1_ENABLED

lib/mbedtls/mbedtls_def_config.h line 100

Quoted 10 lines
lib/mbedtls/mbedtls_def_config.h +10 -0
+#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
+#define MBEDTLS_ECP_DP_BP256R1_ENABLED
+#define MBEDTLS_ECP_DP_BP384R1_ENABLED
+#define MBEDTLS_ECP_DP_BP512R1_ENABLED

MBEDTLS_ECP_DP_SECP256K1_ENABLED is defined twice in this block - please remove the duplicate.

configs/amd_versal2_virt_defconfig CONFIG_VIRTIO_MMIO=y · line 164

Quoted 3 lines
configs/amd_versal2_virt_defconfig +1 -0
@@ -164,6 +164,7 @@ CONFIG_VIRTIO_MMIO=y
+CONFIG_ECDSA=y

The commit message says "Enables the support of ecc in mbedtls" but this is doing more than that - it also adds CONFIG_ECDSA to several defconfigs which is a functional change. Please can you explain in the commit message why these boards need ECDSA enabled? Probably should be a separate commit, too.

Regards,
Simon

#4 lore raw

PATCH v3 2/15 ecdsa: initial support of ecdsa using mbedtls

In reply to Philippe Reynes

Adds an initial support of ecdsa verify using mbedtls.

---
v2:
- rename sw_ecdsa.c to ecdsa.c
v3:
- rename sw_ecdsa_verify to ecdsa_hash_verify
- stop on first group found
- check signature len
- use debug instead of printf
- check function returns
- fix memleaks in ecdsa_hash_verify

 include/crypto/internal/ecdsa.h |  14 ++++
 lib/mbedtls/Makefile            |   3 +
 lib/mbedtls/ecdsa.c             | 141 ++++++++++++++++++++++++++++++++
 3 files changed, 158 insertions(+)
 create mode 100644 include/crypto/internal/ecdsa.h
 create mode 100644 lib/mbedtls/ecdsa.c
include/crypto/internal/ecdsa.h new file +14 -0
new file mode 100644
index 00000000000..d2edc006cc2
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2026, Philippe Reynes <[email protected]>
+ */
+#ifndef __ECDSA_HELPER
+#define __ECDSA_HELPER
+
+struct ecdsa_public_key;
+
+int ecdsa_hash_verify(const struct ecdsa_public_key *pubkey,
+		      const void *hash, size_t hash_len,
+		      const void *signature, size_t sig_len);
+
+#endif
lib/mbedtls/Makefile +3 -0
index 5433e17cc64..6db06092cee 100644
@@ -11,6 +11,9 @@ obj-$(CONFIG_$(PHASE_)SHA1_MBEDTLS) += sha1.o
 obj-$(CONFIG_$(PHASE_)SHA256_MBEDTLS) += sha256.o
 obj-$(CONFIG_$(PHASE_)SHA512_MBEDTLS) += sha512.o
 
+# shim layer for ecdsa
+obj-$(CONFIG_$(PHASE_)ECDSA_MBEDTLS) += ecdsa.o
+
 # x509 libraries
 obj-$(CONFIG_$(PHASE_)ASYMMETRIC_PUBLIC_KEY_MBEDTLS) += \
 	public_key.o
lib/mbedtls/ecdsa.c new file +141 -0

141 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v3 02/15] ecdsa: initial support of ecdsa using mbedtls

Hi Philippe,

Quoted 28 lines · Philippe Reynes

Adds an initial support of ecdsa verify using mbedtls.

---
v2:
- rename sw_ecdsa.c to ecdsa.c
v3:
- rename sw_ecdsa_verify to ecdsa_hash_verify
- stop on first group found
- check signature len
- use debug instead of printf
- check function returns
- fix memleaks in ecdsa_hash_verify

 include/crypto/internal/ecdsa.h |  14 ++++
 lib/mbedtls/Makefile            |   3 +
 lib/mbedtls/ecdsa.c             | 141 ++++++++++++++++++++++++++++++++
 3 files changed, 158 insertions(+)
 create mode 100644 include/crypto/internal/ecdsa.h
 create mode 100644 lib/mbedtls/ecdsa.c
include/crypto/internal/ecdsa.h new file +0 -0
new file mode 100644
index 00000000000..d2edc006cc2

include/crypto/internal/ecdsa.h line 6

Quoted 6 lines
include/crypto/internal/ecdsa.h new file +6 -0
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2026, Philippe Reynes <[email protected]>
+ */
+#ifndef __ECDSA_HELPER
+#define __ECDSA_HELPER

Suggest to keep the same guard style as the existing one for RSA '_RSA_HELPER_'.

Quoted 28 lines
include/crypto/internal/ecdsa.h new file +8 -0
+
+struct ecdsa_public_key;
+
+int ecdsa_hash_verify(const struct ecdsa_public_key *pubkey,
+                     const void *hash, size_t hash_len,
+                     const void *signature, size_t sig_len);
+
+#endif
lib/mbedtls/Makefile +3 -0
index 5433e17cc64..6db06092cee 100644
@@ -11,6 +11,9 @@ obj-$(CONFIG_$(PHASE_)SHA1_MBEDTLS) += sha1.o
 obj-$(CONFIG_$(PHASE_)SHA256_MBEDTLS) += sha256.o
 obj-$(CONFIG_$(PHASE_)SHA512_MBEDTLS) += sha512.o
 
+# shim layer for ecdsa
+obj-$(CONFIG_$(PHASE_)ECDSA_MBEDTLS) += ecdsa.o
+
 # x509 libraries
 obj-$(CONFIG_$(PHASE_)ASYMMETRIC_PUBLIC_KEY_MBEDTLS) += \
        public_key.o
lib/mbedtls/ecdsa.c new file +0 -0
new file mode 100644
index 00000000000..c2ba5c3d72b

lib/mbedtls/ecdsa.c line 6

Quoted 6 lines
lib/mbedtls/ecdsa.c new file +6 -0
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2026 Philippe Reynes <[email protected]>
+ */
+
+#include <crypto/ecdsa-uclass.h>

Should include the header you added:
#include <crypto/internal/ecdsa.h>

lib/mbedtls/ecdsa.c line 7

Quoted 1 line
lib/mbedtls/ecdsa.c new file +1 -0
+#include "mbedtls_options.h" /* required to access private fields */

I didn't find private member access in below code, please double confirm. If there is no private access, suggest removing this line.

lib/mbedtls/ecdsa.c line 20

Quoted 13 lines
lib/mbedtls/ecdsa.c new file +13 -0
+#include <mbedtls/ecdsa.h>
+#include <mbedtls/ecp.h>
+
+static mbedtls_ecp_group_id ecdsa_search_group_id(const char *curve_name)
+{
+       mbedtls_ecp_group_id grp_id = MBEDTLS_ECP_DP_NONE;
+       const mbedtls_ecp_curve_info *info;
+
+       if (!curve_name)
+               goto out;
+
+       if (!strcmp(curve_name, "prime256v1"))
+               grp_id = MBEDTLS_ECP_DP_SECP256R1;

As the statement 'stop on first group found', the grp_id should be returned here.
if (!strcmp(curve_name, "prime256v1"))
return MBEDTLS_ECP_DP_SECP256R1;

Quoted 21 lines
lib/mbedtls/ecdsa.c new file +21 -0
+
+       info = mbedtls_ecp_curve_list();
+       while (info && info->name) {
+               if (!strcmp(curve_name, info->name)) {
+                       grp_id = info->grp_id;
+                       break;
+               }
+               info++;
+       }
+
+ out:
+       return grp_id;
+}
+
+int ecdsa_hash_verify(const struct ecdsa_public_key *pubkey,
+                     const void *hash, size_t hash_len,
+                     const void *signature, size_t sig_len)
+{
+       mbedtls_ecp_group_id grp_id;
+       mbedtls_ecp_group grp;
+       const unsigned char *buf = hash;

lib/mbedtls/ecdsa.c line 51

Quoted 10 lines
lib/mbedtls/ecdsa.c new file +10 -0
+       size_t blen = hash_len;
+       mbedtls_ecp_point Q;
+       mbedtls_mpi r, s;
+       int key_len;
+       int err = -1;
+
+       if (!(pubkey->size_bits % 8))
+               key_len = pubkey->size_bits / 8;
+       else
+               key_len = pubkey->size_bits / 8 + 1;

Please use 'DIV_ROUND_UP(pubkey->size_bits, 8)'.

Quoted 33 lines
lib/mbedtls/ecdsa.c new file +33 -0
+
+       /* check the signature len */
+       if (sig_len != 2 * key_len) {
+               debug("%s: sig len should be twice the key len (sig len = %ld, key len = %d)\n",
+                     __func__, sig_len, key_len);
+               err = -EINVAL;
+               goto out;
+       }
+
+       /* search the group */
+       grp_id = ecdsa_search_group_id(pubkey->curve_name);
+       if (grp_id == MBEDTLS_ECP_DP_NONE) {
+               debug("%s: curve name %s not found\n",
+                     __func__, pubkey->curve_name);
+               err = -EINVAL;
+               goto out;
+       }
+
+       /* init and load the group */
+       mbedtls_ecp_group_init(&grp);
+       err = mbedtls_ecp_group_load(&grp, grp_id);
+       if (err) {
+               err = -EINVAL;
+               goto out1;
+       }
+
+       /* prepare the pubkey */
+       mbedtls_ecp_point_init(&Q);
+       err = mbedtls_mpi_read_binary(&Q.X, pubkey->x, key_len);
+       if (err) {
+               debug("%s: could not read value x of the public key (err = %d)\n",
+                     __func__, err);
+               err = -EINVAL;

lib/mbedtls/ecdsa.c line 94

Quoted 10 lines
lib/mbedtls/ecdsa.c new file +10 -0
+               goto out2;
+       }
+       err = mbedtls_mpi_read_binary(&Q.Y, pubkey->y, key_len);
+       if (err) {
+               debug("%s: could not read value y of the public key (err = %d)\n",
+                     __func__, err);
+               err = -EINVAL;
+               goto out2;
+       }
+       mbedtls_mpi_lset(&Q.Z, 1);

The return code from mbedtls_mpi_lset needs to be checked here.

lib/mbedtls/ecdsa.c line 98

Quoted 4 lines
lib/mbedtls/ecdsa.c new file +4 -0
+
+       /* check if the pubkey is valid */
+       err = mbedtls_ecp_check_pubkey(&grp, &Q);
+       if (err < 0) {

if (err)

Quoted 9 lines
lib/mbedtls/ecdsa.c new file +9 -0
+               debug("%s: public key is invalid (err = %d)\n", __func__, err);
+               err = -EKEYREJECTED;
+               goto out2;
+       }
+
+       /* compute r */
+       mbedtls_mpi_init(&r);
+       err = mbedtls_mpi_read_binary(&r, signature, key_len);
+       if (err) {

lib/mbedtls/ecdsa.c line 117

Quoted 10 lines
lib/mbedtls/ecdsa.c new file +10 -0
+               debug("%s: could not read value r of the signature (err = %d)\n",
+                     __func__, err);
+               err = -EINVAL;
+               goto out3;
+       }
+
+       /* compute s */
+       mbedtls_mpi_init(&s);
+       err = mbedtls_mpi_read_binary(&s, (unsigned char *)signature + key_len,
+                                     key_len);

The casting of 'signature' is not needed.

Regards,
Raymond

Quoted 27 lines
lib/mbedtls/ecdsa.c new file +24 -1
+       if (err) {
+               debug("%s: could not read value s of the signature (err = %d)\n",
+                     __func__, err);
+               err = -EINVAL;
+               goto out4;
+       }
+
+       /* check the signature */
+       err = mbedtls_ecdsa_verify(&grp, buf, blen, &Q, &r, &s);
+       if (err)
+               err = -EINVAL;
+
+ out4:
+       mbedtls_mpi_free(&s);
+ out3:
+       mbedtls_mpi_free(&r);
+ out2:
+       mbedtls_ecp_point_free(&Q);
+ out1:
+       mbedtls_ecp_group_free(&grp);
+ out:
+
+       return err;
+}
--

2.43.0

#6 lore raw

Re: [v3,02/15] ecdsa: initial support of ecdsa using mbedtls

In reply to Philippe Reynes

Hi Philippe,

lib/mbedtls/ecdsa.c line 8

Quoted 10 lines · Philippe Reynes
lib/mbedtls/ecdsa.c +8 -0
@@ -0,0 +1,141 @@
+int ecdsa_hash_verify(const struct ecdsa_public_key *pubkey,
+                   const void *hash, size_t hash_len,
+                   const void *signature, size_t sig_len)
+{
+     mbedtls_ecp_group_id grp_id;
+     mbedtls_ecp_group grp;
+     const unsigned char *buf = hash;
+     size_t blen = hash_len;

The buf and blen variables are not needed - you can pass hash and hash_len directly to mbedtls_ecdsa_verify()

lib/mbedtls/ecdsa.c line 4

Quoted 6 lines
lib/mbedtls/ecdsa.c +4 -0
@@ -0,0 +1,141 @@
+     /* check the signature len */
+     if (sig_len != 2 * key_len) {
+             debug("%s: sig len should be twice the key len (sig len = %ld, key len = %d)\n",
+                   __func__, sig_len, key_len);

The format specifier %ld is not portable for size_t, please use %zu instead.

You can use log_debug() and then don't need __func__

Regards,
Simon

#7 lore raw

PATCH v3 3/15 test: lib: ecdsa: add initial test

In reply to Philippe Reynes

Adds tests to check that the function ecdsa_hash_verify using mbedtls is valid.

---
v2:
- little change to only use test with sha enabled v3:
- remove useless field *k in struct ecdsa_test_vector_s
- change expected value on error (don't use mbedtls error)
- manage function returns
- update third parameter of sha*_csum_wd

 test/lib/Makefile |   1 +
 test/lib/ecdsa.c  | 447 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 448 insertions(+)
 create mode 100644 test/lib/ecdsa.c
test/lib/Makefile +1 -0
index f25383a40e5..2ac80afefdb 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_$(PHASE_)UT_COMPRESSION) += compression.o
 ifeq ($(CONFIG_XPL_BUILD),)
 obj-y += abuf.o
 obj-y += alist.o
+obj-$(CONFIG_ECDSA_MBEDTLS) += ecdsa.o
 obj-$(CONFIG_EFI_LOADER) += efi_device_path.o efi_memory.o
 obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o
 ifdef CONFIG_RISCV
test/lib/ecdsa.c new file +447 -0

447 lines not on this page · raw message

Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH v3 03/15] test: lib: ecdsa: add initial test

Hi Philippe,

Quoted 44 lines · Philippe Reynes

Adds tests to check that the function ecdsa_hash_verify using mbedtls is valid.

---
v2:
- little change to only use test with sha enabled v3:
- remove useless field *k in struct ecdsa_test_vector_s
- change expected value on error (don't use mbedtls error)
- manage function returns
- update third parameter of sha*_csum_wd

 test/lib/Makefile |   1 +
 test/lib/ecdsa.c  | 447 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 448 insertions(+)
 create mode 100644 test/lib/ecdsa.c
test/lib/Makefile +1 -0
index f25383a40e5..2ac80afefdb 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_$(PHASE_)UT_COMPRESSION) += compression.o
 ifeq ($(CONFIG_XPL_BUILD),)
 obj-y += abuf.o
 obj-y += alist.o
+obj-$(CONFIG_ECDSA_MBEDTLS) += ecdsa.o
 obj-$(CONFIG_EFI_LOADER) += efi_device_path.o efi_memory.o
 obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o
 ifdef CONFIG_RISCV
test/lib/ecdsa.c new file +7 -0
new file mode 100644
index 00000000000..95bb84200a6
@@ -0,0 +1,447 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2026 Philippe Reynes <[email protected]>
+ */
+
+#include <command.h>
+#include <image.h>

test/lib/ecdsa.c line 17

Quoted 10 lines
test/lib/ecdsa.c new file +10 -0
+#include <test/lib.h>
+#include <test/test.h>
+#include <test/ut.h>
+#include <crypto/ecdsa-uclass.h>
+#include <crypto/internal/ecdsa.h>
+
+#include <mbedtls/ecp.h>
+
+struct ecdsa_test_vector_s {
+       const char *test_name;

Currently the test_name is useless in the code, can we log it for all tests or at least each failed test?

test/lib/ecdsa.c line 20

Quoted 3 lines
test/lib/ecdsa.c new file +3 -0
+       const char *curve_name;
+       unsigned char *x;
+       unsigned char *y;

const char *x;
const char *y;

test/lib/ecdsa.c line 25

Quoted 5 lines
test/lib/ecdsa.c new file +5 -0
+       int size_bits;
+       unsigned char *hash_type;
+       unsigned char *hash_message;
+       unsigned char *r;
+       unsigned char *s;

const char *hash_type;
const char *hash_message;
const char *r;
const char *s;

test/lib/ecdsa.c line 33

Quoted 8 lines
test/lib/ecdsa.c new file +8 -0
+       int expected;
+};
+
+/*
+ * Those data come from RFC6979
+ */
+
+struct ecdsa_test_vector_s ecdsa_test_vector[] = {

static const struct

Quoted 309 lines
test/lib/ecdsa.c new file +309 -0
+       /*
+        * secp192r1
+        */
+       {
+       .test_name = "secp192r1 sha1",
+       .curve_name = "secp192r1",
+       .x = "AC2C77F529F91689FEA0EA5EFEC7F210D8EEA0B9E047ED56",
+       .y = "3BC723E57670BD4887EBC732C523063D0A7C957BC97C1C43",
+       .size_bits = 192,
+       .hash_type = "sha-1",
+       .hash_message = "sample",
+       .r = "98C6BD12B23EAF5E2A2045132086BE3EB8EBD62ABF6698FF",
+       .s = "57A22B07DEA9530F8DE9471B1DC6624472E8E2844BC25B64",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp192r1 sha256",
+       .curve_name = "secp192r1",
+       .x = "AC2C77F529F91689FEA0EA5EFEC7F210D8EEA0B9E047ED56",
+       .y = "3BC723E57670BD4887EBC732C523063D0A7C957BC97C1C43",
+       .size_bits = 192,
+       .hash_type = "sha-256",
+       .hash_message = "sample",
+       .r = "4B0B8CE98A92866A2820E20AA6B75B56382E0F9BFD5ECB55",
+       .s = "CCDB006926EA9565CBADC840829D8C384E06DE1F1E381B85",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp192r1 sha384",
+       .curve_name = "secp192r1",
+       .x = "AC2C77F529F91689FEA0EA5EFEC7F210D8EEA0B9E047ED56",
+       .y = "3BC723E57670BD4887EBC732C523063D0A7C957BC97C1C43",
+       .size_bits = 192,
+       .hash_type = "sha-384",
+       .hash_message = "sample",
+       .r = "DA63BF0B9ABCF948FBB1E9167F136145F7A20426DCC287D5",
+       .s = "C3AA2C960972BD7A2003A57E1C4C77F0578F8AE95E31EC5E",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp192r1 sha512",
+       .curve_name = "secp192r1",
+       .x = "AC2C77F529F91689FEA0EA5EFEC7F210D8EEA0B9E047ED56",
+       .y = "3BC723E57670BD4887EBC732C523063D0A7C957BC97C1C43",
+       .size_bits = 192,
+       .hash_type = "sha-512",
+       .hash_message = "sample",
+       .r = "4D60C5AB1996BD848343B31C00850205E2EA6922DAC2E4B8",
+       .s = "3F6E837448F027A1BF4B34E796E32A811CBB4050908D8F67",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp192r1 sha512 error",
+       .curve_name = "secp192r1",
+       .x = "AC2C77F529F91689FEA0EA5EFEC7F210D8EEA0B9E047ED56",
+       .y = "3BC723E57670BD4887EBC732C523063D0A7C957BC97C1C43",
+       .size_bits = 192,
+       .hash_type = "sha-512",
+       .hash_message = "sample",
+       .r = "4D60C5AB1996BD848343B31C00850205E2EA6922DAC2E4B8",
+       .s = "0F6E837448F027A1BF4B34E796E32A811CBB4050908D8F67",
+       .expected = -EINVAL,
+       },
+       /*
+        * secp224r1
+        */
+       {
+       .test_name = "secp224r1 sha1",
+       .curve_name = "secp224r1",
+       .x = "00CF08DA5AD719E42707FA431292DEA11244D64FC51610D94B130D6C",
+       .y = "EEAB6F3DEBE455E3DBF85416F7030CBD94F34F2D6F232C69F3C1385A",
+       .size_bits = 224,
+       .hash_type = "sha-1",
+       .hash_message = "sample",
+       .r = "22226F9D40A96E19C4A301CE5B74B115303C0F3A4FD30FC257FB57AC",
+       .s = "66D1CDD83E3AF75605DD6E2FEFF196D30AA7ED7A2EDF7AF475403D69",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp224r1 sha256",
+       .curve_name = "secp224r1",
+       .x = "00CF08DA5AD719E42707FA431292DEA11244D64FC51610D94B130D6C",
+       .y = "EEAB6F3DEBE455E3DBF85416F7030CBD94F34F2D6F232C69F3C1385A",
+       .size_bits = 224,
+       .hash_type = "sha-256",
+       .hash_message = "sample",
+       .r = "61AA3DA010E8E8406C656BC477A7A7189895E7E840CDFE8FF42307BA",
+       .s = "BC814050DAB5D23770879494F9E0A680DC1AF7161991BDE692B10101",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp224r1 sha384",
+       .curve_name = "secp224r1",
+       .x = "00CF08DA5AD719E42707FA431292DEA11244D64FC51610D94B130D6C",
+       .y = "EEAB6F3DEBE455E3DBF85416F7030CBD94F34F2D6F232C69F3C1385A",
+       .size_bits = 224,
+       .hash_type = "sha-384",
+       .hash_message = "sample",
+       .r = "0B115E5E36F0F9EC81F1325A5952878D745E19D7BB3EABFABA77E953",
+       .s = "830F34CCDFE826CCFDC81EB4129772E20E122348A2BBD889A1B1AF1D",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp224r1 sha512",
+       .curve_name = "secp224r1",
+       .x = "00CF08DA5AD719E42707FA431292DEA11244D64FC51610D94B130D6C",
+       .y = "EEAB6F3DEBE455E3DBF85416F7030CBD94F34F2D6F232C69F3C1385A",
+       .size_bits = 224,
+       .hash_type = "sha-512",
+       .hash_message = "sample",
+       .r = "074BD1D979D5F32BF958DDC61E4FB4872ADCAFEB2256497CDAC30397",
+       .s = "A4CECA196C3D5A1FF31027B33185DC8EE43F288B21AB342E5D8EB084",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp224r1 sha512 error",
+       .curve_name = "secp224r1",
+       .x = "00CF08DA5AD719E42707FA431292DEA11244D64FC51610D94B130D6C",
+       .y = "EEAB6F3DEBE455E3DBF85416F7030CBD94F34F2D6F232C69F3C1385A",
+       .size_bits = 224,
+       .hash_type = "sha-512",
+       .hash_message = "sample",
+       .r = "074BD1D979D5F32BF958DDC61E4FB4872ADCAFEB2256497CDAC30397",
+       .s = "04CECA196C3D5A1FF31027B33185DC8EE43F288B21AB342E5D8EB084",
+       .expected = -EINVAL,
+       },
+       /*
+        * secp256r1
+        */
+       {
+       .test_name = "secp256r1 sha1",
+       .curve_name = "secp256r1",
+       .x = "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6",
+       .y = "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299",
+       .size_bits = 256,
+       .hash_type = "sha-1",
+       .hash_message = "sample",
+       .r = "61340C88C3AAEBEB4F6D667F672CA9759A6CCAA9FA8811313039EE4A35471D32",
+       .s = "6D7F147DAC089441BB2E2FE8F7A3FA264B9C475098FDCF6E00D7C996E1B8B7EB",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp256r1 sha256",
+       .curve_name = "secp256r1",
+       .x = "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6",
+       .y = "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299",
+       .size_bits = 256,
+       .hash_type = "sha-256",
+       .hash_message = "sample",
+       .r = "EFD48B2AACB6A8FD1140DD9CD45E81D69D2C877B56AAF991C34D0EA84EAF3716",
+       .s = "F7CB1C942D657C41D436C7A1B6E29F65F3E900DBB9AFF4064DC4AB2F843ACDA8",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp256r1 sha384",
+       .curve_name = "secp256r1",
+       .x = "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6",
+       .y = "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299",
+       .size_bits = 256,
+       .hash_type = "sha-384",
+       .hash_message = "sample",
+       .r = "0EAFEA039B20E9B42309FB1D89E213057CBF973DC0CFC8F129EDDDC800EF7719",
+       .s = "4861F0491E6998B9455193E34E7B0D284DDD7149A74B95B9261F13ABDE940954",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp256r1 sha512",
+       .curve_name = "secp256r1",
+       .x = "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6",
+       .y = "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299",
+       .size_bits = 256,
+       .hash_type = "sha-512",
+       .hash_message = "sample",
+       .r = "8496A60B5E9B47C825488827E0495B0E3FA109EC4568FD3F8D1097678EB97F00",
+       .s = "2362AB1ADBE2B8ADF9CB9EDAB740EA6049C028114F2460F96554F61FAE3302FE",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp256r1 sha512 error",
+       .curve_name = "secp256r1",
+       .x = "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6",
+       .y = "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299",
+       .size_bits = 256,
+       .hash_type = "sha-512",
+       .hash_message = "sample",
+       .r = "8496A60B5E9B47C825488827E0495B0E3FA109EC4568FD3F8D1097678EB97F00",
+       .s = "0362AB1ADBE2B8ADF9CB9EDAB740EA6049C028114F2460F96554F61FAE3302FE",
+       .expected = -EINVAL,
+       },
+       /*
+        * secp384r1
+        */
+       {
+       .test_name = "secp384r1 sha1",
+       .curve_name = "secp384r1",
+       .x = "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64DEF8F0EA9055866064A254515480BC13",
+       .y = "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1288B231C3AE0D4FE7344FD2533264720",
+       .size_bits = 384,
+       .hash_type = "sha-1",
+       .hash_message = "sample",
+       .r = "EC748D839243D6FBEF4FC5C4859A7DFFD7F3ABDDF72014540C16D73309834FA37B9BA002899F6FDA3A4A9386790D4EB2",
+       .s = "A3BCFA947BEEF4732BF247AC17F71676CB31A847B9FF0CBC9C9ED4C1A5B3FACF26F49CA031D4857570CCB5CA4424A443",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp384r1 sha256",
+       .curve_name = "secp384r1",
+       .x = "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64DEF8F0EA9055866064A254515480BC13",
+       .y = "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1288B231C3AE0D4FE7344FD2533264720",
+       .size_bits = 384,
+       .hash_type = "sha-256",
+       .hash_message = "sample",
+       .r = "21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33BDE1E888E63355D92FA2B3C36D8FB2CD",
+       .s = "F3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEBEFDC63ECCD1AC42EC0CB8668A4FA0AB0",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp384r1 sha384",
+       .curve_name = "secp384r1",
+       .x = "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64DEF8F0EA9055866064A254515480BC13",
+       .y = "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1288B231C3AE0D4FE7344FD2533264720",
+       .size_bits = 384,
+       .hash_type = "sha-384",
+       .hash_message = "sample",
+       .r = "94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C81A648152E44ACF96E36DD1E80FABE46",
+       .s = "99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94FA329C145786E679E7B82C71A38628AC8",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp384r1 sha512",
+       .curve_name = "secp384r1",
+       .x = "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64DEF8F0EA9055866064A254515480BC13",
+       .y = "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1288B231C3AE0D4FE7344FD2533264720",
+       .size_bits = 384,
+       .hash_type = "sha-512",
+       .hash_message = "sample",
+       .r = "ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799CFE30F35CC900056D7C99CD7882433709",
+       .s = "512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112DC7CC3EF3446DEFCEB01A45C2667FDD5",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp384r1 sha512 error",
+       .curve_name = "secp384r1",
+       .x = "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64DEF8F0EA9055866064A254515480BC13",
+       .y = "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1288B231C3AE0D4FE7344FD2533264720",
+       .size_bits = 384,
+       .hash_type = "sha-512",
+       .hash_message = "sample",
+       .r = "ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799CFE30F35CC900056D7C99CD7882433709",
+       .s = "012C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112DC7CC3EF3446DEFCEB01A45C2667FDD5",
+       .expected = -EINVAL,
+       },
+       /*
+        * secp521r1
+        */
+       {
+       .test_name = "secp521r1 sha1",
+       .curve_name = "secp521r1",
+       .x = "01894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD371123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F5023A4",
+       .y = "00493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A28A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDFCF5",
+       .size_bits = 521,
+       .hash_type = "sha-1",
+       .hash_message = "sample",
+       .r = "00343B6EC45728975EA5CBA6659BBB6062A5FF89EEA58BE3C80B619F322C87910FE092F7D45BB0F8EEE01ED3F20BABEC079D202AE677B243AB40B5431D497C55D75D",
+       .s = "00E7B0E675A9B24413D448B8CC119D2BF7B2D2DF032741C096634D6D65D0DBE3D5694625FB9E8104D3B842C1B0E2D0B98BEA19341E8676AEF66AE4EBA3D5475D5D16",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp521r1 sha256",
+       .curve_name = "secp521r1",
+       .x = "01894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD371123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F5023A4",
+       .y = "00493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A28A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDFCF5",
+       .size_bits = 521,
+       .hash_type = "sha-256",
+       .hash_message = "sample",
+       .r = "01511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E1A7",
+       .s = "004A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7ECFC",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp521r1 sha384",
+       .curve_name = "secp521r1",
+       .x = "01894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD371123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F5023A4",
+       .y = "00493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A28A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDFCF5",
+       .size_bits = 521,
+       .hash_type = "sha-384",
+       .hash_message = "sample",
+       .r = "01EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67451",
+       .s = "01F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65D61",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp521r1 sha512",
+       .curve_name = "secp521r1",
+       .x = "01894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD371123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F5023A4",
+       .y = "00493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A28A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDFCF5",
+       .size_bits = 521,
+       .hash_type = "sha-512",
+       .hash_message = "sample",
+       .r = "00C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F174E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E377FA",
+       .s = "00617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF282623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A67A",
+       .expected = 0,
+       },
+       {
+       .test_name = "secp521r1 sha512 error",
+       .curve_name = "secp521r1",
+       .x = "01894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD371123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F5023A4",
+       .y = "00493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A28A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDFCF5",
+       .size_bits = 521,

test/lib/ecdsa.c line 352

Quoted 10 lines
test/lib/ecdsa.c new file +10 -0
+       .hash_type = "sha-512",
+       .hash_message = "sample",
+       .r = "00C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F174E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E377FA",
+       .s = "00017CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF282623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A67A",
+       .expected = -EINVAL,
+       },
+};
+
+static int ecdsa_test(struct unit_test_state *uts,
+                     struct ecdsa_test_vector_s *tv)

const struct ecdsa_test_vector *tv

test/lib/ecdsa.c line 358

Quoted 6 lines
test/lib/ecdsa.c new file +6 -0
+{
+       struct ecdsa_public_key pubkey;
+       unsigned char x[528 / 8];
+       unsigned char y[528 / 8];
+       unsigned char hash[512 / 8];
+       unsigned int hash_len;

size_t hash_len;

test/lib/ecdsa.c line 360

Quoted 2 lines
test/lib/ecdsa.c new file +2 -0
+       unsigned char signature[528 / 8 * 2];
+       unsigned int sig_len;

size_t sig_len;

test/lib/ecdsa.c line 366

Quoted 6 lines
test/lib/ecdsa.c new file +6 -0
+       int ret;
+
+       if (!(tv->size_bits % 8))
+               sig_len = tv->size_bits / 8;
+       else
+               sig_len = tv->size_bits / 8 + 1;

DIV_ROUND_UP(tv->size_bits, 8)

Quoted 7 lines
test/lib/ecdsa.c new file +7 -0
+
+       pubkey.curve_name = tv->curve_name;
+       ret = hex2bin(x, tv->x, strlen(tv->x) / 2);
+       ut_asserteq(0, ret);
+       pubkey.x          = x;
+       ret = hex2bin(y, tv->y, strlen(tv->y) / 2);
+       ut_asserteq(0, ret);

test/lib/ecdsa.c line 383

Quoted 10 lines
test/lib/ecdsa.c new file +10 -0
+       pubkey.y          = y;
+       pubkey.size_bits  = tv->size_bits;
+
+       if (!strcmp(tv->hash_type, "sha-1")) {
+#if CONFIG_IS_ENABLED(SHA1)
+               hash_len = SHA1_SUM_LEN;
+               sha1_csum_wd(tv->hash_message, strlen(tv->hash_message),
+                            hash, SHA1_DEF_CHUNK_SZ);
+#else
+               /* sha1 is not supported so we skip this test */

All skipped tests should be logged with 'tv->test_name'. Ditto.

test/lib/ecdsa.c line 390

Quoted 7 lines
test/lib/ecdsa.c new file +7 -0
+               goto out;
+#endif
+       } else if (!strcmp(tv->hash_type, "sha-256")) {
+#if CONFIG_IS_ENABLED(SHA256)
+               hash_len = SHA256_SUM_LEN;
+               sha256_csum_wd(tv->hash_message, strlen(tv->hash_message),
+                              hash, 0x10000);

Suggest to define a SHA256_DEF_CHUNK_SZ in the header then use it.

test/lib/ecdsa.c line 397

Quoted 7 lines
test/lib/ecdsa.c new file +7 -0
+#else
+               /* sha256 is not supported so we skip this test */
+               goto out;
+#endif
+       } else if (!strcmp(tv->hash_type, "sha-384")) {
+#if CONFIG_IS_ENABLED(SHA384)
+               hash_len = SHA384_SUM_LEN;

Suggest to define a SHA384_DEF_CHUNK_SZ in the header then use it.

test/lib/ecdsa.c line 408

Quoted 11 lines
test/lib/ecdsa.c new file +11 -0
+               sha384_csum_wd(tv->hash_message, strlen(tv->hash_message),
+                              hash, 0x10000);
+#else
+               /* sha384 is not supported so we skip this test */
+               goto out;
+#endif
+       } else if (!strcmp(tv->hash_type, "sha-512")) {
+#if CONFIG_IS_ENABLED(SHA512)
+               hash_len = SHA512_SUM_LEN;
+               sha512_csum_wd(tv->hash_message, strlen(tv->hash_message),
+                              hash, 0x10000);

Suggest to define a SHA512_DEF_CHUNK_SZ in the header then use it.

test/lib/ecdsa.c line 415

Quoted 7 lines
test/lib/ecdsa.c new file +7 -0
+#else
+               /* sha512 is not supported so we skip this test */
+               goto out;
+#endif
+       } else {
+               ut_reportf("Unknown hash type (%s)", tv->hash_type);
+               goto out;

Should not return 0 silently, instead:
ut_failf("Unknown hash type (%s)", tv->hash_type); return -EINVAL;

test/lib/ecdsa.c line 418

Quoted 3 lines
test/lib/ecdsa.c new file +3 -0
+       }
+
+       memset(signature, 0, sizeof(signature));

Shall we memset x, y and hash?

Quoted 8 lines
test/lib/ecdsa.c new file +8 -0
+       ret = hex2bin(signature, tv->r, sig_len);
+       ut_asserteq(0, ret);
+       ret = hex2bin(signature + sig_len, tv->s, sig_len);
+       ut_asserteq(0, ret);
+       sig_len = sig_len * 2;
+
+       ret = ecdsa_hash_verify(&pubkey,
+                               hash, hash_len,

test/lib/ecdsa.c line 436

Quoted 10 lines
test/lib/ecdsa.c new file +10 -0
+                               signature, sig_len);
+       ut_asserteq(tv->expected, ret);
+
+ out:
+       return 0;
+}
+
+static int lib_ecdsa(struct unit_test_state *uts)
+{
+       int i, ret, num_test = ARRAY_SIZE(ecdsa_test_vector);

size_t num_test = ARRAY_SIZE(ecdsa_test_vector);

Regards,
Raymond

Quoted 14 lines
test/lib/ecdsa.c new file +11 -1
+
+       for (i = 0; i < num_test; i++) {
+               ret = ecdsa_test(uts, &ecdsa_test_vector[i]);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
+LIB_TEST(lib_ecdsa, 0);
--

2.43.0

#9 lore raw

Re: [v3,03/15] test: lib: ecdsa: add initial test

In reply to Philippe Reynes

Hi Philippe,

test/lib/ecdsa.c line 4

Quoted 6 lines · Philippe Reynes
test/lib/ecdsa.c +4 -0
@@ -0,0 +1,447 @@
+#include <crypto/ecdsa-uclass.h>
+#include <crypto/internal/ecdsa.h>
+
+#include <mbedtls/ecp.h>

This include appears to be unused?

Regards,
Simon

#10 lore raw

PATCH v3 4/15 drivers: crypto: add software ecdsa support

In reply to Philippe Reynes

Add an software ecdsa driver so it is
now possible to use ecdsa signature on
board without ecdsa hardware support.

---
v2:
- no change
v3:
- add depends on ECDSA_VERIFY to ECDSA_SW
- change sw_ecdsa_verify to ecdsa_hash_verify

 drivers/crypto/Kconfig          |  2 ++
 drivers/crypto/Makefile         |  1 +
 drivers/crypto/ecdsa/Kconfig    |  8 ++++++++
 drivers/crypto/ecdsa/Makefile   |  6 ++++++
 drivers/crypto/ecdsa/ecdsa-sw.c | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 50 insertions(+)
 create mode 100644 drivers/crypto/ecdsa/Kconfig
 create mode 100644 drivers/crypto/ecdsa/Makefile
 create mode 100644 drivers/crypto/ecdsa/ecdsa-sw.c
drivers/crypto/Kconfig +2 -0
index 0d58e3910fe..cf49e5c0f7e 100644
@@ -12,4 +12,6 @@ source "drivers/crypto/nuvoton/Kconfig"
 
 source "drivers/crypto/tegra/Kconfig"
 
+source "drivers/crypto/ecdsa/Kconfig"
+
 endmenu
drivers/crypto/Makefile +1 -0
index e4a4482b7f3..8170e4cae9c 100644
@@ -4,6 +4,7 @@
 #	http://www.samsung.com
 
 obj-$(CONFIG_EXYNOS_ACE_SHA)	+= ace_sha.o
+obj-$(CONFIG_ECDSA) += ecdsa/
 obj-y += aes/
 obj-y += rsa_mod_exp/
 obj-y += fsl/
drivers/crypto/ecdsa/Kconfig new file +8 -0
new file mode 100644
index 00000000000..50b65a904ce
@@ -0,0 +1,8 @@
+config ECDSA_SW
+	bool "Enable driver for ECDSA in software"
+	depends on ECDSA_MBEDTLS
+	depends on ECDSA_VERIFY
+	default y if SANDBOX
+	help
+	  Enable driver for ECDSA operations in software. Currently
+	  it supports multiple ECDSA algorithm.
\ No newline at end of file
drivers/crypto/ecdsa/Makefile new file +6 -0
new file mode 100644
index 00000000000..8f9e5a767f8
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2026 Philippe Reynes <[email protected]>
+#
+
+obj-$(CONFIG_ECDSA_SW) += ecdsa-sw.o
drivers/crypto/ecdsa/ecdsa-sw.c new file +33 -0
new file mode 100644
index 00000000000..89ce5a3b888
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2026 Philippe Reynes <[email protected]>
+ */
+#include <dm/device.h>
+#include <linux/types.h>
+#include <u-boot/ecdsa.h>
+#include <crypto/ecdsa-uclass.h>
+#include <dm/platdata.h>
+#include <crypto/internal/ecdsa.h>
+
+static int ops_sw_ecdsa_verify(__always_unused struct udevice *dev,
+			       const struct ecdsa_public_key *pubkey,
+			       const void *hash, size_t hash_len,
+			       const void *signature, size_t sig_len)
+{
+	return ecdsa_hash_verify(pubkey, hash, hash_len, signature, sig_len);
+}
+
+static const struct ecdsa_ops sw_ecdsa_ops = {
+	.verify = ops_sw_ecdsa_verify,
+};
+
+U_BOOT_DRIVER(sw_ecdsa) = {
+	.name	= "sw_ecdsa",
+	.id	= UCLASS_ECDSA,
+	.ops	= &sw_ecdsa_ops,
+	.flags	= DM_FLAG_PRE_RELOC,
+};
+
+U_BOOT_DRVINFO(sw_ecdsa) = {
+	.name = "sw_ecdsa",
+};
Signature · 1 line
2.43.0
#11 lore raw

Re: [v3,04/15] drivers: crypto: add software ecdsa support

Hi Philippe,

drivers/crypto/ecdsa/Kconfig line 4

Quoted 5 lines · Philippe Reynes
drivers/crypto/ecdsa/Kconfig +4 -0
+config ECDSA_SW
+     bool "Enable driver for ECDSA in software"
+     depends on ECDSA_MBEDTLS
+     depends on ECDSA_VERIFY

Raymond has already pointed out on the cover letter that ECDSA_SW may be unnecessary given this is a MbedTLS-only solution. If a future non-MbedTLS software implementation is anticipated, this separation makes sense, but please consider his suggestion to simplify and use ECDSA_MBEDTLS directly.

drivers/crypto/ecdsa/Kconfig line 8

Quoted 4 lines
drivers/crypto/ecdsa/Kconfig +3 -0
+     help
+       Enable driver for ECDSA operations in software. Currently
+       it supports multiple ECDSA algorithm.

\ No newline at end of file

Please add a trailing newline to the Kconfig file. Also "multiple ECDSA algorithm" should be "multiple ECDSA algorithms" (plural).

drivers/crypto/ecdsa/ecdsa-sw.c line 33

Quoted 4 lines
drivers/crypto/ecdsa/ecdsa-sw.c +3 -0
+U_BOOT_DRVINFO(sw_ecdsa) = {
+     .name = "sw_ecdsa",
+};

This file also needs a trailing newline.

drivers/crypto/ecdsa/ecdsa-sw.c line 10

Quoted 7 lines
drivers/crypto/ecdsa/ecdsa-sw.c +6 -0
+#include <dm/device.h>
+#include <linux/types.h>
+#include <u-boot/ecdsa.h>
+#include <crypto/ecdsa-uclass.h>
+#include <dm/platdata.h>
+#include <crypto/internal/ecdsa.h>

Please sort the includes alphabetically as per U-Boot convention. Also <dm.h> is the standard include for driver model, rather than the individual <dm/device.h> and <dm/platdata.h> headers.

Quoted 3 lines

drivers: crypto: add software ecdsa support

Add an software ecdsa driver so it is

Add a software

Regards,
Simon

#12 lore raw

PATCH v3 5/15 ecdsa: fix support of secp521r1

In reply to Philippe Reynes

Current implementation of ecdsa only supports key len aligned on 8 bits. But the curve secp521r1 use a key of 521 bits which is not aligned on 8 bits. In this commit, we update the key management for ecdsa to support key of any lenght.

---
v2:
- intitial version
v3:
- fix typo in comments

 lib/ecdsa/ecdsa-libcrypto.c | 21 +++++++++++++++++++--
 lib/ecdsa/ecdsa-verify.c    | 24 ++++++++++++++++++++++--
 lib/fdt-libcrypto.c         |  2 +-
 tools/image-sig-host.c      |  2 +-
 4 files changed, 43 insertions(+), 6 deletions(-)
lib/ecdsa/ecdsa-libcrypto.c +19 -2
index c4bfb2cec61..f8ed694595c 100644
@@ -45,6 +45,7 @@ static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
 {
 	int x_len;
 	int y_len;
+	int expected_len;
 
 	key->curve_name = fdt_getprop(fdt, node, "ecdsa,curve", NULL);
 	if (!key->curve_name)
@@ -54,6 +55,8 @@ static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
 		key->size_bits = 256;
 	else if (!strcmp(key->curve_name, "secp384r1"))
 		key->size_bits = 384;
+	else if (!strcmp(key->curve_name, "secp521r1"))
+		key->size_bits = 521;
 	else
 		return -EINVAL;
 
@@ -63,7 +66,19 @@ static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
 	if (!key->x || !key->y)
 		return -EINVAL;
 
-	if (x_len != key->size_bits / 8 || y_len != key->size_bits / 8)
+	/*
+	 * The public key is stored as an array of u32, so if the key size is
+	 * not a multiple of 32 (for example 521), we may have extra bytes.
+	 * To avoid any issue later, we shift the x and y pointer to the first
+	 * useful byte.
+	 */
+	expected_len = (key->size_bits + 7) / 8;
+	if (x_len > expected_len)
+		key->x += x_len - expected_len;
+	if (y_len > expected_len)
+		key->y += y_len - expected_len;
+
+	if (x_len < expected_len || y_len < expected_len)
 		return -EINVAL;
 
 	return 0;
@@ -89,6 +104,8 @@ static int read_key_from_fdt(struct signer *ctx, const void *fdt, int node)
 		nid = NID_X9_62_prime256v1;
 	} else if (!strcmp(pubkey.curve_name, "secp384r1")) {
 		nid = NID_secp384r1;
+	} else if (!strcmp(pubkey.curve_name, "secp521r1")) {
+		nid = NID_secp521r1;
 	} else {
 		fprintf(stderr, "Unsupported curve name: '%s'\n", pubkey.curve_name);
 		return -EINVAL;
@@ -111,7 +128,7 @@ static int read_key_from_fdt(struct signer *ctx, const void *fdt, int node)
 		return -ENOMEM;
 	}
 
-	len = pubkey.size_bits / 8;
+	len = (pubkey.size_bits + 7) / 8;
 
 	uint8_t buf[1 + len * 2];
 
lib/ecdsa/ecdsa-verify.c +22 -2
index 629b662cf6c..b90571e9fff 100644
@@ -24,13 +24,15 @@ static int ecdsa_key_size(const char *curve_name)
 		return 256;
 	else if (!strcmp(curve_name, "secp384r1"))
 		return 384;
+	else if (!strcmp(curve_name, "secp521r1"))
+		return 521;
 
 	return 0;
 }
 
 static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
 {
-	int x_len, y_len;
+	int expected_len, x_len, y_len;
 
 	key->curve_name = fdt_getprop(fdt, node, "ecdsa,curve", NULL);
 	if (!key->curve_name) {
@@ -50,7 +52,19 @@ static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
 	if (!key->x || !key->y)
 		return -EINVAL;
 
-	if (x_len != (key->size_bits / 8) || y_len != (key->size_bits / 8)) {
+	/*
+	 * The public key is stored as an array of u32, so if the key size is
+	 * not a multiple of 32 (for example 521), we may have extra bytes.
+	 * To avoid any issue later, we shift the x and y pointer to the first
+	 * useful byte.
+	 */
+	expected_len = (key->size_bits + 7) / 8;
+	if (x_len > expected_len)
+		key->x += x_len - expected_len;
+	if (y_len > expected_len)
+		key->y += y_len - expected_len;
+
+	if (x_len < expected_len || y_len < expected_len) {
 		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;
@@ -135,6 +149,12 @@ U_BOOT_CRYPTO_ALGO(ecdsa384) = {
 	.verify = ecdsa_verify,
 };
 
+U_BOOT_CRYPTO_ALGO(ecdsa521) = {
+	.name = "ecdsa521",
+	.key_len = ECDSA521_BYTES,
+	.verify = ecdsa_verify,
+};
+
 /*
  * uclass definition for ECDSA API
  *
lib/fdt-libcrypto.c +1 -1
index ecb0344c8f6..090246b44e9 100644
@@ -10,7 +10,7 @@
 int fdt_add_bignum(void *blob, int noffset, const char *prop_name,
 		   BIGNUM *num, int num_bits)
 {
-	int nwords = num_bits / 32;
+	int nwords = (num_bits + 31) / 32;
 	int size;
 	uint32_t *buf, *ptr;
 	BIGNUM *tmp, *big2, *big32, *big2_32;
tools/image-sig-host.c +1 -1
index 5285263c616..a2272b196e7 100644
@@ -84,7 +84,7 @@ struct crypto_algo crypto_algos[] = {
 		.verify = ecdsa_verify,
 	},
 	{
-		.name = "secp521r1",
+		.name = "ecdsa521",
 		.key_len = ECDSA521_BYTES,
 		.sign = ecdsa_sign,
 		.add_verify_data = ecdsa_add_verify_data,
Signature · 1 line
2.43.0
#13 lore raw

Re: [PATCH v3 05/15] ecdsa: fix support of secp521r1

Hi Philippe,

Quoted 3 lines · Philippe Reynes

Current implementation of ecdsa only supports key len aligned on 8 bits. But the curve secp521r1 use a key of 521 bits which is not

s/use/uses

Quoted 2 lines

aligned on 8 bits. In this commit, we update the key management for ecdsa to support key of any lenght.

s/key/keys
s/lenght/length
'any' is too arbitrary.

Quoted 37 lines

---
v2:
- intitial version
v3:
- fix typo in comments

 lib/ecdsa/ecdsa-libcrypto.c | 21 +++++++++++++++++++--
 lib/ecdsa/ecdsa-verify.c    | 24 ++++++++++++++++++++++--
 lib/fdt-libcrypto.c         |  2 +-
 tools/image-sig-host.c      |  2 +-
 4 files changed, 43 insertions(+), 6 deletions(-)
lib/ecdsa/ecdsa-libcrypto.c +3 -0
index c4bfb2cec61..f8ed694595c 100644
@@ -45,6 +45,7 @@ static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
 {
        int x_len;
        int y_len;
+       int expected_len;
 
        key->curve_name = fdt_getprop(fdt, node, "ecdsa,curve", NULL);
        if (!key->curve_name)
@@ -54,6 +55,8 @@ static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
                key->size_bits = 256;
        else if (!strcmp(key->curve_name, "secp384r1"))
                key->size_bits = 384;
+       else if (!strcmp(key->curve_name, "secp521r1"))
+               key->size_bits = 521;
        else
                return -EINVAL;
 
@@ -63,7 +66,19 @@ static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
        if (!key->x || !key->y)

lib/ecdsa/ecdsa-libcrypto.c static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node) · line 75

Quoted 10 lines
lib/ecdsa/ecdsa-libcrypto.c +7 -1
                return -EINVAL;
 
-       if (x_len != key->size_bits / 8 || y_len != key->size_bits / 8)
+       /*
+        * The public key is stored as an array of u32, so if the key size is
+        * not a multiple of 32 (for example 521), we may have extra bytes.
+        * To avoid any issue later, we shift the x and y pointer to the first
+        * useful byte.
+        */
+       expected_len = (key->size_bits + 7) / 8;

DIV_ROUND_UP(key->size_bits, 8)

lib/ecdsa/ecdsa-libcrypto.c static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node) · line 77

Quoted 2 lines
lib/ecdsa/ecdsa-libcrypto.c +2 -0
+       if (x_len > expected_len)
+               key->x += x_len - expected_len;

Please don't move the key->x directly, instead, use local variables to store adjusted pointers.

lib/ecdsa/ecdsa-libcrypto.c static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node) · line 79

Quoted 2 lines
lib/ecdsa/ecdsa-libcrypto.c +2 -0
+       if (y_len > expected_len)
+               key->y += y_len - expected_len;

Ditto.

Quoted 48 lines
lib/ecdsa/ecdsa-libcrypto.c +5 -1
+
+       if (x_len < expected_len || y_len < expected_len)
                return -EINVAL;
 
        return 0;
@@ -89,6 +104,8 @@ static int read_key_from_fdt(struct signer *ctx, const void *fdt, int node)
                nid = NID_X9_62_prime256v1;
        } else if (!strcmp(pubkey.curve_name, "secp384r1")) {
                nid = NID_secp384r1;
+       } else if (!strcmp(pubkey.curve_name, "secp521r1")) {
+               nid = NID_secp521r1;
        } else {
                fprintf(stderr, "Unsupported curve name: '%s'\n", pubkey.curve_name);
                return -EINVAL;
@@ -111,7 +128,7 @@ static int read_key_from_fdt(struct signer *ctx, const void *fdt, int node)
                return -ENOMEM;
        }
 
-       len = pubkey.size_bits / 8;
+       len = (pubkey.size_bits + 7) / 8;
 
        uint8_t buf[1 + len * 2];
 
lib/ecdsa/ecdsa-verify.c +3 -1
index 629b662cf6c..b90571e9fff 100644
@@ -24,13 +24,15 @@ static int ecdsa_key_size(const char *curve_name)
                return 256;
        else if (!strcmp(curve_name, "secp384r1"))
                return 384;
+       else if (!strcmp(curve_name, "secp521r1"))
+               return 521;
 
        return 0;
 }
 
 static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
 {
-       int x_len, y_len;
+       int expected_len, x_len, y_len;
 
        key->curve_name = fdt_getprop(fdt, node, "ecdsa,curve", NULL);
        if (!key->curve_name) {
@@ -50,7 +52,19 @@ static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node)
        if (!key->x || !key->y)
                return -EINVAL;
 

lib/ecdsa/ecdsa-verify.c static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node) · line 63

Quoted 10 lines
lib/ecdsa/ecdsa-verify.c +9 -1
-       if (x_len != (key->size_bits / 8) || y_len != (key->size_bits / 8)) {
+       /*
+        * The public key is stored as an array of u32, so if the key size is
+        * not a multiple of 32 (for example 521), we may have extra bytes.
+        * To avoid any issue later, we shift the x and y pointer to the first
+        * useful byte.
+        */
+       expected_len = (key->size_bits + 7) / 8;
+       if (x_len > expected_len)
+               key->x += x_len - expected_len;

Ditto.

lib/ecdsa/ecdsa-verify.c static int fdt_get_key(struct ecdsa_public_key *key, const void *fdt, int node) · line 65

Quoted 2 lines
lib/ecdsa/ecdsa-verify.c +2 -0
+       if (y_len > expected_len)
+               key->y += y_len - expected_len;

Ditto.

Quoted 23 lines
lib/ecdsa/ecdsa-verify.c +8 -0
+
+       if (x_len < expected_len || y_len < expected_len) {
                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;
@@ -135,6 +149,12 @@ U_BOOT_CRYPTO_ALGO(ecdsa384) = {
        .verify = ecdsa_verify,
 };
 
+U_BOOT_CRYPTO_ALGO(ecdsa521) = {
+       .name = "ecdsa521",
+       .key_len = ECDSA521_BYTES,
+       .verify = ecdsa_verify,
+};
+
 /*
  * uclass definition for ECDSA API
  *
lib/fdt-libcrypto.c +0 -0
index ecb0344c8f6..090246b44e9 100644

lib/fdt-libcrypto.c line 13

Quoted 5 lines
lib/fdt-libcrypto.c +1 -1
@@ -10,7 +10,7 @@
 int fdt_add_bignum(void *blob, int noffset, const char *prop_name,
                   BIGNUM *num, int num_bits)
 {
-       int nwords = num_bits / 32;
+       int nwords = (num_bits + 31) / 32;

DIV_ROUND_UP(num_bits, 32)

tools/image-sig-host.c struct crypto_algo crypto_algos[] = { · line 87

Quoted 13 lines
lib/fdt-libcrypto.c +0 -0
        int size;
        uint32_t *buf, *ptr;
        BIGNUM *tmp, *big2, *big32, *big2_32;
tools/image-sig-host.c +1 -1
index 5285263c616..a2272b196e7 100644
@@ -84,7 +84,7 @@ struct crypto_algo crypto_algos[] = {
                .verify = ecdsa_verify,
        },
        {
-               .name = "secp521r1",
+               .name = "ecdsa521",

Does the renaming cause an ABI change and comply with FIT / image signing naming conventions?

Regards,
Raymond

Quoted 6 lines
tools/image-sig-host.c +0 -1
                .key_len = ECDSA521_BYTES,
                .sign = ecdsa_sign,
                .add_verify_data = ecdsa_add_verify_data,
--

2.43.0

#14 lore raw

Re: [v3,05/15] ecdsa: fix support of secp521r1

In reply to Philippe Reynes

Hi Philippe,

tools/image-sig-host.c struct crypto_algo crypto_algos[] = { · line 84

Quoted 4 lines · Philippe Reynes
tools/image-sig-host.c +1 -1
@@ -84,7 +84,7 @@ struct crypto_algo crypto_algos[] = {
-             .name = "secp521r1",
+             .name = "ecdsa521",

Raymond already raised this - Changing this to ecdsa521 breaks backwards compatibility - existing FIT images signed with algo = "sha256,secp521r1" will no longer verify.

If consistency is desired, I suspect the better approach would be to support both names during verification (the old name for compatibility, the new name going forward). What do you think?

Regards,
Simon

#15 lore raw

PATCH v3 6/15 test: dm: ecdsa.c: clean this test as software ecdsa is now implemented

In reply to Philippe Reynes

The test ecdsa was done when ecdsa was only supported by hardware. So it wasn't possible to test ecdsa on sandbox, and there is a test to check that ecdsa is not supported on sandbox.
Now, there is a software implementation of ecdsa. So we remove this outdated test.

---
v2:
- initial version
v3:
- no change

 test/dm/ecdsa.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)
test/dm/ecdsa.c +2 -16
index d7eac7115f7..074b4b25576 100644
@@ -9,29 +9,15 @@
 /*
  * Basic test of the ECDSA uclass and ecdsa_verify()
  *
- * ECDSA implementations in u-boot are hardware-dependent. Until we have a
- * software implementation that can be compiled into the sandbox, all we can
- * test is the uclass support.
- *
- * The uclass_get() test is redundant since ecdsa_verify() would also fail. We
- * run both functions in order to isolate the cause more clearly. i.e. is
- * ecdsa_verify() failing because the UCLASS is absent/broken?
+ * ECDSA software implementation is tested in another test,
+ * so we only check that the class UCLASS_ECDSA may be reached.
  */
 static int dm_test_ecdsa_verify(struct unit_test_state *uts)
 {
 	struct uclass *ucp;
 
-	struct checksum_algo algo = {
-		.checksum_len = 256,
-	};
-
-	struct image_sign_info info = {
-		.checksum = &algo,
-	};
-
 	ut_assertok(uclass_get(UCLASS_ECDSA, &ucp));
 	ut_assertnonnull(ucp);
-	ut_asserteq(-ENODEV, ecdsa_verify(&info, NULL, 0, NULL, 0));
 
 	return 0;
 }
Signature · 1 line
2.43.0
Reviewed-by on v3 6/15
#16 lore raw

Re: [v3,06/15] test: dm: ecdsa.c: clean this test as software ecdsa is now implemented

Hi Philippe,

test/dm/ecdsa.c static int dm_test_ecdsa_verify(struct unit_test_state *uts) · line 9

Quoted 3 lines · Philippe Reynes
test/dm/ecdsa.c +0 -1
@@ -9,29 +9,15 @@ static int dm_test_ecdsa_verify(struct unit_test_state *uts)
-     ut_asserteq(-ENODEV, ecdsa_verify(&info, NULL, 0, NULL, 0));

With the software ECDSA driver now available, this test would no longer return -ENODEV. Rather than just removing this assertion, could the test call ecdsa_verify() with valid test data and check for success? A DM test that exercises the full ecdsa_verify() path would be useful to ensure the driver binding works correctly.

Regards,
Simon

#17 lore raw

PATCH v3 7/15 test: py: vboot: prepare integration test for ecdsa

In reply to Philippe Reynes

The vboot tests only consider rsa algo for signature. To prepare the integration of ecdsa test, the signature algo is now explicit.

---
v2:
- initial version
v3:
- no change

 test/py/tests/test_fit_ecdsa.py               |  2 +-
 test/py/tests/test_vboot.py                   | 99 ++++++++++---------
 ....its => sign-configs-sha1-rsa2048-pss.its} |  0
 ...sha1.its => sign-configs-sha1-rsa2048.its} |  0
 ... sign-configs-sha256-rsa2048-pss-prod.its} |  0
 ...ts => sign-configs-sha256-rsa2048-pss.its} |  0
 ...56.its => sign-configs-sha256-rsa2048.its} |  0
 ...84.its => sign-configs-sha384-rsa3072.its} |  0
 ...s.its => sign-images-sha1-rsa2048-pss.its} |  0
 ...-sha1.its => sign-images-sha1-rsa2048.its} |  0
 ...its => sign-images-sha256-rsa2048-pss.its} |  0
 ...256.its => sign-images-sha256-rsa2048.its} |  0
 ...384.its => sign-images-sha384-rsa3072.its} |  0
 13 files changed, 51 insertions(+), 50 deletions(-)
 rename test/py/tests/vboot/{sign-configs-sha1-pss.its => sign-configs-sha1-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha1.its => sign-configs-sha1-rsa2048.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha256-pss-prod.its => sign-configs-sha256-rsa2048-pss-prod.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha256-pss.its => sign-configs-sha256-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha256.its => sign-configs-sha256-rsa2048.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha384.its => sign-configs-sha384-rsa3072.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha1-pss.its => sign-images-sha1-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha1.its => sign-images-sha1-rsa2048.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha256-pss.its => sign-images-sha256-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha256.its => sign-images-sha256-rsa2048.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha384.its => sign-images-sha384-rsa3072.its} (100%)
test/py/tests/test_fit_ecdsa.py +1 -1
index 3e816d68eb6..e59390374af 100644
@@ -102,7 +102,7 @@ def test_fit_ecdsa(ubman):
     with open(key_file, 'w') as f:
         f.write(key.export_key(format='PEM'))
 
-    assemble_fit_image(fit_file, f'{datadir}/sign-images-sha256.its', tempdir)
+    assemble_fit_image(fit_file, f'{datadir}/sign-images-sha256-rsa2048.its', tempdir)
 
     fit = SignableFitImage(ubman, fit_file)
     nodes = fit.find_signable_image_nodes()
test/py/tests/test_vboot.py +50 -49

198 lines not on this page · raw message

test/py/tests/vboot/sign-configs-sha1-rsa2048-pss.its renamed from test/py/tests/vboot/sign-configs-sha1-pss.its +0 -0
similarity index 100%
rename from test/py/tests/vboot/sign-configs-sha1-pss.its
rename to test/py/tests/vboot/sign-configs-sha1-rsa2048-pss.its
test/py/tests/vboot/sign-configs-sha1-rsa2048.its renamed from test/py/tests/vboot/sign-configs-sha1.its +0 -0
similarity index 100%
rename from test/py/tests/vboot/sign-configs-sha1.its
rename to test/py/tests/vboot/sign-configs-sha1-rsa2048.its
test/py/tests/vboot/sign-configs-sha256-rsa2048-pss-prod.its renamed from test/py/tests/vboot/sign-configs-sha256-pss-prod.its +0 -0
similarity index 100%
rename from test/py/tests/vboot/sign-configs-sha256-pss-prod.its
rename to test/py/tests/vboot/sign-configs-sha256-rsa2048-pss-prod.its
test/py/tests/vboot/sign-configs-sha256-rsa2048-pss.its renamed from test/py/tests/vboot/sign-configs-sha256-pss.its +0 -0
similarity index 100%
rename from test/py/tests/vboot/sign-configs-sha256-pss.its
rename to test/py/tests/vboot/sign-configs-sha256-rsa2048-pss.its
test/py/tests/vboot/sign-configs-sha256-rsa2048.its renamed from test/py/tests/vboot/sign-configs-sha256.its +0 -0
similarity index 100%
rename from test/py/tests/vboot/sign-configs-sha256.its
rename to test/py/tests/vboot/sign-configs-sha256-rsa2048.its
test/py/tests/vboot/sign-configs-sha384-rsa3072.its renamed from test/py/tests/vboot/sign-configs-sha384.its +0 -0
similarity index 100%
rename from test/py/tests/vboot/sign-configs-sha384.its
rename to test/py/tests/vboot/sign-configs-sha384-rsa3072.its
test/py/tests/vboot/sign-images-sha1-rsa2048-pss.its renamed from test/py/tests/vboot/sign-images-sha1-pss.its +0 -0
similarity index 100%
rename from test/py/tests/vboot/sign-images-sha1-pss.its
rename to test/py/tests/vboot/sign-images-sha1-rsa2048-pss.its
test/py/tests/vboot/sign-images-sha1-rsa2048.its renamed from test/py/tests/vboot/sign-images-sha1.its +0 -0
similarity index 100%
rename from test/py/tests/vboot/sign-images-sha1.its
rename to test/py/tests/vboot/sign-images-sha1-rsa2048.its
test/py/tests/vboot/sign-images-sha256-rsa2048-pss.its renamed from test/py/tests/vboot/sign-images-sha256-pss.its +0 -0
similarity index 100%
rename from test/py/tests/vboot/sign-images-sha256-pss.its
rename to test/py/tests/vboot/sign-images-sha256-rsa2048-pss.its
test/py/tests/vboot/sign-images-sha256-rsa2048.its renamed from test/py/tests/vboot/sign-images-sha256.its +0 -0
similarity index 100%
rename from test/py/tests/vboot/sign-images-sha256.its
rename to test/py/tests/vboot/sign-images-sha256-rsa2048.its
test/py/tests/vboot/sign-images-sha384-rsa3072.its renamed from test/py/tests/vboot/sign-images-sha384.its +0 -0
similarity index 100%
rename from test/py/tests/vboot/sign-images-sha384.its
rename to test/py/tests/vboot/sign-images-sha384-rsa3072.its
Signature · 1 line
2.43.0
Reviewed-by on v3 7/15
#18 lore raw

Re: [v3,07/15] test: py: vboot: prepare integration test for ecdsa

Quoted 10 lines · Philippe Reynes

test: py: vboot: prepare integration test for ecdsa

The vboot tests only consider rsa algo for signature. To prepare the integration of ecdsa test, the signature algo is now explicit.

test/py/tests/test_fit_ecdsa.py | 2 +-

Quoted 13 lines
 test/py/tests/test_vboot.py                        | 99 +++++++++++-----------
 ...1-pss.its => sign-configs-sha1-rsa2048-pss.its} |  0
 ...figs-sha1.its => sign-configs-sha1-rsa2048.its} |  0
 ...ts => sign-configs-sha256-rsa2048-pss-prod.its} |  0
 ...pss.its => sign-configs-sha256-rsa2048-pss.its} |  0
 ...-sha256.its => sign-configs-sha256-rsa2048.its} |  0
 ...-sha384.its => sign-configs-sha384-rsa3072.its} |  0
 ...a1-pss.its => sign-images-sha1-rsa2048-pss.its} |  0
 ...mages-sha1.its => sign-images-sha1-rsa2048.its} |  0
 ...-pss.its => sign-images-sha256-rsa2048-pss.its} |  0
 ...s-sha256.its => sign-images-sha256-rsa2048.its} |  0
 ...s-sha384.its => sign-images-sha384-rsa3072.its} |  0
 13 files changed, 51 insertions(+), 50 deletions(-)
#19 lore raw

PATCH v3 8/15 test: vboot: add test for ecdsa

In reply to Philippe Reynes

This commit adds test case for ecdsa on fit, but not (yet) for the global image signature (preload).

---
v2:
- initial version
v3:
- no change

 test/py/tests/test_vboot.py                   | 29 ++++++++++++
 .../vboot/sign-configs-sha256-ecdsa256.its    | 45 +++++++++++++++++++
 .../vboot/sign-configs-sha256-ecdsa384.its    | 45 +++++++++++++++++++
 .../vboot/sign-configs-sha256-ecdsa521.its    | 45 +++++++++++++++++++
 .../vboot/sign-images-sha256-ecdsa256.its     | 42 +++++++++++++++++
 .../vboot/sign-images-sha256-ecdsa384.its     | 42 +++++++++++++++++
 .../vboot/sign-images-sha256-ecdsa521.its     | 42 +++++++++++++++++
 7 files changed, 290 insertions(+)
 create mode 100644 test/py/tests/vboot/sign-configs-sha256-ecdsa256.its
 create mode 100644 test/py/tests/vboot/sign-configs-sha256-ecdsa384.its
 create mode 100644 test/py/tests/vboot/sign-configs-sha256-ecdsa521.its
 create mode 100644 test/py/tests/vboot/sign-images-sha256-ecdsa256.its
 create mode 100644 test/py/tests/vboot/sign-images-sha256-ecdsa384.its
 create mode 100644 test/py/tests/vboot/sign-images-sha256-ecdsa521.its
test/py/tests/test_vboot.py +29 -0
index 496d314c649..4e4d9529031 100644
@@ -94,6 +94,9 @@ TESTDATA_IN = [
     ['sha256-pss-pad', 'sha256', '-rsa2048', '-pss', '-E -p 0x10000', False, False, False, False],
     ['sha256-pss-required', 'sha256', '-rsa2048', '-pss', None, True, False, False, False],
     ['sha256-pss-pad-required', 'sha256', '-rsa2048', '-pss', '-E -p 0x10000', True, True, False, False],
+    ['sha256-basic-ecdsa256', 'sha256', '-ecdsa256', '', None, False, False, False, False],
+    ['sha256-basic-ecdsa384', 'sha256', '-ecdsa384', '', None, False, False, False, False],
+    ['sha256-basic-ecdsa521', 'sha256', '-ecdsa521', '', None, False, False, False, False],
     ['sha384-basic', 'sha384', '-rsa3072', '', None, False, False, False, False],
     ['sha384-pad', 'sha384', '-rsa3072', '', '-E -p 0x10000', False, False, False, False],
     ['algo-arg', 'algo-arg', '', '', '-o sha256,rsa2048', False, False, True, False],
@@ -287,6 +290,29 @@ def test_vboot(ubman, name, sha_algo, sig_algo, padding, sign_options, required,
         utils.run_and_log(ubman, 'openssl req -batch -new -x509 -key %s%s.key '
                           '-out %s%s.crt' % (tmpdir, name, tmpdir, name))
 
+    def create_ecdsa_pair(name):
+        """Generate a new ECDSA key pair
+
+        Args:
+            name: Name of the key (e.g. 'dev')
+        """
+
+        if sig_algo == "-ecdsa256":
+            curve_name = "secp256r1"
+        elif sig_algo == "-ecdsa384":
+            curve_name = "secp384r1"
+        elif sig_algo == "-ecdsa521":
+            curve_name = "secp521r1"
+        else:
+            curve_name = "unknownCurve"
+
+        utils.run_and_log(ubman, 'openssl ecparam -name %s -genkey -noout -out %s%s.pem' %
+                     (curve_name, tmpdir, name))
+
+        # Create a certificate containing the public key
+        utils.run_and_log(ubman, 'openssl req -batch -new -x509 -key %s%s.pem '
+                          '-out %s%s.crt' % (tmpdir, name, tmpdir, name))
+
     def test_with_algo(sha_algo, sig_algo, padding, sign_options):
         """Test verified boot with the given hash algorithm.
 
@@ -537,6 +563,9 @@ def test_vboot(ubman, name, sha_algo, sig_algo, padding, sign_options, required,
     if sig_algo == "-rsa2048" or sig_algo == "-rsa3072" or sig_algo == "":
         create_rsa_pair('dev')
         create_rsa_pair('prod')
+    elif sig_algo == "-ecdsa256" or sig_algo == "-ecdsa384" or sig_algo == "-ecdsa521":
+        create_ecdsa_pair('dev')
+        create_ecdsa_pair('prod')
 
     # Create a number kernel image with zeroes
     with open('%stest-kernel.bin' % tmpdir, 'wb') as fd:
test/py/tests/vboot/sign-configs-sha256-ecdsa256.its new file +45 -0

45 lines not on this page · raw message

test/py/tests/vboot/sign-configs-sha256-ecdsa384.its new file +45 -0

45 lines not on this page · raw message

test/py/tests/vboot/sign-configs-sha256-ecdsa521.its new file +45 -0

45 lines not on this page · raw message

test/py/tests/vboot/sign-images-sha256-ecdsa256.its new file +42 -0

42 lines not on this page · raw message

test/py/tests/vboot/sign-images-sha256-ecdsa384.its new file +42 -0

42 lines not on this page · raw message

test/py/tests/vboot/sign-images-sha256-ecdsa521.its new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v3 8/15
#20 lore raw

Re: [v3,08/15] test: vboot: add test for ecdsa

Quoted 8 lines · Philippe Reynes

test: vboot: add test for ecdsa

This commit adds test case for ecdsa on fit, but not (yet) for the global image signature (preload).

Quoted 8 lines

test/py/tests/test_vboot.py | 29 ++++++++++++++

 .../tests/vboot/sign-configs-sha256-ecdsa256.its   | 45 ++++++++++++++++++++++
 .../tests/vboot/sign-configs-sha256-ecdsa384.its   | 45 ++++++++++++++++++++++
 .../tests/vboot/sign-configs-sha256-ecdsa521.its   | 45 ++++++++++++++++++++++
 .../py/tests/vboot/sign-images-sha256-ecdsa256.its | 42 ++++++++++++++++++++
 .../py/tests/vboot/sign-images-sha256-ecdsa384.its | 42 ++++++++++++++++++++
 .../py/tests/vboot/sign-images-sha256-ecdsa521.its | 42 ++++++++++++++++++++
 7 files changed, 290 insertions(+)
#21 lore raw

PATCH v3 9/15 tools: mkimage: pre-load: add support of ecdsa

In reply to Philippe Reynes

Right now, mkimage can only create pre-load header using rsa. We add the support of ecdsa.

---
v3:
- initial version

 lib/ecdsa/ecdsa-libcrypto.c | 29 ++++++++++----
 tools/image-host.c          | 78 +++++++++++++++++++++++++++++++------
 2 files changed, 88 insertions(+), 19 deletions(-)
lib/ecdsa/ecdsa-libcrypto.c +22 -7
index f8ed694595c..ff396ef9987 100644
@@ -463,14 +463,9 @@ int ecdsa_verify(struct image_sign_info *info,
 	return ret;
 }
 
-static int do_add(struct signer *ctx, void *fdt, const char *key_node_name,
-		  struct image_sign_info *info)
+static int search_key_node(void *fdt, const char *key_node_name)
 {
-	int signature_node, key_node, ret, key_bits;
-	const char *curve_name;
-	const EC_GROUP *group;
-	const EC_POINT *point;
-	BIGNUM *x, *y;
+	int signature_node, key_node;
 
 	signature_node = fdt_subnode_offset(fdt, 0, FIT_SIG_NODENAME);
 	if (signature_node == -FDT_ERR_NOTFOUND) {
@@ -505,6 +500,26 @@ static int do_add(struct signer *ctx, void *fdt, const char *key_node_name,
 		return key_node;
 	}
 
+	return key_node;
+}
+
+static int do_add(struct signer *ctx, void *fdt, const char *key_node_name,
+		  struct image_sign_info *info)
+{
+	int key_node, ret, key_bits;
+	const char *curve_name;
+	const EC_GROUP *group;
+	const EC_POINT *point;
+	BIGNUM *x, *y;
+
+	if (info->required_keynode > 0) {
+		key_node = info->required_keynode;
+	} else {
+		key_node = search_key_node(fdt, key_node_name);
+		if (key_node < 0)
+			return key_node;
+	}
+
 	group = EC_KEY_get0_group(ctx->ecdsa_key);
 	key_bits = EC_GROUP_order_bits(group);
 	curve_name = OBJ_nid2sn(EC_GROUP_get_curve_name(group));
tools/image-host.c +66 -12

102 lines not on this page · raw message

Signature · 1 line
2.43.0
#22 lore raw

Re: [v3,09/15] tools: mkimage: pre-load: add support of ecdsa

Hi Philippe,

tools/image-host.c err_cert: · line 1255

Quoted 13 lines · Philippe Reynes
tools/image-host.c +11 -0
@@ -1244,13 +1245,62 @@ err_cert:
+static int fit_pre_load_data_key_ecdsa(const char *keydir, void *keydest,
+                                    int pre_load_noffset, const void *key_name,
+                                    const void *algo_name)
+{
+     struct image_sign_info info;
+     int keynode;
+
+     memset(&info, 0, sizeof(info));
+     info.keydir = keydir;
+     info.keyname = strdup(key_name);
+     info.name = strdup(algo_name);

Memory is allocated via strdup() for info.keyname and info.name but never freed - please free these before returning.

tools/image-host.c err_cert: · line 1246

Quoted 4 lines
tools/image-host.c +2 -0
@@ -1244,13 +1245,62 @@ err_cert:
+static int fit_pre_load_data_key_ecdsa(const char *keydir, void *keydest,
+                                    int pre_load_noffset, const void *key_name,

The pre_load_noffset parameter is passed in but not used - the function re-calculates the same offset itself.

tools/image-host.c err_cert: · line 1249

Quoted 7 lines
tools/image-host.c +5 -0
@@ -1244,13 +1245,62 @@ err_cert:
+     info.required_keynode = keynode;
+
+     ecdsa_add_verify_data(&info, keydest);
+
+     return 0;

The return value of ecdsa_add_verify_data() is not checked. If it fails, the error is silently ignored. Please can you check the return value and propagate any error.

tools/image-host.c int fit_pre_load_data(const char *keydir, void *keydest, void *fit) · line 1330

Quoted 6 lines
tools/image-host.c +4 -0
@@ -1277,17 +1327,21 @@ int fit_pre_load_data(const char *keydir, void *keydest, void *fit)
+     /* Is it a RSA or an ECDSA key */
+     name = strchr((const char *)algo_name, ',');
+     if (!name)
+             return -EINVAL;

This should use 'goto out' rather than direct return to be consistent with the other error paths in this function.

Regards,
Simon

#23 lore raw

PATCH v3 10/15 tools: binman: pre-load: add support of ecdsa

In reply to Philippe Reynes

Right now, binman can only create pre-load header
using rsa. We add the support of ecdsa.

---
v3:
- initial version

 tools/binman/etype/pre_load.py | 78 ++++++++++++++++++++++++++++++----
 tools/binman/ftest.py          | 31 ++++++++++++++
 2 files changed, 101 insertions(+), 8 deletions(-)
tools/binman/etype/pre_load.py +70 -8
index 00f1a896767..2a2636403d3 100644
@@ -16,8 +16,10 @@ from binman.entry import EntryArg
 
 from Cryptodome.Hash import SHA256, SHA384, SHA512
 from Cryptodome.PublicKey import RSA
+from Cryptodome.PublicKey import ECC
 from Cryptodome.Signature import pkcs1_15
 from Cryptodome.Signature import pss
+from Cryptodome.Signature import DSS
 
 PRE_LOAD_MAGIC = b'UBSH'
 
@@ -27,6 +29,12 @@ RSAS = {
     'rsa4096': 4096 / 8
 }
 
+ECDSAS = {
+    'ecdsa256': 256 / 8 * 2,
+    'ecdsa384': 384 / 8 * 2,
+    'ecdsa521': 132
+}
+
 SHAS = {
     'sha256': SHA256,
     'sha384': SHA384,
@@ -86,17 +94,10 @@ class Entry_pre_load(Entry_collection):
         if self.key_path is None:
             self.key_path = ''
 
-    def _CreateHeader(self):
-        """Create a pre load header"""
-        hash_name, sign_name = self.algo_name.split(',')
-        padding_name = self.padding_name
-        key_name = os.path.join(self.key_path, self.key_name)
-
+    def _CreateHeaderRsa(self, hash_name, sign_name, padding_name, key_name):
         # Check hash and signature name/type
         if hash_name not in SHAS:
             self.Raise(hash_name + " is not supported")
-        if sign_name not in RSAS:
-            self.Raise(sign_name + " is not supported")
 
         # Read the key
         key = RSA.import_key(tools.read_file(key_name))
@@ -151,6 +152,67 @@ class Entry_pre_load(Entry_collection):
 
         return data + pad
 
+    def _CreateHeaderEcdsa(self, hash_name, sign_name, padding_name, key_name):
+        # Check hash and signature name/type
+        if hash_name not in SHAS:
+            self.Raise(hash_name + " is not supported")
+
+        # Read the key
+        key = ECC.import_key(tools.read_file(key_name))
+
+        # Check if the key has the expected size
+        # if key.size_in_bytes() != ECDSAS[sign_name]:
+        #    self.Raise("The key " + self.key_name + " don't have the expected size")
+
+        # Compute the hash
+        hash_image = SHAS[hash_name].new()
+        hash_image.update(self.image)
+
+        # Compute the signature
+        signer = DSS.new(key, 'fips-186-3')
+        sig = signer.sign(hash_image)
+
+        # print("len = %d\n", len(sig))
+
+        hash_sig = SHA256.new()
+        hash_sig.update(sig)
+
+        version = self.version
+        header_size = self.header_size
+        image_size = len(self.image)
+        ofs_img_sig = 64 + len(sig)
+        flags = 0
+        reserved0 = 0
+        reserved1 = 0
+
+        first_header = struct.pack('>4sIIIIIII32s', PRE_LOAD_MAGIC,
+                                   version, header_size, image_size,
+                                   ofs_img_sig, flags, reserved0,
+                                   reserved1, hash_sig.digest())
+
+        hash_first_header = SHAS[hash_name].new()
+        hash_first_header.update(first_header)
+        sig_first_header = signer.sign(hash_first_header)
+
+        data = first_header + sig_first_header + sig
+        pad  = bytearray(self.header_size - len(data))
+
+        return data + pad
+
+    def _CreateHeader(self):
+        """Create a pre load header"""
+        hash_name, sign_name = self.algo_name.split(',')
+        padding_name = self.padding_name
+        key_name = os.path.join(self.key_path, self.key_name)
+
+        if sign_name in RSAS:
+            return self._CreateHeaderRsa(hash_name, sign_name, padding_name, key_name)
+
+        if sign_name in ECDSAS:
+            return self._CreateHeaderEcdsa(hash_name, sign_name, padding_name, key_name)
+
+        self.Raise(sign_name + " is not supported")
+
     def ObtainContents(self):
         """Obtain a placeholder for the header contents"""
         # wait that the image is available
tools/binman/ftest.py +31 -0
index a53e37f31b3..bdb46fbf24f 100644
@@ -5894,6 +5894,37 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
             data = self._DoReadFileDtb('236_pre_load_invalid_key.dts',
                                        entry_args=entry_args)
 
+    def testPreLoadEcdsa(self):
+        """Test an image with a pre-load header using ecdsa key"""
+        entry_args = {
+            'pre-load-key-path': os.path.join(self._binman_dir, 'test'),
+        }
+        data = self._DoReadFileDtb(
+            '351_pre_load_ecdsa.dts', entry_args=entry_args,
+            extra_indirs=[os.path.join(self._binman_dir, 'test')])[0]
+
+        image_fname = tools.get_output_filename('image.bin')
+        is_signed = self._CheckPreload(image_fname, self.TestFile("ecdsa521.pem"), "sha256,ecdsa521")
+
+        self.assertEqual(PRE_LOAD_MAGIC, data[:len(PRE_LOAD_MAGIC)])
+        self.assertEqual(PRE_LOAD_VERSION, data[4:4 + len(PRE_LOAD_VERSION)])
+        self.assertEqual(PRE_LOAD_HDR_SIZE, data[8:8 + len(PRE_LOAD_HDR_SIZE)])
+        self.assertEqual(is_signed, True)
+
+    def testPreLoadEcdsaInvalidSha(self):
+        """Test an image with a pre-load ecdsa header with an invalid hash"""
+        entry_args = {
+            'pre-load-key-path': os.path.join(self._binman_dir, 'test'),
+        }
+        with self.assertRaises(ValueError) as e:
+            self._DoReadFileDtb('352_pre_load_ecdsa_invalid_sha.dts',
+                                entry_args=entry_args)
+
+    def testPreLoadEcdsaInvalidAlgo(self):
+        """Test an image with a pre-load header with an invalid algo"""
+        with self.assertRaises(ValueError) as e:
+            data = self._DoReadFile('353_pre_load_ecdsa_invalid_algo.dts')
+
     def _CheckSafeUniqueNames(self, *images):
         """Check all entries of given images for unsafe unique names"""
         for image in images:
Signature · 1 line
2.43.0
#24 lore raw

Re: [v3,10/15] tools: binman: pre-load: add support of ecdsa

Hi Philippe,

tools/binman/etype/pre_load.py class Entry_pre_load(Entry_collection): · line 162

Quoted 13 lines · Philippe Reynes
tools/binman/etype/pre_load.py +11 -0
@@ -152,6 +152,67 @@ class Entry_pre_load(Entry_collection):
+    def _CreateHeaderEcdsa(self, hash_name, sign_name, padding_name, key_name):
+        # Check hash and signature name/type
+        if hash_name not in SHAS:
+            self.Raise(hash_name + " is not supported")
+
+        # Read the key
+        key = ECC.import_key(tools.read_file(key_name))
+
+        # Check if the key has the expected size
+        # if key.size_in_bytes() != ECDSAS[sign_name]:
+        #    self.Raise("The key " + self.key_name + " don't have the expected size")

Please can you either enable this key size check or remove the commented-out code. Leaving dead code in isn't ideal and suggests the feature is incomplete. If there's a reason the check cannot work, a brief comment explaining why would be helpful.

tools/binman/etype/pre_load.py class Entry_pre_load(Entry_collection): · line 156

Quoted 7 lines
tools/binman/etype/pre_load.py +5 -0
@@ -152,6 +152,67 @@ class Entry_pre_load(Entry_collection):
+        # Compute the signature
+        signer = DSS.new(key, 'fips-186-3')
+        sig = signer.sign(hash_image)
+
+        # print("len = %d\n", len(sig))

Please remove this debug line.

tools/binman/etype/pre_load.py class Entry_pre_load(Entry_collection): · line 152

Quoted 3 lines
tools/binman/etype/pre_load.py +1 -0
@@ -152,6 +152,67 @@ class Entry_pre_load(Entry_collection):
+    def _CreateHeaderEcdsa(self, hash_name, sign_name, padding_name, key_name):

The padding_name argument is passed here but never used in the function body. ECDSA does not use padding like RSA, so this parameter serves no purpose. Please can you either document that it is intentionally ignored (for API consistency) or remove it from the signature and update the caller.

Quoted 5 lines
tools/binman/ftest.py +3 -0
@@ -5894,6 +5894,37 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
+    def testPreLoadEcdsaInvalidSha(self):
+        """Test an image with a pre-load ecdsa header with an invalid hash"""
+        entry_args = {

tools/binman/ftest.py fdt fdtmap Extract the devicetree blob from the fdtmap · line 5906

Quoted 10 lines
tools/binman/ftest.py +10 -0
+            'pre-load-key-path': os.path.join(self._binman_dir, 'test'),
+        }
+        with self.assertRaises(ValueError) as e:
+            self._DoReadFileDtb('352_pre_load_ecdsa_invalid_sha.dts',
+                                entry_args=entry_args)
+
+    def testPreLoadEcdsaInvalidAlgo(self):
+        """Test an image with a pre-load header with an invalid algo"""
+        with self.assertRaises(ValueError) as e:
+            data = self._DoReadFile('353_pre_load_ecdsa_invalid_algo.dts')

The variable 'e' from assertRaises is captured but not used in either test. It would be good to verify the exception message contains the expected error text, similar to how testPreLoadNoKey() does with assertIn().

Also exc is better as we try to avoid single-char var names.

Regards,
Simon

#25 lore raw

PATCH v3 11/15 tools: binman: pre-load: add test for ecdsa

In reply to Philippe Reynes

We add some tests to binman to check the new
support of pre-load header with ecdsa.

---
v3:
- initial version

 tools/binman/test/351_pre_load_ecdsa.dts      | 22 +++++++++++++++++++
 .../test/352_pre_load_ecdsa_invalid_sha.dts   | 22 +++++++++++++++++++
 .../test/353_pre_load_ecdsa_invalid_algo.dts  | 22 +++++++++++++++++++
 tools/binman/test/ecdsa521.pem                |  7 ++++++
 4 files changed, 73 insertions(+)
 create mode 100644 tools/binman/test/351_pre_load_ecdsa.dts
 create mode 100644 tools/binman/test/352_pre_load_ecdsa_invalid_sha.dts
 create mode 100644 tools/binman/test/353_pre_load_ecdsa_invalid_algo.dts
 create mode 100644 tools/binman/test/ecdsa521.pem
tools/binman/test/351_pre_load_ecdsa.dts new file +22 -0
new file mode 100644
index 00000000000..247b85aad4c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		pre-load {
+			content = <&image>;
+			algo-name = "sha256,ecdsa521";
+			key-name = "ecdsa521.pem";
+			header-size = <4096>;
+			version = <0x11223344>;
+		};
+
+		image: blob-ext {
+			filename = "refcode.bin";
+		};
+	};
+};
tools/binman/test/352_pre_load_ecdsa_invalid_sha.dts new file +22 -0
new file mode 100644
index 00000000000..1017707375e
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		pre-load {
+			content = <&image>;
+			algo-name = "sha2560,ecdsa521";
+			key-name = "ecdsa521.pem";
+			header-size = <4096>;
+			version = <0x11223344>;
+		};
+
+		image: blob-ext {
+			filename = "refcode.bin";
+		};
+	};
+};
tools/binman/test/353_pre_load_ecdsa_invalid_algo.dts new file +22 -0
new file mode 100644
index 00000000000..be71edbbdcd
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		pre-load {
+			content = <&image>;
+			algo-name = "sha256,ecdsa5210";
+			key-name = "ecdsa521.pem";
+			header-size = <4096>;
+			version = <0x11223344>;
+		};
+
+		image: blob-ext {
+			filename = "refcode.bin";
+		};
+	};
+};
tools/binman/test/ecdsa521.pem new file +7 -0
new file mode 100644
index 00000000000..ac1904d3955
@@ -0,0 +1,7 @@
+-----BEGIN EC PRIVATE KEY-----
+MIHcAgEBBEIBM+CNnraGci2/mw1wPq44l2HccHnoBbdP3DiU6zqsBOq8IR8uegz2
+FLzWsjxcW7hwROCdEm6tW99wqsyPE25RZ3egBwYFK4EEACOhgYkDgYYABABu5bWV
+aQ4EgnXFjojX9df3gBEBipphEEFAoG87GuoWBdlimFC8UEEXiKNU37w0wlJn4bG0
+8uOKwDqBk3uF+DrmZwB45lCSKkjdRWsJeDt+iEuFe2O/mbXoL4p5D8MM2OsDV5GT
+srUbxhXq+T/i5lV7XXm2+tT/7zU8ZQce6WRufbd9KQ==
+-----END EC PRIVATE KEY-----
Signature · 1 line
2.43.0
#26 lore raw

Re: [v3,11/15] tools: binman: pre-load: add test for ecdsa

Hi Philippe,

tools/binman/test/351_pre_load_ecdsa.dts

Quoted 3 lines · Philippe Reynes
tools/binman/test/351_pre_load_ecdsa.dts new file +0 -0
new file mode 100644
@@ -0,0 +1,22 @@

This patch adds test data files that are referenced by the test code in patch 10.

Please can you squash this patch into patch 10 or move the test data files to patch 10? It's fine to add new functionality and its tests in the same commit.

Regards,
Simon

#27 lore raw

PATCH v3 12/15 boot: pre-load: add support of ecdsa

In reply to Philippe Reynes

Right now, u-boot can only boot image with a
pre-load header with rsa. We add the support
of ecdsa.

---
v3:
- initial version

 boot/image-pre-load.c | 48 +++++++++++++++++++++++++++++++++----------
 1 file changed, 37 insertions(+), 11 deletions(-)
boot/image-pre-load.c +37 -11
index 2f851ebb28c..73d740c4cf2 100644
@@ -70,6 +70,18 @@ static int image_pre_load_sig_setup(struct image_sig_info *info)
 	return 0;
 }
 #else
+
+static int is_ecdsa(const void *algo_name)
+{
+	struct crypto_algo *crypto = image_get_crypto_algo(algo_name);
+	int ret = 0;
+
+	if (crypto && !strncmp(crypto->name, "ecdsa", strlen("ecdsa")))
+		return 1;
+
+	return ret;
+}
+
 /*
  * This function gathers information about the signature check
  * that could be done before launching the image.
@@ -114,11 +126,16 @@ static int image_pre_load_sig_setup(struct image_sig_info *info)
 		goto out;
 	}
 
-	padding_name = fdt_getprop(gd_fdt_blob(), node,
-				   IMAGE_PRE_LOAD_PROP_PADDING_NAME, NULL);
-	if (!padding_name) {
-		log_info("INFO: no padding_name provided, so using pkcs-1.5\n");
-		padding_name = "pkcs-1.5";
+	if (is_ecdsa(algo_name)) {
+		padding_name = NULL;
+	} else {
+		padding_name = fdt_getprop(gd_fdt_blob(), node,
+					   IMAGE_PRE_LOAD_PROP_PADDING_NAME,
+					   NULL);
+		if (!padding_name) {
+			log_info("INFO: no padding_name provided, so using pkcs-1.5\n");
+			padding_name = "pkcs-1.5";
+		}
 	}
 
 	sig_size = fdt_getprop(gd_fdt_blob(), node,
@@ -129,12 +146,17 @@ static int image_pre_load_sig_setup(struct image_sig_info *info)
 		goto out;
 	}
 
-	key = fdt_getprop(gd_fdt_blob(), node,
-			  IMAGE_PRE_LOAD_PROP_PUBLIC_KEY, &key_len);
-	if (!key) {
-		log_err("ERROR: no key for image pre-load sig check\n");
-		ret = -EINVAL;
-		goto out;
+	if (is_ecdsa(algo_name)) {
+		key = NULL;
+		key_len = 0;
+	} else {
+		key = fdt_getprop(gd_fdt_blob(), node,
+				  IMAGE_PRE_LOAD_PROP_PUBLIC_KEY, &key_len);
+		if (!key) {
+			log_err("ERROR: no key for image pre-load sig check\n");
+			ret = -EINVAL;
+			goto out;
+		}
 	}
 
 	info->algo_name		= (char *)algo_name;
@@ -155,6 +177,10 @@ static int image_pre_load_sig_setup(struct image_sig_info *info)
 	info->sig_info.crypto   = image_get_crypto_algo(info->sig_info.name);
 	info->sig_info.key      = info->key;
 	info->sig_info.keylen   = info->key_len;
+	if (is_ecdsa(algo_name)) {
+		info->sig_info.required_keynode = node;
+		info->sig_info.fdt_blob = gd_fdt_blob();
+	}
 
  out:
 	return ret;
Signature · 1 line
2.43.0
#28 lore raw

Re: [v3,12/15] boot: pre-load: add support of ecdsa

Hi Philippe,

boot/image-pre-load.c static int image_pre_load_sig_setup(struct image_sig_info *info) · line 79

Quoted 12 lines · Philippe Reynes
boot/image-pre-load.c +10 -0
@@ -70,6 +70,18 @@ static int image_pre_load_sig_setup(struct image_sig_info *info)
+static int is_ecdsa(const void *algo_name)
+{
+     struct crypto_algo *crypto = image_get_crypto_algo(algo_name);
+     int ret = 0;
+
+     if (crypto && !strncmp(crypto->name, "ecdsa", strlen("ecdsa")))
+             return 1;
+
+     return ret;
+}

This function is called three times in image_pre_load_sig_setup(), calling image_get_crypto_algo() each time.

Coudl we call image_get_crypto_algo() once early in image_pre_load_sig_setup() and then check crypto->name directly in the conditional blocks? This also avoids looking up the algorithm repeatedly.

Also, the return value pattern is a bit awkward - you initialise ret to 0 but never use it since you return 1 directly. Please can you simplify to just return the strncmp result (using !! to get 0/1), or use a simpler pattern like:

if (crypto && !strncmp(crypto->name, "ecdsa", 5))
return 1;
return 0;

Regards,
Simon

#29 lore raw

PATCH v3 13/15 tools: preload_check_sign: add support of ecdsa

In reply to Philippe Reynes

right now, the tool preload_check_sign may only
checks an image with a pre-load header with rsa.
We add the support of pre-load header with ecdsa.

---
v3:
- initial version

 tools/preload_check_sign.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
tools/preload_check_sign.c +24 -0
index ebead459273..6601072be77 100644
@@ -8,6 +8,9 @@
  * complete file. The tool preload_check_sign allows to verify and authenticate
  * a file starting with a preload header.
  */
+
+#define OPENSSL_API_COMPAT 0x10101000L
+
 #include <stdio.h>
 #include <unistd.h>
 #include <openssl/pem.h>
@@ -144,6 +147,27 @@ int main(int argc, char **argv)
 	info.sig_info.key      = info.key;
 	info.sig_info.keylen   = info.key_len;
 
+	/* For ecdsa key, we have to update some values */
+	if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) {
+		EC_KEY *ecdsa_key;
+		const EC_GROUP *group;
+
+		ecdsa_key = EVP_PKEY_get1_EC_KEY(pkey);
+		if (!ecdsa_key) {
+			fprintf(stderr, "Can not extract ECDSA key\n");
+			goto out;
+		}
+
+		group = EC_KEY_get0_group(ecdsa_key);
+		if (!group) {
+			fprintf(stderr, "Can not extract ECDSA group\n");
+			goto out;
+		}
+
+		info.sig_info.keyfile  = keyfile;
+		info.sig_size          = (EC_GROUP_order_bits(group) + 7) / 8 * 2;
+	}
+
 	/* Check the signature */
 	image_pre_load_sig_set_info(&info);
 	ret = image_pre_load_sig((ulong)buffer);
Signature · 1 line
2.43.0
#30 lore raw

Re: [v3,13/15] tools: preload_check_sign: add support of ecdsa

Hi Philippe,

tools/preload_check_sign.c int main(int argc, char **argv) · line 156

Quoted 12 lines · Philippe Reynes
tools/preload_check_sign.c +10 -0
@@ -144,6 +147,27 @@ int main(int argc, char **argv)
+     /* For ecdsa key, we have to update some values */
+     if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) {
+             EC_KEY *ecdsa_key;
+             const EC_GROUP *group;
+
+             ecdsa_key = EVP_PKEY_get1_EC_KEY(pkey);
+             if (!ecdsa_key) {
+                     fprintf(stderr, "Can not extract ECDSA key\n");
+                     goto out;
+             }

EVP_PKEY_get1_EC_KEY() increments the reference count on the returned EC_KEY, so you need to call EC_KEY_free(ecdsa_key) when done with it (see lib/ecdsa/ecdsa-libcrypto.c for the pattern). Otherwise this leaks memory.

tools/preload_check_sign.c int main(int argc, char **argv) · line 157

Quoted 13 lines
tools/preload_check_sign.c +11 -0
@@ -144,6 +147,27 @@ int main(int argc, char **argv)
+             ecdsa_key = EVP_PKEY_get1_EC_KEY(pkey);
+             if (!ecdsa_key) {
+                     fprintf(stderr, "Can not extract ECDSA key\n");
+                     goto out;
+             }
+
+             group = EC_KEY_get0_group(ecdsa_key);
+             if (!group) {
+                     fprintf(stderr, "Can not extract ECDSA group\n");
+                     goto out;
+             }

Both error paths are missing setting ret to EXIT_FAILURE before the goto. Without this, the tool exits with success even when these extractions fail.

Regards,
Simon

#31 lore raw

PATCH v3 14/15 test: py: vboot: prepare test for glocal signature with ecdsa

In reply to Philippe Reynes

The vboot tests only consider rsa for test with global signature. To prepare the integration of test with ecdsa test, the signature algo is now explicit.

---
v3:
- initial version

 test/py/tests/test_vboot.py                          | 12 ++++++------
 ...binman-pss.dts => sandbox-binman-rsa2048-pss.dts} |  0
 ...sandbox-binman.dts => sandbox-binman-rsa2048.dts} |  0
 ...pss.dts => sandbox-u-boot-global-rsa2048-pss.dts} |  0
 ...-global.dts => sandbox-u-boot-global-rsa2048.dts} |  0
 5 files changed, 6 insertions(+), 6 deletions(-)
 rename test/py/tests/vboot/{sandbox-binman-pss.dts => sandbox-binman-rsa2048-pss.dts} (100%)
 rename test/py/tests/vboot/{sandbox-binman.dts => sandbox-binman-rsa2048.dts} (100%)
 rename test/py/tests/vboot/{sandbox-u-boot-global-pss.dts => sandbox-u-boot-global-rsa2048-pss.dts} (100%)
 rename test/py/tests/vboot/{sandbox-u-boot-global.dts => sandbox-u-boot-global-rsa2048.dts} (100%)
test/py/tests/test_vboot.py +6 -6
index 4e4d9529031..22865f653c5 100644
@@ -503,7 +503,7 @@ def test_vboot(ubman, name, sha_algo, sig_algo, padding, sign_options, required,
                           dtb)
         run_bootm(sha_algo, 'multi required key', '', False)
 
-    def test_global_sign(sha_algo, padding, sign_options):
+    def test_global_sign(sha_algo, sig_algo, padding, sign_options):
         """Test global image signature with the given hash algorithm and padding.
 
         Args:
@@ -512,14 +512,14 @@ def test_vboot(ubman, name, sha_algo, sig_algo, padding, sign_options, required,
                     rsa signature algorithm.
         """
 
-        dtb = '%ssandbox-u-boot-global%s.dtb' % (tmpdir, padding)
+        dtb = '%ssandbox-u-boot-global%s%s.dtb' % (tmpdir, sig_algo, padding)
         ubman.config.dtb = dtb
 
         # Compile our device tree files for kernel and U-Boot. These are
         # regenerated here since mkimage will modify them (by adding a
         # public key) below.
         dtc('sandbox-kernel.dts', ubman, dtc_args, datadir, tmpdir, dtb)
-        dtc_options('sandbox-u-boot-global%s.dts' % padding, '-p 1024')
+        dtc_options('sandbox-u-boot-global%s%s.dts' % (sig_algo, padding), '-p 1024')
 
         # Build the FIT with dev key (keys NOT required). This adds the
         # signature into sandbox-u-boot.dtb, NOT marked 'required'.
@@ -528,11 +528,11 @@ def test_vboot(ubman, name, sha_algo, sig_algo, padding, sign_options, required,
 
         # Build the dtb for binman that define the pre-load header
         # with the global sigature.
-        dtc('sandbox-binman%s.dts' % padding, ubman, dtc_args, datadir, tmpdir, dtb)
+        dtc('sandbox-binman%s%s.dts' % (sig_algo, padding), ubman, dtc_args, datadir, tmpdir, dtb)
 
         # Run binman to create the final image with the not signed fit
         # and the pre-load header that contains the global signature.
-        run_binman('sandbox-binman%s.dtb' % padding)
+        run_binman('sandbox-binman%s%s.dtb' % (sig_algo, padding))
 
         # Check that the signature is correctly verified by u-boot
         run_bootm(sha_algo, 'global image signature',
@@ -582,7 +582,7 @@ def test_vboot(ubman, name, sha_algo, sig_algo, padding, sign_options, required,
     try:
         ubman.config.dtb = dtb
         if global_sign:
-            test_global_sign(sha_algo, padding, sign_options)
+            test_global_sign(sha_algo, sig_algo, padding, sign_options)
         elif required:
             test_required_key(sha_algo, sig_algo, padding, sign_options)
         else:
test/py/tests/vboot/sandbox-binman-rsa2048-pss.dts renamed from test/py/tests/vboot/sandbox-binman-pss.dts +0 -0
similarity index 100%
rename from test/py/tests/vboot/sandbox-binman-pss.dts
rename to test/py/tests/vboot/sandbox-binman-rsa2048-pss.dts
test/py/tests/vboot/sandbox-binman-rsa2048.dts renamed from test/py/tests/vboot/sandbox-binman.dts +0 -0
similarity index 100%
rename from test/py/tests/vboot/sandbox-binman.dts
rename to test/py/tests/vboot/sandbox-binman-rsa2048.dts
test/py/tests/vboot/sandbox-u-boot-global-rsa2048-pss.dts renamed from test/py/tests/vboot/sandbox-u-boot-global-pss.dts +0 -0
similarity index 100%
rename from test/py/tests/vboot/sandbox-u-boot-global-pss.dts
rename to test/py/tests/vboot/sandbox-u-boot-global-rsa2048-pss.dts
test/py/tests/vboot/sandbox-u-boot-global-rsa2048.dts renamed from test/py/tests/vboot/sandbox-u-boot-global.dts +0 -0
similarity index 100%
rename from test/py/tests/vboot/sandbox-u-boot-global.dts
rename to test/py/tests/vboot/sandbox-u-boot-global-rsa2048.dts
Signature · 1 line
2.43.0
#32 lore raw

Re: [v3,14/15] test: py: vboot: prepare test for glocal signature with ecdsa

Hi Philippe,

Quoted 1 line · Philippe Reynes

test: py: vboot: prepare test for glocal signature with ecdsa

global

Regards,
Simon

#33 lore raw

PATCH v3 15/15 test: py: vboot: add test for global signature with ecdsa

In reply to Philippe Reynes

As now u-boot supports pre-load header with ecdsa, we add some tests to vboot with ecdsa pre-load header.

---
v3:
- initial version

 test/py/tests/test_vboot.py                   |  3 +++
 .../tests/vboot/sandbox-binman-ecdsa256.dts   | 24 +++++++++++++++++
 .../tests/vboot/sandbox-binman-ecdsa384.dts   | 24 +++++++++++++++++
 .../tests/vboot/sandbox-binman-ecdsa521.dts   | 24 +++++++++++++++++
 .../vboot/sandbox-u-boot-global-ecdsa256.dts  | 27 +++++++++++++++++++
 .../vboot/sandbox-u-boot-global-ecdsa384.dts  | 27 +++++++++++++++++++
 .../vboot/sandbox-u-boot-global-ecdsa521.dts  | 27 +++++++++++++++++++
 7 files changed, 156 insertions(+)
 create mode 100644 test/py/tests/vboot/sandbox-binman-ecdsa256.dts
 create mode 100644 test/py/tests/vboot/sandbox-binman-ecdsa384.dts
 create mode 100644 test/py/tests/vboot/sandbox-binman-ecdsa521.dts
 create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-ecdsa256.dts
 create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-ecdsa384.dts
 create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-ecdsa521.dts
test/py/tests/test_vboot.py +3 -0
index 22865f653c5..e0366e06ddb 100644
@@ -102,6 +102,9 @@ TESTDATA_IN = [
     ['algo-arg', 'algo-arg', '', '', '-o sha256,rsa2048', False, False, True, False],
     ['sha256-global-sign', 'sha256', '-rsa2048', '', '', False, False, False, True],
     ['sha256-global-sign-pss', 'sha256', '-rsa2048', '-pss', '', False, False, False, True],
+    ['sha256-global-sign-ecdsa256', 'sha256', '-ecdsa256', '', '', False, False, False, True],
+    ['sha256-global-sign-ecdsa384', 'sha256', '-ecdsa384', '', '', False, False, False, True],
+    ['sha256-global-sign-ecdsa521', 'sha256', '-ecdsa521', '', '', False, False, False, True],
 ]
 
 # Mark all but the first test as slow, so they are not run with '-k not slow'
test/py/tests/vboot/sandbox-binman-ecdsa256.dts new file +24 -0
new file mode 100644
index 00000000000..0e84b81078b
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		filename = "sandbox.img";
+
+		pre-load {
+			 content = <&image>;
+			 algo-name = "sha256,ecdsa256";
+			 key-name = "dev.pem";
+			 header-size = <4096>;
+			 version = <1>;
+		};
+
+		image: blob-ext {
+			 filename = "test.fit";
+		};
+	};
+};
test/py/tests/vboot/sandbox-binman-ecdsa384.dts new file +24 -0
new file mode 100644
index 00000000000..56faf67fe57
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		filename = "sandbox.img";
+
+		pre-load {
+			 content = <&image>;
+			 algo-name = "sha256,ecdsa384";
+			 key-name = "dev.pem";
+			 header-size = <4096>;
+			 version = <1>;
+		};
+
+		image: blob-ext {
+			 filename = "test.fit";
+		};
+	};
+};
test/py/tests/vboot/sandbox-binman-ecdsa521.dts new file +24 -0
new file mode 100644
index 00000000000..8e2fc3de31d
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		filename = "sandbox.img";
+
+		pre-load {
+			 content = <&image>;
+			 algo-name = "sha256,ecdsa521";
+			 key-name = "dev.pem";
+			 header-size = <4096>;
+			 version = <1>;
+		};
+
+		image: blob-ext {
+			 filename = "test.fit";
+		};
+	};
+};
test/py/tests/vboot/sandbox-u-boot-global-ecdsa256.dts new file +27 -0
new file mode 100644
index 00000000000..f15ada3987c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	model = "Sandbox Verified Boot Test";
+	compatible = "sandbox";
+
+	binman {
+	};
+
+	reset@0 {
+		compatible = "sandbox,reset";
+	};
+
+	image {
+		pre-load {
+			sig {
+				algo-name = "sha256,ecdsa256";
+				signature-size = <64>;
+				mandatory = "yes";
+
+				key-name = "dev";
+			};
+		};
+	};
+};
test/py/tests/vboot/sandbox-u-boot-global-ecdsa384.dts new file +27 -0
new file mode 100644
index 00000000000..24540ace249
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	model = "Sandbox Verified Boot Test";
+	compatible = "sandbox";
+
+	binman {
+	};
+
+	reset@0 {
+		compatible = "sandbox,reset";
+	};
+
+	image {
+		pre-load {
+			sig {
+				algo-name = "sha256,ecdsa384";
+				signature-size = <96>;
+				mandatory = "yes";
+
+				key-name = "dev";
+			};
+		};
+	};
+};
test/py/tests/vboot/sandbox-u-boot-global-ecdsa521.dts new file +27 -0
new file mode 100644
index 00000000000..72fa3b2c790
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	model = "Sandbox Verified Boot Test";
+	compatible = "sandbox";
+
+	binman {
+	};
+
+	reset@0 {
+		compatible = "sandbox,reset";
+	};
+
+	image {
+		pre-load {
+			sig {
+				algo-name = "sha256,ecdsa521";
+				signature-size = <132>;
+				mandatory = "yes";
+
+				key-name = "dev";
+			};
+		};
+	};
+};
Signature · 1 line
2.43.0
Reviewed-by on v3 15/15
#34 lore raw

Re: [v3, 15/15] test: py: vboot: add test for global signature with ecdsa

Quoted 7 lines · Philippe Reynes

test: py: vboot: add test for global signature with ecdsa

As now u-boot supports pre-load header with ecdsa, we add some tests to vboot with ecdsa pre-load header.

Quoted 8 lines

test/py/tests/test_vboot.py | 3 +++

 test/py/tests/vboot/sandbox-binman-ecdsa256.dts    | 24 +++++++++++++++++++
 test/py/tests/vboot/sandbox-binman-ecdsa384.dts    | 24 +++++++++++++++++++
 test/py/tests/vboot/sandbox-binman-ecdsa521.dts    | 24 +++++++++++++++++++
 .../tests/vboot/sandbox-u-boot-global-ecdsa256.dts | 27 ++++++++++++++++++++++
 .../tests/vboot/sandbox-u-boot-global-ecdsa384.dts | 27 ++++++++++++++++++++++
 .../tests/vboot/sandbox-u-boot-global-ecdsa521.dts | 27 ++++++++++++++++++++++
 7 files changed, 156 insertions(+)
#35 lore raw
In reply to Philippe Reynes
Quoted 34 lines · Philippe Reynes

This serie adds the support of ecdsa with software using mbedtls. So boards without ecdsa hardware may also use signature with ecdsa.

To add the support of ecdsa with mbedtls, I have:
- enabled ecdsa in mbedtls
- add a function sw_ecdsa_verify that uses mbedtls
- add a driver sw_ecdsa that call sw_ecdsa_verify

I have tested this code with sandbox, and I have followed those steps:

0) build u-boot using sandbox_defconfig and adding those options:
CONFIG_ECDSA_SW=y
CONFIG_ECDSA_MBEDTLS=y
CONFIG_ECDSA=y
CONFIG_ECDSA_VERIFY=y

1) add a signature node to an its file

	signature-256 {
		algo = "sha256,ecdsa256";
		key-name-hint = "private-key-256";
	};

2) generate an ecdsa key
openssl ecparam -name prime256v1 -genkey -noout -out private-key-256.pem

3) create the itb file
./tools/mkimage -f <file.its> -k . -K arch/sandbox/dts/test.dtb <file.itb>

4) launch sandbox u-boot

./u-boot -d arch/sandbox/dts/test.dtb

Quoted 8 lines

5) on sandbox u-boot prompt, load the itb and launch bootm on it

=> host load hostfs - 1000000 uboot-ecdsa.itb
4628674 bytes read in 1 ms (4.3 GiB/s)
=> bootm 1000000
...
...
Verifying Hash Integrity ... sha256,ecdsa256:private-key-256+ OK

For the next iteration can you please add this as part of the series, so CI tests it? And also put it through Azure at least to make sure there's no other testing surprises that come out. Thanks!

Signature · 1 line
Tom
#36 lore raw
In reply to Philippe Reynes

Hi Philippe,

Quoted 10 lines · Philippe Reynes

This serie adds the support of ecdsa with software using mbedtls. So boards without ecdsa hardware may also use signature with ecdsa.

To add the support of ecdsa with mbedtls, I have:
- enabled ecdsa in mbedtls
- add a function sw_ecdsa_verify that uses mbedtls
- add a driver sw_ecdsa that call sw_ecdsa_verify

Quoted 6 lines

I have tested this code with sandbox, and I have followed those steps:

0) build u-boot using sandbox_defconfig and adding those options:
CONFIG_ECDSA_SW=y
CONFIG_ECDSA_MBEDTLS=y

Same comment as I placed in V2:
As this series introduces a MbedTLS-only solution, duplicating a CONFIG_ECDSA_SW is not necessary, you can just use CONFIG_ECDSA_MBEDTLS when linking with ecdsa-sw.o.

Regards,
Raymond

Quoted 170 lines

CONFIG_ECDSA=y
CONFIG_ECDSA_VERIFY=y

1) add a signature node to an its file

        signature-256 {
                algo = "sha256,ecdsa256";
                key-name-hint = "private-key-256";
        };

2) generate an ecdsa key
openssl ecparam -name prime256v1 -genkey -noout -out private-key-256.pem

3) create the itb file
./tools/mkimage -f <file.its> -k . -K arch/sandbox/dts/test.dtb <file.itb>

4) launch sandbox u-boot

./u-boot -d arch/sandbox/dts/test.dtb

5) on sandbox u-boot prompt, load the itb and launch bootm on it

=> host load hostfs - 1000000 uboot-ecdsa.itb
4628674 bytes read in 1 ms (4.3 GiB/s)
=> bootm 1000000
...
...
Verifying Hash Integrity ... sha256,ecdsa256:private-key-256+ OK

I have tested with success ecdsa256 and ecdsa384, but there is an issue with secp521r1.

Changes in v2:
- move ECDSA_MBEDTLS to MBEDTLS_LIB_X509
- rename lib/mbedtls/sw_ecdsa.c to lib/mbedtls/ecdsa.c
- enhance dependancies for ECDSA_MBEDTLS
- fix support of ecdsa521/secp521r1
- add vboot test using ecdsa

Changes in v3:
- do not use _MBEDTLS in mbedtls_def_config.h
- check returns and remove mem leak in lib/mbedtls/ecdsa.c
- remove useless field *k in struct ecdsa_test_vector_s
- check returns in test/lib/ecdsa.c
- fix third parameter when calling sha*_csum_wd()
- add support of ecdsa in pre-load header

Philippe Reynes (15):
mbedtls: enable support of ecc
ecdsa: initial support of ecdsa using mbedtls
test: lib: ecdsa: add initial test
drivers: crypto: add software ecdsa support
ecdsa: fix support of secp521r1
test: dm: ecdsa.c: clean this test as software ecdsa is now
implemented
test: py: vboot: prepare integration test for ecdsa
test: vboot: add test for ecdsa
tools: mkimage: pre-load: add support of ecdsa
tools: binman: pre-load: add support of ecdsa
tools: binman: pre-load: add test for ecdsa
boot: pre-load: add support of ecdsa
tools: preload_check_sign: add support of ecdsa
test: py: vboot: prepare test for glocal signature with ecdsa
test: py: vboot: add test for global signature with ecdsa

 boot/image-pre-load.c                         |  48 +-
 configs/amd_versal2_virt_defconfig            |   1 +
 configs/qemu_arm64_lwip_defconfig             |   1 +
 configs/starfive_visionfive2_defconfig        |   1 +
 configs/xilinx_versal_net_virt_defconfig      |   1 +
 configs/xilinx_versal_virt_defconfig          |   1 +
 configs/xilinx_zynqmp_kria_defconfig          |   1 +
 configs/xilinx_zynqmp_virt_defconfig          |   1 +
 drivers/crypto/Kconfig                        |   2 +
 drivers/crypto/Makefile                       |   1 +
 drivers/crypto/ecdsa/Kconfig                  |   8 +
 drivers/crypto/ecdsa/Makefile                 |   6 +
 drivers/crypto/ecdsa/ecdsa-sw.c               |  33 ++
 include/crypto/internal/ecdsa.h               |  14 +
 lib/ecdsa/ecdsa-libcrypto.c                   |  50 +-
 lib/ecdsa/ecdsa-verify.c                      |  24 +-
 lib/fdt-libcrypto.c                           |   2 +-
 lib/mbedtls/Kconfig                           |  16 +
 lib/mbedtls/Makefile                          |  19 +-
 lib/mbedtls/ecdsa.c                           | 141 ++++++
 lib/mbedtls/mbedtls_def_config.h              |  18 +
 test/dm/ecdsa.c                               |  18 +-
 test/lib/Makefile                             |   1 +
 test/lib/ecdsa.c                              | 447 ++++++++++++++++++
 test/py/tests/test_fit_ecdsa.py               |   2 +-
 test/py/tests/test_vboot.py                   | 143 +++---
 .../tests/vboot/sandbox-binman-ecdsa256.dts   |  24 +
 .../tests/vboot/sandbox-binman-ecdsa384.dts   |  24 +
 .../tests/vboot/sandbox-binman-ecdsa521.dts   |  24 +
 ...pss.dts => sandbox-binman-rsa2048-pss.dts} |   0
 ...-binman.dts => sandbox-binman-rsa2048.dts} |   0
 .../vboot/sandbox-u-boot-global-ecdsa256.dts  |  27 ++
 .../vboot/sandbox-u-boot-global-ecdsa384.dts  |  27 ++
 .../vboot/sandbox-u-boot-global-ecdsa521.dts  |  27 ++
 ... => sandbox-u-boot-global-rsa2048-pss.dts} |   0
 ....dts => sandbox-u-boot-global-rsa2048.dts} |   0
 ....its => sign-configs-sha1-rsa2048-pss.its} |   0
 ...sha1.its => sign-configs-sha1-rsa2048.its} |   0
 .../vboot/sign-configs-sha256-ecdsa256.its    |  45 ++
 .../vboot/sign-configs-sha256-ecdsa384.its    |  45 ++
 .../vboot/sign-configs-sha256-ecdsa521.its    |  45 ++
 ... sign-configs-sha256-rsa2048-pss-prod.its} |   0
 ...ts => sign-configs-sha256-rsa2048-pss.its} |   0
 ...56.its => sign-configs-sha256-rsa2048.its} |   0
 ...84.its => sign-configs-sha384-rsa3072.its} |   0
 ...s.its => sign-images-sha1-rsa2048-pss.its} |   0
 ...-sha1.its => sign-images-sha1-rsa2048.its} |   0
 .../vboot/sign-images-sha256-ecdsa256.its     |  42 ++
 .../vboot/sign-images-sha256-ecdsa384.its     |  42 ++
 .../vboot/sign-images-sha256-ecdsa521.its     |  42 ++
 ...its => sign-images-sha256-rsa2048-pss.its} |   0
 ...256.its => sign-images-sha256-rsa2048.its} |   0
 ...384.its => sign-images-sha384-rsa3072.its} |   0
 tools/binman/etype/pre_load.py                |  78 ++-
 tools/binman/ftest.py                         |  31 ++
 tools/binman/test/351_pre_load_ecdsa.dts      |  22 +
 .../test/352_pre_load_ecdsa_invalid_sha.dts   |  22 +
 .../test/353_pre_load_ecdsa_invalid_algo.dts  |  22 +
 tools/binman/test/ecdsa521.pem                |   7 +
 tools/image-host.c                            |  78 ++-
 tools/image-sig-host.c                        |   2 +-
 tools/preload_check_sign.c                    |  24 +
 62 files changed, 1577 insertions(+), 123 deletions(-)
 create mode 100644 drivers/crypto/ecdsa/Kconfig
 create mode 100644 drivers/crypto/ecdsa/Makefile
 create mode 100644 drivers/crypto/ecdsa/ecdsa-sw.c
 create mode 100644 include/crypto/internal/ecdsa.h
 create mode 100644 lib/mbedtls/ecdsa.c
 create mode 100644 test/lib/ecdsa.c
 create mode 100644 test/py/tests/vboot/sandbox-binman-ecdsa256.dts
 create mode 100644 test/py/tests/vboot/sandbox-binman-ecdsa384.dts
 create mode 100644 test/py/tests/vboot/sandbox-binman-ecdsa521.dts
 rename test/py/tests/vboot/{sandbox-binman-pss.dts => sandbox-binman-rsa2048-pss.dts} (100%)
 rename test/py/tests/vboot/{sandbox-binman.dts => sandbox-binman-rsa2048.dts} (100%)
 create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-ecdsa256.dts
 create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-ecdsa384.dts
 create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-ecdsa521.dts
 rename test/py/tests/vboot/{sandbox-u-boot-global-pss.dts => sandbox-u-boot-global-rsa2048-pss.dts} (100%)
 rename test/py/tests/vboot/{sandbox-u-boot-global.dts => sandbox-u-boot-global-rsa2048.dts} (100%)
 rename test/py/tests/vboot/{sign-configs-sha1-pss.its => sign-configs-sha1-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha1.its => sign-configs-sha1-rsa2048.its} (100%)
 create mode 100644 test/py/tests/vboot/sign-configs-sha256-ecdsa256.its
 create mode 100644 test/py/tests/vboot/sign-configs-sha256-ecdsa384.its
 create mode 100644 test/py/tests/vboot/sign-configs-sha256-ecdsa521.its
 rename test/py/tests/vboot/{sign-configs-sha256-pss-prod.its => sign-configs-sha256-rsa2048-pss-prod.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha256-pss.its => sign-configs-sha256-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha256.its => sign-configs-sha256-rsa2048.its} (100%)
 rename test/py/tests/vboot/{sign-configs-sha384.its => sign-configs-sha384-rsa3072.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha1-pss.its => sign-images-sha1-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha1.its => sign-images-sha1-rsa2048.its} (100%)
 create mode 100644 test/py/tests/vboot/sign-images-sha256-ecdsa256.its
 create mode 100644 test/py/tests/vboot/sign-images-sha256-ecdsa384.its
 create mode 100644 test/py/tests/vboot/sign-images-sha256-ecdsa521.its
 rename test/py/tests/vboot/{sign-images-sha256-pss.its => sign-images-sha256-rsa2048-pss.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha256.its => sign-images-sha256-rsa2048.its} (100%)
 rename test/py/tests/vboot/{sign-images-sha384.its => sign-images-sha384-rsa3072.its} (100%)
 create mode 100644 tools/binman/test/351_pre_load_ecdsa.dts
 create mode 100644 tools/binman/test/352_pre_load_ecdsa_invalid_sha.dts
 create mode 100644 tools/binman/test/353_pre_load_ecdsa_invalid_algo.dts
 create mode 100644 tools/binman/test/ecdsa521.pem

--
2.43.0

#37 lore raw
In reply to Philippe Reynes

Hi Philippe,,

Quoted 2 lines · Philippe Reynes

This serie adds the support of ecdsa with software using mbedtls.

Thanks for this series, a useful feature! Sorry for not reviewing an earlier version.

Regards,
Simon