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/list.h>
24 #include <linux/slab.h>
25 #include <linux/string.h>
26 #include <linux/uaccess.h>
29 * Algorithm masks and types.
31 #define CRYPTO_ALG_TYPE_MASK 0x0000000f
32 #define CRYPTO_ALG_TYPE_CIPHER 0x00000001
33 #define CRYPTO_ALG_TYPE_DIGEST 0x00000002
34 #define CRYPTO_ALG_TYPE_HASH 0x00000003
35 #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004
36 #define CRYPTO_ALG_TYPE_COMPRESS 0x00000005
38 #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
40 #define CRYPTO_ALG_LARVAL 0x00000010
41 #define CRYPTO_ALG_DEAD 0x00000020
42 #define CRYPTO_ALG_DYING 0x00000040
43 #define CRYPTO_ALG_ASYNC 0x00000080
46 * Transform masks and values (for crt_flags).
48 #define CRYPTO_TFM_MODE_MASK 0x000000ff
49 #define CRYPTO_TFM_REQ_MASK 0x000fff00
50 #define CRYPTO_TFM_RES_MASK 0xfff00000
52 #define CRYPTO_TFM_MODE_ECB 0x00000001
53 #define CRYPTO_TFM_MODE_CBC 0x00000002
54 #define CRYPTO_TFM_MODE_CFB 0x00000004
55 #define CRYPTO_TFM_MODE_CTR 0x00000008
57 #define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100
58 #define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
59 #define CRYPTO_TFM_RES_WEAK_KEY 0x00100000
60 #define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000
61 #define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000
62 #define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000
63 #define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000
66 * Miscellaneous stuff.
68 #define CRYPTO_UNSPEC 0
69 #define CRYPTO_MAX_ALG_NAME 64
71 #define CRYPTO_DIR_ENCRYPT 1
72 #define CRYPTO_DIR_DECRYPT 0
75 * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual
76 * declaration) is used to ensure that the crypto_tfm context structure is
77 * aligned correctly for the given architecture so that there are no alignment
78 * faults for C data types. In particular, this is required on platforms such
79 * as arm where pointers are 32-bit aligned but there are data types such as
80 * u64 which require 64-bit alignment.
82 #if defined(ARCH_KMALLOC_MINALIGN)
83 #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN
84 #elif defined(ARCH_SLAB_MINALIGN)
85 #define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN
88 #ifdef CRYPTO_MINALIGN
89 #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN)))
91 #define CRYPTO_MINALIGN_ATTR
95 struct crypto_blkcipher;
100 struct blkcipher_desc {
101 struct crypto_blkcipher *tfm;
107 struct crypto_tfm *tfm;
108 void (*crfn)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
109 unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst,
110 const u8 *src, unsigned int nbytes);
115 struct crypto_hash *tfm;
120 * Algorithms: modular crypto algorithm implementations, managed
121 * via crypto_register_alg() and crypto_unregister_alg().
123 struct blkcipher_alg {
124 int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
125 unsigned int keylen);
126 int (*encrypt)(struct blkcipher_desc *desc,
127 struct scatterlist *dst, struct scatterlist *src,
128 unsigned int nbytes);
129 int (*decrypt)(struct blkcipher_desc *desc,
130 struct scatterlist *dst, struct scatterlist *src,
131 unsigned int nbytes);
133 unsigned int min_keysize;
134 unsigned int max_keysize;
139 unsigned int cia_min_keysize;
140 unsigned int cia_max_keysize;
141 int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key,
142 unsigned int keylen);
143 void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
144 void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
146 unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc,
147 u8 *dst, const u8 *src,
148 unsigned int nbytes) __deprecated;
149 unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc,
150 u8 *dst, const u8 *src,
151 unsigned int nbytes) __deprecated;
152 unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc,
153 u8 *dst, const u8 *src,
154 unsigned int nbytes) __deprecated;
155 unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc,
156 u8 *dst, const u8 *src,
157 unsigned int nbytes) __deprecated;
161 unsigned int dia_digestsize;
162 void (*dia_init)(struct crypto_tfm *tfm);
163 void (*dia_update)(struct crypto_tfm *tfm, const u8 *data,
165 void (*dia_final)(struct crypto_tfm *tfm, u8 *out);
166 int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key,
167 unsigned int keylen);
171 int (*init)(struct hash_desc *desc);
172 int (*update)(struct hash_desc *desc, struct scatterlist *sg,
173 unsigned int nbytes);
174 int (*final)(struct hash_desc *desc, u8 *out);
175 int (*digest)(struct hash_desc *desc, struct scatterlist *sg,
176 unsigned int nbytes, u8 *out);
177 int (*setkey)(struct crypto_hash *tfm, const u8 *key,
178 unsigned int keylen);
180 unsigned int digestsize;
183 struct compress_alg {
184 int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src,
185 unsigned int slen, u8 *dst, unsigned int *dlen);
186 int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
187 unsigned int slen, u8 *dst, unsigned int *dlen);
190 #define cra_blkcipher cra_u.blkcipher
191 #define cra_cipher cra_u.cipher
192 #define cra_digest cra_u.digest
193 #define cra_hash cra_u.hash
194 #define cra_compress cra_u.compress
197 struct list_head cra_list;
198 struct list_head cra_users;
201 unsigned int cra_blocksize;
202 unsigned int cra_ctxsize;
203 unsigned int cra_alignmask;
208 char cra_name[CRYPTO_MAX_ALG_NAME];
209 char cra_driver_name[CRYPTO_MAX_ALG_NAME];
211 const struct crypto_type *cra_type;
214 struct blkcipher_alg blkcipher;
215 struct cipher_alg cipher;
216 struct digest_alg digest;
217 struct hash_alg hash;
218 struct compress_alg compress;
221 int (*cra_init)(struct crypto_tfm *tfm);
222 void (*cra_exit)(struct crypto_tfm *tfm);
223 void (*cra_destroy)(struct crypto_alg *alg);
225 struct module *cra_module;
229 * Algorithm registration interface.
231 int crypto_register_alg(struct crypto_alg *alg);
232 int crypto_unregister_alg(struct crypto_alg *alg);
235 * Algorithm query interface.
238 int crypto_alg_available(const char *name, u32 flags);
240 static inline int crypto_alg_available(const char *name, u32 flags)
247 * Transforms: user-instantiated objects which encapsulate algorithms
248 * and core processing logic. Managed via crypto_alloc_*() and
249 * crypto_free_*(), as well as the various helpers below.
252 struct blkcipher_tfm {
254 int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
255 unsigned int keylen);
256 int (*encrypt)(struct blkcipher_desc *desc, struct scatterlist *dst,
257 struct scatterlist *src, unsigned int nbytes);
258 int (*decrypt)(struct blkcipher_desc *desc, struct scatterlist *dst,
259 struct scatterlist *src, unsigned int nbytes);
264 unsigned int cit_ivsize;
266 int (*cit_setkey)(struct crypto_tfm *tfm,
267 const u8 *key, unsigned int keylen);
268 int (*cit_encrypt)(struct crypto_tfm *tfm,
269 struct scatterlist *dst,
270 struct scatterlist *src,
271 unsigned int nbytes);
272 int (*cit_encrypt_iv)(struct crypto_tfm *tfm,
273 struct scatterlist *dst,
274 struct scatterlist *src,
275 unsigned int nbytes, u8 *iv);
276 int (*cit_decrypt)(struct crypto_tfm *tfm,
277 struct scatterlist *dst,
278 struct scatterlist *src,
279 unsigned int nbytes);
280 int (*cit_decrypt_iv)(struct crypto_tfm *tfm,
281 struct scatterlist *dst,
282 struct scatterlist *src,
283 unsigned int nbytes, u8 *iv);
284 void (*cit_xor_block)(u8 *dst, const u8 *src);
285 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
286 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
290 int (*init)(struct hash_desc *desc);
291 int (*update)(struct hash_desc *desc,
292 struct scatterlist *sg, unsigned int nsg);
293 int (*final)(struct hash_desc *desc, u8 *out);
294 int (*digest)(struct hash_desc *desc, struct scatterlist *sg,
295 unsigned int nsg, u8 *out);
296 int (*setkey)(struct crypto_hash *tfm, const u8 *key,
297 unsigned int keylen);
298 unsigned int digestsize;
301 struct compress_tfm {
302 int (*cot_compress)(struct crypto_tfm *tfm,
303 const u8 *src, unsigned int slen,
304 u8 *dst, unsigned int *dlen);
305 int (*cot_decompress)(struct crypto_tfm *tfm,
306 const u8 *src, unsigned int slen,
307 u8 *dst, unsigned int *dlen);
310 #define crt_blkcipher crt_u.blkcipher
311 #define crt_cipher crt_u.cipher
312 #define crt_hash crt_u.hash
313 #define crt_compress crt_u.compress
320 struct blkcipher_tfm blkcipher;
321 struct cipher_tfm cipher;
322 struct hash_tfm hash;
323 struct compress_tfm compress;
326 struct crypto_alg *__crt_alg;
328 void *__crt_ctx[] CRYPTO_MINALIGN_ATTR;
331 #define crypto_cipher crypto_tfm
333 struct crypto_blkcipher {
334 struct crypto_tfm base;
338 struct crypto_tfm base;
346 struct crypto_attr_alg {
347 char name[CRYPTO_MAX_ALG_NAME];
351 * Transform user interface.
354 struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags);
355 struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask);
356 void crypto_free_tfm(struct crypto_tfm *tfm);
359 * Transform helpers which query the underlying algorithm.
361 static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm)
363 return tfm->__crt_alg->cra_name;
366 static inline const char *crypto_tfm_alg_driver_name(struct crypto_tfm *tfm)
368 return tfm->__crt_alg->cra_driver_name;
371 static inline int crypto_tfm_alg_priority(struct crypto_tfm *tfm)
373 return tfm->__crt_alg->cra_priority;
376 static inline const char *crypto_tfm_alg_modname(struct crypto_tfm *tfm)
378 return module_name(tfm->__crt_alg->cra_module);
381 static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm)
383 return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK;
386 static unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm)
388 static inline unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm)
390 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
391 return tfm->__crt_alg->cra_cipher.cia_min_keysize;
394 static unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm)
396 static inline unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm)
398 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
399 return tfm->__crt_alg->cra_cipher.cia_max_keysize;
402 static unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm) __deprecated;
403 static inline unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm)
405 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
406 return tfm->crt_cipher.cit_ivsize;
409 static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm)
411 return tfm->__crt_alg->cra_blocksize;
414 static inline unsigned int crypto_tfm_alg_digestsize(struct crypto_tfm *tfm)
416 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
417 return tfm->__crt_alg->cra_digest.dia_digestsize;
420 static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
422 return tfm->__crt_alg->cra_alignmask;
425 static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm)
427 return tfm->crt_flags;
430 static inline void crypto_tfm_set_flags(struct crypto_tfm *tfm, u32 flags)
432 tfm->crt_flags |= flags;
435 static inline void crypto_tfm_clear_flags(struct crypto_tfm *tfm, u32 flags)
437 tfm->crt_flags &= ~flags;
440 static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
442 return tfm->__crt_ctx;
445 static inline unsigned int crypto_tfm_ctx_alignment(void)
447 struct crypto_tfm *tfm;
448 return __alignof__(tfm->__crt_ctx);
454 static inline struct crypto_blkcipher *__crypto_blkcipher_cast(
455 struct crypto_tfm *tfm)
457 return (struct crypto_blkcipher *)tfm;
460 static inline struct crypto_blkcipher *crypto_blkcipher_cast(
461 struct crypto_tfm *tfm)
463 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_BLKCIPHER);
464 return __crypto_blkcipher_cast(tfm);
467 static inline struct crypto_blkcipher *crypto_alloc_blkcipher(
468 const char *alg_name, u32 type, u32 mask)
470 type &= ~CRYPTO_ALG_TYPE_MASK;
471 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
472 mask |= CRYPTO_ALG_TYPE_MASK;
474 return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask));
477 static inline struct crypto_tfm *crypto_blkcipher_tfm(
478 struct crypto_blkcipher *tfm)
483 static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm)
485 crypto_free_tfm(crypto_blkcipher_tfm(tfm));
488 static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm)
490 return crypto_tfm_alg_name(crypto_blkcipher_tfm(tfm));
493 static inline struct blkcipher_tfm *crypto_blkcipher_crt(
494 struct crypto_blkcipher *tfm)
496 return &crypto_blkcipher_tfm(tfm)->crt_blkcipher;
499 static inline struct blkcipher_alg *crypto_blkcipher_alg(
500 struct crypto_blkcipher *tfm)
502 return &crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher;
505 static inline unsigned int crypto_blkcipher_ivsize(struct crypto_blkcipher *tfm)
507 return crypto_blkcipher_alg(tfm)->ivsize;
510 static inline unsigned int crypto_blkcipher_blocksize(
511 struct crypto_blkcipher *tfm)
513 return crypto_tfm_alg_blocksize(crypto_blkcipher_tfm(tfm));
516 static inline unsigned int crypto_blkcipher_alignmask(
517 struct crypto_blkcipher *tfm)
519 return crypto_tfm_alg_alignmask(crypto_blkcipher_tfm(tfm));
522 static inline u32 crypto_blkcipher_get_flags(struct crypto_blkcipher *tfm)
524 return crypto_tfm_get_flags(crypto_blkcipher_tfm(tfm));
527 static inline void crypto_blkcipher_set_flags(struct crypto_blkcipher *tfm,
530 crypto_tfm_set_flags(crypto_blkcipher_tfm(tfm), flags);
533 static inline void crypto_blkcipher_clear_flags(struct crypto_blkcipher *tfm,
536 crypto_tfm_clear_flags(crypto_blkcipher_tfm(tfm), flags);
539 static inline int crypto_blkcipher_setkey(struct crypto_blkcipher *tfm,
540 const u8 *key, unsigned int keylen)
542 return crypto_blkcipher_crt(tfm)->setkey(crypto_blkcipher_tfm(tfm),
546 static inline int crypto_blkcipher_encrypt(struct blkcipher_desc *desc,
547 struct scatterlist *dst,
548 struct scatterlist *src,
551 desc->info = crypto_blkcipher_crt(desc->tfm)->iv;
552 return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes);
555 static inline int crypto_blkcipher_encrypt_iv(struct blkcipher_desc *desc,
556 struct scatterlist *dst,
557 struct scatterlist *src,
560 return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes);
563 static inline int crypto_blkcipher_decrypt(struct blkcipher_desc *desc,
564 struct scatterlist *dst,
565 struct scatterlist *src,
568 desc->info = crypto_blkcipher_crt(desc->tfm)->iv;
569 return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes);
572 static inline int crypto_blkcipher_decrypt_iv(struct blkcipher_desc *desc,
573 struct scatterlist *dst,
574 struct scatterlist *src,
577 return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes);
580 static inline void crypto_blkcipher_set_iv(struct crypto_blkcipher *tfm,
581 const u8 *src, unsigned int len)
583 memcpy(crypto_blkcipher_crt(tfm)->iv, src, len);
586 static inline void crypto_blkcipher_get_iv(struct crypto_blkcipher *tfm,
587 u8 *dst, unsigned int len)
589 memcpy(dst, crypto_blkcipher_crt(tfm)->iv, len);
592 static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm)
594 return (struct crypto_cipher *)tfm;
597 static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm)
599 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
600 return __crypto_cipher_cast(tfm);
603 static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name,
606 type &= ~CRYPTO_ALG_TYPE_MASK;
607 type |= CRYPTO_ALG_TYPE_CIPHER;
608 mask |= CRYPTO_ALG_TYPE_MASK;
610 return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask));
613 static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm)
618 static inline void crypto_free_cipher(struct crypto_cipher *tfm)
620 crypto_free_tfm(crypto_cipher_tfm(tfm));
623 static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm)
625 return &crypto_cipher_tfm(tfm)->crt_cipher;
628 static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm)
630 return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm));
633 static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm)
635 return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm));
638 static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm)
640 return crypto_tfm_get_flags(crypto_cipher_tfm(tfm));
643 static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm,
646 crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags);
649 static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm,
652 crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags);
655 static inline int crypto_cipher_setkey(struct crypto_cipher *tfm,
656 const u8 *key, unsigned int keylen)
658 return crypto_cipher_crt(tfm)->cit_setkey(crypto_cipher_tfm(tfm),
662 static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
663 u8 *dst, const u8 *src)
665 crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm),
669 static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
670 u8 *dst, const u8 *src)
672 crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm),
676 void crypto_digest_init(struct crypto_tfm *tfm);
677 void crypto_digest_update(struct crypto_tfm *tfm,
678 struct scatterlist *sg, unsigned int nsg);
679 void crypto_digest_final(struct crypto_tfm *tfm, u8 *out);
680 void crypto_digest_digest(struct crypto_tfm *tfm,
681 struct scatterlist *sg, unsigned int nsg, u8 *out);
683 static inline struct crypto_hash *__crypto_hash_cast(struct crypto_tfm *tfm)
685 return (struct crypto_hash *)tfm;
688 static inline struct crypto_hash *crypto_hash_cast(struct crypto_tfm *tfm)
690 BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_HASH) &
691 CRYPTO_ALG_TYPE_HASH_MASK);
692 return __crypto_hash_cast(tfm);
695 static inline int crypto_digest_setkey(struct crypto_tfm *tfm,
696 const u8 *key, unsigned int keylen)
698 return tfm->crt_hash.setkey(crypto_hash_cast(tfm), key, keylen);
701 static inline struct crypto_hash *crypto_alloc_hash(const char *alg_name,
704 type &= ~CRYPTO_ALG_TYPE_MASK;
705 type |= CRYPTO_ALG_TYPE_HASH;
706 mask |= CRYPTO_ALG_TYPE_HASH_MASK;
708 return __crypto_hash_cast(crypto_alloc_base(alg_name, type, mask));
711 static inline struct crypto_tfm *crypto_hash_tfm(struct crypto_hash *tfm)
716 static inline void crypto_free_hash(struct crypto_hash *tfm)
718 crypto_free_tfm(crypto_hash_tfm(tfm));
721 static inline struct hash_tfm *crypto_hash_crt(struct crypto_hash *tfm)
723 return &crypto_hash_tfm(tfm)->crt_hash;
726 static inline unsigned int crypto_hash_blocksize(struct crypto_hash *tfm)
728 return crypto_tfm_alg_blocksize(crypto_hash_tfm(tfm));
731 static inline unsigned int crypto_hash_alignmask(struct crypto_hash *tfm)
733 return crypto_tfm_alg_alignmask(crypto_hash_tfm(tfm));
736 static inline unsigned int crypto_hash_digestsize(struct crypto_hash *tfm)
738 return crypto_hash_crt(tfm)->digestsize;
741 static inline u32 crypto_hash_get_flags(struct crypto_hash *tfm)
743 return crypto_tfm_get_flags(crypto_hash_tfm(tfm));
746 static inline void crypto_hash_set_flags(struct crypto_hash *tfm, u32 flags)
748 crypto_tfm_set_flags(crypto_hash_tfm(tfm), flags);
751 static inline void crypto_hash_clear_flags(struct crypto_hash *tfm, u32 flags)
753 crypto_tfm_clear_flags(crypto_hash_tfm(tfm), flags);
756 static inline int crypto_hash_init(struct hash_desc *desc)
758 return crypto_hash_crt(desc->tfm)->init(desc);
761 static inline int crypto_hash_update(struct hash_desc *desc,
762 struct scatterlist *sg,
765 return crypto_hash_crt(desc->tfm)->update(desc, sg, nbytes);
768 static inline int crypto_hash_final(struct hash_desc *desc, u8 *out)
770 return crypto_hash_crt(desc->tfm)->final(desc, out);
773 static inline int crypto_hash_digest(struct hash_desc *desc,
774 struct scatterlist *sg,
775 unsigned int nbytes, u8 *out)
777 return crypto_hash_crt(desc->tfm)->digest(desc, sg, nbytes, out);
780 static inline int crypto_hash_setkey(struct crypto_hash *hash,
781 const u8 *key, unsigned int keylen)
783 return crypto_hash_crt(hash)->setkey(hash, key, keylen);
786 static int crypto_cipher_encrypt(struct crypto_tfm *tfm,
787 struct scatterlist *dst,
788 struct scatterlist *src,
789 unsigned int nbytes) __deprecated;
790 static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm,
791 struct scatterlist *dst,
792 struct scatterlist *src,
795 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
796 return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes);
799 static int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm,
800 struct scatterlist *dst,
801 struct scatterlist *src,
802 unsigned int nbytes, u8 *iv) __deprecated;
803 static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm,
804 struct scatterlist *dst,
805 struct scatterlist *src,
806 unsigned int nbytes, u8 *iv)
808 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
809 return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv);
812 static int crypto_cipher_decrypt(struct crypto_tfm *tfm,
813 struct scatterlist *dst,
814 struct scatterlist *src,
815 unsigned int nbytes) __deprecated;
816 static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm,
817 struct scatterlist *dst,
818 struct scatterlist *src,
821 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
822 return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes);
825 static int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm,
826 struct scatterlist *dst,
827 struct scatterlist *src,
828 unsigned int nbytes, u8 *iv) __deprecated;
829 static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm,
830 struct scatterlist *dst,
831 struct scatterlist *src,
832 unsigned int nbytes, u8 *iv)
834 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
835 return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv);
838 static void crypto_cipher_set_iv(struct crypto_tfm *tfm,
839 const u8 *src, unsigned int len) __deprecated;
840 static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm,
841 const u8 *src, unsigned int len)
843 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
844 memcpy(tfm->crt_cipher.cit_iv, src, len);
847 static void crypto_cipher_get_iv(struct crypto_tfm *tfm,
848 u8 *dst, unsigned int len) __deprecated;
849 static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm,
850 u8 *dst, unsigned int len)
852 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
853 memcpy(dst, tfm->crt_cipher.cit_iv, len);
856 static inline int crypto_comp_compress(struct crypto_tfm *tfm,
857 const u8 *src, unsigned int slen,
858 u8 *dst, unsigned int *dlen)
860 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS);
861 return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen);
864 static inline int crypto_comp_decompress(struct crypto_tfm *tfm,
865 const u8 *src, unsigned int slen,
866 u8 *dst, unsigned int *dlen)
868 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS);
869 return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen);
872 #endif /* _LINUX_CRYPTO_H */