diff mbox series

[11/15] crypto: skcipher - Propagate zero-length requests to lskcipher

Message ID 88c723ec1903971bc726828a8aa2eb3622aa6df8.1707815065.git.herbert@gondor.apana.org.au (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show
Series crypto: Add twopass lskcipher for adiantum | expand

Commit Message

Herbert Xu Dec. 6, 2023, 8:55 a.m. UTC
Propagate zero-length requests down to the lskcipher algorithm as
otherwise the return value could be different, e.g., zero vs. -EINVAL
for xts.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 crypto/lskcipher.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/crypto/lskcipher.c b/crypto/lskcipher.c
index 8660d6e3ccce..00ea963a2d2d 100644
--- a/crypto/lskcipher.c
+++ b/crypto/lskcipher.c
@@ -227,6 +227,11 @@  static int crypto_lskcipher_crypt_sg(struct skcipher_request *req,
 	if (!(req->base.flags & CRYPTO_SKCIPHER_REQ_NOTFINAL))
 		flags |= CRYPTO_LSKCIPHER_FLAG_FINAL;
 
+	if (unlikely(!req->cryptlen)) {
+		err = crypt(tfm, NULL, NULL, 0, ivs, flags);
+		goto out;
+	}
+
 	do {
 		err = skcipher_walk_virt(&walk, req, false);
 		morethanone = walk.nbytes != walk.total;
@@ -245,6 +250,7 @@  static int crypto_lskcipher_crypt_sg(struct skcipher_request *req,
 			return err;
 	} while (!secondpass++ && !isincremental && morethanone);
 
+out:
 	if (flags & CRYPTO_LSKCIPHER_FLAG_FINAL)
 		memcpy(req->iv, ivs, ivsize);