From: Lukas Wunner <lukas@wunner.de>
To: Changwei Zou <changwei.zou@canonical.com>
Cc: Martin.Kepplinger-Novakovic@ginzinger.com, davem@davemloft.net,
herbert@gondor.apana.org.au, ignat@linux.win,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
martink@posteo.de
Subject: Re: [PATCH v3] crypto: rsassa-pkcs1 - Align DMA buffer to CRYPTO_DMA_ALIGN
Date: Wed, 29 Jul 2026 21:26:09 +0200 [thread overview]
Message-ID: <ampT0ZVFqOgxKFa6@wunner.de> (raw)
In-Reply-To: <20260729004156.11925-1-changwei.zou@canonical.com>
On Wed, Jul 29, 2026 at 10:41:56AM +1000, Changwei Zou wrote:
> +++ b/crypto/rsassa-pkcs1.c
> @@ -237,12 +237,13 @@ static int rsassa_pkcs1_verify(struct crypto_sig *tfm,
> return -EINVAL;
>
> /* RFC 8017 sec 8.2.2 step 2 - RSA verification */
> - child_req = kmalloc(sizeof(*child_req) + child_reqsize + ctx->key_size,
> - GFP_KERNEL);
> + child_req = kmalloc(sizeof(*child_req) + child_reqsize +
> + ctx->key_size + CRYPTO_DMA_ALIGN - 1, GFP_KERNEL);
> if (!child_req)
> return -ENOMEM;
>
> - out_buf = (u8 *)(child_req + 1) + child_reqsize;
> + out_buf = PTR_ALIGN((u8 *)(child_req + 1) + child_reqsize,
> + CRYPTO_DMA_ALIGN);
> memcpy(out_buf, src, slen);
>
> crypto_init_wait(&cwait);
Thank, this all looks good to me.
However after reading around a bit in crypto code, I'm under the
impression that the "native" way of doing this is to have struct
caam_akcipher_alg[] in drivers/crypto/caam/caampkc.c define
".cra_alignmask = CRYPTO_DMA_ALIGN - 1," and then have
rsassa_pkcs1_verify() call crypto_akcipher_alignmask()
to determine the amount of padding needed and the alignment.
That crypto_akcipher_alignmask() doesn't exist yet, but can
easily be copy-pasted from crypto_skcipher_alignmask()
except it invokes crypto_akcipher_tfm() instead of
crypto_skcipher_tfm().
Finally the kernel-doc of struct crypto_alg would have to be
amended because the documentation of the cra_alignmask member
does not mention akcipher yet.
Now this may all sound like a roundabout way of doing things
but it seems to fit neatly into the existing OO-like approach
of the crypto subsystem and so I strongly suspect that's what
Herbert would want. I apologize for not having steered you
in that direction right away, I feel like a novice myself
sometimes when navigating that code.
You can find some pre-existing use cases with
"git grep alignmask -- crypto/". E.g. in crypto/xctr.c,
alignmask is determined with crypto_cipher_alignmask()
and that (plus 1) is then fed to PTR_ALIGN().
Basically the idea is that whether padding is added at all
and how much depends on the child request, and that child
request knows exactly whether it needs any padding at all.
I think you can do all of that in a single patch and thus
keep this easily backportable to stable kernels.
Thanks!
Lukas
next prev parent reply other threads:[~2026-07-29 19:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 0:41 [PATCH v3] crypto: rsassa-pkcs1 - Align DMA buffer to CRYPTO_DMA_ALIGN Changwei Zou
2026-07-29 19:26 ` Lukas Wunner [this message]
2026-07-29 23:34 ` Herbert Xu
2026-07-29 20:29 ` Lukas Wunner
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=ampT0ZVFqOgxKFa6@wunner.de \
--to=lukas@wunner.de \
--cc=Martin.Kepplinger-Novakovic@ginzinger.com \
--cc=changwei.zou@canonical.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=ignat@linux.win \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martink@posteo.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).