summaryrefslogtreecommitdiffstats
path: root/crypto/scatterwalk.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-08-29 10:31:34 +0200
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-11 01:55:42 +0200
commit5fa0fea27461f5ff7fad07687618db08272e9502 (patch)
tree4e1fe825e9e45e0d4dab028b8188fe1ceff1f768 /crypto/scatterwalk.c
parent[CRYPTO] api: Move scatterwalk into algapi (diff)
downloadlinux-5fa0fea27461f5ff7fad07687618db08272e9502.tar.xz
linux-5fa0fea27461f5ff7fad07687618db08272e9502.zip
[CRYPTO] scatterwalk: Add scatterwalk_map_and_copy
This patch adds the function scatterwalk_map_and_copy which reads or writes a chunk of data from a scatterlist at a given offset. It will be used by authenc which would read/write the authentication data at the end of the cipher/plain text. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/scatterwalk.c')
-rw-r--r--crypto/scatterwalk.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c
index 81afd1790a1d..e93a8f6f35d4 100644
--- a/crypto/scatterwalk.c
+++ b/crypto/scatterwalk.c
@@ -107,3 +107,25 @@ void scatterwalk_copychunks(void *buf, struct scatter_walk *walk,
}
}
EXPORT_SYMBOL_GPL(scatterwalk_copychunks);
+
+void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
+ unsigned int start, unsigned int nbytes, int out)
+{
+ struct scatter_walk walk;
+ unsigned int offset = 0;
+
+ for (;;) {
+ scatterwalk_start(&walk, sg);
+
+ if (start < offset + sg->length)
+ break;
+
+ offset += sg->length;
+ sg = sg_next(sg);
+ }
+
+ scatterwalk_advance(&walk, start - offset);
+ scatterwalk_copychunks(buf, &walk, nbytes, out);
+ scatterwalk_done(&walk, out, 0);
+}
+EXPORT_SYMBOL_GPL(scatterwalk_map_and_copy);