ipq40xx: qce - add fixes for AES ciphers
[openwrt/staging/jogo.git] / target / linux / ipq40xx / patches-5.4 / 046-crypto-qce-initialize-fallback-only-for-AES.patch
1 From 8ceda883205db6dfedb82e39f67feae3b50c95a1 Mon Sep 17 00:00:00 2001
2 From: Eneas U de Queiroz <cotequeiroz@gmail.com>
3 Date: Fri, 20 Dec 2019 16:02:17 -0300
4 Subject: [PATCH 06/11] crypto: qce - initialize fallback only for AES
5
6 Adjust cra_flags to add CRYPTO_NEED_FALLBACK only for AES ciphers, where
7 AES-192 is not handled by the qce hardware, and don't allocate & free
8 the fallback skcipher for other algorithms.
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/skcipher.c | 17 ++++++++++++++---
14 1 file changed, 14 insertions(+), 3 deletions(-)
15
16 --- a/drivers/crypto/qce/skcipher.c
17 +++ b/drivers/crypto/qce/skcipher.c
18 @@ -257,7 +257,14 @@ static int qce_skcipher_init(struct cryp
19
20 memset(ctx, 0, sizeof(*ctx));
21 crypto_skcipher_set_reqsize(tfm, sizeof(struct qce_cipher_reqctx));
22 + return 0;
23 +}
24 +
25 +static int qce_skcipher_init_fallback(struct crypto_skcipher *tfm)
26 +{
27 + struct qce_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
28
29 + qce_skcipher_init(tfm);
30 ctx->fallback = crypto_alloc_sync_skcipher(crypto_tfm_alg_name(&tfm->base),
31 0, CRYPTO_ALG_NEED_FALLBACK);
32 return PTR_ERR_OR_ZERO(ctx->fallback);
33 @@ -387,14 +394,18 @@ static int qce_skcipher_register_one(con
34
35 alg->base.cra_priority = 300;
36 alg->base.cra_flags = CRYPTO_ALG_ASYNC |
37 - CRYPTO_ALG_NEED_FALLBACK |
38 CRYPTO_ALG_KERN_DRIVER_ONLY;
39 alg->base.cra_ctxsize = sizeof(struct qce_cipher_ctx);
40 alg->base.cra_alignmask = 0;
41 alg->base.cra_module = THIS_MODULE;
42
43 - alg->init = qce_skcipher_init;
44 - alg->exit = qce_skcipher_exit;
45 + if (IS_AES(def->flags)) {
46 + alg->base.cra_flags |= CRYPTO_ALG_NEED_FALLBACK;
47 + alg->init = qce_skcipher_init_fallback;
48 + alg->exit = qce_skcipher_exit;
49 + } else {
50 + alg->init = qce_skcipher_init;
51 + }
52
53 INIT_LIST_HEAD(&tmpl->entry);
54 tmpl->crypto_alg_type = CRYPTO_ALG_TYPE_SKCIPHER;