0012-v5.6-crypto-qce-initialize-fallback-only-for-AES.patch 1.9 KB

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