ccp.h 18 KB

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