crypto.h 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  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/kernel.h>
  21. #include <linux/list.h>
  22. #include <linux/bug.h>
  23. #include <linux/slab.h>
  24. #include <linux/string.h>
  25. #include <linux/uaccess.h>
  26. #include <linux/completion.h>
  27. /*
  28. * Autoloaded crypto modules should only use a prefixed name to avoid allowing
  29. * arbitrary modules to be loaded. Loading from userspace may still need the
  30. * unprefixed names, so retains those aliases as well.
  31. * This uses __MODULE_INFO directly instead of MODULE_ALIAS because pre-4.3
  32. * gcc (e.g. avr32 toolchain) uses __LINE__ for uniqueness, and this macro
  33. * expands twice on the same line. Instead, use a separate base name for the
  34. * alias.
  35. */
  36. #define MODULE_ALIAS_CRYPTO(name) \
  37. __MODULE_INFO(alias, alias_userspace, name); \
  38. __MODULE_INFO(alias, alias_crypto, "crypto-" name)
  39. /*
  40. * Algorithm masks and types.
  41. */
  42. #define CRYPTO_ALG_TYPE_MASK 0x0000000f
  43. #define CRYPTO_ALG_TYPE_CIPHER 0x00000001
  44. #define CRYPTO_ALG_TYPE_COMPRESS 0x00000002
  45. #define CRYPTO_ALG_TYPE_AEAD 0x00000003
  46. #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004
  47. #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005
  48. #define CRYPTO_ALG_TYPE_SKCIPHER 0x00000005
  49. #define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006
  50. #define CRYPTO_ALG_TYPE_KPP 0x00000008
  51. #define CRYPTO_ALG_TYPE_ACOMPRESS 0x0000000a
  52. #define CRYPTO_ALG_TYPE_SCOMPRESS 0x0000000b
  53. #define CRYPTO_ALG_TYPE_RNG 0x0000000c
  54. #define CRYPTO_ALG_TYPE_AKCIPHER 0x0000000d
  55. #define CRYPTO_ALG_TYPE_DIGEST 0x0000000e
  56. #define CRYPTO_ALG_TYPE_HASH 0x0000000e
  57. #define CRYPTO_ALG_TYPE_SHASH 0x0000000e
  58. #define CRYPTO_ALG_TYPE_AHASH 0x0000000f
  59. #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
  60. #define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000e
  61. #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c
  62. #define CRYPTO_ALG_TYPE_ACOMPRESS_MASK 0x0000000e
  63. #define CRYPTO_ALG_LARVAL 0x00000010
  64. #define CRYPTO_ALG_DEAD 0x00000020
  65. #define CRYPTO_ALG_DYING 0x00000040
  66. #define CRYPTO_ALG_ASYNC 0x00000080
  67. /*
  68. * Set this bit if and only if the algorithm requires another algorithm of
  69. * the same type to handle corner cases.
  70. */
  71. #define CRYPTO_ALG_NEED_FALLBACK 0x00000100
  72. /*
  73. * This bit is set for symmetric key ciphers that have already been wrapped
  74. * with a generic IV generator to prevent them from being wrapped again.
  75. */
  76. #define CRYPTO_ALG_GENIV 0x00000200
  77. /*
  78. * Set if the algorithm has passed automated run-time testing. Note that
  79. * if there is no run-time testing for a given algorithm it is considered
  80. * to have passed.
  81. */
  82. #define CRYPTO_ALG_TESTED 0x00000400
  83. /*
  84. * Set if the algorithm is an instance that is built from templates.
  85. */
  86. #define CRYPTO_ALG_INSTANCE 0x00000800
  87. /* Set this bit if the algorithm provided is hardware accelerated but
  88. * not available to userspace via instruction set or so.
  89. */
  90. #define CRYPTO_ALG_KERN_DRIVER_ONLY 0x00001000
  91. /*
  92. * Mark a cipher as a service implementation only usable by another
  93. * cipher and never by a normal user of the kernel crypto API
  94. */
  95. #define CRYPTO_ALG_INTERNAL 0x00002000
  96. /*
  97. * Set if the algorithm has a ->setkey() method but can be used without
  98. * calling it first, i.e. there is a default key.
  99. */
  100. #define CRYPTO_ALG_OPTIONAL_KEY 0x00004000
  101. /*
  102. * Don't trigger module loading
  103. */
  104. #define CRYPTO_NOLOAD 0x00008000
  105. /*
  106. * Transform masks and values (for crt_flags).
  107. */
  108. #define CRYPTO_TFM_NEED_KEY 0x00000001
  109. #define CRYPTO_TFM_REQ_MASK 0x000fff00
  110. #define CRYPTO_TFM_RES_MASK 0xfff00000
  111. #define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100
  112. #define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
  113. #define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400
  114. #define CRYPTO_TFM_RES_WEAK_KEY 0x00100000
  115. #define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000
  116. #define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000
  117. #define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000
  118. #define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000
  119. /*
  120. * Miscellaneous stuff.
  121. */
  122. #define CRYPTO_MAX_ALG_NAME 128
  123. /*
  124. * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual
  125. * declaration) is used to ensure that the crypto_tfm context structure is
  126. * aligned correctly for the given architecture so that there are no alignment
  127. * faults for C data types. In particular, this is required on platforms such
  128. * as arm where pointers are 32-bit aligned but there are data types such as
  129. * u64 which require 64-bit alignment.
  130. */
  131. #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN
  132. #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN)))
  133. struct scatterlist;
  134. struct crypto_ablkcipher;
  135. struct crypto_async_request;
  136. struct crypto_blkcipher;
  137. struct crypto_tfm;
  138. struct crypto_type;
  139. struct skcipher_givcrypt_request;
  140. typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err);
  141. /**
  142. * DOC: Block Cipher Context Data Structures
  143. *
  144. * These data structures define the operating context for each block cipher
  145. * type.
  146. */
  147. struct crypto_async_request {
  148. struct list_head list;
  149. crypto_completion_t complete;
  150. void *data;
  151. struct crypto_tfm *tfm;
  152. u32 flags;
  153. };
  154. struct ablkcipher_request {
  155. struct crypto_async_request base;
  156. unsigned int nbytes;
  157. void *info;
  158. struct scatterlist *src;
  159. struct scatterlist *dst;
  160. void *__ctx[] CRYPTO_MINALIGN_ATTR;
  161. };
  162. struct blkcipher_desc {
  163. struct crypto_blkcipher *tfm;
  164. void *info;
  165. u32 flags;
  166. };
  167. struct cipher_desc {
  168. struct crypto_tfm *tfm;
  169. void (*crfn)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  170. unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst,
  171. const u8 *src, unsigned int nbytes);
  172. void *info;
  173. };
  174. /**
  175. * DOC: Block Cipher Algorithm Definitions
  176. *
  177. * These data structures define modular crypto algorithm implementations,
  178. * managed via crypto_register_alg() and crypto_unregister_alg().
  179. */
  180. /**
  181. * struct ablkcipher_alg - asynchronous block cipher definition
  182. * @min_keysize: Minimum key size supported by the transformation. This is the
  183. * smallest key length supported by this transformation algorithm.
  184. * This must be set to one of the pre-defined values as this is
  185. * not hardware specific. Possible values for this field can be
  186. * found via git grep "_MIN_KEY_SIZE" include/crypto/
  187. * @max_keysize: Maximum key size supported by the transformation. This is the
  188. * largest key length supported by this transformation algorithm.
  189. * This must be set to one of the pre-defined values as this is
  190. * not hardware specific. Possible values for this field can be
  191. * found via git grep "_MAX_KEY_SIZE" include/crypto/
  192. * @setkey: Set key for the transformation. This function is used to either
  193. * program a supplied key into the hardware or store the key in the
  194. * transformation context for programming it later. Note that this
  195. * function does modify the transformation context. This function can
  196. * be called multiple times during the existence of the transformation
  197. * object, so one must make sure the key is properly reprogrammed into
  198. * the hardware. This function is also responsible for checking the key
  199. * length for validity. In case a software fallback was put in place in
  200. * the @cra_init call, this function might need to use the fallback if
  201. * the algorithm doesn't support all of the key sizes.
  202. * @encrypt: Encrypt a scatterlist of blocks. This function is used to encrypt
  203. * the supplied scatterlist containing the blocks of data. The crypto
  204. * API consumer is responsible for aligning the entries of the
  205. * scatterlist properly and making sure the chunks are correctly
  206. * sized. In case a software fallback was put in place in the
  207. * @cra_init call, this function might need to use the fallback if
  208. * the algorithm doesn't support all of the key sizes. In case the
  209. * key was stored in transformation context, the key might need to be
  210. * re-programmed into the hardware in this function. This function
  211. * shall not modify the transformation context, as this function may
  212. * be called in parallel with the same transformation object.
  213. * @decrypt: Decrypt a single block. This is a reverse counterpart to @encrypt
  214. * and the conditions are exactly the same.
  215. * @givencrypt: Update the IV for encryption. With this function, a cipher
  216. * implementation may provide the function on how to update the IV
  217. * for encryption.
  218. * @givdecrypt: Update the IV for decryption. This is the reverse of
  219. * @givencrypt .
  220. * @geniv: The transformation implementation may use an "IV generator" provided
  221. * by the kernel crypto API. Several use cases have a predefined
  222. * approach how IVs are to be updated. For such use cases, the kernel
  223. * crypto API provides ready-to-use implementations that can be
  224. * referenced with this variable.
  225. * @ivsize: IV size applicable for transformation. The consumer must provide an
  226. * IV of exactly that size to perform the encrypt or decrypt operation.
  227. *
  228. * All fields except @givencrypt , @givdecrypt , @geniv and @ivsize are
  229. * mandatory and must be filled.
  230. */
  231. struct ablkcipher_alg {
  232. int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key,
  233. unsigned int keylen);
  234. int (*encrypt)(struct ablkcipher_request *req);
  235. int (*decrypt)(struct ablkcipher_request *req);
  236. int (*givencrypt)(struct skcipher_givcrypt_request *req);
  237. int (*givdecrypt)(struct skcipher_givcrypt_request *req);
  238. const char *geniv;
  239. unsigned int min_keysize;
  240. unsigned int max_keysize;
  241. unsigned int ivsize;
  242. };
  243. /**
  244. * struct blkcipher_alg - synchronous block cipher definition
  245. * @min_keysize: see struct ablkcipher_alg
  246. * @max_keysize: see struct ablkcipher_alg
  247. * @setkey: see struct ablkcipher_alg
  248. * @encrypt: see struct ablkcipher_alg
  249. * @decrypt: see struct ablkcipher_alg
  250. * @geniv: see struct ablkcipher_alg
  251. * @ivsize: see struct ablkcipher_alg
  252. *
  253. * All fields except @geniv and @ivsize are mandatory and must be filled.
  254. */
  255. struct blkcipher_alg {
  256. int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
  257. unsigned int keylen);
  258. int (*encrypt)(struct blkcipher_desc *desc,
  259. struct scatterlist *dst, struct scatterlist *src,
  260. unsigned int nbytes);
  261. int (*decrypt)(struct blkcipher_desc *desc,
  262. struct scatterlist *dst, struct scatterlist *src,
  263. unsigned int nbytes);
  264. const char *geniv;
  265. unsigned int min_keysize;
  266. unsigned int max_keysize;
  267. unsigned int ivsize;
  268. };
  269. /**
  270. * struct cipher_alg - single-block symmetric ciphers definition
  271. * @cia_min_keysize: Minimum key size supported by the transformation. This is
  272. * the smallest key length supported by this transformation
  273. * algorithm. This must be set to one of the pre-defined
  274. * values as this is not hardware specific. Possible values
  275. * for this field can be found via git grep "_MIN_KEY_SIZE"
  276. * include/crypto/
  277. * @cia_max_keysize: Maximum key size supported by the transformation. This is
  278. * the largest key length supported by this transformation
  279. * algorithm. This must be set to one of the pre-defined values
  280. * as this is not hardware specific. Possible values for this
  281. * field can be found via git grep "_MAX_KEY_SIZE"
  282. * include/crypto/
  283. * @cia_setkey: Set key for the transformation. This function is used to either
  284. * program a supplied key into the hardware or store the key in the
  285. * transformation context for programming it later. Note that this
  286. * function does modify the transformation context. This function
  287. * can be called multiple times during the existence of the
  288. * transformation object, so one must make sure the key is properly
  289. * reprogrammed into the hardware. This function is also
  290. * responsible for checking the key length for validity.
  291. * @cia_encrypt: Encrypt a single block. This function is used to encrypt a
  292. * single block of data, which must be @cra_blocksize big. This
  293. * always operates on a full @cra_blocksize and it is not possible
  294. * to encrypt a block of smaller size. The supplied buffers must
  295. * therefore also be at least of @cra_blocksize size. Both the
  296. * input and output buffers are always aligned to @cra_alignmask.
  297. * In case either of the input or output buffer supplied by user
  298. * of the crypto API is not aligned to @cra_alignmask, the crypto
  299. * API will re-align the buffers. The re-alignment means that a
  300. * new buffer will be allocated, the data will be copied into the
  301. * new buffer, then the processing will happen on the new buffer,
  302. * then the data will be copied back into the original buffer and
  303. * finally the new buffer will be freed. In case a software
  304. * fallback was put in place in the @cra_init call, this function
  305. * might need to use the fallback if the algorithm doesn't support
  306. * all of the key sizes. In case the key was stored in
  307. * transformation context, the key might need to be re-programmed
  308. * into the hardware in this function. This function shall not
  309. * modify the transformation context, as this function may be
  310. * called in parallel with the same transformation object.
  311. * @cia_decrypt: Decrypt a single block. This is a reverse counterpart to
  312. * @cia_encrypt, and the conditions are exactly the same.
  313. *
  314. * All fields are mandatory and must be filled.
  315. */
  316. struct cipher_alg {
  317. unsigned int cia_min_keysize;
  318. unsigned int cia_max_keysize;
  319. int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key,
  320. unsigned int keylen);
  321. void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  322. void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  323. };
  324. struct compress_alg {
  325. int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src,
  326. unsigned int slen, u8 *dst, unsigned int *dlen);
  327. int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
  328. unsigned int slen, u8 *dst, unsigned int *dlen);
  329. };
  330. #define cra_ablkcipher cra_u.ablkcipher
  331. #define cra_blkcipher cra_u.blkcipher
  332. #define cra_cipher cra_u.cipher
  333. #define cra_compress cra_u.compress
  334. /**
  335. * struct crypto_alg - definition of a cryptograpic cipher algorithm
  336. * @cra_flags: Flags describing this transformation. See include/linux/crypto.h
  337. * CRYPTO_ALG_* flags for the flags which go in here. Those are
  338. * used for fine-tuning the description of the transformation
  339. * algorithm.
  340. * @cra_blocksize: Minimum block size of this transformation. The size in bytes
  341. * of the smallest possible unit which can be transformed with
  342. * this algorithm. The users must respect this value.
  343. * In case of HASH transformation, it is possible for a smaller
  344. * block than @cra_blocksize to be passed to the crypto API for
  345. * transformation, in case of any other transformation type, an
  346. * error will be returned upon any attempt to transform smaller
  347. * than @cra_blocksize chunks.
  348. * @cra_ctxsize: Size of the operational context of the transformation. This
  349. * value informs the kernel crypto API about the memory size
  350. * needed to be allocated for the transformation context.
  351. * @cra_alignmask: Alignment mask for the input and output data buffer. The data
  352. * buffer containing the input data for the algorithm must be
  353. * aligned to this alignment mask. The data buffer for the
  354. * output data must be aligned to this alignment mask. Note that
  355. * the Crypto API will do the re-alignment in software, but
  356. * only under special conditions and there is a performance hit.
  357. * The re-alignment happens at these occasions for different
  358. * @cra_u types: cipher -- For both input data and output data
  359. * buffer; ahash -- For output hash destination buf; shash --
  360. * For output hash destination buf.
  361. * This is needed on hardware which is flawed by design and
  362. * cannot pick data from arbitrary addresses.
  363. * @cra_priority: Priority of this transformation implementation. In case
  364. * multiple transformations with same @cra_name are available to
  365. * the Crypto API, the kernel will use the one with highest
  366. * @cra_priority.
  367. * @cra_name: Generic name (usable by multiple implementations) of the
  368. * transformation algorithm. This is the name of the transformation
  369. * itself. This field is used by the kernel when looking up the
  370. * providers of particular transformation.
  371. * @cra_driver_name: Unique name of the transformation provider. This is the
  372. * name of the provider of the transformation. This can be any
  373. * arbitrary value, but in the usual case, this contains the
  374. * name of the chip or provider and the name of the
  375. * transformation algorithm.
  376. * @cra_type: Type of the cryptographic transformation. This is a pointer to
  377. * struct crypto_type, which implements callbacks common for all
  378. * transformation types. There are multiple options:
  379. * &crypto_blkcipher_type, &crypto_ablkcipher_type,
  380. * &crypto_ahash_type, &crypto_rng_type.
  381. * This field might be empty. In that case, there are no common
  382. * callbacks. This is the case for: cipher, compress, shash.
  383. * @cra_u: Callbacks implementing the transformation. This is a union of
  384. * multiple structures. Depending on the type of transformation selected
  385. * by @cra_type and @cra_flags above, the associated structure must be
  386. * filled with callbacks. This field might be empty. This is the case
  387. * for ahash, shash.
  388. * @cra_init: Initialize the cryptographic transformation object. This function
  389. * is used to initialize the cryptographic transformation object.
  390. * This function is called only once at the instantiation time, right
  391. * after the transformation context was allocated. In case the
  392. * cryptographic hardware has some special requirements which need to
  393. * be handled by software, this function shall check for the precise
  394. * requirement of the transformation and put any software fallbacks
  395. * in place.
  396. * @cra_exit: Deinitialize the cryptographic transformation object. This is a
  397. * counterpart to @cra_init, used to remove various changes set in
  398. * @cra_init.
  399. * @cra_u.ablkcipher: Union member which contains an asynchronous block cipher
  400. * definition. See @struct @ablkcipher_alg.
  401. * @cra_u.blkcipher: Union member which contains a synchronous block cipher
  402. * definition See @struct @blkcipher_alg.
  403. * @cra_u.cipher: Union member which contains a single-block symmetric cipher
  404. * definition. See @struct @cipher_alg.
  405. * @cra_u.compress: Union member which contains a (de)compression algorithm.
  406. * See @struct @compress_alg.
  407. * @cra_module: Owner of this transformation implementation. Set to THIS_MODULE
  408. * @cra_list: internally used
  409. * @cra_users: internally used
  410. * @cra_refcnt: internally used
  411. * @cra_destroy: internally used
  412. *
  413. * The struct crypto_alg describes a generic Crypto API algorithm and is common
  414. * for all of the transformations. Any variable not documented here shall not
  415. * be used by a cipher implementation as it is internal to the Crypto API.
  416. */
  417. struct crypto_alg {
  418. struct list_head cra_list;
  419. struct list_head cra_users;
  420. u32 cra_flags;
  421. unsigned int cra_blocksize;
  422. unsigned int cra_ctxsize;
  423. unsigned int cra_alignmask;
  424. int cra_priority;
  425. refcount_t cra_refcnt;
  426. char cra_name[CRYPTO_MAX_ALG_NAME];
  427. char cra_driver_name[CRYPTO_MAX_ALG_NAME];
  428. const struct crypto_type *cra_type;
  429. union {
  430. struct ablkcipher_alg ablkcipher;
  431. struct blkcipher_alg blkcipher;
  432. struct cipher_alg cipher;
  433. struct compress_alg compress;
  434. } cra_u;
  435. int (*cra_init)(struct crypto_tfm *tfm);
  436. void (*cra_exit)(struct crypto_tfm *tfm);
  437. void (*cra_destroy)(struct crypto_alg *alg);
  438. struct module *cra_module;
  439. } CRYPTO_MINALIGN_ATTR;
  440. /*
  441. * A helper struct for waiting for completion of async crypto ops
  442. */
  443. struct crypto_wait {
  444. struct completion completion;
  445. int err;
  446. };
  447. /*
  448. * Macro for declaring a crypto op async wait object on stack
  449. */
  450. #define DECLARE_CRYPTO_WAIT(_wait) \
  451. struct crypto_wait _wait = { \
  452. COMPLETION_INITIALIZER_ONSTACK((_wait).completion), 0 }
  453. /*
  454. * Async ops completion helper functioons
  455. */
  456. void crypto_req_done(struct crypto_async_request *req, int err);
  457. static inline int crypto_wait_req(int err, struct crypto_wait *wait)
  458. {
  459. switch (err) {
  460. case -EINPROGRESS:
  461. case -EBUSY:
  462. wait_for_completion(&wait->completion);
  463. reinit_completion(&wait->completion);
  464. err = wait->err;
  465. break;
  466. };
  467. return err;
  468. }
  469. static inline void crypto_init_wait(struct crypto_wait *wait)
  470. {
  471. init_completion(&wait->completion);
  472. }
  473. /*
  474. * Algorithm registration interface.
  475. */
  476. int crypto_register_alg(struct crypto_alg *alg);
  477. int crypto_unregister_alg(struct crypto_alg *alg);
  478. int crypto_register_algs(struct crypto_alg *algs, int count);
  479. int crypto_unregister_algs(struct crypto_alg *algs, int count);
  480. /*
  481. * Algorithm query interface.
  482. */
  483. int crypto_has_alg(const char *name, u32 type, u32 mask);
  484. /*
  485. * Transforms: user-instantiated objects which encapsulate algorithms
  486. * and core processing logic. Managed via crypto_alloc_*() and
  487. * crypto_free_*(), as well as the various helpers below.
  488. */
  489. struct ablkcipher_tfm {
  490. int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key,
  491. unsigned int keylen);
  492. int (*encrypt)(struct ablkcipher_request *req);
  493. int (*decrypt)(struct ablkcipher_request *req);
  494. struct crypto_ablkcipher *base;
  495. unsigned int ivsize;
  496. unsigned int reqsize;
  497. };
  498. struct blkcipher_tfm {
  499. void *iv;
  500. int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
  501. unsigned int keylen);
  502. int (*encrypt)(struct blkcipher_desc *desc, struct scatterlist *dst,
  503. struct scatterlist *src, unsigned int nbytes);
  504. int (*decrypt)(struct blkcipher_desc *desc, struct scatterlist *dst,
  505. struct scatterlist *src, unsigned int nbytes);
  506. };
  507. struct cipher_tfm {
  508. int (*cit_setkey)(struct crypto_tfm *tfm,
  509. const u8 *key, unsigned int keylen);
  510. void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  511. void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
  512. };
  513. struct compress_tfm {
  514. int (*cot_compress)(struct crypto_tfm *tfm,
  515. const u8 *src, unsigned int slen,
  516. u8 *dst, unsigned int *dlen);
  517. int (*cot_decompress)(struct crypto_tfm *tfm,
  518. const u8 *src, unsigned int slen,
  519. u8 *dst, unsigned int *dlen);
  520. };
  521. #define crt_ablkcipher crt_u.ablkcipher
  522. #define crt_blkcipher crt_u.blkcipher
  523. #define crt_cipher crt_u.cipher
  524. #define crt_compress crt_u.compress
  525. struct crypto_tfm {
  526. u32 crt_flags;
  527. union {
  528. struct ablkcipher_tfm ablkcipher;
  529. struct blkcipher_tfm blkcipher;
  530. struct cipher_tfm cipher;
  531. struct compress_tfm compress;
  532. } crt_u;
  533. void (*exit)(struct crypto_tfm *tfm);
  534. struct crypto_alg *__crt_alg;
  535. void *__crt_ctx[] CRYPTO_MINALIGN_ATTR;
  536. };
  537. struct crypto_ablkcipher {
  538. struct crypto_tfm base;
  539. };
  540. struct crypto_blkcipher {
  541. struct crypto_tfm base;
  542. };
  543. struct crypto_cipher {
  544. struct crypto_tfm base;
  545. };
  546. struct crypto_comp {
  547. struct crypto_tfm base;
  548. };
  549. enum {
  550. CRYPTOA_UNSPEC,
  551. CRYPTOA_ALG,
  552. CRYPTOA_TYPE,
  553. CRYPTOA_U32,
  554. __CRYPTOA_MAX,
  555. };
  556. #define CRYPTOA_MAX (__CRYPTOA_MAX - 1)
  557. /* Maximum number of (rtattr) parameters for each template. */
  558. #define CRYPTO_MAX_ATTRS 32
  559. struct crypto_attr_alg {
  560. char name[CRYPTO_MAX_ALG_NAME];
  561. };
  562. struct crypto_attr_type {
  563. u32 type;
  564. u32 mask;
  565. };
  566. struct crypto_attr_u32 {
  567. u32 num;
  568. };
  569. /*
  570. * Transform user interface.
  571. */
  572. struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask);
  573. void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm);
  574. static inline void crypto_free_tfm(struct crypto_tfm *tfm)
  575. {
  576. return crypto_destroy_tfm(tfm, tfm);
  577. }
  578. int alg_test(const char *driver, const char *alg, u32 type, u32 mask);
  579. /*
  580. * Transform helpers which query the underlying algorithm.
  581. */
  582. static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm)
  583. {
  584. return tfm->__crt_alg->cra_name;
  585. }
  586. static inline const char *crypto_tfm_alg_driver_name(struct crypto_tfm *tfm)
  587. {
  588. return tfm->__crt_alg->cra_driver_name;
  589. }
  590. static inline int crypto_tfm_alg_priority(struct crypto_tfm *tfm)
  591. {
  592. return tfm->__crt_alg->cra_priority;
  593. }
  594. static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm)
  595. {
  596. return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK;
  597. }
  598. static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm)
  599. {
  600. return tfm->__crt_alg->cra_blocksize;
  601. }
  602. static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
  603. {
  604. return tfm->__crt_alg->cra_alignmask;
  605. }
  606. static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm)
  607. {
  608. return tfm->crt_flags;
  609. }
  610. static inline void crypto_tfm_set_flags(struct crypto_tfm *tfm, u32 flags)
  611. {
  612. tfm->crt_flags |= flags;
  613. }
  614. static inline void crypto_tfm_clear_flags(struct crypto_tfm *tfm, u32 flags)
  615. {
  616. tfm->crt_flags &= ~flags;
  617. }
  618. static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
  619. {
  620. return tfm->__crt_ctx;
  621. }
  622. static inline unsigned int crypto_tfm_ctx_alignment(void)
  623. {
  624. struct crypto_tfm *tfm;
  625. return __alignof__(tfm->__crt_ctx);
  626. }
  627. /*
  628. * API wrappers.
  629. */
  630. static inline struct crypto_ablkcipher *__crypto_ablkcipher_cast(
  631. struct crypto_tfm *tfm)
  632. {
  633. return (struct crypto_ablkcipher *)tfm;
  634. }
  635. static inline u32 crypto_skcipher_type(u32 type)
  636. {
  637. type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
  638. type |= CRYPTO_ALG_TYPE_BLKCIPHER;
  639. return type;
  640. }
  641. static inline u32 crypto_skcipher_mask(u32 mask)
  642. {
  643. mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
  644. mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
  645. return mask;
  646. }
  647. /**
  648. * DOC: Asynchronous Block Cipher API
  649. *
  650. * Asynchronous block cipher API is used with the ciphers of type
  651. * CRYPTO_ALG_TYPE_ABLKCIPHER (listed as type "ablkcipher" in /proc/crypto).
  652. *
  653. * Asynchronous cipher operations imply that the function invocation for a
  654. * cipher request returns immediately before the completion of the operation.
  655. * The cipher request is scheduled as a separate kernel thread and therefore
  656. * load-balanced on the different CPUs via the process scheduler. To allow
  657. * the kernel crypto API to inform the caller about the completion of a cipher
  658. * request, the caller must provide a callback function. That function is
  659. * invoked with the cipher handle when the request completes.
  660. *
  661. * To support the asynchronous operation, additional information than just the
  662. * cipher handle must be supplied to the kernel crypto API. That additional
  663. * information is given by filling in the ablkcipher_request data structure.
  664. *
  665. * For the asynchronous block cipher API, the state is maintained with the tfm
  666. * cipher handle. A single tfm can be used across multiple calls and in
  667. * parallel. For asynchronous block cipher calls, context data supplied and
  668. * only used by the caller can be referenced the request data structure in
  669. * addition to the IV used for the cipher request. The maintenance of such
  670. * state information would be important for a crypto driver implementer to
  671. * have, because when calling the callback function upon completion of the
  672. * cipher operation, that callback function may need some information about
  673. * which operation just finished if it invoked multiple in parallel. This
  674. * state information is unused by the kernel crypto API.
  675. */
  676. static inline struct crypto_tfm *crypto_ablkcipher_tfm(
  677. struct crypto_ablkcipher *tfm)
  678. {
  679. return &tfm->base;
  680. }
  681. /**
  682. * crypto_free_ablkcipher() - zeroize and free cipher handle
  683. * @tfm: cipher handle to be freed
  684. */
  685. static inline void crypto_free_ablkcipher(struct crypto_ablkcipher *tfm)
  686. {
  687. crypto_free_tfm(crypto_ablkcipher_tfm(tfm));
  688. }
  689. /**
  690. * crypto_has_ablkcipher() - Search for the availability of an ablkcipher.
  691. * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
  692. * ablkcipher
  693. * @type: specifies the type of the cipher
  694. * @mask: specifies the mask for the cipher
  695. *
  696. * Return: true when the ablkcipher is known to the kernel crypto API; false
  697. * otherwise
  698. */
  699. static inline int crypto_has_ablkcipher(const char *alg_name, u32 type,
  700. u32 mask)
  701. {
  702. return crypto_has_alg(alg_name, crypto_skcipher_type(type),
  703. crypto_skcipher_mask(mask));
  704. }
  705. static inline struct ablkcipher_tfm *crypto_ablkcipher_crt(
  706. struct crypto_ablkcipher *tfm)
  707. {
  708. return &crypto_ablkcipher_tfm(tfm)->crt_ablkcipher;
  709. }
  710. /**
  711. * crypto_ablkcipher_ivsize() - obtain IV size
  712. * @tfm: cipher handle
  713. *
  714. * The size of the IV for the ablkcipher referenced by the cipher handle is
  715. * returned. This IV size may be zero if the cipher does not need an IV.
  716. *
  717. * Return: IV size in bytes
  718. */
  719. static inline unsigned int crypto_ablkcipher_ivsize(
  720. struct crypto_ablkcipher *tfm)
  721. {
  722. return crypto_ablkcipher_crt(tfm)->ivsize;
  723. }
  724. /**
  725. * crypto_ablkcipher_blocksize() - obtain block size of cipher
  726. * @tfm: cipher handle
  727. *
  728. * The block size for the ablkcipher referenced with the cipher handle is
  729. * returned. The caller may use that information to allocate appropriate
  730. * memory for the data returned by the encryption or decryption operation
  731. *
  732. * Return: block size of cipher
  733. */
  734. static inline unsigned int crypto_ablkcipher_blocksize(
  735. struct crypto_ablkcipher *tfm)
  736. {
  737. return crypto_tfm_alg_blocksize(crypto_ablkcipher_tfm(tfm));
  738. }
  739. static inline unsigned int crypto_ablkcipher_alignmask(
  740. struct crypto_ablkcipher *tfm)
  741. {
  742. return crypto_tfm_alg_alignmask(crypto_ablkcipher_tfm(tfm));
  743. }
  744. static inline u32 crypto_ablkcipher_get_flags(struct crypto_ablkcipher *tfm)
  745. {
  746. return crypto_tfm_get_flags(crypto_ablkcipher_tfm(tfm));
  747. }
  748. static inline void crypto_ablkcipher_set_flags(struct crypto_ablkcipher *tfm,
  749. u32 flags)
  750. {
  751. crypto_tfm_set_flags(crypto_ablkcipher_tfm(tfm), flags);
  752. }
  753. static inline void crypto_ablkcipher_clear_flags(struct crypto_ablkcipher *tfm,
  754. u32 flags)
  755. {
  756. crypto_tfm_clear_flags(crypto_ablkcipher_tfm(tfm), flags);
  757. }
  758. /**
  759. * crypto_ablkcipher_setkey() - set key for cipher
  760. * @tfm: cipher handle
  761. * @key: buffer holding the key
  762. * @keylen: length of the key in bytes
  763. *
  764. * The caller provided key is set for the ablkcipher referenced by the cipher
  765. * handle.
  766. *
  767. * Note, the key length determines the cipher type. Many block ciphers implement
  768. * different cipher modes depending on the key size, such as AES-128 vs AES-192
  769. * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
  770. * is performed.
  771. *
  772. * Return: 0 if the setting of the key was successful; < 0 if an error occurred
  773. */
  774. static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm,
  775. const u8 *key, unsigned int keylen)
  776. {
  777. struct ablkcipher_tfm *crt = crypto_ablkcipher_crt(tfm);
  778. return crt->setkey(crt->base, key, keylen);
  779. }
  780. /**
  781. * crypto_ablkcipher_reqtfm() - obtain cipher handle from request
  782. * @req: ablkcipher_request out of which the cipher handle is to be obtained
  783. *
  784. * Return the crypto_ablkcipher handle when furnishing an ablkcipher_request
  785. * data structure.
  786. *
  787. * Return: crypto_ablkcipher handle
  788. */
  789. static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm(
  790. struct ablkcipher_request *req)
  791. {
  792. return __crypto_ablkcipher_cast(req->base.tfm);
  793. }
  794. /**
  795. * crypto_ablkcipher_encrypt() - encrypt plaintext
  796. * @req: reference to the ablkcipher_request handle that holds all information
  797. * needed to perform the cipher operation
  798. *
  799. * Encrypt plaintext data using the ablkcipher_request handle. That data
  800. * structure and how it is filled with data is discussed with the
  801. * ablkcipher_request_* functions.
  802. *
  803. * Return: 0 if the cipher operation was successful; < 0 if an error occurred
  804. */
  805. static inline int crypto_ablkcipher_encrypt(struct ablkcipher_request *req)
  806. {
  807. struct ablkcipher_tfm *crt =
  808. crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
  809. return crt->encrypt(req);
  810. }
  811. /**
  812. * crypto_ablkcipher_decrypt() - decrypt ciphertext
  813. * @req: reference to the ablkcipher_request handle that holds all information
  814. * needed to perform the cipher operation
  815. *
  816. * Decrypt ciphertext data using the ablkcipher_request handle. That data
  817. * structure and how it is filled with data is discussed with the
  818. * ablkcipher_request_* functions.
  819. *
  820. * Return: 0 if the cipher operation was successful; < 0 if an error occurred
  821. */
  822. static inline int crypto_ablkcipher_decrypt(struct ablkcipher_request *req)
  823. {
  824. struct ablkcipher_tfm *crt =
  825. crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
  826. return crt->decrypt(req);
  827. }
  828. /**
  829. * DOC: Asynchronous Cipher Request Handle
  830. *
  831. * The ablkcipher_request data structure contains all pointers to data
  832. * required for the asynchronous cipher operation. This includes the cipher
  833. * handle (which can be used by multiple ablkcipher_request instances), pointer
  834. * to plaintext and ciphertext, asynchronous callback function, etc. It acts
  835. * as a handle to the ablkcipher_request_* API calls in a similar way as
  836. * ablkcipher handle to the crypto_ablkcipher_* API calls.
  837. */
  838. /**
  839. * crypto_ablkcipher_reqsize() - obtain size of the request data structure
  840. * @tfm: cipher handle
  841. *
  842. * Return: number of bytes
  843. */
  844. static inline unsigned int crypto_ablkcipher_reqsize(
  845. struct crypto_ablkcipher *tfm)
  846. {
  847. return crypto_ablkcipher_crt(tfm)->reqsize;
  848. }
  849. /**
  850. * ablkcipher_request_set_tfm() - update cipher handle reference in request
  851. * @req: request handle to be modified
  852. * @tfm: cipher handle that shall be added to the request handle
  853. *
  854. * Allow the caller to replace the existing ablkcipher handle in the request
  855. * data structure with a different one.
  856. */
  857. static inline void ablkcipher_request_set_tfm(
  858. struct ablkcipher_request *req, struct crypto_ablkcipher *tfm)
  859. {
  860. req->base.tfm = crypto_ablkcipher_tfm(crypto_ablkcipher_crt(tfm)->base);
  861. }
  862. static inline struct ablkcipher_request *ablkcipher_request_cast(
  863. struct crypto_async_request *req)
  864. {
  865. return container_of(req, struct ablkcipher_request, base);
  866. }
  867. /**
  868. * ablkcipher_request_alloc() - allocate request data structure
  869. * @tfm: cipher handle to be registered with the request
  870. * @gfp: memory allocation flag that is handed to kmalloc by the API call.
  871. *
  872. * Allocate the request data structure that must be used with the ablkcipher
  873. * encrypt and decrypt API calls. During the allocation, the provided ablkcipher
  874. * handle is registered in the request data structure.
  875. *
  876. * Return: allocated request handle in case of success, or NULL if out of memory
  877. */
  878. static inline struct ablkcipher_request *ablkcipher_request_alloc(
  879. struct crypto_ablkcipher *tfm, gfp_t gfp)
  880. {
  881. struct ablkcipher_request *req;
  882. req = kmalloc(sizeof(struct ablkcipher_request) +
  883. crypto_ablkcipher_reqsize(tfm), gfp);
  884. if (likely(req))
  885. ablkcipher_request_set_tfm(req, tfm);
  886. return req;
  887. }
  888. /**
  889. * ablkcipher_request_free() - zeroize and free request data structure
  890. * @req: request data structure cipher handle to be freed
  891. */
  892. static inline void ablkcipher_request_free(struct ablkcipher_request *req)
  893. {
  894. kzfree(req);
  895. }
  896. /**
  897. * ablkcipher_request_set_callback() - set asynchronous callback function
  898. * @req: request handle
  899. * @flags: specify zero or an ORing of the flags
  900. * CRYPTO_TFM_REQ_MAY_BACKLOG the request queue may back log and
  901. * increase the wait queue beyond the initial maximum size;
  902. * CRYPTO_TFM_REQ_MAY_SLEEP the request processing may sleep
  903. * @compl: callback function pointer to be registered with the request handle
  904. * @data: The data pointer refers to memory that is not used by the kernel
  905. * crypto API, but provided to the callback function for it to use. Here,
  906. * the caller can provide a reference to memory the callback function can
  907. * operate on. As the callback function is invoked asynchronously to the
  908. * related functionality, it may need to access data structures of the
  909. * related functionality which can be referenced using this pointer. The
  910. * callback function can access the memory via the "data" field in the
  911. * crypto_async_request data structure provided to the callback function.
  912. *
  913. * This function allows setting the callback function that is triggered once the
  914. * cipher operation completes.
  915. *
  916. * The callback function is registered with the ablkcipher_request handle and
  917. * must comply with the following template::
  918. *
  919. * void callback_function(struct crypto_async_request *req, int error)
  920. */
  921. static inline void ablkcipher_request_set_callback(
  922. struct ablkcipher_request *req,
  923. u32 flags, crypto_completion_t compl, void *data)
  924. {
  925. req->base.complete = compl;
  926. req->base.data = data;
  927. req->base.flags = flags;
  928. }
  929. /**
  930. * ablkcipher_request_set_crypt() - set data buffers
  931. * @req: request handle
  932. * @src: source scatter / gather list
  933. * @dst: destination scatter / gather list
  934. * @nbytes: number of bytes to process from @src
  935. * @iv: IV for the cipher operation which must comply with the IV size defined
  936. * by crypto_ablkcipher_ivsize
  937. *
  938. * This function allows setting of the source data and destination data
  939. * scatter / gather lists.
  940. *
  941. * For encryption, the source is treated as the plaintext and the
  942. * destination is the ciphertext. For a decryption operation, the use is
  943. * reversed - the source is the ciphertext and the destination is the plaintext.
  944. */
  945. static inline void ablkcipher_request_set_crypt(
  946. struct ablkcipher_request *req,
  947. struct scatterlist *src, struct scatterlist *dst,
  948. unsigned int nbytes, void *iv)
  949. {
  950. req->src = src;
  951. req->dst = dst;
  952. req->nbytes = nbytes;
  953. req->info = iv;
  954. }
  955. /**
  956. * DOC: Synchronous Block Cipher API
  957. *
  958. * The synchronous block cipher API is used with the ciphers of type
  959. * CRYPTO_ALG_TYPE_BLKCIPHER (listed as type "blkcipher" in /proc/crypto)
  960. *
  961. * Synchronous calls, have a context in the tfm. But since a single tfm can be
  962. * used in multiple calls and in parallel, this info should not be changeable
  963. * (unless a lock is used). This applies, for example, to the symmetric key.
  964. * However, the IV is changeable, so there is an iv field in blkcipher_tfm
  965. * structure for synchronous blkcipher api. So, its the only state info that can
  966. * be kept for synchronous calls without using a big lock across a tfm.
  967. *
  968. * The block cipher API allows the use of a complete cipher, i.e. a cipher
  969. * consisting of a template (a block chaining mode) and a single block cipher
  970. * primitive (e.g. AES).
  971. *
  972. * The plaintext data buffer and the ciphertext data buffer are pointed to
  973. * by using scatter/gather lists. The cipher operation is performed
  974. * on all segments of the provided scatter/gather lists.
  975. *
  976. * The kernel crypto API supports a cipher operation "in-place" which means that
  977. * the caller may provide the same scatter/gather list for the plaintext and
  978. * cipher text. After the completion of the cipher operation, the plaintext
  979. * data is replaced with the ciphertext data in case of an encryption and vice
  980. * versa for a decryption. The caller must ensure that the scatter/gather lists
  981. * for the output data point to sufficiently large buffers, i.e. multiples of
  982. * the block size of the cipher.
  983. */
  984. static inline struct crypto_blkcipher *__crypto_blkcipher_cast(
  985. struct crypto_tfm *tfm)
  986. {
  987. return (struct crypto_blkcipher *)tfm;
  988. }
  989. static inline struct crypto_blkcipher *crypto_blkcipher_cast(
  990. struct crypto_tfm *tfm)
  991. {
  992. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_BLKCIPHER);
  993. return __crypto_blkcipher_cast(tfm);
  994. }
  995. /**
  996. * crypto_alloc_blkcipher() - allocate synchronous block cipher handle
  997. * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
  998. * blkcipher cipher
  999. * @type: specifies the type of the cipher
  1000. * @mask: specifies the mask for the cipher
  1001. *
  1002. * Allocate a cipher handle for a block cipher. The returned struct
  1003. * crypto_blkcipher is the cipher handle that is required for any subsequent
  1004. * API invocation for that block cipher.
  1005. *
  1006. * Return: allocated cipher handle in case of success; IS_ERR() is true in case
  1007. * of an error, PTR_ERR() returns the error code.
  1008. */
  1009. static inline struct crypto_blkcipher *crypto_alloc_blkcipher(
  1010. const char *alg_name, u32 type, u32 mask)
  1011. {
  1012. type &= ~CRYPTO_ALG_TYPE_MASK;
  1013. type |= CRYPTO_ALG_TYPE_BLKCIPHER;
  1014. mask |= CRYPTO_ALG_TYPE_MASK;
  1015. return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask));
  1016. }
  1017. static inline struct crypto_tfm *crypto_blkcipher_tfm(
  1018. struct crypto_blkcipher *tfm)
  1019. {
  1020. return &tfm->base;
  1021. }
  1022. /**
  1023. * crypto_free_blkcipher() - zeroize and free the block cipher handle
  1024. * @tfm: cipher handle to be freed
  1025. */
  1026. static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm)
  1027. {
  1028. crypto_free_tfm(crypto_blkcipher_tfm(tfm));
  1029. }
  1030. /**
  1031. * crypto_has_blkcipher() - Search for the availability of a block cipher
  1032. * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
  1033. * block cipher
  1034. * @type: specifies the type of the cipher
  1035. * @mask: specifies the mask for the cipher
  1036. *
  1037. * Return: true when the block cipher is known to the kernel crypto API; false
  1038. * otherwise
  1039. */
  1040. static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask)
  1041. {
  1042. type &= ~CRYPTO_ALG_TYPE_MASK;
  1043. type |= CRYPTO_ALG_TYPE_BLKCIPHER;
  1044. mask |= CRYPTO_ALG_TYPE_MASK;
  1045. return crypto_has_alg(alg_name, type, mask);
  1046. }
  1047. /**
  1048. * crypto_blkcipher_name() - return the name / cra_name from the cipher handle
  1049. * @tfm: cipher handle
  1050. *
  1051. * Return: The character string holding the name of the cipher
  1052. */
  1053. static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm)
  1054. {
  1055. return crypto_tfm_alg_name(crypto_blkcipher_tfm(tfm));
  1056. }
  1057. static inline struct blkcipher_tfm *crypto_blkcipher_crt(
  1058. struct crypto_blkcipher *tfm)
  1059. {
  1060. return &crypto_blkcipher_tfm(tfm)->crt_blkcipher;
  1061. }
  1062. static inline struct blkcipher_alg *crypto_blkcipher_alg(
  1063. struct crypto_blkcipher *tfm)
  1064. {
  1065. return &crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher;
  1066. }
  1067. /**
  1068. * crypto_blkcipher_ivsize() - obtain IV size
  1069. * @tfm: cipher handle
  1070. *
  1071. * The size of the IV for the block cipher referenced by the cipher handle is
  1072. * returned. This IV size may be zero if the cipher does not need an IV.
  1073. *
  1074. * Return: IV size in bytes
  1075. */
  1076. static inline unsigned int crypto_blkcipher_ivsize(struct crypto_blkcipher *tfm)
  1077. {
  1078. return crypto_blkcipher_alg(tfm)->ivsize;
  1079. }
  1080. /**
  1081. * crypto_blkcipher_blocksize() - obtain block size of cipher
  1082. * @tfm: cipher handle
  1083. *
  1084. * The block size for the block cipher referenced with the cipher handle is
  1085. * returned. The caller may use that information to allocate appropriate
  1086. * memory for the data returned by the encryption or decryption operation.
  1087. *
  1088. * Return: block size of cipher
  1089. */
  1090. static inline unsigned int crypto_blkcipher_blocksize(
  1091. struct crypto_blkcipher *tfm)
  1092. {
  1093. return crypto_tfm_alg_blocksize(crypto_blkcipher_tfm(tfm));
  1094. }
  1095. static inline unsigned int crypto_blkcipher_alignmask(
  1096. struct crypto_blkcipher *tfm)
  1097. {
  1098. return crypto_tfm_alg_alignmask(crypto_blkcipher_tfm(tfm));
  1099. }
  1100. static inline u32 crypto_blkcipher_get_flags(struct crypto_blkcipher *tfm)
  1101. {
  1102. return crypto_tfm_get_flags(crypto_blkcipher_tfm(tfm));
  1103. }
  1104. static inline void crypto_blkcipher_set_flags(struct crypto_blkcipher *tfm,
  1105. u32 flags)
  1106. {
  1107. crypto_tfm_set_flags(crypto_blkcipher_tfm(tfm), flags);
  1108. }
  1109. static inline void crypto_blkcipher_clear_flags(struct crypto_blkcipher *tfm,
  1110. u32 flags)
  1111. {
  1112. crypto_tfm_clear_flags(crypto_blkcipher_tfm(tfm), flags);
  1113. }
  1114. /**
  1115. * crypto_blkcipher_setkey() - set key for cipher
  1116. * @tfm: cipher handle
  1117. * @key: buffer holding the key
  1118. * @keylen: length of the key in bytes
  1119. *
  1120. * The caller provided key is set for the block cipher referenced by the cipher
  1121. * handle.
  1122. *
  1123. * Note, the key length determines the cipher type. Many block ciphers implement
  1124. * different cipher modes depending on the key size, such as AES-128 vs AES-192
  1125. * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
  1126. * is performed.
  1127. *
  1128. * Return: 0 if the setting of the key was successful; < 0 if an error occurred
  1129. */
  1130. static inline int crypto_blkcipher_setkey(struct crypto_blkcipher *tfm,
  1131. const u8 *key, unsigned int keylen)
  1132. {
  1133. return crypto_blkcipher_crt(tfm)->setkey(crypto_blkcipher_tfm(tfm),
  1134. key, keylen);
  1135. }
  1136. /**
  1137. * crypto_blkcipher_encrypt() - encrypt plaintext
  1138. * @desc: reference to the block cipher handle with meta data
  1139. * @dst: scatter/gather list that is filled by the cipher operation with the
  1140. * ciphertext
  1141. * @src: scatter/gather list that holds the plaintext
  1142. * @nbytes: number of bytes of the plaintext to encrypt.
  1143. *
  1144. * Encrypt plaintext data using the IV set by the caller with a preceding
  1145. * call of crypto_blkcipher_set_iv.
  1146. *
  1147. * The blkcipher_desc data structure must be filled by the caller and can
  1148. * reside on the stack. The caller must fill desc as follows: desc.tfm is filled
  1149. * with the block cipher handle; desc.flags is filled with either
  1150. * CRYPTO_TFM_REQ_MAY_SLEEP or 0.
  1151. *
  1152. * Return: 0 if the cipher operation was successful; < 0 if an error occurred
  1153. */
  1154. static inline int crypto_blkcipher_encrypt(struct blkcipher_desc *desc,
  1155. struct scatterlist *dst,
  1156. struct scatterlist *src,
  1157. unsigned int nbytes)
  1158. {
  1159. desc->info = crypto_blkcipher_crt(desc->tfm)->iv;
  1160. return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes);
  1161. }
  1162. /**
  1163. * crypto_blkcipher_encrypt_iv() - encrypt plaintext with dedicated IV
  1164. * @desc: reference to the block cipher handle with meta data
  1165. * @dst: scatter/gather list that is filled by the cipher operation with the
  1166. * ciphertext
  1167. * @src: scatter/gather list that holds the plaintext
  1168. * @nbytes: number of bytes of the plaintext to encrypt.
  1169. *
  1170. * Encrypt plaintext data with the use of an IV that is solely used for this
  1171. * cipher operation. Any previously set IV is not used.
  1172. *
  1173. * The blkcipher_desc data structure must be filled by the caller and can
  1174. * reside on the stack. The caller must fill desc as follows: desc.tfm is filled
  1175. * with the block cipher handle; desc.info is filled with the IV to be used for
  1176. * the current operation; desc.flags is filled with either
  1177. * CRYPTO_TFM_REQ_MAY_SLEEP or 0.
  1178. *
  1179. * Return: 0 if the cipher operation was successful; < 0 if an error occurred
  1180. */
  1181. static inline int crypto_blkcipher_encrypt_iv(struct blkcipher_desc *desc,
  1182. struct scatterlist *dst,
  1183. struct scatterlist *src,
  1184. unsigned int nbytes)
  1185. {
  1186. return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes);
  1187. }
  1188. /**
  1189. * crypto_blkcipher_decrypt() - decrypt ciphertext
  1190. * @desc: reference to the block cipher handle with meta data
  1191. * @dst: scatter/gather list that is filled by the cipher operation with the
  1192. * plaintext
  1193. * @src: scatter/gather list that holds the ciphertext
  1194. * @nbytes: number of bytes of the ciphertext to decrypt.
  1195. *
  1196. * Decrypt ciphertext data using the IV set by the caller with a preceding
  1197. * call of crypto_blkcipher_set_iv.
  1198. *
  1199. * The blkcipher_desc data structure must be filled by the caller as documented
  1200. * for the crypto_blkcipher_encrypt call above.
  1201. *
  1202. * Return: 0 if the cipher operation was successful; < 0 if an error occurred
  1203. *
  1204. */
  1205. static inline int crypto_blkcipher_decrypt(struct blkcipher_desc *desc,
  1206. struct scatterlist *dst,
  1207. struct scatterlist *src,
  1208. unsigned int nbytes)
  1209. {
  1210. desc->info = crypto_blkcipher_crt(desc->tfm)->iv;
  1211. return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes);
  1212. }
  1213. /**
  1214. * crypto_blkcipher_decrypt_iv() - decrypt ciphertext with dedicated IV
  1215. * @desc: reference to the block cipher handle with meta data
  1216. * @dst: scatter/gather list that is filled by the cipher operation with the
  1217. * plaintext
  1218. * @src: scatter/gather list that holds the ciphertext
  1219. * @nbytes: number of bytes of the ciphertext to decrypt.
  1220. *
  1221. * Decrypt ciphertext data with the use of an IV that is solely used for this
  1222. * cipher operation. Any previously set IV is not used.
  1223. *
  1224. * The blkcipher_desc data structure must be filled by the caller as documented
  1225. * for the crypto_blkcipher_encrypt_iv call above.
  1226. *
  1227. * Return: 0 if the cipher operation was successful; < 0 if an error occurred
  1228. */
  1229. static inline int crypto_blkcipher_decrypt_iv(struct blkcipher_desc *desc,
  1230. struct scatterlist *dst,
  1231. struct scatterlist *src,
  1232. unsigned int nbytes)
  1233. {
  1234. return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes);
  1235. }
  1236. /**
  1237. * crypto_blkcipher_set_iv() - set IV for cipher
  1238. * @tfm: cipher handle
  1239. * @src: buffer holding the IV
  1240. * @len: length of the IV in bytes
  1241. *
  1242. * The caller provided IV is set for the block cipher referenced by the cipher
  1243. * handle.
  1244. */
  1245. static inline void crypto_blkcipher_set_iv(struct crypto_blkcipher *tfm,
  1246. const u8 *src, unsigned int len)
  1247. {
  1248. memcpy(crypto_blkcipher_crt(tfm)->iv, src, len);
  1249. }
  1250. /**
  1251. * crypto_blkcipher_get_iv() - obtain IV from cipher
  1252. * @tfm: cipher handle
  1253. * @dst: buffer filled with the IV
  1254. * @len: length of the buffer dst
  1255. *
  1256. * The caller can obtain the IV set for the block cipher referenced by the
  1257. * cipher handle and store it into the user-provided buffer. If the buffer
  1258. * has an insufficient space, the IV is truncated to fit the buffer.
  1259. */
  1260. static inline void crypto_blkcipher_get_iv(struct crypto_blkcipher *tfm,
  1261. u8 *dst, unsigned int len)
  1262. {
  1263. memcpy(dst, crypto_blkcipher_crt(tfm)->iv, len);
  1264. }
  1265. /**
  1266. * DOC: Single Block Cipher API
  1267. *
  1268. * The single block cipher API is used with the ciphers of type
  1269. * CRYPTO_ALG_TYPE_CIPHER (listed as type "cipher" in /proc/crypto).
  1270. *
  1271. * Using the single block cipher API calls, operations with the basic cipher
  1272. * primitive can be implemented. These cipher primitives exclude any block
  1273. * chaining operations including IV handling.
  1274. *
  1275. * The purpose of this single block cipher API is to support the implementation
  1276. * of templates or other concepts that only need to perform the cipher operation
  1277. * on one block at a time. Templates invoke the underlying cipher primitive
  1278. * block-wise and process either the input or the output data of these cipher
  1279. * operations.
  1280. */
  1281. static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm)
  1282. {
  1283. return (struct crypto_cipher *)tfm;
  1284. }
  1285. static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm)
  1286. {
  1287. BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
  1288. return __crypto_cipher_cast(tfm);
  1289. }
  1290. /**
  1291. * crypto_alloc_cipher() - allocate single block cipher handle
  1292. * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
  1293. * single block cipher
  1294. * @type: specifies the type of the cipher
  1295. * @mask: specifies the mask for the cipher
  1296. *
  1297. * Allocate a cipher handle for a single block cipher. The returned struct
  1298. * crypto_cipher is the cipher handle that is required for any subsequent API
  1299. * invocation for that single block cipher.
  1300. *
  1301. * Return: allocated cipher handle in case of success; IS_ERR() is true in case
  1302. * of an error, PTR_ERR() returns the error code.
  1303. */
  1304. static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name,
  1305. u32 type, u32 mask)
  1306. {
  1307. type &= ~CRYPTO_ALG_TYPE_MASK;
  1308. type |= CRYPTO_ALG_TYPE_CIPHER;
  1309. mask |= CRYPTO_ALG_TYPE_MASK;
  1310. return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask));
  1311. }
  1312. static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm)
  1313. {
  1314. return &tfm->base;
  1315. }
  1316. /**
  1317. * crypto_free_cipher() - zeroize and free the single block cipher handle
  1318. * @tfm: cipher handle to be freed
  1319. */
  1320. static inline void crypto_free_cipher(struct crypto_cipher *tfm)
  1321. {
  1322. crypto_free_tfm(crypto_cipher_tfm(tfm));
  1323. }
  1324. /**
  1325. * crypto_has_cipher() - Search for the availability of a single block cipher
  1326. * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
  1327. * single block cipher
  1328. * @type: specifies the type of the cipher
  1329. * @mask: specifies the mask for the cipher
  1330. *
  1331. * Return: true when the single block cipher is known to the kernel crypto API;
  1332. * false otherwise
  1333. */
  1334. static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask)
  1335. {
  1336. type &= ~CRYPTO_ALG_TYPE_MASK;
  1337. type |= CRYPTO_ALG_TYPE_CIPHER;
  1338. mask |= CRYPTO_ALG_TYPE_MASK;
  1339. return crypto_has_alg(alg_name, type, mask);
  1340. }
  1341. static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm)
  1342. {
  1343. return &crypto_cipher_tfm(tfm)->crt_cipher;
  1344. }
  1345. /**
  1346. * crypto_cipher_blocksize() - obtain block size for cipher
  1347. * @tfm: cipher handle
  1348. *
  1349. * The block size for the single block cipher referenced with the cipher handle
  1350. * tfm is returned. The caller may use that information to allocate appropriate
  1351. * memory for the data returned by the encryption or decryption operation
  1352. *
  1353. * Return: block size of cipher
  1354. */
  1355. static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm)
  1356. {
  1357. return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm));
  1358. }
  1359. static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm)
  1360. {
  1361. return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm));
  1362. }
  1363. static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm)
  1364. {
  1365. return crypto_tfm_get_flags(crypto_cipher_tfm(tfm));
  1366. }
  1367. static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm,
  1368. u32 flags)
  1369. {
  1370. crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags);
  1371. }
  1372. static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm,
  1373. u32 flags)
  1374. {
  1375. crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags);
  1376. }
  1377. /**
  1378. * crypto_cipher_setkey() - set key for cipher
  1379. * @tfm: cipher handle
  1380. * @key: buffer holding the key
  1381. * @keylen: length of the key in bytes
  1382. *
  1383. * The caller provided key is set for the single block cipher referenced by the
  1384. * cipher handle.
  1385. *
  1386. * Note, the key length determines the cipher type. Many block ciphers implement
  1387. * different cipher modes depending on the key size, such as AES-128 vs AES-192
  1388. * vs. AES-256. When providing a 16 byte key for an AES cipher handle, AES-128
  1389. * is performed.
  1390. *
  1391. * Return: 0 if the setting of the key was successful; < 0 if an error occurred
  1392. */
  1393. static inline int crypto_cipher_setkey(struct crypto_cipher *tfm,
  1394. const u8 *key, unsigned int keylen)
  1395. {
  1396. return crypto_cipher_crt(tfm)->cit_setkey(crypto_cipher_tfm(tfm),
  1397. key, keylen);
  1398. }
  1399. /**
  1400. * crypto_cipher_encrypt_one() - encrypt one block of plaintext
  1401. * @tfm: cipher handle
  1402. * @dst: points to the buffer that will be filled with the ciphertext
  1403. * @src: buffer holding the plaintext to be encrypted
  1404. *
  1405. * Invoke the encryption operation of one block. The caller must ensure that
  1406. * the plaintext and ciphertext buffers are at least one block in size.
  1407. */
  1408. static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
  1409. u8 *dst, const u8 *src)
  1410. {
  1411. crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm),
  1412. dst, src);
  1413. }
  1414. /**
  1415. * crypto_cipher_decrypt_one() - decrypt one block of ciphertext
  1416. * @tfm: cipher handle
  1417. * @dst: points to the buffer that will be filled with the plaintext
  1418. * @src: buffer holding the ciphertext to be decrypted
  1419. *
  1420. * Invoke the decryption operation of one block. The caller must ensure that
  1421. * the plaintext and ciphertext buffers are at least one block in size.
  1422. */
  1423. static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
  1424. u8 *dst, const u8 *src)
  1425. {
  1426. crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm),
  1427. dst, src);
  1428. }
  1429. static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm)
  1430. {
  1431. return (struct crypto_comp *)tfm;
  1432. }
  1433. static inline struct crypto_comp *crypto_comp_cast(struct crypto_tfm *tfm)
  1434. {
  1435. BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_COMPRESS) &
  1436. CRYPTO_ALG_TYPE_MASK);
  1437. return __crypto_comp_cast(tfm);
  1438. }
  1439. static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name,
  1440. u32 type, u32 mask)
  1441. {
  1442. type &= ~CRYPTO_ALG_TYPE_MASK;
  1443. type |= CRYPTO_ALG_TYPE_COMPRESS;
  1444. mask |= CRYPTO_ALG_TYPE_MASK;
  1445. return __crypto_comp_cast(crypto_alloc_base(alg_name, type, mask));
  1446. }
  1447. static inline struct crypto_tfm *crypto_comp_tfm(struct crypto_comp *tfm)
  1448. {
  1449. return &tfm->base;
  1450. }
  1451. static inline void crypto_free_comp(struct crypto_comp *tfm)
  1452. {
  1453. crypto_free_tfm(crypto_comp_tfm(tfm));
  1454. }
  1455. static inline int crypto_has_comp(const char *alg_name, u32 type, u32 mask)
  1456. {
  1457. type &= ~CRYPTO_ALG_TYPE_MASK;
  1458. type |= CRYPTO_ALG_TYPE_COMPRESS;
  1459. mask |= CRYPTO_ALG_TYPE_MASK;
  1460. return crypto_has_alg(alg_name, type, mask);
  1461. }
  1462. static inline const char *crypto_comp_name(struct crypto_comp *tfm)
  1463. {
  1464. return crypto_tfm_alg_name(crypto_comp_tfm(tfm));
  1465. }
  1466. static inline struct compress_tfm *crypto_comp_crt(struct crypto_comp *tfm)
  1467. {
  1468. return &crypto_comp_tfm(tfm)->crt_compress;
  1469. }
  1470. static inline int crypto_comp_compress(struct crypto_comp *tfm,
  1471. const u8 *src, unsigned int slen,
  1472. u8 *dst, unsigned int *dlen)
  1473. {
  1474. return crypto_comp_crt(tfm)->cot_compress(crypto_comp_tfm(tfm),
  1475. src, slen, dst, dlen);
  1476. }
  1477. static inline int crypto_comp_decompress(struct crypto_comp *tfm,
  1478. const u8 *src, unsigned int slen,
  1479. u8 *dst, unsigned int *dlen)
  1480. {
  1481. return crypto_comp_crt(tfm)->cot_decompress(crypto_comp_tfm(tfm),
  1482. src, slen, dst, dlen);
  1483. }
  1484. #endif /* _LINUX_CRYPTO_H */