]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - lib/iov_iter.c
iov_iter: introduce hash_and_copy_to_iter helper
[linux.git] / lib / iov_iter.c
index 63a8999a234dd4a0a5974458cf12ad3135524248..1928009f506e8e4531cea681257da6df4b8a8024 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/vmalloc.h>
 #include <linux/splice.h>
 #include <net/checksum.h>
+#include <linux/scatterlist.h>
 
 #define PIPE_PARANOIA /* for now */
 
@@ -1511,6 +1512,21 @@ size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *csump,
 }
 EXPORT_SYMBOL(csum_and_copy_to_iter);
 
+size_t hash_and_copy_to_iter(const void *addr, size_t bytes, void *hashp,
+               struct iov_iter *i)
+{
+       struct ahash_request *hash = hashp;
+       struct scatterlist sg;
+       size_t copied;
+
+       copied = copy_to_iter(addr, bytes, i);
+       sg_init_one(&sg, addr, copied);
+       ahash_request_set_crypt(hash, &sg, NULL, copied);
+       crypto_ahash_update(hash);
+       return copied;
+}
+EXPORT_SYMBOL(hash_and_copy_to_iter);
+
 int iov_iter_npages(const struct iov_iter *i, int maxpages)
 {
        size_t size = i->count;