00dc3791ab1e14511ba7d3b744d14272c23ac098
[openwrt/openwrt.git] / target / linux / ipq40xx / patches-4.19 / 049-crypto-qce-handle-AES-XTS-cases-that-qce-fails.patch
1 From bbf2b1cf22dc98f3df33b6666df046dfb9564d91 Mon Sep 17 00:00:00 2001
2 From: Eneas U de Queiroz <cotequeiroz@gmail.com>
3 Date: Wed, 5 Feb 2020 13:42:25 -0300
4 Subject: [PATCH] crypto: qce - handle AES-XTS cases that qce fails
5
6 QCE hangs when presented with an AES-XTS request whose length is larger
7 than QCE_SECTOR_SIZE (512-bytes), and is not a multiple of it. Let the
8 fallback cipher handle them.
9
10 Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
11
12 --- a/drivers/crypto/qce/common.c
13 +++ b/drivers/crypto/qce/common.c
14 @@ -23,8 +23,6 @@
15 #include "regs-v5.h"
16 #include "sha.h"
17
18 -#define QCE_SECTOR_SIZE 512
19 -
20 static inline u32 qce_read(struct qce_device *qce, u32 offset)
21 {
22 return readl(qce->base + offset);
23 --- a/drivers/crypto/qce/common.h
24 +++ b/drivers/crypto/qce/common.h
25 @@ -20,6 +20,9 @@
26 #include <crypto/hash.h>
27 #include <crypto/internal/skcipher.h>
28
29 +/* xts du size */
30 +#define QCE_SECTOR_SIZE 512
31 +
32 /* key size in bytes */
33 #define QCE_SHA_HMAC_KEY_SIZE 64
34 #define QCE_MAX_CIPHER_KEY_SIZE AES_KEYSIZE_256
35 --- a/drivers/crypto/qce/skcipher.c
36 +++ b/drivers/crypto/qce/skcipher.c
37 @@ -213,9 +213,14 @@ static int qce_skcipher_crypt(struct skc
38 rctx->flags |= encrypt ? QCE_ENCRYPT : QCE_DECRYPT;
39 keylen = IS_XTS(rctx->flags) ? ctx->enc_keylen >> 1 : ctx->enc_keylen;
40
41 + /* qce is hanging when AES-XTS request len > QCE_SECTOR_SIZE and
42 + * is not a multiple of it; pass such requests to the fallback
43 + */
44 if (IS_AES(rctx->flags) &&
45 - ((keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_256) ||
46 - req->cryptlen <= aes_sw_max_len)) {
47 + (((keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_256) ||
48 + req->cryptlen <= aes_sw_max_len) ||
49 + (IS_XTS(rctx->flags) && req->cryptlen > QCE_SECTOR_SIZE &&
50 + req->cryptlen % QCE_SECTOR_SIZE))) {
51 SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback);
52
53 skcipher_request_set_tfm(subreq, ctx->fallback);