Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Scatterlist Cryptographic API. |
| 3 | * |
| 4 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
| 5 | * Copyright (c) 2002 David S. Miller (davem@redhat.com) |
Herbert Xu | 5cb1454 | 2005-11-05 16:58:14 +1100 | [diff] [blame] | 6 | * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * Portions derived from Cryptoapi, by Alexander Kjeldaas <astor@fast.no> |
John Anthony Kazos Jr | 18735dd | 2007-10-19 23:07:36 +0200 | [diff] [blame] | 9 | * and Nettle, by Niels Möller. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
| 16 | */ |
| 17 | #ifndef _LINUX_CRYPTO_H |
| 18 | #define _LINUX_CRYPTO_H |
| 19 | |
Herbert Xu | 6521f30 | 2006-08-06 20:28:44 +1000 | [diff] [blame] | 20 | #include <asm/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/list.h> |
Herbert Xu | 7991110 | 2006-08-21 21:03:52 +1000 | [diff] [blame] | 24 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/string.h> |
Herbert Xu | 7991110 | 2006-08-21 21:03:52 +1000 | [diff] [blame] | 26 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * Algorithm masks and types. |
| 30 | */ |
Herbert Xu | 2825982 | 2006-08-06 21:23:26 +1000 | [diff] [blame] | 31 | #define CRYPTO_ALG_TYPE_MASK 0x0000000f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #define CRYPTO_ALG_TYPE_CIPHER 0x00000001 |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 33 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000002 |
| 34 | #define CRYPTO_ALG_TYPE_AEAD 0x00000003 |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 35 | #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 |
Herbert Xu | 332f884 | 2007-11-15 22:36:07 +0800 | [diff] [blame] | 36 | #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005 |
Herbert Xu | 61da88e | 2007-12-17 21:51:27 +0800 | [diff] [blame] | 37 | #define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006 |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 38 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000008 |
| 39 | #define CRYPTO_ALG_TYPE_HASH 0x00000009 |
| 40 | #define CRYPTO_ALG_TYPE_AHASH 0x0000000a |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 41 | |
| 42 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 43 | #define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c |
Herbert Xu | 332f884 | 2007-11-15 22:36:07 +0800 | [diff] [blame] | 44 | #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Herbert Xu | 2825982 | 2006-08-06 21:23:26 +1000 | [diff] [blame] | 46 | #define CRYPTO_ALG_LARVAL 0x00000010 |
Herbert Xu | 6bfd480 | 2006-09-21 11:39:29 +1000 | [diff] [blame] | 47 | #define CRYPTO_ALG_DEAD 0x00000020 |
| 48 | #define CRYPTO_ALG_DYING 0x00000040 |
Herbert Xu | f3f632d | 2006-08-06 23:12:59 +1000 | [diff] [blame] | 49 | #define CRYPTO_ALG_ASYNC 0x00000080 |
Herbert Xu | 2825982 | 2006-08-06 21:23:26 +1000 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* |
Herbert Xu | 6010439 | 2006-08-26 18:34:10 +1000 | [diff] [blame] | 52 | * Set this bit if and only if the algorithm requires another algorithm of |
| 53 | * the same type to handle corner cases. |
| 54 | */ |
| 55 | #define CRYPTO_ALG_NEED_FALLBACK 0x00000100 |
| 56 | |
| 57 | /* |
Herbert Xu | ecfc432 | 2007-12-05 21:08:36 +1100 | [diff] [blame] | 58 | * This bit is set for symmetric key ciphers that have already been wrapped |
| 59 | * with a generic IV generator to prevent them from being wrapped again. |
| 60 | */ |
| 61 | #define CRYPTO_ALG_GENIV 0x00000200 |
| 62 | |
| 63 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | * Transform masks and values (for crt_flags). |
| 65 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #define CRYPTO_TFM_REQ_MASK 0x000fff00 |
| 67 | #define CRYPTO_TFM_RES_MASK 0xfff00000 |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100 |
Herbert Xu | 64baf3c | 2005-09-01 17:43:05 -0700 | [diff] [blame] | 70 | #define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200 |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 71 | #define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define CRYPTO_TFM_RES_WEAK_KEY 0x00100000 |
| 73 | #define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000 |
| 74 | #define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000 |
| 75 | #define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000 |
| 76 | #define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000 |
| 77 | |
| 78 | /* |
| 79 | * Miscellaneous stuff. |
| 80 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #define CRYPTO_MAX_ALG_NAME 64 |
| 82 | |
Herbert Xu | 7991110 | 2006-08-21 21:03:52 +1000 | [diff] [blame] | 83 | /* |
| 84 | * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual |
| 85 | * declaration) is used to ensure that the crypto_tfm context structure is |
| 86 | * aligned correctly for the given architecture so that there are no alignment |
| 87 | * faults for C data types. In particular, this is required on platforms such |
| 88 | * as arm where pointers are 32-bit aligned but there are data types such as |
| 89 | * u64 which require 64-bit alignment. |
| 90 | */ |
| 91 | #if defined(ARCH_KMALLOC_MINALIGN) |
| 92 | #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN |
| 93 | #elif defined(ARCH_SLAB_MINALIGN) |
| 94 | #define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN |
Herbert Xu | 6eb7228 | 2008-01-08 17:16:44 +1100 | [diff] [blame] | 95 | #else |
| 96 | #define CRYPTO_MINALIGN __alignof__(unsigned long long) |
Herbert Xu | 7991110 | 2006-08-21 21:03:52 +1000 | [diff] [blame] | 97 | #endif |
| 98 | |
Herbert Xu | 7991110 | 2006-08-21 21:03:52 +1000 | [diff] [blame] | 99 | #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN))) |
Herbert Xu | 7991110 | 2006-08-21 21:03:52 +1000 | [diff] [blame] | 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | struct scatterlist; |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 102 | struct crypto_ablkcipher; |
| 103 | struct crypto_async_request; |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 104 | struct crypto_aead; |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 105 | struct crypto_blkcipher; |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 106 | struct crypto_hash; |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 107 | struct crypto_ahash; |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 108 | struct crypto_tfm; |
Herbert Xu | e853c3c | 2006-08-22 00:06:54 +1000 | [diff] [blame] | 109 | struct crypto_type; |
Herbert Xu | 743edf5 | 2007-12-10 16:18:01 +0800 | [diff] [blame] | 110 | struct aead_givcrypt_request; |
Herbert Xu | 61da88e | 2007-12-17 21:51:27 +0800 | [diff] [blame] | 111 | struct skcipher_givcrypt_request; |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 112 | |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 113 | typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err); |
| 114 | |
| 115 | struct crypto_async_request { |
| 116 | struct list_head list; |
| 117 | crypto_completion_t complete; |
| 118 | void *data; |
| 119 | struct crypto_tfm *tfm; |
| 120 | |
| 121 | u32 flags; |
| 122 | }; |
| 123 | |
| 124 | struct ablkcipher_request { |
| 125 | struct crypto_async_request base; |
| 126 | |
| 127 | unsigned int nbytes; |
| 128 | |
| 129 | void *info; |
| 130 | |
| 131 | struct scatterlist *src; |
| 132 | struct scatterlist *dst; |
| 133 | |
| 134 | void *__ctx[] CRYPTO_MINALIGN_ATTR; |
| 135 | }; |
| 136 | |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 137 | struct ahash_request { |
| 138 | struct crypto_async_request base; |
| 139 | |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 140 | unsigned int nbytes; |
| 141 | struct scatterlist *src; |
| 142 | u8 *result; |
| 143 | |
| 144 | void *__ctx[] CRYPTO_MINALIGN_ATTR; |
| 145 | }; |
| 146 | |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 147 | /** |
| 148 | * struct aead_request - AEAD request |
| 149 | * @base: Common attributes for async crypto requests |
| 150 | * @assoclen: Length in bytes of associated data for authentication |
| 151 | * @cryptlen: Length of data to be encrypted or decrypted |
| 152 | * @iv: Initialisation vector |
| 153 | * @assoc: Associated data |
| 154 | * @src: Source data |
| 155 | * @dst: Destination data |
| 156 | * @__ctx: Start of private context data |
| 157 | */ |
| 158 | struct aead_request { |
| 159 | struct crypto_async_request base; |
| 160 | |
| 161 | unsigned int assoclen; |
| 162 | unsigned int cryptlen; |
| 163 | |
| 164 | u8 *iv; |
| 165 | |
| 166 | struct scatterlist *assoc; |
| 167 | struct scatterlist *src; |
| 168 | struct scatterlist *dst; |
| 169 | |
| 170 | void *__ctx[] CRYPTO_MINALIGN_ATTR; |
| 171 | }; |
| 172 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 173 | struct blkcipher_desc { |
| 174 | struct crypto_blkcipher *tfm; |
| 175 | void *info; |
| 176 | u32 flags; |
| 177 | }; |
| 178 | |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 179 | struct cipher_desc { |
| 180 | struct crypto_tfm *tfm; |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 181 | void (*crfn)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 182 | unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst, |
| 183 | const u8 *src, unsigned int nbytes); |
| 184 | void *info; |
| 185 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 187 | struct hash_desc { |
| 188 | struct crypto_hash *tfm; |
| 189 | u32 flags; |
| 190 | }; |
| 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | /* |
| 193 | * Algorithms: modular crypto algorithm implementations, managed |
| 194 | * via crypto_register_alg() and crypto_unregister_alg(). |
| 195 | */ |
Herbert Xu | b5b7f08 | 2007-04-16 20:48:54 +1000 | [diff] [blame] | 196 | struct ablkcipher_alg { |
| 197 | int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key, |
| 198 | unsigned int keylen); |
| 199 | int (*encrypt)(struct ablkcipher_request *req); |
| 200 | int (*decrypt)(struct ablkcipher_request *req); |
Herbert Xu | 61da88e | 2007-12-17 21:51:27 +0800 | [diff] [blame] | 201 | int (*givencrypt)(struct skcipher_givcrypt_request *req); |
| 202 | int (*givdecrypt)(struct skcipher_givcrypt_request *req); |
Herbert Xu | b5b7f08 | 2007-04-16 20:48:54 +1000 | [diff] [blame] | 203 | |
Herbert Xu | 23508e1 | 2007-11-27 21:33:24 +0800 | [diff] [blame] | 204 | const char *geniv; |
| 205 | |
Herbert Xu | b5b7f08 | 2007-04-16 20:48:54 +1000 | [diff] [blame] | 206 | unsigned int min_keysize; |
| 207 | unsigned int max_keysize; |
| 208 | unsigned int ivsize; |
| 209 | }; |
| 210 | |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 211 | struct ahash_alg { |
| 212 | int (*init)(struct ahash_request *req); |
| 213 | int (*update)(struct ahash_request *req); |
| 214 | int (*final)(struct ahash_request *req); |
| 215 | int (*digest)(struct ahash_request *req); |
| 216 | int (*setkey)(struct crypto_ahash *tfm, const u8 *key, |
| 217 | unsigned int keylen); |
| 218 | |
| 219 | unsigned int digestsize; |
| 220 | }; |
| 221 | |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 222 | struct aead_alg { |
| 223 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, |
| 224 | unsigned int keylen); |
Herbert Xu | 7ba683a | 2007-12-02 18:49:21 +1100 | [diff] [blame] | 225 | int (*setauthsize)(struct crypto_aead *tfm, unsigned int authsize); |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 226 | int (*encrypt)(struct aead_request *req); |
| 227 | int (*decrypt)(struct aead_request *req); |
Herbert Xu | 743edf5 | 2007-12-10 16:18:01 +0800 | [diff] [blame] | 228 | int (*givencrypt)(struct aead_givcrypt_request *req); |
| 229 | int (*givdecrypt)(struct aead_givcrypt_request *req); |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 230 | |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 231 | const char *geniv; |
| 232 | |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 233 | unsigned int ivsize; |
Herbert Xu | 7ba683a | 2007-12-02 18:49:21 +1100 | [diff] [blame] | 234 | unsigned int maxauthsize; |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 235 | }; |
| 236 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 237 | struct blkcipher_alg { |
| 238 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, |
| 239 | unsigned int keylen); |
| 240 | int (*encrypt)(struct blkcipher_desc *desc, |
| 241 | struct scatterlist *dst, struct scatterlist *src, |
| 242 | unsigned int nbytes); |
| 243 | int (*decrypt)(struct blkcipher_desc *desc, |
| 244 | struct scatterlist *dst, struct scatterlist *src, |
| 245 | unsigned int nbytes); |
| 246 | |
Herbert Xu | 23508e1 | 2007-11-27 21:33:24 +0800 | [diff] [blame] | 247 | const char *geniv; |
| 248 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 249 | unsigned int min_keysize; |
| 250 | unsigned int max_keysize; |
| 251 | unsigned int ivsize; |
| 252 | }; |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | struct cipher_alg { |
| 255 | unsigned int cia_min_keysize; |
| 256 | unsigned int cia_max_keysize; |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 257 | int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key, |
Herbert Xu | 560c06a | 2006-08-13 14:16:39 +1000 | [diff] [blame] | 258 | unsigned int keylen); |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 259 | void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
| 260 | void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | struct digest_alg { |
| 264 | unsigned int dia_digestsize; |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 265 | void (*dia_init)(struct crypto_tfm *tfm); |
| 266 | void (*dia_update)(struct crypto_tfm *tfm, const u8 *data, |
| 267 | unsigned int len); |
| 268 | void (*dia_final)(struct crypto_tfm *tfm, u8 *out); |
| 269 | int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key, |
Herbert Xu | 560c06a | 2006-08-13 14:16:39 +1000 | [diff] [blame] | 270 | unsigned int keylen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | }; |
| 272 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 273 | struct hash_alg { |
| 274 | int (*init)(struct hash_desc *desc); |
| 275 | int (*update)(struct hash_desc *desc, struct scatterlist *sg, |
| 276 | unsigned int nbytes); |
| 277 | int (*final)(struct hash_desc *desc, u8 *out); |
| 278 | int (*digest)(struct hash_desc *desc, struct scatterlist *sg, |
| 279 | unsigned int nbytes, u8 *out); |
| 280 | int (*setkey)(struct crypto_hash *tfm, const u8 *key, |
| 281 | unsigned int keylen); |
| 282 | |
| 283 | unsigned int digestsize; |
| 284 | }; |
| 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | struct compress_alg { |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 287 | int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src, |
| 288 | unsigned int slen, u8 *dst, unsigned int *dlen); |
| 289 | int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src, |
| 290 | unsigned int slen, u8 *dst, unsigned int *dlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
Herbert Xu | b5b7f08 | 2007-04-16 20:48:54 +1000 | [diff] [blame] | 293 | #define cra_ablkcipher cra_u.ablkcipher |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 294 | #define cra_aead cra_u.aead |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 295 | #define cra_blkcipher cra_u.blkcipher |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | #define cra_cipher cra_u.cipher |
| 297 | #define cra_digest cra_u.digest |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 298 | #define cra_hash cra_u.hash |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 299 | #define cra_ahash cra_u.ahash |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | #define cra_compress cra_u.compress |
| 301 | |
| 302 | struct crypto_alg { |
| 303 | struct list_head cra_list; |
Herbert Xu | 6bfd480 | 2006-09-21 11:39:29 +1000 | [diff] [blame] | 304 | struct list_head cra_users; |
| 305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | u32 cra_flags; |
| 307 | unsigned int cra_blocksize; |
| 308 | unsigned int cra_ctxsize; |
Herbert Xu | 9547737 | 2005-07-06 13:52:09 -0700 | [diff] [blame] | 309 | unsigned int cra_alignmask; |
Herbert Xu | 5cb1454 | 2005-11-05 16:58:14 +1100 | [diff] [blame] | 310 | |
| 311 | int cra_priority; |
Herbert Xu | 6521f30 | 2006-08-06 20:28:44 +1000 | [diff] [blame] | 312 | atomic_t cra_refcnt; |
Herbert Xu | 5cb1454 | 2005-11-05 16:58:14 +1100 | [diff] [blame] | 313 | |
Herbert Xu | d913ea0 | 2006-05-21 08:45:26 +1000 | [diff] [blame] | 314 | char cra_name[CRYPTO_MAX_ALG_NAME]; |
| 315 | char cra_driver_name[CRYPTO_MAX_ALG_NAME]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Herbert Xu | e853c3c | 2006-08-22 00:06:54 +1000 | [diff] [blame] | 317 | const struct crypto_type *cra_type; |
| 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | union { |
Herbert Xu | b5b7f08 | 2007-04-16 20:48:54 +1000 | [diff] [blame] | 320 | struct ablkcipher_alg ablkcipher; |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 321 | struct aead_alg aead; |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 322 | struct blkcipher_alg blkcipher; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | struct cipher_alg cipher; |
| 324 | struct digest_alg digest; |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 325 | struct hash_alg hash; |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 326 | struct ahash_alg ahash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | struct compress_alg compress; |
| 328 | } cra_u; |
Herbert Xu | c7fc059 | 2006-05-24 13:02:26 +1000 | [diff] [blame] | 329 | |
| 330 | int (*cra_init)(struct crypto_tfm *tfm); |
| 331 | void (*cra_exit)(struct crypto_tfm *tfm); |
Herbert Xu | 6521f30 | 2006-08-06 20:28:44 +1000 | [diff] [blame] | 332 | void (*cra_destroy)(struct crypto_alg *alg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
| 334 | struct module *cra_module; |
| 335 | }; |
| 336 | |
| 337 | /* |
| 338 | * Algorithm registration interface. |
| 339 | */ |
| 340 | int crypto_register_alg(struct crypto_alg *alg); |
| 341 | int crypto_unregister_alg(struct crypto_alg *alg); |
| 342 | |
| 343 | /* |
| 344 | * Algorithm query interface. |
| 345 | */ |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 346 | int crypto_has_alg(const char *name, u32 type, u32 mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
| 348 | /* |
| 349 | * Transforms: user-instantiated objects which encapsulate algorithms |
Herbert Xu | 6d7d684 | 2006-07-30 11:53:01 +1000 | [diff] [blame] | 350 | * and core processing logic. Managed via crypto_alloc_*() and |
| 351 | * crypto_free_*(), as well as the various helpers below. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 354 | struct ablkcipher_tfm { |
| 355 | int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key, |
| 356 | unsigned int keylen); |
| 357 | int (*encrypt)(struct ablkcipher_request *req); |
| 358 | int (*decrypt)(struct ablkcipher_request *req); |
Herbert Xu | 61da88e | 2007-12-17 21:51:27 +0800 | [diff] [blame] | 359 | int (*givencrypt)(struct skcipher_givcrypt_request *req); |
| 360 | int (*givdecrypt)(struct skcipher_givcrypt_request *req); |
| 361 | |
Herbert Xu | ecfc432 | 2007-12-05 21:08:36 +1100 | [diff] [blame] | 362 | struct crypto_ablkcipher *base; |
| 363 | |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 364 | unsigned int ivsize; |
| 365 | unsigned int reqsize; |
| 366 | }; |
| 367 | |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 368 | struct aead_tfm { |
| 369 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, |
| 370 | unsigned int keylen); |
| 371 | int (*encrypt)(struct aead_request *req); |
| 372 | int (*decrypt)(struct aead_request *req); |
Herbert Xu | 743edf5 | 2007-12-10 16:18:01 +0800 | [diff] [blame] | 373 | int (*givencrypt)(struct aead_givcrypt_request *req); |
| 374 | int (*givdecrypt)(struct aead_givcrypt_request *req); |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 375 | |
| 376 | struct crypto_aead *base; |
| 377 | |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 378 | unsigned int ivsize; |
| 379 | unsigned int authsize; |
| 380 | unsigned int reqsize; |
| 381 | }; |
| 382 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 383 | struct blkcipher_tfm { |
| 384 | void *iv; |
| 385 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, |
| 386 | unsigned int keylen); |
| 387 | int (*encrypt)(struct blkcipher_desc *desc, struct scatterlist *dst, |
| 388 | struct scatterlist *src, unsigned int nbytes); |
| 389 | int (*decrypt)(struct blkcipher_desc *desc, struct scatterlist *dst, |
| 390 | struct scatterlist *src, unsigned int nbytes); |
| 391 | }; |
| 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | struct cipher_tfm { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | int (*cit_setkey)(struct crypto_tfm *tfm, |
| 395 | const u8 *key, unsigned int keylen); |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 396 | void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
| 397 | void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | }; |
| 399 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 400 | struct hash_tfm { |
| 401 | int (*init)(struct hash_desc *desc); |
| 402 | int (*update)(struct hash_desc *desc, |
| 403 | struct scatterlist *sg, unsigned int nsg); |
| 404 | int (*final)(struct hash_desc *desc, u8 *out); |
| 405 | int (*digest)(struct hash_desc *desc, struct scatterlist *sg, |
| 406 | unsigned int nsg, u8 *out); |
| 407 | int (*setkey)(struct crypto_hash *tfm, const u8 *key, |
| 408 | unsigned int keylen); |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 409 | unsigned int digestsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | }; |
| 411 | |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 412 | struct ahash_tfm { |
| 413 | int (*init)(struct ahash_request *req); |
| 414 | int (*update)(struct ahash_request *req); |
| 415 | int (*final)(struct ahash_request *req); |
| 416 | int (*digest)(struct ahash_request *req); |
| 417 | int (*setkey)(struct crypto_ahash *tfm, const u8 *key, |
| 418 | unsigned int keylen); |
| 419 | |
| 420 | unsigned int digestsize; |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 421 | unsigned int reqsize; |
| 422 | }; |
| 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | struct compress_tfm { |
| 425 | int (*cot_compress)(struct crypto_tfm *tfm, |
| 426 | const u8 *src, unsigned int slen, |
| 427 | u8 *dst, unsigned int *dlen); |
| 428 | int (*cot_decompress)(struct crypto_tfm *tfm, |
| 429 | const u8 *src, unsigned int slen, |
| 430 | u8 *dst, unsigned int *dlen); |
| 431 | }; |
| 432 | |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 433 | #define crt_ablkcipher crt_u.ablkcipher |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 434 | #define crt_aead crt_u.aead |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 435 | #define crt_blkcipher crt_u.blkcipher |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | #define crt_cipher crt_u.cipher |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 437 | #define crt_hash crt_u.hash |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 438 | #define crt_ahash crt_u.ahash |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | #define crt_compress crt_u.compress |
| 440 | |
| 441 | struct crypto_tfm { |
| 442 | |
| 443 | u32 crt_flags; |
| 444 | |
| 445 | union { |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 446 | struct ablkcipher_tfm ablkcipher; |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 447 | struct aead_tfm aead; |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 448 | struct blkcipher_tfm blkcipher; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | struct cipher_tfm cipher; |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 450 | struct hash_tfm hash; |
Loc Ho | 004a403 | 2008-05-14 20:41:47 +0800 | [diff] [blame] | 451 | struct ahash_tfm ahash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | struct compress_tfm compress; |
| 453 | } crt_u; |
| 454 | |
| 455 | struct crypto_alg *__crt_alg; |
Herbert Xu | f10b789 | 2006-01-25 22:34:01 +1100 | [diff] [blame] | 456 | |
Herbert Xu | 7991110 | 2006-08-21 21:03:52 +1000 | [diff] [blame] | 457 | void *__crt_ctx[] CRYPTO_MINALIGN_ATTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | }; |
| 459 | |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 460 | struct crypto_ablkcipher { |
| 461 | struct crypto_tfm base; |
| 462 | }; |
| 463 | |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 464 | struct crypto_aead { |
| 465 | struct crypto_tfm base; |
| 466 | }; |
| 467 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 468 | struct crypto_blkcipher { |
| 469 | struct crypto_tfm base; |
| 470 | }; |
| 471 | |
Herbert Xu | 78a1fe4 | 2006-12-24 10:02:00 +1100 | [diff] [blame] | 472 | struct crypto_cipher { |
| 473 | struct crypto_tfm base; |
| 474 | }; |
| 475 | |
| 476 | struct crypto_comp { |
| 477 | struct crypto_tfm base; |
| 478 | }; |
| 479 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 480 | struct crypto_hash { |
| 481 | struct crypto_tfm base; |
| 482 | }; |
| 483 | |
Herbert Xu | 2b8c19d | 2006-09-21 11:31:44 +1000 | [diff] [blame] | 484 | enum { |
| 485 | CRYPTOA_UNSPEC, |
| 486 | CRYPTOA_ALG, |
Herbert Xu | ebc610e | 2007-01-01 18:37:02 +1100 | [diff] [blame] | 487 | CRYPTOA_TYPE, |
Herbert Xu | 39e1ee0 | 2007-08-29 19:27:26 +0800 | [diff] [blame] | 488 | CRYPTOA_U32, |
Herbert Xu | ebc610e | 2007-01-01 18:37:02 +1100 | [diff] [blame] | 489 | __CRYPTOA_MAX, |
Herbert Xu | 2b8c19d | 2006-09-21 11:31:44 +1000 | [diff] [blame] | 490 | }; |
| 491 | |
Herbert Xu | ebc610e | 2007-01-01 18:37:02 +1100 | [diff] [blame] | 492 | #define CRYPTOA_MAX (__CRYPTOA_MAX - 1) |
| 493 | |
Herbert Xu | 39e1ee0 | 2007-08-29 19:27:26 +0800 | [diff] [blame] | 494 | /* Maximum number of (rtattr) parameters for each template. */ |
| 495 | #define CRYPTO_MAX_ATTRS 32 |
| 496 | |
Herbert Xu | 2b8c19d | 2006-09-21 11:31:44 +1000 | [diff] [blame] | 497 | struct crypto_attr_alg { |
| 498 | char name[CRYPTO_MAX_ALG_NAME]; |
| 499 | }; |
| 500 | |
Herbert Xu | ebc610e | 2007-01-01 18:37:02 +1100 | [diff] [blame] | 501 | struct crypto_attr_type { |
| 502 | u32 type; |
| 503 | u32 mask; |
| 504 | }; |
| 505 | |
Herbert Xu | 39e1ee0 | 2007-08-29 19:27:26 +0800 | [diff] [blame] | 506 | struct crypto_attr_u32 { |
| 507 | u32 num; |
| 508 | }; |
| 509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | /* |
| 511 | * Transform user interface. |
| 512 | */ |
| 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags); |
Herbert Xu | 6d7d684 | 2006-07-30 11:53:01 +1000 | [diff] [blame] | 515 | struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | void crypto_free_tfm(struct crypto_tfm *tfm); |
| 517 | |
| 518 | /* |
| 519 | * Transform helpers which query the underlying algorithm. |
| 520 | */ |
| 521 | static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm) |
| 522 | { |
| 523 | return tfm->__crt_alg->cra_name; |
| 524 | } |
| 525 | |
Michal Ludvig | b14cdd6 | 2006-07-09 09:02:24 +1000 | [diff] [blame] | 526 | static inline const char *crypto_tfm_alg_driver_name(struct crypto_tfm *tfm) |
| 527 | { |
| 528 | return tfm->__crt_alg->cra_driver_name; |
| 529 | } |
| 530 | |
| 531 | static inline int crypto_tfm_alg_priority(struct crypto_tfm *tfm) |
| 532 | { |
| 533 | return tfm->__crt_alg->cra_priority; |
| 534 | } |
| 535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | static inline const char *crypto_tfm_alg_modname(struct crypto_tfm *tfm) |
| 537 | { |
| 538 | return module_name(tfm->__crt_alg->cra_module); |
| 539 | } |
| 540 | |
| 541 | static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm) |
| 542 | { |
| 543 | return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK; |
| 544 | } |
| 545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm) |
| 547 | { |
| 548 | return tfm->__crt_alg->cra_blocksize; |
| 549 | } |
| 550 | |
Herbert Xu | fbdae9f | 2005-07-06 13:53:29 -0700 | [diff] [blame] | 551 | static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm) |
| 552 | { |
| 553 | return tfm->__crt_alg->cra_alignmask; |
| 554 | } |
| 555 | |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 556 | static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm) |
| 557 | { |
| 558 | return tfm->crt_flags; |
| 559 | } |
| 560 | |
| 561 | static inline void crypto_tfm_set_flags(struct crypto_tfm *tfm, u32 flags) |
| 562 | { |
| 563 | tfm->crt_flags |= flags; |
| 564 | } |
| 565 | |
| 566 | static inline void crypto_tfm_clear_flags(struct crypto_tfm *tfm, u32 flags) |
| 567 | { |
| 568 | tfm->crt_flags &= ~flags; |
| 569 | } |
| 570 | |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 571 | static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) |
| 572 | { |
Herbert Xu | f10b789 | 2006-01-25 22:34:01 +1100 | [diff] [blame] | 573 | return tfm->__crt_ctx; |
| 574 | } |
| 575 | |
| 576 | static inline unsigned int crypto_tfm_ctx_alignment(void) |
| 577 | { |
| 578 | struct crypto_tfm *tfm; |
| 579 | return __alignof__(tfm->__crt_ctx); |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* |
| 583 | * API wrappers. |
| 584 | */ |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 585 | static inline struct crypto_ablkcipher *__crypto_ablkcipher_cast( |
| 586 | struct crypto_tfm *tfm) |
| 587 | { |
| 588 | return (struct crypto_ablkcipher *)tfm; |
| 589 | } |
| 590 | |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 591 | static inline u32 crypto_skcipher_type(u32 type) |
| 592 | { |
Herbert Xu | ecfc432 | 2007-12-05 21:08:36 +1100 | [diff] [blame] | 593 | type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV); |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 594 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
| 595 | return type; |
| 596 | } |
| 597 | |
| 598 | static inline u32 crypto_skcipher_mask(u32 mask) |
| 599 | { |
Herbert Xu | ecfc432 | 2007-12-05 21:08:36 +1100 | [diff] [blame] | 600 | mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV); |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 601 | mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK; |
| 602 | return mask; |
| 603 | } |
| 604 | |
Herbert Xu | b9c55aa | 2007-12-04 12:46:48 +1100 | [diff] [blame] | 605 | struct crypto_ablkcipher *crypto_alloc_ablkcipher(const char *alg_name, |
| 606 | u32 type, u32 mask); |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 607 | |
| 608 | static inline struct crypto_tfm *crypto_ablkcipher_tfm( |
| 609 | struct crypto_ablkcipher *tfm) |
| 610 | { |
| 611 | return &tfm->base; |
| 612 | } |
| 613 | |
| 614 | static inline void crypto_free_ablkcipher(struct crypto_ablkcipher *tfm) |
| 615 | { |
| 616 | crypto_free_tfm(crypto_ablkcipher_tfm(tfm)); |
| 617 | } |
| 618 | |
| 619 | static inline int crypto_has_ablkcipher(const char *alg_name, u32 type, |
| 620 | u32 mask) |
| 621 | { |
Herbert Xu | 378f4f5 | 2007-12-17 20:07:31 +0800 | [diff] [blame] | 622 | return crypto_has_alg(alg_name, crypto_skcipher_type(type), |
| 623 | crypto_skcipher_mask(mask)); |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static inline struct ablkcipher_tfm *crypto_ablkcipher_crt( |
| 627 | struct crypto_ablkcipher *tfm) |
| 628 | { |
| 629 | return &crypto_ablkcipher_tfm(tfm)->crt_ablkcipher; |
| 630 | } |
| 631 | |
| 632 | static inline unsigned int crypto_ablkcipher_ivsize( |
| 633 | struct crypto_ablkcipher *tfm) |
| 634 | { |
| 635 | return crypto_ablkcipher_crt(tfm)->ivsize; |
| 636 | } |
| 637 | |
| 638 | static inline unsigned int crypto_ablkcipher_blocksize( |
| 639 | struct crypto_ablkcipher *tfm) |
| 640 | { |
| 641 | return crypto_tfm_alg_blocksize(crypto_ablkcipher_tfm(tfm)); |
| 642 | } |
| 643 | |
| 644 | static inline unsigned int crypto_ablkcipher_alignmask( |
| 645 | struct crypto_ablkcipher *tfm) |
| 646 | { |
| 647 | return crypto_tfm_alg_alignmask(crypto_ablkcipher_tfm(tfm)); |
| 648 | } |
| 649 | |
| 650 | static inline u32 crypto_ablkcipher_get_flags(struct crypto_ablkcipher *tfm) |
| 651 | { |
| 652 | return crypto_tfm_get_flags(crypto_ablkcipher_tfm(tfm)); |
| 653 | } |
| 654 | |
| 655 | static inline void crypto_ablkcipher_set_flags(struct crypto_ablkcipher *tfm, |
| 656 | u32 flags) |
| 657 | { |
| 658 | crypto_tfm_set_flags(crypto_ablkcipher_tfm(tfm), flags); |
| 659 | } |
| 660 | |
| 661 | static inline void crypto_ablkcipher_clear_flags(struct crypto_ablkcipher *tfm, |
| 662 | u32 flags) |
| 663 | { |
| 664 | crypto_tfm_clear_flags(crypto_ablkcipher_tfm(tfm), flags); |
| 665 | } |
| 666 | |
| 667 | static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm, |
| 668 | const u8 *key, unsigned int keylen) |
| 669 | { |
Herbert Xu | ecfc432 | 2007-12-05 21:08:36 +1100 | [diff] [blame] | 670 | struct ablkcipher_tfm *crt = crypto_ablkcipher_crt(tfm); |
| 671 | |
| 672 | return crt->setkey(crt->base, key, keylen); |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm( |
| 676 | struct ablkcipher_request *req) |
| 677 | { |
| 678 | return __crypto_ablkcipher_cast(req->base.tfm); |
| 679 | } |
| 680 | |
| 681 | static inline int crypto_ablkcipher_encrypt(struct ablkcipher_request *req) |
| 682 | { |
| 683 | struct ablkcipher_tfm *crt = |
| 684 | crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req)); |
| 685 | return crt->encrypt(req); |
| 686 | } |
| 687 | |
| 688 | static inline int crypto_ablkcipher_decrypt(struct ablkcipher_request *req) |
| 689 | { |
| 690 | struct ablkcipher_tfm *crt = |
| 691 | crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req)); |
| 692 | return crt->decrypt(req); |
| 693 | } |
| 694 | |
Herbert Xu | b16c3a2 | 2007-08-29 19:02:04 +0800 | [diff] [blame] | 695 | static inline unsigned int crypto_ablkcipher_reqsize( |
| 696 | struct crypto_ablkcipher *tfm) |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 697 | { |
| 698 | return crypto_ablkcipher_crt(tfm)->reqsize; |
| 699 | } |
| 700 | |
Herbert Xu | e196d62 | 2007-04-14 16:09:14 +1000 | [diff] [blame] | 701 | static inline void ablkcipher_request_set_tfm( |
| 702 | struct ablkcipher_request *req, struct crypto_ablkcipher *tfm) |
| 703 | { |
Herbert Xu | ecfc432 | 2007-12-05 21:08:36 +1100 | [diff] [blame] | 704 | req->base.tfm = crypto_ablkcipher_tfm(crypto_ablkcipher_crt(tfm)->base); |
Herbert Xu | e196d62 | 2007-04-14 16:09:14 +1000 | [diff] [blame] | 705 | } |
| 706 | |
Herbert Xu | b5b7f08 | 2007-04-16 20:48:54 +1000 | [diff] [blame] | 707 | static inline struct ablkcipher_request *ablkcipher_request_cast( |
| 708 | struct crypto_async_request *req) |
| 709 | { |
| 710 | return container_of(req, struct ablkcipher_request, base); |
| 711 | } |
| 712 | |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 713 | static inline struct ablkcipher_request *ablkcipher_request_alloc( |
| 714 | struct crypto_ablkcipher *tfm, gfp_t gfp) |
| 715 | { |
| 716 | struct ablkcipher_request *req; |
| 717 | |
| 718 | req = kmalloc(sizeof(struct ablkcipher_request) + |
| 719 | crypto_ablkcipher_reqsize(tfm), gfp); |
| 720 | |
| 721 | if (likely(req)) |
Herbert Xu | e196d62 | 2007-04-14 16:09:14 +1000 | [diff] [blame] | 722 | ablkcipher_request_set_tfm(req, tfm); |
Herbert Xu | 32e3983 | 2007-03-24 14:35:34 +1100 | [diff] [blame] | 723 | |
| 724 | return req; |
| 725 | } |
| 726 | |
| 727 | static inline void ablkcipher_request_free(struct ablkcipher_request *req) |
| 728 | { |
| 729 | kfree(req); |
| 730 | } |
| 731 | |
| 732 | static inline void ablkcipher_request_set_callback( |
| 733 | struct ablkcipher_request *req, |
| 734 | u32 flags, crypto_completion_t complete, void *data) |
| 735 | { |
| 736 | req->base.complete = complete; |
| 737 | req->base.data = data; |
| 738 | req->base.flags = flags; |
| 739 | } |
| 740 | |
| 741 | static inline void ablkcipher_request_set_crypt( |
| 742 | struct ablkcipher_request *req, |
| 743 | struct scatterlist *src, struct scatterlist *dst, |
| 744 | unsigned int nbytes, void *iv) |
| 745 | { |
| 746 | req->src = src; |
| 747 | req->dst = dst; |
| 748 | req->nbytes = nbytes; |
| 749 | req->info = iv; |
| 750 | } |
| 751 | |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 752 | static inline struct crypto_aead *__crypto_aead_cast(struct crypto_tfm *tfm) |
| 753 | { |
| 754 | return (struct crypto_aead *)tfm; |
| 755 | } |
| 756 | |
Herbert Xu | d29ce98 | 2007-12-12 19:24:27 +0800 | [diff] [blame] | 757 | struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask); |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 758 | |
| 759 | static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm) |
| 760 | { |
| 761 | return &tfm->base; |
| 762 | } |
| 763 | |
| 764 | static inline void crypto_free_aead(struct crypto_aead *tfm) |
| 765 | { |
| 766 | crypto_free_tfm(crypto_aead_tfm(tfm)); |
| 767 | } |
| 768 | |
| 769 | static inline struct aead_tfm *crypto_aead_crt(struct crypto_aead *tfm) |
| 770 | { |
| 771 | return &crypto_aead_tfm(tfm)->crt_aead; |
| 772 | } |
| 773 | |
| 774 | static inline unsigned int crypto_aead_ivsize(struct crypto_aead *tfm) |
| 775 | { |
| 776 | return crypto_aead_crt(tfm)->ivsize; |
| 777 | } |
| 778 | |
| 779 | static inline unsigned int crypto_aead_authsize(struct crypto_aead *tfm) |
| 780 | { |
| 781 | return crypto_aead_crt(tfm)->authsize; |
| 782 | } |
| 783 | |
| 784 | static inline unsigned int crypto_aead_blocksize(struct crypto_aead *tfm) |
| 785 | { |
| 786 | return crypto_tfm_alg_blocksize(crypto_aead_tfm(tfm)); |
| 787 | } |
| 788 | |
| 789 | static inline unsigned int crypto_aead_alignmask(struct crypto_aead *tfm) |
| 790 | { |
| 791 | return crypto_tfm_alg_alignmask(crypto_aead_tfm(tfm)); |
| 792 | } |
| 793 | |
| 794 | static inline u32 crypto_aead_get_flags(struct crypto_aead *tfm) |
| 795 | { |
| 796 | return crypto_tfm_get_flags(crypto_aead_tfm(tfm)); |
| 797 | } |
| 798 | |
| 799 | static inline void crypto_aead_set_flags(struct crypto_aead *tfm, u32 flags) |
| 800 | { |
| 801 | crypto_tfm_set_flags(crypto_aead_tfm(tfm), flags); |
| 802 | } |
| 803 | |
| 804 | static inline void crypto_aead_clear_flags(struct crypto_aead *tfm, u32 flags) |
| 805 | { |
| 806 | crypto_tfm_clear_flags(crypto_aead_tfm(tfm), flags); |
| 807 | } |
| 808 | |
| 809 | static inline int crypto_aead_setkey(struct crypto_aead *tfm, const u8 *key, |
| 810 | unsigned int keylen) |
| 811 | { |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 812 | struct aead_tfm *crt = crypto_aead_crt(tfm); |
| 813 | |
| 814 | return crt->setkey(crt->base, key, keylen); |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 815 | } |
| 816 | |
Herbert Xu | 7ba683a | 2007-12-02 18:49:21 +1100 | [diff] [blame] | 817 | int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize); |
| 818 | |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 819 | static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req) |
| 820 | { |
| 821 | return __crypto_aead_cast(req->base.tfm); |
| 822 | } |
| 823 | |
| 824 | static inline int crypto_aead_encrypt(struct aead_request *req) |
| 825 | { |
| 826 | return crypto_aead_crt(crypto_aead_reqtfm(req))->encrypt(req); |
| 827 | } |
| 828 | |
| 829 | static inline int crypto_aead_decrypt(struct aead_request *req) |
| 830 | { |
| 831 | return crypto_aead_crt(crypto_aead_reqtfm(req))->decrypt(req); |
| 832 | } |
| 833 | |
Herbert Xu | b16c3a2 | 2007-08-29 19:02:04 +0800 | [diff] [blame] | 834 | static inline unsigned int crypto_aead_reqsize(struct crypto_aead *tfm) |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 835 | { |
| 836 | return crypto_aead_crt(tfm)->reqsize; |
| 837 | } |
| 838 | |
| 839 | static inline void aead_request_set_tfm(struct aead_request *req, |
| 840 | struct crypto_aead *tfm) |
| 841 | { |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 842 | req->base.tfm = crypto_aead_tfm(crypto_aead_crt(tfm)->base); |
Herbert Xu | 1ae9782 | 2007-08-30 15:36:14 +0800 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm, |
| 846 | gfp_t gfp) |
| 847 | { |
| 848 | struct aead_request *req; |
| 849 | |
| 850 | req = kmalloc(sizeof(*req) + crypto_aead_reqsize(tfm), gfp); |
| 851 | |
| 852 | if (likely(req)) |
| 853 | aead_request_set_tfm(req, tfm); |
| 854 | |
| 855 | return req; |
| 856 | } |
| 857 | |
| 858 | static inline void aead_request_free(struct aead_request *req) |
| 859 | { |
| 860 | kfree(req); |
| 861 | } |
| 862 | |
| 863 | static inline void aead_request_set_callback(struct aead_request *req, |
| 864 | u32 flags, |
| 865 | crypto_completion_t complete, |
| 866 | void *data) |
| 867 | { |
| 868 | req->base.complete = complete; |
| 869 | req->base.data = data; |
| 870 | req->base.flags = flags; |
| 871 | } |
| 872 | |
| 873 | static inline void aead_request_set_crypt(struct aead_request *req, |
| 874 | struct scatterlist *src, |
| 875 | struct scatterlist *dst, |
| 876 | unsigned int cryptlen, u8 *iv) |
| 877 | { |
| 878 | req->src = src; |
| 879 | req->dst = dst; |
| 880 | req->cryptlen = cryptlen; |
| 881 | req->iv = iv; |
| 882 | } |
| 883 | |
| 884 | static inline void aead_request_set_assoc(struct aead_request *req, |
| 885 | struct scatterlist *assoc, |
| 886 | unsigned int assoclen) |
| 887 | { |
| 888 | req->assoc = assoc; |
| 889 | req->assoclen = assoclen; |
| 890 | } |
| 891 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 892 | static inline struct crypto_blkcipher *__crypto_blkcipher_cast( |
| 893 | struct crypto_tfm *tfm) |
| 894 | { |
| 895 | return (struct crypto_blkcipher *)tfm; |
| 896 | } |
| 897 | |
| 898 | static inline struct crypto_blkcipher *crypto_blkcipher_cast( |
| 899 | struct crypto_tfm *tfm) |
| 900 | { |
| 901 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_BLKCIPHER); |
| 902 | return __crypto_blkcipher_cast(tfm); |
| 903 | } |
| 904 | |
| 905 | static inline struct crypto_blkcipher *crypto_alloc_blkcipher( |
| 906 | const char *alg_name, u32 type, u32 mask) |
| 907 | { |
Herbert Xu | 332f884 | 2007-11-15 22:36:07 +0800 | [diff] [blame] | 908 | type &= ~CRYPTO_ALG_TYPE_MASK; |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 909 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
Herbert Xu | 332f884 | 2007-11-15 22:36:07 +0800 | [diff] [blame] | 910 | mask |= CRYPTO_ALG_TYPE_MASK; |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 911 | |
| 912 | return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask)); |
| 913 | } |
| 914 | |
| 915 | static inline struct crypto_tfm *crypto_blkcipher_tfm( |
| 916 | struct crypto_blkcipher *tfm) |
| 917 | { |
| 918 | return &tfm->base; |
| 919 | } |
| 920 | |
| 921 | static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm) |
| 922 | { |
| 923 | crypto_free_tfm(crypto_blkcipher_tfm(tfm)); |
| 924 | } |
| 925 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 926 | static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask) |
| 927 | { |
Herbert Xu | 332f884 | 2007-11-15 22:36:07 +0800 | [diff] [blame] | 928 | type &= ~CRYPTO_ALG_TYPE_MASK; |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 929 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
Herbert Xu | 332f884 | 2007-11-15 22:36:07 +0800 | [diff] [blame] | 930 | mask |= CRYPTO_ALG_TYPE_MASK; |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 931 | |
| 932 | return crypto_has_alg(alg_name, type, mask); |
| 933 | } |
| 934 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 935 | static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm) |
| 936 | { |
| 937 | return crypto_tfm_alg_name(crypto_blkcipher_tfm(tfm)); |
| 938 | } |
| 939 | |
| 940 | static inline struct blkcipher_tfm *crypto_blkcipher_crt( |
| 941 | struct crypto_blkcipher *tfm) |
| 942 | { |
| 943 | return &crypto_blkcipher_tfm(tfm)->crt_blkcipher; |
| 944 | } |
| 945 | |
| 946 | static inline struct blkcipher_alg *crypto_blkcipher_alg( |
| 947 | struct crypto_blkcipher *tfm) |
| 948 | { |
| 949 | return &crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher; |
| 950 | } |
| 951 | |
| 952 | static inline unsigned int crypto_blkcipher_ivsize(struct crypto_blkcipher *tfm) |
| 953 | { |
| 954 | return crypto_blkcipher_alg(tfm)->ivsize; |
| 955 | } |
| 956 | |
| 957 | static inline unsigned int crypto_blkcipher_blocksize( |
| 958 | struct crypto_blkcipher *tfm) |
| 959 | { |
| 960 | return crypto_tfm_alg_blocksize(crypto_blkcipher_tfm(tfm)); |
| 961 | } |
| 962 | |
| 963 | static inline unsigned int crypto_blkcipher_alignmask( |
| 964 | struct crypto_blkcipher *tfm) |
| 965 | { |
| 966 | return crypto_tfm_alg_alignmask(crypto_blkcipher_tfm(tfm)); |
| 967 | } |
| 968 | |
| 969 | static inline u32 crypto_blkcipher_get_flags(struct crypto_blkcipher *tfm) |
| 970 | { |
| 971 | return crypto_tfm_get_flags(crypto_blkcipher_tfm(tfm)); |
| 972 | } |
| 973 | |
| 974 | static inline void crypto_blkcipher_set_flags(struct crypto_blkcipher *tfm, |
| 975 | u32 flags) |
| 976 | { |
| 977 | crypto_tfm_set_flags(crypto_blkcipher_tfm(tfm), flags); |
| 978 | } |
| 979 | |
| 980 | static inline void crypto_blkcipher_clear_flags(struct crypto_blkcipher *tfm, |
| 981 | u32 flags) |
| 982 | { |
| 983 | crypto_tfm_clear_flags(crypto_blkcipher_tfm(tfm), flags); |
| 984 | } |
| 985 | |
| 986 | static inline int crypto_blkcipher_setkey(struct crypto_blkcipher *tfm, |
| 987 | const u8 *key, unsigned int keylen) |
| 988 | { |
| 989 | return crypto_blkcipher_crt(tfm)->setkey(crypto_blkcipher_tfm(tfm), |
| 990 | key, keylen); |
| 991 | } |
| 992 | |
| 993 | static inline int crypto_blkcipher_encrypt(struct blkcipher_desc *desc, |
| 994 | struct scatterlist *dst, |
| 995 | struct scatterlist *src, |
| 996 | unsigned int nbytes) |
| 997 | { |
| 998 | desc->info = crypto_blkcipher_crt(desc->tfm)->iv; |
| 999 | return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes); |
| 1000 | } |
| 1001 | |
| 1002 | static inline int crypto_blkcipher_encrypt_iv(struct blkcipher_desc *desc, |
| 1003 | struct scatterlist *dst, |
| 1004 | struct scatterlist *src, |
| 1005 | unsigned int nbytes) |
| 1006 | { |
| 1007 | return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes); |
| 1008 | } |
| 1009 | |
| 1010 | static inline int crypto_blkcipher_decrypt(struct blkcipher_desc *desc, |
| 1011 | struct scatterlist *dst, |
| 1012 | struct scatterlist *src, |
| 1013 | unsigned int nbytes) |
| 1014 | { |
| 1015 | desc->info = crypto_blkcipher_crt(desc->tfm)->iv; |
| 1016 | return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes); |
| 1017 | } |
| 1018 | |
| 1019 | static inline int crypto_blkcipher_decrypt_iv(struct blkcipher_desc *desc, |
| 1020 | struct scatterlist *dst, |
| 1021 | struct scatterlist *src, |
| 1022 | unsigned int nbytes) |
| 1023 | { |
| 1024 | return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes); |
| 1025 | } |
| 1026 | |
| 1027 | static inline void crypto_blkcipher_set_iv(struct crypto_blkcipher *tfm, |
| 1028 | const u8 *src, unsigned int len) |
| 1029 | { |
| 1030 | memcpy(crypto_blkcipher_crt(tfm)->iv, src, len); |
| 1031 | } |
| 1032 | |
| 1033 | static inline void crypto_blkcipher_get_iv(struct crypto_blkcipher *tfm, |
| 1034 | u8 *dst, unsigned int len) |
| 1035 | { |
| 1036 | memcpy(dst, crypto_blkcipher_crt(tfm)->iv, len); |
| 1037 | } |
| 1038 | |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 1039 | static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm) |
| 1040 | { |
| 1041 | return (struct crypto_cipher *)tfm; |
| 1042 | } |
| 1043 | |
| 1044 | static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm) |
| 1045 | { |
| 1046 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
| 1047 | return __crypto_cipher_cast(tfm); |
| 1048 | } |
| 1049 | |
| 1050 | static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name, |
| 1051 | u32 type, u32 mask) |
| 1052 | { |
| 1053 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 1054 | type |= CRYPTO_ALG_TYPE_CIPHER; |
| 1055 | mask |= CRYPTO_ALG_TYPE_MASK; |
| 1056 | |
| 1057 | return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask)); |
| 1058 | } |
| 1059 | |
| 1060 | static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm) |
| 1061 | { |
Herbert Xu | 78a1fe4 | 2006-12-24 10:02:00 +1100 | [diff] [blame] | 1062 | return &tfm->base; |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | static inline void crypto_free_cipher(struct crypto_cipher *tfm) |
| 1066 | { |
| 1067 | crypto_free_tfm(crypto_cipher_tfm(tfm)); |
| 1068 | } |
| 1069 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 1070 | static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask) |
| 1071 | { |
| 1072 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 1073 | type |= CRYPTO_ALG_TYPE_CIPHER; |
| 1074 | mask |= CRYPTO_ALG_TYPE_MASK; |
| 1075 | |
| 1076 | return crypto_has_alg(alg_name, type, mask); |
| 1077 | } |
| 1078 | |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 1079 | static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm) |
| 1080 | { |
| 1081 | return &crypto_cipher_tfm(tfm)->crt_cipher; |
| 1082 | } |
| 1083 | |
| 1084 | static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm) |
| 1085 | { |
| 1086 | return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm)); |
| 1087 | } |
| 1088 | |
| 1089 | static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm) |
| 1090 | { |
| 1091 | return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm)); |
| 1092 | } |
| 1093 | |
| 1094 | static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm) |
| 1095 | { |
| 1096 | return crypto_tfm_get_flags(crypto_cipher_tfm(tfm)); |
| 1097 | } |
| 1098 | |
| 1099 | static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm, |
| 1100 | u32 flags) |
| 1101 | { |
| 1102 | crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags); |
| 1103 | } |
| 1104 | |
| 1105 | static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm, |
| 1106 | u32 flags) |
| 1107 | { |
| 1108 | crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags); |
| 1109 | } |
| 1110 | |
Herbert Xu | 7226bc8 | 2006-08-21 21:40:49 +1000 | [diff] [blame] | 1111 | static inline int crypto_cipher_setkey(struct crypto_cipher *tfm, |
| 1112 | const u8 *key, unsigned int keylen) |
| 1113 | { |
| 1114 | return crypto_cipher_crt(tfm)->cit_setkey(crypto_cipher_tfm(tfm), |
| 1115 | key, keylen); |
| 1116 | } |
| 1117 | |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 1118 | static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm, |
| 1119 | u8 *dst, const u8 *src) |
| 1120 | { |
| 1121 | crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm), |
| 1122 | dst, src); |
| 1123 | } |
| 1124 | |
| 1125 | static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm, |
| 1126 | u8 *dst, const u8 *src) |
| 1127 | { |
| 1128 | crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm), |
| 1129 | dst, src); |
| 1130 | } |
| 1131 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 1132 | static inline struct crypto_hash *__crypto_hash_cast(struct crypto_tfm *tfm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | { |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 1134 | return (struct crypto_hash *)tfm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 1137 | static inline struct crypto_hash *crypto_hash_cast(struct crypto_tfm *tfm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | { |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 1139 | BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_HASH) & |
| 1140 | CRYPTO_ALG_TYPE_HASH_MASK); |
| 1141 | return __crypto_hash_cast(tfm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 1144 | static inline struct crypto_hash *crypto_alloc_hash(const char *alg_name, |
| 1145 | u32 type, u32 mask) |
| 1146 | { |
| 1147 | type &= ~CRYPTO_ALG_TYPE_MASK; |
Herbert Xu | 551a09a | 2007-12-01 21:47:07 +1100 | [diff] [blame] | 1148 | mask &= ~CRYPTO_ALG_TYPE_MASK; |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 1149 | type |= CRYPTO_ALG_TYPE_HASH; |
| 1150 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; |
| 1151 | |
| 1152 | return __crypto_hash_cast(crypto_alloc_base(alg_name, type, mask)); |
| 1153 | } |
| 1154 | |
| 1155 | static inline struct crypto_tfm *crypto_hash_tfm(struct crypto_hash *tfm) |
| 1156 | { |
| 1157 | return &tfm->base; |
| 1158 | } |
| 1159 | |
| 1160 | static inline void crypto_free_hash(struct crypto_hash *tfm) |
| 1161 | { |
| 1162 | crypto_free_tfm(crypto_hash_tfm(tfm)); |
| 1163 | } |
| 1164 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 1165 | static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask) |
| 1166 | { |
| 1167 | type &= ~CRYPTO_ALG_TYPE_MASK; |
Herbert Xu | 551a09a | 2007-12-01 21:47:07 +1100 | [diff] [blame] | 1168 | mask &= ~CRYPTO_ALG_TYPE_MASK; |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 1169 | type |= CRYPTO_ALG_TYPE_HASH; |
| 1170 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; |
| 1171 | |
| 1172 | return crypto_has_alg(alg_name, type, mask); |
| 1173 | } |
| 1174 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 1175 | static inline struct hash_tfm *crypto_hash_crt(struct crypto_hash *tfm) |
| 1176 | { |
| 1177 | return &crypto_hash_tfm(tfm)->crt_hash; |
| 1178 | } |
| 1179 | |
| 1180 | static inline unsigned int crypto_hash_blocksize(struct crypto_hash *tfm) |
| 1181 | { |
| 1182 | return crypto_tfm_alg_blocksize(crypto_hash_tfm(tfm)); |
| 1183 | } |
| 1184 | |
| 1185 | static inline unsigned int crypto_hash_alignmask(struct crypto_hash *tfm) |
| 1186 | { |
| 1187 | return crypto_tfm_alg_alignmask(crypto_hash_tfm(tfm)); |
| 1188 | } |
| 1189 | |
| 1190 | static inline unsigned int crypto_hash_digestsize(struct crypto_hash *tfm) |
| 1191 | { |
| 1192 | return crypto_hash_crt(tfm)->digestsize; |
| 1193 | } |
| 1194 | |
| 1195 | static inline u32 crypto_hash_get_flags(struct crypto_hash *tfm) |
| 1196 | { |
| 1197 | return crypto_tfm_get_flags(crypto_hash_tfm(tfm)); |
| 1198 | } |
| 1199 | |
| 1200 | static inline void crypto_hash_set_flags(struct crypto_hash *tfm, u32 flags) |
| 1201 | { |
| 1202 | crypto_tfm_set_flags(crypto_hash_tfm(tfm), flags); |
| 1203 | } |
| 1204 | |
| 1205 | static inline void crypto_hash_clear_flags(struct crypto_hash *tfm, u32 flags) |
| 1206 | { |
| 1207 | crypto_tfm_clear_flags(crypto_hash_tfm(tfm), flags); |
| 1208 | } |
| 1209 | |
| 1210 | static inline int crypto_hash_init(struct hash_desc *desc) |
| 1211 | { |
| 1212 | return crypto_hash_crt(desc->tfm)->init(desc); |
| 1213 | } |
| 1214 | |
| 1215 | static inline int crypto_hash_update(struct hash_desc *desc, |
| 1216 | struct scatterlist *sg, |
| 1217 | unsigned int nbytes) |
| 1218 | { |
| 1219 | return crypto_hash_crt(desc->tfm)->update(desc, sg, nbytes); |
| 1220 | } |
| 1221 | |
| 1222 | static inline int crypto_hash_final(struct hash_desc *desc, u8 *out) |
| 1223 | { |
| 1224 | return crypto_hash_crt(desc->tfm)->final(desc, out); |
| 1225 | } |
| 1226 | |
| 1227 | static inline int crypto_hash_digest(struct hash_desc *desc, |
| 1228 | struct scatterlist *sg, |
| 1229 | unsigned int nbytes, u8 *out) |
| 1230 | { |
| 1231 | return crypto_hash_crt(desc->tfm)->digest(desc, sg, nbytes, out); |
| 1232 | } |
| 1233 | |
| 1234 | static inline int crypto_hash_setkey(struct crypto_hash *hash, |
| 1235 | const u8 *key, unsigned int keylen) |
| 1236 | { |
| 1237 | return crypto_hash_crt(hash)->setkey(hash, key, keylen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 1240 | static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm) |
| 1241 | { |
| 1242 | return (struct crypto_comp *)tfm; |
| 1243 | } |
| 1244 | |
| 1245 | static inline struct crypto_comp *crypto_comp_cast(struct crypto_tfm *tfm) |
| 1246 | { |
| 1247 | BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_COMPRESS) & |
| 1248 | CRYPTO_ALG_TYPE_MASK); |
| 1249 | return __crypto_comp_cast(tfm); |
| 1250 | } |
| 1251 | |
| 1252 | static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name, |
| 1253 | u32 type, u32 mask) |
| 1254 | { |
| 1255 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 1256 | type |= CRYPTO_ALG_TYPE_COMPRESS; |
| 1257 | mask |= CRYPTO_ALG_TYPE_MASK; |
| 1258 | |
| 1259 | return __crypto_comp_cast(crypto_alloc_base(alg_name, type, mask)); |
| 1260 | } |
| 1261 | |
| 1262 | static inline struct crypto_tfm *crypto_comp_tfm(struct crypto_comp *tfm) |
| 1263 | { |
Herbert Xu | 78a1fe4 | 2006-12-24 10:02:00 +1100 | [diff] [blame] | 1264 | return &tfm->base; |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | static inline void crypto_free_comp(struct crypto_comp *tfm) |
| 1268 | { |
| 1269 | crypto_free_tfm(crypto_comp_tfm(tfm)); |
| 1270 | } |
| 1271 | |
| 1272 | static inline int crypto_has_comp(const char *alg_name, u32 type, u32 mask) |
| 1273 | { |
| 1274 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 1275 | type |= CRYPTO_ALG_TYPE_COMPRESS; |
| 1276 | mask |= CRYPTO_ALG_TYPE_MASK; |
| 1277 | |
| 1278 | return crypto_has_alg(alg_name, type, mask); |
| 1279 | } |
| 1280 | |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 1281 | static inline const char *crypto_comp_name(struct crypto_comp *tfm) |
| 1282 | { |
| 1283 | return crypto_tfm_alg_name(crypto_comp_tfm(tfm)); |
| 1284 | } |
| 1285 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 1286 | static inline struct compress_tfm *crypto_comp_crt(struct crypto_comp *tfm) |
| 1287 | { |
| 1288 | return &crypto_comp_tfm(tfm)->crt_compress; |
| 1289 | } |
| 1290 | |
| 1291 | static inline int crypto_comp_compress(struct crypto_comp *tfm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | const u8 *src, unsigned int slen, |
| 1293 | u8 *dst, unsigned int *dlen) |
| 1294 | { |
Herbert Xu | 78a1fe4 | 2006-12-24 10:02:00 +1100 | [diff] [blame] | 1295 | return crypto_comp_crt(tfm)->cot_compress(crypto_comp_tfm(tfm), |
| 1296 | src, slen, dst, dlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 1299 | static inline int crypto_comp_decompress(struct crypto_comp *tfm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | const u8 *src, unsigned int slen, |
| 1301 | u8 *dst, unsigned int *dlen) |
| 1302 | { |
Herbert Xu | 78a1fe4 | 2006-12-24 10:02:00 +1100 | [diff] [blame] | 1303 | return crypto_comp_crt(tfm)->cot_decompress(crypto_comp_tfm(tfm), |
| 1304 | src, slen, dst, dlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | #endif /* _LINUX_CRYPTO_H */ |
| 1308 | |