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> |
| 9 | * and Nettle, by Niels Möller. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the Free |
| 13 | * Software Foundation; either version 2 of the License, or (at your option) |
| 14 | * any later version. |
| 15 | * |
| 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 |
| 36 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000005 |
| 37 | |
| 38 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Herbert Xu | 2825982 | 2006-08-06 21:23:26 +1000 | [diff] [blame] | 40 | #define CRYPTO_ALG_LARVAL 0x00000010 |
Herbert Xu | 6bfd480 | 2006-09-21 11:39:29 +1000 | [diff] [blame] | 41 | #define CRYPTO_ALG_DEAD 0x00000020 |
| 42 | #define CRYPTO_ALG_DYING 0x00000040 |
Herbert Xu | f3f632d | 2006-08-06 23:12:59 +1000 | [diff] [blame] | 43 | #define CRYPTO_ALG_ASYNC 0x00000080 |
Herbert Xu | 2825982 | 2006-08-06 21:23:26 +1000 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* |
Herbert Xu | 6010439 | 2006-08-26 18:34:10 +1000 | [diff] [blame] | 46 | * Set this bit if and only if the algorithm requires another algorithm of |
| 47 | * the same type to handle corner cases. |
| 48 | */ |
| 49 | #define CRYPTO_ALG_NEED_FALLBACK 0x00000100 |
| 50 | |
| 51 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | * Transform masks and values (for crt_flags). |
| 53 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #define CRYPTO_TFM_REQ_MASK 0x000fff00 |
| 55 | #define CRYPTO_TFM_RES_MASK 0xfff00000 |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100 |
Herbert Xu | 64baf3c | 2005-09-01 17:43:05 -0700 | [diff] [blame] | 58 | #define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #define CRYPTO_TFM_RES_WEAK_KEY 0x00100000 |
| 60 | #define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000 |
| 61 | #define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000 |
| 62 | #define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000 |
| 63 | #define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000 |
| 64 | |
| 65 | /* |
| 66 | * Miscellaneous stuff. |
| 67 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #define CRYPTO_MAX_ALG_NAME 64 |
| 69 | |
Herbert Xu | 7991110 | 2006-08-21 21:03:52 +1000 | [diff] [blame] | 70 | /* |
| 71 | * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual |
| 72 | * declaration) is used to ensure that the crypto_tfm context structure is |
| 73 | * aligned correctly for the given architecture so that there are no alignment |
| 74 | * faults for C data types. In particular, this is required on platforms such |
| 75 | * as arm where pointers are 32-bit aligned but there are data types such as |
| 76 | * u64 which require 64-bit alignment. |
| 77 | */ |
| 78 | #if defined(ARCH_KMALLOC_MINALIGN) |
| 79 | #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN |
| 80 | #elif defined(ARCH_SLAB_MINALIGN) |
| 81 | #define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN |
| 82 | #endif |
| 83 | |
| 84 | #ifdef CRYPTO_MINALIGN |
| 85 | #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN))) |
| 86 | #else |
| 87 | #define CRYPTO_MINALIGN_ATTR |
| 88 | #endif |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | struct scatterlist; |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 91 | struct crypto_blkcipher; |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 92 | struct crypto_hash; |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 93 | struct crypto_tfm; |
Herbert Xu | e853c3c | 2006-08-22 00:06:54 +1000 | [diff] [blame] | 94 | struct crypto_type; |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 95 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 96 | struct blkcipher_desc { |
| 97 | struct crypto_blkcipher *tfm; |
| 98 | void *info; |
| 99 | u32 flags; |
| 100 | }; |
| 101 | |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 102 | struct cipher_desc { |
| 103 | struct crypto_tfm *tfm; |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 104 | void (*crfn)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 105 | unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst, |
| 106 | const u8 *src, unsigned int nbytes); |
| 107 | void *info; |
| 108 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 110 | struct hash_desc { |
| 111 | struct crypto_hash *tfm; |
| 112 | u32 flags; |
| 113 | }; |
| 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /* |
| 116 | * Algorithms: modular crypto algorithm implementations, managed |
| 117 | * via crypto_register_alg() and crypto_unregister_alg(). |
| 118 | */ |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 119 | struct blkcipher_alg { |
| 120 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, |
| 121 | unsigned int keylen); |
| 122 | int (*encrypt)(struct blkcipher_desc *desc, |
| 123 | struct scatterlist *dst, struct scatterlist *src, |
| 124 | unsigned int nbytes); |
| 125 | int (*decrypt)(struct blkcipher_desc *desc, |
| 126 | struct scatterlist *dst, struct scatterlist *src, |
| 127 | unsigned int nbytes); |
| 128 | |
| 129 | unsigned int min_keysize; |
| 130 | unsigned int max_keysize; |
| 131 | unsigned int ivsize; |
| 132 | }; |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | struct cipher_alg { |
| 135 | unsigned int cia_min_keysize; |
| 136 | unsigned int cia_max_keysize; |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 137 | int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key, |
Herbert Xu | 560c06a | 2006-08-13 14:16:39 +1000 | [diff] [blame] | 138 | unsigned int keylen); |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 139 | void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
| 140 | void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | struct digest_alg { |
| 144 | unsigned int dia_digestsize; |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 145 | void (*dia_init)(struct crypto_tfm *tfm); |
| 146 | void (*dia_update)(struct crypto_tfm *tfm, const u8 *data, |
| 147 | unsigned int len); |
| 148 | void (*dia_final)(struct crypto_tfm *tfm, u8 *out); |
| 149 | int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key, |
Herbert Xu | 560c06a | 2006-08-13 14:16:39 +1000 | [diff] [blame] | 150 | unsigned int keylen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 153 | struct hash_alg { |
| 154 | int (*init)(struct hash_desc *desc); |
| 155 | int (*update)(struct hash_desc *desc, struct scatterlist *sg, |
| 156 | unsigned int nbytes); |
| 157 | int (*final)(struct hash_desc *desc, u8 *out); |
| 158 | int (*digest)(struct hash_desc *desc, struct scatterlist *sg, |
| 159 | unsigned int nbytes, u8 *out); |
| 160 | int (*setkey)(struct crypto_hash *tfm, const u8 *key, |
| 161 | unsigned int keylen); |
| 162 | |
| 163 | unsigned int digestsize; |
| 164 | }; |
| 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | struct compress_alg { |
Herbert Xu | 6c2bb98 | 2006-05-16 22:09:29 +1000 | [diff] [blame] | 167 | int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src, |
| 168 | unsigned int slen, u8 *dst, unsigned int *dlen); |
| 169 | int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src, |
| 170 | unsigned int slen, u8 *dst, unsigned int *dlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | }; |
| 172 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 173 | #define cra_blkcipher cra_u.blkcipher |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | #define cra_cipher cra_u.cipher |
| 175 | #define cra_digest cra_u.digest |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 176 | #define cra_hash cra_u.hash |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | #define cra_compress cra_u.compress |
| 178 | |
| 179 | struct crypto_alg { |
| 180 | struct list_head cra_list; |
Herbert Xu | 6bfd480 | 2006-09-21 11:39:29 +1000 | [diff] [blame] | 181 | struct list_head cra_users; |
| 182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | u32 cra_flags; |
| 184 | unsigned int cra_blocksize; |
| 185 | unsigned int cra_ctxsize; |
Herbert Xu | 9547737 | 2005-07-06 13:52:09 -0700 | [diff] [blame] | 186 | unsigned int cra_alignmask; |
Herbert Xu | 5cb1454 | 2005-11-05 16:58:14 +1100 | [diff] [blame] | 187 | |
| 188 | int cra_priority; |
Herbert Xu | 6521f30 | 2006-08-06 20:28:44 +1000 | [diff] [blame] | 189 | atomic_t cra_refcnt; |
Herbert Xu | 5cb1454 | 2005-11-05 16:58:14 +1100 | [diff] [blame] | 190 | |
Herbert Xu | d913ea0 | 2006-05-21 08:45:26 +1000 | [diff] [blame] | 191 | char cra_name[CRYPTO_MAX_ALG_NAME]; |
| 192 | char cra_driver_name[CRYPTO_MAX_ALG_NAME]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Herbert Xu | e853c3c | 2006-08-22 00:06:54 +1000 | [diff] [blame] | 194 | const struct crypto_type *cra_type; |
| 195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | union { |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 197 | struct blkcipher_alg blkcipher; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | struct cipher_alg cipher; |
| 199 | struct digest_alg digest; |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 200 | struct hash_alg hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | struct compress_alg compress; |
| 202 | } cra_u; |
Herbert Xu | c7fc059 | 2006-05-24 13:02:26 +1000 | [diff] [blame] | 203 | |
| 204 | int (*cra_init)(struct crypto_tfm *tfm); |
| 205 | void (*cra_exit)(struct crypto_tfm *tfm); |
Herbert Xu | 6521f30 | 2006-08-06 20:28:44 +1000 | [diff] [blame] | 206 | void (*cra_destroy)(struct crypto_alg *alg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | struct module *cra_module; |
| 209 | }; |
| 210 | |
| 211 | /* |
| 212 | * Algorithm registration interface. |
| 213 | */ |
| 214 | int crypto_register_alg(struct crypto_alg *alg); |
| 215 | int crypto_unregister_alg(struct crypto_alg *alg); |
| 216 | |
| 217 | /* |
| 218 | * Algorithm query interface. |
| 219 | */ |
| 220 | #ifdef CONFIG_CRYPTO |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 221 | int crypto_has_alg(const char *name, u32 type, u32 mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | #else |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 223 | static inline int crypto_has_alg(const char *name, u32 type, u32 mask) |
| 224 | { |
| 225 | return 0; |
| 226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | #endif |
| 228 | |
| 229 | /* |
| 230 | * Transforms: user-instantiated objects which encapsulate algorithms |
Herbert Xu | 6d7d684 | 2006-07-30 11:53:01 +1000 | [diff] [blame] | 231 | * and core processing logic. Managed via crypto_alloc_*() and |
| 232 | * crypto_free_*(), as well as the various helpers below. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 235 | struct blkcipher_tfm { |
| 236 | void *iv; |
| 237 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, |
| 238 | unsigned int keylen); |
| 239 | int (*encrypt)(struct blkcipher_desc *desc, struct scatterlist *dst, |
| 240 | struct scatterlist *src, unsigned int nbytes); |
| 241 | int (*decrypt)(struct blkcipher_desc *desc, struct scatterlist *dst, |
| 242 | struct scatterlist *src, unsigned int nbytes); |
| 243 | }; |
| 244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | struct cipher_tfm { |
| 246 | void *cit_iv; |
| 247 | unsigned int cit_ivsize; |
| 248 | u32 cit_mode; |
| 249 | int (*cit_setkey)(struct crypto_tfm *tfm, |
| 250 | const u8 *key, unsigned int keylen); |
| 251 | int (*cit_encrypt)(struct crypto_tfm *tfm, |
| 252 | struct scatterlist *dst, |
| 253 | struct scatterlist *src, |
| 254 | unsigned int nbytes); |
| 255 | int (*cit_encrypt_iv)(struct crypto_tfm *tfm, |
| 256 | struct scatterlist *dst, |
| 257 | struct scatterlist *src, |
| 258 | unsigned int nbytes, u8 *iv); |
| 259 | int (*cit_decrypt)(struct crypto_tfm *tfm, |
| 260 | struct scatterlist *dst, |
| 261 | struct scatterlist *src, |
| 262 | unsigned int nbytes); |
| 263 | int (*cit_decrypt_iv)(struct crypto_tfm *tfm, |
| 264 | struct scatterlist *dst, |
| 265 | struct scatterlist *src, |
| 266 | unsigned int nbytes, u8 *iv); |
| 267 | void (*cit_xor_block)(u8 *dst, const u8 *src); |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 268 | void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
| 269 | 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] | 270 | }; |
| 271 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 272 | struct hash_tfm { |
| 273 | int (*init)(struct hash_desc *desc); |
| 274 | int (*update)(struct hash_desc *desc, |
| 275 | struct scatterlist *sg, unsigned int nsg); |
| 276 | int (*final)(struct hash_desc *desc, u8 *out); |
| 277 | int (*digest)(struct hash_desc *desc, struct scatterlist *sg, |
| 278 | unsigned int nsg, u8 *out); |
| 279 | int (*setkey)(struct crypto_hash *tfm, const u8 *key, |
| 280 | unsigned int keylen); |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 281 | unsigned int digestsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | }; |
| 283 | |
| 284 | struct compress_tfm { |
| 285 | int (*cot_compress)(struct crypto_tfm *tfm, |
| 286 | const u8 *src, unsigned int slen, |
| 287 | u8 *dst, unsigned int *dlen); |
| 288 | int (*cot_decompress)(struct crypto_tfm *tfm, |
| 289 | const u8 *src, unsigned int slen, |
| 290 | u8 *dst, unsigned int *dlen); |
| 291 | }; |
| 292 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 293 | #define crt_blkcipher crt_u.blkcipher |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | #define crt_cipher crt_u.cipher |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 295 | #define crt_hash crt_u.hash |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | #define crt_compress crt_u.compress |
| 297 | |
| 298 | struct crypto_tfm { |
| 299 | |
| 300 | u32 crt_flags; |
| 301 | |
| 302 | union { |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 303 | struct blkcipher_tfm blkcipher; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | struct cipher_tfm cipher; |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 305 | struct hash_tfm hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | struct compress_tfm compress; |
| 307 | } crt_u; |
| 308 | |
| 309 | struct crypto_alg *__crt_alg; |
Herbert Xu | f10b789 | 2006-01-25 22:34:01 +1100 | [diff] [blame] | 310 | |
Herbert Xu | 7991110 | 2006-08-21 21:03:52 +1000 | [diff] [blame] | 311 | void *__crt_ctx[] CRYPTO_MINALIGN_ATTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | }; |
| 313 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 314 | struct crypto_blkcipher { |
| 315 | struct crypto_tfm base; |
| 316 | }; |
| 317 | |
Herbert Xu | 78a1fe4 | 2006-12-24 10:02:00 +1100 | [diff] [blame] | 318 | struct crypto_cipher { |
| 319 | struct crypto_tfm base; |
| 320 | }; |
| 321 | |
| 322 | struct crypto_comp { |
| 323 | struct crypto_tfm base; |
| 324 | }; |
| 325 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 326 | struct crypto_hash { |
| 327 | struct crypto_tfm base; |
| 328 | }; |
| 329 | |
Herbert Xu | 2b8c19d | 2006-09-21 11:31:44 +1000 | [diff] [blame] | 330 | enum { |
| 331 | CRYPTOA_UNSPEC, |
| 332 | CRYPTOA_ALG, |
| 333 | }; |
| 334 | |
| 335 | struct crypto_attr_alg { |
| 336 | char name[CRYPTO_MAX_ALG_NAME]; |
| 337 | }; |
| 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | /* |
| 340 | * Transform user interface. |
| 341 | */ |
| 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | 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] | 344 | 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] | 345 | void crypto_free_tfm(struct crypto_tfm *tfm); |
| 346 | |
| 347 | /* |
| 348 | * Transform helpers which query the underlying algorithm. |
| 349 | */ |
| 350 | static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm) |
| 351 | { |
| 352 | return tfm->__crt_alg->cra_name; |
| 353 | } |
| 354 | |
Michal Ludvig | b14cdd6 | 2006-07-09 09:02:24 +1000 | [diff] [blame] | 355 | static inline const char *crypto_tfm_alg_driver_name(struct crypto_tfm *tfm) |
| 356 | { |
| 357 | return tfm->__crt_alg->cra_driver_name; |
| 358 | } |
| 359 | |
| 360 | static inline int crypto_tfm_alg_priority(struct crypto_tfm *tfm) |
| 361 | { |
| 362 | return tfm->__crt_alg->cra_priority; |
| 363 | } |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | static inline const char *crypto_tfm_alg_modname(struct crypto_tfm *tfm) |
| 366 | { |
| 367 | return module_name(tfm->__crt_alg->cra_module); |
| 368 | } |
| 369 | |
| 370 | static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm) |
| 371 | { |
| 372 | return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK; |
| 373 | } |
| 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm) |
| 376 | { |
| 377 | return tfm->__crt_alg->cra_blocksize; |
| 378 | } |
| 379 | |
Herbert Xu | fbdae9f | 2005-07-06 13:53:29 -0700 | [diff] [blame] | 380 | static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm) |
| 381 | { |
| 382 | return tfm->__crt_alg->cra_alignmask; |
| 383 | } |
| 384 | |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 385 | static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm) |
| 386 | { |
| 387 | return tfm->crt_flags; |
| 388 | } |
| 389 | |
| 390 | static inline void crypto_tfm_set_flags(struct crypto_tfm *tfm, u32 flags) |
| 391 | { |
| 392 | tfm->crt_flags |= flags; |
| 393 | } |
| 394 | |
| 395 | static inline void crypto_tfm_clear_flags(struct crypto_tfm *tfm, u32 flags) |
| 396 | { |
| 397 | tfm->crt_flags &= ~flags; |
| 398 | } |
| 399 | |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 400 | static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) |
| 401 | { |
Herbert Xu | f10b789 | 2006-01-25 22:34:01 +1100 | [diff] [blame] | 402 | return tfm->__crt_ctx; |
| 403 | } |
| 404 | |
| 405 | static inline unsigned int crypto_tfm_ctx_alignment(void) |
| 406 | { |
| 407 | struct crypto_tfm *tfm; |
| 408 | return __alignof__(tfm->__crt_ctx); |
Herbert Xu | 4072518 | 2005-07-06 13:51:52 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | /* |
| 412 | * API wrappers. |
| 413 | */ |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 414 | static inline struct crypto_blkcipher *__crypto_blkcipher_cast( |
| 415 | struct crypto_tfm *tfm) |
| 416 | { |
| 417 | return (struct crypto_blkcipher *)tfm; |
| 418 | } |
| 419 | |
| 420 | static inline struct crypto_blkcipher *crypto_blkcipher_cast( |
| 421 | struct crypto_tfm *tfm) |
| 422 | { |
| 423 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_BLKCIPHER); |
| 424 | return __crypto_blkcipher_cast(tfm); |
| 425 | } |
| 426 | |
| 427 | static inline struct crypto_blkcipher *crypto_alloc_blkcipher( |
| 428 | const char *alg_name, u32 type, u32 mask) |
| 429 | { |
| 430 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 431 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
| 432 | mask |= CRYPTO_ALG_TYPE_MASK; |
| 433 | |
| 434 | return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask)); |
| 435 | } |
| 436 | |
| 437 | static inline struct crypto_tfm *crypto_blkcipher_tfm( |
| 438 | struct crypto_blkcipher *tfm) |
| 439 | { |
| 440 | return &tfm->base; |
| 441 | } |
| 442 | |
| 443 | static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm) |
| 444 | { |
| 445 | crypto_free_tfm(crypto_blkcipher_tfm(tfm)); |
| 446 | } |
| 447 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 448 | static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask) |
| 449 | { |
| 450 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 451 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
| 452 | mask |= CRYPTO_ALG_TYPE_MASK; |
| 453 | |
| 454 | return crypto_has_alg(alg_name, type, mask); |
| 455 | } |
| 456 | |
Herbert Xu | 5cde0af | 2006-08-22 00:07:53 +1000 | [diff] [blame] | 457 | static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm) |
| 458 | { |
| 459 | return crypto_tfm_alg_name(crypto_blkcipher_tfm(tfm)); |
| 460 | } |
| 461 | |
| 462 | static inline struct blkcipher_tfm *crypto_blkcipher_crt( |
| 463 | struct crypto_blkcipher *tfm) |
| 464 | { |
| 465 | return &crypto_blkcipher_tfm(tfm)->crt_blkcipher; |
| 466 | } |
| 467 | |
| 468 | static inline struct blkcipher_alg *crypto_blkcipher_alg( |
| 469 | struct crypto_blkcipher *tfm) |
| 470 | { |
| 471 | return &crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher; |
| 472 | } |
| 473 | |
| 474 | static inline unsigned int crypto_blkcipher_ivsize(struct crypto_blkcipher *tfm) |
| 475 | { |
| 476 | return crypto_blkcipher_alg(tfm)->ivsize; |
| 477 | } |
| 478 | |
| 479 | static inline unsigned int crypto_blkcipher_blocksize( |
| 480 | struct crypto_blkcipher *tfm) |
| 481 | { |
| 482 | return crypto_tfm_alg_blocksize(crypto_blkcipher_tfm(tfm)); |
| 483 | } |
| 484 | |
| 485 | static inline unsigned int crypto_blkcipher_alignmask( |
| 486 | struct crypto_blkcipher *tfm) |
| 487 | { |
| 488 | return crypto_tfm_alg_alignmask(crypto_blkcipher_tfm(tfm)); |
| 489 | } |
| 490 | |
| 491 | static inline u32 crypto_blkcipher_get_flags(struct crypto_blkcipher *tfm) |
| 492 | { |
| 493 | return crypto_tfm_get_flags(crypto_blkcipher_tfm(tfm)); |
| 494 | } |
| 495 | |
| 496 | static inline void crypto_blkcipher_set_flags(struct crypto_blkcipher *tfm, |
| 497 | u32 flags) |
| 498 | { |
| 499 | crypto_tfm_set_flags(crypto_blkcipher_tfm(tfm), flags); |
| 500 | } |
| 501 | |
| 502 | static inline void crypto_blkcipher_clear_flags(struct crypto_blkcipher *tfm, |
| 503 | u32 flags) |
| 504 | { |
| 505 | crypto_tfm_clear_flags(crypto_blkcipher_tfm(tfm), flags); |
| 506 | } |
| 507 | |
| 508 | static inline int crypto_blkcipher_setkey(struct crypto_blkcipher *tfm, |
| 509 | const u8 *key, unsigned int keylen) |
| 510 | { |
| 511 | return crypto_blkcipher_crt(tfm)->setkey(crypto_blkcipher_tfm(tfm), |
| 512 | key, keylen); |
| 513 | } |
| 514 | |
| 515 | static inline int crypto_blkcipher_encrypt(struct blkcipher_desc *desc, |
| 516 | struct scatterlist *dst, |
| 517 | struct scatterlist *src, |
| 518 | unsigned int nbytes) |
| 519 | { |
| 520 | desc->info = crypto_blkcipher_crt(desc->tfm)->iv; |
| 521 | return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes); |
| 522 | } |
| 523 | |
| 524 | static inline int crypto_blkcipher_encrypt_iv(struct blkcipher_desc *desc, |
| 525 | struct scatterlist *dst, |
| 526 | struct scatterlist *src, |
| 527 | unsigned int nbytes) |
| 528 | { |
| 529 | return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes); |
| 530 | } |
| 531 | |
| 532 | static inline int crypto_blkcipher_decrypt(struct blkcipher_desc *desc, |
| 533 | struct scatterlist *dst, |
| 534 | struct scatterlist *src, |
| 535 | unsigned int nbytes) |
| 536 | { |
| 537 | desc->info = crypto_blkcipher_crt(desc->tfm)->iv; |
| 538 | return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes); |
| 539 | } |
| 540 | |
| 541 | static inline int crypto_blkcipher_decrypt_iv(struct blkcipher_desc *desc, |
| 542 | struct scatterlist *dst, |
| 543 | struct scatterlist *src, |
| 544 | unsigned int nbytes) |
| 545 | { |
| 546 | return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes); |
| 547 | } |
| 548 | |
| 549 | static inline void crypto_blkcipher_set_iv(struct crypto_blkcipher *tfm, |
| 550 | const u8 *src, unsigned int len) |
| 551 | { |
| 552 | memcpy(crypto_blkcipher_crt(tfm)->iv, src, len); |
| 553 | } |
| 554 | |
| 555 | static inline void crypto_blkcipher_get_iv(struct crypto_blkcipher *tfm, |
| 556 | u8 *dst, unsigned int len) |
| 557 | { |
| 558 | memcpy(dst, crypto_blkcipher_crt(tfm)->iv, len); |
| 559 | } |
| 560 | |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 561 | static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm) |
| 562 | { |
| 563 | return (struct crypto_cipher *)tfm; |
| 564 | } |
| 565 | |
| 566 | static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm) |
| 567 | { |
| 568 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
| 569 | return __crypto_cipher_cast(tfm); |
| 570 | } |
| 571 | |
| 572 | static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name, |
| 573 | u32 type, u32 mask) |
| 574 | { |
| 575 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 576 | type |= CRYPTO_ALG_TYPE_CIPHER; |
| 577 | mask |= CRYPTO_ALG_TYPE_MASK; |
| 578 | |
| 579 | return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask)); |
| 580 | } |
| 581 | |
| 582 | static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm) |
| 583 | { |
Herbert Xu | 78a1fe4 | 2006-12-24 10:02:00 +1100 | [diff] [blame] | 584 | return &tfm->base; |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | static inline void crypto_free_cipher(struct crypto_cipher *tfm) |
| 588 | { |
| 589 | crypto_free_tfm(crypto_cipher_tfm(tfm)); |
| 590 | } |
| 591 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 592 | static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask) |
| 593 | { |
| 594 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 595 | type |= CRYPTO_ALG_TYPE_CIPHER; |
| 596 | mask |= CRYPTO_ALG_TYPE_MASK; |
| 597 | |
| 598 | return crypto_has_alg(alg_name, type, mask); |
| 599 | } |
| 600 | |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 601 | static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm) |
| 602 | { |
| 603 | return &crypto_cipher_tfm(tfm)->crt_cipher; |
| 604 | } |
| 605 | |
| 606 | static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm) |
| 607 | { |
| 608 | return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm)); |
| 609 | } |
| 610 | |
| 611 | static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm) |
| 612 | { |
| 613 | return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm)); |
| 614 | } |
| 615 | |
| 616 | static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm) |
| 617 | { |
| 618 | return crypto_tfm_get_flags(crypto_cipher_tfm(tfm)); |
| 619 | } |
| 620 | |
| 621 | static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm, |
| 622 | u32 flags) |
| 623 | { |
| 624 | crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags); |
| 625 | } |
| 626 | |
| 627 | static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm, |
| 628 | u32 flags) |
| 629 | { |
| 630 | crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags); |
| 631 | } |
| 632 | |
Herbert Xu | 7226bc8 | 2006-08-21 21:40:49 +1000 | [diff] [blame] | 633 | static inline int crypto_cipher_setkey(struct crypto_cipher *tfm, |
| 634 | const u8 *key, unsigned int keylen) |
| 635 | { |
| 636 | return crypto_cipher_crt(tfm)->cit_setkey(crypto_cipher_tfm(tfm), |
| 637 | key, keylen); |
| 638 | } |
| 639 | |
Herbert Xu | f28776a | 2006-08-13 20:58:18 +1000 | [diff] [blame] | 640 | static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm, |
| 641 | u8 *dst, const u8 *src) |
| 642 | { |
| 643 | crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm), |
| 644 | dst, src); |
| 645 | } |
| 646 | |
| 647 | static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm, |
| 648 | u8 *dst, const u8 *src) |
| 649 | { |
| 650 | crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm), |
| 651 | dst, src); |
| 652 | } |
| 653 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 654 | static inline struct crypto_hash *__crypto_hash_cast(struct crypto_tfm *tfm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | { |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 656 | return (struct crypto_hash *)tfm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 659 | static inline struct crypto_hash *crypto_hash_cast(struct crypto_tfm *tfm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | { |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 661 | BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_HASH) & |
| 662 | CRYPTO_ALG_TYPE_HASH_MASK); |
| 663 | return __crypto_hash_cast(tfm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 666 | static inline struct crypto_hash *crypto_alloc_hash(const char *alg_name, |
| 667 | u32 type, u32 mask) |
| 668 | { |
| 669 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 670 | type |= CRYPTO_ALG_TYPE_HASH; |
| 671 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; |
| 672 | |
| 673 | return __crypto_hash_cast(crypto_alloc_base(alg_name, type, mask)); |
| 674 | } |
| 675 | |
| 676 | static inline struct crypto_tfm *crypto_hash_tfm(struct crypto_hash *tfm) |
| 677 | { |
| 678 | return &tfm->base; |
| 679 | } |
| 680 | |
| 681 | static inline void crypto_free_hash(struct crypto_hash *tfm) |
| 682 | { |
| 683 | crypto_free_tfm(crypto_hash_tfm(tfm)); |
| 684 | } |
| 685 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 686 | static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask) |
| 687 | { |
| 688 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 689 | type |= CRYPTO_ALG_TYPE_HASH; |
| 690 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; |
| 691 | |
| 692 | return crypto_has_alg(alg_name, type, mask); |
| 693 | } |
| 694 | |
Herbert Xu | 055bcee | 2006-08-19 22:24:23 +1000 | [diff] [blame] | 695 | static inline struct hash_tfm *crypto_hash_crt(struct crypto_hash *tfm) |
| 696 | { |
| 697 | return &crypto_hash_tfm(tfm)->crt_hash; |
| 698 | } |
| 699 | |
| 700 | static inline unsigned int crypto_hash_blocksize(struct crypto_hash *tfm) |
| 701 | { |
| 702 | return crypto_tfm_alg_blocksize(crypto_hash_tfm(tfm)); |
| 703 | } |
| 704 | |
| 705 | static inline unsigned int crypto_hash_alignmask(struct crypto_hash *tfm) |
| 706 | { |
| 707 | return crypto_tfm_alg_alignmask(crypto_hash_tfm(tfm)); |
| 708 | } |
| 709 | |
| 710 | static inline unsigned int crypto_hash_digestsize(struct crypto_hash *tfm) |
| 711 | { |
| 712 | return crypto_hash_crt(tfm)->digestsize; |
| 713 | } |
| 714 | |
| 715 | static inline u32 crypto_hash_get_flags(struct crypto_hash *tfm) |
| 716 | { |
| 717 | return crypto_tfm_get_flags(crypto_hash_tfm(tfm)); |
| 718 | } |
| 719 | |
| 720 | static inline void crypto_hash_set_flags(struct crypto_hash *tfm, u32 flags) |
| 721 | { |
| 722 | crypto_tfm_set_flags(crypto_hash_tfm(tfm), flags); |
| 723 | } |
| 724 | |
| 725 | static inline void crypto_hash_clear_flags(struct crypto_hash *tfm, u32 flags) |
| 726 | { |
| 727 | crypto_tfm_clear_flags(crypto_hash_tfm(tfm), flags); |
| 728 | } |
| 729 | |
| 730 | static inline int crypto_hash_init(struct hash_desc *desc) |
| 731 | { |
| 732 | return crypto_hash_crt(desc->tfm)->init(desc); |
| 733 | } |
| 734 | |
| 735 | static inline int crypto_hash_update(struct hash_desc *desc, |
| 736 | struct scatterlist *sg, |
| 737 | unsigned int nbytes) |
| 738 | { |
| 739 | return crypto_hash_crt(desc->tfm)->update(desc, sg, nbytes); |
| 740 | } |
| 741 | |
| 742 | static inline int crypto_hash_final(struct hash_desc *desc, u8 *out) |
| 743 | { |
| 744 | return crypto_hash_crt(desc->tfm)->final(desc, out); |
| 745 | } |
| 746 | |
| 747 | static inline int crypto_hash_digest(struct hash_desc *desc, |
| 748 | struct scatterlist *sg, |
| 749 | unsigned int nbytes, u8 *out) |
| 750 | { |
| 751 | return crypto_hash_crt(desc->tfm)->digest(desc, sg, nbytes, out); |
| 752 | } |
| 753 | |
| 754 | static inline int crypto_hash_setkey(struct crypto_hash *hash, |
| 755 | const u8 *key, unsigned int keylen) |
| 756 | { |
| 757 | return crypto_hash_crt(hash)->setkey(hash, key, keylen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 760 | static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm) |
| 761 | { |
| 762 | return (struct crypto_comp *)tfm; |
| 763 | } |
| 764 | |
| 765 | static inline struct crypto_comp *crypto_comp_cast(struct crypto_tfm *tfm) |
| 766 | { |
| 767 | BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_COMPRESS) & |
| 768 | CRYPTO_ALG_TYPE_MASK); |
| 769 | return __crypto_comp_cast(tfm); |
| 770 | } |
| 771 | |
| 772 | static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name, |
| 773 | u32 type, u32 mask) |
| 774 | { |
| 775 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 776 | type |= CRYPTO_ALG_TYPE_COMPRESS; |
| 777 | mask |= CRYPTO_ALG_TYPE_MASK; |
| 778 | |
| 779 | return __crypto_comp_cast(crypto_alloc_base(alg_name, type, mask)); |
| 780 | } |
| 781 | |
| 782 | static inline struct crypto_tfm *crypto_comp_tfm(struct crypto_comp *tfm) |
| 783 | { |
Herbert Xu | 78a1fe4 | 2006-12-24 10:02:00 +1100 | [diff] [blame] | 784 | return &tfm->base; |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | static inline void crypto_free_comp(struct crypto_comp *tfm) |
| 788 | { |
| 789 | crypto_free_tfm(crypto_comp_tfm(tfm)); |
| 790 | } |
| 791 | |
| 792 | static inline int crypto_has_comp(const char *alg_name, u32 type, u32 mask) |
| 793 | { |
| 794 | type &= ~CRYPTO_ALG_TYPE_MASK; |
| 795 | type |= CRYPTO_ALG_TYPE_COMPRESS; |
| 796 | mask |= CRYPTO_ALG_TYPE_MASK; |
| 797 | |
| 798 | return crypto_has_alg(alg_name, type, mask); |
| 799 | } |
| 800 | |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 801 | static inline const char *crypto_comp_name(struct crypto_comp *tfm) |
| 802 | { |
| 803 | return crypto_tfm_alg_name(crypto_comp_tfm(tfm)); |
| 804 | } |
| 805 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 806 | static inline struct compress_tfm *crypto_comp_crt(struct crypto_comp *tfm) |
| 807 | { |
| 808 | return &crypto_comp_tfm(tfm)->crt_compress; |
| 809 | } |
| 810 | |
| 811 | static inline int crypto_comp_compress(struct crypto_comp *tfm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | const u8 *src, unsigned int slen, |
| 813 | u8 *dst, unsigned int *dlen) |
| 814 | { |
Herbert Xu | 78a1fe4 | 2006-12-24 10:02:00 +1100 | [diff] [blame] | 815 | return crypto_comp_crt(tfm)->cot_compress(crypto_comp_tfm(tfm), |
| 816 | src, slen, dst, dlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | } |
| 818 | |
Herbert Xu | fce32d7 | 2006-08-26 17:35:45 +1000 | [diff] [blame] | 819 | static inline int crypto_comp_decompress(struct crypto_comp *tfm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | const u8 *src, unsigned int slen, |
| 821 | u8 *dst, unsigned int *dlen) |
| 822 | { |
Herbert Xu | 78a1fe4 | 2006-12-24 10:02:00 +1100 | [diff] [blame] | 823 | return crypto_comp_crt(tfm)->cot_decompress(crypto_comp_tfm(tfm), |
| 824 | src, slen, dst, dlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | #endif /* _LINUX_CRYPTO_H */ |
| 828 | |