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

TOMOYO Linux Cross Reference
Linux/include/linux/crypto.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 ] ~

Diff markup

Differences between /include/linux/crypto.h (Version linux-6.11.5) and /include/linux/crypto.h (Version linux-4.15.18)


  1 /* SPDX-License-Identifier: GPL-2.0-or-later * << 
  2 /*                                                  1 /*
  3  * Scatterlist Cryptographic API.                   2  * Scatterlist Cryptographic API.
  4  *                                                  3  *
  5  * Copyright (c) 2002 James Morris <jmorris@in      4  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  6  * Copyright (c) 2002 David S. Miller (davem@r      5  * Copyright (c) 2002 David S. Miller (davem@redhat.com)
  7  * Copyright (c) 2005 Herbert Xu <herbert@gond      6  * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
  8  *                                                  7  *
  9  * Portions derived from Cryptoapi, by Alexand      8  * Portions derived from Cryptoapi, by Alexander Kjeldaas <astor@fast.no>
 10  * and Nettle, by Niels Möller.                    9  * and Nettle, by Niels Möller.
                                                   >>  10  * 
                                                   >>  11  * This program is free software; you can redistribute it and/or modify it
                                                   >>  12  * under the terms of the GNU General Public License as published by the Free
                                                   >>  13  * Software Foundation; either version 2 of the License, or (at your option) 
                                                   >>  14  * any later version.
                                                   >>  15  *
 11  */                                                16  */
 12 #ifndef _LINUX_CRYPTO_H                            17 #ifndef _LINUX_CRYPTO_H
 13 #define _LINUX_CRYPTO_H                            18 #define _LINUX_CRYPTO_H
 14                                                    19 
 15 #include <linux/completion.h>                  !!  20 #include <linux/atomic.h>
 16 #include <linux/refcount.h>                    !!  21 #include <linux/kernel.h>
                                                   >>  22 #include <linux/list.h>
                                                   >>  23 #include <linux/bug.h>
 17 #include <linux/slab.h>                            24 #include <linux/slab.h>
 18 #include <linux/types.h>                       !!  25 #include <linux/string.h>
                                                   >>  26 #include <linux/uaccess.h>
                                                   >>  27 #include <linux/completion.h>
                                                   >>  28 
                                                   >>  29 /*
                                                   >>  30  * Autoloaded crypto modules should only use a prefixed name to avoid allowing
                                                   >>  31  * arbitrary modules to be loaded. Loading from userspace may still need the
                                                   >>  32  * unprefixed names, so retains those aliases as well.
                                                   >>  33  * This uses __MODULE_INFO directly instead of MODULE_ALIAS because pre-4.3
                                                   >>  34  * gcc (e.g. avr32 toolchain) uses __LINE__ for uniqueness, and this macro
                                                   >>  35  * expands twice on the same line. Instead, use a separate base name for the
                                                   >>  36  * alias.
                                                   >>  37  */
                                                   >>  38 #define MODULE_ALIAS_CRYPTO(name)       \
                                                   >>  39                 __MODULE_INFO(alias, alias_userspace, name);    \
                                                   >>  40                 __MODULE_INFO(alias, alias_crypto, "crypto-" name)
 19                                                    41 
 20 /*                                                 42 /*
 21  * Algorithm masks and types.                      43  * Algorithm masks and types.
 22  */                                                44  */
 23 #define CRYPTO_ALG_TYPE_MASK            0x0000     45 #define CRYPTO_ALG_TYPE_MASK            0x0000000f
 24 #define CRYPTO_ALG_TYPE_CIPHER          0x0000     46 #define CRYPTO_ALG_TYPE_CIPHER          0x00000001
 25 #define CRYPTO_ALG_TYPE_COMPRESS        0x0000     47 #define CRYPTO_ALG_TYPE_COMPRESS        0x00000002
 26 #define CRYPTO_ALG_TYPE_AEAD            0x0000     48 #define CRYPTO_ALG_TYPE_AEAD            0x00000003
 27 #define CRYPTO_ALG_TYPE_LSKCIPHER       0x0000 !!  49 #define CRYPTO_ALG_TYPE_BLKCIPHER       0x00000004
                                                   >>  50 #define CRYPTO_ALG_TYPE_ABLKCIPHER      0x00000005
 28 #define CRYPTO_ALG_TYPE_SKCIPHER        0x0000     51 #define CRYPTO_ALG_TYPE_SKCIPHER        0x00000005
 29 #define CRYPTO_ALG_TYPE_AKCIPHER        0x0000 !!  52 #define CRYPTO_ALG_TYPE_GIVCIPHER       0x00000006
 30 #define CRYPTO_ALG_TYPE_SIG             0x0000 << 
 31 #define CRYPTO_ALG_TYPE_KPP             0x0000     53 #define CRYPTO_ALG_TYPE_KPP             0x00000008
 32 #define CRYPTO_ALG_TYPE_ACOMPRESS       0x0000     54 #define CRYPTO_ALG_TYPE_ACOMPRESS       0x0000000a
 33 #define CRYPTO_ALG_TYPE_SCOMPRESS       0x0000     55 #define CRYPTO_ALG_TYPE_SCOMPRESS       0x0000000b
 34 #define CRYPTO_ALG_TYPE_RNG             0x0000     56 #define CRYPTO_ALG_TYPE_RNG             0x0000000c
                                                   >>  57 #define CRYPTO_ALG_TYPE_AKCIPHER        0x0000000d
                                                   >>  58 #define CRYPTO_ALG_TYPE_DIGEST          0x0000000e
 35 #define CRYPTO_ALG_TYPE_HASH            0x0000     59 #define CRYPTO_ALG_TYPE_HASH            0x0000000e
 36 #define CRYPTO_ALG_TYPE_SHASH           0x0000     60 #define CRYPTO_ALG_TYPE_SHASH           0x0000000e
 37 #define CRYPTO_ALG_TYPE_AHASH           0x0000     61 #define CRYPTO_ALG_TYPE_AHASH           0x0000000f
 38                                                    62 
                                                   >>  63 #define CRYPTO_ALG_TYPE_HASH_MASK       0x0000000e
                                                   >>  64 #define CRYPTO_ALG_TYPE_AHASH_MASK      0x0000000e
                                                   >>  65 #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK  0x0000000c
 39 #define CRYPTO_ALG_TYPE_ACOMPRESS_MASK  0x0000     66 #define CRYPTO_ALG_TYPE_ACOMPRESS_MASK  0x0000000e
 40                                                    67 
 41 #define CRYPTO_ALG_LARVAL               0x0000     68 #define CRYPTO_ALG_LARVAL               0x00000010
 42 #define CRYPTO_ALG_DEAD                 0x0000     69 #define CRYPTO_ALG_DEAD                 0x00000020
 43 #define CRYPTO_ALG_DYING                0x0000     70 #define CRYPTO_ALG_DYING                0x00000040
 44 #define CRYPTO_ALG_ASYNC                0x0000     71 #define CRYPTO_ALG_ASYNC                0x00000080
 45                                                    72 
 46 /*                                                 73 /*
 47  * Set if the algorithm (or an algorithm which !!  74  * Set this bit if and only if the algorithm requires another algorithm of
 48  * algorithm of the same type to handle corner !!  75  * the same type to handle corner cases.
 49  */                                                76  */
 50 #define CRYPTO_ALG_NEED_FALLBACK        0x0000     77 #define CRYPTO_ALG_NEED_FALLBACK        0x00000100
 51                                                    78 
 52 /*                                                 79 /*
                                                   >>  80  * This bit is set for symmetric key ciphers that have already been wrapped
                                                   >>  81  * with a generic IV generator to prevent them from being wrapped again.
                                                   >>  82  */
                                                   >>  83 #define CRYPTO_ALG_GENIV                0x00000200
                                                   >>  84 
                                                   >>  85 /*
 53  * Set if the algorithm has passed automated r     86  * Set if the algorithm has passed automated run-time testing.  Note that
 54  * if there is no run-time testing for a given     87  * if there is no run-time testing for a given algorithm it is considered
 55  * to have passed.                                 88  * to have passed.
 56  */                                                89  */
 57                                                    90 
 58 #define CRYPTO_ALG_TESTED               0x0000     91 #define CRYPTO_ALG_TESTED               0x00000400
 59                                                    92 
 60 /*                                                 93 /*
 61  * Set if the algorithm is an instance that is     94  * Set if the algorithm is an instance that is built from templates.
 62  */                                                95  */
 63 #define CRYPTO_ALG_INSTANCE             0x0000     96 #define CRYPTO_ALG_INSTANCE             0x00000800
 64                                                    97 
 65 /* Set this bit if the algorithm provided is h     98 /* Set this bit if the algorithm provided is hardware accelerated but
 66  * not available to userspace via instruction      99  * not available to userspace via instruction set or so.
 67  */                                               100  */
 68 #define CRYPTO_ALG_KERN_DRIVER_ONLY     0x0000    101 #define CRYPTO_ALG_KERN_DRIVER_ONLY     0x00001000
 69                                                   102 
 70 /*                                                103 /*
 71  * Mark a cipher as a service implementation o    104  * Mark a cipher as a service implementation only usable by another
 72  * cipher and never by a normal user of the ke    105  * cipher and never by a normal user of the kernel crypto API
 73  */                                               106  */
 74 #define CRYPTO_ALG_INTERNAL             0x0000    107 #define CRYPTO_ALG_INTERNAL             0x00002000
 75                                                   108 
 76 /*                                                109 /*
 77  * Set if the algorithm has a ->setkey() metho    110  * Set if the algorithm has a ->setkey() method but can be used without
 78  * calling it first, i.e. there is a default k    111  * calling it first, i.e. there is a default key.
 79  */                                               112  */
 80 #define CRYPTO_ALG_OPTIONAL_KEY         0x0000    113 #define CRYPTO_ALG_OPTIONAL_KEY         0x00004000
 81                                                   114 
 82 /*                                                115 /*
 83  * Don't trigger module loading                << 
 84  */                                            << 
 85 #define CRYPTO_NOLOAD                   0x0000 << 
 86                                                << 
 87 /*                                             << 
 88  * The algorithm may allocate memory during re << 
 89  * encryption, decryption, or hashing.  Users  << 
 90  * flag unset if they can't handle memory allo << 
 91  *                                             << 
 92  * This flag is currently only implemented for << 
 93  * "aead", "ahash", "shash", and "cipher".  Al << 
 94  * have this flag set even if they allocate me << 
 95  *                                             << 
 96  * In some edge cases, algorithms can allocate << 
 97  * To avoid these cases, users must obey the f << 
 98  *    skcipher:                                << 
 99  *      - The IV buffer and all scatterlist el << 
100  *        algorithm's alignmask.               << 
101  *      - If the data were to be divided into  << 
102  *        crypto_skcipher_walksize() (with any << 
103  *        chunk can cross a page boundary or a << 
104  *    aead:                                    << 
105  *      - The IV buffer and all scatterlist el << 
106  *        algorithm's alignmask.               << 
107  *      - The first scatterlist element must c << 
108  *        and its pages must be !PageHighMem.  << 
109  *      - If the plaintext/ciphertext were to  << 
110  *        crypto_aead_walksize() (with the rem << 
111  *        can cross a page boundary or a scatt << 
112  *    ahash:                                   << 
113  *      - crypto_ahash_finup() must not be use << 
114  *        ->finup() natively.                  << 
115  */                                            << 
116 #define CRYPTO_ALG_ALLOCATES_MEMORY     0x0001 << 
117                                                << 
118 /*                                             << 
119  * Mark an algorithm as a service implementati << 
120  * template and never by a normal user of the  << 
121  * This is intended to be used by algorithms t << 
122  * not FIPS-approved but may instead be used t << 
123  * a FIPS-approved algorithm (e.g., dh vs. ffd << 
124  */                                            << 
125 #define CRYPTO_ALG_FIPS_INTERNAL        0x0002 << 
126                                                << 
127 /*                                             << 
128  * Transform masks and values (for crt_flags).    116  * Transform masks and values (for crt_flags).
129  */                                               117  */
130 #define CRYPTO_TFM_NEED_KEY             0x0000    118 #define CRYPTO_TFM_NEED_KEY             0x00000001
131                                                   119 
132 #define CRYPTO_TFM_REQ_MASK             0x000f    120 #define CRYPTO_TFM_REQ_MASK             0x000fff00
133 #define CRYPTO_TFM_REQ_FORBID_WEAK_KEYS 0x0000 !! 121 #define CRYPTO_TFM_RES_MASK             0xfff00000
                                                   >> 122 
                                                   >> 123 #define CRYPTO_TFM_REQ_WEAK_KEY         0x00000100
134 #define CRYPTO_TFM_REQ_MAY_SLEEP        0x0000    124 #define CRYPTO_TFM_REQ_MAY_SLEEP        0x00000200
135 #define CRYPTO_TFM_REQ_MAY_BACKLOG      0x0000    125 #define CRYPTO_TFM_REQ_MAY_BACKLOG      0x00000400
                                                   >> 126 #define CRYPTO_TFM_RES_WEAK_KEY         0x00100000
                                                   >> 127 #define CRYPTO_TFM_RES_BAD_KEY_LEN      0x00200000
                                                   >> 128 #define CRYPTO_TFM_RES_BAD_KEY_SCHED    0x00400000
                                                   >> 129 #define CRYPTO_TFM_RES_BAD_BLOCK_LEN    0x00800000
                                                   >> 130 #define CRYPTO_TFM_RES_BAD_FLAGS        0x01000000
136                                                   131 
137 /*                                                132 /*
138  * Miscellaneous stuff.                           133  * Miscellaneous stuff.
139  */                                               134  */
140 #define CRYPTO_MAX_ALG_NAME             128       135 #define CRYPTO_MAX_ALG_NAME             128
141                                                   136 
142 /*                                                137 /*
143  * The macro CRYPTO_MINALIGN_ATTR (along with     138  * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual
144  * declaration) is used to ensure that the cry    139  * declaration) is used to ensure that the crypto_tfm context structure is
145  * aligned correctly for the given architectur    140  * aligned correctly for the given architecture so that there are no alignment
146  * faults for C data types.  On architectures  !! 141  * faults for C data types.  In particular, this is required on platforms such
147  * DMA, such as ARM or arm64, it also takes in !! 142  * as arm where pointers are 32-bit aligned but there are data types such as
148  * that is required to ensure that the context !! 143  * u64 which require 64-bit alignment.
149  * cachelines with the rest of the struct. Thi << 
150  * maintenance for non-coherent DMA (cache inv << 
151  * affect data that may be accessed by the CPU << 
152  */                                               144  */
153 #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN     145 #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN
154                                                   146 
155 #define CRYPTO_MINALIGN_ATTR __attribute__ ((_    147 #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN)))
156                                                   148 
                                                   >> 149 struct scatterlist;
                                                   >> 150 struct crypto_ablkcipher;
                                                   >> 151 struct crypto_async_request;
                                                   >> 152 struct crypto_blkcipher;
157 struct crypto_tfm;                                153 struct crypto_tfm;
158 struct crypto_type;                               154 struct crypto_type;
159 struct module;                                 !! 155 struct skcipher_givcrypt_request;
160                                                   156 
161 typedef void (*crypto_completion_t)(void *req, !! 157 typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err);
162                                                   158 
163 /**                                               159 /**
164  * DOC: Block Cipher Context Data Structures      160  * DOC: Block Cipher Context Data Structures
165  *                                                161  *
166  * These data structures define the operating     162  * These data structures define the operating context for each block cipher
167  * type.                                          163  * type.
168  */                                               164  */
169                                                   165 
170 struct crypto_async_request {                     166 struct crypto_async_request {
171         struct list_head list;                    167         struct list_head list;
172         crypto_completion_t complete;             168         crypto_completion_t complete;
173         void *data;                               169         void *data;
174         struct crypto_tfm *tfm;                   170         struct crypto_tfm *tfm;
175                                                   171 
176         u32 flags;                                172         u32 flags;
177 };                                                173 };
178                                                   174 
                                                   >> 175 struct ablkcipher_request {
                                                   >> 176         struct crypto_async_request base;
                                                   >> 177 
                                                   >> 178         unsigned int nbytes;
                                                   >> 179 
                                                   >> 180         void *info;
                                                   >> 181 
                                                   >> 182         struct scatterlist *src;
                                                   >> 183         struct scatterlist *dst;
                                                   >> 184 
                                                   >> 185         void *__ctx[] CRYPTO_MINALIGN_ATTR;
                                                   >> 186 };
                                                   >> 187 
                                                   >> 188 struct blkcipher_desc {
                                                   >> 189         struct crypto_blkcipher *tfm;
                                                   >> 190         void *info;
                                                   >> 191         u32 flags;
                                                   >> 192 };
                                                   >> 193 
                                                   >> 194 struct cipher_desc {
                                                   >> 195         struct crypto_tfm *tfm;
                                                   >> 196         void (*crfn)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
                                                   >> 197         unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst,
                                                   >> 198                              const u8 *src, unsigned int nbytes);
                                                   >> 199         void *info;
                                                   >> 200 };
                                                   >> 201 
