From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "Lukas Wunner" <lukas@wunner.de>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
"Eric Biggers" <ebiggers@google.com>,
"Stefan Berger" <stefanb@linux.ibm.com>,
"Vitaly Chikunov" <vt@altlinux.org>,
"Tadeusz Struk" <tstruk@gigaio.com>
Cc: "David Howells" <dhowells@redhat.com>,
"Andrew Zaborowski" <andrew.zaborowski@intel.com>,
"Saulo Alessandre" <saulo.alessandre@tse.jus.br>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
"Ignat Korchagin" <ignat@cloudflare.com>,
"Marek Behun" <kabel@kernel.org>,
"Varad Gautam" <varadgautam@google.com>,
"Stephan Mueller" <smueller@chronox.de>,
"Denis Kenzior" <denkenz@gmail.com>,
<linux-crypto@vger.kernel.org>, <keyrings@vger.kernel.org>
Subject: Re: [PATCH v2 04/19] crypto: ecrdsa - Migrate to sig_alg backend
Date: Wed, 11 Sep 2024 15:49:07 +0300 [thread overview]
Message-ID: <D43GTXWLMJ2E.258ZI34E5JRK6@kernel.org> (raw)
In-Reply-To: <45acc8db555f80408c8b975771da34c569da45da.1725972334.git.lukas@wunner.de>
On Tue Sep 10, 2024 at 5:30 PM EEST, Lukas Wunner wrote:
> A sig_alg backend has just been introduced with the intent of moving all
> asymmetric sign/verify algorithms to it one by one.
>
> Migrate ecrdsa.c to the new backend.
>
> One benefit of the new API is the use of kernel buffers instead of
> sglists, which avoids the overhead of copying signature and digest
> sglists back into kernel buffers. ecrdsa.c is thus simplified quite
> a bit.
>
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
> ---
> crypto/Kconfig | 2 +-
> crypto/ecrdsa.c | 56 +++++++++++++++++++++---------------------------
> crypto/testmgr.c | 4 ++--
> crypto/testmgr.h | 7 +-----
> 4 files changed, 28 insertions(+), 41 deletions(-)
>
> diff --git a/crypto/Kconfig b/crypto/Kconfig
> index 89b728c72f07..e8488b8c45e3 100644
> --- a/crypto/Kconfig
> +++ b/crypto/Kconfig
> @@ -302,7 +302,7 @@ config CRYPTO_ECDSA
> config CRYPTO_ECRDSA
> tristate "EC-RDSA (Elliptic Curve Russian Digital Signature Algorithm)"
> select CRYPTO_ECC
> - select CRYPTO_AKCIPHER
> + select CRYPTO_SIG
> select CRYPTO_STREEBOG
> select OID_REGISTRY
> select ASN1
> diff --git a/crypto/ecrdsa.c b/crypto/ecrdsa.c
> index 3811f3805b5d..7383dd11089b 100644
> --- a/crypto/ecrdsa.c
> +++ b/crypto/ecrdsa.c
> @@ -18,12 +18,11 @@
>
> #include <linux/module.h>
> #include <linux/crypto.h>
> +#include <crypto/sig.h>
> #include <crypto/streebog.h>
> -#include <crypto/internal/akcipher.h>
> #include <crypto/internal/ecc.h>
> -#include <crypto/akcipher.h>
> +#include <crypto/internal/sig.h>
> #include <linux/oid_registry.h>
> -#include <linux/scatterlist.h>
> #include "ecrdsa_params.asn1.h"
> #include "ecrdsa_pub_key.asn1.h"
> #include "ecrdsa_defs.h"
> @@ -68,13 +67,12 @@ static const struct ecc_curve *get_curve_by_oid(enum OID oid)
> }
> }
>
> -static int ecrdsa_verify(struct akcipher_request *req)
> +static int ecrdsa_verify(struct crypto_sig *tfm,
> + const void *src, unsigned int slen,
> + const void *digest, unsigned int dlen)
> {
> - struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
> - struct ecrdsa_ctx *ctx = akcipher_tfm_ctx(tfm);
> - unsigned char sig[ECRDSA_MAX_SIG_SIZE];
> - unsigned char digest[STREEBOG512_DIGEST_SIZE];
> - unsigned int ndigits = req->dst_len / sizeof(u64);
> + struct ecrdsa_ctx *ctx = crypto_sig_ctx(tfm);
> + unsigned int ndigits = dlen / sizeof(u64);
> u64 r[ECRDSA_MAX_DIGITS]; /* witness (r) */
> u64 _r[ECRDSA_MAX_DIGITS]; /* -r */
> u64 s[ECRDSA_MAX_DIGITS]; /* second part of sig (s) */
> @@ -91,25 +89,19 @@ static int ecrdsa_verify(struct akcipher_request *req)
> */
> if (!ctx->curve ||
> !ctx->digest ||
> - !req->src ||
> + !src ||
> + !digest ||
> !ctx->pub_key.x ||
> - req->dst_len != ctx->digest_len ||
> - req->dst_len != ctx->curve->g.ndigits * sizeof(u64) ||
> + dlen != ctx->digest_len ||
> + dlen != ctx->curve->g.ndigits * sizeof(u64) ||
> ctx->pub_key.ndigits != ctx->curve->g.ndigits ||
> - req->dst_len * 2 != req->src_len ||
> - WARN_ON(req->src_len > sizeof(sig)) ||
> - WARN_ON(req->dst_len > sizeof(digest)))
> + dlen * 2 != slen ||
> + WARN_ON(slen > ECRDSA_MAX_SIG_SIZE) ||
> + WARN_ON(dlen > STREEBOG512_DIGEST_SIZE))
Despite being migration I don't see no point recycling use of WARN_ON()
here, given panic_on_warn kernel command-line flag.
If you want to print to something, please do separate checks and use
pr_warn() instead at most.
BR, Jarkko
next prev parent reply other threads:[~2024-09-11 12:49 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 14:30 [PATCH v2 00/19] Migrate to sig_alg and templatize ecdsa Lukas Wunner
2024-09-10 14:30 ` Lukas Wunner
2024-09-10 14:30 ` [PATCH v2 01/19] crypto: ecdsa - Drop unused test vector elements Lukas Wunner
2024-09-10 18:49 ` Stefan Berger
2024-09-11 11:52 ` Jarkko Sakkinen
2024-09-12 7:59 ` Lukas Wunner
2024-09-10 14:30 ` [PATCH v2 02/19] crypto: sig - Introduce sig_alg backend Lukas Wunner
2024-09-11 12:12 ` Jarkko Sakkinen
2024-09-12 7:54 ` Lukas Wunner
2024-09-12 14:19 ` Jarkko Sakkinen
2024-09-12 15:27 ` Lukas Wunner
2024-09-12 17:14 ` Jarkko Sakkinen
2024-11-18 7:56 ` Jarkko Sakkinen
2024-09-13 18:40 ` Jonathan Cameron
2024-09-10 14:30 ` [PATCH v2 03/19] crypto: ecdsa - Migrate to " Lukas Wunner
2024-09-10 14:30 ` [PATCH v2 04/19] crypto: ecrdsa " Lukas Wunner
2024-09-11 12:49 ` Jarkko Sakkinen [this message]
2024-09-12 8:05 ` Lukas Wunner
2024-09-12 14:20 ` Jarkko Sakkinen
2024-09-10 14:30 ` [PATCH v2 05/19] crypto: rsa-pkcs1pad - Deduplicate set_{pub,priv}_key callbacks Lukas Wunner
2024-09-10 19:03 ` Stefan Berger
2024-09-11 12:54 ` Jarkko Sakkinen
2024-09-10 14:30 ` [PATCH v2 06/19] crypto: rsassa-pkcs1 - Migrate to sig_alg backend Lukas Wunner
2024-09-11 12:56 ` Jarkko Sakkinen
2024-10-21 16:08 ` Klara Modin
2024-10-21 19:02 ` Lukas Wunner
2024-10-22 10:15 ` Klara Modin
2024-10-23 10:19 ` Klara Modin
2024-10-25 7:17 ` Lukas Wunner
2024-10-25 16:50 ` Eric Biggers
2024-10-26 9:40 ` Klara Modin
2024-10-28 11:45 ` Klara Modin
2024-09-10 14:30 ` [PATCH v2 07/19] crypto: rsassa-pkcs1 - Harden digest length verification Lukas Wunner
2024-09-11 12:58 ` Jarkko Sakkinen
2024-09-10 14:30 ` [PATCH v2 08/19] crypto: rsassa-pkcs1 - Avoid copying hash prefix Lukas Wunner
2024-09-11 13:00 ` Jarkko Sakkinen
2024-09-10 14:30 ` [PATCH v2 09/19] crypto: virtio - Drop sign/verify operations Lukas Wunner
2024-09-10 14:30 ` [PATCH v2 10/19] crypto: drivers " Lukas Wunner
2024-09-10 14:30 ` Lukas Wunner
2024-09-10 14:30 ` [PATCH v2 11/19] crypto: akcipher " Lukas Wunner
2024-09-10 14:30 ` [PATCH v2 12/19] crypto: sig - Move crypto_sig_*() API calls to include file Lukas Wunner
2024-09-10 19:24 ` Stefan Berger
2024-09-10 14:30 ` [PATCH v2 13/19] ASN.1: Clean up include statements in public headers Lukas Wunner
2024-09-10 14:30 ` [PATCH v2 14/19] crypto: ecdsa - Avoid signed integer overflow on signature decoding Lukas Wunner
2024-09-10 14:30 ` [PATCH v2 15/19] crypto: ecdsa - Move X9.62 signature decoding into template Lukas Wunner
2024-09-10 20:46 ` Stefan Berger
2024-09-10 14:30 ` [PATCH v2 16/19] crypto: sig - Rename crypto_sig_maxsize() to crypto_sig_keysize() Lukas Wunner
2024-09-11 13:02 ` Jarkko Sakkinen
2024-09-12 8:12 ` Lukas Wunner
2024-09-10 14:30 ` [PATCH v2 17/19] crypto: ecdsa - Move X9.62 signature size calculation into template Lukas Wunner
2024-09-10 14:30 ` [PATCH v2 18/19] crypto: ecdsa - Support P1363 signature decoding Lukas Wunner
2024-09-10 21:46 ` Stefan Berger
2024-09-10 14:30 ` [PATCH v2 19/19] crypto: ecrdsa - Fix signature size calculation Lukas Wunner
2024-10-01 9:17 ` [PATCH v2 00/19] Migrate to sig_alg and templatize ecdsa Lukas Wunner
2024-10-01 9:17 ` Lukas Wunner
2024-10-05 5:27 ` Herbert Xu
2024-10-05 5:27 ` Herbert Xu
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=D43GTXWLMJ2E.258ZI34E5JRK6@kernel.org \
--to=jarkko@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=andrew.zaborowski@intel.com \
--cc=davem@davemloft.net \
--cc=denkenz@gmail.com \
--cc=dhowells@redhat.com \
--cc=ebiggers@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=ignat@cloudflare.com \
--cc=kabel@kernel.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=saulo.alessandre@tse.jus.br \
--cc=smueller@chronox.de \
--cc=stefanb@linux.ibm.com \
--cc=tstruk@gigaio.com \
--cc=varadgautam@google.com \
--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.