crypto.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  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/list.h>
  23. #include <linux/slab.h>
  24. #include <linux/string.h>
  25. #include <linux/uaccess.h>
  26. /*
  27. * Algorithm masks and types.
  28. */
  29. #define CRYPTO_ALG_TYPE_MASK 0x0000000f
  30. #define CRYPTO_ALG_TYPE_CIPHER 0x00000001
  31. #define CRYPTO_ALG_TYPE_DIGEST 0x00000002
  32. #define CRYPTO_ALG_TYPE_HASH 0x00000003
  33. #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004
  34. #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005
  35. #define CRYPTO_ALG_TYPE_COMPRESS 0x00000008
  36. #define CRYPTO_ALG_TYPE_AEAD 0x00000009
  37. #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
  38. #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c
  39. #define CRYPTO_ALG_LARVAL 0x00000010
  40. #define CRYPTO_ALG_DEAD 0x00000020
  41. #define CRYPTO_ALG_DYING 0x00000040
  42. #define CRYPTO_ALG_ASYNC 0x00000080
  43. /*
  44. * Set this bit if and only if the algorithm requires another algorithm of
  45. * the same type to handle corner cases.
  46. */
  47. #define CRYPTO_ALG_NEED_FALLBACK 0x00000100
  48. /*
  49. * Transform masks and values (for crt_flags).
  50. */
  51. #define CRYPTO_TFM_REQ_MASK 0x000fff00
  52. #define CRYPTO_TFM_RES_MASK 0xfff00000
  53. #define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100
  54. #define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
  55. #define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400
  56. #define CRYPTO_TFM_RES_WEAK_KEY 0x00100000
  57. #define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000
  58. #define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000
  59. #define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000
  60. #define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000
  61. /*
  62. * Miscellaneous stuff.
  63. */
  64. #define CRYPTO_MAX_ALG_NAME 64
  65. /*
  66. * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual
  67. * declaration) is used to ensure that the crypto_tfm context structure is
  68. * aligned correctly for the given architecture so that there are no alignment
  69. * faults for C data types. In particular, this is required on platforms such
  70. * as arm where pointers are 32-bit aligned but there are data types such as
  71. * u64 which require 64-bit alignment.
  72. */
  73. #if defined(ARCH_KMALLOC_MINALIGN)
  74. #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN
  75. #elif defined(ARCH_SLAB_MINALIGN)
  76. #define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN
  77. #endif
  78. #ifdef CRYPTO_MINALIGN
  79. #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN)))
  80. #else
  81. #define CRYPTO_MINALIGN_ATTR
  82. #endif
  83. struct scatterlist;
  84. struct crypto_ablkcipher;
  85. struct crypto_async_request;
  86. struct crypto_aead;
  87. struct crypto_blkcipher;
  88. struct crypto_hash;
  89. struct crypto_tfm;
  90. struct crypto_type;
  91. typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err);
  92. struct crypto_async_request {
  93. struct list_head list;
  94. crypto_completion_t complete;
  95. void *data;
  96. struct crypto_tfm *tfm;
  97. u32 flags;
  98. };
  99. struct ablkcipher_request {
  100. struct crypto_async_request base;
  101. unsigned int nbytes;
  102. void *info;
  103. struct scatterlist *src;
  104. struct scatterlist *dst;
  105. void *__ctx[] CRYPTO_MINALIGN_ATTR;
  106. };
  107. /**
  108. * struct aead_request - AEAD request
  109. * @base: Common attributes for async crypto requests
  110. * @assoclen: Length in bytes of associated data for authentication
  111. * @cryptlen: Length of data to be encrypted or decrypted
  112. * @iv: Initialisation vector
  113. * @assoc: Associated data
  114. * @src: Source data
  115. * @dst: Destination data
  116. * @__ctx: Start of private context data
  117. */
  118. struct aead_request {
  119. struct crypto_async_request base;
  120. unsigned int assoclen;
  121. unsigned int cryptlen;
  122. u8 *iv;
  123. struct scatterlist *assoc;
  124. struct scatterlist *src;
  125. struct scatterlist *dst;
  126. void *__ctx[] CRYPTO_MINALIGN_ATTR;
  127. };
  128. struct blkcipher_desc {
  129. struct crypto_blkcipher *tfm;
  130. void *info;
  131. u32 flags;
  132. };
  133. struct cipher_desc {
  134. struct crypto_tfm *tfm;
  135. void (*crfn)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  136. unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst,
  137. const u8 *src, unsigned int nbytes);
  138. void *info;
  139. };
  140. struct hash_desc {
  141. struct crypto_hash *tfm;
  142. u32 flags;
  143. };
  144. /*
  145. * Algorithms: modular crypto algorithm implementations, managed
  146. * via crypto_register_alg() and crypto_unregister_alg().
  147. */
  148. struct ablkcipher_alg {
  149. int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key,
  150. unsigned int keylen);
  151. int (*encrypt)(struct ablkcipher_request *req);
  152. int (*decrypt)(struct ablkcipher_request *req);
  153. unsigned int min_keysize;
  154. unsigned int max_keysize;
  155. unsigned int ivsize;
  156. };
  157. struct aead_alg {
  158. int (*setkey)(struct crypto_aead *tfm, const u8 *key,
  159. unsigned int keylen);
  160. int (*setauthsize)(struct crypto_aead *tfm, unsigned int authsize);
  161. int (*encrypt)(struct aead_request *req);
  162. int (*decrypt)(struct aead_request *req);
  163. unsigned int ivsize;
  164. unsigned int maxauthsize;
  165. };
  166. struct blkcipher_alg {
  167. int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
  168. unsigned int keylen);
  169. int (*encrypt)(struct blkcipher_desc *desc,
  170. struct scatterlist *dst, struct scatterlist *src,
  171. unsigned int nbytes);
  172. int (*decrypt)(struct blkcipher_desc *desc,
  173. struct scatterlist *dst, struct scatterlist *src,
  174. unsigned int nbytes);
  175. unsigned int min_keysize;
  176. unsigned int max_keysize;
  177. unsigned int ivsize;
  178. };
  179. struct cipher_alg {
  180. unsigned int cia_min_keysize;
  181. unsigned int cia_max_keysize;
  182. int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key,
  183. unsigned int keylen);
  184. void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  185. void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  186. };
  187. struct digest_alg {
  188. unsigned int dia_digestsize;
  189. void (*dia_init)(struct crypto_tfm *tfm);
  190. void (*dia_update)(struct crypto_tfm *tfm, const u8 *data,
  191. unsigned int len);
  192. void (*dia_final)(struct crypto_tfm *tfm, u8 *out);
  193. int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key,
  194. unsigned int keylen);
  195. };
  196. struct hash_alg {
  197. int (*init)(struct hash_desc *desc);
  198. int (*update)(struct hash_desc *desc, struct scatterlist *sg,
  199. unsigned int nbytes);
  200. int (*final)(struct hash_desc *desc, u8 *out);
  201. int (*digest)(struct hash_desc *desc, struct scatterlist *sg,
  202. unsigned int nbytes, u8 *out);
  203. int (*setkey)(struct crypto_hash *tfm, const u8 *key,
  204. unsigned int keylen);
  205. unsigned int digestsize;
  206. };
  207. struct compress_alg {
  208. int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src,
  209. unsigned int slen, u8 *dst, unsigned int *dlen);
  210. int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
  211. unsigned int slen, u8 *dst, unsigned int *dlen);
  212. };
  213. #define cra_ablkcipher cra_u.ablkcipher
  214. #define cra_aead cra_u.aead
  215. #define cra_blkcipher cra_u.blkcipher
  216. #define cra_cipher cra_u.cipher
  217. #define cra_digest cra_u.digest
  218. #define cra_hash cra_u.hash
  219. #define cra_compress cra_u.compress
  220. struct crypto_alg {
  221. struct list_head cra_list;
  222. struct list_head cra_users;
  223. u32 cra_flags;
  224. unsigned int cra_blocksize;
  225. unsigned int cra_ctxsize;
  226. unsigned int cra_alignmask;
  227. int cra_priority;
  228. atomic_t cra_refcnt;
  229. char cra_name[CRYPTO_MAX_ALG_NAME];
  230. char cra_driver_name[CRYPTO_MAX_ALG_NAME];
  231. const struct crypto_type *cra_type;
  232. union {
  233. struct ablkcipher_alg ablkcipher;
  234. struct aead_alg aead;
  235. struct blkcipher_alg blkcipher;
  236. struct cipher_alg cipher;
  237. struct digest_alg digest;
  238. struct hash_alg hash;
  239. struct compress_alg compress;
  240. } cra_u;
  241. int (*cra_init)(struct crypto_tfm *tfm);
  242. void (*cra_exit)(struct crypto_tfm *tfm);
  243. void (*cra_destroy)(struct crypto_alg *alg);
  244. struct module *cra_module;
  245. };
  246. /*
  247. * Algorithm registration interface.
  248. */
  249. int crypto_register_alg(struct crypto_alg *alg);
  250. int crypto_unregister_alg(struct crypto_alg *alg);
  251. /*
  252. * Algorithm query interface.
  253. */
  254. #ifdef CONFIG_CRYPTO
  255. int crypto_has_alg(const char *name, u32 type, u32 mask);
  256. #else
  257. static inline int crypto_has_alg(const char *name, u32 type, u32 mask)
  258. {
  259. return 0;
  260. }
  261. #endif
  262. /*
  263. * Transforms: user-instantiated objects which encapsulate algorithms
  264. * and core processing logic. Managed via crypto_alloc_*() and
  265. * crypto_free_*(), as well as the various helpers below.
  266. */
  267. struct ablkcipher_tfm {
  268. int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key,
  269. unsigned int keylen);
  270. int (*encrypt)(struct ablkcipher_request *req);
  271. int (*decrypt)(struct ablkcipher_request *req);
  272. unsigned int ivsize;
  273. unsigned int reqsize;
  274. };
  275. struct aead_tfm {
  276. int (*setkey)(struct crypto_aead *tfm, const u8 *key,
  277. unsigned int keylen);
  278. int (*encrypt)(struct aead_request *req);
  279. int (*decrypt)(struct aead_request *req);
  280. unsigned int ivsize;
  281. unsigned int authsize;
  282. unsigned int reqsize;
  283. };
  284. struct blkcipher_tfm {
  285. void *iv;
  286. int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
  287. unsigned int keylen);
  288. int (*encrypt)(struct blkcipher_desc *desc, struct scatterlist *dst,
  289. struct scatterlist *src, unsigned int nbytes);
  290. int (*decrypt)(struct blkcipher_desc *desc, struct scatterlist *dst,
  291. struct scatterlist *src, unsigned int nbytes);
  292. };
  293. struct cipher_tfm {
  294. int (*cit_setkey)(struct crypto_tfm *tfm,
  295. const u8 *key, unsigned int keylen);
  296. void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  297. void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  298. };
  299. struct hash_tfm {
  300. int (*init)(struct hash_desc *desc);
  301. int (*update)(struct hash_desc *desc,
  302. struct scatterlist *sg, unsigned int nsg);
  303. int (*final)(struct hash_desc *desc, u8 *out);
  304. int (*digest)(struct hash_desc *desc, struct scatterlist *sg,
  305. unsigned int nsg, u8 *out);
  306. int (*setkey)(struct crypto_hash *tfm, const u8 *key,
  307. unsigned int keylen);
  308. unsigned int digestsize;
  309. };
  310. struct compress_tfm {
  311. int (*cot_compress)(struct crypto_tfm *tfm,
  312. const u8 *src, unsigned int slen,
  313. u8 *dst, unsigned int *dlen);
  314. int (*cot_decompress)(struct crypto_tfm *tfm,
  315. const u8 *src, unsigned int slen,
  316. u8 *dst, unsigned int *dlen);
  317. };
  318. #define crt_ablkcipher crt_u.ablkcipher
  319. #define crt_aead crt_u.aead
  320. #define crt_blkcipher crt_u.blkcipher
  321. #define crt_cipher crt_u.cipher
  322. #define crt_hash crt_u.hash
  323. #define crt_compress crt_u.compress
  324. struct crypto_tfm {
  325. u32 crt_flags;
  326. union {
  327. struct ablkcipher_tfm ablkcipher;
  328. struct aead_tfm aead;
  329. struct blkcipher_tfm blkcipher;
  330. struct cipher_tfm cipher;
  331. struct hash_tfm hash;
  332. struct compress_tfm compress;
  333. } crt_u;
  334. struct crypto_alg *__crt_alg;
  335. void *__crt_ctx[] CRYPTO_MINALIGN_ATTR;
  336. };
  337. struct crypto_ablkcipher {
  338. struct crypto_tfm base;
  339. };
  340. struct crypto_aead {
  341. struct crypto_tfm base;
  342. };
  343. struct crypto_blkcipher {
  344. struct crypto_tfm base;
  345. };
  346. struct crypto_cipher {
  347. struct crypto_tfm base;
  348. };
  349. struct crypto_comp {
  350. struct crypto_tfm base;
  351. };
  352. struct crypto_hash {
  353. struct crypto_tfm base;
  354. };
  355. enum {
  356. CRYPTOA_UNSPEC,
  357. CRYPTOA_ALG,
  358. CRYPTOA_TYPE,
  359. CRYPTOA_U32,
  360. __CRYPTOA_MAX,
  361. };
  362. #define CRYPTOA_MAX (__CRYPTOA_MAX - 1)
  363. /* Maximum number of (rtattr) parameters for each template. */
  364. #define CRYPTO_MAX_ATTRS 32
  365. struct crypto_attr_alg {
  366. char name[CRYPTO_MAX_ALG_NAME];
  367. };
  368. struct crypto_attr_type {
  369. u32 type;
  370. u32 mask;
  371. };
  372. struct crypto_attr_u32 {
  373. u32 num;
  374. };
  375. /*
  376. * Transform user interface.
  377. */
  378. struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags);
  379. struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask);
  380. void crypto_free_tfm(struct crypto_tfm *tfm);
  381. /*
  382. * Transform helpers which query the underlying algorithm.
  383. */
  384. static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm)
  385. {
  386. return tfm->__crt_alg->cra_name;
  387. }
  388. static inline const char *crypto_tfm_alg_driver_name(struct crypto_tfm *tfm)
  389. {
  390. return tfm->__crt_alg->cra_driver_name;
  391. }
  392. static inline int crypto_tfm_alg_priority(struct crypto_tfm *tfm)
  393. {
  394. return tfm->__crt_alg->cra_priority;
  395. }
  396. static inline const char *crypto_tfm_alg_modname(struct crypto_tfm *tfm)
  397. {
  398. return module_name(tfm->__crt_alg->cra_module);
  399. }
  400. static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm)
  401. {
  402. return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK;
  403. }
  404. static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm)
  405. {
  406. return tfm->__crt_alg->cra_blocksize;
  407. }
  408. static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
  409. {
  410. return tfm->__crt_alg->cra_alignmask;
  411. }
  412. static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm)
  413. {
  414. return tfm->crt_flags;
  415. }
  416. static inline void crypto_tfm_set_flags(struct crypto_tfm *tfm, u32 flags)
  417. {
  418. tfm->crt_flags |= flags;
  419. }
  420. static inline void crypto_tfm_clear_flags(struct crypto_tfm *tfm, u32 flags)
  421. {
  422. tfm->crt_flags &= ~flags;
  423. }
  424. static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
  425. {
  426. return tfm->__crt_ctx;
  427. }
  428. static inline unsigned int crypto_tfm_ctx_alignment(void)
  429. {
  430. struct crypto_tfm *tfm;
  431. return __alignof__(tfm->__crt_ctx);
  432. }
  433. /*
  434. * API wrappers.
  435. */
  436. static inline struct crypto_ablkcipher *__crypto_ablkcipher_cast(
  437. struct crypto_tfm *tfm)
  438. {
  439. return (struct crypto_ablkcipher *)tfm;
  440. }
  441. static inline struct crypto_ablkcipher *crypto_alloc_ablkcipher(
  442. const char *alg_name, u32 type, u32 mask)
  443. {
  444. type &= ~CRYPTO_ALG_TYPE_MASK;
  445. mask &= ~CRYPTO_ALG_TYPE_MASK;
  446. type |= CRYPTO_ALG_TYPE_BLKCIPHER;
  447. mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
  448. return __crypto_ablkcipher_cast(
  449. crypto_alloc_base(alg_name, type, mask));
  450. }
  451. static inline struct crypto_tfm *crypto_ablkcipher_tfm(
  452. struct crypto_ablkcipher *tfm)
  453. {
  454. return &tfm->base;
  455. }
  456. static inline void crypto_free_ablkcipher(struct crypto_ablkcipher *tfm)
  457. {
  458. crypto_free_tfm(crypto_ablkcipher_tfm(tfm));
  459. }
  460. static inline int crypto_has_ablkcipher(const char *alg_name, u32 type,
  461. u32 mask)
  462. {
  463. type &= ~CRYPTO_ALG_TYPE_MASK;
  464. mask &= ~CRYPTO_ALG_TYPE_MASK;
  465. type |= CRYPTO_ALG_TYPE_BLKCIPHER;
  466. mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
  467. return crypto_has_alg(alg_name, type, mask);
  468. }
  469. static inline struct ablkcipher_tfm *crypto_ablkcipher_crt(
  470. struct crypto_ablkcipher *tfm)
  471. {
  472. return &crypto_ablkcipher_tfm(tfm)->crt_ablkcipher;
  473. }
  474. static inline unsigned int crypto_ablkcipher_ivsize(
  475. struct crypto_ablkcipher *tfm)
  476. {
  477. return crypto_ablkcipher_crt(tfm)->ivsize;
  478. }
  479. static inline unsigned int crypto_ablkcipher_blocksize(
  480. struct crypto_ablkcipher *tfm)
  481. {
  482. return crypto_tfm_alg_blocksize(crypto_ablkcipher_tfm(tfm));
  483. }
  484. static inline unsigned int crypto_ablkcipher_alignmask(
  485. struct crypto_ablkcipher *tfm)
  486. {
  487. return crypto_tfm_alg_alignmask(crypto_ablkcipher_tfm(tfm));
  488. }
  489. static inline u32 crypto_ablkcipher_get_flags(struct crypto_ablkcipher *tfm)
  490. {
  491. return crypto_tfm_get_flags(crypto_ablkcipher_tfm(tfm));
  492. }
  493. static inline void crypto_ablkcipher_set_flags(struct crypto_ablkcipher *tfm,
  494. u32 flags)
  495. {
  496. crypto_tfm_set_flags(crypto_ablkcipher_tfm(tfm), flags);
  497. }
  498. static inline void crypto_ablkcipher_clear_flags(struct crypto_ablkcipher *tfm,
  499. u32 flags)
  500. {
  501. crypto_tfm_clear_flags(crypto_ablkcipher_tfm(tfm), flags);
  502. }
  503. static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm,
  504. const u8 *key, unsigned int keylen)
  505. {
  506. return crypto_ablkcipher_crt(tfm)->setkey(tfm, key, keylen);
  507. }
  508. static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm(
  509. struct ablkcipher_request *req)
  510. {
  511. return __crypto_ablkcipher_cast(req->base.tfm);
  512. }
  513. static inline int crypto_ablkcipher_encrypt(struct ablkcipher_request *req)
  514. {
  515. struct ablkcipher_tfm *crt =
  516. crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
  517. return crt->encrypt(req);
  518. }
  519. static inline int crypto_ablkcipher_decrypt(struct ablkcipher_request *req)
  520. {
  521. struct ablkcipher_tfm *crt =
  522. crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
  523. return crt->decrypt(req);
  524. }
  525. static inline unsigned int crypto_ablkcipher_reqsize(
  526. struct crypto_ablkcipher *tfm)
  527. {
  528. return crypto_ablkcipher_crt(tfm)->reqsize;
  529. }
  530. static inline void ablkcipher_request_set_tfm(
  531. struct ablkcipher_request *req, struct crypto_ablkcipher *tfm)
  532. {
  533. req->base.tfm = crypto_ablkcipher_tfm(tfm);
  534. }
  535. static inline struct ablkcipher_request *ablkcipher_request_cast(
  536. struct crypto_async_request *req)
  537. {
  538. return container_of(req, struct ablkcipher_request, base);
  539. }
  540. static inline struct ablkcipher_request *ablkcipher_request_alloc(
  541. struct crypto_ablkcipher *tfm, gfp_t gfp)
  542. {
  543. struct ablkcipher_request *req;
  544. req = kmalloc(sizeof(struct ablkcipher_request) +
  545. crypto_ablkcipher_reqsize(tfm), gfp);
  546. if (likely(req))
  547. ablkcipher_request_set_tfm(req, tfm);
  548. return req;
  549. }
  550. static inline void ablkcipher_request_free(struct ablkcipher_request *req)
  551. {
  552. kfree(req);
  553. }
  554. static inline void ablkcipher_request_set_callback(
  555. struct ablkcipher_request *req,
  556. u32 flags, crypto_completion_t complete, void *data)
  557. {
  558. req->base.complete = complete;
  559. req->base.data = data;
  560. req->base.flags = flags;
  561. }
  562. static inline void ablkcipher_request_set_crypt(
  563. struct ablkcipher_request *req,
  564. struct scatterlist *src, struct scatterlist *dst,
  565. unsigned int nbytes, void *iv)
  566. {
  567. req->src = src;
  568. req->dst = dst;
  569. req->nbytes = nbytes;
  570. req->info = iv;
  571. }
  572. static inline struct crypto_aead *__crypto_aead_cast(struct crypto_tfm *tfm)
  573. {
  574. return (struct crypto_aead *)tfm;
  575. }
  576. static inline struct crypto_aead *crypto_alloc_aead(const char *alg_name,
  577. u32 type, u32 mask)
  578. {
  579. type &= ~CRYPTO_ALG_TYPE_MASK;
  580. type |= CRYPTO_ALG_TYPE_AEAD;
  581. mask |= CRYPTO_ALG_TYPE_MASK;
  582. return __crypto_aead_cast(crypto_alloc_base(alg_name, type, mask));
  583. }
  584. static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm)
  585. {
  586. return &tfm->base;
  587. }
  588. static inline void crypto_free_aead(struct crypto_aead *tfm)
  589. {
  590. crypto_free_tfm(crypto_aead_tfm(tfm));
  591. }
  592. static inline struct aead_tfm *crypto_aead_crt(struct crypto_aead *tfm)
  593. {
  594. return &crypto_aead_tfm(tfm)->crt_aead;
  595. }
  596. static inline unsigned int crypto_aead_ivsize(struct crypto_aead *tfm)
  597. {
  598. return crypto_aead_crt(tfm)->ivsize;
  599. }
  600. static inline unsigned int crypto_aead_authsize(struct crypto_aead *tfm)
  601. {
  602. return crypto_aead_crt(tfm)->authsize;
  603. }
  604. static inline unsigned int crypto_aead_blocksize(struct crypto_aead *tfm)
  605. {
  606. return crypto_tfm_alg_blocksize(crypto_aead_tfm(tfm));
  607. }
  608. static inline unsigned int crypto_aead_alignmask(struct crypto_aead *tfm)
  609. {
  610. return crypto_tfm_alg_alignmask(crypto_aead_tfm(tfm));
  611. }
  612. static inline u32 crypto_aead_get_flags(struct crypto_aead *tfm)
  613. {
  614. return crypto_tfm_get_flags(crypto_aead_tfm(tfm));
  615. }
  616. static inline void crypto_aead_set_flags(struct crypto_aead *tfm, u32 flags)
  617. {
  618. crypto_tfm_set_flags(crypto_aead_tfm(tfm), flags);
  619. }
  620. static inline void crypto_aead_clear_flags(struct crypto_aead *tfm, u32 flags)
  621. {
  622. crypto_tfm_clear_flags(crypto_aead_tfm(tfm), flags);
  623. }
  624. static inline int crypto_aead_setkey(struct crypto_aead *tfm, const u8 *key,
  625. unsigned int keylen)
  626. {
  627. return crypto_aead_crt(tfm)->setkey(tfm, key, keylen);
  628. }
  629. int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize);
  630. static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req)
  631. {
  632. return __crypto_aead_cast(req->base.tfm);
  633. }
  634. static inline int crypto_aead_encrypt(struct aead_request *req)
  635. {
  636. return crypto_aead_crt(crypto_aead_reqtfm(req))->encrypt(req);
  637. }
  638. static inline int crypto_aead_decrypt(struct aead_request *req)
  639. {
  640. return crypto_aead_crt(crypto_aead_reqtfm(req))->decrypt(req);
  641. }
  642. static inline unsigned int crypto_aead_reqsize(struct crypto_aead *tfm)
  643. {
  644. return crypto_aead_crt(tfm)->reqsize;
  645. }
  646. static inline void aead_request_set_tfm(struct aead_request *req,
  647. struct crypto_aead *tfm)
  648. {
  649. req->base.tfm = crypto_aead_tfm(tfm);
  650. }
  651. static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm,
  652. gfp_t gfp)
  653. {
  654. struct aead_request *req;
  655. req = kmalloc(sizeof(*req) + crypto_aead_reqsize(tfm), gfp);
  656. if (likely(req))
  657. aead_request_set_tfm(req, tfm);
  658. return req;
  659. }
  660. static inline void aead_request_free(struct aead_request *req)
  661. {
  662. kfree(req);
  663. }
  664. static inline void aead_request_set_callback(struct aead_request *req,
  665. u32 flags,
  666. crypto_completion_t complete,
  667. void *data)
  668. {
  669. req->base.complete = complete;
  670. req->base.data = data;
  671. req->base.flags = flags;
  672. }
  673. static inline void aead_request_set_crypt(struct aead_request *req,
  674. struct scatterlist *src,
  675. struct scatterlist *dst,
  676. unsigned int cryptlen, u8 *iv)
  677. {
  678. req->src = src;
  679. req->dst = dst;
  680. req->cryptlen = cryptlen;
  681. req->iv = iv;
  682. }
  683. static inline void aead_request_set_assoc(struct aead_request *req,
  684. struct scatterlist *assoc,
  685. unsigned int assoclen)
  686. {
  687. req->assoc = assoc;
  688. req->assoclen = assoclen;
  689. }
  690. static inline struct crypto_blkcipher *__crypto_blkcipher_cast(
  691. struct crypto_tfm *tfm)
  692. {
  693. return (struct crypto_blkcipher *)tfm;
  694. }
  695. static inline struct crypto_blkcipher *crypto_blkcipher_cast(
  696. struct crypto_tfm *tfm)
  697. {
  698. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_BLKCIPHER);
  699. return __crypto_blkcipher_cast(tfm);
  700. }
  701. static inline struct crypto_blkcipher *crypto_alloc_blkcipher(
  702. const char *alg_name, u32 type, u32 mask)
  703. {
  704. type &= ~CRYPTO_ALG_TYPE_MASK;
  705. type |= CRYPTO_ALG_TYPE_BLKCIPHER;
  706. mask |= CRYPTO_ALG_TYPE_MASK;
  707. return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask));
  708. }
  709. static inline struct crypto_tfm *crypto_blkcipher_tfm(
  710. struct crypto_blkcipher *tfm)
  711. {
  712. return &tfm->base;
  713. }
  714. static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm)
  715. {
  716. crypto_free_tfm(crypto_blkcipher_tfm(tfm));
  717. }
  718. static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask)
  719. {
  720. type &= ~CRYPTO_ALG_TYPE_MASK;
  721. type |= CRYPTO_ALG_TYPE_BLKCIPHER;
  722. mask |= CRYPTO_ALG_TYPE_MASK;
  723. return crypto_has_alg(alg_name, type, mask);
  724. }
  725. static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm)
  726. {
  727. return crypto_tfm_alg_name(crypto_blkcipher_tfm(tfm));
  728. }
  729. static inline struct blkcipher_tfm *crypto_blkcipher_crt(
  730. struct crypto_blkcipher *tfm)
  731. {
  732. return &crypto_blkcipher_tfm(tfm)->crt_blkcipher;
  733. }
  734. static inline struct blkcipher_alg *crypto_blkcipher_alg(
  735. struct crypto_blkcipher *tfm)
  736. {
  737. return &crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher;
  738. }
  739. static inline unsigned int crypto_blkcipher_ivsize(struct crypto_blkcipher *tfm)
  740. {
  741. return crypto_blkcipher_alg(tfm)->ivsize;
  742. }
  743. static inline unsigned int crypto_blkcipher_blocksize(
  744. struct crypto_blkcipher *tfm)
  745. {
  746. return crypto_tfm_alg_blocksize(crypto_blkcipher_tfm(tfm));
  747. }
  748. static inline unsigned int crypto_blkcipher_alignmask(
  749. struct crypto_blkcipher *tfm)
  750. {
  751. return crypto_tfm_alg_alignmask(crypto_blkcipher_tfm(tfm));
  752. }
  753. static inline u32 crypto_blkcipher_get_flags(struct crypto_blkcipher *tfm)
  754. {
  755. return crypto_tfm_get_flags(crypto_blkcipher_tfm(tfm));
  756. }
  757. static inline void crypto_blkcipher_set_flags(struct crypto_blkcipher *tfm,
  758. u32 flags)
  759. {
  760. crypto_tfm_set_flags(crypto_blkcipher_tfm(tfm), flags);
  761. }
  762. static inline void crypto_blkcipher_clear_flags(struct crypto_blkcipher *tfm,
  763. u32 flags)
  764. {
  765. crypto_tfm_clear_flags(crypto_blkcipher_tfm(tfm), flags);
  766. }
  767. static inline int crypto_blkcipher_setkey(struct crypto_blkcipher *tfm,
  768. const u8 *key, unsigned int keylen)
  769. {
  770. return crypto_blkcipher_crt(tfm)->setkey(crypto_blkcipher_tfm(tfm),
  771. key, keylen);
  772. }
  773. static inline int crypto_blkcipher_encrypt(struct blkcipher_desc *desc,
  774. struct scatterlist *dst,
  775. struct scatterlist *src,
  776. unsigned int nbytes)
  777. {
  778. desc->info = crypto_blkcipher_crt(desc->tfm)->iv;
  779. return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes);
  780. }
  781. static inline int crypto_blkcipher_encrypt_iv(struct blkcipher_desc *desc,
  782. struct scatterlist *dst,
  783. struct scatterlist *src,
  784. unsigned int nbytes)
  785. {
  786. return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes);
  787. }
  788. static inline int crypto_blkcipher_decrypt(struct blkcipher_desc *desc,
  789. struct scatterlist *dst,
  790. struct scatterlist *src,
  791. unsigned int nbytes)
  792. {
  793. desc->info = crypto_blkcipher_crt(desc->tfm)->iv;
  794. return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes);
  795. }
  796. static inline int crypto_blkcipher_decrypt_iv(struct blkcipher_desc *desc,
  797. struct scatterlist *dst,
  798. struct scatterlist *src,
  799. unsigned int nbytes)
  800. {
  801. return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes);
  802. }
  803. static inline void crypto_blkcipher_set_iv(struct crypto_blkcipher *tfm,
  804. const u8 *src, unsigned int len)
  805. {
  806. memcpy(crypto_blkcipher_crt(tfm)->iv, src, len);
  807. }
  808. static inline void crypto_blkcipher_get_iv(struct crypto_blkcipher *tfm,
  809. u8 *dst, unsigned int len)
  810. {
  811. memcpy(dst, crypto_blkcipher_crt(tfm)->iv, len);
  812. }
  813. static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm)
  814. {
  815. return (struct crypto_cipher *)tfm;
  816. }
  817. static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm)
  818. {
  819. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  820. return __crypto_cipher_cast(tfm);
  821. }
  822. static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name,
  823. u32 type, u32 mask)
  824. {
  825. type &= ~CRYPTO_ALG_TYPE_MASK;
  826. type |= CRYPTO_ALG_TYPE_CIPHER;
  827. mask |= CRYPTO_ALG_TYPE_MASK;
  828. return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask));
  829. }
  830. static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm)
  831. {
  832. return &tfm->base;
  833. }
  834. static inline void crypto_free_cipher(struct crypto_cipher *tfm)
  835. {
  836. crypto_free_tfm(crypto_cipher_tfm(tfm));
  837. }
  838. static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask)
  839. {
  840. type &= ~CRYPTO_ALG_TYPE_MASK;
  841. type |= CRYPTO_ALG_TYPE_CIPHER;
  842. mask |= CRYPTO_ALG_TYPE_MASK;
  843. return crypto_has_alg(alg_name, type, mask);
  844. }
  845. static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm)
  846. {
  847. return &crypto_cipher_tfm(tfm)->crt_cipher;
  848. }
  849. static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm)
  850. {
  851. return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm));
  852. }
  853. static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm)
  854. {
  855. return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm));
  856. }
  857. static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm)
  858. {
  859. return crypto_tfm_get_flags(crypto_cipher_tfm(tfm));
  860. }
  861. static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm,
  862. u32 flags)
  863. {
  864. crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags);
  865. }
  866. static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm,
  867. u32 flags)
  868. {
  869. crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags);
  870. }
  871. static inline int crypto_cipher_setkey(struct crypto_cipher *tfm,
  872. const u8 *key, unsigned int keylen)
  873. {
  874. return crypto_cipher_crt(tfm)->cit_setkey(crypto_cipher_tfm(tfm),
  875. key, keylen);
  876. }
  877. static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
  878. u8 *dst, const u8 *src)
  879. {
  880. crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm),
  881. dst, src);
  882. }
  883. static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
  884. u8 *dst, const u8 *src)
  885. {
  886. crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm),
  887. dst, src);
  888. }
  889. static inline struct crypto_hash *__crypto_hash_cast(struct crypto_tfm *tfm)
  890. {
  891. return (struct crypto_hash *)tfm;
  892. }
  893. static inline struct crypto_hash *crypto_hash_cast(struct crypto_tfm *tfm)
  894. {
  895. BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_HASH) &
  896. CRYPTO_ALG_TYPE_HASH_MASK);
  897. return __crypto_hash_cast(tfm);
  898. }
  899. static inline struct crypto_hash *crypto_alloc_hash(const char *alg_name,
  900. u32 type, u32 mask)
  901. {
  902. type &= ~CRYPTO_ALG_TYPE_MASK;
  903. mask &= ~CRYPTO_ALG_TYPE_MASK;
  904. type |= CRYPTO_ALG_TYPE_HASH;
  905. mask |= CRYPTO_ALG_TYPE_HASH_MASK;
  906. return __crypto_hash_cast(crypto_alloc_base(alg_name, type, mask));
  907. }
  908. static inline struct crypto_tfm *crypto_hash_tfm(struct crypto_hash *tfm)
  909. {
  910. return &tfm->base;
  911. }
  912. static inline void crypto_free_hash(struct crypto_hash *tfm)
  913. {
  914. crypto_free_tfm(crypto_hash_tfm(tfm));
  915. }
  916. static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask)
  917. {
  918. type &= ~CRYPTO_ALG_TYPE_MASK;
  919. mask &= ~CRYPTO_ALG_TYPE_MASK;
  920. type |= CRYPTO_ALG_TYPE_HASH;
  921. mask |= CRYPTO_ALG_TYPE_HASH_MASK;
  922. return crypto_has_alg(alg_name, type, mask);
  923. }
  924. static inline struct hash_tfm *crypto_hash_crt(struct crypto_hash *tfm)
  925. {
  926. return &crypto_hash_tfm(tfm)->crt_hash;
  927. }
  928. static inline unsigned int crypto_hash_blocksize(struct crypto_hash *tfm)
  929. {
  930. return crypto_tfm_alg_blocksize(crypto_hash_tfm(tfm));
  931. }
  932. static inline unsigned int crypto_hash_alignmask(struct crypto_hash *tfm)
  933. {
  934. return crypto_tfm_alg_alignmask(crypto_hash_tfm(tfm));
  935. }
  936. static inline unsigned int crypto_hash_digestsize(struct crypto_hash *tfm)
  937. {
  938. return crypto_hash_crt(tfm)->digestsize;
  939. }
  940. static inline u32 crypto_hash_get_flags(struct crypto_hash *tfm)
  941. {
  942. return crypto_tfm_get_flags(crypto_hash_tfm(tfm));
  943. }
  944. static inline void crypto_hash_set_flags(struct crypto_hash *tfm, u32 flags)
  945. {
  946. crypto_tfm_set_flags(crypto_hash_tfm(tfm), flags);
  947. }
  948. static inline void crypto_hash_clear_flags(struct crypto_hash *tfm, u32 flags)
  949. {
  950. crypto_tfm_clear_flags(crypto_hash_tfm(tfm), flags);
  951. }
  952. static inline int crypto_hash_init(struct hash_desc *desc)
  953. {
  954. return crypto_hash_crt(desc->tfm)->init(desc);
  955. }
  956. static inline int crypto_hash_update(struct hash_desc *desc,
  957. struct scatterlist *sg,
  958. unsigned int nbytes)
  959. {
  960. return crypto_hash_crt(desc->tfm)->update(desc, sg, nbytes);
  961. }
  962. static inline int crypto_hash_final(struct hash_desc *desc, u8 *out)
  963. {
  964. return crypto_hash_crt(desc->tfm)->final(desc, out);
  965. }
  966. static inline int crypto_hash_digest(struct hash_desc *desc,
  967. struct scatterlist *sg,
  968. unsigned int nbytes, u8 *out)
  969. {
  970. return crypto_hash_crt(desc->tfm)->digest(desc, sg, nbytes, out);
  971. }
  972. static inline int crypto_hash_setkey(struct crypto_hash *hash,
  973. const u8 *key, unsigned int keylen)
  974. {
  975. return crypto_hash_crt(hash)->setkey(hash, key, keylen);
  976. }
  977. static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm)
  978. {
  979. return (struct crypto_comp *)tfm;
  980. }
  981. static inline struct crypto_comp *crypto_comp_cast(struct crypto_tfm *tfm)
  982. {
  983. BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_COMPRESS) &
  984. CRYPTO_ALG_TYPE_MASK);
  985. return __crypto_comp_cast(tfm);
  986. }
  987. static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name,
  988. u32 type, u32 mask)
  989. {
  990. type &= ~CRYPTO_ALG_TYPE_MASK;
  991. type |= CRYPTO_ALG_TYPE_COMPRESS;
  992. mask |= CRYPTO_ALG_TYPE_MASK;
  993. return __crypto_comp_cast(crypto_alloc_base(alg_name, type, mask));
  994. }
  995. static inline struct crypto_tfm *crypto_comp_tfm(struct crypto_comp *tfm)
  996. {
  997. return &tfm->base;
  998. }
  999. static inline void crypto_free_comp(struct crypto_comp *tfm)
  1000. {
  1001. crypto_free_tfm(crypto_comp_tfm(tfm));
  1002. }
  1003. static inline int crypto_has_comp(const char *alg_name, u32 type, u32 mask)
  1004. {
  1005. type &= ~CRYPTO_ALG_TYPE_MASK;
  1006. type |= CRYPTO_ALG_TYPE_COMPRESS;
  1007. mask |= CRYPTO_ALG_TYPE_MASK;
  1008. return crypto_has_alg(alg_name, type, mask);
  1009. }
  1010. static inline const char *crypto_comp_name(struct crypto_comp *tfm)
  1011. {
  1012. return crypto_tfm_alg_name(crypto_comp_tfm(tfm));
  1013. }
  1014. static inline struct compress_tfm *crypto_comp_crt(struct crypto_comp *tfm)
  1015. {
  1016. return &crypto_comp_tfm(tfm)->crt_compress;
  1017. }
  1018. static inline int crypto_comp_compress(struct crypto_comp *tfm,
  1019. const u8 *src, unsigned int slen,
  1020. u8 *dst, unsigned int *dlen)
  1021. {
  1022. return crypto_comp_crt(tfm)->cot_compress(crypto_comp_tfm(tfm),
  1023. src, slen, dst, dlen);
  1024. }
  1025. static inline int crypto_comp_decompress(struct crypto_comp *tfm,
  1026. const u8 *src, unsigned int slen,
  1027. u8 *dst, unsigned int *dlen)
  1028. {
  1029. return crypto_comp_crt(tfm)->cot_decompress(crypto_comp_tfm(tfm),
  1030. src, slen, dst, dlen);
  1031. }
  1032. #endif /* _LINUX_CRYPTO_H */