]> www.infradead.org Git - users/jedix/linux-maple.git/commit
crypto: ecdsa - Fix NIST P521 key size reported by KEYCTL_PKEY_QUERY
authorLukas Wunner <lukas@wunner.de>
Mon, 7 Apr 2025 19:32:42 +0000 (21:32 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Wed, 16 Apr 2025 07:16:21 +0000 (15:16 +0800)
commit6b7f9397c98c72902f9364056413c73fe6dee1d8
treef2b0c7b7989bb46cec0a8f242a3b7b8ba0ba8d3e
parent3828485e1c7b111290122ab6e083c2a37132b5c2
crypto: ecdsa - Fix NIST P521 key size reported by KEYCTL_PKEY_QUERY

When user space issues a KEYCTL_PKEY_QUERY system call for a NIST P521
key, the key_size is incorrectly reported as 528 bits instead of 521.

That's because the key size obtained through crypto_sig_keysize() is in
bytes and software_key_query() multiplies by 8 to yield the size in bits.
The underlying assumption is that the key size is always a multiple of 8.
With the recent addition of NIST P521, that's no longer the case.

Fix by returning the key_size in bits from crypto_sig_keysize() and
adjusting the calculations in software_key_query().

The ->key_size() callbacks of sig_alg algorithms now return the size in
bits, whereas the ->digest_size() and ->max_size() callbacks return the
size in bytes.  This matches with the units in struct keyctl_pkey_query.

Fixes: a7d45ba77d3d ("crypto: ecdsa - Register NIST P521 and extend test suite")
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Ignat Korchagin <ignat@cloudflare.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/asymmetric_keys/public_key.c
crypto/ecdsa-p1363.c
crypto/ecdsa-x962.c
crypto/ecdsa.c
crypto/ecrdsa.c
crypto/rsassa-pkcs1.c
crypto/sig.c
include/crypto/sig.h