Skip to content

Commit

Permalink
[CRYPTO] scatterwalk: Add scatterwalk_map_and_copy
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
herbertx authored and David S. Miller committed Oct 10, 2007
1 parent e962a65 commit 5fa0fea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions crypto/scatterwalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
3 changes: 3 additions & 0 deletions crypto/scatterwalk.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ void scatterwalk_copychunks(void *buf, struct scatter_walk *walk,
void *scatterwalk_map(struct scatter_walk *walk, int out);
void scatterwalk_done(struct scatter_walk *walk, int out, int more);

void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
unsigned int start, unsigned int nbytes, int out);

#endif /* _CRYPTO_SCATTERWALK_H */

0 comments on commit 5fa0fea

Please sign in to comment.