aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-08-29 04:31:34 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:55:42 -0400
commit5fa0fea27461f5ff7fad07687618db08272e9502 (patch)
tree4e1fe825e9e45e0d4dab028b8188fe1ceff1f768
parente962a653f3146330d99aefa5adadeaed60bc9bb5 (diff)
[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>
-rw-r--r--crypto/scatterwalk.c22
-rw-r--r--crypto/scatterwalk.h3
2 files changed, 25 insertions, 0 deletions
diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c
index 81afd1790a1..e93a8f6f35d 100644
--- a/crypto/scatterwalk.c
+++ b/crypto/scatterwalk.c
@@ -107,3 +107,25 @@ void scatterwalk_copychunks(void *buf, struct scatter_walk *walk,
107 } 107 }
108} 108}
109EXPORT_SYMBOL_GPL(scatterwalk_copychunks); 109EXPORT_SYMBOL_GPL(scatterwalk_copychunks);
110
111void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
112 unsigned int start, unsigned int nbytes, int out)
113{
114 struct scatter_walk walk;
115 unsigned int offset = 0;
116
117 for (;;) {
118 scatterwalk_start(&walk, sg);
119
120 if (start < offset + sg->length)
121 break;
122
123 offset += sg->length;
124 sg = sg_next(sg);
125 }
126
127 scatterwalk_advance(&walk, start - offset);
128 scatterwalk_copychunks(buf, &walk, nbytes, out);
129 scatterwalk_done(&walk, out, 0);
130}
131EXPORT_SYMBOL_GPL(scatterwalk_map_and_copy);
diff --git a/crypto/scatterwalk.h b/crypto/scatterwalk.h
index f1592cc2d0f..500a220ad90 100644
--- a/crypto/scatterwalk.h
+++ b/crypto/scatterwalk.h
@@ -74,4 +74,7 @@ void scatterwalk_copychunks(void *buf, struct scatter_walk *walk,
74void *scatterwalk_map(struct scatter_walk *walk, int out); 74void *scatterwalk_map(struct scatter_walk *walk, int out);
75void scatterwalk_done(struct scatter_walk *walk, int out, int more); 75void scatterwalk_done(struct scatter_walk *walk, int out, int more);
76 76
77void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
78 unsigned int start, unsigned int nbytes, int out);
79
77#endif /* _CRYPTO_SCATTERWALK_H */ 80#endif /* _CRYPTO_SCATTERWALK_H */