Commit 5964f26c authored by Herbert Xu's avatar Herbert Xu

crypto: seqiv - Replace seqniv with seqiv

This patch replaces the seqniv generator with seqiv when the
underlying algorithm understands the new calling convention.

This not only makes more sense as now seqiv is solely responsible
for IV generation rather than also determining how the IV is going
to be used, it also allows for optimisations in the underlying
implementation.  For example, the space for the IV could be used
to add padding for authentication.

This patch also removes the unnecessary copying of IV to dst
during seqiv decryption as the IV is part of the AD and not cipher
text.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 5499b1a7
...@@ -467,9 +467,6 @@ static int seqiv_aead_decrypt(struct aead_request *req) ...@@ -467,9 +467,6 @@ static int seqiv_aead_decrypt(struct aead_request *req)
aead_request_set_ad(subreq, req->assoclen + ivsize); aead_request_set_ad(subreq, req->assoclen + ivsize);
scatterwalk_map_and_copy(req->iv, req->src, req->assoclen, ivsize, 0); scatterwalk_map_and_copy(req->iv, req->src, req->assoclen, ivsize, 0);
if (req->src != req->dst)
scatterwalk_map_and_copy(req->iv, req->dst,
req->assoclen, ivsize, 1);
return crypto_aead_decrypt(subreq); return crypto_aead_decrypt(subreq);
} }
...@@ -516,9 +513,9 @@ static int seqiv_old_aead_init(struct crypto_tfm *tfm) ...@@ -516,9 +513,9 @@ static int seqiv_old_aead_init(struct crypto_tfm *tfm)
return err ?: aead_geniv_init(tfm); return err ?: aead_geniv_init(tfm);
} }
static int seqiv_aead_init_common(struct crypto_tfm *tfm, unsigned int reqsize) static int seqiv_aead_init_common(struct crypto_aead *geniv,
unsigned int reqsize)
{ {
struct crypto_aead *geniv = __crypto_aead_cast(tfm);
struct seqiv_aead_ctx *ctx = crypto_aead_ctx(geniv); struct seqiv_aead_ctx *ctx = crypto_aead_ctx(geniv);
int err; int err;
...@@ -541,7 +538,7 @@ static int seqiv_aead_init_common(struct crypto_tfm *tfm, unsigned int reqsize) ...@@ -541,7 +538,7 @@ static int seqiv_aead_init_common(struct crypto_tfm *tfm, unsigned int reqsize)
if (IS_ERR(ctx->null)) if (IS_ERR(ctx->null))
goto out; goto out;
err = aead_geniv_init(tfm); err = aead_geniv_init(crypto_aead_tfm(geniv));
if (err) if (err)
goto drop_null; goto drop_null;
...@@ -556,19 +553,19 @@ static int seqiv_aead_init_common(struct crypto_tfm *tfm, unsigned int reqsize) ...@@ -556,19 +553,19 @@ static int seqiv_aead_init_common(struct crypto_tfm *tfm, unsigned int reqsize)
goto out; goto out;
} }
static int seqiv_aead_init(struct crypto_tfm *tfm) static int seqiv_aead_init(struct crypto_aead *tfm)
{ {
return seqiv_aead_init_common(tfm, sizeof(struct aead_request)); return seqiv_aead_init_common(tfm, sizeof(struct aead_request));
} }
static int seqniv_aead_init(struct crypto_tfm *tfm) static int seqniv_aead_init(struct crypto_aead *tfm)
{ {
return seqiv_aead_init_common(tfm, sizeof(struct seqniv_request_ctx)); return seqiv_aead_init_common(tfm, sizeof(struct seqniv_request_ctx));
} }
static void seqiv_aead_exit(struct crypto_tfm *tfm) static void seqiv_aead_exit(struct crypto_aead *tfm)
{ {
struct seqiv_aead_ctx *ctx = crypto_tfm_ctx(tfm); struct seqiv_aead_ctx *ctx = crypto_aead_ctx(tfm);
crypto_free_aead(ctx->geniv.child); crypto_free_aead(ctx->geniv.child);
crypto_put_default_null_skcipher(); crypto_put_default_null_skcipher();
...@@ -666,11 +663,11 @@ static int seqiv_aead_create(struct crypto_template *tmpl, struct rtattr **tb) ...@@ -666,11 +663,11 @@ static int seqiv_aead_create(struct crypto_template *tmpl, struct rtattr **tb)
inst->alg.encrypt = seqiv_aead_encrypt; inst->alg.encrypt = seqiv_aead_encrypt;
inst->alg.decrypt = seqiv_aead_decrypt; inst->alg.decrypt = seqiv_aead_decrypt;
inst->alg.base.cra_init = seqiv_aead_init; inst->alg.init = seqiv_aead_init;
inst->alg.base.cra_exit = seqiv_aead_exit; inst->alg.exit = seqiv_aead_exit;
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.ivsize;
done: done:
err = aead_register_instance(tmpl, inst); err = aead_register_instance(tmpl, inst);
...@@ -727,8 +724,15 @@ static int seqniv_create(struct crypto_template *tmpl, struct rtattr **tb) ...@@ -727,8 +724,15 @@ static int seqniv_create(struct crypto_template *tmpl, struct rtattr **tb)
inst->alg.encrypt = seqniv_aead_encrypt; inst->alg.encrypt = seqniv_aead_encrypt;
inst->alg.decrypt = seqniv_aead_decrypt; inst->alg.decrypt = seqniv_aead_decrypt;
inst->alg.base.cra_init = seqniv_aead_init; inst->alg.init = seqniv_aead_init;
inst->alg.base.cra_exit = seqiv_aead_exit; inst->alg.exit = seqiv_aead_exit;
if ((alg->base.cra_flags & CRYPTO_ALG_AEAD_NEW)) {
inst->alg.encrypt = seqiv_aead_encrypt;
inst->alg.decrypt = seqiv_aead_decrypt;
inst->alg.init = seqiv_aead_init;
}
inst->alg.base.cra_alignmask |= __alignof__(u32) - 1; inst->alg.base.cra_alignmask |= __alignof__(u32) - 1;
inst->alg.base.cra_ctxsize = sizeof(struct seqiv_aead_ctx); inst->alg.base.cra_ctxsize = sizeof(struct seqiv_aead_ctx);
......
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