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 <[email protected]>
---
 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 <[email protected]>


Reply via email to