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