ipq40xx: Remove kernel 4.14 support
[openwrt/openwrt.git] / target / linux / ipq40xx / patches-4.19 / 042-crypto-qce-fix-xts-aes-qce-key-sizes.patch
1 From 0138c3c13809250338d7cfba6f4ca3b2da02b2c8 Mon Sep 17 00:00:00 2001
2 From: Eneas U de Queiroz <cotequeiroz@gmail.com>
3 Date: Thu, 21 Nov 2019 14:28:23 -0300
4 Subject: [PATCH] crypto: qce - fix xts-aes-qce key sizes
5
6 XTS-mode uses two keys, so the keysizes should be doubled in
7 skcipher_def, and halved when checking if it is AES-128/192/256.
8
9 Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
10
11 --- a/drivers/crypto/qce/skcipher.c
12 +++ b/drivers/crypto/qce/skcipher.c
13 @@ -168,7 +168,7 @@ static int qce_skcipher_setkey(struct cr
14 return -EINVAL;
15
16 if (IS_AES(flags)) {
17 - switch (keylen) {
18 + switch (IS_XTS(flags) ? keylen >> 1 : keylen) {
19 case AES_KEYSIZE_128:
20 case AES_KEYSIZE_256:
21 break;
22 @@ -203,13 +203,15 @@ static int qce_skcipher_crypt(struct skc
23 struct qce_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
24 struct qce_cipher_reqctx *rctx = skcipher_request_ctx(req);
25 struct qce_alg_template *tmpl = to_cipher_tmpl(tfm);
26 + int keylen;
27 int ret;
28
29 rctx->flags = tmpl->alg_flags;
30 rctx->flags |= encrypt ? QCE_ENCRYPT : QCE_DECRYPT;
31 + keylen = IS_XTS(rctx->flags) ? ctx->enc_keylen >> 1 : ctx->enc_keylen;
32
33 - if (IS_AES(rctx->flags) && ctx->enc_keylen != AES_KEYSIZE_128 &&
34 - ctx->enc_keylen != AES_KEYSIZE_256) {
35 + if (IS_AES(rctx->flags) && keylen != AES_KEYSIZE_128 &&
36 + keylen != AES_KEYSIZE_256) {
37 SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback);
38
39 skcipher_request_set_tfm(subreq, ctx->fallback);
40 @@ -302,8 +304,8 @@ static const struct qce_skcipher_def skc
41 .drv_name = "xts-aes-qce",
42 .blocksize = AES_BLOCK_SIZE,
43 .ivsize = AES_BLOCK_SIZE,
44 - .min_keysize = AES_MIN_KEY_SIZE,
45 - .max_keysize = AES_MAX_KEY_SIZE,
46 + .min_keysize = AES_MIN_KEY_SIZE * 2,
47 + .max_keysize = AES_MAX_KEY_SIZE * 2,
48 },
49 {
50 .flags = QCE_ALG_DES | QCE_MODE_ECB,