From: "Herbert Xu" <herbert@gondor.apana.org.au>
To: Ard Biesheuvel <ardb@kernel.org>,
Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
Eric Biggers <ebiggers@kernel.org>,
Stephan Mueller <smueller@chronox.de>
Subject: [v2 PATCH 2/3] crypto: algif_skcipher - Add support for fcsize
Date: Fri, 12 Jun 2020 22:21:28 +1000 [thread overview]
Message-ID: <E1jjiga-0005Pj-Ej@fornost.hmeau.com> (raw)
In-Reply-To: 20200612122105.GA18892@gondor.apana.org.au
As it stands algif_skcipher assumes all algorithms support chaining.
This patch teaches it about the new fcsize attribute which can be
used to disable chaining on a given algorithm. It can also be used
to support chaining on algorithms such as cts that cannot otherwise
do chaining. For that case algif_skcipher will also now set the
request flag CRYPTO_TFM_REQ_MORE when needed.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
crypto/algif_skcipher.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index f8a7fca3203eb..7fc873d28f4a7 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -57,12 +57,18 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
struct af_alg_ctx *ctx = ask->private;
struct crypto_skcipher *tfm = pask->private;
unsigned int bs = crypto_skcipher_chunksize(tfm);
+ unsigned int rflags = CRYPTO_TFM_REQ_MAY_SLEEP;
+ int fc = crypto_skcipher_fcsize(tfm);
struct af_alg_async_req *areq;
+ unsigned int min = bs;
int err = 0;
size_t len = 0;
- if (!ctx->init || (ctx->more && ctx->used < bs)) {
- err = af_alg_wait_for_data(sk, flags, bs);
+ if (fc >= 0)
+ min += fc;
+
+ if (!ctx->init || (ctx->more && ctx->used < min)) {
+ err = af_alg_wait_for_data(sk, flags, min);
if (err)
return err;
}
@@ -78,13 +84,22 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
if (err)
goto free;
+ err = -EINVAL;
+
/*
* If more buffers are to be expected to be processed, process only
- * full block size buffers.
+ * full block size buffers and withhold data according to fcsize.
*/
- if (ctx->more || len < ctx->used)
+ if (ctx->more || len < ctx->used) {
+ if (fc < 0)
+ goto free;
+
+ len -= fc;
len -= len % bs;
+ rflags |= CRYPTO_TFM_REQ_MORE;
+ }
+
/*
* Create a per request TX SGL for this request which tracks the
* SG entries from the global TX SGL.
@@ -116,8 +131,7 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
areq->outlen = len;
skcipher_request_set_callback(&areq->cra_u.skcipher_req,
- CRYPTO_TFM_REQ_MAY_SLEEP,
- af_alg_async_cb, areq);
+ rflags, af_alg_async_cb, areq);
err = ctx->enc ?
crypto_skcipher_encrypt(&areq->cra_u.skcipher_req) :
crypto_skcipher_decrypt(&areq->cra_u.skcipher_req);
@@ -129,9 +143,9 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
sock_put(sk);
} else {
/* Synchronous operation */
+ rflags |= CRYPTO_TFM_REQ_MAY_BACKLOG;
skcipher_request_set_callback(&areq->cra_u.skcipher_req,
- CRYPTO_TFM_REQ_MAY_SLEEP |
- CRYPTO_TFM_REQ_MAY_BACKLOG,
+ rflags,
crypto_req_done, &ctx->wait);
err = crypto_wait_req(ctx->enc ?
crypto_skcipher_encrypt(&areq->cra_u.skcipher_req) :
next prev parent reply other threads:[~2020-06-12 12:21 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 19:02 [RFC/RFT PATCH 0/2] crypto: add CTS output IVs for arm64 and testmgr Ard Biesheuvel
2020-05-19 19:02 ` [RFC/RFT PATCH 1/2] crypto: arm64/aes - align output IV with generic CBC-CTS driver Ard Biesheuvel
2020-05-19 19:02 ` [RFC/RFT PATCH 2/2] crypto: testmgr - add output IVs for AES-CBC with ciphertext stealing Ard Biesheuvel
2020-05-19 19:04 ` [RFC/RFT PATCH 0/2] crypto: add CTS output IVs for arm64 and testmgr Ard Biesheuvel
2020-05-20 6:03 ` Stephan Mueller
2020-05-20 6:40 ` Ard Biesheuvel
2020-05-20 6:47 ` Stephan Mueller
2020-05-20 6:54 ` Ard Biesheuvel
2020-05-20 7:01 ` Stephan Mueller
2020-05-20 7:09 ` Ard Biesheuvel
2020-05-21 13:01 ` Gilad Ben-Yossef
2020-05-21 13:23 ` Ard Biesheuvel
2020-05-23 18:52 ` Stephan Müller
2020-05-23 22:40 ` Ard Biesheuvel
2020-05-28 7:33 ` Herbert Xu
2020-05-28 8:33 ` Ard Biesheuvel
2020-05-29 8:05 ` Herbert Xu
2020-05-29 8:20 ` Ard Biesheuvel
2020-05-29 11:51 ` Herbert Xu
2020-05-29 12:00 ` Ard Biesheuvel
2020-05-29 12:02 ` Herbert Xu
2020-05-29 13:10 ` Ard Biesheuvel
2020-05-29 13:19 ` Herbert Xu
2020-05-29 13:41 ` Ard Biesheuvel
2020-05-29 13:42 ` Herbert Xu
2020-06-12 12:06 ` [PATCH 0/3] crypto: skcipher - Add support for no chaining and partial chaining Herbert Xu
2020-06-12 12:07 ` [PATCH 1/3] crypto: skcipher - Add final chunk size field for chaining Herbert Xu
2020-06-12 12:15 ` Stephan Mueller
2020-06-12 12:16 ` Herbert Xu
2020-06-12 12:21 ` [v2 PATCH 0/3] crypto: skcipher - Add support for no chaining and partial chaining Herbert Xu
2020-06-12 12:21 ` [v2 PATCH 1/3] crypto: skcipher - Add final chunk size field for chaining Herbert Xu
2020-06-12 12:21 ` Herbert Xu [this message]
2020-06-12 12:21 ` [v2 PATCH 3/3] crypto: cts - Add support " Herbert Xu
2020-06-12 16:10 ` [v2 PATCH 0/3] crypto: skcipher - Add support for no chaining and partial chaining Ard Biesheuvel
2020-06-15 7:30 ` Herbert Xu
2020-06-15 7:50 ` Ard Biesheuvel
2020-06-15 18:50 ` Eric Biggers
2020-06-15 23:18 ` Ard Biesheuvel
2020-06-16 11:04 ` Herbert Xu
2020-06-16 16:53 ` Eric Biggers
2020-06-12 12:07 ` [PATCH 2/3] crypto: algif_skcipher - Add support for fcsize Herbert Xu
2020-06-12 12:07 ` [PATCH 3/3] crypto: cts - Add support for chaining 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=E1jjiga-0005Pj-Ej@fornost.hmeau.com \
--to=herbert@gondor.apana.org.au \
--cc=ardb@kernel.org \
--cc=ebiggers@kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=smueller@chronox.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).