]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: qat - allow xts requests not multiple of block
authorGiovanni Cabiddu <giovanni.cabiddu@intel.com>
Mon, 29 Jun 2020 17:16:17 +0000 (18:16 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Aug 2020 06:26:07 +0000 (08:26 +0200)
[ Upstream commit 528f776df67c440361b2847b4da400d8754bf030 ]

Allow AES-XTS requests that are not multiple of the block size.
If a request is smaller than the block size, return -EINVAL.

This fixes the following issue reported by the crypto testmgr self-test:

  alg: skcipher: qat_aes_xts encryption failed on test vector "random: len=116 klen=64"; expected_error=0, actual_error=-22, cfg="random: inplace may_sleep use_finup src_divs=[<reimport>45.85%@+4077, <flush>54.15%@alignmask+18]"

Fixes: 96ee111a659e ("crypto: qat - return error for block...")
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/qat/qat_common/qat_algs.c

index e14d3dd291f0946ce1b7adaeef1c1c1a1de0a219..1b050391c0c90fd2326e68a2ab8238cd56b9628f 100644 (file)
@@ -55,6 +55,7 @@
 #include <crypto/hmac.h>
 #include <crypto/algapi.h>
 #include <crypto/authenc.h>
+#include <crypto/xts.h>
 #include <linux/dma-mapping.h>
 #include "adf_accel_devices.h"
 #include "adf_transport.h"
@@ -1102,6 +1103,14 @@ static int qat_alg_skcipher_blk_encrypt(struct skcipher_request *req)
        return qat_alg_skcipher_encrypt(req);
 }
 
+static int qat_alg_skcipher_xts_encrypt(struct skcipher_request *req)
+{
+       if (req->cryptlen < XTS_BLOCK_SIZE)
+               return -EINVAL;
+
+       return qat_alg_skcipher_encrypt(req);
+}
+
 static int qat_alg_skcipher_decrypt(struct skcipher_request *req)
 {
        struct crypto_skcipher *stfm = crypto_skcipher_reqtfm(req);
@@ -1161,6 +1170,15 @@ static int qat_alg_skcipher_blk_decrypt(struct skcipher_request *req)
 
        return qat_alg_skcipher_decrypt(req);
 }
+
+static int qat_alg_skcipher_xts_decrypt(struct skcipher_request *req)
+{
+       if (req->cryptlen < XTS_BLOCK_SIZE)
+               return -EINVAL;
+
+       return qat_alg_skcipher_decrypt(req);
+}
+
 static int qat_alg_aead_init(struct crypto_aead *tfm,
                             enum icp_qat_hw_auth_algo hash,
                             const char *hash_name)
@@ -1354,8 +1372,8 @@ static struct skcipher_alg qat_skciphers[] = { {
        .init = qat_alg_skcipher_init_tfm,
        .exit = qat_alg_skcipher_exit_tfm,
        .setkey = qat_alg_skcipher_xts_setkey,
-       .decrypt = qat_alg_skcipher_blk_decrypt,
-       .encrypt = qat_alg_skcipher_blk_encrypt,
+       .decrypt = qat_alg_skcipher_xts_decrypt,
+       .encrypt = qat_alg_skcipher_xts_encrypt,
        .min_keysize = 2 * AES_MIN_KEY_SIZE,
        .max_keysize = 2 * AES_MAX_KEY_SIZE,
        .ivsize = AES_BLOCK_SIZE,