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

TOMOYO Linux Cross Reference
Linux/arch/x86/crypto/ecb_cbc_helpers.h

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 */
  2 
  3 #ifndef _CRYPTO_ECB_CBC_HELPER_H
  4 #define _CRYPTO_ECB_CBC_HELPER_H
  5 
  6 #include <crypto/internal/skcipher.h>
  7 #include <asm/fpu/api.h>
  8 
  9 /*
 10  * Mode helpers to instantiate parameterized skcipher ECB/CBC modes without
 11  * having to rely on indirect calls and retpolines.
 12  */
 13 
 14 #define ECB_WALK_START(req, bsize, fpu_blocks) do {                     \
 15         void *ctx = crypto_skcipher_ctx(crypto_skcipher_reqtfm(req));   \
 16         const int __fpu_blocks = (fpu_blocks);                          \
 17         const int __bsize = (bsize);                                    \
 18         struct skcipher_walk walk;                                      \
 19         int err = skcipher_walk_virt(&walk, (req), false);              \
 20         while (walk.nbytes > 0) {                                       \
 21                 unsigned int nbytes = walk.nbytes;                      \
 22                 bool do_fpu = __fpu_blocks != -1 &&                     \
 23                               nbytes >= __fpu_blocks * __bsize;         \
 24                 const u8 *src = walk.src.virt.addr;                     \
 25                 u8 *dst = walk.dst.virt.addr;                           \
 26                 u8 __maybe_unused buf[(bsize)];                         \
 27                 if (do_fpu) kernel_fpu_begin()
 28 
 29 #define CBC_WALK_START(req, bsize, fpu_blocks)                          \
 30         ECB_WALK_START(req, bsize, fpu_blocks)
 31 
 32 #define ECB_WALK_ADVANCE(blocks) do {                                   \
 33         dst += (blocks) * __bsize;                                      \
 34         src += (blocks) * __bsize;                                      \
 35         nbytes -= (blocks) * __bsize;                                   \
 36 } while (0)
 37 
 38 #define ECB_BLOCK(blocks, func) do {                                    \
 39         const int __blocks = (blocks);                                  \
 40         if (do_fpu && __blocks < __fpu_blocks) {                        \
 41                 kernel_fpu_end();                                       \
 42                 do_fpu = false;                                         \
 43         }                                                               \
 44         while (nbytes >= __blocks * __bsize) {                          \
 45                 (func)(ctx, dst, src);                                  \
 46                 ECB_WALK_ADVANCE(blocks);                               \
 47         }                                                               \
 48 } while (0)
 49 
 50 #define CBC_ENC_BLOCK(func) do {                                        \
 51         const u8 *__iv = walk.iv;                                       \
 52         while (nbytes >= __bsize) {                                     \
 53                 crypto_xor_cpy(dst, src, __iv, __bsize);                \
 54                 (func)(ctx, dst, dst);                                  \
 55                 __iv = dst;                                             \
 56                 ECB_WALK_ADVANCE(1);                                    \
 57         }                                                               \
 58         memcpy(walk.iv, __iv, __bsize);                                 \
 59 } while (0)
 60 
 61 #define CBC_DEC_BLOCK(blocks, func) do {                                \
 62         const int __blocks = (blocks);                                  \
 63         if (do_fpu && __blocks <  __fpu_blocks) {                       \
 64                 kernel_fpu_end();                                       \
 65                 do_fpu = false;                                         \
 66         }                                                               \
 67         while (nbytes >= __blocks * __bsize) {                          \
 68                 const u8 *__iv = src + ((blocks) - 1) * __bsize;        \
 69                 if (dst == src)                                         \
 70                         __iv = memcpy(buf, __iv, __bsize);              \
 71                 (func)(ctx, dst, src);                                  \
 72                 crypto_xor(dst, walk.iv, __bsize);                      \
 73                 memcpy(walk.iv, __iv, __bsize);                         \
 74                 ECB_WALK_ADVANCE(blocks);                               \
 75         }                                                               \
 76 } while (0)
 77 
 78 #define ECB_WALK_END()                                                  \
 79                 if (do_fpu) kernel_fpu_end();                           \
 80                 err = skcipher_walk_done(&walk, nbytes);                \
 81         }                                                               \
 82         return err;                                                     \
 83 } while (0)
 84 
 85 #define CBC_WALK_END() ECB_WALK_END()
 86 
 87 #endif
 88 

~ [ 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