179 /**                                               202 /**
180  * DOC: Block Cipher Algorithm Definitions        203  * DOC: Block Cipher Algorithm Definitions
181  *                                                204  *
182  * These data structures define modular crypto    205  * These data structures define modular crypto algorithm implementations,
183  * managed via crypto_register_alg() and crypt    206  * managed via crypto_register_alg() and crypto_unregister_alg().
184  */                                               207  */
185                                                   208 
186 /**                                               209 /**
                                                   >> 210  * struct ablkcipher_alg - asynchronous block cipher definition
                                                   >> 211  * @min_keysize: Minimum key size supported by the transformation. This is the
                                                   >> 212  *               smallest key length supported by this transformation algorithm.
                                                   >> 213  *               This must be set to one of the pre-defined values as this is
                                                   >> 214  *               not hardware specific. Possible values for this field can be
                                                   >> 215  *               found via git grep "_MIN_KEY_SIZE" include/crypto/
                                                   >> 216  * @max_keysize: Maximum key size supported by the transformation. This is the
                                                   >> 217  *               largest key length supported by this transformation algorithm.
                                                   >> 218  *               This must be set to one of the pre-defined values as this is
                                                   >> 219  *               not hardware specific. Possible values for this field can be
                                                   >> 220  *               found via git grep "_MAX_KEY_SIZE" include/crypto/
                                                   >> 221  * @setkey: Set key for the transformation. This function is used to either
                                                   >> 222  *          program a supplied key into the hardware or store the key in the
                                                   >> 223  *          transformation context for programming it later. Note that this
                                                   >> 224  *          function does modify the transformation context. This function can
                                                   >> 225  *          be called multiple times during the existence of the transformation
                                                   >> 226  *          object, so one must make sure the key is properly reprogrammed into
                                                   >> 227  *          the hardware. This function is also responsible for checking the key
                                                   >> 228  *          length for validity. In case a software fallback was put in place in
                                                   >> 229  *          the @cra_init call, this function might need to use the fallback if
                                                   >> 230  *          the algorithm doesn't support all of the key sizes.
                                                   >> 231  * @encrypt: Encrypt a scatterlist of blocks. This function is used to encrypt
                                                   >> 232  *           the supplied scatterlist containing the blocks of data. The crypto
                                                   >> 233  *           API consumer is responsible for aligning the entries of the
                                                   >> 234  *           scatterlist properly and making sure the chunks are correctly
                                                   >> 235  *           sized. In case a software fallback was put in place in the
                                                   >> 236  *           @cra_init call, this function might need to use the fallback if
                                                   >> 237  *           the algorithm doesn't support all of the key sizes. In case the
                                                   >> 238  *           key was stored in transformation context, the key might need to be
                                                   >> 239  *           re-programmed into the hardware in this function. This function
                                                   >> 240  *           shall not modify the transformation context, as this function may
                                                   >> 241  *           be called in parallel with the same transformation object.
                                                   >> 242  * @decrypt: Decrypt a single block. This is a reverse counterpart to @encrypt
                                                   >> 243  *           and the conditions are exactly the same.
                                                   >> 244  * @givencrypt: Update the IV for encryption. With this function, a cipher
                                                   >> 245  *              implementation may provide the function on how to update the IV
                                                   >> 246  *              for encryption.
                                                   >> 247  * @givdecrypt: Update the IV for decryption. This is the reverse of
                                                   >> 248  *              @givencrypt .
                                                   >> 249  * @geniv: The transformation implementation may use an "IV generator" provided
                                                   >> 250  *         by the kernel crypto API. Several use cases have a predefined
                                                   >> 251  *         approach how IVs are to be updated. For such use cases, the kernel
                                                   >> 252  *         crypto API provides ready-to-use implementations that can be
                                                   >> 253  *         referenced with this variable.
                                                   >> 254  * @ivsize: IV size applicable for transformation. The consumer must provide an
                                                   >> 255  *          IV of exactly that size to perform the encrypt or decrypt operation.
                                                   >> 256  *
                                                   >> 257  * All fields except @givencrypt , @givdecrypt , @geniv and @ivsize are
                                                   >> 258  * mandatory and must be filled.
                                                   >> 259  */
                                                   >> 260 struct ablkcipher_alg {
                                                   >> 261         int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key,
                                                   >> 262                       unsigned int keylen);
                                                   >> 263         int (*encrypt)(struct ablkcipher_request *req);
                                                   >> 264         int (*decrypt)(struct ablkcipher_request *req);
                                                   >> 265         int (*givencrypt)(struct skcipher_givcrypt_request *req);
                                                   >> 266         int (*givdecrypt)(struct skcipher_givcrypt_request *req);
                                                   >> 267 
                                                   >> 268         const char *geniv;
                                                   >> 269 
                                                   >> 270         unsigned int min_keysize;
                                                   >> 271         unsigned int max_keysize;
                                                   >> 272         unsigned int ivsize;
                                                   >> 273 };
                                                   >> 274 
                                                   >> 275 /**
                                                   >> 276  * struct blkcipher_alg - synchronous block cipher definition
                                                   >> 277  * @min_keysize: see struct ablkcipher_alg
                                                   >> 278  * @max_keysize: see struct ablkcipher_alg
                                                   >> 279  * @setkey: see struct ablkcipher_alg
                                                   >> 280  * @encrypt: see struct ablkcipher_alg
                                                   >> 281  * @decrypt: see struct ablkcipher_alg
                                                   >> 282  * @geniv: see struct ablkcipher_alg
                                                   >> 283  * @ivsize: see struct ablkcipher_alg
                                                   >> 284  *
                                                   >> 285  * All fields except @geniv and @ivsize are mandatory and must be filled.
                                                   >> 286  */
                                                   >> 287 struct blkcipher_alg {
                                                   >> 288         int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
                                                   >> 289                       unsigned int keylen);
                                                   >> 290         int (*encrypt)(struct blkcipher_desc *desc,
                                                   >> 291                        struct scatterlist *dst, struct scatterlist *src,
                                                   >> 292                        unsigned int nbytes);
                                                   >> 293         int (*decrypt)(struct blkcipher_desc *desc,
                                                   >> 294                        struct scatterlist *dst, struct scatterlist *src,
                                                   >> 295                        unsigned int nbytes);
                                                   >> 296 
                                                   >> 297         const char *geniv;
                                                   >> 298 
                                                   >> 299         unsigned int min_keysize;
                                                   >> 300         unsigned int max_keysize;
                                                   >> 301         unsigned int ivsize;
                                                   >> 302 };
                                                   >> 303 
                                                   >> 304 /**
187  * struct cipher_alg - single-block symmetric     305  * struct cipher_alg - single-block symmetric ciphers definition
188  * @cia_min_keysize: Minimum key size supporte    306  * @cia_min_keysize: Minimum key size supported by the transformation. This is
189  *                   the smallest key length s    307  *                   the smallest key length supported by this transformation
190  *                   algorithm. This must be s    308  *                   algorithm. This must be set to one of the pre-defined
191  *                   values as this is not har    309  *                   values as this is not hardware specific. Possible values
192  *                   for this field can be fou    310  *                   for this field can be found via git grep "_MIN_KEY_SIZE"
193  *                   include/crypto/              311  *                   include/crypto/
194  * @cia_max_keysize: Maximum key size supporte    312  * @cia_max_keysize: Maximum key size supported by the transformation. This is
195  *                  the largest key length sup    313  *                  the largest key length supported by this transformation
196  *                  algorithm. This must be se    314  *                  algorithm. This must be set to one of the pre-defined values
197  *                  as this is not hardware sp    315  *                  as this is not hardware specific. Possible values for this
198  *                  field can be found via git    316  *                  field can be found via git grep "_MAX_KEY_SIZE"
199  *                  include/crypto/               317  *                  include/crypto/
200  * @cia_setkey: Set key for the transformation    318  * @cia_setkey: Set key for the transformation. This function is used to either
201  *              program a supplied key into th    319  *              program a supplied key into the hardware or store the key in the
202  *              transformation context for pro    320  *              transformation context for programming it later. Note that this
203  *              function does modify the trans    321  *              function does modify the transformation context. This function
204  *              can be called multiple times d    322  *              can be called multiple times during the existence of the
205  *              transformation object, so one     323  *              transformation object, so one must make sure the key is properly
206  *              reprogrammed into the hardware    324  *              reprogrammed into the hardware. This function is also
207  *              responsible for checking the k    325  *              responsible for checking the key length for validity.
208  * @cia_encrypt: Encrypt a single block. This     326  * @cia_encrypt: Encrypt a single block. This function is used to encrypt a
209  *               single block of data, which m    327  *               single block of data, which must be @cra_blocksize big. This
210  *               always operates on a full @cr    328  *               always operates on a full @cra_blocksize and it is not possible
211  *               to encrypt a block of smaller    329  *               to encrypt a block of smaller size. The supplied buffers must
212  *               therefore also be at least of    330  *               therefore also be at least of @cra_blocksize size. Both the
213  *               input and output buffers are     331  *               input and output buffers are always aligned to @cra_alignmask.
214  *               In case either of the input o    332  *               In case either of the input or output buffer supplied by user
215  *               of the crypto API is not alig    333  *               of the crypto API is not aligned to @cra_alignmask, the crypto
216  *               API will re-align the buffers    334  *               API will re-align the buffers. The re-alignment means that a
217  *               new buffer will be allocated,    335  *               new buffer will be allocated, the data will be copied into the
218  *               new buffer, then the processi    336  *               new buffer, then the processing will happen on the new buffer,
219  *               then the data will be copied     337  *               then the data will be copied back into the original buffer and
220  *               finally the new buffer will b    338  *               finally the new buffer will be freed. In case a software
221  *               fallback was put in place in     339  *               fallback was put in place in the @cra_init call, this function
222  *               might need to use the fallbac    340  *               might need to use the fallback if the algorithm doesn't support
223  *               all of the key sizes. In case    341  *               all of the key sizes. In case the key was stored in
224  *               transformation context, the k    342  *               transformation context, the key might need to be re-programmed
225  *               into the hardware in this fun    343  *               into the hardware in this function. This function shall not
226  *               modify the transformation con    344  *               modify the transformation context, as this function may be
227  *               called in parallel with the s    345  *               called in parallel with the same transformation object.
228  * @cia_decrypt: Decrypt a single block. This     346  * @cia_decrypt: Decrypt a single block. This is a reverse counterpart to
229  *               @cia_encrypt, and the conditi    347  *               @cia_encrypt, and the conditions are exactly the same.
230  *                                                348  *
231  * All fields are mandatory and must be filled    349  * All fields are mandatory and must be filled.
232  */                                               350  */
233 struct cipher_alg {                               351 struct cipher_alg {
234         unsigned int cia_min_keysize;             352         unsigned int cia_min_keysize;
235         unsigned int cia_max_keysize;             353         unsigned int cia_max_keysize;
236         int (*cia_setkey)(struct crypto_tfm *t    354         int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key,
237                           unsigned int keylen)    355                           unsigned int keylen);
238         void (*cia_encrypt)(struct crypto_tfm     356         void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
239         void (*cia_decrypt)(struct crypto_tfm     357         void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
240 };                                                358 };
241                                                   359 
242 /**                                            << 
243  * struct compress_alg - compression/decompres << 
244  * @coa_compress: Compress a buffer of specifi << 
245  *                data in the specified buffer << 
246  *                compressed data in dlen.     << 
247  * @coa_decompress: Decompress the source buff << 
248  *                  data in the specified buff << 
249  *                  returned in dlen.          << 
250  *                                             << 
251  * All fields are mandatory.                   << 
252  */                                            << 
253 struct compress_alg {                             360 struct compress_alg {
254         int (*coa_compress)(struct crypto_tfm     361         int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src,
255                             unsigned int slen,    362                             unsigned int slen, u8 *dst, unsigned int *dlen);
256         int (*coa_decompress)(struct crypto_tf    363         int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
257                               unsigned int sle    364                               unsigned int slen, u8 *dst, unsigned int *dlen);
258 };                                                365 };
259                                                   366 
                                                   >> 367 
                                                   >> 368 #define cra_ablkcipher  cra_u.ablkcipher
                                                   >> 369 #define cra_blkcipher   cra_u.blkcipher
260 #define cra_cipher      cra_u.cipher              370 #define cra_cipher      cra_u.cipher
261 #define cra_compress    cra_u.compress            371 #define cra_compress    cra_u.compress
262                                                   372 
263 /**                                               373 /**
264  * struct crypto_alg - definition of a cryptog    374  * struct crypto_alg - definition of a cryptograpic cipher algorithm
265  * @cra_flags: Flags describing this transform    375  * @cra_flags: Flags describing this transformation. See include/linux/crypto.h
266  *             CRYPTO_ALG_* flags for the flag    376  *             CRYPTO_ALG_* flags for the flags which go in here. Those are
267  *             used for fine-tuning the descri    377  *             used for fine-tuning the description of the transformation
268  *             algorithm.                         378  *             algorithm.
269  * @cra_blocksize: Minimum block size of this     379  * @cra_blocksize: Minimum block size of this transformation. The size in bytes
270  *                 of the smallest possible un    380  *                 of the smallest possible unit which can be transformed with
271  *                 this algorithm. The users m    381  *                 this algorithm. The users must respect this value.
272  *                 In case of HASH transformat    382  *                 In case of HASH transformation, it is possible for a smaller
273  *                 block than @cra_blocksize t    383  *                 block than @cra_blocksize to be passed to the crypto API for
274  *                 transformation, in case of     384  *                 transformation, in case of any other transformation type, an
275  *                 error will be returned upon    385  *                 error will be returned upon any attempt to transform smaller
276  *                 than @cra_blocksize chunks.    386  *                 than @cra_blocksize chunks.
277  * @cra_ctxsize: Size of the operational conte    387  * @cra_ctxsize: Size of the operational context of the transformation. This
278  *               value informs the kernel cryp    388  *               value informs the kernel crypto API about the memory size
279  *               needed to be allocated for th    389  *               needed to be allocated for the transformation context.
280  * @cra_alignmask: For cipher, skcipher, lskci !! 390  * @cra_alignmask: Alignment mask for the input and output data buffer. The data
281  *                 1 less than the alignment,  !! 391  *                 buffer containing the input data for the algorithm must be
282  *                 implementation requires for !! 392  *                 aligned to this alignment mask. The data buffer for the
283  *                 the crypto API is invoked w !! 393  *                 output data must be aligned to this alignment mask. Note that
284  *                 to this alignment, the cryp !! 394  *                 the Crypto API will do the re-alignment in software, but
285  *                 appropriately aligned tempo !! 395  *                 only under special conditions and there is a performance hit.
286  *                 the algorithm needs.  (For  !! 396  *                 The re-alignment happens at these occasions for different
287  *                 the algorithm uses the skci !! 397  *                 @cra_u types: cipher -- For both input data and output data
288  *                 misalignment handling carri !! 398  *                 buffer; ahash -- For output hash destination buf; shash --
289  *                 preferred that algorithms d !! 399  *                 For output hash destination buf.
290  *                 Also, crypto API users may  !! 400  *                 This is needed on hardware which is flawed by design and
291  *                 to the alignmask of the alg !! 401  *                 cannot pick data from arbitrary addresses.
292  *                 avoid the API having to rea << 
293  *                 not supported for hash algo << 
294  * @cra_priority: Priority of this transformat    402  * @cra_priority: Priority of this transformation implementation. In case
295  *                multiple transformations wit    403  *                multiple transformations with same @cra_name are available to
296  *                the Crypto API, the kernel w    404  *                the Crypto API, the kernel will use the one with highest
297  *                @cra_priority.                  405  *                @cra_priority.
298  * @cra_name: Generic name (usable by multiple    406  * @cra_name: Generic name (usable by multiple implementations) of the
299  *            transformation algorithm. This i    407  *            transformation algorithm. This is the name of the transformation
300  *            itself. This field is used by th    408  *            itself. This field is used by the kernel when looking up the
301  *            providers of particular transfor    409  *            providers of particular transformation.
302  * @cra_driver_name: Unique name of the transf    410  * @cra_driver_name: Unique name of the transformation provider. This is the
303  *                   name of the provider of t    411  *                   name of the provider of the transformation. This can be any
304  *                   arbitrary value, but in t    412  *                   arbitrary value, but in the usual case, this contains the
305  *                   name of the chip or provi    413  *                   name of the chip or provider and the name of the
306  *                   transformation algorithm.    414  *                   transformation algorithm.
307  * @cra_type: Type of the cryptographic transf    415  * @cra_type: Type of the cryptographic transformation. This is a pointer to
308  *            struct crypto_type, which implem    416  *            struct crypto_type, which implements callbacks common for all
309  *            transformation types. There are  !! 417  *            transformation types. There are multiple options:
310  *            &crypto_skcipher_type, &crypto_a !! 418  *            &crypto_blkcipher_type, &crypto_ablkcipher_type,
                                                   >> 419  *            &crypto_ahash_type, &crypto_rng_type.
311  *            This field might be empty. In th    420  *            This field might be empty. In that case, there are no common
312  *            callbacks. This is the case for:    421  *            callbacks. This is the case for: cipher, compress, shash.
313  * @cra_u: Callbacks implementing the transfor    422  * @cra_u: Callbacks implementing the transformation. This is a union of
314  *         multiple structures. Depending on t    423  *         multiple structures. Depending on the type of transformation selected
315  *         by @cra_type and @cra_flags above,     424  *         by @cra_type and @cra_flags above, the associated structure must be
316  *         filled with callbacks. This field m    425  *         filled with callbacks. This field might be empty. This is the case
317  *         for ahash, shash.                      426  *         for ahash, shash.
318  * @cra_init: Initialize the cryptographic tra    427  * @cra_init: Initialize the cryptographic transformation object. This function
319  *            is used to initialize the crypto    428  *            is used to initialize the cryptographic transformation object.
320  *            This function is called only onc    429  *            This function is called only once at the instantiation time, right
321  *            after the transformation context    430  *            after the transformation context was allocated. In case the
322  *            cryptographic hardware has some     431  *            cryptographic hardware has some special requirements which need to
323  *            be handled by software, this fun    432  *            be handled by software, this function shall check for the precise
324  *            requirement of the transformatio    433  *            requirement of the transformation and put any software fallbacks
325  *            in place.                           434  *            in place.
326  * @cra_exit: Deinitialize the cryptographic t    435  * @cra_exit: Deinitialize the cryptographic transformation object. This is a
327  *            counterpart to @cra_init, used t    436  *            counterpart to @cra_init, used to remove various changes set in
328  *            @cra_init.                          437  *            @cra_init.
329  * @cra_u.cipher: Union member which contains  << 
330  *                definition. See @struct @cip << 
331  * @cra_u.compress: Union member which contain << 
332  *                  See @struct @compress_alg. << 
333  * @cra_module: Owner of this transformation i    438  * @cra_module: Owner of this transformation implementation. Set to THIS_MODULE
334  * @cra_list: internally used                     439  * @cra_list: internally used
335  * @cra_users: internally used                    440  * @cra_users: internally used
336  * @cra_refcnt: internally used                   441  * @cra_refcnt: internally used
337  * @cra_destroy: internally used                  442  * @cra_destroy: internally used
338  *                                                443  *
339  * The struct crypto_alg describes a generic C    444  * The struct crypto_alg describes a generic Crypto API algorithm and is common
340  * for all of the transformations. Any variabl    445  * for all of the transformations. Any variable not documented here shall not
341  * be used by a cipher implementation as it is    446  * be used by a cipher implementation as it is internal to the Crypto API.
342  */                                               447  */
343 struct crypto_alg {                               448 struct crypto_alg {
344         struct list_head cra_list;                449         struct list_head cra_list;
345         struct list_head cra_users;               450         struct list_head cra_users;
346                                                   451 
347         u32 cra_flags;                            452         u32 cra_flags;
348         unsigned int cra_blocksize;               453         unsigned int cra_blocksize;
349         unsigned int cra_ctxsize;                 454         unsigned int cra_ctxsize;
350         unsigned int cra_alignmask;               455         unsigned int cra_alignmask;
351                                                   456 
352         int cra_priority;                         457         int cra_priority;
353         refcount_t cra_refcnt;                 !! 458         atomic_t cra_refcnt;
354                                                   459 
355         char cra_name[CRYPTO_MAX_ALG_NAME];       460         char cra_name[CRYPTO_MAX_ALG_NAME];
356         char cra_driver_name[CRYPTO_MAX_ALG_NA    461         char cra_driver_name[CRYPTO_MAX_ALG_NAME];
357                                                   462 
358         const struct crypto_type *cra_type;       463         const struct crypto_type *cra_type;
359                                                   464 
360         union {                                   465         union {
                                                   >> 466                 struct ablkcipher_alg ablkcipher;
                                                   >> 467                 struct blkcipher_alg blkcipher;
361                 struct cipher_alg cipher;         468                 struct cipher_alg cipher;
362                 struct compress_alg compress;     469                 struct compress_alg compress;
363         } cra_u;                                  470         } cra_u;
364                                                   471 
365         int (*cra_init)(struct crypto_tfm *tfm    472         int (*cra_init)(struct crypto_tfm *tfm);
366         void (*cra_exit)(struct crypto_tfm *tf    473         void (*cra_exit)(struct crypto_tfm *tfm);
367         void (*cra_destroy)(struct crypto_alg     474         void (*cra_destroy)(struct crypto_alg *alg);
368                                                   475         
369         struct module *cra_module;                476         struct module *cra_module;
370 } CRYPTO_MINALIGN_ATTR;                           477 } CRYPTO_MINALIGN_ATTR;
371                                                   478 
372 /*                                                479 /*
373  * A helper struct for waiting for completion     480  * A helper struct for waiting for completion of async crypto ops
374  */                                               481  */
375 struct crypto_wait {                              482 struct crypto_wait {
376         struct completion completion;             483         struct completion completion;
377         int err;                                  484         int err;
378 };                                                485 };
379                                                   486 
380 /*                                                487 /*
381  * Macro for declaring a crypto op async wait     488  * Macro for declaring a crypto op async wait object on stack
382  */                                               489  */
383 #define DECLARE_CRYPTO_WAIT(_wait) \              490 #define DECLARE_CRYPTO_WAIT(_wait) \
384         struct crypto_wait _wait = { \            491         struct crypto_wait _wait = { \
385                 COMPLETION_INITIALIZER_ONSTACK    492                 COMPLETION_INITIALIZER_ONSTACK((_wait).completion), 0 }
386                                                   493 
387 /*                                                494 /*
388  * Async ops completion helper functioons         495  * Async ops completion helper functioons
389  */                                               496  */
390 void crypto_req_done(void *req, int err);      !! 497 void crypto_req_done(struct crypto_async_request *req, int err);
391                                                   498 
392 static inline int crypto_wait_req(int err, str    499 static inline int crypto_wait_req(int err, struct crypto_wait *wait)
393 {                                                 500 {
394         switch (err) {                            501         switch (err) {
395         case -EINPROGRESS:                        502         case -EINPROGRESS:
396         case -EBUSY:                              503         case -EBUSY:
397                 wait_for_completion(&wait->com    504                 wait_for_completion(&wait->completion);
398                 reinit_completion(&wait->compl    505                 reinit_completion(&wait->completion);
399                 err = wait->err;                  506                 err = wait->err;
400                 break;                            507                 break;
401         }                                      !! 508         };
402                                                   509 
403         return err;                               510         return err;
404 }                                                 511 }
405                                                   512 
406 static inline void crypto_init_wait(struct cry    513 static inline void crypto_init_wait(struct crypto_wait *wait)
407 {                                                 514 {
408         init_completion(&wait->completion);       515         init_completion(&wait->completion);
409 }                                                 516 }
410                                                   517 
411 /*                                                518 /*
                                                   >> 519  * Algorithm registration interface.
                                                   >> 520  */
                                                   >> 521 int crypto_register_alg(struct crypto_alg *alg);
                                                   >> 522 int crypto_unregister_alg(struct crypto_alg *alg);
                                                   >> 523 int crypto_register_algs(struct crypto_alg *algs, int count);
                                                   >> 524 int crypto_unregister_algs(struct crypto_alg *algs, int count);
                                                   >> 525 
                                                   >> 526 /*
412  * Algorithm query interface.                     527  * Algorithm query interface.
413  */                                               528  */
414 int crypto_has_alg(const char *name, u32 type,    529 int crypto_has_alg(const char *name, u32 type, u32 mask);
415                                                   530 
416 /*                                                531 /*
417  * Transforms: user-instantiated objects which    532  * Transforms: user-instantiated objects which encapsulate algorithms
418  * and core processing logic.  Managed via cry    533  * and core processing logic.  Managed via crypto_alloc_*() and
419  * crypto_free_*(), as well as the various hel    534  * crypto_free_*(), as well as the various helpers below.
420  */                                               535  */
421                                                   536 
                                                   >> 537 struct ablkcipher_tfm {
                                                   >> 538         int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key,
                                                   >> 539                       unsigned int keylen);
                                                   >> 540         int (*encrypt)(struct ablkcipher_request *req);
                                                   >> 541         int (*decrypt)(struct ablkcipher_request *req);
                                                   >> 542 
                                                   >> 543         struct crypto_ablkcipher *base;
                                                   >> 544 
                                                   >> 545         unsigned int ivsize;
                                                   >> 546         unsigned int reqsize;
                                                   >> 547 };
                                                   >> 548 
                                                   >> 549 struct blkcipher_tfm {
                                                   >> 550         void *iv;
                                                   >> 551         int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
                                                   >> 552                       unsigned int keylen);
                                                   >> 553         int (*encrypt)(struct blkcipher_desc *desc, struct scatterlist *dst,
                                                   >> 554                        struct scatterlist *src, unsigned int nbytes);
                                                   >> 555         int (*decrypt)(struct blkcipher_desc *desc, struct scatterlist *dst,
                                                   >> 556                        struct scatterlist *src, unsigned int nbytes);
                                                   >> 557 };
                                                   >> 558 
                                                   >> 559 struct cipher_tfm {
                                                   >> 560         int (*cit_setkey)(struct crypto_tfm *tfm,
                                                   >> 561                           const u8 *key, unsigned int keylen);
                                                   >> 562         void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
                                                   >> 563         void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
                                                   >> 564 };
                                                   >> 565 
                                                   >> 566 struct compress_tfm {
                                                   >> 567         int (*cot_compress)(struct crypto_tfm *tfm,
                                                   >> 568                             const u8 *src, unsigned int slen,
                                                   >> 569                             u8 *dst, unsigned int *dlen);
                                                   >> 570         int (*cot_decompress)(struct crypto_tfm *tfm,
                                                   >> 571                               const u8 *src, unsigned int slen,
                                                   >> 572                               u8 *dst, unsigned int *dlen);
                                                   >> 573 };
                                                   >> 574 
                                                   >> 575 #define crt_ablkcipher  crt_u.ablkcipher
                                                   >> 576 #define crt_blkcipher   crt_u.blkcipher
                                                   >> 577 #define crt_cipher      crt_u.cipher
                                                   >> 578 #define crt_compress    crt_u.compress
                                                   >> 579 
422 struct crypto_tfm {                               580 struct crypto_tfm {
423         refcount_t refcnt;                     << 
424                                                   581 
425         u32 crt_flags;                            582         u32 crt_flags;
426                                                << 
427         int node;                              << 
428                                                   583         
                                                   >> 584         union {
                                                   >> 585                 struct ablkcipher_tfm ablkcipher;
                                                   >> 586                 struct blkcipher_tfm blkcipher;
                                                   >> 587                 struct cipher_tfm cipher;
                                                   >> 588                 struct compress_tfm compress;
                                                   >> 589         } crt_u;
                                                   >> 590 
429         void (*exit)(struct crypto_tfm *tfm);     591         void (*exit)(struct crypto_tfm *tfm);
430                                                   592         
431         struct crypto_alg *__crt_alg;             593         struct crypto_alg *__crt_alg;
432                                                   594 
433         void *__crt_ctx[] CRYPTO_MINALIGN_ATTR    595         void *__crt_ctx[] CRYPTO_MINALIGN_ATTR;
434 };                                                596 };
435                                                   597 
                                                   >> 598 struct crypto_ablkcipher {
                                                   >> 599         struct crypto_tfm base;
                                                   >> 600 };
                                                   >> 601 
                                                   >> 602 struct crypto_blkcipher {
                                                   >> 603         struct crypto_tfm base;
                                                   >> 604 };
                                                   >> 605 
                                                   >> 606 struct crypto_cipher {
                                                   >> 607         struct crypto_tfm base;
                                                   >> 608 };
                                                   >> 609 
436 struct crypto_comp {                              610 struct crypto_comp {
437         struct crypto_tfm base;                   611         struct crypto_tfm base;
438 };                                                612 };
439                                                   613 
                                                   >> 614 enum {
                                                   >> 615         CRYPTOA_UNSPEC,
                                                   >> 616         CRYPTOA_ALG,
                                                   >> 617         CRYPTOA_TYPE,
                                                   >> 618         CRYPTOA_U32,
                                                   >> 619         __CRYPTOA_MAX,
                                                   >> 620 };
                                                   >> 621 
                                                   >> 622 #define CRYPTOA_MAX (__CRYPTOA_MAX - 1)
                                                   >> 623 
                                                   >> 624 /* Maximum number of (rtattr) parameters for each template. */
                                                   >> 625 #define CRYPTO_MAX_ATTRS 32
                                                   >> 626 
                                                   >> 627 struct crypto_attr_alg {
                                                   >> 628         char name[CRYPTO_MAX_ALG_NAME];
                                                   >> 629 };
                                                   >> 630 
                                                   >> 631 struct crypto_attr_type {
                                                   >> 632         u32 type;
                                                   >> 633         u32 mask;
                                                   >> 634 };
                                                   >> 635 
                                                   >> 636 struct crypto_attr_u32 {
                                                   >> 637         u32 num;
                                                   >> 638 };
                                                   >> 639 
440 /*                                                640 /* 
441  * Transform user interface.                      641  * Transform user interface.
442  */                                               642  */
443                                                   643  
444 struct crypto_tfm *crypto_alloc_base(const cha    644 struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask);
445 void crypto_destroy_tfm(void *mem, struct cryp    645 void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm);
446                                                   646 
447 static inline void crypto_free_tfm(struct cryp    647 static inline void crypto_free_tfm(struct crypto_tfm *tfm)
448 {                                                 648 {
449         return crypto_destroy_tfm(tfm, tfm);      649         return crypto_destroy_tfm(tfm, tfm);
450 }                                                 650 }
451                                                   651 
                                                   >> 652 int alg_test(const char *driver, const char *alg, u32 type, u32 mask);
                                                   >> 653 
452 /*                                                654 /*
453  * Transform helpers which query the underlyin    655  * Transform helpers which query the underlying algorithm.
454  */                                               656  */
455 static inline const char *crypto_tfm_alg_name(    657 static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm)
456 {                                                 658 {
457         return tfm->__crt_alg->cra_name;          659         return tfm->__crt_alg->cra_name;
458 }                                                 660 }
459                                                   661 
460 static inline const char *crypto_tfm_alg_drive    662 static inline const char *crypto_tfm_alg_driver_name(struct crypto_tfm *tfm)
461 {                                                 663 {
462         return tfm->__crt_alg->cra_driver_name    664         return tfm->__crt_alg->cra_driver_name;
463 }                                                 665 }
464                                                   666 
                                                   >> 667 static inline int crypto_tfm_alg_priority(struct crypto_tfm *tfm)
                                                   >> 668 {
                                                   >> 669         return tfm->__crt_alg->cra_priority;
                                                   >> 670 }
                                                   >> 671 
                                                   >> 672 static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm)
                                                   >> 673 {
                                                   >> 674         return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK;
                                                   >> 675 }
                                                   >> 676 
465 static inline unsigned int crypto_tfm_alg_bloc    677 static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm)
466 {                                                 678 {
467         return tfm->__crt_alg->cra_blocksize;     679         return tfm->__crt_alg->cra_blocksize;
468 }                                                 680 }
469                                                   681 
470 static inline unsigned int crypto_tfm_alg_alig    682 static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
471 {                                                 683 {
472         return tfm->__crt_alg->cra_alignmask;     684         return tfm->__crt_alg->cra_alignmask;
473 }                                                 685 }
474                                                   686 
475 static inline u32 crypto_tfm_get_flags(struct     687 static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm)
476 {                                                 688 {
477         return tfm->crt_flags;                    689         return tfm->crt_flags;
478 }                                                 690 }
479                                                   691 
480 static inline void crypto_tfm_set_flags(struct    692 static inline void crypto_tfm_set_flags(struct crypto_tfm *tfm, u32 flags)
481 {                                                 693 {
482         tfm->crt_flags |= flags;                  694         tfm->crt_flags |= flags;
483 }                                                 695 }
484                                                   696 
485 static inline void crypto_tfm_clear_flags(stru    697 static inline void crypto_tfm_clear_flags(struct crypto_tfm *tfm, u32 flags)
486 {                                                 698 {
487         tfm->crt_flags &= ~flags;                 699         tfm->crt_flags &= ~flags;
488 }                                                 700 }
489                                                   701 
                                                   >> 702 static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
                                                   >> 703 {
                                                   >> 704         return tfm->__crt_ctx;
                                                   >> 705 }
                                                   >> 706 
490 static inline unsigned int crypto_tfm_ctx_alig    707 static inline unsigned int crypto_tfm_ctx_alignment(void)
491 {                                                 708 {
492         struct crypto_tfm *tfm;                   709         struct crypto_tfm *tfm;
493         return __alignof__(tfm->__crt_ctx);       710         return __alignof__(tfm->__crt_ctx);
494 }                                                 711 }
495                                                   712 
                                                   >> 713 /*
                                                   >> 714  * API wrappers.
                                                   >> 715  */
                                                   >> 716 static inline struct crypto_ablkcipher *__crypto_ablkcipher_cast(
                                                   >> 717         struct crypto_tfm *tfm)
                                                   >> 718 {
                                                   >> 719         return (struct crypto_ablkcipher *)tfm;
                                                   >> 720 }
                                                   >> 721 
                                                   >> 722 static inline u32 crypto_skcipher_type(u32 type)
                                                   >> 723 {
                                                   >> 724         type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
                                                   >> 725         type |= CRYPTO_ALG_TYPE_BLKCIPHER;
                                                   >> 726         return type;
                                                   >> 727 }
                                                   >> 728 
                                                   >> 729 static inline u32 crypto_skcipher_mask(u32 mask)
                                                   >> 730 {
                                                   >> 731         mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
                                                   >> 732         mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
                                                   >> 733         return mask;
                                                   >> 734 }
                                                   >> 735 
                                                   >> 736 /**
                                                   >> 737  * DOC: Asynchronous Block Cipher API
                                                   >> 738  *
                                                   >> 739  * Asynchronous block cipher API is used with the ciphers of type
                                                   >> 740  * CRYPTO_ALG_TYPE_ABLKCIPHER (listed as type "ablkcipher" in /proc/crypto).
                                                   >> 741  *
                                                   >> 742  * Asynchronous cipher operations imply that the function invocation for a
                                                   >> 743  * cipher request returns immediately before the completion of the operation.
                                                   >> 744  * The cipher request is scheduled as a separate kernel thread and therefore
                                                   >> 745  * load-balanced on the different CPUs via the process scheduler. To allow
                                                   >> 746  * the kernel crypto API to inform the caller about the completion of a cipher
                                                   >> 747  * request, the caller must provide a callback function. That function is
                                                   >> 748  * invoked with the cipher handle when the request completes.
                                                   >> 749  *
                                                   >> 750  * To support the asynchronous operation, additional information than just the
                                                   >> 751  * cipher handle must be supplied to the kernel crypto API. That additional
                                                   >> 752  * information is given by filling in the ablkcipher_request data structure.
                                                   >> 753  *
                                                   >> 754  * For the asynchronous block cipher API, the state is maintained with the tfm
                                                   >> 755  * cipher handle. A single tfm can be used across multiple calls and in
                                                   >> 756  * parallel. For asynchronous block cipher calls, context data supplied and
                                                   >> 757  * only used by the caller can be referenced the request data structure in
                                                   >> 758  * addition to the IV used for the cipher request. The maintenance of such
                                                   >> 759  * state information would be important for a crypto driver implementer to
                                                   >> 760  * have, because when calling the callback function upon completion of the
                                                   >> 761  * cipher operation, that callback function may need some information about
                                                   >> 762  * which operation just finished if it invoked multiple in parallel. This
                                                   >> 763  * state information is unused by the kernel crypto API.
                                                   >> 764  */
                                                   >> 765 
                                                   >> 766 static inline struct crypto_tfm *crypto_ablkcipher_tfm(
                                                   >> 767         struct crypto_ablkcipher *tfm)
                                                   >> 768 {
                                                   >> 769         return &tfm->base;
                                                   >> 770 }
                                                   >> 771 
                                                   >> 772 /**
                                                   >> 773  * crypto_free_ablkcipher() - zeroize and free cipher handle
                                                   >> 774  * @tfm: cipher handle to be freed
                                                   >> 775  */
                                                   >> 776 static inline void crypto_free_ablkcipher(struct crypto_ablkcipher *tfm)
                                                   >> 777 {
                                                   >> 778         crypto_free_tfm(crypto_ablkcipher_tfm(tfm));
                                                   >> 779 }
                                                   >> 780 
                                                   >> 781 /**
                                                   >> 782  * crypto_has_ablkcipher() - Search for the availability of an ablkcipher.
                                                   >> 783  * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
                                                   >> 784  *            ablkcipher
                                                   >> 785  * @type: specifies the type of the cipher
                                                   >> 786  * @mask: specifies the mask for the cipher
                                                   >> 787  *
                                                   >> 788  * Return: true when the ablkcipher is known to the kernel crypto API; false
                                                   >> 789  *         otherwise
                                                   >> 790  */
                                                   >> 791 static inline int crypto_has_ablkcipher(const char *alg_name, u32 type,
                                                   >> 792                                         u32 mask)
                                                   >> 793 {
                                                   >> 794         return crypto_has_alg(alg_name, crypto_skcipher_type(type),
                                                   >> 795                               crypto_skcipher_mask(mask));
                                                   >> 796 }
                                                   >> 797 
                                                   >> 798 static inline struct ablkcipher_tfm *crypto_ablkcipher_crt(
                                                   >> 799         struct crypto_ablkcipher *tfm)
                                                   >> 800 {
                                                   >> 801         return &crypto_ablkcipher_tfm(tfm)->crt_ablkcipher;
                                                   >> 802 }
                                                   >> 803 
                                                   >> 804 /**
                                                   >> 805  * crypto_ablkcipher_ivsize() - obtain IV size
                                                   >> 806  * @tfm: cipher handle
                                                   >> 807  *
                                                   >> 808  * The size of the IV for the ablkcipher referenced by the cipher handle is
                                                   >> 809  * returned. This IV size may be zero if the cipher does not need an IV.
                                                   >> 810  *
                                                   >> 811  * Return: IV size in bytes
                                                   >> 812  */
                                                   >> 813 static inline unsigned int crypto_ablkcipher_ivsize(
                                                   >> 814         struct crypto_ablkcipher *tfm)
                                                   >> 815 {
                                                   >> 816         return crypto_ablkcipher_crt(tfm)->ivsize;
                                                   >> 817 }
                                                   >> 818 
                                                   >> 819 /**
                                                   >> 820  * crypto_ablkcipher_blocksize() - obtain block size of cipher
                                                   >> 821  * @tfm: cipher handle
                                                   >> 822  *
                                                   >> 823  * The block size for the ablkcipher referenced with the cipher handle is
                                                   >> 824  * returned. The caller may use that information to allocate appropriate
                                                   >> 825  * memory for the data returned by the encryption or decryption operation
                                                   >> 826  *
                                                   >> 827  * Return: block size of cipher
                                                   >> 828  */
                                                   >> 829 static inline unsigned int crypto_ablkcipher_blocksize(
                                                   >> 830         struct crypto_ablkcipher *tfm)
                                                   >> 831 {
                                                   >> 832         return crypto_tfm_alg_blocksize(crypto_ablkcipher_tfm(tfm));
                                                   >> 833 }
                                                   >> 834 
                                                   >> 835 static inline unsigned int crypto_ablkcipher_alignmask(
                                                   >> 836         struct crypto_ablkcipher *tfm)
                                                   >> 837 {
                                                   >> 838         return crypto_tfm_alg_alignmask(crypto_ablkcipher_tfm(tfm));
                                                   >> 839 }
                                                   >> 840 
                                                   >> 841 static inline u32 crypto_ablkcipher_get_flags(struct crypto_ablkcipher *tfm)
                                                   >> 842 {
                                                   >> 843         return crypto_tfm_get_flags(crypto_ablkcipher_tfm(tfm));
                                                   >> 844 }
                                                   >> 845 
                                                   >> 846 static inline void crypto_ablkcipher_set_flags(struct crypto_ablkcipher *tfm,
                                                   >> 847                                                u32 flags)
                                                   >> 848 {
                                                   >> 849         crypto_tfm_set_flags(crypto_ablkcipher_tfm(tfm), flags);
                                                   >> 850 }
                                                   >> 851 
                                                   >> 852 static inline void crypto_ablkcipher_clear_flags(struct crypto_ablkcipher *tfm,
                                                   >> 853                                                  u32 flags)
                                                   >> 854 {
                                                   >> 855         crypto_tfm_clear_flags(crypto_ablkcipher_tfm(tfm), flags);
                                                   >> 856 }
                                                   >> 857 
                                                   >> 858 /**
                                                   >> 859  * crypto_ablkcipher_setkey() - set key for cipher
                                                   >> 860  * @tfm: cipher handle
                                                   >> 861  * @key: buffer holding the key
                                                   >> 862  * @keylen: length of the key in bytes
                                                   >> 863  *
                                                   >> 864  * The caller provided key is set for the ablkcipher referenced by the cipher
                                                   >> 865  * handle.
                                                   >> 866  *
                                                   >> 867  * Note, the key length determines the cipher type. Many block ciphers implement
                                                   >> 868  * different cipher modes depending on the key size, such as AES-128 vs AES-192
                                                   >> 869  * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
                                                   >> 870  * is performed.
                                                   >> 871  *
                                                   >> 872  * Return: 0 if the setting of the key was successful; < 0 if an error occurred
                                                   >> 873  */
                                                   >> 874 static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm,
                                                   >> 875                                            const u8 *key, unsigned int keylen)
                                                   >> 876 {
                                                   >> 877         struct ablkcipher_tfm *crt = crypto_ablkcipher_crt(tfm);
                                                   >> 878 
                                                   >> 879         return crt->setkey(crt->base, key, keylen);
                                                   >> 880 }
                                                   >> 881 
                                                   >> 882 /**
                                                   >> 883  * crypto_ablkcipher_reqtfm() - obtain cipher handle from request
                                                   >> 884  * @req: ablkcipher_request out of which the cipher handle is to be obtained
                                                   >> 885  *
                                                   >> 886  * Return the crypto_ablkcipher handle when furnishing an ablkcipher_request
                                                   >> 887  * data structure.
                                                   >> 888  *
                                                   >> 889  * Return: crypto_ablkcipher handle
                                                   >> 890  */
                                                   >> 891 static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm(
                                                   >> 892         struct ablkcipher_request *req)
                                                   >> 893 {
                                                   >> 894         return __crypto_ablkcipher_cast(req->base.tfm);
                                                   >> 895 }
                                                   >> 896 
                                                   >> 897 /**
                                                   >> 898  * crypto_ablkcipher_encrypt() - encrypt plaintext
                                                   >> 899  * @req: reference to the ablkcipher_request handle that holds all information
                                                   >> 900  *       needed to perform the cipher operation
                                                   >> 901  *
                                                   >> 902  * Encrypt plaintext data using the ablkcipher_request handle. That data
                                                   >> 903  * structure and how it is filled with data is discussed with the
                                                   >> 904  * ablkcipher_request_* functions.
                                                   >> 905  *
                                                   >> 906  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
                                                   >> 907  */
                                                   >> 908 static inline int crypto_ablkcipher_encrypt(struct ablkcipher_request *req)
                                                   >> 909 {
                                                   >> 910         struct ablkcipher_tfm *crt =
                                                   >> 911                 crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
                                                   >> 912         return crt->encrypt(req);
                                                   >> 913 }
                                                   >> 914 
                                                   >> 915 /**
                                                   >> 916  * crypto_ablkcipher_decrypt() - decrypt ciphertext
                                                   >> 917  * @req: reference to the ablkcipher_request handle that holds all information
                                                   >> 918  *       needed to perform the cipher operation
                                                   >> 919  *
                                                   >> 920  * Decrypt ciphertext data using the ablkcipher_request handle. That data
                                                   >> 921  * structure and how it is filled with data is discussed with the
                                                   >> 922  * ablkcipher_request_* functions.
                                                   >> 923  *
                                                   >> 924  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
                                                   >> 925  */
                                                   >> 926 static inline int crypto_ablkcipher_decrypt(struct ablkcipher_request *req)
                                                   >> 927 {
                                                   >> 928         struct ablkcipher_tfm *crt =
                                                   >> 929                 crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
                                                   >> 930         return crt->decrypt(req);
                                                   >> 931 }
                                                   >> 932 
                                                   >> 933 /**
                                                   >> 934  * DOC: Asynchronous Cipher Request Handle
                                                   >> 935  *
                                                   >> 936  * The ablkcipher_request data structure contains all pointers to data
                                                   >> 937  * required for the asynchronous cipher operation. This includes the cipher
                                                   >> 938  * handle (which can be used by multiple ablkcipher_request instances), pointer
                                                   >> 939  * to plaintext and ciphertext, asynchronous callback function, etc. It acts
                                                   >> 940  * as a handle to the ablkcipher_request_* API calls in a similar way as
                                                   >> 941  * ablkcipher handle to the crypto_ablkcipher_* API calls.
                                                   >> 942  */
                                                   >> 943 
                                                   >> 944 /**
                                                   >> 945  * crypto_ablkcipher_reqsize() - obtain size of the request data structure
                                                   >> 946  * @tfm: cipher handle
                                                   >> 947  *
                                                   >> 948  * Return: number of bytes
                                                   >> 949  */
                                                   >> 950 static inline unsigned int crypto_ablkcipher_reqsize(
                                                   >> 951         struct crypto_ablkcipher *tfm)
                                                   >> 952 {
                                                   >> 953         return crypto_ablkcipher_crt(tfm)->reqsize;
                                                   >> 954 }
                                                   >> 955 
                                                   >> 956 /**
                                                   >> 957  * ablkcipher_request_set_tfm() - update cipher handle reference in request
                                                   >> 958  * @req: request handle to be modified
                                                   >> 959  * @tfm: cipher handle that shall be added to the request handle
                                                   >> 960  *
                                                   >> 961  * Allow the caller to replace the existing ablkcipher handle in the request
                                                   >> 962  * data structure with a different one.
                                                   >> 963  */
                                                   >> 964 static inline void ablkcipher_request_set_tfm(
                                                   >> 965         struct ablkcipher_request *req, struct crypto_ablkcipher *tfm)
                                                   >> 966 {
                                                   >> 967         req->base.tfm = crypto_ablkcipher_tfm(crypto_ablkcipher_crt(tfm)->base);
                                                   >> 968 }
                                                   >> 969 
                                                   >> 970 static inline struct ablkcipher_request *ablkcipher_request_cast(
                                                   >> 971         struct crypto_async_request *req)
                                                   >> 972 {
                                                   >> 973         return container_of(req, struct ablkcipher_request, base);
                                                   >> 974 }
                                                   >> 975 
                                                   >> 976 /**
                                                   >> 977  * ablkcipher_request_alloc() - allocate request data structure
                                                   >> 978  * @tfm: cipher handle to be registered with the request
                                                   >> 979  * @gfp: memory allocation flag that is handed to kmalloc by the API call.
                                                   >> 980  *
                                                   >> 981  * Allocate the request data structure that must be used with the ablkcipher
                                                   >> 982  * encrypt and decrypt API calls. During the allocation, the provided ablkcipher
                                                   >> 983  * handle is registered in the request data structure.
                                                   >> 984  *
                                                   >> 985  * Return: allocated request handle in case of success, or NULL if out of memory
                                                   >> 986  */
                                                   >> 987 static inline struct ablkcipher_request *ablkcipher_request_alloc(
                                                   >> 988         struct crypto_ablkcipher *tfm, gfp_t gfp)
                                                   >> 989 {
                                                   >> 990         struct ablkcipher_request *req;
                                                   >> 991 
                                                   >> 992         req = kmalloc(sizeof(struct ablkcipher_request) +
                                                   >> 993                       crypto_ablkcipher_reqsize(tfm), gfp);
                                                   >> 994 
                                                   >> 995         if (likely(req))
                                                   >> 996                 ablkcipher_request_set_tfm(req, tfm);
                                                   >> 997 
                                                   >> 998         return req;
                                                   >> 999 }
                                                   >> 1000 
                                                   >> 1001 /**
                                                   >> 1002  * ablkcipher_request_free() - zeroize and free request data structure
                                                   >> 1003  * @req: request data structure cipher handle to be freed
                                                   >> 1004  */
                                                   >> 1005 static inline void ablkcipher_request_free(struct ablkcipher_request *req)
                                                   >> 1006 {
                                                   >> 1007         kzfree(req);
                                                   >> 1008 }
                                                   >> 1009 
                                                   >> 1010 /**
                                                   >> 1011  * ablkcipher_request_set_callback() - set asynchronous callback function
                                                   >> 1012  * @req: request handle
                                                   >> 1013  * @flags: specify zero or an ORing of the flags
                                                   >> 1014  *         CRYPTO_TFM_REQ_MAY_BACKLOG the request queue may back log and
                                                   >> 1015  *         increase the wait queue beyond the initial maximum size;
                                                   >> 1016  *         CRYPTO_TFM_REQ_MAY_SLEEP the request processing may sleep
                                                   >> 1017  * @compl: callback function pointer to be registered with the request handle
                                                   >> 1018  * @data: The data pointer refers to memory that is not used by the kernel
                                                   >> 1019  *        crypto API, but provided to the callback function for it to use. Here,
                                                   >> 1020  *        the caller can provide a reference to memory the callback function can
                                                   >> 1021  *        operate on. As the callback function is invoked asynchronously to the
                                                   >> 1022  *        related functionality, it may need to access data structures of the
                                                   >> 1023  *        related functionality which can be referenced using this pointer. The
                                                   >> 1024  *        callback function can access the memory via the "data" field in the
                                                   >> 1025  *        crypto_async_request data structure provided to the callback function.
                                                   >> 1026  *
                                                   >> 1027  * This function allows setting the callback function that is triggered once the
                                                   >> 1028  * cipher operation completes.
                                                   >> 1029  *
                                                   >> 1030  * The callback function is registered with the ablkcipher_request handle and
                                                   >> 1031  * must comply with the following template::
                                                   >> 1032  *
                                                   >> 1033  *      void callback_function(struct crypto_async_request *req, int error)
                                                   >> 1034  */
                                                   >> 1035 static inline void ablkcipher_request_set_callback(
                                                   >> 1036         struct ablkcipher_request *req,
                                                   >> 1037         u32 flags, crypto_completion_t compl, void *data)
                                                   >> 1038 {
                                                   >> 1039         req->base.complete = compl;
                                                   >> 1040         req->base.data = data;
                                                   >> 1041         req->base.flags = flags;
                                                   >> 1042 }
                                                   >> 1043 
                                                   >> 1044 /**
                                                   >> 1045  * ablkcipher_request_set_crypt() - set data buffers
                                                   >> 1046  * @req: request handle
                                                   >> 1047  * @src: source scatter / gather list
                                                   >> 1048  * @dst: destination scatter / gather list
                                                   >> 1049  * @nbytes: number of bytes to process from @src
                                                   >> 1050  * @iv: IV for the cipher operation which must comply with the IV size defined
                                                   >> 1051  *      by crypto_ablkcipher_ivsize
                                                   >> 1052  *
                                                   >> 1053  * This function allows setting of the source data and destination data
                                                   >> 1054  * scatter / gather lists.
                                                   >> 1055  *
                                                   >> 1056  * For encryption, the source is treated as the plaintext and the
                                                   >> 1057  * destination is the ciphertext. For a decryption operation, the use is
                                                   >> 1058  * reversed - the source is the ciphertext and the destination is the plaintext.
                                                   >> 1059  */
                                                   >> 1060 static inline void ablkcipher_request_set_crypt(
                                                   >> 1061         struct ablkcipher_request *req,
                                                   >> 1062         struct scatterlist *src, struct scatterlist *dst,
                                                   >> 1063         unsigned int nbytes, void *iv)
                                                   >> 1064 {
                                                   >> 1065         req->src = src;
                                                   >> 1066         req->dst = dst;
                                                   >> 1067         req->nbytes = nbytes;
                                                   >> 1068         req->info = iv;
                                                   >> 1069 }
                                                   >> 1070 
                                                   >> 1071 /**
                                                   >> 1072  * DOC: Synchronous Block Cipher API
                                                   >> 1073  *
                                                   >> 1074  * The synchronous block cipher API is used with the ciphers of type
                                                   >> 1075  * CRYPTO_ALG_TYPE_BLKCIPHER (listed as type "blkcipher" in /proc/crypto)
                                                   >> 1076  *
                                                   >> 1077  * Synchronous calls, have a context in the tfm. But since a single tfm can be
                                                   >> 1078  * used in multiple calls and in parallel, this info should not be changeable
                                                   >> 1079  * (unless a lock is used). This applies, for example, to the symmetric key.
                                                   >> 1080  * However, the IV is changeable, so there is an iv field in blkcipher_tfm
                                                   >> 1081  * structure for synchronous blkcipher api. So, its the only state info that can
                                                   >> 1082  * be kept for synchronous calls without using a big lock across a tfm.
                                                   >> 1083  *
                                                   >> 1084  * The block cipher API allows the use of a complete cipher, i.e. a cipher
                                                   >> 1085  * consisting of a template (a block chaining mode) and a single block cipher
                                                   >> 1086  * primitive (e.g. AES).
                                                   >> 1087  *
                                                   >> 1088  * The plaintext data buffer and the ciphertext data buffer are pointed to
                                                   >> 1089  * by using scatter/gather lists. The cipher operation is performed
                                                   >> 1090  * on all segments of the provided scatter/gather lists.
                                                   >> 1091  *
                                                   >> 1092  * The kernel crypto API supports a cipher operation "in-place" which means that
                                                   >> 1093  * the caller may provide the same scatter/gather list for the plaintext and
                                                   >> 1094  * cipher text. After the completion of the cipher operation, the plaintext
                                                   >> 1095  * data is replaced with the ciphertext data in case of an encryption and vice
                                                   >> 1096  * versa for a decryption. The caller must ensure that the scatter/gather lists
                                                   >> 1097  * for the output data point to sufficiently large buffers, i.e. multiples of
                                                   >> 1098  * the block size of the cipher.
                                                   >> 1099  */
                                                   >> 1100 
                                                   >> 1101 static inline struct crypto_blkcipher *__crypto_blkcipher_cast(
                                                   >> 1102         struct crypto_tfm *tfm)
                                                   >> 1103 {
                                                   >> 1104         return (struct crypto_blkcipher *)tfm;
                                                   >> 1105 }
                                                   >> 1106 
                                                   >> 1107 static inline struct crypto_blkcipher *crypto_blkcipher_cast(
                                                   >> 1108         struct crypto_tfm *tfm)
                                                   >> 1109 {
                                                   >> 1110         BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_BLKCIPHER);
                                                   >> 1111         return __crypto_blkcipher_cast(tfm);
                                                   >> 1112 }
                                                   >> 1113 
                                                   >> 1114 /**
                                                   >> 1115  * crypto_alloc_blkcipher() - allocate synchronous block cipher handle
                                                   >> 1116  * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
                                                   >> 1117  *            blkcipher cipher
                                                   >> 1118  * @type: specifies the type of the cipher
                                                   >> 1119  * @mask: specifies the mask for the cipher
                                                   >> 1120  *
                                                   >> 1121  * Allocate a cipher handle for a block cipher. The returned struct
                                                   >> 1122  * crypto_blkcipher is the cipher handle that is required for any subsequent
                                                   >> 1123  * API invocation for that block cipher.
                                                   >> 1124  *
                                                   >> 1125  * Return: allocated cipher handle in case of success; IS_ERR() is true in case
                                                   >> 1126  *         of an error, PTR_ERR() returns the error code.
                                                   >> 1127  */
                                                   >> 1128 static inline struct crypto_blkcipher *crypto_alloc_blkcipher(
                                                   >> 1129         const char *alg_name, u32 type, u32 mask)
                                                   >> 1130 {
                                                   >> 1131         type &= ~CRYPTO_ALG_TYPE_MASK;
                                                   >> 1132         type |= CRYPTO_ALG_TYPE_BLKCIPHER;
                                                   >> 1133         mask |= CRYPTO_ALG_TYPE_MASK;
                                                   >> 1134 
                                                   >> 1135         return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask));
                                                   >> 1136 }
                                                   >> 1137 
                                                   >> 1138 static inline struct crypto_tfm *crypto_blkcipher_tfm(
                                                   >> 1139         struct crypto_blkcipher *tfm)
                                                   >> 1140 {
                                                   >> 1141         return &tfm->base;
                                                   >> 1142 }
                                                   >> 1143 
                                                   >> 1144 /**
                                                   >> 1145  * crypto_free_blkcipher() - zeroize and free the block cipher handle
                                                   >> 1146  * @tfm: cipher handle to be freed
                                                   >> 1147  */
                                                   >> 1148 static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm)
                                                   >> 1149 {
                                                   >> 1150         crypto_free_tfm(crypto_blkcipher_tfm(tfm));
                                                   >> 1151 }
                                                   >> 1152 
                                                   >> 1153 /**
                                                   >> 1154  * crypto_has_blkcipher() - Search for the availability of a block cipher
                                                   >> 1155  * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
                                                   >> 1156  *            block cipher
                                                   >> 1157  * @type: specifies the type of the cipher
                                                   >> 1158  * @mask: specifies the mask for the cipher
                                                   >> 1159  *
                                                   >> 1160  * Return: true when the block cipher is known to the kernel crypto API; false
                                                   >> 1161  *         otherwise
                                                   >> 1162  */
                                                   >> 1163 static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask)
                                                   >> 1164 {
                                                   >> 1165         type &= ~CRYPTO_ALG_TYPE_MASK;
                                                   >> 1166         type |= CRYPTO_ALG_TYPE_BLKCIPHER;
                                                   >> 1167         mask |= CRYPTO_ALG_TYPE_MASK;
                                                   >> 1168 
                                                   >> 1169         return crypto_has_alg(alg_name, type, mask);
                                                   >> 1170 }
                                                   >> 1171 
                                                   >> 1172 /**
                                                   >> 1173  * crypto_blkcipher_name() - return the name / cra_name from the cipher handle
                                                   >> 1174  * @tfm: cipher handle
                                                   >> 1175  *
                                                   >> 1176  * Return: The character string holding the name of the cipher
                                                   >> 1177  */
                                                   >> 1178 static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm)
                                                   >> 1179 {
                                                   >> 1180         return crypto_tfm_alg_name(crypto_blkcipher_tfm(tfm));
                                                   >> 1181 }
                                                   >> 1182 
                                                   >> 1183 static inline struct blkcipher_tfm *crypto_blkcipher_crt(
                                                   >> 1184         struct crypto_blkcipher *tfm)
                                                   >> 1185 {
                                                   >> 1186         return &crypto_blkcipher_tfm(tfm)->crt_blkcipher;
                                                   >> 1187 }
                                                   >> 1188 
                                                   >> 1189 static inline struct blkcipher_alg *crypto_blkcipher_alg(
                                                   >> 1190         struct crypto_blkcipher *tfm)
                                                   >> 1191 {
                                                   >> 1192         return &crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher;
                                                   >> 1193 }
                                                   >> 1194 
                                                   >> 1195 /**
                                                   >> 1196  * crypto_blkcipher_ivsize() - obtain IV size
                                                   >> 1197  * @tfm: cipher handle
                                                   >> 1198  *
                                                   >> 1199  * The size of the IV for the block cipher referenced by the cipher handle is
                                                   >> 1200  * returned. This IV size may be zero if the cipher does not need an IV.
                                                   >> 1201  *
                                                   >> 1202  * Return: IV size in bytes
                                                   >> 1203  */
                                                   >> 1204 static inline unsigned int crypto_blkcipher_ivsize(struct crypto_blkcipher *tfm)
                                                   >> 1205 {
                                                   >> 1206         return crypto_blkcipher_alg(tfm)->ivsize;
                                                   >> 1207 }
                                                   >> 1208 
                                                   >> 1209 /**
                                                   >> 1210  * crypto_blkcipher_blocksize() - obtain block size of cipher
                                                   >> 1211  * @tfm: cipher handle
                                                   >> 1212  *
                                                   >> 1213  * The block size for the block cipher referenced with the cipher handle is
                                                   >> 1214  * returned. The caller may use that information to allocate appropriate
                                                   >> 1215  * memory for the data returned by the encryption or decryption operation.
                                                   >> 1216  *
                                                   >> 1217  * Return: block size of cipher
                                                   >> 1218  */
                                                   >> 1219 static inline unsigned int crypto_blkcipher_blocksize(
                                                   >> 1220         struct crypto_blkcipher *tfm)
                                                   >> 1221 {
                                                   >> 1222         return crypto_tfm_alg_blocksize(crypto_blkcipher_tfm(tfm));
                                                   >> 1223 }
                                                   >> 1224 
                                                   >> 1225 static inline unsigned int crypto_blkcipher_alignmask(
                                                   >> 1226         struct crypto_blkcipher *tfm)
                                                   >> 1227 {
                                                   >> 1228         return crypto_tfm_alg_alignmask(crypto_blkcipher_tfm(tfm));
                                                   >> 1229 }
                                                   >> 1230 
                                                   >> 1231 static inline u32 crypto_blkcipher_get_flags(struct crypto_blkcipher *tfm)
                                                   >> 1232 {
                                                   >> 1233         return crypto_tfm_get_flags(crypto_blkcipher_tfm(tfm));
                                                   >> 1234 }
                                                   >> 1235 
                                                   >> 1236 static inline void crypto_blkcipher_set_flags(struct crypto_blkcipher *tfm,
                                                   >> 1237                                               u32 flags)
                                                   >> 1238 {
                                                   >> 1239         crypto_tfm_set_flags(crypto_blkcipher_tfm(tfm), flags);
                                                   >> 1240 }
                                                   >> 1241 
                                                   >> 1242 static inline void crypto_blkcipher_clear_flags(struct crypto_blkcipher *tfm,
                                                   >> 1243                                                 u32 flags)
                                                   >> 1244 {
                                                   >> 1245         crypto_tfm_clear_flags(crypto_blkcipher_tfm(tfm), flags);
                                                   >> 1246 }
                                                   >> 1247 
                                                   >> 1248 /**
                                                   >> 1249  * crypto_blkcipher_setkey() - set key for cipher
                                                   >> 1250  * @tfm: cipher handle
                                                   >> 1251  * @key: buffer holding the key
                                                   >> 1252  * @keylen: length of the key in bytes
                                                   >> 1253  *
                                                   >> 1254  * The caller provided key is set for the block cipher referenced by the cipher
                                                   >> 1255  * handle.
                                                   >> 1256  *
                                                   >> 1257  * Note, the key length determines the cipher type. Many block ciphers implement
                                                   >> 1258  * different cipher modes depending on the key size, such as AES-128 vs AES-192
                                                   >> 1259  * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
                                                   >> 1260  * is performed.
                                                   >> 1261  *
                                                   >> 1262  * Return: 0 if the setting of the key was successful; < 0 if an error occurred
                                                   >> 1263  */
                                                   >> 1264 static inline int crypto_blkcipher_setkey(struct crypto_blkcipher *tfm,
                                                   >> 1265                                           const u8 *key, unsigned int keylen)
                                                   >> 1266 {
                                                   >> 1267         return crypto_blkcipher_crt(tfm)->setkey(crypto_blkcipher_tfm(tfm),
                                                   >> 1268                                                  key, keylen);
                                                   >> 1269 }
                                                   >> 1270 
                                                   >> 1271 /**
                                                   >> 1272  * crypto_blkcipher_encrypt() - encrypt plaintext
                                                   >> 1273  * @desc: reference to the block cipher handle with meta data
                                                   >> 1274  * @dst: scatter/gather list that is filled by the cipher operation with the
                                                   >> 1275  *      ciphertext
                                                   >> 1276  * @src: scatter/gather list that holds the plaintext
                                                   >> 1277  * @nbytes: number of bytes of the plaintext to encrypt.
                                                   >> 1278  *
                                                   >> 1279  * Encrypt plaintext data using the IV set by the caller with a preceding
                                                   >> 1280  * call of crypto_blkcipher_set_iv.
                                                   >> 1281  *
                                                   >> 1282  * The blkcipher_desc data structure must be filled by the caller and can
                                                   >> 1283  * reside on the stack. The caller must fill desc as follows: desc.tfm is filled
                                                   >> 1284  * with the block cipher handle; desc.flags is filled with either
                                                   >> 1285  * CRYPTO_TFM_REQ_MAY_SLEEP or 0.
                                                   >> 1286  *
                                                   >> 1287  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
                                                   >> 1288  */
                                                   >> 1289 static inline int crypto_blkcipher_encrypt(struct blkcipher_desc *desc,
                                                   >> 1290                                            struct scatterlist *dst,
                                                   >> 1291                                            struct scatterlist *src,
                                                   >> 1292                                            unsigned int nbytes)
                                                   >> 1293 {
                                                   >> 1294         desc->info = crypto_blkcipher_crt(desc->tfm)->iv;
                                                   >> 1295         return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes);
                                                   >> 1296 }
                                                   >> 1297 
                                                   >> 1298 /**
                                                   >> 1299  * crypto_blkcipher_encrypt_iv() - encrypt plaintext with dedicated IV
                                                   >> 1300  * @desc: reference to the block cipher handle with meta data
                                                   >> 1301  * @dst: scatter/gather list that is filled by the cipher operation with the
                                                   >> 1302  *      ciphertext
                                                   >> 1303  * @src: scatter/gather list that holds the plaintext
                                                   >> 1304  * @nbytes: number of bytes of the plaintext to encrypt.
                                                   >> 1305  *
                                                   >> 1306  * Encrypt plaintext data with the use of an IV that is solely used for this
                                                   >> 1307  * cipher operation. Any previously set IV is not used.
                                                   >> 1308  *
                                                   >> 1309  * The blkcipher_desc data structure must be filled by the caller and can
                                                   >> 1310  * reside on the stack. The caller must fill desc as follows: desc.tfm is filled
                                                   >> 1311  * with the block cipher handle; desc.info is filled with the IV to be used for
                                                   >> 1312  * the current operation; desc.flags is filled with either
                                                   >> 1313  * CRYPTO_TFM_REQ_MAY_SLEEP or 0.
                                                   >> 1314  *
                                                   >> 1315  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
                                                   >> 1316  */
                                                   >> 1317 static inline int crypto_blkcipher_encrypt_iv(struct blkcipher_desc *desc,
                                                   >> 1318                                               struct scatterlist *dst,
                                                   >> 1319                                               struct scatterlist *src,
                                                   >> 1320                                               unsigned int nbytes)
                                                   >> 1321 {
                                                   >> 1322         return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes);
                                                   >> 1323 }
                                                   >> 1324 
                                                   >> 1325 /**
                                                   >> 1326  * crypto_blkcipher_decrypt() - decrypt ciphertext
                                                   >> 1327  * @desc: reference to the block cipher handle with meta data
                                                   >> 1328  * @dst: scatter/gather list that is filled by the cipher operation with the
                                                   >> 1329  *      plaintext
                                                   >> 1330  * @src: scatter/gather list that holds the ciphertext
                                                   >> 1331  * @nbytes: number of bytes of the ciphertext to decrypt.
                                                   >> 1332  *
                                                   >> 1333  * Decrypt ciphertext data using the IV set by the caller with a preceding
                                                   >> 1334  * call of crypto_blkcipher_set_iv.
                                                   >> 1335  *
                                                   >> 1336  * The blkcipher_desc data structure must be filled by the caller as documented
                                                   >> 1337  * for the crypto_blkcipher_encrypt call above.
                                                   >> 1338  *
                                                   >> 1339  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
                                                   >> 1340  *
                                                   >> 1341  */
                                                   >> 1342 static inline int crypto_blkcipher_decrypt(struct blkcipher_desc *desc,
                                                   >> 1343                                            struct scatterlist *dst,
                                                   >> 1344                                            struct scatterlist *src,
                                                   >> 1345                                            unsigned int nbytes)
                                                   >> 1346 {
                                                   >> 1347         desc->info = crypto_blkcipher_crt(desc->tfm)->iv;
                                                   >> 1348         return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes);
                                                   >> 1349 }
                                                   >> 1350 
                                                   >> 1351 /**
                                                   >> 1352  * crypto_blkcipher_decrypt_iv() - decrypt ciphertext with dedicated IV
                                                   >> 1353  * @desc: reference to the block cipher handle with meta data
                                                   >> 1354  * @dst: scatter/gather list that is filled by the cipher operation with the
                                                   >> 1355  *      plaintext
                                                   >> 1356  * @src: scatter/gather list that holds the ciphertext
                                                   >> 1357  * @nbytes: number of bytes of the ciphertext to decrypt.
                                                   >> 1358  *
                                                   >> 1359  * Decrypt ciphertext data with the use of an IV that is solely used for this
                                                   >> 1360  * cipher operation. Any previously set IV is not used.
                                                   >> 1361  *
                                                   >> 1362  * The blkcipher_desc data structure must be filled by the caller as documented
                                                   >> 1363  * for the crypto_blkcipher_encrypt_iv call above.
                                                   >> 1364  *
                                                   >> 1365  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
                                                   >> 1366  */
                                                   >> 1367 static inline int crypto_blkcipher_decrypt_iv(struct blkcipher_desc *desc,
                                                   >> 1368                                               struct scatterlist *dst,
                                                   >> 1369                                               struct scatterlist *src,
                                                   >> 1370                                               unsigned int nbytes)
                                                   >> 1371 {
                                                   >> 1372         return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes);
                                                   >> 1373 }
                                                   >> 1374 
                                                   >> 1375 /**
                                                   >> 1376  * crypto_blkcipher_set_iv() - set IV for cipher
                                                   >> 1377  * @tfm: cipher handle
                                                   >> 1378  * @src: buffer holding the IV
                                                   >> 1379  * @len: length of the IV in bytes
                                                   >> 1380  *
                                                   >> 1381  * The caller provided IV is set for the block cipher referenced by the cipher
                                                   >> 1382  * handle.
                                                   >> 1383  */
                                                   >> 1384 static inline void crypto_blkcipher_set_iv(struct crypto_blkcipher *tfm,
                                                   >> 1385                                            const u8 *src, unsigned int len)
                                                   >> 1386 {
                                                   >> 1387         memcpy(crypto_blkcipher_crt(tfm)->iv, src, len);
                                                   >> 1388 }
                                                   >> 1389 
                                                   >> 1390 /**
                                                   >> 1391  * crypto_blkcipher_get_iv() - obtain IV from cipher
                                                   >> 1392  * @tfm: cipher handle
                                                   >> 1393  * @dst: buffer filled with the IV
                                                   >> 1394  * @len: length of the buffer dst
                                                   >> 1395  *
                                                   >> 1396  * The caller can obtain the IV set for the block cipher referenced by the
                                                   >> 1397  * cipher handle and store it into the user-provided buffer. If the buffer
                                                   >> 1398  * has an insufficient space, the IV is truncated to fit the buffer.
                                                   >> 1399  */
                                                   >> 1400 static inline void crypto_blkcipher_get_iv(struct crypto_blkcipher *tfm,
                                                   >> 1401                                            u8 *dst, unsigned int len)
                                                   >> 1402 {
                                                   >> 1403         memcpy(dst, crypto_blkcipher_crt(tfm)->iv, len);
                                                   >> 1404 }
                                                   >> 1405 
                                                   >> 1406 /**
                                                   >> 1407  * DOC: Single Block Cipher API
                                                   >> 1408  *
                                                   >> 1409  * The single block cipher API is used with the ciphers of type
                                                   >> 1410  * CRYPTO_ALG_TYPE_CIPHER (listed as type "cipher" in /proc/crypto).
                                                   >> 1411  *
                                                   >> 1412  * Using the single block cipher API calls, operations with the basic cipher
                                                   >> 1413  * primitive can be implemented. These cipher primitives exclude any block
                                                   >> 1414  * chaining operations including IV handling.
                                                   >> 1415  *
                                                   >> 1416  * The purpose of this single block cipher API is to support the implementation
                                                   >> 1417  * of templates or other concepts that only need to perform the cipher operation
                                                   >> 1418  * on one block at a time. Templates invoke the underlying cipher primitive
                                                   >> 1419  * block-wise and process either the input or the output data of these cipher
                                                   >> 1420  * operations.
                                                   >> 1421  */
                                                   >> 1422 
                                                   >> 1423 static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm)
                                                   >> 1424 {
                                                   >> 1425         return (struct crypto_cipher *)tfm;
                                                   >> 1426 }
                                                   >> 1427 
                                                   >> 1428 static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm)
                                                   >> 1429 {
                                                   >> 1430         BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
                                                   >> 1431         return __crypto_cipher_cast(tfm);
                                                   >> 1432 }
                                                   >> 1433 
                                                   >> 1434 /**
                                                   >> 1435  * crypto_alloc_cipher() - allocate single block cipher handle
                                                   >> 1436  * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
                                                   >> 1437  *           single block cipher
                                                   >> 1438  * @type: specifies the type of the cipher
                                                   >> 1439  * @mask: specifies the mask for the cipher
                                                   >> 1440  *
                                                   >> 1441  * Allocate a cipher handle for a single block cipher. The returned struct
                                                   >> 1442  * crypto_cipher is the cipher handle that is required for any subsequent API
                                                   >> 1443  * invocation for that single block cipher.
                                                   >> 1444  *
                                                   >> 1445  * Return: allocated cipher handle in case of success; IS_ERR() is true in case
                                                   >> 1446  *         of an error, PTR_ERR() returns the error code.
                                                   >> 1447  */
                                                   >> 1448 static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name,
                                                   >> 1449                                                         u32 type, u32 mask)
                                                   >> 1450 {
                                                   >> 1451         type &= ~CRYPTO_ALG_TYPE_MASK;
                                                   >> 1452         type |= CRYPTO_ALG_TYPE_CIPHER;
                                                   >> 1453         mask |= CRYPTO_ALG_TYPE_MASK;
                                                   >> 1454 
                                                   >> 1455         return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask));
                                                   >> 1456 }
                                                   >> 1457 
                                                   >> 1458 static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm)
                                                   >> 1459 {
                                                   >> 1460         return &tfm->base;
                                                   >> 1461 }
                                                   >> 1462 
                                                   >> 1463 /**
                                                   >> 1464  * crypto_free_cipher() - zeroize and free the single block cipher handle
                                                   >> 1465  * @tfm: cipher handle to be freed
                                                   >> 1466  */
                                                   >> 1467 static inline void crypto_free_cipher(struct crypto_cipher *tfm)
                                                   >> 1468 {
                                                   >> 1469         crypto_free_tfm(crypto_cipher_tfm(tfm));
                                                   >> 1470 }
                                                   >> 1471 
                                                   >> 1472 /**
                                                   >> 1473  * crypto_has_cipher() - Search for the availability of a single block cipher
                                                   >> 1474  * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
                                                   >> 1475  *           single block cipher
                                                   >> 1476  * @type: specifies the type of the cipher
                                                   >> 1477  * @mask: specifies the mask for the cipher
                                                   >> 1478  *
                                                   >> 1479  * Return: true when the single block cipher is known to the kernel crypto API;
                                                   >> 1480  *         false otherwise
                                                   >> 1481  */
                                                   >> 1482 static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask)
                                                   >> 1483 {
                                                   >> 1484         type &= ~CRYPTO_ALG_TYPE_MASK;
                                                   >> 1485         type |= CRYPTO_ALG_TYPE_CIPHER;
                                                   >> 1486         mask |= CRYPTO_ALG_TYPE_MASK;
                                                   >> 1487 
                                                   >> 1488         return crypto_has_alg(alg_name, type, mask);
                                                   >> 1489 }
                                                   >> 1490 
                                                   >> 1491 static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm)
                                                   >> 1492 {
                                                   >> 1493         return &crypto_cipher_tfm(tfm)->crt_cipher;
                                                   >> 1494 }
                                                   >> 1495 
                                                   >> 1496 /**
                                                   >> 1497  * crypto_cipher_blocksize() - obtain block size for cipher
                                                   >> 1498  * @tfm: cipher handle
                                                   >> 1499  *
                                                   >> 1500  * The block size for the single block cipher referenced with the cipher handle
                                                   >> 1501  * tfm is returned. The caller may use that information to allocate appropriate
                                                   >> 1502  * memory for the data returned by the encryption or decryption operation
                                                   >> 1503  *
                                                   >> 1504  * Return: block size of cipher
                                                   >> 1505  */
                                                   >> 1506 static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm)
                                                   >> 1507 {
                                                   >> 1508         return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm));
                                                   >> 1509 }
                                                   >> 1510 
                                                   >> 1511 static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm)
                                                   >> 1512 {
                                                   >> 1513         return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm));
                                                   >> 1514 }
                                                   >> 1515 
                                                   >> 1516 static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm)
                                                   >> 1517 {
                                                   >> 1518         return crypto_tfm_get_flags(crypto_cipher_tfm(tfm));
                                                   >> 1519 }
                                                   >> 1520 
                                                   >> 1521 static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm,
                                                   >> 1522                                            u32 flags)
                                                   >> 1523 {
                                                   >> 1524         crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags);
                                                   >> 1525 }
                                                   >> 1526 
                                                   >> 1527 static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm,
                                                   >> 1528                                              u32 flags)
                                                   >> 1529 {
                                                   >> 1530         crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags);
                                                   >> 1531 }
                                                   >> 1532 
                                                   >> 1533 /**
                                                   >> 1534  * crypto_cipher_setkey() - set key for cipher
                                                   >> 1535  * @tfm: cipher handle
                                                   >> 1536  * @key: buffer holding the key
                                                   >> 1537  * @keylen: length of the key in bytes
                                                   >> 1538  *
                                                   >> 1539  * The caller provided key is set for the single block cipher referenced by the
                                                   >> 1540  * cipher handle.
                                                   >> 1541  *
                                                   >> 1542  * Note, the key length determines the cipher type. Many block ciphers implement
                                                   >> 1543  * different cipher modes depending on the key size, such as AES-128 vs AES-192
                                                   >> 1544  * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
                                                   >> 1545  * is performed.
                                                   >> 1546  *
                                                   >> 1547  * Return: 0 if the setting of the key was successful; < 0 if an error occurred
                                                   >> 1548  */
                                                   >> 1549 static inline int crypto_cipher_setkey(struct crypto_cipher *tfm,
                                                   >> 1550                                        const u8 *key, unsigned int keylen)
                                                   >> 1551 {
                                                   >> 1552         return crypto_cipher_crt(tfm)->cit_setkey(crypto_cipher_tfm(tfm),
                                                   >> 1553                                                   key, keylen);
                                                   >> 1554 }
                                                   >> 1555 
                                                   >> 1556 /**
                                                   >> 1557  * crypto_cipher_encrypt_one() - encrypt one block of plaintext
                                                   >> 1558  * @tfm: cipher handle
                                                   >> 1559  * @dst: points to the buffer that will be filled with the ciphertext
                                                   >> 1560  * @src: buffer holding the plaintext to be encrypted
                                                   >> 1561  *
                                                   >> 1562  * Invoke the encryption operation of one block. The caller must ensure that
                                                   >> 1563  * the plaintext and ciphertext buffers are at least one block in size.
                                                   >> 1564  */
                                                   >> 1565 static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
                                                   >> 1566                                              u8 *dst, const u8 *src)
                                                   >> 1567 {
                                                   >> 1568         crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm),
                                                   >> 1569                                                 dst, src);
                                                   >> 1570 }
                                                   >> 1571 
                                                   >> 1572 /**
                                                   >> 1573  * crypto_cipher_decrypt_one() - decrypt one block of ciphertext
                                                   >> 1574  * @tfm: cipher handle
                                                   >> 1575  * @dst: points to the buffer that will be filled with the plaintext
                                                   >> 1576  * @src: buffer holding the ciphertext to be decrypted
                                                   >> 1577  *
                                                   >> 1578  * Invoke the decryption operation of one block. The caller must ensure that
                                                   >> 1579  * the plaintext and ciphertext buffers are at least one block in size.
                                                   >> 1580  */
                                                   >> 1581 static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
                                                   >> 1582                                              u8 *dst, const u8 *src)
                                                   >> 1583 {
                                                   >> 1584         crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm),
                                                   >> 1585                                                 dst, src);
                                                   >> 1586 }
                                                   >> 1587 
