Re: [PATCH v5 3/8] crypto: hctr2 - Add HCTR2 support

Eric Biggers
2022-05-02T18:25:56Z

On Wed, Apr 27, 2022 at 12:37:54AM +0000, Nathan Huckleberry wrote:
> +static int hctr2_create_common(struct crypto_template *tmpl,
> + struct rtattr **tb,
> + const char *xctr_name,
> + const char *polyval_name)
> +{
> + u32 mask;
> + struct skcipher_instance *inst;
> + struct hctr2_instance_ctx *ictx;
> + struct skcipher_alg *xctr_alg;
> + struct crypto_alg *blockcipher_alg;
> + struct shash_alg *polyval_alg;
> + char blockcipher_name[CRYPTO_MAX_ALG_NAME];
> + int len;
> + int err;
> +
> + err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SKCIPHER, &mask);
> + if (err)
> + return err;
> +
> + inst = kzalloc(sizeof(*inst) + sizeof(*ictx), GFP_KERNEL);
> + if (!inst)
> + return -ENOMEM;
> + ictx = skcipher_instance_ctx(inst);
> +
> + /* Stream cipher, xctr(block_cipher) */
> + err = crypto_grab_skcipher(&ictx->xctr_spawn,
> + skcipher_crypto_instance(inst),
> + xctr_name, 0, mask);
> + if (err)
> + goto err_free_inst;
> + xctr_alg = crypto_spawn_skcipher_alg(&ictx->xctr_spawn);
> +
> + err = -EINVAL;
> + if (strncmp(xctr_alg->base.cra_name, "xctr(", 5))
> + goto err_free_inst;
> + len = strscpy(blockcipher_name, xctr_name + 5,
> + sizeof(blockcipher_name));

Found a bug here; 'xctr_name' in the strscpy() statement needs to be
xctr_alg->base.cra_name. Otherwise something like
'hctr2_base(xctr-aes-aesni,polyval-clmulni)' doesn't work, as it will try to
extract the block cipher name from the driver name "xctr-aes-aesni" instead of
from the algorithm name "xctr(aes)" as intended.

- Eric