diff options
Diffstat (limited to 'include/linux/crypto.h')
| -rw-r--r-- | include/linux/crypto.h | 723 |
1 files changed, 625 insertions, 98 deletions
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 5a0470e36111..8f2ffa4caabf 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
| @@ -17,20 +17,36 @@ | |||
| 17 | #ifndef _LINUX_CRYPTO_H | 17 | #ifndef _LINUX_CRYPTO_H |
| 18 | #define _LINUX_CRYPTO_H | 18 | #define _LINUX_CRYPTO_H |
| 19 | 19 | ||
| 20 | #include <asm/atomic.h> | ||
| 20 | #include <linux/module.h> | 21 | #include <linux/module.h> |
| 21 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
| 22 | #include <linux/types.h> | ||
| 23 | #include <linux/list.h> | 23 | #include <linux/list.h> |
| 24 | #include <linux/slab.h> | ||
| 24 | #include <linux/string.h> | 25 | #include <linux/string.h> |
| 25 | #include <asm/page.h> | 26 | #include <linux/uaccess.h> |
| 26 | 27 | ||
| 27 | /* | 28 | /* |
| 28 | * Algorithm masks and types. | 29 | * Algorithm masks and types. |
| 29 | */ | 30 | */ |
| 30 | #define CRYPTO_ALG_TYPE_MASK 0x000000ff | 31 | #define CRYPTO_ALG_TYPE_MASK 0x0000000f |
| 31 | #define CRYPTO_ALG_TYPE_CIPHER 0x00000001 | 32 | #define CRYPTO_ALG_TYPE_CIPHER 0x00000001 |
| 32 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000002 | 33 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000002 |
| 33 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000004 | 34 | #define CRYPTO_ALG_TYPE_HASH 0x00000003 |
| 35 | #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 | ||
| 36 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000005 | ||
| 37 | |||
| 38 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e | ||
| 39 | |||
| 40 | #define CRYPTO_ALG_LARVAL 0x00000010 | ||
| 41 | #define CRYPTO_ALG_DEAD 0x00000020 | ||
| 42 | #define CRYPTO_ALG_DYING 0x00000040 | ||
| 43 | #define CRYPTO_ALG_ASYNC 0x00000080 | ||
| 44 | |||
| 45 | /* | ||
| 46 | * Set this bit if and only if the algorithm requires another algorithm of | ||
| 47 | * the same type to handle corner cases. | ||
| 48 | */ | ||
| 49 | #define CRYPTO_ALG_NEED_FALLBACK 0x00000100 | ||
| 34 | 50 | ||
| 35 | /* | 51 | /* |
| 36 | * Transform masks and values (for crt_flags). | 52 | * Transform masks and values (for crt_flags). |
| @@ -61,82 +77,156 @@ | |||
| 61 | #define CRYPTO_DIR_ENCRYPT 1 | 77 | #define CRYPTO_DIR_ENCRYPT 1 |
| 62 | #define CRYPTO_DIR_DECRYPT 0 | 78 | #define CRYPTO_DIR_DECRYPT 0 |
| 63 | 79 | ||
| 80 | /* | ||
| 81 | * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual | ||
| 82 | * declaration) is used to ensure that the crypto_tfm context structure is | ||
| 83 | * aligned correctly for the given architecture so that there are no alignment | ||
| 84 | * faults for C data types. In particular, this is required on platforms such | ||
| 85 | * as arm where pointers are 32-bit aligned but there are data types such as | ||
| 86 | * u64 which require 64-bit alignment. | ||
| 87 | */ | ||
| 88 | #if defined(ARCH_KMALLOC_MINALIGN) | ||
| 89 | #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN | ||
| 90 | #elif defined(ARCH_SLAB_MINALIGN) | ||
| 91 | #define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN | ||
| 92 | #endif | ||
| 93 | |||
| 94 | #ifdef CRYPTO_MINALIGN | ||
| 95 | #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN))) | ||
| 96 | #else | ||
| 97 | #define CRYPTO_MINALIGN_ATTR | ||
| 98 | #endif | ||
| 99 | |||
| 64 | struct scatterlist; | 100 | struct scatterlist; |
| 101 | struct crypto_blkcipher; | ||
| 102 | struct crypto_hash; | ||
| 65 | struct crypto_tfm; | 103 | struct crypto_tfm; |
| 104 | struct crypto_type; | ||
| 105 | |||
| 106 | struct blkcipher_desc { | ||
| 107 | struct crypto_blkcipher *tfm; | ||
| 108 | void *info; | ||
| 109 | u32 flags; | ||
| 110 | }; | ||
| 66 | 111 | ||
| 67 | struct cipher_desc { | 112 | struct cipher_desc { |
| 68 | struct crypto_tfm *tfm; | 113 | struct crypto_tfm *tfm; |
| 69 | void (*crfn)(void *ctx, u8 *dst, const u8 *src); | 114 | void (*crfn)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
| 70 | unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst, | 115 | unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst, |
| 71 | const u8 *src, unsigned int nbytes); | 116 | const u8 *src, unsigned int nbytes); |
| 72 | void *info; | 117 | void *info; |
| 73 | }; | 118 | }; |
| 74 | 119 | ||
| 120 | struct hash_desc { | ||
| 121 | struct crypto_hash *tfm; | ||
| 122 | u32 flags; | ||
| 123 | }; | ||
| 124 | |||
| 75 | /* | 125 | /* |
| 76 | * Algorithms: modular crypto algorithm implementations, managed | 126 | * Algorithms: modular crypto algorithm implementations, managed |
| 77 | * via crypto_register_alg() and crypto_unregister_alg(). | 127 | * via crypto_register_alg() and crypto_unregister_alg(). |
| 78 | */ | 128 | */ |
| 129 | struct blkcipher_alg { | ||
| 130 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, | ||
| 131 | unsigned int keylen); | ||
| 132 | int (*encrypt)(struct blkcipher_desc *desc, | ||
| 133 | struct scatterlist *dst, struct scatterlist *src, | ||
| 134 | unsigned int nbytes); | ||
| 135 | int (*decrypt)(struct blkcipher_desc *desc, | ||
| 136 | struct scatterlist *dst, struct scatterlist *src, | ||
| 137 | unsigned int nbytes); | ||
| 138 | |||
| 139 | unsigned int min_keysize; | ||
| 140 | unsigned int max_keysize; | ||
| 141 | unsigned int ivsize; | ||
| 142 | }; | ||
| 143 | |||
| 79 | struct cipher_alg { | 144 | struct cipher_alg { |
| 80 | unsigned int cia_min_keysize; | 145 | unsigned int cia_min_keysize; |
| 81 | unsigned int cia_max_keysize; | 146 | unsigned int cia_max_keysize; |
| 82 | int (*cia_setkey)(void *ctx, const u8 *key, | 147 | int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key, |
| 83 | unsigned int keylen, u32 *flags); | 148 | unsigned int keylen); |
| 84 | void (*cia_encrypt)(void *ctx, u8 *dst, const u8 *src); | 149 | void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
| 85 | void (*cia_decrypt)(void *ctx, u8 *dst, const u8 *src); | 150 | void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
| 86 | 151 | ||
| 87 | unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc, | 152 | unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc, |
| 88 | u8 *dst, const u8 *src, | 153 | u8 *dst, const u8 *src, |
| 89 | unsigned int nbytes); | 154 | unsigned int nbytes) __deprecated; |
| 90 | unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc, | 155 | unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc, |
| 91 | u8 *dst, const u8 *src, | 156 | u8 *dst, const u8 *src, |
| 92 | unsigned int nbytes); | 157 | unsigned int nbytes) __deprecated; |
| 93 | unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc, | 158 | unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc, |
| 94 | u8 *dst, const u8 *src, | 159 | u8 *dst, const u8 *src, |
| 95 | unsigned int nbytes); | 160 | unsigned int nbytes) __deprecated; |
| 96 | unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc, | 161 | unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc, |
| 97 | u8 *dst, const u8 *src, | 162 | u8 *dst, const u8 *src, |
| 98 | unsigned int nbytes); | 163 | unsigned int nbytes) __deprecated; |
| 99 | }; | 164 | }; |
| 100 | 165 | ||
| 101 | struct digest_alg { | 166 | struct digest_alg { |
| 102 | unsigned int dia_digestsize; | 167 | unsigned int dia_digestsize; |
| 103 | void (*dia_init)(void *ctx); | 168 | void (*dia_init)(struct crypto_tfm *tfm); |
| 104 | void (*dia_update)(void *ctx, const u8 *data, unsigned int len); | 169 | void (*dia_update)(struct crypto_tfm *tfm, const u8 *data, |
| 105 | void (*dia_final)(void *ctx, u8 *out); | 170 | unsigned int len); |
| 106 | int (*dia_setkey)(void *ctx, const u8 *key, | 171 | void (*dia_final)(struct crypto_tfm *tfm, u8 *out); |
| 107 | unsigned int keylen, u32 *flags); | 172 | int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key, |
| 173 | unsigned int keylen); | ||
| 174 | }; | ||
| 175 | |||
| 176 | struct hash_alg { | ||
| 177 | int (*init)(struct hash_desc *desc); | ||
| 178 | int (*update)(struct hash_desc *desc, struct scatterlist *sg, | ||
| 179 | unsigned int nbytes); | ||
| 180 | int (*final)(struct hash_desc *desc, u8 *out); | ||
| 181 | int (*digest)(struct hash_desc *desc, struct scatterlist *sg, | ||
| 182 | unsigned int nbytes, u8 *out); | ||
| 183 | int (*setkey)(struct crypto_hash *tfm, const u8 *key, | ||
| 184 | unsigned int keylen); | ||
| 185 | |||
| 186 | unsigned int digestsize; | ||
| 108 | }; | 187 | }; |
| 109 | 188 | ||
| 110 | struct compress_alg { | 189 | struct compress_alg { |
| 111 | int (*coa_init)(void *ctx); | 190 | int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src, |
| 112 | void (*coa_exit)(void *ctx); | 191 | unsigned int slen, u8 *dst, unsigned int *dlen); |
| 113 | int (*coa_compress)(void *ctx, const u8 *src, unsigned int slen, | 192 | int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src, |
| 114 | u8 *dst, unsigned int *dlen); | 193 | unsigned int slen, u8 *dst, unsigned int *dlen); |
| 115 | int (*coa_decompress)(void *ctx, const u8 *src, unsigned int slen, | ||
| 116 | u8 *dst, unsigned int *dlen); | ||
| 117 | }; | 194 | }; |
| 118 | 195 | ||
| 196 | #define cra_blkcipher cra_u.blkcipher | ||
| 119 | #define cra_cipher cra_u.cipher | 197 | #define cra_cipher cra_u.cipher |
| 120 | #define cra_digest cra_u.digest | 198 | #define cra_digest cra_u.digest |
| 199 | #define cra_hash cra_u.hash | ||
| 121 | #define cra_compress cra_u.compress | 200 | #define cra_compress cra_u.compress |
| 122 | 201 | ||
| 123 | struct crypto_alg { | 202 | struct crypto_alg { |
| 124 | struct list_head cra_list; | 203 | struct list_head cra_list; |
| 204 | struct list_head cra_users; | ||
| 205 | |||
| 125 | u32 cra_flags; | 206 | u32 cra_flags; |
| 126 | unsigned int cra_blocksize; | 207 | unsigned int cra_blocksize; |
| 127 | unsigned int cra_ctxsize; | 208 | unsigned int cra_ctxsize; |
| 128 | unsigned int cra_alignmask; | 209 | unsigned int cra_alignmask; |
| 129 | 210 | ||
| 130 | int cra_priority; | 211 | int cra_priority; |
| 212 | atomic_t cra_refcnt; | ||
| 131 | 213 | ||
| 132 | const char cra_name[CRYPTO_MAX_ALG_NAME]; | 214 | char cra_name[CRYPTO_MAX_ALG_NAME]; |
| 133 | const char cra_driver_name[CRYPTO_MAX_ALG_NAME]; | 215 | char cra_driver_name[CRYPTO_MAX_ALG_NAME]; |
| 216 | |||
| 217 | const struct crypto_type *cra_type; | ||
| 134 | 218 | ||
| 135 | union { | 219 | union { |
| 220 | struct blkcipher_alg blkcipher; | ||
| 136 | struct cipher_alg cipher; | 221 | struct cipher_alg cipher; |
| 137 | struct digest_alg digest; | 222 | struct digest_alg digest; |
| 223 | struct hash_alg hash; | ||
| 138 | struct compress_alg compress; | 224 | struct compress_alg compress; |
| 139 | } cra_u; | 225 | } cra_u; |
| 226 | |||
| 227 | int (*cra_init)(struct crypto_tfm *tfm); | ||
| 228 | void (*cra_exit)(struct crypto_tfm *tfm); | ||
| 229 | void (*cra_destroy)(struct crypto_alg *alg); | ||
| 140 | 230 | ||
| 141 | struct module *cra_module; | 231 | struct module *cra_module; |
| 142 | }; | 232 | }; |
| @@ -151,20 +241,39 @@ int crypto_unregister_alg(struct crypto_alg *alg); | |||
| 151 | * Algorithm query interface. | 241 | * Algorithm query interface. |
| 152 | */ | 242 | */ |
| 153 | #ifdef CONFIG_CRYPTO | 243 | #ifdef CONFIG_CRYPTO |
| 154 | int crypto_alg_available(const char *name, u32 flags); | 244 | int crypto_alg_available(const char *name, u32 flags) |
| 245 | __deprecated_for_modules; | ||
| 246 | int crypto_has_alg(const char *name, u32 type, u32 mask); | ||
| 155 | #else | 247 | #else |
| 248 | static int crypto_alg_available(const char *name, u32 flags); | ||
| 249 | __deprecated_for_modules; | ||
| 156 | static inline int crypto_alg_available(const char *name, u32 flags) | 250 | static inline int crypto_alg_available(const char *name, u32 flags) |
| 157 | { | 251 | { |
| 158 | return 0; | 252 | return 0; |
| 159 | } | 253 | } |
| 254 | |||
| 255 | static inline int crypto_has_alg(const char *name, u32 type, u32 mask) | ||
| 256 | { | ||
| 257 | return 0; | ||
| 258 | } | ||
| 160 | #endif | 259 | #endif |
| 161 | 260 | ||
| 162 | /* | 261 | /* |
| 163 | * Transforms: user-instantiated objects which encapsulate algorithms | 262 | * Transforms: user-instantiated objects which encapsulate algorithms |
| 164 | * and core processing logic. Managed via crypto_alloc_tfm() and | 263 | * and core processing logic. Managed via crypto_alloc_*() and |
| 165 | * crypto_free_tfm(), as well as the various helpers below. | 264 | * crypto_free_*(), as well as the various helpers below. |
| 166 | */ | 265 | */ |
| 167 | 266 | ||
| 267 | struct blkcipher_tfm { | ||
| 268 | void *iv; | ||
| 269 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, | ||
| 270 | unsigned int keylen); | ||
| 271 | int (*encrypt)(struct blkcipher_desc *desc, struct scatterlist *dst, | ||
| 272 | struct scatterlist *src, unsigned int nbytes); | ||
| 273 | int (*decrypt)(struct blkcipher_desc *desc, struct scatterlist *dst, | ||
| 274 | struct scatterlist *src, unsigned int nbytes); | ||
| 275 | }; | ||
| 276 | |||
| 168 | struct cipher_tfm { | 277 | struct cipher_tfm { |
| 169 | void *cit_iv; | 278 | void *cit_iv; |
| 170 | unsigned int cit_ivsize; | 279 | unsigned int cit_ivsize; |
| @@ -188,20 +297,20 @@ struct cipher_tfm { | |||
| 188 | struct scatterlist *src, | 297 | struct scatterlist *src, |
| 189 | unsigned int nbytes, u8 *iv); | 298 | unsigned int nbytes, u8 *iv); |
| 190 | void (*cit_xor_block)(u8 *dst, const u8 *src); | 299 | void (*cit_xor_block)(u8 *dst, const u8 *src); |
| 300 | void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); | ||
| 301 | void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); | ||
| 191 | }; | 302 | }; |
| 192 | 303 | ||
| 193 | struct digest_tfm { | 304 | struct hash_tfm { |
| 194 | void (*dit_init)(struct crypto_tfm *tfm); | 305 | int (*init)(struct hash_desc *desc); |
| 195 | void (*dit_update)(struct crypto_tfm *tfm, | 306 | int (*update)(struct hash_desc *desc, |
| 196 | struct scatterlist *sg, unsigned int nsg); | 307 | struct scatterlist *sg, unsigned int nsg); |
| 197 | void (*dit_final)(struct crypto_tfm *tfm, u8 *out); | 308 | int (*final)(struct hash_desc *desc, u8 *out); |
| 198 | void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg, | 309 | int (*digest)(struct hash_desc *desc, struct scatterlist *sg, |
| 199 | unsigned int nsg, u8 *out); | 310 | unsigned int nsg, u8 *out); |
| 200 | int (*dit_setkey)(struct crypto_tfm *tfm, | 311 | int (*setkey)(struct crypto_hash *tfm, const u8 *key, |
| 201 | const u8 *key, unsigned int keylen); | 312 | unsigned int keylen); |
| 202 | #ifdef CONFIG_CRYPTO_HMAC | 313 | unsigned int digestsize; |
| 203 | void *dit_hmac_block; | ||
| 204 | #endif | ||
| 205 | }; | 314 | }; |
| 206 | 315 | ||
| 207 | struct compress_tfm { | 316 | struct compress_tfm { |
| @@ -213,8 +322,9 @@ struct compress_tfm { | |||
| 213 | u8 *dst, unsigned int *dlen); | 322 | u8 *dst, unsigned int *dlen); |
| 214 | }; | 323 | }; |
| 215 | 324 | ||
| 325 | #define crt_blkcipher crt_u.blkcipher | ||
| 216 | #define crt_cipher crt_u.cipher | 326 | #define crt_cipher crt_u.cipher |
| 217 | #define crt_digest crt_u.digest | 327 | #define crt_hash crt_u.hash |
| 218 | #define crt_compress crt_u.compress | 328 | #define crt_compress crt_u.compress |
| 219 | 329 | ||
| 220 | struct crypto_tfm { | 330 | struct crypto_tfm { |
| @@ -222,30 +332,43 @@ struct crypto_tfm { | |||
| 222 | u32 crt_flags; | 332 | u32 crt_flags; |
| 223 | 333 | ||
| 224 | union { | 334 | union { |
| 335 | struct blkcipher_tfm blkcipher; | ||
| 225 | struct cipher_tfm cipher; | 336 | struct cipher_tfm cipher; |
| 226 | struct digest_tfm digest; | 337 | struct hash_tfm hash; |
| 227 | struct compress_tfm compress; | 338 | struct compress_tfm compress; |
| 228 | } crt_u; | 339 | } crt_u; |
| 229 | 340 | ||
| 230 | struct crypto_alg *__crt_alg; | 341 | struct crypto_alg *__crt_alg; |
| 231 | 342 | ||
| 232 | char __crt_ctx[] __attribute__ ((__aligned__)); | 343 | void *__crt_ctx[] CRYPTO_MINALIGN_ATTR; |
| 344 | }; | ||
| 345 | |||
| 346 | #define crypto_cipher crypto_tfm | ||
| 347 | #define crypto_comp crypto_tfm | ||
| 348 | |||
| 349 | struct crypto_blkcipher { | ||
| 350 | struct crypto_tfm base; | ||
| 351 | }; | ||
| 352 | |||
| 353 | struct crypto_hash { | ||
| 354 | struct crypto_tfm base; | ||
| 355 | }; | ||
| 356 | |||
| 357 | enum { | ||
| 358 | CRYPTOA_UNSPEC, | ||
| 359 | CRYPTOA_ALG, | ||
| 360 | }; | ||
| 361 | |||
| 362 | struct crypto_attr_alg { | ||
| 363 | char name[CRYPTO_MAX_ALG_NAME]; | ||
| 233 | }; | 364 | }; |
| 234 | 365 | ||
| 235 | /* | 366 | /* |
| 236 | * Transform user interface. | 367 | * Transform user interface. |
| 237 | */ | 368 | */ |
| 238 | 369 | ||
| 239 | /* | ||
| 240 | * crypto_alloc_tfm() will first attempt to locate an already loaded algorithm. | ||
| 241 | * If that fails and the kernel supports dynamically loadable modules, it | ||
| 242 | * will then attempt to load a module of the same name or alias. A refcount | ||
| 243 | * is grabbed on the algorithm which is then associated with the new transform. | ||
| 244 | * | ||
| 245 | * crypto_free_tfm() frees up the transform and any associated resources, | ||
| 246 | * then drops the refcount on the associated algorithm. | ||
| 247 | */ | ||
| 248 | struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags); | 370 | struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags); |
| 371 | struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask); | ||
| 249 | void crypto_free_tfm(struct crypto_tfm *tfm); | 372 | void crypto_free_tfm(struct crypto_tfm *tfm); |
| 250 | 373 | ||
| 251 | /* | 374 | /* |
| @@ -256,6 +379,16 @@ static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm) | |||
| 256 | return tfm->__crt_alg->cra_name; | 379 | return tfm->__crt_alg->cra_name; |
| 257 | } | 380 | } |
| 258 | 381 | ||
| 382 | static inline const char *crypto_tfm_alg_driver_name(struct crypto_tfm *tfm) | ||
| 383 | { | ||
| 384 | return tfm->__crt_alg->cra_driver_name; | ||
| 385 | } | ||
| 386 | |||
| 387 | static inline int crypto_tfm_alg_priority(struct crypto_tfm *tfm) | ||
| 388 | { | ||
| 389 | return tfm->__crt_alg->cra_priority; | ||
| 390 | } | ||
| 391 | |||
| 259 | static inline const char *crypto_tfm_alg_modname(struct crypto_tfm *tfm) | 392 | static inline const char *crypto_tfm_alg_modname(struct crypto_tfm *tfm) |
| 260 | { | 393 | { |
| 261 | return module_name(tfm->__crt_alg->cra_module); | 394 | return module_name(tfm->__crt_alg->cra_module); |
| @@ -266,18 +399,23 @@ static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm) | |||
| 266 | return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK; | 399 | return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK; |
| 267 | } | 400 | } |
| 268 | 401 | ||
| 402 | static unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm) | ||
| 403 | __deprecated; | ||
| 269 | static inline unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm) | 404 | static inline unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm) |
| 270 | { | 405 | { |
| 271 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 406 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
| 272 | return tfm->__crt_alg->cra_cipher.cia_min_keysize; | 407 | return tfm->__crt_alg->cra_cipher.cia_min_keysize; |
| 273 | } | 408 | } |
| 274 | 409 | ||
| 410 | static unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm) | ||
| 411 | __deprecated; | ||
| 275 | static inline unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm) | 412 | static inline unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm) |
| 276 | { | 413 | { |
| 277 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 414 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
| 278 | return tfm->__crt_alg->cra_cipher.cia_max_keysize; | 415 | return tfm->__crt_alg->cra_cipher.cia_max_keysize; |
| 279 | } | 416 | } |
| 280 | 417 | ||
| 418 | static unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm) __deprecated; | ||
| 281 | static inline unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm) | 419 | static inline unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm) |
| 282 | { | 420 | { |
| 283 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 421 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
| @@ -300,6 +438,21 @@ static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm) | |||
| 300 | return tfm->__crt_alg->cra_alignmask; | 438 | return tfm->__crt_alg->cra_alignmask; |
| 301 | } | 439 | } |
| 302 | 440 | ||
| 441 | static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm) | ||
| 442 | { | ||
| 443 | return tfm->crt_flags; | ||
| 444 | } | ||
| 445 | |||
| 446 | static inline void crypto_tfm_set_flags(struct crypto_tfm *tfm, u32 flags) | ||
| 447 | { | ||
| 448 | tfm->crt_flags |= flags; | ||
| 449 | } | ||
| 450 | |||
| 451 | static inline void crypto_tfm_clear_flags(struct crypto_tfm *tfm, u32 flags) | ||
| 452 | { | ||
| 453 | tfm->crt_flags &= ~flags; | ||
| 454 | } | ||
| 455 | |||
| 303 | static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) | 456 | static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) |
| 304 | { | 457 | { |
| 305 | return tfm->__crt_ctx; | 458 | return tfm->__crt_ctx; |
| @@ -314,50 +467,374 @@ static inline unsigned int crypto_tfm_ctx_alignment(void) | |||
| 314 | /* | 467 | /* |
| 315 | * API wrappers. | 468 | * API wrappers. |
| 316 | */ | 469 | */ |
| 317 | static inline void crypto_digest_init(struct crypto_tfm *tfm) | 470 | static inline struct crypto_blkcipher *__crypto_blkcipher_cast( |
| 471 | struct crypto_tfm *tfm) | ||
| 318 | { | 472 | { |
| 319 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); | 473 | return (struct crypto_blkcipher *)tfm; |
| 320 | tfm->crt_digest.dit_init(tfm); | ||
| 321 | } | 474 | } |
| 322 | 475 | ||
| 323 | static inline void crypto_digest_update(struct crypto_tfm *tfm, | 476 | static inline struct crypto_blkcipher *crypto_blkcipher_cast( |
| 324 | struct scatterlist *sg, | 477 | struct crypto_tfm *tfm) |
| 325 | unsigned int nsg) | ||
| 326 | { | 478 | { |
| 327 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); | 479 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_BLKCIPHER); |
| 328 | tfm->crt_digest.dit_update(tfm, sg, nsg); | 480 | return __crypto_blkcipher_cast(tfm); |
| 329 | } | 481 | } |
| 330 | 482 | ||
| 331 | static inline void crypto_digest_final(struct crypto_tfm *tfm, u8 *out) | 483 | static inline struct crypto_blkcipher *crypto_alloc_blkcipher( |
| 484 | const char *alg_name, u32 type, u32 mask) | ||
| 332 | { | 485 | { |
| 333 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); | 486 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 334 | tfm->crt_digest.dit_final(tfm, out); | 487 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
| 488 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
| 489 | |||
| 490 | return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask)); | ||
| 335 | } | 491 | } |
| 336 | 492 | ||
| 337 | static inline void crypto_digest_digest(struct crypto_tfm *tfm, | 493 | static inline struct crypto_tfm *crypto_blkcipher_tfm( |
| 338 | struct scatterlist *sg, | 494 | struct crypto_blkcipher *tfm) |
| 339 | unsigned int nsg, u8 *out) | ||
| 340 | { | 495 | { |
| 341 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); | 496 | return &tfm->base; |
| 342 | tfm->crt_digest.dit_digest(tfm, sg, nsg, out); | ||
| 343 | } | 497 | } |
| 344 | 498 | ||
| 345 | static inline int crypto_digest_setkey(struct crypto_tfm *tfm, | 499 | static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm) |
| 500 | { | ||
| 501 | crypto_free_tfm(crypto_blkcipher_tfm(tfm)); | ||
| 502 | } | ||
| 503 | |||
| 504 | static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask) | ||
| 505 | { | ||
| 506 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
| 507 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; | ||
| 508 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
| 509 | |||
| 510 | return crypto_has_alg(alg_name, type, mask); | ||
| 511 | } | ||
| 512 | |||
| 513 | static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm) | ||
| 514 | { | ||
| 515 | return crypto_tfm_alg_name(crypto_blkcipher_tfm(tfm)); | ||
| 516 | } | ||
| 517 | |||
| 518 | static inline struct blkcipher_tfm *crypto_blkcipher_crt( | ||
| 519 | struct crypto_blkcipher *tfm) | ||
| 520 | { | ||
| 521 | return &crypto_blkcipher_tfm(tfm)->crt_blkcipher; | ||
| 522 | } | ||
| 523 | |||
| 524 | static inline struct blkcipher_alg *crypto_blkcipher_alg( | ||
| 525 | struct crypto_blkcipher *tfm) | ||
| 526 | { | ||
| 527 | return &crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher; | ||
| 528 | } | ||
| 529 | |||
| 530 | static inline unsigned int crypto_blkcipher_ivsize(struct crypto_blkcipher *tfm) | ||
| 531 | { | ||
| 532 | return crypto_blkcipher_alg(tfm)->ivsize; | ||
| 533 | } | ||
| 534 | |||
| 535 | static inline unsigned int crypto_blkcipher_blocksize( | ||
| 536 | struct crypto_blkcipher *tfm) | ||
| 537 | { | ||
| 538 | return crypto_tfm_alg_blocksize(crypto_blkcipher_tfm(tfm)); | ||
| 539 | } | ||
| 540 | |||
| 541 | static inline unsigned int crypto_blkcipher_alignmask( | ||
| 542 | struct crypto_blkcipher *tfm) | ||
| 543 | { | ||
| 544 | return crypto_tfm_alg_alignmask(crypto_blkcipher_tfm(tfm)); | ||
| 545 | } | ||
| 546 | |||
| 547 | static inline u32 crypto_blkcipher_get_flags(struct crypto_blkcipher *tfm) | ||
| 548 | { | ||
| 549 | return crypto_tfm_get_flags(crypto_blkcipher_tfm(tfm)); | ||
| 550 | } | ||
| 551 | |||
| 552 | static inline void crypto_blkcipher_set_flags(struct crypto_blkcipher *tfm, | ||
| 553 | u32 flags) | ||
| 554 | { | ||
| 555 | crypto_tfm_set_flags(crypto_blkcipher_tfm(tfm), flags); | ||
| 556 | } | ||
| 557 | |||
| 558 | static inline void crypto_blkcipher_clear_flags(struct crypto_blkcipher *tfm, | ||
| 559 | u32 flags) | ||
| 560 | { | ||
| 561 | crypto_tfm_clear_flags(crypto_blkcipher_tfm(tfm), flags); | ||
| 562 | } | ||
| 563 | |||
| 564 | static inline int crypto_blkcipher_setkey(struct crypto_blkcipher *tfm, | ||
| 565 | const u8 *key, unsigned int keylen) | ||
| 566 | { | ||
| 567 | return crypto_blkcipher_crt(tfm)->setkey(crypto_blkcipher_tfm(tfm), | ||
| 568 | key, keylen); | ||
| 569 | } | ||
| 570 | |||
| 571 | static inline int crypto_blkcipher_encrypt(struct blkcipher_desc *desc, | ||
| 572 | struct scatterlist *dst, | ||
| 573 | struct scatterlist *src, | ||
| 574 | unsigned int nbytes) | ||
| 575 | { | ||
| 576 | desc->info = crypto_blkcipher_crt(desc->tfm)->iv; | ||
| 577 | return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes); | ||
| 578 | } | ||
| 579 | |||
| 580 | static inline int crypto_blkcipher_encrypt_iv(struct blkcipher_desc *desc, | ||
| 581 | struct scatterlist *dst, | ||
| 582 | struct scatterlist *src, | ||
| 583 | unsigned int nbytes) | ||
| 584 | { | ||
| 585 | return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes); | ||
| 586 | } | ||
| 587 | |||
| 588 | static inline int crypto_blkcipher_decrypt(struct blkcipher_desc *desc, | ||
| 589 | struct scatterlist *dst, | ||
| 590 | struct scatterlist *src, | ||
| 591 | unsigned int nbytes) | ||
| 592 | { | ||
| 593 | desc->info = crypto_blkcipher_crt(desc->tfm)->iv; | ||
| 594 | return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes); | ||
| 595 | } | ||
| 596 | |||
| 597 | static inline int crypto_blkcipher_decrypt_iv(struct blkcipher_desc *desc, | ||
| 598 | struct scatterlist *dst, | ||
| 599 | struct scatterlist *src, | ||
| 600 | unsigned int nbytes) | ||
| 601 | { | ||
| 602 | return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes); | ||
| 603 | } | ||
| 604 | |||
| 605 | static inline void crypto_blkcipher_set_iv(struct crypto_blkcipher *tfm, | ||
| 606 | const u8 *src, unsigned int len) | ||
| 607 | { | ||
| 608 | memcpy(crypto_blkcipher_crt(tfm)->iv, src, len); | ||
| 609 | } | ||
| 610 | |||
| 611 | static inline void crypto_blkcipher_get_iv(struct crypto_blkcipher *tfm, | ||
| 612 | u8 *dst, unsigned int len) | ||
| 613 | { | ||
| 614 | memcpy(dst, crypto_blkcipher_crt(tfm)->iv, len); | ||
| 615 | } | ||
| 616 | |||
| 617 | static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm) | ||
| 618 | { | ||
| 619 | return (struct crypto_cipher *)tfm; | ||
| 620 | } | ||
| 621 | |||
| 622 | static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm) | ||
| 623 | { | ||
| 624 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | ||
| 625 | return __crypto_cipher_cast(tfm); | ||
| 626 | } | ||
| 627 | |||
| 628 | static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name, | ||
| 629 | u32 type, u32 mask) | ||
| 630 | { | ||
| 631 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
| 632 | type |= CRYPTO_ALG_TYPE_CIPHER; | ||
| 633 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
| 634 | |||
| 635 | return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask)); | ||
| 636 | } | ||
| 637 | |||
| 638 | static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm) | ||
| 639 | { | ||
| 640 | return tfm; | ||
| 641 | } | ||
| 642 | |||
| 643 | static inline void crypto_free_cipher(struct crypto_cipher *tfm) | ||
| 644 | { | ||
| 645 | crypto_free_tfm(crypto_cipher_tfm(tfm)); | ||
| 646 | } | ||
| 647 | |||
| 648 | static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask) | ||
| 649 | { | ||
| 650 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
| 651 | type |= CRYPTO_ALG_TYPE_CIPHER; | ||
| 652 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
| 653 | |||
| 654 | return crypto_has_alg(alg_name, type, mask); | ||
| 655 | } | ||
| 656 | |||
| 657 | static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm) | ||
| 658 | { | ||
| 659 | return &crypto_cipher_tfm(tfm)->crt_cipher; | ||
| 660 | } | ||
| 661 | |||
| 662 | static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm) | ||
| 663 | { | ||
| 664 | return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm)); | ||
| 665 | } | ||
| 666 | |||
| 667 | static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm) | ||
| 668 | { | ||
| 669 | return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm)); | ||
| 670 | } | ||
| 671 | |||
| 672 | static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm) | ||
| 673 | { | ||
| 674 | return crypto_tfm_get_flags(crypto_cipher_tfm(tfm)); | ||
| 675 | } | ||
| 676 | |||
| 677 | static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm, | ||
| 678 | u32 flags) | ||
| 679 | { | ||
| 680 | crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags); | ||
| 681 | } | ||
| 682 | |||
| 683 | static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm, | ||
| 684 | u32 flags) | ||
| 685 | { | ||
| 686 | crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags); | ||
| 687 | } | ||
| 688 | |||
| 689 | static inline int crypto_cipher_setkey(struct crypto_cipher *tfm, | ||
| 346 | const u8 *key, unsigned int keylen) | 690 | const u8 *key, unsigned int keylen) |
| 347 | { | 691 | { |
| 348 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); | 692 | return crypto_cipher_crt(tfm)->cit_setkey(crypto_cipher_tfm(tfm), |
| 349 | if (tfm->crt_digest.dit_setkey == NULL) | 693 | key, keylen); |
| 350 | return -ENOSYS; | 694 | } |
| 351 | return tfm->crt_digest.dit_setkey(tfm, key, keylen); | 695 | |
| 696 | static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm, | ||
| 697 | u8 *dst, const u8 *src) | ||
| 698 | { | ||
| 699 | crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm), | ||
| 700 | dst, src); | ||
| 701 | } | ||
| 702 | |||
| 703 | static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm, | ||
| 704 | u8 *dst, const u8 *src) | ||
| 705 | { | ||
| 706 | crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm), | ||
| 707 | dst, src); | ||
| 352 | } | 708 | } |
| 353 | 709 | ||
| 354 | static inline int crypto_cipher_setkey(struct crypto_tfm *tfm, | 710 | void crypto_digest_init(struct crypto_tfm *tfm) __deprecated_for_modules; |
| 711 | void crypto_digest_update(struct crypto_tfm *tfm, | ||
| 712 | struct scatterlist *sg, unsigned int nsg) | ||
| 713 | __deprecated_for_modules; | ||
| 714 | void crypto_digest_final(struct crypto_tfm *tfm, u8 *out) | ||
| 715 | __deprecated_for_modules; | ||
| 716 | void crypto_digest_digest(struct crypto_tfm *tfm, | ||
| 717 | struct scatterlist *sg, unsigned int nsg, u8 *out) | ||
| 718 | __deprecated_for_modules; | ||
| 719 | |||
| 720 | static inline struct crypto_hash *__crypto_hash_cast(struct crypto_tfm *tfm) | ||
| 721 | { | ||
| 722 | return (struct crypto_hash *)tfm; | ||
| 723 | } | ||
| 724 | |||
| 725 | static inline struct crypto_hash *crypto_hash_cast(struct crypto_tfm *tfm) | ||
| 726 | { | ||
| 727 | BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_HASH) & | ||
| 728 | CRYPTO_ALG_TYPE_HASH_MASK); | ||
| 729 | return __crypto_hash_cast(tfm); | ||
| 730 | } | ||
| 731 | |||
| 732 | static int crypto_digest_setkey(struct crypto_tfm *tfm, const u8 *key, | ||
| 733 | unsigned int keylen) __deprecated; | ||
| 734 | static inline int crypto_digest_setkey(struct crypto_tfm *tfm, | ||
| 355 | const u8 *key, unsigned int keylen) | 735 | const u8 *key, unsigned int keylen) |
| 356 | { | 736 | { |
| 357 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 737 | return tfm->crt_hash.setkey(crypto_hash_cast(tfm), key, keylen); |
| 358 | return tfm->crt_cipher.cit_setkey(tfm, key, keylen); | ||
| 359 | } | 738 | } |
| 360 | 739 | ||
| 740 | static inline struct crypto_hash *crypto_alloc_hash(const char *alg_name, | ||
| 741 | u32 type, u32 mask) | ||
| 742 | { | ||
| 743 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
| 744 | type |= CRYPTO_ALG_TYPE_HASH; | ||
| 745 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; | ||
| 746 | |||
| 747 | return __crypto_hash_cast(crypto_alloc_base(alg_name, type, mask)); | ||
| 748 | } | ||
| 749 | |||
| 750 | static inline struct crypto_tfm *crypto_hash_tfm(struct crypto_hash *tfm) | ||
| 751 | { | ||
| 752 | return &tfm->base; | ||
| 753 | } | ||
| 754 | |||
| 755 | static inline void crypto_free_hash(struct crypto_hash *tfm) | ||
| 756 | { | ||
| 757 | crypto_free_tfm(crypto_hash_tfm(tfm)); | ||
| 758 | } | ||
| 759 | |||
| 760 | static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask) | ||
| 761 | { | ||
| 762 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
| 763 | type |= CRYPTO_ALG_TYPE_HASH; | ||
| 764 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; | ||
| 765 | |||
| 766 | return crypto_has_alg(alg_name, type, mask); | ||
| 767 | } | ||
| 768 | |||
| 769 | static inline struct hash_tfm *crypto_hash_crt(struct crypto_hash *tfm) | ||
| 770 | { | ||
| 771 | return &crypto_hash_tfm(tfm)->crt_hash; | ||
| 772 | } | ||
| 773 | |||
| 774 | static inline unsigned int crypto_hash_blocksize(struct crypto_hash *tfm) | ||
| 775 | { | ||
| 776 | return crypto_tfm_alg_blocksize(crypto_hash_tfm(tfm)); | ||
| 777 | } | ||
| 778 | |||
| 779 | static inline unsigned int crypto_hash_alignmask(struct crypto_hash *tfm) | ||
| 780 | { | ||
| 781 | return crypto_tfm_alg_alignmask(crypto_hash_tfm(tfm)); | ||
| 782 | } | ||
| 783 | |||
| 784 | static inline unsigned int crypto_hash_digestsize(struct crypto_hash *tfm) | ||
| 785 | { | ||
| 786 | return crypto_hash_crt(tfm)->digestsize; | ||
| 787 | } | ||
| 788 | |||
| 789 | static inline u32 crypto_hash_get_flags(struct crypto_hash *tfm) | ||
| 790 | { | ||
| 791 | return crypto_tfm_get_flags(crypto_hash_tfm(tfm)); | ||
| 792 | } | ||
| 793 | |||
| 794 | static inline void crypto_hash_set_flags(struct crypto_hash *tfm, u32 flags) | ||
| 795 | { | ||
| 796 | crypto_tfm_set_flags(crypto_hash_tfm(tfm), flags); | ||
| 797 | } | ||
| 798 | |||
| 799 | static inline void crypto_hash_clear_flags(struct crypto_hash *tfm, u32 flags) | ||
| 800 | { | ||
| 801 | crypto_tfm_clear_flags(crypto_hash_tfm(tfm), flags); | ||
| 802 | } | ||
| 803 | |||
| 804 | static inline int crypto_hash_init(struct hash_desc *desc) | ||
| 805 | { | ||
| 806 | return crypto_hash_crt(desc->tfm)->init(desc); | ||
| 807 | } | ||
| 808 | |||
| 809 | static inline int crypto_hash_update(struct hash_desc *desc, | ||
| 810 | struct scatterlist *sg, | ||
| 811 | unsigned int nbytes) | ||
| 812 | { | ||
| 813 | return crypto_hash_crt(desc->tfm)->update(desc, sg, nbytes); | ||
| 814 | } | ||
| 815 | |||
| 816 | static inline int crypto_hash_final(struct hash_desc *desc, u8 *out) | ||
| 817 | { | ||
| 818 | return crypto_hash_crt(desc->tfm)->final(desc, out); | ||
| 819 | } | ||
| 820 | |||
| 821 | static inline int crypto_hash_digest(struct hash_desc *desc, | ||
| 822 | struct scatterlist *sg, | ||
| 823 | unsigned int nbytes, u8 *out) | ||
| 824 | { | ||
| 825 | return crypto_hash_crt(desc->tfm)->digest(desc, sg, nbytes, out); | ||
| 826 | } | ||
| 827 | |||
| 828 | static inline int crypto_hash_setkey(struct crypto_hash *hash, | ||
| 829 | const u8 *key, unsigned int keylen) | ||
| 830 | { | ||
| 831 | return crypto_hash_crt(hash)->setkey(hash, key, keylen); | ||
| 832 | } | ||
| 833 | |||
| 834 | static int crypto_cipher_encrypt(struct crypto_tfm *tfm, | ||
| 835 | struct scatterlist *dst, | ||
| 836 | struct scatterlist *src, | ||
| 837 | unsigned int nbytes) __deprecated; | ||
| 361 | static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, | 838 | static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, |
| 362 | struct scatterlist *dst, | 839 | struct scatterlist *dst, |
| 363 | struct scatterlist *src, | 840 | struct scatterlist *src, |
| @@ -367,16 +844,23 @@ static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, | |||
| 367 | return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes); | 844 | return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes); |
| 368 | } | 845 | } |
| 369 | 846 | ||
| 847 | static int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, | ||
| 848 | struct scatterlist *dst, | ||
| 849 | struct scatterlist *src, | ||
| 850 | unsigned int nbytes, u8 *iv) __deprecated; | ||
| 370 | static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, | 851 | static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, |
| 371 | struct scatterlist *dst, | 852 | struct scatterlist *dst, |
| 372 | struct scatterlist *src, | 853 | struct scatterlist *src, |
| 373 | unsigned int nbytes, u8 *iv) | 854 | unsigned int nbytes, u8 *iv) |
| 374 | { | 855 | { |
| 375 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 856 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
| 376 | BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB); | ||
| 377 | return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv); | 857 | return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv); |
| 378 | } | 858 | } |
| 379 | 859 | ||
| 860 | static int crypto_cipher_decrypt(struct crypto_tfm *tfm, | ||
| 861 | struct scatterlist *dst, | ||
| 862 | struct scatterlist *src, | ||
| 863 | unsigned int nbytes) __deprecated; | ||
| 380 | static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, | 864 | static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, |
| 381 | struct scatterlist *dst, | 865 | struct scatterlist *dst, |
| 382 | struct scatterlist *src, | 866 | struct scatterlist *src, |
| @@ -386,16 +870,21 @@ static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, | |||
| 386 | return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes); | 870 | return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes); |
| 387 | } | 871 | } |
| 388 | 872 | ||
| 873 | static int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, | ||
| 874 | struct scatterlist *dst, | ||
| 875 | struct scatterlist *src, | ||
| 876 | unsigned int nbytes, u8 *iv) __deprecated; | ||
| 389 | static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, | 877 | static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, |
| 390 | struct scatterlist *dst, | 878 | struct scatterlist *dst, |
| 391 | struct scatterlist *src, | 879 | struct scatterlist *src, |
| 392 | unsigned int nbytes, u8 *iv) | 880 | unsigned int nbytes, u8 *iv) |
| 393 | { | 881 | { |
| 394 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 882 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
| 395 | BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB); | ||
| 396 | return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv); | 883 | return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv); |
| 397 | } | 884 | } |
| 398 | 885 | ||
| 886 | static void crypto_cipher_set_iv(struct crypto_tfm *tfm, | ||
| 887 | const u8 *src, unsigned int len) __deprecated; | ||
| 399 | static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, | 888 | static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, |
| 400 | const u8 *src, unsigned int len) | 889 | const u8 *src, unsigned int len) |
| 401 | { | 890 | { |
| @@ -403,6 +892,8 @@ static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, | |||
| 403 | memcpy(tfm->crt_cipher.cit_iv, src, len); | 892 | memcpy(tfm->crt_cipher.cit_iv, src, len); |
| 404 | } | 893 | } |
| 405 | 894 | ||
| 895 | static void crypto_cipher_get_iv(struct crypto_tfm *tfm, | ||
| 896 | u8 *dst, unsigned int len) __deprecated; | ||
| 406 | static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, | 897 | static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, |
| 407 | u8 *dst, unsigned int len) | 898 | u8 *dst, unsigned int len) |
| 408 | { | 899 | { |
| @@ -410,34 +901,70 @@ static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, | |||
| 410 | memcpy(dst, tfm->crt_cipher.cit_iv, len); | 901 | memcpy(dst, tfm->crt_cipher.cit_iv, len); |
| 411 | } | 902 | } |
| 412 | 903 | ||
| 413 | static inline int crypto_comp_compress(struct crypto_tfm *tfm, | 904 | static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm) |
| 905 | { | ||
| 906 | return (struct crypto_comp *)tfm; | ||
| 907 | } | ||
| 908 | |||
| 909 | static inline struct crypto_comp *crypto_comp_cast(struct crypto_tfm *tfm) | ||
| 910 | { | ||
| 911 | BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_COMPRESS) & | ||
| 912 | CRYPTO_ALG_TYPE_MASK); | ||
| 913 | return __crypto_comp_cast(tfm); | ||
| 914 | } | ||
| 915 | |||
| 916 | static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name, | ||
| 917 | u32 type, u32 mask) | ||
| 918 | { | ||
| 919 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
| 920 | type |= CRYPTO_ALG_TYPE_COMPRESS; | ||
| 921 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
| 922 | |||
| 923 | return __crypto_comp_cast(crypto_alloc_base(alg_name, type, mask)); | ||
| 924 | } | ||
| 925 | |||
| 926 | static inline struct crypto_tfm *crypto_comp_tfm(struct crypto_comp *tfm) | ||
| 927 | { | ||
| 928 | return tfm; | ||
| 929 | } | ||
| 930 | |||
| 931 | static inline void crypto_free_comp(struct crypto_comp *tfm) | ||
| 932 | { | ||
| 933 | crypto_free_tfm(crypto_comp_tfm(tfm)); | ||
| 934 | } | ||
| 935 | |||
| 936 | static inline int crypto_has_comp(const char *alg_name, u32 type, u32 mask) | ||
| 937 | { | ||
| 938 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
| 939 | type |= CRYPTO_ALG_TYPE_COMPRESS; | ||
| 940 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
| 941 | |||
| 942 | return crypto_has_alg(alg_name, type, mask); | ||
| 943 | } | ||
| 944 | |||
| 945 | static inline const char *crypto_comp_name(struct crypto_comp *tfm) | ||
| 946 | { | ||
| 947 | return crypto_tfm_alg_name(crypto_comp_tfm(tfm)); | ||
| 948 | } | ||
| 949 | |||
| 950 | static inline struct compress_tfm *crypto_comp_crt(struct crypto_comp *tfm) | ||
| 951 | { | ||
| 952 | return &crypto_comp_tfm(tfm)->crt_compress; | ||
| 953 | } | ||
| 954 | |||
| 955 | static inline int crypto_comp_compress(struct crypto_comp *tfm, | ||
| 414 | const u8 *src, unsigned int slen, | 956 | const u8 *src, unsigned int slen, |
| 415 | u8 *dst, unsigned int *dlen) | 957 | u8 *dst, unsigned int *dlen) |
| 416 | { | 958 | { |
| 417 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS); | 959 | return crypto_comp_crt(tfm)->cot_compress(tfm, src, slen, dst, dlen); |
| 418 | return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen); | ||
| 419 | } | 960 | } |
| 420 | 961 | ||
| 421 | static inline int crypto_comp_decompress(struct crypto_tfm *tfm, | 962 | static inline int crypto_comp_decompress(struct crypto_comp *tfm, |
| 422 | const u8 *src, unsigned int slen, | 963 | const u8 *src, unsigned int slen, |
| 423 | u8 *dst, unsigned int *dlen) | 964 | u8 *dst, unsigned int *dlen) |
| 424 | { | 965 | { |
| 425 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS); | 966 | return crypto_comp_crt(tfm)->cot_decompress(tfm, src, slen, dst, dlen); |
| 426 | return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen); | ||
| 427 | } | 967 | } |
| 428 | 968 | ||
| 429 | /* | ||
| 430 | * HMAC support. | ||
| 431 | */ | ||
| 432 | #ifdef CONFIG_CRYPTO_HMAC | ||
| 433 | void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen); | ||
| 434 | void crypto_hmac_update(struct crypto_tfm *tfm, | ||
| 435 | struct scatterlist *sg, unsigned int nsg); | ||
| 436 | void crypto_hmac_final(struct crypto_tfm *tfm, u8 *key, | ||
| 437 | unsigned int *keylen, u8 *out); | ||
| 438 | void crypto_hmac(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen, | ||
| 439 | struct scatterlist *sg, unsigned int nsg, u8 *out); | ||
| 440 | #endif /* CONFIG_CRYPTO_HMAC */ | ||
| 441 | |||
| 442 | #endif /* _LINUX_CRYPTO_H */ | 969 | #endif /* _LINUX_CRYPTO_H */ |
| 443 | 970 | ||
