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