mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jonas Rebmann <jre@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 BAREBOX <barebox@lists.infradead.org>
Cc: Jonas Rebmann <jre@pengutronix.de>
Subject: [PATCH] fixup! public-keys: move list out of struct public_key
Date: Tue, 28 Oct 2025 16:01:57 +0100	[thread overview]
Message-ID: <20251028-fixup-ecdsa-v1-1-aca221d4672b@pengutronix.de> (raw)

After not invoking ecdsa_key_dup() on keys before first use anymore,
key->size bits remains uninitialized, breaking ecdsa_verify() and
thereby ECDSA at large.

 - Drop the unused ecdsa_key_dup
 - Drop the uninitialized size_bits field in struct ecdsa_public_key
 - Invoke ecdsa_key_size() in ecdsa_verify() instead

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
 crypto/ecdsa.c         | 22 ++++------------------
 include/crypto/ecdsa.h |  1 -
 2 files changed, 4 insertions(+), 19 deletions(-)

diff --git a/crypto/ecdsa.c b/crypto/ecdsa.c
index 6aaeff5c14..6bc4da2cdd 100644
--- a/crypto/ecdsa.c
+++ b/crypto/ecdsa.c
@@ -78,7 +78,10 @@ int ecdsa_verify(const struct ecdsa_public_key *key, const uint8_t *sig,
 	const void *r, *s;
 	u64 rh[4], sh[4];
 	u64 mhash[ECC_MAX_DIGITS];
-	int key_size_bytes = key->size_bits / 8;
+	int key_size_bits, key_size_bytes;
+
+	key_size_bits = ecdsa_key_size(key->curve_name);
+	key_size_bytes = key_size_bits / 8;
 
 	ctx->curve_id = curve_id;
 	ctx->curve = ecc_get_curve(curve_id);
@@ -103,20 +106,3 @@ int ecdsa_verify(const struct ecdsa_public_key *key, const uint8_t *sig,
 
 	return _ecdsa_verify(ctx, (void *)mhash, rh, sh);
 }
-
-struct ecdsa_public_key *ecdsa_key_dup(const struct ecdsa_public_key *key)
-{
-	struct ecdsa_public_key *new;
-	int key_size_bits;
-
-	key_size_bits = ecdsa_key_size(key->curve_name);
-	if (!key_size_bits)
-		return NULL;
-
-	new = xmemdup(key, sizeof(*key));
-	new->x = xmemdup(key->x, key_size_bits / 8);
-	new->y = xmemdup(key->y, key_size_bits / 8);
-	new->size_bits = key_size_bits;
-
-	return new;
-}
diff --git a/include/crypto/ecdsa.h b/include/crypto/ecdsa.h
index 3b6bb394d9..7c8aeadc25 100644
--- a/include/crypto/ecdsa.h
+++ b/include/crypto/ecdsa.h
@@ -10,7 +10,6 @@ struct ecdsa_public_key {
 	const char *curve_name;	/* Name of curve, e.g. "prime256v1" */
 	const uint64_t *x;	/* x coordinate of public key */
 	const uint64_t *y;	/* y coordinate of public key */
-	unsigned int size_bits;	/* key size in bits, derived from curve name */
 };
 
 #ifdef CONFIG_CRYPTO_ECDSA

---
base-commit: 946cf6bbbe2bdaac56b17185af673a1fa3288635
change-id: 20251028-fixup-ecdsa-8af6dc75f31b

Best regards,
--  
Jonas Rebmann <jre@pengutronix.de>




                 reply	other threads:[~2025-10-28 15:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251028-fixup-ecdsa-v1-1-aca221d4672b@pengutronix.de \
    --to=jre@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox