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