crypto.h 32 KB

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