[CRYPTO] scatterwalk: Add scatterwalk_map_and_copy
authorHerbert Xu <herbert@gondor.apana.org.au>
Wed, 29 Aug 2007 08:31:34 +0000 (16:31 +0800)
committerDavid S. Miller <davem@sunset.davemloft.net>
Wed, 10 Oct 2007 23:55:42 +0000 (16:55 -0700)
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>
crypto/scatterwalk.c
crypto/scatterwalk.h

index 81afd1790a1d1c28fc8a7e2569940401a668d5ac..e93a8f6f35d48b32f76815c0a9b6676ccbd65775 100644 (file)
@@ -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);
index f1592cc2d0f42bb76132667fe69cf3f5e61bb8cb..500a220ad908cbad83bc8f1a285a03c169d71961 100644 (file)
@@ -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 */