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