Skip to content

Commit c920fa6

Browse files
klassertherbertx
authored andcommitted
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>
1 parent 079f2f7 commit c920fa6

3 files changed

Lines changed: 8 additions & 51 deletions

File tree

‎crypto/authenc.c‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,6 @@ static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
107107
goto out;
108108
}
109109

110-
static void authenc_chain(struct scatterlist *head, struct scatterlist *sg,
111-
int chain)
112-
{
113-
if (chain) {
114-
head->length += sg->length;
115-
sg = scatterwalk_sg_next(sg);
116-
}
117-
118-
if (sg)
119-
scatterwalk_sg_chain(head, 2, sg);
120-
else
121-
sg_mark_end(head);
122-
}
123-
124110
static void authenc_geniv_ahash_update_done(struct crypto_async_request *areq,
125111
int err)
126112
{
@@ -345,7 +331,7 @@ static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
345331
if (ivsize) {
346332
sg_init_table(cipher, 2);
347333
sg_set_buf(cipher, iv, ivsize);
348-
authenc_chain(cipher, dst, vdst == iv + ivsize);
334+
scatterwalk_crypto_chain(cipher, dst, vdst == iv + ivsize, 2);
349335
dst = cipher;
350336
cryptlen += ivsize;
351337
}
@@ -354,7 +340,7 @@ static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
354340
authenc_ahash_fn = crypto_authenc_ahash;
355341
sg_init_table(asg, 2);
356342
sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset);
357-
authenc_chain(asg, dst, 0);
343+
scatterwalk_crypto_chain(asg, dst, 0, 2);
358344
dst = asg;
359345
cryptlen += req->assoclen;
360346
}
@@ -499,7 +485,7 @@ static int crypto_authenc_iverify(struct aead_request *req, u8 *iv,
499485
if (ivsize) {
500486
sg_init_table(cipher, 2);
501487
sg_set_buf(cipher, iv, ivsize);
502-
authenc_chain(cipher, src, vsrc == iv + ivsize);
488+
scatterwalk_crypto_chain(cipher, src, vsrc == iv + ivsize, 2);
503489
src = cipher;
504490
cryptlen += ivsize;
505491
}
@@ -508,7 +494,7 @@ static int crypto_authenc_iverify(struct aead_request *req, u8 *iv,
508494
authenc_ahash_fn = crypto_authenc_ahash;
509495
sg_init_table(asg, 2);
510496
sg_set_page(asg, sg_page(assoc), assoc->length, assoc->offset);
511-
authenc_chain(asg, src, 0);
497+
scatterwalk_crypto_chain(asg, src, 0, 2);
512498
src = asg;
513499
cryptlen += req->assoclen;
514500
}

‎crypto/eseqiv.c‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,6 @@ static void eseqiv_complete(struct crypto_async_request *base, int err)
6262
skcipher_givcrypt_complete(req, err);
6363
}
6464

65-
static void eseqiv_chain(struct scatterlist *head, struct scatterlist *sg,
66-
int chain)
67-
{
68-
if (chain) {
69-
head->length += sg->length;
70-
sg = scatterwalk_sg_next(sg);
71-
}
72-
73-
if (sg)
74-
scatterwalk_sg_chain(head, 2, sg);
75-
else
76-
sg_mark_end(head);
77-
}
78-
7965
static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
8066
{
8167
struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
@@ -124,13 +110,13 @@ static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
124110

125111
sg_init_table(reqctx->src, 2);
126112
sg_set_buf(reqctx->src, giv, ivsize);
127-
eseqiv_chain(reqctx->src, osrc, vsrc == giv + ivsize);
113+
scatterwalk_crypto_chain(reqctx->src, osrc, vsrc == giv + ivsize, 2);
128114

129115
dst = reqctx->src;
130116
if (osrc != odst) {
131117
sg_init_table(reqctx->dst, 2);
132118
sg_set_buf(reqctx->dst, giv, ivsize);
133-
eseqiv_chain(reqctx->dst, odst, vdst == giv + ivsize);
119+
scatterwalk_crypto_chain(reqctx->dst, odst, vdst == giv + ivsize, 2);
134120

135121
dst = reqctx->dst;
136122
}

‎crypto/gcm.c‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,21 +1102,6 @@ static int crypto_rfc4543_setauthsize(struct crypto_aead *parent,
11021102
return crypto_aead_setauthsize(ctx->child, authsize);
11031103
}
11041104

1105-
/* this is the same as crypto_authenc_chain */
1106-
static void crypto_rfc4543_chain(struct scatterlist *head,
1107-
struct scatterlist *sg, int chain)
1108-
{
1109-
if (chain) {
1110-
head->length += sg->length;
1111-
sg = scatterwalk_sg_next(sg);
1112-
}
1113-
1114-
if (sg)
1115-
scatterwalk_sg_chain(head, 2, sg);
1116-
else
1117-
sg_mark_end(head);
1118-
}
1119-
11201105
static struct aead_request *crypto_rfc4543_crypt(struct aead_request *req,
11211106
int enc)
11221107
{
@@ -1154,13 +1139,13 @@ static struct aead_request *crypto_rfc4543_crypt(struct aead_request *req,
11541139

11551140
sg_init_table(payload, 2);
11561141
sg_set_buf(payload, req->iv, 8);
1157-
crypto_rfc4543_chain(payload, dst, vdst == req->iv + 8);
1142+
scatterwalk_crypto_chain(payload, dst, vdst == req->iv + 8, 2);
11581143
assoclen += 8 + req->cryptlen - (enc ? 0 : authsize);
11591144

11601145
sg_init_table(assoc, 2);
11611146
sg_set_page(assoc, sg_page(req->assoc), req->assoc->length,
11621147
req->assoc->offset);
1163-
crypto_rfc4543_chain(assoc, payload, 0);
1148+
scatterwalk_crypto_chain(assoc, payload, 0, 2);
11641149

11651150
aead_request_set_tfm(subreq, ctx->child);
11661151
aead_request_set_callback(subreq, req->base.flags, req->base.complete,

0 commit comments

Comments
 (0)