public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* How to use ECDSA for signature verification?
@ 2025-10-13 18:36 Marko Mäkelä
  2025-11-08 17:24 ` Marko Mäkelä
  0 siblings, 1 reply; 5+ messages in thread
From: Marko Mäkelä @ 2025-10-13 18:36 UTC (permalink / raw)
  To: u-boot

Hi all,

Yesterday, I successfully built the u-boot master branch with 
CONFIG_FIT_SIGNATURE=y and CONFIG_RSA=y and got the signature 
verification working with sha256,rsa2048.

Today, I wanted to try out CONFIG_ECDSA=y, but I am facing some trouble.  
I am generating the key and trying to add its public part to the device 
tree blob as with fdt_add_pubkey as follows:

openssl ecparam -name secp521r1 -genkey -noout -out dev-private.pem
openssl ec -in dev-private.pem -pubout -out dev.pem
cd u-boot
make ...
cp u-boot.dtb u-pubkey.dtb
tools/fdt_add_pubkey -a sha512,secp521r1 -n dev -k .. -r conf u-pubkey.dtb

The next step would be to run make EXT_DTB=u-pubkey.dtb ... so that the 
public key will be embedded and the signature verification will be 
enabled in the final u-boot.img.

Alas, the fdt_add_pubkey command would crash in SIGSEGV in alloc_ctx().  
I figured out that the hash algorithm is not being looked up and 
assigned. Maybe this is not necessary for the -a sha256,rsa2048 which I 
was successfully using previously. The following patch fixes the 
SIGSEGV:

diff --git a/tools/fdt_add_pubkey.c b/tools/fdt_add_pubkey.c
index 5582d7a8efe..4f7028cc15c 100644
--- a/tools/fdt_add_pubkey.c
+++ b/tools/fdt_add_pubkey.c
@@ -73,9 +73,10 @@ static void reset_info(struct image_sign_info *info)
  	info->keyname = keyname;
  	info->name = algo_name;
  	info->require_keys = require_keys;
+	info->checksum = image_get_checksum_algo(algo_name);
  	info->crypto = image_get_crypto_algo(algo_name);
  
-	if (!info->crypto) {
+	if (!info->checksum || !info->crypto) {
  		fprintf(stderr, "Unsupported signature algorithm '%s'\n",
  			algo_name);
  		exit(EXIT_FAILURE);

However, with the above patch applied, I am facing the next trouble:
tools/fdt_add_pubkey -a sha512,secp521r1 -n dev -k .. -r conf u-boot-key.dtb
Can not read key from '../dev.pem'
tools/fdt_add_pubkey: Cannot add public key to FIT blob: Unknown error -5

In GDB, I can see that read_key() in lib/ecdsa/ecdsa-libcrypto.c would 
invoke PEM_read_PrivateKey(), which I assume will fail, because 
../dev.pem only contains a public key. In the planned deployment, the 
private key would be private to a HSM or an external service. Moreover, 
I do not understand why fdt_add_pubkey would attempt to access a private 
key in the first place; that should only be needed for signing the 
fitImage. Both prepare_ctx() and ecdsa_add_verify_data() would return 
-5, which main() is reporting to stderr.

Has some way of using ECDSA based signature verification been tested?  
The reason why I would like to avoid RSA is that it is not thought to be 
quantum-secure, or secure against a cryptalalytic attack by a quantum 
computer.

With best regards,

	Marko Mäkelä

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-03  5:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-13 18:36 How to use ECDSA for signature verification? Marko Mäkelä
2025-11-08 17:24 ` Marko Mäkelä
2025-11-11  4:22   ` Anshul Dalal
2025-11-11 15:56     ` Marko Mäkelä
2026-02-03  5:32       ` Anshul Dalal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox