ipq40xx: qce - add fixes for AES ciphers
[openwrt/staging/jogo.git] / target / linux / ipq40xx / patches-5.4 / 049-crypto-qce-handle-AES-XTS-cases-that-qce-fails.patch
1 From 7f19380b2cfd412dcef2facefb3f6c62788864d7 Mon Sep 17 00:00:00 2001
2 From: Eneas U de Queiroz <cotequeiroz@gmail.com>
3 Date: Fri, 7 Feb 2020 12:02:27 -0300
4 Subject: [PATCH 11/11] 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 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
12 ---
13 drivers/crypto/qce/common.c | 2 --
14 drivers/crypto/qce/common.h | 3 +++
15 drivers/crypto/qce/skcipher.c | 9 +++++++--
16 3 files changed, 10 insertions(+), 4 deletions(-)
17
18 --- a/drivers/crypto/qce/common.c
19 +++ b/drivers/crypto/qce/common.c
20 @@ -15,8 +15,6 @@
21 #include "regs-v5.h"
22 #include "sha.h"
23
24 -#define QCE_SECTOR_SIZE 512
25 -
26 static inline u32 qce_read(struct qce_device *qce, u32 offset)
27 {
28 return readl(qce->base + offset);
29 --- a/drivers/crypto/qce/common.h
30 +++ b/drivers/crypto/qce/common.h
31 @@ -12,6 +12,9 @@
32 #include <crypto/hash.h>
33 #include <crypto/internal/skcipher.h>
34
35 +/* xts du size */
36 +#define QCE_SECTOR_SIZE 512
37 +
38 /* key size in bytes */
39 #define QCE_SHA_HMAC_KEY_SIZE 64
40 #define QCE_MAX_CIPHER_KEY_SIZE AES_KEYSIZE_256
41 --- a/drivers/crypto/qce/skcipher.c
42 +++ b/drivers/crypto/qce/skcipher.c
43 @@ -227,9 +227,14 @@ static int qce_skcipher_crypt(struct skc
44 rctx->flags |= encrypt ? QCE_ENCRYPT : QCE_DECRYPT;
45 keylen = IS_XTS(rctx->flags) ? ctx->enc_keylen >> 1 : ctx->enc_keylen;
46
47 + /* qce is hanging when AES-XTS request len > QCE_SECTOR_SIZE and
48 + * is not a multiple of it; pass such requests to the fallback
49 + */
50 if (IS_AES(rctx->flags) &&
51 - ((keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_256) ||
52 - req->cryptlen <= aes_sw_max_len)) {
53 + (((keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_256) ||
54 + req->cryptlen <= aes_sw_max_len) ||
55 + (IS_XTS(rctx->flags) && req->cryptlen > QCE_SECTOR_SIZE &&
56 + req->cryptlen % QCE_SECTOR_SIZE))) {
57 SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback);
58
59 skcipher_request_set_sync_tfm(subreq, ctx->fallback);