Skip to content
This repository
Browse code

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>
  • Loading branch information...
commit c920fa6051c1e7eb3733eaefd01e5bcdddb3d4c8 1 parent 079f2f7
authored November 22, 2010 herbertx committed December 02, 2010
22  crypto/authenc.c
@@ -107,20 +107,6 @@ static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
107 107
 	goto out;
108 108
 }
109 109
 
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  
-
124 110
 static void authenc_geniv_ahash_update_done(struct crypto_async_request *areq,
125 111
 					    int err)
126 112
 {
@@ -345,7 +331,7 @@ static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
345 331
 	if (ivsize) {
346 332
 		sg_init_table(cipher, 2);
347 333
 		sg_set_buf(cipher, iv, ivsize);
348  
-		authenc_chain(cipher, dst, vdst == iv + ivsize);
  334
+		scatterwalk_crypto_chain(cipher, dst, vdst == iv + ivsize, 2);
349 335
 		dst = cipher;
350 336
 		cryptlen += ivsize;
351 337
 	}
@@ -354,7 +340,7 @@ static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
354 340
 		authenc_ahash_fn = crypto_authenc_ahash;
355 341
 		sg_init_table(asg, 2);
356 342
 		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);
358 344
 		dst = asg;
359 345
 		cryptlen += req->assoclen;
360 346
 	}
@@ -499,7 +485,7 @@ static int crypto_authenc_iverify(struct aead_request *req, u8 *iv,
499 485
 	if (ivsize) {
500 486
 		sg_init_table(cipher, 2);
501 487
 		sg_set_buf(cipher, iv, ivsize);
502  
-		authenc_chain(cipher, src, vsrc == iv + ivsize);
  488
+		scatterwalk_crypto_chain(cipher, src, vsrc == iv + ivsize, 2);
503 489
 		src = cipher;
504 490
 		cryptlen += ivsize;
505 491
 	}
@@ -508,7 +494,7 @@ static int crypto_authenc_iverify(struct aead_request *req, u8 *iv,
508 494
 		authenc_ahash_fn = crypto_authenc_ahash;
509 495
 		sg_init_table(asg, 2);
510 496
 		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);
512 498
 		src = asg;
513 499
 		cryptlen += req->assoclen;
514 500
 	}
18  crypto/eseqiv.c
@@ -62,20 +62,6 @@ static void eseqiv_complete(struct crypto_async_request *base, int err)
62 62
 	skcipher_givcrypt_complete(req, err);
63 63
 }
64 64
 
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  
-
79 65
 static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
80 66
 {
81 67
 	struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
@@ -124,13 +110,13 @@ static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
124 110
 
125 111
 	sg_init_table(reqctx->src, 2);
126 112
 	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);
128 114
 
129 115
 	dst = reqctx->src;
130 116
 	if (osrc != odst) {
131 117
 		sg_init_table(reqctx->dst, 2);
132 118
 		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);
134 120
 
135 121
 		dst = reqctx->dst;
136 122
 	}
19  crypto/gcm.c
@@ -1102,21 +1102,6 @@ static int crypto_rfc4543_setauthsize(struct crypto_aead *parent,
1102 1102
 	return crypto_aead_setauthsize(ctx->child, authsize);
1103 1103
 }
1104 1104
 
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  
-
1120 1105
 static struct aead_request *crypto_rfc4543_crypt(struct aead_request *req,
1121 1106
 						 int enc)
1122 1107
 {
@@ -1154,13 +1139,13 @@ static struct aead_request *crypto_rfc4543_crypt(struct aead_request *req,
1154 1139
 
1155 1140
 	sg_init_table(payload, 2);
1156 1141
 	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);
1158 1143
 	assoclen += 8 + req->cryptlen - (enc ? 0 : authsize);
1159 1144
 
1160 1145
 	sg_init_table(assoc, 2);
1161 1146
 	sg_set_page(assoc, sg_page(req->assoc), req->assoc->length,
1162 1147
 		    req->assoc->offset);
1163  
-	crypto_rfc4543_chain(assoc, payload, 0);
  1148
+	scatterwalk_crypto_chain(assoc, payload, 0, 2);
1164 1149
 
1165 1150
 	aead_request_set_tfm(subreq, ctx->child);
1166 1151
 	aead_request_set_callback(subreq, req->base.flags, req->base.complete,

0 notes on commit c920fa6

Please sign in to comment.
Something went wrong with that request. Please try again.