Commit 5fa0fea27461f5ff7fad07687618db08272e9502
Committed by
David S. Miller
1 parent
e962a653f3
Exists in
master
and in
4 other branches
[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>
Showing 2 changed files with 25 additions and 0 deletions Side-by-side Diff
crypto/scatterwalk.c
... | ... | @@ -107,4 +107,26 @@ |
107 | 107 | } |
108 | 108 | } |
109 | 109 | EXPORT_SYMBOL_GPL(scatterwalk_copychunks); |
110 | + | |
111 | +void 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 | +} | |
131 | +EXPORT_SYMBOL_GPL(scatterwalk_map_and_copy); |
crypto/scatterwalk.h
... | ... | @@ -74,5 +74,8 @@ |
74 | 74 | void *scatterwalk_map(struct scatter_walk *walk, int out); |
75 | 75 | void scatterwalk_done(struct scatter_walk *walk, int out, int more); |
76 | 76 | |
77 | +void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, | |
78 | + unsigned int start, unsigned int nbytes, int out); | |
79 | + | |
77 | 80 | #endif /* _CRYPTO_SCATTERWALK_H */ |