mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -04:00
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: a7d45ba77d ("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>
This commit is contained in:
@@ -82,7 +82,7 @@ static int ecdsa_x962_verify(struct crypto_sig *tfm,
|
||||
int err;
|
||||
|
||||
sig_ctx.ndigits = DIV_ROUND_UP_POW2(crypto_sig_keysize(ctx->child),
|
||||
sizeof(u64));
|
||||
sizeof(u64) * BITS_PER_BYTE);
|
||||
|
||||
err = asn1_ber_decoder(&ecdsasignature_decoder, &sig_ctx, src, slen);
|
||||
if (err < 0)
|
||||
@@ -103,7 +103,8 @@ static unsigned int ecdsa_x962_max_size(struct crypto_sig *tfm)
|
||||
{
|
||||
struct ecdsa_x962_ctx *ctx = crypto_sig_ctx(tfm);
|
||||
struct sig_alg *alg = crypto_sig_alg(ctx->child);
|
||||
int slen = crypto_sig_keysize(ctx->child);
|
||||
int slen = DIV_ROUND_UP_POW2(crypto_sig_keysize(ctx->child),
|
||||
BITS_PER_BYTE);
|
||||
|
||||
/*
|
||||
* Verify takes ECDSA-Sig-Value (described in RFC 5480) as input,
|
||||
|
||||
Reference in New Issue
Block a user