crypto: scatterwalk - Add scatterwalk_ffwd helper
authorHerbert Xu <herbert@gondor.apana.org.au>
Thu, 21 May 2015 07:10:59 +0000 (15:10 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 22 May 2015 03:25:50 +0000 (11:25 +0800)
This patch adds the scatterwalk_ffwd helper which can create an
SG list that starts in the middle of an existing SG list.  The
new list may either be part of the existing list or be a chain
that latches onto part of the existing list.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/scatterwalk.c
include/crypto/scatterwalk.h

index 3bd749c7bb7062d33ee694e4131d13ce7c051c31..db920b59a6c3332fdb771a5bcc0b0c338fce3d95 100644 (file)
@@ -146,3 +146,25 @@ int scatterwalk_bytes_sglen(struct scatterlist *sg, int num_bytes)
        return n;
 }
 EXPORT_SYMBOL_GPL(scatterwalk_bytes_sglen);
+
+struct scatterlist *scatterwalk_ffwd(struct scatterlist dst[2],
+                                    struct scatterlist *src,
+                                    unsigned int len)
+{
+       for (;;) {
+               if (!len)
+                       return src;
+
+               if (src->length > len)
+                       break;
+
+               len -= src->length;
+               src = sg_next(src);
+       }
+
+       sg_set_page(dst, sg_page(src), src->length - len, src->offset + len);
+       scatterwalk_crypto_chain(dst, sg_next(src), 0, 2);
+
+       return dst;
+}
+EXPORT_SYMBOL_GPL(scatterwalk_ffwd);
index 20e4226a2e14e68e3a5e6fc6541993ff228919d7..96670e7e7c145f741b104afccae780b95b22a41d 100644 (file)
@@ -102,4 +102,8 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
 
 int scatterwalk_bytes_sglen(struct scatterlist *sg, int num_bytes);
 
+struct scatterlist *scatterwalk_ffwd(struct scatterlist dst[2],
+                                    struct scatterlist *src,
+                                    unsigned int len);
+
 #endif  /* _CRYPTO_SCATTERWALK_H */