crypto: caam - add xts check for block length equal to zero
authorAndrei Botila <andrei.botila@nxp.com>
Tue, 22 Sep 2020 16:03:25 +0000 (19:03 +0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 2 Oct 2020 08:02:11 +0000 (18:02 +1000)
XTS should not return succes when dealing with block length equal to zero.
This is different than the rest of the skcipher algorithms.

Fixes: 31bb2f0da1b50 ("crypto: caam - check zero-length input")
Cc: <stable@vger.kernel.org> # v5.4+
Signed-off-by: Andrei Botila <andrei.botila@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/caam/caamalg.c
drivers/crypto/caam/caamalg_qi.c
drivers/crypto/caam/caamalg_qi2.c

index a79b26f841697bef4a9ad5d9e7af8892031063f8..e72aa3e2e0656827edd745348a5fd86759ac1047 100644 (file)
@@ -1787,7 +1787,12 @@ static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt)
        u32 *desc;
        int ret = 0;
 
-       if (!req->cryptlen)
+       /*
+        * XTS is expected to return an error even for input length = 0
+        * Note that the case input length < block size will be caught during
+        * HW offloading and return an error.
+        */
+       if (!req->cryptlen && !ctx->fallback)
                return 0;
 
        if (ctx->fallback && (xts_skcipher_ivsize(req) ||
index 30aceaf325d78fd36ae832c610c0e3284ba47dcc..efcc7cb050fc7a160d1d97b588a7a8a89d8e9b0f 100644 (file)
@@ -1405,7 +1405,12 @@ static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt)
        struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
        int ret;
 
-       if (!req->cryptlen)
+       /*
+        * XTS is expected to return an error even for input length = 0
+        * Note that the case input length < block size will be caught during
+        * HW offloading and return an error.
+        */
+       if (!req->cryptlen && !ctx->fallback)
                return 0;
 
        if (ctx->fallback && (xts_skcipher_ivsize(req) ||
index 255b818c82b28c3f32091f6cddffce87612c5c6f..4cbd7e834888266a57ab7489b8bc7f1172c96454 100644 (file)
@@ -1472,7 +1472,12 @@ static int skcipher_encrypt(struct skcipher_request *req)
        struct caam_request *caam_req = skcipher_request_ctx(req);
        int ret;
 
-       if (!req->cryptlen)
+       /*
+        * XTS is expected to return an error even for input length = 0
+        * Note that the case input length < block size will be caught during
+        * HW offloading and return an error.
+        */
+       if (!req->cryptlen && !ctx->fallback)
                return 0;
 
        if (ctx->fallback && (xts_skcipher_ivsize(req) ||
@@ -1516,7 +1521,12 @@ static int skcipher_decrypt(struct skcipher_request *req)
        struct caam_request *caam_req = skcipher_request_ctx(req);
        int ret;
 
-       if (!req->cryptlen)
+       /*
+        * XTS is expected to return an error even for input length = 0
+        * Note that the case input length < block size will be caught during
+        * HW offloading and return an error.
+        */
+       if (!req->cryptlen && !ctx->fallback)
                return 0;
 
        if (ctx->fallback && (xts_skcipher_ivsize(req) ||