From: Stefan Berger <stefanb@linux.ibm.com>
To: Vitaly Chikunov <vt@altlinux.org>,
keyrings@vger.kernel.org, Jarkko Sakkinen <jarkko@kernel.org>,
David Howells <dhowells@redhat.com>
Cc: linux-crypto@vger.kernel.org, linux-integrity@vger.kernel.org,
Eric Biggers <ebiggers@kernel.org>
Subject: Re: [RFC PATCH] KEYS: Double max_size to make keyctl pkey_verify work
Date: Wed, 2 Feb 2022 22:15:24 -0500 [thread overview]
Message-ID: <7c9d973f-847e-e8bc-95fb-6c98a98a02e6@linux.ibm.com> (raw)
In-Reply-To: <20220202065906.2598366-1-vt@altlinux.org>
On 2/2/22 01:59, Vitaly Chikunov wrote:
> Rarely used `keyctl pkey_verify' can verify raw signatures, but was
> failing, because ECDSA/EC-RDSA signature sizes are twice key sizes which
> does not pass in/out sizes check in keyctl_pkey_params_get_2.
> This in turn because these values cannot be distinguished by a single
> `max_size' callback return value.
> Also, `keyctl pkey_query` displays incorrect `max_sig_size' about these
> algorithms.
>
> Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
> ---
> crypto/asymmetric_keys/public_key.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
> index 4fefb219bfdc..3ffbab07ed2a 100644
> --- a/crypto/asymmetric_keys/public_key.c
> +++ b/crypto/asymmetric_keys/public_key.c
> @@ -143,8 +143,19 @@ static int software_key_query(const struct kernel_pkey_params *params,
>
> len = crypto_akcipher_maxsize(tfm);
> info->key_size = len * 8;
> - info->max_data_size = len;
> - info->max_sig_size = len;
> + if (strcmp(alg_name, "ecrdsa") == 0 ||
> + strncmp(alg_name, "ecdsa-", 6) == 0) {
> + /*
> + * For these algos sig size is twice key size.
> + * keyctl uses max_sig_size as minimum input size, and
> + * max_data_size as minimum output size for a signature.
> + */
> + info->max_data_size = len * 2;
> + info->max_sig_size = len * 2;
I don't know about the data size but following my tests this is not
enough for ECDSA signature size. In ECDSA case the r and s components of
the signature are encode in asn.1, not 'raw'. So there are 2 bytes at
the beginning for sequence identifier , 2 bytes asn.1 for the r
component, 1 additional 0-byte to make the r component always a positive
number, then the r component, then 2 bytes asn.1 for the s component, 1
addition 0-byte to make the s component a positive number, then the s
component. Phew.
info->max_sig_size = 2 + (2 + 1 + len) * 2;
so for NIST P384 it's: 2 + (2+1+48) * 2 = 104
Then it works for me as well.
> + } else {
> + info->max_data_size = len;
> + info->max_sig_size = len;
> + }
> info->max_enc_size = len;
> info->max_dec_size = len;
> info->supported_ops = (KEYCTL_SUPPORTS_ENCRYPT |
next prev parent reply other threads:[~2022-02-03 3:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-02 6:59 [RFC PATCH] KEYS: Double max_size to make keyctl pkey_verify work Vitaly Chikunov
2022-02-02 12:55 ` Stefan Berger
2022-02-02 21:24 ` Vitaly Chikunov
2022-02-02 22:38 ` Vitaly Chikunov
2022-02-03 3:42 ` Stefan Berger
2022-02-03 0:07 ` Vitaly Chikunov
2022-02-20 23:31 ` Jarkko Sakkinen
2022-02-03 3:15 ` Stefan Berger [this message]
2022-02-03 3:34 ` Vitaly Chikunov
2022-02-20 23:29 ` Jarkko Sakkinen
2022-02-21 2:43 ` Vitaly Chikunov
2022-02-25 19:47 ` Stefan Berger
2022-02-20 23:25 ` Jarkko Sakkinen
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=7c9d973f-847e-e8bc-95fb-6c98a98a02e6@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=dhowells@redhat.com \
--cc=ebiggers@kernel.org \
--cc=jarkko@kernel.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=vt@altlinux.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.