Commit 0677157b authored by Herbert Xu's avatar Herbert Xu

crypto: seqiv - Use aead_register_instance

New style AEAD instances must use aead_register_instance.  This
worked by chance because aead_geniv_alloc is still setting things
the old way.

This patch converts the template over to the create model where
we are responsible for instance registration so that we can call
the correct function.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 72af865d
...@@ -38,6 +38,8 @@ struct seqiv_aead_ctx { ...@@ -38,6 +38,8 @@ struct seqiv_aead_ctx {
u8 salt[] __attribute__ ((aligned(__alignof__(u32)))); u8 salt[] __attribute__ ((aligned(__alignof__(u32))));
}; };
static void seqiv_free(struct crypto_instance *inst);
static int seqiv_aead_setkey(struct crypto_aead *tfm, static int seqiv_aead_setkey(struct crypto_aead *tfm,
const u8 *key, unsigned int keylen) const u8 *key, unsigned int keylen)
{ {
...@@ -583,23 +585,20 @@ static void seqiv_aead_exit(struct crypto_tfm *tfm) ...@@ -583,23 +585,20 @@ static void seqiv_aead_exit(struct crypto_tfm *tfm)
crypto_put_default_null_skcipher(); crypto_put_default_null_skcipher();
} }
static struct crypto_template seqiv_tmpl; static int seqiv_ablkcipher_create(struct crypto_template *tmpl,
static struct crypto_template seqniv_tmpl; struct rtattr **tb)
static struct crypto_instance *seqiv_ablkcipher_alloc(struct rtattr **tb)
{ {
struct crypto_instance *inst; struct crypto_instance *inst;
int err;
inst = skcipher_geniv_alloc(&seqiv_tmpl, tb, 0, 0); inst = skcipher_geniv_alloc(tmpl, tb, 0, 0);
if (IS_ERR(inst)) if (IS_ERR(inst))
goto out; return PTR_ERR(inst);
if (inst->alg.cra_ablkcipher.ivsize < sizeof(u64)) { err = -EINVAL;
skcipher_geniv_free(inst); if (inst->alg.cra_ablkcipher.ivsize < sizeof(u64))
inst = ERR_PTR(-EINVAL); goto free_inst;
goto out;
}
inst->alg.cra_ablkcipher.givencrypt = seqiv_givencrypt_first; inst->alg.cra_ablkcipher.givencrypt = seqiv_givencrypt_first;
...@@ -609,18 +608,28 @@ static struct crypto_instance *seqiv_ablkcipher_alloc(struct rtattr **tb) ...@@ -609,18 +608,28 @@ static struct crypto_instance *seqiv_ablkcipher_alloc(struct rtattr **tb)
inst->alg.cra_ctxsize += inst->alg.cra_ablkcipher.ivsize; inst->alg.cra_ctxsize += inst->alg.cra_ablkcipher.ivsize;
inst->alg.cra_ctxsize += sizeof(struct seqiv_ctx); inst->alg.cra_ctxsize += sizeof(struct seqiv_ctx);
inst->alg.cra_alignmask |= __alignof__(u32) - 1;
err = crypto_register_instance(tmpl, inst);
if (err)
goto free_inst;
out: out:
return inst; return err;
free_inst:
skcipher_geniv_free(inst);
goto out;
} }
static struct crypto_instance *seqiv_old_aead_alloc(struct aead_instance *aead) static int seqiv_old_aead_create(struct crypto_template *tmpl,
struct aead_instance *aead)
{ {
struct crypto_instance *inst = aead_crypto_instance(aead); struct crypto_instance *inst = aead_crypto_instance(aead);
int err = -EINVAL;
if (inst->alg.cra_aead.ivsize < sizeof(u64)) { if (inst->alg.cra_aead.ivsize < sizeof(u64))
aead_geniv_free(aead); goto free_inst;
return ERR_PTR(-EINVAL);
}
inst->alg.cra_aead.givencrypt = seqiv_aead_givencrypt_first; inst->alg.cra_aead.givencrypt = seqiv_aead_givencrypt_first;
...@@ -630,28 +639,38 @@ static struct crypto_instance *seqiv_old_aead_alloc(struct aead_instance *aead) ...@@ -630,28 +639,38 @@ static struct crypto_instance *seqiv_old_aead_alloc(struct aead_instance *aead)
inst->alg.cra_ctxsize = inst->alg.cra_aead.ivsize; inst->alg.cra_ctxsize = inst->alg.cra_aead.ivsize;
inst->alg.cra_ctxsize += sizeof(struct seqiv_ctx); inst->alg.cra_ctxsize += sizeof(struct seqiv_ctx);
return inst; err = crypto_register_instance(tmpl, inst);
if (err)
goto free_inst;
out:
return err;
free_inst:
aead_geniv_free(aead);
goto out;
} }
static struct crypto_instance *seqiv_aead_alloc(struct rtattr **tb) static int seqiv_aead_create(struct crypto_template *tmpl, struct rtattr **tb)
{ {
struct aead_instance *inst; struct aead_instance *inst;
struct crypto_aead_spawn *spawn; struct crypto_aead_spawn *spawn;
struct aead_alg *alg; struct aead_alg *alg;
int err;
inst = aead_geniv_alloc(&seqiv_tmpl, tb, 0, 0); inst = aead_geniv_alloc(tmpl, tb, 0, 0);
if (IS_ERR(inst)) if (IS_ERR(inst))
goto out; return PTR_ERR(inst);
inst->alg.base.cra_alignmask |= __alignof__(u32) - 1;
if (inst->alg.base.cra_aead.encrypt) if (inst->alg.base.cra_aead.encrypt)
return seqiv_old_aead_alloc(inst); return seqiv_old_aead_create(tmpl, inst);
if (inst->alg.ivsize < sizeof(u64)) { err = -EINVAL;
aead_geniv_free(inst); if (inst->alg.ivsize < sizeof(u64))
inst = ERR_PTR(-EINVAL); goto free_inst;
goto out;
}
spawn = aead_instance_ctx(inst); spawn = aead_instance_ctx(inst);
alg = crypto_spawn_aead_alg(spawn); alg = crypto_spawn_aead_alg(spawn);
...@@ -675,43 +694,43 @@ static struct crypto_instance *seqiv_aead_alloc(struct rtattr **tb) ...@@ -675,43 +694,43 @@ static struct crypto_instance *seqiv_aead_alloc(struct rtattr **tb)
inst->alg.base.cra_exit = seqiv_aead_compat_exit; inst->alg.base.cra_exit = seqiv_aead_compat_exit;
} }
err = aead_register_instance(tmpl, inst);
if (err)
goto free_inst;
out: out:
return aead_crypto_instance(inst); return err;
free_inst:
aead_geniv_free(inst);
goto out;
} }
static struct crypto_instance *seqiv_alloc(struct rtattr **tb) static int seqiv_create(struct crypto_template *tmpl, struct rtattr **tb)
{ {
struct crypto_attr_type *algt; struct crypto_attr_type *algt;
struct crypto_instance *inst;
int err; int err;
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);
err = crypto_get_default_rng(); err = crypto_get_default_rng();
if (err) if (err)
return ERR_PTR(err); return err;
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK) if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK)
inst = seqiv_ablkcipher_alloc(tb); err = seqiv_ablkcipher_create(tmpl, tb);
else else
inst = seqiv_aead_alloc(tb); err = seqiv_aead_create(tmpl, tb);
if (IS_ERR(inst))
goto put_rng;
inst->alg.cra_alignmask |= __alignof__(u32) - 1;
out:
return inst;
put_rng: if (err)
crypto_put_default_rng(); crypto_put_default_rng();
goto out;
return err;
} }
static struct crypto_instance *seqniv_alloc(struct rtattr **tb) static int seqniv_create(struct crypto_template *tmpl, struct rtattr **tb)
{ {
struct aead_instance *inst; struct aead_instance *inst;
struct crypto_aead_spawn *spawn; struct crypto_aead_spawn *spawn;
...@@ -720,18 +739,16 @@ static struct crypto_instance *seqniv_alloc(struct rtattr **tb) ...@@ -720,18 +739,16 @@ static struct crypto_instance *seqniv_alloc(struct rtattr **tb)
err = crypto_get_default_rng(); err = crypto_get_default_rng();
if (err) if (err)
return ERR_PTR(err); return err;
inst = aead_geniv_alloc(&seqniv_tmpl, tb, 0, 0);
inst = aead_geniv_alloc(tmpl, tb, 0, 0);
err = PTR_ERR(inst);
if (IS_ERR(inst)) if (IS_ERR(inst))
goto put_rng; goto put_rng;
if (inst->alg.ivsize < sizeof(u64)) { err = -EINVAL;
aead_geniv_free(inst); if (inst->alg.ivsize < sizeof(u64))
inst = ERR_PTR(-EINVAL); goto free_inst;
goto put_rng;
}
spawn = aead_instance_ctx(inst); spawn = aead_instance_ctx(inst);
alg = crypto_spawn_aead_alg(spawn); alg = crypto_spawn_aead_alg(spawn);
...@@ -748,9 +765,15 @@ static struct crypto_instance *seqniv_alloc(struct rtattr **tb) ...@@ -748,9 +765,15 @@ static struct crypto_instance *seqniv_alloc(struct rtattr **tb)
inst->alg.base.cra_ctxsize = sizeof(struct seqiv_aead_ctx); inst->alg.base.cra_ctxsize = sizeof(struct seqiv_aead_ctx);
inst->alg.base.cra_ctxsize += inst->alg.base.cra_aead.ivsize; inst->alg.base.cra_ctxsize += inst->alg.base.cra_aead.ivsize;
err = aead_register_instance(tmpl, inst);
if (err)
goto free_inst;
out: out:
return aead_crypto_instance(inst); return err;
free_inst:
aead_geniv_free(inst);
put_rng: put_rng:
crypto_put_default_rng(); crypto_put_default_rng();
goto out; goto out;
...@@ -767,14 +790,14 @@ static void seqiv_free(struct crypto_instance *inst) ...@@ -767,14 +790,14 @@ static void seqiv_free(struct crypto_instance *inst)
static struct crypto_template seqiv_tmpl = { static struct crypto_template seqiv_tmpl = {
.name = "seqiv", .name = "seqiv",
.alloc = seqiv_alloc, .create = seqiv_create,
.free = seqiv_free, .free = seqiv_free,
.module = THIS_MODULE, .module = THIS_MODULE,
}; };
static struct crypto_template seqniv_tmpl = { static struct crypto_template seqniv_tmpl = {
.name = "seqniv", .name = "seqniv",
.alloc = seqniv_alloc, .create = seqniv_create,
.free = seqiv_free, .free = seqiv_free,
.module = THIS_MODULE, .module = THIS_MODULE,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment