crypto: scatterwalk - Add scatterwalk_crypto_chain helper
authorSteffen Klassert <steffen.klassert@secunet.com>
Mon, 22 Nov 2010 10:25:50 +0000 (11:25 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 2 Dec 2010 06:47:15 +0000 (14:47 +0800)
A lot of crypto algorithms implement their own chaining function.
So add a generic one that can be used from all the algorithms that
need scatterlist chaining.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
include/crypto/scatterwalk.h

index 833d208c25d64194525e8b1ff09d8ddaf261251d..4fd95a323beb295ddf9efbe1dfb8a63db15c3a09 100644 (file)
@@ -68,6 +68,21 @@ static inline struct scatterlist *scatterwalk_sg_next(struct scatterlist *sg)
        return (++sg)->length ? sg : (void *)sg_page(sg);
 }
 
+static inline void scatterwalk_crypto_chain(struct scatterlist *head,
+                                           struct scatterlist *sg,
+                                           int chain, int num)
+{
+       if (chain) {
+               head->length += sg->length;
+               sg = scatterwalk_sg_next(sg);
+       }
+
+       if (sg)
+               scatterwalk_sg_chain(head, num, sg);
+       else
+               sg_mark_end(head);
+}
+
 static inline unsigned long scatterwalk_samebuf(struct scatter_walk *walk_in,
                                                struct scatter_walk *walk_out)
 {