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

TOMOYO Linux Cross Reference
Linux/arch/x86/include/asm/crypto/glue_helper.h

Version: ~ [ linux-5.5-rc1 ] ~ [ linux-5.4.2 ] ~ [ linux-5.3.15 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.88 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.158 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.206 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.206 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.78 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Shared glue code for 128bit block ciphers
  3  */
  4 
  5 #ifndef _CRYPTO_GLUE_HELPER_H
  6 #define _CRYPTO_GLUE_HELPER_H
  7 
  8 #include <linux/kernel.h>
  9 #include <linux/crypto.h>
 10 #include <asm/fpu/api.h>
 11 #include <crypto/b128ops.h>
 12 
 13 typedef void (*common_glue_func_t)(void *ctx, u8 *dst, const u8 *src);
 14 typedef void (*common_glue_cbc_func_t)(void *ctx, u128 *dst, const u128 *src);
 15 typedef void (*common_glue_ctr_func_t)(void *ctx, u128 *dst, const u128 *src,
 16                                        le128 *iv);
 17 typedef void (*common_glue_xts_func_t)(void *ctx, u128 *dst, const u128 *src,
 18                                        le128 *iv);
 19 
 20 #define GLUE_FUNC_CAST(fn) ((common_glue_func_t)(fn))
 21 #define GLUE_CBC_FUNC_CAST(fn) ((common_glue_cbc_func_t)(fn))
 22 #define GLUE_CTR_FUNC_CAST(fn) ((common_glue_ctr_func_t)(fn))
 23 #define GLUE_XTS_FUNC_CAST(fn) ((common_glue_xts_func_t)(fn))
 24 
 25 struct common_glue_func_entry {
 26         unsigned int num_blocks; /* number of blocks that @fn will process */
 27         union {
 28                 common_glue_func_t ecb;
 29                 common_glue_cbc_func_t cbc;
 30                 common_glue_ctr_func_t ctr;
 31                 common_glue_xts_func_t xts;
 32         } fn_u;
 33 };
 34 
 35 struct common_glue_ctx {
 36         unsigned int num_funcs;
 37         int fpu_blocks_limit; /* -1 means fpu not needed at all */
 38 
 39         /*
 40          * First funcs entry must have largest num_blocks and last funcs entry
 41          * must have num_blocks == 1!
 42          */
 43         struct common_glue_func_entry funcs[];
 44 };
 45 
 46 static inline bool glue_fpu_begin(unsigned int bsize, int fpu_blocks_limit,
 47                                   struct blkcipher_desc *desc,
 48                                   bool fpu_enabled, unsigned int nbytes)
 49 {
 50         if (likely(fpu_blocks_limit < 0))
 51                 return false;
 52 
 53         if (fpu_enabled)
 54                 return true;
 55 
 56         /*
 57          * Vector-registers are only used when chunk to be processed is large
 58          * enough, so do not enable FPU until it is necessary.
 59          */
 60         if (nbytes < bsize * (unsigned int)fpu_blocks_limit)
 61                 return false;
 62 
 63         if (desc) {
 64                 /* prevent sleeping if FPU is in use */
 65                 desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
 66         }
 67 
 68         kernel_fpu_begin();
 69         return true;
 70 }
 71 
 72 static inline void glue_fpu_end(bool fpu_enabled)
 73 {
 74         if (fpu_enabled)
 75                 kernel_fpu_end();
 76 }
 77 
 78 static inline void le128_to_be128(be128 *dst, const le128 *src)
 79 {
 80         dst->a = cpu_to_be64(le64_to_cpu(src->a));
 81         dst->b = cpu_to_be64(le64_to_cpu(src->b));
 82 }
 83 
 84 static inline void be128_to_le128(le128 *dst, const be128 *src)
 85 {
 86         dst->a = cpu_to_le64(be64_to_cpu(src->a));
 87         dst->b = cpu_to_le64(be64_to_cpu(src->b));
 88 }
 89 
 90 static inline void le128_inc(le128 *i)
 91 {
 92         u64 a = le64_to_cpu(i->a);
 93         u64 b = le64_to_cpu(i->b);
 94 
 95         b++;
 96         if (!b)
 97                 a++;
 98 
 99         i->a = cpu_to_le64(a);
100         i->b = cpu_to_le64(b);
101 }
102 
103 static inline void le128_gf128mul_x_ble(le128 *dst, const le128 *src)
104 {
105         u64 a = le64_to_cpu(src->a);
106         u64 b = le64_to_cpu(src->b);
107         u64 _tt = ((s64)a >> 63) & 0x87;
108 
109         dst->a = cpu_to_le64((a << 1) ^ (b >> 63));
110         dst->b = cpu_to_le64((b << 1) ^ _tt);
111 }
112 
113 extern int glue_ecb_crypt_128bit(const struct common_glue_ctx *gctx,
114                                  struct blkcipher_desc *desc,
115                                  struct scatterlist *dst,
116                                  struct scatterlist *src, unsigned int nbytes);
117 
118 extern int glue_cbc_encrypt_128bit(const common_glue_func_t fn,
119                                    struct blkcipher_desc *desc,
120                                    struct scatterlist *dst,
121                                    struct scatterlist *src,
122                                    unsigned int nbytes);
123 
124 extern int glue_cbc_decrypt_128bit(const struct common_glue_ctx *gctx,
125                                    struct blkcipher_desc *desc,
126                                    struct scatterlist *dst,
127                                    struct scatterlist *src,
128                                    unsigned int nbytes);
129 
130 extern int glue_ctr_crypt_128bit(const struct common_glue_ctx *gctx,
131                                  struct blkcipher_desc *desc,
132                                  struct scatterlist *dst,
133                                  struct scatterlist *src, unsigned int nbytes);
134 
135 extern int glue_xts_crypt_128bit(const struct common_glue_ctx *gctx,
136                                  struct blkcipher_desc *desc,
137                                  struct scatterlist *dst,
138                                  struct scatterlist *src, unsigned int nbytes,
139                                  common_glue_func_t tweak_fn, void *tweak_ctx,
140                                  void *crypt_ctx);
141 
142 extern void glue_xts_crypt_128bit_one(void *ctx, u128 *dst, const u128 *src,
143                                       le128 *iv, common_glue_func_t fn);
144 
145 #endif /* _CRYPTO_GLUE_HELPER_H */
146 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp