mirror of
https://github.com/adulau/aha.git
synced 2024-12-27 11:16:11 +00:00
crypto: cryptd - Switch to template create API
This patch changes cryptd to use the template->create function instead of alloc in anticipation for the switch to new style ahash algorithms. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
52861c7cd7
commit
9cd899a32f
3 changed files with 32 additions and 27 deletions
|
@ -287,8 +287,9 @@ out_free_inst:
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct crypto_instance *cryptd_alloc_blkcipher(
|
static int cryptd_create_blkcipher(struct crypto_template *tmpl,
|
||||||
struct rtattr **tb, struct cryptd_queue *queue)
|
struct rtattr **tb,
|
||||||
|
struct cryptd_queue *queue)
|
||||||
{
|
{
|
||||||
struct cryptd_instance_ctx *ctx;
|
struct cryptd_instance_ctx *ctx;
|
||||||
struct crypto_instance *inst;
|
struct crypto_instance *inst;
|
||||||
|
@ -298,7 +299,7 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
|
||||||
alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER,
|
alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER,
|
||||||
CRYPTO_ALG_TYPE_MASK);
|
CRYPTO_ALG_TYPE_MASK);
|
||||||
if (IS_ERR(alg))
|
if (IS_ERR(alg))
|
||||||
return ERR_CAST(alg);
|
return PTR_ERR(alg);
|
||||||
|
|
||||||
inst = cryptd_alloc_instance(alg, sizeof(*ctx));
|
inst = cryptd_alloc_instance(alg, sizeof(*ctx));
|
||||||
if (IS_ERR(inst))
|
if (IS_ERR(inst))
|
||||||
|
@ -330,14 +331,16 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
|
||||||
inst->alg.cra_ablkcipher.encrypt = cryptd_blkcipher_encrypt_enqueue;
|
inst->alg.cra_ablkcipher.encrypt = cryptd_blkcipher_encrypt_enqueue;
|
||||||
inst->alg.cra_ablkcipher.decrypt = cryptd_blkcipher_decrypt_enqueue;
|
inst->alg.cra_ablkcipher.decrypt = cryptd_blkcipher_decrypt_enqueue;
|
||||||
|
|
||||||
|
err = crypto_register_instance(tmpl, inst);
|
||||||
|
if (err) {
|
||||||
|
crypto_drop_spawn(&ctx->spawn);
|
||||||
|
out_free_inst:
|
||||||
|
kfree(inst);
|
||||||
|
}
|
||||||
|
|
||||||
out_put_alg:
|
out_put_alg:
|
||||||
crypto_mod_put(alg);
|
crypto_mod_put(alg);
|
||||||
return inst;
|
return err;
|
||||||
|
|
||||||
out_free_inst:
|
|
||||||
kfree(inst);
|
|
||||||
inst = ERR_PTR(err);
|
|
||||||
goto out_put_alg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cryptd_hash_init_tfm(struct crypto_tfm *tfm)
|
static int cryptd_hash_init_tfm(struct crypto_tfm *tfm)
|
||||||
|
@ -502,8 +505,8 @@ static int cryptd_hash_digest_enqueue(struct ahash_request *req)
|
||||||
return cryptd_hash_enqueue(req, cryptd_hash_digest);
|
return cryptd_hash_enqueue(req, cryptd_hash_digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct crypto_instance *cryptd_alloc_hash(
|
static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
|
||||||
struct rtattr **tb, struct cryptd_queue *queue)
|
struct cryptd_queue *queue)
|
||||||
{
|
{
|
||||||
struct hashd_instance_ctx *ctx;
|
struct hashd_instance_ctx *ctx;
|
||||||
struct crypto_instance *inst;
|
struct crypto_instance *inst;
|
||||||
|
@ -513,7 +516,7 @@ static struct crypto_instance *cryptd_alloc_hash(
|
||||||
|
|
||||||
salg = shash_attr_alg(tb[1], 0, 0);
|
salg = shash_attr_alg(tb[1], 0, 0);
|
||||||
if (IS_ERR(salg))
|
if (IS_ERR(salg))
|
||||||
return ERR_CAST(salg);
|
return PTR_ERR(salg);
|
||||||
|
|
||||||
alg = &salg->base;
|
alg = &salg->base;
|
||||||
inst = cryptd_alloc_instance(alg, sizeof(*ctx));
|
inst = cryptd_alloc_instance(alg, sizeof(*ctx));
|
||||||
|
@ -542,34 +545,36 @@ static struct crypto_instance *cryptd_alloc_hash(
|
||||||
inst->alg.cra_ahash.setkey = cryptd_hash_setkey;
|
inst->alg.cra_ahash.setkey = cryptd_hash_setkey;
|
||||||
inst->alg.cra_ahash.digest = cryptd_hash_digest_enqueue;
|
inst->alg.cra_ahash.digest = cryptd_hash_digest_enqueue;
|
||||||
|
|
||||||
|
err = crypto_register_instance(tmpl, inst);
|
||||||
|
if (err) {
|
||||||
|
crypto_drop_shash(&ctx->spawn);
|
||||||
|
out_free_inst:
|
||||||
|
kfree(inst);
|
||||||
|
}
|
||||||
|
|
||||||
out_put_alg:
|
out_put_alg:
|
||||||
crypto_mod_put(alg);
|
crypto_mod_put(alg);
|
||||||
return inst;
|
return err;
|
||||||
|
|
||||||
out_free_inst:
|
|
||||||
kfree(inst);
|
|
||||||
inst = ERR_PTR(err);
|
|
||||||
goto out_put_alg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct cryptd_queue queue;
|
static struct cryptd_queue queue;
|
||||||
|
|
||||||
static struct crypto_instance *cryptd_alloc(struct rtattr **tb)
|
static int cryptd_create(struct crypto_template *tmpl, struct rtattr **tb)
|
||||||
{
|
{
|
||||||
struct crypto_attr_type *algt;
|
struct crypto_attr_type *algt;
|
||||||
|
|
||||||
algt = crypto_get_attr_type(tb);
|
algt = crypto_get_attr_type(tb);
|
||||||
if (IS_ERR(algt))
|
if (IS_ERR(algt))
|
||||||
return ERR_CAST(algt);
|
return PTR_ERR(algt);
|
||||||
|
|
||||||
switch (algt->type & algt->mask & CRYPTO_ALG_TYPE_MASK) {
|
switch (algt->type & algt->mask & CRYPTO_ALG_TYPE_MASK) {
|
||||||
case CRYPTO_ALG_TYPE_BLKCIPHER:
|
case CRYPTO_ALG_TYPE_BLKCIPHER:
|
||||||
return cryptd_alloc_blkcipher(tb, &queue);
|
return cryptd_create_blkcipher(tmpl, tb, &queue);
|
||||||
case CRYPTO_ALG_TYPE_DIGEST:
|
case CRYPTO_ALG_TYPE_DIGEST:
|
||||||
return cryptd_alloc_hash(tb, &queue);
|
return cryptd_create_hash(tmpl, tb, &queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERR_PTR(-EINVAL);
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cryptd_free(struct crypto_instance *inst)
|
static void cryptd_free(struct crypto_instance *inst)
|
||||||
|
@ -582,7 +587,7 @@ static void cryptd_free(struct crypto_instance *inst)
|
||||||
|
|
||||||
static struct crypto_template cryptd_tmpl = {
|
static struct crypto_template cryptd_tmpl = {
|
||||||
.name = "cryptd",
|
.name = "cryptd",
|
||||||
.alloc = cryptd_alloc,
|
.create = cryptd_create,
|
||||||
.free = cryptd_free,
|
.free = cryptd_free,
|
||||||
.module = THIS_MODULE,
|
.module = THIS_MODULE,
|
||||||
};
|
};
|
||||||
|
|
|
@ -97,9 +97,6 @@ struct crypto_alg *crypto_find_alg(const char *alg_name,
|
||||||
void *crypto_alloc_tfm(const char *alg_name,
|
void *crypto_alloc_tfm(const char *alg_name,
|
||||||
const struct crypto_type *frontend, u32 type, u32 mask);
|
const struct crypto_type *frontend, u32 type, u32 mask);
|
||||||
|
|
||||||
int crypto_register_instance(struct crypto_template *tmpl,
|
|
||||||
struct crypto_instance *inst);
|
|
||||||
|
|
||||||
int crypto_register_notifier(struct notifier_block *nb);
|
int crypto_register_notifier(struct notifier_block *nb);
|
||||||
int crypto_unregister_notifier(struct notifier_block *nb);
|
int crypto_unregister_notifier(struct notifier_block *nb);
|
||||||
int crypto_probing_notify(unsigned long val, void *v);
|
int crypto_probing_notify(unsigned long val, void *v);
|
||||||
|
|
|
@ -114,6 +114,9 @@ int crypto_register_template(struct crypto_template *tmpl);
|
||||||
void crypto_unregister_template(struct crypto_template *tmpl);
|
void crypto_unregister_template(struct crypto_template *tmpl);
|
||||||
struct crypto_template *crypto_lookup_template(const char *name);
|
struct crypto_template *crypto_lookup_template(const char *name);
|
||||||
|
|
||||||
|
int crypto_register_instance(struct crypto_template *tmpl,
|
||||||
|
struct crypto_instance *inst);
|
||||||
|
|
||||||
int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg,
|
int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg,
|
||||||
struct crypto_instance *inst, u32 mask);
|
struct crypto_instance *inst, u32 mask);
|
||||||
int crypto_init_spawn2(struct crypto_spawn *spawn, struct crypto_alg *alg,
|
int crypto_init_spawn2(struct crypto_spawn *spawn, struct crypto_alg *alg,
|
||||||
|
|
Loading…
Reference in a new issue