~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/crypto/scatterwalk.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Cryptographic API.
  4  *
  5  * Cipher operations.
  6  *
  7  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  8  *               2002 Adam J. Richter <adam@yggdrasil.com>
  9  *               2004 Jean-Luc Cooke <jlcooke@certainkey.com>
 10  */
 11 
 12 #include <crypto/scatterwalk.h>
 13 #include <linux/kernel.h>
 14 #include <linux/mm.h>
 15 #include <linux/module.h>
 16 #include <linux/scatterlist.h>
 17 
 18 static inline void memcpy_dir(void *buf, void *sgdata, size_t nbytes, int out)
 19 {
 20         void *src = out ? buf : sgdata;
 21         void *dst = out ? sgdata : buf;
 22 
 23         memcpy(dst, src, nbytes);
 24 }
 25 
 26 void scatterwalk_copychunks(void *buf, struct scatter_walk *walk,
 27                             size_t nbytes, int out)
 28 {
 29         for (;;) {
 30                 unsigned int len_this_page = scatterwalk_pagelen(walk);
 31                 u8 *vaddr;
 32 
 33                 if (len_this_page > nbytes)
 34                         len_this_page = nbytes;
 35 
 36                 if (out != 2) {
 37                         vaddr = scatterwalk_map(walk);
 38                         memcpy_dir(buf, vaddr, len_this_page, out);
 39                         scatterwalk_unmap(vaddr);
 40                 }
 41 
 42                 scatterwalk_advance(walk, len_this_page);
 43 
 44                 if (nbytes == len_this_page)
 45                         break;
 46 
 47                 buf += len_this_page;
 48                 nbytes -= len_this_page;
 49 
 50                 scatterwalk_pagedone(walk, out & 1, 1);
 51         }
 52 }
 53 EXPORT_SYMBOL_GPL(scatterwalk_copychunks);
 54 
 55 void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
 56                               unsigned int start, unsigned int nbytes, int out)
 57 {
 58         struct scatter_walk walk;
 59         struct scatterlist tmp[2];
 60 
 61         if (!nbytes)
 62                 return;
 63 
 64         sg = scatterwalk_ffwd(tmp, sg, start);
 65 
 66         scatterwalk_start(&walk, sg);
 67         scatterwalk_copychunks(buf, &walk, nbytes, out);
 68         scatterwalk_done(&walk, out, 0);
 69 }
 70 EXPORT_SYMBOL_GPL(scatterwalk_map_and_copy);
 71 
 72 struct scatterlist *scatterwalk_ffwd(struct scatterlist dst[2],
 73                                      struct scatterlist *src,
 74                                      unsigned int len)
 75 {
 76         for (;;) {
 77                 if (!len)
 78                         return src;
 79 
 80                 if (src->length > len)
 81                         break;
 82 
 83                 len -= src->length;
 84                 src = sg_next(src);
 85         }
 86 
 87         sg_init_table(dst, 2);
 88         sg_set_page(dst, sg_page(src), src->length - len, src->offset + len);
 89         scatterwalk_crypto_chain(dst, sg_next(src), 2);
 90 
 91         return dst;
 92 }
 93 EXPORT_SYMBOL_GPL(scatterwalk_ffwd);
 94 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php