dect
/
linux-2.6
Archived
13
0
Fork 0

crypto: Use scatterwalk_crypto_chain

Use scatterwalk_crypto_chain in favor of locally defined chaining functions.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Steffen Klassert 2010-11-22 11:26:54 +01:00 committed by Herbert Xu
parent 079f2f7485
commit c920fa6051
3 changed files with 8 additions and 51 deletions

View File

@ -107,20 +107,6 @@ badkey:
goto out; goto out;
} }
static void authenc_chain(struct scatterlist *head, struct scatterlist *sg,
int chain)
{
if (chain) {
head->length += sg->length;
sg = scatterwalk_sg_next(sg);
}
if (sg)
scatterwalk_sg_chain(head, 2, sg);
else
sg_mark_end(head);
}
static void authenc_geniv_ahash_update_done(struct crypto_async_request *areq, static void authenc_geniv_ahash_update_done(struct crypto_async_request *areq,
int err) int err)
{ {
@ -345,7 +331,7 @@ static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
if (ivsize) { if (ivsize) {
sg_init_table(cipher, 2); sg_init_table(cipher, 2);
sg_set_buf(cipher, iv, ivsize); sg_set_buf(cipher, iv, ivsize);
authenc_chain(cipher, dst, vdst == iv + ivsize); scatterwalk_crypto_chain(cipher, dst, vdst == iv + ivsize, 2);
dst = cipher; dst = cipher;
cryptlen += ivsize; cryptlen += ivsize;
} }
@ -354,7 +340,7 @@ static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
authenc_ahash_fn = crypto_authenc_ahash; authenc_ahash_fn = crypto_authenc_ahash;
sg_init_table(asg, 2); sg_init_table(asg, 2);
sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset); sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset);
authenc_chain(asg, dst, 0); scatterwalk_crypto_chain(asg, dst, 0, 2);
dst = asg; dst = asg;
cryptlen += req->assoclen; cryptlen += req->assoclen;
} }
@ -499,7 +485,7 @@ static int crypto_authenc_iverify(struct aead_request *req, u8 *iv,
if (ivsize) { if (ivsize) {
sg_init_table(cipher, 2); sg_init_table(cipher, 2);
sg_set_buf(cipher, iv, ivsize); sg_set_buf(cipher, iv, ivsize);
authenc_chain(cipher, src, vsrc == iv + ivsize); scatterwalk_crypto_chain(cipher, src, vsrc == iv + ivsize, 2);
src = cipher; src = cipher;
cryptlen += ivsize; cryptlen += ivsize;
} }
@ -508,7 +494,7 @@ static int crypto_authenc_iverify(struct aead_request *req, u8 *iv,
authenc_ahash_fn = crypto_authenc_ahash; authenc_ahash_fn = crypto_authenc_ahash;
sg_init_table(asg, 2); sg_init_table(asg, 2);
sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset); sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset);
authenc_chain(asg, src, 0); scatterwalk_crypto_chain(asg, src, 0, 2);
src = asg; src = asg;
cryptlen += req->assoclen; cryptlen += req->assoclen;
} }

View File

@ -62,20 +62,6 @@ out:
skcipher_givcrypt_complete(req, err); skcipher_givcrypt_complete(req, err);
} }
static void eseqiv_chain(struct scatterlist *head, struct scatterlist *sg,
int chain)
{
if (chain) {
head->length += sg->length;
sg = scatterwalk_sg_next(sg);
}
if (sg)
scatterwalk_sg_chain(head, 2, sg);
else
sg_mark_end(head);
}
static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req) static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
{ {
struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req); struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
@ -124,13 +110,13 @@ static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
sg_init_table(reqctx->src, 2); sg_init_table(reqctx->src, 2);
sg_set_buf(reqctx->src, giv, ivsize); sg_set_buf(reqctx->src, giv, ivsize);
eseqiv_chain(reqctx->src, osrc, vsrc == giv + ivsize); scatterwalk_crypto_chain(reqctx->src, osrc, vsrc == giv + ivsize, 2);
dst = reqctx->src; dst = reqctx->src;
if (osrc != odst) { if (osrc != odst) {
sg_init_table(reqctx->dst, 2); sg_init_table(reqctx->dst, 2);
sg_set_buf(reqctx->dst, giv, ivsize); sg_set_buf(reqctx->dst, giv, ivsize);
eseqiv_chain(reqctx->dst, odst, vdst == giv + ivsize); scatterwalk_crypto_chain(reqctx->dst, odst, vdst == giv + ivsize, 2);
dst = reqctx->dst; dst = reqctx->dst;
} }

View File

@ -1102,21 +1102,6 @@ static int crypto_rfc4543_setauthsize(struct crypto_aead *parent,
return crypto_aead_setauthsize(ctx->child, authsize); return crypto_aead_setauthsize(ctx->child, authsize);
} }
/* this is the same as crypto_authenc_chain */
static void crypto_rfc4543_chain(struct scatterlist *head,
struct scatterlist *sg, int chain)
{
if (chain) {
head->length += sg->length;
sg = scatterwalk_sg_next(sg);
}
if (sg)
scatterwalk_sg_chain(head, 2, sg);
else
sg_mark_end(head);
}
static struct aead_request *crypto_rfc4543_crypt(struct aead_request *req, static struct aead_request *crypto_rfc4543_crypt(struct aead_request *req,
int enc) int enc)
{ {
@ -1154,13 +1139,13 @@ static struct aead_request *crypto_rfc4543_crypt(struct aead_request *req,
sg_init_table(payload, 2); sg_init_table(payload, 2);
sg_set_buf(payload, req->iv, 8); sg_set_buf(payload, req->iv, 8);
crypto_rfc4543_chain(payload, dst, vdst == req->iv + 8); scatterwalk_crypto_chain(payload, dst, vdst == req->iv + 8, 2);
assoclen += 8 + req->cryptlen - (enc ? 0 : authsize); assoclen += 8 + req->cryptlen - (enc ? 0 : authsize);
sg_init_table(assoc, 2); sg_init_table(assoc, 2);
sg_set_page(assoc, sg_page(req->assoc), req->assoc->length, sg_set_page(assoc, sg_page(req->assoc), req->assoc->length,
req->assoc->offset); req->assoc->offset);
crypto_rfc4543_chain(assoc, payload, 0); scatterwalk_crypto_chain(assoc, payload, 0, 2);
aead_request_set_tfm(subreq, ctx->child); aead_request_set_tfm(subreq, ctx->child);
aead_request_set_callback(subreq, req->base.flags, req->base.complete, aead_request_set_callback(subreq, req->base.flags, req->base.complete,