Skip to content

Commit f52bbf5

Browse files
smuellerDDherbertx
authored andcommitted
crypto: mcryptd - process CRYPTO_ALG_INTERNAL
The mcryptd is used as a wrapper around internal ciphers. Therefore, the mcryptd must process the internal cipher by marking mcryptd as internal if the underlying cipher is an internal cipher. Signed-off-by: Stephan Mueller <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent cd98411 commit f52bbf5

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

crypto/mcryptd.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,20 @@ static void *mcryptd_alloc_instance(struct crypto_alg *alg, unsigned int head,
258258
goto out;
259259
}
260260

261+
static inline void mcryptd_check_internal(struct rtattr **tb, u32 *type,
262+
u32 *mask)
263+
{
264+
struct crypto_attr_type *algt;
265+
266+
algt = crypto_get_attr_type(tb);
267+
if (IS_ERR(algt))
268+
return;
269+
if ((algt->type & CRYPTO_ALG_INTERNAL))
270+
*type |= CRYPTO_ALG_INTERNAL;
271+
if ((algt->mask & CRYPTO_ALG_INTERNAL))
272+
*mask |= CRYPTO_ALG_INTERNAL;
273+
}
274+
261275
static int mcryptd_hash_init_tfm(struct crypto_tfm *tfm)
262276
{
263277
struct crypto_instance *inst = crypto_tfm_alg_instance(tfm);
@@ -480,9 +494,13 @@ static int mcryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
480494
struct ahash_instance *inst;
481495
struct shash_alg *salg;
482496
struct crypto_alg *alg;
497+
u32 type = 0;
498+
u32 mask = 0;
483499
int err;
484500

485-
salg = shash_attr_alg(tb[1], 0, 0);
501+
mcryptd_check_internal(tb, &type, &mask);
502+
503+
salg = shash_attr_alg(tb[1], type, mask);
486504
if (IS_ERR(salg))
487505
return PTR_ERR(salg);
488506

@@ -502,7 +520,10 @@ static int mcryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
502520
if (err)
503521
goto out_free_inst;
504522

505-
inst->alg.halg.base.cra_flags = CRYPTO_ALG_ASYNC;
523+
type = CRYPTO_ALG_ASYNC;
524+
if (alg->cra_flags & CRYPTO_ALG_INTERNAL)
525+
type |= CRYPTO_ALG_INTERNAL;
526+
inst->alg.halg.base.cra_flags = type;
506527

507528
inst->alg.halg.digestsize = salg->digestsize;
508529
inst->alg.halg.base.cra_ctxsize = sizeof(struct mcryptd_hash_ctx);

0 commit comments

Comments
 (0)