Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: cbcmac - use crypto_grab_cipher() and simplify error paths

Make the cbcmac template use the new function crypto_grab_cipher() to
initialize its cipher spawn.

This is needed to make all spawns be initialized in a consistent way.

This required making cbcmac_create() allocate the instance directly
rather than use shash_alloc_instance().

Also simplify the error handling by taking advantage of crypto_drop_*()
now accepting (as a no-op) spawns that haven't been initialized yet, and
by taking advantage of crypto_grab_*() now handling ERR_PTR() names.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
16672970 aacd5b4c

+16 -19
+16 -19
crypto/ccm.c
··· 887 887 static int cbcmac_create(struct crypto_template *tmpl, struct rtattr **tb) 888 888 { 889 889 struct shash_instance *inst; 890 + struct crypto_cipher_spawn *spawn; 890 891 struct crypto_alg *alg; 891 892 int err; 892 893 ··· 895 894 if (err) 896 895 return err; 897 896 898 - alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, 899 - CRYPTO_ALG_TYPE_MASK); 900 - if (IS_ERR(alg)) 901 - return PTR_ERR(alg); 897 + inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); 898 + if (!inst) 899 + return -ENOMEM; 900 + spawn = shash_instance_ctx(inst); 902 901 903 - inst = shash_alloc_instance("cbcmac", alg); 904 - err = PTR_ERR(inst); 905 - if (IS_ERR(inst)) 906 - goto out_put_alg; 907 - 908 - err = crypto_init_spawn(shash_instance_ctx(inst), alg, 909 - shash_crypto_instance(inst), 910 - CRYPTO_ALG_TYPE_MASK); 902 + err = crypto_grab_cipher(spawn, shash_crypto_instance(inst), 903 + crypto_attr_alg_name(tb[1]), 0, 0); 911 904 if (err) 912 - goto out_free_inst; 905 + goto err_free_inst; 906 + alg = crypto_spawn_cipher_alg(spawn); 907 + 908 + err = crypto_inst_setname(shash_crypto_instance(inst), tmpl->name, alg); 909 + if (err) 910 + goto err_free_inst; 913 911 914 912 inst->alg.base.cra_priority = alg->cra_priority; 915 913 inst->alg.base.cra_blocksize = 1; ··· 928 928 inst->alg.setkey = crypto_cbcmac_digest_setkey; 929 929 930 930 err = shash_register_instance(tmpl, inst); 931 - 932 - out_free_inst: 933 - if (err) 931 + if (err) { 932 + err_free_inst: 934 933 shash_free_instance(shash_crypto_instance(inst)); 935 - 936 - out_put_alg: 937 - crypto_mod_put(alg); 934 + } 938 935 return err; 939 936 } 940 937