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