crypto.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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. #include <asm/atomic.h>
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/types.h>
  23. #include <linux/list.h>
  24. #include <linux/slab.h>
  25. #include <linux/string.h>
  26. #include <linux/uaccess.h>
  27. /*
  28. * Algorithm masks and types.
  29. */
  30. #define CRYPTO_ALG_TYPE_MASK 0x0000000f
  31. #define CRYPTO_ALG_TYPE_CIPHER 0x00000001
  32. #define CRYPTO_ALG_TYPE_DIGEST 0x00000002
  33. #define CRYPTO_ALG_TYPE_COMPRESS 0x00000004
  34. #define CRYPTO_ALG_LARVAL 0x00000010
  35. #define CRYPTO_ALG_DEAD 0x00000020
  36. #define CRYPTO_ALG_DYING 0x00000040
  37. #define CRYPTO_ALG_ASYNC 0x00000080
  38. /*
  39. * Transform masks and values (for crt_flags).
  40. */
  41. #define CRYPTO_TFM_MODE_MASK 0x000000ff
  42. #define CRYPTO_TFM_REQ_MASK 0x000fff00
  43. #define CRYPTO_TFM_RES_MASK 0xfff00000
  44. #define CRYPTO_TFM_MODE_ECB 0x00000001
  45. #define CRYPTO_TFM_MODE_CBC 0x00000002
  46. #define CRYPTO_TFM_MODE_CFB 0x00000004
  47. #define CRYPTO_TFM_MODE_CTR 0x00000008
  48. #define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100
  49. #define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
  50. #define CRYPTO_TFM_RES_WEAK_KEY 0x00100000
  51. #define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000
  52. #define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000
  53. #define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000
  54. #define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000
  55. /*
  56. * Miscellaneous stuff.
  57. */
  58. #define CRYPTO_UNSPEC 0
  59. #define CRYPTO_MAX_ALG_NAME 64
  60. #define CRYPTO_DIR_ENCRYPT 1
  61. #define CRYPTO_DIR_DECRYPT 0
  62. /*
  63. * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual
  64. * declaration) is used to ensure that the crypto_tfm context structure is
  65. * aligned correctly for the given architecture so that there are no alignment
  66. * faults for C data types. In particular, this is required on platforms such
  67. * as arm where pointers are 32-bit aligned but there are data types such as
  68. * u64 which require 64-bit alignment.
  69. */
  70. #if defined(ARCH_KMALLOC_MINALIGN)
  71. #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN
  72. #elif defined(ARCH_SLAB_MINALIGN)
  73. #define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN
  74. #endif
  75. #ifdef CRYPTO_MINALIGN
  76. #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN)))
  77. #else
  78. #define CRYPTO_MINALIGN_ATTR
  79. #endif
  80. struct scatterlist;
  81. struct crypto_tfm;
  82. struct crypto_type;
  83. struct cipher_desc {
  84. struct crypto_tfm *tfm;
  85. void (*crfn)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  86. unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst,
  87. const u8 *src, unsigned int nbytes);
  88. void *info;
  89. };
  90. /*
  91. * Algorithms: modular crypto algorithm implementations, managed
  92. * via crypto_register_alg() and crypto_unregister_alg().
  93. */
  94. struct cipher_alg {
  95. unsigned int cia_min_keysize;
  96. unsigned int cia_max_keysize;
  97. int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key,
  98. unsigned int keylen);
  99. void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  100. void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  101. unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc,
  102. u8 *dst, const u8 *src,
  103. unsigned int nbytes);
  104. unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc,
  105. u8 *dst, const u8 *src,
  106. unsigned int nbytes);
  107. unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc,
  108. u8 *dst, const u8 *src,
  109. unsigned int nbytes);
  110. unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc,
  111. u8 *dst, const u8 *src,
  112. unsigned int nbytes);
  113. };
  114. struct digest_alg {
  115. unsigned int dia_digestsize;
  116. void (*dia_init)(struct crypto_tfm *tfm);
  117. void (*dia_update)(struct crypto_tfm *tfm, const u8 *data,
  118. unsigned int len);
  119. void (*dia_final)(struct crypto_tfm *tfm, u8 *out);
  120. int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key,
  121. unsigned int keylen);
  122. };
  123. struct compress_alg {
  124. int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src,
  125. unsigned int slen, u8 *dst, unsigned int *dlen);
  126. int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
  127. unsigned int slen, u8 *dst, unsigned int *dlen);
  128. };
  129. #define cra_cipher cra_u.cipher
  130. #define cra_digest cra_u.digest
  131. #define cra_compress cra_u.compress
  132. struct crypto_alg {
  133. struct list_head cra_list;
  134. struct list_head cra_users;
  135. u32 cra_flags;
  136. unsigned int cra_blocksize;
  137. unsigned int cra_ctxsize;
  138. unsigned int cra_alignmask;
  139. int cra_priority;
  140. atomic_t cra_refcnt;
  141. char cra_name[CRYPTO_MAX_ALG_NAME];
  142. char cra_driver_name[CRYPTO_MAX_ALG_NAME];
  143. const struct crypto_type *cra_type;
  144. union {
  145. struct cipher_alg cipher;
  146. struct digest_alg digest;
  147. struct compress_alg compress;
  148. } cra_u;
  149. int (*cra_init)(struct crypto_tfm *tfm);
  150. void (*cra_exit)(struct crypto_tfm *tfm);
  151. void (*cra_destroy)(struct crypto_alg *alg);
  152. struct module *cra_module;
  153. };
  154. /*
  155. * Algorithm registration interface.
  156. */
  157. int crypto_register_alg(struct crypto_alg *alg);
  158. int crypto_unregister_alg(struct crypto_alg *alg);
  159. /*
  160. * Algorithm query interface.
  161. */
  162. #ifdef CONFIG_CRYPTO
  163. int crypto_alg_available(const char *name, u32 flags);
  164. #else
  165. static inline int crypto_alg_available(const char *name, u32 flags)
  166. {
  167. return 0;
  168. }
  169. #endif
  170. /*
  171. * Transforms: user-instantiated objects which encapsulate algorithms
  172. * and core processing logic. Managed via crypto_alloc_*() and
  173. * crypto_free_*(), as well as the various helpers below.
  174. */
  175. struct cipher_tfm {
  176. void *cit_iv;
  177. unsigned int cit_ivsize;
  178. u32 cit_mode;
  179. int (*cit_setkey)(struct crypto_tfm *tfm,
  180. const u8 *key, unsigned int keylen);
  181. int (*cit_encrypt)(struct crypto_tfm *tfm,
  182. struct scatterlist *dst,
  183. struct scatterlist *src,
  184. unsigned int nbytes);
  185. int (*cit_encrypt_iv)(struct crypto_tfm *tfm,
  186. struct scatterlist *dst,
  187. struct scatterlist *src,
  188. unsigned int nbytes, u8 *iv);
  189. int (*cit_decrypt)(struct crypto_tfm *tfm,
  190. struct scatterlist *dst,
  191. struct scatterlist *src,
  192. unsigned int nbytes);
  193. int (*cit_decrypt_iv)(struct crypto_tfm *tfm,
  194. struct scatterlist *dst,
  195. struct scatterlist *src,
  196. unsigned int nbytes, u8 *iv);
  197. void (*cit_xor_block)(u8 *dst, const u8 *src);
  198. void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  199. void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  200. };
  201. struct digest_tfm {
  202. void (*dit_init)(struct crypto_tfm *tfm);
  203. void (*dit_update)(struct crypto_tfm *tfm,
  204. struct scatterlist *sg, unsigned int nsg);
  205. void (*dit_final)(struct crypto_tfm *tfm, u8 *out);
  206. void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg,
  207. unsigned int nsg, u8 *out);
  208. int (*dit_setkey)(struct crypto_tfm *tfm,
  209. const u8 *key, unsigned int keylen);
  210. #ifdef CONFIG_CRYPTO_HMAC
  211. void *dit_hmac_block;
  212. #endif
  213. };
  214. struct compress_tfm {
  215. int (*cot_compress)(struct crypto_tfm *tfm,
  216. const u8 *src, unsigned int slen,
  217. u8 *dst, unsigned int *dlen);
  218. int (*cot_decompress)(struct crypto_tfm *tfm,
  219. const u8 *src, unsigned int slen,
  220. u8 *dst, unsigned int *dlen);
  221. };
  222. #define crt_cipher crt_u.cipher
  223. #define crt_digest crt_u.digest
  224. #define crt_compress crt_u.compress
  225. struct crypto_tfm {
  226. u32 crt_flags;
  227. union {
  228. struct cipher_tfm cipher;
  229. struct digest_tfm digest;
  230. struct compress_tfm compress;
  231. } crt_u;
  232. struct crypto_alg *__crt_alg;
  233. void *__crt_ctx[] CRYPTO_MINALIGN_ATTR;
  234. };
  235. #define crypto_cipher crypto_tfm
  236. enum {
  237. CRYPTOA_UNSPEC,
  238. CRYPTOA_ALG,
  239. };
  240. struct crypto_attr_alg {
  241. char name[CRYPTO_MAX_ALG_NAME];
  242. };
  243. /*
  244. * Transform user interface.
  245. */
  246. struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags);
  247. struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask);
  248. void crypto_free_tfm(struct crypto_tfm *tfm);
  249. /*
  250. * Transform helpers which query the underlying algorithm.
  251. */
  252. static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm)
  253. {
  254. return tfm->__crt_alg->cra_name;
  255. }
  256. static inline const char *crypto_tfm_alg_driver_name(struct crypto_tfm *tfm)
  257. {
  258. return tfm->__crt_alg->cra_driver_name;
  259. }
  260. static inline int crypto_tfm_alg_priority(struct crypto_tfm *tfm)
  261. {
  262. return tfm->__crt_alg->cra_priority;
  263. }
  264. static inline const char *crypto_tfm_alg_modname(struct crypto_tfm *tfm)
  265. {
  266. return module_name(tfm->__crt_alg->cra_module);
  267. }
  268. static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm)
  269. {
  270. return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK;
  271. }
  272. static inline unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm)
  273. {
  274. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  275. return tfm->__crt_alg->cra_cipher.cia_min_keysize;
  276. }
  277. static inline unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm)
  278. {
  279. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  280. return tfm->__crt_alg->cra_cipher.cia_max_keysize;
  281. }
  282. static inline unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm)
  283. {
  284. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  285. return tfm->crt_cipher.cit_ivsize;
  286. }
  287. static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm)
  288. {
  289. return tfm->__crt_alg->cra_blocksize;
  290. }
  291. static inline unsigned int crypto_tfm_alg_digestsize(struct crypto_tfm *tfm)
  292. {
  293. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
  294. return tfm->__crt_alg->cra_digest.dia_digestsize;
  295. }
  296. static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
  297. {
  298. return tfm->__crt_alg->cra_alignmask;
  299. }
  300. static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm)
  301. {
  302. return tfm->crt_flags;
  303. }
  304. static inline void crypto_tfm_set_flags(struct crypto_tfm *tfm, u32 flags)
  305. {
  306. tfm->crt_flags |= flags;
  307. }
  308. static inline void crypto_tfm_clear_flags(struct crypto_tfm *tfm, u32 flags)
  309. {
  310. tfm->crt_flags &= ~flags;
  311. }
  312. static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
  313. {
  314. return tfm->__crt_ctx;
  315. }
  316. static inline unsigned int crypto_tfm_ctx_alignment(void)
  317. {
  318. struct crypto_tfm *tfm;
  319. return __alignof__(tfm->__crt_ctx);
  320. }
  321. /*
  322. * API wrappers.
  323. */
  324. static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm)
  325. {
  326. return (struct crypto_cipher *)tfm;
  327. }
  328. static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm)
  329. {
  330. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  331. return __crypto_cipher_cast(tfm);
  332. }
  333. static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name,
  334. u32 type, u32 mask)
  335. {
  336. type &= ~CRYPTO_ALG_TYPE_MASK;
  337. type |= CRYPTO_ALG_TYPE_CIPHER;
  338. mask |= CRYPTO_ALG_TYPE_MASK;
  339. return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask));
  340. }
  341. static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm)
  342. {
  343. return tfm;
  344. }
  345. static inline void crypto_free_cipher(struct crypto_cipher *tfm)
  346. {
  347. crypto_free_tfm(crypto_cipher_tfm(tfm));
  348. }
  349. static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm)
  350. {
  351. return &crypto_cipher_tfm(tfm)->crt_cipher;
  352. }
  353. static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm)
  354. {
  355. return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm));
  356. }
  357. static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm)
  358. {
  359. return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm));
  360. }
  361. static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm)
  362. {
  363. return crypto_tfm_get_flags(crypto_cipher_tfm(tfm));
  364. }
  365. static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm,
  366. u32 flags)
  367. {
  368. crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags);
  369. }
  370. static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm,
  371. u32 flags)
  372. {
  373. crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags);
  374. }
  375. static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
  376. u8 *dst, const u8 *src)
  377. {
  378. crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm),
  379. dst, src);
  380. }
  381. static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
  382. u8 *dst, const u8 *src)
  383. {
  384. crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm),
  385. dst, src);
  386. }
  387. static inline void crypto_digest_init(struct crypto_tfm *tfm)
  388. {
  389. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
  390. tfm->crt_digest.dit_init(tfm);
  391. }
  392. static inline void crypto_digest_update(struct crypto_tfm *tfm,
  393. struct scatterlist *sg,
  394. unsigned int nsg)
  395. {
  396. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
  397. tfm->crt_digest.dit_update(tfm, sg, nsg);
  398. }
  399. static inline void crypto_digest_final(struct crypto_tfm *tfm, u8 *out)
  400. {
  401. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
  402. tfm->crt_digest.dit_final(tfm, out);
  403. }
  404. static inline void crypto_digest_digest(struct crypto_tfm *tfm,
  405. struct scatterlist *sg,
  406. unsigned int nsg, u8 *out)
  407. {
  408. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
  409. tfm->crt_digest.dit_digest(tfm, sg, nsg, out);
  410. }
  411. static inline int crypto_digest_setkey(struct crypto_tfm *tfm,
  412. const u8 *key, unsigned int keylen)
  413. {
  414. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
  415. return tfm->crt_digest.dit_setkey(tfm, key, keylen);
  416. }
  417. static inline int crypto_cipher_setkey(struct crypto_tfm *tfm,
  418. const u8 *key, unsigned int keylen)
  419. {
  420. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  421. return tfm->crt_cipher.cit_setkey(tfm, key, keylen);
  422. }
  423. static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm,
  424. struct scatterlist *dst,
  425. struct scatterlist *src,
  426. unsigned int nbytes)
  427. {
  428. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  429. return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes);
  430. }
  431. static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm,
  432. struct scatterlist *dst,
  433. struct scatterlist *src,
  434. unsigned int nbytes, u8 *iv)
  435. {
  436. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  437. return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv);
  438. }
  439. static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm,
  440. struct scatterlist *dst,
  441. struct scatterlist *src,
  442. unsigned int nbytes)
  443. {
  444. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  445. return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes);
  446. }
  447. static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm,
  448. struct scatterlist *dst,
  449. struct scatterlist *src,
  450. unsigned int nbytes, u8 *iv)
  451. {
  452. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  453. return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv);
  454. }
  455. static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm,
  456. const u8 *src, unsigned int len)
  457. {
  458. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  459. memcpy(tfm->crt_cipher.cit_iv, src, len);
  460. }
  461. static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm,
  462. u8 *dst, unsigned int len)
  463. {
  464. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  465. memcpy(dst, tfm->crt_cipher.cit_iv, len);
  466. }
  467. static inline int crypto_comp_compress(struct crypto_tfm *tfm,
  468. const u8 *src, unsigned int slen,
  469. u8 *dst, unsigned int *dlen)
  470. {
  471. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS);
  472. return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen);
  473. }
  474. static inline int crypto_comp_decompress(struct crypto_tfm *tfm,
  475. const u8 *src, unsigned int slen,
  476. u8 *dst, unsigned int *dlen)
  477. {
  478. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS);
  479. return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen);
  480. }
  481. /*
  482. * HMAC support.
  483. */
  484. #ifdef CONFIG_CRYPTO_HMAC
  485. void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen);
  486. void crypto_hmac_update(struct crypto_tfm *tfm,
  487. struct scatterlist *sg, unsigned int nsg);
  488. void crypto_hmac_final(struct crypto_tfm *tfm, u8 *key,
  489. unsigned int *keylen, u8 *out);
  490. void crypto_hmac(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen,
  491. struct scatterlist *sg, unsigned int nsg, u8 *out);
  492. #endif /* CONFIG_CRYPTO_HMAC */
  493. #endif /* _LINUX_CRYPTO_H */