crypto.h 32 KB

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