496 static inline struct crypto_comp *__crypto_com    1588 static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm)
497 {                                                 1589 {
498         return (struct crypto_comp *)tfm;         1590         return (struct crypto_comp *)tfm;
499 }                                                 1591 }
500                                                   1592 
                                                   >> 1593 static inline struct crypto_comp *crypto_comp_cast(struct crypto_tfm *tfm)
                                                   >> 1594 {
                                                   >> 1595         BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_COMPRESS) &
                                                   >> 1596                CRYPTO_ALG_TYPE_MASK);
                                                   >> 1597         return __crypto_comp_cast(tfm);
                                                   >> 1598 }
                                                   >> 1599 
501 static inline struct crypto_comp *crypto_alloc    1600 static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name,
502                                                   1601                                                     u32 type, u32 mask)
503 {                                                 1602 {
504         type &= ~CRYPTO_ALG_TYPE_MASK;            1603         type &= ~CRYPTO_ALG_TYPE_MASK;
505         type |= CRYPTO_ALG_TYPE_COMPRESS;         1604         type |= CRYPTO_ALG_TYPE_COMPRESS;
506         mask |= CRYPTO_ALG_TYPE_MASK;             1605         mask |= CRYPTO_ALG_TYPE_MASK;
507                                                   1606 
508         return __crypto_comp_cast(crypto_alloc    1607         return __crypto_comp_cast(crypto_alloc_base(alg_name, type, mask));
509 }                                                 1608 }
510                                                   1609 
511 static inline struct crypto_tfm *crypto_comp_t    1610 static inline struct crypto_tfm *crypto_comp_tfm(struct crypto_comp *tfm)
512 {                                                 1611 {
513         return &tfm->base;                        1612         return &tfm->base;
514 }                                                 1613 }
515                                                   1614 
516 static inline void crypto_free_comp(struct cry    1615 static inline void crypto_free_comp(struct crypto_comp *tfm)
517 {                                                 1616 {
518         crypto_free_tfm(crypto_comp_tfm(tfm));    1617         crypto_free_tfm(crypto_comp_tfm(tfm));
519 }                                                 1618 }
520                                                   1619 
521 static inline int crypto_has_comp(const char *    1620 static inline int crypto_has_comp(const char *alg_name, u32 type, u32 mask)
522 {                                                 1621 {
523         type &= ~CRYPTO_ALG_TYPE_MASK;            1622         type &= ~CRYPTO_ALG_TYPE_MASK;
524         type |= CRYPTO_ALG_TYPE_COMPRESS;         1623         type |= CRYPTO_ALG_TYPE_COMPRESS;
525         mask |= CRYPTO_ALG_TYPE_MASK;             1624         mask |= CRYPTO_ALG_TYPE_MASK;
526                                                   1625 
527         return crypto_has_alg(alg_name, type,     1626         return crypto_has_alg(alg_name, type, mask);
528 }                                                 1627 }
529                                                   1628 
530 static inline const char *crypto_comp_name(str    1629 static inline const char *crypto_comp_name(struct crypto_comp *tfm)
531 {                                                 1630 {
532         return crypto_tfm_alg_name(crypto_comp    1631         return crypto_tfm_alg_name(crypto_comp_tfm(tfm));
533 }                                                 1632 }
534                                                   1633 
535 int crypto_comp_compress(struct crypto_comp *t !! 1634 static inline struct compress_tfm *crypto_comp_crt(struct crypto_comp *tfm)
536                          const u8 *src, unsign !! 1635 {
537                          u8 *dst, unsigned int !! 1636         return &crypto_comp_tfm(tfm)->crt_compress;
538                                                !! 1637 }
539 int crypto_comp_decompress(struct crypto_comp  !! 1638 
540                            const u8 *src, unsi !! 1639 static inline int crypto_comp_compress(struct crypto_comp *tfm,
541                            u8 *dst, unsigned i !! 1640                                        const u8 *src, unsigned int slen,
                                                   >> 1641                                        u8 *dst, unsigned int *dlen)
                                                   >> 1642 {
                                                   >> 1643         return crypto_comp_crt(tfm)->cot_compress(crypto_comp_tfm(tfm),
                                                   >> 1644                                                   src, slen, dst, dlen);
                                                   >> 1645 }
                                                   >> 1646 
                                                   >> 1647 static inline int crypto_comp_decompress(struct crypto_comp *tfm,
                                                   >> 1648                                          const u8 *src, unsigned int slen,
                                                   >> 1649                                          u8 *dst, unsigned int *dlen)
                                                   >> 1650 {
                                                   >> 1651         return crypto_comp_crt(tfm)->cot_decompress(crypto_comp_tfm(tfm),
                                                   >> 1652                                                     src, slen, dst, dlen);
                                                   >> 1653 }
542                                                   1654 
543 #endif  /* _LINUX_CRYPTO_H */                     1655 #endif  /* _LINUX_CRYPTO_H */
544                                                   1656 
545                                                   1657 

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