__be64 seq;
int err;
+ if (req->cryptlen < ivsize)
+ return -EINVAL;
+
compl = req->base.complete;
data = req->base.data;
crypto_completion_t compl;
void *data;
u8 *info;
- unsigned int ivsize;
+ unsigned int ivsize = crypto_aead_ivsize(geniv);
int err;
+ if (req->cryptlen < ivsize)
+ return -EINVAL;
+
aead_request_set_tfm(subreq, ctx->child);
compl = echainiv_encrypt_complete;
data = req;
info = req->iv;
- ivsize = crypto_aead_ivsize(geniv);
-
if (req->src != req->dst) {
struct scatterlist src[2];
struct scatterlist dst[2];
aead_request_set_callback(subreq, req->base.flags, compl, data);
aead_request_set_crypt(subreq, req->dst, req->dst,
req->cryptlen - ivsize, info);
- aead_request_set_ad(subreq, req->assoclen + ivsize, 0);
+ aead_request_set_ad(subreq, req->assoclen + ivsize);
crypto_xor(info, ctx->salt, ivsize);
scatterwalk_map_and_copy(info, req->dst, req->assoclen, ivsize, 1);
{
struct crypto_aead *geniv = crypto_aead_reqtfm(req);
struct echainiv_ctx *ctx = crypto_aead_ctx(geniv);
- struct aead_request *subreq = aead_request_ctx(req);
+ struct echainiv_request_ctx *rctx = aead_request_ctx(req);
+ struct aead_request *subreq = &rctx->subreq.areq;
crypto_completion_t compl;
void *data;
- unsigned int ivsize;
+ unsigned int ivsize = crypto_aead_ivsize(geniv);
+
+ if (req->cryptlen < ivsize + crypto_aead_authsize(geniv))
+ return -EINVAL;
aead_request_set_tfm(subreq, ctx->child);
compl = req->base.complete;
data = req->base.data;
- ivsize = crypto_aead_ivsize(geniv);
-
aead_request_set_callback(subreq, req->base.flags, compl, data);
- aead_request_set_crypt(subreq, req->src, req->dst,
+ aead_request_set_crypt(subreq,
+ scatterwalk_ffwd(rctx->src, req->src,
+ req->assoclen + ivsize),
+ scatterwalk_ffwd(rctx->dst, req->dst,
+ req->assoclen + ivsize),
req->cryptlen - ivsize, req->iv);
- aead_request_set_ad(subreq, req->assoclen, ivsize);
+ aead_request_set_assoc(subreq, req->src, req->assoclen);
scatterwalk_map_and_copy(req->iv, req->src, req->assoclen, ivsize, 0);
struct aead_request *subreq = aead_request_ctx(req);
crypto_completion_t compl;
void *data;
- unsigned int ivsize;
+ unsigned int ivsize = crypto_aead_ivsize(geniv);
+
+ if (req->cryptlen < ivsize + crypto_aead_authsize(geniv))
+ return -EINVAL;
aead_request_set_tfm(subreq, ctx->child);
compl = req->base.complete;
data = req->base.data;
- ivsize = crypto_aead_ivsize(geniv);
-
aead_request_set_callback(subreq, req->base.flags, compl, data);
aead_request_set_crypt(subreq, req->src, req->dst,
req->cryptlen - ivsize, req->iv);
- aead_request_set_ad(subreq, req->assoclen + ivsize, 0);
+ aead_request_set_ad(subreq, req->assoclen + ivsize);
scatterwalk_map_and_copy(req->iv, req->src, req->assoclen, ivsize, 0);
if (req->src != req->dst)
crypto_put_default_null_skcipher();
}
-static struct crypto_template echainiv_tmpl;
-
-static struct crypto_instance *echainiv_aead_alloc(struct rtattr **tb)
+static int echainiv_aead_create(struct crypto_template *tmpl,
+ struct rtattr **tb)
{
struct aead_instance *inst;
struct crypto_aead_spawn *spawn;
struct aead_alg *alg;
+ int err;
- inst = aead_geniv_alloc(&echainiv_tmpl, tb, 0, 0);
+ inst = aead_geniv_alloc(tmpl, tb, 0, 0);
if (IS_ERR(inst))
- goto out;
+ return PTR_ERR(inst);
+ err = -EINVAL;
if (inst->alg.ivsize < sizeof(u64) ||
inst->alg.ivsize & (sizeof(u32) - 1) ||
- inst->alg.ivsize > MAX_IV_SIZE) {
- aead_geniv_free(inst);
- inst = ERR_PTR(-EINVAL);
- goto out;
- }
+ inst->alg.ivsize > MAX_IV_SIZE)
+ goto free_inst;
spawn = aead_instance_ctx(inst);
alg = crypto_spawn_aead_alg(spawn);
inst->alg.base.cra_exit = echainiv_compat_exit;
}
+ err = aead_register_instance(tmpl, inst);
+ if (err)
+ goto free_inst;
+
out:
- return aead_crypto_instance(inst);
+ return err;
+
+free_inst:
+ aead_geniv_free(inst);
+ goto out;
}
-static struct crypto_instance *echainiv_alloc(struct rtattr **tb)
+static int echainiv_create(struct crypto_template *tmpl, struct rtattr **tb)
{
- struct crypto_instance *inst;
int err;
err = crypto_get_default_rng();
if (err)
- return ERR_PTR(err);
-
- inst = echainiv_aead_alloc(tb);
+ goto out;
- if (IS_ERR(inst))
+ err = echainiv_aead_create(tmpl, tb);
+ if (err)
goto put_rng;
out:
- return inst;
+ return err;
put_rng:
crypto_put_default_rng();
static struct crypto_template echainiv_tmpl = {
.name = "echainiv",
- .alloc = echainiv_alloc,
+ .create = echainiv_create,
.free = echainiv_free,
.module = THIS_MODULE,
};