[dm-devel] [PATCH 2/6] crypto: algapi - use common mechanism for inheriting flags

Herbert Xu herbert at gondor.apana.org.au
Thu Jul 9 05:31:26 UTC 2020


Eric Biggers <ebiggers at kernel.org> wrote:
>
> @@ -875,14 +873,21 @@ static void cbcmac_exit_tfm(struct crypto_tfm *tfm)
> 
> static int cbcmac_create(struct crypto_template *tmpl, struct rtattr **tb)
> {
> +       struct crypto_attr_type *algt;
>        struct shash_instance *inst;
>        struct crypto_cipher_spawn *spawn;
>        struct crypto_alg *alg;
> +       u32 mask;
>        int err;
> 
> -       err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH);
> -       if (err)
> -               return err;
> +       algt = crypto_get_attr_type(tb);
> +       if (IS_ERR(algt))
> +               return PTR_ERR(algt);
> +
> +       if ((algt->type ^ CRYPTO_ALG_TYPE_SHASH) & algt->mask)
> +               return -EINVAL;
> +
> +       mask = crypto_algt_inherited_mask(algt);

How about moving the types check into crypto_algt_inherited_mask,
e.g.,

	u32 mask;
	int err;

	err = crypto_algt_inherited_mask(tb, CRYPTO_ALG_TYPE_SHASH);
	if (err < 0)
		return err;

	mask = err;

This could then be used to simplify other templates too, such as
gcm.

Thanks,
-- 
Email: Herbert Xu <herbert at gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt




More information about the dm-devel mailing list