ccp.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * AMD Cryptographic Coprocessor (CCP) driver
  4. *
  5. * Copyright (C) 2013,2017 Advanced Micro Devices, Inc.
  6. *
  7. * Author: Tom Lendacky <[email protected]>
  8. * Author: Gary R Hook <[email protected]>
  9. */
  10. #ifndef __CCP_H__
  11. #define __CCP_H__
  12. #include <linux/scatterlist.h>
  13. #include <linux/workqueue.h>
  14. #include <linux/list.h>
  15. #include <crypto/aes.h>
  16. #include <crypto/sha1.h>
  17. #include <crypto/sha2.h>
  18. struct ccp_device;
  19. struct ccp_cmd;
  20. #if defined(CONFIG_CRYPTO_DEV_SP_CCP)
  21. /**
  22. * ccp_present - check if a CCP device is present
  23. *
  24. * Returns zero if a CCP device is present, -ENODEV otherwise.
  25. */
  26. int ccp_present(void);
  27. #define CCP_VSIZE 16
  28. #define CCP_VMASK ((unsigned int)((1 << CCP_VSIZE) - 1))
  29. #define CCP_VERSION(v, r) ((unsigned int)((v << CCP_VSIZE) \
  30. | (r & CCP_VMASK)))
  31. /**
  32. * ccp_version - get the version of the CCP
  33. *
  34. * Returns a positive version number, or zero if no CCP
  35. */
  36. unsigned int ccp_version(void);
  37. /**
  38. * ccp_enqueue_cmd - queue an operation for processing by the CCP
  39. *
  40. * @cmd: ccp_cmd struct to be processed
  41. *
  42. * Refer to the ccp_cmd struct below for required fields.
  43. *
  44. * Queue a cmd to be processed by the CCP. If queueing the cmd
  45. * would exceed the defined length of the cmd queue the cmd will
  46. * only be queued if the CCP_CMD_MAY_BACKLOG flag is set and will
  47. * result in a return code of -EBUSY.
  48. *
  49. * The callback routine specified in the ccp_cmd struct will be
  50. * called to notify the caller of completion (if the cmd was not
  51. * backlogged) or advancement out of the backlog. If the cmd has
  52. * advanced out of the backlog the "err" value of the callback
  53. * will be -EINPROGRESS. Any other "err" value during callback is
  54. * the result of the operation.
  55. *
  56. * The cmd has been successfully queued if:
  57. * the return code is -EINPROGRESS or
  58. * the return code is -EBUSY and CCP_CMD_MAY_BACKLOG flag is set
  59. */
  60. int ccp_enqueue_cmd(struct ccp_cmd *cmd);
  61. #else /* CONFIG_CRYPTO_DEV_CCP_SP_DEV is not enabled */
  62. static inline int ccp_present(void)
  63. {
  64. return -ENODEV;
  65. }
  66. static inline unsigned int ccp_version(void)
  67. {
  68. return 0;
  69. }
  70. static inline int ccp_enqueue_cmd(struct ccp_cmd *cmd)
  71. {
  72. return -ENODEV;
  73. }
  74. #endif /* CONFIG_CRYPTO_DEV_SP_CCP */
  75. /***** AES engine *****/
  76. /**
  77. * ccp_aes_type - AES key size
  78. *
  79. * @CCP_AES_TYPE_128: 128-bit key
  80. * @CCP_AES_TYPE_192: 192-bit key
  81. * @CCP_AES_TYPE_256: 256-bit key
  82. */
  83. enum ccp_aes_type {
  84. CCP_AES_TYPE_128 = 0,
  85. CCP_AES_TYPE_192,
  86. CCP_AES_TYPE_256,
  87. CCP_AES_TYPE__LAST,
  88. };
  89. /**
  90. * ccp_aes_mode - AES operation mode
  91. *
  92. * @CCP_AES_MODE_ECB: ECB mode
  93. * @CCP_AES_MODE_CBC: CBC mode
  94. * @CCP_AES_MODE_OFB: OFB mode
  95. * @CCP_AES_MODE_CFB: CFB mode
  96. * @CCP_AES_MODE_CTR: CTR mode
  97. * @CCP_AES_MODE_CMAC: CMAC mode
  98. */
  99. enum ccp_aes_mode {
  100. CCP_AES_MODE_ECB = 0,
  101. CCP_AES_MODE_CBC,
  102. CCP_AES_MODE_OFB,
  103. CCP_AES_MODE_CFB,
  104. CCP_AES_MODE_CTR,
  105. CCP_AES_MODE_CMAC,
  106. CCP_AES_MODE_GHASH,
  107. CCP_AES_MODE_GCTR,
  108. CCP_AES_MODE_GCM,
  109. CCP_AES_MODE_GMAC,
  110. CCP_AES_MODE__LAST,
  111. };
  112. /**
  113. * ccp_aes_mode - AES operation mode
  114. *
  115. * @CCP_AES_ACTION_DECRYPT: AES decrypt operation
  116. * @CCP_AES_ACTION_ENCRYPT: AES encrypt operation
  117. */
  118. enum ccp_aes_action {
  119. CCP_AES_ACTION_DECRYPT = 0,
  120. CCP_AES_ACTION_ENCRYPT,
  121. CCP_AES_ACTION__LAST,
  122. };
  123. /* Overloaded field */
  124. #define CCP_AES_GHASHAAD CCP_AES_ACTION_DECRYPT
  125. #define CCP_AES_GHASHFINAL CCP_AES_ACTION_ENCRYPT
  126. /**
  127. * struct ccp_aes_engine - CCP AES operation
  128. * @type: AES operation key size
  129. * @mode: AES operation mode
  130. * @action: AES operation (decrypt/encrypt)
  131. * @key: key to be used for this AES operation
  132. * @key_len: length in bytes of key
  133. * @iv: IV to be used for this AES operation
  134. * @iv_len: length in bytes of iv
  135. * @src: data to be used for this operation
  136. * @dst: data produced by this operation
  137. * @src_len: length in bytes of data used for this operation
  138. * @cmac_final: indicates final operation when running in CMAC mode
  139. * @cmac_key: K1/K2 key used in final CMAC operation
  140. * @cmac_key_len: length in bytes of cmac_key
  141. *
  142. * Variables required to be set when calling ccp_enqueue_cmd():
  143. * - type, mode, action, key, key_len, src, dst, src_len
  144. * - iv, iv_len for any mode other than ECB
  145. * - cmac_final for CMAC mode
  146. * - cmac_key, cmac_key_len for CMAC mode if cmac_final is non-zero
  147. *
  148. * The iv variable is used as both input and output. On completion of the
  149. * AES operation the new IV overwrites the old IV.
  150. */
  151. struct ccp_aes_engine {
  152. enum ccp_aes_type type;
  153. enum ccp_aes_mode mode;
  154. enum ccp_aes_action action;
  155. u32 authsize;
  156. struct scatterlist *key;
  157. u32 key_len; /* In bytes */
  158. struct scatterlist *iv;
  159. u32 iv_len; /* In bytes */
  160. struct scatterlist *src, *dst;
  161. u64 src_len; /* In bytes */
  162. u32 cmac_final; /* Indicates final cmac cmd */
  163. struct scatterlist *cmac_key; /* K1/K2 cmac key required for
  164. * final cmac cmd */
  165. u32 cmac_key_len; /* In bytes */
  166. u32 aad_len; /* In bytes */
  167. };
  168. /***** XTS-AES engine *****/
  169. /**
  170. * ccp_xts_aes_unit_size - XTS unit size
  171. *
  172. * @CCP_XTS_AES_UNIT_SIZE_16: Unit size of 16 bytes
  173. * @CCP_XTS_AES_UNIT_SIZE_512: Unit size of 512 bytes
  174. * @CCP_XTS_AES_UNIT_SIZE_1024: Unit size of 1024 bytes
  175. * @CCP_XTS_AES_UNIT_SIZE_2048: Unit size of 2048 bytes
  176. * @CCP_XTS_AES_UNIT_SIZE_4096: Unit size of 4096 bytes
  177. */
  178. enum ccp_xts_aes_unit_size {
  179. CCP_XTS_AES_UNIT_SIZE_16 = 0,
  180. CCP_XTS_AES_UNIT_SIZE_512,
  181. CCP_XTS_AES_UNIT_SIZE_1024,
  182. CCP_XTS_AES_UNIT_SIZE_2048,
  183. CCP_XTS_AES_UNIT_SIZE_4096,
  184. CCP_XTS_AES_UNIT_SIZE__LAST,
  185. };
  186. /**
  187. * struct ccp_xts_aes_engine - CCP XTS AES operation
  188. * @action: AES operation (decrypt/encrypt)
  189. * @unit_size: unit size of the XTS operation
  190. * @key: key to be used for this XTS AES operation
  191. * @key_len: length in bytes of key
  192. * @iv: IV to be used for this XTS AES operation
  193. * @iv_len: length in bytes of iv
  194. * @src: data to be used for this operation
  195. * @dst: data produced by this operation
  196. * @src_len: length in bytes of data used for this operation
  197. * @final: indicates final XTS operation
  198. *
  199. * Variables required to be set when calling ccp_enqueue_cmd():
  200. * - action, unit_size, key, key_len, iv, iv_len, src, dst, src_len, final
  201. *
  202. * The iv variable is used as both input and output. On completion of the
  203. * AES operation the new IV overwrites the old IV.
  204. */
  205. struct ccp_xts_aes_engine {
  206. enum ccp_aes_type type;
  207. enum ccp_aes_action action;
  208. enum ccp_xts_aes_unit_size unit_size;
  209. struct scatterlist *key;
  210. u32 key_len; /* In bytes */
  211. struct scatterlist *iv;
  212. u32 iv_len; /* In bytes */
  213. struct scatterlist *src, *dst;
  214. u64 src_len; /* In bytes */
  215. u32 final;
  216. };
  217. /***** SHA engine *****/
  218. /**
  219. * ccp_sha_type - type of SHA operation
  220. *
  221. * @CCP_SHA_TYPE_1: SHA-1 operation
  222. * @CCP_SHA_TYPE_224: SHA-224 operation
  223. * @CCP_SHA_TYPE_256: SHA-256 operation
  224. */
  225. enum ccp_sha_type {
  226. CCP_SHA_TYPE_1 = 1,
  227. CCP_SHA_TYPE_224,
  228. CCP_SHA_TYPE_256,
  229. CCP_SHA_TYPE_384,
  230. CCP_SHA_TYPE_512,
  231. CCP_SHA_TYPE__LAST,
  232. };
  233. /**
  234. * struct ccp_sha_engine - CCP SHA operation
  235. * @type: Type of SHA operation
  236. * @ctx: current hash value
  237. * @ctx_len: length in bytes of hash value
  238. * @src: data to be used for this operation
  239. * @src_len: length in bytes of data used for this operation
  240. * @opad: data to be used for final HMAC operation
  241. * @opad_len: length in bytes of data used for final HMAC operation
  242. * @first: indicates first SHA operation
  243. * @final: indicates final SHA operation
  244. * @msg_bits: total length of the message in bits used in final SHA operation
  245. *
  246. * Variables required to be set when calling ccp_enqueue_cmd():
  247. * - type, ctx, ctx_len, src, src_len, final
  248. * - msg_bits if final is non-zero
  249. *
  250. * The ctx variable is used as both input and output. On completion of the
  251. * SHA operation the new hash value overwrites the old hash value.
  252. */
  253. struct ccp_sha_engine {
  254. enum ccp_sha_type type;
  255. struct scatterlist *ctx;
  256. u32 ctx_len; /* In bytes */
  257. struct scatterlist *src;
  258. u64 src_len; /* In bytes */
  259. struct scatterlist *opad;
  260. u32 opad_len; /* In bytes */
  261. u32 first; /* Indicates first sha cmd */
  262. u32 final; /* Indicates final sha cmd */
  263. u64 msg_bits; /* Message length in bits required for
  264. * final sha cmd */
  265. };
  266. /***** 3DES engine *****/
  267. enum ccp_des3_mode {
  268. CCP_DES3_MODE_ECB = 0,
  269. CCP_DES3_MODE_CBC,
  270. CCP_DES3_MODE_CFB,
  271. CCP_DES3_MODE__LAST,
  272. };
  273. enum ccp_des3_type {
  274. CCP_DES3_TYPE_168 = 1,
  275. CCP_DES3_TYPE__LAST,
  276. };
  277. enum ccp_des3_action {
  278. CCP_DES3_ACTION_DECRYPT = 0,
  279. CCP_DES3_ACTION_ENCRYPT,
  280. CCP_DES3_ACTION__LAST,
  281. };
  282. /**
  283. * struct ccp_des3_engine - CCP SHA operation
  284. * @type: Type of 3DES operation
  285. * @mode: cipher mode
  286. * @action: 3DES operation (decrypt/encrypt)
  287. * @key: key to be used for this 3DES operation
  288. * @key_len: length of key (in bytes)
  289. * @iv: IV to be used for this AES operation
  290. * @iv_len: length in bytes of iv
  291. * @src: input data to be used for this operation
  292. * @src_len: length of input data used for this operation (in bytes)
  293. * @dst: output data produced by this operation
  294. *
  295. * Variables required to be set when calling ccp_enqueue_cmd():
  296. * - type, mode, action, key, key_len, src, dst, src_len
  297. * - iv, iv_len for any mode other than ECB
  298. *
  299. * The iv variable is used as both input and output. On completion of the
  300. * 3DES operation the new IV overwrites the old IV.
  301. */
  302. struct ccp_des3_engine {
  303. enum ccp_des3_type type;
  304. enum ccp_des3_mode mode;
  305. enum ccp_des3_action action;
  306. struct scatterlist *key;
  307. u32 key_len; /* In bytes */
  308. struct scatterlist *iv;
  309. u32 iv_len; /* In bytes */
  310. struct scatterlist *src, *dst;
  311. u64 src_len; /* In bytes */
  312. };
  313. /***** RSA engine *****/
  314. /**
  315. * struct ccp_rsa_engine - CCP RSA operation
  316. * @key_size: length in bits of RSA key
  317. * @exp: RSA exponent
  318. * @exp_len: length in bytes of exponent
  319. * @mod: RSA modulus
  320. * @mod_len: length in bytes of modulus
  321. * @src: data to be used for this operation
  322. * @dst: data produced by this operation
  323. * @src_len: length in bytes of data used for this operation
  324. *
  325. * Variables required to be set when calling ccp_enqueue_cmd():
  326. * - key_size, exp, exp_len, mod, mod_len, src, dst, src_len
  327. */
  328. struct ccp_rsa_engine {
  329. u32 key_size; /* In bits */
  330. struct scatterlist *exp;
  331. u32 exp_len; /* In bytes */
  332. struct scatterlist *mod;
  333. u32 mod_len; /* In bytes */
  334. struct scatterlist *src, *dst;
  335. u32 src_len; /* In bytes */
  336. };
  337. /***** Passthru engine *****/
  338. /**
  339. * ccp_passthru_bitwise - type of bitwise passthru operation
  340. *
  341. * @CCP_PASSTHRU_BITWISE_NOOP: no bitwise operation performed
  342. * @CCP_PASSTHRU_BITWISE_AND: perform bitwise AND of src with mask
  343. * @CCP_PASSTHRU_BITWISE_OR: perform bitwise OR of src with mask
  344. * @CCP_PASSTHRU_BITWISE_XOR: perform bitwise XOR of src with mask
  345. * @CCP_PASSTHRU_BITWISE_MASK: overwrite with mask
  346. */
  347. enum ccp_passthru_bitwise {
  348. CCP_PASSTHRU_BITWISE_NOOP = 0,
  349. CCP_PASSTHRU_BITWISE_AND,
  350. CCP_PASSTHRU_BITWISE_OR,
  351. CCP_PASSTHRU_BITWISE_XOR,
  352. CCP_PASSTHRU_BITWISE_MASK,
  353. CCP_PASSTHRU_BITWISE__LAST,
  354. };
  355. /**
  356. * ccp_passthru_byteswap - type of byteswap passthru operation
  357. *
  358. * @CCP_PASSTHRU_BYTESWAP_NOOP: no byte swapping performed
  359. * @CCP_PASSTHRU_BYTESWAP_32BIT: swap bytes within 32-bit words
  360. * @CCP_PASSTHRU_BYTESWAP_256BIT: swap bytes within 256-bit words
  361. */
  362. enum ccp_passthru_byteswap {
  363. CCP_PASSTHRU_BYTESWAP_NOOP = 0,
  364. CCP_PASSTHRU_BYTESWAP_32BIT,
  365. CCP_PASSTHRU_BYTESWAP_256BIT,
  366. CCP_PASSTHRU_BYTESWAP__LAST,
  367. };
  368. /**
  369. * struct ccp_passthru_engine - CCP pass-through operation
  370. * @bit_mod: bitwise operation to perform
  371. * @byte_swap: byteswap operation to perform
  372. * @mask: mask to be applied to data
  373. * @mask_len: length in bytes of mask
  374. * @src: data to be used for this operation
  375. * @dst: data produced by this operation
  376. * @src_len: length in bytes of data used for this operation
  377. * @final: indicate final pass-through operation
  378. *
  379. * Variables required to be set when calling ccp_enqueue_cmd():
  380. * - bit_mod, byte_swap, src, dst, src_len
  381. * - mask, mask_len if bit_mod is not CCP_PASSTHRU_BITWISE_NOOP
  382. */
  383. struct ccp_passthru_engine {
  384. enum ccp_passthru_bitwise bit_mod;
  385. enum ccp_passthru_byteswap byte_swap;
  386. struct scatterlist *mask;
  387. u32 mask_len; /* In bytes */
  388. struct scatterlist *src, *dst;
  389. u64 src_len; /* In bytes */
  390. u32 final;
  391. };
  392. /**
  393. * struct ccp_passthru_nomap_engine - CCP pass-through operation
  394. * without performing DMA mapping
  395. * @bit_mod: bitwise operation to perform
  396. * @byte_swap: byteswap operation to perform
  397. * @mask: mask to be applied to data
  398. * @mask_len: length in bytes of mask
  399. * @src: data to be used for this operation
  400. * @dst: data produced by this operation
  401. * @src_len: length in bytes of data used for this operation
  402. * @final: indicate final pass-through operation
  403. *
  404. * Variables required to be set when calling ccp_enqueue_cmd():
  405. * - bit_mod, byte_swap, src, dst, src_len
  406. * - mask, mask_len if bit_mod is not CCP_PASSTHRU_BITWISE_NOOP
  407. */
  408. struct ccp_passthru_nomap_engine {
  409. enum ccp_passthru_bitwise bit_mod;
  410. enum ccp_passthru_byteswap byte_swap;
  411. dma_addr_t mask;
  412. u32 mask_len; /* In bytes */
  413. dma_addr_t src_dma, dst_dma;
  414. u64 src_len; /* In bytes */
  415. u32 final;
  416. };
  417. /***** ECC engine *****/
  418. #define CCP_ECC_MODULUS_BYTES 48 /* 384-bits */
  419. #define CCP_ECC_MAX_OPERANDS 6
  420. #define CCP_ECC_MAX_OUTPUTS 3
  421. /**
  422. * ccp_ecc_function - type of ECC function
  423. *
  424. * @CCP_ECC_FUNCTION_MMUL_384BIT: 384-bit modular multiplication
  425. * @CCP_ECC_FUNCTION_MADD_384BIT: 384-bit modular addition
  426. * @CCP_ECC_FUNCTION_MINV_384BIT: 384-bit multiplicative inverse
  427. * @CCP_ECC_FUNCTION_PADD_384BIT: 384-bit point addition
  428. * @CCP_ECC_FUNCTION_PMUL_384BIT: 384-bit point multiplication
  429. * @CCP_ECC_FUNCTION_PDBL_384BIT: 384-bit point doubling
  430. */
  431. enum ccp_ecc_function {
  432. CCP_ECC_FUNCTION_MMUL_384BIT = 0,
  433. CCP_ECC_FUNCTION_MADD_384BIT,
  434. CCP_ECC_FUNCTION_MINV_384BIT,
  435. CCP_ECC_FUNCTION_PADD_384BIT,
  436. CCP_ECC_FUNCTION_PMUL_384BIT,
  437. CCP_ECC_FUNCTION_PDBL_384BIT,
  438. };
  439. /**
  440. * struct ccp_ecc_modular_math - CCP ECC modular math parameters
  441. * @operand_1: first operand for the modular math operation
  442. * @operand_1_len: length of the first operand
  443. * @operand_2: second operand for the modular math operation
  444. * (not used for CCP_ECC_FUNCTION_MINV_384BIT)
  445. * @operand_2_len: length of the second operand
  446. * (not used for CCP_ECC_FUNCTION_MINV_384BIT)
  447. * @result: result of the modular math operation
  448. * @result_len: length of the supplied result buffer
  449. */
  450. struct ccp_ecc_modular_math {
  451. struct scatterlist *operand_1;
  452. unsigned int operand_1_len; /* In bytes */
  453. struct scatterlist *operand_2;
  454. unsigned int operand_2_len; /* In bytes */
  455. struct scatterlist *result;
  456. unsigned int result_len; /* In bytes */
  457. };
  458. /**
  459. * struct ccp_ecc_point - CCP ECC point definition
  460. * @x: the x coordinate of the ECC point
  461. * @x_len: the length of the x coordinate
  462. * @y: the y coordinate of the ECC point
  463. * @y_len: the length of the y coordinate
  464. */
  465. struct ccp_ecc_point {
  466. struct scatterlist *x;
  467. unsigned int x_len; /* In bytes */
  468. struct scatterlist *y;
  469. unsigned int y_len; /* In bytes */
  470. };
  471. /**
  472. * struct ccp_ecc_point_math - CCP ECC point math parameters
  473. * @point_1: the first point of the ECC point math operation
  474. * @point_2: the second point of the ECC point math operation
  475. * (only used for CCP_ECC_FUNCTION_PADD_384BIT)
  476. * @domain_a: the a parameter of the ECC curve
  477. * @domain_a_len: the length of the a parameter
  478. * @scalar: the scalar parameter for the point match operation
  479. * (only used for CCP_ECC_FUNCTION_PMUL_384BIT)
  480. * @scalar_len: the length of the scalar parameter
  481. * (only used for CCP_ECC_FUNCTION_PMUL_384BIT)
  482. * @result: the point resulting from the point math operation
  483. */
  484. struct ccp_ecc_point_math {
  485. struct ccp_ecc_point point_1;
  486. struct ccp_ecc_point point_2;
  487. struct scatterlist *domain_a;
  488. unsigned int domain_a_len; /* In bytes */
  489. struct scatterlist *scalar;
  490. unsigned int scalar_len; /* In bytes */
  491. struct ccp_ecc_point result;
  492. };
  493. /**
  494. * struct ccp_ecc_engine - CCP ECC operation
  495. * @function: ECC function to perform
  496. * @mod: ECC modulus
  497. * @mod_len: length in bytes of modulus
  498. * @mm: module math parameters
  499. * @pm: point math parameters
  500. * @ecc_result: result of the ECC operation
  501. *
  502. * Variables required to be set when calling ccp_enqueue_cmd():
  503. * - function, mod, mod_len
  504. * - operand, operand_len, operand_count, output, output_len, output_count
  505. * - ecc_result
  506. */
  507. struct ccp_ecc_engine {
  508. enum ccp_ecc_function function;
  509. struct scatterlist *mod;
  510. u32 mod_len; /* In bytes */
  511. union {
  512. struct ccp_ecc_modular_math mm;
  513. struct ccp_ecc_point_math pm;
  514. } u;
  515. u16 ecc_result;
  516. };
  517. /**
  518. * ccp_engine - CCP operation identifiers
  519. *
  520. * @CCP_ENGINE_AES: AES operation
  521. * @CCP_ENGINE_XTS_AES: 128-bit XTS AES operation
  522. * @CCP_ENGINE_RSVD1: unused
  523. * @CCP_ENGINE_SHA: SHA operation
  524. * @CCP_ENGINE_RSA: RSA operation
  525. * @CCP_ENGINE_PASSTHRU: pass-through operation
  526. * @CCP_ENGINE_ZLIB_DECOMPRESS: unused
  527. * @CCP_ENGINE_ECC: ECC operation
  528. */
  529. enum ccp_engine {
  530. CCP_ENGINE_AES = 0,
  531. CCP_ENGINE_XTS_AES_128,
  532. CCP_ENGINE_DES3,
  533. CCP_ENGINE_SHA,
  534. CCP_ENGINE_RSA,
  535. CCP_ENGINE_PASSTHRU,
  536. CCP_ENGINE_ZLIB_DECOMPRESS,
  537. CCP_ENGINE_ECC,
  538. CCP_ENGINE__LAST,
  539. };
  540. /* Flag values for flags member of ccp_cmd */
  541. #define CCP_CMD_MAY_BACKLOG 0x00000001
  542. #define CCP_CMD_PASSTHRU_NO_DMA_MAP 0x00000002
  543. /**
  544. * struct ccp_cmd - CCP operation request
  545. * @entry: list element (ccp driver use only)
  546. * @work: work element used for callbacks (ccp driver use only)
  547. * @ccp: CCP device to be run on
  548. * @ret: operation return code (ccp driver use only)
  549. * @flags: cmd processing flags
  550. * @engine: CCP operation to perform
  551. * @engine_error: CCP engine return code
  552. * @u: engine specific structures, refer to specific engine struct below
  553. * @callback: operation completion callback function
  554. * @data: parameter value to be supplied to the callback function
  555. *
  556. * Variables required to be set when calling ccp_enqueue_cmd():
  557. * - engine, callback
  558. * - See the operation structures below for what is required for each
  559. * operation.
  560. */
  561. struct ccp_cmd {
  562. /* The list_head, work_struct, ccp and ret variables are for use
  563. * by the CCP driver only.
  564. */
  565. struct list_head entry;
  566. struct work_struct work;
  567. struct ccp_device *ccp;
  568. int ret;
  569. u32 flags;
  570. enum ccp_engine engine;
  571. u32 engine_error;
  572. union {
  573. struct ccp_aes_engine aes;
  574. struct ccp_xts_aes_engine xts;
  575. struct ccp_des3_engine des3;
  576. struct ccp_sha_engine sha;
  577. struct ccp_rsa_engine rsa;
  578. struct ccp_passthru_engine passthru;
  579. struct ccp_passthru_nomap_engine passthru_nomap;
  580. struct ccp_ecc_engine ecc;
  581. } u;
  582. /* Completion callback support */
  583. void (*callback)(void *data, int err);
  584. void *data;
  585. };
  586. #endif