2 * Scatterlist Cryptographic API.
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>
8 * Portions derived from Cryptoapi, by Alexander Kjeldaas <astor@fast.no>
9 * and Nettle, by Niels Möller.
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)
17 #ifndef _LINUX_CRYPTO_H
18 #define _LINUX_CRYPTO_H
20 #include <asm/atomic.h>
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/types.h>
24 #include <linux/list.h>
25 #include <linux/slab.h>
26 #include <linux/string.h>
27 #include <linux/uaccess.h>
30 * Algorithm masks and types.
32 #define CRYPTO_ALG_TYPE_MASK 0x0000000f
33 #define CRYPTO_ALG_TYPE_CIPHER 0x00000001
34 #define CRYPTO_ALG_TYPE_DIGEST 0x00000002
35 #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000003
36 #define CRYPTO_ALG_TYPE_COMPRESS 0x00000004
38 #define CRYPTO_ALG_LARVAL 0x00000010
39 #define CRYPTO_ALG_DEAD 0x00000020
40 #define CRYPTO_ALG_DYING 0x00000040
41 #define CRYPTO_ALG_ASYNC 0x00000080
44 * Transform masks and values (for crt_flags).
46 #define CRYPTO_TFM_MODE_MASK 0x000000ff
47 #define CRYPTO_TFM_REQ_MASK 0x000fff00
48 #define CRYPTO_TFM_RES_MASK 0xfff00000
50 #define CRYPTO_TFM_MODE_ECB 0x00000001
51 #define CRYPTO_TFM_MODE_CBC 0x00000002
52 #define CRYPTO_TFM_MODE_CFB 0x00000004
53 #define CRYPTO_TFM_MODE_CTR 0x00000008
55 #define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100
56 #define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
57 #define CRYPTO_TFM_RES_WEAK_KEY 0x00100000
58 #define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000
59 #define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000
60 #define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000
61 #define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000
64 * Miscellaneous stuff.
66 #define CRYPTO_UNSPEC 0
67 #define CRYPTO_MAX_ALG_NAME 64
69 #define CRYPTO_DIR_ENCRYPT 1
70 #define CRYPTO_DIR_DECRYPT 0
73 * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual
74 * declaration) is used to ensure that the crypto_tfm context structure is
75 * aligned correctly for the given architecture so that there are no alignment
76 * faults for C data types. In particular, this is required on platforms such
77 * as arm where pointers are 32-bit aligned but there are data types such as
78 * u64 which require 64-bit alignment.
80 #if defined(ARCH_KMALLOC_MINALIGN)
81 #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN
82 #elif defined(ARCH_SLAB_MINALIGN)
83 #define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN
86 #ifdef CRYPTO_MINALIGN
87 #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN)))
89 #define CRYPTO_MINALIGN_ATTR
93 struct crypto_blkcipher;
97 struct blkcipher_desc {
98 struct crypto_blkcipher *tfm;
104 struct crypto_tfm *tfm;
105 void (*crfn)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
106 unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst,
107 const u8 *src, unsigned int nbytes);
112 * Algorithms: modular crypto algorithm implementations, managed
113 * via crypto_register_alg() and crypto_unregister_alg().
115 struct blkcipher_alg {
116 int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
117 unsigned int keylen);
118 int (*encrypt)(struct blkcipher_desc *desc,
119 struct scatterlist *dst, struct scatterlist *src,
120 unsigned int nbytes);
121 int (*decrypt)(struct blkcipher_desc *desc,
122 struct scatterlist *dst, struct scatterlist *src,
123 unsigned int nbytes);
125 unsigned int min_keysize;
126 unsigned int max_keysize;
131 unsigned int cia_min_keysize;
132 unsigned int cia_max_keysize;
133 int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key,
134 unsigned int keylen);
135 void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
136 void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
138 unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc,
139 u8 *dst, const u8 *src,
140 unsigned int nbytes);
141 unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc,
142 u8 *dst, const u8 *src,
143 unsigned int nbytes);
144 unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc,
145 u8 *dst, const u8 *src,
146 unsigned int nbytes);
147 unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc,
148 u8 *dst, const u8 *src,
149 unsigned int nbytes);
153 unsigned int dia_digestsize;
154 void (*dia_init)(struct crypto_tfm *tfm);
155 void (*dia_update)(struct crypto_tfm *tfm, const u8 *data,
157 void (*dia_final)(struct crypto_tfm *tfm, u8 *out);
158 int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key,
159 unsigned int keylen);
162 struct compress_alg {
163 int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src,
164 unsigned int slen, u8 *dst, unsigned int *dlen);
165 int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
166 unsigned int slen, u8 *dst, unsigned int *dlen);
169 #define cra_blkcipher cra_u.blkcipher
170 #define cra_cipher cra_u.cipher
171 #define cra_digest cra_u.digest
172 #define cra_compress cra_u.compress
175 struct list_head cra_list;
176 struct list_head cra_users;
179 unsigned int cra_blocksize;
180 unsigned int cra_ctxsize;
181 unsigned int cra_alignmask;
186 char cra_name[CRYPTO_MAX_ALG_NAME];
187 char cra_driver_name[CRYPTO_MAX_ALG_NAME];
189 const struct crypto_type *cra_type;
192 struct blkcipher_alg blkcipher;
193 struct cipher_alg cipher;
194 struct digest_alg digest;
195 struct compress_alg compress;
198 int (*cra_init)(struct crypto_tfm *tfm);
199 void (*cra_exit)(struct crypto_tfm *tfm);
200 void (*cra_destroy)(struct crypto_alg *alg);
202 struct module *cra_module;
206 * Algorithm registration interface.
208 int crypto_register_alg(struct crypto_alg *alg);
209 int crypto_unregister_alg(struct crypto_alg *alg);
212 * Algorithm query interface.
215 int crypto_alg_available(const char *name, u32 flags);
217 static inline int crypto_alg_available(const char *name, u32 flags)
224 * Transforms: user-instantiated objects which encapsulate algorithms
225 * and core processing logic. Managed via crypto_alloc_*() and
226 * crypto_free_*(), as well as the various helpers below.
229 struct blkcipher_tfm {
231 int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
232 unsigned int keylen);
233 int (*encrypt)(struct blkcipher_desc *desc, struct scatterlist *dst,
234 struct scatterlist *src, unsigned int nbytes);
235 int (*decrypt)(struct blkcipher_desc *desc, struct scatterlist *dst,
236 struct scatterlist *src, unsigned int nbytes);
241 unsigned int cit_ivsize;
243 int (*cit_setkey)(struct crypto_tfm *tfm,
244 const u8 *key, unsigned int keylen);
245 int (*cit_encrypt)(struct crypto_tfm *tfm,
246 struct scatterlist *dst,
247 struct scatterlist *src,
248 unsigned int nbytes);
249 int (*cit_encrypt_iv)(struct crypto_tfm *tfm,
250 struct scatterlist *dst,
251 struct scatterlist *src,
252 unsigned int nbytes, u8 *iv);
253 int (*cit_decrypt)(struct crypto_tfm *tfm,
254 struct scatterlist *dst,
255 struct scatterlist *src,
256 unsigned int nbytes);
257 int (*cit_decrypt_iv)(struct crypto_tfm *tfm,
258 struct scatterlist *dst,
259 struct scatterlist *src,
260 unsigned int nbytes, u8 *iv);
261 void (*cit_xor_block)(u8 *dst, const u8 *src);
262 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
263 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
267 void (*dit_init)(struct crypto_tfm *tfm);
268 void (*dit_update)(struct crypto_tfm *tfm,
269 struct scatterlist *sg, unsigned int nsg);
270 void (*dit_final)(struct crypto_tfm *tfm, u8 *out);
271 void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg,
272 unsigned int nsg, u8 *out);
273 int (*dit_setkey)(struct crypto_tfm *tfm,
274 const u8 *key, unsigned int keylen);
275 #ifdef CONFIG_CRYPTO_HMAC
276 void *dit_hmac_block;
280 struct compress_tfm {
281 int (*cot_compress)(struct crypto_tfm *tfm,
282 const u8 *src, unsigned int slen,
283 u8 *dst, unsigned int *dlen);
284 int (*cot_decompress)(struct crypto_tfm *tfm,
285 const u8 *src, unsigned int slen,
286 u8 *dst, unsigned int *dlen);
289 #define crt_blkcipher crt_u.blkcipher
290 #define crt_cipher crt_u.cipher
291 #define crt_digest crt_u.digest
292 #define crt_compress crt_u.compress
299 struct blkcipher_tfm blkcipher;
300 struct cipher_tfm cipher;
301 struct digest_tfm digest;
302 struct compress_tfm compress;
305 struct crypto_alg *__crt_alg;
307 void *__crt_ctx[] CRYPTO_MINALIGN_ATTR;
310 #define crypto_cipher crypto_tfm
312 struct crypto_blkcipher {
313 struct crypto_tfm base;
321 struct crypto_attr_alg {
322 char name[CRYPTO_MAX_ALG_NAME];
326 * Transform user interface.
329 struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags);
330 struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask);
331 void crypto_free_tfm(struct crypto_tfm *tfm);
334 * Transform helpers which query the underlying algorithm.
336 static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm)
338 return tfm->__crt_alg->cra_name;
341 static inline const char *crypto_tfm_alg_driver_name(struct crypto_tfm *tfm)
343 return tfm->__crt_alg->cra_driver_name;
346 static inline int crypto_tfm_alg_priority(struct crypto_tfm *tfm)
348 return tfm->__crt_alg->cra_priority;
351 static inline const char *crypto_tfm_alg_modname(struct crypto_tfm *tfm)
353 return module_name(tfm->__crt_alg->cra_module);
356 static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm)
358 return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK;
361 static inline unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm)
363 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
364 return tfm->__crt_alg->cra_cipher.cia_min_keysize;
367 static inline unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm)
369 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
370 return tfm->__crt_alg->cra_cipher.cia_max_keysize;
373 static inline unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm)
375 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
376 return tfm->crt_cipher.cit_ivsize;
379 static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm)
381 return tfm->__crt_alg->cra_blocksize;
384 static inline unsigned int crypto_tfm_alg_digestsize(struct crypto_tfm *tfm)
386 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
387 return tfm->__crt_alg->cra_digest.dia_digestsize;
390 static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
392 return tfm->__crt_alg->cra_alignmask;
395 static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm)
397 return tfm->crt_flags;
400 static inline void crypto_tfm_set_flags(struct crypto_tfm *tfm, u32 flags)
402 tfm->crt_flags |= flags;
405 static inline void crypto_tfm_clear_flags(struct crypto_tfm *tfm, u32 flags)
407 tfm->crt_flags &= ~flags;
410 static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
412 return tfm->__crt_ctx;
415 static inline unsigned int crypto_tfm_ctx_alignment(void)
417 struct crypto_tfm *tfm;
418 return __alignof__(tfm->__crt_ctx);
424 static inline struct crypto_blkcipher *__crypto_blkcipher_cast(
425 struct crypto_tfm *tfm)
427 return (struct crypto_blkcipher *)tfm;
430 static inline struct crypto_blkcipher *crypto_blkcipher_cast(
431 struct crypto_tfm *tfm)
433 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_BLKCIPHER);
434 return __crypto_blkcipher_cast(tfm);
437 static inline struct crypto_blkcipher *crypto_alloc_blkcipher(
438 const char *alg_name, u32 type, u32 mask)
440 type &= ~CRYPTO_ALG_TYPE_MASK;
441 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
442 mask |= CRYPTO_ALG_TYPE_MASK;
444 return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask));
447 static inline struct crypto_tfm *crypto_blkcipher_tfm(
448 struct crypto_blkcipher *tfm)
453 static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm)
455 crypto_free_tfm(crypto_blkcipher_tfm(tfm));
458 static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm)
460 return crypto_tfm_alg_name(crypto_blkcipher_tfm(tfm));
463 static inline struct blkcipher_tfm *crypto_blkcipher_crt(
464 struct crypto_blkcipher *tfm)
466 return &crypto_blkcipher_tfm(tfm)->crt_blkcipher;
469 static inline struct blkcipher_alg *crypto_blkcipher_alg(
470 struct crypto_blkcipher *tfm)
472 return &crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher;
475 static inline unsigned int crypto_blkcipher_ivsize(struct crypto_blkcipher *tfm)
477 return crypto_blkcipher_alg(tfm)->ivsize;
480 static inline unsigned int crypto_blkcipher_blocksize(
481 struct crypto_blkcipher *tfm)
483 return crypto_tfm_alg_blocksize(crypto_blkcipher_tfm(tfm));
486 static inline unsigned int crypto_blkcipher_alignmask(
487 struct crypto_blkcipher *tfm)
489 return crypto_tfm_alg_alignmask(crypto_blkcipher_tfm(tfm));
492 static inline u32 crypto_blkcipher_get_flags(struct crypto_blkcipher *tfm)
494 return crypto_tfm_get_flags(crypto_blkcipher_tfm(tfm));
497 static inline void crypto_blkcipher_set_flags(struct crypto_blkcipher *tfm,
500 crypto_tfm_set_flags(crypto_blkcipher_tfm(tfm), flags);
503 static inline void crypto_blkcipher_clear_flags(struct crypto_blkcipher *tfm,
506 crypto_tfm_clear_flags(crypto_blkcipher_tfm(tfm), flags);
509 static inline int crypto_blkcipher_setkey(struct crypto_blkcipher *tfm,
510 const u8 *key, unsigned int keylen)
512 return crypto_blkcipher_crt(tfm)->setkey(crypto_blkcipher_tfm(tfm),
516 static inline int crypto_blkcipher_encrypt(struct blkcipher_desc *desc,
517 struct scatterlist *dst,
518 struct scatterlist *src,
521 desc->info = crypto_blkcipher_crt(desc->tfm)->iv;
522 return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes);
525 static inline int crypto_blkcipher_encrypt_iv(struct blkcipher_desc *desc,
526 struct scatterlist *dst,
527 struct scatterlist *src,
530 return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes);
533 static inline int crypto_blkcipher_decrypt(struct blkcipher_desc *desc,
534 struct scatterlist *dst,
535 struct scatterlist *src,
538 desc->info = crypto_blkcipher_crt(desc->tfm)->iv;
539 return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes);
542 static inline int crypto_blkcipher_decrypt_iv(struct blkcipher_desc *desc,
543 struct scatterlist *dst,
544 struct scatterlist *src,
547 return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes);
550 static inline void crypto_blkcipher_set_iv(struct crypto_blkcipher *tfm,
551 const u8 *src, unsigned int len)
553 memcpy(crypto_blkcipher_crt(tfm)->iv, src, len);
556 static inline void crypto_blkcipher_get_iv(struct crypto_blkcipher *tfm,
557 u8 *dst, unsigned int len)
559 memcpy(dst, crypto_blkcipher_crt(tfm)->iv, len);
562 static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm)
564 return (struct crypto_cipher *)tfm;
567 static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm)
569 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
570 return __crypto_cipher_cast(tfm);
573 static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name,
576 type &= ~CRYPTO_ALG_TYPE_MASK;
577 type |= CRYPTO_ALG_TYPE_CIPHER;
578 mask |= CRYPTO_ALG_TYPE_MASK;
580 return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask));
583 static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm)
588 static inline void crypto_free_cipher(struct crypto_cipher *tfm)
590 crypto_free_tfm(crypto_cipher_tfm(tfm));
593 static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm)
595 return &crypto_cipher_tfm(tfm)->crt_cipher;
598 static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm)
600 return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm));
603 static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm)
605 return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm));
608 static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm)
610 return crypto_tfm_get_flags(crypto_cipher_tfm(tfm));
613 static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm,
616 crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags);
619 static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm,
622 crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags);
625 static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
626 u8 *dst, const u8 *src)
628 crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm),
632 static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
633 u8 *dst, const u8 *src)
635 crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm),
639 static inline void crypto_digest_init(struct crypto_tfm *tfm)
641 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
642 tfm->crt_digest.dit_init(tfm);
645 static inline void crypto_digest_update(struct crypto_tfm *tfm,
646 struct scatterlist *sg,
649 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
650 tfm->crt_digest.dit_update(tfm, sg, nsg);
653 static inline void crypto_digest_final(struct crypto_tfm *tfm, u8 *out)
655 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
656 tfm->crt_digest.dit_final(tfm, out);
659 static inline void crypto_digest_digest(struct crypto_tfm *tfm,
660 struct scatterlist *sg,
661 unsigned int nsg, u8 *out)
663 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
664 tfm->crt_digest.dit_digest(tfm, sg, nsg, out);
667 static inline int crypto_digest_setkey(struct crypto_tfm *tfm,
668 const u8 *key, unsigned int keylen)
670 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
671 return tfm->crt_digest.dit_setkey(tfm, key, keylen);
674 static inline int crypto_cipher_setkey(struct crypto_tfm *tfm,
675 const u8 *key, unsigned int keylen)
677 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
678 return tfm->crt_cipher.cit_setkey(tfm, key, keylen);
681 static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm,
682 struct scatterlist *dst,
683 struct scatterlist *src,
686 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
687 return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes);
690 static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm,
691 struct scatterlist *dst,
692 struct scatterlist *src,
693 unsigned int nbytes, u8 *iv)
695 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
696 return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv);
699 static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm,
700 struct scatterlist *dst,
701 struct scatterlist *src,
704 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
705 return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes);
708 static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm,
709 struct scatterlist *dst,
710 struct scatterlist *src,
711 unsigned int nbytes, u8 *iv)
713 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
714 return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv);
717 static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm,
718 const u8 *src, unsigned int len)
720 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
721 memcpy(tfm->crt_cipher.cit_iv, src, len);
724 static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm,
725 u8 *dst, unsigned int len)
727 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
728 memcpy(dst, tfm->crt_cipher.cit_iv, len);
731 static inline int crypto_comp_compress(struct crypto_tfm *tfm,
732 const u8 *src, unsigned int slen,
733 u8 *dst, unsigned int *dlen)
735 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS);
736 return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen);
739 static inline int crypto_comp_decompress(struct crypto_tfm *tfm,
740 const u8 *src, unsigned int slen,
741 u8 *dst, unsigned int *dlen)
743 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS);
744 return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen);
750 #ifdef CONFIG_CRYPTO_HMAC
751 void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen);
752 void crypto_hmac_update(struct crypto_tfm *tfm,
753 struct scatterlist *sg, unsigned int nsg);
754 void crypto_hmac_final(struct crypto_tfm *tfm, u8 *key,
755 unsigned int *keylen, u8 *out);
756 void crypto_hmac(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen,
757 struct scatterlist *sg, unsigned int nsg, u8 *out);
758 #endif /* CONFIG_CRYPTO_HMAC */
760 #endif /* _LINUX_CRYPTO_H */