Skip to content

Commit 8ceda88

Browse files
cotequeirozherbertx
authored andcommitted
crypto: qce - initialize fallback only for AES
Adjust cra_flags to add CRYPTO_NEED_FALLBACK only for AES ciphers, where AES-192 is not handled by the qce hardware, and don't allocate & free the fallback skcipher for other algorithms. Signed-off-by: Eneas U de Queiroz <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 3e806a1 commit 8ceda88

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

drivers/crypto/qce/skcipher.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,14 @@ static int qce_skcipher_init(struct crypto_skcipher *tfm)
257257

258258
memset(ctx, 0, sizeof(*ctx));
259259
crypto_skcipher_set_reqsize(tfm, sizeof(struct qce_cipher_reqctx));
260+
return 0;
261+
}
260262

263+
static int qce_skcipher_init_fallback(struct crypto_skcipher *tfm)
264+
{
265+
struct qce_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
266+
267+
qce_skcipher_init(tfm);
261268
ctx->fallback = crypto_alloc_sync_skcipher(crypto_tfm_alg_name(&tfm->base),
262269
0, CRYPTO_ALG_NEED_FALLBACK);
263270
return PTR_ERR_OR_ZERO(ctx->fallback);
@@ -387,14 +394,18 @@ static int qce_skcipher_register_one(const struct qce_skcipher_def *def,
387394

388395
alg->base.cra_priority = 300;
389396
alg->base.cra_flags = CRYPTO_ALG_ASYNC |
390-
CRYPTO_ALG_NEED_FALLBACK |
391397
CRYPTO_ALG_KERN_DRIVER_ONLY;
392398
alg->base.cra_ctxsize = sizeof(struct qce_cipher_ctx);
393399
alg->base.cra_alignmask = 0;
394400
alg->base.cra_module = THIS_MODULE;
395401

396-
alg->init = qce_skcipher_init;
397-
alg->exit = qce_skcipher_exit;
402+
if (IS_AES(def->flags)) {
403+
alg->base.cra_flags |= CRYPTO_ALG_NEED_FALLBACK;
404+
alg->init = qce_skcipher_init_fallback;
405+
alg->exit = qce_skcipher_exit;
406+
} else {
407+
alg->init = qce_skcipher_init;
408+
}
398409

399410
INIT_LIST_HEAD(&tmpl->entry);
400411
tmpl->crypto_alg_type = CRYPTO_ALG_TYPE_SKCIPHER;

0 commit comments

Comments
 (0)